hunt-mint-swap
Version:
A React component library for swapping MINT / HUNT buildings
3,437 lines • 133 kB
JavaScript
import { isAddress as Nn, isAddressEqual as On, hexToNumber as ht } from "viem";
import { g as Dn, b as Un, s as jn, E as Bn } from "./index-CxZxEBmz.js";
class J {
constructor(e, n) {
this.scope = e, this.module = n;
}
storeObject(e, n) {
this.setItem(e, JSON.stringify(n));
}
loadObject(e) {
const n = this.getItem(e);
return n ? JSON.parse(n) : void 0;
}
setItem(e, n) {
localStorage.setItem(this.scopedKey(e), n);
}
getItem(e) {
return localStorage.getItem(this.scopedKey(e));
}
removeItem(e) {
localStorage.removeItem(this.scopedKey(e));
}
clear() {
const e = this.scopedKey(""), n = [];
for (let s = 0; s < localStorage.length; s++) {
const r = localStorage.key(s);
typeof r == "string" && r.startsWith(e) && n.push(r);
}
n.forEach((s) => localStorage.removeItem(s));
}
scopedKey(e) {
return `-${this.scope}${this.module ? `:${this.module}` : ""}:${e}`;
}
static clearAll() {
new J("CBWSDK").clear(), new J("walletlink").clear();
}
}
const j = {
rpc: {
invalidInput: -32e3,
resourceNotFound: -32001,
resourceUnavailable: -32002,
transactionRejected: -32003,
methodNotSupported: -32004,
limitExceeded: -32005,
parse: -32700,
invalidRequest: -32600,
methodNotFound: -32601,
invalidParams: -32602,
internal: -32603
},
provider: {
userRejectedRequest: 4001,
unauthorized: 4100,
unsupportedMethod: 4200,
disconnected: 4900,
chainDisconnected: 4901,
unsupportedChain: 4902
}
}, Fe = {
"-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."
}
}, Vt = "Unspecified error message.", Hn = "Unspecified server error.";
function et(t, e = Vt) {
if (t && Number.isInteger(t)) {
const n = t.toString();
if (ze(Fe, n))
return Fe[n].message;
if (Jt(t))
return Hn;
}
return e;
}
function Wn(t) {
if (!Number.isInteger(t))
return !1;
const e = t.toString();
return !!(Fe[e] || Jt(t));
}
function qn(t, { shouldIncludeStack: e = !1 } = {}) {
const n = {};
if (t && typeof t == "object" && !Array.isArray(t) && ze(t, "code") && Wn(t.code)) {
const s = t;
n.code = s.code, s.message && typeof s.message == "string" ? (n.message = s.message, ze(s, "data") && (n.data = s.data)) : (n.message = et(n.code), n.data = { originalError: ft(t) });
} else
n.code = j.rpc.internal, n.message = pt(t, "message") ? t.message : Vt, n.data = { originalError: ft(t) };
return e && (n.stack = pt(t, "stack") ? t.stack : void 0), n;
}
function Jt(t) {
return t >= -32099 && t <= -32e3;
}
function ft(t) {
return t && typeof t == "object" && !Array.isArray(t) ? Object.assign({}, t) : t;
}
function ze(t, e) {
return Object.prototype.hasOwnProperty.call(t, e);
}
function pt(t, e) {
return typeof t == "object" && t !== null && e in t && typeof t[e] == "string";
}
const P = {
rpc: {
parse: (t) => G(j.rpc.parse, t),
invalidRequest: (t) => G(j.rpc.invalidRequest, t),
invalidParams: (t) => G(j.rpc.invalidParams, t),
methodNotFound: (t) => G(j.rpc.methodNotFound, t),
internal: (t) => G(j.rpc.internal, t),
server: (t) => {
if (!t || typeof t != "object" || Array.isArray(t))
throw new Error("Ethereum RPC Server errors must provide single object argument.");
const { code: e } = t;
if (!Number.isInteger(e) || e > -32005 || e < -32099)
throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');
return G(e, t);
},
invalidInput: (t) => G(j.rpc.invalidInput, t),
resourceNotFound: (t) => G(j.rpc.resourceNotFound, t),
resourceUnavailable: (t) => G(j.rpc.resourceUnavailable, t),
transactionRejected: (t) => G(j.rpc.transactionRejected, t),
methodNotSupported: (t) => G(j.rpc.methodNotSupported, t),
limitExceeded: (t) => G(j.rpc.limitExceeded, t)
},
provider: {
userRejectedRequest: (t) => oe(j.provider.userRejectedRequest, t),
unauthorized: (t) => oe(j.provider.unauthorized, t),
unsupportedMethod: (t) => oe(j.provider.unsupportedMethod, t),
disconnected: (t) => oe(j.provider.disconnected, t),
chainDisconnected: (t) => oe(j.provider.chainDisconnected, t),
unsupportedChain: (t) => oe(j.provider.unsupportedChain, t),
custom: (t) => {
if (!t || typeof t != "object" || Array.isArray(t))
throw new Error("Ethereum Provider custom errors must provide single object argument.");
const { code: e, message: n, data: s } = t;
if (!n || typeof n != "string")
throw new Error('"message" must be a nonempty string');
return new Xt(e, n, s);
}
}
};
function G(t, e) {
const [n, s] = Qt(e);
return new Zt(t, n || et(t), s);
}
function oe(t, e) {
const [n, s] = Qt(e);
return new Xt(t, n || et(t), s);
}
function Qt(t) {
if (t) {
if (typeof t == "string")
return [t];
if (typeof t == "object" && !Array.isArray(t)) {
const { message: e, data: n } = t;
if (e && typeof e != "string")
throw new Error("Must specify string message.");
return [e || void 0, n];
}
}
return [];
}
class Zt extends Error {
constructor(e, n, s) {
if (!Number.isInteger(e))
throw new Error('"code" must be an integer.');
if (!n || typeof n != "string")
throw new Error('"message" must be a nonempty string.');
super(n), this.code = e, s !== void 0 && (this.data = s);
}
}
class Xt extends Zt {
/**
* Create an Ethereum Provider JSON-RPC error.
* `code` must be an integer in the 1000 <= 4999 range.
*/
constructor(e, n, s) {
if (!Kn(e))
throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');
super(e, n, s);
}
}
function Kn(t) {
return Number.isInteger(t) && t >= 1e3 && t <= 4999;
}
function tt() {
return (t) => t;
}
const _e = tt(), Fn = tt(), zn = tt();
function Q(t) {
return Math.floor(t);
}
const en = /^[0-9]*$/, tn = /^[a-f0-9]*$/;
function ie(t) {
return nt(crypto.getRandomValues(new Uint8Array(t)));
}
function nt(t) {
return [...t].map((e) => e.toString(16).padStart(2, "0")).join("");
}
function ve(t) {
return new Uint8Array(t.match(/.{1,2}/g).map((e) => Number.parseInt(e, 16)));
}
function he(t, e = !1) {
const n = t.toString("hex");
return _e(e ? `0x${n}` : n);
}
function Ne(t) {
return he($e(t), !0);
}
function Y(t) {
return zn(t.toString(10));
}
function ne(t) {
return _e(`0x${BigInt(t).toString(16)}`);
}
function nn(t) {
return t.startsWith("0x") || t.startsWith("0X");
}
function st(t) {
return nn(t) ? t.slice(2) : t;
}
function sn(t) {
return nn(t) ? `0x${t.slice(2)}` : `0x${t}`;
}
function xe(t) {
if (typeof t != "string")
return !1;
const e = st(t).toLowerCase();
return tn.test(e);
}
function $n(t, e = !1) {
if (typeof t == "string") {
const n = st(t).toLowerCase();
if (tn.test(n))
return _e(e ? `0x${n}` : n);
}
throw P.rpc.invalidParams(`"${String(t)}" is not a hexadecimal string`);
}
function it(t, e = !1) {
let n = $n(t, !1);
return n.length % 2 === 1 && (n = _e(`0${n}`)), e ? _e(`0x${n}`) : n;
}
function ee(t) {
if (typeof t == "string") {
const e = st(t).toLowerCase();
if (xe(e) && e.length === 40)
return Fn(sn(e));
}
throw P.rpc.invalidParams(`Invalid Ethereum address: ${String(t)}`);
}
function $e(t) {
if (Buffer.isBuffer(t))
return t;
if (typeof t == "string") {
if (xe(t)) {
const e = it(t, !1);
return Buffer.from(e, "hex");
}
return Buffer.from(t, "utf8");
}
throw P.rpc.invalidParams(`Not binary data: ${String(t)}`);
}
function fe(t) {
if (typeof t == "number" && Number.isInteger(t))
return Q(t);
if (typeof t == "string") {
if (en.test(t))
return Q(Number(t));
if (xe(t))
return Q(Number(BigInt(it(t, !0))));
}
throw P.rpc.invalidParams(`Not an integer: ${String(t)}`);
}
function le(t) {
if (t !== null && (typeof t == "bigint" || Yn(t)))
return BigInt(t.toString(10));
if (typeof t == "number")
return BigInt(fe(t));
if (typeof t == "string") {
if (en.test(t))
return BigInt(t);
if (xe(t))
return BigInt(it(t, !0));
}
throw P.rpc.invalidParams(`Not an integer: ${String(t)}`);
}
function Gn(t) {
if (typeof t == "string")
return JSON.parse(t);
if (typeof t == "object")
return t;
throw P.rpc.invalidParams(`Not a JSON string or an object: ${String(t)}`);
}
function Yn(t) {
if (t == null || typeof t.constructor != "function")
return !1;
const { constructor: e } = t;
return typeof e.config == "function" && typeof e.EUCLID == "number";
}
async function Vn() {
return crypto.subtle.generateKey({
name: "ECDH",
namedCurve: "P-256"
}, !0, ["deriveKey"]);
}
async function Jn(t, e) {
return crypto.subtle.deriveKey({
name: "ECDH",
public: e
}, t, {
name: "AES-GCM",
length: 256
}, !1, ["encrypt", "decrypt"]);
}
async function Qn(t, e) {
const n = crypto.getRandomValues(new Uint8Array(12)), s = await crypto.subtle.encrypt({
name: "AES-GCM",
iv: n
}, t, new TextEncoder().encode(e));
return { iv: n, cipherText: s };
}
async function Zn(t, { iv: e, cipherText: n }) {
const s = await crypto.subtle.decrypt({
name: "AES-GCM",
iv: e
}, t, n);
return new TextDecoder().decode(s);
}
function rn(t) {
switch (t) {
case "public":
return "spki";
case "private":
return "pkcs8";
}
}
async function an(t, e) {
const n = rn(t), s = await crypto.subtle.exportKey(n, e);
return nt(new Uint8Array(s));
}
async function on(t, e) {
const n = rn(t), s = ve(e).buffer;
return await crypto.subtle.importKey(n, new Uint8Array(s), {
name: "ECDH",
namedCurve: "P-256"
}, !0, t === "private" ? ["deriveKey"] : []);
}
async function Xn(t, e) {
const n = JSON.stringify(t, (s, r) => {
if (!(r instanceof Error))
return r;
const i = r;
return Object.assign(Object.assign({}, i.code ? { code: i.code } : {}), { message: i.message });
});
return Qn(e, n);
}
async function es(t, e) {
return JSON.parse(await Zn(e, t));
}
const Oe = {
storageKey: "ownPrivateKey",
keyType: "private"
}, De = {
storageKey: "ownPublicKey",
keyType: "public"
}, Ue = {
storageKey: "peerPublicKey",
keyType: "public"
};
class ts {
constructor() {
this.storage = new J("CBWSDK", "SCWKeyManager"), this.ownPrivateKey = null, this.ownPublicKey = null, this.peerPublicKey = null, this.sharedSecret = null;
}
async getOwnPublicKey() {
return await this.loadKeysIfNeeded(), this.ownPublicKey;
}
// returns null if the shared secret is not yet derived
async getSharedSecret() {
return await this.loadKeysIfNeeded(), this.sharedSecret;
}
async setPeerPublicKey(e) {
this.sharedSecret = null, this.peerPublicKey = e, await this.storeKey(Ue, e), await this.loadKeysIfNeeded();
}
async clear() {
this.ownPrivateKey = null, this.ownPublicKey = null, this.peerPublicKey = null, this.sharedSecret = null, this.storage.removeItem(De.storageKey), this.storage.removeItem(Oe.storageKey), this.storage.removeItem(Ue.storageKey);
}
async generateKeyPair() {
const e = await Vn();
this.ownPrivateKey = e.privateKey, this.ownPublicKey = e.publicKey, await this.storeKey(Oe, e.privateKey), await this.storeKey(De, e.publicKey);
}
async loadKeysIfNeeded() {
if (this.ownPrivateKey === null && (this.ownPrivateKey = await this.loadKey(Oe)), this.ownPublicKey === null && (this.ownPublicKey = await this.loadKey(De)), (this.ownPrivateKey === null || this.ownPublicKey === null) && await this.generateKeyPair(), this.peerPublicKey === null && (this.peerPublicKey = await this.loadKey(Ue)), this.sharedSecret === null) {
if (this.ownPrivateKey === null || this.peerPublicKey === null)
return;
this.sharedSecret = await Jn(this.ownPrivateKey, this.peerPublicKey);
}
}
// storage methods
async loadKey(e) {
const n = this.storage.getItem(e.storageKey);
return n ? on(e.keyType, n) : null;
}
async storeKey(e, n) {
const s = await an(e.keyType, n);
this.storage.setItem(e.storageKey, s);
}
}
function ns(t) {
if (!t || !Array.isArray(t) || t.length !== 1 && t.length !== 2 || typeof t[0] != "string" || !Nn(t[0]))
throw P.rpc.invalidParams();
if (t.length === 2) {
if (!Array.isArray(t[1]))
throw P.rpc.invalidParams();
for (const e of t[1])
if (typeof e != "string" || !e.startsWith("0x"))
throw P.rpc.invalidParams();
}
}
const me = "4.3.7", cn = "@coinbase/wallet-sdk";
async function rt(t, e) {
const n = Object.assign(Object.assign({}, t), { jsonrpc: "2.0", id: crypto.randomUUID() }), s = await window.fetch(e, {
method: "POST",
body: JSON.stringify(n),
mode: "cors",
headers: {
"Content-Type": "application/json",
"X-Cbw-Sdk-Version": me,
"X-Cbw-Sdk-Platform": cn
}
}), { result: r, error: i } = await s.json();
if (i)
throw i;
return r;
}
function ss() {
return globalThis.coinbaseWalletExtension;
}
function is() {
var t, e;
try {
const n = globalThis;
return (e = (t = n.top) === null || t === void 0 ? void 0 : t.ethereum) !== null && e !== void 0 ? e : n.ethereum;
} catch {
return;
}
}
function rs({ metadata: t, preference: e }) {
var n, s;
const { appName: r, appLogoUrl: i, appChainIds: a } = t;
if (e.options !== "smartWalletOnly") {
const h = ss();
if (h)
return (n = h.setAppInfo) === null || n === void 0 || n.call(h, r, i, a, e), h;
}
const o = is();
if (o?.isCoinbaseBrowser)
return (s = o.setAppInfo) === null || s === void 0 || s.call(o, r, i, a, e), o;
}
function as(t) {
if (!t || typeof t != "object" || Array.isArray(t))
throw P.rpc.invalidParams({
message: "Expected a single, non-array, object argument.",
data: t
});
const { method: e, params: n } = t;
if (typeof e != "string" || e.length === 0)
throw P.rpc.invalidParams({
message: "'args.method' must be a non-empty string.",
data: t
});
if (n !== void 0 && !Array.isArray(n) && (typeof n != "object" || n === null))
throw P.rpc.invalidParams({
message: "'args.params' must be an object or array if provided.",
data: t
});
switch (e) {
case "eth_sign":
case "eth_signTypedData_v2":
case "eth_subscribe":
case "eth_unsubscribe":
throw P.provider.unsupportedMethod();
}
}
const gt = "accounts", _t = "activeChain", mt = "availableChains", yt = "walletCapabilities";
class os {
constructor(e) {
var n, s, r;
this.metadata = e.metadata, this.communicator = e.communicator, this.callback = e.callback, this.keyManager = new ts(), this.storage = new J("CBWSDK", "SCWStateManager"), this.accounts = (n = this.storage.loadObject(gt)) !== null && n !== void 0 ? n : [], this.chain = this.storage.loadObject(_t) || {
id: (r = (s = e.metadata.appChainIds) === null || s === void 0 ? void 0 : s[0]) !== null && r !== void 0 ? r : 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 n, s, r, i;
await ((s = (n = this.communicator).waitForPopupLoaded) === null || s === void 0 ? void 0 : s.call(n));
const a = await this.createRequestMessage({
handshake: {
method: e.method,
params: Object.assign({}, this.metadata, (r = e.params) !== null && r !== void 0 ? r : {})
}
}), o = await this.communicator.postRequestAndWaitForResponse(a);
if ("failure" in o.content)
throw o.content.failure;
const h = await on("public", o.sender);
await this.keyManager.setPeerPublicKey(h);
const g = (await this.decryptResponseMessage(o)).result;
if ("error" in g)
throw g.error;
if (e.method === "eth_requestAccounts") {
const d = g.value;
this.accounts = d, this.storage.storeObject(gt, d), (i = this.callback) === null || i === void 0 || i.call(this, "accountsChanged", d);
}
}
async request(e) {
var n;
if (this.accounts.length === 0) {
if (e.method === "wallet_sendCalls")
return this.sendRequestToPopup(e);
throw P.provider.unauthorized();
}
switch (e.method) {
case "eth_requestAccounts":
return (n = this.callback) === null || n === void 0 || n.call(this, "connect", { chainId: ne(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 ne(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 P.rpc.internal("No RPC URL set for chain");
return rt(e, this.chain.rpcUrl);
}
}
async sendRequestToPopup(e) {
var n, s;
await ((s = (n = this.communicator).waitForPopupLoaded) === null || s === void 0 ? void 0 : s.call(n));
const r = await this.sendEncryptedRequest(e), a = (await this.decryptResponseMessage(r)).result;
if ("error" in a)
throw a.error;
return a.value;
}
async cleanup() {
var e, n;
this.storage.clear(), await this.keyManager.clear(), this.accounts = [], this.chain = {
id: (n = (e = this.metadata.appChainIds) === null || e === void 0 ? void 0 : e[0]) !== null && n !== void 0 ? n : 1
};
}
/**
* @returns `null` if the request was successful.
* https://eips.ethereum.org/EIPS/eip-3326#wallet_switchethereumchain
*/
async handleSwitchChainRequest(e) {
var n;
const s = e.params;
if (!s || !(!((n = s[0]) === null || n === void 0) && n.chainId))
throw P.rpc.invalidParams();
const r = fe(s[0].chainId);
if (this.updateChain(r))
return null;
const a = await this.sendRequestToPopup(e);
return a === null && this.updateChain(r), a;
}
async handleGetCapabilitiesRequest(e) {
ns(e.params);
const n = e.params[0], s = e.params[1];
if (!this.accounts.some((o) => On(o, n)))
throw P.provider.unauthorized("no active account found");
const r = this.storage.loadObject(yt);
if (!r)
return {};
if (!s || s.length === 0)
return r;
const i = new Set(s.map((o) => ht(o)));
return Object.fromEntries(Object.entries(r).filter(([o]) => {
try {
const h = ht(o);
return i.has(h);
} catch {
return !1;
}
}));
}
async sendEncryptedRequest(e) {
const n = await this.keyManager.getSharedSecret();
if (!n)
throw P.provider.unauthorized("No valid session found, try requestAccounts before other methods");
const s = await Xn({
action: e,
chainId: this.chain.id
}, n), r = await this.createRequestMessage({ encrypted: s });
return this.communicator.postRequestAndWaitForResponse(r);
}
async createRequestMessage(e) {
const n = await an("public", await this.keyManager.getOwnPublicKey());
return {
id: crypto.randomUUID(),
sender: n,
content: e,
timestamp: /* @__PURE__ */ new Date()
};
}
async decryptResponseMessage(e) {
var n, s;
const r = e.content;
if ("failure" in r)
throw r.failure;
const i = await this.keyManager.getSharedSecret();
if (!i)
throw P.provider.unauthorized("Invalid session");
const a = await es(r.encrypted, i), o = (n = a.data) === null || n === void 0 ? void 0 : n.chains;
if (o) {
const u = Object.entries(o).map(([g, d]) => ({
id: Number(g),
rpcUrl: d
}));
this.storage.storeObject(mt, u), this.updateChain(this.chain.id, u);
}
const h = (s = a.data) === null || s === void 0 ? void 0 : s.capabilities;
return h && this.storage.storeObject(yt, h), a;
}
updateChain(e, n) {
var s;
const r = n ?? this.storage.loadObject(mt), i = r?.find((a) => a.id === e);
return i ? (i !== this.chain && (this.chain = i, this.storage.storeObject(_t, i), (s = this.callback) === null || s === void 0 || s.call(this, "chainChanged", ne(i.id))), !0) : !1;
}
}
var T = {}, A = {}, bt;
function cs() {
if (bt) return A;
bt = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.toBig = A.shrSL = A.shrSH = A.rotrSL = A.rotrSH = A.rotrBL = A.rotrBH = A.rotr32L = A.rotr32H = A.rotlSL = A.rotlSH = A.rotlBL = A.rotlBH = A.add5L = A.add5H = A.add4L = A.add4H = A.add3L = A.add3H = void 0, A.add = v, A.fromBig = n, A.split = s;
const t = /* @__PURE__ */ BigInt(2 ** 32 - 1), e = /* @__PURE__ */ BigInt(32);
function n(m, _ = !1) {
return _ ? { h: Number(m & t), l: Number(m >> e & t) } : { h: Number(m >> e & t) | 0, l: Number(m & t) | 0 };
}
function s(m, _ = !1) {
const b = m.length;
let U = new Uint32Array(b), W = new Uint32Array(b);
for (let q = 0; q < b; q++) {
const { h: re, l: ae } = n(m[q], _);
[U[q], W[q]] = [re, ae];
}
return [U, W];
}
const r = (m, _) => BigInt(m >>> 0) << e | BigInt(_ >>> 0);
A.toBig = r;
const i = (m, _, b) => m >>> b;
A.shrSH = i;
const a = (m, _, b) => m << 32 - b | _ >>> b;
A.shrSL = a;
const o = (m, _, b) => m >>> b | _ << 32 - b;
A.rotrSH = o;
const h = (m, _, b) => m << 32 - b | _ >>> b;
A.rotrSL = h;
const u = (m, _, b) => m << 64 - b | _ >>> b - 32;
A.rotrBH = u;
const g = (m, _, b) => m >>> b - 32 | _ << 64 - b;
A.rotrBL = g;
const d = (m, _) => _;
A.rotr32H = d;
const l = (m, _) => m;
A.rotr32L = l;
const c = (m, _, b) => m << b | _ >>> 32 - b;
A.rotlSH = c;
const p = (m, _, b) => _ << b | m >>> 32 - b;
A.rotlSL = p;
const S = (m, _, b) => _ << b - 32 | m >>> 64 - b;
A.rotlBH = S;
const w = (m, _, b) => m << b - 32 | _ >>> 64 - b;
A.rotlBL = w;
function v(m, _, b, U) {
const W = (_ >>> 0) + (U >>> 0);
return { h: m + b + (W / 2 ** 32 | 0) | 0, l: W | 0 };
}
const E = (m, _, b) => (m >>> 0) + (_ >>> 0) + (b >>> 0);
A.add3L = E;
const L = (m, _, b, U) => _ + b + U + (m / 2 ** 32 | 0) | 0;
A.add3H = L;
const k = (m, _, b, U) => (m >>> 0) + (_ >>> 0) + (b >>> 0) + (U >>> 0);
A.add4L = k;
const y = (m, _, b, U, W) => _ + b + U + W + (m / 2 ** 32 | 0) | 0;
A.add4H = y;
const C = (m, _, b, U, W) => (m >>> 0) + (_ >>> 0) + (b >>> 0) + (U >>> 0) + (W >>> 0);
A.add5L = C;
const x = (m, _, b, U, W, q) => _ + b + U + W + q + (m / 2 ** 32 | 0) | 0;
A.add5H = x;
const M = {
fromBig: n,
split: s,
toBig: r,
shrSH: i,
shrSL: a,
rotrSH: o,
rotrSL: h,
rotrBH: u,
rotrBL: g,
rotr32H: d,
rotr32L: l,
rotlSH: c,
rotlSL: p,
rotlBH: S,
rotlBL: w,
add: v,
add3L: E,
add3H: L,
add4L: k,
add4H: y,
add5H: x,
add5L: C
};
return A.default = M, A;
}
var je = {}, ue = {}, wt;
function ds() {
return wt || (wt = 1, Object.defineProperty(ue, "__esModule", { value: !0 }), ue.crypto = void 0, ue.crypto = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0), ue;
}
var vt;
function ls() {
return vt || (vt = 1, (function(t) {
Object.defineProperty(t, "__esModule", { value: !0 }), t.wrapXOFConstructorWithOpts = t.wrapConstructorWithOpts = t.wrapConstructor = t.Hash = t.nextTick = t.swap32IfBE = t.byteSwapIfBE = t.swap8IfBE = t.isLE = void 0, t.isBytes = n, t.anumber = s, t.abytes = r, t.ahash = i, t.aexists = a, t.aoutput = o, t.u8 = h, t.u32 = u, t.clean = g, t.createView = d, t.rotr = l, t.rotl = c, t.byteSwap = p, t.byteSwap32 = S, t.bytesToHex = E, t.hexToBytes = y, t.asyncLoop = x, t.utf8ToBytes = M, t.bytesToUtf8 = m, t.toBytes = _, t.kdfInputToBytes = b, t.concatBytes = U, t.checkOpts = W, t.createHasher = re, t.createOptHasher = ae, t.createXOFer = se, t.randomBytes = Rn;
const e = /* @__PURE__ */ ds();
function n(f) {
return f instanceof Uint8Array || ArrayBuffer.isView(f) && f.constructor.name === "Uint8Array";
}
function s(f) {
if (!Number.isSafeInteger(f) || f < 0)
throw new Error("positive integer expected, got " + f);
}
function r(f, ...I) {
if (!n(f))
throw new Error("Uint8Array expected");
if (I.length > 0 && !I.includes(f.length))
throw new Error("Uint8Array expected of length " + I + ", got length=" + f.length);
}
function i(f) {
if (typeof f != "function" || typeof f.create != "function")
throw new Error("Hash should be wrapped by utils.createHasher");
s(f.outputLen), s(f.blockLen);
}
function a(f, I = !0) {
if (f.destroyed)
throw new Error("Hash instance has been destroyed");
if (I && f.finished)
throw new Error("Hash#digest() has already been called");
}
function o(f, I) {
r(f);
const O = I.outputLen;
if (f.length < O)
throw new Error("digestInto() expects output buffer of length at least " + O);
}
function h(f) {
return new Uint8Array(f.buffer, f.byteOffset, f.byteLength);
}
function u(f) {
return new Uint32Array(f.buffer, f.byteOffset, Math.floor(f.byteLength / 4));
}
function g(...f) {
for (let I = 0; I < f.length; I++)
f[I].fill(0);
}
function d(f) {
return new DataView(f.buffer, f.byteOffset, f.byteLength);
}
function l(f, I) {
return f << 32 - I | f >>> I;
}
function c(f, I) {
return f << I | f >>> 32 - I >>> 0;
}
t.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
function p(f) {
return f << 24 & 4278190080 | f << 8 & 16711680 | f >>> 8 & 65280 | f >>> 24 & 255;
}
t.swap8IfBE = t.isLE ? (f) => f : (f) => p(f), t.byteSwapIfBE = t.swap8IfBE;
function S(f) {
for (let I = 0; I < f.length; I++)
f[I] = p(f[I]);
return f;
}
t.swap32IfBE = t.isLE ? (f) => f : S;
const w = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", v = /* @__PURE__ */ Array.from({ length: 256 }, (f, I) => I.toString(16).padStart(2, "0"));
function E(f) {
if (r(f), w)
return f.toHex();
let I = "";
for (let O = 0; O < f.length; O++)
I += v[f[O]];
return I;
}
const L = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
function k(f) {
if (f >= L._0 && f <= L._9)
return f - L._0;
if (f >= L.A && f <= L.F)
return f - (L.A - 10);
if (f >= L.a && f <= L.f)
return f - (L.a - 10);
}
function y(f) {
if (typeof f != "string")
throw new Error("hex string expected, got " + typeof f);
if (w)
return Uint8Array.fromHex(f);
const I = f.length, O = I / 2;
if (I % 2)
throw new Error("hex string expected, got unpadded hex of length " + I);
const D = new Uint8Array(O);
for (let K = 0, z = 0; K < O; K++, z += 2) {
const lt = k(f.charCodeAt(z)), ut = k(f.charCodeAt(z + 1));
if (lt === void 0 || ut === void 0) {
const Tn = f[z] + f[z + 1];
throw new Error('hex string expected, got non-hex character "' + Tn + '" at index ' + z);
}
D[K] = lt * 16 + ut;
}
return D;
}
const C = async () => {
};
t.nextTick = C;
async function x(f, I, O) {
let D = Date.now();
for (let K = 0; K < f; K++) {
O(K);
const z = Date.now() - D;
z >= 0 && z < I || (await (0, t.nextTick)(), D += z);
}
}
function M(f) {
if (typeof f != "string")
throw new Error("string expected");
return new Uint8Array(new TextEncoder().encode(f));
}
function m(f) {
return new TextDecoder().decode(f);
}
function _(f) {
return typeof f == "string" && (f = M(f)), r(f), f;
}
function b(f) {
return typeof f == "string" && (f = M(f)), r(f), f;
}
function U(...f) {
let I = 0;
for (let D = 0; D < f.length; D++) {
const K = f[D];
r(K), I += K.length;
}
const O = new Uint8Array(I);
for (let D = 0, K = 0; D < f.length; D++) {
const z = f[D];
O.set(z, K), K += z.length;
}
return O;
}
function W(f, I) {
if (I !== void 0 && {}.toString.call(I) !== "[object Object]")
throw new Error("options should be object or undefined");
return Object.assign(f, I);
}
class q {
}
t.Hash = q;
function re(f) {
const I = (D) => f().update(_(D)).digest(), O = f();
return I.outputLen = O.outputLen, I.blockLen = O.blockLen, I.create = () => f(), I;
}
function ae(f) {
const I = (D, K) => f(K).update(_(D)).digest(), O = f({});
return I.outputLen = O.outputLen, I.blockLen = O.blockLen, I.create = (D) => f(D), I;
}
function se(f) {
const I = (D, K) => f(K).update(_(D)).digest(), O = f({});
return I.outputLen = O.outputLen, I.blockLen = O.blockLen, I.create = (D) => f(D), I;
}
t.wrapConstructor = re, t.wrapConstructorWithOpts = ae, t.wrapXOFConstructorWithOpts = se;
function Rn(f = 32) {
if (e.crypto && typeof e.crypto.getRandomValues == "function")
return e.crypto.getRandomValues(new Uint8Array(f));
if (e.crypto && typeof e.crypto.randomBytes == "function")
return Uint8Array.from(e.crypto.randomBytes(f));
throw new Error("crypto.getRandomValues must be defined");
}
})(je)), je;
}
var kt;
function us() {
if (kt) return T;
kt = 1, 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 = w;
const t = /* @__PURE__ */ cs(), e = /* @__PURE__ */ ls(), n = BigInt(0), s = BigInt(1), r = BigInt(2), i = BigInt(7), a = BigInt(256), o = BigInt(113), h = [], u = [], g = [];
for (let k = 0, y = s, C = 1, x = 0; k < 24; k++) {
[C, x] = [x, (2 * C + 3 * x) % 5], h.push(2 * (5 * x + C)), u.push((k + 1) * (k + 2) / 2 % 64);
let M = n;
for (let m = 0; m < 7; m++)
y = (y << s ^ (y >> i) * o) % a, y & r && (M ^= s << (s << /* @__PURE__ */ BigInt(m)) - s);
g.push(M);
}
const d = (0, t.split)(g, !0), l = d[0], c = d[1], p = (k, y, C) => C > 32 ? (0, t.rotlBH)(k, y, C) : (0, t.rotlSH)(k, y, C), S = (k, y, C) => C > 32 ? (0, t.rotlBL)(k, y, C) : (0, t.rotlSL)(k, y, C);
function w(k, y = 24) {
const C = new Uint32Array(10);
for (let x = 24 - y; x < 24; x++) {
for (let _ = 0; _ < 10; _++)
C[_] = k[_] ^ k[_ + 10] ^ k[_ + 20] ^ k[_ + 30] ^ k[_ + 40];
for (let _ = 0; _ < 10; _ += 2) {
const b = (_ + 8) % 10, U = (_ + 2) % 10, W = C[U], q = C[U + 1], re = p(W, q, 1) ^ C[b], ae = S(W, q, 1) ^ C[b + 1];
for (let se = 0; se < 50; se += 10)
k[_ + se] ^= re, k[_ + se + 1] ^= ae;
}
let M = k[2], m = k[3];
for (let _ = 0; _ < 24; _++) {
const b = u[_], U = p(M, m, b), W = S(M, m, b), q = h[_];
M = k[q], m = k[q + 1], k[q] = U, k[q + 1] = W;
}
for (let _ = 0; _ < 50; _ += 10) {
for (let b = 0; b < 10; b++)
C[b] = k[_ + b];
for (let b = 0; b < 10; b++)
k[_ + b] ^= ~C[(b + 2) % 10] & C[(b + 4) % 10];
}
k[0] ^= l[x], k[1] ^= c[x];
}
(0, e.clean)(C);
}
class v extends e.Hash {
// NOTE: we accept arguments in bytes instead of bits here.
constructor(y, C, x, M = !1, m = 24) {
if (super(), this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, this.enableXOF = !1, this.blockLen = y, this.suffix = C, this.outputLen = x, this.enableXOF = M, this.rounds = m, (0, e.anumber)(x), !(0 < y && y < 200))
throw new Error("only keccak-f1600 function is supported");
this.state = new Uint8Array(200), this.state32 = (0, e.u32)(this.state);
}
clone() {
return this._cloneInto();
}
keccak() {
(0, e.swap32IfBE)(this.state32), w(this.state32, this.rounds), (0, e.swap32IfBE)(this.state32), this.posOut = 0, this.pos = 0;
}
update(y) {
(0, e.aexists)(this), y = (0, e.toBytes)(y), (0, e.abytes)(y);
const { blockLen: C, state: x } = this, M = y.length;
for (let m = 0; m < M; ) {
const _ = Math.min(C - this.pos, M - m);
for (let b = 0; b < _; b++)
x[this.pos++] ^= y[m++];
this.pos === C && this.keccak();
}
return this;
}
finish() {
if (this.finished)
return;
this.finished = !0;
const { state: y, suffix: C, pos: x, blockLen: M } = this;
y[x] ^= C, (C & 128) !== 0 && x === M - 1 && this.keccak(), y[M - 1] ^= 128, this.keccak();
}
writeInto(y) {
(0, e.aexists)(this, !1), (0, e.abytes)(y), this.finish();
const C = this.state, { blockLen: x } = this;
for (let M = 0, m = y.length; M < m; ) {
this.posOut >= x && this.keccak();
const _ = Math.min(x - this.posOut, m - M);
y.set(C.subarray(this.posOut, this.posOut + _), M), this.posOut += _, M += _;
}
return y;
}
xofInto(y) {
if (!this.enableXOF)
throw new Error("XOF is not possible for this instance");
return this.writeInto(y);
}
xof(y) {
return (0, e.anumber)(y), this.xofInto(new Uint8Array(y));
}
digestInto(y) {
if ((0, e.aoutput)(y, this), this.finished)
throw new Error("digest() was already called");
return this.writeInto(y), this.destroy(), y;
}
digest() {
return this.digestInto(new Uint8Array(this.outputLen));
}
destroy() {
this.destroyed = !0, (0, e.clean)(this.state);
}
_cloneInto(y) {
const { blockLen: C, suffix: x, outputLen: M, rounds: m, enableXOF: _ } = this;
return y || (y = new v(C, x, M, _, m)), y.state32.set(this.state32), y.pos = this.pos, y.posOut = this.posOut, y.finished = this.finished, y.rounds = m, y.suffix = x, y.outputLen = M, y.enableXOF = _, y.destroyed = this.destroyed, y;
}
}
T.Keccak = v;
const E = (k, y, C) => (0, e.createHasher)(() => new v(y, k, C));
T.sha3_224 = E(6, 144, 224 / 8), T.sha3_256 = E(6, 136, 256 / 8), T.sha3_384 = E(6, 104, 384 / 8), T.sha3_512 = E(6, 72, 512 / 8), T.keccak_224 = E(1, 144, 224 / 8), T.keccak_256 = E(1, 136, 256 / 8), T.keccak_384 = E(1, 104, 384 / 8), T.keccak_512 = E(1, 72, 512 / 8);
const L = (k, y, C) => (0, e.createXOFer)((x = {}) => new v(y, k, x.dkLen === void 0 ? C : x.dkLen, !0));
return T.shake128 = L(31, 168, 128 / 8), T.shake256 = L(31, 136, 256 / 8), T;
}
var Be, Et;
function dn() {
if (Et) return Be;
Et = 1;
const { keccak_256: t } = /* @__PURE__ */ us();
function e(c) {
return Buffer.allocUnsafe(c).fill(0);
}
function n(c) {
return c.toString(2).length;
}
function s(c, p) {
let S = c.toString(16);
S.length % 2 !== 0 && (S = "0" + S);
const w = S.match(/.{1,2}/g).map((v) => parseInt(v, 16));
for (; w.length < p; )
w.unshift(0);
return Buffer.from(w);
}
function r(c, p) {
const S = c < 0n;
let w;
if (S) {
const v = (1n << BigInt(p)) - 1n;
w = (~c & v) + 1n;
} else
w = c;
return w &= (1n << BigInt(p)) - 1n, w;
}
function i(c, p, S) {
const w = e(p);
return c = o(c), S ? c.length < p ? (c.copy(w), w) : c.slice(0, p) : c.length < p ? (c.copy(w, p - c.length), w) : c.slice(-p);
}
function a(c, p) {
return i(c, p, !0);
}
function o(c) {
if (!Buffer.isBuffer(c))
if (Array.isArray(c))
c = Buffer.from(c);
else if (typeof c == "string")
d(c) ? c = Buffer.from(g(l(c)), "hex") : c = Buffer.from(c);
else if (typeof c == "number")
c = intToBuffer(c);
else if (c == null)
c = Buffer.allocUnsafe(0);
else if (typeof c == "bigint")
c = s(c);
else if (c.toArray)
c = Buffer.from(c.toArray());
else
throw new Error("invalid type");
return c;
}
function h(c) {
return c = o(c), "0x" + c.toString("hex");
}
function u(c, p) {
if (c = o(c), p || (p = 256), p !== 256)
throw new Error("unsupported");
return Buffer.from(t(new Uint8Array(c)));
}
function g(c) {
return c.length % 2 ? "0" + c : c;
}
function d(c) {
return typeof c == "string" && c.match(/^0x[0-9A-Fa-f]*$/);
}
function l(c) {
return typeof c == "string" && c.startsWith("0x") ? c.slice(2) : c;
}
return Be = {
zeros: e,
setLength: i,
setLengthRight: a,
isHexString: d,
stripHexPrefix: l,
toBuffer: o,
bufferToHex: h,
keccak: u,
bitLengthFromBigInt: n,
bufferBEFromBigInt: s,
twosFromBigInt: r
}, Be;
}
var He, It;
function hs() {
if (It) return He;
It = 1;
const t = /* @__PURE__ */ dn();
function e(l) {
return l.startsWith("int[") ? "int256" + l.slice(3) : l === "int" ? "int256" : l.startsWith("uint[") ? "uint256" + l.slice(4) : l === "uint" ? "uint256" : l.startsWith("fixed[") ? "fixed128x128" + l.slice(5) : l === "fixed" ? "fixed128x128" : l.startsWith("ufixed[") ? "ufixed128x128" + l.slice(6) : l === "ufixed" ? "ufixed128x128" : l;
}
function n(l) {
return Number.parseInt(/^\D+(\d+)$/.exec(l)[1], 10);
}
function s(l) {
var c = /^\D+(\d+)x(\d+)$/.exec(l);
return [Number.parseInt(c[1], 10), Number.parseInt(c[2], 10)];
}
function r(l) {
var c = l.match(/(.*)\[(.*?)\]$/);
return c ? c[2] === "" ? "dynamic" : Number.parseInt(c[2], 10) : null;
}
function i(l) {
var c = typeof l;
if (c === "string" || c === "number")
return BigInt(l);
if (c === "bigint")
return l;
throw new Error("Argument is not a number");
}
function a(l, c) {
var p, S, w, v;
if (l === "address")
return a("uint160", i(c));
if (l === "bool")
return a("uint8", c ? 1 : 0);
if (l === "string")
return a("bytes", new Buffer(c, "utf8"));
if (h(l)) {
if (typeof c.length > "u")
throw new Error("Not an array?");
if (p = r(l), p !== "dynamic" && p !== 0 && c.length > p)
throw new Error("Elements exceed array size: " + p);
w = [], l = l.slice(0, l.lastIndexOf("[")), typeof c == "string" && (c = JSON.parse(c));
for (v in c)
w.push(a(l, c[v]));
if (p === "dynamic") {
var E = a("uint256", c.length);
w.unshift(E);
}
return Buffer.concat(w);
} else {
if (l === "bytes")
return c = new Buffer(c), w = Buffer.concat([a("uint256", c.length), c]), c.length % 32 !== 0 && (w = Buffer.concat([w, t.zeros(32 - c.length % 32)])), w;
if (l.startsWith("bytes")) {
if (p = n(l), p < 1 || p > 32)
throw new Error("Invalid bytes<N> width: " + p);
return t.setLengthRight(c, 32);
} else if (l.startsWith("uint")) {
if (p = n(l), p % 8 || p < 8 || p > 256)
throw new Error("Invalid uint<N> width: " + p);
S = i(c);
const L = t.bitLengthFromBigInt(S);
if (L > p)
throw new Error("Supplied uint exceeds width: " + p + " vs " + L);
if (S < 0)
throw new Error("Supplied uint is negative");
return t.bufferBEFromBigInt(S, 32);
} else if (l.startsWith("int")) {
if (p = n(l), p % 8 || p < 8 || p > 256)
throw new Error("Invalid int<N> width: " + p);
S = i(c);
const L = t.bitLengthFromBigInt(S);
if (L > p)
throw new Error("Supplied int exceeds width: " + p + " vs " + L);
const k = t.twosFromBigInt(S, 256);
return t.bufferBEFromBigInt(k, 32);
} else if (l.startsWith("ufixed")) {
if (p = s(l), S = i(c), S < 0)
throw new Error("Supplied ufixed is negative");
return a("uint256", S * BigInt(2) ** BigInt(p[1]));
} else if (l.startsWith("fixed"))
return p = s(l), a("int256", i(c) * BigInt(2) ** BigInt(p[1]));
}
throw new Error("Unsupported or invalid type: " + l);
}
function o(l) {
return l === "string" || l === "bytes" || r(l) === "dynamic";
}
function h(l) {
return l.lastIndexOf("]") === l.length - 1;
}
function u(l, c) {
var p = [], S = [], w = 32 * l.length;
for (var v in l) {
var E = e(l[v]), L = c[v], k = a(E, L);
o(E) ? (p.push(a("uint256", w)), S.push(k), w += k.length) : p.push(k);
}
return Buffer.concat(p.concat(S));
}
function g(l, c) {
if (l.length !== c.length)
throw new Error("Number of types are not matching the values");
for (var p, S, w = [], v = 0; v < l.length; v++) {
var E = e(l[v]), L = c[v];
if (E === "bytes")
w.push(L);
else if (E === "string")
w.push(new Buffer(L, "utf8"));
else if (E === "bool")
w.push(new Buffer(L ? "01" : "00", "hex"));
else if (E === "address")
w.push(t.setLength(L, 20));
else if (E.startsWith("bytes")) {
if (p = n(E), p < 1 || p > 32)
throw new Error("Invalid bytes<N> width: " + p);
w.push(t.setLengthRight(L, p));
} else if (E.startsWith("uint")) {
if (p = n(E), p % 8 || p < 8 || p > 256)
throw new Error("Invalid uint<N> width: " + p);
S = i(L);
const k = t.bitLengthFromBigInt(S);
if (k > p)
throw new Error("Supplied uint exceeds width: " + p + " vs " + k);
w.push(t.bufferBEFromBigInt(S, p / 8));
} else if (E.startsWith("int")) {
if (p = n(E), p % 8 || p < 8 || p > 256)
throw new Error("Invalid int<N> width: " + p);
S = i(L);
const k = t.bitLengthFromBigInt(S);
if (k > p)
throw new Error("Supplied int exceeds width: " + p + " vs " + k);
const y = t.twosFromBigInt(S, p);
w.push(t.bufferBEFromBigInt(y, p / 8));
} else
throw new Error("Unsupported or invalid type: " + E);
}
return Buffer.concat(w);
}
function d(l, c) {
return t.keccak(g(l, c));
}
return He = {
rawEncode: u,
solidityPack: g,
soliditySHA3: d
}, He;
}
var We, St;
function fs() {
if (St) return We;
St = 1;
const t = /* @__PURE__ */ dn(), e = /* @__PURE__ */ hs(), n = {
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"]
}, s = {
/**
* Encodes an object by encoding and concatenating each of its members
*
* @param {string} primaryType - Root type
* @param {Object} data - Object to encode
* @param {Object} types - Type definitions
* @returns {string} - Encoded representation of an object
*/
encodeData(i, a, o, h = !0) {
const u = ["bytes32"], g = [this.hashType(i, o)];
if (h) {
const d = (l, c, p) => {
if (o[c] !== void 0)
return ["bytes32", p == null ? "0x0000000000000000000000000000000000000000000000000000000000000000" : t.keccak(this.encodeData(c, p, o, h))];
if (p === void 0)
throw new Error(`missing value for field ${l} of type ${c}`);
if (c === "bytes")
return ["bytes32", t.keccak(p)];
if (c === "string")
return typeof p == "string" && (p = Buffer.from(p, "utf8")), ["bytes32", t.keccak(p)];
if (c.lastIndexOf("]") === c.length - 1) {
const S = c.slice(0, c.lastIndexOf("[")), w = p.map((v) => d(l, S, v));
return ["bytes32", t.keccak(e.rawEncode(
w.map(([v]) => v),
w.map(([, v]) => v)
))];
}
return [c, p];
};
for (const l of o[i]) {
const [c, p] = d(l.name, l.type, a[l.name]);
u.push(c), g.push(p);
}
} else
for (const d of o[i]) {
let l = a[d.name];
if (l !== void 0)
if (d.type === "bytes")
u.push("bytes32"), l = t.keccak(l), g.push(l);
else if (d.type === "string")
u.push("bytes32"), typeof l == "string" && (l = Buffer.from(l, "utf8")), l = t.keccak(l), g.push(l);
else if (o[d.type] !== void 0)
u.push("bytes32"), l = t.keccak(this.encodeData(d.type, l, o, h)), g.push(l);
else {
if (d.type.lastIndexOf("]") === d.type.length - 1)
throw new Error("Arrays currently unimplemented in encodeData");
u.push(d.type), g.push(l);
}
}
return e.rawEncode(u, g);
},
/**
* Encodes the type of an object by encoding a comma delimited list of its members
*
* @param {string} primaryType - Root type to encode
* @param {Object} types - Type definitions
* @returns {string} - Encoded representation of the type of an object
*/
encodeType(i, a) {
let o = "", h = this.findTypeDependencies(i, a).filter((u) => u !== i);
h = [i].concat(h.sort());
for (const u of h) {
if (!a[u])
throw new Error("No type definition specified: " + u);
o += u + "(" + a[u].map(({ name: d, type: l }) => l + " " + d).join(",") + ")";
}
return o;
},
/**
* Finds all types within a type definition object
*
* @param {string} primaryType - Root type
* @param {Object} types - Type definitions
* @param {Array} results - current set of accumulated types
* @returns {Array} - Set of all types found in the type definition
*/
findTypeDependencies(i, a, o = []) {
if (i = i.match(/^\w*/)[0], o.includes(i) || a[i] === void 0)
return o;
o.push(i);
for (const h of a[i])
for (const u of this.findTypeDependencies(h.type, a, o))
!o.includes(u) && o.push(u);
return o;
},
/**
* Hashes an object
*
* @param {string} primaryType - Root type
* @param {Object} data - Object to hash
* @param {Object} types - Type definitions
* @returns {Buffer} - Hash of an object
*/
hashStruct(i, a, o, h = !0) {
return t.keccak(this.encodeData(i, a, o, h));
},
/**
* Hashes the type of an object
*
* @param {string} primaryType - Root type to hash
* @param {Object} types - Type definitions
* @returns {string} - Hash of an object
*/
hashType(i, a) {
return t.keccak(this.encodeType(i, a));
},
/**
* Removes properties from a message object that are not defined per EIP-712
*
* @param {Object} data - typed message object
* @returns {Object} - typed message object with only allowed fields
*/
sanitizeData(i) {
const a = {};
for (const o in n.properties)
i[o] && (a[o] = i[o]);
return a.types && (a.types = Object.assign({ EIP712Domain: [] }, a.types)), a;
},
/**
* Returns the hash of a typed message as per EIP-712 for signing
*
* @param {Object} typedData - Types message data to sign
* @returns {string} - sha3 hash for signing
*/
hash(i, a = !0) {
const o = this.sanitizeData(i), h = [Buffer.from("1901", "hex")];
return h.push(this.hashStruct("EIP712Domain", o.domain, o.types, a)), o.primaryType !== "EIP712Domain" && h.push(this.hashStruct(o.primaryType, o.message, o.types, a)), t.keccak(Buffer.concat(h));
}
};
We = {
TYPED_MESSAGE_SCHEMA: n,
TypedDataUtils: s,
hashForSignTypedDataLegacy: function(i) {
return r(i.data);
},
hashForSignTypedData_v3: function(i) {
return s.hash(i.data, !1);
},
hashForSignTypedData_v4: function(i) {
return s.hash(i.data);
}
};
function r(i) {
const a = new Error("Expect argument to be non-empty array");
if (typeof i != "object" || !i.length) throw a;
const o = i.map(function(g) {
return g.type === "bytes" ? t.toBuffer(g.value) : g.value;
}), h = i.map(function(g) {
return g.type;
}), u = i.map(function(g) {
if (!g.name) throw a;
return g.type + " " + g.name;
});
return e.soliditySHA3(
["bytes32", "bytes32"],
[
e.soliditySHA3(new Array(i.length).fill("string"), u),
e.soliditySHA3(h, o)
]
);
}
return We;
}
var ps = /* @__PURE__ */ fs();
const ye = /* @__PURE__ */ Dn(ps), gs = "walletUsername", Ge = "Addresses", _s = "AppVersion";
function F(t) {
return t.errorMessage !== void 0;
}
class ms {
// @param secret hex representation of 32-byte secret
constructor(e) {
this.secret = e;
}
/**
*
* @param plainText string to be encrypted
* returns hex string representation of bytes in the order: initialization vector (iv),
* auth tag, encrypted plaintext. IV is 12 bytes. Auth tag is 16 bytes. Remaining bytes are the
* encrypted plainText.
*/
async encrypt(e) {
const n = this.secret;
if (n.length !== 64)
throw Error("secret must be 256 bits");
const s = crypto.getRandomValues(new Uint8Array(12)), r = await crypto.subtle.importKey("raw", ve(n), { name: "aes-gcm" }, !1, ["encrypt", "decrypt"]), i = new TextEncoder(), a = await window.crypto.subtle.encrypt({
name: "AES-GCM",
iv: s
}, r, i.encode(e)), o = 16, h = a.slice(a.byteLength - o), u = a.slice(0, a.byteLength - o), g = new Uint8Array(h), d = new Uint8Array(u), l = new Uint8Array([...s, ...g, ...d]);
return nt(l);
}
/**
*
* @param cipherText hex string representation of bytes in the order: initialization vector (iv),
* auth tag, encrypted plaintext. IV is 12 bytes. Auth tag is 16 bytes.
*/
async decrypt(e) {
const n = this.secret;
if (n.length !== 64)
throw Error("secret must be 256 bits");
return new Promise((s, r) => {
(async function() {
const i = await crypto.subtle.importKey("raw", ve(n), { name: "aes-gcm" }, !1, ["encrypt", "decrypt"]), a = ve(e), o = a.slice(0, 12), h = a.slice(12, 28), u = a.slice(28), g = new Uint8Array([...u, ...h]), d = {
name: "AES-GCM",
iv: new Uint8Array(o)
};
try {
const l = await window.crypto.subtle.decrypt(d, i, g), c = new TextDecoder();
s(c.decode(l));
} catch (l) {
r(l);
}
})();
});
}
}
class ys {
constructor(e, n, s) {
this.linkAPIUrl = e, this.sessionId = n;
const r = `${n}:${s}`;
this.auth = `Basic ${btoa(r)}`;
}
// mark unseen events as seen
async markUnseenEventsAsSeen(e) {
return Promise.all(e.map((n) => fetch(`${this.linkAPIUrl}/events/${n.eventId}/seen`, {
method: "POST",
headers: {
Authorization: this.auth
}
}))).catch((n) => console.error("Unabled to mark event as failed:", n));
}
async fetchUnseenEvents() {
var e;
const n = await fetch(`${this.linkAPIUrl}/events?unseen=true`, {
headers: {
Authorization: this.auth
}
});
if (n.ok) {
const { events: s, error: r } = await n.json();
if (r)
throw new Error(`Check unseen events failed: ${r}`);
const i = (e = s?.filter((a) => a.event === "Web3Response").map((a) => ({
type: "Event",
sessionId: this.sessionId,
eventId: a.id,
event: a.event,
data: a.data
}))) !== null && e !== void 0 ? e : [];
return this.markUnseenEventsAsSeen(i), i;
}
throw new Error(`Check unseen events failed: ${n.status}`);
}
}
var V;
(function(t) {
t[t.DISCONNECTED = 0] = "DISCONNECTED", t[t.CONNECTING = 1] = "CONNECTING", t[t.CONNECTED = 2] = "CONNECTED";
})(V || (V = {}));
class $ {
setConnectionStateListener(e) {
this.connectionStateListener = e;
}
setIncomingDataListener(e) {
this.incomingDataListener = e;
}
/**
* Constructor
* @param url WebSocket server URL
* @param [WebSocketClass] Custom WebSocket implementation
*/
constructor(e, n = WebSocket) {
this.WebSocketClass = n, this.webSocket = null, this.isDisconnecting = !1, this.url = e.replace(/^http/, "ws"), this.instanceId = $.instanceCounter++, $.activeInstances.add(this.instanceId);
}
/**
* Make a websocket connection
* @returns a Promise that resolves when connected
*/
async connect() {
if (this.webSocket)
throw new Error("webSocket object is not null");
if (this.isDisconnecting)
throw new Error("WebSocket is disconnecting, cannot reconnect on same instance");
return new Promise((e, n) => {
var s;
let r;
try {
this.webSocket = r = new this.WebSocketClass(this.url);
} catch (i) {
n(i);
return;
}
(s = this.connectionStateListener) === null || s === void 0 || s.call(this, V.CONNECTING), r.onclose = (i) => {
var a;
this.clearWebSocket(), r.readyState !== WebSocket.OPEN && n(new Error(`websocket error ${i.code}: ${i.reason}`)), (a = this.connectionStateListener) === null || a === void 0 || a.call(this, V.DISCONNECTED);
}, r.onopen = (i) => {
var a;
e(), (a = this.connectionStateListener) === null || a === void 0 || a.call(this, V.CONNECTED), $.pendingData.length > 0 && ([...$.pendingData].forEach((h) => this.sendData(h)), $.pendingData = []);
}, r.onmessage = (i) => {
var a, o;
if (i.data === "h")
(a = this.incomingDataListener) === null || a === void 0 || a.call(this, {
type: "Heartbeat"
});
else
try {
const h = JSON.parse(i.data);
(o = this.incomingDataListener) === null || o === void 0 || o.call(this, h);
} catch {
}
};
});
}
/**
* Disconnect from server
*/
disconnect() {
var e;
const { webSocket: n } = this;
if (n) {
this.isDisconnecting = !0, this.clearWebSocket(), (e = this.connectionStateListener) === null || e === void 0 || e.call(this, V.DISCONNECTED), this.connectionStateListener = void 0, this.incomingDataListener = void 0;
try {
n.close();
} catch {
}
}
}
/**
* Send data to server
* @param data text to send
*/
sendData(e) {
const { webSocket: n } = this;
if (!n) {
$.pendingData.push(e), this.isDisconnecting || this.connect();
return;
}
if (n.readyState !== WebSocket.OPEN) {
$.pendingData.push(e);
return;
}
n.send(e);
}
clearWebSocket() {
const { webSocket: e } = this;
e && (this.webSocket = null, e.onclose = null, e.onerror = null, e.onmessage = null, e.onopen = null);
}
/**
* remove ws from active instances
*/
cleanup() {
$.activeInstances.delete(this.instanceId);
}
}
$.instanceCounter = 0;
$.activeInstances = /* @__PURE__ */ new Set();
$.pendingData = [];
const Ct = 1e4, bs = 6e4;
class ws {
/**
* Constructor
* @param session Session
* @param linkAPIUrl Coinbase Wallet link server URL
* @param listener WalletLinkConnectionUpdateListener
* @param [WebSocketClass] Custom WebSocket implementation
*/
constructor({ session: e, linkAPIUrl: n, listener: s }) {
this.destroyed = !1, this.lastHeartbeatResponse = 0, this.nextReqId = Q(1), this.reconnectAttempts = 0, this.isReconnecting = !1, this._connected = !1, this._linked = !1, this.requestResolutions = /* @__PURE__ */ new Map(), this.handleSessionMetadataUpdated = (i) => {
if (!i)
return;
(/* @__PURE__ */ new Map([
["__destroyed", this.handleDestroyed],
["EthereumAddress", this.handleAccountUpdated],
["WalletUsername", this.handleWalletUsernameUpdated],
["AppVersion", this.handleAppVersionUpdated],
[
"ChainId",
// ChainId and JsonRpcUrl are always updated together
(o) => i.JsonRpcUrl && this.handleChainUpdated(o, i.JsonRpcUrl)
]
])).forEach((o, h) => {
const u = i[h];
u !== void 0 && o(u);
});
}, this.handleDestroyed = (i) => {
var a;
i === "1" && ((a = this.listener) === null || a === void 0 || a.resetAndReload());
}, this.handleAccountUpdated = async (i) => {
var a;
try {
const o = await this.cipher.decrypt(i);
(a = this.listener) === null || a === void 0 || a.accountUpdated(o);
} catch {
}
}, this.handleMetadataUpdated = async (i, a) => {
var o;
try {
const h = await this.cipher.decrypt(a);
(o = this.listener) === null || o === void 0 || o.metadataUpdated(i, h);
} catch {
}
}, this.handleWalletUsernameUpdated = async (i) => {
this.handleMetadataUpdated(gs, i);
}, this.handleAppVersionUpdated = async (i) => {
this.handleMetadataUpdated(_s, i);
}, this.handleChainUpdated = async (i, a) => {
var o;
try {
const h = await this.cipher.decrypt(i), u = await this.cipher.decrypt(a);
(o = this.listener) === null || o === void 0 || o.chainUpdated(h, u);
} catch {
}
}, this.session = e, this.cipher = new ms(e.secret), this.listener = s, this.linkAPIUrl = n, this.WebSocketClass = WebSocket;
const r = this.createWebSocket();
this.ws = r, this.http = new ys(n, e.id, e.key), this.setupVisibilityChangeHandler();
}
createWebSocket() {
const e = new $(`${this.linkAPIUrl}/rpc`, this.WebSocketClass);
return this.activeWsInstance = e, e.setConnectionStateListener(async (n) => {
if (e !== this.activeWsInstance)
return;
let s = !1;
switch (n) {
case V.DISCONNECTED:
this.heartbeatIntervalId && (clearInterval(this.heartbeatIntervalId), this.heartbeatIntervalId = void 0), this.lastHeartbeatResponse = 0, s = !1, this.destroyed || (async () => {
if (this.isReconnecting)
return;
this.isReconnecting = !0;
const i = this.reconnectAttempts === 0 ? 0 : 3e3;
await new Promise((a) => setTimeout(a, i)), !this.destroyed && e === this.activeWsInstance ? (this.reconnectAttempts++, "cleanup" in this.ws && typeof this.ws.cleanup == "function" && this.ws.cleanup(), this.ws = this.createWebSocket(), this.ws.connect().catch(() => {
}).finally(() => {
this.isReconnecting = !1;
})) : this.isReconnecting = !1;
})();
break;
case V.CONNECTED:
this.reconnectAttempts = 0;
try {
s = await this.handleConnected(), this.fetchUnseenEventsAPI().catch(() => {
});
} catch {
break;
}
this.connected = s, this.updateLastHeartbeat(), this.heartbeatIntervalId && clearInterval(this.heartbeatIntervalId), this.heartbeatIntervalId = window.setInterval(() => {
this.heartbeat();
}, Ct), setTimeout(() => {
this.heartbeat();
}, 100);
break;
case V.CONNECTING:
break;
}
n !== V.CONNECTED && (this.connected = s);
}), e.setIncomingDataListener((n) => {
var s;
switch (n.type) {
// handle server's heartbeat responses
case "Heartbeat":
this.updateLastHeartbeat();
return;
// handle link status updates
case "IsLinkedOK":
case "Linked": {
const r = n.type === "IsLinkedOK" ? n.linked : void 0;
this.linked = r || n.onlineGuests > 0;
break;
}
// handle session config updates
case "GetSessionConfigOK":
case "SessionConfigUpdated": {
this.handleSessionMetadataUpdated(n.metadata);
break;
}
case "Event": {
this.handleIncomingEvent(n);
break;
}
}
n.id !== void 0 && ((s = this.requestResolutions.get(n.id)) === null || s === void 0 || s(n));
}), 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;
const e = this.ws;
this.activeWsInstance = void 0, e.disconnect(), "cleanup" in e && typeof e.cleanup == "function" && e.cleanup(), this.ws = this.createWebSocket(), this.ws.connect().catch(() => {
});
}
/**
* Make a connection to the server
*/
connect() {
if (this.destroyed)
throw new Error("instance is destroyed");
this.ws.connect();
}
/**
* Terminate connection, and mark as destroyed. To reconnect, create a new
* instance of WalletSDKConnection
*/
async destroy() {
this.destroyed || (await this.makeRequest({
type: "SetSessionConfig",
id: Q(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 && typeof this.ws.cleanup == "function" && 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 n, s;
this._linked = e, e && ((n = this.onceLinked) === null || n === void 0 || n.call(this)), (s = this.listener) === null || s === void 0 || s.linkedUpdated(e);
}
setOnceLinked(e) {
return new Promise((n) => {
this.linked ? e().then(n) : this.onceLinked = () => {
e().then(n), this.onceLinked = void 0;
};
});
}
async handleIncomingEvent(e) {
var n;
if (!(e.type !== "Event" || e.event !== "Web3Response"))
try {
const s = await this.cipher.decrypt(e.data), r = JSON.parse(s);
if (r.type !== "WEB3_RESPONSE")
return;
(n = this.listener) === null || n === void 0 || n.handleWeb3ResponseMessage(r.id, r.response);
} catch {
}
}
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((n) => {
this.handleIncomingEvent(n);
});
} catch {
}
}
/**
* Publish an event and emit event ID when successful
* @param event event name
* @param unencryptedData unencrypted event data
* @param callWebhook whether the webhook should be invoked
* @returns a Promise that emits event ID when successful
*/
async publishEvent(e, n, s = !1) {
const r = await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({}, n), { origin: location.origin, location: location.href, relaySource: "coinbaseWalletExtension" in window && window.coinbaseWalletExtension ? "injected_sdk" : "sdk" }))), i = {
type: "PublishEvent",
id: Q(this.nextReqId++),
sessionId: this.session.id,
event: e,
data: r,
callWebhook: s
};
return this.setOnceLinked(async () => {
const a = await this.makeRequest(i);
if (a.type === "Fail")
throw new Error(a.error || "failed to publish event");
return a.eventId;
});
}
sendData(e) {
this.ws.sendData(JSON.stringify(e));
}
updateLastHeartbeat() {
this.lastHeartbeatResponse = Date.now();
}
heartbeat() {
if (Date.now() - this.lastHeartbeatResponse > Ct * 2) {
this.ws.disconnect();
return;
}
if (this.connected)
try {
this.ws.sendData("h");
} catch {
}
}
async makeRequest(e, n = { timeout: bs }) {
const s = e.id;
this.sendData(e);
let r;
return Promise.race([
new Promise((i, a) => {
r = window.setTimeout(() => {
a(new Error(`request ${s} timed out`));
}, n.timeout);
}),
new Promise((i) => {
this.requestResolutions.set(s, (a) => {
clearTimeout(r), i(a), this.requestResolutions.delete(s);
});
})
]);
}
async handleConnected() {
return (await this.makeRequest({
type: "HostSession",
id: Q(this.nextReqId++),
sessionId: this.session.id,
sessionKey: this.session.key
})).type === "Fail" ? !1 : (this.sendData({
type: "IsLinked",
id: Q(this.nextReqId++),
sessionId: this.session.id
}), this.sendData({
type: "GetSessionConfig",
id: Q(this.nextReqId++),
sessionId: this.session.id
}), !0);
}
}
class vs {
constructor() {
this._nextRequestId = 0, this.callbacks = /* @__PURE__ */ new Map();
}
makeRequestId() {
this._nextRequestId = (this._nextRequestId + 1) % 2147483647;
const e = this._nextRequestId, n = sn(e.toString(16));
return this.callbacks.get(n) && this.callbacks.delete(n), e;
}
}
const At = "session:id", Lt = "session:secret", Pt = "session:linked";
class ce {
constructor(e, n, s, r = !1) {
this.storage = e, this.id = n, this.secret = s, this.key = Un(jn(`${n}, ${s} WalletLink`)), this._linked = !!r;
}
static create(e) {
const n = ie(16), s = ie(32);
return new ce(e, n, s).save();
}
static load(e) {
const n = e.getItem(At), s = e.getItem(Pt), r = e.getItem(Lt);
return n && r ? new ce(e, n, r, s === "1") : null;
}
get linked() {
return this._linked;
}
set linked(e) {
this._linked = e, this.persistLinked();
}
save() {
return this.storage.setItem(At, this.id), this.storage.setItem(Lt, this.secret), this.persistLinked(), this;
}
persistLinked() {
this.storage.setItem(Pt, this._linked ? "1" : "0");
}
}
function ks() {
try {
return window.frameElement !== null;
} catch {
return !1;
}
}
function Es() {
try {
return ks() && window.top ? window.top.location : window.location;
} catch {
return window.location;
}
}
function Is() {
var t;
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test((t = window?.navigator) === null || t === void 0 ? void 0 : t.userAgent);
}
function ln() {
var t, e;
return (e = (t = window?.matchMedia) === null || t === void 0 ? void 0 : t.call(window, "(prefers-color-scheme: dark)").matches) !== null && e !== void 0 ? e : !1;
}
const Ss = '@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}';
function un() {
const t = document.createElement("style");
t.type = "text/css", t.appendChild(document.createTextNode(Ss)), document.documentElement.appendChild(t);
}
function hn(t) {
var e, n, s = "";
if (typeof t == "string" || typeof t == "number") s += t;
else if (typeof t == "object") if (Array.isArray(t)) for (e = 0; e < t.length; e++) t[e] && (n = hn(t[e])) && (s && (s += " "), s += n);
else for (e in t) t[e] && (s && (s += " "), s += e);
return s;
}
function pe() {
for (var t, e, n = 0, s = ""; n < arguments.length; ) (t = arguments[n++]) && (e = hn(t)) && (s && (s += " "), s += e);
return s;
}
var Me, N, fn, te, xt, pn, gn, qe, ke, ge, _n, at, Ye, Ve, Ce = {}, Ae = [], Cs = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, Re = Array.isArray;
function X(t, e) {
for (var n in e) t[n] = e[n];
return t;
}
function ot(t) {
t && t.parentNode && t.parentNode.removeChild(t);
}
function R(t, e, n) {
var s, r, i, a = {};
for (i in e) i == "key" ? s = e[i] : i == "ref" ? r = e[i] : a[i] = e[i];
if (arguments.length > 2 && (a.children = arguments.length > 3 ? Me.call(arguments, 2) : n), typeof t == "function" && t.defaultProps != null) for (i in t.defaultProps) a[i] === void 0 && (a[i] = t.defaultProps[i]);
return Ee(t, a, s, r, null);
}
function Ee(t, e, n, s, r) {
var i = { type: t, props: e, key: n, ref: s, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: r ?? ++fn, __i: -1, __u: 0 };
return r == null && N.vnode != null && N.vnode(i), i;
}
function Te(t) {
return t.children;
}
function Ie(t, e) {
this.props = t, this.context = e;
}
function de(t, e) {
if (e == null) return t.__ ? de(t.__, t.__i + 1) : null;
for (var n; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) return n.__e;
return typeof t.type == "function" ? de(t) : null;
}
function As(t) {
if (t.__P && t.__d) {
var e = t.__v, n = e.__e, s = [], r = [], i = X({}, e);
i.__v = e.__v + 1, N.vnode && N.vnode(i), ct(t.__P, i, e, t.__n, t.__P.namespaceURI, 32 & e.__u ? [n] : null, s, n ?? de(e), !!(32 & e.__u), r), i.__v = e.__v, i.__.__k[i.__i] = i, wn(s, i, r), e.__e = e.__ = null, i.__e != n && mn(i);
}
}
function mn(t) {
if ((t = t.__) != null && t.__c != null) return t.__e = t.__c.base = null, t.__k.some(function(e) {
if (e != null && e.__e != null) return t.__e = t.__c.base = e.__e;
}), mn(t);
}
function Mt(t) {
(!t.__d && (t.__d = !0) && te.push(t) && !Le.__r++ || xt != N.debounceRendering) && ((xt = N.debounceRendering) || pn)(Le);
}
function Le() {
try {
for (var t, e = 1; te.length; ) te.length > e && te.sort(gn), t = te.shift(), e = te.length, As(t);
} finally {
te.length = Le.__r = 0;
}
}
function yn(t, e, n, s, r, i, a, o, h, u, g) {
var d, l, c, p, S, w, v, E = s && s.__k || Ae, L = e.length;
for (h = Ls(n, e, E, h, L), d = 0; d < L; d++) (c = n.__k[d]) != null && (l = c.__i != -1 && E[c.__i] || Ce, c.__i = d, w = ct(t, c, l, r, i, a, o, h, u, g), p = c.__e, c.ref && l.ref != c.ref && (l.ref && dt(l.ref, null, c), g.push(c.ref, c.__c || p, c)), S == null && p != null && (S = p), (v = !!(4 & c.__u)) || l.__k === c.__k ? (h = bn(c, h, t, v), v && l.__e && (l.__e = null)) : typeof c.type == "function" && w !== void 0 ? h = w : p && (h = p.nextSibling), c.__u &= -7);
return n.__e = S, h;
}
function Ls(t, e, n, s, r) {
var i, a, o, h, u, g = n.length, d = g, l = 0;
for (t.__k = new Array(r), i = 0; i < r; i++) (a = e[i]) != null && typeof a != "boolean" && typeof a != "function" ? (typeof a == "string" || typeof a == "number" || typeof a == "bigint" || a.constructor == String ? a = t.__k[i] = Ee(null, a, null, null, null) : Re(a) ? a = t.__k[i] = Ee(Te, { children: a }, null, null, null) : a.constructor === void 0 && a.__b > 0 ? a = t.__k[i] = Ee(a.type, a.props, a.key, a.ref ? a.ref : null, a.__v) : t.__k[i] = a, h = i + l, a.__ = t, a.__b = t.__b + 1, o = null, (u = a.__i = Ps(a, n, h, d)) != -1 && (d--, (o = n[u]) && (o.__u |= 2)), o == null || o.__v == null ? (u == -1 && (r > g ? l-- : r < g && l++), typeof a.type != "function" && (a.__u |= 4)) : u != h && (u == h - 1 ? l-- : u == h + 1 ? l++ : (u > h ? l-- : l++, a.__u |= 4))) : t.__k[i] = null;
if (d) for (i = 0; i < g; i++) (o = n[i]) != null && (2 & o.__u) == 0 && (o.__e == s && (s = de(o)), kn(o, o));
return s;
}
function bn(t, e, n, s) {
var r, i;
if (typeof t.type == "function") {
for (r = t.__k, i = 0; r && i < r.length; i++) r[i] && (r[i].__ = t, e = bn(r[i], e, n, s));
return e;
}
t.__e != e && (s && (e && t.type && !e.parentNode && (e = de(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
do
e = e && e.nextSibling;
while (e != null && e.nodeType == 8);
return e;
}
function Ps(t, e, n, s) {
var r, i, a, o = t.key, h = t.type, u = e[n], g = u != null && (2 & u.__u) == 0;
if (u === null && o == null || g && o == u.key && h == u.type) return n;
if (s > (g ? 1 : 0)) {
for (r = n - 1, i = n + 1; r >= 0 || i < e.length; ) if ((u = e[a = r >= 0 ? r-- : i++]) != null && (2 & u.__u) == 0 && o == u.key && h == u.type) return a;
}
return -1;
}
function Rt(t, e, n) {
e[0] == "-" ? t.setProperty(e, n ?? "") : t[e] = n == null ? "" : typeof n != "number" || Cs.test(e) ? n : n + "px";
}
function be(t, e, n, s, r) {
var i, a;
e: if (e == "style") if (typeof n == "string") t.style.cssText = n;
else {
if (typeof s == "string" && (t.style.cssText = s = ""), s) for (e in s) n && e in n || Rt(t.style, e, "");
if (n) for (e in n) s && n[e] == s[e] || Rt(t.style, e, n[e]);
}
else if (e[0] == "o" && e[1] == "n") i = e != (e = e.replace(_n, "$1")), a = e.toLowerCase(), e = a in t || e == "onFocusOut" || e == "onFocusIn" ? a.slice(2) : e.slice(2), t.l || (t.l = {}), t.l[e + i] = n, n ? s ? n[ge] = s[ge] : (n[ge] = at, t.addEventListener(e, i ? Ve : Ye, i)) : t.removeEventListener(e, i ? Ve : Ye, i);
else {
if (r == "http://www.w3.org/2000/svg") e = e.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
else if (e != "width" && e != "height" && e != "href" && e != "list" && e != "form" && e != "tabIndex" && e != "download" && e != "rowSpan" && e != "colSpan" && e != "role" && e != "popover" && e in t) try {
t[e] = n ?? "";
break e;
} catch {
}
typeof n == "function" || (n == null || n === !1 && e[4] != "-" ? t.removeAttribute(e) : t.setAttribute(e, e == "popover" && n == 1 ? "" : n));
}
}
function Tt(t) {
return function(e) {
if (this.l) {
var n = this.l[e.type + t];
if (e[ke] == null) e[ke] = at++;
else if (e[ke] < n[ge]) return;
return n(N.event ? N.event(e) : e);
}
};
}
function ct(t, e, n, s, r, i, a, o, h, u) {
var g, d, l, c, p, S, w, v, E, L, k, y, C, x, M, m = e.type;
if (e.constructor !== void 0) return null;
128 & n.__u && (h = !!(32 & n.__u), i = [o = e.__e = n.__e]), (g = N.__b) && g(e);
e: if (typeof m == "function") try {
if (v = e.props, E = m.prototype && m.prototype.render, L = (g = m.contextType) && s[g.__c], k = g ? L ? L.props.value : g.__ : s, n.__c ? w = (d = e.__c = n.__c).__ = d.__E : (E ? e.__c = d = new m(v, k) : (e.__c = d = new Ie(v, k), d.constructor = m, d.render = Ms), L && L.sub(d), d.state || (d.state = {}), d.__n = s, l = d.__d = !0, d.__h = [], d._sb = []), E && d.__s == null && (d.__s = d.state), E && m.getDerivedStateFromProps != null && (d.__s == d.state && (d.__s = X({}, d.__s)), X(d.__s, m.getDerivedStateFromProps(v, d.__s))), c = d.props, p = d.state, d.__v = e, l) E && m.getDerivedStateFromProps == null && d.componentWillMount != null && d.componentWillMount(), E && d.componentDidMount != null && d.__h.push(d.componentDidMount);
else {
if (E && m.getDerivedStateFromProps == null && v !== c && d.componentWillReceiveProps != null && d.componentWillReceiveProps(v, k), e.__v == n.__v || !d.__e && d.shouldComponentUpdate != null && d.shouldComponentUpdate(v, d.__s, k) === !1) {
e.__v != n.__v && (d.props = v, d.state = d.__s, d.__d = !1), e.__e = n.__e, e.__k = n.__k, e.__k.some(function(_) {
_ && (_.__ = e);
}), Ae.push.apply(d.__h, d._sb), d._sb = [], d.__h.length && a.push(d);
break e;
}
d.componentWillUpdate != null && d.componentWillUpdate(v, d.__s, k), E && d.componentDidUpdate != null && d.__h.push(function() {
d.componentDidUpdate(c, p, S);
});
}
if (d.context = k, d.props = v, d.__P = t, d.__e = !1, y = N.__r, C = 0, E) d.state = d.__s, d.__d = !1, y && y(e), g = d.render(d.props, d.state, d.context), Ae.push.apply(d.__h, d._sb), d._sb = [];
else do
d.__d = !1, y && y(e), g = d.render(d.props, d.state, d.context), d.state = d.__s;
while (d.__d && ++C < 25);
d.state = d.__s, d.getChildContext != null && (s = X(X({}, s), d.getChildContext())), E && !l && d.getSnapshotBeforeUpdate != null && (S = d.getSnapshotBeforeUpdate(c, p)), x = g != null && g.type === Te && g.key == null ? vn(g.props.children) : g, o = yn(t, Re(x) ? x : [x], e, n, s, r, i, a, o, h, u), d.base = e.__e, e.__u &= -161, d.__h.length && a.push(d), w && (d.__E = d.__ = null);
} catch (_) {
if (e.__v = null, h || i != null) if (_.then) {
for (e.__u |= h ? 160 : 128; o && o.nodeType == 8 && o.nextSibling; ) o = o.nextSibling;
i[i.indexOf(o)] = null, e.__e = o;
} else {
for (M = i.length; M--; ) ot(i[M]);
Je(e);
}
else e.__e = n.__e, e.__k = n.__k, _.then || Je(e);
N.__e(_, e, n);
}
else i == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : o = e.__e = xs(n.__e, e, n, s, r, i, a, h, u);
return (g = N.diffed) && g(e), 128 & e.__u ? void 0 : o;
}
function Je(t) {
t && (t.__c && (t.__c.__e = !0), t.__k && t.__k.some(Je));
}
function wn(t, e, n) {
for (var s = 0; s < n.length; s++) dt(n[s], n[++s], n[++s]);
N.__c && N.__c(e, t), t.some(function(r) {
try {
t = r.__h, r.__h = [], t.some(function(i) {
i.call(r);
});
} catch (i) {
N.__e(i, r.__v);
}
});
}
function vn(t) {
return typeof t != "object" || t == null || t.__b > 0 ? t : Re(t) ? t.map(vn) : X({}, t);
}
function xs(t, e, n, s, r, i, a, o, h) {
var u, g, d, l, c, p, S, w = n.props || Ce, v = e.props, E = e.type;
if (E == "svg" ? r = "http://www.w3.org/2000/svg" : E == "math" ? r = "http://www.w3.org/1998/Math/MathML" : r || (r = "http://www.w3.org/1999/xhtml"), i != null) {
for (u = 0; u < i.length; u++) if ((c = i[u]) && "setAttribute" in c == !!E && (E ? c.localName == E : c.nodeType == 3)) {
t = c, i[u] = null;
break;
}
}
if (t == null) {
if (E == null) return document.createTextNode(v);
t = document.createElementNS(r, E, v.is && v), o && (N.__m && N.__m(e, i), o = !1), i = null;
}
if (E == null) w === v || o && t.data == v || (t.data = v);
else {
if (i = i && Me.call(t.childNodes), !o && i != null) for (w = {}, u = 0; u < t.attributes.length; u++) w[(c = t.attributes[u]).name] = c.value;
for (u in w) c = w[u], u == "dangerouslySetInnerHTML" ? d = c : u == "children" || u in v || u == "value" && "defaultValue" in v || u == "checked" && "defaultChecked" in v || be(t, u, null, c, r);
for (u in v) c = v[u], u == "children" ? l = c : u == "dangerouslySetInnerHTML" ? g = c : u == "value" ? p = c : u == "checked" ? S = c : o && typeof c != "function" || w[u] === c || be(t, u, c, w[u], r);
if (g) o || d && (g.__html == d.__html || g.__html == t.innerHTML) || (t.innerHTML = g.__html), e.__k = [];
else if (d && (t.innerHTML = ""), yn(e.type == "template" ? t.content : t, Re(l) ? l : [l], e, n, s, E == "foreignObject" ? "http://www.w3.org/1999/xhtml" : r, i, a, i ? i[0] : n.__k && de(n, 0), o, h), i != null) for (u = i.length; u--; ) ot(i[u]);
o || (u = "value", E == "progress" && p == null ? t.removeAttribute("value") : p != null && (p !== t[u] || E == "progress" && !p || E == "option" && p != w[u]) && be(t, u, p, w[u], r), u = "checked", S != null && S != t[u] && be(t, u, S, w[u], r));
}
return t;
}
function dt(t, e, n) {
try {
if (typeof t == "function") {
var s = typeof t.__u == "function";
s && t.__u(), s && e == null || (t.__u = t(e));
} else t.current = e;
} catch (r) {
N.__e(r, n);
}
}
function kn(t, e, n) {
var s, r;
if (N.unmount && N.unmount(t), (s = t.ref) && (s.current && s.current != t.__e || dt(s, null, e)), (s = t.__c) != null) {
if (s.componentWillUnmount) try {
s.componentWillUnmount();
} catch (i) {
N.__e(i, e);
}
s.base = s.__P = null;
}
if (s = t.__k) for (r = 0; r < s.length; r++) s[r] && kn(s[r], e, n || typeof t.type != "function");
n || ot(t.__e), t.__c = t.__ = t.__e = void 0;
}
function Ms(t, e, n) {
return this.constructor(t, n);
}
function Qe(t, e, n) {
var s, r, i, a;
e == document && (e = document.documentElement), N.__ && N.__(t, e), r = (s = !1) ? null : e.__k, i = [], a = [], ct(e, t = e.__k = R(Te, null, [t]), r || Ce, Ce, e.namespaceURI, r ? null : e.firstChild ? Me.call(e.childNodes) : null, i, r ? r.__e : e.firstChild, s, a), wn(i, t, a);
}
Me = Ae.slice, N = { __e: function(t, e, n, s) {
for (var r, i, a; e = e.__; ) if ((r = e.__c) && !r.__) try {
if ((i = r.constructor) && i.getDerivedStateFromError != null && (r.setState(i.getDerivedStateFromError(t)), a = r.__d), r.componentDidCatch != null && (r.componentDidCatch(t, s || {}), a = r.__d), a) return r.__E = r;
} catch (o) {
t = o;
}
throw t;
} }, fn = 0, Ie.prototype.setState = function(t, e) {
var n;
n = this.__s != null && this.__s != this.state ? this.__s : this.__s = X({}, this.state), typeof t == "function" && (t = t(X({}, n), this.props)), t && X(n, t), t != null && this.__v && (e && this._sb.push(e), Mt(this));
}, Ie.prototype.forceUpdate = function(t) {
this.__v && (this.__e = !0, t && this.__h.push(t), Mt(this));
}, Ie.prototype.render = Te, te = [], pn = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, gn = function(t, e) {
return t.__v.__b - e.__v.__b;
}, Le.__r = 0, qe = Math.random().toString(8), ke = "__d" + qe, ge = "__a" + qe, _n = /(PointerCapture)$|Capture$/i, at = 0, Ye = Tt(!1), Ve = Tt(!0);
var Pe, B, Ke, Nt, Ze = 0, En = [], H = N, Ot = H.__b, Dt = H.__r, Ut = H.diffed, jt = H.__c, Bt = H.unmount, Ht = H.__;
function In(t, e) {
H.__h && H.__h(B, t, Ze || e), Ze = 0;
var n = B.__H || (B.__H = { __: [], __h: [] });
return t >= n.__.length && n.__.push({}), n.__[t];
}
function Wt(t) {
return Ze = 1, Rs(Sn, t);
}
function Rs(t, e, n) {
var s = In(Pe++, 2);
if (s.t = t, !s.__c && (s.__ = [Sn(void 0, e), function(o) {
var h = s.__N ? s.__N[0] : s.__[0], u = s.t(h, o);
h !== u && (s.__N = [u, s.__[1]], s.__c.setState({}));
}], s.__c = B, !B.__f)) {
var r = function(o, h, u) {
if (!s.__c.__H) return !0;
var g = s.__c.__H.__.filter(function(l) {
return l.__c;
});
if (g.every(function(l) {
return !l.__N;
})) return !i || i.call(this, o, h, u);
var d = s.__c.props !== o;
return g.some(function(l) {
if (l.__N) {
var c = l.__[0];
l.__ = l.__N, l.__N = void 0, c !== l.__[0] && (d = !0);
}
}), i && i.call(this, o, h, u) || d;
};
B.__f = !0;
var i = B.shouldComponentUpdate, a = B.componentWillUpdate;
B.componentWillUpdate = function(o, h, u) {
if (this.__e) {
var g = i;
i = void 0, r(o, h, u), i = g;
}
a && a.call(this, o, h, u);
}, B.shouldComponentUpdate = r;
}
return s.__N || s.__;
}
function Ts(t, e) {
var n = In(Pe++, 3);
!H.__s && Ds(n.__H, e) && (n.__ = t, n.u = e, B.__H.__h.push(n));
}
function Ns() {
for (var t; t = En.shift(); ) {
var e = t.__H;
if (t.__P && e) try {
e.__h.some(Se), e.__h.some(Xe), e.__h = [];
} catch (n) {
e.__h = [], H.__e(n, t.__v);
}
}
}
H.__b = function(t) {
B = null, Ot && Ot(t);
}, H.__ = function(t, e) {
t && e.__k && e.__k.__m && (t.__m = e.__k.__m), Ht && Ht(t, e);
}, H.__r = function(t) {
Dt && Dt(t), Pe = 0;
var e = (B = t.__c).__H;
e && (Ke === B ? (e.__h = [], B.__h = [], e.__.some(function(n) {
n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
})) : (e.__h.some(Se), e.__h.some(Xe), e.__h = [], Pe = 0)), Ke = B;
}, H.diffed = function(t) {
Ut && Ut(t);
var e = t.__c;
e && e.__H && (e.__H.__h.length && (En.push(e) !== 1 && Nt === H.requestAnimationFrame || ((Nt = H.requestAnimationFrame) || Os)(Ns)), e.__H.__.some(function(n) {
n.u && (n.__H = n.u), n.u = void 0;
})), Ke = B = null;
}, H.__c = function(t, e) {
e.some(function(n) {
try {
n.__h.some(Se), n.__h = n.__h.filter(function(s) {
return !s.__ || Xe(s);
});
} catch (s) {
e.some(function(r) {
r.__h && (r.__h = []);
}), e = [], H.__e(s, n.__v);
}
}), jt && jt(t, e);
}, H.unmount = function(t) {
Bt && Bt(t);
var e, n = t.__c;
n && n.__H && (n.__H.__.some(function(s) {
try {
Se(s);
} catch (r) {
e = r;
}
}), n.__H = void 0, e && H.__e(e, n.__v));
};
var qt = typeof requestAnimationFrame == "function";
function Os(t) {
var e, n = function() {
clearTimeout(s), qt && cancelAnimationFrame(e), setTimeout(t);
}, s = setTimeout(n, 35);
qt && (e = requestAnimationFrame(n));
}
function Se(t) {
var e = B, n = t.__c;
typeof n == "function" && (t.__c = void 0, n()), B = e;
}
function Xe(t) {
var e = B;
t.__c = t.__(), B = e;
}
function Ds(t, e) {
return !t || t.length !== e.length || e.some(function(n, s) {
return n !== t[s];
});
}
function Sn(t, e) {
return typeof e == "function" ? e(t) : e;
}
const Us = ".-cbwsdk-css-reset .-gear-container{margin-left:16px !important;margin-right:9px !important;display:flex;align-items:center;justify-content:center;width:24px;height:24px;transition:opacity .25s}.-cbwsdk-css-reset .-gear-container *{user-select:none}.-cbwsdk-css-reset .-gear-container svg{opacity:0;position:absolute}.-cbwsdk-css-reset .-gear-icon{height:12px;width:12px;z-index:10000}.-cbwsdk-css-reset .-cbwsdk-snackbar{align-items:flex-end;display:flex;flex-direction:column;position:fixed;right:0;top:0;z-index:2147483647}.-cbwsdk-css-reset .-cbwsdk-snackbar *{user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance{display:flex;flex-direction:column;margin:8px 16px 0 16px;overflow:visible;text-align:left;transform:translateX(0);transition:opacity .25s,transform .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header:hover .-gear-container svg{opacity:1}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header{display:flex;align-items:center;background:#fff;overflow:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-cblogo{margin:8px 8px 8px 8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-message{color:#000;font-size:13px;line-height:1.5;user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu{background:#fff;transition:opacity .25s ease-in-out,transform .25s linear,visibility 0s;visibility:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;opacity:0;flex-direction:column;padding-left:8px;padding-right:8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:last-child{margin-bottom:8px !important}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover{background:#f5f7f8;border-radius:6px;transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover span{color:#050f19;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover svg path{fill:#000;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item{visibility:inherit;height:35px;margin-top:8px;margin-bottom:0;display:flex;flex-direction:row;align-items:center;padding:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item *{visibility:inherit;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover{background:rgba(223,95,103,.2);transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover svg path{fill:#df5f67;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover span{color:#df5f67;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-info{color:#aaa;font-size:13px;margin:0 8px 0 32px;position:absolute}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-hidden{opacity:0;text-align:left;transform:translateX(25%);transition:opacity .5s linear}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-expanded .-cbwsdk-snackbar-instance-menu{opacity:1;display:flex;transform:translateY(8px);visibility:visible}", js = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEuNDkyIDEwLjQxOWE4LjkzIDguOTMgMCAwMTguOTMtOC45M2gxMS4xNjNhOC45MyA4LjkzIDAgMDE4LjkzIDguOTN2MTEuMTYzYTguOTMgOC45MyAwIDAxLTguOTMgOC45M0gxMC40MjJhOC45MyA4LjkzIDAgMDEtOC45My04LjkzVjEwLjQxOXoiIGZpbGw9IiMxNjUyRjAiLz48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwLjQxOSAwSDIxLjU4QzI3LjMzNSAwIDMyIDQuNjY1IDMyIDEwLjQxOVYyMS41OEMzMiAyNy4zMzUgMjcuMzM1IDMyIDIxLjU4MSAzMkgxMC40MkM0LjY2NSAzMiAwIDI3LjMzNSAwIDIxLjU4MVYxMC40MkMwIDQuNjY1IDQuNjY1IDAgMTAuNDE5IDB6bTAgMS40ODhhOC45MyA4LjkzIDAgMDAtOC45MyA4LjkzdjExLjE2M2E4LjkzIDguOTMgMCAwMDguOTMgOC45M0gyMS41OGE4LjkzIDguOTMgMCAwMDguOTMtOC45M1YxMC40MmE4LjkzIDguOTMgMCAwMC04LjkzLTguOTNIMTAuNDJ6IiBmaWxsPSIjZmZmIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNS45OTggMjYuMDQ5Yy01LjU0OSAwLTEwLjA0Ny00LjQ5OC0xMC4wNDctMTAuMDQ3IDAtNS41NDggNC40OTgtMTAuMDQ2IDEwLjA0Ny0xMC4wNDYgNS41NDggMCAxMC4wNDYgNC40OTggMTAuMDQ2IDEwLjA0NiAwIDUuNTQ5LTQuNDk4IDEwLjA0Ny0xMC4wNDYgMTAuMDQ3eiIgZmlsbD0iI2ZmZiIvPjxwYXRoIGQ9Ik0xMi43NjIgMTQuMjU0YzAtLjgyMi42NjctMS40ODkgMS40ODktMS40ODloMy40OTdjLjgyMiAwIDEuNDg4LjY2NiAxLjQ4OCAxLjQ4OXYzLjQ5N2MwIC44MjItLjY2NiAxLjQ4OC0xLjQ4OCAxLjQ4OGgtMy40OTdhMS40ODggMS40ODggMCAwMS0xLjQ4OS0xLjQ4OHYtMy40OTh6IiBmaWxsPSIjMTY1MkYwIi8+PC9zdmc+", Bs = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDYuNzV2LTEuNWwtMS43Mi0uNTdjLS4wOC0uMjctLjE5LS41Mi0uMzItLjc3bC44MS0xLjYyLTEuMDYtMS4wNi0xLjYyLjgxYy0uMjQtLjEzLS41LS4yNC0uNzctLjMyTDYuNzUgMGgtMS41bC0uNTcgMS43MmMtLjI3LjA4LS41My4xOS0uNzcuMzJsLTEuNjItLjgxLTEuMDYgMS4wNi44MSAxLjYyYy0uMTMuMjQtLjI0LjUtLjMyLjc3TDAgNS4yNXYxLjVsMS43Mi41N2MuMDguMjcuMTkuNTMuMzIuNzdsLS44MSAxLjYyIDEuMDYgMS4wNiAxLjYyLS44MWMuMjQuMTMuNS4yMy43Ny4zMkw1LjI1IDEyaDEuNWwuNTctMS43MmMuMjctLjA4LjUyLS4xOS43Ny0uMzJsMS42Mi44MSAxLjA2LTEuMDYtLjgxLTEuNjJjLjEzLS4yNC4yMy0uNS4zMi0uNzdMMTIgNi43NXpNNiA4LjVhMi41IDIuNSAwIDAxMC01IDIuNSAyLjUgMCAwMTAgNXoiIGZpbGw9IiMwNTBGMTkiLz48L3N2Zz4=";
class Cn {
constructor() {
this.items = /* @__PURE__ */ new Map(), this.nextItemKey = 0, this.root = null, this.darkMode = ln();
}
attach(e) {
this.root = document.createElement("div"), this.root.className = "-cbwsdk-snackbar-root", e.appendChild(this.root), this.render();
}
presentItem(e) {
const n = this.nextItemKey++;
return this.items.set(n, e), this.render(), () => {
this.items.delete(n), this.render();
};
}
clear() {
this.items.clear(), this.render();
}
render() {
this.root && Qe(R(
"div",
null,
R(An, { darkMode: this.darkMode }, Array.from(this.items.entries()).map(([e, n]) => R(Hs, Object.assign({}, n, { key: e }))))
), this.root);
}
}
const An = (t) => R(
"div",
{ class: pe("-cbwsdk-snackbar-container") },
R("style", null, Us),
R("div", { class: "-cbwsdk-snackbar" }, t.children)
), Hs = ({ autoExpand: t, message: e, menuItems: n }) => {
const [s, r] = Wt(!0), [i, a] = Wt(t ?? !1);
Ts(() => {
const h = [
window.setTimeout(() => {
r(!1);
}, 1),
window.setTimeout(() => {
a(!0);
}, 1e4)
];
return () => {
h.forEach(window.clearTimeout);
};
});
const o = () => {
a(!i);
};
return R(
"div",
{ class: pe("-cbwsdk-snackbar-instance", s && "-cbwsdk-snackbar-instance-hidden", i && "-cbwsdk-snackbar-instance-expanded") },
R(
"div",
{ class: "-cbwsdk-snackbar-instance-header", onClick: o },
R("img", { src: js, class: "-cbwsdk-snackbar-instance-header-cblogo" }),
" ",
R("div", { class: "-cbwsdk-snackbar-instance-header-message" }, e),
R(
"div",
{ class: "-gear-container" },
!i && R(
"svg",
{ width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
R("circle", { cx: "12", cy: "12", r: "12", fill: "#F5F7F8" })
),
R("img", { src: Bs, class: "-gear-icon", title: "Expand" })
)
),
n && n.length > 0 && R("div", { class: "-cbwsdk-snackbar-instance-menu" }, n.map((h, u) => R(
"div",
{ class: pe("-cbwsdk-snackbar-instance-menu-item", h.isRed && "-cbwsdk-snackbar-instance-menu-item-is-red"), onClick: h.onClick, key: u },
R(
"svg",
{ width: h.svgWidth, height: h.svgHeight, viewBox: "0 0 10 11", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
R("path", { "fill-rule": h.defaultFillRule, "clip-rule": h.defaultClipRule, d: h.path, fill: "#AAAAAA" })
),
R("span", { class: pe("-cbwsdk-snackbar-instance-menu-item-info", h.isRed && "-cbwsdk-snackbar-instance-menu-item-info-is-red") }, h.info)
)))
);
}, Ln = "M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z";
class Ws {
constructor() {
this.attached = !1, this.snackbar = new Cn();
}
attach() {
if (this.attached)
throw new Error("Coinbase Wallet SDK UI is already attached");
const e = document.documentElement, n = document.createElement("div");
n.className = "-cbwsdk-css-reset", e.appendChild(n), this.snackbar.attach(n), this.attached = !0, un();
}
showConnecting(e) {
let n;
return e.isUnlinkedErrorState ? n = {
autoExpand: !0,
message: "Connection lost",
menuItems: [
{
isRed: !1,
info: "Reset connection",
svgWidth: "10",
svgHeight: "11",
path: "M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",
defaultFillRule: "evenodd",
defaultClipRule: "evenodd",
onClick: e.onResetConnection
}
]
} : n = {
message: "Confirm on phone",
menuItems: [
{
isRed: !0,
info: "Cancel transaction",
svgWidth: "11",
svgHeight: "11",
path: "M10.3711 1.52346L9.21775 0.370117L5.37109 4.21022L1.52444 0.370117L0.371094 1.52346L4.2112 5.37012L0.371094 9.21677L1.52444 10.3701L5.37109 6.53001L9.21775 10.3701L10.3711 9.21677L6.53099 5.37012L10.3711 1.52346Z",
defaultFillRule: "inherit",
defaultClipRule: "inherit",
onClick: e.onCancel
},
{
isRed: !1,
info: "Reset connection",
svgWidth: "10",
svgHeight: "11",
path: Ln,
defaultFillRule: "evenodd",
defaultClipRule: "evenodd",
onClick: e.onResetConnection
}
]
}, this.snackbar.presentItem(n);
}
}
const qs = ".-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;transition:opacity .25s;background-color:rgba(10,11,13,.5)}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop-hidden{opacity:0}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box{display:block;position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);padding:20px;border-radius:8px;background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box p{display:block;font-weight:400;font-size:14px;line-height:20px;padding-bottom:12px;color:#5b636e}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box button{appearance:none;border:none;background:none;color:#0052ff;padding:0;text-decoration:none;display:block;font-weight:600;font-size:16px;line-height:24px}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark{background-color:#0a0b0d;color:#fff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark button{color:#0052ff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light{background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light button{color:#0052ff}";
class Ks {
constructor() {
this.root = null, this.darkMode = ln();
}
attach() {
const e = document.documentElement;
this.root = document.createElement("div"), this.root.className = "-cbwsdk-css-reset", e.appendChild(this.root), un();
}
present(e) {
this.render(e);
}
clear() {
this.render(null);
}
render(e) {
this.root && (Qe(null, this.root), e && Qe(R(Fs, Object.assign({}, e, { onDismiss: () => {
this.clear();
}, darkMode: this.darkMode })), this.root));
}
}
const Fs = ({ title: t, buttonText: e, darkMode: n, onButtonClick: s, onDismiss: r }) => {
const i = n ? "dark" : "light";
return R(
An,
{ darkMode: n },
R(
"div",
{ class: "-cbwsdk-redirect-dialog" },
R("style", null, qs),
R("div", { class: "-cbwsdk-redirect-dialog-backdrop", onClick: r }),
R(
"div",
{ class: pe("-cbwsdk-redirect-dialog-box", i) },
R("p", null, t),
R("button", { onClick: s }, e)
)
)
);
}, zs = "https://keys.coinbase.com/connect", $s = "https://rpc.wallet.coinbase.com", Kt = "https://www.walletlink.org", Gs = "https://go.cb-w.com/walletlink";
class Ft {
constructor() {
this.attached = !1, this.redirectDialog = new Ks();
}
attach() {
if (this.attached)
throw new Error("Coinbase Wallet SDK UI is already attached");
this.redirectDialog.attach(), this.attached = !0;
}
redirectToCoinbaseWallet(e) {
const n = new URL(Gs);
n.searchParams.append("redirect_url", Es().href), e && n.searchParams.append("wl_url", e);
const s = document.createElement("a");
s.target = "cbw-opener", s.href = n.href, s.rel = "noreferrer noopener", s.click();
}
openCoinbaseWalletDeeplink(e) {
this.redirectToCoinbaseWallet(e), setTimeout(() => {
this.redirectDialog.present({
title: "Redirecting to Coinbase Wallet...",
buttonText: "Open",
onButtonClick: () => {
this.redirectToCoinbaseWallet(e);
}
});
}, 99);
}
showConnecting(e) {
return () => {
this.redirectDialog.clear();
};
}
}
class Z {
constructor(e) {
this.chainCallbackParams = { chainId: "", jsonRpcUrl: "" }, this.isMobileWeb = Is(), this.linkedUpdated = (i) => {
this.isLinked = i;
const a = this.storage.getItem(Ge);
if (i && (this._session.linked = i), this.isUnlinkedErrorState = !1, a) {
const o = a.split(" "), h = this.storage.getItem("IsStandaloneSigning") === "true";
o[0] !== "" && !i && this._session.linked && !h && (this.isUnlinkedErrorState = !0);
}
}, this.metadataUpdated = (i, a) => {
this.storage.setItem(i, a);
}, this.chainUpdated = (i, a) => {
this.chainCallbackParams.chainId === i && this.chainCallbackParams.jsonRpcUrl === a || (this.chainCallbackParams = {
chainId: i,
jsonRpcUrl: a
}, this.chainCallback && this.chainCallback(a, Number.parseInt(i, 10)));
}, this.accountUpdated = (i) => {
this.accountsCallback && this.accountsCallback([i]), Z.accountRequestCallbackIds.size > 0 && (Array.from(Z.accountRequestCallbackIds.values()).forEach((a) => {
this.invokeCallback(a, {
method: "requestEthereumAccounts",
result: [i]
});
}), Z.accountRequestCallbackIds.clear());
}, this.resetAndReload = this.resetAndReload.bind(this), this.linkAPIUrl = e.linkAPIUrl, this.storage = e.storage, this.metadata = e.metadata, this.accountsCallback = e.accountsCallback, this.chainCallback = e.chainCallback;
const { session: n, ui: s, connection: r } = this.subscribe();
this._session = n, this.connection = r, this.relayEventManager = new vs(), this.ui = s, this.ui.attach();
}
subscribe() {
const e = ce.load(this.storage) || ce.create(this.storage), { linkAPIUrl: n } = this, s = new ws({
session: e,
linkAPIUrl: n,
listener: this
}), r = this.isMobileWeb ? new Ft() : new Ws();
return s.connect(), { session: e, ui: r, connection: s };
}
resetAndReload() {
this.connection.destroy().then(() => {
const e = ce.load(this.storage);
e?.id === this._session.id && J.clearAll(), document.location.reload();
}).catch((e) => {
});
}
signEthereumTransaction(e) {
return this.sendRequest({
method: "signEthereumTransaction",
params: {
fromAddress: e.fromAddress,
toAddress: e.toAddress,
weiValue: Y(e.weiValue),
data: he(e.data, !0),
nonce: e.nonce,
gasPriceInWei: e.gasPriceInWei ? Y(e.gasPriceInWei) : null,
maxFeePerGas: e.gasPriceInWei ? Y(e.gasPriceInWei) : null,
maxPriorityFeePerGas: e.gasPriceInWei ? Y(e.gasPriceInWei) : null,
gasLimit: e.gasLimit ? Y(e.gasLimit) : null,
chainId: e.chainId,
shouldSubmit: !1
}
});
}
signAndSubmitEthereumTransaction(e) {
return this.sendRequest({
method: "signEthereumTransaction",
params: {
fromAddress: e.fromAddress,
toAddress: e.toAddress,
weiValue: Y(e.weiValue),
data: he(e.data, !0),
nonce: e.nonce,
gasPriceInWei: e.gasPriceInWei ? Y(e.gasPriceInWei) : null,
maxFeePerGas: e.maxFeePerGas ? Y(e.maxFeePerGas) : null,
maxPriorityFeePerGas: e.maxPriorityFeePerGas ? Y(e.maxPriorityFeePerGas) : null,
gasLimit: e.gasLimit ? Y(e.gasLimit) : null,
chainId: e.chainId,
shouldSubmit: !0
}
});
}
submitEthereumTransaction(e, n) {
return this.sendRequest({
method: "submitEthereumTransaction",
params: {
signedTransaction: he(e, !0),
chainId: n
}
});
}
getWalletLinkSession() {
return this._session;
}
sendRequest(e) {
let n = null;
const s = ie(8), r = (i) => {
this.publishWeb3RequestCanceledEvent(s), this.handleErrorResponse(s, e.method, i), n?.();
};
return new Promise((i, a) => {
n = this.ui.showConnecting({
isUnlinkedErrorState: this.isUnlinkedErrorState,
onCancel: r,
onResetConnection: this.resetAndReload
// eslint-disable-line @typescript-eslint/unbound-method
}), this.relayEventManager.callbacks.set(s, (o) => {
if (n?.(), F(o))
return a(new Error(o.errorMessage));
i(o);
}), this.publishWeb3RequestEvent(s, e);
});
}
publishWeb3RequestEvent(e, n) {
const s = { type: "WEB3_REQUEST", id: e, request: n };
this.publishEvent("Web3Request", s, !0).then((r) => {
}).catch((r) => {
this.handleWeb3ResponseMessage(s.id, {
method: n.method,
errorMessage: r.message
});
}), this.isMobileWeb && this.openCoinbaseWalletDeeplink(n.method);
}
// copied from MobileRelay
openCoinbaseWalletDeeplink(e) {
if (this.ui instanceof Ft)
switch (e) {
case "requestEthereumAccounts":
// requestEthereumAccounts is handled via popup
case "switchEthereumChain":
return;
default:
window.addEventListener("blur", () => {
window.addEventListener("focus", () => {
this.connection.checkUnseenEvents();
}, { once: !0 });
}, { once: !0 }), this.ui.openCoinbaseWalletDeeplink();
break;
}
}
publishWeb3RequestCanceledEvent(e) {
const n = {
type: "WEB3_REQUEST_CANCELED",
id: e
};
this.publishEvent("Web3RequestCanceled", n, !1).then();
}
publishEvent(e, n, s) {
return this.connection.publishEvent(e, n, s);
}
handleWeb3ResponseMessage(e, n) {
if (n.method === "requestEthereumAccounts") {
Z.accountRequestCallbackIds.forEach((s) => this.invokeCallback(s, n)), Z.accountRequestCallbackIds.clear();
return;
}
this.invokeCallback(e, n);
}
handleErrorResponse(e, n, s) {
var r;
const i = (r = s?.message) !== null && r !== void 0 ? r : "Unspecified error message.";
this.handleWeb3ResponseMessage(e, {
method: n,
errorMessage: i
});
}
invokeCallback(e, n) {
const s = this.relayEventManager.callbacks.get(e);
s && (s(n), this.relayEventManager.callbacks.delete(e));
}
requestEthereumAccounts() {
const { appName: e, appLogoUrl: n } = this.metadata, s = {
method: "requestEthereumAccounts",
params: {
appName: e,
appLogoUrl: n
}
}, r = ie(8);
return new Promise((i, a) => {
this.relayEventManager.callbacks.set(r, (o) => {
if (F(o))
return a(new Error(o.errorMessage));
i(o);
}), Z.accountRequestCallbackIds.add(r), this.publishWeb3RequestEvent(r, s);
});
}
watchAsset(e, n, s, r, i, a) {
const o = {
method: "watchAsset",
params: {
type: e,
options: {
address: n,
symbol: s,
decimals: r,
image: i
},
chainId: a
}
};
let h = null;
const u = ie(8), g = (d) => {
this.publishWeb3RequestCanceledEvent(u), this.handleErrorResponse(u, o.method, d), h?.();
};
return h = this.ui.showConnecting({
isUnlinkedErrorState: this.isUnlinkedErrorState,
onCancel: g,
onResetConnection: this.resetAndReload
// eslint-disable-line @typescript-eslint/unbound-method
}), new Promise((d, l) => {
this.relayEventManager.callbacks.set(u, (c) => {
if (h?.(), F(c))
return l(new Error(c.errorMessage));
d(c);
}), this.publishWeb3RequestEvent(u, o);
});
}
addEthereumChain(e, n, s, r, i, a) {
const o = {
method: "addEthereumChain",
params: {
chainId: e,
rpcUrls: n,
blockExplorerUrls: r,
chainName: i,
iconUrls: s,
nativeCurrency: a
}
};
let h = null;
const u = ie(8), g = (d) => {
this.publishWeb3RequestCanceledEvent(u), this.handleErrorResponse(u, o.method, d), h?.();
};
return h = this.ui.showConnecting({
isUnlinkedErrorState: this.isUnlinkedErrorState,
onCancel: g,
onResetConnection: this.resetAndReload
// eslint-disable-line @typescript-eslint/unbound-method
}), new Promise((d, l) => {
this.relayEventManager.callbacks.set(u, (c) => {
if (h?.(), F(c))
return l(new Error(c.errorMessage));
d(c);
}), this.publishWeb3RequestEvent(u, o);
});
}
switchEthereumChain(e, n) {
const s = {
method: "switchEthereumChain",
params: Object.assign({ chainId: e }, { address: n })
};
let r = null;
const i = ie(8), a = (o) => {
this.publishWeb3RequestCanceledEvent(i), this.handleErrorResponse(i, s.method, o), r?.();
};
return r = this.ui.showConnecting({
isUnlinkedErrorState: this.isUnlinkedErrorState,
onCancel: a,
onResetConnection: this.resetAndReload
// eslint-disable-line @typescript-eslint/unbound-method
}), new Promise((o, h) => {
this.relayEventManager.callbacks.set(i, (u) => {
if (r?.(), F(u) && u.errorCode)
return h(P.provider.custom({
code: u.errorCode,
message: "Unrecognized chain ID. Try adding the chain using addEthereumChain first."
}));
if (F(u))
return h(new Error(u.errorMessage));
o(u);
}), this.publishWeb3RequestEvent(i, s);
});
}
}
Z.accountRequestCallbackIds = /* @__PURE__ */ new Set();
const zt = "DefaultChainId", $t = "DefaultJsonRpcUrl";
class Pn {
constructor(e) {
this._relay = null, this._addresses = [], this.metadata = e.metadata, this._storage = new J("walletlink", Kt), this.callback = e.callback || null;
const n = this._storage.getItem(Ge);
if (n) {
const s = n.split(" ");
s[0] !== "" && (this._addresses = s.map((r) => ee(r)));
}
this.initializeRelay();
}
getSession() {
const e = this.initializeRelay(), { id: n, secret: s } = e.getWalletLinkSession();
return { id: n, secret: s };
}
async handshake() {
await this._eth_requestAccounts();
}
get selectedAddress() {
return this._addresses[0] || void 0;
}
get jsonRpcUrl() {
var e;
return (e = this._storage.getItem($t)) !== null && e !== void 0 ? e : void 0;
}
set jsonRpcUrl(e) {
this._storage.setItem($t, e);
}
updateProviderInfo(e, n) {
var s;
this.jsonRpcUrl = e;
const r = this.getChainId();
this._storage.setItem(zt, n.toString(10)), fe(n) !== r && ((s = this.callback) === null || s === void 0 || s.call(this, "chainChanged", ne(n)));
}
async watchAsset(e) {
const n = Array.isArray(e) ? e[0] : e;
if (!n.type)
throw P.rpc.invalidParams("Type is required");
if (n?.type !== "ERC20")
throw P.rpc.invalidParams(`Asset of type '${n.type}' is not supported`);
if (!n?.options)
throw P.rpc.invalidParams("Options are required");
if (!n?.options.address)
throw P.rpc.invalidParams("Address is required");
const s = this.getChainId(), { address: r, symbol: i, image: a, decimals: o } = n.options, u = await this.initializeRelay().watchAsset(n.type, r, i, o, a, s?.toString());
return F(u) ? !1 : !!u.result;
}
async addEthereumChain(e) {
var n, s;
const r = e[0];
if (((n = r.rpcUrls) === null || n === void 0 ? void 0 : n.length) === 0)
throw P.rpc.invalidParams("please pass in at least 1 rpcUrl");
if (!r.chainName || r.chainName.trim() === "")
throw P.rpc.invalidParams("chainName is a required field");
if (!r.nativeCurrency)
throw P.rpc.invalidParams("nativeCurrency is a required field");
const i = Number.parseInt(r.chainId, 16);
if (i === this.getChainId())
return !1;
const a = this.initializeRelay(), { rpcUrls: o = [], blockExplorerUrls: h = [], chainName: u, iconUrls: g = [], nativeCurrency: d } = r, l = await a.addEthereumChain(i.toString(), o, g, h, u, d);
if (F(l))
return !1;
if (((s = l.result) === null || s === void 0 ? void 0 : s.isApproved) === !0)
return this.updateProviderInfo(o[0], i), null;
throw P.rpc.internal("unable to add ethereum chain");
}
async switchEthereumChain(e) {
const n = e[0], s = Number.parseInt(n.chainId, 16), i = await this.initializeRelay().switchEthereumChain(s.toString(10), this.selectedAddress || void 0);
if (F(i))
throw i;
const a = i.result;
return a.isApproved && a.rpcUrl.length > 0 && this.updateProviderInfo(a.rpcUrl, s), null;
}
async cleanup() {
this.callback = null, this._relay && this._relay.resetAndReload(), this._storage.clear();
}
_setAddresses(e, n) {
var s;
if (!Array.isArray(e))
throw new Error("addresses is not an array");
const r = e.map((i) => ee(i));
JSON.stringify(r) !== JSON.stringify(this._addresses) && (this._addresses = r, (s = this.callback) === null || s === void 0 || s.call(this, "accountsChanged", r), this._storage.setItem(Ge, r.join(" ")));
}
async request(e) {
const n = e.params || [];
switch (e.method) {
case "eth_accounts":
return [...this._addresses];
case "eth_coinbase":
return this.selectedAddress || null;
case "net_version":
return this.getChainId().toString(10);
case "eth_chainId":
return ne(this.getChainId());
case "eth_requestAccounts":
return this._eth_requestAccounts();
case "eth_ecRecover":
case "personal_ecRecover":
return this.ecRecover(e);
case "personal_sign":
return this.personalSign(e);
case "eth_signTransaction":
return this._eth_signTransaction(n);
case "eth_sendRawTransaction":
return this._eth_sendRawTransaction(n);
case "eth_sendTransaction":
return this._eth_sendTransaction(n);
case "eth_signTypedData_v1":
case "eth_signTypedData_v3":
case "eth_signTypedData_v4":
case "eth_signTypedData":
return this.signTypedData(e);
case "wallet_addEthereumChain":
return this.addEthereumChain(n);
case "wallet_switchEthereumChain":
return this.switchEthereumChain(n);
case "wallet_watchAsset":
return this.watchAsset(n);
default:
if (!this.jsonRpcUrl)
throw P.rpc.internal("No RPC URL set for chain");
return rt(e, this.jsonRpcUrl);
}
}
_ensureKnownAddress(e) {
const n = ee(e);
if (!this._addresses.map((r) => ee(r)).includes(n))
throw new Error("Unknown Ethereum address");
}
_prepareTransactionParams(e) {
const n = e.from ? ee(e.from) : this.selectedAddress;
if (!n)
throw new Error("Ethereum address is unavailable");
this._ensureKnownAddress(n);
const s = e.to ? ee(e.to) : null, r = e.value != null ? le(e.value) : BigInt(0), i = e.data ? $e(e.data) : Buffer.alloc(0), a = e.nonce != null ? fe(e.nonce) : null, o = e.gasPrice != null ? le(e.gasPrice) : null, h = e.maxFeePerGas != null ? le(e.maxFeePerGas) : null, u = e.maxPriorityFeePerGas != null ? le(e.maxPriorityFeePerGas) : null, g = e.gas != null ? le(e.gas) : null, d = e.chainId ? fe(e.chainId) : this.getChainId();
return {
fromAddress: n,
toAddress: s,
weiValue: r,
data: i,
nonce: a,
gasPriceInWei: o,
maxFeePerGas: h,
maxPriorityFeePerGas: u,
gasLimit: g,
chainId: d
};
}
async ecRecover(e) {
const { method: n, params: s } = e;
if (!Array.isArray(s))
throw P.rpc.invalidParams();
const i = await this.initializeRelay().sendRequest({
method: "ethereumAddressFromSignedMessage",
params: {
message: Ne(s[0]),
signature: Ne(s[1]),
addPrefix: n === "personal_ecRecover"
}
});
if (F(i))
throw i;
return i.result;
}
getChainId() {
var e;
return Number.parseInt((e = this._storage.getItem(zt)) !== null && e !== void 0 ? e : "1", 10);
}
async _eth_requestAccounts() {
var e, n;
if (this._addresses.length > 0)
return (e = this.callback) === null || e === void 0 || e.call(this, "connect", { chainId: ne(this.getChainId()) }), this._addresses;
const r = await this.initializeRelay().requestEthereumAccounts();
if (F(r))
throw r;
if (!r.result)
throw new Error("accounts received is empty");
return this._setAddresses(r.result), (n = this.callback) === null || n === void 0 || n.call(this, "connect", { chainId: ne(this.getChainId()) }), this._addresses;
}
async personalSign({ params: e }) {
if (!Array.isArray(e))
throw P.rpc.invalidParams();
const n = e[1], s = e[0];
this._ensureKnownAddress(n);
const i = await this.initializeRelay().sendRequest({
method: "signEthereumMessage",
params: {
address: ee(n),
message: Ne(s),
addPrefix: !0,
typedDataJson: null
}
});
if (F(i))
throw i;
return i.result;
}
async _eth_signTransaction(e) {
const n = this._prepareTransactionParams(e[0] || {}), r = await this.initializeRelay().signEthereumTransaction(n);
if (F(r))
throw r;
return r.result;
}
async _eth_sendRawTransaction(e) {
const n = $e(e[0]), r = await this.initializeRelay().submitEthereumTransaction(n, this.getChainId());
if (F(r))
throw r;
return r.result;
}
async _eth_sendTransaction(e) {
const n = this._prepareTransactionParams(e[0] || {}), r = await this.initializeRelay().signAndSubmitEthereumTransaction(n);
if (F(r))
throw r;
return r.result;
}
async signTypedData(e) {
const { method: n, params: s } = e;
if (!Array.isArray(s))
throw P.rpc.invalidParams();
const r = (u) => {
const g = {
eth_signTypedData_v1: ye.hashForSignTypedDataLegacy,
eth_signTypedData_v3: ye.hashForSignTypedData_v3,
eth_signTypedData_v4: ye.hashForSignTypedData_v4,
eth_signTypedData: ye.hashForSignTypedData_v4
};
return he(g[n]({
data: Gn(u)
}), !0);
}, i = s[n === "eth_signTypedData_v1" ? 1 : 0], a = s[n === "eth_signTypedData_v1" ? 0 : 1];
this._ensureKnownAddress(i);
const h = await this.initializeRelay().sendRequest({
method: "signEthereumMessage",
params: {
address: ee(i),
message: r(a),
typedDataJson: JSON.stringify(a, null, 2),
addPrefix: !1
}
});
if (F(h))
throw h;
return h.result;
}
initializeRelay() {
return this._relay || (this._relay = new Z({
linkAPIUrl: Kt,
storage: this._storage,
metadata: this.metadata,
accountsCallback: this._setAddresses.bind(this),
chainCallback: this.updateProviderInfo.bind(this)
})), this._relay;
}
}
const xn = "SignerType", Mn = new J("CBWSDK", "SignerConfigurator");
function Ys() {
return Mn.getItem(xn);
}
function Vs(t) {
Mn.setItem(xn, t);
}
async function Js(t) {
const { communicator: e, metadata: n, handshakeRequest: s, callback: r } = t;
Zs(e, n, r).catch(() => {
});
const i = {
id: crypto.randomUUID(),
event: "selectSignerType",
data: Object.assign(Object.assign({}, t.preference), { handshakeRequest: s })
}, { data: a } = await e.postRequestAndWaitForResponse(i);
return a;
}
function Qs(t) {
const { signerType: e, metadata: n, communicator: s, callback: r } = t;
switch (e) {
case "scw":
return new os({
metadata: n,
callback: r,
communicator: s
});
case "walletlink":
return new Pn({
metadata: n,
callback: r
});
}
}
async function Zs(t, e, n) {
await t.onMessage(({ event: r }) => r === "WalletLinkSessionRequest");
const s = new Pn({
metadata: e,
callback: n
});
t.postMessage({
event: "WalletLinkUpdate",
data: { session: s.getSession() }
}), await s.handshake(), t.postMessage({
event: "WalletLinkUpdate",
data: { connected: !0 }
});
}
const Xs = `Coinbase Wallet SDK requires the Cross-Origin-Opener-Policy header to not be set to 'same-origin'. This is to ensure that the SDK can communicate with the Coinbase Smart Wallet app.
Please see https://www.smartwallet.dev/guides/tips/popup-tips#cross-origin-opener-policy for more information.`, ei = () => {
let t;
return {
getCrossOriginOpenerPolicy: () => t === void 0 ? "undefined" : t,
checkCrossOriginOpenerPolicy: async () => {
if (typeof window > "u") {
t = "non-browser-env";
return;
}
try {
const e = `${window.location.origin}${window.location.pathname}`, n = await fetch(e, {
method: "HEAD"
});
if (!n.ok)
throw new Error(`HTTP error! status: ${n.status}`);
const s = n.headers.get("Cross-Origin-Opener-Policy");
t = s ?? "null", t === "same-origin" && console.error(Xs);
} catch (e) {
console.error("Error checking Cross-Origin-Opener-Policy:", e.message), t = "error";
}
}
};
}, { checkCrossOriginOpenerPolicy: ti, getCrossOriginOpenerPolicy: ni } = ei(), Gt = 420, Yt = 540, si = {
isRed: !1,
info: "Retry",
svgWidth: "10",
svgHeight: "11",
path: Ln,
defaultFillRule: "evenodd",
defaultClipRule: "evenodd"
}, ii = "Popup was blocked. Try again.";
let we = null;
function ri(t) {
const e = (window.innerWidth - Gt) / 2 + window.screenX, n = (window.innerHeight - Yt) / 2 + window.screenY;
oi(t);
function s() {
const i = `wallet_${crypto.randomUUID()}`, a = window.open(t, i, `width=${Gt}, height=${Yt}, left=${e}, top=${n}`);
return a?.focus(), a || null;
}
let r = s();
if (!r) {
const i = ci();
return new Promise((a, o) => {
i.presentItem({
autoExpand: !0,
message: ii,
menuItems: [
Object.assign(Object.assign({}, si), { onClick: () => {
r = s(), r ? a(r) : o(P.rpc.internal("Popup window was blocked")), i.clear();
} })
]
});
});
}
return Promise.resolve(r);
}
function ai(t) {
t && !t.closed && t.close();
}
function oi(t) {
const e = {
sdkName: cn,
sdkVersion: me,
origin: window.location.origin,
coop: ni()
};
for (const [n, s] of Object.entries(e))
t.searchParams.append(n, s.toString());
}
function ci() {
if (!we) {
const t = document.createElement("div");
t.className = "-cbwsdk-css-reset", document.body.appendChild(t), we = new Cn(), we.attach(t);
}
return we;
}
class di {
constructor({ url: e = zs, metadata: n, preference: s }) {
this.popup = null, this.listeners = /* @__PURE__ */ new Map(), this.postMessage = async (r) => {
(await this.waitForPopupLoaded()).postMessage(r, this.url.origin);
}, this.postRequestAndWaitForResponse = async (r) => {
const i = this.onMessage(({ requestId: a }) => a === r.id);
return this.postMessage(r), await i;
}, this.onMessage = async (r) => new Promise((i, a) => {
const o = (h) => {
if (h.origin !== this.url.origin)
return;
const u = h.data;
r(u) && (i(u), window.removeEventListener("message", o), this.listeners.delete(o));
};
window.addEventListener("message", o), this.listeners.set(o, { reject: a });
}), this.disconnect = () => {
ai(this.popup), this.popup = null, this.listeners.forEach(({ reject: r }, i) => {
r(P.provider.userRejectedRequest("Request rejected")), window.removeEventListener("message", i);
}), this.listeners.clear();
}, this.waitForPopupLoaded = async () => this.popup && !this.popup.closed ? (this.popup.focus(), this.popup) : (this.popup = await ri(this.url), this.onMessage(({ event: r }) => r === "PopupUnload").then(this.disconnect).catch(() => {
}), this.onMessage(({ event: r }) => r === "PopupLoaded").then((r) => {
this.postMessage({
requestId: r.id,
data: {
version: me,
metadata: this.metadata,
preference: this.preference,
location: window.location.toString()
}
});
}).then(() => {
if (!this.popup)
throw P.rpc.internal();
return this.popup;
})), this.url = new URL(e), this.metadata = n, this.preference = s;
}
}
function li(t) {
const e = qn(ui(t), {
shouldIncludeStack: !0
}), n = new URL("https://docs.cloud.coinbase.com/wallet-sdk/docs/errors");
return n.searchParams.set("version", me), n.searchParams.set("code", e.code.toString()), n.searchParams.set("message", e.message), Object.assign(Object.assign({}, e), { docUrl: n.href });
}
function ui(t) {
var e;
if (typeof t == "string")
return {
message: t,
code: j.rpc.internal
};
if (F(t)) {
const n = t.errorMessage, s = (e = t.errorCode) !== null && e !== void 0 ? e : n.match(/(denied|rejected)/i) ? j.provider.userRejectedRequest : void 0;
return Object.assign(Object.assign({}, t), {
message: n,
code: s,
data: { method: t.method }
});
}
return t;
}
class hi extends Bn {
}
var fi = function(t, e) {
var n = {};
for (var s in t) Object.prototype.hasOwnProperty.call(t, s) && e.indexOf(s) < 0 && (n[s] = t[s]);
if (t != null && typeof Object.getOwnPropertySymbols == "function")
for (var r = 0, s = Object.getOwnPropertySymbols(t); r < s.length; r++)
e.indexOf(s[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, s[r]) && (n[s[r]] = t[s[r]]);
return n;
};
class pi extends hi {
constructor(e) {
var { metadata: n } = e, s = e.preference, { keysUrl: r } = s, i = fi(s, ["keysUrl"]);
super(), this.signer = null, this.isCoinbaseWallet = !0, this.metadata = n, this.preference = i, this.communicator = new di({
url: r,
metadata: n,
preference: i
});
const a = Ys();
a && (this.signer = this.initSigner(a));
}
async request(e) {
try {
if (as(e), !this.signer)
switch (e.method) {
case "eth_requestAccounts": {
const n = await this.requestSignerSelection(e), s = this.initSigner(n);
await s.handshake(e), this.signer = s, Vs(n);
break;
}
case "wallet_sendCalls": {
const n = this.initSigner("scw");
await n.handshake({ method: "handshake" });
const s = await n.request(e);
return await n.cleanup(), s;
}
case "wallet_getCallsStatus":
return rt(e, $s);
case "net_version":
return 1;
// default value
case "eth_chainId":
return ne(1);
// default value
default:
throw P.provider.unauthorized("Must call 'eth_requestAccounts' before other methods");
}
return await this.signer.request(e);
} catch (n) {
const { code: s } = n;
return s === j.provider.unauthorized && this.disconnect(), Promise.reject(li(n));
}
}
/** @deprecated Use `.request({ method: 'eth_requestAccounts' })` instead. */
async enable() {
return console.warn('.enable() has been deprecated. Please use .request({ method: "eth_requestAccounts" }) instead.'), await this.request({
method: "eth_requestAccounts"
});
}
async disconnect() {
var e;
await ((e = this.signer) === null || e === void 0 ? void 0 : e.cleanup()), this.signer = null, J.clearAll(), this.emit("disconnect", P.provider.disconnected("User initiated disconnection"));
}
requestSignerSelection(e) {
return Js({
communicator: this.communicator,
preference: this.preference,
metadata: this.metadata,
handshakeRequest: e,
callback: this.emit.bind(this)
});
}
initSigner(e) {
return Qs({
signerType: e,
metadata: this.metadata,
communicator: this.communicator,
callback: this.emit.bind(this)
});
}
}
function gi(t) {
if (t) {
if (!["all", "smartWalletOnly", "eoaOnly"].includes(t.options))
throw new Error(`Invalid options: ${t.options}`);
if (t.attribution && t.attribution.auto !== void 0 && t.attribution.dataSuffix !== void 0)
throw new Error("Attribution cannot contain both auto and dataSuffix properties");
}
}
function _i(t) {
var e;
const n = {
metadata: t.metadata,
preference: t.preference
};
return (e = rs(n)) !== null && e !== void 0 ? e : new pi(n);
}
const mi = {
options: "all"
};
function wi(t) {
var e;
new J("CBWSDK").setItem("VERSION", me), ti();
const s = {
metadata: {
appName: t.appName || "Dapp",
appLogoUrl: t.appLogoUrl || "",
appChainIds: t.appChainIds || []
},
preference: Object.assign(mi, (e = t.preference) !== null && e !== void 0 ? e : {})
};
gi(s.preference);
let r = null;
return {
getProvider: () => (r || (r = _i(s)), r)
};
}
export {
wi as createCoinbaseWalletSDK
};