public static bool TryParse(ReadOnlySpan <byte> in64, out SchnorrSignature sig) { sig = null; if (in64.Length != 64) { return(false); } if (!Secp256k1.SecpSchnorrSignature.TryCreate(in64, out var secpShnorr) || secpShnorr is null) { return(false); } sig = new SchnorrSignature(secpShnorr); return(true); }
public static bool TryParse(byte[] in64, [MaybeNullWhen(false)] out SchnorrSignature sig) { if (in64 == null) { throw new ArgumentNullException(nameof(in64)); } sig = null; if (in64.Length != 64) { return(false); } sig = new SchnorrSignature(in64); return(true); }
public bool Verify(uint256 m, PubKey pubkey, SchnorrSignature sig) { if (sig.R.CompareTo(PP) >= 0 || sig.S.CompareTo(Secp256k1.N) >= 0) { return(false); } var e = new BigInteger(1, Hashes.SHA256(Utils.BigIntegerToBytes(sig.R, 32).Concat(pubkey.ToBytes(), m.ToBytes()))).Mod(Secp256k1.N); var q = pubkey.ECKey.GetPublicKeyParameters().Q.Normalize(); var P = Secp256k1.Curve.CreatePoint(q.XCoord.ToBigInteger(), q.YCoord.ToBigInteger()); var R = Secp256k1.G.Multiply(sig.S).Add(P.Multiply(Secp256k1.N.Subtract(e))).Normalize(); if (R.IsInfinity || R.XCoord.ToBigInteger().CompareTo(sig.R) != 0 || BigInteger.Jacobi(R.YCoord.ToBigInteger(), PP) != 1) { return(false); } return(true); }
public static bool TryParse(byte[] in64, [MaybeNullWhen(false)] out SchnorrSignature sig) { return(TryParse(in64.AsSpan(), out sig)); }