createProgramAddress static method
Derives a program address from the seeds
and programId
.
Throws an AssertionError if seeds
contains an invalid seed.
Throws an ED25519Exception if the generated Pubkey falls on the ed25519
curve.
Implementation
static Pubkey createProgramAddress(
final List<List<int>> seeds,
final Pubkey programId,
) {
final List<int> buffer = [];
for (final List<int> seed in seeds) {
check(seed.length <= nacl.maxSeedLength, 'Invalid seed length.');
buffer.addAll(seed);
}
buffer
..addAll(programId.toBytes())
..addAll(utf8.encode('ProgramDerivedAddress'));
final digestBytes = Uint8List.fromList(sha256.convert(buffer).bytes);
if (isOnCurve(digestBytes)) {
throw ED25519Exception('Invalid seeds $seeds\n'
'The public key address must fall off the `ed25519` curve.');
}
return Pubkey.fromUint8List(digestBytes);
}