From 164ea2e4c979321e1cd270765169a8b224340d21 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Fri, 31 May 2024 01:00:08 -0400 Subject: [PATCH] [PSDK-187] Server Signer Support --- src/client/api.ts | 3175 +++++++++++++++++++++++++++++++------- src/client/common.ts | 5 +- src/coinbase/address.ts | 38 +- src/coinbase/coinbase.ts | 14 +- src/coinbase/transfer.ts | 42 +- src/coinbase/types.ts | 16 +- src/coinbase/wallet.ts | 79 +- 7 files changed, 2778 insertions(+), 591 deletions(-) diff --git a/src/client/api.ts b/src/client/api.ts index 3986d439..93f5bc40 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -176,6 +176,19 @@ export interface Balance { */ asset: Asset; } +/** + * + * @export + * @interface BroadcastTradeRequest + */ +export interface BroadcastTradeRequest { + /** + * The hex-encoded signed payload of the trade + * @type {string} + * @memberof BroadcastTradeRequest + */ + signed_payload: string; +} /** * * @export @@ -200,13 +213,57 @@ export interface CreateAddressRequest { * @type {string} * @memberof CreateAddressRequest */ - public_key: string; + public_key?: string; /** * An attestation signed by the private key that is associated with the wallet. The attestation will be a hex-encoded signature of a json payload with fields `wallet_id` and `public_key`, signed by the private key associated with the public_key set in the request. * @type {string} * @memberof CreateAddressRequest */ - attestation: string; + attestation?: string; +} +/** + * + * @export + * @interface CreateServerSignerRequest + */ +export interface CreateServerSignerRequest { + /** + * The ID of the server signer + * @type {string} + * @memberof CreateServerSignerRequest + */ + server_signer_id: string; + /** + * The enrollment data of the server signer. This will be the base64 encoded server-signer-id. + * @type {string} + * @memberof CreateServerSignerRequest + */ + enrollment_data: string; +} +/** + * + * @export + * @interface CreateTradeRequest + */ +export interface CreateTradeRequest { + /** + * The amount to trade + * @type {string} + * @memberof CreateTradeRequest + */ + amount: string; + /** + * The ID of the asset to trade + * @type {string} + * @memberof CreateTradeRequest + */ + from_asset_id: string; + /** + * The ID of the asset to receive from the trade + * @type {string} + * @memberof CreateTradeRequest + */ + to_asset_id: string; } /** * @@ -247,10 +304,29 @@ export interface CreateTransferRequest { export interface CreateWalletRequest { /** * - * @type {Wallet} + * @type {CreateWalletRequestWallet} * @memberof CreateWalletRequest */ - wallet: Wallet; + wallet: CreateWalletRequestWallet; +} +/** + * Parameters for configuring a wallet + * @export + * @interface CreateWalletRequestWallet + */ +export interface CreateWalletRequestWallet { + /** + * The ID of the blockchain network + * @type {string} + * @memberof CreateWalletRequestWallet + */ + network_id: string; + /** + * Whether the wallet should use the project\'s server signer or if the addresses in the wallets will belong to a private key the developer manages. Defaults to false. + * @type {boolean} + * @memberof CreateWalletRequestWallet + */ + use_server_signer?: boolean; } /** * @@ -285,237 +361,1457 @@ export interface ModelError { message: string; } /** - * A transfer of an asset from one address to another + * An event representing a seed creation. * @export - * @interface Transfer + * @interface SeedCreationEvent */ -export interface Transfer { - /** - * The ID of the blockchain network - * @type {string} - * @memberof Transfer - */ - network_id: string; +export interface SeedCreationEvent { /** - * The ID of the wallet that owns the from address + * The ID of the wallet that the server-signer should create the seed for * @type {string} - * @memberof Transfer + * @memberof SeedCreationEvent */ wallet_id: string; /** - * The onchain address of the sender + * The ID of the user that the wallet belongs to * @type {string} - * @memberof Transfer + * @memberof SeedCreationEvent */ - address_id: string; + wallet_user_id: string; +} +/** + * The result to a SeedCreationEvent. + * @export + * @interface SeedCreationEventResult + */ +export interface SeedCreationEventResult { /** - * The onchain address of the recipient + * The ID of the wallet that the seed was created for * @type {string} - * @memberof Transfer + * @memberof SeedCreationEventResult */ - destination: string; + wallet_id: string; /** - * The amount in the atomic units of the asset + * The ID of the user that the wallet belongs to * @type {string} - * @memberof Transfer + * @memberof SeedCreationEventResult */ - amount: string; + wallet_user_id: string; /** - * The ID of the asset being transferred + * The extended public key for the first master key derived from seed. * @type {string} - * @memberof Transfer + * @memberof SeedCreationEventResult */ - asset_id: string; + extended_public_key: string; /** - * The ID of the transfer + * The ID of the seed in Server-Signer used to generate the extended public key. * @type {string} - * @memberof Transfer + * @memberof SeedCreationEventResult */ - transfer_id: string; + seed_id: string; +} +/** + * A Server-Signer assigned to sign transactions in a wallet. + * @export + * @interface ServerSigner + */ +export interface ServerSigner { /** - * The unsigned payload of the transfer. This is the payload that needs to be signed by the sender. + * The ID of the server-signer * @type {string} - * @memberof Transfer + * @memberof ServerSigner */ - unsigned_payload: string; + server_signer_id: string; /** - * The signed payload of the transfer. This is the payload that has been signed by the sender. - * @type {string} - * @memberof Transfer + * The IDs of the wallets that the server-signer can sign for + * @type {Array} + * @memberof ServerSigner */ - signed_payload?: string; + wallets?: Array; +} +/** + * An event that is waiting to be processed by a Server-Signer. + * @export + * @interface ServerSignerEvent + */ +export interface ServerSignerEvent { /** - * The hash of the transfer transaction + * The ID of the server-signer that the event is for * @type {string} - * @memberof Transfer + * @memberof ServerSignerEvent */ - transaction_hash?: string; + server_signer_id: string; /** - * The status of the transfer - * @type {string} - * @memberof Transfer + * + * @type {ServerSignerEventEvent} + * @memberof ServerSignerEvent */ - status: TransferStatusEnum; + event: ServerSignerEventEvent; } - -export const TransferStatusEnum = { - Pending: "pending", - Broadcast: "broadcast", - Complete: "complete", - Failed: "failed", -} as const; - -export type TransferStatusEnum = (typeof TransferStatusEnum)[keyof typeof TransferStatusEnum]; +/** + * @type ServerSignerEventEvent + * @export + */ +export type ServerSignerEventEvent = SeedCreationEvent | SignatureCreationEvent; /** * * @export - * @interface TransferList + * @interface ServerSignerEventList */ -export interface TransferList { +export interface ServerSignerEventList { /** * - * @type {Array} - * @memberof TransferList + * @type {Array} + * @memberof ServerSignerEventList */ - data: Array; + data: Array; /** * True if this list has another page of items after this one that can be fetched. * @type {boolean} - * @memberof TransferList + * @memberof ServerSignerEventList */ has_more: boolean; /** * The page token to be used to fetch the next page. * @type {string} - * @memberof TransferList + * @memberof ServerSignerEventList */ next_page: string; /** - * The total number of transfers for the address in the wallet. + * The total number of events for the server signer. * @type {number} - * @memberof TransferList + * @memberof ServerSignerEventList */ total_count: number; } /** - * + * An event representing a signature creation. * @export - * @interface User + * @interface SignatureCreationEvent */ -export interface User { +export interface SignatureCreationEvent { /** - * The ID of the user + * The ID of the seed that the server-signer should create the signature for * @type {string} - * @memberof User + * @memberof SignatureCreationEvent */ - id: string; + seed_id: string; + /** + * The ID of the wallet the signature is for + * @type {string} + * @memberof SignatureCreationEvent + */ + wallet_id: string; + /** + * The ID of the user that the wallet belongs to + * @type {string} + * @memberof SignatureCreationEvent + */ + wallet_user_id: string; + /** + * The ID of the address the transfer belongs to + * @type {string} + * @memberof SignatureCreationEvent + */ + address_id: string; + /** + * The index of the address that the server-signer should sign with + * @type {number} + * @memberof SignatureCreationEvent + */ + address_index: number; + /** + * The payload that the server-signer should sign + * @type {string} + * @memberof SignatureCreationEvent + */ + signing_payload: string; /** * + * @type {TransactionType} + * @memberof SignatureCreationEvent + */ + transaction_type: TransactionType; + /** + * The ID of the transaction that the server-signer should sign * @type {string} - * @memberof User + * @memberof SignatureCreationEvent */ - display_name?: string; + transaction_id: string; } + /** - * + * The result to a SignatureCreationEvent. * @export - * @interface Wallet + * @interface SignatureCreationEventResult */ -export interface Wallet { +export interface SignatureCreationEventResult { /** - * The server-assigned ID for the wallet. + * The ID of the wallet that the event was created for. * @type {string} - * @memberof Wallet + * @memberof SignatureCreationEventResult + */ + wallet_id: string; + /** + * The ID of the user that the wallet belongs to + * @type {string} + * @memberof SignatureCreationEventResult */ - id?: string; + wallet_user_id: string; + /** + * The ID of the address the transfer belongs to + * @type {string} + * @memberof SignatureCreationEventResult + */ + address_id: string; + /** + * + * @type {TransactionType} + * @memberof SignatureCreationEventResult + */ + transaction_type: TransactionType; + /** + * The ID of the transaction that the Server-Signer has signed for + * @type {string} + * @memberof SignatureCreationEventResult + */ + transaction_id: string; + /** + * The signature created by the server-signer. + * @type {string} + * @memberof SignatureCreationEventResult + */ + signature: string; +} + +/** + * A trade of an asset to another asset + * @export + * @interface Trade + */ +export interface Trade { /** * The ID of the blockchain network * @type {string} - * @memberof Wallet + * @memberof Trade */ network_id: string; + /** + * The ID of the wallet that owns the from address + * @type {string} + * @memberof Trade + */ + wallet_id: string; + /** + * The onchain address of the sender + * @type {string} + * @memberof Trade + */ + address_id: string; + /** + * The ID of the trade + * @type {string} + * @memberof Trade + */ + trade_id: string; + /** + * The amount of the from asset to be traded (in atomic units of the from asset) + * @type {string} + * @memberof Trade + */ + from_amount: string; /** * - * @type {Address} - * @memberof Wallet + * @type {Asset} + * @memberof Trade */ - default_address?: Address; + from_asset: Asset; + /** + * The amount of the to asset that will be received (in atomic units of the to asset) + * @type {string} + * @memberof Trade + */ + to_amount: string; + /** + * + * @type {Asset} + * @memberof Trade + */ + to_asset: Asset; + /** + * + * @type {Transaction} + * @memberof Trade + */ + transaction: Transaction; } /** - * Paginated list of wallets + * * @export - * @interface WalletList + * @interface TradeList */ -export interface WalletList { +export interface TradeList { /** * - * @type {Array} - * @memberof WalletList + * @type {Array} + * @memberof TradeList */ - data: Array; + data: Array; /** * True if this list has another page of items after this one that can be fetched. * @type {boolean} - * @memberof WalletList + * @memberof TradeList */ has_more: boolean; /** * The page token to be used to fetch the next page. * @type {string} - * @memberof WalletList + * @memberof TradeList */ next_page: string; /** - * The total number of wallets + * The total number of trades for the address in the wallet. * @type {number} - * @memberof WalletList + * @memberof TradeList */ total_count: number; } - /** - * AddressesApi - axios parameter creator + * An onchain transaction. * @export + * @interface Transaction */ -export const AddressesApiAxiosParamCreator = function (configuration?: Configuration) { - return { - /** - * Create a new address scoped to the wallet. - * @summary Create a new address - * @param {string} walletId The ID of the wallet to create the address in. - * @param {CreateAddressRequest} [createAddressRequest] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - createAddress: async ( - walletId: string, - createAddressRequest?: CreateAddressRequest, - options: RawAxiosRequestConfig = {}, - ): Promise => { - // verify required parameter 'walletId' is not null or undefined - assertParamExists("createAddress", "walletId", walletId); - const localVarPath = `/v1/wallets/{wallet_id}/addresses`.replace( - `{${"wallet_id"}}`, - encodeURIComponent(String(walletId)), - ); - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { - method: "POST", - ...baseOptions, - ...options, - }; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - localVarHeaderParameter["Content-Type"] = "application/json"; - +export interface Transaction { + /** + * The ID of the blockchain network + * @type {string} + * @memberof Transaction + */ + network_id: string; + /** + * The onchain address of the sender + * @type {string} + * @memberof Transaction + */ + from_address_id: string; + /** + * The unsigned payload of the transaction. This is the payload that needs to be signed by the sender. + * @type {string} + * @memberof Transaction + */ + unsigned_payload: string; + /** + * The signed payload of the transaction. This is the payload that has been signed by the sender. + * @type {string} + * @memberof Transaction + */ + signed_payload?: string; + /** + * The hash of the transaction + * @type {string} + * @memberof Transaction + */ + transaction_hash?: string; + /** + * The status of the transaction + * @type {string} + * @memberof Transaction + */ + status: TransactionStatusEnum; +} + +export const TransactionStatusEnum = { + Pending: "pending", + Broadcast: "broadcast", + Complete: "complete", + Failed: "failed", +} as const; + +export type TransactionStatusEnum = + (typeof TransactionStatusEnum)[keyof typeof TransactionStatusEnum]; + +/** + * + * @export + * @enum {string} + */ + +export const TransactionType = { + Transfer: "transfer", +} as const; + +export type TransactionType = (typeof TransactionType)[keyof typeof TransactionType]; + +/** + * A transfer of an asset from one address to another + * @export + * @interface Transfer + */ +export interface Transfer { + /** + * The ID of the blockchain network + * @type {string} + * @memberof Transfer + */ + network_id: string; + /** + * The ID of the wallet that owns the from address + * @type {string} + * @memberof Transfer + */ + wallet_id: string; + /** + * The onchain address of the sender + * @type {string} + * @memberof Transfer + */ + address_id: string; + /** + * The onchain address of the recipient + * @type {string} + * @memberof Transfer + */ + destination: string; + /** + * The amount in the atomic units of the asset + * @type {string} + * @memberof Transfer + */ + amount: string; + /** + * The ID of the asset being transferred + * @type {string} + * @memberof Transfer + */ + asset_id: string; + /** + * The ID of the transfer + * @type {string} + * @memberof Transfer + */ + transfer_id: string; + /** + * The unsigned payload of the transfer. This is the payload that needs to be signed by the sender. + * @type {string} + * @memberof Transfer + */ + unsigned_payload: string; + /** + * The signed payload of the transfer. This is the payload that has been signed by the sender. + * @type {string} + * @memberof Transfer + */ + signed_payload?: string; + /** + * The hash of the transfer transaction + * @type {string} + * @memberof Transfer + */ + transaction_hash?: string; + /** + * The status of the transfer + * @type {string} + * @memberof Transfer + */ + status: TransferStatusEnum; +} + +export const TransferStatusEnum = { + Pending: "pending", + Broadcast: "broadcast", + Complete: "complete", + Failed: "failed", +} as const; + +export type TransferStatusEnum = (typeof TransferStatusEnum)[keyof typeof TransferStatusEnum]; + +/** + * + * @export + * @interface TransferList + */ +export interface TransferList { + /** + * + * @type {Array} + * @memberof TransferList + */ + data: Array; + /** + * True if this list has another page of items after this one that can be fetched. + * @type {boolean} + * @memberof TransferList + */ + has_more: boolean; + /** + * The page token to be used to fetch the next page. + * @type {string} + * @memberof TransferList + */ + next_page: string; + /** + * The total number of transfers for the address in the wallet. + * @type {number} + * @memberof TransferList + */ + total_count: number; +} +/** + * + * @export + * @interface User + */ +export interface User { + /** + * The ID of the user + * @type {string} + * @memberof User + */ + id: string; + /** + * + * @type {string} + * @memberof User + */ + display_name?: string; +} +/** + * + * @export + * @interface Wallet + */ +export interface Wallet { + /** + * The server-assigned ID for the wallet. + * @type {string} + * @memberof Wallet + */ + id: string; + /** + * The ID of the blockchain network + * @type {string} + * @memberof Wallet + */ + network_id: string; + /** + * + * @type {Address} + * @memberof Wallet + */ + default_address?: Address; + /** + * The status of the Server-Signer for the wallet if present. + * @type {string} + * @memberof Wallet + */ + server_signer_status?: WalletServerSignerStatusEnum; +} + +export const WalletServerSignerStatusEnum = { + PendingSeedCreation: "pending_seed_creation", + ActiveSeed: "active_seed", +} as const; + +export type WalletServerSignerStatusEnum = + (typeof WalletServerSignerStatusEnum)[keyof typeof WalletServerSignerStatusEnum]; + +/** + * Paginated list of wallets + * @export + * @interface WalletList + */ +export interface WalletList { + /** + * + * @type {Array} + * @memberof WalletList + */ + data: Array; + /** + * True if this list has another page of items after this one that can be fetched. + * @type {boolean} + * @memberof WalletList + */ + has_more: boolean; + /** + * The page token to be used to fetch the next page. + * @type {string} + * @memberof WalletList + */ + next_page: string; + /** + * The total number of wallets + * @type {number} + * @memberof WalletList + */ + total_count: number; +} + +/** + * AddressesApi - axios parameter creator + * @export + */ +export const AddressesApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * Create a new address scoped to the wallet. + * @summary Create a new address + * @param {string} walletId The ID of the wallet to create the address in. + * @param {CreateAddressRequest} [createAddressRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createAddress: async ( + walletId: string, + createAddressRequest?: CreateAddressRequest, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("createAddress", "walletId", walletId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses`.replace( + `{${"wallet_id"}}`, + encodeURIComponent(String(walletId)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter["Content-Type"] = "application/json"; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + localVarRequestOptions.data = serializeDataIfNeeded( + createAddressRequest, + localVarRequestOptions, + configuration, + ); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Get address + * @summary Get address by onchain address + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getAddress: async ( + walletId: string, + addressId: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("getAddress", "walletId", walletId); + // verify required parameter 'addressId' is not null or undefined + assertParamExists("getAddress", "addressId", addressId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}` + .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) + .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Get address balance + * @summary Get address balance for asset + * @param {string} walletId The ID of the wallet to fetch the balance for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} assetId The symbol of the asset to fetch the balance for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getAddressBalance: async ( + walletId: string, + addressId: string, + assetId: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("getAddressBalance", "walletId", walletId); + // verify required parameter 'addressId' is not null or undefined + assertParamExists("getAddressBalance", "addressId", addressId); + // verify required parameter 'assetId' is not null or undefined + assertParamExists("getAddressBalance", "assetId", assetId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/balances/{asset_id}` + .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) + .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))) + .replace(`{${"asset_id"}}`, encodeURIComponent(String(assetId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Get address balances + * @summary Get all balances for address + * @param {string} walletId The ID of the wallet to fetch the balances for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listAddressBalances: async ( + walletId: string, + addressId: string, + page?: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("listAddressBalances", "walletId", walletId); + // verify required parameter 'addressId' is not null or undefined + assertParamExists("listAddressBalances", "addressId", addressId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/balances` + .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) + .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (page !== undefined) { + localVarQueryParameter["page"] = page; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * List addresses in the wallet. + * @summary List addresses in a wallet. + * @param {string} walletId The ID of the wallet whose addresses to fetch + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listAddresses: async ( + walletId: string, + limit?: number, + page?: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("listAddresses", "walletId", walletId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses`.replace( + `{${"wallet_id"}}`, + encodeURIComponent(String(walletId)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (limit !== undefined) { + localVarQueryParameter["limit"] = limit; + } + + if (page !== undefined) { + localVarQueryParameter["page"] = page; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Request faucet funds to be sent to onchain address. + * @summary Request faucet funds for onchain address. + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + requestFaucetFunds: async ( + walletId: string, + addressId: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("requestFaucetFunds", "walletId", walletId); + // verify required parameter 'addressId' is not null or undefined + assertParamExists("requestFaucetFunds", "addressId", addressId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/faucet` + .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) + .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; +}; + +/** + * AddressesApi - functional programming interface + * @export + */ +export const AddressesApiFp = function (configuration?: Configuration) { + const localVarAxiosParamCreator = AddressesApiAxiosParamCreator(configuration); + return { + /** + * Create a new address scoped to the wallet. + * @summary Create a new address + * @param {string} walletId The ID of the wallet to create the address in. + * @param {CreateAddressRequest} [createAddressRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async createAddress( + walletId: string, + createAddressRequest?: CreateAddressRequest, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise
> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createAddress( + walletId, + createAddressRequest, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["AddressesApi.createAddress"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Get address + * @summary Get address by onchain address + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getAddress( + walletId: string, + addressId: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise
> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getAddress( + walletId, + addressId, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["AddressesApi.getAddress"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Get address balance + * @summary Get address balance for asset + * @param {string} walletId The ID of the wallet to fetch the balance for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} assetId The symbol of the asset to fetch the balance for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getAddressBalance( + walletId: string, + addressId: string, + assetId: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getAddressBalance( + walletId, + addressId, + assetId, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["AddressesApi.getAddressBalance"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Get address balances + * @summary Get all balances for address + * @param {string} walletId The ID of the wallet to fetch the balances for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async listAddressBalances( + walletId: string, + addressId: string, + page?: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.listAddressBalances( + walletId, + addressId, + page, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["AddressesApi.listAddressBalances"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * List addresses in the wallet. + * @summary List addresses in a wallet. + * @param {string} walletId The ID of the wallet whose addresses to fetch + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async listAddresses( + walletId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.listAddresses( + walletId, + limit, + page, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["AddressesApi.listAddresses"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Request faucet funds to be sent to onchain address. + * @summary Request faucet funds for onchain address. + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async requestFaucetFunds( + walletId: string, + addressId: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.requestFaucetFunds( + walletId, + addressId, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["AddressesApi.requestFaucetFunds"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + }; +}; + +/** + * AddressesApi - factory interface + * @export + */ +export const AddressesApiFactory = function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance, +) { + const localVarFp = AddressesApiFp(configuration); + return { + /** + * Create a new address scoped to the wallet. + * @summary Create a new address + * @param {string} walletId The ID of the wallet to create the address in. + * @param {CreateAddressRequest} [createAddressRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createAddress( + walletId: string, + createAddressRequest?: CreateAddressRequest, + options?: any, + ): AxiosPromise
{ + return localVarFp + .createAddress(walletId, createAddressRequest, options) + .then(request => request(axios, basePath)); + }, + /** + * Get address + * @summary Get address by onchain address + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getAddress(walletId: string, addressId: string, options?: any): AxiosPromise
{ + return localVarFp + .getAddress(walletId, addressId, options) + .then(request => request(axios, basePath)); + }, + /** + * Get address balance + * @summary Get address balance for asset + * @param {string} walletId The ID of the wallet to fetch the balance for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} assetId The symbol of the asset to fetch the balance for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getAddressBalance( + walletId: string, + addressId: string, + assetId: string, + options?: any, + ): AxiosPromise { + return localVarFp + .getAddressBalance(walletId, addressId, assetId, options) + .then(request => request(axios, basePath)); + }, + /** + * Get address balances + * @summary Get all balances for address + * @param {string} walletId The ID of the wallet to fetch the balances for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listAddressBalances( + walletId: string, + addressId: string, + page?: string, + options?: any, + ): AxiosPromise { + return localVarFp + .listAddressBalances(walletId, addressId, page, options) + .then(request => request(axios, basePath)); + }, + /** + * List addresses in the wallet. + * @summary List addresses in a wallet. + * @param {string} walletId The ID of the wallet whose addresses to fetch + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listAddresses( + walletId: string, + limit?: number, + page?: string, + options?: any, + ): AxiosPromise { + return localVarFp + .listAddresses(walletId, limit, page, options) + .then(request => request(axios, basePath)); + }, + /** + * Request faucet funds to be sent to onchain address. + * @summary Request faucet funds for onchain address. + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + requestFaucetFunds( + walletId: string, + addressId: string, + options?: any, + ): AxiosPromise { + return localVarFp + .requestFaucetFunds(walletId, addressId, options) + .then(request => request(axios, basePath)); + }, + }; +}; + +/** + * AddressesApi - interface + * @export + * @interface AddressesApi + */ +export interface AddressesApiInterface { + /** + * Create a new address scoped to the wallet. + * @summary Create a new address + * @param {string} walletId The ID of the wallet to create the address in. + * @param {CreateAddressRequest} [createAddressRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApiInterface + */ + createAddress( + walletId: string, + createAddressRequest?: CreateAddressRequest, + options?: RawAxiosRequestConfig, + ): AxiosPromise
; + + /** + * Get address + * @summary Get address by onchain address + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApiInterface + */ + getAddress( + walletId: string, + addressId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise
; + + /** + * Get address balance + * @summary Get address balance for asset + * @param {string} walletId The ID of the wallet to fetch the balance for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} assetId The symbol of the asset to fetch the balance for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApiInterface + */ + getAddressBalance( + walletId: string, + addressId: string, + assetId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * Get address balances + * @summary Get all balances for address + * @param {string} walletId The ID of the wallet to fetch the balances for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApiInterface + */ + listAddressBalances( + walletId: string, + addressId: string, + page?: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * List addresses in the wallet. + * @summary List addresses in a wallet. + * @param {string} walletId The ID of the wallet whose addresses to fetch + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApiInterface + */ + listAddresses( + walletId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * Request faucet funds to be sent to onchain address. + * @summary Request faucet funds for onchain address. + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApiInterface + */ + requestFaucetFunds( + walletId: string, + addressId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; +} + +/** + * AddressesApi - object-oriented interface + * @export + * @class AddressesApi + * @extends {BaseAPI} + */ +export class AddressesApi extends BaseAPI implements AddressesApiInterface { + /** + * Create a new address scoped to the wallet. + * @summary Create a new address + * @param {string} walletId The ID of the wallet to create the address in. + * @param {CreateAddressRequest} [createAddressRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public createAddress( + walletId: string, + createAddressRequest?: CreateAddressRequest, + options?: RawAxiosRequestConfig, + ) { + return AddressesApiFp(this.configuration) + .createAddress(walletId, createAddressRequest, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Get address + * @summary Get address by onchain address + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public getAddress(walletId: string, addressId: string, options?: RawAxiosRequestConfig) { + return AddressesApiFp(this.configuration) + .getAddress(walletId, addressId, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Get address balance + * @summary Get address balance for asset + * @param {string} walletId The ID of the wallet to fetch the balance for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} assetId The symbol of the asset to fetch the balance for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public getAddressBalance( + walletId: string, + addressId: string, + assetId: string, + options?: RawAxiosRequestConfig, + ) { + return AddressesApiFp(this.configuration) + .getAddressBalance(walletId, addressId, assetId, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Get address balances + * @summary Get all balances for address + * @param {string} walletId The ID of the wallet to fetch the balances for + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public listAddressBalances( + walletId: string, + addressId: string, + page?: string, + options?: RawAxiosRequestConfig, + ) { + return AddressesApiFp(this.configuration) + .listAddressBalances(walletId, addressId, page, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * List addresses in the wallet. + * @summary List addresses in a wallet. + * @param {string} walletId The ID of the wallet whose addresses to fetch + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public listAddresses( + walletId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ) { + return AddressesApiFp(this.configuration) + .listAddresses(walletId, limit, page, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Request faucet funds to be sent to onchain address. + * @summary Request faucet funds for onchain address. + * @param {string} walletId The ID of the wallet the address belongs to. + * @param {string} addressId The onchain address of the address that is being fetched. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AddressesApi + */ + public requestFaucetFunds(walletId: string, addressId: string, options?: RawAxiosRequestConfig) { + return AddressesApiFp(this.configuration) + .requestFaucetFunds(walletId, addressId, options) + .then(request => request(this.axios, this.basePath)); + } +} + +/** + * ServerSignersApi - axios parameter creator + * @export + */ +export const ServerSignersApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * Create a new Server-Signer + * @summary Create a new Server-Signer + * @param {CreateServerSignerRequest} [createServerSignerRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createServerSigner: async ( + createServerSignerRequest?: CreateServerSignerRequest, + options: RawAxiosRequestConfig = {}, + ): Promise => { + const localVarPath = `/v1/server_signers`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter["Content-Type"] = "application/json"; + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { @@ -524,89 +1820,774 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura ...options.headers, }; localVarRequestOptions.data = serializeDataIfNeeded( - createAddressRequest, + createServerSignerRequest, + localVarRequestOptions, + configuration, + ); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Get a server signer by ID + * @summary Get a server signer by ID + * @param {string} serverSignerId The ID of the server signer to fetch + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getServerSigner: async ( + serverSignerId: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'serverSignerId' is not null or undefined + assertParamExists("getServerSigner", "serverSignerId", serverSignerId); + const localVarPath = `/v1/server_signers/{server_signer_id}`.replace( + `{${"server_signer_id"}}`, + encodeURIComponent(String(serverSignerId)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * List events for a server signer + * @summary List events for a server signer + * @param {string} serverSignerId The ID of the server signer to fetch events for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listServerSignerEvents: async ( + serverSignerId: string, + limit?: number, + page?: string, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'serverSignerId' is not null or undefined + assertParamExists("listServerSignerEvents", "serverSignerId", serverSignerId); + const localVarPath = `/v1/server_signers/{server_signer_id}/events`.replace( + `{${"server_signer_id"}}`, + encodeURIComponent(String(serverSignerId)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (limit !== undefined) { + localVarQueryParameter["limit"] = limit; + } + + if (page !== undefined) { + localVarQueryParameter["page"] = page; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * List server signers for the current project + * @summary List server signers for the current project + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listServerSigners: async (options: RawAxiosRequestConfig = {}): Promise => { + const localVarPath = `/v1/server_signers`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SeedCreationEventResult} [seedCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + submitServerSignerSeedEventResult: async ( + serverSignerId: string, + seedCreationEventResult?: SeedCreationEventResult, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'serverSignerId' is not null or undefined + assertParamExists("submitServerSignerSeedEventResult", "serverSignerId", serverSignerId); + const localVarPath = `/v1/server_signers/{server_signer_id}/seed_event_result`.replace( + `{${"server_signer_id"}}`, + encodeURIComponent(String(serverSignerId)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter["Content-Type"] = "application/json"; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + localVarRequestOptions.data = serializeDataIfNeeded( + seedCreationEventResult, + localVarRequestOptions, + configuration, + ); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SignatureCreationEventResult} [signatureCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + submitServerSignerSignatureEventResult: async ( + serverSignerId: string, + signatureCreationEventResult?: SignatureCreationEventResult, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'serverSignerId' is not null or undefined + assertParamExists("submitServerSignerSignatureEventResult", "serverSignerId", serverSignerId); + const localVarPath = `/v1/server_signers/{server_signer_id}/signature_event_result`.replace( + `{${"server_signer_id"}}`, + encodeURIComponent(String(serverSignerId)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter["Content-Type"] = "application/json"; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + localVarRequestOptions.data = serializeDataIfNeeded( + signatureCreationEventResult, localVarRequestOptions, configuration, ); - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; +}; + +/** + * ServerSignersApi - functional programming interface + * @export + */ +export const ServerSignersApiFp = function (configuration?: Configuration) { + const localVarAxiosParamCreator = ServerSignersApiAxiosParamCreator(configuration); + return { + /** + * Create a new Server-Signer + * @summary Create a new Server-Signer + * @param {CreateServerSignerRequest} [createServerSignerRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async createServerSigner( + createServerSignerRequest?: CreateServerSignerRequest, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createServerSigner( + createServerSignerRequest, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["ServerSignersApi.createServerSigner"]?.[localVarOperationServerIndex] + ?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Get a server signer by ID + * @summary Get a server signer by ID + * @param {string} serverSignerId The ID of the server signer to fetch + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getServerSigner( + serverSignerId: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getServerSigner( + serverSignerId, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["ServerSignersApi.getServerSigner"]?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * List events for a server signer + * @summary List events for a server signer + * @param {string} serverSignerId The ID of the server signer to fetch events for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async listServerSignerEvents( + serverSignerId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.listServerSignerEvents( + serverSignerId, + limit, + page, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["ServerSignersApi.listServerSignerEvents"]?.[ + localVarOperationServerIndex + ]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * List server signers for the current project + * @summary List server signers for the current project + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async listServerSigners( + options?: RawAxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.listServerSigners(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["ServerSignersApi.listServerSigners"]?.[localVarOperationServerIndex] + ?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SeedCreationEventResult} [seedCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async submitServerSignerSeedEventResult( + serverSignerId: string, + seedCreationEventResult?: SeedCreationEventResult, + options?: RawAxiosRequestConfig, + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.submitServerSignerSeedEventResult( + serverSignerId, + seedCreationEventResult, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["ServerSignersApi.submitServerSignerSeedEventResult"]?.[ + localVarOperationServerIndex + ]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SignatureCreationEventResult} [signatureCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async submitServerSignerSignatureEventResult( + serverSignerId: string, + signatureCreationEventResult?: SignatureCreationEventResult, + options?: RawAxiosRequestConfig, + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.submitServerSignerSignatureEventResult( + serverSignerId, + signatureCreationEventResult, + options, + ); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["ServerSignersApi.submitServerSignerSignatureEventResult"]?.[ + localVarOperationServerIndex + ]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + }; +}; + +/** + * ServerSignersApi - factory interface + * @export + */ +export const ServerSignersApiFactory = function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance, +) { + const localVarFp = ServerSignersApiFp(configuration); + return { + /** + * Create a new Server-Signer + * @summary Create a new Server-Signer + * @param {CreateServerSignerRequest} [createServerSignerRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createServerSigner( + createServerSignerRequest?: CreateServerSignerRequest, + options?: any, + ): AxiosPromise { + return localVarFp + .createServerSigner(createServerSignerRequest, options) + .then(request => request(axios, basePath)); }, /** - * Get address - * @summary Get address by onchain address - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. + * Get a server signer by ID + * @summary Get a server signer by ID + * @param {string} serverSignerId The ID of the server signer to fetch * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAddress: async ( - walletId: string, - addressId: string, - options: RawAxiosRequestConfig = {}, - ): Promise => { - // verify required parameter 'walletId' is not null or undefined - assertParamExists("getAddress", "walletId", walletId); - // verify required parameter 'addressId' is not null or undefined - assertParamExists("getAddress", "addressId", addressId); - const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}` - .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) - .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))); - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } + getServerSigner(serverSignerId: string, options?: any): AxiosPromise { + return localVarFp + .getServerSigner(serverSignerId, options) + .then(request => request(axios, basePath)); + }, + /** + * List events for a server signer + * @summary List events for a server signer + * @param {string} serverSignerId The ID of the server signer to fetch events for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listServerSignerEvents( + serverSignerId: string, + limit?: number, + page?: string, + options?: any, + ): AxiosPromise { + return localVarFp + .listServerSignerEvents(serverSignerId, limit, page, options) + .then(request => request(axios, basePath)); + }, + /** + * List server signers for the current project + * @summary List server signers for the current project + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listServerSigners(options?: any): AxiosPromise { + return localVarFp.listServerSigners(options).then(request => request(axios, basePath)); + }, + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SeedCreationEventResult} [seedCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + submitServerSignerSeedEventResult( + serverSignerId: string, + seedCreationEventResult?: SeedCreationEventResult, + options?: any, + ): AxiosPromise { + return localVarFp + .submitServerSignerSeedEventResult(serverSignerId, seedCreationEventResult, options) + .then(request => request(axios, basePath)); + }, + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SignatureCreationEventResult} [signatureCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + submitServerSignerSignatureEventResult( + serverSignerId: string, + signatureCreationEventResult?: SignatureCreationEventResult, + options?: any, + ): AxiosPromise { + return localVarFp + .submitServerSignerSignatureEventResult( + serverSignerId, + signatureCreationEventResult, + options, + ) + .then(request => request(axios, basePath)); + }, + }; +}; - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; +/** + * ServerSignersApi - interface + * @export + * @interface ServerSignersApi + */ +export interface ServerSignersApiInterface { + /** + * Create a new Server-Signer + * @summary Create a new Server-Signer + * @param {CreateServerSignerRequest} [createServerSignerRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApiInterface + */ + createServerSigner( + createServerSignerRequest?: CreateServerSignerRequest, + options?: RawAxiosRequestConfig, + ): AxiosPromise; - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - }; + /** + * Get a server signer by ID + * @summary Get a server signer by ID + * @param {string} serverSignerId The ID of the server signer to fetch + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApiInterface + */ + getServerSigner( + serverSignerId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, + /** + * List events for a server signer + * @summary List events for a server signer + * @param {string} serverSignerId The ID of the server signer to fetch events for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApiInterface + */ + listServerSignerEvents( + serverSignerId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * List server signers for the current project + * @summary List server signers for the current project + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApiInterface + */ + listServerSigners(options?: RawAxiosRequestConfig): AxiosPromise; + + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SeedCreationEventResult} [seedCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApiInterface + */ + submitServerSignerSeedEventResult( + serverSignerId: string, + seedCreationEventResult?: SeedCreationEventResult, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SignatureCreationEventResult} [signatureCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApiInterface + */ + submitServerSignerSignatureEventResult( + serverSignerId: string, + signatureCreationEventResult?: SignatureCreationEventResult, + options?: RawAxiosRequestConfig, + ): AxiosPromise; +} + +/** + * ServerSignersApi - object-oriented interface + * @export + * @class ServerSignersApi + * @extends {BaseAPI} + */ +export class ServerSignersApi extends BaseAPI implements ServerSignersApiInterface { + /** + * Create a new Server-Signer + * @summary Create a new Server-Signer + * @param {CreateServerSignerRequest} [createServerSignerRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApi + */ + public createServerSigner( + createServerSignerRequest?: CreateServerSignerRequest, + options?: RawAxiosRequestConfig, + ) { + return ServerSignersApiFp(this.configuration) + .createServerSigner(createServerSignerRequest, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Get a server signer by ID + * @summary Get a server signer by ID + * @param {string} serverSignerId The ID of the server signer to fetch + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApi + */ + public getServerSigner(serverSignerId: string, options?: RawAxiosRequestConfig) { + return ServerSignersApiFp(this.configuration) + .getServerSigner(serverSignerId, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * List events for a server signer + * @summary List events for a server signer + * @param {string} serverSignerId The ID of the server signer to fetch events for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApi + */ + public listServerSignerEvents( + serverSignerId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ) { + return ServerSignersApiFp(this.configuration) + .listServerSignerEvents(serverSignerId, limit, page, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * List server signers for the current project + * @summary List server signers for the current project + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApi + */ + public listServerSigners(options?: RawAxiosRequestConfig) { + return ServerSignersApiFp(this.configuration) + .listServerSigners(options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SeedCreationEventResult} [seedCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApi + */ + public submitServerSignerSeedEventResult( + serverSignerId: string, + seedCreationEventResult?: SeedCreationEventResult, + options?: RawAxiosRequestConfig, + ) { + return ServerSignersApiFp(this.configuration) + .submitServerSignerSeedEventResult(serverSignerId, seedCreationEventResult, options) + .then(request => request(this.axios, this.basePath)); + } + + /** + * Submit the result of a server signer event + * @summary Submit the result of a server signer event + * @param {string} serverSignerId The ID of the server signer to submit the event result for + * @param {SignatureCreationEventResult} [signatureCreationEventResult] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerSignersApi + */ + public submitServerSignerSignatureEventResult( + serverSignerId: string, + signatureCreationEventResult?: SignatureCreationEventResult, + options?: RawAxiosRequestConfig, + ) { + return ServerSignersApiFp(this.configuration) + .submitServerSignerSignatureEventResult(serverSignerId, signatureCreationEventResult, options) + .then(request => request(this.axios, this.basePath)); + } +} + +/** + * TradesApi - axios parameter creator + * @export + */ +export const TradesApiAxiosParamCreator = function (configuration?: Configuration) { + return { /** - * Get address balance - * @summary Get address balance for asset - * @param {string} walletId The ID of the wallet to fetch the balance for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} assetId The symbol of the asset to fetch the balance for + * Broadcast a trade + * @summary Broadcast a trade + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to broadcast + * @param {BroadcastTradeRequest} broadcastTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAddressBalance: async ( + broadcastTrade: async ( walletId: string, addressId: string, - assetId: string, - options: RawAxiosRequestConfig = {}, - ): Promise => { - // verify required parameter 'walletId' is not null or undefined - assertParamExists("getAddressBalance", "walletId", walletId); - // verify required parameter 'addressId' is not null or undefined - assertParamExists("getAddressBalance", "addressId", addressId); - // verify required parameter 'assetId' is not null or undefined - assertParamExists("getAddressBalance", "assetId", assetId); - const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/balances/{asset_id}` - .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) - .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))) - .replace(`{${"asset_id"}}`, encodeURIComponent(String(assetId))); + tradeId: string, + broadcastTradeRequest: BroadcastTradeRequest, + options: RawAxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'walletId' is not null or undefined + assertParamExists("broadcastTrade", "walletId", walletId); + // verify required parameter 'addressId' is not null or undefined + assertParamExists("broadcastTrade", "addressId", addressId); + // verify required parameter 'tradeId' is not null or undefined + assertParamExists("broadcastTrade", "tradeId", tradeId); + // verify required parameter 'broadcastTradeRequest' is not null or undefined + assertParamExists("broadcastTrade", "broadcastTradeRequest", broadcastTradeRequest); + const localVarPath = + `/v1/wallets/{wallet_id}/addresses/{address_id}/trades/{trade_id}/broadcast` + .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) + .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))) + .replace(`{${"trade_id"}}`, encodeURIComponent(String(tradeId))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; @@ -614,14 +2595,12 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; + localVarHeaderParameter["Content-Type"] = "application/json"; + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { @@ -629,6 +2608,11 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura ...headersFromBaseOptions, ...options.headers, }; + localVarRequestOptions.data = serializeDataIfNeeded( + broadcastTradeRequest, + localVarRequestOptions, + configuration, + ); return { url: toPathString(localVarUrlObj), @@ -636,25 +2620,27 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura }; }, /** - * Get address balances - * @summary Get all balances for address - * @param {string} walletId The ID of the wallet to fetch the balances for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * Create a new trade + * @summary Create a new trade for an address + * @param {string} walletId The ID of the wallet the source address belongs to + * @param {string} addressId The ID of the address to conduct the trade from + * @param {CreateTradeRequest} createTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - listAddressBalances: async ( + createTrade: async ( walletId: string, addressId: string, - page?: string, + createTradeRequest: CreateTradeRequest, options: RawAxiosRequestConfig = {}, ): Promise => { // verify required parameter 'walletId' is not null or undefined - assertParamExists("listAddressBalances", "walletId", walletId); + assertParamExists("createTrade", "walletId", walletId); // verify required parameter 'addressId' is not null or undefined - assertParamExists("listAddressBalances", "addressId", addressId); - const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/balances` + assertParamExists("createTrade", "addressId", addressId); + // verify required parameter 'createTradeRequest' is not null or undefined + assertParamExists("createTrade", "createTradeRequest", createTradeRequest); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/trades` .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))); // use dummy base URL string because the URL constructor only accepts absolute URLs. @@ -664,17 +2650,11 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; - if (page !== undefined) { - localVarQueryParameter["page"] = page; - } + localVarHeaderParameter["Content-Type"] = "application/json"; setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; @@ -683,6 +2663,11 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura ...headersFromBaseOptions, ...options.headers, }; + localVarRequestOptions.data = serializeDataIfNeeded( + createTradeRequest, + localVarRequestOptions, + configuration, + ); return { url: toPathString(localVarUrlObj), @@ -690,26 +2675,30 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura }; }, /** - * List addresses in the wallet. - * @summary List addresses in a wallet. - * @param {string} walletId The ID of the wallet whose addresses to fetch - * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * Get a trade by ID + * @summary Get a trade by ID + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to fetch * @param {*} [options] Override http request option. * @throws {RequiredError} */ - listAddresses: async ( + getTrade: async ( walletId: string, - limit?: number, - page?: string, + addressId: string, + tradeId: string, options: RawAxiosRequestConfig = {}, ): Promise => { // verify required parameter 'walletId' is not null or undefined - assertParamExists("listAddresses", "walletId", walletId); - const localVarPath = `/v1/wallets/{wallet_id}/addresses`.replace( - `{${"wallet_id"}}`, - encodeURIComponent(String(walletId)), - ); + assertParamExists("getTrade", "walletId", walletId); + // verify required parameter 'addressId' is not null or undefined + assertParamExists("getTrade", "addressId", addressId); + // verify required parameter 'tradeId' is not null or undefined + assertParamExists("getTrade", "tradeId", tradeId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/trades/{trade_id}` + .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) + .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))) + .replace(`{${"trade_id"}}`, encodeURIComponent(String(tradeId))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); let baseOptions; @@ -717,22 +2706,10 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; - if (limit !== undefined) { - localVarQueryParameter["limit"] = limit; - } - - if (page !== undefined) { - localVarQueryParameter["page"] = page; - } - setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { @@ -747,23 +2724,27 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura }; }, /** - * Request faucet funds to be sent to onchain address. - * @summary Request faucet funds for onchain address. - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. + * List trades for an address. + * @summary List trades for an address. + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address to list trades for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - requestFaucetFunds: async ( + listTrades: async ( walletId: string, addressId: string, + limit?: number, + page?: string, options: RawAxiosRequestConfig = {}, ): Promise => { // verify required parameter 'walletId' is not null or undefined - assertParamExists("requestFaucetFunds", "walletId", walletId); + assertParamExists("listTrades", "walletId", walletId); // verify required parameter 'addressId' is not null or undefined - assertParamExists("requestFaucetFunds", "addressId", addressId); - const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/faucet` + assertParamExists("listTrades", "addressId", addressId); + const localVarPath = `/v1/wallets/{wallet_id}/addresses/{address_id}/trades` .replace(`{${"wallet_id"}}`, encodeURIComponent(String(walletId))) .replace(`{${"address_id"}}`, encodeURIComponent(String(addressId))); // use dummy base URL string because the URL constructor only accepts absolute URLs. @@ -773,14 +2754,18 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "POST", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; + if (limit !== undefined) { + localVarQueryParameter["limit"] = limit; + } + + if (page !== undefined) { + localVarQueryParameter["page"] = page; + } + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { @@ -798,62 +2783,39 @@ export const AddressesApiAxiosParamCreator = function (configuration?: Configura }; /** - * AddressesApi - functional programming interface + * TradesApi - functional programming interface * @export */ -export const AddressesApiFp = function (configuration?: Configuration) { - const localVarAxiosParamCreator = AddressesApiAxiosParamCreator(configuration); +export const TradesApiFp = function (configuration?: Configuration) { + const localVarAxiosParamCreator = TradesApiAxiosParamCreator(configuration); return { /** - * Create a new address scoped to the wallet. - * @summary Create a new address - * @param {string} walletId The ID of the wallet to create the address in. - * @param {CreateAddressRequest} [createAddressRequest] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async createAddress( - walletId: string, - createAddressRequest?: CreateAddressRequest, - options?: RawAxiosRequestConfig, - ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise
> { - const localVarAxiosArgs = await localVarAxiosParamCreator.createAddress( - walletId, - createAddressRequest, - options, - ); - const localVarOperationServerIndex = configuration?.serverIndex ?? 0; - const localVarOperationServerBasePath = - operationServerMap["AddressesApi.createAddress"]?.[localVarOperationServerIndex]?.url; - return (axios, basePath) => - createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration, - )(axios, localVarOperationServerBasePath || basePath); - }, - /** - * Get address - * @summary Get address by onchain address - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. + * Broadcast a trade + * @summary Broadcast a trade + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to broadcast + * @param {BroadcastTradeRequest} broadcastTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getAddress( + async broadcastTrade( walletId: string, addressId: string, + tradeId: string, + broadcastTradeRequest: BroadcastTradeRequest, options?: RawAxiosRequestConfig, - ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise
> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getAddress( + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.broadcastTrade( walletId, addressId, + tradeId, + broadcastTradeRequest, options, ); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = - operationServerMap["AddressesApi.getAddress"]?.[localVarOperationServerIndex]?.url; + operationServerMap["TradesApi.broadcastTrade"]?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction( localVarAxiosArgs, @@ -863,29 +2825,29 @@ export const AddressesApiFp = function (configuration?: Configuration) { )(axios, localVarOperationServerBasePath || basePath); }, /** - * Get address balance - * @summary Get address balance for asset - * @param {string} walletId The ID of the wallet to fetch the balance for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} assetId The symbol of the asset to fetch the balance for + * Create a new trade + * @summary Create a new trade for an address + * @param {string} walletId The ID of the wallet the source address belongs to + * @param {string} addressId The ID of the address to conduct the trade from + * @param {CreateTradeRequest} createTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getAddressBalance( + async createTrade( walletId: string, addressId: string, - assetId: string, + createTradeRequest: CreateTradeRequest, options?: RawAxiosRequestConfig, - ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getAddressBalance( + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createTrade( walletId, addressId, - assetId, + createTradeRequest, options, ); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = - operationServerMap["AddressesApi.getAddressBalance"]?.[localVarOperationServerIndex]?.url; + operationServerMap["TradesApi.createTrade"]?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction( localVarAxiosArgs, @@ -895,29 +2857,29 @@ export const AddressesApiFp = function (configuration?: Configuration) { )(axios, localVarOperationServerBasePath || basePath); }, /** - * Get address balances - * @summary Get all balances for address - * @param {string} walletId The ID of the wallet to fetch the balances for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * Get a trade by ID + * @summary Get a trade by ID + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to fetch * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async listAddressBalances( + async getTrade( walletId: string, addressId: string, - page?: string, + tradeId: string, options?: RawAxiosRequestConfig, - ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.listAddressBalances( + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getTrade( walletId, addressId, - page, + tradeId, options, ); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = - operationServerMap["AddressesApi.listAddressBalances"]?.[localVarOperationServerIndex]?.url; + operationServerMap["TradesApi.getTrade"]?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction( localVarAxiosArgs, @@ -927,58 +2889,32 @@ export const AddressesApiFp = function (configuration?: Configuration) { )(axios, localVarOperationServerBasePath || basePath); }, /** - * List addresses in the wallet. - * @summary List addresses in a wallet. - * @param {string} walletId The ID of the wallet whose addresses to fetch + * List trades for an address. + * @summary List trades for an address. + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address to list trades for * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async listAddresses( + async listTrades( walletId: string, + addressId: string, limit?: number, page?: string, options?: RawAxiosRequestConfig, - ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.listAddresses( + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.listTrades( walletId, + addressId, limit, page, options, ); const localVarOperationServerIndex = configuration?.serverIndex ?? 0; const localVarOperationServerBasePath = - operationServerMap["AddressesApi.listAddresses"]?.[localVarOperationServerIndex]?.url; - return (axios, basePath) => - createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration, - )(axios, localVarOperationServerBasePath || basePath); - }, - /** - * Request faucet funds to be sent to onchain address. - * @summary Request faucet funds for onchain address. - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async requestFaucetFunds( - walletId: string, - addressId: string, - options?: RawAxiosRequestConfig, - ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.requestFaucetFunds( - walletId, - addressId, - options, - ); - const localVarOperationServerIndex = configuration?.serverIndex ?? 0; - const localVarOperationServerBasePath = - operationServerMap["AddressesApi.requestFaucetFunds"]?.[localVarOperationServerIndex]?.url; + operationServerMap["TradesApi.listTrades"]?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction( localVarAxiosArgs, @@ -991,239 +2927,270 @@ export const AddressesApiFp = function (configuration?: Configuration) { }; /** - * AddressesApi - factory interface + * TradesApi - factory interface * @export */ -export const AddressesApiFactory = function ( +export const TradesApiFactory = function ( configuration?: Configuration, basePath?: string, axios?: AxiosInstance, ) { - const localVarFp = AddressesApiFp(configuration); + const localVarFp = TradesApiFp(configuration); return { /** - * Create a new address scoped to the wallet. - * @summary Create a new address - * @param {string} walletId The ID of the wallet to create the address in. - * @param {CreateAddressRequest} [createAddressRequest] + * Broadcast a trade + * @summary Broadcast a trade + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to broadcast + * @param {BroadcastTradeRequest} broadcastTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - createAddress( + broadcastTrade( walletId: string, - createAddressRequest?: CreateAddressRequest, + addressId: string, + tradeId: string, + broadcastTradeRequest: BroadcastTradeRequest, options?: any, - ): AxiosPromise
{ - return localVarFp - .createAddress(walletId, createAddressRequest, options) - .then(request => request(axios, basePath)); - }, - /** - * Get address - * @summary Get address by onchain address - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getAddress(walletId: string, addressId: string, options?: any): AxiosPromise
{ + ): AxiosPromise { return localVarFp - .getAddress(walletId, addressId, options) + .broadcastTrade(walletId, addressId, tradeId, broadcastTradeRequest, options) .then(request => request(axios, basePath)); }, /** - * Get address balance - * @summary Get address balance for asset - * @param {string} walletId The ID of the wallet to fetch the balance for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} assetId The symbol of the asset to fetch the balance for + * Create a new trade + * @summary Create a new trade for an address + * @param {string} walletId The ID of the wallet the source address belongs to + * @param {string} addressId The ID of the address to conduct the trade from + * @param {CreateTradeRequest} createTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAddressBalance( + createTrade( walletId: string, addressId: string, - assetId: string, + createTradeRequest: CreateTradeRequest, options?: any, - ): AxiosPromise { + ): AxiosPromise { return localVarFp - .getAddressBalance(walletId, addressId, assetId, options) + .createTrade(walletId, addressId, createTradeRequest, options) .then(request => request(axios, basePath)); }, /** - * Get address balances - * @summary Get all balances for address - * @param {string} walletId The ID of the wallet to fetch the balances for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * Get a trade by ID + * @summary Get a trade by ID + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to fetch * @param {*} [options] Override http request option. * @throws {RequiredError} */ - listAddressBalances( + getTrade( walletId: string, addressId: string, - page?: string, + tradeId: string, options?: any, - ): AxiosPromise { + ): AxiosPromise { return localVarFp - .listAddressBalances(walletId, addressId, page, options) + .getTrade(walletId, addressId, tradeId, options) .then(request => request(axios, basePath)); }, /** - * List addresses in the wallet. - * @summary List addresses in a wallet. - * @param {string} walletId The ID of the wallet whose addresses to fetch + * List trades for an address. + * @summary List trades for an address. + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address to list trades for * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - listAddresses( - walletId: string, - limit?: number, - page?: string, - options?: any, - ): AxiosPromise { - return localVarFp - .listAddresses(walletId, limit, page, options) - .then(request => request(axios, basePath)); - }, - /** - * Request faucet funds to be sent to onchain address. - * @summary Request faucet funds for onchain address. - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - requestFaucetFunds( + listTrades( walletId: string, addressId: string, + limit?: number, + page?: string, options?: any, - ): AxiosPromise { + ): AxiosPromise { return localVarFp - .requestFaucetFunds(walletId, addressId, options) + .listTrades(walletId, addressId, limit, page, options) .then(request => request(axios, basePath)); }, }; }; /** - * AddressesApi - object-oriented interface + * TradesApi - interface * @export - * @class AddressesApi - * @extends {BaseAPI} + * @interface TradesApi */ -export class AddressesApi extends BaseAPI { +export interface TradesApiInterface { /** - * Create a new address scoped to the wallet. - * @summary Create a new address - * @param {string} walletId The ID of the wallet to create the address in. - * @param {CreateAddressRequest} [createAddressRequest] + * Broadcast a trade + * @summary Broadcast a trade + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to broadcast + * @param {BroadcastTradeRequest} broadcastTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof AddressesApi + * @memberof TradesApiInterface */ - public createAddress( + broadcastTrade( walletId: string, - createAddressRequest?: CreateAddressRequest, + addressId: string, + tradeId: string, + broadcastTradeRequest: BroadcastTradeRequest, options?: RawAxiosRequestConfig, - ) { - return AddressesApiFp(this.configuration) - .createAddress(walletId, createAddressRequest, options) - .then(request => request(this.axios, this.basePath)); - } + ): AxiosPromise; /** - * Get address - * @summary Get address by onchain address - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. + * Create a new trade + * @summary Create a new trade for an address + * @param {string} walletId The ID of the wallet the source address belongs to + * @param {string} addressId The ID of the address to conduct the trade from + * @param {CreateTradeRequest} createTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof AddressesApi + * @memberof TradesApiInterface */ - public getAddress(walletId: string, addressId: string, options?: RawAxiosRequestConfig) { - return AddressesApiFp(this.configuration) - .getAddress(walletId, addressId, options) - .then(request => request(this.axios, this.basePath)); - } + createTrade( + walletId: string, + addressId: string, + createTradeRequest: CreateTradeRequest, + options?: RawAxiosRequestConfig, + ): AxiosPromise; /** - * Get address balance - * @summary Get address balance for asset - * @param {string} walletId The ID of the wallet to fetch the balance for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} assetId The symbol of the asset to fetch the balance for + * Get a trade by ID + * @summary Get a trade by ID + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to fetch * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof AddressesApi + * @memberof TradesApiInterface */ - public getAddressBalance( + getTrade( walletId: string, addressId: string, - assetId: string, + tradeId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * List trades for an address. + * @summary List trades for an address. + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address to list trades for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TradesApiInterface + */ + listTrades( + walletId: string, + addressId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; +} + +/** + * TradesApi - object-oriented interface + * @export + * @class TradesApi + * @extends {BaseAPI} + */ +export class TradesApi extends BaseAPI implements TradesApiInterface { + /** + * Broadcast a trade + * @summary Broadcast a trade + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to broadcast + * @param {BroadcastTradeRequest} broadcastTradeRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TradesApi + */ + public broadcastTrade( + walletId: string, + addressId: string, + tradeId: string, + broadcastTradeRequest: BroadcastTradeRequest, options?: RawAxiosRequestConfig, ) { - return AddressesApiFp(this.configuration) - .getAddressBalance(walletId, addressId, assetId, options) + return TradesApiFp(this.configuration) + .broadcastTrade(walletId, addressId, tradeId, broadcastTradeRequest, options) .then(request => request(this.axios, this.basePath)); } /** - * Get address balances - * @summary Get all balances for address - * @param {string} walletId The ID of the wallet to fetch the balances for - * @param {string} addressId The onchain address of the address that is being fetched. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * Create a new trade + * @summary Create a new trade for an address + * @param {string} walletId The ID of the wallet the source address belongs to + * @param {string} addressId The ID of the address to conduct the trade from + * @param {CreateTradeRequest} createTradeRequest * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof AddressesApi + * @memberof TradesApi */ - public listAddressBalances( + public createTrade( walletId: string, addressId: string, - page?: string, + createTradeRequest: CreateTradeRequest, options?: RawAxiosRequestConfig, ) { - return AddressesApiFp(this.configuration) - .listAddressBalances(walletId, addressId, page, options) + return TradesApiFp(this.configuration) + .createTrade(walletId, addressId, createTradeRequest, options) .then(request => request(this.axios, this.basePath)); } /** - * List addresses in the wallet. - * @summary List addresses in a wallet. - * @param {string} walletId The ID of the wallet whose addresses to fetch - * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. - * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * Get a trade by ID + * @summary Get a trade by ID + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the trade belongs to + * @param {string} tradeId The ID of the trade to fetch * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof AddressesApi + * @memberof TradesApi */ - public listAddresses( + public getTrade( walletId: string, - limit?: number, - page?: string, + addressId: string, + tradeId: string, options?: RawAxiosRequestConfig, ) { - return AddressesApiFp(this.configuration) - .listAddresses(walletId, limit, page, options) + return TradesApiFp(this.configuration) + .getTrade(walletId, addressId, tradeId, options) .then(request => request(this.axios, this.basePath)); } /** - * Request faucet funds to be sent to onchain address. - * @summary Request faucet funds for onchain address. - * @param {string} walletId The ID of the wallet the address belongs to. - * @param {string} addressId The onchain address of the address that is being fetched. + * List trades for an address. + * @summary List trades for an address. + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address to list trades for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof AddressesApi + * @memberof TradesApi */ - public requestFaucetFunds(walletId: string, addressId: string, options?: RawAxiosRequestConfig) { - return AddressesApiFp(this.configuration) - .requestFaucetFunds(walletId, addressId, options) + public listTrades( + walletId: string, + addressId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ) { + return TradesApiFp(this.configuration) + .listTrades(walletId, addressId, limit, page, options) .then(request => request(this.axios, this.basePath)); } } @@ -1271,11 +3238,7 @@ export const TransfersApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "POST", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -1330,11 +3293,7 @@ export const TransfersApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "POST", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -1390,11 +3349,7 @@ export const TransfersApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -1442,11 +3397,7 @@ export const TransfersApiAxiosParamCreator = function (configuration?: Configura baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -1712,13 +3663,92 @@ export const TransfersApiFactory = function ( }; }; +/** + * TransfersApi - interface + * @export + * @interface TransfersApi + */ +export interface TransfersApiInterface { + /** + * Broadcast a transfer + * @summary Broadcast a transfer + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the transfer belongs to + * @param {string} transferId The ID of the transfer to broadcast + * @param {BroadcastTransferRequest} broadcastTransferRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TransfersApiInterface + */ + broadcastTransfer( + walletId: string, + addressId: string, + transferId: string, + broadcastTransferRequest: BroadcastTransferRequest, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * Create a new transfer + * @summary Create a new transfer for an address + * @param {string} walletId The ID of the wallet the source address belongs to + * @param {string} addressId The ID of the address to transfer from + * @param {CreateTransferRequest} createTransferRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TransfersApiInterface + */ + createTransfer( + walletId: string, + addressId: string, + createTransferRequest: CreateTransferRequest, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * Get a transfer by ID + * @summary Get a transfer by ID + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address the transfer belongs to + * @param {string} transferId The ID of the transfer to fetch + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TransfersApiInterface + */ + getTransfer( + walletId: string, + addressId: string, + transferId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * List transfers for an address. + * @summary List transfers for an address. + * @param {string} walletId The ID of the wallet the address belongs to + * @param {string} addressId The ID of the address to list transfers for + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TransfersApiInterface + */ + listTransfers( + walletId: string, + addressId: string, + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; +} + /** * TransfersApi - object-oriented interface * @export * @class TransfersApi * @extends {BaseAPI} */ -export class TransfersApi extends BaseAPI { +export class TransfersApi extends BaseAPI implements TransfersApiInterface { /** * Broadcast a transfer * @summary Broadcast a transfer @@ -1829,11 +3859,7 @@ export const UsersApiAxiosParamCreator = function (configuration?: Configuration baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -1907,13 +3933,29 @@ export const UsersApiFactory = function ( }; }; +/** + * UsersApi - interface + * @export + * @interface UsersApi + */ +export interface UsersApiInterface { + /** + * Get current user + * @summary Get current user + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UsersApiInterface + */ + getCurrentUser(options?: RawAxiosRequestConfig): AxiosPromise; +} + /** * UsersApi - object-oriented interface * @export * @class UsersApi * @extends {BaseAPI} */ -export class UsersApi extends BaseAPI { +export class UsersApi extends BaseAPI implements UsersApiInterface { /** * Get current user * @summary Get current user @@ -1953,11 +3995,7 @@ export const WalletsApiAxiosParamCreator = function (configuration?: Configurati baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "POST", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "POST", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -2005,11 +4043,7 @@ export const WalletsApiAxiosParamCreator = function (configuration?: Configurati baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -2053,11 +4087,7 @@ export const WalletsApiAxiosParamCreator = function (configuration?: Configurati baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -2098,11 +4128,7 @@ export const WalletsApiAxiosParamCreator = function (configuration?: Configurati baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -2140,11 +4166,7 @@ export const WalletsApiAxiosParamCreator = function (configuration?: Configurati baseOptions = configuration.baseOptions; } - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; + const localVarRequestOptions = { method: "GET", ...baseOptions, ...options }; const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -2383,13 +4405,86 @@ export const WalletsApiFactory = function ( }; }; +/** + * WalletsApi - interface + * @export + * @interface WalletsApi + */ +export interface WalletsApiInterface { + /** + * Create a new wallet scoped to the user. + * @summary Create a new wallet + * @param {CreateWalletRequest} [createWalletRequest] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof WalletsApiInterface + */ + createWallet( + createWalletRequest?: CreateWalletRequest, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * Get wallet + * @summary Get wallet by ID + * @param {string} walletId The ID of the wallet to fetch + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof WalletsApiInterface + */ + getWallet(walletId: string, options?: RawAxiosRequestConfig): AxiosPromise; + + /** + * Get the aggregated balance of an asset across all of the addresses in the wallet. + * @summary Get the balance of an asset in the wallet + * @param {string} walletId The ID of the wallet to fetch the balance for + * @param {string} assetId The symbol of the asset to fetch the balance for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof WalletsApiInterface + */ + getWalletBalance( + walletId: string, + assetId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * List the balances of all of the addresses in the wallet aggregated by asset. + * @summary List wallet balances + * @param {string} walletId The ID of the wallet to fetch the balances for + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof WalletsApiInterface + */ + listWalletBalances( + walletId: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; + + /** + * List wallets belonging to the user. + * @summary List wallets + * @param {number} [limit] A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + * @param {string} [page] A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof WalletsApiInterface + */ + listWallets( + limit?: number, + page?: string, + options?: RawAxiosRequestConfig, + ): AxiosPromise; +} + /** * WalletsApi - object-oriented interface * @export * @class WalletsApi * @extends {BaseAPI} */ -export class WalletsApi extends BaseAPI { +export class WalletsApi extends BaseAPI implements WalletsApiInterface { /** * Create a new wallet scoped to the user. * @summary Create a new wallet diff --git a/src/client/common.ts b/src/client/common.ts index dafa34a3..33f7c8af 100644 --- a/src/client/common.ts +++ b/src/client/common.ts @@ -65,10 +65,7 @@ export const setApiKeyToObject = async function ( */ export const setBasicAuthToObject = function (object: any, configuration?: Configuration) { if (configuration && (configuration.username || configuration.password)) { - object["auth"] = { - username: configuration.username, - password: configuration.password, - }; + object["auth"] = { username: configuration.username, password: configuration.password }; } }; diff --git a/src/coinbase/address.ts b/src/coinbase/address.ts index 827ef542..e8939e1b 100644 --- a/src/coinbase/address.ts +++ b/src/coinbase/address.ts @@ -162,7 +162,7 @@ export class Address { intervalSeconds = 0.2, timeoutSeconds = 10, ): Promise { - if (!this.key) { + if (!Coinbase.useServerSigner && !this.key) { throw new InternalError("Cannot transfer from address without private key loaded"); } let normalizedAmount = new Decimal(amount.toString()); @@ -218,29 +218,33 @@ export class Address { createTransferRequest, ); - const transfer = Transfer.fromModel(response.data); - const transaction = transfer.getTransaction(); - let signedPayload = await this.key.signTransaction(transaction); - signedPayload = signedPayload.slice(2); + let transfer = Transfer.fromModel(response.data); - const broadcastTransferRequest = { - signed_payload: signedPayload, - }; + if (!Coinbase.useServerSigner) { + const transaction = transfer.getTransaction(); + let signedPayload = await this.key!.signTransaction(transaction); + signedPayload = signedPayload.slice(2); - response = await Coinbase.apiClients.transfer!.broadcastTransfer( - this.getWalletId(), - this.getId(), - transfer.getId(), - broadcastTransferRequest, - ); + const broadcastTransferRequest = { + signed_payload: signedPayload, + }; - const updatedTransfer = Transfer.fromModel(response.data); + response = await Coinbase.apiClients.transfer!.broadcastTransfer( + this.getWalletId(), + this.getId(), + transfer.getId(), + broadcastTransferRequest, + ); + + transfer = Transfer.fromModel(response.data); + } const startTime = Date.now(); while (Date.now() - startTime < timeoutSeconds * 1000) { - const status = await updatedTransfer.getStatus(); + await transfer.reload(); + const status = transfer.getStatus(); if (status === TransferStatus.COMPLETE || status === TransferStatus.FAILED) { - return updatedTransfer; + return transfer; } await delay(intervalSeconds); } diff --git a/src/coinbase/coinbase.ts b/src/coinbase/coinbase.ts index 7f5f25a3..1c4a53b8 100644 --- a/src/coinbase/coinbase.ts +++ b/src/coinbase/coinbase.ts @@ -51,12 +51,20 @@ export class Coinbase { */ static apiKeyPrivateKey: string; + /** + * Whether to use server signer or not. + * + * @constant + */ + static useServerSigner: boolean; + /** * Initializes the Coinbase SDK. * * @class * @param apiKeyName - The API key name. * @param privateKey - The private key associated with the API key. + * @param useServerSigner - Whether to use server signer or not. * @param debugging - If true, logs API requests and responses to the console. * @param basePath - The base path for the API. * @throws {InternalError} If the configuration is invalid. @@ -65,6 +73,7 @@ export class Coinbase { constructor( apiKeyName: string, privateKey: string, + useServerSigner: boolean = false, debugging = false, basePath: string = BASE_PATH, ) { @@ -93,12 +102,14 @@ export class Coinbase { "https://sepolia.base.org", ); Coinbase.apiKeyPrivateKey = privateKey; + Coinbase.useServerSigner = useServerSigner; } /** * Reads the API key and private key from a JSON file and initializes the Coinbase SDK. * * @param filePath - The path to the JSON file containing the API key and private key. + * @param useServerSigner - Whether to use server signer or not. * @param debugging - If true, logs API requests and responses to the console. * @param basePath - The base path for the API. * @returns A new instance of the Coinbase SDK. @@ -108,6 +119,7 @@ export class Coinbase { */ static configureFromJson( filePath: string = "coinbase_cloud_api_key.json", + useServerSigner: boolean = false, debugging: boolean = false, basePath: string = BASE_PATH, ): Coinbase { @@ -121,7 +133,7 @@ export class Coinbase { throw new InvalidAPIKeyFormat("Invalid configuration: missing configuration values"); } - return new Coinbase(config.name, config.privateKey, debugging, basePath); + return new Coinbase(config.name, config.privateKey, useServerSigner, debugging, basePath); } catch (e) { if (e instanceof SyntaxError) { throw new InvalidAPIKeyFormat("Not able to parse the configuration file"); diff --git a/src/coinbase/transfer.ts b/src/coinbase/transfer.ts index f0bbafd2..c1ffe2ee 100644 --- a/src/coinbase/transfer.ts +++ b/src/coinbase/transfer.ts @@ -188,18 +188,19 @@ export class Transfer { * * @returns The Status of the Transfer. */ - public async getStatus(): Promise { - const transactionHash = this.getTransactionHash(); - if (!transactionHash) return TransferStatus.PENDING; - - const onchainTransaction = - await Coinbase.apiClients.baseSepoliaProvider!.getTransaction(transactionHash); - if (!onchainTransaction) return TransferStatus.PENDING; - if (!onchainTransaction.blockHash) return TransferStatus.BROADCAST; - - const transactionReceipt = - await Coinbase.apiClients.baseSepoliaProvider!.getTransactionReceipt(transactionHash); - return transactionReceipt?.status ? TransferStatus.COMPLETE : TransferStatus.FAILED; + public getStatus(): TransferStatus | undefined { + switch (this.model.status) { + case TransferStatus.PENDING: + return TransferStatus.PENDING; + case TransferStatus.BROADCAST: + return TransferStatus.BROADCAST; + case TransferStatus.COMPLETE: + return TransferStatus.COMPLETE; + case TransferStatus.FAILED: + return TransferStatus.FAILED; + default: + return undefined; + } } /** @@ -211,18 +212,31 @@ export class Transfer { return `https://sepolia.basescan.org/tx/${this.getTransactionHash()}`; } + /** + * Reloads the Transfer model with the latest data from the server. + * + * @throws {APIError} if the API request to get a Transfer fails. + */ + public async reload(): Promise { + const result = await Coinbase.apiClients.transfer!.getTransfer( + this.getWalletId(), + this.getFromAddressId(), + this.getId(), + ); + this.model = result?.data; + } + /** * Returns a string representation of the Transfer. * * @returns The string representation of the Transfer. */ public async toString(): Promise { - const status = await this.getStatus(); return ( `Transfer{transferId: '${this.getId()}', networkId: '${this.getNetworkId()}', ` + `fromAddressId: '${this.getFromAddressId()}', destinationAddressId: '${this.getDestinationAddressId()}', ` + `assetId: '${this.getAssetId()}', amount: '${this.getAmount()}', transactionHash: '${this.getTransactionHash()}', ` + - `transactionLink: '${this.getTransactionLink()}', status: '${status}'}` + `transactionLink: '${this.getTransactionLink()}', status: '${this.getStatus()}'}` ); } } diff --git a/src/coinbase/types.ts b/src/coinbase/types.ts index c983ad6d..24e5ad2c 100644 --- a/src/coinbase/types.ts +++ b/src/coinbase/types.ts @@ -305,10 +305,10 @@ export type ApiClients = { * Transfer status type definition. */ export enum TransferStatus { - PENDING = "PENDING", - BROADCAST = "BROADCAST", - COMPLETE = "COMPLETE", - FAILED = "FAILED", + PENDING = "pending", + BROADCAST = "broadcast", + COMPLETE = "complete", + FAILED = "failed", } /** @@ -339,3 +339,11 @@ export type Amount = number | bigint | Decimal; * Destination type definition. */ export type Destination = string | Address | Wallet; + +/** + * ServerSigner status type definition. + */ +export enum ServerSignerStatus { + PENDING = "pending_seed_creation", + ACTIVE = "active_seed", +} diff --git a/src/coinbase/wallet.ts b/src/coinbase/wallet.ts index 0ec5ea2a..615a0836 100644 --- a/src/coinbase/wallet.ts +++ b/src/coinbase/wallet.ts @@ -9,8 +9,8 @@ import { Address } from "./address"; import { Coinbase } from "./coinbase"; import { ArgumentError, InternalError } from "./errors"; import { Transfer } from "./transfer"; -import { Amount, Destination, SeedData, WalletData } from "./types"; -import { convertStringToHex } from "./utils"; +import { Amount, Destination, SeedData, WalletData, ServerSignerStatus } from "./types"; +import { convertStringToHex, delay } from "./utils"; import { FaucetTransaction } from "./faucet_transaction"; import { BalanceMap } from "./balance_map"; import Decimal from "decimal.js"; @@ -69,17 +69,47 @@ export class Wallet { const result = await Coinbase.apiClients.wallet!.createWallet({ wallet: { network_id: Coinbase.networkList.BaseSepolia, + use_server_signer: Coinbase.useServerSigner, }, }); const wallet = await Wallet.init(result.data, undefined, []); + if (Coinbase.useServerSigner) { + await wallet.waitForSigner(wallet.getId()!); + } + await wallet.createAddress(); await wallet.reload(); return wallet; } + /** + * Waits until the ServerSigner has created a seed for the Wallet. + * + * @param walletId - The ID of the Wallet that is awaiting seed creation. + * @param intervalSeconds - The interval at which to poll the CDPService, in seconds. + * @param timeoutSeconds - The maximum amount of time to wait for the ServerSigner to create a seed, in seconds. + * @throws {APIError} if the API request to get a Wallet fails. + * @throws {Error} if the ServerSigner times out. + */ + private async waitForSigner( + walletId: string, + intervalSeconds = 0.2, + timeoutSeconds = 20, + ): Promise { + const startTime = Date.now(); + while (Date.now() - startTime < timeoutSeconds * 1000) { + const response = await Coinbase.apiClients.wallet!.getWallet(walletId); + if (response?.data.server_signer_status === ServerSignerStatus.ACTIVE) { + return; + } + await delay(intervalSeconds); + } + throw new Error("Wallet creation timed out. Check status of your Server-Signer"); + } + /** * Returns a new Wallet object. Do not use this method directly. Instead, use User.createWallet or User.importWallet. * @@ -100,6 +130,10 @@ export class Wallet { ): Promise { this.validateSeedAndAddressModels(seed, addressModels); + if (Coinbase.useServerSigner) { + return new Wallet(model, undefined, undefined, addressModels); + } + const seedAndMaster = this.getSeedAndMasterKey(seed); const wallet = new Wallet(model, seedAndMaster.master, seedAndMaster.seed, addressModels); wallet.deriveAddresses(addressModels); @@ -111,6 +145,8 @@ export class Wallet { * Exports the Wallet's data to a WalletData object. * * @returns The Wallet's data. + * @throws {APIError} - If the request fails. + */ public export(): WalletData { if (!this.seed) { @@ -140,15 +176,18 @@ export class Wallet { * @throws {APIError} - If the address creation fails. */ public async createAddress(): Promise
{ - const hdKey = this.deriveKey(); - const attestation = this.createAttestation(hdKey); - const publicKey = convertStringToHex(hdKey.publicKey!); - const key = new ethers.Wallet(convertStringToHex(hdKey.privateKey!)); - - const payload = { - public_key: publicKey, - attestation: attestation, - }; + let payload, key; + if (!Coinbase.useServerSigner) { + const hdKey = this.deriveKey(); + const attestation = this.createAttestation(hdKey); + const publicKey = convertStringToHex(hdKey.publicKey!); + key = new ethers.Wallet(convertStringToHex(hdKey.privateKey!)); + + payload = { + public_key: publicKey, + attestation: attestation, + }; + } const response = await Coinbase.apiClients.address!.createAddress(this.model.id!, payload); this.cacheAddress(response!.data, key); @@ -188,6 +227,8 @@ export class Wallet { /** * Reloads the Wallet model with the latest data from the server. + * + * @throws {APIError} if the API request to get a Wallet fails. */ private async reload(): Promise { const result = await Coinbase.apiClients.wallet!.getWallet(this.model.id!); @@ -325,6 +366,22 @@ export class Wallet { return this.model.network_id; } + /** + * Returns the ServerSigner Status of the Wallet. + * + * @returns the ServerSigner Status. + */ + public getServerSignerStatus(): ServerSignerStatus | undefined { + switch (this.model.server_signer_status) { + case ServerSignerStatus.PENDING: + return ServerSignerStatus.PENDING; + case ServerSignerStatus.ACTIVE: + return ServerSignerStatus.ACTIVE; + default: + return undefined; + } + } + /** * Returns the wallet ID. *