From 0bea06f785ac4e6eac6a132ad05ca405949bd0c5 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 2 Jul 2014 11:39:21 -0700 Subject: [PATCH 1/2] add BIP70 protobuf features in new PayPro lib file ...and add to the "main" bundle, but not the "all" bundle, since it adds hundreds of kilobytes to the bundle. --- bitcore.js | 1 + browser/build.js | 5 +- browser/bundle.js | 18 ++-- browser/testdata.js | 7 +- lib/PayPro.js | 186 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + test/index.html | 1 + test/test.PayPro.js | 212 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 417 insertions(+), 14 deletions(-) create mode 100644 lib/PayPro.js create mode 100644 test/test.PayPro.js diff --git a/bitcore.js b/bitcore.js index d0c12aca4e0..658a31d20fa 100644 --- a/bitcore.js +++ b/bitcore.js @@ -60,6 +60,7 @@ requireWhenAccessed('Script', './lib/Script'); requireWhenAccessed('Transaction', './lib/Transaction'); requireWhenAccessed('TransactionBuilder', './lib/TransactionBuilder'); requireWhenAccessed('Connection', './lib/Connection'); +requireWhenAccessed('PayPro', './lib/PayPro'); requireWhenAccessed('Peer', './lib/Peer'); requireWhenAccessed('Block', './lib/Block'); requireWhenAccessed('ScriptInterpreter', './lib/ScriptInterpreter'); diff --git a/browser/build.js b/browser/build.js index 1d21e43eaac..6b55c2c205c 100644 --- a/browser/build.js +++ b/browser/build.js @@ -38,6 +38,7 @@ var modules = [ 'lib/Electrum', 'lib/Message', 'lib/Opcode', + 'lib/PayPro', 'lib/Peer', 'lib/PeerManager', 'lib/PrivateKey', @@ -87,12 +88,14 @@ var createBitcore = function(opts) { var submodules = opts.submodules; + //modules not included in "main" bundle if (opts.includemain) { submodules = JSON.parse(JSON.stringify(modules)); submodules.splice(submodules.indexOf('lib/BIP39'), 1); submodules.splice(submodules.indexOf('lib/BIP39WordlistEn'), 1); + submodules.splice(submodules.indexOf('lib/PayPro'), 1); var assert = require('assert'); - assert(submodules.length == modules.length - 2); + assert(submodules.length == modules.length - 3); } if (opts.submodules) { diff --git a/browser/bundle.js b/browser/bundle.js index 8ef3ec0b275..018477cf910 100644 --- a/browser/bundle.js +++ b/browser/bundle.js @@ -51,11 +51,11 @@ require= // Override the current require with this new one return newRequire; }) -({"bitcore":[function(require,module,exports){ +({"tmvhGl":[function(require,module,exports){ +(function(e){var i=function(e,i){Object.defineProperty(module.exports,e,{get:function(){return require(i)}})};i("Bignum","bignum"),Object.defineProperty(module.exports,"bignum",{get:function(){return console.log('bignum (with a lower-case "b") is deprecated. Use bitcore.Bignum (capital "B") instead.'),require("bignum")}}),i("Base58","./lib/Base58"),Object.defineProperty(module.exports,"base58",{get:function(){return console.log('base58 (with a lower-case "b") is deprecated. Use bitcore.Base58 (capital "B") instead.'),require("./lib/Base58")}}),i("bufferput","bufferput"),i("buffertools","buffertools"),i("Buffers.monkey","./patches/Buffers.monkey"),i("config","./config"),i("const","./const"),i("Curve","./lib/Curve"),i("Deserialize","./lib/Deserialize"),i("ECIES","./lib/ECIES"),i("log","./util/log"),i("networks","./networks"),i("SecureRandom","./lib/SecureRandom"),i("sjcl","./lib/sjcl"),i("util","./util/util"),i("EncodedData","./util/EncodedData"),i("VersionedData","./util/VersionedData"),i("BinaryParser","./util/BinaryParser"),i("Address","./lib/Address"),i("HierarchicalKey","./lib/HierarchicalKey"),Object.defineProperty(module.exports,"BIP32",{get:function(){return console.log("BIP32 is deprecated. Use bitcore.HierarchicalKey instead."),require("./lib/HierarchicalKey")}}),i("BIP39","./lib/BIP39"),i("BIP39WordlistEn","./lib/BIP39WordlistEn"),i("Point","./lib/Point"),i("Opcode","./lib/Opcode"),i("Script","./lib/Script"),i("Transaction","./lib/Transaction"),i("TransactionBuilder","./lib/TransactionBuilder"),i("Connection","./lib/Connection"),i("PayPro","./lib/PayPro"),i("Peer","./lib/Peer"),i("Block","./lib/Block"),i("ScriptInterpreter","./lib/ScriptInterpreter"),i("Bloom","./lib/Bloom"),i("Key","./lib/Key"),Object.defineProperty(module.exports,"KeyModule",{get:function(){return console.log("KeyModule is deprecated."),require("bindings")("KeyModule")}}),i("SINKey","./lib/SINKey"),i("SIN","./lib/SIN"),i("PrivateKey","./lib/PrivateKey"),i("RpcClient","./lib/RpcClient"),i("Wallet","./lib/Wallet"),i("WalletKey","./lib/WalletKey"),i("PeerManager","./lib/PeerManager"),i("Message","./lib/Message"),i("Electrum","./lib/Electrum"),i("Armory","./lib/Armory"),module.exports.Buffer=e}).call(this,require("buffer").Buffer); +},{"./lib/Base58":"6VqyzY","./lib/HierarchicalKey":"x1O6JW","bignum":58,"bindings":78,"buffer":85}],"bitcore":[function(require,module,exports){ module.exports=require('tmvhGl'); -},{}],"tmvhGl":[function(require,module,exports){ -(function(e){var i=function(e,i){Object.defineProperty(module.exports,e,{get:function(){return require(i)}})};i("Bignum","bignum"),Object.defineProperty(module.exports,"bignum",{get:function(){return console.log('bignum (with a lower-case "b") is deprecated. Use bitcore.Bignum (capital "B") instead.'),require("bignum")}}),i("Base58","./lib/Base58"),Object.defineProperty(module.exports,"base58",{get:function(){return console.log('base58 (with a lower-case "b") is deprecated. Use bitcore.Base58 (capital "B") instead.'),require("./lib/Base58")}}),i("bufferput","bufferput"),i("buffertools","buffertools"),i("Buffers.monkey","./patches/Buffers.monkey"),i("config","./config"),i("const","./const"),i("Curve","./lib/Curve"),i("Deserialize","./lib/Deserialize"),i("ECIES","./lib/ECIES"),i("log","./util/log"),i("networks","./networks"),i("SecureRandom","./lib/SecureRandom"),i("sjcl","./lib/sjcl"),i("util","./util/util"),i("EncodedData","./util/EncodedData"),i("VersionedData","./util/VersionedData"),i("BinaryParser","./util/BinaryParser"),i("Address","./lib/Address"),i("HierarchicalKey","./lib/HierarchicalKey"),Object.defineProperty(module.exports,"BIP32",{get:function(){return console.log("BIP32 is deprecated. Use bitcore.HierarchicalKey instead."),require("./lib/HierarchicalKey")}}),i("BIP39","./lib/BIP39"),i("BIP39WordlistEn","./lib/BIP39WordlistEn"),i("Point","./lib/Point"),i("Opcode","./lib/Opcode"),i("Script","./lib/Script"),i("Transaction","./lib/Transaction"),i("TransactionBuilder","./lib/TransactionBuilder"),i("Connection","./lib/Connection"),i("Peer","./lib/Peer"),i("Block","./lib/Block"),i("ScriptInterpreter","./lib/ScriptInterpreter"),i("Bloom","./lib/Bloom"),i("Key","./lib/Key"),Object.defineProperty(module.exports,"KeyModule",{get:function(){return console.log("KeyModule is deprecated."),require("bindings")("KeyModule")}}),i("SINKey","./lib/SINKey"),i("SIN","./lib/SIN"),i("PrivateKey","./lib/PrivateKey"),i("RpcClient","./lib/RpcClient"),i("Wallet","./lib/Wallet"),i("WalletKey","./lib/WalletKey"),i("PeerManager","./lib/PeerManager"),i("Message","./lib/Message"),i("Electrum","./lib/Electrum"),i("Armory","./lib/Armory"),module.exports.Buffer=e}).call(this,require("buffer").Buffer); -},{"./lib/Base58":"6VqyzY","./lib/HierarchicalKey":"x1O6JW","bignum":58,"bindings":78,"buffer":85}],3:[function(require,module,exports){ +},{}],3:[function(require,module,exports){ function BigInteger(t,e,r){null!=t&&("number"==typeof t?this.fromNumber(t,e,r):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}function nbi(){return new BigInteger(null)}function am1(t,e,r,i,n,o){for(;--o>=0;){var s=e*this[t++]+r[i]+n;n=Math.floor(s/67108864),r[i++]=67108863&s}return n}function am2(t,e,r,i,n,o){for(var s=32767&e,u=e>>15;--o>=0;){var p=32767&this[t],h=this[t++]>>15,a=u*p+h*s;p=s*p+((32767&a)<<15)+r[i]+(1073741823&n),n=(p>>>30)+(a>>>15)+u*h+(n>>>30),r[i++]=1073741823&p}return n}function am3(t,e,r,i,n,o){for(var s=16383&e,u=e>>14;--o>=0;){var p=16383&this[t],h=this[t++]>>14,a=u*p+h*s;p=s*p+((16383&a)<<14)+r[i]+n,n=(p>>28)+(a>>14)+u*h,r[i++]=268435455&p}return n}function int2char(t){return BI_RM.charAt(t)}function intAt(t,e){var r=BI_RC[t.charCodeAt(e)];return null==r?-1:r}function bnpCopyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=0>t?-1:0,t>0?this[0]=t:-1>t?this[0]=t+DV:this.t=0}function nbv(t){var e=nbi();return e.fromInt(t),e}function bnpFromString(t,e){var r;if(16==e)r=4;else if(8==e)r=3;else if(256==e)r=8;else if(2==e)r=1;else if(32==e)r=5;else{if(4!=e)return void this.fromRadix(t,e);r=2}this.t=0,this.s=0;for(var i=t.length,n=!1,o=0;--i>=0;){var s=8==r?255&t[i]:intAt(t,i);0>s?"-"==t.charAt(i)&&(n=!0):(n=!1,0==o?this[this.t++]=s:o+r>this.DB?(this[this.t-1]|=(s&(1<>this.DB-o):this[this.t-1]|=s<=this.DB&&(o-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,o>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t}function bnToString(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var r,i=(1<0)for(u>u)>0&&(n=!0,o=int2char(r));s>=0;)e>u?(r=(this[s]&(1<>(u+=this.DB-e)):(r=this[s]>>(u-=e)&i,0>=u&&(u+=this.DB,--s)),r>0&&(n=!0),n&&(o+=int2char(r));return n?o:"0"}function bnNegate(){var t=nbi();return BigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var e=this.s-t.s;if(0!=e)return e;var r=this.t;if(e=r-t.t,0!=e)return this.s<0?-e:e;for(;--r>=0;)if(0!=(e=this[r]-t[r]))return e;return 0}function nbits(t){var e,r=1;return 0!=(e=t>>>16)&&(t=e,r+=16),0!=(e=t>>8)&&(t=e,r+=8),0!=(e=t>>4)&&(t=e,r+=4),0!=(e=t>>2)&&(t=e,r+=2),0!=(e=t>>1)&&(t=e,r+=1),r}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,e){var r;for(r=this.t-1;r>=0;--r)e[r+t]=this[r];for(r=t-1;r>=0;--r)e[r]=0;e.t=this.t+t,e.s=this.s}function bnpDRShiftTo(t,e){for(var r=t;r=0;--r)e[r+s+1]=this[r]>>n|u,u=(this[r]&o)<=0;--r)e[r]=0;e[s]=u,e.t=this.t+s+1,e.s=this.s,e.clamp()}function bnpRShiftTo(t,e){e.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)return void(e.t=0);var i=t%this.DB,n=this.DB-i,o=(1<>i;for(var s=r+1;s>i;i>0&&(e[this.t-r-1]|=(this.s&o)<r;)i+=this[r]-t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t>=this.DB;i+=this.s}else{for(i+=this.s;r>=this.DB;i-=t.s}e.s=0>i?-1:0,-1>i?e[r++]=this.DV+i:i>0&&(e[r++]=i),e.t=r,e.clamp()}function bnpMultiplyTo(t,e){var r=this.abs(),i=t.abs(),n=r.t;for(e.t=n+i.t;--n>=0;)e[n]=0;for(n=0;n=0;)t[r]=0;for(r=0;r=e.DV&&(t[r+e.t]-=e.DV,t[r+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(r,e[r],t,2*r,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,e,r){var i=t.abs();if(!(i.t<=0)){var n=this.abs();if(n.t0?(i.lShiftTo(p,o),n.lShiftTo(p,r)):(i.copyTo(o),n.copyTo(r));var h=o.t,a=o[h-1];if(0!=a){var F=a*(1<1?o[h-2]>>this.F2:0),g=this.FV/F,f=(1<=0&&(r[r.t++]=1,r.subTo(m,r)),BigInteger.ONE.dlShiftTo(h,m),m.subTo(o,o);o.t=0;){var y=r[--l]==a?this.DM:Math.floor(r[l]*g+(r[l-1]+c)*f);if((r[l]+=o.am(0,y,r,B,0,h))0&&r.rShiftTo(p,r),0>s&&BigInteger.ZERO.subTo(r,r)}}}function bnMod(t){var e=nbi();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(BigInteger.ZERO)>0&&t.subTo(e,e),e}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,e,r){t.multiplyTo(e,r),this.reduce(r)}function cSqrTo(t,e){t.squareTo(e),this.reduce(e)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return e=e*(2-(15&t)*e)&15,e=e*(2-(255&t)*e)&255,e=e*(2-((65535&t)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<0&&this.m.subTo(e,e),e}function montRevert(t){var e=nbi();return t.copyTo(e),this.reduce(e),e}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(r=e+this.m.t,t[r]+=this.m.am(0,i,t,e,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,e){t.squareTo(e),this.reduce(e)}function montMulTo(t,e,r){t.multiplyTo(e,r),this.reduce(r)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,e){if(t>4294967295||1>t)return BigInteger.ONE;var r=nbi(),i=nbi(),n=e.convert(this),o=nbits(t)-1;for(n.copyTo(r);--o>=0;)if(e.sqrTo(r,i),(t&1<0)e.mulTo(i,n,r);else{var s=r;r=i,i=s}return e.revert(r)}function bnModPowInt(t,e){var r;return r=256>t||e.isEven()?new Classic(e):new Montgomery(e),this.exp(t,r)}function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||2>t||t>36)return"0";var e=this.chunkSize(t),r=Math.pow(t,e),i=nbv(r),n=nbi(),o=nbi(),s="";for(this.divRemTo(i,n,o);n.signum()>0;)s=(r+o.intValue()).toString(t).substr(1)+s,n.divRemTo(i,n,o);return o.intValue().toString(t)+s}function bnpFromRadix(t,e){this.fromInt(0),null==e&&(e=10);for(var r=this.chunkSize(e),i=Math.pow(e,r),n=!1,o=0,s=0,u=0;up?"-"==t.charAt(u)&&0==this.signum()&&(n=!0):(s=e*s+p,++o>=r&&(this.dMultiply(i),this.dAddOffset(s,0),o=0,s=0))}o>0&&(this.dMultiply(Math.pow(e,o)),this.dAddOffset(s,0)),n&&BigInteger.ZERO.subTo(this,this)}function bnpFromNumber(t,e,r){if("number"==typeof e)if(2>t)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(t-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(BigInteger.ONE.shiftLeft(t-1),this);else{var i=new Array,n=7&t;i.length=(t>>3)+1,e.nextBytes(i),n>0?i[0]&=(1<0)for(i>i)!=(this.s&this.DM)>>i&&(e[n++]=r|this.s<=0;)8>i?(r=(this[t]&(1<>(i+=this.DB-8)):(r=this[t]>>(i-=8)&255,0>=i&&(i+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==n&&(128&this.s)!=(128&r)&&++n,(n>0||r!=this.s)&&(e[n++]=r);return e}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,e,r){var i,n,o=Math.min(t.t,this.t);for(i=0;o>i;++i)r[i]=e(this[i],t[i]);if(t.tt?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}function bnShiftRight(t){var e=nbi();return 0>t?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}function lbit(t){if(0==t)return-1;var e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function bnGetLowestSetBit(){for(var t=0;t=this.t?0!=this.s:0!=(this[e]&1<r;)i+=this[r]+t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t>=this.DB;i+=this.s}else{for(i+=this.s;r>=this.DB;i+=t.s}e.s=0>i?-1:0,i>0?e[r++]=i:-1>i&&(e[r++]=this.DV+i),e.t=r,e.clamp()}function bnAdd(t){var e=nbi();return this.addTo(t,e),e}function bnSubtract(t){var e=nbi();return this.subTo(t,e),e}function bnMultiply(t){var e=nbi();return this.multiplyTo(t,e),e}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var e=nbi();return this.divRemTo(t,e,null),e}function bnRemainder(t){var e=nbi();return this.divRemTo(t,null,e),e}function bnDivideAndRemainder(t){var e=nbi(),r=nbi();return this.divRemTo(t,e,r),new Array(e,r)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,e,r){t.multiplyTo(e,r)}function nSqrTo(t,e){t.squareTo(e)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,e,r){var i=Math.min(this.t+t.t,e);for(r.s=0,r.t=i;i>0;)r[--i]=0;var n;for(n=r.t-this.t;n>i;++i)r[i+this.t]=this.am(0,t[i],r,i,0,this.t);for(n=Math.min(t.t,e);n>i;++i)this.am(0,t[i],r,i,0,e-i);r.clamp()}function bnpMultiplyUpperTo(t,e,r){--e;var i=r.t=this.t+t.t-e;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(e-this.t,0);i2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=nbi();return t.copyTo(e),this.reduce(e),e}function barrettRevert(t){return t}function barrettReduce(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}function barrettSqrTo(t,e){t.squareTo(e),this.reduce(e)}function barrettMulTo(t,e,r){t.multiplyTo(e,r),this.reduce(r)}function bnModPow(t,e){var r,i,n=t.bitLength(),o=nbv(1);if(0>=n)return o;r=18>n?1:48>n?3:144>n?4:768>n?5:6,i=8>n?new Classic(e):e.isEven()?new Barrett(e):new Montgomery(e);var s=new Array,u=3,p=r-1,h=(1<1){var a=nbi();for(i.sqrTo(s[1],a);h>=u;)s[u]=nbi(),i.mulTo(a,s[u-2],s[u]),u+=2}var F,g,f=t.t-1,c=!0,l=nbi();for(n=nbits(t[f])-1;f>=0;){for(n>=p?F=t[f]>>n-p&h:(F=(t[f]&(1<0&&(F|=t[f-1]>>this.DB+n-p)),u=r;0==(1&F);)F>>=1,--u;if((n-=u)<0&&(n+=this.DB,--f),c)s[F].copyTo(o),c=!1;else{for(;u>1;)i.sqrTo(o,l),i.sqrTo(l,o),u-=2;u>0?i.sqrTo(o,l):(g=o,o=l,l=g),i.mulTo(l,s[F],o)}for(;f>=0&&0==(t[f]&1<o)return e;for(o>n&&(o=n),o>0&&(e.rShiftTo(o,e),r.rShiftTo(o,r));e.signum()>0;)(n=e.getLowestSetBit())>0&&e.rShiftTo(n,e),(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r}function bnpModInt(t){if(0>=t)return 0;var e=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==e)r=this[0]%t;else for(var i=this.t-1;i>=0;--i)r=(e*r+this[i])%t;return r}function bnModInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return BigInteger.ZERO;for(var r=t.clone(),i=this.clone(),n=nbv(1),o=nbv(0),s=nbv(0),u=nbv(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),e?(n.isEven()&&o.isEven()||(n.addTo(this,n),o.subTo(t,o)),n.rShiftTo(1,n)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;i.isEven();)i.rShiftTo(1,i),e?(s.isEven()&&u.isEven()||(s.addTo(this,s),u.subTo(t,u)),s.rShiftTo(1,s)):u.isEven()||u.subTo(t,u),u.rShiftTo(1,u);r.compareTo(i)>=0?(r.subTo(i,r),e&&n.subTo(s,n),o.subTo(u,o)):(i.subTo(r,i),e&&s.subTo(n,s),u.subTo(o,u))}return 0!=i.compareTo(BigInteger.ONE)?BigInteger.ZERO:u.compareTo(t)>=0?u.subtract(t):u.signum()<0?(u.addTo(t,u),u.signum()<0?u.add(t):u):u}function bnIsProbablePrime(t){var e,r=this.abs();if(1==r.t&&r[0]<=lowprimes[lowprimes.length-1]){for(e=0;ei;)i*=lowprimes[n++];for(i=r.modInt(i);n>e;)if(i%lowprimes[e++]==0)return!1}return r.millerRabin(t)}function bnpMillerRabin(t){var e=this.subtract(BigInteger.ONE),r=e.getLowestSetBit();if(0>=r)return!1;var i=e.shiftRight(r);t=t+1>>1,t>lowprimes.length&&(t=lowprimes.length);for(var n=nbi(),o=0;t>o;++o){n.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var s=n.modPow(i,this);if(0!=s.compareTo(BigInteger.ONE)&&0!=s.compareTo(e)){for(var u=1;u++e;++e)this.S[e]=e;for(r=0,e=0;256>e;++e)r=r+this.S[e]+t[e%t.length]&255,i=this.S[e],this.S[e]=this.S[r],this.S[r]=i;this.i=0,this.j=0}function ARC4next(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}function rng_seed_int(t){rng_pool[rng_pptr++]^=255&t,rng_pool[rng_pptr++]^=t>>8&255,rng_pool[rng_pptr++]^=t>>16&255,rng_pool[rng_pptr++]^=t>>24&255,rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}function rng_get_byte(){if(null==rng_state){for(rng_seed_time(),rng_state=prng_newstate(),rng_state.init(rng_pool),rng_pptr=0;rng_pptr0;--e){o=o.twice();var s=i.testBit(e),u=r.testBit(e);s!=u&&(o=o.add(s?this:n))}return o}function pointFpMultiplyTwo(t,e,r){var i;i=t.bitLength()>r.bitLength()?t.bitLength()-1:r.bitLength()-1;for(var n=this.curve.getInfinity(),o=this.add(e);i>=0;)n=n.twice(),t.testBit(i)?n=n.add(r.testBit(i)?o:this):r.testBit(i)&&(n=n.add(e)),--i;return n}function ECCurveFp(t,e,r){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(r),this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(t){return t==this?!0:this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(t){return new ECFieldElementFp(this.q,t)}function curveFpDecodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var e=(t.length-2)/2,r=t.substr(2,e),i=t.substr(e+2,e);return new ECPointFp(this,this.fromBigInteger(new BigInteger(r,16)),this.fromBigInteger(new BigInteger(i,16)));default:return null}}function X9ECParameters(t,e,r,i){this.curve=t,this.g=e,this.n=r,this.h=i}function x9getCurve(){return this.curve}function x9getG(){return this.g}function x9getN(){return this.n}function x9getH(){return this.h}function fromHex(t){return new BigInteger(t,16)}function secp128r1(){var t=fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF"),e=fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC"),r=fromHex("E87579C11079F43DD824993C2CEE5ED3"),i=fromHex("FFFFFFFE0000000075A30D1B9038A115"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("04161FF7528B899B2D0C28607CA52C5B86CF5AC8395BAFEB13C02DA292DDED7A83");return new X9ECParameters(o,s,i,n)}function secp160k1(){var t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73"),e=BigInteger.ZERO,r=fromHex("7"),i=fromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("043B4C382CE37AA192A4019E763036F4F5DD4D7EBB938CF935318FDCED6BC28286531733C3F03C4FEE");return new X9ECParameters(o,s,i,n)}function secp160r1(){var t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF"),e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC"),r=fromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45"),i=fromHex("0100000000000000000001F4C8F927AED3CA752257"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("044A96B5688EF573284664698968C38BB913CBFC8223A628553168947D59DCC912042351377AC5FB32");return new X9ECParameters(o,s,i,n)}function secp192k1(){var t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37"),e=BigInteger.ZERO,r=fromHex("3"),i=fromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("04DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D");return new X9ECParameters(o,s,i,n)}function secp192r1(){var t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"),e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC"),r=fromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1"),i=fromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("04188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF101207192B95FFC8DA78631011ED6B24CDD573F977A11E794811");return new X9ECParameters(o,s,i,n)}function secp224r1(){var t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001"),e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE"),r=fromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4"),i=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("04B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34");return new X9ECParameters(o,s,i,n)}function secp256k1(){var t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"),e=BigInteger.ZERO,r=fromHex("7"),i=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new X9ECParameters(o,s,i,n)}function secp256r1(){var t=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF"),e=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC"),r=fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B"),i=fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"),n=BigInteger.ONE,o=new ECCurveFp(t,e,r),s=o.decodePointHex("046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");return new X9ECParameters(o,s,i,n)}function getSECCurveByName(t){return"secp128r1"==t?secp128r1():"secp160k1"==t?secp160k1():"secp160r1"==t?secp160r1():"secp192k1"==t?secp192k1():"secp192r1"==t?secp192r1():"secp224r1"==t?secp224r1():"secp256k1"==t?secp256k1():"secp256r1"==t?secp256r1():null}function integerToBytes(t,e){var r=t.toByteArrayUnsigned();if(er.length;)r.unshift(0);return r}function dmp(t){return t instanceof BigInteger||(t=t.toBigInteger()),Crypto.util.bytesToHex(t.toByteArrayUnsigned())}if("undefined"==typeof window&&(window=this),Bitcoin={},"undefined"==typeof navigator){var navigator={};navigator.appName="NodeJS"}var base64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Crypto=window.Crypto={},util=Crypto.util={rotl:function(t,e){return t<>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&util.rotl(t,8)|4278255360&util.rotl(t,24);for(var e=0;e0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],r=0,i=0;r>>5]|=t[r]<<24-i%32;return e},wordsToBytes:function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},bytesToHex:function(t){for(var e=[],r=0;r>>4).toString(16)),e.push((15&t[r]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],r=0;rn;n++)e.push(8*r+6*n<=8*t.length?base64map.charAt(i>>>6*(3-n)&63):"=");return e.join("")},base64ToBytes:function(t){if("function"==typeof atob)return Binary.stringToBytes(atob(t));t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],r=0,i=0;r>>6-2*i);return e}};Crypto.mode={};var charenc=Crypto.charenc={},UTF8=charenc.UTF8={stringToBytes:function(t){return Binary.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(Binary.bytesToString(t)))}},Binary=charenc.Binary={stringToBytes:function(t){for(var e=[],r=0;rn;n++)e[i+n>>>2]|=(r[n>>>2]>>>24-8*(n%4)&255)<<24-8*((i+n)%4);else if(65535n;n+=4)e[i+n>>>2]=r[n>>>2];else e.push.apply(e,r);return this.sigBytes+=t,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-8*(r%4),e.length=t.ceil(r/4)},clone:function(){var t=o.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var r=[],i=0;e>i;i+=4)r.push(4294967296*t.random()|0);return new s.init(r,e)}}),u=r.enc={},p=u.Hex={stringify:function(t){var e=t.words;t=t.sigBytes;for(var r=[],i=0;t>i;i++){var n=e[i>>>2]>>>24-8*(i%4)&255;r.push((n>>>4).toString(16)),r.push((15&n).toString(16))}return r.join("")},parse:function(t){for(var e=t.length,r=[],i=0;e>i;i+=2)r[i>>>3]|=parseInt(t.substr(i,2),16)<<24-4*(i%8);return new s.init(r,e/2)}},h=u.Latin1={stringify:function(t){var e=t.words;t=t.sigBytes;for(var r=[],i=0;t>i;i++)r.push(String.fromCharCode(e[i>>>2]>>>24-8*(i%4)&255));return r.join("")},parse:function(t){for(var e=t.length,r=[],i=0;e>i;i++)r[i>>>2]|=(255&t.charCodeAt(i))<<24-8*(i%4);return new s.init(r,e)}},a=u.Utf8={stringify:function(t){try{return decodeURIComponent(escape(h.stringify(t)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(t){return h.parse(unescape(encodeURIComponent(t)))}},F=i.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=a.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var r=this._data,i=r.words,n=r.sigBytes,o=this.blockSize,u=n/(4*o),u=e?t.ceil(u):t.max((0|u)-this._minBufferSize,0);if(e=u*o,n=t.min(4*e,n),e){for(var p=0;e>p;p+=o)this._doProcessBlock(i,p);p=i.splice(0,e),r.sigBytes-=n}return new s.init(p,n)},clone:function(){var t=o.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});i.Hasher=F.extend({cfg:o.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){F.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize()},blockSize:16,_createHelper:function(t){return function(e,r){return new t.init(r).finalize(e)}},_createHmacHelper:function(t){return function(e,r){return new g.HMAC.init(t,r).finalize(e)}}});var g=r.algo={};return r}(Math);!function(){var t=CryptoJS,e=t.lib,r=e.WordArray,i=e.Hasher,e=t.algo,n=r.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),o=r.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),s=r.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),u=r.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),p=r.create([0,1518500249,1859775393,2400959708,2840853838]),h=r.create([1352829926,1548603684,1836072691,2053994217,0]),e=e.RIPEMD160=i.extend({_doReset:function(){this._hash=r.create([1732584193,4023233417,2562383102,271733878,3285377520]) },_doProcessBlock:function(t,e){for(var r=0;16>r;r++){var i=e+r,a=t[i];t[i]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}var F,g,f,c,l,B,m,y,d,v,i=this._hash.words,a=p.words,b=h.words,I=n.words,E=o.words,C=s.words,T=u.words;B=F=i[0],m=g=i[1],y=f=i[2],d=c=i[3],v=l=i[4];for(var w,r=0;80>r;r+=1)w=F+t[e+I[r]]|0,w=16>r?w+((g^f^c)+a[0]):32>r?w+((g&f|~g&c)+a[1]):48>r?w+(((g|~f)^c)+a[2]):64>r?w+((g&c|f&~c)+a[3]):w+((g^(f|~c))+a[4]),w|=0,w=w<>>32-C[r],w=w+l|0,F=l,l=c,c=f<<10|f>>>22,f=g,g=w,w=B+t[e+E[r]]|0,w=16>r?w+((m^(y|~d))+b[0]):32>r?w+((m&d|y&~d)+b[1]):48>r?w+(((m|~y)^d)+b[2]):64>r?w+((m&y|~m&d)+b[3]):w+((m^y^d)+b[4]),w|=0,w=w<>>32-T[r],w=w+v|0,B=v,v=d,d=y<<10|y>>>22,y=m,m=w;w=i[1]+f+d|0,i[1]=i[2]+c+v|0,i[2]=i[3]+l+B|0,i[3]=i[4]+F+m|0,i[4]=i[0]+g+y|0,i[0]=w},_doFinalize:function(){var t=this._data,e=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;for(e[i>>>5]|=128<<24-i%32,e[(i+64>>>9<<4)+14]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(e.length+1),this._process(),t=this._hash,e=t.words,r=0;5>r;r++)i=e[r],e[r]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(e),t.HmacRIPEMD160=i._createHmacHelper(e)}(Math),module.exports.crypto31=CryptoJS;var dbits,canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);j_lm&&"Microsoft Internet Explorer"==navigator.appName?(BigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(BigInteger.prototype.am=am1,dbits=26):(BigInteger.prototype.am=am3,dbits=28),BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<=vv;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,BigInteger.prototype.copyTo=bnpCopyTo,BigInteger.prototype.fromInt=bnpFromInt,BigInteger.prototype.fromString=bnpFromString,BigInteger.prototype.clamp=bnpClamp,BigInteger.prototype.dlShiftTo=bnpDLShiftTo,BigInteger.prototype.drShiftTo=bnpDRShiftTo,BigInteger.prototype.lShiftTo=bnpLShiftTo,BigInteger.prototype.rShiftTo=bnpRShiftTo,BigInteger.prototype.subTo=bnpSubTo,BigInteger.prototype.multiplyTo=bnpMultiplyTo,BigInteger.prototype.squareTo=bnpSquareTo,BigInteger.prototype.divRemTo=bnpDivRemTo,BigInteger.prototype.invDigit=bnpInvDigit,BigInteger.prototype.isEven=bnpIsEven,BigInteger.prototype.exp=bnpExp,BigInteger.prototype.toString=bnToString,BigInteger.prototype.negate=bnNegate,BigInteger.prototype.abs=bnAbs,BigInteger.prototype.compareTo=bnCompareTo,BigInteger.prototype.bitLength=bnBitLength,BigInteger.prototype.mod=bnMod,BigInteger.prototype.modPowInt=bnModPowInt,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=(1<<26)/lowprimes[lowprimes.length-1];BigInteger.prototype.chunkSize=bnpChunkSize,BigInteger.prototype.toRadix=bnpToRadix,BigInteger.prototype.fromRadix=bnpFromRadix,BigInteger.prototype.fromNumber=bnpFromNumber,BigInteger.prototype.bitwiseTo=bnpBitwiseTo,BigInteger.prototype.changeBit=bnpChangeBit,BigInteger.prototype.addTo=bnpAddTo,BigInteger.prototype.dMultiply=bnpDMultiply,BigInteger.prototype.dAddOffset=bnpDAddOffset,BigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,BigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,BigInteger.prototype.modInt=bnpModInt,BigInteger.prototype.millerRabin=bnpMillerRabin,BigInteger.prototype.clone=bnClone,BigInteger.prototype.intValue=bnIntValue,BigInteger.prototype.byteValue=bnByteValue,BigInteger.prototype.shortValue=bnShortValue,BigInteger.prototype.signum=bnSigNum,BigInteger.prototype.toByteArray=bnToByteArray,BigInteger.prototype.equals=bnEquals,BigInteger.prototype.min=bnMin,BigInteger.prototype.max=bnMax,BigInteger.prototype.and=bnAnd,BigInteger.prototype.or=bnOr,BigInteger.prototype.xor=bnXor,BigInteger.prototype.andNot=bnAndNot,BigInteger.prototype.not=bnNot,BigInteger.prototype.shiftLeft=bnShiftLeft,BigInteger.prototype.shiftRight=bnShiftRight,BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,BigInteger.prototype.bitCount=bnBitCount,BigInteger.prototype.testBit=bnTestBit,BigInteger.prototype.setBit=bnSetBit,BigInteger.prototype.clearBit=bnClearBit,BigInteger.prototype.flipBit=bnFlipBit,BigInteger.prototype.add=bnAdd,BigInteger.prototype.subtract=bnSubtract,BigInteger.prototype.multiply=bnMultiply,BigInteger.prototype.divide=bnDivide,BigInteger.prototype.remainder=bnRemainder,BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,BigInteger.prototype.modPow=bnModPow,BigInteger.prototype.modInverse=bnModInverse,BigInteger.prototype.pow=bnPow,BigInteger.prototype.gcd=bnGCD,BigInteger.prototype.isProbablePrime=bnIsProbablePrime,BigInteger.prototype.square=bnSquare,module.exports.BigInteger=BigInteger,Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256;BigInteger.valueOf=nbv,BigInteger.prototype.toByteArrayUnsigned=function(){var t=this.abs().toByteArray();return t.length?(0==t[0]&&(t=t.slice(1)),t.map(function(t){return 0>t?t+256:t})):t},BigInteger.fromByteArrayUnsigned=function(t){return t.length?new BigInteger(128&t[0]?[0].concat(t):t):t.valueOf(0)},BigInteger.prototype.toByteArraySigned=function(){var t=this.abs().toByteArrayUnsigned(),e=this.compareTo(BigInteger.ZERO)<0;return e?128&t[0]?t.unshift(128):t[0]|=128:128&t[0]&&t.unshift(0),t},BigInteger.fromByteArraySigned=function(t){return 128&t[0]?(t[0]&=127,BigInteger.fromByteArrayUnsigned(t).negate()):BigInteger.fromByteArrayUnsigned(t)};var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];"undefined"==typeof window.console&&(window.console={});for(var i=0;ii;)r[i++]=e;return r},numToVarInt:function(t){if(253>t)return[t];if(65536>t)return[253,255&t,t>>>8];if(4294967296>t)return[254].concat(Crypto.util.wordsToBytes([t]).reverse());throw"quadword not implemented"},valueToBigInt:function(t){return t instanceof BigInteger?t:BigInteger.fromByteArrayUnsigned(t)},formatValue:function(t){for(var e=this.valueToBigInt(t).toString(),r=e.length>8?e.substr(0,e.length-8):"0",i=e.length>8?e.substr(e.length-8):e;i.length<8;)i="0"+i;for(i=i.replace(/0*$/,"");i.length<2;)i+="0";return r+"."+i},parseValue:function(t){for(var e=t.split("."),r=e[0],i=e[1]||"0";i.length<8;)i+="0";i=i.replace(/^0+/g,"");var n=BigInteger.valueOf(parseInt(r));return n=n.multiply(BigInteger.valueOf(1e8)),n=n.add(BigInteger.valueOf(parseInt(i)))},sha256ripe160:function(t){return Crypto.RIPEMD160(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0})}};for(var i in Crypto.util)Crypto.util.hasOwnProperty(i)&&(Bitcoin.Util[i]=Crypto.util[i]);var rng_state,rng_pool,rng_pptr;if(null==rng_pool){rng_pool=new Array,rng_pptr=0;var t;if("Netscape"==navigator.appName&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;trng_pptr;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=255&t;rng_pptr=0,rng_seed_time()}SecureRandom.prototype.nextBytes=function(){throw new Error("Should not use old RNG")},ECFieldElementFp.prototype.equals=feFpEquals,ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger,ECFieldElementFp.prototype.negate=feFpNegate,ECFieldElementFp.prototype.add=feFpAdd,ECFieldElementFp.prototype.subtract=feFpSubtract,ECFieldElementFp.prototype.multiply=feFpMultiply,ECFieldElementFp.prototype.square=feFpSquare,ECFieldElementFp.prototype.divide=feFpDivide,ECPointFp.prototype.getX=pointFpGetX,ECPointFp.prototype.getY=pointFpGetY,ECPointFp.prototype.equals=pointFpEquals,ECPointFp.prototype.isInfinity=pointFpIsInfinity,ECPointFp.prototype.negate=pointFpNegate,ECPointFp.prototype.add=pointFpAdd,ECPointFp.prototype.twice=pointFpTwice,ECPointFp.prototype.multiply=pointFpMultiply,ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo,ECCurveFp.prototype.getQ=curveFpGetQ,ECCurveFp.prototype.getA=curveFpGetA,ECCurveFp.prototype.getB=curveFpGetB,ECCurveFp.prototype.equals=curveFpEquals,ECCurveFp.prototype.getInfinity=curveFpGetInfinity,ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger,ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex,module.exports.ECPointFp=ECPointFp,module.exports.ECFieldElementFp=ECFieldElementFp,X9ECParameters.prototype.getCurve=x9getCurve,X9ECParameters.prototype.getG=x9getG,X9ECParameters.prototype.getN=x9getN,X9ECParameters.prototype.getH=x9getH,module.exports.getSECCurveByName=getSECCurveByName,ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},ECPointFp.prototype.getEncoded=function(t){var e=this.getX().toBigInteger(),r=this.getY().toBigInteger(),i=integerToBytes(e,32);return t?i.unshift(r.isEven()?2:3):(i.unshift(4),i=i.concat(integerToBytes(r,32))),i},ECPointFp.decodeFrom=function(t,e){var r=e[0],i=e.length-1;if(4===r)var n=e.slice(1,1+i/2),o=e.slice(1+i/2,1+i),s=BigInteger.fromByteArrayUnsigned(n),u=BigInteger.fromByteArrayUnsigned(o);else{var n=e.slice(1),s=BigInteger.fromByteArrayUnsigned(n),p=t.getQ(),h=s.multiply(s).multiply(s).add(new BigInteger("7")).mod(p),a=p.add(new BigInteger("1")).divide(new BigInteger("4")),u=h.modPow(a,p);u.mod(new BigInteger("2")).toString()!=""+r%2&&(u=p.subtract(u))}return new ECPointFp(t,t.fromBigInteger(s),t.fromBigInteger(u))},ECPointFp.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),r=t.y.subtract(this.y),i=r.divide(e),n=i.square().subtract(this.x).subtract(t.x),o=i.multiply(this.x.subtract(n)).subtract(this.y);return new ECPointFp(this.curve,n,o)},ECPointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(BigInteger.valueOf(2)),e=this.curve.fromBigInteger(BigInteger.valueOf(3)),r=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),i=r.square().subtract(this.x.multiply(t)),n=r.multiply(this.x.subtract(i)).subtract(this.y);return new ECPointFp(this.curve,i,n)},ECPointFp.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,r=t,i=r.multiply(new BigInteger("3")),n=this.negate(),o=this;for(e=i.bitLength()-2;e>0;--e){o=o.twice();var s=i.testBit(e),u=r.testBit(e);s!=u&&(o=o.add2D(s?this:n))}return o},ECPointFp.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),r=this.curve.getA().toBigInteger(),i=this.curve.getB().toBigInteger(),n=this.curve.getQ(),o=e.multiply(e).mod(n),s=t.multiply(t).multiply(t).add(r.multiply(t)).add(i).mod(n);return o.equals(s)},ECPointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ECPointFp.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),r=this.getY().toBigInteger();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("x coordinate out of bounds");if(r.compareTo(BigInteger.ONE)<0||r.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0},Bitcoin.ECDSA=function(){function t(t,e,r,i){for(var n=Math.max(e.bitLength(),i.bitLength()),o=t.add2D(r),s=t.curve.getInfinity(),u=n-1;u>=0;--u)s=s.twice2D(),s.z=BigInteger.ONE,e.testBit(u)?s=s.add2D(i.testBit(u)?o:t):i.testBit(u)&&(s=s.add2D(r));return s}var e=getSECCurveByName("secp256k1"),r=new SecureRandom,i=null,n={getBigRandom:function(t){return new BigInteger(t.bitLength(),r).mod(t.subtract(BigInteger.ONE)).add(BigInteger.ONE)},sign:function(t,r){var i=r,o=e.getN(),s=BigInteger.fromByteArrayUnsigned(t);do var u=n.getBigRandom(o),p=e.getG(),h=p.multiply(u),a=h.getX().toBigInteger().mod(o);while(a.compareTo(BigInteger.ZERO)<=0);var F=u.modInverse(o).multiply(s.add(i.multiply(a))).mod(o);return n.serializeSig(a,F)},verify:function(t,r,i){var o,s;if(Bitcoin.Util.isArray(r)){var u=n.parseSig(r);o=u.r,s=u.s}else{if("object"!=typeof r||!r.r||!r.s)throw"Invalid value for signature";o=r.r,s=r.s}var p;if(i instanceof ECPointFp)p=i;else{if(!Bitcoin.Util.isArray(i))throw"Invalid format for pubkey value, must be byte array or ECPointFp";p=ECPointFp.decodeFrom(e.getCurve(),i)}var h=BigInteger.fromByteArrayUnsigned(t);return n.verifyRaw(h,o,s,p)},verifyRaw:function(t,r,i,n){var o=e.getN(),s=e.getG();if(r.compareTo(BigInteger.ONE)<0||r.compareTo(o)>=0)return!1;if(i.compareTo(BigInteger.ONE)<0||i.compareTo(o)>=0)return!1;var u=i.modInverse(o),p=t.multiply(u).mod(o),h=r.multiply(u).mod(o),a=s.multiply(p).add(n.multiply(h)),F=a.getX().toBigInteger().mod(o);return F.equals(r)},serializeSig:function(t,e){var r=t.toByteArraySigned(),i=e.toByteArraySigned(),n=[];return n.push(2),n.push(r.length),n=n.concat(r),n.push(2),n.push(i.length),n=n.concat(i),n.unshift(n.length),n.unshift(48),n},parseSig:function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(e=2,2!=t[e])throw new Error("First element in signature must be a DERInteger");var r=t.slice(e+2,e+2+t[e+1]);if(e+=2+t[e+1],2!=t[e])throw new Error("Second element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);e+=2+t[e+1];var n=BigInteger.fromByteArrayUnsigned(r),o=BigInteger.fromByteArrayUnsigned(i);return{r:n,s:o}},parseSigCompact:function(t){if(65!==t.length)throw"Signature has the wrong length";var r=t[0]-27;if(0>r||r>7)throw"Invalid signature type";var i=e.getN(),n=BigInteger.fromByteArrayUnsigned(t.slice(1,33)).mod(i),o=BigInteger.fromByteArrayUnsigned(t.slice(33,65)).mod(i);return{r:n,s:o,i:r}},recoverPubKey:function(r,o,s,u){u=3&u;var p=1&u,h=u>>1,a=e.getN(),F=e.getG(),g=e.getCurve(),f=g.getQ(),c=g.getA().toBigInteger(),l=g.getB().toBigInteger();i||(i=f.add(BigInteger.ONE).divide(BigInteger.valueOf(4)));var B=h?r.add(a):r,m=B.multiply(B).multiply(B).add(c.multiply(B)).add(l).mod(f),y=m.modPow(i,f),d=(y.isEven()?u%2:(u+1)%2,(y.isEven()?!p:p)?y:f.subtract(y)),v=new ECPointFp(g,g.fromBigInteger(B),g.fromBigInteger(d));v.validate();var b=BigInteger.fromByteArrayUnsigned(s),I=BigInteger.ZERO.subtract(b).mod(a),E=r.modInverse(a),C=t(v,o,F,I).multiply(E);if(C.validate(),!n.verifyRaw(b,r,o,C))throw"Pubkey recovery unsuccessful";var T=new Bitcoin.ECKey;return T.pub=C,T},calcPubkeyRecoveryParam:function(t,e,r,i){for(var n=0;4>n;n++)try{var o=Bitcoin.ECDSA.recoverPubKey(e,r,i,n);if(o.getBitcoinAddress().toString()==t)return n}catch(s){}throw"Unable to find valid recovery factor"}};return n}(),Bitcoin.ECKey=function(){var t=Bitcoin.ECDSA,e=getSECCurveByName("secp256k1"),r=(new SecureRandom,function(t){if(t)t instanceof BigInteger?this.priv=t:Bitcoin.Util.isArray(t)?this.priv=BigInteger.fromByteArrayUnsigned(t):"string"==typeof t&&(this.priv=BigInteger.fromByteArrayUnsigned(51==t.length&&"5"==t[0]?r.decodeString(t):Crypto.util.hexToBytes(t)));else{e.getN()}this.compressed=!!r.compressByDefault});return r.compressByDefault=!1,r.prototype.setCompressed=function(t){this.compressed=!!t},r.prototype.getPub=function(){return this.getPubPoint().getEncoded(this.compressed)},r.prototype.getPubPoint=function(){return this.pub||(this.pub=e.getG().multiply(this.priv)),this.pub},r.prototype.getPubKeyHash=function(){return this.pubKeyHash?this.pubKeyHash:this.pubKeyHash=Bitcoin.Util.sha256ripe160(this.getPub())},r.prototype.getBitcoinAddress=function(){var t=this.getPubKeyHash(),e=new Bitcoin.Address(t);return e},r.prototype.getExportedPrivateKey=function(){for(var t=this.priv.toByteArrayUnsigned();t.length<32;)t.unshift(0);t.unshift(128);var e=Crypto.SHA256(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0}),r=t.concat(e.slice(0,4));return Bitcoin.Base58.encode(r)},r.prototype.setPub=function(t){this.pub=ECPointFp.decodeFrom(e.getCurve(),t)},r.prototype.toString=function(t){return"base64"===t?Crypto.util.bytesToBase64(this.priv.toByteArrayUnsigned()):Crypto.util.bytesToHex(this.priv.toByteArrayUnsigned())},r.prototype.sign=function(e){return t.sign(e,this.priv)},r.prototype.verify=function(e,r){return t.verify(e,r,this.getPub())},r.decodeString=function(t){var e=Bitcoin.Base58.decode(t),r=e.slice(0,33),i=Crypto.SHA256(Crypto.SHA256(r,{asBytes:!0}),{asBytes:!0});if(i[0]!=e[33]||i[1]!=e[34]||i[2]!=e[35]||i[3]!=e[36])throw"Checksum validation failed!";var n=r.shift();if(128!=n)throw"Version "+n+" not supported!";return r},r}(),module.exports.ECKey=Bitcoin.ECKey; },{}],"4itQ50":[function(require,module,exports){ @@ -138,11 +138,11 @@ module.exports=require('tBM27q'); function SINKey(e){"object"!=typeof e&&(e={}),this.created=e.created,this.privKey=e.privKey}var coinUtil=require("../util"),timeUtil=require("../util/time"),Key=require("./Key"),SIN=require("./SIN");SINKey.prototype.generate=function(){this.privKey=Key.generateSync(),this.created=timeUtil.curtime()},SINKey.prototype.pubkeyHash=function(){return coinUtil.sha256ripe160(this.privKey.public)},SINKey.prototype.storeObj=function(){var e=this.privKey.public.toString("hex"),t=this.pubkeyHash(),i=new SIN(SIN.SIN_EPHEM,t),r={created:this.created,priv:this.privKey.private.toString("hex"),pub:e,sin:i.toString()};return r},module.exports=require("soop")(SINKey); },{"../util":143,"../util/time":146,"./Key":"ALJ4PS","./SIN":"tBM27q","soop":129}],"./lib/SINKey":[function(require,module,exports){ module.exports=require('EyghZQ'); -},{}],"./lib/Script":[function(require,module,exports){ -module.exports=require('hQ0t76'); },{}],"hQ0t76":[function(require,module,exports){ -(function(t){function e(t){this.buffer=t?t:c.EMPTY_BUFFER,this.chunks=[],this.parse()}function r(t){return t==o.map.OP_0||t>=o.map.OP_1&&t<=o.map.OP_16}function n(t){return t=t?2:65535>=t?3:5}function s(e){var r=void 0;return e=e?(r=new t(2),r.writeUInt8(o.map.OP_PUSHDATA1,0),r.writeUInt8(e,1)):65535>=e?(r=new t(3),r.writeUInt8(o.map.OP_PUSHDATA2,0),r.writeUInt16LE(e,1)):(r=new t(5),r.writeUInt8(o.map.OP_PUSHDATA4,0),r.writeUInt32LE(e,1)),r}var u=require("soop").imports(),h=(u.config||require("../config"),u.log||require("../util/log")),o=u.Opcode||require("./Opcode"),f=u.buffertools||require("buffertools"),c=u.util||require("../util/util"),p=u.Parser||require("../util/BinaryParser"),a=u.Put||require("bufferput"),l=0,g=1,k=2,w=3,P=4,y=["unknown","pubkey","pubkeyhash","multisig","scripthash"];e.TX_UNKNOWN=l,e.TX_PUBKEY=g,e.TX_PUBKEYHASH=k,e.TX_MULTISIG=w,e.TX_SCRIPTHASH=P,e.prototype.parse=function(){this.chunks=[];for(var t=new p(this.buffer);!t.eof();){var e,r,n=t.word8();n>0&&no.map.OP_16)return!1}return!0},e.prototype.isP2SH=function(){return 3==this.chunks.length&&this.chunks[0]==o.map.OP_HASH160&&t.isBuffer(this.chunks[1])&&20==this.chunks[1].length&&this.chunks[2]==o.map.OP_EQUAL},e.prototype.isPubkey=function(){return 2==this.chunks.length&&t.isBuffer(this.chunks[0])&&this.chunks[1]==o.map.OP_CHECKSIG},e.prototype.isPubkeyHash=function(){return 5==this.chunks.length&&this.chunks[0]==o.map.OP_DUP&&this.chunks[1]==o.map.OP_HASH160&&t.isBuffer(this.chunks[2])&&20==this.chunks[2].length&&this.chunks[3]==o.map.OP_EQUALVERIFY&&this.chunks[4]==o.map.OP_CHECKSIG},e.prototype.isMultiSig=function(){return this.chunks.length>3&&r(this.chunks[0])&&this.chunks.slice(1,this.chunks.length-2).every(function(e){return t.isBuffer(e)})&&r(this.chunks[this.chunks.length-2])&&this.chunks[this.chunks.length-1]==o.map.OP_CHECKMULTISIG},e.prototype.isP2shScriptSig=function(){if(!r(this.chunks[0])||0!==this.chunks[0])return!1;var t=new e(this.chunks[this.chunks.length-1]),n=t.classify();return n!==l},e.prototype.isMultiSigScriptSig=function(){return r(this.chunks[0])&&0===this.chunks[0]?!this.isP2shScriptSig():!1},e.prototype.countSignatures=function(){var t=0,e=this.chunks.length;return t=this.isMultiSigScriptSig()?e-1:this.isP2shScriptSig()?e-2:0===f.compare(this.getBuffer(),c.EMPTY_BUFFER)?0:1},e.prototype.countMissingSignatures=function(){if(this.isMultiSig())return h.debug("Can not count missing signatures on normal Multisig script"),null;var t=0,n=this.chunks.length;if(r(this.chunks[0])&&0===this.chunks[0]){var i=new e(this.chunks[n-1]);if(r(i.chunks[0])){var s=i.chunks[0]-80;t=s-(n-2)}else h.debug("Unrecognized script type")}else 0===f.compare(this.getBuffer(),c.EMPTY_BUFFER)&&(t=1);return t},e.prototype.finishedMultiSig=function(){var t=this.countMissingSignatures();return null===t?null:0===t},e.prototype.getMultiSigInfo=function(){if(!this.isMultiSig())throw new Error("Script.getMultiSigInfo(): Not a multiSig script.");for(var t=this.chunks[0]-80,e=this.chunks[this.chunks.length-2]-80,r=[],n=1;ni;i++){var u=this.chunks[i];if(i>0&&(n+=" "),n+=t.isBuffer(u)?"0x"+c.formatBuffer(u,e?null:0):o.reverseMap[u],r&&i>r){n+=" ...";break}}return n},e.prototype.toString=function(t,e){var r=" + diff --git a/test/test.PayPro.js b/test/test.PayPro.js new file mode 100644 index 00000000000..4b654f6f0fe --- /dev/null +++ b/test/test.PayPro.js @@ -0,0 +1,212 @@ +'use strict'; + +var chai = chai || require('chai'); +var should = chai.should(); +var expect = chai.expect; +var bitcore = bitcore || require('../bitcore'); + +var PayPro = bitcore.PayPro; +var Key = bitcore.Key; + +describe('PayPro', function() { + + it('should be able to create class', function() { + should.exist(PayPro); + }); + + describe('#Output', function() { + + it('should not fail', function() { + var obj = {}; + var output = new PayPro.Output(); + output.$set('amount', 20); + }); + + it('should be able to set the amount of an output', function() { + var output = new PayPro.Output(); + output.set('amount', 20); + output.get('amount').toInt().should.equal(20); + }); + + }); + + describe('#PaymentDetails', function() { + + it('should not fail', function() { + var obj = {}; + var pd = new PayPro.PaymentDetails(); + }); + + it('should set the memo', function() { + var obj = {}; + var pd = new PayPro.PaymentDetails(); + pd.set('memo', 'test memo'); + pd.get('memo').should.equal('test memo'); + }); + + it('should serialize', function() { + var obj = {}; + var pd = new PayPro.PaymentDetails(); + pd.set('time', 0); + pd.set('memo', 'test memo'); + var hex = pd.toHex(); + hex.length.should.be.greaterThan(0); + }); + + }); + + describe('#PaymentRequest', function() { + + it('should not fail', function() { + var obj = {}; + var pd = new PayPro.PaymentRequest(); + }); + + it('should serialize', function() { + var obj = {}; + var pd = new PayPro.PaymentDetails(); + pd.set('time', 0); + var pdbuf = pd.toBuffer(); + var pr = new PayPro.PaymentRequest(); + pr.set('serialized_payment_details', pdbuf); + var prhex = pr.toHex(); + prhex.length.should.be.greaterThan(0); + }); + + }); + + describe('#Payment', function() { + + it('should not fail', function() { + var obj = {}; + var pd = new PayPro.Payment(); + }); + + it('should serialize', function() { + var obj = {}; + var p = new PayPro.Payment(); + p.set('memo', 'this is a memo'); + p.get('memo').should.equal('this is a memo'); + var phex = p.toHex(); + phex.length.should.be.greaterThan(0); + }); + + }); + + describe('#PaymentACK', function() { + + it('should not fail', function() { + var obj = {}; + var pd = new PayPro.PaymentACK(); + }); + + it('should serialize', function() { + var obj = {}; + var p = new PayPro.Payment(); + var pa = new PayPro.PaymentACK(); + pa.set('payment', p); + pa.set('memo', 'this is a memo'); + pa.get('memo').should.equal('this is a memo'); + var pahex = pa.toHex(); + pahex.length.should.be.greaterThan(0); + }); + + }); + + describe('#X509Certificates', function() { + + it('should not fail', function() { + var obj = {}; + var pd = new PayPro.X509Certificates(); + }); + + it('should serialize', function() { + var obj = {}; + var x = new PayPro.X509Certificates(); + var fakecertificate = new Buffer([0, 0, 0, 0]); + x.set('certificate', [fakecertificate]); + var xhex = x.toHex(); + xhex.length.should.be.greaterThan(0); + }); + + }); + + describe('#isValidSize', function() { + + it('should return true for validly sized payment', function() { + var paypro = new PayPro(); + paypro.makePayment(); + paypro.set('memo', 'test memo'); + paypro.isValidSize().should.equal(true); + }); + + }); + + describe('#getContentType', function() { + + it('should get a content type for payment', function() { + var paypro = new PayPro(); + paypro.makePayment(); + paypro.set('memo', 'test memo'); + paypro.getContentType().should.equal('application/bitcoin-payment'); + }); + + }); + + describe('#set', function() { + + it('should set a field', function() { + var obj = {}; + var paypro = new PayPro(); + paypro.makePaymentDetails(); + paypro.set('memo', 'test memo'); + paypro.get('memo').should.equal('test memo'); + }); + + }); + + describe('#get', function() { + + it('should get a field', function() { + var obj = {}; + var paypro = new PayPro(); + paypro.makePaymentDetails(); + paypro.set('memo', 'test memo'); + paypro.get('memo').should.equal('test memo'); + }); + + }); + + describe('#serialize', function() { + + it('should serialize', function() { + var obj = {}; + var paypro = new PayPro(); + paypro.makePaymentDetails(); + paypro.set('memo', 'test memo'); + paypro.set('time', 0); + var buf = paypro.serialize(); + buf.length.should.be.greaterThan(0); + Buffer.isBuffer(buf).should.equal(true); + }); + + }); + + describe('#deserialize', function() { + + it('should deserialize a serialized message', function() { + var obj = {}; + var paypro = new PayPro(); + paypro.makePaymentDetails(); + paypro.set('memo', 'test memo'); + paypro.set('time', 0); + var buf = paypro.serialize(); + var paypro2 = new PayPro(); + paypro2.deserialize(buf, 'PaymentDetails'); + paypro2.get('memo').should.equal('test memo'); + paypro2.get('time').should.equal(0); + }); + + }); + +}); From 0722ce46d70fca4ec92b0f67648e370ab5253c11 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 2 Jul 2014 11:51:15 -0700 Subject: [PATCH 2/2] comment typo --- browser/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/build.js b/browser/build.js index 6b55c2c205c..b427f5aab75 100644 --- a/browser/build.js +++ b/browser/build.js @@ -88,7 +88,7 @@ var createBitcore = function(opts) { var submodules = opts.submodules; - //modules not included in "main" bundle + //modules included in "all" but not included in "main" bundle if (opts.includemain) { submodules = JSON.parse(JSON.stringify(modules)); submodules.splice(submodules.indexOf('lib/BIP39'), 1);