hardDerive method

Tuple<SchnorrkelSecretKey, List<int>> hardDerive(
  1. List<int> chainCode, {
  2. List<int>? message,
  3. ExpansionMode mode = ExpansionMode.ed25519,
})

Derives a new Schnorrkel secret key and chain code from the current secret key, chain code, and an optional message.

This method performs a hard derivation following the Schnorrkel RistrettoPoint Hierarchical Deterministic Key Derivation (HDKD) scheme.

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.
  • mode (optional): The expansion mode for converting the mini-secret key. Default is ExpansionMode.ed25519.

Returns: A tuple containing a new Schnorrkel secret key and a new chain code, derived from the current secret key, chain code, and message.

Example Usage:

List<int> chainCode = ...;
SchnorrkelSecretKey currentSecretKey = ...;
List<int> message = ...;
var (newSecretKey, newChainCode) = currentSecretKey.hardDerive(chainCode, message);

The hardDerive method follows the Schnorrkel RistrettoPoint HDKD scheme to derive a new Schnorrkel secret key and chain code. It combines the current secret key, chain code, and an optional message to compute the new secret key and chain code. The mode parameter allows specifying the expansion mode for converting the mini-secret key.

Implementation

Tuple<SchnorrkelSecretKey, List<int>> hardDerive(List<int> chainCode,
    {List<int>? message, ExpansionMode mode = ExpansionMode.ed25519}) {
  final script = MerlinTranscript("SchnorrRistrettoHDKD");
  script.additionalData('sign-bytes'.codeUnits, message ?? List.empty());
  script.additionalData("chain-code".codeUnits, chainCode);
  script.additionalData("secret-key".codeUnits, key());
  final newSecret = script.toBytes("HDKD-hard".codeUnits, 32);
  final newChainCode = script.toBytes("HDKD-chaincode".codeUnits, 32);
  return Tuple(SchnorrkelMiniSecretKey.fromBytes(newSecret).toSecretKey(mode),
      newChainCode);
}