ethereumjs-tx
Advanced tools
Comparing version 0.6.12 to 0.6.14
@@ -1,1 +0,1 @@ | ||
{"/home/null/code/ethereumjs-tx/index.js":{"path":"/home/null/code/ethereumjs-tx/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":125,"10":125,"11":0,"12":0,"13":0,"14":0,"15":0,"16":125,"17":1,"18":0,"19":1,"20":48,"21":48,"22":0,"23":48,"24":0,"25":48,"26":48,"27":1,"28":23,"29":23,"30":23,"31":1,"32":23,"33":0,"34":23,"35":1,"36":48,"37":48,"38":48,"39":48,"40":15,"41":33,"42":0,"43":33,"44":0,"45":0,"46":0,"47":33,"48":33,"49":1,"50":0,"51":0,"52":0,"53":0,"54":0,"55":1,"56":33,"57":33,"58":33,"59":10486347,"60":165,"61":10486182,"62":33,"63":1,"64":33,"65":1,"66":0,"67":1,"68":48},"b":{"1":[0,0],"2":[0,48],"3":[0,48],"4":[0,23],"5":[23,23],"6":[0,33],"7":[0,33],"8":[0,0],"9":[165,10486182],"10":[48,33]},"f":{"1":125,"2":0,"3":0,"4":0,"5":48,"6":23,"7":23,"8":48,"9":0,"10":33,"11":33,"12":0,"13":48},"fnMap":{"1":{"name":"(anonymous_1)","line":16,"loc":{"start":{"line":16,"column":35},"end":{"line":16,"column":51}}},"2":{"name":"(anonymous_2)","line":66,"loc":{"start":{"line":66,"column":9},"end":{"line":66,"column":21}}},"3":{"name":"(anonymous_3)","line":73,"loc":{"start":{"line":73,"column":9},"end":{"line":73,"column":22}}},"4":{"name":"(anonymous_4)","line":86,"loc":{"start":{"line":86,"column":34},"end":{"line":86,"column":46}}},"5":{"name":"(anonymous_5)","line":96,"loc":{"start":{"line":96,"column":29},"end":{"line":96,"column":50}}},"6":{"name":"(anonymous_6)","line":118,"loc":{"start":{"line":118,"column":41},"end":{"line":118,"column":53}}},"7":{"name":"(anonymous_7)","line":129,"loc":{"start":{"line":129,"column":43},"end":{"line":129,"column":55}}},"8":{"name":"(anonymous_8)","line":141,"loc":{"start":{"line":141,"column":40},"end":{"line":141,"column":52}}},"9":{"name":"(anonymous_9)","line":175,"loc":{"start":{"line":175,"column":29},"end":{"line":175,"column":51}}},"10":{"name":"(anonymous_10)","line":188,"loc":{"start":{"line":188,"column":35},"end":{"line":188,"column":47}}},"11":{"name":"(anonymous_11)","line":206,"loc":{"start":{"line":206,"column":35},"end":{"line":206,"column":47}}},"12":{"name":"(anonymous_12)","line":215,"loc":{"start":{"line":215,"column":39},"end":{"line":215,"column":51}}},"13":{"name":"(anonymous_13)","line":226,"loc":{"start":{"line":226,"column":33},"end":{"line":226,"column":45}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":42}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":39}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":34}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":21}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":23}},"6":{"start":{"line":8,"column":0},"end":{"line":8,"column":22}},"7":{"start":{"line":9,"column":0},"end":{"line":9,"column":24}},"8":{"start":{"line":16,"column":0},"end":{"line":79,"column":1}},"9":{"start":{"line":18,"column":2},"end":{"line":61,"column":4}},"10":{"start":{"line":63,"column":2},"end":{"line":76,"column":4}},"11":{"start":{"line":67,"column":6},"end":{"line":69,"column":7}},"12":{"start":{"line":68,"column":8},"end":{"line":68,"column":25}},"13":{"start":{"line":70,"column":6},"end":{"line":70,"column":42}},"14":{"start":{"line":71,"column":6},"end":{"line":71,"column":23}},"15":{"start":{"line":74,"column":6},"end":{"line":74,"column":20}},"16":{"start":{"line":78,"column":2},"end":{"line":78,"column":46}},"17":{"start":{"line":86,"column":0},"end":{"line":88,"column":1}},"18":{"start":{"line":87,"column":2},"end":{"line":87,"column":29}},"19":{"start":{"line":96,"column":0},"end":{"line":111,"column":1}},"20":{"start":{"line":97,"column":2},"end":{"line":97,"column":12}},"21":{"start":{"line":99,"column":2},"end":{"line":101,"column":3}},"22":{"start":{"line":100,"column":4},"end":{"line":100,"column":20}},"23":{"start":{"line":103,"column":2},"end":{"line":107,"column":3}},"24":{"start":{"line":104,"column":4},"end":{"line":104,"column":21}},"25":{"start":{"line":106,"column":4},"end":{"line":106,"column":33}},"26":{"start":{"line":110,"column":2},"end":{"line":110,"column":41}},"27":{"start":{"line":118,"column":0},"end":{"line":122,"column":1}},"28":{"start":{"line":119,"column":2},"end":{"line":119,"column":40}},"29":{"start":{"line":120,"column":2},"end":{"line":120,"column":48}},"30":{"start":{"line":121,"column":2},"end":{"line":121,"column":37}},"31":{"start":{"line":129,"column":0},"end":{"line":135,"column":1}},"32":{"start":{"line":130,"column":2},"end":{"line":132,"column":3}},"33":{"start":{"line":131,"column":4},"end":{"line":131,"column":26}},"34":{"start":{"line":134,"column":2},"end":{"line":134,"column":27}},"35":{"start":{"line":141,"column":0},"end":{"line":169,"column":1}},"36":{"start":{"line":142,"column":2},"end":{"line":142,"column":32}},"37":{"start":{"line":143,"column":2},"end":{"line":146,"column":3}},"38":{"start":{"line":148,"column":2},"end":{"line":152,"column":3}},"39":{"start":{"line":149,"column":4},"end":{"line":149,"column":80}},"40":{"start":{"line":151,"column":4},"end":{"line":151,"column":16}},"41":{"start":{"line":154,"column":2},"end":{"line":156,"column":3}},"42":{"start":{"line":155,"column":4},"end":{"line":155,"column":16}},"43":{"start":{"line":159,"column":2},"end":{"line":166,"column":3}},"44":{"start":{"line":160,"column":4},"end":{"line":160,"column":77}},"45":{"start":{"line":161,"column":4},"end":{"line":163,"column":5}},"46":{"start":{"line":162,"column":6},"end":{"line":162,"column":31}},"47":{"start":{"line":165,"column":4},"end":{"line":165,"column":33}},"48":{"start":{"line":168,"column":2},"end":{"line":168,"column":15}},"49":{"start":{"line":175,"column":0},"end":{"line":182,"column":1}},"50":{"start":{"line":176,"column":2},"end":{"line":176,"column":32}},"51":{"start":{"line":177,"column":2},"end":{"line":177,"column":47}},"52":{"start":{"line":179,"column":2},"end":{"line":179,"column":37}},"53":{"start":{"line":180,"column":2},"end":{"line":180,"column":38}},"54":{"start":{"line":181,"column":2},"end":{"line":181,"column":28}},"55":{"start":{"line":188,"column":0},"end":{"line":199,"column":1}},"56":{"start":{"line":189,"column":2},"end":{"line":189,"column":26}},"57":{"start":{"line":190,"column":2},"end":{"line":190,"column":22}},"58":{"start":{"line":191,"column":2},"end":{"line":197,"column":3}},"59":{"start":{"line":192,"column":4},"end":{"line":196,"column":5}},"60":{"start":{"line":193,"column":6},"end":{"line":193,"column":38}},"61":{"start":{"line":195,"column":6},"end":{"line":195,"column":41}},"62":{"start":{"line":198,"column":2},"end":{"line":198,"column":13}},"63":{"start":{"line":206,"column":0},"end":{"line":208,"column":1}},"64":{"start":{"line":207,"column":2},"end":{"line":207,"column":45}},"65":{"start":{"line":215,"column":0},"end":{"line":219,"column":1}},"66":{"start":{"line":216,"column":2},"end":{"line":218,"column":28}},"67":{"start":{"line":226,"column":0},"end":{"line":228,"column":1}},"68":{"start":{"line":227,"column":2},"end":{"line":227,"column":111}}},"branchMap":{"1":{"line":67,"type":"if","locations":[{"start":{"line":67,"column":6},"end":{"line":67,"column":6}},{"start":{"line":67,"column":6},"end":{"line":67,"column":6}}]},"2":{"line":99,"type":"if","locations":[{"start":{"line":99,"column":2},"end":{"line":99,"column":2}},{"start":{"line":99,"column":2},"end":{"line":99,"column":2}}]},"3":{"line":103,"type":"if","locations":[{"start":{"line":103,"column":2},"end":{"line":103,"column":2}},{"start":{"line":103,"column":2},"end":{"line":103,"column":2}}]},"4":{"line":130,"type":"if","locations":[{"start":{"line":130,"column":2},"end":{"line":130,"column":2}},{"start":{"line":130,"column":2},"end":{"line":130,"column":2}}]},"5":{"line":130,"type":"binary-expr","locations":[{"start":{"line":130,"column":6},"end":{"line":130,"column":25}},{"start":{"line":130,"column":29},"end":{"line":130,"column":55}}]},"6":{"line":154,"type":"if","locations":[{"start":{"line":154,"column":2},"end":{"line":154,"column":2}},{"start":{"line":154,"column":2},"end":{"line":154,"column":2}}]},"7":{"line":159,"type":"if","locations":[{"start":{"line":159,"column":2},"end":{"line":159,"column":2}},{"start":{"line":159,"column":2},"end":{"line":159,"column":2}}]},"8":{"line":161,"type":"if","locations":[{"start":{"line":161,"column":4},"end":{"line":161,"column":4}},{"start":{"line":161,"column":4},"end":{"line":161,"column":4}}]},"9":{"line":192,"type":"if","locations":[{"start":{"line":192,"column":4},"end":{"line":192,"column":4}},{"start":{"line":192,"column":4},"end":{"line":192,"column":4}}]},"10":{"line":227,"type":"binary-expr","locations":[{"start":{"line":227,"column":9},"end":{"line":227,"column":31}},{"start":{"line":227,"column":36},"end":{"line":227,"column":110}}]}}}} | ||
{"/home/null/code/ethereumjs-tx/index.js":{"path":"/home/null/code/ethereumjs-tx/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":132,"10":132,"11":0,"12":0,"13":0,"14":0,"15":0,"16":132,"17":1,"18":5,"19":1,"20":67,"21":67,"22":0,"23":67,"24":0,"25":67,"26":67,"27":1,"28":26,"29":26,"30":26,"31":1,"32":26,"33":0,"34":26,"35":1,"36":64,"37":64,"38":64,"39":64,"40":21,"41":43,"42":0,"43":43,"44":0,"45":0,"46":0,"47":43,"48":43,"49":1,"50":3,"51":3,"52":3,"53":3,"54":3,"55":1,"56":37,"57":37,"58":37,"59":10486351,"60":167,"61":10486184,"62":37,"63":1,"64":37,"65":1,"66":0,"67":1,"68":55},"b":{"1":[0,0],"2":[0,67],"3":[0,67],"4":[0,26],"5":[26,26],"6":[0,43],"7":[0,43],"8":[0,0],"9":[167,10486184],"10":[55,37]},"f":{"1":132,"2":0,"3":0,"4":5,"5":67,"6":26,"7":26,"8":64,"9":3,"10":37,"11":37,"12":0,"13":55},"fnMap":{"1":{"name":"(anonymous_1)","line":16,"loc":{"start":{"line":16,"column":35},"end":{"line":16,"column":51}}},"2":{"name":"(anonymous_2)","line":66,"loc":{"start":{"line":66,"column":9},"end":{"line":66,"column":21}}},"3":{"name":"(anonymous_3)","line":73,"loc":{"start":{"line":73,"column":9},"end":{"line":73,"column":22}}},"4":{"name":"(anonymous_4)","line":86,"loc":{"start":{"line":86,"column":34},"end":{"line":86,"column":46}}},"5":{"name":"(anonymous_5)","line":96,"loc":{"start":{"line":96,"column":29},"end":{"line":96,"column":50}}},"6":{"name":"(anonymous_6)","line":118,"loc":{"start":{"line":118,"column":41},"end":{"line":118,"column":53}}},"7":{"name":"(anonymous_7)","line":129,"loc":{"start":{"line":129,"column":43},"end":{"line":129,"column":55}}},"8":{"name":"(anonymous_8)","line":141,"loc":{"start":{"line":141,"column":40},"end":{"line":141,"column":52}}},"9":{"name":"(anonymous_9)","line":175,"loc":{"start":{"line":175,"column":29},"end":{"line":175,"column":51}}},"10":{"name":"(anonymous_10)","line":188,"loc":{"start":{"line":188,"column":35},"end":{"line":188,"column":47}}},"11":{"name":"(anonymous_11)","line":206,"loc":{"start":{"line":206,"column":35},"end":{"line":206,"column":47}}},"12":{"name":"(anonymous_12)","line":215,"loc":{"start":{"line":215,"column":39},"end":{"line":215,"column":51}}},"13":{"name":"(anonymous_13)","line":226,"loc":{"start":{"line":226,"column":33},"end":{"line":226,"column":45}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":42}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":39}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":34}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":21}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":23}},"6":{"start":{"line":8,"column":0},"end":{"line":8,"column":22}},"7":{"start":{"line":9,"column":0},"end":{"line":9,"column":24}},"8":{"start":{"line":16,"column":0},"end":{"line":79,"column":1}},"9":{"start":{"line":18,"column":2},"end":{"line":61,"column":4}},"10":{"start":{"line":63,"column":2},"end":{"line":76,"column":4}},"11":{"start":{"line":67,"column":6},"end":{"line":69,"column":7}},"12":{"start":{"line":68,"column":8},"end":{"line":68,"column":25}},"13":{"start":{"line":70,"column":6},"end":{"line":70,"column":42}},"14":{"start":{"line":71,"column":6},"end":{"line":71,"column":23}},"15":{"start":{"line":74,"column":6},"end":{"line":74,"column":20}},"16":{"start":{"line":78,"column":2},"end":{"line":78,"column":46}},"17":{"start":{"line":86,"column":0},"end":{"line":88,"column":1}},"18":{"start":{"line":87,"column":2},"end":{"line":87,"column":29}},"19":{"start":{"line":96,"column":0},"end":{"line":111,"column":1}},"20":{"start":{"line":97,"column":2},"end":{"line":97,"column":12}},"21":{"start":{"line":99,"column":2},"end":{"line":101,"column":3}},"22":{"start":{"line":100,"column":4},"end":{"line":100,"column":20}},"23":{"start":{"line":103,"column":2},"end":{"line":107,"column":3}},"24":{"start":{"line":104,"column":4},"end":{"line":104,"column":21}},"25":{"start":{"line":106,"column":4},"end":{"line":106,"column":33}},"26":{"start":{"line":110,"column":2},"end":{"line":110,"column":41}},"27":{"start":{"line":118,"column":0},"end":{"line":122,"column":1}},"28":{"start":{"line":119,"column":2},"end":{"line":119,"column":40}},"29":{"start":{"line":120,"column":2},"end":{"line":120,"column":48}},"30":{"start":{"line":121,"column":2},"end":{"line":121,"column":37}},"31":{"start":{"line":129,"column":0},"end":{"line":135,"column":1}},"32":{"start":{"line":130,"column":2},"end":{"line":132,"column":3}},"33":{"start":{"line":131,"column":4},"end":{"line":131,"column":26}},"34":{"start":{"line":134,"column":2},"end":{"line":134,"column":27}},"35":{"start":{"line":141,"column":0},"end":{"line":169,"column":1}},"36":{"start":{"line":142,"column":2},"end":{"line":142,"column":32}},"37":{"start":{"line":143,"column":2},"end":{"line":146,"column":3}},"38":{"start":{"line":148,"column":2},"end":{"line":152,"column":3}},"39":{"start":{"line":149,"column":4},"end":{"line":149,"column":80}},"40":{"start":{"line":151,"column":4},"end":{"line":151,"column":16}},"41":{"start":{"line":154,"column":2},"end":{"line":156,"column":3}},"42":{"start":{"line":155,"column":4},"end":{"line":155,"column":16}},"43":{"start":{"line":159,"column":2},"end":{"line":166,"column":3}},"44":{"start":{"line":160,"column":4},"end":{"line":160,"column":77}},"45":{"start":{"line":161,"column":4},"end":{"line":163,"column":5}},"46":{"start":{"line":162,"column":6},"end":{"line":162,"column":31}},"47":{"start":{"line":165,"column":4},"end":{"line":165,"column":33}},"48":{"start":{"line":168,"column":2},"end":{"line":168,"column":15}},"49":{"start":{"line":175,"column":0},"end":{"line":182,"column":1}},"50":{"start":{"line":176,"column":2},"end":{"line":176,"column":32}},"51":{"start":{"line":177,"column":2},"end":{"line":177,"column":47}},"52":{"start":{"line":179,"column":2},"end":{"line":179,"column":37}},"53":{"start":{"line":180,"column":2},"end":{"line":180,"column":38}},"54":{"start":{"line":181,"column":2},"end":{"line":181,"column":28}},"55":{"start":{"line":188,"column":0},"end":{"line":199,"column":1}},"56":{"start":{"line":189,"column":2},"end":{"line":189,"column":26}},"57":{"start":{"line":190,"column":2},"end":{"line":190,"column":22}},"58":{"start":{"line":191,"column":2},"end":{"line":197,"column":3}},"59":{"start":{"line":192,"column":4},"end":{"line":196,"column":5}},"60":{"start":{"line":193,"column":6},"end":{"line":193,"column":38}},"61":{"start":{"line":195,"column":6},"end":{"line":195,"column":41}},"62":{"start":{"line":198,"column":2},"end":{"line":198,"column":13}},"63":{"start":{"line":206,"column":0},"end":{"line":208,"column":1}},"64":{"start":{"line":207,"column":2},"end":{"line":207,"column":45}},"65":{"start":{"line":215,"column":0},"end":{"line":219,"column":1}},"66":{"start":{"line":216,"column":2},"end":{"line":218,"column":28}},"67":{"start":{"line":226,"column":0},"end":{"line":228,"column":1}},"68":{"start":{"line":227,"column":2},"end":{"line":227,"column":111}}},"branchMap":{"1":{"line":67,"type":"if","locations":[{"start":{"line":67,"column":6},"end":{"line":67,"column":6}},{"start":{"line":67,"column":6},"end":{"line":67,"column":6}}]},"2":{"line":99,"type":"if","locations":[{"start":{"line":99,"column":2},"end":{"line":99,"column":2}},{"start":{"line":99,"column":2},"end":{"line":99,"column":2}}]},"3":{"line":103,"type":"if","locations":[{"start":{"line":103,"column":2},"end":{"line":103,"column":2}},{"start":{"line":103,"column":2},"end":{"line":103,"column":2}}]},"4":{"line":130,"type":"if","locations":[{"start":{"line":130,"column":2},"end":{"line":130,"column":2}},{"start":{"line":130,"column":2},"end":{"line":130,"column":2}}]},"5":{"line":130,"type":"binary-expr","locations":[{"start":{"line":130,"column":6},"end":{"line":130,"column":25}},{"start":{"line":130,"column":29},"end":{"line":130,"column":55}}]},"6":{"line":154,"type":"if","locations":[{"start":{"line":154,"column":2},"end":{"line":154,"column":2}},{"start":{"line":154,"column":2},"end":{"line":154,"column":2}}]},"7":{"line":159,"type":"if","locations":[{"start":{"line":159,"column":2},"end":{"line":159,"column":2}},{"start":{"line":159,"column":2},"end":{"line":159,"column":2}}]},"8":{"line":161,"type":"if","locations":[{"start":{"line":161,"column":4},"end":{"line":161,"column":4}},{"start":{"line":161,"column":4},"end":{"line":161,"column":4}}]},"9":{"line":192,"type":"if","locations":[{"start":{"line":192,"column":4},"end":{"line":192,"column":4}},{"start":{"line":192,"column":4},"end":{"line":192,"column":4}}]},"10":{"line":227,"type":"binary-expr","locations":[{"start":{"line":227,"column":9},"end":{"line":227,"column":31}},{"start":{"line":227,"column":36},"end":{"line":227,"column":110}}]}}}} |
90
index.js
@@ -7,2 +7,5 @@ const ethUtil = require('ethereumjs-util') | ||
// secp256k1n/2 | ||
const N_DIV_2 = new BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16) | ||
// give browser access to Buffers | ||
@@ -13,5 +16,29 @@ global.Buffer = Buffer | ||
/** | ||
* Represents a transaction | ||
* Creates a new transaction object | ||
* @constructor | ||
* @param {Buffer|Array} data raw data, deserialized | ||
* @class {Buffer|Array} data a transaction can be initiailized with either a buffer containing the RLP serialized transaction or an array of buffers relating to each of the tx Properties, listed in order below in the exmple. Or lastly an Object containing the Properties of the transaction like in the Usage example | ||
* | ||
* For Object and Arrays each of the elements can either be a Buffer, a hex-prefixed (0x) String , Number, or an object with a toBuffer method such as Bignum | ||
* @example | ||
* var rawTx = { | ||
* nonce: '00', | ||
* gasPrice: '09184e72a000', | ||
* gasLimit: '2710', | ||
* to: '0000000000000000000000000000000000000000', | ||
* value: '00', | ||
* data: '7f7465737432000000000000000000000000000000000000000000000000000000600057', | ||
* v: '1c', | ||
* r: '5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab', | ||
* s '5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13' | ||
* }; | ||
* var tx = new Transaction(rawTx); | ||
* @prop {Buffer} raw The raw rlp decoded transaction | ||
* @prop {Buffer} nonce | ||
* @prop {Buffer} to the to address | ||
* @prop {Buffer} value the amount of ether sent | ||
* @prop {Buffer} data this will contain the data of the message or the init of a contract | ||
* @prop {Buffer} v EC signature parameter | ||
* @prop {Buffer} r EC signature parameter | ||
* @prop {Buffer} s EC recovery ID | ||
* @prop {Buffer} from If you are not planing on signing the tx you can set the from property. If you do sign it will be over written | ||
*/ | ||
@@ -93,5 +120,5 @@ var Transaction = module.exports = function (data) { | ||
/** | ||
* Computes a sha3-256 hash of the tx | ||
* Computes a sha3-256 hash of the serialized tx | ||
* @method hash | ||
* @param {Boolean} [true] signature - whether or not to inculde the signature | ||
* @param {Boolean} [signature=true] whether or not to inculde the signature | ||
* @return {Buffer} | ||
@@ -106,14 +133,10 @@ */ | ||
if (signature) { | ||
toHash = this.raw | ||
} else { | ||
toHash = this.raw.slice(0, 6) | ||
} | ||
toHash = signature ? this.raw : this.raw.slice(0, 6) | ||
// create hash | ||
return ethUtil.sha3(rlp.encode(toHash)) | ||
return ethUtil.rlphash(toHash) | ||
} | ||
/** | ||
* gets the senders address | ||
* returns the sender`s address | ||
* @method getSenderAddress | ||
@@ -129,3 +152,3 @@ * @return {Buffer} | ||
/** | ||
* gets the senders public key | ||
* returns the public key of the sender | ||
* @method getSenderPublicKey | ||
@@ -143,2 +166,3 @@ * @return {Buffer} | ||
/** | ||
* Determines if the signature is valid | ||
* @method verifySignature | ||
@@ -149,9 +173,12 @@ * @return {Boolean} | ||
var msgHash = this.hash(false) | ||
var sig = { | ||
signature: Buffer.concat([ethUtil.pad(this.r, 32), ethUtil.pad(this.s, 32)], 64), | ||
recovery: ethUtil.bufferToInt(this.v) - 27 | ||
var signature = Buffer.concat([ethUtil.pad(this.r, 32), ethUtil.pad(this.s, 32)], 64) | ||
var recovery = ethUtil.bufferToInt(this.v) - 27 | ||
// All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid. | ||
if (!this._skipSValueCheck && new BN(this.s).cmp(N_DIV_2) === 1) { | ||
return false | ||
} | ||
try { | ||
this._senderPubKey = ecdsa.recoverSync(msgHash, sig.signature, sig.recovery) | ||
this._senderPubKey = ecdsa.recoverSync(msgHash, signature, recovery) | ||
} catch (e) { | ||
@@ -165,5 +192,12 @@ return false | ||
// hack to force elliptic to verify | ||
// | ||
// In node-secp256k1, `recover` will fail on invalid inputs, but in | ||
// elliptic this is not enforced. | ||
// | ||
// Here we enable a pubkey based verification only in the case | ||
// of browserified output, where elliptic will be used, to workaround the issue. | ||
// | ||
// TODO: fix elliptic? | ||
if (process.browser) { | ||
var result = ecdsa.verifySync(msgHash, sig.signature, this._senderPubKey) | ||
var result = ecdsa.verifySync(msgHash, signature, this._senderPubKey) | ||
if (!result) { | ||
@@ -194,3 +228,3 @@ this._senderPubKey = null | ||
* @method getDataFee | ||
* @return {bn.js} | ||
* @return {BN} | ||
*/ | ||
@@ -201,7 +235,3 @@ Transaction.prototype.getDataFee = function () { | ||
for (var i = 0; i < data.length; i++) { | ||
if (data[i] === 0) { | ||
cost.iaddn(fees.txDataZeroGas.v) | ||
} else { | ||
cost.iaddn(fees.txDataNonZeroGas.v) | ||
} | ||
data[i] === 0 ? cost.iaddn(fees.txDataZeroGas.v) : cost.iaddn(fees.txDataNonZeroGas.v) | ||
} | ||
@@ -212,8 +242,8 @@ return cost | ||
/** | ||
* the base amount of gas it takes to be a valid tx | ||
* the minimum amount of gas the tx must have (DataFee + TxFee) | ||
* @method getBaseFee | ||
* @return {bn.js} | ||
* @return {BN} | ||
*/ | ||
Transaction.prototype.getBaseFee = function () { | ||
return this.getDataFee().addn(fees.txGas.v) | ||
return this.getDataFee().iaddn(fees.txGas.v) | ||
} | ||
@@ -228,4 +258,4 @@ | ||
return new BN(this.gasLimit) | ||
.mul(new BN(this.gasPrice)) | ||
.add(new BN(this.value)) | ||
.imul(new BN(this.gasPrice)) | ||
.iadd(new BN(this.value)) | ||
} | ||
@@ -239,3 +269,3 @@ | ||
Transaction.prototype.validate = function () { | ||
return this.verifySignature() && (Number(this.getBaseFee().toString()) <= ethUtil.bufferToInt(this.gasLimit)) | ||
return this.verifySignature() && (this.getBaseFee().cmp(new BN(this.gasLimit)) <= 0) | ||
} |
@@ -0,6 +1,10 @@ | ||
process.env.ethTest = 'TransactionTests' | ||
module.exports = function (config) { | ||
config.set({ | ||
browserNoActivityTimeout: 60000, | ||
frameworks: ['browserify', 'detectBrowsers', 'tap'], | ||
files: [ | ||
'./test/transactions.js' | ||
'./test/api.js', | ||
'./test/transactionRunner.js' | ||
], | ||
@@ -19,5 +23,2 @@ preprocessors: { | ||
], | ||
browserify: { | ||
debug: true | ||
}, | ||
detectBrowsers: { | ||
@@ -24,0 +25,0 @@ enabled: true, |
{ | ||
"name": "ethereumjs-tx", | ||
"version": "0.6.12", | ||
"version": "0.6.14", | ||
"description": "An simple module for creating, manipulating and signing ethereum transactions", | ||
"main": "index.js", | ||
"scripts": { | ||
"coverage": "istanbul cover ./test/tester.js", | ||
"coverage": "istanbul cover ./test/index.js", | ||
"coveralls": "npm run coverage && coveralls <coverage/lcov.info", | ||
"lint": "standard", | ||
"prepublish": "npm run lint && npm run test && npm run build", | ||
"test": "npm run test:node && npm run test:browser", | ||
"test:browser": "karma start karma.conf.js", | ||
"test:node": "node ./test/tester -a", | ||
"build": "browserify --s EthTx index.js > ./dist/ethereumjs-tx.js" | ||
"test:node": "tape ./test/index.js", | ||
"build": "browserify --s EthTx index.js > ./dist/ethereumjs-tx.js", | ||
"build:docs": "documentation --github -f md ./index.js > ./docs/index.md" | ||
}, | ||
@@ -23,4 +23,4 @@ "keywords": [ | ||
"dependencies": { | ||
"ethereum-common": "0.0.10", | ||
"ethereumjs-util": "^2.3.2", | ||
"ethereum-common": "0.0.13", | ||
"ethereumjs-util": "^2.5.0", | ||
"secp256k1": "^2.0.7" | ||
@@ -32,3 +32,4 @@ }, | ||
"coveralls": "^2.11.4", | ||
"ethereumjs-testing": "git+https://github.com/wanderer/ethereumjs-testing.git", | ||
"documentation": "^3.0.4", | ||
"ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git", | ||
"istanbul": "^0.4.1", | ||
@@ -48,7 +49,8 @@ "karma": "^0.13.15", | ||
"type": "git", | ||
"url": "https://github.com/ethereum/ethereumjs-tx.git" | ||
"url": "https://github.com/ethereumjs/ethereumjs-tx.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/ethereum/ethereumjs-tx/issues" | ||
"url": "https://github.com/ethereumjs/ethereumjs-tx/issues" | ||
}, | ||
"homepage": "https://github.com/ethereumjs/ethereumjs-tx", | ||
"standard": { | ||
@@ -55,0 +57,0 @@ "ignore": [ |
130
README.md
# SYNOPSIS | ||
[![NPM Package](https://img.shields.io/npm/v/ethereumjs-tx.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-tx) | ||
[![Build Status](https://img.shields.io/travis/ethereum/ethereumjs-tx.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereum/ethereumjs-tx) | ||
[![Coverage Status](https://img.shields.io/coveralls/ethereum/ethereumjs-tx.svg?style=flat-square)](https://coveralls.io/r/ethereum/ethereumjs-tx) | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/ethereumjs-lib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) or #ethereumjs on freenode | ||
[![Build Status](https://img.shields.io/travis/ethereumjs/ethereumjs-tx.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereumjs/ethereumjs-tx) | ||
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-tx.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-tx) | ||
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode | ||
@@ -14,3 +14,3 @@ [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) | ||
- [example](https://github.com/ethereum/ethereumjs-tx/blob/master/examples/transactions.js) | ||
- [example](https://github.com/ethereumjs/ethereumjs-tx/blob/master/examples/transactions.js) | ||
@@ -43,125 +43,5 @@ ```javascript | ||
# API | ||
- [`new Transaction([data])`](#new-transactiondata) | ||
- [`Transaction` Properties](#transaction-properties) | ||
- [`Transaction` Methods](#transaction-methods) | ||
- [`transaction.serialize()`](#transactionserialize) | ||
- [`transaction.hash([signature])`](#transactionhashsignature) | ||
- [`transaction.sign(privateKey)`](#transactionsignprivatekey) | ||
- [`transaction.getSenderAddress()`](#transactiongetsenderaddress) | ||
- [`transaction.getSenderPublicKey()`](#transactiongetsenderpublickey) | ||
- [`transaction.validate()`](#transactionvalidate) | ||
- [`transaction.validateSignature()`](#transactionvalidatesignature) | ||
- [`transaction.getDataFee()`](#transactiongetdatafee) | ||
- [`transaction.getBaseFee()`](#transactiongetbasefee) | ||
- [`transaction.getUpfrontCost()`](#transactiongetupfrontcost) | ||
- [`transaction.toJSON([object])`](#transactiontojsonobject) | ||
[./docs/](./docs/index.md) | ||
### `new Transaction([data])` | ||
Creates a new transaction object | ||
- `data` - a transaction can be initiailized with either a `buffer` containing the RLP serialized transaction or an `array` of buffers relating to each of the tx Properties, listed in order below. For example. | ||
```javascript | ||
var rawTx = { | ||
nonce: '00', | ||
gasPrice: '09184e72a000', | ||
gasLimit: '2710', | ||
to: '0000000000000000000000000000000000000000', | ||
value: '00', | ||
data: '7f7465737432000000000000000000000000000000000000000000000000000000600057', | ||
v: '1c', | ||
r: '5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab', | ||
s '5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13' | ||
}; | ||
var tx = new Transaction(rawTx); | ||
``` | ||
Or lastly an `Object` containing the Properties of the transaction like in the [Usage](#usage) example | ||
For `Object` and `Arrays` each of the elements can either be a `Buffer`, a hex-prefixed (0x) `String` , `Number`, or an object with a `toBuffer` method such as `Bignum` | ||
### `transaction` Properties | ||
- `raw` - The raw rlp decoded transaction. | ||
- `nonce` | ||
- `to` - the to address | ||
- `value` - the amount of ether sent | ||
- `data` - this will contain the `data` of the message or the `init` of a contract. | ||
- `v` - EC signature parameter | ||
- `r` - EC signature parameter | ||
- `s` - EC recovery ID | ||
-------------------------------------------------------- | ||
### `Transaction` Methods | ||
#### `transaction.serialize()` | ||
Returns the RLP serialization of the transaction | ||
**Return:** 32 Byte `Buffer` | ||
-------------------------------------------------------- | ||
#### `transaction.hash([signature])` | ||
Returns the SHA3-256 hash of the rlp transaction | ||
**Parameters** | ||
- `signature` - a `Boolean` determining if to include the signature components of the transaction. Defaults to true. | ||
**Return:** 32 Byte `Buffer` | ||
-------------------------------------------------------- | ||
#### `transaction.sign(privateKey)` | ||
Signs the transaction with the given privateKey. | ||
**Parameters** | ||
- `privateKey` - a 32 Byte `Buffer` | ||
-------------------------------------------------------- | ||
#### `transaction.getSenderAddress()` | ||
Returns the senders address | ||
**Return:** 20 Byte `Buffer` | ||
-------------------------------------------------------- | ||
#### `transaction.getSenderPublicKey()` | ||
returns the public key of the sender | ||
**Return:** `Buffer` | ||
-------------------------------------------------------- | ||
#### `transaction.validate()` | ||
Determines if the transaction is schematicly valid by checking its signature and gasCost. | ||
**Return:** `Boolean` | ||
-------------------------------------------------------- | ||
#### `transaction.validateSignature()` | ||
Determines if the signature is valid | ||
**Return:** `Boolean` | ||
-------------------------------------------------------- | ||
#### `transaction.getDataFee()` | ||
Returns the amount of gas to be paid for the data in this transaction | ||
**Return:** `bn.js` | ||
-------------------------------------------------------- | ||
#### `transaction.getBaseFee()` | ||
Returns the minimum amount of gas the tx must have (DataFee + TxFee) | ||
**Return:** `bn.js` | ||
-------------------------------------------------------- | ||
#### `transaction.getUpfrontCost()` | ||
The total amount needed in the account of the sender for the transaction to be valid | ||
**Return:** `bn.js` | ||
-------------------------------------------------------- | ||
#### `transaction.toJSON([object])` | ||
Returns transaction as JSON | ||
**Parameters** | ||
- `object` - a `Boolean` that defaults to false. If `object` is true then this will return an object else it will return an `array` | ||
**Return:** `Object` or `Array` | ||
# LICENSE | ||
[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)) |
@@ -1,4 +0,9 @@ | ||
var Tx = require('../index.js') | ||
var ethUtil = require('ethereumjs-util') | ||
const Tx = require('../index.js') | ||
const tape = require('tape') | ||
const ethUtil = require('ethereumjs-util') | ||
const argv = require('minimist')(process.argv.slice(2)) | ||
const testing = require('ethereumjs-testing') | ||
var txTests = testing.getTests('transaction', argv) | ||
function addPad (v) { | ||
@@ -19,9 +24,13 @@ if (v.length % 2 === 1) { | ||
module.exports = function txRunner (testData, t, cb) { | ||
testing.runTests(function (testData, sst, cb) { | ||
var tTx = testData.transaction | ||
try { | ||
var tx = new Tx(new Buffer(testData.rlp.slice(2), 'hex')) | ||
if (testData.blocknumber !== '900000') { | ||
tx._skipSValueCheck = true | ||
} | ||
} catch (e) { | ||
t.equal(undefined, tTx, 'should not have any fields ') | ||
if (cb) cb() | ||
sst.equal(undefined, tTx, 'should not have any fields ') | ||
cb() | ||
return | ||
@@ -32,9 +41,9 @@ } | ||
try { | ||
t.equal(tx.data.toString('hex'), addPad(tTx.data.slice(2)), 'data') | ||
t.equal(ethUtil.bufferToInt(tx.gasLimit), Number(tTx.gasLimit), 'gasLimit') | ||
t.equal(ethUtil.bufferToInt(tx.gasPrice), Number(tTx.gasPrice), 'gasPrice') | ||
t.equal(ethUtil.bufferToInt(tx.nonce), Number(tTx.nonce), 'nonce') | ||
t.equal(tx.r.toString('hex'), addPad(tTx.r.slice(2)), 'r') | ||
t.equal(tx.s.toString('hex'), addPad(tTx.s.slice(2)), 's') | ||
t.equal(ethUtil.bufferToInt(tx.v), Number(tTx.v), 'v') | ||
sst.equal(tx.data.toString('hex'), addPad(tTx.data.slice(2)), 'data') | ||
sst.equal(ethUtil.bufferToInt(tx.gasLimit), Number(tTx.gasLimit), 'gasLimit') | ||
sst.equal(ethUtil.bufferToInt(tx.gasPrice), Number(tTx.gasPrice), 'gasPrice') | ||
sst.equal(ethUtil.bufferToInt(tx.nonce), Number(tTx.nonce), 'nonce') | ||
sst.equal(ethUtil.pad(tx.r, 32).toString('hex'), ethUtil.pad(tTx.r, 32).toString('hex'), 'r') | ||
sst.equal(tx.s.toString('hex'), addPad(tTx.s.slice(2)), 's') | ||
sst.equal(ethUtil.bufferToInt(tx.v), Number(tTx.v), 'v') | ||
if (tTx.to[1] === 'x') { | ||
@@ -44,15 +53,12 @@ tTx.to = tTx.to.slice(2) | ||
t.equal(tx.to.toString('hex'), tTx.to, 'to') | ||
t.equal(ifZero(tx.value.toString('hex')), tTx.value.slice(2), 'value') | ||
t.equal(tx.getSenderAddress().toString('hex'), testData.sender, "sender's address") | ||
sst.equal(tx.to.toString('hex'), tTx.to, 'to') | ||
sst.equal(ifZero(tx.value.toString('hex')), tTx.value.slice(2), 'value') | ||
sst.equal(tx.getSenderAddress().toString('hex'), testData.sender, "sender's address") | ||
} catch (e) { | ||
t.fail(e) | ||
sst.fail(e) | ||
} | ||
} else { | ||
t.equal(undefined, tTx, 'should have fields ') | ||
sst.equal(undefined, tTx, 'should have fields ') | ||
} | ||
if (cb) { | ||
cb() | ||
} | ||
} | ||
cb() | ||
}, txTests, tape) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1683518
36171
1
0
0
16
33
46
+ Addedethereum-common@0.0.13(transitive)
- Removedethereum-common@0.0.10(transitive)
Updatedethereum-common@0.0.13
Updatedethereumjs-util@^2.5.0