示例#1
0
        public static byte[] RecoverKeyFromCompact(byte[] messageHash, byte[] compactSignature, int recoveryId, bool compressed)
        {
            byte[] publicKey           = new byte[64];
            byte[] serializedPublicKey = new byte[compressed ? 33 : 65];
            uint   outputSize          = (uint)serializedPublicKey.Length;
            uint   flags = compressed ? Secp256K1EcCompressed : Secp256K1EcUncompressed;

            byte[] recoverableSignature = new byte[65];
            if (IsWindows
                ? !Win64Lib.secp256k1_ecdsa_recoverable_signature_parse_compact(Context, recoverableSignature, compactSignature, recoveryId)
                : !PosixLib.secp256k1_ecdsa_recoverable_signature_parse_compact(Context, recoverableSignature, compactSignature, recoveryId))
            {
                return(null);
            }

            if (IsWindows
                ? !Win64Lib.secp256k1_ecdsa_recover(Context, publicKey, recoverableSignature, messageHash)
                : !PosixLib.secp256k1_ecdsa_recover(Context, publicKey, recoverableSignature, messageHash))
            {
                return(null);
            }

            if (IsWindows
                ? !Win64Lib.secp256k1_ec_pubkey_serialize(Context, serializedPublicKey, ref outputSize, publicKey, flags)
                : !PosixLib.secp256k1_ec_pubkey_serialize(Context, serializedPublicKey, ref outputSize, publicKey, flags))
            {
                return(null);
            }

            return(serializedPublicKey);
        }