bitcoinjs-lib
Advanced tools
Comparing version
@@ -0,1 +1,13 @@ | ||
| # 2.2.0 | ||
| __added__ | ||
| - Added `Block.calculateTarget` for difficulty calculations (#509) | ||
| - Added `Block.prototype.checkProofOfWork` (#509) | ||
| - Added `opcodes.OP_CHECKLOCKTIMEVERIFY` alias for `OP_NOP2` (#511) | ||
| - Added `script.number.[encode/decode]` for CScriptNum-encoded `Buffer`s (#516) | ||
| - Added `TransactionBuilder.prototype.setLockTime` (#507) | ||
| __fixed__ | ||
| - Bumped `typeforce` version to fix erroneous error message from `types.Hash*bit` types (#534) | ||
| # 2.1.4 | ||
@@ -2,0 +14,0 @@ __fixed__ |
| { | ||
| "name": "bitcoinjs-lib", | ||
| "version": "2.1.4", | ||
| "version": "2.2.0", | ||
| "description": "Client-side Bitcoin JavaScript library", | ||
@@ -65,2 +65,3 @@ "main": "./src/index.js", | ||
| "bs58check": "^1.0.5", | ||
| "buffer-compare": "^1.1.0", | ||
| "buffer-equals": "^1.0.3", | ||
@@ -72,3 +73,3 @@ "buffer-reverse": "^1.0.0", | ||
| "randombytes": "^2.0.1", | ||
| "typeforce": "^1.5.5", | ||
| "typeforce": "^1.6.2", | ||
| "wif": "^1.1.0" | ||
@@ -75,0 +76,0 @@ }, |
| # BitcoinJS (bitcoinjs-lib) | ||
| [](https://travis-ci.org/bitcoinjs/bitcoinjs-lib) | ||
| [](https://www.npmjs.org/package/bitcoinjs-lib) | ||
| [](http://tip4commit.com/projects/735) | ||
| [](https://www.npmjs.org/package/bitcoinjs-lib) | ||
| [](http://tip4commit.com/projects/735) | ||
@@ -118,2 +118,3 @@ [](https://github.com/feross/standard) | ||
| - [Dogechain Wallet](https://dogechain.info) | ||
| - [EI8HT Wallet](http://ei8.ht/) | ||
| - [GreenAddress](https://greenaddress.it) | ||
@@ -169,10 +170,9 @@ - [Hive Wallet](https://www.hivewallet.com) | ||
| ## License | ||
| ## LICENSE [MIT](LICENSE) | ||
| This library is free and open-source software released under the MIT license. | ||
| ## Copyright | ||
| BitcoinJS (c) 2011-2015 Bitcoinjs-lib contributors | ||
| BitcoinJS (c) 2011-2016 bitcoinjs-lib contributors | ||
| Released under MIT license |
@@ -21,4 +21,4 @@ var bs58check = require('bs58check') | ||
| if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(3, 23), network.pubKeyHash) | ||
| if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(scriptPubKey.slice(2, 22), network.scriptHash) | ||
| if (bscript.isPubKeyHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(3, 23), network.pubKeyHash) | ||
| if (bscript.isScriptHashOutput(scriptPubKey)) return toBase58Check(bscript.compile(scriptPubKey).slice(2, 22), network.scriptHash) | ||
@@ -25,0 +25,0 @@ throw new Error(bscript.toASM(scriptPubKey) + ' has no matching Address') |
| var bufferutils = require('./bufferutils') | ||
| var bcrypto = require('./crypto') | ||
| var compare = require('buffer-compare') | ||
@@ -118,2 +119,25 @@ var Transaction = require('./transaction') | ||
| Block.calculateTarget = function (bits) { | ||
| var exponent = ((bits & 0xff000000) >> 24) - 3 | ||
| var mantissa = bits & 0x007fffff | ||
| var i = 31 - exponent | ||
| var target = new Buffer(32) | ||
| target.fill(0) | ||
| target[i] = mantissa & 0xff | ||
| target[i - 1] = mantissa >> 8 | ||
| target[i - 2] = mantissa >> 16 | ||
| target[i - 3] = mantissa >> 24 | ||
| return target | ||
| } | ||
| Block.prototype.checkProofOfWork = function () { | ||
| var hash = [].reverse.call(this.getHash()) | ||
| var target = Block.calculateTarget(this.bits) | ||
| return compare(hash, target) <= 0 | ||
| } | ||
| module.exports = Block |
@@ -116,2 +116,4 @@ { | ||
| "OP_NOP2": 177, | ||
| "OP_CHECKLOCKTIMEVERIFY": 177, | ||
| "OP_NOP3": 178, | ||
@@ -118,0 +120,0 @@ "OP_NOP4": 179, |
@@ -19,3 +19,3 @@ var bip66 = require('bip66') | ||
| function toASM (chunks) { | ||
| if (types.Buffer(chunks)) { | ||
| if (Buffer.isBuffer(chunks)) { | ||
| chunks = decompile(chunks) | ||
@@ -47,3 +47,3 @@ } | ||
| // TODO: remove me | ||
| if (types.Buffer(chunks)) return chunks | ||
| if (Buffer.isBuffer(chunks)) return chunks | ||
@@ -377,2 +377,4 @@ typeforce(types.Array, chunks) | ||
| number: require('./script_number'), | ||
| isCanonicalPubKey: isCanonicalPubKey, | ||
@@ -379,0 +381,0 @@ isCanonicalSignature: isCanonicalSignature, |
@@ -7,2 +7,4 @@ var baddress = require('./address') | ||
| var ops = require('./opcodes') | ||
| var typeforce = require('typeforce') | ||
| var types = require('./types') | ||
@@ -139,2 +141,17 @@ var ECPair = require('./ecpair') | ||
| TransactionBuilder.prototype.setLockTime = function (locktime) { | ||
| typeforce(types.UInt32, locktime) | ||
| // if any signatures exist, throw | ||
| if (this.inputs.some(function (input) { | ||
| if (!input.signatures) return false | ||
| return input.signatures.some(function (s) { return s }) | ||
| })) { | ||
| throw new Error('No, this would invalidate signatures') | ||
| } | ||
| this.tx.locktime = locktime | ||
| } | ||
| TransactionBuilder.fromTransaction = function (transaction, network) { | ||
@@ -213,10 +230,13 @@ var txb = new TransactionBuilder(network) | ||
| var valid = this.inputs.every(function (input2) { | ||
| if (input2.hashType === undefined) return true | ||
| // if signatures exist, adding inputs is only acceptable if SIGHASH_ANYONECANPAY is used | ||
| // throw if any signatures *didn't* use SIGHASH_ANYONECANPAY | ||
| if (!this.inputs.every(function (otherInput) { | ||
| // no signature | ||
| if (otherInput.hashType === undefined) return true | ||
| return input2.hashType & Transaction.SIGHASH_ANYONECANPAY | ||
| }) | ||
| return otherInput.hashType & Transaction.SIGHASH_ANYONECANPAY | ||
| })) { | ||
| throw new Error('No, this would invalidate signatures') | ||
| } | ||
| if (!valid) throw new Error('No, this would invalidate signatures') | ||
| var prevOut = txHash.toString('hex') + ':' + vout | ||
@@ -233,12 +253,21 @@ if (this.prevTxMap[prevOut]) throw new Error('Transaction is already an input') | ||
| TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) { | ||
| var tx = this.tx | ||
| var valid = this.inputs.every(function (input, index) { | ||
| var nOutputs = this.tx.outs.length | ||
| // if signatures exist, adding outputs is only acceptable if SIGHASH_NONE or SIGHASH_SINGLE is used | ||
| // throws if any signatures didn't use SIGHASH_NONE|SIGHASH_SINGLE | ||
| if (!this.inputs.every(function (input, index) { | ||
| // no signature | ||
| if (input.hashType === undefined) return true | ||
| var hashType = input.hashType & 0x1f | ||
| return hashType === Transaction.SIGHASH_NONE || | ||
| (hashType === Transaction.SIGHASH_SINGLE && index < tx.outs.length) | ||
| }) | ||
| var hashTypeMod = input.hashType & 0x1f | ||
| if (hashTypeMod === Transaction.SIGHASH_NONE) return true | ||
| if (hashTypeMod === Transaction.SIGHASH_SINGLE) { | ||
| // account for SIGHASH_SINGLE signing of a non-existing output, aka the "SIGHASH_SINGLE" bug | ||
| return index < nOutputs | ||
| } | ||
| if (!valid) throw new Error('No, this would invalidate signatures') | ||
| return false | ||
| })) { | ||
| throw new Error('No, this would invalidate signatures') | ||
| } | ||
@@ -250,3 +279,3 @@ // Attempt to get a script if it's a base58 address string | ||
| return tx.addOutput(scriptPubKey, value) | ||
| return this.tx.addOutput(scriptPubKey, value) | ||
| } | ||
@@ -253,0 +282,0 @@ |
@@ -5,3 +5,4 @@ var typeforce = require('typeforce') | ||
| typeforce(types.Buffer, value) | ||
| if (value.length !== n) throw new Error('Expected ' + (n * 8) + '-bit Buffer, got ' + (value.length * 8) + '-bit Buffer') | ||
| if (value.length !== n) throw new typeforce.TfTypeError('Expected ' + (n * 8) + '-bit Buffer, got ' + (value.length * 8) + '-bit Buffer') | ||
| return true | ||
@@ -8,0 +9,0 @@ } |
Sorry, the diff of this file is not supported yet
86956
4.34%22
4.76%2155
4.82%12
9.09%+ Added
+ Added
Updated