import {z} from 'zod' export type Quantity = string | number; export type Hex = string; export type EthereumSign7702Authorization = {contract: string, chain_id: Quantity, nonce: Quantity, r: Hex, s: Hex, y_parity: number}; export type TempoCall = {to: string, data?: Hex | undefined, value?: Quantity | undefined}; export type TempoFeePayerSignature = {r: Hex, s: Hex, y_parity: number | number}; export type AccessListEntry = {address: string, storage_keys: Array}; export type TempoAAAuthorization = {contract: string, chain_id: Quantity, nonce: Quantity, signature: Hex}; export type UnsignedEthereumTransaction = {from?: string | undefined, to?: string | undefined, chain_id?: Quantity | undefined, nonce?: Quantity | undefined, data?: Hex | undefined, value?: Quantity | undefined, type?: (number | number | number) | undefined, gas_limit?: Quantity | undefined, gas_price?: Quantity | undefined, max_fee_per_gas?: Quantity | undefined, max_priority_fee_per_gas?: Quantity | undefined, authorization_list?: Array | undefined} | {type: number, from?: string | undefined, chain_id?: Quantity | undefined, nonce?: Quantity | undefined, gas_limit?: Quantity | undefined, max_fee_per_gas?: Quantity | undefined, max_priority_fee_per_gas?: Quantity | undefined, calls: Array, fee_token?: string | undefined, nonce_key?: Quantity | undefined, valid_before?: Quantity | undefined, valid_after?: Quantity | undefined, fee_payer_signature?: TempoFeePayerSignature | undefined, access_list?: Array | undefined, aa_authorization_list?: Array | undefined}; export type EthereumSignTransactionRpcInputParams = {transaction: UnsignedEthereumTransaction}; export type CAIP2 = string; export type EthereumSendTransactionRpcInputParams = {transaction: UnsignedEthereumTransaction}; export type RpcSponsorAsset = string; export type RpcSponsorOptions = {asset: RpcSponsorAsset}; export type EthereumPersonalSignRpcInputParams = {message: string, encoding: 'utf-8' | 'hex'}; export type SignatureType = 'ecdsa' | 'erc1271'; export type SignatureOptions = {type: SignatureType}; export type TypedDataDomainInputParams = {[key: string]: unknown}; export type TypedDataTypeFieldInput = {name: string, type: string}; export type TypedDataTypesInputParams = {[key: string]: Array}; export type EthereumTypedDataInput = {domain: TypedDataDomainInputParams, types: TypedDataTypesInputParams, message: {[key: string]: unknown}, primary_type: string}; export type EthereumSignTypedDataRpcInputParams = {typed_data: EthereumTypedDataInput}; export type EthereumSecp256k1SignRpcInputParams = {hash: Hex}; export type EthereumSign7702AuthorizationRpcInputParams = {contract: string, chain_id: Quantity, nonce?: Quantity | undefined, executor?: 'self' | undefined}; export type UserOperationInput = {sender: string, nonce: Hex, factory?: string | undefined, factory_data?: Hex | undefined, call_data: Hex, paymaster?: string | undefined, paymaster_data?: Hex | undefined, paymaster_post_op_gas_limit?: Hex | undefined, paymaster_verification_gas_limit?: Hex | undefined, max_priority_fee_per_gas: Hex, max_fee_per_gas: Hex, call_gas_limit: Hex, verification_gas_limit: Hex, pre_verification_gas: Hex}; export type EthereumSignUserOperationRpcInputParams = {contract: string, user_operation: UserOperationInput, chain_id: Quantity}; export type EthereumSendCallsCall = {to: string, value?: Quantity | undefined, data?: Hex | undefined}; export type EthereumSendCallsRpcInputParams = {calls: Array}; export type AptosBcsHex = string; export type AptosSignTransactionRpcInputParams = {transaction: AptosBcsHex}; export type SolanaSignTransactionRpcInputParams = {transaction: string, encoding: 'base64'}; export type SolanaSignAndSendTransactionRpcInputParams = {transaction: string, encoding: 'base64'}; export type SolanaSignMessageRpcInputParams = {message: string, encoding: 'base64'}; export type SparkTransferRpcInputParams = {receiver_spark_address: string, amount_sats: number}; export type SparkOutputSelectionStrategy = 'SMALL_FIRST' | 'LARGE_FIRST'; export type TokenOutput = {id?: string | undefined, owner_public_key: string, revocation_commitment?: string | undefined, withdraw_bond_sats?: number | undefined, withdraw_relative_block_locktime?: number | undefined, token_public_key?: string | undefined, token_identifier?: string | undefined, token_amount: string}; export type OutputWithPreviousTransactionData = {output?: TokenOutput | undefined, previous_transaction_hash: string, previous_transaction_vout: number}; export type SparkTransferTokensRpcInputParams = {token_identifier: string, token_amount: number, receiver_spark_address: string, output_selection_strategy?: SparkOutputSelectionStrategy | undefined, selected_outputs?: Array | undefined}; export type SparkGetClaimStaticDepositQuoteRpcInputParams = {transaction_id: string, output_index?: number | undefined}; export type SparkClaimStaticDepositRpcInputParams = {transaction_id: string, output_index?: number | undefined, credit_amount_sats: number, signature: string}; export type SparkCreateLightningInvoiceRpcInputParams = {amount_sats: number, memo?: string | undefined, expiry_seconds?: number | undefined, include_spark_address?: boolean | undefined, receiver_identity_pubkey?: string | undefined, description_hash?: string | undefined}; export type SparkPayLightningInvoiceRpcInputParams = {invoice: string, max_fee_sats: number, prefer_spark?: boolean | undefined, amount_sats_to_send?: number | undefined}; export type SparkSignMessageWithIdentityKeyRpcInputParams = {message: string, compact?: boolean | undefined}; export type SparkExitSpeed = 'FAST' | 'MEDIUM' | 'SLOW'; export type SparkWithdrawRpcInputParams = {onchain_address: string, exit_speed: SparkExitSpeed, amount_sats?: number | undefined, fee_amount_sats?: number | undefined, fee_quote_id?: string | undefined, deduct_fee_from_withdrawal_amount?: boolean | undefined}; export type SparkGetWithdrawalFeeQuoteRpcInputParams = {amount_sats: number, onchain_address: string}; export type TronHexAddress = string; export type TronContract = {type: 'TransferContract', owner_address: TronHexAddress, to_address: TronHexAddress, amount: number} | {type: 'TriggerSmartContract', owner_address: TronHexAddress, contract_address: TronHexAddress, data?: string | undefined, call_value?: number | undefined, call_token_value?: number | undefined, token_id?: number | undefined}; export type TronRawDataForSign = {contract: Array, data?: string | undefined, timestamp?: number | undefined, fee_limit?: number | undefined, ref_block_bytes: string, ref_block_hash: string, expiration: number}; export type TronSignTransactionRpcInputParams = {raw_data: TronRawDataForSign}; export type TronRawDataForSend = {contract: Array, data?: string | undefined, timestamp?: number | undefined, fee_limit?: number | undefined, ref_block_bytes?: string | undefined, ref_block_hash?: string | undefined, expiration?: number | undefined}; export type TronSendTransactionRpcInputParams = {raw_data: TronRawDataForSend, reference_id?: string | undefined}; export type XrplSignTransactionRpcInputParams = {transaction: string, encoding: 'hex'}; export type NearUnsignedTransactionBorshBase64 = string; export type NearSignTransactionRpcRequestBodyParams = {transaction: NearUnsignedTransactionBorshBase64}; export type HPKEEncryption = 'HPKE'; export type RecipientPublicKey = string | string; export type ExportType = 'display' | 'client'; export type PrivateKeyExportInput = {encryption_type: HPKEEncryption, recipient_public_key: RecipientPublicKey, export_type?: ExportType | undefined, export_seed_phrase?: boolean | undefined}; export type SeedPhraseExportInput = {encryption_type: HPKEEncryption, recipient_public_key: RecipientPublicKey, export_type?: ExportType | undefined, export_seed_phrase?: boolean | undefined}; export type WalletRpcRequestBody = {method: 'eth_signTransaction', params: EthereumSignTransactionRpcInputParams, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'eth_sendTransaction', caip2: CAIP2, params: EthereumSendTransactionRpcInputParams, sponsor?: boolean | undefined, sponsor_options?: RpcSponsorOptions | undefined, reference_id?: string | undefined, experimental_data_suffix?: Hex | undefined, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'personal_sign', params: EthereumPersonalSignRpcInputParams, caip2?: CAIP2 | undefined, signature_options?: SignatureOptions | undefined, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'eth_signTypedData_v4', params: EthereumSignTypedDataRpcInputParams, caip2?: CAIP2 | undefined, signature_options?: SignatureOptions | undefined, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'secp256k1_sign', params: EthereumSecp256k1SignRpcInputParams, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'eth_sign7702Authorization', params: EthereumSign7702AuthorizationRpcInputParams, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'eth_signUserOperation', params: EthereumSignUserOperationRpcInputParams, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'wallet_sendCalls', caip2: CAIP2, params: EthereumSendCallsRpcInputParams, sponsor?: boolean | undefined, sponsor_options?: RpcSponsorOptions | undefined, experimental_data_suffix?: Hex | undefined, address?: string | undefined, chain_type?: 'ethereum' | undefined, wallet_id?: string | undefined} | {method: 'aptos_signTransaction', params: AptosSignTransactionRpcInputParams} | {method: 'signTransaction', params: SolanaSignTransactionRpcInputParams, address?: string | undefined, chain_type?: 'solana' | undefined, wallet_id?: string | undefined} | {method: 'signAndSendTransaction', caip2: CAIP2, params: SolanaSignAndSendTransactionRpcInputParams, sponsor?: boolean | undefined, sponsor_options?: RpcSponsorOptions | undefined, reference_id?: string | undefined, optimistic_broadcast?: boolean | undefined, address?: string | undefined, chain_type?: 'solana' | undefined, wallet_id?: string | undefined} | {method: 'signMessage', params: SolanaSignMessageRpcInputParams, address?: string | undefined, chain_type?: 'solana' | undefined, wallet_id?: string | undefined} | {method: 'transfer', params: SparkTransferRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'getBalance', network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'transferTokens', params: SparkTransferTokensRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'getStaticDepositAddress', network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'getClaimStaticDepositQuote', params: SparkGetClaimStaticDepositQuoteRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'claimStaticDeposit', params: SparkClaimStaticDepositRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'createLightningInvoice', params: SparkCreateLightningInvoiceRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'payLightningInvoice', params: SparkPayLightningInvoiceRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'signMessageWithIdentityKey', params: SparkSignMessageWithIdentityKeyRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'withdraw', params: SparkWithdrawRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'getWithdrawalFeeQuote', params: SparkGetWithdrawalFeeQuoteRpcInputParams, network?: ('MAINNET' | 'REGTEST') | undefined} | {method: 'tron_signTransaction', params: TronSignTransactionRpcInputParams} | {method: 'tron_sendTransaction', caip2?: CAIP2 | undefined, params: TronSendTransactionRpcInputParams} | {method: 'xrpl_signTransaction', params: XrplSignTransactionRpcInputParams} | {method: 'near_signTransaction', params: NearSignTransactionRpcRequestBodyParams} | {address: string, method: 'exportPrivateKey', params: PrivateKeyExportInput} | {address: string, method: 'exportSeedPhrase', params: SeedPhraseExportInput}; export type CreateApiV1IntentsWalletsWalletIdRpcArgs = {wallet_id: string, 'privy-app-id': string, 'privy-request-expiry'?: string | undefined, body: WalletRpcRequestBody}; export type CreateApiV1IntentsWalletsWalletIdRpcOptions = {baseUrl?: string | undefined, appSecretAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intentAuthorizationKeyQuorumMember = z.discriminatedUnion("type", [z.object({type: z.literal("user"), user_id: z.string(), signed_at: z.number().nullable()}), z.object({type: z.literal("key"), public_key: z.string(), signed_at: z.number().nullable()})]); export const intentAuthorizationMember = z.discriminatedUnion("type", [z.object({type: z.literal("user"), user_id: z.string(), signed_at: z.number().nullable()}), z.object({type: z.literal("key"), public_key: z.string(), signed_at: z.number().nullable()}), z.object({type: z.literal("key_quorum"), key_quorum_id: z.string(), display_name: z.string().optional(), threshold_met: z.boolean(), threshold: z.number(), members: z.array(intentAuthorizationKeyQuorumMember)})]); export const intentAuthorization = z.object({members: z.array(intentAuthorizationMember), threshold: z.number(), display_name: z.string().optional()}); export const intentStatus = z.enum(["pending", "processing", "executed", "failed", "expired", "rejected", "dismissed"]); export const quantity = z.union([z.string().max(300002), z.number().int().gte(-9007199254740991).lte(9007199254740991)]); export const hex = z.string().max(300002); export const ethereumSign7702Authorization = z.object({contract: z.string(), chain_id: quantity, nonce: quantity, r: hex, s: hex, y_parity: z.number()}); export const tempoCall = z.object({to: z.string(), data: hex.optional(), value: quantity.optional()}); export const tempoFeePayerSignature = z.object({r: hex, s: hex, y_parity: z.union([z.literal(0), z.literal(1)])}); export const accessListEntry = z.object({address: z.string(), storage_keys: z.array(hex)}); export const tempoAAAuthorization = z.object({contract: z.string(), chain_id: quantity, nonce: quantity, signature: hex}); export const unsignedEthereumTransaction = z.union([z.object({from: z.string().optional(), to: z.string().optional(), chain_id: quantity.optional(), nonce: quantity.optional(), data: hex.optional(), value: quantity.optional(), type: z.union([z.literal(0), z.literal(2), z.literal(4)]).optional(), gas_limit: quantity.optional(), gas_price: quantity.optional(), max_fee_per_gas: quantity.optional(), max_priority_fee_per_gas: quantity.optional(), authorization_list: z.array(ethereumSign7702Authorization).optional()}), z.object({type: z.literal(118), from: z.string().optional(), chain_id: quantity.optional(), nonce: quantity.optional(), gas_limit: quantity.optional(), max_fee_per_gas: quantity.optional(), max_priority_fee_per_gas: quantity.optional(), calls: z.array(tempoCall), fee_token: z.string().optional(), nonce_key: quantity.optional(), valid_before: quantity.optional(), valid_after: quantity.optional(), fee_payer_signature: tempoFeePayerSignature.optional(), access_list: z.array(accessListEntry).optional(), aa_authorization_list: z.array(tempoAAAuthorization).optional()})]); export const ethereumSignTransactionRpcInputParams = z.object({transaction: unsignedEthereumTransaction}); export const cAIP2 = z.string(); export const ethereumSendTransactionRpcInputParams = z.object({transaction: unsignedEthereumTransaction}); export const rpcSponsorAsset = z.string(); export const rpcSponsorOptions = z.object({asset: rpcSponsorAsset}); export const ethereumPersonalSignRpcInputParams = z.object({message: z.string().max(300002), encoding: z.union([z.literal("utf-8"), z.literal("hex")])}); export const signatureType = z.enum(["ecdsa", "erc1271"]); export const signatureOptions = z.object({type: signatureType}); export const typedDataDomainInputParams = z.record(z.string(), z.unknown()); export const typedDataTypeFieldInput = z.object({name: z.string(), type: z.string()}); export const typedDataTypesInputParams = z.record(z.string(), z.array(typedDataTypeFieldInput)); export const ethereumTypedDataInput = z.object({domain: typedDataDomainInputParams, types: typedDataTypesInputParams, message: z.record(z.string(), z.unknown()), primary_type: z.string()}); export const ethereumSignTypedDataRpcInputParams = z.object({typed_data: ethereumTypedDataInput}); export const ethereumSecp256k1SignRpcInputParams = z.object({hash: hex}); export const ethereumSign7702AuthorizationRpcInputParams = z.object({contract: z.string(), chain_id: quantity, nonce: quantity.optional(), executor: z.literal("self").optional()}); export const userOperationInput = z.object({sender: z.string(), nonce: hex, factory: z.string().optional(), factory_data: hex.optional(), call_data: hex, paymaster: z.string().optional(), paymaster_data: hex.optional(), paymaster_post_op_gas_limit: hex.optional(), paymaster_verification_gas_limit: hex.optional(), max_priority_fee_per_gas: hex, max_fee_per_gas: hex, call_gas_limit: hex, verification_gas_limit: hex, pre_verification_gas: hex}); export const ethereumSignUserOperationRpcInputParams = z.object({contract: z.string(), user_operation: userOperationInput, chain_id: quantity}); export const ethereumSendCallsCall = z.object({to: z.string(), value: quantity.optional(), data: hex.optional()}); export const ethereumSendCallsRpcInputParams = z.object({calls: z.array(ethereumSendCallsCall)}); export const aptosBcsHex = z.string().max(300002); export const aptosSignTransactionRpcInputParams = z.object({transaction: aptosBcsHex}); export const solanaSignTransactionRpcInputParams = z.object({transaction: z.string().max(300002), encoding: z.literal("base64")}); export const solanaSignAndSendTransactionRpcInputParams = z.object({transaction: z.string().max(300002), encoding: z.literal("base64")}); export const solanaSignMessageRpcInputParams = z.object({message: z.string().max(300002), encoding: z.literal("base64")}); export const sparkTransferRpcInputParams = z.object({receiver_spark_address: z.string(), amount_sats: z.number()}); export const sparkOutputSelectionStrategy = z.enum(["SMALL_FIRST", "LARGE_FIRST"]); export const tokenOutput = z.object({id: z.string().optional(), owner_public_key: z.string(), revocation_commitment: z.string().optional(), withdraw_bond_sats: z.number().optional(), withdraw_relative_block_locktime: z.number().optional(), token_public_key: z.string().optional(), token_identifier: z.string().optional(), token_amount: z.string()}); export const outputWithPreviousTransactionData = z.object({output: tokenOutput.optional(), previous_transaction_hash: z.string(), previous_transaction_vout: z.number()}); export const sparkTransferTokensRpcInputParams = z.object({token_identifier: z.string(), token_amount: z.number(), receiver_spark_address: z.string(), output_selection_strategy: sparkOutputSelectionStrategy.optional(), selected_outputs: z.array(outputWithPreviousTransactionData).optional()}); export const sparkGetClaimStaticDepositQuoteRpcInputParams = z.object({transaction_id: z.string(), output_index: z.number().optional()}); export const sparkClaimStaticDepositRpcInputParams = z.object({transaction_id: z.string(), output_index: z.number().optional(), credit_amount_sats: z.number(), signature: z.string()}); export const sparkCreateLightningInvoiceRpcInputParams = z.object({amount_sats: z.number(), memo: z.string().optional(), expiry_seconds: z.number().optional(), include_spark_address: z.boolean().optional(), receiver_identity_pubkey: z.string().optional(), description_hash: z.string().optional()}); export const sparkPayLightningInvoiceRpcInputParams = z.object({invoice: z.string(), max_fee_sats: z.number(), prefer_spark: z.boolean().optional(), amount_sats_to_send: z.number().optional()}); export const sparkSignMessageWithIdentityKeyRpcInputParams = z.object({message: z.string(), compact: z.boolean().optional()}); export const sparkExitSpeed = z.enum(["FAST", "MEDIUM", "SLOW"]); export const sparkWithdrawRpcInputParams = z.object({onchain_address: z.string(), exit_speed: sparkExitSpeed, amount_sats: z.number().optional(), fee_amount_sats: z.number().optional(), fee_quote_id: z.string().optional(), deduct_fee_from_withdrawal_amount: z.boolean().optional()}); export const sparkGetWithdrawalFeeQuoteRpcInputParams = z.object({amount_sats: z.number(), onchain_address: z.string()}); export const tronHexAddress = z.string(); export const tronContract = z.discriminatedUnion("type", [z.object({type: z.literal("TransferContract"), owner_address: tronHexAddress, to_address: tronHexAddress, amount: z.number().int().gt(0)}), z.object({type: z.literal("TriggerSmartContract"), owner_address: tronHexAddress, contract_address: tronHexAddress, data: z.string().optional(), call_value: z.number().int().gte(0).optional(), call_token_value: z.number().int().gte(0).optional(), token_id: z.number().int().gte(0).optional()})]); export const tronRawDataForSign = z.object({contract: z.array(tronContract), data: z.string().optional(), timestamp: z.number().int().gte(0).optional(), fee_limit: z.number().int().gte(0).optional(), ref_block_bytes: z.string(), ref_block_hash: z.string(), expiration: z.number().int().gte(0)}); export const tronSignTransactionRpcInputParams = z.object({raw_data: tronRawDataForSign}); export const tronRawDataForSend = z.object({contract: z.array(tronContract), data: z.string().optional(), timestamp: z.number().int().gte(0).optional(), fee_limit: z.number().int().gte(0).optional(), ref_block_bytes: z.string().optional(), ref_block_hash: z.string().optional(), expiration: z.number().int().gte(0).optional()}); export const tronSendTransactionRpcInputParams = z.object({raw_data: tronRawDataForSend, reference_id: z.string().max(64).optional()}); export const xrplSignTransactionRpcInputParams = z.object({transaction: z.string().max(300002), encoding: z.literal("hex")}); export const nearUnsignedTransactionBorshBase64 = z.string().min(1).max(300002); export const nearSignTransactionRpcRequestBodyParams = z.object({transaction: nearUnsignedTransactionBorshBase64}); export const hPKEEncryption = z.literal("HPKE"); export const recipientPublicKey = z.union([z.string(), z.string()]); export const exportType = z.enum(["display", "client"]); export const privateKeyExportInput = z.object({encryption_type: hPKEEncryption, recipient_public_key: recipientPublicKey, export_type: exportType.optional(), export_seed_phrase: z.boolean().optional()}); export const seedPhraseExportInput = z.object({encryption_type: hPKEEncryption, recipient_public_key: recipientPublicKey, export_type: exportType.optional(), export_seed_phrase: z.boolean().optional()}); export const walletRpcRequestBody = z.discriminatedUnion("method", [z.object({method: z.literal("eth_signTransaction"), params: ethereumSignTransactionRpcInputParams, address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("eth_sendTransaction"), caip2: cAIP2, params: ethereumSendTransactionRpcInputParams, sponsor: z.boolean().optional(), sponsor_options: rpcSponsorOptions.optional(), reference_id: z.string().min(1).max(64).optional(), experimental_data_suffix: hex.optional(), address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("personal_sign"), params: ethereumPersonalSignRpcInputParams, caip2: cAIP2.optional(), signature_options: signatureOptions.optional(), address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("eth_signTypedData_v4"), params: ethereumSignTypedDataRpcInputParams, caip2: cAIP2.optional(), signature_options: signatureOptions.optional(), address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("secp256k1_sign"), params: ethereumSecp256k1SignRpcInputParams, address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("eth_sign7702Authorization"), params: ethereumSign7702AuthorizationRpcInputParams, address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("eth_signUserOperation"), params: ethereumSignUserOperationRpcInputParams, address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("wallet_sendCalls"), caip2: cAIP2, params: ethereumSendCallsRpcInputParams, sponsor: z.boolean().optional(), sponsor_options: rpcSponsorOptions.optional(), experimental_data_suffix: hex.optional(), address: z.string().optional(), chain_type: z.literal("ethereum").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("aptos_signTransaction"), params: aptosSignTransactionRpcInputParams}), z.object({method: z.literal("signTransaction"), params: solanaSignTransactionRpcInputParams, address: z.string().optional(), chain_type: z.literal("solana").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("signAndSendTransaction"), caip2: cAIP2, params: solanaSignAndSendTransactionRpcInputParams, sponsor: z.boolean().optional(), sponsor_options: rpcSponsorOptions.optional(), reference_id: z.string().min(1).max(64).optional(), optimistic_broadcast: z.boolean().optional(), address: z.string().optional(), chain_type: z.literal("solana").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("signMessage"), params: solanaSignMessageRpcInputParams, address: z.string().optional(), chain_type: z.literal("solana").optional(), wallet_id: z.string().optional()}), z.object({method: z.literal("transfer"), params: sparkTransferRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("getBalance"), network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("transferTokens"), params: sparkTransferTokensRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("getStaticDepositAddress"), network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("getClaimStaticDepositQuote"), params: sparkGetClaimStaticDepositQuoteRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("claimStaticDeposit"), params: sparkClaimStaticDepositRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("createLightningInvoice"), params: sparkCreateLightningInvoiceRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("payLightningInvoice"), params: sparkPayLightningInvoiceRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("signMessageWithIdentityKey"), params: sparkSignMessageWithIdentityKeyRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("withdraw"), params: sparkWithdrawRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("getWithdrawalFeeQuote"), params: sparkGetWithdrawalFeeQuoteRpcInputParams, network: z.enum(["MAINNET", "REGTEST"]).optional()}), z.object({method: z.literal("tron_signTransaction"), params: tronSignTransactionRpcInputParams}), z.object({method: z.literal("tron_sendTransaction"), caip2: cAIP2.optional(), params: tronSendTransactionRpcInputParams}), z.object({method: z.literal("xrpl_signTransaction"), params: xrplSignTransactionRpcInputParams}), z.object({method: z.literal("near_signTransaction"), params: nearSignTransactionRpcRequestBodyParams}), z.object({address: z.string(), method: z.literal("exportPrivateKey"), params: privateKeyExportInput}), z.object({address: z.string(), method: z.literal("exportSeedPhrase"), params: seedPhraseExportInput})]); export const walletChainType = z.enum(["ethereum", "solana", "cosmos", "stellar", "sui", "aptos", "movement", "tron", "bitcoin-segwit", "bitcoin-taproot", "pearl", "near", "ton", "starknet", "xrpl", "spark"]); export const entityId = z.string().min(1); export const walletEntityType = z.enum(["user", "organization"]); export const walletEntity = z.object({id: entityId, type: walletEntityType}); export const keyQuorumId = z.string(); export const policyInput = z.array(z.string().min(24).max(24)); export const walletAdditionalSignerItem = z.object({signer_id: keyQuorumId, override_policy_ids: policyInput.optional()}); export const walletAdditionalSigner = z.array(walletAdditionalSignerItem); export const attachedWalletAutomation = z.object({id: z.string(), enabled: z.boolean()}); export const walletCustodian = z.object({provider: z.string(), provider_user_id: z.string()}); export const ethereumPersonalSignRpcResponseData = z.object({signature: z.string(), encoding: z.literal("hex")}); export const ethereumSignTypedDataRpcResponseData = z.object({signature: z.string(), encoding: z.literal("hex")}); export const ethereumSignTransactionRpcResponseData = z.object({signed_transaction: z.string(), encoding: z.literal("rlp")}); export const ethereumSendTransactionRpcResponseData = z.object({transaction_id: z.string().optional(), hash: z.string(), caip2: cAIP2, transaction_request: unsignedEthereumTransaction.optional(), user_operation_hash: z.string().optional(), reference_id: z.string().nullable().optional()}); export const ethereumSignUserOperationRpcResponseData = z.object({signature: z.string(), encoding: z.literal("hex")}); export const ethereumSign7702AuthorizationRpcResponseData = z.object({authorization: ethereumSign7702Authorization}); export const ethereumSecp256k1SignRpcResponseData = z.object({signature: hex, encoding: z.literal("hex")}); export const ethereumSendCallsRpcResponseData = z.object({transaction_id: z.string(), caip2: cAIP2}); export const aptosSignedTransactionBcsHex = z.string().max(300200); export const aptosSignTransactionRpcResponseData = z.object({signed_transaction: aptosSignedTransactionBcsHex, encoding: z.literal("hex")}); export const solanaSignMessageRpcResponseData = z.object({signature: z.string(), encoding: z.literal("base64")}); export const solanaSignTransactionRpcResponseData = z.object({signed_transaction: z.string(), encoding: z.literal("base64")}); export const solanaSignAndSendTransactionRpcResponseData = z.object({transaction_id: z.string().optional(), hash: z.string(), caip2: cAIP2, reference_id: z.string().nullable().optional(), signed_transaction: z.string().optional()}); export const sparkSigningKeyshare = z.object({owner_identifiers: z.array(z.string()), threshold: z.number(), public_key: z.string(), public_shares: z.record(z.string(), z.string()), updated_time: z.string()}); export const sparkNetwork = z.enum(["MAINNET", "REGTEST"]); export const sparkWalletLeaf = z.object({id: z.string(), tree_id: z.string(), value: z.number(), parent_node_id: z.string().optional(), node_tx: z.string(), refund_tx: z.string(), vout: z.number(), verifying_public_key: z.string(), owner_identity_public_key: z.string(), signing_keyshare: sparkSigningKeyshare.optional(), status: z.string(), network: sparkNetwork}); export const sparkTransferLeaf = z.object({leaf: sparkWalletLeaf.optional(), secret_cipher: z.string(), signature: z.string(), intermediate_refund_tx: z.string()}); export const sparkTransfer = z.object({id: z.string(), sender_identity_public_key: z.string(), receiver_identity_public_key: z.string(), status: z.string(), total_value: z.number(), expiry_time: z.string().optional(), leaves: z.array(sparkTransferLeaf), created_time: z.string().optional(), updated_time: z.string().optional(), type: z.string(), transfer_direction: z.string()}); export const sparkUserTokenMetadata = z.object({raw_token_identifier: z.string(), token_public_key: z.string(), token_name: z.string(), token_ticker: z.string(), decimals: z.number(), max_supply: z.string()}); export const sparkTokenBalance = z.object({balance: z.string(), token_metadata: sparkUserTokenMetadata}); export const sparkBalance = z.object({balance: z.string(), token_balances: z.record(z.string(), sparkTokenBalance)}); export const sparkTransferTokensRpcResponseData = z.object({id: z.string()}); export const sparkGetStaticDepositAddressRpcResponseData = z.object({address: z.string()}); export const sparkGetClaimStaticDepositQuoteRpcResponseData = z.object({transaction_id: z.string(), output_index: z.number(), network: z.string(), credit_amount_sats: z.number(), signature: z.string()}); export const sparkClaimStaticDepositRpcResponseData = z.object({transfer_id: z.string()}); export const sparkLightningReceiveRequest = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), network: z.string(), invoice: z.unknown(), status: z.string(), typename: z.string(), transfer: z.unknown(), payment_preimage: z.string().optional(), receiver_identity_public_key: z.string().optional()}); export const sparkLightningFee = z.object({original_value: z.number(), original_unit: z.string()}); export const sparkLightningSendRequest = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), network: z.string(), encoded_invoice: z.string(), fee: sparkLightningFee, idempotency_key: z.string(), status: z.string(), typename: z.string(), transfer: z.unknown(), payment_preimage: z.string().optional()}); export const sparkSignMessageWithIdentityKeyRpcResponseData = z.object({signature: z.string()}); export const sparkCurrencyAmount = z.object({original_value: z.number(), original_unit: z.string()}); export const sparkCoopExitRequest = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), network: z.string(), fee: sparkCurrencyAmount, l1_broadcast_fee: sparkCurrencyAmount, status: z.string(), expires_at: z.string(), coop_exit_txid: z.string(), fee_quote_id: z.string().optional(), exit_speed: sparkExitSpeed.optional()}); export const sparkCoopExitFeeQuote = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), network: z.string(), total_amount: sparkCurrencyAmount, user_fee_fast: sparkCurrencyAmount, user_fee_medium: sparkCurrencyAmount, user_fee_slow: sparkCurrencyAmount, l1_broadcast_fee_fast: sparkCurrencyAmount, l1_broadcast_fee_medium: sparkCurrencyAmount, l1_broadcast_fee_slow: sparkCurrencyAmount, expires_at: z.string()}); export const tronSignTransactionRpcResponseData = z.object({signed_transaction: z.string(), encoding: z.literal("hex")}); export const tronSendTransactionRpcResponseData = z.object({hash: z.string(), caip2: cAIP2, transaction_id: z.string(), reference_id: z.string().optional()}); export const xrplSignTransactionRpcResponseData = z.object({txn_signature: z.string(), signed_transaction: z.string(), encoding: z.literal("hex")}); export const nearSignedTransactionBorshBase64 = z.string().min(1).max(300090); export const nearSignTransactionRpcResponseData = z.object({signed_transaction: nearSignedTransactionBorshBase64, encoding: z.literal("base64")}); export const seedPhraseExportResponse = z.object({encryption_type: hPKEEncryption, ciphertext: z.string(), encapsulated_key: z.string()}); export const walletRpcResponse = z.discriminatedUnion("method", [z.object({method: z.literal("personal_sign"), data: ethereumPersonalSignRpcResponseData}), z.object({method: z.literal("eth_signTypedData_v4"), data: ethereumSignTypedDataRpcResponseData}), z.object({method: z.literal("eth_signTransaction"), data: ethereumSignTransactionRpcResponseData}), z.object({method: z.literal("eth_sendTransaction"), data: ethereumSendTransactionRpcResponseData}), z.object({method: z.literal("eth_signUserOperation"), data: ethereumSignUserOperationRpcResponseData}), z.object({method: z.literal("eth_sign7702Authorization"), data: ethereumSign7702AuthorizationRpcResponseData}), z.object({method: z.literal("secp256k1_sign"), data: ethereumSecp256k1SignRpcResponseData}), z.object({method: z.literal("wallet_sendCalls"), data: ethereumSendCallsRpcResponseData}), z.object({method: z.literal("aptos_signTransaction"), data: aptosSignTransactionRpcResponseData}), z.object({method: z.literal("signMessage"), data: solanaSignMessageRpcResponseData}), z.object({method: z.literal("signTransaction"), data: solanaSignTransactionRpcResponseData}), z.object({method: z.literal("signAndSendTransaction"), data: solanaSignAndSendTransactionRpcResponseData}), z.object({method: z.literal("transfer"), data: sparkTransfer.optional()}), z.object({method: z.literal("getBalance"), data: sparkBalance.optional()}), z.object({method: z.literal("transferTokens"), data: sparkTransferTokensRpcResponseData.optional()}), z.object({method: z.literal("getStaticDepositAddress"), data: sparkGetStaticDepositAddressRpcResponseData.optional()}), z.object({method: z.literal("getClaimStaticDepositQuote"), data: sparkGetClaimStaticDepositQuoteRpcResponseData.optional()}), z.object({method: z.literal("claimStaticDeposit"), data: sparkClaimStaticDepositRpcResponseData.optional()}), z.object({method: z.literal("createLightningInvoice"), data: sparkLightningReceiveRequest.optional()}), z.object({method: z.literal("payLightningInvoice"), data: z.union([sparkTransfer, sparkLightningSendRequest]).optional()}), z.object({method: z.literal("signMessageWithIdentityKey"), data: sparkSignMessageWithIdentityKeyRpcResponseData.optional()}), z.object({method: z.literal("withdraw"), data: sparkCoopExitRequest.optional()}), z.object({method: z.literal("getWithdrawalFeeQuote"), data: sparkCoopExitFeeQuote.optional()}), z.object({method: z.literal("tron_signTransaction"), data: tronSignTransactionRpcResponseData}), z.object({method: z.literal("tron_sendTransaction"), data: tronSendTransactionRpcResponseData}), z.object({method: z.literal("xrpl_signTransaction"), data: xrplSignTransactionRpcResponseData}), z.object({method: z.literal("near_signTransaction"), data: nearSignTransactionRpcResponseData}), z.object({method: z.literal("exportPrivateKey"), data: privateKeyExportInput}), z.object({method: z.literal("exportSeedPhrase"), data: seedPhraseExportResponse})]); export const rpcIntentResponse = z.object({intent_id: z.string(), created_by_display_name: z.string(), created_by_id: z.string().optional(), created_at: z.number(), resource_id: z.string(), authorization_details: z.array(intentAuthorization), status: intentStatus, custom_expiry: z.boolean(), expires_at: z.number(), rejected_at: z.number().optional(), dismissed_at: z.number().optional(), dismissal_reason: z.string().optional(), intent_type: z.literal("RPC"), request_details: z.object({method: z.literal("POST"), url: z.string(), body: walletRpcRequestBody}), current_resource_data: z.object({id: z.string(), address: z.string(), display_name: z.string().optional(), external_id: z.string().max(64).optional(), public_key: z.string().optional(), created_at: z.number(), chain_type: walletChainType, policy_ids: z.array(z.string()), owner_id: z.string().nullable(), parent_wallet_id: z.string().nullable().optional(), entity: walletEntity.nullable().optional(), additional_signers: walletAdditionalSigner, exported_at: z.number().nullable(), imported_at: z.number().nullable(), authorization_threshold: z.number().optional(), automations: z.array(attachedWalletAutomation).optional(), archived_at: z.number().nullable().optional(), chain: z.enum(["base", "solana", "tempo"]).optional(), custody: walletCustodian.optional()}).optional(), action_result: z.object({status_code: z.number(), executed_at: z.number(), authorized_by_display_name: z.string().optional(), authorized_by_id: z.string().optional(), response_body: walletRpcResponse}).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 RPC intent * * POST /v1/intents/wallets/{wallet_id}/rpc */ export const createApiV1IntentsWalletsWalletIdRpc = async (args: CreateApiV1IntentsWalletsWalletIdRpcArgs, options?: CreateApiV1IntentsWalletsWalletIdRpcOptions) => { const {baseUrl = "https://api.privy.io", fetch: fetchFn = fetch, appSecretAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['privy-app-id'] != null) headers.set("privy-app-id", String(args['privy-app-id'])) if (args['privy-request-expiry'] != null) headers.set("privy-request-expiry", String(args['privy-request-expiry'])) if (appSecretAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${appSecretAuth.username}:${appSecretAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/intents/wallets/${encodeURIComponent(String(args.wallet_id))}/rpc${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(rpcIntentResponse, await res.json()) };