deriveKeyHalves static method

Tuple<List<int>, List<int>> deriveKeyHalves(
  1. String passphrase,
  2. List<int> addressHash
)

Derive key halves from a passphrase and an address hash.

This method derives key halves from the provided passphrase and address hash. It uses scrypt key derivation to obtain two key halves for use in BIP38 encryption and decryption.

  • passphrase: The passphrase for key derivation.
  • addressHash: The address hash as input for key derivation.
  • Returns: A tuple (pair) containing the two derived key halves as List

Implementation

static Tuple<List<int>, List<int>> deriveKeyHalves(
    String passphrase, List<int> addressHash) {
  final key = Scrypt.deriveKey(
    StringUtils.encode(passphrase),
    addressHash,
    dkLen: Bip38NoEcConst.scryptKeyLen,
    n: Bip38NoEcConst.scryptN,
    r: Bip38NoEcConst.scryptR,
    p: Bip38NoEcConst.scryptP,
  );

  final derivedHalf1 = key.sublist(0, Bip38NoEcConst.scryptKeyLen ~/ 2);
  final derivedHalf2 = key.sublist(Bip38NoEcConst.scryptKeyLen ~/ 2);

  return Tuple(derivedHalf1, derivedHalf2);
}