/// Determines the public key for which `sig` is a valid signature for /// `msg`. Requires a verify-capable context. public PublicKey Recover(Message msg, RecoverableSigniture sig) { if (Caps == ContextFlag.SignOnly || Caps == ContextFlag.None) { throw new Exception("IncapableContext"); } var pkBytes = new byte[64]; if (Proxy.secp256k1_ecdsa_recover(Ctx, pkBytes, sig.Value, msg.Value) != 1) { throw new Exception("InvalidSignature"); } return(PublicKey.From(pkBytes)); }
/// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce /// Requires a signing-capable context. public RecoverableSigniture sign_recoverable(Message msg, SecretKey sk) { if (Caps == ContextFlag.VerifyOnly || Caps == ContextFlag.None) { throw new Exception("IncapableContext"); } var ret = new byte[65]; // 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_recoverable(Ctx, ret, msg.Value, sk.Value, IntPtr.Zero /*Proxy.secp256k1_nonce_function_rfc6979()*/, IntPtr.Zero) == 1) { return(RecoverableSigniture.From(ret)); } throw new Exception("This should never happen!"); }