import {z} from 'zod' export type GetApiNcwWalletsWalletIdAccountsAccountIdAssetsArgs = {walletId: string, accountId: string, sort?: (Array<'assetId' | 'createdAt'>) | undefined, pageCursor?: string | undefined, pageSize?: number | undefined, order?: ('ASC' | 'DESC') | undefined}; export type GetApiNcwWalletsWalletIdAccountsAccountIdAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const embeddedWalletAssetResponse = z.object({id: z.string(), symbol: z.string(), name: z.string(), decimals: z.number(), networkProtocol: z.string(), testnet: z.boolean(), hasFee: z.boolean(), baseAsset: z.string(), ethNetwork: z.string().optional(), ethContractAddress: z.string().optional(), issuerAddress: z.string().optional(), blockchainSymbol: z.string().optional(), deprecated: z.boolean().optional(), coinType: z.number(), blockchain: z.string(), blockchainDisplayName: z.string().optional(), algorithm: z.enum(["MPC_ECDSA_SECP256K1", "MPC_EDDSA_ED25519"]).optional()}); export const embeddedWalletPaginatedAssetsResponse = z.object({data: z.array(embeddedWalletAssetResponse), 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 assets * * GET /ncw/wallets/{walletId}/accounts/{accountId}/assets */ export const getApiNcwWalletsWalletIdAccountsAccountIdAssets = async (args: GetApiNcwWalletsWalletIdAccountsAccountIdAssetsArgs, options?: GetApiNcwWalletsWalletIdAccountsAccountIdAssetsOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.order != null) query.append("order", String(args.order)) const url = `${baseUrl.replace(/\/+$/, '')}/ncw/wallets/${encodeURIComponent(String(args.walletId))}/accounts/${encodeURIComponent(String(args.accountId))}/assets${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(embeddedWalletPaginatedAssetsResponse, await res.json()) };