nonceAgg static method
Aggregates public nonces for MuSig2
Implementation
static List<int> nonceAgg(List<List<int>> pubnonces) {
if (pubnonces.length < MuSig2Const.minimumRequiredKey) {
throw MuSig2Exception(
"At least two public nonces are required for aggregation.");
}
for (final i in pubnonces) {
if (i.length != MuSig2Const.pubnonceLength) {
throw MuSig2Exception("Invalid public nonce length.", details: {
"excpected": MuSig2Const.pubnonceLength,
"length": i.length
});
}
}
final nonce = DynamicByteTracker();
for (int i = 1; i < 3; i++) {
ProjectiveECCPoint? rJ;
for (final n in pubnonces) {
final offset = (i - 1) * EcdsaKeysConst.pubKeyCompressedByteLen;
final key = MuSig2Utils.encodePointAsEven(
n.sublist(offset, offset + EcdsaKeysConst.pubKeyCompressedByteLen));
if (rJ != null) {
rJ = (rJ + key).cast();
} else {
rJ = key;
}
}
if (rJ!.isInfinity) {
nonce.add(MuSig2Const.zero);
} else {
nonce.add(rJ.toBytes());
}
}
return nonce.toBytes();
}