generateRandomAddress static method
Uint8List
generateRandomAddress(
- Uint8List? tag,
- Uint8List secret, [
- RandomGenerator randomGenerator = randomBytes
Generates a random WOTS address using the randomGenerator Note: use your own randomGenerator that fills in deterministic bytes if you want to generate a specific address
Implementation
static Uint8List generateRandomAddress(
Uint8List? tag,
Uint8List secret, [
RandomGenerator randomGenerator = randomBytes,
]) {
if (secret.length != PARAMSN) {
throw ArgumentError('Invalid secret length');
}
if (tag != null && tag.length != 12) {
throw ArgumentError('Invalid tag length');
}
final address = Uint8List(2208);
final rnd2 = Uint8List(PARAMSN);
// Generate random bytes for address
randomGenerator(address);
// Copy random bytes to rnd2
rnd2.setRange(0, PARAMSN, address, 2176);
// Generate public key
wotsPkgen(address, secret,
address.sublist(WOTSSIGBYTES, WOTSSIGBYTES + PARAMSN), 0, rnd2);
address.setRange(2176, 2208, rnd2);
stampAddressSuffix(address);
final readyAddress = tag != null ? Tag.tag(address, tag) : address;
if (!isValid(secret, readyAddress, randomGenerator)) {
// Reached only when this library builds a key it cannot verify.
throw ArgumentError('Invalid WOTS'); // coverage:ignore-line
}
return readyAddress;
}