public Signiture To_standard(Secp256K1 secp) { var ret = new byte[65]; var err = Proxy.secp256k1_ecdsa_recoverable_signature_convert(secp.Ctx, ret, Value); if (err == 1) { return(Signiture.From(ret)); } throw new Exception("This should never happen!"); }
/// Checks that `sig` is a valid ECDSA signature for `msg` using the public /// key `pubkey`. Returns `Ok(true)` on success. Note that this function cannot /// be used for Bitcoin consensus checking since there may exist signatures /// which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a /// verify-capable context. public void Verify(Message msg, Signiture sig, PublicKey pk) { if (Caps == ContextFlag.SignOnly || Caps == ContextFlag.None) { throw new Exception("IncapableContext"); } if (!pk.is_valid()) { throw new Exception("InvalidPublicKey"); } if (Proxy.secp256k1_ecdsa_verify(Ctx, sig.Value, msg.Value, pk.Value) == 0) { throw new Exception("IncorrectSignature"); } }
/// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce /// Requires a signing-capable context. public Signiture Sign(Message msg, SecretKey sk) { if (Caps == ContextFlag.VerifyOnly || Caps == ContextFlag.None) { throw new Exception("IncapableContext"); } var ret = new byte[64]; //// We can assume the return value because it's not possible to construct //// an invalid signature from a valid `Message` and `SecretKey` if (Proxy.secp256k1_ecdsa_sign(Ctx, ret, msg.Value, sk.Value, IntPtr.Zero /* Proxy.secp256k1_nonce_function_rfc6979()*/, IntPtr.Zero) == 1) { return(Signiture.From(ret)); } throw new Exception("This should never happen!"); }