import {z} from 'zod' export type TravelRuleNotationEnum = Array<'fireblocks' | 'notabene'>; export type TravelRuleAddress = {street?: string | undefined, city?: string | undefined, state?: string | undefined, postalCode?: string | undefined}; export type TravelRuleValidateTransactionRequest = {transactionAsset: string, destination: string, transactionAmount: string, transactionAssetDecimals?: number | undefined, originatorVASPdid: string, originatorEqualsBeneficiary: boolean, travelRuleBehavior?: boolean | undefined, beneficiaryVASPdid?: string | undefined, beneficiaryVASPname?: string | undefined, beneficiaryName?: string | undefined, beneficiaryAccountNumber?: string | undefined, beneficiaryAddress?: TravelRuleAddress | undefined}; export type CreateApiScreeningTravelRuleTransactionValidateArgs = {notation?: TravelRuleNotationEnum | undefined, 'Idempotency-Key'?: string | undefined, body: TravelRuleValidateTransactionRequest}; export type CreateApiScreeningTravelRuleTransactionValidateOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const travelRuleValidateTransactionResponse = z.object({isValid: z.boolean(), type: z.string(), beneficiaryAddressType: z.enum(["UNKNOWN", "HOSTED", "UNHOSTED"]), addressSource: z.enum(["UNKNOWN", "ADDRESS_HASH", "ADDRESS_GRAPH", "CHAINALYSIS", "ELLIPTIC", "CRYSTAL"]), beneficiaryVASPdid: z.string(), beneficiaryVASPname: z.string(), warnings: z.array(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 }; /** * Validate Travel Rule Transaction * * POST /screening/travel_rule/transaction/validate */ export const createApiScreeningTravelRuleTransactionValidate = async (args: CreateApiScreeningTravelRuleTransactionValidateArgs, options?: CreateApiScreeningTravelRuleTransactionValidateOptions) => { 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") for (const item of args.notation ?? []) query.append("notation", String(item)) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/screening/travel_rule/transaction/validate${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(travelRuleValidateTransactionResponse, await res.json()) };