nonceGenerate method

  1. @override
MuSig2Nonce nonceGenerate({
  1. required List<int> publicKey,
  2. List<int>? rand,
  3. List<int>? sk,
  4. List<int>? aggPubKey,
  5. List<int>? msg,
  6. List<int>? extra,
})
override

Generates a MuSig2 nonce for signing publicKey is 33 bytes (compressed); optional 32-byte rand (random if null) and 32-byte sk (binds nonce to key); aggPubKey, msg and extra bind the nonce hash. Returns the 97-byte secret nonce with its 66-byte public nonce. Throws on invalid lengths.

Implementation

@override
MuSig2Nonce nonceGenerate({
  required List<int> publicKey,
  List<int>? rand,
  List<int>? sk,
  List<int>? aggPubKey,
  List<int>? msg,
  List<int>? extra,
}) {
  final result = api.nonceGenerate(
    publicKey: publicKey.asBytes,
    aggPubKey: aggPubKey?.asBytes,
    extra: extra?.asBytes,
    msg: msg?.asBytes,
    rand: (rand ?? QuickCrypto.generateRandom()).asBytes,
    sk: sk?.asBytes,
  );

  return result
      .map((e) => MuSig2Nonce(pubnonce: e.pubnonce, secnonce: e.secnonce))
      .unwrapOrThrowCryptoError();
}