ethers.js/dist/ethers-wallet.min.js

6 lines
188 KiB
JavaScript
Raw Normal View History

!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){b.exports=void 0},{}],2:[function(a,b,c){function d(a){return(1<<a)-1<<8-a}function e(a){return(1<<a)-1}function f(a,b,c,d){if(!(this instanceof f))throw new Error("missing new");m.defineProperty(this,"_keyPair",a),m.defineProperty(this,"privateKey",m.hexlify(a.priv.toArray("be",32))),m.defineProperty(this,"publicKey","0x"+a.getPublic(!0,"hex")),m.defineProperty(this,"chainCode",m.hexlify(b)),m.defineProperty(this,"index",c),m.defineProperty(this,"depth",d)}function g(a,b){if(b)if(b.normalize)b=b.normalize("NFKD");else for(var c=0;c<b.length;c++){var d=b.charCodeAt(c);if(d<32||d>127)throw new Error("passwords with non-ASCII characters not supported in this environment")}else b="";a=m.toUtf8Bytes(a,"NFKD");var e=m.toUtf8Bytes("mnemonic"+b,"NFKD");return m.hexlify(m.pbkdf2(a,e,2048,64,m.createSha512Hmac))}function h(a){var b=a.toLowerCase().split(" ");if(b.length%3!==0)throw new Error("invalid mnemonic");for(var c=new Uint8Array(Math.ceil(11*b.length/8)),e=0,f=0;f<b.length;f++){var g=l.indexOf(b[f]);if(g===-1)throw new Error("invalid mnemonic");for(var h=0;h<11;h++)g&1<<10-h&&(c[e>>3]|=1<<7-e%8),e++}var i=32*b.length/3,j=b.length/3,k=d(j),n=m.arrayify(m.sha256(c.slice(0,i/8)))[0];if(n&=k,n!==(c[c.length-1]&k))throw new Error("invalid checksum");return m.hexlify(c.slice(0,i/8))}function i(a){if(a=m.arrayify(a),a.length%4!==0||a.length<16||a.length>32)throw new Error("invalid entropy");for(var b=[0],c=11,f=0;f<a.length;f++)c>8?(b[b.length-1]<<=8,b[b.length-1]|=a[f],c-=8):(b[b.length-1]<<=c,b[b.length-1]|=a[f]>>8-c,b.push(a[f]&e(8-c)),c+=3);var g=m.arrayify(m.sha256(a))[0],h=a.length/4;g&=d(h),b[b.length-1]<<=h,b[b.length-1]|=g>>8-h;for(var f=0;f<b.length;f++)b[f]=l[b[f]];return b.join(" ")}function j(a){try{return h(a),!0}catch(b){}return!1}var k=new(a("elliptic").ec)("secp256k1"),l=function(){var b=a("./words.json");return b.replace(/([A-Z])/g," $1").toLowerCase().substring(1).split(" ")}(),m=function(){var b=a("ethers-utils/convert.js"),c=a("ethers-utils/sha2"),d=a("ethers-utils/hmac");return{defineProperty:a("ethers-utils/properties.js").defineProperty,arrayify:b.arrayify,bigNumberify:a("ethers-utils/bignumber.js").bigNumberify,hexlify:b.hexlify,toUtf8Bytes:a("ethers-utils/utf8.js").toUtf8Bytes,sha256:c.sha256,createSha512Hmac:d.createSha512Hmac,pbkdf2:a("ethers-utils/pbkdf2.js")}}(),n=m.toUtf8Bytes("Bitcoin seed"),o=2147483648;m.defineProperty(f.prototype,"_derive",function(a){if(!this.privateKey){if(a>=o)throw new Error("cannot derive child of neutered node");throw new Error("not implemented")}var b=new Uint8Array(37);a&o?b.set(m.arrayify(this.privateKey),1):b.set(this._keyPair.getPublic().encode(null,!0));for(var c=24;c>=0;c-=8)b[33+(c>>3)]=a>>24-c&255;var d=m.createSha512Hmac(this.chainCode).update(b).digest(),e=m.bigNumberify(d.slice(0,32)),g=(d.slice(32),e.add("0x"+this._keyPair.getPrivate("hex")).mod("0x"+k.curve.n.toString(16)));return new f(k.keyFromPrivate(m.arrayify(g)),d.slice(32),a,this.depth+1)}),m.defineProperty(f.prototype,"derivePath",function(a){var b=a.split("/");if(0===b.length||"m"===b[0]&&0!==this.depth)throw new Error("invalid path");"m"===b[0]&&b.shift();for(var c=this,d=0;d<b.length;d++){var e=b[d];if(e.match(/^[0-9]+'$/)){var f=parseInt(e.substring(0,e.length-1));if(f>=o)throw new Error("invalid path index - "+e);c=c._derive(o+f)}else{if(!e.match(/^[0-9]+$/))throw new Error("invlaid path component - "+e);var f=parseInt(e);if(f>=o)throw new Error("invalid path index - "+e);c=c._derive(f)}}return c}),m.defineProperty(f,"fromMnemonic",function(a){return h(a),f.fromSeed(g(a))}),m.defineProperty(f,"fromSeed",function(a){if(a=m.arrayify(a),a.length<16|
if(!(this instanceof D))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:f(a,!0)}),this._prepare()};D.prototype._prepare=function(){var a=n[this.key.length];if(null==a)throw new Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var b=0;b<=a;b++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);for(var c,d=4*(a+1),e=this.key.length/4,f=i(this.key),b=0;b<e;b++)c=b>>2,this._Ke[c][b%4]=f[b],this._Kd[a-c][b%4]=f[b];for(var g,h=0,j=e;j<d;){if(g=f[e-1],f[0]^=p[g>>16&255]<<24^p[g>>8&255]<<16^p[255&g]<<8^p[g>>24&255]^o[h]<<24,h+=1,8!=e)for(var b=1;b<e;b++)f[b]^=f[b-1];else{for(var b=1;b<e/2;b++)f[b]^=f[b-1];g=f[e/2-1],f[e/2]^=p[255&g]^p[g>>8&255]<<8^p[g>>16&255]<<16^p[g>>24&255]<<24;for(var b=e/2+1;b<e;b++)f[b]^=f[b-1]}for(var k,l,b=0;b<e&&j<d;)k=j>>2,l=j%4,this._Ke[k][l]=f[b],this._Kd[a-k][l]=f[b++],j++}for(var k=1;k<a;k++)for(var l=0;l<4;l++)g=this._Kd[k][l],this._Kd[k][l]=z[g>>24&255]^A[g>>16&255]^B[g>>8&255]^C[255&g]},D.prototype.encrypt=function(a){if(16!=a.length)throw new Error("invalid plaintext size (must be 16 bytes)");for(var b=this._Ke.length-1,c=[0,0,0,0],d=i(a),e=0;e<4;e++)d[e]^=this._Ke[0][e];for(var f=1;f<b;f++){for(var e=0;e<4;e++)c[e]=r[d[e]>>24&255]^s[d[(e+1)%4]>>16&255]^t[d[(e+2)%4]>>8&255]^u[255&d[(e+3)%4]]^this._Ke[f][e];d=c.slice()}for(var h,j=g(16),e=0;e<4;e++)h=this._Ke[b][e],j[4*e]=255&(p[d[e]>>24&255]^h>>24),j[4*e+1]=255&(p[d[(e+1)%4]>>16&255]^h>>16),j[4*e+2]=255&(p[d[(e+2)%4]>>8&255]^h>>8),j[4*e+3]=255&(p[255&d[(e+3)%4]]^h);return j},D.prototype.decrypt=function(a){if(16!=a.length)throw new Error("invalid ciphertext size (must be 16 bytes)");for(var b=this._Kd.length-1,c=[0,0,0,0],d=i(a),e=0;e<4;e++)d[e]^=this._Kd[0][e];for(var f=1;f<b;f++){for(var e=0;e<4;e++)c[e]=v[d[e]>>24&255]^w[d[(e+3)%4]>>16&255]^x[d[(e+2)%4]>>8&255]^y[255&d[(e+1)%4]]^this._Kd[f][e];d=c.slice()}for(var h,j=g(16),e=0;e<4;e++)h=this._Kd[b][e],j[4*e]=255&(q[d[e]>>24&255]^h>>24),j[4*e+1]=255&(q[d[(e+3)%4]>>16&255]^h>>16),j[4*e+2]=255&(q[d[(e+2)%4]>>8&255]^h>>8),j[4*e+3]=255&(q[255&d[(e+1)%4]]^h);return j};var E=function(a){if(!(this instanceof E))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new D(a)};E.prototype.encrypt=function(a){if(a=f(a),a.length%16!==0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var b=g(a.length),c=g(16),d=0;d<a.length;d+=16)h(a,c,0,d,d+16),c=this._aes.encrypt(c),h(c,b,d);return b},E.prototype.decrypt=function(a){if(a=f(a),a.length%16!==0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var b=g(a.length),c=g(16),d=0;d<a.length;d+=16)h(a,c,0,d,d+16),c=this._aes.decrypt(c),h(c,b,d);return b};var F=function(a,b){if(!(this instanceof F))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",b){if(16!=b.length)throw new Error("invalid initialation vector size (must be 16 bytes)")}else b=g(16);this._lastCipherblock=f(b,!0),this._aes=new D(a)};F.prototype.encrypt=function(a){if(a=f(a),a.length%16!==0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var b=g(a.length),c=g(16),d=0;d<a.length;d+=16){h(a,c,0,d,d+16);for(var e=0;e<16;e++)c[e]^=this._lastCipherblock[e];this._lastCipherblock=this._aes.encrypt(c),h(this._lastCipherblock,b,d)}return b},F.prototype.decrypt=function(a){if(a=f(a),a.length%16!==0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var b=g(a.length),c=g(16),d=0;d<a.length;d+=16){h(a,c,0,d,d+16),c=this._aes.decrypt(c);for(var e=0;e<16;e++)b[d+e]=c[e]^this._lastCipherblock[e];h(a,this._lastCipherblock,0,d,d+16)}return b};var G=function(a,b,c){if(!(this instanceof G))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",b){if(16!=b.length)throw new Error("invalid initialation vector size (must be 16 size)")}else b=g(16);c||(c=1),this.segmentSize=c,this._shiftRegister=f(b,!0),this._aes=new D(a)};G.prototype.encrypt=function(a){if(a.length%
c[2*g]=8191&f,f>>>=13,c[2*g+1]=8191&f,f>>>=13;for(g=2*b;g<e;++g)c[g]=0;d(0===f),d(0===(f&-8192))},m.prototype.stub=function(a){for(var b=new Array(a),c=0;c<a;c++)b[c]=0;return b},m.prototype.mulp=function(a,b,c){var d=2*this.guessLen13b(a.length,b.length),e=this.makeRBT(d),f=this.stub(d),g=new Array(d),h=new Array(d),i=new Array(d),j=new Array(d),k=new Array(d),l=new Array(d),m=c.words;m.length=d,this.convert13b(a.words,a.length,g,d),this.convert13b(b.words,b.length,j,d),this.transform(g,f,h,i,d,e),this.transform(j,f,k,l,d,e);for(var n=0;n<d;n++){var o=h[n]*k[n]-i[n]*l[n];i[n]=h[n]*l[n]+i[n]*k[n],h[n]=o}return this.conjugate(h,i,d),this.transform(h,i,m,f,d,e),this.conjugate(m,f,d),this.normalize13b(m,d),c.negative=a.negative^b.negative,c.length=a.length+b.length,c.strip()},f.prototype.mul=function(a){var b=new f(null);return b.words=new Array(this.length+a.length),this.mulTo(a,b)},f.prototype.mulf=function(a){var b=new f(null);return b.words=new Array(this.length+a.length),l(this,a,b)},f.prototype.imul=function(a){return this.clone().mulTo(a,this)},f.prototype.imuln=function(a){d("number"==typeof a),d(a<67108864);for(var b=0,c=0;c<this.length;c++){var e=(0|this.words[c])*a,f=(67108863&e)+(67108863&b);b>>=26,b+=e/67108864|0,b+=f>>>26,this.words[c]=67108863&f}return 0!==b&&(this.words[c]=b,this.length++),this},f.prototype.muln=function(a){return this.clone().imuln(a)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(a){var b=i(a);if(0===b.length)return new f(1);for(var c=this,d=0;d<b.length&&0===b[d];d++,c=c.sqr());if(++d<b.length)for(var e=c.sqr();d<b.length;d++,e=e.sqr())0!==b[d]&&(c=c.mul(e));return c},f.prototype.iushln=function(a){d("number"==typeof a&&a>=0);var b,c=a%26,e=(a-c)/26,f=67108863>>>26-c<<26-c;if(0!==c){var g=0;for(b=0;b<this.length;b++){var h=this.words[b]&f,i=(0|this.words[b])-h<<c;this.words[b]=i|g,g=h>>>26-c}g&&(this.words[b]=g,this.length++)}if(0!==e){for(b=this.length-1;b>=0;b--)this.words[b+e]=this.words[b];for(b=0;b<e;b++)this.words[b]=0;this.length+=e}return this.strip()},f.prototype.ishln=function(a){return d(0===this.negative),this.iushln(a)},f.prototype.iushrn=function(a,b,c){d("number"==typeof a&&a>=0);var e;e=b?(b-b%26)/26:0;var f=a%26,g=Math.min((a-f)/26,this.length),h=67108863^67108863>>>f<<f,i=c;if(e-=g,e=Math.max(0,e),i){for(var j=0;j<g;j++)i.words[j]=this.words[j];i.length=g}if(0===g);else if(this.length>g)for(this.length-=g,j=0;j<this.length;j++)this.words[j]=this.words[j+g];else this.words[0]=0,this.length=1;var k=0;for(j=this.length-1;j>=0&&(0!==k||j>=e);j--){var l=0|this.words[j];this.words[j]=k<<26-f|l>>>f,k=l&h}return i&&0!==k&&(i.words[i.length++]=k),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(a,b,c){return d(0===this.negative),this.iushrn(a,b,c)},f.prototype.shln=function(a){return this.clone().ishln(a)},f.prototype.ushln=function(a){return this.clone().iushln(a)},f.prototype.shrn=function(a){return this.clone().ishrn(a)},f.prototype.ushrn=function(a){return this.clone().iushrn(a)},f.prototype.testn=function(a){d("number"==typeof a&&a>=0);var b=a%26,c=(a-b)/26,e=1<<b;if(this.length<=c)return!1;var f=this.words[c];return!!(f&e)},f.prototype.imaskn=function(a){d("number"==typeof a&&a>=0);var b=a%26,c=(a-b)/26;if(d(0===this.negative,"imaskn works only with positive numbers"),this.length<=c)return this;if(0!==b&&c++,this.length=Math.min(c,this.length),0!==b){var e=67108863^67108863>>>b<<b;this.words[this.length-1]&=e}return this.strip()},f.prototype.maskn=function(a){return this.clone().imaskn(a)},f.prototype.iaddn=function(a){return d("number"==typeof a),d(a<67108864),a<0?this.isubn(-a):0!==this.negative?1===this.length&&(0|this.words[0])<a?(this.words[0]=a-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(a),this.negative=1,this):this._iaddn(a)},f.prototype._iaddn=function(a){this.words[0]+=a;for(var b=0;b<this.length&&this.words[b]>=67108864;b++)this.words[b]-=67108864,b===this.length-1?this.words[b+1]=1:this.words[b+1]++;return thi
return this.curve.jpoint(l,m,n)},f.prototype.dblp=function(a){if(0===a)return this;if(this.isInfinity())return this;if(!a)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var b=this,c=0;c<a;c++)b=b.dbl();return b}for(var d=this.curve.a,e=this.curve.tinv,f=this.x,g=this.y,h=this.z,i=h.redSqr().redSqr(),j=g.redAdd(g),c=0;c<a;c++){var k=f.redSqr(),l=j.redSqr(),m=l.redSqr(),n=k.redAdd(k).redIAdd(k).redIAdd(d.redMul(i)),o=f.redMul(l),p=n.redSqr().redISub(o.redAdd(o)),q=o.redISub(p),r=n.redMul(q);r=r.redIAdd(r).redISub(m);var s=j.redMul(h);c+1<a&&(i=i.redMul(m)),f=p,h=s,j=r}return this.curve.jpoint(f,j.redMul(e),h)},f.prototype.dbl=function(){return this.isInfinity()?this:this.curve.zeroA?this._zeroDbl():this.curve.threeA?this._threeDbl():this._dbl()},f.prototype._zeroDbl=function(){var a,b,c;if(this.zOne){var d=this.x.redSqr(),e=this.y.redSqr(),f=e.redSqr(),g=this.x.redAdd(e).redSqr().redISub(d).redISub(f);g=g.redIAdd(g);var h=d.redAdd(d).redIAdd(d),i=h.redSqr().redISub(g).redISub(g),j=f.redIAdd(f);j=j.redIAdd(j),j=j.redIAdd(j),a=i,b=h.redMul(g.redISub(i)).redISub(j),c=this.y.redAdd(this.y)}else{var k=this.x.redSqr(),l=this.y.redSqr(),m=l.redSqr(),n=this.x.redAdd(l).redSqr().redISub(k).redISub(m);n=n.redIAdd(n);var o=k.redAdd(k).redIAdd(k),p=o.redSqr(),q=m.redIAdd(m);q=q.redIAdd(q),q=q.redIAdd(q),a=p.redISub(n).redISub(n),b=o.redMul(n.redISub(a)).redISub(q),c=this.y.redMul(this.z),c=c.redIAdd(c)}return this.curve.jpoint(a,b,c)},f.prototype._threeDbl=function(){var a,b,c;if(this.zOne){var d=this.x.redSqr(),e=this.y.redSqr(),f=e.redSqr(),g=this.x.redAdd(e).redSqr().redISub(d).redISub(f);g=g.redIAdd(g);var h=d.redAdd(d).redIAdd(d).redIAdd(this.curve.a),i=h.redSqr().redISub(g).redISub(g);a=i;var j=f.redIAdd(f);j=j.redIAdd(j),j=j.redIAdd(j),b=h.redMul(g.redISub(i)).redISub(j),c=this.y.redAdd(this.y)}else{var k=this.z.redSqr(),l=this.y.redSqr(),m=this.x.redMul(l),n=this.x.redSub(k).redMul(this.x.redAdd(k));n=n.redAdd(n).redIAdd(n);var o=m.redIAdd(m);o=o.redIAdd(o);var p=o.redAdd(o);a=n.redSqr().redISub(p),c=this.y.redAdd(this.z).redSqr().redISub(l).redISub(k);var q=l.redSqr();q=q.redIAdd(q),q=q.redIAdd(q),q=q.redIAdd(q),b=n.redMul(o.redISub(a)).redISub(q)}return this.curve.jpoint(a,b,c)},f.prototype._dbl=function(){var a=this.curve.a,b=this.x,c=this.y,d=this.z,e=d.redSqr().redSqr(),f=b.redSqr(),g=c.redSqr(),h=f.redAdd(f).redIAdd(f).redIAdd(a.redMul(e)),i=b.redAdd(b);i=i.redIAdd(i);var j=i.redMul(g),k=h.redSqr().redISub(j.redAdd(j)),l=j.redISub(k),m=g.redSqr();m=m.redIAdd(m),m=m.redIAdd(m),m=m.redIAdd(m);var n=h.redMul(l).redISub(m),o=c.redAdd(c).redMul(d);return this.curve.jpoint(k,n,o)},f.prototype.trpl=function(){if(!this.curve.zeroA)return this.dbl().add(this);var a=this.x.redSqr(),b=this.y.redSqr(),c=this.z.redSqr(),d=b.redSqr(),e=a.redAdd(a).redIAdd(a),f=e.redSqr(),g=this.x.redAdd(b).redSqr().redISub(a).redISub(d);g=g.redIAdd(g),g=g.redAdd(g).redIAdd(g),g=g.redISub(f);var h=g.redSqr(),i=d.redIAdd(d);i=i.redIAdd(i),i=i.redIAdd(i),i=i.redIAdd(i);var j=e.redIAdd(g).redSqr().redISub(f).redISub(h).redISub(i),k=b.redMul(j);k=k.redIAdd(k),k=k.redIAdd(k);var l=this.x.redMul(h).redISub(k);l=l.redIAdd(l),l=l.redIAdd(l);var m=this.y.redMul(j.redMul(i.redISub(j)).redISub(g.redMul(h)));m=m.redIAdd(m),m=m.redIAdd(m),m=m.redIAdd(m);var n=this.z.redAdd(g).redSqr().redISub(c).redISub(h);return this.curve.jpoint(l,m,n)},f.prototype.mul=function(a,b){return a=new i(a,b),this.curve._wnafMul(this,a)},f.prototype.eq=function(a){if("affine"===a.type)return this.eq(a.toJ());if(this===a)return!0;var b=this.z.redSqr(),c=a.z.redSqr();if(0!==this.x.redMul(c).redISub(a.x.redMul(b)).cmpn(0))return!1;var d=b.redMul(this.z),e=c.redMul(a.z);return 0===this.y.redMul(e).redISub(a.y.redMul(d)).cmpn(0)},f.prototype.eqXToP=function(a){var b=this.z.redSqr(),c=a.toRed(this.curve.red).redMul(b);if(0===this.x.cmp(c))return!0;for(var d=a.clone(),e=this.curve.redN.redMul(b);;){if(d.iadd(this.curve.n),d.cmp(this.curve.p)>=0)return!1;if(c.redIAdd(e),0===this.x.cmp(c))return!0}return!1},f.prototype.inspect=function(){return this.isInfinity()?"<EC JPoint Infin
2017-07-06 03:30:28 +03:00
e=5}if(c+e>a.length){for(;c<a.length&&a[c]>>6==2;c++);if(c!=a.length)continue;return b}var g,h=d&(1<<8-e-1)-1;for(g=0;g<e;g++){var i=a[c++];if(i>>6!=2)break;h=h<<6|63&i}g==e?h<=65535?b+=String.fromCharCode(h):(h-=65536,b+=String.fromCharCode((h>>10&1023)+55296,(1023&h)+56320)):c--}}else b+=String.fromCharCode(d)}return b}var f=a("./convert.js");b.exports={toUtf8Bytes:d,toUtf8String:e}},{"./convert.js":26}],38:[function(a,b,c){var d=c;d.utils=a("./hash/utils"),d.common=a("./hash/common"),d.sha=a("./hash/sha"),d.ripemd=a("./hash/ripemd"),d.hmac=a("./hash/hmac"),d.sha1=d.sha.sha1,d.sha256=d.sha.sha256,d.sha224=d.sha.sha224,d.sha384=d.sha.sha384,d.sha512=d.sha.sha512,d.ripemd160=d.ripemd.ripemd160},{"./hash/common":39,"./hash/hmac":40,"./hash/ripemd":41,"./hash/sha":42,"./hash/utils":43}],39:[function(a,b,c){function d(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}var e=a("../hash"),f=e.utils,g=f.assert;c.BlockHash=d,d.prototype.update=function(a,b){if(a=f.toArray(a,b),this.pending?this.pending=this.pending.concat(a):this.pending=a,this.pendingTotal+=a.length,this.pending.length>=this._delta8){a=this.pending;var c=a.length%this._delta8;this.pending=a.slice(a.length-c,a.length),0===this.pending.length&&(this.pending=null),a=f.join32(a,0,a.length-c,this.endian);for(var d=0;d<a.length;d+=this._delta32)this._update(a,d,d+this._delta32)}return this},d.prototype.digest=function(a){return this.update(this._pad()),g(null===this.pending),this._digest(a)},d.prototype._pad=function(){var a=this.pendingTotal,b=this._delta8,c=b-(a+this.padLength)%b,d=new Array(c+this.padLength);d[0]=128;for(var e=1;e<c;e++)d[e]=0;if(a<<=3,"big"===this.endian){for(var f=8;f<this.padLength;f++)d[e++]=0;d[e++]=0,d[e++]=0,d[e++]=0,d[e++]=0,d[e++]=a>>>24&255,d[e++]=a>>>16&255,d[e++]=a>>>8&255,d[e++]=255&a}else{d[e++]=255&a,d[e++]=a>>>8&255,d[e++]=a>>>16&255,d[e++]=a>>>24&255,d[e++]=0,d[e++]=0,d[e++]=0,d[e++]=0;for(var f=8;f<this.padLength;f++)d[e++]=0}return d}},{"../hash":38}],40:[function(a,b,c){function d(a,b,c){return this instanceof d?(this.Hash=a,this.blockSize=a.blockSize/8,this.outSize=a.outSize/8,this.inner=null,this.outer=null,void this._init(f.toArray(b,c))):new d(a,b,c)}var e=a("../hash"),f=e.utils,g=f.assert;b.exports=d,d.prototype._init=function(a){a.length>this.blockSize&&(a=(new this.Hash).update(a).digest()),g(a.length<=this.blockSize);for(var b=a.length;b<this.blockSize;b++)a.push(0);for(var b=0;b<a.length;b++)a[b]^=54;this.inner=(new this.Hash).update(a);for(var b=0;b<a.length;b++)a[b]^=106;this.outer=(new this.Hash).update(a)},d.prototype.update=function(a,b){return this.inner.update(a,b),this},d.prototype.digest=function(a){return this.outer.update(this.inner.digest()),this.outer.digest(a)}},{"../hash":38}],41:[function(a,b,c){b.exports={ripemd160:null}},{}],42:[function(a,b,c){function d(){return this instanceof d?(V.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=W,void(this.W=new Array(64))):new d}function e(){return this instanceof e?(d.call(this),void(this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])):new e}function f(){return this instanceof f?(V.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=X,void(this.W=new Array(160))):new f}function g(){return this instanceof g?(f.call(this),void(this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428])):new g}function h(){return this instanceof h?(V.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],void(this.W=new Array(80))):new h}function i(a,
2017-10-20 22:44:54 +03:00
r=g.padding.pkcs7.strip(r);for(var s="",t=0;t<r.length;t++)s+=String.fromCharCode(r[t]);var u=l.toUtf8Bytes(s),v=new m(l.keccak256(u));if(v.address!==h)throw new Error("corrupt crowdsale wallet");return v}),l.defineProperty(n,"decrypt",function(a,b,c){var i=JSON.parse(a);b=e(b);var n=function(a,b){var c=f(i,"crypto/cipher");if("aes-128-ctr"===c){var e=d(f(i,"crypto/cipherparams/iv"),"crypto/cipherparams/iv"),h=new g.Counter(e),j=new g.ModeOfOperation.ctr(a,h);return new d(j.decrypt(b))}return null},o=function(a,b){return l.keccak256(l.concat([a,b]))},p=function(a,b){var c=d(f(i,"crypto/ciphertext")),e=l.hexlify(o(a.slice(16,32),c)).substring(2);if(e!==f(i,"crypto/mac").toLowerCase())return b(new Error("invalid password")),null;var g=n(a.slice(0,16),c);if(!g)return b(new Error("unsupported cipher")),null;var h=new m(g);return h.address!==l.getAddress(i.address)?(b(new Error("address mismatch")),null):h};return new Promise(function(a,e){var g=f(i,"crypto/kdf");if(g&&"string"==typeof g)if("scrypt"===g.toLowerCase()){var l=d(f(i,"crypto/kdfparams/salt"),"crypto/kdfparams/salt"),m=parseInt(f(i,"crypto/kdfparams/n")),n=parseInt(f(i,"crypto/kdfparams/r")),o=parseInt(f(i,"crypto/kdfparams/p"));if(!m||!n||!o)return void e(new Error("unsupported key-derivation function parameters"));if(0!==(m&m-1))return void e(new Error("unsupported key-derivation function parameter value for N"));var q=parseInt(f(i,"crypto/kdfparams/dklen"));if(32!==q)return void e(new Error("unsupported key-derivation derived-key length"));h(b,l,m,n,o,q,function(b,f,g){if(b)b.progress=f,e(b);else if(g){g=d(g);var h=p(g,e);if(!h)return;c&&c(1),a(h)}else if(c)return c(f)})}else if("pbkdf2"===g.toLowerCase()){var l=d(f(i,"crypto/kdfparams/salt"),"crypto/kdfparams/salt"),r=null,s=f(i,"crypto/kdfparams/prf");if("hmac-sha256"===s)r=j.createSha256Hmac;else{if("hmac-sha512"!==s)return void e(new Error("unsupported prf"));r=j.createSha512Hmac}var t=parseInt(f(i,"crypto/kdfparams/c")),q=parseInt(f(i,"crypto/kdfparams/dklen"));if(32!==q)return void e(new Error("unsupported key-derivation derived-key length"));var u=k(b,l,t,q,r),v=p(u,e);if(!v)return;a(v)}else e(new Error("unsupported key-derivation function"));else e(new Error("unsupported key-derivation function"))})}),l.defineProperty(n,"encrypt",function(a,b,c,f){if("function"!=typeof c||f||(f=c,c={}),c||(c={}),a instanceof m&&(a=a.privateKey),a=l.arrayify(a,"private key"),32!==a.length)throw new Erro("invalid private key");b=e(b);var j=c.salt;j=j?d(j,"salt"):l.randomBytes(32);var k=null;if(c.iv&&(k=d(c.iv,"iv"),16!==k.length))throw new Error("invalid iv");var n=c.uuid;if(n&&(n=l.arrayify(n,"uuid"),16!==n.length))throw new Error("invalid uuid");var o=1<<17,p=8,q=1;return c.scrypt&&(c.scrypt.N&&(o=c.scrypt.N),c.scrypt.r&&(p=c.scrypt.r),c.scrypt.p&&(q=c.scrypt.p)),new Promise(function(c,e){h(b,j,o,p,q,64,function(b,h,r){if(b)b.progress=h,e(b);else if(r){r=d(r);var s=r.slice(0,16),t=r.slice(16,32);k||(k=r.slice(32,48)),n||(n=r.slice(48,64));var u=new m(a).address,v=new g.Counter(k),w=new g.ModeOfOperation.ctr(s,v),x=l.arrayify(w.encrypt(a)),y=l.keccak256(l.concat([t,x])),z={address:u.substring(2).toLowerCase(),id:i.v4({random:n}),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:l.hexlify(k).substring(2)},ciphertext:l.hexlify(x).substring(2),kdf:"scrypt",kdfparams:{salt:l.hexlify(j).substring(2),n:o,dklen:32,p:q,r:p},mac:y.substring(2)}};f&&f(1),c(JSON.stringify(z))}else if(f)return f(h)})})}),b.exports=n},{"./signing-key.js":51,"aes-js":4,"ethers-utils":28,"ethers-utils/hmac":27,"ethers-utils/pbkdf2":30,"scrypt-js":46,uuid:49}],51:[function(a,b,c){"use strict";function d(a){if(!(this instanceof d))throw new Error("missing new");if(a=f.arrayify(a),32!==a.length)throw new Error("invalid private key");f.defineProperty(this,"privateKey",f.hexlify(a));var b=e.keyFromPrivate(a);f.defineProperty(this,"publicKey","0x"+b.getPublic(!0,"hex"));var c=d.publicKeyToAddress("0x"+b.getPublic(!1,"hex"));f.defineProperty(this,"address",c),f.defineProperty(this,"signDigest",function(a){var c=b.sign(f.arrayify(a),{canonical:!0});retu