generateIntermediatePassphrase static method

String generateIntermediatePassphrase(
  1. String passphrase, {
  2. int? lotNum,
  3. int? sequenceNum,
})

Generate an intermediate passphrase from a regular passphrase.

This method creates an intermediate passphrase from the given regular passphrase. It includes lot and sequence numbers if provided, and follows BIP38 standards for encoding.

  • passphrase: The regular passphrase to be transformed.
  • lotNum: The optional lot number.
  • sequenceNum: The optional sequence number.
  • Returns: A BIP38-compliant intermediate passphrase.

Implementation

static String generateIntermediatePassphrase(String passphrase,
    {int? lotNum, int? sequenceNum}) {
  /// Determine if lot and sequence numbers are included.
  final hasLotSeq = lotNum != null && sequenceNum != null;

  /// Generate owner entropy based on lot and sequence numbers.
  final ownerEntropy = hasLotSeq
      ? Bip38EcUtils.ownerEntropyWithLotSeq(lotNum, sequenceNum)
      : Bip38EcUtils.ownerEntropyNoLotSeq();

  /// Derive passfactor and passpoint from the passphrase and owner entropy.
  final passfactor =
      Bip38EcUtils.passFactor(passphrase, ownerEntropy, hasLotSeq);
  final passpoint = Bip38EcUtils.passPoint(passfactor);

  /// Determine the appropriate magic number based on lot and sequence numbers.
  final magic = hasLotSeq
      ? Bip38EcConst.intPassMagicWithLotSeq
      : Bip38EcConst.intPassMagicNoLotSeq;

  /// Encode the intermediate passphrase
  final intermediatePassphrase = Base58Encoder.checkEncode(
      List<int>.from([...magic, ...ownerEntropy, ...passpoint]));

  return intermediatePassphrase;
}