@clerk/clerk-js
Version:
Clerk JS library
1 lines • 108 kB
JavaScript
(globalThis.webpackChunk_clerk_clerk_js=globalThis.webpackChunk_clerk_clerk_js||[]).push([["965"],{468:function(e,t){"use strict";function n(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)}function s(e,...t){if(!(e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name))throw Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw Error("Uint8Array expected of length "+t+", got length="+e.length)}Object.defineProperty(t,"__esModule",{value:!0}),t.anumber=n,t.abytes=s,t.ahash=function(e){if("function"!=typeof e||"function"!=typeof e.create)throw Error("Hash should be wrapped by utils.wrapConstructor");n(e.outputLen),n(e.blockLen)},t.aexists=function(e,t=!0){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){s(e);let n=t.outputLen;if(e.length<n)throw Error("digestInto() expects output buffer of length at least "+n)}},547:function(e,t){"use strict";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=r,t.split=i,t.add=b;let n=BigInt(0x100000000-1),s=BigInt(32);function r(e,t=!1){return t?{h:Number(e&n),l:Number(e>>s&n)}:{h:0|Number(e>>s&n),l:0|Number(e&n)}}function i(e,t=!1){let n=new Uint32Array(e.length),s=new Uint32Array(e.length);for(let i=0;i<e.length;i++){let{h:a,l:o}=r(e[i],t);[n[i],s[i]]=[a,o]}return[n,s]}let a=(e,t)=>BigInt(e>>>0)<<s|BigInt(t>>>0);t.toBig=a;let o=(e,t,n)=>e>>>n;t.shrSH=o;let l=(e,t,n)=>e<<32-n|t>>>n;t.shrSL=l;let c=(e,t,n)=>e>>>n|t<<32-n;t.rotrSH=c;let h=(e,t,n)=>e<<32-n|t>>>n;t.rotrSL=h;let u=(e,t,n)=>e<<64-n|t>>>n-32;t.rotrBH=u;let d=(e,t,n)=>e>>>n-32|t<<64-n;t.rotrBL=d;let f=(e,t)=>t;t.rotr32H=f;let p=(e,t)=>e;t.rotr32L=p;let g=(e,t,n)=>e<<n|t>>>32-n;t.rotlSH=g;let m=(e,t,n)=>t<<n|e>>>32-n;t.rotlSL=m;let y=(e,t,n)=>t<<n-32|e>>>64-n;t.rotlBH=y;let _=(e,t,n)=>e<<n-32|t>>>64-n;function b(e,t,n,s){let r=(t>>>0)+(s>>>0);return{h:e+n+(r/0x100000000|0)|0,l:0|r}}t.rotlBL=_;let w=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0);t.add3L=w;let v=(e,t,n,s)=>t+n+s+(e/0x100000000|0)|0;t.add3H=v;let k=(e,t,n,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0);t.add4L=k;let x=(e,t,n,s,r)=>t+n+s+r+(e/0x100000000|0)|0;t.add4H=x;let C=(e,t,n,s,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0)+(r>>>0);t.add5L=C;let E=(e,t,n,s,r,i)=>t+n+s+r+i+(e/0x100000000|0)|0;t.add5H=E,t.default={fromBig:r,split:i,toBig:a,shrSH:o,shrSL:l,rotrSH:c,rotrSL:h,rotrBH:u,rotrBL:d,rotr32H:f,rotr32L:p,rotlSH:g,rotlSL:m,rotlBH:y,rotlBL:_,add:b,add3L:w,add3H:v,add4L:k,add4H:x,add5H:E,add5L:C}},221: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},145:function(e,t,n){"use strict";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(468),r=n(547),i=n(865),a=[],o=[],l=[],c=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=c;for(let e=0;e<7;e++)(t=(t<<h^(t>>d)*p)%f)&u&&(r^=h<<(h<<BigInt(e))-h);l.push(r)}let[g,m]=(0,r.split)(l,!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,t=24){let 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],l=_(i,a,1)^n[s+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=l}let t=e[2],r=e[3];for(let n=0;n<24;n++){let s=o[n],i=y(t,r,s),l=_(t,r,s),c=a[n];t=e[c],r=e[c+1],e[c]=i,e[c+1]=l}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{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)}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}}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)((s={})=>new w(t,e,void 0===s.dkLen?n:s.dkLen,!0));t.shake128=k(31,168,16),t.shake256=k(31,136,32)},865:function(e,t,n){"use strict";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=l,t.utf8ToBytes=c,t.toBytes=h,t.concatBytes=function(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];(0,r.abytes)(s),t+=s.length}let n=new Uint8Array(t);for(let t=0,s=0;t<e.length;t++){let r=e[t];n.set(r,s),s+=r.length}return n},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(e=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(221),r=n(468);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 l(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 c(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=c(e)),(0,r.abytes)(e),e}t.nextTick=async()=>{},t.Hash=class{clone(){return this._cloneInto()}}},825:function(e){"use strict";var t=Object.prototype.hasOwnProperty,n="~";function s(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,s,i,a){if("function"!=typeof s)throw TypeError("The listener must be a function");var o=new r(s,i||e,a),l=n?n+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],o]:e._events[l].push(o):(e._events[l]=o,e._eventsCount++),e}function a(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function o(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(n=!1)),o.prototype.eventNames=function(){var e,s,r=[];if(0===this._eventsCount)return r;for(s in e=this._events)t.call(e,s)&&r.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},o.prototype.listeners=function(e){var t=n?n+e:e,s=this._events[t];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,i=s.length,a=Array(i);r<i;r++)a[r]=s[r].fn;return a},o.prototype.listenerCount=function(e){var t=n?n+e:e,s=this._events[t];return s?s.fn?1:s.length:0},o.prototype.emit=function(e,t,s,r,i,a){var o=n?n+e:e;if(!this._events[o])return!1;var l,c,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,s),!0;case 4:return h.fn.call(h.context,t,s,r),!0;case 5:return h.fn.call(h.context,t,s,r,i),!0;case 6:return h.fn.call(h.context,t,s,r,i,a),!0}for(c=1,l=Array(u-1);c<u;c++)l[c-1]=arguments[c];h.fn.apply(h.context,l)}else{var d,f=h.length;for(c=0;c<f;c++)switch(h[c].once&&this.removeListener(e,h[c].fn,void 0,!0),u){case 1:h[c].fn.call(h[c].context);break;case 2:h[c].fn.call(h[c].context,t);break;case 3:h[c].fn.call(h[c].context,t,s);break;case 4:h[c].fn.call(h[c].context,t,s,r);break;default:if(!l)for(d=1,l=Array(u-1);d<u;d++)l[d-1]=arguments[d];h[c].fn.apply(h[c].context,l)}}return!0},o.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},o.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},o.prototype.removeListener=function(e,t,s,r){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return a(this,i),this;var o=this._events[i];if(o.fn)o.fn!==t||r&&!o.once||s&&o.context!==s||a(this,i);else{for(var l=0,c=[],h=o.length;l<h;l++)(o[l].fn!==t||r&&!o[l].once||s&&o[l].context!==s)&&c.push(o[l]);c.length?this._events[i]=1===c.length?c[0]:c:a(this,i)}return this},o.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&a(this,t)):(this._events=new s,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=n,o.EventEmitter=o,e.exports=o},170:function(e,t,n){let s=n(689);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 l(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 c(e,t){if("address"===e)return c("uint160",l(t));if("bool"===e)return c("uint8",+!!t);if("string"===e)return c("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(c(e,t[u]));if("dynamic"===n){var n,r,h,u,d,f=c("uint256",t.length);h.unshift(f)}return Buffer.concat(h)}else if("bytes"===e)return t=new Buffer(t),h=Buffer.concat([c("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=l(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=l(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=l(t))<0)throw Error("Supplied ufixed is negative");return c("uint256",r*BigInt(2)**BigInt(n[1]))}else if(e.startsWith("fixed"))return n=a(e),c("int256",l(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=[],c=0;c<e.length;c++){var h=r(e[c]),u=t[c];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=l(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=l(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 l=r(e[a]),h=c(l,t[a]);"string"===l||"bytes"===l||"dynamic"===o(l)?(n.push(c("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))}}},50:function(e,t,n){let s=n(689),r=n(170),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 l=(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=>l(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]=l(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)}}},689:function(e,t,n){let{keccak_256:s}=n(145);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=l(e)?Buffer.from((t=c(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 l(e){return"string"==typeof e&&e.match(/^0x[0-9A-Fa-f]*$/)}function c(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:l,stripHexPrefix:c,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}}},279:function(e,t,n){"use strict";let s;n.r(t),n.d(t,{CoinbaseWalletSDK:()=>t6,default:()=>ne,createCoinbaseWalletSDK:()=>t9});class r{constructor(e,t){this.scope=e,this.module=t}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`-${this.scope}${this.module?`:${this.module}`:""}:${e}`}static clearAll(){new r("CBWSDK").clear(),new r("walletlink").clear()}}let i=-32602,a=-32603,o=4001,l=4100,c=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,t=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(l,e),v=e=>E(c,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,t=!1){let n=e.toString("hex");return t?`0x${n}`:n}function R(e){return P(K(e),!0)}function U(e){return e.toString(10)}function j(e){return`0x${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${e.slice(2)}`:`0x${e}`}function q(e){if("string"!=typeof e)return!1;let t=H(e).toLowerCase();return D.test(t)}function V(e,t=!1){let n=function(e,t=!1){if("string"==typeof e){let n=H(e).toLowerCase();if(D.test(n))return t?`0x${n}`:n}throw y(`"${String(e)}" is not a hexadecimal string`)}(e,!1);return n.length%2==1&&(n=`0${n}`),t?`0x${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: ${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: ${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: ${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: ${String(e)}`)}async function $(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"])}async function G(e,t){return crypto.subtle.deriveKey({name:"ECDH",public:t},e,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function J(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 Y(e,{iv:t,cipherText:n}){let s=await crypto.subtle.decrypt({name:"AES-GCM",iv:t},e,n);return new TextDecoder().decode(s)}function Q(e){switch(e){case"public":return"spki";case"private":return"pkcs8"}}async function X(e,t){let n=Q(e);return N(new Uint8Array(await crypto.subtle.exportKey(n,t)))}async function ee(e,t){let n=Q(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 J(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 Y(t,e))}let es={storageKey:"ownPrivateKey",keyType:"private"},er={storageKey:"ownPublicKey",keyType:"public"},ei={storageKey:"peerPublicKey",keyType:"public"};class ea{constructor(){this.storage=new r("CBWSDK","SCWKeyManager"),this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null}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 $();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 G(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 X(e.keyType,t);this.storage.setItem(e.storageKey,n)}}let eo="4.3.0",el="@coinbase/wallet-sdk";async function ec(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":el}}),{result:r,error:i}=await s.json();if(i)throw i;return r}function eh({metadata:e,preference:t}){var n,s;let{appName:r,appLogoUrl:i,appChainIds:a}=e;if("smartWalletOnly"!==t.options){let e=globalThis.coinbaseWalletExtension;if(e)return null==(n=e.setAppInfo)||n.call(e,r,i,a,t),e}let o=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==o?void 0:o.isCoinbaseBrowser)return null==(s=o.setAppInfo)||s.call(o,r,i,a,t),o}let eu="accounts",ed="activeChain",ef="availableChains",ep="walletCapabilities";class eg{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)}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 l=(await this.decryptResponseMessage(a)).result;if("error"in l)throw l.error;if("eth_requestAccounts"===e.method){let e=l.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 ec(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 X("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,t])=>({id:Number(e),rpcUrl:t}));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)}}var em=n(50);let ey="Addresses";function e_(e){return void 0!==e.errorMessage}class eb{constructor(e){this.secret=e}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),l=new Uint8Array(a),c=new Uint8Array(o);return N(new Uint8Array([...n,...l,...c]))}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),l=new Uint8Array([...i.slice(28),...o]),c={name:"AES-GCM",iv:new Uint8Array(a)};try{let e=await window.crypto.subtle.decrypt(c,r,l),t=new TextDecoder;n(t.decode(e))}catch(e){s(e)}}()})}}class ew{constructor(e,t,n){this.linkAPIUrl=e,this.sessionId=t;let s=`${t}:${n}`;this.auth=`Basic ${btoa(s)}`}async markUnseenEventsAsSeen(e){return Promise.all(e.map(e=>fetch(`${this.linkAPIUrl}/events/${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(`${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: ${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: ${t.status}`)}}(eZ=eK||(eK={}))[eZ.DISCONNECTED=0]="DISCONNECTED",eZ[eZ.CONNECTING=1]="CONNECTING",eZ[eZ.CONNECTED=2]="CONNECTED";class ev{setConnectionStateListener(e){this.connectionStateListener=e}setIncomingDataListener(e){this.incomingDataListener=e}constructor(e,t=WebSocket){this.WebSocketClass=t,this.webSocket=null,this.pendingData=[],this.url=e.replace(/^http/,"ws")}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,eK.CONNECTING),s.onclose=e=>{var n;this.clearWebSocket(),t(Error(`websocket error ${e.code}: ${e.reason}`)),null==(n=this.connectionStateListener)||n.call(this,eK.DISCONNECTED)},s.onopen=t=>{var n;e(),null==(n=this.connectionStateListener)||n.call(this,eK.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,eK.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)}}class ek{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(`${t}/rpc`,WebSocket);s.setConnectionStateListener(async e=>{let t=!1;switch(e){case eK.DISCONNECTED:if(!this.destroyed){let e=async()=>{await new Promise(e=>setTimeout(e,5e3)),this.destroyed||s.connect().catch(()=>{e()})};e()}break;case eK.CONNECTED:t=await this.handleConnected(),this.updateLastHeartbeat(),setInterval(()=>{this.heartbeat()},1e4),this.shouldFetchUnseenEventsOnConnect&&this.fetchUnseenEventsAPI();case eK.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)}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,n=!1){let 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,t={timeout:6e4}){let n,s=e.id;return this.sendData(e),Promise.race([new Promise((e,r)=>{n=window.setTimeout(()=>{r(Error(`request ${s} timed out`))},t.timeout)}),new Promise(e=>{this.requestResolutions.set(s,t=>{clearTimeout(n),e(t),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)}}class ex{constructor(){this._nextRequestId=0,this.callbacks=new Map}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}}function eC(e,...t){if(!(e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name))throw Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw Error("Uint8Array expected of length "+t+", got length="+e.length)}function eE(e,t=!0){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}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{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)}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),l=4*!!s,c=4*!s;e.setUint32(t+l,a,s),e.setUint32(t+c,o,s)}(s,r-8,BigInt(8*this.length),i),this.process(s,0);let o=eI(e),l=this.outputLen;if(l%4)throw Error("_sha2: outputLen should be aligned to 32bit");let c=l/4,h=this.get();if(c>h.length)throw Error("_sha2: outputLen bigger than state");for(let e=0;e<c;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}}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{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]}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:l,H:c}=this;for(let e=0;e<64;e++){var h,u,d,f;let t=c+(eS(a,6)^eS(a,11)^eS(a,25))+((h=a)&o^~h&l)+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;c=l,l=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,l=l+this.G|0,c=c+this.H|0,this.set(n,s,r,i,a,o,l,c)}roundClean(){eO.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}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{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(`${t}, ${n} WalletLink`)),this._linked=!!s}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")}}function eW(){var e,t;return null!=(t=null==(e=null==window?void 0:window.matchMedia)?void 0:e.call(window,"(prefers-color-scheme: dark)").matches)&&t}function eq(){let e=document.createElement("style");e.type="text/css",e.appendChild(document.createTextNode('@namespace svg "http://www.w3.org/2000/svg";.-cbwsdk-css-reset,.-cbwsdk-css-reset *{animation:none;animation-delay:0;animation-direction:normal;animation-duration:0;animation-fill-mode:none;animation-iteration-count:1;animation-name:none;animation-play-state:running;animation-timing-function:ease;backface-visibility:visible;background:0;background-attachment:scroll;background-clip:border-box;background-color:rgba(0,0,0,0);background-image:none;background-origin:padding-box;background-position:0 0;background-position-x:0;background-position-y:0;background-repeat:repeat;background-size:auto auto;border:0;border-style:none;border-width:medium;border-color:inherit;border-bottom:0;border-bottom-color:inherit;border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom-style:none;border-bottom-width:medium;border-collapse:separate;border-image:none;border-left:0;border-left-color:inherit;border-left-style:none;border-left-width:medium;border-radius:0;border-right:0;border-right-color:inherit;border-right-style:none;border-right-width:medium;border-spacing:0;border-top:0;border-top-color:inherit;border-top-left-radius:0;border-top-right-radius:0;border-top-style:none;border-top-width:medium;box-shadow:none;box-sizing:border-box;caption-side:top;clear:none;clip:auto;color:inherit;columns:auto;column-count:auto;column-fill:balance;column-gap:normal;column-rule:medium none currentColor;column-rule-color:currentColor;column-rule-style:none;column-rule-width:none;column-span:1;column-width:auto;counter-increment:none;counter-reset:none;direction:ltr;empty-cells:show;float:none;font:normal;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;height:auto;hyphens:none;letter-spacing:normal;line-height:normal;list-style:none;list-style-image:none;list-style-position:outs