ethr-did-resolver
Advanced tools
Comparing version 2.4.0 to 3.0.0
@@ -0,1 +1,13 @@ | ||
# [3.0.0](https://github.com/decentralized-identity/ethr-did-resolver/compare/2.4.0...3.0.0) (2020-08-24) | ||
### Bug Fixes | ||
* change 'owner' to 'controller' to follow W3C Spec ([#75](https://github.com/decentralized-identity/ethr-did-resolver/issues/75)) ([#81](https://github.com/decentralized-identity/ethr-did-resolver/issues/81)) ([af37b3f](https://github.com/decentralized-identity/ethr-did-resolver/commit/af37b3fe66dedda688156bb421948364c3ab3606)) | ||
### BREAKING CHANGES | ||
* JWTs that refer to the `did:ethr:...#owner` key in their header may be considered invalid after this upgrade, as the key id is now `did:ethr:...#controller` | ||
# [2.4.0](https://github.com/decentralized-identity/ethr-did-resolver/compare/2.3.4...2.4.0) (2020-08-21) | ||
@@ -2,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
import t from"ethjs-provider-http";import i from"ethjs-query";import e from"ethjs-abi";import n,{Buffer as r}from"buffer";import o from"ethjs-contract";import{ec as s}from"elliptic";import{keccak_256 as h}from"js-sha3";var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a=function(t,i,e){return function(t){!function(t,i){function e(t,i){if(!t)throw new Error(i||"Assertion failed")}function r(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}function o(t,i,e){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(e=i,i=10),this._init(t||0,i||10,e||"be"))}var s;"object"==typeof t?t.exports=o:i.BN=o,o.BN=o,o.wordSize=26;try{s=n.Buffer}catch(t){}function h(t,i,e){for(var n=0,r=Math.min(t.length,e),o=i;o<r;o++){var s=t.charCodeAt(o)-48;n<<=4,n|=s>=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function u(t,i,e,n){for(var r=0,o=Math.min(t.length,e),s=i;s<o;s++){var h=t.charCodeAt(s)-48;r*=n,r+=h>=49?h-49+10:h>=17?h-17+10:h}return r}o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,i){return t.cmp(i)>0?t:i},o.min=function(t,i){return t.cmp(i)<0?t:i},o.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),e(i===(0|i)&&i>=2&&i<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===i?this._parseHex(t,r):this._parseBase(t,i,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),i,n)},o.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},o.prototype._initArray=function(t,i,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,s,h=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)this.words[o]|=(s=t[r]|t[r-1]<<8|t[r-2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)this.words[o]|=(s=t[r]|t[r+1]<<8|t[r+2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);return this.strip()},o.prototype._parseHex=function(t,i){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var n,r,o=0;for(e=t.length-6,n=0;e>=i;e-=6)r=h(t,e,e+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);e+6!==i&&(r=h(t,i,e+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303),this.strip()},o.prototype._parseBase=function(t,i,e){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=i)n++;n--,r=r/i|0;for(var o=t.length-e,s=o%n,h=Math.min(o,o-s)+e,a=0,l=e;l<h;l+=n)a=u(t,l,l+n,i),this.imuln(r),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==s){var m=1;for(a=u(t,l,t.length,i),l=0;l<s;l++)m*=i;this.imuln(m),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}},o.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},o.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},o.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,e){e.negative=i.negative^t.negative;var n=t.length+i.length|0;e.length=n,n=n-1|0;var r=0|t.words[0],o=0|i.words[0],s=r*o,h=s/67108864|0;e.words[0]=67108863&s;for(var u=1;u<n;u++){for(var a=h>>>26,l=67108863&h,m=Math.min(u,i.length-1),d=Math.max(0,u-t.length+1);d<=m;d++)a+=(s=(r=0|t.words[u-d|0])*(o=0|i.words[d])+l)/67108864|0,l=67108863&s;e.words[u]=0|l,h=0|a}return 0!==h?e.words[u]=0|h:e.length--,e.strip()}o.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var h=this.words[s],u=(16777215&(h<<r|o)).toString(16);n=0!=(o=h>>>24-r&16777215)||s!==this.length-1?a[6-u.length]+u+n:u+n,(r+=2)>=26&&(r-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:a[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(t,i){return e(void 0!==s),this.toArrayLike(s,t,i)},o.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},o.prototype.toArrayLike=function(t,i,n){var r=this.byteLength(),o=n||Math.max(1,r);e(r<=o,"byte array longer than desired length"),e(o>0,"Requested array length <= 0"),this.strip();var s,h,u="le"===i,a=new t(o),l=this.clone();if(u){for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[h]=s;for(;h<o;h++)a[h]=0}else{for(h=0;h<o-r;h++)a[h]=0;for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[o-h-1]=s}return a},o.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var i=t,e=0;return i>=4096&&(e+=13,i>>>=13),i>=64&&(e+=7,i>>>=7),i>=8&&(e+=4,i>>>=4),i>=2&&(e+=2,i>>>=2),e+i},o.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,e=0;return 0==(8191&i)&&(e+=13,i>>>=13),0==(127&i)&&(e+=7,i>>>=7),0==(15&i)&&(e+=4,i>>>=4),0==(3&i)&&(e+=2,i>>>=2),0==(1&i)&&e++,e},o.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var e=this._zeroBits(this.words[i]);if(t+=e,26!==e)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},o.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var e=0;e<i.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=i.length,this.strip()},o.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var i,e;this.length>t.length?(i=this,e=t):(i=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=i.words[n]^e.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},o.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var r=0;r<i;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,i){e("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},o.prototype.iadd=function(t){var i,e,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0,o=0;o<n.length;o++)this.words[o]=67108863&(i=(0|e.words[o])+(0|n.words[o])+r),r=i>>>26;for(;0!==r&&o<e.length;o++)this.words[o]=67108863&(i=(0|e.words[o])+r),r=i>>>26;if(this.length=e.length,0!==r)this.words[this.length]=r,this.length++;else if(e!==this)for(;o<e.length;o++)this.words[o]=e.words[o];return this},o.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(e=this,n=t):(e=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(i=(0|e.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&i;for(;0!==o&&s<e.length;s++)o=(i=(0|e.words[s])+o)>>26,this.words[s]=67108863&i;if(0===o&&s<e.length&&e!==this)for(;s<e.length;s++)this.words[s]=e.words[s];return this.length=Math.max(this.length,s),e!==this&&(this.negative=1),this.strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,i,e){var n,r,o,s=t.words,h=i.words,u=e.words,a=0,l=0|s[0],m=8191&l,d=l>>>13,f=0|s[1],p=8191&f,c=f>>>13,y=0|s[2],v=8191&y,g=y>>>13,M=0|s[3],w=8191&M,b=M>>>13,_=0|s[4],k=8191&_,x=_>>>13,S=0|s[5],A=8191&S,R=S>>>13,D=0|s[6],K=8191&D,q=D>>>13,B=0|s[7],T=8191&B,Z=B>>>13,N=0|s[8],I=8191&N,j=N>>>13,E=0|s[9],O=8191&E,C=E>>>13,L=0|h[0],P=8191&L,$=L>>>13,z=0|h[1],V=8191&z,F=z>>>13,U=0|h[2],H=8191&U,G=U>>>13,J=0|h[3],W=8191&J,Y=J>>>13,Q=0|h[4],X=8191&Q,tt=Q>>>13,it=0|h[5],et=8191&it,nt=it>>>13,rt=0|h[6],ot=8191&rt,st=rt>>>13,ht=0|h[7],ut=8191&ht,at=ht>>>13,lt=0|h[8],mt=8191<,dt=lt>>>13,ft=0|h[9],pt=8191&ft,ct=ft>>>13;e.negative=t.negative^i.negative,e.length=19;var yt=(a+(n=Math.imul(m,P))|0)+((8191&(r=(r=Math.imul(m,$))+Math.imul(d,P)|0))<<13)|0;a=((o=Math.imul(d,$))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,P),r=(r=Math.imul(p,$))+Math.imul(c,P)|0,o=Math.imul(c,$);var vt=(a+(n=n+Math.imul(m,V)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,V)|0))<<13)|0;a=((o=o+Math.imul(d,F)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,P),r=(r=Math.imul(v,$))+Math.imul(g,P)|0,o=Math.imul(g,$),n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,V)|0,o=o+Math.imul(c,F)|0;var gt=(a+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;a=((o=o+Math.imul(d,G)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(w,P),r=(r=Math.imul(w,$))+Math.imul(b,P)|0,o=Math.imul(b,$),n=n+Math.imul(v,V)|0,r=(r=r+Math.imul(v,F)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,o=o+Math.imul(c,G)|0;var Mt=(a+(n=n+Math.imul(m,W)|0)|0)+((8191&(r=(r=r+Math.imul(m,Y)|0)+Math.imul(d,W)|0))<<13)|0;a=((o=o+Math.imul(d,Y)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(k,P),r=(r=Math.imul(k,$))+Math.imul(x,P)|0,o=Math.imul(x,$),n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,F)|0,n=n+Math.imul(v,H)|0,r=(r=r+Math.imul(v,G)|0)+Math.imul(g,H)|0,o=o+Math.imul(g,G)|0,n=n+Math.imul(p,W)|0,r=(r=r+Math.imul(p,Y)|0)+Math.imul(c,W)|0,o=o+Math.imul(c,Y)|0;var wt=(a+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;a=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,P),r=(r=Math.imul(A,$))+Math.imul(R,P)|0,o=Math.imul(R,$),n=n+Math.imul(k,V)|0,r=(r=r+Math.imul(k,F)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,o=o+Math.imul(b,G)|0,n=n+Math.imul(v,W)|0,r=(r=r+Math.imul(v,Y)|0)+Math.imul(g,W)|0,o=o+Math.imul(g,Y)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,o=o+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(m,et)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,et)|0))<<13)|0;a=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(K,P),r=(r=Math.imul(K,$))+Math.imul(q,P)|0,o=Math.imul(q,$),n=n+Math.imul(A,V)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,F)|0,n=n+Math.imul(k,H)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(x,H)|0,o=o+Math.imul(x,G)|0,n=n+Math.imul(w,W)|0,r=(r=r+Math.imul(w,Y)|0)+Math.imul(b,W)|0,o=o+Math.imul(b,Y)|0,n=n+Math.imul(v,X)|0,r=(r=r+Math.imul(v,tt)|0)+Math.imul(g,X)|0,o=o+Math.imul(g,tt)|0,n=n+Math.imul(p,et)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,et)|0,o=o+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(m,ot)|0)|0)+((8191&(r=(r=r+Math.imul(m,st)|0)+Math.imul(d,ot)|0))<<13)|0;a=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(T,P),r=(r=Math.imul(T,$))+Math.imul(Z,P)|0,o=Math.imul(Z,$),n=n+Math.imul(K,V)|0,r=(r=r+Math.imul(K,F)|0)+Math.imul(q,V)|0,o=o+Math.imul(q,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,o=o+Math.imul(R,G)|0,n=n+Math.imul(k,W)|0,r=(r=r+Math.imul(k,Y)|0)+Math.imul(x,W)|0,o=o+Math.imul(x,Y)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(v,et)|0,r=(r=r+Math.imul(v,nt)|0)+Math.imul(g,et)|0,o=o+Math.imul(g,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(c,ot)|0,o=o+Math.imul(c,st)|0;var kt=(a+(n=n+Math.imul(m,ut)|0)|0)+((8191&(r=(r=r+Math.imul(m,at)|0)+Math.imul(d,ut)|0))<<13)|0;a=((o=o+Math.imul(d,at)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(I,P),r=(r=Math.imul(I,$))+Math.imul(j,P)|0,o=Math.imul(j,$),n=n+Math.imul(T,V)|0,r=(r=r+Math.imul(T,F)|0)+Math.imul(Z,V)|0,o=o+Math.imul(Z,F)|0,n=n+Math.imul(K,H)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(q,H)|0,o=o+Math.imul(q,G)|0,n=n+Math.imul(A,W)|0,r=(r=r+Math.imul(A,Y)|0)+Math.imul(R,W)|0,o=o+Math.imul(R,Y)|0,n=n+Math.imul(k,X)|0,r=(r=r+Math.imul(k,tt)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(w,et)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,et)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(v,ot)|0,r=(r=r+Math.imul(v,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,at)|0)+Math.imul(c,ut)|0,o=o+Math.imul(c,at)|0;var xt=(a+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;a=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(O,P),r=(r=Math.imul(O,$))+Math.imul(C,P)|0,o=Math.imul(C,$),n=n+Math.imul(I,V)|0,r=(r=r+Math.imul(I,F)|0)+Math.imul(j,V)|0,o=o+Math.imul(j,F)|0,n=n+Math.imul(T,H)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(Z,H)|0,o=o+Math.imul(Z,G)|0,n=n+Math.imul(K,W)|0,r=(r=r+Math.imul(K,Y)|0)+Math.imul(q,W)|0,o=o+Math.imul(q,Y)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,n=n+Math.imul(k,et)|0,r=(r=r+Math.imul(k,nt)|0)+Math.imul(x,et)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,n=n+Math.imul(v,ut)|0,r=(r=r+Math.imul(v,at)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,at)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,o=o+Math.imul(c,dt)|0;var St=(a+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;a=((o=o+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(O,V),r=(r=Math.imul(O,F))+Math.imul(C,V)|0,o=Math.imul(C,F),n=n+Math.imul(I,H)|0,r=(r=r+Math.imul(I,G)|0)+Math.imul(j,H)|0,o=o+Math.imul(j,G)|0,n=n+Math.imul(T,W)|0,r=(r=r+Math.imul(T,Y)|0)+Math.imul(Z,W)|0,o=o+Math.imul(Z,Y)|0,n=n+Math.imul(K,X)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(q,X)|0,o=o+Math.imul(q,tt)|0,n=n+Math.imul(A,et)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,et)|0,o=o+Math.imul(R,nt)|0,n=n+Math.imul(k,ot)|0,r=(r=r+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,at)|0)+Math.imul(b,ut)|0,o=o+Math.imul(b,at)|0,n=n+Math.imul(v,mt)|0,r=(r=r+Math.imul(v,dt)|0)+Math.imul(g,mt)|0,o=o+Math.imul(g,dt)|0;var At=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((o=o+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(O,H),r=(r=Math.imul(O,G))+Math.imul(C,H)|0,o=Math.imul(C,G),n=n+Math.imul(I,W)|0,r=(r=r+Math.imul(I,Y)|0)+Math.imul(j,W)|0,o=o+Math.imul(j,Y)|0,n=n+Math.imul(T,X)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(Z,X)|0,o=o+Math.imul(Z,tt)|0,n=n+Math.imul(K,et)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(q,et)|0,o=o+Math.imul(q,nt)|0,n=n+Math.imul(A,ot)|0,r=(r=r+Math.imul(A,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,n=n+Math.imul(k,ut)|0,r=(r=r+Math.imul(k,at)|0)+Math.imul(x,ut)|0,o=o+Math.imul(x,at)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,o=o+Math.imul(b,dt)|0;var Rt=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(r=(r=r+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((o=o+Math.imul(g,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(O,W),r=(r=Math.imul(O,Y))+Math.imul(C,W)|0,o=Math.imul(C,Y),n=n+Math.imul(I,X)|0,r=(r=r+Math.imul(I,tt)|0)+Math.imul(j,X)|0,o=o+Math.imul(j,tt)|0,n=n+Math.imul(T,et)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(Z,et)|0,o=o+Math.imul(Z,nt)|0,n=n+Math.imul(K,ot)|0,r=(r=r+Math.imul(K,st)|0)+Math.imul(q,ot)|0,o=o+Math.imul(q,st)|0,n=n+Math.imul(A,ut)|0,r=(r=r+Math.imul(A,at)|0)+Math.imul(R,ut)|0,o=o+Math.imul(R,at)|0,n=n+Math.imul(k,mt)|0,r=(r=r+Math.imul(k,dt)|0)+Math.imul(x,mt)|0,o=o+Math.imul(x,dt)|0;var Dt=(a+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((o=o+Math.imul(b,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(O,X),r=(r=Math.imul(O,tt))+Math.imul(C,X)|0,o=Math.imul(C,tt),n=n+Math.imul(I,et)|0,r=(r=r+Math.imul(I,nt)|0)+Math.imul(j,et)|0,o=o+Math.imul(j,nt)|0,n=n+Math.imul(T,ot)|0,r=(r=r+Math.imul(T,st)|0)+Math.imul(Z,ot)|0,o=o+Math.imul(Z,st)|0,n=n+Math.imul(K,ut)|0,r=(r=r+Math.imul(K,at)|0)+Math.imul(q,ut)|0,o=o+Math.imul(q,at)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,o=o+Math.imul(R,dt)|0;var Kt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(r=(r=r+Math.imul(k,ct)|0)+Math.imul(x,pt)|0))<<13)|0;a=((o=o+Math.imul(x,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(O,et),r=(r=Math.imul(O,nt))+Math.imul(C,et)|0,o=Math.imul(C,nt),n=n+Math.imul(I,ot)|0,r=(r=r+Math.imul(I,st)|0)+Math.imul(j,ot)|0,o=o+Math.imul(j,st)|0,n=n+Math.imul(T,ut)|0,r=(r=r+Math.imul(T,at)|0)+Math.imul(Z,ut)|0,o=o+Math.imul(Z,at)|0,n=n+Math.imul(K,mt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(q,mt)|0,o=o+Math.imul(q,dt)|0;var qt=(a+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;a=((o=o+Math.imul(R,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(O,ot),r=(r=Math.imul(O,st))+Math.imul(C,ot)|0,o=Math.imul(C,st),n=n+Math.imul(I,ut)|0,r=(r=r+Math.imul(I,at)|0)+Math.imul(j,ut)|0,o=o+Math.imul(j,at)|0,n=n+Math.imul(T,mt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(Z,mt)|0,o=o+Math.imul(Z,dt)|0;var Bt=(a+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,ct)|0)+Math.imul(q,pt)|0))<<13)|0;a=((o=o+Math.imul(q,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(O,ut),r=(r=Math.imul(O,at))+Math.imul(C,ut)|0,o=Math.imul(C,at),n=n+Math.imul(I,mt)|0,r=(r=r+Math.imul(I,dt)|0)+Math.imul(j,mt)|0,o=o+Math.imul(j,dt)|0;var Tt=(a+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((o=o+Math.imul(Z,ct)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(O,mt),r=(r=Math.imul(O,dt))+Math.imul(C,mt)|0,o=Math.imul(C,dt);var Zt=(a+(n=n+Math.imul(I,pt)|0)|0)+((8191&(r=(r=r+Math.imul(I,ct)|0)+Math.imul(j,pt)|0))<<13)|0;a=((o=o+Math.imul(j,ct)|0)+(r>>>13)|0)+(Zt>>>26)|0,Zt&=67108863;var Nt=(a+(n=Math.imul(O,pt))|0)+((8191&(r=(r=Math.imul(O,ct))+Math.imul(C,pt)|0))<<13)|0;return a=((o=Math.imul(C,ct))+(r>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,u[0]=yt,u[1]=vt,u[2]=gt,u[3]=Mt,u[4]=wt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=xt,u[9]=St,u[10]=At,u[11]=Rt,u[12]=Dt,u[13]=Kt,u[14]=qt,u[15]=Bt,u[16]=Tt,u[17]=Zt,u[18]=Nt,0!==a&&(u[19]=a,e.length++),e};function p(t,i,e){return(new c).mulp(t,i,e)}function c(t,i){this.x=t,this.y=i}Math.imul||(f=d),o.prototype.mulTo=function(t,i){var e=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,i):e<63?d(this,t,i):e<1024?function(t,i,e){e.negative=i.negative^t.negative,e.length=t.length+i.length;for(var n=0,r=0,o=0;o<e.length-1;o++){var s=r;r=0;for(var h=67108863&n,u=Math.min(o,i.length-1),a=Math.max(0,o-t.length+1);a<=u;a++){var l=(0|t.words[o-a])*(0|i.words[a]),m=67108863&l;h=67108863&(m=m+h|0),r+=(s=(s=s+(l/67108864|0)|0)+(m>>>26)|0)>>>26,s&=67108863}e.words[o]=h,n=s,s=r}return 0!==n?e.words[o]=n:e.length--,e.strip()}(this,t,i):p(this,t,i)},c.prototype.makeRBT=function(t){for(var i=new Array(t),e=o.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,e,t);return i},c.prototype.revBin=function(t,i,e){if(0===t||t===e-1)return t;for(var n=0,r=0;r<i;r++)n|=(1&t)<<i-r-1,t>>=1;return n},c.prototype.permute=function(t,i,e,n,r,o){for(var s=0;s<o;s++)n[s]=i[t[s]],r[s]=e[t[s]]},c.prototype.transform=function(t,i,e,n,r,o){this.permute(o,t,i,e,n,r);for(var s=1;s<r;s<<=1)for(var h=s<<1,u=Math.cos(2*Math.PI/h),a=Math.sin(2*Math.PI/h),l=0;l<r;l+=h)for(var m=u,d=a,f=0;f<s;f++){var p=e[l+f],c=n[l+f],y=e[l+f+s],v=n[l+f+s],g=m*y-d*v;v=m*v+d*y,e[l+f]=p+(y=g),n[l+f]=c+v,e[l+f+s]=p-y,n[l+f+s]=c-v,f!==h&&(g=u*m-a*d,d=u*d+a*m,m=g)}},c.prototype.guessLen13b=function(t,i){var e=1|Math.max(i,t),n=1&e,r=0;for(e=e/2|0;e;e>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,i,e){if(!(e<=1))for(var n=0;n<e/2;n++){var r=t[n];t[n]=t[e-n-1],t[e-n-1]=r,r=i[n],i[n]=-i[e-n-1],i[e-n-1]=-r}},c.prototype.normalize13b=function(t,i){for(var e=0,n=0;n<i/2;n++){var r=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+e;t[n]=67108863&r,e=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,i,n,r){for(var o=0,s=0;s<i;s++)n[2*s]=8191&(o+=0|t[s]),n[2*s+1]=8191&(o>>>=13),o>>>=13;for(s=2*i;s<r;++s)n[s]=0;e(0===o),e(0==(-8192&o))},c.prototype.stub=function(t){for(var i=new Array(t),e=0;e<t;e++)i[e]=0;return i},c.prototype.mulp=function(t,i,e){var n=2*this.guessLen13b(t.length,i.length),r=this.makeRBT(n),o=this.stub(n),s=new Array(n),h=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),m=new Array(n),d=e.words;d.length=n,this.convert13b(t.words,t.length,s,n),this.convert13b(i.words,i.length,a,n),this.transform(s,o,h,u,n,r),this.transform(a,o,l,m,n,r);for(var f=0;f<n;f++){var p=h[f]*l[f]-u[f]*m[f];u[f]=h[f]*m[f]+u[f]*l[f],h[f]=p}return this.conjugate(h,u,n),this.transform(h,u,d,o,n,r),this.conjugate(d,o,n),this.normalize13b(d,n),e.negative=t.negative^i.negative,e.length=t.length+i.length,e.strip()},o.prototype.mul=function(t){var i=new o(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},o.prototype.mulf=function(t){var i=new o(null);return i.words=new Array(this.length+t.length),p(this,t,i)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var i=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,o=(67108863&r)+(67108863&i);i>>=26,i+=r/67108864|0,i+=o>>>26,this.words[n]=67108863&o}return 0!==i&&(this.words[n]=i,this.length++),this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),e=0;e<i.length;e++){var n=e%26;i[e]=(t.words[e/26|0]&1<<n)>>>n}return i}(t);if(0===i.length)return new o(1);for(var e=this,n=0;n<i.length&&0===i[n];n++,e=e.sqr());if(++n<i.length)for(var r=e.sqr();n<i.length;n++,r=r.sqr())0!==i[n]&&(e=e.mul(r));return e},o.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var i,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(i=0;i<this.length;i++){var h=this.words[i]&o;this.words[i]=(0|this.words[i])-h<<n|s,s=h>>>26-n}s&&(this.words[i]=s,this.length++)}if(0!==r){for(i=this.length-1;i>=0;i--)this.words[i+r]=this.words[i];for(i=0;i<r;i++)this.words[i]=0;this.length+=r}return this.strip()},o.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,i,n){var r;e("number"==typeof t&&t>=0),r=i?(i-i%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),h=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var a=0;a<s;a++)u.words[a]=this.words[a];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,a=0;a<this.length;a++)this.words[a]=this.words[a+s];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=r);a--){var m=0|this.words[a];this.words[a]=l<<26-o|m>>>o,l=m&h}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(t,i,n){return e(0===this.negative),this.iushrn(t,i,n)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return!(this.length<=n||!(this.words[n]&1<<i))},o.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==i&&n++,this.length=Math.min(n,this.length),0!==i&&(this.words[this.length-1]&=67108863^67108863>>>i<<i),this.strip())},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},o.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,i,n){var r,o;this._expand(t.length+n);var s=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+s;var h=(0|t.words[r])*i;s=((o-=67108863&h)>>26)-(h/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)s=(o=(0|this.words[r+n])+s)>>26,this.words[r+n]=67108863&o;if(0===s)return this.strip();for(e(-1===s),s=0,r=0;r<this.length;r++)s=(o=-(0|this.words[r])+s)>>26,this.words[r]=67108863&o;return this.negative=1,this.strip()},o.prototype._wordDiv=function(t,i){var e,n=this.clone(),r=t,s=0|r.words[r.length-1];0!=(e=26-this._countBits(s))&&(r=r.ushln(e),n.iushln(e),s=0|r.words[r.length-1]);var h,u=n.length-r.length;if("mod"!==i){(h=new o(null)).length=u+1,h.words=new Array(h.length);for(var a=0;a<h.length;a++)h.words[a]=0}var l=n.clone()._ishlnsubmul(r,1,u);0===l.negative&&(n=l,h&&(h.words[u]=1));for(var m=u-1;m>=0;m--){var d=67108864*(0|n.words[r.length+m])+(0|n.words[r.length+m-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(r,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(r,1,m),n.isZero()||(n.negative^=1);h&&(h.words[m]=d)}return h&&h.strip(),n.strip(),"div"!==i&&0!==e&&n.iushrn(e),{div:h||null,mod:n}},o.prototype.divmod=function(t,i,n){return e(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,i),"mod"!==i&&(r=h.div.neg()),"div"!==i&&(s=h.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:r,mod:s}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),i),"mod"!==i&&(r=h.div.neg()),{div:r,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),i),"div"!==i&&(s=h.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:h.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new o(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modn(t.words[0]))}:this._wordDiv(t,i);var r,s,h},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var e=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),r=t.andln(1),o=e.cmp(n);return o<0||1===r&&0===o?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},o.prototype.modn=function(t){e(t<=67108863);for(var i=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(i*n+(0|this.words[r]))%t;return n},o.prototype.idivn=function(t){e(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*i;this.words[n]=r/t|0,i=r%t}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r=new o(1),s=new o(0),h=new o(0),u=new o(1),a=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),m=i.clone();!i.isZero();){for(var d=0,f=1;0==(i.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(i.iushrn(d);d-- >0;)(r.isOdd()||s.isOdd())&&(r.iadd(l),s.isub(m)),r.iushrn(1),s.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(h.isOdd()||u.isOdd())&&(h.iadd(l),u.isub(m)),h.iushrn(1),u.iushrn(1);i.cmp(n)>=0?(i.isub(n),r.isub(h),s.isub(u)):(n.isub(i),h.isub(r),u.isub(s))}return{a:h,b:u,gcd:n.iushln(a)}},o.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r,s=new o(1),h=new o(0),u=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(i.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(i.iushrn(a);a-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)h.isOdd()&&h.iadd(u),h.iushrn(1);i.cmp(n)>=0?(i.isub(n),s.isub(h)):(n.isub(i),h.isub(s))}return(r=0===i.cmpn(1)?s:h).cmpn(0)<0&&r.iadd(t),r},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),e=t.clone();i.negative=0,e.negative=0;for(var n=0;i.isEven()&&e.isEven();n++)i.iushrn(1),e.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;e.isEven();)e.iushrn(1);var r=i.cmp(e);if(r<0){var o=i;i=e,e=o}else if(0===r||0===e.cmpn(1))break;i.isub(e)}return e.iushln(n)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){e("number"==typeof t);var i=t%26,n=(t-i)/26,r=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var h=0|this.words[s];o=(h+=o)>>>26,this.words[s]=h&=67108863}return 0!==o&&(this.words[s]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var r=0|this.words[0];i=r===t?0:r<t?-1:1}return 0!==this.negative?0|-i:i},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],r=0|t.words[e];if(n!==r){n<r?i=-1:n>r&&(i=1);break}}return i},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new _(t)},o.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,i){this.name=t,this.p=new o(i,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=o._prime(t);this.m=i.p,this.prime=i}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var i,e=t;do{this.split(e,this.tmp),i=(e=(e=this.imulK(e)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):void 0!==e.strip?e.strip():e._strip(),e},v.prototype.split=function(t,i){t.iushrn(this.n,0,i)},v.prototype.imulK=function(t){return t.imul(this.k)},r(g,v),g.prototype.split=function(t,i){for(var e=Math.min(t.length,9),n=0;n<e;n++)i.words[n]=t.words[n];if(i.length=e,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(i.words[i.length++]=4194303&r,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(4194303&o)<<4|r>>>22,r=o}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,e=0;e<t.length;e++){var n=0|t.words[e];t.words[e]=67108863&(i+=977*n),i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(M,v),r(w,v),r(b,v),b.prototype.imulK=function(t){for(var i=0,e=0;e<t.length;e++){var n=19*(0|t.words[e])+i,r=67108863&n;n>>>=26,t.words[e]=r,i=n}return 0!==i&&(t.words[t.length++]=i),t},o._prime=function(t){if(y[t])return y[t];var i;if("k256"===t)i=new g;else if("p224"===t)i=new M;else if("p192"===t)i=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return y[t]=i,i},_.prototype._verify1=function(t){e(0===t.negative,"red works only with positives"),e(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){e(0==(t.negative|i.negative),"red works only with positives"),e(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var e=t.add(i);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var e=t.iadd(i);return e.cmp(this.m)>=0&&e.isub(this.m),e},_.prototype.sub=function(t,i){this._verify2(t,i);var e=t.sub(i);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var e=t.isub(i);return e.cmpn(0)<0&&e.iadd(this.m),e},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(e(i%2==1),3===i){var n=this.m.add(new o(1)).iushrn(2);return this.pow(t,n)}for(var r=this.m.subn(1),s=0;!r.isZero()&&0===r.andln(1);)s++,r.iushrn(1);e(!r.isZero());var h=new o(1).toRed(this),u=h.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var m=this.pow(l,r),d=this.pow(t,r.addn(1).iushrn(1)),f=this.pow(t,r),p=s;0!==f.cmp(h);){for(var c=f,y=0;0!==c.cmp(h);y++)c=c.redSqr();e(y<p);var v=this.pow(m,new o(1).iushln(p-y-1));d=d.redMul(v),m=v.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new o(1).toRed(this);if(0===i.cmpn(1))return t.clone();var e=new Array(16);e[0]=new o(1).toRed(this),e[1]=t;for(var n=2;n<e.length;n++)e[n]=this.mul(e[n-1],t);var r=e[0],s=0,h=0,u=i.bitLength()%26;for(0===u&&(u=26),n=i.length-1;n>=0;n--){for(var a=i.words[n],l=u-1;l>=0;l--){var m=a>>l&1;r!==e[0]&&(r=this.sqr(r)),0!==m||0!==s?(s<<=1,s|=m,(4==++h||0===n&&0===l)&&(r=this.mul(r,e[s]),h=0,s=0)):h=0}u=26}return r},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},o.mont=function(t){return new k(t)},r(k,_),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},k.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new o(0)._forceRed(this);var e=t.mul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),s=r;return r.cmp(this.m)>=0?s=r.isub(this.m):r.cmpn(0)<0&&(s=r.iadd(this.m)),s._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,u)}(e={path:void 0,exports:{},require:function(t,i){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),e.exports}(),l=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function m(t){return r.from(h.arrayBuffer(t))}const d=new s("secp256k1");function f(t){const i=(""+t).startsWith("0x")?t.slice(2):t,e=d.keyFromPublic(i,"hex").getPublic().encode("hex");return function(t){var i=t;const e=m(i=i.substring(2).toLowerCase());i=i.split("");for(var n=0;n<40;n+=2)e[n/2]>>4>=8&&(i[n]=i[n].toUpperCase()),(15&e[n/2])>=8&&(i[n+1]=i[n+1].toUpperCase());return"0x"+i.join("")}("0x"+m(r.from(e.slice(2),"hex")).slice(-20).toString("hex"))}function p(t,i,e){if(!t.s){if(e instanceof y){if(!e.s)return void(e.o=p.bind(null,t,i));1&i&&(i=e.s),e=e.v}if(e&&e.then)return void e.then(p.bind(null,t,i),p.bind(null,t,2));t.s=i,t.v=e;const n=t.o;n&&n(t)}}const c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",y=function(){function t(){}return t.prototype.then=function(i,e){const n=new t,r=this.s;if(r){const t=1&r?i:e;if(t){try{p(n,1,t(this.v))}catch(t){p(n,2,t)}return n}return this}return this.o=function(t){try{const r=t.v;1&t.s?p(n,1,i?i(r):r):e?p(n,1,e(r)):p(n,2,r)}catch(t){p(n,2,t)}},n},t}();function v(t){return t instanceof y&&1&t.s}const g=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function M(t){return r.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function w(t){const i="0x"+r.from(t).slice(0,32).toString("hex");return i+"0".repeat(66-i.length)}const b={Secp256k1SignatureAuthentication2018:w("sigAuth"),Secp256k1VerificationKey2018:w("veriKey")},_={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function k(t,i,e,n){const o=new a(Math.floor((new Date).getTime()/1e3)),s=[{id:t+"#owner",type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:i}],h=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#owner"}];e&&(s.push({id:t+"#ownerKey",type:"Secp256k1VerificationKey2018",owner:t,publicKeyHex:e}),h.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#ownerKey"}));let u=0;const l={},m={},d={};for(const i of n){const e=i.validTo,n=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(e&&e.gte(o)){if("DIDDelegateChanged"===i._eventName)switch(u++,M(i.delegateType)){case"sigAuth":l[n]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${u}`};case"veriKey":m[n]={id:`${t}#delegate-${u}`,type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:i.delegate}}else if("DIDAttributeChanged"===i._eventName){const e=M(i.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(e){const o=e[2],s=_[e[4]]||e[4],h=e[6];switch(e[1]){case"pub":{u++;const e={id:`${t}#delegate-${u}`,type:`${o}${s}`,owner:t};switch(h){case null:case void 0:case"hex":e.publicKeyHex=i.value.slice(2);break;case"base64":e.publicKeyBase64=r.from(i.value.slice(2),"hex").toString("base64");break;case"base58":e.publicKeyBase58=r.from(i.value.slice(2),"hex").toString("base58");break;case"pem":e.publicKeyPem=r.from(i.value.slice(2),"hex").toString();break;default:e.value=i.value}m[n]=e;break}case"svc":d[n]={type:o,serviceEndpoint:r.from(i.value.slice(2),"hex").toString()}}}}}else u>0&&("DIDDelegateChanged"===i._eventName||"DIDAttributeChanged"===i._eventName&&M(i.name).match(/^did\/pub\//))&&e.lt(o)&&u--,delete l[n],delete m[n],delete d[n]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:s.concat(Object.values(m)),authentication:h.concat(Object.values(l))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function x(e={}){const n=function(i={}){return i.provider?i.provider:i.web3?i.web3.currentProvider:i.rpcUrl?new t(i.rpcUrl):null}(e);if(null===n)return null;const r=new i(n),s=e.registry||c;return{eth:r,registryAddress:s,didReg:new o(r)(l).at(s)}}function S(t=[]){const i={};for(let e=0;e<t.length;e++){const n=t[e];i[n.name]=x(n),null===i[n.name]&&console.warn("invalid configuration for "+n.name)}return i}module.exports={REGISTRY:c,bytes32toString:M,stringToBytes32:w,delegateTypes:b,attrTypes:_,wrapDidDocument:k,getResolver:function(t={}){const i=e.logDecoder(l,!1),n={mainnet:x(t),...S(t.networks)};return function(t={},i={}){if((i.provider||i.web3||i.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(i&&i.networks)for(const e of i.networks)if(!t[e.name])throw new Error(`Ethereum provider configuration for ${e.name} was attempted but no valid configuration was provided`);let e=0;for(const i of Object.keys(t))null!==t[i]&&e++;if(0===e)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(n,t),{ethr:function(t,e){try{const r=e.id.match(g);if(!r)throw new Error("Not a valid ethr DID: "+t);const o=r[2],s=r[1]?r[1].slice(0,-1):"mainnet";if(!n[s])throw new Error("No conf for networkId: "+s);return Promise.resolve(function(t,e){try{const o=[];let{address:s,publicKey:h}=(r=t).length>42?{address:f(r),publicKey:r}:{address:r},u=s;return Promise.resolve(function(t,i){try{return Promise.resolve(n[i].didReg.changed(t)).then(function(t){if(t)return t[0]})}catch(t){return Promise.reject(t)}}(s,e)).then(function(t){function r(){function r(){return{owner:u,history:o,publicKey:h}}const a=function(t,i,e){for(var n;;){var r=t();if(v(r)&&(r=r.v),!r)return o;if(r.then){n=0;break}var o=e();if(o&&o.then){if(!v(o)){n=1;break}o=o.s}}var s=new y,h=p.bind(null,s,2);return(0===n?r.then(a):1===n?o.then(u):(void 0).then(function(){(r=t())?r.then?r.then(a).then(void 0,h):a(r):p(s,1,o)})).then(void 0,h),s;function u(i){o=i;do{if(!(r=t())||v(r)&&!r.v)return void p(s,1,o);if(r.then)return void r.then(a).then(void 0,h);v(o=e())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,h)}function a(t){t?(o=e())&&o.then?o.then(u).then(void 0,h):u(o):p(s,1,o)}}(function(){return!!t},0,function(){const r=t;return Promise.resolve(n[e].eth.getLogs({address:n[e].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:t,toBlock:t})).then(function(e){const n=i(e);t=void 0;for(const i of n)o.unshift(i),i.previousChange.lt(r)&&(t=i.previousChange)})});return a&&a.then?a.then(r):r()}const a=function(){if(t)return Promise.resolve(n[e].didReg.identityOwner(s)).then(function(t){const i=""+t[0];i.toLowerCase()!==u.toLowerCase()&&(h=null),u=i})}();return a&&a.then?a.then(r):r()})}catch(t){return Promise.reject(t)}var r}(o,s)).then(function({owner:i,history:e,publicKey:n}){return k(t,i,n,e)})}catch(t){return Promise.reject(t)}}}},identifierMatcher:g}; | ||
import t from"ethjs-provider-http";import i from"ethjs-query";import e from"ethjs-abi";import n,{Buffer as r}from"buffer";import o from"ethjs-contract";import{ec as s}from"elliptic";import{keccak_256 as h}from"js-sha3";var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a=function(t,i,e){return function(t){!function(t,i){function e(t,i){if(!t)throw new Error(i||"Assertion failed")}function r(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}function o(t,i,e){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(e=i,i=10),this._init(t||0,i||10,e||"be"))}var s;"object"==typeof t?t.exports=o:i.BN=o,o.BN=o,o.wordSize=26;try{s=n.Buffer}catch(t){}function h(t,i,e){for(var n=0,r=Math.min(t.length,e),o=i;o<r;o++){var s=t.charCodeAt(o)-48;n<<=4,n|=s>=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function u(t,i,e,n){for(var r=0,o=Math.min(t.length,e),s=i;s<o;s++){var h=t.charCodeAt(s)-48;r*=n,r+=h>=49?h-49+10:h>=17?h-17+10:h}return r}o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,i){return t.cmp(i)>0?t:i},o.min=function(t,i){return t.cmp(i)<0?t:i},o.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),e(i===(0|i)&&i>=2&&i<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===i?this._parseHex(t,r):this._parseBase(t,i,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),i,n)},o.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},o.prototype._initArray=function(t,i,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,s,h=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)this.words[o]|=(s=t[r]|t[r-1]<<8|t[r-2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)this.words[o]|=(s=t[r]|t[r+1]<<8|t[r+2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);return this.strip()},o.prototype._parseHex=function(t,i){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var n,r,o=0;for(e=t.length-6,n=0;e>=i;e-=6)r=h(t,e,e+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);e+6!==i&&(r=h(t,i,e+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303),this.strip()},o.prototype._parseBase=function(t,i,e){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=i)n++;n--,r=r/i|0;for(var o=t.length-e,s=o%n,h=Math.min(o,o-s)+e,a=0,l=e;l<h;l+=n)a=u(t,l,l+n,i),this.imuln(r),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==s){var m=1;for(a=u(t,l,t.length,i),l=0;l<s;l++)m*=i;this.imuln(m),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}},o.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},o.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},o.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,e){e.negative=i.negative^t.negative;var n=t.length+i.length|0;e.length=n,n=n-1|0;var r=0|t.words[0],o=0|i.words[0],s=r*o,h=s/67108864|0;e.words[0]=67108863&s;for(var u=1;u<n;u++){for(var a=h>>>26,l=67108863&h,m=Math.min(u,i.length-1),d=Math.max(0,u-t.length+1);d<=m;d++)a+=(s=(r=0|t.words[u-d|0])*(o=0|i.words[d])+l)/67108864|0,l=67108863&s;e.words[u]=0|l,h=0|a}return 0!==h?e.words[u]=0|h:e.length--,e.strip()}o.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var h=this.words[s],u=(16777215&(h<<r|o)).toString(16);n=0!=(o=h>>>24-r&16777215)||s!==this.length-1?a[6-u.length]+u+n:u+n,(r+=2)>=26&&(r-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:a[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(t,i){return e(void 0!==s),this.toArrayLike(s,t,i)},o.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},o.prototype.toArrayLike=function(t,i,n){var r=this.byteLength(),o=n||Math.max(1,r);e(r<=o,"byte array longer than desired length"),e(o>0,"Requested array length <= 0"),this.strip();var s,h,u="le"===i,a=new t(o),l=this.clone();if(u){for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[h]=s;for(;h<o;h++)a[h]=0}else{for(h=0;h<o-r;h++)a[h]=0;for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[o-h-1]=s}return a},o.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var i=t,e=0;return i>=4096&&(e+=13,i>>>=13),i>=64&&(e+=7,i>>>=7),i>=8&&(e+=4,i>>>=4),i>=2&&(e+=2,i>>>=2),e+i},o.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,e=0;return 0==(8191&i)&&(e+=13,i>>>=13),0==(127&i)&&(e+=7,i>>>=7),0==(15&i)&&(e+=4,i>>>=4),0==(3&i)&&(e+=2,i>>>=2),0==(1&i)&&e++,e},o.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var e=this._zeroBits(this.words[i]);if(t+=e,26!==e)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},o.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var e=0;e<i.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=i.length,this.strip()},o.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var i,e;this.length>t.length?(i=this,e=t):(i=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=i.words[n]^e.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},o.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var r=0;r<i;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,i){e("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},o.prototype.iadd=function(t){var i,e,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0,o=0;o<n.length;o++)this.words[o]=67108863&(i=(0|e.words[o])+(0|n.words[o])+r),r=i>>>26;for(;0!==r&&o<e.length;o++)this.words[o]=67108863&(i=(0|e.words[o])+r),r=i>>>26;if(this.length=e.length,0!==r)this.words[this.length]=r,this.length++;else if(e!==this)for(;o<e.length;o++)this.words[o]=e.words[o];return this},o.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(e=this,n=t):(e=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(i=(0|e.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&i;for(;0!==o&&s<e.length;s++)o=(i=(0|e.words[s])+o)>>26,this.words[s]=67108863&i;if(0===o&&s<e.length&&e!==this)for(;s<e.length;s++)this.words[s]=e.words[s];return this.length=Math.max(this.length,s),e!==this&&(this.negative=1),this.strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,i,e){var n,r,o,s=t.words,h=i.words,u=e.words,a=0,l=0|s[0],m=8191&l,d=l>>>13,f=0|s[1],p=8191&f,c=f>>>13,y=0|s[2],v=8191&y,g=y>>>13,M=0|s[3],w=8191&M,b=M>>>13,_=0|s[4],k=8191&_,x=_>>>13,S=0|s[5],A=8191&S,R=S>>>13,D=0|s[6],K=8191&D,q=D>>>13,B=0|s[7],T=8191&B,Z=B>>>13,N=0|s[8],I=8191&N,j=N>>>13,E=0|s[9],O=8191&E,C=E>>>13,L=0|h[0],P=8191&L,$=L>>>13,z=0|h[1],V=8191&z,F=z>>>13,U=0|h[2],H=8191&U,G=U>>>13,J=0|h[3],W=8191&J,Y=J>>>13,Q=0|h[4],X=8191&Q,tt=Q>>>13,it=0|h[5],et=8191&it,nt=it>>>13,rt=0|h[6],ot=8191&rt,st=rt>>>13,ht=0|h[7],ut=8191&ht,at=ht>>>13,lt=0|h[8],mt=8191<,dt=lt>>>13,ft=0|h[9],pt=8191&ft,ct=ft>>>13;e.negative=t.negative^i.negative,e.length=19;var yt=(a+(n=Math.imul(m,P))|0)+((8191&(r=(r=Math.imul(m,$))+Math.imul(d,P)|0))<<13)|0;a=((o=Math.imul(d,$))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,P),r=(r=Math.imul(p,$))+Math.imul(c,P)|0,o=Math.imul(c,$);var vt=(a+(n=n+Math.imul(m,V)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,V)|0))<<13)|0;a=((o=o+Math.imul(d,F)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,P),r=(r=Math.imul(v,$))+Math.imul(g,P)|0,o=Math.imul(g,$),n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,V)|0,o=o+Math.imul(c,F)|0;var gt=(a+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;a=((o=o+Math.imul(d,G)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(w,P),r=(r=Math.imul(w,$))+Math.imul(b,P)|0,o=Math.imul(b,$),n=n+Math.imul(v,V)|0,r=(r=r+Math.imul(v,F)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,o=o+Math.imul(c,G)|0;var Mt=(a+(n=n+Math.imul(m,W)|0)|0)+((8191&(r=(r=r+Math.imul(m,Y)|0)+Math.imul(d,W)|0))<<13)|0;a=((o=o+Math.imul(d,Y)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(k,P),r=(r=Math.imul(k,$))+Math.imul(x,P)|0,o=Math.imul(x,$),n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,F)|0,n=n+Math.imul(v,H)|0,r=(r=r+Math.imul(v,G)|0)+Math.imul(g,H)|0,o=o+Math.imul(g,G)|0,n=n+Math.imul(p,W)|0,r=(r=r+Math.imul(p,Y)|0)+Math.imul(c,W)|0,o=o+Math.imul(c,Y)|0;var wt=(a+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;a=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,P),r=(r=Math.imul(A,$))+Math.imul(R,P)|0,o=Math.imul(R,$),n=n+Math.imul(k,V)|0,r=(r=r+Math.imul(k,F)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,o=o+Math.imul(b,G)|0,n=n+Math.imul(v,W)|0,r=(r=r+Math.imul(v,Y)|0)+Math.imul(g,W)|0,o=o+Math.imul(g,Y)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,o=o+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(m,et)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,et)|0))<<13)|0;a=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(K,P),r=(r=Math.imul(K,$))+Math.imul(q,P)|0,o=Math.imul(q,$),n=n+Math.imul(A,V)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,F)|0,n=n+Math.imul(k,H)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(x,H)|0,o=o+Math.imul(x,G)|0,n=n+Math.imul(w,W)|0,r=(r=r+Math.imul(w,Y)|0)+Math.imul(b,W)|0,o=o+Math.imul(b,Y)|0,n=n+Math.imul(v,X)|0,r=(r=r+Math.imul(v,tt)|0)+Math.imul(g,X)|0,o=o+Math.imul(g,tt)|0,n=n+Math.imul(p,et)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,et)|0,o=o+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(m,ot)|0)|0)+((8191&(r=(r=r+Math.imul(m,st)|0)+Math.imul(d,ot)|0))<<13)|0;a=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(T,P),r=(r=Math.imul(T,$))+Math.imul(Z,P)|0,o=Math.imul(Z,$),n=n+Math.imul(K,V)|0,r=(r=r+Math.imul(K,F)|0)+Math.imul(q,V)|0,o=o+Math.imul(q,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,o=o+Math.imul(R,G)|0,n=n+Math.imul(k,W)|0,r=(r=r+Math.imul(k,Y)|0)+Math.imul(x,W)|0,o=o+Math.imul(x,Y)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(v,et)|0,r=(r=r+Math.imul(v,nt)|0)+Math.imul(g,et)|0,o=o+Math.imul(g,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(c,ot)|0,o=o+Math.imul(c,st)|0;var kt=(a+(n=n+Math.imul(m,ut)|0)|0)+((8191&(r=(r=r+Math.imul(m,at)|0)+Math.imul(d,ut)|0))<<13)|0;a=((o=o+Math.imul(d,at)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(I,P),r=(r=Math.imul(I,$))+Math.imul(j,P)|0,o=Math.imul(j,$),n=n+Math.imul(T,V)|0,r=(r=r+Math.imul(T,F)|0)+Math.imul(Z,V)|0,o=o+Math.imul(Z,F)|0,n=n+Math.imul(K,H)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(q,H)|0,o=o+Math.imul(q,G)|0,n=n+Math.imul(A,W)|0,r=(r=r+Math.imul(A,Y)|0)+Math.imul(R,W)|0,o=o+Math.imul(R,Y)|0,n=n+Math.imul(k,X)|0,r=(r=r+Math.imul(k,tt)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(w,et)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,et)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(v,ot)|0,r=(r=r+Math.imul(v,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,at)|0)+Math.imul(c,ut)|0,o=o+Math.imul(c,at)|0;var xt=(a+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;a=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(O,P),r=(r=Math.imul(O,$))+Math.imul(C,P)|0,o=Math.imul(C,$),n=n+Math.imul(I,V)|0,r=(r=r+Math.imul(I,F)|0)+Math.imul(j,V)|0,o=o+Math.imul(j,F)|0,n=n+Math.imul(T,H)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(Z,H)|0,o=o+Math.imul(Z,G)|0,n=n+Math.imul(K,W)|0,r=(r=r+Math.imul(K,Y)|0)+Math.imul(q,W)|0,o=o+Math.imul(q,Y)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,n=n+Math.imul(k,et)|0,r=(r=r+Math.imul(k,nt)|0)+Math.imul(x,et)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,n=n+Math.imul(v,ut)|0,r=(r=r+Math.imul(v,at)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,at)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,o=o+Math.imul(c,dt)|0;var St=(a+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;a=((o=o+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(O,V),r=(r=Math.imul(O,F))+Math.imul(C,V)|0,o=Math.imul(C,F),n=n+Math.imul(I,H)|0,r=(r=r+Math.imul(I,G)|0)+Math.imul(j,H)|0,o=o+Math.imul(j,G)|0,n=n+Math.imul(T,W)|0,r=(r=r+Math.imul(T,Y)|0)+Math.imul(Z,W)|0,o=o+Math.imul(Z,Y)|0,n=n+Math.imul(K,X)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(q,X)|0,o=o+Math.imul(q,tt)|0,n=n+Math.imul(A,et)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,et)|0,o=o+Math.imul(R,nt)|0,n=n+Math.imul(k,ot)|0,r=(r=r+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,at)|0)+Math.imul(b,ut)|0,o=o+Math.imul(b,at)|0,n=n+Math.imul(v,mt)|0,r=(r=r+Math.imul(v,dt)|0)+Math.imul(g,mt)|0,o=o+Math.imul(g,dt)|0;var At=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((o=o+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(O,H),r=(r=Math.imul(O,G))+Math.imul(C,H)|0,o=Math.imul(C,G),n=n+Math.imul(I,W)|0,r=(r=r+Math.imul(I,Y)|0)+Math.imul(j,W)|0,o=o+Math.imul(j,Y)|0,n=n+Math.imul(T,X)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(Z,X)|0,o=o+Math.imul(Z,tt)|0,n=n+Math.imul(K,et)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(q,et)|0,o=o+Math.imul(q,nt)|0,n=n+Math.imul(A,ot)|0,r=(r=r+Math.imul(A,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,n=n+Math.imul(k,ut)|0,r=(r=r+Math.imul(k,at)|0)+Math.imul(x,ut)|0,o=o+Math.imul(x,at)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,o=o+Math.imul(b,dt)|0;var Rt=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(r=(r=r+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((o=o+Math.imul(g,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(O,W),r=(r=Math.imul(O,Y))+Math.imul(C,W)|0,o=Math.imul(C,Y),n=n+Math.imul(I,X)|0,r=(r=r+Math.imul(I,tt)|0)+Math.imul(j,X)|0,o=o+Math.imul(j,tt)|0,n=n+Math.imul(T,et)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(Z,et)|0,o=o+Math.imul(Z,nt)|0,n=n+Math.imul(K,ot)|0,r=(r=r+Math.imul(K,st)|0)+Math.imul(q,ot)|0,o=o+Math.imul(q,st)|0,n=n+Math.imul(A,ut)|0,r=(r=r+Math.imul(A,at)|0)+Math.imul(R,ut)|0,o=o+Math.imul(R,at)|0,n=n+Math.imul(k,mt)|0,r=(r=r+Math.imul(k,dt)|0)+Math.imul(x,mt)|0,o=o+Math.imul(x,dt)|0;var Dt=(a+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((o=o+Math.imul(b,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(O,X),r=(r=Math.imul(O,tt))+Math.imul(C,X)|0,o=Math.imul(C,tt),n=n+Math.imul(I,et)|0,r=(r=r+Math.imul(I,nt)|0)+Math.imul(j,et)|0,o=o+Math.imul(j,nt)|0,n=n+Math.imul(T,ot)|0,r=(r=r+Math.imul(T,st)|0)+Math.imul(Z,ot)|0,o=o+Math.imul(Z,st)|0,n=n+Math.imul(K,ut)|0,r=(r=r+Math.imul(K,at)|0)+Math.imul(q,ut)|0,o=o+Math.imul(q,at)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,o=o+Math.imul(R,dt)|0;var Kt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(r=(r=r+Math.imul(k,ct)|0)+Math.imul(x,pt)|0))<<13)|0;a=((o=o+Math.imul(x,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(O,et),r=(r=Math.imul(O,nt))+Math.imul(C,et)|0,o=Math.imul(C,nt),n=n+Math.imul(I,ot)|0,r=(r=r+Math.imul(I,st)|0)+Math.imul(j,ot)|0,o=o+Math.imul(j,st)|0,n=n+Math.imul(T,ut)|0,r=(r=r+Math.imul(T,at)|0)+Math.imul(Z,ut)|0,o=o+Math.imul(Z,at)|0,n=n+Math.imul(K,mt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(q,mt)|0,o=o+Math.imul(q,dt)|0;var qt=(a+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;a=((o=o+Math.imul(R,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(O,ot),r=(r=Math.imul(O,st))+Math.imul(C,ot)|0,o=Math.imul(C,st),n=n+Math.imul(I,ut)|0,r=(r=r+Math.imul(I,at)|0)+Math.imul(j,ut)|0,o=o+Math.imul(j,at)|0,n=n+Math.imul(T,mt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(Z,mt)|0,o=o+Math.imul(Z,dt)|0;var Bt=(a+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,ct)|0)+Math.imul(q,pt)|0))<<13)|0;a=((o=o+Math.imul(q,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(O,ut),r=(r=Math.imul(O,at))+Math.imul(C,ut)|0,o=Math.imul(C,at),n=n+Math.imul(I,mt)|0,r=(r=r+Math.imul(I,dt)|0)+Math.imul(j,mt)|0,o=o+Math.imul(j,dt)|0;var Tt=(a+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((o=o+Math.imul(Z,ct)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(O,mt),r=(r=Math.imul(O,dt))+Math.imul(C,mt)|0,o=Math.imul(C,dt);var Zt=(a+(n=n+Math.imul(I,pt)|0)|0)+((8191&(r=(r=r+Math.imul(I,ct)|0)+Math.imul(j,pt)|0))<<13)|0;a=((o=o+Math.imul(j,ct)|0)+(r>>>13)|0)+(Zt>>>26)|0,Zt&=67108863;var Nt=(a+(n=Math.imul(O,pt))|0)+((8191&(r=(r=Math.imul(O,ct))+Math.imul(C,pt)|0))<<13)|0;return a=((o=Math.imul(C,ct))+(r>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,u[0]=yt,u[1]=vt,u[2]=gt,u[3]=Mt,u[4]=wt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=xt,u[9]=St,u[10]=At,u[11]=Rt,u[12]=Dt,u[13]=Kt,u[14]=qt,u[15]=Bt,u[16]=Tt,u[17]=Zt,u[18]=Nt,0!==a&&(u[19]=a,e.length++),e};function p(t,i,e){return(new c).mulp(t,i,e)}function c(t,i){this.x=t,this.y=i}Math.imul||(f=d),o.prototype.mulTo=function(t,i){var e=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,i):e<63?d(this,t,i):e<1024?function(t,i,e){e.negative=i.negative^t.negative,e.length=t.length+i.length;for(var n=0,r=0,o=0;o<e.length-1;o++){var s=r;r=0;for(var h=67108863&n,u=Math.min(o,i.length-1),a=Math.max(0,o-t.length+1);a<=u;a++){var l=(0|t.words[o-a])*(0|i.words[a]),m=67108863&l;h=67108863&(m=m+h|0),r+=(s=(s=s+(l/67108864|0)|0)+(m>>>26)|0)>>>26,s&=67108863}e.words[o]=h,n=s,s=r}return 0!==n?e.words[o]=n:e.length--,e.strip()}(this,t,i):p(this,t,i)},c.prototype.makeRBT=function(t){for(var i=new Array(t),e=o.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,e,t);return i},c.prototype.revBin=function(t,i,e){if(0===t||t===e-1)return t;for(var n=0,r=0;r<i;r++)n|=(1&t)<<i-r-1,t>>=1;return n},c.prototype.permute=function(t,i,e,n,r,o){for(var s=0;s<o;s++)n[s]=i[t[s]],r[s]=e[t[s]]},c.prototype.transform=function(t,i,e,n,r,o){this.permute(o,t,i,e,n,r);for(var s=1;s<r;s<<=1)for(var h=s<<1,u=Math.cos(2*Math.PI/h),a=Math.sin(2*Math.PI/h),l=0;l<r;l+=h)for(var m=u,d=a,f=0;f<s;f++){var p=e[l+f],c=n[l+f],y=e[l+f+s],v=n[l+f+s],g=m*y-d*v;v=m*v+d*y,e[l+f]=p+(y=g),n[l+f]=c+v,e[l+f+s]=p-y,n[l+f+s]=c-v,f!==h&&(g=u*m-a*d,d=u*d+a*m,m=g)}},c.prototype.guessLen13b=function(t,i){var e=1|Math.max(i,t),n=1&e,r=0;for(e=e/2|0;e;e>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,i,e){if(!(e<=1))for(var n=0;n<e/2;n++){var r=t[n];t[n]=t[e-n-1],t[e-n-1]=r,r=i[n],i[n]=-i[e-n-1],i[e-n-1]=-r}},c.prototype.normalize13b=function(t,i){for(var e=0,n=0;n<i/2;n++){var r=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+e;t[n]=67108863&r,e=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,i,n,r){for(var o=0,s=0;s<i;s++)n[2*s]=8191&(o+=0|t[s]),n[2*s+1]=8191&(o>>>=13),o>>>=13;for(s=2*i;s<r;++s)n[s]=0;e(0===o),e(0==(-8192&o))},c.prototype.stub=function(t){for(var i=new Array(t),e=0;e<t;e++)i[e]=0;return i},c.prototype.mulp=function(t,i,e){var n=2*this.guessLen13b(t.length,i.length),r=this.makeRBT(n),o=this.stub(n),s=new Array(n),h=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),m=new Array(n),d=e.words;d.length=n,this.convert13b(t.words,t.length,s,n),this.convert13b(i.words,i.length,a,n),this.transform(s,o,h,u,n,r),this.transform(a,o,l,m,n,r);for(var f=0;f<n;f++){var p=h[f]*l[f]-u[f]*m[f];u[f]=h[f]*m[f]+u[f]*l[f],h[f]=p}return this.conjugate(h,u,n),this.transform(h,u,d,o,n,r),this.conjugate(d,o,n),this.normalize13b(d,n),e.negative=t.negative^i.negative,e.length=t.length+i.length,e.strip()},o.prototype.mul=function(t){var i=new o(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},o.prototype.mulf=function(t){var i=new o(null);return i.words=new Array(this.length+t.length),p(this,t,i)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var i=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,o=(67108863&r)+(67108863&i);i>>=26,i+=r/67108864|0,i+=o>>>26,this.words[n]=67108863&o}return 0!==i&&(this.words[n]=i,this.length++),this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),e=0;e<i.length;e++){var n=e%26;i[e]=(t.words[e/26|0]&1<<n)>>>n}return i}(t);if(0===i.length)return new o(1);for(var e=this,n=0;n<i.length&&0===i[n];n++,e=e.sqr());if(++n<i.length)for(var r=e.sqr();n<i.length;n++,r=r.sqr())0!==i[n]&&(e=e.mul(r));return e},o.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var i,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(i=0;i<this.length;i++){var h=this.words[i]&o;this.words[i]=(0|this.words[i])-h<<n|s,s=h>>>26-n}s&&(this.words[i]=s,this.length++)}if(0!==r){for(i=this.length-1;i>=0;i--)this.words[i+r]=this.words[i];for(i=0;i<r;i++)this.words[i]=0;this.length+=r}return this.strip()},o.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,i,n){var r;e("number"==typeof t&&t>=0),r=i?(i-i%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),h=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var a=0;a<s;a++)u.words[a]=this.words[a];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,a=0;a<this.length;a++)this.words[a]=this.words[a+s];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=r);a--){var m=0|this.words[a];this.words[a]=l<<26-o|m>>>o,l=m&h}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(t,i,n){return e(0===this.negative),this.iushrn(t,i,n)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return!(this.length<=n||!(this.words[n]&1<<i))},o.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==i&&n++,this.length=Math.min(n,this.length),0!==i&&(this.words[this.length-1]&=67108863^67108863>>>i<<i),this.strip())},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},o.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,i,n){var r,o;this._expand(t.length+n);var s=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+s;var h=(0|t.words[r])*i;s=((o-=67108863&h)>>26)-(h/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)s=(o=(0|this.words[r+n])+s)>>26,this.words[r+n]=67108863&o;if(0===s)return this.strip();for(e(-1===s),s=0,r=0;r<this.length;r++)s=(o=-(0|this.words[r])+s)>>26,this.words[r]=67108863&o;return this.negative=1,this.strip()},o.prototype._wordDiv=function(t,i){var e,n=this.clone(),r=t,s=0|r.words[r.length-1];0!=(e=26-this._countBits(s))&&(r=r.ushln(e),n.iushln(e),s=0|r.words[r.length-1]);var h,u=n.length-r.length;if("mod"!==i){(h=new o(null)).length=u+1,h.words=new Array(h.length);for(var a=0;a<h.length;a++)h.words[a]=0}var l=n.clone()._ishlnsubmul(r,1,u);0===l.negative&&(n=l,h&&(h.words[u]=1));for(var m=u-1;m>=0;m--){var d=67108864*(0|n.words[r.length+m])+(0|n.words[r.length+m-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(r,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(r,1,m),n.isZero()||(n.negative^=1);h&&(h.words[m]=d)}return h&&h.strip(),n.strip(),"div"!==i&&0!==e&&n.iushrn(e),{div:h||null,mod:n}},o.prototype.divmod=function(t,i,n){return e(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,i),"mod"!==i&&(r=h.div.neg()),"div"!==i&&(s=h.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:r,mod:s}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),i),"mod"!==i&&(r=h.div.neg()),{div:r,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),i),"div"!==i&&(s=h.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:h.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new o(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modn(t.words[0]))}:this._wordDiv(t,i);var r,s,h},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var e=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),r=t.andln(1),o=e.cmp(n);return o<0||1===r&&0===o?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},o.prototype.modn=function(t){e(t<=67108863);for(var i=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(i*n+(0|this.words[r]))%t;return n},o.prototype.idivn=function(t){e(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*i;this.words[n]=r/t|0,i=r%t}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r=new o(1),s=new o(0),h=new o(0),u=new o(1),a=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),m=i.clone();!i.isZero();){for(var d=0,f=1;0==(i.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(i.iushrn(d);d-- >0;)(r.isOdd()||s.isOdd())&&(r.iadd(l),s.isub(m)),r.iushrn(1),s.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(h.isOdd()||u.isOdd())&&(h.iadd(l),u.isub(m)),h.iushrn(1),u.iushrn(1);i.cmp(n)>=0?(i.isub(n),r.isub(h),s.isub(u)):(n.isub(i),h.isub(r),u.isub(s))}return{a:h,b:u,gcd:n.iushln(a)}},o.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r,s=new o(1),h=new o(0),u=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(i.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(i.iushrn(a);a-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)h.isOdd()&&h.iadd(u),h.iushrn(1);i.cmp(n)>=0?(i.isub(n),s.isub(h)):(n.isub(i),h.isub(s))}return(r=0===i.cmpn(1)?s:h).cmpn(0)<0&&r.iadd(t),r},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),e=t.clone();i.negative=0,e.negative=0;for(var n=0;i.isEven()&&e.isEven();n++)i.iushrn(1),e.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;e.isEven();)e.iushrn(1);var r=i.cmp(e);if(r<0){var o=i;i=e,e=o}else if(0===r||0===e.cmpn(1))break;i.isub(e)}return e.iushln(n)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){e("number"==typeof t);var i=t%26,n=(t-i)/26,r=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var h=0|this.words[s];o=(h+=o)>>>26,this.words[s]=h&=67108863}return 0!==o&&(this.words[s]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var r=0|this.words[0];i=r===t?0:r<t?-1:1}return 0!==this.negative?0|-i:i},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],r=0|t.words[e];if(n!==r){n<r?i=-1:n>r&&(i=1);break}}return i},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new _(t)},o.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,i){this.name=t,this.p=new o(i,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=o._prime(t);this.m=i.p,this.prime=i}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var i,e=t;do{this.split(e,this.tmp),i=(e=(e=this.imulK(e)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):void 0!==e.strip?e.strip():e._strip(),e},v.prototype.split=function(t,i){t.iushrn(this.n,0,i)},v.prototype.imulK=function(t){return t.imul(this.k)},r(g,v),g.prototype.split=function(t,i){for(var e=Math.min(t.length,9),n=0;n<e;n++)i.words[n]=t.words[n];if(i.length=e,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(i.words[i.length++]=4194303&r,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(4194303&o)<<4|r>>>22,r=o}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,e=0;e<t.length;e++){var n=0|t.words[e];t.words[e]=67108863&(i+=977*n),i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(M,v),r(w,v),r(b,v),b.prototype.imulK=function(t){for(var i=0,e=0;e<t.length;e++){var n=19*(0|t.words[e])+i,r=67108863&n;n>>>=26,t.words[e]=r,i=n}return 0!==i&&(t.words[t.length++]=i),t},o._prime=function(t){if(y[t])return y[t];var i;if("k256"===t)i=new g;else if("p224"===t)i=new M;else if("p192"===t)i=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return y[t]=i,i},_.prototype._verify1=function(t){e(0===t.negative,"red works only with positives"),e(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){e(0==(t.negative|i.negative),"red works only with positives"),e(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var e=t.add(i);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var e=t.iadd(i);return e.cmp(this.m)>=0&&e.isub(this.m),e},_.prototype.sub=function(t,i){this._verify2(t,i);var e=t.sub(i);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var e=t.isub(i);return e.cmpn(0)<0&&e.iadd(this.m),e},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(e(i%2==1),3===i){var n=this.m.add(new o(1)).iushrn(2);return this.pow(t,n)}for(var r=this.m.subn(1),s=0;!r.isZero()&&0===r.andln(1);)s++,r.iushrn(1);e(!r.isZero());var h=new o(1).toRed(this),u=h.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var m=this.pow(l,r),d=this.pow(t,r.addn(1).iushrn(1)),f=this.pow(t,r),p=s;0!==f.cmp(h);){for(var c=f,y=0;0!==c.cmp(h);y++)c=c.redSqr();e(y<p);var v=this.pow(m,new o(1).iushln(p-y-1));d=d.redMul(v),m=v.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new o(1).toRed(this);if(0===i.cmpn(1))return t.clone();var e=new Array(16);e[0]=new o(1).toRed(this),e[1]=t;for(var n=2;n<e.length;n++)e[n]=this.mul(e[n-1],t);var r=e[0],s=0,h=0,u=i.bitLength()%26;for(0===u&&(u=26),n=i.length-1;n>=0;n--){for(var a=i.words[n],l=u-1;l>=0;l--){var m=a>>l&1;r!==e[0]&&(r=this.sqr(r)),0!==m||0!==s?(s<<=1,s|=m,(4==++h||0===n&&0===l)&&(r=this.mul(r,e[s]),h=0,s=0)):h=0}u=26}return r},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},o.mont=function(t){return new k(t)},r(k,_),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},k.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new o(0)._forceRed(this);var e=t.mul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),s=r;return r.cmp(this.m)>=0?s=r.isub(this.m):r.cmpn(0)<0&&(s=r.iadd(this.m)),s._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,u)}(e={path:void 0,exports:{},require:function(t,i){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),e.exports}(),l=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function m(t){return r.from(h.arrayBuffer(t))}const d=new s("secp256k1");function f(t){const i=(""+t).startsWith("0x")?t.slice(2):t,e=d.keyFromPublic(i,"hex").getPublic().encode("hex");return function(t){var i=t;const e=m(i=i.substring(2).toLowerCase());i=i.split("");for(var n=0;n<40;n+=2)e[n/2]>>4>=8&&(i[n]=i[n].toUpperCase()),(15&e[n/2])>=8&&(i[n+1]=i[n+1].toUpperCase());return"0x"+i.join("")}("0x"+m(r.from(e.slice(2),"hex")).slice(-20).toString("hex"))}function p(t,i,e){if(!t.s){if(e instanceof y){if(!e.s)return void(e.o=p.bind(null,t,i));1&i&&(i=e.s),e=e.v}if(e&&e.then)return void e.then(p.bind(null,t,i),p.bind(null,t,2));t.s=i,t.v=e;const n=t.o;n&&n(t)}}const c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",y=function(){function t(){}return t.prototype.then=function(i,e){const n=new t,r=this.s;if(r){const t=1&r?i:e;if(t){try{p(n,1,t(this.v))}catch(t){p(n,2,t)}return n}return this}return this.o=function(t){try{const r=t.v;1&t.s?p(n,1,i?i(r):r):e?p(n,1,e(r)):p(n,2,r)}catch(t){p(n,2,t)}},n},t}();function v(t){return t instanceof y&&1&t.s}const g=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function M(t){return r.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function w(t){const i="0x"+r.from(t).slice(0,32).toString("hex");return i+"0".repeat(66-i.length)}const b={Secp256k1SignatureAuthentication2018:w("sigAuth"),Secp256k1VerificationKey2018:w("veriKey")},_={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function k(t,i,e,n){const o=new a(Math.floor((new Date).getTime()/1e3)),s=[{id:t+"#controller",type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:i}],h=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controller"}];e&&(s.push({id:t+"#controllerKey",type:"Secp256k1VerificationKey2018",controller:t,publicKeyHex:e}),h.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controllerKey"}));let u=0;const l={},m={},d={};for(const i of n){const e=i.validTo,n=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(e&&e.gte(o)){if("DIDDelegateChanged"===i._eventName)switch(u++,M(i.delegateType)){case"sigAuth":l[n]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${u}`};case"veriKey":m[n]={id:`${t}#delegate-${u}`,type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:i.delegate}}else if("DIDAttributeChanged"===i._eventName){const e=M(i.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(e){const o=e[2],s=_[e[4]]||e[4],h=e[6];switch(e[1]){case"pub":{u++;const e={id:`${t}#delegate-${u}`,type:`${o}${s}`,controller:t};switch(h){case null:case void 0:case"hex":e.publicKeyHex=i.value.slice(2);break;case"base64":e.publicKeyBase64=r.from(i.value.slice(2),"hex").toString("base64");break;case"base58":e.publicKeyBase58=r.from(i.value.slice(2),"hex").toString("base58");break;case"pem":e.publicKeyPem=r.from(i.value.slice(2),"hex").toString();break;default:e.value=i.value}m[n]=e;break}case"svc":d[n]={type:o,serviceEndpoint:r.from(i.value.slice(2),"hex").toString()}}}}}else u>0&&("DIDDelegateChanged"===i._eventName||"DIDAttributeChanged"===i._eventName&&M(i.name).match(/^did\/pub\//))&&e.lt(o)&&u--,delete l[n],delete m[n],delete d[n]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:s.concat(Object.values(m)),authentication:h.concat(Object.values(l))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function x(e={}){const n=function(i={}){return i.provider?i.provider:i.web3?i.web3.currentProvider:i.rpcUrl?new t(i.rpcUrl):null}(e);if(null===n)return null;const r=new i(n),s=e.registry||c;return{eth:r,registryAddress:s,didReg:new o(r)(l).at(s)}}function S(t=[]){const i={};for(let e=0;e<t.length;e++){const n=t[e];i[n.name]=x(n),null===i[n.name]&&console.warn("invalid configuration for "+n.name)}return i}module.exports={REGISTRY:c,bytes32toString:M,stringToBytes32:w,delegateTypes:b,attrTypes:_,wrapDidDocument:k,getResolver:function(t={}){const i=e.logDecoder(l,!1),n={mainnet:x(t),...S(t.networks)};return function(t={},i={}){if((i.provider||i.web3||i.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(i&&i.networks)for(const e of i.networks)if(!t[e.name])throw new Error(`Ethereum provider configuration for ${e.name} was attempted but no valid configuration was provided`);let e=0;for(const i of Object.keys(t))null!==t[i]&&e++;if(0===e)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(n,t),{ethr:function(t,e){try{const r=e.id.match(g);if(!r)throw new Error("Not a valid ethr DID: "+t);const o=r[2],s=r[1]?r[1].slice(0,-1):"mainnet";if(!n[s])throw new Error("No conf for networkId: "+s);return Promise.resolve(function(t,e){try{const o=[];let{address:s,publicKey:h}=(r=t).length>42?{address:f(r),publicKey:r}:{address:r},u=s;return Promise.resolve(function(t,i){try{return Promise.resolve(n[i].didReg.changed(t)).then(function(t){if(t)return t[0]})}catch(t){return Promise.reject(t)}}(s,e)).then(function(t){function r(){function r(){return{controller:u,history:o,publicKey:h}}const a=function(t,i,e){for(var n;;){var r=t();if(v(r)&&(r=r.v),!r)return o;if(r.then){n=0;break}var o=e();if(o&&o.then){if(!v(o)){n=1;break}o=o.s}}var s=new y,h=p.bind(null,s,2);return(0===n?r.then(a):1===n?o.then(u):(void 0).then(function(){(r=t())?r.then?r.then(a).then(void 0,h):a(r):p(s,1,o)})).then(void 0,h),s;function u(i){o=i;do{if(!(r=t())||v(r)&&!r.v)return void p(s,1,o);if(r.then)return void r.then(a).then(void 0,h);v(o=e())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,h)}function a(t){t?(o=e())&&o.then?o.then(u).then(void 0,h):u(o):p(s,1,o)}}(function(){return!!t},0,function(){const r=t;return Promise.resolve(n[e].eth.getLogs({address:n[e].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:t,toBlock:t})).then(function(e){const n=i(e);t=void 0;for(const i of n)o.unshift(i),i.previousChange.lt(r)&&(t=i.previousChange)})});return a&&a.then?a.then(r):r()}const a=function(){if(t)return Promise.resolve(n[e].didReg.identityOwner(s)).then(function(t){const i=""+t[0];i.toLowerCase()!==u.toLowerCase()&&(h=null),u=i})}();return a&&a.then?a.then(r):r()})}catch(t){return Promise.reject(t)}var r}(o,s)).then(function({controller:i,history:e,publicKey:n}){return k(t,i,n,e)})}catch(t){return Promise.reject(t)}}}},identifierMatcher:g}; | ||
//# sourceMappingURL=ethr-did-resolver.esm.js.map |
@@ -1,2 +0,2 @@ | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var i=t(require("ethjs-provider-http")),e=t(require("ethjs-query")),n=t(require("ethjs-abi")),r=require("buffer"),s=t(r),h=t(require("ethjs-contract")),o=require("elliptic"),u=require("js-sha3"),a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},l=function(t,i,e){return function(t){!function(t,i){function e(t,i){if(!t)throw new Error(i||"Assertion failed")}function n(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}function r(t,i,e){if(r.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(e=i,i=10),this._init(t||0,i||10,e||"be"))}var h;"object"==typeof t?t.exports=r:i.BN=r,r.BN=r,r.wordSize=26;try{h=s.Buffer}catch(t){}function o(t,i,e){for(var n=0,r=Math.min(t.length,e),s=i;s<r;s++){var h=t.charCodeAt(s)-48;n<<=4,n|=h>=49&&h<=54?h-49+10:h>=17&&h<=22?h-17+10:15&h}return n}function u(t,i,e,n){for(var r=0,s=Math.min(t.length,e),h=i;h<s;h++){var o=t.charCodeAt(h)-48;r*=n,r+=o>=49?o-49+10:o>=17?o-17+10:o}return r}r.isBN=function(t){return t instanceof r||null!==t&&"object"==typeof t&&t.constructor.wordSize===r.wordSize&&Array.isArray(t.words)},r.max=function(t,i){return t.cmp(i)>0?t:i},r.min=function(t,i){return t.cmp(i)<0?t:i},r.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),e(i===(0|i)&&i>=2&&i<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===i?this._parseHex(t,r):this._parseBase(t,i,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),i,n)},r.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},r.prototype._initArray=function(t,i,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var s,h,o=0;if("be"===n)for(r=t.length-1,s=0;r>=0;r-=3)this.words[s]|=(h=t[r]|t[r-1]<<8|t[r-2]<<16)<<o&67108863,this.words[s+1]=h>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);else if("le"===n)for(r=0,s=0;r<t.length;r+=3)this.words[s]|=(h=t[r]|t[r+1]<<8|t[r+2]<<16)<<o&67108863,this.words[s+1]=h>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);return this.strip()},r.prototype._parseHex=function(t,i){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var n,r,s=0;for(e=t.length-6,n=0;e>=i;e-=6)r=o(t,e,e+6),this.words[n]|=r<<s&67108863,this.words[n+1]|=r>>>26-s&4194303,(s+=24)>=26&&(s-=26,n++);e+6!==i&&(r=o(t,i,e+6),this.words[n]|=r<<s&67108863,this.words[n+1]|=r>>>26-s&4194303),this.strip()},r.prototype._parseBase=function(t,i,e){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=i)n++;n--,r=r/i|0;for(var s=t.length-e,h=s%n,o=Math.min(s,s-h)+e,a=0,l=e;l<o;l+=n)a=u(t,l,l+n,i),this.imuln(r),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==h){var m=1;for(a=u(t,l,t.length,i),l=0;l<h;l++)m*=i;this.imuln(m),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}},r.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},r.prototype.clone=function(){var t=new r(null);return this.copy(t),t},r.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},r.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},r.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},r.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,e){e.negative=i.negative^t.negative;var n=t.length+i.length|0;e.length=n,n=n-1|0;var r=0|t.words[0],s=0|i.words[0],h=r*s,o=h/67108864|0;e.words[0]=67108863&h;for(var u=1;u<n;u++){for(var a=o>>>26,l=67108863&o,m=Math.min(u,i.length-1),d=Math.max(0,u-t.length+1);d<=m;d++)a+=(h=(r=0|t.words[u-d|0])*(s=0|i.words[d])+l)/67108864|0,l=67108863&h;e.words[u]=0|l,o=0|a}return 0!==o?e.words[u]=0|o:e.length--,e.strip()}r.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,s=0,h=0;h<this.length;h++){var o=this.words[h],u=(16777215&(o<<r|s)).toString(16);n=0!=(s=o>>>24-r&16777215)||h!==this.length-1?a[6-u.length]+u+n:u+n,(r+=2)>=26&&(r-=26,h--)}for(0!==s&&(n=s.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:a[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},r.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},r.prototype.toJSON=function(){return this.toString(16)},r.prototype.toBuffer=function(t,i){return e(void 0!==h),this.toArrayLike(h,t,i)},r.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},r.prototype.toArrayLike=function(t,i,n){var r=this.byteLength(),s=n||Math.max(1,r);e(r<=s,"byte array longer than desired length"),e(s>0,"Requested array length <= 0"),this.strip();var h,o,u="le"===i,a=new t(s),l=this.clone();if(u){for(o=0;!l.isZero();o++)h=l.andln(255),l.iushrn(8),a[o]=h;for(;o<s;o++)a[o]=0}else{for(o=0;o<s-r;o++)a[o]=0;for(o=0;!l.isZero();o++)h=l.andln(255),l.iushrn(8),a[s-o-1]=h}return a},r.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var i=t,e=0;return i>=4096&&(e+=13,i>>>=13),i>=64&&(e+=7,i>>>=7),i>=8&&(e+=4,i>>>=4),i>=2&&(e+=2,i>>>=2),e+i},r.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,e=0;return 0==(8191&i)&&(e+=13,i>>>=13),0==(127&i)&&(e+=7,i>>>=7),0==(15&i)&&(e+=4,i>>>=4),0==(3&i)&&(e+=2,i>>>=2),0==(1&i)&&e++,e},r.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var e=this._zeroBits(this.words[i]);if(t+=e,26!==e)break}return t},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},r.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return 0!==this.negative},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},r.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},r.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},r.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},r.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var e=0;e<i.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=i.length,this.strip()},r.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},r.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},r.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},r.prototype.iuxor=function(t){var i,e;this.length>t.length?(i=this,e=t):(i=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=i.words[n]^e.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},r.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},r.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},r.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},r.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var r=0;r<i;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},r.prototype.notn=function(t){return this.clone().inotn(t)},r.prototype.setn=function(t,i){e("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},r.prototype.iadd=function(t){var i,e,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0,s=0;s<n.length;s++)this.words[s]=67108863&(i=(0|e.words[s])+(0|n.words[s])+r),r=i>>>26;for(;0!==r&&s<e.length;s++)this.words[s]=67108863&(i=(0|e.words[s])+r),r=i>>>26;if(this.length=e.length,0!==r)this.words[this.length]=r,this.length++;else if(e!==this)for(;s<e.length;s++)this.words[s]=e.words[s];return this},r.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},r.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(e=this,n=t):(e=t,n=this);for(var s=0,h=0;h<n.length;h++)s=(i=(0|e.words[h])-(0|n.words[h])+s)>>26,this.words[h]=67108863&i;for(;0!==s&&h<e.length;h++)s=(i=(0|e.words[h])+s)>>26,this.words[h]=67108863&i;if(0===s&&h<e.length&&e!==this)for(;h<e.length;h++)this.words[h]=e.words[h];return this.length=Math.max(this.length,h),e!==this&&(this.negative=1),this.strip()},r.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,i,e){var n,r,s,h=t.words,o=i.words,u=e.words,a=0,l=0|h[0],m=8191&l,d=l>>>13,f=0|h[1],p=8191&f,c=f>>>13,y=0|h[2],v=8191&y,g=y>>>13,M=0|h[3],w=8191&M,b=M>>>13,_=0|h[4],k=8191&_,x=_>>>13,S=0|h[5],A=8191&S,R=S>>>13,B=0|h[6],q=8191&B,D=B>>>13,K=0|h[7],T=8191&K,Z=K>>>13,N=0|h[8],I=8191&N,j=N>>>13,E=0|h[9],O=8191&E,C=E>>>13,L=0|o[0],P=8191&L,$=L>>>13,z=0|o[1],V=8191&z,F=z>>>13,U=0|o[2],H=8191&U,G=U>>>13,J=0|o[3],W=8191&J,Y=J>>>13,Q=0|o[4],X=8191&Q,tt=Q>>>13,it=0|o[5],et=8191&it,nt=it>>>13,rt=0|o[6],st=8191&rt,ht=rt>>>13,ot=0|o[7],ut=8191&ot,at=ot>>>13,lt=0|o[8],mt=8191<,dt=lt>>>13,ft=0|o[9],pt=8191&ft,ct=ft>>>13;e.negative=t.negative^i.negative,e.length=19;var yt=(a+(n=Math.imul(m,P))|0)+((8191&(r=(r=Math.imul(m,$))+Math.imul(d,P)|0))<<13)|0;a=((s=Math.imul(d,$))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,P),r=(r=Math.imul(p,$))+Math.imul(c,P)|0,s=Math.imul(c,$);var vt=(a+(n=n+Math.imul(m,V)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,V)|0))<<13)|0;a=((s=s+Math.imul(d,F)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,P),r=(r=Math.imul(v,$))+Math.imul(g,P)|0,s=Math.imul(g,$),n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,V)|0,s=s+Math.imul(c,F)|0;var gt=(a+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;a=((s=s+Math.imul(d,G)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(w,P),r=(r=Math.imul(w,$))+Math.imul(b,P)|0,s=Math.imul(b,$),n=n+Math.imul(v,V)|0,r=(r=r+Math.imul(v,F)|0)+Math.imul(g,V)|0,s=s+Math.imul(g,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,s=s+Math.imul(c,G)|0;var Mt=(a+(n=n+Math.imul(m,W)|0)|0)+((8191&(r=(r=r+Math.imul(m,Y)|0)+Math.imul(d,W)|0))<<13)|0;a=((s=s+Math.imul(d,Y)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(k,P),r=(r=Math.imul(k,$))+Math.imul(x,P)|0,s=Math.imul(x,$),n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,V)|0,s=s+Math.imul(b,F)|0,n=n+Math.imul(v,H)|0,r=(r=r+Math.imul(v,G)|0)+Math.imul(g,H)|0,s=s+Math.imul(g,G)|0,n=n+Math.imul(p,W)|0,r=(r=r+Math.imul(p,Y)|0)+Math.imul(c,W)|0,s=s+Math.imul(c,Y)|0;var wt=(a+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;a=((s=s+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,P),r=(r=Math.imul(A,$))+Math.imul(R,P)|0,s=Math.imul(R,$),n=n+Math.imul(k,V)|0,r=(r=r+Math.imul(k,F)|0)+Math.imul(x,V)|0,s=s+Math.imul(x,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,G)|0,n=n+Math.imul(v,W)|0,r=(r=r+Math.imul(v,Y)|0)+Math.imul(g,W)|0,s=s+Math.imul(g,Y)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,s=s+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(m,et)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,et)|0))<<13)|0;a=((s=s+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(q,P),r=(r=Math.imul(q,$))+Math.imul(D,P)|0,s=Math.imul(D,$),n=n+Math.imul(A,V)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,V)|0,s=s+Math.imul(R,F)|0,n=n+Math.imul(k,H)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(x,H)|0,s=s+Math.imul(x,G)|0,n=n+Math.imul(w,W)|0,r=(r=r+Math.imul(w,Y)|0)+Math.imul(b,W)|0,s=s+Math.imul(b,Y)|0,n=n+Math.imul(v,X)|0,r=(r=r+Math.imul(v,tt)|0)+Math.imul(g,X)|0,s=s+Math.imul(g,tt)|0,n=n+Math.imul(p,et)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,et)|0,s=s+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(m,st)|0)|0)+((8191&(r=(r=r+Math.imul(m,ht)|0)+Math.imul(d,st)|0))<<13)|0;a=((s=s+Math.imul(d,ht)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(T,P),r=(r=Math.imul(T,$))+Math.imul(Z,P)|0,s=Math.imul(Z,$),n=n+Math.imul(q,V)|0,r=(r=r+Math.imul(q,F)|0)+Math.imul(D,V)|0,s=s+Math.imul(D,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,s=s+Math.imul(R,G)|0,n=n+Math.imul(k,W)|0,r=(r=r+Math.imul(k,Y)|0)+Math.imul(x,W)|0,s=s+Math.imul(x,Y)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,s=s+Math.imul(b,tt)|0,n=n+Math.imul(v,et)|0,r=(r=r+Math.imul(v,nt)|0)+Math.imul(g,et)|0,s=s+Math.imul(g,nt)|0,n=n+Math.imul(p,st)|0,r=(r=r+Math.imul(p,ht)|0)+Math.imul(c,st)|0,s=s+Math.imul(c,ht)|0;var kt=(a+(n=n+Math.imul(m,ut)|0)|0)+((8191&(r=(r=r+Math.imul(m,at)|0)+Math.imul(d,ut)|0))<<13)|0;a=((s=s+Math.imul(d,at)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(I,P),r=(r=Math.imul(I,$))+Math.imul(j,P)|0,s=Math.imul(j,$),n=n+Math.imul(T,V)|0,r=(r=r+Math.imul(T,F)|0)+Math.imul(Z,V)|0,s=s+Math.imul(Z,F)|0,n=n+Math.imul(q,H)|0,r=(r=r+Math.imul(q,G)|0)+Math.imul(D,H)|0,s=s+Math.imul(D,G)|0,n=n+Math.imul(A,W)|0,r=(r=r+Math.imul(A,Y)|0)+Math.imul(R,W)|0,s=s+Math.imul(R,Y)|0,n=n+Math.imul(k,X)|0,r=(r=r+Math.imul(k,tt)|0)+Math.imul(x,X)|0,s=s+Math.imul(x,tt)|0,n=n+Math.imul(w,et)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,et)|0,s=s+Math.imul(b,nt)|0,n=n+Math.imul(v,st)|0,r=(r=r+Math.imul(v,ht)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ht)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,at)|0)+Math.imul(c,ut)|0,s=s+Math.imul(c,at)|0;var xt=(a+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;a=((s=s+Math.imul(d,dt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(O,P),r=(r=Math.imul(O,$))+Math.imul(C,P)|0,s=Math.imul(C,$),n=n+Math.imul(I,V)|0,r=(r=r+Math.imul(I,F)|0)+Math.imul(j,V)|0,s=s+Math.imul(j,F)|0,n=n+Math.imul(T,H)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(Z,H)|0,s=s+Math.imul(Z,G)|0,n=n+Math.imul(q,W)|0,r=(r=r+Math.imul(q,Y)|0)+Math.imul(D,W)|0,s=s+Math.imul(D,Y)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,s=s+Math.imul(R,tt)|0,n=n+Math.imul(k,et)|0,r=(r=r+Math.imul(k,nt)|0)+Math.imul(x,et)|0,s=s+Math.imul(x,nt)|0,n=n+Math.imul(w,st)|0,r=(r=r+Math.imul(w,ht)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ht)|0,n=n+Math.imul(v,ut)|0,r=(r=r+Math.imul(v,at)|0)+Math.imul(g,ut)|0,s=s+Math.imul(g,at)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,s=s+Math.imul(c,dt)|0;var St=(a+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;a=((s=s+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(O,V),r=(r=Math.imul(O,F))+Math.imul(C,V)|0,s=Math.imul(C,F),n=n+Math.imul(I,H)|0,r=(r=r+Math.imul(I,G)|0)+Math.imul(j,H)|0,s=s+Math.imul(j,G)|0,n=n+Math.imul(T,W)|0,r=(r=r+Math.imul(T,Y)|0)+Math.imul(Z,W)|0,s=s+Math.imul(Z,Y)|0,n=n+Math.imul(q,X)|0,r=(r=r+Math.imul(q,tt)|0)+Math.imul(D,X)|0,s=s+Math.imul(D,tt)|0,n=n+Math.imul(A,et)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,et)|0,s=s+Math.imul(R,nt)|0,n=n+Math.imul(k,st)|0,r=(r=r+Math.imul(k,ht)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,ht)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,at)|0)+Math.imul(b,ut)|0,s=s+Math.imul(b,at)|0,n=n+Math.imul(v,mt)|0,r=(r=r+Math.imul(v,dt)|0)+Math.imul(g,mt)|0,s=s+Math.imul(g,dt)|0;var At=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((s=s+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(O,H),r=(r=Math.imul(O,G))+Math.imul(C,H)|0,s=Math.imul(C,G),n=n+Math.imul(I,W)|0,r=(r=r+Math.imul(I,Y)|0)+Math.imul(j,W)|0,s=s+Math.imul(j,Y)|0,n=n+Math.imul(T,X)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(Z,X)|0,s=s+Math.imul(Z,tt)|0,n=n+Math.imul(q,et)|0,r=(r=r+Math.imul(q,nt)|0)+Math.imul(D,et)|0,s=s+Math.imul(D,nt)|0,n=n+Math.imul(A,st)|0,r=(r=r+Math.imul(A,ht)|0)+Math.imul(R,st)|0,s=s+Math.imul(R,ht)|0,n=n+Math.imul(k,ut)|0,r=(r=r+Math.imul(k,at)|0)+Math.imul(x,ut)|0,s=s+Math.imul(x,at)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,s=s+Math.imul(b,dt)|0;var Rt=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(r=(r=r+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((s=s+Math.imul(g,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(O,W),r=(r=Math.imul(O,Y))+Math.imul(C,W)|0,s=Math.imul(C,Y),n=n+Math.imul(I,X)|0,r=(r=r+Math.imul(I,tt)|0)+Math.imul(j,X)|0,s=s+Math.imul(j,tt)|0,n=n+Math.imul(T,et)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(Z,et)|0,s=s+Math.imul(Z,nt)|0,n=n+Math.imul(q,st)|0,r=(r=r+Math.imul(q,ht)|0)+Math.imul(D,st)|0,s=s+Math.imul(D,ht)|0,n=n+Math.imul(A,ut)|0,r=(r=r+Math.imul(A,at)|0)+Math.imul(R,ut)|0,s=s+Math.imul(R,at)|0,n=n+Math.imul(k,mt)|0,r=(r=r+Math.imul(k,dt)|0)+Math.imul(x,mt)|0,s=s+Math.imul(x,dt)|0;var Bt=(a+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((s=s+Math.imul(b,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(O,X),r=(r=Math.imul(O,tt))+Math.imul(C,X)|0,s=Math.imul(C,tt),n=n+Math.imul(I,et)|0,r=(r=r+Math.imul(I,nt)|0)+Math.imul(j,et)|0,s=s+Math.imul(j,nt)|0,n=n+Math.imul(T,st)|0,r=(r=r+Math.imul(T,ht)|0)+Math.imul(Z,st)|0,s=s+Math.imul(Z,ht)|0,n=n+Math.imul(q,ut)|0,r=(r=r+Math.imul(q,at)|0)+Math.imul(D,ut)|0,s=s+Math.imul(D,at)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,s=s+Math.imul(R,dt)|0;var qt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(r=(r=r+Math.imul(k,ct)|0)+Math.imul(x,pt)|0))<<13)|0;a=((s=s+Math.imul(x,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(O,et),r=(r=Math.imul(O,nt))+Math.imul(C,et)|0,s=Math.imul(C,nt),n=n+Math.imul(I,st)|0,r=(r=r+Math.imul(I,ht)|0)+Math.imul(j,st)|0,s=s+Math.imul(j,ht)|0,n=n+Math.imul(T,ut)|0,r=(r=r+Math.imul(T,at)|0)+Math.imul(Z,ut)|0,s=s+Math.imul(Z,at)|0,n=n+Math.imul(q,mt)|0,r=(r=r+Math.imul(q,dt)|0)+Math.imul(D,mt)|0,s=s+Math.imul(D,dt)|0;var Dt=(a+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;a=((s=s+Math.imul(R,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(O,st),r=(r=Math.imul(O,ht))+Math.imul(C,st)|0,s=Math.imul(C,ht),n=n+Math.imul(I,ut)|0,r=(r=r+Math.imul(I,at)|0)+Math.imul(j,ut)|0,s=s+Math.imul(j,at)|0,n=n+Math.imul(T,mt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(Z,mt)|0,s=s+Math.imul(Z,dt)|0;var Kt=(a+(n=n+Math.imul(q,pt)|0)|0)+((8191&(r=(r=r+Math.imul(q,ct)|0)+Math.imul(D,pt)|0))<<13)|0;a=((s=s+Math.imul(D,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(O,ut),r=(r=Math.imul(O,at))+Math.imul(C,ut)|0,s=Math.imul(C,at),n=n+Math.imul(I,mt)|0,r=(r=r+Math.imul(I,dt)|0)+Math.imul(j,mt)|0,s=s+Math.imul(j,dt)|0;var Tt=(a+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((s=s+Math.imul(Z,ct)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(O,mt),r=(r=Math.imul(O,dt))+Math.imul(C,mt)|0,s=Math.imul(C,dt);var Zt=(a+(n=n+Math.imul(I,pt)|0)|0)+((8191&(r=(r=r+Math.imul(I,ct)|0)+Math.imul(j,pt)|0))<<13)|0;a=((s=s+Math.imul(j,ct)|0)+(r>>>13)|0)+(Zt>>>26)|0,Zt&=67108863;var Nt=(a+(n=Math.imul(O,pt))|0)+((8191&(r=(r=Math.imul(O,ct))+Math.imul(C,pt)|0))<<13)|0;return a=((s=Math.imul(C,ct))+(r>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,u[0]=yt,u[1]=vt,u[2]=gt,u[3]=Mt,u[4]=wt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=xt,u[9]=St,u[10]=At,u[11]=Rt,u[12]=Bt,u[13]=qt,u[14]=Dt,u[15]=Kt,u[16]=Tt,u[17]=Zt,u[18]=Nt,0!==a&&(u[19]=a,e.length++),e};function p(t,i,e){return(new c).mulp(t,i,e)}function c(t,i){this.x=t,this.y=i}Math.imul||(f=d),r.prototype.mulTo=function(t,i){var e=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,i):e<63?d(this,t,i):e<1024?function(t,i,e){e.negative=i.negative^t.negative,e.length=t.length+i.length;for(var n=0,r=0,s=0;s<e.length-1;s++){var h=r;r=0;for(var o=67108863&n,u=Math.min(s,i.length-1),a=Math.max(0,s-t.length+1);a<=u;a++){var l=(0|t.words[s-a])*(0|i.words[a]),m=67108863&l;o=67108863&(m=m+o|0),r+=(h=(h=h+(l/67108864|0)|0)+(m>>>26)|0)>>>26,h&=67108863}e.words[s]=o,n=h,h=r}return 0!==n?e.words[s]=n:e.length--,e.strip()}(this,t,i):p(this,t,i)},c.prototype.makeRBT=function(t){for(var i=new Array(t),e=r.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,e,t);return i},c.prototype.revBin=function(t,i,e){if(0===t||t===e-1)return t;for(var n=0,r=0;r<i;r++)n|=(1&t)<<i-r-1,t>>=1;return n},c.prototype.permute=function(t,i,e,n,r,s){for(var h=0;h<s;h++)n[h]=i[t[h]],r[h]=e[t[h]]},c.prototype.transform=function(t,i,e,n,r,s){this.permute(s,t,i,e,n,r);for(var h=1;h<r;h<<=1)for(var o=h<<1,u=Math.cos(2*Math.PI/o),a=Math.sin(2*Math.PI/o),l=0;l<r;l+=o)for(var m=u,d=a,f=0;f<h;f++){var p=e[l+f],c=n[l+f],y=e[l+f+h],v=n[l+f+h],g=m*y-d*v;v=m*v+d*y,e[l+f]=p+(y=g),n[l+f]=c+v,e[l+f+h]=p-y,n[l+f+h]=c-v,f!==o&&(g=u*m-a*d,d=u*d+a*m,m=g)}},c.prototype.guessLen13b=function(t,i){var e=1|Math.max(i,t),n=1&e,r=0;for(e=e/2|0;e;e>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,i,e){if(!(e<=1))for(var n=0;n<e/2;n++){var r=t[n];t[n]=t[e-n-1],t[e-n-1]=r,r=i[n],i[n]=-i[e-n-1],i[e-n-1]=-r}},c.prototype.normalize13b=function(t,i){for(var e=0,n=0;n<i/2;n++){var r=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+e;t[n]=67108863&r,e=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,i,n,r){for(var s=0,h=0;h<i;h++)n[2*h]=8191&(s+=0|t[h]),n[2*h+1]=8191&(s>>>=13),s>>>=13;for(h=2*i;h<r;++h)n[h]=0;e(0===s),e(0==(-8192&s))},c.prototype.stub=function(t){for(var i=new Array(t),e=0;e<t;e++)i[e]=0;return i},c.prototype.mulp=function(t,i,e){var n=2*this.guessLen13b(t.length,i.length),r=this.makeRBT(n),s=this.stub(n),h=new Array(n),o=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),m=new Array(n),d=e.words;d.length=n,this.convert13b(t.words,t.length,h,n),this.convert13b(i.words,i.length,a,n),this.transform(h,s,o,u,n,r),this.transform(a,s,l,m,n,r);for(var f=0;f<n;f++){var p=o[f]*l[f]-u[f]*m[f];u[f]=o[f]*m[f]+u[f]*l[f],o[f]=p}return this.conjugate(o,u,n),this.transform(o,u,d,s,n,r),this.conjugate(d,s,n),this.normalize13b(d,n),e.negative=t.negative^i.negative,e.length=t.length+i.length,e.strip()},r.prototype.mul=function(t){var i=new r(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},r.prototype.mulf=function(t){var i=new r(null);return i.words=new Array(this.length+t.length),p(this,t,i)},r.prototype.imul=function(t){return this.clone().mulTo(t,this)},r.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var i=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,s=(67108863&r)+(67108863&i);i>>=26,i+=r/67108864|0,i+=s>>>26,this.words[n]=67108863&s}return 0!==i&&(this.words[n]=i,this.length++),this},r.prototype.muln=function(t){return this.clone().imuln(t)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),e=0;e<i.length;e++){var n=e%26;i[e]=(t.words[e/26|0]&1<<n)>>>n}return i}(t);if(0===i.length)return new r(1);for(var e=this,n=0;n<i.length&&0===i[n];n++,e=e.sqr());if(++n<i.length)for(var s=e.sqr();n<i.length;n++,s=s.sqr())0!==i[n]&&(e=e.mul(s));return e},r.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var i,n=t%26,r=(t-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var h=0;for(i=0;i<this.length;i++){var o=this.words[i]&s;this.words[i]=(0|this.words[i])-o<<n|h,h=o>>>26-n}h&&(this.words[i]=h,this.length++)}if(0!==r){for(i=this.length-1;i>=0;i--)this.words[i+r]=this.words[i];for(i=0;i<r;i++)this.words[i]=0;this.length+=r}return this.strip()},r.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},r.prototype.iushrn=function(t,i,n){var r;e("number"==typeof t&&t>=0),r=i?(i-i%26)/26:0;var s=t%26,h=Math.min((t-s)/26,this.length),o=67108863^67108863>>>s<<s,u=n;if(r-=h,r=Math.max(0,r),u){for(var a=0;a<h;a++)u.words[a]=this.words[a];u.length=h}if(0===h);else if(this.length>h)for(this.length-=h,a=0;a<this.length;a++)this.words[a]=this.words[a+h];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=r);a--){var m=0|this.words[a];this.words[a]=l<<26-s|m>>>s,l=m&o}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},r.prototype.ishrn=function(t,i,n){return e(0===this.negative),this.iushrn(t,i,n)},r.prototype.shln=function(t){return this.clone().ishln(t)},r.prototype.ushln=function(t){return this.clone().iushln(t)},r.prototype.shrn=function(t){return this.clone().ishrn(t)},r.prototype.ushrn=function(t){return this.clone().iushrn(t)},r.prototype.testn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return!(this.length<=n||!(this.words[n]&1<<i))},r.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==i&&n++,this.length=Math.min(n,this.length),0!==i&&(this.words[this.length-1]&=67108863^67108863>>>i<<i),this.strip())},r.prototype.maskn=function(t){return this.clone().imaskn(t)},r.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},r.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},r.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},r.prototype.addn=function(t){return this.clone().iaddn(t)},r.prototype.subn=function(t){return this.clone().isubn(t)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(t,i,n){var r,s;this._expand(t.length+n);var h=0;for(r=0;r<t.length;r++){s=(0|this.words[r+n])+h;var o=(0|t.words[r])*i;h=((s-=67108863&o)>>26)-(o/67108864|0),this.words[r+n]=67108863&s}for(;r<this.length-n;r++)h=(s=(0|this.words[r+n])+h)>>26,this.words[r+n]=67108863&s;if(0===h)return this.strip();for(e(-1===h),h=0,r=0;r<this.length;r++)h=(s=-(0|this.words[r])+h)>>26,this.words[r]=67108863&s;return this.negative=1,this.strip()},r.prototype._wordDiv=function(t,i){var e,n=this.clone(),s=t,h=0|s.words[s.length-1];0!=(e=26-this._countBits(h))&&(s=s.ushln(e),n.iushln(e),h=0|s.words[s.length-1]);var o,u=n.length-s.length;if("mod"!==i){(o=new r(null)).length=u+1,o.words=new Array(o.length);for(var a=0;a<o.length;a++)o.words[a]=0}var l=n.clone()._ishlnsubmul(s,1,u);0===l.negative&&(n=l,o&&(o.words[u]=1));for(var m=u-1;m>=0;m--){var d=67108864*(0|n.words[s.length+m])+(0|n.words[s.length+m-1]);for(d=Math.min(d/h|0,67108863),n._ishlnsubmul(s,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(s,1,m),n.isZero()||(n.negative^=1);o&&(o.words[m]=d)}return o&&o.strip(),n.strip(),"div"!==i&&0!==e&&n.iushrn(e),{div:o||null,mod:n}},r.prototype.divmod=function(t,i,n){return e(!t.isZero()),this.isZero()?{div:new r(0),mod:new r(0)}:0!==this.negative&&0===t.negative?(o=this.neg().divmod(t,i),"mod"!==i&&(s=o.div.neg()),"div"!==i&&(h=o.mod.neg(),n&&0!==h.negative&&h.iadd(t)),{div:s,mod:h}):0===this.negative&&0!==t.negative?(o=this.divmod(t.neg(),i),"mod"!==i&&(s=o.div.neg()),{div:s,mod:o.mod}):0!=(this.negative&t.negative)?(o=this.neg().divmod(t.neg(),i),"div"!==i&&(h=o.mod.neg(),n&&0!==h.negative&&h.isub(t)),{div:o.div,mod:h}):t.length>this.length||this.cmp(t)<0?{div:new r(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new r(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new r(this.modn(t.words[0]))}:this._wordDiv(t,i);var s,h,o},r.prototype.div=function(t){return this.divmod(t,"div",!1).div},r.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},r.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},r.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var e=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),r=t.andln(1),s=e.cmp(n);return s<0||1===r&&0===s?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},r.prototype.modn=function(t){e(t<=67108863);for(var i=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(i*n+(0|this.words[r]))%t;return n},r.prototype.idivn=function(t){e(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*i;this.words[n]=r/t|0,i=r%t}return this.strip()},r.prototype.divn=function(t){return this.clone().idivn(t)},r.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var s=new r(1),h=new r(0),o=new r(0),u=new r(1),a=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),m=i.clone();!i.isZero();){for(var d=0,f=1;0==(i.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(i.iushrn(d);d-- >0;)(s.isOdd()||h.isOdd())&&(s.iadd(l),h.isub(m)),s.iushrn(1),h.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(o.isOdd()||u.isOdd())&&(o.iadd(l),u.isub(m)),o.iushrn(1),u.iushrn(1);i.cmp(n)>=0?(i.isub(n),s.isub(o),h.isub(u)):(n.isub(i),o.isub(s),u.isub(h))}return{a:o,b:u,gcd:n.iushln(a)}},r.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var s,h=new r(1),o=new r(0),u=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(i.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(i.iushrn(a);a-- >0;)h.isOdd()&&h.iadd(u),h.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)o.isOdd()&&o.iadd(u),o.iushrn(1);i.cmp(n)>=0?(i.isub(n),h.isub(o)):(n.isub(i),o.isub(h))}return(s=0===i.cmpn(1)?h:o).cmpn(0)<0&&s.iadd(t),s},r.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),e=t.clone();i.negative=0,e.negative=0;for(var n=0;i.isEven()&&e.isEven();n++)i.iushrn(1),e.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;e.isEven();)e.iushrn(1);var r=i.cmp(e);if(r<0){var s=i;i=e,e=s}else if(0===r||0===e.cmpn(1))break;i.isub(e)}return e.iushln(n)},r.prototype.invm=function(t){return this.egcd(t).a.umod(t)},r.prototype.isEven=function(){return 0==(1&this.words[0])},r.prototype.isOdd=function(){return 1==(1&this.words[0])},r.prototype.andln=function(t){return this.words[0]&t},r.prototype.bincn=function(t){e("number"==typeof t);var i=t%26,n=(t-i)/26,r=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var s=r,h=n;0!==s&&h<this.length;h++){var o=0|this.words[h];s=(o+=s)>>>26,this.words[h]=o&=67108863}return 0!==s&&(this.words[h]=s,this.length++),this},r.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},r.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var r=0|this.words[0];i=r===t?0:r<t?-1:1}return 0!==this.negative?0|-i:i},r.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},r.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],r=0|t.words[e];if(n!==r){n<r?i=-1:n>r&&(i=1);break}}return i},r.prototype.gtn=function(t){return 1===this.cmpn(t)},r.prototype.gt=function(t){return 1===this.cmp(t)},r.prototype.gten=function(t){return this.cmpn(t)>=0},r.prototype.gte=function(t){return this.cmp(t)>=0},r.prototype.ltn=function(t){return-1===this.cmpn(t)},r.prototype.lt=function(t){return-1===this.cmp(t)},r.prototype.lten=function(t){return this.cmpn(t)<=0},r.prototype.lte=function(t){return this.cmp(t)<=0},r.prototype.eqn=function(t){return 0===this.cmpn(t)},r.prototype.eq=function(t){return 0===this.cmp(t)},r.red=function(t){return new _(t)},r.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},r.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(t){return this.red=t,this},r.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},r.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},r.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},r.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},r.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},r.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},r.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},r.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},r.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,i){this.name=t,this.p=new r(i,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=r._prime(t);this.m=i.p,this.prime=i}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new r(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new r(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var i,e=t;do{this.split(e,this.tmp),i=(e=(e=this.imulK(e)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):void 0!==e.strip?e.strip():e._strip(),e},v.prototype.split=function(t,i){t.iushrn(this.n,0,i)},v.prototype.imulK=function(t){return t.imul(this.k)},n(g,v),g.prototype.split=function(t,i){for(var e=Math.min(t.length,9),n=0;n<e;n++)i.words[n]=t.words[n];if(i.length=e,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(i.words[i.length++]=4194303&r,n=10;n<t.length;n++){var s=0|t.words[n];t.words[n-10]=(4194303&s)<<4|r>>>22,r=s}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,e=0;e<t.length;e++){var n=0|t.words[e];t.words[e]=67108863&(i+=977*n),i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(M,v),n(w,v),n(b,v),b.prototype.imulK=function(t){for(var i=0,e=0;e<t.length;e++){var n=19*(0|t.words[e])+i,r=67108863&n;n>>>=26,t.words[e]=r,i=n}return 0!==i&&(t.words[t.length++]=i),t},r._prime=function(t){if(y[t])return y[t];var i;if("k256"===t)i=new g;else if("p224"===t)i=new M;else if("p192"===t)i=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return y[t]=i,i},_.prototype._verify1=function(t){e(0===t.negative,"red works only with positives"),e(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){e(0==(t.negative|i.negative),"red works only with positives"),e(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var e=t.add(i);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var e=t.iadd(i);return e.cmp(this.m)>=0&&e.isub(this.m),e},_.prototype.sub=function(t,i){this._verify2(t,i);var e=t.sub(i);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var e=t.isub(i);return e.cmpn(0)<0&&e.iadd(this.m),e},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(e(i%2==1),3===i){var n=this.m.add(new r(1)).iushrn(2);return this.pow(t,n)}for(var s=this.m.subn(1),h=0;!s.isZero()&&0===s.andln(1);)h++,s.iushrn(1);e(!s.isZero());var o=new r(1).toRed(this),u=o.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new r(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var m=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),p=h;0!==f.cmp(o);){for(var c=f,y=0;0!==c.cmp(o);y++)c=c.redSqr();e(y<p);var v=this.pow(m,new r(1).iushln(p-y-1));d=d.redMul(v),m=v.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new r(1).toRed(this);if(0===i.cmpn(1))return t.clone();var e=new Array(16);e[0]=new r(1).toRed(this),e[1]=t;for(var n=2;n<e.length;n++)e[n]=this.mul(e[n-1],t);var s=e[0],h=0,o=0,u=i.bitLength()%26;for(0===u&&(u=26),n=i.length-1;n>=0;n--){for(var a=i.words[n],l=u-1;l>=0;l--){var m=a>>l&1;s!==e[0]&&(s=this.sqr(s)),0!==m||0!==h?(h<<=1,h|=m,(4==++o||0===n&&0===l)&&(s=this.mul(s,e[h]),o=0,h=0)):o=0}u=26}return s},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},r.mont=function(t){return new k(t)},n(k,_),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},k.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),s=r;return r.cmp(this.m)>=0?s=r.isub(this.m):r.cmpn(0)<0&&(s=r.iadd(this.m)),s._forceRed(this)},k.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new r(0)._forceRed(this);var e=t.mul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=e.isub(n).iushrn(this.shift),h=s;return s.cmp(this.m)>=0?h=s.isub(this.m):s.cmpn(0)<0&&(h=s.iadd(this.m)),h._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,a)}(e={path:void 0,exports:{},require:function(t,i){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),e.exports}(),m=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function d(t){return r.Buffer.from(u.keccak_256.arrayBuffer(t))}const f=new o.ec("secp256k1");function p(t){const i=(""+t).startsWith("0x")?t.slice(2):t,e=f.keyFromPublic(i,"hex").getPublic().encode("hex");return function(t){var i=t;const e=d(i=i.substring(2).toLowerCase());i=i.split("");for(var n=0;n<40;n+=2)e[n/2]>>4>=8&&(i[n]=i[n].toUpperCase()),(15&e[n/2])>=8&&(i[n+1]=i[n+1].toUpperCase());return"0x"+i.join("")}("0x"+d(r.Buffer.from(e.slice(2),"hex")).slice(-20).toString("hex"))}function c(t,i,e){if(!t.s){if(e instanceof v){if(!e.s)return void(e.o=c.bind(null,t,i));1&i&&(i=e.s),e=e.v}if(e&&e.then)return void e.then(c.bind(null,t,i),c.bind(null,t,2));t.s=i,t.v=e;const n=t.o;n&&n(t)}}const y="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",v=function(){function t(){}return t.prototype.then=function(i,e){const n=new t,r=this.s;if(r){const t=1&r?i:e;if(t){try{c(n,1,t(this.v))}catch(t){c(n,2,t)}return n}return this}return this.o=function(t){try{const r=t.v;1&t.s?c(n,1,i?i(r):r):e?c(n,1,e(r)):c(n,2,r)}catch(t){c(n,2,t)}},n},t}();function g(t){return t instanceof v&&1&t.s}const M=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function w(t){return r.Buffer.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function b(t){const i="0x"+r.Buffer.from(t).slice(0,32).toString("hex");return i+"0".repeat(66-i.length)}const _={Secp256k1SignatureAuthentication2018:b("sigAuth"),Secp256k1VerificationKey2018:b("veriKey")},k={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function x(t,i,e,n){const s=new l(Math.floor((new Date).getTime()/1e3)),h=[{id:t+"#owner",type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:i}],o=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#owner"}];e&&(h.push({id:t+"#ownerKey",type:"Secp256k1VerificationKey2018",owner:t,publicKeyHex:e}),o.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#ownerKey"}));let u=0;const a={},m={},d={};for(const i of n){const e=i.validTo,n=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(e&&e.gte(s)){if("DIDDelegateChanged"===i._eventName)switch(u++,w(i.delegateType)){case"sigAuth":a[n]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${u}`};case"veriKey":m[n]={id:`${t}#delegate-${u}`,type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:i.delegate}}else if("DIDAttributeChanged"===i._eventName){const e=w(i.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(e){const s=e[2],h=k[e[4]]||e[4],o=e[6];switch(e[1]){case"pub":{u++;const e={id:`${t}#delegate-${u}`,type:`${s}${h}`,owner:t};switch(o){case null:case void 0:case"hex":e.publicKeyHex=i.value.slice(2);break;case"base64":e.publicKeyBase64=r.Buffer.from(i.value.slice(2),"hex").toString("base64");break;case"base58":e.publicKeyBase58=r.Buffer.from(i.value.slice(2),"hex").toString("base58");break;case"pem":e.publicKeyPem=r.Buffer.from(i.value.slice(2),"hex").toString();break;default:e.value=i.value}m[n]=e;break}case"svc":d[n]={type:s,serviceEndpoint:r.Buffer.from(i.value.slice(2),"hex").toString()}}}}}else u>0&&("DIDDelegateChanged"===i._eventName||"DIDAttributeChanged"===i._eventName&&w(i.name).match(/^did\/pub\//))&&e.lt(s)&&u--,delete a[n],delete m[n],delete d[n]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:h.concat(Object.values(m)),authentication:o.concat(Object.values(a))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function S(t={}){const n=function(t={}){return t.provider?t.provider:t.web3?t.web3.currentProvider:t.rpcUrl?new i(t.rpcUrl):null}(t);if(null===n)return null;const r=new e(n),s=t.registry||y;return{eth:r,registryAddress:s,didReg:new h(r)(m).at(s)}}function A(t=[]){const i={};for(let e=0;e<t.length;e++){const n=t[e];i[n.name]=S(n),null===i[n.name]&&console.warn("invalid configuration for "+n.name)}return i}module.exports={REGISTRY:y,bytes32toString:w,stringToBytes32:b,delegateTypes:_,attrTypes:k,wrapDidDocument:x,getResolver:function(t={}){const i=n.logDecoder(m,!1),e={mainnet:S(t),...A(t.networks)};return function(t={},i={}){if((i.provider||i.web3||i.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(i&&i.networks)for(const e of i.networks)if(!t[e.name])throw new Error(`Ethereum provider configuration for ${e.name} was attempted but no valid configuration was provided`);let e=0;for(const i of Object.keys(t))null!==t[i]&&e++;if(0===e)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(e,t),{ethr:function(t,n){try{const r=n.id.match(M);if(!r)throw new Error("Not a valid ethr DID: "+t);const s=r[2],h=r[1]?r[1].slice(0,-1):"mainnet";if(!e[h])throw new Error("No conf for networkId: "+h);return Promise.resolve(function(t,n){try{const s=[];let{address:h,publicKey:o}=(r=t).length>42?{address:p(r),publicKey:r}:{address:r},u=h;return Promise.resolve(function(t,i){try{return Promise.resolve(e[i].didReg.changed(t)).then(function(t){if(t)return t[0]})}catch(t){return Promise.reject(t)}}(h,n)).then(function(t){function r(){function r(){return{owner:u,history:s,publicKey:o}}const a=function(t,i,e){for(var n;;){var r=t();if(g(r)&&(r=r.v),!r)return s;if(r.then){n=0;break}var s=e();if(s&&s.then){if(!g(s)){n=1;break}s=s.s}}var h=new v,o=c.bind(null,h,2);return(0===n?r.then(a):1===n?s.then(u):(void 0).then(function(){(r=t())?r.then?r.then(a).then(void 0,o):a(r):c(h,1,s)})).then(void 0,o),h;function u(i){s=i;do{if(!(r=t())||g(r)&&!r.v)return void c(h,1,s);if(r.then)return void r.then(a).then(void 0,o);g(s=e())&&(s=s.v)}while(!s||!s.then);s.then(u).then(void 0,o)}function a(t){t?(s=e())&&s.then?s.then(u).then(void 0,o):u(s):c(h,1,s)}}(function(){return!!t},0,function(){const r=t;return Promise.resolve(e[n].eth.getLogs({address:e[n].registryAddress,topics:[null,"0x000000000000000000000000"+h.slice(2)],fromBlock:t,toBlock:t})).then(function(e){const n=i(e);t=void 0;for(const i of n)s.unshift(i),i.previousChange.lt(r)&&(t=i.previousChange)})});return a&&a.then?a.then(r):r()}const a=function(){if(t)return Promise.resolve(e[n].didReg.identityOwner(h)).then(function(t){const i=""+t[0];i.toLowerCase()!==u.toLowerCase()&&(o=null),u=i})}();return a&&a.then?a.then(r):r()})}catch(t){return Promise.reject(t)}var r}(s,h)).then(function({owner:i,history:e,publicKey:n}){return x(t,i,n,e)})}catch(t){return Promise.reject(t)}}}},identifierMatcher:M}; | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var i=t(require("ethjs-provider-http")),e=t(require("ethjs-query")),n=t(require("ethjs-abi")),r=require("buffer"),o=t(r),s=t(require("ethjs-contract")),h=require("elliptic"),u=require("js-sha3"),a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},l=function(t,i,e){return function(t){!function(t,i){function e(t,i){if(!t)throw new Error(i||"Assertion failed")}function n(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}function r(t,i,e){if(r.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(e=i,i=10),this._init(t||0,i||10,e||"be"))}var s;"object"==typeof t?t.exports=r:i.BN=r,r.BN=r,r.wordSize=26;try{s=o.Buffer}catch(t){}function h(t,i,e){for(var n=0,r=Math.min(t.length,e),o=i;o<r;o++){var s=t.charCodeAt(o)-48;n<<=4,n|=s>=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function u(t,i,e,n){for(var r=0,o=Math.min(t.length,e),s=i;s<o;s++){var h=t.charCodeAt(s)-48;r*=n,r+=h>=49?h-49+10:h>=17?h-17+10:h}return r}r.isBN=function(t){return t instanceof r||null!==t&&"object"==typeof t&&t.constructor.wordSize===r.wordSize&&Array.isArray(t.words)},r.max=function(t,i){return t.cmp(i)>0?t:i},r.min=function(t,i){return t.cmp(i)<0?t:i},r.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),e(i===(0|i)&&i>=2&&i<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===i?this._parseHex(t,r):this._parseBase(t,i,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),i,n)},r.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},r.prototype._initArray=function(t,i,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,s,h=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)this.words[o]|=(s=t[r]|t[r-1]<<8|t[r-2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)this.words[o]|=(s=t[r]|t[r+1]<<8|t[r+2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);return this.strip()},r.prototype._parseHex=function(t,i){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var n,r,o=0;for(e=t.length-6,n=0;e>=i;e-=6)r=h(t,e,e+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);e+6!==i&&(r=h(t,i,e+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303),this.strip()},r.prototype._parseBase=function(t,i,e){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=i)n++;n--,r=r/i|0;for(var o=t.length-e,s=o%n,h=Math.min(o,o-s)+e,a=0,l=e;l<h;l+=n)a=u(t,l,l+n,i),this.imuln(r),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==s){var m=1;for(a=u(t,l,t.length,i),l=0;l<s;l++)m*=i;this.imuln(m),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}},r.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},r.prototype.clone=function(){var t=new r(null);return this.copy(t),t},r.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},r.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},r.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},r.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,e){e.negative=i.negative^t.negative;var n=t.length+i.length|0;e.length=n,n=n-1|0;var r=0|t.words[0],o=0|i.words[0],s=r*o,h=s/67108864|0;e.words[0]=67108863&s;for(var u=1;u<n;u++){for(var a=h>>>26,l=67108863&h,m=Math.min(u,i.length-1),d=Math.max(0,u-t.length+1);d<=m;d++)a+=(s=(r=0|t.words[u-d|0])*(o=0|i.words[d])+l)/67108864|0,l=67108863&s;e.words[u]=0|l,h=0|a}return 0!==h?e.words[u]=0|h:e.length--,e.strip()}r.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var h=this.words[s],u=(16777215&(h<<r|o)).toString(16);n=0!=(o=h>>>24-r&16777215)||s!==this.length-1?a[6-u.length]+u+n:u+n,(r+=2)>=26&&(r-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:a[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},r.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},r.prototype.toJSON=function(){return this.toString(16)},r.prototype.toBuffer=function(t,i){return e(void 0!==s),this.toArrayLike(s,t,i)},r.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},r.prototype.toArrayLike=function(t,i,n){var r=this.byteLength(),o=n||Math.max(1,r);e(r<=o,"byte array longer than desired length"),e(o>0,"Requested array length <= 0"),this.strip();var s,h,u="le"===i,a=new t(o),l=this.clone();if(u){for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[h]=s;for(;h<o;h++)a[h]=0}else{for(h=0;h<o-r;h++)a[h]=0;for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[o-h-1]=s}return a},r.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var i=t,e=0;return i>=4096&&(e+=13,i>>>=13),i>=64&&(e+=7,i>>>=7),i>=8&&(e+=4,i>>>=4),i>=2&&(e+=2,i>>>=2),e+i},r.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,e=0;return 0==(8191&i)&&(e+=13,i>>>=13),0==(127&i)&&(e+=7,i>>>=7),0==(15&i)&&(e+=4,i>>>=4),0==(3&i)&&(e+=2,i>>>=2),0==(1&i)&&e++,e},r.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var e=this._zeroBits(this.words[i]);if(t+=e,26!==e)break}return t},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},r.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return 0!==this.negative},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},r.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},r.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},r.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},r.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var e=0;e<i.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=i.length,this.strip()},r.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},r.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},r.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},r.prototype.iuxor=function(t){var i,e;this.length>t.length?(i=this,e=t):(i=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=i.words[n]^e.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},r.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},r.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},r.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},r.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var r=0;r<i;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},r.prototype.notn=function(t){return this.clone().inotn(t)},r.prototype.setn=function(t,i){e("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},r.prototype.iadd=function(t){var i,e,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0,o=0;o<n.length;o++)this.words[o]=67108863&(i=(0|e.words[o])+(0|n.words[o])+r),r=i>>>26;for(;0!==r&&o<e.length;o++)this.words[o]=67108863&(i=(0|e.words[o])+r),r=i>>>26;if(this.length=e.length,0!==r)this.words[this.length]=r,this.length++;else if(e!==this)for(;o<e.length;o++)this.words[o]=e.words[o];return this},r.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},r.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(e=this,n=t):(e=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(i=(0|e.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&i;for(;0!==o&&s<e.length;s++)o=(i=(0|e.words[s])+o)>>26,this.words[s]=67108863&i;if(0===o&&s<e.length&&e!==this)for(;s<e.length;s++)this.words[s]=e.words[s];return this.length=Math.max(this.length,s),e!==this&&(this.negative=1),this.strip()},r.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,i,e){var n,r,o,s=t.words,h=i.words,u=e.words,a=0,l=0|s[0],m=8191&l,d=l>>>13,f=0|s[1],p=8191&f,c=f>>>13,y=0|s[2],v=8191&y,g=y>>>13,M=0|s[3],w=8191&M,b=M>>>13,_=0|s[4],k=8191&_,x=_>>>13,S=0|s[5],A=8191&S,R=S>>>13,B=0|s[6],q=8191&B,D=B>>>13,K=0|s[7],T=8191&K,Z=K>>>13,N=0|s[8],I=8191&N,j=N>>>13,E=0|s[9],O=8191&E,C=E>>>13,L=0|h[0],P=8191&L,$=L>>>13,z=0|h[1],V=8191&z,F=z>>>13,U=0|h[2],H=8191&U,G=U>>>13,J=0|h[3],W=8191&J,Y=J>>>13,Q=0|h[4],X=8191&Q,tt=Q>>>13,it=0|h[5],et=8191&it,nt=it>>>13,rt=0|h[6],ot=8191&rt,st=rt>>>13,ht=0|h[7],ut=8191&ht,at=ht>>>13,lt=0|h[8],mt=8191<,dt=lt>>>13,ft=0|h[9],pt=8191&ft,ct=ft>>>13;e.negative=t.negative^i.negative,e.length=19;var yt=(a+(n=Math.imul(m,P))|0)+((8191&(r=(r=Math.imul(m,$))+Math.imul(d,P)|0))<<13)|0;a=((o=Math.imul(d,$))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,P),r=(r=Math.imul(p,$))+Math.imul(c,P)|0,o=Math.imul(c,$);var vt=(a+(n=n+Math.imul(m,V)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,V)|0))<<13)|0;a=((o=o+Math.imul(d,F)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,P),r=(r=Math.imul(v,$))+Math.imul(g,P)|0,o=Math.imul(g,$),n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,V)|0,o=o+Math.imul(c,F)|0;var gt=(a+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;a=((o=o+Math.imul(d,G)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(w,P),r=(r=Math.imul(w,$))+Math.imul(b,P)|0,o=Math.imul(b,$),n=n+Math.imul(v,V)|0,r=(r=r+Math.imul(v,F)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,o=o+Math.imul(c,G)|0;var Mt=(a+(n=n+Math.imul(m,W)|0)|0)+((8191&(r=(r=r+Math.imul(m,Y)|0)+Math.imul(d,W)|0))<<13)|0;a=((o=o+Math.imul(d,Y)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(k,P),r=(r=Math.imul(k,$))+Math.imul(x,P)|0,o=Math.imul(x,$),n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,F)|0,n=n+Math.imul(v,H)|0,r=(r=r+Math.imul(v,G)|0)+Math.imul(g,H)|0,o=o+Math.imul(g,G)|0,n=n+Math.imul(p,W)|0,r=(r=r+Math.imul(p,Y)|0)+Math.imul(c,W)|0,o=o+Math.imul(c,Y)|0;var wt=(a+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;a=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,P),r=(r=Math.imul(A,$))+Math.imul(R,P)|0,o=Math.imul(R,$),n=n+Math.imul(k,V)|0,r=(r=r+Math.imul(k,F)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,o=o+Math.imul(b,G)|0,n=n+Math.imul(v,W)|0,r=(r=r+Math.imul(v,Y)|0)+Math.imul(g,W)|0,o=o+Math.imul(g,Y)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,o=o+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(m,et)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,et)|0))<<13)|0;a=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(q,P),r=(r=Math.imul(q,$))+Math.imul(D,P)|0,o=Math.imul(D,$),n=n+Math.imul(A,V)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,F)|0,n=n+Math.imul(k,H)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(x,H)|0,o=o+Math.imul(x,G)|0,n=n+Math.imul(w,W)|0,r=(r=r+Math.imul(w,Y)|0)+Math.imul(b,W)|0,o=o+Math.imul(b,Y)|0,n=n+Math.imul(v,X)|0,r=(r=r+Math.imul(v,tt)|0)+Math.imul(g,X)|0,o=o+Math.imul(g,tt)|0,n=n+Math.imul(p,et)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,et)|0,o=o+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(m,ot)|0)|0)+((8191&(r=(r=r+Math.imul(m,st)|0)+Math.imul(d,ot)|0))<<13)|0;a=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(T,P),r=(r=Math.imul(T,$))+Math.imul(Z,P)|0,o=Math.imul(Z,$),n=n+Math.imul(q,V)|0,r=(r=r+Math.imul(q,F)|0)+Math.imul(D,V)|0,o=o+Math.imul(D,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,o=o+Math.imul(R,G)|0,n=n+Math.imul(k,W)|0,r=(r=r+Math.imul(k,Y)|0)+Math.imul(x,W)|0,o=o+Math.imul(x,Y)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(v,et)|0,r=(r=r+Math.imul(v,nt)|0)+Math.imul(g,et)|0,o=o+Math.imul(g,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(c,ot)|0,o=o+Math.imul(c,st)|0;var kt=(a+(n=n+Math.imul(m,ut)|0)|0)+((8191&(r=(r=r+Math.imul(m,at)|0)+Math.imul(d,ut)|0))<<13)|0;a=((o=o+Math.imul(d,at)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(I,P),r=(r=Math.imul(I,$))+Math.imul(j,P)|0,o=Math.imul(j,$),n=n+Math.imul(T,V)|0,r=(r=r+Math.imul(T,F)|0)+Math.imul(Z,V)|0,o=o+Math.imul(Z,F)|0,n=n+Math.imul(q,H)|0,r=(r=r+Math.imul(q,G)|0)+Math.imul(D,H)|0,o=o+Math.imul(D,G)|0,n=n+Math.imul(A,W)|0,r=(r=r+Math.imul(A,Y)|0)+Math.imul(R,W)|0,o=o+Math.imul(R,Y)|0,n=n+Math.imul(k,X)|0,r=(r=r+Math.imul(k,tt)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(w,et)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,et)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(v,ot)|0,r=(r=r+Math.imul(v,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,at)|0)+Math.imul(c,ut)|0,o=o+Math.imul(c,at)|0;var xt=(a+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;a=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(O,P),r=(r=Math.imul(O,$))+Math.imul(C,P)|0,o=Math.imul(C,$),n=n+Math.imul(I,V)|0,r=(r=r+Math.imul(I,F)|0)+Math.imul(j,V)|0,o=o+Math.imul(j,F)|0,n=n+Math.imul(T,H)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(Z,H)|0,o=o+Math.imul(Z,G)|0,n=n+Math.imul(q,W)|0,r=(r=r+Math.imul(q,Y)|0)+Math.imul(D,W)|0,o=o+Math.imul(D,Y)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,n=n+Math.imul(k,et)|0,r=(r=r+Math.imul(k,nt)|0)+Math.imul(x,et)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,n=n+Math.imul(v,ut)|0,r=(r=r+Math.imul(v,at)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,at)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,o=o+Math.imul(c,dt)|0;var St=(a+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;a=((o=o+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(O,V),r=(r=Math.imul(O,F))+Math.imul(C,V)|0,o=Math.imul(C,F),n=n+Math.imul(I,H)|0,r=(r=r+Math.imul(I,G)|0)+Math.imul(j,H)|0,o=o+Math.imul(j,G)|0,n=n+Math.imul(T,W)|0,r=(r=r+Math.imul(T,Y)|0)+Math.imul(Z,W)|0,o=o+Math.imul(Z,Y)|0,n=n+Math.imul(q,X)|0,r=(r=r+Math.imul(q,tt)|0)+Math.imul(D,X)|0,o=o+Math.imul(D,tt)|0,n=n+Math.imul(A,et)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,et)|0,o=o+Math.imul(R,nt)|0,n=n+Math.imul(k,ot)|0,r=(r=r+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,at)|0)+Math.imul(b,ut)|0,o=o+Math.imul(b,at)|0,n=n+Math.imul(v,mt)|0,r=(r=r+Math.imul(v,dt)|0)+Math.imul(g,mt)|0,o=o+Math.imul(g,dt)|0;var At=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((o=o+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(O,H),r=(r=Math.imul(O,G))+Math.imul(C,H)|0,o=Math.imul(C,G),n=n+Math.imul(I,W)|0,r=(r=r+Math.imul(I,Y)|0)+Math.imul(j,W)|0,o=o+Math.imul(j,Y)|0,n=n+Math.imul(T,X)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(Z,X)|0,o=o+Math.imul(Z,tt)|0,n=n+Math.imul(q,et)|0,r=(r=r+Math.imul(q,nt)|0)+Math.imul(D,et)|0,o=o+Math.imul(D,nt)|0,n=n+Math.imul(A,ot)|0,r=(r=r+Math.imul(A,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,n=n+Math.imul(k,ut)|0,r=(r=r+Math.imul(k,at)|0)+Math.imul(x,ut)|0,o=o+Math.imul(x,at)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,o=o+Math.imul(b,dt)|0;var Rt=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(r=(r=r+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((o=o+Math.imul(g,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(O,W),r=(r=Math.imul(O,Y))+Math.imul(C,W)|0,o=Math.imul(C,Y),n=n+Math.imul(I,X)|0,r=(r=r+Math.imul(I,tt)|0)+Math.imul(j,X)|0,o=o+Math.imul(j,tt)|0,n=n+Math.imul(T,et)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(Z,et)|0,o=o+Math.imul(Z,nt)|0,n=n+Math.imul(q,ot)|0,r=(r=r+Math.imul(q,st)|0)+Math.imul(D,ot)|0,o=o+Math.imul(D,st)|0,n=n+Math.imul(A,ut)|0,r=(r=r+Math.imul(A,at)|0)+Math.imul(R,ut)|0,o=o+Math.imul(R,at)|0,n=n+Math.imul(k,mt)|0,r=(r=r+Math.imul(k,dt)|0)+Math.imul(x,mt)|0,o=o+Math.imul(x,dt)|0;var Bt=(a+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((o=o+Math.imul(b,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(O,X),r=(r=Math.imul(O,tt))+Math.imul(C,X)|0,o=Math.imul(C,tt),n=n+Math.imul(I,et)|0,r=(r=r+Math.imul(I,nt)|0)+Math.imul(j,et)|0,o=o+Math.imul(j,nt)|0,n=n+Math.imul(T,ot)|0,r=(r=r+Math.imul(T,st)|0)+Math.imul(Z,ot)|0,o=o+Math.imul(Z,st)|0,n=n+Math.imul(q,ut)|0,r=(r=r+Math.imul(q,at)|0)+Math.imul(D,ut)|0,o=o+Math.imul(D,at)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,o=o+Math.imul(R,dt)|0;var qt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(r=(r=r+Math.imul(k,ct)|0)+Math.imul(x,pt)|0))<<13)|0;a=((o=o+Math.imul(x,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(O,et),r=(r=Math.imul(O,nt))+Math.imul(C,et)|0,o=Math.imul(C,nt),n=n+Math.imul(I,ot)|0,r=(r=r+Math.imul(I,st)|0)+Math.imul(j,ot)|0,o=o+Math.imul(j,st)|0,n=n+Math.imul(T,ut)|0,r=(r=r+Math.imul(T,at)|0)+Math.imul(Z,ut)|0,o=o+Math.imul(Z,at)|0,n=n+Math.imul(q,mt)|0,r=(r=r+Math.imul(q,dt)|0)+Math.imul(D,mt)|0,o=o+Math.imul(D,dt)|0;var Dt=(a+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;a=((o=o+Math.imul(R,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(O,ot),r=(r=Math.imul(O,st))+Math.imul(C,ot)|0,o=Math.imul(C,st),n=n+Math.imul(I,ut)|0,r=(r=r+Math.imul(I,at)|0)+Math.imul(j,ut)|0,o=o+Math.imul(j,at)|0,n=n+Math.imul(T,mt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(Z,mt)|0,o=o+Math.imul(Z,dt)|0;var Kt=(a+(n=n+Math.imul(q,pt)|0)|0)+((8191&(r=(r=r+Math.imul(q,ct)|0)+Math.imul(D,pt)|0))<<13)|0;a=((o=o+Math.imul(D,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(O,ut),r=(r=Math.imul(O,at))+Math.imul(C,ut)|0,o=Math.imul(C,at),n=n+Math.imul(I,mt)|0,r=(r=r+Math.imul(I,dt)|0)+Math.imul(j,mt)|0,o=o+Math.imul(j,dt)|0;var Tt=(a+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((o=o+Math.imul(Z,ct)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(O,mt),r=(r=Math.imul(O,dt))+Math.imul(C,mt)|0,o=Math.imul(C,dt);var Zt=(a+(n=n+Math.imul(I,pt)|0)|0)+((8191&(r=(r=r+Math.imul(I,ct)|0)+Math.imul(j,pt)|0))<<13)|0;a=((o=o+Math.imul(j,ct)|0)+(r>>>13)|0)+(Zt>>>26)|0,Zt&=67108863;var Nt=(a+(n=Math.imul(O,pt))|0)+((8191&(r=(r=Math.imul(O,ct))+Math.imul(C,pt)|0))<<13)|0;return a=((o=Math.imul(C,ct))+(r>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,u[0]=yt,u[1]=vt,u[2]=gt,u[3]=Mt,u[4]=wt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=xt,u[9]=St,u[10]=At,u[11]=Rt,u[12]=Bt,u[13]=qt,u[14]=Dt,u[15]=Kt,u[16]=Tt,u[17]=Zt,u[18]=Nt,0!==a&&(u[19]=a,e.length++),e};function p(t,i,e){return(new c).mulp(t,i,e)}function c(t,i){this.x=t,this.y=i}Math.imul||(f=d),r.prototype.mulTo=function(t,i){var e=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,i):e<63?d(this,t,i):e<1024?function(t,i,e){e.negative=i.negative^t.negative,e.length=t.length+i.length;for(var n=0,r=0,o=0;o<e.length-1;o++){var s=r;r=0;for(var h=67108863&n,u=Math.min(o,i.length-1),a=Math.max(0,o-t.length+1);a<=u;a++){var l=(0|t.words[o-a])*(0|i.words[a]),m=67108863&l;h=67108863&(m=m+h|0),r+=(s=(s=s+(l/67108864|0)|0)+(m>>>26)|0)>>>26,s&=67108863}e.words[o]=h,n=s,s=r}return 0!==n?e.words[o]=n:e.length--,e.strip()}(this,t,i):p(this,t,i)},c.prototype.makeRBT=function(t){for(var i=new Array(t),e=r.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,e,t);return i},c.prototype.revBin=function(t,i,e){if(0===t||t===e-1)return t;for(var n=0,r=0;r<i;r++)n|=(1&t)<<i-r-1,t>>=1;return n},c.prototype.permute=function(t,i,e,n,r,o){for(var s=0;s<o;s++)n[s]=i[t[s]],r[s]=e[t[s]]},c.prototype.transform=function(t,i,e,n,r,o){this.permute(o,t,i,e,n,r);for(var s=1;s<r;s<<=1)for(var h=s<<1,u=Math.cos(2*Math.PI/h),a=Math.sin(2*Math.PI/h),l=0;l<r;l+=h)for(var m=u,d=a,f=0;f<s;f++){var p=e[l+f],c=n[l+f],y=e[l+f+s],v=n[l+f+s],g=m*y-d*v;v=m*v+d*y,e[l+f]=p+(y=g),n[l+f]=c+v,e[l+f+s]=p-y,n[l+f+s]=c-v,f!==h&&(g=u*m-a*d,d=u*d+a*m,m=g)}},c.prototype.guessLen13b=function(t,i){var e=1|Math.max(i,t),n=1&e,r=0;for(e=e/2|0;e;e>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,i,e){if(!(e<=1))for(var n=0;n<e/2;n++){var r=t[n];t[n]=t[e-n-1],t[e-n-1]=r,r=i[n],i[n]=-i[e-n-1],i[e-n-1]=-r}},c.prototype.normalize13b=function(t,i){for(var e=0,n=0;n<i/2;n++){var r=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+e;t[n]=67108863&r,e=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,i,n,r){for(var o=0,s=0;s<i;s++)n[2*s]=8191&(o+=0|t[s]),n[2*s+1]=8191&(o>>>=13),o>>>=13;for(s=2*i;s<r;++s)n[s]=0;e(0===o),e(0==(-8192&o))},c.prototype.stub=function(t){for(var i=new Array(t),e=0;e<t;e++)i[e]=0;return i},c.prototype.mulp=function(t,i,e){var n=2*this.guessLen13b(t.length,i.length),r=this.makeRBT(n),o=this.stub(n),s=new Array(n),h=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),m=new Array(n),d=e.words;d.length=n,this.convert13b(t.words,t.length,s,n),this.convert13b(i.words,i.length,a,n),this.transform(s,o,h,u,n,r),this.transform(a,o,l,m,n,r);for(var f=0;f<n;f++){var p=h[f]*l[f]-u[f]*m[f];u[f]=h[f]*m[f]+u[f]*l[f],h[f]=p}return this.conjugate(h,u,n),this.transform(h,u,d,o,n,r),this.conjugate(d,o,n),this.normalize13b(d,n),e.negative=t.negative^i.negative,e.length=t.length+i.length,e.strip()},r.prototype.mul=function(t){var i=new r(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},r.prototype.mulf=function(t){var i=new r(null);return i.words=new Array(this.length+t.length),p(this,t,i)},r.prototype.imul=function(t){return this.clone().mulTo(t,this)},r.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var i=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,o=(67108863&r)+(67108863&i);i>>=26,i+=r/67108864|0,i+=o>>>26,this.words[n]=67108863&o}return 0!==i&&(this.words[n]=i,this.length++),this},r.prototype.muln=function(t){return this.clone().imuln(t)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),e=0;e<i.length;e++){var n=e%26;i[e]=(t.words[e/26|0]&1<<n)>>>n}return i}(t);if(0===i.length)return new r(1);for(var e=this,n=0;n<i.length&&0===i[n];n++,e=e.sqr());if(++n<i.length)for(var o=e.sqr();n<i.length;n++,o=o.sqr())0!==i[n]&&(e=e.mul(o));return e},r.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var i,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(i=0;i<this.length;i++){var h=this.words[i]&o;this.words[i]=(0|this.words[i])-h<<n|s,s=h>>>26-n}s&&(this.words[i]=s,this.length++)}if(0!==r){for(i=this.length-1;i>=0;i--)this.words[i+r]=this.words[i];for(i=0;i<r;i++)this.words[i]=0;this.length+=r}return this.strip()},r.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},r.prototype.iushrn=function(t,i,n){var r;e("number"==typeof t&&t>=0),r=i?(i-i%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),h=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var a=0;a<s;a++)u.words[a]=this.words[a];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,a=0;a<this.length;a++)this.words[a]=this.words[a+s];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=r);a--){var m=0|this.words[a];this.words[a]=l<<26-o|m>>>o,l=m&h}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},r.prototype.ishrn=function(t,i,n){return e(0===this.negative),this.iushrn(t,i,n)},r.prototype.shln=function(t){return this.clone().ishln(t)},r.prototype.ushln=function(t){return this.clone().iushln(t)},r.prototype.shrn=function(t){return this.clone().ishrn(t)},r.prototype.ushrn=function(t){return this.clone().iushrn(t)},r.prototype.testn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return!(this.length<=n||!(this.words[n]&1<<i))},r.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==i&&n++,this.length=Math.min(n,this.length),0!==i&&(this.words[this.length-1]&=67108863^67108863>>>i<<i),this.strip())},r.prototype.maskn=function(t){return this.clone().imaskn(t)},r.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},r.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},r.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},r.prototype.addn=function(t){return this.clone().iaddn(t)},r.prototype.subn=function(t){return this.clone().isubn(t)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(t,i,n){var r,o;this._expand(t.length+n);var s=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+s;var h=(0|t.words[r])*i;s=((o-=67108863&h)>>26)-(h/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)s=(o=(0|this.words[r+n])+s)>>26,this.words[r+n]=67108863&o;if(0===s)return this.strip();for(e(-1===s),s=0,r=0;r<this.length;r++)s=(o=-(0|this.words[r])+s)>>26,this.words[r]=67108863&o;return this.negative=1,this.strip()},r.prototype._wordDiv=function(t,i){var e,n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(e=26-this._countBits(s))&&(o=o.ushln(e),n.iushln(e),s=0|o.words[o.length-1]);var h,u=n.length-o.length;if("mod"!==i){(h=new r(null)).length=u+1,h.words=new Array(h.length);for(var a=0;a<h.length;a++)h.words[a]=0}var l=n.clone()._ishlnsubmul(o,1,u);0===l.negative&&(n=l,h&&(h.words[u]=1));for(var m=u-1;m>=0;m--){var d=67108864*(0|n.words[o.length+m])+(0|n.words[o.length+m-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(o,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(o,1,m),n.isZero()||(n.negative^=1);h&&(h.words[m]=d)}return h&&h.strip(),n.strip(),"div"!==i&&0!==e&&n.iushrn(e),{div:h||null,mod:n}},r.prototype.divmod=function(t,i,n){return e(!t.isZero()),this.isZero()?{div:new r(0),mod:new r(0)}:0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,i),"mod"!==i&&(o=h.div.neg()),"div"!==i&&(s=h.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),i),"mod"!==i&&(o=h.div.neg()),{div:o,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),i),"div"!==i&&(s=h.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:h.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new r(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new r(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new r(this.modn(t.words[0]))}:this._wordDiv(t,i);var o,s,h},r.prototype.div=function(t){return this.divmod(t,"div",!1).div},r.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},r.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},r.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var e=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),r=t.andln(1),o=e.cmp(n);return o<0||1===r&&0===o?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},r.prototype.modn=function(t){e(t<=67108863);for(var i=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(i*n+(0|this.words[r]))%t;return n},r.prototype.idivn=function(t){e(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*i;this.words[n]=r/t|0,i=r%t}return this.strip()},r.prototype.divn=function(t){return this.clone().idivn(t)},r.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var o=new r(1),s=new r(0),h=new r(0),u=new r(1),a=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),m=i.clone();!i.isZero();){for(var d=0,f=1;0==(i.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(i.iushrn(d);d-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(l),s.isub(m)),o.iushrn(1),s.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(h.isOdd()||u.isOdd())&&(h.iadd(l),u.isub(m)),h.iushrn(1),u.iushrn(1);i.cmp(n)>=0?(i.isub(n),o.isub(h),s.isub(u)):(n.isub(i),h.isub(o),u.isub(s))}return{a:h,b:u,gcd:n.iushln(a)}},r.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var o,s=new r(1),h=new r(0),u=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(i.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(i.iushrn(a);a-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)h.isOdd()&&h.iadd(u),h.iushrn(1);i.cmp(n)>=0?(i.isub(n),s.isub(h)):(n.isub(i),h.isub(s))}return(o=0===i.cmpn(1)?s:h).cmpn(0)<0&&o.iadd(t),o},r.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),e=t.clone();i.negative=0,e.negative=0;for(var n=0;i.isEven()&&e.isEven();n++)i.iushrn(1),e.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;e.isEven();)e.iushrn(1);var r=i.cmp(e);if(r<0){var o=i;i=e,e=o}else if(0===r||0===e.cmpn(1))break;i.isub(e)}return e.iushln(n)},r.prototype.invm=function(t){return this.egcd(t).a.umod(t)},r.prototype.isEven=function(){return 0==(1&this.words[0])},r.prototype.isOdd=function(){return 1==(1&this.words[0])},r.prototype.andln=function(t){return this.words[0]&t},r.prototype.bincn=function(t){e("number"==typeof t);var i=t%26,n=(t-i)/26,r=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var h=0|this.words[s];o=(h+=o)>>>26,this.words[s]=h&=67108863}return 0!==o&&(this.words[s]=o,this.length++),this},r.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},r.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var r=0|this.words[0];i=r===t?0:r<t?-1:1}return 0!==this.negative?0|-i:i},r.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},r.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],r=0|t.words[e];if(n!==r){n<r?i=-1:n>r&&(i=1);break}}return i},r.prototype.gtn=function(t){return 1===this.cmpn(t)},r.prototype.gt=function(t){return 1===this.cmp(t)},r.prototype.gten=function(t){return this.cmpn(t)>=0},r.prototype.gte=function(t){return this.cmp(t)>=0},r.prototype.ltn=function(t){return-1===this.cmpn(t)},r.prototype.lt=function(t){return-1===this.cmp(t)},r.prototype.lten=function(t){return this.cmpn(t)<=0},r.prototype.lte=function(t){return this.cmp(t)<=0},r.prototype.eqn=function(t){return 0===this.cmpn(t)},r.prototype.eq=function(t){return 0===this.cmp(t)},r.red=function(t){return new _(t)},r.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},r.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(t){return this.red=t,this},r.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},r.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},r.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},r.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},r.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},r.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},r.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},r.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},r.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,i){this.name=t,this.p=new r(i,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=r._prime(t);this.m=i.p,this.prime=i}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new r(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new r(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var i,e=t;do{this.split(e,this.tmp),i=(e=(e=this.imulK(e)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):void 0!==e.strip?e.strip():e._strip(),e},v.prototype.split=function(t,i){t.iushrn(this.n,0,i)},v.prototype.imulK=function(t){return t.imul(this.k)},n(g,v),g.prototype.split=function(t,i){for(var e=Math.min(t.length,9),n=0;n<e;n++)i.words[n]=t.words[n];if(i.length=e,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(i.words[i.length++]=4194303&r,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(4194303&o)<<4|r>>>22,r=o}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,e=0;e<t.length;e++){var n=0|t.words[e];t.words[e]=67108863&(i+=977*n),i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(M,v),n(w,v),n(b,v),b.prototype.imulK=function(t){for(var i=0,e=0;e<t.length;e++){var n=19*(0|t.words[e])+i,r=67108863&n;n>>>=26,t.words[e]=r,i=n}return 0!==i&&(t.words[t.length++]=i),t},r._prime=function(t){if(y[t])return y[t];var i;if("k256"===t)i=new g;else if("p224"===t)i=new M;else if("p192"===t)i=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return y[t]=i,i},_.prototype._verify1=function(t){e(0===t.negative,"red works only with positives"),e(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){e(0==(t.negative|i.negative),"red works only with positives"),e(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var e=t.add(i);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var e=t.iadd(i);return e.cmp(this.m)>=0&&e.isub(this.m),e},_.prototype.sub=function(t,i){this._verify2(t,i);var e=t.sub(i);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var e=t.isub(i);return e.cmpn(0)<0&&e.iadd(this.m),e},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(e(i%2==1),3===i){var n=this.m.add(new r(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);e(!o.isZero());var h=new r(1).toRed(this),u=h.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new r(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var m=this.pow(l,o),d=this.pow(t,o.addn(1).iushrn(1)),f=this.pow(t,o),p=s;0!==f.cmp(h);){for(var c=f,y=0;0!==c.cmp(h);y++)c=c.redSqr();e(y<p);var v=this.pow(m,new r(1).iushln(p-y-1));d=d.redMul(v),m=v.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new r(1).toRed(this);if(0===i.cmpn(1))return t.clone();var e=new Array(16);e[0]=new r(1).toRed(this),e[1]=t;for(var n=2;n<e.length;n++)e[n]=this.mul(e[n-1],t);var o=e[0],s=0,h=0,u=i.bitLength()%26;for(0===u&&(u=26),n=i.length-1;n>=0;n--){for(var a=i.words[n],l=u-1;l>=0;l--){var m=a>>l&1;o!==e[0]&&(o=this.sqr(o)),0!==m||0!==s?(s<<=1,s|=m,(4==++h||0===n&&0===l)&&(o=this.mul(o,e[s]),h=0,s=0)):h=0}u=26}return o},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},r.mont=function(t){return new k(t)},n(k,_),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},k.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new r(0)._forceRed(this);var e=t.mul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=e.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,a)}(e={path:void 0,exports:{},require:function(t,i){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),e.exports}(),m=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function d(t){return r.Buffer.from(u.keccak_256.arrayBuffer(t))}const f=new h.ec("secp256k1");function p(t){const i=(""+t).startsWith("0x")?t.slice(2):t,e=f.keyFromPublic(i,"hex").getPublic().encode("hex");return function(t){var i=t;const e=d(i=i.substring(2).toLowerCase());i=i.split("");for(var n=0;n<40;n+=2)e[n/2]>>4>=8&&(i[n]=i[n].toUpperCase()),(15&e[n/2])>=8&&(i[n+1]=i[n+1].toUpperCase());return"0x"+i.join("")}("0x"+d(r.Buffer.from(e.slice(2),"hex")).slice(-20).toString("hex"))}function c(t,i,e){if(!t.s){if(e instanceof v){if(!e.s)return void(e.o=c.bind(null,t,i));1&i&&(i=e.s),e=e.v}if(e&&e.then)return void e.then(c.bind(null,t,i),c.bind(null,t,2));t.s=i,t.v=e;const n=t.o;n&&n(t)}}const y="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",v=function(){function t(){}return t.prototype.then=function(i,e){const n=new t,r=this.s;if(r){const t=1&r?i:e;if(t){try{c(n,1,t(this.v))}catch(t){c(n,2,t)}return n}return this}return this.o=function(t){try{const r=t.v;1&t.s?c(n,1,i?i(r):r):e?c(n,1,e(r)):c(n,2,r)}catch(t){c(n,2,t)}},n},t}();function g(t){return t instanceof v&&1&t.s}const M=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function w(t){return r.Buffer.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function b(t){const i="0x"+r.Buffer.from(t).slice(0,32).toString("hex");return i+"0".repeat(66-i.length)}const _={Secp256k1SignatureAuthentication2018:b("sigAuth"),Secp256k1VerificationKey2018:b("veriKey")},k={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function x(t,i,e,n){const o=new l(Math.floor((new Date).getTime()/1e3)),s=[{id:t+"#controller",type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:i}],h=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controller"}];e&&(s.push({id:t+"#controllerKey",type:"Secp256k1VerificationKey2018",controller:t,publicKeyHex:e}),h.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controllerKey"}));let u=0;const a={},m={},d={};for(const i of n){const e=i.validTo,n=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(e&&e.gte(o)){if("DIDDelegateChanged"===i._eventName)switch(u++,w(i.delegateType)){case"sigAuth":a[n]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${u}`};case"veriKey":m[n]={id:`${t}#delegate-${u}`,type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:i.delegate}}else if("DIDAttributeChanged"===i._eventName){const e=w(i.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(e){const o=e[2],s=k[e[4]]||e[4],h=e[6];switch(e[1]){case"pub":{u++;const e={id:`${t}#delegate-${u}`,type:`${o}${s}`,controller:t};switch(h){case null:case void 0:case"hex":e.publicKeyHex=i.value.slice(2);break;case"base64":e.publicKeyBase64=r.Buffer.from(i.value.slice(2),"hex").toString("base64");break;case"base58":e.publicKeyBase58=r.Buffer.from(i.value.slice(2),"hex").toString("base58");break;case"pem":e.publicKeyPem=r.Buffer.from(i.value.slice(2),"hex").toString();break;default:e.value=i.value}m[n]=e;break}case"svc":d[n]={type:o,serviceEndpoint:r.Buffer.from(i.value.slice(2),"hex").toString()}}}}}else u>0&&("DIDDelegateChanged"===i._eventName||"DIDAttributeChanged"===i._eventName&&w(i.name).match(/^did\/pub\//))&&e.lt(o)&&u--,delete a[n],delete m[n],delete d[n]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:s.concat(Object.values(m)),authentication:h.concat(Object.values(a))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function S(t={}){const n=function(t={}){return t.provider?t.provider:t.web3?t.web3.currentProvider:t.rpcUrl?new i(t.rpcUrl):null}(t);if(null===n)return null;const r=new e(n),o=t.registry||y;return{eth:r,registryAddress:o,didReg:new s(r)(m).at(o)}}function A(t=[]){const i={};for(let e=0;e<t.length;e++){const n=t[e];i[n.name]=S(n),null===i[n.name]&&console.warn("invalid configuration for "+n.name)}return i}module.exports={REGISTRY:y,bytes32toString:w,stringToBytes32:b,delegateTypes:_,attrTypes:k,wrapDidDocument:x,getResolver:function(t={}){const i=n.logDecoder(m,!1),e={mainnet:S(t),...A(t.networks)};return function(t={},i={}){if((i.provider||i.web3||i.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(i&&i.networks)for(const e of i.networks)if(!t[e.name])throw new Error(`Ethereum provider configuration for ${e.name} was attempted but no valid configuration was provided`);let e=0;for(const i of Object.keys(t))null!==t[i]&&e++;if(0===e)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(e,t),{ethr:function(t,n){try{const r=n.id.match(M);if(!r)throw new Error("Not a valid ethr DID: "+t);const o=r[2],s=r[1]?r[1].slice(0,-1):"mainnet";if(!e[s])throw new Error("No conf for networkId: "+s);return Promise.resolve(function(t,n){try{const o=[];let{address:s,publicKey:h}=(r=t).length>42?{address:p(r),publicKey:r}:{address:r},u=s;return Promise.resolve(function(t,i){try{return Promise.resolve(e[i].didReg.changed(t)).then(function(t){if(t)return t[0]})}catch(t){return Promise.reject(t)}}(s,n)).then(function(t){function r(){function r(){return{controller:u,history:o,publicKey:h}}const a=function(t,i,e){for(var n;;){var r=t();if(g(r)&&(r=r.v),!r)return o;if(r.then){n=0;break}var o=e();if(o&&o.then){if(!g(o)){n=1;break}o=o.s}}var s=new v,h=c.bind(null,s,2);return(0===n?r.then(a):1===n?o.then(u):(void 0).then(function(){(r=t())?r.then?r.then(a).then(void 0,h):a(r):c(s,1,o)})).then(void 0,h),s;function u(i){o=i;do{if(!(r=t())||g(r)&&!r.v)return void c(s,1,o);if(r.then)return void r.then(a).then(void 0,h);g(o=e())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,h)}function a(t){t?(o=e())&&o.then?o.then(u).then(void 0,h):u(o):c(s,1,o)}}(function(){return!!t},0,function(){const r=t;return Promise.resolve(e[n].eth.getLogs({address:e[n].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:t,toBlock:t})).then(function(e){const n=i(e);t=void 0;for(const i of n)o.unshift(i),i.previousChange.lt(r)&&(t=i.previousChange)})});return a&&a.then?a.then(r):r()}const a=function(){if(t)return Promise.resolve(e[n].didReg.identityOwner(s)).then(function(t){const i=""+t[0];i.toLowerCase()!==u.toLowerCase()&&(h=null),u=i})}();return a&&a.then?a.then(r):r()})}catch(t){return Promise.reject(t)}var r}(o,s)).then(function({controller:i,history:e,publicKey:n}){return x(t,i,n,e)})}catch(t){return Promise.reject(t)}}}},identifierMatcher:M}; | ||
//# sourceMappingURL=ethr-did-resolver.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"ethjs-provider-http";import i from"ethjs-query";import e from"ethjs-abi";import n,{Buffer as r}from"buffer";import s from"ethjs-contract";import{ec as h}from"elliptic";import{keccak_256 as o}from"js-sha3";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u=function(t,i,e){return function(t){!function(t,i){function e(t,i){if(!t)throw new Error(i||"Assertion failed")}function r(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}function s(t,i,e){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(e=i,i=10),this._init(t||0,i||10,e||"be"))}var h;"object"==typeof t?t.exports=s:i.BN=s,s.BN=s,s.wordSize=26;try{h=n.Buffer}catch(t){}function o(t,i,e){for(var n=0,r=Math.min(t.length,e),s=i;s<r;s++){var h=t.charCodeAt(s)-48;n<<=4,n|=h>=49&&h<=54?h-49+10:h>=17&&h<=22?h-17+10:15&h}return n}function a(t,i,e,n){for(var r=0,s=Math.min(t.length,e),h=i;h<s;h++){var o=t.charCodeAt(h)-48;r*=n,r+=o>=49?o-49+10:o>=17?o-17+10:o}return r}s.isBN=function(t){return t instanceof s||null!==t&&"object"==typeof t&&t.constructor.wordSize===s.wordSize&&Array.isArray(t.words)},s.max=function(t,i){return t.cmp(i)>0?t:i},s.min=function(t,i){return t.cmp(i)<0?t:i},s.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),e(i===(0|i)&&i>=2&&i<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===i?this._parseHex(t,r):this._parseBase(t,i,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),i,n)},s.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},s.prototype._initArray=function(t,i,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var s,h,o=0;if("be"===n)for(r=t.length-1,s=0;r>=0;r-=3)this.words[s]|=(h=t[r]|t[r-1]<<8|t[r-2]<<16)<<o&67108863,this.words[s+1]=h>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);else if("le"===n)for(r=0,s=0;r<t.length;r+=3)this.words[s]|=(h=t[r]|t[r+1]<<8|t[r+2]<<16)<<o&67108863,this.words[s+1]=h>>>26-o&67108863,(o+=24)>=26&&(o-=26,s++);return this.strip()},s.prototype._parseHex=function(t,i){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var n,r,s=0;for(e=t.length-6,n=0;e>=i;e-=6)r=o(t,e,e+6),this.words[n]|=r<<s&67108863,this.words[n+1]|=r>>>26-s&4194303,(s+=24)>=26&&(s-=26,n++);e+6!==i&&(r=o(t,i,e+6),this.words[n]|=r<<s&67108863,this.words[n+1]|=r>>>26-s&4194303),this.strip()},s.prototype._parseBase=function(t,i,e){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=i)n++;n--,r=r/i|0;for(var s=t.length-e,h=s%n,o=Math.min(s,s-h)+e,u=0,l=e;l<o;l+=n)u=a(t,l,l+n,i),this.imuln(r),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==h){var m=1;for(u=a(t,l,t.length,i),l=0;l<h;l++)m*=i;this.imuln(m),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},s.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},s.prototype.clone=function(){var t=new s(null);return this.copy(t),t},s.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var u=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,e){e.negative=i.negative^t.negative;var n=t.length+i.length|0;e.length=n,n=n-1|0;var r=0|t.words[0],s=0|i.words[0],h=r*s,o=h/67108864|0;e.words[0]=67108863&h;for(var a=1;a<n;a++){for(var u=o>>>26,l=67108863&o,m=Math.min(a,i.length-1),d=Math.max(0,a-t.length+1);d<=m;d++)u+=(h=(r=0|t.words[a-d|0])*(s=0|i.words[d])+l)/67108864|0,l=67108863&h;e.words[a]=0|l,o=0|u}return 0!==o?e.words[a]=0|o:e.length--,e.strip()}s.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,s=0,h=0;h<this.length;h++){var o=this.words[h],a=(16777215&(o<<r|s)).toString(16);n=0!=(s=o>>>24-r&16777215)||h!==this.length-1?u[6-a.length]+a+n:a+n,(r+=2)>=26&&(r-=26,h--)}for(0!==s&&(n=s.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:u[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(t,i){return e(void 0!==h),this.toArrayLike(h,t,i)},s.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},s.prototype.toArrayLike=function(t,i,n){var r=this.byteLength(),s=n||Math.max(1,r);e(r<=s,"byte array longer than desired length"),e(s>0,"Requested array length <= 0"),this.strip();var h,o,a="le"===i,u=new t(s),l=this.clone();if(a){for(o=0;!l.isZero();o++)h=l.andln(255),l.iushrn(8),u[o]=h;for(;o<s;o++)u[o]=0}else{for(o=0;o<s-r;o++)u[o]=0;for(o=0;!l.isZero();o++)h=l.andln(255),l.iushrn(8),u[s-o-1]=h}return u},s.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var i=t,e=0;return i>=4096&&(e+=13,i>>>=13),i>=64&&(e+=7,i>>>=7),i>=8&&(e+=4,i>>>=4),i>=2&&(e+=2,i>>>=2),e+i},s.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,e=0;return 0==(8191&i)&&(e+=13,i>>>=13),0==(127&i)&&(e+=7,i>>>=7),0==(15&i)&&(e+=4,i>>>=4),0==(3&i)&&(e+=2,i>>>=2),0==(1&i)&&e++,e},s.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var e=this._zeroBits(this.words[i]);if(t+=e,26!==e)break}return t},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},s.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return 0!==this.negative},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},s.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},s.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var e=0;e<i.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=i.length,this.strip()},s.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},s.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var i,e;this.length>t.length?(i=this,e=t):(i=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=i.words[n]^e.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},s.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},s.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var r=0;r<i;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},s.prototype.notn=function(t){return this.clone().inotn(t)},s.prototype.setn=function(t,i){e("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},s.prototype.iadd=function(t){var i,e,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0,s=0;s<n.length;s++)this.words[s]=67108863&(i=(0|e.words[s])+(0|n.words[s])+r),r=i>>>26;for(;0!==r&&s<e.length;s++)this.words[s]=67108863&(i=(0|e.words[s])+r),r=i>>>26;if(this.length=e.length,0!==r)this.words[this.length]=r,this.length++;else if(e!==this)for(;s<e.length;s++)this.words[s]=e.words[s];return this},s.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(e=this,n=t):(e=t,n=this);for(var s=0,h=0;h<n.length;h++)s=(i=(0|e.words[h])-(0|n.words[h])+s)>>26,this.words[h]=67108863&i;for(;0!==s&&h<e.length;h++)s=(i=(0|e.words[h])+s)>>26,this.words[h]=67108863&i;if(0===s&&h<e.length&&e!==this)for(;h<e.length;h++)this.words[h]=e.words[h];return this.length=Math.max(this.length,h),e!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,i,e){var n,r,s,h=t.words,o=i.words,a=e.words,u=0,l=0|h[0],m=8191&l,d=l>>>13,f=0|h[1],p=8191&f,c=f>>>13,y=0|h[2],g=8191&y,v=y>>>13,M=0|h[3],w=8191&M,b=M>>>13,_=0|h[4],x=8191&_,k=_>>>13,S=0|h[5],A=8191&S,R=S>>>13,D=0|h[6],K=8191&D,q=D>>>13,B=0|h[7],T=8191&B,Z=B>>>13,N=0|h[8],I=8191&N,E=N>>>13,O=0|h[9],C=8191&O,L=O>>>13,j=0|o[0],$=8191&j,z=j>>>13,V=0|o[1],P=8191&V,F=V>>>13,U=0|o[2],H=8191&U,G=U>>>13,J=0|o[3],W=8191&J,Y=J>>>13,Q=0|o[4],X=8191&Q,tt=Q>>>13,it=0|o[5],et=8191&it,nt=it>>>13,rt=0|o[6],st=8191&rt,ht=rt>>>13,ot=0|o[7],at=8191&ot,ut=ot>>>13,lt=0|o[8],mt=8191<,dt=lt>>>13,ft=0|o[9],pt=8191&ft,ct=ft>>>13;e.negative=t.negative^i.negative,e.length=19;var yt=(u+(n=Math.imul(m,$))|0)+((8191&(r=(r=Math.imul(m,z))+Math.imul(d,$)|0))<<13)|0;u=((s=Math.imul(d,z))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,$),r=(r=Math.imul(p,z))+Math.imul(c,$)|0,s=Math.imul(c,z);var gt=(u+(n=n+Math.imul(m,P)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,P)|0))<<13)|0;u=((s=s+Math.imul(d,F)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(g,$),r=(r=Math.imul(g,z))+Math.imul(v,$)|0,s=Math.imul(v,z),n=n+Math.imul(p,P)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,P)|0,s=s+Math.imul(c,F)|0;var vt=(u+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;u=((s=s+Math.imul(d,G)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(w,$),r=(r=Math.imul(w,z))+Math.imul(b,$)|0,s=Math.imul(b,z),n=n+Math.imul(g,P)|0,r=(r=r+Math.imul(g,F)|0)+Math.imul(v,P)|0,s=s+Math.imul(v,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,s=s+Math.imul(c,G)|0;var Mt=(u+(n=n+Math.imul(m,W)|0)|0)+((8191&(r=(r=r+Math.imul(m,Y)|0)+Math.imul(d,W)|0))<<13)|0;u=((s=s+Math.imul(d,Y)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(x,$),r=(r=Math.imul(x,z))+Math.imul(k,$)|0,s=Math.imul(k,z),n=n+Math.imul(w,P)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,P)|0,s=s+Math.imul(b,F)|0,n=n+Math.imul(g,H)|0,r=(r=r+Math.imul(g,G)|0)+Math.imul(v,H)|0,s=s+Math.imul(v,G)|0,n=n+Math.imul(p,W)|0,r=(r=r+Math.imul(p,Y)|0)+Math.imul(c,W)|0,s=s+Math.imul(c,Y)|0;var wt=(u+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,$),r=(r=Math.imul(A,z))+Math.imul(R,$)|0,s=Math.imul(R,z),n=n+Math.imul(x,P)|0,r=(r=r+Math.imul(x,F)|0)+Math.imul(k,P)|0,s=s+Math.imul(k,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,G)|0,n=n+Math.imul(g,W)|0,r=(r=r+Math.imul(g,Y)|0)+Math.imul(v,W)|0,s=s+Math.imul(v,Y)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,s=s+Math.imul(c,tt)|0;var bt=(u+(n=n+Math.imul(m,et)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,et)|0))<<13)|0;u=((s=s+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(K,$),r=(r=Math.imul(K,z))+Math.imul(q,$)|0,s=Math.imul(q,z),n=n+Math.imul(A,P)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,P)|0,s=s+Math.imul(R,F)|0,n=n+Math.imul(x,H)|0,r=(r=r+Math.imul(x,G)|0)+Math.imul(k,H)|0,s=s+Math.imul(k,G)|0,n=n+Math.imul(w,W)|0,r=(r=r+Math.imul(w,Y)|0)+Math.imul(b,W)|0,s=s+Math.imul(b,Y)|0,n=n+Math.imul(g,X)|0,r=(r=r+Math.imul(g,tt)|0)+Math.imul(v,X)|0,s=s+Math.imul(v,tt)|0,n=n+Math.imul(p,et)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,et)|0,s=s+Math.imul(c,nt)|0;var _t=(u+(n=n+Math.imul(m,st)|0)|0)+((8191&(r=(r=r+Math.imul(m,ht)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ht)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(T,$),r=(r=Math.imul(T,z))+Math.imul(Z,$)|0,s=Math.imul(Z,z),n=n+Math.imul(K,P)|0,r=(r=r+Math.imul(K,F)|0)+Math.imul(q,P)|0,s=s+Math.imul(q,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,s=s+Math.imul(R,G)|0,n=n+Math.imul(x,W)|0,r=(r=r+Math.imul(x,Y)|0)+Math.imul(k,W)|0,s=s+Math.imul(k,Y)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,s=s+Math.imul(b,tt)|0,n=n+Math.imul(g,et)|0,r=(r=r+Math.imul(g,nt)|0)+Math.imul(v,et)|0,s=s+Math.imul(v,nt)|0,n=n+Math.imul(p,st)|0,r=(r=r+Math.imul(p,ht)|0)+Math.imul(c,st)|0,s=s+Math.imul(c,ht)|0;var xt=(u+(n=n+Math.imul(m,at)|0)|0)+((8191&(r=(r=r+Math.imul(m,ut)|0)+Math.imul(d,at)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(I,$),r=(r=Math.imul(I,z))+Math.imul(E,$)|0,s=Math.imul(E,z),n=n+Math.imul(T,P)|0,r=(r=r+Math.imul(T,F)|0)+Math.imul(Z,P)|0,s=s+Math.imul(Z,F)|0,n=n+Math.imul(K,H)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(q,H)|0,s=s+Math.imul(q,G)|0,n=n+Math.imul(A,W)|0,r=(r=r+Math.imul(A,Y)|0)+Math.imul(R,W)|0,s=s+Math.imul(R,Y)|0,n=n+Math.imul(x,X)|0,r=(r=r+Math.imul(x,tt)|0)+Math.imul(k,X)|0,s=s+Math.imul(k,tt)|0,n=n+Math.imul(w,et)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,et)|0,s=s+Math.imul(b,nt)|0,n=n+Math.imul(g,st)|0,r=(r=r+Math.imul(g,ht)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ht)|0,n=n+Math.imul(p,at)|0,r=(r=r+Math.imul(p,ut)|0)+Math.imul(c,at)|0,s=s+Math.imul(c,ut)|0;var kt=(u+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(C,$),r=(r=Math.imul(C,z))+Math.imul(L,$)|0,s=Math.imul(L,z),n=n+Math.imul(I,P)|0,r=(r=r+Math.imul(I,F)|0)+Math.imul(E,P)|0,s=s+Math.imul(E,F)|0,n=n+Math.imul(T,H)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(Z,H)|0,s=s+Math.imul(Z,G)|0,n=n+Math.imul(K,W)|0,r=(r=r+Math.imul(K,Y)|0)+Math.imul(q,W)|0,s=s+Math.imul(q,Y)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,s=s+Math.imul(R,tt)|0,n=n+Math.imul(x,et)|0,r=(r=r+Math.imul(x,nt)|0)+Math.imul(k,et)|0,s=s+Math.imul(k,nt)|0,n=n+Math.imul(w,st)|0,r=(r=r+Math.imul(w,ht)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ht)|0,n=n+Math.imul(g,at)|0,r=(r=r+Math.imul(g,ut)|0)+Math.imul(v,at)|0,s=s+Math.imul(v,ut)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,s=s+Math.imul(c,dt)|0;var St=(u+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;u=((s=s+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(C,P),r=(r=Math.imul(C,F))+Math.imul(L,P)|0,s=Math.imul(L,F),n=n+Math.imul(I,H)|0,r=(r=r+Math.imul(I,G)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,G)|0,n=n+Math.imul(T,W)|0,r=(r=r+Math.imul(T,Y)|0)+Math.imul(Z,W)|0,s=s+Math.imul(Z,Y)|0,n=n+Math.imul(K,X)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(q,X)|0,s=s+Math.imul(q,tt)|0,n=n+Math.imul(A,et)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,et)|0,s=s+Math.imul(R,nt)|0,n=n+Math.imul(x,st)|0,r=(r=r+Math.imul(x,ht)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ht)|0,n=n+Math.imul(w,at)|0,r=(r=r+Math.imul(w,ut)|0)+Math.imul(b,at)|0,s=s+Math.imul(b,ut)|0,n=n+Math.imul(g,mt)|0,r=(r=r+Math.imul(g,dt)|0)+Math.imul(v,mt)|0,s=s+Math.imul(v,dt)|0;var At=(u+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;u=((s=s+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(C,H),r=(r=Math.imul(C,G))+Math.imul(L,H)|0,s=Math.imul(L,G),n=n+Math.imul(I,W)|0,r=(r=r+Math.imul(I,Y)|0)+Math.imul(E,W)|0,s=s+Math.imul(E,Y)|0,n=n+Math.imul(T,X)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(Z,X)|0,s=s+Math.imul(Z,tt)|0,n=n+Math.imul(K,et)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(q,et)|0,s=s+Math.imul(q,nt)|0,n=n+Math.imul(A,st)|0,r=(r=r+Math.imul(A,ht)|0)+Math.imul(R,st)|0,s=s+Math.imul(R,ht)|0,n=n+Math.imul(x,at)|0,r=(r=r+Math.imul(x,ut)|0)+Math.imul(k,at)|0,s=s+Math.imul(k,ut)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,s=s+Math.imul(b,dt)|0;var Rt=(u+(n=n+Math.imul(g,pt)|0)|0)+((8191&(r=(r=r+Math.imul(g,ct)|0)+Math.imul(v,pt)|0))<<13)|0;u=((s=s+Math.imul(v,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(C,W),r=(r=Math.imul(C,Y))+Math.imul(L,W)|0,s=Math.imul(L,Y),n=n+Math.imul(I,X)|0,r=(r=r+Math.imul(I,tt)|0)+Math.imul(E,X)|0,s=s+Math.imul(E,tt)|0,n=n+Math.imul(T,et)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(Z,et)|0,s=s+Math.imul(Z,nt)|0,n=n+Math.imul(K,st)|0,r=(r=r+Math.imul(K,ht)|0)+Math.imul(q,st)|0,s=s+Math.imul(q,ht)|0,n=n+Math.imul(A,at)|0,r=(r=r+Math.imul(A,ut)|0)+Math.imul(R,at)|0,s=s+Math.imul(R,ut)|0,n=n+Math.imul(x,mt)|0,r=(r=r+Math.imul(x,dt)|0)+Math.imul(k,mt)|0,s=s+Math.imul(k,dt)|0;var Dt=(u+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;u=((s=s+Math.imul(b,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(C,X),r=(r=Math.imul(C,tt))+Math.imul(L,X)|0,s=Math.imul(L,tt),n=n+Math.imul(I,et)|0,r=(r=r+Math.imul(I,nt)|0)+Math.imul(E,et)|0,s=s+Math.imul(E,nt)|0,n=n+Math.imul(T,st)|0,r=(r=r+Math.imul(T,ht)|0)+Math.imul(Z,st)|0,s=s+Math.imul(Z,ht)|0,n=n+Math.imul(K,at)|0,r=(r=r+Math.imul(K,ut)|0)+Math.imul(q,at)|0,s=s+Math.imul(q,ut)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,s=s+Math.imul(R,dt)|0;var Kt=(u+(n=n+Math.imul(x,pt)|0)|0)+((8191&(r=(r=r+Math.imul(x,ct)|0)+Math.imul(k,pt)|0))<<13)|0;u=((s=s+Math.imul(k,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(C,et),r=(r=Math.imul(C,nt))+Math.imul(L,et)|0,s=Math.imul(L,nt),n=n+Math.imul(I,st)|0,r=(r=r+Math.imul(I,ht)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ht)|0,n=n+Math.imul(T,at)|0,r=(r=r+Math.imul(T,ut)|0)+Math.imul(Z,at)|0,s=s+Math.imul(Z,ut)|0,n=n+Math.imul(K,mt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(q,mt)|0,s=s+Math.imul(q,dt)|0;var qt=(u+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;u=((s=s+Math.imul(R,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(C,st),r=(r=Math.imul(C,ht))+Math.imul(L,st)|0,s=Math.imul(L,ht),n=n+Math.imul(I,at)|0,r=(r=r+Math.imul(I,ut)|0)+Math.imul(E,at)|0,s=s+Math.imul(E,ut)|0,n=n+Math.imul(T,mt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(Z,mt)|0,s=s+Math.imul(Z,dt)|0;var Bt=(u+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,ct)|0)+Math.imul(q,pt)|0))<<13)|0;u=((s=s+Math.imul(q,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(C,at),r=(r=Math.imul(C,ut))+Math.imul(L,at)|0,s=Math.imul(L,ut),n=n+Math.imul(I,mt)|0,r=(r=r+Math.imul(I,dt)|0)+Math.imul(E,mt)|0,s=s+Math.imul(E,dt)|0;var Tt=(u+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;u=((s=s+Math.imul(Z,ct)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(C,mt),r=(r=Math.imul(C,dt))+Math.imul(L,mt)|0,s=Math.imul(L,dt);var Zt=(u+(n=n+Math.imul(I,pt)|0)|0)+((8191&(r=(r=r+Math.imul(I,ct)|0)+Math.imul(E,pt)|0))<<13)|0;u=((s=s+Math.imul(E,ct)|0)+(r>>>13)|0)+(Zt>>>26)|0,Zt&=67108863;var Nt=(u+(n=Math.imul(C,pt))|0)+((8191&(r=(r=Math.imul(C,ct))+Math.imul(L,pt)|0))<<13)|0;return u=((s=Math.imul(L,ct))+(r>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,a[0]=yt,a[1]=gt,a[2]=vt,a[3]=Mt,a[4]=wt,a[5]=bt,a[6]=_t,a[7]=xt,a[8]=kt,a[9]=St,a[10]=At,a[11]=Rt,a[12]=Dt,a[13]=Kt,a[14]=qt,a[15]=Bt,a[16]=Tt,a[17]=Zt,a[18]=Nt,0!==u&&(a[19]=u,e.length++),e};function p(t,i,e){return(new c).mulp(t,i,e)}function c(t,i){this.x=t,this.y=i}Math.imul||(f=d),s.prototype.mulTo=function(t,i){var e=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,i):e<63?d(this,t,i):e<1024?function(t,i,e){e.negative=i.negative^t.negative,e.length=t.length+i.length;for(var n=0,r=0,s=0;s<e.length-1;s++){var h=r;r=0;for(var o=67108863&n,a=Math.min(s,i.length-1),u=Math.max(0,s-t.length+1);u<=a;u++){var l=(0|t.words[s-u])*(0|i.words[u]),m=67108863&l;o=67108863&(m=m+o|0),r+=(h=(h=h+(l/67108864|0)|0)+(m>>>26)|0)>>>26,h&=67108863}e.words[s]=o,n=h,h=r}return 0!==n?e.words[s]=n:e.length--,e.strip()}(this,t,i):p(this,t,i)},c.prototype.makeRBT=function(t){for(var i=new Array(t),e=s.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,e,t);return i},c.prototype.revBin=function(t,i,e){if(0===t||t===e-1)return t;for(var n=0,r=0;r<i;r++)n|=(1&t)<<i-r-1,t>>=1;return n},c.prototype.permute=function(t,i,e,n,r,s){for(var h=0;h<s;h++)n[h]=i[t[h]],r[h]=e[t[h]]},c.prototype.transform=function(t,i,e,n,r,s){this.permute(s,t,i,e,n,r);for(var h=1;h<r;h<<=1)for(var o=h<<1,a=Math.cos(2*Math.PI/o),u=Math.sin(2*Math.PI/o),l=0;l<r;l+=o)for(var m=a,d=u,f=0;f<h;f++){var p=e[l+f],c=n[l+f],y=e[l+f+h],g=n[l+f+h],v=m*y-d*g;g=m*g+d*y,e[l+f]=p+(y=v),n[l+f]=c+g,e[l+f+h]=p-y,n[l+f+h]=c-g,f!==o&&(v=a*m-u*d,d=a*d+u*m,m=v)}},c.prototype.guessLen13b=function(t,i){var e=1|Math.max(i,t),n=1&e,r=0;for(e=e/2|0;e;e>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,i,e){if(!(e<=1))for(var n=0;n<e/2;n++){var r=t[n];t[n]=t[e-n-1],t[e-n-1]=r,r=i[n],i[n]=-i[e-n-1],i[e-n-1]=-r}},c.prototype.normalize13b=function(t,i){for(var e=0,n=0;n<i/2;n++){var r=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+e;t[n]=67108863&r,e=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,i,n,r){for(var s=0,h=0;h<i;h++)n[2*h]=8191&(s+=0|t[h]),n[2*h+1]=8191&(s>>>=13),s>>>=13;for(h=2*i;h<r;++h)n[h]=0;e(0===s),e(0==(-8192&s))},c.prototype.stub=function(t){for(var i=new Array(t),e=0;e<t;e++)i[e]=0;return i},c.prototype.mulp=function(t,i,e){var n=2*this.guessLen13b(t.length,i.length),r=this.makeRBT(n),s=this.stub(n),h=new Array(n),o=new Array(n),a=new Array(n),u=new Array(n),l=new Array(n),m=new Array(n),d=e.words;d.length=n,this.convert13b(t.words,t.length,h,n),this.convert13b(i.words,i.length,u,n),this.transform(h,s,o,a,n,r),this.transform(u,s,l,m,n,r);for(var f=0;f<n;f++){var p=o[f]*l[f]-a[f]*m[f];a[f]=o[f]*m[f]+a[f]*l[f],o[f]=p}return this.conjugate(o,a,n),this.transform(o,a,d,s,n,r),this.conjugate(d,s,n),this.normalize13b(d,n),e.negative=t.negative^i.negative,e.length=t.length+i.length,e.strip()},s.prototype.mul=function(t){var i=new s(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},s.prototype.mulf=function(t){var i=new s(null);return i.words=new Array(this.length+t.length),p(this,t,i)},s.prototype.imul=function(t){return this.clone().mulTo(t,this)},s.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var i=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,s=(67108863&r)+(67108863&i);i>>=26,i+=r/67108864|0,i+=s>>>26,this.words[n]=67108863&s}return 0!==i&&(this.words[n]=i,this.length++),this},s.prototype.muln=function(t){return this.clone().imuln(t)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),e=0;e<i.length;e++){var n=e%26;i[e]=(t.words[e/26|0]&1<<n)>>>n}return i}(t);if(0===i.length)return new s(1);for(var e=this,n=0;n<i.length&&0===i[n];n++,e=e.sqr());if(++n<i.length)for(var r=e.sqr();n<i.length;n++,r=r.sqr())0!==i[n]&&(e=e.mul(r));return e},s.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var i,n=t%26,r=(t-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var h=0;for(i=0;i<this.length;i++){var o=this.words[i]&s;this.words[i]=(0|this.words[i])-o<<n|h,h=o>>>26-n}h&&(this.words[i]=h,this.length++)}if(0!==r){for(i=this.length-1;i>=0;i--)this.words[i+r]=this.words[i];for(i=0;i<r;i++)this.words[i]=0;this.length+=r}return this.strip()},s.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},s.prototype.iushrn=function(t,i,n){var r;e("number"==typeof t&&t>=0),r=i?(i-i%26)/26:0;var s=t%26,h=Math.min((t-s)/26,this.length),o=67108863^67108863>>>s<<s,a=n;if(r-=h,r=Math.max(0,r),a){for(var u=0;u<h;u++)a.words[u]=this.words[u];a.length=h}if(0===h);else if(this.length>h)for(this.length-=h,u=0;u<this.length;u++)this.words[u]=this.words[u+h];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=r);u--){var m=0|this.words[u];this.words[u]=l<<26-s|m>>>s,l=m&o}return a&&0!==l&&(a.words[a.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.ishrn=function(t,i,n){return e(0===this.negative),this.iushrn(t,i,n)},s.prototype.shln=function(t){return this.clone().ishln(t)},s.prototype.ushln=function(t){return this.clone().iushln(t)},s.prototype.shrn=function(t){return this.clone().ishrn(t)},s.prototype.ushrn=function(t){return this.clone().iushrn(t)},s.prototype.testn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return!(this.length<=n||!(this.words[n]&1<<i))},s.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==i&&n++,this.length=Math.min(n,this.length),0!==i&&(this.words[this.length-1]&=67108863^67108863>>>i<<i),this.strip())},s.prototype.maskn=function(t){return this.clone().imaskn(t)},s.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},s.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},s.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},s.prototype.addn=function(t){return this.clone().iaddn(t)},s.prototype.subn=function(t){return this.clone().isubn(t)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(t,i,n){var r,s;this._expand(t.length+n);var h=0;for(r=0;r<t.length;r++){s=(0|this.words[r+n])+h;var o=(0|t.words[r])*i;h=((s-=67108863&o)>>26)-(o/67108864|0),this.words[r+n]=67108863&s}for(;r<this.length-n;r++)h=(s=(0|this.words[r+n])+h)>>26,this.words[r+n]=67108863&s;if(0===h)return this.strip();for(e(-1===h),h=0,r=0;r<this.length;r++)h=(s=-(0|this.words[r])+h)>>26,this.words[r]=67108863&s;return this.negative=1,this.strip()},s.prototype._wordDiv=function(t,i){var e,n=this.clone(),r=t,h=0|r.words[r.length-1];0!=(e=26-this._countBits(h))&&(r=r.ushln(e),n.iushln(e),h=0|r.words[r.length-1]);var o,a=n.length-r.length;if("mod"!==i){(o=new s(null)).length=a+1,o.words=new Array(o.length);for(var u=0;u<o.length;u++)o.words[u]=0}var l=n.clone()._ishlnsubmul(r,1,a);0===l.negative&&(n=l,o&&(o.words[a]=1));for(var m=a-1;m>=0;m--){var d=67108864*(0|n.words[r.length+m])+(0|n.words[r.length+m-1]);for(d=Math.min(d/h|0,67108863),n._ishlnsubmul(r,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(r,1,m),n.isZero()||(n.negative^=1);o&&(o.words[m]=d)}return o&&o.strip(),n.strip(),"div"!==i&&0!==e&&n.iushrn(e),{div:o||null,mod:n}},s.prototype.divmod=function(t,i,n){return e(!t.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===t.negative?(o=this.neg().divmod(t,i),"mod"!==i&&(r=o.div.neg()),"div"!==i&&(h=o.mod.neg(),n&&0!==h.negative&&h.iadd(t)),{div:r,mod:h}):0===this.negative&&0!==t.negative?(o=this.divmod(t.neg(),i),"mod"!==i&&(r=o.div.neg()),{div:r,mod:o.mod}):0!=(this.negative&t.negative)?(o=this.neg().divmod(t.neg(),i),"div"!==i&&(h=o.mod.neg(),n&&0!==h.negative&&h.isub(t)),{div:o.div,mod:h}):t.length>this.length||this.cmp(t)<0?{div:new s(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new s(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new s(this.modn(t.words[0]))}:this._wordDiv(t,i);var r,h,o},s.prototype.div=function(t){return this.divmod(t,"div",!1).div},s.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},s.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},s.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var e=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),r=t.andln(1),s=e.cmp(n);return s<0||1===r&&0===s?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},s.prototype.modn=function(t){e(t<=67108863);for(var i=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(i*n+(0|this.words[r]))%t;return n},s.prototype.idivn=function(t){e(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*i;this.words[n]=r/t|0,i=r%t}return this.strip()},s.prototype.divn=function(t){return this.clone().idivn(t)},s.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r=new s(1),h=new s(0),o=new s(0),a=new s(1),u=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++u;for(var l=n.clone(),m=i.clone();!i.isZero();){for(var d=0,f=1;0==(i.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(i.iushrn(d);d-- >0;)(r.isOdd()||h.isOdd())&&(r.iadd(l),h.isub(m)),r.iushrn(1),h.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(o.isOdd()||a.isOdd())&&(o.iadd(l),a.isub(m)),o.iushrn(1),a.iushrn(1);i.cmp(n)>=0?(i.isub(n),r.isub(o),h.isub(a)):(n.isub(i),o.isub(r),a.isub(h))}return{a:o,b:a,gcd:n.iushln(u)}},s.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r,h=new s(1),o=new s(0),a=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var u=0,l=1;0==(i.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(i.iushrn(u);u-- >0;)h.isOdd()&&h.iadd(a),h.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)o.isOdd()&&o.iadd(a),o.iushrn(1);i.cmp(n)>=0?(i.isub(n),h.isub(o)):(n.isub(i),o.isub(h))}return(r=0===i.cmpn(1)?h:o).cmpn(0)<0&&r.iadd(t),r},s.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),e=t.clone();i.negative=0,e.negative=0;for(var n=0;i.isEven()&&e.isEven();n++)i.iushrn(1),e.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;e.isEven();)e.iushrn(1);var r=i.cmp(e);if(r<0){var s=i;i=e,e=s}else if(0===r||0===e.cmpn(1))break;i.isub(e)}return e.iushln(n)},s.prototype.invm=function(t){return this.egcd(t).a.umod(t)},s.prototype.isEven=function(){return 0==(1&this.words[0])},s.prototype.isOdd=function(){return 1==(1&this.words[0])},s.prototype.andln=function(t){return this.words[0]&t},s.prototype.bincn=function(t){e("number"==typeof t);var i=t%26,n=(t-i)/26,r=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var s=r,h=n;0!==s&&h<this.length;h++){var o=0|this.words[h];s=(o+=s)>>>26,this.words[h]=o&=67108863}return 0!==s&&(this.words[h]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var r=0|this.words[0];i=r===t?0:r<t?-1:1}return 0!==this.negative?0|-i:i},s.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},s.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],r=0|t.words[e];if(n!==r){n<r?i=-1:n>r&&(i=1);break}}return i},s.prototype.gtn=function(t){return 1===this.cmpn(t)},s.prototype.gt=function(t){return 1===this.cmp(t)},s.prototype.gten=function(t){return this.cmpn(t)>=0},s.prototype.gte=function(t){return this.cmp(t)>=0},s.prototype.ltn=function(t){return-1===this.cmpn(t)},s.prototype.lt=function(t){return-1===this.cmp(t)},s.prototype.lten=function(t){return this.cmpn(t)<=0},s.prototype.lte=function(t){return this.cmp(t)<=0},s.prototype.eqn=function(t){return 0===this.cmpn(t)},s.prototype.eq=function(t){return 0===this.cmp(t)},s.red=function(t){return new _(t)},s.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},s.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(t){return this.red=t,this},s.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},s.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},s.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},s.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},s.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},s.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},s.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},s.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},s.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function g(t,i){this.name=t,this.p=new s(i,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function v(){g.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){g.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){g.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){g.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=s._prime(t);this.m=i.p,this.prime=i}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}g.prototype._tmp=function(){var t=new s(null);return t.words=new Array(Math.ceil(this.n/13)),t},g.prototype.ireduce=function(t){var i,e=t;do{this.split(e,this.tmp),i=(e=(e=this.imulK(e)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):void 0!==e.strip?e.strip():e._strip(),e},g.prototype.split=function(t,i){t.iushrn(this.n,0,i)},g.prototype.imulK=function(t){return t.imul(this.k)},r(v,g),v.prototype.split=function(t,i){for(var e=Math.min(t.length,9),n=0;n<e;n++)i.words[n]=t.words[n];if(i.length=e,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(i.words[i.length++]=4194303&r,n=10;n<t.length;n++){var s=0|t.words[n];t.words[n-10]=(4194303&s)<<4|r>>>22,r=s}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},v.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,e=0;e<t.length;e++){var n=0|t.words[e];t.words[e]=67108863&(i+=977*n),i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(M,g),r(w,g),r(b,g),b.prototype.imulK=function(t){for(var i=0,e=0;e<t.length;e++){var n=19*(0|t.words[e])+i,r=67108863&n;n>>>=26,t.words[e]=r,i=n}return 0!==i&&(t.words[t.length++]=i),t},s._prime=function(t){if(y[t])return y[t];var i;if("k256"===t)i=new v;else if("p224"===t)i=new M;else if("p192"===t)i=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return y[t]=i,i},_.prototype._verify1=function(t){e(0===t.negative,"red works only with positives"),e(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){e(0==(t.negative|i.negative),"red works only with positives"),e(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var e=t.add(i);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var e=t.iadd(i);return e.cmp(this.m)>=0&&e.isub(this.m),e},_.prototype.sub=function(t,i){this._verify2(t,i);var e=t.sub(i);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var e=t.isub(i);return e.cmpn(0)<0&&e.iadd(this.m),e},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(e(i%2==1),3===i){var n=this.m.add(new s(1)).iushrn(2);return this.pow(t,n)}for(var r=this.m.subn(1),h=0;!r.isZero()&&0===r.andln(1);)h++,r.iushrn(1);e(!r.isZero());var o=new s(1).toRed(this),a=o.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new s(2*l*l).toRed(this);0!==this.pow(l,u).cmp(a);)l.redIAdd(a);for(var m=this.pow(l,r),d=this.pow(t,r.addn(1).iushrn(1)),f=this.pow(t,r),p=h;0!==f.cmp(o);){for(var c=f,y=0;0!==c.cmp(o);y++)c=c.redSqr();e(y<p);var g=this.pow(m,new s(1).iushln(p-y-1));d=d.redMul(g),m=g.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new s(1).toRed(this);if(0===i.cmpn(1))return t.clone();var e=new Array(16);e[0]=new s(1).toRed(this),e[1]=t;for(var n=2;n<e.length;n++)e[n]=this.mul(e[n-1],t);var r=e[0],h=0,o=0,a=i.bitLength()%26;for(0===a&&(a=26),n=i.length-1;n>=0;n--){for(var u=i.words[n],l=a-1;l>=0;l--){var m=u>>l&1;r!==e[0]&&(r=this.sqr(r)),0!==m||0!==h?(h<<=1,h|=m,(4==++o||0===n&&0===l)&&(r=this.mul(r,e[h]),o=0,h=0)):o=0}a=26}return r},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},s.mont=function(t){return new x(t)},r(x,_),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},x.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),s=r;return r.cmp(this.m)>=0?s=r.isub(this.m):r.cmpn(0)<0&&(s=r.iadd(this.m)),s._forceRed(this)},x.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new s(0)._forceRed(this);var e=t.mul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),h=r;return r.cmp(this.m)>=0?h=r.isub(this.m):r.cmpn(0)<0&&(h=r.iadd(this.m)),h._forceRed(this)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,a)}(e={path:void 0,exports:{},require:function(t,i){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),e.exports}(),l=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function m(t){return r.from(o.arrayBuffer(t))}const d=new h("secp256k1");function f(t){const i=(""+t).startsWith("0x")?t.slice(2):t,e=d.keyFromPublic(i,"hex").getPublic().encode("hex");return function(t){var i=t;const e=m(i=i.substring(2).toLowerCase());i=i.split("");for(var n=0;n<40;n+=2)e[n/2]>>4>=8&&(i[n]=i[n].toUpperCase()),(15&e[n/2])>=8&&(i[n+1]=i[n+1].toUpperCase());return"0x"+i.join("")}("0x"+m(r.from(e.slice(2),"hex")).slice(-20).toString("hex"))}const p="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",c=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function y(t){return r.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function g(t){const i="0x"+r.from(t).slice(0,32).toString("hex");return i+"0".repeat(66-i.length)}const v={Secp256k1SignatureAuthentication2018:g("sigAuth"),Secp256k1VerificationKey2018:g("veriKey")},M={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function w(t,i,e,n){const s=new u(Math.floor((new Date).getTime()/1e3)),h=[{id:t+"#owner",type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:i}],o=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#owner"}];e&&(h.push({id:t+"#ownerKey",type:"Secp256k1VerificationKey2018",owner:t,publicKeyHex:e}),o.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#ownerKey"}));let a=0;const l={},m={},d={};for(const i of n){const e=i.validTo,n=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(e&&e.gte(s)){if("DIDDelegateChanged"===i._eventName)switch(a++,y(i.delegateType)){case"sigAuth":l[n]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${a}`};case"veriKey":m[n]={id:`${t}#delegate-${a}`,type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:i.delegate}}else if("DIDAttributeChanged"===i._eventName){const e=y(i.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(e){const s=e[2],h=M[e[4]]||e[4],o=e[6];switch(e[1]){case"pub":{a++;const e={id:`${t}#delegate-${a}`,type:`${s}${h}`,owner:t};switch(o){case null:case void 0:case"hex":e.publicKeyHex=i.value.slice(2);break;case"base64":e.publicKeyBase64=r.from(i.value.slice(2),"hex").toString("base64");break;case"base58":e.publicKeyBase58=r.from(i.value.slice(2),"hex").toString("base58");break;case"pem":e.publicKeyPem=r.from(i.value.slice(2),"hex").toString();break;default:e.value=i.value}m[n]=e;break}case"svc":d[n]={type:s,serviceEndpoint:r.from(i.value.slice(2),"hex").toString()}}}}}else a>0&&("DIDDelegateChanged"===i._eventName||"DIDAttributeChanged"===i._eventName&&y(i.name).match(/^did\/pub\//))&&e.lt(s)&&a--,delete l[n],delete m[n],delete d[n]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:h.concat(Object.values(m)),authentication:o.concat(Object.values(l))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function b(e={}){const n=function(i={}){return i.provider?i.provider:i.web3?i.web3.currentProvider:i.rpcUrl?new t(i.rpcUrl):null}(e);if(null===n)return null;const r=new i(n),h=e.registry||p;return{eth:r,registryAddress:h,didReg:new s(r)(l).at(h)}}function _(t=[]){const i={};for(let e=0;e<t.length;e++){const n=t[e];i[n.name]=b(n),null===i[n.name]&&console.warn("invalid configuration for "+n.name)}return i}module.exports={REGISTRY:p,bytes32toString:y,stringToBytes32:g,delegateTypes:v,attrTypes:M,wrapDidDocument:w,getResolver:function(t={}){const i=e.logDecoder(l,!1),n={mainnet:b(t),..._(t.networks)};return function(t={},i={}){if((i.provider||i.web3||i.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(i&&i.networks)for(const e of i.networks)if(!t[e.name])throw new Error(`Ethereum provider configuration for ${e.name} was attempted but no valid configuration was provided`);let e=0;for(const i of Object.keys(t))null!==t[i]&&e++;if(0===e)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(n,t),{ethr:async function(t,e){const r=e.id.match(c);if(!r)throw new Error("Not a valid ethr DID: "+t);const s=r[2],h=r[1]?r[1].slice(0,-1):"mainnet";if(!n[h])throw new Error("No conf for networkId: "+h);const{owner:o,history:a,publicKey:u}=await async function(t,e){const r=[];let{address:s,publicKey:h}=(o=t).length>42?{address:f(o),publicKey:o}:{address:o};var o;let a=s,u=await(async(t,i)=>{const e=await n[i].didReg.changed(t);if(e)return e[0]})(s,e);if(u){const t=""+(await n[e].didReg.identityOwner(s))[0];t.toLowerCase()!==a.toLowerCase()&&(h=null),a=t}for(;u;){const t=u,h=await n[e].eth.getLogs({address:n[e].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:u,toBlock:u}),o=i(h);u=void 0;for(const i of o)r.unshift(i),i.previousChange.lt(t)&&(u=i.previousChange)}return{owner:a,history:r,publicKey:h}}(s,h);return w(t,o,u,a)}}},identifierMatcher:c}; | ||
import t from"ethjs-provider-http";import i from"ethjs-query";import e from"ethjs-abi";import n,{Buffer as r}from"buffer";import s from"ethjs-contract";import{ec as o}from"elliptic";import{keccak_256 as h}from"js-sha3";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u=function(t,i,e){return function(t){!function(t,i){function e(t,i){if(!t)throw new Error(i||"Assertion failed")}function r(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}function s(t,i,e){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==i&&"be"!==i||(e=i,i=10),this._init(t||0,i||10,e||"be"))}var o;"object"==typeof t?t.exports=s:i.BN=s,s.BN=s,s.wordSize=26;try{o=n.Buffer}catch(t){}function h(t,i,e){for(var n=0,r=Math.min(t.length,e),s=i;s<r;s++){var o=t.charCodeAt(s)-48;n<<=4,n|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return n}function a(t,i,e,n){for(var r=0,s=Math.min(t.length,e),o=i;o<s;o++){var h=t.charCodeAt(o)-48;r*=n,r+=h>=49?h-49+10:h>=17?h-17+10:h}return r}s.isBN=function(t){return t instanceof s||null!==t&&"object"==typeof t&&t.constructor.wordSize===s.wordSize&&Array.isArray(t.words)},s.max=function(t,i){return t.cmp(i)>0?t:i},s.min=function(t,i){return t.cmp(i)<0?t:i},s.prototype._init=function(t,i,n){if("number"==typeof t)return this._initNumber(t,i,n);if("object"==typeof t)return this._initArray(t,i,n);"hex"===i&&(i=16),e(i===(0|i)&&i>=2&&i<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===i?this._parseHex(t,r):this._parseBase(t,i,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),i,n)},s.prototype._initNumber=function(t,i,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),i,n)},s.prototype._initArray=function(t,i,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var s,o,h=0;if("be"===n)for(r=t.length-1,s=0;r>=0;r-=3)this.words[s]|=(o=t[r]|t[r-1]<<8|t[r-2]<<16)<<h&67108863,this.words[s+1]=o>>>26-h&67108863,(h+=24)>=26&&(h-=26,s++);else if("le"===n)for(r=0,s=0;r<t.length;r+=3)this.words[s]|=(o=t[r]|t[r+1]<<8|t[r+2]<<16)<<h&67108863,this.words[s+1]=o>>>26-h&67108863,(h+=24)>=26&&(h-=26,s++);return this.strip()},s.prototype._parseHex=function(t,i){this.length=Math.ceil((t.length-i)/6),this.words=new Array(this.length);for(var e=0;e<this.length;e++)this.words[e]=0;var n,r,s=0;for(e=t.length-6,n=0;e>=i;e-=6)r=h(t,e,e+6),this.words[n]|=r<<s&67108863,this.words[n+1]|=r>>>26-s&4194303,(s+=24)>=26&&(s-=26,n++);e+6!==i&&(r=h(t,i,e+6),this.words[n]|=r<<s&67108863,this.words[n+1]|=r>>>26-s&4194303),this.strip()},s.prototype._parseBase=function(t,i,e){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=i)n++;n--,r=r/i|0;for(var s=t.length-e,o=s%n,h=Math.min(s,s-o)+e,u=0,l=e;l<h;l+=n)u=a(t,l,l+n,i),this.imuln(r),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var m=1;for(u=a(t,l,t.length,i),l=0;l<o;l++)m*=i;this.imuln(m),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},s.prototype.copy=function(t){t.words=new Array(this.length);for(var i=0;i<this.length;i++)t.words[i]=this.words[i];t.length=this.length,t.negative=this.negative,t.red=this.red},s.prototype.clone=function(){var t=new s(null);return this.copy(t),t},s.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var u=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,e){e.negative=i.negative^t.negative;var n=t.length+i.length|0;e.length=n,n=n-1|0;var r=0|t.words[0],s=0|i.words[0],o=r*s,h=o/67108864|0;e.words[0]=67108863&o;for(var a=1;a<n;a++){for(var u=h>>>26,l=67108863&h,m=Math.min(a,i.length-1),d=Math.max(0,a-t.length+1);d<=m;d++)u+=(o=(r=0|t.words[a-d|0])*(s=0|i.words[d])+l)/67108864|0,l=67108863&o;e.words[a]=0|l,h=0|u}return 0!==h?e.words[a]=0|h:e.length--,e.strip()}s.prototype.toString=function(t,i){var n;if(i=0|i||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,s=0,o=0;o<this.length;o++){var h=this.words[o],a=(16777215&(h<<r|s)).toString(16);n=0!=(s=h>>>24-r&16777215)||o!==this.length-1?u[6-a.length]+a+n:a+n,(r+=2)>=26&&(r-=26,o--)}for(0!==s&&(n=s.toString(16)+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:u[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%i!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(t,i){return e(void 0!==o),this.toArrayLike(o,t,i)},s.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},s.prototype.toArrayLike=function(t,i,n){var r=this.byteLength(),s=n||Math.max(1,r);e(r<=s,"byte array longer than desired length"),e(s>0,"Requested array length <= 0"),this.strip();var o,h,a="le"===i,u=new t(s),l=this.clone();if(a){for(h=0;!l.isZero();h++)o=l.andln(255),l.iushrn(8),u[h]=o;for(;h<s;h++)u[h]=0}else{for(h=0;h<s-r;h++)u[h]=0;for(h=0;!l.isZero();h++)o=l.andln(255),l.iushrn(8),u[s-h-1]=o}return u},s.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var i=t,e=0;return i>=4096&&(e+=13,i>>>=13),i>=64&&(e+=7,i>>>=7),i>=8&&(e+=4,i>>>=4),i>=2&&(e+=2,i>>>=2),e+i},s.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,e=0;return 0==(8191&i)&&(e+=13,i>>>=13),0==(127&i)&&(e+=7,i>>>=7),0==(15&i)&&(e+=4,i>>>=4),0==(3&i)&&(e+=2,i>>>=2),0==(1&i)&&e++,e},s.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,i=0;i<this.length;i++){var e=this._zeroBits(this.words[i]);if(t+=e,26!==e)break}return t},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},s.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return 0!==this.negative},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var i=0;i<t.length;i++)this.words[i]=this.words[i]|t.words[i];return this.strip()},s.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},s.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var i;i=this.length>t.length?t:this;for(var e=0;e<i.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=i.length,this.strip()},s.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},s.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var i,e;this.length>t.length?(i=this,e=t):(i=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=i.words[n]^e.words[n];if(this!==i)for(;n<i.length;n++)this.words[n]=i.words[n];return this.length=i.length,this.strip()},s.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},s.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var i=0|Math.ceil(t/26),n=t%26;this._expand(i),n>0&&i--;for(var r=0;r<i;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},s.prototype.notn=function(t){return this.clone().inotn(t)},s.prototype.setn=function(t,i){e("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=i?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},s.prototype.iadd=function(t){var i,e,n;if(0!==this.negative&&0===t.negative)return this.negative=0,i=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,i=this.isub(t),t.negative=1,i._normSign();this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0,s=0;s<n.length;s++)this.words[s]=67108863&(i=(0|e.words[s])+(0|n.words[s])+r),r=i>>>26;for(;0!==r&&s<e.length;s++)this.words[s]=67108863&(i=(0|e.words[s])+r),r=i>>>26;if(this.length=e.length,0!==r)this.words[this.length]=r,this.length++;else if(e!==this)for(;s<e.length;s++)this.words[s]=e.words[s];return this},s.prototype.add=function(t){var i;return 0!==t.negative&&0===this.negative?(t.negative=0,i=this.sub(t),t.negative^=1,i):0===t.negative&&0!==this.negative?(this.negative=0,i=t.sub(this),this.negative=1,i):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var i=this.iadd(t);return t.negative=1,i._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(e=this,n=t):(e=t,n=this);for(var s=0,o=0;o<n.length;o++)s=(i=(0|e.words[o])-(0|n.words[o])+s)>>26,this.words[o]=67108863&i;for(;0!==s&&o<e.length;o++)s=(i=(0|e.words[o])+s)>>26,this.words[o]=67108863&i;if(0===s&&o<e.length&&e!==this)for(;o<e.length;o++)this.words[o]=e.words[o];return this.length=Math.max(this.length,o),e!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,i,e){var n,r,s,o=t.words,h=i.words,a=e.words,u=0,l=0|o[0],m=8191&l,d=l>>>13,f=0|o[1],p=8191&f,c=f>>>13,y=0|o[2],g=8191&y,v=y>>>13,M=0|o[3],w=8191&M,b=M>>>13,_=0|o[4],x=8191&_,k=_>>>13,S=0|o[5],A=8191&S,R=S>>>13,D=0|o[6],K=8191&D,q=D>>>13,B=0|o[7],T=8191&B,Z=B>>>13,N=0|o[8],I=8191&N,E=N>>>13,O=0|o[9],C=8191&O,L=O>>>13,j=0|h[0],$=8191&j,z=j>>>13,V=0|h[1],P=8191&V,F=V>>>13,U=0|h[2],H=8191&U,G=U>>>13,J=0|h[3],W=8191&J,Y=J>>>13,Q=0|h[4],X=8191&Q,tt=Q>>>13,it=0|h[5],et=8191&it,nt=it>>>13,rt=0|h[6],st=8191&rt,ot=rt>>>13,ht=0|h[7],at=8191&ht,ut=ht>>>13,lt=0|h[8],mt=8191<,dt=lt>>>13,ft=0|h[9],pt=8191&ft,ct=ft>>>13;e.negative=t.negative^i.negative,e.length=19;var yt=(u+(n=Math.imul(m,$))|0)+((8191&(r=(r=Math.imul(m,z))+Math.imul(d,$)|0))<<13)|0;u=((s=Math.imul(d,z))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,$),r=(r=Math.imul(p,z))+Math.imul(c,$)|0,s=Math.imul(c,z);var gt=(u+(n=n+Math.imul(m,P)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,P)|0))<<13)|0;u=((s=s+Math.imul(d,F)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(g,$),r=(r=Math.imul(g,z))+Math.imul(v,$)|0,s=Math.imul(v,z),n=n+Math.imul(p,P)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,P)|0,s=s+Math.imul(c,F)|0;var vt=(u+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;u=((s=s+Math.imul(d,G)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(w,$),r=(r=Math.imul(w,z))+Math.imul(b,$)|0,s=Math.imul(b,z),n=n+Math.imul(g,P)|0,r=(r=r+Math.imul(g,F)|0)+Math.imul(v,P)|0,s=s+Math.imul(v,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,s=s+Math.imul(c,G)|0;var Mt=(u+(n=n+Math.imul(m,W)|0)|0)+((8191&(r=(r=r+Math.imul(m,Y)|0)+Math.imul(d,W)|0))<<13)|0;u=((s=s+Math.imul(d,Y)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(x,$),r=(r=Math.imul(x,z))+Math.imul(k,$)|0,s=Math.imul(k,z),n=n+Math.imul(w,P)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,P)|0,s=s+Math.imul(b,F)|0,n=n+Math.imul(g,H)|0,r=(r=r+Math.imul(g,G)|0)+Math.imul(v,H)|0,s=s+Math.imul(v,G)|0,n=n+Math.imul(p,W)|0,r=(r=r+Math.imul(p,Y)|0)+Math.imul(c,W)|0,s=s+Math.imul(c,Y)|0;var wt=(u+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,$),r=(r=Math.imul(A,z))+Math.imul(R,$)|0,s=Math.imul(R,z),n=n+Math.imul(x,P)|0,r=(r=r+Math.imul(x,F)|0)+Math.imul(k,P)|0,s=s+Math.imul(k,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,G)|0,n=n+Math.imul(g,W)|0,r=(r=r+Math.imul(g,Y)|0)+Math.imul(v,W)|0,s=s+Math.imul(v,Y)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,s=s+Math.imul(c,tt)|0;var bt=(u+(n=n+Math.imul(m,et)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,et)|0))<<13)|0;u=((s=s+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(K,$),r=(r=Math.imul(K,z))+Math.imul(q,$)|0,s=Math.imul(q,z),n=n+Math.imul(A,P)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,P)|0,s=s+Math.imul(R,F)|0,n=n+Math.imul(x,H)|0,r=(r=r+Math.imul(x,G)|0)+Math.imul(k,H)|0,s=s+Math.imul(k,G)|0,n=n+Math.imul(w,W)|0,r=(r=r+Math.imul(w,Y)|0)+Math.imul(b,W)|0,s=s+Math.imul(b,Y)|0,n=n+Math.imul(g,X)|0,r=(r=r+Math.imul(g,tt)|0)+Math.imul(v,X)|0,s=s+Math.imul(v,tt)|0,n=n+Math.imul(p,et)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,et)|0,s=s+Math.imul(c,nt)|0;var _t=(u+(n=n+Math.imul(m,st)|0)|0)+((8191&(r=(r=r+Math.imul(m,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(T,$),r=(r=Math.imul(T,z))+Math.imul(Z,$)|0,s=Math.imul(Z,z),n=n+Math.imul(K,P)|0,r=(r=r+Math.imul(K,F)|0)+Math.imul(q,P)|0,s=s+Math.imul(q,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,s=s+Math.imul(R,G)|0,n=n+Math.imul(x,W)|0,r=(r=r+Math.imul(x,Y)|0)+Math.imul(k,W)|0,s=s+Math.imul(k,Y)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,s=s+Math.imul(b,tt)|0,n=n+Math.imul(g,et)|0,r=(r=r+Math.imul(g,nt)|0)+Math.imul(v,et)|0,s=s+Math.imul(v,nt)|0,n=n+Math.imul(p,st)|0,r=(r=r+Math.imul(p,ot)|0)+Math.imul(c,st)|0,s=s+Math.imul(c,ot)|0;var xt=(u+(n=n+Math.imul(m,at)|0)|0)+((8191&(r=(r=r+Math.imul(m,ut)|0)+Math.imul(d,at)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(I,$),r=(r=Math.imul(I,z))+Math.imul(E,$)|0,s=Math.imul(E,z),n=n+Math.imul(T,P)|0,r=(r=r+Math.imul(T,F)|0)+Math.imul(Z,P)|0,s=s+Math.imul(Z,F)|0,n=n+Math.imul(K,H)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(q,H)|0,s=s+Math.imul(q,G)|0,n=n+Math.imul(A,W)|0,r=(r=r+Math.imul(A,Y)|0)+Math.imul(R,W)|0,s=s+Math.imul(R,Y)|0,n=n+Math.imul(x,X)|0,r=(r=r+Math.imul(x,tt)|0)+Math.imul(k,X)|0,s=s+Math.imul(k,tt)|0,n=n+Math.imul(w,et)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,et)|0,s=s+Math.imul(b,nt)|0,n=n+Math.imul(g,st)|0,r=(r=r+Math.imul(g,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,n=n+Math.imul(p,at)|0,r=(r=r+Math.imul(p,ut)|0)+Math.imul(c,at)|0,s=s+Math.imul(c,ut)|0;var kt=(u+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(C,$),r=(r=Math.imul(C,z))+Math.imul(L,$)|0,s=Math.imul(L,z),n=n+Math.imul(I,P)|0,r=(r=r+Math.imul(I,F)|0)+Math.imul(E,P)|0,s=s+Math.imul(E,F)|0,n=n+Math.imul(T,H)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(Z,H)|0,s=s+Math.imul(Z,G)|0,n=n+Math.imul(K,W)|0,r=(r=r+Math.imul(K,Y)|0)+Math.imul(q,W)|0,s=s+Math.imul(q,Y)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,s=s+Math.imul(R,tt)|0,n=n+Math.imul(x,et)|0,r=(r=r+Math.imul(x,nt)|0)+Math.imul(k,et)|0,s=s+Math.imul(k,nt)|0,n=n+Math.imul(w,st)|0,r=(r=r+Math.imul(w,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,n=n+Math.imul(g,at)|0,r=(r=r+Math.imul(g,ut)|0)+Math.imul(v,at)|0,s=s+Math.imul(v,ut)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,s=s+Math.imul(c,dt)|0;var St=(u+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;u=((s=s+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(C,P),r=(r=Math.imul(C,F))+Math.imul(L,P)|0,s=Math.imul(L,F),n=n+Math.imul(I,H)|0,r=(r=r+Math.imul(I,G)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,G)|0,n=n+Math.imul(T,W)|0,r=(r=r+Math.imul(T,Y)|0)+Math.imul(Z,W)|0,s=s+Math.imul(Z,Y)|0,n=n+Math.imul(K,X)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(q,X)|0,s=s+Math.imul(q,tt)|0,n=n+Math.imul(A,et)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,et)|0,s=s+Math.imul(R,nt)|0,n=n+Math.imul(x,st)|0,r=(r=r+Math.imul(x,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,n=n+Math.imul(w,at)|0,r=(r=r+Math.imul(w,ut)|0)+Math.imul(b,at)|0,s=s+Math.imul(b,ut)|0,n=n+Math.imul(g,mt)|0,r=(r=r+Math.imul(g,dt)|0)+Math.imul(v,mt)|0,s=s+Math.imul(v,dt)|0;var At=(u+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;u=((s=s+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(C,H),r=(r=Math.imul(C,G))+Math.imul(L,H)|0,s=Math.imul(L,G),n=n+Math.imul(I,W)|0,r=(r=r+Math.imul(I,Y)|0)+Math.imul(E,W)|0,s=s+Math.imul(E,Y)|0,n=n+Math.imul(T,X)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(Z,X)|0,s=s+Math.imul(Z,tt)|0,n=n+Math.imul(K,et)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(q,et)|0,s=s+Math.imul(q,nt)|0,n=n+Math.imul(A,st)|0,r=(r=r+Math.imul(A,ot)|0)+Math.imul(R,st)|0,s=s+Math.imul(R,ot)|0,n=n+Math.imul(x,at)|0,r=(r=r+Math.imul(x,ut)|0)+Math.imul(k,at)|0,s=s+Math.imul(k,ut)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,s=s+Math.imul(b,dt)|0;var Rt=(u+(n=n+Math.imul(g,pt)|0)|0)+((8191&(r=(r=r+Math.imul(g,ct)|0)+Math.imul(v,pt)|0))<<13)|0;u=((s=s+Math.imul(v,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(C,W),r=(r=Math.imul(C,Y))+Math.imul(L,W)|0,s=Math.imul(L,Y),n=n+Math.imul(I,X)|0,r=(r=r+Math.imul(I,tt)|0)+Math.imul(E,X)|0,s=s+Math.imul(E,tt)|0,n=n+Math.imul(T,et)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(Z,et)|0,s=s+Math.imul(Z,nt)|0,n=n+Math.imul(K,st)|0,r=(r=r+Math.imul(K,ot)|0)+Math.imul(q,st)|0,s=s+Math.imul(q,ot)|0,n=n+Math.imul(A,at)|0,r=(r=r+Math.imul(A,ut)|0)+Math.imul(R,at)|0,s=s+Math.imul(R,ut)|0,n=n+Math.imul(x,mt)|0,r=(r=r+Math.imul(x,dt)|0)+Math.imul(k,mt)|0,s=s+Math.imul(k,dt)|0;var Dt=(u+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;u=((s=s+Math.imul(b,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(C,X),r=(r=Math.imul(C,tt))+Math.imul(L,X)|0,s=Math.imul(L,tt),n=n+Math.imul(I,et)|0,r=(r=r+Math.imul(I,nt)|0)+Math.imul(E,et)|0,s=s+Math.imul(E,nt)|0,n=n+Math.imul(T,st)|0,r=(r=r+Math.imul(T,ot)|0)+Math.imul(Z,st)|0,s=s+Math.imul(Z,ot)|0,n=n+Math.imul(K,at)|0,r=(r=r+Math.imul(K,ut)|0)+Math.imul(q,at)|0,s=s+Math.imul(q,ut)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,s=s+Math.imul(R,dt)|0;var Kt=(u+(n=n+Math.imul(x,pt)|0)|0)+((8191&(r=(r=r+Math.imul(x,ct)|0)+Math.imul(k,pt)|0))<<13)|0;u=((s=s+Math.imul(k,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(C,et),r=(r=Math.imul(C,nt))+Math.imul(L,et)|0,s=Math.imul(L,nt),n=n+Math.imul(I,st)|0,r=(r=r+Math.imul(I,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,n=n+Math.imul(T,at)|0,r=(r=r+Math.imul(T,ut)|0)+Math.imul(Z,at)|0,s=s+Math.imul(Z,ut)|0,n=n+Math.imul(K,mt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(q,mt)|0,s=s+Math.imul(q,dt)|0;var qt=(u+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;u=((s=s+Math.imul(R,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(C,st),r=(r=Math.imul(C,ot))+Math.imul(L,st)|0,s=Math.imul(L,ot),n=n+Math.imul(I,at)|0,r=(r=r+Math.imul(I,ut)|0)+Math.imul(E,at)|0,s=s+Math.imul(E,ut)|0,n=n+Math.imul(T,mt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(Z,mt)|0,s=s+Math.imul(Z,dt)|0;var Bt=(u+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,ct)|0)+Math.imul(q,pt)|0))<<13)|0;u=((s=s+Math.imul(q,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(C,at),r=(r=Math.imul(C,ut))+Math.imul(L,at)|0,s=Math.imul(L,ut),n=n+Math.imul(I,mt)|0,r=(r=r+Math.imul(I,dt)|0)+Math.imul(E,mt)|0,s=s+Math.imul(E,dt)|0;var Tt=(u+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,ct)|0)+Math.imul(Z,pt)|0))<<13)|0;u=((s=s+Math.imul(Z,ct)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(C,mt),r=(r=Math.imul(C,dt))+Math.imul(L,mt)|0,s=Math.imul(L,dt);var Zt=(u+(n=n+Math.imul(I,pt)|0)|0)+((8191&(r=(r=r+Math.imul(I,ct)|0)+Math.imul(E,pt)|0))<<13)|0;u=((s=s+Math.imul(E,ct)|0)+(r>>>13)|0)+(Zt>>>26)|0,Zt&=67108863;var Nt=(u+(n=Math.imul(C,pt))|0)+((8191&(r=(r=Math.imul(C,ct))+Math.imul(L,pt)|0))<<13)|0;return u=((s=Math.imul(L,ct))+(r>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,a[0]=yt,a[1]=gt,a[2]=vt,a[3]=Mt,a[4]=wt,a[5]=bt,a[6]=_t,a[7]=xt,a[8]=kt,a[9]=St,a[10]=At,a[11]=Rt,a[12]=Dt,a[13]=Kt,a[14]=qt,a[15]=Bt,a[16]=Tt,a[17]=Zt,a[18]=Nt,0!==u&&(a[19]=u,e.length++),e};function p(t,i,e){return(new c).mulp(t,i,e)}function c(t,i){this.x=t,this.y=i}Math.imul||(f=d),s.prototype.mulTo=function(t,i){var e=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,i):e<63?d(this,t,i):e<1024?function(t,i,e){e.negative=i.negative^t.negative,e.length=t.length+i.length;for(var n=0,r=0,s=0;s<e.length-1;s++){var o=r;r=0;for(var h=67108863&n,a=Math.min(s,i.length-1),u=Math.max(0,s-t.length+1);u<=a;u++){var l=(0|t.words[s-u])*(0|i.words[u]),m=67108863&l;h=67108863&(m=m+h|0),r+=(o=(o=o+(l/67108864|0)|0)+(m>>>26)|0)>>>26,o&=67108863}e.words[s]=h,n=o,o=r}return 0!==n?e.words[s]=n:e.length--,e.strip()}(this,t,i):p(this,t,i)},c.prototype.makeRBT=function(t){for(var i=new Array(t),e=s.prototype._countBits(t)-1,n=0;n<t;n++)i[n]=this.revBin(n,e,t);return i},c.prototype.revBin=function(t,i,e){if(0===t||t===e-1)return t;for(var n=0,r=0;r<i;r++)n|=(1&t)<<i-r-1,t>>=1;return n},c.prototype.permute=function(t,i,e,n,r,s){for(var o=0;o<s;o++)n[o]=i[t[o]],r[o]=e[t[o]]},c.prototype.transform=function(t,i,e,n,r,s){this.permute(s,t,i,e,n,r);for(var o=1;o<r;o<<=1)for(var h=o<<1,a=Math.cos(2*Math.PI/h),u=Math.sin(2*Math.PI/h),l=0;l<r;l+=h)for(var m=a,d=u,f=0;f<o;f++){var p=e[l+f],c=n[l+f],y=e[l+f+o],g=n[l+f+o],v=m*y-d*g;g=m*g+d*y,e[l+f]=p+(y=v),n[l+f]=c+g,e[l+f+o]=p-y,n[l+f+o]=c-g,f!==h&&(v=a*m-u*d,d=a*d+u*m,m=v)}},c.prototype.guessLen13b=function(t,i){var e=1|Math.max(i,t),n=1&e,r=0;for(e=e/2|0;e;e>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,i,e){if(!(e<=1))for(var n=0;n<e/2;n++){var r=t[n];t[n]=t[e-n-1],t[e-n-1]=r,r=i[n],i[n]=-i[e-n-1],i[e-n-1]=-r}},c.prototype.normalize13b=function(t,i){for(var e=0,n=0;n<i/2;n++){var r=8192*Math.round(t[2*n+1]/i)+Math.round(t[2*n]/i)+e;t[n]=67108863&r,e=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,i,n,r){for(var s=0,o=0;o<i;o++)n[2*o]=8191&(s+=0|t[o]),n[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*i;o<r;++o)n[o]=0;e(0===s),e(0==(-8192&s))},c.prototype.stub=function(t){for(var i=new Array(t),e=0;e<t;e++)i[e]=0;return i},c.prototype.mulp=function(t,i,e){var n=2*this.guessLen13b(t.length,i.length),r=this.makeRBT(n),s=this.stub(n),o=new Array(n),h=new Array(n),a=new Array(n),u=new Array(n),l=new Array(n),m=new Array(n),d=e.words;d.length=n,this.convert13b(t.words,t.length,o,n),this.convert13b(i.words,i.length,u,n),this.transform(o,s,h,a,n,r),this.transform(u,s,l,m,n,r);for(var f=0;f<n;f++){var p=h[f]*l[f]-a[f]*m[f];a[f]=h[f]*m[f]+a[f]*l[f],h[f]=p}return this.conjugate(h,a,n),this.transform(h,a,d,s,n,r),this.conjugate(d,s,n),this.normalize13b(d,n),e.negative=t.negative^i.negative,e.length=t.length+i.length,e.strip()},s.prototype.mul=function(t){var i=new s(null);return i.words=new Array(this.length+t.length),this.mulTo(t,i)},s.prototype.mulf=function(t){var i=new s(null);return i.words=new Array(this.length+t.length),p(this,t,i)},s.prototype.imul=function(t){return this.clone().mulTo(t,this)},s.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var i=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,s=(67108863&r)+(67108863&i);i>>=26,i+=r/67108864|0,i+=s>>>26,this.words[n]=67108863&s}return 0!==i&&(this.words[n]=i,this.length++),this},s.prototype.muln=function(t){return this.clone().imuln(t)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(t){var i=function(t){for(var i=new Array(t.bitLength()),e=0;e<i.length;e++){var n=e%26;i[e]=(t.words[e/26|0]&1<<n)>>>n}return i}(t);if(0===i.length)return new s(1);for(var e=this,n=0;n<i.length&&0===i[n];n++,e=e.sqr());if(++n<i.length)for(var r=e.sqr();n<i.length;n++,r=r.sqr())0!==i[n]&&(e=e.mul(r));return e},s.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var i,n=t%26,r=(t-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var o=0;for(i=0;i<this.length;i++){var h=this.words[i]&s;this.words[i]=(0|this.words[i])-h<<n|o,o=h>>>26-n}o&&(this.words[i]=o,this.length++)}if(0!==r){for(i=this.length-1;i>=0;i--)this.words[i+r]=this.words[i];for(i=0;i<r;i++)this.words[i]=0;this.length+=r}return this.strip()},s.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},s.prototype.iushrn=function(t,i,n){var r;e("number"==typeof t&&t>=0),r=i?(i-i%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),h=67108863^67108863>>>s<<s,a=n;if(r-=o,r=Math.max(0,r),a){for(var u=0;u<o;u++)a.words[u]=this.words[u];a.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=r);u--){var m=0|this.words[u];this.words[u]=l<<26-s|m>>>s,l=m&h}return a&&0!==l&&(a.words[a.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.ishrn=function(t,i,n){return e(0===this.negative),this.iushrn(t,i,n)},s.prototype.shln=function(t){return this.clone().ishln(t)},s.prototype.ushln=function(t){return this.clone().iushln(t)},s.prototype.shrn=function(t){return this.clone().ishrn(t)},s.prototype.ushrn=function(t){return this.clone().iushrn(t)},s.prototype.testn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return!(this.length<=n||!(this.words[n]&1<<i))},s.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var i=t%26,n=(t-i)/26;return e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==i&&n++,this.length=Math.min(n,this.length),0!==i&&(this.words[this.length-1]&=67108863^67108863>>>i<<i),this.strip())},s.prototype.maskn=function(t){return this.clone().imaskn(t)},s.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},s.prototype._iaddn=function(t){this.words[0]+=t;for(var i=0;i<this.length&&this.words[i]>=67108864;i++)this.words[i]-=67108864,i===this.length-1?this.words[i+1]=1:this.words[i+1]++;return this.length=Math.max(this.length,i+1),this},s.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var i=0;i<this.length&&this.words[i]<0;i++)this.words[i]+=67108864,this.words[i+1]-=1;return this.strip()},s.prototype.addn=function(t){return this.clone().iaddn(t)},s.prototype.subn=function(t){return this.clone().isubn(t)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(t,i,n){var r,s;this._expand(t.length+n);var o=0;for(r=0;r<t.length;r++){s=(0|this.words[r+n])+o;var h=(0|t.words[r])*i;o=((s-=67108863&h)>>26)-(h/67108864|0),this.words[r+n]=67108863&s}for(;r<this.length-n;r++)o=(s=(0|this.words[r+n])+o)>>26,this.words[r+n]=67108863&s;if(0===o)return this.strip();for(e(-1===o),o=0,r=0;r<this.length;r++)o=(s=-(0|this.words[r])+o)>>26,this.words[r]=67108863&s;return this.negative=1,this.strip()},s.prototype._wordDiv=function(t,i){var e,n=this.clone(),r=t,o=0|r.words[r.length-1];0!=(e=26-this._countBits(o))&&(r=r.ushln(e),n.iushln(e),o=0|r.words[r.length-1]);var h,a=n.length-r.length;if("mod"!==i){(h=new s(null)).length=a+1,h.words=new Array(h.length);for(var u=0;u<h.length;u++)h.words[u]=0}var l=n.clone()._ishlnsubmul(r,1,a);0===l.negative&&(n=l,h&&(h.words[a]=1));for(var m=a-1;m>=0;m--){var d=67108864*(0|n.words[r.length+m])+(0|n.words[r.length+m-1]);for(d=Math.min(d/o|0,67108863),n._ishlnsubmul(r,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(r,1,m),n.isZero()||(n.negative^=1);h&&(h.words[m]=d)}return h&&h.strip(),n.strip(),"div"!==i&&0!==e&&n.iushrn(e),{div:h||null,mod:n}},s.prototype.divmod=function(t,i,n){return e(!t.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,i),"mod"!==i&&(r=h.div.neg()),"div"!==i&&(o=h.mod.neg(),n&&0!==o.negative&&o.iadd(t)),{div:r,mod:o}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),i),"mod"!==i&&(r=h.div.neg()),{div:r,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),i),"div"!==i&&(o=h.mod.neg(),n&&0!==o.negative&&o.isub(t)),{div:h.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new s(0),mod:this}:1===t.length?"div"===i?{div:this.divn(t.words[0]),mod:null}:"mod"===i?{div:null,mod:new s(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new s(this.modn(t.words[0]))}:this._wordDiv(t,i);var r,o,h},s.prototype.div=function(t){return this.divmod(t,"div",!1).div},s.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},s.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},s.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var e=0!==i.div.negative?i.mod.isub(t):i.mod,n=t.ushrn(1),r=t.andln(1),s=e.cmp(n);return s<0||1===r&&0===s?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},s.prototype.modn=function(t){e(t<=67108863);for(var i=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(i*n+(0|this.words[r]))%t;return n},s.prototype.idivn=function(t){e(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*i;this.words[n]=r/t|0,i=r%t}return this.strip()},s.prototype.divn=function(t){return this.clone().idivn(t)},s.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r=new s(1),o=new s(0),h=new s(0),a=new s(1),u=0;i.isEven()&&n.isEven();)i.iushrn(1),n.iushrn(1),++u;for(var l=n.clone(),m=i.clone();!i.isZero();){for(var d=0,f=1;0==(i.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(i.iushrn(d);d-- >0;)(r.isOdd()||o.isOdd())&&(r.iadd(l),o.isub(m)),r.iushrn(1),o.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(h.isOdd()||a.isOdd())&&(h.iadd(l),a.isub(m)),h.iushrn(1),a.iushrn(1);i.cmp(n)>=0?(i.isub(n),r.isub(h),o.isub(a)):(n.isub(i),h.isub(r),a.isub(o))}return{a:h,b:a,gcd:n.iushln(u)}},s.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var i=this,n=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var r,o=new s(1),h=new s(0),a=n.clone();i.cmpn(1)>0&&n.cmpn(1)>0;){for(var u=0,l=1;0==(i.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(i.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(a),o.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)h.isOdd()&&h.iadd(a),h.iushrn(1);i.cmp(n)>=0?(i.isub(n),o.isub(h)):(n.isub(i),h.isub(o))}return(r=0===i.cmpn(1)?o:h).cmpn(0)<0&&r.iadd(t),r},s.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),e=t.clone();i.negative=0,e.negative=0;for(var n=0;i.isEven()&&e.isEven();n++)i.iushrn(1),e.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;e.isEven();)e.iushrn(1);var r=i.cmp(e);if(r<0){var s=i;i=e,e=s}else if(0===r||0===e.cmpn(1))break;i.isub(e)}return e.iushln(n)},s.prototype.invm=function(t){return this.egcd(t).a.umod(t)},s.prototype.isEven=function(){return 0==(1&this.words[0])},s.prototype.isOdd=function(){return 1==(1&this.words[0])},s.prototype.andln=function(t){return this.words[0]&t},s.prototype.bincn=function(t){e("number"==typeof t);var i=t%26,n=(t-i)/26,r=1<<i;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var s=r,o=n;0!==s&&o<this.length;o++){var h=0|this.words[o];s=(h+=s)>>>26,this.words[o]=h&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(t){var i,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)i=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var r=0|this.words[0];i=r===t?0:r<t?-1:1}return 0!==this.negative?0|-i:i},s.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var i=this.ucmp(t);return 0!==this.negative?0|-i:i},s.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var i=0,e=this.length-1;e>=0;e--){var n=0|this.words[e],r=0|t.words[e];if(n!==r){n<r?i=-1:n>r&&(i=1);break}}return i},s.prototype.gtn=function(t){return 1===this.cmpn(t)},s.prototype.gt=function(t){return 1===this.cmp(t)},s.prototype.gten=function(t){return this.cmpn(t)>=0},s.prototype.gte=function(t){return this.cmp(t)>=0},s.prototype.ltn=function(t){return-1===this.cmpn(t)},s.prototype.lt=function(t){return-1===this.cmp(t)},s.prototype.lten=function(t){return this.cmpn(t)<=0},s.prototype.lte=function(t){return this.cmp(t)<=0},s.prototype.eqn=function(t){return 0===this.cmpn(t)},s.prototype.eq=function(t){return 0===this.cmp(t)},s.red=function(t){return new _(t)},s.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},s.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(t){return this.red=t,this},s.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},s.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},s.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},s.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},s.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},s.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},s.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},s.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},s.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function g(t,i){this.name=t,this.p=new s(i,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function v(){g.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){g.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){g.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){g.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var i=s._prime(t);this.m=i.p,this.prime=i}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}g.prototype._tmp=function(){var t=new s(null);return t.words=new Array(Math.ceil(this.n/13)),t},g.prototype.ireduce=function(t){var i,e=t;do{this.split(e,this.tmp),i=(e=(e=this.imulK(e)).iadd(this.tmp)).bitLength()}while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return 0===n?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):void 0!==e.strip?e.strip():e._strip(),e},g.prototype.split=function(t,i){t.iushrn(this.n,0,i)},g.prototype.imulK=function(t){return t.imul(this.k)},r(v,g),v.prototype.split=function(t,i){for(var e=Math.min(t.length,9),n=0;n<e;n++)i.words[n]=t.words[n];if(i.length=e,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(i.words[i.length++]=4194303&r,n=10;n<t.length;n++){var s=0|t.words[n];t.words[n-10]=(4194303&s)<<4|r>>>22,r=s}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},v.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,e=0;e<t.length;e++){var n=0|t.words[e];t.words[e]=67108863&(i+=977*n),i=64*n+(i/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(M,g),r(w,g),r(b,g),b.prototype.imulK=function(t){for(var i=0,e=0;e<t.length;e++){var n=19*(0|t.words[e])+i,r=67108863&n;n>>>=26,t.words[e]=r,i=n}return 0!==i&&(t.words[t.length++]=i),t},s._prime=function(t){if(y[t])return y[t];var i;if("k256"===t)i=new v;else if("p224"===t)i=new M;else if("p192"===t)i=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);i=new b}return y[t]=i,i},_.prototype._verify1=function(t){e(0===t.negative,"red works only with positives"),e(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,i){e(0==(t.negative|i.negative),"red works only with positives"),e(t.red&&t.red===i.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,i){this._verify2(t,i);var e=t.add(i);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},_.prototype.iadd=function(t,i){this._verify2(t,i);var e=t.iadd(i);return e.cmp(this.m)>=0&&e.isub(this.m),e},_.prototype.sub=function(t,i){this._verify2(t,i);var e=t.sub(i);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},_.prototype.isub=function(t,i){this._verify2(t,i);var e=t.isub(i);return e.cmpn(0)<0&&e.iadd(this.m),e},_.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},_.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},_.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var i=this.m.andln(3);if(e(i%2==1),3===i){var n=this.m.add(new s(1)).iushrn(2);return this.pow(t,n)}for(var r=this.m.subn(1),o=0;!r.isZero()&&0===r.andln(1);)o++,r.iushrn(1);e(!r.isZero());var h=new s(1).toRed(this),a=h.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new s(2*l*l).toRed(this);0!==this.pow(l,u).cmp(a);)l.redIAdd(a);for(var m=this.pow(l,r),d=this.pow(t,r.addn(1).iushrn(1)),f=this.pow(t,r),p=o;0!==f.cmp(h);){for(var c=f,y=0;0!==c.cmp(h);y++)c=c.redSqr();e(y<p);var g=this.pow(m,new s(1).iushln(p-y-1));d=d.redMul(g),m=g.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var i=t._invmp(this.m);return 0!==i.negative?(i.negative=0,this.imod(i).redNeg()):this.imod(i)},_.prototype.pow=function(t,i){if(i.isZero())return new s(1).toRed(this);if(0===i.cmpn(1))return t.clone();var e=new Array(16);e[0]=new s(1).toRed(this),e[1]=t;for(var n=2;n<e.length;n++)e[n]=this.mul(e[n-1],t);var r=e[0],o=0,h=0,a=i.bitLength()%26;for(0===a&&(a=26),n=i.length-1;n>=0;n--){for(var u=i.words[n],l=a-1;l>=0;l--){var m=u>>l&1;r!==e[0]&&(r=this.sqr(r)),0!==m||0!==o?(o<<=1,o|=m,(4==++h||0===n&&0===l)&&(r=this.mul(r,e[o]),h=0,o=0)):h=0}a=26}return r},_.prototype.convertTo=function(t){var i=t.umod(this.m);return i===t?i.clone():i},_.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},s.mont=function(t){return new x(t)},r(x,_),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var i=this.imod(t.mul(this.rinv));return i.red=null,i},x.prototype.imul=function(t,i){if(t.isZero()||i.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),s=r;return r.cmp(this.m)>=0?s=r.isub(this.m):r.cmpn(0)<0&&(s=r.iadd(this.m)),s._forceRed(this)},x.prototype.mul=function(t,i){if(t.isZero()||i.isZero())return new s(0)._forceRed(this);var e=t.mul(i),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=e.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,a)}(e={path:void 0,exports:{},require:function(t,i){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),e.exports}(),l=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function m(t){return r.from(h.arrayBuffer(t))}const d=new o("secp256k1");function f(t){const i=(""+t).startsWith("0x")?t.slice(2):t,e=d.keyFromPublic(i,"hex").getPublic().encode("hex");return function(t){var i=t;const e=m(i=i.substring(2).toLowerCase());i=i.split("");for(var n=0;n<40;n+=2)e[n/2]>>4>=8&&(i[n]=i[n].toUpperCase()),(15&e[n/2])>=8&&(i[n+1]=i[n+1].toUpperCase());return"0x"+i.join("")}("0x"+m(r.from(e.slice(2),"hex")).slice(-20).toString("hex"))}const p="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",c=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function y(t){return r.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function g(t){const i="0x"+r.from(t).slice(0,32).toString("hex");return i+"0".repeat(66-i.length)}const v={Secp256k1SignatureAuthentication2018:g("sigAuth"),Secp256k1VerificationKey2018:g("veriKey")},M={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function w(t,i,e,n){const s=new u(Math.floor((new Date).getTime()/1e3)),o=[{id:t+"#controller",type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:i}],h=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controller"}];e&&(o.push({id:t+"#controllerKey",type:"Secp256k1VerificationKey2018",controller:t,publicKeyHex:e}),h.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controllerKey"}));let a=0;const l={},m={},d={};for(const i of n){const e=i.validTo,n=`${i._eventName}-${i.delegateType||i.name}-${i.delegate||i.value}`;if(e&&e.gte(s)){if("DIDDelegateChanged"===i._eventName)switch(a++,y(i.delegateType)){case"sigAuth":l[n]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${a}`};case"veriKey":m[n]={id:`${t}#delegate-${a}`,type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:i.delegate}}else if("DIDAttributeChanged"===i._eventName){const e=y(i.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(e){const s=e[2],o=M[e[4]]||e[4],h=e[6];switch(e[1]){case"pub":{a++;const e={id:`${t}#delegate-${a}`,type:`${s}${o}`,controller:t};switch(h){case null:case void 0:case"hex":e.publicKeyHex=i.value.slice(2);break;case"base64":e.publicKeyBase64=r.from(i.value.slice(2),"hex").toString("base64");break;case"base58":e.publicKeyBase58=r.from(i.value.slice(2),"hex").toString("base58");break;case"pem":e.publicKeyPem=r.from(i.value.slice(2),"hex").toString();break;default:e.value=i.value}m[n]=e;break}case"svc":d[n]={type:s,serviceEndpoint:r.from(i.value.slice(2),"hex").toString()}}}}}else a>0&&("DIDDelegateChanged"===i._eventName||"DIDAttributeChanged"===i._eventName&&y(i.name).match(/^did\/pub\//))&&e.lt(s)&&a--,delete l[n],delete m[n],delete d[n]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:o.concat(Object.values(m)),authentication:h.concat(Object.values(l))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function b(e={}){const n=function(i={}){return i.provider?i.provider:i.web3?i.web3.currentProvider:i.rpcUrl?new t(i.rpcUrl):null}(e);if(null===n)return null;const r=new i(n),o=e.registry||p;return{eth:r,registryAddress:o,didReg:new s(r)(l).at(o)}}function _(t=[]){const i={};for(let e=0;e<t.length;e++){const n=t[e];i[n.name]=b(n),null===i[n.name]&&console.warn("invalid configuration for "+n.name)}return i}module.exports={REGISTRY:p,bytes32toString:y,stringToBytes32:g,delegateTypes:v,attrTypes:M,wrapDidDocument:w,getResolver:function(t={}){const i=e.logDecoder(l,!1),n={mainnet:b(t),..._(t.networks)};return function(t={},i={}){if((i.provider||i.web3||i.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(i&&i.networks)for(const e of i.networks)if(!t[e.name])throw new Error(`Ethereum provider configuration for ${e.name} was attempted but no valid configuration was provided`);let e=0;for(const i of Object.keys(t))null!==t[i]&&e++;if(0===e)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(n,t),{ethr:async function(t,e){const r=e.id.match(c);if(!r)throw new Error("Not a valid ethr DID: "+t);const s=r[2],o=r[1]?r[1].slice(0,-1):"mainnet";if(!n[o])throw new Error("No conf for networkId: "+o);const{controller:h,history:a,publicKey:u}=await async function(t,e){const r=[];let{address:s,publicKey:o}=(h=t).length>42?{address:f(h),publicKey:h}:{address:h};var h;let a=s,u=await(async(t,i)=>{const e=await n[i].didReg.changed(t);if(e)return e[0]})(s,e);if(u){const t=""+(await n[e].didReg.identityOwner(s))[0];t.toLowerCase()!==a.toLowerCase()&&(o=null),a=t}for(;u;){const t=u,o=await n[e].eth.getLogs({address:n[e].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:u,toBlock:u}),h=i(o);u=void 0;for(const i of h)r.unshift(i),i.previousChange.lt(t)&&(u=i.previousChange)}return{controller:a,history:r,publicKey:o}}(s,o);return w(t,h,u,a)}}},identifierMatcher:c}; | ||
//# sourceMappingURL=ethr-did-resolver.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("ethjs-provider-http"),require("ethjs-query"),require("ethjs-abi"),require("buffer"),require("ethjs-contract"),require("elliptic"),require("js-sha3")):"function"==typeof define&&define.amd?define(["ethjs-provider-http","ethjs-query","ethjs-abi","buffer","ethjs-contract","elliptic","js-sha3"],e):e((t=t||self).ethjsProviderHttp,t.ethjsQuery,t.ethjsAbi,t.buffer,t.ethjsContract,t.elliptic,t.jsSha3)}(this,function(t,e,i,n,r,o,s){t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;var h="default"in n?n.default:n;r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a=function(t,e,i){return function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function r(t,e,i){if(r.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var o;"object"==typeof t?t.exports=r:e.BN=r,r.BN=r,r.wordSize=26;try{o=h.Buffer}catch(t){}function s(t,e,i){for(var n=0,r=Math.min(t.length,i),o=e;o<r;o++){var s=t.charCodeAt(o)-48;n<<=4,n|=s>=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function u(t,e,i,n){for(var r=0,o=Math.min(t.length,i),s=e;s<o;s++){var h=t.charCodeAt(s)-48;r*=n,r+=h>=49?h-49+10:h>=17?h-17+10:h}return r}r.isBN=function(t){return t instanceof r||null!==t&&"object"==typeof t&&t.constructor.wordSize===r.wordSize&&Array.isArray(t.words)},r.max=function(t,e){return t.cmp(e)>0?t:e},r.min=function(t,e){return t.cmp(e)<0?t:e},r.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===e?this._parseHex(t,r):this._parseBase(t,e,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),e,n)},r.prototype._initNumber=function(t,e,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},r.prototype._initArray=function(t,e,n){if(i("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,s,h=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)this.words[o]|=(s=t[r]|t[r-1]<<8|t[r-2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)this.words[o]|=(s=t[r]|t[r+1]<<8|t[r+2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);return this.strip()},r.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var n,r,o=0;for(i=t.length-6,n=0;i>=e;i-=6)r=s(t,i,i+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);i+6!==e&&(r=s(t,e,i+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303),this.strip()},r.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=e)n++;n--,r=r/e|0;for(var o=t.length-i,s=o%n,h=Math.min(o,o-s)+i,a=0,l=i;l<h;l+=n)a=u(t,l,l+n,e),this.imuln(r),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==s){var m=1;for(a=u(t,l,t.length,e),l=0;l<s;l++)m*=e;this.imuln(m),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}},r.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},r.prototype.clone=function(){var t=new r(null);return this.copy(t),t},r.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},r.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},r.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},r.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,e,i){i.negative=e.negative^t.negative;var n=t.length+e.length|0;i.length=n,n=n-1|0;var r=0|t.words[0],o=0|e.words[0],s=r*o,h=s/67108864|0;i.words[0]=67108863&s;for(var u=1;u<n;u++){for(var a=h>>>26,l=67108863&h,m=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=m;d++)a+=(s=(r=0|t.words[u-d|0])*(o=0|e.words[d])+l)/67108864|0,l=67108863&s;i.words[u]=0|l,h=0|a}return 0!==h?i.words[u]=0|h:i.length--,i.strip()}r.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var h=this.words[s],u=(16777215&(h<<r|o)).toString(16);n=0!=(o=h>>>24-r&16777215)||s!==this.length-1?a[6-u.length]+u+n:u+n,(r+=2)>=26&&(r-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:a[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}i(!1,"Base should be between 2 and 36")},r.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},r.prototype.toJSON=function(){return this.toString(16)},r.prototype.toBuffer=function(t,e){return i(void 0!==o),this.toArrayLike(o,t,e)},r.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},r.prototype.toArrayLike=function(t,e,n){var r=this.byteLength(),o=n||Math.max(1,r);i(r<=o,"byte array longer than desired length"),i(o>0,"Requested array length <= 0"),this.strip();var s,h,u="le"===e,a=new t(o),l=this.clone();if(u){for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[h]=s;for(;h<o;h++)a[h]=0}else{for(h=0;h<o-r;h++)a[h]=0;for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[o-h-1]=s}return a},r.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},r.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},r.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},r.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return 0!==this.negative},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this.strip()},r.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},r.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},r.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},r.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},r.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},r.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},r.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},r.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var n=0;n<i.length;n++)this.words[n]=e.words[n]^i.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this.strip()},r.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},r.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},r.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},r.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var r=0;r<e;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},r.prototype.notn=function(t){return this.clone().inotn(t)},r.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},r.prototype.iadd=function(t){var e,i,n;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(i=this,n=t):(i=t,n=this);for(var r=0,o=0;o<n.length;o++)this.words[o]=67108863&(e=(0|i.words[o])+(0|n.words[o])+r),r=e>>>26;for(;0!==r&&o<i.length;o++)this.words[o]=67108863&(e=(0|i.words[o])+r),r=e>>>26;if(this.length=i.length,0!==r)this.words[this.length]=r,this.length++;else if(i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this},r.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},r.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(i=this,n=t):(i=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|i.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<i.length;s++)o=(e=(0|i.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<i.length&&i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this.length=Math.max(this.length,s),i!==this&&(this.negative=1),this.strip()},r.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,e,i){var n,r,o,s=t.words,h=e.words,u=i.words,a=0,l=0|s[0],m=8191&l,d=l>>>13,f=0|s[1],p=8191&f,c=f>>>13,y=0|s[2],v=8191&y,g=y>>>13,M=0|s[3],w=8191&M,b=M>>>13,_=0|s[4],k=8191&_,x=_>>>13,S=0|s[5],A=8191&S,R=S>>>13,j=0|s[6],q=8191&j,B=j>>>13,D=0|s[7],K=8191&D,O=D>>>13,T=0|s[8],Z=8191&T,N=T>>>13,I=0|s[9],P=8191&I,C=I>>>13,E=0|h[0],L=8191&E,$=E>>>13,z=0|h[1],V=8191&z,F=z>>>13,U=0|h[2],H=8191&U,G=U>>>13,J=0|h[3],Q=8191&J,W=J>>>13,Y=0|h[4],X=8191&Y,tt=Y>>>13,et=0|h[5],it=8191&et,nt=et>>>13,rt=0|h[6],ot=8191&rt,st=rt>>>13,ht=0|h[7],ut=8191&ht,at=ht>>>13,lt=0|h[8],mt=8191<,dt=lt>>>13,ft=0|h[9],pt=8191&ft,ct=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var yt=(a+(n=Math.imul(m,L))|0)+((8191&(r=(r=Math.imul(m,$))+Math.imul(d,L)|0))<<13)|0;a=((o=Math.imul(d,$))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,L),r=(r=Math.imul(p,$))+Math.imul(c,L)|0,o=Math.imul(c,$);var vt=(a+(n=n+Math.imul(m,V)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,V)|0))<<13)|0;a=((o=o+Math.imul(d,F)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,L),r=(r=Math.imul(v,$))+Math.imul(g,L)|0,o=Math.imul(g,$),n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,V)|0,o=o+Math.imul(c,F)|0;var gt=(a+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;a=((o=o+Math.imul(d,G)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(w,L),r=(r=Math.imul(w,$))+Math.imul(b,L)|0,o=Math.imul(b,$),n=n+Math.imul(v,V)|0,r=(r=r+Math.imul(v,F)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,o=o+Math.imul(c,G)|0;var Mt=(a+(n=n+Math.imul(m,Q)|0)|0)+((8191&(r=(r=r+Math.imul(m,W)|0)+Math.imul(d,Q)|0))<<13)|0;a=((o=o+Math.imul(d,W)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(k,L),r=(r=Math.imul(k,$))+Math.imul(x,L)|0,o=Math.imul(x,$),n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,F)|0,n=n+Math.imul(v,H)|0,r=(r=r+Math.imul(v,G)|0)+Math.imul(g,H)|0,o=o+Math.imul(g,G)|0,n=n+Math.imul(p,Q)|0,r=(r=r+Math.imul(p,W)|0)+Math.imul(c,Q)|0,o=o+Math.imul(c,W)|0;var wt=(a+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;a=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,L),r=(r=Math.imul(A,$))+Math.imul(R,L)|0,o=Math.imul(R,$),n=n+Math.imul(k,V)|0,r=(r=r+Math.imul(k,F)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,o=o+Math.imul(b,G)|0,n=n+Math.imul(v,Q)|0,r=(r=r+Math.imul(v,W)|0)+Math.imul(g,Q)|0,o=o+Math.imul(g,W)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,o=o+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(m,it)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,it)|0))<<13)|0;a=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(q,L),r=(r=Math.imul(q,$))+Math.imul(B,L)|0,o=Math.imul(B,$),n=n+Math.imul(A,V)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,F)|0,n=n+Math.imul(k,H)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(x,H)|0,o=o+Math.imul(x,G)|0,n=n+Math.imul(w,Q)|0,r=(r=r+Math.imul(w,W)|0)+Math.imul(b,Q)|0,o=o+Math.imul(b,W)|0,n=n+Math.imul(v,X)|0,r=(r=r+Math.imul(v,tt)|0)+Math.imul(g,X)|0,o=o+Math.imul(g,tt)|0,n=n+Math.imul(p,it)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,it)|0,o=o+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(m,ot)|0)|0)+((8191&(r=(r=r+Math.imul(m,st)|0)+Math.imul(d,ot)|0))<<13)|0;a=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(K,L),r=(r=Math.imul(K,$))+Math.imul(O,L)|0,o=Math.imul(O,$),n=n+Math.imul(q,V)|0,r=(r=r+Math.imul(q,F)|0)+Math.imul(B,V)|0,o=o+Math.imul(B,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,o=o+Math.imul(R,G)|0,n=n+Math.imul(k,Q)|0,r=(r=r+Math.imul(k,W)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,W)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(v,it)|0,r=(r=r+Math.imul(v,nt)|0)+Math.imul(g,it)|0,o=o+Math.imul(g,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(c,ot)|0,o=o+Math.imul(c,st)|0;var kt=(a+(n=n+Math.imul(m,ut)|0)|0)+((8191&(r=(r=r+Math.imul(m,at)|0)+Math.imul(d,ut)|0))<<13)|0;a=((o=o+Math.imul(d,at)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(Z,L),r=(r=Math.imul(Z,$))+Math.imul(N,L)|0,o=Math.imul(N,$),n=n+Math.imul(K,V)|0,r=(r=r+Math.imul(K,F)|0)+Math.imul(O,V)|0,o=o+Math.imul(O,F)|0,n=n+Math.imul(q,H)|0,r=(r=r+Math.imul(q,G)|0)+Math.imul(B,H)|0,o=o+Math.imul(B,G)|0,n=n+Math.imul(A,Q)|0,r=(r=r+Math.imul(A,W)|0)+Math.imul(R,Q)|0,o=o+Math.imul(R,W)|0,n=n+Math.imul(k,X)|0,r=(r=r+Math.imul(k,tt)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(w,it)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,it)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(v,ot)|0,r=(r=r+Math.imul(v,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,at)|0)+Math.imul(c,ut)|0,o=o+Math.imul(c,at)|0;var xt=(a+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;a=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(P,L),r=(r=Math.imul(P,$))+Math.imul(C,L)|0,o=Math.imul(C,$),n=n+Math.imul(Z,V)|0,r=(r=r+Math.imul(Z,F)|0)+Math.imul(N,V)|0,o=o+Math.imul(N,F)|0,n=n+Math.imul(K,H)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(O,H)|0,o=o+Math.imul(O,G)|0,n=n+Math.imul(q,Q)|0,r=(r=r+Math.imul(q,W)|0)+Math.imul(B,Q)|0,o=o+Math.imul(B,W)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,n=n+Math.imul(k,it)|0,r=(r=r+Math.imul(k,nt)|0)+Math.imul(x,it)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,n=n+Math.imul(v,ut)|0,r=(r=r+Math.imul(v,at)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,at)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,o=o+Math.imul(c,dt)|0;var St=(a+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;a=((o=o+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(P,V),r=(r=Math.imul(P,F))+Math.imul(C,V)|0,o=Math.imul(C,F),n=n+Math.imul(Z,H)|0,r=(r=r+Math.imul(Z,G)|0)+Math.imul(N,H)|0,o=o+Math.imul(N,G)|0,n=n+Math.imul(K,Q)|0,r=(r=r+Math.imul(K,W)|0)+Math.imul(O,Q)|0,o=o+Math.imul(O,W)|0,n=n+Math.imul(q,X)|0,r=(r=r+Math.imul(q,tt)|0)+Math.imul(B,X)|0,o=o+Math.imul(B,tt)|0,n=n+Math.imul(A,it)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,it)|0,o=o+Math.imul(R,nt)|0,n=n+Math.imul(k,ot)|0,r=(r=r+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,at)|0)+Math.imul(b,ut)|0,o=o+Math.imul(b,at)|0,n=n+Math.imul(v,mt)|0,r=(r=r+Math.imul(v,dt)|0)+Math.imul(g,mt)|0,o=o+Math.imul(g,dt)|0;var At=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((o=o+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(P,H),r=(r=Math.imul(P,G))+Math.imul(C,H)|0,o=Math.imul(C,G),n=n+Math.imul(Z,Q)|0,r=(r=r+Math.imul(Z,W)|0)+Math.imul(N,Q)|0,o=o+Math.imul(N,W)|0,n=n+Math.imul(K,X)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(O,X)|0,o=o+Math.imul(O,tt)|0,n=n+Math.imul(q,it)|0,r=(r=r+Math.imul(q,nt)|0)+Math.imul(B,it)|0,o=o+Math.imul(B,nt)|0,n=n+Math.imul(A,ot)|0,r=(r=r+Math.imul(A,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,n=n+Math.imul(k,ut)|0,r=(r=r+Math.imul(k,at)|0)+Math.imul(x,ut)|0,o=o+Math.imul(x,at)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,o=o+Math.imul(b,dt)|0;var Rt=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(r=(r=r+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((o=o+Math.imul(g,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(P,Q),r=(r=Math.imul(P,W))+Math.imul(C,Q)|0,o=Math.imul(C,W),n=n+Math.imul(Z,X)|0,r=(r=r+Math.imul(Z,tt)|0)+Math.imul(N,X)|0,o=o+Math.imul(N,tt)|0,n=n+Math.imul(K,it)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(O,it)|0,o=o+Math.imul(O,nt)|0,n=n+Math.imul(q,ot)|0,r=(r=r+Math.imul(q,st)|0)+Math.imul(B,ot)|0,o=o+Math.imul(B,st)|0,n=n+Math.imul(A,ut)|0,r=(r=r+Math.imul(A,at)|0)+Math.imul(R,ut)|0,o=o+Math.imul(R,at)|0,n=n+Math.imul(k,mt)|0,r=(r=r+Math.imul(k,dt)|0)+Math.imul(x,mt)|0,o=o+Math.imul(x,dt)|0;var jt=(a+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((o=o+Math.imul(b,ct)|0)+(r>>>13)|0)+(jt>>>26)|0,jt&=67108863,n=Math.imul(P,X),r=(r=Math.imul(P,tt))+Math.imul(C,X)|0,o=Math.imul(C,tt),n=n+Math.imul(Z,it)|0,r=(r=r+Math.imul(Z,nt)|0)+Math.imul(N,it)|0,o=o+Math.imul(N,nt)|0,n=n+Math.imul(K,ot)|0,r=(r=r+Math.imul(K,st)|0)+Math.imul(O,ot)|0,o=o+Math.imul(O,st)|0,n=n+Math.imul(q,ut)|0,r=(r=r+Math.imul(q,at)|0)+Math.imul(B,ut)|0,o=o+Math.imul(B,at)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,o=o+Math.imul(R,dt)|0;var qt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(r=(r=r+Math.imul(k,ct)|0)+Math.imul(x,pt)|0))<<13)|0;a=((o=o+Math.imul(x,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(P,it),r=(r=Math.imul(P,nt))+Math.imul(C,it)|0,o=Math.imul(C,nt),n=n+Math.imul(Z,ot)|0,r=(r=r+Math.imul(Z,st)|0)+Math.imul(N,ot)|0,o=o+Math.imul(N,st)|0,n=n+Math.imul(K,ut)|0,r=(r=r+Math.imul(K,at)|0)+Math.imul(O,ut)|0,o=o+Math.imul(O,at)|0,n=n+Math.imul(q,mt)|0,r=(r=r+Math.imul(q,dt)|0)+Math.imul(B,mt)|0,o=o+Math.imul(B,dt)|0;var Bt=(a+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;a=((o=o+Math.imul(R,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(P,ot),r=(r=Math.imul(P,st))+Math.imul(C,ot)|0,o=Math.imul(C,st),n=n+Math.imul(Z,ut)|0,r=(r=r+Math.imul(Z,at)|0)+Math.imul(N,ut)|0,o=o+Math.imul(N,at)|0,n=n+Math.imul(K,mt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(O,mt)|0,o=o+Math.imul(O,dt)|0;var Dt=(a+(n=n+Math.imul(q,pt)|0)|0)+((8191&(r=(r=r+Math.imul(q,ct)|0)+Math.imul(B,pt)|0))<<13)|0;a=((o=o+Math.imul(B,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(P,ut),r=(r=Math.imul(P,at))+Math.imul(C,ut)|0,o=Math.imul(C,at),n=n+Math.imul(Z,mt)|0,r=(r=r+Math.imul(Z,dt)|0)+Math.imul(N,mt)|0,o=o+Math.imul(N,dt)|0;var Kt=(a+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,ct)|0)+Math.imul(O,pt)|0))<<13)|0;a=((o=o+Math.imul(O,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(P,mt),r=(r=Math.imul(P,dt))+Math.imul(C,mt)|0,o=Math.imul(C,dt);var Ot=(a+(n=n+Math.imul(Z,pt)|0)|0)+((8191&(r=(r=r+Math.imul(Z,ct)|0)+Math.imul(N,pt)|0))<<13)|0;a=((o=o+Math.imul(N,ct)|0)+(r>>>13)|0)+(Ot>>>26)|0,Ot&=67108863;var Tt=(a+(n=Math.imul(P,pt))|0)+((8191&(r=(r=Math.imul(P,ct))+Math.imul(C,pt)|0))<<13)|0;return a=((o=Math.imul(C,ct))+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,u[0]=yt,u[1]=vt,u[2]=gt,u[3]=Mt,u[4]=wt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=xt,u[9]=St,u[10]=At,u[11]=Rt,u[12]=jt,u[13]=qt,u[14]=Bt,u[15]=Dt,u[16]=Kt,u[17]=Ot,u[18]=Tt,0!==a&&(u[19]=a,i.length++),i};function p(t,e,i){return(new c).mulp(t,e,i)}function c(t,e){this.x=t,this.y=e}Math.imul||(f=d),r.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,e):i<63?d(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var n=0,r=0,o=0;o<i.length-1;o++){var s=r;r=0;for(var h=67108863&n,u=Math.min(o,e.length-1),a=Math.max(0,o-t.length+1);a<=u;a++){var l=(0|t.words[o-a])*(0|e.words[a]),m=67108863&l;h=67108863&(m=m+h|0),r+=(s=(s=s+(l/67108864|0)|0)+(m>>>26)|0)>>>26,s&=67108863}i.words[o]=h,n=s,s=r}return 0!==n?i.words[o]=n:i.length--,i.strip()}(this,t,e):p(this,t,e)},c.prototype.makeRBT=function(t){for(var e=new Array(t),i=r.prototype._countBits(t)-1,n=0;n<t;n++)e[n]=this.revBin(n,i,t);return e},c.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var n=0,r=0;r<e;r++)n|=(1&t)<<e-r-1,t>>=1;return n},c.prototype.permute=function(t,e,i,n,r,o){for(var s=0;s<o;s++)n[s]=e[t[s]],r[s]=i[t[s]]},c.prototype.transform=function(t,e,i,n,r,o){this.permute(o,t,e,i,n,r);for(var s=1;s<r;s<<=1)for(var h=s<<1,u=Math.cos(2*Math.PI/h),a=Math.sin(2*Math.PI/h),l=0;l<r;l+=h)for(var m=u,d=a,f=0;f<s;f++){var p=i[l+f],c=n[l+f],y=i[l+f+s],v=n[l+f+s],g=m*y-d*v;v=m*v+d*y,i[l+f]=p+(y=g),n[l+f]=c+v,i[l+f+s]=p-y,n[l+f+s]=c-v,f!==h&&(g=u*m-a*d,d=u*d+a*m,m=g)}},c.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),n=1&i,r=0;for(i=i/2|0;i;i>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var n=0;n<i/2;n++){var r=t[n];t[n]=t[i-n-1],t[i-n-1]=r,r=e[n],e[n]=-e[i-n-1],e[i-n-1]=-r}},c.prototype.normalize13b=function(t,e){for(var i=0,n=0;n<e/2;n++){var r=8192*Math.round(t[2*n+1]/e)+Math.round(t[2*n]/e)+i;t[n]=67108863&r,i=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,e,n,r){for(var o=0,s=0;s<e;s++)n[2*s]=8191&(o+=0|t[s]),n[2*s+1]=8191&(o>>>=13),o>>>=13;for(s=2*e;s<r;++s)n[s]=0;i(0===o),i(0==(-8192&o))},c.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},c.prototype.mulp=function(t,e,i){var n=2*this.guessLen13b(t.length,e.length),r=this.makeRBT(n),o=this.stub(n),s=new Array(n),h=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),m=new Array(n),d=i.words;d.length=n,this.convert13b(t.words,t.length,s,n),this.convert13b(e.words,e.length,a,n),this.transform(s,o,h,u,n,r),this.transform(a,o,l,m,n,r);for(var f=0;f<n;f++){var p=h[f]*l[f]-u[f]*m[f];u[f]=h[f]*m[f]+u[f]*l[f],h[f]=p}return this.conjugate(h,u,n),this.transform(h,u,d,o,n,r),this.conjugate(d,o,n),this.normalize13b(d,n),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},r.prototype.mul=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},r.prototype.mulf=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),p(this,t,e)},r.prototype.imul=function(t){return this.clone().mulTo(t,this)},r.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,o=(67108863&r)+(67108863&e);e>>=26,e+=r/67108864|0,e+=o>>>26,this.words[n]=67108863&o}return 0!==e&&(this.words[n]=e,this.length++),this},r.prototype.muln=function(t){return this.clone().imuln(t)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var n=i%26;e[i]=(t.words[i/26|0]&1<<n)>>>n}return e}(t);if(0===e.length)return new r(1);for(var i=this,n=0;n<e.length&&0===e[n];n++,i=i.sqr());if(++n<e.length)for(var o=i.sqr();n<e.length;n++,o=o.sqr())0!==e[n]&&(i=i.mul(o));return i},r.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e<this.length;e++){var h=this.words[e]&o;this.words[e]=(0|this.words[e])-h<<n|s,s=h>>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==r){for(e=this.length-1;e>=0;e--)this.words[e+r]=this.words[e];for(e=0;e<r;e++)this.words[e]=0;this.length+=r}return this.strip()},r.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},r.prototype.iushrn=function(t,e,n){var r;i("number"==typeof t&&t>=0),r=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),h=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var a=0;a<s;a++)u.words[a]=this.words[a];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,a=0;a<this.length;a++)this.words[a]=this.words[a+s];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=r);a--){var m=0|this.words[a];this.words[a]=l<<26-o|m>>>o,l=m&h}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},r.prototype.ishrn=function(t,e,n){return i(0===this.negative),this.iushrn(t,e,n)},r.prototype.shln=function(t){return this.clone().ishln(t)},r.prototype.ushln=function(t){return this.clone().iushln(t)},r.prototype.shrn=function(t){return this.clone().ishrn(t)},r.prototype.ushrn=function(t){return this.clone().iushrn(t)},r.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;return!(this.length<=n||!(this.words[n]&1<<e))},r.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==e&&n++,this.length=Math.min(n,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},r.prototype.maskn=function(t){return this.clone().imaskn(t)},r.prototype.iaddn=function(t){return i("number"==typeof t),i(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},r.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},r.prototype.isubn=function(t){if(i("number"==typeof t),i(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this.strip()},r.prototype.addn=function(t){return this.clone().iaddn(t)},r.prototype.subn=function(t){return this.clone().isubn(t)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(t,e,n){var r,o;this._expand(t.length+n);var s=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+s;var h=(0|t.words[r])*e;s=((o-=67108863&h)>>26)-(h/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)s=(o=(0|this.words[r+n])+s)>>26,this.words[r+n]=67108863&o;if(0===s)return this.strip();for(i(-1===s),s=0,r=0;r<this.length;r++)s=(o=-(0|this.words[r])+s)>>26,this.words[r]=67108863&o;return this.negative=1,this.strip()},r.prototype._wordDiv=function(t,e){var i,n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(i=26-this._countBits(s))&&(o=o.ushln(i),n.iushln(i),s=0|o.words[o.length-1]);var h,u=n.length-o.length;if("mod"!==e){(h=new r(null)).length=u+1,h.words=new Array(h.length);for(var a=0;a<h.length;a++)h.words[a]=0}var l=n.clone()._ishlnsubmul(o,1,u);0===l.negative&&(n=l,h&&(h.words[u]=1));for(var m=u-1;m>=0;m--){var d=67108864*(0|n.words[o.length+m])+(0|n.words[o.length+m-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(o,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(o,1,m),n.isZero()||(n.negative^=1);h&&(h.words[m]=d)}return h&&h.strip(),n.strip(),"div"!==e&&0!==i&&n.iushrn(i),{div:h||null,mod:n}},r.prototype.divmod=function(t,e,n){return i(!t.isZero()),this.isZero()?{div:new r(0),mod:new r(0)}:0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,e),"mod"!==e&&(o=h.div.neg()),"div"!==e&&(s=h.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),e),"mod"!==e&&(o=h.div.neg()),{div:o,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),e),"div"!==e&&(s=h.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:h.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new r(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new r(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new r(this.modn(t.words[0]))}:this._wordDiv(t,e);var o,s,h},r.prototype.div=function(t){return this.divmod(t,"div",!1).div},r.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},r.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},r.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),r=t.andln(1),o=i.cmp(n);return o<0||1===r&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},r.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(e*n+(0|this.words[r]))%t;return n},r.prototype.idivn=function(t){i(t<=67108863);for(var e=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*e;this.words[n]=r/t|0,e=r%t}return this.strip()},r.prototype.divn=function(t){return this.clone().idivn(t)},r.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o=new r(1),s=new r(0),h=new r(0),u=new r(1),a=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),m=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(l),s.isub(m)),o.iushrn(1),s.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(h.isOdd()||u.isOdd())&&(h.iadd(l),u.isub(m)),h.iushrn(1),u.iushrn(1);e.cmp(n)>=0?(e.isub(n),o.isub(h),s.isub(u)):(n.isub(e),h.isub(o),u.isub(s))}return{a:h,b:u,gcd:n.iushln(a)}},r.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o,s=new r(1),h=new r(0),u=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(e.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(e.iushrn(a);a-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)h.isOdd()&&h.iadd(u),h.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(h)):(n.isub(e),h.isub(s))}return(o=0===e.cmpn(1)?s:h).cmpn(0)<0&&o.iadd(t),o},r.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var n=0;e.isEven()&&i.isEven();n++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var r=e.cmp(i);if(r<0){var o=e;e=i,i=o}else if(0===r||0===i.cmpn(1))break;e.isub(i)}return i.iushln(n)},r.prototype.invm=function(t){return this.egcd(t).a.umod(t)},r.prototype.isEven=function(){return 0==(1&this.words[0])},r.prototype.isOdd=function(){return 1==(1&this.words[0])},r.prototype.andln=function(t){return this.words[0]&t},r.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,n=(t-e)/26,r=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var h=0|this.words[s];o=(h+=o)>>>26,this.words[s]=h&=67108863}return 0!==o&&(this.words[s]=o,this.length++),this},r.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},r.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)e=1;else{n&&(t=-t),i(t<=67108863,"Number is too big");var r=0|this.words[0];e=r===t?0:r<t?-1:1}return 0!==this.negative?0|-e:e},r.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},r.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var n=0|this.words[i],r=0|t.words[i];if(n!==r){n<r?e=-1:n>r&&(e=1);break}}return e},r.prototype.gtn=function(t){return 1===this.cmpn(t)},r.prototype.gt=function(t){return 1===this.cmp(t)},r.prototype.gten=function(t){return this.cmpn(t)>=0},r.prototype.gte=function(t){return this.cmp(t)>=0},r.prototype.ltn=function(t){return-1===this.cmpn(t)},r.prototype.lt=function(t){return-1===this.cmp(t)},r.prototype.lten=function(t){return this.cmpn(t)<=0},r.prototype.lte=function(t){return this.cmp(t)<=0},r.prototype.eqn=function(t){return 0===this.cmpn(t)},r.prototype.eq=function(t){return 0===this.cmp(t)},r.red=function(t){return new _(t)},r.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},r.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(t){return this.red=t,this},r.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},r.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},r.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},r.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},r.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},r.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},r.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},r.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},r.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new r(e,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var e=r._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new r(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new r(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:i.ucmp(this.p);return 0===n?(i.words[0]=0,i.length=1):n>0?i.isub(this.p):void 0!==i.strip?i.strip():i._strip(),i},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},n(g,v),g.prototype.split=function(t,e){for(var i=Math.min(t.length,9),n=0;n<i;n++)e.words[n]=t.words[n];if(e.length=i,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(e.words[e.length++]=4194303&r,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(4194303&o)<<4|r>>>22,r=o}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var n=0|t.words[i];t.words[i]=67108863&(e+=977*n),e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(M,v),n(w,v),n(b,v),b.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var n=19*(0|t.words[i])+e,r=67108863&n;n>>>=26,t.words[i]=r,e=n}return 0!==e&&(t.words[t.length++]=e),t},r._prime=function(t){if(y[t])return y[t];var e;if("k256"===t)e=new g;else if("p224"===t)e=new M;else if("p192"===t)e=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new b}return y[t]=e,e},_.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},_.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},_.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},_.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},_.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},_.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},_.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var n=this.m.add(new r(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);i(!o.isZero());var h=new r(1).toRed(this),u=h.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new r(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var m=this.pow(l,o),d=this.pow(t,o.addn(1).iushrn(1)),f=this.pow(t,o),p=s;0!==f.cmp(h);){for(var c=f,y=0;0!==c.cmp(h);y++)c=c.redSqr();i(y<p);var v=this.pow(m,new r(1).iushln(p-y-1));d=d.redMul(v),m=v.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},_.prototype.pow=function(t,e){if(e.isZero())return new r(1).toRed(this);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new r(1).toRed(this),i[1]=t;for(var n=2;n<i.length;n++)i[n]=this.mul(i[n-1],t);var o=i[0],s=0,h=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var a=e.words[n],l=u-1;l>=0;l--){var m=a>>l&1;o!==i[0]&&(o=this.sqr(o)),0!==m||0!==s?(s<<=1,s|=m,(4==++h||0===n&&0===l)&&(o=this.mul(o,i[s]),h=0,s=0)):h=0}u=26}return o},_.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},_.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},r.mont=function(t){return new k(t)},n(k,_),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},k.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=i.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new r(0)._forceRed(this);var i=t.mul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=i.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,u)}(i={path:void 0,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),i.exports}(),l=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function m(t){return n.Buffer.from(s.keccak_256.arrayBuffer(t))}const d=new o.ec("secp256k1");function f(t){const e=(""+t).startsWith("0x")?t.slice(2):t,i=d.keyFromPublic(e,"hex").getPublic().encode("hex");return function(t){var e=t;const i=m(e=e.substring(2).toLowerCase());e=e.split("");for(var n=0;n<40;n+=2)i[n/2]>>4>=8&&(e[n]=e[n].toUpperCase()),(15&i[n/2])>=8&&(e[n+1]=e[n+1].toUpperCase());return"0x"+e.join("")}("0x"+m(n.Buffer.from(i.slice(2),"hex")).slice(-20).toString("hex"))}function p(t,e,i){if(!t.s){if(i instanceof y){if(!i.s)return void(i.o=p.bind(null,t,e));1&e&&(e=i.s),i=i.v}if(i&&i.then)return void i.then(p.bind(null,t,e),p.bind(null,t,2));t.s=e,t.v=i;const n=t.o;n&&n(t)}}const c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",y=function(){function t(){}return t.prototype.then=function(e,i){const n=new t,r=this.s;if(r){const t=1&r?e:i;if(t){try{p(n,1,t(this.v))}catch(t){p(n,2,t)}return n}return this}return this.o=function(t){try{const r=t.v;1&t.s?p(n,1,e?e(r):r):i?p(n,1,i(r)):p(n,2,r)}catch(t){p(n,2,t)}},n},t}();function v(t){return t instanceof y&&1&t.s}const g=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function M(t){return n.Buffer.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function w(t){const e="0x"+n.Buffer.from(t).slice(0,32).toString("hex");return e+"0".repeat(66-e.length)}const b={Secp256k1SignatureAuthentication2018:w("sigAuth"),Secp256k1VerificationKey2018:w("veriKey")},_={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function k(t,e,i,r){const o=new a(Math.floor((new Date).getTime()/1e3)),s=[{id:t+"#owner",type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:e}],h=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#owner"}];i&&(s.push({id:t+"#ownerKey",type:"Secp256k1VerificationKey2018",owner:t,publicKeyHex:i}),h.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#ownerKey"}));let u=0;const l={},m={},d={};for(const e of r){const i=e.validTo,r=`${e._eventName}-${e.delegateType||e.name}-${e.delegate||e.value}`;if(i&&i.gte(o)){if("DIDDelegateChanged"===e._eventName)switch(u++,M(e.delegateType)){case"sigAuth":l[r]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${u}`};case"veriKey":m[r]={id:`${t}#delegate-${u}`,type:"Secp256k1VerificationKey2018",owner:t,ethereumAddress:e.delegate}}else if("DIDAttributeChanged"===e._eventName){const i=M(e.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(i){const o=i[2],s=_[i[4]]||i[4],h=i[6];switch(i[1]){case"pub":{u++;const i={id:`${t}#delegate-${u}`,type:`${o}${s}`,owner:t};switch(h){case null:case void 0:case"hex":i.publicKeyHex=e.value.slice(2);break;case"base64":i.publicKeyBase64=n.Buffer.from(e.value.slice(2),"hex").toString("base64");break;case"base58":i.publicKeyBase58=n.Buffer.from(e.value.slice(2),"hex").toString("base58");break;case"pem":i.publicKeyPem=n.Buffer.from(e.value.slice(2),"hex").toString();break;default:i.value=e.value}m[r]=i;break}case"svc":d[r]={type:o,serviceEndpoint:n.Buffer.from(e.value.slice(2),"hex").toString()}}}}}else u>0&&("DIDDelegateChanged"===e._eventName||"DIDAttributeChanged"===e._eventName&&M(e.name).match(/^did\/pub\//))&&i.lt(o)&&u--,delete l[r],delete m[r],delete d[r]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:s.concat(Object.values(m)),authentication:h.concat(Object.values(l))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function x(i={}){const n=function(e={}){return e.provider?e.provider:e.web3?e.web3.currentProvider:e.rpcUrl?new t(e.rpcUrl):null}(i);if(null===n)return null;const o=new e(n),s=i.registry||c;return{eth:o,registryAddress:s,didReg:new r(o)(l).at(s)}}function S(t=[]){const e={};for(let i=0;i<t.length;i++){const n=t[i];e[n.name]=x(n),null===e[n.name]&&console.warn("invalid configuration for "+n.name)}return e}module.exports={REGISTRY:c,bytes32toString:M,stringToBytes32:w,delegateTypes:b,attrTypes:_,wrapDidDocument:k,getResolver:function(t={}){const e=i.logDecoder(l,!1),n={mainnet:x(t),...S(t.networks)};return function(t={},e={}){if((e.provider||e.web3||e.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(e&&e.networks)for(const i of e.networks)if(!t[i.name])throw new Error(`Ethereum provider configuration for ${i.name} was attempted but no valid configuration was provided`);let i=0;for(const e of Object.keys(t))null!==t[e]&&i++;if(0===i)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(n,t),{ethr:function(t,i){try{const r=i.id.match(g);if(!r)throw new Error("Not a valid ethr DID: "+t);const o=r[2],s=r[1]?r[1].slice(0,-1):"mainnet";if(!n[s])throw new Error("No conf for networkId: "+s);return Promise.resolve(function(t,i){try{const o=[];let{address:s,publicKey:h}=(r=t).length>42?{address:f(r),publicKey:r}:{address:r},u=s;return Promise.resolve(function(t,e){try{return Promise.resolve(n[e].didReg.changed(t)).then(function(t){if(t)return t[0]})}catch(t){return Promise.reject(t)}}(s,i)).then(function(t){function r(){function r(){return{owner:u,history:o,publicKey:h}}const a=function(t,e,i){for(var n;;){var r=t();if(v(r)&&(r=r.v),!r)return o;if(r.then){n=0;break}var o=i();if(o&&o.then){if(!v(o)){n=1;break}o=o.s}}var s=new y,h=p.bind(null,s,2);return(0===n?r.then(a):1===n?o.then(u):(void 0).then(function(){(r=t())?r.then?r.then(a).then(void 0,h):a(r):p(s,1,o)})).then(void 0,h),s;function u(e){o=e;do{if(!(r=t())||v(r)&&!r.v)return void p(s,1,o);if(r.then)return void r.then(a).then(void 0,h);v(o=i())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,h)}function a(t){t?(o=i())&&o.then?o.then(u).then(void 0,h):u(o):p(s,1,o)}}(function(){return!!t},0,function(){const r=t;return Promise.resolve(n[i].eth.getLogs({address:n[i].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:t,toBlock:t})).then(function(i){const n=e(i);t=void 0;for(const e of n)o.unshift(e),e.previousChange.lt(r)&&(t=e.previousChange)})});return a&&a.then?a.then(r):r()}const a=function(){if(t)return Promise.resolve(n[i].didReg.identityOwner(s)).then(function(t){const e=""+t[0];e.toLowerCase()!==u.toLowerCase()&&(h=null),u=e})}();return a&&a.then?a.then(r):r()})}catch(t){return Promise.reject(t)}var r}(o,s)).then(function({owner:e,history:i,publicKey:n}){return k(t,e,n,i)})}catch(t){return Promise.reject(t)}}}},identifierMatcher:g}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("ethjs-provider-http"),require("ethjs-query"),require("ethjs-abi"),require("buffer"),require("ethjs-contract"),require("elliptic"),require("js-sha3")):"function"==typeof define&&define.amd?define(["ethjs-provider-http","ethjs-query","ethjs-abi","buffer","ethjs-contract","elliptic","js-sha3"],e):e((t=t||self).ethjsProviderHttp,t.ethjsQuery,t.ethjsAbi,t.buffer,t.ethjsContract,t.elliptic,t.jsSha3)}(this,function(t,e,i,n,r,o,s){t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;var h="default"in n?n.default:n;r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a=function(t,e,i){return function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function r(t,e,i){if(r.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var o;"object"==typeof t?t.exports=r:e.BN=r,r.BN=r,r.wordSize=26;try{o=h.Buffer}catch(t){}function s(t,e,i){for(var n=0,r=Math.min(t.length,i),o=e;o<r;o++){var s=t.charCodeAt(o)-48;n<<=4,n|=s>=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function u(t,e,i,n){for(var r=0,o=Math.min(t.length,i),s=e;s<o;s++){var h=t.charCodeAt(s)-48;r*=n,r+=h>=49?h-49+10:h>=17?h-17+10:h}return r}r.isBN=function(t){return t instanceof r||null!==t&&"object"==typeof t&&t.constructor.wordSize===r.wordSize&&Array.isArray(t.words)},r.max=function(t,e){return t.cmp(e)>0?t:e},r.min=function(t,e){return t.cmp(e)<0?t:e},r.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&r++,16===e?this._parseHex(t,r):this._parseBase(t,e,r),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),e,n)},r.prototype._initNumber=function(t,e,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},r.prototype._initArray=function(t,e,n){if(i("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,s,h=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)this.words[o]|=(s=t[r]|t[r-1]<<8|t[r-2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)this.words[o]|=(s=t[r]|t[r+1]<<8|t[r+2]<<16)<<h&67108863,this.words[o+1]=s>>>26-h&67108863,(h+=24)>=26&&(h-=26,o++);return this.strip()},r.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var n,r,o=0;for(i=t.length-6,n=0;i>=e;i-=6)r=s(t,i,i+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);i+6!==e&&(r=s(t,e,i+6),this.words[n]|=r<<o&67108863,this.words[n+1]|=r>>>26-o&4194303),this.strip()},r.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=e)n++;n--,r=r/e|0;for(var o=t.length-i,s=o%n,h=Math.min(o,o-s)+i,a=0,l=i;l<h;l+=n)a=u(t,l,l+n,e),this.imuln(r),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(0!==s){var m=1;for(a=u(t,l,t.length,e),l=0;l<s;l++)m*=e;this.imuln(m),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}},r.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},r.prototype.clone=function(){var t=new r(null);return this.copy(t),t},r.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},r.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},r.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},r.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var a=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,e,i){i.negative=e.negative^t.negative;var n=t.length+e.length|0;i.length=n,n=n-1|0;var r=0|t.words[0],o=0|e.words[0],s=r*o,h=s/67108864|0;i.words[0]=67108863&s;for(var u=1;u<n;u++){for(var a=h>>>26,l=67108863&h,m=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=m;d++)a+=(s=(r=0|t.words[u-d|0])*(o=0|e.words[d])+l)/67108864|0,l=67108863&s;i.words[u]=0|l,h=0|a}return 0!==h?i.words[u]=0|h:i.length--,i.strip()}r.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var h=this.words[s],u=(16777215&(h<<r|o)).toString(16);n=0!=(o=h>>>24-r&16777215)||s!==this.length-1?a[6-u.length]+u+n:u+n,(r+=2)>=26&&(r-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var d=l[t],f=m[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modn(f).toString(t);n=(p=p.idivn(f)).isZero()?c+n:a[d-c.length]+c+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}i(!1,"Base should be between 2 and 36")},r.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},r.prototype.toJSON=function(){return this.toString(16)},r.prototype.toBuffer=function(t,e){return i(void 0!==o),this.toArrayLike(o,t,e)},r.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},r.prototype.toArrayLike=function(t,e,n){var r=this.byteLength(),o=n||Math.max(1,r);i(r<=o,"byte array longer than desired length"),i(o>0,"Requested array length <= 0"),this.strip();var s,h,u="le"===e,a=new t(o),l=this.clone();if(u){for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[h]=s;for(;h<o;h++)a[h]=0}else{for(h=0;h<o-r;h++)a[h]=0;for(h=0;!l.isZero();h++)s=l.andln(255),l.iushrn(8),a[o-h-1]=s}return a},r.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},r.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},r.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},r.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return 0!==this.negative},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this.strip()},r.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},r.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},r.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},r.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},r.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},r.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},r.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},r.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var n=0;n<i.length;n++)this.words[n]=e.words[n]^i.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this.strip()},r.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},r.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},r.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},r.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var r=0;r<e;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},r.prototype.notn=function(t){return this.clone().inotn(t)},r.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<r:this.words[n]&~(1<<r),this.strip()},r.prototype.iadd=function(t){var e,i,n;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(i=this,n=t):(i=t,n=this);for(var r=0,o=0;o<n.length;o++)this.words[o]=67108863&(e=(0|i.words[o])+(0|n.words[o])+r),r=e>>>26;for(;0!==r&&o<i.length;o++)this.words[o]=67108863&(e=(0|i.words[o])+r),r=e>>>26;if(this.length=i.length,0!==r)this.words[this.length]=r,this.length++;else if(i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this},r.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},r.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(i=this,n=t):(i=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|i.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<i.length;s++)o=(e=(0|i.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<i.length&&i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this.length=Math.max(this.length,s),i!==this&&(this.negative=1),this.strip()},r.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,e,i){var n,r,o,s=t.words,h=e.words,u=i.words,a=0,l=0|s[0],m=8191&l,d=l>>>13,f=0|s[1],p=8191&f,c=f>>>13,y=0|s[2],v=8191&y,g=y>>>13,M=0|s[3],w=8191&M,b=M>>>13,_=0|s[4],k=8191&_,x=_>>>13,S=0|s[5],A=8191&S,R=S>>>13,j=0|s[6],q=8191&j,B=j>>>13,D=0|s[7],K=8191&D,O=D>>>13,T=0|s[8],Z=8191&T,N=T>>>13,I=0|s[9],P=8191&I,C=I>>>13,E=0|h[0],L=8191&E,$=E>>>13,z=0|h[1],V=8191&z,F=z>>>13,U=0|h[2],H=8191&U,G=U>>>13,J=0|h[3],Q=8191&J,W=J>>>13,Y=0|h[4],X=8191&Y,tt=Y>>>13,et=0|h[5],it=8191&et,nt=et>>>13,rt=0|h[6],ot=8191&rt,st=rt>>>13,ht=0|h[7],ut=8191&ht,at=ht>>>13,lt=0|h[8],mt=8191<,dt=lt>>>13,ft=0|h[9],pt=8191&ft,ct=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var yt=(a+(n=Math.imul(m,L))|0)+((8191&(r=(r=Math.imul(m,$))+Math.imul(d,L)|0))<<13)|0;a=((o=Math.imul(d,$))+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(p,L),r=(r=Math.imul(p,$))+Math.imul(c,L)|0,o=Math.imul(c,$);var vt=(a+(n=n+Math.imul(m,V)|0)|0)+((8191&(r=(r=r+Math.imul(m,F)|0)+Math.imul(d,V)|0))<<13)|0;a=((o=o+Math.imul(d,F)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(v,L),r=(r=Math.imul(v,$))+Math.imul(g,L)|0,o=Math.imul(g,$),n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,F)|0)+Math.imul(c,V)|0,o=o+Math.imul(c,F)|0;var gt=(a+(n=n+Math.imul(m,H)|0)|0)+((8191&(r=(r=r+Math.imul(m,G)|0)+Math.imul(d,H)|0))<<13)|0;a=((o=o+Math.imul(d,G)|0)+(r>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(w,L),r=(r=Math.imul(w,$))+Math.imul(b,L)|0,o=Math.imul(b,$),n=n+Math.imul(v,V)|0,r=(r=r+Math.imul(v,F)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,F)|0,n=n+Math.imul(p,H)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(c,H)|0,o=o+Math.imul(c,G)|0;var Mt=(a+(n=n+Math.imul(m,Q)|0)|0)+((8191&(r=(r=r+Math.imul(m,W)|0)+Math.imul(d,Q)|0))<<13)|0;a=((o=o+Math.imul(d,W)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(k,L),r=(r=Math.imul(k,$))+Math.imul(x,L)|0,o=Math.imul(x,$),n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,F)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,F)|0,n=n+Math.imul(v,H)|0,r=(r=r+Math.imul(v,G)|0)+Math.imul(g,H)|0,o=o+Math.imul(g,G)|0,n=n+Math.imul(p,Q)|0,r=(r=r+Math.imul(p,W)|0)+Math.imul(c,Q)|0,o=o+Math.imul(c,W)|0;var wt=(a+(n=n+Math.imul(m,X)|0)|0)+((8191&(r=(r=r+Math.imul(m,tt)|0)+Math.imul(d,X)|0))<<13)|0;a=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(A,L),r=(r=Math.imul(A,$))+Math.imul(R,L)|0,o=Math.imul(R,$),n=n+Math.imul(k,V)|0,r=(r=r+Math.imul(k,F)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,F)|0,n=n+Math.imul(w,H)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,H)|0,o=o+Math.imul(b,G)|0,n=n+Math.imul(v,Q)|0,r=(r=r+Math.imul(v,W)|0)+Math.imul(g,Q)|0,o=o+Math.imul(g,W)|0,n=n+Math.imul(p,X)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(c,X)|0,o=o+Math.imul(c,tt)|0;var bt=(a+(n=n+Math.imul(m,it)|0)|0)+((8191&(r=(r=r+Math.imul(m,nt)|0)+Math.imul(d,it)|0))<<13)|0;a=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(q,L),r=(r=Math.imul(q,$))+Math.imul(B,L)|0,o=Math.imul(B,$),n=n+Math.imul(A,V)|0,r=(r=r+Math.imul(A,F)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,F)|0,n=n+Math.imul(k,H)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(x,H)|0,o=o+Math.imul(x,G)|0,n=n+Math.imul(w,Q)|0,r=(r=r+Math.imul(w,W)|0)+Math.imul(b,Q)|0,o=o+Math.imul(b,W)|0,n=n+Math.imul(v,X)|0,r=(r=r+Math.imul(v,tt)|0)+Math.imul(g,X)|0,o=o+Math.imul(g,tt)|0,n=n+Math.imul(p,it)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(c,it)|0,o=o+Math.imul(c,nt)|0;var _t=(a+(n=n+Math.imul(m,ot)|0)|0)+((8191&(r=(r=r+Math.imul(m,st)|0)+Math.imul(d,ot)|0))<<13)|0;a=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(K,L),r=(r=Math.imul(K,$))+Math.imul(O,L)|0,o=Math.imul(O,$),n=n+Math.imul(q,V)|0,r=(r=r+Math.imul(q,F)|0)+Math.imul(B,V)|0,o=o+Math.imul(B,F)|0,n=n+Math.imul(A,H)|0,r=(r=r+Math.imul(A,G)|0)+Math.imul(R,H)|0,o=o+Math.imul(R,G)|0,n=n+Math.imul(k,Q)|0,r=(r=r+Math.imul(k,W)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,W)|0,n=n+Math.imul(w,X)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(v,it)|0,r=(r=r+Math.imul(v,nt)|0)+Math.imul(g,it)|0,o=o+Math.imul(g,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(c,ot)|0,o=o+Math.imul(c,st)|0;var kt=(a+(n=n+Math.imul(m,ut)|0)|0)+((8191&(r=(r=r+Math.imul(m,at)|0)+Math.imul(d,ut)|0))<<13)|0;a=((o=o+Math.imul(d,at)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(Z,L),r=(r=Math.imul(Z,$))+Math.imul(N,L)|0,o=Math.imul(N,$),n=n+Math.imul(K,V)|0,r=(r=r+Math.imul(K,F)|0)+Math.imul(O,V)|0,o=o+Math.imul(O,F)|0,n=n+Math.imul(q,H)|0,r=(r=r+Math.imul(q,G)|0)+Math.imul(B,H)|0,o=o+Math.imul(B,G)|0,n=n+Math.imul(A,Q)|0,r=(r=r+Math.imul(A,W)|0)+Math.imul(R,Q)|0,o=o+Math.imul(R,W)|0,n=n+Math.imul(k,X)|0,r=(r=r+Math.imul(k,tt)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(w,it)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,it)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(v,ot)|0,r=(r=r+Math.imul(v,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,at)|0)+Math.imul(c,ut)|0,o=o+Math.imul(c,at)|0;var xt=(a+(n=n+Math.imul(m,mt)|0)|0)+((8191&(r=(r=r+Math.imul(m,dt)|0)+Math.imul(d,mt)|0))<<13)|0;a=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(P,L),r=(r=Math.imul(P,$))+Math.imul(C,L)|0,o=Math.imul(C,$),n=n+Math.imul(Z,V)|0,r=(r=r+Math.imul(Z,F)|0)+Math.imul(N,V)|0,o=o+Math.imul(N,F)|0,n=n+Math.imul(K,H)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(O,H)|0,o=o+Math.imul(O,G)|0,n=n+Math.imul(q,Q)|0,r=(r=r+Math.imul(q,W)|0)+Math.imul(B,Q)|0,o=o+Math.imul(B,W)|0,n=n+Math.imul(A,X)|0,r=(r=r+Math.imul(A,tt)|0)+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,n=n+Math.imul(k,it)|0,r=(r=r+Math.imul(k,nt)|0)+Math.imul(x,it)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,n=n+Math.imul(v,ut)|0,r=(r=r+Math.imul(v,at)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,at)|0,n=n+Math.imul(p,mt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(c,mt)|0,o=o+Math.imul(c,dt)|0;var St=(a+(n=n+Math.imul(m,pt)|0)|0)+((8191&(r=(r=r+Math.imul(m,ct)|0)+Math.imul(d,pt)|0))<<13)|0;a=((o=o+Math.imul(d,ct)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(P,V),r=(r=Math.imul(P,F))+Math.imul(C,V)|0,o=Math.imul(C,F),n=n+Math.imul(Z,H)|0,r=(r=r+Math.imul(Z,G)|0)+Math.imul(N,H)|0,o=o+Math.imul(N,G)|0,n=n+Math.imul(K,Q)|0,r=(r=r+Math.imul(K,W)|0)+Math.imul(O,Q)|0,o=o+Math.imul(O,W)|0,n=n+Math.imul(q,X)|0,r=(r=r+Math.imul(q,tt)|0)+Math.imul(B,X)|0,o=o+Math.imul(B,tt)|0,n=n+Math.imul(A,it)|0,r=(r=r+Math.imul(A,nt)|0)+Math.imul(R,it)|0,o=o+Math.imul(R,nt)|0,n=n+Math.imul(k,ot)|0,r=(r=r+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,at)|0)+Math.imul(b,ut)|0,o=o+Math.imul(b,at)|0,n=n+Math.imul(v,mt)|0,r=(r=r+Math.imul(v,dt)|0)+Math.imul(g,mt)|0,o=o+Math.imul(g,dt)|0;var At=(a+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,ct)|0)+Math.imul(c,pt)|0))<<13)|0;a=((o=o+Math.imul(c,ct)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(P,H),r=(r=Math.imul(P,G))+Math.imul(C,H)|0,o=Math.imul(C,G),n=n+Math.imul(Z,Q)|0,r=(r=r+Math.imul(Z,W)|0)+Math.imul(N,Q)|0,o=o+Math.imul(N,W)|0,n=n+Math.imul(K,X)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(O,X)|0,o=o+Math.imul(O,tt)|0,n=n+Math.imul(q,it)|0,r=(r=r+Math.imul(q,nt)|0)+Math.imul(B,it)|0,o=o+Math.imul(B,nt)|0,n=n+Math.imul(A,ot)|0,r=(r=r+Math.imul(A,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,n=n+Math.imul(k,ut)|0,r=(r=r+Math.imul(k,at)|0)+Math.imul(x,ut)|0,o=o+Math.imul(x,at)|0,n=n+Math.imul(w,mt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,mt)|0,o=o+Math.imul(b,dt)|0;var Rt=(a+(n=n+Math.imul(v,pt)|0)|0)+((8191&(r=(r=r+Math.imul(v,ct)|0)+Math.imul(g,pt)|0))<<13)|0;a=((o=o+Math.imul(g,ct)|0)+(r>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(P,Q),r=(r=Math.imul(P,W))+Math.imul(C,Q)|0,o=Math.imul(C,W),n=n+Math.imul(Z,X)|0,r=(r=r+Math.imul(Z,tt)|0)+Math.imul(N,X)|0,o=o+Math.imul(N,tt)|0,n=n+Math.imul(K,it)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(O,it)|0,o=o+Math.imul(O,nt)|0,n=n+Math.imul(q,ot)|0,r=(r=r+Math.imul(q,st)|0)+Math.imul(B,ot)|0,o=o+Math.imul(B,st)|0,n=n+Math.imul(A,ut)|0,r=(r=r+Math.imul(A,at)|0)+Math.imul(R,ut)|0,o=o+Math.imul(R,at)|0,n=n+Math.imul(k,mt)|0,r=(r=r+Math.imul(k,dt)|0)+Math.imul(x,mt)|0,o=o+Math.imul(x,dt)|0;var jt=(a+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,ct)|0)+Math.imul(b,pt)|0))<<13)|0;a=((o=o+Math.imul(b,ct)|0)+(r>>>13)|0)+(jt>>>26)|0,jt&=67108863,n=Math.imul(P,X),r=(r=Math.imul(P,tt))+Math.imul(C,X)|0,o=Math.imul(C,tt),n=n+Math.imul(Z,it)|0,r=(r=r+Math.imul(Z,nt)|0)+Math.imul(N,it)|0,o=o+Math.imul(N,nt)|0,n=n+Math.imul(K,ot)|0,r=(r=r+Math.imul(K,st)|0)+Math.imul(O,ot)|0,o=o+Math.imul(O,st)|0,n=n+Math.imul(q,ut)|0,r=(r=r+Math.imul(q,at)|0)+Math.imul(B,ut)|0,o=o+Math.imul(B,at)|0,n=n+Math.imul(A,mt)|0,r=(r=r+Math.imul(A,dt)|0)+Math.imul(R,mt)|0,o=o+Math.imul(R,dt)|0;var qt=(a+(n=n+Math.imul(k,pt)|0)|0)+((8191&(r=(r=r+Math.imul(k,ct)|0)+Math.imul(x,pt)|0))<<13)|0;a=((o=o+Math.imul(x,ct)|0)+(r>>>13)|0)+(qt>>>26)|0,qt&=67108863,n=Math.imul(P,it),r=(r=Math.imul(P,nt))+Math.imul(C,it)|0,o=Math.imul(C,nt),n=n+Math.imul(Z,ot)|0,r=(r=r+Math.imul(Z,st)|0)+Math.imul(N,ot)|0,o=o+Math.imul(N,st)|0,n=n+Math.imul(K,ut)|0,r=(r=r+Math.imul(K,at)|0)+Math.imul(O,ut)|0,o=o+Math.imul(O,at)|0,n=n+Math.imul(q,mt)|0,r=(r=r+Math.imul(q,dt)|0)+Math.imul(B,mt)|0,o=o+Math.imul(B,dt)|0;var Bt=(a+(n=n+Math.imul(A,pt)|0)|0)+((8191&(r=(r=r+Math.imul(A,ct)|0)+Math.imul(R,pt)|0))<<13)|0;a=((o=o+Math.imul(R,ct)|0)+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(P,ot),r=(r=Math.imul(P,st))+Math.imul(C,ot)|0,o=Math.imul(C,st),n=n+Math.imul(Z,ut)|0,r=(r=r+Math.imul(Z,at)|0)+Math.imul(N,ut)|0,o=o+Math.imul(N,at)|0,n=n+Math.imul(K,mt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(O,mt)|0,o=o+Math.imul(O,dt)|0;var Dt=(a+(n=n+Math.imul(q,pt)|0)|0)+((8191&(r=(r=r+Math.imul(q,ct)|0)+Math.imul(B,pt)|0))<<13)|0;a=((o=o+Math.imul(B,ct)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(P,ut),r=(r=Math.imul(P,at))+Math.imul(C,ut)|0,o=Math.imul(C,at),n=n+Math.imul(Z,mt)|0,r=(r=r+Math.imul(Z,dt)|0)+Math.imul(N,mt)|0,o=o+Math.imul(N,dt)|0;var Kt=(a+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,ct)|0)+Math.imul(O,pt)|0))<<13)|0;a=((o=o+Math.imul(O,ct)|0)+(r>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,n=Math.imul(P,mt),r=(r=Math.imul(P,dt))+Math.imul(C,mt)|0,o=Math.imul(C,dt);var Ot=(a+(n=n+Math.imul(Z,pt)|0)|0)+((8191&(r=(r=r+Math.imul(Z,ct)|0)+Math.imul(N,pt)|0))<<13)|0;a=((o=o+Math.imul(N,ct)|0)+(r>>>13)|0)+(Ot>>>26)|0,Ot&=67108863;var Tt=(a+(n=Math.imul(P,pt))|0)+((8191&(r=(r=Math.imul(P,ct))+Math.imul(C,pt)|0))<<13)|0;return a=((o=Math.imul(C,ct))+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,u[0]=yt,u[1]=vt,u[2]=gt,u[3]=Mt,u[4]=wt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=xt,u[9]=St,u[10]=At,u[11]=Rt,u[12]=jt,u[13]=qt,u[14]=Bt,u[15]=Dt,u[16]=Kt,u[17]=Ot,u[18]=Tt,0!==a&&(u[19]=a,i.length++),i};function p(t,e,i){return(new c).mulp(t,e,i)}function c(t,e){this.x=t,this.y=e}Math.imul||(f=d),r.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,e):i<63?d(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var n=0,r=0,o=0;o<i.length-1;o++){var s=r;r=0;for(var h=67108863&n,u=Math.min(o,e.length-1),a=Math.max(0,o-t.length+1);a<=u;a++){var l=(0|t.words[o-a])*(0|e.words[a]),m=67108863&l;h=67108863&(m=m+h|0),r+=(s=(s=s+(l/67108864|0)|0)+(m>>>26)|0)>>>26,s&=67108863}i.words[o]=h,n=s,s=r}return 0!==n?i.words[o]=n:i.length--,i.strip()}(this,t,e):p(this,t,e)},c.prototype.makeRBT=function(t){for(var e=new Array(t),i=r.prototype._countBits(t)-1,n=0;n<t;n++)e[n]=this.revBin(n,i,t);return e},c.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var n=0,r=0;r<e;r++)n|=(1&t)<<e-r-1,t>>=1;return n},c.prototype.permute=function(t,e,i,n,r,o){for(var s=0;s<o;s++)n[s]=e[t[s]],r[s]=i[t[s]]},c.prototype.transform=function(t,e,i,n,r,o){this.permute(o,t,e,i,n,r);for(var s=1;s<r;s<<=1)for(var h=s<<1,u=Math.cos(2*Math.PI/h),a=Math.sin(2*Math.PI/h),l=0;l<r;l+=h)for(var m=u,d=a,f=0;f<s;f++){var p=i[l+f],c=n[l+f],y=i[l+f+s],v=n[l+f+s],g=m*y-d*v;v=m*v+d*y,i[l+f]=p+(y=g),n[l+f]=c+v,i[l+f+s]=p-y,n[l+f+s]=c-v,f!==h&&(g=u*m-a*d,d=u*d+a*m,m=g)}},c.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),n=1&i,r=0;for(i=i/2|0;i;i>>>=1)r++;return 1<<r+1+n},c.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var n=0;n<i/2;n++){var r=t[n];t[n]=t[i-n-1],t[i-n-1]=r,r=e[n],e[n]=-e[i-n-1],e[i-n-1]=-r}},c.prototype.normalize13b=function(t,e){for(var i=0,n=0;n<e/2;n++){var r=8192*Math.round(t[2*n+1]/e)+Math.round(t[2*n]/e)+i;t[n]=67108863&r,i=r<67108864?0:r/67108864|0}return t},c.prototype.convert13b=function(t,e,n,r){for(var o=0,s=0;s<e;s++)n[2*s]=8191&(o+=0|t[s]),n[2*s+1]=8191&(o>>>=13),o>>>=13;for(s=2*e;s<r;++s)n[s]=0;i(0===o),i(0==(-8192&o))},c.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},c.prototype.mulp=function(t,e,i){var n=2*this.guessLen13b(t.length,e.length),r=this.makeRBT(n),o=this.stub(n),s=new Array(n),h=new Array(n),u=new Array(n),a=new Array(n),l=new Array(n),m=new Array(n),d=i.words;d.length=n,this.convert13b(t.words,t.length,s,n),this.convert13b(e.words,e.length,a,n),this.transform(s,o,h,u,n,r),this.transform(a,o,l,m,n,r);for(var f=0;f<n;f++){var p=h[f]*l[f]-u[f]*m[f];u[f]=h[f]*m[f]+u[f]*l[f],h[f]=p}return this.conjugate(h,u,n),this.transform(h,u,d,o,n,r),this.conjugate(d,o,n),this.normalize13b(d,n),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},r.prototype.mul=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},r.prototype.mulf=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),p(this,t,e)},r.prototype.imul=function(t){return this.clone().mulTo(t,this)},r.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,n=0;n<this.length;n++){var r=(0|this.words[n])*t,o=(67108863&r)+(67108863&e);e>>=26,e+=r/67108864|0,e+=o>>>26,this.words[n]=67108863&o}return 0!==e&&(this.words[n]=e,this.length++),this},r.prototype.muln=function(t){return this.clone().imuln(t)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var n=i%26;e[i]=(t.words[i/26|0]&1<<n)>>>n}return e}(t);if(0===e.length)return new r(1);for(var i=this,n=0;n<e.length&&0===e[n];n++,i=i.sqr());if(++n<e.length)for(var o=i.sqr();n<e.length;n++,o=o.sqr())0!==e[n]&&(i=i.mul(o));return i},r.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e<this.length;e++){var h=this.words[e]&o;this.words[e]=(0|this.words[e])-h<<n|s,s=h>>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==r){for(e=this.length-1;e>=0;e--)this.words[e+r]=this.words[e];for(e=0;e<r;e++)this.words[e]=0;this.length+=r}return this.strip()},r.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},r.prototype.iushrn=function(t,e,n){var r;i("number"==typeof t&&t>=0),r=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),h=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var a=0;a<s;a++)u.words[a]=this.words[a];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,a=0;a<this.length;a++)this.words[a]=this.words[a+s];else this.words[0]=0,this.length=1;var l=0;for(a=this.length-1;a>=0&&(0!==l||a>=r);a--){var m=0|this.words[a];this.words[a]=l<<26-o|m>>>o,l=m&h}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},r.prototype.ishrn=function(t,e,n){return i(0===this.negative),this.iushrn(t,e,n)},r.prototype.shln=function(t){return this.clone().ishln(t)},r.prototype.ushln=function(t){return this.clone().iushln(t)},r.prototype.shrn=function(t){return this.clone().ishrn(t)},r.prototype.ushrn=function(t){return this.clone().iushrn(t)},r.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;return!(this.length<=n||!(this.words[n]&1<<e))},r.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=n?this:(0!==e&&n++,this.length=Math.min(n,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},r.prototype.maskn=function(t){return this.clone().imaskn(t)},r.prototype.iaddn=function(t){return i("number"==typeof t),i(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},r.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},r.prototype.isubn=function(t){if(i("number"==typeof t),i(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this.strip()},r.prototype.addn=function(t){return this.clone().iaddn(t)},r.prototype.subn=function(t){return this.clone().isubn(t)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(t,e,n){var r,o;this._expand(t.length+n);var s=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+s;var h=(0|t.words[r])*e;s=((o-=67108863&h)>>26)-(h/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)s=(o=(0|this.words[r+n])+s)>>26,this.words[r+n]=67108863&o;if(0===s)return this.strip();for(i(-1===s),s=0,r=0;r<this.length;r++)s=(o=-(0|this.words[r])+s)>>26,this.words[r]=67108863&o;return this.negative=1,this.strip()},r.prototype._wordDiv=function(t,e){var i,n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(i=26-this._countBits(s))&&(o=o.ushln(i),n.iushln(i),s=0|o.words[o.length-1]);var h,u=n.length-o.length;if("mod"!==e){(h=new r(null)).length=u+1,h.words=new Array(h.length);for(var a=0;a<h.length;a++)h.words[a]=0}var l=n.clone()._ishlnsubmul(o,1,u);0===l.negative&&(n=l,h&&(h.words[u]=1));for(var m=u-1;m>=0;m--){var d=67108864*(0|n.words[o.length+m])+(0|n.words[o.length+m-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(o,d,m);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(o,1,m),n.isZero()||(n.negative^=1);h&&(h.words[m]=d)}return h&&h.strip(),n.strip(),"div"!==e&&0!==i&&n.iushrn(i),{div:h||null,mod:n}},r.prototype.divmod=function(t,e,n){return i(!t.isZero()),this.isZero()?{div:new r(0),mod:new r(0)}:0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,e),"mod"!==e&&(o=h.div.neg()),"div"!==e&&(s=h.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),e),"mod"!==e&&(o=h.div.neg()),{div:o,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),e),"div"!==e&&(s=h.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:h.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new r(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new r(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new r(this.modn(t.words[0]))}:this._wordDiv(t,e);var o,s,h},r.prototype.div=function(t){return this.divmod(t,"div",!1).div},r.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},r.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},r.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),r=t.andln(1),o=i.cmp(n);return o<0||1===r&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},r.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,n=0,r=this.length-1;r>=0;r--)n=(e*n+(0|this.words[r]))%t;return n},r.prototype.idivn=function(t){i(t<=67108863);for(var e=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*e;this.words[n]=r/t|0,e=r%t}return this.strip()},r.prototype.divn=function(t){return this.clone().idivn(t)},r.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o=new r(1),s=new r(0),h=new r(0),u=new r(1),a=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++a;for(var l=n.clone(),m=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(l),s.isub(m)),o.iushrn(1),s.iushrn(1);for(var p=0,c=1;0==(n.words[0]&c)&&p<26;++p,c<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(h.isOdd()||u.isOdd())&&(h.iadd(l),u.isub(m)),h.iushrn(1),u.iushrn(1);e.cmp(n)>=0?(e.isub(n),o.isub(h),s.isub(u)):(n.isub(e),h.isub(o),u.isub(s))}return{a:h,b:u,gcd:n.iushln(a)}},r.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o,s=new r(1),h=new r(0),u=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var a=0,l=1;0==(e.words[0]&l)&&a<26;++a,l<<=1);if(a>0)for(e.iushrn(a);a-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var m=0,d=1;0==(n.words[0]&d)&&m<26;++m,d<<=1);if(m>0)for(n.iushrn(m);m-- >0;)h.isOdd()&&h.iadd(u),h.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(h)):(n.isub(e),h.isub(s))}return(o=0===e.cmpn(1)?s:h).cmpn(0)<0&&o.iadd(t),o},r.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var n=0;e.isEven()&&i.isEven();n++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var r=e.cmp(i);if(r<0){var o=e;e=i,i=o}else if(0===r||0===i.cmpn(1))break;e.isub(i)}return i.iushln(n)},r.prototype.invm=function(t){return this.egcd(t).a.umod(t)},r.prototype.isEven=function(){return 0==(1&this.words[0])},r.prototype.isOdd=function(){return 1==(1&this.words[0])},r.prototype.andln=function(t){return this.words[0]&t},r.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,n=(t-e)/26,r=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var h=0|this.words[s];o=(h+=o)>>>26,this.words[s]=h&=67108863}return 0!==o&&(this.words[s]=o,this.length++),this},r.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},r.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)e=1;else{n&&(t=-t),i(t<=67108863,"Number is too big");var r=0|this.words[0];e=r===t?0:r<t?-1:1}return 0!==this.negative?0|-e:e},r.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},r.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var n=0|this.words[i],r=0|t.words[i];if(n!==r){n<r?e=-1:n>r&&(e=1);break}}return e},r.prototype.gtn=function(t){return 1===this.cmpn(t)},r.prototype.gt=function(t){return 1===this.cmp(t)},r.prototype.gten=function(t){return this.cmpn(t)>=0},r.prototype.gte=function(t){return this.cmp(t)>=0},r.prototype.ltn=function(t){return-1===this.cmpn(t)},r.prototype.lt=function(t){return-1===this.cmp(t)},r.prototype.lten=function(t){return this.cmpn(t)<=0},r.prototype.lte=function(t){return this.cmp(t)<=0},r.prototype.eqn=function(t){return 0===this.cmpn(t)},r.prototype.eq=function(t){return 0===this.cmp(t)},r.red=function(t){return new _(t)},r.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},r.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(t){return this.red=t,this},r.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},r.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},r.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},r.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},r.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},r.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},r.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},r.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},r.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new r(e,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function g(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var e=r._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function k(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new r(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new r(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:i.ucmp(this.p);return 0===n?(i.words[0]=0,i.length=1):n>0?i.isub(this.p):void 0!==i.strip?i.strip():i._strip(),i},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},n(g,v),g.prototype.split=function(t,e){for(var i=Math.min(t.length,9),n=0;n<i;n++)e.words[n]=t.words[n];if(e.length=i,t.length<=9)return t.words[0]=0,void(t.length=1);var r=t.words[9];for(e.words[e.length++]=4194303&r,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(4194303&o)<<4|r>>>22,r=o}t.words[n-10]=r>>>=22,t.length-=0===r&&t.length>10?10:9},g.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var n=0|t.words[i];t.words[i]=67108863&(e+=977*n),e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(M,v),n(w,v),n(b,v),b.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var n=19*(0|t.words[i])+e,r=67108863&n;n>>>=26,t.words[i]=r,e=n}return 0!==e&&(t.words[t.length++]=e),t},r._prime=function(t){if(y[t])return y[t];var e;if("k256"===t)e=new g;else if("p224"===t)e=new M;else if("p192"===t)e=new w;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new b}return y[t]=e,e},_.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},_.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},_.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},_.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},_.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},_.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},_.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var n=this.m.add(new r(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);i(!o.isZero());var h=new r(1).toRed(this),u=h.redNeg(),a=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new r(2*l*l).toRed(this);0!==this.pow(l,a).cmp(u);)l.redIAdd(u);for(var m=this.pow(l,o),d=this.pow(t,o.addn(1).iushrn(1)),f=this.pow(t,o),p=s;0!==f.cmp(h);){for(var c=f,y=0;0!==c.cmp(h);y++)c=c.redSqr();i(y<p);var v=this.pow(m,new r(1).iushln(p-y-1));d=d.redMul(v),m=v.redSqr(),f=f.redMul(m),p=y}return d},_.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},_.prototype.pow=function(t,e){if(e.isZero())return new r(1).toRed(this);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new r(1).toRed(this),i[1]=t;for(var n=2;n<i.length;n++)i[n]=this.mul(i[n-1],t);var o=i[0],s=0,h=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var a=e.words[n],l=u-1;l>=0;l--){var m=a>>l&1;o!==i[0]&&(o=this.sqr(o)),0!==m||0!==s?(s<<=1,s|=m,(4==++h||0===n&&0===l)&&(o=this.mul(o,i[s]),h=0,s=0)):h=0}u=26}return o},_.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},_.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},r.mont=function(t){return new k(t)},n(k,_),k.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},k.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},k.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=i.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},k.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new r(0)._forceRed(this);var i=t.mul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=i.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},k.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,u)}(i={path:void 0,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),i.exports}(),l=[{constant:!0,inputs:[{name:"",type:"address"}],name:"owners",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"bytes32"},{name:"",type:"address"}],name:"delegates",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"nonce",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"changed",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"owner",type:"address"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDOwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"delegateType",type:"bytes32"},{indexed:!1,name:"delegate",type:"address"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDDelegateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"identity",type:"address"},{indexed:!1,name:"name",type:"bytes32"},{indexed:!1,name:"value",type:"bytes"},{indexed:!1,name:"validTo",type:"uint256"},{indexed:!1,name:"previousChange",type:"uint256"}],name:"DIDAttributeChanged",type:"event"},{constant:!0,inputs:[{name:"identity",type:"address"}],name:"identityOwner",outputs:[{name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"validDelegate",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"newOwner",type:"address"}],name:"changeOwner",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"newOwner",type:"address"}],name:"changeOwnerSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"},{name:"validity",type:"uint256"}],name:"addDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegate",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"delegateType",type:"bytes32"},{name:"delegate",type:"address"}],name:"revokeDelegateSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"},{name:"validity",type:"uint256"}],name:"setAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttribute",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"identity",type:"address"},{name:"sigV",type:"uint8"},{name:"sigR",type:"bytes32"},{name:"sigS",type:"bytes32"},{name:"name",type:"bytes32"},{name:"value",type:"bytes"}],name:"revokeAttributeSigned",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"}];function m(t){return n.Buffer.from(s.keccak_256.arrayBuffer(t))}const d=new o.ec("secp256k1");function f(t){const e=(""+t).startsWith("0x")?t.slice(2):t,i=d.keyFromPublic(e,"hex").getPublic().encode("hex");return function(t){var e=t;const i=m(e=e.substring(2).toLowerCase());e=e.split("");for(var n=0;n<40;n+=2)i[n/2]>>4>=8&&(e[n]=e[n].toUpperCase()),(15&i[n/2])>=8&&(e[n+1]=e[n+1].toUpperCase());return"0x"+e.join("")}("0x"+m(n.Buffer.from(i.slice(2),"hex")).slice(-20).toString("hex"))}function p(t,e,i){if(!t.s){if(i instanceof y){if(!i.s)return void(i.o=p.bind(null,t,e));1&e&&(e=i.s),i=i.v}if(i&&i.then)return void i.then(p.bind(null,t,e),p.bind(null,t,2));t.s=e,t.v=i;const n=t.o;n&&n(t)}}const c="0xdca7ef03e98e0dc2b855be647c39abe984fcf21b",y=function(){function t(){}return t.prototype.then=function(e,i){const n=new t,r=this.s;if(r){const t=1&r?e:i;if(t){try{p(n,1,t(this.v))}catch(t){p(n,2,t)}return n}return this}return this.o=function(t){try{const r=t.v;1&t.s?p(n,1,e?e(r):r):i?p(n,1,i(r)):p(n,2,r)}catch(t){p(n,2,t)}},n},t}();function v(t){return t instanceof y&&1&t.s}const g=/^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/;function M(t){return n.Buffer.from(t.slice(2),"hex").toString("utf8").replace(/\0+$/,"")}function w(t){const e="0x"+n.Buffer.from(t).slice(0,32).toString("hex");return e+"0".repeat(66-e.length)}const b={Secp256k1SignatureAuthentication2018:w("sigAuth"),Secp256k1VerificationKey2018:w("veriKey")},_={sigAuth:"SignatureAuthentication2018",veriKey:"VerificationKey2018",enc:"KeyAgreementKey2019"};function k(t,e,i,r){const o=new a(Math.floor((new Date).getTime()/1e3)),s=[{id:t+"#controller",type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:e}],h=[{type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controller"}];i&&(s.push({id:t+"#controllerKey",type:"Secp256k1VerificationKey2018",controller:t,publicKeyHex:i}),h.push({type:"Secp256k1SignatureAuthentication2018",publicKey:t+"#controllerKey"}));let u=0;const l={},m={},d={};for(const e of r){const i=e.validTo,r=`${e._eventName}-${e.delegateType||e.name}-${e.delegate||e.value}`;if(i&&i.gte(o)){if("DIDDelegateChanged"===e._eventName)switch(u++,M(e.delegateType)){case"sigAuth":l[r]={type:"Secp256k1SignatureAuthentication2018",publicKey:`${t}#delegate-${u}`};case"veriKey":m[r]={id:`${t}#delegate-${u}`,type:"Secp256k1VerificationKey2018",controller:t,ethereumAddress:e.delegate}}else if("DIDAttributeChanged"===e._eventName){const i=M(e.name).match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/);if(i){const o=i[2],s=_[i[4]]||i[4],h=i[6];switch(i[1]){case"pub":{u++;const i={id:`${t}#delegate-${u}`,type:`${o}${s}`,controller:t};switch(h){case null:case void 0:case"hex":i.publicKeyHex=e.value.slice(2);break;case"base64":i.publicKeyBase64=n.Buffer.from(e.value.slice(2),"hex").toString("base64");break;case"base58":i.publicKeyBase58=n.Buffer.from(e.value.slice(2),"hex").toString("base58");break;case"pem":i.publicKeyPem=n.Buffer.from(e.value.slice(2),"hex").toString();break;default:i.value=e.value}m[r]=i;break}case"svc":d[r]={type:o,serviceEndpoint:n.Buffer.from(e.value.slice(2),"hex").toString()}}}}}else u>0&&("DIDDelegateChanged"===e._eventName||"DIDAttributeChanged"===e._eventName&&M(e.name).match(/^did\/pub\//))&&i.lt(o)&&u--,delete l[r],delete m[r],delete d[r]}const f={"@context":"https://w3id.org/did/v1",id:t,publicKey:s.concat(Object.values(m)),authentication:h.concat(Object.values(l))};return Object.values(d).length>0&&(f.service=Object.values(d)),f}function x(i={}){const n=function(e={}){return e.provider?e.provider:e.web3?e.web3.currentProvider:e.rpcUrl?new t(e.rpcUrl):null}(i);if(null===n)return null;const o=new e(n),s=i.registry||c;return{eth:o,registryAddress:s,didReg:new r(o)(l).at(s)}}function S(t=[]){const e={};for(let i=0;i<t.length;i++){const n=t[i];e[n.name]=x(n),null===e[n.name]&&console.warn("invalid configuration for "+n.name)}return e}module.exports={REGISTRY:c,bytes32toString:M,stringToBytes32:w,delegateTypes:b,attrTypes:_,wrapDidDocument:k,getResolver:function(t={}){const e=i.logDecoder(l,!1),n={mainnet:x(t),...S(t.networks)};return function(t={},e={}){if((e.provider||e.web3||e.rpcUrl)&&!t.mainnet)throw new Error("Ethereum provider configuration for mainnet was attempted but no valid configuration was provided.");if(e&&e.networks)for(const i of e.networks)if(!t[i.name])throw new Error(`Ethereum provider configuration for ${i.name} was attempted but no valid configuration was provided`);let i=0;for(const e of Object.keys(t))null!==t[e]&&i++;if(0===i)throw new Error("EthrDIDResolver requires a provider configuration for at least one network")}(n,t),{ethr:function(t,i){try{const r=i.id.match(g);if(!r)throw new Error("Not a valid ethr DID: "+t);const o=r[2],s=r[1]?r[1].slice(0,-1):"mainnet";if(!n[s])throw new Error("No conf for networkId: "+s);return Promise.resolve(function(t,i){try{const o=[];let{address:s,publicKey:h}=(r=t).length>42?{address:f(r),publicKey:r}:{address:r},u=s;return Promise.resolve(function(t,e){try{return Promise.resolve(n[e].didReg.changed(t)).then(function(t){if(t)return t[0]})}catch(t){return Promise.reject(t)}}(s,i)).then(function(t){function r(){function r(){return{controller:u,history:o,publicKey:h}}const a=function(t,e,i){for(var n;;){var r=t();if(v(r)&&(r=r.v),!r)return o;if(r.then){n=0;break}var o=i();if(o&&o.then){if(!v(o)){n=1;break}o=o.s}}var s=new y,h=p.bind(null,s,2);return(0===n?r.then(a):1===n?o.then(u):(void 0).then(function(){(r=t())?r.then?r.then(a).then(void 0,h):a(r):p(s,1,o)})).then(void 0,h),s;function u(e){o=e;do{if(!(r=t())||v(r)&&!r.v)return void p(s,1,o);if(r.then)return void r.then(a).then(void 0,h);v(o=i())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,h)}function a(t){t?(o=i())&&o.then?o.then(u).then(void 0,h):u(o):p(s,1,o)}}(function(){return!!t},0,function(){const r=t;return Promise.resolve(n[i].eth.getLogs({address:n[i].registryAddress,topics:[null,"0x000000000000000000000000"+s.slice(2)],fromBlock:t,toBlock:t})).then(function(i){const n=e(i);t=void 0;for(const e of n)o.unshift(e),e.previousChange.lt(r)&&(t=e.previousChange)})});return a&&a.then?a.then(r):r()}const a=function(){if(t)return Promise.resolve(n[i].didReg.identityOwner(s)).then(function(t){const e=""+t[0];e.toLowerCase()!==u.toLowerCase()&&(h=null),u=e})}();return a&&a.then?a.then(r):r()})}catch(t){return Promise.reject(t)}var r}(o,s)).then(function({controller:e,history:i,publicKey:n}){return k(t,e,n,i)})}catch(t){return Promise.reject(t)}}}},identifierMatcher:g}}); | ||
//# sourceMappingURL=ethr-did-resolver.umd.js.map |
{ | ||
"name": "ethr-did-resolver", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"description": "Resolve DID documents around ethereum addresses", | ||
@@ -62,3 +62,3 @@ "main": "dist/ethr-did-resolver.js", | ||
"jdom": "3.2.1", | ||
"jest": "26.4.1", | ||
"jest": "26.4.2", | ||
"microbundle": "0.12.3", | ||
@@ -65,0 +65,0 @@ "prettier": "2.0.5", |
@@ -40,3 +40,3 @@ --- | ||
The did resolver takes the ethereum address, checks for the current owner, looks at contract events and builds a simple DID document. | ||
The did resolver takes the ethereum address, checks for the current controller, looks at contract events and builds a simple DID document. | ||
@@ -50,9 +50,9 @@ The minimal DID document for a an ethereum address `0xb9c5714089478a327f09197987f16f9e5d936e8a` with no transactions to the registry looks like this: | ||
publicKey: [{ | ||
id: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#owner', | ||
id: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#controller', | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a', | ||
controller: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a', | ||
ethereumAddress: '0xb9c5714089478a327f09197987f16f9e5d936e8a'}], | ||
authentication: [{ | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#owner'}] | ||
publicKey: 'did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#controller'}] | ||
} | ||
@@ -69,7 +69,7 @@ ``` | ||
### Owner Address | ||
### Controller Address | ||
Each identity always has an owner address. By default it's the same as the identity address, but check the read only contract function `identityOwner(address identity)` on the deployed version of the EthrDIDRegistry contract. | ||
Each identity always has a controller address. By default it's the same as the identity address, but check the read only contract function `identityOwner(address identity)` on the deployed version of the EthrDIDRegistry contract. | ||
The Identity owner will always have a `publicKey` with the id set as the DID with the fragment `#owner` appended. | ||
The Identity controller will always have a `publicKey` with the id set as the DID with the fragment `#controller` appended. | ||
@@ -82,3 +82,3 @@ An entry is also added to the `authentication` array of the DID document with type `Secp256k1SignatureAuthentication2018`. | ||
- `DIDOwnerChanged` | ||
- `DIDOwnerChanged` (indicating a change of controller) | ||
- `DIDDelegateChanged` | ||
@@ -176,3 +176,3 @@ - `DIDAttributeChanged` | ||
type: "Secp256k1VerificationKey2018", | ||
owner: "did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74", | ||
controller: "did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74", | ||
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71' | ||
@@ -192,3 +192,3 @@ } | ||
type: "Ed25519VerificationKey2018", | ||
owner: "did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74", | ||
controller: "did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74", | ||
publicKeyBase64: "uXww3nZ/CEzjCAFo7ikwU7ozsjXXEWoyY9KfFFCTa3E=" | ||
@@ -209,3 +209,3 @@ } | ||
type: "X25519KeyAgreementKey2019", | ||
owner: "did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74", | ||
controller: "did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74", | ||
publicKeyBase64: "MCowBQYDK2VuAyEAEYVXd3/7B4d0NxpSsA/tdVYdz5deYcR1U+ZkphdmEFI=" | ||
@@ -252,3 +252,3 @@ } | ||
// getResolver will return an object with a key/value pair of { "ethr": resolver } where resolver is a function used by the generic did resolver. | ||
// getResolver will return an object with a key/value pair of { "ethr": resolver } where resolver is a function used by the generic did resolver. | ||
const ethrDidResolver = getResolver(providerConfig) | ||
@@ -289,4 +289,4 @@ const didResolver = new Resolver(ethrDidResolver) | ||
These providers will have to support and `eth_call`, `eth_getLogs` to be able to resolve DIDs specific to that network. | ||
These providers will have to support and `eth_call`, `eth_getLogs` to be able to resolve DIDs specific to that network. | ||
You can also override the default registry address by specifying a `registry` attribute per network. |
@@ -97,3 +97,3 @@ import { Resolver } from 'did-resolver' | ||
let registry, accounts, did, identity, owner, delegate1, delegate2, ethr, didResolver | ||
let registry, accounts, did, identity, controller, delegate1, delegate2, ethr, didResolver | ||
@@ -103,3 +103,3 @@ beforeAll(async () => { | ||
identity = accounts[1] | ||
owner = accounts[2] | ||
controller = accounts[2] | ||
delegate1 = accounts[3] | ||
@@ -125,5 +125,5 @@ delegate2 = accounts[4] | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: identity | ||
@@ -135,3 +135,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -150,11 +150,11 @@ ] | ||
{ | ||
id: `${pubdid}#owner`, | ||
id: `${pubdid}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: pubdid, | ||
controller: pubdid, | ||
ethereumAddress: identity | ||
}, | ||
{ | ||
id: `${pubdid}#ownerKey`, | ||
id: `${pubdid}#controllerKey`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: pubdid, | ||
controller: pubdid, | ||
publicKeyHex: pubKey | ||
@@ -166,7 +166,7 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${pubdid}#owner` | ||
publicKey: `${pubdid}#controller` | ||
}, | ||
{ | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${pubdid}#ownerKey` | ||
publicKey: `${pubdid}#controllerKey` | ||
} | ||
@@ -178,5 +178,5 @@ ] | ||
describe('owner changed', () => { | ||
describe('controller changed', () => { | ||
beforeAll(async () => { | ||
await registry.changeOwner(identity, owner, { from: identity }) | ||
await registry.changeOwner(identity, controller, { from: identity }) | ||
}) | ||
@@ -190,6 +190,6 @@ | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
} | ||
@@ -200,3 +200,3 @@ ], | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -207,3 +207,3 @@ ] | ||
it('changing owner invalidates the publicKey as identifier', async () => { | ||
it('changing controller invalidates the publicKey as identifier', async () => { | ||
const pubKey = '0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798' | ||
@@ -217,6 +217,6 @@ const pubdid = `did:ethr:${pubKey}` | ||
{ | ||
id: `${pubdid}#owner`, | ||
id: `${pubdid}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: pubdid, | ||
ethereumAddress: owner | ||
controller: pubdid, | ||
ethereumAddress: controller | ||
} | ||
@@ -227,3 +227,3 @@ ], | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${pubdid}#owner` | ||
publicKey: `${pubdid}#controller` | ||
} | ||
@@ -240,3 +240,3 @@ ] | ||
beforeAll(async () => { | ||
await registry.addDelegate(identity, Secp256k1VerificationKey2018, delegate1, 2, { from: owner }) | ||
await registry.addDelegate(identity, Secp256k1VerificationKey2018, delegate1, 2, { from: controller }) | ||
}) | ||
@@ -250,6 +250,6 @@ | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -259,3 +259,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate1 | ||
@@ -267,3 +267,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -277,3 +277,3 @@ ] | ||
beforeAll(async () => { | ||
await registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 10, { from: owner }) | ||
await registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 10, { from: controller }) | ||
}) | ||
@@ -287,6 +287,6 @@ | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -296,3 +296,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate1 | ||
@@ -303,3 +303,3 @@ }, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -311,3 +311,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -334,6 +334,6 @@ { | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -343,3 +343,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -351,3 +351,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -365,3 +365,3 @@ { | ||
beforeAll(async () => { | ||
await registry.revokeDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, { from: owner }) | ||
await registry.revokeDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, { from: controller }) | ||
await sleep(1) | ||
@@ -376,6 +376,6 @@ }) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
} | ||
@@ -386,3 +386,3 @@ ], | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -397,3 +397,3 @@ ] | ||
await sleep(3) | ||
await registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 86400, { from: owner }) | ||
await registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 86400, { from: controller }) | ||
}) | ||
@@ -407,6 +407,6 @@ | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -416,3 +416,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -424,3 +424,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -446,3 +446,3 @@ { | ||
10, | ||
{ from: owner } | ||
{ from: controller } | ||
) | ||
@@ -456,6 +456,6 @@ }) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -465,3 +465,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -472,3 +472,3 @@ }, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71' | ||
@@ -480,3 +480,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -499,3 +499,3 @@ { | ||
10, | ||
{ from: owner } | ||
{ from: controller } | ||
) | ||
@@ -510,6 +510,6 @@ }) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -519,3 +519,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -526,3 +526,3 @@ }, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71' | ||
@@ -533,3 +533,3 @@ }, | ||
type: 'Ed25519VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyBase64: Buffer.from( | ||
@@ -544,3 +544,3 @@ '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -563,3 +563,3 @@ { | ||
10, | ||
{ from: owner } | ||
{ from: controller } | ||
) | ||
@@ -574,6 +574,6 @@ }) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -583,3 +583,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -590,3 +590,3 @@ }, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71' | ||
@@ -597,3 +597,3 @@ }, | ||
type: 'Ed25519VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyBase64: Buffer.from( | ||
@@ -607,3 +607,3 @@ '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', | ||
type: 'RSAVerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyPem: '-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n' | ||
@@ -615,3 +615,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -652,5 +652,5 @@ { | ||
{ | ||
id: `${did1}#owner`, | ||
id: `${did1}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did1, | ||
controller: did1, | ||
ethereumAddress: identity1 | ||
@@ -661,3 +661,3 @@ }, | ||
type: 'X25519KeyAgreementKey2019', | ||
owner: did1, | ||
controller: did1, | ||
publicKeyBase64: 'MCowBQYDK2VuAyEAEYVXd3/7B4d0NxpSsA/tdVYdz5deYcR1U+ZkphdmEFI=' | ||
@@ -669,3 +669,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did1}#owner` | ||
publicKey: `${did1}#controller` | ||
} | ||
@@ -682,3 +682,3 @@ ] | ||
await registry.setAttribute(identity, stringToBytes32('did/svc/HubService'), 'https://hubs.uport.me', 10, { | ||
from: owner | ||
from: controller | ||
}) | ||
@@ -692,6 +692,6 @@ }) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -701,3 +701,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -708,3 +708,3 @@ }, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71' | ||
@@ -715,3 +715,3 @@ }, | ||
type: 'Ed25519VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyBase64: Buffer.from( | ||
@@ -725,3 +725,3 @@ '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', | ||
type: 'RSAVerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyPem: '-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n' | ||
@@ -733,3 +733,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -759,3 +759,3 @@ { | ||
'0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', | ||
{ from: owner } | ||
{ from: controller } | ||
) | ||
@@ -770,6 +770,6 @@ sleep(1) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -779,3 +779,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -786,3 +786,3 @@ }, | ||
type: 'Ed25519VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyBase64: Buffer.from( | ||
@@ -796,3 +796,3 @@ '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', | ||
type: 'RSAVerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyPem: '-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n' | ||
@@ -804,3 +804,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -828,3 +828,3 @@ { | ||
'0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', | ||
{ from: owner } | ||
{ from: controller } | ||
) | ||
@@ -839,6 +839,6 @@ sleep(1) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -848,3 +848,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -855,3 +855,3 @@ }, | ||
type: 'RSAVerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyPem: '-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n' | ||
@@ -863,3 +863,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -887,3 +887,3 @@ { | ||
'-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n', | ||
{ from: owner } | ||
{ from: controller } | ||
) | ||
@@ -899,6 +899,6 @@ sleep(1) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -908,3 +908,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -916,3 +916,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -939,3 +939,3 @@ { | ||
await registry.revokeAttribute(identity, stringToBytes32('did/svc/HubService'), 'https://hubs.uport.me', { | ||
from: owner | ||
from: controller | ||
}) | ||
@@ -951,6 +951,6 @@ sleep(1) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -960,3 +960,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -968,3 +968,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -987,6 +987,6 @@ { | ||
registry.setAttribute(identity, stringToBytes32('did/svc/TestService'), 'https://test.uport.me', 10, { | ||
from: owner | ||
from: controller | ||
}), | ||
registry.setAttribute(identity, stringToBytes32('did/svc/TestService'), 'https://test.uport.me', 10, { | ||
from: owner | ||
from: controller | ||
}), | ||
@@ -1003,6 +1003,6 @@ sleep(1).then(() => startMining()) | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
}, | ||
@@ -1012,3 +1012,3 @@ { | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: delegate2 | ||
@@ -1020,3 +1020,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
@@ -1023,0 +1023,0 @@ { |
@@ -23,5 +23,5 @@ import { Resolver } from 'did-resolver' | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: addr | ||
@@ -33,3 +33,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -51,5 +51,5 @@ ] | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: addr | ||
@@ -61,3 +61,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -79,5 +79,5 @@ ] | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: addr | ||
@@ -89,3 +89,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -105,5 +105,5 @@ ] | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: addr | ||
@@ -115,3 +115,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -131,5 +131,5 @@ ] | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: addr | ||
@@ -141,3 +141,3 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
@@ -158,11 +158,11 @@ ] | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: '0xf3beac30c498d9e26865f34fcaa57dbb935b0d74' | ||
}, | ||
{ | ||
id: `${did}#ownerKey`, | ||
id: `${did}#controllerKey`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
publicKeyHex: '0x03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479' | ||
@@ -174,7 +174,7 @@ } | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
}, | ||
{ | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#ownerKey` | ||
publicKey: `${did}#controllerKey` | ||
} | ||
@@ -181,0 +181,0 @@ ] |
@@ -34,3 +34,3 @@ import HttpProvider from 'ethjs-provider-http' | ||
function wrapDidDocument(did, owner, ownerKey, history) { | ||
function wrapDidDocument(did, controller, controllerKey, history) { | ||
const now = new BN(Math.floor(new Date().getTime() / 1000)) | ||
@@ -40,6 +40,6 @@ // const expired = {} | ||
{ | ||
id: `${did}#owner`, | ||
id: `${did}#controller`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
ethereumAddress: owner | ||
controller: did, | ||
ethereumAddress: controller | ||
} | ||
@@ -51,12 +51,12 @@ ] | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#owner` | ||
publicKey: `${did}#controller` | ||
} | ||
] | ||
if (ownerKey) { | ||
if (controllerKey) { | ||
publicKey.push({ | ||
id: `${did}#ownerKey`, | ||
id: `${did}#controllerKey`, | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
publicKeyHex: ownerKey | ||
controller: did, | ||
publicKeyHex: controllerKey | ||
}) | ||
@@ -66,3 +66,3 @@ | ||
type: 'Secp256k1SignatureAuthentication2018', | ||
publicKey: `${did}#ownerKey` | ||
publicKey: `${did}#controllerKey` | ||
}) | ||
@@ -93,3 +93,3 @@ } | ||
type: 'Secp256k1VerificationKey2018', | ||
owner: did, | ||
controller: did, | ||
ethereumAddress: event.delegate | ||
@@ -113,3 +113,3 @@ } | ||
type: `${algo}${type}`, | ||
owner: did | ||
controller: did | ||
} | ||
@@ -270,11 +270,11 @@ switch (encoding) { | ||
let { address, publicKey } = interpretIdentifier(identity) | ||
let owner = address | ||
let controller = address | ||
let previousChange = await lastChanged(address, networkId) | ||
if (previousChange) { | ||
const ownerRecord = await networks[networkId].didReg.identityOwner(address) | ||
const newOwner = '' + ownerRecord['0'] | ||
if (newOwner.toLowerCase() !== owner.toLowerCase()) { | ||
const controllerRecord = await networks[networkId].didReg.identityOwner(address) | ||
const newController = '' + controllerRecord['0'] | ||
if (newController.toLowerCase() !== controller.toLowerCase()) { | ||
publicKey = null | ||
} | ||
owner = newOwner | ||
controller = newController | ||
} | ||
@@ -298,3 +298,3 @@ while (previousChange) { | ||
} | ||
return { owner, history, publicKey } | ||
return { controller, history, publicKey } | ||
} | ||
@@ -309,4 +309,4 @@ async function resolve(did, parsed) { | ||
const { owner, history, publicKey } = await changeLog(id, networkId) | ||
return wrapDidDocument(did, owner, publicKey, history) | ||
const { controller, history, publicKey } = await changeLog(id, networkId) | ||
return wrapDidDocument(did, controller, publicKey, history) | ||
} | ||
@@ -313,0 +313,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
1020002
2327