import {z} from 'zod' export type GetApiTransferCryptoDestinationAddressesArgs = {ids?: Array | undefined, identity_ids?: Array | undefined, crypto_networks?: (Array<'BITCOIN' | 'ETHEREUM' | 'BITCOIN_CASH' | 'LITECOIN' | 'SOLANA' | 'POLYGON_POS' | 'BASE' | 'ARBITRUM_ONE' | 'STELLAR' | 'INK' | 'XLAYER' | 'AVALANCHE' | 'DOGECOIN' | 'SUI' | 'ROBINHOOD' | 'BNB'>) | undefined, addresses?: Array | undefined, nicknames?: Array | undefined, bookmarked_status?: boolean | undefined, 'created_at.lt'?: string | undefined, 'created_at.lte'?: string | undefined, 'created_at.eq'?: string | undefined, 'created_at.gte'?: string | undefined, 'created_at.gt'?: string | undefined, limit?: number | undefined, order?: ('DESC' | 'ASC') | undefined, order_by?: 'CREATED_AT' | undefined, page_cursor?: string | undefined}; export type GetApiTransferCryptoDestinationAddressesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const cryptoNetwork = z.enum(["BITCOIN", "ETHEREUM", "BITCOIN_CASH", "LITECOIN", "SOLANA", "POLYGON_POS", "BASE", "ARBITRUM_ONE", "STELLAR", "INK", "XLAYER", "AVALANCHE", "DOGECOIN", "SUI", "ROBINHOOD", "BNB"]); export const cryptoDestinationAddressStatus = z.enum(["PENDING", "APPROVED", "REJECTED"]); export const geographicAddress = z.object({country: z.string(), address1: z.string().max(35).optional(), address2: z.string().max(35).optional(), city: z.string().max(35).optional(), province: z.string().max(35).optional(), zip_code: z.string().max(35).optional()}); export const beneficiaryPerson = z.object({first_name: z.string(), last_name: z.string(), physical_address: geographicAddress.optional()}); export const beneficiaryInstitution = z.object({name: z.string(), physical_address: geographicAddress.optional()}); export const beneficiary = z.object({person_details: beneficiaryPerson.optional(), institution_details: beneficiaryInstitution.optional(), self: z.boolean().optional()}); export const cryptoDestinationAddressVasp = z.object({id: z.string().optional(), name: z.string().optional(), custom_vasp_name: z.string().optional(), custom_vasp_website: z.string().optional()}); export const custodianType = z.enum(["VASP", "PRIVATE"]); export const cryptoDestinationAddressTravelruleMetadata = z.object({beneficiary: beneficiary.optional(), vasp: cryptoDestinationAddressVasp.optional(), custodian_type: custodianType.optional(), transfer_purpose: z.string().optional()}); export const cryptoDestinationAddress = z.object({id: z.string(), identity_id: z.string().optional(), crypto_network: cryptoNetwork, address: z.string(), nickname: z.string().optional(), status: cryptoDestinationAddressStatus.optional(), created_at: z.string().optional(), bookmarked: z.boolean().optional(), policy_execution_id: z.string().optional(), travelrule_metadata: cryptoDestinationAddressTravelruleMetadata.optional()}); export const listCryptoDestinationAddressesResponse = z.object({addresses: z.array(cryptoDestinationAddress).optional(), next_page_cursor: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List Crypto Destination Addresses * * GET /transfer/crypto-destination-addresses */ export const getApiTransferCryptoDestinationAddresses = async (args: GetApiTransferCryptoDestinationAddressesArgs, options?: GetApiTransferCryptoDestinationAddressesOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.ids ?? []) query.append("ids", String(item)) for (const item of args.identity_ids ?? []) query.append("identity_ids", String(item)) for (const item of args.crypto_networks ?? []) query.append("crypto_networks", String(item)) for (const item of args.addresses ?? []) query.append("addresses", String(item)) for (const item of args.nicknames ?? []) query.append("nicknames", String(item)) if (args.bookmarked_status != null) query.append("bookmarked_status", String(args.bookmarked_status)) if (args['created_at.lt'] != null) query.append("created_at.lt", String(args['created_at.lt'])) if (args['created_at.lte'] != null) query.append("created_at.lte", String(args['created_at.lte'])) if (args['created_at.eq'] != null) query.append("created_at.eq", String(args['created_at.eq'])) if (args['created_at.gte'] != null) query.append("created_at.gte", String(args['created_at.gte'])) if (args['created_at.gt'] != null) query.append("created_at.gt", String(args['created_at.gt'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.page_cursor != null) query.append("page_cursor", String(args.page_cursor)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/transfer/crypto-destination-addresses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listCryptoDestinationAddressesResponse, await res.json()) };