@swtc/keypairs
Version:
swtc keypairs
3 lines (2 loc) • 36.6 kB
JavaScript
"use strict";var t=require("brorand"),e=require("inherits"),r=require("elliptic"),n=require("bn.js"),i=require("@swtc/address-codec"),s=require("@swtc/common");function o(t){var e=Object.create(null);return t&&Object.keys(t).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}}),e.default=t,Object.freeze(e)}var u=o(r);function c(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var a,f,p,l={},d={};function g(){if(f)return a;function t(t,e){if(!t)throw new Error(e||"Assertion failed")}return f=1,a=t,t.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)},a}function y(){if(p)return d;p=1;var t=g(),r=e;function n(t,e){return 55296==(64512&t.charCodeAt(e))&&(!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1)))}function i(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function s(t){return 1===t.length?"0"+t:t}function o(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}return d.inherits=r,d.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),s=0;s<t.length;s+=2)r.push(parseInt(t[s]+t[s+1],16))}else for(var i=0,s=0;s<t.length;s++){var o=t.charCodeAt(s);o<128?r[i++]=o:o<2048?(r[i++]=o>>6|192,r[i++]=63&o|128):n(t,s)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++s)),r[i++]=o>>18|240,r[i++]=o>>12&63|128,r[i++]=o>>6&63|128,r[i++]=63&o|128):(r[i++]=o>>12|224,r[i++]=o>>6&63|128,r[i++]=63&o|128)}else for(s=0;s<t.length;s++)r[s]=0|t[s];return r},d.toHex=function(t){for(var e="",r=0;r<t.length;r++)e+=s(t[r].toString(16));return e},d.htonl=i,d.toHex32=function(t,e){for(var r="",n=0;n<t.length;n++){var s=t[n];"little"===e&&(s=i(s)),r+=o(s.toString(16))}return r},d.zero2=s,d.zero8=o,d.join32=function(e,r,n,i){var s=n-r;t(s%4==0);for(var o=new Array(s/4),h=0,u=r;h<o.length;h++,u+=4){var c;c="big"===i?e[u]<<24|e[u+1]<<16|e[u+2]<<8|e[u+3]:e[u+3]<<24|e[u+2]<<16|e[u+1]<<8|e[u],o[h]=c>>>0}return o},d.split32=function(t,e){for(var r=new Array(4*t.length),n=0,i=0;n<t.length;n++,i+=4){var s=t[n];"big"===e?(r[i]=s>>>24,r[i+1]=s>>>16&255,r[i+2]=s>>>8&255,r[i+3]=255&s):(r[i+3]=s>>>24,r[i+2]=s>>>16&255,r[i+1]=s>>>8&255,r[i]=255&s)}return r},d.rotr32=function(t,e){return t>>>e|t<<32-e},d.rotl32=function(t,e){return t<<e|t>>>32-e},d.sum32=function(t,e){return t+e>>>0},d.sum32_3=function(t,e,r){return t+e+r>>>0},d.sum32_4=function(t,e,r,n){return t+e+r+n>>>0},d.sum32_5=function(t,e,r,n,i){return t+e+r+n+i>>>0},d.sum64=function(t,e,r,n){var i=t[e],s=n+t[e+1]>>>0,o=(s<n?1:0)+r+i;t[e]=o>>>0,t[e+1]=s},d.sum64_hi=function(t,e,r,n){return(e+n>>>0<e?1:0)+t+r>>>0},d.sum64_lo=function(t,e,r,n){return e+n>>>0},d.sum64_4_hi=function(t,e,r,n,i,s,o,h){var u=0,c=e;return u+=(c=c+n>>>0)<e?1:0,u+=(c=c+s>>>0)<s?1:0,t+r+i+o+(u+=(c=c+h>>>0)<h?1:0)>>>0},d.sum64_4_lo=function(t,e,r,n,i,s,o,h){return e+n+s+h>>>0},d.sum64_5_hi=function(t,e,r,n,i,s,o,h,u,c){var a=0,f=e;return a+=(f=f+n>>>0)<e?1:0,a+=(f=f+s>>>0)<s?1:0,a+=(f=f+h>>>0)<h?1:0,t+r+i+o+u+(a+=(f=f+c>>>0)<c?1:0)>>>0},d.sum64_5_lo=function(t,e,r,n,i,s,o,h,u,c){return e+n+s+h+c>>>0},d.rotr64_hi=function(t,e,r){return(e<<32-r|t>>>r)>>>0},d.rotr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},d.shr64_hi=function(t,e,r){return t>>>r},d.shr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},d}var v,m={};function F(){if(v)return m;v=1;var t=y(),e=g();function r(){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}return m.BlockHash=r,r.prototype.update=function(e,r){if(e=t.toArray(e,r),this.pending?this.pending=this.pending.concat(e):this.pending=e,this.pendingTotal+=e.length,this.pending.length>=this._delta8){var n=(e=this.pending).length%this._delta8;this.pending=e.slice(e.length-n,e.length),0===this.pending.length&&(this.pending=null),e=t.join32(e,0,e.length-n,this.endian);for(var i=0;i<e.length;i+=this._delta32)this._update(e,i,i+this._delta32)}return this},r.prototype.digest=function(t){return this.update(this._pad()),e(null===this.pending),this._digest(t)},r.prototype._pad=function(){var t=this.pendingTotal,e=this._delta8,r=e-(t+this.padLength)%e,n=new Array(r+this.padLength);n[0]=128;for(var i=1;i<r;i++)n[i]=0;if(t<<=3,"big"===this.endian){for(var s=8;s<this.padLength;s++)n[i++]=0;n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=t>>>24&255,n[i++]=t>>>16&255,n[i++]=t>>>8&255,n[i++]=255&t}else for(n[i++]=255&t,n[i++]=t>>>8&255,n[i++]=t>>>16&255,n[i++]=t>>>24&255,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,s=8;s<this.padLength;s++)n[i++]=0;return n},m}var b,w,_,B,k,S,A,T,H,E,K,z,C={},D={};function P(){if(b)return D;b=1;var t=y().rotr32;function e(t,e,r){return t&e^~t&r}function r(t,e,r){return t&e^t&r^e&r}function n(t,e,r){return t^e^r}return D.ft_1=function(t,i,s,o){return 0===t?e(i,s,o):1===t||3===t?n(i,s,o):2===t?r(i,s,o):void 0},D.ch32=e,D.maj32=r,D.p32=n,D.s0_256=function(e){return t(e,2)^t(e,13)^t(e,22)},D.s1_256=function(e){return t(e,6)^t(e,11)^t(e,25)},D.g0_256=function(e){return t(e,7)^t(e,18)^e>>>3},D.g1_256=function(e){return t(e,17)^t(e,19)^e>>>10},D}function M(){if(k)return B;k=1;var t=y(),e=F(),r=P(),n=g(),i=t.sum32,s=t.sum32_4,o=t.sum32_5,h=r.ch32,u=r.maj32,c=r.s0_256,a=r.s1_256,f=r.g0_256,p=r.g1_256,l=e.BlockHash,d=[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];function v(){if(!(this instanceof v))return new v;l.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=d,this.W=new Array(64)}return t.inherits(v,l),B=v,v.blockSize=512,v.outSize=256,v.hmacStrength=192,v.padLength=64,v.prototype._update=function(t,e){for(var r=this.W,l=0;l<16;l++)r[l]=t[e+l];for(;l<r.length;l++)r[l]=s(p(r[l-2]),r[l-7],f(r[l-15]),r[l-16]);var d=this.h[0],g=this.h[1],y=this.h[2],v=this.h[3],m=this.h[4],F=this.h[5],b=this.h[6],w=this.h[7];for(n(this.k.length===r.length),l=0;l<r.length;l++){var _=o(w,a(m),h(m,F,b),this.k[l],r[l]),x=i(c(d),u(d,g,y));w=b,b=F,F=m,m=i(v,_),v=y,y=g,g=d,d=i(_,x)}this.h[0]=i(this.h[0],d),this.h[1]=i(this.h[1],g),this.h[2]=i(this.h[2],y),this.h[3]=i(this.h[3],v),this.h[4]=i(this.h[4],m),this.h[5]=i(this.h[5],F),this.h[6]=i(this.h[6],b),this.h[7]=i(this.h[7],w)},v.prototype._digest=function(e){return"hex"===e?t.toHex32(this.h,"big"):t.split32(this.h,"big")},B}function j(){if(H)return T;H=1;var t=y(),e=F(),r=g(),n=t.rotr64_hi,i=t.rotr64_lo,s=t.shr64_hi,o=t.shr64_lo,h=t.sum64,u=t.sum64_hi,c=t.sum64_lo,a=t.sum64_4_hi,f=t.sum64_4_lo,p=t.sum64_5_hi,l=t.sum64_5_lo,d=e.BlockHash,v=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function m(){if(!(this instanceof m))return new m;d.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=v,this.W=new Array(160)}function b(t,e,r,n,i){var s=t&r^~t&i;return s<0&&(s+=4294967296),s}function w(t,e,r,n,i,s){var o=e&n^~e&s;return o<0&&(o+=4294967296),o}function _(t,e,r,n,i){var s=t&r^t&i^r&i;return s<0&&(s+=4294967296),s}function x(t,e,r,n,i,s){var o=e&n^e&s^n&s;return o<0&&(o+=4294967296),o}function B(t,e){var r=n(t,e,28)^n(e,t,2)^n(e,t,7);return r<0&&(r+=4294967296),r}function k(t,e){var r=i(t,e,28)^i(e,t,2)^i(e,t,7);return r<0&&(r+=4294967296),r}function S(t,e){var r=n(t,e,14)^n(t,e,18)^n(e,t,9);return r<0&&(r+=4294967296),r}function A(t,e){var r=i(t,e,14)^i(t,e,18)^i(e,t,9);return r<0&&(r+=4294967296),r}function E(t,e){var r=n(t,e,1)^n(t,e,8)^s(t,e,7);return r<0&&(r+=4294967296),r}function K(t,e){var r=i(t,e,1)^i(t,e,8)^o(t,e,7);return r<0&&(r+=4294967296),r}function z(t,e){var r=n(t,e,19)^n(e,t,29)^s(t,e,6);return r<0&&(r+=4294967296),r}function C(t,e){var r=i(t,e,19)^i(e,t,29)^o(t,e,6);return r<0&&(r+=4294967296),r}return t.inherits(m,d),T=m,m.blockSize=1024,m.outSize=512,m.hmacStrength=192,m.padLength=128,m.prototype._prepareBlock=function(t,e){for(var r=this.W,n=0;n<32;n++)r[n]=t[e+n];for(;n<r.length;n+=2){var i=z(r[n-4],r[n-3]),s=C(r[n-4],r[n-3]),o=r[n-14],h=r[n-13],u=E(r[n-30],r[n-29]),c=K(r[n-30],r[n-29]),p=r[n-32],l=r[n-31];r[n]=a(i,s,o,h,u,c,p,l),r[n+1]=f(i,s,o,h,u,c,p,l)}},m.prototype._update=function(t,e){this._prepareBlock(t,e);var n=this.W,i=this.h[0],s=this.h[1],o=this.h[2],a=this.h[3],f=this.h[4],d=this.h[5],g=this.h[6],y=this.h[7],v=this.h[8],m=this.h[9],F=this.h[10],T=this.h[11],H=this.h[12],E=this.h[13],K=this.h[14],z=this.h[15];r(this.k.length===n.length);for(var C=0;C<n.length;C+=2){var D=K,P=z,M=S(v,m),j=A(v,m),R=b(v,m,F,T,H),V=w(v,m,F,T,H,E),q=this.k[C],L=this.k[C+1],N=n[C],I=n[C+1],U=p(D,P,M,j,R,V,q,L,N,I),W=l(D,P,M,j,R,V,q,L,N,I);D=B(i,s),P=k(i,s),M=_(i,s,o,a,f),j=x(i,s,o,a,f,d);var Y=u(D,P,M,j),O=c(D,P,M,j);K=H,z=E,H=F,E=T,F=v,T=m,v=u(g,y,U,W),m=c(y,y,U,W),g=f,y=d,f=o,d=a,o=i,a=s,i=u(U,W,Y,O),s=c(U,W,Y,O)}h(this.h,0,i,s),h(this.h,2,o,a),h(this.h,4,f,d),h(this.h,6,g,y),h(this.h,8,v,m),h(this.h,10,F,T),h(this.h,12,H,E),h(this.h,14,K,z)},m.prototype._digest=function(e){return"hex"===e?t.toHex32(this.h,"big"):t.split32(this.h,"big")},T}function R(){return z||(z=1,C.sha1=function(){if(_)return w;_=1;var t=y(),e=F(),r=P(),n=t.rotl32,i=t.sum32,s=t.sum32_5,o=r.ft_1,h=e.BlockHash,u=[1518500249,1859775393,2400959708,3395469782];function c(){if(!(this instanceof c))return new c;h.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}return t.inherits(c,h),w=c,c.blockSize=512,c.outSize=160,c.hmacStrength=80,c.padLength=64,c.prototype._update=function(t,e){for(var r=this.W,h=0;h<16;h++)r[h]=t[e+h];for(;h<r.length;h++)r[h]=n(r[h-3]^r[h-8]^r[h-14]^r[h-16],1);var c=this.h[0],a=this.h[1],f=this.h[2],p=this.h[3],l=this.h[4];for(h=0;h<r.length;h++){var d=~~(h/20),g=s(n(c,5),o(d,a,f,p),l,r[h],u[d]);l=p,p=f,f=n(a,30),a=c,c=g}this.h[0]=i(this.h[0],c),this.h[1]=i(this.h[1],a),this.h[2]=i(this.h[2],f),this.h[3]=i(this.h[3],p),this.h[4]=i(this.h[4],l)},c.prototype._digest=function(e){return"hex"===e?t.toHex32(this.h,"big"):t.split32(this.h,"big")},w}(),C.sha224=function(){if(A)return S;A=1;var t=y(),e=M();function r(){if(!(this instanceof r))return new r;e.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}return t.inherits(r,e),S=r,r.blockSize=512,r.outSize=224,r.hmacStrength=192,r.padLength=64,r.prototype._digest=function(e){return"hex"===e?t.toHex32(this.h.slice(0,7),"big"):t.split32(this.h.slice(0,7),"big")},S}(),C.sha256=M(),C.sha384=function(){if(K)return E;K=1;var t=y(),e=j();function r(){if(!(this instanceof r))return new r;e.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}return t.inherits(r,e),E=r,r.blockSize=1024,r.outSize=384,r.hmacStrength=192,r.padLength=128,r.prototype._digest=function(e){return"hex"===e?t.toHex32(this.h.slice(0,12),"big"):t.split32(this.h.slice(0,12),"big")},E}(),C.sha512=j()),C}var V,q,L,N,I={};function U(){return N||(N=1,function(t){var e=t;e.utils=y(),e.common=F(),e.sha=R(),e.ripemd=function(){if(V)return I;V=1;var t=y(),e=F(),r=t.rotl32,n=t.sum32,i=t.sum32_3,s=t.sum32_4,o=e.BlockHash;function h(){if(!(this instanceof h))return new h;o.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}function u(t,e,r,n){return t<=15?e^r^n:t<=31?e&r|~e&n:t<=47?(e|~r)^n:t<=63?e&n|r&~n:e^(r|~n)}function c(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function a(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}t.inherits(h,o),I.ripemd160=h,h.blockSize=512,h.outSize=160,h.hmacStrength=192,h.padLength=64,h.prototype._update=function(t,e){for(var o=this.h[0],h=this.h[1],g=this.h[2],y=this.h[3],v=this.h[4],m=o,F=h,b=g,w=y,_=v,x=0;x<80;x++){var B=n(r(s(o,u(x,h,g,y),t[f[x]+e],c(x)),l[x]),v);o=v,v=y,y=r(g,10),g=h,h=B,B=n(r(s(m,u(79-x,F,b,w),t[p[x]+e],a(x)),d[x]),_),m=_,_=w,w=r(b,10),b=F,F=B}B=i(this.h[1],g,w),this.h[1]=i(this.h[2],y,_),this.h[2]=i(this.h[3],v,m),this.h[3]=i(this.h[4],o,F),this.h[4]=i(this.h[0],h,b),this.h[0]=B},h.prototype._digest=function(e){return"hex"===e?t.toHex32(this.h,"little"):t.split32(this.h,"little")};var f=[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],p=[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],l=[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],d=[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];return I}(),e.hmac=function(){if(L)return q;L=1;var t=y(),e=g();function r(e,n,i){if(!(this instanceof r))return new r(e,n,i);this.Hash=e,this.blockSize=e.blockSize/8,this.outSize=e.outSize/8,this.inner=null,this.outer=null,this._init(t.toArray(n,i))}return q=r,r.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),e(t.length<=this.blockSize);for(var r=t.length;r<this.blockSize;r++)t.push(0);for(r=0;r<t.length;r++)t[r]^=54;for(this.inner=(new this.Hash).update(t),r=0;r<t.length;r++)t[r]^=106;this.outer=(new this.Hash).update(t)},r.prototype.update=function(t,e){return this.inner.update(t,e),this},r.prototype.digest=function(t){return this.outer.update(this.inner.digest()),this.outer.digest(t)},q}(),e.sha1=e.sha.sha1,e.sha256=e.sha.sha256,e.sha224=e.sha.sha224,e.sha384=e.sha.sha384,e.sha512=e.sha.sha512,e.ripemd160=e.ripemd.ripemd160}(l)),l}var W,Y,O,X=c(U()),Z={},G={};function J(){return W||(W=1,function(){var t=G;function e(t){return 1===t.length?"0"+t:t}function r(t){for(var r="",n=0;n<t.length;n++)r+=e(t[n].toString(16));return r}t.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"!=typeof t){for(var n=0;n<t.length;n++)r[n]=0|t[n];return r}if("hex"===e){(t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t);for(n=0;n<t.length;n+=2)r.push(parseInt(t[n]+t[n+1],16))}else for(n=0;n<t.length;n++){var i=t.charCodeAt(n),s=i>>8,o=255&i;s?r.push(s,o):r.push(o)}return r},t.zero2=e,t.toHex=r,t.encode=function(t,e){return"hex"===e?r(t):t}}()),G}var Q,$,tt,et,rt,nt,it={},st={};function ot(){return Q||(Q=1,function(e){var r=e,i=n,s=t;r.strToBytes=function(t){for(var e,r,n=[],i=0;i<t.length;i++){e=t.charCodeAt(i),r=[];do{r.push(255&e),e>>=8}while(e);n=n.concat(r.reverse())}return n},r.hashToBN=function(t){if("string"==typeof t)return new i(t,16);for(var e="",r=0;r<t.length;r++){var n=t[r].toString(16);1==n.length&&(e+="0"),e+=n}return new i(e,16)},r.random=function(t){return s(t).toString("hex")},r.padStart=function(t,e,r){return t.length>=e?t:r.repeat(e-t.length)+t}}(st)),st}function ht(){if(tt)return $;tt=1;var t=ot();function e(){if(!(this instanceof e))return new e;this.reg=new Array(8),this.chunk=[],this.size=0,this.reset()}function r(t,e){return(t<<(e%=32)|t>>>32-e)>>>0}function n(t){return 0<=t&&t<16?2043430169:16<=t&&t<64?2055708042:void console.error("invalid j for constant Tj")}function i(t,e,r,n){return 0<=t&&t<16?(e^r^n)>>>0:16<=t&&t<64?(e&r|e&n|r&n)>>>0:(console.error("invalid j for bool function FF"),0)}function s(t,e,r,n){return 0<=t&&t<16?(e^r^n)>>>0:16<=t&&t<64?(e&r|~e&n)>>>0:(console.error("invalid j for bool function GG"),0)}return $=e,e.prototype.reset=function(){this.reg[0]=1937774191,this.reg[1]=1226093241,this.reg[2]=388252375,this.reg[3]=3666478592,this.reg[4]=2842636476,this.reg[5]=372324522,this.reg[6]=3817729613,this.reg[7]=2969243214,this.chunk=[],this.size=0},e.prototype.write=function(e){var r="string"==typeof e?t.strToBytes(e):e;this.size+=r.length;var n=64-this.chunk.length;if(r.length<n)this.chunk=this.chunk.concat(r);else for(this.chunk=this.chunk.concat(r.slice(0,n));this.chunk.length>=64;)this._compress(this.chunk),n<r.length?this.chunk=r.slice(n,Math.min(n+64,r.length)):this.chunk=[],n+=64},e.prototype.sum=function(e,r){e&&(this.reset(),this.write(e)),this._fill();for(var n=0;n<this.chunk.length;n+=64)this._compress(this.chunk.slice(n,n+64));var i=null;if("hex"==r){i="";for(n=0;n<8;n++)i+=t.padStart(this.reg[n].toString(16),8,"0")}else for(i=new Array(32),n=0;n<8;n++)h=this.reg[n],i[4*n+3]=(255&h)>>>0,h>>>=8,i[4*n+2]=(255&h)>>>0,h>>>=8,i[4*n+1]=(255&h)>>>0,h>>>=8,i[4*n]=(255&h)>>>0;return this.reset(),i},e.prototype._compress=function(t){if(t<64)console.error("compress error: not enough data");else{for(var e=function(t){for(var e=new Array(132),n=0;n<16;n++)e[n]=t[4*n]<<24,e[n]|=t[4*n+1]<<16,e[n]|=t[4*n+2]<<8,e[n]|=t[4*n+3],e[n]>>>=0;for(var i=16;i<68;i++)x=e[i-16]^e[i-9]^r(e[i-3],15),x=x^r(x,15)^r(x,23),e[i]=(x^r(e[i-13],7)^e[i-6])>>>0;for(i=0;i<64;i++)e[i+68]=(e[i]^e[i+4])>>>0;return e}(t),o=this.reg.slice(0),h=0;h<64;h++){var u=r(o[0],12)+o[4]+r(n(h),h),c=((u=r(u=(4294967295&u)>>>0,7))^r(o[0],12))>>>0,a=i(h,o[0],o[1],o[2]);a=(4294967295&(a=a+o[3]+c+e[h+68]))>>>0;var f=s(h,o[4],o[5],o[6]);f=(4294967295&(f=f+o[7]+u+e[h]))>>>0,o[3]=o[2],o[2]=r(o[1],9),o[1]=o[0],o[0]=a,o[7]=o[6],o[6]=r(o[5],19),o[5]=o[4],o[4]=(f^r(f,9)^r(f,17))>>>0}for(var p=0;p<8;p++)this.reg[p]=(this.reg[p]^o[p])>>>0}},e.prototype._fill=function(){var t=8*this.size,e=this.chunk.push(128)%64;for(64-e<8&&(e-=64);e<56;e++)this.chunk.push(0);for(var r=0;r<4;r++){var n=Math.floor(t/4294967296);this.chunk.push(n>>>8*(3-r)&255)}for(r=0;r<4;r++)this.chunk.push(t>>>8*(3-r)&255)},$}function ut(){if(nt)return it;nt=1;var t,i=ht(),s=ot(),o=r,u=n,c=function(){if(rt)return et;rt=1;var t=U(),e=J(),r=g();function n(t){if(!(this instanceof n))return new n(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var i=e.toArray(t.entropy,t.entropyEnc||"hex"),s=e.toArray(t.nonce,t.nonceEnc||"hex"),o=e.toArray(t.pers,t.persEnc||"hex");r(i.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(i,s,o)}return et=n,n.prototype._init=function(t,e,r){var n=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var i=0;i<this.V.length;i++)this.K[i]=0,this.V[i]=1;this._update(n),this._reseed=1,this.reseedInterval=281474976710656},n.prototype._hmac=function(){return new t.hmac(this.hash,this.K)},n.prototype._update=function(t){var e=this._hmac().update(this.V).update([0]);t&&(e=e.update(t)),this.K=e.digest(),this.V=this._hmac().update(this.V).digest(),t&&(this.K=this._hmac().update(this.V).update([1]).update(t).digest(),this.V=this._hmac().update(this.V).digest())},n.prototype.reseed=function(t,n,i,s){"string"!=typeof n&&(s=i,i=n,n=null),t=e.toArray(t,n),i=e.toArray(i,s),r(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(i||[])),this._reseed=1},n.prototype.generate=function(t,r,n,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof r&&(i=n,n=r,r=null),n&&(n=e.toArray(n,i||"hex"),this._update(n));for(var s=[];s.length<t;)this.V=this._hmac().update(this.V).digest(),s=s.concat(this.V);var o=s.slice(0,t);return this._update(n),this._reseed++,e.encode(o,r)},et}(),a=U(),f=e,p=new c({hash:a.sha256,entropy:"UQi4W3Y2bJfzleYy+oEZ2kA9A+9jrmwewST9vmBZNgMmFyzzH0S9Vol/UK",nonce:"0123456789avcdef",pers:"0123456789abcdef"});function l(t){if(!(this instanceof l))return new l(t);o.curve.short.call(this,t)}function d(e,r,n){if(null==e)return t.point();var i;if(null!=r){if(i=t.point(e,r),!t.validate(i))throw"point is not on curve"}else{var s=new u(e,16).toRed(t.red),o=s.redSqr().redMul(s);"odd"===n!=(o=o.redIAdd(s.redMul(t.a)).redIAdd(t.b).redSqrt()).fromRed().isOdd()&&(o=o.redNeg()),i=t.point(s,o)}return i}function y(e,r){if(!(this instanceof y))return new y(e,r);this.curve=t,this.pub=null,this.pri=null;var n=!1,i=!1;if(null!=e)if("string"==typeof e)this._pubFromString(e);else if(Array.isArray(e))this._pubFromBytes(e);else{if(!("x"in e&&u.isBN(e.x)&&"y"in e&&u.isBN(e.y)))throw"invalid public key";this.pub=e,n=!0}if(null!=r){if("string"==typeof r)this.pri=new u(r,16);else{if(!u.isBN(r))throw"invalid private key";this.pri=r,i=!0}null==this.pub&&(this.pub=t.g.mul(this.pri))}if(!(n&&i||this.validate()))throw"invalid key"}return f(l,o.curve.short),t=l({type:"SM2",prime:null,p:"FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 00000000 FFFFFFFF FFFFFFFF",a:"FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 00000000 FFFFFFFF FFFFFFFC",b:"28E9FA9E 9D9F5E34 4D5A9E4B CF6509A7 F39789F5 15AB8F92 DDBCBD41 4D940E93",n:"FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF 7203DF6B 21C6052B 53BBF409 39D54123",hash:i,gRed:!1,g:["32C4AE2C 1F198119 5F990446 6A39C994 8FE30BBF F2660BE1 715A4589 334C74C7","BC3736A2 F4F6779C 59BDCEE3 6B692153 D0A9877C C62A4740 02DF32E5 2139F0A0"]}),it.curve=t,it.SM2KeyPair=y,it.genKeyPair=function(){var e=0,r=t.n.sub(new u(2));do{e=new u(p.generate(32,"hex",s.random(64)))}while(e.cmp(r)>0);return new y(null,e)},y.prototype._pubFromString=function(t){var e="invalid key string";if(t.length<66)throw e;var r=t.slice(2,66);switch(t.slice(0,2)){case"00":throw"public key should not be infinity";case"02":this.pub=d(r,null,"even");break;case"03":this.pub=d(r,null,"odd");break;case"04":case"06":case"07":if(t.length<130)throw e;this.pub=d(r,t.slice(66,130));break;default:throw e}},y.prototype._pubFromBytes=function(t){var e="unrecognized key";if(t.length<33)throw e;var r=t.slice(1,33);switch(t[0]){case 0:throw"public key should not be infinity";case 2:this.pub=d(r,null,"even");break;case 3:this.pub=d(r,null,"odd");break;case 4:case 6:case 7:if(t.length<65)throw e;this.pub=d(r,t.slice(33,65));break;default:throw e}},y.prototype.validate=function(){if(null!=this.pub){if(this.pub.isInfinity())return!1;if(!this.curve.validate(this.pub))return!1;if(!this.pub.mul(this.curve.n).isInfinity())return!1}if(null!=this.pri){if(this.pri.cmp(this.curve.n.sub(new u(2)))>0)return!1;if(null!=this.pub&&!this.pub.eq(this.curve.g.mul(this.pri)))return!1}return!0},y.prototype.pubToString=function(t){var e="";switch(t){case"compress":return(e=this.pub.getY().isEven()?"02":"03")+this.pub.getX().toString(16,32);case"mix":e=this.pub.getY().isEven()?"06":"07";break;default:e="04"}return e+this.pub.getX().toString(16,32)+this.pub.getY().toString(16,32)},y.prototype.pubToBytes=function(t){var e=[];switch(t){case"compress":return this.pub.getY().isEven()?e.push(2):e.push(3),e.concat(this.pub.getX().toArray("be",32));case"mix":this.pub.getY().isEven()?e.push(6):e.push(7);break;default:e.push(4)}return e.concat(this.pub.getX().toArray("be",32)).concat(this.pub.getY().toArray("be",32))},y.prototype.sign=function(t){if(null==this.pri)throw"cannot sign message without private key";return"string"==typeof t?this.signDigest((new i).sum(this._combine(s.strToBytes(t)))):this.signDigest((new i).sum(this._combine(t)))},y.prototype.verify=function(t,e,r){if(null==this.pub)throw"cannot verify signature without public key";return this.verifyDigest((new i).sum(this._combine(t)),e,r)},y.prototype.signRaw=function(t){return this.signDigest((new i).sum(t))},y.prototype.verifyRaw=function(t,e,r){return this.verifyDigest((new i).sum(t),e,r)},y.prototype.signDigest=function(t){for(var e={r:"",s:""};;){var r=new u(p.generate(32,"hex",s.random(64)),16).umod(this.curve.n),n=this.curve.g.mul(r),i=s.hashToBN(t).add(n.getX()).umod(this.curve.n);if(!i.isZero()&&!i.add(r).eq(this.curve.n)){var o=new u(1).add(this.pri).invm(this.curve.n),h=r.sub(i.mul(this.pri)).umod(this.curve.n),c=o.mul(h).umod(this.curve.n);if(!c.isZero()){e.r=s.padStart(i.toString(16),64,"0"),e.s=s.padStart(c.toString(16),64,"0");break}}}return e},y.prototype.verifyDigest=function(t,e,r){var n=new u(e,16);if(n.cmp(this.curve.n)>=0)return!1;var i=new u(r,16);if(i.cmp(this.curve.n)>=0)return!1;var o=n.add(i).umod(this.curve.n);if(o.isZero())return!1;var h=this.curve.g.mul(i).add(this.pub.mul(o));return!!s.hashToBN(t).add(h.getX()).umod(this.curve.n).eq(n)},y.prototype._combine=function(t){var e=[0,128,49,50,51,52,53,54,55,56,49,50,51,52,53,54,55,56];return e=(e=(e=(e=(e=(e=e.concat(this.curve.a.fromRed().toArray())).concat(this.curve.b.fromRed().toArray())).concat(this.curve.g.getX().toArray())).concat(this.curve.g.getY().toArray())).concat(this.pub.getX().toArray())).concat(this.pub.getY().toArray()),h=new i,e=h.sum(e),"string"==typeof t?e.concat(s.strToBytes(t)):e.concat(t)},y.prototype.toString=function(){var t="public: ";return this.pub?t+="("+this.pub.getX().toString(16)+", "+this.pub.getY().toString(16)+")":t+="null",t+=", private: ",this.pri?t+=s.padStart(this.pri.toString(16),64,"0"):t+="null",t},it}var ct,at="0.1.12";var ft,pt=(ct||(ct=1,(ft=Z).Signature=function(){if(O)return Y;O=1;var t=n,e=J(),r=g();function i(e,n){if(e instanceof i)return e;this._importDER(e,n)||(r(e.r&&e.s,"Signature without r or s"),this.r=new t(e.r,16),this.s=new t(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}function s(){this.place=0}function o(t,e){var r=t[e.place++];if(!(128&r))return r;var n=15&r;if(0===n||n>4)return!1;for(var i=0,s=0,o=e.place;s<n;s++,o++)i<<=8,i|=t[o],i>>>=0;return!(i<=127)&&(e.place=o,i)}function h(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e<r;)e++;return 0===e?t:t.slice(e)}function u(t,e){if(e<128)t.push(e);else{var r=1+(Math.log(e)/Math.LN2>>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}return Y=i,i.prototype._importDER=function(r,n){r=e.toArray(r,n);var i=new s;if(48!==r[i.place++])return!1;var h=o(r,i);if(!1===h)return!1;if(h+i.place!==r.length)return!1;if(2!==r[i.place++])return!1;var u=o(r,i);if(!1===u)return!1;var c=r.slice(i.place,u+i.place);if(i.place+=u,2!==r[i.place++])return!1;var a=o(r,i);if(!1===a)return!1;if(r.length!==a+i.place)return!1;var f=r.slice(i.place,a+i.place);if(0===c[0]){if(!(128&c[1]))return!1;c=c.slice(1)}if(0===f[0]){if(!(128&f[1]))return!1;f=f.slice(1)}return this.r=new t(c),this.s=new t(f),this.recoveryParam=null,!0},i.prototype.toDER=function(t){var r=this.r.toArray(),n=this.s.toArray();for(128&r[0]&&(r=[0].concat(r)),128&n[0]&&(n=[0].concat(n)),r=h(r),n=h(n);!(n[0]||128&n[1]);)n=n.slice(1);var i=[2];u(i,r.length),(i=i.concat(r)).push(2),u(i,n.length);var s=i.concat(n),o=[48];return u(o,s.length),o=o.concat(s),e.encode(o,t)},Y}(),ft.sm2=ut(),ft.sm3=ht(),ft.version=at),Z);class lt{constructor(){this.hash=X.sha512()}add(t){return this.hash.update(t),this}addU32(t){return this.add([t>>>24&255,t>>>16&255,t>>>8&255,255&t])}finish(){return this.hash.digest()}first256(){return this.finish().slice(0,32)}first256BN(){return new n(this.first256())}}const dt=u.ec("secp256k1");function gt(t,e){const r=dt.curve.n;for(let n=0;n<=4294967295;n++){const i=(new lt).add(t);void 0!==e&&i.addU32(e),i.addU32(n);const s=i.first256BN();if(s.cmpn(0)>0&&s.cmp(r)<0)return s}throw new Error("impossible unicorn ;)")}function yt(t,e={}){const r=e.validator,n=dt.curve.n,i=gt(t);if(r)return i;const s=dt.g.mul(i),o=e.accountIndex||0;return gt(s.encodeCompressed(),o).add(i).mod(n)}function vt(t){const e=dt.curve.decodePoint(t),r=gt(t,0),n=dt.g.mul(r);return e.add(n).encodeCompressed()}function mt(t,e){const r=pt.sm2.curve.n;for(let i=0;i<=4294967295;i++){const o=void 0!==e?Buffer.alloc(41):Buffer.alloc(20);o.fill(Buffer.from(t),0,t.length),void 0!==e&&(o.writeUIntBE(e,t.length,4),o.writeUIntBE(i,t.length+4,4)),o.writeUIntBE(i,t.length,4);const h=(new s.SM3).update(o).digest("hex"),u=new n(h,"hex");if(u.cmpn(0)>0&&u.cmp(r)<0)return u}throw new Error("impossible unicorn ;)")}function Ft(t){return X.sha512().update(t).digest().slice(0,16)}function bt(t){return(new s.SM3).update(t).digest().slice(0,16)}const wt=r.eddsa("ed25519"),_t=r.ec("secp256k1");function xt(t){return X.sha512().update(t).digest().slice(0,32)}function Bt(t){return(new s.SM3).update(t).digest().slice(0,32)}function kt(e="jingtum"){const r=i.Factory(e),o=r.guomi,h=r.token,u=o?Bt:xt,c={deriveKeypair:(t,e={})=>{const r="00"+yt(t,e).toString(16,64).toUpperCase(),n=s.funcBytesToHex(_t.keyFromPrivate(r.slice(2)).getPublic().encodeCompressed());return{privateKey:r,publicKey:n}},deriveKeypairWithPrivateKey:t=>{const e="00"+t.toUpperCase(),r=s.funcBytesToHex(_t.keyFromPrivate(e.slice(2)).getPublic().encodeCompressed());return{privateKey:e,publicKey:r}},sign:(t,e)=>s.funcBytesToHex(_t.sign(u(t),s.funcHexToBytes(e),{canonical:!0}).toDER()),verify:(t,e,r)=>_t.verify(u(t),e,s.funcHexToBytes(r)),signTx:(t,e)=>s.funcBytesToHex(_t.sign(t,s.funcHexToBytes(e),{canonical:!0}).toDER()),verifyTx:(t,e,r)=>_t.verify(t,e,s.funcHexToBytes(r))},a={deriveKeypair:(t,e={})=>{const r=function(t,e={}){const r=e.validator,n=pt.sm2.curve.n,i=mt(t);if(r)return i;const s=pt.sm2.curve.g.mul(i),o=e.accountIndex||0;return mt(s.encodeCompressed(),o).add(i).mod(n)}(t,e);return{privateKey:"00"+r.toString(16,64).toUpperCase(),publicKey:s.funcBytesToHex(pt.sm2.SM2KeyPair(null,r).pub.encodeCompressed())}},deriveKeypairWithPrivateKey:t=>{const e=new n(t,"hex");return{privateKey:"00"+t.toUpperCase(),publicKey:s.funcBytesToHex(pt.sm2.SM2KeyPair(null,e).pub.encodeCompressed())}},sign:(t,e)=>{const r=pt.sm2.SM2KeyPair(null,new n(e,"hex"));return s.funcBytesToHex(new pt.Signature(r.sign(u(t))).toDER())},verify:(t,e,r)=>{const n=pt.sm2.SM2KeyPair(r),i=new pt.Signature(e,"hex");return n.verify(u(t),i.r,i.s)},signTx:(t,e)=>{"string"==typeof t&&/^[0-9A-F]{16}/i.test(t)&&(t=s.funcHexToBytes(t));const r=pt.sm2.SM2KeyPair(null,new n(e,"hex"));return s.funcBytesToHex(new pt.Signature(r.sign(t)).toDER())},verifyTx:(t,e,r)=>{"string"==typeof t&&/^[0-9A-F]{16}/i.test(t)&&(t=s.funcHexToBytes(t));const n=pt.sm2.SM2KeyPair(r),i=new pt.Signature(e,"hex");return n.verify(u(t),i.r,i.s)}},f={deriveKeypair:t=>{const e=u(t);return{privateKey:"ED"+s.funcBytesToHex(e),publicKey:"ED"+s.funcBytesToHex(wt.keyFromSecret(e).pubBytes())}},deriveKeypairWithPrivateKey:t=>({privateKey:"ED"+t.toUpperCase(),publicKey:"ED"+s.funcBytesToHex(wt.keyFromSecret(s.funcHexToBytes(t)).pubBytes())}),sign:(t,e)=>(s.funcAssert(Array.isArray(t),"message must be array of octets"),s.funcBytesToHex(wt.sign(t,s.funcHexToBytes(e).slice(1)).toBytes())),verify:(t,e,r)=>wt.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1)),signTx:(t,e)=>wt.sign(t,s.funcHexToBytes(e).slice(1)).toHex(),verifyTx:(t,e,r)=>wt.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1))},p={deriveKeypair:t=>{const e=u(t);return{privateKey:"ED"+s.funcBytesToHex(e),publicKey:"ED"+s.funcBytesToHex(wt.keyFromSecret(e).pubBytes())}},deriveKeypairWithPrivateKey:t=>({privateKey:"ED"+t.toUpperCase(),publicKey:"ED"+s.funcBytesToHex(wt.keyFromSecret(s.funcHexToBytes(t)).pubBytes())}),sign:(t,e)=>(s.funcAssert(Array.isArray(t),"message must be array of octets"),s.funcBytesToHex(wt.sign(t,s.funcHexToBytes(e).slice(1)).toBytes())),verify:(t,e,r)=>wt.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1)),signTx:(t,e)=>wt.sign(t,s.funcHexToBytes(e).slice(1)).toHex(),verifyTx:(t,e,r)=>wt.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1))};function l(t){const e={secp256k1:c,sm2p256v1:a,ed25519:f,ed25519guomi:p};return"ed25519"===t?o?e.ed25519guomi:e.ed25519:e[t]}function d(t){const e=s.funcHexToBytes(t);return 33===e.length&&237===e[0]?"ed25519":o?"sm2p256v1":"secp256k1"}function g(t,e=(o?"sm2p256v1":"secp256k1")){const n=t;let i,s,h=t;if("string"!=typeof t)throw new Error("deriving keypair requires secret or private key");if(/^s/.test(t)){const t=r.decodeSeed(n);s=l(e="ed25519"===t.type?"ed25519":o?"sm2p256v1":"secp256k1"),i=s.deriveKeypair(t.bytes)}else{if(64===t.length)e="ed25519"===e?"ed25519":o?"sm2p256v1":"secp256k1";else{if(66!==t.length)throw new Error("deriving keypair requires valid private key");if("00"===t.slice(0,2))e=o?"sm2p256v1":"secp256k1";else{if("ED"!==t.slice(0,2).toUpperCase())throw new Error("deriving keypair requires correct prefixed private key");e="ed25519"}h=t.slice(2)}s=l(e),i=s.deriveKeypairWithPrivateKey(h)}const c=u("This test message should verify."),a=s.sign(c,i.privateKey);if(!0!==s.verify(c,a,i.publicKey))throw new Error("derived keypair did not generate verifiable signature");return i}function y(t){return r.encodeAccountID(Buffer.from(o?function(t){const e=(new s.SM3).update(t).digest();return X.ripemd160().update(e).digest()}(t):function(t){const e=X.sha256().update(t).digest();return X.ripemd160().update(e).digest()}(t)))}return{guomi:o,token:h,addressCodec:r,deriveKeyPair:g,hash:u,seedFromPhrase:o?bt:Ft,signTx:function(t,e){return l(d(e)).signTx(t,e)},verifyTx:function(t,e,r){return l(d(r)).verifyTx(t,e,r)},convertAddressToBytes:function(t){return r.decodeAddress(t).toJSON().data},convertBytesToAddress:function(t){return r.encodeAddress(t)},checkAddress:r.isValidAddress,isValidAddress:r.isValidAddress,deriveKeypair:g,generateSeed:function(e={}){s.funcAssert(!e.entropy||e.entropy.length>=16,"entropy too short");const n=e.entropy?e.entropy.slice(0,16):t(16),i="ed25519"===e.algorithm?"ed25519":o?"sm2p256v1":"secp256k1";return r.encodeSeed(n,i)},sign:function(t,e){return l(d(e)).sign(s.funcHexToBytes(t),e)},verify:function(t,e,r){return l(d(r)).verify(s.funcHexToBytes(t),e,r)},deriveAddress:function(t){return y(s.funcHexToBytes(t))},deriveNodeAddress:function(t){const e=r.decodeNodePublic(t);return y(o?function(t){const e=pt.sm2.curve.decodePoint(t),r=mt(t,0),n=pt.sm2.curve.g.mul(r);return e.add(n).encodeCompressed()}(e):vt(e))}}}const St=kt(),At=kt("guomi");exports.Factory=kt,exports.Keypairs=St,exports.KeypairsGm=At,exports.sm2=pt.sm2;
//# sourceMappingURL=index.js.map