diff --git a/TODO b/TODO new file mode 100644 index 0000000..ff18e15 --- /dev/null +++ b/TODO @@ -0,0 +1,53 @@ +- hexate encode all values +- transaction tests +- maybe implement verify signature +- get_sender_address +- get_sender_public_key +- maybe pad/unpad functions +- maybe from unsigned / to signed +- check ethUtils.hashPersonalMessage +- check toChecksumAddress + isValidChecksumAddress +- fromRPCtoSig, toRPCSig + +function intToHex (i) { + var hex = i.toString(16) + if (hex.length % 2) { + hex = '0' + hex + } + + return hex +} + + +describe('message sig', function () { + const r = Buffer.from('99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9', 'hex') + const s = Buffer.from('129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66', 'hex') + + it('should return hex strings that the RPC can use', function () { + assert.equal(ethUtils.toRpcSig(27, r, s), '0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca6600') + assert.deepEqual(ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca6600'), { + v: 27, + r: r, + s: s + }) + }) + + it('should throw on invalid length', function () { + assert.throws(function () { + ethUtils.fromRpcSig('') + }) + assert.throws(function () { + ethUtils.fromRpcSig('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca660042') + }) + }) + + it('pad short r and s values', function () { + assert.equal(ethUtils.toRpcSig(27, r.slice(20), s.slice(20)), '0x00000000000000000000000000000000000000004a1579cf389ef88b20a1abe90000000000000000000000000000000000000000326fa689f228040429e3ca6600') + }) + + it('should throw on invalid v value', function () { + assert.throws(function () { + ethUtils.toRpcSig(1, r, s) + }) + }) +}) diff --git a/test/fixtures/eip155_vitalik_tests.json b/test/fixtures/eip155_vitalik_tests.json new file mode 100644 index 0000000..7699a7b --- /dev/null +++ b/test/fixtures/eip155_vitalik_tests.json @@ -0,0 +1,189 @@ +[ + { + "blocknumber" : "3500000", + "hash" : "e0be81f8d506dbe3a5549e720b51eb79492378d6638087740824f168667e5239", + "rlp" : "0xf864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", + "sender" : "f0f6f18bca1b28cd68e4357452947e021241e9ce", + "transaction" : { + "data" : "", + "gasLimit" : "0x5208", + "gasPrice" : "0x04a817c800", + "nonce" : "0x00", + "r" : "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", + "s" : "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x00" + } + }, + { + "blocknumber" : "3500000", + "hash" : "50b6e7b58320c885ab7b2ee0d0b5813a697268bd2494a06de792790b13668c08", + "rlp" : "0xf867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", + "sender" : "9bddad43f934d313c2b79ca28a432dd2b7281029", + "transaction" : { + "data" : "", + "gasLimit" : "0x02e248", + "gasPrice" : "0x04a817c808", + "nonce" : "0x08", + "r" : "0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12", + "s" : "0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x0200" + } + }, + { + "blocknumber" : "3500000", + "hash" : "24fd18c70146a2b002254810473fa26b744f7899258a1f32924cc73e7a8f4d4f", + "rlp" : "0xf867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", + "sender" : "3c24d7329e92f84f08556ceb6df1cdb0104ca49f", + "transaction" : { + "data" : "", + "gasLimit" : "0x033450", + "gasPrice" : "0x04a817c809", + "nonce" : "0x09", + "r" : "0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", + "s" : "0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x02d9" + } + }, + { + "blocknumber" : "3500000", + "hash" : "42973b488dbb3aa237db3d1a3bad18a8d2148af795fb6cdbbbeef5c736df97b9", + "rlp" : "0xf864018504a817c80182a410943535353535353535353535353535353535353535018025a0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bcaa0489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6", + "sender" : "23ef145a395ea3fa3deb533b8a9e1b4c6c25d112", + "transaction" : { + "data" : "", + "gasLimit" : "0xa410", + "gasPrice" : "0x04a817c801", + "nonce" : "0x01", + "r" : "0x489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bca", + "s" : "0x489efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x01" + } + }, + { + "blocknumber" : "3500000", + "hash" : "e68afed5d359c7e60a0408093da23c57b63e84acb2e368ac7c47630518d6f4d9", + "rlp" : "0xf864028504a817c80282f618943535353535353535353535353535353535353535088025a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5a02d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", + "sender" : "2e485e0c23b4c3c542628a5f672eeab0ad4888be", + "transaction" : { + "data" : "", + "gasLimit" : "0xf618", + "gasPrice" : "0x04a817c802", + "nonce" : "0x02", + "r" : "0x2d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", + "s" : "0x2d7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x08" + } + }, + { + "blocknumber" : "3500000", + "hash" : "bcb6f653e06c276a080e9d68e5a967847a896cf52a6dc81917dc2c57ae0a31ef", + "rlp" : "0xf865038504a817c803830148209435353535353535353535353535353535353535351b8025a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4e0a02a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4de", + "sender" : "82a88539669a3fd524d669e858935de5e5410cf0", + "transaction" : { + "data" : "", + "gasLimit" : "0x014820", + "gasPrice" : "0x04a817c803", + "nonce" : "0x03", + "r" : "0x2a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4e0", + "s" : "0x2a80e1ef1d7842f27f2e6be0972bb708b9a135c38860dbe73c27c3486c34f4de", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x1b" + } + }, + { + "blocknumber" : "3500000", + "hash" : "244e4b57522352c3e9f93ad8ac8a47d1b46c3dcda6da2522caedad009ac9afb7", + "rlp" : "0xf865048504a817c80483019a28943535353535353535353535353535353535353535408025a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c063a013600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c060", + "sender" : "f9358f2538fd5ccfeb848b64a96b743fcc930554", + "transaction" : { + "data" : "", + "gasLimit" : "0x019a28", + "gasPrice" : "0x04a817c804", + "nonce" : "0x04", + "r" : "0x13600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c063", + "s" : "0x13600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c060", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x40" + } + }, + { + "blocknumber" : "3500000", + "hash" : "581c0b79498b1cf1b8fa4f69bc5f21c0c60371cd08d4682b15c4334aac1cccfd", + "rlp" : "0xf865058504a817c8058301ec309435353535353535353535353535353535353535357d8025a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", + "sender" : "a8f7aba377317440bc5b26198a363ad22af1f3a4", + "transaction" : { + "data" : "", + "gasLimit" : "0x01ec30", + "gasPrice" : "0x04a817c805", + "nonce" : "0x05", + "r" : "0x4eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", + "s" : "0x4eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x7d" + } + }, + { + "blocknumber" : "3500000", + "hash" : "581c0b79498b1cf1b8fa4f69bc5f21c0c60371cd08d4682b15c4334aac1cccfd", + "rlp" : "0xf865058504a817c8058301ec309435353535353535353535353535353535353535357d8025a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1a04eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", + "sender" : "a8f7aba377317440bc5b26198a363ad22af1f3a4", + "transaction" : { + "data" : "", + "gasLimit" : "0x01ec30", + "gasPrice" : "0x04a817c805", + "nonce" : "0x05", + "r" : "0x4eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", + "s" : "0x4eebf77a833b30520287ddd9478ff51abbdffa30aa90a8d655dba0e8a79ce0c1", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x7d" + } + }, + { + "blocknumber" : "3500000", + "hash" : "678ae2053a840f5fe550a63d724d1c85420d2955a0ccc4f868dd59e27afdf279", + "rlp" : "0xf866068504a817c80683023e3894353535353535353535353535353535353535353581d88025a06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2fa06455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2d", + "sender" : "f1f571dc362a0e5b2696b8e775f8491d3e50de35", + "transaction" : { + "data" : "", + "gasLimit" : "0x023e38", + "gasPrice" : "0x04a817c806", + "nonce" : "0x06", + "r" : "0x6455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2f", + "s" : "0x6455bf8ea6e7463a1046a0b52804526e119b4bf5136279614e0b1e8e296a4e2d", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0xd8" + } + }, + { + "blocknumber" : "3500000", + "hash" : "81aa03ada1474ff3ca4b86afb8e8c0f8b22791e156e706231a695ef8c51515ab", + "rlp" : "0xf867078504a817c807830290409435353535353535353535353535353535353535358201578025a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021a052f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", + "sender" : "d37922162ab7cea97c97a87551ed02c9a38b7332", + "transaction" : { + "data" : "", + "gasLimit" : "0x029040", + "gasPrice" : "0x04a817c807", + "nonce" : "0x07", + "r" : "0x52f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", + "s" : "0x52f1a9b320cab38e5da8a8f97989383aab0a49165fc91c737310e4f7e9821021", + "to" : "0x3535353535353535353535353535353535353535", + "v" : "0x25", + "value" : "0x0157" + } + } +] diff --git a/test/fixtures/transactions.json b/test/fixtures/transactions.json new file mode 100644 index 0000000..feb159b --- /dev/null +++ b/test/fixtures/transactions.json @@ -0,0 +1,61 @@ +[{ + "privateKey": "164122e5d39e9814ca723a749253663bafb07f6af91704d9754c361eb315f0c1", + "sendersAddress": "1f36f546477cda21bf2296c50976f2740247906f", + "type": "contract", + "cost": 680, + "raw": [ + "0x", + "0x09184e72a000", + "0x2710", + "0x0000000000000000000000000000000000000000", + "0x", + "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", + "0x1c", + "0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab", + "0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13" + ] +}, { + "privateKey": "e0a462586887362a18a318b128dbc1e3a0cae6d4b0739f5d0419ec25114bc722", + "sendersAddress": "d13d825eb15c87b247c4c26331d66f225a5f632e", + "type": "message", + "cost": 500, + "raw": [ + "0x06", + "0x09184e72a000", + "0x01f4", + "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", + "0x016345785d8a0000", + "0x", + "0x1c", + "0x24a484bfa7380860e9fa0a9f5e4b64b985e860ca31abd36e66583f9030c2e29d", + "0x4d5ef07d9e73fa2fbfdad059591b4f13d0aa79e7634a2bb00174c9200cabb04d" + ] +}, { + "privateKey": "164122e5d39e9814ca723a749253663bafb07f6af91704d9754c361eb315f0c1", + "sendersAddress": "1f36f546477cda21bf2296c50976f2740247906f", + "type": "message", + "cost": 2420, + "raw": [ + "0x06", + "0x09184e72a000", + "0x0974", + "0xbe862ad9abfe6f22bcb087716c7d89a26051f74c", + "0x016345785d8a0000", + "0x00000000000000000000000000000000000000000000000000000000000000ad000000000000000000000000000000000000000000000000000000000000fafa0000000000000000000000000000000000000000000000000000000000000dfa0000000000000000000000000000000000000000000000000000000000000dfa00000000000000000000000000000000000000000000000000000000000000ad000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000df000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000df000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000d", + "0x1c", + "0x5e9361ca27e14f3af0e6b28466406ad8be026d3b0f2ae56e3c064043fb73ec77", + "0x29ae9893dac4f9afb1af743e25fbb6a63f7879a61437203cb48c997b0fcefc3a" + ] +}, { + "raw": [ + "0x0b", + "0x051f4d5c00", + "0x5208", + "0x656e929d6fc0cac52d3d9526d288fe02dcd56fbd", + "0x2386f26fc10000", + "0x", + "0x26", + "0xef903f6bbcb7d6214d478df27db6591d857b1063954eade1bb24e69e58511f96", + "0x5433f8e1abf886cbec64891f38a2ea6fd9f9ffe078421f5e238b9fec03eea97a" + ] +}]