import {z} from 'zod' export type CommonDID = string; export type TransactionBlockchainInfo = {txHash?: string | undefined, origin?: string | undefined, destination: string}; export type Text = string; export type NaturalPersonNameTypeCode = 'ALIA' | 'BIRT' | 'MAID' | 'LEGL' | 'MISC'; export type NaturalPersonNameID = {primaryIdentifier?: Text | undefined, secondaryIdentifier?: Text | undefined, nameIdentifierType?: NaturalPersonNameTypeCode | undefined}; export type LocalNaturalPersonNameID = {primaryIdentifier?: Text | undefined, secondaryIdentifier?: Text | undefined, nameIdentifierType?: NaturalPersonNameTypeCode | undefined}; export type NaturalPersonName = {nameIdentifier: Array, localNameIdentifier?: Array | undefined, phoneticNameIdentifier?: Array | undefined}; export type AddressTypeCode = 'HOME' | 'BIZZ' | 'GEOG'; export type Ivms101CountryCode = string; export type Ivms101Address = {addressType?: AddressTypeCode | undefined, department?: Text | undefined, subDepartment?: Text | undefined, streetName?: Text | undefined, buildingNumber?: Text | undefined, buildingName?: Text | undefined, floor?: Text | undefined, postBox?: Text | undefined, room?: Text | undefined, postCode?: Text | undefined, townName?: Text | undefined, townLocationName?: Text | undefined, districtName?: Text | undefined, countrySubDivision?: Text | undefined, addressLine?: Array | undefined, country?: Ivms101CountryCode | undefined}; export type NationalIdentifierTypeCode = 'ARNU' | 'CCPT' | 'RAID' | 'DRLC' | 'FIIN' | 'TXID' | 'SOCS' | 'IDCD' | 'LEIX' | 'MISC'; export type NationalIdentification = {nationalIdentifier: Text, nationalIdentifierType: NationalIdentifierTypeCode, countryOfIssue?: Ivms101CountryCode | undefined, registrationAuthority?: Text | undefined}; export type Date = string; export type DateAndPlaceOfBirth = {dateOfBirth: Date, placeOfBirth: Text}; export type NaturalPerson = {name: Array, geographicAddress?: Array | undefined, nationalIdentification?: NationalIdentification | undefined, customerIdentification?: Text | undefined, dateAndPlaceOfBirth?: DateAndPlaceOfBirth | undefined, countryOfResidence?: Ivms101CountryCode | undefined}; export type LegalPersonNameTypeCode = 'LEGL' | 'SHRT' | 'TRAD'; export type LegalPersonNameID = {legalPersonName?: Text | undefined, legalPersonNameIdentifierType?: LegalPersonNameTypeCode | undefined}; export type LocalLegalPersonNameID = {legalPersonName?: Text | undefined, legalPersonNameIdentifierType?: LegalPersonNameTypeCode | undefined}; export type LegalPersonName = {nameIdentifier: Array, localNameIdentifier?: Array | undefined, phoneticNameIdentifier?: Array | undefined}; export type LegalPerson = {name: LegalPersonName, geographicAddress?: Array | undefined, customerNumber?: Text | undefined, nationalIdentification?: NationalIdentification | undefined, dateOfRegistration?: Date | undefined, countryOfRegistration?: Ivms101CountryCode | undefined}; export type Ivms101Person = {naturalPerson?: NaturalPerson | undefined, legalPerson?: LegalPerson | undefined}; export type Ivms101Originator = {originatorPersons: Array, accountNumber?: Array | undefined}; export type Ivms101Beneficiary = {beneficiaryPersons: Array, accountNumber?: Array | undefined}; export type TrTravelRuleProtocol = 'TRLight' | 'TRP' | 'OpenVASP'; export type OwnershipProof = {type: 'eip-191' | 'eip-712' | 'bip-137', proof: string, attestation: string, address?: string | undefined, status?: string | undefined} | {type: 'screenshot', url: string} | {type: 'self-declaration', did?: string | undefined, address?: string | undefined, attestation: string, confirmed?: boolean | undefined, status?: string | undefined} | {type: 'microtransfer', did?: string | undefined, address?: string | undefined, proof: string, chain?: string | undefined, destination?: string | undefined, amountSubunits?: string | undefined, status?: string | undefined} | {type: string} | {[key: string]: unknown}; export type PiiNaturalPersonNameID = {primaryIdentifier?: Text | undefined, secondaryIdentifier?: Text | undefined, nameIdentifierType?: Text | undefined}; export type PiiLocalNaturalPersonNameID = {primaryIdentifier?: Text | undefined, secondaryIdentifier?: Text | undefined, nameIdentifierType?: Text | undefined}; export type PiiNaturalPersonName = {nameIdentifier: Array, localNameIdentifier?: Array | undefined, phoneticNameIdentifier?: Array | undefined}; export type PiiAddress = {addressType?: Text | undefined, department?: Text | undefined, subDepartment?: Text | undefined, streetName?: Text | undefined, buildingNumber?: Text | undefined, buildingName?: Text | undefined, floor?: Text | undefined, postBox?: Text | undefined, room?: Text | undefined, postCode?: Text | undefined, townName?: Text | undefined, townLocationName?: Text | undefined, districtName?: Text | undefined, countrySubDivision?: Text | undefined, addressLine?: Array | undefined, country?: Text | undefined}; export type PiiNationalIdentification = {nationalIdentifier: Text, nationalIdentifierType: Text, countryOfIssue?: Text | undefined, registrationAuthority?: Text | undefined}; export type PiiDateAndPlaceOfBirth = {dateOfBirth: Text, placeOfBirth: Text}; export type PiiNaturalPerson = {name: Array, geographicAddress?: Array | undefined, nationalIdentification?: PiiNationalIdentification | undefined, customerIdentification?: Text | undefined, dateAndPlaceOfBirth?: PiiDateAndPlaceOfBirth | undefined, countryOfResidence?: Text | undefined}; export type PiiLegalPersonNameID = {legalPersonName?: Text | undefined, legalPersonNameIdentifierType?: Text | undefined}; export type PiiLocalLegalPersonNameID = {legalPersonName?: Text | undefined, legalPersonNameIdentifierType?: Text | undefined}; export type PiiLegalPersonName = {nameIdentifier: Array, localNameIdentifier?: Array | undefined, phoneticNameIdentifier?: Array | undefined}; export type PiiLegalPerson = {name: PiiLegalPersonName, geographicAddress?: Array | undefined, customerNumber?: Text | undefined, nationalIdentification?: PiiNationalIdentification | undefined, dateOfRegistration?: Text | undefined, countryOfRegistration?: Text | undefined}; export type PiiPerson = {naturalPerson?: PiiNaturalPerson | undefined, legalPerson?: PiiLegalPerson | undefined}; export type PiiOriginator = {originatorPersons: Array, accountNumber?: Array | undefined}; export type PiiBeneficiary = {beneficiaryPersons: Array, accountNumber?: Array | undefined}; export type PiiOriginatingVASP = {originatingVASP?: PiiPerson | undefined}; export type PiiBeneficiaryVASP = {beneficiaryVASP?: PiiPerson | undefined}; export type PiiIntermediaryVASP = {intermediaryVASP: PiiPerson, sequence: Text}; export type PiiTransferPath = {transferPath?: Array | undefined}; export type PiiPayloadMetadata = {transliterationMethod?: Array | undefined}; export type PIIIVMS = {originator?: PiiOriginator | undefined, beneficiary?: PiiBeneficiary | undefined, originatingVASP?: PiiOriginatingVASP | undefined, beneficiaryVASP?: PiiBeneficiaryVASP | undefined, transferPath?: PiiTransferPath | undefined, payloadMetadata?: PiiPayloadMetadata | undefined}; export type ValidatePartyFields = 'BENEFICIARY' | 'ORIGINATOR' | 'ALL'; export type TransactionValidateFullRequest = {transactionAsset: string, transactionAmount: string, transactionAssetDecimals?: number | undefined, originatorDid?: CommonDID | undefined, beneficiaryDid?: CommonDID | undefined, originatorVASPdid?: CommonDID | undefined, beneficiaryVASPdid?: CommonDID | undefined, beneficiaryVASPname?: string | undefined, transactionBlockchainInfo: TransactionBlockchainInfo, originator?: Ivms101Originator | undefined, beneficiary?: Ivms101Beneficiary | undefined, encrypted?: string | undefined, protocol?: TrTravelRuleProtocol | undefined, notificationEmail?: string | undefined, skipBeneficiaryDataValidation?: boolean | undefined, travelRuleBehavior?: boolean | undefined, originatorProof?: OwnershipProof | undefined, beneficiaryProof?: OwnershipProof | undefined, pii?: PIIIVMS | undefined, network?: string | undefined, validatePartyFields?: ValidatePartyFields | undefined, onBehalfOfMyself?: boolean | undefined}; export type CreateApiTxValidateFullArgs = {body: TransactionValidateFullRequest}; export type CreateApiTxValidateFullOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionType = z.enum(["BELOW_THRESHOLD", "NON_CUSTODIAL", "TRAVELRULE", "UNKNOWN"]); export const blockchainAddressType = z.enum(["UNKNOWN", "HOSTED", "UNHOSTED"]); export const blockchainAddressInfoSource = z.enum(["UNKNOWN", "ADDRESS_HASH", "ADDRESS_GRAPH", "CHAINALYSIS", "ELLIPTIC"]); export const transactionFullValidationResult = z.object({isValid: z.boolean(), type: transactionType, beneficiaryAddressType: blockchainAddressType.optional(), addressSource: blockchainAddressInfoSource.optional(), beneficiaryVASPname: z.string().optional(), errors: z.array(z.string()).optional(), warnings: z.array(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 }; /** * Fully Validate transfer * * POST /tx/validate/full */ export const createApiTxValidateFull = async (args: CreateApiTxValidateFullArgs, options?: CreateApiTxValidateFullOptions) => { const {baseUrl = "https://api.eu1.notabene.id", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/tx/validate/full${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(transactionFullValidationResult, await res.json()) };