generateAddress static method

Uint8List generateAddress(
  1. Uint8List? tag,
  2. Uint8List secret,
  3. Map<String, Uint8List> componentsGenerator(
    1. Uint8List wotsSeed
    )
)

Generates a WOTS address using the componentsGenerator. Note: use your own componentsGenerator that fills in deterministic bytes if you want to generate a specific address

Implementation

static Uint8List generateAddress(
  Uint8List? tag,
  Uint8List secret,
  Map<String, Uint8List> Function(Uint8List wotsSeed) componentsGenerator,
) {
  if (secret.length != PARAMSN) {
    throw ArgumentError('Invalid secret length');
  }
  if (tag != null && tag.length != 12) {
    throw ArgumentError('Invalid tag length');
  }

  final sourcePK = Uint8List(WOTSSIGBYTES);
  final components = componentsGenerator(secret);
  final privateSeed = components['private_seed']!;

  wotsPkgen(sourcePK, privateSeed, components['public_seed']!, 0,
      components['addr_seed']!);

  final sourceAddress = Uint8List(2208);
  sourceAddress.setRange(0, WOTSSIGBYTES, sourcePK);
  sourceAddress.setRange(
      WOTSSIGBYTES, WOTSSIGBYTES + 32, components['public_seed']!);
  sourceAddress.setRange(WOTSSIGBYTES + 32, 2208, components['addr_seed']!);
  stampAddressSuffix(sourceAddress);

  final readyAddress =
      tag != null ? Tag.tag(sourceAddress, tag) : sourceAddress;

  if (!isValid(privateSeed, readyAddress, randomBytes)) {
    // Reached only when this library builds a key it cannot verify.
    throw ArgumentError('Invalid WOTS'); // coverage:ignore-line
  }

  return readyAddress;
}