nonceAgg method

  1. @override
List<int> nonceAgg(
  1. List<List<int>> pubnonces
)
override

Implementation

@override
List<int> nonceAgg(List<List<int>> pubnonces) {
  if (pubnonces.length < MuSig2Constants.minimumRequiredKey) {
    throw ArgumentException.invalidOperationArguments(
      "nonceAggConst",
      name: "pubnonces",
      reason: "Invalid public nonce length.",
    );
  }
  for (final i in pubnonces) {
    if (i.length != MuSig2Constants.pubnonceLength) {
      throw ArgumentException.invalidOperationArguments(
        "nonceAggConst",
        name: "pubnonces",
        reason: "Invalid public nonce length.",
      );
    }
  }
  final nonce = DynamicByteTracker();
  for (int i = 1; i < 3; i++) {
    Secp256k1Gej? rJ;
    for (final n in pubnonces) {
      final offset = (i - 1) * EcdsaKeysConst.pubKeyCompressedByteLen;
      final key = MuSig2UtilsConst.encodePointAsEvenConst(
        n.sublist(offset, offset + EcdsaKeysConst.pubKeyCompressedByteLen),
      );
      if (rJ != null) {
        Secp256k1.secp256k1GejAddGe(rJ, rJ, key);
      } else {
        rJ = Secp256k1Gej();
        Secp256k1.secp256k1GejSetGe(rJ, key);
      }
    }
    if (rJ!.infinity.toBool) {
      nonce.add(MuSig2Utils.zeroPk());
    } else {
      final e = Secp256k1Ge();
      Secp256k1.secp256k1GeSetGej(e, rJ);
      nonce.add(Secp256k1Utils.geToBytes(e));
    }
  }

  return nonce.toBytes();
}