import {z} from 'zod' export type GetApiNcwWalletsWalletIdAccountsAccountIdAssetsAssetIdAddressesArgs = {walletId: string, accountId: string, assetId: string, pageCursor?: string | undefined, pageSize?: number | undefined, sort?: ('address' | 'createdAt') | undefined, order?: ('DESC' | 'ASC') | undefined, enabled?: boolean | undefined}; export type GetApiNcwWalletsWalletIdAccountsAccountIdAssetsAssetIdAddressesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const embeddedWalletAddressDetails = z.object({accountName: z.string(), accountId: z.string(), asset: z.string(), address: z.string(), addressType: z.enum(["PERMANENT", "CHANGE", "DEFAULT", "ADDRESS"]), addressDescription: z.string(), tag: z.string(), addressIndex: z.number().optional(), change: z.number().optional(), coinType: z.number().optional(), customerRefId: z.string().optional(), addressFormat: z.string().optional(), legacyAddress: z.string().optional(), paymentAddress: z.string().optional(), userDefined: z.boolean().optional(), state: z.enum(["PENDING_ACTIVATION", "ACTIVATION_FAILED", "READY"]).optional()}); export const embeddedWalletPaginatedAddressesResponse = z.object({data: z.array(embeddedWalletAddressDetails), next: z.string().nullable().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 }; /** * Retrieve asset addresses * * GET /ncw/wallets/{walletId}/accounts/{accountId}/assets/{assetId}/addresses */ export const getApiNcwWalletsWalletIdAccountsAccountIdAssetsAssetIdAddresses = async (args: GetApiNcwWalletsWalletIdAccountsAccountIdAssetsAssetIdAddressesArgs, options?: GetApiNcwWalletsWalletIdAccountsAccountIdAssetsAssetIdAddressesOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (args.enabled != null) query.append("enabled", String(args.enabled)) const url = `${baseUrl.replace(/\/+$/, '')}/ncw/wallets/${encodeURIComponent(String(args.walletId))}/accounts/${encodeURIComponent(String(args.accountId))}/assets/${encodeURIComponent(String(args.assetId))}/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(embeddedWalletPaginatedAddressesResponse, await res.json()) };