@clerk/clerk-js
Version:
Clerk JS library
1 lines • 111 kB
JavaScript
(globalThis.webpackChunk_clerk_clerk_js=globalThis.webpackChunk_clerk_clerk_js||[]).push([["956"],{93468:function(e,t,n){"use strict";function s(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)}function r(e){for(var t=arguments.length,n=Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];if(!(e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name))throw Error("Uint8Array expected");if(n.length>0&&!n.includes(e.length))throw Error("Uint8Array expected of length "+n+", got length="+e.length)}n(92037),n(73588),n(75184),n(12100),n(29646),n(67581),n(63782),n(14311),n(72547),n(86936),n(20889),n(54357),n(86775),n(6763),n(28419),Object.defineProperty(t,"__esModule",{value:!0}),t.anumber=s,t.abytes=r,t.ahash=function(e){if("function"!=typeof e||"function"!=typeof e.create)throw Error("Hash should be wrapped by utils.wrapConstructor");s(e.outputLen),s(e.blockLen)},t.aexists=function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(e.destroyed)throw Error("Hash instance has been destroyed");if(t&&e.finished)throw Error("Hash#digest() has already been called")},t.aoutput=function(e,t){r(e);let n=t.outputLen;if(e.length<n)throw Error("digestInto() expects output buffer of length at least "+n)}},1547:function(e,t,n){"use strict";n(56113),n(12745),n(75184),n(12100),n(29646),n(67581),n(63782),n(14311),n(72547),n(86936),n(20889),n(54357),n(86775),n(6763),n(65223),Object.defineProperty(t,"__esModule",{value:!0}),t.add5L=t.add5H=t.add4H=t.add4L=t.add3H=t.add3L=t.rotlBL=t.rotlBH=t.rotlSL=t.rotlSH=t.rotr32L=t.rotr32H=t.rotrBL=t.rotrBH=t.rotrSL=t.rotrSH=t.shrSL=t.shrSH=t.toBig=void 0,t.fromBig=i,t.split=a,t.add=w;let s=BigInt(0x100000000-1),r=BigInt(32);function i(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return t?{h:Number(e&s),l:Number(e>>r&s)}:{h:0|Number(e>>r&s),l:0|Number(e&s)}}function a(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=new Uint32Array(e.length),s=new Uint32Array(e.length);for(let r=0;r<e.length;r++){let{h:a,l:o}=i(e[r],t);[n[r],s[r]]=[a,o]}return[n,s]}let o=(e,t)=>BigInt(e>>>0)<<r|BigInt(t>>>0);t.toBig=o;let c=(e,t,n)=>e>>>n;t.shrSH=c;let l=(e,t,n)=>e<<32-n|t>>>n;t.shrSL=l;let h=(e,t,n)=>e>>>n|t<<32-n;t.rotrSH=h;let u=(e,t,n)=>e<<32-n|t>>>n;t.rotrSL=u;let d=(e,t,n)=>e<<64-n|t>>>n-32;t.rotrBH=d;let f=(e,t,n)=>e>>>n-32|t<<64-n;t.rotrBL=f;let p=(e,t)=>t;t.rotr32H=p;let g=(e,t)=>e;t.rotr32L=g;let m=(e,t,n)=>e<<n|t>>>32-n;t.rotlSH=m;let y=(e,t,n)=>t<<n|e>>>32-n;t.rotlSL=y;let _=(e,t,n)=>t<<n-32|e>>>64-n;t.rotlBH=_;let b=(e,t,n)=>e<<n-32|t>>>64-n;function w(e,t,n,s){let r=(t>>>0)+(s>>>0);return{h:e+n+(r/0x100000000|0)|0,l:0|r}}t.rotlBL=b;let v=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0);t.add3L=v;let k=(e,t,n,s)=>t+n+s+(e/0x100000000|0)|0;t.add3H=k;let x=(e,t,n,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0);t.add4L=x;let C=(e,t,n,s,r)=>t+n+s+r+(e/0x100000000|0)|0;t.add4H=C;let E=(e,t,n,s,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0)+(r>>>0);t.add5L=E;let I=(e,t,n,s,r,i)=>t+n+s+r+i+(e/0x100000000|0)|0;t.add5H=I,t.default={fromBig:i,split:a,toBig:o,shrSH:c,shrSL:l,rotrSH:h,rotrSL:u,rotrBH:d,rotrBL:f,rotr32H:p,rotr32L:g,rotlSH:m,rotlSL:y,rotlBH:_,rotlBL:b,add:w,add3L:v,add3H:k,add4L:x,add4H:C,add5H:I,add5L:E}},10221:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.crypto=void 0,t.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0},88145:function(e,t,n){"use strict";n(65223),n(79876),n(56113),n(12745),n(75184),n(12100),n(29646),n(67581),n(63782),n(14311),n(72547),n(86936),n(20889),n(54357),n(86775),n(6763),n(92037),n(73588),Object.defineProperty(t,"__esModule",{value:!0}),t.shake256=t.shake128=t.keccak_512=t.keccak_384=t.keccak_256=t.keccak_224=t.sha3_512=t.sha3_384=t.sha3_256=t.sha3_224=t.Keccak=void 0,t.keccakP=b;let s=n(93468),r=n(1547),i=n(94865),a=[],o=[],c=[],l=BigInt(0),h=BigInt(1),u=BigInt(2),d=BigInt(7),f=BigInt(256),p=BigInt(113);for(let e=0,t=h,n=1,s=0;e<24;e++){[n,s]=[s,(2*n+3*s)%5],a.push(2*(5*s+n)),o.push((e+1)*(e+2)/2%64);let r=l;for(let e=0;e<7;e++)(t=(t<<h^(t>>d)*p)%f)&u&&(r^=h<<(h<<BigInt(e))-h);c.push(r)}let[g,m]=(0,r.split)(c,!0),y=(e,t,n)=>n>32?(0,r.rotlBH)(e,t,n):(0,r.rotlSH)(e,t,n),_=(e,t,n)=>n>32?(0,r.rotlBL)(e,t,n):(0,r.rotlSL)(e,t,n);function b(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:24,n=new Uint32Array(10);for(let s=24-t;s<24;s++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let s=(t+8)%10,r=(t+2)%10,i=n[r],a=n[r+1],o=y(i,a,1)^n[s],c=_(i,a,1)^n[s+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=c}let t=e[2],r=e[3];for(let n=0;n<24;n++){let s=o[n],i=y(t,r,s),c=_(t,r,s),l=a[n];t=e[l],r=e[l+1],e[l]=i,e[l+1]=c}for(let t=0;t<50;t+=10){for(let s=0;s<10;s++)n[s]=e[t+s];for(let s=0;s<10;s++)e[t+s]^=~n[(s+2)%10]&n[(s+4)%10]}e[0]^=g[s],e[1]^=m[s]}n.fill(0)}class w extends i.Hash{keccak(){i.isLE||(0,i.byteSwap32)(this.state32),b(this.state32,this.rounds),i.isLE||(0,i.byteSwap32)(this.state32),this.posOut=0,this.pos=0}update(e){(0,s.aexists)(this);let{blockLen:t,state:n}=this,r=(e=(0,i.toBytes)(e)).length;for(let s=0;s<r;){let i=Math.min(t-this.pos,r-s);for(let t=0;t<i;t++)n[this.pos++]^=e[s++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:s}=this;e[n]^=t,(128&t)!=0&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){(0,s.aexists)(this,!1),(0,s.abytes)(e),this.finish();let t=this.state,{blockLen:n}=this;for(let s=0,r=e.length;s<r;){this.posOut>=n&&this.keccak();let i=Math.min(n-this.posOut,r-s);e.set(t.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return e}xofInto(e){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,s.anumber)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,s.aoutput)(e,this),this.finished)throw Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:s,rounds:r,enableXOF:i}=this;return e||(e=new w(t,n,s,i,r)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=r,e.suffix=n,e.outputLen=s,e.enableXOF=i,e.destroyed=this.destroyed,e}constructor(e,t,n,r=!1,a=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=a,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,(0,s.anumber)(n),0>=this.blockLen||this.blockLen>=200)throw Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=(0,i.u32)(this.state)}}t.Keccak=w;let v=(e,t,n)=>(0,i.wrapConstructor)(()=>new w(t,e,n));t.sha3_224=v(6,144,28),t.sha3_256=v(6,136,32),t.sha3_384=v(6,104,48),t.sha3_512=v(6,72,64),t.keccak_224=v(1,144,28),t.keccak_256=v(1,136,32),t.keccak_384=v(1,104,48),t.keccak_512=v(1,72,64);let k=(e,t,n)=>(0,i.wrapXOFConstructorWithOpts)(function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new w(t,e,void 0===s.dkLen?n:s.dkLen,!0)});t.shake128=k(31,168,16),t.shake256=k(31,136,32)},94865:function(e,t,n){"use strict";n(73588),n(75184),n(12100),n(29646),n(67581),n(63782),n(14311),n(72547),n(86936),n(20889),n(54357),n(86775),n(6763),n(12745),n(92037),n(50725),Object.defineProperty(t,"__esModule",{value:!0}),t.Hash=t.nextTick=t.byteSwapIfBE=t.isLE=void 0,t.isBytes=function(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name},t.u8=function(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},t.u32=function(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))},t.createView=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},t.rotr=function(e,t){return e<<32-t|e>>>t},t.rotl=function(e,t){return e<<t|e>>>32-t>>>0},t.byteSwap=i,t.byteSwap32=function(e){for(let t=0;t<e.length;t++)e[t]=i(e[t])},t.bytesToHex=function(e){(0,r.abytes)(e);let t="";for(let n=0;n<e.length;n++)t+=a[e[n]];return t},t.hexToBytes=function(e){if("string"!=typeof e)throw Error("hex string expected, got "+typeof e);let t=e.length,n=t/2;if(t%2)throw Error("hex string expected, got unpadded hex of length "+t);let s=new Uint8Array(n);for(let t=0,r=0;t<n;t++,r+=2){let n=o(e.charCodeAt(r)),i=o(e.charCodeAt(r+1));if(void 0===n||void 0===i)throw Error('hex string expected, got non-hex character "'+(e[r]+e[r+1])+'" at index '+r);s[t]=16*n+i}return s},t.asyncLoop=c,t.utf8ToBytes=l,t.toBytes=h,t.concatBytes=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];let s=0;for(let e=0;e<t.length;e++){let n=t[e];(0,r.abytes)(n),s+=n.length}let i=new Uint8Array(s);for(let e=0,n=0;e<t.length;e++){let s=t[e];i.set(s,n),n+=s.length}return i},t.checkOpts=function(e,t){if(void 0!==t&&"[object Object]"!==({}).toString.call(t))throw Error("Options should be object or undefined");return Object.assign(e,t)},t.wrapConstructor=function(e){let t=t=>e().update(h(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t},t.wrapConstructorWithOpts=function(e){let t=(t,n)=>e(n).update(h(t)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t},t.wrapXOFConstructorWithOpts=function(e){let t=(t,n)=>e(n).update(h(t)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t},t.randomBytes=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32;if(s.crypto&&"function"==typeof s.crypto.getRandomValues)return s.crypto.getRandomValues(new Uint8Array(e));if(s.crypto&&"function"==typeof s.crypto.randomBytes)return s.crypto.randomBytes(e);throw Error("crypto.getRandomValues must be defined")};let s=n(10221),r=n(93468);function i(e){return e<<24&0xff000000|e<<8&0xff0000|e>>>8&65280|e>>>24&255}t.isLE=68===new Uint8Array(new Uint32Array([0x11223344]).buffer)[0],t.byteSwapIfBE=t.isLE?e=>e:e=>i(e);let a=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function o(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}async function c(e,n,s){let r=Date.now();for(let i=0;i<e;i++){s(i);let e=Date.now()-r;e>=0&&e<n||(await (0,t.nextTick)(),r+=e)}}function l(e){if("string"!=typeof e)throw Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function h(e){return"string"==typeof e&&(e=l(e)),(0,r.abytes)(e),e}t.nextTick=async()=>{},t.Hash=class{clone(){return this._cloneInto()}}},92825:function(e,t,n){"use strict";n(92037),n(79876);var s=Object.prototype.hasOwnProperty,r="~";function i(){}function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,s,i){if("function"!=typeof n)throw TypeError("The listener must be a function");var o=new a(n,s||e,i),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],o]:e._events[c].push(o):(e._events[c]=o,e._eventsCount++),e}function c(e,t){0==--e._eventsCount?e._events=new i:delete e._events[t]}function l(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1)),l.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)s.call(e,t)&&n.push(r?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},l.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,a=Array(i);s<i;s++)a[s]=n[s].fn;return a},l.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},l.prototype.emit=function(e,t,n,s,i,a){var o=r?r+e:e;if(!this._events[o])return!1;var c,l,h=this._events[o],u=arguments.length;if(h.fn){switch(h.once&&this.removeListener(e,h.fn,void 0,!0),u){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,t),!0;case 3:return h.fn.call(h.context,t,n),!0;case 4:return h.fn.call(h.context,t,n,s),!0;case 5:return h.fn.call(h.context,t,n,s,i),!0;case 6:return h.fn.call(h.context,t,n,s,i,a),!0}for(l=1,c=Array(u-1);l<u;l++)c[l-1]=arguments[l];h.fn.apply(h.context,c)}else{var d,f=h.length;for(l=0;l<f;l++)switch(h[l].once&&this.removeListener(e,h[l].fn,void 0,!0),u){case 1:h[l].fn.call(h[l].context);break;case 2:h[l].fn.call(h[l].context,t);break;case 3:h[l].fn.call(h[l].context,t,n);break;case 4:h[l].fn.call(h[l].context,t,n,s);break;default:if(!c)for(d=1,c=Array(u-1);d<u;d++)c[d-1]=arguments[d];h[l].fn.apply(h[l].context,c)}}return!0},l.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},l.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},l.prototype.removeListener=function(e,t,n,s){var i=r?r+e:e;if(!this._events[i])return this;if(!t)return c(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||s&&!a.once||n&&a.context!==n||c(this,i);else{for(var o=0,l=[],h=a.length;o<h;o++)(a[o].fn!==t||s&&!a[o].once||n&&a[o].context!==n)&&l.push(a[o]);l.length?this._events[i]=1===l.length?l[0]:l:c(this,i)}return this},l.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&c(this,t)):(this._events=new i,this._eventsCount=0),this},l.prototype.off=l.prototype.removeListener,l.prototype.addListener=l.prototype.on,l.prefixed=r,l.EventEmitter=l,e.exports=l},73170:function(e,t,n){let s=n(88689);function r(e){if(e.startsWith("int["))return"int256"+e.slice(3);if("int"===e)return"int256";if(e.startsWith("uint["))return"uint256"+e.slice(4);if("uint"===e)return"uint256";if(e.startsWith("fixed["))return"fixed128x128"+e.slice(5);else if("fixed"===e)return"fixed128x128";else if(e.startsWith("ufixed["))return"ufixed128x128"+e.slice(6);else if("ufixed"===e)return"ufixed128x128";return e}function i(e){return Number.parseInt(/^\D+(\d+)$/.exec(e)[1],10)}function a(e){var t=/^\D+(\d+)x(\d+)$/.exec(e);return[Number.parseInt(t[1],10),Number.parseInt(t[2],10)]}function o(e){var t=e.match(/(.*)\[(.*?)\]$/);return t?""===t[2]?"dynamic":Number.parseInt(t[2],10):null}function c(e){var t=typeof e;if("string"===t||"number"===t)return BigInt(e);if("bigint"===t)return e;throw Error("Argument is not a number")}function l(e,t){if("address"===e)return l("uint160",c(t));if("bool"===e)return l("uint8",+!!t);if("string"===e)return l("bytes",new Buffer(t,"utf8"));if((d=e).lastIndexOf("]")===d.length-1){if(void 0===t.length)throw Error("Not an array?");if("dynamic"!==(n=o(e))&&0!==n&&t.length>n)throw Error("Elements exceed array size: "+n);for(u in h=[],e=e.slice(0,e.lastIndexOf("[")),"string"==typeof t&&(t=JSON.parse(t)),t)h.push(l(e,t[u]));if("dynamic"===n){var n,r,h,u,d,f=l("uint256",t.length);h.unshift(f)}return Buffer.concat(h)}else if("bytes"===e)return t=new Buffer(t),h=Buffer.concat([l("uint256",t.length),t]),t.length%32!=0&&(h=Buffer.concat([h,s.zeros(32-t.length%32)])),h;else if(e.startsWith("bytes")){if((n=i(e))<1||n>32)throw Error("Invalid bytes<N> width: "+n);return s.setLengthRight(t,32)}else if(e.startsWith("uint")){if((n=i(e))%8||n<8||n>256)throw Error("Invalid uint<N> width: "+n);r=c(t);let a=s.bitLengthFromBigInt(r);if(a>n)throw Error("Supplied uint exceeds width: "+n+" vs "+a);if(r<0)throw Error("Supplied uint is negative");return s.bufferBEFromBigInt(r,32)}else if(e.startsWith("int")){if((n=i(e))%8||n<8||n>256)throw Error("Invalid int<N> width: "+n);r=c(t);let a=s.bitLengthFromBigInt(r);if(a>n)throw Error("Supplied int exceeds width: "+n+" vs "+a);let o=s.twosFromBigInt(r,256);return s.bufferBEFromBigInt(o,32)}else if(e.startsWith("ufixed")){if(n=a(e),(r=c(t))<0)throw Error("Supplied ufixed is negative");return l("uint256",r*BigInt(2)**BigInt(n[1]))}else if(e.startsWith("fixed"))return n=a(e),l("int256",c(t)*BigInt(2)**BigInt(n[1]));throw Error("Unsupported or invalid type: "+e)}function h(e,t){if(e.length!==t.length)throw Error("Number of types are not matching the values");for(var n,a,o=[],l=0;l<e.length;l++){var h=r(e[l]),u=t[l];if("bytes"===h)o.push(u);else if("string"===h)o.push(new Buffer(u,"utf8"));else if("bool"===h)o.push(new Buffer(u?"01":"00","hex"));else if("address"===h)o.push(s.setLength(u,20));else if(h.startsWith("bytes")){if((n=i(h))<1||n>32)throw Error("Invalid bytes<N> width: "+n);o.push(s.setLengthRight(u,n))}else if(h.startsWith("uint")){if((n=i(h))%8||n<8||n>256)throw Error("Invalid uint<N> width: "+n);a=c(u);let e=s.bitLengthFromBigInt(a);if(e>n)throw Error("Supplied uint exceeds width: "+n+" vs "+e);o.push(s.bufferBEFromBigInt(a,n/8))}else if(h.startsWith("int")){if((n=i(h))%8||n<8||n>256)throw Error("Invalid int<N> width: "+n);a=c(u);let e=s.bitLengthFromBigInt(a);if(e>n)throw Error("Supplied int exceeds width: "+n+" vs "+e);let t=s.twosFromBigInt(a,n);o.push(s.bufferBEFromBigInt(t,n/8))}else throw Error("Unsupported or invalid type: "+h)}return Buffer.concat(o)}e.exports={rawEncode:function(e,t){var n=[],s=[],i=32*e.length;for(var a in e){var c=r(e[a]),h=l(c,t[a]);"string"===c||"bytes"===c||"dynamic"===o(c)?(n.push(l("uint256",i)),s.push(h),i+=h.length):n.push(h)}return Buffer.concat(n.concat(s))},solidityPack:h,soliditySHA3:function(e,t){return s.keccak(h(e,t))}}},91050:function(e,t,n){let s=n(88689),r=n(73170),i={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]},a={encodeData(e,t,n,i=!0){let a=["bytes32"],o=[this.hashType(e,n)];if(i){let c=(e,t,a)=>{if(void 0!==n[t])return["bytes32",null==a?"0x0000000000000000000000000000000000000000000000000000000000000000":s.keccak(this.encodeData(t,a,n,i))];if(void 0===a)throw Error(`missing value for field ${e} of type ${t}`);if("bytes"===t)return["bytes32",s.keccak(a)];if("string"===t)return"string"==typeof a&&(a=Buffer.from(a,"utf8")),["bytes32",s.keccak(a)];if(t.lastIndexOf("]")===t.length-1){let n=t.slice(0,t.lastIndexOf("[")),i=a.map(t=>c(e,n,t));return["bytes32",s.keccak(r.rawEncode(i.map(([e])=>e),i.map(([,e])=>e)))]}return[t,a]};for(let s of n[e]){let[e,n]=c(s.name,s.type,t[s.name]);a.push(e),o.push(n)}}else for(let r of n[e]){let e=t[r.name];if(void 0!==e)if("bytes"===r.type)a.push("bytes32"),e=s.keccak(e),o.push(e);else if("string"===r.type)a.push("bytes32"),"string"==typeof e&&(e=Buffer.from(e,"utf8")),e=s.keccak(e),o.push(e);else if(void 0!==n[r.type])a.push("bytes32"),e=s.keccak(this.encodeData(r.type,e,n,i)),o.push(e);else if(r.type.lastIndexOf("]")===r.type.length-1)throw Error("Arrays currently unimplemented in encodeData");else a.push(r.type),o.push(e)}return r.rawEncode(a,o)},encodeType(e,t){let n="",s=this.findTypeDependencies(e,t).filter(t=>t!==e);for(let r of s=[e].concat(s.sort())){if(!t[r])throw Error("No type definition specified: "+r);n+=r+"("+t[r].map(({name:e,type:t})=>t+" "+e).join(",")+")"}return n},findTypeDependencies(e,t,n=[]){if(e=e.match(/^\w*/)[0],n.includes(e)||void 0===t[e])return n;for(let s of(n.push(e),t[e]))for(let e of this.findTypeDependencies(s.type,t,n))n.includes(e)||n.push(e);return n},hashStruct(e,t,n,r=!0){return s.keccak(this.encodeData(e,t,n,r))},hashType(e,t){return s.keccak(this.encodeType(e,t))},sanitizeData(e){let t={};for(let n in i.properties)e[n]&&(t[n]=e[n]);return t.types&&(t.types=Object.assign({EIP712Domain:[]},t.types)),t},hash(e,t=!0){let n=this.sanitizeData(e),r=[Buffer.from("1901","hex")];return r.push(this.hashStruct("EIP712Domain",n.domain,n.types,t)),"EIP712Domain"!==n.primaryType&&r.push(this.hashStruct(n.primaryType,n.message,n.types,t)),s.keccak(Buffer.concat(r))}};e.exports={TYPED_MESSAGE_SCHEMA:i,TypedDataUtils:a,hashForSignTypedDataLegacy:function(e){return function(e){let t=Error("Expect argument to be non-empty array");if("object"!=typeof e||!e.length)throw t;let n=e.map(function(e){return"bytes"===e.type?s.toBuffer(e.value):e.value}),i=e.map(function(e){return e.type}),a=e.map(function(e){if(!e.name)throw t;return e.type+" "+e.name});return r.soliditySHA3(["bytes32","bytes32"],[r.soliditySHA3(Array(e.length).fill("string"),a),r.soliditySHA3(i,n)])}(e.data)},hashForSignTypedData_v3:function(e){return a.hash(e.data,!1)},hashForSignTypedData_v4:function(e){return a.hash(e.data)}}},88689:function(e,t,n){let{keccak_256:s}=n(88145);function r(e){return Buffer.allocUnsafe(e).fill(0)}function i(e,t){let n=e.toString(16);n.length%2!=0&&(n="0"+n);let s=n.match(/.{1,2}/g).map(e=>parseInt(e,16));for(;s.length<t;)s.unshift(0);return Buffer.from(s)}function a(e,t,n){let s=r(t);return(e=o(e),n)?e.length<t?(e.copy(s),s):e.slice(0,t):e.length<t?(e.copy(s,t-e.length),s):e.slice(-t)}function o(e){if(!Buffer.isBuffer(e))if(Array.isArray(e))e=Buffer.from(e);else if("string"==typeof e){var t;e=c(e)?Buffer.from((t=l(e)).length%2?"0"+t:t,"hex"):Buffer.from(e)}else if("number"==typeof e)e=intToBuffer(e);else if(null==e)e=Buffer.allocUnsafe(0);else if("bigint"==typeof e)e=i(e);else if(e.toArray)e=Buffer.from(e.toArray());else throw Error("invalid type");return e}function c(e){return"string"==typeof e&&e.match(/^0x[0-9A-Fa-f]*$/)}function l(e){return"string"==typeof e&&e.startsWith("0x")?e.slice(2):e}e.exports={zeros:r,setLength:a,setLengthRight:function(e,t){return a(e,t,!0)},isHexString:c,stripHexPrefix:l,toBuffer:o,bufferToHex:function(e){return"0x"+(e=o(e)).toString("hex")},keccak:function(e,t){if(e=o(e),t||(t=256),256!==t)throw Error("unsupported");return Buffer.from(s(new Uint8Array(e)))},bitLengthFromBigInt:function(e){return e.toString(2).length},bufferBEFromBigInt:i,twosFromBigInt:function(e,t){return(e<0n?(~e&(1n<<BigInt(t))-1n)+1n:e)&(1n<<BigInt(t))-1n}}},77453:function(e,t,n){"use strict";let s;n.r(t),n.d(t,{CoinbaseWalletSDK:()=>t8,default:()=>t9,createCoinbaseWalletSDK:()=>t7}),n(50725),n(65223),n(79876);class r{storeObject(e,t){this.setItem(e,JSON.stringify(t))}loadObject(e){let t=this.getItem(e);return t?JSON.parse(t):void 0}setItem(e,t){localStorage.setItem(this.scopedKey(e),t)}getItem(e){return localStorage.getItem(this.scopedKey(e))}removeItem(e){localStorage.removeItem(this.scopedKey(e))}clear(){let e=this.scopedKey(""),t=[];for(let n=0;n<localStorage.length;n++){let s=localStorage.key(n);"string"==typeof s&&s.startsWith(e)&&t.push(s)}t.forEach(e=>localStorage.removeItem(e))}scopedKey(e){return"-".concat(this.scope).concat(this.module?":".concat(this.module):"",":").concat(e)}static clearAll(){new r("CBWSDK").clear(),new r("walletlink").clear()}constructor(e,t){this.scope=e,this.module=t}}n(73588),n(75184),n(12100),n(29646),n(67581),n(63782),n(14311),n(72547),n(86936),n(20889),n(54357),n(86775),n(6763),n(92037),n(56113),n(80194),n(25800);let i=-32602,a=-32603,o=4001,c=4100,l=4200,h=4900,u={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."},4902:{standard:"EIP-3085",message:"Unrecognized chain ID."}},d="Unspecified error message.";function f(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d;if(e&&Number.isInteger(e)){var n;let t=e.toString();if(g(u,t))return u[t].message;if((n=e)>=-32099&&n<=-32e3)return"Unspecified server error."}return t}function p(e){return e&&"object"==typeof e&&!Array.isArray(e)?Object.assign({},e):e}function g(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function m(e,t){return"object"==typeof e&&null!==e&&t in e&&"string"==typeof e[t]}let y=e=>C(i,e),_=e=>C(a,e),b=e=>E(o,e),w=e=>E(c,e),v=e=>E(l,e),k=e=>E(h,e),x=e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw Error("Ethereum Provider custom errors must provide single object argument.");let{code:t,message:n,data:s}=e;if(!n||"string"!=typeof n)throw Error('"message" must be a nonempty string');return new M(t,n,s)};function C(e,t){let[n,s]=I(t);return new S(e,n||f(e),s)}function E(e,t){let[n,s]=I(t);return new M(e,n||f(e),s)}function I(e){if(e){if("string"==typeof e)return[e];else if("object"==typeof e&&!Array.isArray(e)){let{message:t,data:n}=e;if(t&&"string"!=typeof t)throw Error("Must specify string message.");return[t||void 0,n]}}return[]}class S extends Error{constructor(e,t,n){if(!Number.isInteger(e))throw Error('"code" must be an integer.');if(!t||"string"!=typeof t)throw Error('"message" must be a nonempty string.');super(t),this.code=e,void 0!==n&&(this.data=n)}}class M extends S{constructor(e,t,n){if(!function(e){return Number.isInteger(e)&&e>=1e3&&e<=4999}(e))throw Error('"code" must be an integer such that: 1000 <= code <= 4999');super(e,t,n)}}function L(e){return Math.floor(e)}let A=/^[0-9]*$/,D=/^[a-f0-9]*$/;function T(e){return N(crypto.getRandomValues(new Uint8Array(e)))}function N(e){return[...e].map(e=>e.toString(16).padStart(2,"0")).join("")}function O(e){return new Uint8Array(e.match(/.{1,2}/g).map(e=>Number.parseInt(e,16)))}function P(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=e.toString("hex");return t?"0x".concat(n):n}function R(e){return P(K(e),!0)}function U(e){return e.toString(10)}function j(e){return"0x".concat(BigInt(e).toString(16))}function B(e){return e.startsWith("0x")||e.startsWith("0X")}function H(e){return B(e)?e.slice(2):e}function W(e){return B(e)?"0x".concat(e.slice(2)):"0x".concat(e)}function q(e){if("string"!=typeof e)return!1;let t=H(e).toLowerCase();return D.test(t)}function V(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if("string"==typeof e){let n=H(e).toLowerCase();if(D.test(n))return t?"0x".concat(n):n}throw y('"'.concat(String(e),'" is not a hexadecimal string'))}(e,!1);return n.length%2==1&&(n="0".concat(n)),t?"0x".concat(n):n}function Z(e){if("string"==typeof e){let t=H(e).toLowerCase();if(q(t)&&40===t.length)return W(t)}throw y("Invalid Ethereum address: ".concat(String(e)))}function K(e){if(Buffer.isBuffer(e))return e;if("string"==typeof e){if(q(e)){let t=V(e,!1);return Buffer.from(t,"hex")}return Buffer.from(e,"utf8")}throw y("Not binary data: ".concat(String(e)))}function z(e){if("number"==typeof e&&Number.isInteger(e))return L(e);if("string"==typeof e){if(A.test(e))return L(Number(e));if(q(e))return L(Number(BigInt(V(e,!0))))}throw y("Not an integer: ".concat(String(e)))}function F(e){if(null!==e&&("bigint"==typeof e||function(e){if(null==e||"function"!=typeof e.constructor)return!1;let{constructor:t}=e;return"function"==typeof t.config&&"number"==typeof t.EUCLID}(e)))return BigInt(e.toString(10));if("number"==typeof e)return BigInt(z(e));if("string"==typeof e){if(A.test(e))return BigInt(e);if(q(e))return BigInt(V(e,!0))}throw y("Not an integer: ".concat(String(e)))}async function G(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"])}async function J(e,t){return crypto.subtle.deriveKey({name:"ECDH",public:t},e,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function Y(e,t){let n=crypto.getRandomValues(new Uint8Array(12)),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:n},e,new TextEncoder().encode(t));return{iv:n,cipherText:s}}async function Q(e,t){let{iv:n,cipherText:s}=t,r=await crypto.subtle.decrypt({name:"AES-GCM",iv:n},e,s);return new TextDecoder().decode(r)}function X(e){switch(e){case"public":return"spki";case"private":return"pkcs8"}}async function $(e,t){let n=X(e);return N(new Uint8Array(await crypto.subtle.exportKey(n,t)))}async function ee(e,t){let n=X(e),s=O(t).buffer;return await crypto.subtle.importKey(n,new Uint8Array(s),{name:"ECDH",namedCurve:"P-256"},!0,"private"===e?["deriveKey"]:[])}async function et(e,t){return Y(t,JSON.stringify(e,(e,t)=>t instanceof Error?Object.assign(Object.assign({},t.code?{code:t.code}:{}),{message:t.message}):t))}async function en(e,t){return JSON.parse(await Q(t,e))}let es={storageKey:"ownPrivateKey",keyType:"private"},er={storageKey:"ownPublicKey",keyType:"public"},ei={storageKey:"peerPublicKey",keyType:"public"};class ea{async getOwnPublicKey(){return await this.loadKeysIfNeeded(),this.ownPublicKey}async getSharedSecret(){return await this.loadKeysIfNeeded(),this.sharedSecret}async setPeerPublicKey(e){this.sharedSecret=null,this.peerPublicKey=e,await this.storeKey(ei,e),await this.loadKeysIfNeeded()}async clear(){this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null,this.storage.removeItem(er.storageKey),this.storage.removeItem(es.storageKey),this.storage.removeItem(ei.storageKey)}async generateKeyPair(){let e=await G();this.ownPrivateKey=e.privateKey,this.ownPublicKey=e.publicKey,await this.storeKey(es,e.privateKey),await this.storeKey(er,e.publicKey)}async loadKeysIfNeeded(){null===this.ownPrivateKey&&(this.ownPrivateKey=await this.loadKey(es)),null===this.ownPublicKey&&(this.ownPublicKey=await this.loadKey(er)),(null===this.ownPrivateKey||null===this.ownPublicKey)&&await this.generateKeyPair(),null===this.peerPublicKey&&(this.peerPublicKey=await this.loadKey(ei)),null===this.sharedSecret&&null!==this.ownPrivateKey&&null!==this.peerPublicKey&&(this.sharedSecret=await J(this.ownPrivateKey,this.peerPublicKey))}async loadKey(e){let t=this.storage.getItem(e.storageKey);return t?ee(e.keyType,t):null}async storeKey(e,t){let n=await $(e.keyType,t);this.storage.setItem(e.storageKey,n)}constructor(){this.storage=new r("CBWSDK","SCWKeyManager"),this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null}}let eo="4.3.0",ec="@coinbase/wallet-sdk";async function el(e,t){let n=Object.assign(Object.assign({},e),{jsonrpc:"2.0",id:crypto.randomUUID()}),s=await window.fetch(t,{method:"POST",body:JSON.stringify(n),mode:"cors",headers:{"Content-Type":"application/json","X-Cbw-Sdk-Version":eo,"X-Cbw-Sdk-Platform":ec}}),{result:r,error:i}=await s.json();if(i)throw i;return r}function eh(e){var t,n;let{metadata:s,preference:r}=e,{appName:i,appLogoUrl:a,appChainIds:o}=s;if("smartWalletOnly"!==r.options){let e=globalThis.coinbaseWalletExtension;if(e)return null==(t=e.setAppInfo)||t.call(e,i,a,o,r),e}let c=function(){var e,t;try{let n=globalThis;return null!=(e=n.ethereum)?e:null==(t=n.top)?void 0:t.ethereum}catch(e){return}}();if(null==c?void 0:c.isCoinbaseBrowser)return null==(n=c.setAppInfo)||n.call(c,i,a,o,r),c}let eu="accounts",ed="activeChain",ef="availableChains",ep="walletCapabilities";class eg{async handshake(e){var t,n,s,r;await (null==(n=(t=this.communicator).waitForPopupLoaded)?void 0:n.call(t));let i=await this.createRequestMessage({handshake:{method:e.method,params:Object.assign({},this.metadata,null!=(s=e.params)?s:{})}}),a=await this.communicator.postRequestAndWaitForResponse(i);if("failure"in a.content)throw a.content.failure;let o=await ee("public",a.sender);await this.keyManager.setPeerPublicKey(o);let c=(await this.decryptResponseMessage(a)).result;if("error"in c)throw c.error;if("eth_requestAccounts"===e.method){let e=c.value;this.accounts=e,this.storage.storeObject(eu,e),null==(r=this.callback)||r.call(this,"accountsChanged",e)}}async request(e){var t;if(0===this.accounts.length)if("wallet_sendCalls"===e.method)return this.sendRequestToPopup(e);else throw w();switch(e.method){case"eth_requestAccounts":return null==(t=this.callback)||t.call(this,"connect",{chainId:j(this.chain.id)}),this.accounts;case"eth_accounts":return this.accounts;case"eth_coinbase":return this.accounts[0];case"net_version":return this.chain.id;case"eth_chainId":return j(this.chain.id);case"wallet_getCapabilities":return this.storage.loadObject(ep);case"wallet_switchEthereumChain":return this.handleSwitchChainRequest(e);case"eth_ecRecover":case"personal_sign":case"wallet_sign":case"personal_ecRecover":case"eth_signTransaction":case"eth_sendTransaction":case"eth_signTypedData_v1":case"eth_signTypedData_v3":case"eth_signTypedData_v4":case"eth_signTypedData":case"wallet_addEthereumChain":case"wallet_watchAsset":case"wallet_sendCalls":case"wallet_showCallsStatus":case"wallet_grantPermissions":return this.sendRequestToPopup(e);default:if(!this.chain.rpcUrl)throw _("No RPC URL set for chain");return el(e,this.chain.rpcUrl)}}async sendRequestToPopup(e){var t,n;await (null==(n=(t=this.communicator).waitForPopupLoaded)?void 0:n.call(t));let s=await this.sendEncryptedRequest(e),r=(await this.decryptResponseMessage(s)).result;if("error"in r)throw r.error;return r.value}async cleanup(){var e,t;this.storage.clear(),await this.keyManager.clear(),this.accounts=[],this.chain={id:null!=(t=null==(e=this.metadata.appChainIds)?void 0:e[0])?t:1}}async handleSwitchChainRequest(e){var t;let n=e.params;if(!n||!(null==(t=n[0])?void 0:t.chainId))throw y();let s=z(n[0].chainId);if(this.updateChain(s))return null;let r=await this.sendRequestToPopup(e);return null===r&&this.updateChain(s),r}async sendEncryptedRequest(e){let t=await this.keyManager.getSharedSecret();if(!t)throw w("No valid session found, try requestAccounts before other methods");let n=await et({action:e,chainId:this.chain.id},t),s=await this.createRequestMessage({encrypted:n});return this.communicator.postRequestAndWaitForResponse(s)}async createRequestMessage(e){let t=await $("public",await this.keyManager.getOwnPublicKey());return{id:crypto.randomUUID(),sender:t,content:e,timestamp:new Date}}async decryptResponseMessage(e){var t,n;let s=e.content;if("failure"in s)throw s.failure;let r=await this.keyManager.getSharedSecret();if(!r)throw w("Invalid session");let i=await en(s.encrypted,r),a=null==(t=i.data)?void 0:t.chains;if(a){let e=Object.entries(a).map(e=>{let[t,n]=e;return{id:Number(t),rpcUrl:n}});this.storage.storeObject(ef,e),this.updateChain(this.chain.id,e)}let o=null==(n=i.data)?void 0:n.capabilities;return o&&this.storage.storeObject(ep,o),i}updateChain(e,t){var n;let s=null!=t?t:this.storage.loadObject(ef),r=null==s?void 0:s.find(t=>t.id===e);return!!r&&(r!==this.chain&&(this.chain=r,this.storage.storeObject(ed,r),null==(n=this.callback)||n.call(this,"chainChanged",j(r.id))),!0)}constructor(e){var t,n,s;this.metadata=e.metadata,this.communicator=e.communicator,this.callback=e.callback,this.keyManager=new ea,this.storage=new r("CBWSDK","SCWStateManager"),this.accounts=null!=(t=this.storage.loadObject(eu))?t:[],this.chain=this.storage.loadObject(ed)||{id:null!=(s=null==(n=e.metadata.appChainIds)?void 0:n[0])?s:1},this.handshake=this.handshake.bind(this),this.request=this.request.bind(this),this.createRequestMessage=this.createRequestMessage.bind(this),this.decryptResponseMessage=this.decryptResponseMessage.bind(this)}}n(28419);var em=n(91050);let ey="Addresses";function e_(e){return void 0!==e.errorMessage}n(13189),n(63277),n(82230),n(27899),n(37389),n(27968),n(46299);class eb{async encrypt(e){let t=this.secret;if(64!==t.length)throw Error("secret must be 256 bits");let n=crypto.getRandomValues(new Uint8Array(12)),s=await crypto.subtle.importKey("raw",O(t),{name:"aes-gcm"},!1,["encrypt","decrypt"]),r=new TextEncoder,i=await window.crypto.subtle.encrypt({name:"AES-GCM",iv:n},s,r.encode(e)),a=i.slice(i.byteLength-16),o=i.slice(0,i.byteLength-16),c=new Uint8Array(a),l=new Uint8Array(o);return N(new Uint8Array([...n,...c,...l]))}async decrypt(e){let t=this.secret;if(64!==t.length)throw Error("secret must be 256 bits");return new Promise((n,s)=>{!async function(){let r=await crypto.subtle.importKey("raw",O(t),{name:"aes-gcm"},!1,["encrypt","decrypt"]),i=O(e),a=i.slice(0,12),o=i.slice(12,28),c=new Uint8Array([...i.slice(28),...o]),l={name:"AES-GCM",iv:new Uint8Array(a)};try{let e=await window.crypto.subtle.decrypt(l,r,c),t=new TextDecoder;n(t.decode(e))}catch(e){s(e)}}()})}constructor(e){this.secret=e}}n(50886);class ew{async markUnseenEventsAsSeen(e){return Promise.all(e.map(e=>fetch("".concat(this.linkAPIUrl,"/events/").concat(e.eventId,"/seen"),{method:"POST",headers:{Authorization:this.auth}}))).catch(e=>console.error("Unabled to mark event as failed:",e))}async fetchUnseenEvents(){var e;let t=await fetch("".concat(this.linkAPIUrl,"/events?unseen=true"),{headers:{Authorization:this.auth}});if(t.ok){let{events:n,error:s}=await t.json();if(s)throw Error("Check unseen events failed: ".concat(s));let r=null!=(e=null==n?void 0:n.filter(e=>"Web3Response"===e.event).map(e=>({type:"Event",sessionId:this.sessionId,eventId:e.id,event:e.event,data:e.data})))?e:[];return this.markUnseenEventsAsSeen(r),r}throw Error("Check unseen events failed: ".concat(t.status))}constructor(e,t,n){this.linkAPIUrl=e,this.sessionId=t;let s="".concat(t,":").concat(n);this.auth="Basic ".concat(btoa(s))}}n(87945),(eV=eZ||(eZ={}))[eV.DISCONNECTED=0]="DISCONNECTED",eV[eV.CONNECTING=1]="CONNECTING",eV[eV.CONNECTED=2]="CONNECTED";class ev{setConnectionStateListener(e){this.connectionStateListener=e}setIncomingDataListener(e){this.incomingDataListener=e}async connect(){if(this.webSocket)throw Error("webSocket object is not null");return new Promise((e,t)=>{var n;let s;try{this.webSocket=s=new this.WebSocketClass(this.url)}catch(e){t(e);return}null==(n=this.connectionStateListener)||n.call(this,eZ.CONNECTING),s.onclose=e=>{var n;this.clearWebSocket(),t(Error("websocket error ".concat(e.code,": ").concat(e.reason))),null==(n=this.connectionStateListener)||n.call(this,eZ.DISCONNECTED)},s.onopen=t=>{var n;e(),null==(n=this.connectionStateListener)||n.call(this,eZ.CONNECTED),this.pendingData.length>0&&([...this.pendingData].forEach(e=>this.sendData(e)),this.pendingData=[])},s.onmessage=e=>{var t,n;if("h"===e.data)null==(t=this.incomingDataListener)||t.call(this,{type:"Heartbeat"});else try{let t=JSON.parse(e.data);null==(n=this.incomingDataListener)||n.call(this,t)}catch(e){}}})}disconnect(){var e;let{webSocket:t}=this;if(t){this.clearWebSocket(),null==(e=this.connectionStateListener)||e.call(this,eZ.DISCONNECTED),this.connectionStateListener=void 0,this.incomingDataListener=void 0;try{t.close()}catch(e){}}}sendData(e){let{webSocket:t}=this;if(!t){this.pendingData.push(e),this.connect();return}t.send(e)}clearWebSocket(){let{webSocket:e}=this;e&&(this.webSocket=null,e.onclose=null,e.onerror=null,e.onmessage=null,e.onopen=null)}constructor(e,t=WebSocket){this.WebSocketClass=t,this.webSocket=null,this.pendingData=[],this.url=e.replace(/^http/,"ws")}}class ek{connect(){if(this.destroyed)throw Error("instance is destroyed");this.ws.connect()}async destroy(){this.destroyed||(await this.makeRequest({type:"SetSessionConfig",id:L(this.nextReqId++),sessionId:this.session.id,metadata:{__destroyed:"1"}},{timeout:1e3}),this.destroyed=!0,this.ws.disconnect(),this.listener=void 0)}get connected(){return this._connected}set connected(e){this._connected=e}get linked(){return this._linked}set linked(e){var t,n;this._linked=e,e&&(null==(t=this.onceLinked)||t.call(this)),null==(n=this.listener)||n.linkedUpdated(e)}setOnceLinked(e){return new Promise(t=>{this.linked?e().then(t):this.onceLinked=()=>{e().then(t),this.onceLinked=void 0}})}async handleIncomingEvent(e){var t;if("Event"!==e.type||"Web3Response"!==e.event)return;let n=JSON.parse(await this.cipher.decrypt(e.data));if("WEB3_RESPONSE"!==n.type)return;let{id:s,response:r}=n;null==(t=this.listener)||t.handleWeb3ResponseMessage(s,r)}async checkUnseenEvents(){if(!this.connected){this.shouldFetchUnseenEventsOnConnect=!0;return}await new Promise(e=>setTimeout(e,250));try{await this.fetchUnseenEventsAPI()}catch(e){console.error("Unable to check for unseen events",e)}}async fetchUnseenEventsAPI(){this.shouldFetchUnseenEventsOnConnect=!1,(await this.http.fetchUnseenEvents()).forEach(e=>this.handleIncomingEvent(e))}async publishEvent(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({},t),{origin:location.origin,location:location.href,relaySource:"coinbaseWalletExtension"in window&&window.coinbaseWalletExtension?"injected_sdk":"sdk"}))),r={type:"PublishEvent",id:L(this.nextReqId++),sessionId:this.session.id,event:e,data:s,callWebhook:n};return this.setOnceLinked(async()=>{let e=await this.makeRequest(r);if("Fail"===e.type)throw Error(e.error||"failed to publish event");return e.eventId})}sendData(e){this.ws.sendData(JSON.stringify(e))}updateLastHeartbeat(){this.lastHeartbeatResponse=Date.now()}heartbeat(){if(Date.now()-this.lastHeartbeatResponse>2e4)return void this.ws.disconnect();try{this.ws.sendData("h")}catch(e){}}async makeRequest(e){let t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{timeout:6e4},s=e.id;return this.sendData(e),Promise.race([new Promise((e,r)=>{t=window.setTimeout(()=>{r(Error("request ".concat(s," timed out")))},n.timeout)}),new Promise(e=>{this.requestResolutions.set(s,n=>{clearTimeout(t),e(n),this.requestResolutions.delete(s)})})])}async handleConnected(){return"Fail"!==(await this.makeRequest({type:"HostSession",id:L(this.nextReqId++),sessionId:this.session.id,sessionKey:this.session.key})).type&&(this.sendData({type:"IsLinked",id:L(this.nextReqId++),sessionId:this.session.id}),this.sendData({type:"GetSessionConfig",id:L(this.nextReqId++),sessionId:this.session.id}),!0)}constructor({session:e,linkAPIUrl:t,listener:n}){this.destroyed=!1,this.lastHeartbeatResponse=0,this.nextReqId=L(1),this._connected=!1,this._linked=!1,this.shouldFetchUnseenEventsOnConnect=!1,this.requestResolutions=new Map,this.handleSessionMetadataUpdated=e=>{e&&new Map([["__destroyed",this.handleDestroyed],["EthereumAddress",this.handleAccountUpdated],["WalletUsername",this.handleWalletUsernameUpdated],["AppVersion",this.handleAppVersionUpdated],["ChainId",t=>e.JsonRpcUrl&&this.handleChainUpdated(t,e.JsonRpcUrl)]]).forEach((t,n)=>{let s=e[n];void 0!==s&&t(s)})},this.handleDestroyed=e=>{var t;"1"===e&&(null==(t=this.listener)||t.resetAndReload())},this.handleAccountUpdated=async e=>{var t;let n=await this.cipher.decrypt(e);null==(t=this.listener)||t.accountUpdated(n)},this.handleMetadataUpdated=async(e,t)=>{var n;let s=await this.cipher.decrypt(t);null==(n=this.listener)||n.metadataUpdated(e,s)},this.handleWalletUsernameUpdated=async e=>{this.handleMetadataUpdated("walletUsername",e)},this.handleAppVersionUpdated=async e=>{this.handleMetadataUpdated("AppVersion",e)},this.handleChainUpdated=async(e,t)=>{var n;let s=await this.cipher.decrypt(e),r=await this.cipher.decrypt(t);null==(n=this.listener)||n.chainUpdated(s,r)},this.session=e,this.cipher=new eb(e.secret),this.listener=n;let s=new ev("".concat(t,"/rpc"),WebSocket);s.setConnectionStateListener(async e=>{let t=!1;switch(e){case eZ.DISCONNECTED:if(!this.destroyed){let e=async()=>{await new Promise(e=>setTimeout(e,5e3)),this.destroyed||s.connect().catch(()=>{e()})};e()}break;case eZ.CONNECTED:t=await this.handleConnected(),this.updateLastHeartbeat(),setInterval(()=>{this.heartbeat()},1e4),this.shouldFetchUnseenEventsOnConnect&&this.fetchUnseenEventsAPI();case eZ.CONNECTING:}this.connected!==t&&(this.connected=t)}),s.setIncomingDataListener(e=>{var t;switch(e.type){case"Heartbeat":this.updateLastHeartbeat();return;case"IsLinkedOK":case"Linked":{let t="IsLinkedOK"===e.type?e.linked:void 0;this.linked=t||e.onlineGuests>0;break}case"GetSessionConfigOK":case"SessionConfigUpdated":this.handleSessionMetadataUpdated(e.metadata);break;case"Event":this.handleIncomingEvent(e)}void 0!==e.id&&(null==(t=this.requestResolutions.get(e.id))||t(e))}),this.ws=s,this.http=new ew(t,e.id,e.key)}}class ex{makeRequestId(){this._nextRequestId=(this._nextRequestId+1)%0x7fffffff;let e=this._nextRequestId,t=W(e.toString(16));return this.callbacks.get(t)&&this.callbacks.delete(t),e}constructor(){this._nextRequestId=0,this.callbacks=new Map}}function eC(e){for(var t=arguments.length,n=Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];if(!(e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name))throw Error("Uint8Array expected");if(n.length>0&&!n.includes(e.length))throw Error("Uint8Array expected of length "+n+", got length="+e.length)}function eE(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(e.destroyed)throw Error("Hash instance has been destroyed");if(t&&e.finished)throw Error("Hash#digest() has already been called")}function eI(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function eS(e,t){return e<<32-t|e>>>t}n(12745);let eM=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function eL(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}(e)),eC(e),e}class eA{clone(){return this._cloneInto()}}class eD extends eA{update(e){eE(this);let{view:t,buffer:n,blockLen:s}=this,r=(e=eL(e)).length;for(let i=0;i<r;){let a=Math.min(s-this.pos,r-i);if(a===s){let t=eI(e);for(;s<=r-i;i+=s)this.process(t,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){eE(this);eC(e);let t=this.outputLen;if(e.length<t)throw Error("digestInto() expects output buffer of length at least "+t);this.finished=!0;let{buffer:n,view:s,blockLen:r,isLE:i}=this,{pos:a}=this;n[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>r-a&&(this.process(s,0),a=0);for(let e=a;e<r;e++)n[e]=0;!function(e,t,n,s){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,s);let r=BigInt(32),i=BigInt(0xffffffff),a=Number(n>>r&i),o=Number(n&i),c=4*!!s,l=4*!s;e.setUint32(t+c,a,s),e.setUint32(t+l,o,s)}(s,r-8,BigInt(8*this.length),i),this.process(s,0);let o=eI(e),c=this.outputLen;if(c%4)throw Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)o.setUint32(4*e,h[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:r,destroyed:i,pos:a}=this;return e.length=s,e.pos=a,e.finished=r,e.destroyed=i,s%t&&e.buffer.set(n),e}constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=eI(this.buffer)}}let eT=new Uint32Array([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]),eN=new Uint32Array([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),eO=new Uint32Array(64);class eP extends eD{get(){let{A:e,B:t,C:n,D:s,E:r,F:i,G:a,H:o}=this;return[e,t,n,s,r,i,a,o]}set(e,t,n,s,r,i,a,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|s,this.E=0|r,this.F=0|i,this.G=0|a,this.H=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)eO[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=eO[e-15],n=eO[e-2],s=eS(t,7)^eS(t,18)^t>>>3,r=eS(n,17)^eS(n,19)^n>>>10;eO[e]=r+eO[e-7]+s+eO[e-16]|0}let{A:n,B:s,C:r,D:i,E:a,F:o,G:c,H:l}=this;for(let e=0;e<64;e++){var h,u,d,f;let t=l+(eS(a,6)^eS(a,11)^eS(a,25))+((h=a)&o^~h&c)+eT[e]+eO[e]|0,p=(eS(n,2)^eS(n,13)^eS(n,22))+((u=n)&(d=s)^u&(f=r)^d&f)|0;l=c,c=o,o=a,a=i+t|0,i=r,r=s,s=n,n=t+p|0}n=n+this.A|0,s=s+this.B|0,r=r+this.C|0,i=i+this.D|0,a=a+this.E|0,o=o+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,s,r,i,a,o,c,l)}roundClean(){eO.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}constructor(){super(64,32,8,!1),this.A=0|eN[0],this.B=0|eN[1],this.C=0|eN[2],this.D=0|eN[3],this.E=0|eN[4],this.F=0|eN[5],this.G=0|eN[6],this.H=0|eN[7]}}let eR=function(e){let t=t=>e().update(eL(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}(()=>new eP),eU="session:id",ej="session:secret",eB="session:linked";class eH{static create(e){return new eH(e,T(16),T(32)).save()}static load(e){let t=e.getItem(eU),n=e.getItem(eB),s=e.getItem(ej);return t&&s?new eH(e,t,s,"1"===n):null}get linked(){return this._linked}set linked(e){this._linked=e,this.persistLinked()}save(){return this.storage.setItem(eU,this.id),this.storage.setItem(ej,this.secret),this.persistLinked(),this}persistLinked(){this.storage.setItem(eB,this._linked?"1":"0")}constructor(e,t,n,s=!1){this.storage=e,this.id=t,this.secret=n,this.key=function(e){eC(e);let t="";for(let n=0;n<e.length;n++)t+=eM[e[n]];return t}(eR("".concat(t,", ").concat(n," WalletLink"))),this._linked=!!s}}function eW(){var e,t;return null!=(t=null==(e=null==window