import {z} from 'zod' export type GetApiAssetsIdArgs = {id: string, 'Idempotency-Key'?: string | undefined}; export type GetApiAssetsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const assetClass = z.enum(["NATIVE", "FT", "FIAT", "NFT", "SFT", "VIRTUAL"]); export const assetDetailsOnchain = z.object({symbol: z.string(), name: z.string(), address: z.string().optional(), decimals: z.number(), standards: z.array(z.string()).optional()}); export const assetScope = z.enum(["GLOBAL", "LOCAL"]); export const assetMedia = z.object({url: z.string(), type: z.enum(["image/svg+xml", "image/png"]), attributes: z.object({monochrome: z.boolean().optional()}).optional()}); export const assetNote = z.object({text: z.string(), userId: z.string(), userName: z.string(), updatedAt: z.string()}); export const assetFeature = z.literal("STABLECOIN"); export const assetDetailsMetadata = z.object({scope: assetScope, verified: z.boolean(), deprecated: z.boolean(), deprecationReferralId: z.string().optional(), website: z.string().optional(), media: z.array(assetMedia).optional(), note: assetNote.optional(), features: z.array(assetFeature).optional()}); export const asset = z.object({id: z.string(), legacyId: z.string(), blockchainId: z.string().optional(), displayName: z.string(), displaySymbol: z.string(), providerId: z.string().optional(), peggedAssetId: z.string().optional(), assets: z.array(z.string()).optional(), assetClass: assetClass, decimals: z.number().optional(), onchain: assetDetailsOnchain.optional(), metadata: assetDetailsMetadata}); 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 an asset * * GET /assets/{id} */ export const getApiAssetsId = async (args: GetApiAssetsIdArgs, options?: GetApiAssetsIdOptions) => { 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['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/assets/${encodeURIComponent(String(args.id))}${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(asset, await res.json()) };