import {z} from 'zod' export type StringNoEdgeSpaces = string; export type CountryCodeForRequest = string; export type SubdivisionCodeForRequest = string; export type GetApiCoreRequestsForInformationArgs = {reference: string, 'X-On-Behalf-Of'?: string | undefined, 'X-Uphold-User-Ip'?: (string | string) | undefined, 'X-Uphold-User-Agent'?: StringNoEdgeSpaces | undefined, 'X-Uphold-User-Origin'?: StringNoEdgeSpaces | undefined, 'X-Uphold-User-Country'?: CountryCodeForRequest | undefined, 'X-Uphold-User-Subdivision'?: SubdivisionCodeForRequest | undefined, 'X-Uphold-User-City'?: StringNoEdgeSpaces | undefined}; export type GetApiCoreRequestsForInformationOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const requestForInformationSelfDeclarationProof = z.object({type: z.literal("self-declaration"), attestation: z.string()}).and(z.record(z.string(), z.unknown())); export const requestForInformationMessageSigningProof = z.object({type: z.enum(["bip-137", "bip-322", "cip-8", "concordium", "cosmos-ecdsa", "ed25519", "eip-1271", "eip-191", "eip-712", "siwe", "siwx", "sol-siwx", "sr25519", "tip-191", "xlm-ed25519", "xpub", "xrp-ed25519"]), address: z.string().optional(), attestation: z.string().optional(), proof: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const requestForInformationSatoshiTestProof = z.object({type: z.literal("satoshi-test"), proof: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const requestForInformationTravelRule = z.object({id: z.string(), type: z.literal("travel-rule"), status: z.enum(["ok", "pending", "failed"]), expiresAt: z.string().optional(), context: z.object({network: z.string(), addresses: z.array(z.string())}), proofOptions: z.object({selfDeclaration: z.object({schema: z.record(z.string(), z.unknown()).optional()}).optional(), messageSigning: z.object({schema: z.record(z.string(), z.unknown()).optional(), message: z.string().optional()}).optional(), satoshiTest: z.object({address: z.string(), asset: z.string(), amount: z.string(), amountSubunits: z.string(), decimals: z.number().int().optional(), reference: z.string().optional()}).optional()}), proof: z.object({originatorProof: z.union([requestForInformationSelfDeclarationProof, requestForInformationMessageSigningProof, requestForInformationSatoshiTestProof]).optional(), beneficiaryProof: z.union([requestForInformationSelfDeclarationProof, requestForInformationMessageSigningProof, requestForInformationSatoshiTestProof]).optional()}).and(z.record(z.string(), z.unknown())).optional()}); export const requestForInformationCryptoAddressTravelRule = z.object({id: z.string(), type: z.literal("crypto-address-travel-rule"), status: z.enum(["ok", "pending", "failed"]), expiresAt: z.string().optional(), context: z.object({network: z.string(), addresses: z.array(z.string())}), proofOptions: z.object({selfDeclaration: z.object({schema: z.record(z.string(), z.unknown()).optional()}).optional(), messageSigning: z.object({schema: z.record(z.string(), z.unknown()).optional(), message: z.string().optional()}).optional(), satoshiTest: z.object({address: z.string(), asset: z.string(), amount: z.string(), amountSubunits: z.string(), decimals: z.number().int().optional(), reference: z.string().optional()}).optional()}), proof: z.object({isVASP: z.boolean(), isSelfHostedWallet: z.boolean(), isSelfOwnedCryptoAddress: z.boolean(), isBusiness: z.boolean().optional(), name: z.record(z.string(), z.unknown()).optional()}).and(z.record(z.string(), z.unknown())).optional()}); export const requestForInformationCryptoAddressVerification = z.object({id: z.string(), type: z.literal("crypto-address-verification"), status: z.enum(["ok", "pending", "failed"]), expiresAt: z.string().optional(), context: z.object({network: z.string(), addresses: z.array(z.string())}), proofOptions: z.object({selfDeclaration: z.object({schema: z.record(z.string(), z.unknown()).optional()}).optional(), messageSigning: z.object({schema: z.record(z.string(), z.unknown()).optional(), message: z.string().optional()}).optional(), satoshiTest: z.object({address: z.string(), asset: z.string(), amount: z.string(), amountSubunits: z.string(), decimals: z.number().int().optional(), reference: z.string().optional()}).optional()}), proof: z.union([requestForInformationMessageSigningProof, requestForInformationSatoshiTestProof]).optional()}); export const requestForInformation = z.discriminatedUnion("type", [requestForInformationTravelRule, requestForInformationCryptoAddressTravelRule, requestForInformationCryptoAddressVerification]); export const getApiCoreRequestsForInformationResponse = z.object({requestsForInformation: z.array(requestForInformation)}); 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 requests for information * * GET /core/requests-for-information */ export const getApiCoreRequestsForInformation = async (args: GetApiCoreRequestsForInformationArgs, options?: GetApiCoreRequestsForInformationOptions) => { const {baseUrl = "https://api.enterprise.sandbox.uphold.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.reference != null) query.append("reference", String(args.reference)) if (args['X-On-Behalf-Of'] != null) headers.set("X-On-Behalf-Of", String(args['X-On-Behalf-Of'])) if (args['X-Uphold-User-Ip'] != null) headers.set("X-Uphold-User-Ip", String(args['X-Uphold-User-Ip'])) if (args['X-Uphold-User-Agent'] != null) headers.set("X-Uphold-User-Agent", String(args['X-Uphold-User-Agent'])) if (args['X-Uphold-User-Origin'] != null) headers.set("X-Uphold-User-Origin", String(args['X-Uphold-User-Origin'])) if (args['X-Uphold-User-Country'] != null) headers.set("X-Uphold-User-Country", String(args['X-Uphold-User-Country'])) if (args['X-Uphold-User-Subdivision'] != null) headers.set("X-Uphold-User-Subdivision", String(args['X-Uphold-User-Subdivision'])) if (args['X-Uphold-User-City'] != null) headers.set("X-Uphold-User-City", String(args['X-Uphold-User-City'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/core/requests-for-information${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(getApiCoreRequestsForInformationResponse, await res.json()) };