///
import { Signature } from '@railgun-community/circomlibjs';
import { Database } from '../database/database';
import { SpendingKeyPair } from '../key-derivation';
import { AbstractWallet } from './abstract-wallet';
import { PublicInputsRailgun } from '../models';
import { Prover } from '../prover/prover';
import { HDNodeWallet, Authorization } from 'ethers';
import { TransactionStructV2, TransactionStructV3 } from '../models/transaction-types';
import { RelayAdapt7702 } from '../abi/typechain/RelayAdapt7702';
import { RelayAdapt7702ExecutionDetails } from '../transaction/relay-adapt-7702-signature';
import type { RelayAdapt7702HookedSigner } from '../transaction/relay-adapt-7702-signer';
export type EphemeralWalletDerivationStrategy = (index: number) => string;
export type EphemeralWalletDBPathStrategy = () => string[];
export type EphemeralSignerRequest = {
readonly railgunWalletID: string;
readonly railgunAccountIndex: number;
readonly chainId: bigint;
readonly ephemeralIndex: number;
};
export interface EphemeralSignerProvider {
getPathSuffix: EphemeralWalletDerivationStrategy;
getDBPathSuffix: EphemeralWalletDBPathStrategy;
getSigner?: (request: EphemeralSignerRequest) => Promise;
}
declare class RailgunWallet extends AbstractWallet {
ephemeralWalletOverride: HDNodeWallet | undefined;
private ephemeralSignerProvider;
private ephemeralProviderIsCustom;
private ephemeralIndexLocks;
/**
* Load encrypted spending key Node from database
* Spending key should be kept private and only accessed on demand
* @returns {Promise}
*/
getSpendingKeyPair(encryptionKey: string, mnemonicPassword?: string): Promise;
sign(publicInputs: PublicInputsRailgun, encryptionKey: string, mnemonicPassword?: string): Promise;
/**
* Get ephemeral wallet for RelayAdapt7702
* @param {string} encryptionKey - encryption key to use with database
* @param {bigint} chainId - Chain ID for the ephemeral key
* @param {number} index - index of derivation path
* @param {string} mnemonicPassword - BIP-39 mnemonic password, if the wallet uses one
* @returns {Promise}
*/
getEphemeralWallet(encryptionKey: string, chainId: bigint, index: number, mnemonicPassword?: string): Promise;
/**
* Get current ephemeral key index
* @returns {Promise}
*/
getEphemeralKeyIndex(chainId: bigint): Promise;
/**
* Set ephemeral key index
* @param {bigint} chainId - Chain ID for the ephemeral key
* @param {number} index - new index
* @returns {Promise}
*/
setEphemeralKeyIndex(chainId: bigint, index: number): Promise;
/**
* Get current ephemeral address
* @param {string} encryptionKey - encryption key to use with database
* @param {bigint} chainId - Chain ID for the ephemeral key
* @returns {Promise}
*/
getCurrentEphemeralAddress(encryptionKey: string, chainId: bigint, mnemonicPassword?: string): Promise;
getCurrentEphemeralSigner(encryptionKey: string, chainId: bigint, mnemonicPassword?: string): Promise;
/**
* RAILGUN account index handed to a custom ephemeral signer provider.
* @param {string} encryptionKey - encryption key to use with database
* @returns {Promise}
*/
protected getEphemeralSignerAccountIndex(encryptionKey: string): Promise;
/**
* Get current ephemeral wallet
* @param {string} encryptionKey - encryption key to use with database
* @returns {Promise}
*/
getCurrentEphemeralWallet(encryptionKey: string, chainId: bigint, mnemonicPassword?: string): Promise;
setEphemeralSignerProvider(provider: EphemeralSignerProvider): void;
setEphemeralWalletDerivationStrategy(strategy: EphemeralWalletDerivationStrategy): void;
/**
* Whether ephemeral derivation uses the engine's default canonical layout
* (m/.../'). A custom signer provider controls its own derivation, so the
* engine cannot reconstruct its addresses from an integer index — index ratcheting
* and history scanning are therefore unsupported for custom providers, which must
* manage their own index via setEphemeralKeyIndex (namespaced by getDBPathSuffix).
*/
isCanonicalEphemeralProvider(): boolean;
/**
* Set current ephemeral wallet. This is not typically needed as the wallet can be derived on demand, but can be used to set a specific wallet if desired.
*/
setCurrentEphemeralWallet(wallet: HDNodeWallet): Promise;
/**
* Sign EIP-7702 Authorization and Execution Payload
* @param {string} encryptionKey - encryption key to use with database
* @param {string} contractAddress - RelayAdapt7702 contract address
* @param {bigint} chainId - Chain ID
* @param {(TransactionStructV2 | TransactionStructV3)[]} transactions - Railgun transactions
* @param {RelayAdapt7702.ActionDataStruct} actionData - Action Data
* @returns {Promise<{ authorization: Authorization; signature: string }>}
*/
sign7702Request(encryptionKey: string, contractAddress: string, chainId: bigint, transactions: (TransactionStructV2 | TransactionStructV3)[], actionData: RelayAdapt7702.ActionDataStruct, nonce?: number, executionDetails?: RelayAdapt7702ExecutionDetails, mnemonicPassword?: Optional, expectedEphemeralAddress?: Optional): Promise<{
authorization: Authorization;
signature: string;
}>;
/**
* Serialize a read-modify-write of the ephemeral key index per chain so
* concurrent callers can never observe the same index and derive the same
* ephemeral signer (which would reuse the EIP-7702 key / execute nonce).
*/
private runExclusiveEphemeralIndex;
/**
* Whether the engine may ratchet the ephemeral key index. By default only for the
* default provider: a custom provider manages its own index.
* @returns {boolean}
*/
protected ratchetsEphemeralIndex(_provider: EphemeralSignerProvider, providerIsCustom: boolean): boolean;
/**
* Atomically increment and persist the ephemeral key index for a chain,
* returning the new index.
* @returns {Promise}
*/
incrementEphemeralKeyIndex(chainId: bigint): Promise;
/**
* Atomically raise the ephemeral key index to candidateIndex when it exceeds the
* current stored index, returning the resulting index. Serialized with
* incrementEphemeralKeyIndex so a concurrent ratchet cannot be clobbered (used by the
* history-recovery scan).
* @returns {Promise}
*/
setEphemeralKeyIndexIfGreater(chainId: bigint, candidateIndex: number): Promise;
/**
* Ratchet ephemeral key index
* @returns {Promise}
*/
ratchetEphemeralAddress(chainId: bigint): Promise;
/**
* Load encrypted node from database with encryption key
* @param {BytesData} encryptionKey
* @returns {Node} BabyJubJub node
*/
private loadSpendingKey;
/**
* Helper to get the ethereum/whatever address is associated with this wallet.
* The BIP39 mnemonic password (if any) must be supplied; it is never stored.
*/
getChainAddress(encryptionKey: string, mnemonicPassword?: string): Promise;
/**
* Calculate Wallet ID from mnemonic and derivation path index
* @returns {string} hash of mnemonic and index
*/
private static generateID;
/**
* The BIP39 mnemonic password is never persisted; it must be supplied by the caller
* on load and on every spend. Verify the supplied password reproduces this wallet's
* ID — a mismatch means the wrong (or a missing) password was supplied, which would
* otherwise silently derive a different, unrelated key. Fail loudly instead.
*/
private static assertMnemonicPasswordMatchesID;
private static createWallet;
/**
* Create a wallet from mnemonic
* @param {Database} db - database
* @param {BytesData} encryptionKey - encryption key to use with database
* @param {string} mnemonic - mnemonic to load wallet from
* @param {number} index - index of derivation path to derive if not 0
* @returns {RailgunWallet} Wallet
*/
static fromMnemonic(db: Database, encryptionKey: string, mnemonic: string, index: number, creationBlockNumbers: Optional, prover: Prover): Promise;
/**
* Create a wallet from mnemonic and BIP39 mnemonic password.
*/
static fromMnemonicWithPassword(db: Database, encryptionKey: string, mnemonic: string, mnemonicPassword: string, index: number, creationBlockNumbers: Optional, prover: Prover): Promise;
/**
* Loads wallet data from database and creates wallet object
* @param {Database} db - database
* @param {BytesData} encryptionKey - encryption key to use with database
* @param {string} id - wallet id
* @returns {RailgunWallet} Wallet
*/
static loadExisting(db: Database, encryptionKey: string, id: string, prover: Prover, mnemonicPassword?: string): Promise;
}
export { RailgunWallet };