import {z} from 'zod' export type CryptoNetwork = 'BITCOIN' | 'ETHEREUM' | 'BITCOIN_CASH' | 'LITECOIN' | 'SOLANA' | 'POLYGON_POS' | 'BASE' | 'ARBITRUM_ONE' | 'STELLAR' | 'INK' | 'XLAYER' | 'AVALANCHE' | 'DOGECOIN' | 'SUI' | 'ROBINHOOD' | 'BNB'; export type GeographicAddress = {country: string, address1?: string | undefined, address2?: string | undefined, city?: string | undefined, province?: string | undefined, zip_code?: string | undefined}; export type BeneficiaryPerson = {first_name: string, last_name: string, physical_address?: GeographicAddress | undefined}; export type BeneficiaryInstitution = {name: string, physical_address?: GeographicAddress | undefined}; export type Beneficiary = {person_details?: BeneficiaryPerson | undefined, institution_details?: BeneficiaryInstitution | undefined, self?: boolean | undefined}; export type PutCryptoDestinationAddressRequestVasp = {id?: string | undefined, custom_vasp_name?: string | undefined, custom_vasp_website?: string | undefined}; export type CustodianType = 'VASP' | 'PRIVATE'; export type PutCryptoDestinationAddressRequestTravelruleMetadata = {beneficiary?: Beneficiary | undefined, vasp?: PutCryptoDestinationAddressRequestVasp | undefined, custodian_type?: CustodianType | undefined, transfer_purpose?: string | undefined}; export type PutCryptoDestinationAddressRequest = {id?: string | undefined, identity_id?: string | undefined, crypto_network?: CryptoNetwork | undefined, address?: string | undefined, nickname?: string | undefined, bookmarked_status?: boolean | undefined, travelrule_metadata?: PutCryptoDestinationAddressRequestTravelruleMetadata | undefined}; export type UpdateApiTransferCryptoDestinationAddressArgs = {body: PutCryptoDestinationAddressRequest}; export type UpdateApiTransferCryptoDestinationAddressOptions = {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 putCryptoDestinationAddressResponse = z.object({address: cryptoDestinationAddress.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 }; /** * Put Crypto Destination Addresses * * PUT /transfer/crypto-destination-address */ export const updateApiTransferCryptoDestinationAddress = async (args: UpdateApiTransferCryptoDestinationAddressArgs, options?: UpdateApiTransferCryptoDestinationAddressOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/transfer/crypto-destination-address${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(putCryptoDestinationAddressResponse, await res.json()) };