/** * Common shared types used by both browser and iframe packages */ // Basic types export interface FeatureFlags { isMultiBackupEnabled?: boolean /** Enable presignature buffer for faster signing (SECP256K1 only). */ usePresignatures?: boolean /** Per-curve max presignatures (e.g. { SECP256K1: 3 }). */ maxPresignaturesPerCurve?: Partial> } export interface Network { id: string chainId: string name: string } export interface Address { id: string network: Network value: string } export interface Balance { contractAddress: string balance: string } export interface PortalError { code: number message?: string } // DKG types export interface DkgData { backupSharePairId?: string share: string signingSharePairId?: string } /** Presignature item stored per curve (SECP256K1 only in current implementation). */ export interface Presignature { id: string expiresAt: string data: string } // Transaction types export interface EIP1559Transaction { from: string to: string // Optional data?: string gasLimit?: string maxFeePerGas?: string maxPriorityFeePerGas?: string nonce?: string value?: string } export interface LegacyTransaction { from: string to: string // Optional data?: string gasLimit?: string gasPrice?: string nonce?: string value?: string } export type EthereumTransaction = EIP1559Transaction | LegacyTransaction // Legacy transaction type (deprecated - use TransactionHistoryItem instead) export interface Transaction { asset: string blockNum: string category: string chainId: string erc1155Metadata: null | string erc721TokenId: null | string from: string hash: string metadata: { blockTimestamp: string } rawContract: { address: string decimal: string value: string } to: string tokenId: null | string uniqueId: string value: number } /** * Solana error type (can be string, structured object, or null) * Observed from backend: errors can be strings or objects with code/message */ export type SolanaError = | string | { code?: string | number message?: string data?: unknown } | null /** * Solana transaction instruction data structure * Backend returns variable shapes depending on program * Extended version with optional parsed fields */ export interface SolanaTransactionInstruction { accounts: number[] data: string programIdIndex: number stackHeight?: number parsed?: unknown program?: string programId?: string } /** * Token balance type for Solana pre/post balances * Structure varies by token standard (SPL, Token-2022, etc.) */ export interface SolanaTokenBalance { accountIndex: number mint: string owner?: string programId?: string uiTokenAmount?: { amount: string decimals: number uiAmount: number | null uiAmountString: string } } /** * Inner instruction structure for Solana transactions * Nested program invocations */ export interface SolanaInnerInstruction { index: number instructions: Array<{ accounts: number[] data: string programIdIndex: number parsed?: unknown }> } /** * Solana transaction reward entry */ export interface SolanaReward { pubkey: string lamports: number postBalance: number rewardType: string | null commission: number | null } /** * Base transaction type shared by both regular and UserOp transactions */ interface BaseTransactionHistoryItem { hash: string from: string to: string | null value: string blockNumber: string | null blockTimestamp: number | null status: string | null chainId: string } /** * Regular blockchain transaction (EVM, Bitcoin, Tron, Stellar, etc.) * Includes optional token transfer metadata */ export interface RegularTransaction extends BaseTransactionHistoryItem { type: 'transaction' asset?: string tokenAddress?: string tokenDecimals?: number // UserOp fields must NOT be present userOpHash?: never entryPoint?: never actualGasCost?: never actualGasUsed?: never } /** * ERC-4337 User Operation transaction (EVM only) * Always has to=null and value='0', includes UserOp-specific fields */ export interface UserOperationTransaction extends BaseTransactionHistoryItem { type: 'userOperation' to: null value: '0' userOpHash: string entryPoint: string actualGasCost?: string actualGasUsed?: string // Token fields must NOT be present asset?: never tokenAddress?: never tokenDecimals?: never } /** * Discriminated union for unified transaction format * Used by EVM, Bitcoin, Tron, Stellar chains */ export type TransactionHistoryItem = RegularTransaction | UserOperationTransaction /** * Solana transaction details (legacy format) * Returned only for chains with namespace 'solana:*' * Uses signature-based identification instead of hash */ export interface SolanaTransactionDetails { blockTime: number error: SolanaError signature: string status: string tokenMint: string | null transactionDetails: { transaction: { message: { accountKeys: string[] header: { numRequiredSignatures: number numReadonlySignedAccounts: number numReadonlyUnsignedAccounts: number } instructions: SolanaTransactionInstruction[] recentBlockhash: string } signatures: string[] } | null signatureDetails: { blockTime: number confirmationStatus: string error: SolanaError memo: string | null signature: string slot: number } | null metadata: { blockTime: number | null slot: number | null error: SolanaError fee: number | null innerInstructions?: SolanaInnerInstruction[] | null loadedAddresses?: { readonly: string[] writable: string[] } | null logMessages: string[] | null postBalances: number[] | null postTokenBalances?: SolanaTokenBalance[] | null preBalances: number[] | null preTokenBalances?: SolanaTokenBalance[] | null rewards?: SolanaReward[] | null status: { Ok?: null | unknown Err?: unknown } | null version: 'legacy' | number | null } | null } | null } /** * Request parameters for fetching transaction history */ export interface GetTransactionHistoryParams { chainId: string limit?: number offset?: number order?: 'asc' | 'desc' address?: string userOperations?: 'include' | 'only' | 'exclude' } /** * Response metadata (same structure for both Solana and unified formats) */ export interface GetTransactionHistoryMetadata { address: string chainId: string clientId: string limit: number offset: number count: number } /** * Response for Solana chains (solana:*) */ export interface SolanaTransactionsResponse { data: { transactions: SolanaTransactionDetails[] } metadata: GetTransactionHistoryMetadata } /** * Response for unified format (EVM, Bitcoin, Tron, Stellar, etc.) */ export interface UnifiedTransactionsResponse { data: { transactions: TransactionHistoryItem[] } metadata: GetTransactionHistoryMetadata } /** * Polymorphic response type based on chain namespace * Runtime discrimination: check metadata.chainId namespace */ export type GetTransactionHistoryResponse = | SolanaTransactionsResponse | UnifiedTransactionsResponse // Built transaction types export type BuiltTransaction = BuiltEip155Transaction | BuiltSolanaTransaction | BuiltTronTransaction export interface BuiltEip155Transaction { transaction: { from: string to: string data: string } metadata: { amount: string fromAddress: string toAddress: string tokenAddress: string tokenDecimals: number rawAmount: string } } /** * Solana token extension data * Structure varies by extension type (e.g., transfer fee, metadata pointer) */ export interface SolanaTokenExtension { extension?: string state?: unknown } export interface BuiltSolanaTransaction { transaction: | string | { from: string to: string data?: string value?: string } metadata: { amount: string fromAddress: string toAddress: string tokenMintAddress: string tokenDecimals: number tokenProgramId: string tokenExtensions: SolanaTokenExtension[] rawAmount: string lastValidBlockHeight: string serializedTransactionBase64Encoded: string serializedTransactionBase58Encoded: string unsignedTransactionMessage: { signatures: null message: { accountKeys: string[] header: { numRequiredSignatures: number numReadonlySignedAccounts: number numReadonlyUnsignedAccounts: number } instructions: { programIdIndex: number accounts: number[] data: string }[] recentBlockhash: string } } } } export interface BuiltTronTransaction { transaction: { id: string network: string } metadata: { amount: string fromAddress: string toAddress: string tokenSymbol: string contractAddress: string | null } } // Simulation types export interface SimulateTransactionParam { to: string value?: string data?: string gas?: string gasPrice?: string maxFeePerGas?: string maxPriorityFeePerGas?: string } export interface SimulatedTransactionChange { amount?: string assetType?: string changeType?: string contractAddress?: string decimals?: number from?: string name?: string rawAmount?: string symbol?: string to?: string tokenId?: number } export interface SimulatedTransactionError { message: string } export interface SimulatedTransaction { changes: SimulatedTransactionChange[] gasUsed?: string error?: SimulatedTransactionError requestError?: SimulatedTransactionError } export type EvaluateTransactionParam = | { to: string value?: string data?: string gas?: string gasPrice?: string maxFeePerGas?: string maxPriorityFeePerGas?: string } | { transactions: string[] } export type EvaluateTransactionOperationType = | 'validation' | 'simulation' | 'all' export interface EvaluatedTransaction { validation?: Validation simulation?: Simulation block?: number } interface AssetMovement { summary: string value: string usdPrice?: string rawValue: string } /** * Asset metadata from Blockaid simulation */ export interface AssetMetadata { type: string decimals: number chainName?: string chainId?: number logoUrl?: string name?: string symbol?: string } /** * Asset differential (inflows/outflows) */ interface AssetDiff { asset: Record in: Record[] out: Record[] } /** * Extended asset properties from Blockaid * Structure varies by chain and asset type */ export interface ExtendedAssetProperties { address?: string contractAddress?: string tokenId?: string standard?: string [key: string]: unknown } /** * Account-level summary from simulation */ interface AccountSummary { assetsDiffs: Record[] exposures?: Record[] totalUsdDiff?: Record totalUsdExposure?: Record } /** * Address details from simulation (contract info, labels, etc.) */ export interface AddressDetails { contractName?: string type?: string isVerified?: boolean [key: string]: unknown } /** * Solana-specific delegation info */ export interface SolanaDelegation { account: string authority?: string amount?: string state?: string [key: string]: unknown } /** * Solana-specific ownership diff */ export interface SolanaOwnershipDiff { account: string before?: string after?: string [key: string]: unknown } export type Simulation = SuccessfulSimulation | UnsuccessfulSimulation interface SuccessfulSimulation { accountAddress: string accountSummary: AccountSummary addressDetails: Record assetsDiffs: Record status: string exposures?: Record totalUsdDiff?: Record totalUsdExposure?: Record solana?: { delegations: Record assetsOwnershipDiff: Record } } interface UnsuccessfulSimulation { status: 'Error' error: string } export type Validation = SuccessfulValidation | UnsuccessfulValidation interface SuccessfulValidation { classification?: string | null description?: string | null features: { type?: 'Malicious' | 'Warning' | 'Benign' | 'Info' featureId?: string description: string address?: string | null }[] reason?: string | null resultType: 'Benign' | 'Warning' | 'Malicious' status: string } interface UnsuccessfulValidation { error: string classification?: string | null description?: string | null features: { type?: 'Malicious' | 'Warning' | 'Benign' | 'Info' featureId?: string description: string address?: string | null }[] reason?: string | null resultType: 'Error' status: 'Error' } // NFT types export interface NFTContract { address: string } export interface TokenId { tokenId: string tokenMetadata: TokenMetadata } export interface TokenMetadata { tokenType: string } export interface TokenUri { gateway: string raw: string } export interface Media { gateway: string thumbnail: string raw: string format: string bytes: number } export interface Metadata { name: string description: string image: string external_url?: string } export interface ContractMetadata { name: string symbol: string tokenType: string contractDeployer: string deployedBlockNumber: number openSea?: OpenSeaMetadata } export interface OpenSeaMetadata { collectionName: string safelistRequestStatus: string imageUrl?: string description: string externalUrl: string lastIngestedAt: string floorPrice?: number twitterUsername?: string discordUrl?: string } export interface NFT { contract: NFTContract id: TokenId balance: string title: string description: string tokenUri: TokenUri media: Media[] metadata: Metadata timeLastUpdated: string contractMetadata: ContractMetadata } // Config types export interface GDriveConfig { clientId: string } export interface PasskeyConfig { relyingParty?: string relyingPartyOrigins?: string[] webAuthnHost?: string } export interface RpcConfig { [key: string]: string } export interface RpcProxyRequest { requestId: string method: string params: unknown[] chainId: string } export interface RpcProxyResponse { requestId: string jsonrpc: '2.0' id: string result?: unknown error?: { code: number; message: string } } export interface CustomBackupConfig { encryptionKey: string } // Backup method types - matches enum values from both browser and iframe packages export type BackupMethod = | 'GDRIVE' | 'PASSWORD' | 'PASSKEY' | 'CUSTOM' | 'FIREBASE' | 'UNKNOWN' export interface BackupConfigs { passwordStorage?: PasswordConfig customStorage?: CustomBackupConfig skipStorageWrite?: boolean } export interface BackupWorkerResult { result: EncryptedData | EncryptedWithPasswordData backupMethod: BackupMethod } export interface PasswordConfig { password: string } export interface OrgBackupShares { SECP256K1: string ED25519?: string } // Fund types export interface FundParams { amount: string token: string } export interface FundResponseData { explorerUrl: string txHash: string } export interface FundResponseMetadata { amount: string chainId: string clientId: string custodianId: string environmentId: string token: string } export interface FundResponse { data?: FundResponseData metadata: FundResponseMetadata error?: string } // Send asset types export interface SendAssetParams { amount: string to: string token: string sponsorGas?: boolean signatureApprovalMemo?: string /** Optional trace ID for correlating this operation with backend logs (X-Portal-Trace-Id). */ traceId?: string } export interface SendAssetResponse { transactionHash: string metadata: { amount?: string lastValidBlockHeight?: string rawAmount?: string tokenAddress?: string tokenDecimals?: number tokenSymbol?: string } } // Encrypt/Decrypt types export interface EncryptedData { cipherText: string key: string } export interface EncryptedWithPasswordData { cipherText: string } // Alias for backward compatibility export type EncryptWithPasswordData = EncryptedWithPasswordData export interface DecryptData { plaintext: string } // Quote types export interface QuoteArgs { affiliateAddress?: string buyAmount?: number buyToken: string buyTokenPercentageFee?: number enableSlippageProtection?: boolean excludedSources?: string feeRecipient?: string gasPrice?: number includedSources?: string intentOnFilling?: boolean priceImpactProtectionPercentage?: number sellAmount?: number sellToken: string skipValidation?: boolean slippagePercentage?: number takerAddress?: string } export interface QuoteResponse { allowanceTarget: string cost: string transaction: EIP1559Transaction | LegacyTransaction } // Misc types export interface SwitchEthereumChainParameter { chainId: string } export interface TypedData { types: Type[] primaryType: string domain: string message: string } export interface Type { name: string type: string } // Dapp types export interface DappOnNetwork { clientUrl?: string dapp: Dapp id: string network: Network } export interface Dapp { id: string name: string addresses: Address[] dappOnNetworks: DappOnNetwork[] image: DappImage } export interface DappImage { id: string filename: string data: string } // MPC operation types export interface SignArgs { chainId: string method: string params: string rpcUrl: string sponsorGas?: boolean /** Optional memo displayed to the user during the signature approval flow. */ signatureApprovalMemo?: string traceId?: string } export interface SignResult { data: string error: PortalError } /** Options for raw sign (e.g. raw_sign) operations. */ export interface RawSignOptions { /** Optional memo displayed to the user during the signature approval flow. */ signatureApprovalMemo?: string /** Caller-supplied trace ID for end-to-end request correlation. When provided it is * forwarded to the iframe and MPC layer instead of generating a new one. */ traceId?: string } export interface EncryptArgs { dkgData: string } export interface DecryptArgs { cipherText: string key?: string privateKey?: string } export interface GenerateData { address: string dkgResult: DkgData } export interface EncryptedResult { data: EncryptedData | EncryptedWithPasswordData error: PortalError } export interface DecryptResult { data: DecryptData error: PortalError } export interface EncryptedWithPasswordResult { data: EncryptedWithPasswordData error: PortalError } export interface MpcStatus { status: string done: boolean } export interface SharesOnDeviceResponse { ED25519: boolean SECP256K1: boolean } export interface EjectResult { SECP256K1: string } export interface EjectPrivateKeysResult { ED25519: string SECP256K1: string } export interface GenerateResult { data: GenerateData error: PortalError } export interface GenerateResponse { address: string cipherText?: string share?: string } export interface RotateData { address: string dkgResult: DkgData } export interface RotateResult { data: RotateData error: PortalError } export interface BackupData { share: string } export interface BackupResult { backupIds: string[] cipherText: string encryptionKey?: string } export interface BackupResponse { cipherText: string storageCallback: () => Promise encryptionKey?: string } export interface AddressResult { data: string type: string } // Passkey types export interface PasskeyStatusResponse { status: string } export interface PasskeyStorageOptions { portal: TPortal relyingParty?: string relyingPartyOrigins?: string[] webAuthnHost?: string authOrigin?: string } // Client Response types export type SharePairStatus = 'completed' | 'incomplete' export interface ClientResponseCustodian { id: string name: string } export interface ClientResponseSharePair { id: string createdAt: string status: SharePairStatus } export interface WalletPublicKey { X: string Y: string } // MPC Operation types export interface MpcOperationArgs { host: string mpcVersion: string apiKey?: string featureFlags?: FeatureFlags } export type GenerateArgs = MpcOperationArgs export interface EjectWorkerArgs extends MpcOperationArgs { clientShare: string organizationBackupShare: string }