deriveKeyHalves static method

Tuple<List<int>, List<int>> deriveKeyHalves(
  1. List<int> passpoint,
  2. List<int> addressHash,
  3. List<int> ownerEntropy
)

Derive key halves from passpoint, address hash, and owner entropy.

This method derives two halves of a key using Scrypt key derivation function. It takes a passpoint, an address hash, and owner entropy as input, combines them, and then derives two key halves. The Scrypt parameters are defined in Bip38EcConst for consistency and security.

  • passpoint: The passpoint used in key derivation.
  • addressHash: The address hash to be combined in key derivation.
  • ownerEntropy: The owner entropy used in key derivation.
  • Returns: A tuple (pair) of List

Implementation

static Tuple<List<int>, List<int>> deriveKeyHalves(
    List<int> passpoint, List<int> addressHash, List<int> ownerEntropy) {
  /// Derive a key using Scrypt with combined data.
  final key = Scrypt.deriveKey(
    passpoint,
    List<int>.from([...addressHash, ...ownerEntropy]),
    dkLen: Bip38EcConst.scryptHalvesKeyLen,
    n: Bip38EcConst.scryptHalvesN,
    p: Bip38EcConst.scryptHalvesP,
    r: Bip38EcConst.scryptHalvesR,
  );

  /// Split the derived key into two halves.
  final derivedHalf1 =
      List<int>.from(key.sublist(0, Bip38EcConst.scryptHalvesKeyLen ~/ 2));
  final derivedHalf2 =
      List<int>.from(key.sublist(Bip38EcConst.scryptHalvesKeyLen ~/ 2));

  return Tuple(derivedHalf1, derivedHalf2);
}