public void Test_External_Signature() { // using old chain id /* * message is raw hash of eth transaction with following parameters * const txParams = { * nonce: '0x00', * gasPrice: '0x09184e72a000', * gasLimit: '0x27100000', * value: '0x00', * data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057', * }; * EIP-155 encoding used, with chain id = 25 * Signature created from private key: 0xd95d6db65f3e2223703c5d8e205d98e3e6b470f067b0f94f6c6bf73d4301ce48 * Address: 0x6Bc32575ACb8754886dC283c2c8ac54B1Bd93195 * RLP: 0xf7808609184e72a00084271000008080a47f7465737432000000000000000000000000000000000000000000000000000000600057198080 * Check here: https://toolkit.abdk.consulting/ethereum#transaction */ var rlp = "0xf7808609184e72a00084271000008080a47f7465737432000000000000000000000000000000000000000000000000000000600057198080" .HexToBytes(); var message = rlp.Keccak().ToBytes(); // check the signature with python script var signature = "0xCC3D45ADFC4570ABA45FE873D17741434310F178B7AB406C11A2CD4E6AF8DCB727A3F460B3B7601425CFAEB7B89E734F637509F4691A5553547F638DBEB17BBB56" .HexToBytes(); var pubKey = Crypto.RecoverSignatureHashed(message, signature, false); Assert.AreEqual( "0x6Bc32575ACb8754886dC283c2c8ac54B1Bd93195".ToLower(), Crypto.ComputeAddress(pubKey).ToHex().ToLower() ); // using new chain id /* * message is raw hash of eth transaction with following parameters * const txParams = { * nonce: '0x00', * gasPrice: '0x09184e72a000', * gasLimit: '0x27100000', * value: '0x00', * data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057', * }; * EIP-155 encoding used, with chain id = 225 * Signature created from private key: 0xd95d6db65f3e2223703c5d8e205d98e3e6b470f067b0f94f6c6bf73d4301ce48 * Address: 0x6Bc32575ACb8754886dC283c2c8ac54B1Bd93195 * RLP: 0xf838808609184e72a00084271000008080a47f746573743200000000000000000000000000000000000000000000000000000060005781e18080 * Check here: https://toolkit.abdk.consulting/ethereum#transaction */ rlp = "0xf838808609184e72a00084271000008080a47f746573743200000000000000000000000000000000000000000000000000000060005781e18080" .HexToBytes(); message = rlp.Keccak().ToBytes(); // check the signature with python script signature = "0x3BBFC886AD74E518C99D59966B5B4B656D3ED03B71FACD9384A82D08C8ED825B170B6E685A3E15FA9969D729B6C036ED3E5C3926B6FC424708F8F7DE0728003401E6" .HexToBytes(); pubKey = Crypto.RecoverSignatureHashed(message, signature, true); Assert.AreEqual( "0x6Bc32575ACb8754886dC283c2c8ac54B1Bd93195".ToLower(), Crypto.ComputeAddress(pubKey).ToHex().ToLower() ); }
public static ECDSAPublicKey RecoverPublicKey(this TransactionReceipt receipt, bool useNewChainId) { return(Crypto .RecoverSignatureHashed(receipt.Transaction.RawHash(useNewChainId).ToBytes(), receipt.Signature.Encode(), useNewChainId) .ToPublicKey()); }