UNPKG

@clerk/clerk-js

Version:
1 lines • 128 kB
(globalThis.rspackChunk_clerk_clerk_js=globalThis.rspackChunk_clerk_clerk_js||[]).push([[158],{3009(e,t){"use strict";t.rotlSL=t.rotlSH=t.rotlBL=t.rotlBH=void 0,t.split=function(e,t=!1){let i=e.length,r=new Uint32Array(i),a=new Uint32Array(i);for(let o=0;o<i;o++){let{h:i,l:c}=function(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)}}(e[o],t);[r[o],a[o]]=[i,c]}return[r,a]};let n=BigInt(0x100000000-1),s=BigInt(32);t.rotlSH=(e,t,n)=>e<<n|t>>>32-n;t.rotlSL=(e,t,n)=>t<<n|e>>>32-n;t.rotlBH=(e,t,n)=>t<<n-32|e>>>64-n;t.rotlBL=(e,t,n)=>e<<n-32|t>>>64-n},8510(e,t){"use strict";t.crypto=void 0,t.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0},5376(e,t,n){"use strict";t.keccak_256=void 0;let s=n(3009),i=n(6770),r=BigInt(0),a=BigInt(1),o=BigInt(2),c=BigInt(7),l=BigInt(256),h=BigInt(113),u=[],d=[],f=[];for(let e=0,t=a,n=1,s=0;e<24;e++){[n,s]=[s,(2*n+3*s)%5],u.push(2*(5*s+n)),d.push((e+1)*(e+2)/2%64);let i=r;for(let e=0;e<7;e++)(t=(t<<a^(t>>c)*h)%l)&o&&(i^=a<<(a<<BigInt(e))-a);f.push(i)}let p=(0,s.split)(f,!0),g=p[0],b=p[1],m=(e,t,n)=>n>32?(0,s.rotlBH)(e,t,n):(0,s.rotlSH)(e,t,n),y=(e,t,n)=>n>32?(0,s.rotlBL)(e,t,n):(0,s.rotlSL)(e,t,n);class w extends i.Hash{constructor(e,t,n,s=!1,r=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=s,this.rounds=r,(0,i.anumber)(n),!(0<e&&e<200))throw Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=(0,i.u32)(this.state)}clone(){return this._cloneInto()}keccak(){(0,i.swap32IfBE)(this.state32),function(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,i=(t+2)%10,r=n[i],a=n[i+1],o=m(r,a,1)^n[s],c=y(r,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],i=e[3];for(let n=0;n<24;n++){let s=d[n],r=m(t,i,s),a=y(t,i,s),o=u[n];t=e[o],i=e[o+1],e[o]=r,e[o+1]=a}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]^=b[s]}(0,i.clean)(n)}(this.state32,this.rounds),(0,i.swap32IfBE)(this.state32),this.posOut=0,this.pos=0}update(e){(0,i.aexists)(this),e=(0,i.toBytes)(e),(0,i.abytes)(e);let{blockLen:t,state:n}=this,s=e.length;for(let i=0;i<s;){let r=Math.min(t-this.pos,s-i);for(let t=0;t<r;t++)n[this.pos++]^=e[i++];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,i.aexists)(this,!1),(0,i.abytes)(e),this.finish();let t=this.state,{blockLen:n}=this;for(let s=0,i=e.length;s<i;){this.posOut>=n&&this.keccak();let r=Math.min(n-this.posOut,i-s);e.set(t.subarray(this.posOut,this.posOut+r),s),this.posOut+=r,s+=r}return e}xofInto(e){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,i.anumber)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,i.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,(0,i.clean)(this.state)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:s,rounds:i,enableXOF:r}=this;return e||(e=new w(t,n,s,r,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=s,e.enableXOF=r,e.destroyed=this.destroyed,e}}let _=(e,t,n)=>(0,i.createHasher)(()=>new w(t,e,n));_(6,144,28),_(6,136,32),_(6,104,48),_(6,72,64),_(1,144,28),t.keccak_256=_(1,136,32),_(1,104,48),_(1,72,64);let v=(e,t,n)=>(0,i.createXOFer)((s={})=>new w(t,e,void 0===s.dkLen?n:s.dkLen,!0));v(31,168,16),v(31,136,32)},6770(e,t,n){"use strict";t.Hash=t.dY=t.swap32IfBE=t.Y1=t.qv=void 0,t.anumber=function(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)},t.abytes=s,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)},t.u32=function(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))},t.clean=function(...e){for(let t=0;t<e.length;t++)e[t].fill(0)},t.toBytes=r,t.createHasher=function(e){let t=t=>e().update(r(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t},t.createXOFer=function(e){let t=(t,n)=>e(n).update(r(t)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t},n(8510);function s(e,...t){var n;if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.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 i(e){return e<<24&0xff000000|e<<8&0xff0000|e>>>8&65280|e>>>24&255}t.qv=68===new Uint8Array(new Uint32Array([0x11223344]).buffer)[0],t.Y1=t.qv?e=>e:e=>i(e),t.Y1,t.swap32IfBE=t.qv?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=i(e[t]);return e},"function"==typeof Uint8Array.from([]).toHex&&Uint8Array.fromHex,(e,t)=>t.toString(16).padStart(2,"0");function r(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}(e)),s(e),e}t.dY=async()=>{};t.Hash=class{}},4362(e,t,n){"use strict";function s(){for(var e,t,n=0,s="";n<arguments.length;)(e=arguments[n++])&&(t=function e(t){var n,s,i="";if("string"==typeof t||"number"==typeof t)i+=t;else if("object"==typeof t)if(Array.isArray(t))for(n=0;n<t.length;n++)t[n]&&(s=e(t[n]))&&(i&&(i+=" "),i+=s);else for(n in t)t[n]&&(i&&(i+=" "),i+=n);return i}(e))&&(s&&(s+=" "),s+=t);return s}n.d(t,{$:()=>s})},7215(e){"use strict";var t=Object.prototype.hasOwnProperty,n="~";function s(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function r(e,t,s,r,a){if("function"!=typeof s)throw TypeError("The listener must be a function");var o=new i(s,r||e,a),c=n?n+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 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,i=[];if(0===this._eventsCount)return i;for(s in e=this._events)t.call(e,s)&&i.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},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 i=0,r=s.length,a=Array(r);i<r;i++)a[i]=s[i].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,i,r,a){var o=n?n+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,s),!0;case 4:return h.fn.call(h.context,t,s,i),!0;case 5:return h.fn.call(h.context,t,s,i,r),!0;case 6:return h.fn.call(h.context,t,s,i,r,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,s);break;case 4:h[l].fn.call(h[l].context,t,s,i);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},o.prototype.on=function(e,t,n){return r(this,e,t,n,!1)},o.prototype.once=function(e,t,n){return r(this,e,t,n,!0)},o.prototype.removeListener=function(e,t,s,i){var r=n?n+e:e;if(!this._events[r])return this;if(!t)return a(this,r),this;var o=this._events[r];if(o.fn)o.fn!==t||i&&!o.once||s&&o.context!==s||a(this,r);else{for(var c=0,l=[],h=o.length;c<h;c++)(o[c].fn!==t||i&&!o[c].once||s&&o[c].context!==s)&&l.push(o[c]);l.length?this._events[r]=1===l.length?l[0]:l:a(this,r)}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},990(e,t,n){let s=n(768);function i(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 r(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,i,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=r(e))<1||n>32)throw Error("Invalid bytes<N> width: "+n);return s.setLengthRight(t,32)}else if(e.startsWith("uint")){if((n=r(e))%8||n<8||n>256)throw Error("Invalid uint<N> width: "+n);i=c(t);let a=s.bitLengthFromBigInt(i);if(a>n)throw Error("Supplied uint exceeds width: "+n+" vs "+a);if(i<0)throw Error("Supplied uint is negative");return s.bufferBEFromBigInt(i,32)}else if(e.startsWith("int")){if((n=r(e))%8||n<8||n>256)throw Error("Invalid int<N> width: "+n);i=c(t);let a=s.bitLengthFromBigInt(i);if(a>n)throw Error("Supplied int exceeds width: "+n+" vs "+a);let o=s.twosFromBigInt(i,256);return s.bufferBEFromBigInt(o,32)}else if(e.startsWith("ufixed")){if(n=a(e),(i=c(t))<0)throw Error("Supplied ufixed is negative");return l("uint256",i*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=i(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=r(h))<1||n>32)throw Error("Invalid bytes<N> width: "+n);o.push(s.setLengthRight(u,n))}else if(h.startsWith("uint")){if((n=r(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=r(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=[],r=32*e.length;for(var a in e){var c=i(e[a]),h=l(c,t[a]);"string"===c||"bytes"===c||"dynamic"===o(c)?(n.push(l("uint256",r)),s.push(h),r+=h.length):n.push(h)}return Buffer.concat(n.concat(s))},solidityPack:h,soliditySHA3:function(e,t){return s.keccak(h(e,t))}}},5912(e,t,n){let s=n(768),i=n(990),r={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,r=!0){let a=["bytes32"],o=[this.hashType(e,n)];if(r){let c=(e,t,a)=>{if(void 0!==n[t])return["bytes32",null==a?"0x0000000000000000000000000000000000000000000000000000000000000000":s.keccak(this.encodeData(t,a,n,r))];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("[")),r=a.map(t=>c(e,n,t));return["bytes32",s.keccak(i.rawEncode(r.map(([e])=>e),r.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 i of n[e]){let e=t[i.name];if(void 0!==e)if("bytes"===i.type)a.push("bytes32"),e=s.keccak(e),o.push(e);else if("string"===i.type)a.push("bytes32"),"string"==typeof e&&(e=Buffer.from(e,"utf8")),e=s.keccak(e),o.push(e);else if(void 0!==n[i.type])a.push("bytes32"),e=s.keccak(this.encodeData(i.type,e,n,r)),o.push(e);else if(i.type.lastIndexOf("]")===i.type.length-1)throw Error("Arrays currently unimplemented in encodeData");else a.push(i.type),o.push(e)}return i.rawEncode(a,o)},encodeType(e,t){let n="",s=this.findTypeDependencies(e,t).filter(t=>t!==e);for(let i of s=[e].concat(s.sort())){if(!t[i])throw Error("No type definition specified: "+i);n+=i+"("+t[i].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,i=!0){return s.keccak(this.encodeData(e,t,n,i))},hashType(e,t){return s.keccak(this.encodeType(e,t))},sanitizeData(e){let t={};for(let n in r.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),i=[Buffer.from("1901","hex")];return i.push(this.hashStruct("EIP712Domain",n.domain,n.types,t)),"EIP712Domain"!==n.primaryType&&i.push(this.hashStruct(n.primaryType,n.message,n.types,t)),s.keccak(Buffer.concat(i))}};e.exports={TYPED_MESSAGE_SCHEMA:r,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}),r=e.map(function(e){return e.type}),a=e.map(function(e){if(!e.name)throw t;return e.type+" "+e.name});return i.soliditySHA3(["bytes32","bytes32"],[i.soliditySHA3(Array(e.length).fill("string"),a),i.soliditySHA3(r,n)])}(e.data)},hashForSignTypedData_v3:function(e){return a.hash(e.data,!1)},hashForSignTypedData_v4:function(e){return a.hash(e.data)}}},768(e,t,n){let{keccak_256:s}=n(5376);function i(e){return Buffer.allocUnsafe(e).fill(0)}function r(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=i(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=r(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:i,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:r,twosFromBigInt:function(e,t){return(e<0n?(~e&(1n<<BigInt(t))-1n)+1n:e)&(1n<<BigInt(t))-1n}}},3197(e,t,n){"use strict";let s;n.r(t),n.d(t,{CoinbaseWalletSDK:()=>t1,createCoinbaseWalletSDK:()=>t3,default:()=>t5});var i=n(5544),r=n(5074);class a{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 a("CBWSDK").clear(),new a("walletlink").clear()}}let o=-32602,c=-32603,l=4001,h=4100,u=4200,d=4900,f={"-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."}},p="Unspecified error message.";function g(e,t=p){if(e&&Number.isInteger(e)){var n;let t=e.toString();if(m(f,t))return f[t].message;if((n=e)>=-32099&&n<=-32e3)return"Unspecified server error."}return t}function b(e){return e&&"object"==typeof e&&!Array.isArray(e)?Object.assign({},e):e}function m(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function y(e,t){return"object"==typeof e&&null!==e&&t in e&&"string"==typeof e[t]}let w=e=>I(o,e),_=e=>I(c,e),v=e=>S(l,e),x=e=>S(h,e),k=e=>S(u,e),C=e=>S(d,e),E=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 L(t,n,s)};function I(e,t){let[n,s]=A(t);return new M(e,n||g(e),s)}function S(e,t){let[n,s]=A(t);return new L(e,n||g(e),s)}function A(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 M 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 L extends M{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 O(e){return Math.floor(e)}let D=/^[0-9]*$/,N=/^[a-f0-9]*$/;function P(e){return T(crypto.getRandomValues(new Uint8Array(e)))}function T(e){return[...e].map(e=>e.toString(16).padStart(2,"0")).join("")}function U(e){return new Uint8Array(e.match(/.{1,2}/g).map(e=>Number.parseInt(e,16)))}function R(e,t=!1){let n=e.toString("hex");return t?`0x${n}`:n}function j(e){return R(Z(e),!0)}function H(e){return e.toString(10)}function B(e){return`0x${BigInt(e).toString(16)}`}function W(e){return e.startsWith("0x")||e.startsWith("0X")}function q(e){return W(e)?e.slice(2):e}function $(e){return W(e)?`0x${e.slice(2)}`:`0x${e}`}function z(e){if("string"!=typeof e)return!1;let t=q(e).toLowerCase();return N.test(t)}function V(e,t=!1){let n=function(e,t=!1){if("string"==typeof e){let n=q(e).toLowerCase();if(N.test(n))return t?`0x${n}`:n}throw w(`"${String(e)}" is not a hexadecimal string`)}(e,!1);return n.length%2==1&&(n=`0${n}`),t?`0x${n}`:n}function F(e){if("string"==typeof e){let t=q(e).toLowerCase();if(z(t)&&40===t.length)return $(t)}throw w(`Invalid Ethereum address: ${String(e)}`)}function Z(e){if(Buffer.isBuffer(e))return e;if("string"==typeof e){if(z(e)){let t=V(e,!1);return Buffer.from(t,"hex")}return Buffer.from(e,"utf8")}throw w(`Not binary data: ${String(e)}`)}function K(e){if("number"==typeof e&&Number.isInteger(e))return O(e);if("string"==typeof e){if(D.test(e))return O(Number(e));if(z(e))return O(Number(BigInt(V(e,!0))))}throw w(`Not an integer: ${String(e)}`)}function G(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(K(e));if("string"==typeof e){if(D.test(e))return BigInt(e);if(z(e))return BigInt(V(e,!0))}throw w(`Not an integer: ${String(e)}`)}async function Q(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"])}async function Y(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 X(e,{iv:t,cipherText:n}){let s=await crypto.subtle.decrypt({name:"AES-GCM",iv:t},e,n);return new TextDecoder().decode(s)}function ee(e){switch(e){case"public":return"spki";case"private":return"pkcs8"}}async function et(e,t){let n=ee(e);return T(new Uint8Array(await crypto.subtle.exportKey(n,t)))}async function en(e,t){let n=ee(e),s=U(t).buffer;return await crypto.subtle.importKey(n,new Uint8Array(s),{name:"ECDH",namedCurve:"P-256"},!0,"private"===e?["deriveKey"]:[])}async function es(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 ei(e,t){return JSON.parse(await X(t,e))}let er={storageKey:"ownPrivateKey",keyType:"private"},ea={storageKey:"ownPublicKey",keyType:"public"},eo={storageKey:"peerPublicKey",keyType:"public"};class ec{constructor(){this.storage=new a("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(eo,e),await this.loadKeysIfNeeded()}async clear(){this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null,this.storage.removeItem(ea.storageKey),this.storage.removeItem(er.storageKey),this.storage.removeItem(eo.storageKey)}async generateKeyPair(){let e=await Q();this.ownPrivateKey=e.privateKey,this.ownPublicKey=e.publicKey,await this.storeKey(er,e.privateKey),await this.storeKey(ea,e.publicKey)}async loadKeysIfNeeded(){null===this.ownPrivateKey&&(this.ownPrivateKey=await this.loadKey(er)),null===this.ownPublicKey&&(this.ownPublicKey=await this.loadKey(ea)),(null===this.ownPrivateKey||null===this.ownPublicKey)&&await this.generateKeyPair(),null===this.peerPublicKey&&(this.peerPublicKey=await this.loadKey(eo)),null===this.sharedSecret&&null!==this.ownPrivateKey&&null!==this.peerPublicKey&&(this.sharedSecret=await Y(this.ownPrivateKey,this.peerPublicKey))}async loadKey(e){let t=this.storage.getItem(e.storageKey);return t?en(e.keyType,t):null}async storeKey(e,t){let n=await et(e.keyType,t);this.storage.setItem(e.storageKey,n)}}var el=n(7138);let eh="@coinbase/wallet-sdk";async function eu(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":"4.3.7","X-Cbw-Sdk-Platform":eh}}),{result:i,error:r}=await s.json();if(r)throw r;return i}function ed({metadata:e,preference:t}){var n,s;let{appName:i,appLogoUrl:r,appChainIds:a}=e;if("smartWalletOnly"!==t.options){let e=globalThis.coinbaseWalletExtension;if(e)return null==(n=e.setAppInfo)||n.call(e,i,r,a,t),e}let o=function(){var e,t;try{let n=globalThis;return null!=(t=null==(e=n.top)?void 0:e.ethereum)?t:n.ethereum}catch(e){return}}();if(null==o?void 0:o.isCoinbaseBrowser)return null==(s=o.setAppInfo)||s.call(o,i,r,a,t),o}let ef="accounts",ep="activeChain",eg="availableChains",eb="walletCapabilities";class em{constructor(e){var t,n,s;this.metadata=e.metadata,this.communicator=e.communicator,this.callback=e.callback,this.keyManager=new ec,this.storage=new a("CBWSDK","SCWStateManager"),this.accounts=null!=(t=this.storage.loadObject(ef))?t:[],this.chain=this.storage.loadObject(ep)||{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,i;await (null==(n=(t=this.communicator).waitForPopupLoaded)?void 0:n.call(t));let r=await this.createRequestMessage({handshake:{method:e.method,params:Object.assign({},this.metadata,null!=(s=e.params)?s:{})}}),a=await this.communicator.postRequestAndWaitForResponse(r);if("failure"in a.content)throw a.content.failure;let o=await en("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(ef,e),null==(i=this.callback)||i.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 x();switch(e.method){case"eth_requestAccounts":return null==(t=this.callback)||t.call(this,"connect",{chainId:B(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 B(this.chain.id);case"wallet_getCapabilities":return this.handleGetCapabilitiesRequest(e);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 eu(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),i=(await this.decryptResponseMessage(s)).result;if("error"in i)throw i.error;return i.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 w();let s=K(n[0].chainId);if(this.updateChain(s))return null;let i=await this.sendRequestToPopup(e);return null===i&&this.updateChain(s),i}async handleGetCapabilitiesRequest(e){var t=e.params;if(!t||!Array.isArray(t)||1!==t.length&&2!==t.length||"string"!=typeof t[0]||!(0,el.P)(t[0]))throw w();if(2===t.length){if(!Array.isArray(t[1]))throw w();for(let e of t[1])if("string"!=typeof e||!e.startsWith("0x"))throw w()}let n=e.params[0],s=e.params[1];if(!this.accounts.some(e=>(0,i.h)(e,n)))throw x("no active account found");let a=this.storage.loadObject(eb);if(!a)return{};if(!s||0===s.length)return a;let o=new Set(s.map(e=>(0,r.ME)(e)));return Object.fromEntries(Object.entries(a).filter(([e])=>{try{let t=(0,r.ME)(e);return o.has(t)}catch(e){return!1}}))}async sendEncryptedRequest(e){let t=await this.keyManager.getSharedSecret();if(!t)throw x("No valid session found, try requestAccounts before other methods");let n=await es({action:e,chainId:this.chain.id},t),s=await this.createRequestMessage({encrypted:n});return this.communicator.postRequestAndWaitForResponse(s)}async createRequestMessage(e){let t=await et("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 i=await this.keyManager.getSharedSecret();if(!i)throw x("Invalid session");let r=await ei(s.encrypted,i),a=null==(t=r.data)?void 0:t.chains;if(a){let e=Object.entries(a).map(([e,t])=>({id:Number(e),rpcUrl:t}));this.storage.storeObject(eg,e),this.updateChain(this.chain.id,e)}let o=null==(n=r.data)?void 0:n.capabilities;return o&&this.storage.storeObject(eb,o),r}updateChain(e,t){var n;let s=null!=t?t:this.storage.loadObject(eg),i=null==s?void 0:s.find(t=>t.id===e);return!!i&&(i!==this.chain&&(this.chain=i,this.storage.storeObject(ep,i),null==(n=this.callback)||n.call(this,"chainChanged",B(i.id))),!0)}}var ey=n(5912);let ew="Addresses";function e_(e){return void 0!==e.errorMessage}class ev{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",U(t),{name:"aes-gcm"},!1,["encrypt","decrypt"]),i=new TextEncoder,r=await window.crypto.subtle.encrypt({name:"AES-GCM",iv:n},s,i.encode(e)),a=r.slice(r.byteLength-16),o=r.slice(0,r.byteLength-16),c=new Uint8Array(a),l=new Uint8Array(o);return T(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 i=await crypto.subtle.importKey("raw",U(t),{name:"aes-gcm"},!1,["encrypt","decrypt"]),r=U(e),a=r.slice(0,12),o=r.slice(12,28),c=new Uint8Array([...r.slice(28),...o]),l={name:"AES-GCM",iv:new Uint8Array(a)};try{let e=await window.crypto.subtle.decrypt(l,i,c),t=new TextDecoder;n(t.decode(e))}catch(e){s(e)}}()})}}class ex{constructor(e,t,n){this.linkAPIUrl=e,this.sessionId=t;const 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 i=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(i),i}throw Error(`Check unseen events failed: ${t.status}`)}}(eP=eT||(eT={}))[eP.DISCONNECTED=0]="DISCONNECTED",eP[eP.CONNECTING=1]="CONNECTING",eP[eP.CONNECTED=2]="CONNECTED";class ek{setConnectionStateListener(e){this.connectionStateListener=e}setIncomingDataListener(e){this.incomingDataListener=e}constructor(e,t=WebSocket){this.WebSocketClass=t,this.webSocket=null,this.isDisconnecting=!1,this.url=e.replace(/^http/,"ws"),this.instanceId=ek.instanceCounter++,ek.activeInstances.add(this.instanceId)}async connect(){if(this.webSocket)throw Error("webSocket object is not null");if(this.isDisconnecting)throw Error("WebSocket is disconnecting, cannot reconnect on same instance");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,eT.CONNECTING),s.onclose=e=>{var n;this.clearWebSocket(),s.readyState!==WebSocket.OPEN&&t(Error(`websocket error ${e.code}: ${e.reason}`)),null==(n=this.connectionStateListener)||n.call(this,eT.DISCONNECTED)},s.onopen=t=>{var n;e(),null==(n=this.connectionStateListener)||n.call(this,eT.CONNECTED),ek.pendingData.length>0&&([...ek.pendingData].forEach(e=>this.sendData(e)),ek.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.isDisconnecting=!0,this.clearWebSocket(),null==(e=this.connectionStateListener)||e.call(this,eT.DISCONNECTED),this.connectionStateListener=void 0,this.incomingDataListener=void 0;try{t.close()}catch(e){}}}sendData(e){let{webSocket:t}=this;if(!t){ek.pendingData.push(e),this.isDisconnecting||this.connect();return}t.readyState!==WebSocket.OPEN?ek.pendingData.push(e):t.send(e)}clearWebSocket(){let{webSocket:e}=this;e&&(this.webSocket=null,e.onclose=null,e.onerror=null,e.onmessage=null,e.onopen=null)}cleanup(){ek.activeInstances.delete(this.instanceId)}}ek.instanceCounter=0,ek.activeInstances=new Set,ek.pendingData=[];class eC{constructor({session:e,linkAPIUrl:t,listener:n}){this.destroyed=!1,this.lastHeartbeatResponse=0,this.nextReqId=O(1),this.reconnectAttempts=0,this.isReconnecting=!1,this._connected=!1,this._linked=!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;try{let n=await this.cipher.decrypt(e);null==(t=this.listener)||t.accountUpdated(n)}catch(e){}},this.handleMetadataUpdated=async(e,t)=>{var n;try{let s=await this.cipher.decrypt(t);null==(n=this.listener)||n.metadataUpdated(e,s)}catch(e){}},this.handleWalletUsernameUpdated=async e=>{this.handleMetadataUpdated("walletUsername",e)},this.handleAppVersionUpdated=async e=>{this.handleMetadataUpdated("AppVersion",e)},this.handleChainUpdated=async(e,t)=>{var n;try{let s=await this.cipher.decrypt(e),i=await this.cipher.decrypt(t);null==(n=this.listener)||n.chainUpdated(s,i)}catch(e){}},this.session=e,this.cipher=new ev(e.secret),this.listener=n,this.linkAPIUrl=t,this.WebSocketClass=WebSocket;const s=this.createWebSocket();this.ws=s,this.http=new ex(t,e.id,e.key),this.setupVisibilityChangeHandler()}createWebSocket(){let e=new ek(`${this.linkAPIUrl}/rpc`,this.WebSocketClass);return this.activeWsInstance=e,e.setConnectionStateListener(async t=>{if(e!==this.activeWsInstance)return;let n=!1;switch(t){case eT.DISCONNECTED:this.heartbeatIntervalId&&(clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=void 0),this.lastHeartbeatResponse=0,n=!1,this.destroyed||(async()=>{if(this.isReconnecting)return;this.isReconnecting=!0;let t=3e3*(0!==this.reconnectAttempts);await new Promise(e=>setTimeout(e,t)),this.destroyed||e!==this.activeWsInstance?this.isReconnecting=!1:(this.reconnectAttempts++,"cleanup"in this.ws&&"function"==typeof this.ws.cleanup&&this.ws.cleanup(),this.ws=this.createWebSocket(),this.ws.connect().catch(()=>{}).finally(()=>{this.isReconnecting=!1}))})();break;case eT.CONNECTED:this.reconnectAttempts=0;try{n=await this.handleConnected(),this.fetchUnseenEventsAPI().catch(()=>{})}catch(e){break}this.connected=n,this.updateLastHeartbeat(),this.heartbeatIntervalId&&clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=window.setInterval(()=>{this.heartbeat()},1e4),setTimeout(()=>{this.heartbeat()},100);case eT.CONNECTING:}t!==eT.CONNECTED&&(this.connected=n)}),e.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))}),e}setupVisibilityChangeHandler(){this.visibilityChangeHandler=()=>{document.hidden||this.destroyed||(this.connected?this.heartbeat():this.reconnectWithFreshWebSocket())},this.focusHandler=()=>{this.destroyed||this.connected||this.reconnectWithFreshWebSocket()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),window.addEventListener("focus",this.focusHandler),window.addEventListener("pageshow",e=>{e.persisted&&this.focusHandler&&this.focusHandler()})}reconnectWithFreshWebSocket(){if(this.destroyed)return;let e=this.ws;this.activeWsInstance=void 0,e.disconnect(),"cleanup"in e&&"function"==typeof e.cleanup&&e.cleanup(),this.ws=this.createWebSocket(),this.ws.connect().catch(()=>{})}connect(){if(this.destroyed)throw Error("instance is destroyed");this.ws.connect()}async destroy(){this.destroyed||(await this.makeRequest({type:"SetSessionConfig",id:O(this.nextReqId++),sessionId:this.session.id,metadata:{__destroyed:"1"}},{timeout:1e3}),this.destroyed=!0,this.activeWsInstance=void 0,this.heartbeatIntervalId&&(clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=void 0),this.visibilityChangeHandler&&document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.focusHandler&&window.removeEventListener("focus",this.focusHandler),this.ws.disconnect(),"cleanup"in this.ws&&"function"==typeof this.ws.cleanup&&this.ws.cleanup(),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)try{let n=await this.cipher.decrypt(e.data),s=JSON.parse(n);if("WEB3_RESPONSE"!==s.type)return;null==(t=this.listener)||t.handleWeb3ResponseMessage(s.id,s.response)}catch(e){}}async checkUnseenEvents(){await new Promise(e=>setTimeout(e,250));try{await this.fetchUnseenEventsAPI()}catch(e){console.error("Unable to check for unseen events",e)}}async fetchUnseenEventsAPI(){try{(await this.http.fetchUnseenEvents()).forEach(e=>{this.handleIncomingEvent(e)})}catch(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"}))),i={type:"PublishEvent",id:O(this.nextReqId++),sessionId:this.session.id,event:e,data:s,callWebhook:n};return this.setOnceLinked(async()=>{let e=await this.makeRequest(i);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();if(this.connected)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,i)=>{n=window.setTimeout(()=>{i(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:O(this.nextReqId++),sessionId:this.session.id,sessionKey:this.session.key})).type&&(this.sendData({type:"IsLinked",id:O(this.nextReqId++),sessionId:this.session.id}),this.sendData({type:"GetSessionConfig",id:O(this.nextReqId++),sessionId:this.session.id}),!0)}}class eE{constructor(){this._nextRequestId=0,this.callbacks=new Map}makeRequestId(){this._nextRequestId=(this._nextRequestId+1)%0x7fffffff;let e=this._nextRequestId,t=$(e.toString(16));return this.callbacks.get(t)&&this.callbacks.delete(t),e}}var eI=n(5013),eS=n(6167);let eA="session:id",eM="session:secret",eL="session:linked";class eO{constructor(e,t,n,s=!1){this.storage=e,this.id=t,this.secret=n,this.key=(0,eS.My)((0,eI.sc)(`${t}, ${n} WalletLink`)),this._linked=!!s}static create(e){return new eO(e,P(16),P(32)).save()}static load(e){let t=e.getItem(eA),n=e.getItem(eL),s=e.getItem(eM);return t&&s?new eO(e,t,s,"1"===n):null}get linked(){return this._linked}set linked(e){this._linked=e,this.persistLinked()}save(){return this.storage.setItem(eA,this.id),this.storage.setItem(eM,this.secret),this.persistLinked(),this}persistLinked(){this.storage.setItem(eL,this._linked?"1":"0")}}function eD(){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 eN(){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:outside;list-style-type:disc;margin:0;margin-bottom:0;margin-left:0;margin-right:0;margin-top:0;opacity:1;orphans:0;outline:0;outline-color:invert;outline-style:none;outline-width:medium;overflow:visible;overflow-x:visible;overflow-y:visible;padding:0;padding-bottom:0;padding-left:0;padding-right:0;padding-top:0;page-break-after:auto;page-break-before:auto;page-break-inside:auto;perspective:none;perspective-origin:50% 50%;pointer-events:auto;position:static;quotes:"\\201C" "\\201D" "\\2018" "\\2019";tab-size:8;table-layout:auto;text-align:inherit;text-align-last:auto;text-decoration:none;text-decoration-color:inherit;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-shadow:none;text-transform:none;transform:none;transform-style:flat;transition:none;transition-delay:0s;transition-duration:0s;transition-property:none;transition-timing-function:ease;unicode-bidi:normal;vertical-align:baseline;visibility:visible;white-space:normal;widows:0;word-spacing:normal;z-index:auto}.-cbwsdk-css-reset strong{font-weight:bold}.-cbwsdk-css-reset *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;line-height:1}.-cbwsdk-css-reset [class*=container]{margin:0;padding:0}.-cbwsdk-css-reset style{display:none}')),document.documentElement.appendChild(e)}var eP,eT,eU,eR,ej,eH,eB,eW,eq,e$,ez,eV,eF,eZ=n(4362),eK={},eG=[],eQ=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,eY=Array.isArray;function eJ(e,t){for(var n in t)e[n]=t[n];return e}function eX(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function e0(e,t,n){var s,i,r,a={};for(r in t)"key"==r?s=t[r]:"ref"==r?i=t[r]:a[r]=t[r];if(arguments.length>2&&(a.children=arguments.length>3?eU.call(arguments,2):n),"function"==typeof e&&null!=e.defaultProps)for(r in e.defaultProps)void 0===a[r]&&(a[r]=e.defaultProps[r]);return e1(e,a,s,i,null)}function e1(e,t,n,s,i){var r={type:e,props:t,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==i?++ej:i,__i:-1,__u:0};return null==i&&null!=eR.vnode&&eR.vnode(r),r}function e2(e){return e.children}function e3(e,t){this.props=e,this.context=t}function e5(e,t){if(null==t)return e.__?e5(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?e5(e):null}function e4(e){(!e.__d&&(e.__d=!0)&&eH.push(e)&&!e8.__r++||eB!=eR.debounceRendering)&&((eB=eR.debounceRendering)||eW)(e8)}function e8(){for(var e,t,n,s,i,r,a=1;eH.length;)eH.length>a&&eH.sort(eq),e=eH.shift(),a=eH.length,e.__d&&(t=void 0,n=void 0,s=(n=e.__v).__e,i=[],r=[],e.__P&&((t=eJ({},n)).__v=n.__v+1,eR.vnode&&eR.vnode(t),tt(e.__P,t,n,e.__n,e.__P.namespaceURI,32&n.__u?[s]:null,i,null==s?e5(n):s,!!(32&n.__u),r),t.__v=n.__v,t.__.__k[t.__i]=t,ts(i,t,r),n.__e=n.__=null,t.__e!=s&&function e(t){var n,s;if(null!=(t=t.__)&&null!=t.__c){for(t.__e=t.__c.base=null,n=0;n<t.__k.length;n++)if(null!=(s=t.__k[n])&&null!=s.__e){t.__e=t.__c.base=s.__e;break}return e(t)}}(t)));e8.__r=0}function e6(e,t,n,s,i,r,a,o,c,l,h){var u,d,f,p,g,b,m,y=s&&s.__k||eG,w=t.length;for(c=function(e,t,n,s,i){var r,a,o,c,l,h=n.length,u=h,d=0;for(e.__k=Array(i),r=0;r<i;r++)null!=(a=t[r])&&"boolean"!=typeof a&&"function"!=typeof a?(c=r+d,(a=e.__k[r]="string"==typeof a||"number"==typeof a||"bigint"==typeof a||a.constructor==String?e1(null,a,null,null,null):eY(a)?e1(e2,{children:a},null,null,null):void 0===a.constructor&&a.__b>0?e1(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=e,a.__b=e.__b+1,o=null,-1!=(l=a.__i=function(e,t,n,s){var i,r,a,o=e.key,c=e.type,l=t[n],h=null!=l&&0==(2&l.__u);if(null===l&&null==e.key||h&&o==l.key&&c==l.type)return n;if(s>+!!h){for(i=n-1,r=n+1;i>=0||r<t.length;)if(null!=(l=t[a=i>=0?i--:r++])&&0==(2&l.__u)&&o==l.key&&c==l.type)return a}return -1}(a,n,c,u))&&(u--,(o=n[l])&&(o.__u|=2)),null==o||null==o.__v?(-1==l&&(i>h?d--:i<h&&d++),"function"!=typeof a.type&&(a.__u|=4)):l!=c&&(l==c-1?d--:l==c+1?d++:(l>c?d--:d++,a.__u|=4))):e.__k[r]=null;if(u)for(r=0;r<h;r++)null!=(o=n[r])&&0==(2&o.__u)&&(o.__e==s&&(s=e5(o)),function e(t,n,s){var i,r;if(eR.unmount&&eR.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||ti(i,null,n)),null!=(i=t.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){eR.__e(e,n)}i.base=i.__P=null}if(i=t.__k)for(r=0;r<i.length;r++)i[r]&&e(i[r],n,s||"function"!=typeof t.type);s||eX(t.__e),t.__c=t.__=t.__e=void 0}(o,o));return s}(n,t,y,c,w),u=0;u<w;u++)null!=(f=n.__k[u])&&(d=-1==f.__i?eK:y[f.__i]||eK,f.__i=u,b=tt(e,f,d,i,r,a,o,c,l,h),p=f.__e,f.ref&&d.ref!=f.ref&&(d.ref&&ti(d.ref,null,f),h.push(f.ref,f.__c||p,f)),null==g&&null!=p&&(g=p),(m=!!(4&f.__u))||d.__k===f.__k?c=function e(t,n,s,i){var r,a;if("function"==typeof t.type){for(r=t.__k,a=0;r&&a<r.length;a++)r[a]&&(r[a].__=t,n=e(r[a],n,s,i));return n}t.__e!=n&&(i&&(n&&t.type&&!n.parentNode&&(n=e5(t)),s.insertBefore(t.__e,n||null)),n=t.__e);do n=n&&n.nextSibling;while(null!=n&&8==n.nodeType)return n}(f,c,e,m):"function"==typeof f.type&&void 0!==b?c=b:p&&(c