softDerive method
(SchnorrkelSecretKey, List<int> )
softDerive(
- List<
int> chainCode, { - List<
int> ? message, - GenerateRandom? nonceGenerator,
Derives a new Schnorrkel secret key and chain code from the current secret key, chain code, and an optional message.
Parameters:
chainCode: A chain code used in the derivation.message(optional): An optional byte array message used in the derivation. Default is an empty byte array.nonceGenerator(optional): A function that generates a nonce. Default is a function that generates a random 32-byte nonce.
Implementation
(SchnorrkelSecretKey, List<int>) softDerive(
List<int> chainCode, {
List<int>? message,
GenerateRandom? nonceGenerator,
}) {
final derivePub = publicKey()._deriveScalarAndChainCode(chainCode, message);
final nonce =
nonceGenerator?.call(SchnorrkelKeyCost.nonceLength) ??
QuickCrypto.generateRandom(SchnorrkelKeyCost.nonceLength);
if (nonce.length != SchnorrkelKeyCost.nonceLength) {
throw const CryptoException("invalid none length.");
}
final newKey = Ed25519Utils.add(key(), derivePub.$1);
final combine = [...newKey, ...nonce];
return (SchnorrkelSecretKey.fromBytes(combine), derivePub.$2);
}