generateAddress static method
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);
wotsPkgen(sourcePK, components['private_seed']!, 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']!);
// Apply tag if provided using Tag.tag
final readyAddress =
tag != null ? Tag.tag(sourceAddress, tag) : sourceAddress;
// Validate address
for (int i = 0; i < 10; i++) {
if (!isValid(secret, readyAddress, randomBytes)) {
throw ArgumentError('Invalid WOTS');
}
}
return readyAddress;
}