import {z} from 'zod' export type CustodyNetworkAddress = string; export type CustodyDestinationID = string; export type GetApiV1WalletsSelfHostedVerificationAttemptsArgs = {address?: CustodyNetworkAddress | undefined, destinationId?: CustodyDestinationID | undefined}; export type GetApiV1WalletsSelfHostedVerificationAttemptsOptions = {baseUrl?: string | undefined, jwtTokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const custodyDestinationID = z.string(); export const networkID = z.string(); export const custodySymbol = z.string(); export const custodyNetworkAddress = z.string(); export const custodyWithdrawalMemo = z.string(); export const custodySelfHostedVerificationStatus = z.enum(["VERIFIED", "PENDING_VERIFICATION", "VERIFICATION_EXPIRED"]); export const custodySelfHostedRequestedDepositAmount = z.string(); export const custodySelfHostedVerificationAmount = z.string(); export const custodySelfHostedTotalDepositAmount = z.string(); export const dateTime = z.string(); export const custodyGetSelfHostedVerificationResponse = z.object({destinationId: custodyDestinationID, network: networkID, symbol: custodySymbol, address: custodyNetworkAddress, memo: custodyWithdrawalMemo.optional(), verificationStatus: custodySelfHostedVerificationStatus, requestedDepositAmount: custodySelfHostedRequestedDepositAmount, verificationAmount: custodySelfHostedVerificationAmount, totalDepositAmount: custodySelfHostedTotalDepositAmount, verificationExpiryTime: dateTime}); export const getApiV1WalletsSelfHostedVerificationAttemptsResponse = z.array(custodyGetSelfHostedVerificationResponse); 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 }; /** * Get a List of Self-Hosted Wallet Verification Attempts * * GET /v1/wallets/self-hosted/verification-attempts */ export const getApiV1WalletsSelfHostedVerificationAttempts = async (args: GetApiV1WalletsSelfHostedVerificationAttemptsArgs, options?: GetApiV1WalletsSelfHostedVerificationAttemptsOptions) => { const {baseUrl = "https://api.exchange.bullish.com/trading-api", fetch: fetchFn = fetch, jwtTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.address != null) query.append("address", String(args.address)) if (args.destinationId != null) query.append("destinationId", String(args.destinationId)) if (jwtTokenAuth !== undefined) headers.set('authorization', `Bearer ${jwtTokenAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/wallets/self-hosted/verification-attempts${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(getApiV1WalletsSelfHostedVerificationAttemptsResponse, await res.json()) };