getSessionKeyAggCoeffConst static method

Secp256k1Scalar getSessionKeyAggCoeffConst({
  1. required MuSig2Session session,
  2. required List<int> pkBytes,
})

Implementation

static Secp256k1Scalar getSessionKeyAggCoeffConst({
  required MuSig2Session session,
  required List<int> pkBytes,
}) {
  final signerPk = session.publicKeys.any(
    (e) => BytesUtils.bytesEqualConst(e, pkBytes),
  );
  if (!signerPk) {
    throw ArgumentException.invalidOperationArguments(
      "getSessionKeyAggCoeff",
      name: "pk",
      reason: "The signer pubkey does not exists in pubkey list.",
    );
  }
  if (_isSecondUniqueKey(keys: session.publicKeys, key: pkBytes)) {
    return Secp256k1Const.secp256k1ScalarOne;
  }
  final hashKeys = P2TRUtils.taggedHash(
    MuSig2Constants.keyAggListDomain,
    session.publicKeys.expand((e) => e).toList(),
  );
  final hash = P2TRUtils.taggedHash(MuSig2Constants.keyAggCoeffDomain, [
    ...hashKeys,
    ...pkBytes,
  ]);
  return Secp256k1Utils.scalarFromBytes(hash);
}