decodeSessionConst static method

MuSig2SessionValues decodeSessionConst(
  1. MuSig2Session session
)

Implementation

static MuSig2SessionValues decodeSessionConst(MuSig2Session session) {
  final tweak = keyAggAndTweak(
    publicKeys: session.publicKeys,
    tweaks: session.tweaks,
  );
  final hash = P2TRUtils.taggedHash(MuSig2Constants.noncecoefDomain, [
    ...session.aggnonce,
    ...tweak.xOnly(),
    ...session.msg,
  ]);
  final b = _frUnchecked(hash);
  Secp256k1Point r1 = encodePointAsEvenConst(
    session.aggnonce.sublist(0, EcdsaKeysConst.pubKeyCompressedByteLen),
    allowInfitity: true,
  );
  Secp256k1Point r2 = encodePointAsEvenConst(
    session.aggnonce.sublist(
      EcdsaKeysConst.pubKeyCompressedByteLen,
      EcdsaKeysConst.pubKeyCompressedByteLen * 2,
    ),
    allowInfitity: true,
  );
  final r = () {
    final agg = r1 + r2 * b;
    // BIP-327 session fallback (mirrors `MuSig2Utils.decodeSession`):
    // an infinity aggregate nonce stands in for the generator.
    if (agg.isZero()) return MuSig2Constants.generator;
    return agg;
  }();
  final rBytes = r.toXOnly();
  final eHash = P2TRUtils.taggedHash(MuSig2Constants.challengeDomain, [
    ...rBytes,
    ...tweak.xOnly(),
    ...session.msg,
  ]);
  final sc = _frUnchecked(eHash);
  return MuSig2SessionValues(
    publicKey: tweak.publicKey,
    gacc: tweak.gacc,
    tacc: tweak.tacc,
    b: b.toBytes(),
    r: r,
    e: sc.toBytes(),
  );
}