passFactor static method

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

Derive the pass factor for BIP38 encryption.

  • 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.

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([...prefactor, ...ownerEntropy])
          : prefactor;

  return combinedValue;
}