import {z} from 'zod' export type GetApiV2VaultsVaultIdWalletsWalletIdAddressesBatchGetArgs = {vault_id: string, wallet_id: string, names: Array}; export type GetApiV2VaultsVaultIdWalletsWalletIdAddressesBatchGetOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const walletAddressFormat = z.enum(["BITCOIN_P2PKH", "BITCOIN_P2WPKH", "EVM", "TRON_BASE58", "BASE58", "TON_NON_BOUNCEABLE", "SUBSTRATE_58", "BITCOIN_P2TR"]); export const v2WalletAddressType = z.enum(["MAIN", "DEPOSIT", "CHANGE"]); export const bTCDetailsAddressFormat = z.enum(["P2PKH", "P2WPKH", "P2TR"]); export const v2WalletAddressCreateParamsBTCDetails = z.object({format: bTCDetailsAddressFormat}); export const v2WalletAddressCreateParams = z.object({btcDetails: v2WalletAddressCreateParamsBTCDetails.optional()}); export const v2WalletAddress = z.object({name: z.string().optional(), displayName: z.string().optional(), network: z.string(), address: z.string().optional(), format: walletAddressFormat.optional(), key: z.string().optional(), keyDerivationPath: z.array(z.string()).optional(), type: v2WalletAddressType.optional(), note: z.string().optional(), createParams: v2WalletAddressCreateParams.optional()}); export const v2BatchGetWalletAddressesResponse = z.object({walletAddresses: z.array(v2WalletAddress).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 }; /** * BatchGetWalletAddresses * * GET /v2/vaults/{vault_id}/wallets/{wallet_id}/addresses:batchGet */ export const getApiV2VaultsVaultIdWalletsWalletIdAddressesBatchGet = async (args: GetApiV2VaultsVaultIdWalletsWalletIdAddressesBatchGetArgs, options?: GetApiV2VaultsVaultIdWalletsWalletIdAddressesBatchGetOptions) => { const {baseUrl = "https://api.utila.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.names ?? []) query.append("names", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/vaults/${encodeURIComponent(String(args.vault_id))}/wallets/${encodeURIComponent(String(args.wallet_id))}/addresses:batchGet${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(v2BatchGetWalletAddressesResponse, await res.json()) };