passFactor static method

List<int> passFactor(
  1. String passphrase,
  2. List<int> ownerEntropy,
  3. bool hasLotSeq
)

Derive the pass factor for BIP38 encryption.

This method calculates the pass factor used in BIP38 encryption by applying the Scrypt key derivation function to a passphrase, owner entropy, and a flag indicating whether lot and sequence numbers are included in the owner entropy.

  • passphrase: The passphrase to be used in deriving the pass factor.
  • ownerEntropy: The owner entropy from which the pass factor is derived.
  • hasLotSeq: A boolean flag indicating whether lot and sequence numbers are included in the owner entropy.
  • Returns: A List

Implementation

static List<int> passFactor(
    String passphrase, List<int> ownerEntropy, bool hasLotSeq) {
  final ownerSalt = ownerSaltFromEntropy(ownerEntropy, hasLotSeq);

  /// Derive the prefactor using Scrypt key derivation function.
  final prefactor = Scrypt.deriveKey(
    StringUtils.encode(passphrase),
    ownerSalt,
    dkLen: Bip38EcConst.scryptPrefactorKeyLen,
    n: Bip38EcConst.scryptPrefactorN,
    p: Bip38EcConst.scryptPrefactorP,
    r: Bip38EcConst.scryptPrefactorR,
  );

  /// Combine the prefactor with owner entropy, if present.
  final combinedValue = hasLotSeq
      ? QuickCrypto.sha256DoubleHash(
          List<int>.from([...prefactor, ...ownerEntropy]))
      : prefactor;

  return combinedValue;
}