///
import type { AbstractLevelDOWN } from 'abstract-leveldown';
import EventEmitter from 'events';
import { FallbackProvider } from 'ethers';
import { RailgunSmartWalletContract } from './contracts/railgun-smart-wallet/V2/railgun-smart-wallet';
import { RelayAdaptV2Contract } from './contracts/relay-adapt/V2/relay-adapt-v2';
import { RelayAdapt7702Contract } from './contracts/relay-adapt/V2/relay-adapt-7702';
import { RelayAdapt7702ExecutionType } from './transaction/relay-adapt-7702-signature';
import { RegistryContract } from './contracts/relay-adapt/V2/registry';
import { Database } from './database/database';
import { Prover } from './prover/prover';
import { encodeAddress, decodeAddress } from './key-derivation/bech32';
import { RailgunWallet } from './wallet/railgun-wallet';
import { Chain, EngineDebugger } from './models/engine-types';
import { LegacyGeneratedCommitment, ShieldCommitment } from './models/formatted-types';
import { GetLatestValidatedRailgunTxid, QuickSyncEvents, QuickSyncRailgunTransactionsV2 } from './models/event-types';
import { ViewOnlyWallet } from './wallet/view-only-wallet';
import { HardwareWallet, type ExternalSignerConnector } from './wallet/hardware-wallet';
import { AbstractWallet } from './wallet/abstract-wallet';
import { ArtifactGetter } from './models/prover-types';
import { PollingJsonRpcProvider } from './provider/polling-json-rpc-provider';
import { UTXOMerkletree } from './merkletree/utxo-merkletree';
import { TXIDMerkletree } from './merkletree/txid-merkletree';
import { MerklerootValidator } from './models/merkletree-types';
import { TXIDVersion } from './models/poi-types';
import { Registry } from './utils/registry';
declare class RailgunEngine extends EventEmitter {
readonly db: Database;
private readonly utxoMerkletrees;
private readonly txidMerkletrees;
readonly prover: Prover;
readonly wallets: {
[key: string]: AbstractWallet;
};
readonly deploymentBlocks: Registry;
readonly quickSyncEvents: QuickSyncEvents;
readonly quickSyncRailgunTransactionsV2: QuickSyncRailgunTransactionsV2;
readonly validateRailgunTxidMerkleroot: MerklerootValidator;
readonly getLatestValidatedRailgunTxid: GetLatestValidatedRailgunTxid;
static walletSource: Optional;
private readonly skipMerkletreeScans;
private readonly hasSyncedRailgunTransactionsV2;
readonly isPOINode: boolean;
private constructor();
/**
* Create a RAILGUN Engine instance for a RAILGUN-compatible Wallet.
* @param walletSource - string representing your wallet's name (16 char max, lowercase and numerals only)
* @param leveldown - abstract-leveldown compatible store
* @param artifactGetter - async function to retrieve artifacts
* @param quickSync - quick sync function to speed up sync
* @param engineDebugger - log and error callbacks for verbose logging
* @param skipMerkletreeScans - whether to skip UTXO merkletree scans - useful for shield-only interfaces without Railgun wallets.
* @param isPOINode - run as POI node with full Railgun Txid merkletrees. set to false for all wallet implementations.
*/
static initForWallet(walletSource: string, leveldown: AbstractLevelDOWN, artifactGetter: ArtifactGetter, quickSyncEvents: QuickSyncEvents, quickSyncRailgunTransactionsV2: QuickSyncRailgunTransactionsV2, validateRailgunTxidMerkleroot: MerklerootValidator, getLatestValidatedRailgunTxid: GetLatestValidatedRailgunTxid, engineDebugger: Optional, skipMerkletreeScans?: boolean): Promise;
static initForPOINode(leveldown: AbstractLevelDOWN, artifactGetter: ArtifactGetter, quickSyncEvents: QuickSyncEvents, quickSyncRailgunTransactionsV2: QuickSyncRailgunTransactionsV2, engineDebugger: Optional): Promise;
static setEngineDebugger: (engineDebugger: EngineDebugger) => void;
/**
* Handle new commitment events and kick off balance scan on wallets
* @param chain - chain type/id for commitments
* @param treeNumber - tree of commitments
* @param startingIndex - starting index of commitments
* @param leaves - commitment data from events
*/
private commitmentListener;
private triggerDelayedTXIDMerkletreeSyncV2;
/**
* Handle new nullifiers
* @param chain - chain type/id for nullifiers
* @param nullifiers - transaction info to nullify commitment
*/
private nullifierListener;
/**
* Handle new unshield events
* @param chain - chain type/id
* @param unshields - unshield events
*/
private unshieldListener;
/**
* Handle new railgun transaction events for V3
* @param chain - chain type/id
* @param railgunTransactions - railgun transaction events
*/
private railgunTransactionsV3Listener;
private getMostRecentValidCommitmentBlock;
private getStartScanningBlock;
private performQuickSync;
private emitUTXOMerkletreeScanUpdateEvent;
private emitTXIDMerkletreeScanUpdateEvent;
private getNextStartingBlockSlowScan;
/**
* Scan contract history and sync
* @param chain - chain type/id to scan
* @param walletIdFilter - optional list of wallet ids to decrypt balances
*/
scanContractHistory(chain: Chain, walletIdFilter: Optional): Promise;
/**
* Scan (via quick sync or slow sync) on-chain data for the UTXO merkletree.
*/
private scanUTXOHistory;
emitScanEventHistoryComplete(txidVersion: TXIDVersion, chain: Chain): void;
private slowSyncV2;
private slowSyncV3;
/**
* Scan subgraph data for railgun transactions to build the TXID merkletree.
*/
private scanTXIDHistoryV2;
/**
* Sync Railgun txid merkletree.
* @param chain - chain type/id to scan
*/
syncRailgunTransactionsV2(chain: Chain, trigger: string): Promise;
private shouldAddNewRailgunTransactions;
private getLatestValidatedTxidIndex;
/**
* Use the log-derived Action path as a SOURCE for the V2 txid tree, not just a check.
* Off by default: the subgraph stays the sole writer until a deployment has opted in.
*/
setUseActionEventTxidSourceV2(enabled: boolean): void;
private useActionEventTxidSourceV2;
private fetchNextRailgunTransactionsV2;
private performSyncRailgunTransactionsV2;
private handleNewRailgunTransactionsV2;
private handleNewRailgunTransactionsV3;
getLatestRailgunTxidData(txidVersion: TXIDVersion, chain: Chain): Promise<{
txidIndex: number;
merkleroot: string;
}>;
/**
* Clears all merkletree leaves stored in database.
* @param chain - chain type/id to clear
*/
private clearSyncedUTXOMerkletreeLeavesAllTXIDVersions;
private clearUTXOMerkletreeAndLoadedWalletsAllTXIDVersions;
private clearSyncedUnshieldEvents;
private clearTXIDMerkletree;
/**
* Clears stored merkletree leaves and wallet balances, and re-scans fully.
* @param chain - chain type/id to rescan
* @param forceRescanDevOnly - can corrupt an existing scan, so only recommended in extreme cases (DEV only)
*/
fullRescanUTXOMerkletreesAndWallets(chain: Chain, walletIdFilter: Optional, forceRescanDevOnly?: boolean): Promise;
fullResetTXIDMerkletreesV2(chain: Chain): Promise;
private clearTXIDMerkletreeData;
resetRailgunTxidsAfterTxidIndex(txidVersion: TXIDVersion, chain: Chain, txidIndex: number): Promise;
private static validateMerkleroot;
/**
* Load network
* @param railgunSmartWalletContractAddress - address of railgun instance (proxy contract)
* @param relayAdaptV2ContractAddress - address of railgun instance (proxy contract)
* @param provider - ethers provider for network
* @param deploymentBlock - block number to start scanning from
*/
loadNetwork(chain: Chain, railgunSmartWalletContractAddress: string, relayAdaptV2ContractAddress: string, poseidonMerkleAccumulatorV3Address: string, poseidonMerkleVerifierV3Address: string, tokenVaultV3Address: string, defaultProvider: PollingJsonRpcProvider | FallbackProvider, pollingProvider: PollingJsonRpcProvider, deploymentBlocks: Record, poiLaunchBlock: Optional, supportsV3: boolean, relayAdapt7702ContractAddress?: string, railgunRegistryContractAddress?: string, relayAdapt7702ExecutionType?: RelayAdapt7702ExecutionType): Promise;
/**
* Unload network
* @param chain - chainID of network to unload
*/
private unloadNetwork;
private static getLastSyncedBlockDBPrefix;
/**
* Sets last synced block to resume syncing on next load.
* @param chain - chain type/id to store value for
* @param lastSyncedBlock - last synced block
*/
private setLastSyncedBlock;
/**
* Gets last synced block to resume syncing from.
* @param chain - chain type/id to get value for
* @returns lastSyncedBlock - last synced block
*/
private getLastSyncedBlock;
private static getUTXOMerkletreeHistoryVersionDBPrefix;
private static getTxidV2MerkletreeHistoryVersionDBPrefix;
private setUTXOMerkletreeHistoryVersion;
private getUTXOMerkletreeHistoryVersion;
private setTxidV2MerkletreeHistoryVersion;
private getTxidV2MerkletreeHistoryVersion;
getUTXOMerkletree(txidVersion: TXIDVersion, chain: Chain): UTXOMerkletree;
private hasUTXOMerkletree;
getTXIDMerkletree(txidVersion: TXIDVersion, chain: Chain): TXIDMerkletree;
private hasTXIDMerkletree;
getCompletedTxidFromNullifiers(txidVersion: TXIDVersion, chain: Chain, nullifiers: string[]): Promise>;
private decryptBalancesAllWallets;
private invalidateTXOsCacheAllWallets;
private allWallets;
/**
* Unload wallet
* @param id - wallet id to unload
*/
unloadWallet(id: string): void;
/**
* Unloads wallets, removes listeners and closes DB.
*/
unload(): Promise;
private loadWallet;
/**
* Load existing wallet
* @param {string} encryptionKey - encryption key of wallet
* @param {string} id - wallet ID
* @param {string} mnemonicPassword - BIP39 mnemonic password, if the wallet was created
* with one. Not stored by the engine; must be supplied on every load (and on spend).
* @returns id
*/
loadExistingWallet(encryptionKey: string, id: string, mnemonicPassword?: string): Promise;
/**
* Load existing wallet
* @param {string} encryptionKey - encryption key of wallet
* @param {string} id - wallet ID
* @returns id
*/
loadExistingViewOnlyWallet(encryptionKey: string, id: string): Promise;
loadExistingHardwareWallet(encryptionKey: string, id: string, connector: ExternalSignerConnector): Promise;
deleteWallet(id: string): Promise;
/**
* Creates wallet from mnemonic
* @param {string} encryptionKey - encryption key of wallet
* @param {string} mnemonic - mnemonic to load
* @param {number} index - derivation index to load
* @returns id
*/
createWalletFromMnemonic(encryptionKey: string, mnemonic: string, index?: number, creationBlockNumbers?: Optional): Promise;
/**
* Creates wallet from mnemonic and BIP39 mnemonic password.
* The mnemonic password is distinct from the wallet database encryption key.
*/
createWalletFromMnemonicWithPassword(encryptionKey: string, mnemonic: string, mnemonicPassword: string, index?: number, creationBlockNumbers?: Optional): Promise;
createViewOnlyWalletFromShareableViewingKey(encryptionKey: string, shareableViewingKey: string, creationBlockNumbers: Optional): Promise;
/**
* @param railgunAccountIndex - device account the viewing key came from. Required on first
* create; re-creating a stored wallet may omit it and keeps the stored account.
*/
createHardwareWalletFromShareableViewingKey(encryptionKey: string, shareableViewingKey: string, creationBlockNumbers: Optional, connector: ExternalSignerConnector, railgunAccountIndex?: number): Promise;
getAllShieldCommitments(txidVersion: TXIDVersion, chain: Chain, startingBlock: number): Promise<(ShieldCommitment | LegacyGeneratedCommitment)[]>;
/**
* Get RelayAdapt7702 contract address
* @param chain - chain type/id
* @returns address
*/
getRelayAdapt7702ContractAddress(chain: Chain): Optional;
/**
* Validate RelayAdapt7702 contract address
* @param chain - chain type/id
* @param address - address to validate
* @returns true if valid
*/
validateRelayAdapt7702Address(chain: Chain, address: string): Promise;
/**
* Pure check: returns false only when the registry reports a concrete (defined,
* non-zero) RelayAdapt7702 address that differs from the configured one. An absent
* or zero-address registry entry returns true (cannot confirm or deny).
*/
static relayAdapt7702AddressMatchesRegistry(registeredAddress: Optional, configuredAddress: string): boolean;
/**
* Warn (do not block) if the configured RelayAdapt7702 delegate address disagrees with
* the on-chain registry. Users sign EIP-7702 authorizations delegating to this address,
* so a mismatch is worth surfacing — but the registry can legitimately lag behind freshly
* deployed contracts, and blocking on that would brick otherwise-valid wallets. The engine
* keeps using the configured address; the warning flags the discrepancy for reconciliation.
*/
private warnIfRelayAdapt7702AddressMismatchesRegistry;
static encodeAddress: typeof encodeAddress;
static decodeAddress: typeof decodeAddress;
railgunSmartWalletContracts: Registry;
relayAdaptV2Contracts: Registry;
relayAdapt7702Contracts: Registry;
railgunRegistryContract: Registry;
}
export { RailgunEngine };