crypto-addr-codec
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -1,2 +0,2 @@ | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var r=require("sha3"),e=t(require("base-x")),n=require("safe-buffer"),i=t(require("big-integer")),o=t(require("bs58")),f=require("ripemd160-min"),u=require("blakejs/blake2b"),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",a=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],h=function(t){for(var r=new ArrayBuffer(5*t.length/8),e=new Uint8Array(r),n=0;n<t.length/8;n++){for(var i=[0,0,0,0,0,0,0,0],o=0;o<8;++o)i[o]=s.indexOf(t[8*n+o]);e[5*n+0]=i[0]<<3|i[1]>>2,e[5*n+1]=(3&i[1])<<6|i[2]<<1|i[3]>>4,e[5*n+2]=(15&i[3])<<4|i[4]>>1,e[5*n+3]=(1&i[4])<<7|i[5]<<2|i[6]>>3,e[5*n+4]=(7&i[6])<<5|i[7]}return e};function c(t,r){this._block=n.Buffer.alloc(t),this._finalSize=r,this._blockSize=t,this._len=0}c.prototype.update=function(t,r){"string"==typeof t&&(t=n.Buffer.from(t,r=r||"utf8"));for(var e=this._block,i=this._blockSize,o=t.length,f=this._len,u=0;u<o;){for(var s=f%i,a=Math.min(o-u,i-s),h=0;h<a;h++)e[s+h]=t[u+h];u+=a,(f+=a)%i==0&&this._update(e)}return this._len+=o,this},c.prototype.digest=function(t){var r=this._len%this._blockSize;this._block[r]=128,this._block.fill(0,r+1),r>=this._finalSize&&(this._update(this._block),this._block.fill(0));var e=8*this._len;if(e<=4294967295)this._block.writeUInt32BE(e,this._blockSize-4);else{var n=(4294967295&e)>>>0;this._block.writeUInt32BE((e-n)/4294967296,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var i=this._hash();return t?i.toString(t):i},c.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var l,d,p=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],v=new Array(64);function y(){this.init(),this._w=v,c.call(this,64,56)}function g(t,r,e){return e^t&(r^e)}function w(t,r,e){return t&r|e&(t|r)}function m(t){return(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10)}function b(t){return(t>>>6|t<<26)^(t>>>11|t<<21)^(t>>>25|t<<7)}function _(t){return(t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3}function x(t){return void 0!==t.length}l=y,(d=c)&&(l.super_=d,l.prototype=Object.create(d.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}})),y.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},y.prototype._update=function(t){for(var r,e=this._w,n=0|this._a,i=0|this._b,o=0|this._c,f=0|this._d,u=0|this._e,s=0|this._f,a=0|this._g,h=0|this._h,c=0;c<16;++c)e[c]=t.readInt32BE(4*c);for(;c<64;++c)e[c]=0|(((r=e[c-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10)+e[c-7]+_(e[c-15])+e[c-16];for(var l=0;l<64;++l){var d=h+b(u)+g(u,s,a)+p[l]+e[l]|0,v=m(n)+w(n,i,o)|0;h=a,a=s,s=u,u=f+d|0,f=o,o=i,i=n,n=d+v|0}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=f+this._d|0,this._e=u+this._e|0,this._f=s+this._f|0,this._g=a+this._g|0,this._h=h+this._h|0},y.prototype._hash=function(){var t=n.Buffer.allocUnsafe(32);return t.writeInt32BE(this._a,0),t.writeInt32BE(this._b,4),t.writeInt32BE(this._c,8),t.writeInt32BE(this._d,12),t.writeInt32BE(this._e,16),t.writeInt32BE(this._f,20),t.writeInt32BE(this._g,24),t.writeInt32BE(this._h,28),t};var E=new(function(){function t(t){this.sha256=t.sha256,this.alphabet=t.alphabet,this.codec=e(this.alphabet),this.base=this.alphabet.length}var r=t.prototype;return r.encodeChecked=function(t){var r=this.sha256(this.sha256(t)).slice(0,4);return this.encodeRaw(Buffer.from(function(){for(var t=[],r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return e.forEach(function(r){if(x(r))for(var e=0;e<r.length;e++)t.push(r[e]);else t.push(r)}),t}(t,r)))},r.encodeRaw=function(t){return this.codec.encode(t)},r.decodeChecked=function(t){var r=this.decodeRaw(t);if(r.length<5)throw new Error("invalid_input_size: decoded data must have length >= 5");if(!this.verifyCheckSum(r))throw new Error("checksum_invalid");return r.slice(0,-4)},r.decodeRaw=function(t){return this.codec.decode(t)},r.verifyCheckSum=function(t){return function(t,r){if(t.length!==r.length)return!1;for(var e=0;e<t.length;e++)if(t[e]!==r[e])return!1;return!0}(this.sha256(this.sha256(t.slice(0,-4))).slice(0,4),t.slice(-4))},t}())({sha256:function(t){return(new y).update(Buffer.from(t)).digest()},alphabet:"rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"}),I=function(t){return"0x"===t.slice(0,2)?t.slice(2):t},B=function(t,e){if(void 0===e&&(e=null),"string"!=typeof t)throw new Error("stripHexPrefix param must be type 'string', is currently type "+typeof t+".");for(var n,i=I(t).toLowerCase(),o=(n=(null!=e?e.toString()+"0x":"")+i,new r.Keccak(256).update(n).digest()).toString("hex"),f="0x",u=0;u<i.length;u++)f+=parseInt(o[u],16)>=8?i[u].toUpperCase():i[u];return f},A=function(t,r){if(!t)throw r},S=function(t,r){if(!Buffer.isBuffer(t))throw r},k=i.one,z=i.zero,C=i(3);function O(t,r){return t.and(k.shiftLeft(r)).notEquals(z)}function U(t){return i.fromArray(Array.prototype.slice.call(t,0),256)}function P(t,r){var e=t.toArray(256).value,n=r?Math.max(r-e.length,0):0;return Buffer.from([].concat(Array(n).fill(0),e))}function q(t,r,e,n){A(void 0!==n,"Missing Z coordinate"),this.curve=t,this.x=r,this.y=e,this.z=n,this._zInv=null,this.compressed=!0}Object.defineProperty(q.prototype,"zInv",{get:function(){return null===this._zInv&&(this._zInv=this.z.modInv(this.curve.p)),this._zInv}}),Object.defineProperty(q.prototype,"affineX",{get:function(){return this.x.multiply(this.zInv).mod(this.curve.p)}}),Object.defineProperty(q.prototype,"affineY",{get:function(){return this.y.multiply(this.zInv).mod(this.curve.p)}}),q.fromAffine=function(t,r,e){return new q(t,r,e,k)},q.prototype.equals=function(t){return t===this||(this.curve.isInfinity(this)?this.curve.isInfinity(t):this.curve.isInfinity(t)?this.curve.isInfinity(this):0===t.y.multiply(this.z).subtract(this.y.multiply(t.z)).mod(this.curve.p).compare(z)&&0===t.x.multiply(this.z).subtract(this.x.multiply(t.z)).mod(this.curve.p).compare(z))},q.prototype.negate=function(){var t=this.curve.p.subtract(this.y);return new q(this.curve,this.x,t,this.z)},q.prototype.add=function(t){if(this.curve.isInfinity(this))return t;if(this.curve.isInfinity(t))return this;var r=this.x,e=this.y,n=t.x,i=t.y.multiply(this.z).subtract(e.multiply(t.z)).mod(this.curve.p),o=n.multiply(this.z).subtract(r.multiply(t.z)).mod(this.curve.p);if(0===o.compare(z))return 0===i.compare(z)?this.twice():this.curve.infinity;var f=o.square(),u=f.multiply(o),s=r.multiply(f),a=i.square().multiply(this.z),h=a.subtract(s.shiftLeft(1)).multiply(t.z).subtract(u).multiply(o).mod(this.curve.p),c=s.multiply(C).multiply(i).subtract(e.multiply(u)).subtract(a.multiply(i)).multiply(t.z).add(i.multiply(u)).mod(this.curve.p),l=u.multiply(this.z).multiply(t.z).mod(this.curve.p);return new q(this.curve,h,c,l)},q.prototype.twice=function(){if(this.curve.isInfinity(this))return this;if(0===this.y.compare(z))return this.curve.infinity;var t=this.x,r=this.y,e=r.multiply(this.z).mod(this.curve.p),n=e.multiply(r).mod(this.curve.p),i=this.curve.a,o=t.square().multiply(C);0!==i.compare(z)&&(o=o.add(this.z.square().multiply(i)));var f=(o=o.mod(this.curve.p)).square().subtract(t.shiftLeft(3).multiply(n)).shiftLeft(1).multiply(e).mod(this.curve.p),u=o.multiply(C).multiply(t).subtract(n.shiftLeft(1)).shiftLeft(2).multiply(n).subtract(o.pow(3)).mod(this.curve.p),s=e.pow(3).shiftLeft(3).mod(this.curve.p);return new q(this.curve,f,u,s)},q.prototype.multiply=function(t){if(this.curve.isInfinity(this))return this;if(0===t.compare(z))return this.curve.infinity;for(var r=t,e=r.multiply(C),n=this.negate(),i=this,o=e.bitLength()-2;o>0;--o){var f=O(e,o),u=O(r,o);i=i.twice(),f!==u&&(i=i.add(f?this:n))}return i},q.prototype.multiplyTwo=function(t,r,e){for(var n=Math.max(t.bitLength(),e.bitLength())-1,i=this.curve.infinity,o=this.add(r);n>=0;){var f=O(t,n),u=O(e,n);i=i.twice(),f?i=i.add(u?o:this):u&&(i=i.add(r)),--n}return i},q.prototype.getEncoded=function(t){if(null==t&&(t=this.compressed),this.curve.isInfinity(this))return new Buffer("00","hex");var r,e=this.affineX,n=this.affineY,i=this.curve.pLength;return t?(r=new Buffer(1+i)).writeUInt8(n.isEven()?2:3,0):((r=new Buffer(1+i+i)).writeUInt8(4,0),P(n,i).copy(r,1+i)),P(e,i).copy(r,1),r},q.decodeFrom=function(t,r){var e,n=r.readUInt8(0),i=4!==n,o=Math.floor((t.p.bitLength()+7)/8),f=U(r.slice(1,1+o));if(i)A(r.length===o+1,"Invalid sequence length"),A(2===n||3===n,"Invalid sequence tag"),e=t.pointFromX(3===n,f);else{A(r.length===1+o+o,"Invalid sequence length");var u=U(r.slice(1+o));e=q.fromAffine(t,f,u)}return e.compressed=i,e},q.prototype.toString=function(){return this.curve.isInfinity(this)?"(INFINITY)":"("+this.affineX.toString()+","+this.affineY.toString()+")"};var L=i.zero,j=i.one;function R(t,r,e,n,i,o,f){this.p=t,this.a=r,this.b=e,this.G=q.fromAffine(this,n,i),this.n=o,this.h=f,this.infinity=new q(this,null,null,L),this.pOverFour=t.add(j).shiftRight(2),this.pLength=Math.floor((this.p.bitLength()+7)/8)}R.prototype.pointFromX=function(t,r){var e=r.pow(3).add(this.a.multiply(r)).add(this.b).mod(this.p).modPow(this.pOverFour,this.p),n=e;return e.isEven()^!t&&(n=this.p.subtract(n)),q.fromAffine(this,r,n)},R.prototype.isInfinity=function(t){return t===this.infinity||0===t.z.compare(L)&&0!==t.y.compare(L)},R.prototype.isOnCurve=function(t){if(this.isInfinity(t))return!0;var r=t.affineX,e=t.affineY,n=this.a,i=this.b,o=this.p;if(r.compare(L)<0||r.compareTo(o)>=0)return!1;if(e.compare(L)<0||e.compareTo(o)>=0)return!1;var f=e.square().mod(o),u=r.pow(3).add(n.multiply(r)).add(i).mod(o);return f.equals(u)},R.prototype.validate=function(t){A(!this.isInfinity(t),"Point is at infinity"),A(this.isOnCurve(t),"Point is not on the curve");var r=t.multiply(this.n);return A(this.isInfinity(r),"Point is not a scalar multiple of G"),!0};var M={p:"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",a:"00",b:"07",n:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",h:"01",Gx:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",Gy:"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"};function F(t,e){return new r.SHA3(256).update(t).digest(e)}function T(t){return Buffer.from((new f.RIPEMD160).update(t).digest())}function D(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(S(t,"expecting keyBuffer<Buffer>"),"sha256x2"===r){var e=F(F(t)).slice(0,4);return o.encode(Buffer.concat([t,e]))}var n=[t];r&&n.push(Buffer.from(r));var i=T(Buffer.concat(n)).slice(0,4);return o.encode(Buffer.concat([t,i]))}function H(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;A(t,"private key expected");var e,n=new Buffer(o.decode(t)),i=n.slice(-4),f=n.slice(0,-4);if("sha256x2"===r)e=F(F(f)).slice(0,4);else{var u=[f];r&&u.push(Buffer.from(r)),e=T(Buffer.concat(u)).slice(0,4)}if(i.toString("hex")!==e.toString("hex"))throw new Error("Invalid checksum, "+"".concat(i.toString("hex")," != ").concat(e.toString("hex")));return f}var G=function(t){var r=M;if(!r)return null;var e=i(r.p,16),n=i(r.a,16),o=i(r.b,16),f=i(r.n,16),u=i(r.h,16);return new R(e,n,o,i(r.Gx,16),i(r.Gy,16),f,u)}();function N(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS";if("string"==typeof t)return N.fromString(t,r);if(Buffer.isBuffer(t))return N.fromBuffer(t);if("object"==typeof t&&t.Q)return N(t.Q);function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.compressed;return t.getEncoded(r)}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"EOS";return t+D(e())}function i(){return e().toString("hex")}return{Q:t,toString:n,toBuffer:e,toHex:i}}N.isValid=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS";try{return N(t,r),!0}catch(t){return!1}},N.fromBuffer=function(t){return N(q.decodeFrom(G,t))},N.fromString=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS";try{return N.fromStringOrThrow(t,r)}catch(t){return null}},N.fromStringOrThrow=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS",e=t.match(/^PUB_([A-Za-z0-9]+)_([A-Za-z0-9]+)$/);if(null===e){var n=new RegExp("^"+r);return n.test(t)&&(t=t.substring(r.length)),N.fromBuffer(H(t))}var i=e[1],o=e[2];return N.fromBuffer(H(o,i))},N.fromHex=function(t){return N.fromBuffer(new Buffer(t,"hex"))},N.fromStringHex=function(t){return N.fromString(new Buffer(t,"hex"))};var X=e("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),K=X.encode,Y=X.decode,V=function(t){return void 0===t},Q={ed25519PublicKey:48,ed25519SecretSeed:144,preAuthTx:152,sha256Hash:184},Z=function(t){var r=Buffer.alloc(2);return r.writeUInt16LE(function(t,r){Buffer.isBuffer(t)||(t=new Buffer);for(var e=0,n=0;n<t.length;n++){var i=e>>>8&255;i^=255&t[n],e=e<<8&65535,e^=i^=i>>>4,e^=i=i<<5&65535,e^=i=i<<7&65535}return e}(t),0),r};function J(t){return(J=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function W(t,r){return(W=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function $(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function tt(t,r,e){return(tt=$()?Reflect.construct:function(t,r,e){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(t,n));return e&&W(i,e.prototype),i}).apply(null,arguments)}function rt(t){var r="function"==typeof Map?new Map:void 0;return(rt=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return tt(t,arguments,J(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),W(e,t)})(t)}var et=[0,1,2,42,43,68,69],nt=function(t){for(var r=new Uint8Array(t.length),e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return r}("SS58PRE"),it=function(t){var r,e;function n(){return t.apply(this,arguments)||this}return e=t,(r=n).prototype=Object.create(e.prototype),r.prototype.constructor=r,r.__proto__=e,n.prototype.toJSON=function(){return{_type:"AccountIndex",data:this+0}},n}(rt(Number));function ot(t,r){t.length||(t=[t]),r.length||(r=[r]);var e=new Uint8Array(t.length+r.length);return e.set(t),e.set(r,t.length),e}function ft(t){var r=new Error;this.name=r.name="ValidationError",this.message=r.message=t,this.stack=r.stack}function ut(t,r){if(null==r&&(r="Assertion failed."),!t)throw new ft(r)}ft.prototype=Object.create(Error.prototype);var st=function(){function t(t,r){this.hi=0|t,this.lo=0|r}return t.prototype.ushrn32=function(t){var r=this.lo;return 0==(t&=63)||(t<32?(r>>>=t,r|=this.hi<<32-t):r=this.hi>>>t-32),r},t}(),at=Buffer.allocUnsafe(105),ht="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ct=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,15,-1,10,17,21,20,26,30,7,5,-1,-1,-1,-1,-1,-1,-1,29,-1,24,13,25,9,8,23,-1,18,22,31,27,19,-1,1,0,3,16,11,28,12,14,6,4,2,-1,-1,-1,-1,-1,-1,29,-1,24,13,25,9,8,23,-1,18,22,31,27,19,-1,1,0,3,16,11,28,12,14,6,4,2,-1,-1,-1,-1,-1],lt=new st(7,4294967295),dt=[new st(152,4072443489),new st(121,3077413346),new st(243,1046459332),new st(174,783016616),new st(30,1329849456)];function pt(t,r){var e=t,n=e.hi>>>3;e.hi&=lt.hi,e.lo&=lt.lo,e.hi<<=5,e.hi|=e.lo>>>27,e.lo<<=5;for(var i=0;i<dt.length;i++)n>>>i&1&&(e.hi^=dt[i].hi,e.lo^=dt[i].lo);return e.lo^=r,e}function vt(t,r,e,n,i,o,f){ut(Buffer.isBuffer(t)),ut(r>>>0===r),ut(Buffer.isBuffer(e)),ut(n>>>0===n),ut((255&i)===i),ut((255&o)===o),ut("boolean"==typeof f);for(var u=(1<<o)-1,s=0,a=0;r<t.length;r++){var h=t[r];if(h>>>i!=0)throw new Error("Invalid bits.");for(s=s<<i|h,a+=i;a>=o;)e[n++]=s>>>(a-=o)&u}if(f)a&&(e[n++]=s<<o-a&u);else if(a>=i||s<<o-a&u)throw new Error("Invalid bits.");return ut(n<=e.length),e.slice(0,n)}var yt=function(t){function r(r){var e=r.slice(0,-4),n=r.slice(-4),i=t(e);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return e}return{bs58Encode:function(r){var e=t(r);return o.encode(Buffer.concat([r,e],r.length+4))},bs58Decode:function(t){var e=r(o.decode(t));if(!e)throw new Error("Invalid checksum");return e},decodeUnsafe:function(t){var e=o.decodeUnsafe(t);if(e)return r(e)}}}(function(t){var r=(new y).update(t).digest();return(new y).update(r).digest()}),gt=yt.bs58Decode,wt=yt.bs58Encode;exports.b32decode=h,exports.b32encode=function(t){var r=[],e=Math.floor(t.length/5),n=t.length%5;if(0!=n){for(var i=0;i<5-n;i++)t+="\0";e+=1}for(var o=0;o<e;o++)r.push(s.charAt(t.charCodeAt(5*o)>>3)),r.push(s.charAt((7&t.charCodeAt(5*o))<<2|t.charCodeAt(5*o+1)>>6)),r.push(s.charAt((63&t.charCodeAt(5*o+1))>>1)),r.push(s.charAt((1&t.charCodeAt(5*o+1))<<4|t.charCodeAt(5*o+2)>>4)),r.push(s.charAt((15&t.charCodeAt(5*o+2))<<1|t.charCodeAt(5*o+3)>>7)),r.push(s.charAt((127&t.charCodeAt(5*o+3))>>2)),r.push(s.charAt((3&t.charCodeAt(5*o+3))<<3|t.charCodeAt(5*o+4)>>5)),r.push(s.charAt(31&t.charCodeAt(5*o+4)));var f=0;1==n?f=6:2==n?f=4:3==n?f=3:4==n&&(f=1);for(var u=0;u<f;u++)r.pop();for(var a=0;a<f;a++)r.push("=");return r.join("")},exports.bs58Decode=gt,exports.bs58Encode=wt,exports.calculateChecksum=Z,exports.cashaddrDecode=function(t,r){void 0===r&&(r="bitcoincash"),ut("string"==typeof t),ut("string"==typeof r);var e=function(t,r){if(ut("string"==typeof t),t.length<8||t.length>196)throw new Error("Invalid cashaddr data length.");for(var e=!1,n=!1,i=!1,o=0,f=0;f<t.length;f++){var u=t.charCodeAt(f);if(u>=97&&u<=122)e=!0;else if(u>=65&&u<=90)n=!0;else if(u>=48&&u<=57)i=!0;else{if(58!==u)throw new Error("Invalid cashaddr character.");if(i||0===f||f>83)throw new Error("Invalid cashaddr prefix.");if(0!==o)throw new Error("Invalid cashaddr separators.");o=f}}if(n&&e)throw new Error("Invalid cashaddr casing.");var s,a=new st(0,1);0===o?s=r.toLowerCase():(s=t.substring(0,o).toLowerCase(),o+=1);for(var h=0;h<s.length;h++)pt(a,31&(32|s.charCodeAt(h)));pt(a,0);var c=t.length-o;if(c<=8||c>112)throw new Error("Invalid cashaddr data length.");for(var l=Buffer.allocUnsafe(c),d=o;d<t.length;d++){var p=t.charCodeAt(d),v=65408&p?-1:ct[p];if(-1===v)throw new Error("Invalid cashaddr character.");pt(a,v),d+8<t.length&&(l[d-o]=v)}if(0!==a.hi||1!==a.lo||s!==r)throw new Error("Invalid cashaddr checksum.");return[s,l.slice(0,-8)]}(t,r),n=e[0],i=e[1],o=5*i.length&7;if(o>=5)throw new Error("Invalid padding in data.");if(i[i.length-1]&(1<<o)-1)throw new Error("Non zero padding.");var f=vt(i,0,i,0,5,8,!1),u=f[0]>>>3&31,s=f.slice(1),a=20+4*(3&f[0]);if(4&f[0]&&(a*=2),a!==s.length)throw new Error("Invalid cashaddr data length.");return{prefix:n,type:u,hash:s}},exports.cashaddrEncode=function(t,r,e){if(ut("string"==typeof t),ut((15&r)===r,"Invalid cashaddr type."),ut(Buffer.isBuffer(e)),0===t.length||t.length>83)throw new Error("Invalid cashaddr prefix.");var n=function(t){switch(ut(t>>>0===t),t){case 20:return 0;case 24:return 1;case 28:return 2;case 32:return 3;case 40:return 4;case 48:return 5;case 56:return 6;case 64:return 7;default:throw new Error("Non standard length.")}}(e.length),i=Buffer.allocUnsafe(e.length+1);return i[0]=r<<3|n,e.copy(i,1),function(t,r){ut("string"==typeof t),ut(Buffer.isBuffer(r));for(var e=new st(0,1),n="",i=!1,o=!1,f=0;f<t.length;f++){var u=t.charCodeAt(f);if(65280&u||u>>>5==0)throw new Error("Invalid cashaddr character.");if(u>=97&&u<=122)o=!0;else if(u>=65&&u<=90)i=!0,u=u-65+97;else if(u>=48&&u<=57)throw new Error("Invalid cashaddr prefix.");pt(e,31&u),n+=String.fromCharCode(u)}if(o&&i)throw new Error("Invalid cashaddr prefix.");pt(e,0),n+=":";for(var s=0;s<r.length;s++){var a=r[s];if(a>>>5!=0)throw new Error("Invalid cashaddr value.");pt(e,a),n+=ht[a]}for(var h=0;h<8;h++)pt(e,0);e.lo^=1;for(var c=0;c<8;c++){var l=31&e.ushrn32(5*(7-c));n+=ht[l]}return n}(t,vt(i,0,at,0,8,5,!0))},exports.codec=E,exports.decodeCheck=function(t,r){if("string"!=typeof r)throw new TypeError("encoded argument must be of type String");var e=Y(r),n=e[0],i=e.slice(0,-2),o=i.slice(1),f=e.slice(-2);if(r!==K(e))throw new Error("invalid encoded string");var u=Q[t];if(V(u))throw new Error(t+' is not a valid version byte name. expected one of "accountId" or "seed"');if(n!==u)throw new Error("invalid version byte. expected "+u+", got "+n);if(!function(t,r){if(t.length!==r.length)return!1;if(0===t.length)return!0;for(var e=0;e<t.length;e+=1)if(t[e]!==r[e])return!1;return!0}(Z(i),f))throw new Error("invalid checksum");return Buffer.from(o)},exports.encodeCheck=function(t,r){if(null===r||V(r))throw new Error("cannot encode null data");var e=Q[t];if(V(e))throw new Error(t+' is not a valid version byte name. expected one of "ed25519PublicKey", "ed25519SecretSeed", "preAuthTx", "sha256Hash"');r=Buffer.from(r);var n=Buffer.from([e]),i=Buffer.concat([n,r]),o=Z(i),f=Buffer.concat([i,o]);return K(f)},exports.eosPublicKey=N,exports.hex2a=function(t){for(var r=t.toString(),e="",n=0;n<r.length;n+=2)e+=String.fromCharCode(parseInt(r.substr(n,2),16));return e},exports.isValid=function(t){var e=t.toString().toUpperCase().replace(/-/g,"");if(!e||40!==e.length)return!1;var n,i=function(t){for(var r="",e=0;e<t.length;e++){var n=Math.round(t[e]).toString(16);1===n.length&&(n="0"+n),r+=n}return r}(h(e));return n=Buffer.from(i.slice(0,42),"hex"),new r.Keccak(256).update(n).digest("hex").toString().substr(0,8)===i.slice(42)},exports.isValidChecksumAddress=function(t,r){return function(t){return/^0x[0-9a-fA-F]{40}$/.test(t)}(t)&&B(t,r)===t},exports.ss58Decode=function(t,r){var e;void 0===r&&(r=0);try{e=o.decode(t)}catch(t){return null}if(-1===et.indexOf(e[0]))return null;if(e.length<3)return null;var n,i=e.length<=3?1:e.length<=5?2:e.length<=9?4:e.length<=17?8:32,f=e.length-1-i,s=e.slice(1,1+i);e.slice(1+e.length),32===i&&(n=s);var a=i<32?new it(function(t){var r=0,e=1;return t.forEach(function(t){r+=t*e,e*=256}),r}(s)):new Buffer.from(s);if(e[0]%1&&!n&&!r)return null;for(var h=u.blake2b(ot(nt,e[0]%1?n||r(a):e.slice(0,1+i))),c=0;c<f;++c)if(h[c]!==e[1+i+c])return null;return a},exports.ss58Encode=function(t,r,e,n,i){var f;if(void 0===r&&(r=42),void 0===e&&(e=null),void 0===n&&(n=null),-1===et.indexOf(r))throw new Error("Unknown ss58 address type",r);if("number"==typeof t||t instanceof it){var s=t<256?1:t<65536?2:t<1?4:8;if(-1===[1,2,4,8].indexOf(n=n||s))throw new Error("Invalid length");if(n=Math.max(s,n),e&&"number"!=typeof e)throw new Error("Invalid checksum length");switch(n){case 1:e=1;break;case 2:e=[1,2].indexOf(e)+1||1;break;case 4:e=[1,2,3,4].indexOf(e)+1||1;break;case 8:e=[1,2,3,4,5,6,7,8].indexOf(e)+1||1}f=function(t,r){var e=!1;t<0&&(t=-t-1,e=!0);for(var n=new Uint8Array(r),i=0;i<r;++i)n[i]=t%256,e&&(n[i]=255&~n[i]),t/=256;return n}(t,n)}else{if(!(t instanceof Uint8Array)||32!==t.length&&35!==t.length)throw new Error("Unknown item to encode as ss58. Passing back.",t);e=2,i=f=35===t.length?t.slice(1,33):t}var a=u.blake2b(ot(nt,1&r?i:ot(r,f))),h=ot(ot(r,f),a.slice(0,e));return o.encode(Buffer.from(h))},exports.stripHexPrefix=I,exports.toChecksumAddress=B,exports.ua2hex=function(t){for(var r="",e=0;e<t.length;e++){var n=t[e];r+=a[n>>>4],r+=a[15&n]}return r}; | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var r=require("sha3"),e=t(require("base-x")),n=require("safe-buffer"),i=t(require("big-integer")),o=t(require("bs58")),f=require("ripemd160-min"),u=require("blakejs/blake2b"),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",a=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],h=function(t){for(var r=new ArrayBuffer(5*t.length/8),e=new Uint8Array(r),n=0;n<t.length/8;n++){for(var i=[0,0,0,0,0,0,0,0],o=0;o<8;++o)i[o]=s.indexOf(t[8*n+o]);e[5*n+0]=i[0]<<3|i[1]>>2,e[5*n+1]=(3&i[1])<<6|i[2]<<1|i[3]>>4,e[5*n+2]=(15&i[3])<<4|i[4]>>1,e[5*n+3]=(1&i[4])<<7|i[5]<<2|i[6]>>3,e[5*n+4]=(7&i[6])<<5|i[7]}return Buffer.from(e)};function c(t,r){this._block=n.Buffer.alloc(t),this._finalSize=r,this._blockSize=t,this._len=0}c.prototype.update=function(t,r){"string"==typeof t&&(t=n.Buffer.from(t,r=r||"utf8"));for(var e=this._block,i=this._blockSize,o=t.length,f=this._len,u=0;u<o;){for(var s=f%i,a=Math.min(o-u,i-s),h=0;h<a;h++)e[s+h]=t[u+h];u+=a,(f+=a)%i==0&&this._update(e)}return this._len+=o,this},c.prototype.digest=function(t){var r=this._len%this._blockSize;this._block[r]=128,this._block.fill(0,r+1),r>=this._finalSize&&(this._update(this._block),this._block.fill(0));var e=8*this._len;if(e<=4294967295)this._block.writeUInt32BE(e,this._blockSize-4);else{var n=(4294967295&e)>>>0;this._block.writeUInt32BE((e-n)/4294967296,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var i=this._hash();return t?i.toString(t):i},c.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var l,d,p=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],v=new Array(64);function y(){this.init(),this._w=v,c.call(this,64,56)}function g(t,r,e){return e^t&(r^e)}function w(t,r,e){return t&r|e&(t|r)}function m(t){return(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10)}function b(t){return(t>>>6|t<<26)^(t>>>11|t<<21)^(t>>>25|t<<7)}function _(t){return(t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3}function x(t){return void 0!==t.length}l=y,(d=c)&&(l.super_=d,l.prototype=Object.create(d.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}})),y.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},y.prototype._update=function(t){for(var r,e=this._w,n=0|this._a,i=0|this._b,o=0|this._c,f=0|this._d,u=0|this._e,s=0|this._f,a=0|this._g,h=0|this._h,c=0;c<16;++c)e[c]=t.readInt32BE(4*c);for(;c<64;++c)e[c]=0|(((r=e[c-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10)+e[c-7]+_(e[c-15])+e[c-16];for(var l=0;l<64;++l){var d=h+b(u)+g(u,s,a)+p[l]+e[l]|0,v=m(n)+w(n,i,o)|0;h=a,a=s,s=u,u=f+d|0,f=o,o=i,i=n,n=d+v|0}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=f+this._d|0,this._e=u+this._e|0,this._f=s+this._f|0,this._g=a+this._g|0,this._h=h+this._h|0},y.prototype._hash=function(){var t=n.Buffer.allocUnsafe(32);return t.writeInt32BE(this._a,0),t.writeInt32BE(this._b,4),t.writeInt32BE(this._c,8),t.writeInt32BE(this._d,12),t.writeInt32BE(this._e,16),t.writeInt32BE(this._f,20),t.writeInt32BE(this._g,24),t.writeInt32BE(this._h,28),t};var E=new(function(){function t(t){this.sha256=t.sha256,this.alphabet=t.alphabet,this.codec=e(this.alphabet),this.base=this.alphabet.length}var r=t.prototype;return r.encodeChecked=function(t){var r=this.sha256(this.sha256(t)).slice(0,4);return this.encodeRaw(Buffer.from(function(){for(var t=[],r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return e.forEach(function(r){if(x(r))for(var e=0;e<r.length;e++)t.push(r[e]);else t.push(r)}),t}(t,r)))},r.encodeRaw=function(t){return this.codec.encode(t)},r.decodeChecked=function(t){var r=this.decodeRaw(t);if(r.length<5)throw new Error("invalid_input_size: decoded data must have length >= 5");if(!this.verifyCheckSum(r))throw new Error("checksum_invalid");return r.slice(0,-4)},r.decodeRaw=function(t){return this.codec.decode(t)},r.verifyCheckSum=function(t){return function(t,r){if(t.length!==r.length)return!1;for(var e=0;e<t.length;e++)if(t[e]!==r[e])return!1;return!0}(this.sha256(this.sha256(t.slice(0,-4))).slice(0,4),t.slice(-4))},t}())({sha256:function(t){return(new y).update(Buffer.from(t)).digest()},alphabet:"rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"}),B=function(t){return"0x"===t.slice(0,2)?t.slice(2):t},I=function(t,e){if(void 0===e&&(e=null),"string"!=typeof t)throw new Error("stripHexPrefix param must be type 'string', is currently type "+typeof t+".");for(var n,i=B(t).toLowerCase(),o=(n=(null!=e?e.toString()+"0x":"")+i,new r.Keccak(256).update(n).digest()).toString("hex"),f="0x",u=0;u<i.length;u++)f+=parseInt(o[u],16)>=8?i[u].toUpperCase():i[u];return f},A=function(t,r){if(!t)throw r},S=function(t,r){if(!Buffer.isBuffer(t))throw r},k=i.one,z=i.zero,C=i(3);function O(t,r){return t.and(k.shiftLeft(r)).notEquals(z)}function U(t){return i.fromArray(Array.prototype.slice.call(t,0),256)}function P(t,r){var e=t.toArray(256).value,n=r?Math.max(r-e.length,0):0;return Buffer.from([].concat(Array(n).fill(0),e))}function q(t,r,e,n){A(void 0!==n,"Missing Z coordinate"),this.curve=t,this.x=r,this.y=e,this.z=n,this._zInv=null,this.compressed=!0}Object.defineProperty(q.prototype,"zInv",{get:function(){return null===this._zInv&&(this._zInv=this.z.modInv(this.curve.p)),this._zInv}}),Object.defineProperty(q.prototype,"affineX",{get:function(){return this.x.multiply(this.zInv).mod(this.curve.p)}}),Object.defineProperty(q.prototype,"affineY",{get:function(){return this.y.multiply(this.zInv).mod(this.curve.p)}}),q.fromAffine=function(t,r,e){return new q(t,r,e,k)},q.prototype.equals=function(t){return t===this||(this.curve.isInfinity(this)?this.curve.isInfinity(t):this.curve.isInfinity(t)?this.curve.isInfinity(this):0===t.y.multiply(this.z).subtract(this.y.multiply(t.z)).mod(this.curve.p).compare(z)&&0===t.x.multiply(this.z).subtract(this.x.multiply(t.z)).mod(this.curve.p).compare(z))},q.prototype.negate=function(){var t=this.curve.p.subtract(this.y);return new q(this.curve,this.x,t,this.z)},q.prototype.add=function(t){if(this.curve.isInfinity(this))return t;if(this.curve.isInfinity(t))return this;var r=this.x,e=this.y,n=t.x,i=t.y.multiply(this.z).subtract(e.multiply(t.z)).mod(this.curve.p),o=n.multiply(this.z).subtract(r.multiply(t.z)).mod(this.curve.p);if(0===o.compare(z))return 0===i.compare(z)?this.twice():this.curve.infinity;var f=o.square(),u=f.multiply(o),s=r.multiply(f),a=i.square().multiply(this.z),h=a.subtract(s.shiftLeft(1)).multiply(t.z).subtract(u).multiply(o).mod(this.curve.p),c=s.multiply(C).multiply(i).subtract(e.multiply(u)).subtract(a.multiply(i)).multiply(t.z).add(i.multiply(u)).mod(this.curve.p),l=u.multiply(this.z).multiply(t.z).mod(this.curve.p);return new q(this.curve,h,c,l)},q.prototype.twice=function(){if(this.curve.isInfinity(this))return this;if(0===this.y.compare(z))return this.curve.infinity;var t=this.x,r=this.y,e=r.multiply(this.z).mod(this.curve.p),n=e.multiply(r).mod(this.curve.p),i=this.curve.a,o=t.square().multiply(C);0!==i.compare(z)&&(o=o.add(this.z.square().multiply(i)));var f=(o=o.mod(this.curve.p)).square().subtract(t.shiftLeft(3).multiply(n)).shiftLeft(1).multiply(e).mod(this.curve.p),u=o.multiply(C).multiply(t).subtract(n.shiftLeft(1)).shiftLeft(2).multiply(n).subtract(o.pow(3)).mod(this.curve.p),s=e.pow(3).shiftLeft(3).mod(this.curve.p);return new q(this.curve,f,u,s)},q.prototype.multiply=function(t){if(this.curve.isInfinity(this))return this;if(0===t.compare(z))return this.curve.infinity;for(var r=t,e=r.multiply(C),n=this.negate(),i=this,o=e.bitLength()-2;o>0;--o){var f=O(e,o),u=O(r,o);i=i.twice(),f!==u&&(i=i.add(f?this:n))}return i},q.prototype.multiplyTwo=function(t,r,e){for(var n=Math.max(t.bitLength(),e.bitLength())-1,i=this.curve.infinity,o=this.add(r);n>=0;){var f=O(t,n),u=O(e,n);i=i.twice(),f?i=i.add(u?o:this):u&&(i=i.add(r)),--n}return i},q.prototype.getEncoded=function(t){if(null==t&&(t=this.compressed),this.curve.isInfinity(this))return new Buffer("00","hex");var r,e=this.affineX,n=this.affineY,i=this.curve.pLength;return t?(r=new Buffer(1+i)).writeUInt8(n.isEven()?2:3,0):((r=new Buffer(1+i+i)).writeUInt8(4,0),P(n,i).copy(r,1+i)),P(e,i).copy(r,1),r},q.decodeFrom=function(t,r){var e,n=r.readUInt8(0),i=4!==n,o=Math.floor((t.p.bitLength()+7)/8),f=U(r.slice(1,1+o));if(i)A(r.length===o+1,"Invalid sequence length"),A(2===n||3===n,"Invalid sequence tag"),e=t.pointFromX(3===n,f);else{A(r.length===1+o+o,"Invalid sequence length");var u=U(r.slice(1+o));e=q.fromAffine(t,f,u)}return e.compressed=i,e},q.prototype.toString=function(){return this.curve.isInfinity(this)?"(INFINITY)":"("+this.affineX.toString()+","+this.affineY.toString()+")"};var L=i.zero,j=i.one;function R(t,r,e,n,i,o,f){this.p=t,this.a=r,this.b=e,this.G=q.fromAffine(this,n,i),this.n=o,this.h=f,this.infinity=new q(this,null,null,L),this.pOverFour=t.add(j).shiftRight(2),this.pLength=Math.floor((this.p.bitLength()+7)/8)}R.prototype.pointFromX=function(t,r){var e=r.pow(3).add(this.a.multiply(r)).add(this.b).mod(this.p).modPow(this.pOverFour,this.p),n=e;return e.isEven()^!t&&(n=this.p.subtract(n)),q.fromAffine(this,r,n)},R.prototype.isInfinity=function(t){return t===this.infinity||0===t.z.compare(L)&&0!==t.y.compare(L)},R.prototype.isOnCurve=function(t){if(this.isInfinity(t))return!0;var r=t.affineX,e=t.affineY,n=this.a,i=this.b,o=this.p;if(r.compare(L)<0||r.compareTo(o)>=0)return!1;if(e.compare(L)<0||e.compareTo(o)>=0)return!1;var f=e.square().mod(o),u=r.pow(3).add(n.multiply(r)).add(i).mod(o);return f.equals(u)},R.prototype.validate=function(t){A(!this.isInfinity(t),"Point is at infinity"),A(this.isOnCurve(t),"Point is not on the curve");var r=t.multiply(this.n);return A(this.isInfinity(r),"Point is not a scalar multiple of G"),!0};var M={p:"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",a:"00",b:"07",n:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",h:"01",Gx:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",Gy:"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"};function F(t,e){return new r.SHA3(256).update(t).digest(e)}function T(t){return Buffer.from((new f.RIPEMD160).update(t).digest())}function D(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(S(t,"expecting keyBuffer<Buffer>"),"sha256x2"===r){var e=F(F(t)).slice(0,4);return o.encode(Buffer.concat([t,e]))}var n=[t];r&&n.push(Buffer.from(r));var i=T(Buffer.concat(n)).slice(0,4);return o.encode(Buffer.concat([t,i]))}function H(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;A(t,"private key expected");var e,n=new Buffer(o.decode(t)),i=n.slice(-4),f=n.slice(0,-4);if("sha256x2"===r)e=F(F(f)).slice(0,4);else{var u=[f];r&&u.push(Buffer.from(r)),e=T(Buffer.concat(u)).slice(0,4)}if(i.toString("hex")!==e.toString("hex"))throw new Error("Invalid checksum, "+"".concat(i.toString("hex")," != ").concat(e.toString("hex")));return f}var G=function(t){var r=M;if(!r)return null;var e=i(r.p,16),n=i(r.a,16),o=i(r.b,16),f=i(r.n,16),u=i(r.h,16);return new R(e,n,o,i(r.Gx,16),i(r.Gy,16),f,u)}();function N(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS";if("string"==typeof t)return N.fromString(t,r);if(Buffer.isBuffer(t))return N.fromBuffer(t);if("object"==typeof t&&t.Q)return N(t.Q);function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.compressed;return t.getEncoded(r)}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"EOS";return t+D(e())}function i(){return e().toString("hex")}return{Q:t,toString:n,toBuffer:e,toHex:i}}N.isValid=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS";try{return N(t,r),!0}catch(t){return!1}},N.fromBuffer=function(t){return N(q.decodeFrom(G,t))},N.fromString=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS";try{return N.fromStringOrThrow(t,r)}catch(t){return null}},N.fromStringOrThrow=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"EOS",e=t.match(/^PUB_([A-Za-z0-9]+)_([A-Za-z0-9]+)$/);if(null===e){var n=new RegExp("^"+r);return n.test(t)&&(t=t.substring(r.length)),N.fromBuffer(H(t))}var i=e[1],o=e[2];return N.fromBuffer(H(o,i))},N.fromHex=function(t){return N.fromBuffer(new Buffer(t,"hex"))},N.fromStringHex=function(t){return N.fromString(new Buffer(t,"hex"))};var X=e("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),K=X.encode,Y=X.decode,V=function(t){return void 0===t},Q={ed25519PublicKey:48,ed25519SecretSeed:144,preAuthTx:152,sha256Hash:184},Z=function(t){var r=Buffer.alloc(2);return r.writeUInt16LE(function(t,r){Buffer.isBuffer(t)||(t=new Buffer);for(var e=0,n=0;n<t.length;n++){var i=e>>>8&255;i^=255&t[n],e=e<<8&65535,e^=i^=i>>>4,e^=i=i<<5&65535,e^=i=i<<7&65535}return e}(t),0),r};function J(t){return(J=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function W(t,r){return(W=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function $(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function tt(t,r,e){return(tt=$()?Reflect.construct:function(t,r,e){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(t,n));return e&&W(i,e.prototype),i}).apply(null,arguments)}function rt(t){var r="function"==typeof Map?new Map:void 0;return(rt=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return tt(t,arguments,J(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),W(e,t)})(t)}var et=[0,1,2,42,43,68,69],nt=function(t){for(var r=new Uint8Array(t.length),e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return r}("SS58PRE"),it=function(t){var r,e;function n(){return t.apply(this,arguments)||this}return e=t,(r=n).prototype=Object.create(e.prototype),r.prototype.constructor=r,r.__proto__=e,n.prototype.toJSON=function(){return{_type:"AccountIndex",data:this+0}},n}(rt(Number));function ot(t,r){t.length||(t=[t]),r.length||(r=[r]);var e=new Uint8Array(t.length+r.length);return e.set(t),e.set(r,t.length),e}function ft(t){var r=new Error;this.name=r.name="ValidationError",this.message=r.message=t,this.stack=r.stack}function ut(t,r){if(null==r&&(r="Assertion failed."),!t)throw new ft(r)}ft.prototype=Object.create(Error.prototype);var st=function(){function t(t,r){this.hi=0|t,this.lo=0|r}return t.prototype.ushrn32=function(t){var r=this.lo;return 0==(t&=63)||(t<32?(r>>>=t,r|=this.hi<<32-t):r=this.hi>>>t-32),r},t}(),at=Buffer.allocUnsafe(105),ht="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ct=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,15,-1,10,17,21,20,26,30,7,5,-1,-1,-1,-1,-1,-1,-1,29,-1,24,13,25,9,8,23,-1,18,22,31,27,19,-1,1,0,3,16,11,28,12,14,6,4,2,-1,-1,-1,-1,-1,-1,29,-1,24,13,25,9,8,23,-1,18,22,31,27,19,-1,1,0,3,16,11,28,12,14,6,4,2,-1,-1,-1,-1,-1],lt=new st(7,4294967295),dt=[new st(152,4072443489),new st(121,3077413346),new st(243,1046459332),new st(174,783016616),new st(30,1329849456)];function pt(t,r){var e=t,n=e.hi>>>3;e.hi&=lt.hi,e.lo&=lt.lo,e.hi<<=5,e.hi|=e.lo>>>27,e.lo<<=5;for(var i=0;i<dt.length;i++)n>>>i&1&&(e.hi^=dt[i].hi,e.lo^=dt[i].lo);return e.lo^=r,e}function vt(t,r,e,n,i,o,f){ut(Buffer.isBuffer(t)),ut(r>>>0===r),ut(Buffer.isBuffer(e)),ut(n>>>0===n),ut((255&i)===i),ut((255&o)===o),ut("boolean"==typeof f);for(var u=(1<<o)-1,s=0,a=0;r<t.length;r++){var h=t[r];if(h>>>i!=0)throw new Error("Invalid bits.");for(s=s<<i|h,a+=i;a>=o;)e[n++]=s>>>(a-=o)&u}if(f)a&&(e[n++]=s<<o-a&u);else if(a>=i||s<<o-a&u)throw new Error("Invalid bits.");return ut(n<=e.length),e.slice(0,n)}var yt=function(t){function r(r){var e=r.slice(0,-4),n=r.slice(-4),i=t(e);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return e}return{bs58Encode:function(r){var e=t(r);return o.encode(Buffer.concat([r,e],r.length+4))},bs58Decode:function(t){var e=r(o.decode(t));if(!e)throw new Error("Invalid checksum");return e},decodeUnsafe:function(t){var e=o.decodeUnsafe(t);if(e)return r(e)}}}(function(t){var r=(new y).update(t).digest();return(new y).update(r).digest()}),gt=yt.bs58Decode,wt=yt.bs58Encode;exports.b32decode=h,exports.b32encode=function(t){var r=[],e=Math.floor(t.length/5),n=t.length%5;if(0!=n){for(var i=0;i<5-n;i++)t+="\0";e+=1}for(var o=0;o<e;o++)r.push(s.charAt(t.charCodeAt(5*o)>>3)),r.push(s.charAt((7&t.charCodeAt(5*o))<<2|t.charCodeAt(5*o+1)>>6)),r.push(s.charAt((63&t.charCodeAt(5*o+1))>>1)),r.push(s.charAt((1&t.charCodeAt(5*o+1))<<4|t.charCodeAt(5*o+2)>>4)),r.push(s.charAt((15&t.charCodeAt(5*o+2))<<1|t.charCodeAt(5*o+3)>>7)),r.push(s.charAt((127&t.charCodeAt(5*o+3))>>2)),r.push(s.charAt((3&t.charCodeAt(5*o+3))<<3|t.charCodeAt(5*o+4)>>5)),r.push(s.charAt(31&t.charCodeAt(5*o+4)));var f=0;1==n?f=6:2==n?f=4:3==n?f=3:4==n&&(f=1);for(var u=0;u<f;u++)r.pop();for(var a=0;a<f;a++)r.push("=");return r.join("")},exports.bs58Decode=gt,exports.bs58Encode=wt,exports.calculateChecksum=Z,exports.cashaddrDecode=function(t,r){void 0===r&&(r="bitcoincash"),ut("string"==typeof t),ut("string"==typeof r);var e=function(t,r){if(ut("string"==typeof t),t.length<8||t.length>196)throw new Error("Invalid cashaddr data length.");for(var e=!1,n=!1,i=!1,o=0,f=0;f<t.length;f++){var u=t.charCodeAt(f);if(u>=97&&u<=122)e=!0;else if(u>=65&&u<=90)n=!0;else if(u>=48&&u<=57)i=!0;else{if(58!==u)throw new Error("Invalid cashaddr character.");if(i||0===f||f>83)throw new Error("Invalid cashaddr prefix.");if(0!==o)throw new Error("Invalid cashaddr separators.");o=f}}if(n&&e)throw new Error("Invalid cashaddr casing.");var s,a=new st(0,1);0===o?s=r.toLowerCase():(s=t.substring(0,o).toLowerCase(),o+=1);for(var h=0;h<s.length;h++)pt(a,31&(32|s.charCodeAt(h)));pt(a,0);var c=t.length-o;if(c<=8||c>112)throw new Error("Invalid cashaddr data length.");for(var l=Buffer.allocUnsafe(c),d=o;d<t.length;d++){var p=t.charCodeAt(d),v=65408&p?-1:ct[p];if(-1===v)throw new Error("Invalid cashaddr character.");pt(a,v),d+8<t.length&&(l[d-o]=v)}if(0!==a.hi||1!==a.lo||s!==r)throw new Error("Invalid cashaddr checksum.");return[s,l.slice(0,-8)]}(t,r),n=e[0],i=e[1],o=5*i.length&7;if(o>=5)throw new Error("Invalid padding in data.");if(i[i.length-1]&(1<<o)-1)throw new Error("Non zero padding.");var f=vt(i,0,i,0,5,8,!1),u=f[0]>>>3&31,s=f.slice(1),a=20+4*(3&f[0]);if(4&f[0]&&(a*=2),a!==s.length)throw new Error("Invalid cashaddr data length.");return{prefix:n,type:u,hash:s}},exports.cashaddrEncode=function(t,r,e){if(ut("string"==typeof t),ut((15&r)===r,"Invalid cashaddr type."),ut(Buffer.isBuffer(e)),0===t.length||t.length>83)throw new Error("Invalid cashaddr prefix.");var n=function(t){switch(ut(t>>>0===t),t){case 20:return 0;case 24:return 1;case 28:return 2;case 32:return 3;case 40:return 4;case 48:return 5;case 56:return 6;case 64:return 7;default:throw new Error("Non standard length.")}}(e.length),i=Buffer.allocUnsafe(e.length+1);return i[0]=r<<3|n,e.copy(i,1),function(t,r){ut("string"==typeof t),ut(Buffer.isBuffer(r));for(var e=new st(0,1),n="",i=!1,o=!1,f=0;f<t.length;f++){var u=t.charCodeAt(f);if(65280&u||u>>>5==0)throw new Error("Invalid cashaddr character.");if(u>=97&&u<=122)o=!0;else if(u>=65&&u<=90)i=!0,u=u-65+97;else if(u>=48&&u<=57)throw new Error("Invalid cashaddr prefix.");pt(e,31&u),n+=String.fromCharCode(u)}if(o&&i)throw new Error("Invalid cashaddr prefix.");pt(e,0),n+=":";for(var s=0;s<r.length;s++){var a=r[s];if(a>>>5!=0)throw new Error("Invalid cashaddr value.");pt(e,a),n+=ht[a]}for(var h=0;h<8;h++)pt(e,0);e.lo^=1;for(var c=0;c<8;c++){var l=31&e.ushrn32(5*(7-c));n+=ht[l]}return n}(t,vt(i,0,at,0,8,5,!0))},exports.codec=E,exports.decodeCheck=function(t,r){if("string"!=typeof r)throw new TypeError("encoded argument must be of type String");var e=Y(r),n=e[0],i=e.slice(0,-2),o=i.slice(1),f=e.slice(-2);if(r!==K(e))throw new Error("invalid encoded string");var u=Q[t];if(V(u))throw new Error(t+' is not a valid version byte name. expected one of "accountId" or "seed"');if(n!==u)throw new Error("invalid version byte. expected "+u+", got "+n);if(!function(t,r){if(t.length!==r.length)return!1;if(0===t.length)return!0;for(var e=0;e<t.length;e+=1)if(t[e]!==r[e])return!1;return!0}(Z(i),f))throw new Error("invalid checksum");return Buffer.from(o)},exports.encodeCheck=function(t,r){if(null===r||V(r))throw new Error("cannot encode null data");var e=Q[t];if(V(e))throw new Error(t+' is not a valid version byte name. expected one of "ed25519PublicKey", "ed25519SecretSeed", "preAuthTx", "sha256Hash"');r=Buffer.from(r);var n=Buffer.from([e]),i=Buffer.concat([n,r]),o=Z(i),f=Buffer.concat([i,o]);return K(f)},exports.eosPublicKey=N,exports.hex2a=function(t){for(var r=t.toString(),e="",n=0;n<r.length;n+=2)e+=String.fromCharCode(parseInt(r.substr(n,2),16));return e},exports.isValid=function(t){var e=t.toString().toUpperCase().replace(/-/g,"");if(!e||40!==e.length)return!1;var n,i=function(t){for(var r="",e=0;e<t.length;e++){var n=Math.round(t[e]).toString(16);1===n.length&&(n="0"+n),r+=n}return r}(h(e));return n=Buffer.from(i.slice(0,42),"hex"),new r.Keccak(256).update(n).digest("hex").toString().substr(0,8)===i.slice(42)},exports.isValidChecksumAddress=function(t,r){return function(t){return/^0x[0-9a-fA-F]{40}$/.test(t)}(t)&&I(t,r)===t},exports.ss58Decode=function(t,r){var e;void 0===r&&(r=0);try{e=o.decode(t)}catch(t){return null}if(-1===et.indexOf(e[0]))return null;if(e.length<3)return null;var n,i=e.length<=3?1:e.length<=5?2:e.length<=9?4:e.length<=17?8:32,f=e.length-1-i,s=e.slice(1,1+i);e.slice(1+e.length),32===i&&(n=s);var a=i<32?new it(function(t){var r=0,e=1;return t.forEach(function(t){r+=t*e,e*=256}),r}(s)):new Buffer.from(s);if(e[0]%1&&!n&&!r)return null;for(var h=u.blake2b(ot(nt,e[0]%1?n||r(a):e.slice(0,1+i))),c=0;c<f;++c)if(h[c]!==e[1+i+c])return null;return a},exports.ss58Encode=function(t,r,e,n,i){var f;if(void 0===r&&(r=42),void 0===e&&(e=null),void 0===n&&(n=null),-1===et.indexOf(r))throw new Error("Unknown ss58 address type",r);if("number"==typeof t||t instanceof it){var s=t<256?1:t<65536?2:t<1?4:8;if(-1===[1,2,4,8].indexOf(n=n||s))throw new Error("Invalid length");if(n=Math.max(s,n),e&&"number"!=typeof e)throw new Error("Invalid checksum length");switch(n){case 1:e=1;break;case 2:e=[1,2].indexOf(e)+1||1;break;case 4:e=[1,2,3,4].indexOf(e)+1||1;break;case 8:e=[1,2,3,4,5,6,7,8].indexOf(e)+1||1}f=function(t,r){var e=!1;t<0&&(t=-t-1,e=!0);for(var n=new Uint8Array(r),i=0;i<r;++i)n[i]=t%256,e&&(n[i]=255&~n[i]),t/=256;return n}(t,n)}else{if(!(t instanceof Uint8Array)||32!==t.length&&35!==t.length)throw new Error("Unknown item to encode as ss58. Passing back.",t);e=2,i=f=35===t.length?t.slice(1,33):t}var a=u.blake2b(ot(nt,1&r?i:ot(r,f))),h=ot(ot(r,f),a.slice(0,e));return o.encode(Buffer.from(h))},exports.stripHexPrefix=B,exports.toChecksumAddress=I,exports.ua2hex=function(t){for(var r="",e=0;e<t.length;e++){var n=t[e];r+=a[n>>>4],r+=a[15&n]}return r}; | ||
//# sourceMappingURL=index.js.map |
@@ -66,3 +66,3 @@ /*! | ||
} | ||
return b; | ||
return Buffer.from(b); | ||
}; | ||
@@ -69,0 +69,0 @@ |
{ | ||
"name": "crypto-addr-codec", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Light weight package for serializing different crypto addresses", | ||
@@ -5,0 +5,0 @@ "source": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
3
103835
27
1803
1