UserWallet class
Encrypted wallet container for secure key storage. Use static methods to create from keys or load from files.
Example
// From secret key
final wallet = await UserWallet.fromSecretKey(
secretKey: mySecretKey,
password: 'password',
);
// From mnemonic
final wallet = UserWallet.fromMnemonic(
mnemonic: '24 word phrase...',
password: 'password',
);
// Save to file
wallet.save('wallet.json');
// Load and decrypt
final key = await UserWallet.loadSecretKey('wallet.json', 'password');
Constructors
- UserWallet.fromMnemonic({required String mnemonic, required String password, Randomness? randomness})
-
Creates encrypted wallet from mnemonic phrase.
factory
- UserWallet.fromMnemonicWithBytes({required String mnemonic, required Uint8List passwordBytes, Randomness? randomness})
-
Creates encrypted wallet from a mnemonic phrase using a mutable
password buffer (
Uint8List) so callers can zero the password after use (M2-9). The mnemonic plaintext buffer is also zeroed in atry/finallyafter encryption (M2-10).factory
Properties
- encryptedData → EncryptedData
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- kind → UserWalletKind
-
final
- publicKeyWhenKindIsSecretKey → UserPublicKey?
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
save(
String filePath, {String? addressHrp}) → void - Saves encrypted wallet to file.
-
toJson(
{String? addressHrp}) → Map< String, dynamic> - Converts encrypted wallet to JSON.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
decrypt(
Map< String, dynamic> keyFileObject, String password, {int? addressIndex}) → Future<UserSecretKey> - Decrypts keystore file and returns secret key.
-
decryptMnemonic(
Map< String, dynamic> keyFileObject, String password) → Mnemonic - Decrypts a mnemonic-kind keystore to a Mnemonic.
-
decryptMnemonicBytes(
Map< String, dynamic> keyFileObject, String password) → Uint8List - Decrypts a mnemonic-kind keystore to the raw UTF-8 bytes of the mnemonic phrase.
-
decryptWithBytes(
Map< String, dynamic> keyFileObject, Uint8List passwordBytes, {int? addressIndex}) → Future<UserSecretKey> - Decrypts a keystore using a mutable password buffer that the caller can zero after use (M2-9).
-
fromSecretKey(
{required UserSecretKey secretKey, required String password, Randomness? randomness}) → Future< UserWallet> - Creates encrypted wallet from secret key using a UTF-8 password string.
-
fromSecretKeyWithBytes(
{required UserSecretKey secretKey, required Uint8List passwordBytes, Randomness? randomness}) → Future< UserWallet> -
Creates encrypted wallet from secret key using a mutable password
buffer (
Uint8List). -
loadMnemonic(
String filePath, String password) → Future< Mnemonic> - Loads and decrypts a mnemonic-kind keystore from a file on disk.
-
loadSecretKey(
String filePath, String password, {int? addressIndex}) → Future< UserSecretKey> - Loads secret key from encrypted keystore file.