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 mult = Ed25519Utils.scalarMultBase(derive.item1);
final pAdd = Ed25519Utils.pointAdd(toPoint().toEdwardBytes(), mult);
final newPoint = RistrettoPoint.fromEdwardBytes(pAdd);
return Tuple(SchnorrkelPublicKey(newPoint.toBytes()), derive.item2);
}