import {z} from 'zod' export type CreateApiV1AccountsArgs = {'X-Steward-Request-Timestamp'?: string | undefined, 'X-Steward-Request-Expires-At'?: string | undefined, 'X-Steward-Signature'?: string | undefined, 'X-Steward-Signing-Key-Id'?: string | undefined, 'Idempotency-Key'?: string | undefined, body: {id?: string | undefined, display_name?: (string | null) | undefined, displayName?: (string | null) | undefined, metadata?: {[key: string]: unknown} | undefined, owner_user_ids?: Array | undefined, ownerUserIds?: Array | undefined, additional_signer_ids?: Array | undefined, additionalSignerIds?: Array | undefined, signer_policy_ids?: Array | undefined, signerPolicyIds?: Array | undefined, wallet_ids?: Array | undefined, walletIds?: Array | undefined, user_wallet_ids?: Array | undefined, userWalletIds?: Array | undefined, wallets_configuration?: (Array<{chain_type?: ('ethereum' | 'evm' | 'solana' | 'bitcoin' | 'monero') | undefined, chainType?: ('ethereum' | 'evm' | 'solana' | 'bitcoin' | 'monero') | undefined, name?: string | undefined, wallet_id?: string | undefined, walletId?: string | undefined}>) | undefined, walletsConfiguration?: (Array<{chainType?: ('ethereum' | 'evm' | 'solana' | 'bitcoin' | 'monero') | undefined, name?: string | undefined, walletId?: string | undefined}>) | undefined}}; export type CreateApiV1AccountsOptions = {baseUrl?: string | undefined, tenantApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AccountsResponse = z.object({ok: z.literal(true), data: z.object({id: z.string(), tenantId: z.string(), displayName: z.string().nullable(), display_name: z.string().nullable().optional(), metadata: z.record(z.string(), z.unknown()), ownerUserIds: z.array(z.string()).optional(), owner_user_ids: z.array(z.string()).optional(), additionalSignerIds: z.array(z.string()).optional(), additional_signer_ids: z.array(z.string()).optional(), signerPolicyIds: z.array(z.string()).optional(), signer_policy_ids: z.array(z.string()).optional(), walletIds: z.array(z.string()), wallet_ids: z.array(z.string()).optional(), wallets: z.array(z.object({id: z.string(), walletId: z.string(), membershipId: z.string(), name: z.string().nullable(), ownerUserId: z.string().nullable().optional(), owner_user_id: z.string().nullable().optional(), walletType: z.string().nullable().optional(), wallet_type: z.string().nullable().optional(), custody: z.object({type: z.enum(["server", "user_embedded"]).optional(), ownerUserId: z.string().nullable().optional(), owner_user_id: z.string().nullable().optional()}).optional(), signing: z.object({signerCount: z.number().int().gte(0).optional(), activeSignerCount: z.number().int().gte(0).optional(), quorumCount: z.number().int().gte(0).optional(), activeQuorumCount: z.number().int().gte(0).optional()}).optional(), capabilities: z.array(z.enum(["sign_transaction", "sign_message", "sign_typed_data", "sign_user_operation", "sign_authorization", "send_calls", "transfer", "solana_transaction", "export_private_key"])), capabilityMetadata: z.record(z.string(), z.unknown()), capability_metadata: z.record(z.string(), z.unknown()).optional(), chainType: z.enum(["ethereum", "solana", "bitcoin", "monero"]), chainFamily: z.enum(["evm", "solana", "bitcoin", "monero"]), address: z.string().nullable(), purpose: z.string().nullable().optional(), venue: z.string().nullable().optional(), createdAt: z.string().nullable().optional()})), capabilities: z.array(z.enum(["sign_transaction", "sign_message", "sign_typed_data", "sign_user_operation", "sign_authorization", "send_calls", "transfer", "solana_transaction", "export_private_key"])), capabilityMetadata: z.record(z.string(), z.unknown()), capability_metadata: z.record(z.string(), z.unknown()).optional(), createdAt: z.string(), created_at: z.string().optional(), updatedAt: z.string(), updated_at: 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 }; /** * Create a digital asset account * * POST /v1/accounts */ export const createApiV1Accounts = async (args: CreateApiV1AccountsArgs, options?: CreateApiV1AccountsOptions) => { const {baseUrl = "http://localhost:3200", fetch: fetchFn = fetch, tenantApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Steward-Request-Timestamp'] != null) headers.set("X-Steward-Request-Timestamp", String(args['X-Steward-Request-Timestamp'])) if (args['X-Steward-Request-Expires-At'] != null) headers.set("X-Steward-Request-Expires-At", String(args['X-Steward-Request-Expires-At'])) if (args['X-Steward-Signature'] != null) headers.set("X-Steward-Signature", String(args['X-Steward-Signature'])) if (args['X-Steward-Signing-Key-Id'] != null) headers.set("X-Steward-Signing-Key-Id", String(args['X-Steward-Signing-Key-Id'])) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (tenantApiKey !== undefined) headers.set("X-Steward-API-Key", tenantApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts${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(createApiV1AccountsResponse, await res.json()) };