From 398aedb75b7610ff90c549267127137d5b336a4d Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 21 Feb 2024 14:45:24 +0400 Subject: [PATCH 01/11] feat(passkeys): added passkeys api calls --- .gitmodules | 4 +- binary-websocket-api | 2 +- .../passkeys_list_response_result.dart | 180 ++++ .../passkeys_options_response_result.dart | 502 ++++++++++ ...keys_register_options_response_result.dart | 857 ++++++++++++++++++ .../passkeys_register_response_result.dart | 172 ++++ .../passkeys_rename_response_result.dart | 81 ++ .../passkeys_revoke_response_result.dart | 81 ++ 8 files changed, 1876 insertions(+), 3 deletions(-) create mode 100644 lib/api/response/passkeys_list_response_result.dart create mode 100644 lib/api/response/passkeys_options_response_result.dart create mode 100644 lib/api/response/passkeys_register_options_response_result.dart create mode 100644 lib/api/response/passkeys_register_response_result.dart create mode 100644 lib/api/response/passkeys_rename_response_result.dart create mode 100644 lib/api/response/passkeys_revoke_response_result.dart diff --git a/.gitmodules b/.gitmodules index 5acd714fe2..9f0c5d2dc8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "binary-websocket-api"] path = binary-websocket-api - url = https://github.com/regentmarkets/binary-websocket-api.git - branch = master + url = https://github.com/bassam-deriv/binary-websocket-api.git + branch = deriv_passkeys diff --git a/binary-websocket-api b/binary-websocket-api index 4a2ead83f9..f43a079b2f 160000 --- a/binary-websocket-api +++ b/binary-websocket-api @@ -1 +1 @@ -Subproject commit 4a2ead83f9323d0b8bfe762710b2898060a9c98f +Subproject commit f43a079b2f35ec1f2c4c7a51e50399df62fb9ed5 diff --git a/lib/api/response/passkeys_list_response_result.dart b/lib/api/response/passkeys_list_response_result.dart new file mode 100644 index 0000000000..c396f86a7e --- /dev/null +++ b/lib/api/response/passkeys_list_response_result.dart @@ -0,0 +1,180 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_list_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_list_send.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Passkeys list response model class. +abstract class PasskeysListResponseModel { + /// Initializes Passkeys list response model class . + const PasskeysListResponseModel({ + this.passkeysList, + }); + + /// The list of passkeys. + final List? passkeysList; +} + +/// Passkeys list response class. +class PasskeysListResponse extends PasskeysListResponseModel { + /// Initializes Passkeys list response class. + const PasskeysListResponse({ + super.passkeysList, + }); + + /// Creates an instance from JSON. + factory PasskeysListResponse.fromJson( + dynamic passkeysListJson, + ) => + PasskeysListResponse( + passkeysList: passkeysListJson == null + ? null + : List.from( + passkeysListJson?.map( + (dynamic item) => PasskeysListItem.fromJson(item), + ), + ), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (passkeysList != null) { + resultMap['passkeys_list'] = passkeysList! + .map( + (PasskeysListItem item) => item.toJson(), + ) + .toList(); + } + + return resultMap; + } + + static final BaseAPI _api = Injector()(); + + /// List all passkeys. + static Future fetch( + PasskeysListRequest request, + ) async { + final PasskeysListReceive response = await fetchRaw(request); + + return PasskeysListResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys list response. + static Future fetchRaw( + PasskeysListRequest request, + ) async { + final PasskeysListReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } + + /// Creates a copy of instance with given parameters. + PasskeysListResponse copyWith({ + List? passkeysList, + }) => + PasskeysListResponse( + passkeysList: passkeysList ?? this.passkeysList, + ); +} + +/// Passkeys list item model class. +abstract class PasskeysListItemModel { + /// Initializes Passkeys list item model class . + const PasskeysListItemModel({ + this.createdOn, + this.id, + this.lastUsed, + this.name, + this.passkey, + this.userId, + }); + + /// The date of the passkey creation + final String? createdOn; + + /// The system id of the passkey + final String? id; + + /// The date of the last passkey usage + final String? lastUsed; + + /// The name of the passkey + final String? name; + + /// The id of the credential. for mock only + final Map? passkey; + + /// The id of the user. for mock only + final String? userId; +} + +/// Passkeys list item class. +class PasskeysListItem extends PasskeysListItemModel { + /// Initializes Passkeys list item class. + const PasskeysListItem({ + super.createdOn, + super.id, + super.lastUsed, + super.name, + super.passkey, + super.userId, + }); + + /// Creates an instance from JSON. + factory PasskeysListItem.fromJson(Map json) => + PasskeysListItem( + createdOn: json['created_on'], + id: json['id'], + lastUsed: json['last_used'], + name: json['name'], + passkey: json['passkey'], + userId: json['user_id'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['created_on'] = createdOn; + resultMap['id'] = id; + resultMap['last_used'] = lastUsed; + resultMap['name'] = name; + resultMap['passkey'] = passkey; + resultMap['user_id'] = userId; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PasskeysListItem copyWith({ + String? createdOn, + String? id, + String? lastUsed, + String? name, + Map? passkey, + String? userId, + }) => + PasskeysListItem( + createdOn: createdOn ?? this.createdOn, + id: id ?? this.id, + lastUsed: lastUsed ?? this.lastUsed, + name: name ?? this.name, + passkey: passkey ?? this.passkey, + userId: userId ?? this.userId, + ); +} diff --git a/lib/api/response/passkeys_options_response_result.dart b/lib/api/response/passkeys_options_response_result.dart new file mode 100644 index 0000000000..9db91448d8 --- /dev/null +++ b/lib/api/response/passkeys_options_response_result.dart @@ -0,0 +1,502 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_options_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_options_send.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Passkeys options response model class. +abstract class PasskeysOptionsResponseModel { + /// Initializes Passkeys options response model class . + const PasskeysOptionsResponseModel({ + this.passkeysOptions, + }); + + /// Wrapper of the response. + final PasskeysOptions? passkeysOptions; +} + +/// Passkeys options response class. +class PasskeysOptionsResponse extends PasskeysOptionsResponseModel { + /// Initializes Passkeys options response class. + const PasskeysOptionsResponse({ + super.passkeysOptions, + }); + + /// Creates an instance from JSON. + factory PasskeysOptionsResponse.fromJson( + dynamic passkeysOptionsJson, + ) => + PasskeysOptionsResponse( + passkeysOptions: passkeysOptionsJson == null + ? null + : PasskeysOptions.fromJson(passkeysOptionsJson), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (passkeysOptions != null) { + resultMap['passkeys_options'] = passkeysOptions!.toJson(); + } + + return resultMap; + } + + static final BaseAPI _api = Injector()(); + + /// List all passkeys options. + static Future fetch( + PasskeysOptionsRequest request, + ) async { + final PasskeysOptionsReceive response = await fetchRaw(request); + + return PasskeysOptionsResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys options response. + static Future fetchRaw( + PasskeysOptionsRequest request, + ) async { + final PasskeysOptionsReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } + + /// Creates a copy of instance with given parameters. + PasskeysOptionsResponse copyWith({ + PasskeysOptions? passkeysOptions, + }) => + PasskeysOptionsResponse( + passkeysOptions: passkeysOptions ?? this.passkeysOptions, + ); +} + +/// TransportsItemEnum mapper. +final Map transportsItemEnumMapper = + { + "usb": TransportsItemEnum.usb, + "nfc": TransportsItemEnum.nfc, + "ble": TransportsItemEnum.ble, + "internal": TransportsItemEnum.internal, +}; + +/// TransportsItem Enum. +enum TransportsItemEnum { + /// usb. + usb, + + /// nfc. + nfc, + + /// ble. + ble, + + /// internal. + internal, +} + +/// TypeEnum mapper. +final Map typeEnumMapper = { + "public-key": TypeEnum.publicKey, +}; + +/// Type Enum. +enum TypeEnum { + /// public-key. + publicKey, +} + +/// UserVerificationEnum mapper. +final Map userVerificationEnumMapper = + { + "required": UserVerificationEnum.required, + "preferred": UserVerificationEnum.preferred, + "discouraged": UserVerificationEnum.discouraged, +}; + +/// UserVerification Enum. +enum UserVerificationEnum { + /// required. + required, + + /// preferred. + preferred, + + /// discouraged. + discouraged, +} + +/// Passkeys options model class. +abstract class PasskeysOptionsModel { + /// Initializes Passkeys options model class . + const PasskeysOptionsModel({ + this.publicKey, + }); + + /// Wrapper of the options. + final PublicKey? publicKey; +} + +/// Passkeys options class. +class PasskeysOptions extends PasskeysOptionsModel { + /// Initializes Passkeys options class. + const PasskeysOptions({ + super.publicKey, + }); + + /// Creates an instance from JSON. + factory PasskeysOptions.fromJson(Map json) => + PasskeysOptions( + publicKey: json['publicKey'] == null + ? null + : PublicKey.fromJson(json['publicKey']), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (publicKey != null) { + resultMap['publicKey'] = publicKey!.toJson(); + } + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PasskeysOptions copyWith({ + PublicKey? publicKey, + }) => + PasskeysOptions( + publicKey: publicKey ?? this.publicKey, + ); +} + +/// Public key model class. +abstract class PublicKeyModel { + /// Initializes Public key model class . + const PublicKeyModel({ + this.allowCredentials, + this.challenge, + this.extensions, + this.rpId, + this.timeout, + this.userVerification, + }); + + /// List of credentials that are already registered. Only listed credentials are allowed to authenticate. + final List? allowCredentials; + + /// Random string to be signed by the authenticator. will be byte array base64 encoded. + final String? challenge; + + /// Empty for now + final Extensions? extensions; + + /// Relying party id. + final String? rpId; + + /// Time before expiring the cermony in milliseconds. + final DateTime? timeout; + + /// Ask the user to enter thier authentication method (PIN, fingerprint, etc). Default is discouraged. + final UserVerificationEnum? userVerification; +} + +/// Public key class. +class PublicKey extends PublicKeyModel { + /// Initializes Public key class. + const PublicKey({ + super.allowCredentials, + super.challenge, + super.extensions, + super.rpId, + super.timeout, + super.userVerification, + }); + + /// Creates an instance from JSON. + factory PublicKey.fromJson(Map json) => PublicKey( + allowCredentials: json['allowCredentials'] == null + ? null + : List.from( + json['allowCredentials']?.map( + (dynamic item) => AllowCredentialsItem.fromJson(item), + ), + ), + challenge: json['challenge'], + extensions: json['extensions'] == null + ? null + : Extensions.fromJson(json['extensions']), + rpId: json['rpId'], + timeout: getDateTime(json['timeout']), + userVerification: json['userVerification'] == null + ? null + : userVerificationEnumMapper[json['userVerification']], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (allowCredentials != null) { + resultMap['allowCredentials'] = allowCredentials! + .map( + (AllowCredentialsItem item) => item.toJson(), + ) + .toList(); + } + resultMap['challenge'] = challenge; + if (extensions != null) { + resultMap['extensions'] = extensions!.toJson(); + } + resultMap['rpId'] = rpId; + resultMap['timeout'] = getSecondsSinceEpochDateTime(timeout); + resultMap['userVerification'] = userVerificationEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == userVerification) + .key; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PublicKey copyWith({ + List? allowCredentials, + String? challenge, + Extensions? extensions, + String? rpId, + DateTime? timeout, + UserVerificationEnum? userVerification, + }) => + PublicKey( + allowCredentials: allowCredentials ?? this.allowCredentials, + challenge: challenge ?? this.challenge, + extensions: extensions ?? this.extensions, + rpId: rpId ?? this.rpId, + timeout: timeout ?? this.timeout, + userVerification: userVerification ?? this.userVerification, + ); +} + +/// Allow credentials item model class. +abstract class AllowCredentialsItemModel { + /// Initializes Allow credentials item model class . + const AllowCredentialsItemModel({ + this.id, + this.transports, + this.type, + }); + + /// The credential id. base64 encoded. + final String? id; + + /// The transports supported by the authenticator. + final List? transports; + + /// Will be always public-key. + final TypeEnum? type; +} + +/// Allow credentials item class. +class AllowCredentialsItem extends AllowCredentialsItemModel { + /// Initializes Allow credentials item class. + const AllowCredentialsItem({ + super.id, + super.transports, + super.type, + }); + + /// Creates an instance from JSON. + factory AllowCredentialsItem.fromJson(Map json) => + AllowCredentialsItem( + id: json['id'], + transports: json['transports'] == null + ? null + : List.from( + json['transports']?.map( + (dynamic item) => + item == null ? null : transportsItemEnumMapper[item], + ), + ), + type: json['type'] == null ? null : typeEnumMapper[json['type']], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['id'] = id; + if (transports != null) { + resultMap['transports'] = transports! + .map( + (TransportsItemEnum item) => transportsItemEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == item) + .key, + ) + .toList(); + } + resultMap['type'] = typeEnumMapper.entries + .firstWhere((MapEntry entry) => entry.value == type) + .key; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + AllowCredentialsItem copyWith({ + String? id, + List? transports, + TypeEnum? type, + }) => + AllowCredentialsItem( + id: id ?? this.id, + transports: transports ?? this.transports, + type: type ?? this.type, + ); +} + +/// Extensions model class. +abstract class ExtensionsModel { + /// Initializes Extensions model class . + const ExtensionsModel({ + this.exts, + this.loc, + this.txAuthGeneric, + this.txAuthSimple, + this.uvi, + }); + + /// The exts. + final bool? exts; + + /// The loc. + final bool? loc; + + /// The txAuthGeneric. + final TxAuthGeneric? txAuthGeneric; + + /// The txAuthSimple. + final String? txAuthSimple; + + /// The uvi. + final bool? uvi; +} + +/// Extensions class. +class Extensions extends ExtensionsModel { + /// Initializes Extensions class. + const Extensions({ + super.exts, + super.loc, + super.txAuthGeneric, + super.txAuthSimple, + super.uvi, + }); + + /// Creates an instance from JSON. + factory Extensions.fromJson(Map json) => Extensions( + exts: getBool(json['exts']), + loc: getBool(json['loc']), + txAuthGeneric: json['txAuthGeneric'] == null + ? null + : TxAuthGeneric.fromJson(json['txAuthGeneric']), + txAuthSimple: json['txAuthSimple'], + uvi: getBool(json['uvi']), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['exts'] = exts; + resultMap['loc'] = loc; + if (txAuthGeneric != null) { + resultMap['txAuthGeneric'] = txAuthGeneric!.toJson(); + } + resultMap['txAuthSimple'] = txAuthSimple; + resultMap['uvi'] = uvi; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + Extensions copyWith({ + bool? exts, + bool? loc, + TxAuthGeneric? txAuthGeneric, + String? txAuthSimple, + bool? uvi, + }) => + Extensions( + exts: exts ?? this.exts, + loc: loc ?? this.loc, + txAuthGeneric: txAuthGeneric ?? this.txAuthGeneric, + txAuthSimple: txAuthSimple ?? this.txAuthSimple, + uvi: uvi ?? this.uvi, + ); +} + +/// Tx auth generic model class. +abstract class TxAuthGenericModel { + /// Initializes Tx auth generic model class . + const TxAuthGenericModel({ + this.content, + this.contentType, + }); + + /// The content. + final String? content; + + /// The contentType. + final String? contentType; +} + +/// Tx auth generic class. +class TxAuthGeneric extends TxAuthGenericModel { + /// Initializes Tx auth generic class. + const TxAuthGeneric({ + super.content, + super.contentType, + }); + + /// Creates an instance from JSON. + factory TxAuthGeneric.fromJson(Map json) => TxAuthGeneric( + content: json['content'], + contentType: json['contentType'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['content'] = content; + resultMap['contentType'] = contentType; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + TxAuthGeneric copyWith({ + String? content, + String? contentType, + }) => + TxAuthGeneric( + content: content ?? this.content, + contentType: contentType ?? this.contentType, + ); +} diff --git a/lib/api/response/passkeys_register_options_response_result.dart b/lib/api/response/passkeys_register_options_response_result.dart new file mode 100644 index 0000000000..7bef9942c7 --- /dev/null +++ b/lib/api/response/passkeys_register_options_response_result.dart @@ -0,0 +1,857 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_register_options_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_register_options_send.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Passkeys register options response model class. +abstract class PasskeysRegisterOptionsResponseModel { + /// Initializes Passkeys register options response model class . + const PasskeysRegisterOptionsResponseModel({ + this.passkeysRegisterOptions, + }); + + /// Wrapper of the response. + final PasskeysRegisterOptions? passkeysRegisterOptions; +} + +/// Passkeys register options response class. +class PasskeysRegisterOptionsResponse + extends PasskeysRegisterOptionsResponseModel { + /// Initializes Passkeys register options response class. + const PasskeysRegisterOptionsResponse({ + super.passkeysRegisterOptions, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterOptionsResponse.fromJson( + dynamic passkeysRegisterOptionsJson, + ) => + PasskeysRegisterOptionsResponse( + passkeysRegisterOptions: passkeysRegisterOptionsJson == null + ? null + : PasskeysRegisterOptions.fromJson(passkeysRegisterOptionsJson), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (passkeysRegisterOptions != null) { + resultMap['passkeys_register_options'] = + passkeysRegisterOptions!.toJson(); + } + + return resultMap; + } + + static final BaseAPI _api = Injector()(); + + /// List all register passkeys options. + static Future fetch( + PasskeysRegisterOptionsRequest request, + ) async { + final PasskeysRegisterOptionsReceive response = await fetchRaw(request); + + return PasskeysRegisterOptionsResponse.fromJson(response.toJson()); + } + + /// Fetches raw register passkeys options response. + static Future fetchRaw( + PasskeysRegisterOptionsRequest request, + ) async { + final PasskeysRegisterOptionsReceive response = + await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } + + /// Creates a copy of instance with given parameters. + PasskeysRegisterOptionsResponse copyWith({ + PasskeysRegisterOptions? passkeysRegisterOptions, + }) => + PasskeysRegisterOptionsResponse( + passkeysRegisterOptions: + passkeysRegisterOptions ?? this.passkeysRegisterOptions, + ); +} + +/// AttestationEnum mapper. +final Map attestationEnumMapper = + { + "none": AttestationEnum.none, + "indirect": AttestationEnum.indirect, + "direct": AttestationEnum.direct, +}; + +/// Attestation Enum. +enum AttestationEnum { + /// none. + none, + + /// indirect. + indirect, + + /// direct. + direct, +} + +/// AuthenticatorAttachmentEnum mapper. +final Map + authenticatorAttachmentEnumMapper = { + "platform": AuthenticatorAttachmentEnum.platform, + "cross-platform": AuthenticatorAttachmentEnum.crossPlatform, +}; + +/// AuthenticatorAttachment Enum. +enum AuthenticatorAttachmentEnum { + /// platform. + platform, + + /// cross-platform. + crossPlatform, +} + +/// UserVerificationEnum mapper. +final Map userVerificationEnumMapper = + { + "required": UserVerificationEnum.required, + "preferred": UserVerificationEnum.preferred, + "discouraged": UserVerificationEnum.discouraged, +}; + +/// UserVerification Enum. +enum UserVerificationEnum { + /// required. + required, + + /// preferred. + preferred, + + /// discouraged. + discouraged, +} + +/// ResidentKeyEnum mapper. +final Map residentKeyEnumMapper = + { + "required": ResidentKeyEnum.required, + "preferred": ResidentKeyEnum.preferred, + "discouraged": ResidentKeyEnum.discouraged, +}; + +/// ResidentKey Enum. +enum ResidentKeyEnum { + /// required. + required, + + /// preferred. + preferred, + + /// discouraged. + discouraged, +} + +/// TransportsItemEnum mapper. +final Map transportsItemEnumMapper = + { + "usb": TransportsItemEnum.usb, + "nfc": TransportsItemEnum.nfc, + "ble": TransportsItemEnum.ble, + "internal": TransportsItemEnum.internal, +}; + +/// TransportsItem Enum. +enum TransportsItemEnum { + /// usb. + usb, + + /// nfc. + nfc, + + /// ble. + ble, + + /// internal. + internal, +} + +/// TypeEnum mapper. +final Map typeEnumMapper = { + "public-key": TypeEnum.publicKey, +}; + +/// Type Enum. +enum TypeEnum { + /// public-key. + publicKey, +} + +/// Passkeys register options model class. +abstract class PasskeysRegisterOptionsModel { + /// Initializes Passkeys register options model class . + const PasskeysRegisterOptionsModel({ + this.publicKey, + }); + + /// Wrapper of the options. + final PublicKey? publicKey; +} + +/// Passkeys register options class. +class PasskeysRegisterOptions extends PasskeysRegisterOptionsModel { + /// Initializes Passkeys register options class. + const PasskeysRegisterOptions({ + super.publicKey, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterOptions.fromJson(Map json) => + PasskeysRegisterOptions( + publicKey: json['publicKey'] == null + ? null + : PublicKey.fromJson(json['publicKey']), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (publicKey != null) { + resultMap['publicKey'] = publicKey!.toJson(); + } + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PasskeysRegisterOptions copyWith({ + PublicKey? publicKey, + }) => + PasskeysRegisterOptions( + publicKey: publicKey ?? this.publicKey, + ); +} + +/// Public key model class. +abstract class PublicKeyModel { + /// Initializes Public key model class . + const PublicKeyModel({ + this.attestation, + this.authenticatorSelection, + this.challenge, + this.excludeCredentials, + this.extensions, + this.pubKeyCredParams, + this.rp, + this.timeout, + this.user, + }); + + /// The attestation settings, weather the authenticator will attest the respone on no. Default is none. + final AttestationEnum? attestation; + + /// Settings to control authenticator behavior and selection. + final AuthenticatorSelection? authenticatorSelection; + + /// Random string to be signed by the authenticator. will be byte array base64 encoded. + final String? challenge; + + /// List of already registered credentials to avoid re-registering. + final List? excludeCredentials; + + /// Empty for now + final Extensions? extensions; + + /// Supported public key algorithms. + final List? pubKeyCredParams; + + /// The relying party info. + final Rp? rp; + + /// Time before expiring the cermony in milliseconds. + final DateTime? timeout; + + /// The user info + final User? user; +} + +/// Public key class. +class PublicKey extends PublicKeyModel { + /// Initializes Public key class. + const PublicKey({ + super.attestation, + super.authenticatorSelection, + super.challenge, + super.excludeCredentials, + super.extensions, + super.pubKeyCredParams, + super.rp, + super.timeout, + super.user, + }); + + /// Creates an instance from JSON. + factory PublicKey.fromJson(Map json) => PublicKey( + attestation: json['attestation'] == null + ? null + : attestationEnumMapper[json['attestation']], + authenticatorSelection: json['authenticatorSelection'] == null + ? null + : AuthenticatorSelection.fromJson(json['authenticatorSelection']), + challenge: json['challenge'], + excludeCredentials: json['excludeCredentials'] == null + ? null + : List.from( + json['excludeCredentials']?.map( + (dynamic item) => ExcludeCredentialsItem.fromJson(item), + ), + ), + extensions: json['extensions'] == null + ? null + : Extensions.fromJson(json['extensions']), + pubKeyCredParams: json['pubKeyCredParams'] == null + ? null + : List.from( + json['pubKeyCredParams']?.map( + (dynamic item) => PubKeyCredParamsItem.fromJson(item), + ), + ), + rp: json['rp'] == null ? null : Rp.fromJson(json['rp']), + timeout: getDateTime(json['timeout']), + user: json['user'] == null ? null : User.fromJson(json['user']), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['attestation'] = attestationEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == attestation) + .key; + if (authenticatorSelection != null) { + resultMap['authenticatorSelection'] = authenticatorSelection!.toJson(); + } + resultMap['challenge'] = challenge; + if (excludeCredentials != null) { + resultMap['excludeCredentials'] = excludeCredentials! + .map( + (ExcludeCredentialsItem item) => item.toJson(), + ) + .toList(); + } + if (extensions != null) { + resultMap['extensions'] = extensions!.toJson(); + } + if (pubKeyCredParams != null) { + resultMap['pubKeyCredParams'] = pubKeyCredParams! + .map( + (PubKeyCredParamsItem item) => item.toJson(), + ) + .toList(); + } + if (rp != null) { + resultMap['rp'] = rp!.toJson(); + } + resultMap['timeout'] = getSecondsSinceEpochDateTime(timeout); + if (user != null) { + resultMap['user'] = user!.toJson(); + } + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PublicKey copyWith({ + AttestationEnum? attestation, + AuthenticatorSelection? authenticatorSelection, + String? challenge, + List? excludeCredentials, + Extensions? extensions, + List? pubKeyCredParams, + Rp? rp, + DateTime? timeout, + User? user, + }) => + PublicKey( + attestation: attestation ?? this.attestation, + authenticatorSelection: + authenticatorSelection ?? this.authenticatorSelection, + challenge: challenge ?? this.challenge, + excludeCredentials: excludeCredentials ?? this.excludeCredentials, + extensions: extensions ?? this.extensions, + pubKeyCredParams: pubKeyCredParams ?? this.pubKeyCredParams, + rp: rp ?? this.rp, + timeout: timeout ?? this.timeout, + user: user ?? this.user, + ); +} + +/// Authenticator selection model class. +abstract class AuthenticatorSelectionModel { + /// Initializes Authenticator selection model class . + const AuthenticatorSelectionModel({ + this.authenticatorAttachment, + this.requireResidentKey, + this.userVerification, + this.residentKey, + }); + + /// Weather to allow cross platform authenticators (QR) or only the ones installed on the device itself. + final AuthenticatorAttachmentEnum? authenticatorAttachment; + + /// Ask the auth to save the passkey on the device. this will allow seamless login without the need to enter the user name. will be true always + final bool? requireResidentKey; + + /// Ask the user to enter thier authentication method (PIN, fingerprint, etc). Default is required. + final UserVerificationEnum? userVerification; + + /// L2 related to requireResidentKey, will be required + final ResidentKeyEnum? residentKey; +} + +/// Authenticator selection class. +class AuthenticatorSelection extends AuthenticatorSelectionModel { + /// Initializes Authenticator selection class. + const AuthenticatorSelection({ + super.authenticatorAttachment, + super.requireResidentKey, + super.userVerification, + super.residentKey, + }); + + /// Creates an instance from JSON. + factory AuthenticatorSelection.fromJson(Map json) => + AuthenticatorSelection( + authenticatorAttachment: json['authenticatorAttachment'] == null + ? null + : authenticatorAttachmentEnumMapper[ + json['authenticatorAttachment']], + requireResidentKey: getBool(json['requireResidentKey']), + userVerification: json['userVerification'] == null + ? null + : userVerificationEnumMapper[json['userVerification']], + residentKey: json['residentKey'] == null + ? null + : residentKeyEnumMapper[json['residentKey']], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['authenticatorAttachment'] = authenticatorAttachmentEnumMapper + .entries + .firstWhere((MapEntry entry) => + entry.value == authenticatorAttachment) + .key; + resultMap['requireResidentKey'] = requireResidentKey; + resultMap['userVerification'] = userVerificationEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == userVerification) + .key; + resultMap['residentKey'] = residentKeyEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == residentKey) + .key; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + AuthenticatorSelection copyWith({ + AuthenticatorAttachmentEnum? authenticatorAttachment, + bool? requireResidentKey, + UserVerificationEnum? userVerification, + ResidentKeyEnum? residentKey, + }) => + AuthenticatorSelection( + authenticatorAttachment: + authenticatorAttachment ?? this.authenticatorAttachment, + requireResidentKey: requireResidentKey ?? this.requireResidentKey, + userVerification: userVerification ?? this.userVerification, + residentKey: residentKey ?? this.residentKey, + ); +} + +/// Exclude credentials item model class. +abstract class ExcludeCredentialsItemModel { + /// Initializes Exclude credentials item model class . + const ExcludeCredentialsItemModel({ + this.id, + this.transports, + this.type, + }); + + /// The credential id. base64 encoded. + final String? id; + + /// The transports supported by the authenticator. + final List? transports; + + /// Will be always public-key. + final TypeEnum? type; +} + +/// Exclude credentials item class. +class ExcludeCredentialsItem extends ExcludeCredentialsItemModel { + /// Initializes Exclude credentials item class. + const ExcludeCredentialsItem({ + super.id, + super.transports, + super.type, + }); + + /// Creates an instance from JSON. + factory ExcludeCredentialsItem.fromJson(Map json) => + ExcludeCredentialsItem( + id: json['id'], + transports: json['transports'] == null + ? null + : List.from( + json['transports']?.map( + (dynamic item) => + item == null ? null : transportsItemEnumMapper[item], + ), + ), + type: json['type'] == null ? null : typeEnumMapper[json['type']], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['id'] = id; + if (transports != null) { + resultMap['transports'] = transports! + .map( + (TransportsItemEnum item) => transportsItemEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == item) + .key, + ) + .toList(); + } + resultMap['type'] = typeEnumMapper.entries + .firstWhere((MapEntry entry) => entry.value == type) + .key; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + ExcludeCredentialsItem copyWith({ + String? id, + List? transports, + TypeEnum? type, + }) => + ExcludeCredentialsItem( + id: id ?? this.id, + transports: transports ?? this.transports, + type: type ?? this.type, + ); +} + +/// Extensions model class. +abstract class ExtensionsModel { + /// Initializes Extensions model class . + const ExtensionsModel({ + this.exts, + this.loc, + this.txAuthGeneric, + this.txAuthSimple, + this.uvi, + }); + + /// The exts. + final bool? exts; + + /// The loc. + final bool? loc; + + /// The txAuthGeneric. + final TxAuthGeneric? txAuthGeneric; + + /// The txAuthSimple. + final String? txAuthSimple; + + /// The uvi. + final bool? uvi; +} + +/// Extensions class. +class Extensions extends ExtensionsModel { + /// Initializes Extensions class. + const Extensions({ + super.exts, + super.loc, + super.txAuthGeneric, + super.txAuthSimple, + super.uvi, + }); + + /// Creates an instance from JSON. + factory Extensions.fromJson(Map json) => Extensions( + exts: getBool(json['exts']), + loc: getBool(json['loc']), + txAuthGeneric: json['txAuthGeneric'] == null + ? null + : TxAuthGeneric.fromJson(json['txAuthGeneric']), + txAuthSimple: json['txAuthSimple'], + uvi: getBool(json['uvi']), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['exts'] = exts; + resultMap['loc'] = loc; + if (txAuthGeneric != null) { + resultMap['txAuthGeneric'] = txAuthGeneric!.toJson(); + } + resultMap['txAuthSimple'] = txAuthSimple; + resultMap['uvi'] = uvi; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + Extensions copyWith({ + bool? exts, + bool? loc, + TxAuthGeneric? txAuthGeneric, + String? txAuthSimple, + bool? uvi, + }) => + Extensions( + exts: exts ?? this.exts, + loc: loc ?? this.loc, + txAuthGeneric: txAuthGeneric ?? this.txAuthGeneric, + txAuthSimple: txAuthSimple ?? this.txAuthSimple, + uvi: uvi ?? this.uvi, + ); +} + +/// Tx auth generic model class. +abstract class TxAuthGenericModel { + /// Initializes Tx auth generic model class . + const TxAuthGenericModel({ + this.content, + this.contentType, + }); + + /// The content. + final String? content; + + /// The contentType. + final String? contentType; +} + +/// Tx auth generic class. +class TxAuthGeneric extends TxAuthGenericModel { + /// Initializes Tx auth generic class. + const TxAuthGeneric({ + super.content, + super.contentType, + }); + + /// Creates an instance from JSON. + factory TxAuthGeneric.fromJson(Map json) => TxAuthGeneric( + content: json['content'], + contentType: json['contentType'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['content'] = content; + resultMap['contentType'] = contentType; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + TxAuthGeneric copyWith({ + String? content, + String? contentType, + }) => + TxAuthGeneric( + content: content ?? this.content, + contentType: contentType ?? this.contentType, + ); +} + +/// Pub key cred params item model class. +abstract class PubKeyCredParamsItemModel { + /// Initializes Pub key cred params item model class . + const PubKeyCredParamsItemModel({ + this.alg, + this.type, + }); + + /// Algorithm + final String? alg; + + /// Type + final String? type; +} + +/// Pub key cred params item class. +class PubKeyCredParamsItem extends PubKeyCredParamsItemModel { + /// Initializes Pub key cred params item class. + const PubKeyCredParamsItem({ + super.alg, + super.type, + }); + + /// Creates an instance from JSON. + factory PubKeyCredParamsItem.fromJson(Map json) => + PubKeyCredParamsItem( + alg: json['alg'], + type: json['type'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['alg'] = alg; + resultMap['type'] = type; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PubKeyCredParamsItem copyWith({ + String? alg, + String? type, + }) => + PubKeyCredParamsItem( + alg: alg ?? this.alg, + type: type ?? this.type, + ); +} + +/// Rp model class. +abstract class RpModel { + /// Initializes Rp model class . + const RpModel({ + this.id, + this.name, + }); + + /// Relying party id. + final String? id; + + /// Relying party name. + final String? name; +} + +/// Rp class. +class Rp extends RpModel { + /// Initializes Rp class. + const Rp({ + super.id, + super.name, + }); + + /// Creates an instance from JSON. + factory Rp.fromJson(Map json) => Rp( + id: json['id'], + name: json['name'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['id'] = id; + resultMap['name'] = name; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + Rp copyWith({ + String? id, + String? name, + }) => + Rp( + id: id ?? this.id, + name: name ?? this.name, + ); +} + +/// User model class. +abstract class UserModel { + /// Initializes User model class . + const UserModel({ + this.displayName, + this.id, + this.name, + }); + + /// Display name of the user. will be email + final String? displayName; + + /// Binary user id + final String? id; + + /// Name of the user, will be email + final String? name; +} + +/// User class. +class User extends UserModel { + /// Initializes User class. + const User({ + super.displayName, + super.id, + super.name, + }); + + /// Creates an instance from JSON. + factory User.fromJson(Map json) => User( + displayName: json['displayName'], + id: json['id'], + name: json['name'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['displayName'] = displayName; + resultMap['id'] = id; + resultMap['name'] = name; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + User copyWith({ + String? displayName, + String? id, + String? name, + }) => + User( + displayName: displayName ?? this.displayName, + id: id ?? this.id, + name: name ?? this.name, + ); +} diff --git a/lib/api/response/passkeys_register_response_result.dart b/lib/api/response/passkeys_register_response_result.dart new file mode 100644 index 0000000000..d7df0d7f1f --- /dev/null +++ b/lib/api/response/passkeys_register_response_result.dart @@ -0,0 +1,172 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_register_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_register_send.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Passkeys register response model class. +abstract class PasskeysRegisterResponseModel { + /// Initializes Passkeys register response model class . + const PasskeysRegisterResponseModel({ + this.passkeysRegister, + }); + + /// Wrapper of the response. + final PasskeysRegister? passkeysRegister; +} + +/// Passkeys register response class. +class PasskeysRegisterResponse extends PasskeysRegisterResponseModel { + /// Initializes Passkeys register response class. + const PasskeysRegisterResponse({ + super.passkeysRegister, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterResponse.fromJson( + dynamic passkeysRegisterJson, + ) => + PasskeysRegisterResponse( + passkeysRegister: passkeysRegisterJson == null + ? null + : PasskeysRegister.fromJson(passkeysRegisterJson), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (passkeysRegister != null) { + resultMap['passkeys_register'] = passkeysRegister!.toJson(); + } + + return resultMap; + } + + static final BaseAPI _api = Injector()(); + + /// register a new passkey. + static Future fetch( + PasskeysRegisterRequest request, + ) async { + final PasskeysRegisterReceive response = await fetchRaw(request); + + return PasskeysRegisterResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys register response. + static Future fetchRaw( + PasskeysRegisterRequest request, + ) async { + final PasskeysRegisterReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } + + /// Creates a copy of instance with given parameters. + PasskeysRegisterResponse copyWith({ + PasskeysRegister? passkeysRegister, + }) => + PasskeysRegisterResponse( + passkeysRegister: passkeysRegister ?? this.passkeysRegister, + ); +} + +/// Passkeys register model class. +abstract class PasskeysRegisterModel { + /// Initializes Passkeys register model class . + const PasskeysRegisterModel({ + this.createdOn, + this.id, + this.lastUsed, + this.name, + this.passkey, + this.userId, + }); + + /// The date of the passkey creation + final String? createdOn; + + /// The system id of the passkey + final String? id; + + /// The date of the last passkey usage + final String? lastUsed; + + /// The name of the passkey + final String? name; + + /// The id of the credential. for mock only + final Map? passkey; + + /// The id of the user. for mock only + final String? userId; +} + +/// Passkeys register class. +class PasskeysRegister extends PasskeysRegisterModel { + /// Initializes Passkeys register class. + const PasskeysRegister({ + super.createdOn, + super.id, + super.lastUsed, + super.name, + super.passkey, + super.userId, + }); + + /// Creates an instance from JSON. + factory PasskeysRegister.fromJson(Map json) => + PasskeysRegister( + createdOn: json['created_on'], + id: json['id'], + lastUsed: json['last_used'], + name: json['name'], + passkey: json['passkey'], + userId: json['user_id'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['created_on'] = createdOn; + resultMap['id'] = id; + resultMap['last_used'] = lastUsed; + resultMap['name'] = name; + resultMap['passkey'] = passkey; + resultMap['user_id'] = userId; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PasskeysRegister copyWith({ + String? createdOn, + String? id, + String? lastUsed, + String? name, + Map? passkey, + String? userId, + }) => + PasskeysRegister( + createdOn: createdOn ?? this.createdOn, + id: id ?? this.id, + lastUsed: lastUsed ?? this.lastUsed, + name: name ?? this.name, + passkey: passkey ?? this.passkey, + userId: userId ?? this.userId, + ); +} diff --git a/lib/api/response/passkeys_rename_response_result.dart b/lib/api/response/passkeys_rename_response_result.dart new file mode 100644 index 0000000000..940c57266c --- /dev/null +++ b/lib/api/response/passkeys_rename_response_result.dart @@ -0,0 +1,81 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_rename_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_rename_send.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Passkeys rename response model class. +abstract class PasskeysRenameResponseModel { + /// Initializes Passkeys rename response model class . + const PasskeysRenameResponseModel({ + this.passkeysRename, + }); + + /// 1 on success + final int? passkeysRename; +} + +/// Passkeys rename response class. +class PasskeysRenameResponse extends PasskeysRenameResponseModel { + /// Initializes Passkeys rename response class. + const PasskeysRenameResponse({ + super.passkeysRename, + }); + + /// Creates an instance from JSON. + factory PasskeysRenameResponse.fromJson( + dynamic passkeysRenameJson, + ) => + PasskeysRenameResponse( + passkeysRename: passkeysRenameJson, + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['passkeys_rename'] = passkeysRename; + + return resultMap; + } + + static final BaseAPI _api = Injector()(); + + /// rename a passkey. + static Future fetch( + PasskeysRenameRequest request, + ) async { + final PasskeysRenameReceive response = await fetchRaw(request); + + return PasskeysRenameResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys rename response. + static Future fetchRaw( + PasskeysRenameRequest request, + ) async { + final PasskeysRenameReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } + + /// Creates a copy of instance with given parameters. + PasskeysRenameResponse copyWith({ + int? passkeysRename, + }) => + PasskeysRenameResponse( + passkeysRename: passkeysRename ?? this.passkeysRename, + ); +} diff --git a/lib/api/response/passkeys_revoke_response_result.dart b/lib/api/response/passkeys_revoke_response_result.dart new file mode 100644 index 0000000000..edc2576ada --- /dev/null +++ b/lib/api/response/passkeys_revoke_response_result.dart @@ -0,0 +1,81 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_revoke_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/passkeys_revoke_send.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Passkeys revoke response model class. +abstract class PasskeysRevokeResponseModel { + /// Initializes Passkeys revoke response model class . + const PasskeysRevokeResponseModel({ + this.passkeysRevoke, + }); + + /// 1 on success + final int? passkeysRevoke; +} + +/// Passkeys revoke response class. +class PasskeysRevokeResponse extends PasskeysRevokeResponseModel { + /// Initializes Passkeys revoke response class. + const PasskeysRevokeResponse({ + super.passkeysRevoke, + }); + + /// Creates an instance from JSON. + factory PasskeysRevokeResponse.fromJson( + dynamic passkeysRevokeJson, + ) => + PasskeysRevokeResponse( + passkeysRevoke: passkeysRevokeJson, + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['passkeys_revoke'] = passkeysRevoke; + + return resultMap; + } + + static final BaseAPI _api = Injector()(); + + /// revoke a passkey. + static Future fetch( + PasskeysRevokeRequest request, + ) async { + final PasskeysRevokeReceive response = await fetchRaw(request); + + return PasskeysRevokeResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys revoke response. + static Future fetchRaw( + PasskeysRevokeRequest request, + ) async { + final PasskeysRevokeReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } + + /// Creates a copy of instance with given parameters. + PasskeysRevokeResponse copyWith({ + int? passkeysRevoke, + }) => + PasskeysRevokeResponse( + passkeysRevoke: passkeysRevoke ?? this.passkeysRevoke, + ); +} From 64abb0fd0cbdccfb18015e854d2de5e109b039f2 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 21 Feb 2024 14:52:13 +0400 Subject: [PATCH 02/11] feat(passkeys): added passkeys api calls and json objects --- lib/basic_api/generated/api.dart | 38 ++++++++- .../passkeys_list_receive_methods.json | 4 + .../passkeys_options_receive_methods.json | 4 + ...keys_register_options_receive_methods.json | 4 + .../passkeys_register_receive_methods.json | 4 + .../passkeys_rename_receive_methods.json | 4 + .../passkeys_revoke_receive_methods.json | 4 + .../generated/passkeys_list_receive.dart | 64 ++++++++++++++ .../generated/passkeys_list_send.dart | 65 +++++++++++++++ .../generated/passkeys_options_receive.dart | 61 ++++++++++++++ .../generated/passkeys_options_send.dart | 74 +++++++++++++++++ .../passkeys_register_options_receive.dart | 63 ++++++++++++++ .../passkeys_register_options_send.dart | 67 +++++++++++++++ .../generated/passkeys_register_receive.dart | 61 ++++++++++++++ .../generated/passkeys_register_send.dart | 83 +++++++++++++++++++ .../generated/passkeys_rename_receive.dart | 61 ++++++++++++++ .../generated/passkeys_rename_send.dart | 82 ++++++++++++++++++ .../generated/passkeys_revoke_receive.dart | 61 ++++++++++++++ .../generated/passkeys_revoke_send.dart | 83 +++++++++++++++++++ .../helper/response_mapper.helper.dart | 19 +++++ 20 files changed, 904 insertions(+), 2 deletions(-) create mode 100644 lib/basic_api/generated/methods/passkeys_list_receive_methods.json create mode 100644 lib/basic_api/generated/methods/passkeys_options_receive_methods.json create mode 100644 lib/basic_api/generated/methods/passkeys_register_options_receive_methods.json create mode 100644 lib/basic_api/generated/methods/passkeys_register_receive_methods.json create mode 100644 lib/basic_api/generated/methods/passkeys_rename_receive_methods.json create mode 100644 lib/basic_api/generated/methods/passkeys_revoke_receive_methods.json create mode 100644 lib/basic_api/generated/passkeys_list_receive.dart create mode 100644 lib/basic_api/generated/passkeys_list_send.dart create mode 100644 lib/basic_api/generated/passkeys_options_receive.dart create mode 100644 lib/basic_api/generated/passkeys_options_send.dart create mode 100644 lib/basic_api/generated/passkeys_register_options_receive.dart create mode 100644 lib/basic_api/generated/passkeys_register_options_send.dart create mode 100644 lib/basic_api/generated/passkeys_register_receive.dart create mode 100644 lib/basic_api/generated/passkeys_register_send.dart create mode 100644 lib/basic_api/generated/passkeys_rename_receive.dart create mode 100644 lib/basic_api/generated/passkeys_rename_send.dart create mode 100644 lib/basic_api/generated/passkeys_revoke_receive.dart create mode 100644 lib/basic_api/generated/passkeys_revoke_send.dart diff --git a/lib/basic_api/generated/api.dart b/lib/basic_api/generated/api.dart index a9c4d1911a..cddb4987ef 100644 --- a/lib/basic_api/generated/api.dart +++ b/lib/basic_api/generated/api.dart @@ -1,13 +1,19 @@ export "account_closure_receive.dart"; export "account_closure_send.dart"; +export "account_list_receive.dart"; +export "account_list_send.dart"; export "account_security_receive.dart"; export "account_security_send.dart"; export "account_statistics_receive.dart"; export "account_statistics_send.dart"; export "active_symbols_receive.dart"; export "active_symbols_send.dart"; -export "affiliate_account_add_receive.dart"; -export "affiliate_account_add_send.dart"; +export "affiliate_add_company_receive.dart"; +export "affiliate_add_company_send.dart"; +export "affiliate_add_person_receive.dart"; +export "affiliate_add_person_send.dart"; +export "affiliate_register_person_receive.dart"; +export "affiliate_register_person_send.dart"; export "api_token_receive.dart"; export "api_token_send.dart"; export "app_delete_receive.dart"; @@ -28,6 +34,8 @@ export "asset_index_receive.dart"; export "asset_index_send.dart"; export "authorize_receive.dart"; export "authorize_send.dart"; +export "available_accounts_receive.dart"; +export "available_accounts_send.dart"; export "balance_receive.dart"; export "balance_send.dart"; export "buy_contract_for_multiple_accounts_receive.dart"; @@ -62,6 +70,8 @@ export "copytrading_statistics_receive.dart"; export "copytrading_statistics_send.dart"; export "crypto_config_receive.dart"; export "crypto_config_send.dart"; +export "crypto_estimations_receive.dart"; +export "crypto_estimations_send.dart"; export "document_upload_receive.dart"; export "document_upload_send.dart"; export "economic_calendar_receive.dart"; @@ -88,6 +98,8 @@ export "get_settings_receive.dart"; export "get_settings_send.dart"; export "identity_verification_document_add_receive.dart"; export "identity_verification_document_add_send.dart"; +export "kyc_auth_status_receive.dart"; +export "kyc_auth_status_send.dart"; export "landing_company_details_receive.dart"; export "landing_company_details_send.dart"; export "landing_company_receive.dart"; @@ -168,6 +180,20 @@ export "p2p_payment_methods_receive.dart"; export "p2p_payment_methods_send.dart"; export "p2p_ping_receive.dart"; export "p2p_ping_send.dart"; +export "p2p_settings_receive.dart"; +export "p2p_settings_send.dart"; +export "passkeys_list_receive.dart"; +export "passkeys_list_send.dart"; +export "passkeys_options_receive.dart"; +export "passkeys_options_send.dart"; +export "passkeys_register_options_receive.dart"; +export "passkeys_register_options_send.dart"; +export "passkeys_register_receive.dart"; +export "passkeys_register_send.dart"; +export "passkeys_rename_receive.dart"; +export "passkeys_rename_send.dart"; +export "passkeys_revoke_receive.dart"; +export "passkeys_revoke_send.dart"; export "payment_methods_receive.dart"; export "payment_methods_send.dart"; export "paymentagent_create_receive.dart"; @@ -178,6 +204,8 @@ export "paymentagent_list_receive.dart"; export "paymentagent_list_send.dart"; export "paymentagent_transfer_receive.dart"; export "paymentagent_transfer_send.dart"; +export "paymentagent_withdraw_justification_receive.dart"; +export "paymentagent_withdraw_justification_send.dart"; export "paymentagent_withdraw_receive.dart"; export "paymentagent_withdraw_send.dart"; export "payout_currencies_receive.dart"; @@ -236,6 +264,8 @@ export "trading_durations_receive.dart"; export "trading_durations_send.dart"; export "trading_platform_accounts_receive.dart"; export "trading_platform_accounts_send.dart"; +export "trading_platform_asset_listing_receive.dart"; +export "trading_platform_asset_listing_send.dart"; export "trading_platform_available_accounts_receive.dart"; export "trading_platform_available_accounts_send.dart"; export "trading_platform_deposit_receive.dart"; @@ -244,6 +274,8 @@ export "trading_platform_investor_password_change_receive.dart"; export "trading_platform_investor_password_change_send.dart"; export "trading_platform_investor_password_reset_receive.dart"; export "trading_platform_investor_password_reset_send.dart"; +export "trading_platform_leverage_receive.dart"; +export "trading_platform_leverage_send.dart"; export "trading_platform_new_account_receive.dart"; export "trading_platform_new_account_send.dart"; export "trading_platform_password_change_receive.dart"; @@ -268,5 +300,7 @@ export "verify_email_cellxpert_receive.dart"; export "verify_email_cellxpert_send.dart"; export "verify_email_receive.dart"; export "verify_email_send.dart"; +export "wallet_migration_receive.dart"; +export "wallet_migration_send.dart"; export "website_status_receive.dart"; export "website_status_send.dart"; diff --git a/lib/basic_api/generated/methods/passkeys_list_receive_methods.json b/lib/basic_api/generated/methods/passkeys_list_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/passkeys_list_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/methods/passkeys_options_receive_methods.json b/lib/basic_api/generated/methods/passkeys_options_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/passkeys_options_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/methods/passkeys_register_options_receive_methods.json b/lib/basic_api/generated/methods/passkeys_register_options_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/passkeys_register_options_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/methods/passkeys_register_receive_methods.json b/lib/basic_api/generated/methods/passkeys_register_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/passkeys_register_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/methods/passkeys_rename_receive_methods.json b/lib/basic_api/generated/methods/passkeys_rename_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/passkeys_rename_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/methods/passkeys_revoke_receive_methods.json b/lib/basic_api/generated/methods/passkeys_revoke_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/passkeys_revoke_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/passkeys_list_receive.dart b/lib/basic_api/generated/passkeys_list_receive.dart new file mode 100644 index 0000000000..1ecb985e89 --- /dev/null +++ b/lib/basic_api/generated/passkeys_list_receive.dart @@ -0,0 +1,64 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_list_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Passkeys list receive class. +class PasskeysListReceive extends Response { + /// Initialize PasskeysListReceive. + const PasskeysListReceive({ + this.passkeysList, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysListReceive.fromJson(Map json) => + PasskeysListReceive( + passkeysList: (json['passkeys_list'] as List?) + ?.map>( + (dynamic item) => item as Map) + .toList(), + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// The list of passkeys. + final List>? passkeysList; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'passkeys_list': passkeysList, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysListReceive copyWith({ + List>? passkeysList, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + PasskeysListReceive( + passkeysList: passkeysList ?? this.passkeysList, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_list_send.dart b/lib/basic_api/generated/passkeys_list_send.dart new file mode 100644 index 0000000000..73d428574b --- /dev/null +++ b/lib/basic_api/generated/passkeys_list_send.dart @@ -0,0 +1,65 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_list_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Passkeys list request class. +class PasskeysListRequest extends Request { + /// Initialize PasskeysListRequest. + const PasskeysListRequest({ + this.loginid, + this.passkeysList = true, + super.msgType = 'passkeys_list', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysListRequest.fromJson(Map json) => + PasskeysListRequest( + loginid: json['loginid'] as String?, + passkeysList: + json['passkeys_list'] == null ? null : json['passkeys_list'] == 1, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// Must be `true` + final bool? passkeysList; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'loginid': loginid, + 'passkeys_list': passkeysList == null + ? null + : passkeysList! + ? 1 + : 0, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysListRequest copyWith({ + String? loginid, + bool? passkeysList, + Map? passthrough, + int? reqId, + }) => + PasskeysListRequest( + loginid: loginid ?? this.loginid, + passkeysList: passkeysList ?? this.passkeysList, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_options_receive.dart b/lib/basic_api/generated/passkeys_options_receive.dart new file mode 100644 index 0000000000..95f1a7f15b --- /dev/null +++ b/lib/basic_api/generated/passkeys_options_receive.dart @@ -0,0 +1,61 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_options_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Passkeys options receive class. +class PasskeysOptionsReceive extends Response { + /// Initialize PasskeysOptionsReceive. + const PasskeysOptionsReceive({ + this.passkeysOptions, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysOptionsReceive.fromJson(Map json) => + PasskeysOptionsReceive( + passkeysOptions: json['passkeys_options'] as Map?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// Wrapper of the response. + final Map? passkeysOptions; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'passkeys_options': passkeysOptions, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysOptionsReceive copyWith({ + Map? passkeysOptions, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + PasskeysOptionsReceive( + passkeysOptions: passkeysOptions ?? this.passkeysOptions, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_options_send.dart b/lib/basic_api/generated/passkeys_options_send.dart new file mode 100644 index 0000000000..56a06b413d --- /dev/null +++ b/lib/basic_api/generated/passkeys_options_send.dart @@ -0,0 +1,74 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_options_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Passkeys options request class. +class PasskeysOptionsRequest extends Request { + /// Initialize PasskeysOptionsRequest. + const PasskeysOptionsRequest({ + this.loginid, + this.passkeyId, + this.passkeysOptions = true, + super.msgType = 'passkeys_options', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysOptionsRequest.fromJson(Map json) => + PasskeysOptionsRequest( + loginid: json['loginid'] as String?, + passkeyId: json['passkey_id'] as String?, + passkeysOptions: json['passkeys_options'] == null + ? null + : json['passkeys_options'] == 1, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// [Optional] The id of the passkey. If left unspecified, User can use any passkey to authorize. + final String? passkeyId; + + /// Must be `true` + final bool? passkeysOptions; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'loginid': loginid, + 'passkey_id': passkeyId, + 'passkeys_options': passkeysOptions == null + ? null + : passkeysOptions! + ? 1 + : 0, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysOptionsRequest copyWith({ + String? loginid, + String? passkeyId, + bool? passkeysOptions, + Map? passthrough, + int? reqId, + }) => + PasskeysOptionsRequest( + loginid: loginid ?? this.loginid, + passkeyId: passkeyId ?? this.passkeyId, + passkeysOptions: passkeysOptions ?? this.passkeysOptions, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_register_options_receive.dart b/lib/basic_api/generated/passkeys_register_options_receive.dart new file mode 100644 index 0000000000..9c1a6cc1d3 --- /dev/null +++ b/lib/basic_api/generated/passkeys_register_options_receive.dart @@ -0,0 +1,63 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_register_options_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Passkeys register options receive class. +class PasskeysRegisterOptionsReceive extends Response { + /// Initialize PasskeysRegisterOptionsReceive. + const PasskeysRegisterOptionsReceive({ + this.passkeysRegisterOptions, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterOptionsReceive.fromJson(Map json) => + PasskeysRegisterOptionsReceive( + passkeysRegisterOptions: + json['passkeys_register_options'] as Map?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// Wrapper of the response. + final Map? passkeysRegisterOptions; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'passkeys_register_options': passkeysRegisterOptions, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRegisterOptionsReceive copyWith({ + Map? passkeysRegisterOptions, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + PasskeysRegisterOptionsReceive( + passkeysRegisterOptions: + passkeysRegisterOptions ?? this.passkeysRegisterOptions, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_register_options_send.dart b/lib/basic_api/generated/passkeys_register_options_send.dart new file mode 100644 index 0000000000..2ddb9357fc --- /dev/null +++ b/lib/basic_api/generated/passkeys_register_options_send.dart @@ -0,0 +1,67 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_register_options_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Passkeys register options request class. +class PasskeysRegisterOptionsRequest extends Request { + /// Initialize PasskeysRegisterOptionsRequest. + const PasskeysRegisterOptionsRequest({ + this.loginid, + this.passkeysRegisterOptions = true, + super.msgType = 'passkeys_register_options', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterOptionsRequest.fromJson(Map json) => + PasskeysRegisterOptionsRequest( + loginid: json['loginid'] as String?, + passkeysRegisterOptions: json['passkeys_register_options'] == null + ? null + : json['passkeys_register_options'] == 1, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// Must be `true` + final bool? passkeysRegisterOptions; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'loginid': loginid, + 'passkeys_register_options': passkeysRegisterOptions == null + ? null + : passkeysRegisterOptions! + ? 1 + : 0, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRegisterOptionsRequest copyWith({ + String? loginid, + bool? passkeysRegisterOptions, + Map? passthrough, + int? reqId, + }) => + PasskeysRegisterOptionsRequest( + loginid: loginid ?? this.loginid, + passkeysRegisterOptions: + passkeysRegisterOptions ?? this.passkeysRegisterOptions, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_register_receive.dart b/lib/basic_api/generated/passkeys_register_receive.dart new file mode 100644 index 0000000000..59adf0d2d4 --- /dev/null +++ b/lib/basic_api/generated/passkeys_register_receive.dart @@ -0,0 +1,61 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_register_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Passkeys register receive class. +class PasskeysRegisterReceive extends Response { + /// Initialize PasskeysRegisterReceive. + const PasskeysRegisterReceive({ + this.passkeysRegister, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterReceive.fromJson(Map json) => + PasskeysRegisterReceive( + passkeysRegister: json['passkeys_register'] as Map?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// Wrapper of the response. + final Map? passkeysRegister; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'passkeys_register': passkeysRegister, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRegisterReceive copyWith({ + Map? passkeysRegister, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + PasskeysRegisterReceive( + passkeysRegister: passkeysRegister ?? this.passkeysRegister, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_register_send.dart b/lib/basic_api/generated/passkeys_register_send.dart new file mode 100644 index 0000000000..ec996a7b2b --- /dev/null +++ b/lib/basic_api/generated/passkeys_register_send.dart @@ -0,0 +1,83 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_register_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Passkeys register request class. +class PasskeysRegisterRequest extends Request { + /// Initialize PasskeysRegisterRequest. + const PasskeysRegisterRequest({ + this.loginid, + required this.name, + this.passkeysRegister = true, + required this.publicKeyCredential, + super.msgType = 'passkeys_register', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRegisterRequest.fromJson(Map json) => + PasskeysRegisterRequest( + loginid: json['loginid'] as String?, + name: json['name'] as String?, + passkeysRegister: json['passkeys_register'] == null + ? null + : json['passkeys_register'] == 1, + publicKeyCredential: + json['publicKeyCredential'] as Map?, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// The name of the passkey. + final String? name; + + /// Must be `true` + final bool? passkeysRegister; + + /// The public key credential returned from the authenticator. + final Map? publicKeyCredential; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'loginid': loginid, + 'name': name, + 'passkeys_register': passkeysRegister == null + ? null + : passkeysRegister! + ? 1 + : 0, + 'publicKeyCredential': publicKeyCredential, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRegisterRequest copyWith({ + String? loginid, + String? name, + bool? passkeysRegister, + Map? publicKeyCredential, + Map? passthrough, + int? reqId, + }) => + PasskeysRegisterRequest( + loginid: loginid ?? this.loginid, + name: name ?? this.name, + passkeysRegister: passkeysRegister ?? this.passkeysRegister, + publicKeyCredential: publicKeyCredential ?? this.publicKeyCredential, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_rename_receive.dart b/lib/basic_api/generated/passkeys_rename_receive.dart new file mode 100644 index 0000000000..b17d4051f0 --- /dev/null +++ b/lib/basic_api/generated/passkeys_rename_receive.dart @@ -0,0 +1,61 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_rename_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Passkeys rename receive class. +class PasskeysRenameReceive extends Response { + /// Initialize PasskeysRenameReceive. + const PasskeysRenameReceive({ + this.passkeysRename, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRenameReceive.fromJson(Map json) => + PasskeysRenameReceive( + passkeysRename: json['passkeys_rename'] as int?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// 1 on success + final int? passkeysRename; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'passkeys_rename': passkeysRename, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRenameReceive copyWith({ + int? passkeysRename, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + PasskeysRenameReceive( + passkeysRename: passkeysRename ?? this.passkeysRename, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_rename_send.dart b/lib/basic_api/generated/passkeys_rename_send.dart new file mode 100644 index 0000000000..e3e464203c --- /dev/null +++ b/lib/basic_api/generated/passkeys_rename_send.dart @@ -0,0 +1,82 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_rename_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Passkeys rename request class. +class PasskeysRenameRequest extends Request { + /// Initialize PasskeysRenameRequest. + const PasskeysRenameRequest({ + required this.id, + this.loginid, + required this.name, + this.passkeysRename = true, + super.msgType = 'passkeys_rename', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRenameRequest.fromJson(Map json) => + PasskeysRenameRequest( + id: json['id'] as int?, + loginid: json['loginid'] as String?, + name: json['name'] as String?, + passkeysRename: json['passkeys_rename'] == null + ? null + : json['passkeys_rename'] == 1, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// The id of the passkey to rename. + final int? id; + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// The new name of the passkey. + final String? name; + + /// Must be `true` + final bool? passkeysRename; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'id': id, + 'loginid': loginid, + 'name': name, + 'passkeys_rename': passkeysRename == null + ? null + : passkeysRename! + ? 1 + : 0, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRenameRequest copyWith({ + int? id, + String? loginid, + String? name, + bool? passkeysRename, + Map? passthrough, + int? reqId, + }) => + PasskeysRenameRequest( + id: id ?? this.id, + loginid: loginid ?? this.loginid, + name: name ?? this.name, + passkeysRename: passkeysRename ?? this.passkeysRename, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_revoke_receive.dart b/lib/basic_api/generated/passkeys_revoke_receive.dart new file mode 100644 index 0000000000..1b268a9654 --- /dev/null +++ b/lib/basic_api/generated/passkeys_revoke_receive.dart @@ -0,0 +1,61 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_revoke_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Passkeys revoke receive class. +class PasskeysRevokeReceive extends Response { + /// Initialize PasskeysRevokeReceive. + const PasskeysRevokeReceive({ + this.passkeysRevoke, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRevokeReceive.fromJson(Map json) => + PasskeysRevokeReceive( + passkeysRevoke: json['passkeys_revoke'] as int?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// 1 on success + final int? passkeysRevoke; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'passkeys_revoke': passkeysRevoke, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRevokeReceive copyWith({ + int? passkeysRevoke, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + PasskeysRevokeReceive( + passkeysRevoke: passkeysRevoke ?? this.passkeysRevoke, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/passkeys_revoke_send.dart b/lib/basic_api/generated/passkeys_revoke_send.dart new file mode 100644 index 0000000000..ebbac29e9b --- /dev/null +++ b/lib/basic_api/generated/passkeys_revoke_send.dart @@ -0,0 +1,83 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/passkeys_revoke_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Passkeys revoke request class. +class PasskeysRevokeRequest extends Request { + /// Initialize PasskeysRevokeRequest. + const PasskeysRevokeRequest({ + required this.id, + this.loginid, + this.passkeysRevoke = true, + required this.publicKeyCredential, + super.msgType = 'passkeys_revoke', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory PasskeysRevokeRequest.fromJson(Map json) => + PasskeysRevokeRequest( + id: json['id'] as int?, + loginid: json['loginid'] as String?, + passkeysRevoke: json['passkeys_revoke'] == null + ? null + : json['passkeys_revoke'] == 1, + publicKeyCredential: + json['publicKeyCredential'] as Map?, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// The system id of the passkey. + final int? id; + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// Must be `true` + final bool? passkeysRevoke; + + /// The public key credential returned from the authenticator. + final Map? publicKeyCredential; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'id': id, + 'loginid': loginid, + 'passkeys_revoke': passkeysRevoke == null + ? null + : passkeysRevoke! + ? 1 + : 0, + 'publicKeyCredential': publicKeyCredential, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + PasskeysRevokeRequest copyWith({ + int? id, + String? loginid, + bool? passkeysRevoke, + Map? publicKeyCredential, + Map? passthrough, + int? reqId, + }) => + PasskeysRevokeRequest( + id: id ?? this.id, + loginid: loginid ?? this.loginid, + passkeysRevoke: passkeysRevoke ?? this.passkeysRevoke, + publicKeyCredential: publicKeyCredential ?? this.publicKeyCredential, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/helper/response_mapper.helper.dart b/lib/basic_api/helper/response_mapper.helper.dart index 75e71d1dc3..b4633bc979 100644 --- a/lib/basic_api/helper/response_mapper.helper.dart +++ b/lib/basic_api/helper/response_mapper.helper.dart @@ -140,6 +140,12 @@ import '../generated/verify_email_cellxpert_receive.dart'; import '../generated/verify_email_receive.dart'; import '../generated/wallet_migration_receive.dart'; import '../generated/website_status_receive.dart'; +import '../generated/passkeys_list_receive.dart'; +import '../generated/passkeys_options_receive.dart'; +import '../generated/passkeys_register_options_receive.dart'; +import '../generated/passkeys_register_receive.dart'; +import '../generated/passkeys_rename_receive.dart'; +import '../generated/passkeys_revoke_receive.dart'; import '../response.dart'; /// A function that create a sub-type of [Response] based on @@ -420,6 +426,19 @@ Response getGeneratedResponse(Map responseMap) { return WalletMigrationReceive.fromJson(responseMap); case 'website_status': return WebsiteStatusReceive.fromJson(responseMap); + case 'passkeys_list': + return PasskeysListReceive.fromJson(responseMap); + + case 'passkeys_options': + return PasskeysOptionsReceive.fromJson(responseMap); + case 'passkeys_register_options': + return PasskeysRegisterOptionsReceive.fromJson(responseMap); + case 'passkeys_register': + return PasskeysRegisterReceive.fromJson(responseMap); + case 'passkeys_rename': + return PasskeysRenameReceive.fromJson(responseMap); + case 'passkeys_revoke': + return PasskeysRevokeReceive.fromJson(responseMap); default: return Response.fromJson(responseMap); From 82ddc3e22ca6ac85a6c7ff4bac082a1574a90c93 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Tue, 27 Feb 2024 18:24:33 +0400 Subject: [PATCH 03/11] refactor: fix wrong imports --- lib/api/response/p2p_advert_create_response_result.dart | 6 +++++- lib/api/response/p2p_advert_list_response_result.dart | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/api/response/p2p_advert_create_response_result.dart b/lib/api/response/p2p_advert_create_response_result.dart index cae00b3e42..1467f21aac 100644 --- a/lib/api/response/p2p_advert_create_response_result.dart +++ b/lib/api/response/p2p_advert_create_response_result.dart @@ -1,8 +1,8 @@ // ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; -import 'package:flutter_deriv_api/api/exceptions/p2p_advert_exception.dart'; import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_receive.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_send.dart'; @@ -221,6 +221,7 @@ enum VisibilityStatusItemEnum { /// advertiser_temp_ban. advertiserTempBan, } + /// P2p advert create model class. abstract class P2pAdvertCreateModel { /// Initializes P2p advert create model class . @@ -720,6 +721,7 @@ class P2pAdvertCreate extends P2pAdvertCreateModel { visibilityStatus: visibilityStatus ?? this.visibilityStatus, ); } + /// Advertiser details model class. abstract class AdvertiserDetailsModel { /// Initializes Advertiser details model class . @@ -861,6 +863,7 @@ class AdvertiserDetails extends AdvertiserDetailsModel { totalCompletionRate: totalCompletionRate ?? this.totalCompletionRate, ); } + /// Payment method details property model class. abstract class PaymentMethodDetailsPropertyModel { /// Initializes Payment method details property model class . @@ -989,6 +992,7 @@ class PaymentMethodDetailsProperty extends PaymentMethodDetailsPropertyModel { usedByOrders: usedByOrders ?? this.usedByOrders, ); } + /// Fields property model class. abstract class FieldsPropertyModel { /// Initializes Fields property model class . diff --git a/lib/api/response/p2p_advert_list_response_result.dart b/lib/api/response/p2p_advert_list_response_result.dart index d3dc565671..6000a9a8c5 100644 --- a/lib/api/response/p2p_advert_list_response_result.dart +++ b/lib/api/response/p2p_advert_list_response_result.dart @@ -1,8 +1,8 @@ // ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import import 'package:equatable/equatable.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; -import 'package:flutter_deriv_api/api/exceptions/p2p_advert_exception.dart'; import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_list_receive.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_list_send.dart'; @@ -208,6 +208,7 @@ enum VisibilityStatusItemEnum { /// advertiser_temp_ban. advertiserTempBan, } + /// P2p advert list model class. abstract class P2pAdvertListModel { /// Initializes P2p advert list model class . @@ -256,6 +257,7 @@ class P2pAdvertList extends P2pAdvertListModel { list: list ?? this.list, ); } + /// List item model class. abstract class ListItemModel { /// Initializes List item model class . @@ -784,6 +786,7 @@ class ListItem extends ListItemModel { visibilityStatus: visibilityStatus ?? this.visibilityStatus, ); } + /// Advertiser details model class. abstract class AdvertiserDetailsModel { /// Initializes Advertiser details model class . From a8caea30dd42fcadbe50ad4cdc42cbde0c798c52 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Tue, 12 Mar 2024 09:20:58 +0400 Subject: [PATCH 04/11] revert: reverted .gitmodules to regentmarkets and master branch --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9f0c5d2dc8..cf49523818 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "binary-websocket-api"] path = binary-websocket-api - url = https://github.com/bassam-deriv/binary-websocket-api.git - branch = deriv_passkeys + url = git@github.com:regentmarkets/binary-websocket-api.git + branch = master From 367d63a5431069bf67132ee5196c75b80019e0cf Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:21:04 +0400 Subject: [PATCH 05/11] test(deriv_passkeys): added mock data passkeysRegisterOptionsResponse --- .../connection/api_manager/mock_api.dart | 3 ++ .../passkeys_register_options_response.dart | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart diff --git a/lib/services/connection/api_manager/mock_api.dart b/lib/services/connection/api_manager/mock_api.dart index 15e702553a..45ef84a3d6 100644 --- a/lib/services/connection/api_manager/mock_api.dart +++ b/lib/services/connection/api_manager/mock_api.dart @@ -13,6 +13,7 @@ import 'package:flutter_deriv_api/services/connection/api_manager/connection_inf import 'package:flutter_deriv_api/services/connection/api_manager/exceptions/api_manager_exception.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/account/new_account_wallet_response.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/cashier/cashier_payments_response.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart'; import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart'; import 'package:flutter_deriv_api/services/connection/call_manager/exceptions/call_manager_exception.dart'; @@ -375,6 +376,8 @@ class MockAPI extends BaseAPI { return websiteStatusResponse; case 'wallet_migration': return walletMigrationResponse; + case 'passkeys_register_options': + return passkeysRegisterOptionsResponse; default: throw APIManagerException( diff --git a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart new file mode 100644 index 0000000000..b51d9a515e --- /dev/null +++ b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart @@ -0,0 +1,46 @@ +/// Wallet migration response mock data. +const String passkeysRegisterOptionsResponse = '''{ + "echo_req": { + "passkeys_register_options": 1 + }, + "msg_type": "passkeys_register_options", + "passkeys_register_options": { + "publicKey": { + "attestation": "direct", + "authenticatorSelection": { + "requireResidentKey": true, + "residentKey": "required", + "userVerification": "preferred" + }, + "challenge": "40gAmfy2FaUGwsV_VrxtvBgPa77dl8W6fFLxQf5WHMc", + "excludeCredentials": [], + "extensions": { + "credProps": true + }, + "pubKeyCredParams": [ + { + "alg": -8, + "type": "public-key" + }, + { + "alg": -7, + "type": "public-key" + }, + { + "alg": -257, + "type": "public-key" + } + ], + "rp": { + "id": "deriv.com", + "name": "Deriv" + }, + "timeout": 60000, + "user": { + "displayName": "bassam@deriv.com", + "id": 14, + "name": "bassam@deriv.com" + } + } + } +}'''; From 861009ae1ceca291c31d72d9b9d8de086920ff67 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:36:04 +0400 Subject: [PATCH 06/11] refactor(deriv_passkeys): moved fetch and fetchRaw calls to extended response classes --- .../passkeys_list_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_list_response_result.dart | 26 ------------- ...ys_register_options_response_extended.dart | 38 +++++++++++++++++++ ...keys_register_options_response_result.dart | 27 ------------- .../passkeys_register_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_register_response_result.dart | 26 ------------- .../passkeys_rename_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_rename_response_result.dart | 26 ------------- .../passkeys_revoke_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_revoke_response_result.dart | 26 ------------- 10 files changed, 182 insertions(+), 131 deletions(-) create mode 100644 lib/api/response/passkeys_list_response_extended.dart create mode 100644 lib/api/response/passkeys_register_options_response_extended.dart create mode 100644 lib/api/response/passkeys_register_response_extended.dart create mode 100644 lib/api/response/passkeys_rename_response_extended.dart create mode 100644 lib/api/response/passkeys_revoke_response_extended.dart diff --git a/lib/api/response/passkeys_list_response_extended.dart b/lib/api/response/passkeys_list_response_extended.dart new file mode 100644 index 0000000000..3208ea3ab4 --- /dev/null +++ b/lib/api/response/passkeys_list_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_list_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysListResponse] class. +class PasskeysListResponseExtended extends PasskeysListResponse { + static final BaseAPI _api = Injector()(); + + /// List all passkeys. + static Future fetch( + PasskeysListRequest request, + ) async { + final PasskeysListReceive response = await fetchRaw(request); + + return PasskeysListResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys list response. + static Future fetchRaw( + PasskeysListRequest request, + ) async { + final PasskeysListReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_list_response_result.dart b/lib/api/response/passkeys_list_response_result.dart index c396f86a7e..d6ba1afb53 100644 --- a/lib/api/response/passkeys_list_response_result.dart +++ b/lib/api/response/passkeys_list_response_result.dart @@ -57,32 +57,6 @@ class PasskeysListResponse extends PasskeysListResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// List all passkeys. - static Future fetch( - PasskeysListRequest request, - ) async { - final PasskeysListReceive response = await fetchRaw(request); - - return PasskeysListResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys list response. - static Future fetchRaw( - PasskeysListRequest request, - ) async { - final PasskeysListReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysListResponse copyWith({ List? passkeysList, diff --git a/lib/api/response/passkeys_register_options_response_extended.dart b/lib/api/response/passkeys_register_options_response_extended.dart new file mode 100644 index 0000000000..5affaa9efd --- /dev/null +++ b/lib/api/response/passkeys_register_options_response_extended.dart @@ -0,0 +1,38 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_register_options_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRegisterOptionsResponse] class. +class PasskeysRegisterOptionsResponseExtended + extends PasskeysRegisterOptionsResponse { + static final BaseAPI _api = Injector()(); + + /// List all register passkeys options. + static Future fetch( + PasskeysRegisterOptionsRequest request, + ) async { + final PasskeysRegisterOptionsReceive response = await fetchRaw(request); + + return PasskeysRegisterOptionsResponse.fromJson(response.toJson()); + } + + /// Fetches raw register passkeys options response. + static Future fetchRaw( + PasskeysRegisterOptionsRequest request, + ) async { + final PasskeysRegisterOptionsReceive response = + await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_register_options_response_result.dart b/lib/api/response/passkeys_register_options_response_result.dart index 7bef9942c7..83b1e10b31 100644 --- a/lib/api/response/passkeys_register_options_response_result.dart +++ b/lib/api/response/passkeys_register_options_response_result.dart @@ -51,33 +51,6 @@ class PasskeysRegisterOptionsResponse return resultMap; } - static final BaseAPI _api = Injector()(); - - /// List all register passkeys options. - static Future fetch( - PasskeysRegisterOptionsRequest request, - ) async { - final PasskeysRegisterOptionsReceive response = await fetchRaw(request); - - return PasskeysRegisterOptionsResponse.fromJson(response.toJson()); - } - - /// Fetches raw register passkeys options response. - static Future fetchRaw( - PasskeysRegisterOptionsRequest request, - ) async { - final PasskeysRegisterOptionsReceive response = - await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRegisterOptionsResponse copyWith({ PasskeysRegisterOptions? passkeysRegisterOptions, diff --git a/lib/api/response/passkeys_register_response_extended.dart b/lib/api/response/passkeys_register_response_extended.dart new file mode 100644 index 0000000000..d5ef3927a1 --- /dev/null +++ b/lib/api/response/passkeys_register_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_register_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRegisterResponse] class. +class PasskeysRegisterResponseExtended extends PasskeysRegisterResponse { + static final BaseAPI _api = Injector()(); + + /// register a new passkey. + static Future fetch( + PasskeysRegisterRequest request, + ) async { + final PasskeysRegisterReceive response = await fetchRaw(request); + + return PasskeysRegisterResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys register response. + static Future fetchRaw( + PasskeysRegisterRequest request, + ) async { + final PasskeysRegisterReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_register_response_result.dart b/lib/api/response/passkeys_register_response_result.dart index d7df0d7f1f..133daa46f4 100644 --- a/lib/api/response/passkeys_register_response_result.dart +++ b/lib/api/response/passkeys_register_response_result.dart @@ -49,32 +49,6 @@ class PasskeysRegisterResponse extends PasskeysRegisterResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// register a new passkey. - static Future fetch( - PasskeysRegisterRequest request, - ) async { - final PasskeysRegisterReceive response = await fetchRaw(request); - - return PasskeysRegisterResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys register response. - static Future fetchRaw( - PasskeysRegisterRequest request, - ) async { - final PasskeysRegisterReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRegisterResponse copyWith({ PasskeysRegister? passkeysRegister, diff --git a/lib/api/response/passkeys_rename_response_extended.dart b/lib/api/response/passkeys_rename_response_extended.dart new file mode 100644 index 0000000000..2ce3be5369 --- /dev/null +++ b/lib/api/response/passkeys_rename_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_rename_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRenameResponse] class. +class PasskeysRenameResponseExtended extends PasskeysRenameResponse { + static final BaseAPI _api = Injector()(); + + /// rename a passkey. + static Future fetch( + PasskeysRenameRequest request, + ) async { + final PasskeysRenameReceive response = await fetchRaw(request); + + return PasskeysRenameResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys rename response. + static Future fetchRaw( + PasskeysRenameRequest request, + ) async { + final PasskeysRenameReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_rename_response_result.dart b/lib/api/response/passkeys_rename_response_result.dart index 940c57266c..40c099eee2 100644 --- a/lib/api/response/passkeys_rename_response_result.dart +++ b/lib/api/response/passkeys_rename_response_result.dart @@ -45,32 +45,6 @@ class PasskeysRenameResponse extends PasskeysRenameResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// rename a passkey. - static Future fetch( - PasskeysRenameRequest request, - ) async { - final PasskeysRenameReceive response = await fetchRaw(request); - - return PasskeysRenameResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys rename response. - static Future fetchRaw( - PasskeysRenameRequest request, - ) async { - final PasskeysRenameReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRenameResponse copyWith({ int? passkeysRename, diff --git a/lib/api/response/passkeys_revoke_response_extended.dart b/lib/api/response/passkeys_revoke_response_extended.dart new file mode 100644 index 0000000000..aa6d97074d --- /dev/null +++ b/lib/api/response/passkeys_revoke_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_revoke_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRevokeReceive] class. +class PasskeysRevokeReceiveExtended extends PasskeysRevokeReceive { + static final BaseAPI _api = Injector()(); + + /// revoke a passkey. + static Future fetch( + PasskeysRevokeRequest request, + ) async { + final PasskeysRevokeReceive response = await fetchRaw(request); + + return PasskeysRevokeResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys revoke response. + static Future fetchRaw( + PasskeysRevokeRequest request, + ) async { + final PasskeysRevokeReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_revoke_response_result.dart b/lib/api/response/passkeys_revoke_response_result.dart index edc2576ada..d4c1398866 100644 --- a/lib/api/response/passkeys_revoke_response_result.dart +++ b/lib/api/response/passkeys_revoke_response_result.dart @@ -45,32 +45,6 @@ class PasskeysRevokeResponse extends PasskeysRevokeResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// revoke a passkey. - static Future fetch( - PasskeysRevokeRequest request, - ) async { - final PasskeysRevokeReceive response = await fetchRaw(request); - - return PasskeysRevokeResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys revoke response. - static Future fetchRaw( - PasskeysRevokeRequest request, - ) async { - final PasskeysRevokeReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRevokeResponse copyWith({ int? passkeysRevoke, From df67b57d18e38b9d655b1124198bf5f94f849b5a Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:39:10 +0400 Subject: [PATCH 07/11] refactor(deriv_passkeys): removed unused api calls --- .../passkeys_options_response_result.dart | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/lib/api/response/passkeys_options_response_result.dart b/lib/api/response/passkeys_options_response_result.dart index 9db91448d8..f8c887d4dc 100644 --- a/lib/api/response/passkeys_options_response_result.dart +++ b/lib/api/response/passkeys_options_response_result.dart @@ -49,32 +49,6 @@ class PasskeysOptionsResponse extends PasskeysOptionsResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// List all passkeys options. - static Future fetch( - PasskeysOptionsRequest request, - ) async { - final PasskeysOptionsReceive response = await fetchRaw(request); - - return PasskeysOptionsResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys options response. - static Future fetchRaw( - PasskeysOptionsRequest request, - ) async { - final PasskeysOptionsReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysOptionsResponse copyWith({ PasskeysOptions? passkeysOptions, From d3c836a6b6c4f1a808a39194450bf298af195be1 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:49:12 +0400 Subject: [PATCH 08/11] test(deriv_passkeys): added mock data passkeysRegisterResponse --- .../connection/api_manager/mock_api.dart | 3 +++ .../passkeys/passkeys_register_response.dart | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart diff --git a/lib/services/connection/api_manager/mock_api.dart b/lib/services/connection/api_manager/mock_api.dart index 45ef84a3d6..bfc72f2313 100644 --- a/lib/services/connection/api_manager/mock_api.dart +++ b/lib/services/connection/api_manager/mock_api.dart @@ -14,6 +14,7 @@ import 'package:flutter_deriv_api/services/connection/api_manager/exceptions/api import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/account/new_account_wallet_response.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/cashier/cashier_payments_response.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart'; import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart'; import 'package:flutter_deriv_api/services/connection/call_manager/exceptions/call_manager_exception.dart'; @@ -378,6 +379,8 @@ class MockAPI extends BaseAPI { return walletMigrationResponse; case 'passkeys_register_options': return passkeysRegisterOptionsResponse; + case 'passkeys_register': + return passkeysRegisterResponse; default: throw APIManagerException( diff --git a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart new file mode 100644 index 0000000000..5259853a84 --- /dev/null +++ b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart @@ -0,0 +1,17 @@ +/// Wallet migration response mock data. +const String passkeysRegisterResponse = '''{ + "echo_req": { + "passkeys_register": 1 + }, + "msg_type": "passkeys_register", + "passkeys_register": { + "properties": { + "created_at": 10000, + "id": "id", + "last_used": 10000, + "name": "Passkey", + "passkey_id": "passkeyId", + "stored_on": "storedOn", + } + } +}'''; From 93ac618ff46163a540d7690923ce9539e25b9bad Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:50:52 +0400 Subject: [PATCH 09/11] refactor(deriv_passkeys): fixed typo in mock response passkeysRegisterResponse --- .../mock_data/passkeys/passkeys_register_response.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart index 5259853a84..a12b3be9fb 100644 --- a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart +++ b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart @@ -11,7 +11,7 @@ const String passkeysRegisterResponse = '''{ "last_used": 10000, "name": "Passkey", "passkey_id": "passkeyId", - "stored_on": "storedOn", + "stored_on": "storedOn" } } }'''; From 2a0b3b5f8e7030ae8705e26f1e4d90741a87c28d Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:54:04 +0400 Subject: [PATCH 10/11] test(deriv_passkeys): added mock data passkeysListResponse --- .../connection/api_manager/mock_api.dart | 3 +++ .../passkeys/passkeys_list_response.dart | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart diff --git a/lib/services/connection/api_manager/mock_api.dart b/lib/services/connection/api_manager/mock_api.dart index bfc72f2313..2f5374d02e 100644 --- a/lib/services/connection/api_manager/mock_api.dart +++ b/lib/services/connection/api_manager/mock_api.dart @@ -13,6 +13,7 @@ import 'package:flutter_deriv_api/services/connection/api_manager/connection_inf import 'package:flutter_deriv_api/services/connection/api_manager/exceptions/api_manager_exception.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/account/new_account_wallet_response.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/cashier/cashier_payments_response.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_register_response.dart'; import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart'; @@ -381,6 +382,8 @@ class MockAPI extends BaseAPI { return passkeysRegisterOptionsResponse; case 'passkeys_register': return passkeysRegisterResponse; + case 'passkeys_list': + return passkeysListResponse; default: throw APIManagerException( diff --git a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart new file mode 100644 index 0000000000..e3386966e0 --- /dev/null +++ b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart @@ -0,0 +1,17 @@ +/// Wallet migration response mock data. +const String passkeysListResponse = '''{ + "echo_req": { + "passkeysList": 1 + }, + "msg_type": "passkeysList", + "passkeysList": [ + { + "created_at": 10000, + "id": "id", + "last_used": 10000, + "name": "Passkey", + "passkey_id": "passkeyId", + "stored_on": "storedOn" + } + ] +}'''; From 7332a49c97a7103c64e2c00e42bc0649d47c8b57 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:55:41 +0400 Subject: [PATCH 11/11] refactor(deriv_passkeys): fixed typo in mock response passkeysListResponse --- .../mock_data/passkeys/passkeys_list_response.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart index e3386966e0..cdd6f80c41 100644 --- a/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart +++ b/lib/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart @@ -1,10 +1,10 @@ /// Wallet migration response mock data. const String passkeysListResponse = '''{ "echo_req": { - "passkeysList": 1 + "passkeys_list": 1 }, - "msg_type": "passkeysList", - "passkeysList": [ + "msg_type": "passkeys_list", + "passkeys_list": [ { "created_at": 10000, "id": "id",