SecretWallet.encode constructor

SecretWallet.encode(
  1. String credentials,
  2. String password, {
  3. int scryptN = 8192,
  4. int p = 1,
})

Creates a new wallet wrapping the specified credentials by encrypting the private key with the password You can configure the parameter N of the scrypt algorithm if you need to. The default value for scryptN is 8192. Be aware that this N must be a power of two.

using a separate thread for encode or decode secret wallet.

Implementation

factory SecretWallet.encode(
  String credentials,
  String password, {
  int scryptN = 8192,
  int p = 1,
}) {
  final passwordBytes = Uint8List.fromList(utf8.encode(password));

  /// Generate a random salt for key derivation.
  final salt = generateRandom(size: 32);

  /// Create a Scrypt key derivator with specified parameters.
  final derivator = _ScryptKeyDerivator(32, scryptN, 8, p, salt);

  /// Generate a random UUID and convert it to a buffer.
  final uuid = UUID.toBuffer(UUID.generateUUIDv4());

  /// Generate a random initialization vector (IV) for encryption.
  final iv = generateRandom(size: 128 ~/ 8);

  /// Create a SecretWallet instance with the provided parameters.
  return SecretWallet._(credentials, derivator, passwordBytes, iv, uuid);
}