UNPKG

@swtc/keypairs

Version:
3 lines (2 loc) 38.1 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("brorand"),e=require("inherits"),r=require("elliptic"),i=require("bn.js"),n=require("@swtc/address-codec"),s=require("@swtc/common");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function u(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var c=o(t),a=o(e),f=o(r),l=u(r),p=o(i);function d(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}var g=y;function y(t,e){if(!t)throw new Error(e||"Assertion failed")}function v(t,e){return 55296==(64512&t.charCodeAt(e))&&(!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1)))}function m(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function F(t){return 1===t.length?"0"+t:t}function b(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}y.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var w={inherits:a.default,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),n=0;n<t.length;n+=2)r.push(parseInt(t[n]+t[n+1],16))}else for(var i=0,n=0;n<t.length;n++){var s=t.charCodeAt(n);s<128?r[i++]=s:s<2048?(r[i++]=s>>6|192,r[i++]=63&s|128):v(t,n)?(s=65536+((1023&s)<<10)+(1023&t.charCodeAt(++n)),r[i++]=s>>18|240,r[i++]=s>>12&63|128,r[i++]=s>>6&63|128,r[i++]=63&s|128):(r[i++]=s>>12|224,r[i++]=s>>6&63|128,r[i++]=63&s|128)}else for(n=0;n<t.length;n++)r[n]=0|t[n];return r},toHex:function(t){for(var e="",r=0;r<t.length;r++)e+=F(t[r].toString(16));return e},htonl:m,toHex32:function(t,e){for(var r="",i=0;i<t.length;i++){var n=t[i];"little"===e&&(n=m(n)),r+=b(n.toString(16))}return r},zero2:F,zero8:b,join32:function(t,e,r,i){var n=r-e;g(n%4==0);for(var s=new Array(n/4),o=0,h=e;o<s.length;o++,h+=4){var u;u="big"===i?t[h]<<24|t[h+1]<<16|t[h+2]<<8|t[h+3]:t[h+3]<<24|t[h+2]<<16|t[h+1]<<8|t[h],s[o]=u>>>0}return s},split32:function(t,e){for(var r=new Array(4*t.length),i=0,n=0;i<t.length;i++,n+=4){var s=t[i];"big"===e?(r[n]=s>>>24,r[n+1]=s>>>16&255,r[n+2]=s>>>8&255,r[n+3]=255&s):(r[n+3]=s>>>24,r[n+2]=s>>>16&255,r[n+1]=s>>>8&255,r[n]=255&s)}return r},rotr32:function(t,e){return t>>>e|t<<32-e},rotl32:function(t,e){return t<<e|t>>>32-e},sum32:function(t,e){return t+e>>>0},sum32_3:function(t,e,r){return t+e+r>>>0},sum32_4:function(t,e,r,i){return t+e+r+i>>>0},sum32_5:function(t,e,r,i,n){return t+e+r+i+n>>>0},sum64:function(t,e,r,i){var n=t[e],s=i+t[e+1]>>>0,o=(s<i?1:0)+r+n;t[e]=o>>>0,t[e+1]=s},sum64_hi:function(t,e,r,i){return(e+i>>>0<e?1:0)+t+r>>>0},sum64_lo:function(t,e,r,i){return e+i>>>0},sum64_4_hi:function(t,e,r,i,n,s,o,h){var u=0,c=e;return u+=(c=c+i>>>0)<e?1:0,u+=(c=c+s>>>0)<s?1:0,t+r+n+o+(u+=(c=c+h>>>0)<h?1:0)>>>0},sum64_4_lo:function(t,e,r,i,n,s,o,h){return e+i+s+h>>>0},sum64_5_hi:function(t,e,r,i,n,s,o,h,u,c){var a=0,f=e;return a+=(f=f+i>>>0)<e?1:0,a+=(f=f+s>>>0)<s?1:0,a+=(f=f+h>>>0)<h?1:0,t+r+n+o+u+(a+=(f=f+c>>>0)<c?1:0)>>>0},sum64_5_lo:function(t,e,r,i,n,s,o,h,u,c){return e+i+s+h+c>>>0},rotr64_hi:function(t,e,r){return(e<<32-r|t>>>r)>>>0},rotr64_lo:function(t,e,r){return(t<<32-r|e>>>r)>>>0},shr64_hi:function(t,e,r){return t>>>r},shr64_lo:function(t,e,r){return(t<<32-r|e>>>r)>>>0}};function _(){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 B=_;_.prototype.update=function(t,e){if(t=w.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=w.join32(t,0,t.length-r,this.endian);for(var i=0;i<t.length;i+=this._delta32)this._update(t,i,i+this._delta32)}return this},_.prototype.digest=function(t){return this.update(this._pad()),g(null===this.pending),this._digest(t)},_.prototype._pad=function(){var t=this.pendingTotal,e=this._delta8,r=e-(t+this.padLength)%e,i=new Array(r+this.padLength);i[0]=128;for(var n=1;n<r;n++)i[n]=0;if(t<<=3,"big"===this.endian){for(var s=8;s<this.padLength;s++)i[n++]=0;i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=t>>>24&255,i[n++]=t>>>16&255,i[n++]=t>>>8&255,i[n++]=255&t}else for(i[n++]=255&t,i[n++]=t>>>8&255,i[n++]=t>>>16&255,i[n++]=t>>>24&255,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,s=8;s<this.padLength;s++)i[n++]=0;return i};var S={BlockHash:B},k=w.rotr32;function A(t,e,r){return t&e^~t&r}function T(t,e,r){return t&e^t&r^e&r}function H(t,e,r){return t^e^r}var E={ft_1:function(t,e,r,i){return 0===t?A(e,r,i):1===t||3===t?H(e,r,i):2===t?T(e,r,i):void 0},ch32:A,maj32:T,p32:H,s0_256:function(t){return k(t,2)^k(t,13)^k(t,22)},s1_256:function(t){return k(t,6)^k(t,11)^k(t,25)},g0_256:function(t){return k(t,7)^k(t,18)^t>>>3},g1_256:function(t){return k(t,17)^k(t,19)^t>>>10}},K=w.rotl32,j=w.sum32,z=w.sum32_5,C=E.ft_1,D=S.BlockHash,P=[1518500249,1859775393,2400959708,3395469782];function M(){if(!(this instanceof M))return new M;D.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}w.inherits(M,D);var q=M;M.blockSize=512,M.outSize=160,M.hmacStrength=80,M.padLength=64,M.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;i<r.length;i++)r[i]=K(r[i-3]^r[i-8]^r[i-14]^r[i-16],1);var n=this.h[0],s=this.h[1],o=this.h[2],h=this.h[3],u=this.h[4];for(i=0;i<r.length;i++){var c=~~(i/20),a=z(K(n,5),C(c,s,o,h),u,r[i],P[c]);u=h,h=o,o=K(s,30),s=n,n=a}this.h[0]=j(this.h[0],n),this.h[1]=j(this.h[1],s),this.h[2]=j(this.h[2],o),this.h[3]=j(this.h[3],h),this.h[4]=j(this.h[4],u)},M.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"big"):w.split32(this.h,"big")};var L=w.sum32,N=w.sum32_4,V=w.sum32_5,I=E.ch32,R=E.maj32,U=E.s0_256,W=E.s1_256,O=E.g0_256,Y=E.g1_256,X=S.BlockHash,Q=[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 G(){if(!(this instanceof G))return new G;X.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=Q,this.W=new Array(64)}w.inherits(G,X);var Z=G;function J(){if(!(this instanceof J))return new J;Z.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}G.blockSize=512,G.outSize=256,G.hmacStrength=192,G.padLength=64,G.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;i<r.length;i++)r[i]=N(Y(r[i-2]),r[i-7],O(r[i-15]),r[i-16]);var n=this.h[0],s=this.h[1],o=this.h[2],h=this.h[3],u=this.h[4],c=this.h[5],a=this.h[6],f=this.h[7];for(g(this.k.length===r.length),i=0;i<r.length;i++){var l=V(f,W(u),I(u,c,a),this.k[i],r[i]),p=L(U(n),R(n,s,o));f=a,a=c,c=u,u=L(h,l),h=o,o=s,s=n,n=L(l,p)}this.h[0]=L(this.h[0],n),this.h[1]=L(this.h[1],s),this.h[2]=L(this.h[2],o),this.h[3]=L(this.h[3],h),this.h[4]=L(this.h[4],u),this.h[5]=L(this.h[5],c),this.h[6]=L(this.h[6],a),this.h[7]=L(this.h[7],f)},G.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"big"):w.split32(this.h,"big")},w.inherits(J,Z);var $=J;J.blockSize=512,J.outSize=224,J.hmacStrength=192,J.padLength=64,J.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h.slice(0,7),"big"):w.split32(this.h.slice(0,7),"big")};var tt=w.rotr64_hi,et=w.rotr64_lo,rt=w.shr64_hi,it=w.shr64_lo,nt=w.sum64,st=w.sum64_hi,ot=w.sum64_lo,ht=w.sum64_4_hi,ut=w.sum64_4_lo,ct=w.sum64_5_hi,at=w.sum64_5_lo,ft=S.BlockHash,lt=[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 pt(){if(!(this instanceof pt))return new pt;ft.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=lt,this.W=new Array(160)}w.inherits(pt,ft);var dt=pt;function gt(t,e,r,i,n){var s=t&r^~t&n;return s<0&&(s+=4294967296),s}function yt(t,e,r,i,n,s){var o=e&i^~e&s;return o<0&&(o+=4294967296),o}function vt(t,e,r,i,n){var s=t&r^t&n^r&n;return s<0&&(s+=4294967296),s}function mt(t,e,r,i,n,s){var o=e&i^e&s^i&s;return o<0&&(o+=4294967296),o}function Ft(t,e){var r=tt(t,e,28)^tt(e,t,2)^tt(e,t,7);return r<0&&(r+=4294967296),r}function bt(t,e){var r=et(t,e,28)^et(e,t,2)^et(e,t,7);return r<0&&(r+=4294967296),r}function wt(t,e){var r=tt(t,e,14)^tt(t,e,18)^tt(e,t,9);return r<0&&(r+=4294967296),r}function _t(t,e){var r=et(t,e,14)^et(t,e,18)^et(e,t,9);return r<0&&(r+=4294967296),r}function xt(t,e){var r=tt(t,e,1)^tt(t,e,8)^rt(t,e,7);return r<0&&(r+=4294967296),r}function Bt(t,e){var r=et(t,e,1)^et(t,e,8)^it(t,e,7);return r<0&&(r+=4294967296),r}function St(t,e){var r=tt(t,e,19)^tt(e,t,29)^rt(t,e,6);return r<0&&(r+=4294967296),r}function kt(t,e){var r=et(t,e,19)^et(e,t,29)^it(t,e,6);return r<0&&(r+=4294967296),r}function At(){if(!(this instanceof At))return new At;dt.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}pt.blockSize=1024,pt.outSize=512,pt.hmacStrength=192,pt.padLength=128,pt.prototype._prepareBlock=function(t,e){for(var r=this.W,i=0;i<32;i++)r[i]=t[e+i];for(;i<r.length;i+=2){var n=St(r[i-4],r[i-3]),s=kt(r[i-4],r[i-3]),o=r[i-14],h=r[i-13],u=xt(r[i-30],r[i-29]),c=Bt(r[i-30],r[i-29]),a=r[i-32],f=r[i-31];r[i]=ht(n,s,o,h,u,c,a,f),r[i+1]=ut(n,s,o,h,u,c,a,f)}},pt.prototype._update=function(t,e){this._prepareBlock(t,e);var r=this.W,i=this.h[0],n=this.h[1],s=this.h[2],o=this.h[3],h=this.h[4],u=this.h[5],c=this.h[6],a=this.h[7],f=this.h[8],l=this.h[9],p=this.h[10],d=this.h[11],y=this.h[12],v=this.h[13],m=this.h[14],F=this.h[15];g(this.k.length===r.length);for(var b=0;b<r.length;b+=2){var w=m,_=F,x=wt(f,l),B=_t(f,l),S=gt(f,l,p,d,y),k=yt(f,l,p,d,y,v),A=this.k[b],T=this.k[b+1],H=r[b],E=r[b+1],K=ct(w,_,x,B,S,k,A,T,H,E),j=at(w,_,x,B,S,k,A,T,H,E);w=Ft(i,n),_=bt(i,n),x=vt(i,n,s,o,h),B=mt(i,n,s,o,h,u);var z=st(w,_,x,B),C=ot(w,_,x,B);m=y,F=v,y=p,v=d,p=f,d=l,f=st(c,a,K,j),l=ot(a,a,K,j),c=h,a=u,h=s,u=o,s=i,o=n,i=st(K,j,z,C),n=ot(K,j,z,C)}nt(this.h,0,i,n),nt(this.h,2,s,o),nt(this.h,4,h,u),nt(this.h,6,c,a),nt(this.h,8,f,l),nt(this.h,10,p,d),nt(this.h,12,y,v),nt(this.h,14,m,F)},pt.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"big"):w.split32(this.h,"big")},w.inherits(At,dt);var Tt=At;At.blockSize=1024,At.outSize=384,At.hmacStrength=192,At.padLength=128,At.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h.slice(0,12),"big"):w.split32(this.h.slice(0,12),"big")};var Ht={sha1:q,sha224:$,sha256:Z,sha384:Tt,sha512:dt},Et=w.rotl32,Kt=w.sum32,jt=w.sum32_3,zt=w.sum32_4,Ct=S.BlockHash;function Dt(){if(!(this instanceof Dt))return new Dt;Ct.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}w.inherits(Dt,Ct);var Pt=Dt;function Mt(t,e,r,i){return t<=15?e^r^i:t<=31?e&r|~e&i:t<=47?(e|~r)^i:t<=63?e&i|r&~i:e^(r|~i)}function qt(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function Lt(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}Dt.blockSize=512,Dt.outSize=160,Dt.hmacStrength=192,Dt.padLength=64,Dt.prototype._update=function(t,e){for(var r=this.h[0],i=this.h[1],n=this.h[2],s=this.h[3],o=this.h[4],h=r,u=i,c=n,a=s,f=o,l=0;l<80;l++){var p=Kt(Et(zt(r,Mt(l,i,n,s),t[Nt[l]+e],qt(l)),It[l]),o);r=o,o=s,s=Et(n,10),n=i,i=p,p=Kt(Et(zt(h,Mt(79-l,u,c,a),t[Vt[l]+e],Lt(l)),Rt[l]),f),h=f,f=a,a=Et(c,10),c=u,u=p}p=jt(this.h[1],n,a),this.h[1]=jt(this.h[2],s,f),this.h[2]=jt(this.h[3],o,h),this.h[3]=jt(this.h[4],r,u),this.h[4]=jt(this.h[0],i,c),this.h[0]=p},Dt.prototype._digest=function(t){return"hex"===t?w.toHex32(this.h,"little"):w.split32(this.h,"little")};var Nt=[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],Vt=[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],It=[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],Rt=[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],Ut={ripemd160:Pt};function Wt(t,e,r){if(!(this instanceof Wt))return new Wt(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(w.toArray(e,r))}var Ot=Wt;Wt.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),g(t.length<=this.blockSize);for(var e=t.length;e<this.blockSize;e++)t.push(0);for(e=0;e<t.length;e++)t[e]^=54;for(this.inner=(new this.Hash).update(t),e=0;e<t.length;e++)t[e]^=106;this.outer=(new this.Hash).update(t)},Wt.prototype.update=function(t,e){return this.inner.update(t,e),this},Wt.prototype.digest=function(t){return this.outer.update(this.inner.digest()),this.outer.digest(t)};var Yt=d((function(t,e){var r=e;r.utils=w,r.common=S,r.sha=Ht,r.ripemd=Ut,r.hmac=Ot,r.sha1=r.sha.sha1,r.sha256=r.sha.sha256,r.sha224=r.sha.sha224,r.sha384=r.sha.sha384,r.sha512=r.sha.sha512,r.ripemd160=r.ripemd.ripemd160})),Xt=d((function(t,e){var r=e;function i(t){return 1===t.length?"0"+t:t}function n(t){for(var e="",r=0;r<t.length;r++)e+=i(t[r].toString(16));return e}r.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"!=typeof t){for(var i=0;i<t.length;i++)r[i]=0|t[i];return r}if("hex"===e){(t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t);for(i=0;i<t.length;i+=2)r.push(parseInt(t[i]+t[i+1],16))}else for(i=0;i<t.length;i++){var n=t.charCodeAt(i),s=n>>8,o=255&n;s?r.push(s,o):r.push(o)}return r},r.zero2=i,r.toHex=n,r.encode=function(t,e){return"hex"===e?n(t):t}}));function Qt(t,e){if(t instanceof Qt)return t;this._importDER(t,e)||(g(t.r&&t.s,"Signature without r or s"),this.r=new p.default(t.r,16),this.s=new p.default(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var Gt=Qt;function Zt(){this.place=0}function Jt(t,e){var r=t[e.place++];if(!(128&r))return r;var i=15&r;if(0===i||i>4)return!1;for(var n=0,s=0,o=e.place;s<i;s++,o++)n<<=8,n|=t[o],n>>>=0;return!(n<=127)&&(e.place=o,n)}function $t(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 te(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)}}Qt.prototype._importDER=function(t,e){t=Xt.toArray(t,e);var r=new Zt;if(48!==t[r.place++])return!1;var i=Jt(t,r);if(!1===i)return!1;if(i+r.place!==t.length)return!1;if(2!==t[r.place++])return!1;var n=Jt(t,r);if(!1===n)return!1;var s=t.slice(r.place,n+r.place);if(r.place+=n,2!==t[r.place++])return!1;var o=Jt(t,r);if(!1===o)return!1;if(t.length!==o+r.place)return!1;var h=t.slice(r.place,o+r.place);if(0===s[0]){if(!(128&s[1]))return!1;s=s.slice(1)}if(0===h[0]){if(!(128&h[1]))return!1;h=h.slice(1)}return this.r=new p.default(s),this.s=new p.default(h),this.recoveryParam=null,!0},Qt.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=$t(e),r=$t(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];te(i,e.length),(i=i.concat(e)).push(2),te(i,r.length);var n=i.concat(r),s=[48];return te(s,n.length),s=s.concat(n),Xt.encode(s,t)};var ee=d((function(t,e){var r=e;r.strToBytes=function(t){for(var e,r,i=[],n=0;n<t.length;n++){e=t.charCodeAt(n),r=[];do{r.push(255&e),e>>=8}while(e);i=i.concat(r.reverse())}return i},r.hashToBN=function(t){if("string"==typeof t)return new p.default(t,16);for(var e="",r=0;r<t.length;r++){var i=t[r].toString(16);1==i.length&&(e+="0"),e+=i}return new p.default(e,16)},r.random=function(t){return c.default(t).toString("hex")},r.padStart=function(t,e,r){return t.length>=e?t:r.repeat(e-t.length)+t}}));function re(){if(!(this instanceof re))return new re;this.reg=new Array(8),this.chunk=[],this.size=0,this.reset()}var ie=re;function ne(t,e){return(t<<(e%=32)|t>>>32-e)>>>0}function se(t){return 0<=t&&t<16?2043430169:16<=t&&t<64?2055708042:void console.error("invalid j for constant Tj")}function oe(t,e,r,i){return 0<=t&&t<16?(e^r^i)>>>0:16<=t&&t<64?(e&r|e&i|r&i)>>>0:(console.error("invalid j for bool function FF"),0)}function he(t,e,r,i){return 0<=t&&t<16?(e^r^i)>>>0:16<=t&&t<64?(e&r|~e&i)>>>0:(console.error("invalid j for bool function GG"),0)}function ue(t){if(!(this instanceof ue))return new ue(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 e=Xt.toArray(t.entropy,t.entropyEnc||"hex"),r=Xt.toArray(t.nonce,t.nonceEnc||"hex"),i=Xt.toArray(t.pers,t.persEnc||"hex");g(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}re.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},re.prototype.write=function(t){var e="string"==typeof t?ee.strToBytes(t):t;this.size+=e.length;var r=64-this.chunk.length;if(e.length<r)this.chunk=this.chunk.concat(e);else for(this.chunk=this.chunk.concat(e.slice(0,r));this.chunk.length>=64;)this._compress(this.chunk),r<e.length?this.chunk=e.slice(r,Math.min(r+64,e.length)):this.chunk=[],r+=64},re.prototype.sum=function(t,e){t&&(this.reset(),this.write(t)),this._fill();for(var r=0;r<this.chunk.length;r+=64)this._compress(this.chunk.slice(r,r+64));var i=null;if("hex"==e){i="";for(r=0;r<8;r++)i+=ee.padStart(this.reg[r].toString(16),8,"0")}else for(i=new Array(32),r=0;r<8;r++)h=this.reg[r],i[4*r+3]=(255&h)>>>0,h>>>=8,i[4*r+2]=(255&h)>>>0,h>>>=8,i[4*r+1]=(255&h)>>>0,h>>>=8,i[4*r]=(255&h)>>>0;return this.reset(),i},re.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),r=0;r<16;r++)e[r]=t[4*r]<<24,e[r]|=t[4*r+1]<<16,e[r]|=t[4*r+2]<<8,e[r]|=t[4*r+3],e[r]>>>=0;for(var i=16;i<68;i++)x=e[i-16]^e[i-9]^ne(e[i-3],15),x=x^ne(x,15)^ne(x,23),e[i]=(x^ne(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),r=this.reg.slice(0),i=0;i<64;i++){var n=ne(r[0],12)+r[4]+ne(se(i),i),s=((n=ne(n=(4294967295&n)>>>0,7))^ne(r[0],12))>>>0,o=oe(i,r[0],r[1],r[2]);o=(4294967295&(o=o+r[3]+s+e[i+68]))>>>0;var h=he(i,r[4],r[5],r[6]);h=(4294967295&(h=h+r[7]+n+e[i]))>>>0,r[3]=r[2],r[2]=ne(r[1],9),r[1]=r[0],r[0]=o,r[7]=r[6],r[6]=ne(r[5],19),r[5]=r[4],r[4]=(h^ne(h,9)^ne(h,17))>>>0}for(var u=0;u<8;u++)this.reg[u]=(this.reg[u]^r[u])>>>0}},re.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 i=Math.floor(t/4294967296);this.chunk.push(i>>>8*(3-r)&255)}for(r=0;r<4;r++)this.chunk.push(t>>>8*(3-r)&255)};var ce,ae=ue;ue.prototype._init=function(t,e,r){var i=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n<this.V.length;n++)this.K[n]=0,this.V[n]=1;this._update(i),this._reseed=1,this.reseedInterval=281474976710656},ue.prototype._hmac=function(){return new Yt.hmac(this.hash,this.K)},ue.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())},ue.prototype.reseed=function(t,e,r,i){"string"!=typeof e&&(i=r,r=e,e=null),t=Xt.toArray(t,e),r=Xt.toArray(r,i),g(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},ue.prototype.generate=function(t,e,r,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(i=r,r=e,e=null),r&&(r=Xt.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length<t;)this.V=this._hmac().update(this.V).digest(),n=n.concat(this.V);var s=n.slice(0,t);return this._update(r),this._reseed++,Xt.encode(s,e)};var fe=new ae({hash:Yt.sha256,entropy:"UQi4W3Y2bJfzleYy+oEZ2kA9A+9jrmwewST9vmBZNgMmFyzzH0S9Vol/UK",nonce:"0123456789avcdef",pers:"0123456789abcdef"});function le(t){if(!(this instanceof le))return new le(t);f.default.curve.short.call(this,t)}a.default(le,f.default.curve.short);var pe=ce=le({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:ie,gRed:!1,g:["32C4AE2C 1F198119 5F990446 6A39C994 8FE30BBF F2660BE1 715A4589 334C74C7","BC3736A2 F4F6779C 59BDCEE3 6B692153 D0A9877C C62A4740 02DF32E5 2139F0A0"]});function de(t,e,r){if(null==t)return ce.point();var i;if(null!=e){if(i=ce.point(t,e),!ce.validate(i))throw"point is not on curve"}else{var n=new p.default(t,16).toRed(ce.red),s=n.redSqr().redMul(n);"odd"===r!=(s=s.redIAdd(n.redMul(ce.a)).redIAdd(ce.b).redSqrt()).fromRed().isOdd()&&(s=s.redNeg()),i=ce.point(n,s)}return i}function ge(t,e){if(!(this instanceof ge))return new ge(t,e);this.curve=ce,this.pub=null,this.pri=null;var r=!1,i=!1;if(null!=t)if("string"==typeof t)this._pubFromString(t);else if(Array.isArray(t))this._pubFromBytes(t);else{if(!("x"in t&&p.default.isBN(t.x)&&"y"in t&&p.default.isBN(t.y)))throw"invalid public key";this.pub=t,r=!0}if(null!=e){if("string"==typeof e)this.pri=new p.default(e,16);else{if(!p.default.isBN(e))throw"invalid private key";this.pri=e,i=!0}null==this.pub&&(this.pub=ce.g.mul(this.pri))}if(!(r&&i||this.validate()))throw"invalid key"}var ye=ge;ge.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=de(r,null,"even");break;case"03":this.pub=de(r,null,"odd");break;case"04":case"06":case"07":if(t.length<130)throw e;this.pub=de(r,t.slice(66,130));break;default:throw e}},ge.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=de(r,null,"even");break;case 3:this.pub=de(r,null,"odd");break;case 4:case 6:case 7:if(t.length<65)throw e;this.pub=de(r,t.slice(33,65));break;default:throw e}},ge.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 p.default(2)))>0)return!1;if(null!=this.pub&&!this.pub.eq(this.curve.g.mul(this.pri)))return!1}return!0},ge.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)},ge.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))},ge.prototype.sign=function(t){if(null==this.pri)throw"cannot sign message without private key";return"string"==typeof t?this.signDigest((new ie).sum(this._combine(ee.strToBytes(t)))):this.signDigest((new ie).sum(this._combine(t)))},ge.prototype.verify=function(t,e,r){if(null==this.pub)throw"cannot verify signature without public key";return this.verifyDigest((new ie).sum(this._combine(t)),e,r)},ge.prototype.signRaw=function(t){return this.signDigest((new ie).sum(t))},ge.prototype.verifyRaw=function(t,e,r){return this.verifyDigest((new ie).sum(t),e,r)},ge.prototype.signDigest=function(t){for(var e={r:"",s:""};;){var r=new p.default(fe.generate(32,"hex",ee.random(64)),16).umod(this.curve.n),i=this.curve.g.mul(r),n=ee.hashToBN(t).add(i.getX()).umod(this.curve.n);if(!n.isZero()&&!n.add(r).eq(this.curve.n)){var s=new p.default(1).add(this.pri).invm(this.curve.n),o=r.sub(n.mul(this.pri)).umod(this.curve.n),h=s.mul(o).umod(this.curve.n);if(!h.isZero()){e.r=ee.padStart(n.toString(16),64,"0"),e.s=ee.padStart(h.toString(16),64,"0");break}}}return e},ge.prototype.verifyDigest=function(t,e,r){var i=new p.default(e,16);if(i.cmp(this.curve.n)>=0)return!1;var n=new p.default(r,16);if(n.cmp(this.curve.n)>=0)return!1;var s=i.add(n).umod(this.curve.n);if(s.isZero())return!1;var o=this.curve.g.mul(n).add(this.pub.mul(s));return!!ee.hashToBN(t).add(o.getX()).umod(this.curve.n).eq(i)},ge.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 ie,e=h.sum(e),"string"==typeof t?e.concat(ee.strToBytes(t)):e.concat(t)},ge.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+=ee.padStart(this.pri.toString(16),64,"0"):t+="null",t};var ve,me={curve:pe,SM2KeyPair:ye,genKeyPair:function(){var t=0,e=ce.n.sub(new p.default(2));do{t=new p.default(fe.generate(32,"hex",ee.random(64)))}while(t.cmp(e)>0);return new ge(null,t)}},Fe="@swtc/sm.js@^0.1.12",be="@swtc/sm.js@0.1.12",we="sha512-Kx1G0CSt4CF3+my0OT7os2VFNdm1sUSQZ9JCK4G2qhJ1QPpTAHAS0jSJ53QQU/BsGu+8QwFiMIRQsNPiVovjBg==",_e={},xe={type:"range",registry:!0,raw:"@swtc/sm.js@^0.1.12",name:"@swtc/sm.js",escapedName:"@swtc%2fsm.js",scope:"@swtc",rawSpec:"^0.1.12",saveSpec:null,fetchSpec:"^0.1.12"},Be=["/","/@swtc/keypairs"],Se="https://registry.npmjs.org/@swtc/sm.js/-/sm.js-0.1.12.tgz",ke="b24d6e3da6401096cf970c68ac4e98755294f38c",Ae="@swtc/sm.js@^0.1.12",Te="/Users/xcliu/swtc/swtclib",He={name:"Alver Lyu"},Ee={url:"https://github.com/AlverLyu/sm.js/issues"},Ke={"bn.js":"^4.11.6",elliptic:"^6.4.0","hash.js":"^1.0.3","hmac-drbg":"^1.0.1",inherits:"^2.0.3"},je="SM series cryptography in javascript implementation",ze={"uglify-js":"^3.0.15"},Ce="https://github.com/AlverLyu/sm.js#readme",De=["sm2","sm3","crypto","ecc"],Pe={type:"git",url:"git+https://github.com/AlverLyu/sm.js.git"},Me={test:""},qe={_from:Fe,_id:be,_inBundle:!1,_integrity:we,_location:"/@swtc/sm.js",_phantomChildren:_e,_requested:xe,_requiredBy:Be,_resolved:Se,_shasum:ke,_spec:Ae,_where:Te,author:He,bugs:Ee,bundleDependencies:!1,dependencies:Ke,deprecated:!1,description:je,devDependencies:ze,homepage:Ce,keywords:De,license:"MIT",main:"index.js",name:"@swtc/sm.js",repository:Pe,scripts:Me,version:"0.1.12"},Le=(ve=Object.freeze({__proto__:null,_from:Fe,_id:be,_inBundle:!1,_integrity:we,_location:"/@swtc/sm.js",_phantomChildren:_e,_requested:xe,_requiredBy:Be,_resolved:Se,_shasum:ke,_spec:Ae,_where:Te,author:He,bugs:Ee,bundleDependencies:!1,dependencies:Ke,deprecated:!1,description:je,devDependencies:ze,homepage:Ce,keywords:De,license:"MIT",main:"index.js",name:"@swtc/sm.js",repository:Pe,scripts:Me,version:"0.1.12",default:qe}))&&ve.default||ve,Ne=d((function(t,e){var r=e;r.Signature=Gt,r.sm2=me,r.sm3=ie,r.version=Le.version}));class Ve{constructor(){this.hash=Yt.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 p.default(this.first256())}}const Ie=l.ec("secp256k1");function Re(t,e){const r=Ie.curve.n;for(let i=0;i<=4294967295;i++){const n=(new Ve).add(t);void 0!==e&&n.addU32(e),n.addU32(i);const s=n.first256BN();if(s.cmpn(0)>0&&s.cmp(r)<0)return s}throw new Error("impossible unicorn ;)")}function Ue(t,e={}){const r=e.validator,i=Ie.curve.n,n=Re(t);if(r)return n;const s=Ie.g.mul(n),o=e.accountIndex||0;return Re(s.encodeCompressed(),o).add(n).mod(i)}function We(t){const e=Ie.curve.decodePoint(t),r=Re(t,0),i=Ie.g.mul(r);return e.add(i).encodeCompressed()}function Oe(t,e){const r=Ne.sm2.curve.n;for(let i=0;i<=4294967295;i++){const n=void 0!==e?Buffer.alloc(41):Buffer.alloc(20);n.fill(Buffer.from(t),0,t.length),void 0!==e&&(n.writeUIntBE(e,t.length,4),n.writeUIntBE(i,t.length+4,4)),n.writeUIntBE(i,t.length,4);const o=(new s.SM3).update(n).digest("hex"),h=new p.default(o,"hex");if(h.cmpn(0)>0&&h.cmp(r)<0)return h}throw new Error("impossible unicorn ;)")}function Ye(t){return Yt.sha512().update(t).digest().slice(0,16)}function Xe(t){return(new s.SM3).update(t).digest().slice(0,16)}const Qe=r.eddsa("ed25519"),Ge=r.ec("secp256k1");function Ze(t){return Yt.sha512().update(t).digest().slice(0,32)}function Je(t){return(new s.SM3).update(t).digest().slice(0,32)}function $e(t="jingtum"){const e=n.Factory(t),r=e.guomi,i=e.token,o=r?Je:Ze,h={deriveKeypair:(t,e={})=>{const r="00"+Ue(t,e).toString(16,64).toUpperCase(),i=s.funcBytesToHex(Ge.keyFromPrivate(r.slice(2)).getPublic().encodeCompressed());return{privateKey:r,publicKey:i}},deriveKeypairWithPrivateKey:t=>{const e="00"+t.toUpperCase(),r=s.funcBytesToHex(Ge.keyFromPrivate(e.slice(2)).getPublic().encodeCompressed());return{privateKey:e,publicKey:r}},sign:(t,e)=>s.funcBytesToHex(Ge.sign(o(t),s.funcHexToBytes(e),{canonical:!0}).toDER()),verify:(t,e,r)=>Ge.verify(o(t),e,s.funcHexToBytes(r)),signTx:(t,e)=>s.funcBytesToHex(Ge.sign(t,s.funcHexToBytes(e),{canonical:!0}).toDER()),verifyTx:(t,e,r)=>Ge.verify(t,e,s.funcHexToBytes(r))},u={deriveKeypair:(t,e={})=>{const r=function(t,e={}){const r=e.validator,i=Ne.sm2.curve.n,n=Oe(t);if(r)return n;const s=Ne.sm2.curve.g.mul(n),o=e.accountIndex||0;return Oe(s.encodeCompressed(),o).add(n).mod(i)}(t,e);return{privateKey:"00"+r.toString(16,64).toUpperCase(),publicKey:s.funcBytesToHex(Ne.sm2.SM2KeyPair(null,r).pub.encodeCompressed())}},deriveKeypairWithPrivateKey:t=>{const e=new p.default(t,"hex");return{privateKey:"00"+t.toUpperCase(),publicKey:s.funcBytesToHex(Ne.sm2.SM2KeyPair(null,e).pub.encodeCompressed())}},sign:(t,e)=>{const r=Ne.sm2.SM2KeyPair(null,new p.default(e,"hex"));return s.funcBytesToHex(new Ne.Signature(r.sign(o(t))).toDER())},verify:(t,e,r)=>{const i=Ne.sm2.SM2KeyPair(r),n=new Ne.Signature(e,"hex");return i.verify(o(t),n.r,n.s)},signTx:(t,e)=>{"string"==typeof t&&/^[0-9A-F]{16}/i.test(t)&&(t=s.funcHexToBytes(t));const r=Ne.sm2.SM2KeyPair(null,new p.default(e,"hex"));return s.funcBytesToHex(new Ne.Signature(r.sign(t)).toDER())},verifyTx:(t,e,r)=>{"string"==typeof t&&/^[0-9A-F]{16}/i.test(t)&&(t=s.funcHexToBytes(t));const i=Ne.sm2.SM2KeyPair(r),n=new Ne.Signature(e,"hex");return i.verify(o(t),n.r,n.s)}},a={deriveKeypair:t=>{const e=o(t);return{privateKey:"ED"+s.funcBytesToHex(e),publicKey:"ED"+s.funcBytesToHex(Qe.keyFromSecret(e).pubBytes())}},deriveKeypairWithPrivateKey:t=>({privateKey:"ED"+t.toUpperCase(),publicKey:"ED"+s.funcBytesToHex(Qe.keyFromSecret(s.funcHexToBytes(t)).pubBytes())}),sign:(t,e)=>(s.funcAssert(Array.isArray(t),"message must be array of octets"),s.funcBytesToHex(Qe.sign(t,s.funcHexToBytes(e).slice(1)).toBytes())),verify:(t,e,r)=>Qe.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1)),signTx:(t,e)=>Qe.sign(t,s.funcHexToBytes(e).slice(1)).toHex(),verifyTx:(t,e,r)=>Qe.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1))},f={deriveKeypair:t=>{const e=o(t);return{privateKey:"ED"+s.funcBytesToHex(e),publicKey:"ED"+s.funcBytesToHex(Qe.keyFromSecret(e).pubBytes())}},deriveKeypairWithPrivateKey:t=>({privateKey:"ED"+t.toUpperCase(),publicKey:"ED"+s.funcBytesToHex(Qe.keyFromSecret(s.funcHexToBytes(t)).pubBytes())}),sign:(t,e)=>(s.funcAssert(Array.isArray(t),"message must be array of octets"),s.funcBytesToHex(Qe.sign(t,s.funcHexToBytes(e).slice(1)).toBytes())),verify:(t,e,r)=>Qe.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1)),signTx:(t,e)=>Qe.sign(t,s.funcHexToBytes(e).slice(1)).toHex(),verifyTx:(t,e,r)=>Qe.verify(t,s.funcHexToBytes(e),s.funcHexToBytes(r).slice(1))};function l(t){const e={secp256k1:h,sm2p256v1:u,ed25519:a,ed25519guomi:f};return"ed25519"===t?r?e.ed25519guomi:e.ed25519:e[t]}function d(t){const e=s.funcHexToBytes(t);return 33===e.length&&237===e[0]?"ed25519":r?"sm2p256v1":"secp256k1"}function g(t,i=(r?"sm2p256v1":"secp256k1")){const n=t;let s,h,u=t;if("string"!=typeof t)throw new Error("deriving keypair requires secret or private key");if(/^s/.test(t)){const t=e.decodeSeed(n);h=l(i="ed25519"===t.type?"ed25519":r?"sm2p256v1":"secp256k1"),s=h.deriveKeypair(t.bytes)}else{if(64===t.length)i="ed25519"===i?"ed25519":r?"sm2p256v1":"secp256k1";else{if(66!==t.length)throw new Error("deriving keypair requires valid private key");if("00"===t.slice(0,2))i=r?"sm2p256v1":"secp256k1";else{if("ED"!==t.slice(0,2).toUpperCase())throw new Error("deriving keypair requires correct prefixed private key");i="ed25519"}u=t.slice(2)}h=l(i),s=h.deriveKeypairWithPrivateKey(u)}const c=o("This test message should verify."),a=h.sign(c,s.privateKey);if(!0!==h.verify(c,a,s.publicKey))throw new Error("derived keypair did not generate verifiable signature");return s}function y(t){return e.encodeAccountID(Buffer.from(r?function(t){const e=(new s.SM3).update(t).digest();return Yt.ripemd160().update(e).digest()}(t):function(t){const e=Yt.sha256().update(t).digest();return Yt.ripemd160().update(e).digest()}(t)))}return{guomi:r,token:i,addressCodec:e,deriveKeyPair:g,hash:o,seedFromPhrase:r?Xe:Ye,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 e.decodeAddress(t).toJSON().data},convertBytesToAddress:function(t){return e.encodeAddress(t)},checkAddress:e.isValidAddress,isValidAddress:e.isValidAddress,deriveKeypair:g,generateSeed:function(t={}){s.funcAssert(!t.entropy||t.entropy.length>=16,"entropy too short");const i=t.entropy?t.entropy.slice(0,16):c.default(16),n="ed25519"===t.algorithm?"ed25519":r?"sm2p256v1":"secp256k1";return e.encodeSeed(i,n)},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 i=e.decodeNodePublic(t);return y(r?function(t){const e=Ne.sm2.curve.decodePoint(t),r=Oe(t,0),i=Ne.sm2.curve.g.mul(r);return e.add(i).encodeCompressed()}(i):We(i))}}}const tr=$e(),er=$e("guomi");exports.Factory=$e,exports.Keypairs=tr,exports.KeypairsGm=er,exports.sm2=Ne.sm2; //# sourceMappingURL=index.js.map