derive method
Derives a new Schnorrkel public key and chain code using hierarchical deterministic key derivation (HDKD).
This method derives a new Schnorrkel public key and chain code from the current public key, an optional message, and a provided chain code. It is used for hierarchical deterministic key derivation scenarios.
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.
Returns: A tuple containing the derived Schnorrkel public key and chain code.
Example Usage:
SchnorrkelPublicKey currentPublicKey = ...;
List<int> chainCode = ...;
List<int> message = ...;
var (derivedPublicKey, derivedChainCode) = currentPublicKey.derive(chainCode, message);
The derive
method is used for hierarchical deterministic key derivation (HDKD)
and returns a tuple with the derived Schnorrkel public key and chain code.
Implementation
Tuple<SchnorrkelPublicKey, List<int>> derive(List<int> chainCode,
[List<int>? message]) {
final derive = _deriveScalarAndChainCode(chainCode, message);
final newKeyBigint =
BigintUtils.fromBytes(derive.item1, byteOrder: Endian.little);
final p = toPoint() + (Curves.generatorED25519 * newKeyBigint);
return Tuple(SchnorrkelPublicKey(p.toBytes()), derive.item2);
}