import {z} from 'zod' export type ParticipantOnboardingPayload = {expiresAt?: string | undefined, operator?: string | undefined, compliance?: string | undefined, registrar?: string | undefined, clientOnboarder?: string | undefined, upgrader?: string | undefined}; export type CantonCallParticipantOnboarding = {type: 'DTCC_PARTICIPANT_ONBOARDING', vaultAccountId: string, blockchainId: 'CANTON' | 'CANTON_TEST', payload?: ParticipantOnboardingPayload | undefined}; export type EndInvestorPayload = {endInvestor: string}; export type CantonCallEndInvestorInvite = {type: 'DTCC_END_INVESTOR_INVITE', vaultAccountId: string, blockchainId: 'CANTON' | 'CANTON_TEST', payload: EndInvestorPayload}; export type CantonCallEndInvestorInviteCancel = {type: 'DTCC_END_INVESTOR_INVITE_CANCEL', vaultAccountId: string, blockchainId: 'CANTON' | 'CANTON_TEST', payload: EndInvestorPayload}; export type CantonCallEndInvestorOffboard = {type: 'DTCC_END_INVESTOR_OFFBOARD', vaultAccountId: string, blockchainId: 'CANTON' | 'CANTON_TEST', payload: EndInvestorPayload}; export type AllowListPayload = {wallets: Array}; export type CantonCallAllowListAdd = {type: 'DTCC_ALLOW_LIST_ADD', vaultAccountId: string, blockchainId: 'CANTON' | 'CANTON_TEST', payload: AllowListPayload}; export type CantonCallAllowListRemove = {type: 'DTCC_ALLOW_LIST_REMOVE', vaultAccountId: string, blockchainId: 'CANTON' | 'CANTON_TEST', payload: AllowListPayload}; export type CantonCall = CantonCallParticipantOnboarding | CantonCallEndInvestorInvite | CantonCallEndInvestorInviteCancel | CantonCallEndInvestorOffboard | CantonCallAllowListAdd | CantonCallAllowListRemove; export type CreateApiOperationsCantonCallsArgs = {'Idempotency-Key'?: string | undefined, body: CantonCall}; export type CreateApiOperationsCantonCallsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const callAccepted = z.object({transactionId: z.string(), status: z.string()}); 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 }; /** * Make a Canton call * * POST /operations/canton/calls */ export const createApiOperationsCantonCalls = async (args: CreateApiOperationsCantonCallsArgs, options?: CreateApiOperationsCantonCallsOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/operations/canton/calls${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(callAccepted, await res.json()) };