@dodoex/wallet-web3 0.0.29-9 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/__node-resolve_empty-e1566f45.js +1 -0
  2. package/dist/__tslib-4d4076e0.js +1 -0
  3. package/dist/{blocto-afa3bd2f.js → blocto-946b5112.js} +1 -1
  4. package/dist/{bn-0d54f183.js → bn-5dd9f132.js} +1 -1
  5. package/dist/{browser-ponyfill-2b89ba5a.js → browser-ponyfill-61d16ee5.js} +1 -1
  6. package/dist/cjs/__node-resolve_empty-690ee38d.cjs +1 -0
  7. package/dist/cjs/__tslib-46c2c225.cjs +1 -0
  8. package/dist/cjs/{blocto-c82f60fd.cjs → blocto-3109a759.cjs} +2 -2
  9. package/dist/cjs/{bn-7519dfb9.cjs → bn-38430ff3.cjs} +1 -1
  10. package/dist/cjs/{browser-ponyfill-a2fe110e.cjs → browser-ponyfill-7d6670e8.cjs} +1 -1
  11. package/dist/cjs/{ethers-0cbd9a94.cjs → ethers-3911c609.cjs} +1 -1
  12. package/dist/cjs/{id-c1f8ef21.cjs → id-67b5e34a.cjs} +1 -1
  13. package/dist/cjs/{index-390f74d4.cjs → index-329ccca1.cjs} +1 -1
  14. package/dist/cjs/{index-851bfb86.cjs → index-52f26f3c.cjs} +1 -1
  15. package/dist/cjs/{index-bd265b4f.cjs → index-5a8ff274.cjs} +1 -1
  16. package/dist/cjs/{index-1438cc4a.cjs → index-69f728ba.cjs} +1 -1
  17. package/dist/cjs/{index-3da4db03.cjs → index-b0f5ff53.cjs} +1 -1
  18. package/dist/cjs/{index-bcd299f4.cjs → index-b43239cd.cjs} +1 -1
  19. package/dist/cjs/{index-7153e6ba.cjs → index-cf8b127f.cjs} +1 -1
  20. package/dist/cjs/{index-d018e2ad.cjs → index-d7d13ab0.cjs} +1 -1
  21. package/dist/cjs/{index-b6307a36.cjs → index-f88b47da.cjs} +2 -2
  22. package/dist/cjs/{index-41e51f13.cjs → index-fa663091.cjs} +1 -1
  23. package/dist/cjs/index.cjs +1 -1
  24. package/dist/cjs/index.es-a20773ea.cjs +9 -0
  25. package/dist/cjs/{interface-1b3e558c.cjs → interface-93744caa.cjs} +1 -1
  26. package/dist/cjs/{portis-413df2bf.cjs → portis-9ab2c756.cjs} +1 -1
  27. package/dist/cjs/{provider-db635447.cjs → provider-b01d5481.cjs} +1 -1
  28. package/dist/cjs/rainbow-5ae47af3.cjs +1 -0
  29. package/dist/cjs/{typed-data-7f7e9b45.cjs → typed-data-98ccfc5c.cjs} +1 -1
  30. package/dist/cjs/{uAuth-a1275c54.cjs → uAuth-85827a28.cjs} +1 -1
  31. package/dist/cjs/walletConnect-22739c95.cjs +1 -0
  32. package/dist/cjs/{walletLink-27c00203.cjs → walletLink-5383f285.cjs} +1 -1
  33. package/dist/{ethers-74dad587.js → ethers-9c596f50.js} +1 -1
  34. package/dist/{id-d7d5f03e.js → id-72712db8.js} +1 -1
  35. package/dist/{index-4dce94d5.js → index-0584962a.js} +1 -1
  36. package/dist/{index-6ecf854b.js → index-22bb9a54.js} +1 -1
  37. package/dist/{index-493779ab.js → index-449b3118.js} +1 -1
  38. package/dist/index-60d83ccb.js +1 -0
  39. package/dist/{index-be6f7624.js → index-630690bd.js} +1 -1
  40. package/dist/{index-cc5641ed.js → index-73cff2da.js} +1 -1
  41. package/dist/{index-d0eabf14.js → index-abd6d361.js} +1 -1
  42. package/dist/{index-85bfd871.js → index-e521c970.js} +1 -1
  43. package/dist/{index-d427f2bf.js → index-f880e28d.js} +1 -1
  44. package/dist/{index-74bba30f.js → index-faff7520.js} +1 -1
  45. package/dist/index.es-e74a0595.js +9 -0
  46. package/dist/index.js +1 -1
  47. package/dist/{interface-768e3325.js → interface-c011e37d.js} +1 -1
  48. package/dist/{portis-ce1ca3cf.js → portis-e988182d.js} +1 -1
  49. package/dist/{provider-7f913f49.js → provider-3043044d.js} +1 -1
  50. package/dist/rainbow-cc9c0f96.js +1 -0
  51. package/dist/{typed-data-dbd0df56.js → typed-data-175ea6bd.js} +1 -1
  52. package/dist/{uAuth-09917ec4.js → uAuth-1a754eae.js} +1 -1
  53. package/dist/walletConnect-fbd0fb87.js +1 -0
  54. package/dist/{walletLink-23f3e292.js → walletLink-ae49ebb7.js} +1 -1
  55. package/package.json +1 -1
  56. package/dist/__node-resolve_empty-791ff599.js +0 -1
  57. package/dist/__tslib-f57b178c.js +0 -1
  58. package/dist/cjs/__node-resolve_empty-8d047230.cjs +0 -1
  59. package/dist/cjs/__tslib-ba3a83a3.cjs +0 -1
  60. package/dist/cjs/index.es-40aefdd1.cjs +0 -9
  61. package/dist/cjs/rainbow-bd266faf.cjs +0 -1
  62. package/dist/cjs/walletConnect-d9d188f0.cjs +0 -1
  63. package/dist/index-876d4980.js +0 -1
  64. package/dist/index.es-b66a38fc.js +0 -9
  65. package/dist/rainbow-5b082b7d.js +0 -1
  66. package/dist/walletConnect-a0a95dd7.js +0 -1
@@ -1,7 +1,7 @@
1
- "use strict";var t=require("./index-bd265b4f.cjs"),e=require("buffer"),r=require("./__node-resolve_empty-8d047230.cjs"),n=require("./index-cf3bf3b5.cjs");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}require("@ethersproject/providers"),require("zustand"),require("events"),require("@ethersproject/address"),require("@ethersproject/constants"),require("@ethersproject/contracts"),require("@ethersproject/properties"),require("@ethersproject/transactions"),require("@ethersproject/bytes");var o=i(e),s={exports:{}};function a(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function u(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}const c={number:a,bool:function(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)},bytes:u,hash:function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");a(t.outputLen),a(t.blockLen)},exists:function(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")},output:function(t,e){u(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}},h=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),l=(t,e)=>t<<32-e|t>>>e;
1
+ "use strict";var t=require("./index-5a8ff274.cjs"),e=require("buffer"),r=require("./__node-resolve_empty-690ee38d.cjs"),n=require("./index-cf3bf3b5.cjs");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}require("@ethersproject/providers"),require("zustand"),require("events"),require("@ethersproject/address"),require("@ethersproject/constants"),require("@ethersproject/contracts"),require("@ethersproject/properties"),require("@ethersproject/transactions"),require("@ethersproject/bytes");var o=i(e),s={exports:{}};function a(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function u(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}const c={number:a,bool:function(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)},bytes:u,hash:function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");a(t.outputLen),a(t.blockLen)},exists:function(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")},output:function(t,e){u(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}},h=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),l=(t,e)=>t<<32-e|t>>>e;
2
2
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function d(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));class f{clone(){return this._cloneInto()}}function p(t){const e=e=>t().update(d(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}class m extends f{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=h(this.buffer)}update(t){c.exists(this);const{view:e,buffer:r,blockLen:n}=this,i=(t=d(t)).length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s!==n)r.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=h(t);for(;n<=i-o;o+=n)this.process(e,o)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){c.exists(this),c.output(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(r,0),o=0);for(let t=o;t<n;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,c=n?0:4;t.setUint32(e+u,s,n),t.setUint32(e+c,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const s=h(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<u;t++)s.setUint32(4*t,l[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=o,n%e&&t.buffer.set(r),t}}const g=BigInt(2**32-1),y=BigInt(32);function w(t,e=!1){return e?{h:Number(t&g),l:Number(t>>y&g)}:{h:0|Number(t>>y&g),l:0|Number(t&g)}}const b={fromBig:w,split:function(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:o,l:s}=w(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]},toBig:(t,e)=>BigInt(t>>>0)<<y|BigInt(e>>>0),shrSH:(t,e,r)=>t>>>r,shrSL:(t,e,r)=>t<<32-r|e>>>r,rotrSH:(t,e,r)=>t>>>r|e<<32-r,rotrSL:(t,e,r)=>t<<32-r|e>>>r,rotrBH:(t,e,r)=>t<<64-r|e>>>r-32,rotrBL:(t,e,r)=>t>>>r-32|e<<64-r,rotr32H:(t,e)=>e,rotr32L:(t,e)=>t,rotlSH:(t,e,r)=>t<<r|e>>>32-r,rotlSL:(t,e,r)=>e<<r|t>>>32-r,rotlBH:(t,e,r)=>e<<r-32|t>>>64-r,rotlBL:(t,e,r)=>t<<r-32|e>>>64-r,add:function(t,e,r,n){const i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:0|i}},add3L:(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),add3H:(t,e,r,n)=>e+r+n+(t/2**32|0)|0,add4L:(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),add4H:(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,add5H:(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0,add5L:(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0)},[v,k]=b.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((t=>BigInt(t)))),S=new Uint32Array(80),_=new Uint32Array(80);class A extends m{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:e,Bh:r,Bl:n,Ch:i,Cl:o,Dh:s,Dl:a,Eh:u,El:c,Fh:h,Fl:l,Gh:d,Gl:f,Hh:p,Hl:m}=this;return[t,e,r,n,i,o,s,a,u,c,h,l,d,f,p,m]}set(t,e,r,n,i,o,s,a,u,c,h,l,d,f,p,m){this.Ah=0|t,this.Al=0|e,this.Bh=0|r,this.Bl=0|n,this.Ch=0|i,this.Cl=0|o,this.Dh=0|s,this.Dl=0|a,this.Eh=0|u,this.El=0|c,this.Fh=0|h,this.Fl=0|l,this.Gh=0|d,this.Gl=0|f,this.Hh=0|p,this.Hl=0|m}process(t,e){for(let r=0;r<16;r++,e+=4)S[r]=t.getUint32(e),_[r]=t.getUint32(e+=4);for(let t=16;t<80;t++){const e=0|S[t-15],r=0|_[t-15],n=b.rotrSH(e,r,1)^b.rotrSH(e,r,8)^b.shrSH(e,r,7),i=b.rotrSL(e,r,1)^b.rotrSL(e,r,8)^b.shrSL(e,r,7),o=0|S[t-2],s=0|_[t-2],a=b.rotrSH(o,s,19)^b.rotrBH(o,s,61)^b.shrSH(o,s,6),u=b.rotrSL(o,s,19)^b.rotrBL(o,s,61)^b.shrSL(o,s,6),c=b.add4L(i,u,_[t-7],_[t-16]),h=b.add4H(c,n,a,S[t-7],S[t-16]);S[t]=0|h,_[t]=0|c}let{Ah:r,Al:n,Bh:i,Bl:o,Ch:s,Cl:a,Dh:u,Dl:c,Eh:h,El:l,Fh:d,Fl:f,Gh:p,Gl:m,Hh:g,Hl:y}=this;for(let t=0;t<80;t++){const e=b.rotrSH(h,l,14)^b.rotrSH(h,l,18)^b.rotrBH(h,l,41),w=b.rotrSL(h,l,14)^b.rotrSL(h,l,18)^b.rotrBL(h,l,41),A=h&d^~h&p,M=l&f^~l&m,I=b.add5L(y,w,M,k[t],_[t]),E=b.add5H(I,g,e,A,v[t],S[t]),x=0|I,B=b.rotrSH(r,n,28)^b.rotrBH(r,n,34)^b.rotrBH(r,n,39),P=b.rotrSL(r,n,28)^b.rotrBL(r,n,34)^b.rotrBL(r,n,39),R=r&i^r&s^i&s,T=n&o^n&a^o&a;g=0|p,y=0|m,p=0|d,m=0|f,d=0|h,f=0|l,({h:h,l:l}=b.add(0|u,0|c,0|E,0|x)),u=0|s,c=0|a,s=0|i,a=0|o,i=0|r,o=0|n;const L=b.add3L(x,P,T);r=b.add3H(L,E,B,R),n=0|L}({h:r,l:n}=b.add(0|this.Ah,0|this.Al,0|r,0|n)),({h:i,l:o}=b.add(0|this.Bh,0|this.Bl,0|i,0|o)),({h:s,l:a}=b.add(0|this.Ch,0|this.Cl,0|s,0|a)),({h:u,l:c}=b.add(0|this.Dh,0|this.Dl,0|u,0|c)),({h:h,l:l}=b.add(0|this.Eh,0|this.El,0|h,0|l)),({h:d,l:f}=b.add(0|this.Fh,0|this.Fl,0|d,0|f)),({h:p,l:m}=b.add(0|this.Gh,0|this.Gl,0|p,0|m)),({h:g,l:y}=b.add(0|this.Hh,0|this.Hl,0|g,0|y)),this.set(r,n,i,o,s,a,u,c,h,l,d,f,p,m,g,y)}roundClean(){S.fill(0),_.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class M extends A{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}class I extends A{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class E extends A{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}const x=p((()=>new A));p((()=>new M)),p((()=>new I)),p((()=>new E));
3
3
  /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
4
- const B=BigInt(0),P=BigInt(1),R=BigInt(2),T=BigInt(8),L=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),O=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:L,n:L,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),C=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),U=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const N=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),z=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),K=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),W=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class q{constructor(t,e,r,n){this.x=t,this.y=e,this.z=r,this.t=n}static fromAffine(t){if(!(t instanceof G))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return t.equals(G.ZERO)?q.ZERO:new q(t.x,t.y,P,st(t.x*t.y))}static toAffineBatch(t){const e=function(t,e=O.P){const r=new Array(t.length),n=t.reduce(((t,n,i)=>n===B?t:(r[i]=t,st(t*n,e))),P),i=at(n,e);return t.reduceRight(((t,n,i)=>n===B?t:(r[i]=st(t*r[i],e),st(t*n,e))),i),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return this.toAffineBatch(t).map(this.fromAffine)}equals(t){j(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:s}=t,a=st(e*s),u=st(i*n),c=st(r*s),h=st(o*n);return a===u&&c===h}negate(){return new q(st(-this.x),this.y,this.z,st(-this.t))}double(){const{x:t,y:e,z:r}=this,{a:n}=O,i=st(t*t),o=st(e*e),s=st(R*st(r*r)),a=st(n*i),u=t+e,c=st(st(u*u)-i-o),h=a+o,l=h-s,d=a-o,f=st(c*l),p=st(h*d),m=st(c*d),g=st(l*h);return new q(f,p,g,m)}add(t){j(t);const{x:e,y:r,z:n,t:i}=this,{x:o,y:s,z:a,t:u}=t,c=st((r-e)*(s+o)),h=st((r+e)*(s-o)),l=st(h-c);if(l===B)return this.double();const d=st(n*R*u),f=st(i*R*a),p=f+d,m=h+c,g=f-d,y=st(p*l),w=st(m*g),b=st(p*g),v=st(l*m);return new q(y,w,v,b)}subtract(t){return this.add(t.negate())}precomputeWindow(t){const e=1+256/t,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(q.BASE)&&(e=G.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&V.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=q.normalizeZ(n),V.set(e,n)));let i=q.ZERO,o=q.BASE;const s=1+256/r,a=2**(r-1),u=BigInt(2**r-1),c=2**r,h=BigInt(r);for(let e=0;e<s;e++){const r=e*a;let s=Number(t&u);t>>=h,s>a&&(s-=c,t+=P);const l=r,d=r+Math.abs(s)-1,f=e%2!=0,p=s<0;0===s?o=o.add(D(f,n[l])):i=i.add(D(p,n[d]))}return q.normalizeZ([i,o])[0]}multiply(t,e){return this.wNAF(ft(t,O.l),e)}multiplyUnsafe(t){let e=ft(t,O.l,!1);const r=q.BASE,n=q.ZERO;if(e===B)return n;if(this.equals(n)||e===P)return this;if(this.equals(r))return this.wNAF(e);let i=n,o=this;for(;e>B;)e&P&&(i=i.add(o)),o=o.double(),e>>=P;return i}isSmallOrder(){return this.multiplyUnsafe(O.h).equals(q.ZERO)}isTorsionFree(){let t=this.multiplyUnsafe(O.l/R).double();return O.l%R&&(t=t.add(this)),t.equals(q.ZERO)}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(q.ZERO);null==t&&(t=i?T:at(n));const o=st(e*t),s=st(r*t),a=st(n*t);if(i)return G.ZERO;if(a!==P)throw new Error("invZ was invalid");return new G(o,s)}fromRistrettoBytes(){F()}toRistrettoBytes(){F()}fromRistrettoHash(){F()}}function D(t,e){const r=e.negate();return t?r:e}function j(t){if(!(t instanceof q))throw new TypeError("ExtendedPoint expected")}function H(t){if(!(t instanceof $))throw new TypeError("RistrettoPoint expected")}function F(){throw new Error("Legacy method: switch to RistrettoPoint")}q.BASE=new q(O.Gx,O.Gy,P,st(O.Gx*O.Gy)),q.ZERO=new q(B,P,P,B);class ${constructor(t){this.ep=t}static calcElligatorRistrettoMap(t){const{d:e}=O,r=st(U*t*t),n=st((r+P)*K);let i=BigInt(-1);const o=st((i-e*r)*st(r+e));let{isValid:s,value:a}=ct(n,o),u=st(a*t);rt(u)||(u=st(-u)),s||(a=u),s||(i=r);const c=st(i*(r-P)*W-o),h=a*a,l=st((a+a)*o),d=st(c*N),f=st(P-h),p=st(P+h);return new q(st(l*p),st(f*d),st(d*p),st(l*f))}static hashToCurve(t){const e=ot((t=dt(t,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(e),n=ot(t.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new $(r.add(i))}static fromHex(t){t=dt(t,32);const{a:e,d:r}=O,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=ot(t);if(!function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(et(i),t)||rt(i))throw new Error(n);const o=st(i*i),s=st(P+e*o),a=st(P-e*o),u=st(s*s),c=st(a*a),h=st(e*r*u-c),{isValid:l,value:d}=ht(st(h*c)),f=st(d*a),p=st(d*f*h);let m=st((i+i)*f);rt(m)&&(m=st(-m));const g=st(s*p),y=st(m*g);if(!l||rt(y)||g===B)throw new Error(n);return new $(new q(m,g,P,y))}toRawBytes(){let{x:t,y:e,z:r,t:n}=this.ep;const i=st(st(r+e)*st(r-e)),o=st(t*e),s=st(o*o),{value:a}=ht(st(i*s)),u=st(a*i),c=st(a*o),h=st(u*c*n);let l;if(rt(n*h)){let r=st(e*U),n=st(t*U);t=r,e=n,l=st(u*z)}else l=c;rt(t*h)&&(e=st(-e));let d=st((r-e)*l);return rt(d)&&(d=st(-d)),et(d)}toHex(){return X(this.toRawBytes())}toString(){return this.toHex()}equals(t){H(t);const e=this.ep,r=t.ep,n=st(e.x*r.y)===st(e.y*r.x),i=st(e.y*r.y)===st(e.x*r.x);return n||i}add(t){return H(t),new $(this.ep.add(t.ep))}subtract(t){return H(t),new $(this.ep.subtract(t.ep))}multiply(t){return new $(this.ep.multiply(t))}multiplyUnsafe(t){return new $(this.ep.multiplyUnsafe(t))}}$.BASE=new $(q.BASE),$.ZERO=new $(q.ZERO);const V=new WeakMap;class G{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,V.delete(this)}static fromHex(t,e=!0){const{d:r,P:n}=O,i=(t=dt(t,32)).slice();i[31]=-129&t[31];const o=nt(i);if(e&&o>=n)throw new Error("Expected 0 < hex < P");if(!e&&o>=C)throw new Error("Expected 0 < hex < 2**256");const s=st(o*o),a=st(s-P),u=st(r*s+P);let{isValid:c,value:h}=ct(a,u);if(!c)throw new Error("Point.fromHex: invalid y coordinate");const l=(h&P)===P;return 0!=(128&t[31])!==l&&(h=st(-h)),new G(h,o)}static async fromPrivateKey(t){return(await wt(t)).point}toRawBytes(){const t=et(this.y);return t[31]|=this.x&P?128:0,t}toHex(){return X(this.toRawBytes())}toX25519(){const{y:t}=this;return et(st((P+t)*at(P-t)))}isTorsionFree(){return q.fromAffine(this).isTorsionFree()}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new G(st(-this.x),this.y)}add(t){return q.fromAffine(this).add(q.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return q.fromAffine(this).multiply(t,this).toAffine()}}G.BASE=new G(O.Gx,O.Gy),G.ZERO=new G(B,P);class Z{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=dt(t,64),r=G.fromHex(e.slice(0,32),!1),n=nt(e.slice(32,64));return new Z(r,n)}assertValidity(){const{r:t,s:e}=this;if(!(t instanceof G))throw new Error("Expected Point instance");return ft(e,O.l,!1),this}toRawBytes(){const t=new Uint8Array(64);return t.set(this.r.toRawBytes()),t.set(et(this.s),32),t}toHex(){return X(this.toRawBytes())}}function Y(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const J=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function X(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=J[t[r]];return e}function Q(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function tt(t){return Q(t.toString(16).padStart(64,"0"))}function et(t){return tt(t).reverse()}function rt(t){return(st(t)&P)===P}function nt(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+X(Uint8Array.from(t).reverse()))}const it=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function ot(t){return st(nt(t)&it)}function st(t,e=O.P){const r=t%e;return r>=B?r:e+r}function at(t,e=O.P){if(t===B||e<=B)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=st(t,e),n=e,i=B,o=P;for(;r!==B;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==P)throw new Error("invert: does not exist");return st(i,e)}function ut(t,e){const{P:r}=O;let n=t;for(;e-- >B;)n*=n,n%=r;return n}function ct(t,e){const r=st(e*e*e),n=function(t){const{P:e}=O,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),s=BigInt(80),a=t*t%e*t%e,u=ut(a,R)*a%e,c=ut(u,P)*t%e,h=ut(c,r)*c%e,l=ut(h,n)*h%e,d=ut(l,i)*l%e,f=ut(d,o)*d%e,p=ut(f,s)*f%e,m=ut(p,s)*f%e,g=ut(m,n)*h%e;return{pow_p_5_8:ut(g,R)*t%e,b2:a}}(t*st(r*r*e)).pow_p_5_8;let i=st(t*r*n);const o=st(e*i*i),s=i,a=st(i*U),u=o===t,c=o===st(-t),h=o===st(-t*U);return u&&(i=s),(c||h)&&(i=a),rt(i)&&(i=st(-i)),{isValid:u||c,value:i}}function ht(t){return ct(P,t)}function lt(t){return st(nt(t),O.l)}function dt(t,e){const r=t instanceof Uint8Array?Uint8Array.from(t):Q(t);if("number"==typeof e&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function ft(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if("number"==typeof t&&Number.isSafeInteger(t)&&(t=BigInt(t)),"bigint"==typeof t&&t<e)if(r){if(B<t)return t}else if(B<=t)return t;throw new TypeError("Expected valid scalar: 0 < scalar < max")}function pt(t){if(32!==(t="bigint"==typeof t||"number"==typeof t?tt(ft(t,C)):dt(t)).length)throw new Error("Expected 32 bytes");return t}function mt(t){const e=function(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}(t.slice(0,32)),r=t.slice(32,64),n=lt(e),i=G.BASE.multiply(n),o=i.toRawBytes();return{head:e,prefix:r,scalar:n,point:i,pointBytes:o}}let gt;function yt(...t){if("function"!=typeof gt)throw new Error("utils.sha512Sync must be set to use sync methods");return gt(...t)}async function wt(t){return mt(await St.sha512(pt(t)))}function bt(t){return mt(yt(pt(t)))}const vt={getExtendedPublicKey:bt,getPublicKey:function(t){return bt(t).pointBytes},sign:function(t,e){t=dt(t);const{prefix:r,scalar:n,pointBytes:i}=bt(e),o=lt(yt(r,t)),s=G.BASE.multiply(o),a=st(o+lt(yt(s.toRawBytes(),i,t))*n,O.l);return new Z(s,a).toRawBytes()},verify:function(t,e,r){const{r:n,SB:i,msg:o,pub:s}=function(t,e,r){e=dt(e),r instanceof G||(r=G.fromHex(r,!1));const{r:n,s:i}=t instanceof Z?t.assertValidity():Z.fromHex(t);return{r:n,s:i,SB:q.BASE.multiplyUnsafe(i),pub:r,msg:e}}(t,e,r),a=yt(n.toRawBytes(),s.toRawBytes(),o);return function(t,e,r,n){const i=lt(n),o=q.fromAffine(t).multiplyUnsafe(i);return q.fromAffine(e).add(o).subtract(r).multiplyUnsafe(O.h).equals(q.ZERO)}(s,n,i,a)}};G.BASE._setWindowSize(8);const kt={node:r.nodeCrypto,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},St={bytesToHex:X,hexToBytes:Q,concatBytes:Y,getExtendedPublicKey:wt,mod:st,invert:at,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if((t=dt(t)).length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return st(nt(t),O.l-P)+P},randomBytes:(t=32)=>{if(kt.web)return kt.web.getRandomValues(new Uint8Array(t));if(kt.node){const{randomBytes:e}=kt.node;return new Uint8Array(e(t).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>St.randomBytes(32),sha512:async(...t)=>{const e=Y(...t);if(kt.web){const t=await kt.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(t)}if(kt.node)return Uint8Array.from(kt.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")},precompute(t=8,e=G.BASE){const r=e.equals(G.BASE)?e:new G(e.x,e.y);return r._setWindowSize(t),r.multiply(R),r},sha512Sync:void 0};Object.defineProperties(St,{sha512Sync:{configurable:!1,get:()=>gt,set(t){gt||(gt=t)}}});var _t={exports:{}};!function(t,e){function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function o(t,e,r){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof t?t.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r.require$$0.Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(!1,"Invalid character in "+t)}function u(t,e,r){var n=a(t,r);return r-1>=e&&(n|=a(t,r-1)<<4),n}function c(t,e,r,i){for(var o=0,s=0,a=Math.min(t.length,r),u=e;u<a;u++){var c=t.charCodeAt(u)-48;o*=i,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<i,"Invalid character"),o+=s}return o}function h(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(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,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,r):(this._parseBase(t,e,i),"le"===r&&this._initArray(this.toArray(),e,r)))},o.prototype._initNumber=function(t,e,r){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):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},o.prototype._initArray=function(t,e,r){if(n("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 i=0;i<this.length;i++)this.words[i]=0;var o,s,a=0;if("be"===r)for(i=t.length-1,o=0;i>=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===r)for(i=0,o=0;i<t.length;i+=3)s=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},o.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,o=0,s=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;this._strip()},o.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var o=t.length-r,s=o%n,a=Math.min(o,o-s)+r,u=0,h=r;h<a;h+=n)u=c(t,h,h+n,e),this.imuln(i),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==s){var l=1;for(u=c(t,h,t.length,e),h=0;h<s;h++)l*=e;this.imuln(l),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},o.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},o.prototype._move=function(t){h(t,this)},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},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","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"],f=[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],p=[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 m(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,u=s/67108864|0;r.words[0]=a;for(var c=1;c<n;c++){for(var h=u>>>26,l=67108863&u,d=Math.min(c,e.length-1),f=Math.max(0,c-t.length+1);f<=d;f++){var p=c-f|0;h+=(s=(i=0|t.words[p])*(o=0|e.words[f])+l)/67108864|0,l=67108863&s}r.words[c]=0|l,u=0|h}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var i=0,o=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<i|o)).toString(16);o=a>>>24-i&16777215,(i+=2)>=26&&(i-=26,s--),r=0!==o||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==o&&(r=o.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=f[t],h=p[t];r="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modrn(h).toString(t);r=(l=l.idivn(h)).isZero()?m+r:d[c-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!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&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},s&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var i=this.byteLength(),o=r||Math.max(1,i);n(i<=o,"byte array longer than desired length"),n(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,i),s},o.prototype._toArrayLikeLE=function(t,e){for(var r=0,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r++]=255&s,r<t.length&&(t[r++]=s>>8&255),r<t.length&&(t[r++]=s>>16&255),6===o?(r<t.length&&(t[r++]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r<t.length)for(t[r++]=n;r<t.length;)t[r++]=0},o.prototype._toArrayLikeBE=function(t,e){for(var r=t.length-1,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r--]=255&s,r>=0&&(t[r--]=s>>8&255),r>=0&&(t[r--]=s>>16&255),6===o?(r>=0&&(t[r--]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r>=0)for(t[r--]=n;r>=0;)t[r--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)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 e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return n(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 e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return n(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 e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return n(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){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,i=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<i:this.words[r]&~(1<<i),this._strip()},o.prototype.iadd=function(t){var e,r,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?(r=this,n=t):(r=t,n=this);for(var i=0,o=0;o<n.length;o++)e=(0|r.words[o])+(0|n.words[o])+i,this.words[o]=67108863&e,i=e>>>26;for(;0!==i&&o<r.length;o++)e=(0|r.words[o])+i,this.words[o]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this},o.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)},o.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 r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|r.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<r.length;s++)o=(e=(0|r.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var g=function(t,e,r){var n,i,o,s=t.words,a=e.words,u=r.words,c=0,h=0|s[0],l=8191&h,d=h>>>13,f=0|s[1],p=8191&f,m=f>>>13,g=0|s[2],y=8191&g,w=g>>>13,b=0|s[3],v=8191&b,k=b>>>13,S=0|s[4],_=8191&S,A=S>>>13,M=0|s[5],I=8191&M,E=M>>>13,x=0|s[6],B=8191&x,P=x>>>13,R=0|s[7],T=8191&R,L=R>>>13,O=0|s[8],C=8191&O,U=O>>>13,N=0|s[9],z=8191&N,K=N>>>13,W=0|a[0],q=8191&W,D=W>>>13,j=0|a[1],H=8191&j,F=j>>>13,$=0|a[2],V=8191&$,G=$>>>13,Z=0|a[3],Y=8191&Z,J=Z>>>13,X=0|a[4],Q=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,nt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ut=8191&at,ct=at>>>13,ht=0|a[8],lt=8191&ht,dt=ht>>>13,ft=0|a[9],pt=8191&ft,mt=ft>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(c+(n=Math.imul(l,q))|0)+((8191&(i=(i=Math.imul(l,D))+Math.imul(d,q)|0))<<13)|0;c=((o=Math.imul(d,D))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(p,q),i=(i=Math.imul(p,D))+Math.imul(m,q)|0,o=Math.imul(m,D);var yt=(c+(n=n+Math.imul(l,H)|0)|0)+((8191&(i=(i=i+Math.imul(l,F)|0)+Math.imul(d,H)|0))<<13)|0;c=((o=o+Math.imul(d,F)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,q),i=(i=Math.imul(y,D))+Math.imul(w,q)|0,o=Math.imul(w,D),n=n+Math.imul(p,H)|0,i=(i=i+Math.imul(p,F)|0)+Math.imul(m,H)|0,o=o+Math.imul(m,F)|0;var wt=(c+(n=n+Math.imul(l,V)|0)|0)+((8191&(i=(i=i+Math.imul(l,G)|0)+Math.imul(d,V)|0))<<13)|0;c=((o=o+Math.imul(d,G)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(v,q),i=(i=Math.imul(v,D))+Math.imul(k,q)|0,o=Math.imul(k,D),n=n+Math.imul(y,H)|0,i=(i=i+Math.imul(y,F)|0)+Math.imul(w,H)|0,o=o+Math.imul(w,F)|0,n=n+Math.imul(p,V)|0,i=(i=i+Math.imul(p,G)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,G)|0;var bt=(c+(n=n+Math.imul(l,Y)|0)|0)+((8191&(i=(i=i+Math.imul(l,J)|0)+Math.imul(d,Y)|0))<<13)|0;c=((o=o+Math.imul(d,J)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(_,q),i=(i=Math.imul(_,D))+Math.imul(A,q)|0,o=Math.imul(A,D),n=n+Math.imul(v,H)|0,i=(i=i+Math.imul(v,F)|0)+Math.imul(k,H)|0,o=o+Math.imul(k,F)|0,n=n+Math.imul(y,V)|0,i=(i=i+Math.imul(y,G)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,G)|0,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,J)|0;var vt=(c+(n=n+Math.imul(l,Q)|0)|0)+((8191&(i=(i=i+Math.imul(l,tt)|0)+Math.imul(d,Q)|0))<<13)|0;c=((o=o+Math.imul(d,tt)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(I,q),i=(i=Math.imul(I,D))+Math.imul(E,q)|0,o=Math.imul(E,D),n=n+Math.imul(_,H)|0,i=(i=i+Math.imul(_,F)|0)+Math.imul(A,H)|0,o=o+Math.imul(A,F)|0,n=n+Math.imul(v,V)|0,i=(i=i+Math.imul(v,G)|0)+Math.imul(k,V)|0,o=o+Math.imul(k,G)|0,n=n+Math.imul(y,Y)|0,i=(i=i+Math.imul(y,J)|0)+Math.imul(w,Y)|0,o=o+Math.imul(w,J)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var kt=(c+(n=n+Math.imul(l,rt)|0)|0)+((8191&(i=(i=i+Math.imul(l,nt)|0)+Math.imul(d,rt)|0))<<13)|0;c=((o=o+Math.imul(d,nt)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(B,q),i=(i=Math.imul(B,D))+Math.imul(P,q)|0,o=Math.imul(P,D),n=n+Math.imul(I,H)|0,i=(i=i+Math.imul(I,F)|0)+Math.imul(E,H)|0,o=o+Math.imul(E,F)|0,n=n+Math.imul(_,V)|0,i=(i=i+Math.imul(_,G)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,G)|0,n=n+Math.imul(v,Y)|0,i=(i=i+Math.imul(v,J)|0)+Math.imul(k,Y)|0,o=o+Math.imul(k,J)|0,n=n+Math.imul(y,Q)|0,i=(i=i+Math.imul(y,tt)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,tt)|0,n=n+Math.imul(p,rt)|0,i=(i=i+Math.imul(p,nt)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,nt)|0;var St=(c+(n=n+Math.imul(l,ot)|0)|0)+((8191&(i=(i=i+Math.imul(l,st)|0)+Math.imul(d,ot)|0))<<13)|0;c=((o=o+Math.imul(d,st)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(T,q),i=(i=Math.imul(T,D))+Math.imul(L,q)|0,o=Math.imul(L,D),n=n+Math.imul(B,H)|0,i=(i=i+Math.imul(B,F)|0)+Math.imul(P,H)|0,o=o+Math.imul(P,F)|0,n=n+Math.imul(I,V)|0,i=(i=i+Math.imul(I,G)|0)+Math.imul(E,V)|0,o=o+Math.imul(E,G)|0,n=n+Math.imul(_,Y)|0,i=(i=i+Math.imul(_,J)|0)+Math.imul(A,Y)|0,o=o+Math.imul(A,J)|0,n=n+Math.imul(v,Q)|0,i=(i=i+Math.imul(v,tt)|0)+Math.imul(k,Q)|0,o=o+Math.imul(k,tt)|0,n=n+Math.imul(y,rt)|0,i=(i=i+Math.imul(y,nt)|0)+Math.imul(w,rt)|0,o=o+Math.imul(w,nt)|0,n=n+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0;var _t=(c+(n=n+Math.imul(l,ut)|0)|0)+((8191&(i=(i=i+Math.imul(l,ct)|0)+Math.imul(d,ut)|0))<<13)|0;c=((o=o+Math.imul(d,ct)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(C,q),i=(i=Math.imul(C,D))+Math.imul(U,q)|0,o=Math.imul(U,D),n=n+Math.imul(T,H)|0,i=(i=i+Math.imul(T,F)|0)+Math.imul(L,H)|0,o=o+Math.imul(L,F)|0,n=n+Math.imul(B,V)|0,i=(i=i+Math.imul(B,G)|0)+Math.imul(P,V)|0,o=o+Math.imul(P,G)|0,n=n+Math.imul(I,Y)|0,i=(i=i+Math.imul(I,J)|0)+Math.imul(E,Y)|0,o=o+Math.imul(E,J)|0,n=n+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,tt)|0,n=n+Math.imul(v,rt)|0,i=(i=i+Math.imul(v,nt)|0)+Math.imul(k,rt)|0,o=o+Math.imul(k,nt)|0,n=n+Math.imul(y,ot)|0,i=(i=i+Math.imul(y,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,n=n+Math.imul(p,ut)|0,i=(i=i+Math.imul(p,ct)|0)+Math.imul(m,ut)|0,o=o+Math.imul(m,ct)|0;var At=(c+(n=n+Math.imul(l,lt)|0)|0)+((8191&(i=(i=i+Math.imul(l,dt)|0)+Math.imul(d,lt)|0))<<13)|0;c=((o=o+Math.imul(d,dt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(z,q),i=(i=Math.imul(z,D))+Math.imul(K,q)|0,o=Math.imul(K,D),n=n+Math.imul(C,H)|0,i=(i=i+Math.imul(C,F)|0)+Math.imul(U,H)|0,o=o+Math.imul(U,F)|0,n=n+Math.imul(T,V)|0,i=(i=i+Math.imul(T,G)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,G)|0,n=n+Math.imul(B,Y)|0,i=(i=i+Math.imul(B,J)|0)+Math.imul(P,Y)|0,o=o+Math.imul(P,J)|0,n=n+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(_,rt)|0,i=(i=i+Math.imul(_,nt)|0)+Math.imul(A,rt)|0,o=o+Math.imul(A,nt)|0,n=n+Math.imul(v,ot)|0,i=(i=i+Math.imul(v,st)|0)+Math.imul(k,ot)|0,o=o+Math.imul(k,st)|0,n=n+Math.imul(y,ut)|0,i=(i=i+Math.imul(y,ct)|0)+Math.imul(w,ut)|0,o=o+Math.imul(w,ct)|0,n=n+Math.imul(p,lt)|0,i=(i=i+Math.imul(p,dt)|0)+Math.imul(m,lt)|0,o=o+Math.imul(m,dt)|0;var Mt=(c+(n=n+Math.imul(l,pt)|0)|0)+((8191&(i=(i=i+Math.imul(l,mt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((o=o+Math.imul(d,mt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(z,H),i=(i=Math.imul(z,F))+Math.imul(K,H)|0,o=Math.imul(K,F),n=n+Math.imul(C,V)|0,i=(i=i+Math.imul(C,G)|0)+Math.imul(U,V)|0,o=o+Math.imul(U,G)|0,n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,Y)|0,o=o+Math.imul(L,J)|0,n=n+Math.imul(B,Q)|0,i=(i=i+Math.imul(B,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,n=n+Math.imul(I,rt)|0,i=(i=i+Math.imul(I,nt)|0)+Math.imul(E,rt)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,n=n+Math.imul(v,ut)|0,i=(i=i+Math.imul(v,ct)|0)+Math.imul(k,ut)|0,o=o+Math.imul(k,ct)|0,n=n+Math.imul(y,lt)|0,i=(i=i+Math.imul(y,dt)|0)+Math.imul(w,lt)|0,o=o+Math.imul(w,dt)|0;var It=(c+(n=n+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;c=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(z,V),i=(i=Math.imul(z,G))+Math.imul(K,V)|0,o=Math.imul(K,G),n=n+Math.imul(C,Y)|0,i=(i=i+Math.imul(C,J)|0)+Math.imul(U,Y)|0,o=o+Math.imul(U,J)|0,n=n+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,tt)|0,n=n+Math.imul(B,rt)|0,i=(i=i+Math.imul(B,nt)|0)+Math.imul(P,rt)|0,o=o+Math.imul(P,nt)|0,n=n+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(_,ut)|0,i=(i=i+Math.imul(_,ct)|0)+Math.imul(A,ut)|0,o=o+Math.imul(A,ct)|0,n=n+Math.imul(v,lt)|0,i=(i=i+Math.imul(v,dt)|0)+Math.imul(k,lt)|0,o=o+Math.imul(k,dt)|0;var Et=(c+(n=n+Math.imul(y,pt)|0)|0)+((8191&(i=(i=i+Math.imul(y,mt)|0)+Math.imul(w,pt)|0))<<13)|0;c=((o=o+Math.imul(w,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(z,Y),i=(i=Math.imul(z,J))+Math.imul(K,Y)|0,o=Math.imul(K,J),n=n+Math.imul(C,Q)|0,i=(i=i+Math.imul(C,tt)|0)+Math.imul(U,Q)|0,o=o+Math.imul(U,tt)|0,n=n+Math.imul(T,rt)|0,i=(i=i+Math.imul(T,nt)|0)+Math.imul(L,rt)|0,o=o+Math.imul(L,nt)|0,n=n+Math.imul(B,ot)|0,i=(i=i+Math.imul(B,st)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,st)|0,n=n+Math.imul(I,ut)|0,i=(i=i+Math.imul(I,ct)|0)+Math.imul(E,ut)|0,o=o+Math.imul(E,ct)|0,n=n+Math.imul(_,lt)|0,i=(i=i+Math.imul(_,dt)|0)+Math.imul(A,lt)|0,o=o+Math.imul(A,dt)|0;var xt=(c+(n=n+Math.imul(v,pt)|0)|0)+((8191&(i=(i=i+Math.imul(v,mt)|0)+Math.imul(k,pt)|0))<<13)|0;c=((o=o+Math.imul(k,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(z,Q),i=(i=Math.imul(z,tt))+Math.imul(K,Q)|0,o=Math.imul(K,tt),n=n+Math.imul(C,rt)|0,i=(i=i+Math.imul(C,nt)|0)+Math.imul(U,rt)|0,o=o+Math.imul(U,nt)|0,n=n+Math.imul(T,ot)|0,i=(i=i+Math.imul(T,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,n=n+Math.imul(B,ut)|0,i=(i=i+Math.imul(B,ct)|0)+Math.imul(P,ut)|0,o=o+Math.imul(P,ct)|0,n=n+Math.imul(I,lt)|0,i=(i=i+Math.imul(I,dt)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,dt)|0;var Bt=(c+(n=n+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,mt)|0)+Math.imul(A,pt)|0))<<13)|0;c=((o=o+Math.imul(A,mt)|0)+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(z,rt),i=(i=Math.imul(z,nt))+Math.imul(K,rt)|0,o=Math.imul(K,nt),n=n+Math.imul(C,ot)|0,i=(i=i+Math.imul(C,st)|0)+Math.imul(U,ot)|0,o=o+Math.imul(U,st)|0,n=n+Math.imul(T,ut)|0,i=(i=i+Math.imul(T,ct)|0)+Math.imul(L,ut)|0,o=o+Math.imul(L,ct)|0,n=n+Math.imul(B,lt)|0,i=(i=i+Math.imul(B,dt)|0)+Math.imul(P,lt)|0,o=o+Math.imul(P,dt)|0;var Pt=(c+(n=n+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,mt)|0)+Math.imul(E,pt)|0))<<13)|0;c=((o=o+Math.imul(E,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(z,ot),i=(i=Math.imul(z,st))+Math.imul(K,ot)|0,o=Math.imul(K,st),n=n+Math.imul(C,ut)|0,i=(i=i+Math.imul(C,ct)|0)+Math.imul(U,ut)|0,o=o+Math.imul(U,ct)|0,n=n+Math.imul(T,lt)|0,i=(i=i+Math.imul(T,dt)|0)+Math.imul(L,lt)|0,o=o+Math.imul(L,dt)|0;var Rt=(c+(n=n+Math.imul(B,pt)|0)|0)+((8191&(i=(i=i+Math.imul(B,mt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((o=o+Math.imul(P,mt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(z,ut),i=(i=Math.imul(z,ct))+Math.imul(K,ut)|0,o=Math.imul(K,ct),n=n+Math.imul(C,lt)|0,i=(i=i+Math.imul(C,dt)|0)+Math.imul(U,lt)|0,o=o+Math.imul(U,dt)|0;var Tt=(c+(n=n+Math.imul(T,pt)|0)|0)+((8191&(i=(i=i+Math.imul(T,mt)|0)+Math.imul(L,pt)|0))<<13)|0;c=((o=o+Math.imul(L,mt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(z,lt),i=(i=Math.imul(z,dt))+Math.imul(K,lt)|0,o=Math.imul(K,dt);var Lt=(c+(n=n+Math.imul(C,pt)|0)|0)+((8191&(i=(i=i+Math.imul(C,mt)|0)+Math.imul(U,pt)|0))<<13)|0;c=((o=o+Math.imul(U,mt)|0)+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863;var Ot=(c+(n=Math.imul(z,pt))|0)+((8191&(i=(i=Math.imul(z,mt))+Math.imul(K,pt)|0))<<13)|0;return c=((o=Math.imul(K,mt))+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,u[0]=gt,u[1]=yt,u[2]=wt,u[3]=bt,u[4]=vt,u[5]=kt,u[6]=St,u[7]=_t,u[8]=At,u[9]=Mt,u[10]=It,u[11]=Et,u[12]=xt,u[13]=Bt,u[14]=Pt,u[15]=Rt,u[16]=Tt,u[17]=Lt,u[18]=Ot,0!==c&&(u[19]=c,r.length++),r};function y(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,o=0;o<r.length-1;o++){var s=i;i=0;for(var a=67108863&n,u=Math.min(o,e.length-1),c=Math.max(0,o-t.length+1);c<=u;c++){var h=o-c,l=(0|t.words[h])*(0|e.words[c]),d=67108863&l;a=67108863&(d=d+a|0),i+=(s=(s=s+(l/67108864|0)|0)+(d>>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r._strip()}function w(t,e,r){return y(t,e,r)}Math.imul||(g=m),o.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?m(this,t,e):r<1024?y(this,t,e):w(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),w(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),n("number"==typeof t),n(t<67108864);for(var r=0,i=0;i<this.length;i++){var o=(0|this.words[i])*t,s=(67108863&o)+(67108863&r);r>>=26,r+=o/67108864|0,r+=s>>>26,this.words[i]=67108863&s}return 0!==r&&(this.words[i]=r,this.length++),e?this.ineg():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 e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=t.words[n]>>>i&1}return e}(t);if(0===e.length)return new o(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var i=r.sqr();n<e.length;n++,i=i.sqr())0!==e[n]&&(r=r.mul(i));return r},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,i=(t-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,u=(0|this.words[e])-a<<r;this.words[e]=u|s,s=a>>>26-r}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this._strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,r){var i;n("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,u=r;if(i-=s,i=Math.max(0,i),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var h=0;for(c=this.length-1;c>=0&&(0!==h||c>=i);c--){var l=0|this.words[c];this.words[c]=h<<26-o|l>>>o,h=l&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},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){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,i=1<<e;return!(this.length<=r||!(this.words[r]&i))},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return n("number"==typeof t),n(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 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},o.prototype.isubn=function(t){if(n("number"==typeof t),n(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()},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,e,r){var i,o,s=t.length+r;this._expand(s);var a=0;for(i=0;i<t.length;i++){o=(0|this.words[i+r])+a;var u=(0|t.words[i])*e;a=((o-=67108863&u)>>26)-(u/67108864|0),this.words[i+r]=67108863&o}for(;i<this.length-r;i++)a=(o=(0|this.words[i+r])+a)>>26,this.words[i+r]=67108863&o;if(0===a)return this._strip();for(n(-1===a),a=0,i=0;i<this.length;i++)a=(o=-(0|this.words[i])+a)>>26,this.words[i]=67108863&o;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),i=t,s=0|i.words[i.length-1];0!=(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,u=n.length-i.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var h=n.clone()._ishlnsubmul(i,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var d=67108864*(0|n.words[i.length+l])+(0|n.words[i.length+l-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(i,d,l);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(i,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var i,s,a},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 e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=(1<<26)%t,i=0,o=this.length-1;o>=0;o--)i=(r*i+(0|this.words[o]))%t;return e?-i:i},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var o=(0|this.words[i])+67108864*r;this.words[i]=o/t|0,r=o%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var h=r.clone(),l=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;)(i.isOdd()||s.isOdd())&&(i.iadd(h),s.isub(l)),i.iushrn(1),s.iushrn(1);for(var p=0,m=1;0==(r.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(l)),a.iushrn(1),u.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(a),s.isub(u)):(r.isub(e),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,h=1;0==(e.words[0]&h)&&c<26;++c,h<<=1);if(c>0)for(e.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,d=1;0==(r.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(r.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a)):(r.isub(e),a.isub(s))}return(i=0===e.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var o=e;e=r,r=o}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.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){n("number"==typeof t);var e=t%26,r=(t-e)/26,i=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var o=i,s=r;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}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 e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},o.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},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},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 M(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(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 n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function k(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function S(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function _(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function M(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function I(t){M.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 e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},i(k,v),k.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),i=0;i<n;i++)e.words[i]=t.words[i];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&r,i=10;i<t.length;i++){var s=0|t.words[i];t.words[i-10]=(s&r)<<4|o>>>22,o=s}o>>>=22,t.words[i-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},k.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},i(S,v),i(_,v),i(A,v),A.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new k;else if("p224"===t)e=new S;else if("p192"===t)e=new _;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return b[t]=e,e},M.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},M.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},M.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(h(t,t.umod(this.m)._forceRed(this)),t)},M.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},M.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},M.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},M.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},M.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},M.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},M.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},M.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},M.prototype.isqr=function(t){return this.imul(t,t.clone())},M.prototype.sqr=function(t){return this.mul(t,t)},M.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new o(2*h*h).toRed(this);0!==this.pow(h,c).cmp(u);)h.redIAdd(u);for(var l=this.pow(h,i),d=this.pow(t,i.addn(1).iushrn(1)),f=this.pow(t,i),p=s;0!==f.cmp(a);){for(var m=f,g=0;0!==m.cmp(a);g++)m=m.redSqr();n(g<p);var y=this.pow(l,new o(1).iushln(p-g-1));d=d.redMul(y),l=y.redSqr(),f=f.redMul(l),p=g}return d},M.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},M.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var i=r[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var c=e.words[n],h=u-1;h>=0;h--){var l=c>>h&1;i!==r[0]&&(i=this.sqr(i)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===h)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}u=26}return i},M.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},M.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new I(t)},i(I,M),I.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},I.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},I.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},I.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},I.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(_t,t.commonjsGlobal);var At=_t.exports,Mt=n.safeBuffer.exports.Buffer;var It=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=n}var s=t.length,a=t.charAt(0),u=Math.log(s)/Math.log(256),c=Math.log(256)/Math.log(s);function h(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return Mt.alloc(0);for(var r=0,n=0,i=0;t[r]===a;)n++,r++;for(var o=(t.length-r)*u+1>>>0,c=new Uint8Array(o);t[r];){var h=e[t.charCodeAt(r)];if(255===h)return;for(var l=0,d=o-1;(0!==h||l<i)&&-1!==d;d--,l++)h+=s*c[d]>>>0,c[d]=h%256>>>0,h=h/256>>>0;if(0!==h)throw new Error("Non-zero carry");i=l,r++}for(var f=o-i;f!==o&&0===c[f];)f++;var p=Mt.allocUnsafe(n+(o-f));p.fill(0,0,n);for(var m=n;f!==o;)p[m++]=c[f++];return p}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=Mt.from(e)),!Mt.isBuffer(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,n=0,i=0,o=e.length;i!==o&&0===e[i];)i++,r++;for(var u=(o-i)*c+1>>>0,h=new Uint8Array(u);i!==o;){for(var l=e[i],d=0,f=u-1;(0!==l||d<n)&&-1!==f;f--,d++)l+=256*h[f]>>>0,h[f]=l%s>>>0,l=l/s>>>0;if(0!==l)throw new Error("Non-zero carry");n=d,i++}for(var p=u-n;p!==u&&0===h[p];)p++;for(var m=a.repeat(r);p<u;++p)m+=t.charAt(h[p]);return m},decodeUnsafe:h,decode:function(t){var e=h(t);if(e)return e;throw new Error("Non-base"+s+" character")}}},Et=It("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const xt=(t,e,r)=>t&e^t&r^e&r,Bt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Pt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rt=new Uint32Array(64);class Tt extends m{constructor(){super(64,32,8,!1),this.A=0|Pt[0],this.B=0|Pt[1],this.C=0|Pt[2],this.D=0|Pt[3],this.E=0|Pt[4],this.F=0|Pt[5],this.G=0|Pt[6],this.H=0|Pt[7]}get(){const{A:t,B:e,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[t,e,r,n,i,o,s,a]}set(t,e,r,n,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)Rt[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=Rt[t-15],r=Rt[t-2],n=l(e,7)^l(e,18)^e>>>3,i=l(r,17)^l(r,19)^r>>>10;Rt[t]=i+Rt[t-7]+n+Rt[t-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let t=0;t<64;t++){const e=c+(l(s,6)^l(s,11)^l(s,25))+((h=s)&a^~h&u)+Bt[t]+Rt[t]|0,d=(l(r,2)^l(r,13)^l(r,22))+xt(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+d|0}var h;r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){Rt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Lt extends Tt{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const Ot=p((()=>new Tt));p((()=>new Lt));var Ct={},Ut={exports:{}};function Nt(t,e,r){return e<=t&&t<=r}function zt(t){if(void 0===t)return{};if(t===Object(t))return t;throw TypeError("Could not convert argument to dictionary")}!function(t,e){function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function o(t,e,r){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof t?t.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r.require$$0.Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(!1,"Invalid character in "+t)}function u(t,e,r){var n=a(t,r);return r-1>=e&&(n|=a(t,r-1)<<4),n}function c(t,e,r,i){for(var o=0,s=0,a=Math.min(t.length,r),u=e;u<a;u++){var c=t.charCodeAt(u)-48;o*=i,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<i,"Invalid character"),o+=s}return o}function h(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(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,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,r):(this._parseBase(t,e,i),"le"===r&&this._initArray(this.toArray(),e,r)))},o.prototype._initNumber=function(t,e,r){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):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},o.prototype._initArray=function(t,e,r){if(n("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 i=0;i<this.length;i++)this.words[i]=0;var o,s,a=0;if("be"===r)for(i=t.length-1,o=0;i>=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===r)for(i=0,o=0;i<t.length;i+=3)s=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},o.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,o=0,s=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;this._strip()},o.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var o=t.length-r,s=o%n,a=Math.min(o,o-s)+r,u=0,h=r;h<a;h+=n)u=c(t,h,h+n,e),this.imuln(i),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==s){var l=1;for(u=c(t,h,t.length,e),h=0;h<s;h++)l*=e;this.imuln(l),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},o.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},o.prototype._move=function(t){h(t,this)},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},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","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"],f=[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],p=[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 m(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,u=s/67108864|0;r.words[0]=a;for(var c=1;c<n;c++){for(var h=u>>>26,l=67108863&u,d=Math.min(c,e.length-1),f=Math.max(0,c-t.length+1);f<=d;f++){var p=c-f|0;h+=(s=(i=0|t.words[p])*(o=0|e.words[f])+l)/67108864|0,l=67108863&s}r.words[c]=0|l,u=0|h}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var i=0,o=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<i|o)).toString(16);o=a>>>24-i&16777215,(i+=2)>=26&&(i-=26,s--),r=0!==o||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==o&&(r=o.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=f[t],h=p[t];r="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modrn(h).toString(t);r=(l=l.idivn(h)).isZero()?m+r:d[c-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!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&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},s&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var i=this.byteLength(),o=r||Math.max(1,i);n(i<=o,"byte array longer than desired length"),n(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,i),s},o.prototype._toArrayLikeLE=function(t,e){for(var r=0,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r++]=255&s,r<t.length&&(t[r++]=s>>8&255),r<t.length&&(t[r++]=s>>16&255),6===o?(r<t.length&&(t[r++]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r<t.length)for(t[r++]=n;r<t.length;)t[r++]=0},o.prototype._toArrayLikeBE=function(t,e){for(var r=t.length-1,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r--]=255&s,r>=0&&(t[r--]=s>>8&255),r>=0&&(t[r--]=s>>16&255),6===o?(r>=0&&(t[r--]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r>=0)for(t[r--]=n;r>=0;)t[r--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)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 e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return n(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 e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return n(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 e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return n(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){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,i=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<i:this.words[r]&~(1<<i),this._strip()},o.prototype.iadd=function(t){var e,r,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?(r=this,n=t):(r=t,n=this);for(var i=0,o=0;o<n.length;o++)e=(0|r.words[o])+(0|n.words[o])+i,this.words[o]=67108863&e,i=e>>>26;for(;0!==i&&o<r.length;o++)e=(0|r.words[o])+i,this.words[o]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this},o.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)},o.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 r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|r.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<r.length;s++)o=(e=(0|r.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var g=function(t,e,r){var n,i,o,s=t.words,a=e.words,u=r.words,c=0,h=0|s[0],l=8191&h,d=h>>>13,f=0|s[1],p=8191&f,m=f>>>13,g=0|s[2],y=8191&g,w=g>>>13,b=0|s[3],v=8191&b,k=b>>>13,S=0|s[4],_=8191&S,A=S>>>13,M=0|s[5],I=8191&M,E=M>>>13,x=0|s[6],B=8191&x,P=x>>>13,R=0|s[7],T=8191&R,L=R>>>13,O=0|s[8],C=8191&O,U=O>>>13,N=0|s[9],z=8191&N,K=N>>>13,W=0|a[0],q=8191&W,D=W>>>13,j=0|a[1],H=8191&j,F=j>>>13,$=0|a[2],V=8191&$,G=$>>>13,Z=0|a[3],Y=8191&Z,J=Z>>>13,X=0|a[4],Q=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,nt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ut=8191&at,ct=at>>>13,ht=0|a[8],lt=8191&ht,dt=ht>>>13,ft=0|a[9],pt=8191&ft,mt=ft>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(c+(n=Math.imul(l,q))|0)+((8191&(i=(i=Math.imul(l,D))+Math.imul(d,q)|0))<<13)|0;c=((o=Math.imul(d,D))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(p,q),i=(i=Math.imul(p,D))+Math.imul(m,q)|0,o=Math.imul(m,D);var yt=(c+(n=n+Math.imul(l,H)|0)|0)+((8191&(i=(i=i+Math.imul(l,F)|0)+Math.imul(d,H)|0))<<13)|0;c=((o=o+Math.imul(d,F)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,q),i=(i=Math.imul(y,D))+Math.imul(w,q)|0,o=Math.imul(w,D),n=n+Math.imul(p,H)|0,i=(i=i+Math.imul(p,F)|0)+Math.imul(m,H)|0,o=o+Math.imul(m,F)|0;var wt=(c+(n=n+Math.imul(l,V)|0)|0)+((8191&(i=(i=i+Math.imul(l,G)|0)+Math.imul(d,V)|0))<<13)|0;c=((o=o+Math.imul(d,G)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(v,q),i=(i=Math.imul(v,D))+Math.imul(k,q)|0,o=Math.imul(k,D),n=n+Math.imul(y,H)|0,i=(i=i+Math.imul(y,F)|0)+Math.imul(w,H)|0,o=o+Math.imul(w,F)|0,n=n+Math.imul(p,V)|0,i=(i=i+Math.imul(p,G)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,G)|0;var bt=(c+(n=n+Math.imul(l,Y)|0)|0)+((8191&(i=(i=i+Math.imul(l,J)|0)+Math.imul(d,Y)|0))<<13)|0;c=((o=o+Math.imul(d,J)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(_,q),i=(i=Math.imul(_,D))+Math.imul(A,q)|0,o=Math.imul(A,D),n=n+Math.imul(v,H)|0,i=(i=i+Math.imul(v,F)|0)+Math.imul(k,H)|0,o=o+Math.imul(k,F)|0,n=n+Math.imul(y,V)|0,i=(i=i+Math.imul(y,G)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,G)|0,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,J)|0;var vt=(c+(n=n+Math.imul(l,Q)|0)|0)+((8191&(i=(i=i+Math.imul(l,tt)|0)+Math.imul(d,Q)|0))<<13)|0;c=((o=o+Math.imul(d,tt)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(I,q),i=(i=Math.imul(I,D))+Math.imul(E,q)|0,o=Math.imul(E,D),n=n+Math.imul(_,H)|0,i=(i=i+Math.imul(_,F)|0)+Math.imul(A,H)|0,o=o+Math.imul(A,F)|0,n=n+Math.imul(v,V)|0,i=(i=i+Math.imul(v,G)|0)+Math.imul(k,V)|0,o=o+Math.imul(k,G)|0,n=n+Math.imul(y,Y)|0,i=(i=i+Math.imul(y,J)|0)+Math.imul(w,Y)|0,o=o+Math.imul(w,J)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var kt=(c+(n=n+Math.imul(l,rt)|0)|0)+((8191&(i=(i=i+Math.imul(l,nt)|0)+Math.imul(d,rt)|0))<<13)|0;c=((o=o+Math.imul(d,nt)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(B,q),i=(i=Math.imul(B,D))+Math.imul(P,q)|0,o=Math.imul(P,D),n=n+Math.imul(I,H)|0,i=(i=i+Math.imul(I,F)|0)+Math.imul(E,H)|0,o=o+Math.imul(E,F)|0,n=n+Math.imul(_,V)|0,i=(i=i+Math.imul(_,G)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,G)|0,n=n+Math.imul(v,Y)|0,i=(i=i+Math.imul(v,J)|0)+Math.imul(k,Y)|0,o=o+Math.imul(k,J)|0,n=n+Math.imul(y,Q)|0,i=(i=i+Math.imul(y,tt)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,tt)|0,n=n+Math.imul(p,rt)|0,i=(i=i+Math.imul(p,nt)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,nt)|0;var St=(c+(n=n+Math.imul(l,ot)|0)|0)+((8191&(i=(i=i+Math.imul(l,st)|0)+Math.imul(d,ot)|0))<<13)|0;c=((o=o+Math.imul(d,st)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(T,q),i=(i=Math.imul(T,D))+Math.imul(L,q)|0,o=Math.imul(L,D),n=n+Math.imul(B,H)|0,i=(i=i+Math.imul(B,F)|0)+Math.imul(P,H)|0,o=o+Math.imul(P,F)|0,n=n+Math.imul(I,V)|0,i=(i=i+Math.imul(I,G)|0)+Math.imul(E,V)|0,o=o+Math.imul(E,G)|0,n=n+Math.imul(_,Y)|0,i=(i=i+Math.imul(_,J)|0)+Math.imul(A,Y)|0,o=o+Math.imul(A,J)|0,n=n+Math.imul(v,Q)|0,i=(i=i+Math.imul(v,tt)|0)+Math.imul(k,Q)|0,o=o+Math.imul(k,tt)|0,n=n+Math.imul(y,rt)|0,i=(i=i+Math.imul(y,nt)|0)+Math.imul(w,rt)|0,o=o+Math.imul(w,nt)|0,n=n+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0;var _t=(c+(n=n+Math.imul(l,ut)|0)|0)+((8191&(i=(i=i+Math.imul(l,ct)|0)+Math.imul(d,ut)|0))<<13)|0;c=((o=o+Math.imul(d,ct)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(C,q),i=(i=Math.imul(C,D))+Math.imul(U,q)|0,o=Math.imul(U,D),n=n+Math.imul(T,H)|0,i=(i=i+Math.imul(T,F)|0)+Math.imul(L,H)|0,o=o+Math.imul(L,F)|0,n=n+Math.imul(B,V)|0,i=(i=i+Math.imul(B,G)|0)+Math.imul(P,V)|0,o=o+Math.imul(P,G)|0,n=n+Math.imul(I,Y)|0,i=(i=i+Math.imul(I,J)|0)+Math.imul(E,Y)|0,o=o+Math.imul(E,J)|0,n=n+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,tt)|0,n=n+Math.imul(v,rt)|0,i=(i=i+Math.imul(v,nt)|0)+Math.imul(k,rt)|0,o=o+Math.imul(k,nt)|0,n=n+Math.imul(y,ot)|0,i=(i=i+Math.imul(y,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,n=n+Math.imul(p,ut)|0,i=(i=i+Math.imul(p,ct)|0)+Math.imul(m,ut)|0,o=o+Math.imul(m,ct)|0;var At=(c+(n=n+Math.imul(l,lt)|0)|0)+((8191&(i=(i=i+Math.imul(l,dt)|0)+Math.imul(d,lt)|0))<<13)|0;c=((o=o+Math.imul(d,dt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(z,q),i=(i=Math.imul(z,D))+Math.imul(K,q)|0,o=Math.imul(K,D),n=n+Math.imul(C,H)|0,i=(i=i+Math.imul(C,F)|0)+Math.imul(U,H)|0,o=o+Math.imul(U,F)|0,n=n+Math.imul(T,V)|0,i=(i=i+Math.imul(T,G)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,G)|0,n=n+Math.imul(B,Y)|0,i=(i=i+Math.imul(B,J)|0)+Math.imul(P,Y)|0,o=o+Math.imul(P,J)|0,n=n+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(_,rt)|0,i=(i=i+Math.imul(_,nt)|0)+Math.imul(A,rt)|0,o=o+Math.imul(A,nt)|0,n=n+Math.imul(v,ot)|0,i=(i=i+Math.imul(v,st)|0)+Math.imul(k,ot)|0,o=o+Math.imul(k,st)|0,n=n+Math.imul(y,ut)|0,i=(i=i+Math.imul(y,ct)|0)+Math.imul(w,ut)|0,o=o+Math.imul(w,ct)|0,n=n+Math.imul(p,lt)|0,i=(i=i+Math.imul(p,dt)|0)+Math.imul(m,lt)|0,o=o+Math.imul(m,dt)|0;var Mt=(c+(n=n+Math.imul(l,pt)|0)|0)+((8191&(i=(i=i+Math.imul(l,mt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((o=o+Math.imul(d,mt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(z,H),i=(i=Math.imul(z,F))+Math.imul(K,H)|0,o=Math.imul(K,F),n=n+Math.imul(C,V)|0,i=(i=i+Math.imul(C,G)|0)+Math.imul(U,V)|0,o=o+Math.imul(U,G)|0,n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,Y)|0,o=o+Math.imul(L,J)|0,n=n+Math.imul(B,Q)|0,i=(i=i+Math.imul(B,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,n=n+Math.imul(I,rt)|0,i=(i=i+Math.imul(I,nt)|0)+Math.imul(E,rt)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,n=n+Math.imul(v,ut)|0,i=(i=i+Math.imul(v,ct)|0)+Math.imul(k,ut)|0,o=o+Math.imul(k,ct)|0,n=n+Math.imul(y,lt)|0,i=(i=i+Math.imul(y,dt)|0)+Math.imul(w,lt)|0,o=o+Math.imul(w,dt)|0;var It=(c+(n=n+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;c=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(z,V),i=(i=Math.imul(z,G))+Math.imul(K,V)|0,o=Math.imul(K,G),n=n+Math.imul(C,Y)|0,i=(i=i+Math.imul(C,J)|0)+Math.imul(U,Y)|0,o=o+Math.imul(U,J)|0,n=n+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,tt)|0,n=n+Math.imul(B,rt)|0,i=(i=i+Math.imul(B,nt)|0)+Math.imul(P,rt)|0,o=o+Math.imul(P,nt)|0,n=n+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(_,ut)|0,i=(i=i+Math.imul(_,ct)|0)+Math.imul(A,ut)|0,o=o+Math.imul(A,ct)|0,n=n+Math.imul(v,lt)|0,i=(i=i+Math.imul(v,dt)|0)+Math.imul(k,lt)|0,o=o+Math.imul(k,dt)|0;var Et=(c+(n=n+Math.imul(y,pt)|0)|0)+((8191&(i=(i=i+Math.imul(y,mt)|0)+Math.imul(w,pt)|0))<<13)|0;c=((o=o+Math.imul(w,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(z,Y),i=(i=Math.imul(z,J))+Math.imul(K,Y)|0,o=Math.imul(K,J),n=n+Math.imul(C,Q)|0,i=(i=i+Math.imul(C,tt)|0)+Math.imul(U,Q)|0,o=o+Math.imul(U,tt)|0,n=n+Math.imul(T,rt)|0,i=(i=i+Math.imul(T,nt)|0)+Math.imul(L,rt)|0,o=o+Math.imul(L,nt)|0,n=n+Math.imul(B,ot)|0,i=(i=i+Math.imul(B,st)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,st)|0,n=n+Math.imul(I,ut)|0,i=(i=i+Math.imul(I,ct)|0)+Math.imul(E,ut)|0,o=o+Math.imul(E,ct)|0,n=n+Math.imul(_,lt)|0,i=(i=i+Math.imul(_,dt)|0)+Math.imul(A,lt)|0,o=o+Math.imul(A,dt)|0;var xt=(c+(n=n+Math.imul(v,pt)|0)|0)+((8191&(i=(i=i+Math.imul(v,mt)|0)+Math.imul(k,pt)|0))<<13)|0;c=((o=o+Math.imul(k,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(z,Q),i=(i=Math.imul(z,tt))+Math.imul(K,Q)|0,o=Math.imul(K,tt),n=n+Math.imul(C,rt)|0,i=(i=i+Math.imul(C,nt)|0)+Math.imul(U,rt)|0,o=o+Math.imul(U,nt)|0,n=n+Math.imul(T,ot)|0,i=(i=i+Math.imul(T,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,n=n+Math.imul(B,ut)|0,i=(i=i+Math.imul(B,ct)|0)+Math.imul(P,ut)|0,o=o+Math.imul(P,ct)|0,n=n+Math.imul(I,lt)|0,i=(i=i+Math.imul(I,dt)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,dt)|0;var Bt=(c+(n=n+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,mt)|0)+Math.imul(A,pt)|0))<<13)|0;c=((o=o+Math.imul(A,mt)|0)+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(z,rt),i=(i=Math.imul(z,nt))+Math.imul(K,rt)|0,o=Math.imul(K,nt),n=n+Math.imul(C,ot)|0,i=(i=i+Math.imul(C,st)|0)+Math.imul(U,ot)|0,o=o+Math.imul(U,st)|0,n=n+Math.imul(T,ut)|0,i=(i=i+Math.imul(T,ct)|0)+Math.imul(L,ut)|0,o=o+Math.imul(L,ct)|0,n=n+Math.imul(B,lt)|0,i=(i=i+Math.imul(B,dt)|0)+Math.imul(P,lt)|0,o=o+Math.imul(P,dt)|0;var Pt=(c+(n=n+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,mt)|0)+Math.imul(E,pt)|0))<<13)|0;c=((o=o+Math.imul(E,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(z,ot),i=(i=Math.imul(z,st))+Math.imul(K,ot)|0,o=Math.imul(K,st),n=n+Math.imul(C,ut)|0,i=(i=i+Math.imul(C,ct)|0)+Math.imul(U,ut)|0,o=o+Math.imul(U,ct)|0,n=n+Math.imul(T,lt)|0,i=(i=i+Math.imul(T,dt)|0)+Math.imul(L,lt)|0,o=o+Math.imul(L,dt)|0;var Rt=(c+(n=n+Math.imul(B,pt)|0)|0)+((8191&(i=(i=i+Math.imul(B,mt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((o=o+Math.imul(P,mt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(z,ut),i=(i=Math.imul(z,ct))+Math.imul(K,ut)|0,o=Math.imul(K,ct),n=n+Math.imul(C,lt)|0,i=(i=i+Math.imul(C,dt)|0)+Math.imul(U,lt)|0,o=o+Math.imul(U,dt)|0;var Tt=(c+(n=n+Math.imul(T,pt)|0)|0)+((8191&(i=(i=i+Math.imul(T,mt)|0)+Math.imul(L,pt)|0))<<13)|0;c=((o=o+Math.imul(L,mt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(z,lt),i=(i=Math.imul(z,dt))+Math.imul(K,lt)|0,o=Math.imul(K,dt);var Lt=(c+(n=n+Math.imul(C,pt)|0)|0)+((8191&(i=(i=i+Math.imul(C,mt)|0)+Math.imul(U,pt)|0))<<13)|0;c=((o=o+Math.imul(U,mt)|0)+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863;var Ot=(c+(n=Math.imul(z,pt))|0)+((8191&(i=(i=Math.imul(z,mt))+Math.imul(K,pt)|0))<<13)|0;return c=((o=Math.imul(K,mt))+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,u[0]=gt,u[1]=yt,u[2]=wt,u[3]=bt,u[4]=vt,u[5]=kt,u[6]=St,u[7]=_t,u[8]=At,u[9]=Mt,u[10]=It,u[11]=Et,u[12]=xt,u[13]=Bt,u[14]=Pt,u[15]=Rt,u[16]=Tt,u[17]=Lt,u[18]=Ot,0!==c&&(u[19]=c,r.length++),r};function y(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,o=0;o<r.length-1;o++){var s=i;i=0;for(var a=67108863&n,u=Math.min(o,e.length-1),c=Math.max(0,o-t.length+1);c<=u;c++){var h=o-c,l=(0|t.words[h])*(0|e.words[c]),d=67108863&l;a=67108863&(d=d+a|0),i+=(s=(s=s+(l/67108864|0)|0)+(d>>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r._strip()}function w(t,e,r){return y(t,e,r)}Math.imul||(g=m),o.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?m(this,t,e):r<1024?y(this,t,e):w(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),w(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),n("number"==typeof t),n(t<67108864);for(var r=0,i=0;i<this.length;i++){var o=(0|this.words[i])*t,s=(67108863&o)+(67108863&r);r>>=26,r+=o/67108864|0,r+=s>>>26,this.words[i]=67108863&s}return 0!==r&&(this.words[i]=r,this.length++),e?this.ineg():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 e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=t.words[n]>>>i&1}return e}(t);if(0===e.length)return new o(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var i=r.sqr();n<e.length;n++,i=i.sqr())0!==e[n]&&(r=r.mul(i));return r},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,i=(t-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,u=(0|this.words[e])-a<<r;this.words[e]=u|s,s=a>>>26-r}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this._strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,r){var i;n("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,u=r;if(i-=s,i=Math.max(0,i),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var h=0;for(c=this.length-1;c>=0&&(0!==h||c>=i);c--){var l=0|this.words[c];this.words[c]=h<<26-o|l>>>o,h=l&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},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){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,i=1<<e;return!(this.length<=r||!(this.words[r]&i))},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return n("number"==typeof t),n(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 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},o.prototype.isubn=function(t){if(n("number"==typeof t),n(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()},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,e,r){var i,o,s=t.length+r;this._expand(s);var a=0;for(i=0;i<t.length;i++){o=(0|this.words[i+r])+a;var u=(0|t.words[i])*e;a=((o-=67108863&u)>>26)-(u/67108864|0),this.words[i+r]=67108863&o}for(;i<this.length-r;i++)a=(o=(0|this.words[i+r])+a)>>26,this.words[i+r]=67108863&o;if(0===a)return this._strip();for(n(-1===a),a=0,i=0;i<this.length;i++)a=(o=-(0|this.words[i])+a)>>26,this.words[i]=67108863&o;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),i=t,s=0|i.words[i.length-1];0!=(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,u=n.length-i.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var h=n.clone()._ishlnsubmul(i,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var d=67108864*(0|n.words[i.length+l])+(0|n.words[i.length+l-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(i,d,l);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(i,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var i,s,a},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 e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=(1<<26)%t,i=0,o=this.length-1;o>=0;o--)i=(r*i+(0|this.words[o]))%t;return e?-i:i},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var o=(0|this.words[i])+67108864*r;this.words[i]=o/t|0,r=o%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var h=r.clone(),l=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;)(i.isOdd()||s.isOdd())&&(i.iadd(h),s.isub(l)),i.iushrn(1),s.iushrn(1);for(var p=0,m=1;0==(r.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(l)),a.iushrn(1),u.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(a),s.isub(u)):(r.isub(e),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,h=1;0==(e.words[0]&h)&&c<26;++c,h<<=1);if(c>0)for(e.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,d=1;0==(r.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(r.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a)):(r.isub(e),a.isub(s))}return(i=0===e.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var o=e;e=r,r=o}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.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){n("number"==typeof t);var e=t%26,r=(t-e)/26,i=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var o=i,s=r;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}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 e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},o.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},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},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 M(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(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 n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function k(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function S(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function _(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function M(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function I(t){M.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 e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},i(k,v),k.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),i=0;i<n;i++)e.words[i]=t.words[i];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&r,i=10;i<t.length;i++){var s=0|t.words[i];t.words[i-10]=(s&r)<<4|o>>>22,o=s}o>>>=22,t.words[i-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},k.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},i(S,v),i(_,v),i(A,v),A.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new k;else if("p224"===t)e=new S;else if("p192"===t)e=new _;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return b[t]=e,e},M.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},M.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},M.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(h(t,t.umod(this.m)._forceRed(this)),t)},M.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},M.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},M.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},M.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},M.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},M.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},M.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},M.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},M.prototype.isqr=function(t){return this.imul(t,t.clone())},M.prototype.sqr=function(t){return this.mul(t,t)},M.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new o(2*h*h).toRed(this);0!==this.pow(h,c).cmp(u);)h.redIAdd(u);for(var l=this.pow(h,i),d=this.pow(t,i.addn(1).iushrn(1)),f=this.pow(t,i),p=s;0!==f.cmp(a);){for(var m=f,g=0;0!==m.cmp(a);g++)m=m.redSqr();n(g<p);var y=this.pow(l,new o(1).iushln(p-g-1));d=d.redMul(y),l=y.redSqr(),f=f.redMul(l),p=g}return d},M.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},M.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var i=r[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var c=e.words[n],h=u-1;h>=0;h--){var l=c>>h&1;i!==r[0]&&(i=this.sqr(i)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===h)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}u=26}return i},M.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},M.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new I(t)},i(I,M),I.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},I.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},I.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},I.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},I.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(Ut,t.commonjsGlobal);var Kt=-1;function Wt(t){this.tokens=[].slice.call(t)}Wt.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():Kt},prepend:function(t){if(Array.isArray(t))for(var e=t;e.length;)this.tokens.unshift(e.pop());else this.tokens.unshift(t)},push:function(t){if(Array.isArray(t))for(var e=t;e.length;)this.tokens.push(e.shift());else this.tokens.push(t)}};var qt=-1;function Dt(t,e){if(t)throw TypeError("Decoder error");return e||65533}var jt="utf-8";function Ht(t,e){if(!(this instanceof Ht))return new Ht(t,e);if((t=void 0!==t?String(t).toLowerCase():jt)!==jt)throw new Error("Encoding not supported. Only utf-8 is supported");e=zt(e),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=Boolean(e.fatal),this._ignoreBOM=Boolean(e.ignoreBOM),Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function Ft(t,e){if(!(this instanceof Ft))return new Ft(t,e);if((t=void 0!==t?String(t).toLowerCase():jt)!==jt)throw new Error("Encoding not supported. Only utf-8 is supported");e=zt(e),this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(e.fatal)},Object.defineProperty(this,"encoding",{value:"utf-8"})}function $t(t){var e=t.fatal,r=0,n=0,i=0,o=128,s=191;this.handler=function(t,a){if(a===Kt&&0!==i)return i=0,Dt(e);if(a===Kt)return qt;if(0===i){if(Nt(a,0,127))return a;if(Nt(a,194,223))i=1,r=a-192;else if(Nt(a,224,239))224===a&&(o=160),237===a&&(s=159),i=2,r=a-224;else{if(!Nt(a,240,244))return Dt(e);240===a&&(o=144),244===a&&(s=143),i=3,r=a-240}return r<<=6*i,null}if(!Nt(a,o,s))return r=i=n=0,o=128,s=191,t.prepend(a),Dt(e);if(o=128,s=191,r+=a-128<<6*(i-(n+=1)),n!==i)return null;var u=r;return r=i=n=0,u}}function Vt(t){t.fatal,this.handler=function(t,e){if(e===Kt)return qt;if(Nt(e,0,127))return e;var r,n;Nt(e,128,2047)?(r=1,n=192):Nt(e,2048,65535)?(r=2,n=224):Nt(e,65536,1114111)&&(r=3,n=240);for(var i=[(e>>6*r)+n];r>0;){var o=e>>6*(r-1);i.push(128|63&o),r-=1}return i}}Ht.prototype={decode:function(t,e){var r;r="object"==typeof t&&t instanceof ArrayBuffer?new Uint8Array(t):"object"==typeof t&&"buffer"in t&&t.buffer instanceof ArrayBuffer?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(0),e=zt(e),this._streaming||(this._decoder=new $t({fatal:this._fatal}),this._BOMseen=!1),this._streaming=Boolean(e.stream);for(var n,i=new Wt(r),o=[];!i.endOfStream()&&(n=this._decoder.handler(i,i.read()))!==qt;)null!==n&&(Array.isArray(n)?o.push.apply(o,n):o.push(n));if(!this._streaming){do{if((n=this._decoder.handler(i,i.read()))===qt)break;null!==n&&(Array.isArray(n)?o.push.apply(o,n):o.push(n))}while(!i.endOfStream());this._decoder=null}return o.length&&(-1===["utf-8"].indexOf(this.encoding)||this._ignoreBOM||this._BOMseen||(65279===o[0]?(this._BOMseen=!0,o.shift()):this._BOMseen=!0)),function(t){for(var e="",r=0;r<t.length;++r){var n=t[r];n<=65535?e+=String.fromCharCode(n):(n-=65536,e+=String.fromCharCode(55296+(n>>10),56320+(1023&n)))}return e}(o)}},Ft.prototype={encode:function(t,e){t=t?String(t):"",e=zt(e),this._streaming||(this._encoder=new Vt(this._options)),this._streaming=Boolean(e.stream);for(var r,n=[],i=new Wt(function(t){for(var e=String(t),r=e.length,n=0,i=[];n<r;){var o=e.charCodeAt(n);if(o<55296||o>57343)i.push(o);else if(56320<=o&&o<=57343)i.push(65533);else if(55296<=o&&o<=56319)if(n===r-1)i.push(65533);else{var s=t.charCodeAt(n+1);if(56320<=s&&s<=57343){var a=1023&o,u=1023&s;i.push(65536+(a<<10)+u),n+=1}else i.push(65533)}n+=1}return i}(t));!i.endOfStream()&&(r=this._encoder.handler(i,i.read()))!==qt;)Array.isArray(r)?n.push.apply(n,r):n.push(r);if(!this._streaming){for(;(r=this._encoder.handler(i,i.read()))!==qt;)Array.isArray(r)?n.push.apply(n,r):n.push(r);this._encoder=null}return new Uint8Array(n)}};var Gt=Object.freeze({__proto__:null,TextEncoder:Ft,TextDecoder:Ht}),Zt=t.getAugmentedNamespace(Gt),Yt=t.commonjsGlobal&&t.commonjsGlobal.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),Jt=t.commonjsGlobal&&t.commonjsGlobal.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Xt=t.commonjsGlobal&&t.commonjsGlobal.__decorate||function(t,e,r,n){var i,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(o<3?i(s):o>3?i(e,r,s):i(e,r))||s);return o>3&&s&&Object.defineProperty(e,r,s),s},Qt=t.commonjsGlobal&&t.commonjsGlobal.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.hasOwnProperty.call(t,r)&&Yt(e,t,r);return Jt(e,t),e},te=t.commonjsGlobal&&t.commonjsGlobal.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(Ct,"__esModule",{value:!0});var ee=Ct.deserializeUnchecked=ye=Ct.deserialize=pe=Ct.serialize=Ct.BinaryReader=Ct.BinaryWriter=Ct.BorshError=Ct.baseDecode=Ct.baseEncode=void 0;const re=te(Ut.exports),ne=te(Et),ie=Qt(Zt),oe=new("function"!=typeof TextDecoder?ie.TextDecoder:TextDecoder)("utf-8",{fatal:!0});Ct.baseEncode=function(t){return"string"==typeof t&&(t=Buffer.from(t,"utf8")),ne.default.encode(Buffer.from(t))},Ct.baseDecode=function(t){return Buffer.from(ne.default.decode(t))};const se=1024;class ae extends Error{constructor(t){super(t),this.fieldPath=[],this.originalMessage=t}addToFieldPath(t){this.fieldPath.splice(0,0,t),this.message=this.originalMessage+": "+this.fieldPath.join(".")}}Ct.BorshError=ae;class ue{constructor(){this.buf=Buffer.alloc(se),this.length=0}maybeResize(){this.buf.length<16+this.length&&(this.buf=Buffer.concat([this.buf,Buffer.alloc(se)]))}writeU8(t){this.maybeResize(),this.buf.writeUInt8(t,this.length),this.length+=1}writeU16(t){this.maybeResize(),this.buf.writeUInt16LE(t,this.length),this.length+=2}writeU32(t){this.maybeResize(),this.buf.writeUInt32LE(t,this.length),this.length+=4}writeU64(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",8)))}writeU128(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",16)))}writeU256(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",32)))}writeU512(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",64)))}writeBuffer(t){this.buf=Buffer.concat([Buffer.from(this.buf.subarray(0,this.length)),t,Buffer.alloc(se)]),this.length+=t.length}writeString(t){this.maybeResize();const e=Buffer.from(t,"utf8");this.writeU32(e.length),this.writeBuffer(e)}writeFixedArray(t){this.writeBuffer(Buffer.from(t))}writeArray(t,e){this.maybeResize(),this.writeU32(t.length);for(const r of t)this.maybeResize(),e(r)}toArray(){return this.buf.subarray(0,this.length)}}function ce(t,e,r){const n=r.value;r.value=function(...t){try{return n.apply(this,t)}catch(t){if(t instanceof RangeError){const e=t.code;if(["ERR_BUFFER_OUT_OF_BOUNDS","ERR_OUT_OF_RANGE"].indexOf(e)>=0)throw new ae("Reached the end of buffer when deserializing")}throw t}}}Ct.BinaryWriter=ue;class he{constructor(t){this.buf=t,this.offset=0}readU8(){const t=this.buf.readUInt8(this.offset);return this.offset+=1,t}readU16(){const t=this.buf.readUInt16LE(this.offset);return this.offset+=2,t}readU32(){const t=this.buf.readUInt32LE(this.offset);return this.offset+=4,t}readU64(){const t=this.readBuffer(8);return new re.default(t,"le")}readU128(){const t=this.readBuffer(16);return new re.default(t,"le")}readU256(){const t=this.readBuffer(32);return new re.default(t,"le")}readU512(){const t=this.readBuffer(64);return new re.default(t,"le")}readBuffer(t){if(this.offset+t>this.buf.length)throw new ae(`Expected buffer length ${t} isn't within bounds`);const e=this.buf.slice(this.offset,this.offset+t);return this.offset+=t,e}readString(){const t=this.readU32(),e=this.readBuffer(t);try{return oe.decode(e)}catch(t){throw new ae(`Error decoding UTF-8 string: ${t}`)}}readFixedArray(t){return new Uint8Array(this.readBuffer(t))}readArray(t){const e=this.readU32(),r=Array();for(let n=0;n<e;++n)r.push(t());return r}}function le(t){return t.charAt(0).toUpperCase()+t.slice(1)}function de(t,e,r,n,i){try{if("string"==typeof n)i[`write${le(n)}`](r);else if(n instanceof Array)if("number"==typeof n[0]){if(r.length!==n[0])throw new ae(`Expecting byte array of length ${n[0]}, but got ${r.length} bytes`);i.writeFixedArray(r)}else if(2===n.length&&"number"==typeof n[1]){if(r.length!==n[1])throw new ae(`Expecting byte array of length ${n[1]}, but got ${r.length} bytes`);for(let e=0;e<n[1];e++)de(t,null,r[e],n[0],i)}else i.writeArray(r,(r=>{de(t,e,r,n[0],i)}));else if(void 0!==n.kind)switch(n.kind){case"option":null==r?i.writeU8(0):(i.writeU8(1),de(t,e,r,n.type,i));break;case"map":i.writeU32(r.size),r.forEach(((r,o)=>{de(t,e,o,n.key,i),de(t,e,r,n.value,i)}));break;default:throw new ae(`FieldType ${n} unrecognized`)}else fe(t,r,i)}catch(t){throw t instanceof ae&&t.addToFieldPath(e),t}}function fe(t,e,r){if("function"==typeof e.borshSerialize)return void e.borshSerialize(r);const n=t.get(e.constructor);if(!n)throw new ae(`Class ${e.constructor.name} is missing in schema`);if("struct"===n.kind)n.fields.map((([n,i])=>{de(t,n,e[n],i,r)}));else{if("enum"!==n.kind)throw new ae(`Unexpected schema kind: ${n.kind} for ${e.constructor.name}`);{const i=e[n.field];for(let o=0;o<n.values.length;++o){const[s,a]=n.values[o];if(s===i){r.writeU8(o),de(t,s,e[s],a,r);break}}}}}Xt([ce],he.prototype,"readU8",null),Xt([ce],he.prototype,"readU16",null),Xt([ce],he.prototype,"readU32",null),Xt([ce],he.prototype,"readU64",null),Xt([ce],he.prototype,"readU128",null),Xt([ce],he.prototype,"readU256",null),Xt([ce],he.prototype,"readU512",null),Xt([ce],he.prototype,"readString",null),Xt([ce],he.prototype,"readFixedArray",null),Xt([ce],he.prototype,"readArray",null),Ct.BinaryReader=he;var pe=Ct.serialize=function(t,e,r=ue){const n=new r;return fe(t,e,n),n.toArray()};function me(t,e,r,n){try{if("string"==typeof r)return n[`read${le(r)}`]();if(r instanceof Array){if("number"==typeof r[0])return n.readFixedArray(r[0]);if("number"==typeof r[1]){const e=[];for(let i=0;i<r[1];i++)e.push(me(t,null,r[0],n));return e}return n.readArray((()=>me(t,e,r[0],n)))}if("option"===r.kind){return n.readU8()?me(t,e,r.type,n):void 0}if("map"===r.kind){let i=new Map;const o=n.readU32();for(let s=0;s<o;s++){const o=me(t,e,r.key,n),s=me(t,e,r.value,n);i.set(o,s)}return i}return ge(t,r,n)}catch(t){throw t instanceof ae&&t.addToFieldPath(e),t}}function ge(t,e,r){if("function"==typeof e.borshDeserialize)return e.borshDeserialize(r);const n=t.get(e);if(!n)throw new ae(`Class ${e.name} is missing in schema`);if("struct"===n.kind){const n={};for(const[i,o]of t.get(e).fields)n[i]=me(t,i,o,r);return new e(n)}if("enum"===n.kind){const i=r.readU8();if(i>=n.values.length)throw new ae(`Enum index: ${i} is out of range`);const[o,s]=n.values[i];return new e({[o]:me(t,o,s,r)})}throw new ae(`Unexpected schema kind: ${n.kind} for ${e.constructor.name}`)}var ye=Ct.deserialize=function(t,e,r,n=he){const i=new n(r),o=ge(t,e,i);if(i.offset<r.length)throw new ae(`Unexpected ${r.length-i.offset} bytes after deserialized data`);return o};ee=Ct.deserializeUnchecked=function(t,e,r,n=he){return ge(t,e,new n(r))};var we={};Object.defineProperty(we,"__esModule",{value:!0}),we.s16=we.s8=we.nu64be=we.u48be=we.u40be=we.u32be=we.u24be=we.u16be=sr=we.nu64=we.u48=we.u40=or=we.u32=we.u24=ir=we.u16=nr=we.u8=rr=we.offset=we.greedy=we.Constant=we.UTF8=we.CString=we.Blob=we.Boolean=we.BitField=we.BitStructure=we.VariantLayout=we.Union=we.UnionLayoutDiscriminator=we.UnionDiscriminator=we.Structure=we.Sequence=we.DoubleBE=we.Double=we.FloatBE=we.Float=we.NearInt64BE=we.NearInt64=we.NearUInt64BE=we.NearUInt64=we.IntBE=we.Int=we.UIntBE=we.UInt=we.OffsetLayout=we.GreedyCount=we.ExternalLayout=we.bindConstructorLayout=we.nameWithProperty=we.Layout=we.uint8ArrayToBuffer=we.checkUint8Array=void 0,we.constant=we.utf8=we.cstr=hr=we.blob=we.unionLayoutDiscriminator=we.union=cr=we.seq=we.bits=ur=we.struct=we.f64be=we.f64=we.f32be=we.f32=we.ns64be=we.s48be=we.s40be=we.s32be=we.s24be=we.s16be=ar=we.ns64=we.s48=we.s40=we.s32=we.s24=void 0;const be=o.default;function ve(t){if(!(t instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}function ke(t){return ve(t),be.Buffer.from(t.buffer,t.byteOffset,t.length)}we.checkUint8Array=ve,we.uint8ArrayToBuffer=ke;class Se{constructor(t,e){if(!Number.isInteger(t))throw new TypeError("span must be an integer");this.span=t,this.property=e}makeDestinationObject(){return{}}getSpan(t,e){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(t){const e=Object.create(this.constructor.prototype);return Object.assign(e,this),e.property=t,e}fromArray(t){}}function _e(t,e){return e.property?t+"["+e.property+"]":t}we.Layout=Se,we.nameWithProperty=_e,we.bindConstructorLayout=function(t,e){if("function"!=typeof t)throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(t,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Se))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");t.layout_=e,e.boundConstructor_=t,e.makeDestinationObject=()=>new t,Object.defineProperty(t.prototype,"encode",{value(t,r){return e.encode(this,t,r)},writable:!0}),Object.defineProperty(t,"decode",{value:(t,r)=>e.decode(t,r),writable:!0})};class Ae extends Se{isCount(){throw new Error("ExternalLayout is abstract")}}we.ExternalLayout=Ae;class Me extends Ae{constructor(t=1,e){if(!Number.isInteger(t)||0>=t)throw new TypeError("elementSpan must be a (positive) integer");super(-1,e),this.elementSpan=t}isCount(){return!0}decode(t,e=0){ve(t);const r=t.length-e;return Math.floor(r/this.elementSpan)}encode(t,e,r){return 0}}we.GreedyCount=Me;class Ie extends Ae{constructor(t,e=0,r){if(!(t instanceof Se))throw new TypeError("layout must be a Layout");if(!Number.isInteger(e))throw new TypeError("offset must be integer or undefined");super(t.span,r||t.property),this.layout=t,this.offset=e}isCount(){return this.layout instanceof Ee||this.layout instanceof xe}decode(t,e=0){return this.layout.decode(t,e+this.offset)}encode(t,e,r=0){return this.layout.encode(t,e,r+this.offset)}}we.OffsetLayout=Ie;class Ee extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readUIntLE(e,this.span)}encode(t,e,r=0){return ke(e).writeUIntLE(t,r,this.span),this.span}}we.UInt=Ee;class xe extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readUIntBE(e,this.span)}encode(t,e,r=0){return ke(e).writeUIntBE(t,r,this.span),this.span}}we.UIntBE=xe;class Be extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readIntLE(e,this.span)}encode(t,e,r=0){return ke(e).writeIntLE(t,r,this.span),this.span}}we.Int=Be;class Pe extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readIntBE(e,this.span)}encode(t,e,r=0){return ke(e).writeIntBE(t,r,this.span),this.span}}we.IntBE=Pe;const Re=Math.pow(2,32);function Te(t){const e=Math.floor(t/Re);return{hi32:e,lo32:t-e*Re}}function Le(t,e){return t*Re+e}class Oe extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t),n=r.readUInt32LE(e);return Le(r.readUInt32LE(e+4),n)}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeUInt32LE(n.lo32,r),i.writeUInt32LE(n.hi32,r+4),8}}we.NearUInt64=Oe;class Ce extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t);return Le(r.readUInt32BE(e),r.readUInt32BE(e+4))}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeUInt32BE(n.hi32,r),i.writeUInt32BE(n.lo32,r+4),8}}we.NearUInt64BE=Ce;class Ue extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t),n=r.readUInt32LE(e);return Le(r.readInt32LE(e+4),n)}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeUInt32LE(n.lo32,r),i.writeInt32LE(n.hi32,r+4),8}}we.NearInt64=Ue;class Ne extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t);return Le(r.readInt32BE(e),r.readUInt32BE(e+4))}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeInt32BE(n.hi32,r),i.writeUInt32BE(n.lo32,r+4),8}}we.NearInt64BE=Ne;class ze extends Se{constructor(t){super(4,t)}decode(t,e=0){return ke(t).readFloatLE(e)}encode(t,e,r=0){return ke(e).writeFloatLE(t,r),4}}we.Float=ze;class Ke extends Se{constructor(t){super(4,t)}decode(t,e=0){return ke(t).readFloatBE(e)}encode(t,e,r=0){return ke(e).writeFloatBE(t,r),4}}we.FloatBE=Ke;class We extends Se{constructor(t){super(8,t)}decode(t,e=0){return ke(t).readDoubleLE(e)}encode(t,e,r=0){return ke(e).writeDoubleLE(t,r),8}}we.Double=We;class qe extends Se{constructor(t){super(8,t)}decode(t,e=0){return ke(t).readDoubleBE(e)}encode(t,e,r=0){return ke(e).writeDoubleBE(t,r),8}}we.DoubleBE=qe;class De extends Se{constructor(t,e,r){if(!(t instanceof Se))throw new TypeError("elementLayout must be a Layout");if(!(e instanceof Ae&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(e instanceof Ae)&&0<t.span&&(n=e*t.span),super(n,r),this.elementLayout=t,this.count=e}getSpan(t,e=0){if(0<=this.span)return this.span;let r=0,n=this.count;if(n instanceof Ae&&(n=n.decode(t,e)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let i=0;for(;i<n;)r+=this.elementLayout.getSpan(t,e+r),++i}return r}decode(t,e=0){const r=[];let n=0,i=this.count;for(i instanceof Ae&&(i=i.decode(t,e));n<i;)r.push(this.elementLayout.decode(t,e)),e+=this.elementLayout.getSpan(t,e),n+=1;return r}encode(t,e,r=0){const n=this.elementLayout,i=t.reduce(((t,i)=>t+n.encode(i,e,r+t)),0);return this.count instanceof Ae&&this.count.encode(t.length,e,r),i}}we.Sequence=De;class je extends Se{constructor(t,e,r){if(!Array.isArray(t)||!t.reduce(((t,e)=>t&&e instanceof Se),!0))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof e&&void 0===r&&(r=e,e=void 0);for(const e of t)if(0>e.span&&void 0===e.property)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=t.reduce(((t,e)=>t+e.getSpan()),0)}catch(t){}super(n,e),this.fields=t,this.decodePrefixes=!!r}getSpan(t,e=0){if(0<=this.span)return this.span;let r=0;try{r=this.fields.reduce(((r,n)=>{const i=n.getSpan(t,e);return e+=i,r+i}),0)}catch(t){throw new RangeError("indeterminate span")}return r}decode(t,e=0){ve(t);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(t,e)),e+=n.getSpan(t,e),this.decodePrefixes&&t.length===e)break;return r}encode(t,e,r=0){const n=r;let i=0,o=0;for(const n of this.fields){let s=n.span;if(o=0<s?s:0,void 0!==n.property){const i=t[n.property];void 0!==i&&(o=n.encode(i,e,r),0>s&&(s=n.getSpan(e,r)))}i=r,r+=s}return i+o-n}fromArray(t){const e=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<t.length&&(e[r.property]=t.shift());return e}layoutFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}offsetOf(t){if("string"!=typeof t)throw new TypeError("property must be string");let e=0;for(const r of this.fields){if(r.property===t)return e;0>r.span?e=-1:0<=e&&(e+=r.span)}}}we.Structure=je;class He{constructor(t){this.property=t}decode(t,e){throw new Error("UnionDiscriminator is abstract")}encode(t,e,r){throw new Error("UnionDiscriminator is abstract")}}we.UnionDiscriminator=He;class Fe extends He{constructor(t,e){if(!(t instanceof Ae&&t.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(e||t.property||"variant"),this.layout=t}decode(t,e){return this.layout.decode(t,e)}encode(t,e,r){return this.layout.encode(t,e,r)}}we.UnionLayoutDiscriminator=Fe;class $e extends Se{constructor(t,e,r){let n;if(t instanceof Ee||t instanceof xe)n=new Fe(new Ie(t));else if(t instanceof Ae&&t.isCount())n=new Fe(t);else{if(!(t instanceof He))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");n=t}if(void 0===e&&(e=null),!(null===e||e instanceof Se))throw new TypeError("defaultLayout must be null or a Layout");if(null!==e){if(0>e.span)throw new Error("defaultLayout must have constant span");void 0===e.property&&(e=e.replicate("content"))}let i=-1;e&&(i=e.span,0<=i&&(t instanceof Ee||t instanceof xe)&&(i+=n.layout.span)),super(i,r),this.discriminator=n,this.usesPrefixDiscriminator=t instanceof Ee||t instanceof xe,this.defaultLayout=e,this.registry={};let o=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(t){return o(t)},this.configGetSourceVariant=function(t){o=t.bind(this)}}getSpan(t,e=0){if(0<=this.span)return this.span;const r=this.getVariant(t,e);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(t,e)}defaultGetSourceVariant(t){if(Object.prototype.hasOwnProperty.call(t,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(t,this.defaultLayout.property))return;const e=this.registry[t[this.discriminator.property]];if(e&&(!e.layout||e.property&&Object.prototype.hasOwnProperty.call(t,e.property)))return e}else for(const e in this.registry){const r=this.registry[e];if(r.property&&Object.prototype.hasOwnProperty.call(t,r.property))return r}throw new Error("unable to infer src variant")}decode(t,e=0){let r;const n=this.discriminator,i=n.decode(t,e),o=this.registry[i];if(void 0===o){const o=this.defaultLayout;let s=0;this.usesPrefixDiscriminator&&(s=n.layout.span),r=this.makeDestinationObject(),r[n.property]=i,r[o.property]=o.decode(t,e+s)}else r=o.decode(t,e);return r}encode(t,e,r=0){const n=this.getSourceVariant(t);if(void 0===n){const n=this.discriminator,i=this.defaultLayout;let o=0;return this.usesPrefixDiscriminator&&(o=n.layout.span),n.encode(t[n.property],e,r),o+i.encode(t[i.property],e,r+o)}return n.encode(t,e,r)}addVariant(t,e,r){const n=new Ve(this,t,e,r);return this.registry[t]=n,n}getVariant(t,e=0){let r;return r=t instanceof Uint8Array?this.discriminator.decode(t,e):t,this.registry[r]}}we.Union=$e;class Ve extends Se{constructor(t,e,r,n){if(!(t instanceof $e))throw new TypeError("union must be a Union");if(!Number.isInteger(e)||0>e)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof Se))throw new TypeError("layout must be a Layout");if(null!==t.defaultLayout&&0<=r.span&&r.span>t.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let i=t.span;0>t.span&&(i=r?r.span:0,0<=i&&t.usesPrefixDiscriminator&&(i+=t.discriminator.layout.span)),super(i,n),this.union=t,this.variant=e,this.layout=r||null}getSpan(t,e=0){if(0<=this.span)return this.span;let r=0;this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span);let n=0;return this.layout&&(n=this.layout.getSpan(t,e+r)),r+n}decode(t,e=0){const r=this.makeDestinationObject();if(this!==this.union.getVariant(t,e))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(t,e+n):this.property?r[this.property]=!0:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(t,e,r=0){let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(t,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,e,r);let i=n;if(this.layout&&(this.layout.encode(t[this.property],e,r+n),i+=this.layout.getSpan(e,r+n),0<=this.union.span&&i>this.union.span))throw new Error("encoded variant overruns containing union");return i}fromArray(t){if(this.layout)return this.layout.fromArray(t)}}function Ge(t){return 0>t&&(t+=4294967296),t}we.VariantLayout=Ve;class Ze extends Se{constructor(t,e,r){if(!(t instanceof Ee||t instanceof xe))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof e&&void 0===r&&(r=e,e=!1),4<t.span)throw new RangeError("word cannot exceed 32 bits");super(t.span,r),this.word=t,this.msb=!!e,this.fields=[];let n=0;this._packedSetValue=function(t){return n=Ge(t),this},this._packedGetValue=function(){return n}}decode(t,e=0){const r=this.makeDestinationObject(),n=this.word.decode(t,e);this._packedSetValue(n);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(t));return r}encode(t,e,r=0){const n=this.word.decode(e,r);this._packedSetValue(n);for(const e of this.fields)if(void 0!==e.property){const r=t[e.property];void 0!==r&&e.encode(r)}return this.word.encode(this._packedGetValue(),e,r)}addField(t,e){const r=new Ye(this,t,e);return this.fields.push(r),r}addBoolean(t){const e=new Je(this,t);return this.fields.push(e),e}fieldFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}}we.BitStructure=Ze;class Ye{constructor(t,e,r){if(!(t instanceof Ze))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(e)||0>=e)throw new TypeError("bits must be positive integer");const n=8*t.span,i=t.fields.reduce(((t,e)=>t+e.bits),0);if(e+i>n)throw new Error("bits too long for span remainder ("+(n-i)+" of "+n+" remain)");this.container=t,this.bits=e,this.valueMask=(1<<e)-1,32===e&&(this.valueMask=4294967295),this.start=i,this.container.msb&&(this.start=n-i-e),this.wordMask=Ge(this.valueMask<<this.start),this.property=r}decode(t,e){return Ge(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(t){if("number"!=typeof t||!Number.isInteger(t)||t!==Ge(t&this.valueMask))throw new TypeError(_e("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const e=this.container._packedGetValue(),r=Ge(t<<this.start);this.container._packedSetValue(Ge(e&~this.wordMask)|r)}}we.BitField=Ye;class Je extends Ye{constructor(t,e){super(t,1,e)}decode(t,e){return!!super.decode(t,e)}encode(t){"boolean"==typeof t&&(t=+t),super.encode(t)}}we.Boolean=Je;class Xe extends Se{constructor(t,e){if(!(t instanceof Ae&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;t instanceof Ae||(r=t),super(r,e),this.length=t}getSpan(t,e){let r=this.span;return 0>r&&(r=this.length.decode(t,e)),r}decode(t,e=0){let r=this.span;return 0>r&&(r=this.length.decode(t,e)),ke(t).slice(e,e+r)}encode(t,e,r){let n=this.length;if(this.length instanceof Ae&&(n=t.length),!(t instanceof Uint8Array&&n===t.length))throw new TypeError(_e("Blob.encode",this)+" requires (length "+n+") Uint8Array as src");if(r+n>e.length)throw new RangeError("encoding overruns Uint8Array");const i=ke(t);return ke(e).write(i.toString("hex"),r,n,"hex"),this.length instanceof Ae&&this.length.encode(n,e,r),n}}we.Blob=Xe;class Qe extends Se{constructor(t){super(-1,t)}getSpan(t,e=0){ve(t);let r=e;for(;r<t.length&&0!==t[r];)r+=1;return 1+r-e}decode(t,e=0){const r=this.getSpan(t,e);return ke(t).slice(e,e+r-1).toString("utf-8")}encode(t,e,r=0){"string"!=typeof t&&(t=String(t));const n=be.Buffer.from(t,"utf8"),i=n.length;if(r+i>e.length)throw new RangeError("encoding overruns Buffer");const o=ke(e);return n.copy(o,r),o[r+i]=0,i+1}}we.CString=Qe;class tr extends Se{constructor(t,e){if("string"==typeof t&&void 0===e&&(e=t,t=void 0),void 0===t)t=-1;else if(!Number.isInteger(t))throw new TypeError("maxSpan must be an integer");super(-1,e),this.maxSpan=t}getSpan(t,e=0){return ve(t),t.length-e}decode(t,e=0){const r=this.getSpan(t,e);if(0<=this.maxSpan&&this.maxSpan<r)throw new RangeError("text length exceeds maxSpan");return ke(t).slice(e,e+r).toString("utf-8")}encode(t,e,r=0){"string"!=typeof t&&(t=String(t));const n=be.Buffer.from(t,"utf8"),i=n.length;if(0<=this.maxSpan&&this.maxSpan<i)throw new RangeError("text length exceeds maxSpan");if(r+i>e.length)throw new RangeError("encoding overruns Buffer");return n.copy(ke(e),r),i}}we.UTF8=tr;class er extends Se{constructor(t,e){super(0,e),this.value=t}decode(t,e){return this.value}encode(t,e,r){return 0}}we.Constant=er,we.greedy=(t,e)=>new Me(t,e);var rr=we.offset=(t,e,r)=>new Ie(t,e,r),nr=we.u8=t=>new Ee(1,t),ir=we.u16=t=>new Ee(2,t);we.u24=t=>new Ee(3,t);var or=we.u32=t=>new Ee(4,t);we.u40=t=>new Ee(5,t),we.u48=t=>new Ee(6,t);var sr=we.nu64=t=>new Oe(t);we.u16be=t=>new xe(2,t),we.u24be=t=>new xe(3,t),we.u32be=t=>new xe(4,t),we.u40be=t=>new xe(5,t),we.u48be=t=>new xe(6,t),we.nu64be=t=>new Ce(t),we.s8=t=>new Be(1,t),we.s16=t=>new Be(2,t),we.s24=t=>new Be(3,t),we.s32=t=>new Be(4,t),we.s40=t=>new Be(5,t),we.s48=t=>new Be(6,t);var ar=we.ns64=t=>new Ue(t);we.s16be=t=>new Pe(2,t),we.s24be=t=>new Pe(3,t),we.s32be=t=>new Pe(4,t),we.s40be=t=>new Pe(5,t),we.s48be=t=>new Pe(6,t),we.ns64be=t=>new Ne(t),we.f32=t=>new ze(t),we.f32be=t=>new Ke(t),we.f64=t=>new We(t),we.f64be=t=>new qe(t);var ur=we.struct=(t,e,r)=>new je(t,e,r);we.bits=(t,e,r)=>new Ze(t,e,r);var cr=we.seq=(t,e,r)=>new De(t,e,r);we.union=(t,e,r)=>new $e(t,e,r),we.unionLayoutDiscriminator=(t,e)=>new Fe(t,e);var hr=we.blob=(t,e)=>new Xe(t,e);we.cstr=t=>new Qe(t),we.utf8=(t,e)=>new tr(t,e),we.constant=(t,e)=>new er(t,e);var lr={};Object.defineProperty(lr,"__esModule",{value:!0});var dr=lr.toBigIntLE=function(t){{const e=Buffer.from(t);e.reverse();const r=e.toString("hex");return 0===r.length?BigInt(0):BigInt(`0x${r}`)}};lr.toBigIntBE=function(t){{const e=t.toString("hex");return 0===e.length?BigInt(0):BigInt(`0x${e}`)}};var fr,pr=lr.toBufferLE=function(t,e){{const r=t.toString(16),n=Buffer.from(r.padStart(2*e,"0").slice(0,2*e),"hex");return n.reverse(),n}};lr.toBufferBE=function(t,e){{const r=t.toString(16);return Buffer.from(r.padStart(2*e,"0").slice(0,2*e),"hex")}};class mr extends TypeError{constructor(t,e){let r;const{message:n,...i}=t,{path:o}=t;super(0===o.length?n:"At path: "+o.join(".")+" -- "+n),Object.assign(this,i),this.name=this.constructor.name,this.failures=()=>{var n;return null!=(n=r)?n:r=[t,...e()]}}}function gr(t){return"object"==typeof t&&null!=t}function yr(t){return"string"==typeof t?JSON.stringify(t):""+t}function wr(t,e,r,n){if(!0===t)return;!1===t?t={}:"string"==typeof t&&(t={message:t});const{path:i,branch:o}=e,{type:s}=r,{refinement:a,message:u="Expected a value of type `"+s+"`"+(a?" with refinement `"+a+"`":"")+", but received: `"+yr(n)+"`"}=t;return{value:n,type:s,refinement:a,key:i[i.length-1],path:i,branch:o,...t,message:u}}function*br(t,e,r,n){var i;gr(i=t)&&"function"==typeof i[Symbol.iterator]||(t=[t]);for(const i of t){const t=wr(i,e,r,n);t&&(yield t)}}function*vr(t,e,r={}){const{path:n=[],branch:i=[t],coerce:o=!1,mask:s=!1}=r,a={path:n,branch:i};if(o&&(t=e.coercer(t,a),s&&"type"!==e.type&&gr(e.schema)&&gr(t)&&!Array.isArray(t)))for(const r in t)void 0===e.schema[r]&&delete t[r];let u=!0;for(const r of e.validator(t,a))u=!1,yield[r,void 0];for(let[r,c,h]of e.entries(t,a)){const e=vr(c,h,{path:void 0===r?n:[...n,r],branch:void 0===r?i:[...i,c],coerce:o,mask:s});for(const n of e)n[0]?(u=!1,yield[n[0],void 0]):o&&(c=n[1],void 0===r?t=c:t instanceof Map?t.set(r,c):t instanceof Set?t.add(c):gr(t)&&(t[r]=c))}if(u)for(const r of e.refiner(t,a))u=!1,yield[r,void 0];u&&(yield[void 0,t])}class kr{constructor(t){const{type:e,schema:r,validator:n,refiner:i,coercer:o=(t=>t),entries:s=function*(){}}=t;this.type=e,this.schema=r,this.entries=s,this.coercer=o,this.validator=n?(t,e)=>br(n(t,e),e,this,t):()=>[],this.refiner=i?(t,e)=>br(i(t,e),e,this,t):()=>[]}assert(t){return Sr(t,this)}create(t){return _r(t,this)}is(t){return Ar(t,this)}mask(t){return function(t,e){const r=Mr(t,e,{coerce:!0,mask:!0});if(r[0])throw r[0];return r[1]}(t,this)}validate(t,e={}){return Mr(t,this,e)}}function Sr(t,e){const r=Mr(t,e);if(r[0])throw r[0]}function _r(t,e){const r=Mr(t,e,{coerce:!0});if(r[0])throw r[0];return r[1]}function Ar(t,e){return!Mr(t,e)[0]}function Mr(t,e,r={}){const n=vr(t,e,r),i=function(t){const{done:e,value:r}=t.next();return e?void 0:r}(n);if(i[0]){return[new mr(i[0],(function*(){for(const t of n)t[0]&&(yield t[0])})),void 0]}return[void 0,i[1]]}function Ir(t,e){return new kr({type:t,schema:null,validator:e})}function Er(t){return new kr({type:"array",schema:t,*entries(e){if(t&&Array.isArray(e))for(const[r,n]of e.entries())yield[r,n,t]},coercer:t=>Array.isArray(t)?t.slice():t,validator:t=>Array.isArray(t)||"Expected an array value, but received: "+yr(t)})}function xr(){return Ir("boolean",(t=>"boolean"==typeof t))}function Br(t){return Ir("instance",(e=>e instanceof t||"Expected a `"+t.name+"` instance, but received: "+yr(e)))}function Pr(t){const e=yr(t),r=typeof t;return new kr({type:"literal",schema:"string"===r||"number"===r||"boolean"===r?t:null,validator:r=>r===t||"Expected the literal `"+e+"`, but received: "+yr(r)})}function Rr(t){return new kr({...t,validator:(e,r)=>null===e||t.validator(e,r),refiner:(e,r)=>null===e||t.refiner(e,r)})}function Tr(){return Ir("number",(t=>"number"==typeof t&&!isNaN(t)||"Expected a number, but received: "+yr(t)))}function Lr(t){return new kr({...t,validator:(e,r)=>void 0===e||t.validator(e,r),refiner:(e,r)=>void 0===e||t.refiner(e,r)})}function Or(t,e){return new kr({type:"record",schema:null,*entries(r){if(gr(r))for(const n in r){const i=r[n];yield[n,n,t],yield[n,i,e]}},validator:t=>gr(t)||"Expected an object, but received: "+yr(t)})}function Cr(){return Ir("string",(t=>"string"==typeof t||"Expected a string, but received: "+yr(t)))}function Ur(t){const e=Ir("never",(()=>!1));return new kr({type:"tuple",schema:null,*entries(r){if(Array.isArray(r)){const n=Math.max(t.length,r.length);for(let i=0;i<n;i++)yield[i,r[i],t[i]||e]}},validator:t=>Array.isArray(t)||"Expected an array, but received: "+yr(t)})}function Nr(t){const e=Object.keys(t);return new kr({type:"type",schema:t,*entries(r){if(gr(r))for(const n of e)yield[n,r[n],t[n]]},validator:t=>gr(t)||"Expected an object, but received: "+yr(t)})}function zr(t){const e=t.map((t=>t.type)).join(" | ");return new kr({type:"union",schema:null,validator(r,n){const i=[];for(const e of t){const[...t]=vr(r,e,n),[o]=t;if(!o[0])return[];for(const[e]of t)e&&i.push(e)}return["Expected the value to satisfy a union of `"+e+"`, but received: "+yr(r),...i]}})}function Kr(){return Ir("unknown",(()=>!0))}function Wr(t,e,r){return new kr({...t,coercer:(n,i)=>Ar(n,e)?t.coercer(r(n,i),i):t.coercer(n,i)})}var qr=new Uint8Array(16);function Dr(){if(!fr&&!(fr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return fr(qr)}var jr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Hr(t){return"string"==typeof t&&jr.test(t)}for(var Fr,$r,Vr=[],Gr=0;Gr<256;++Gr)Vr.push((Gr+256).toString(16).substr(1));function Zr(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(Vr[t[e+0]]+Vr[t[e+1]]+Vr[t[e+2]]+Vr[t[e+3]]+"-"+Vr[t[e+4]]+Vr[t[e+5]]+"-"+Vr[t[e+6]]+Vr[t[e+7]]+"-"+Vr[t[e+8]]+Vr[t[e+9]]+"-"+Vr[t[e+10]]+Vr[t[e+11]]+Vr[t[e+12]]+Vr[t[e+13]]+Vr[t[e+14]]+Vr[t[e+15]]).toLowerCase();if(!Hr(r))throw TypeError("Stringified UUID is invalid");return r}var Yr=0,Jr=0;function Xr(t){if(!Hr(t))throw TypeError("Invalid UUID");var e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=255&e,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=255&e,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=255&e,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=255&e,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=255&e,r}function Qr(t,e,r){function n(t,n,i,o){if("string"==typeof t&&(t=function(t){t=unescape(encodeURIComponent(t));for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}(t)),"string"==typeof n&&(n=Xr(n)),16!==n.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var s=new Uint8Array(16+t.length);if(s.set(n),s.set(t,n.length),(s=r(s))[6]=15&s[6]|e,s[8]=63&s[8]|128,i){o=o||0;for(var a=0;a<16;++a)i[o+a]=s[a];return i}return Zr(s)}try{n.name=t}catch(t){}return n.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",n.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",n}function tn(t){return 14+(t+64>>>9<<4)+1}function en(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function rn(t,e,r,n,i,o){return en((s=en(en(e,t),en(n,o)))<<(a=i)|s>>>32-a,r);var s,a}function nn(t,e,r,n,i,o,s){return rn(e&r|~e&n,t,e,i,o,s)}function on(t,e,r,n,i,o,s){return rn(e&n|r&~n,t,e,i,o,s)}function sn(t,e,r,n,i,o,s){return rn(e^r^n,t,e,i,o,s)}function an(t,e,r,n,i,o,s){return rn(r^(e|~n),t,e,i,o,s)}var un=Qr("v3",48,(function(t){if("string"==typeof t){var e=unescape(encodeURIComponent(t));t=new Uint8Array(e.length);for(var r=0;r<e.length;++r)t[r]=e.charCodeAt(r)}return function(t){for(var e=[],r=32*t.length,n="0123456789abcdef",i=0;i<r;i+=8){var o=t[i>>5]>>>i%32&255,s=parseInt(n.charAt(o>>>4&15)+n.charAt(15&o),16);e.push(s)}return e}(function(t,e){t[e>>5]|=128<<e%32,t[tn(e)-1]=e;for(var r=1732584193,n=-271733879,i=-1732584194,o=271733878,s=0;s<t.length;s+=16){var a=r,u=n,c=i,h=o;r=nn(r,n,i,o,t[s],7,-680876936),o=nn(o,r,n,i,t[s+1],12,-389564586),i=nn(i,o,r,n,t[s+2],17,606105819),n=nn(n,i,o,r,t[s+3],22,-1044525330),r=nn(r,n,i,o,t[s+4],7,-176418897),o=nn(o,r,n,i,t[s+5],12,1200080426),i=nn(i,o,r,n,t[s+6],17,-1473231341),n=nn(n,i,o,r,t[s+7],22,-45705983),r=nn(r,n,i,o,t[s+8],7,1770035416),o=nn(o,r,n,i,t[s+9],12,-1958414417),i=nn(i,o,r,n,t[s+10],17,-42063),n=nn(n,i,o,r,t[s+11],22,-1990404162),r=nn(r,n,i,o,t[s+12],7,1804603682),o=nn(o,r,n,i,t[s+13],12,-40341101),i=nn(i,o,r,n,t[s+14],17,-1502002290),r=on(r,n=nn(n,i,o,r,t[s+15],22,1236535329),i,o,t[s+1],5,-165796510),o=on(o,r,n,i,t[s+6],9,-1069501632),i=on(i,o,r,n,t[s+11],14,643717713),n=on(n,i,o,r,t[s],20,-373897302),r=on(r,n,i,o,t[s+5],5,-701558691),o=on(o,r,n,i,t[s+10],9,38016083),i=on(i,o,r,n,t[s+15],14,-660478335),n=on(n,i,o,r,t[s+4],20,-405537848),r=on(r,n,i,o,t[s+9],5,568446438),o=on(o,r,n,i,t[s+14],9,-1019803690),i=on(i,o,r,n,t[s+3],14,-187363961),n=on(n,i,o,r,t[s+8],20,1163531501),r=on(r,n,i,o,t[s+13],5,-1444681467),o=on(o,r,n,i,t[s+2],9,-51403784),i=on(i,o,r,n,t[s+7],14,1735328473),r=sn(r,n=on(n,i,o,r,t[s+12],20,-1926607734),i,o,t[s+5],4,-378558),o=sn(o,r,n,i,t[s+8],11,-2022574463),i=sn(i,o,r,n,t[s+11],16,1839030562),n=sn(n,i,o,r,t[s+14],23,-35309556),r=sn(r,n,i,o,t[s+1],4,-1530992060),o=sn(o,r,n,i,t[s+4],11,1272893353),i=sn(i,o,r,n,t[s+7],16,-155497632),n=sn(n,i,o,r,t[s+10],23,-1094730640),r=sn(r,n,i,o,t[s+13],4,681279174),o=sn(o,r,n,i,t[s],11,-358537222),i=sn(i,o,r,n,t[s+3],16,-722521979),n=sn(n,i,o,r,t[s+6],23,76029189),r=sn(r,n,i,o,t[s+9],4,-640364487),o=sn(o,r,n,i,t[s+12],11,-421815835),i=sn(i,o,r,n,t[s+15],16,530742520),r=an(r,n=sn(n,i,o,r,t[s+2],23,-995338651),i,o,t[s],6,-198630844),o=an(o,r,n,i,t[s+7],10,1126891415),i=an(i,o,r,n,t[s+14],15,-1416354905),n=an(n,i,o,r,t[s+5],21,-57434055),r=an(r,n,i,o,t[s+12],6,1700485571),o=an(o,r,n,i,t[s+3],10,-1894986606),i=an(i,o,r,n,t[s+10],15,-1051523),n=an(n,i,o,r,t[s+1],21,-2054922799),r=an(r,n,i,o,t[s+8],6,1873313359),o=an(o,r,n,i,t[s+15],10,-30611744),i=an(i,o,r,n,t[s+6],15,-1560198380),n=an(n,i,o,r,t[s+13],21,1309151649),r=an(r,n,i,o,t[s+4],6,-145523070),o=an(o,r,n,i,t[s+11],10,-1120210379),i=an(i,o,r,n,t[s+2],15,718787259),n=an(n,i,o,r,t[s+9],21,-343485551),r=en(r,a),n=en(n,u),i=en(i,c),o=en(o,h)}return[r,n,i,o]}(function(t){if(0===t.length)return[];for(var e=8*t.length,r=new Uint32Array(tn(e)),n=0;n<e;n+=8)r[n>>5]|=(255&t[n/8])<<n%32;return r}(t),8*t.length))})),cn=un;function hn(t,e,r,n){switch(t){case 0:return e&r^~e&n;case 1:case 3:return e^r^n;case 2:return e&r^e&n^r&n}}function ln(t,e){return t<<e|t>>>32-e}var dn=Qr("v5",80,(function(t){var e=[1518500249,1859775393,2400959708,3395469782],r=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof t){var n=unescape(encodeURIComponent(t));t=[];for(var i=0;i<n.length;++i)t.push(n.charCodeAt(i))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var o=t.length/4+2,s=Math.ceil(o/16),a=new Array(s),u=0;u<s;++u){for(var c=new Uint32Array(16),h=0;h<16;++h)c[h]=t[64*u+4*h]<<24|t[64*u+4*h+1]<<16|t[64*u+4*h+2]<<8|t[64*u+4*h+3];a[u]=c}a[s-1][14]=8*(t.length-1)/Math.pow(2,32),a[s-1][14]=Math.floor(a[s-1][14]),a[s-1][15]=8*(t.length-1)&4294967295;for(var l=0;l<s;++l){for(var d=new Uint32Array(80),f=0;f<16;++f)d[f]=a[l][f];for(var p=16;p<80;++p)d[p]=ln(d[p-3]^d[p-8]^d[p-14]^d[p-16],1);for(var m=r[0],g=r[1],y=r[2],w=r[3],b=r[4],v=0;v<80;++v){var k=Math.floor(v/20),S=ln(m,5)+hn(k,g,y,w)+b+e[k]+d[v]>>>0;b=w,w=y,y=ln(g,30)>>>0,g=m,m=S}r[0]=r[0]+m>>>0,r[1]=r[1]+g>>>0,r[2]=r[2]+y>>>0,r[3]=r[3]+w>>>0,r[4]=r[4]+b>>>0}return[r[0]>>24&255,r[0]>>16&255,r[0]>>8&255,255&r[0],r[1]>>24&255,r[1]>>16&255,r[1]>>8&255,255&r[1],r[2]>>24&255,r[2]>>16&255,r[2]>>8&255,255&r[2],r[3]>>24&255,r[3]>>16&255,r[3]>>8&255,255&r[3],r[4]>>24&255,r[4]>>16&255,r[4]>>8&255,255&r[4]]})),fn=dn;var pn=Object.freeze({__proto__:null,v1:function(t,e,r){var n=e&&r||0,i=e||new Array(16),o=(t=t||{}).node||Fr,s=void 0!==t.clockseq?t.clockseq:$r;if(null==o||null==s){var a=t.random||(t.rng||Dr)();null==o&&(o=Fr=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==s&&(s=$r=16383&(a[6]<<8|a[7]))}var u=void 0!==t.msecs?t.msecs:Date.now(),c=void 0!==t.nsecs?t.nsecs:Jr+1,h=u-Yr+(c-Jr)/1e4;if(h<0&&void 0===t.clockseq&&(s=s+1&16383),(h<0||u>Yr)&&void 0===t.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Yr=u,Jr=c,$r=s;var l=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;i[n++]=l>>>24&255,i[n++]=l>>>16&255,i[n++]=l>>>8&255,i[n++]=255&l;var d=u/4294967296*1e4&268435455;i[n++]=d>>>8&255,i[n++]=255&d,i[n++]=d>>>24&15|16,i[n++]=d>>>16&255,i[n++]=s>>>8|128,i[n++]=255&s;for(var f=0;f<6;++f)i[n+f]=o[f];return e||Zr(i)},v3:cn,v4:function(t,e,r){var n=(t=t||{}).random||(t.rng||Dr)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){r=r||0;for(var i=0;i<16;++i)e[r+i]=n[i];return e}return Zr(n)},v5:fn,NIL:"00000000-0000-0000-0000-000000000000",version:function(t){if(!Hr(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)},validate:Hr,stringify:Zr,parse:Xr}),mn=t.getAugmentedNamespace(pn);const gn=mn.v4;var yn=function(t,e,r,n){if("string"!=typeof t)throw new TypeError(t+" must be a string");const i="number"==typeof(n=n||{}).version?n.version:2;if(1!==i&&2!==i)throw new TypeError(i+" must be 1 or 2");const o={method:t};if(2===i&&(o.jsonrpc="2.0"),e){if("object"!=typeof e&&!Array.isArray(e))throw new TypeError(e+" must be an object, array or omitted");o.params=e}if(void 0===r){const t="function"==typeof n.generator?n.generator:function(){return gn()};o.id=t(o,n)}else 2===i&&null===r?n.notificationIdNull&&(o.id=null):o.id=r;return o};const wn=mn.v4,bn=yn,vn=function(t,e){if(!(this instanceof vn))return new vn(t,e);e||(e={}),this.options={reviver:void 0!==e.reviver?e.reviver:null,replacer:void 0!==e.replacer?e.replacer:null,generator:void 0!==e.generator?e.generator:function(){return wn()},version:void 0!==e.version?e.version:2,notificationIdNull:"boolean"==typeof e.notificationIdNull&&e.notificationIdNull},this.callServer=t};var kn=vn;vn.prototype.request=function(t,e,r,n){const i=this;let o=null;const s=Array.isArray(t)&&"function"==typeof e;if(1===this.options.version&&s)throw new TypeError("JSON-RPC 1.0 does not support batching");if(s||!s&&t&&"object"==typeof t&&"function"==typeof e)n=e,o=t;else{"function"==typeof r&&(n=r,r=void 0);const i="function"==typeof n;try{o=bn(t,e,r,{generator:this.options.generator,version:this.options.version,notificationIdNull:this.options.notificationIdNull})}catch(t){if(i)return n(t);throw t}if(!i)return o}let a;try{a=JSON.stringify(o,this.options.replacer)}catch(t){return n(t)}return this.callServer(a,(function(t,e){i._parseResponse(t,e,n)})),o},vn.prototype._parseResponse=function(t,e,r){if(t)return void r(t);if(!e)return r();let n;try{n=JSON.parse(e,this.options.reviver)}catch(t){return r(t)}if(3===r.length){if(Array.isArray(n)){const t=function(t){return void 0!==t.error},e=function(e){return!t(e)};return r(null,n.filter(t),n.filter(e))}return r(null,n.error,n.result)}r(null,n)};var Sn,_n={},An={exports:{}};(Sn=An).exports=function(t){return t&&t.__esModule?t:{default:t}},Sn.exports.__esModule=!0,Sn.exports.default=Sn.exports;var Mn,In,En,xn,Bn={exports:{}},Pn={exports:{}};function Rn(){return Mn||(Mn=1,function(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(Pn)),Pn.exports}function Tn(){return In||(In=1,function(t){var e=Rn().default;function r(){
4
+ const B=BigInt(0),P=BigInt(1),R=BigInt(2),T=BigInt(8),L=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),O=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:L,n:L,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),C=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),U=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const N=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),z=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),K=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),W=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class q{constructor(t,e,r,n){this.x=t,this.y=e,this.z=r,this.t=n}static fromAffine(t){if(!(t instanceof G))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return t.equals(G.ZERO)?q.ZERO:new q(t.x,t.y,P,st(t.x*t.y))}static toAffineBatch(t){const e=function(t,e=O.P){const r=new Array(t.length),n=t.reduce(((t,n,i)=>n===B?t:(r[i]=t,st(t*n,e))),P),i=at(n,e);return t.reduceRight(((t,n,i)=>n===B?t:(r[i]=st(t*r[i],e),st(t*n,e))),i),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return this.toAffineBatch(t).map(this.fromAffine)}equals(t){j(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:s}=t,a=st(e*s),u=st(i*n),c=st(r*s),h=st(o*n);return a===u&&c===h}negate(){return new q(st(-this.x),this.y,this.z,st(-this.t))}double(){const{x:t,y:e,z:r}=this,{a:n}=O,i=st(t*t),o=st(e*e),s=st(R*st(r*r)),a=st(n*i),u=t+e,c=st(st(u*u)-i-o),h=a+o,l=h-s,d=a-o,f=st(c*l),p=st(h*d),m=st(c*d),g=st(l*h);return new q(f,p,g,m)}add(t){j(t);const{x:e,y:r,z:n,t:i}=this,{x:o,y:s,z:a,t:u}=t,c=st((r-e)*(s+o)),h=st((r+e)*(s-o)),l=st(h-c);if(l===B)return this.double();const d=st(n*R*u),f=st(i*R*a),p=f+d,m=h+c,g=f-d,y=st(p*l),w=st(m*g),b=st(p*g),v=st(l*m);return new q(y,w,v,b)}subtract(t){return this.add(t.negate())}precomputeWindow(t){const e=1+256/t,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(q.BASE)&&(e=G.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&V.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=q.normalizeZ(n),V.set(e,n)));let i=q.ZERO,o=q.BASE;const s=1+256/r,a=2**(r-1),u=BigInt(2**r-1),c=2**r,h=BigInt(r);for(let e=0;e<s;e++){const r=e*a;let s=Number(t&u);t>>=h,s>a&&(s-=c,t+=P);const l=r,d=r+Math.abs(s)-1,f=e%2!=0,p=s<0;0===s?o=o.add(D(f,n[l])):i=i.add(D(p,n[d]))}return q.normalizeZ([i,o])[0]}multiply(t,e){return this.wNAF(ft(t,O.l),e)}multiplyUnsafe(t){let e=ft(t,O.l,!1);const r=q.BASE,n=q.ZERO;if(e===B)return n;if(this.equals(n)||e===P)return this;if(this.equals(r))return this.wNAF(e);let i=n,o=this;for(;e>B;)e&P&&(i=i.add(o)),o=o.double(),e>>=P;return i}isSmallOrder(){return this.multiplyUnsafe(O.h).equals(q.ZERO)}isTorsionFree(){let t=this.multiplyUnsafe(O.l/R).double();return O.l%R&&(t=t.add(this)),t.equals(q.ZERO)}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(q.ZERO);null==t&&(t=i?T:at(n));const o=st(e*t),s=st(r*t),a=st(n*t);if(i)return G.ZERO;if(a!==P)throw new Error("invZ was invalid");return new G(o,s)}fromRistrettoBytes(){F()}toRistrettoBytes(){F()}fromRistrettoHash(){F()}}function D(t,e){const r=e.negate();return t?r:e}function j(t){if(!(t instanceof q))throw new TypeError("ExtendedPoint expected")}function H(t){if(!(t instanceof $))throw new TypeError("RistrettoPoint expected")}function F(){throw new Error("Legacy method: switch to RistrettoPoint")}q.BASE=new q(O.Gx,O.Gy,P,st(O.Gx*O.Gy)),q.ZERO=new q(B,P,P,B);class ${constructor(t){this.ep=t}static calcElligatorRistrettoMap(t){const{d:e}=O,r=st(U*t*t),n=st((r+P)*K);let i=BigInt(-1);const o=st((i-e*r)*st(r+e));let{isValid:s,value:a}=ct(n,o),u=st(a*t);rt(u)||(u=st(-u)),s||(a=u),s||(i=r);const c=st(i*(r-P)*W-o),h=a*a,l=st((a+a)*o),d=st(c*N),f=st(P-h),p=st(P+h);return new q(st(l*p),st(f*d),st(d*p),st(l*f))}static hashToCurve(t){const e=ot((t=dt(t,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(e),n=ot(t.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new $(r.add(i))}static fromHex(t){t=dt(t,32);const{a:e,d:r}=O,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=ot(t);if(!function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(et(i),t)||rt(i))throw new Error(n);const o=st(i*i),s=st(P+e*o),a=st(P-e*o),u=st(s*s),c=st(a*a),h=st(e*r*u-c),{isValid:l,value:d}=ht(st(h*c)),f=st(d*a),p=st(d*f*h);let m=st((i+i)*f);rt(m)&&(m=st(-m));const g=st(s*p),y=st(m*g);if(!l||rt(y)||g===B)throw new Error(n);return new $(new q(m,g,P,y))}toRawBytes(){let{x:t,y:e,z:r,t:n}=this.ep;const i=st(st(r+e)*st(r-e)),o=st(t*e),s=st(o*o),{value:a}=ht(st(i*s)),u=st(a*i),c=st(a*o),h=st(u*c*n);let l;if(rt(n*h)){let r=st(e*U),n=st(t*U);t=r,e=n,l=st(u*z)}else l=c;rt(t*h)&&(e=st(-e));let d=st((r-e)*l);return rt(d)&&(d=st(-d)),et(d)}toHex(){return X(this.toRawBytes())}toString(){return this.toHex()}equals(t){H(t);const e=this.ep,r=t.ep,n=st(e.x*r.y)===st(e.y*r.x),i=st(e.y*r.y)===st(e.x*r.x);return n||i}add(t){return H(t),new $(this.ep.add(t.ep))}subtract(t){return H(t),new $(this.ep.subtract(t.ep))}multiply(t){return new $(this.ep.multiply(t))}multiplyUnsafe(t){return new $(this.ep.multiplyUnsafe(t))}}$.BASE=new $(q.BASE),$.ZERO=new $(q.ZERO);const V=new WeakMap;class G{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,V.delete(this)}static fromHex(t,e=!0){const{d:r,P:n}=O,i=(t=dt(t,32)).slice();i[31]=-129&t[31];const o=nt(i);if(e&&o>=n)throw new Error("Expected 0 < hex < P");if(!e&&o>=C)throw new Error("Expected 0 < hex < 2**256");const s=st(o*o),a=st(s-P),u=st(r*s+P);let{isValid:c,value:h}=ct(a,u);if(!c)throw new Error("Point.fromHex: invalid y coordinate");const l=(h&P)===P;return 0!=(128&t[31])!==l&&(h=st(-h)),new G(h,o)}static async fromPrivateKey(t){return(await wt(t)).point}toRawBytes(){const t=et(this.y);return t[31]|=this.x&P?128:0,t}toHex(){return X(this.toRawBytes())}toX25519(){const{y:t}=this;return et(st((P+t)*at(P-t)))}isTorsionFree(){return q.fromAffine(this).isTorsionFree()}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new G(st(-this.x),this.y)}add(t){return q.fromAffine(this).add(q.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return q.fromAffine(this).multiply(t,this).toAffine()}}G.BASE=new G(O.Gx,O.Gy),G.ZERO=new G(B,P);class Z{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=dt(t,64),r=G.fromHex(e.slice(0,32),!1),n=nt(e.slice(32,64));return new Z(r,n)}assertValidity(){const{r:t,s:e}=this;if(!(t instanceof G))throw new Error("Expected Point instance");return ft(e,O.l,!1),this}toRawBytes(){const t=new Uint8Array(64);return t.set(this.r.toRawBytes()),t.set(et(this.s),32),t}toHex(){return X(this.toRawBytes())}}function Y(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const J=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function X(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=J[t[r]];return e}function Q(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function tt(t){return Q(t.toString(16).padStart(64,"0"))}function et(t){return tt(t).reverse()}function rt(t){return(st(t)&P)===P}function nt(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+X(Uint8Array.from(t).reverse()))}const it=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function ot(t){return st(nt(t)&it)}function st(t,e=O.P){const r=t%e;return r>=B?r:e+r}function at(t,e=O.P){if(t===B||e<=B)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=st(t,e),n=e,i=B,o=P;for(;r!==B;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==P)throw new Error("invert: does not exist");return st(i,e)}function ut(t,e){const{P:r}=O;let n=t;for(;e-- >B;)n*=n,n%=r;return n}function ct(t,e){const r=st(e*e*e),n=function(t){const{P:e}=O,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),s=BigInt(80),a=t*t%e*t%e,u=ut(a,R)*a%e,c=ut(u,P)*t%e,h=ut(c,r)*c%e,l=ut(h,n)*h%e,d=ut(l,i)*l%e,f=ut(d,o)*d%e,p=ut(f,s)*f%e,m=ut(p,s)*f%e,g=ut(m,n)*h%e;return{pow_p_5_8:ut(g,R)*t%e,b2:a}}(t*st(r*r*e)).pow_p_5_8;let i=st(t*r*n);const o=st(e*i*i),s=i,a=st(i*U),u=o===t,c=o===st(-t),h=o===st(-t*U);return u&&(i=s),(c||h)&&(i=a),rt(i)&&(i=st(-i)),{isValid:u||c,value:i}}function ht(t){return ct(P,t)}function lt(t){return st(nt(t),O.l)}function dt(t,e){const r=t instanceof Uint8Array?Uint8Array.from(t):Q(t);if("number"==typeof e&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function ft(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if("number"==typeof t&&Number.isSafeInteger(t)&&(t=BigInt(t)),"bigint"==typeof t&&t<e)if(r){if(B<t)return t}else if(B<=t)return t;throw new TypeError("Expected valid scalar: 0 < scalar < max")}function pt(t){if(32!==(t="bigint"==typeof t||"number"==typeof t?tt(ft(t,C)):dt(t)).length)throw new Error("Expected 32 bytes");return t}function mt(t){const e=function(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}(t.slice(0,32)),r=t.slice(32,64),n=lt(e),i=G.BASE.multiply(n),o=i.toRawBytes();return{head:e,prefix:r,scalar:n,point:i,pointBytes:o}}let gt;function yt(...t){if("function"!=typeof gt)throw new Error("utils.sha512Sync must be set to use sync methods");return gt(...t)}async function wt(t){return mt(await St.sha512(pt(t)))}function bt(t){return mt(yt(pt(t)))}const vt={getExtendedPublicKey:bt,getPublicKey:function(t){return bt(t).pointBytes},sign:function(t,e){t=dt(t);const{prefix:r,scalar:n,pointBytes:i}=bt(e),o=lt(yt(r,t)),s=G.BASE.multiply(o),a=st(o+lt(yt(s.toRawBytes(),i,t))*n,O.l);return new Z(s,a).toRawBytes()},verify:function(t,e,r){const{r:n,SB:i,msg:o,pub:s}=function(t,e,r){e=dt(e),r instanceof G||(r=G.fromHex(r,!1));const{r:n,s:i}=t instanceof Z?t.assertValidity():Z.fromHex(t);return{r:n,s:i,SB:q.BASE.multiplyUnsafe(i),pub:r,msg:e}}(t,e,r),a=yt(n.toRawBytes(),s.toRawBytes(),o);return function(t,e,r,n){const i=lt(n),o=q.fromAffine(t).multiplyUnsafe(i);return q.fromAffine(e).add(o).subtract(r).multiplyUnsafe(O.h).equals(q.ZERO)}(s,n,i,a)}};G.BASE._setWindowSize(8);const kt={node:r.nodeCrypto,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},St={bytesToHex:X,hexToBytes:Q,concatBytes:Y,getExtendedPublicKey:wt,mod:st,invert:at,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if((t=dt(t)).length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return st(nt(t),O.l-P)+P},randomBytes:(t=32)=>{if(kt.web)return kt.web.getRandomValues(new Uint8Array(t));if(kt.node){const{randomBytes:e}=kt.node;return new Uint8Array(e(t).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>St.randomBytes(32),sha512:async(...t)=>{const e=Y(...t);if(kt.web){const t=await kt.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(t)}if(kt.node)return Uint8Array.from(kt.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")},precompute(t=8,e=G.BASE){const r=e.equals(G.BASE)?e:new G(e.x,e.y);return r._setWindowSize(t),r.multiply(R),r},sha512Sync:void 0};Object.defineProperties(St,{sha512Sync:{configurable:!1,get:()=>gt,set(t){gt||(gt=t)}}});var _t={exports:{}};!function(t,e){function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function o(t,e,r){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof t?t.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r.require$$1.Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(!1,"Invalid character in "+t)}function u(t,e,r){var n=a(t,r);return r-1>=e&&(n|=a(t,r-1)<<4),n}function c(t,e,r,i){for(var o=0,s=0,a=Math.min(t.length,r),u=e;u<a;u++){var c=t.charCodeAt(u)-48;o*=i,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<i,"Invalid character"),o+=s}return o}function h(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(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,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,r):(this._parseBase(t,e,i),"le"===r&&this._initArray(this.toArray(),e,r)))},o.prototype._initNumber=function(t,e,r){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):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},o.prototype._initArray=function(t,e,r){if(n("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 i=0;i<this.length;i++)this.words[i]=0;var o,s,a=0;if("be"===r)for(i=t.length-1,o=0;i>=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===r)for(i=0,o=0;i<t.length;i+=3)s=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},o.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,o=0,s=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;this._strip()},o.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var o=t.length-r,s=o%n,a=Math.min(o,o-s)+r,u=0,h=r;h<a;h+=n)u=c(t,h,h+n,e),this.imuln(i),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==s){var l=1;for(u=c(t,h,t.length,e),h=0;h<s;h++)l*=e;this.imuln(l),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},o.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},o.prototype._move=function(t){h(t,this)},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},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","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"],f=[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],p=[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 m(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,u=s/67108864|0;r.words[0]=a;for(var c=1;c<n;c++){for(var h=u>>>26,l=67108863&u,d=Math.min(c,e.length-1),f=Math.max(0,c-t.length+1);f<=d;f++){var p=c-f|0;h+=(s=(i=0|t.words[p])*(o=0|e.words[f])+l)/67108864|0,l=67108863&s}r.words[c]=0|l,u=0|h}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var i=0,o=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<i|o)).toString(16);o=a>>>24-i&16777215,(i+=2)>=26&&(i-=26,s--),r=0!==o||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==o&&(r=o.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=f[t],h=p[t];r="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modrn(h).toString(t);r=(l=l.idivn(h)).isZero()?m+r:d[c-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!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&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},s&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var i=this.byteLength(),o=r||Math.max(1,i);n(i<=o,"byte array longer than desired length"),n(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,i),s},o.prototype._toArrayLikeLE=function(t,e){for(var r=0,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r++]=255&s,r<t.length&&(t[r++]=s>>8&255),r<t.length&&(t[r++]=s>>16&255),6===o?(r<t.length&&(t[r++]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r<t.length)for(t[r++]=n;r<t.length;)t[r++]=0},o.prototype._toArrayLikeBE=function(t,e){for(var r=t.length-1,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r--]=255&s,r>=0&&(t[r--]=s>>8&255),r>=0&&(t[r--]=s>>16&255),6===o?(r>=0&&(t[r--]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r>=0)for(t[r--]=n;r>=0;)t[r--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)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 e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return n(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 e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return n(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 e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return n(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){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,i=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<i:this.words[r]&~(1<<i),this._strip()},o.prototype.iadd=function(t){var e,r,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?(r=this,n=t):(r=t,n=this);for(var i=0,o=0;o<n.length;o++)e=(0|r.words[o])+(0|n.words[o])+i,this.words[o]=67108863&e,i=e>>>26;for(;0!==i&&o<r.length;o++)e=(0|r.words[o])+i,this.words[o]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this},o.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)},o.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 r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|r.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<r.length;s++)o=(e=(0|r.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var g=function(t,e,r){var n,i,o,s=t.words,a=e.words,u=r.words,c=0,h=0|s[0],l=8191&h,d=h>>>13,f=0|s[1],p=8191&f,m=f>>>13,g=0|s[2],y=8191&g,w=g>>>13,b=0|s[3],v=8191&b,k=b>>>13,S=0|s[4],_=8191&S,A=S>>>13,M=0|s[5],I=8191&M,E=M>>>13,x=0|s[6],B=8191&x,P=x>>>13,R=0|s[7],T=8191&R,L=R>>>13,O=0|s[8],C=8191&O,U=O>>>13,N=0|s[9],z=8191&N,K=N>>>13,W=0|a[0],q=8191&W,D=W>>>13,j=0|a[1],H=8191&j,F=j>>>13,$=0|a[2],V=8191&$,G=$>>>13,Z=0|a[3],Y=8191&Z,J=Z>>>13,X=0|a[4],Q=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,nt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ut=8191&at,ct=at>>>13,ht=0|a[8],lt=8191&ht,dt=ht>>>13,ft=0|a[9],pt=8191&ft,mt=ft>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(c+(n=Math.imul(l,q))|0)+((8191&(i=(i=Math.imul(l,D))+Math.imul(d,q)|0))<<13)|0;c=((o=Math.imul(d,D))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(p,q),i=(i=Math.imul(p,D))+Math.imul(m,q)|0,o=Math.imul(m,D);var yt=(c+(n=n+Math.imul(l,H)|0)|0)+((8191&(i=(i=i+Math.imul(l,F)|0)+Math.imul(d,H)|0))<<13)|0;c=((o=o+Math.imul(d,F)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,q),i=(i=Math.imul(y,D))+Math.imul(w,q)|0,o=Math.imul(w,D),n=n+Math.imul(p,H)|0,i=(i=i+Math.imul(p,F)|0)+Math.imul(m,H)|0,o=o+Math.imul(m,F)|0;var wt=(c+(n=n+Math.imul(l,V)|0)|0)+((8191&(i=(i=i+Math.imul(l,G)|0)+Math.imul(d,V)|0))<<13)|0;c=((o=o+Math.imul(d,G)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(v,q),i=(i=Math.imul(v,D))+Math.imul(k,q)|0,o=Math.imul(k,D),n=n+Math.imul(y,H)|0,i=(i=i+Math.imul(y,F)|0)+Math.imul(w,H)|0,o=o+Math.imul(w,F)|0,n=n+Math.imul(p,V)|0,i=(i=i+Math.imul(p,G)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,G)|0;var bt=(c+(n=n+Math.imul(l,Y)|0)|0)+((8191&(i=(i=i+Math.imul(l,J)|0)+Math.imul(d,Y)|0))<<13)|0;c=((o=o+Math.imul(d,J)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(_,q),i=(i=Math.imul(_,D))+Math.imul(A,q)|0,o=Math.imul(A,D),n=n+Math.imul(v,H)|0,i=(i=i+Math.imul(v,F)|0)+Math.imul(k,H)|0,o=o+Math.imul(k,F)|0,n=n+Math.imul(y,V)|0,i=(i=i+Math.imul(y,G)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,G)|0,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,J)|0;var vt=(c+(n=n+Math.imul(l,Q)|0)|0)+((8191&(i=(i=i+Math.imul(l,tt)|0)+Math.imul(d,Q)|0))<<13)|0;c=((o=o+Math.imul(d,tt)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(I,q),i=(i=Math.imul(I,D))+Math.imul(E,q)|0,o=Math.imul(E,D),n=n+Math.imul(_,H)|0,i=(i=i+Math.imul(_,F)|0)+Math.imul(A,H)|0,o=o+Math.imul(A,F)|0,n=n+Math.imul(v,V)|0,i=(i=i+Math.imul(v,G)|0)+Math.imul(k,V)|0,o=o+Math.imul(k,G)|0,n=n+Math.imul(y,Y)|0,i=(i=i+Math.imul(y,J)|0)+Math.imul(w,Y)|0,o=o+Math.imul(w,J)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var kt=(c+(n=n+Math.imul(l,rt)|0)|0)+((8191&(i=(i=i+Math.imul(l,nt)|0)+Math.imul(d,rt)|0))<<13)|0;c=((o=o+Math.imul(d,nt)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(B,q),i=(i=Math.imul(B,D))+Math.imul(P,q)|0,o=Math.imul(P,D),n=n+Math.imul(I,H)|0,i=(i=i+Math.imul(I,F)|0)+Math.imul(E,H)|0,o=o+Math.imul(E,F)|0,n=n+Math.imul(_,V)|0,i=(i=i+Math.imul(_,G)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,G)|0,n=n+Math.imul(v,Y)|0,i=(i=i+Math.imul(v,J)|0)+Math.imul(k,Y)|0,o=o+Math.imul(k,J)|0,n=n+Math.imul(y,Q)|0,i=(i=i+Math.imul(y,tt)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,tt)|0,n=n+Math.imul(p,rt)|0,i=(i=i+Math.imul(p,nt)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,nt)|0;var St=(c+(n=n+Math.imul(l,ot)|0)|0)+((8191&(i=(i=i+Math.imul(l,st)|0)+Math.imul(d,ot)|0))<<13)|0;c=((o=o+Math.imul(d,st)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(T,q),i=(i=Math.imul(T,D))+Math.imul(L,q)|0,o=Math.imul(L,D),n=n+Math.imul(B,H)|0,i=(i=i+Math.imul(B,F)|0)+Math.imul(P,H)|0,o=o+Math.imul(P,F)|0,n=n+Math.imul(I,V)|0,i=(i=i+Math.imul(I,G)|0)+Math.imul(E,V)|0,o=o+Math.imul(E,G)|0,n=n+Math.imul(_,Y)|0,i=(i=i+Math.imul(_,J)|0)+Math.imul(A,Y)|0,o=o+Math.imul(A,J)|0,n=n+Math.imul(v,Q)|0,i=(i=i+Math.imul(v,tt)|0)+Math.imul(k,Q)|0,o=o+Math.imul(k,tt)|0,n=n+Math.imul(y,rt)|0,i=(i=i+Math.imul(y,nt)|0)+Math.imul(w,rt)|0,o=o+Math.imul(w,nt)|0,n=n+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0;var _t=(c+(n=n+Math.imul(l,ut)|0)|0)+((8191&(i=(i=i+Math.imul(l,ct)|0)+Math.imul(d,ut)|0))<<13)|0;c=((o=o+Math.imul(d,ct)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(C,q),i=(i=Math.imul(C,D))+Math.imul(U,q)|0,o=Math.imul(U,D),n=n+Math.imul(T,H)|0,i=(i=i+Math.imul(T,F)|0)+Math.imul(L,H)|0,o=o+Math.imul(L,F)|0,n=n+Math.imul(B,V)|0,i=(i=i+Math.imul(B,G)|0)+Math.imul(P,V)|0,o=o+Math.imul(P,G)|0,n=n+Math.imul(I,Y)|0,i=(i=i+Math.imul(I,J)|0)+Math.imul(E,Y)|0,o=o+Math.imul(E,J)|0,n=n+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,tt)|0,n=n+Math.imul(v,rt)|0,i=(i=i+Math.imul(v,nt)|0)+Math.imul(k,rt)|0,o=o+Math.imul(k,nt)|0,n=n+Math.imul(y,ot)|0,i=(i=i+Math.imul(y,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,n=n+Math.imul(p,ut)|0,i=(i=i+Math.imul(p,ct)|0)+Math.imul(m,ut)|0,o=o+Math.imul(m,ct)|0;var At=(c+(n=n+Math.imul(l,lt)|0)|0)+((8191&(i=(i=i+Math.imul(l,dt)|0)+Math.imul(d,lt)|0))<<13)|0;c=((o=o+Math.imul(d,dt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(z,q),i=(i=Math.imul(z,D))+Math.imul(K,q)|0,o=Math.imul(K,D),n=n+Math.imul(C,H)|0,i=(i=i+Math.imul(C,F)|0)+Math.imul(U,H)|0,o=o+Math.imul(U,F)|0,n=n+Math.imul(T,V)|0,i=(i=i+Math.imul(T,G)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,G)|0,n=n+Math.imul(B,Y)|0,i=(i=i+Math.imul(B,J)|0)+Math.imul(P,Y)|0,o=o+Math.imul(P,J)|0,n=n+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(_,rt)|0,i=(i=i+Math.imul(_,nt)|0)+Math.imul(A,rt)|0,o=o+Math.imul(A,nt)|0,n=n+Math.imul(v,ot)|0,i=(i=i+Math.imul(v,st)|0)+Math.imul(k,ot)|0,o=o+Math.imul(k,st)|0,n=n+Math.imul(y,ut)|0,i=(i=i+Math.imul(y,ct)|0)+Math.imul(w,ut)|0,o=o+Math.imul(w,ct)|0,n=n+Math.imul(p,lt)|0,i=(i=i+Math.imul(p,dt)|0)+Math.imul(m,lt)|0,o=o+Math.imul(m,dt)|0;var Mt=(c+(n=n+Math.imul(l,pt)|0)|0)+((8191&(i=(i=i+Math.imul(l,mt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((o=o+Math.imul(d,mt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(z,H),i=(i=Math.imul(z,F))+Math.imul(K,H)|0,o=Math.imul(K,F),n=n+Math.imul(C,V)|0,i=(i=i+Math.imul(C,G)|0)+Math.imul(U,V)|0,o=o+Math.imul(U,G)|0,n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,Y)|0,o=o+Math.imul(L,J)|0,n=n+Math.imul(B,Q)|0,i=(i=i+Math.imul(B,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,n=n+Math.imul(I,rt)|0,i=(i=i+Math.imul(I,nt)|0)+Math.imul(E,rt)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,n=n+Math.imul(v,ut)|0,i=(i=i+Math.imul(v,ct)|0)+Math.imul(k,ut)|0,o=o+Math.imul(k,ct)|0,n=n+Math.imul(y,lt)|0,i=(i=i+Math.imul(y,dt)|0)+Math.imul(w,lt)|0,o=o+Math.imul(w,dt)|0;var It=(c+(n=n+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;c=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(z,V),i=(i=Math.imul(z,G))+Math.imul(K,V)|0,o=Math.imul(K,G),n=n+Math.imul(C,Y)|0,i=(i=i+Math.imul(C,J)|0)+Math.imul(U,Y)|0,o=o+Math.imul(U,J)|0,n=n+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,tt)|0,n=n+Math.imul(B,rt)|0,i=(i=i+Math.imul(B,nt)|0)+Math.imul(P,rt)|0,o=o+Math.imul(P,nt)|0,n=n+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(_,ut)|0,i=(i=i+Math.imul(_,ct)|0)+Math.imul(A,ut)|0,o=o+Math.imul(A,ct)|0,n=n+Math.imul(v,lt)|0,i=(i=i+Math.imul(v,dt)|0)+Math.imul(k,lt)|0,o=o+Math.imul(k,dt)|0;var Et=(c+(n=n+Math.imul(y,pt)|0)|0)+((8191&(i=(i=i+Math.imul(y,mt)|0)+Math.imul(w,pt)|0))<<13)|0;c=((o=o+Math.imul(w,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(z,Y),i=(i=Math.imul(z,J))+Math.imul(K,Y)|0,o=Math.imul(K,J),n=n+Math.imul(C,Q)|0,i=(i=i+Math.imul(C,tt)|0)+Math.imul(U,Q)|0,o=o+Math.imul(U,tt)|0,n=n+Math.imul(T,rt)|0,i=(i=i+Math.imul(T,nt)|0)+Math.imul(L,rt)|0,o=o+Math.imul(L,nt)|0,n=n+Math.imul(B,ot)|0,i=(i=i+Math.imul(B,st)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,st)|0,n=n+Math.imul(I,ut)|0,i=(i=i+Math.imul(I,ct)|0)+Math.imul(E,ut)|0,o=o+Math.imul(E,ct)|0,n=n+Math.imul(_,lt)|0,i=(i=i+Math.imul(_,dt)|0)+Math.imul(A,lt)|0,o=o+Math.imul(A,dt)|0;var xt=(c+(n=n+Math.imul(v,pt)|0)|0)+((8191&(i=(i=i+Math.imul(v,mt)|0)+Math.imul(k,pt)|0))<<13)|0;c=((o=o+Math.imul(k,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(z,Q),i=(i=Math.imul(z,tt))+Math.imul(K,Q)|0,o=Math.imul(K,tt),n=n+Math.imul(C,rt)|0,i=(i=i+Math.imul(C,nt)|0)+Math.imul(U,rt)|0,o=o+Math.imul(U,nt)|0,n=n+Math.imul(T,ot)|0,i=(i=i+Math.imul(T,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,n=n+Math.imul(B,ut)|0,i=(i=i+Math.imul(B,ct)|0)+Math.imul(P,ut)|0,o=o+Math.imul(P,ct)|0,n=n+Math.imul(I,lt)|0,i=(i=i+Math.imul(I,dt)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,dt)|0;var Bt=(c+(n=n+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,mt)|0)+Math.imul(A,pt)|0))<<13)|0;c=((o=o+Math.imul(A,mt)|0)+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(z,rt),i=(i=Math.imul(z,nt))+Math.imul(K,rt)|0,o=Math.imul(K,nt),n=n+Math.imul(C,ot)|0,i=(i=i+Math.imul(C,st)|0)+Math.imul(U,ot)|0,o=o+Math.imul(U,st)|0,n=n+Math.imul(T,ut)|0,i=(i=i+Math.imul(T,ct)|0)+Math.imul(L,ut)|0,o=o+Math.imul(L,ct)|0,n=n+Math.imul(B,lt)|0,i=(i=i+Math.imul(B,dt)|0)+Math.imul(P,lt)|0,o=o+Math.imul(P,dt)|0;var Pt=(c+(n=n+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,mt)|0)+Math.imul(E,pt)|0))<<13)|0;c=((o=o+Math.imul(E,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(z,ot),i=(i=Math.imul(z,st))+Math.imul(K,ot)|0,o=Math.imul(K,st),n=n+Math.imul(C,ut)|0,i=(i=i+Math.imul(C,ct)|0)+Math.imul(U,ut)|0,o=o+Math.imul(U,ct)|0,n=n+Math.imul(T,lt)|0,i=(i=i+Math.imul(T,dt)|0)+Math.imul(L,lt)|0,o=o+Math.imul(L,dt)|0;var Rt=(c+(n=n+Math.imul(B,pt)|0)|0)+((8191&(i=(i=i+Math.imul(B,mt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((o=o+Math.imul(P,mt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(z,ut),i=(i=Math.imul(z,ct))+Math.imul(K,ut)|0,o=Math.imul(K,ct),n=n+Math.imul(C,lt)|0,i=(i=i+Math.imul(C,dt)|0)+Math.imul(U,lt)|0,o=o+Math.imul(U,dt)|0;var Tt=(c+(n=n+Math.imul(T,pt)|0)|0)+((8191&(i=(i=i+Math.imul(T,mt)|0)+Math.imul(L,pt)|0))<<13)|0;c=((o=o+Math.imul(L,mt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(z,lt),i=(i=Math.imul(z,dt))+Math.imul(K,lt)|0,o=Math.imul(K,dt);var Lt=(c+(n=n+Math.imul(C,pt)|0)|0)+((8191&(i=(i=i+Math.imul(C,mt)|0)+Math.imul(U,pt)|0))<<13)|0;c=((o=o+Math.imul(U,mt)|0)+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863;var Ot=(c+(n=Math.imul(z,pt))|0)+((8191&(i=(i=Math.imul(z,mt))+Math.imul(K,pt)|0))<<13)|0;return c=((o=Math.imul(K,mt))+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,u[0]=gt,u[1]=yt,u[2]=wt,u[3]=bt,u[4]=vt,u[5]=kt,u[6]=St,u[7]=_t,u[8]=At,u[9]=Mt,u[10]=It,u[11]=Et,u[12]=xt,u[13]=Bt,u[14]=Pt,u[15]=Rt,u[16]=Tt,u[17]=Lt,u[18]=Ot,0!==c&&(u[19]=c,r.length++),r};function y(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,o=0;o<r.length-1;o++){var s=i;i=0;for(var a=67108863&n,u=Math.min(o,e.length-1),c=Math.max(0,o-t.length+1);c<=u;c++){var h=o-c,l=(0|t.words[h])*(0|e.words[c]),d=67108863&l;a=67108863&(d=d+a|0),i+=(s=(s=s+(l/67108864|0)|0)+(d>>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r._strip()}function w(t,e,r){return y(t,e,r)}Math.imul||(g=m),o.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?m(this,t,e):r<1024?y(this,t,e):w(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),w(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),n("number"==typeof t),n(t<67108864);for(var r=0,i=0;i<this.length;i++){var o=(0|this.words[i])*t,s=(67108863&o)+(67108863&r);r>>=26,r+=o/67108864|0,r+=s>>>26,this.words[i]=67108863&s}return 0!==r&&(this.words[i]=r,this.length++),e?this.ineg():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 e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=t.words[n]>>>i&1}return e}(t);if(0===e.length)return new o(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var i=r.sqr();n<e.length;n++,i=i.sqr())0!==e[n]&&(r=r.mul(i));return r},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,i=(t-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,u=(0|this.words[e])-a<<r;this.words[e]=u|s,s=a>>>26-r}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this._strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,r){var i;n("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,u=r;if(i-=s,i=Math.max(0,i),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var h=0;for(c=this.length-1;c>=0&&(0!==h||c>=i);c--){var l=0|this.words[c];this.words[c]=h<<26-o|l>>>o,h=l&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},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){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,i=1<<e;return!(this.length<=r||!(this.words[r]&i))},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return n("number"==typeof t),n(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 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},o.prototype.isubn=function(t){if(n("number"==typeof t),n(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()},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,e,r){var i,o,s=t.length+r;this._expand(s);var a=0;for(i=0;i<t.length;i++){o=(0|this.words[i+r])+a;var u=(0|t.words[i])*e;a=((o-=67108863&u)>>26)-(u/67108864|0),this.words[i+r]=67108863&o}for(;i<this.length-r;i++)a=(o=(0|this.words[i+r])+a)>>26,this.words[i+r]=67108863&o;if(0===a)return this._strip();for(n(-1===a),a=0,i=0;i<this.length;i++)a=(o=-(0|this.words[i])+a)>>26,this.words[i]=67108863&o;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),i=t,s=0|i.words[i.length-1];0!=(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,u=n.length-i.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var h=n.clone()._ishlnsubmul(i,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var d=67108864*(0|n.words[i.length+l])+(0|n.words[i.length+l-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(i,d,l);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(i,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var i,s,a},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 e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=(1<<26)%t,i=0,o=this.length-1;o>=0;o--)i=(r*i+(0|this.words[o]))%t;return e?-i:i},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var o=(0|this.words[i])+67108864*r;this.words[i]=o/t|0,r=o%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var h=r.clone(),l=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;)(i.isOdd()||s.isOdd())&&(i.iadd(h),s.isub(l)),i.iushrn(1),s.iushrn(1);for(var p=0,m=1;0==(r.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(l)),a.iushrn(1),u.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(a),s.isub(u)):(r.isub(e),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,h=1;0==(e.words[0]&h)&&c<26;++c,h<<=1);if(c>0)for(e.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,d=1;0==(r.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(r.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a)):(r.isub(e),a.isub(s))}return(i=0===e.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var o=e;e=r,r=o}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.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){n("number"==typeof t);var e=t%26,r=(t-e)/26,i=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var o=i,s=r;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}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 e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},o.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},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},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 M(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(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 n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function k(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function S(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function _(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function M(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function I(t){M.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 e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},i(k,v),k.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),i=0;i<n;i++)e.words[i]=t.words[i];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&r,i=10;i<t.length;i++){var s=0|t.words[i];t.words[i-10]=(s&r)<<4|o>>>22,o=s}o>>>=22,t.words[i-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},k.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},i(S,v),i(_,v),i(A,v),A.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new k;else if("p224"===t)e=new S;else if("p192"===t)e=new _;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return b[t]=e,e},M.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},M.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},M.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(h(t,t.umod(this.m)._forceRed(this)),t)},M.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},M.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},M.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},M.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},M.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},M.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},M.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},M.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},M.prototype.isqr=function(t){return this.imul(t,t.clone())},M.prototype.sqr=function(t){return this.mul(t,t)},M.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new o(2*h*h).toRed(this);0!==this.pow(h,c).cmp(u);)h.redIAdd(u);for(var l=this.pow(h,i),d=this.pow(t,i.addn(1).iushrn(1)),f=this.pow(t,i),p=s;0!==f.cmp(a);){for(var m=f,g=0;0!==m.cmp(a);g++)m=m.redSqr();n(g<p);var y=this.pow(l,new o(1).iushln(p-g-1));d=d.redMul(y),l=y.redSqr(),f=f.redMul(l),p=g}return d},M.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},M.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var i=r[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var c=e.words[n],h=u-1;h>=0;h--){var l=c>>h&1;i!==r[0]&&(i=this.sqr(i)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===h)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}u=26}return i},M.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},M.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new I(t)},i(I,M),I.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},I.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},I.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},I.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},I.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(_t,t.commonjsGlobal);var At=_t.exports,Mt=n.safeBuffer.exports.Buffer;var It=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=n}var s=t.length,a=t.charAt(0),u=Math.log(s)/Math.log(256),c=Math.log(256)/Math.log(s);function h(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return Mt.alloc(0);for(var r=0,n=0,i=0;t[r]===a;)n++,r++;for(var o=(t.length-r)*u+1>>>0,c=new Uint8Array(o);t[r];){var h=e[t.charCodeAt(r)];if(255===h)return;for(var l=0,d=o-1;(0!==h||l<i)&&-1!==d;d--,l++)h+=s*c[d]>>>0,c[d]=h%256>>>0,h=h/256>>>0;if(0!==h)throw new Error("Non-zero carry");i=l,r++}for(var f=o-i;f!==o&&0===c[f];)f++;var p=Mt.allocUnsafe(n+(o-f));p.fill(0,0,n);for(var m=n;f!==o;)p[m++]=c[f++];return p}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=Mt.from(e)),!Mt.isBuffer(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,n=0,i=0,o=e.length;i!==o&&0===e[i];)i++,r++;for(var u=(o-i)*c+1>>>0,h=new Uint8Array(u);i!==o;){for(var l=e[i],d=0,f=u-1;(0!==l||d<n)&&-1!==f;f--,d++)l+=256*h[f]>>>0,h[f]=l%s>>>0,l=l/s>>>0;if(0!==l)throw new Error("Non-zero carry");n=d,i++}for(var p=u-n;p!==u&&0===h[p];)p++;for(var m=a.repeat(r);p<u;++p)m+=t.charAt(h[p]);return m},decodeUnsafe:h,decode:function(t){var e=h(t);if(e)return e;throw new Error("Non-base"+s+" character")}}},Et=It("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const xt=(t,e,r)=>t&e^t&r^e&r,Bt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Pt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rt=new Uint32Array(64);class Tt extends m{constructor(){super(64,32,8,!1),this.A=0|Pt[0],this.B=0|Pt[1],this.C=0|Pt[2],this.D=0|Pt[3],this.E=0|Pt[4],this.F=0|Pt[5],this.G=0|Pt[6],this.H=0|Pt[7]}get(){const{A:t,B:e,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[t,e,r,n,i,o,s,a]}set(t,e,r,n,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)Rt[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=Rt[t-15],r=Rt[t-2],n=l(e,7)^l(e,18)^e>>>3,i=l(r,17)^l(r,19)^r>>>10;Rt[t]=i+Rt[t-7]+n+Rt[t-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let t=0;t<64;t++){const e=c+(l(s,6)^l(s,11)^l(s,25))+((h=s)&a^~h&u)+Bt[t]+Rt[t]|0,d=(l(r,2)^l(r,13)^l(r,22))+xt(r,n,i)|0;c=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+d|0}var h;r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){Rt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Lt extends Tt{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const Ot=p((()=>new Tt));p((()=>new Lt));var Ct={},Ut={exports:{}};function Nt(t,e,r){return e<=t&&t<=r}function zt(t){if(void 0===t)return{};if(t===Object(t))return t;throw TypeError("Could not convert argument to dictionary")}!function(t,e){function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function o(t,e,r){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof t?t.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r.require$$1.Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(!1,"Invalid character in "+t)}function u(t,e,r){var n=a(t,r);return r-1>=e&&(n|=a(t,r-1)<<4),n}function c(t,e,r,i){for(var o=0,s=0,a=Math.min(t.length,r),u=e;u<a;u++){var c=t.charCodeAt(u)-48;o*=i,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<i,"Invalid character"),o+=s}return o}function h(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(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,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,r):(this._parseBase(t,e,i),"le"===r&&this._initArray(this.toArray(),e,r)))},o.prototype._initNumber=function(t,e,r){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):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},o.prototype._initArray=function(t,e,r){if(n("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 i=0;i<this.length;i++)this.words[i]=0;var o,s,a=0;if("be"===r)for(i=t.length-1,o=0;i>=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===r)for(i=0,o=0;i<t.length;i+=3)s=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},o.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,o=0,s=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;this._strip()},o.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var o=t.length-r,s=o%n,a=Math.min(o,o-s)+r,u=0,h=r;h<a;h+=n)u=c(t,h,h+n,e),this.imuln(i),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==s){var l=1;for(u=c(t,h,t.length,e),h=0;h<s;h++)l*=e;this.imuln(l),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},o.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},o.prototype._move=function(t){h(t,this)},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},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","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"],f=[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],p=[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 m(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,u=s/67108864|0;r.words[0]=a;for(var c=1;c<n;c++){for(var h=u>>>26,l=67108863&u,d=Math.min(c,e.length-1),f=Math.max(0,c-t.length+1);f<=d;f++){var p=c-f|0;h+=(s=(i=0|t.words[p])*(o=0|e.words[f])+l)/67108864|0,l=67108863&s}r.words[c]=0|l,u=0|h}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var i=0,o=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<i|o)).toString(16);o=a>>>24-i&16777215,(i+=2)>=26&&(i-=26,s--),r=0!==o||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==o&&(r=o.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=f[t],h=p[t];r="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modrn(h).toString(t);r=(l=l.idivn(h)).isZero()?m+r:d[c-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!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&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},s&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var i=this.byteLength(),o=r||Math.max(1,i);n(i<=o,"byte array longer than desired length"),n(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,i),s},o.prototype._toArrayLikeLE=function(t,e){for(var r=0,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r++]=255&s,r<t.length&&(t[r++]=s>>8&255),r<t.length&&(t[r++]=s>>16&255),6===o?(r<t.length&&(t[r++]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r<t.length)for(t[r++]=n;r<t.length;)t[r++]=0},o.prototype._toArrayLikeBE=function(t,e){for(var r=t.length-1,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r--]=255&s,r>=0&&(t[r--]=s>>8&255),r>=0&&(t[r--]=s>>16&255),6===o?(r>=0&&(t[r--]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r>=0)for(t[r--]=n;r>=0;)t[r--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)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 e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return n(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 e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return n(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 e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return n(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){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return r>0&&(this.words[i]=~this.words[i]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,i=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<i:this.words[r]&~(1<<i),this._strip()},o.prototype.iadd=function(t){var e,r,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?(r=this,n=t):(r=t,n=this);for(var i=0,o=0;o<n.length;o++)e=(0|r.words[o])+(0|n.words[o])+i,this.words[o]=67108863&e,i=e>>>26;for(;0!==i&&o<r.length;o++)e=(0|r.words[o])+i,this.words[o]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this},o.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)},o.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 r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|r.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<r.length;s++)o=(e=(0|r.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var g=function(t,e,r){var n,i,o,s=t.words,a=e.words,u=r.words,c=0,h=0|s[0],l=8191&h,d=h>>>13,f=0|s[1],p=8191&f,m=f>>>13,g=0|s[2],y=8191&g,w=g>>>13,b=0|s[3],v=8191&b,k=b>>>13,S=0|s[4],_=8191&S,A=S>>>13,M=0|s[5],I=8191&M,E=M>>>13,x=0|s[6],B=8191&x,P=x>>>13,R=0|s[7],T=8191&R,L=R>>>13,O=0|s[8],C=8191&O,U=O>>>13,N=0|s[9],z=8191&N,K=N>>>13,W=0|a[0],q=8191&W,D=W>>>13,j=0|a[1],H=8191&j,F=j>>>13,$=0|a[2],V=8191&$,G=$>>>13,Z=0|a[3],Y=8191&Z,J=Z>>>13,X=0|a[4],Q=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,nt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ut=8191&at,ct=at>>>13,ht=0|a[8],lt=8191&ht,dt=ht>>>13,ft=0|a[9],pt=8191&ft,mt=ft>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(c+(n=Math.imul(l,q))|0)+((8191&(i=(i=Math.imul(l,D))+Math.imul(d,q)|0))<<13)|0;c=((o=Math.imul(d,D))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(p,q),i=(i=Math.imul(p,D))+Math.imul(m,q)|0,o=Math.imul(m,D);var yt=(c+(n=n+Math.imul(l,H)|0)|0)+((8191&(i=(i=i+Math.imul(l,F)|0)+Math.imul(d,H)|0))<<13)|0;c=((o=o+Math.imul(d,F)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,q),i=(i=Math.imul(y,D))+Math.imul(w,q)|0,o=Math.imul(w,D),n=n+Math.imul(p,H)|0,i=(i=i+Math.imul(p,F)|0)+Math.imul(m,H)|0,o=o+Math.imul(m,F)|0;var wt=(c+(n=n+Math.imul(l,V)|0)|0)+((8191&(i=(i=i+Math.imul(l,G)|0)+Math.imul(d,V)|0))<<13)|0;c=((o=o+Math.imul(d,G)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(v,q),i=(i=Math.imul(v,D))+Math.imul(k,q)|0,o=Math.imul(k,D),n=n+Math.imul(y,H)|0,i=(i=i+Math.imul(y,F)|0)+Math.imul(w,H)|0,o=o+Math.imul(w,F)|0,n=n+Math.imul(p,V)|0,i=(i=i+Math.imul(p,G)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,G)|0;var bt=(c+(n=n+Math.imul(l,Y)|0)|0)+((8191&(i=(i=i+Math.imul(l,J)|0)+Math.imul(d,Y)|0))<<13)|0;c=((o=o+Math.imul(d,J)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(_,q),i=(i=Math.imul(_,D))+Math.imul(A,q)|0,o=Math.imul(A,D),n=n+Math.imul(v,H)|0,i=(i=i+Math.imul(v,F)|0)+Math.imul(k,H)|0,o=o+Math.imul(k,F)|0,n=n+Math.imul(y,V)|0,i=(i=i+Math.imul(y,G)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,G)|0,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,J)|0;var vt=(c+(n=n+Math.imul(l,Q)|0)|0)+((8191&(i=(i=i+Math.imul(l,tt)|0)+Math.imul(d,Q)|0))<<13)|0;c=((o=o+Math.imul(d,tt)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(I,q),i=(i=Math.imul(I,D))+Math.imul(E,q)|0,o=Math.imul(E,D),n=n+Math.imul(_,H)|0,i=(i=i+Math.imul(_,F)|0)+Math.imul(A,H)|0,o=o+Math.imul(A,F)|0,n=n+Math.imul(v,V)|0,i=(i=i+Math.imul(v,G)|0)+Math.imul(k,V)|0,o=o+Math.imul(k,G)|0,n=n+Math.imul(y,Y)|0,i=(i=i+Math.imul(y,J)|0)+Math.imul(w,Y)|0,o=o+Math.imul(w,J)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var kt=(c+(n=n+Math.imul(l,rt)|0)|0)+((8191&(i=(i=i+Math.imul(l,nt)|0)+Math.imul(d,rt)|0))<<13)|0;c=((o=o+Math.imul(d,nt)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(B,q),i=(i=Math.imul(B,D))+Math.imul(P,q)|0,o=Math.imul(P,D),n=n+Math.imul(I,H)|0,i=(i=i+Math.imul(I,F)|0)+Math.imul(E,H)|0,o=o+Math.imul(E,F)|0,n=n+Math.imul(_,V)|0,i=(i=i+Math.imul(_,G)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,G)|0,n=n+Math.imul(v,Y)|0,i=(i=i+Math.imul(v,J)|0)+Math.imul(k,Y)|0,o=o+Math.imul(k,J)|0,n=n+Math.imul(y,Q)|0,i=(i=i+Math.imul(y,tt)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,tt)|0,n=n+Math.imul(p,rt)|0,i=(i=i+Math.imul(p,nt)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,nt)|0;var St=(c+(n=n+Math.imul(l,ot)|0)|0)+((8191&(i=(i=i+Math.imul(l,st)|0)+Math.imul(d,ot)|0))<<13)|0;c=((o=o+Math.imul(d,st)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(T,q),i=(i=Math.imul(T,D))+Math.imul(L,q)|0,o=Math.imul(L,D),n=n+Math.imul(B,H)|0,i=(i=i+Math.imul(B,F)|0)+Math.imul(P,H)|0,o=o+Math.imul(P,F)|0,n=n+Math.imul(I,V)|0,i=(i=i+Math.imul(I,G)|0)+Math.imul(E,V)|0,o=o+Math.imul(E,G)|0,n=n+Math.imul(_,Y)|0,i=(i=i+Math.imul(_,J)|0)+Math.imul(A,Y)|0,o=o+Math.imul(A,J)|0,n=n+Math.imul(v,Q)|0,i=(i=i+Math.imul(v,tt)|0)+Math.imul(k,Q)|0,o=o+Math.imul(k,tt)|0,n=n+Math.imul(y,rt)|0,i=(i=i+Math.imul(y,nt)|0)+Math.imul(w,rt)|0,o=o+Math.imul(w,nt)|0,n=n+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0;var _t=(c+(n=n+Math.imul(l,ut)|0)|0)+((8191&(i=(i=i+Math.imul(l,ct)|0)+Math.imul(d,ut)|0))<<13)|0;c=((o=o+Math.imul(d,ct)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(C,q),i=(i=Math.imul(C,D))+Math.imul(U,q)|0,o=Math.imul(U,D),n=n+Math.imul(T,H)|0,i=(i=i+Math.imul(T,F)|0)+Math.imul(L,H)|0,o=o+Math.imul(L,F)|0,n=n+Math.imul(B,V)|0,i=(i=i+Math.imul(B,G)|0)+Math.imul(P,V)|0,o=o+Math.imul(P,G)|0,n=n+Math.imul(I,Y)|0,i=(i=i+Math.imul(I,J)|0)+Math.imul(E,Y)|0,o=o+Math.imul(E,J)|0,n=n+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,tt)|0,n=n+Math.imul(v,rt)|0,i=(i=i+Math.imul(v,nt)|0)+Math.imul(k,rt)|0,o=o+Math.imul(k,nt)|0,n=n+Math.imul(y,ot)|0,i=(i=i+Math.imul(y,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,n=n+Math.imul(p,ut)|0,i=(i=i+Math.imul(p,ct)|0)+Math.imul(m,ut)|0,o=o+Math.imul(m,ct)|0;var At=(c+(n=n+Math.imul(l,lt)|0)|0)+((8191&(i=(i=i+Math.imul(l,dt)|0)+Math.imul(d,lt)|0))<<13)|0;c=((o=o+Math.imul(d,dt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(z,q),i=(i=Math.imul(z,D))+Math.imul(K,q)|0,o=Math.imul(K,D),n=n+Math.imul(C,H)|0,i=(i=i+Math.imul(C,F)|0)+Math.imul(U,H)|0,o=o+Math.imul(U,F)|0,n=n+Math.imul(T,V)|0,i=(i=i+Math.imul(T,G)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,G)|0,n=n+Math.imul(B,Y)|0,i=(i=i+Math.imul(B,J)|0)+Math.imul(P,Y)|0,o=o+Math.imul(P,J)|0,n=n+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(_,rt)|0,i=(i=i+Math.imul(_,nt)|0)+Math.imul(A,rt)|0,o=o+Math.imul(A,nt)|0,n=n+Math.imul(v,ot)|0,i=(i=i+Math.imul(v,st)|0)+Math.imul(k,ot)|0,o=o+Math.imul(k,st)|0,n=n+Math.imul(y,ut)|0,i=(i=i+Math.imul(y,ct)|0)+Math.imul(w,ut)|0,o=o+Math.imul(w,ct)|0,n=n+Math.imul(p,lt)|0,i=(i=i+Math.imul(p,dt)|0)+Math.imul(m,lt)|0,o=o+Math.imul(m,dt)|0;var Mt=(c+(n=n+Math.imul(l,pt)|0)|0)+((8191&(i=(i=i+Math.imul(l,mt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((o=o+Math.imul(d,mt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(z,H),i=(i=Math.imul(z,F))+Math.imul(K,H)|0,o=Math.imul(K,F),n=n+Math.imul(C,V)|0,i=(i=i+Math.imul(C,G)|0)+Math.imul(U,V)|0,o=o+Math.imul(U,G)|0,n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,Y)|0,o=o+Math.imul(L,J)|0,n=n+Math.imul(B,Q)|0,i=(i=i+Math.imul(B,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,n=n+Math.imul(I,rt)|0,i=(i=i+Math.imul(I,nt)|0)+Math.imul(E,rt)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,n=n+Math.imul(v,ut)|0,i=(i=i+Math.imul(v,ct)|0)+Math.imul(k,ut)|0,o=o+Math.imul(k,ct)|0,n=n+Math.imul(y,lt)|0,i=(i=i+Math.imul(y,dt)|0)+Math.imul(w,lt)|0,o=o+Math.imul(w,dt)|0;var It=(c+(n=n+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;c=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(z,V),i=(i=Math.imul(z,G))+Math.imul(K,V)|0,o=Math.imul(K,G),n=n+Math.imul(C,Y)|0,i=(i=i+Math.imul(C,J)|0)+Math.imul(U,Y)|0,o=o+Math.imul(U,J)|0,n=n+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,tt)|0,n=n+Math.imul(B,rt)|0,i=(i=i+Math.imul(B,nt)|0)+Math.imul(P,rt)|0,o=o+Math.imul(P,nt)|0,n=n+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(_,ut)|0,i=(i=i+Math.imul(_,ct)|0)+Math.imul(A,ut)|0,o=o+Math.imul(A,ct)|0,n=n+Math.imul(v,lt)|0,i=(i=i+Math.imul(v,dt)|0)+Math.imul(k,lt)|0,o=o+Math.imul(k,dt)|0;var Et=(c+(n=n+Math.imul(y,pt)|0)|0)+((8191&(i=(i=i+Math.imul(y,mt)|0)+Math.imul(w,pt)|0))<<13)|0;c=((o=o+Math.imul(w,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(z,Y),i=(i=Math.imul(z,J))+Math.imul(K,Y)|0,o=Math.imul(K,J),n=n+Math.imul(C,Q)|0,i=(i=i+Math.imul(C,tt)|0)+Math.imul(U,Q)|0,o=o+Math.imul(U,tt)|0,n=n+Math.imul(T,rt)|0,i=(i=i+Math.imul(T,nt)|0)+Math.imul(L,rt)|0,o=o+Math.imul(L,nt)|0,n=n+Math.imul(B,ot)|0,i=(i=i+Math.imul(B,st)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,st)|0,n=n+Math.imul(I,ut)|0,i=(i=i+Math.imul(I,ct)|0)+Math.imul(E,ut)|0,o=o+Math.imul(E,ct)|0,n=n+Math.imul(_,lt)|0,i=(i=i+Math.imul(_,dt)|0)+Math.imul(A,lt)|0,o=o+Math.imul(A,dt)|0;var xt=(c+(n=n+Math.imul(v,pt)|0)|0)+((8191&(i=(i=i+Math.imul(v,mt)|0)+Math.imul(k,pt)|0))<<13)|0;c=((o=o+Math.imul(k,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(z,Q),i=(i=Math.imul(z,tt))+Math.imul(K,Q)|0,o=Math.imul(K,tt),n=n+Math.imul(C,rt)|0,i=(i=i+Math.imul(C,nt)|0)+Math.imul(U,rt)|0,o=o+Math.imul(U,nt)|0,n=n+Math.imul(T,ot)|0,i=(i=i+Math.imul(T,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,n=n+Math.imul(B,ut)|0,i=(i=i+Math.imul(B,ct)|0)+Math.imul(P,ut)|0,o=o+Math.imul(P,ct)|0,n=n+Math.imul(I,lt)|0,i=(i=i+Math.imul(I,dt)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,dt)|0;var Bt=(c+(n=n+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,mt)|0)+Math.imul(A,pt)|0))<<13)|0;c=((o=o+Math.imul(A,mt)|0)+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(z,rt),i=(i=Math.imul(z,nt))+Math.imul(K,rt)|0,o=Math.imul(K,nt),n=n+Math.imul(C,ot)|0,i=(i=i+Math.imul(C,st)|0)+Math.imul(U,ot)|0,o=o+Math.imul(U,st)|0,n=n+Math.imul(T,ut)|0,i=(i=i+Math.imul(T,ct)|0)+Math.imul(L,ut)|0,o=o+Math.imul(L,ct)|0,n=n+Math.imul(B,lt)|0,i=(i=i+Math.imul(B,dt)|0)+Math.imul(P,lt)|0,o=o+Math.imul(P,dt)|0;var Pt=(c+(n=n+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,mt)|0)+Math.imul(E,pt)|0))<<13)|0;c=((o=o+Math.imul(E,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(z,ot),i=(i=Math.imul(z,st))+Math.imul(K,ot)|0,o=Math.imul(K,st),n=n+Math.imul(C,ut)|0,i=(i=i+Math.imul(C,ct)|0)+Math.imul(U,ut)|0,o=o+Math.imul(U,ct)|0,n=n+Math.imul(T,lt)|0,i=(i=i+Math.imul(T,dt)|0)+Math.imul(L,lt)|0,o=o+Math.imul(L,dt)|0;var Rt=(c+(n=n+Math.imul(B,pt)|0)|0)+((8191&(i=(i=i+Math.imul(B,mt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((o=o+Math.imul(P,mt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(z,ut),i=(i=Math.imul(z,ct))+Math.imul(K,ut)|0,o=Math.imul(K,ct),n=n+Math.imul(C,lt)|0,i=(i=i+Math.imul(C,dt)|0)+Math.imul(U,lt)|0,o=o+Math.imul(U,dt)|0;var Tt=(c+(n=n+Math.imul(T,pt)|0)|0)+((8191&(i=(i=i+Math.imul(T,mt)|0)+Math.imul(L,pt)|0))<<13)|0;c=((o=o+Math.imul(L,mt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(z,lt),i=(i=Math.imul(z,dt))+Math.imul(K,lt)|0,o=Math.imul(K,dt);var Lt=(c+(n=n+Math.imul(C,pt)|0)|0)+((8191&(i=(i=i+Math.imul(C,mt)|0)+Math.imul(U,pt)|0))<<13)|0;c=((o=o+Math.imul(U,mt)|0)+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863;var Ot=(c+(n=Math.imul(z,pt))|0)+((8191&(i=(i=Math.imul(z,mt))+Math.imul(K,pt)|0))<<13)|0;return c=((o=Math.imul(K,mt))+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,u[0]=gt,u[1]=yt,u[2]=wt,u[3]=bt,u[4]=vt,u[5]=kt,u[6]=St,u[7]=_t,u[8]=At,u[9]=Mt,u[10]=It,u[11]=Et,u[12]=xt,u[13]=Bt,u[14]=Pt,u[15]=Rt,u[16]=Tt,u[17]=Lt,u[18]=Ot,0!==c&&(u[19]=c,r.length++),r};function y(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,o=0;o<r.length-1;o++){var s=i;i=0;for(var a=67108863&n,u=Math.min(o,e.length-1),c=Math.max(0,o-t.length+1);c<=u;c++){var h=o-c,l=(0|t.words[h])*(0|e.words[c]),d=67108863&l;a=67108863&(d=d+a|0),i+=(s=(s=s+(l/67108864|0)|0)+(d>>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r._strip()}function w(t,e,r){return y(t,e,r)}Math.imul||(g=m),o.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?m(this,t,e):r<1024?y(this,t,e):w(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),w(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),n("number"==typeof t),n(t<67108864);for(var r=0,i=0;i<this.length;i++){var o=(0|this.words[i])*t,s=(67108863&o)+(67108863&r);r>>=26,r+=o/67108864|0,r+=s>>>26,this.words[i]=67108863&s}return 0!==r&&(this.words[i]=r,this.length++),e?this.ineg():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 e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=t.words[n]>>>i&1}return e}(t);if(0===e.length)return new o(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var i=r.sqr();n<e.length;n++,i=i.sqr())0!==e[n]&&(r=r.mul(i));return r},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,i=(t-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,u=(0|this.words[e])-a<<r;this.words[e]=u|s,s=a>>>26-r}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this._strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,r){var i;n("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,u=r;if(i-=s,i=Math.max(0,i),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var h=0;for(c=this.length-1;c>=0&&(0!==h||c>=i);c--){var l=0|this.words[c];this.words[c]=h<<26-o|l>>>o,h=l&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},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){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,i=1<<e;return!(this.length<=r||!(this.words[r]&i))},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return n("number"==typeof t),n(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 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},o.prototype.isubn=function(t){if(n("number"==typeof t),n(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()},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,e,r){var i,o,s=t.length+r;this._expand(s);var a=0;for(i=0;i<t.length;i++){o=(0|this.words[i+r])+a;var u=(0|t.words[i])*e;a=((o-=67108863&u)>>26)-(u/67108864|0),this.words[i+r]=67108863&o}for(;i<this.length-r;i++)a=(o=(0|this.words[i+r])+a)>>26,this.words[i+r]=67108863&o;if(0===a)return this._strip();for(n(-1===a),a=0,i=0;i<this.length;i++)a=(o=-(0|this.words[i])+a)>>26,this.words[i]=67108863&o;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),i=t,s=0|i.words[i.length-1];0!=(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,u=n.length-i.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var h=n.clone()._ishlnsubmul(i,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var d=67108864*(0|n.words[i.length+l])+(0|n.words[i.length+l-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(i,d,l);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(i,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var i,s,a},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 e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=(1<<26)%t,i=0,o=this.length-1;o>=0;o--)i=(r*i+(0|this.words[o]))%t;return e?-i:i},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=0,i=this.length-1;i>=0;i--){var o=(0|this.words[i])+67108864*r;this.words[i]=o/t|0,r=o%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var h=r.clone(),l=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;)(i.isOdd()||s.isOdd())&&(i.iadd(h),s.isub(l)),i.iushrn(1),s.iushrn(1);for(var p=0,m=1;0==(r.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(l)),a.iushrn(1),u.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(a),s.isub(u)):(r.isub(e),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,h=1;0==(e.words[0]&h)&&c<26;++c,h<<=1);if(c>0)for(e.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,d=1;0==(r.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(r.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a)):(r.isub(e),a.isub(s))}return(i=0===e.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var o=e;e=r,r=o}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.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){n("number"==typeof t);var e=t%26,r=(t-e)/26,i=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=i,this;for(var o=i,s=r;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}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 e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},o.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},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},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 M(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(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 n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function k(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function S(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function _(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function M(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function I(t){M.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 e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},i(k,v),k.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),i=0;i<n;i++)e.words[i]=t.words[i];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&r,i=10;i<t.length;i++){var s=0|t.words[i];t.words[i-10]=(s&r)<<4|o>>>22,o=s}o>>>=22,t.words[i-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},k.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},i(S,v),i(_,v),i(A,v),A.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new k;else if("p224"===t)e=new S;else if("p192"===t)e=new _;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return b[t]=e,e},M.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},M.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},M.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(h(t,t.umod(this.m)._forceRed(this)),t)},M.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},M.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},M.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},M.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},M.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},M.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},M.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},M.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},M.prototype.isqr=function(t){return this.imul(t,t.clone())},M.prototype.sqr=function(t){return this.mul(t,t)},M.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new o(2*h*h).toRed(this);0!==this.pow(h,c).cmp(u);)h.redIAdd(u);for(var l=this.pow(h,i),d=this.pow(t,i.addn(1).iushrn(1)),f=this.pow(t,i),p=s;0!==f.cmp(a);){for(var m=f,g=0;0!==m.cmp(a);g++)m=m.redSqr();n(g<p);var y=this.pow(l,new o(1).iushln(p-g-1));d=d.redMul(y),l=y.redSqr(),f=f.redMul(l),p=g}return d},M.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},M.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new o(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var i=r[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var c=e.words[n],h=u-1;h>=0;h--){var l=c>>h&1;i!==r[0]&&(i=this.sqr(i)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===h)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}u=26}return i},M.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},M.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new I(t)},i(I,M),I.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},I.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},I.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},I.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},I.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(Ut,t.commonjsGlobal);var Kt=-1;function Wt(t){this.tokens=[].slice.call(t)}Wt.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():Kt},prepend:function(t){if(Array.isArray(t))for(var e=t;e.length;)this.tokens.unshift(e.pop());else this.tokens.unshift(t)},push:function(t){if(Array.isArray(t))for(var e=t;e.length;)this.tokens.push(e.shift());else this.tokens.push(t)}};var qt=-1;function Dt(t,e){if(t)throw TypeError("Decoder error");return e||65533}var jt="utf-8";function Ht(t,e){if(!(this instanceof Ht))return new Ht(t,e);if((t=void 0!==t?String(t).toLowerCase():jt)!==jt)throw new Error("Encoding not supported. Only utf-8 is supported");e=zt(e),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=Boolean(e.fatal),this._ignoreBOM=Boolean(e.ignoreBOM),Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function Ft(t,e){if(!(this instanceof Ft))return new Ft(t,e);if((t=void 0!==t?String(t).toLowerCase():jt)!==jt)throw new Error("Encoding not supported. Only utf-8 is supported");e=zt(e),this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(e.fatal)},Object.defineProperty(this,"encoding",{value:"utf-8"})}function $t(t){var e=t.fatal,r=0,n=0,i=0,o=128,s=191;this.handler=function(t,a){if(a===Kt&&0!==i)return i=0,Dt(e);if(a===Kt)return qt;if(0===i){if(Nt(a,0,127))return a;if(Nt(a,194,223))i=1,r=a-192;else if(Nt(a,224,239))224===a&&(o=160),237===a&&(s=159),i=2,r=a-224;else{if(!Nt(a,240,244))return Dt(e);240===a&&(o=144),244===a&&(s=143),i=3,r=a-240}return r<<=6*i,null}if(!Nt(a,o,s))return r=i=n=0,o=128,s=191,t.prepend(a),Dt(e);if(o=128,s=191,r+=a-128<<6*(i-(n+=1)),n!==i)return null;var u=r;return r=i=n=0,u}}function Vt(t){t.fatal,this.handler=function(t,e){if(e===Kt)return qt;if(Nt(e,0,127))return e;var r,n;Nt(e,128,2047)?(r=1,n=192):Nt(e,2048,65535)?(r=2,n=224):Nt(e,65536,1114111)&&(r=3,n=240);for(var i=[(e>>6*r)+n];r>0;){var o=e>>6*(r-1);i.push(128|63&o),r-=1}return i}}Ht.prototype={decode:function(t,e){var r;r="object"==typeof t&&t instanceof ArrayBuffer?new Uint8Array(t):"object"==typeof t&&"buffer"in t&&t.buffer instanceof ArrayBuffer?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(0),e=zt(e),this._streaming||(this._decoder=new $t({fatal:this._fatal}),this._BOMseen=!1),this._streaming=Boolean(e.stream);for(var n,i=new Wt(r),o=[];!i.endOfStream()&&(n=this._decoder.handler(i,i.read()))!==qt;)null!==n&&(Array.isArray(n)?o.push.apply(o,n):o.push(n));if(!this._streaming){do{if((n=this._decoder.handler(i,i.read()))===qt)break;null!==n&&(Array.isArray(n)?o.push.apply(o,n):o.push(n))}while(!i.endOfStream());this._decoder=null}return o.length&&(-1===["utf-8"].indexOf(this.encoding)||this._ignoreBOM||this._BOMseen||(65279===o[0]?(this._BOMseen=!0,o.shift()):this._BOMseen=!0)),function(t){for(var e="",r=0;r<t.length;++r){var n=t[r];n<=65535?e+=String.fromCharCode(n):(n-=65536,e+=String.fromCharCode(55296+(n>>10),56320+(1023&n)))}return e}(o)}},Ft.prototype={encode:function(t,e){t=t?String(t):"",e=zt(e),this._streaming||(this._encoder=new Vt(this._options)),this._streaming=Boolean(e.stream);for(var r,n=[],i=new Wt(function(t){for(var e=String(t),r=e.length,n=0,i=[];n<r;){var o=e.charCodeAt(n);if(o<55296||o>57343)i.push(o);else if(56320<=o&&o<=57343)i.push(65533);else if(55296<=o&&o<=56319)if(n===r-1)i.push(65533);else{var s=t.charCodeAt(n+1);if(56320<=s&&s<=57343){var a=1023&o,u=1023&s;i.push(65536+(a<<10)+u),n+=1}else i.push(65533)}n+=1}return i}(t));!i.endOfStream()&&(r=this._encoder.handler(i,i.read()))!==qt;)Array.isArray(r)?n.push.apply(n,r):n.push(r);if(!this._streaming){for(;(r=this._encoder.handler(i,i.read()))!==qt;)Array.isArray(r)?n.push.apply(n,r):n.push(r);this._encoder=null}return new Uint8Array(n)}};var Gt=Object.freeze({__proto__:null,TextEncoder:Ft,TextDecoder:Ht}),Zt=t.getAugmentedNamespace(Gt),Yt=t.commonjsGlobal&&t.commonjsGlobal.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),Jt=t.commonjsGlobal&&t.commonjsGlobal.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Xt=t.commonjsGlobal&&t.commonjsGlobal.__decorate||function(t,e,r,n){var i,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(o<3?i(s):o>3?i(e,r,s):i(e,r))||s);return o>3&&s&&Object.defineProperty(e,r,s),s},Qt=t.commonjsGlobal&&t.commonjsGlobal.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.hasOwnProperty.call(t,r)&&Yt(e,t,r);return Jt(e,t),e},te=t.commonjsGlobal&&t.commonjsGlobal.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(Ct,"__esModule",{value:!0});var ee=Ct.deserializeUnchecked=ye=Ct.deserialize=pe=Ct.serialize=Ct.BinaryReader=Ct.BinaryWriter=Ct.BorshError=Ct.baseDecode=Ct.baseEncode=void 0;const re=te(Ut.exports),ne=te(Et),ie=Qt(Zt),oe=new("function"!=typeof TextDecoder?ie.TextDecoder:TextDecoder)("utf-8",{fatal:!0});Ct.baseEncode=function(t){return"string"==typeof t&&(t=Buffer.from(t,"utf8")),ne.default.encode(Buffer.from(t))},Ct.baseDecode=function(t){return Buffer.from(ne.default.decode(t))};const se=1024;class ae extends Error{constructor(t){super(t),this.fieldPath=[],this.originalMessage=t}addToFieldPath(t){this.fieldPath.splice(0,0,t),this.message=this.originalMessage+": "+this.fieldPath.join(".")}}Ct.BorshError=ae;class ue{constructor(){this.buf=Buffer.alloc(se),this.length=0}maybeResize(){this.buf.length<16+this.length&&(this.buf=Buffer.concat([this.buf,Buffer.alloc(se)]))}writeU8(t){this.maybeResize(),this.buf.writeUInt8(t,this.length),this.length+=1}writeU16(t){this.maybeResize(),this.buf.writeUInt16LE(t,this.length),this.length+=2}writeU32(t){this.maybeResize(),this.buf.writeUInt32LE(t,this.length),this.length+=4}writeU64(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",8)))}writeU128(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",16)))}writeU256(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",32)))}writeU512(t){this.maybeResize(),this.writeBuffer(Buffer.from(new re.default(t).toArray("le",64)))}writeBuffer(t){this.buf=Buffer.concat([Buffer.from(this.buf.subarray(0,this.length)),t,Buffer.alloc(se)]),this.length+=t.length}writeString(t){this.maybeResize();const e=Buffer.from(t,"utf8");this.writeU32(e.length),this.writeBuffer(e)}writeFixedArray(t){this.writeBuffer(Buffer.from(t))}writeArray(t,e){this.maybeResize(),this.writeU32(t.length);for(const r of t)this.maybeResize(),e(r)}toArray(){return this.buf.subarray(0,this.length)}}function ce(t,e,r){const n=r.value;r.value=function(...t){try{return n.apply(this,t)}catch(t){if(t instanceof RangeError){const e=t.code;if(["ERR_BUFFER_OUT_OF_BOUNDS","ERR_OUT_OF_RANGE"].indexOf(e)>=0)throw new ae("Reached the end of buffer when deserializing")}throw t}}}Ct.BinaryWriter=ue;class he{constructor(t){this.buf=t,this.offset=0}readU8(){const t=this.buf.readUInt8(this.offset);return this.offset+=1,t}readU16(){const t=this.buf.readUInt16LE(this.offset);return this.offset+=2,t}readU32(){const t=this.buf.readUInt32LE(this.offset);return this.offset+=4,t}readU64(){const t=this.readBuffer(8);return new re.default(t,"le")}readU128(){const t=this.readBuffer(16);return new re.default(t,"le")}readU256(){const t=this.readBuffer(32);return new re.default(t,"le")}readU512(){const t=this.readBuffer(64);return new re.default(t,"le")}readBuffer(t){if(this.offset+t>this.buf.length)throw new ae(`Expected buffer length ${t} isn't within bounds`);const e=this.buf.slice(this.offset,this.offset+t);return this.offset+=t,e}readString(){const t=this.readU32(),e=this.readBuffer(t);try{return oe.decode(e)}catch(t){throw new ae(`Error decoding UTF-8 string: ${t}`)}}readFixedArray(t){return new Uint8Array(this.readBuffer(t))}readArray(t){const e=this.readU32(),r=Array();for(let n=0;n<e;++n)r.push(t());return r}}function le(t){return t.charAt(0).toUpperCase()+t.slice(1)}function de(t,e,r,n,i){try{if("string"==typeof n)i[`write${le(n)}`](r);else if(n instanceof Array)if("number"==typeof n[0]){if(r.length!==n[0])throw new ae(`Expecting byte array of length ${n[0]}, but got ${r.length} bytes`);i.writeFixedArray(r)}else if(2===n.length&&"number"==typeof n[1]){if(r.length!==n[1])throw new ae(`Expecting byte array of length ${n[1]}, but got ${r.length} bytes`);for(let e=0;e<n[1];e++)de(t,null,r[e],n[0],i)}else i.writeArray(r,(r=>{de(t,e,r,n[0],i)}));else if(void 0!==n.kind)switch(n.kind){case"option":null==r?i.writeU8(0):(i.writeU8(1),de(t,e,r,n.type,i));break;case"map":i.writeU32(r.size),r.forEach(((r,o)=>{de(t,e,o,n.key,i),de(t,e,r,n.value,i)}));break;default:throw new ae(`FieldType ${n} unrecognized`)}else fe(t,r,i)}catch(t){throw t instanceof ae&&t.addToFieldPath(e),t}}function fe(t,e,r){if("function"==typeof e.borshSerialize)return void e.borshSerialize(r);const n=t.get(e.constructor);if(!n)throw new ae(`Class ${e.constructor.name} is missing in schema`);if("struct"===n.kind)n.fields.map((([n,i])=>{de(t,n,e[n],i,r)}));else{if("enum"!==n.kind)throw new ae(`Unexpected schema kind: ${n.kind} for ${e.constructor.name}`);{const i=e[n.field];for(let o=0;o<n.values.length;++o){const[s,a]=n.values[o];if(s===i){r.writeU8(o),de(t,s,e[s],a,r);break}}}}}Xt([ce],he.prototype,"readU8",null),Xt([ce],he.prototype,"readU16",null),Xt([ce],he.prototype,"readU32",null),Xt([ce],he.prototype,"readU64",null),Xt([ce],he.prototype,"readU128",null),Xt([ce],he.prototype,"readU256",null),Xt([ce],he.prototype,"readU512",null),Xt([ce],he.prototype,"readString",null),Xt([ce],he.prototype,"readFixedArray",null),Xt([ce],he.prototype,"readArray",null),Ct.BinaryReader=he;var pe=Ct.serialize=function(t,e,r=ue){const n=new r;return fe(t,e,n),n.toArray()};function me(t,e,r,n){try{if("string"==typeof r)return n[`read${le(r)}`]();if(r instanceof Array){if("number"==typeof r[0])return n.readFixedArray(r[0]);if("number"==typeof r[1]){const e=[];for(let i=0;i<r[1];i++)e.push(me(t,null,r[0],n));return e}return n.readArray((()=>me(t,e,r[0],n)))}if("option"===r.kind){return n.readU8()?me(t,e,r.type,n):void 0}if("map"===r.kind){let i=new Map;const o=n.readU32();for(let s=0;s<o;s++){const o=me(t,e,r.key,n),s=me(t,e,r.value,n);i.set(o,s)}return i}return ge(t,r,n)}catch(t){throw t instanceof ae&&t.addToFieldPath(e),t}}function ge(t,e,r){if("function"==typeof e.borshDeserialize)return e.borshDeserialize(r);const n=t.get(e);if(!n)throw new ae(`Class ${e.name} is missing in schema`);if("struct"===n.kind){const n={};for(const[i,o]of t.get(e).fields)n[i]=me(t,i,o,r);return new e(n)}if("enum"===n.kind){const i=r.readU8();if(i>=n.values.length)throw new ae(`Enum index: ${i} is out of range`);const[o,s]=n.values[i];return new e({[o]:me(t,o,s,r)})}throw new ae(`Unexpected schema kind: ${n.kind} for ${e.constructor.name}`)}var ye=Ct.deserialize=function(t,e,r,n=he){const i=new n(r),o=ge(t,e,i);if(i.offset<r.length)throw new ae(`Unexpected ${r.length-i.offset} bytes after deserialized data`);return o};ee=Ct.deserializeUnchecked=function(t,e,r,n=he){return ge(t,e,new n(r))};var we={};Object.defineProperty(we,"__esModule",{value:!0}),we.s16=we.s8=we.nu64be=we.u48be=we.u40be=we.u32be=we.u24be=we.u16be=sr=we.nu64=we.u48=we.u40=or=we.u32=we.u24=ir=we.u16=nr=we.u8=rr=we.offset=we.greedy=we.Constant=we.UTF8=we.CString=we.Blob=we.Boolean=we.BitField=we.BitStructure=we.VariantLayout=we.Union=we.UnionLayoutDiscriminator=we.UnionDiscriminator=we.Structure=we.Sequence=we.DoubleBE=we.Double=we.FloatBE=we.Float=we.NearInt64BE=we.NearInt64=we.NearUInt64BE=we.NearUInt64=we.IntBE=we.Int=we.UIntBE=we.UInt=we.OffsetLayout=we.GreedyCount=we.ExternalLayout=we.bindConstructorLayout=we.nameWithProperty=we.Layout=we.uint8ArrayToBuffer=we.checkUint8Array=void 0,we.constant=we.utf8=we.cstr=hr=we.blob=we.unionLayoutDiscriminator=we.union=cr=we.seq=we.bits=ur=we.struct=we.f64be=we.f64=we.f32be=we.f32=we.ns64be=we.s48be=we.s40be=we.s32be=we.s24be=we.s16be=ar=we.ns64=we.s48=we.s40=we.s32=we.s24=void 0;const be=o.default;function ve(t){if(!(t instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}function ke(t){return ve(t),be.Buffer.from(t.buffer,t.byteOffset,t.length)}we.checkUint8Array=ve,we.uint8ArrayToBuffer=ke;class Se{constructor(t,e){if(!Number.isInteger(t))throw new TypeError("span must be an integer");this.span=t,this.property=e}makeDestinationObject(){return{}}getSpan(t,e){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(t){const e=Object.create(this.constructor.prototype);return Object.assign(e,this),e.property=t,e}fromArray(t){}}function _e(t,e){return e.property?t+"["+e.property+"]":t}we.Layout=Se,we.nameWithProperty=_e,we.bindConstructorLayout=function(t,e){if("function"!=typeof t)throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(t,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Se))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");t.layout_=e,e.boundConstructor_=t,e.makeDestinationObject=()=>new t,Object.defineProperty(t.prototype,"encode",{value(t,r){return e.encode(this,t,r)},writable:!0}),Object.defineProperty(t,"decode",{value:(t,r)=>e.decode(t,r),writable:!0})};class Ae extends Se{isCount(){throw new Error("ExternalLayout is abstract")}}we.ExternalLayout=Ae;class Me extends Ae{constructor(t=1,e){if(!Number.isInteger(t)||0>=t)throw new TypeError("elementSpan must be a (positive) integer");super(-1,e),this.elementSpan=t}isCount(){return!0}decode(t,e=0){ve(t);const r=t.length-e;return Math.floor(r/this.elementSpan)}encode(t,e,r){return 0}}we.GreedyCount=Me;class Ie extends Ae{constructor(t,e=0,r){if(!(t instanceof Se))throw new TypeError("layout must be a Layout");if(!Number.isInteger(e))throw new TypeError("offset must be integer or undefined");super(t.span,r||t.property),this.layout=t,this.offset=e}isCount(){return this.layout instanceof Ee||this.layout instanceof xe}decode(t,e=0){return this.layout.decode(t,e+this.offset)}encode(t,e,r=0){return this.layout.encode(t,e,r+this.offset)}}we.OffsetLayout=Ie;class Ee extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readUIntLE(e,this.span)}encode(t,e,r=0){return ke(e).writeUIntLE(t,r,this.span),this.span}}we.UInt=Ee;class xe extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readUIntBE(e,this.span)}encode(t,e,r=0){return ke(e).writeUIntBE(t,r,this.span),this.span}}we.UIntBE=xe;class Be extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readIntLE(e,this.span)}encode(t,e,r=0){return ke(e).writeIntLE(t,r,this.span),this.span}}we.Int=Be;class Pe extends Se{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ke(t).readIntBE(e,this.span)}encode(t,e,r=0){return ke(e).writeIntBE(t,r,this.span),this.span}}we.IntBE=Pe;const Re=Math.pow(2,32);function Te(t){const e=Math.floor(t/Re);return{hi32:e,lo32:t-e*Re}}function Le(t,e){return t*Re+e}class Oe extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t),n=r.readUInt32LE(e);return Le(r.readUInt32LE(e+4),n)}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeUInt32LE(n.lo32,r),i.writeUInt32LE(n.hi32,r+4),8}}we.NearUInt64=Oe;class Ce extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t);return Le(r.readUInt32BE(e),r.readUInt32BE(e+4))}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeUInt32BE(n.hi32,r),i.writeUInt32BE(n.lo32,r+4),8}}we.NearUInt64BE=Ce;class Ue extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t),n=r.readUInt32LE(e);return Le(r.readInt32LE(e+4),n)}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeUInt32LE(n.lo32,r),i.writeInt32LE(n.hi32,r+4),8}}we.NearInt64=Ue;class Ne extends Se{constructor(t){super(8,t)}decode(t,e=0){const r=ke(t);return Le(r.readInt32BE(e),r.readUInt32BE(e+4))}encode(t,e,r=0){const n=Te(t),i=ke(e);return i.writeInt32BE(n.hi32,r),i.writeUInt32BE(n.lo32,r+4),8}}we.NearInt64BE=Ne;class ze extends Se{constructor(t){super(4,t)}decode(t,e=0){return ke(t).readFloatLE(e)}encode(t,e,r=0){return ke(e).writeFloatLE(t,r),4}}we.Float=ze;class Ke extends Se{constructor(t){super(4,t)}decode(t,e=0){return ke(t).readFloatBE(e)}encode(t,e,r=0){return ke(e).writeFloatBE(t,r),4}}we.FloatBE=Ke;class We extends Se{constructor(t){super(8,t)}decode(t,e=0){return ke(t).readDoubleLE(e)}encode(t,e,r=0){return ke(e).writeDoubleLE(t,r),8}}we.Double=We;class qe extends Se{constructor(t){super(8,t)}decode(t,e=0){return ke(t).readDoubleBE(e)}encode(t,e,r=0){return ke(e).writeDoubleBE(t,r),8}}we.DoubleBE=qe;class De extends Se{constructor(t,e,r){if(!(t instanceof Se))throw new TypeError("elementLayout must be a Layout");if(!(e instanceof Ae&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(e instanceof Ae)&&0<t.span&&(n=e*t.span),super(n,r),this.elementLayout=t,this.count=e}getSpan(t,e=0){if(0<=this.span)return this.span;let r=0,n=this.count;if(n instanceof Ae&&(n=n.decode(t,e)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let i=0;for(;i<n;)r+=this.elementLayout.getSpan(t,e+r),++i}return r}decode(t,e=0){const r=[];let n=0,i=this.count;for(i instanceof Ae&&(i=i.decode(t,e));n<i;)r.push(this.elementLayout.decode(t,e)),e+=this.elementLayout.getSpan(t,e),n+=1;return r}encode(t,e,r=0){const n=this.elementLayout,i=t.reduce(((t,i)=>t+n.encode(i,e,r+t)),0);return this.count instanceof Ae&&this.count.encode(t.length,e,r),i}}we.Sequence=De;class je extends Se{constructor(t,e,r){if(!Array.isArray(t)||!t.reduce(((t,e)=>t&&e instanceof Se),!0))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof e&&void 0===r&&(r=e,e=void 0);for(const e of t)if(0>e.span&&void 0===e.property)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=t.reduce(((t,e)=>t+e.getSpan()),0)}catch(t){}super(n,e),this.fields=t,this.decodePrefixes=!!r}getSpan(t,e=0){if(0<=this.span)return this.span;let r=0;try{r=this.fields.reduce(((r,n)=>{const i=n.getSpan(t,e);return e+=i,r+i}),0)}catch(t){throw new RangeError("indeterminate span")}return r}decode(t,e=0){ve(t);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(t,e)),e+=n.getSpan(t,e),this.decodePrefixes&&t.length===e)break;return r}encode(t,e,r=0){const n=r;let i=0,o=0;for(const n of this.fields){let s=n.span;if(o=0<s?s:0,void 0!==n.property){const i=t[n.property];void 0!==i&&(o=n.encode(i,e,r),0>s&&(s=n.getSpan(e,r)))}i=r,r+=s}return i+o-n}fromArray(t){const e=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<t.length&&(e[r.property]=t.shift());return e}layoutFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}offsetOf(t){if("string"!=typeof t)throw new TypeError("property must be string");let e=0;for(const r of this.fields){if(r.property===t)return e;0>r.span?e=-1:0<=e&&(e+=r.span)}}}we.Structure=je;class He{constructor(t){this.property=t}decode(t,e){throw new Error("UnionDiscriminator is abstract")}encode(t,e,r){throw new Error("UnionDiscriminator is abstract")}}we.UnionDiscriminator=He;class Fe extends He{constructor(t,e){if(!(t instanceof Ae&&t.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(e||t.property||"variant"),this.layout=t}decode(t,e){return this.layout.decode(t,e)}encode(t,e,r){return this.layout.encode(t,e,r)}}we.UnionLayoutDiscriminator=Fe;class $e extends Se{constructor(t,e,r){let n;if(t instanceof Ee||t instanceof xe)n=new Fe(new Ie(t));else if(t instanceof Ae&&t.isCount())n=new Fe(t);else{if(!(t instanceof He))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");n=t}if(void 0===e&&(e=null),!(null===e||e instanceof Se))throw new TypeError("defaultLayout must be null or a Layout");if(null!==e){if(0>e.span)throw new Error("defaultLayout must have constant span");void 0===e.property&&(e=e.replicate("content"))}let i=-1;e&&(i=e.span,0<=i&&(t instanceof Ee||t instanceof xe)&&(i+=n.layout.span)),super(i,r),this.discriminator=n,this.usesPrefixDiscriminator=t instanceof Ee||t instanceof xe,this.defaultLayout=e,this.registry={};let o=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(t){return o(t)},this.configGetSourceVariant=function(t){o=t.bind(this)}}getSpan(t,e=0){if(0<=this.span)return this.span;const r=this.getVariant(t,e);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(t,e)}defaultGetSourceVariant(t){if(Object.prototype.hasOwnProperty.call(t,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(t,this.defaultLayout.property))return;const e=this.registry[t[this.discriminator.property]];if(e&&(!e.layout||e.property&&Object.prototype.hasOwnProperty.call(t,e.property)))return e}else for(const e in this.registry){const r=this.registry[e];if(r.property&&Object.prototype.hasOwnProperty.call(t,r.property))return r}throw new Error("unable to infer src variant")}decode(t,e=0){let r;const n=this.discriminator,i=n.decode(t,e),o=this.registry[i];if(void 0===o){const o=this.defaultLayout;let s=0;this.usesPrefixDiscriminator&&(s=n.layout.span),r=this.makeDestinationObject(),r[n.property]=i,r[o.property]=o.decode(t,e+s)}else r=o.decode(t,e);return r}encode(t,e,r=0){const n=this.getSourceVariant(t);if(void 0===n){const n=this.discriminator,i=this.defaultLayout;let o=0;return this.usesPrefixDiscriminator&&(o=n.layout.span),n.encode(t[n.property],e,r),o+i.encode(t[i.property],e,r+o)}return n.encode(t,e,r)}addVariant(t,e,r){const n=new Ve(this,t,e,r);return this.registry[t]=n,n}getVariant(t,e=0){let r;return r=t instanceof Uint8Array?this.discriminator.decode(t,e):t,this.registry[r]}}we.Union=$e;class Ve extends Se{constructor(t,e,r,n){if(!(t instanceof $e))throw new TypeError("union must be a Union");if(!Number.isInteger(e)||0>e)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof Se))throw new TypeError("layout must be a Layout");if(null!==t.defaultLayout&&0<=r.span&&r.span>t.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let i=t.span;0>t.span&&(i=r?r.span:0,0<=i&&t.usesPrefixDiscriminator&&(i+=t.discriminator.layout.span)),super(i,n),this.union=t,this.variant=e,this.layout=r||null}getSpan(t,e=0){if(0<=this.span)return this.span;let r=0;this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span);let n=0;return this.layout&&(n=this.layout.getSpan(t,e+r)),r+n}decode(t,e=0){const r=this.makeDestinationObject();if(this!==this.union.getVariant(t,e))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(t,e+n):this.property?r[this.property]=!0:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(t,e,r=0){let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(t,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,e,r);let i=n;if(this.layout&&(this.layout.encode(t[this.property],e,r+n),i+=this.layout.getSpan(e,r+n),0<=this.union.span&&i>this.union.span))throw new Error("encoded variant overruns containing union");return i}fromArray(t){if(this.layout)return this.layout.fromArray(t)}}function Ge(t){return 0>t&&(t+=4294967296),t}we.VariantLayout=Ve;class Ze extends Se{constructor(t,e,r){if(!(t instanceof Ee||t instanceof xe))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof e&&void 0===r&&(r=e,e=!1),4<t.span)throw new RangeError("word cannot exceed 32 bits");super(t.span,r),this.word=t,this.msb=!!e,this.fields=[];let n=0;this._packedSetValue=function(t){return n=Ge(t),this},this._packedGetValue=function(){return n}}decode(t,e=0){const r=this.makeDestinationObject(),n=this.word.decode(t,e);this._packedSetValue(n);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(t));return r}encode(t,e,r=0){const n=this.word.decode(e,r);this._packedSetValue(n);for(const e of this.fields)if(void 0!==e.property){const r=t[e.property];void 0!==r&&e.encode(r)}return this.word.encode(this._packedGetValue(),e,r)}addField(t,e){const r=new Ye(this,t,e);return this.fields.push(r),r}addBoolean(t){const e=new Je(this,t);return this.fields.push(e),e}fieldFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}}we.BitStructure=Ze;class Ye{constructor(t,e,r){if(!(t instanceof Ze))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(e)||0>=e)throw new TypeError("bits must be positive integer");const n=8*t.span,i=t.fields.reduce(((t,e)=>t+e.bits),0);if(e+i>n)throw new Error("bits too long for span remainder ("+(n-i)+" of "+n+" remain)");this.container=t,this.bits=e,this.valueMask=(1<<e)-1,32===e&&(this.valueMask=4294967295),this.start=i,this.container.msb&&(this.start=n-i-e),this.wordMask=Ge(this.valueMask<<this.start),this.property=r}decode(t,e){return Ge(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(t){if("number"!=typeof t||!Number.isInteger(t)||t!==Ge(t&this.valueMask))throw new TypeError(_e("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const e=this.container._packedGetValue(),r=Ge(t<<this.start);this.container._packedSetValue(Ge(e&~this.wordMask)|r)}}we.BitField=Ye;class Je extends Ye{constructor(t,e){super(t,1,e)}decode(t,e){return!!super.decode(t,e)}encode(t){"boolean"==typeof t&&(t=+t),super.encode(t)}}we.Boolean=Je;class Xe extends Se{constructor(t,e){if(!(t instanceof Ae&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;t instanceof Ae||(r=t),super(r,e),this.length=t}getSpan(t,e){let r=this.span;return 0>r&&(r=this.length.decode(t,e)),r}decode(t,e=0){let r=this.span;return 0>r&&(r=this.length.decode(t,e)),ke(t).slice(e,e+r)}encode(t,e,r){let n=this.length;if(this.length instanceof Ae&&(n=t.length),!(t instanceof Uint8Array&&n===t.length))throw new TypeError(_e("Blob.encode",this)+" requires (length "+n+") Uint8Array as src");if(r+n>e.length)throw new RangeError("encoding overruns Uint8Array");const i=ke(t);return ke(e).write(i.toString("hex"),r,n,"hex"),this.length instanceof Ae&&this.length.encode(n,e,r),n}}we.Blob=Xe;class Qe extends Se{constructor(t){super(-1,t)}getSpan(t,e=0){ve(t);let r=e;for(;r<t.length&&0!==t[r];)r+=1;return 1+r-e}decode(t,e=0){const r=this.getSpan(t,e);return ke(t).slice(e,e+r-1).toString("utf-8")}encode(t,e,r=0){"string"!=typeof t&&(t=String(t));const n=be.Buffer.from(t,"utf8"),i=n.length;if(r+i>e.length)throw new RangeError("encoding overruns Buffer");const o=ke(e);return n.copy(o,r),o[r+i]=0,i+1}}we.CString=Qe;class tr extends Se{constructor(t,e){if("string"==typeof t&&void 0===e&&(e=t,t=void 0),void 0===t)t=-1;else if(!Number.isInteger(t))throw new TypeError("maxSpan must be an integer");super(-1,e),this.maxSpan=t}getSpan(t,e=0){return ve(t),t.length-e}decode(t,e=0){const r=this.getSpan(t,e);if(0<=this.maxSpan&&this.maxSpan<r)throw new RangeError("text length exceeds maxSpan");return ke(t).slice(e,e+r).toString("utf-8")}encode(t,e,r=0){"string"!=typeof t&&(t=String(t));const n=be.Buffer.from(t,"utf8"),i=n.length;if(0<=this.maxSpan&&this.maxSpan<i)throw new RangeError("text length exceeds maxSpan");if(r+i>e.length)throw new RangeError("encoding overruns Buffer");return n.copy(ke(e),r),i}}we.UTF8=tr;class er extends Se{constructor(t,e){super(0,e),this.value=t}decode(t,e){return this.value}encode(t,e,r){return 0}}we.Constant=er,we.greedy=(t,e)=>new Me(t,e);var rr=we.offset=(t,e,r)=>new Ie(t,e,r),nr=we.u8=t=>new Ee(1,t),ir=we.u16=t=>new Ee(2,t);we.u24=t=>new Ee(3,t);var or=we.u32=t=>new Ee(4,t);we.u40=t=>new Ee(5,t),we.u48=t=>new Ee(6,t);var sr=we.nu64=t=>new Oe(t);we.u16be=t=>new xe(2,t),we.u24be=t=>new xe(3,t),we.u32be=t=>new xe(4,t),we.u40be=t=>new xe(5,t),we.u48be=t=>new xe(6,t),we.nu64be=t=>new Ce(t),we.s8=t=>new Be(1,t),we.s16=t=>new Be(2,t),we.s24=t=>new Be(3,t),we.s32=t=>new Be(4,t),we.s40=t=>new Be(5,t),we.s48=t=>new Be(6,t);var ar=we.ns64=t=>new Ue(t);we.s16be=t=>new Pe(2,t),we.s24be=t=>new Pe(3,t),we.s32be=t=>new Pe(4,t),we.s40be=t=>new Pe(5,t),we.s48be=t=>new Pe(6,t),we.ns64be=t=>new Ne(t),we.f32=t=>new ze(t),we.f32be=t=>new Ke(t),we.f64=t=>new We(t),we.f64be=t=>new qe(t);var ur=we.struct=(t,e,r)=>new je(t,e,r);we.bits=(t,e,r)=>new Ze(t,e,r);var cr=we.seq=(t,e,r)=>new De(t,e,r);we.union=(t,e,r)=>new $e(t,e,r),we.unionLayoutDiscriminator=(t,e)=>new Fe(t,e);var hr=we.blob=(t,e)=>new Xe(t,e);we.cstr=t=>new Qe(t),we.utf8=(t,e)=>new tr(t,e),we.constant=(t,e)=>new er(t,e);var lr={};Object.defineProperty(lr,"__esModule",{value:!0});var dr=lr.toBigIntLE=function(t){{const e=Buffer.from(t);e.reverse();const r=e.toString("hex");return 0===r.length?BigInt(0):BigInt(`0x${r}`)}};lr.toBigIntBE=function(t){{const e=t.toString("hex");return 0===e.length?BigInt(0):BigInt(`0x${e}`)}};var fr,pr=lr.toBufferLE=function(t,e){{const r=t.toString(16),n=Buffer.from(r.padStart(2*e,"0").slice(0,2*e),"hex");return n.reverse(),n}};lr.toBufferBE=function(t,e){{const r=t.toString(16);return Buffer.from(r.padStart(2*e,"0").slice(0,2*e),"hex")}};class mr extends TypeError{constructor(t,e){let r;const{message:n,...i}=t,{path:o}=t;super(0===o.length?n:"At path: "+o.join(".")+" -- "+n),Object.assign(this,i),this.name=this.constructor.name,this.failures=()=>{var n;return null!=(n=r)?n:r=[t,...e()]}}}function gr(t){return"object"==typeof t&&null!=t}function yr(t){return"string"==typeof t?JSON.stringify(t):""+t}function wr(t,e,r,n){if(!0===t)return;!1===t?t={}:"string"==typeof t&&(t={message:t});const{path:i,branch:o}=e,{type:s}=r,{refinement:a,message:u="Expected a value of type `"+s+"`"+(a?" with refinement `"+a+"`":"")+", but received: `"+yr(n)+"`"}=t;return{value:n,type:s,refinement:a,key:i[i.length-1],path:i,branch:o,...t,message:u}}function*br(t,e,r,n){var i;gr(i=t)&&"function"==typeof i[Symbol.iterator]||(t=[t]);for(const i of t){const t=wr(i,e,r,n);t&&(yield t)}}function*vr(t,e,r={}){const{path:n=[],branch:i=[t],coerce:o=!1,mask:s=!1}=r,a={path:n,branch:i};if(o&&(t=e.coercer(t,a),s&&"type"!==e.type&&gr(e.schema)&&gr(t)&&!Array.isArray(t)))for(const r in t)void 0===e.schema[r]&&delete t[r];let u=!0;for(const r of e.validator(t,a))u=!1,yield[r,void 0];for(let[r,c,h]of e.entries(t,a)){const e=vr(c,h,{path:void 0===r?n:[...n,r],branch:void 0===r?i:[...i,c],coerce:o,mask:s});for(const n of e)n[0]?(u=!1,yield[n[0],void 0]):o&&(c=n[1],void 0===r?t=c:t instanceof Map?t.set(r,c):t instanceof Set?t.add(c):gr(t)&&(t[r]=c))}if(u)for(const r of e.refiner(t,a))u=!1,yield[r,void 0];u&&(yield[void 0,t])}class kr{constructor(t){const{type:e,schema:r,validator:n,refiner:i,coercer:o=(t=>t),entries:s=function*(){}}=t;this.type=e,this.schema=r,this.entries=s,this.coercer=o,this.validator=n?(t,e)=>br(n(t,e),e,this,t):()=>[],this.refiner=i?(t,e)=>br(i(t,e),e,this,t):()=>[]}assert(t){return Sr(t,this)}create(t){return _r(t,this)}is(t){return Ar(t,this)}mask(t){return function(t,e){const r=Mr(t,e,{coerce:!0,mask:!0});if(r[0])throw r[0];return r[1]}(t,this)}validate(t,e={}){return Mr(t,this,e)}}function Sr(t,e){const r=Mr(t,e);if(r[0])throw r[0]}function _r(t,e){const r=Mr(t,e,{coerce:!0});if(r[0])throw r[0];return r[1]}function Ar(t,e){return!Mr(t,e)[0]}function Mr(t,e,r={}){const n=vr(t,e,r),i=function(t){const{done:e,value:r}=t.next();return e?void 0:r}(n);if(i[0]){return[new mr(i[0],(function*(){for(const t of n)t[0]&&(yield t[0])})),void 0]}return[void 0,i[1]]}function Ir(t,e){return new kr({type:t,schema:null,validator:e})}function Er(t){return new kr({type:"array",schema:t,*entries(e){if(t&&Array.isArray(e))for(const[r,n]of e.entries())yield[r,n,t]},coercer:t=>Array.isArray(t)?t.slice():t,validator:t=>Array.isArray(t)||"Expected an array value, but received: "+yr(t)})}function xr(){return Ir("boolean",(t=>"boolean"==typeof t))}function Br(t){return Ir("instance",(e=>e instanceof t||"Expected a `"+t.name+"` instance, but received: "+yr(e)))}function Pr(t){const e=yr(t),r=typeof t;return new kr({type:"literal",schema:"string"===r||"number"===r||"boolean"===r?t:null,validator:r=>r===t||"Expected the literal `"+e+"`, but received: "+yr(r)})}function Rr(t){return new kr({...t,validator:(e,r)=>null===e||t.validator(e,r),refiner:(e,r)=>null===e||t.refiner(e,r)})}function Tr(){return Ir("number",(t=>"number"==typeof t&&!isNaN(t)||"Expected a number, but received: "+yr(t)))}function Lr(t){return new kr({...t,validator:(e,r)=>void 0===e||t.validator(e,r),refiner:(e,r)=>void 0===e||t.refiner(e,r)})}function Or(t,e){return new kr({type:"record",schema:null,*entries(r){if(gr(r))for(const n in r){const i=r[n];yield[n,n,t],yield[n,i,e]}},validator:t=>gr(t)||"Expected an object, but received: "+yr(t)})}function Cr(){return Ir("string",(t=>"string"==typeof t||"Expected a string, but received: "+yr(t)))}function Ur(t){const e=Ir("never",(()=>!1));return new kr({type:"tuple",schema:null,*entries(r){if(Array.isArray(r)){const n=Math.max(t.length,r.length);for(let i=0;i<n;i++)yield[i,r[i],t[i]||e]}},validator:t=>Array.isArray(t)||"Expected an array, but received: "+yr(t)})}function Nr(t){const e=Object.keys(t);return new kr({type:"type",schema:t,*entries(r){if(gr(r))for(const n of e)yield[n,r[n],t[n]]},validator:t=>gr(t)||"Expected an object, but received: "+yr(t)})}function zr(t){const e=t.map((t=>t.type)).join(" | ");return new kr({type:"union",schema:null,validator(r,n){const i=[];for(const e of t){const[...t]=vr(r,e,n),[o]=t;if(!o[0])return[];for(const[e]of t)e&&i.push(e)}return["Expected the value to satisfy a union of `"+e+"`, but received: "+yr(r),...i]}})}function Kr(){return Ir("unknown",(()=>!0))}function Wr(t,e,r){return new kr({...t,coercer:(n,i)=>Ar(n,e)?t.coercer(r(n,i),i):t.coercer(n,i)})}var qr=new Uint8Array(16);function Dr(){if(!fr&&!(fr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return fr(qr)}var jr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Hr(t){return"string"==typeof t&&jr.test(t)}for(var Fr,$r,Vr=[],Gr=0;Gr<256;++Gr)Vr.push((Gr+256).toString(16).substr(1));function Zr(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(Vr[t[e+0]]+Vr[t[e+1]]+Vr[t[e+2]]+Vr[t[e+3]]+"-"+Vr[t[e+4]]+Vr[t[e+5]]+"-"+Vr[t[e+6]]+Vr[t[e+7]]+"-"+Vr[t[e+8]]+Vr[t[e+9]]+"-"+Vr[t[e+10]]+Vr[t[e+11]]+Vr[t[e+12]]+Vr[t[e+13]]+Vr[t[e+14]]+Vr[t[e+15]]).toLowerCase();if(!Hr(r))throw TypeError("Stringified UUID is invalid");return r}var Yr=0,Jr=0;function Xr(t){if(!Hr(t))throw TypeError("Invalid UUID");var e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=255&e,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=255&e,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=255&e,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=255&e,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=255&e,r}function Qr(t,e,r){function n(t,n,i,o){if("string"==typeof t&&(t=function(t){t=unescape(encodeURIComponent(t));for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}(t)),"string"==typeof n&&(n=Xr(n)),16!==n.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var s=new Uint8Array(16+t.length);if(s.set(n),s.set(t,n.length),(s=r(s))[6]=15&s[6]|e,s[8]=63&s[8]|128,i){o=o||0;for(var a=0;a<16;++a)i[o+a]=s[a];return i}return Zr(s)}try{n.name=t}catch(t){}return n.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",n.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",n}function tn(t){return 14+(t+64>>>9<<4)+1}function en(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function rn(t,e,r,n,i,o){return en((s=en(en(e,t),en(n,o)))<<(a=i)|s>>>32-a,r);var s,a}function nn(t,e,r,n,i,o,s){return rn(e&r|~e&n,t,e,i,o,s)}function on(t,e,r,n,i,o,s){return rn(e&n|r&~n,t,e,i,o,s)}function sn(t,e,r,n,i,o,s){return rn(e^r^n,t,e,i,o,s)}function an(t,e,r,n,i,o,s){return rn(r^(e|~n),t,e,i,o,s)}var un=Qr("v3",48,(function(t){if("string"==typeof t){var e=unescape(encodeURIComponent(t));t=new Uint8Array(e.length);for(var r=0;r<e.length;++r)t[r]=e.charCodeAt(r)}return function(t){for(var e=[],r=32*t.length,n="0123456789abcdef",i=0;i<r;i+=8){var o=t[i>>5]>>>i%32&255,s=parseInt(n.charAt(o>>>4&15)+n.charAt(15&o),16);e.push(s)}return e}(function(t,e){t[e>>5]|=128<<e%32,t[tn(e)-1]=e;for(var r=1732584193,n=-271733879,i=-1732584194,o=271733878,s=0;s<t.length;s+=16){var a=r,u=n,c=i,h=o;r=nn(r,n,i,o,t[s],7,-680876936),o=nn(o,r,n,i,t[s+1],12,-389564586),i=nn(i,o,r,n,t[s+2],17,606105819),n=nn(n,i,o,r,t[s+3],22,-1044525330),r=nn(r,n,i,o,t[s+4],7,-176418897),o=nn(o,r,n,i,t[s+5],12,1200080426),i=nn(i,o,r,n,t[s+6],17,-1473231341),n=nn(n,i,o,r,t[s+7],22,-45705983),r=nn(r,n,i,o,t[s+8],7,1770035416),o=nn(o,r,n,i,t[s+9],12,-1958414417),i=nn(i,o,r,n,t[s+10],17,-42063),n=nn(n,i,o,r,t[s+11],22,-1990404162),r=nn(r,n,i,o,t[s+12],7,1804603682),o=nn(o,r,n,i,t[s+13],12,-40341101),i=nn(i,o,r,n,t[s+14],17,-1502002290),r=on(r,n=nn(n,i,o,r,t[s+15],22,1236535329),i,o,t[s+1],5,-165796510),o=on(o,r,n,i,t[s+6],9,-1069501632),i=on(i,o,r,n,t[s+11],14,643717713),n=on(n,i,o,r,t[s],20,-373897302),r=on(r,n,i,o,t[s+5],5,-701558691),o=on(o,r,n,i,t[s+10],9,38016083),i=on(i,o,r,n,t[s+15],14,-660478335),n=on(n,i,o,r,t[s+4],20,-405537848),r=on(r,n,i,o,t[s+9],5,568446438),o=on(o,r,n,i,t[s+14],9,-1019803690),i=on(i,o,r,n,t[s+3],14,-187363961),n=on(n,i,o,r,t[s+8],20,1163531501),r=on(r,n,i,o,t[s+13],5,-1444681467),o=on(o,r,n,i,t[s+2],9,-51403784),i=on(i,o,r,n,t[s+7],14,1735328473),r=sn(r,n=on(n,i,o,r,t[s+12],20,-1926607734),i,o,t[s+5],4,-378558),o=sn(o,r,n,i,t[s+8],11,-2022574463),i=sn(i,o,r,n,t[s+11],16,1839030562),n=sn(n,i,o,r,t[s+14],23,-35309556),r=sn(r,n,i,o,t[s+1],4,-1530992060),o=sn(o,r,n,i,t[s+4],11,1272893353),i=sn(i,o,r,n,t[s+7],16,-155497632),n=sn(n,i,o,r,t[s+10],23,-1094730640),r=sn(r,n,i,o,t[s+13],4,681279174),o=sn(o,r,n,i,t[s],11,-358537222),i=sn(i,o,r,n,t[s+3],16,-722521979),n=sn(n,i,o,r,t[s+6],23,76029189),r=sn(r,n,i,o,t[s+9],4,-640364487),o=sn(o,r,n,i,t[s+12],11,-421815835),i=sn(i,o,r,n,t[s+15],16,530742520),r=an(r,n=sn(n,i,o,r,t[s+2],23,-995338651),i,o,t[s],6,-198630844),o=an(o,r,n,i,t[s+7],10,1126891415),i=an(i,o,r,n,t[s+14],15,-1416354905),n=an(n,i,o,r,t[s+5],21,-57434055),r=an(r,n,i,o,t[s+12],6,1700485571),o=an(o,r,n,i,t[s+3],10,-1894986606),i=an(i,o,r,n,t[s+10],15,-1051523),n=an(n,i,o,r,t[s+1],21,-2054922799),r=an(r,n,i,o,t[s+8],6,1873313359),o=an(o,r,n,i,t[s+15],10,-30611744),i=an(i,o,r,n,t[s+6],15,-1560198380),n=an(n,i,o,r,t[s+13],21,1309151649),r=an(r,n,i,o,t[s+4],6,-145523070),o=an(o,r,n,i,t[s+11],10,-1120210379),i=an(i,o,r,n,t[s+2],15,718787259),n=an(n,i,o,r,t[s+9],21,-343485551),r=en(r,a),n=en(n,u),i=en(i,c),o=en(o,h)}return[r,n,i,o]}(function(t){if(0===t.length)return[];for(var e=8*t.length,r=new Uint32Array(tn(e)),n=0;n<e;n+=8)r[n>>5]|=(255&t[n/8])<<n%32;return r}(t),8*t.length))})),cn=un;function hn(t,e,r,n){switch(t){case 0:return e&r^~e&n;case 1:case 3:return e^r^n;case 2:return e&r^e&n^r&n}}function ln(t,e){return t<<e|t>>>32-e}var dn=Qr("v5",80,(function(t){var e=[1518500249,1859775393,2400959708,3395469782],r=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof t){var n=unescape(encodeURIComponent(t));t=[];for(var i=0;i<n.length;++i)t.push(n.charCodeAt(i))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var o=t.length/4+2,s=Math.ceil(o/16),a=new Array(s),u=0;u<s;++u){for(var c=new Uint32Array(16),h=0;h<16;++h)c[h]=t[64*u+4*h]<<24|t[64*u+4*h+1]<<16|t[64*u+4*h+2]<<8|t[64*u+4*h+3];a[u]=c}a[s-1][14]=8*(t.length-1)/Math.pow(2,32),a[s-1][14]=Math.floor(a[s-1][14]),a[s-1][15]=8*(t.length-1)&4294967295;for(var l=0;l<s;++l){for(var d=new Uint32Array(80),f=0;f<16;++f)d[f]=a[l][f];for(var p=16;p<80;++p)d[p]=ln(d[p-3]^d[p-8]^d[p-14]^d[p-16],1);for(var m=r[0],g=r[1],y=r[2],w=r[3],b=r[4],v=0;v<80;++v){var k=Math.floor(v/20),S=ln(m,5)+hn(k,g,y,w)+b+e[k]+d[v]>>>0;b=w,w=y,y=ln(g,30)>>>0,g=m,m=S}r[0]=r[0]+m>>>0,r[1]=r[1]+g>>>0,r[2]=r[2]+y>>>0,r[3]=r[3]+w>>>0,r[4]=r[4]+b>>>0}return[r[0]>>24&255,r[0]>>16&255,r[0]>>8&255,255&r[0],r[1]>>24&255,r[1]>>16&255,r[1]>>8&255,255&r[1],r[2]>>24&255,r[2]>>16&255,r[2]>>8&255,255&r[2],r[3]>>24&255,r[3]>>16&255,r[3]>>8&255,255&r[3],r[4]>>24&255,r[4]>>16&255,r[4]>>8&255,255&r[4]]})),fn=dn;var pn=Object.freeze({__proto__:null,v1:function(t,e,r){var n=e&&r||0,i=e||new Array(16),o=(t=t||{}).node||Fr,s=void 0!==t.clockseq?t.clockseq:$r;if(null==o||null==s){var a=t.random||(t.rng||Dr)();null==o&&(o=Fr=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==s&&(s=$r=16383&(a[6]<<8|a[7]))}var u=void 0!==t.msecs?t.msecs:Date.now(),c=void 0!==t.nsecs?t.nsecs:Jr+1,h=u-Yr+(c-Jr)/1e4;if(h<0&&void 0===t.clockseq&&(s=s+1&16383),(h<0||u>Yr)&&void 0===t.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Yr=u,Jr=c,$r=s;var l=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;i[n++]=l>>>24&255,i[n++]=l>>>16&255,i[n++]=l>>>8&255,i[n++]=255&l;var d=u/4294967296*1e4&268435455;i[n++]=d>>>8&255,i[n++]=255&d,i[n++]=d>>>24&15|16,i[n++]=d>>>16&255,i[n++]=s>>>8|128,i[n++]=255&s;for(var f=0;f<6;++f)i[n+f]=o[f];return e||Zr(i)},v3:cn,v4:function(t,e,r){var n=(t=t||{}).random||(t.rng||Dr)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){r=r||0;for(var i=0;i<16;++i)e[r+i]=n[i];return e}return Zr(n)},v5:fn,NIL:"00000000-0000-0000-0000-000000000000",version:function(t){if(!Hr(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)},validate:Hr,stringify:Zr,parse:Xr}),mn=t.getAugmentedNamespace(pn);const gn=mn.v4;var yn=function(t,e,r,n){if("string"!=typeof t)throw new TypeError(t+" must be a string");const i="number"==typeof(n=n||{}).version?n.version:2;if(1!==i&&2!==i)throw new TypeError(i+" must be 1 or 2");const o={method:t};if(2===i&&(o.jsonrpc="2.0"),e){if("object"!=typeof e&&!Array.isArray(e))throw new TypeError(e+" must be an object, array or omitted");o.params=e}if(void 0===r){const t="function"==typeof n.generator?n.generator:function(){return gn()};o.id=t(o,n)}else 2===i&&null===r?n.notificationIdNull&&(o.id=null):o.id=r;return o};const wn=mn.v4,bn=yn,vn=function(t,e){if(!(this instanceof vn))return new vn(t,e);e||(e={}),this.options={reviver:void 0!==e.reviver?e.reviver:null,replacer:void 0!==e.replacer?e.replacer:null,generator:void 0!==e.generator?e.generator:function(){return wn()},version:void 0!==e.version?e.version:2,notificationIdNull:"boolean"==typeof e.notificationIdNull&&e.notificationIdNull},this.callServer=t};var kn=vn;vn.prototype.request=function(t,e,r,n){const i=this;let o=null;const s=Array.isArray(t)&&"function"==typeof e;if(1===this.options.version&&s)throw new TypeError("JSON-RPC 1.0 does not support batching");if(s||!s&&t&&"object"==typeof t&&"function"==typeof e)n=e,o=t;else{"function"==typeof r&&(n=r,r=void 0);const i="function"==typeof n;try{o=bn(t,e,r,{generator:this.options.generator,version:this.options.version,notificationIdNull:this.options.notificationIdNull})}catch(t){if(i)return n(t);throw t}if(!i)return o}let a;try{a=JSON.stringify(o,this.options.replacer)}catch(t){return n(t)}return this.callServer(a,(function(t,e){i._parseResponse(t,e,n)})),o},vn.prototype._parseResponse=function(t,e,r){if(t)return void r(t);if(!e)return r();let n;try{n=JSON.parse(e,this.options.reviver)}catch(t){return r(t)}if(3===r.length){if(Array.isArray(n)){const t=function(t){return void 0!==t.error},e=function(e){return!t(e)};return r(null,n.filter(t),n.filter(e))}return r(null,n.error,n.result)}r(null,n)};var Sn,_n={},An={exports:{}};(Sn=An).exports=function(t){return t&&t.__esModule?t:{default:t}},Sn.exports.__esModule=!0,Sn.exports.default=Sn.exports;var Mn,In,En,xn,Bn={exports:{}},Pn={exports:{}};function Rn(){return Mn||(Mn=1,function(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(Pn)),Pn.exports}function Tn(){return In||(In=1,function(t){var e=Rn().default;function r(){
5
5
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
6
6
  t.exports=r=function(){return n},t.exports.__esModule=!0,t.exports.default=t.exports;var n={},i=Object.prototype,o=i.hasOwnProperty,s=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",h=a.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function d(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,o=Object.create(i.prototype),a=new x(n||[]);return s(o,"_invoke",{value:A(t,r,a)}),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}n.wrap=d;var p={};function m(){}function g(){}function y(){}var w={};l(w,u,(function(){return this}));var b=Object.getPrototypeOf,v=b&&b(b(B([])));v&&v!==i&&o.call(v,u)&&(w=v);var k=y.prototype=m.prototype=Object.create(w);function S(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function _(t,r){function n(i,s,a,u){var c=f(t[i],t,s);if("throw"!==c.type){var h=c.arg,l=h.value;return l&&"object"==e(l)&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(l).then((function(t){h.value=t,a(h)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var i;s(this,"_invoke",{value:function(t,e){function o(){return new r((function(r,i){n(t,e,r,i)}))}return i=i?i.then(o,o):o()}})}function A(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=M(s,r);if(a){if(a===p)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function M(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,M(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=f(n,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,p;var o=i.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function I(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function B(t){if(t){var e=t[u];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r<t.length;)if(o.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return n.next=n}}return{next:P}}function P(){return{value:void 0,done:!0}}return g.prototype=y,s(k,"constructor",{value:y,configurable:!0}),s(y,"constructor",{value:g,configurable:!0}),g.displayName=l(y,h,"GeneratorFunction"),n.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},n.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,l(t,h,"GeneratorFunction")),t.prototype=Object.create(k),t},n.awrap=function(t){return{__await:t}},S(_.prototype),l(_.prototype,c,(function(){return this})),n.AsyncIterator=_,n.async=function(t,e,r,i,o){void 0===o&&(o=Promise);var s=new _(d(t,e,r,i),o);return n.isGeneratorFunction(e)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},S(k),l(k,h,"Generator"),l(k,u,(function(){return this})),l(k,"toString",(function(){return"[object Generator]"})),n.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},n.values=B,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return s.type="throw",s.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n],s=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var a=o.call(i,"catchLoc"),u=o.call(i,"finallyLoc");if(a&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:B(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},n}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}(Bn)),Bn.exports}var Ln,On={exports:{}};var Cn,Un={exports:{}};function Nn(){return Cn||(Cn=1,function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports}(Un)),Un.exports}var zn,Kn,Wn,qn={exports:{}},Dn={exports:{}},jn={exports:{}};function Hn(){return zn||(zn=1,function(t){var e=Rn().default;t.exports=function(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports}(jn)),jn.exports}function Fn(){return Kn||(Kn=1,function(t){var e=Rn().default,r=Hn();t.exports=function(t){var n=r(t,"string");return"symbol"===e(n)?n:String(n)},t.exports.__esModule=!0,t.exports.default=t.exports}(Dn)),Dn.exports}function $n(){return Wn||(Wn=1,function(t){var e=Fn();function r(t,r){for(var n=0;n<r.length;n++){var i=r[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,e(i.key),i)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports}(qn)),qn.exports}var Vn,Gn,Zn={exports:{}},Yn={exports:{}};function Jn(){return Vn||(Vn=1,function(t){function e(r,n){return t.exports=e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r,n)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(Yn)),Yn.exports}function Xn(){return Gn||(Gn=1,function(t){var e=Jn();t.exports=function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&e(t,r)},t.exports.__esModule=!0,t.exports.default=t.exports}(Zn)),Zn.exports}var Qn,ti,ei={exports:{}},ri={exports:{}};function ni(){return Qn||(Qn=1,function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.__esModule=!0,t.exports.default=t.exports}(ri)),ri.exports}function ii(){return ti||(ti=1,function(t){var e=Rn().default,r=ni();t.exports=function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return r(t)},t.exports.__esModule=!0,t.exports.default=t.exports}(ei)),ei.exports}var oi,si={exports:{}};function ai(){return oi||(oi=1,function(t){function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(si)),si.exports}var ui,ci={exports:{}};function hi(){return ui||(ui=1,function(t){var e=Object.prototype.hasOwnProperty,r="~";function n(){}function i(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function o(t,e,n,o,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new i(n,o||t,s),u=r?r+e:e;return t._events[u]?t._events[u].fn?t._events[u]=[t._events[u],a]:t._events[u].push(a):(t._events[u]=a,t._eventsCount++),t}function s(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,n,i=[];if(0===this._eventsCount)return i;for(n in t=this._events)e.call(t,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},a.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s},a.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,i,o,s){var a=r?r+t:t;if(!this._events[a])return!1;var u,c,h=this._events[a],l=arguments.length;if(h.fn){switch(h.once&&this.removeListener(t,h.fn,void 0,!0),l){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,e),!0;case 3:return h.fn.call(h.context,e,n),!0;case 4:return h.fn.call(h.context,e,n,i),!0;case 5:return h.fn.call(h.context,e,n,i,o),!0;case 6:return h.fn.call(h.context,e,n,i,o,s),!0}for(c=1,u=new Array(l-1);c<l;c++)u[c-1]=arguments[c];h.fn.apply(h.context,u)}else{var d,f=h.length;for(c=0;c<f;c++)switch(h[c].once&&this.removeListener(t,h[c].fn,void 0,!0),l){case 1:h[c].fn.call(h[c].context);break;case 2:h[c].fn.call(h[c].context,e);break;case 3:h[c].fn.call(h[c].context,e,n);break;case 4:h[c].fn.call(h[c].context,e,n,i);break;default:if(!u)for(d=1,u=new Array(l-1);d<l;d++)u[d-1]=arguments[d];h[c].fn.apply(h[c].context,u)}}return!0},a.prototype.on=function(t,e,r){return o(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return o(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,n,i){var o=r?r+t:t;if(!this._events[o])return this;if(!e)return s(this,o),this;var a=this._events[o];if(a.fn)a.fn!==e||i&&!a.once||n&&a.context!==n||s(this,o);else{for(var u=0,c=[],h=a.length;u<h;u++)(a[u].fn!==e||i&&!a[u].once||n&&a[u].context!==n)&&c.push(a[u]);c.length?this._events[o]=1===c.length?c[0]:c:s(this,o)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&s(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a}(ci)),ci.exports}!function(t){var e=An.exports;Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=e(function(){if(xn)return En;xn=1;var t=Tn()();En=t;try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}return En}()),n=e((Ln||(Ln=1,function(t){function e(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(i,o){var s=t.apply(r,n);function a(t){e(s,i,o,a,u,"next",t)}function u(t){e(s,i,o,a,u,"throw",t)}a(void 0)}))}},t.exports.__esModule=!0,t.exports.default=t.exports}(On)),On.exports)),i=e(Rn()),o=e(Nn()),s=e($n()),a=e(Xn()),u=e(ii()),c=e(ai()),h=hi();function l(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=(0,c.default)(t);if(e){var i=(0,c.default)(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return(0,u.default)(this,r)}}var d=function(t){(0,a.default)(f,t);var e,u,c,h,d=l(f);function f(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"ws://localhost:8080",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3?arguments[3]:void 0;(0,o.default)(this,f);var s=n.autoconnect,a=void 0===s||s,u=n.reconnect,c=void 0===u||u,h=n.reconnect_interval,l=void 0===h?1e3:h,p=n.max_reconnects,m=void 0===p?5:p,g=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(n,["autoconnect","reconnect","reconnect_interval","max_reconnects"]);return(e=d.call(this)).webSocketFactory=t,e.queue={},e.rpc_id=0,e.address=r,e.autoconnect=a,e.ready=!1,e.reconnect=c,e.reconnect_timer_id=void 0,e.reconnect_interval=l,e.max_reconnects=m,e.rest_options=g,e.current_reconnects=0,e.generate_request_id=i||function(){return++e.rpc_id},e.autoconnect&&e._connect(e.address,Object.assign({autoconnect:e.autoconnect,reconnect:e.reconnect,reconnect_interval:e.reconnect_interval,max_reconnects:e.max_reconnects},e.rest_options)),e}return(0,s.default)(f,[{key:"connect",value:function(){this.socket||this._connect(this.address,Object.assign({autoconnect:this.autoconnect,reconnect:this.reconnect,reconnect_interval:this.reconnect_interval,max_reconnects:this.max_reconnects},this.rest_options))}},{key:"call",value:function(t,e,r,n){var o=this;return n||"object"!==(0,i.default)(r)||(n=r,r=null),new Promise((function(i,s){if(!o.ready)return s(new Error("socket not ready"));var a=o.generate_request_id(t,e),u={jsonrpc:"2.0",method:t,params:e||null,id:a};o.socket.send(JSON.stringify(u),n,(function(t){if(t)return s(t);o.queue[a]={promise:[i,s]},r&&(o.queue[a].timeout=setTimeout((function(){delete o.queue[a],s(new Error("reply timeout"))}),r))}))}))}},{key:"login",value:(h=(0,n.default)(r.default.mark((function t(e){var n;return r.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.call("rpc.login",e);case 2:if(n=t.sent){t.next=5;break}throw new Error("authentication failed");case 5:return t.abrupt("return",n);case 6:case"end":return t.stop()}}),t,this)}))),function(t){return h.apply(this,arguments)})},{key:"listMethods",value:(c=(0,n.default)(r.default.mark((function t(){return r.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.call("__listMethods");case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)}))),function(){return c.apply(this,arguments)})},{key:"notify",value:function(t,e){var r=this;return new Promise((function(n,i){if(!r.ready)return i(new Error("socket not ready"));var o={jsonrpc:"2.0",method:t,params:e||null};r.socket.send(JSON.stringify(o),(function(t){if(t)return i(t);n()}))}))}},{key:"subscribe",value:(u=(0,n.default)(r.default.mark((function t(e){var n;return r.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return"string"==typeof e&&(e=[e]),t.next=3,this.call("rpc.on",e);case 3:if(n=t.sent,"string"!=typeof e||"ok"===n[e]){t.next=6;break}throw new Error("Failed subscribing to an event '"+e+"' with: "+n[e]);case 6:return t.abrupt("return",n);case 7:case"end":return t.stop()}}),t,this)}))),function(t){return u.apply(this,arguments)})},{key:"unsubscribe",value:(e=(0,n.default)(r.default.mark((function t(e){var n;return r.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return"string"==typeof e&&(e=[e]),t.next=3,this.call("rpc.off",e);case 3:if(n=t.sent,"string"!=typeof e||"ok"===n[e]){t.next=6;break}throw new Error("Failed unsubscribing from an event with: "+n);case 6:return t.abrupt("return",n);case 7:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})},{key:"close",value:function(t,e){this.socket.close(t||1e3,e)}},{key:"_connect",value:function(t,e){var r=this;clearTimeout(this.reconnect_timer_id),this.socket=this.webSocketFactory(t,e),this.socket.addEventListener("open",(function(){r.ready=!0,r.emit("open"),r.current_reconnects=0})),this.socket.addEventListener("message",(function(t){var e=t.data;e instanceof ArrayBuffer&&(e=Buffer.from(e).toString());try{e=JSON.parse(e)}catch(t){return}if(e.notification&&r.listeners(e.notification).length){if(!Object.keys(e.params).length)return r.emit(e.notification);var n=[e.notification];if(e.params.constructor===Object)n.push(e.params);else for(var i=0;i<e.params.length;i++)n.push(e.params[i]);return Promise.resolve().then((function(){r.emit.apply(r,n)}))}if(!r.queue[e.id])return e.method&&e.params?Promise.resolve().then((function(){r.emit(e.method,e.params)})):void 0;"error"in e=="result"in e&&r.queue[e.id].promise[1](new Error('Server response malformed. Response must include either "result" or "error", but not both.')),r.queue[e.id].timeout&&clearTimeout(r.queue[e.id].timeout),e.error?r.queue[e.id].promise[1](e.error):r.queue[e.id].promise[0](e.result),delete r.queue[e.id]})),this.socket.addEventListener("error",(function(t){return r.emit("error",t)})),this.socket.addEventListener("close",(function(n){var i=n.code,o=n.reason;r.ready&&setTimeout((function(){return r.emit("close",i,o)}),0),r.ready=!1,r.socket=void 0,1e3!==i&&(r.current_reconnects++,r.reconnect&&(r.max_reconnects>r.current_reconnects||0===r.max_reconnects)&&(r.reconnect_timer_id=setTimeout((function(){return r._connect(t,e)}),r.reconnect_interval)))}))}}]),f}(h.EventEmitter);t.default=d}(_n);var li=t.getDefaultExportFromCjs(_n),di={};!function(t){var e=An.exports;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(t,e){return new u(t,e)};var r=e(Nn()),n=e($n()),i=e(Xn()),o=e(ii()),s=e(ai());function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=(0,s.default)(t);if(e){var i=(0,s.default)(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return(0,o.default)(this,r)}}var u=function(t){(0,i.default)(o,t);var e=a(o);function o(t,n,i){var s;return(0,r.default)(this,o),(s=e.call(this)).socket=new window.WebSocket(t,i),s.socket.onopen=function(){return s.emit("open")},s.socket.onmessage=function(t){return s.emit("message",t.data)},s.socket.onerror=function(t){return s.emit("error",t)},s.socket.onclose=function(t){s.emit("close",t.code,t.reason)},s}return(0,n.default)(o,[{key:"send",value:function(t,e,r){var n=r||e;try{this.socket.send(t),n()}catch(t){n(t)}}},{key:"close",value:function(t,e){this.socket.close(t,e)}},{key:"addEventListener",value:function(t,e,r){this.socket.addEventListener(t,e,r)}}]),o}(hi().EventEmitter)}(di);var fi=t.getDefaultExportFromCjs(di);const[pi,mi,gi]=[[],[],[]],yi=BigInt(0),wi=BigInt(1),bi=BigInt(2),vi=BigInt(7),ki=BigInt(256),Si=BigInt(113);for(let t=0,e=wi,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],pi.push(2*(5*n+r)),mi.push((t+1)*(t+2)/2%64);let i=yi;for(let t=0;t<7;t++)e=(e<<wi^(e>>vi)*Si)%ki,e&bi&&(i^=wi<<(wi<<BigInt(t))-wi);gi.push(i)}const[_i,Ai]=b.split(gi,!0),Mi=(t,e,r)=>r>32?b.rotlBH(t,e,r):b.rotlSH(t,e,r),Ii=(t,e,r)=>r>32?b.rotlBL(t,e,r):b.rotlSL(t,e,r);class Ei extends f{constructor(t,e,r,n=!1,i=24){if(super(),this.blockLen=t,this.suffix=e,this.outputLen=r,this.enableXOF=n,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,c.number(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}keccak(){!function(t,e=24){const r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let e=0;e<10;e++)r[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const n=(e+8)%10,i=(e+2)%10,o=r[i],s=r[i+1],a=Mi(o,s,1)^r[n],u=Ii(o,s,1)^r[n+1];for(let r=0;r<50;r+=10)t[e+r]^=a,t[e+r+1]^=u}let e=t[2],i=t[3];for(let r=0;r<24;r++){const n=mi[r],o=Mi(e,i,n),s=Ii(e,i,n),a=pi[r];e=t[a],i=t[a+1],t[a]=o,t[a+1]=s}for(let e=0;e<50;e+=10){for(let n=0;n<10;n++)r[n]=t[e+n];for(let n=0;n<10;n++)t[e+n]^=~r[(n+2)%10]&r[(n+4)%10]}t[0]^=_i[n],t[1]^=Ai[n]}r.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){c.exists(this);const{blockLen:e,state:r}=this,n=(t=d(t)).length;for(let i=0;i<n;){const o=Math.min(e-this.pos,n-i);for(let e=0;e<o;e++)r[this.pos++]^=t[i++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:e,pos:r,blockLen:n}=this;t[r]^=e,0!=(128&e)&&r===n-1&&this.keccak(),t[n-1]^=128,this.keccak()}writeInto(t){c.exists(this,!1),c.bytes(t),this.finish();const e=this.state,{blockLen:r}=this;for(let n=0,i=t.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);t.set(e.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return c.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(c.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:e,suffix:r,outputLen:n,rounds:i,enableXOF:o}=this;return t||(t=new Ei(e,r,n,o,i)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=i,t.suffix=r,t.outputLen=n,t.enableXOF=o,t.destroyed=this.destroyed,t}}const xi=(t,e,r)=>p((()=>new Ei(e,t,r)));xi(6,144,28),xi(6,136,32),xi(6,104,48),xi(6,72,64),xi(1,144,28);const Bi=xi(1,136,32);xi(1,104,48),xi(1,72,64);const Pi=(t,e,r)=>function(t){const e=(e,r)=>t(r).update(d(e)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=e=>t(e),e}(((n={})=>new Ei(e,t,void 0===n.dkLen?r:n.dkLen,!0)));Pi(31,168,16),Pi(31,136,32);class Ri extends f{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,c.hash(t);const r=d(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?t.create().update(r).digest():r);for(let t=0;t<i.length;t++)i[t]^=54;this.iHash.update(i),this.oHash=t.create();for(let t=0;t<i.length;t++)i[t]^=106;this.oHash.update(i),i.fill(0)}update(t){return c.exists(this),this.iHash.update(t),this}digestInto(t){c.exists(this),c.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:r,finished:n,destroyed:i,blockLen:o,outputLen:s}=this;return t.finished=n,t.destroyed=i,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ti=(t,e,r)=>new Ri(t,e).update(r).digest();Ti.create=(t,e)=>new Ri(t,e)
7
7
  /*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */;const Li=BigInt(0),Oi=BigInt(1),Ci=BigInt(2),Ui=BigInt(3),Ni=BigInt(8),zi=Object.freeze({a:Li,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:Oi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),Ki=(t,e)=>(t+e/Ci)/e,Wi={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const{n:e}=zi,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Oi*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),a=Ki(o*t,e),u=Ki(-n*t,e);let c=mo(t-a*r-u*i,e),h=mo(-a*n-u*o,e);const l=c>s,d=h>s;if(l&&(c=e-c),d&&(h=e-h),c>s||h>s)throw new Error("splitScalarEndo: Endomorphism failed, k="+t);return{k1neg:l,k1:c,k2neg:d,k2:h}}},qi=32,Di=32,ji=qi+1,Hi=2*qi+1;function Fi(t){const{a:e,b:r}=zi,n=mo(t*t),i=mo(n*t);return mo(i+e*t+r)}const $i=zi.a===Li;class Vi extends Error{constructor(t){super(t)}}function Gi(t){if(!(t instanceof Zi))throw new TypeError("JacobianPoint expected")}class Zi{constructor(t,e,r){this.x=t,this.y=e,this.z=r}static fromAffine(t){if(!(t instanceof Xi))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(Xi.ZERO)?Zi.ZERO:new Zi(t.x,t.y,Oi)}static toAffineBatch(t){const e=function(t,e=zi.P){const r=new Array(t.length),n=t.reduce(((t,n,i)=>n===Li?t:(r[i]=t,mo(t*n,e))),Oi),i=yo(n,e);return t.reduceRight(((t,n,i)=>n===Li?t:(r[i]=mo(t*r[i],e),mo(t*n,e))),i),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return Zi.toAffineBatch(t).map(Zi.fromAffine)}equals(t){Gi(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:s}=t,a=mo(n*n),u=mo(s*s),c=mo(e*u),h=mo(i*a),l=mo(mo(r*s)*u),d=mo(mo(o*n)*a);return c===h&&l===d}negate(){return new Zi(this.x,mo(-this.y),this.z)}double(){const{x:t,y:e,z:r}=this,n=mo(t*t),i=mo(e*e),o=mo(i*i),s=t+i,a=mo(Ci*(mo(s*s)-n-o)),u=mo(Ui*n),c=mo(u*u),h=mo(c-Ci*a),l=mo(u*(a-h)-Ni*o),d=mo(Ci*e*r);return new Zi(h,l,d)}add(t){Gi(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:s}=t;if(i===Li||o===Li)return this;if(e===Li||r===Li)return t;const a=mo(n*n),u=mo(s*s),c=mo(e*u),h=mo(i*a),l=mo(mo(r*s)*u),d=mo(mo(o*n)*a),f=mo(h-c),p=mo(d-l);if(f===Li)return p===Li?this.double():Zi.ZERO;const m=mo(f*f),g=mo(f*m),y=mo(c*m),w=mo(p*p-g-Ci*y),b=mo(p*(y-w)-l*g),v=mo(n*s*f);return new Zi(w,b,v)}subtract(t){return this.add(t.negate())}multiplyUnsafe(t){const e=Zi.ZERO;if("bigint"==typeof t&&t===Li)return e;let r=po(t);if(r===Oi)return this;if(!$i){let t=e,n=this;for(;r>Li;)r&Oi&&(t=t.add(n)),n=n.double(),r>>=Oi;return t}let{k1neg:n,k1:i,k2neg:o,k2:s}=Wi.splitScalar(r),a=e,u=e,c=this;for(;i>Li||s>Li;)i&Oi&&(a=a.add(c)),s&Oi&&(u=u.add(c)),c=c.double(),i>>=Oi,s>>=Oi;return n&&(a=a.negate()),o&&(u=u.negate()),u=new Zi(mo(u.x*Wi.beta),u.y,u.z),a.add(u)}precomputeWindow(t){const e=$i?128/t+1:256/t+1,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(Zi.BASE)&&(e=Xi.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&Ji.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=Zi.normalizeZ(n),Ji.set(e,n)));let i=Zi.ZERO,o=Zi.BASE;const s=1+($i?128/r:256/r),a=2**(r-1),u=BigInt(2**r-1),c=2**r,h=BigInt(r);for(let e=0;e<s;e++){const r=e*a;let s=Number(t&u);t>>=h,s>a&&(s-=c,t+=Oi);const l=r,d=r+Math.abs(s)-1,f=e%2!=0,p=s<0;0===s?o=o.add(Yi(f,n[l])):i=i.add(Yi(p,n[d]))}return{p:i,f:o}}multiply(t,e){let r,n,i=po(t);if($i){const{k1neg:t,k1:o,k2neg:s,k2:a}=Wi.splitScalar(i);let{p:u,f:c}=this.wNAF(o,e),{p:h,f:l}=this.wNAF(a,e);u=Yi(t,u),h=Yi(s,h),h=new Zi(mo(h.x*Wi.beta),h.y,h.z),r=u.add(h),n=c.add(l)}else{const{p:t,f:o}=this.wNAF(i,e);r=t,n=o}return Zi.normalizeZ([r,n])[0]}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(Zi.ZERO);null==t&&(t=i?Ni:yo(n));const o=t,s=mo(o*o),a=mo(s*o),u=mo(e*s),c=mo(r*a),h=mo(n*o);if(i)return Xi.ZERO;if(h!==Oi)throw new Error("invZ was invalid");return new Xi(u,c)}}function Yi(t,e){const r=e.negate();return t?r:e}Zi.BASE=new Zi(zi.Gx,zi.Gy,Oi),Zi.ZERO=new Zi(Li,Oi,Li);const Ji=new WeakMap;class Xi{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,Ji.delete(this)}hasEvenY(){return this.y%Ci===Li}static fromCompressedHex(t){const e=32===t.length,r=lo(e?t:t.subarray(1));if(!_o(r))throw new Error("Point is not on curve");let n=function(t){const{P:e}=zi,r=BigInt(6),n=BigInt(11),i=BigInt(22),o=BigInt(23),s=BigInt(44),a=BigInt(88),u=t*t*t%e,c=u*u*t%e,h=go(c,Ui)*c%e,l=go(h,Ui)*c%e,d=go(l,Ci)*u%e,f=go(d,n)*d%e,p=go(f,i)*f%e,m=go(p,s)*p%e,g=go(m,a)*m%e,y=go(g,s)*p%e,w=go(y,Ui)*c%e,b=go(w,o)*f%e,v=go(b,r)*u%e,k=go(v,Ci);if(k*k%e!==t)throw new Error("Cannot find square root");return k}(Fi(r));const i=(n&Oi)===Oi;if(e)i&&(n=mo(-n));else{1==(1&t[0])!==i&&(n=mo(-n))}const o=new Xi(r,n);return o.assertValidity(),o}static fromUncompressedHex(t){const e=lo(t.subarray(1,qi+1)),r=lo(t.subarray(qi+1,2*qi+1)),n=new Xi(e,r);return n.assertValidity(),n}static fromHex(t){const e=fo(t),r=e.length,n=e[0];if(r===qi)return this.fromCompressedHex(e);if(r===ji&&(2===n||3===n))return this.fromCompressedHex(e);if(r===Hi&&4===n)return this.fromUncompressedHex(e);throw new Error(`Point.fromHex: received invalid point. Expected 32-${ji} compressed bytes or ${Hi} uncompressed bytes, not ${r}`)}static fromPrivateKey(t){return Xi.BASE.multiply(Mo(t))}static fromSignature(t,e,r){const{r:n,s:i}=function(t){if(t instanceof eo)return t.assertValidity(),t;try{return eo.fromDER(t)}catch(e){return eo.fromCompact(t)}}(e);if(![0,1,2,3].includes(r))throw new Error("Cannot recover: invalid recovery bit");const o=wo(fo(t)),{n:s}=zi,a=2===r||3===r?n+s:n,u=yo(a,s),c=mo(-o*u,s),h=mo(i*u,s),l=1&r?"03":"02",d=Xi.fromHex(l+so(a)),f=Xi.BASE.multiplyAndAddUnsafe(d,c,h);if(!f)throw new Error("Cannot recover signature: point at infinify");return f.assertValidity(),f}toRawBytes(t=!1){return ho(this.toHex(t))}toHex(t=!1){const e=so(this.x);if(t){return`${this.hasEvenY()?"02":"03"}${e}`}return`04${e}${so(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const t="Point is not on elliptic curve",{x:e,y:r}=this;if(!_o(e)||!_o(r))throw new Error(t);const n=mo(r*r);if(mo(n-Fi(e))!==Li)throw new Error(t)}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new Xi(this.x,mo(-this.y))}double(){return Zi.fromAffine(this).double().toAffine()}add(t){return Zi.fromAffine(this).add(Zi.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return Zi.fromAffine(this).multiply(t,this).toAffine()}multiplyAndAddUnsafe(t,e,r){const n=Zi.fromAffine(this),i=e===Li||e===Oi||this!==Xi.BASE?n.multiplyUnsafe(e):n.multiply(e),o=Zi.fromAffine(t).multiplyUnsafe(r),s=i.add(o);return s.equals(Zi.ZERO)?void 0:s.toAffine()}}function Qi(t){return Number.parseInt(t[0],16)>=8?"00"+t:t}function to(t){if(t.length<2||2!==t[0])throw new Error(`Invalid signature integer tag: ${io(t)}`);const e=t[1],r=t.subarray(2,e+2);if(!e||r.length!==e)throw new Error("Invalid signature integer: wrong length");if(0===r[0]&&r[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:lo(r),left:t.subarray(e+2)}}Xi.BASE=new Xi(zi.Gx,zi.Gy),Xi.ZERO=new Xi(Li,Li);class eo{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromCompact(t){const e=t instanceof Uint8Array,r="Signature.fromCompact";if("string"!=typeof t&&!e)throw new TypeError(`${r}: Expected string or Uint8Array`);const n=e?io(t):t;if(128!==n.length)throw new Error(`${r}: Expected 64-byte hex`);return new eo(co(n.slice(0,64)),co(n.slice(64,128)))}static fromDER(t){const e=t instanceof Uint8Array;if("string"!=typeof t&&!e)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:r,s:n}=function(t){if(t.length<2||48!=t[0])throw new Error(`Invalid signature tag: ${io(t)}`);if(t[1]!==t.length-2)throw new Error("Invalid signature: incorrect length");const{data:e,left:r}=to(t.subarray(2)),{data:n,left:i}=to(r);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${io(i)}`);return{r:e,s:n}}(e?t:ho(t));return new eo(r,n)}static fromHex(t){return this.fromDER(t)}assertValidity(){const{r:t,s:e}=this;if(!So(t))throw new Error("Invalid Signature: r must be 0 < r < n");if(!So(e))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const t=zi.n>>Oi;return this.s>t}normalizeS(){return this.hasHighS()?new eo(this.r,mo(-this.s,zi.n)):this}toDERRawBytes(){return ho(this.toDERHex())}toDERHex(){const t=Qi(uo(this.s)),e=Qi(uo(this.r)),r=t.length/2,n=e.length/2,i=uo(r),o=uo(n);return`30${uo(n+r+4)}02${o}${e}02${i}${t}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return ho(this.toCompactHex())}toCompactHex(){return so(this.r)+so(this.s)}}function ro(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const no=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function io(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");let e="";for(let r=0;r<t.length;r++)e+=no[t[r]];return e}const oo=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function so(t){if("bigint"!=typeof t)throw new Error("Expected bigint");if(!(Li<=t&&t<oo))throw new Error("Expected number 0 <= n < 2^256");return t.toString(16).padStart(64,"0")}function ao(t){const e=ho(so(t));if(32!==e.length)throw new Error("Error: expected 32 bytes");return e}function uo(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function co(t){if("string"!=typeof t)throw new TypeError("hexToNumber: expected string, got "+typeof t);return BigInt(`0x${t}`)}function ho(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex"+t.length);const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function lo(t){return co(io(t))}function fo(t){return t instanceof Uint8Array?Uint8Array.from(t):ho(t)}function po(t){if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)return BigInt(t);if("bigint"==typeof t&&So(t))return t;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function mo(t,e=zi.P){const r=t%e;return r>=Li?r:e+r}function go(t,e){const{P:r}=zi;let n=t;for(;e-- >Li;)n*=n,n%=r;return n}function yo(t,e=zi.P){if(t===Li||e<=Li)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=mo(t,e),n=e,i=Li,o=Oi;for(;r!==Li;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==Oi)throw new Error("invert: does not exist");return mo(i,e)}function wo(t,e=!1){const r=function(t){const e=8*t.length-8*Di,r=lo(t);return e>0?r>>BigInt(e):r}(t);if(e)return r;const{n:n}=zi;return r>=n?r-n:r}let bo,vo;class ko{constructor(t,e){if(this.hashLen=t,this.qByteLen=e,"number"!=typeof t||t<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");this.v=new Uint8Array(t).fill(1),this.k=new Uint8Array(t).fill(0),this.counter=0}hmac(...t){return To.hmacSha256(this.k,...t)}hmacSync(...t){return vo(this.k,...t)}checkSync(){if("function"!=typeof vo)throw new Vi("hmacSha256Sync needs to be set")}incr(){if(this.counter>=1e3)throw new Error("Tried 1,000 k values for sign(), all were invalid");this.counter+=1}async reseed(t=new Uint8Array){this.k=await this.hmac(this.v,Uint8Array.from([0]),t),this.v=await this.hmac(this.v),0!==t.length&&(this.k=await this.hmac(this.v,Uint8Array.from([1]),t),this.v=await this.hmac(this.v))}reseedSync(t=new Uint8Array){this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),t),this.v=this.hmacSync(this.v),0!==t.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),t),this.v=this.hmacSync(this.v))}async generate(){this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=await this.hmac(this.v);const r=this.v.slice();e.push(r),t+=this.v.length}return ro(...e)}generateSync(){this.checkSync(),this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=this.hmacSync(this.v);const r=this.v.slice();e.push(r),t+=this.v.length}return ro(...e)}}function So(t){return Li<t&&t<zi.n}function _o(t){return Li<t&&t<zi.P}function Ao(t,e,r,n=!0){const{n:i}=zi,o=wo(t,!0);if(!So(o))return;const s=yo(o,i),a=Xi.BASE.multiply(o),u=mo(a.x,i);if(u===Li)return;const c=mo(s*mo(e+r*u,i),i);if(c===Li)return;let h=new eo(u,c),l=(a.x===h.r?0:2)|Number(a.y&Oi);return n&&h.hasHighS()&&(h=h.normalizeS(),l^=1),{sig:h,recovery:l}}function Mo(t){let e;if("bigint"==typeof t)e=t;else if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)e=BigInt(t);else if("string"==typeof t){if(t.length!==2*Di)throw new Error("Expected 32 bytes of private key");e=co(t)}else{if(!(t instanceof Uint8Array))throw new TypeError("Expected valid private key");if(t.length!==Di)throw new Error("Expected 32 bytes of private key");e=lo(t)}if(!So(e))throw new Error("Expected private key: 0 < key < n");return e}function Io(t){return lo(t.length>qi?t.slice(0,qi):t)}function Eo(t){const e=Io(t),r=mo(e,zi.n);return xo(r<Li?e:r)}function xo(t){return ao(t)}function Bo(t,e,r={}){const{seed:n,m:i,d:o}=function(t,e,r){if(null==t)throw new Error(`sign: expected valid message hash, not "${t}"`);const n=fo(t),i=Mo(e),o=[xo(i),Eo(n)];if(null!=r){!0===r&&(r=To.randomBytes(qi));const t=fo(r);if(t.length!==qi)throw new Error(`sign: Expected ${qi} bytes of extra data`);o.push(t)}return{seed:ro(...o),m:Io(n),d:i}}(t,e,r.extraEntropy),s=new ko(32,Di);let a;for(s.reseedSync(n);!(a=Ao(s.generateSync(),i,o,r.canonical));)s.reseedSync();return function(t,e){const{sig:r,recovery:n}=t,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},e),s=i?r.toDERRawBytes():r.toCompactRawBytes();return o?[s,n]:s}(a,r)}Xi.BASE._setWindowSize(8);const Po={node:r.nodeCrypto,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},Ro={},To={bytesToHex:io,hexToBytes:ho,concatBytes:ro,mod:mo,invert:yo,isValidPrivateKey(t){try{return Mo(t),!0}catch(t){return!1}},_bigintTo32Bytes:ao,_normalizePrivateKey:Mo,hashToPrivateKey:t=>{t=fo(t);const e=Di+8;if(t.length<e||t.length>1024)throw new Error("Expected valid bytes of private key as per FIPS 186");return ao(mo(lo(t),zi.n-Oi)+Oi)},randomBytes:(t=32)=>{if(Po.web)return Po.web.getRandomValues(new Uint8Array(t));if(Po.node){const{randomBytes:e}=Po.node;return Uint8Array.from(e(t))}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>To.hashToPrivateKey(To.randomBytes(Di+8)),precompute(t=8,e=Xi.BASE){const r=e===Xi.BASE?e:new Xi(e.x,e.y);return r._setWindowSize(t),r.multiply(Ui),r},sha256:async(...t)=>{if(Po.web){const e=await Po.web.subtle.digest("SHA-256",ro(...t));return new Uint8Array(e)}if(Po.node){const{createHash:e}=Po.node,r=e("sha256");return t.forEach((t=>r.update(t))),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(t,...e)=>{if(Po.web){const r=await Po.web.subtle.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),n=ro(...e),i=await Po.web.subtle.sign("HMAC",r,n);return new Uint8Array(i)}if(Po.node){const{createHmac:r}=Po.node,n=r("sha256",t);return e.forEach((t=>n.update(t))),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(t,...e)=>{let r=Ro[t];if(void 0===r){const e=await To.sha256(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=ro(e,e),Ro[t]=r}return To.sha256(r,...e)},taggedHashSync:(t,...e)=>{if("function"!=typeof bo)throw new Vi("sha256Sync is undefined, you need to set it");let r=Ro[t];if(void 0===r){const e=bo(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=ro(e,e),Ro[t]=r}return bo(r,...e)},_JacobianPoint:Zi};Object.defineProperties(To,{sha256Sync:{configurable:!1,get:()=>bo,set(t){bo||(bo=t)}},hmacSha256Sync:{configurable:!1,get:()=>vo,set(t){vo||(vo=t)}}}),St.sha512Sync=(...t)=>x(St.concatBytes(...t));const Lo=St.randomPrivateKey,Oo=()=>{const t=St.randomPrivateKey(),e=Co(t),r=new Uint8Array(64);return r.set(t),r.set(e,32),{publicKey:e,secretKey:r}},Co=vt.getPublicKey;function Uo(t){try{return G.fromHex(t,!0),!0}catch{return!1}}const No=(t,e)=>vt.sign(t,e.slice(0,32)),zo=vt.verify,Ko=t=>e.Buffer.isBuffer(t)?t:t instanceof Uint8Array?e.Buffer.from(t.buffer,t.byteOffset,t.byteLength):e.Buffer.from(t);class Wo{constructor(t){Object.assign(this,t)}encode(){return e.Buffer.from(pe(qo,this))}static decode(t){return ye(qo,this,t)}static decodeUnchecked(t){return ee(qo,this,t)}}const qo=new Map;let Do;const jo=32;let Ho=1;Do=Symbol.toStringTag;class Fo extends Wo{constructor(t){if(super({}),this._bn=void 0,function(t){return void 0!==t._bn}(t))this._bn=t._bn;else{if("string"==typeof t){const e=Et.decode(t);if(e.length!=jo)throw new Error("Invalid public key input");this._bn=new At(e)}else this._bn=new At(t);if(this._bn.byteLength()>jo)throw new Error("Invalid public key input")}}static unique(){const t=new Fo(Ho);return Ho+=1,new Fo(t.toBuffer())}equals(t){return this._bn.eq(t._bn)}toBase58(){return Et.encode(this.toBytes())}toJSON(){return this.toBase58()}toBytes(){const t=this.toBuffer();return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}toBuffer(){const t=this._bn.toArrayLike(e.Buffer);if(t.length===jo)return t;const r=e.Buffer.alloc(32);return t.copy(r,32-t.length),r}get[Do](){return`PublicKey(${this.toString()})`}toString(){return this.toBase58()}static async createWithSeed(t,r,n){const i=e.Buffer.concat([t.toBuffer(),e.Buffer.from(r),n.toBuffer()]),o=Ot(i);return new Fo(o)}static createProgramAddressSync(t,r){let n=e.Buffer.alloc(0);t.forEach((function(t){if(t.length>32)throw new TypeError("Max seed length exceeded");n=e.Buffer.concat([n,Ko(t)])})),n=e.Buffer.concat([n,r.toBuffer(),e.Buffer.from("ProgramDerivedAddress")]);const i=Ot(n);if(Uo(i))throw new Error("Invalid seeds, address must fall off the curve");return new Fo(i)}static async createProgramAddress(t,e){return this.createProgramAddressSync(t,e)}static findProgramAddressSync(t,r){let n,i=255;for(;0!=i;){try{const o=t.concat(e.Buffer.from([i]));n=this.createProgramAddressSync(o,r)}catch(t){if(t instanceof TypeError)throw t;i--;continue}return[n,i]}throw new Error("Unable to find a viable program address nonce")}static async findProgramAddress(t,e){return this.findProgramAddressSync(t,e)}static isOnCurve(t){return Uo(new Fo(t).toBytes())}}Fo.default=new Fo("11111111111111111111111111111111"),qo.set(Fo,{kind:"struct",fields:[["_bn","u256"]]});const $o=new Fo("BPFLoader1111111111111111111111111111111111"),Vo=1232,Go=127,Zo=64;class Yo extends Error{constructor(t){super(`Signature ${t} has expired: block height exceeded.`),this.signature=void 0,this.signature=t}}Object.defineProperty(Yo.prototype,"name",{value:"TransactionExpiredBlockheightExceededError"});class Jo extends Error{constructor(t,e){super(`Transaction was not confirmed in ${e.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${t} using the Solana Explorer or CLI tools.`),this.signature=void 0,this.signature=t}}Object.defineProperty(Jo.prototype,"name",{value:"TransactionExpiredTimeoutError"});class Xo extends Error{constructor(t){super(`Signature ${t} has expired: the nonce is no longer valid.`),this.signature=void 0,this.signature=t}}Object.defineProperty(Xo.prototype,"name",{value:"TransactionExpiredNonceInvalidError"});class Qo{constructor(t,e){this.staticAccountKeys=void 0,this.accountKeysFromLookups=void 0,this.staticAccountKeys=t,this.accountKeysFromLookups=e}keySegments(){const t=[this.staticAccountKeys];return this.accountKeysFromLookups&&(t.push(this.accountKeysFromLookups.writable),t.push(this.accountKeysFromLookups.readonly)),t}get(t){for(const e of this.keySegments()){if(t<e.length)return e[t];t-=e.length}}get length(){return this.keySegments().flat().length}compileInstructions(t){if(this.length>256)throw new Error("Account index overflow encountered during compilation");const e=new Map;this.keySegments().flat().forEach(((t,r)=>{e.set(t.toBase58(),r)}));const r=t=>{const r=e.get(t.toBase58());if(void 0===r)throw new Error("Encountered an unknown instruction account key during compilation");return r};return t.map((t=>({programIdIndex:r(t.programId),accountKeyIndexes:t.keys.map((t=>r(t.pubkey))),data:t.data})))}}const ts=(t="publicKey")=>hr(32,t),es=(t="signature")=>hr(64,t),rs=(t="string")=>{const r=ur([or("length"),or("lengthPadding"),hr(rr(or(),-8),"chars")],t),n=r.decode.bind(r),i=r.encode.bind(r),o=r;return o.decode=(t,e)=>n(t,e).chars.toString(),o.encode=(t,r,n)=>{const o={chars:e.Buffer.from(t,"utf8")};return i(o,r,n)},o.alloc=t=>or().span+or().span+e.Buffer.from(t,"utf8").length,o};function ns(t,e){const r=t=>{if(t.span>=0)return t.span;if("function"==typeof t.alloc)return t.alloc(e[t.property]);if("count"in t&&"elementLayout"in t){const n=e[t.property];if(Array.isArray(n))return n.length*r(t.elementLayout)}else if("fields"in t)return ns({layout:t},e[t.property]);return 0};let n=0;return t.layout.fields.forEach((t=>{n+=r(t)})),n}function is(t){let e=0,r=0;for(;;){let n=t.shift();if(e|=(127&n)<<7*r,r+=1,0==(128&n))break}return e}function os(t,e){let r=e;for(;;){let e=127&r;if(r>>=7,0==r){t.push(e);break}e|=128,t.push(e)}}function ss(t,e){if(!t)throw new Error(e||"Assertion failed")}class as{constructor(t,e){this.payer=void 0,this.keyMetaMap=void 0,this.payer=t,this.keyMetaMap=e}static compile(t,e){const r=new Map,n=t=>{const e=t.toBase58();let n=r.get(e);return void 0===n&&(n={isSigner:!1,isWritable:!1,isInvoked:!1},r.set(e,n)),n},i=n(e);i.isSigner=!0,i.isWritable=!0;for(const e of t){n(e.programId).isInvoked=!0;for(const t of e.keys){const e=n(t.pubkey);e.isSigner||(e.isSigner=t.isSigner),e.isWritable||(e.isWritable=t.isWritable)}}return new as(e,r)}getMessageComponents(){const t=[...this.keyMetaMap.entries()];ss(t.length<=256,"Max static account keys length exceeded");const e=t.filter((([,t])=>t.isSigner&&t.isWritable)),r=t.filter((([,t])=>t.isSigner&&!t.isWritable)),n=t.filter((([,t])=>!t.isSigner&&t.isWritable)),i=t.filter((([,t])=>!t.isSigner&&!t.isWritable)),o={numRequiredSignatures:e.length+r.length,numReadonlySignedAccounts:r.length,numReadonlyUnsignedAccounts:i.length};{ss(e.length>0,"Expected at least one writable signer key");const[t]=e[0];ss(t===this.payer.toBase58(),"Expected first writable signer key to be the fee payer")}return[o,[...e.map((([t])=>new Fo(t))),...r.map((([t])=>new Fo(t))),...n.map((([t])=>new Fo(t))),...i.map((([t])=>new Fo(t)))]]}extractTableLookup(t){const[e,r]=this.drainKeysFoundInLookupTable(t.state.addresses,(t=>!t.isSigner&&!t.isInvoked&&t.isWritable)),[n,i]=this.drainKeysFoundInLookupTable(t.state.addresses,(t=>!t.isSigner&&!t.isInvoked&&!t.isWritable));if(0!==e.length||0!==n.length)return[{accountKey:t.key,writableIndexes:e,readonlyIndexes:n},{writable:r,readonly:i}]}drainKeysFoundInLookupTable(t,e){const r=new Array,n=new Array;for(const[i,o]of this.keyMetaMap.entries())if(e(o)){const e=new Fo(i),o=t.findIndex((t=>t.equals(e)));o>=0&&(ss(o<256,"Max lookup table index exceeded"),r.push(o),n.push(e),this.keyMetaMap.delete(i))}return[r,n]}}class us{constructor(t){this.header=void 0,this.accountKeys=void 0,this.recentBlockhash=void 0,this.instructions=void 0,this.indexToProgramIds=new Map,this.header=t.header,this.accountKeys=t.accountKeys.map((t=>new Fo(t))),this.recentBlockhash=t.recentBlockhash,this.instructions=t.instructions,this.instructions.forEach((t=>this.indexToProgramIds.set(t.programIdIndex,this.accountKeys[t.programIdIndex])))}get version(){return"legacy"}get staticAccountKeys(){return this.accountKeys}get compiledInstructions(){return this.instructions.map((t=>({programIdIndex:t.programIdIndex,accountKeyIndexes:t.accounts,data:Et.decode(t.data)})))}get addressTableLookups(){return[]}getAccountKeys(){return new Qo(this.staticAccountKeys)}static compile(t){const e=as.compile(t.instructions,t.payerKey),[r,n]=e.getMessageComponents(),i=new Qo(n).compileInstructions(t.instructions).map((t=>({programIdIndex:t.programIdIndex,accounts:t.accountKeyIndexes,data:Et.encode(t.data)})));return new us({header:r,accountKeys:n,recentBlockhash:t.recentBlockhash,instructions:i})}isAccountSigner(t){return t<this.header.numRequiredSignatures}isAccountWritable(t){const e=this.header.numRequiredSignatures;if(t>=this.header.numRequiredSignatures){return t-e<this.accountKeys.length-e-this.header.numReadonlyUnsignedAccounts}return t<e-this.header.numReadonlySignedAccounts}isProgramId(t){return this.indexToProgramIds.has(t)}programIds(){return[...this.indexToProgramIds.values()]}nonProgramIds(){return this.accountKeys.filter(((t,e)=>!this.isProgramId(e)))}serialize(){const t=this.accountKeys.length;let r=[];os(r,t);const n=this.instructions.map((t=>{const{accounts:r,programIdIndex:n}=t,i=Array.from(Et.decode(t.data));let o=[];os(o,r.length);let s=[];return os(s,i.length),{programIdIndex:n,keyIndicesCount:e.Buffer.from(o),keyIndices:r,dataLength:e.Buffer.from(s),data:i}}));let i=[];os(i,n.length);let o=e.Buffer.alloc(Vo);e.Buffer.from(i).copy(o);let s=i.length;n.forEach((t=>{const e=ur([nr("programIdIndex"),hr(t.keyIndicesCount.length,"keyIndicesCount"),cr(nr("keyIndex"),t.keyIndices.length,"keyIndices"),hr(t.dataLength.length,"dataLength"),cr(nr("userdatum"),t.data.length,"data")]).encode(t,o,s);s+=e})),o=o.slice(0,s);const a=ur([hr(1,"numRequiredSignatures"),hr(1,"numReadonlySignedAccounts"),hr(1,"numReadonlyUnsignedAccounts"),hr(r.length,"keyCount"),cr(ts("key"),t,"keys"),ts("recentBlockhash")]),u={numRequiredSignatures:e.Buffer.from([this.header.numRequiredSignatures]),numReadonlySignedAccounts:e.Buffer.from([this.header.numReadonlySignedAccounts]),numReadonlyUnsignedAccounts:e.Buffer.from([this.header.numReadonlyUnsignedAccounts]),keyCount:e.Buffer.from(r),keys:this.accountKeys.map((t=>Ko(t.toBytes()))),recentBlockhash:Et.decode(this.recentBlockhash)};let c=e.Buffer.alloc(2048);const h=a.encode(u,c);return o.copy(c,h),c.slice(0,h+o.length)}static from(t){let r=[...t];const n=r.shift();if(n!==(n&Go))throw new Error("Versioned messages must be deserialized with VersionedMessage.deserialize()");const i=r.shift(),o=r.shift(),s=is(r);let a=[];for(let t=0;t<s;t++){const t=r.slice(0,jo);r=r.slice(jo),a.push(new Fo(e.Buffer.from(t)))}const u=r.slice(0,jo);r=r.slice(jo);const c=is(r);let h=[];for(let t=0;t<c;t++){const t=r.shift(),n=is(r),i=r.slice(0,n);r=r.slice(n);const o=is(r),s=r.slice(0,o),a=Et.encode(e.Buffer.from(s));r=r.slice(o),h.push({programIdIndex:t,accounts:i,data:a})}const l={header:{numRequiredSignatures:n,numReadonlySignedAccounts:i,numReadonlyUnsignedAccounts:o},recentBlockhash:Et.encode(e.Buffer.from(u)),accountKeys:a,instructions:h};return new us(l)}}class cs{constructor(t){this.header=void 0,this.staticAccountKeys=void 0,this.recentBlockhash=void 0,this.compiledInstructions=void 0,this.addressTableLookups=void 0,this.header=t.header,this.staticAccountKeys=t.staticAccountKeys,this.recentBlockhash=t.recentBlockhash,this.compiledInstructions=t.compiledInstructions,this.addressTableLookups=t.addressTableLookups}get version(){return 0}get numAccountKeysFromLookups(){let t=0;for(const e of this.addressTableLookups)t+=e.readonlyIndexes.length+e.writableIndexes.length;return t}getAccountKeys(t){let e;if(t&&"accountKeysFromLookups"in t&&t.accountKeysFromLookups){if(this.numAccountKeysFromLookups!=t.accountKeysFromLookups.writable.length+t.accountKeysFromLookups.readonly.length)throw new Error("Failed to get account keys because of a mismatch in the number of account keys from lookups");e=t.accountKeysFromLookups}else if(t&&"addressLookupTableAccounts"in t&&t.addressLookupTableAccounts)e=this.resolveAddressTableLookups(t.addressLookupTableAccounts);else if(this.addressTableLookups.length>0)throw new Error("Failed to get account keys because address table lookups were not resolved");return new Qo(this.staticAccountKeys,e)}isAccountSigner(t){return t<this.header.numRequiredSignatures}isAccountWritable(t){const e=this.header.numRequiredSignatures,r=this.staticAccountKeys.length;if(t>=r){return t-r<this.addressTableLookups.reduce(((t,e)=>t+e.writableIndexes.length),0)}if(t>=this.header.numRequiredSignatures){return t-e<r-e-this.header.numReadonlyUnsignedAccounts}return t<e-this.header.numReadonlySignedAccounts}resolveAddressTableLookups(t){const e={writable:[],readonly:[]};for(const r of this.addressTableLookups){const n=t.find((t=>t.key.equals(r.accountKey)));if(!n)throw new Error(`Failed to find address lookup table account for table key ${r.accountKey.toBase58()}`);for(const t of r.writableIndexes){if(!(t<n.state.addresses.length))throw new Error(`Failed to find address for index ${t} in address lookup table ${r.accountKey.toBase58()}`);e.writable.push(n.state.addresses[t])}for(const t of r.readonlyIndexes){if(!(t<n.state.addresses.length))throw new Error(`Failed to find address for index ${t} in address lookup table ${r.accountKey.toBase58()}`);e.readonly.push(n.state.addresses[t])}}return e}static compile(t){const e=as.compile(t.instructions,t.payerKey),r=new Array,n={writable:new Array,readonly:new Array},i=t.addressLookupTableAccounts||[];for(const t of i){const i=e.extractTableLookup(t);if(void 0!==i){const[t,{writable:e,readonly:o}]=i;r.push(t),n.writable.push(...e),n.readonly.push(...o)}}const[o,s]=e.getMessageComponents(),a=new Qo(s,n).compileInstructions(t.instructions);return new cs({header:o,staticAccountKeys:s,recentBlockhash:t.recentBlockhash,compiledInstructions:a,addressTableLookups:r})}serialize(){const t=Array();os(t,this.staticAccountKeys.length);const e=this.serializeInstructions(),r=Array();os(r,this.compiledInstructions.length);const n=this.serializeAddressTableLookups(),i=Array();os(i,this.addressTableLookups.length);const o=ur([nr("prefix"),ur([nr("numRequiredSignatures"),nr("numReadonlySignedAccounts"),nr("numReadonlyUnsignedAccounts")],"header"),hr(t.length,"staticAccountKeysLength"),cr(ts(),this.staticAccountKeys.length,"staticAccountKeys"),ts("recentBlockhash"),hr(r.length,"instructionsLength"),hr(e.length,"serializedInstructions"),hr(i.length,"addressTableLookupsLength"),hr(n.length,"serializedAddressTableLookups")]),s=new Uint8Array(Vo),a=o.encode({prefix:128,header:this.header,staticAccountKeysLength:new Uint8Array(t),staticAccountKeys:this.staticAccountKeys.map((t=>t.toBytes())),recentBlockhash:Et.decode(this.recentBlockhash),instructionsLength:new Uint8Array(r),serializedInstructions:e,addressTableLookupsLength:new Uint8Array(i),serializedAddressTableLookups:n},s);return s.slice(0,a)}serializeInstructions(){let t=0;const e=new Uint8Array(Vo);for(const r of this.compiledInstructions){const n=Array();os(n,r.accountKeyIndexes.length);const i=Array();os(i,r.data.length);t+=ur([nr("programIdIndex"),hr(n.length,"encodedAccountKeyIndexesLength"),cr(nr(),r.accountKeyIndexes.length,"accountKeyIndexes"),hr(i.length,"encodedDataLength"),hr(r.data.length,"data")]).encode({programIdIndex:r.programIdIndex,encodedAccountKeyIndexesLength:new Uint8Array(n),accountKeyIndexes:r.accountKeyIndexes,encodedDataLength:new Uint8Array(i),data:r.data},e,t)}return e.slice(0,t)}serializeAddressTableLookups(){let t=0;const e=new Uint8Array(Vo);for(const r of this.addressTableLookups){const n=Array();os(n,r.writableIndexes.length);const i=Array();os(i,r.readonlyIndexes.length);t+=ur([ts("accountKey"),hr(n.length,"encodedWritableIndexesLength"),cr(nr(),r.writableIndexes.length,"writableIndexes"),hr(i.length,"encodedReadonlyIndexesLength"),cr(nr(),r.readonlyIndexes.length,"readonlyIndexes")]).encode({accountKey:r.accountKey.toBytes(),encodedWritableIndexesLength:new Uint8Array(n),writableIndexes:r.writableIndexes,encodedReadonlyIndexesLength:new Uint8Array(i),readonlyIndexes:r.readonlyIndexes},e,t)}return e.slice(0,t)}static deserialize(t){let e=[...t];const r=e.shift(),n=r&Go;ss(r!==n,"Expected versioned message but received legacy message");ss(0===n,`Expected versioned message with version 0 but found version ${n}`);const i={numRequiredSignatures:e.shift(),numReadonlySignedAccounts:e.shift(),numReadonlyUnsignedAccounts:e.shift()},o=[],s=is(e);for(let t=0;t<s;t++)o.push(new Fo(e.splice(0,jo)));const a=Et.encode(e.splice(0,jo)),u=is(e),c=[];for(let t=0;t<u;t++){const t=e.shift(),r=is(e),n=e.splice(0,r),i=is(e),o=new Uint8Array(e.splice(0,i));c.push({programIdIndex:t,accountKeyIndexes:n,data:o})}const h=is(e),l=[];for(let t=0;t<h;t++){const t=new Fo(e.splice(0,jo)),r=is(e),n=e.splice(0,r),i=is(e),o=e.splice(0,i);l.push({accountKey:t,writableIndexes:n,readonlyIndexes:o})}return new cs({header:i,staticAccountKeys:o,recentBlockhash:a,compiledInstructions:c,addressTableLookups:l})}}const hs={deserializeMessageVersion(t){const e=t[0],r=e&Go;return r===e?"legacy":r},deserialize:t=>{const e=hs.deserializeMessageVersion(t);if("legacy"===e)return us.from(t);if(0===e)return cs.deserialize(t);throw new Error(`Transaction message version ${e} deserialization is not supported`)}};let ls;!function(t){t[t.BLOCKHEIGHT_EXCEEDED=0]="BLOCKHEIGHT_EXCEEDED",t[t.PROCESSED=1]="PROCESSED",t[t.TIMED_OUT=2]="TIMED_OUT",t[t.NONCE_INVALID=3]="NONCE_INVALID"}(ls||(ls={}));const ds=e.Buffer.alloc(Zo).fill(0);class fs{constructor(t){this.keys=void 0,this.programId=void 0,this.data=e.Buffer.alloc(0),this.programId=t.programId,this.keys=t.keys,t.data&&(this.data=t.data)}toJSON(){return{keys:this.keys.map((({pubkey:t,isSigner:e,isWritable:r})=>({pubkey:t.toJSON(),isSigner:e,isWritable:r}))),programId:this.programId.toJSON(),data:[...this.data]}}}class ps{get signature(){return this.signatures.length>0?this.signatures[0].signature:null}constructor(t){if(this.signatures=[],this.feePayer=void 0,this.instructions=[],this.recentBlockhash=void 0,this.lastValidBlockHeight=void 0,this.nonceInfo=void 0,this.minNonceContextSlot=void 0,this._message=void 0,this._json=void 0,t)if(t.feePayer&&(this.feePayer=t.feePayer),t.signatures&&(this.signatures=t.signatures),Object.prototype.hasOwnProperty.call(t,"nonceInfo")){const{minContextSlot:e,nonceInfo:r}=t;this.minNonceContextSlot=e,this.nonceInfo=r}else if(Object.prototype.hasOwnProperty.call(t,"lastValidBlockHeight")){const{blockhash:e,lastValidBlockHeight:r}=t;this.recentBlockhash=e,this.lastValidBlockHeight=r}else{const{recentBlockhash:e,nonceInfo:r}=t;r&&(this.nonceInfo=r),this.recentBlockhash=e}}toJSON(){return{recentBlockhash:this.recentBlockhash||null,feePayer:this.feePayer?this.feePayer.toJSON():null,nonceInfo:this.nonceInfo?{nonce:this.nonceInfo.nonce,nonceInstruction:this.nonceInfo.nonceInstruction.toJSON()}:null,instructions:this.instructions.map((t=>t.toJSON())),signers:this.signatures.map((({publicKey:t})=>t.toJSON()))}}add(...t){if(0===t.length)throw new Error("No instructions");return t.forEach((t=>{"instructions"in t?this.instructions=this.instructions.concat(t.instructions):"data"in t&&"programId"in t&&"keys"in t?this.instructions.push(t):this.instructions.push(new fs(t))})),this}compileMessage(){if(this._message&&JSON.stringify(this.toJSON())===JSON.stringify(this._json))return this._message;let t,e,r;if(this.nonceInfo?(t=this.nonceInfo.nonce,e=this.instructions[0]!=this.nonceInfo.nonceInstruction?[this.nonceInfo.nonceInstruction,...this.instructions]:this.instructions):(t=this.recentBlockhash,e=this.instructions),!t)throw new Error("Transaction recentBlockhash required");if(e.length<1&&console.warn("No instructions provided"),this.feePayer)r=this.feePayer;else{if(!(this.signatures.length>0&&this.signatures[0].publicKey))throw new Error("Transaction fee payer required");r=this.signatures[0].publicKey}for(let t=0;t<e.length;t++)if(void 0===e[t].programId)throw new Error(`Transaction instruction index ${t} has undefined program id`);const n=[],i=[];e.forEach((t=>{t.keys.forEach((t=>{i.push({...t})}));const e=t.programId.toString();n.includes(e)||n.push(e)})),n.forEach((t=>{i.push({pubkey:new Fo(t),isSigner:!1,isWritable:!1})}));const o=[];i.forEach((t=>{const e=t.pubkey.toString(),r=o.findIndex((t=>t.pubkey.toString()===e));r>-1?(o[r].isWritable=o[r].isWritable||t.isWritable,o[r].isSigner=o[r].isSigner||t.isSigner):o.push(t)})),o.sort((function(t,e){return t.isSigner!==e.isSigner?t.isSigner?-1:1:t.isWritable!==e.isWritable?t.isWritable?-1:1:t.pubkey.toBase58().localeCompare(e.pubkey.toBase58())}));const s=o.findIndex((t=>t.pubkey.equals(r)));if(s>-1){const[t]=o.splice(s,1);t.isSigner=!0,t.isWritable=!0,o.unshift(t)}else o.unshift({pubkey:r,isSigner:!0,isWritable:!0});for(const t of this.signatures){const e=o.findIndex((e=>e.pubkey.equals(t.publicKey)));if(!(e>-1))throw new Error(`unknown signer: ${t.publicKey.toString()}`);o[e].isSigner||(o[e].isSigner=!0,console.warn("Transaction references a signature that is unnecessary, only the fee payer and instruction signer accounts should sign a transaction. This behavior is deprecated and will throw an error in the next major version release."))}let a=0,u=0,c=0;const h=[],l=[];o.forEach((({pubkey:t,isSigner:e,isWritable:r})=>{e?(h.push(t.toString()),a+=1,r||(u+=1)):(l.push(t.toString()),r||(c+=1))}));const d=h.concat(l),f=e.map((t=>{const{data:e,programId:r}=t;return{programIdIndex:d.indexOf(r.toString()),accounts:t.keys.map((t=>d.indexOf(t.pubkey.toString()))),data:Et.encode(e)}}));return f.forEach((t=>{ss(t.programIdIndex>=0),t.accounts.forEach((t=>ss(t>=0)))})),new us({header:{numRequiredSignatures:a,numReadonlySignedAccounts:u,numReadonlyUnsignedAccounts:c},accountKeys:d,recentBlockhash:t,instructions:f})}_compile(){const t=this.compileMessage(),e=t.accountKeys.slice(0,t.header.numRequiredSignatures);if(this.signatures.length===e.length){const r=this.signatures.every(((t,r)=>e[r].equals(t.publicKey)));if(r)return t}return this.signatures=e.map((t=>({signature:null,publicKey:t}))),t}serializeMessage(){return this._compile().serialize()}async getEstimatedFee(t){return(await t.getFeeForMessage(this.compileMessage())).value}setSigners(...t){if(0===t.length)throw new Error("No signers");const e=new Set;this.signatures=t.filter((t=>{const r=t.toString();return!e.has(r)&&(e.add(r),!0)})).map((t=>({signature:null,publicKey:t})))}sign(...t){if(0===t.length)throw new Error("No signers");const e=new Set,r=[];for(const n of t){const t=n.publicKey.toString();e.has(t)||(e.add(t),r.push(n))}this.signatures=r.map((t=>({signature:null,publicKey:t.publicKey})));const n=this._compile();this._partialSign(n,...r)}partialSign(...t){if(0===t.length)throw new Error("No signers");const e=new Set,r=[];for(const n of t){const t=n.publicKey.toString();e.has(t)||(e.add(t),r.push(n))}const n=this._compile();this._partialSign(n,...r)}_partialSign(t,...e){const r=t.serialize();e.forEach((t=>{const e=No(r,t.secretKey);this._addSignature(t.publicKey,Ko(e))}))}addSignature(t,e){this._compile(),this._addSignature(t,e)}_addSignature(t,r){ss(64===r.length);const n=this.signatures.findIndex((e=>t.equals(e.publicKey)));if(n<0)throw new Error(`unknown signer: ${t.toString()}`);this.signatures[n].signature=e.Buffer.from(r)}verifySignatures(t){return this._verifySignatures(this.serializeMessage(),void 0===t||t)}_verifySignatures(t,e){for(const{signature:r,publicKey:n}of this.signatures)if(null===r){if(e)return!1}else if(!zo(r,t,n.toBytes()))return!1;return!0}serialize(t){const{requireAllSignatures:e,verifySignatures:r}=Object.assign({requireAllSignatures:!0,verifySignatures:!0},t),n=this.serializeMessage();if(r&&!this._verifySignatures(n,e))throw new Error("Signature verification failed");return this._serialize(n)}_serialize(t){const{signatures:r}=this,n=[];os(n,r.length);const i=n.length+64*r.length+t.length,o=e.Buffer.alloc(i);return ss(r.length<256),e.Buffer.from(n).copy(o,0),r.forEach((({signature:t},r)=>{null!==t&&(ss(64===t.length,"signature has invalid length"),e.Buffer.from(t).copy(o,n.length+64*r))})),t.copy(o,n.length+64*r.length),ss(o.length<=Vo,`Transaction too large: ${o.length} > 1232`),o}get keys(){return ss(1===this.instructions.length),this.instructions[0].keys.map((t=>t.pubkey))}get programId(){return ss(1===this.instructions.length),this.instructions[0].programId}get data(){return ss(1===this.instructions.length),this.instructions[0].data}static from(t){let r=[...t];const n=is(r);let i=[];for(let t=0;t<n;t++){const t=r.slice(0,Zo);r=r.slice(Zo),i.push(Et.encode(e.Buffer.from(t)))}return ps.populate(us.from(r),i)}static populate(t,e=[]){const r=new ps;return r.recentBlockhash=t.recentBlockhash,t.header.numRequiredSignatures>0&&(r.feePayer=t.accountKeys[0]),e.forEach(((e,n)=>{const i={signature:e==Et.encode(ds)?null:Et.decode(e),publicKey:t.accountKeys[n]};r.signatures.push(i)})),t.instructions.forEach((e=>{const n=e.accounts.map((e=>{const n=t.accountKeys[e];return{pubkey:n,isSigner:r.signatures.some((t=>t.publicKey.toString()===n.toString()))||t.isAccountSigner(e),isWritable:t.isAccountWritable(e)}}));r.instructions.push(new fs({keys:n,programId:t.accountKeys[e.programIdIndex],data:Et.decode(e.data)}))})),r._message=t,r._json=r.toJSON(),r}}class ms{constructor(t){this.payerKey=void 0,this.instructions=void 0,this.recentBlockhash=void 0,this.payerKey=t.payerKey,this.instructions=t.instructions,this.recentBlockhash=t.recentBlockhash}static decompile(t,e){const{header:r,compiledInstructions:n,recentBlockhash:i}=t,{numRequiredSignatures:o,numReadonlySignedAccounts:s,numReadonlyUnsignedAccounts:a}=r,u=o-s;ss(u>0,"Message header is invalid");const c=t.staticAccountKeys.length-o-a;ss(c>=0,"Message header is invalid");const h=t.getAccountKeys(e),l=h.get(0);if(void 0===l)throw new Error("Failed to decompile message because no account keys were found");const d=[];for(const t of n){const e=[];for(const n of t.accountKeyIndexes){const t=h.get(n);if(void 0===t)throw new Error(`Failed to find key for account key index ${n}`);let i;i=n<o?n<u:n<h.staticAccountKeys.length?n-o<c:n-h.staticAccountKeys.length<h.accountKeysFromLookups.writable.length,e.push({pubkey:t,isSigner:n<r.numRequiredSignatures,isWritable:i})}const n=h.get(t.programIdIndex);if(void 0===n)throw new Error(`Failed to find program id for program id index ${t.programIdIndex}`);d.push(new fs({programId:n,data:Ko(t.data),keys:e}))}return new ms({payerKey:l,instructions:d,recentBlockhash:i})}compileToLegacyMessage(){return us.compile({payerKey:this.payerKey,recentBlockhash:this.recentBlockhash,instructions:this.instructions})}compileToV0Message(t){return cs.compile({payerKey:this.payerKey,recentBlockhash:this.recentBlockhash,instructions:this.instructions,addressLookupTableAccounts:t})}}class gs{get version(){return this.message.version}constructor(t,e){if(this.signatures=void 0,this.message=void 0,void 0!==e)ss(e.length===t.header.numRequiredSignatures,"Expected signatures length to be equal to the number of required signatures"),this.signatures=e;else{const e=[];for(let r=0;r<t.header.numRequiredSignatures;r++)e.push(new Uint8Array(Zo));this.signatures=e}this.message=t}serialize(){const t=this.message.serialize(),e=Array();os(e,this.signatures.length);const r=ur([hr(e.length,"encodedSignaturesLength"),cr(es(),this.signatures.length,"signatures"),hr(t.length,"serializedMessage")]),n=new Uint8Array(2048),i=r.encode({encodedSignaturesLength:new Uint8Array(e),signatures:this.signatures,serializedMessage:t},n);return n.slice(0,i)}static deserialize(t){let e=[...t];const r=[],n=is(e);for(let t=0;t<n;t++)r.push(new Uint8Array(e.splice(0,Zo)));const i=hs.deserialize(new Uint8Array(e));return new gs(i,r)}sign(t){const e=this.message.serialize(),r=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures);for(const n of t){const t=r.findIndex((t=>t.equals(n.publicKey)));ss(t>=0,`Cannot sign with non signer key ${n.publicKey.toBase58()}`),this.signatures[t]=No(e,n.secretKey)}}addSignature(t,e){ss(64===e.byteLength,"Signature must be 64 bytes long");const r=this.message.staticAccountKeys.slice(0,this.message.header.numRequiredSignatures).findIndex((e=>e.equals(t)));ss(r>=0,`Can not add signature; \`${t.toBase58()}\` is not required to sign this transaction`),this.signatures[r]=e}}const ys=new Fo("SysvarC1ock11111111111111111111111111111111"),ws=new Fo("SysvarEpochSchedu1e111111111111111111111111"),bs=new Fo("Sysvar1nstructions1111111111111111111111111"),vs=new Fo("SysvarRecentB1ockHashes11111111111111111111"),ks=new Fo("SysvarRent111111111111111111111111111111111"),Ss=new Fo("SysvarRewards111111111111111111111111111111"),_s=new Fo("SysvarS1otHashes111111111111111111111111111"),As=new Fo("SysvarS1otHistory11111111111111111111111111"),Ms=new Fo("SysvarStakeHistory1111111111111111111111111");async function Is(t,e,r,n){const i=n&&{skipPreflight:n.skipPreflight,preflightCommitment:n.preflightCommitment||n.commitment,maxRetries:n.maxRetries,minContextSlot:n.minContextSlot},o=await t.sendTransaction(e,r,i);let s;if(null!=e.recentBlockhash&&null!=e.lastValidBlockHeight)s=(await t.confirmTransaction({abortSignal:n?.abortSignal,signature:o,blockhash:e.recentBlockhash,lastValidBlockHeight:e.lastValidBlockHeight},n&&n.commitment)).value;else if(null!=e.minNonceContextSlot&&null!=e.nonceInfo){const{nonceInstruction:r}=e.nonceInfo,i=r.keys[0].pubkey;s=(await t.confirmTransaction({abortSignal:n?.abortSignal,minContextSlot:e.minNonceContextSlot,nonceAccountPubkey:i,nonceValue:e.nonceInfo.nonce,signature:o},n&&n.commitment)).value}else null!=n?.abortSignal&&console.warn("sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` or a combination of `nonceInfo` and `minNonceContextSlot` are abortable."),s=(await t.confirmTransaction(o,n&&n.commitment)).value;if(s.err)throw new Error(`Transaction ${o} failed (${JSON.stringify(s)})`);return o}function Es(t){return new Promise((e=>setTimeout(e,t)))}function xs(t,r){const n=t.layout.span>=0?t.layout.span:ns(t,r),i=e.Buffer.alloc(n),o=Object.assign({instruction:t.index},r);return t.layout.encode(o,i),i}function Bs(t,e){let r;try{r=t.layout.decode(e)}catch(t){throw new Error("invalid instruction; "+t)}if(r.instruction!==t.index)throw new Error(`invalid instruction; instruction index mismatch ${r.instruction} != ${t.index}`);return r}const Ps=sr("lamportsPerSignature"),Rs=ur([or("version"),or("state"),ts("authorizedPubkey"),ts("nonce"),ur([Ps],"feeCalculator")]),Ts=Rs.span;class Ls{constructor(t){this.authorizedPubkey=void 0,this.nonce=void 0,this.feeCalculator=void 0,this.authorizedPubkey=t.authorizedPubkey,this.nonce=t.nonce,this.feeCalculator=t.feeCalculator}static fromAccountData(t){const e=Rs.decode(Ko(t),0);return new Ls({authorizedPubkey:new Fo(e.authorizedPubkey),nonce:new Fo(e.nonce).toString(),feeCalculator:e.feeCalculator})}}const Os=(Cs=8,t=>{const r=hr(Cs,t),{encode:n,decode:i}=(t=>({decode:t.decode.bind(t),encode:t.encode.bind(t)}))(r),o=r;return o.decode=(t,r)=>{const n=i(t,r);return dr(e.Buffer.from(n))},o.encode=(t,e,r)=>{const i=pr(t,Cs);return n(i,e,r)},o});var Cs;const Us=Object.freeze({Create:{index:0,layout:ur([or("instruction"),ar("lamports"),ar("space"),ts("programId")])},Assign:{index:1,layout:ur([or("instruction"),ts("programId")])},Transfer:{index:2,layout:ur([or("instruction"),Os("lamports")])},CreateWithSeed:{index:3,layout:ur([or("instruction"),ts("base"),rs("seed"),ar("lamports"),ar("space"),ts("programId")])},AdvanceNonceAccount:{index:4,layout:ur([or("instruction")])},WithdrawNonceAccount:{index:5,layout:ur([or("instruction"),ar("lamports")])},InitializeNonceAccount:{index:6,layout:ur([or("instruction"),ts("authorized")])},AuthorizeNonceAccount:{index:7,layout:ur([or("instruction"),ts("authorized")])},Allocate:{index:8,layout:ur([or("instruction"),ar("space")])},AllocateWithSeed:{index:9,layout:ur([or("instruction"),ts("base"),rs("seed"),ar("space"),ts("programId")])},AssignWithSeed:{index:10,layout:ur([or("instruction"),ts("base"),rs("seed"),ts("programId")])},TransferWithSeed:{index:11,layout:ur([or("instruction"),Os("lamports"),rs("seed"),ts("programId")])},UpgradeNonceAccount:{index:12,layout:ur([or("instruction")])}});class Ns{constructor(){}static createAccount(t){const e=xs(Us.Create,{lamports:t.lamports,space:t.space,programId:Ko(t.programId.toBuffer())});return new fs({keys:[{pubkey:t.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:t.newAccountPubkey,isSigner:!0,isWritable:!0}],programId:this.programId,data:e})}static transfer(t){let e,r;if("basePubkey"in t){e=xs(Us.TransferWithSeed,{lamports:BigInt(t.lamports),seed:t.seed,programId:Ko(t.programId.toBuffer())}),r=[{pubkey:t.fromPubkey,isSigner:!1,isWritable:!0},{pubkey:t.basePubkey,isSigner:!0,isWritable:!1},{pubkey:t.toPubkey,isSigner:!1,isWritable:!0}]}else{e=xs(Us.Transfer,{lamports:BigInt(t.lamports)}),r=[{pubkey:t.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:t.toPubkey,isSigner:!1,isWritable:!0}]}return new fs({keys:r,programId:this.programId,data:e})}static assign(t){let e,r;if("basePubkey"in t){e=xs(Us.AssignWithSeed,{base:Ko(t.basePubkey.toBuffer()),seed:t.seed,programId:Ko(t.programId.toBuffer())}),r=[{pubkey:t.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:t.basePubkey,isSigner:!0,isWritable:!1}]}else{e=xs(Us.Assign,{programId:Ko(t.programId.toBuffer())}),r=[{pubkey:t.accountPubkey,isSigner:!0,isWritable:!0}]}return new fs({keys:r,programId:this.programId,data:e})}static createAccountWithSeed(t){const e=xs(Us.CreateWithSeed,{base:Ko(t.basePubkey.toBuffer()),seed:t.seed,lamports:t.lamports,space:t.space,programId:Ko(t.programId.toBuffer())});let r=[{pubkey:t.fromPubkey,isSigner:!0,isWritable:!0},{pubkey:t.newAccountPubkey,isSigner:!1,isWritable:!0}];return t.basePubkey!=t.fromPubkey&&r.push({pubkey:t.basePubkey,isSigner:!0,isWritable:!1}),new fs({keys:r,programId:this.programId,data:e})}static createNonceAccount(t){const e=new ps;"basePubkey"in t&&"seed"in t?e.add(Ns.createAccountWithSeed({fromPubkey:t.fromPubkey,newAccountPubkey:t.noncePubkey,basePubkey:t.basePubkey,seed:t.seed,lamports:t.lamports,space:Ts,programId:this.programId})):e.add(Ns.createAccount({fromPubkey:t.fromPubkey,newAccountPubkey:t.noncePubkey,lamports:t.lamports,space:Ts,programId:this.programId}));const r={noncePubkey:t.noncePubkey,authorizedPubkey:t.authorizedPubkey};return e.add(this.nonceInitialize(r)),e}static nonceInitialize(t){const e=xs(Us.InitializeNonceAccount,{authorized:Ko(t.authorizedPubkey.toBuffer())}),r={keys:[{pubkey:t.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:vs,isSigner:!1,isWritable:!1},{pubkey:ks,isSigner:!1,isWritable:!1}],programId:this.programId,data:e};return new fs(r)}static nonceAdvance(t){const e=xs(Us.AdvanceNonceAccount),r={keys:[{pubkey:t.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:vs,isSigner:!1,isWritable:!1},{pubkey:t.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:e};return new fs(r)}static nonceWithdraw(t){const e=xs(Us.WithdrawNonceAccount,{lamports:t.lamports});return new fs({keys:[{pubkey:t.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:t.toPubkey,isSigner:!1,isWritable:!0},{pubkey:vs,isSigner:!1,isWritable:!1},{pubkey:ks,isSigner:!1,isWritable:!1},{pubkey:t.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:e})}static nonceAuthorize(t){const e=xs(Us.AuthorizeNonceAccount,{authorized:Ko(t.newAuthorizedPubkey.toBuffer())});return new fs({keys:[{pubkey:t.noncePubkey,isSigner:!1,isWritable:!0},{pubkey:t.authorizedPubkey,isSigner:!0,isWritable:!1}],programId:this.programId,data:e})}static allocate(t){let e,r;if("basePubkey"in t){e=xs(Us.AllocateWithSeed,{base:Ko(t.basePubkey.toBuffer()),seed:t.seed,space:t.space,programId:Ko(t.programId.toBuffer())}),r=[{pubkey:t.accountPubkey,isSigner:!1,isWritable:!0},{pubkey:t.basePubkey,isSigner:!0,isWritable:!1}]}else{e=xs(Us.Allocate,{space:t.space}),r=[{pubkey:t.accountPubkey,isSigner:!0,isWritable:!0}]}return new fs({keys:r,programId:this.programId,data:e})}}Ns.programId=new Fo("11111111111111111111111111111111");class zs{constructor(){}static getMinNumSignatures(t){return 2*(Math.ceil(t/zs.chunkSize)+1+1)}static async load(t,r,n,i,o){{const e=await t.getMinimumBalanceForRentExemption(o.length),s=await t.getAccountInfo(n.publicKey,"confirmed");let a=null;if(null!==s){if(s.executable)return console.error("Program load failed, account is already executable"),!1;s.data.length!==o.length&&(a=a||new ps,a.add(Ns.allocate({accountPubkey:n.publicKey,space:o.length}))),s.owner.equals(i)||(a=a||new ps,a.add(Ns.assign({accountPubkey:n.publicKey,programId:i}))),s.lamports<e&&(a=a||new ps,a.add(Ns.transfer({fromPubkey:r.publicKey,toPubkey:n.publicKey,lamports:e-s.lamports})))}else a=(new ps).add(Ns.createAccount({fromPubkey:r.publicKey,newAccountPubkey:n.publicKey,lamports:e>0?e:1,space:o.length,programId:i}));null!==a&&await Is(t,a,[r,n],{commitment:"confirmed"})}const s=ur([or("instruction"),or("offset"),or("bytesLength"),or("bytesLengthPadding"),cr(nr("byte"),rr(or(),-8),"bytes")]),a=zs.chunkSize;let u=0,c=o,h=[];for(;c.length>0;){const o=c.slice(0,a),l=e.Buffer.alloc(a+16);s.encode({instruction:0,offset:u,bytes:o,bytesLength:0,bytesLengthPadding:0},l);const d=(new ps).add({keys:[{pubkey:n.publicKey,isSigner:!0,isWritable:!0}],programId:i,data:l});if(h.push(Is(t,d,[r,n],{commitment:"confirmed"})),t._rpcEndpoint.includes("solana.com")){const t=4;await Es(1e3/t)}u+=a,c=c.slice(a)}await Promise.all(h);{const o=ur([or("instruction")]),s=e.Buffer.alloc(o.span);o.encode({instruction:1},s);const a=(new ps).add({keys:[{pubkey:n.publicKey,isSigner:!0,isWritable:!0},{pubkey:ks,isSigner:!1,isWritable:!1}],programId:i,data:s});await Is(t,a,[r,n],{commitment:"confirmed"})}return!0}}zs.chunkSize=932;const Ks=new Fo("BPFLoader2111111111111111111111111111111111");var Ws=Object.prototype.toString,qs=Object.keys||function(t){var e=[];for(var r in t)e.push(r);return e};function Ds(t,e){var r,n,i,o,s,a,u;if(!0===t)return"true";if(!1===t)return"false";switch(typeof t){case"object":if(null===t)return null;if(t.toJSON&&"function"==typeof t.toJSON)return Ds(t.toJSON(),e);if("[object Array]"===(u=Ws.call(t))){for(i="[",n=t.length-1,r=0;r<n;r++)i+=Ds(t[r],!0)+",";return n>-1&&(i+=Ds(t[r],!0)),i+"]"}if("[object Object]"===u){for(n=(o=qs(t).sort()).length,i="",r=0;r<n;)void 0!==(a=Ds(t[s=o[r]],!1))&&(i&&(i+=","),i+=JSON.stringify(s)+":"+a),r++;return"{"+i+"}"}return JSON.stringify(t);case"function":case"undefined":return e?null:void 0;case"string":return JSON.stringify(t);default:return isFinite(t)?t:null}}var js=function(t){var e=Ds(t,!1);if(void 0!==e)return""+e};function Hs(t){let e=0;for(;t>1;)t/=2,e++;return e}class Fs{constructor(t,e,r,n,i){this.slotsPerEpoch=void 0,this.leaderScheduleSlotOffset=void 0,this.warmup=void 0,this.firstNormalEpoch=void 0,this.firstNormalSlot=void 0,this.slotsPerEpoch=t,this.leaderScheduleSlotOffset=e,this.warmup=r,this.firstNormalEpoch=n,this.firstNormalSlot=i}getEpoch(t){return this.getEpochAndSlotIndex(t)[0]}getEpochAndSlotIndex(t){if(t<this.firstNormalSlot){const r=Hs(0===(e=t+32+1)?1:(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,1+(e|=e>>32)))-Hs(32)-1;return[r,t-(this.getSlotsInEpoch(r)-32)]}{const e=t-this.firstNormalSlot,r=Math.floor(e/this.slotsPerEpoch);return[this.firstNormalEpoch+r,e%this.slotsPerEpoch]}var e}getFirstSlotInEpoch(t){return t<=this.firstNormalEpoch?32*(Math.pow(2,t)-1):(t-this.firstNormalEpoch)*this.slotsPerEpoch+this.firstNormalSlot}getLastSlotInEpoch(t){return this.getFirstSlotInEpoch(t)+this.getSlotsInEpoch(t)-1}getSlotsInEpoch(t){return t<this.firstNormalEpoch?Math.pow(2,t+Hs(32)):this.slotsPerEpoch}}class $s extends Error{constructor(t,e){super(t),this.logs=void 0,this.logs=e}}class Vs extends Error{constructor({code:t,message:e,data:r},n){super(null!=n?`${n}: ${e}`:e),this.code=void 0,this.data=void 0,this.code=t,this.data=r,this.name="SolanaJSONRPCError"}}var Gs=globalThis.fetch;class Zs extends li{constructor(t,e,r){super((t=>{const r=fi(t,{autoconnect:!0,max_reconnects:5,reconnect:!0,reconnect_interval:1e3,...e});return this.underlyingSocket="socket"in r?r.socket:r,r}),t,e,r),this.underlyingSocket=void 0}call(...t){const e=this.underlyingSocket?.readyState;return 1===e?super.call(...t):Promise.reject(new Error("Tried to call a JSON-RPC method `"+t[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+e+")"))}notify(...t){const e=this.underlyingSocket?.readyState;return 1===e?super.notify(...t):Promise.reject(new Error("Tried to send a JSON-RPC notification `"+t[0]+"` but the socket was not `CONNECTING` or `OPEN` (`readyState` was "+e+")"))}}class Ys{constructor(t){this.key=void 0,this.state=void 0,this.key=t.key,this.state=t.state}isActive(){const t=BigInt("0xffffffffffffffff");return this.state.deactivationSlot===t}static deserialize(t){const e=function(t,e){let r;try{r=t.layout.decode(e)}catch(t){throw new Error("invalid instruction; "+t)}if(r.typeIndex!==t.index)throw new Error(`invalid account data; account type mismatch ${r.typeIndex} != ${t.index}`);return r}(Js,t),r=t.length-56;ss(r>=0,"lookup table is invalid"),ss(r%32==0,"lookup table is invalid");const n=r/32,{addresses:i}=ur([cr(ts(),n,"addresses")]).decode(t.slice(56));return{deactivationSlot:e.deactivationSlot,lastExtendedSlot:e.lastExtendedSlot,lastExtendedSlotStartIndex:e.lastExtendedStartIndex,authority:0!==e.authority.length?new Fo(e.authority[0]):void 0,addresses:i.map((t=>new Fo(t)))}}}const Js={index:1,layout:ur([or("typeIndex"),Os("deactivationSlot"),sr("lastExtendedSlot"),nr("lastExtendedStartIndex"),nr(),cr(ts(),rr(nr(),-1),"authority")])},Xs=/^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;const Qs=Wr(Br(Fo),Cr(),(t=>new Fo(t))),ta=Ur([Cr(),Pr("base64")]),ea=Wr(Br(e.Buffer),ta,(t=>e.Buffer.from(t[0],"base64")));function ra(t){let e,r;if("string"==typeof t)e=t;else if(t){const{commitment:n,...i}=t;e=n,r=i}return{commitment:e,config:r}}function na(t){return zr([Nr({jsonrpc:Pr("2.0"),id:Cr(),result:t}),Nr({jsonrpc:Pr("2.0"),id:Cr(),error:Nr({code:Kr(),message:Cr(),data:Lr(Ir("any",(()=>!0)))})})])}const ia=na(Kr());function oa(t){return Wr(na(t),ia,(e=>"error"in e?e:{...e,result:_r(e.result,t)}))}function sa(t){return oa(Nr({context:Nr({slot:Tr()}),value:t}))}function aa(t){return Nr({context:Nr({slot:Tr()}),value:t})}function ua(t,e){return 0===t?new cs({header:e.header,staticAccountKeys:e.accountKeys.map((t=>new Fo(t))),recentBlockhash:e.recentBlockhash,compiledInstructions:e.instructions.map((t=>({programIdIndex:t.programIdIndex,accountKeyIndexes:t.accounts,data:Et.decode(t.data)}))),addressTableLookups:e.addressTableLookups}):new us(e)}const ca=Nr({foundation:Tr(),foundationTerm:Tr(),initial:Tr(),taper:Tr(),terminal:Tr()}),ha=oa(Er(Rr(Nr({epoch:Tr(),effectiveSlot:Tr(),amount:Tr(),postBalance:Tr(),commission:Lr(Rr(Tr()))})))),la=Er(Nr({slot:Tr(),prioritizationFee:Tr()})),da=Nr({total:Tr(),validator:Tr(),foundation:Tr(),epoch:Tr()}),fa=Nr({epoch:Tr(),slotIndex:Tr(),slotsInEpoch:Tr(),absoluteSlot:Tr(),blockHeight:Lr(Tr()),transactionCount:Lr(Tr())}),pa=Nr({slotsPerEpoch:Tr(),leaderScheduleSlotOffset:Tr(),warmup:xr(),firstNormalEpoch:Tr(),firstNormalSlot:Tr()}),ma=Or(Cr(),Er(Tr())),ga=Rr(zr([Nr({}),Cr()])),ya=Nr({err:ga}),wa=Pr("receivedSignature"),ba=Nr({"solana-core":Cr(),"feature-set":Lr(Tr())}),va=sa(Nr({err:Rr(zr([Nr({}),Cr()])),logs:Rr(Er(Cr())),accounts:Lr(Rr(Er(Rr(Nr({executable:xr(),owner:Cr(),lamports:Tr(),data:Er(Cr()),rentEpoch:Lr(Tr())}))))),unitsConsumed:Lr(Tr()),returnData:Lr(Rr(Nr({programId:Cr(),data:Ur([Cr(),Pr("base64")])})))})),ka=sa(Nr({byIdentity:Or(Cr(),Er(Tr())),range:Nr({firstSlot:Tr(),lastSlot:Tr()})}));const Sa=oa(ca),_a=oa(da),Aa=oa(la),Ma=oa(fa),Ia=oa(pa),Ea=oa(ma),xa=oa(Tr()),Ba=sa(Nr({total:Tr(),circulating:Tr(),nonCirculating:Tr(),nonCirculatingAccounts:Er(Qs)})),Pa=Nr({amount:Cr(),uiAmount:Rr(Tr()),decimals:Tr(),uiAmountString:Lr(Cr())}),Ra=sa(Er(Nr({address:Qs,amount:Cr(),uiAmount:Rr(Tr()),decimals:Tr(),uiAmountString:Lr(Cr())}))),Ta=sa(Er(Nr({pubkey:Qs,account:Nr({executable:xr(),owner:Qs,lamports:Tr(),data:ea,rentEpoch:Tr()})}))),La=Nr({program:Cr(),parsed:Kr(),space:Tr()}),Oa=sa(Er(Nr({pubkey:Qs,account:Nr({executable:xr(),owner:Qs,lamports:Tr(),data:La,rentEpoch:Tr()})}))),Ca=sa(Er(Nr({lamports:Tr(),address:Qs}))),Ua=Nr({executable:xr(),owner:Qs,lamports:Tr(),data:ea,rentEpoch:Tr()}),Na=Nr({pubkey:Qs,account:Ua}),za=Wr(zr([Br(e.Buffer),La]),zr([ta,La]),(t=>Array.isArray(t)?_r(t,ea):t)),Ka=Nr({executable:xr(),owner:Qs,lamports:Tr(),data:za,rentEpoch:Tr()}),Wa=Nr({pubkey:Qs,account:Ka}),qa=Nr({state:zr([Pr("active"),Pr("inactive"),Pr("activating"),Pr("deactivating")]),active:Tr(),inactive:Tr()}),Da=oa(Er(Nr({signature:Cr(),slot:Tr(),err:ga,memo:Rr(Cr()),blockTime:Lr(Rr(Tr()))}))),ja=oa(Er(Nr({signature:Cr(),slot:Tr(),err:ga,memo:Rr(Cr()),blockTime:Lr(Rr(Tr()))}))),Ha=Nr({subscription:Tr(),result:aa(Ua)}),Fa=Nr({pubkey:Qs,account:Ua}),$a=Nr({subscription:Tr(),result:aa(Fa)}),Va=Nr({parent:Tr(),slot:Tr(),root:Tr()}),Ga=Nr({subscription:Tr(),result:Va}),Za=zr([Nr({type:zr([Pr("firstShredReceived"),Pr("completed"),Pr("optimisticConfirmation"),Pr("root")]),slot:Tr(),timestamp:Tr()}),Nr({type:Pr("createdBank"),parent:Tr(),slot:Tr(),timestamp:Tr()}),Nr({type:Pr("frozen"),slot:Tr(),timestamp:Tr(),stats:Nr({numTransactionEntries:Tr(),numSuccessfulTransactions:Tr(),numFailedTransactions:Tr(),maxTransactionsPerEntry:Tr()})}),Nr({type:Pr("dead"),slot:Tr(),timestamp:Tr(),err:Cr()})]),Ya=Nr({subscription:Tr(),result:Za}),Ja=Nr({subscription:Tr(),result:aa(zr([ya,wa]))}),Xa=Nr({subscription:Tr(),result:Tr()}),Qa=Nr({pubkey:Cr(),gossip:Rr(Cr()),tpu:Rr(Cr()),rpc:Rr(Cr()),version:Rr(Cr())}),tu=Nr({votePubkey:Cr(),nodePubkey:Cr(),activatedStake:Tr(),epochVoteAccount:xr(),epochCredits:Er(Ur([Tr(),Tr(),Tr()])),commission:Tr(),lastVote:Tr(),rootSlot:Rr(Tr())}),eu=oa(Nr({current:Er(tu),delinquent:Er(tu)})),ru=zr([Pr("processed"),Pr("confirmed"),Pr("finalized")]),nu=Nr({slot:Tr(),confirmations:Rr(Tr()),err:ga,confirmationStatus:Lr(ru)}),iu=sa(Er(Rr(nu))),ou=oa(Tr()),su=Nr({accountKey:Qs,writableIndexes:Er(Tr()),readonlyIndexes:Er(Tr())}),au=Nr({signatures:Er(Cr()),message:Nr({accountKeys:Er(Cr()),header:Nr({numRequiredSignatures:Tr(),numReadonlySignedAccounts:Tr(),numReadonlyUnsignedAccounts:Tr()}),instructions:Er(Nr({accounts:Er(Tr()),data:Cr(),programIdIndex:Tr()})),recentBlockhash:Cr(),addressTableLookups:Lr(Er(su))})}),uu=Nr({pubkey:Qs,signer:xr(),writable:xr(),source:Lr(zr([Pr("transaction"),Pr("lookupTable")]))}),cu=Nr({accountKeys:Er(uu),signatures:Er(Cr())}),hu=Nr({parsed:Kr(),program:Cr(),programId:Qs}),lu=Nr({accounts:Er(Qs),data:Cr(),programId:Qs}),du=Wr(zr([lu,hu]),zr([Nr({parsed:Kr(),program:Cr(),programId:Cr()}),Nr({accounts:Er(Cr()),data:Cr(),programId:Cr()})]),(t=>_r(t,"accounts"in t?lu:hu))),fu=Nr({signatures:Er(Cr()),message:Nr({accountKeys:Er(uu),instructions:Er(du),recentBlockhash:Cr(),addressTableLookups:Lr(Rr(Er(su)))})}),pu=Nr({accountIndex:Tr(),mint:Cr(),owner:Lr(Cr()),uiTokenAmount:Pa}),mu=Nr({writable:Er(Qs),readonly:Er(Qs)}),gu=Nr({err:ga,fee:Tr(),innerInstructions:Lr(Rr(Er(Nr({index:Tr(),instructions:Er(Nr({accounts:Er(Tr()),data:Cr(),programIdIndex:Tr()}))})))),preBalances:Er(Tr()),postBalances:Er(Tr()),logMessages:Lr(Rr(Er(Cr()))),preTokenBalances:Lr(Rr(Er(pu))),postTokenBalances:Lr(Rr(Er(pu))),loadedAddresses:Lr(mu),computeUnitsConsumed:Lr(Tr())}),yu=Nr({err:ga,fee:Tr(),innerInstructions:Lr(Rr(Er(Nr({index:Tr(),instructions:Er(du)})))),preBalances:Er(Tr()),postBalances:Er(Tr()),logMessages:Lr(Rr(Er(Cr()))),preTokenBalances:Lr(Rr(Er(pu))),postTokenBalances:Lr(Rr(Er(pu))),loadedAddresses:Lr(mu),computeUnitsConsumed:Lr(Tr())}),wu=zr([Pr(0),Pr("legacy")]),bu=Nr({pubkey:Cr(),lamports:Tr(),postBalance:Rr(Tr()),rewardType:Rr(Cr()),commission:Lr(Rr(Tr()))}),vu=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),transactions:Er(Nr({transaction:au,meta:Rr(gu),version:Lr(wu)})),rewards:Lr(Er(bu)),blockTime:Rr(Tr()),blockHeight:Rr(Tr())}))),ku=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),rewards:Lr(Er(bu)),blockTime:Rr(Tr()),blockHeight:Rr(Tr())}))),Su=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),transactions:Er(Nr({transaction:cu,meta:Rr(gu),version:Lr(wu)})),rewards:Lr(Er(bu)),blockTime:Rr(Tr()),blockHeight:Rr(Tr())}))),_u=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),transactions:Er(Nr({transaction:fu,meta:Rr(yu),version:Lr(wu)})),rewards:Lr(Er(bu)),blockTime:Rr(Tr()),blockHeight:Rr(Tr())}))),Au=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),transactions:Er(Nr({transaction:cu,meta:Rr(yu),version:Lr(wu)})),rewards:Lr(Er(bu)),blockTime:Rr(Tr()),blockHeight:Rr(Tr())}))),Mu=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),rewards:Lr(Er(bu)),blockTime:Rr(Tr()),blockHeight:Rr(Tr())}))),Iu=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),transactions:Er(Nr({transaction:au,meta:Rr(gu)})),rewards:Lr(Er(bu)),blockTime:Rr(Tr())}))),Eu=oa(Rr(Nr({blockhash:Cr(),previousBlockhash:Cr(),parentSlot:Tr(),signatures:Er(Cr()),blockTime:Rr(Tr())}))),xu=oa(Rr(Nr({slot:Tr(),meta:gu,blockTime:Lr(Rr(Tr())),transaction:au,version:Lr(wu)}))),Bu=oa(Rr(Nr({slot:Tr(),transaction:fu,meta:Rr(yu),blockTime:Lr(Rr(Tr())),version:Lr(wu)}))),Pu=sa(Nr({blockhash:Cr(),feeCalculator:Nr({lamportsPerSignature:Tr()})})),Ru=sa(Nr({blockhash:Cr(),lastValidBlockHeight:Tr()})),Tu=oa(Er(Nr({slot:Tr(),numTransactions:Tr(),numSlots:Tr(),samplePeriodSecs:Tr()}))),Lu=sa(Rr(Nr({feeCalculator:Nr({lamportsPerSignature:Tr()})}))),Ou=oa(Cr()),Cu=oa(Cr()),Uu=Nr({err:ga,logs:Er(Cr()),signature:Cr()}),Nu=Nr({result:aa(Uu),subscription:Tr()}),zu={"solana-client":"js/0.0.0-development"};class Ku{constructor(t){this._keypair=void 0,this._keypair=t??Oo()}static generate(){return new Ku(Oo())}static fromSecretKey(t,e){if(64!==t.byteLength)throw new Error("bad secret key size");const r=t.slice(32,64);if(!e||!e.skipValidation){const e=t.slice(0,32),n=Co(e);for(let t=0;t<32;t++)if(r[t]!==n[t])throw new Error("provided secretKey is invalid")}return new Ku({publicKey:r,secretKey:t})}static fromSeed(t){const e=Co(t),r=new Uint8Array(64);return r.set(t),r.set(e,32),new Ku({publicKey:e,secretKey:r})}get publicKey(){return new Fo(this._keypair.publicKey)}get secretKey(){return new Uint8Array(this._keypair.secretKey)}}const Wu=Object.freeze({CreateLookupTable:{index:0,layout:ur([or("instruction"),Os("recentSlot"),nr("bumpSeed")])},FreezeLookupTable:{index:1,layout:ur([or("instruction")])},ExtendLookupTable:{index:2,layout:ur([or("instruction"),Os(),cr(ts(),rr(or(),-8),"addresses")])},DeactivateLookupTable:{index:3,layout:ur([or("instruction")])},CloseLookupTable:{index:4,layout:ur([or("instruction")])}});class qu{constructor(){}static createLookupTable(t){const[e,r]=Fo.findProgramAddressSync([t.authority.toBuffer(),pr(BigInt(t.recentSlot),8)],this.programId),n=xs(Wu.CreateLookupTable,{recentSlot:BigInt(t.recentSlot),bumpSeed:r}),i=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:t.authority,isSigner:!0,isWritable:!1},{pubkey:t.payer,isSigner:!0,isWritable:!0},{pubkey:Ns.programId,isSigner:!1,isWritable:!1}];return[new fs({programId:this.programId,keys:i,data:n}),e]}static freezeLookupTable(t){const e=xs(Wu.FreezeLookupTable),r=[{pubkey:t.lookupTable,isSigner:!1,isWritable:!0},{pubkey:t.authority,isSigner:!0,isWritable:!1}];return new fs({programId:this.programId,keys:r,data:e})}static extendLookupTable(t){const e=xs(Wu.ExtendLookupTable,{addresses:t.addresses.map((t=>t.toBytes()))}),r=[{pubkey:t.lookupTable,isSigner:!1,isWritable:!0},{pubkey:t.authority,isSigner:!0,isWritable:!1}];return t.payer&&r.push({pubkey:t.payer,isSigner:!0,isWritable:!0},{pubkey:Ns.programId,isSigner:!1,isWritable:!1}),new fs({programId:this.programId,keys:r,data:e})}static deactivateLookupTable(t){const e=xs(Wu.DeactivateLookupTable),r=[{pubkey:t.lookupTable,isSigner:!1,isWritable:!0},{pubkey:t.authority,isSigner:!0,isWritable:!1}];return new fs({programId:this.programId,keys:r,data:e})}static closeLookupTable(t){const e=xs(Wu.CloseLookupTable),r=[{pubkey:t.lookupTable,isSigner:!1,isWritable:!0},{pubkey:t.authority,isSigner:!0,isWritable:!1},{pubkey:t.recipient,isSigner:!1,isWritable:!0}];return new fs({programId:this.programId,keys:r,data:e})}}qu.programId=new Fo("AddressLookupTab1e1111111111111111111111111");const Du=Object.freeze({RequestUnits:{index:0,layout:ur([nr("instruction"),or("units"),or("additionalFee")])},RequestHeapFrame:{index:1,layout:ur([nr("instruction"),or("bytes")])},SetComputeUnitLimit:{index:2,layout:ur([nr("instruction"),or("units")])},SetComputeUnitPrice:{index:3,layout:ur([nr("instruction"),Os("microLamports")])}});class ju{constructor(){}static requestUnits(t){const e=xs(Du.RequestUnits,t);return new fs({keys:[],programId:this.programId,data:e})}static requestHeapFrame(t){const e=xs(Du.RequestHeapFrame,t);return new fs({keys:[],programId:this.programId,data:e})}static setComputeUnitLimit(t){const e=xs(Du.SetComputeUnitLimit,t);return new fs({keys:[],programId:this.programId,data:e})}static setComputeUnitPrice(t){const e=xs(Du.SetComputeUnitPrice,{microLamports:BigInt(t.microLamports)});return new fs({keys:[],programId:this.programId,data:e})}}ju.programId=new Fo("ComputeBudget111111111111111111111111111111");const Hu=ur([nr("numSignatures"),nr("padding"),ir("signatureOffset"),ir("signatureInstructionIndex"),ir("publicKeyOffset"),ir("publicKeyInstructionIndex"),ir("messageDataOffset"),ir("messageDataSize"),ir("messageInstructionIndex")]);class Fu{constructor(){}static createInstructionWithPublicKey(t){const{publicKey:r,message:n,signature:i,instructionIndex:o}=t;ss(32===r.length,`Public Key must be 32 bytes but received ${r.length} bytes`),ss(64===i.length,`Signature must be 64 bytes but received ${i.length} bytes`);const s=Hu.span,a=s+r.length,u=a+i.length,c=e.Buffer.alloc(u+n.length),h=null==o?65535:o;return Hu.encode({numSignatures:1,padding:0,signatureOffset:a,signatureInstructionIndex:h,publicKeyOffset:s,publicKeyInstructionIndex:h,messageDataOffset:u,messageDataSize:n.length,messageInstructionIndex:h},c),c.fill(r,s),c.fill(i,a),c.fill(n,u),new fs({keys:[],programId:Fu.programId,data:c})}static createInstructionWithPrivateKey(t){const{privateKey:e,message:r,instructionIndex:n}=t;ss(64===e.length,`Private key must be 64 bytes but received ${e.length} bytes`);try{const t=Ku.fromSecretKey(e),i=t.publicKey.toBytes(),o=No(r,t.secretKey);return this.createInstructionWithPublicKey({publicKey:i,message:r,signature:o,instructionIndex:n})}catch(t){throw new Error(`Error creating instruction; ${t}`)}}}Fu.programId=new Fo("Ed25519SigVerify111111111111111111111111111"),To.hmacSha256Sync=(t,...e)=>{const r=Ti.create(Ot,t);return e.forEach((t=>r.update(t))),r.digest()};To.isValidPrivateKey;const $u=function(t,e=!1){return Xi.fromPrivateKey(t).toRawBytes(e)},Vu=ur([nr("numSignatures"),ir("signatureOffset"),nr("signatureInstructionIndex"),ir("ethAddressOffset"),nr("ethAddressInstructionIndex"),ir("messageDataOffset"),ir("messageDataSize"),nr("messageInstructionIndex"),hr(20,"ethAddress"),hr(64,"signature"),nr("recoveryId")]);class Gu{constructor(){}static publicKeyToEthAddress(t){ss(64===t.length,`Public key must be 64 bytes but received ${t.length} bytes`);try{return e.Buffer.from(Bi(Ko(t))).slice(-20)}catch(t){throw new Error(`Error constructing Ethereum address: ${t}`)}}static createInstructionWithPublicKey(t){const{publicKey:e,message:r,signature:n,recoveryId:i,instructionIndex:o}=t;return Gu.createInstructionWithEthAddress({ethAddress:Gu.publicKeyToEthAddress(e),message:r,signature:n,recoveryId:i,instructionIndex:o})}static createInstructionWithEthAddress(t){const{ethAddress:r,message:n,signature:i,recoveryId:o,instructionIndex:s=0}=t;let a;a="string"==typeof r?r.startsWith("0x")?e.Buffer.from(r.substr(2),"hex"):e.Buffer.from(r,"hex"):r,ss(20===a.length,`Address must be 20 bytes but received ${a.length} bytes`);const u=12+a.length,c=u+i.length+1,h=e.Buffer.alloc(Vu.span+n.length);return Vu.encode({numSignatures:1,signatureOffset:u,signatureInstructionIndex:s,ethAddressOffset:12,ethAddressInstructionIndex:s,messageDataOffset:c,messageDataSize:n.length,messageInstructionIndex:s,signature:Ko(i),ethAddress:Ko(a),recoveryId:o},h),h.fill(Ko(n),Vu.span),new fs({keys:[],programId:Gu.programId,data:h})}static createInstructionWithPrivateKey(t){const{privateKey:r,message:n,instructionIndex:i}=t;ss(32===r.length,`Private key must be 32 bytes but received ${r.length} bytes`);try{const t=Ko(r),o=$u(t,!1).slice(1),s=e.Buffer.from(Bi(Ko(n))),[a,u]=Bo(s,t,{der:!1,recovered:!0});return this.createInstructionWithPublicKey({publicKey:o,message:n,signature:a,recoveryId:u,instructionIndex:i})}catch(t){throw new Error(`Error creating instruction; ${t}`)}}}Gu.programId=new Fo("KeccakSecp256k11111111111111111111111111111");const Zu=new Fo("StakeConfig11111111111111111111111111111111");class Yu{constructor(t,e){this.staker=void 0,this.withdrawer=void 0,this.staker=t,this.withdrawer=e}}class Ju{constructor(t,e,r){this.unixTimestamp=void 0,this.epoch=void 0,this.custodian=void 0,this.unixTimestamp=t,this.epoch=e,this.custodian=r}}Ju.default=new Ju(0,0,Fo.default);const Xu=Object.freeze({Initialize:{index:0,layout:ur([or("instruction"),((t="authorized")=>ur([ts("staker"),ts("withdrawer")],t))(),((t="lockup")=>ur([ar("unixTimestamp"),ar("epoch"),ts("custodian")],t))()])},Authorize:{index:1,layout:ur([or("instruction"),ts("newAuthorized"),or("stakeAuthorizationType")])},Delegate:{index:2,layout:ur([or("instruction")])},Split:{index:3,layout:ur([or("instruction"),ar("lamports")])},Withdraw:{index:4,layout:ur([or("instruction"),ar("lamports")])},Deactivate:{index:5,layout:ur([or("instruction")])},Merge:{index:7,layout:ur([or("instruction")])},AuthorizeWithSeed:{index:8,layout:ur([or("instruction"),ts("newAuthorized"),or("stakeAuthorizationType"),rs("authoritySeed"),ts("authorityOwner")])}}),Qu=Object.freeze({Staker:{index:0},Withdrawer:{index:1}});class tc{constructor(){}static initialize(t){const{stakePubkey:e,authorized:r,lockup:n}=t,i=n||Ju.default,o=xs(Xu.Initialize,{authorized:{staker:Ko(r.staker.toBuffer()),withdrawer:Ko(r.withdrawer.toBuffer())},lockup:{unixTimestamp:i.unixTimestamp,epoch:i.epoch,custodian:Ko(i.custodian.toBuffer())}}),s={keys:[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:ks,isSigner:!1,isWritable:!1}],programId:this.programId,data:o};return new fs(s)}static createAccountWithSeed(t){const e=new ps;e.add(Ns.createAccountWithSeed({fromPubkey:t.fromPubkey,newAccountPubkey:t.stakePubkey,basePubkey:t.basePubkey,seed:t.seed,lamports:t.lamports,space:this.space,programId:this.programId}));const{stakePubkey:r,authorized:n,lockup:i}=t;return e.add(this.initialize({stakePubkey:r,authorized:n,lockup:i}))}static createAccount(t){const e=new ps;e.add(Ns.createAccount({fromPubkey:t.fromPubkey,newAccountPubkey:t.stakePubkey,lamports:t.lamports,space:this.space,programId:this.programId}));const{stakePubkey:r,authorized:n,lockup:i}=t;return e.add(this.initialize({stakePubkey:r,authorized:n,lockup:i}))}static delegate(t){const{stakePubkey:e,authorizedPubkey:r,votePubkey:n}=t,i=xs(Xu.Delegate);return(new ps).add({keys:[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:Ms,isSigner:!1,isWritable:!1},{pubkey:Zu,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:i})}static authorize(t){const{stakePubkey:e,authorizedPubkey:r,newAuthorizedPubkey:n,stakeAuthorizationType:i,custodianPubkey:o}=t,s=xs(Xu.Authorize,{newAuthorized:Ko(n.toBuffer()),stakeAuthorizationType:i.index}),a=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:ys,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1}];return o&&a.push({pubkey:o,isSigner:!1,isWritable:!1}),(new ps).add({keys:a,programId:this.programId,data:s})}static authorizeWithSeed(t){const{stakePubkey:e,authorityBase:r,authoritySeed:n,authorityOwner:i,newAuthorizedPubkey:o,stakeAuthorizationType:s,custodianPubkey:a}=t,u=xs(Xu.AuthorizeWithSeed,{newAuthorized:Ko(o.toBuffer()),stakeAuthorizationType:s.index,authoritySeed:n,authorityOwner:Ko(i.toBuffer())}),c=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1},{pubkey:ys,isSigner:!1,isWritable:!1}];return a&&c.push({pubkey:a,isSigner:!1,isWritable:!1}),(new ps).add({keys:c,programId:this.programId,data:u})}static splitInstruction(t){const{stakePubkey:e,authorizedPubkey:r,splitStakePubkey:n,lamports:i}=t,o=xs(Xu.Split,{lamports:i});return new fs({keys:[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:o})}static split(t){const e=new ps;return e.add(Ns.createAccount({fromPubkey:t.authorizedPubkey,newAccountPubkey:t.splitStakePubkey,lamports:0,space:this.space,programId:this.programId})),e.add(this.splitInstruction(t))}static splitWithSeed(t){const{stakePubkey:e,authorizedPubkey:r,splitStakePubkey:n,basePubkey:i,seed:o,lamports:s}=t,a=new ps;return a.add(Ns.allocate({accountPubkey:n,basePubkey:i,seed:o,space:this.space,programId:this.programId})),a.add(this.splitInstruction({stakePubkey:e,authorizedPubkey:r,splitStakePubkey:n,lamports:s}))}static merge(t){const{stakePubkey:e,sourceStakePubKey:r,authorizedPubkey:n}=t,i=xs(Xu.Merge);return(new ps).add({keys:[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:Ms,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],programId:this.programId,data:i})}static withdraw(t){const{stakePubkey:e,authorizedPubkey:r,toPubkey:n,lamports:i,custodianPubkey:o}=t,s=xs(Xu.Withdraw,{lamports:i}),a=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:Ms,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}];return o&&a.push({pubkey:o,isSigner:!1,isWritable:!1}),(new ps).add({keys:a,programId:this.programId,data:s})}static deactivate(t){const{stakePubkey:e,authorizedPubkey:r}=t,n=xs(Xu.Deactivate);return(new ps).add({keys:[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:n})}}tc.programId=new Fo("Stake11111111111111111111111111111111111111"),tc.space=200;class ec{constructor(t,e,r,n){this.nodePubkey=void 0,this.authorizedVoter=void 0,this.authorizedWithdrawer=void 0,this.commission=void 0,this.nodePubkey=t,this.authorizedVoter=e,this.authorizedWithdrawer=r,this.commission=n}}const rc=Object.freeze({InitializeAccount:{index:0,layout:ur([or("instruction"),((t="voteInit")=>ur([ts("nodePubkey"),ts("authorizedVoter"),ts("authorizedWithdrawer"),nr("commission")],t))()])},Authorize:{index:1,layout:ur([or("instruction"),ts("newAuthorized"),or("voteAuthorizationType")])},Withdraw:{index:3,layout:ur([or("instruction"),ar("lamports")])},AuthorizeWithSeed:{index:10,layout:ur([or("instruction"),((t="voteAuthorizeWithSeedArgs")=>ur([or("voteAuthorizationType"),ts("currentAuthorityDerivedKeyOwnerPubkey"),rs("currentAuthorityDerivedKeySeed"),ts("newAuthorized")],t))()])}}),nc=Object.freeze({Voter:{index:0},Withdrawer:{index:1}});class ic{constructor(){}static initializeAccount(t){const{votePubkey:e,nodePubkey:r,voteInit:n}=t,i=xs(rc.InitializeAccount,{voteInit:{nodePubkey:Ko(n.nodePubkey.toBuffer()),authorizedVoter:Ko(n.authorizedVoter.toBuffer()),authorizedWithdrawer:Ko(n.authorizedWithdrawer.toBuffer()),commission:n.commission}}),o={keys:[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:ks,isSigner:!1,isWritable:!1},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}],programId:this.programId,data:i};return new fs(o)}static createAccount(t){const e=new ps;return e.add(Ns.createAccount({fromPubkey:t.fromPubkey,newAccountPubkey:t.votePubkey,lamports:t.lamports,space:this.space,programId:this.programId})),e.add(this.initializeAccount({votePubkey:t.votePubkey,nodePubkey:t.voteInit.nodePubkey,voteInit:t.voteInit}))}static authorize(t){const{votePubkey:e,authorizedPubkey:r,newAuthorizedPubkey:n,voteAuthorizationType:i}=t,o=xs(rc.Authorize,{newAuthorized:Ko(n.toBuffer()),voteAuthorizationType:i.index}),s=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!0,isWritable:!1}];return(new ps).add({keys:s,programId:this.programId,data:o})}static authorizeWithSeed(t){const{currentAuthorityDerivedKeyBasePubkey:e,currentAuthorityDerivedKeyOwnerPubkey:r,currentAuthorityDerivedKeySeed:n,newAuthorizedPubkey:i,voteAuthorizationType:o,votePubkey:s}=t,a=xs(rc.AuthorizeWithSeed,{voteAuthorizeWithSeedArgs:{currentAuthorityDerivedKeyOwnerPubkey:Ko(r.toBuffer()),currentAuthorityDerivedKeySeed:n,newAuthorized:Ko(i.toBuffer()),voteAuthorizationType:o.index}}),u=[{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:ys,isSigner:!1,isWritable:!1},{pubkey:e,isSigner:!0,isWritable:!1}];return(new ps).add({keys:u,programId:this.programId,data:a})}static withdraw(t){const{votePubkey:e,authorizedWithdrawerPubkey:r,lamports:n,toPubkey:i}=t,o=xs(rc.Withdraw,{lamports:n}),s=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1}];return(new ps).add({keys:s,programId:this.programId,data:o})}static safeWithdraw(t,e,r){if(t.lamports>e-r)throw new Error("Withdraw will leave vote account with insuffcient funds.");return ic.withdraw(t)}}ic.programId=new Fo("Vote111111111111111111111111111111111111111"),ic.space=3731;const oc=new Fo("Va1idator1nfo111111111111111111111111111111"),sc=Nr({name:Cr(),website:Lr(Cr()),details:Lr(Cr()),keybaseUsername:Lr(Cr())});class ac{constructor(t,e){this.key=void 0,this.info=void 0,this.key=t,this.info=e}static fromConfigData(t){let r=[...t];if(2!==is(r))return null;const n=[];for(let t=0;t<2;t++){const t=new Fo(r.slice(0,jo));r=r.slice(jo);const e=1===r.slice(0,1)[0];r=r.slice(1),n.push({publicKey:t,isSigner:e})}if(n[0].publicKey.equals(oc)&&n[1].isSigner){const t=rs().decode(e.Buffer.from(r)),i=JSON.parse(t);return Sr(i,sc),new ac(n[1].publicKey,i)}return null}}const uc=new Fo("Vote111111111111111111111111111111111111111"),cc=ur([ts("nodePubkey"),ts("authorizedWithdrawer"),nr("commission"),sr(),cr(ur([sr("slot"),or("confirmationCount")]),rr(or(),-8),"votes"),nr("rootSlotValid"),sr("rootSlot"),sr(),cr(ur([sr("epoch"),ts("authorizedVoter")]),rr(or(),-8),"authorizedVoters"),ur([cr(ur([ts("authorizedPubkey"),sr("epochOfLastAuthorizedSwitch"),sr("targetEpoch")]),32,"buf"),sr("idx"),nr("isEmpty")],"priorVoters"),sr(),cr(ur([sr("epoch"),sr("credits"),sr("prevCredits")]),rr(or(),-8),"epochCredits"),ur([sr("slot"),sr("timestamp")],"lastTimestamp")]);class hc{constructor(t){this.nodePubkey=void 0,this.authorizedWithdrawer=void 0,this.commission=void 0,this.rootSlot=void 0,this.votes=void 0,this.authorizedVoters=void 0,this.priorVoters=void 0,this.epochCredits=void 0,this.lastTimestamp=void 0,this.nodePubkey=t.nodePubkey,this.authorizedWithdrawer=t.authorizedWithdrawer,this.commission=t.commission,this.rootSlot=t.rootSlot,this.votes=t.votes,this.authorizedVoters=t.authorizedVoters,this.priorVoters=t.priorVoters,this.epochCredits=t.epochCredits,this.lastTimestamp=t.lastTimestamp}static fromAccountData(t){const e=cc.decode(Ko(t),4);let r=e.rootSlot;return e.rootSlotValid||(r=null),new hc({nodePubkey:new Fo(e.nodePubkey),authorizedWithdrawer:new Fo(e.authorizedWithdrawer),commission:e.commission,votes:e.votes,rootSlot:r,authorizedVoters:e.authorizedVoters.map(lc),priorVoters:fc(e.priorVoters),epochCredits:e.epochCredits,lastTimestamp:e.lastTimestamp})}}function lc({authorizedVoter:t,epoch:e}){return{epoch:e,authorizedVoter:new Fo(t)}}function dc({authorizedPubkey:t,epochOfLastAuthorizedSwitch:e,targetEpoch:r}){return{authorizedPubkey:new Fo(t),epochOfLastAuthorizedSwitch:e,targetEpoch:r}}function fc({buf:t,idx:e,isEmpty:r}){return r?[]:[...t.slice(e+1).map(dc),...t.slice(0,e).map(dc)]}const pc={http:{devnet:"http://api.devnet.solana.com",testnet:"http://api.testnet.solana.com","mainnet-beta":"http://api.mainnet-beta.solana.com/"},https:{devnet:"https://api.devnet.solana.com",testnet:"https://api.testnet.solana.com","mainnet-beta":"https://api.mainnet-beta.solana.com/"}};var mc=Object.freeze({__proto__:null,Account:class{constructor(t){if(this._publicKey=void 0,this._secretKey=void 0,t){const e=Ko(t);if(64!==t.length)throw new Error("bad secret key size");this._publicKey=e.slice(32,64),this._secretKey=e.slice(0,32)}else this._secretKey=Ko(Lo()),this._publicKey=Ko(Co(this._secretKey))}get publicKey(){return new Fo(this._publicKey)}get secretKey(){return e.Buffer.concat([this._secretKey,this._publicKey],64)}},AddressLookupTableAccount:Ys,AddressLookupTableInstruction:class{constructor(){}static decodeInstructionType(t){this.checkProgramId(t.programId);const e=or("instruction").decode(t.data);let r;for(const[t,n]of Object.entries(Wu))if(n.index==e){r=t;break}if(!r)throw new Error("Invalid Instruction. Should be a LookupTable Instruction");return r}static decodeCreateLookupTable(t){this.checkProgramId(t.programId),this.checkKeysLength(t.keys,4);const{recentSlot:e}=Bs(Wu.CreateLookupTable,t.data);return{authority:t.keys[1].pubkey,payer:t.keys[2].pubkey,recentSlot:Number(e)}}static decodeExtendLookupTable(t){if(this.checkProgramId(t.programId),t.keys.length<2)throw new Error(`invalid instruction; found ${t.keys.length} keys, expected at least 2`);const{addresses:e}=Bs(Wu.ExtendLookupTable,t.data);return{lookupTable:t.keys[0].pubkey,authority:t.keys[1].pubkey,payer:t.keys.length>2?t.keys[2].pubkey:void 0,addresses:e.map((t=>new Fo(t)))}}static decodeCloseLookupTable(t){return this.checkProgramId(t.programId),this.checkKeysLength(t.keys,3),{lookupTable:t.keys[0].pubkey,authority:t.keys[1].pubkey,recipient:t.keys[2].pubkey}}static decodeFreezeLookupTable(t){return this.checkProgramId(t.programId),this.checkKeysLength(t.keys,2),{lookupTable:t.keys[0].pubkey,authority:t.keys[1].pubkey}}static decodeDeactivateLookupTable(t){return this.checkProgramId(t.programId),this.checkKeysLength(t.keys,2),{lookupTable:t.keys[0].pubkey,authority:t.keys[1].pubkey}}static checkProgramId(t){if(!t.equals(qu.programId))throw new Error("invalid instruction; programId is not AddressLookupTable Program")}static checkKeysLength(t,e){if(t.length<e)throw new Error(`invalid instruction; found ${t.length} keys, expected at least ${e}`)}},AddressLookupTableProgram:qu,Authorized:Yu,BLOCKHASH_CACHE_TIMEOUT_MS:3e4,BPF_LOADER_DEPRECATED_PROGRAM_ID:$o,BPF_LOADER_PROGRAM_ID:Ks,BpfLoader:class{static getMinNumSignatures(t){return zs.getMinNumSignatures(t)}static load(t,e,r,n,i){return zs.load(t,e,r,i,n)}},COMPUTE_BUDGET_INSTRUCTION_LAYOUTS:Du,ComputeBudgetInstruction:class{constructor(){}static decodeInstructionType(t){this.checkProgramId(t.programId);const e=nr("instruction").decode(t.data);let r;for(const[t,n]of Object.entries(Du))if(n.index==e){r=t;break}if(!r)throw new Error("Instruction type incorrect; not a ComputeBudgetInstruction");return r}static decodeRequestUnits(t){this.checkProgramId(t.programId);const{units:e,additionalFee:r}=Bs(Du.RequestUnits,t.data);return{units:e,additionalFee:r}}static decodeRequestHeapFrame(t){this.checkProgramId(t.programId);const{bytes:e}=Bs(Du.RequestHeapFrame,t.data);return{bytes:e}}static decodeSetComputeUnitLimit(t){this.checkProgramId(t.programId);const{units:e}=Bs(Du.SetComputeUnitLimit,t.data);return{units:e}}static decodeSetComputeUnitPrice(t){this.checkProgramId(t.programId);const{microLamports:e}=Bs(Du.SetComputeUnitPrice,t.data);return{microLamports:e}}static checkProgramId(t){if(!t.equals(ju.programId))throw new Error("invalid instruction; programId is not ComputeBudgetProgram")}},ComputeBudgetProgram:ju,Connection:class{constructor(t,e){let r,n,i,o,s,a;this._commitment=void 0,this._confirmTransactionInitialTimeout=void 0,this._rpcEndpoint=void 0,this._rpcWsEndpoint=void 0,this._rpcClient=void 0,this._rpcRequest=void 0,this._rpcBatchRequest=void 0,this._rpcWebSocket=void 0,this._rpcWebSocketConnected=!1,this._rpcWebSocketHeartbeat=null,this._rpcWebSocketIdleTimeout=null,this._rpcWebSocketGeneration=0,this._disableBlockhashCaching=!1,this._pollingBlockhash=!1,this._blockhashInfo={latestBlockhash:null,lastFetch:0,transactionSignatures:[],simulatedSignatures:[]},this._nextClientSubscriptionId=0,this._subscriptionDisposeFunctionsByClientSubscriptionId={},this._subscriptionHashByClientSubscriptionId={},this._subscriptionStateChangeCallbacksByHash={},this._subscriptionCallbacksByServerSubscriptionId={},this._subscriptionsByHash={},this._subscriptionsAutoDisposedByRpc=new Set,this.getBlockHeight=(()=>{const t={};return async e=>{const{commitment:r,config:n}=ra(e),i=this._buildArgs([],r,void 0,n),o=js(i);return t[o]=t[o]??(async()=>{try{const t=_r(await this._rpcRequest("getBlockHeight",i),oa(Tr()));if("error"in t)throw new Vs(t.error,"failed to get block height information");return t.result}finally{delete t[o]}})(),await t[o]}})(),e&&"string"==typeof e?this._commitment=e:e&&(this._commitment=e.commitment,this._confirmTransactionInitialTimeout=e.confirmTransactionInitialTimeout,r=e.wsEndpoint,n=e.httpHeaders,i=e.fetch,o=e.fetchMiddleware,s=e.disableRetryOnRateLimit,a=e.httpAgent),this._rpcEndpoint=function(t){if(!1===/^https?:/.test(t))throw new TypeError("Endpoint URL must start with `http:` or `https:`.");return t}(t),this._rpcWsEndpoint=r||function(t){const e=t.match(Xs);if(null==e)throw TypeError(`Failed to validate endpoint URL \`${t}\``);const[r,n,i,o]=e,s=t.startsWith("https:")?"wss:":"ws:",a=null==i?null:parseInt(i.slice(1),10);return`${s}//${n}${null==a?"":`:${a+1}`}${o}`}(t),this._rpcClient=function(t,e,r,n,i,o){const s=r||Gs;let a;return null!=o&&console.warn("You have supplied an `httpAgent` when creating a `Connection` in a browser environment.It has been ignored; `httpAgent` is only used in Node environments."),n&&(a=async(t,e)=>{const r=await new Promise(((r,i)=>{try{n(t,e,((t,e)=>r([t,e])))}catch(t){i(t)}}));return await s(...r)}),new kn((async(r,n)=>{const o={method:"POST",body:r,agent:void 0,headers:Object.assign({"Content-Type":"application/json"},e||{},zu)};try{let e,r=5,u=500;for(;e=a?await a(t,o):await s(t,o),429===e.status&&!0!==i&&(r-=1,0!==r);)console.log(`Server responded with ${e.status} ${e.statusText}. Retrying after ${u}ms delay...`),await Es(u),u*=2;const c=await e.text();e.ok?n(null,c):n(new Error(`${e.status} ${e.statusText}: ${c}`))}catch(t){t instanceof Error&&n(t)}}),{})}(t,n,i,o,s,a),this._rpcRequest=function(t){return(e,r)=>new Promise(((n,i)=>{t.request(e,r,((t,e)=>{t?i(t):n(e)}))}))}(this._rpcClient),this._rpcBatchRequest=function(t){return e=>new Promise(((r,n)=>{0===e.length&&r([]);const i=e.map((e=>t.request(e.methodName,e.args)));t.request(i,((t,e)=>{t?n(t):r(e)}))}))}(this._rpcClient),this._rpcWebSocket=new Zs(this._rpcWsEndpoint,{autoconnect:!1,max_reconnects:1/0}),this._rpcWebSocket.on("open",this._wsOnOpen.bind(this)),this._rpcWebSocket.on("error",this._wsOnError.bind(this)),this._rpcWebSocket.on("close",this._wsOnClose.bind(this)),this._rpcWebSocket.on("accountNotification",this._wsOnAccountNotification.bind(this)),this._rpcWebSocket.on("programNotification",this._wsOnProgramAccountNotification.bind(this)),this._rpcWebSocket.on("slotNotification",this._wsOnSlotNotification.bind(this)),this._rpcWebSocket.on("slotsUpdatesNotification",this._wsOnSlotUpdatesNotification.bind(this)),this._rpcWebSocket.on("signatureNotification",this._wsOnSignatureNotification.bind(this)),this._rpcWebSocket.on("rootNotification",this._wsOnRootNotification.bind(this)),this._rpcWebSocket.on("logsNotification",this._wsOnLogsNotification.bind(this))}get commitment(){return this._commitment}get rpcEndpoint(){return this._rpcEndpoint}async getBalanceAndContext(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgs([t.toBase58()],r,void 0,n),o=_r(await this._rpcRequest("getBalance",i),sa(Tr()));if("error"in o)throw new Vs(o.error,`failed to get balance for ${t.toBase58()}`);return o.result}async getBalance(t,e){return await this.getBalanceAndContext(t,e).then((t=>t.value)).catch((e=>{throw new Error("failed to get balance of account "+t.toBase58()+": "+e)}))}async getBlockTime(t){const e=_r(await this._rpcRequest("getBlockTime",[t]),oa(Rr(Tr())));if("error"in e)throw new Vs(e.error,`failed to get block time for slot ${t}`);return e.result}async getMinimumLedgerSlot(){const t=_r(await this._rpcRequest("minimumLedgerSlot",[]),oa(Tr()));if("error"in t)throw new Vs(t.error,"failed to get minimum ledger slot");return t.result}async getFirstAvailableBlock(){const t=_r(await this._rpcRequest("getFirstAvailableBlock",[]),xa);if("error"in t)throw new Vs(t.error,"failed to get first available block");return t.result}async getSupply(t){let e={};e="string"==typeof t?{commitment:t}:t?{...t,commitment:t&&t.commitment||this.commitment}:{commitment:this.commitment};const r=_r(await this._rpcRequest("getSupply",[e]),Ba);if("error"in r)throw new Vs(r.error,"failed to get supply");return r.result}async getTokenSupply(t,e){const r=this._buildArgs([t.toBase58()],e),n=_r(await this._rpcRequest("getTokenSupply",r),sa(Pa));if("error"in n)throw new Vs(n.error,"failed to get token supply");return n.result}async getTokenAccountBalance(t,e){const r=this._buildArgs([t.toBase58()],e),n=_r(await this._rpcRequest("getTokenAccountBalance",r),sa(Pa));if("error"in n)throw new Vs(n.error,"failed to get token account balance");return n.result}async getTokenAccountsByOwner(t,e,r){const{commitment:n,config:i}=ra(r);let o=[t.toBase58()];"mint"in e?o.push({mint:e.mint.toBase58()}):o.push({programId:e.programId.toBase58()});const s=this._buildArgs(o,n,"base64",i),a=_r(await this._rpcRequest("getTokenAccountsByOwner",s),Ta);if("error"in a)throw new Vs(a.error,`failed to get token accounts owned by account ${t.toBase58()}`);return a.result}async getParsedTokenAccountsByOwner(t,e,r){let n=[t.toBase58()];"mint"in e?n.push({mint:e.mint.toBase58()}):n.push({programId:e.programId.toBase58()});const i=this._buildArgs(n,r,"jsonParsed"),o=_r(await this._rpcRequest("getTokenAccountsByOwner",i),Oa);if("error"in o)throw new Vs(o.error,`failed to get token accounts owned by account ${t.toBase58()}`);return o.result}async getLargestAccounts(t){const e={...t,commitment:t&&t.commitment||this.commitment},r=e.filter||e.commitment?[e]:[],n=_r(await this._rpcRequest("getLargestAccounts",r),Ca);if("error"in n)throw new Vs(n.error,"failed to get largest accounts");return n.result}async getTokenLargestAccounts(t,e){const r=this._buildArgs([t.toBase58()],e),n=_r(await this._rpcRequest("getTokenLargestAccounts",r),Ra);if("error"in n)throw new Vs(n.error,"failed to get token largest accounts");return n.result}async getAccountInfoAndContext(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgs([t.toBase58()],r,"base64",n),o=_r(await this._rpcRequest("getAccountInfo",i),sa(Rr(Ua)));if("error"in o)throw new Vs(o.error,`failed to get info about account ${t.toBase58()}`);return o.result}async getParsedAccountInfo(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgs([t.toBase58()],r,"jsonParsed",n),o=_r(await this._rpcRequest("getAccountInfo",i),sa(Rr(Ka)));if("error"in o)throw new Vs(o.error,`failed to get info about account ${t.toBase58()}`);return o.result}async getAccountInfo(t,e){try{return(await this.getAccountInfoAndContext(t,e)).value}catch(e){throw new Error("failed to get info about account "+t.toBase58()+": "+e)}}async getMultipleParsedAccounts(t,e){const{commitment:r,config:n}=ra(e),i=t.map((t=>t.toBase58())),o=this._buildArgs([i],r,"jsonParsed",n),s=_r(await this._rpcRequest("getMultipleAccounts",o),sa(Er(Rr(Ka))));if("error"in s)throw new Vs(s.error,`failed to get info for accounts ${i}`);return s.result}async getMultipleAccountsInfoAndContext(t,e){const{commitment:r,config:n}=ra(e),i=t.map((t=>t.toBase58())),o=this._buildArgs([i],r,"base64",n),s=_r(await this._rpcRequest("getMultipleAccounts",o),sa(Er(Rr(Ua))));if("error"in s)throw new Vs(s.error,`failed to get info for accounts ${i}`);return s.result}async getMultipleAccountsInfo(t,e){return(await this.getMultipleAccountsInfoAndContext(t,e)).value}async getStakeActivation(t,e,r){const{commitment:n,config:i}=ra(e),o=this._buildArgs([t.toBase58()],n,void 0,{...i,epoch:null!=r?r:i?.epoch}),s=_r(await this._rpcRequest("getStakeActivation",o),oa(qa));if("error"in s)throw new Vs(s.error,`failed to get Stake Activation ${t.toBase58()}`);return s.result}async getProgramAccounts(t,e){const{commitment:r,config:n}=ra(e),{encoding:i,...o}=n||{},s=this._buildArgs([t.toBase58()],r,i||"base64",o),a=_r(await this._rpcRequest("getProgramAccounts",s),oa(Er(Na)));if("error"in a)throw new Vs(a.error,`failed to get accounts owned by program ${t.toBase58()}`);return a.result}async getParsedProgramAccounts(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgs([t.toBase58()],r,"jsonParsed",n),o=_r(await this._rpcRequest("getProgramAccounts",i),oa(Er(Wa)));if("error"in o)throw new Vs(o.error,`failed to get accounts owned by program ${t.toBase58()}`);return o.result}async confirmTransaction(t,e){let r,n;if("string"==typeof t)r=t;else{const e=t;if(e.abortSignal?.aborted)return Promise.reject(e.abortSignal.reason);r=e.signature}try{n=Et.decode(r)}catch(t){throw new Error("signature must be base58 encoded: "+r)}return ss(64===n.length,"signature has invalid length"),"string"==typeof t?await this.confirmTransactionUsingLegacyTimeoutStrategy({commitment:e||this.commitment,signature:r}):"lastValidBlockHeight"in t?await this.confirmTransactionUsingBlockHeightExceedanceStrategy({commitment:e||this.commitment,strategy:t}):await this.confirmTransactionUsingDurableNonceStrategy({commitment:e||this.commitment,strategy:t})}getCancellationPromise(t){return new Promise(((e,r)=>{null!=t&&(t.aborted?r(t.reason):t.addEventListener("abort",(()=>{r(t.reason)})))}))}getTransactionConfirmationPromise({commitment:t,signature:e}){let r,n,i=!1;return{abortConfirmation:()=>{n&&(n(),n=void 0),null!=r&&(this.removeSignatureListener(r),r=void 0)},confirmationPromise:new Promise(((o,s)=>{try{r=this.onSignature(e,((t,e)=>{r=void 0;const n={context:e,value:t};o({__type:ls.PROCESSED,response:n})}),t);const a=new Promise((t=>{null==r?t():n=this._onSubscriptionStateChange(r,(e=>{"subscribed"===e&&t()}))}));(async()=>{if(await a,i)return;const r=await this.getSignatureStatus(e);if(i)return;if(null==r)return;const{context:n,value:u}=r;if(null!=u)if(u?.err)s(u.err);else{switch(t){case"confirmed":case"single":case"singleGossip":if("processed"===u.confirmationStatus)return;break;case"finalized":case"max":case"root":if("processed"===u.confirmationStatus||"confirmed"===u.confirmationStatus)return}i=!0,o({__type:ls.PROCESSED,response:{context:n,value:u}})}})()}catch(t){s(t)}}))}}async confirmTransactionUsingBlockHeightExceedanceStrategy({commitment:t,strategy:{abortSignal:e,lastValidBlockHeight:r,signature:n}}){let i=!1;const o=new Promise((e=>{const n=async()=>{try{return await this.getBlockHeight(t)}catch(t){return-1}};(async()=>{let t=await n();if(!i){for(;t<=r;){if(await Es(1e3),i)return;if(t=await n(),i)return}e({__type:ls.BLOCKHEIGHT_EXCEEDED})}})()})),{abortConfirmation:s,confirmationPromise:a}=this.getTransactionConfirmationPromise({commitment:t,signature:n}),u=this.getCancellationPromise(e);let c;try{const t=await Promise.race([u,a,o]);if(t.__type!==ls.PROCESSED)throw new Yo(n);c=t.response}finally{i=!0,s()}return c}async confirmTransactionUsingDurableNonceStrategy({commitment:t,strategy:{abortSignal:e,minContextSlot:r,nonceAccountPubkey:n,nonceValue:i,signature:o}}){let s=!1;const a=new Promise((e=>{let o=i,a=null;const u=async()=>{try{const{context:e,value:i}=await this.getNonceAndContext(n,{commitment:t,minContextSlot:r});return a=e.slot,i?.nonce}catch(t){return o}};(async()=>{if(o=await u(),!s)for(;;){if(i!==o)return void e({__type:ls.NONCE_INVALID,slotInWhichNonceDidAdvance:a});if(await Es(2e3),s)return;if(o=await u(),s)return}})()})),{abortConfirmation:u,confirmationPromise:c}=this.getTransactionConfirmationPromise({commitment:t,signature:o}),h=this.getCancellationPromise(e);let l;try{const e=await Promise.race([h,c,a]);if(e.__type===ls.PROCESSED)l=e.response;else{let n;for(;;){const t=await this.getSignatureStatus(o);if(null==t)break;if(!(t.context.slot<(e.slotInWhichNonceDidAdvance??r))){n=t;break}await Es(400)}if(!n?.value)throw new Xo(o);{const e=t||"finalized",{confirmationStatus:r}=n.value;switch(e){case"processed":case"recent":if("processed"!==r&&"confirmed"!==r&&"finalized"!==r)throw new Xo(o);break;case"confirmed":case"single":case"singleGossip":if("confirmed"!==r&&"finalized"!==r)throw new Xo(o);break;case"finalized":case"max":case"root":if("finalized"!==r)throw new Xo(o)}l={context:n.context,value:{err:n.value.err}}}}}finally{s=!0,u()}return l}async confirmTransactionUsingLegacyTimeoutStrategy({commitment:t,signature:e}){let r;const n=new Promise((e=>{let n=this._confirmTransactionInitialTimeout||6e4;switch(t){case"processed":case"recent":case"single":case"confirmed":case"singleGossip":n=this._confirmTransactionInitialTimeout||3e4}r=setTimeout((()=>e({__type:ls.TIMED_OUT,timeoutMs:n})),n)})),{abortConfirmation:i,confirmationPromise:o}=this.getTransactionConfirmationPromise({commitment:t,signature:e});let s;try{const t=await Promise.race([o,n]);if(t.__type!==ls.PROCESSED)throw new Jo(e,t.timeoutMs/1e3);s=t.response}finally{clearTimeout(r),i()}return s}async getClusterNodes(){const t=_r(await this._rpcRequest("getClusterNodes",[]),oa(Er(Qa)));if("error"in t)throw new Vs(t.error,"failed to get cluster nodes");return t.result}async getVoteAccounts(t){const e=this._buildArgs([],t),r=_r(await this._rpcRequest("getVoteAccounts",e),eu);if("error"in r)throw new Vs(r.error,"failed to get vote accounts");return r.result}async getSlot(t){const{commitment:e,config:r}=ra(t),n=this._buildArgs([],e,void 0,r),i=_r(await this._rpcRequest("getSlot",n),oa(Tr()));if("error"in i)throw new Vs(i.error,"failed to get slot");return i.result}async getSlotLeader(t){const{commitment:e,config:r}=ra(t),n=this._buildArgs([],e,void 0,r),i=_r(await this._rpcRequest("getSlotLeader",n),oa(Cr()));if("error"in i)throw new Vs(i.error,"failed to get slot leader");return i.result}async getSlotLeaders(t,e){const r=[t,e],n=_r(await this._rpcRequest("getSlotLeaders",r),oa(Er(Qs)));if("error"in n)throw new Vs(n.error,"failed to get slot leaders");return n.result}async getSignatureStatus(t,e){const{context:r,value:n}=await this.getSignatureStatuses([t],e);ss(1===n.length);return{context:r,value:n[0]}}async getSignatureStatuses(t,e){const r=[t];e&&r.push(e);const n=_r(await this._rpcRequest("getSignatureStatuses",r),iu);if("error"in n)throw new Vs(n.error,"failed to get signature status");return n.result}async getTransactionCount(t){const{commitment:e,config:r}=ra(t),n=this._buildArgs([],e,void 0,r),i=_r(await this._rpcRequest("getTransactionCount",n),oa(Tr()));if("error"in i)throw new Vs(i.error,"failed to get transaction count");return i.result}async getTotalSupply(t){return(await this.getSupply({commitment:t,excludeNonCirculatingAccountsList:!0})).value.total}async getInflationGovernor(t){const e=this._buildArgs([],t),r=_r(await this._rpcRequest("getInflationGovernor",e),Sa);if("error"in r)throw new Vs(r.error,"failed to get inflation");return r.result}async getInflationReward(t,e,r){const{commitment:n,config:i}=ra(r),o=this._buildArgs([t.map((t=>t.toBase58()))],n,void 0,{...i,epoch:null!=e?e:i?.epoch}),s=_r(await this._rpcRequest("getInflationReward",o),ha);if("error"in s)throw new Vs(s.error,"failed to get inflation reward");return s.result}async getInflationRate(){const t=_r(await this._rpcRequest("getInflationRate",[]),_a);if("error"in t)throw new Vs(t.error,"failed to get inflation rate");return t.result}async getEpochInfo(t){const{commitment:e,config:r}=ra(t),n=this._buildArgs([],e,void 0,r),i=_r(await this._rpcRequest("getEpochInfo",n),Ma);if("error"in i)throw new Vs(i.error,"failed to get epoch info");return i.result}async getEpochSchedule(){const t=_r(await this._rpcRequest("getEpochSchedule",[]),Ia);if("error"in t)throw new Vs(t.error,"failed to get epoch schedule");const e=t.result;return new Fs(e.slotsPerEpoch,e.leaderScheduleSlotOffset,e.warmup,e.firstNormalEpoch,e.firstNormalSlot)}async getLeaderSchedule(){const t=_r(await this._rpcRequest("getLeaderSchedule",[]),Ea);if("error"in t)throw new Vs(t.error,"failed to get leader schedule");return t.result}async getMinimumBalanceForRentExemption(t,e){const r=this._buildArgs([t],e),n=_r(await this._rpcRequest("getMinimumBalanceForRentExemption",r),ou);return"error"in n?(console.warn("Unable to fetch minimum balance for rent exemption"),0):n.result}async getRecentBlockhashAndContext(t){const e=this._buildArgs([],t),r=_r(await this._rpcRequest("getRecentBlockhash",e),Pu);if("error"in r)throw new Vs(r.error,"failed to get recent blockhash");return r.result}async getRecentPerformanceSamples(t){const e=_r(await this._rpcRequest("getRecentPerformanceSamples",t?[t]:[]),Tu);if("error"in e)throw new Vs(e.error,"failed to get recent performance samples");return e.result}async getFeeCalculatorForBlockhash(t,e){const r=this._buildArgs([t],e),n=_r(await this._rpcRequest("getFeeCalculatorForBlockhash",r),Lu);if("error"in n)throw new Vs(n.error,"failed to get fee calculator");const{context:i,value:o}=n.result;return{context:i,value:null!==o?o.feeCalculator:null}}async getFeeForMessage(t,e){const r=Ko(t.serialize()).toString("base64"),n=this._buildArgs([r],e),i=_r(await this._rpcRequest("getFeeForMessage",n),sa(Rr(Tr())));if("error"in i)throw new Vs(i.error,"failed to get fee for message");if(null===i.result)throw new Error("invalid blockhash");return i.result}async getRecentPrioritizationFees(t){const e=t?.lockedWritableAccounts?.map((t=>t.toBase58())),r=this._buildArgs(e?.length?[e]:[]),n=_r(await this._rpcRequest("getRecentPrioritizationFees",r),Aa);if("error"in n)throw new Vs(n.error,"failed to get recent prioritization fees");return n.result}async getRecentBlockhash(t){try{return(await this.getRecentBlockhashAndContext(t)).value}catch(t){throw new Error("failed to get recent blockhash: "+t)}}async getLatestBlockhash(t){try{return(await this.getLatestBlockhashAndContext(t)).value}catch(t){throw new Error("failed to get recent blockhash: "+t)}}async getLatestBlockhashAndContext(t){const{commitment:e,config:r}=ra(t),n=this._buildArgs([],e,void 0,r),i=_r(await this._rpcRequest("getLatestBlockhash",n),Ru);if("error"in i)throw new Vs(i.error,"failed to get latest blockhash");return i.result}async getVersion(){const t=_r(await this._rpcRequest("getVersion",[]),oa(ba));if("error"in t)throw new Vs(t.error,"failed to get version");return t.result}async getGenesisHash(){const t=_r(await this._rpcRequest("getGenesisHash",[]),oa(Cr()));if("error"in t)throw new Vs(t.error,"failed to get genesis hash");return t.result}async getBlock(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgsAtLeastConfirmed([t],r,void 0,n),o=await this._rpcRequest("getBlock",i);try{switch(n?.transactionDetails){case"accounts":{const t=_r(o,Su);if("error"in t)throw t.error;return t.result}case"none":{const t=_r(o,ku);if("error"in t)throw t.error;return t.result}default:{const t=_r(o,vu);if("error"in t)throw t.error;const{result:e}=t;return e?{...e,transactions:e.transactions.map((({transaction:t,meta:e,version:r})=>({meta:e,transaction:{...t,message:ua(r,t.message)},version:r})))}:null}}}catch(t){throw new Vs(t,"failed to get confirmed block")}}async getParsedBlock(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgsAtLeastConfirmed([t],r,"jsonParsed",n),o=await this._rpcRequest("getBlock",i);try{switch(n?.transactionDetails){case"accounts":{const t=_r(o,Au);if("error"in t)throw t.error;return t.result}case"none":{const t=_r(o,Mu);if("error"in t)throw t.error;return t.result}default:{const t=_r(o,_u);if("error"in t)throw t.error;return t.result}}}catch(t){throw new Vs(t,"failed to get block")}}async getBlockProduction(t){let e,r;if("string"==typeof t)r=t;else if(t){const{commitment:n,...i}=t;r=n,e=i}const n=this._buildArgs([],r,"base64",e),i=_r(await this._rpcRequest("getBlockProduction",n),ka);if("error"in i)throw new Vs(i.error,"failed to get block production information");return i.result}async getTransaction(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgsAtLeastConfirmed([t],r,void 0,n),o=_r(await this._rpcRequest("getTransaction",i),xu);if("error"in o)throw new Vs(o.error,"failed to get transaction");const s=o.result;return s?{...s,transaction:{...s.transaction,message:ua(s.version,s.transaction.message)}}:s}async getParsedTransaction(t,e){const{commitment:r,config:n}=ra(e),i=this._buildArgsAtLeastConfirmed([t],r,"jsonParsed",n),o=_r(await this._rpcRequest("getTransaction",i),Bu);if("error"in o)throw new Vs(o.error,"failed to get transaction");return o.result}async getParsedTransactions(t,e){const{commitment:r,config:n}=ra(e),i=t.map((t=>({methodName:"getTransaction",args:this._buildArgsAtLeastConfirmed([t],r,"jsonParsed",n)})));return(await this._rpcBatchRequest(i)).map((t=>{const e=_r(t,Bu);if("error"in e)throw new Vs(e.error,"failed to get transactions");return e.result}))}async getTransactions(t,e){const{commitment:r,config:n}=ra(e),i=t.map((t=>({methodName:"getTransaction",args:this._buildArgsAtLeastConfirmed([t],r,void 0,n)})));return(await this._rpcBatchRequest(i)).map((t=>{const e=_r(t,xu);if("error"in e)throw new Vs(e.error,"failed to get transactions");const r=e.result;return r?{...r,transaction:{...r.transaction,message:ua(r.version,r.transaction.message)}}:r}))}async getConfirmedBlock(t,e){const r=this._buildArgsAtLeastConfirmed([t],e),n=_r(await this._rpcRequest("getConfirmedBlock",r),Iu);if("error"in n)throw new Vs(n.error,"failed to get confirmed block");const i=n.result;if(!i)throw new Error("Confirmed block "+t+" not found");const o={...i,transactions:i.transactions.map((({transaction:t,meta:e})=>{const r=new us(t.message);return{meta:e,transaction:{...t,message:r}}}))};return{...o,transactions:o.transactions.map((({transaction:t,meta:e})=>({meta:e,transaction:ps.populate(t.message,t.signatures)})))}}async getBlocks(t,e,r){const n=this._buildArgsAtLeastConfirmed(void 0!==e?[t,e]:[t],r),i=_r(await this._rpcRequest("getBlocks",n),oa(Er(Tr())));if("error"in i)throw new Vs(i.error,"failed to get blocks");return i.result}async getBlockSignatures(t,e){const r=this._buildArgsAtLeastConfirmed([t],e,void 0,{transactionDetails:"signatures",rewards:!1}),n=_r(await this._rpcRequest("getBlock",r),Eu);if("error"in n)throw new Vs(n.error,"failed to get block");const i=n.result;if(!i)throw new Error("Block "+t+" not found");return i}async getConfirmedBlockSignatures(t,e){const r=this._buildArgsAtLeastConfirmed([t],e,void 0,{transactionDetails:"signatures",rewards:!1}),n=_r(await this._rpcRequest("getConfirmedBlock",r),Eu);if("error"in n)throw new Vs(n.error,"failed to get confirmed block");const i=n.result;if(!i)throw new Error("Confirmed block "+t+" not found");return i}async getConfirmedTransaction(t,e){const r=this._buildArgsAtLeastConfirmed([t],e),n=_r(await this._rpcRequest("getConfirmedTransaction",r),xu);if("error"in n)throw new Vs(n.error,"failed to get transaction");const i=n.result;if(!i)return i;const o=new us(i.transaction.message),s=i.transaction.signatures;return{...i,transaction:ps.populate(o,s)}}async getParsedConfirmedTransaction(t,e){const r=this._buildArgsAtLeastConfirmed([t],e,"jsonParsed"),n=_r(await this._rpcRequest("getConfirmedTransaction",r),Bu);if("error"in n)throw new Vs(n.error,"failed to get confirmed transaction");return n.result}async getParsedConfirmedTransactions(t,e){const r=t.map((t=>({methodName:"getConfirmedTransaction",args:this._buildArgsAtLeastConfirmed([t],e,"jsonParsed")})));return(await this._rpcBatchRequest(r)).map((t=>{const e=_r(t,Bu);if("error"in e)throw new Vs(e.error,"failed to get confirmed transactions");return e.result}))}async getConfirmedSignaturesForAddress(t,e,r){let n={},i=await this.getFirstAvailableBlock();for(;!("until"in n)&&!(--e<=0||e<i);)try{const t=await this.getConfirmedBlockSignatures(e,"finalized");t.signatures.length>0&&(n.until=t.signatures[t.signatures.length-1].toString())}catch(t){if(t instanceof Error&&t.message.includes("skipped"))continue;throw t}let o=await this.getSlot("finalized");for(;!("before"in n||++r>o);)try{const t=await this.getConfirmedBlockSignatures(r);t.signatures.length>0&&(n.before=t.signatures[t.signatures.length-1].toString())}catch(t){if(t instanceof Error&&t.message.includes("skipped"))continue;throw t}return(await this.getConfirmedSignaturesForAddress2(t,n)).map((t=>t.signature))}async getConfirmedSignaturesForAddress2(t,e,r){const n=this._buildArgsAtLeastConfirmed([t.toBase58()],r,void 0,e),i=_r(await this._rpcRequest("getConfirmedSignaturesForAddress2",n),Da);if("error"in i)throw new Vs(i.error,"failed to get confirmed signatures for address");return i.result}async getSignaturesForAddress(t,e,r){const n=this._buildArgsAtLeastConfirmed([t.toBase58()],r,void 0,e),i=_r(await this._rpcRequest("getSignaturesForAddress",n),ja);if("error"in i)throw new Vs(i.error,"failed to get signatures for address");return i.result}async getAddressLookupTable(t,e){const{context:r,value:n}=await this.getAccountInfoAndContext(t,e);let i=null;return null!==n&&(i=new Ys({key:t,state:Ys.deserialize(n.data)})),{context:r,value:i}}async getNonceAndContext(t,e){const{context:r,value:n}=await this.getAccountInfoAndContext(t,e);let i=null;return null!==n&&(i=Ls.fromAccountData(n.data)),{context:r,value:i}}async getNonce(t,e){return await this.getNonceAndContext(t,e).then((t=>t.value)).catch((e=>{throw new Error("failed to get nonce for account "+t.toBase58()+": "+e)}))}async requestAirdrop(t,e){const r=_r(await this._rpcRequest("requestAirdrop",[t.toBase58(),e]),Ou);if("error"in r)throw new Vs(r.error,`airdrop to ${t.toBase58()} failed`);return r.result}async _blockhashWithExpiryBlockHeight(t){if(!t){for(;this._pollingBlockhash;)await Es(100);const t=Date.now()-this._blockhashInfo.lastFetch>=3e4;if(null!==this._blockhashInfo.latestBlockhash&&!t)return this._blockhashInfo.latestBlockhash}return await this._pollNewBlockhash()}async _pollNewBlockhash(){this._pollingBlockhash=!0;try{const t=Date.now(),e=this._blockhashInfo.latestBlockhash,r=e?e.blockhash:null;for(let t=0;t<50;t++){const t=await this.getLatestBlockhash("finalized");if(r!==t.blockhash)return this._blockhashInfo={latestBlockhash:t,lastFetch:Date.now(),transactionSignatures:[],simulatedSignatures:[]},t;await Es(200)}throw new Error(`Unable to obtain a new blockhash after ${Date.now()-t}ms`)}finally{this._pollingBlockhash=!1}}async getStakeMinimumDelegation(t){const{commitment:e,config:r}=ra(t),n=this._buildArgs([],e,"base64",r),i=_r(await this._rpcRequest("getStakeMinimumDelegation",n),sa(Tr()));if("error"in i)throw new Vs(i.error,"failed to get stake minimum delegation");return i.result}async simulateTransaction(t,r,n){if("message"in t){const i=t.serialize(),o=e.Buffer.from(i).toString("base64");if(Array.isArray(r)||void 0!==n)throw new Error("Invalid arguments");const s=r||{};s.encoding="base64","commitment"in s||(s.commitment=this.commitment);const a=[o,s],u=_r(await this._rpcRequest("simulateTransaction",a),va);if("error"in u)throw new Error("failed to simulate transaction: "+u.error.message);return u.result}let i;if(t instanceof ps){let e=t;i=new ps,i.feePayer=e.feePayer,i.instructions=t.instructions,i.nonceInfo=e.nonceInfo,i.signatures=e.signatures}else i=ps.populate(t),i._message=i._json=void 0;if(void 0!==r&&!Array.isArray(r))throw new Error("Invalid arguments");const o=r;if(i.nonceInfo&&o)i.sign(...o);else{let t=this._disableBlockhashCaching;for(;;){const e=await this._blockhashWithExpiryBlockHeight(t);if(i.lastValidBlockHeight=e.lastValidBlockHeight,i.recentBlockhash=e.blockhash,!o)break;if(i.sign(...o),!i.signature)throw new Error("!signature");const r=i.signature.toString("base64");if(!this._blockhashInfo.simulatedSignatures.includes(r)&&!this._blockhashInfo.transactionSignatures.includes(r)){this._blockhashInfo.simulatedSignatures.push(r);break}t=!0}}const s=i._compile(),a=s.serialize(),u=i._serialize(a).toString("base64"),c={encoding:"base64",commitment:this.commitment};if(n){const t=(Array.isArray(n)?n:s.nonProgramIds()).map((t=>t.toBase58()));c.accounts={encoding:"base64",addresses:t}}o&&(c.sigVerify=!0);const h=[u,c],l=_r(await this._rpcRequest("simulateTransaction",h),va);if("error"in l){let t;if("data"in l.error&&(t=l.error.data.logs,t&&Array.isArray(t))){const e="\n ",r=e+t.join(e);console.error(l.error.message,r)}throw new $s("failed to simulate transaction: "+l.error.message,t)}return l.result}async sendTransaction(t,e,r){if("version"in t){if(e&&Array.isArray(e))throw new Error("Invalid arguments");const r=t.serialize();return await this.sendRawTransaction(r,e)}if(void 0===e||!Array.isArray(e))throw new Error("Invalid arguments");const n=e;if(t.nonceInfo)t.sign(...n);else{let e=this._disableBlockhashCaching;for(;;){const r=await this._blockhashWithExpiryBlockHeight(e);if(t.lastValidBlockHeight=r.lastValidBlockHeight,t.recentBlockhash=r.blockhash,t.sign(...n),!t.signature)throw new Error("!signature");const i=t.signature.toString("base64");if(!this._blockhashInfo.transactionSignatures.includes(i)){this._blockhashInfo.transactionSignatures.push(i);break}e=!0}}const i=t.serialize();return await this.sendRawTransaction(i,r)}async sendRawTransaction(t,e){const r=Ko(t).toString("base64");return await this.sendEncodedTransaction(r,e)}async sendEncodedTransaction(t,e){const r={encoding:"base64"},n=e&&e.skipPreflight,i=e&&e.preflightCommitment||this.commitment;e&&null!=e.maxRetries&&(r.maxRetries=e.maxRetries),e&&null!=e.minContextSlot&&(r.minContextSlot=e.minContextSlot),n&&(r.skipPreflight=n),i&&(r.preflightCommitment=i);const o=[t,r],s=_r(await this._rpcRequest("sendTransaction",o),Cu);if("error"in s){let t;throw"data"in s.error&&(t=s.error.data.logs),new $s("failed to send transaction: "+s.error.message,t)}return s.result}_wsOnOpen(){this._rpcWebSocketConnected=!0,this._rpcWebSocketHeartbeat=setInterval((()=>{(async()=>{try{await this._rpcWebSocket.notify("ping")}catch{}})()}),5e3),this._updateSubscriptions()}_wsOnError(t){this._rpcWebSocketConnected=!1,console.error("ws error:",t.message)}_wsOnClose(t){this._rpcWebSocketConnected=!1,this._rpcWebSocketGeneration=(this._rpcWebSocketGeneration+1)%Number.MAX_SAFE_INTEGER,this._rpcWebSocketIdleTimeout&&(clearTimeout(this._rpcWebSocketIdleTimeout),this._rpcWebSocketIdleTimeout=null),this._rpcWebSocketHeartbeat&&(clearInterval(this._rpcWebSocketHeartbeat),this._rpcWebSocketHeartbeat=null),1e3!==t?(this._subscriptionCallbacksByServerSubscriptionId={},Object.entries(this._subscriptionsByHash).forEach((([t,e])=>{this._setSubscription(t,{...e,state:"pending"})}))):this._updateSubscriptions()}_setSubscription(t,e){const r=this._subscriptionsByHash[t]?.state;if(this._subscriptionsByHash[t]=e,r!==e.state){const r=this._subscriptionStateChangeCallbacksByHash[t];r&&r.forEach((t=>{try{t(e.state)}catch{}}))}}_onSubscriptionStateChange(t,e){var r;const n=this._subscriptionHashByClientSubscriptionId[t];if(null==n)return()=>{};const i=(r=this._subscriptionStateChangeCallbacksByHash)[n]||(r[n]=new Set);return i.add(e),()=>{i.delete(e),0===i.size&&delete this._subscriptionStateChangeCallbacksByHash[n]}}async _updateSubscriptions(){if(0===Object.keys(this._subscriptionsByHash).length)return void(this._rpcWebSocketConnected&&(this._rpcWebSocketConnected=!1,this._rpcWebSocketIdleTimeout=setTimeout((()=>{this._rpcWebSocketIdleTimeout=null;try{this._rpcWebSocket.close()}catch(t){t instanceof Error&&console.log(`Error when closing socket connection: ${t.message}`)}}),500)));if(null!==this._rpcWebSocketIdleTimeout&&(clearTimeout(this._rpcWebSocketIdleTimeout),this._rpcWebSocketIdleTimeout=null,this._rpcWebSocketConnected=!0),!this._rpcWebSocketConnected)return void this._rpcWebSocket.connect();const t=this._rpcWebSocketGeneration,e=()=>t===this._rpcWebSocketGeneration;await Promise.all(Object.keys(this._subscriptionsByHash).map((async t=>{const r=this._subscriptionsByHash[t];if(void 0!==r)switch(r.state){case"pending":case"unsubscribed":if(0===r.callbacks.size)return delete this._subscriptionsByHash[t],"unsubscribed"===r.state&&delete this._subscriptionCallbacksByServerSubscriptionId[r.serverSubscriptionId],void await this._updateSubscriptions();await(async()=>{const{args:n,method:i}=r;try{this._setSubscription(t,{...r,state:"subscribing"});const e=await this._rpcWebSocket.call(i,n);this._setSubscription(t,{...r,serverSubscriptionId:e,state:"subscribed"}),this._subscriptionCallbacksByServerSubscriptionId[e]=r.callbacks,await this._updateSubscriptions()}catch(o){if(o instanceof Error&&console.error(`${i} error for argument`,n,o.message),!e())return;this._setSubscription(t,{...r,state:"pending"}),await this._updateSubscriptions()}})();break;case"subscribed":0===r.callbacks.size&&await(async()=>{const{serverSubscriptionId:n,unsubscribeMethod:i}=r;if(this._subscriptionsAutoDisposedByRpc.has(n))this._subscriptionsAutoDisposedByRpc.delete(n);else{this._setSubscription(t,{...r,state:"unsubscribing"}),this._setSubscription(t,{...r,state:"unsubscribing"});try{await this._rpcWebSocket.call(i,[n])}catch(n){if(n instanceof Error&&console.error(`${i} error:`,n.message),!e())return;return this._setSubscription(t,{...r,state:"subscribed"}),void await this._updateSubscriptions()}}this._setSubscription(t,{...r,state:"unsubscribed"}),await this._updateSubscriptions()})()}})))}_handleServerNotification(t,e){const r=this._subscriptionCallbacksByServerSubscriptionId[t];void 0!==r&&r.forEach((t=>{try{t(...e)}catch(t){console.error(t)}}))}_wsOnAccountNotification(t){const{result:e,subscription:r}=_r(t,Ha);this._handleServerNotification(r,[e.value,e.context])}_makeSubscription(t,e){const r=this._nextClientSubscriptionId++,n=js([t.method,e]),i=this._subscriptionsByHash[n];return void 0===i?this._subscriptionsByHash[n]={...t,args:e,callbacks:new Set([t.callback]),state:"pending"}:i.callbacks.add(t.callback),this._subscriptionHashByClientSubscriptionId[r]=n,this._subscriptionDisposeFunctionsByClientSubscriptionId[r]=async()=>{delete this._subscriptionDisposeFunctionsByClientSubscriptionId[r],delete this._subscriptionHashByClientSubscriptionId[r];const e=this._subscriptionsByHash[n];ss(void 0!==e,`Could not find a \`Subscription\` when tearing down client subscription #${r}`),e.callbacks.delete(t.callback),await this._updateSubscriptions()},this._updateSubscriptions(),r}onAccountChange(t,e,r){const n=this._buildArgs([t.toBase58()],r||this._commitment||"finalized","base64");return this._makeSubscription({callback:e,method:"accountSubscribe",unsubscribeMethod:"accountUnsubscribe"},n)}async removeAccountChangeListener(t){await this._unsubscribeClientSubscription(t,"account change")}_wsOnProgramAccountNotification(t){const{result:e,subscription:r}=_r(t,$a);this._handleServerNotification(r,[{accountId:e.value.pubkey,accountInfo:e.value.account},e.context])}onProgramAccountChange(t,e,r,n){const i=this._buildArgs([t.toBase58()],r||this._commitment||"finalized","base64",n?{filters:n}:void 0);return this._makeSubscription({callback:e,method:"programSubscribe",unsubscribeMethod:"programUnsubscribe"},i)}async removeProgramAccountChangeListener(t){await this._unsubscribeClientSubscription(t,"program account change")}onLogs(t,e,r){const n=this._buildArgs(["object"==typeof t?{mentions:[t.toString()]}:t],r||this._commitment||"finalized");return this._makeSubscription({callback:e,method:"logsSubscribe",unsubscribeMethod:"logsUnsubscribe"},n)}async removeOnLogsListener(t){await this._unsubscribeClientSubscription(t,"logs")}_wsOnLogsNotification(t){const{result:e,subscription:r}=_r(t,Nu);this._handleServerNotification(r,[e.value,e.context])}_wsOnSlotNotification(t){const{result:e,subscription:r}=_r(t,Ga);this._handleServerNotification(r,[e])}onSlotChange(t){return this._makeSubscription({callback:t,method:"slotSubscribe",unsubscribeMethod:"slotUnsubscribe"},[])}async removeSlotChangeListener(t){await this._unsubscribeClientSubscription(t,"slot change")}_wsOnSlotUpdatesNotification(t){const{result:e,subscription:r}=_r(t,Ya);this._handleServerNotification(r,[e])}onSlotUpdate(t){return this._makeSubscription({callback:t,method:"slotsUpdatesSubscribe",unsubscribeMethod:"slotsUpdatesUnsubscribe"},[])}async removeSlotUpdateListener(t){await this._unsubscribeClientSubscription(t,"slot update")}async _unsubscribeClientSubscription(t,e){const r=this._subscriptionDisposeFunctionsByClientSubscriptionId[t];r?await r():console.warn(`Ignored unsubscribe request because an active subscription with id \`${t}\` for '${e}' events could not be found.`)}_buildArgs(t,e,r,n){const i=e||this._commitment;if(i||r||n){let e={};r&&(e.encoding=r),i&&(e.commitment=i),n&&(e=Object.assign(e,n)),t.push(e)}return t}_buildArgsAtLeastConfirmed(t,e,r,n){const i=e||this._commitment;if(i&&!["confirmed","finalized"].includes(i))throw new Error("Using Connection with default commitment: `"+this._commitment+"`, but method requires at least `confirmed`");return this._buildArgs(t,e,r,n)}_wsOnSignatureNotification(t){const{result:e,subscription:r}=_r(t,Ja);"receivedSignature"!==e.value&&this._subscriptionsAutoDisposedByRpc.add(r),this._handleServerNotification(r,"receivedSignature"===e.value?[{type:"received"},e.context]:[{type:"status",result:e.value},e.context])}onSignature(t,e,r){const n=this._buildArgs([t],r||this._commitment||"finalized"),i=this._makeSubscription({callback:(t,r)=>{if("status"===t.type){e(t.result,r);try{this.removeSignatureListener(i)}catch(t){}}},method:"signatureSubscribe",unsubscribeMethod:"signatureUnsubscribe"},n);return i}onSignatureWithOptions(t,e,r){const{commitment:n,...i}={...r,commitment:r&&r.commitment||this._commitment||"finalized"},o=this._buildArgs([t],n,void 0,i),s=this._makeSubscription({callback:(t,r)=>{e(t,r);try{this.removeSignatureListener(s)}catch(t){}},method:"signatureSubscribe",unsubscribeMethod:"signatureUnsubscribe"},o);return s}async removeSignatureListener(t){await this._unsubscribeClientSubscription(t,"signature result")}_wsOnRootNotification(t){const{result:e,subscription:r}=_r(t,Xa);this._handleServerNotification(r,[e])}onRootChange(t){return this._makeSubscription({callback:t,method:"rootSubscribe",unsubscribeMethod:"rootUnsubscribe"},[])}async removeRootChangeListener(t){await this._unsubscribeClientSubscription(t,"root change")}},Ed25519Program:Fu,Enum:class extends Wo{constructor(t){if(super(t),this.enum="",1!==Object.keys(t).length)throw new Error("Enum can only take single value");Object.keys(t).map((t=>{this.enum=t}))}},EpochSchedule:Fs,FeeCalculatorLayout:Ps,Keypair:Ku,LAMPORTS_PER_SOL:1e9,LOOKUP_TABLE_INSTRUCTION_LAYOUTS:Wu,Loader:zs,Lockup:Ju,MAX_SEED_LENGTH:32,Message:us,MessageAccountKeys:Qo,MessageV0:cs,NONCE_ACCOUNT_LENGTH:Ts,NonceAccount:Ls,PACKET_DATA_SIZE:Vo,PUBLIC_KEY_LENGTH:jo,PublicKey:Fo,SIGNATURE_LENGTH_IN_BYTES:Zo,SOLANA_SCHEMA:qo,STAKE_CONFIG_ID:Zu,STAKE_INSTRUCTION_LAYOUTS:Xu,SYSTEM_INSTRUCTION_LAYOUTS:Us,SYSVAR_CLOCK_PUBKEY:ys,SYSVAR_EPOCH_SCHEDULE_PUBKEY:ws,SYSVAR_INSTRUCTIONS_PUBKEY:bs,SYSVAR_RECENT_BLOCKHASHES_PUBKEY:vs,SYSVAR_RENT_PUBKEY:ks,SYSVAR_REWARDS_PUBKEY:Ss,SYSVAR_SLOT_HASHES_PUBKEY:_s,SYSVAR_SLOT_HISTORY_PUBKEY:As,SYSVAR_STAKE_HISTORY_PUBKEY:Ms,Secp256k1Program:Gu,SendTransactionError:$s,SolanaJSONRPCError:Vs,SolanaJSONRPCErrorCode:{JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP:-32001,JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE:-32002,JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE:-32003,JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE:-32004,JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY:-32005,JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE:-32006,JSON_RPC_SERVER_ERROR_SLOT_SKIPPED:-32007,JSON_RPC_SERVER_ERROR_NO_SNAPSHOT:-32008,JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED:-32009,JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX:-32010,JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE:-32011,JSON_RPC_SCAN_ERROR:-32012,JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH:-32013,JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET:-32014,JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION:-32015,JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED:-32016},StakeAuthorizationLayout:Qu,StakeInstruction:class{constructor(){}static decodeInstructionType(t){this.checkProgramId(t.programId);const e=or("instruction").decode(t.data);let r;for(const[t,n]of Object.entries(Xu))if(n.index==e){r=t;break}if(!r)throw new Error("Instruction type incorrect; not a StakeInstruction");return r}static decodeInitialize(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,2);const{authorized:e,lockup:r}=Bs(Xu.Initialize,t.data);return{stakePubkey:t.keys[0].pubkey,authorized:new Yu(new Fo(e.staker),new Fo(e.withdrawer)),lockup:new Ju(r.unixTimestamp,r.epoch,new Fo(r.custodian))}}static decodeDelegate(t){return this.checkProgramId(t.programId),this.checkKeyLength(t.keys,6),Bs(Xu.Delegate,t.data),{stakePubkey:t.keys[0].pubkey,votePubkey:t.keys[1].pubkey,authorizedPubkey:t.keys[5].pubkey}}static decodeAuthorize(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{newAuthorized:e,stakeAuthorizationType:r}=Bs(Xu.Authorize,t.data),n={stakePubkey:t.keys[0].pubkey,authorizedPubkey:t.keys[2].pubkey,newAuthorizedPubkey:new Fo(e),stakeAuthorizationType:{index:r}};return t.keys.length>3&&(n.custodianPubkey=t.keys[3].pubkey),n}static decodeAuthorizeWithSeed(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,2);const{newAuthorized:e,stakeAuthorizationType:r,authoritySeed:n,authorityOwner:i}=Bs(Xu.AuthorizeWithSeed,t.data),o={stakePubkey:t.keys[0].pubkey,authorityBase:t.keys[1].pubkey,authoritySeed:n,authorityOwner:new Fo(i),newAuthorizedPubkey:new Fo(e),stakeAuthorizationType:{index:r}};return t.keys.length>3&&(o.custodianPubkey=t.keys[3].pubkey),o}static decodeSplit(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{lamports:e}=Bs(Xu.Split,t.data);return{stakePubkey:t.keys[0].pubkey,splitStakePubkey:t.keys[1].pubkey,authorizedPubkey:t.keys[2].pubkey,lamports:e}}static decodeMerge(t){return this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3),Bs(Xu.Merge,t.data),{stakePubkey:t.keys[0].pubkey,sourceStakePubKey:t.keys[1].pubkey,authorizedPubkey:t.keys[4].pubkey}}static decodeWithdraw(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,5);const{lamports:e}=Bs(Xu.Withdraw,t.data),r={stakePubkey:t.keys[0].pubkey,toPubkey:t.keys[1].pubkey,authorizedPubkey:t.keys[4].pubkey,lamports:e};return t.keys.length>5&&(r.custodianPubkey=t.keys[5].pubkey),r}static decodeDeactivate(t){return this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3),Bs(Xu.Deactivate,t.data),{stakePubkey:t.keys[0].pubkey,authorizedPubkey:t.keys[2].pubkey}}static checkProgramId(t){if(!t.equals(tc.programId))throw new Error("invalid instruction; programId is not StakeProgram")}static checkKeyLength(t,e){if(t.length<e)throw new Error(`invalid instruction; found ${t.length} keys, expected at least ${e}`)}},StakeProgram:tc,Struct:Wo,SystemInstruction:class{constructor(){}static decodeInstructionType(t){this.checkProgramId(t.programId);const e=or("instruction").decode(t.data);let r;for(const[t,n]of Object.entries(Us))if(n.index==e){r=t;break}if(!r)throw new Error("Instruction type incorrect; not a SystemInstruction");return r}static decodeCreateAccount(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,2);const{lamports:e,space:r,programId:n}=Bs(Us.Create,t.data);return{fromPubkey:t.keys[0].pubkey,newAccountPubkey:t.keys[1].pubkey,lamports:e,space:r,programId:new Fo(n)}}static decodeTransfer(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,2);const{lamports:e}=Bs(Us.Transfer,t.data);return{fromPubkey:t.keys[0].pubkey,toPubkey:t.keys[1].pubkey,lamports:e}}static decodeTransferWithSeed(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{lamports:e,seed:r,programId:n}=Bs(Us.TransferWithSeed,t.data);return{fromPubkey:t.keys[0].pubkey,basePubkey:t.keys[1].pubkey,toPubkey:t.keys[2].pubkey,lamports:e,seed:r,programId:new Fo(n)}}static decodeAllocate(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,1);const{space:e}=Bs(Us.Allocate,t.data);return{accountPubkey:t.keys[0].pubkey,space:e}}static decodeAllocateWithSeed(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,1);const{base:e,seed:r,space:n,programId:i}=Bs(Us.AllocateWithSeed,t.data);return{accountPubkey:t.keys[0].pubkey,basePubkey:new Fo(e),seed:r,space:n,programId:new Fo(i)}}static decodeAssign(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,1);const{programId:e}=Bs(Us.Assign,t.data);return{accountPubkey:t.keys[0].pubkey,programId:new Fo(e)}}static decodeAssignWithSeed(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,1);const{base:e,seed:r,programId:n}=Bs(Us.AssignWithSeed,t.data);return{accountPubkey:t.keys[0].pubkey,basePubkey:new Fo(e),seed:r,programId:new Fo(n)}}static decodeCreateWithSeed(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,2);const{base:e,seed:r,lamports:n,space:i,programId:o}=Bs(Us.CreateWithSeed,t.data);return{fromPubkey:t.keys[0].pubkey,newAccountPubkey:t.keys[1].pubkey,basePubkey:new Fo(e),seed:r,lamports:n,space:i,programId:new Fo(o)}}static decodeNonceInitialize(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{authorized:e}=Bs(Us.InitializeNonceAccount,t.data);return{noncePubkey:t.keys[0].pubkey,authorizedPubkey:new Fo(e)}}static decodeNonceAdvance(t){return this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3),Bs(Us.AdvanceNonceAccount,t.data),{noncePubkey:t.keys[0].pubkey,authorizedPubkey:t.keys[2].pubkey}}static decodeNonceWithdraw(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,5);const{lamports:e}=Bs(Us.WithdrawNonceAccount,t.data);return{noncePubkey:t.keys[0].pubkey,toPubkey:t.keys[1].pubkey,authorizedPubkey:t.keys[4].pubkey,lamports:e}}static decodeNonceAuthorize(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,2);const{authorized:e}=Bs(Us.AuthorizeNonceAccount,t.data);return{noncePubkey:t.keys[0].pubkey,authorizedPubkey:t.keys[1].pubkey,newAuthorizedPubkey:new Fo(e)}}static checkProgramId(t){if(!t.equals(Ns.programId))throw new Error("invalid instruction; programId is not SystemProgram")}static checkKeyLength(t,e){if(t.length<e)throw new Error(`invalid instruction; found ${t.length} keys, expected at least ${e}`)}},SystemProgram:Ns,Transaction:ps,TransactionExpiredBlockheightExceededError:Yo,TransactionExpiredNonceInvalidError:Xo,TransactionExpiredTimeoutError:Jo,TransactionInstruction:fs,TransactionMessage:ms,get TransactionStatus(){return ls},VALIDATOR_INFO_KEY:oc,VERSION_PREFIX_MASK:Go,VOTE_PROGRAM_ID:uc,ValidatorInfo:ac,VersionedMessage:hs,VersionedTransaction:gs,VoteAccount:hc,VoteAuthorizationLayout:nc,VoteInit:ec,VoteInstruction:class{constructor(){}static decodeInstructionType(t){this.checkProgramId(t.programId);const e=or("instruction").decode(t.data);let r;for(const[t,n]of Object.entries(rc))if(n.index==e){r=t;break}if(!r)throw new Error("Instruction type incorrect; not a VoteInstruction");return r}static decodeInitializeAccount(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,4);const{voteInit:e}=Bs(rc.InitializeAccount,t.data);return{votePubkey:t.keys[0].pubkey,nodePubkey:t.keys[3].pubkey,voteInit:new ec(new Fo(e.nodePubkey),new Fo(e.authorizedVoter),new Fo(e.authorizedWithdrawer),e.commission)}}static decodeAuthorize(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{newAuthorized:e,voteAuthorizationType:r}=Bs(rc.Authorize,t.data);return{votePubkey:t.keys[0].pubkey,authorizedPubkey:t.keys[2].pubkey,newAuthorizedPubkey:new Fo(e),voteAuthorizationType:{index:r}}}static decodeAuthorizeWithSeed(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{voteAuthorizeWithSeedArgs:{currentAuthorityDerivedKeyOwnerPubkey:e,currentAuthorityDerivedKeySeed:r,newAuthorized:n,voteAuthorizationType:i}}=Bs(rc.AuthorizeWithSeed,t.data);return{currentAuthorityDerivedKeyBasePubkey:t.keys[2].pubkey,currentAuthorityDerivedKeyOwnerPubkey:new Fo(e),currentAuthorityDerivedKeySeed:r,newAuthorizedPubkey:new Fo(n),voteAuthorizationType:{index:i},votePubkey:t.keys[0].pubkey}}static decodeWithdraw(t){this.checkProgramId(t.programId),this.checkKeyLength(t.keys,3);const{lamports:e}=Bs(rc.Withdraw,t.data);return{votePubkey:t.keys[0].pubkey,authorizedWithdrawerPubkey:t.keys[2].pubkey,lamports:e,toPubkey:t.keys[1].pubkey}}static checkProgramId(t){if(!t.equals(ic.programId))throw new Error("invalid instruction; programId is not VoteProgram")}static checkKeyLength(t,e){if(t.length<e)throw new Error(`invalid instruction; found ${t.length} keys, expected at least ${e}`)}},VoteProgram:ic,clusterApiUrl:function(t,e){const r=!1===e?"http":"https";if(!t)return pc[r].devnet;const n=pc[r][t];if(!n)throw new Error(`Unknown ${r} cluster: ${t}`);return n},sendAndConfirmRawTransaction:async function(t,e,r,n){let i,o;r&&Object.prototype.hasOwnProperty.call(r,"lastValidBlockHeight")||r&&Object.prototype.hasOwnProperty.call(r,"nonceValue")?(i=r,o=n):o=r;const s=o&&{skipPreflight:o.skipPreflight,preflightCommitment:o.preflightCommitment||o.commitment,minContextSlot:o.minContextSlot},a=await t.sendRawTransaction(e,s),u=o&&o.commitment,c=i?t.confirmTransaction(i,u):t.confirmTransaction(a,u),h=(await c).value;if(h.err)throw new Error(`Raw transaction ${a} failed (${JSON.stringify(h)})`);return a},sendAndConfirmTransaction:Is}),gc=t.getAugmentedNamespace(mc);!function(e,r){t.commonjsGlobal,e.exports=function(){function e(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function r(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}function n(t,e){if(!t)throw new Error(e)}const i={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545",137:"https://rpc-mainnet.maticvigil.com/",80001:"https://rpc-mumbai.matic.today/",43114:"https://api.avax.network/ext/bc/C/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",42161:"https://arb1.arbitrum.io/rpc",421613:"https://endpoints.omniatech.io/v1/arbitrum/goerli/public",10:"https://mainnet.optimism.io",420:"https://goerli.optimism.io"},o={1:"ethereum",5:"ethereum",56:"bsc",97:"bsc",137:"polygon",80001:"polygon",43114:"avalanche",43113:"avalanche",42161:"arbitrum",421613:"arbitrum",10:"optimism",420:"optimism"},s={1:"mainnet",5:"testnet",56:"mainnet",97:"testnet",137:"mainnet",80001:"testnet",43114:"mainnet",43113:"testnet",42161:"mainnet",421613:"testnet",10:"mainnet",420:"testnet"},a={1:"https://wallet-v2.blocto.app",5:"https://wallet-v2-dev.blocto.app",56:"https://wallet-v2.blocto.app",97:"https://wallet-v2-dev.blocto.app",137:"https://wallet-v2.blocto.app",80001:"https://wallet-v2-dev.blocto.app",43114:"https://wallet-v2.blocto.app",43113:"https://wallet-v2-dev.blocto.app",42161:"https://wallet-v2.blocto.app",421613:"https://wallet-v2-dev.blocto.app",10:"https://wallet-v2.blocto.app",420:"https://wallet-v2-dev.blocto.app"},u={prod:"https://wallet-v2.blocto.app",staging:"https://wallet-v2-staging.blocto.app",dev:"https://wallet-v2-dev.blocto.app"},c={devnet:"https://wallet-v2-dev.blocto.app",testnet:"https://wallet-v2-dev.blocto.app","mainnet-beta":"https://wallet-v2.blocto.app"},h=["devnet","testnet","mainnet-beta"],l={1:"https://wallet-v2.blocto.app",2:"https://wallet-v2-dev.blocto.app",3:"https://wallet-v2-dev.blocto.app",4:"https://wallet-v2-dev.blocto.app",5:"https://wallet-v2-staging.blocto.app"};var d;!function(t){t.Mainnet="mainnet",t.Testnet="testnet",t.Devnet="devnet",t.Testing="testing",t.Premainnet="premainnet"}(d||(d={}));const f={1:d.Mainnet,2:d.Testnet,3:d.Devnet,4:d.Testing,5:d.Premainnet},p={1:"https://fullnode.mainnet.aptoslabs.com/v1",2:"https://fullnode.testnet.aptoslabs.com/v1",3:"https://fullnode.devnet.aptoslabs.com/v1",4:"",5:"https://premainnet.aptosdev.com/v1"},m=["connect","disconnect","message","chainChanged","accountsChanged"],g=864e5,y="00000000-0000-0000-0000-000000000000",w="sdk.session",b="undefined"!=typeof window?window.memoryStorage:new class{constructor(){this.storage={}}getItem(t){return this[t]||null}setItem(t,e){this.storage[t]=e}removeItem(t){delete this.storage[t]}};"undefined"!=typeof window&&(window.memoryStorage=b);const v=(()=>{if("undefined"==typeof window)return!1;try{window.localStorage.setItem("local_storage_supported","1");const t=window.localStorage.getItem("local_storage_supported");return window.localStorage.removeItem("local_storage_supported"),"1"===t}catch(t){return!1}})()?window.localStorage:b,k=(t,e=null)=>{const r=((t,e=null)=>{const r=v.getItem(t);try{return r&&JSON.parse(r)||e}catch(t){return r||e}})(t,null);return r?(new Date).getTime()>r.expiry?(A(t),e):r.value:e},S=(t,e)=>v.setItem(t,"string"==typeof e?e:JSON.stringify(e)),_=(t,e,r)=>S(t,{value:e,expiry:(new Date).getTime()+r}),A=t=>{S(t,""),v.removeItem(t)};class M{constructor(t){this.isBlocto=!0,this.isConnecting=!1,this.eventListeners={},this.sessionKey=w,this.off=this.removeListener,this.session=t,m.forEach((t=>{this.eventListeners[t]=[]}))}formatAndSetSessionAccount(t={}){this.session.accounts=Object.keys(t).reduce(((e,r)=>(e[r]=[t[r]],e)),{})}tryRetrieveSessionFromStorage(t){const e=k(this.sessionKey,{}),r=e&&e.code,n=e&&e.address&&e.address[t];this.session.connected=Boolean(r&&n),this.session.code=r||null,this.formatAndSetSessionAccount(e?e.address:{})}request(t){return e(this,void 0,void 0,(function*(){}))}on(t,e){m.includes(t)&&this.eventListeners[t].push(e)}once(){}removeListener(t,e){const r=this.eventListeners[t].findIndex((t=>t===e));-1!==r&&this.eventListeners[t].splice(r,1)}}function I(t){const e=document.createElement("iframe");return e.setAttribute("src",t),e.setAttribute("style","width:100vw;height:100%;position:fixed;top:0;left:0;z-index:2147483646;border:none;"),e}function E(t){document.body.appendChild(t)}function x(t){const e=t&&t.parentNode;e&&e.removeChild instanceof Function&&e.removeChild(t)}var B=(t,e,r=window)=>{r.addEventListener(t,(function n(i){e(i,(()=>r.removeEventListener(t,n)))}))};function P(t,r){return e(this,void 0,void 0,(function*(){if(403===t.status)throw r.session.code=null,A(r.sessionKey),new Error("[Blocto SDK]: Session expired!");return t.json()}))}const R=t=>/\S+@\S+\.\S+/.test(t);function T(){return e(this,void 0,void 0,(function*(){const{networks:t}=yield fetch("https://api.blocto.app/networks/evm").then((t=>t.json()));return t.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.chain_id]:e})),{})}))}var L,O,C;function U(t){return t?"number"==typeof t?t:t.startsWith("0x")?parseInt(t,16):parseInt(t,10):1}class N extends M{constructor({chainId:t,rpc:e,server:r,appId:u,session:c}){super(c),L.add(this),this.supportNetwork={},this.switchableNetwork={},n(t,"'chainId' is required"),this.chainId=U(t),this.networkId=this.chainId,this.chain=o[this.chainId],this.net=s[this.chainId],n(this.chain,`unsupported 'chainId': ${this.chainId}`),this.rpc=e||i[this.chainId]||"",n(this.rpc,"'rpc' is required for Ethereum"),this.server=r||a[this.chainId]||"",this.appId=u||y,this.switchableNetwork[this.chainId]={name:this.chain,display_name:this.chain,network_type:this.net,wallet_web_url:this.server,rpc_url:this.rpc}}loadSwitchableNetwork(t){return e(this,void 0,void 0,(function*(){return T().then((e=>(this.supportNetwork=e,(null==t?void 0:t.length)&&t.forEach((({chainId:t,rpcUrls:e})=>{if(n(e,"rpcUrls is required for networksList"),!(null==e?void 0:e.length))throw new Error("Empty rpcUrls array");r(this,L,"m",O).call(this,{chainId:U(t),rpcUrls:e})})),null)))}))}send(t,r){return e(this,void 0,void 0,(function*(){switch(!0){case r instanceof Function:return this.sendAsync(t,r);case"string"==typeof t&&Array.isArray(r):return this.sendAsync({jsonrpc:"2.0",method:t,params:r});default:return this.sendAsync(t)}}))}sendAsync(t,r){return e(this,void 0,void 0,(function*(){const e=new Promise((e=>{if(Array.isArray(t)){const r=t.filter((t=>"eth_sendTransaction"===t.method)).map((t=>{var e;return null===(e=t.params)||void 0===e?void 0:e[0]})),n=Math.floor(1e4*Math.random()),i={method:"blocto_sendBatchTransaction",params:r},o=this.request(i),s=t.map((({method:t,params:e},r)=>"eth_sendTransaction"===t?o:this.request({id:n+r+1,jsonrpc:"2.0",method:t,params:e})));Promise.allSettled(s).then((r=>e(r.map(((e,r)=>({id:String(n+r+1),jsonrpc:"2.0",method:t[r].method,result:"fulfilled"===e.status?e.value:void 0,error:"fulfilled"!==e.status?e.reason:void 0}))))))}else this.request(Object.assign(Object.assign({},t),{id:Number(t.id)})).then(e)}));if(!r)return e;e.then((t=>r(null,t))).catch((t=>r(t)))}))}request(t){var i,o,s,a,u,c,h;return e(this,void 0,void 0,(function*(){const e=window.ethereum;if(e&&e.isBlocto)return e.request(t);if(!this.session.connected){const e=null===(i=null==t?void 0:t.params)||void 0===i?void 0:i[0];"eth_requestAccounts"===t.method&&R(e)?yield this.enable(e):yield this.enable()}try{let e=null,i=null;switch(t.method){case"eth_requestAccounts":yield this.fetchAccounts();case"eth_accounts":i=this.session.accounts[this.chain];break;case"eth_coinbase":i=this.session.accounts[this.chain][0];break;case"eth_chainId":i=this.chainId,i=`0x${i.toString(16)}`;break;case"net_version":i=this.networkId||this.chainId,i=`0x${i.toString(16)}`;break;case"eth_signTypedData_v3":case"eth_signTypedData":case"eth_signTypedData_v4":case"personal_sign":case"eth_sign":i=yield this.handleSign(t);break;case"wallet_disconnect":this.handleDisconnect(),i=null;break;case"blocto_sendBatchTransaction":case"eth_sendTransaction":i=yield this.handleSendTransaction(t);break;case"eth_signTransaction":case"eth_sendRawTransaction":i=null;break;case"wallet_addEthereumChain":if(!(null===(s=null===(o=null==t?void 0:t.params)||void 0===o?void 0:o[0])||void 0===s?void 0:s.chainId)||!(null===(u=null===(a=null==t?void 0:t.params)||void 0===a?void 0:a[0])||void 0===u?void 0:u.rpcUrls.length))throw new Error("Invalid params");yield T().then((e=>{var n,i,o;this.supportNetwork=e,r(this,L,"m",O).call(this,{chainId:U(null===(i=null===(n=null==t?void 0:t.params)||void 0===n?void 0:n[0])||void 0===i?void 0:i.chainId),rpcUrls:null===(o=null==t?void 0:t.params)||void 0===o?void 0:o[0].rpcUrls})})),i=null;break;case"wallet_switchEthereumChain":if(!(null===(h=null===(c=null==t?void 0:t.params)||void 0===c?void 0:c[0])||void 0===h?void 0:h.chainId))throw new Error("Invalid params");if(!this.switchableNetwork[U(t.params[0].chainId)]){const t=new Error("This chain has not been added to SDK. Please try wallet_addEthereumChain first.");throw t.code=4902,t}this.chainId=U(t.params[0].chainId),this.networkId=this.chainId,this.chain=this.switchableNetwork[this.chainId].name,this.net=this.switchableNetwork[this.chainId].network_type,n(this.chain,`unsupported 'chainId': ${this.chainId}`),this.rpc=this.switchableNetwork[this.chainId].rpc_url,n(this.rpc,"'rpc' is required"),this.server=this.switchableNetwork[this.chainId].wallet_web_url,yield this.fetchAccounts(),this.eventListeners.chainChanged.forEach((t=>t(this.chainId))),i=null;break;default:e=yield this.handleReadRequests(t)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw new Error(t)}return e?e.result:i}catch(e){throw console.error(e),e}}))}enable(t){return e(this,void 0,void 0,(function*(){const e=window.ethereum;if(e&&e.isBlocto){if(parseInt(e.chainId,16)!==this.chainId)try{yield e.request({method:"wallet_addEthereumChain",params:[{chainId:`0x${this.chainId.toString(16)}`}]}),this.session.accounts[this.chain]=[e.address]}catch(e){console.error(e)}return new Promise(((t,r)=>setTimeout((()=>e.enable().then(t).catch(r)),10)))}return this.tryRetrieveSessionFromStorage(this.chain),new Promise(((e,r)=>{if("undefined"==typeof window)return r("Currently only supported in browser");if(this.session.connected)return e(this.session.accounts[this.chain]);const n=new URLSearchParams;n.set("l6n",window.location.origin);const i=t&&R(t)?`/${t}`:"",o=I(`${this.server}/${this.appId}/${this.chain}/authn${i}?${n.toString()}`);E(o),B("message",((t,n)=>{const i=t;if(i.origin===this.server){if("ETH:FRAME:RESPONSE"===i.data.type){n(),x(o),this.session.code=i.data.code,this.session.connected=!0,this.eventListeners.connect.forEach((t=>t(this.chainId)));const t=i.data.address;this.formatAndSetSessionAccount(t),_(this.sessionKey,{code:this.session.code,address:t},g),e(this.session.accounts[this.chain])}"ETH:FRAME:CLOSE"===i.data.type&&(n(),x(o),r(new Error("User declined the login request")))}}))}))}))}fetchAccounts(){return e(this,void 0,void 0,(function*(){r(this,L,"m",C).call(this);const{accounts:t}=yield fetch(`${this.server}/api/${this.chain}/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>P(t,this)));return this.session.accounts[this.chain]=t,t}))}handleReadRequests(t){return e(this,void 0,void 0,(function*(){return r(this,L,"m",C).call(this),fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then((t=>t.json()))}))}handleSign({method:t,params:n}){return e(this,void 0,void 0,(function*(){let e="";if(Array.isArray(n))if("eth_sign"===t)e=n[1].slice(2);else if("personal_sign"===t)e=n[0].slice(2);else if(["eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4"].includes(t)){e=n[1];const{domain:t}=JSON.parse(e);if(U(t.chainId)!==U(this.chainId))throw new Error(`Provided chainId "${t.chainId}" must match the active chainId "${this.chainId}"`)}r(this,L,"m",C).call(this);const{signatureId:i}=yield fetch(`${this.server}/api/${this.chain}/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify({method:t,message:e})}).then((t=>P(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const o=I(`${this.server}/${this.appId}/${this.chain}/user-signature/${i}`);return E(o),new Promise(((t,e)=>B("message",((r,n)=>{const i=r;i.origin===this.server&&"ETH:FRAME:RESPONSE"===i.data.type&&("APPROVED"===i.data.status&&(n(),x(o),t(i.data.signature)),"DECLINED"===i.data.status&&(n(),x(o),e(new Error(i.data.errorMessage))))}))))}))}handleSendTransaction(t){return e(this,void 0,void 0,(function*(){r(this,L,"m",C).call(this);const{authorizationId:e}=yield fetch(`${this.server}/api/${this.chain}/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>P(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const n=I(`${this.server}/${this.appId}/${this.chain}/authz/${e}`);return E(n),new Promise(((t,e)=>B("message",((r,i)=>{const o=r;o.origin===this.server&&"ETH:FRAME:RESPONSE"===o.data.type&&("APPROVED"===o.data.status&&(i(),x(n),t(o.data.txHash)),"DECLINED"===o.data.status&&(i(),x(n),e(new Error(o.data.errorMessage))))}))))}))}handleDisconnect(){return e(this,void 0,void 0,(function*(){this.session.connected=!1,this.session.code=null,this.session.accounts={},A(w)}))}}L=new WeakSet,O=function({chainId:t,rpcUrls:e}){const r=new URL(e[0]).hostname,{chain_id:n,name:i,display_name:o,network_type:s,blocto_service_environment:a,rpc_endpoint_domains:c}=this.supportNetwork[t];if(c.includes(r)){const t=u[a];this.switchableNetwork[n]={name:i,display_name:o,network_type:s,wallet_web_url:t,rpc_url:e[0]}}else console.warn(`The rpc url ${e[0]} is not supported.`)},C=function(){const t=window.ethereum;if(t&&t.isBlocto&&parseInt(t.chainId,16)!==this.chainId)throw new Error("Blocto SDK network mismatched")};var z=[],K=[],W="undefined"!=typeof Uint8Array?Uint8Array:Array,q=!1;function D(){q=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)z[e]=t[e],K[t.charCodeAt(e)]=e;K["-".charCodeAt(0)]=62,K["_".charCodeAt(0)]=63}function j(t,e,r){for(var n,i,o=[],s=e;s<r;s+=3)n=(t[s]<<16)+(t[s+1]<<8)+t[s+2],o.push(z[(i=n)>>18&63]+z[i>>12&63]+z[i>>6&63]+z[63&i]);return o.join("")}function H(t){var e;q||D();for(var r=t.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;a<u;a+=s)o.push(j(t,a,a+s>u?u:a+s));return 1===n?(e=t[r-1],i+=z[e>>2],i+=z[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=z[e>>10],i+=z[e>>4&63],i+=z[e<<2&63],i+="="),o.push(i),o.join("")}function F(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,h=-7,l=r?i-1:0,d=r?-1:1,f=t[e+l];for(l+=d,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+t[e+l],l+=d,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=d,h-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=c}return(f?-1:1)*s*Math.pow(2,o-n)}function $(t,e,r,n,i,o){var s,a,u,c=8*o-i-1,h=(1<<c)-1,l=h>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+l>=1?d/u:d*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+f]=255&a,f+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;t[r+f]=255&s,f+=p,s/=256,c-=8);t[r+f-p]|=128*m}var V={}.toString,G=Array.isArray||function(t){return"[object Array]"==V.call(t)};function Z(){return J.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Y(t,e){if(Z()<e)throw new RangeError("Invalid typed array length");return J.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=J.prototype:(null===t&&(t=new J(e)),t.length=e),t}function J(t,e,r){if(!(J.TYPED_ARRAY_SUPPORT||this instanceof J))return new J(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return tt(this,t)}return X(this,t,e,r)}function X(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n),J.TYPED_ARRAY_SUPPORT?(t=e).__proto__=J.prototype:t=et(t,e),t}(t,e,r,n):"string"==typeof e?function(t,e,r){if("string"==typeof r&&""!==r||(r="utf8"),!J.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|it(e,r),i=(t=Y(t,n)).write(e,r);return i!==n&&(t=t.slice(0,i)),t}(t,e,r):function(t,e){if(nt(e)){var r=0|rt(e.length);return 0===(t=Y(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?Y(t,0):et(t,e);if("Buffer"===e.type&&G(e.data))return et(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function Q(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function tt(t,e){if(Q(e),t=Y(t,e<0?0:0|rt(e)),!J.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function et(t,e){var r=e.length<0?0:0|rt(e.length);t=Y(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function rt(t){if(t>=Z())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Z().toString(16)+" bytes");return 0|t}function nt(t){return!(null==t||!t._isBuffer)}function it(t,e){if(nt(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Rt(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Tt(t).length;default:if(n)return Rt(t).length;e=(""+e).toLowerCase(),n=!0}}function ot(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return vt(this,e,r);case"utf8":case"utf-8":return gt(this,e,r);case"ascii":return wt(this,e,r);case"latin1":case"binary":return bt(this,e,r);case"base64":return mt(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return kt(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function st(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function at(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=J.from(e,n)),nt(e))return 0===e.length?-1:ut(t,e,r,n,i);if("number"==typeof e)return e&=255,J.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):ut(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ut(t,e,r,n,i){var o,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var h=-1;for(o=r;o<a;o++)if(c(t,o)===c(e,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===u)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var l=!0,d=0;d<u;d++)if(c(t,o+d)!==c(e,d)){l=!1;break}if(l)return o}return-1}function ct(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}function ht(t,e,r,n){return Lt(Rt(e,t.length-r),t,r,n)}function lt(t,e,r,n){return Lt(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function dt(t,e,r,n){return lt(t,e,r,n)}function ft(t,e,r,n){return Lt(Tt(e),t,r,n)}function pt(t,e,r,n){return Lt(function(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(r=t.charCodeAt(s))>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function mt(t,e,r){return 0===e&&r===t.length?H(t):H(t.slice(e,r))}function gt(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,a,u,c=t[i],h=null,l=c>239?4:c>223?3:c>191?2:1;if(i+l<=r)switch(l){case 1:c<128&&(h=c);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&c)<<6|63&o)>127&&(h=u);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,l=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=l}return function(t){var e=t.length;if(e<=yt)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=yt));return r}(n)}J.TYPED_ARRAY_SUPPORT=void 0===t.commonjsGlobal.TYPED_ARRAY_SUPPORT||t.commonjsGlobal.TYPED_ARRAY_SUPPORT,Z(),J.poolSize=8192,J._augment=function(t){return t.__proto__=J.prototype,t},J.from=function(t,e,r){return X(null,t,e,r)},J.TYPED_ARRAY_SUPPORT&&(J.prototype.__proto__=Uint8Array.prototype,J.__proto__=Uint8Array),J.alloc=function(t,e,r){return function(t,e,r,n){return Q(e),e<=0?Y(t,e):void 0!==r?"string"==typeof n?Y(t,e).fill(r,n):Y(t,e).fill(r):Y(t,e)}(null,t,e,r)},J.allocUnsafe=function(t){return tt(null,t)},J.allocUnsafeSlow=function(t){return tt(null,t)},J.isBuffer=function(t){return null!=t&&(!!t._isBuffer||Ot(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Ot(t.slice(0,0))}(t))},J.compare=function(t,e){if(!nt(t)||!nt(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},J.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},J.concat=function(t,e){if(!G(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return J.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=J.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(!nt(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},J.byteLength=it,J.prototype._isBuffer=!0,J.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)st(this,e,e+1);return this},J.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)st(this,e,e+3),st(this,e+1,e+2);return this},J.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)st(this,e,e+7),st(this,e+1,e+6),st(this,e+2,e+5),st(this,e+3,e+4);return this},J.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?gt(this,0,t):ot.apply(this,arguments)},J.prototype.equals=function(t){if(!nt(t))throw new TypeError("Argument must be a Buffer");return this===t||0===J.compare(this,t)},J.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},J.prototype.compare=function(t,e,r,n,i){if(!nt(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(o,s),u=this.slice(n,i),c=t.slice(e,r),h=0;h<a;++h)if(u[h]!==c[h]){o=u[h],s=c[h];break}return o<s?-1:s<o?1:0},J.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},J.prototype.indexOf=function(t,e,r){return at(this,t,e,r,!0)},J.prototype.lastIndexOf=function(t,e,r){return at(this,t,e,r,!1)},J.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return ct(this,t,e,r);case"utf8":case"utf-8":return ht(this,t,e,r);case"ascii":return lt(this,t,e,r);case"latin1":case"binary":return dt(this,t,e,r);case"base64":return ft(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return pt(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},J.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var yt=4096;function wt(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function bt(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function vt(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=Pt(t[o]);return i}function kt(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function St(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function _t(t,e,r,n,i,o){if(!nt(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function At(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function Mt(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function It(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Et(t,e,r,n,i){return i||It(t,0,r,4),$(t,e,r,n,23,4),r+4}function xt(t,e,r,n,i){return i||It(t,0,r,8),$(t,e,r,n,52,8),r+8}J.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),J.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=J.prototype;else{var i=e-t;r=new J(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},J.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||St(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},J.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||St(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},J.prototype.readUInt8=function(t,e){return e||St(t,1,this.length),this[t]},J.prototype.readUInt16LE=function(t,e){return e||St(t,2,this.length),this[t]|this[t+1]<<8},J.prototype.readUInt16BE=function(t,e){return e||St(t,2,this.length),this[t]<<8|this[t+1]},J.prototype.readUInt32LE=function(t,e){return e||St(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},J.prototype.readUInt32BE=function(t,e){return e||St(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},J.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||St(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},J.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||St(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},J.prototype.readInt8=function(t,e){return e||St(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},J.prototype.readInt16LE=function(t,e){e||St(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},J.prototype.readInt16BE=function(t,e){e||St(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},J.prototype.readInt32LE=function(t,e){return e||St(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},J.prototype.readInt32BE=function(t,e){return e||St(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},J.prototype.readFloatLE=function(t,e){return e||St(t,4,this.length),F(this,t,!0,23,4)},J.prototype.readFloatBE=function(t,e){return e||St(t,4,this.length),F(this,t,!1,23,4)},J.prototype.readDoubleLE=function(t,e){return e||St(t,8,this.length),F(this,t,!0,52,8)},J.prototype.readDoubleBE=function(t,e){return e||St(t,8,this.length),F(this,t,!1,52,8)},J.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||_t(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},J.prototype.writeUIntBE=function(t,e,r,n){t=+t,e|=0,r|=0,n||_t(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},J.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,1,255,0),J.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},J.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,2,65535,0),J.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):At(this,t,e,!0),e+2},J.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,2,65535,0),J.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):At(this,t,e,!1),e+2},J.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,4,4294967295,0),J.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):Mt(this,t,e,!0),e+4},J.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,4,4294967295,0),J.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Mt(this,t,e,!1),e+4},J.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);_t(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===a&&0!==this[e+o-1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},J.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);_t(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},J.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,1,127,-128),J.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},J.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,2,32767,-32768),J.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):At(this,t,e,!0),e+2},J.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,2,32767,-32768),J.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):At(this,t,e,!1),e+2},J.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,4,2147483647,-2147483648),J.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):Mt(this,t,e,!0),e+4},J.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||_t(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),J.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Mt(this,t,e,!1),e+4},J.prototype.writeFloatLE=function(t,e,r){return Et(this,t,e,!0,r)},J.prototype.writeFloatBE=function(t,e,r){return Et(this,t,e,!1,r)},J.prototype.writeDoubleLE=function(t,e,r){return xt(this,t,e,!0,r)},J.prototype.writeDoubleBE=function(t,e,r){return xt(this,t,e,!1,r)},J.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;i>=0;--i)t[i+e]=this[i+r];else if(o<1e3||!J.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},J.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!J.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=nt(t)?t:Rt(new J(t,n).toString()),a=s.length;for(o=0;o<r-e;++o)this[o+e]=s[o%a]}return this};var Bt=/[^+\/0-9A-Za-z-_]/g;function Pt(t){return t<16?"0"+t.toString(16):t.toString(16)}function Rt(t,e){var r;e=e||1/0;for(var n=t.length,i=null,o=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Tt(t){return function(t){var e,r,n,i,o,s;q||D();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[a-2]?2:"="===t[a-1]?1:0,s=new W(3*a/4-o),n=o>0?a-4:a;var u=0;for(e=0,r=0;e<n;e+=4,r+=3)i=K[t.charCodeAt(e)]<<18|K[t.charCodeAt(e+1)]<<12|K[t.charCodeAt(e+2)]<<6|K[t.charCodeAt(e+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=K[t.charCodeAt(e)]<<2|K[t.charCodeAt(e+1)]>>4,s[u++]=255&i):1===o&&(i=K[t.charCodeAt(e)]<<10|K[t.charCodeAt(e+1)]<<4|K[t.charCodeAt(e+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Bt,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Lt(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Ot(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function Ct(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ut=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=n}var s=t.length,a=t.charAt(0),u=Math.log(s)/Math.log(256),c=Math.log(256)/Math.log(s);function h(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var r=0,n=0,i=0;t[r]===a;)n++,r++;for(var o=(t.length-r)*u+1>>>0,c=new Uint8Array(o);t[r];){var h=e[t.charCodeAt(r)];if(255===h)return;for(var l=0,d=o-1;(0!==h||l<i)&&-1!==d;d--,l++)h+=s*c[d]>>>0,c[d]=h%256>>>0,h=h/256>>>0;if(0!==h)throw new Error("Non-zero carry");i=l,r++}for(var f=o-i;f!==o&&0===c[f];)f++;for(var p=new Uint8Array(n+(o-f)),m=n;f!==o;)p[m++]=c[f++];return p}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,n=0,i=0,o=e.length;i!==o&&0===e[i];)i++,r++;for(var u=(o-i)*c+1>>>0,h=new Uint8Array(u);i!==o;){for(var l=e[i],d=0,f=u-1;(0!==l||d<n)&&-1!==f;f--,d++)l+=256*h[f]>>>0,h[f]=l%s>>>0,l=l/s>>>0;if(0!==l)throw new Error("Non-zero carry");n=d,i++}for(var p=u-n;p!==u&&0===h[p];)p++;for(var m=a.repeat(r);p<u;++p)m+=t.charAt(h[p]);return m},decodeUnsafe:h,decode:function(t){var e=h(t);if(e)return e;throw new Error("Non-base"+s+" character")}}},Nt=Ct(Ut("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));let zt;try{zt=gc}catch(e){}class Kt extends M{constructor({net:t="mainnet-beta",server:e,appId:r,rpc:i,session:o}){if(super(o),n(t,"'net' is required"),n(h.includes(t),"unsupported net"),this.net=t,this.rpc=i||("mainnet-beta"===t?"https://free.rpcpool.com":`https://api.${t}.solana.com`),this.server=e||c[this.net]||"",this.appId=r||y,!zt)throw new Error("No @solana/web3.js installed. Please install it to interact with Solana.")}request(t){return e(this,void 0,void 0,(function*(){this.session.connected||(yield this.connect());try{let e=null,r=null;switch(t.method){case"connect":r=yield this.fetchAccounts();break;case"disconnect":this.disconnect();break;case"getAccounts":r=this.session.accounts.solana.length?this.session.accounts.solana:yield this.fetchAccounts();break;case"getAccountInfo":{const e=yield this.handleReadRequests(t),[n,i]=e.result.value.data;r=Object.assign(Object.assign({},e.result.value),{data:J.from(n,i),owner:new zt.PublicKey(e.result.value.owner)});break}case"convertToProgramWalletTransaction":r=yield this.handleConvertTransaction(t);break;case"signAndSendTransaction":r=yield this.handleSignAndSendTransaction(t);break;case"signTransaction":case"signAllTransactions":throw new Error(`Blocto is program wallet, which doesn't support ${t.method}. Use signAndSendTransaction instead.`);default:e=yield this.handleReadRequests(t)}if(e&&!e.result&&e.error){const t=e.error.message?e.error.message:"Request failed";throw new Error(t)}return e?e.result:r}catch(t){throw console.error(t),t}}))}connect(){return e(this,void 0,void 0,(function*(){const t=window.solana;return t&&t.isBlocto?new Promise((e=>{t.on("connect",(()=>{this.session.accounts.solana=[t.publicKey.toBase58()],e()})),t.connect()})):(this.tryRetrieveSessionFromStorage("solana"),new Promise(((t,e)=>{if("undefined"==typeof window)return e("Currently only supported in browser");if(this.session.connected)return t();const r=encodeURIComponent(window.location.origin),n=I(`${this.server}/${this.appId}/solana/authn?l6n=${r}`);E(n),B("message",((r,i)=>{const o=r;if(o.origin===this.server){if("SOL:FRAME:RESPONSE"===o.data.type){i(),x(n),this.session.code=o.data.code,this.session.connected=!0,this.eventListeners.connect.forEach((t=>t(this.net)));const e=o.data.address;this.formatAndSetSessionAccount(e),_(this.sessionKey,{code:this.session.code,address:e},g),t()}"SOL:FRAME:CLOSE"===o.data.type&&(i(),x(n),e(new Error("User declined the login request")))}}))})))}))}disconnect(){return e(this,void 0,void 0,(function*(){const t=window.solana;t&&t.isBlocto?yield t.disconnect():(this.session.code=null,this.session.accounts={},this.eventListeners.disconnect.forEach((t=>t(null))),this.session.connected=!1)}))}fetchAccounts(){return e(this,void 0,void 0,(function*(){const{accounts:t}=yield fetch(`${this.server}/api/solana/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>t.json()));return this.session.accounts.solana=t,t}))}handleReadRequests(t){return e(this,void 0,void 0,(function*(){return fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({id:1,jsonrpc:"2.0"},t))}).then((t=>t.json()))}))}convertToProgramWalletTransaction(t){return e(this,void 0,void 0,(function*(){const e=window.solana;if(e&&e.isBlocto)return e.convertToProgramWalletTransaction(t);const r=yield this.request({method:"convertToProgramWalletTransaction",params:{message:t.serializeMessage().toString("hex")}});return this.toTransaction(r,[])}))}signAndSendTransaction(t,r){return e(this,void 0,void 0,(function*(){const e=window.solana;if(e&&e.isBlocto)return e.signAndSendTransaction(t);const n={};if(r){r.commitment&&(n.commitment=r.commitment);const t=r?r._rpcEndpoint:null;t&&t!==this.rpc&&(this.rpc=t,this.disconnect(),yield this.connect())}return this.request({method:"signAndSendTransaction",params:Object.assign({signatures:yield this.collectSignatures(t),message:t.serializeMessage().toString("hex")},n)})}))}toTransaction(t,r){return e(this,void 0,void 0,(function*(){const e=zt.Message.from(J.from(t,"hex")),n=new zt.Transaction;return n.recentBlockhash=e.recentBlockhash,e.header.numRequiredSignatures>0&&(n.feePayer=e.accountKeys[0]),r.forEach(((t,r)=>{const i={signature:t===zt.PublicKey.default.toBase58()?null:Nt.decode(t),publicKey:e.accountKeys[r]};n.signatures.push(i)})),e.instructions.forEach((t=>{const r=t.accounts.map((t=>({pubkey:e.accountKeys[t],isSigner:t<e.header.numRequiredSignatures,isWritable:e.isAccountWritable(t)})));n.instructions.push(new zt.TransactionInstruction({keys:r,programId:e.accountKeys[t.programIdIndex],data:Nt.decode(t.data)}))})),n}))}collectSignatures(t){return e(this,void 0,void 0,(function*(){return t.signatures.reduce(((t,e)=>(e.signature&&(t[e.publicKey.toBase58()]=e.signature.toString("hex")),t)),{})}))}handleConvertTransaction(t){return e(this,void 0,void 0,(function*(){return fetch(`${this.server}/api/solana/convertToWalletTx`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>P(t,this)))}))}handleSignAndSendTransaction(t){return e(this,void 0,void 0,(function*(){const{authorizationId:e}=yield fetch(`${this.server}/api/solana/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(t.params)}).then((t=>P(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const r=I(`${this.server}/${this.appId}/solana/authz/${e}`);return E(r),new Promise(((t,e)=>B("message",((n,i)=>{const o=n;o.origin===this.server&&"SOL:FRAME:RESPONSE"===o.data.type&&("APPROVED"===o.data.status&&(i(),x(r),t(o.data.txHash)),"DECLINED"===o.data.status&&(i(),x(r),e(new Error(o.data.errorMessage))))}))))}))}}class Wt extends M{constructor({chainId:t,server:e,appId:r,session:i}){super(i),this.publicKey=[],this.authKey="",n(t,"'chainId' is required"),n(r,"It is necessary to interact with Blocto wallet via your app id. Please visit https://developers.blocto.app for more details."),this.chainId=t,this.networkName=f[t],this.api=p[t];const o=l[t];this.appId=r||y,this.server=e||o||""}get publicAccount(){return{address:this.session.accounts.aptos[0]||null,publicKey:this.publicKey.length?this.publicKey:null,authKey:null,minKeysRequired:2}}network(){return e(this,void 0,void 0,(function*(){return{name:this.networkName,api:this.api,chainId:this.chainId.toString()}}))}isConnected(){return e(this,void 0,void 0,(function*(){return this.session.connected}))}signTransaction(t){return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signTransaction(t);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");throw new Error("signTransaction method not supported.")}))}disconnect(){return e(this,void 0,void 0,(function*(){const t=window.bloctoAptos;t?yield t.disconnect():(this.session.code=null,this.session.accounts={},this.session.connected=!1)}))}signAndSubmitTransaction(t,r={}){return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos;if(e)return e.signAndSubmitTransaction(t,r);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");const{authorizationId:n}=yield fetch(`${this.server}/api/aptos/authz`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(Object.assign(Object.assign({},t),r))}).then((t=>P(t,this)));if("undefined"==typeof window)throw new Error("Currently only supported in browser");const i=I(`${this.server}/${this.appId}/aptos/authz/${n}`);return E(i),new Promise(((t,e)=>B("message",((r,n)=>{const o=r;o.origin===this.server&&"APTOS:FRAME:RESPONSE"===o.data.type&&("APPROVED"===o.data.status&&(n(),x(i),t({hash:o.data.txHash})),"DECLINED"===o.data.status&&(n(),x(i),e(new Error(o.data.errorMessage))))}))))}))}signMessage(t){return e(this,void 0,void 0,(function*(){const e=window.bloctoAptos,r=(t=>{var e,r;const n=Object.assign({},t),{message:i,nonce:o,address:s,application:a,chainId:u}=t;return"string"!=typeof i&&(n.message=null!==(e=String(i))&&void 0!==e?e:""),"string"!=typeof o&&(n.nonce=null!==(r=String(o))&&void 0!==r?r:""),s&&"boolean"!=typeof s&&(n.address=!!s),a&&"boolean"!=typeof a&&(n.application=!!a),u&&"boolean"!=typeof u&&(n.chainId=!!u),n})(t);if(e)return e.signMessage(r);if((yield this.isConnected())||(yield this.connect()),!this.session.accounts.aptos.length)throw new Error("Fail to get account");if("undefined"==typeof window)throw new Error("Currently only supported in browser");const{signatureId:n}=yield fetch(`${this.server}/api/aptos/user-signature`,{method:"POST",headers:{"Content-Type":"application/json","Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code},body:JSON.stringify(r)}).then((t=>P(t,this))),i=I(`${this.server}/${this.appId}/aptos/user-signature/${n}`);return E(i),new Promise(((t,e)=>B("message",((r,n)=>{const o=r;o.origin===this.server&&"APTOS:FRAME:RESPONSE"===o.data.type&&("APPROVED"===o.data.status&&(n(),x(i),t(o.data)),"DECLINED"===o.data.status&&(n(),x(i),e(new Error(o.data.errorMessage))))}))))}))}connect(){return e(this,void 0,void 0,(function*(){const t=window.bloctoAptos;return t?new Promise(((e,r)=>setTimeout((()=>t.connect().then(e).catch(r)),10))):(this.tryRetrieveSessionFromStorage("aptos"),new Promise(((t,r)=>{if("undefined"==typeof window)return r("Currently only supported in browser");if(this.session.connected&&this.session.accounts.aptos.length)return t({address:this.session.accounts.aptos[0],publicKey:this.publicKey,authKey:null,minKeysRequired:2});const n=encodeURIComponent(window.location.origin),i=I(`${this.server}/${this.appId}/aptos/authn?l6n=${n}`);E(i),B("message",((n,o)=>e(this,void 0,void 0,(function*(){const e=n;if(e.origin===this.server){if("APTOS:FRAME:RESPONSE"===e.data.type){o(),x(i),this.session.code=e.data.code,this.session.connected=!0;const n=e.data.address;if(this.formatAndSetSessionAccount(n),_(this.sessionKey,{code:this.session.code,address:n},g),!this.session.accounts.aptos.length)return r();try{const{public_keys:e}=yield fetch(`${this.server}/blocto/aptos/accounts/${this.session.accounts.aptos[0]}`).then((t=>t.json()));this.publicKey=e||[],t({address:this.session.accounts.aptos[0]||"",publicKey:this.publicKey,authKey:null,minKeysRequired:2})}catch(t){return r(e)}}"APTOS:FRAME:CLOSE"===e.data.type&&(o(),x(i),r(new Error("User declined the login request")))}}))))})))}))}fetchAddress(){return e(this,void 0,void 0,(function*(){const{accounts:t}=yield fetch(`${this.server}/api/aptos/accounts`,{headers:{"Blocto-Application-Identifier":this.appId,"Blocto-Session-Identifier":this.session.code}}).then((t=>P(t,this)));return this.session.accounts.aptos=t||[],this.session.accounts.aptos[0]}))}}const qt={connected:!1,code:null,accounts:{}};return class{constructor({appId:t,ethereum:e,solana:r,aptos:n}){e&&(this.ethereum=new N(Object.assign(Object.assign({},e),{appId:t,session:qt}))),r&&(this.solana=new Kt(Object.assign(Object.assign({},r),{appId:t,session:qt}))),n&&(this.aptos=new Wt(Object.assign(Object.assign({},n),{appId:t,session:qt})))}}}()}(s);var yc=t.getDefaultExportFromCjs(s.exports);exports.default=function({chainId:e,rpcUrl:r,rpc:n,bloctoParams:i},o){return t.__awaiter(this,void 0,void 0,(function*(){let s;if(!e)throw new Error("chainId is required");r?s=r:e&&n&&(s=n[e]);const a=new yc({appId:null==i?void 0:i.appId,ethereum:{chainId:e,rpc:s}}).ethereum;if(!a)throw new Error("No provider");return a.on("connect",o.connect),a.on("disconnect",o.disconnect),a.on("accountsChanged",o.accountsChanged),a.on("chainChanged",o.chainChanged),yield a.request({method:"eth_requestAccounts"}),t.convertWeb3Provider(a)}))};