@imtbl/wallet 2.10.7-alpha.2

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 (71) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/LICENSE.md +176 -0
  3. package/dist/browser/index.mjs +21 -0
  4. package/dist/node/index.js +71 -0
  5. package/dist/node/index.mjs +22 -0
  6. package/dist/types/config.d.ts +13 -0
  7. package/dist/types/errors.d.ts +14 -0
  8. package/dist/types/guardian/index.d.ts +57 -0
  9. package/dist/types/index.d.ts +12 -0
  10. package/dist/types/magic/index.d.ts +1 -0
  11. package/dist/types/magic/magicTEESigner.d.ts +24 -0
  12. package/dist/types/network/chains.d.ts +32 -0
  13. package/dist/types/network/constants.d.ts +3 -0
  14. package/dist/types/network/retry.d.ts +8 -0
  15. package/dist/types/provider/eip6963.d.ts +3 -0
  16. package/dist/types/types.d.ts +163 -0
  17. package/dist/types/utils/metrics.d.ts +3 -0
  18. package/dist/types/utils/string.d.ts +1 -0
  19. package/dist/types/utils/typedEventEmitter.d.ts +6 -0
  20. package/dist/types/zkEvm/JsonRpcError.d.ts +25 -0
  21. package/dist/types/zkEvm/index.d.ts +2 -0
  22. package/dist/types/zkEvm/personalSign.d.ts +15 -0
  23. package/dist/types/zkEvm/provider/eip6963.d.ts +3 -0
  24. package/dist/types/zkEvm/relayerClient.d.ts +60 -0
  25. package/dist/types/zkEvm/sendDeployTransactionAndPersonalSign.d.ts +6 -0
  26. package/dist/types/zkEvm/sendTransaction.d.ts +6 -0
  27. package/dist/types/zkEvm/sessionActivity/errorBoundary.d.ts +1 -0
  28. package/dist/types/zkEvm/sessionActivity/request.d.ts +15 -0
  29. package/dist/types/zkEvm/sessionActivity/sessionActivity.d.ts +2 -0
  30. package/dist/types/zkEvm/signEjectionTransaction.d.ts +6 -0
  31. package/dist/types/zkEvm/signTypedDataV4.d.ts +14 -0
  32. package/dist/types/zkEvm/transactionHelpers.d.ts +31 -0
  33. package/dist/types/zkEvm/types.d.ts +120 -0
  34. package/dist/types/zkEvm/user/index.d.ts +1 -0
  35. package/dist/types/zkEvm/user/registerZkEvmUser.d.ts +13 -0
  36. package/dist/types/zkEvm/walletHelpers.d.ts +33 -0
  37. package/dist/types/zkEvm/zkEvmProvider.d.ts +25 -0
  38. package/package.json +55 -0
  39. package/src/config.ts +51 -0
  40. package/src/errors.ts +33 -0
  41. package/src/guardian/index.ts +358 -0
  42. package/src/index.ts +27 -0
  43. package/src/magic/index.ts +1 -0
  44. package/src/magic/magicTEESigner.ts +214 -0
  45. package/src/network/chains.ts +33 -0
  46. package/src/network/constants.ts +28 -0
  47. package/src/network/retry.ts +37 -0
  48. package/src/provider/eip6963.ts +25 -0
  49. package/src/types.ts +192 -0
  50. package/src/utils/metrics.ts +57 -0
  51. package/src/utils/string.ts +12 -0
  52. package/src/utils/typedEventEmitter.ts +26 -0
  53. package/src/zkEvm/JsonRpcError.ts +33 -0
  54. package/src/zkEvm/index.ts +2 -0
  55. package/src/zkEvm/personalSign.ts +62 -0
  56. package/src/zkEvm/provider/eip6963.ts +25 -0
  57. package/src/zkEvm/relayerClient.ts +216 -0
  58. package/src/zkEvm/sendDeployTransactionAndPersonalSign.ts +44 -0
  59. package/src/zkEvm/sendTransaction.ts +34 -0
  60. package/src/zkEvm/sessionActivity/errorBoundary.ts +33 -0
  61. package/src/zkEvm/sessionActivity/request.ts +62 -0
  62. package/src/zkEvm/sessionActivity/sessionActivity.ts +140 -0
  63. package/src/zkEvm/signEjectionTransaction.ts +33 -0
  64. package/src/zkEvm/signTypedDataV4.ts +103 -0
  65. package/src/zkEvm/transactionHelpers.ts +295 -0
  66. package/src/zkEvm/types.ts +136 -0
  67. package/src/zkEvm/user/index.ts +1 -0
  68. package/src/zkEvm/user/registerZkEvmUser.ts +75 -0
  69. package/src/zkEvm/walletHelpers.ts +243 -0
  70. package/src/zkEvm/zkEvmProvider.ts +453 -0
  71. package/tsconfig.json +15 -0
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ var metrics = require('@imtbl/metrics');
4
+ var ethers = require('ethers');
5
+ var events = require('events');
6
+ var auth = require('@imtbl/auth');
7
+ var abi = require('@0xsequence/abi');
8
+ var core = require('@0xsequence/core');
9
+ var Xe = require('@imtbl/generated-clients');
10
+ var un = require('axios');
11
+ var config = require('@imtbl/config');
12
+ var uuid = require('uuid');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n.default = e;
31
+ return Object.freeze(n);
32
+ }
33
+
34
+ var Xe__namespace = /*#__PURE__*/_interopNamespace(Xe);
35
+ var un__default = /*#__PURE__*/_interopDefault(un);
36
+
37
+ var Nn=Object.create;var Ne=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var kn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var On=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(s,h)=>(typeof require<"u"?require:s)[h]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var qt=(n,s)=>()=>(s||n((s={exports:{}}).exports,s),s.exports),Ln=(n,s)=>{for(var h in s)Ne(n,h,{get:s[h],enumerable:!0});},Gn=(n,s,h,p)=>{if(s&&typeof s=="object"||typeof s=="function")for(let a of Bn(s))!Un.call(n,a)&&a!==h&&Ne(n,a,{get:()=>s[a],enumerable:!(p=Dn(s,a))||p.enumerable});return n};var br=(n,s,h)=>(h=n!=null?Nn(kn(n)):{},Gn(Ne(h,"default",{value:n,enumerable:!0}),n));var qr=qt((Fr,Le)=>{(function(n,s){function h(c,t){if(!c)throw new Error(t||"Assertion failed")}function p(c,t){c.super_=t;var r=function(){};r.prototype=t.prototype,c.prototype=new r,c.prototype.constructor=c;}function a(c,t,r){if(a.isBN(c))return c;this.negative=0,this.words=null,this.length=0,this.red=null,c!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(c||0,t||10,r||"be"));}typeof n=="object"?n.exports=a:s.BN=a,a.BN=a,a.wordSize=26;var g;try{typeof window<"u"&&typeof window.Buffer<"u"?g=window.Buffer:g=On("buffer").Buffer;}catch{}a.isBN=function(t){return t instanceof a?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===a.wordSize&&Array.isArray(t.words)},a.max=function(t,r){return t.cmp(r)>0?t:r},a.min=function(t,r){return t.cmp(r)<0?t:r},a.prototype._init=function(t,r,i){if(typeof t=="number")return this._initNumber(t,r,i);if(typeof t=="object")return this._initArray(t,r,i);r==="hex"&&(r=16),h(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var o=0;t[0]==="-"&&(o++,this.negative=1),o<t.length&&(r===16?this._parseHex(t,o,i):(this._parseBase(t,r,o),i==="le"&&this._initArray(this.toArray(),r,i)));},a.prototype._initNumber=function(t,r,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(h(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),r,i);},a.prototype._initArray=function(t,r,i){if(h(typeof t.length=="number"),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 o=0;o<this.length;o++)this.words[o]=0;var l,d,m=0;if(i==="be")for(o=t.length-1,l=0;o>=0;o-=3)d=t[o]|t[o-1]<<8|t[o-2]<<16,this.words[l]|=d<<m&67108863,this.words[l+1]=d>>>26-m&67108863,m+=24,m>=26&&(m-=26,l++);else if(i==="le")for(o=0,l=0;o<t.length;o+=3)d=t[o]|t[o+1]<<8|t[o+2]<<16,this.words[l]|=d<<m&67108863,this.words[l+1]=d>>>26-m&67108863,m+=24,m>=26&&(m-=26,l++);return this._strip()};function v(c,t){var r=c.charCodeAt(t);if(r>=48&&r<=57)return r-48;if(r>=65&&r<=70)return r-55;if(r>=97&&r<=102)return r-87;h(!1,"Invalid character in "+c);}function y(c,t,r){var i=v(c,r);return r-1>=t&&(i|=v(c,r-1)<<4),i}a.prototype._parseHex=function(t,r,i){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var l=0,d=0,m;if(i==="be")for(o=t.length-1;o>=r;o-=2)m=y(t,r,o)<<l,this.words[d]|=m&67108863,l>=18?(l-=18,d+=1,this.words[d]|=m>>>26):l+=8;else {var f=t.length-r;for(o=f%2===0?r+1:r;o<t.length;o+=2)m=y(t,r,o)<<l,this.words[d]|=m&67108863,l>=18?(l-=18,d+=1,this.words[d]|=m>>>26):l+=8;}this._strip();};function A(c,t,r,i){for(var o=0,l=0,d=Math.min(c.length,r),m=t;m<d;m++){var f=c.charCodeAt(m)-48;o*=i,f>=49?l=f-49+10:f>=17?l=f-17+10:l=f,h(f>=0&&l<i,"Invalid character"),o+=l;}return o}a.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var o=0,l=1;l<=67108863;l*=r)o++;o--,l=l/r|0;for(var d=t.length-i,m=d%o,f=Math.min(d,d-m)+i,e=0,u=i;u<f;u+=o)e=A(t,u,u+o,r),this.imuln(l),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(m!==0){var w=1;for(e=A(t,u,t.length,r),u=0;u<m;u++)w*=r;this.imuln(w),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);}this._strip();},a.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red;};function C(c,t){c.words=t.words,c.length=t.length,c.negative=t.negative,c.red=t.red;}if(a.prototype._move=function(t){C(t,this);},a.prototype.clone=function(){var t=new a(null);return this.copy(t),t},a.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=S;}catch{a.prototype.inspect=S;}else a.prototype.inspect=S;function S(){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"],mt=[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],yt=[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];a.prototype.toString=function(t,r){t=t||10,r=r|0||1;var i;if(t===16||t==="hex"){i="";for(var o=0,l=0,d=0;d<this.length;d++){var m=this.words[d],f=((m<<o|l)&16777215).toString(16);l=m>>>24-o&16777215,o+=2,o>=26&&(o-=26,d--),l!==0||d!==this.length-1?i=D[6-f.length]+f+i:i=f+i;}for(l!==0&&(i=l.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=mt[t],u=yt[t];i="";var w=this.clone();for(w.negative=0;!w.isZero();){var M=w.modrn(u).toString(t);w=w.idivn(u),w.isZero()?i=M+i:i=D[e-M.length]+M+i;}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}h(!1,"Base should be between 2 and 36");},a.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&h(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},a.prototype.toJSON=function(){return this.toString(16,2)},g&&(a.prototype.toBuffer=function(t,r){return this.toArrayLike(g,t,r)}),a.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)};var bt=function(t,r){return t.allocUnsafe?t.allocUnsafe(r):new t(r)};a.prototype.toArrayLike=function(t,r,i){this._strip();var o=this.byteLength(),l=i||Math.max(1,o);h(o<=l,"byte array longer than desired length"),h(l>0,"Requested array length <= 0");var d=bt(t,l),m=r==="le"?"LE":"BE";return this["_toArrayLike"+m](d,o),d},a.prototype._toArrayLikeLE=function(t,r){for(var i=0,o=0,l=0,d=0;l<this.length;l++){var m=this.words[l]<<d|o;t[i++]=m&255,i<t.length&&(t[i++]=m>>8&255),i<t.length&&(t[i++]=m>>16&255),d===6?(i<t.length&&(t[i++]=m>>24&255),o=0,d=0):(o=m>>>24,d+=2);}if(i<t.length)for(t[i++]=o;i<t.length;)t[i++]=0;},a.prototype._toArrayLikeBE=function(t,r){for(var i=t.length-1,o=0,l=0,d=0;l<this.length;l++){var m=this.words[l]<<d|o;t[i--]=m&255,i>=0&&(t[i--]=m>>8&255),i>=0&&(t[i--]=m>>16&255),d===6?(i>=0&&(t[i--]=m>>24&255),o=0,d=0):(o=m>>>24,d+=2);}if(i>=0)for(t[i--]=o;i>=0;)t[i--]=0;},Math.clz32?a.prototype._countBits=function(t){return 32-Math.clz32(t)}:a.prototype._countBits=function(t){var r=t,i=0;return r>=4096&&(i+=13,r>>>=13),r>=64&&(i+=7,r>>>=7),r>=8&&(i+=4,r>>>=4),r>=2&&(i+=2,r>>>=2),i+r},a.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,i=0;return r&8191||(i+=13,r>>>=13),r&127||(i+=7,r>>>=7),r&15||(i+=4,r>>>=4),r&3||(i+=2,r>>>=2),r&1||i++,i},a.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return (this.length-1)*26+r};function Et(c){for(var t=new Array(c.bitLength()),r=0;r<t.length;r++){var i=r/26|0,o=r%26;t[r]=c.words[i]>>>o&1;}return t}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var i=this._zeroBits(this.words[r]);if(t+=i,i!==26)break}return t},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},a.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this._strip()},a.prototype.ior=function(t){return h((this.negative|t.negative)===0),this.iuor(t)},a.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},a.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},a.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var i=0;i<r.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=r.length,this._strip()},a.prototype.iand=function(t){return h((this.negative|t.negative)===0),this.iuand(t)},a.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},a.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},a.prototype.iuxor=function(t){var r,i;this.length>t.length?(r=this,i=t):(r=t,i=this);for(var o=0;o<i.length;o++)this.words[o]=r.words[o]^i.words[o];if(this!==r)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=r.length,this._strip()},a.prototype.ixor=function(t){return h((this.negative|t.negative)===0),this.iuxor(t)},a.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},a.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},a.prototype.inotn=function(t){h(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,i=t%26;this._expand(r),i>0&&r--;for(var o=0;o<r;o++)this.words[o]=~this.words[o]&67108863;return i>0&&(this.words[o]=~this.words[o]&67108863>>26-i),this._strip()},a.prototype.notn=function(t){return this.clone().inotn(t)},a.prototype.setn=function(t,r){h(typeof t=="number"&&t>=0);var i=t/26|0,o=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<o:this.words[i]=this.words[i]&~(1<<o),this._strip()},a.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var i,o;this.length>t.length?(i=this,o=t):(i=t,o=this);for(var l=0,d=0;d<o.length;d++)r=(i.words[d]|0)+(o.words[d]|0)+l,this.words[d]=r&67108863,l=r>>>26;for(;l!==0&&d<i.length;d++)r=(i.words[d]|0)+l,this.words[d]=r&67108863,l=r>>>26;if(this.length=i.length,l!==0)this.words[this.length]=l,this.length++;else if(i!==this)for(;d<i.length;d++)this.words[d]=i.words[d];return this},a.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},a.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var o,l;i>0?(o=this,l=t):(o=t,l=this);for(var d=0,m=0;m<l.length;m++)r=(o.words[m]|0)-(l.words[m]|0)+d,d=r>>26,this.words[m]=r&67108863;for(;d!==0&&m<o.length;m++)r=(o.words[m]|0)+d,d=r>>26,this.words[m]=r&67108863;if(d===0&&m<o.length&&o!==this)for(;m<o.length;m++)this.words[m]=o.words[m];return this.length=Math.max(this.length,m),o!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(t){return this.clone().isub(t)};function wt(c,t,r){r.negative=t.negative^c.negative;var i=c.length+t.length|0;r.length=i,i=i-1|0;var o=c.words[0]|0,l=t.words[0]|0,d=o*l,m=d&67108863,f=d/67108864|0;r.words[0]=m;for(var e=1;e<i;e++){for(var u=f>>>26,w=f&67108863,M=Math.min(e,t.length-1),T=Math.max(0,e-c.length+1);T<=M;T++){var x=e-T|0;o=c.words[x]|0,l=t.words[T]|0,d=o*l+w,u+=d/67108864|0,w=d&67108863;}r.words[e]=w|0,f=u|0;}return f!==0?r.words[e]=f|0:r.length--,r._strip()}var Gt=function(t,r,i){var o=t.words,l=r.words,d=i.words,m=0,f,e,u,w=o[0]|0,M=w&8191,T=w>>>13,x=o[1]|0,b=x&8191,I=x>>>13,At=o[2]|0,_=At&8191,P=At>>>13,lr=o[3]|0,B=lr&8191,k=lr>>>13,ur=o[4]|0,U=ur&8191,O=ur>>>13,cr=o[5]|0,L=cr&8191,G=cr>>>13,dr=o[6]|0,F=dr&8191,q=dr>>>13,mr=o[7]|0,H=mr&8191,Z=mr>>>13,pr=o[8]|0,W=pr&8191,J=pr>>>13,gr=o[9]|0,V=gr&8191,$=gr>>>13,vr=l[0]|0,z=vr&8191,j=vr>>>13,yr=l[1]|0,Y=yr&8191,K=yr>>>13,wr=l[2]|0,X=wr&8191,Q=wr>>>13,Mr=l[3]|0,tt=Mr&8191,et=Mr>>>13,Er=l[4]|0,rt=Er&8191,nt=Er>>>13,Tr=l[5]|0,it=Tr&8191,at=Tr>>>13,Ar=l[6]|0,st=Ar&8191,ot=Ar>>>13,Rr=l[7]|0,ht=Rr&8191,ft=Rr>>>13,xr=l[8]|0,lt=xr&8191,ut=xr>>>13,Cr=l[9]|0,ct=Cr&8191,dt=Cr>>>13;i.negative=t.negative^r.negative,i.length=19,f=Math.imul(M,z),e=Math.imul(M,j),e=e+Math.imul(T,z)|0,u=Math.imul(T,j);var de=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(de>>>26)|0,de&=67108863,f=Math.imul(b,z),e=Math.imul(b,j),e=e+Math.imul(I,z)|0,u=Math.imul(I,j),f=f+Math.imul(M,Y)|0,e=e+Math.imul(M,K)|0,e=e+Math.imul(T,Y)|0,u=u+Math.imul(T,K)|0;var me=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(me>>>26)|0,me&=67108863,f=Math.imul(_,z),e=Math.imul(_,j),e=e+Math.imul(P,z)|0,u=Math.imul(P,j),f=f+Math.imul(b,Y)|0,e=e+Math.imul(b,K)|0,e=e+Math.imul(I,Y)|0,u=u+Math.imul(I,K)|0,f=f+Math.imul(M,X)|0,e=e+Math.imul(M,Q)|0,e=e+Math.imul(T,X)|0,u=u+Math.imul(T,Q)|0;var pe=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(pe>>>26)|0,pe&=67108863,f=Math.imul(B,z),e=Math.imul(B,j),e=e+Math.imul(k,z)|0,u=Math.imul(k,j),f=f+Math.imul(_,Y)|0,e=e+Math.imul(_,K)|0,e=e+Math.imul(P,Y)|0,u=u+Math.imul(P,K)|0,f=f+Math.imul(b,X)|0,e=e+Math.imul(b,Q)|0,e=e+Math.imul(I,X)|0,u=u+Math.imul(I,Q)|0,f=f+Math.imul(M,tt)|0,e=e+Math.imul(M,et)|0,e=e+Math.imul(T,tt)|0,u=u+Math.imul(T,et)|0;var ge=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(ge>>>26)|0,ge&=67108863,f=Math.imul(U,z),e=Math.imul(U,j),e=e+Math.imul(O,z)|0,u=Math.imul(O,j),f=f+Math.imul(B,Y)|0,e=e+Math.imul(B,K)|0,e=e+Math.imul(k,Y)|0,u=u+Math.imul(k,K)|0,f=f+Math.imul(_,X)|0,e=e+Math.imul(_,Q)|0,e=e+Math.imul(P,X)|0,u=u+Math.imul(P,Q)|0,f=f+Math.imul(b,tt)|0,e=e+Math.imul(b,et)|0,e=e+Math.imul(I,tt)|0,u=u+Math.imul(I,et)|0,f=f+Math.imul(M,rt)|0,e=e+Math.imul(M,nt)|0,e=e+Math.imul(T,rt)|0,u=u+Math.imul(T,nt)|0;var ve=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,f=Math.imul(L,z),e=Math.imul(L,j),e=e+Math.imul(G,z)|0,u=Math.imul(G,j),f=f+Math.imul(U,Y)|0,e=e+Math.imul(U,K)|0,e=e+Math.imul(O,Y)|0,u=u+Math.imul(O,K)|0,f=f+Math.imul(B,X)|0,e=e+Math.imul(B,Q)|0,e=e+Math.imul(k,X)|0,u=u+Math.imul(k,Q)|0,f=f+Math.imul(_,tt)|0,e=e+Math.imul(_,et)|0,e=e+Math.imul(P,tt)|0,u=u+Math.imul(P,et)|0,f=f+Math.imul(b,rt)|0,e=e+Math.imul(b,nt)|0,e=e+Math.imul(I,rt)|0,u=u+Math.imul(I,nt)|0,f=f+Math.imul(M,it)|0,e=e+Math.imul(M,at)|0,e=e+Math.imul(T,it)|0,u=u+Math.imul(T,at)|0;var ye=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(ye>>>26)|0,ye&=67108863,f=Math.imul(F,z),e=Math.imul(F,j),e=e+Math.imul(q,z)|0,u=Math.imul(q,j),f=f+Math.imul(L,Y)|0,e=e+Math.imul(L,K)|0,e=e+Math.imul(G,Y)|0,u=u+Math.imul(G,K)|0,f=f+Math.imul(U,X)|0,e=e+Math.imul(U,Q)|0,e=e+Math.imul(O,X)|0,u=u+Math.imul(O,Q)|0,f=f+Math.imul(B,tt)|0,e=e+Math.imul(B,et)|0,e=e+Math.imul(k,tt)|0,u=u+Math.imul(k,et)|0,f=f+Math.imul(_,rt)|0,e=e+Math.imul(_,nt)|0,e=e+Math.imul(P,rt)|0,u=u+Math.imul(P,nt)|0,f=f+Math.imul(b,it)|0,e=e+Math.imul(b,at)|0,e=e+Math.imul(I,it)|0,u=u+Math.imul(I,at)|0,f=f+Math.imul(M,st)|0,e=e+Math.imul(M,ot)|0,e=e+Math.imul(T,st)|0,u=u+Math.imul(T,ot)|0;var we=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(we>>>26)|0,we&=67108863,f=Math.imul(H,z),e=Math.imul(H,j),e=e+Math.imul(Z,z)|0,u=Math.imul(Z,j),f=f+Math.imul(F,Y)|0,e=e+Math.imul(F,K)|0,e=e+Math.imul(q,Y)|0,u=u+Math.imul(q,K)|0,f=f+Math.imul(L,X)|0,e=e+Math.imul(L,Q)|0,e=e+Math.imul(G,X)|0,u=u+Math.imul(G,Q)|0,f=f+Math.imul(U,tt)|0,e=e+Math.imul(U,et)|0,e=e+Math.imul(O,tt)|0,u=u+Math.imul(O,et)|0,f=f+Math.imul(B,rt)|0,e=e+Math.imul(B,nt)|0,e=e+Math.imul(k,rt)|0,u=u+Math.imul(k,nt)|0,f=f+Math.imul(_,it)|0,e=e+Math.imul(_,at)|0,e=e+Math.imul(P,it)|0,u=u+Math.imul(P,at)|0,f=f+Math.imul(b,st)|0,e=e+Math.imul(b,ot)|0,e=e+Math.imul(I,st)|0,u=u+Math.imul(I,ot)|0,f=f+Math.imul(M,ht)|0,e=e+Math.imul(M,ft)|0,e=e+Math.imul(T,ht)|0,u=u+Math.imul(T,ft)|0;var Me=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Me>>>26)|0,Me&=67108863,f=Math.imul(W,z),e=Math.imul(W,j),e=e+Math.imul(J,z)|0,u=Math.imul(J,j),f=f+Math.imul(H,Y)|0,e=e+Math.imul(H,K)|0,e=e+Math.imul(Z,Y)|0,u=u+Math.imul(Z,K)|0,f=f+Math.imul(F,X)|0,e=e+Math.imul(F,Q)|0,e=e+Math.imul(q,X)|0,u=u+Math.imul(q,Q)|0,f=f+Math.imul(L,tt)|0,e=e+Math.imul(L,et)|0,e=e+Math.imul(G,tt)|0,u=u+Math.imul(G,et)|0,f=f+Math.imul(U,rt)|0,e=e+Math.imul(U,nt)|0,e=e+Math.imul(O,rt)|0,u=u+Math.imul(O,nt)|0,f=f+Math.imul(B,it)|0,e=e+Math.imul(B,at)|0,e=e+Math.imul(k,it)|0,u=u+Math.imul(k,at)|0,f=f+Math.imul(_,st)|0,e=e+Math.imul(_,ot)|0,e=e+Math.imul(P,st)|0,u=u+Math.imul(P,ot)|0,f=f+Math.imul(b,ht)|0,e=e+Math.imul(b,ft)|0,e=e+Math.imul(I,ht)|0,u=u+Math.imul(I,ft)|0,f=f+Math.imul(M,lt)|0,e=e+Math.imul(M,ut)|0,e=e+Math.imul(T,lt)|0,u=u+Math.imul(T,ut)|0;var Ee=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,f=Math.imul(V,z),e=Math.imul(V,j),e=e+Math.imul($,z)|0,u=Math.imul($,j),f=f+Math.imul(W,Y)|0,e=e+Math.imul(W,K)|0,e=e+Math.imul(J,Y)|0,u=u+Math.imul(J,K)|0,f=f+Math.imul(H,X)|0,e=e+Math.imul(H,Q)|0,e=e+Math.imul(Z,X)|0,u=u+Math.imul(Z,Q)|0,f=f+Math.imul(F,tt)|0,e=e+Math.imul(F,et)|0,e=e+Math.imul(q,tt)|0,u=u+Math.imul(q,et)|0,f=f+Math.imul(L,rt)|0,e=e+Math.imul(L,nt)|0,e=e+Math.imul(G,rt)|0,u=u+Math.imul(G,nt)|0,f=f+Math.imul(U,it)|0,e=e+Math.imul(U,at)|0,e=e+Math.imul(O,it)|0,u=u+Math.imul(O,at)|0,f=f+Math.imul(B,st)|0,e=e+Math.imul(B,ot)|0,e=e+Math.imul(k,st)|0,u=u+Math.imul(k,ot)|0,f=f+Math.imul(_,ht)|0,e=e+Math.imul(_,ft)|0,e=e+Math.imul(P,ht)|0,u=u+Math.imul(P,ft)|0,f=f+Math.imul(b,lt)|0,e=e+Math.imul(b,ut)|0,e=e+Math.imul(I,lt)|0,u=u+Math.imul(I,ut)|0,f=f+Math.imul(M,ct)|0,e=e+Math.imul(M,dt)|0,e=e+Math.imul(T,ct)|0,u=u+Math.imul(T,dt)|0;var Te=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Te>>>26)|0,Te&=67108863,f=Math.imul(V,Y),e=Math.imul(V,K),e=e+Math.imul($,Y)|0,u=Math.imul($,K),f=f+Math.imul(W,X)|0,e=e+Math.imul(W,Q)|0,e=e+Math.imul(J,X)|0,u=u+Math.imul(J,Q)|0,f=f+Math.imul(H,tt)|0,e=e+Math.imul(H,et)|0,e=e+Math.imul(Z,tt)|0,u=u+Math.imul(Z,et)|0,f=f+Math.imul(F,rt)|0,e=e+Math.imul(F,nt)|0,e=e+Math.imul(q,rt)|0,u=u+Math.imul(q,nt)|0,f=f+Math.imul(L,it)|0,e=e+Math.imul(L,at)|0,e=e+Math.imul(G,it)|0,u=u+Math.imul(G,at)|0,f=f+Math.imul(U,st)|0,e=e+Math.imul(U,ot)|0,e=e+Math.imul(O,st)|0,u=u+Math.imul(O,ot)|0,f=f+Math.imul(B,ht)|0,e=e+Math.imul(B,ft)|0,e=e+Math.imul(k,ht)|0,u=u+Math.imul(k,ft)|0,f=f+Math.imul(_,lt)|0,e=e+Math.imul(_,ut)|0,e=e+Math.imul(P,lt)|0,u=u+Math.imul(P,ut)|0,f=f+Math.imul(b,ct)|0,e=e+Math.imul(b,dt)|0,e=e+Math.imul(I,ct)|0,u=u+Math.imul(I,dt)|0;var Ae=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,f=Math.imul(V,X),e=Math.imul(V,Q),e=e+Math.imul($,X)|0,u=Math.imul($,Q),f=f+Math.imul(W,tt)|0,e=e+Math.imul(W,et)|0,e=e+Math.imul(J,tt)|0,u=u+Math.imul(J,et)|0,f=f+Math.imul(H,rt)|0,e=e+Math.imul(H,nt)|0,e=e+Math.imul(Z,rt)|0,u=u+Math.imul(Z,nt)|0,f=f+Math.imul(F,it)|0,e=e+Math.imul(F,at)|0,e=e+Math.imul(q,it)|0,u=u+Math.imul(q,at)|0,f=f+Math.imul(L,st)|0,e=e+Math.imul(L,ot)|0,e=e+Math.imul(G,st)|0,u=u+Math.imul(G,ot)|0,f=f+Math.imul(U,ht)|0,e=e+Math.imul(U,ft)|0,e=e+Math.imul(O,ht)|0,u=u+Math.imul(O,ft)|0,f=f+Math.imul(B,lt)|0,e=e+Math.imul(B,ut)|0,e=e+Math.imul(k,lt)|0,u=u+Math.imul(k,ut)|0,f=f+Math.imul(_,ct)|0,e=e+Math.imul(_,dt)|0,e=e+Math.imul(P,ct)|0,u=u+Math.imul(P,dt)|0;var Re=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Re>>>26)|0,Re&=67108863,f=Math.imul(V,tt),e=Math.imul(V,et),e=e+Math.imul($,tt)|0,u=Math.imul($,et),f=f+Math.imul(W,rt)|0,e=e+Math.imul(W,nt)|0,e=e+Math.imul(J,rt)|0,u=u+Math.imul(J,nt)|0,f=f+Math.imul(H,it)|0,e=e+Math.imul(H,at)|0,e=e+Math.imul(Z,it)|0,u=u+Math.imul(Z,at)|0,f=f+Math.imul(F,st)|0,e=e+Math.imul(F,ot)|0,e=e+Math.imul(q,st)|0,u=u+Math.imul(q,ot)|0,f=f+Math.imul(L,ht)|0,e=e+Math.imul(L,ft)|0,e=e+Math.imul(G,ht)|0,u=u+Math.imul(G,ft)|0,f=f+Math.imul(U,lt)|0,e=e+Math.imul(U,ut)|0,e=e+Math.imul(O,lt)|0,u=u+Math.imul(O,ut)|0,f=f+Math.imul(B,ct)|0,e=e+Math.imul(B,dt)|0,e=e+Math.imul(k,ct)|0,u=u+Math.imul(k,dt)|0;var xe=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(xe>>>26)|0,xe&=67108863,f=Math.imul(V,rt),e=Math.imul(V,nt),e=e+Math.imul($,rt)|0,u=Math.imul($,nt),f=f+Math.imul(W,it)|0,e=e+Math.imul(W,at)|0,e=e+Math.imul(J,it)|0,u=u+Math.imul(J,at)|0,f=f+Math.imul(H,st)|0,e=e+Math.imul(H,ot)|0,e=e+Math.imul(Z,st)|0,u=u+Math.imul(Z,ot)|0,f=f+Math.imul(F,ht)|0,e=e+Math.imul(F,ft)|0,e=e+Math.imul(q,ht)|0,u=u+Math.imul(q,ft)|0,f=f+Math.imul(L,lt)|0,e=e+Math.imul(L,ut)|0,e=e+Math.imul(G,lt)|0,u=u+Math.imul(G,ut)|0,f=f+Math.imul(U,ct)|0,e=e+Math.imul(U,dt)|0,e=e+Math.imul(O,ct)|0,u=u+Math.imul(O,dt)|0;var Ce=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,f=Math.imul(V,it),e=Math.imul(V,at),e=e+Math.imul($,it)|0,u=Math.imul($,at),f=f+Math.imul(W,st)|0,e=e+Math.imul(W,ot)|0,e=e+Math.imul(J,st)|0,u=u+Math.imul(J,ot)|0,f=f+Math.imul(H,ht)|0,e=e+Math.imul(H,ft)|0,e=e+Math.imul(Z,ht)|0,u=u+Math.imul(Z,ft)|0,f=f+Math.imul(F,lt)|0,e=e+Math.imul(F,ut)|0,e=e+Math.imul(q,lt)|0,u=u+Math.imul(q,ut)|0,f=f+Math.imul(L,ct)|0,e=e+Math.imul(L,dt)|0,e=e+Math.imul(G,ct)|0,u=u+Math.imul(G,dt)|0;var be=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(be>>>26)|0,be&=67108863,f=Math.imul(V,st),e=Math.imul(V,ot),e=e+Math.imul($,st)|0,u=Math.imul($,ot),f=f+Math.imul(W,ht)|0,e=e+Math.imul(W,ft)|0,e=e+Math.imul(J,ht)|0,u=u+Math.imul(J,ft)|0,f=f+Math.imul(H,lt)|0,e=e+Math.imul(H,ut)|0,e=e+Math.imul(Z,lt)|0,u=u+Math.imul(Z,ut)|0,f=f+Math.imul(F,ct)|0,e=e+Math.imul(F,dt)|0,e=e+Math.imul(q,ct)|0,u=u+Math.imul(q,dt)|0;var Se=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Se>>>26)|0,Se&=67108863,f=Math.imul(V,ht),e=Math.imul(V,ft),e=e+Math.imul($,ht)|0,u=Math.imul($,ft),f=f+Math.imul(W,lt)|0,e=e+Math.imul(W,ut)|0,e=e+Math.imul(J,lt)|0,u=u+Math.imul(J,ut)|0,f=f+Math.imul(H,ct)|0,e=e+Math.imul(H,dt)|0,e=e+Math.imul(Z,ct)|0,u=u+Math.imul(Z,dt)|0;var Ie=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,f=Math.imul(V,lt),e=Math.imul(V,ut),e=e+Math.imul($,lt)|0,u=Math.imul($,ut),f=f+Math.imul(W,ct)|0,e=e+Math.imul(W,dt)|0,e=e+Math.imul(J,ct)|0,u=u+Math.imul(J,dt)|0;var _e=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(_e>>>26)|0,_e&=67108863,f=Math.imul(V,ct),e=Math.imul(V,dt),e=e+Math.imul($,ct)|0,u=Math.imul($,dt);var Pe=(m+f|0)+((e&8191)<<13)|0;return m=(u+(e>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,d[0]=de,d[1]=me,d[2]=pe,d[3]=ge,d[4]=ve,d[5]=ye,d[6]=we,d[7]=Me,d[8]=Ee,d[9]=Te,d[10]=Ae,d[11]=Re,d[12]=xe,d[13]=Ce,d[14]=be,d[15]=Se,d[16]=Ie,d[17]=_e,d[18]=Pe,m!==0&&(d[19]=m,i.length++),i};Math.imul||(Gt=wt);function sr(c,t,r){r.negative=t.negative^c.negative,r.length=c.length+t.length;for(var i=0,o=0,l=0;l<r.length-1;l++){var d=o;o=0;for(var m=i&67108863,f=Math.min(l,t.length-1),e=Math.max(0,l-c.length+1);e<=f;e++){var u=l-e,w=c.words[u]|0,M=t.words[e]|0,T=w*M,x=T&67108863;d=d+(T/67108864|0)|0,x=x+m|0,m=x&67108863,d=d+(x>>>26)|0,o+=d>>>26,d&=67108863;}r.words[l]=m,i=d,d=o;}return i!==0?r.words[l]=i:r.length--,r._strip()}function or(c,t,r){return sr(c,t,r)}a.prototype.mulTo=function(t,r){var i,o=this.length+t.length;return this.length===10&&t.length===10?i=Gt(this,t,r):o<63?i=wt(this,t,r):o<1024?i=sr(this,t,r):i=or(this,t,r),i};a.prototype.mul=function(t){var r=new a(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},a.prototype.mulf=function(t){var r=new a(null);return r.words=new Array(this.length+t.length),or(this,t,r)},a.prototype.imul=function(t){return this.clone().mulTo(t,this)},a.prototype.imuln=function(t){var r=t<0;r&&(t=-t),h(typeof t=="number"),h(t<67108864);for(var i=0,o=0;o<this.length;o++){var l=(this.words[o]|0)*t,d=(l&67108863)+(i&67108863);i>>=26,i+=l/67108864|0,i+=d>>>26,this.words[o]=d&67108863;}return i!==0&&(this.words[o]=i,this.length++),r?this.ineg():this},a.prototype.muln=function(t){return this.clone().imuln(t)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(t){var r=Et(t);if(r.length===0)return new a(1);for(var i=this,o=0;o<r.length&&r[o]===0;o++,i=i.sqr());if(++o<r.length)for(var l=i.sqr();o<r.length;o++,l=l.sqr())r[o]!==0&&(i=i.mul(l));return i},a.prototype.iushln=function(t){h(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,o=67108863>>>26-r<<26-r,l;if(r!==0){var d=0;for(l=0;l<this.length;l++){var m=this.words[l]&o,f=(this.words[l]|0)-m<<r;this.words[l]=f|d,d=m>>>26-r;}d&&(this.words[l]=d,this.length++);}if(i!==0){for(l=this.length-1;l>=0;l--)this.words[l+i]=this.words[l];for(l=0;l<i;l++)this.words[l]=0;this.length+=i;}return this._strip()},a.prototype.ishln=function(t){return h(this.negative===0),this.iushln(t)},a.prototype.iushrn=function(t,r,i){h(typeof t=="number"&&t>=0);var o;r?o=(r-r%26)/26:o=0;var l=t%26,d=Math.min((t-l)/26,this.length),m=67108863^67108863>>>l<<l,f=i;if(o-=d,o=Math.max(0,o),f){for(var e=0;e<d;e++)f.words[e]=this.words[e];f.length=d;}if(d!==0)if(this.length>d)for(this.length-=d,e=0;e<this.length;e++)this.words[e]=this.words[e+d];else this.words[0]=0,this.length=1;var u=0;for(e=this.length-1;e>=0&&(u!==0||e>=o);e--){var w=this.words[e]|0;this.words[e]=u<<26-l|w>>>l,u=w&m;}return f&&u!==0&&(f.words[f.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(t,r,i){return h(this.negative===0),this.iushrn(t,r,i)},a.prototype.shln=function(t){return this.clone().ishln(t)},a.prototype.ushln=function(t){return this.clone().iushln(t)},a.prototype.shrn=function(t){return this.clone().ishrn(t)},a.prototype.ushrn=function(t){return this.clone().iushrn(t)},a.prototype.testn=function(t){h(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,o=1<<r;if(this.length<=i)return !1;var l=this.words[i];return !!(l&o)},a.prototype.imaskn=function(t){h(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26;if(h(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(r!==0&&i++,this.length=Math.min(i,this.length),r!==0){var o=67108863^67108863>>>r<<r;this.words[this.length-1]&=o;}return this._strip()},a.prototype.maskn=function(t){return this.clone().imaskn(t)},a.prototype.iaddn=function(t){return h(typeof t=="number"),h(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<=t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},a.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},a.prototype.isubn=function(t){if(h(typeof t=="number"),h(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this._strip()},a.prototype.addn=function(t){return this.clone().iaddn(t)},a.prototype.subn=function(t){return this.clone().isubn(t)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(t,r,i){var o=t.length+i,l;this._expand(o);var d,m=0;for(l=0;l<t.length;l++){d=(this.words[l+i]|0)+m;var f=(t.words[l]|0)*r;d-=f&67108863,m=(d>>26)-(f/67108864|0),this.words[l+i]=d&67108863;}for(;l<this.length-i;l++)d=(this.words[l+i]|0)+m,m=d>>26,this.words[l+i]=d&67108863;if(m===0)return this._strip();for(h(m===-1),m=0,l=0;l<this.length;l++)d=-(this.words[l]|0)+m,m=d>>26,this.words[l]=d&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(t,r){var i=this.length-t.length,o=this.clone(),l=t,d=l.words[l.length-1]|0,m=this._countBits(d);i=26-m,i!==0&&(l=l.ushln(i),o.iushln(i),d=l.words[l.length-1]|0);var f=o.length-l.length,e;if(r!=="mod"){e=new a(null),e.length=f+1,e.words=new Array(e.length);for(var u=0;u<e.length;u++)e.words[u]=0;}var w=o.clone()._ishlnsubmul(l,1,f);w.negative===0&&(o=w,e&&(e.words[f]=1));for(var M=f-1;M>=0;M--){var T=(o.words[l.length+M]|0)*67108864+(o.words[l.length+M-1]|0);for(T=Math.min(T/d|0,67108863),o._ishlnsubmul(l,T,M);o.negative!==0;)T--,o.negative=0,o._ishlnsubmul(l,1,M),o.isZero()||(o.negative^=1);e&&(e.words[M]=T);}return e&&e._strip(),o._strip(),r!=="div"&&i!==0&&o.iushrn(i),{div:e||null,mod:o}},a.prototype.divmod=function(t,r,i){if(h(!t.isZero()),this.isZero())return {div:new a(0),mod:new a(0)};var o,l,d;return this.negative!==0&&t.negative===0?(d=this.neg().divmod(t,r),r!=="mod"&&(o=d.div.neg()),r!=="div"&&(l=d.mod.neg(),i&&l.negative!==0&&l.iadd(t)),{div:o,mod:l}):this.negative===0&&t.negative!==0?(d=this.divmod(t.neg(),r),r!=="mod"&&(o=d.div.neg()),{div:o,mod:d.mod}):this.negative&t.negative?(d=this.neg().divmod(t.neg(),r),r!=="div"&&(l=d.mod.neg(),i&&l.negative!==0&&l.isub(t)),{div:d.div,mod:l}):t.length>this.length||this.cmp(t)<0?{div:new a(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new a(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new a(this.modrn(t.words[0]))}:this._wordDiv(t,r)},a.prototype.div=function(t){return this.divmod(t,"div",!1).div},a.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},a.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},a.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var i=r.div.negative!==0?r.mod.isub(t):r.mod,o=t.ushrn(1),l=t.andln(1),d=i.cmp(o);return d<0||l===1&&d===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},a.prototype.modrn=function(t){var r=t<0;r&&(t=-t),h(t<=67108863);for(var i=(1<<26)%t,o=0,l=this.length-1;l>=0;l--)o=(i*o+(this.words[l]|0))%t;return r?-o:o},a.prototype.modn=function(t){return this.modrn(t)},a.prototype.idivn=function(t){var r=t<0;r&&(t=-t),h(t<=67108863);for(var i=0,o=this.length-1;o>=0;o--){var l=(this.words[o]|0)+i*67108864;this.words[o]=l/t|0,i=l%t;}return this._strip(),r?this.ineg():this},a.prototype.divn=function(t){return this.clone().idivn(t)},a.prototype.egcd=function(t){h(t.negative===0),h(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var o=new a(1),l=new a(0),d=new a(0),m=new a(1),f=0;r.isEven()&&i.isEven();)r.iushrn(1),i.iushrn(1),++f;for(var e=i.clone(),u=r.clone();!r.isZero();){for(var w=0,M=1;!(r.words[0]&M)&&w<26;++w,M<<=1);if(w>0)for(r.iushrn(w);w-- >0;)(o.isOdd()||l.isOdd())&&(o.iadd(e),l.isub(u)),o.iushrn(1),l.iushrn(1);for(var T=0,x=1;!(i.words[0]&x)&&T<26;++T,x<<=1);if(T>0)for(i.iushrn(T);T-- >0;)(d.isOdd()||m.isOdd())&&(d.iadd(e),m.isub(u)),d.iushrn(1),m.iushrn(1);r.cmp(i)>=0?(r.isub(i),o.isub(d),l.isub(m)):(i.isub(r),d.isub(o),m.isub(l));}return {a:d,b:m,gcd:i.iushln(f)}},a.prototype._invmp=function(t){h(t.negative===0),h(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var o=new a(1),l=new a(0),d=i.clone();r.cmpn(1)>0&&i.cmpn(1)>0;){for(var m=0,f=1;!(r.words[0]&f)&&m<26;++m,f<<=1);if(m>0)for(r.iushrn(m);m-- >0;)o.isOdd()&&o.iadd(d),o.iushrn(1);for(var e=0,u=1;!(i.words[0]&u)&&e<26;++e,u<<=1);if(e>0)for(i.iushrn(e);e-- >0;)l.isOdd()&&l.iadd(d),l.iushrn(1);r.cmp(i)>=0?(r.isub(i),o.isub(l)):(i.isub(r),l.isub(o));}var w;return r.cmpn(1)===0?w=o:w=l,w.cmpn(0)<0&&w.iadd(t),w},a.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),i=t.clone();r.negative=0,i.negative=0;for(var o=0;r.isEven()&&i.isEven();o++)r.iushrn(1),i.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;i.isEven();)i.iushrn(1);var l=r.cmp(i);if(l<0){var d=r;r=i,i=d;}else if(l===0||i.cmpn(1)===0)break;r.isub(i);}while(!0);return i.iushln(o)},a.prototype.invm=function(t){return this.egcd(t).a.umod(t)},a.prototype.isEven=function(){return (this.words[0]&1)===0},a.prototype.isOdd=function(){return (this.words[0]&1)===1},a.prototype.andln=function(t){return this.words[0]&t},a.prototype.bincn=function(t){h(typeof t=="number");var r=t%26,i=(t-r)/26,o=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=o,this;for(var l=o,d=i;l!==0&&d<this.length;d++){var m=this.words[d]|0;m+=l,l=m>>>26,m&=67108863,this.words[d]=m;}return l!==0&&(this.words[d]=l,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return -1;if(this.negative===0&&r)return 1;this._strip();var i;if(this.length>1)i=1;else {r&&(t=-t),h(t<=67108863,"Number is too big");var o=this.words[0]|0;i=o===t?0:o<t?-1:1;}return this.negative!==0?-i|0:i},a.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return -1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},a.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return -1;for(var r=0,i=this.length-1;i>=0;i--){var o=this.words[i]|0,l=t.words[i]|0;if(o!==l){o<l?r=-1:o>l&&(r=1);break}}return r},a.prototype.gtn=function(t){return this.cmpn(t)===1},a.prototype.gt=function(t){return this.cmp(t)===1},a.prototype.gten=function(t){return this.cmpn(t)>=0},a.prototype.gte=function(t){return this.cmp(t)>=0},a.prototype.ltn=function(t){return this.cmpn(t)===-1},a.prototype.lt=function(t){return this.cmp(t)===-1},a.prototype.lten=function(t){return this.cmpn(t)<=0},a.prototype.lte=function(t){return this.cmp(t)<=0},a.prototype.eqn=function(t){return this.cmpn(t)===0},a.prototype.eq=function(t){return this.cmp(t)===0},a.red=function(t){return new N(t)},a.prototype.toRed=function(t){return h(!this.red,"Already a number in reduction context"),h(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},a.prototype.fromRed=function(){return h(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(t){return this.red=t,this},a.prototype.forceRed=function(t){return h(!this.red,"Already a number in reduction context"),this._forceRed(t)},a.prototype.redAdd=function(t){return h(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},a.prototype.redIAdd=function(t){return h(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},a.prototype.redSub=function(t){return h(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},a.prototype.redISub=function(t){return h(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},a.prototype.redShl=function(t){return h(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},a.prototype.redMul=function(t){return h(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},a.prototype.redIMul=function(t){return h(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},a.prototype.redSqr=function(){return h(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return h(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return h(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return h(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return h(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(t){return h(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var ue={k256:null,p224:null,p192:null,p25519:null};function gt(c,t){this.name=c,this.p=new a(t,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp();}gt.prototype._tmp=function(){var t=new a(null);return t.words=new Array(Math.ceil(this.n/13)),t},gt.prototype.ireduce=function(t){var r=t,i;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),i=r.bitLength();while(i>this.n);var o=i<this.n?-1:r.ucmp(this.p);return o===0?(r.words[0]=0,r.length=1):o>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},gt.prototype.split=function(t,r){t.iushrn(this.n,0,r);},gt.prototype.imulK=function(t){return t.imul(this.k)};function Ft(){gt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");}p(Ft,gt),Ft.prototype.split=function(t,r){for(var i=4194303,o=Math.min(t.length,9),l=0;l<o;l++)r.words[l]=t.words[l];if(r.length=o,t.length<=9){t.words[0]=0,t.length=1;return}var d=t.words[9];for(r.words[r.length++]=d&i,l=10;l<t.length;l++){var m=t.words[l]|0;t.words[l-10]=(m&i)<<4|d>>>22,d=m;}d>>>=22,t.words[l-10]=d,d===0&&t.length>10?t.length-=10:t.length-=9;},Ft.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,i=0;i<t.length;i++){var o=t.words[i]|0;r+=o*977,t.words[i]=r&67108863,r=o*64+(r/67108864|0);}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function hr(){gt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");}p(hr,gt);function fr(){gt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");}p(fr,gt);function ce(){gt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");}p(ce,gt),ce.prototype.imulK=function(t){for(var r=0,i=0;i<t.length;i++){var o=(t.words[i]|0)*19+r,l=o&67108863;o>>>=26,t.words[i]=l,r=o;}return r!==0&&(t.words[t.length++]=r),t},a._prime=function(t){if(ue[t])return ue[t];var r;if(t==="k256")r=new Ft;else if(t==="p224")r=new hr;else if(t==="p192")r=new fr;else if(t==="p25519")r=new ce;else throw new Error("Unknown prime "+t);return ue[t]=r,r};function N(c){if(typeof c=="string"){var t=a._prime(c);this.m=t.p,this.prime=t;}else h(c.gtn(1),"modulus must be greater than 1"),this.m=c,this.prime=null;}N.prototype._verify1=function(t){h(t.negative===0,"red works only with positives"),h(t.red,"red works only with red numbers");},N.prototype._verify2=function(t,r){h((t.negative|r.negative)===0,"red works only with positives"),h(t.red&&t.red===r.red,"red works only with red numbers");},N.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(C(t,t.umod(this.m)._forceRed(this)),t)},N.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},N.prototype.add=function(t,r){this._verify2(t,r);var i=t.add(r);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},N.prototype.iadd=function(t,r){this._verify2(t,r);var i=t.iadd(r);return i.cmp(this.m)>=0&&i.isub(this.m),i},N.prototype.sub=function(t,r){this._verify2(t,r);var i=t.sub(r);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},N.prototype.isub=function(t,r){this._verify2(t,r);var i=t.isub(r);return i.cmpn(0)<0&&i.iadd(this.m),i},N.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},N.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},N.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},N.prototype.isqr=function(t){return this.imul(t,t.clone())},N.prototype.sqr=function(t){return this.mul(t,t)},N.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(h(r%2===1),r===3){var i=this.m.add(new a(1)).iushrn(2);return this.pow(t,i)}for(var o=this.m.subn(1),l=0;!o.isZero()&&o.andln(1)===0;)l++,o.iushrn(1);h(!o.isZero());var d=new a(1).toRed(this),m=d.redNeg(),f=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new a(2*e*e).toRed(this);this.pow(e,f).cmp(m)!==0;)e.redIAdd(m);for(var u=this.pow(e,o),w=this.pow(t,o.addn(1).iushrn(1)),M=this.pow(t,o),T=l;M.cmp(d)!==0;){for(var x=M,b=0;x.cmp(d)!==0;b++)x=x.redSqr();h(b<T);var I=this.pow(u,new a(1).iushln(T-b-1));w=w.redMul(I),u=I.redSqr(),M=M.redMul(u),T=b;}return w},N.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},N.prototype.pow=function(t,r){if(r.isZero())return new a(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var i=4,o=new Array(1<<i);o[0]=new a(1).toRed(this),o[1]=t;for(var l=2;l<o.length;l++)o[l]=this.mul(o[l-1],t);var d=o[0],m=0,f=0,e=r.bitLength()%26;for(e===0&&(e=26),l=r.length-1;l>=0;l--){for(var u=r.words[l],w=e-1;w>=0;w--){var M=u>>w&1;if(d!==o[0]&&(d=this.sqr(d)),M===0&&m===0){f=0;continue}m<<=1,m|=M,f++,!(f!==i&&(l!==0||w!==0))&&(d=this.mul(d,o[m]),f=0,m=0);}e=26;}return d},N.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},N.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},a.mont=function(t){return new St(t)};function St(c){N.call(this,c),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(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);}p(St,N),St.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},St.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},St.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),o=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),l=i.isub(o).iushrn(this.shift),d=l;return l.cmp(this.m)>=0?d=l.isub(this.m):l.cmpn(0)<0&&(d=l.iadd(this.m)),d._forceRed(this)},St.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new a(0)._forceRed(this);var i=t.mul(r),o=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),l=i.isub(o).iushrn(this.shift),d=l;return l.cmp(this.m)>=0?d=l.isub(this.m):l.cmpn(0)<0&&(d=l.iadd(this.m)),d._forceRed(this)},St.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)};})(typeof Le>"u"||Le,Fr);});var Fe=qt((ka,Wr)=>{Wr.exports=Ge;Ge.strict=Hr;Ge.loose=Zr;var ti=Object.prototype.toString,ei={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0};function Ge(n){return Hr(n)||Zr(n)}function Hr(n){return n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray||n instanceof Uint16Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array}function Zr(n){return ei[ti.call(n)]}});var Vr=qt((Ua,Jr)=>{var ri=Fe().strict;Jr.exports=function(s){if(ri(s)){var h=Buffer.from(s.buffer);return s.byteLength!==s.buffer.byteLength&&(h=h.slice(s.byteOffset,s.byteOffset+s.byteLength)),h}else return Buffer.from(s)};});var hn=qt(E=>{var $r=E&&E.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(E,"__esModule",{value:!0});var ni=$r(Fe()),ii=$r(Vr()),qe="hex",He="utf8",ai="binary",si="buffer",oi="array",hi="typed-array",fi="array-buffer",Bt="0";function zt(n){return new Uint8Array(n)}E.bufferToArray=zt;function Ze(n,s=!1){let h=n.toString(qe);return s?Qt(h):h}E.bufferToHex=Ze;function We(n){return n.toString(He)}E.bufferToUtf8=We;function zr(n){return n.readUIntBE(0,n.length)}E.bufferToNumber=zr;function li(n){return jt(zt(n))}E.bufferToBinary=li;function kt(n){return ii.default(n)}E.arrayToBuffer=kt;function jr(n,s=!1){return Ze(kt(n),s)}E.arrayToHex=jr;function Yr(n){return We(kt(n))}E.arrayToUtf8=Yr;function Je(n){return zr(kt(n))}E.arrayToNumber=Je;function jt(n){return Array.from(n).map(Ut).join("")}E.arrayToBinary=jt;function Ve(n){return Buffer.from(Xt(n),qe)}E.hexToBuffer=Ve;function $e(n){return zt(Ve(n))}E.hexToArray=$e;function ui(n){return We(Ve(n))}E.hexToUtf8=ui;function ci(n){return Je($e(n))}E.hexToNumber=ci;function Kr(n){return jt($e(n))}E.hexToBinary=Kr;function ze(n){return Buffer.from(n,He)}E.utf8ToBuffer=ze;function Xr(n){return zt(ze(n))}E.utf8ToArray=Xr;function di(n,s=!1){return Ze(ze(n),s)}E.utf8ToHex=di;function mi(n){let s=parseInt(n,10);return Bi(Di(s),"Number can only safely store up to 53 bits"),s}E.utf8ToNumber=mi;function pi(n){return jt(Xr(n))}E.utf8ToBinary=pi;function gi(n){return Qr(Ut(n))}E.numberToBuffer=gi;function vi(n){return _t(Ut(n))}E.numberToArray=vi;function yi(n,s){return je(Ut(n),s)}E.numberToHex=yi;function wi(n){return `${n}`}E.numberToUtf8=wi;function Ut(n){let s=(n>>>0).toString(2);return Kt(s)}E.numberToBinary=Ut;function Qr(n){return kt(_t(n))}E.binaryToBuffer=Qr;function _t(n){return new Uint8Array(Ke(n).map(s=>parseInt(s,2)))}E.binaryToArray=_t;function je(n,s){return jr(_t(n),s)}E.binaryToHex=je;function Mi(n){return Yr(_t(n))}E.binaryToUtf8=Mi;function Ei(n){return Je(_t(n))}E.binaryToNumber=Ei;function tn(n){return !(typeof n!="string"||!new RegExp(/^[01]+$/).test(n)||n.length%8!==0)}E.isBinaryString=tn;function en(n,s){return !(typeof n!="string"||!n.match(/^0x[0-9A-Fa-f]*$/)||s&&n.length!==2+2*s)}E.isHexString=en;function Yt(n){return Buffer.isBuffer(n)}E.isBuffer=Yt;function Ye(n){return ni.default.strict(n)&&!Yt(n)}E.isTypedArray=Ye;function rn(n){return !Ye(n)&&!Yt(n)&&typeof n.byteLength<"u"}E.isArrayBuffer=rn;function Ti(n){return Yt(n)?si:Ye(n)?hi:rn(n)?fi:Array.isArray(n)?oi:typeof n}E.getType=Ti;function Ai(n){return tn(n)?ai:en(n)?qe:He}E.getEncoding=Ai;function Ri(...n){return Buffer.concat(n)}E.concatBuffers=Ri;function xi(...n){let s=[];return n.forEach(h=>s=s.concat(Array.from(h))),new Uint8Array([...s])}E.concatArrays=xi;function Ci(n,s){let h=n.length-s;return h>0&&(n=n.slice(h)),n}E.trimLeft=Ci;function bi(n,s){return n.slice(0,s)}E.trimRight=bi;function nn(n,s=8){let h=n%s;return h?(n-h)/s*s+s:n}E.calcByteLength=nn;function Ke(n,s=8){let h=Kt(n).match(new RegExp(`.{${s}}`,"gi"));return Array.from(h||[])}E.splitBytes=Ke;function an(n){return Ke(n).map(ki).join("")}E.swapBytes=an;function Si(n){return je(an(Kr(n)))}E.swapHex=Si;function Kt(n,s=8,h=Bt){return sn(n,nn(n.length,s),h)}E.sanitizeBytes=Kt;function sn(n,s,h=Bt){return on(n,s,!0,h)}E.padLeft=sn;function Ii(n,s,h=Bt){return on(n,s,!1,h)}E.padRight=Ii;function Xt(n){return n.replace(/^0x/,"")}E.removeHexPrefix=Xt;function Qt(n){return n.startsWith("0x")?n:`0x${n}`}E.addHexPrefix=Qt;function _i(n){return n=Xt(n),n=Kt(n,2),n&&(n=Qt(n)),n}E.sanitizeHex=_i;function Pi(n){let s=n.startsWith("0x");return n=Xt(n),n=n.startsWith(Bt)?n.substring(1):n,s?Qt(n):n}E.removeHexLeadingZeros=Pi;function Ni(n){return typeof n>"u"}function Di(n){return !Ni(n)}function Bi(n,s){if(!n)throw new Error(s)}function ki(n){return n.split("").reverse().join("")}function on(n,s,h,p=Bt){let a=s-n.length,g=n;if(a>0){let v=p.repeat(a);g=h?v+n:n+v;}return g}});var It=class{emitter=new events.EventEmitter;emit(s,...h){this.emitter.emit(s,...h);}on(s,h){this.emitter.on(s,h);}removeListener(s,h){this.emitter.removeListener(s,h);}};var Sr=(p=>(p.LOGGED_OUT="loggedOut",p.LOGGED_IN="loggedIn",p.ACCOUNTS_REQUESTED="accountsRequested",p))(Sr||{}),qn=(s=>(s.ACCOUNTS_CHANGED="accountsChanged",s))(qn||{}),Hn=(v=>(v.PENDING="PENDING",v.SUBMITTED="SUBMITTED",v.SUCCESSFUL="SUCCESSFUL",v.REVERTED="REVERTED",v.FAILED="FAILED",v.CANCELLED="CANCELLED",v))(Hn||{});var Gr={};Ln(Gr,{coerceNonceSpace:()=>Or,digestOfTransactionsAndNonce:()=>Ur,encodeMessageSubDigest:()=>Wt,encodeNonce:()=>Lr,encodedTransactions:()=>ke,getEip155ChainId:()=>pt,getNonce:()=>Nt,getNormalisedTransactions:()=>Zt,packSignatures:()=>Vt,signAndPackTypedData:()=>Ue,signERC191Message:()=>Oe,signMetaTransactions:()=>Jt});var Dr=1,Yn=1,Kn=2,Br="02",Xn="",kr=`tuple(
38
+ bool delegateCall,
39
+ bool revertOnError,
40
+ uint256 gasLimit,
41
+ address target,
42
+ uint256 value,
43
+ bytes data
44
+ )[]`,Zt=n=>n.map(s=>({delegateCall:s.delegateCall===!0,revertOnError:s.revertOnError===!0,gasLimit:s.gasLimit??BigInt(0),target:s.to??ethers.ZeroAddress,value:s.value??BigInt(0),data:s.data??"0x"})),Ur=(n,s)=>{let h=ethers.AbiCoder.defaultAbiCoder().encode(["uint256",kr],[n,s]);return ethers.keccak256(h)},ke=n=>ethers.AbiCoder.defaultAbiCoder().encode([kr],[n]),Or=n=>n||0n,Lr=(n,s)=>{let h=BigInt(n)*2n**96n;return BigInt(s)+h},Nt=async(n,s,h)=>{try{let p=new ethers.Contract(s,abi.walletContracts.mainModule.abi,n),a=Or(h),g=await p.readNonce(a);if(typeof g=="bigint")return Lr(a,g);throw new Error("Unexpected result from contract.nonce() call.")}catch(p){if(ethers.isError(p,"BAD_DATA"))return BigInt(0);throw p}},Wt=(n,s,h)=>ethers.solidityPacked(["string","uint256","address","bytes32"],[Xn,n,s,h]),Jt=async(n,s,h,p,a)=>{let g=Zt(n),v=Ur(s,g),y=Wt(h,p,v),A=ethers.keccak256(y),C=ethers.getBytes(A),D=`${await a.signMessage(C)}${Br}`,mt=core.v1.signature.encodeSignature({version:1,threshold:Yn,signers:[{isDynamic:!1,unrecovered:!0,weight:Dr,signature:D}]}),yt=new ethers.Interface(abi.walletContracts.mainModule.abi);return yt.encodeFunctionData(yt.getFunction("execute")??"",[g,s,mt])},Qn=n=>{let s=`0x0000${n}`;return core.v1.signature.decodeSignature(s)},Vt=(n,s,h)=>{let p=`${n}${Br}`,{signers:a}=Qn(h),v=[...a,{isDynamic:!1,unrecovered:!0,weight:Dr,signature:p,address:s}].sort((y,A)=>{let C=BigInt(y.address??0),S=BigInt(A.address??0);return C<=S?-1:C===S?0:1});return core.v1.signature.encodeSignature({version:1,threshold:Kn,signers:v})},Ue=async(n,s,h,p,a)=>{let g={...n.types};delete g.EIP712Domain;let v=ethers.TypedDataEncoder.hash(n.domain,g,n.message),y=Wt(h,p,v),A=ethers.keccak256(y),C=ethers.getBytes(A),S=await a.signMessage(C),D=await a.getAddress();return Vt(S,D,s)},Oe=async(n,s,h,p)=>{let a=ethers.hashMessage(s),g=Wt(n,p,a),v=ethers.keccak256(g),y=ethers.getBytes(v);return h.signMessage(y)},pt=n=>`eip155:${n}`;var Dt=class n{config;rpcProvider;authManager;constructor({config:s,rpcProvider:h,authManager:p}){this.config=s,this.rpcProvider=h,this.authManager=p;}static getResponsePreview(s){return s.length>100?`${s.substring(0,50)}...${s.substring(s.length-50)}`:s}async postToRelayer(s){let h={id:1,jsonrpc:"2.0",...s},p=await this.authManager.getUserZkEvm(),a=await fetch(`${this.config.relayerUrl}/v1/transactions`,{method:"POST",headers:{Authorization:`Bearer ${p.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(h)}),g=await a.text();if(!a.ok){let y=n.getResponsePreview(g);throw new Error(`Relayer HTTP error: ${a.status}. Content: "${y}"`)}let v;try{v=JSON.parse(g);}catch(y){let A=n.getResponsePreview(g);throw new Error(`Relayer JSON parse error: ${y instanceof Error?y.message:"Unknown error"}. Content: "${A}"`)}if(v.error)throw new Error(v.error);return v}async ethSendTransaction(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"eth_sendTransaction",params:[{to:s,data:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}async imGetTransactionByHash(s){let h={method:"im_getTransactionByHash",params:[s]},{result:p}=await this.postToRelayer(h);return p}async imGetFeeOptions(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"im_getFeeOptions",params:[{userAddress:s,data:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}async imSignTypedData(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"im_signTypedData",params:[{address:s,eip712Payload:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}async imSign(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"im_sign",params:[{address:s,message:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}};var $t=(a=>(a[a.USER_REJECTED_REQUEST=4001]="USER_REJECTED_REQUEST",a[a.UNAUTHORIZED=4100]="UNAUTHORIZED",a[a.UNSUPPORTED_METHOD=4200]="UNSUPPORTED_METHOD",a[a.DISCONNECTED=4900]="DISCONNECTED",a))($t||{}),Tt=(y=>(y[y.RPC_SERVER_ERROR=-32e3]="RPC_SERVER_ERROR",y[y.INVALID_REQUEST=-32600]="INVALID_REQUEST",y[y.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",y[y.INVALID_PARAMS=-32602]="INVALID_PARAMS",y[y.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",y[y.PARSE_ERROR=-32700]="PARSE_ERROR",y[y.TRANSACTION_REJECTED=-32003]="TRANSACTION_REJECTED",y))(Tt||{}),R=class extends Error{message;code;constructor(s,h){super(h),this.message=h,this.code=s;}};var Rt=br(qr()),xt=br(hn());function Ui(n){return xt.addHexPrefix(xt.padLeft(n.r.toString(16),64)+xt.padLeft(n.s.toString(16),64)+xt.padLeft(n.recoveryParam?.toString(16)||"",2))}function Oi(n){let s=new Rt.default(n,16).cmp(new Rt.default(27))!==-1?new Rt.default(n,16).sub(new Rt.default(27)).toNumber():new Rt.default(n,16).toNumber();return n.trim()?s:void 0}function Li(n,s=64){let h=xt.removeHexPrefix(n);return {r:new Rt.default(h.substring(0,s),"hex"),s:new Rt.default(h.substring(s,s*2),"hex"),recoveryParam:Oi(h.substring(s*2,s*2+2))}}async function fn(n,s){let h=Li(await s.signMessage(n));return Ui(h)}var Gi="Only sign this message from Immutable Passport";async function ln({authManager:n,ethSigner:s,multiRollupApiClients:h,accessToken:p,rpcProvider:a,flow:g}){let v=s.getAddress();v.then(()=>g.addEvent("endGetAddress"));let y=fn(Gi,s);y.then(()=>g.addEvent("endSignRaw"));let A=a.getNetwork();A.then(()=>g.addEvent("endDetectNetwork"));let C=h.chainsApi.listChains();C.then(()=>g.addEvent("endListChains"));let[S,D,mt,yt]=await Promise.all([v,y,A,C]),bt=pt(Number(mt.chainId)),Et=yt.data?.result?.find(wt=>wt.id===bt)?.name;if(!Et)throw new R(-32603,`Chain name does not exist on for chain id ${mt.chainId}`);try{let wt=await h.passportApi.createCounterfactualAddressV2({chainName:Et,createCounterfactualAddressRequest:{ethereum_address:S,ethereum_signature:D}},{headers:{Authorization:`Bearer ${p}`}});return g.addEvent("endCreateCounterfactualAddress"),n.forceUserRefreshInBackground(),wt.data.counterfactual_address}catch(wt){throw new R(-32603,`Failed to create counterfactual address: ${wt}`)}}var Fi=n=>new Promise(s=>{setTimeout(()=>s(),n);}),Pt=async(n,s)=>{let{retries:h=3,interval:p=1e3,finalErr:a=Error("Retry failed"),finallyFn:g=()=>{}}=s||{};try{return await n()}catch{return h<=0?Promise.reject(a):(await Fi(p),Pt(n,{retries:h-1,finalErr:a,finallyFn:g}))}finally{h<=0&&g();}};var te=(y=>(y.WALLET_CONNECTION_ERROR="WALLET_CONNECTION_ERROR",y.TRANSACTION_REJECTED="TRANSACTION_REJECTED",y.INVALID_CONFIGURATION="INVALID_CONFIGURATION",y.UNAUTHORIZED="UNAUTHORIZED",y.GUARDIAN_ERROR="GUARDIAN_ERROR",y.SERVICE_UNAVAILABLE_ERROR="SERVICE_UNAVAILABLE_ERROR",y.NOT_LOGGED_IN_ERROR="NOT_LOGGED_IN_ERROR",y))(te||{}),vt=class extends Error{type;constructor(s,h){super(s),this.name="WalletError",this.type=h;}};var ee="Transaction requires confirmation but this functionality is not supported in this environment. Please contact Immutable support if you need to enable this feature.",re=n=>BigInt(n).toString(),Hi=n=>{try{return n.map(s=>({delegateCall:s.delegateCall===!0,revertOnError:s.revertOnError===!0,gasLimit:s.gasLimit?re(s.gasLimit):"0",target:s.to??ethers.ZeroAddress,value:s.value?re(s.value):"0",data:s.data?s.data.toString():"0x"}))}catch(s){let h=s instanceof Error?s.message:String(s);throw new R(-32602,`Transaction failed to parsing: ${h}`)}},ne=class{guardianApi;confirmationScreen;crossSdkBridgeEnabled;authManager;constructor({confirmationScreen:s,config:h,authManager:p,guardianApi:a}){this.confirmationScreen=s,this.crossSdkBridgeEnabled=h.crossSdkBridgeEnabled,this.guardianApi=a,this.authManager=p;}withConfirmationScreen(s){return h=>this.withConfirmationScreenTask(s)(h)()}withConfirmationScreenTask(s){return h=>async()=>{this.confirmationScreen.loading(s);try{return await h()}catch(p){throw p instanceof vt&&p.type==="SERVICE_UNAVAILABLE_ERROR"?(await this.confirmationScreen.showServiceUnavailable(),p):(this.confirmationScreen.closeWindow(),p)}}}withDefaultConfirmationScreenTask(s){return this.withConfirmationScreenTask()(s)}async evaluateImxTransaction({payloadHash:s}){try{let h=()=>{this.confirmationScreen.closeWindow();},p=await this.authManager.getUserImx(),a={Authorization:`Bearer ${p.accessToken}`};if(!(await Pt(async()=>this.guardianApi.getTransactionByID({transactionID:s,chainType:"starkex"},{headers:a}),{finallyFn:h})).data.id)throw new Error("Transaction doesn't exists");let v=await this.guardianApi.evaluateTransaction({id:s,transactionEvaluationRequest:{chainType:"starkex"}},{headers:a}),{confirmationRequired:y}=v.data;if(y){if(this.crossSdkBridgeEnabled)throw new Error(ee);if(!(await this.confirmationScreen.requestConfirmation(s,p.imx.ethAddress,Xe__namespace.mr.TransactionApprovalRequestChainTypeEnum.Starkex)).confirmed)throw new Error("Transaction rejected by user")}else this.confirmationScreen.closeWindow();}catch(h){throw un__default.default.isAxiosError(h)&&h.response?.status===403?new vt("Service unavailable","SERVICE_UNAVAILABLE_ERROR"):h}}async evaluateEVMTransaction({chainId:s,nonce:h,metaTransactions:p}){let a=await this.authManager.getUserZkEvm(),g={Authorization:`Bearer ${a.accessToken}`},v=Hi(p);try{return (await this.guardianApi.evaluateTransaction({id:"evm",transactionEvaluationRequest:{chainType:"evm",chainId:s,transactionData:{nonce:h,userAddress:a.zkEvm.ethAddress,metaTransactions:v}}},{headers:g})).data}catch(y){if(un__default.default.isAxiosError(y)&&y.response?.status===403)throw new vt("Service unavailable","SERVICE_UNAVAILABLE_ERROR");let A=y instanceof Error?y.message:String(y);throw new R(-32603,`Transaction failed to validate with error: ${A}`)}}async validateEVMTransaction({chainId:s,nonce:h,metaTransactions:p,isBackgroundTransaction:a}){let g=await this.evaluateEVMTransaction({chainId:s,nonce:h,metaTransactions:p}),{confirmationRequired:v,transactionId:y}=g;if(v&&this.crossSdkBridgeEnabled)throw new R(-32003,ee);if(v&&y){let A=await this.authManager.getUserZkEvm();if(!(await this.confirmationScreen.requestConfirmation(y,A.zkEvm.ethAddress,Xe__namespace.mr.TransactionApprovalRequestChainTypeEnum.Evm,s)).confirmed)throw new R(-32003,"Transaction rejected by user")}else a||this.confirmationScreen.closeWindow();}async handleEIP712MessageEvaluation({chainID:s,payload:h}){try{let p=await this.authManager.getUserZkEvm();if(p===null)throw new R(4100,"User not logged in. Please log in first.");return (await this.guardianApi.evaluateMessage({messageEvaluationRequest:{chainID:s,payload:h}},{headers:{Authorization:`Bearer ${p.accessToken}`}})).data}catch(p){let a=p instanceof Error?p.message:String(p);throw new R(-32603,`Message failed to validate with error: ${a}`)}}async evaluateEIP712Message({chainID:s,payload:h}){let{messageId:p,confirmationRequired:a}=await this.handleEIP712MessageEvaluation({chainID:s,payload:h});if(a&&this.crossSdkBridgeEnabled)throw new R(-32003,ee);if(a&&p){let g=await this.authManager.getUserZkEvm();if(!(await this.confirmationScreen.requestMessageConfirmation(p,g.zkEvm.ethAddress,"eip712")).confirmed)throw new R(-32003,"Signature rejected by user")}else this.confirmationScreen.closeWindow();}async handleERC191MessageEvaluation({chainID:s,payload:h}){try{let p=await this.authManager.getUserZkEvm();if(p===null)throw new R(4100,"User not logged in. Please log in first.");return (await this.guardianApi.evaluateErc191Message({eRC191MessageEvaluationRequest:{chainID:pt(Number(s)),payload:h}},{headers:{Authorization:`Bearer ${p.accessToken}`}})).data}catch(p){let a=p instanceof Error?p.message:String(p);throw new R(-32603,`Message failed to validate with error: ${a}`)}}async evaluateERC191Message({chainID:s,payload:h}){let{messageId:p,confirmationRequired:a}=await this.handleERC191MessageEvaluation({chainID:s,payload:h});if(a&&this.crossSdkBridgeEnabled)throw new R(-32003,ee);if(a&&p){let g=await this.authManager.getUserZkEvm();if(!(await this.confirmationScreen.requestMessageConfirmation(p,g.zkEvm.ethAddress,"erc191")).confirmed)throw new R(-32003,"Signature rejected by user")}else this.confirmationScreen.closeWindow();}};var Zi=30,Wi=1e3,Ji=async(n,s,h)=>{let p=Zt([n]),a=ke(p),g=await h.imGetFeeOptions(s,a);if(!g||!Array.isArray(g))throw new Error("Invalid fee options received from relayer");let v=g.find(y=>y.tokenSymbol==="IMX");if(!v)throw new Error("Failed to retrieve fees for IMX token");return v},Vi=async(n,s,h,p,a)=>{if(!n.to)throw new R(-32602,'eth_sendTransaction requires a "to" field');let g={to:n.to.toString(),data:n.data,nonce:BigInt(0),value:n.value,revertOnError:!0},[v,y]=await Promise.all([Nt(s,p,a),Ji(g,p,h)]),A=[{...g,nonce:v}],C=BigInt(y.tokenPrice);return C!==BigInt(0)&&A.push({nonce:v,to:y.recipientAddress,value:C,revertOnError:!0}),A},ie=async(n,s,h)=>{let a=await Pt(async()=>{let g=await n.imGetTransactionByHash(s);if(g.status==="PENDING")throw new Error;return g},{retries:Zi,interval:Wi,finalErr:new R(-32e3,"transaction hash not generated in time")});if(h.addEvent("endRetrieveRelayerTransaction"),!["SUBMITTED","SUCCESSFUL"].includes(a.status)){let g=`Transaction failed to submit with status ${a.status}.`;throw a.statusMessage&&(g+=` Error message: ${a.statusMessage}`),new R(-32e3,g)}return a},ae=async({transactionRequest:n,ethSigner:s,rpcProvider:h,guardianClient:p,relayerClient:a,zkEvmAddress:g,flow:v,nonceSpace:y,isBackgroundTransaction:A})=>{let{chainId:C}=await h.getNetwork(),S=BigInt(C);v.addEvent("endDetectNetwork");let D=await Vi(n,h,a,g,y);v.addEvent("endBuildMetaTransactions");let{nonce:mt}=D[0];if(typeof mt>"u")throw new Error("Failed to retrieve nonce from the smart wallet");let yt=async()=>{await p.validateEVMTransaction({chainId:pt(Number(C)),nonce:re(mt),metaTransactions:D,isBackgroundTransaction:A}),v.addEvent("endValidateEVMTransaction");},bt=async()=>{let Gt=await Jt(D,mt,S,g,s);return v.addEvent("endGetSignedMetaTransactions"),Gt},[,Et]=await Promise.all([yt(),bt()]),wt=await a.ethSendTransaction(g,Et);return v.addEvent("endRelayerSendTransaction"),{signedTransactions:Et,relayerId:wt,nonce:mt}},$i=async n=>{if(!n.to)throw new R(-32602,'im_signEjectionTransaction requires a "to" field');if(typeof n.nonce>"u")throw new R(-32602,'im_signEjectionTransaction requires a "nonce" field');if(!n.chainId)throw new R(-32602,'im_signEjectionTransaction requires a "chainId" field');return [{to:n.to.toString(),data:n.data,nonce:n.nonce??void 0,value:n.value,revertOnError:!0}]},cn=async({transactionRequest:n,ethSigner:s,zkEvmAddress:h,flow:p})=>{let a=await $i(n);p.addEvent("endBuildMetaTransactions");let g=await Jt(a,n.nonce,BigInt(n.chainId??0),h,s);return p.addEvent("endGetSignedMetaTransactions"),{to:h,data:g,chainId:pt(Number(n.chainId??0))}};var Qe=async({params:n,ethSigner:s,rpcProvider:h,relayerClient:p,guardianClient:a,zkEvmAddress:g,flow:v,nonceSpace:y,isBackgroundTransaction:A=!1})=>{let C=n[0],{relayerId:S}=await ae({transactionRequest:C,ethSigner:s,rpcProvider:h,guardianClient:a,relayerClient:p,zkEvmAddress:g,flow:v,nonceSpace:y,isBackgroundTransaction:A}),{hash:D}=await ie(p,S,v);return D};var dn=["types","domain","primaryType","message"],zi=n=>dn.every(s=>s in n),ji=(n,s)=>{let h;if(typeof n=="string")try{h=JSON.parse(n);}catch(a){throw new R(-32602,`Failed to parse typed data JSON: ${a}`)}else if(typeof n=="object")h=n;else throw new R(-32602,`Invalid typed data argument: ${n}`);if(!zi(h))throw new R(-32602,`Invalid typed data argument. The following properties are required: ${dn.join(", ")}`);let p=h.domain?.chainId;if(p&&(typeof p=="string"&&(p.startsWith("0x")?h.domain.chainId=parseInt(p,16).toString():h.domain.chainId=parseInt(p,10).toString()),BigInt(h.domain.chainId??0)!==s))throw new R(-32602,`Invalid chainId, expected ${s}`);return h},mn=async({params:n,method:s,ethSigner:h,rpcProvider:p,relayerClient:a,guardianClient:g,flow:v})=>{let y=n[0],A=n[1];if(!y||!A)throw new R(-32602,`${s} requires an address and a typed data JSON`);let{chainId:C}=await p.getNetwork(),S=ji(A,C);v.addEvent("endDetectNetwork"),await g.evaluateEIP712Message({chainID:String(C),payload:S}),v.addEvent("endValidateMessage");let D=await a.imSignTypedData(y,S);v.addEvent("endRelayerSignTypedData");let mt=await Ue(S,D,BigInt(C),y,h);return v.addEvent("getSignedTypedData"),mt};var pn=n=>{if(!n)return n;try{let s=ethers.stripZerosLeft(ethers.getBytes(n));return ethers.toUtf8String(s)}catch{return n}};var se=async({params:n,ethSigner:s,zkEvmAddress:h,rpcProvider:p,guardianClient:a,relayerClient:g,flow:v})=>{let y=n[0],A=n[1];if(!A||!y)throw new R(-32602,"personal_sign requires an address and a message");if(A.toLowerCase()!==h.toLowerCase())throw new R(-32602,"personal_sign requires the signer to be the from address");let C=pn(y),{chainId:S}=await p.getNetwork();v.addEvent("endDetectNetwork");let D=BigInt(S),mt=Oe(D,C,s,A);mt.then(()=>v.addEvent("endEOASignature")),await a.evaluateERC191Message({chainID:S,payload:C}),v.addEvent("endEvaluateERC191Message");let[yt,bt]=await Promise.all([mt,g.imSign(A,C)]);v.addEvent("endRelayerSign");let Et=await s.getAddress();return v.addEvent("endGetEOAAddress"),Vt(yt,Et,bt)};var ta="https://api.immutable.com",ea="https://api.sandbox.immutable.com",ra="/v1/sdk/session-activity/check",na=n=>{switch(n){case config.Environment.SANDBOX:return ea;case config.Environment.PRODUCTION:return ta;default:throw new Error("Environment not supported")}},oe,vn=n=>{oe||(oe=un__default.default.create({baseURL:na(n)}));};async function yn(n){if(!oe)throw new Error("Client not initialised");return oe.get(ra,{params:n}).then(s=>s.data).catch(s=>{if(s.response.status!==404)throw s})}function Mn(n,s){return (...h)=>{try{let p=n(...h);return p instanceof Promise?p.catch(a=>(a instanceof Error&&metrics.trackError("passport","sessionActivityError",a),s)):p}catch(p){return p instanceof Error&&metrics.trackError("passport","sessionActivityError",p),s}}}var{getItem:En,setItem:tr}=metrics.utils.localStorage,er="sessionActivitySendCount",Tn="sessionActivityDate",rr={},Ct={},he={},An=()=>{Ct=En(er)||{};let n=En(Tn),s=new Date,h=s.getFullYear(),p=`${s.getMonth()+1}`.padStart(2,"0"),a=`${s.getDate()}`.padStart(2,"0"),g=`${h}-${p}-${a}`;(!n||n!==g)&&(Ct={}),tr(Tn,g),tr(er,Ct);};An();var ha=n=>{An(),Ct[n]||(Ct[n]=0),Ct[n]++,tr(er,Ct),rr[n]=0;},fa=async n=>new Promise(s=>{setTimeout(s,n*1e3);}),la=async n=>{let s=n.flow||metrics.trackFlow("passport","sendSessionActivity"),h=n.passportClient;if(!h)throw s.addEvent("No Passport Client ID"),new Error("No Passport Client ID provided");if(he[h])return;he[h]=!0;let{sendTransaction:p,environment:a}=n;if(!p)throw new Error("No sendTransaction function provided");if(!a)throw new Error("No environment provided");vn(a);let g=n.walletAddress;if(!g)throw s.addEvent("No Passport Wallet Address"),new Error("No wallet address");let v;try{if(v=await yn({clientId:h,wallet:g,checkCount:rr[h]||0,sendCount:Ct[h]||0}),rr[h]++,!v)return}catch(y){throw s.addEvent("Failed to fetch details"),new Error("Failed to get details",{cause:y})}if(v&&v.contractAddress&&v.functionName){let A=new ethers.Interface([`function ${v.functionName}()`]).encodeFunctionData(v.functionName),C=v.contractAddress;try{s.addEvent("Start Sending Transaction");let S=await n.sendTransaction([{to:C,from:g,data:A}],s);ha(h),s.addEvent("Transaction Sent",{tx:S});}catch(S){s.addEvent("Failed to send Transaction");let D=new Error("Failed to send transaction",{cause:S});metrics.trackError("passport","sessionActivityError",D,{flowId:s.details.flowId});}}v&&v.delay&&v.delay>0&&(s.addEvent("Delaying Transaction",{delay:v.delay}),await fa(v.delay),setTimeout(()=>{s.addEvent("Retrying after Delay"),he[h]=!1,Rn({...n,flow:s});},0));},Rn=n=>Mn(la)(n).then(()=>{he[n.passportClient]=!1;}),xn=Rn;var Cn=async({params:n,ethSigner:s,rpcProvider:h,relayerClient:p,guardianClient:a,zkEvmAddress:g,flow:v})=>{let y={to:g,value:0},{relayerId:A}=await ae({transactionRequest:y,ethSigner:s,rpcProvider:h,guardianClient:a,relayerClient:p,zkEvmAddress:g,flow:v});return a.withConfirmationScreen()(async()=>{let C=await se({params:n,ethSigner:s,zkEvmAddress:g,rpcProvider:h,guardianClient:a,relayerClient:p,flow:v});return await ie(p,A,v),C})};var bn=async({params:n,ethSigner:s,zkEvmAddress:h,flow:p})=>{if(!n||n.length!==1)throw new R(-32602,"im_signEjectionTransaction requires a singular param (hash)");let a=n[0];return await cn({transactionRequest:a,ethSigner:s,zkEvmAddress:h,flow:p})};var fe=n=>"zkEvm"in n,nr=class{#a;#s;#o;#f;#e;#t;#l;#i;#r;isPassport=!0;constructor({authManager:s,config:h,multiRollupApiClients:p,passportEventEmitter:a,guardianClient:g,ethSigner:v,user:y}){this.#a=s,this.#s=h,this.#e=g,this.#f=a,this.#r=v,this.#t=new ethers.JsonRpcProvider(this.#s.zkEvmRpcUrl,void 0,{staticNetwork:!0}),this.#i=new Dt({config:this.#s,rpcProvider:this.#t,authManager:this.#a}),this.#l=p,this.#o=new It,y&&fe(y)&&this.#h(y.zkEvm.ethAddress),a.on("loggedIn",A=>{fe(A)&&this.#h(A.zkEvm.ethAddress);}),a.on("loggedOut",this.#u),a.on("accountsRequested",xn);}#u=()=>{this.#o.emit("accountsChanged",[]);};async#h(s,h){let p=BigInt(1),a=async(g,v)=>await Qe({params:g,ethSigner:this.#r,guardianClient:this.#e,rpcProvider:this.#t,relayerClient:this.#i,zkEvmAddress:s,flow:v,nonceSpace:p,isBackgroundTransaction:!0});this.#f.emit("accountsRequested",{environment:this.#s.environment,sendTransaction:a,walletAddress:s,passportClient:h||"wallet"});}async#n(){try{let s=await this.#a.getUser();return s&&fe(s)?s.zkEvm.ethAddress:void 0}catch{return}}async#c(s){switch(s.method){case"eth_requestAccounts":{let h=await this.#n();if(h)return [h];let p=metrics.trackFlow("passport","ethRequestAccounts");try{let a=await this.#a.getUserOrLogin();p.addEvent("endGetUserOrLogin");let g;return fe(a)?g=a.zkEvm.ethAddress:(p.addEvent("startUserRegistration"),g=await ln({ethSigner:this.#r,authManager:this.#a,multiRollupApiClients:this.#l,accessToken:a.accessToken,rpcProvider:this.#t,flow:p}),p.addEvent("endUserRegistration")),this.#o.emit("accountsChanged",[g]),metrics.identify({passportId:a.profile.sub}),this.#h(g),[g]}catch(a){throw a instanceof Error?metrics.trackError("passport","ethRequestAccounts",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_sendTransaction":{let h=await this.#n();if(!h)throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=metrics.trackFlow("passport","ethSendTransaction");try{return await this.#e.withConfirmationScreen({width:480,height:720})(async()=>await Qe({params:s.params||[],ethSigner:this.#r,guardianClient:this.#e,rpcProvider:this.#t,relayerClient:this.#i,zkEvmAddress:h,flow:p}))}catch(a){throw a instanceof Error?metrics.trackError("passport","eth_sendTransaction",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_accounts":{let h=await this.#n();return h?[h]:[]}case"personal_sign":{let h=await this.#n();if(!h)throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=metrics.trackFlow("passport","personalSign");try{return await this.#e.withConfirmationScreen({width:480,height:720})(async()=>this.#s.forceScwDeployBeforeMessageSignature&&!(await Nt(this.#t,h)>BigInt(0))?await Cn({params:s.params||[],zkEvmAddress:h,ethSigner:this.#r,rpcProvider:this.#t,guardianClient:this.#e,relayerClient:this.#i,flow:p}):await se({params:s.params||[],zkEvmAddress:h,ethSigner:this.#r,rpcProvider:this.#t,guardianClient:this.#e,relayerClient:this.#i,flow:p}))}catch(a){throw a instanceof Error?metrics.trackError("passport","personal_sign",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_signTypedData":case"eth_signTypedData_v4":{if(!await this.#n())throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=metrics.trackFlow("passport","ethSignTypedDataV4");try{return await this.#e.withConfirmationScreen({width:480,height:720})(async()=>await mn({method:s.method,params:s.params||[],ethSigner:this.#r,rpcProvider:this.#t,relayerClient:this.#i,guardianClient:this.#e,flow:p}))}catch(a){throw a instanceof Error?metrics.trackError("passport","eth_signTypedData",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_chainId":{let{chainId:h}=await this.#t.getNetwork();return ethers.toBeHex(h)}case"eth_getBalance":case"eth_getCode":case"eth_getTransactionCount":{let[h,p]=s.params||[];return this.#t.send(s.method,[h,p||"latest"])}case"eth_getStorageAt":{let[h,p,a]=s.params||[];return this.#t.send(s.method,[h,p,a||"latest"])}case"eth_call":case"eth_estimateGas":{let[h,p]=s.params||[];return this.#t.send(s.method,[h,p||"latest"])}case"eth_gasPrice":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":return this.#t.send(s.method,s.params||[]);case"im_signEjectionTransaction":{let h=await this.#n();if(!h)throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=metrics.trackFlow("passport","imSignEjectionTransaction");try{return await bn({params:s.params||[],ethSigner:this.#r,zkEvmAddress:h,flow:p})}catch(a){throw a instanceof Error?metrics.trackError("passport","imSignEjectionTransaction",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"im_addSessionActivity":{let[h]=s.params||[],p=await this.#n();return p&&this.#h(p,h),null}default:throw new R(4200,"Method not supported")}}async request(s){try{return this.#c(s)}catch(h){throw h instanceof R?h:h instanceof Error?new R(-32603,h.message):new R(-32603,"Internal error")}}on(s,h){this.#o.on(s,h);}removeListener(s,h){this.#o.removeListener(s,h);}};var ir=class{environment;passportDomain;zkEvmRpcUrl;relayerUrl;indexerMrBasePath;jsonRpcReferrer;forceScwDeployBeforeMessageSignature;crossSdkBridgeEnabled;constructor(s){if(this.environment=s.baseConfig.environment,this.jsonRpcReferrer=s.jsonRpcReferrer,this.forceScwDeployBeforeMessageSignature=s.forceScwDeployBeforeMessageSignature||!1,this.crossSdkBridgeEnabled=s.crossSdkBridgeEnabled||!1,s.overrides)this.passportDomain=s.overrides.passportDomain,this.zkEvmRpcUrl=s.overrides.zkEvmRpcUrl,this.relayerUrl=s.overrides.relayerUrl,this.indexerMrBasePath=s.overrides.indexerMrBasePath;else switch(s.baseConfig.environment){case config.Environment.PRODUCTION:this.passportDomain="https://passport.immutable.com",this.zkEvmRpcUrl="https://rpc.immutable.com",this.relayerUrl="https://api.immutable.com/relayer-mr",this.indexerMrBasePath="https://api.immutable.com";break;case config.Environment.SANDBOX:this.passportDomain="https://passport.sandbox.immutable.com",this.zkEvmRpcUrl="https://rpc.testnet.immutable.com",this.relayerUrl="https://api.sandbox.immutable.com/relayer-mr",this.indexerMrBasePath="https://api.sandbox.immutable.com";break;default:throw new Error(`Unsupported environment: ${s.baseConfig.environment}`)}}};var ar=async(n,s,h=!0,p=!0)=>{let a=metrics.trackFlow("passport",s,h);try{return await n(a)}catch(g){throw g instanceof Error?metrics.trackError("passport",s,g,{flowId:a.details.flowId}):a.addEvent("errored"),g}finally{p&&a.addEvent("End");}};var Pn="ETH",le=class n extends ethers.AbstractSigner{authManager;magicTeeApiClient;userWallet=null;createWalletPromise=null;constructor(s,h){super(),this.authManager=s,this.magicTeeApiClient=h;}async getUserWallet(){let{userWallet:s}=this;s||(s=await this.createWallet());let h=await this.getUserOrThrow();if(h.profile.sub!==s.userIdentifier&&(s=await this.createWallet(h)),auth.isUserImx(h)&&h.imx.userAdminAddress.toLowerCase()!==s.walletAddress.toLowerCase())throw new vt(`Wallet address mismatch.Rollup: IMX, TEE address: ${s.walletAddress}, profile address: ${h.imx.userAdminAddress}`,"WALLET_CONNECTION_ERROR");if(auth.isUserZkEvm(h)&&h.zkEvm.userAdminAddress.toLowerCase()!==s.walletAddress.toLowerCase())throw new vt(`Wallet address mismatch.Rollup: zkEVM, TEE address: ${s.walletAddress}, profile address: ${h.zkEvm.userAdminAddress}`,"WALLET_CONNECTION_ERROR");return s}async createWallet(s){return this.createWalletPromise?this.createWalletPromise:(this.createWalletPromise=new Promise(async(h,p)=>{try{this.userWallet=null;let a=s||await this.getUserOrThrow(),g=n.getHeaders(a);await ar(async v=>{try{let y=performance.now(),A=await this.magicTeeApiClient.walletApi.createWalletV1WalletPost({xMagicChain:Pn},{headers:g});return metrics.trackDuration("passport",v.details.flowName,Math.round(performance.now()-y)),this.userWallet={userIdentifier:a.profile.sub,walletAddress:A.data.public_address},h(this.userWallet)}catch(y){let A="MagicTEE: Failed to initialise EOA";return un.isAxiosError(y)?y.response?A+=` with status ${y.response.status}: ${JSON.stringify(y.response.data)}`:A+=`: ${y.message}`:A+=`: ${y.message}`,p(new Error(A))}},"magicCreateWallet");}catch(a){p(a);}finally{this.createWalletPromise=null;}}),this.createWalletPromise)}async getUserOrThrow(){let s=await this.authManager.getUser();if(!s)throw new vt("User has been logged out","NOT_LOGGED_IN_ERROR");return s}static getHeaders(s){if(!s)throw new vt("User has been logged out","NOT_LOGGED_IN_ERROR");return {Authorization:`Bearer ${s.idToken}`}}async getAddress(){return (await this.getUserWallet()).walletAddress}async signMessage(s){await this.getUserWallet();let h=s instanceof Uint8Array?`0x${Buffer.from(s).toString("hex")}`:s,p=await this.getUserOrThrow(),a=await n.getHeaders(p);return ar(async g=>{try{let v=performance.now(),y=await this.magicTeeApiClient.signOperationsApi.signMessageV1WalletSignMessagePost({signMessageRequest:{message_base64:Buffer.from(h,"utf-8").toString("base64")},xMagicChain:Pn},{headers:a});return metrics.trackDuration("passport",g.details.flowName,Math.round(performance.now()-v)),y.data.signature}catch(v){let y="MagicTEE: Failed to sign message using EOA";throw un.isAxiosError(v)?v.response?y+=` with status ${v.response.status}: ${JSON.stringify(v.response.data)}`:y+=`: ${v.message}`:y+=`: ${v.message}`,new Error(y)}},"magicSignMessage")}connect(){throw new Error("Method not implemented.")}signTransaction(){throw new Error("Method not implemented.")}signTypedData(){throw new Error("Method not implemented.")}};var ya={icon:'data:image/svg+xml,<svg viewBox="0 0 48 48" class="SvgIcon undefined Logo Logo--PassportSymbolOutlined css-1dn9atd" xmlns="http://www.w3.org/2000/svg"><g data-testid="undefined__g"><circle cx="24" cy="24" r="22.5" fill="url(%23paint0_radial_6324_83922)"></circle><circle cx="24" cy="24" r="22.5" fill="url(%23paint1_radial_6324_83922)"></circle><path d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM23.0718 9.16608C23.7383 8.83951 24.4406 8.86188 25.087 9.2287C27.3282 10.5059 29.5627 11.7942 31.786 13.096C32.5018 13.5165 32.8686 14.1897 32.8708 15.0173C32.8843 17.9184 32.8798 20.8171 32.8708 23.7182C32.8708 23.8255 32.8015 23.9821 32.7143 24.0335C31.8531 24.548 30.9808 25.0423 30.0347 25.5881V25.1318C30.0347 22.148 30.0257 19.1664 30.0414 16.1827C30.0436 15.6101 29.8468 15.241 29.339 14.9525C26.7377 13.474 24.1499 11.9687 21.5575 10.4723C21.4457 10.4075 21.3361 10.3381 21.1661 10.2352C21.8326 9.85722 22.4321 9.47698 23.0673 9.16608H23.0718ZM22.5953 38.8451C22.45 38.7713 22.3426 38.7198 22.2375 38.6595C18.8041 36.68 15.3752 34.687 11.9307 32.7232C10.9644 32.173 10.5238 31.3879 10.5349 30.2852C10.5551 27.9411 10.5484 25.597 10.5372 23.2507C10.5327 22.1927 10.9622 21.4255 11.8926 20.8977C14.3105 19.5221 16.715 18.1264 19.1195 16.7284C19.3275 16.6076 19.4796 16.5875 19.6965 16.7172C20.5264 17.216 21.3719 17.6924 22.2554 18.2024C22.0876 18.3031 21.9601 18.3791 21.8304 18.4552C19.2268 19.9582 16.6278 21.4658 14.0175 22.9599C13.5903 23.2037 13.3912 23.5213 13.3957 24.0179C13.4091 25.8654 13.4114 27.713 13.3957 29.5605C13.3912 30.0705 13.5948 30.3948 14.0332 30.6453C16.7866 32.2199 19.5288 33.8125 22.28 35.3916C22.5126 35.5258 22.611 35.6645 22.6065 35.9418C22.5864 36.888 22.5998 37.8363 22.5998 38.8473L22.5953 38.8451ZM22.5953 33.553C22.356 33.4166 22.1838 33.3204 22.0116 33.2198C19.8285 31.9605 17.6477 30.6967 15.4602 29.4464C15.2231 29.3122 15.1359 29.1668 15.1381 28.8917C15.1538 27.4714 15.1471 26.0511 15.1426 24.6308C15.1426 24.4384 15.1717 24.3064 15.3618 24.1991C16.167 23.7495 16.9633 23.2798 17.7618 22.8212C17.8199 22.7877 17.8826 22.7631 17.9877 22.7116V24.3064C17.9877 25.1698 18.0011 26.0354 17.9832 26.8988C17.972 27.3909 18.1622 27.7241 18.5916 27.9657C19.8285 28.6636 21.0498 29.3883 22.2867 30.0839C22.5305 30.2203 22.6043 30.3724 22.5998 30.6408C22.5842 31.5847 22.5931 32.5308 22.5931 33.5508L22.5953 33.553ZM20.0746 14.91C19.6116 14.6371 19.2157 14.6393 18.7527 14.91C16.1581 16.4265 13.5523 17.9228 10.9487 19.4259C10.8391 19.4908 10.7251 19.5489 10.5305 19.6541C10.5998 18.6654 10.3873 17.7327 10.7251 16.8291C10.9085 16.3348 11.2529 15.9635 11.7092 15.6995C13.8811 14.4447 16.0507 13.1877 18.227 11.9396C19.0211 11.4833 19.8308 11.4945 20.6248 11.953C23.0964 13.3756 25.5657 14.8026 28.0306 16.2341C28.1357 16.2945 28.2677 16.4309 28.2677 16.5338C28.2856 17.5493 28.2788 18.567 28.2788 19.6563C27.3819 19.1396 26.5543 18.6609 25.7267 18.1823C23.8412 17.093 21.9512 16.0149 20.0746 14.91ZM37.4427 30.8779C37.3778 31.6764 36.9103 32.2423 36.2192 32.6404C33.5732 34.1614 30.9294 35.6913 28.2856 37.2168C27.4557 37.6954 26.6259 38.1741 25.7938 38.6527C25.6932 38.7109 25.5903 38.7601 25.4539 38.8317C25.4449 38.693 25.4337 38.5924 25.4337 38.4917C25.4337 37.6149 25.4382 36.7404 25.4293 35.8636C25.4293 35.6645 25.4762 35.5437 25.6596 35.4386C29.5157 33.2198 33.3696 30.9942 37.2212 28.7709C37.2794 28.7374 37.3443 28.7105 37.4539 28.6591C37.4539 29.4375 37.4986 30.1622 37.4427 30.8779ZM37.4628 25.3577C37.4561 26.2658 36.9663 26.9033 36.1901 27.3506C33.175 29.0841 30.1622 30.8265 27.1493 32.5666C26.5991 32.8842 26.0466 33.1996 25.4561 33.5396C25.4472 33.3897 25.436 33.2913 25.436 33.1907C25.436 32.3273 25.4449 31.4617 25.4293 30.5983C25.4248 30.3523 25.5075 30.2226 25.72 30.0995C28.46 28.5271 31.1911 26.9368 33.9355 25.3733C34.4231 25.096 34.6378 24.7538 34.6334 24.1812C34.6132 21.1974 34.6244 18.2136 34.6244 15.2298V14.7087C35.3402 15.1404 36.0112 15.496 36.624 15.9299C37.1832 16.3258 37.465 16.9253 37.4673 17.6164C37.4762 20.1976 37.4829 22.7788 37.465 25.3599L37.4628 25.3577Z" fill="%230D0D0D"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint2_radial_6324_83922)"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint3_radial_6324_83922)"></path><defs><radialGradient id="paint0_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(13.4442 13.3899) rotate(44.9817) scale(46.7487 99.1435)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint1_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(25.9515 43.7068) rotate(84.265) scale(24.2138 46.3215)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient><radialGradient id="paint2_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(12.7405 12.6825) rotate(44.9817) scale(49.8653 105.753)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint3_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26.0816 45.0206) rotate(84.265) scale(25.828 49.4096)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient></defs></g></svg>',name:"Immutable Passport",rdns:"com.immutable.passport",uuid:uuid.v4()};function wa(n){if(typeof window>"u")return;let s=new CustomEvent("eip6963:announceProvider",{detail:Object.freeze(n)});window.dispatchEvent(s);let h=()=>window.dispatchEvent(s);window.addEventListener("eip6963:requestProvider",h);}
45
+
46
+ Object.defineProperty(exports, "isUserImx", {
47
+ enumerable: true,
48
+ get: function () { return auth.isUserImx; }
49
+ });
50
+ Object.defineProperty(exports, "isUserZkEvm", {
51
+ enumerable: true,
52
+ get: function () { return auth.isUserZkEvm; }
53
+ });
54
+ exports.GuardianClient = ne;
55
+ exports.JsonRpcError = R;
56
+ exports.MagicTEESigner = le;
57
+ exports.PassportEvents = Sr;
58
+ exports.ProviderErrorCode = $t;
59
+ exports.ProviderEvent = qn;
60
+ exports.RelayerClient = Dt;
61
+ exports.RelayerTransactionStatus = Hn;
62
+ exports.RpcErrorCode = Tt;
63
+ exports.TypedEventEmitter = It;
64
+ exports.WalletConfiguration = ir;
65
+ exports.WalletError = vt;
66
+ exports.WalletErrorType = te;
67
+ exports.ZkEvmProvider = nr;
68
+ exports.announceProvider = wa;
69
+ exports.passportProviderInfo = ya;
70
+ exports.retryWithDelay = Pt;
71
+ exports.walletHelpers = Gr;
@@ -0,0 +1,22 @@
1
+ import { utils, trackFlow, trackError, identify, trackDuration } from '@imtbl/metrics';
2
+ import { ZeroAddress, AbiCoder, keccak256, Contract, isError, solidityPacked, getBytes, Interface, TypedDataEncoder, hashMessage, JsonRpcProvider, toBeHex, AbstractSigner, stripZerosLeft, toUtf8String } from 'ethers';
3
+ import { EventEmitter } from 'events';
4
+ import { isUserImx, isUserZkEvm } from '@imtbl/auth';
5
+ export { isUserImx, isUserZkEvm } from '@imtbl/auth';
6
+ import { walletContracts } from '@0xsequence/abi';
7
+ import { v1 } from '@0xsequence/core';
8
+ import * as Xe from '@imtbl/generated-clients';
9
+ import un, { isAxiosError } from 'axios';
10
+ import { Environment } from '@imtbl/config';
11
+ import { v4 } from 'uuid';
12
+
13
+ var Nn=Object.create;var Ne=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var kn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var On=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(s,h)=>(typeof require<"u"?require:s)[h]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var qt=(n,s)=>()=>(s||n((s={exports:{}}).exports,s),s.exports),Ln=(n,s)=>{for(var h in s)Ne(n,h,{get:s[h],enumerable:!0});},Gn=(n,s,h,p)=>{if(s&&typeof s=="object"||typeof s=="function")for(let a of Bn(s))!Un.call(n,a)&&a!==h&&Ne(n,a,{get:()=>s[a],enumerable:!(p=Dn(s,a))||p.enumerable});return n};var br=(n,s,h)=>(h=n!=null?Nn(kn(n)):{},Gn(Ne(h,"default",{value:n,enumerable:!0}),n));var qr=qt((Fr,Le)=>{(function(n,s){function h(c,t){if(!c)throw new Error(t||"Assertion failed")}function p(c,t){c.super_=t;var r=function(){};r.prototype=t.prototype,c.prototype=new r,c.prototype.constructor=c;}function a(c,t,r){if(a.isBN(c))return c;this.negative=0,this.words=null,this.length=0,this.red=null,c!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(c||0,t||10,r||"be"));}typeof n=="object"?n.exports=a:s.BN=a,a.BN=a,a.wordSize=26;var g;try{typeof window<"u"&&typeof window.Buffer<"u"?g=window.Buffer:g=On("buffer").Buffer;}catch{}a.isBN=function(t){return t instanceof a?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===a.wordSize&&Array.isArray(t.words)},a.max=function(t,r){return t.cmp(r)>0?t:r},a.min=function(t,r){return t.cmp(r)<0?t:r},a.prototype._init=function(t,r,i){if(typeof t=="number")return this._initNumber(t,r,i);if(typeof t=="object")return this._initArray(t,r,i);r==="hex"&&(r=16),h(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var o=0;t[0]==="-"&&(o++,this.negative=1),o<t.length&&(r===16?this._parseHex(t,o,i):(this._parseBase(t,r,o),i==="le"&&this._initArray(this.toArray(),r,i)));},a.prototype._initNumber=function(t,r,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(h(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),r,i);},a.prototype._initArray=function(t,r,i){if(h(typeof t.length=="number"),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 o=0;o<this.length;o++)this.words[o]=0;var l,d,m=0;if(i==="be")for(o=t.length-1,l=0;o>=0;o-=3)d=t[o]|t[o-1]<<8|t[o-2]<<16,this.words[l]|=d<<m&67108863,this.words[l+1]=d>>>26-m&67108863,m+=24,m>=26&&(m-=26,l++);else if(i==="le")for(o=0,l=0;o<t.length;o+=3)d=t[o]|t[o+1]<<8|t[o+2]<<16,this.words[l]|=d<<m&67108863,this.words[l+1]=d>>>26-m&67108863,m+=24,m>=26&&(m-=26,l++);return this._strip()};function v(c,t){var r=c.charCodeAt(t);if(r>=48&&r<=57)return r-48;if(r>=65&&r<=70)return r-55;if(r>=97&&r<=102)return r-87;h(!1,"Invalid character in "+c);}function y(c,t,r){var i=v(c,r);return r-1>=t&&(i|=v(c,r-1)<<4),i}a.prototype._parseHex=function(t,r,i){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var l=0,d=0,m;if(i==="be")for(o=t.length-1;o>=r;o-=2)m=y(t,r,o)<<l,this.words[d]|=m&67108863,l>=18?(l-=18,d+=1,this.words[d]|=m>>>26):l+=8;else {var f=t.length-r;for(o=f%2===0?r+1:r;o<t.length;o+=2)m=y(t,r,o)<<l,this.words[d]|=m&67108863,l>=18?(l-=18,d+=1,this.words[d]|=m>>>26):l+=8;}this._strip();};function A(c,t,r,i){for(var o=0,l=0,d=Math.min(c.length,r),m=t;m<d;m++){var f=c.charCodeAt(m)-48;o*=i,f>=49?l=f-49+10:f>=17?l=f-17+10:l=f,h(f>=0&&l<i,"Invalid character"),o+=l;}return o}a.prototype._parseBase=function(t,r,i){this.words=[0],this.length=1;for(var o=0,l=1;l<=67108863;l*=r)o++;o--,l=l/r|0;for(var d=t.length-i,m=d%o,f=Math.min(d,d-m)+i,e=0,u=i;u<f;u+=o)e=A(t,u,u+o,r),this.imuln(l),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);if(m!==0){var w=1;for(e=A(t,u,t.length,r),u=0;u<m;u++)w*=r;this.imuln(w),this.words[0]+e<67108864?this.words[0]+=e:this._iaddn(e);}this._strip();},a.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red;};function C(c,t){c.words=t.words,c.length=t.length,c.negative=t.negative,c.red=t.red;}if(a.prototype._move=function(t){C(t,this);},a.prototype.clone=function(){var t=new a(null);return this.copy(t),t},a.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=S;}catch{a.prototype.inspect=S;}else a.prototype.inspect=S;function S(){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"],mt=[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],yt=[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];a.prototype.toString=function(t,r){t=t||10,r=r|0||1;var i;if(t===16||t==="hex"){i="";for(var o=0,l=0,d=0;d<this.length;d++){var m=this.words[d],f=((m<<o|l)&16777215).toString(16);l=m>>>24-o&16777215,o+=2,o>=26&&(o-=26,d--),l!==0||d!==this.length-1?i=D[6-f.length]+f+i:i=f+i;}for(l!==0&&(i=l.toString(16)+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var e=mt[t],u=yt[t];i="";var w=this.clone();for(w.negative=0;!w.isZero();){var M=w.modrn(u).toString(t);w=w.idivn(u),w.isZero()?i=M+i:i=D[e-M.length]+M+i;}for(this.isZero()&&(i="0"+i);i.length%r!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}h(!1,"Base should be between 2 and 36");},a.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&h(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},a.prototype.toJSON=function(){return this.toString(16,2)},g&&(a.prototype.toBuffer=function(t,r){return this.toArrayLike(g,t,r)}),a.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)};var bt=function(t,r){return t.allocUnsafe?t.allocUnsafe(r):new t(r)};a.prototype.toArrayLike=function(t,r,i){this._strip();var o=this.byteLength(),l=i||Math.max(1,o);h(o<=l,"byte array longer than desired length"),h(l>0,"Requested array length <= 0");var d=bt(t,l),m=r==="le"?"LE":"BE";return this["_toArrayLike"+m](d,o),d},a.prototype._toArrayLikeLE=function(t,r){for(var i=0,o=0,l=0,d=0;l<this.length;l++){var m=this.words[l]<<d|o;t[i++]=m&255,i<t.length&&(t[i++]=m>>8&255),i<t.length&&(t[i++]=m>>16&255),d===6?(i<t.length&&(t[i++]=m>>24&255),o=0,d=0):(o=m>>>24,d+=2);}if(i<t.length)for(t[i++]=o;i<t.length;)t[i++]=0;},a.prototype._toArrayLikeBE=function(t,r){for(var i=t.length-1,o=0,l=0,d=0;l<this.length;l++){var m=this.words[l]<<d|o;t[i--]=m&255,i>=0&&(t[i--]=m>>8&255),i>=0&&(t[i--]=m>>16&255),d===6?(i>=0&&(t[i--]=m>>24&255),o=0,d=0):(o=m>>>24,d+=2);}if(i>=0)for(t[i--]=o;i>=0;)t[i--]=0;},Math.clz32?a.prototype._countBits=function(t){return 32-Math.clz32(t)}:a.prototype._countBits=function(t){var r=t,i=0;return r>=4096&&(i+=13,r>>>=13),r>=64&&(i+=7,r>>>=7),r>=8&&(i+=4,r>>>=4),r>=2&&(i+=2,r>>>=2),i+r},a.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,i=0;return r&8191||(i+=13,r>>>=13),r&127||(i+=7,r>>>=7),r&15||(i+=4,r>>>=4),r&3||(i+=2,r>>>=2),r&1||i++,i},a.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return (this.length-1)*26+r};function Et(c){for(var t=new Array(c.bitLength()),r=0;r<t.length;r++){var i=r/26|0,o=r%26;t[r]=c.words[i]>>>o&1;}return t}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var i=this._zeroBits(this.words[r]);if(t+=i,i!==26)break}return t},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},a.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this._strip()},a.prototype.ior=function(t){return h((this.negative|t.negative)===0),this.iuor(t)},a.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},a.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},a.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var i=0;i<r.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=r.length,this._strip()},a.prototype.iand=function(t){return h((this.negative|t.negative)===0),this.iuand(t)},a.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},a.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},a.prototype.iuxor=function(t){var r,i;this.length>t.length?(r=this,i=t):(r=t,i=this);for(var o=0;o<i.length;o++)this.words[o]=r.words[o]^i.words[o];if(this!==r)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=r.length,this._strip()},a.prototype.ixor=function(t){return h((this.negative|t.negative)===0),this.iuxor(t)},a.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},a.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},a.prototype.inotn=function(t){h(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,i=t%26;this._expand(r),i>0&&r--;for(var o=0;o<r;o++)this.words[o]=~this.words[o]&67108863;return i>0&&(this.words[o]=~this.words[o]&67108863>>26-i),this._strip()},a.prototype.notn=function(t){return this.clone().inotn(t)},a.prototype.setn=function(t,r){h(typeof t=="number"&&t>=0);var i=t/26|0,o=t%26;return this._expand(i+1),r?this.words[i]=this.words[i]|1<<o:this.words[i]=this.words[i]&~(1<<o),this._strip()},a.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var i,o;this.length>t.length?(i=this,o=t):(i=t,o=this);for(var l=0,d=0;d<o.length;d++)r=(i.words[d]|0)+(o.words[d]|0)+l,this.words[d]=r&67108863,l=r>>>26;for(;l!==0&&d<i.length;d++)r=(i.words[d]|0)+l,this.words[d]=r&67108863,l=r>>>26;if(this.length=i.length,l!==0)this.words[this.length]=l,this.length++;else if(i!==this)for(;d<i.length;d++)this.words[d]=i.words[d];return this},a.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},a.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var o,l;i>0?(o=this,l=t):(o=t,l=this);for(var d=0,m=0;m<l.length;m++)r=(o.words[m]|0)-(l.words[m]|0)+d,d=r>>26,this.words[m]=r&67108863;for(;d!==0&&m<o.length;m++)r=(o.words[m]|0)+d,d=r>>26,this.words[m]=r&67108863;if(d===0&&m<o.length&&o!==this)for(;m<o.length;m++)this.words[m]=o.words[m];return this.length=Math.max(this.length,m),o!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(t){return this.clone().isub(t)};function wt(c,t,r){r.negative=t.negative^c.negative;var i=c.length+t.length|0;r.length=i,i=i-1|0;var o=c.words[0]|0,l=t.words[0]|0,d=o*l,m=d&67108863,f=d/67108864|0;r.words[0]=m;for(var e=1;e<i;e++){for(var u=f>>>26,w=f&67108863,M=Math.min(e,t.length-1),T=Math.max(0,e-c.length+1);T<=M;T++){var x=e-T|0;o=c.words[x]|0,l=t.words[T]|0,d=o*l+w,u+=d/67108864|0,w=d&67108863;}r.words[e]=w|0,f=u|0;}return f!==0?r.words[e]=f|0:r.length--,r._strip()}var Gt=function(t,r,i){var o=t.words,l=r.words,d=i.words,m=0,f,e,u,w=o[0]|0,M=w&8191,T=w>>>13,x=o[1]|0,b=x&8191,I=x>>>13,At=o[2]|0,_=At&8191,P=At>>>13,lr=o[3]|0,B=lr&8191,k=lr>>>13,ur=o[4]|0,U=ur&8191,O=ur>>>13,cr=o[5]|0,L=cr&8191,G=cr>>>13,dr=o[6]|0,F=dr&8191,q=dr>>>13,mr=o[7]|0,H=mr&8191,Z=mr>>>13,pr=o[8]|0,W=pr&8191,J=pr>>>13,gr=o[9]|0,V=gr&8191,$=gr>>>13,vr=l[0]|0,z=vr&8191,j=vr>>>13,yr=l[1]|0,Y=yr&8191,K=yr>>>13,wr=l[2]|0,X=wr&8191,Q=wr>>>13,Mr=l[3]|0,tt=Mr&8191,et=Mr>>>13,Er=l[4]|0,rt=Er&8191,nt=Er>>>13,Tr=l[5]|0,it=Tr&8191,at=Tr>>>13,Ar=l[6]|0,st=Ar&8191,ot=Ar>>>13,Rr=l[7]|0,ht=Rr&8191,ft=Rr>>>13,xr=l[8]|0,lt=xr&8191,ut=xr>>>13,Cr=l[9]|0,ct=Cr&8191,dt=Cr>>>13;i.negative=t.negative^r.negative,i.length=19,f=Math.imul(M,z),e=Math.imul(M,j),e=e+Math.imul(T,z)|0,u=Math.imul(T,j);var de=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(de>>>26)|0,de&=67108863,f=Math.imul(b,z),e=Math.imul(b,j),e=e+Math.imul(I,z)|0,u=Math.imul(I,j),f=f+Math.imul(M,Y)|0,e=e+Math.imul(M,K)|0,e=e+Math.imul(T,Y)|0,u=u+Math.imul(T,K)|0;var me=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(me>>>26)|0,me&=67108863,f=Math.imul(_,z),e=Math.imul(_,j),e=e+Math.imul(P,z)|0,u=Math.imul(P,j),f=f+Math.imul(b,Y)|0,e=e+Math.imul(b,K)|0,e=e+Math.imul(I,Y)|0,u=u+Math.imul(I,K)|0,f=f+Math.imul(M,X)|0,e=e+Math.imul(M,Q)|0,e=e+Math.imul(T,X)|0,u=u+Math.imul(T,Q)|0;var pe=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(pe>>>26)|0,pe&=67108863,f=Math.imul(B,z),e=Math.imul(B,j),e=e+Math.imul(k,z)|0,u=Math.imul(k,j),f=f+Math.imul(_,Y)|0,e=e+Math.imul(_,K)|0,e=e+Math.imul(P,Y)|0,u=u+Math.imul(P,K)|0,f=f+Math.imul(b,X)|0,e=e+Math.imul(b,Q)|0,e=e+Math.imul(I,X)|0,u=u+Math.imul(I,Q)|0,f=f+Math.imul(M,tt)|0,e=e+Math.imul(M,et)|0,e=e+Math.imul(T,tt)|0,u=u+Math.imul(T,et)|0;var ge=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(ge>>>26)|0,ge&=67108863,f=Math.imul(U,z),e=Math.imul(U,j),e=e+Math.imul(O,z)|0,u=Math.imul(O,j),f=f+Math.imul(B,Y)|0,e=e+Math.imul(B,K)|0,e=e+Math.imul(k,Y)|0,u=u+Math.imul(k,K)|0,f=f+Math.imul(_,X)|0,e=e+Math.imul(_,Q)|0,e=e+Math.imul(P,X)|0,u=u+Math.imul(P,Q)|0,f=f+Math.imul(b,tt)|0,e=e+Math.imul(b,et)|0,e=e+Math.imul(I,tt)|0,u=u+Math.imul(I,et)|0,f=f+Math.imul(M,rt)|0,e=e+Math.imul(M,nt)|0,e=e+Math.imul(T,rt)|0,u=u+Math.imul(T,nt)|0;var ve=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(ve>>>26)|0,ve&=67108863,f=Math.imul(L,z),e=Math.imul(L,j),e=e+Math.imul(G,z)|0,u=Math.imul(G,j),f=f+Math.imul(U,Y)|0,e=e+Math.imul(U,K)|0,e=e+Math.imul(O,Y)|0,u=u+Math.imul(O,K)|0,f=f+Math.imul(B,X)|0,e=e+Math.imul(B,Q)|0,e=e+Math.imul(k,X)|0,u=u+Math.imul(k,Q)|0,f=f+Math.imul(_,tt)|0,e=e+Math.imul(_,et)|0,e=e+Math.imul(P,tt)|0,u=u+Math.imul(P,et)|0,f=f+Math.imul(b,rt)|0,e=e+Math.imul(b,nt)|0,e=e+Math.imul(I,rt)|0,u=u+Math.imul(I,nt)|0,f=f+Math.imul(M,it)|0,e=e+Math.imul(M,at)|0,e=e+Math.imul(T,it)|0,u=u+Math.imul(T,at)|0;var ye=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(ye>>>26)|0,ye&=67108863,f=Math.imul(F,z),e=Math.imul(F,j),e=e+Math.imul(q,z)|0,u=Math.imul(q,j),f=f+Math.imul(L,Y)|0,e=e+Math.imul(L,K)|0,e=e+Math.imul(G,Y)|0,u=u+Math.imul(G,K)|0,f=f+Math.imul(U,X)|0,e=e+Math.imul(U,Q)|0,e=e+Math.imul(O,X)|0,u=u+Math.imul(O,Q)|0,f=f+Math.imul(B,tt)|0,e=e+Math.imul(B,et)|0,e=e+Math.imul(k,tt)|0,u=u+Math.imul(k,et)|0,f=f+Math.imul(_,rt)|0,e=e+Math.imul(_,nt)|0,e=e+Math.imul(P,rt)|0,u=u+Math.imul(P,nt)|0,f=f+Math.imul(b,it)|0,e=e+Math.imul(b,at)|0,e=e+Math.imul(I,it)|0,u=u+Math.imul(I,at)|0,f=f+Math.imul(M,st)|0,e=e+Math.imul(M,ot)|0,e=e+Math.imul(T,st)|0,u=u+Math.imul(T,ot)|0;var we=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(we>>>26)|0,we&=67108863,f=Math.imul(H,z),e=Math.imul(H,j),e=e+Math.imul(Z,z)|0,u=Math.imul(Z,j),f=f+Math.imul(F,Y)|0,e=e+Math.imul(F,K)|0,e=e+Math.imul(q,Y)|0,u=u+Math.imul(q,K)|0,f=f+Math.imul(L,X)|0,e=e+Math.imul(L,Q)|0,e=e+Math.imul(G,X)|0,u=u+Math.imul(G,Q)|0,f=f+Math.imul(U,tt)|0,e=e+Math.imul(U,et)|0,e=e+Math.imul(O,tt)|0,u=u+Math.imul(O,et)|0,f=f+Math.imul(B,rt)|0,e=e+Math.imul(B,nt)|0,e=e+Math.imul(k,rt)|0,u=u+Math.imul(k,nt)|0,f=f+Math.imul(_,it)|0,e=e+Math.imul(_,at)|0,e=e+Math.imul(P,it)|0,u=u+Math.imul(P,at)|0,f=f+Math.imul(b,st)|0,e=e+Math.imul(b,ot)|0,e=e+Math.imul(I,st)|0,u=u+Math.imul(I,ot)|0,f=f+Math.imul(M,ht)|0,e=e+Math.imul(M,ft)|0,e=e+Math.imul(T,ht)|0,u=u+Math.imul(T,ft)|0;var Me=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Me>>>26)|0,Me&=67108863,f=Math.imul(W,z),e=Math.imul(W,j),e=e+Math.imul(J,z)|0,u=Math.imul(J,j),f=f+Math.imul(H,Y)|0,e=e+Math.imul(H,K)|0,e=e+Math.imul(Z,Y)|0,u=u+Math.imul(Z,K)|0,f=f+Math.imul(F,X)|0,e=e+Math.imul(F,Q)|0,e=e+Math.imul(q,X)|0,u=u+Math.imul(q,Q)|0,f=f+Math.imul(L,tt)|0,e=e+Math.imul(L,et)|0,e=e+Math.imul(G,tt)|0,u=u+Math.imul(G,et)|0,f=f+Math.imul(U,rt)|0,e=e+Math.imul(U,nt)|0,e=e+Math.imul(O,rt)|0,u=u+Math.imul(O,nt)|0,f=f+Math.imul(B,it)|0,e=e+Math.imul(B,at)|0,e=e+Math.imul(k,it)|0,u=u+Math.imul(k,at)|0,f=f+Math.imul(_,st)|0,e=e+Math.imul(_,ot)|0,e=e+Math.imul(P,st)|0,u=u+Math.imul(P,ot)|0,f=f+Math.imul(b,ht)|0,e=e+Math.imul(b,ft)|0,e=e+Math.imul(I,ht)|0,u=u+Math.imul(I,ft)|0,f=f+Math.imul(M,lt)|0,e=e+Math.imul(M,ut)|0,e=e+Math.imul(T,lt)|0,u=u+Math.imul(T,ut)|0;var Ee=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,f=Math.imul(V,z),e=Math.imul(V,j),e=e+Math.imul($,z)|0,u=Math.imul($,j),f=f+Math.imul(W,Y)|0,e=e+Math.imul(W,K)|0,e=e+Math.imul(J,Y)|0,u=u+Math.imul(J,K)|0,f=f+Math.imul(H,X)|0,e=e+Math.imul(H,Q)|0,e=e+Math.imul(Z,X)|0,u=u+Math.imul(Z,Q)|0,f=f+Math.imul(F,tt)|0,e=e+Math.imul(F,et)|0,e=e+Math.imul(q,tt)|0,u=u+Math.imul(q,et)|0,f=f+Math.imul(L,rt)|0,e=e+Math.imul(L,nt)|0,e=e+Math.imul(G,rt)|0,u=u+Math.imul(G,nt)|0,f=f+Math.imul(U,it)|0,e=e+Math.imul(U,at)|0,e=e+Math.imul(O,it)|0,u=u+Math.imul(O,at)|0,f=f+Math.imul(B,st)|0,e=e+Math.imul(B,ot)|0,e=e+Math.imul(k,st)|0,u=u+Math.imul(k,ot)|0,f=f+Math.imul(_,ht)|0,e=e+Math.imul(_,ft)|0,e=e+Math.imul(P,ht)|0,u=u+Math.imul(P,ft)|0,f=f+Math.imul(b,lt)|0,e=e+Math.imul(b,ut)|0,e=e+Math.imul(I,lt)|0,u=u+Math.imul(I,ut)|0,f=f+Math.imul(M,ct)|0,e=e+Math.imul(M,dt)|0,e=e+Math.imul(T,ct)|0,u=u+Math.imul(T,dt)|0;var Te=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Te>>>26)|0,Te&=67108863,f=Math.imul(V,Y),e=Math.imul(V,K),e=e+Math.imul($,Y)|0,u=Math.imul($,K),f=f+Math.imul(W,X)|0,e=e+Math.imul(W,Q)|0,e=e+Math.imul(J,X)|0,u=u+Math.imul(J,Q)|0,f=f+Math.imul(H,tt)|0,e=e+Math.imul(H,et)|0,e=e+Math.imul(Z,tt)|0,u=u+Math.imul(Z,et)|0,f=f+Math.imul(F,rt)|0,e=e+Math.imul(F,nt)|0,e=e+Math.imul(q,rt)|0,u=u+Math.imul(q,nt)|0,f=f+Math.imul(L,it)|0,e=e+Math.imul(L,at)|0,e=e+Math.imul(G,it)|0,u=u+Math.imul(G,at)|0,f=f+Math.imul(U,st)|0,e=e+Math.imul(U,ot)|0,e=e+Math.imul(O,st)|0,u=u+Math.imul(O,ot)|0,f=f+Math.imul(B,ht)|0,e=e+Math.imul(B,ft)|0,e=e+Math.imul(k,ht)|0,u=u+Math.imul(k,ft)|0,f=f+Math.imul(_,lt)|0,e=e+Math.imul(_,ut)|0,e=e+Math.imul(P,lt)|0,u=u+Math.imul(P,ut)|0,f=f+Math.imul(b,ct)|0,e=e+Math.imul(b,dt)|0,e=e+Math.imul(I,ct)|0,u=u+Math.imul(I,dt)|0;var Ae=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,f=Math.imul(V,X),e=Math.imul(V,Q),e=e+Math.imul($,X)|0,u=Math.imul($,Q),f=f+Math.imul(W,tt)|0,e=e+Math.imul(W,et)|0,e=e+Math.imul(J,tt)|0,u=u+Math.imul(J,et)|0,f=f+Math.imul(H,rt)|0,e=e+Math.imul(H,nt)|0,e=e+Math.imul(Z,rt)|0,u=u+Math.imul(Z,nt)|0,f=f+Math.imul(F,it)|0,e=e+Math.imul(F,at)|0,e=e+Math.imul(q,it)|0,u=u+Math.imul(q,at)|0,f=f+Math.imul(L,st)|0,e=e+Math.imul(L,ot)|0,e=e+Math.imul(G,st)|0,u=u+Math.imul(G,ot)|0,f=f+Math.imul(U,ht)|0,e=e+Math.imul(U,ft)|0,e=e+Math.imul(O,ht)|0,u=u+Math.imul(O,ft)|0,f=f+Math.imul(B,lt)|0,e=e+Math.imul(B,ut)|0,e=e+Math.imul(k,lt)|0,u=u+Math.imul(k,ut)|0,f=f+Math.imul(_,ct)|0,e=e+Math.imul(_,dt)|0,e=e+Math.imul(P,ct)|0,u=u+Math.imul(P,dt)|0;var Re=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Re>>>26)|0,Re&=67108863,f=Math.imul(V,tt),e=Math.imul(V,et),e=e+Math.imul($,tt)|0,u=Math.imul($,et),f=f+Math.imul(W,rt)|0,e=e+Math.imul(W,nt)|0,e=e+Math.imul(J,rt)|0,u=u+Math.imul(J,nt)|0,f=f+Math.imul(H,it)|0,e=e+Math.imul(H,at)|0,e=e+Math.imul(Z,it)|0,u=u+Math.imul(Z,at)|0,f=f+Math.imul(F,st)|0,e=e+Math.imul(F,ot)|0,e=e+Math.imul(q,st)|0,u=u+Math.imul(q,ot)|0,f=f+Math.imul(L,ht)|0,e=e+Math.imul(L,ft)|0,e=e+Math.imul(G,ht)|0,u=u+Math.imul(G,ft)|0,f=f+Math.imul(U,lt)|0,e=e+Math.imul(U,ut)|0,e=e+Math.imul(O,lt)|0,u=u+Math.imul(O,ut)|0,f=f+Math.imul(B,ct)|0,e=e+Math.imul(B,dt)|0,e=e+Math.imul(k,ct)|0,u=u+Math.imul(k,dt)|0;var xe=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(xe>>>26)|0,xe&=67108863,f=Math.imul(V,rt),e=Math.imul(V,nt),e=e+Math.imul($,rt)|0,u=Math.imul($,nt),f=f+Math.imul(W,it)|0,e=e+Math.imul(W,at)|0,e=e+Math.imul(J,it)|0,u=u+Math.imul(J,at)|0,f=f+Math.imul(H,st)|0,e=e+Math.imul(H,ot)|0,e=e+Math.imul(Z,st)|0,u=u+Math.imul(Z,ot)|0,f=f+Math.imul(F,ht)|0,e=e+Math.imul(F,ft)|0,e=e+Math.imul(q,ht)|0,u=u+Math.imul(q,ft)|0,f=f+Math.imul(L,lt)|0,e=e+Math.imul(L,ut)|0,e=e+Math.imul(G,lt)|0,u=u+Math.imul(G,ut)|0,f=f+Math.imul(U,ct)|0,e=e+Math.imul(U,dt)|0,e=e+Math.imul(O,ct)|0,u=u+Math.imul(O,dt)|0;var Ce=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,f=Math.imul(V,it),e=Math.imul(V,at),e=e+Math.imul($,it)|0,u=Math.imul($,at),f=f+Math.imul(W,st)|0,e=e+Math.imul(W,ot)|0,e=e+Math.imul(J,st)|0,u=u+Math.imul(J,ot)|0,f=f+Math.imul(H,ht)|0,e=e+Math.imul(H,ft)|0,e=e+Math.imul(Z,ht)|0,u=u+Math.imul(Z,ft)|0,f=f+Math.imul(F,lt)|0,e=e+Math.imul(F,ut)|0,e=e+Math.imul(q,lt)|0,u=u+Math.imul(q,ut)|0,f=f+Math.imul(L,ct)|0,e=e+Math.imul(L,dt)|0,e=e+Math.imul(G,ct)|0,u=u+Math.imul(G,dt)|0;var be=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(be>>>26)|0,be&=67108863,f=Math.imul(V,st),e=Math.imul(V,ot),e=e+Math.imul($,st)|0,u=Math.imul($,ot),f=f+Math.imul(W,ht)|0,e=e+Math.imul(W,ft)|0,e=e+Math.imul(J,ht)|0,u=u+Math.imul(J,ft)|0,f=f+Math.imul(H,lt)|0,e=e+Math.imul(H,ut)|0,e=e+Math.imul(Z,lt)|0,u=u+Math.imul(Z,ut)|0,f=f+Math.imul(F,ct)|0,e=e+Math.imul(F,dt)|0,e=e+Math.imul(q,ct)|0,u=u+Math.imul(q,dt)|0;var Se=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Se>>>26)|0,Se&=67108863,f=Math.imul(V,ht),e=Math.imul(V,ft),e=e+Math.imul($,ht)|0,u=Math.imul($,ft),f=f+Math.imul(W,lt)|0,e=e+Math.imul(W,ut)|0,e=e+Math.imul(J,lt)|0,u=u+Math.imul(J,ut)|0,f=f+Math.imul(H,ct)|0,e=e+Math.imul(H,dt)|0,e=e+Math.imul(Z,ct)|0,u=u+Math.imul(Z,dt)|0;var Ie=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,f=Math.imul(V,lt),e=Math.imul(V,ut),e=e+Math.imul($,lt)|0,u=Math.imul($,ut),f=f+Math.imul(W,ct)|0,e=e+Math.imul(W,dt)|0,e=e+Math.imul(J,ct)|0,u=u+Math.imul(J,dt)|0;var _e=(m+f|0)+((e&8191)<<13)|0;m=(u+(e>>>13)|0)+(_e>>>26)|0,_e&=67108863,f=Math.imul(V,ct),e=Math.imul(V,dt),e=e+Math.imul($,ct)|0,u=Math.imul($,dt);var Pe=(m+f|0)+((e&8191)<<13)|0;return m=(u+(e>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,d[0]=de,d[1]=me,d[2]=pe,d[3]=ge,d[4]=ve,d[5]=ye,d[6]=we,d[7]=Me,d[8]=Ee,d[9]=Te,d[10]=Ae,d[11]=Re,d[12]=xe,d[13]=Ce,d[14]=be,d[15]=Se,d[16]=Ie,d[17]=_e,d[18]=Pe,m!==0&&(d[19]=m,i.length++),i};Math.imul||(Gt=wt);function sr(c,t,r){r.negative=t.negative^c.negative,r.length=c.length+t.length;for(var i=0,o=0,l=0;l<r.length-1;l++){var d=o;o=0;for(var m=i&67108863,f=Math.min(l,t.length-1),e=Math.max(0,l-c.length+1);e<=f;e++){var u=l-e,w=c.words[u]|0,M=t.words[e]|0,T=w*M,x=T&67108863;d=d+(T/67108864|0)|0,x=x+m|0,m=x&67108863,d=d+(x>>>26)|0,o+=d>>>26,d&=67108863;}r.words[l]=m,i=d,d=o;}return i!==0?r.words[l]=i:r.length--,r._strip()}function or(c,t,r){return sr(c,t,r)}a.prototype.mulTo=function(t,r){var i,o=this.length+t.length;return this.length===10&&t.length===10?i=Gt(this,t,r):o<63?i=wt(this,t,r):o<1024?i=sr(this,t,r):i=or(this,t,r),i};a.prototype.mul=function(t){var r=new a(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},a.prototype.mulf=function(t){var r=new a(null);return r.words=new Array(this.length+t.length),or(this,t,r)},a.prototype.imul=function(t){return this.clone().mulTo(t,this)},a.prototype.imuln=function(t){var r=t<0;r&&(t=-t),h(typeof t=="number"),h(t<67108864);for(var i=0,o=0;o<this.length;o++){var l=(this.words[o]|0)*t,d=(l&67108863)+(i&67108863);i>>=26,i+=l/67108864|0,i+=d>>>26,this.words[o]=d&67108863;}return i!==0&&(this.words[o]=i,this.length++),r?this.ineg():this},a.prototype.muln=function(t){return this.clone().imuln(t)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(t){var r=Et(t);if(r.length===0)return new a(1);for(var i=this,o=0;o<r.length&&r[o]===0;o++,i=i.sqr());if(++o<r.length)for(var l=i.sqr();o<r.length;o++,l=l.sqr())r[o]!==0&&(i=i.mul(l));return i},a.prototype.iushln=function(t){h(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,o=67108863>>>26-r<<26-r,l;if(r!==0){var d=0;for(l=0;l<this.length;l++){var m=this.words[l]&o,f=(this.words[l]|0)-m<<r;this.words[l]=f|d,d=m>>>26-r;}d&&(this.words[l]=d,this.length++);}if(i!==0){for(l=this.length-1;l>=0;l--)this.words[l+i]=this.words[l];for(l=0;l<i;l++)this.words[l]=0;this.length+=i;}return this._strip()},a.prototype.ishln=function(t){return h(this.negative===0),this.iushln(t)},a.prototype.iushrn=function(t,r,i){h(typeof t=="number"&&t>=0);var o;r?o=(r-r%26)/26:o=0;var l=t%26,d=Math.min((t-l)/26,this.length),m=67108863^67108863>>>l<<l,f=i;if(o-=d,o=Math.max(0,o),f){for(var e=0;e<d;e++)f.words[e]=this.words[e];f.length=d;}if(d!==0)if(this.length>d)for(this.length-=d,e=0;e<this.length;e++)this.words[e]=this.words[e+d];else this.words[0]=0,this.length=1;var u=0;for(e=this.length-1;e>=0&&(u!==0||e>=o);e--){var w=this.words[e]|0;this.words[e]=u<<26-l|w>>>l,u=w&m;}return f&&u!==0&&(f.words[f.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(t,r,i){return h(this.negative===0),this.iushrn(t,r,i)},a.prototype.shln=function(t){return this.clone().ishln(t)},a.prototype.ushln=function(t){return this.clone().iushln(t)},a.prototype.shrn=function(t){return this.clone().ishrn(t)},a.prototype.ushrn=function(t){return this.clone().iushrn(t)},a.prototype.testn=function(t){h(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26,o=1<<r;if(this.length<=i)return !1;var l=this.words[i];return !!(l&o)},a.prototype.imaskn=function(t){h(typeof t=="number"&&t>=0);var r=t%26,i=(t-r)/26;if(h(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(r!==0&&i++,this.length=Math.min(i,this.length),r!==0){var o=67108863^67108863>>>r<<r;this.words[this.length-1]&=o;}return this._strip()},a.prototype.maskn=function(t){return this.clone().imaskn(t)},a.prototype.iaddn=function(t){return h(typeof t=="number"),h(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<=t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},a.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},a.prototype.isubn=function(t){if(h(typeof t=="number"),h(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this._strip()},a.prototype.addn=function(t){return this.clone().iaddn(t)},a.prototype.subn=function(t){return this.clone().isubn(t)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(t,r,i){var o=t.length+i,l;this._expand(o);var d,m=0;for(l=0;l<t.length;l++){d=(this.words[l+i]|0)+m;var f=(t.words[l]|0)*r;d-=f&67108863,m=(d>>26)-(f/67108864|0),this.words[l+i]=d&67108863;}for(;l<this.length-i;l++)d=(this.words[l+i]|0)+m,m=d>>26,this.words[l+i]=d&67108863;if(m===0)return this._strip();for(h(m===-1),m=0,l=0;l<this.length;l++)d=-(this.words[l]|0)+m,m=d>>26,this.words[l]=d&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(t,r){var i=this.length-t.length,o=this.clone(),l=t,d=l.words[l.length-1]|0,m=this._countBits(d);i=26-m,i!==0&&(l=l.ushln(i),o.iushln(i),d=l.words[l.length-1]|0);var f=o.length-l.length,e;if(r!=="mod"){e=new a(null),e.length=f+1,e.words=new Array(e.length);for(var u=0;u<e.length;u++)e.words[u]=0;}var w=o.clone()._ishlnsubmul(l,1,f);w.negative===0&&(o=w,e&&(e.words[f]=1));for(var M=f-1;M>=0;M--){var T=(o.words[l.length+M]|0)*67108864+(o.words[l.length+M-1]|0);for(T=Math.min(T/d|0,67108863),o._ishlnsubmul(l,T,M);o.negative!==0;)T--,o.negative=0,o._ishlnsubmul(l,1,M),o.isZero()||(o.negative^=1);e&&(e.words[M]=T);}return e&&e._strip(),o._strip(),r!=="div"&&i!==0&&o.iushrn(i),{div:e||null,mod:o}},a.prototype.divmod=function(t,r,i){if(h(!t.isZero()),this.isZero())return {div:new a(0),mod:new a(0)};var o,l,d;return this.negative!==0&&t.negative===0?(d=this.neg().divmod(t,r),r!=="mod"&&(o=d.div.neg()),r!=="div"&&(l=d.mod.neg(),i&&l.negative!==0&&l.iadd(t)),{div:o,mod:l}):this.negative===0&&t.negative!==0?(d=this.divmod(t.neg(),r),r!=="mod"&&(o=d.div.neg()),{div:o,mod:d.mod}):this.negative&t.negative?(d=this.neg().divmod(t.neg(),r),r!=="div"&&(l=d.mod.neg(),i&&l.negative!==0&&l.isub(t)),{div:d.div,mod:l}):t.length>this.length||this.cmp(t)<0?{div:new a(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new a(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new a(this.modrn(t.words[0]))}:this._wordDiv(t,r)},a.prototype.div=function(t){return this.divmod(t,"div",!1).div},a.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},a.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},a.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var i=r.div.negative!==0?r.mod.isub(t):r.mod,o=t.ushrn(1),l=t.andln(1),d=i.cmp(o);return d<0||l===1&&d===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},a.prototype.modrn=function(t){var r=t<0;r&&(t=-t),h(t<=67108863);for(var i=(1<<26)%t,o=0,l=this.length-1;l>=0;l--)o=(i*o+(this.words[l]|0))%t;return r?-o:o},a.prototype.modn=function(t){return this.modrn(t)},a.prototype.idivn=function(t){var r=t<0;r&&(t=-t),h(t<=67108863);for(var i=0,o=this.length-1;o>=0;o--){var l=(this.words[o]|0)+i*67108864;this.words[o]=l/t|0,i=l%t;}return this._strip(),r?this.ineg():this},a.prototype.divn=function(t){return this.clone().idivn(t)},a.prototype.egcd=function(t){h(t.negative===0),h(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var o=new a(1),l=new a(0),d=new a(0),m=new a(1),f=0;r.isEven()&&i.isEven();)r.iushrn(1),i.iushrn(1),++f;for(var e=i.clone(),u=r.clone();!r.isZero();){for(var w=0,M=1;!(r.words[0]&M)&&w<26;++w,M<<=1);if(w>0)for(r.iushrn(w);w-- >0;)(o.isOdd()||l.isOdd())&&(o.iadd(e),l.isub(u)),o.iushrn(1),l.iushrn(1);for(var T=0,x=1;!(i.words[0]&x)&&T<26;++T,x<<=1);if(T>0)for(i.iushrn(T);T-- >0;)(d.isOdd()||m.isOdd())&&(d.iadd(e),m.isub(u)),d.iushrn(1),m.iushrn(1);r.cmp(i)>=0?(r.isub(i),o.isub(d),l.isub(m)):(i.isub(r),d.isub(o),m.isub(l));}return {a:d,b:m,gcd:i.iushln(f)}},a.prototype._invmp=function(t){h(t.negative===0),h(!t.isZero());var r=this,i=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var o=new a(1),l=new a(0),d=i.clone();r.cmpn(1)>0&&i.cmpn(1)>0;){for(var m=0,f=1;!(r.words[0]&f)&&m<26;++m,f<<=1);if(m>0)for(r.iushrn(m);m-- >0;)o.isOdd()&&o.iadd(d),o.iushrn(1);for(var e=0,u=1;!(i.words[0]&u)&&e<26;++e,u<<=1);if(e>0)for(i.iushrn(e);e-- >0;)l.isOdd()&&l.iadd(d),l.iushrn(1);r.cmp(i)>=0?(r.isub(i),o.isub(l)):(i.isub(r),l.isub(o));}var w;return r.cmpn(1)===0?w=o:w=l,w.cmpn(0)<0&&w.iadd(t),w},a.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),i=t.clone();r.negative=0,i.negative=0;for(var o=0;r.isEven()&&i.isEven();o++)r.iushrn(1),i.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;i.isEven();)i.iushrn(1);var l=r.cmp(i);if(l<0){var d=r;r=i,i=d;}else if(l===0||i.cmpn(1)===0)break;r.isub(i);}while(!0);return i.iushln(o)},a.prototype.invm=function(t){return this.egcd(t).a.umod(t)},a.prototype.isEven=function(){return (this.words[0]&1)===0},a.prototype.isOdd=function(){return (this.words[0]&1)===1},a.prototype.andln=function(t){return this.words[0]&t},a.prototype.bincn=function(t){h(typeof t=="number");var r=t%26,i=(t-r)/26,o=1<<r;if(this.length<=i)return this._expand(i+1),this.words[i]|=o,this;for(var l=o,d=i;l!==0&&d<this.length;d++){var m=this.words[d]|0;m+=l,l=m>>>26,m&=67108863,this.words[d]=m;}return l!==0&&(this.words[d]=l,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return -1;if(this.negative===0&&r)return 1;this._strip();var i;if(this.length>1)i=1;else {r&&(t=-t),h(t<=67108863,"Number is too big");var o=this.words[0]|0;i=o===t?0:o<t?-1:1;}return this.negative!==0?-i|0:i},a.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return -1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},a.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return -1;for(var r=0,i=this.length-1;i>=0;i--){var o=this.words[i]|0,l=t.words[i]|0;if(o!==l){o<l?r=-1:o>l&&(r=1);break}}return r},a.prototype.gtn=function(t){return this.cmpn(t)===1},a.prototype.gt=function(t){return this.cmp(t)===1},a.prototype.gten=function(t){return this.cmpn(t)>=0},a.prototype.gte=function(t){return this.cmp(t)>=0},a.prototype.ltn=function(t){return this.cmpn(t)===-1},a.prototype.lt=function(t){return this.cmp(t)===-1},a.prototype.lten=function(t){return this.cmpn(t)<=0},a.prototype.lte=function(t){return this.cmp(t)<=0},a.prototype.eqn=function(t){return this.cmpn(t)===0},a.prototype.eq=function(t){return this.cmp(t)===0},a.red=function(t){return new N(t)},a.prototype.toRed=function(t){return h(!this.red,"Already a number in reduction context"),h(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},a.prototype.fromRed=function(){return h(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(t){return this.red=t,this},a.prototype.forceRed=function(t){return h(!this.red,"Already a number in reduction context"),this._forceRed(t)},a.prototype.redAdd=function(t){return h(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},a.prototype.redIAdd=function(t){return h(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},a.prototype.redSub=function(t){return h(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},a.prototype.redISub=function(t){return h(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},a.prototype.redShl=function(t){return h(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},a.prototype.redMul=function(t){return h(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},a.prototype.redIMul=function(t){return h(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},a.prototype.redSqr=function(){return h(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return h(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return h(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return h(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return h(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(t){return h(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var ue={k256:null,p224:null,p192:null,p25519:null};function gt(c,t){this.name=c,this.p=new a(t,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp();}gt.prototype._tmp=function(){var t=new a(null);return t.words=new Array(Math.ceil(this.n/13)),t},gt.prototype.ireduce=function(t){var r=t,i;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),i=r.bitLength();while(i>this.n);var o=i<this.n?-1:r.ucmp(this.p);return o===0?(r.words[0]=0,r.length=1):o>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},gt.prototype.split=function(t,r){t.iushrn(this.n,0,r);},gt.prototype.imulK=function(t){return t.imul(this.k)};function Ft(){gt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");}p(Ft,gt),Ft.prototype.split=function(t,r){for(var i=4194303,o=Math.min(t.length,9),l=0;l<o;l++)r.words[l]=t.words[l];if(r.length=o,t.length<=9){t.words[0]=0,t.length=1;return}var d=t.words[9];for(r.words[r.length++]=d&i,l=10;l<t.length;l++){var m=t.words[l]|0;t.words[l-10]=(m&i)<<4|d>>>22,d=m;}d>>>=22,t.words[l-10]=d,d===0&&t.length>10?t.length-=10:t.length-=9;},Ft.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,i=0;i<t.length;i++){var o=t.words[i]|0;r+=o*977,t.words[i]=r&67108863,r=o*64+(r/67108864|0);}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function hr(){gt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");}p(hr,gt);function fr(){gt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");}p(fr,gt);function ce(){gt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");}p(ce,gt),ce.prototype.imulK=function(t){for(var r=0,i=0;i<t.length;i++){var o=(t.words[i]|0)*19+r,l=o&67108863;o>>>=26,t.words[i]=l,r=o;}return r!==0&&(t.words[t.length++]=r),t},a._prime=function(t){if(ue[t])return ue[t];var r;if(t==="k256")r=new Ft;else if(t==="p224")r=new hr;else if(t==="p192")r=new fr;else if(t==="p25519")r=new ce;else throw new Error("Unknown prime "+t);return ue[t]=r,r};function N(c){if(typeof c=="string"){var t=a._prime(c);this.m=t.p,this.prime=t;}else h(c.gtn(1),"modulus must be greater than 1"),this.m=c,this.prime=null;}N.prototype._verify1=function(t){h(t.negative===0,"red works only with positives"),h(t.red,"red works only with red numbers");},N.prototype._verify2=function(t,r){h((t.negative|r.negative)===0,"red works only with positives"),h(t.red&&t.red===r.red,"red works only with red numbers");},N.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(C(t,t.umod(this.m)._forceRed(this)),t)},N.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},N.prototype.add=function(t,r){this._verify2(t,r);var i=t.add(r);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},N.prototype.iadd=function(t,r){this._verify2(t,r);var i=t.iadd(r);return i.cmp(this.m)>=0&&i.isub(this.m),i},N.prototype.sub=function(t,r){this._verify2(t,r);var i=t.sub(r);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},N.prototype.isub=function(t,r){this._verify2(t,r);var i=t.isub(r);return i.cmpn(0)<0&&i.iadd(this.m),i},N.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},N.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},N.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},N.prototype.isqr=function(t){return this.imul(t,t.clone())},N.prototype.sqr=function(t){return this.mul(t,t)},N.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(h(r%2===1),r===3){var i=this.m.add(new a(1)).iushrn(2);return this.pow(t,i)}for(var o=this.m.subn(1),l=0;!o.isZero()&&o.andln(1)===0;)l++,o.iushrn(1);h(!o.isZero());var d=new a(1).toRed(this),m=d.redNeg(),f=this.m.subn(1).iushrn(1),e=this.m.bitLength();for(e=new a(2*e*e).toRed(this);this.pow(e,f).cmp(m)!==0;)e.redIAdd(m);for(var u=this.pow(e,o),w=this.pow(t,o.addn(1).iushrn(1)),M=this.pow(t,o),T=l;M.cmp(d)!==0;){for(var x=M,b=0;x.cmp(d)!==0;b++)x=x.redSqr();h(b<T);var I=this.pow(u,new a(1).iushln(T-b-1));w=w.redMul(I),u=I.redSqr(),M=M.redMul(u),T=b;}return w},N.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},N.prototype.pow=function(t,r){if(r.isZero())return new a(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var i=4,o=new Array(1<<i);o[0]=new a(1).toRed(this),o[1]=t;for(var l=2;l<o.length;l++)o[l]=this.mul(o[l-1],t);var d=o[0],m=0,f=0,e=r.bitLength()%26;for(e===0&&(e=26),l=r.length-1;l>=0;l--){for(var u=r.words[l],w=e-1;w>=0;w--){var M=u>>w&1;if(d!==o[0]&&(d=this.sqr(d)),M===0&&m===0){f=0;continue}m<<=1,m|=M,f++,!(f!==i&&(l!==0||w!==0))&&(d=this.mul(d,o[m]),f=0,m=0);}e=26;}return d},N.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},N.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},a.mont=function(t){return new St(t)};function St(c){N.call(this,c),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(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);}p(St,N),St.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},St.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},St.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(r),o=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),l=i.isub(o).iushrn(this.shift),d=l;return l.cmp(this.m)>=0?d=l.isub(this.m):l.cmpn(0)<0&&(d=l.iadd(this.m)),d._forceRed(this)},St.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new a(0)._forceRed(this);var i=t.mul(r),o=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),l=i.isub(o).iushrn(this.shift),d=l;return l.cmp(this.m)>=0?d=l.isub(this.m):l.cmpn(0)<0&&(d=l.iadd(this.m)),d._forceRed(this)},St.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)};})(typeof Le>"u"||Le,Fr);});var Fe=qt((ka,Wr)=>{Wr.exports=Ge;Ge.strict=Hr;Ge.loose=Zr;var ti=Object.prototype.toString,ei={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0};function Ge(n){return Hr(n)||Zr(n)}function Hr(n){return n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray||n instanceof Uint16Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array}function Zr(n){return ei[ti.call(n)]}});var Vr=qt((Ua,Jr)=>{var ri=Fe().strict;Jr.exports=function(s){if(ri(s)){var h=Buffer.from(s.buffer);return s.byteLength!==s.buffer.byteLength&&(h=h.slice(s.byteOffset,s.byteOffset+s.byteLength)),h}else return Buffer.from(s)};});var hn=qt(E=>{var $r=E&&E.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(E,"__esModule",{value:!0});var ni=$r(Fe()),ii=$r(Vr()),qe="hex",He="utf8",ai="binary",si="buffer",oi="array",hi="typed-array",fi="array-buffer",Bt="0";function zt(n){return new Uint8Array(n)}E.bufferToArray=zt;function Ze(n,s=!1){let h=n.toString(qe);return s?Qt(h):h}E.bufferToHex=Ze;function We(n){return n.toString(He)}E.bufferToUtf8=We;function zr(n){return n.readUIntBE(0,n.length)}E.bufferToNumber=zr;function li(n){return jt(zt(n))}E.bufferToBinary=li;function kt(n){return ii.default(n)}E.arrayToBuffer=kt;function jr(n,s=!1){return Ze(kt(n),s)}E.arrayToHex=jr;function Yr(n){return We(kt(n))}E.arrayToUtf8=Yr;function Je(n){return zr(kt(n))}E.arrayToNumber=Je;function jt(n){return Array.from(n).map(Ut).join("")}E.arrayToBinary=jt;function Ve(n){return Buffer.from(Xt(n),qe)}E.hexToBuffer=Ve;function $e(n){return zt(Ve(n))}E.hexToArray=$e;function ui(n){return We(Ve(n))}E.hexToUtf8=ui;function ci(n){return Je($e(n))}E.hexToNumber=ci;function Kr(n){return jt($e(n))}E.hexToBinary=Kr;function ze(n){return Buffer.from(n,He)}E.utf8ToBuffer=ze;function Xr(n){return zt(ze(n))}E.utf8ToArray=Xr;function di(n,s=!1){return Ze(ze(n),s)}E.utf8ToHex=di;function mi(n){let s=parseInt(n,10);return Bi(Di(s),"Number can only safely store up to 53 bits"),s}E.utf8ToNumber=mi;function pi(n){return jt(Xr(n))}E.utf8ToBinary=pi;function gi(n){return Qr(Ut(n))}E.numberToBuffer=gi;function vi(n){return _t(Ut(n))}E.numberToArray=vi;function yi(n,s){return je(Ut(n),s)}E.numberToHex=yi;function wi(n){return `${n}`}E.numberToUtf8=wi;function Ut(n){let s=(n>>>0).toString(2);return Kt(s)}E.numberToBinary=Ut;function Qr(n){return kt(_t(n))}E.binaryToBuffer=Qr;function _t(n){return new Uint8Array(Ke(n).map(s=>parseInt(s,2)))}E.binaryToArray=_t;function je(n,s){return jr(_t(n),s)}E.binaryToHex=je;function Mi(n){return Yr(_t(n))}E.binaryToUtf8=Mi;function Ei(n){return Je(_t(n))}E.binaryToNumber=Ei;function tn(n){return !(typeof n!="string"||!new RegExp(/^[01]+$/).test(n)||n.length%8!==0)}E.isBinaryString=tn;function en(n,s){return !(typeof n!="string"||!n.match(/^0x[0-9A-Fa-f]*$/)||s&&n.length!==2+2*s)}E.isHexString=en;function Yt(n){return Buffer.isBuffer(n)}E.isBuffer=Yt;function Ye(n){return ni.default.strict(n)&&!Yt(n)}E.isTypedArray=Ye;function rn(n){return !Ye(n)&&!Yt(n)&&typeof n.byteLength<"u"}E.isArrayBuffer=rn;function Ti(n){return Yt(n)?si:Ye(n)?hi:rn(n)?fi:Array.isArray(n)?oi:typeof n}E.getType=Ti;function Ai(n){return tn(n)?ai:en(n)?qe:He}E.getEncoding=Ai;function Ri(...n){return Buffer.concat(n)}E.concatBuffers=Ri;function xi(...n){let s=[];return n.forEach(h=>s=s.concat(Array.from(h))),new Uint8Array([...s])}E.concatArrays=xi;function Ci(n,s){let h=n.length-s;return h>0&&(n=n.slice(h)),n}E.trimLeft=Ci;function bi(n,s){return n.slice(0,s)}E.trimRight=bi;function nn(n,s=8){let h=n%s;return h?(n-h)/s*s+s:n}E.calcByteLength=nn;function Ke(n,s=8){let h=Kt(n).match(new RegExp(`.{${s}}`,"gi"));return Array.from(h||[])}E.splitBytes=Ke;function an(n){return Ke(n).map(ki).join("")}E.swapBytes=an;function Si(n){return je(an(Kr(n)))}E.swapHex=Si;function Kt(n,s=8,h=Bt){return sn(n,nn(n.length,s),h)}E.sanitizeBytes=Kt;function sn(n,s,h=Bt){return on(n,s,!0,h)}E.padLeft=sn;function Ii(n,s,h=Bt){return on(n,s,!1,h)}E.padRight=Ii;function Xt(n){return n.replace(/^0x/,"")}E.removeHexPrefix=Xt;function Qt(n){return n.startsWith("0x")?n:`0x${n}`}E.addHexPrefix=Qt;function _i(n){return n=Xt(n),n=Kt(n,2),n&&(n=Qt(n)),n}E.sanitizeHex=_i;function Pi(n){let s=n.startsWith("0x");return n=Xt(n),n=n.startsWith(Bt)?n.substring(1):n,s?Qt(n):n}E.removeHexLeadingZeros=Pi;function Ni(n){return typeof n>"u"}function Di(n){return !Ni(n)}function Bi(n,s){if(!n)throw new Error(s)}function ki(n){return n.split("").reverse().join("")}function on(n,s,h,p=Bt){let a=s-n.length,g=n;if(a>0){let v=p.repeat(a);g=h?v+n:n+v;}return g}});var It=class{emitter=new EventEmitter;emit(s,...h){this.emitter.emit(s,...h);}on(s,h){this.emitter.on(s,h);}removeListener(s,h){this.emitter.removeListener(s,h);}};var Sr=(p=>(p.LOGGED_OUT="loggedOut",p.LOGGED_IN="loggedIn",p.ACCOUNTS_REQUESTED="accountsRequested",p))(Sr||{}),qn=(s=>(s.ACCOUNTS_CHANGED="accountsChanged",s))(qn||{}),Hn=(v=>(v.PENDING="PENDING",v.SUBMITTED="SUBMITTED",v.SUCCESSFUL="SUCCESSFUL",v.REVERTED="REVERTED",v.FAILED="FAILED",v.CANCELLED="CANCELLED",v))(Hn||{});var Gr={};Ln(Gr,{coerceNonceSpace:()=>Or,digestOfTransactionsAndNonce:()=>Ur,encodeMessageSubDigest:()=>Wt,encodeNonce:()=>Lr,encodedTransactions:()=>ke,getEip155ChainId:()=>pt,getNonce:()=>Nt,getNormalisedTransactions:()=>Zt,packSignatures:()=>Vt,signAndPackTypedData:()=>Ue,signERC191Message:()=>Oe,signMetaTransactions:()=>Jt});var Dr=1,Yn=1,Kn=2,Br="02",Xn="",kr=`tuple(
14
+ bool delegateCall,
15
+ bool revertOnError,
16
+ uint256 gasLimit,
17
+ address target,
18
+ uint256 value,
19
+ bytes data
20
+ )[]`,Zt=n=>n.map(s=>({delegateCall:s.delegateCall===!0,revertOnError:s.revertOnError===!0,gasLimit:s.gasLimit??BigInt(0),target:s.to??ZeroAddress,value:s.value??BigInt(0),data:s.data??"0x"})),Ur=(n,s)=>{let h=AbiCoder.defaultAbiCoder().encode(["uint256",kr],[n,s]);return keccak256(h)},ke=n=>AbiCoder.defaultAbiCoder().encode([kr],[n]),Or=n=>n||0n,Lr=(n,s)=>{let h=BigInt(n)*2n**96n;return BigInt(s)+h},Nt=async(n,s,h)=>{try{let p=new Contract(s,walletContracts.mainModule.abi,n),a=Or(h),g=await p.readNonce(a);if(typeof g=="bigint")return Lr(a,g);throw new Error("Unexpected result from contract.nonce() call.")}catch(p){if(isError(p,"BAD_DATA"))return BigInt(0);throw p}},Wt=(n,s,h)=>solidityPacked(["string","uint256","address","bytes32"],[Xn,n,s,h]),Jt=async(n,s,h,p,a)=>{let g=Zt(n),v=Ur(s,g),y=Wt(h,p,v),A=keccak256(y),C=getBytes(A),D=`${await a.signMessage(C)}${Br}`,mt=v1.signature.encodeSignature({version:1,threshold:Yn,signers:[{isDynamic:!1,unrecovered:!0,weight:Dr,signature:D}]}),yt=new Interface(walletContracts.mainModule.abi);return yt.encodeFunctionData(yt.getFunction("execute")??"",[g,s,mt])},Qn=n=>{let s=`0x0000${n}`;return v1.signature.decodeSignature(s)},Vt=(n,s,h)=>{let p=`${n}${Br}`,{signers:a}=Qn(h),v=[...a,{isDynamic:!1,unrecovered:!0,weight:Dr,signature:p,address:s}].sort((y,A)=>{let C=BigInt(y.address??0),S=BigInt(A.address??0);return C<=S?-1:C===S?0:1});return v1.signature.encodeSignature({version:1,threshold:Kn,signers:v})},Ue=async(n,s,h,p,a)=>{let g={...n.types};delete g.EIP712Domain;let v=TypedDataEncoder.hash(n.domain,g,n.message),y=Wt(h,p,v),A=keccak256(y),C=getBytes(A),S=await a.signMessage(C),D=await a.getAddress();return Vt(S,D,s)},Oe=async(n,s,h,p)=>{let a=hashMessage(s),g=Wt(n,p,a),v=keccak256(g),y=getBytes(v);return h.signMessage(y)},pt=n=>`eip155:${n}`;var Dt=class n{config;rpcProvider;authManager;constructor({config:s,rpcProvider:h,authManager:p}){this.config=s,this.rpcProvider=h,this.authManager=p;}static getResponsePreview(s){return s.length>100?`${s.substring(0,50)}...${s.substring(s.length-50)}`:s}async postToRelayer(s){let h={id:1,jsonrpc:"2.0",...s},p=await this.authManager.getUserZkEvm(),a=await fetch(`${this.config.relayerUrl}/v1/transactions`,{method:"POST",headers:{Authorization:`Bearer ${p.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(h)}),g=await a.text();if(!a.ok){let y=n.getResponsePreview(g);throw new Error(`Relayer HTTP error: ${a.status}. Content: "${y}"`)}let v;try{v=JSON.parse(g);}catch(y){let A=n.getResponsePreview(g);throw new Error(`Relayer JSON parse error: ${y instanceof Error?y.message:"Unknown error"}. Content: "${A}"`)}if(v.error)throw new Error(v.error);return v}async ethSendTransaction(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"eth_sendTransaction",params:[{to:s,data:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}async imGetTransactionByHash(s){let h={method:"im_getTransactionByHash",params:[s]},{result:p}=await this.postToRelayer(h);return p}async imGetFeeOptions(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"im_getFeeOptions",params:[{userAddress:s,data:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}async imSignTypedData(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"im_signTypedData",params:[{address:s,eip712Payload:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}async imSign(s,h){let{chainId:p}=await this.rpcProvider.getNetwork(),a={method:"im_sign",params:[{address:s,message:h,chainId:pt(Number(p))}]},{result:g}=await this.postToRelayer(a);return g}};var $t=(a=>(a[a.USER_REJECTED_REQUEST=4001]="USER_REJECTED_REQUEST",a[a.UNAUTHORIZED=4100]="UNAUTHORIZED",a[a.UNSUPPORTED_METHOD=4200]="UNSUPPORTED_METHOD",a[a.DISCONNECTED=4900]="DISCONNECTED",a))($t||{}),Tt=(y=>(y[y.RPC_SERVER_ERROR=-32e3]="RPC_SERVER_ERROR",y[y.INVALID_REQUEST=-32600]="INVALID_REQUEST",y[y.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",y[y.INVALID_PARAMS=-32602]="INVALID_PARAMS",y[y.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",y[y.PARSE_ERROR=-32700]="PARSE_ERROR",y[y.TRANSACTION_REJECTED=-32003]="TRANSACTION_REJECTED",y))(Tt||{}),R=class extends Error{message;code;constructor(s,h){super(h),this.message=h,this.code=s;}};var Rt=br(qr()),xt=br(hn());function Ui(n){return xt.addHexPrefix(xt.padLeft(n.r.toString(16),64)+xt.padLeft(n.s.toString(16),64)+xt.padLeft(n.recoveryParam?.toString(16)||"",2))}function Oi(n){let s=new Rt.default(n,16).cmp(new Rt.default(27))!==-1?new Rt.default(n,16).sub(new Rt.default(27)).toNumber():new Rt.default(n,16).toNumber();return n.trim()?s:void 0}function Li(n,s=64){let h=xt.removeHexPrefix(n);return {r:new Rt.default(h.substring(0,s),"hex"),s:new Rt.default(h.substring(s,s*2),"hex"),recoveryParam:Oi(h.substring(s*2,s*2+2))}}async function fn(n,s){let h=Li(await s.signMessage(n));return Ui(h)}var Gi="Only sign this message from Immutable Passport";async function ln({authManager:n,ethSigner:s,multiRollupApiClients:h,accessToken:p,rpcProvider:a,flow:g}){let v=s.getAddress();v.then(()=>g.addEvent("endGetAddress"));let y=fn(Gi,s);y.then(()=>g.addEvent("endSignRaw"));let A=a.getNetwork();A.then(()=>g.addEvent("endDetectNetwork"));let C=h.chainsApi.listChains();C.then(()=>g.addEvent("endListChains"));let[S,D,mt,yt]=await Promise.all([v,y,A,C]),bt=pt(Number(mt.chainId)),Et=yt.data?.result?.find(wt=>wt.id===bt)?.name;if(!Et)throw new R(-32603,`Chain name does not exist on for chain id ${mt.chainId}`);try{let wt=await h.passportApi.createCounterfactualAddressV2({chainName:Et,createCounterfactualAddressRequest:{ethereum_address:S,ethereum_signature:D}},{headers:{Authorization:`Bearer ${p}`}});return g.addEvent("endCreateCounterfactualAddress"),n.forceUserRefreshInBackground(),wt.data.counterfactual_address}catch(wt){throw new R(-32603,`Failed to create counterfactual address: ${wt}`)}}var Fi=n=>new Promise(s=>{setTimeout(()=>s(),n);}),Pt=async(n,s)=>{let{retries:h=3,interval:p=1e3,finalErr:a=Error("Retry failed"),finallyFn:g=()=>{}}=s||{};try{return await n()}catch{return h<=0?Promise.reject(a):(await Fi(p),Pt(n,{retries:h-1,finalErr:a,finallyFn:g}))}finally{h<=0&&g();}};var te=(y=>(y.WALLET_CONNECTION_ERROR="WALLET_CONNECTION_ERROR",y.TRANSACTION_REJECTED="TRANSACTION_REJECTED",y.INVALID_CONFIGURATION="INVALID_CONFIGURATION",y.UNAUTHORIZED="UNAUTHORIZED",y.GUARDIAN_ERROR="GUARDIAN_ERROR",y.SERVICE_UNAVAILABLE_ERROR="SERVICE_UNAVAILABLE_ERROR",y.NOT_LOGGED_IN_ERROR="NOT_LOGGED_IN_ERROR",y))(te||{}),vt=class extends Error{type;constructor(s,h){super(s),this.name="WalletError",this.type=h;}};var ee="Transaction requires confirmation but this functionality is not supported in this environment. Please contact Immutable support if you need to enable this feature.",re=n=>BigInt(n).toString(),Hi=n=>{try{return n.map(s=>({delegateCall:s.delegateCall===!0,revertOnError:s.revertOnError===!0,gasLimit:s.gasLimit?re(s.gasLimit):"0",target:s.to??ZeroAddress,value:s.value?re(s.value):"0",data:s.data?s.data.toString():"0x"}))}catch(s){let h=s instanceof Error?s.message:String(s);throw new R(-32602,`Transaction failed to parsing: ${h}`)}},ne=class{guardianApi;confirmationScreen;crossSdkBridgeEnabled;authManager;constructor({confirmationScreen:s,config:h,authManager:p,guardianApi:a}){this.confirmationScreen=s,this.crossSdkBridgeEnabled=h.crossSdkBridgeEnabled,this.guardianApi=a,this.authManager=p;}withConfirmationScreen(s){return h=>this.withConfirmationScreenTask(s)(h)()}withConfirmationScreenTask(s){return h=>async()=>{this.confirmationScreen.loading(s);try{return await h()}catch(p){throw p instanceof vt&&p.type==="SERVICE_UNAVAILABLE_ERROR"?(await this.confirmationScreen.showServiceUnavailable(),p):(this.confirmationScreen.closeWindow(),p)}}}withDefaultConfirmationScreenTask(s){return this.withConfirmationScreenTask()(s)}async evaluateImxTransaction({payloadHash:s}){try{let h=()=>{this.confirmationScreen.closeWindow();},p=await this.authManager.getUserImx(),a={Authorization:`Bearer ${p.accessToken}`};if(!(await Pt(async()=>this.guardianApi.getTransactionByID({transactionID:s,chainType:"starkex"},{headers:a}),{finallyFn:h})).data.id)throw new Error("Transaction doesn't exists");let v=await this.guardianApi.evaluateTransaction({id:s,transactionEvaluationRequest:{chainType:"starkex"}},{headers:a}),{confirmationRequired:y}=v.data;if(y){if(this.crossSdkBridgeEnabled)throw new Error(ee);if(!(await this.confirmationScreen.requestConfirmation(s,p.imx.ethAddress,Xe.mr.TransactionApprovalRequestChainTypeEnum.Starkex)).confirmed)throw new Error("Transaction rejected by user")}else this.confirmationScreen.closeWindow();}catch(h){throw un.isAxiosError(h)&&h.response?.status===403?new vt("Service unavailable","SERVICE_UNAVAILABLE_ERROR"):h}}async evaluateEVMTransaction({chainId:s,nonce:h,metaTransactions:p}){let a=await this.authManager.getUserZkEvm(),g={Authorization:`Bearer ${a.accessToken}`},v=Hi(p);try{return (await this.guardianApi.evaluateTransaction({id:"evm",transactionEvaluationRequest:{chainType:"evm",chainId:s,transactionData:{nonce:h,userAddress:a.zkEvm.ethAddress,metaTransactions:v}}},{headers:g})).data}catch(y){if(un.isAxiosError(y)&&y.response?.status===403)throw new vt("Service unavailable","SERVICE_UNAVAILABLE_ERROR");let A=y instanceof Error?y.message:String(y);throw new R(-32603,`Transaction failed to validate with error: ${A}`)}}async validateEVMTransaction({chainId:s,nonce:h,metaTransactions:p,isBackgroundTransaction:a}){let g=await this.evaluateEVMTransaction({chainId:s,nonce:h,metaTransactions:p}),{confirmationRequired:v,transactionId:y}=g;if(v&&this.crossSdkBridgeEnabled)throw new R(-32003,ee);if(v&&y){let A=await this.authManager.getUserZkEvm();if(!(await this.confirmationScreen.requestConfirmation(y,A.zkEvm.ethAddress,Xe.mr.TransactionApprovalRequestChainTypeEnum.Evm,s)).confirmed)throw new R(-32003,"Transaction rejected by user")}else a||this.confirmationScreen.closeWindow();}async handleEIP712MessageEvaluation({chainID:s,payload:h}){try{let p=await this.authManager.getUserZkEvm();if(p===null)throw new R(4100,"User not logged in. Please log in first.");return (await this.guardianApi.evaluateMessage({messageEvaluationRequest:{chainID:s,payload:h}},{headers:{Authorization:`Bearer ${p.accessToken}`}})).data}catch(p){let a=p instanceof Error?p.message:String(p);throw new R(-32603,`Message failed to validate with error: ${a}`)}}async evaluateEIP712Message({chainID:s,payload:h}){let{messageId:p,confirmationRequired:a}=await this.handleEIP712MessageEvaluation({chainID:s,payload:h});if(a&&this.crossSdkBridgeEnabled)throw new R(-32003,ee);if(a&&p){let g=await this.authManager.getUserZkEvm();if(!(await this.confirmationScreen.requestMessageConfirmation(p,g.zkEvm.ethAddress,"eip712")).confirmed)throw new R(-32003,"Signature rejected by user")}else this.confirmationScreen.closeWindow();}async handleERC191MessageEvaluation({chainID:s,payload:h}){try{let p=await this.authManager.getUserZkEvm();if(p===null)throw new R(4100,"User not logged in. Please log in first.");return (await this.guardianApi.evaluateErc191Message({eRC191MessageEvaluationRequest:{chainID:pt(Number(s)),payload:h}},{headers:{Authorization:`Bearer ${p.accessToken}`}})).data}catch(p){let a=p instanceof Error?p.message:String(p);throw new R(-32603,`Message failed to validate with error: ${a}`)}}async evaluateERC191Message({chainID:s,payload:h}){let{messageId:p,confirmationRequired:a}=await this.handleERC191MessageEvaluation({chainID:s,payload:h});if(a&&this.crossSdkBridgeEnabled)throw new R(-32003,ee);if(a&&p){let g=await this.authManager.getUserZkEvm();if(!(await this.confirmationScreen.requestMessageConfirmation(p,g.zkEvm.ethAddress,"erc191")).confirmed)throw new R(-32003,"Signature rejected by user")}else this.confirmationScreen.closeWindow();}};var Zi=30,Wi=1e3,Ji=async(n,s,h)=>{let p=Zt([n]),a=ke(p),g=await h.imGetFeeOptions(s,a);if(!g||!Array.isArray(g))throw new Error("Invalid fee options received from relayer");let v=g.find(y=>y.tokenSymbol==="IMX");if(!v)throw new Error("Failed to retrieve fees for IMX token");return v},Vi=async(n,s,h,p,a)=>{if(!n.to)throw new R(-32602,'eth_sendTransaction requires a "to" field');let g={to:n.to.toString(),data:n.data,nonce:BigInt(0),value:n.value,revertOnError:!0},[v,y]=await Promise.all([Nt(s,p,a),Ji(g,p,h)]),A=[{...g,nonce:v}],C=BigInt(y.tokenPrice);return C!==BigInt(0)&&A.push({nonce:v,to:y.recipientAddress,value:C,revertOnError:!0}),A},ie=async(n,s,h)=>{let a=await Pt(async()=>{let g=await n.imGetTransactionByHash(s);if(g.status==="PENDING")throw new Error;return g},{retries:Zi,interval:Wi,finalErr:new R(-32e3,"transaction hash not generated in time")});if(h.addEvent("endRetrieveRelayerTransaction"),!["SUBMITTED","SUCCESSFUL"].includes(a.status)){let g=`Transaction failed to submit with status ${a.status}.`;throw a.statusMessage&&(g+=` Error message: ${a.statusMessage}`),new R(-32e3,g)}return a},ae=async({transactionRequest:n,ethSigner:s,rpcProvider:h,guardianClient:p,relayerClient:a,zkEvmAddress:g,flow:v,nonceSpace:y,isBackgroundTransaction:A})=>{let{chainId:C}=await h.getNetwork(),S=BigInt(C);v.addEvent("endDetectNetwork");let D=await Vi(n,h,a,g,y);v.addEvent("endBuildMetaTransactions");let{nonce:mt}=D[0];if(typeof mt>"u")throw new Error("Failed to retrieve nonce from the smart wallet");let yt=async()=>{await p.validateEVMTransaction({chainId:pt(Number(C)),nonce:re(mt),metaTransactions:D,isBackgroundTransaction:A}),v.addEvent("endValidateEVMTransaction");},bt=async()=>{let Gt=await Jt(D,mt,S,g,s);return v.addEvent("endGetSignedMetaTransactions"),Gt},[,Et]=await Promise.all([yt(),bt()]),wt=await a.ethSendTransaction(g,Et);return v.addEvent("endRelayerSendTransaction"),{signedTransactions:Et,relayerId:wt,nonce:mt}},$i=async n=>{if(!n.to)throw new R(-32602,'im_signEjectionTransaction requires a "to" field');if(typeof n.nonce>"u")throw new R(-32602,'im_signEjectionTransaction requires a "nonce" field');if(!n.chainId)throw new R(-32602,'im_signEjectionTransaction requires a "chainId" field');return [{to:n.to.toString(),data:n.data,nonce:n.nonce??void 0,value:n.value,revertOnError:!0}]},cn=async({transactionRequest:n,ethSigner:s,zkEvmAddress:h,flow:p})=>{let a=await $i(n);p.addEvent("endBuildMetaTransactions");let g=await Jt(a,n.nonce,BigInt(n.chainId??0),h,s);return p.addEvent("endGetSignedMetaTransactions"),{to:h,data:g,chainId:pt(Number(n.chainId??0))}};var Qe=async({params:n,ethSigner:s,rpcProvider:h,relayerClient:p,guardianClient:a,zkEvmAddress:g,flow:v,nonceSpace:y,isBackgroundTransaction:A=!1})=>{let C=n[0],{relayerId:S}=await ae({transactionRequest:C,ethSigner:s,rpcProvider:h,guardianClient:a,relayerClient:p,zkEvmAddress:g,flow:v,nonceSpace:y,isBackgroundTransaction:A}),{hash:D}=await ie(p,S,v);return D};var dn=["types","domain","primaryType","message"],zi=n=>dn.every(s=>s in n),ji=(n,s)=>{let h;if(typeof n=="string")try{h=JSON.parse(n);}catch(a){throw new R(-32602,`Failed to parse typed data JSON: ${a}`)}else if(typeof n=="object")h=n;else throw new R(-32602,`Invalid typed data argument: ${n}`);if(!zi(h))throw new R(-32602,`Invalid typed data argument. The following properties are required: ${dn.join(", ")}`);let p=h.domain?.chainId;if(p&&(typeof p=="string"&&(p.startsWith("0x")?h.domain.chainId=parseInt(p,16).toString():h.domain.chainId=parseInt(p,10).toString()),BigInt(h.domain.chainId??0)!==s))throw new R(-32602,`Invalid chainId, expected ${s}`);return h},mn=async({params:n,method:s,ethSigner:h,rpcProvider:p,relayerClient:a,guardianClient:g,flow:v})=>{let y=n[0],A=n[1];if(!y||!A)throw new R(-32602,`${s} requires an address and a typed data JSON`);let{chainId:C}=await p.getNetwork(),S=ji(A,C);v.addEvent("endDetectNetwork"),await g.evaluateEIP712Message({chainID:String(C),payload:S}),v.addEvent("endValidateMessage");let D=await a.imSignTypedData(y,S);v.addEvent("endRelayerSignTypedData");let mt=await Ue(S,D,BigInt(C),y,h);return v.addEvent("getSignedTypedData"),mt};var pn=n=>{if(!n)return n;try{let s=stripZerosLeft(getBytes(n));return toUtf8String(s)}catch{return n}};var se=async({params:n,ethSigner:s,zkEvmAddress:h,rpcProvider:p,guardianClient:a,relayerClient:g,flow:v})=>{let y=n[0],A=n[1];if(!A||!y)throw new R(-32602,"personal_sign requires an address and a message");if(A.toLowerCase()!==h.toLowerCase())throw new R(-32602,"personal_sign requires the signer to be the from address");let C=pn(y),{chainId:S}=await p.getNetwork();v.addEvent("endDetectNetwork");let D=BigInt(S),mt=Oe(D,C,s,A);mt.then(()=>v.addEvent("endEOASignature")),await a.evaluateERC191Message({chainID:S,payload:C}),v.addEvent("endEvaluateERC191Message");let[yt,bt]=await Promise.all([mt,g.imSign(A,C)]);v.addEvent("endRelayerSign");let Et=await s.getAddress();return v.addEvent("endGetEOAAddress"),Vt(yt,Et,bt)};var ta="https://api.immutable.com",ea="https://api.sandbox.immutable.com",ra="/v1/sdk/session-activity/check",na=n=>{switch(n){case Environment.SANDBOX:return ea;case Environment.PRODUCTION:return ta;default:throw new Error("Environment not supported")}},oe,vn=n=>{oe||(oe=un.create({baseURL:na(n)}));};async function yn(n){if(!oe)throw new Error("Client not initialised");return oe.get(ra,{params:n}).then(s=>s.data).catch(s=>{if(s.response.status!==404)throw s})}function Mn(n,s){return (...h)=>{try{let p=n(...h);return p instanceof Promise?p.catch(a=>(a instanceof Error&&trackError("passport","sessionActivityError",a),s)):p}catch(p){return p instanceof Error&&trackError("passport","sessionActivityError",p),s}}}var{getItem:En,setItem:tr}=utils.localStorage,er="sessionActivitySendCount",Tn="sessionActivityDate",rr={},Ct={},he={},An=()=>{Ct=En(er)||{};let n=En(Tn),s=new Date,h=s.getFullYear(),p=`${s.getMonth()+1}`.padStart(2,"0"),a=`${s.getDate()}`.padStart(2,"0"),g=`${h}-${p}-${a}`;(!n||n!==g)&&(Ct={}),tr(Tn,g),tr(er,Ct);};An();var ha=n=>{An(),Ct[n]||(Ct[n]=0),Ct[n]++,tr(er,Ct),rr[n]=0;},fa=async n=>new Promise(s=>{setTimeout(s,n*1e3);}),la=async n=>{let s=n.flow||trackFlow("passport","sendSessionActivity"),h=n.passportClient;if(!h)throw s.addEvent("No Passport Client ID"),new Error("No Passport Client ID provided");if(he[h])return;he[h]=!0;let{sendTransaction:p,environment:a}=n;if(!p)throw new Error("No sendTransaction function provided");if(!a)throw new Error("No environment provided");vn(a);let g=n.walletAddress;if(!g)throw s.addEvent("No Passport Wallet Address"),new Error("No wallet address");let v;try{if(v=await yn({clientId:h,wallet:g,checkCount:rr[h]||0,sendCount:Ct[h]||0}),rr[h]++,!v)return}catch(y){throw s.addEvent("Failed to fetch details"),new Error("Failed to get details",{cause:y})}if(v&&v.contractAddress&&v.functionName){let A=new Interface([`function ${v.functionName}()`]).encodeFunctionData(v.functionName),C=v.contractAddress;try{s.addEvent("Start Sending Transaction");let S=await n.sendTransaction([{to:C,from:g,data:A}],s);ha(h),s.addEvent("Transaction Sent",{tx:S});}catch(S){s.addEvent("Failed to send Transaction");let D=new Error("Failed to send transaction",{cause:S});trackError("passport","sessionActivityError",D,{flowId:s.details.flowId});}}v&&v.delay&&v.delay>0&&(s.addEvent("Delaying Transaction",{delay:v.delay}),await fa(v.delay),setTimeout(()=>{s.addEvent("Retrying after Delay"),he[h]=!1,Rn({...n,flow:s});},0));},Rn=n=>Mn(la)(n).then(()=>{he[n.passportClient]=!1;}),xn=Rn;var Cn=async({params:n,ethSigner:s,rpcProvider:h,relayerClient:p,guardianClient:a,zkEvmAddress:g,flow:v})=>{let y={to:g,value:0},{relayerId:A}=await ae({transactionRequest:y,ethSigner:s,rpcProvider:h,guardianClient:a,relayerClient:p,zkEvmAddress:g,flow:v});return a.withConfirmationScreen()(async()=>{let C=await se({params:n,ethSigner:s,zkEvmAddress:g,rpcProvider:h,guardianClient:a,relayerClient:p,flow:v});return await ie(p,A,v),C})};var bn=async({params:n,ethSigner:s,zkEvmAddress:h,flow:p})=>{if(!n||n.length!==1)throw new R(-32602,"im_signEjectionTransaction requires a singular param (hash)");let a=n[0];return await cn({transactionRequest:a,ethSigner:s,zkEvmAddress:h,flow:p})};var fe=n=>"zkEvm"in n,nr=class{#a;#s;#o;#f;#e;#t;#l;#i;#r;isPassport=!0;constructor({authManager:s,config:h,multiRollupApiClients:p,passportEventEmitter:a,guardianClient:g,ethSigner:v,user:y}){this.#a=s,this.#s=h,this.#e=g,this.#f=a,this.#r=v,this.#t=new JsonRpcProvider(this.#s.zkEvmRpcUrl,void 0,{staticNetwork:!0}),this.#i=new Dt({config:this.#s,rpcProvider:this.#t,authManager:this.#a}),this.#l=p,this.#o=new It,y&&fe(y)&&this.#h(y.zkEvm.ethAddress),a.on("loggedIn",A=>{fe(A)&&this.#h(A.zkEvm.ethAddress);}),a.on("loggedOut",this.#u),a.on("accountsRequested",xn);}#u=()=>{this.#o.emit("accountsChanged",[]);};async#h(s,h){let p=BigInt(1),a=async(g,v)=>await Qe({params:g,ethSigner:this.#r,guardianClient:this.#e,rpcProvider:this.#t,relayerClient:this.#i,zkEvmAddress:s,flow:v,nonceSpace:p,isBackgroundTransaction:!0});this.#f.emit("accountsRequested",{environment:this.#s.environment,sendTransaction:a,walletAddress:s,passportClient:h||"wallet"});}async#n(){try{let s=await this.#a.getUser();return s&&fe(s)?s.zkEvm.ethAddress:void 0}catch{return}}async#c(s){switch(s.method){case"eth_requestAccounts":{let h=await this.#n();if(h)return [h];let p=trackFlow("passport","ethRequestAccounts");try{let a=await this.#a.getUserOrLogin();p.addEvent("endGetUserOrLogin");let g;return fe(a)?g=a.zkEvm.ethAddress:(p.addEvent("startUserRegistration"),g=await ln({ethSigner:this.#r,authManager:this.#a,multiRollupApiClients:this.#l,accessToken:a.accessToken,rpcProvider:this.#t,flow:p}),p.addEvent("endUserRegistration")),this.#o.emit("accountsChanged",[g]),identify({passportId:a.profile.sub}),this.#h(g),[g]}catch(a){throw a instanceof Error?trackError("passport","ethRequestAccounts",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_sendTransaction":{let h=await this.#n();if(!h)throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=trackFlow("passport","ethSendTransaction");try{return await this.#e.withConfirmationScreen({width:480,height:720})(async()=>await Qe({params:s.params||[],ethSigner:this.#r,guardianClient:this.#e,rpcProvider:this.#t,relayerClient:this.#i,zkEvmAddress:h,flow:p}))}catch(a){throw a instanceof Error?trackError("passport","eth_sendTransaction",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_accounts":{let h=await this.#n();return h?[h]:[]}case"personal_sign":{let h=await this.#n();if(!h)throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=trackFlow("passport","personalSign");try{return await this.#e.withConfirmationScreen({width:480,height:720})(async()=>this.#s.forceScwDeployBeforeMessageSignature&&!(await Nt(this.#t,h)>BigInt(0))?await Cn({params:s.params||[],zkEvmAddress:h,ethSigner:this.#r,rpcProvider:this.#t,guardianClient:this.#e,relayerClient:this.#i,flow:p}):await se({params:s.params||[],zkEvmAddress:h,ethSigner:this.#r,rpcProvider:this.#t,guardianClient:this.#e,relayerClient:this.#i,flow:p}))}catch(a){throw a instanceof Error?trackError("passport","personal_sign",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_signTypedData":case"eth_signTypedData_v4":{if(!await this.#n())throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=trackFlow("passport","ethSignTypedDataV4");try{return await this.#e.withConfirmationScreen({width:480,height:720})(async()=>await mn({method:s.method,params:s.params||[],ethSigner:this.#r,rpcProvider:this.#t,relayerClient:this.#i,guardianClient:this.#e,flow:p}))}catch(a){throw a instanceof Error?trackError("passport","eth_signTypedData",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"eth_chainId":{let{chainId:h}=await this.#t.getNetwork();return toBeHex(h)}case"eth_getBalance":case"eth_getCode":case"eth_getTransactionCount":{let[h,p]=s.params||[];return this.#t.send(s.method,[h,p||"latest"])}case"eth_getStorageAt":{let[h,p,a]=s.params||[];return this.#t.send(s.method,[h,p,a||"latest"])}case"eth_call":case"eth_estimateGas":{let[h,p]=s.params||[];return this.#t.send(s.method,[h,p||"latest"])}case"eth_gasPrice":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":return this.#t.send(s.method,s.params||[]);case"im_signEjectionTransaction":{let h=await this.#n();if(!h)throw new R(4100,"Unauthorised - call eth_requestAccounts first");let p=trackFlow("passport","imSignEjectionTransaction");try{return await bn({params:s.params||[],ethSigner:this.#r,zkEvmAddress:h,flow:p})}catch(a){throw a instanceof Error?trackError("passport","imSignEjectionTransaction",a,{flowId:p.details.flowId}):p.addEvent("errored"),a}finally{p.addEvent("End");}}case"im_addSessionActivity":{let[h]=s.params||[],p=await this.#n();return p&&this.#h(p,h),null}default:throw new R(4200,"Method not supported")}}async request(s){try{return this.#c(s)}catch(h){throw h instanceof R?h:h instanceof Error?new R(-32603,h.message):new R(-32603,"Internal error")}}on(s,h){this.#o.on(s,h);}removeListener(s,h){this.#o.removeListener(s,h);}};var ir=class{environment;passportDomain;zkEvmRpcUrl;relayerUrl;indexerMrBasePath;jsonRpcReferrer;forceScwDeployBeforeMessageSignature;crossSdkBridgeEnabled;constructor(s){if(this.environment=s.baseConfig.environment,this.jsonRpcReferrer=s.jsonRpcReferrer,this.forceScwDeployBeforeMessageSignature=s.forceScwDeployBeforeMessageSignature||!1,this.crossSdkBridgeEnabled=s.crossSdkBridgeEnabled||!1,s.overrides)this.passportDomain=s.overrides.passportDomain,this.zkEvmRpcUrl=s.overrides.zkEvmRpcUrl,this.relayerUrl=s.overrides.relayerUrl,this.indexerMrBasePath=s.overrides.indexerMrBasePath;else switch(s.baseConfig.environment){case Environment.PRODUCTION:this.passportDomain="https://passport.immutable.com",this.zkEvmRpcUrl="https://rpc.immutable.com",this.relayerUrl="https://api.immutable.com/relayer-mr",this.indexerMrBasePath="https://api.immutable.com";break;case Environment.SANDBOX:this.passportDomain="https://passport.sandbox.immutable.com",this.zkEvmRpcUrl="https://rpc.testnet.immutable.com",this.relayerUrl="https://api.sandbox.immutable.com/relayer-mr",this.indexerMrBasePath="https://api.sandbox.immutable.com";break;default:throw new Error(`Unsupported environment: ${s.baseConfig.environment}`)}}};var ar=async(n,s,h=!0,p=!0)=>{let a=trackFlow("passport",s,h);try{return await n(a)}catch(g){throw g instanceof Error?trackError("passport",s,g,{flowId:a.details.flowId}):a.addEvent("errored"),g}finally{p&&a.addEvent("End");}};var Pn="ETH",le=class n extends AbstractSigner{authManager;magicTeeApiClient;userWallet=null;createWalletPromise=null;constructor(s,h){super(),this.authManager=s,this.magicTeeApiClient=h;}async getUserWallet(){let{userWallet:s}=this;s||(s=await this.createWallet());let h=await this.getUserOrThrow();if(h.profile.sub!==s.userIdentifier&&(s=await this.createWallet(h)),isUserImx(h)&&h.imx.userAdminAddress.toLowerCase()!==s.walletAddress.toLowerCase())throw new vt(`Wallet address mismatch.Rollup: IMX, TEE address: ${s.walletAddress}, profile address: ${h.imx.userAdminAddress}`,"WALLET_CONNECTION_ERROR");if(isUserZkEvm(h)&&h.zkEvm.userAdminAddress.toLowerCase()!==s.walletAddress.toLowerCase())throw new vt(`Wallet address mismatch.Rollup: zkEVM, TEE address: ${s.walletAddress}, profile address: ${h.zkEvm.userAdminAddress}`,"WALLET_CONNECTION_ERROR");return s}async createWallet(s){return this.createWalletPromise?this.createWalletPromise:(this.createWalletPromise=new Promise(async(h,p)=>{try{this.userWallet=null;let a=s||await this.getUserOrThrow(),g=n.getHeaders(a);await ar(async v=>{try{let y=performance.now(),A=await this.magicTeeApiClient.walletApi.createWalletV1WalletPost({xMagicChain:Pn},{headers:g});return trackDuration("passport",v.details.flowName,Math.round(performance.now()-y)),this.userWallet={userIdentifier:a.profile.sub,walletAddress:A.data.public_address},h(this.userWallet)}catch(y){let A="MagicTEE: Failed to initialise EOA";return isAxiosError(y)?y.response?A+=` with status ${y.response.status}: ${JSON.stringify(y.response.data)}`:A+=`: ${y.message}`:A+=`: ${y.message}`,p(new Error(A))}},"magicCreateWallet");}catch(a){p(a);}finally{this.createWalletPromise=null;}}),this.createWalletPromise)}async getUserOrThrow(){let s=await this.authManager.getUser();if(!s)throw new vt("User has been logged out","NOT_LOGGED_IN_ERROR");return s}static getHeaders(s){if(!s)throw new vt("User has been logged out","NOT_LOGGED_IN_ERROR");return {Authorization:`Bearer ${s.idToken}`}}async getAddress(){return (await this.getUserWallet()).walletAddress}async signMessage(s){await this.getUserWallet();let h=s instanceof Uint8Array?`0x${Buffer.from(s).toString("hex")}`:s,p=await this.getUserOrThrow(),a=await n.getHeaders(p);return ar(async g=>{try{let v=performance.now(),y=await this.magicTeeApiClient.signOperationsApi.signMessageV1WalletSignMessagePost({signMessageRequest:{message_base64:Buffer.from(h,"utf-8").toString("base64")},xMagicChain:Pn},{headers:a});return trackDuration("passport",g.details.flowName,Math.round(performance.now()-v)),y.data.signature}catch(v){let y="MagicTEE: Failed to sign message using EOA";throw isAxiosError(v)?v.response?y+=` with status ${v.response.status}: ${JSON.stringify(v.response.data)}`:y+=`: ${v.message}`:y+=`: ${v.message}`,new Error(y)}},"magicSignMessage")}connect(){throw new Error("Method not implemented.")}signTransaction(){throw new Error("Method not implemented.")}signTypedData(){throw new Error("Method not implemented.")}};var ya={icon:'data:image/svg+xml,<svg viewBox="0 0 48 48" class="SvgIcon undefined Logo Logo--PassportSymbolOutlined css-1dn9atd" xmlns="http://www.w3.org/2000/svg"><g data-testid="undefined__g"><circle cx="24" cy="24" r="22.5" fill="url(%23paint0_radial_6324_83922)"></circle><circle cx="24" cy="24" r="22.5" fill="url(%23paint1_radial_6324_83922)"></circle><path d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM23.0718 9.16608C23.7383 8.83951 24.4406 8.86188 25.087 9.2287C27.3282 10.5059 29.5627 11.7942 31.786 13.096C32.5018 13.5165 32.8686 14.1897 32.8708 15.0173C32.8843 17.9184 32.8798 20.8171 32.8708 23.7182C32.8708 23.8255 32.8015 23.9821 32.7143 24.0335C31.8531 24.548 30.9808 25.0423 30.0347 25.5881V25.1318C30.0347 22.148 30.0257 19.1664 30.0414 16.1827C30.0436 15.6101 29.8468 15.241 29.339 14.9525C26.7377 13.474 24.1499 11.9687 21.5575 10.4723C21.4457 10.4075 21.3361 10.3381 21.1661 10.2352C21.8326 9.85722 22.4321 9.47698 23.0673 9.16608H23.0718ZM22.5953 38.8451C22.45 38.7713 22.3426 38.7198 22.2375 38.6595C18.8041 36.68 15.3752 34.687 11.9307 32.7232C10.9644 32.173 10.5238 31.3879 10.5349 30.2852C10.5551 27.9411 10.5484 25.597 10.5372 23.2507C10.5327 22.1927 10.9622 21.4255 11.8926 20.8977C14.3105 19.5221 16.715 18.1264 19.1195 16.7284C19.3275 16.6076 19.4796 16.5875 19.6965 16.7172C20.5264 17.216 21.3719 17.6924 22.2554 18.2024C22.0876 18.3031 21.9601 18.3791 21.8304 18.4552C19.2268 19.9582 16.6278 21.4658 14.0175 22.9599C13.5903 23.2037 13.3912 23.5213 13.3957 24.0179C13.4091 25.8654 13.4114 27.713 13.3957 29.5605C13.3912 30.0705 13.5948 30.3948 14.0332 30.6453C16.7866 32.2199 19.5288 33.8125 22.28 35.3916C22.5126 35.5258 22.611 35.6645 22.6065 35.9418C22.5864 36.888 22.5998 37.8363 22.5998 38.8473L22.5953 38.8451ZM22.5953 33.553C22.356 33.4166 22.1838 33.3204 22.0116 33.2198C19.8285 31.9605 17.6477 30.6967 15.4602 29.4464C15.2231 29.3122 15.1359 29.1668 15.1381 28.8917C15.1538 27.4714 15.1471 26.0511 15.1426 24.6308C15.1426 24.4384 15.1717 24.3064 15.3618 24.1991C16.167 23.7495 16.9633 23.2798 17.7618 22.8212C17.8199 22.7877 17.8826 22.7631 17.9877 22.7116V24.3064C17.9877 25.1698 18.0011 26.0354 17.9832 26.8988C17.972 27.3909 18.1622 27.7241 18.5916 27.9657C19.8285 28.6636 21.0498 29.3883 22.2867 30.0839C22.5305 30.2203 22.6043 30.3724 22.5998 30.6408C22.5842 31.5847 22.5931 32.5308 22.5931 33.5508L22.5953 33.553ZM20.0746 14.91C19.6116 14.6371 19.2157 14.6393 18.7527 14.91C16.1581 16.4265 13.5523 17.9228 10.9487 19.4259C10.8391 19.4908 10.7251 19.5489 10.5305 19.6541C10.5998 18.6654 10.3873 17.7327 10.7251 16.8291C10.9085 16.3348 11.2529 15.9635 11.7092 15.6995C13.8811 14.4447 16.0507 13.1877 18.227 11.9396C19.0211 11.4833 19.8308 11.4945 20.6248 11.953C23.0964 13.3756 25.5657 14.8026 28.0306 16.2341C28.1357 16.2945 28.2677 16.4309 28.2677 16.5338C28.2856 17.5493 28.2788 18.567 28.2788 19.6563C27.3819 19.1396 26.5543 18.6609 25.7267 18.1823C23.8412 17.093 21.9512 16.0149 20.0746 14.91ZM37.4427 30.8779C37.3778 31.6764 36.9103 32.2423 36.2192 32.6404C33.5732 34.1614 30.9294 35.6913 28.2856 37.2168C27.4557 37.6954 26.6259 38.1741 25.7938 38.6527C25.6932 38.7109 25.5903 38.7601 25.4539 38.8317C25.4449 38.693 25.4337 38.5924 25.4337 38.4917C25.4337 37.6149 25.4382 36.7404 25.4293 35.8636C25.4293 35.6645 25.4762 35.5437 25.6596 35.4386C29.5157 33.2198 33.3696 30.9942 37.2212 28.7709C37.2794 28.7374 37.3443 28.7105 37.4539 28.6591C37.4539 29.4375 37.4986 30.1622 37.4427 30.8779ZM37.4628 25.3577C37.4561 26.2658 36.9663 26.9033 36.1901 27.3506C33.175 29.0841 30.1622 30.8265 27.1493 32.5666C26.5991 32.8842 26.0466 33.1996 25.4561 33.5396C25.4472 33.3897 25.436 33.2913 25.436 33.1907C25.436 32.3273 25.4449 31.4617 25.4293 30.5983C25.4248 30.3523 25.5075 30.2226 25.72 30.0995C28.46 28.5271 31.1911 26.9368 33.9355 25.3733C34.4231 25.096 34.6378 24.7538 34.6334 24.1812C34.6132 21.1974 34.6244 18.2136 34.6244 15.2298V14.7087C35.3402 15.1404 36.0112 15.496 36.624 15.9299C37.1832 16.3258 37.465 16.9253 37.4673 17.6164C37.4762 20.1976 37.4829 22.7788 37.465 25.3599L37.4628 25.3577Z" fill="%230D0D0D"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint2_radial_6324_83922)"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint3_radial_6324_83922)"></path><defs><radialGradient id="paint0_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(13.4442 13.3899) rotate(44.9817) scale(46.7487 99.1435)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint1_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(25.9515 43.7068) rotate(84.265) scale(24.2138 46.3215)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient><radialGradient id="paint2_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(12.7405 12.6825) rotate(44.9817) scale(49.8653 105.753)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint3_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26.0816 45.0206) rotate(84.265) scale(25.828 49.4096)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient></defs></g></svg>',name:"Immutable Passport",rdns:"com.immutable.passport",uuid:v4()};function wa(n){if(typeof window>"u")return;let s=new CustomEvent("eip6963:announceProvider",{detail:Object.freeze(n)});window.dispatchEvent(s);let h=()=>window.dispatchEvent(s);window.addEventListener("eip6963:requestProvider",h);}
21
+
22
+ export { ne as GuardianClient, R as JsonRpcError, le as MagicTEESigner, Sr as PassportEvents, $t as ProviderErrorCode, qn as ProviderEvent, Dt as RelayerClient, Hn as RelayerTransactionStatus, Tt as RpcErrorCode, It as TypedEventEmitter, ir as WalletConfiguration, vt as WalletError, te as WalletErrorType, nr as ZkEvmProvider, wa as announceProvider, ya as passportProviderInfo, Pt as retryWithDelay, Gr as walletHelpers };
@@ -0,0 +1,13 @@
1
+ import { Environment } from '@imtbl/config';
2
+ import { WalletModuleConfiguration } from './types';
3
+ export declare class WalletConfiguration {
4
+ readonly environment: Environment;
5
+ readonly passportDomain: string;
6
+ readonly zkEvmRpcUrl: string;
7
+ readonly relayerUrl: string;
8
+ readonly indexerMrBasePath: string;
9
+ readonly jsonRpcReferrer?: string;
10
+ readonly forceScwDeployBeforeMessageSignature: boolean;
11
+ readonly crossSdkBridgeEnabled: boolean;
12
+ constructor(config: WalletModuleConfiguration);
13
+ }
@@ -0,0 +1,14 @@
1
+ export declare enum WalletErrorType {
2
+ WALLET_CONNECTION_ERROR = "WALLET_CONNECTION_ERROR",
3
+ TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
4
+ INVALID_CONFIGURATION = "INVALID_CONFIGURATION",
5
+ UNAUTHORIZED = "UNAUTHORIZED",
6
+ GUARDIAN_ERROR = "GUARDIAN_ERROR",
7
+ SERVICE_UNAVAILABLE_ERROR = "SERVICE_UNAVAILABLE_ERROR",
8
+ NOT_LOGGED_IN_ERROR = "NOT_LOGGED_IN_ERROR"
9
+ }
10
+ export declare class WalletError extends Error {
11
+ readonly type: WalletErrorType;
12
+ constructor(message: string, type: WalletErrorType);
13
+ }
14
+ export declare function withWalletError<T>(fn: () => Promise<T>, defaultErrorType: WalletErrorType): Promise<T>;
@@ -0,0 +1,57 @@
1
+ import * as GeneratedClients from '@imtbl/generated-clients';
2
+ import { BigNumberish } from 'ethers';
3
+ import { AuthManager, ConfirmationScreen } from '@imtbl/auth';
4
+ import { MetaTransaction, TypedDataPayload } from '../zkEvm/types';
5
+ import { WalletConfiguration } from '../config';
6
+ export type GuardianClientParams = {
7
+ confirmationScreen: ConfirmationScreen;
8
+ config: WalletConfiguration;
9
+ authManager: AuthManager;
10
+ guardianApi: GeneratedClients.mr.GuardianApi;
11
+ };
12
+ export type GuardianEvaluateImxTransactionParams = {
13
+ payloadHash: string;
14
+ };
15
+ type GuardianEVMTxnEvaluationParams = {
16
+ chainId: string;
17
+ nonce: string;
18
+ metaTransactions: MetaTransaction[];
19
+ isBackgroundTransaction?: boolean;
20
+ };
21
+ type GuardianEIP712MessageEvaluationParams = {
22
+ chainID: string;
23
+ payload: TypedDataPayload;
24
+ };
25
+ type GuardianERC191MessageEvaluationParams = {
26
+ chainID: bigint;
27
+ payload: string;
28
+ };
29
+ export declare const convertBigNumberishToString: (value: BigNumberish) => string;
30
+ export default class GuardianClient {
31
+ private readonly guardianApi;
32
+ private readonly confirmationScreen;
33
+ private readonly crossSdkBridgeEnabled;
34
+ private readonly authManager;
35
+ constructor({ confirmationScreen, config, authManager, guardianApi, }: GuardianClientParams);
36
+ /**
37
+ * Open confirmation screen and close it automatically if the
38
+ * underlying task fails.
39
+ */
40
+ withConfirmationScreen(popupWindowSize?: {
41
+ width: number;
42
+ height: number;
43
+ }): <T>(task: () => Promise<T>) => Promise<T>;
44
+ withConfirmationScreenTask(popupWindowSize?: {
45
+ width: number;
46
+ height: number;
47
+ }): <T>(task: () => Promise<T>) => (() => Promise<T>);
48
+ withDefaultConfirmationScreenTask<T>(task: () => Promise<T>): (() => Promise<T>);
49
+ evaluateImxTransaction({ payloadHash }: GuardianEvaluateImxTransactionParams): Promise<void>;
50
+ private evaluateEVMTransaction;
51
+ validateEVMTransaction({ chainId, nonce, metaTransactions, isBackgroundTransaction, }: GuardianEVMTxnEvaluationParams): Promise<void>;
52
+ private handleEIP712MessageEvaluation;
53
+ evaluateEIP712Message({ chainID, payload }: GuardianEIP712MessageEvaluationParams): Promise<void>;
54
+ private handleERC191MessageEvaluation;
55
+ evaluateERC191Message({ chainID, payload }: GuardianERC191MessageEvaluationParams): Promise<void>;
56
+ }
57
+ export {};