bitcore-channel
Advanced tools
Comparing version 0.10.1 to 0.11.0
{ | ||
"name": "bitcore-channel", | ||
"main": "./bitcore-channel.min.js", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"homepage": "https://github.com/bitpay/bitcore-channel", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -132,3 +132,3 @@ 'use strict'; | ||
$.checkState(this.commitmentTx.isFullySigned()); | ||
var amount = this.commitmentTx.amount; | ||
var amount = this.commitmentTx.amount - this.commitmentTx.getFee(); | ||
var multisigOut = { | ||
@@ -141,6 +141,5 @@ txid: this.commitmentTx.id, | ||
this.refundTx = new Refund() | ||
.from(multisigOut, this.commitmentTx.publicKeys, 2) | ||
.change(this.refundAddress); | ||
.from(multisigOut, this.commitmentTx.publicKeys, 2); | ||
this.refundTx.to(this.refundAddress, this.refundTx.inputAmount); | ||
this.refundTx.inputs[0].sequenceNumber = 0; | ||
this.refundTx._updateChangeOutput(); | ||
this.refundTx.nLockTime = this.expires; | ||
@@ -160,6 +159,7 @@ return this.refundTx; | ||
refund.sign(this.commitmentKey); | ||
$.checkState(new Address(refund.outputs[0].script, this.network).toString() === | ||
this.refundAddress.toString()); | ||
var receivedAddress = new Address(refund.outputs[0].script, this.network).toString(); | ||
$.checkState(receivedAddress === this.refundAddress.toString()); | ||
var amount = refund.outputs[0].satoshis; | ||
$.checkState(amount + refund._estimateFee() === this.commitmentTx.amount); | ||
$.checkState(amount === this.commitmentTx.amount - this.commitmentTx.getFee(), | ||
'Refund amount must equal commitmentTx amount'); | ||
$.checkState(refund.outputs.length === 1, 'More than expected outputs received'); | ||
@@ -169,3 +169,12 @@ $.checkState(refund.isFullySigned(), 'Refund was not fully signed'); | ||
refund.inputs[0].script, | ||
refund.inputs[0].output.script | ||
refund.inputs[0].output.script, | ||
refund, | ||
0, | ||
Script.Interpreter.SCRIPT_VERIFY_P2SH | ||
| | ||
Script.Interpreter.SCRIPT_VERIFY_STRICTENC | ||
| | ||
Script.Interpreter.SCRIPT_VERIFY_MINIMALDATA | ||
| | ||
Script.Interpreter.SCRIPT_VERIFY_SIGPUSHONLY | ||
), 'Refund is incorrectly signed'); | ||
@@ -172,0 +181,0 @@ this.refundTx = refund; |
@@ -51,7 +51,17 @@ 'use strict'; | ||
}); | ||
$.checkState(!_.isUndefined(newAmount), 'No output found corresponding to paymentAddress'); | ||
$.checkState(Script.Interpreter().verify( | ||
payment.inputs[0].script, | ||
payment.inputs[0].output.script | ||
payment.inputs[0].output.script, | ||
payment, | ||
0, | ||
Script.Interpreter.SCRIPT_VERIFY_P2SH | ||
| | ||
Script.Interpreter.SCRIPT_VERIFY_STRICTENC | ||
| | ||
Script.Interpreter.SCRIPT_VERIFY_MINIMALDATA | ||
| | ||
Script.Interpreter.SCRIPT_VERIFY_SIGPUSHONLY | ||
), 'Script did not evaluate correctly (probably a bad signature received)'); | ||
$.checkState(!_.isUndefined(newAmount) && newAmount > this.currentAmount, | ||
$.checkState(newAmount > this.currentAmount, | ||
'A payment for a greater amount was already received'); | ||
@@ -58,0 +68,0 @@ this.paymentTx = payment; |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var PrivateKey = require('bitcore').PrivateKey; | ||
var Address = require('bitcore').Address; | ||
var Script = require('bitcore').Script; | ||
@@ -31,3 +29,5 @@ var Transaction = require('bitcore').Transaction; | ||
this.address = this.outscript.toScriptHashOut().toAddress(); | ||
this.change(this.address); | ||
if (!this.outputs.length) { | ||
this.change(this.address); | ||
} | ||
@@ -37,6 +37,5 @@ Object.defineProperty(this, 'amount', { | ||
get: function() { | ||
return this._inputAmount; | ||
return this.inputAmount; | ||
} | ||
}); | ||
this._updateChange = undefined; | ||
} | ||
@@ -43,0 +42,0 @@ inherits(Commitment, Transaction); |
@@ -28,3 +28,6 @@ 'use strict'; | ||
this.paymentAddress = new Address(opts.paymentAddress); | ||
this._change = new Address(opts.changeAddress); | ||
this.changeAddress = new Address(opts.changeAddress); | ||
if (!this.outputs.length) { | ||
this.change(this.changeAddress); | ||
} | ||
@@ -36,11 +39,6 @@ this.multisigOut = new Transaction.UnspentOutput(opts.multisigOut); | ||
} | ||
if (this.outputs.length < 2) { | ||
this._updateChangeOutput(); | ||
} | ||
this.amount = this.outputAmount; | ||
this.sequence = opts.sequence || 0; | ||
this._fee = FEE_AMOUNT; | ||
this.paid = opts.paid || 0; | ||
$.checkArgument(_.isNumber(this.amount), 'Amount must be a number'); | ||
this._changeSetup = undefined; | ||
} | ||
@@ -50,8 +48,5 @@ inherits(Payment, Transaction); | ||
Payment.prototype._updateTransaction = function() { | ||
this.outputs = []; | ||
this._changeOutput = undefined; | ||
this._outputAmount = 0; | ||
this.clearOutputs(); | ||
this.to(this.paymentAddress, this.paid); | ||
this.inputs[0].sequence = this.sequence; | ||
this._changeSetup = false; | ||
}; | ||
@@ -75,3 +70,3 @@ | ||
paymentAddress: this.paymentAddress.toString(), | ||
changeAddress: this._change.toString(), | ||
changeAddress: this.changeAddress.toString(), | ||
transaction: Transaction.prototype.toObject.apply(this) | ||
@@ -78,0 +73,0 @@ }; |
@@ -12,3 +12,2 @@ 'use strict'; | ||
Transaction.apply(this, arguments); | ||
this._changeSetup = undefined; | ||
} | ||
@@ -15,0 +14,0 @@ inherits(Refund, Transaction); |
{ | ||
"name": "bitcore-channel", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "Add payment channels support to bitcore", | ||
@@ -10,3 +10,13 @@ "scripts": { | ||
}, | ||
"author": "Esteban Ordano <eordano@gmail.com>", | ||
"author": "BitPay <dev@bitpay.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Esteban Ordano", | ||
"email": "eordano@gmail.com" | ||
}, | ||
{ | ||
"name": "Manuel Araoz", | ||
"email": "manuelaraoz@gmail.com" | ||
} | ||
], | ||
"keywords": [ | ||
@@ -22,6 +32,5 @@ "bitcoin", | ||
"license": "MIT", | ||
"repository": "https://github.com/eordano/bitcore-channel", | ||
"repository": "https://github.com/bitpay/bitcore-channel", | ||
"dependencies": { | ||
"bitcore": "^0.12.0", | ||
"browserify": "^8.1.0", | ||
"bitcore": "^0.12.6", | ||
"inherits": "=2.0.1" | ||
@@ -28,0 +37,0 @@ }, |
<img src="http://bitcore.io/css/images/module-channel.png" alt="bitcore payment channels" height="35"> | ||
# Payment channels for bitcore | ||
# Payment Channels for Bitcore | ||
@@ -4,0 +4,0 @@ [![NPM Package](https://img.shields.io/npm/v/bitcore-channel.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-channel) |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var bitcore = require('bitcore'); | ||
var Networks = require('bitcore/lib/networks'); | ||
var Networks = bitcore.Networks; | ||
@@ -28,6 +28,6 @@ describe('Simple Payment Channel usage', function() { | ||
'sequenceNumber': 4294967295, | ||
'script': '483045022100d1905baf6c16cf6c2aefd23f57c000f607bac82eada248fb9ad40d2be46a0f2d022045da95d5b7767f2793f5ea9f8c4240de79ebe6cb8454fec706b8e11dca8fa891012103bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'scriptString': '72 0x3045022100d1905baf6c16cf6c2aefd23f57c000f607bac82eada248fb9ad40d2be46a0f2d022045da95d5b7767f2793f5ea9f8c4240de79ebe6cb8454fec706b8e11dca8fa89101 33 0x03bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'script': '483045022100e5e9a5660ed650b377d1063c57ba210d2f8e36f350489a5b0ca9b46eb8fb659a02205a6d336c2252b39fcb7534fdfc3a593a87b5c34c0d3ad27e25bd5edea027308a012103bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'scriptString': '72 0x3045022100e5e9a5660ed650b377d1063c57ba210d2f8e36f350489a5b0ca9b46eb8fb659a02205a6d336c2252b39fcb7534fdfc3a593a87b5c34c0d3ad27e25bd5edea027308a01 33 0x03bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'output': { | ||
'satoshis': 100000, | ||
'satoshis': 50000000, | ||
'script': '76a91469b678f36c91bf635ff6e9479edd3253a5dfd41a88ac' | ||
@@ -39,6 +39,6 @@ } | ||
'sequenceNumber': 4294967295, | ||
'script': '483045022100c3d8097771be0850c8134d1ff8fc854a4ad004b538cf19b08cb9e5d4734fa972022017f976bfdfc3ec8af5117eb07e2ed8588110ede7b21a4a9202cc239497c94bc3012103bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'scriptString': '72 0x3045022100c3d8097771be0850c8134d1ff8fc854a4ad004b538cf19b08cb9e5d4734fa972022017f976bfdfc3ec8af5117eb07e2ed8588110ede7b21a4a9202cc239497c94bc301 33 0x03bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'script': '47304402205d5c5ae33804c2842311bedca88474ee47d49efba2a3aece49e7039551cc98b00220338b5aed644a810b0d92c9717029a1dfe3808f8a5ce74ec4f5cc03c6a7af2148012103bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'scriptString': '71 0x304402205d5c5ae33804c2842311bedca88474ee47d49efba2a3aece49e7039551cc98b00220338b5aed644a810b0d92c9717029a1dfe3808f8a5ce74ec4f5cc03c6a7af214801 33 0x03bca86b6a422d1ffec9fd0a1e8d37feaef4e41f76bbdde68852251b7ae8ca6fab', | ||
'output': { | ||
'satoshis': 1000000, | ||
'satoshis': 10000000, | ||
'script': '76a91469b678f36c91bf635ff6e9479edd3253a5dfd41a88ac' | ||
@@ -48,3 +48,3 @@ } | ||
'outputs': [{ | ||
'satoshis': 1090000, | ||
'satoshis': 59990000, | ||
'script': 'a914fdeaa734587dfed0090c98fbf1bf8730009ddda887' | ||
@@ -56,6 +56,3 @@ }], | ||
}, | ||
'publicKeys': [ | ||
'027f10e67bea70f847b3ab92c18776c6a97a78f84def158afc31fd98513d42912e', | ||
'023bc028f67697712efeb0216ef1bc7208e2c9156bf0731204d79328f4c8ef643a' | ||
], | ||
'publicKeys': ['027f10e67bea70f847b3ab92c18776c6a97a78f84def158afc31fd98513d42912e', '023bc028f67697712efeb0216ef1bc7208e2c9156bf0731204d79328f4c8ef643a'], | ||
'network': 'testnet' | ||
@@ -68,3 +65,3 @@ }; | ||
var consumer = getFundedConsumer().consumer; | ||
consumer.commitmentTx.amount.should.equal(1100000); | ||
consumer.commitmentTx.amount.should.equal(60000000); | ||
}); | ||
@@ -125,2 +122,15 @@ | ||
}); | ||
it('calculates fees normally', function() { | ||
var provider = getProvider(); | ||
var consumer = getValidatedConsumer().consumer; | ||
provider.validPayment(consumer.incrementPaymentBy(1000)); | ||
provider.currentAmount.should.equal(1000); | ||
provider.paymentTx.getFee().should.equal(10000); | ||
provider.validPayment(consumer.incrementPaymentBy(1000)); | ||
provider.validPayment(consumer.incrementPaymentBy(1000)); | ||
provider.validPayment(consumer.incrementPaymentBy(1000)); | ||
provider.currentAmount.should.equal(4000); | ||
provider.paymentTx.getFee().should.equal(10000); | ||
}); | ||
}); | ||
@@ -163,3 +173,3 @@ }); | ||
'scriptPubKey': '76a91469b678f36c91bf635ff6e9479edd3253a5dfd41a88ac', | ||
'amount': 0.001, | ||
'amount': 0.5, | ||
'confirmationsFromCache': false | ||
@@ -172,3 +182,3 @@ }, { | ||
'scriptPubKey': '76a91469b678f36c91bf635ff6e9479edd3253a5dfd41a88ac', | ||
'amount': 0.01, | ||
'amount': 0.1, | ||
'confirmations': 18, | ||
@@ -175,0 +185,0 @@ 'confirmationsFromCache': false |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
42986
2
28
845
0
- Removedbrowserify@^8.1.0
- RemovedBase64@0.2.1(transitive)
- RemovedJSONStream@0.8.41.3.5(transitive)
- Removedacorn@4.0.135.7.47.4.1(transitive)
- Removedacorn-node@1.8.2(transitive)
- Removedacorn-walk@7.2.0(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedasn1.js@4.10.1(transitive)
- Removedassert@1.3.0(transitive)
- Removedastw@2.2.0(transitive)
- Removedasync@0.2.10(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase64-js@0.0.8(transitive)
- Removedbn.js@4.12.15.2.1(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedbrowser-pack@3.2.0(transitive)
- Removedbrowser-resolve@1.11.3(transitive)
- Removedbrowserify@8.1.3(transitive)
- Removedbrowserify-aes@1.2.0(transitive)
- Removedbrowserify-cipher@1.0.1(transitive)
- Removedbrowserify-des@1.0.2(transitive)
- Removedbrowserify-rsa@4.1.1(transitive)
- Removedbrowserify-sign@4.2.3(transitive)
- Removedbrowserify-zlib@0.1.4(transitive)
- Removedbuffer@3.6.2(transitive)
- Removedbuffer-xor@1.0.3(transitive)
- Removedbuiltins@0.0.7(transitive)
- Removedcallsite@1.0.0(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcipher-base@1.0.6(transitive)
- Removedcombine-source-map@0.3.00.6.1(transitive)
- Removedcommondir@0.0.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconcat-stream@1.4.11(transitive)
- Removedconsole-browserify@1.2.0(transitive)
- Removedconstants-browserify@0.0.1(transitive)
- Removedconvert-source-map@0.3.51.1.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcreate-ecdh@4.0.4(transitive)
- Removedcreate-hash@1.2.0(transitive)
- Removedcreate-hmac@1.1.7(transitive)
- Removedcrypto-browserify@3.12.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddeep-equal@0.2.2(transitive)
- Removeddefined@0.0.01.0.1(transitive)
- Removeddeps-sort@1.3.9(transitive)
- Removeddes.js@1.1.0(transitive)
- Removeddetective@4.7.1(transitive)
- Removeddiffie-hellman@5.0.3(transitive)
- Removeddomain-browser@1.1.7(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedelliptic@6.6.1(transitive)
- Removedevents@1.0.2(transitive)
- Removedevp_bytestokey@1.0.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedglob@4.5.3(transitive)
- Removedhash-base@3.0.5(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedhttp-browserify@1.7.0(transitive)
- Removedhttps-browserify@0.0.1(transitive)
- Removedieee754@1.2.1(transitive)
- Removedindexof@0.0.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.32.0.4(transitive)
- Removedinline-source-map@0.3.10.5.0(transitive)
- Removedinsert-module-globals@6.6.3(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedjson-stable-stringify@0.0.1(transitive)
- Removedjsonify@0.0.1(transitive)
- Removedjsonparse@0.0.51.3.1(transitive)
- Removedlabeled-stream-splicer@1.0.2(transitive)
- Removedlexical-scope@1.2.0(transitive)
- Removedlodash.memoize@3.0.4(transitive)
- Removedmd5.js@1.3.5(transitive)
- Removedmiller-rabin@4.0.1(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedminimatch@2.0.10(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmodule-deps@3.9.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedoptimist@0.3.7(transitive)
- Removedos-browserify@0.1.2(transitive)
- Removedpako@0.2.9(transitive)
- Removedparents@1.0.1(transitive)
- Removedparse-asn1@5.1.7(transitive)
- Removedpath-browserify@0.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-platform@0.11.15(transitive)
- Removedpbkdf2@3.1.2(transitive)
- Removedprocess@0.10.10.11.10(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpublic-encrypt@4.0.3(transitive)
- Removedpunycode@1.2.41.3.2(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedquerystring-es3@0.2.1(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedrandomfill@1.0.4(transitive)
- Removedreadable-stream@1.0.341.1.142.3.8(transitive)
- Removedreadable-wrap@1.0.0(transitive)
- Removedresolve@0.3.10.7.41.1.71.22.10(transitive)
- Removedrfile@1.0.0(transitive)
- Removedripemd160@2.0.2(transitive)
- Removedruglify@1.0.0(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedsha.js@2.4.11(transitive)
- Removedshallow-copy@0.0.1(transitive)
- Removedshasum@1.0.2(transitive)
- Removedshell-quote@0.0.1(transitive)
- Removedsource-map@0.1.340.1.430.3.00.4.4(transitive)
- Removedstream-browserify@1.0.0(transitive)
- Removedstream-combiner2@1.0.2(transitive)
- Removedstream-splicer@1.3.2(transitive)
- Removedstring_decoder@0.10.311.1.1(transitive)
- Removedsubarg@1.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedsyntax-error@1.4.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedthrough2@0.5.11.1.1(transitive)
- Removedtimers-browserify@1.4.2(transitive)
- Removedtty-browserify@0.0.1(transitive)
- Removedtypedarray@0.0.7(transitive)
- Removeduglify-js@2.2.52.4.24(transitive)
- Removeduglify-to-browserify@1.0.2(transitive)
- Removedumd@2.1.0(transitive)
- Removedurl@0.10.3(transitive)
- Removedutil@0.10.30.10.4(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvm-browserify@0.0.4(transitive)
- Removedwindow-size@0.1.0(transitive)
- Removedwordwrap@0.0.20.0.3(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@3.0.04.0.2(transitive)
- Removedyargs@3.5.4(transitive)
Updatedbitcore@^0.12.6