import {z} from 'zod' export type CoreSortOrder = 'ASC' | 'DESC'; export type CoreLockStatus = 'Unlocked' | 'Locked' | 'Archived'; export type CoreAccountProcessingStatus = 'Pending' | 'Preparing' | 'Tracked' | 'Recovering' | 'Completed' | 'Interrupted'; export type CoreAccountLedgerStatus = 'Activating' | 'AwaitingLedgerActivation' | 'Activated'; export type GetApiV1DomainsDomainIdAccountsArgs = {domainId: string, limit?: number | undefined, startingAfter?: string | undefined, sortBy?: ('id' | 'alias' | 'ledgerId' | 'lock' | 'metadata.createdAt' | 'metadata.lastModifiedAt') | undefined, sortOrder?: CoreSortOrder | undefined, ledgerId?: string | undefined, alias?: string | undefined, 'providerDetails.vaultId'?: string | undefined, 'metadata.createdBy'?: string | undefined, 'metadata.lastModifiedBy'?: string | undefined, 'metadata.description'?: string | undefined, 'metadata.customProperties'?: Array | undefined, lock?: Array | undefined, 'additionalDetails.processingStatus'?: CoreAccountProcessingStatus | undefined, 'additionalDetails.ledgers.ledgerId'?: Array | undefined, 'additionalDetails.ledgers.status'?: Array | undefined}; export type GetApiV1DomainsDomainIdAccountsOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const coreAccountKeyStrategy = z.enum(["VaultHard", "VaultSoft", "Random"]); export const coreAccountPublicKeyExtendedPublicKey = z.object({value: z.string(), chainCode: z.string(), type: z.literal("ExtendedPublicKey")}); export const coreAccountPublicKeyPublicKey = z.object({value: z.string(), type: z.literal("PublicKey")}); export const coreAccountPublicKey = z.discriminatedUnion("type", [coreAccountPublicKeyExtendedPublicKey, coreAccountPublicKeyPublicKey]); export const coreVaultAccountKeyInformationRandom = z.object({publicKey: coreAccountPublicKey.optional(), type: z.literal("Random")}); export const coreVaultAccountKeyInformationVaultDerived = z.object({publicKey: coreAccountPublicKey.optional(), derivationPath: z.string().min(1), type: z.literal("VaultDerived")}); export const coreVaultAccountKeyInformation = z.discriminatedUnion("type", [coreVaultAccountKeyInformationRandom, coreVaultAccountKeyInformationVaultDerived]); export const coreVaultAccountProviderInformationKeyId = z.enum(["SECP256K1_CUSTODY_1", "ED25519_CUSTODY_1", "ED25519_CUSTODY_2", "ED25519_STAKING_1"]); export const coreAccountPublicKeyExtendedOnly = z.object({value: z.string(), chainCode: z.string(), type: z.literal("ExtendedPublicKey")}); export const coreVaultAccountProviderInformationKeyVaultDerived = z.object({id: coreVaultAccountProviderInformationKeyId, derivationPath: z.string().min(1), publicKey: coreAccountPublicKeyExtendedOnly.optional(), type: z.literal("VaultDerived")}); export const coreAccountPublicKeyOnly = z.object({value: z.string(), type: z.literal("PublicKey")}); export const coreVaultAccountProviderInformationKeyVaultDerivedNonExtended = z.object({id: coreVaultAccountProviderInformationKeyId, derivationPath: z.string().min(1), publicKey: coreAccountPublicKeyOnly, type: z.literal("VaultDerivedNonExtended")}); export const coreVaultAccountProviderInformationKeyVaultRandom = z.object({id: coreVaultAccountProviderInformationKeyId, publicKey: coreAccountPublicKey.optional(), type: z.literal("VaultRandom")}); export const coreVaultAccountProviderInformationKey = z.discriminatedUnion("type", [coreVaultAccountProviderInformationKeyVaultDerived, coreVaultAccountProviderInformationKeyVaultDerivedNonExtended, coreVaultAccountProviderInformationKeyVaultRandom]); export const coreAccountProviderInformation = z.object({vaultId: z.string(), keyStrategy: coreAccountKeyStrategy, keyInformation: coreVaultAccountKeyInformation, keys: z.array(coreVaultAccountProviderInformationKey).optional(), type: z.literal("Vault")}); export const coreLockStatus = z.enum(["Unlocked", "Locked", "Archived"]); export const coreUserReference = z.object({id: z.string(), domainId: z.string()}); export const coreStringsMap = z.record(z.string(), z.string()); export const coreEntityMetadata = z.object({description: z.string().max(250).optional(), revision: z.number().int().gte(1), createdAt: z.string(), createdBy: coreUserReference.optional(), lastModifiedAt: z.string(), lastModifiedBy: coreUserReference.optional(), customProperties: coreStringsMap}); export const coreAccount = z.object({id: z.string(), domainId: z.string(), alias: z.string().min(1).max(75), ledgerId: z.string().min(1).max(100).optional(), providerDetails: coreAccountProviderInformation, lock: coreLockStatus, metadata: coreEntityMetadata}); export const coreAccountProcessingDetailsCompleted = z.object({status: z.literal("Completed")}); export const coreAccountProcessingDetailsInterrupted = z.object({reason: z.string().min(1).max(200), status: z.literal("Interrupted")}); export const coreApiPendingAccountProcessingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountProcessingDetailsPending = z.object({hint: coreApiPendingAccountProcessingHint.optional(), status: z.literal("Pending")}); export const coreApiPreparingAccountProcessingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountProcessingDetailsPreparing = z.object({hint: coreApiPreparingAccountProcessingHint.optional(), status: z.literal("Preparing")}); export const coreApiRecoveringAccountProcessingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountProcessingDetailsRecovering = z.object({hint: coreApiRecoveringAccountProcessingHint.optional(), status: z.literal("Recovering")}); export const coreAccountProcessingDetailsTracked = z.object({status: z.literal("Tracked")}); export const coreAccountProcessingDetails = z.discriminatedUnion("status", [coreAccountProcessingDetailsCompleted, coreAccountProcessingDetailsInterrupted, coreAccountProcessingDetailsPending, coreAccountProcessingDetailsPreparing, coreAccountProcessingDetailsRecovering, coreAccountProcessingDetailsTracked]); export const coreApiAccountLedgerProcessingActivated = z.object({ledgerId: z.string().min(1).max(100), lastBalancesUpdateRequestedAt: z.string().optional(), lastBalancesUpdateProcessedAt: z.string().optional(), status: z.literal("Activated")}); export const coreAccountLedgerProcessingDetailsPendingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsPending = z.object({hint: coreAccountLedgerProcessingDetailsPendingHint.optional(), status: z.literal("Pending")}); export const coreAccountLedgerProcessingDetailsPreparingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsPreparing = z.object({hint: coreAccountLedgerProcessingDetailsPreparingHint.optional(), status: z.literal("Preparing")}); export const coreAccountLedgerProcessingDetailsRecoveringHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsRecovering = z.object({hint: coreAccountLedgerProcessingDetailsRecoveringHint.optional(), status: z.literal("Recovering")}); export const coreAccountLedgerProcessingDetailsTrackedHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsTracked = z.object({hint: coreAccountLedgerProcessingDetailsTrackedHint.optional(), status: z.literal("Tracked")}); export const coreAccountLedgerProcessingDetails = z.discriminatedUnion("status", [coreAccountLedgerProcessingDetailsPending, coreAccountLedgerProcessingDetailsPreparing, coreAccountLedgerProcessingDetailsRecovering, coreAccountLedgerProcessingDetailsTracked]); export const coreApiAccountLedgerProcessingActivating = z.object({ledgerId: z.string().min(1).max(100), processing: coreAccountLedgerProcessingDetails, status: z.literal("Activating")}); export const coreApiAccountLedgerProcessingAvailable = z.object({ledgerId: z.string().min(1).max(100), status: z.literal("Available")}); export const coreApiAccountLedgerProcessingAwaitingLedgerActivation = z.object({ledgerId: z.string().min(1).max(100), status: z.literal("AwaitingLedgerActivation")}); export const coreApiAccountLedgerProcessingUnavailable = z.object({ledgerId: z.string().min(1).max(100), status: z.literal("Unavailable")}); export const coreApiAccountLedgerProcessing = z.discriminatedUnion("status", [coreApiAccountLedgerProcessingActivated, coreApiAccountLedgerProcessingActivating, coreApiAccountLedgerProcessingAvailable, coreApiAccountLedgerProcessingAwaitingLedgerActivation, coreApiAccountLedgerProcessingUnavailable]); export const coreAccountAdditionalDetails = z.object({processing: coreAccountProcessingDetails, lastBalancesUpdateRequestedAt: z.string().optional(), lastBalancesUpdateProcessedAt: z.string().optional(), ledgers: z.array(coreApiAccountLedgerProcessing)}); export const coreApiAccount = z.object({data: coreAccount, signature: z.string(), signingKey: z.string(), additionalDetails: coreAccountAdditionalDetails.optional()}); export const coreAccountsCollection = z.object({items: z.array(coreApiAccount), count: z.number().int(), currentStartingAfter: z.string().optional(), nextStartingAfter: 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 accounts * * GET /v1/domains/{domainId}/accounts */ export const getApiV1DomainsDomainIdAccounts = async (args: GetApiV1DomainsDomainIdAccountsArgs, options: GetApiV1DomainsDomainIdAccountsOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.startingAfter != null) query.append("startingAfter", String(args.startingAfter)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.ledgerId != null) query.append("ledgerId", String(args.ledgerId)) if (args.alias != null) query.append("alias", String(args.alias)) if (args['providerDetails.vaultId'] != null) query.append("providerDetails.vaultId", String(args['providerDetails.vaultId'])) if (args['metadata.createdBy'] != null) query.append("metadata.createdBy", String(args['metadata.createdBy'])) if (args['metadata.lastModifiedBy'] != null) query.append("metadata.lastModifiedBy", String(args['metadata.lastModifiedBy'])) if (args['metadata.description'] != null) query.append("metadata.description", String(args['metadata.description'])) for (const item of args['metadata.customProperties'] ?? []) query.append("metadata.customProperties", String(item)) for (const item of args.lock ?? []) query.append("lock", String(item)) if (args['additionalDetails.processingStatus'] != null) query.append("additionalDetails.processingStatus", String(args['additionalDetails.processingStatus'])) for (const item of args['additionalDetails.ledgers.ledgerId'] ?? []) query.append("additionalDetails.ledgers.ledgerId", String(item)) for (const item of args['additionalDetails.ledgers.status'] ?? []) query.append("additionalDetails.ledgers.status", String(item)) if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/domains/${encodeURIComponent(String(args.domainId))}/accounts${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(coreAccountsCollection, await res.json()) };