isValidWithComponents static method

bool isValidWithComponents(
  1. Uint8List secret,
  2. Uint8List pk,
  3. Uint8List pubSeed,
  4. Uint8List rnd2,
  5. RandomGenerator randomGenerator,
)

Validates WOTS components

Implementation

static bool isValidWithComponents(
  Uint8List secret,
  Uint8List pk,
  Uint8List pubSeed,
  Uint8List rnd2,
  RandomGenerator randomGenerator,
) {
  if (secret.length != PARAMSN) {
    throw ArgumentError('Invalid secret length');
  }
  if (pk.length != WOTSSIGBYTES) {
    throw ArgumentError('Invalid pk length');
  }
  if (pubSeed.length != PARAMSN) {
    throw ArgumentError('Invalid pubSeed length');
  }
  if (rnd2.length != PARAMSN) {
    throw ArgumentError('Invalid rnd2 length');
  }

  // Generate random message
  final msg = Uint8List(PARAMSN);
  randomGenerator(msg);

  // Sign message
  final sig = Uint8List(WOTSSIGBYTES);
  wotsSign(sig, msg, secret, pubSeed, 0, rnd2);

  // Verify signature
  final computedPk = wotsPkFromSig(sig, msg, pubSeed, rnd2);

  // Compare public keys
  return _compareBytes(computedPk, pk);
}