import {z} from 'zod' export type BlockchainStateFilter = 'BLOCKCHAIN_STATE_CREATED' | 'BLOCKCHAIN_STATE_ACTIVATING' | 'BLOCKCHAIN_STATE_ACTIVATED' | 'BLOCKCHAIN_STATE_DEACTIVATING' | 'BLOCKCHAIN_STATE_DEACTIVATED' | 'BLOCKCHAIN_STATE_TECHNICAL_FAILURE'; export type BlockchainEnvironment = 'MAINNET' | 'TESTNET'; export type BlockchainSortField = 'createdAt' | 'chainName' | 'symbolName' | 'status'; export type GetApiBlockchainLinkBlockchainsArgs = {pageCursor?: string | undefined, pageSize?: number | undefined, search?: string | undefined, status?: Array | undefined, blockchainEnv?: BlockchainEnvironment | undefined, sortBy?: BlockchainSortField | undefined, order?: ('ASC' | 'DESC') | undefined, statusExclude?: Array | undefined}; export type GetApiBlockchainLinkBlockchainsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const blockchainRpcAuth = z.object({type: z.enum(["RPC_AUTH_BASIC", "RPC_AUTH_BEARER", "RPC_AUTH_CUSTOM_HEADER"]), username: z.string().optional(), password: z.string().optional(), token: z.string().optional(), headerName: z.string().optional(), headerValue: z.string().optional()}); export const blockchainDeclaredProperties = z.object({chainName: z.string(), chainId: z.number(), symbolName: z.string(), decimals: z.number().optional(), rpcUrls: z.array(z.string()), environmentType: z.enum(["ENVIRONMENT_TYPE_MAINNET", "ENVIRONMENT_TYPE_TESTNET"]), blockExplorerUrl: z.string().optional(), blockExplorerTransactionPath: z.string().optional(), blockExplorerAddressPath: z.string().optional(), networkId: z.number().optional(), hasFee: z.boolean().optional(), isPoa: z.boolean().optional(), hasLayeredFee: z.boolean().optional(), nodeType: z.enum(["NODE_TYPE_CORE_GETH", "NODE_TYPE_FANTOM", "NODE_TYPE_ERIGON", "NODE_TYPE_PARITY", "NODE_TYPE_BESU"]).optional(), transactionFormat: z.number().optional(), baseAssetTenantIds: z.array(z.string()).optional(), explorerApiUrl: z.string().optional(), explorerApiKey: z.string().optional(), isTraceEnabled: z.boolean().optional(), rpcAuth: blockchainRpcAuth.optional()}); export const blockchain = z.object({id: z.string(), blockchainState: z.enum(["BLOCKCHAIN_STATE_CREATED", "BLOCKCHAIN_STATE_ACTIVATING", "BLOCKCHAIN_STATE_ACTIVATED", "BLOCKCHAIN_STATE_DEACTIVATING", "BLOCKCHAIN_STATE_DEACTIVATED", "BLOCKCHAIN_STATE_TECHNICAL_FAILURE"]), declaredProperties: blockchainDeclaredProperties, createdAtUtc: z.number(), updatedAtUtc: z.number(), validationSessionId: z.string().optional(), validationStatus: z.enum(["VALIDATION_STATUS_PENDING", "VALIDATION_STATUS_IN_PROGRESS", "VALIDATION_STATUS_SUCCEEDED", "VALIDATION_STATUS_FAILED", "VALIDATION_STATUS_TECHNICAL_FAILURE"]).optional(), validationCreatedAtUtc: z.number().optional(), validationUpdatedAtUtc: z.number().optional(), validationCompletedAtUtc: z.number().optional(), validationFailureReasons: z.array(z.string()), failedStep: z.enum(["FAILED_STEP_CONFIGURATION", "FAILED_STEP_RESOURCES_ALLOCATION", "FAILED_STEP_TEST_TX_EXTERNAL_TO_FIREBLOCKS", "FAILED_STEP_TEST_TX_FIREBLOCKS_TO_FIREBLOCKS"]).optional()}); export const listBlockchainsResponse2 = z.object({data: z.array(blockchain), total: z.number(), next: z.string().optional(), prev: z.string().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 }; /** * List blockchains with pagination and filtering * * GET /blockchain_link/blockchains */ export const getApiBlockchainLinkBlockchains = async (args: GetApiBlockchainLinkBlockchainsArgs, options?: GetApiBlockchainLinkBlockchainsOptions) => { 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.search != null) query.append("search", String(args.search)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.blockchainEnv != null) query.append("blockchainEnv", String(args.blockchainEnv)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.order != null) query.append("order", String(args.order)) for (const item of args.statusExclude ?? []) query.append("statusExclude", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/blockchain_link/blockchains${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(listBlockchainsResponse2, await res.json()) };