constructor(options?: {
peers?: string[], // Custom Gun peers
localStorage?: boolean, // Enable/disable localStorage
radisk?: boolean, // Enable/disable radisk
gun?: Gun // Existing Gun instance
})Creates a new WalletManager instance. Initializes Gun, user and managers for Ethereum and StealthChain.
Parameters:
options: Optional configuration objectpeers: Array of Gun peer URLs (default: predefined peers)localStorage: Whether to use localStorage (default: false)radisk: Whether to use radisk storage (default: false)gun: Existing Gun instance to use instead of creating a new one
Default Configuration:
{
peers: [
"https://gun-manhattan.herokuapp.com/gun",
"https://peer.wallie.io/gun",
"https://gun-relay.scobrudot.dev/gun"
],
localStorage: false,
radisk: false
}async createAccount(alias: string, passphrase: string, callback?: (error?: Error) => void): Promise<void>Creates a new GunDB account.
alias: Account usernamepassphrase: Account passwordcallback: Optional callback for error handling
async login(alias: string, passphrase: string): Promise<string>Performs login with specified credentials.
alias: Account usernamepassphrase: Account password- Returns: Public key of authenticated user
logout(): voidLogs out current user.
async loginWithPrivateKey(privateKey: string): Promise<string>Performs login using an Ethereum private key.
privateKey: Ethereum private key- Returns: Account public key
async saveWallet(wallet: Wallet, publicKey: string, storageType?: StorageType): Promise<void>Saves a wallet to specified storage.
wallet: Wallet to savepublicKey: Associated public keystorageType: Storage type (GUN, LOCAL, BOTH)
async saveWalletToGun(wallet: Wallet, publicKey: string): Promise<void>Saves a wallet to Gun.
wallet: Wallet to savepublicKey: Associated public key
async retrieveWallets(publicKey: string): Promise<Wallet[]>Retrieves all wallets from Gun.
publicKey: User's public key- Returns: Array of wallets
async retrieveWalletLocally(publicKey: string): Promise<Wallet | null>Retrieves a wallet from localStorage.
publicKey: User's public key- Returns: Found wallet or null
async deleteWallet(publicKey: string, walletAddress: string): Promise<void>Deletes a specific wallet.
publicKey: User's public keywalletAddress: Address of wallet to delete
async convertToEthPk(gunPrivateKey: string): Promise<string>Converts a Gun private key to Ethereum format.
gunPrivateKey: Gun private key in base64Url format- Returns: Private key in hex format
static async createWalletObj(gunKeyPair: GunKeyPair): Promise<WalletResult>Creates a new wallet from a Gun key pair.
gunKeyPair: Gun key pair- Returns: Object containing wallet and entropy
static async createWalletFromSalt(gunKeyPair: GunKeyPair, salt: string): Promise<Wallet>Creates a wallet from salt and Gun key pair.
gunKeyPair: Gun key pairsalt: Salt for derivation- Returns: New wallet
async exportAllData(publicKey: string): Promise<string>Exports all user data.
publicKey: User's public key- Returns: JSON containing all data
async importAllData(jsonData: string, publicKey: string): Promise<void>Imports user data.
jsonData: JSON data to importpublicKey: User's public key
async checkLocalData(publicKey: string): Promise<{hasWallet: boolean, hasStealthKeys: boolean, hasPasskey: boolean}>Checks user's local data.
publicKey: Public key to check- Returns: Local data status
async clearLocalData(publicKey: string): Promise<void>Clears all local data for a user.
publicKey: Public key of data to clear
getPublicKey(): stringGets current user's public key.
- Returns: User's public key
getCurrentUserKeyPair(): GunKeyPairGets current user's key pair.
- Returns: Gun key pair
async exportGunKeyPair(): Promise<string>Exports current user's Gun key pair.
- Returns: JSON string of key pair
async importGunKeyPair(keyPairJson: string): Promise<string>Imports a Gun key pair.
keyPairJson: JSON string of key pair- Returns: Imported account's public key
constructor(gun: Gun)Creates a new StealthChain instance.
gun: Gun instance to use
generateStealthKeys(cb: Callback<StealthKeyPair>): voidGenerates a new stealth key pair.
cb: Callback receiving key pair- Callback Result:
StealthKeyPair
generateStealthAddress(recipientPublicKey: string, cb: Callback<StealthAddressResult>): voidGenerates a stealth address for a recipient.
recipientPublicKey: Recipient's public keycb: Callback receiving result- Callback Result:
StealthAddressResult
openStealthAddress(stealthAddress: string, ephemeralKey: string, cb: Callback<ethers.Wallet>): voidOpens a stealth address.
stealthAddress: Stealth address to openephemeralKey: Ephemeral keycb: Callback receiving wallet- Callback Result:
ethers.Wallet
saveStealthKeys(stealthKeyPair: StealthKeyPair, cb: Callback<void>): voidSaves stealth keys.
stealthKeyPair: Key pair to savecb: Completion callback
retrieveStealthKeysFromRegistry(publicKey: string, cb: Callback<string>): voidRetrieves stealth keys from registry.
publicKey: Public key to look upcb: Callback receiving keys
constructor(walletManager: WalletManager)Creates a new EthereumManager instance.
walletManager: WalletManager instance
setCustomProvider(rpcUrl: string, privateKey: string): voidSets a custom provider.
rpcUrl: RPC provider URLprivateKey: Wallet private key
async createAccountWithEthereum(): Promise<string>Creates an account using an Ethereum account.
- Returns: Created username (Ethereum address)
async loginWithEthereum(): Promise<string | null>Performs login using an Ethereum account.
- Returns: Public key if login successful
enum StorageType {
GUN, // Decentralized storage
LOCAL, // Local storage
BOTH // Both storages
}interface StealthKeyPair {
pub: string; // Public key
priv: string; // Private key
epub: string; // Ephemeral public key
epriv: string; // Ephemeral private key
}interface StealthAddressResult {
stealthAddress: string; // Generated stealth address
ephemeralPublicKey: string; // Ephemeral public key
recipientPublicKey: string; // Recipient public key
}interface WalletResult {
walletObj: Wallet; // Wallet object
entropy: string; // Used entropy
}