From 7152200be28dd1c5dd35b7376df7260569f4a3b5 Mon Sep 17 00:00:00 2001 From: Alex Jbanca Date: Tue, 24 Sep 2024 11:26:28 +0300 Subject: [PATCH] draft: Remove the business logic from UI components --- storybook/pages/DAppsWorkflowPage.qml | 37 +- .../src/StatusQ/Core/Utils/ModelUtils.qml | 12 + .../Wallet/panels/DAppsWorkflow.qml | 304 ++++++----- .../AppLayouts/Wallet/panels/WalletHeader.qml | 39 +- .../dapps/ConnectorDAppsListProvider.qml | 62 ++- .../services/dapps/DAppsListProvider.qml | 38 +- .../services/dapps/DAppsRequestHandler.qml | 77 +-- .../services/dapps/DappsConnectorSDK.qml | 32 +- .../services/dapps/WalletConnectSDK.qml | 43 +- .../services/dapps/WalletConnectSDKBase.qml | 9 +- .../services/dapps/WalletConnectService.qml | 482 +++++++++++------- .../services/dapps/sdk/generated/bundle.js | 2 +- .../services/dapps/sdk/package-lock.json | 87 ++-- .../Wallet/services/dapps/sdk/package.json | 2 +- .../Wallet/services/dapps/sdk/src/index.js | 4 +- .../dapps/types/SessionRequestResolved.qml | 26 +- .../dapps/types/SessionRequestsModel.qml | 19 +- .../Wallet/services/dapps/types/qmldir | 1 + .../popups/walletconnect/ConnectDAppModal.qml | 4 +- .../walletconnect/DAppSignRequestModal.qml | 8 +- ui/imports/utils/Constants.qml | 5 + 21 files changed, 799 insertions(+), 494 deletions(-) diff --git a/storybook/pages/DAppsWorkflowPage.qml b/storybook/pages/DAppsWorkflowPage.qml index 99edee61bf3..f276532682b 100644 --- a/storybook/pages/DAppsWorkflowPage.qml +++ b/storybook/pages/DAppsWorkflowPage.qml @@ -63,9 +63,42 @@ Item { spacing: 8 - wcService: walletConnectService + readonly property var wcService: walletConnectService loginType: Constants.LoginType.Biometrics selectedAccountAddress: "" + + model: wcService.dappsModel + accountsModel: wcService.validAccounts + networksModel: wcService.flatNetworks + sessionRequestsModel: wcService.sessionRequestsModel + + //formatBigNumber: (number, symbol, noSymbolOption) => wcService.walletRootStore.currencyStore.formatBigNumber(number, symbol, noSymbolOption) + + onDisconnectRequested: (connectionId) => wcService.disconnectDapp(connectionId) + onPairingRequested: (uri) => wcService.pair(uri) + onPairingValidationRequested: (uri) => wcService.validatePairingUri(uri) + onConnectionAccepted: (pairingId, chainIds, selectedAccount) => wcService.approvePairSession(pairingId, chainIds, selectedAccount) + onConnectionDeclined: (pairingId) => wcService.rejectPairSession(pairingId) + onSignRequestAccepted: (connectionId, requestId) => wcService.sign(connectionId, requestId) + onSignRequestRejected: (connectionId, requestId) => wcService.rejectSign(connectionId, requestId, false /*hasError*/) + + Connections { + target: dappsWorkflow.wcService + function onPairingValidated(validationState) { + dappsWorkflow.pairingValidated(validationState) + } + function onApproveSessionResult(pairingId, err, newConnectionId) { + if (err) { + dappsWorkflow.connectionFailed(pairingId) + return + } + + dappsWorkflow.connectionSuccessful(pairingId, newConnectionId) + } + function onConnectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) { + dappsWorkflow.connectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) + } + } } } ColumnLayout {} @@ -128,7 +161,7 @@ Item { ListView { Layout.fillWidth: true Layout.preferredHeight: Math.min(50, contentHeight) - model: walletConnectService.requestHandler.requestsModel + model: walletConnectService.sessionRequestsModel delegate: RowLayout { StatusBaseText { text: SQUtils.Utils.elideAndFormatWalletAddress(model.topic, 6, 4) diff --git a/ui/StatusQ/src/StatusQ/Core/Utils/ModelUtils.qml b/ui/StatusQ/src/StatusQ/Core/Utils/ModelUtils.qml index 166d5019ec0..8d4c1796245 100644 --- a/ui/StatusQ/src/StatusQ/Core/Utils/ModelUtils.qml +++ b/ui/StatusQ/src/StatusQ/Core/Utils/ModelUtils.qml @@ -157,4 +157,16 @@ QtObject { return null } + + function forEach(model, callback) { + if (!model) + return + + const count = model.rowCount() + + for (let i = 0; i < count; i++) { + const modelItem = Internal.ModelUtils.get(model, i) + callback(modelItem) + } + } } diff --git a/ui/app/AppLayouts/Wallet/panels/DAppsWorkflow.qml b/ui/app/AppLayouts/Wallet/panels/DAppsWorkflow.qml index 8e9309caf4f..815180e24b3 100644 --- a/ui/app/AppLayouts/Wallet/panels/DAppsWorkflow.qml +++ b/ui/app/AppLayouts/Wallet/panels/DAppsWorkflow.qml @@ -18,14 +18,46 @@ import utils 1.0 DappsComboBox { id: root - required property WalletConnectService wcService // Values mapped to Constants.LoginType required property int loginType + property var accountsModel + property var networksModel + property SessionRequestsModel sessionRequestsModel property string selectedAccountAddress + property var formatBigNumber: (number, symbol, noSymbolOption) => console.error("formatBigNumber not set") + signal pairWCReady() - model: root.wcService.dappsModel + signal disconnectRequested(string connectionId) + signal pairingRequested(string uri) + signal pairingValidationRequested(string uri) + signal connectionAccepted(var pairingId, var chainIds, string selectedAccount) + signal connectionDeclined(var pairingId) + signal signRequestAccepted(string connectionId, string requestId) + signal signRequestRejected(string connectionId, string requestId) + + /// Response to pairingValidationRequested + function pairingValidated(validationState) { + if (pairWCLoader.item) { + pairWCLoader.item.pairingValidated(validationState) + } + } + + /// Confirmation received on connectionAccepted + function connectionSuccessful(pairingId, newConnectionId) { + connectDappLoader.connectionSuccessful(pairingId, newConnectionId) + } + + /// Confirmation received on connectionAccepted + function connectionFailed(pairingId) { + connectDappLoader.connectionFailed(pairingId) + } + + /// Request to connect to a dApp + function connectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) { + connectDappLoader.connect(dappChains, dappUrl, dappName, dappIcon, pairingId) + } onPairDapp: { pairWCLoader.active = true @@ -44,7 +76,7 @@ DappsComboBox { active: false onLoaded: { - const dApp = wcService.getDApp(dAppUrl); + const dApp = SQUtils.ModelUtils.getByKey(root.model, "url", dAppUrl); if (dApp) { item.dappName = dApp.name; item.dappIcon = dApp.iconUrl; @@ -63,7 +95,11 @@ DappsComboBox { } onAccepted: { - root.wcService.disconnectDapp(dappUrl) + SQUtils.ModelUtils.forEach(model, (dApp) => { + if (dApp.url === dAppUrl) { + root.disconnectRequested(dApp.topic) + } + }) } } } @@ -82,15 +118,8 @@ DappsComboBox { visible: true onClosed: pairWCLoader.active = false - - onPair: (uri) => { - this.isPairing = true - root.wcService.pair(uri) - } - - onPairUriChanged: (uri) => { - root.wcService.validatePairingUri(uri) - } + onPair: (uri) => root.pairingRequested(uri) + onPairUriChanged: (uri) => root.pairingValidationRequested(uri) } } @@ -99,21 +128,67 @@ DappsComboBox { active: false - property var dappChains: [] - property var sessionProposal: null - property var availableNamespaces: null - property var sessionTopic: null - readonly property var proposalMedatada: !!sessionProposal - ? sessionProposal.params.proposer.metadata - : { name: "", url: "", icons: [] } + // Array of chaind ids + property var dappChains + property url dappUrl + property string dappName + property url dappIcon + property var key + property var topic + + property var connectionQueue: [] + onActiveChanged: { + if (!active && connectionQueue.length > 0) { + connect(connectionQueue[0].dappChains, + connectionQueue[0].dappUrl, + connectionQueue[0].dappName, + connectionQueue[0].dappIcon, + connectionQueue[0].key) + connectionQueue.shift() + } + } + + function connect(dappChains, dappUrl, dappName, dappIcon, key) { + if (connectDappLoader.active) { + connectionQueue.push({ dappChains, dappUrl, dappName, dappIcon, key }) + return + } + + connectDappLoader.dappChains = dappChains + connectDappLoader.dappUrl = dappUrl + connectDappLoader.dappName = dappName + connectDappLoader.dappIcon = dappIcon + connectDappLoader.key = key + + if (pairWCLoader.item) { + // Allow user to get the uri valid confirmation + pairWCLoader.item.pairingValidated(Pairing.errors.dappReadyForApproval) + connectDappTimer.start() + } else { + connectDappLoader.active = true + } + } + + function connectionSuccessful(key, newTopic) { + if (connectDappLoader.key === key && connectDappLoader.item) { + connectDappLoader.topic = newTopic + connectDappLoader.item.pairSuccessful() + } + } + + function connectionFailed(id) { + if (connectDappLoader.key === key && connectDappLoader.item) { + connectDappLoader.item.pairFailed() + } + } sourceComponent: ConnectDAppModal { visible: true - + onClosed: connectDappLoader.active = false - accounts: root.wcService.validAccounts + accounts: root.accountsModel flatNetworks: SortFilterProxyModel { - sourceModel: root.wcService.flatNetworks + sourceModel: root.networksModel filters: [ FastExpressionFilter { inverted: true @@ -124,41 +199,45 @@ DappsComboBox { } selectedAccountAddress: root.selectedAccountAddress - dAppUrl: proposalMedatada.url - dAppName: proposalMedatada.name - dAppIconUrl: !!proposalMedatada.icons && proposalMedatada.icons.length > 0 ? proposalMedatada.icons[0] : "" + dAppUrl: connectDappLoader.dappUrl + dAppName: connectDappLoader.dappName + dAppIconUrl: connectDappLoader.dappIcon onConnect: { - root.wcService.approvePairSession(sessionProposal, selectedChains, selectedAccount) + if (!selectedAccount || !selectedAccount.address) { + console.error("Missing account selection") + return + } + if (!selectedChains || selectedChains.length === 0) { + console.error("Missing chain selection") + return + } + + root.connectionAccepted(connectDappLoader.key, selectedChains, selectedAccount.address) } onDecline: { - connectDappLoader.active = false - root.wcService.rejectPairSession(sessionProposal.id) + root.connectionDeclined(connectDappLoader.key) + close() } - onDisconnect: { - connectDappLoader.active = false - root.wcService.disconnectSession(sessionTopic) + onDisconnect: { + root.disconnectRequested(connectDappLoader.topic) + close() } } } - Loader { - id: sessionRequestLoader - - active: false - - onLoaded: item.open() - - property SessionRequestResolved request: null - property bool requestHandled: false - - sourceComponent: DAppSignRequestModal { + Instantiator { + model: root.sessionRequestsModel + delegate: DAppSignRequestModal { id: dappRequestModal objectName: "dappsRequestModal" - property var feesInfo: null + required property var model + required property int index + + readonly property var request: model.requestItem readonly property var account: accountEntry.available ? accountEntry.item : { name: "", address: "", @@ -170,10 +249,24 @@ DappsComboBox { chainName: "", iconUrl: "" } + property bool requestHandled: false + + function rejectRequest() { + // Allow rejecting only once + if (requestHandled) { + return + } + requestHandled = true + let userRejected = true + root.signRequestRejected(request.topic, request.id) + } + + parent: root loginType: account.migragedToKeycard ? Constants.LoginType.Keycard : root.loginType - formatBigNumber: (number, symbol, noSymbolOption) => root.wcService.walletRootStore.currencyStore.formatBigNumber(number, symbol, noSymbolOption) - visible: true + formatBigNumber: root.formatBigNumber + + visible: !!request.dappUrl dappUrl: request.dappUrl dappIcon: request.dappIcon @@ -187,143 +280,48 @@ DappsComboBox { networkName: network.chainName networkIconPath: Style.svg(network.iconUrl) - fiatFees: request.maxFeesText - cryptoFees: request.maxFeesEthText - estimatedTime: "" - feesLoading: !request.maxFeesText || !request.maxFeesEthText + fiatFees: request.fiatMaxFees ? request.fiatMaxFees.toFixed() : "" + cryptoFees: request.ethMaxFees ? request.ethMaxFees.toFixed() : "" + estimatedTime: WalletUtils.getLabelForEstimatedTxTime(request.estimatedTimeCategory) + feesLoading: hasFees && (!fiatFees || !cryptoFees) hasFees: signingTransaction - enoughFundsForTransaction: request.enoughFunds - enoughFundsForFees: request.enoughFunds + enoughFundsForTransaction: request.haveEnoughFunds + enoughFundsForFees: request.haveEnoughFees signingTransaction: !!request.method && (request.method === SessionRequest.methods.signTransaction.name || request.method === SessionRequest.methods.sendTransaction.name) requestPayload: request.preparedData + expirationSeconds: request.expirationTimestamp - requestTimestamp.getTime() / 1000 + onClosed: { - Qt.callLater( () => { - rejectRequest() - sessionRequestLoader.active = false - }) + Qt.callLater(rejectRequest) } onAccepted: { - if (!request) { - console.error("Error signing: request is null") - return - } - requestHandled = true - root.wcService.requestHandler.authenticate(request, JSON.stringify(feesInfo)) + root.signRequestAccepted(request.topic, request.id) } onRejected: { rejectRequest() } - function rejectRequest() { - // Allow rejecting only once - if (requestHandled) { - return - } - requestHandled = true - let userRejected = true - root.wcService.requestHandler.rejectSessionRequest(request, userRejected) - } - - Connections { - target: root.wcService.requestHandler - - function onMaxFeesUpdated(fiatMaxFees, ethMaxFees, haveEnoughFunds, haveEnoughFees, symbol, feesInfo) { - dappRequestModal.hasFees = !!ethMaxFees - dappRequestModal.feesLoading = !dappRequestModal.hasFees - if (!dappRequestModal.hasFees) { - return - } - dappRequestModal.fiatFees = fiatMaxFees.toFixed() - dappRequestModal.cryptoFees = ethMaxFees.toFixed() - dappRequestModal.enoughFundsForTransaction = haveEnoughFunds - dappRequestModal.enoughFundsForFees = haveEnoughFees - dappRequestModal.feesInfo = feesInfo - } - - function onEstimatedTimeUpdated(estimatedTimeEnum) { - dappRequestModal.estimatedTime = WalletUtils.getLabelForEstimatedTxTime(estimatedTimeEnum) - } - } - ModelEntry { id: accountEntry - sourceModel: root.wcService.validAccounts + sourceModel: root.accountsModel key: "address" value: request.accountAddress } ModelEntry { id: networkEntry - sourceModel: root.wcService.flatNetworks + sourceModel: root.networksModel key: "chainId" value: request.chainId } } } - Connections { - target: root.wcService ? root.wcService.requestHandler : null - - function onSessionRequestResult(request, isSuccess) { - if (isSuccess) { - sessionRequestLoader.active = false - } else { - // TODO #14762 handle the error case - let userRejected = false - root.wcService.requestHandler.rejectSessionRequest(request, userRejected) - } - } - } - - Connections { - target: root.wcService - - function onPairingValidated(validationState) { - if (pairWCLoader.item) { - pairWCLoader.item.pairingValidated(validationState) - } - } - - function onConnectDApp(dappChains, sessionProposal, availableNamespaces) { - connectDappLoader.dappChains = dappChains - connectDappLoader.sessionProposal = sessionProposal - connectDappLoader.availableNamespaces = availableNamespaces - connectDappLoader.sessionTopic = null - - if (pairWCLoader.item) { - // Allow user to get the uri valid confirmation - pairWCLoader.item.pairingValidated(Pairing.errors.dappReadyForApproval) - connectDappTimer.start() - } else { - connectDappLoader.active = true - } - } - - function onApproveSessionResult(session, err) { - connectDappLoader.sessionTopic = session.topic - - let modal = connectDappLoader.item - if (!!modal) { - if (err) { - modal.pairFailed(session, err) - } else { - modal.pairSuccessful(session) - } - } - } - - function onSessionRequest(request) { - sessionRequestLoader.request = request - sessionRequestLoader.requestHandled = false - sessionRequestLoader.active = true - } - } - // Used between transitioning from PairWCModal to ConnectDAppModal Timer { id: connectDappTimer diff --git a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml index 887e29da094..fec27ca765c 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml @@ -16,6 +16,7 @@ import SortFilterProxyModel 0.2 import shared.stores 1.0 import AppLayouts.Wallet.stores 1.0 as WalletStores +import AppLayouts.Wallet.services.dapps 1.0 import utils 1.0 @@ -134,19 +135,53 @@ Item { } DAppsWorkflow { + id: dappsWorkflow Layout.alignment: Qt.AlignTop + readonly property WalletConnectService wcService: Global.walletConnectService + spacing: 8 visible: !root.walletStore.showSavedAddresses && root.dappsEnabled - && Global.walletConnectService.isServiceAvailableForAddressSelection + && wcService.serviceAvailableToCurrentAddress enabled: !!Global.walletConnectService - wcService: Global.walletConnectService loginType: root.store.loginType selectedAccountAddress: root.walletStore.selectedAddress + model: wcService.dappsModel + accountsModel: wcService.validAccounts + networksModel: wcService.flatNetworks + sessionRequestsModel: wcService.sessionRequestsModel + + formatBigNumber: (number, symbol, noSymbolOption) => wcService.walletRootStore.currencyStore.formatBigNumber(number, symbol, noSymbolOption) + + onDisconnectRequested: (connectionId) => wcService.disconnectDapp(connectionId) + onPairingRequested: (uri) => wcService.pair(uri) + onPairingValidationRequested: (uri) => wcService.validatePairingUri(uri) + onConnectionAccepted: (pairingId, chainIds, selectedAccount) => wcService.approvePairSession(pairingId, chainIds, selectedAccount) + onConnectionDeclined: (pairingId) => wcService.rejectPairSession(pairingId) + onSignRequestAccepted: (connectionId, requestId) => wcService.sign(connectionId, requestId) + onSignRequestRejected: (connectionId, requestId) => wcService.rejectSign(connectionId, requestId, false /*hasError*/) + + Connections { + target: dappsWorkflow.wcService + function onPairingValidated(validationState) { + dappsWorkflow.pairingValidated(validationState) + } + function onApproveSessionResult(pairingId, err, newConnectionId) { + if (err) { + dappsWorkflow.connectionFailed(pairingId) + return + } + + dappsWorkflow.connectionSuccessful(pairingId, newConnectionId) + } + function onConnectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) { + dappsWorkflow.connectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) + } + } } StatusButton { diff --git a/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml b/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml index ba49a136e15..438083506fb 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml @@ -1,6 +1,8 @@ import QtQuick 2.15 -import StatusQ.Core.Utils 0.1 + import AppLayouts.Wallet.services.dapps 1.0 +import StatusQ.Core.Utils 0.1 + import shared.stores 1.0 import utils 1.0 @@ -8,17 +10,39 @@ QObject { id: root readonly property alias dappsModel: d.dappsModel + readonly property int connectorId: Constants.StatusConnect + + function addSession(url, name, iconUrl, accountAddress) { + if (!url || !name || !iconUrl || !accountAddress) { + console.error("addSession: missing required parameters") + return + } - function addSession(session) { - d.addSession(session) + const topic = url + const activeSession = getActiveSession(topic) + if (!activeSession) { + d.addSession({ + url, + name, + iconUrl, + topic, + connectorId: root.connectorId, + accountAddresses: [{address: accountAddress}] + }) + return + } + + if (!ModelUtils.contains(activeSession.accountAddresses, "address", accountAddress, Qt.CaseInsensitive)) { + activeSession.accountAddresses.append({address: accountAddress}) + } } - function revokeSession(session) { - d.revokeSession(session) + function revokeSession(topic) { + d.revokeSession(topic) } - function getActiveSession(dAppUrl) { - return d.getActionSession(dAppUrl) + function getActiveSession(topic) { + return d.getActiveSession(topic) } QObject { @@ -28,16 +52,14 @@ QObject { id: dapps } - function addSession(dappInfo) { - let dappItem = JSON.parse(dappInfo) + function addSession(dappItem) { dapps.append(dappItem) } - function revokeSession(dappInfo) { - let dappItem = JSON.parse(dappInfo) + function revokeSession(topic) { for (let i = 0; i < dapps.count; i++) { let existingDapp = dapps.get(i) - if (existingDapp.url === dappItem.url) { + if (existingDapp.topic === topic) { dapps.remove(i) break } @@ -50,19 +72,21 @@ QObject { } } - function getActionSession(dAppUrl) { + function getActiveSession(topic) { for (let i = 0; i < dapps.count; i++) { - let existingDapp = dapps.get(i) + const existingDapp = dapps.get(i) - if (existingDapp.url === dAppUrl) { - return JSON.stringify({ + if (existingDapp.topic === topic) { + return { name: existingDapp.name, url: existingDapp.url, - icon: existingDapp.iconUrl - }); + icon: existingDapp.iconUrl, + topic: existingDapp.topic, + connectorId: existingDapp.connectorId, + accountAddresses: existingDapp.accountAddresses + }; } } - return null } } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml index a12a45545ef..fdfbde62489 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml @@ -3,8 +3,6 @@ import QtQuick 2.15 import StatusQ 0.1 import StatusQ.Core.Utils 0.1 -import SortFilterProxyModel 0.2 - import AppLayouts.Wallet.services.dapps 1.0 import shared.stores 1.0 @@ -17,25 +15,8 @@ QObject { required property WalletConnectSDKBase sdk required property DAppsStore store required property var supportedAccountsModel - - property string selectedAddress: "" - - readonly property SortFilterProxyModel dappsModel: SortFilterProxyModel { - objectName: "DAppsModelFiltered" - sourceModel: d.dappsModel - - filters: FastExpressionFilter { - enabled: !!root.selectedAddress - - function isAddressIncluded(accountAddressesSubModel, selectedAddress) { - const addresses = ModelUtils.modelToFlatArray(accountAddressesSubModel, "address") - return addresses.includes(root.selectedAddress) - } - expression: isAddressIncluded(model.accountAddresses, root.selectedAddress) - - expectedRoles: "accountAddresses" - } - } + readonly property int connectorId: Constants.WalletConnect + readonly property var dappsModel: d.dappsModel function updateDapps() { d.updateDappsModel() @@ -66,7 +47,10 @@ QObject { url: cachedEntry.url, name: cachedEntry.name, iconUrl: cachedEntry.iconUrl, - accountAddresses: [{address: ''}] + accountAddresses: [], + topic: "", + connectorId: root.connectorId, + sessions: [] } dapps.append(dappEntryWithRequiredRoles); } @@ -86,6 +70,7 @@ QObject { const dAppsMap = {} const topics = [] const sessions = DAppsHelpers.filterActiveSessionsForKnownAccounts(allSessionsAllProfiles, supportedAccountsModel) + for (const sessionID in sessions) { const session = sessions[sessionID] const dapp = session.peer.metadata @@ -101,11 +86,13 @@ QObject { // more modern syntax (ES-6) is not available yet const combinedAddresses = new Set(existingDApp.accountAddresses.concat(accounts)); existingDApp.accountAddresses = Array.from(combinedAddresses); + dapp.sessions = existingDApp.sessions.push(session) } else { dapp.accountAddresses = accounts + dapp.topic = sessionID + dapp.sessions = [session] dAppsMap[dapp.url] = dapp } - topics.push(sessionID) } @@ -113,11 +100,12 @@ QObject { dapps.clear(); // Iterate dAppsMap and fill dapps - for (const topic in dAppsMap) { - const dAppEntry = dAppsMap[topic]; + for (const uri in dAppsMap) { + const dAppEntry = dAppsMap[uri]; // Due to ListModel converting flat array to empty nested ListModel // having array of key value pair fixes the problem dAppEntry.accountAddresses = dAppEntry.accountAddresses.filter(account => (!!account)).map(account => ({address: account})); + dAppEntry.connectorId = root.connectorId; dapps.append(dAppEntry); } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml b/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml index bdeebd30700..1428e078cab 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml @@ -23,22 +23,17 @@ SQUtils.QObject { property alias requestsModel: requests - function rejectSessionRequest(request, userRejected) { - let error = userRejected ? false : true - sdk.rejectSessionRequest(request.topic, request.id, error) + function rejectSessionRequest(topic, id, hasError) { + sdk.rejectSessionRequest(topic, id, hasError) } /// Beware, it will fail if called multiple times before getting an answer - function authenticate(request, payload) { - return store.authenticateUser(request.topic, request.id, request.accountAddress, payload) + function authenticate(topic, id, address, payload) { + return store.authenticateUser(topic, id, address, payload) } - signal sessionRequest(SessionRequestResolved request) + signal sessionRequest(string id) signal displayToastMessage(string message, bool error) - signal sessionRequestResult(/*model entry of SessionRequestResolved*/ var request, bool isSuccess) - signal maxFeesUpdated(var /* Big */ fiatMaxFees, var /* Big */ ethMaxFees, bool haveEnoughFunds, bool haveEnoughFees, string symbol, var feesInfo) - // Reports Constants.TransactionEstimatedTime values - signal estimatedTimeUpdated(int estimatedTimeEnum) Connections { target: sdk @@ -78,7 +73,7 @@ SQUtils.QObject { if (error) { root.displayToastMessage(qsTr("Fail to %1 from %2").arg(methodStr).arg(session.peer.metadata.url), true) - root.sessionRequestResult(request, false /*isSuccessful*/) + root.rejectSessionRequest(topic, id, true /*hasError*/) console.error(`Error accepting session request for topic: ${topic}, id: ${id}, accept: ${accept}, error: ${error}`) return @@ -86,10 +81,17 @@ SQUtils.QObject { let actionStr = accept ? qsTr("accepted") : qsTr("rejected") root.displayToastMessage("%1 %2 %3".arg(session.peer.metadata.url).arg(methodStr).arg(actionStr), false) - - root.sessionRequestResult(request, true /*isSuccessful*/) }) } + + function onSessionRequestExpired(sessionId) { + let request = requests.findById(sessionId) + if (request === null) { + console.error("Error finding event for session id", sessionId) + return + } + root.rejectSessionRequest(request.topic, request.id, true /*hasError*/) + } } Connections { @@ -114,23 +116,17 @@ SQUtils.QObject { if (session === null) return root.displayToastMessage(qsTr("Failed to authenticate %1 from %2").arg(methodStr).arg(session.peer.metadata.url), true) - root.sessionRequestResult(request, false /*isSuccessful*/) + root.rejectSessionRequest(topic, id, false /*hasErrors*/) }) } function onSigningResult(topic, id, data) { - let isSuccessful = (data != "") - if (isSuccessful) { + let hasErrors = (data == "") + if (!hasErrors) { // acceptSessionRequest will trigger an sdk.sessionRequestUserAnswerResult signal sdk.acceptSessionRequest(topic, id, data) } else { - console.error("signing error") - var request = requests.findRequest(topic, id) - if (request === null) { - console.error("Error finding event for topic", topic, "id", id) - return - } - root.sessionRequestResult(request, isSuccessful) + root.rejectSessionRequest(topic, id, hasErrors) } } } @@ -167,7 +163,7 @@ SQUtils.QObject { return { obj: null, code: resolveAsyncResult.error } } - let data = extractMethodData(event, method) + const data = extractMethodData(event, method) if(!data) { console.error("Error in event data lookup", JSON.stringify(event)) return { obj: null, code: resolveAsyncResult.error } @@ -175,7 +171,9 @@ SQUtils.QObject { const interpreted = d.prepareData(method, data) - let enoughFunds = !d.isTransactionMethod(method) + const enoughFunds = !d.isTransactionMethod(method) + const requestExpiry = event.params.request.expiryTimestamp ?? 0 + let obj = sessionRequestComponent.createObject(null, { event, topic: event.topic, @@ -188,6 +186,7 @@ SQUtils.QObject { maxFeesText: "?", maxFeesEthText: "?", enoughFunds: enoughFunds, + expirationTimestamp: requestExpiry }) if (obj === null) { console.error("Error creating SessionRequestResolved for event") @@ -205,16 +204,15 @@ SQUtils.QObject { console.error("DAppsRequestHandler.lookupSession: error finding session for topic", obj.topic) return } + obj.resolveDappInfoFromSession(session) - root.sessionRequest(obj) + root.sessionRequest(obj.id) if (!d.isTransactionMethod(method)) { return } - - let estimatedTimeEnum = getEstimatedTimeInterval(data, method, obj.chainId) - root.estimatedTimeUpdated(estimatedTimeEnum) + obj.estimatedTimeCategory = getEstimatedTimeInterval(data, method, obj.chainId) const mainNet = lookupMainnetNetwork() let mainChainId = obj.chainId @@ -223,12 +221,22 @@ SQUtils.QObject { } else { console.error("Error finding mainnet network") } + print ("!!!fees Starting") let st = getEstimatedFeesStatus(data, method, obj.chainId, mainChainId) - + print("getEstimatedFeesStatus") let fundsStatus = checkFundsStatus(st.feesInfo.maxFees, st.feesInfo.l1GasFee, obj.accountAddress, obj.chainId, mainNet.chainId, interpreted.value) - - root.maxFeesUpdated(st.fiatMaxFees, st.maxFeesEth, fundsStatus.haveEnoughFunds, - fundsStatus.haveEnoughForFees, st.symbol, st.feesInfo) + print("checkFundsStatus") + obj.fiatMaxFees = st.fiatMaxFees + print ("!!!fees st.fiatMaxFees") + obj.ethMaxFees = st.maxFeesEth + print ("!!!fees st.maxFeesEth") + obj.haveEnoughFunds = fundsStatus.haveEnoughFunds + print ("!!!fees haveEnoughFunds") + obj.haveEnoughFees = fundsStatus.haveEnoughForFees + print ("!!!fees haveEnoughForFees") + obj.feesInfo = st.feesInfo + + print ("!!!fees Done", obj.haveEnoughFunds, obj.haveEnoughFees, obj.fiatMaxFees, obj.maxFeesEth, obj.feesInfo) }) return { @@ -696,6 +704,9 @@ SQUtils.QObject { id: sessionRequestComponent SessionRequestResolved { + onExpired: { + } + sourceId: Constants.DAppConnectors.WalletConnect } } } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml b/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml index 6b292092f81..d64c7331311 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml @@ -40,6 +40,7 @@ WalletConnectSDKBase { property alias requestsModel: requests readonly property string invalidDAppUrlError: "Invalid dappInfo: URL is missing" + readonly property string invalidDAppTopicError: "Invalid dappInfo: failed to parse topic" projectId: "" @@ -63,6 +64,7 @@ WalletConnectSDKBase { } function resolveAsync(event) { + print("!!! connector received a session event: ", JSON.stringify(event)) let method = event.params.request.method let accountAddress = lookupAccountFromEvent(event, method) if(!accountAddress) { @@ -93,6 +95,7 @@ WalletConnectSDKBase { maxFeesText: "?", maxFeesEthText: "?", enoughFunds: enoughFunds, + expirationTimestamp: 0 }) if (obj === null) { @@ -432,15 +435,13 @@ WalletConnectSDKBase { }; } - let sessionString = root.wcService.connectorDAppsProvider.getActiveSession(dappInfos.url) - if (sessionString === null) { + let session = root.wcService.connectorDAppsProvider.getActiveSession(dappInfos.url) + if (!session) { console.error("Connector.lookupSession: error finding session for requestId ", root.requestId) return } - let session = JSON.parse(sessionString); - return sessionTemplate(session.url, session.name, session.icon) } @@ -652,6 +653,7 @@ WalletConnectSDKBase { id: sessionRequestComponent SessionRequestResolved { + sourceId: Constants.DAppConnectors.StatusConnect } } @@ -662,15 +664,14 @@ WalletConnectSDKBase { Connections { target: root.wcService - function onRevokeSession(dAppUrl) { - if (!dAppUrl) { - console.warn(invalidDAppUrlError) + function onRevokeSession(topic) { + if (!topic) { + console.warn(invalidDAppTopicError) return } - controller.recallDAppPermission(dAppUrl) - const session = { url: dAppUrl, name: "", icon: "" } - root.wcService.connectorDAppsProvider.revokeSession(JSON.stringify(session)) + controller.recallDAppPermission(topic) + root.wcService.connectorDAppsProvider.revokeSession(topic) } } @@ -753,8 +754,8 @@ WalletConnectSDKBase { console.warn(invalidDAppUrlError) return } - const session = { url, name, iconUrl } - root.wcService.connectorDAppsProvider.addSession(JSON.stringify(session)) + + root.wcService.connectorDAppsProvider.addSession(url, name, iconUrl) } onDappRevokeDAppPermission: function(dappInfoString) { @@ -762,7 +763,8 @@ WalletConnectSDKBase { let session = { "url": dappItem.url, "name": dappItem.name, - "iconUrl": dappItem.icon + "iconUrl": dappItem.icon, + "topic": dappItem.url } if (!session.url) { @@ -777,6 +779,10 @@ WalletConnectSDKBase { approveSession: function(requestId, account, selectedChains) { controller.approveDappConnectRequest(requestId, account, JSON.stringify(selectedChains)) const { url, name, icon: iconUrl } = root.dappInfo; + //TODO: temporary solution until we have a proper way to handle accounts + //The dappProvider should add a new session only when the backend has validated the connection + //Currently the dapp info is limited to the url, name and icon + root.wcService.connectorDAppsProvider.addSession(url, name, iconUrl, account) root.wcService.displayToastMessage(qsTr("Successfully authenticated %1").arg(url), false); } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml index 601f2f8569f..c5c3d975265 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml @@ -49,8 +49,8 @@ WalletConnectSDKBase { wcCalls.ping(topic) } - buildApprovedNamespaces: function(params, supportedNamespaces) { - wcCalls.buildApprovedNamespaces(params, supportedNamespaces) + buildApprovedNamespaces: function(id, params, supportedNamespaces) { + wcCalls.buildApprovedNamespaces(id, params, supportedNamespaces) } approveSession: function(sessionProposal, supportedNamespaces) { @@ -134,16 +134,16 @@ WalletConnectSDKBase { ) } - function buildApprovedNamespaces(params, supportedNamespaces) { - console.debug(`WC WalletConnectSDK.wcCall.buildApprovedNamespaces; params: ${JSON.stringify(params)}, supportedNamespaces: ${JSON.stringify(supportedNamespaces)}`) + function buildApprovedNamespaces(pairingId, params, supportedNamespaces) { + console.debug(`WC WalletConnectSDK.wcCall.buildApprovedNamespaces; id: ${pairingId}, params: ${JSON.stringify(params)}, supportedNamespaces: ${JSON.stringify(supportedNamespaces)}`) d.engine.runJavaScript(` wc.buildApprovedNamespaces(${JSON.stringify(params)}, ${JSON.stringify(supportedNamespaces)}) .then((approvedNamespaces) => { - wc.statusObject.onBuildApprovedNamespacesResponse(approvedNamespaces, "") + wc.statusObject.onBuildApprovedNamespacesResponse(${pairingId}, approvedNamespaces, "") }) .catch((e) => { - wc.statusObject.onBuildApprovedNamespacesResponse("", e.message) + wc.statusObject.onBuildApprovedNamespacesResponse(${pairingId}, "", e.message) }) ` ) @@ -155,10 +155,10 @@ WalletConnectSDKBase { d.engine.runJavaScript(` wc.approveSession(${JSON.stringify(sessionProposal)}, ${JSON.stringify(supportedNamespaces)}) .then((session) => { - wc.statusObject.onApproveSessionResponse(session, "") + wc.statusObject.onApproveSessionResponse(${sessionProposal.id}, session, "") }) .catch((e) => { - wc.statusObject.onApproveSessionResponse("", e.message) + wc.statusObject.onApproveSessionResponse(${sessionProposal.id}, "", e.message) }) ` ) @@ -170,10 +170,10 @@ WalletConnectSDKBase { d.engine.runJavaScript(` wc.rejectSession(${id}) .then((value) => { - wc.statusObject.onRejectSessionResponse("") + wc.statusObject.onRejectSessionResponse(${id}, "") }) .catch((e) => { - wc.statusObject.onRejectSessionResponse(e.message) + wc.statusObject.onRejectSessionResponse(${id}, e.message) }) ` ) @@ -296,19 +296,19 @@ WalletConnectSDKBase { console.debug(`WC WalletConnectSDK.onDisconnectPairingResponse; topic: ${topic}, error: ${error}`) } - function onBuildApprovedNamespacesResponse(approvedNamespaces, error) { - console.debug(`WC WalletConnectSDK.onBuildApprovedNamespacesResponse; approvedNamespaces: ${approvedNamespaces ? JSON.stringify(approvedNamespaces) : "-"}, error: ${error}`) - root.buildApprovedNamespacesResult(approvedNamespaces, error) + function onBuildApprovedNamespacesResponse(id, approvedNamespaces, error) { + console.debug(`WC WalletConnectSDK.onBuildApprovedNamespacesResponse; id: ${id}, approvedNamespaces: ${approvedNamespaces ? JSON.stringify(approvedNamespaces) : "-"}, error: ${error}`) + root.buildApprovedNamespacesResult(id, approvedNamespaces, error) } - function onApproveSessionResponse(session, error) { - console.debug(`WC WalletConnectSDK.onApproveSessionResponse; sessionTopic: ${JSON.stringify(session)}, error: ${error}`) - root.approveSessionResult(session, error) + function onApproveSessionResponse(proposalId, session, error) { + console.debug(`WC WalletConnectSDK.onApproveSessionResponse; proposalId: ${proposalId}, sessionTopic: ${JSON.stringify(session)}, error: ${error}`) + root.approveSessionResult(proposalId, session, error) } - function onRejectSessionResponse(error) { - console.debug(`WC WalletConnectSDK.onRejectSessionResponse; error: ${error}`) - root.rejectSessionResult(error) + function onRejectSessionResponse(proposalId, error) { + console.debug(`WC WalletConnectSDK.onRejectSessionResponse; proposalId: ${proposalId}, error: ${error}`) + root.rejectSessionResult(proposalId, error) } function onAcceptSessionRequestResponse(topic, id, error) { @@ -366,6 +366,11 @@ WalletConnectSDKBase { console.debug(`WC WalletConnectSDK.onProposalExpire; details: ${JSON.stringify(details)}`) root.sessionProposalExpired() } + + function onSessionRequestExpire(id) { + console.debug(`WC WalletConnectSDK.onSessionRequestExpire; id: ${id}`) + root.sessionRequestExpired(id) + } } WebEngineLoader { diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDKBase.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDKBase.qml index 073ddc16781..f34f089475b 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDKBase.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDKBase.qml @@ -9,9 +9,10 @@ Item { signal pairResponse(bool success) signal sessionProposal(var sessionProposal) signal sessionProposalExpired() - signal buildApprovedNamespacesResult(var session, string error) - signal approveSessionResult(var approvedNamespaces, string error) - signal rejectSessionResult(string error) + signal buildApprovedNamespacesResult(var id, var session, string error) + signal approveSessionResult(var proposalId, var approvedNamespaces, string error) + signal rejectSessionResult(var proposalId, string error) + signal sessionRequestExpired(var id) signal sessionRequestEvent(var sessionRequest) signal sessionRequestUserAnswerResult(string topic, string id, bool accept /* not reject */, string error) @@ -41,7 +42,7 @@ Item { console.error("ping not implemented") } - property var buildApprovedNamespaces: function(params, supportedNamespaces) { + property var buildApprovedNamespaces: function(id, params, supportedNamespaces) { console.error("buildApprovedNamespaces not implemented") } property var approveSession: function(sessionProposal, supportedNamespaces) { diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml index ec9de28352a..f3f9f856c27 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml @@ -28,234 +28,228 @@ import "types" QObject { id: root + //input properties required property WalletConnectSDKBase wcSDK required property DAppsStore store required property var walletRootStore - readonly property var dappsModel: ConcatModel { - markerRoleName: "source" - - sources: [ - SourceModel { - model: dappsProvider.dappsModel - markerRoleValue: "walletConnect" - }, - SourceModel { - model: connectorDAppsProvider.dappsModel - markerRoleValue: "connector" - } - ] - } - readonly property alias requestHandler: requestHandler - - readonly property bool isServiceAvailableForAddressSelection: dappsProvider.supportedAccountsModel.ModelCount.count - + //output properties + /// Model contaning all dApps available for the currently selected account + readonly property var dappsModel: d.filteredDappsModel + /// Model containig the dApps session requests to be resolved by the user + readonly property SessionRequestsModel sessionRequestsModel: requestHandler.requestsModel + /// Model containing the valid accounts a dApp can interact with + readonly property var validAccounts: d.validAccounts + /// Model containing the networks a dApp can interact with + readonly property var flatNetworks: root.walletRootStore.filteredFlatModel + /// Service can interact with the current address selection + /// Default value: true + readonly property bool serviceAvailableToCurrentAddress: !root.walletRootStore.selectedAddress || + ModelUtils.contains(root.validAccounts, "address", root.walletRootStore.selectedAddress, Qt.CaseInsensitive) + /// TODO: refactor readonly property alias connectorDAppsProvider: connectorDAppsProvider - readonly property var validAccounts: SortFilterProxyModel { - sourceModel: d.supportedAccountsModel - proxyRoles: [ - FastExpressionRole { - name: "colorizedChainPrefixes" - function getChainShortNames(chainIds) { - const chainShortNames = root.walletRootStore.getNetworkShortNames(chainIds) - return WalletUtils.colorizedChainPrefix(chainShortNames) - } - expression: getChainShortNames(model.preferredSharingChainIds) - expectedRoles: ["preferredSharingChainIds"] - } - ] + // methods + /// Triggers the signing process for the given session request + /// @param topic The topic of the session + /// @param id The id of the session request + function sign(topic, id) { + // The authentication triggers the signing process + // authenticate -> sign -> inform the dApp + d.authenticate(topic, id) } - readonly property var flatNetworks: root.walletRootStore.filteredFlatModel - - function validatePairingUri(uri) { - // Check if emoji inside the URI - if(Constants.regularExpressions.emoji.test(uri)) { - root.pairingValidated(Pairing.errors.tooCool) - return - } else if(!DAppsHelpers.validURI(uri)) { - root.pairingValidated(Pairing.errors.invalidUri) - return - } - const info = DAppsHelpers.extractInfoFromPairUri(uri) - wcSDK.getActiveSessions((sessions) => { - // Check if the URI is already paired - let validationState = Pairing.errors.uriOk - for (const key in sessions) { - if (sessions[key].pairingTopic === info.topic) { - validationState = Pairing.errors.alreadyUsed - break - } - } - - // Check if expired - if (validationState === Pairing.errors.uriOk) { - const now = (new Date().getTime())/1000 - if (info.expiry < now) { - validationState = Pairing.errors.expired - } - } + function rejectSign(topic, id, hasError) { + requestHandler.rejectSessionRequest(topic, id, hasError) + } - root.pairingValidated(validationState) - }); + /// Validates the pairing URI + function validatePairingUri(uri) { + d.validatePairingUri(uri) } + /// Initiates the pairing process with the given URI function pair(uri) { - d.acceptedSessionProposal = null timeoutTimer.start() wcSDK.pair(uri) } + + /// Approves or rejects the session proposal + function approvePairSession(key, approvedChainIds, accountAddress) { + if (!d.activeProposals.has(key)) { + console.error("No active proposal found for key: " + key) + return + } - function approvePairSession(sessionProposal, approvedChainIds, approvedAccount) { - d.acceptedSessionProposal = sessionProposal + const proposal = d.activeProposals.get(key) + d.acceptedSessionProposal = proposal const approvedNamespaces = JSON.parse( DAppsHelpers.buildSupportedNamespaces(approvedChainIds, - [approvedAccount.address], + [accountAddress], SessionRequest.getSupportedMethods()) ) - wcSDK.buildApprovedNamespaces(sessionProposal.params, approvedNamespaces) + wcSDK.buildApprovedNamespaces(key, proposal.params, approvedNamespaces) } + /// Rejects the session proposal function rejectPairSession(id) { wcSDK.rejectSession(id) } - function disconnectSession(sessionTopic) { - wcSDK.disconnectSession(sessionTopic) - } - - function disconnectDapp(url) { - wcSDK.getActiveSessions((allSessionsAllProfiles) => { - const sessions = DAppsHelpers.filterActiveSessionsForKnownAccounts(allSessionsAllProfiles, validAccounts) - let dappFoundInWcSessions = false - for (const sessionID in sessions) { - const session = sessions[sessionID] - const accountsInSession = DAppsHelpers.getAccountsInSession(session) - const dapp = session.peer.metadata - const topic = session.topic - if (dapp.url === url) { - if (!dappsProvider.selectedAddress || - (accountsInSession.includes(dappsProvider.selectedAddress))) - { - dappFoundInWcSessions = true - wcSDK.disconnectSession(topic) - } - } - } - - // TODO: #16044 - Refactor Wallet connect service to handle multiple SDKs - if (!dappFoundInWcSessions) { - // Revoke browser plugin session - root.revokeSession(url) - d.notifyDappDisconnect(url, false) - } - }); - } - - function getDApp(dAppUrl) { - return ModelUtils.getByKey(dappsModel, "url", dAppUrl); + /// Disconnects the dApp with the given topic + /// @param topic The topic of the dApp + /// @param source The source of the dApp; either "walletConnect" or "connector" + function disconnectDapp(topic) { + d.disconnectDapp(topic) } - signal connectDApp(var dappChains, var sessionProposal, var approvedNamespaces) - signal approveSessionResult(var session, var error) - signal sessionRequest(SessionRequestResolved request) + // signals + signal connectDApp(var dappChains, url dappUrl, string dappName, url dappIcon, var key) + // Emitted as a response to WalletConnectService.approveSession + // @param key The key of the session proposal + // @param error The error message + // @param topic The new topic of the session + signal approveSessionResult(var key, var error, var topic) + // Emitted when a new session is requested by a dApp + signal sessionRequest(string id) signal displayToastMessage(string message, bool error) // Emitted as a response to WalletConnectService.validatePairingUri or other WalletConnectService.pair // and WalletConnectService.approvePair errors signal pairingValidated(int validationState) + signal revokeSession(string topic) - signal revokeSession(string dAppUrl) + QObject { + id: d - readonly property Connections sdkConnections: Connections { - target: wcSDK + readonly property var validAccounts: SortFilterProxyModel { + sourceModel: root.walletRootStore.nonWatchAccounts + proxyRoles: [ + FastExpressionRole { + name: "colorizedChainPrefixes" + function getChainShortNames(chainIds) { + const chainShortNames = root.walletRootStore.getNetworkShortNames(chainIds) + return WalletUtils.colorizedChainPrefix(chainShortNames) + } + expression: getChainShortNames(model.preferredSharingChainIds) + expectedRoles: ["preferredSharingChainIds"] + } + ] + } - function onPairResponse(ok) { - if (!ok) { - d.reportPairErrorState(Pairing.errors.unknownError) - } // else waiting for onSessionProposal + readonly property var dappsModel: ConcatModel { + id: dappsModel + markerRoleName: "source" + + sources: [ + SourceModel { + model: dappsProvider.dappsModel + markerRoleValue: "walletConnect" + }, + SourceModel { + model: connectorDAppsProvider.dappsModel + markerRoleValue: "statusConnect" + } + ] } - function onSessionProposal(sessionProposal) { - d.currentSessionProposal = sessionProposal + readonly property var filteredDappsModel: SortFilterProxyModel { + id: dappsFilteredModel + objectName: "DAppsModelFiltered" + sourceModel: d.dappsModel + readonly property string selectedAddress: root.walletRootStore.selectedAddress - const supportedNamespacesStr = DAppsHelpers.buildSupportedNamespacesFromModels( - root.flatNetworks, root.validAccounts, SessionRequest.getSupportedMethods()) - wcSDK.buildApprovedNamespaces(sessionProposal.params, JSON.parse(supportedNamespacesStr)) - } + filters: FastExpressionFilter { + enabled: !!dappsFilteredModel.selectedAddress - function onBuildApprovedNamespacesResult(approvedNamespaces, error) { - if(error || !approvedNamespaces) { - // Check that it contains Non conforming namespaces" - if (error.includes("Non conforming namespaces")) { - d.reportPairErrorState(Pairing.errors.unsupportedNetwork) - } else { - d.reportPairErrorState(Pairing.errors.unknownError) + function isAddressIncluded(accountAddressesSubModel, selectedAddress) { + if (!accountAddressesSubModel) { + return false + } + const addresses = ModelUtils.modelToFlatArray(accountAddressesSubModel, "address") + return addresses.includes(selectedAddress) } - return - } - const an = approvedNamespaces.eip155 - if (!(an.accounts) || an.accounts.length === 0 || (!(an.chains) || an.chains.length === 0)) { - d.reportPairErrorState(Pairing.errors.unsupportedNetwork) - return - } - - if (d.acceptedSessionProposal) { - wcSDK.approveSession(d.acceptedSessionProposal, approvedNamespaces) - } else { - const res = DAppsHelpers.extractChainsAndAccountsFromApprovedNamespaces(approvedNamespaces) + expression: isAddressIncluded(model.accountAddresses, dappsFilteredModel.selectedAddress) - root.connectDApp(res.chains, d.currentSessionProposal, approvedNamespaces) + expectedRoles: "accountAddresses" } } - function onApproveSessionResult(session, err) { - if (err) { - d.reportPairErrorState(Pairing.errors.unknownError) - return - } + property var activeProposals: new Map() // key: proposalId, value: sessionProposal + property var acceptedSessionProposal: null - // TODO #14754: implement custom dApp notification - const app_url = d.currentSessionProposal ? d.currentSessionProposal.params.proposer.metadata.url : "-" - const app_domain = StringUtils.extractDomainFromLink(app_url) - root.displayToastMessage(qsTr("Connected to %1 via WalletConnect").arg(app_domain), false) + /// Disconnects the WC session with the given topic + function disconnectSession(sessionTopic) { + wcSDK.disconnectSession(sessionTopic) + } - // Persist session - if(!store.addWalletConnectSession(JSON.stringify(session))) { - console.error("Failed to persist session") + function disconnectDapp(topic) { + const dApp = d.getDAppByTopic(topic) + if (!dApp) { + console.error("Disconnecting dApp: dApp not found") + return } - // Notify client - root.approveSessionResult(session, err) - - dappsProvider.updateDapps() + if (!dApp.connectorId == undefined) { + console.error("Disconnecting dApp: connectorId not found") + return + } + + // TODO: refactor + if (dApp.connectorId === connectorDAppsProvider.connectorId) { + root.revokeSession(topic) + d.notifyDappDisconnect(dApp.url, false) + return + } + // TODO: refactor + if (dApp.connectorId === dappsProvider.connectorId) { + // Currently disconnect acts on all sessions! + for (let i = 0; i < dApp.sessions.ModelCount.count; i++) { + d.disconnectSession(dApp.sessions.get(i).topic) + } + } } - function onRejectSessionResult(err) { - const app_url = d.currentSessionProposal ? d.currentSessionProposal.params.proposer.metadata.url : "-" - const app_domain = StringUtils.extractDomainFromLink(app_url) - if(err) { - d.reportPairErrorState(Pairing.errors.unknownError) - root.displayToastMessage(qsTr("Failed to reject connection request for %1").arg(app_domain), true) - } else { - root.displayToastMessage(qsTr("Connection request for %1 was rejected").arg(app_domain), false) + function validatePairingUri(uri) { + // Check if emoji inside the URI + if(Constants.regularExpressions.emoji.test(uri)) { + root.pairingValidated(Pairing.errors.tooCool) + return + } else if(!DAppsHelpers.validURI(uri)) { + root.pairingValidated(Pairing.errors.invalidUri) + return } - } - function onSessionDelete(topic, err) { - d.disconnectSessionRequested(topic, err) - } - } + const info = DAppsHelpers.extractInfoFromPairUri(uri) + wcSDK.getActiveSessions((sessions) => { + // Check if the URI is already paired + let validationState = Pairing.errors.uriOk + for (const key in sessions) { + if (sessions[key].pairingTopic === info.topic) { + validationState = Pairing.errors.alreadyUsed + break + } + } - QObject { - id: d + // Check if expired + if (validationState === Pairing.errors.uriOk) { + const now = (new Date().getTime())/1000 + if (info.expiry < now) { + validationState = Pairing.errors.expired + } + } - readonly property var supportedAccountsModel: SortFilterProxyModel { - sourceModel: root.walletRootStore.nonWatchAccounts + root.pairingValidated(validationState) + }); + } + + function authenticate(topic, id) { + const request = sessionRequestsModel.findRequest(topic, id) + if (!request) { + console.error("Session request not found") + return + } + requestHandler.authenticate(topic, id, request.accountAddress, request.feesInfo) } - - property var currentSessionProposal: null - property var acceptedSessionProposal: null function reportPairErrorState(state) { timeoutTimer.stop() @@ -309,6 +303,141 @@ QObject { root.displayToastMessage(qsTr("Disconnected from %1").arg(appDomain), false) } } + + function getDAppByTopic(topic) { + return ModelUtils.getFirstModelEntryIf(d.dappsModel, (modelItem) => { + if (modelItem.topic == topic) { + return true + } + if (!modelItem.sessions) { + return false + } + for (let i = 0; i < modelItem.sessions.ModelCount.count; i++) { + if (modelItem.sessions.get(i).topic == topic) { + return true + } + } + }) + } + } + + Connections { + target: wcSDK + + function onPairResponse(ok) { + if (!ok) { + d.reportPairErrorState(Pairing.errors.unknownError) + } // else waiting for onSessionProposal + } + + function onSessionProposal(sessionProposal) { + const key = sessionProposal.id + d.activeProposals.set(key, sessionProposal) + + const supportedNamespacesStr = DAppsHelpers.buildSupportedNamespacesFromModels( + root.flatNetworks, root.validAccounts, SessionRequest.getSupportedMethods()) + wcSDK.buildApprovedNamespaces(key, sessionProposal.params, JSON.parse(supportedNamespacesStr)) + } + + function onBuildApprovedNamespacesResult(key, approvedNamespaces, error) { + if (!d.activeProposals.has(key)) { + console.error("No active proposal found for key: " + key) + return + } + + if(error || !approvedNamespaces) { + // Check that it contains Non conforming namespaces" + if (error.includes("Non conforming namespaces")) { + d.reportPairErrorState(Pairing.errors.unsupportedNetwork) + } else { + d.reportPairErrorState(Pairing.errors.unknownError) + } + return + } + const an = approvedNamespaces.eip155 + if (!(an.accounts) || an.accounts.length === 0 || (!(an.chains) || an.chains.length === 0)) { + d.reportPairErrorState(Pairing.errors.unsupportedNetwork) + return + } + + if (d.acceptedSessionProposal) { + wcSDK.approveSession(d.acceptedSessionProposal, approvedNamespaces) + } else { + const proposal = d.activeProposals.get(key) + const res = DAppsHelpers.extractChainsAndAccountsFromApprovedNamespaces(approvedNamespaces) + const chains = res.chains + const dAppUrl = proposal.params.proposer.metadata.url + const dAppName = proposal.params.proposer.metadata.name + const dAppIcons = proposal.params.proposer.metadata.icons + const dAppIcon = dAppIcons && dAppIcons.length > 0 ? dAppIcons[0] : "" + + root.connectDApp(chains, dAppUrl, dAppName, dAppIcon, key) + } + } + + function onApproveSessionResult(proposalId, session, err) { + if (!d.activeProposals.has(proposalId)) { + console.error("No active proposal found for key: " + proposalId) + return + } + + if (!d.acceptedSessionProposal || d.acceptedSessionProposal.id !== proposalId) { + console.error("No accepted proposal found for key: " + proposalId) + d.activeProposals.delete(proposalId) + return + } + + const proposal = d.activeProposals.get(proposalId) + d.activeProposals.delete(proposalId) + d.acceptedSessionProposal = null + + if (err) { + d.reportPairErrorState(Pairing.errors.unknownError) + return + } + + // TODO #14754: implement custom dApp notification + const app_url = proposal.params.proposer.metadata.url ?? "-" + const app_domain = StringUtils.extractDomainFromLink(app_url) + root.displayToastMessage(qsTr("Connected to %1 via WalletConnect").arg(app_domain), false) + + // Persist session + if(!store.addWalletConnectSession(JSON.stringify(session))) { + console.error("Failed to persist session") + } + + // Notify client + root.approveSessionResult(proposalId, err, session.topic) + + dappsProvider.updateDapps() + } + + function onRejectSessionResult(proposalId, err) { + if (!d.activeProposals.has(proposalId)) { + console.error("No active proposal found for key: " + proposalId) + return + } + + const proposal = d.activeProposals.get(proposalId) + d.activeProposals.delete(proposalId) + + const app_url = proposal.params.proposer.metadata.url ?? "-" + const app_domain = StringUtils.extractDomainFromLink(app_url) + if(err) { + d.reportPairErrorState(Pairing.errors.unknownError) + root.displayToastMessage(qsTr("Failed to reject connection request for %1").arg(app_domain), true) + } else { + root.displayToastMessage(qsTr("Connection request for %1 was rejected").arg(app_domain), false) + } + } + + function onSessionDelete(topic, err) { + d.disconnectSessionRequested(topic, err) + } + + function onSessionRequestExpired(id) { + root.displayToastMessage(qsTr("Session request expired"), true) + } } Component.onCompleted: { @@ -325,9 +454,8 @@ QObject { currenciesStore: root.walletRootStore.currencyStore assetsStore: root.walletRootStore.walletAssetsStore - onSessionRequest: (request) => { + onSessionRequest: (id) => { timeoutTimer.stop() - root.sessionRequest(request) } onDisplayToastMessage: (message, error) => { root.displayToastMessage(message, error) @@ -336,11 +464,9 @@ QObject { DAppsListProvider { id: dappsProvider - sdk: root.wcSDK store: root.store - supportedAccountsModel: d.supportedAccountsModel - selectedAddress: root.walletRootStore.selectedAddress + supportedAccountsModel: root.walletRootStore.nonWatchAccounts } ConnectorDAppsListProvider { diff --git a/ui/app/AppLayouts/Wallet/services/dapps/sdk/generated/bundle.js b/ui/app/AppLayouts/Wallet/services/dapps/sdk/generated/bundle.js index 910b69f75c8..097902deafe 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/sdk/generated/bundle.js +++ b/ui/app/AppLayouts/Wallet/services/dapps/sdk/generated/bundle.js @@ -1,2 +1,2 @@ /*! For license information please see bundle.js.LICENSE.txt */ -var t={972:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(4512);function n(t,e,r){return void 0===e&&(e=new Uint8Array(2)),void 0===r&&(r=0),e[r+0]=t>>>8,e[r+1]=t>>>0,e}function s(t,e,r){return void 0===e&&(e=new Uint8Array(2)),void 0===r&&(r=0),e[r+0]=t>>>0,e[r+1]=t>>>8,e}function o(t,e){return void 0===e&&(e=0),t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3]}function a(t,e){return void 0===e&&(e=0),(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}function h(t,e){return void 0===e&&(e=0),t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function u(t,e){return void 0===e&&(e=0),(t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e])>>>0}function c(t,e,r){return void 0===e&&(e=new Uint8Array(4)),void 0===r&&(r=0),e[r+0]=t>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=t>>>0,e}function l(t,e,r){return void 0===e&&(e=new Uint8Array(4)),void 0===r&&(r=0),e[r+0]=t>>>0,e[r+1]=t>>>8,e[r+2]=t>>>16,e[r+3]=t>>>24,e}function f(t,e,r){return void 0===e&&(e=new Uint8Array(8)),void 0===r&&(r=0),c(t/4294967296>>>0,e,r),c(t>>>0,e,r+4),e}function d(t,e,r){return void 0===e&&(e=new Uint8Array(8)),void 0===r&&(r=0),l(t>>>0,e,r),l(t/4294967296>>>0,e,r+4),e}e.readInt16BE=function(t,e){return void 0===e&&(e=0),(t[e+0]<<8|t[e+1])<<16>>16},e.readUint16BE=function(t,e){return void 0===e&&(e=0),(t[e+0]<<8|t[e+1])>>>0},e.readInt16LE=function(t,e){return void 0===e&&(e=0),(t[e+1]<<8|t[e])<<16>>16},e.readUint16LE=function(t,e){return void 0===e&&(e=0),(t[e+1]<<8|t[e])>>>0},e.writeUint16BE=n,e.writeInt16BE=n,e.writeUint16LE=s,e.writeInt16LE=s,e.readInt32BE=o,e.readUint32BE=a,e.readInt32LE=h,e.readUint32LE=u,e.writeUint32BE=c,e.writeInt32BE=c,e.writeUint32LE=l,e.writeInt32LE=l,e.readInt64BE=function(t,e){void 0===e&&(e=0);var r=o(t,e),i=o(t,e+4);return 4294967296*r+i-4294967296*(i>>31)},e.readUint64BE=function(t,e){return void 0===e&&(e=0),4294967296*a(t,e)+a(t,e+4)},e.readInt64LE=function(t,e){void 0===e&&(e=0);var r=h(t,e);return 4294967296*h(t,e+4)+r-4294967296*(r>>31)},e.readUint64LE=function(t,e){void 0===e&&(e=0);var r=u(t,e);return 4294967296*u(t,e+4)+r},e.writeUint64BE=f,e.writeInt64BE=f,e.writeUint64LE=d,e.writeInt64LE=d,e.readUintBE=function(t,e,r){if(void 0===r&&(r=0),t%8!=0)throw new Error("readUintBE supports only bitLengths divisible by 8");if(t/8>e.length-r)throw new Error("readUintBE: array is too short for the given bitLength");for(var i=0,n=1,s=t/8+r-1;s>=r;s--)i+=e[s]*n,n*=256;return i},e.readUintLE=function(t,e,r){if(void 0===r&&(r=0),t%8!=0)throw new Error("readUintLE supports only bitLengths divisible by 8");if(t/8>e.length-r)throw new Error("readUintLE: array is too short for the given bitLength");for(var i=0,n=1,s=r;s=n;o--)r[o]=e/s&255,s*=256;return r},e.writeUintLE=function(t,e,r,n){if(void 0===r&&(r=new Uint8Array(t/8)),void 0===n&&(n=0),t%8!=0)throw new Error("writeUintLE supports only bitLengths divisible by 8");if(!i.isSafeInteger(e))throw new Error("writeUintLE value must be an integer");for(var s=1,o=n;o{Object.defineProperty(e,"__esModule",{value:!0});var i=r(972),n=r(6228),s=20;function o(t,e,r){for(var n=1634760805,o=857760878,a=2036477234,h=1797285236,u=r[3]<<24|r[2]<<16|r[1]<<8|r[0],c=r[7]<<24|r[6]<<16|r[5]<<8|r[4],l=r[11]<<24|r[10]<<16|r[9]<<8|r[8],f=r[15]<<24|r[14]<<16|r[13]<<8|r[12],d=r[19]<<24|r[18]<<16|r[17]<<8|r[16],p=r[23]<<24|r[22]<<16|r[21]<<8|r[20],g=r[27]<<24|r[26]<<16|r[25]<<8|r[24],m=r[31]<<24|r[30]<<16|r[29]<<8|r[28],y=e[3]<<24|e[2]<<16|e[1]<<8|e[0],v=e[7]<<24|e[6]<<16|e[5]<<8|e[4],w=e[11]<<24|e[10]<<16|e[9]<<8|e[8],b=e[15]<<24|e[14]<<16|e[13]<<8|e[12],_=n,A=o,E=a,S=h,M=u,I=c,x=l,N=f,O=d,P=p,R=g,C=m,T=y,k=v,U=w,L=b,q=0;q>>16|T<<16)|0)>>>20|M<<12,I=(I^=P=P+(k=(k^=A=A+I|0)>>>16|k<<16)|0)>>>20|I<<12,x=(x^=R=R+(U=(U^=E=E+x|0)>>>16|U<<16)|0)>>>20|x<<12,N=(N^=C=C+(L=(L^=S=S+N|0)>>>16|L<<16)|0)>>>20|N<<12,x=(x^=R=R+(U=(U^=E=E+x|0)>>>24|U<<8)|0)>>>25|x<<7,N=(N^=C=C+(L=(L^=S=S+N|0)>>>24|L<<8)|0)>>>25|N<<7,I=(I^=P=P+(k=(k^=A=A+I|0)>>>24|k<<8)|0)>>>25|I<<7,M=(M^=O=O+(T=(T^=_=_+M|0)>>>24|T<<8)|0)>>>25|M<<7,I=(I^=R=R+(L=(L^=_=_+I|0)>>>16|L<<16)|0)>>>20|I<<12,x=(x^=C=C+(T=(T^=A=A+x|0)>>>16|T<<16)|0)>>>20|x<<12,N=(N^=O=O+(k=(k^=E=E+N|0)>>>16|k<<16)|0)>>>20|N<<12,M=(M^=P=P+(U=(U^=S=S+M|0)>>>16|U<<16)|0)>>>20|M<<12,N=(N^=O=O+(k=(k^=E=E+N|0)>>>24|k<<8)|0)>>>25|N<<7,M=(M^=P=P+(U=(U^=S=S+M|0)>>>24|U<<8)|0)>>>25|M<<7,x=(x^=C=C+(T=(T^=A=A+x|0)>>>24|T<<8)|0)>>>25|x<<7,I=(I^=R=R+(L=(L^=_=_+I|0)>>>24|L<<8)|0)>>>25|I<<7;i.writeUint32LE(_+n|0,t,0),i.writeUint32LE(A+o|0,t,4),i.writeUint32LE(E+a|0,t,8),i.writeUint32LE(S+h|0,t,12),i.writeUint32LE(M+u|0,t,16),i.writeUint32LE(I+c|0,t,20),i.writeUint32LE(x+l|0,t,24),i.writeUint32LE(N+f|0,t,28),i.writeUint32LE(O+d|0,t,32),i.writeUint32LE(P+p|0,t,36),i.writeUint32LE(R+g|0,t,40),i.writeUint32LE(C+m|0,t,44),i.writeUint32LE(T+y|0,t,48),i.writeUint32LE(k+v|0,t,52),i.writeUint32LE(U+w|0,t,56),i.writeUint32LE(L+b|0,t,60)}function a(t,e,r,i,s){if(void 0===s&&(s=0),32!==t.length)throw new Error("ChaCha: key size must be 32 bytes");if(i.length>>=8,e++;if(i>0)throw new Error("ChaCha: counter overflow")}e.streamXOR=a,e.stream=function(t,e,r,i){return void 0===i&&(i=0),n.wipe(r),a(t,e,r,r,i)}},1612:(t,e,r)=>{var i=r(9918),n=r(7360),s=r(6228),o=r(972),a=r(6452);e.J4=32,e.PX=12,e.iW=16;var h=new Uint8Array(16),u=function(){function t(t){if(this.nonceLength=e.PX,this.tagLength=e.iW,t.length!==e.J4)throw new Error("ChaCha20Poly1305 needs 32-byte key");this._key=new Uint8Array(t)}return t.prototype.seal=function(t,e,r,n){if(t.length>16)throw new Error("ChaCha20Poly1305: incorrect nonce length");var o=new Uint8Array(16);o.set(t,o.length-t.length);var a=new Uint8Array(32);i.stream(this._key,o,a,4);var h,u=e.length+this.tagLength;if(n){if(n.length!==u)throw new Error("ChaCha20Poly1305: incorrect destination length");h=n}else h=new Uint8Array(u);return i.streamXOR(this._key,o,e,h,4),this._authenticate(h.subarray(h.length-this.tagLength,h.length),a,h.subarray(0,h.length-this.tagLength),r),s.wipe(o),h},t.prototype.open=function(t,e,r,n){if(t.length>16)throw new Error("ChaCha20Poly1305: incorrect nonce length");if(e.length0&&a.update(h.subarray(i.length%16))),a.update(r),r.length%16>0&&a.update(h.subarray(r.length%16));var u=new Uint8Array(8);i&&o.writeUint64LE(i.length,u),a.update(u),o.writeUint64LE(r.length,u),a.update(u);for(var c=a.digest(),l=0;l{function r(t,e){if(t.length!==e.length)return 0;for(var r=0,i=0;i>>8}Object.defineProperty(e,"__esModule",{value:!0}),e.select=function(t,e,r){return~(t-1)&e|t-1&r},e.lessOrEqual=function(t,e){return(0|t)-(0|e)-1>>>31&1},e.compare=r,e.equal=function(t,e){return 0!==t.length&&0!==e.length&&0!==r(t,e)}},4904:(t,e,r)=>{e._S=e.K=e.TP=e.wE=e.Ee=void 0;r(7052);const i=r(4974);r(6228);function n(t){const e=new Float64Array(16);if(t)for(let r=0;r>16&1),r[t-1]&=65535;r[15]=i[15]-32767-(r[14]>>16&1);const t=r[15]>>16&1;r[14]&=65535,f(i,r,1-t)}for(let e=0;e<16;e++)t[2*e]=255&i[e],t[2*e+1]=i[e]>>8}function p(t){const e=new Uint8Array(32);return d(e,t),1&e[0]}function g(t,e,r){for(let i=0;i<16;i++)t[i]=e[i]+r[i]}function m(t,e,r){for(let i=0;i<16;i++)t[i]=e[i]-r[i]}function y(t,e,r){let i,n,s=0,o=0,a=0,h=0,u=0,c=0,l=0,f=0,d=0,p=0,g=0,m=0,y=0,v=0,w=0,b=0,_=0,A=0,E=0,S=0,M=0,I=0,x=0,N=0,O=0,P=0,R=0,C=0,T=0,k=0,U=0,L=r[0],q=r[1],D=r[2],B=r[3],j=r[4],z=r[5],F=r[6],K=r[7],H=r[8],V=r[9],G=r[10],W=r[11],$=r[12],J=r[13],Y=r[14],Q=r[15];i=e[0],s+=i*L,o+=i*q,a+=i*D,h+=i*B,u+=i*j,c+=i*z,l+=i*F,f+=i*K,d+=i*H,p+=i*V,g+=i*G,m+=i*W,y+=i*$,v+=i*J,w+=i*Y,b+=i*Q,i=e[1],o+=i*L,a+=i*q,h+=i*D,u+=i*B,c+=i*j,l+=i*z,f+=i*F,d+=i*K,p+=i*H,g+=i*V,m+=i*G,y+=i*W,v+=i*$,w+=i*J,b+=i*Y,_+=i*Q,i=e[2],a+=i*L,h+=i*q,u+=i*D,c+=i*B,l+=i*j,f+=i*z,d+=i*F,p+=i*K,g+=i*H,m+=i*V,y+=i*G,v+=i*W,w+=i*$,b+=i*J,_+=i*Y,A+=i*Q,i=e[3],h+=i*L,u+=i*q,c+=i*D,l+=i*B,f+=i*j,d+=i*z,p+=i*F,g+=i*K,m+=i*H,y+=i*V,v+=i*G,w+=i*W,b+=i*$,_+=i*J,A+=i*Y,E+=i*Q,i=e[4],u+=i*L,c+=i*q,l+=i*D,f+=i*B,d+=i*j,p+=i*z,g+=i*F,m+=i*K,y+=i*H,v+=i*V,w+=i*G,b+=i*W,_+=i*$,A+=i*J,E+=i*Y,S+=i*Q,i=e[5],c+=i*L,l+=i*q,f+=i*D,d+=i*B,p+=i*j,g+=i*z,m+=i*F,y+=i*K,v+=i*H,w+=i*V,b+=i*G,_+=i*W,A+=i*$,E+=i*J,S+=i*Y,M+=i*Q,i=e[6],l+=i*L,f+=i*q,d+=i*D,p+=i*B,g+=i*j,m+=i*z,y+=i*F,v+=i*K,w+=i*H,b+=i*V,_+=i*G,A+=i*W,E+=i*$,S+=i*J,M+=i*Y,I+=i*Q,i=e[7],f+=i*L,d+=i*q,p+=i*D,g+=i*B,m+=i*j,y+=i*z,v+=i*F,w+=i*K,b+=i*H,_+=i*V,A+=i*G,E+=i*W,S+=i*$,M+=i*J,I+=i*Y,x+=i*Q,i=e[8],d+=i*L,p+=i*q,g+=i*D,m+=i*B,y+=i*j,v+=i*z,w+=i*F,b+=i*K,_+=i*H,A+=i*V,E+=i*G,S+=i*W,M+=i*$,I+=i*J,x+=i*Y,N+=i*Q,i=e[9],p+=i*L,g+=i*q,m+=i*D,y+=i*B,v+=i*j,w+=i*z,b+=i*F,_+=i*K,A+=i*H,E+=i*V,S+=i*G,M+=i*W,I+=i*$,x+=i*J,N+=i*Y,O+=i*Q,i=e[10],g+=i*L,m+=i*q,y+=i*D,v+=i*B,w+=i*j,b+=i*z,_+=i*F,A+=i*K,E+=i*H,S+=i*V,M+=i*G,I+=i*W,x+=i*$,N+=i*J,O+=i*Y,P+=i*Q,i=e[11],m+=i*L,y+=i*q,v+=i*D,w+=i*B,b+=i*j,_+=i*z,A+=i*F,E+=i*K,S+=i*H,M+=i*V,I+=i*G,x+=i*W,N+=i*$,O+=i*J,P+=i*Y,R+=i*Q,i=e[12],y+=i*L,v+=i*q,w+=i*D,b+=i*B,_+=i*j,A+=i*z,E+=i*F,S+=i*K,M+=i*H,I+=i*V,x+=i*G,N+=i*W,O+=i*$,P+=i*J,R+=i*Y,C+=i*Q,i=e[13],v+=i*L,w+=i*q,b+=i*D,_+=i*B,A+=i*j,E+=i*z,S+=i*F,M+=i*K,I+=i*H,x+=i*V,N+=i*G,O+=i*W,P+=i*$,R+=i*J,C+=i*Y,T+=i*Q,i=e[14],w+=i*L,b+=i*q,_+=i*D,A+=i*B,E+=i*j,S+=i*z,M+=i*F,I+=i*K,x+=i*H,N+=i*V,O+=i*G,P+=i*W,R+=i*$,C+=i*J,T+=i*Y,k+=i*Q,i=e[15],b+=i*L,_+=i*q,A+=i*D,E+=i*B,S+=i*j,M+=i*z,I+=i*F,x+=i*K,N+=i*H,O+=i*V,P+=i*G,R+=i*W,C+=i*$,T+=i*J,k+=i*Y,U+=i*Q,s+=38*_,o+=38*A,a+=38*E,h+=38*S,u+=38*M,c+=38*I,l+=38*x,f+=38*N,d+=38*O,p+=38*P,g+=38*R,m+=38*C,y+=38*T,v+=38*k,w+=38*U,n=1,i=s+n+65535,n=Math.floor(i/65536),s=i-65536*n,i=o+n+65535,n=Math.floor(i/65536),o=i-65536*n,i=a+n+65535,n=Math.floor(i/65536),a=i-65536*n,i=h+n+65535,n=Math.floor(i/65536),h=i-65536*n,i=u+n+65535,n=Math.floor(i/65536),u=i-65536*n,i=c+n+65535,n=Math.floor(i/65536),c=i-65536*n,i=l+n+65535,n=Math.floor(i/65536),l=i-65536*n,i=f+n+65535,n=Math.floor(i/65536),f=i-65536*n,i=d+n+65535,n=Math.floor(i/65536),d=i-65536*n,i=p+n+65535,n=Math.floor(i/65536),p=i-65536*n,i=g+n+65535,n=Math.floor(i/65536),g=i-65536*n,i=m+n+65535,n=Math.floor(i/65536),m=i-65536*n,i=y+n+65535,n=Math.floor(i/65536),y=i-65536*n,i=v+n+65535,n=Math.floor(i/65536),v=i-65536*n,i=w+n+65535,n=Math.floor(i/65536),w=i-65536*n,i=b+n+65535,n=Math.floor(i/65536),b=i-65536*n,s+=n-1+37*(n-1),n=1,i=s+n+65535,n=Math.floor(i/65536),s=i-65536*n,i=o+n+65535,n=Math.floor(i/65536),o=i-65536*n,i=a+n+65535,n=Math.floor(i/65536),a=i-65536*n,i=h+n+65535,n=Math.floor(i/65536),h=i-65536*n,i=u+n+65535,n=Math.floor(i/65536),u=i-65536*n,i=c+n+65535,n=Math.floor(i/65536),c=i-65536*n,i=l+n+65535,n=Math.floor(i/65536),l=i-65536*n,i=f+n+65535,n=Math.floor(i/65536),f=i-65536*n,i=d+n+65535,n=Math.floor(i/65536),d=i-65536*n,i=p+n+65535,n=Math.floor(i/65536),p=i-65536*n,i=g+n+65535,n=Math.floor(i/65536),g=i-65536*n,i=m+n+65535,n=Math.floor(i/65536),m=i-65536*n,i=y+n+65535,n=Math.floor(i/65536),y=i-65536*n,i=v+n+65535,n=Math.floor(i/65536),v=i-65536*n,i=w+n+65535,n=Math.floor(i/65536),w=i-65536*n,i=b+n+65535,n=Math.floor(i/65536),b=i-65536*n,s+=n-1+37*(n-1),t[0]=s,t[1]=o,t[2]=a,t[3]=h,t[4]=u,t[5]=c,t[6]=l,t[7]=f,t[8]=d,t[9]=p,t[10]=g,t[11]=m,t[12]=y,t[13]=v,t[14]=w,t[15]=b}function v(t,e){y(t,e,e)}function w(t,e){const r=n(),i=n(),s=n(),o=n(),h=n(),u=n(),c=n(),l=n(),f=n();m(r,t[1],t[0]),m(f,e[1],e[0]),y(r,r,f),g(i,t[0],t[1]),g(f,e[0],e[1]),y(i,i,f),y(s,t[3],e[3]),y(s,s,a),y(o,t[2],e[2]),g(o,o,o),m(h,i,r),m(u,o,s),g(c,o,s),g(l,i,r),y(t[0],h,u),y(t[1],l,c),y(t[2],c,u),y(t[3],h,l)}function b(t,e,r){for(let i=0;i<4;i++)f(t[i],e[i],r)}function _(t,e){const r=n(),i=n(),s=n();(function(t,e){const r=n();let i;for(i=0;i<16;i++)r[i]=e[i];for(i=253;i>=0;i--)v(r,r),2!==i&&4!==i&&y(r,r,e);for(i=0;i<16;i++)t[i]=r[i]})(s,e[2]),y(r,e[0],s),y(i,e[1],s),d(t,i),t[31]^=p(r)<<7}function A(t,e){const r=[n(),n(),n(),n()];c(r[0],h),c(r[1],u),c(r[2],o),y(r[3],h,u),function(t,e,r){c(t[0],s),c(t[1],o),c(t[2],o),c(t[3],s);for(let i=255;i>=0;--i){const n=r[i/8|0]>>(7&i)&1;b(t,e,n),w(e,t),w(t,t),b(t,e,n)}}(t,r,e)}e.K=function(t){if(t.length!==e.TP)throw new Error(`ed25519: seed must be ${e.TP} bytes`);const r=(0,i.hash)(t);r[0]&=248,r[31]&=127,r[31]|=64;const s=new Uint8Array(32),o=[n(),n(),n(),n()];A(o,r),_(s,o);const a=new Uint8Array(64);return a.set(t),a.set(s,32),{publicKey:s,secretKey:a}};const E=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function S(t,e){let r,i,n,s;for(i=63;i>=32;--i){for(r=0,n=i-32,s=i-12;n>4)*E[n],r=e[n]>>8,e[n]&=255;for(n=0;n<32;n++)e[n]-=r*E[n];for(i=0;i<32;i++)e[i+1]+=e[i]>>8,t[i]=255&e[i]}function M(t){const e=new Float64Array(64);for(let r=0;r<64;r++)e[r]=t[r];for(let e=0;e<64;e++)t[e]=0;S(t,e)}e._S=function(t,e){const r=new Float64Array(64),s=[n(),n(),n(),n()],o=(0,i.hash)(t.subarray(0,32));o[0]&=248,o[31]&=127,o[31]|=64;const a=new Uint8Array(64);a.set(o.subarray(32),32);const h=new i.SHA512;h.update(a.subarray(32)),h.update(e);const u=h.digest();h.clean(),M(u),A(s,u),_(a,s),h.reset(),h.update(a.subarray(0,32)),h.update(t.subarray(32)),h.update(e);const c=h.digest();M(c);for(let t=0;t<32;t++)r[t]=u[t];for(let t=0;t<32;t++)for(let e=0;e<32;e++)r[t+e]+=c[t]*o[e];return S(a.subarray(32),r),a}},2670:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isSerializableHash=function(t){return void 0!==t.saveState&&void 0!==t.restoreState&&void 0!==t.cleanSavedState}},6804:(t,e,r)=>{var i=r(2412),n=r(6228),s=function(){function t(t,e,r,n){void 0===r&&(r=new Uint8Array(0)),this._counter=new Uint8Array(1),this._hash=t,this._info=n;var s=i.hmac(this._hash,r,e);this._hmac=new i.HMAC(t,s),this._buffer=new Uint8Array(this._hmac.digestLength),this._bufpos=this._buffer.length}return t.prototype._fillBuffer=function(){this._counter[0]++;var t=this._counter[0];if(0===t)throw new Error("hkdf: cannot expand more");this._hmac.reset(),t>1&&this._hmac.update(this._buffer),this._info&&this._hmac.update(this._info),this._hmac.update(this._counter),this._hmac.finish(this._buffer),this._bufpos=0},t.prototype.expand=function(t){for(var e=new Uint8Array(t),r=0;r{Object.defineProperty(e,"__esModule",{value:!0});var i=r(2670),n=r(6452),s=r(6228),o=function(){function t(t,e){this._finished=!1,this._inner=new t,this._outer=new t,this.blockSize=this._outer.blockSize,this.digestLength=this._outer.digestLength;var r=new Uint8Array(this.blockSize);e.length>this.blockSize?this._inner.update(e).finish(r).clean():r.set(e);for(var n=0;n{Object.defineProperty(e,"__esModule",{value:!0}),e.mul=Math.imul||function(t,e){var r=65535&t,i=65535&e;return r*i+((t>>>16&65535)*i+r*(e>>>16&65535)<<16>>>0)|0},e.add=function(t,e){return t+e|0},e.sub=function(t,e){return t-e|0},e.rotl=function(t,e){return t<>>32-e},e.rotr=function(t,e){return t<<32-e|t>>>e},e.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},e.MAX_SAFE_INTEGER=9007199254740991,e.isSafeInteger=function(t){return e.isInteger(t)&&t>=-e.MAX_SAFE_INTEGER&&t<=e.MAX_SAFE_INTEGER}},7360:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(6452),n=r(6228);e.DIGEST_LENGTH=16;var s=function(){function t(t){this.digestLength=e.DIGEST_LENGTH,this._buffer=new Uint8Array(16),this._r=new Uint16Array(10),this._h=new Uint16Array(10),this._pad=new Uint16Array(8),this._leftover=0,this._fin=0,this._finished=!1;var r=t[0]|t[1]<<8;this._r[0]=8191&r;var i=t[2]|t[3]<<8;this._r[1]=8191&(r>>>13|i<<3);var n=t[4]|t[5]<<8;this._r[2]=7939&(i>>>10|n<<6);var s=t[6]|t[7]<<8;this._r[3]=8191&(n>>>7|s<<9);var o=t[8]|t[9]<<8;this._r[4]=255&(s>>>4|o<<12),this._r[5]=o>>>1&8190;var a=t[10]|t[11]<<8;this._r[6]=8191&(o>>>14|a<<2);var h=t[12]|t[13]<<8;this._r[7]=8065&(a>>>11|h<<5);var u=t[14]|t[15]<<8;this._r[8]=8191&(h>>>8|u<<8),this._r[9]=u>>>5&127,this._pad[0]=t[16]|t[17]<<8,this._pad[1]=t[18]|t[19]<<8,this._pad[2]=t[20]|t[21]<<8,this._pad[3]=t[22]|t[23]<<8,this._pad[4]=t[24]|t[25]<<8,this._pad[5]=t[26]|t[27]<<8,this._pad[6]=t[28]|t[29]<<8,this._pad[7]=t[30]|t[31]<<8}return t.prototype._blocks=function(t,e,r){for(var i=this._fin?0:2048,n=this._h[0],s=this._h[1],o=this._h[2],a=this._h[3],h=this._h[4],u=this._h[5],c=this._h[6],l=this._h[7],f=this._h[8],d=this._h[9],p=this._r[0],g=this._r[1],m=this._r[2],y=this._r[3],v=this._r[4],w=this._r[5],b=this._r[6],_=this._r[7],A=this._r[8],E=this._r[9];r>=16;){var S=t[e+0]|t[e+1]<<8;n+=8191&S;var M=t[e+2]|t[e+3]<<8;s+=8191&(S>>>13|M<<3);var I=t[e+4]|t[e+5]<<8;o+=8191&(M>>>10|I<<6);var x=t[e+6]|t[e+7]<<8;a+=8191&(I>>>7|x<<9);var N=t[e+8]|t[e+9]<<8;h+=8191&(x>>>4|N<<12),u+=N>>>1&8191;var O=t[e+10]|t[e+11]<<8;c+=8191&(N>>>14|O<<2);var P=t[e+12]|t[e+13]<<8;l+=8191&(O>>>11|P<<5);var R=t[e+14]|t[e+15]<<8,C=0,T=C;T+=n*p,T+=s*(5*E),T+=o*(5*A),T+=a*(5*_),C=(T+=h*(5*b))>>>13,T&=8191,T+=u*(5*w),T+=c*(5*v),T+=l*(5*y),T+=(f+=8191&(P>>>8|R<<8))*(5*m);var k=C+=(T+=(d+=R>>>5|i)*(5*g))>>>13;k+=n*g,k+=s*p,k+=o*(5*E),k+=a*(5*A),C=(k+=h*(5*_))>>>13,k&=8191,k+=u*(5*b),k+=c*(5*w),k+=l*(5*v),k+=f*(5*y),C+=(k+=d*(5*m))>>>13,k&=8191;var U=C;U+=n*m,U+=s*g,U+=o*p,U+=a*(5*E),C=(U+=h*(5*A))>>>13,U&=8191,U+=u*(5*_),U+=c*(5*b),U+=l*(5*w),U+=f*(5*v);var L=C+=(U+=d*(5*y))>>>13;L+=n*y,L+=s*m,L+=o*g,L+=a*p,C=(L+=h*(5*E))>>>13,L&=8191,L+=u*(5*A),L+=c*(5*_),L+=l*(5*b),L+=f*(5*w);var q=C+=(L+=d*(5*v))>>>13;q+=n*v,q+=s*y,q+=o*m,q+=a*g,C=(q+=h*p)>>>13,q&=8191,q+=u*(5*E),q+=c*(5*A),q+=l*(5*_),q+=f*(5*b);var D=C+=(q+=d*(5*w))>>>13;D+=n*w,D+=s*v,D+=o*y,D+=a*m,C=(D+=h*g)>>>13,D&=8191,D+=u*p,D+=c*(5*E),D+=l*(5*A),D+=f*(5*_);var B=C+=(D+=d*(5*b))>>>13;B+=n*b,B+=s*w,B+=o*v,B+=a*y,C=(B+=h*m)>>>13,B&=8191,B+=u*g,B+=c*p,B+=l*(5*E),B+=f*(5*A);var j=C+=(B+=d*(5*_))>>>13;j+=n*_,j+=s*b,j+=o*w,j+=a*v,C=(j+=h*y)>>>13,j&=8191,j+=u*m,j+=c*g,j+=l*p,j+=f*(5*E);var z=C+=(j+=d*(5*A))>>>13;z+=n*A,z+=s*_,z+=o*b,z+=a*w,C=(z+=h*v)>>>13,z&=8191,z+=u*y,z+=c*m,z+=l*g,z+=f*p;var F=C+=(z+=d*(5*E))>>>13;F+=n*E,F+=s*A,F+=o*_,F+=a*b,C=(F+=h*w)>>>13,F&=8191,F+=u*v,F+=c*y,F+=l*m,F+=f*g,n=T=8191&(C=(C=((C+=(F+=d*p)>>>13)<<2)+C|0)+(T&=8191)|0),s=k+=C>>>=13,o=U&=8191,a=L&=8191,h=q&=8191,u=D&=8191,c=B&=8191,l=j&=8191,f=z&=8191,d=F&=8191,e+=16,r-=16}this._h[0]=n,this._h[1]=s,this._h[2]=o,this._h[3]=a,this._h[4]=h,this._h[5]=u,this._h[6]=c,this._h[7]=l,this._h[8]=f,this._h[9]=d},t.prototype.finish=function(t,e){void 0===e&&(e=0);var r,i,n,s,o=new Uint16Array(10);if(this._leftover){for(s=this._leftover,this._buffer[s++]=1;s<16;s++)this._buffer[s]=0;this._fin=1,this._blocks(this._buffer,0,16)}for(r=this._h[1]>>>13,this._h[1]&=8191,s=2;s<10;s++)this._h[s]+=r,r=this._h[s]>>>13,this._h[s]&=8191;for(this._h[0]+=5*r,r=this._h[0]>>>13,this._h[0]&=8191,this._h[1]+=r,r=this._h[1]>>>13,this._h[1]&=8191,this._h[2]+=r,o[0]=this._h[0]+5,r=o[0]>>>13,o[0]&=8191,s=1;s<10;s++)o[s]=this._h[s]+r,r=o[s]>>>13,o[s]&=8191;for(o[9]-=8192,i=(1^r)-1,s=0;s<10;s++)o[s]&=i;for(i=~i,s=0;s<10;s++)this._h[s]=this._h[s]&i|o[s];for(this._h[0]=65535&(this._h[0]|this._h[1]<<13),this._h[1]=65535&(this._h[1]>>>3|this._h[2]<<10),this._h[2]=65535&(this._h[2]>>>6|this._h[3]<<7),this._h[3]=65535&(this._h[3]>>>9|this._h[4]<<4),this._h[4]=65535&(this._h[4]>>>12|this._h[5]<<1|this._h[6]<<14),this._h[5]=65535&(this._h[6]>>>2|this._h[7]<<11),this._h[6]=65535&(this._h[7]>>>5|this._h[8]<<8),this._h[7]=65535&(this._h[8]>>>8|this._h[9]<<5),n=this._h[0]+this._pad[0],this._h[0]=65535&n,s=1;s<8;s++)n=(this._h[s]+this._pad[s]|0)+(n>>>16)|0,this._h[s]=65535&n;return t[e+0]=this._h[0]>>>0,t[e+1]=this._h[0]>>>8,t[e+2]=this._h[1]>>>0,t[e+3]=this._h[1]>>>8,t[e+4]=this._h[2]>>>0,t[e+5]=this._h[2]>>>8,t[e+6]=this._h[3]>>>0,t[e+7]=this._h[3]>>>8,t[e+8]=this._h[4]>>>0,t[e+9]=this._h[4]>>>8,t[e+10]=this._h[5]>>>0,t[e+11]=this._h[5]>>>8,t[e+12]=this._h[6]>>>0,t[e+13]=this._h[6]>>>8,t[e+14]=this._h[7]>>>0,t[e+15]=this._h[7]>>>8,this._finished=!0,this},t.prototype.update=function(t){var e,r=0,i=t.length;if(this._leftover){(e=16-this._leftover)>i&&(e=i);for(var n=0;n=16&&(e=i-i%16,this._blocks(t,r,e),r+=e,i-=e),i){for(n=0;n{Object.defineProperty(e,"__esModule",{value:!0}),e.randomStringForEntropy=e.randomString=e.randomUint32=e.randomBytes=e.defaultRandomSource=void 0;const i=r(5492),n=r(972),s=r(6228);function o(t,r=e.defaultRandomSource){return r.randomBytes(t)}e.defaultRandomSource=new i.SystemRandomSource,e.randomBytes=o,e.randomUint32=function(t=e.defaultRandomSource){const r=o(4,t),i=(0,n.readUint32LE)(r);return(0,s.wipe)(r),i};const a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function h(t,r=a,i=e.defaultRandomSource){if(r.length<2)throw new Error("randomString charset is too short");if(r.length>256)throw new Error("randomString charset is too long");let n="";const h=r.length,u=256-256%h;for(;t>0;){const e=o(Math.ceil(256*t/u),i);for(let i=0;i0;i++){const s=e[i];s{Object.defineProperty(e,"__esModule",{value:!0}),e.BrowserRandomSource=void 0,e.BrowserRandomSource=class{constructor(){this.isAvailable=!1,this.isInstantiated=!1;const t="undefined"!=typeof self?self.crypto||self.msCrypto:null;t&&void 0!==t.getRandomValues&&(this._crypto=t,this.isAvailable=!0,this.isInstantiated=!0)}randomBytes(t){if(!this.isAvailable||!this._crypto)throw new Error("Browser random byte generator is not available.");const e=new Uint8Array(t);for(let t=0;t{Object.defineProperty(e,"__esModule",{value:!0}),e.NodeRandomSource=void 0;const i=r(6228);e.NodeRandomSource=class{constructor(){this.isAvailable=!1,this.isInstantiated=!1;{const t=r(9432);t&&t.randomBytes&&(this._crypto=t,this.isAvailable=!0,this.isInstantiated=!0)}}randomBytes(t){if(!this.isAvailable||!this._crypto)throw new Error("Node.js random byte generator is not available.");let e=this._crypto.randomBytes(t);if(e.length!==t)throw new Error("NodeRandomSource: got fewer bytes than requested");const r=new Uint8Array(t);for(let t=0;t{Object.defineProperty(e,"__esModule",{value:!0}),e.SystemRandomSource=void 0;const i=r(7029),n=r(5821);e.SystemRandomSource=class{constructor(){return this.isAvailable=!1,this.name="",this._source=new i.BrowserRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Browser")):(this._source=new n.NodeRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Node")):void 0)}randomBytes(t){if(!this.isAvailable)throw new Error("System random byte generator is not available.");return this._source.randomBytes(t)}}},204:(t,e,r)=>{var i=r(972),n=r(6228);e.On=32,e.cS=64;var s=function(){function t(){this.digestLength=e.On,this.blockSize=e.cS,this._state=new Int32Array(8),this._temp=new Int32Array(64),this._buffer=new Uint8Array(128),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this.reset()}return t.prototype._initState=function(){this._state[0]=1779033703,this._state[1]=3144134277,this._state[2]=1013904242,this._state[3]=2773480762,this._state[4]=1359893119,this._state[5]=2600822924,this._state[6]=528734635,this._state[7]=1541459225},t.prototype.reset=function(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this},t.prototype.clean=function(){n.wipe(this._buffer),n.wipe(this._temp),this.reset()},t.prototype.update=function(t,e){if(void 0===e&&(e=t.length),this._finished)throw new Error("SHA256: can't update because hash was finished.");var r=0;if(this._bytesHashed+=e,this._bufferLength>0){for(;this._bufferLength0;)this._buffer[this._bufferLength++]=t[r++],e--;this._bufferLength===this.blockSize&&(a(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(e>=this.blockSize&&(r=a(this._temp,this._state,t,r,e),e%=this.blockSize);e>0;)this._buffer[this._bufferLength++]=t[r++],e--;return this},t.prototype.finish=function(t){if(!this._finished){var e=this._bytesHashed,r=this._bufferLength,n=e/536870912|0,s=e<<3,o=e%64<56?64:128;this._buffer[r]=128;for(var h=r+1;h0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}},t.prototype.restoreState=function(t){return this._state.set(t.state),this._bufferLength=t.bufferLength,t.buffer&&this._buffer.set(t.buffer),this._bytesHashed=t.bytesHashed,this._finished=!1,this},t.prototype.cleanSavedState=function(t){n.wipe(t.state),t.buffer&&n.wipe(t.buffer),t.bufferLength=0,t.bytesHashed=0},t}();e.aD=s;var o=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function a(t,e,r,n,s){for(;s>=64;){for(var a=e[0],h=e[1],u=e[2],c=e[3],l=e[4],f=e[5],d=e[6],p=e[7],g=0;g<16;g++){var m=n+4*g;t[g]=i.readUint32BE(r,m)}for(g=16;g<64;g++){var y=t[g-2],v=(y>>>17|y<<15)^(y>>>19|y<<13)^y>>>10,w=((y=t[g-15])>>>7|y<<25)^(y>>>18|y<<14)^y>>>3;t[g]=(v+t[g-7]|0)+(w+t[g-16]|0)}for(g=0;g<64;g++)v=(((l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7))+(l&f^~l&d)|0)+(p+(o[g]+t[g]|0)|0)|0,w=((a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10))+(a&h^a&u^h&u)|0,p=d,d=f,f=l,l=c+v|0,c=u,u=h,h=a,a=v+w|0;e[0]+=a,e[1]+=h,e[2]+=u,e[3]+=c,e[4]+=l,e[5]+=f,e[6]+=d,e[7]+=p,n+=64,s-=64}return n}e.tW=function(t){var e=new s;e.update(t);var r=e.digest();return e.clean(),r}},4974:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(972),n=r(6228);e.DIGEST_LENGTH=64,e.BLOCK_SIZE=128;var s=function(){function t(){this.digestLength=e.DIGEST_LENGTH,this.blockSize=e.BLOCK_SIZE,this._stateHi=new Int32Array(8),this._stateLo=new Int32Array(8),this._tempHi=new Int32Array(16),this._tempLo=new Int32Array(16),this._buffer=new Uint8Array(256),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this.reset()}return t.prototype._initState=function(){this._stateHi[0]=1779033703,this._stateHi[1]=3144134277,this._stateHi[2]=1013904242,this._stateHi[3]=2773480762,this._stateHi[4]=1359893119,this._stateHi[5]=2600822924,this._stateHi[6]=528734635,this._stateHi[7]=1541459225,this._stateLo[0]=4089235720,this._stateLo[1]=2227873595,this._stateLo[2]=4271175723,this._stateLo[3]=1595750129,this._stateLo[4]=2917565137,this._stateLo[5]=725511199,this._stateLo[6]=4215389547,this._stateLo[7]=327033209},t.prototype.reset=function(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this},t.prototype.clean=function(){n.wipe(this._buffer),n.wipe(this._tempHi),n.wipe(this._tempLo),this.reset()},t.prototype.update=function(t,r){if(void 0===r&&(r=t.length),this._finished)throw new Error("SHA512: can't update because hash was finished.");var i=0;if(this._bytesHashed+=r,this._bufferLength>0){for(;this._bufferLength0;)this._buffer[this._bufferLength++]=t[i++],r--;this._bufferLength===this.blockSize&&(a(this._tempHi,this._tempLo,this._stateHi,this._stateLo,this._buffer,0,this.blockSize),this._bufferLength=0)}for(r>=this.blockSize&&(i=a(this._tempHi,this._tempLo,this._stateHi,this._stateLo,t,i,r),r%=this.blockSize);r>0;)this._buffer[this._bufferLength++]=t[i++],r--;return this},t.prototype.finish=function(t){if(!this._finished){var e=this._bytesHashed,r=this._bufferLength,n=e/536870912|0,s=e<<3,o=e%128<112?128:256;this._buffer[r]=128;for(var h=r+1;h0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}},t.prototype.restoreState=function(t){return this._stateHi.set(t.stateHi),this._stateLo.set(t.stateLo),this._bufferLength=t.bufferLength,t.buffer&&this._buffer.set(t.buffer),this._bytesHashed=t.bytesHashed,this._finished=!1,this},t.prototype.cleanSavedState=function(t){n.wipe(t.stateHi),n.wipe(t.stateLo),t.buffer&&n.wipe(t.buffer),t.bufferLength=0,t.bytesHashed=0},t}();e.SHA512=s;var o=new Int32Array([1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591]);function a(t,e,r,n,s,a,h){for(var u,c,l,f,d,p,g,m,y=r[0],v=r[1],w=r[2],b=r[3],_=r[4],A=r[5],E=r[6],S=r[7],M=n[0],I=n[1],x=n[2],N=n[3],O=n[4],P=n[5],R=n[6],C=n[7];h>=128;){for(var T=0;T<16;T++){var k=8*T+a;t[T]=i.readUint32BE(s,k),e[T]=i.readUint32BE(s,k+4)}for(T=0;T<80;T++){var U,L,q=y,D=v,B=w,j=b,z=_,F=A,K=E,H=M,V=I,G=x,W=N,$=O,J=P,Y=R;if(d=65535&(c=C),p=c>>>16,g=65535&(u=S),m=u>>>16,d+=65535&(c=(O>>>14|_<<18)^(O>>>18|_<<14)^(_>>>9|O<<23)),p+=c>>>16,g+=65535&(u=(_>>>14|O<<18)^(_>>>18|O<<14)^(O>>>9|_<<23)),m+=u>>>16,d+=65535&(c=O&P^~O&R),p+=c>>>16,g+=65535&(u=_&A^~_&E),m+=u>>>16,u=o[2*T],d+=65535&(c=o[2*T+1]),p+=c>>>16,g+=65535&u,m+=u>>>16,u=t[T%16],p+=(c=e[T%16])>>>16,g+=65535&u,m+=u>>>16,g+=(p+=(d+=65535&c)>>>16)>>>16,d=65535&(c=f=65535&d|p<<16),p=c>>>16,g=65535&(u=l=65535&g|(m+=g>>>16)<<16),m=u>>>16,d+=65535&(c=(M>>>28|y<<4)^(y>>>2|M<<30)^(y>>>7|M<<25)),p+=c>>>16,g+=65535&(u=(y>>>28|M<<4)^(M>>>2|y<<30)^(M>>>7|y<<25)),m+=u>>>16,p+=(c=M&I^M&x^I&x)>>>16,g+=65535&(u=y&v^y&w^v&w),m+=u>>>16,U=65535&(g+=(p+=(d+=65535&c)>>>16)>>>16)|(m+=g>>>16)<<16,L=65535&d|p<<16,d=65535&(c=W),p=c>>>16,g=65535&(u=j),m=u>>>16,p+=(c=f)>>>16,g+=65535&(u=l),m+=u>>>16,v=q,w=D,b=B,_=j=65535&(g+=(p+=(d+=65535&c)>>>16)>>>16)|(m+=g>>>16)<<16,A=z,E=F,S=K,y=U,I=H,x=V,N=G,O=W=65535&d|p<<16,P=$,R=J,C=Y,M=L,T%16==15)for(k=0;k<16;k++)u=t[k],d=65535&(c=e[k]),p=c>>>16,g=65535&u,m=u>>>16,u=t[(k+9)%16],d+=65535&(c=e[(k+9)%16]),p+=c>>>16,g+=65535&u,m+=u>>>16,l=t[(k+1)%16],d+=65535&(c=((f=e[(k+1)%16])>>>1|l<<31)^(f>>>8|l<<24)^(f>>>7|l<<25)),p+=c>>>16,g+=65535&(u=(l>>>1|f<<31)^(l>>>8|f<<24)^l>>>7),m+=u>>>16,l=t[(k+14)%16],p+=(c=((f=e[(k+14)%16])>>>19|l<<13)^(l>>>29|f<<3)^(f>>>6|l<<26))>>>16,g+=65535&(u=(l>>>19|f<<13)^(f>>>29|l<<3)^l>>>6),m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,t[k]=65535&g|m<<16,e[k]=65535&d|p<<16}d=65535&(c=M),p=c>>>16,g=65535&(u=y),m=u>>>16,u=r[0],p+=(c=n[0])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[0]=y=65535&g|m<<16,n[0]=M=65535&d|p<<16,d=65535&(c=I),p=c>>>16,g=65535&(u=v),m=u>>>16,u=r[1],p+=(c=n[1])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[1]=v=65535&g|m<<16,n[1]=I=65535&d|p<<16,d=65535&(c=x),p=c>>>16,g=65535&(u=w),m=u>>>16,u=r[2],p+=(c=n[2])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[2]=w=65535&g|m<<16,n[2]=x=65535&d|p<<16,d=65535&(c=N),p=c>>>16,g=65535&(u=b),m=u>>>16,u=r[3],p+=(c=n[3])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[3]=b=65535&g|m<<16,n[3]=N=65535&d|p<<16,d=65535&(c=O),p=c>>>16,g=65535&(u=_),m=u>>>16,u=r[4],p+=(c=n[4])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[4]=_=65535&g|m<<16,n[4]=O=65535&d|p<<16,d=65535&(c=P),p=c>>>16,g=65535&(u=A),m=u>>>16,u=r[5],p+=(c=n[5])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[5]=A=65535&g|m<<16,n[5]=P=65535&d|p<<16,d=65535&(c=R),p=c>>>16,g=65535&(u=E),m=u>>>16,u=r[6],p+=(c=n[6])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[6]=E=65535&g|m<<16,n[6]=R=65535&d|p<<16,d=65535&(c=C),p=c>>>16,g=65535&(u=S),m=u>>>16,u=r[7],p+=(c=n[7])>>>16,g+=65535&u,m+=u>>>16,m+=(g+=(p+=(d+=65535&c)>>>16)>>>16)>>>16,r[7]=S=65535&g|m<<16,n[7]=C=65535&d|p<<16,a+=128,h-=128}return a}e.hash=function(t){var e=new s;e.update(t);var r=e.digest();return e.clean(),r}},6228:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.wipe=function(t){for(var e=0;e{e.Tc=e.TZ=e.wE=e.Xx=void 0;const i=r(7052),n=r(6228);function s(t){const e=new Float64Array(16);if(t)for(let r=0;r=0;--t){const e=r[t>>>3]>>>(7&t)&1;u(n,o,e),u(p,g,e),c(m,n,p),l(n,n,p),c(p,o,g),l(o,o,g),d(g,m),d(y,n),f(n,p,n),f(p,o,m),c(m,n,p),l(n,n,p),d(o,n),l(p,g,y),f(n,p,a),c(n,n,g),f(p,p,n),f(n,g,y),f(g,o,i),d(o,m),u(n,o,e),u(p,g,e)}for(let t=0;t<16;t++)i[t+16]=n[t],i[t+32]=p[t],i[t+48]=o[t],i[t+64]=g[t];const v=i.subarray(32),w=i.subarray(16);!function(t,e){const r=s();for(let t=0;t<16;t++)r[t]=e[t];for(let t=253;t>=0;t--)d(r,r),2!==t&&4!==t&&f(r,r,e);for(let e=0;e<16;e++)t[e]=r[e]}(v,v),f(w,w,v);const b=new Uint8Array(32);return function(t,e){const r=s(),i=s();for(let t=0;t<16;t++)i[t]=e[t];h(i),h(i),h(i);for(let t=0;t<2;t++){r[0]=i[0]-65517;for(let t=1;t<15;t++)r[t]=i[t]-65535-(r[t-1]>>16&1),r[t-1]&=65535;r[15]=i[15]-32767-(r[14]>>16&1);const t=r[15]>>16&1;r[14]&=65535,u(i,r,1-t)}for(let e=0;e<16;e++)t[2*e]=255&i[e],t[2*e+1]=i[e]>>8}(b,w),b}function g(t){return p(t,o)}e.TZ=function(t){const r=(0,i.randomBytes)(32,t),s=function(t){if(t.length!==e.wE)throw new Error(`x25519: seed must be ${e.wE} bytes`);const r=new Uint8Array(t);return{publicKey:g(r),secretKey:r}}(r);return(0,n.wipe)(r),s},e.Tc=function(t,r,i=!1){if(t.length!==e.Xx)throw new Error("X25519: incorrect secret key length");if(r.length!==e.Xx)throw new Error("X25519: incorrect public key length");const n=p(t,r);if(i){let t=0;for(let e=0;e{function i(){return(null===r.g||void 0===r.g?void 0:r.g.crypto)||(null===r.g||void 0===r.g?void 0:r.g.msCrypto)||{}}function n(){const t=i();return t.subtle||t.webkitSubtle}Object.defineProperty(e,"__esModule",{value:!0}),e.isBrowserCryptoAvailable=e.getSubtleCrypto=e.getBrowerCrypto=void 0,e.getBrowerCrypto=i,e.getSubtleCrypto=n,e.isBrowserCryptoAvailable=function(){return!!i()&&!!n()}},1089:(t,e)=>{function r(){return"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product}function i(){return"undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.versions.node}Object.defineProperty(e,"__esModule",{value:!0}),e.isBrowser=e.isNode=e.isReactNative=void 0,e.isReactNative=r,e.isNode=i,e.isBrowser=function(){return!r()&&!i()}},5682:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(7173),e),i.__exportStar(r(1089),e)},5665:()=>{},9026:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(9244),e),i.__exportStar(r(1861),e)},9244:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ONE_THOUSAND=e.ONE_HUNDRED=void 0,e.ONE_HUNDRED=100,e.ONE_THOUSAND=1e3},1861:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ONE_YEAR=e.FOUR_WEEKS=e.THREE_WEEKS=e.TWO_WEEKS=e.ONE_WEEK=e.THIRTY_DAYS=e.SEVEN_DAYS=e.FIVE_DAYS=e.THREE_DAYS=e.ONE_DAY=e.TWENTY_FOUR_HOURS=e.TWELVE_HOURS=e.SIX_HOURS=e.THREE_HOURS=e.ONE_HOUR=e.SIXTY_MINUTES=e.THIRTY_MINUTES=e.TEN_MINUTES=e.FIVE_MINUTES=e.ONE_MINUTE=e.SIXTY_SECONDS=e.THIRTY_SECONDS=e.TEN_SECONDS=e.FIVE_SECONDS=e.ONE_SECOND=void 0,e.ONE_SECOND=1,e.FIVE_SECONDS=5,e.TEN_SECONDS=10,e.THIRTY_SECONDS=30,e.SIXTY_SECONDS=60,e.ONE_MINUTE=e.SIXTY_SECONDS,e.FIVE_MINUTES=5*e.ONE_MINUTE,e.TEN_MINUTES=10*e.ONE_MINUTE,e.THIRTY_MINUTES=30*e.ONE_MINUTE,e.SIXTY_MINUTES=60*e.ONE_MINUTE,e.ONE_HOUR=e.SIXTY_MINUTES,e.THREE_HOURS=3*e.ONE_HOUR,e.SIX_HOURS=6*e.ONE_HOUR,e.TWELVE_HOURS=12*e.ONE_HOUR,e.TWENTY_FOUR_HOURS=24*e.ONE_HOUR,e.ONE_DAY=e.TWENTY_FOUR_HOURS,e.THREE_DAYS=3*e.ONE_DAY,e.FIVE_DAYS=5*e.ONE_DAY,e.SEVEN_DAYS=7*e.ONE_DAY,e.THIRTY_DAYS=30*e.ONE_DAY,e.ONE_WEEK=e.SEVEN_DAYS,e.TWO_WEEKS=2*e.ONE_WEEK,e.THREE_WEEKS=3*e.ONE_WEEK,e.FOUR_WEEKS=4*e.ONE_WEEK,e.ONE_YEAR=365*e.ONE_DAY},8900:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(9606),e),i.__exportStar(r(9883),e),i.__exportStar(r(2010),e),i.__exportStar(r(9026),e)},2010:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),r(5215).__exportStar(r(3093),e)},3093:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.IWatch=void 0,e.IWatch=class{}},221:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.fromMiliseconds=e.toMiliseconds=void 0;const i=r(9026);e.toMiliseconds=function(t){return t*i.ONE_THOUSAND},e.fromMiliseconds=function(t){return Math.floor(t/i.ONE_THOUSAND)}},2985:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.delay=void 0,e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e(!0)}),t)}))}},9606:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(2985),e),i.__exportStar(r(221),e)},9883:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Watch=void 0;class r{constructor(){this.timestamps=new Map}start(t){if(this.timestamps.has(t))throw new Error(`Watch already started for label: ${t}`);this.timestamps.set(t,{started:Date.now()})}stop(t){const e=this.get(t);if(void 0!==e.elapsed)throw new Error(`Watch already stopped for label: ${t}`);const r=Date.now()-e.started;this.timestamps.set(t,{started:e.started,elapsed:r})}get(t){const e=this.timestamps.get(t);if(void 0===e)throw new Error(`No timestamp found for label: ${t}`);return e}elapsed(t){const e=this.get(t);return e.elapsed||Date.now()-e.started}}e.Watch=r,e.default=r},8196:(t,e)=>{function r(t){let e;return"undefined"!=typeof window&&void 0!==window[t]&&(e=window[t]),e}function i(t){const e=r(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}Object.defineProperty(e,"__esModule",{value:!0}),e.getLocalStorage=e.getLocalStorageOrThrow=e.getCrypto=e.getCryptoOrThrow=e.getLocation=e.getLocationOrThrow=e.getNavigator=e.getNavigatorOrThrow=e.getDocument=e.getDocumentOrThrow=e.getFromWindowOrThrow=e.getFromWindow=void 0,e.getFromWindow=r,e.getFromWindowOrThrow=i,e.getDocumentOrThrow=function(){return i("document")},e.getDocument=function(){return r("document")},e.getNavigatorOrThrow=function(){return i("navigator")},e.getNavigator=function(){return r("navigator")},e.getLocationOrThrow=function(){return i("location")},e.getLocation=function(){return r("location")},e.getCryptoOrThrow=function(){return i("crypto")},e.getCrypto=function(){return r("crypto")},e.getLocalStorageOrThrow=function(){return i("localStorage")},e.getLocalStorage=function(){return r("localStorage")}},2063:(t,e,r)=>{e.g=void 0;const i=r(8196);e.g=function(){let t,e;try{t=i.getDocumentOrThrow(),e=i.getLocationOrThrow()}catch(t){return null}function r(...e){const r=t.getElementsByTagName("meta");for(let t=0;ti.getAttribute(t))).filter((t=>!!t&&e.includes(t)));if(n.length&&n){const t=i.getAttribute("content");if(t)return t}}return""}const n=function(){let e=r("name","og:site_name","og:title","twitter:title");return e||(e=t.title),e}(),s=r("description","og:description","twitter:description","keywords"),o=e.origin,a=function(){const r=t.getElementsByTagName("link"),i=[];for(let t=0;t-1){const t=n.getAttribute("href");if(t)if(-1===t.toLowerCase().indexOf("https:")&&-1===t.toLowerCase().indexOf("http:")&&0!==t.indexOf("//")){let r=e.protocol+"//"+e.host;if(0===t.indexOf("/"))r+=t;else{const i=e.pathname.split("/");i.pop(),r+=i.join("/")+"/"+t}i.push(r)}else if(0===t.indexOf("//")){const r=e.protocol+t;i.push(r)}else i.push(t)}}return i}();return{description:s,url:o,icons:a,name:n}}},9404:function(t,e,r){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function s(t,e,r){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof t?t.exports=s:e.BN=s,s.BN=s,s.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r(7790).Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void i(!1,"Invalid character in "+t)}function h(t,e,r){var i=a(t,r);return r-1>=e&&(i|=a(t,r-1)<<4),i}function u(t,e,r,n){for(var s=0,o=0,a=Math.min(t.length,r),h=e;h=49?u-49+10:u>=17?u-17+10:u,i(u>=0&&o0?t:e},s.min=function(t,e){return t.cmp(e)<0?t:e},s.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},s.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i=e;i-=2)n=h(t,e,i)<=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;else for(i=(t.length-e)%2==0?e+1:e;i=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;this._strip()},s.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,h=0,c=r;c1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{s.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){s.prototype.inspect=l}else s.prototype.inspect=l;function l(){return(this.red?""}var f=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],p=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function g(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,h=o/67108864|0;r.words[0]=a;for(var u=1;u>>26,l=67108863&h,f=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=f;d++){var p=u-d|0;c+=(o=(n=0|t.words[p])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o}r.words[u]=0|l,h=0|c}return 0!==h?r.words[u]=0|h:r.length--,r._strip()}s.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o>>24-n&16777215,(n+=2)>=26&&(n-=26,o--),r=0!==s||o!==this.length-1?f[6-h.length]+h+r:h+r}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var u=d[t],c=p[t];r="";var l=this.clone();for(l.negative=0;!l.isZero();){var g=l.modrn(c).toString(t);r=(l=l.idivn(c)).isZero()?g+r:f[u-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16,2)},o&&(s.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),s.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},s.prototype.toArrayLike=function(t,e,r){this._strip();var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0");var o=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,s);return this["_toArrayLike"+("le"===e?"LE":"BE")](o,n),o},s.prototype._toArrayLikeLE=function(t,e){for(var r=0,i=0,n=0,s=0;n>8&255),r>16&255),6===s?(r>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r=0&&(t[r--]=o>>8&255),r>=0&&(t[r--]=o>>16&255),6===s?(r>=0&&(t[r--]=o>>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r>=0)for(t[r--]=i;r>=0;)t[r--]=0},Math.clz32?s.prototype._countBits=function(t){return 32-Math.clz32(t)}:s.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},s.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},s.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;rt.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;it.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n0&&(this.words[n]=~this.words[n]&67108863>>26-r),this._strip()},s.prototype.notn=function(t){return this.clone().inotn(t)},s.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s>>26;for(;0!==n&&s>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;st.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o>26,this.words[o]=67108863&e;for(;0!==s&&o>26,this.words[o]=67108863&e;if(0===s&&o>>13,d=0|o[1],p=8191&d,g=d>>>13,m=0|o[2],y=8191&m,v=m>>>13,w=0|o[3],b=8191&w,_=w>>>13,A=0|o[4],E=8191&A,S=A>>>13,M=0|o[5],I=8191&M,x=M>>>13,N=0|o[6],O=8191&N,P=N>>>13,R=0|o[7],C=8191&R,T=R>>>13,k=0|o[8],U=8191&k,L=k>>>13,q=0|o[9],D=8191&q,B=q>>>13,j=0|a[0],z=8191&j,F=j>>>13,K=0|a[1],H=8191&K,V=K>>>13,G=0|a[2],W=8191&G,$=G>>>13,J=0|a[3],Y=8191&J,Q=J>>>13,X=0|a[4],Z=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,ct=0|a[8],lt=8191&ct,ft=ct>>>13,dt=0|a[9],pt=8191&dt,gt=dt>>>13;r.negative=t.negative^e.negative,r.length=19;var mt=(u+(i=Math.imul(l,z))|0)+((8191&(n=(n=Math.imul(l,F))+Math.imul(f,z)|0))<<13)|0;u=((s=Math.imul(f,F))+(n>>>13)|0)+(mt>>>26)|0,mt&=67108863,i=Math.imul(p,z),n=(n=Math.imul(p,F))+Math.imul(g,z)|0,s=Math.imul(g,F);var yt=(u+(i=i+Math.imul(l,H)|0)|0)+((8191&(n=(n=n+Math.imul(l,V)|0)+Math.imul(f,H)|0))<<13)|0;u=((s=s+Math.imul(f,V)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(y,z),n=(n=Math.imul(y,F))+Math.imul(v,z)|0,s=Math.imul(v,F),i=i+Math.imul(p,H)|0,n=(n=n+Math.imul(p,V)|0)+Math.imul(g,H)|0,s=s+Math.imul(g,V)|0;var vt=(u+(i=i+Math.imul(l,W)|0)|0)+((8191&(n=(n=n+Math.imul(l,$)|0)+Math.imul(f,W)|0))<<13)|0;u=((s=s+Math.imul(f,$)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(b,z),n=(n=Math.imul(b,F))+Math.imul(_,z)|0,s=Math.imul(_,F),i=i+Math.imul(y,H)|0,n=(n=n+Math.imul(y,V)|0)+Math.imul(v,H)|0,s=s+Math.imul(v,V)|0,i=i+Math.imul(p,W)|0,n=(n=n+Math.imul(p,$)|0)+Math.imul(g,W)|0,s=s+Math.imul(g,$)|0;var wt=(u+(i=i+Math.imul(l,Y)|0)|0)+((8191&(n=(n=n+Math.imul(l,Q)|0)+Math.imul(f,Y)|0))<<13)|0;u=((s=s+Math.imul(f,Q)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(E,z),n=(n=Math.imul(E,F))+Math.imul(S,z)|0,s=Math.imul(S,F),i=i+Math.imul(b,H)|0,n=(n=n+Math.imul(b,V)|0)+Math.imul(_,H)|0,s=s+Math.imul(_,V)|0,i=i+Math.imul(y,W)|0,n=(n=n+Math.imul(y,$)|0)+Math.imul(v,W)|0,s=s+Math.imul(v,$)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,Q)|0;var bt=(u+(i=i+Math.imul(l,Z)|0)|0)+((8191&(n=(n=n+Math.imul(l,tt)|0)+Math.imul(f,Z)|0))<<13)|0;u=((s=s+Math.imul(f,tt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(I,z),n=(n=Math.imul(I,F))+Math.imul(x,z)|0,s=Math.imul(x,F),i=i+Math.imul(E,H)|0,n=(n=n+Math.imul(E,V)|0)+Math.imul(S,H)|0,s=s+Math.imul(S,V)|0,i=i+Math.imul(b,W)|0,n=(n=n+Math.imul(b,$)|0)+Math.imul(_,W)|0,s=s+Math.imul(_,$)|0,i=i+Math.imul(y,Y)|0,n=(n=n+Math.imul(y,Q)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,Q)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,tt)|0;var _t=(u+(i=i+Math.imul(l,rt)|0)|0)+((8191&(n=(n=n+Math.imul(l,it)|0)+Math.imul(f,rt)|0))<<13)|0;u=((s=s+Math.imul(f,it)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(O,z),n=(n=Math.imul(O,F))+Math.imul(P,z)|0,s=Math.imul(P,F),i=i+Math.imul(I,H)|0,n=(n=n+Math.imul(I,V)|0)+Math.imul(x,H)|0,s=s+Math.imul(x,V)|0,i=i+Math.imul(E,W)|0,n=(n=n+Math.imul(E,$)|0)+Math.imul(S,W)|0,s=s+Math.imul(S,$)|0,i=i+Math.imul(b,Y)|0,n=(n=n+Math.imul(b,Q)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,Q)|0,i=i+Math.imul(y,Z)|0,n=(n=n+Math.imul(y,tt)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(g,rt)|0,s=s+Math.imul(g,it)|0;var At=(u+(i=i+Math.imul(l,st)|0)|0)+((8191&(n=(n=n+Math.imul(l,ot)|0)+Math.imul(f,st)|0))<<13)|0;u=((s=s+Math.imul(f,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(C,z),n=(n=Math.imul(C,F))+Math.imul(T,z)|0,s=Math.imul(T,F),i=i+Math.imul(O,H)|0,n=(n=n+Math.imul(O,V)|0)+Math.imul(P,H)|0,s=s+Math.imul(P,V)|0,i=i+Math.imul(I,W)|0,n=(n=n+Math.imul(I,$)|0)+Math.imul(x,W)|0,s=s+Math.imul(x,$)|0,i=i+Math.imul(E,Y)|0,n=(n=n+Math.imul(E,Q)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,Q)|0,i=i+Math.imul(b,Z)|0,n=(n=n+Math.imul(b,tt)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,tt)|0,i=i+Math.imul(y,rt)|0,n=(n=n+Math.imul(y,it)|0)+Math.imul(v,rt)|0,s=s+Math.imul(v,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var Et=(u+(i=i+Math.imul(l,ht)|0)|0)+((8191&(n=(n=n+Math.imul(l,ut)|0)+Math.imul(f,ht)|0))<<13)|0;u=((s=s+Math.imul(f,ut)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(U,z),n=(n=Math.imul(U,F))+Math.imul(L,z)|0,s=Math.imul(L,F),i=i+Math.imul(C,H)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(T,H)|0,s=s+Math.imul(T,V)|0,i=i+Math.imul(O,W)|0,n=(n=n+Math.imul(O,$)|0)+Math.imul(P,W)|0,s=s+Math.imul(P,$)|0,i=i+Math.imul(I,Y)|0,n=(n=n+Math.imul(I,Q)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,Q)|0,i=i+Math.imul(E,Z)|0,n=(n=n+Math.imul(E,tt)|0)+Math.imul(S,Z)|0,s=s+Math.imul(S,tt)|0,i=i+Math.imul(b,rt)|0,n=(n=n+Math.imul(b,it)|0)+Math.imul(_,rt)|0,s=s+Math.imul(_,it)|0,i=i+Math.imul(y,st)|0,n=(n=n+Math.imul(y,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var St=(u+(i=i+Math.imul(l,lt)|0)|0)+((8191&(n=(n=n+Math.imul(l,ft)|0)+Math.imul(f,lt)|0))<<13)|0;u=((s=s+Math.imul(f,ft)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(D,z),n=(n=Math.imul(D,F))+Math.imul(B,z)|0,s=Math.imul(B,F),i=i+Math.imul(U,H)|0,n=(n=n+Math.imul(U,V)|0)+Math.imul(L,H)|0,s=s+Math.imul(L,V)|0,i=i+Math.imul(C,W)|0,n=(n=n+Math.imul(C,$)|0)+Math.imul(T,W)|0,s=s+Math.imul(T,$)|0,i=i+Math.imul(O,Y)|0,n=(n=n+Math.imul(O,Q)|0)+Math.imul(P,Y)|0,s=s+Math.imul(P,Q)|0,i=i+Math.imul(I,Z)|0,n=(n=n+Math.imul(I,tt)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,tt)|0,i=i+Math.imul(E,rt)|0,n=(n=n+Math.imul(E,it)|0)+Math.imul(S,rt)|0,s=s+Math.imul(S,it)|0,i=i+Math.imul(b,st)|0,n=(n=n+Math.imul(b,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,i=i+Math.imul(y,ht)|0,n=(n=n+Math.imul(y,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,i=i+Math.imul(p,lt)|0,n=(n=n+Math.imul(p,ft)|0)+Math.imul(g,lt)|0,s=s+Math.imul(g,ft)|0;var Mt=(u+(i=i+Math.imul(l,pt)|0)|0)+((8191&(n=(n=n+Math.imul(l,gt)|0)+Math.imul(f,pt)|0))<<13)|0;u=((s=s+Math.imul(f,gt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(D,H),n=(n=Math.imul(D,V))+Math.imul(B,H)|0,s=Math.imul(B,V),i=i+Math.imul(U,W)|0,n=(n=n+Math.imul(U,$)|0)+Math.imul(L,W)|0,s=s+Math.imul(L,$)|0,i=i+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,Q)|0)+Math.imul(T,Y)|0,s=s+Math.imul(T,Q)|0,i=i+Math.imul(O,Z)|0,n=(n=n+Math.imul(O,tt)|0)+Math.imul(P,Z)|0,s=s+Math.imul(P,tt)|0,i=i+Math.imul(I,rt)|0,n=(n=n+Math.imul(I,it)|0)+Math.imul(x,rt)|0,s=s+Math.imul(x,it)|0,i=i+Math.imul(E,st)|0,n=(n=n+Math.imul(E,ot)|0)+Math.imul(S,st)|0,s=s+Math.imul(S,ot)|0,i=i+Math.imul(b,ht)|0,n=(n=n+Math.imul(b,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,i=i+Math.imul(y,lt)|0,n=(n=n+Math.imul(y,ft)|0)+Math.imul(v,lt)|0,s=s+Math.imul(v,ft)|0;var It=(u+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(D,W),n=(n=Math.imul(D,$))+Math.imul(B,W)|0,s=Math.imul(B,$),i=i+Math.imul(U,Y)|0,n=(n=n+Math.imul(U,Q)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,Q)|0,i=i+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(T,Z)|0,s=s+Math.imul(T,tt)|0,i=i+Math.imul(O,rt)|0,n=(n=n+Math.imul(O,it)|0)+Math.imul(P,rt)|0,s=s+Math.imul(P,it)|0,i=i+Math.imul(I,st)|0,n=(n=n+Math.imul(I,ot)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,ot)|0,i=i+Math.imul(E,ht)|0,n=(n=n+Math.imul(E,ut)|0)+Math.imul(S,ht)|0,s=s+Math.imul(S,ut)|0,i=i+Math.imul(b,lt)|0,n=(n=n+Math.imul(b,ft)|0)+Math.imul(_,lt)|0,s=s+Math.imul(_,ft)|0;var xt=(u+(i=i+Math.imul(y,pt)|0)|0)+((8191&(n=(n=n+Math.imul(y,gt)|0)+Math.imul(v,pt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(D,Y),n=(n=Math.imul(D,Q))+Math.imul(B,Y)|0,s=Math.imul(B,Q),i=i+Math.imul(U,Z)|0,n=(n=n+Math.imul(U,tt)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,tt)|0,i=i+Math.imul(C,rt)|0,n=(n=n+Math.imul(C,it)|0)+Math.imul(T,rt)|0,s=s+Math.imul(T,it)|0,i=i+Math.imul(O,st)|0,n=(n=n+Math.imul(O,ot)|0)+Math.imul(P,st)|0,s=s+Math.imul(P,ot)|0,i=i+Math.imul(I,ht)|0,n=(n=n+Math.imul(I,ut)|0)+Math.imul(x,ht)|0,s=s+Math.imul(x,ut)|0,i=i+Math.imul(E,lt)|0,n=(n=n+Math.imul(E,ft)|0)+Math.imul(S,lt)|0,s=s+Math.imul(S,ft)|0;var Nt=(u+(i=i+Math.imul(b,pt)|0)|0)+((8191&(n=(n=n+Math.imul(b,gt)|0)+Math.imul(_,pt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,i=Math.imul(D,Z),n=(n=Math.imul(D,tt))+Math.imul(B,Z)|0,s=Math.imul(B,tt),i=i+Math.imul(U,rt)|0,n=(n=n+Math.imul(U,it)|0)+Math.imul(L,rt)|0,s=s+Math.imul(L,it)|0,i=i+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(T,st)|0,s=s+Math.imul(T,ot)|0,i=i+Math.imul(O,ht)|0,n=(n=n+Math.imul(O,ut)|0)+Math.imul(P,ht)|0,s=s+Math.imul(P,ut)|0,i=i+Math.imul(I,lt)|0,n=(n=n+Math.imul(I,ft)|0)+Math.imul(x,lt)|0,s=s+Math.imul(x,ft)|0;var Ot=(u+(i=i+Math.imul(E,pt)|0)|0)+((8191&(n=(n=n+Math.imul(E,gt)|0)+Math.imul(S,pt)|0))<<13)|0;u=((s=s+Math.imul(S,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,i=Math.imul(D,rt),n=(n=Math.imul(D,it))+Math.imul(B,rt)|0,s=Math.imul(B,it),i=i+Math.imul(U,st)|0,n=(n=n+Math.imul(U,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,i=i+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(T,ht)|0,s=s+Math.imul(T,ut)|0,i=i+Math.imul(O,lt)|0,n=(n=n+Math.imul(O,ft)|0)+Math.imul(P,lt)|0,s=s+Math.imul(P,ft)|0;var Pt=(u+(i=i+Math.imul(I,pt)|0)|0)+((8191&(n=(n=n+Math.imul(I,gt)|0)+Math.imul(x,pt)|0))<<13)|0;u=((s=s+Math.imul(x,gt)|0)+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(D,st),n=(n=Math.imul(D,ot))+Math.imul(B,st)|0,s=Math.imul(B,ot),i=i+Math.imul(U,ht)|0,n=(n=n+Math.imul(U,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,i=i+Math.imul(C,lt)|0,n=(n=n+Math.imul(C,ft)|0)+Math.imul(T,lt)|0,s=s+Math.imul(T,ft)|0;var Rt=(u+(i=i+Math.imul(O,pt)|0)|0)+((8191&(n=(n=n+Math.imul(O,gt)|0)+Math.imul(P,pt)|0))<<13)|0;u=((s=s+Math.imul(P,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(D,ht),n=(n=Math.imul(D,ut))+Math.imul(B,ht)|0,s=Math.imul(B,ut),i=i+Math.imul(U,lt)|0,n=(n=n+Math.imul(U,ft)|0)+Math.imul(L,lt)|0,s=s+Math.imul(L,ft)|0;var Ct=(u+(i=i+Math.imul(C,pt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(T,pt)|0))<<13)|0;u=((s=s+Math.imul(T,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,i=Math.imul(D,lt),n=(n=Math.imul(D,ft))+Math.imul(B,lt)|0,s=Math.imul(B,ft);var Tt=(u+(i=i+Math.imul(U,pt)|0)|0)+((8191&(n=(n=n+Math.imul(U,gt)|0)+Math.imul(L,pt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863;var kt=(u+(i=Math.imul(D,pt))|0)+((8191&(n=(n=Math.imul(D,gt))+Math.imul(B,pt)|0))<<13)|0;return u=((s=Math.imul(B,gt))+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h[0]=mt,h[1]=yt,h[2]=vt,h[3]=wt,h[4]=bt,h[5]=_t,h[6]=At,h[7]=Et,h[8]=St,h[9]=Mt,h[10]=It,h[11]=xt,h[12]=Nt,h[13]=Ot,h[14]=Pt,h[15]=Rt,h[16]=Ct,h[17]=Tt,h[18]=kt,0!==u&&(h[19]=u,r.length++),r};function y(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,s=0;s>>26)|0)>>>26,o&=67108863}r.words[s]=a,i=o,o=n}return 0!==i?r.words[s]=i:r.length--,r._strip()}function v(t,e,r){return y(t,e,r)}function w(t,e){this.x=t,this.y=e}Math.imul||(m=g),s.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?m(this,t,e):r<63?g(this,t,e):r<1024?y(this,t,e):v(this,t,e)},w.prototype.makeRBT=function(t){for(var e=new Array(t),r=s.prototype._countBits(t)-1,i=0;i>=1;return i},w.prototype.permute=function(t,e,r,i,n,s){for(var o=0;o>>=1)n++;return 1<>>=13,r[2*o+1]=8191&s,s>>>=13;for(o=2*e;o>=26,r+=s/67108864|0,r+=o>>>26,this.words[n]=67108863&o}return 0!==r&&(this.words[n]=r,this.length++),e?this.ineg():this},s.prototype.muln=function(t){return this.clone().imuln(t)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r>>n&1}return e}(t);if(0===e.length)return new s(1);for(var r=this,i=0;i=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<o)for(this.length-=o,u=0;u=0&&(0!==c||u>=n);u--){var l=0|this.words[u];this.words[u]=c<<26-s|l>>>s,c=l&a}return h&&0!==c&&(h.words[h.length++]=c),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},s.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},s.prototype.shln=function(t){return this.clone().ishln(t)},s.prototype.ushln=function(t){return this.clone().iushln(t)},s.prototype.shrn=function(t){return this.clone().ishrn(t)},s.prototype.ushrn=function(t){return this.clone().iushrn(t)},s.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,n=1<=0);var e=t%26,r=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var n=67108863^67108863>>>e<=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},s.prototype.isubn=function(t){if(i("number"==typeof t),i(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e>26)-(h/67108864|0),this.words[n+r]=67108863&s}for(;n>26,this.words[n+r]=67108863&s;if(0===a)return this._strip();for(i(-1===a),a=0,n=0;n>26,this.words[n]=67108863&s;return this.negative=1,this._strip()},s.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),n=t,o=0|n.words[n.length-1];0!=(r=26-this._countBits(o))&&(n=n.ushln(r),i.iushln(r),o=0|n.words[n.length-1]);var a,h=i.length-n.length;if("mod"!==e){(a=new s(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u=0;l--){var f=67108864*(0|i.words[n.length+l])+(0|i.words[n.length+l-1]);for(f=Math.min(f/o|0,67108863),i._ishlnsubmul(n,f,l);0!==i.negative;)f--,i.negative=0,i._ishlnsubmul(n,1,l),i.isZero()||(i.negative^=1);a&&(a.words[l]=f)}return a&&a._strip(),i._strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:a||null,mod:i}},s.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(n=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:n,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(n=a.div.neg()),{div:n,mod:a.mod}):this.negative&t.negative?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new s(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new s(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new s(this.modrn(t.words[0]))}:this._wordDiv(t,e);var n,o,a},s.prototype.div=function(t){return this.divmod(t,"div",!1).div},s.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},s.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},s.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),s=r.cmp(i);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},s.prototype.modrn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(r*n+(0|this.words[s]))%t;return e?-n:n},s.prototype.modn=function(t){return this.modrn(t)},s.prototype.idivn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=0,n=this.length-1;n>=0;n--){var s=(0|this.words[n])+67108864*r;this.words[n]=s/t|0,r=s%t}return this._strip(),e?this.ineg():this},s.prototype.divn=function(t){return this.clone().idivn(t)},s.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n=new s(1),o=new s(0),a=new s(0),h=new s(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var c=r.clone(),l=e.clone();!e.isZero();){for(var f=0,d=1;!(e.words[0]&d)&&f<26;++f,d<<=1);if(f>0)for(e.iushrn(f);f-- >0;)(n.isOdd()||o.isOdd())&&(n.iadd(c),o.isub(l)),n.iushrn(1),o.iushrn(1);for(var p=0,g=1;!(r.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(c),h.isub(l)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),n.isub(a),o.isub(h)):(r.isub(e),a.isub(n),h.isub(o))}return{a,b:h,gcd:r.iushln(u)}},s.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n,o=new s(1),a=new s(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,c=1;!(e.words[0]&c)&&u<26;++u,c<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var l=0,f=1;!(r.words[0]&f)&&l<26;++l,f<<=1);if(l>0)for(r.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(n=0===e.cmpn(1)?o:a).cmpn(0)<0&&n.iadd(t),n},s.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var s=e;e=r,r=s}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},s.prototype.invm=function(t){return this.egcd(t).a.umod(t)},s.prototype.isEven=function(){return!(1&this.words[0])},s.prototype.isOdd=function(){return!(1&~this.words[0])},s.prototype.andln=function(t){return this.words[0]&t},s.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<>>26,a&=67108863,this.words[o]=a}return 0!==s&&(this.words[o]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:nt.length)return 1;if(this.length=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){in&&(e=1);break}}return e},s.prototype.gtn=function(t){return 1===this.cmpn(t)},s.prototype.gt=function(t){return 1===this.cmp(t)},s.prototype.gten=function(t){return this.cmpn(t)>=0},s.prototype.gte=function(t){return this.cmp(t)>=0},s.prototype.ltn=function(t){return-1===this.cmpn(t)},s.prototype.lt=function(t){return-1===this.cmp(t)},s.prototype.lten=function(t){return this.cmpn(t)<=0},s.prototype.lte=function(t){return this.cmp(t)<=0},s.prototype.eqn=function(t){return 0===this.cmpn(t)},s.prototype.eq=function(t){return 0===this.cmp(t)},s.red=function(t){return new I(t)},s.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},s.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(t){return this.red=t,this},s.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},s.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},s.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},s.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},s.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},s.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},s.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},s.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},s.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function _(t,e){this.name=t,this.p=new s(e,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function A(){_.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function E(){_.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function S(){_.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){_.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function I(t){if("string"==typeof t){var e=s._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){I.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}_.prototype._tmp=function(){var t=new s(null);return t.words=new Array(Math.ceil(this.n/13)),t},_.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},_.prototype.split=function(t,e){t.iushrn(this.n,0,e)},_.prototype.imulK=function(t){return t.imul(this.k)},n(A,_),A.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n>>22,s=o}s>>>=22,t.words[n-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},A.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},s._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new A;else if("p224"===t)e=new E;else if("p192"===t)e=new S;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return b[t]=e,e},I.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},I.prototype._verify2=function(t,e){i(!(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},I.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(c(t,t.umod(this.m)._forceRed(this)),t)},I.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},I.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},I.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},I.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},I.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},I.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},I.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},I.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},I.prototype.isqr=function(t){return this.imul(t,t.clone())},I.prototype.sqr=function(t){return this.mul(t,t)},I.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new s(1)).iushrn(2);return this.pow(t,r)}for(var n=this.m.subn(1),o=0;!n.isZero()&&0===n.andln(1);)o++,n.iushrn(1);i(!n.isZero());var a=new s(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new s(2*c*c).toRed(this);0!==this.pow(c,u).cmp(h);)c.redIAdd(h);for(var l=this.pow(c,n),f=this.pow(t,n.addn(1).iushrn(1)),d=this.pow(t,n),p=o;0!==d.cmp(a);){for(var g=d,m=0;0!==g.cmp(a);m++)g=g.redSqr();i(m=0;i--){for(var u=e.words[i],c=h-1;c>=0;c--){var l=u>>c&1;n!==r[0]&&(n=this.sqr(n)),0!==l||0!==o?(o<<=1,o|=l,(4==++a||0===i&&0===c)&&(n=this.mul(n,r[o]),a=0,o=0)):a=0}h=26}return n},I.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},I.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},s.mont=function(t){return new x(t)},n(x,I),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},x.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},x.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new s(0)._forceRed(this);var r=t.mul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),o=n;return n.cmp(this.m)>=0?o=n.isub(this.m):n.cmpn(0)<0&&(o=n.iadd(this.m)),o._forceRed(this)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t=r.nmd(t),this)},454:t=>{var e="%[a-f0-9]{2}",r=new RegExp("("+e+")|([^%]+?)","gi"),i=new RegExp("("+e+")+","gi");function n(t,e){try{return[decodeURIComponent(t.join(""))]}catch(t){}if(1===t.length)return t;e=e||1;var r=t.slice(0,e),i=t.slice(e);return Array.prototype.concat.call([],n(r),n(i))}function s(t){try{return decodeURIComponent(t)}catch(s){for(var e=t.match(r)||[],i=1;i{var e,r="object"==typeof Reflect?Reflect:null,i=r&&"function"==typeof r.apply?r.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var n=Number.isNaN||function(t){return t!=t};function s(){s.init.call(this)}t.exports=s,t.exports.once=function(t,e){return new Promise((function(r,i){function n(r){t.removeListener(e,s),i(r)}function s(){"function"==typeof t.removeListener&&t.removeListener("error",n),r([].slice.call(arguments))}g(t,e,s,{once:!0}),"error"!==e&&function(t,e,r){"function"==typeof t.on&&g(t,"error",e,{once:!0})}(t,n)}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function a(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function h(t){return void 0===t._maxListeners?s.defaultMaxListeners:t._maxListeners}function u(t,e,r,i){var n,s,o,u;if(a(r),void 0===(s=t._events)?(s=t._events=Object.create(null),t._eventsCount=0):(void 0!==s.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),o=s[e]),void 0===o)o=s[e]=r,++t._eventsCount;else if("function"==typeof o?o=s[e]=i?[r,o]:[o,r]:i?o.unshift(r):o.push(r),(n=h(t))>0&&o.length>n&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=o.length,u=c,console&&console.warn&&console.warn(u)}return t}function c(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(t,e,r){var i={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},n=c.bind(i);return n.listener=r,i.wrapFn=n,n}function f(t,e,r){var i=t._events;if(void 0===i)return[];var n=i[e];return void 0===n?[]:"function"==typeof n?r?[n.listener||n]:[n]:r?function(t){for(var e=new Array(t.length),r=0;r0&&(o=e[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[t];if(void 0===h)return!1;if("function"==typeof h)i(h,this,e);else{var u=h.length,c=p(h,u);for(r=0;r=0;s--)if(r[s]===e||r[s].listener===e){o=r[s].listener,n=s;break}if(n<0)return this;0===n?r.shift():function(t,e){for(;e+1=0;i--)this.removeListener(t,e[i]);return this},s.prototype.listeners=function(t){return f(this,t,!0)},s.prototype.rawListeners=function(t){return f(this,t,!1)},s.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):d.call(t,e)},s.prototype.listenerCount=d,s.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]}},3055:t=>{t.exports=function(t,e){for(var r={},i=Object.keys(t),n=Array.isArray(e),s=0;s{var i=e;i.utils=r(7426),i.common=r(6166),i.sha=r(6229),i.ripemd=r(6784),i.hmac=r(8948),i.sha1=i.sha.sha1,i.sha256=i.sha.sha256,i.sha224=i.sha.sha224,i.sha384=i.sha.sha384,i.sha512=i.sha.sha512,i.ripemd160=i.ripemd.ripemd160},6166:(t,e,r)=>{var i=r(7426),n=r(3349);function s(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}e.BlockHash=s,s.prototype.update=function(t,e){if(t=i.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=i.join32(t,0,t.length-r,this.endian);for(var n=0;n>>24&255,i[n++]=t>>>16&255,i[n++]=t>>>8&255,i[n++]=255&t}else for(i[n++]=255&t,i[n++]=t>>>8&255,i[n++]=t>>>16&255,i[n++]=t>>>24&255,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,s=8;s{var i=r(7426),n=r(3349);function s(t,e,r){if(!(this instanceof s))return new s(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(i.toArray(e,r))}t.exports=s,s.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),n(t.length<=this.blockSize);for(var e=t.length;e{var i=r(7426),n=r(6166),s=i.rotl32,o=i.sum32,a=i.sum32_3,h=i.sum32_4,u=n.BlockHash;function c(){if(!(this instanceof c))return new c;u.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}function l(t,e,r,i){return t<=15?e^r^i:t<=31?e&r|~e&i:t<=47?(e|~r)^i:t<=63?e&i|r&~i:e^(r|~i)}function f(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function d(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}i.inherits(c,u),e.ripemd160=c,c.blockSize=512,c.outSize=160,c.hmacStrength=192,c.padLength=64,c.prototype._update=function(t,e){for(var r=this.h[0],i=this.h[1],n=this.h[2],u=this.h[3],c=this.h[4],v=r,w=i,b=n,_=u,A=c,E=0;E<80;E++){var S=o(s(h(r,l(E,i,n,u),t[p[E]+e],f(E)),m[E]),c);r=c,c=u,u=s(n,10),n=i,i=S,S=o(s(h(v,l(79-E,w,b,_),t[g[E]+e],d(E)),y[E]),A),v=A,A=_,_=s(b,10),b=w,w=S}S=a(this.h[1],n,_),this.h[1]=a(this.h[2],u,A),this.h[2]=a(this.h[3],c,v),this.h[3]=a(this.h[4],r,w),this.h[4]=a(this.h[0],i,b),this.h[0]=S},c.prototype._digest=function(t){return"hex"===t?i.toHex32(this.h,"little"):i.split32(this.h,"little")};var p=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],g=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],m=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],y=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]},6229:(t,e,r)=>{e.sha1=r(3917),e.sha224=r(7714),e.sha256=r(2287),e.sha384=r(1911),e.sha512=r(7766)},3917:(t,e,r)=>{var i=r(7426),n=r(6166),s=r(6225),o=i.rotl32,a=i.sum32,h=i.sum32_5,u=s.ft_1,c=n.BlockHash,l=[1518500249,1859775393,2400959708,3395469782];function f(){if(!(this instanceof f))return new f;c.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}i.inherits(f,c),t.exports=f,f.blockSize=512,f.outSize=160,f.hmacStrength=80,f.padLength=64,f.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;i{var i=r(7426),n=r(2287);function s(){if(!(this instanceof s))return new s;n.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}i.inherits(s,n),t.exports=s,s.blockSize=512,s.outSize=224,s.hmacStrength=192,s.padLength=64,s.prototype._digest=function(t){return"hex"===t?i.toHex32(this.h.slice(0,7),"big"):i.split32(this.h.slice(0,7),"big")}},2287:(t,e,r)=>{var i=r(7426),n=r(6166),s=r(6225),o=r(3349),a=i.sum32,h=i.sum32_4,u=i.sum32_5,c=s.ch32,l=s.maj32,f=s.s0_256,d=s.s1_256,p=s.g0_256,g=s.g1_256,m=n.BlockHash,y=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function v(){if(!(this instanceof v))return new v;m.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=y,this.W=new Array(64)}i.inherits(v,m),t.exports=v,v.blockSize=512,v.outSize=256,v.hmacStrength=192,v.padLength=64,v.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;i{var i=r(7426),n=r(7766);function s(){if(!(this instanceof s))return new s;n.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}i.inherits(s,n),t.exports=s,s.blockSize=1024,s.outSize=384,s.hmacStrength=192,s.padLength=128,s.prototype._digest=function(t){return"hex"===t?i.toHex32(this.h.slice(0,12),"big"):i.split32(this.h.slice(0,12),"big")}},7766:(t,e,r)=>{var i=r(7426),n=r(6166),s=r(3349),o=i.rotr64_hi,a=i.rotr64_lo,h=i.shr64_hi,u=i.shr64_lo,c=i.sum64,l=i.sum64_hi,f=i.sum64_lo,d=i.sum64_4_hi,p=i.sum64_4_lo,g=i.sum64_5_hi,m=i.sum64_5_lo,y=n.BlockHash,v=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function w(){if(!(this instanceof w))return new w;y.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=v,this.W=new Array(160)}function b(t,e,r,i,n){var s=t&r^~t&n;return s<0&&(s+=4294967296),s}function _(t,e,r,i,n,s){var o=e&i^~e&s;return o<0&&(o+=4294967296),o}function A(t,e,r,i,n){var s=t&r^t&n^r&n;return s<0&&(s+=4294967296),s}function E(t,e,r,i,n,s){var o=e&i^e&s^i&s;return o<0&&(o+=4294967296),o}function S(t,e){var r=o(t,e,28)^o(e,t,2)^o(e,t,7);return r<0&&(r+=4294967296),r}function M(t,e){var r=a(t,e,28)^a(e,t,2)^a(e,t,7);return r<0&&(r+=4294967296),r}function I(t,e){var r=a(t,e,14)^a(t,e,18)^a(e,t,9);return r<0&&(r+=4294967296),r}function x(t,e){var r=o(t,e,1)^o(t,e,8)^h(t,e,7);return r<0&&(r+=4294967296),r}function N(t,e){var r=a(t,e,1)^a(t,e,8)^u(t,e,7);return r<0&&(r+=4294967296),r}function O(t,e){var r=a(t,e,19)^a(e,t,29)^u(t,e,6);return r<0&&(r+=4294967296),r}i.inherits(w,y),t.exports=w,w.blockSize=1024,w.outSize=512,w.hmacStrength=192,w.padLength=128,w.prototype._prepareBlock=function(t,e){for(var r=this.W,i=0;i<32;i++)r[i]=t[e+i];for(;i{var i=r(7426).rotr32;function n(t,e,r){return t&e^~t&r}function s(t,e,r){return t&e^t&r^e&r}function o(t,e,r){return t^e^r}e.ft_1=function(t,e,r,i){return 0===t?n(e,r,i):1===t||3===t?o(e,r,i):2===t?s(e,r,i):void 0},e.ch32=n,e.maj32=s,e.p32=o,e.s0_256=function(t){return i(t,2)^i(t,13)^i(t,22)},e.s1_256=function(t){return i(t,6)^i(t,11)^i(t,25)},e.g0_256=function(t){return i(t,7)^i(t,18)^t>>>3},e.g1_256=function(t){return i(t,17)^i(t,19)^t>>>10}},7426:(t,e,r)=>{var i=r(3349),n=r(6698);function s(t,e){return 55296==(64512&t.charCodeAt(e))&&!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1))}function o(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function a(t){return 1===t.length?"0"+t:t}function h(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}e.inherits=n,e.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),n=0;n>6|192,r[i++]=63&o|128):s(t,n)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++n)),r[i++]=o>>18|240,r[i++]=o>>12&63|128,r[i++]=o>>6&63|128,r[i++]=63&o|128):(r[i++]=o>>12|224,r[i++]=o>>6&63|128,r[i++]=63&o|128)}else for(n=0;n>>0}return o},e.split32=function(t,e){for(var r=new Array(4*t.length),i=0,n=0;i>>24,r[n+1]=s>>>16&255,r[n+2]=s>>>8&255,r[n+3]=255&s):(r[n+3]=s>>>24,r[n+2]=s>>>16&255,r[n+1]=s>>>8&255,r[n]=255&s)}return r},e.rotr32=function(t,e){return t>>>e|t<<32-e},e.rotl32=function(t,e){return t<>>32-e},e.sum32=function(t,e){return t+e>>>0},e.sum32_3=function(t,e,r){return t+e+r>>>0},e.sum32_4=function(t,e,r,i){return t+e+r+i>>>0},e.sum32_5=function(t,e,r,i,n){return t+e+r+i+n>>>0},e.sum64=function(t,e,r,i){var n=t[e],s=i+t[e+1]>>>0,o=(s>>0,t[e+1]=s},e.sum64_hi=function(t,e,r,i){return(e+i>>>0>>0},e.sum64_lo=function(t,e,r,i){return e+i>>>0},e.sum64_4_hi=function(t,e,r,i,n,s,o,a){var h=0,u=e;return h+=(u=u+i>>>0)>>0)>>0)>>0},e.sum64_4_lo=function(t,e,r,i,n,s,o,a){return e+i+s+a>>>0},e.sum64_5_hi=function(t,e,r,i,n,s,o,a,h,u){var c=0,l=e;return c+=(l=l+i>>>0)>>0)>>0)>>0)>>0},e.sum64_5_lo=function(t,e,r,i,n,s,o,a,h,u){return e+i+s+a+u>>>0},e.rotr64_hi=function(t,e,r){return(e<<32-r|t>>>r)>>>0},e.rotr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},e.shr64_hi=function(t,e,r){return t>>>r},e.shr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0}},6698:t=>{"function"==typeof Object.create?t.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},916:(t,e,r)=>{t.exports=self.fetch||(self.fetch=r(6782).default||r(6782))},1176:(t,e,r)=>{var i;!function(){var n="input is invalid type",s="object"==typeof window,o=s?window:{};o.JS_SHA3_NO_WINDOW&&(s=!1);var a=!s&&"object"==typeof self;!o.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?o=r.g:a&&(o=self);var h=!o.JS_SHA3_NO_COMMON_JS&&t.exports,u=r.amdO,c=!o.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),f=[4,1024,262144,67108864],d=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],g=[224,256,384,512],m=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],v={128:168,256:136};!o.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!c||!o.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var w=function(t,e,r){return function(i){return new k(t,e,t).update(i)[r]()}},b=function(t,e,r){return function(i,n){return new k(t,e,n).update(i)[r]()}},_=function(t,e,r){return function(e,i,n,s){return I["cshake"+t].update(e,i,n,s)[r]()}},A=function(t,e,r){return function(e,i,n,s){return I["kmac"+t].update(e,i,n,s)[r]()}},E=function(t,e,r,i){for(var n=0;n>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var i=0;i<50;++i)this.s[i]=0}function U(t,e,r){k.call(this,t,e,r)}k.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(n);if(null===t)throw new Error(n);if(c&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||c&&ArrayBuffer.isView(t)))throw new Error(n);e=!0}for(var i,s,o=this.blocks,a=this.byteCount,h=t.length,u=this.blockCount,l=0,f=this.s;l>2]|=t[l]<>2]|=s<>2]|=(192|s>>6)<>2]|=(128|63&s)<=57344?(o[i>>2]|=(224|s>>12)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<>2]|=(240|s>>18)<>2]|=(128|s>>12&63)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<=a){for(this.start=i-a,this.block=o[u],i=0;i>=8);r>0;)n.unshift(r),r=255&(t>>=8),++i;return e?n.push(i):n.unshift(i),this.update(n),n.length},k.prototype.encodeString=function(t){var e,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(n);if(null===t)throw new Error(n);if(c&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||c&&ArrayBuffer.isView(t)))throw new Error(n);e=!0}var i=0,s=t.length;if(e)i=s;else for(var o=0;o=57344?i+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),i+=4)}return i+=this.encode(8*i),this.update(t),i},k.prototype.bytepad=function(t,e){for(var r=this.encode(e),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>4&15]+l[15&t]+l[t>>12&15]+l[t>>8&15]+l[t>>20&15]+l[t>>16&15]+l[t>>28&15]+l[t>>24&15];o%e==0&&(L(r),s=0)}return n&&(t=r[s],a+=l[t>>4&15]+l[15&t],n>1&&(a+=l[t>>12&15]+l[t>>8&15]),n>2&&(a+=l[t>>20&15]+l[t>>16&15])),a},k.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,i=this.outputBlocks,n=this.extraBytes,s=0,o=0,a=this.outputBits>>3;t=n?new ArrayBuffer(i+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);o>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%r==0&&L(i)}return s&&(t=a<<2,e=i[o],h[t]=255&e,s>1&&(h[t+1]=e>>8&255),s>2&&(h[t+2]=e>>16&255)),h},U.prototype=new k,U.prototype.finalize=function(){return this.encode(this.outputBits,!0),k.prototype.finalize.call(this)};var L=function(t){var e,r,i,n,s,o,a,h,u,c,l,f,d,g,m,y,v,w,b,_,A,E,S,M,I,x,N,O,P,R,C,T,k,U,L,q,D,B,j,z,F,K,H,V,G,W,$,J,Y,Q,X,Z,tt,et,rt,it,nt,st,ot,at,ht,ut,ct;for(i=0;i<48;i+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],o=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],h=t[4]^t[14]^t[24]^t[34]^t[44],u=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],l=t[7]^t[17]^t[27]^t[37]^t[47],e=(f=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),r=(d=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|o>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=n^(h<<1|u>>>31),r=s^(u<<1|h>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=o^(c<<1|l>>>31),r=a^(l<<1|c>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=h^(f<<1|d>>>31),r=u^(d<<1|f>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=c^(n<<1|s>>>31),r=l^(s<<1|n>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,g=t[0],m=t[1],W=t[11]<<4|t[10]>>>28,$=t[10]<<4|t[11]>>>28,O=t[20]<<3|t[21]>>>29,P=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,K=t[40]<<18|t[41]>>>14,H=t[41]<<18|t[40]>>>14,U=t[2]<<1|t[3]>>>31,L=t[3]<<1|t[2]>>>31,y=t[13]<<12|t[12]>>>20,v=t[12]<<12|t[13]>>>20,J=t[22]<<10|t[23]>>>22,Y=t[23]<<10|t[22]>>>22,R=t[33]<<13|t[32]>>>19,C=t[32]<<13|t[33]>>>19,ut=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,q=t[14]<<6|t[15]>>>26,D=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,b=t[24]<<11|t[25]>>>21,Q=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,T=t[45]<<29|t[44]>>>3,k=t[44]<<29|t[45]>>>3,M=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,nt=t[16]<<23|t[17]>>>9,B=t[26]<<25|t[27]>>>7,j=t[27]<<25|t[26]>>>7,_=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Z=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,V=t[8]<<27|t[9]>>>5,G=t[9]<<27|t[8]>>>5,x=t[18]<<20|t[19]>>>12,N=t[19]<<20|t[18]>>>12,st=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,z=t[38]<<8|t[39]>>>24,F=t[39]<<8|t[38]>>>24,E=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=g^~y&w,t[1]=m^~v&b,t[10]=M^~x&O,t[11]=I^~N&P,t[20]=U^~q&B,t[21]=L^~D&j,t[30]=V^~W&J,t[31]=G^~$&Y,t[40]=et^~it&st,t[41]=rt^~nt&ot,t[2]=y^~w&_,t[3]=v^~b&A,t[12]=x^~O&R,t[13]=N^~P&C,t[22]=q^~B&z,t[23]=D^~j&F,t[32]=W^~J&Q,t[33]=$^~Y&X,t[42]=it^~st&at,t[43]=nt^~ot&ht,t[4]=w^~_&E,t[5]=b^~A&S,t[14]=O^~R&T,t[15]=P^~C&k,t[24]=B^~z&K,t[25]=j^~F&H,t[34]=J^~Q&Z,t[35]=Y^~X&tt,t[44]=st^~at&ut,t[45]=ot^~ht&ct,t[6]=_^~E&g,t[7]=A^~S&m,t[16]=R^~T&M,t[17]=C^~k&I,t[26]=z^~K&U,t[27]=F^~H&L,t[36]=Q^~Z&V,t[37]=X^~tt&G,t[46]=at^~ut&et,t[47]=ht^~ct&rt,t[8]=E^~g&y,t[9]=S^~m&v,t[18]=T^~M&x,t[19]=k^~I&N,t[28]=K^~U&q,t[29]=H^~L&D,t[38]=Z^~V&W,t[39]=tt^~G&$,t[48]=ut^~et&it,t[49]=ct^~rt&nt,t[0]^=p[i],t[1]^=p[i+1]};if(h)t.exports=I;else{for(N=0;N{t=r.nmd(t);var i="__lodash_hash_undefined__",n=1,s=2,o=9007199254740991,a="[object Arguments]",h="[object Array]",u="[object AsyncFunction]",c="[object Boolean]",l="[object Date]",f="[object Error]",d="[object Function]",p="[object GeneratorFunction]",g="[object Map]",m="[object Number]",y="[object Null]",v="[object Object]",w="[object Promise]",b="[object Proxy]",_="[object RegExp]",A="[object Set]",E="[object String]",S="[object Undefined]",M="[object WeakMap]",I="[object ArrayBuffer]",x="[object DataView]",N=/^\[object .+?Constructor\]$/,O=/^(?:0|[1-9]\d*)$/,P={};P["[object Float32Array]"]=P["[object Float64Array]"]=P["[object Int8Array]"]=P["[object Int16Array]"]=P["[object Int32Array]"]=P["[object Uint8Array]"]=P["[object Uint8ClampedArray]"]=P["[object Uint16Array]"]=P["[object Uint32Array]"]=!0,P[a]=P[h]=P[I]=P[c]=P[x]=P[l]=P[f]=P[d]=P[g]=P[m]=P[v]=P[_]=P[A]=P[E]=P[M]=!1;var R="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g,C="object"==typeof self&&self&&self.Object===Object&&self,T=R||C||Function("return this")(),k=e&&!e.nodeType&&e,U=k&&t&&!t.nodeType&&t,L=U&&U.exports===k,q=L&&R.process,D=function(){try{return q&&q.binding&&q.binding("util")}catch(t){}}(),B=D&&D.isTypedArray;function j(t,e){for(var r=-1,i=null==t?0:t.length;++ru))return!1;var l=a.get(t);if(l&&a.get(e))return l==e;var f=-1,d=!0,p=r&s?new xt:void 0;for(a.set(t,e),a.set(e,t);++f-1},Mt.prototype.set=function(t,e){var r=this.__data__,i=Ot(r,t);return i<0?(++this.size,r.push([t,e])):r[i][1]=e,this},It.prototype.clear=function(){this.size=0,this.__data__={hash:new St,map:new(ft||Mt),string:new St}},It.prototype.delete=function(t){var e=Ut(this,t).delete(t);return this.size-=e?1:0,e},It.prototype.get=function(t){return Ut(this,t).get(t)},It.prototype.has=function(t){return Ut(this,t).has(t)},It.prototype.set=function(t,e){var r=Ut(this,t),i=r.size;return r.set(t,e),this.size+=r.size==i?0:1,this},xt.prototype.add=xt.prototype.push=function(t){return this.__data__.set(t,i),this},xt.prototype.has=function(t){return this.__data__.has(t)},Nt.prototype.clear=function(){this.__data__=new Mt,this.size=0},Nt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Nt.prototype.get=function(t){return this.__data__.get(t)},Nt.prototype.has=function(t){return this.__data__.has(t)},Nt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Mt){var i=r.__data__;if(!ft||i.length<199)return i.push([t,e]),this.size=++r.size,this;r=this.__data__=new It(i)}return r.set(t,e),this.size=r.size,this};var qt=ht?function(t){return null==t?[]:(t=Object(t),function(e,r){for(var i=-1,n=null==e?0:e.length,s=0,o=[];++i-1&&t%1==0&&t-1&&t%1==0&&t<=o}function Wt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function $t(t){return null!=t&&"object"==typeof t}var Jt=B?function(t){return function(e){return t(e)}}(B):function(t){return $t(t)&&Gt(t.length)&&!!P[Pt(t)]};function Yt(t){return null!=(e=t)&&Gt(e.length)&&!Vt(e)?function(t,e){var r=Kt(t),i=!r&&Ft(t),n=!r&&!i&&Ht(t),s=!r&&!i&&!n&&Jt(t),o=r||i||n||s,a=o?function(t,e){for(var r=-1,i=Array(t);++r{function e(t,e){if(!t)throw new Error(e||"Assertion failed")}t.exports=e,e.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)}},6663:(t,e,r)=>{const i=r(4280),n=r(454),s=r(528),o=r(3055),a=Symbol("encodeFragmentIdentifier");function h(t){if("string"!=typeof t||1!==t.length)throw new TypeError("arrayFormatSeparator must be single character string")}function u(t,e){return e.encode?e.strict?i(t):encodeURIComponent(t):t}function c(t,e){return e.decode?n(t):t}function l(t){return Array.isArray(t)?t.sort():"object"==typeof t?l(Object.keys(t)).sort(((t,e)=>Number(t)-Number(e))).map((e=>t[e])):t}function f(t){const e=t.indexOf("#");return-1!==e&&(t=t.slice(0,e)),t}function d(t){const e=(t=f(t)).indexOf("?");return-1===e?"":t.slice(e+1)}function p(t,e){return e.parseNumbers&&!Number.isNaN(Number(t))&&"string"==typeof t&&""!==t.trim()?t=Number(t):!e.parseBooleans||null===t||"true"!==t.toLowerCase()&&"false"!==t.toLowerCase()||(t="true"===t.toLowerCase()),t}function g(t,e){h((e=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},e)).arrayFormatSeparator);const r=function(t){let e;switch(t.arrayFormat){case"index":return(t,r,i)=>{e=/\[(\d*)\]$/.exec(t),t=t.replace(/\[\d*\]$/,""),e?(void 0===i[t]&&(i[t]={}),i[t][e[1]]=r):i[t]=r};case"bracket":return(t,r,i)=>{e=/(\[\])$/.exec(t),t=t.replace(/\[\]$/,""),e?void 0!==i[t]?i[t]=[].concat(i[t],r):i[t]=[r]:i[t]=r};case"colon-list-separator":return(t,r,i)=>{e=/(:list)$/.exec(t),t=t.replace(/:list$/,""),e?void 0!==i[t]?i[t]=[].concat(i[t],r):i[t]=[r]:i[t]=r};case"comma":case"separator":return(e,r,i)=>{const n="string"==typeof r&&r.includes(t.arrayFormatSeparator),s="string"==typeof r&&!n&&c(r,t).includes(t.arrayFormatSeparator);r=s?c(r,t):r;const o=n||s?r.split(t.arrayFormatSeparator).map((e=>c(e,t))):null===r?r:c(r,t);i[e]=o};case"bracket-separator":return(e,r,i)=>{const n=/(\[\])$/.test(e);if(e=e.replace(/\[\]$/,""),!n)return void(i[e]=r?c(r,t):r);const s=null===r?[]:r.split(t.arrayFormatSeparator).map((e=>c(e,t)));void 0!==i[e]?i[e]=[].concat(i[e],s):i[e]=s};default:return(t,e,r)=>{void 0!==r[t]?r[t]=[].concat(r[t],e):r[t]=e}}}(e),i=Object.create(null);if("string"!=typeof t)return i;if(!(t=t.trim().replace(/^[?#&]/,"")))return i;for(const n of t.split("&")){if(""===n)continue;let[t,o]=s(e.decode?n.replace(/\+/g," "):n,"=");o=void 0===o?null:["comma","separator","bracket-separator"].includes(e.arrayFormat)?o:c(o,e),r(c(t,e),o,i)}for(const t of Object.keys(i)){const r=i[t];if("object"==typeof r&&null!==r)for(const t of Object.keys(r))r[t]=p(r[t],e);else i[t]=p(r,e)}return!1===e.sort?i:(!0===e.sort?Object.keys(i).sort():Object.keys(i).sort(e.sort)).reduce(((t,e)=>{const r=i[e];return Boolean(r)&&"object"==typeof r&&!Array.isArray(r)?t[e]=l(r):t[e]=r,t}),Object.create(null))}e.extract=d,e.parse=g,e.stringify=(t,e)=>{if(!t)return"";h((e=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},e)).arrayFormatSeparator);const r=r=>e.skipNull&&null==t[r]||e.skipEmptyString&&""===t[r],i=function(t){switch(t.arrayFormat){case"index":return e=>(r,i)=>{const n=r.length;return void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,[u(e,t),"[",n,"]"].join("")]:[...r,[u(e,t),"[",u(n,t),"]=",u(i,t)].join("")]};case"bracket":return e=>(r,i)=>void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,[u(e,t),"[]"].join("")]:[...r,[u(e,t),"[]=",u(i,t)].join("")];case"colon-list-separator":return e=>(r,i)=>void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,[u(e,t),":list="].join("")]:[...r,[u(e,t),":list=",u(i,t)].join("")];case"comma":case"separator":case"bracket-separator":{const e="bracket-separator"===t.arrayFormat?"[]=":"=";return r=>(i,n)=>void 0===n||t.skipNull&&null===n||t.skipEmptyString&&""===n?i:(n=null===n?"":n,0===i.length?[[u(r,t),e,u(n,t)].join("")]:[[i,u(n,t)].join(t.arrayFormatSeparator)])}default:return e=>(r,i)=>void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,u(e,t)]:[...r,[u(e,t),"=",u(i,t)].join("")]}}(e),n={};for(const e of Object.keys(t))r(e)||(n[e]=t[e]);const s=Object.keys(n);return!1!==e.sort&&s.sort(e.sort),s.map((r=>{const n=t[r];return void 0===n?"":null===n?u(r,e):Array.isArray(n)?0===n.length&&"bracket-separator"===e.arrayFormat?u(r,e)+"[]":n.reduce(i(r),[]).join("&"):u(r,e)+"="+u(n,e)})).filter((t=>t.length>0)).join("&")},e.parseUrl=(t,e)=>{e=Object.assign({decode:!0},e);const[r,i]=s(t,"#");return Object.assign({url:r.split("?")[0]||"",query:g(d(t),e)},e&&e.parseFragmentIdentifier&&i?{fragmentIdentifier:c(i,e)}:{})},e.stringifyUrl=(t,r)=>{r=Object.assign({encode:!0,strict:!0,[a]:!0},r);const i=f(t.url).split("?")[0]||"",n=e.extract(t.url),s=e.parse(n,{sort:!1}),o=Object.assign(s,t.query);let h=e.stringify(o,r);h&&(h=`?${h}`);let c=function(t){let e="";const r=t.indexOf("#");return-1!==r&&(e=t.slice(r)),e}(t.url);return t.fragmentIdentifier&&(c=`#${r[a]?u(t.fragmentIdentifier,r):t.fragmentIdentifier}`),`${i}${h}${c}`},e.pick=(t,r,i)=>{i=Object.assign({parseFragmentIdentifier:!0,[a]:!1},i);const{url:n,query:s,fragmentIdentifier:h}=e.parseUrl(t,i);return e.stringifyUrl({url:n,query:o(s,r),fragmentIdentifier:h},i)},e.exclude=(t,r,i)=>{const n=Array.isArray(r)?t=>!r.includes(t):(t,e)=>!r(t,e);return e.pick(t,n,i)}},793:t=>{function e(t){try{return JSON.stringify(t)}catch(t){return'"[Circular]"'}}t.exports=function(t,r,i){var n=i&&i.stringify||e;if("object"==typeof t&&null!==t){var s=r.length+1;if(1===s)return t;var o=new Array(s);o[0]=n(t);for(var a=1;a-1?l:0,t.charCodeAt(d+1)){case 100:case 102:if(c>=h)break;if(null==r[c])break;l=h)break;if(null==r[c])break;l=h)break;if(void 0===r[c])break;l",l=d+2,d++;break}u+=n(r[c]),l=d+2,d++;break;case 115:if(c>=h)break;l{t.exports=(t,e)=>{if("string"!=typeof t||"string"!=typeof e)throw new TypeError("Expected the arguments to be of type `string`");if(""===e)return[t];const r=t.indexOf(e);return-1===r?[t]:[t.slice(0,r),t.slice(r+e.length)]}},4280:t=>{t.exports=t=>encodeURIComponent(t).replace(/[!'()*]/g,(t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`))},5215:(t,e,r)=>{r.r(e),r.d(e,{__assign:()=>s,__asyncDelegator:()=>b,__asyncGenerator:()=>w,__asyncValues:()=>_,__await:()=>v,__awaiter:()=>c,__classPrivateFieldGet:()=>M,__classPrivateFieldSet:()=>I,__createBinding:()=>f,__decorate:()=>a,__exportStar:()=>d,__extends:()=>n,__generator:()=>l,__importDefault:()=>S,__importStar:()=>E,__makeTemplateObject:()=>A,__metadata:()=>u,__param:()=>h,__read:()=>g,__rest:()=>o,__spread:()=>m,__spreadArrays:()=>y,__values:()=>p});var i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},i(t,e)};function n(t,e){function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var s=function(){return s=Object.assign||function(t){for(var e,r=1,i=arguments.length;r=0;a--)(n=t[a])&&(o=(s<3?n(o):s>3?n(e,r,o):n(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o}function h(t,e){return function(r,i){e(r,i,t)}}function u(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function c(t,e,r,i){return new(r||(r=Promise))((function(n,s){function o(t){try{h(i.next(t))}catch(t){s(t)}}function a(t){try{h(i.throw(t))}catch(t){s(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,a)}h((i=i.apply(t,e||[])).next())}))}function l(t,e){var r,i,n,s,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,i&&(n=2&s[0]?i.return:s[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,s[1])).done)return n;switch(i=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((n=(n=o.trys).length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function g(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var i,n,s=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(i=s.next()).done;)o.push(i.value)}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}return o}function m(){for(var t=[],e=0;e1||a(t,e)}))})}function a(t,e){try{(r=n[t](e)).value instanceof v?Promise.resolve(r.value.v).then(h,u):c(s[0][2],r)}catch(t){c(s[0][3],t)}var r}function h(t){a("next",t)}function u(t){a("throw",t)}function c(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}function b(t){var e,r;return e={},i("next"),i("throw",(function(t){throw t})),i("return"),e[Symbol.iterator]=function(){return this},e;function i(i,n){e[i]=t[i]?function(e){return(r=!r)?{value:v(t[i](e)),done:"return"===i}:n?n(e):e}:n}}function _(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=p(t),e={},i("next"),i("throw"),i("return"),e[Symbol.asyncIterator]=function(){return this},e);function i(r){e[r]=t[r]&&function(e){return new Promise((function(i,n){!function(t,e,r,i){Promise.resolve(i).then((function(e){t({value:e,done:r})}),e)}(i,n,(e=t[r](e)).done,e.value)}))}}}function A(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function E(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function S(t){return t&&t.__esModule?t:{default:t}}function M(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function I(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}},6782:(t,e,r)=>{function i(t,e){return e=e||{},new Promise((function(r,i){var n=new XMLHttpRequest,s=[],o=[],a={},h=function(){return{ok:2==(n.status/100|0),statusText:n.statusText,status:n.status,url:n.responseURL,text:function(){return Promise.resolve(n.responseText)},json:function(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([n.response]))},clone:h,headers:{keys:function(){return s},entries:function(){return o},get:function(t){return a[t.toLowerCase()]},has:function(t){return t.toLowerCase()in a}}}};for(var u in n.open(e.method||"get",t,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(t,e,r){s.push(e=e.toLowerCase()),o.push([e,r]),a[e]=a[e]?a[e]+","+r:r})),r(h())},n.onerror=i,n.withCredentials="include"==e.credentials,e.headers)n.setRequestHeader(u,e.headers[u]);n.send(e.body||null)}))}r.r(e),r.d(e,{default:()=>i})},1591:t=>{t.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},9432:()=>{},7790:()=>{},4874:(t,e,r)=>{const i=r(793);t.exports=o;const n=function(){function t(t){return void 0!==t&&t}try{return"undefined"!=typeof globalThis||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch(e){return t(self)||t(window)||t(this)||{}}}().console||{},s={mapHttpRequest:f,mapHttpResponse:f,wrapRequestSerializer:d,wrapResponseSerializer:d,wrapErrorSerializer:d,req:f,res:f,err:function(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const r in t)void 0===e[r]&&(e[r]=t[r]);return e}};function o(t){(t=t||{}).browser=t.browser||{};const e=t.browser.transmit;if(e&&"function"!=typeof e.send)throw Error("pino: transmit option must have a send function");const r=t.browser.write||n;t.browser.write&&(t.browser.asObject=!0);const i=t.serializers||{},s=function(t,e){if(Array.isArray(t)){const e=t.filter((function(t){return"!stdSerializers.err"!==t}));return e}return!0===t&&Object.keys(e)}(t.browser.serialize,i);let f=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(f=!1),"function"==typeof r&&(r.error=r.fatal=r.warn=r.info=r.debug=r.trace=r),!1===t.enabled&&(t.level="silent");const d=t.level||"info",g=Object.create(r);g.log||(g.log=p),Object.defineProperty(g,"levelVal",{get:function(){return"silent"===this.level?1/0:this.levels.values[this.level]}}),Object.defineProperty(g,"level",{get:function(){return this._level},set:function(t){if("silent"!==t&&!this.levels.values[t])throw Error("unknown level "+t);this._level=t,a(m,g,"error","log"),a(m,g,"fatal","error"),a(m,g,"warn","error"),a(m,g,"info","log"),a(m,g,"debug","log"),a(m,g,"trace","log")}});const m={transmit:e,serialize:s,asObject:t.browser.asObject,levels:["error","fatal","warn","info","debug","trace"],timestamp:l(t)};return g.levels=o.levels,g.level=d,g.setMaxListeners=g.getMaxListeners=g.emit=g.addListener=g.on=g.prependListener=g.once=g.prependOnceListener=g.removeListener=g.removeAllListeners=g.listeners=g.listenerCount=g.eventNames=g.write=g.flush=p,g.serializers=i,g._serialize=s,g._stdErrSerialize=f,g.child=function(r,n){if(!r)throw new Error("missing bindings for child Pino");n=n||{},s&&r.serializers&&(n.serializers=r.serializers);const o=n.serializers;if(s&&o){var a=Object.assign({},i,o),l=!0===t.browser.serialize?Object.keys(a):s;delete r.serializers,h([r],l,a,this._stdErrSerialize)}function f(t){this._childLevel=1+(0|t._childLevel),this.error=u(t,r,"error"),this.fatal=u(t,r,"fatal"),this.warn=u(t,r,"warn"),this.info=u(t,r,"info"),this.debug=u(t,r,"debug"),this.trace=u(t,r,"trace"),a&&(this.serializers=a,this._serialize=l),e&&(this._logEvent=c([].concat(t._logEvent.bindings,r)))}return f.prototype=this,new f(this)},e&&(g._logEvent=c()),g}function a(t,e,r,s){const a=Object.getPrototypeOf(e);e[r]=e.levelVal>e.levels.values[r]?p:a[r]?a[r]:n[r]||n[s]||p,function(t,e,r){var s;(t.transmit||e[r]!==p)&&(e[r]=(s=e[r],function(){const a=t.timestamp(),u=new Array(arguments.length),l=Object.getPrototypeOf&&Object.getPrototypeOf(this)===n?n:this;for(var f=0;f-1&&i in r&&(t[n][i]=r[i](t[n][i]))}function u(t,e,r){return function(){const i=new Array(1+arguments.length);i[0]=e;for(var n=1;n{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.nmd=t=>(t.paths=[],t.children||(t.children=[]),t);var i={};r.r(i),r.d(i,{identity:()=>ie});var n={};r.r(n),r.d(n,{base2:()=>ne});var s={};r.r(s),r.d(s,{base8:()=>se});var o={};r.r(o),r.d(o,{base10:()=>oe});var a={};r.r(a),r.d(a,{base16:()=>ae,base16upper:()=>he});var h={};r.r(h),r.d(h,{base32:()=>ue,base32hex:()=>de,base32hexpad:()=>ge,base32hexpadupper:()=>me,base32hexupper:()=>pe,base32pad:()=>le,base32padupper:()=>fe,base32upper:()=>ce,base32z:()=>ye});var u={};r.r(u),r.d(u,{base36:()=>ve,base36upper:()=>we});var c={};r.r(c),r.d(c,{base58btc:()=>be,base58flickr:()=>_e});var l={};r.r(l),r.d(l,{base64:()=>Ae,base64pad:()=>Ee,base64url:()=>Se,base64urlpad:()=>Me});var f={};r.r(f),r.d(f,{base256emoji:()=>Oe});var d={};r.r(d),r.d(d,{sha256:()=>Qe,sha512:()=>Xe});var p={};r.r(p),r.d(p,{identity:()=>tr});var g={};r.r(g),r.d(g,{code:()=>rr,decode:()=>nr,encode:()=>ir,name:()=>er});var m={};r.r(m),r.d(m,{code:()=>hr,decode:()=>cr,encode:()=>ur,name:()=>ar});var y=r(7007),v=r.n(y);const w=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,b=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,_=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function A(t,e){if(!("__proto__"===t||"constructor"===t&&e&&"object"==typeof e&&"prototype"in e))return e;!function(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}(t)}function E(t,e={}){if("string"!=typeof t)return t;const r=t.trim();if('"'===t[0]&&'"'===t.at(-1)&&!t.includes("\\"))return r.slice(1,-1);if(r.length<=9){const t=r.toLowerCase();if("true"===t)return!0;if("false"===t)return!1;if("undefined"===t)return;if("null"===t)return null;if("nan"===t)return Number.NaN;if("infinity"===t)return Number.POSITIVE_INFINITY;if("-infinity"===t)return Number.NEGATIVE_INFINITY}if(!_.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(w.test(t)||b.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,A)}return JSON.parse(t)}catch(r){if(e.strict)throw r;return t}}function S(t,...e){try{return(r=t(...e))&&"function"==typeof r.then?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}var r}function M(t){if(function(t){const e=typeof t;return null===t||"object"!==e&&"function"!==e}(t))return String(t);if(function(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}(t)||Array.isArray(t))return JSON.stringify(t);if("function"==typeof t.toJSON)return M(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function I(){if(void 0===typeof Buffer)throw new TypeError("[unstorage] Buffer is not supported!")}const x="base64:";function N(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function O(...t){return N(t.join(":"))}function P(t){return(t=N(t))?t+":":""}const R=()=>{const t=new Map;return{name:"memory",options:{},hasItem:e=>t.has(e),getItem:e=>t.get(e)??null,getItemRaw:e=>t.get(e)??null,setItem(e,r){t.set(e,r)},setItemRaw(e,r){t.set(e,r)},removeItem(e){t.delete(e)},getKeys:()=>Array.from(t.keys()),clear(){t.clear()},dispose(){t.clear()}}};function C(t,e,r){return t.watch?t.watch(((t,i)=>e(t,r+i))):()=>{}}async function T(t){"function"==typeof t.dispose&&await S(t.dispose)}function k(t){return new Promise(((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)}))}function U(t,e){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(e);const i=k(r);return(t,r)=>i.then((i=>r(i.transaction(e,t).objectStore(e))))}let L;function q(){return L||(L=U("keyval-store","keyval")),L}function D(t,e=q()){return e("readonly",(e=>k(e.get(t))))}const B=t=>JSON.stringify(t,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),j=t=>{const e=t.replace(/([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g,'$1"$2n"$3');return JSON.parse(e,((t,e)=>"string"==typeof e&&e.match(/^\d+n$/)?BigInt(e.substring(0,e.length-1)):e))};function z(t){if("string"!=typeof t)throw new Error("Cannot safe json parse value of type "+typeof t);try{return j(t)}catch(e){return t}}function F(t){return"string"==typeof t?t:B(t)||""}var K=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",r=t=>e+t;let i;return t.dbName&&t.storeName&&(i=U(t.dbName,t.storeName)),{name:"idb-keyval",options:t,hasItem:async t=>!(typeof await D(r(t),i)>"u"),getItem:async t=>await D(r(t),i)??null,setItem:(t,e)=>function(t,e,r=q()){return r("readwrite",(r=>(r.put(e,t),k(r.transaction))))}(r(t),e,i),removeItem:t=>function(t,e=q()){return e("readwrite",(e=>(e.delete(t),k(e.transaction))))}(r(t),i),getKeys:()=>function(t=q()){return t("readonly",(t=>{if(t.getAllKeys)return k(t.getAllKeys());const e=[];return function(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},k(t.transaction)}(t,(t=>e.push(t.key))).then((()=>e))}))}(i),clear:()=>function(t=q()){return t("readwrite",(t=>(t.clear(),k(t.transaction))))}(i)}};class H{constructor(){this.indexedDb=function(t={}){const e={mounts:{"":t.driver||R()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},r=t=>{for(const r of e.mountpoints)if(t.startsWith(r))return{base:r,relativeKey:t.slice(r.length),driver:e.mounts[r]};return{base:"",relativeKey:t,driver:e.mounts[""]}},i=(t,r)=>e.mountpoints.filter((e=>e.startsWith(t)||r&&t.startsWith(e))).map((r=>({relativeBase:t.length>r.length?t.slice(r.length):void 0,mountpoint:r,driver:e.mounts[r]}))),n=(t,r)=>{if(e.watching){r=N(r);for(const i of e.watchListeners)i(t,r)}},s=async()=>{if(e.watching){for(const t in e.unwatch)await e.unwatch[t]();e.unwatch={},e.watching=!1}},o=(t,e,i)=>{const n=new Map,s=t=>{let e=n.get(t.base);return e||(e={driver:t.driver,base:t.base,items:[]},n.set(t.base,e)),e};for(const i of t){const t="string"==typeof i,n=N(t?i:i.key),o=t?void 0:i.value,a=t||!i.options?e:{...e,...i.options},h=r(n);s(h).items.push({key:n,value:o,relativeKey:h.relativeKey,options:a})}return Promise.all([...n.values()].map((t=>i(t)))).then((t=>t.flat()))},a={hasItem(t,e={}){t=N(t);const{relativeKey:i,driver:n}=r(t);return S(n.hasItem,i,e)},getItem(t,e={}){t=N(t);const{relativeKey:i,driver:n}=r(t);return S(n.getItem,i,e).then((t=>E(t)))},getItems:(t,e)=>o(t,e,(t=>t.driver.getItems?S(t.driver.getItems,t.items.map((t=>({key:t.relativeKey,options:t.options}))),e).then((e=>e.map((e=>({key:O(t.base,e.key),value:E(e.value)}))))):Promise.all(t.items.map((e=>S(t.driver.getItem,e.relativeKey,e.options).then((t=>({key:e.key,value:E(t)})))))))),getItemRaw(t,e={}){t=N(t);const{relativeKey:i,driver:n}=r(t);return n.getItemRaw?S(n.getItemRaw,i,e):S(n.getItem,i,e).then((t=>function(t){return"string"!=typeof t?t:t.startsWith(x)?(I(),Buffer.from(t.slice(7),"base64")):t}(t)))},async setItem(t,e,i={}){if(void 0===e)return a.removeItem(t);t=N(t);const{relativeKey:s,driver:o}=r(t);o.setItem&&(await S(o.setItem,s,M(e),i),o.watch||n("update",t))},async setItems(t,e){await o(t,e,(async t=>{t.driver.setItems&&await S(t.driver.setItems,t.items.map((t=>({key:t.relativeKey,value:M(t.value),options:t.options}))),e),t.driver.setItem&&await Promise.all(t.items.map((e=>S(t.driver.setItem,e.relativeKey,M(e.value),e.options))))}))},async setItemRaw(t,e,i={}){if(void 0===e)return a.removeItem(t,i);t=N(t);const{relativeKey:s,driver:o}=r(t);if(o.setItemRaw)await S(o.setItemRaw,s,e,i);else{if(!o.setItem)return;await S(o.setItem,s,function(t){if("string"==typeof t)return t;I();const e=Buffer.from(t).toString("base64");return x+e}(e),i)}o.watch||n("update",t)},async removeItem(t,e={}){"boolean"==typeof e&&(e={removeMeta:e}),t=N(t);const{relativeKey:i,driver:s}=r(t);s.removeItem&&(await S(s.removeItem,i,e),(e.removeMeta||e.removeMata)&&await S(s.removeItem,i+"$",e),s.watch||n("remove",t))},async getMeta(t,e={}){"boolean"==typeof e&&(e={nativeOnly:e}),t=N(t);const{relativeKey:i,driver:n}=r(t),s=Object.create(null);if(n.getMeta&&Object.assign(s,await S(n.getMeta,i,e)),!e.nativeOnly){const t=await S(n.getItem,i+"$",e).then((t=>E(t)));t&&"object"==typeof t&&("string"==typeof t.atime&&(t.atime=new Date(t.atime)),"string"==typeof t.mtime&&(t.mtime=new Date(t.mtime)),Object.assign(s,t))}return s},setMeta(t,e,r={}){return this.setItem(t+"$",e,r)},removeMeta(t,e={}){return this.removeItem(t+"$",e)},async getKeys(t,e={}){t=P(t);const r=i(t,!0);let n=[];const s=[];for(const t of r){const r=(await S(t.driver.getKeys,t.relativeBase,e)).map((e=>t.mountpoint+N(e))).filter((t=>!n.some((e=>t.startsWith(e)))));s.push(...r),n=[t.mountpoint,...n.filter((e=>!e.startsWith(t.mountpoint)))]}return t?s.filter((e=>e.startsWith(t)&&!e.endsWith("$"))):s.filter((t=>!t.endsWith("$")))},async clear(t,e={}){t=P(t),await Promise.all(i(t,!1).map((async t=>{if(t.driver.clear)return S(t.driver.clear,t.relativeBase,e);if(t.driver.removeItem){const r=await t.driver.getKeys(t.relativeBase||"",e);return Promise.all(r.map((r=>t.driver.removeItem(r,e))))}})))},async dispose(){await Promise.all(Object.values(e.mounts).map((t=>T(t))))},watch:async t=>(await(async()=>{if(!e.watching){e.watching=!0;for(const t in e.mounts)e.unwatch[t]=await C(e.mounts[t],n,t)}})(),e.watchListeners.push(t),async()=>{e.watchListeners=e.watchListeners.filter((e=>e!==t)),0===e.watchListeners.length&&await s()}),async unwatch(){e.watchListeners=[],await s()},mount(t,r){if((t=P(t))&&e.mounts[t])throw new Error(`already mounted at ${t}`);return t&&(e.mountpoints.push(t),e.mountpoints.sort(((t,e)=>e.length-t.length))),e.mounts[t]=r,e.watching&&Promise.resolve(C(r,n,t)).then((r=>{e.unwatch[t]=r})).catch(console.error),a},async unmount(t,r=!0){(t=P(t))&&e.mounts[t]&&(e.watching&&t in e.unwatch&&(e.unwatch[t](),delete e.unwatch[t]),r&&await T(e.mounts[t]),e.mountpoints=e.mountpoints.filter((e=>e!==t)),delete e.mounts[t])},getMount(t=""){t=N(t)+":";const e=r(t);return{driver:e.driver,base:e.base}},getMounts:(t="",e={})=>(t=N(t),i(t,e.parents).map((t=>({driver:t.driver,base:t.mountpoint}))))};return a}({driver:K({dbName:"WALLET_CONNECT_V2_INDEXED_DB",storeName:"keyvaluestorage"})})}async getKeys(){return this.indexedDb.getKeys()}async getEntries(){return(await this.indexedDb.getItems(await this.indexedDb.getKeys())).map((t=>[t.key,t.value]))}async getItem(t){const e=await this.indexedDb.getItem(t);if(null!==e)return e}async setItem(t,e){await this.indexedDb.setItem(t,F(e))}async removeItem(t){await this.indexedDb.removeItem(t)}}var V=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof r.g<"u"?r.g:typeof self<"u"?self:{},G={exports:{}};function W(t){var e;return[t[0],z(null!=(e=t[1])?e:"")]}!function(){let t;function e(){}t=e,t.prototype.getItem=function(t){return this.hasOwnProperty(t)?String(this[t]):null},t.prototype.setItem=function(t,e){this[t]=String(e)},t.prototype.removeItem=function(t){delete this[t]},t.prototype.clear=function(){const t=this;Object.keys(t).forEach((function(e){t[e]=void 0,delete t[e]}))},t.prototype.key=function(t){return t=t||0,Object.keys(this)[t]},t.prototype.__defineGetter__("length",(function(){return Object.keys(this).length})),typeof V<"u"&&V.localStorage?G.exports=V.localStorage:typeof window<"u"&&window.localStorage?G.exports=window.localStorage:G.exports=new e}();class ${constructor(){this.localStorage=G.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(W)}async getItem(t){const e=this.localStorage.getItem(t);if(null!==e)return z(e)}async setItem(t,e){this.localStorage.setItem(t,F(e))}async removeItem(t){this.localStorage.removeItem(t)}}class J{constructor(){this.initialized=!1,this.setInitialized=t=>{this.storage=t,this.initialized=!0};const t=new $;this.storage=t;try{(async(t,e,r)=>{const i="wc_storage_version",n=await e.getItem(i);if(n&&n>=1)return void r(e);const s=await t.getKeys();if(!s.length)return void r(e);const o=[];for(;s.length;){const r=s.shift();if(!r)continue;const i=r.toLowerCase();if(i.includes("wc@")||i.includes("walletconnect")||i.includes("wc_")||i.includes("wallet_connect")){const i=await t.getItem(r);await e.setItem(r,i),o.push(r)}}await e.setItem(i,1),r(e),(async(t,e)=>{e.length&&e.forEach((async e=>{await t.removeItem(e)}))})(t,o)})(t,new H,this.setInitialized)}catch{this.initialized=!0}}async getKeys(){return await this.initialize(),this.storage.getKeys()}async getEntries(){return await this.initialize(),this.storage.getEntries()}async getItem(t){return await this.initialize(),this.storage.getItem(t)}async setItem(t,e){return await this.initialize(),this.storage.setItem(t,e)}async removeItem(t){return await this.initialize(),this.storage.removeItem(t)}async initialize(){this.initialized||await new Promise((t=>{const e=setInterval((()=>{this.initialized&&(clearInterval(e),t())}),20)}))}}var Y=r(8900);class Q{}class X extends Q{constructor(t){super()}}const Z=Y.FIVE_SECONDS,tt="heartbeat_pulse";class et extends X{constructor(t){super(t),this.events=new y.EventEmitter,this.interval=Z,this.interval=t?.interval||Z}static async init(t){const e=new et(t);return await e.init(),e}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async initialize(){this.intervalRef=setInterval((()=>this.pulse()),(0,Y.toMiliseconds)(this.interval))}pulse(){this.events.emit(tt)}}var rt=r(4874),it=r.n(rt);const nt="custom_context";class st{constructor(t){this.nodeValue=t,this.sizeInBytes=(new TextEncoder).encode(this.nodeValue).length,this.next=null}get value(){return this.nodeValue}get size(){return this.sizeInBytes}}class ot{constructor(t){this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=t,this.sizeInBytes=0}append(t){const e=new st(t);if(e.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${t} with size ${e.size}`);for(;this.size+e.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=e),this.tail=e):(this.head=e,this.tail=e),this.lengthInNodes++,this.sizeInBytes+=e.size}shift(){if(!this.head)return;const t=this.head;this.head=this.head.next,this.head||(this.tail=null),this.lengthInNodes--,this.sizeInBytes-=t.size}toArray(){const t=[];let e=this.head;for(;null!==e;)t.push(e.value),e=e.next;return t}get length(){return this.lengthInNodes}get size(){return this.sizeInBytes}toOrderedArray(){return Array.from(this)}[Symbol.iterator](){let t=this.head;return{next:()=>{if(!t)return{done:!0,value:null};const e=t.value;return t=t.next,{done:!1,value:e}}}}}class at{constructor(t,e=1024e3){this.level=t??"error",this.levelValue=rt.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=e,this.logs=new ot(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(t,e){e===rt.levels.values.error?console.error(t):e===rt.levels.values.warn?console.warn(t):e===rt.levels.values.debug?console.debug(t):e===rt.levels.values.trace?console.trace(t):console.log(t)}appendToLogs(t){this.logs.append(F({timestamp:(new Date).toISOString(),log:t}));const e="string"==typeof t?JSON.parse(t).level:t.level;e>=this.levelValue&&this.forwardToConsole(t,e)}getLogs(){return this.logs}clearLogs(){this.logs=new ot(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(t){const e=this.getLogArray();return e.push(F({extraMetadata:t})),new Blob(e,{type:"application/json"})}}class ht{constructor(t,e=1024e3){this.baseChunkLogger=new at(t,e)}write(t){this.baseChunkLogger.appendToLogs(t)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(t){return this.baseChunkLogger.logsToBlob(t)}downloadLogsBlobInBrowser(t){const e=URL.createObjectURL(this.logsToBlob(t)),r=document.createElement("a");r.href=e,r.download=`walletconnect-logs-${(new Date).toISOString()}.txt`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(e)}}class ut{constructor(t,e=1024e3){this.baseChunkLogger=new at(t,e)}write(t){this.baseChunkLogger.appendToLogs(t)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(t){return this.baseChunkLogger.logsToBlob(t)}}var ct=Object.defineProperty,lt=Object.defineProperties,ft=Object.getOwnPropertyDescriptors,dt=Object.getOwnPropertySymbols,pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,mt=(t,e,r)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yt=(t,e)=>{for(var r in e||(e={}))pt.call(e,r)&&mt(t,r,e[r]);if(dt)for(var r of dt(e))gt.call(e,r)&&mt(t,r,e[r]);return t},vt=(t,e)=>lt(t,ft(e));function wt(t){return vt(yt({},t),{level:t?.level||"info"})}function bt(t,e=nt){let r="";return r=typeof t.bindings>"u"?function(t,e=nt){return t[e]||""}(t,e):t.bindings().context||"",r}function _t(t,e,r=nt){const i=function(t,e,r=nt){const i=bt(t,r);return i.trim()?`${i}/${e}`:e}(t,e,r);return function(t,e,r=nt){return t[r]=e,t}(t.child({context:i}),i,r)}function At(t){return typeof t.loggerOverride<"u"&&"string"!=typeof t.loggerOverride?{logger:t.loggerOverride,chunkLoggerController:null}:typeof window<"u"?function(t){var e,r;const i=new ht(null==(e=t.opts)?void 0:e.level,t.maxSizeInBytes);return{logger:it()(vt(yt({},t.opts),{level:"trace",browser:vt(yt({},null==(r=t.opts)?void 0:r.browser),{write:t=>i.write(t)})})),chunkLoggerController:i}}(t):function(t){var e;const r=new ut(null==(e=t.opts)?void 0:e.level,t.maxSizeInBytes);return{logger:it()(vt(yt({},t.opts),{level:"trace"}),r),chunkLoggerController:r}}(t)}class Et extends Q{constructor(t){super(),this.opts=t,this.protocol="wc",this.version=2}}class St extends Q{constructor(t,e){super(),this.core=t,this.logger=e,this.records=new Map}}class Mt{constructor(t,e){this.logger=t,this.core=e}}class It extends Q{constructor(t,e){super(),this.relayer=t,this.logger=e}}class xt extends Q{constructor(t){super()}}class Nt{constructor(t,e,r,i){this.core=t,this.logger=e,this.name=r}}class Ot extends Q{constructor(t,e){super(),this.relayer=t,this.logger=e}}class Pt extends Q{constructor(t,e){super(),this.core=t,this.logger=e}}class Rt{constructor(t,e){this.projectId=t,this.logger=e}}class Ct{constructor(t,e){this.projectId=t,this.logger=e}}v();class Tt{constructor(t){this.opts=t,this.protocol="wc",this.version=2}}y.EventEmitter;class kt{constructor(t){this.client=t}}var Ut=r(4904),Lt=r(7052);const qt="base64url",Dt="utf8",Bt=":",jt="did",zt="key",Ft="base58btc",Kt="z",Ht="K36";function Vt(t){return null!=globalThis.Buffer?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Gt(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?Vt(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}const Wt=function(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i>>0,o=new Uint8Array(s);t[e];){var c=r[t.charCodeAt(e)];if(255===c)return;for(var l=0,f=s-1;(0!==c||l>>0,o[f]=c%256>>>0,c=c/256>>>0;if(0!==c)throw new Error("Non-zero carry");n=l,e++}if(" "!==t[e]){for(var d=s-n;d!==s&&0===o[d];)d++;for(var p=new Uint8Array(i+(s-d)),g=i;d!==s;)p[g++]=o[d++];return p}}}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,i=0,n=0,s=e.length;n!==s&&0===e[n];)n++,r++;for(var o=(s-n)*c+1>>>0,u=new Uint8Array(o);n!==s;){for(var l=e[n],f=0,d=o-1;(0!==l||f>>0,u[d]=l%a>>>0,l=l/a>>>0;if(0!==l)throw new Error("Non-zero carry");i=f,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var g=h.repeat(r);p{if(t instanceof Uint8Array&&"Uint8Array"===t.constructor.name)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")});class Jt{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class Yt{constructor(t,e,r){if(this.name=t,this.prefix=e,void 0===e.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if("string"==typeof t){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(t){return Xt(this,t)}}class Qt{constructor(t){this.decoders=t}or(t){return Xt(this,t)}decode(t){const e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Xt=(t,e)=>new Qt({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Zt{constructor(t,e,r,i){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=i,this.encoder=new Jt(t,e,r),this.decoder=new Yt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const te=({name:t,prefix:e,encode:r,decode:i})=>new Zt(t,e,r,i),ee=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=Wt(r,e);return te({prefix:t,name:e,encode:i,decode:t=>$t(n(t))})},re=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>te({prefix:e,name:t,encode:t=>((t,e,r)=>{const i="="===e[e.length-1],n=(1<r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<((t,e,r,i)=>{const n={};for(let t=0;t=8&&(a-=8,o[u++]=255&h>>a)}if(a>=r||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o})(e,i,r,t)}),ie=te({prefix:"\0",name:"identity",encode:t=>{return e=t,(new TextDecoder).decode(e);var e},decode:t=>(t=>(new TextEncoder).encode(t))(t)}),ne=re({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1}),se=re({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3}),oe=ee({prefix:"9",name:"base10",alphabet:"0123456789"}),ae=re({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),he=re({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4}),ue=re({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ce=re({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),le=re({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),fe=re({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),de=re({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pe=re({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ge=re({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),me=re({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ye=re({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),ve=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),we=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),be=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_e=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),Ae=re({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ee=re({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Se=re({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Me=re({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),Ie=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),xe=Ie.reduce(((t,e,r)=>(t[r]=e,t)),[]),Ne=Ie.reduce(((t,e,r)=>(t[e.codePointAt(0)]=r,t)),[]),Oe=te({prefix:"🚀",name:"base256emoji",encode:function(t){return t.reduce(((t,e)=>t+xe[e]),"")},decode:function(t){const e=[];for(const r of t){const t=Ne[r.codePointAt(0)];if(void 0===t)throw new Error(`Non-base256emoji character: ${r}`);e.push(t)}return new Uint8Array(e)}});var Pe=128,Re=-128,Ce=Math.pow(2,31),Te=Math.pow(2,7),ke=Math.pow(2,14),Ue=Math.pow(2,21),Le=Math.pow(2,28),qe=Math.pow(2,35),De=Math.pow(2,42),Be=Math.pow(2,49),je=Math.pow(2,56),ze=Math.pow(2,63);const Fe=function t(e,r,i){r=r||[];for(var n=i=i||0;e>=Ce;)r[i++]=255&e|Pe,e/=128;for(;eℜ)r[i++]=255&e|Pe,e>>>=7;return r[i]=0|e,t.bytes=i-n+1,r},Ke=function(t){return t(Fe(t,e,r),e),Ve=t=>Ke(t),Ge=(t,e)=>{const r=e.byteLength,i=Ve(t),n=i+Ve(r),s=new Uint8Array(n+r);return He(t,s,0),He(r,s,i),s.set(e,n),new We(t,r,e,s)};class We{constructor(t,e,r,i){this.code=t,this.size=e,this.digest=r,this.bytes=i}}const $e=({name:t,code:e,encode:r})=>new Je(t,e,r);class Je{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){const e=this.encode(t);return e instanceof Uint8Array?Ge(this.code,e):e.then((t=>Ge(this.code,t)))}throw Error("Unknown type, must be binary type")}}const Ye=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Qe=$e({name:"sha2-256",code:18,encode:Ye("SHA-256")}),Xe=$e({name:"sha2-512",code:19,encode:Ye("SHA-512")}),Ze=$t,tr={code:0,name:"identity",encode:Ze,digest:t=>Ge(0,Ze(t))},er="raw",rr=85,ir=t=>$t(t),nr=t=>$t(t),sr=new TextEncoder,or=new TextDecoder,ar="json",hr=512,ur=t=>sr.encode(JSON.stringify(t)),cr=t=>JSON.parse(or.decode(t));Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"),Symbol.for("@ipld/js-cid/CID");const lr={...i,...n,...s,...o,...a,...h,...u,...c,...l,...f};function fr(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const dr=fr("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),pr=fr("ascii","a",(t=>{let e="a";for(let r=0;r{const e=Gt((t=t.substring(1)).length);for(let r=0;rt+e.length),0));const r=Gt(e);let i=0;for(const e of t)r.set(e,i),i+=e.length;return Vt(r)}([e,t]),Ft);return[jt,zt,r].join(Bt)}function br(t=(0,Lt.randomBytes)(32)){return Ut.K(t)}r(5665);var _r=function(t,e,r){if(r||2===arguments.length)for(var i,n=0,s=e.length;nt+e.length),0));const r=Br(e);let i=0;for(const e of t)r.set(e,i),i+=e.length;return r}function zr(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const Fr=zr("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),Kr=zr("ascii","a",(t=>{let e="a";for(let r=0;r{const e=Br((t=t.substring(1)).length);for(let r=0;re in t?Yr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ei=(t,e)=>{for(var r in e||(e={}))Xr.call(e,r)&&ti(t,r,e[r]);if(Qr)for(var r of Qr(e))Zr.call(e,r)&&ti(t,r,e[r]);return t};const ri="ReactNative",ii={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},ni="js";function si(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function oi(){return!(0,Cr.getDocument)()&&!!(0,Cr.getNavigator)()&&navigator.product===ri}function ai(){return!si()&&!!(0,Cr.getNavigator)()&&!!(0,Cr.getDocument)()}function hi(){return oi()?ii.reactNative:si()?ii.node:ai()?ii.browser:ii.unknown}function ui(t,e,i){const n=function(){if(hi()===ii.reactNative&&typeof r.g<"u"&&typeof(null==r.g?void 0:r.g.Platform)<"u"){const{OS:t,Version:e}=r.g.Platform;return[t,e].join("-")}const t=e?Rr(e):"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product?new Ir:"undefined"!=typeof navigator?Rr(navigator.userAgent):"undefined"!=typeof process&&process.version?new Er(process.version.slice(1)):null;var e;if(null===t)return"unknown";const i=t.os?t.os.replace(" ","").toLowerCase():"unknown";return"browser"===t.type?[i,t.name,t.version].join("-"):[i,t.version].join("-")}(),s=function(){var t;const e=hi();return e===ii.browser?[e,(null==(t=(0,Cr.getLocation)())?void 0:t.host)||"unknown"].join(":"):e}();return[[t,e].join("-"),[ni,i].join("-"),n,s].join("/")}function ci(t,e){return t.filter((t=>e.includes(t))).length===t.length}function li(t){return Object.fromEntries(t.entries())}function fi(t){return new Map(Object.entries(t))}function di(t=Y.FIVE_MINUTES,e){const r=(0,Y.toMiliseconds)(t||Y.FIVE_MINUTES);let i,n,s;return{resolve:t=>{s&&i&&(clearTimeout(s),i(t))},reject:t=>{s&&n&&(clearTimeout(s),n(t))},done:()=>new Promise(((t,o)=>{s=setTimeout((()=>{o(new Error(e))}),r),i=t,n=o}))}}function pi(t,e,r){return new Promise((async(i,n)=>{const s=setTimeout((()=>n(new Error(r))),e);try{i(await t)}catch(t){n(t)}clearTimeout(s)}))}function gi(t,e){if("string"==typeof e&&e.startsWith(`${t}:`))return e;if("topic"===t.toLowerCase()){if("string"!=typeof e)throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}if("id"===t.toLowerCase()){if("number"!=typeof e)throw new Error('Value must be "number" for expirer target type: id');return`id:${e}`}throw new Error(`Unknown expirer target type: ${t}`)}function mi(t){const[e,r]=t.split(":"),i={id:void 0,topic:void 0};if("topic"===e&&"string"==typeof r)i.topic=r;else{if("id"!==e||!Number.isInteger(Number(r)))throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${r}`);i.id=Number(r)}return i}function yi(t,e){return(0,Y.fromMiliseconds)((e||Date.now())+(0,Y.toMiliseconds)(t))}function vi(t){return Date.now()>=(0,Y.toMiliseconds)(t)}function wi(t,e){return`${t}${e?`:${e}`:""}`}function bi(t=[],e=[]){return[...new Set([...t,...e])]}var _i,Ai=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof r.g<"u"?r.g:typeof self<"u"?self:{},Ei={exports:{}};_i=Ei,function(){var t="input is invalid type",e="object"==typeof window,r=e?window:{};r.JS_SHA3_NO_WINDOW&&(e=!1);var i=!e&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?r=Ai:i&&(r=self);var n=!r.JS_SHA3_NO_COMMON_JS&&_i.exports,s=!r.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",o="0123456789abcdef".split(""),a=[4,1024,262144,67108864],h=[0,8,16,24],u=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],c=[224,256,384,512],l=[128,256],f=["hex","buffer","arrayBuffer","array","digest"],d={128:168,256:136};(r.JS_SHA3_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),s&&(r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var p=function(t,e,r){return function(i){return new O(t,e,t).update(i)[r]()}},g=function(t,e,r){return function(i,n){return new O(t,e,n).update(i)[r]()}},m=function(t,e,r){return function(e,i,n,s){return _["cshake"+t].update(e,i,n,s)[r]()}},y=function(t,e,r){return function(e,i,n,s){return _["kmac"+t].update(e,i,n,s)[r]()}},v=function(t,e,r,i){for(var n=0;n>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var i=0;i<50;++i)this.s[i]=0}function P(t,e,r){O.call(this,t,e,r)}O.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var r,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(s&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||s&&ArrayBuffer.isView(e)))throw new Error(t);r=!0}for(var n,o,a=this.blocks,u=this.byteCount,c=e.length,l=this.blockCount,f=0,d=this.s;f>2]|=e[f]<>2]|=o<>2]|=(192|o>>6)<>2]|=(128|63&o)<=57344?(a[n>>2]|=(224|o>>12)<>2]|=(128|o>>6&63)<>2]|=(128|63&o)<>2]|=(240|o>>18)<>2]|=(128|o>>12&63)<>2]|=(128|o>>6&63)<>2]|=(128|63&o)<=u){for(this.start=n-u,this.block=a[l],n=0;n>=8);r>0;)n.unshift(r),r=255&(t>>=8),++i;return e?n.push(i):n.unshift(i),this.update(n),n.length},O.prototype.encodeString=function(e){var r,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(s&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||s&&ArrayBuffer.isView(e)))throw new Error(t);r=!0}var n=0,o=e.length;if(r)n=o;else for(var a=0;a=57344?n+=3:(h=65536+((1023&h)<<10|1023&e.charCodeAt(++a)),n+=4)}return n+=this.encode(8*n),this.update(e),n},O.prototype.bytepad=function(t,e){for(var r=this.encode(e),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>4&15]+o[15&t]+o[t>>12&15]+o[t>>8&15]+o[t>>20&15]+o[t>>16&15]+o[t>>28&15]+o[t>>24&15];a%e==0&&(R(r),s=0)}return n&&(t=r[s],h+=o[t>>4&15]+o[15&t],n>1&&(h+=o[t>>12&15]+o[t>>8&15]),n>2&&(h+=o[t>>20&15]+o[t>>16&15])),h},O.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,i=this.outputBlocks,n=this.extraBytes,s=0,o=0,a=this.outputBits>>3;t=n?new ArrayBuffer(i+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);o>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%r==0&&R(i)}return s&&(t=a<<2,e=i[o],h[t]=255&e,s>1&&(h[t+1]=e>>8&255),s>2&&(h[t+2]=e>>16&255)),h},P.prototype=new O,P.prototype.finalize=function(){return this.encode(this.outputBits,!0),O.prototype.finalize.call(this)};var R=function(t){var e,r,i,n,s,o,a,h,c,l,f,d,p,g,m,y,v,w,b,_,A,E,S,M,I,x,N,O,P,R,C,T,k,U,L,q,D,B,j,z,F,K,H,V,G,W,$,J,Y,Q,X,Z,tt,et,rt,it,nt,st,ot,at,ht,ut,ct;for(i=0;i<48;i+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],o=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],h=t[4]^t[14]^t[24]^t[34]^t[44],c=t[5]^t[15]^t[25]^t[35]^t[45],l=t[6]^t[16]^t[26]^t[36]^t[46],f=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),r=(p=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|o>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=n^(h<<1|c>>>31),r=s^(c<<1|h>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=o^(l<<1|f>>>31),r=a^(f<<1|l>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=h^(d<<1|p>>>31),r=c^(p<<1|d>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=l^(n<<1|s>>>31),r=f^(s<<1|n>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,g=t[0],m=t[1],W=t[11]<<4|t[10]>>>28,$=t[10]<<4|t[11]>>>28,O=t[20]<<3|t[21]>>>29,P=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,K=t[40]<<18|t[41]>>>14,H=t[41]<<18|t[40]>>>14,U=t[2]<<1|t[3]>>>31,L=t[3]<<1|t[2]>>>31,y=t[13]<<12|t[12]>>>20,v=t[12]<<12|t[13]>>>20,J=t[22]<<10|t[23]>>>22,Y=t[23]<<10|t[22]>>>22,R=t[33]<<13|t[32]>>>19,C=t[32]<<13|t[33]>>>19,ut=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,q=t[14]<<6|t[15]>>>26,D=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,b=t[24]<<11|t[25]>>>21,Q=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,T=t[45]<<29|t[44]>>>3,k=t[44]<<29|t[45]>>>3,M=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,nt=t[16]<<23|t[17]>>>9,B=t[26]<<25|t[27]>>>7,j=t[27]<<25|t[26]>>>7,_=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Z=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,V=t[8]<<27|t[9]>>>5,G=t[9]<<27|t[8]>>>5,x=t[18]<<20|t[19]>>>12,N=t[19]<<20|t[18]>>>12,st=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,z=t[38]<<8|t[39]>>>24,F=t[39]<<8|t[38]>>>24,E=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=g^~y&w,t[1]=m^~v&b,t[10]=M^~x&O,t[11]=I^~N&P,t[20]=U^~q&B,t[21]=L^~D&j,t[30]=V^~W&J,t[31]=G^~$&Y,t[40]=et^~it&st,t[41]=rt^~nt&ot,t[2]=y^~w&_,t[3]=v^~b&A,t[12]=x^~O&R,t[13]=N^~P&C,t[22]=q^~B&z,t[23]=D^~j&F,t[32]=W^~J&Q,t[33]=$^~Y&X,t[42]=it^~st&at,t[43]=nt^~ot&ht,t[4]=w^~_&E,t[5]=b^~A&S,t[14]=O^~R&T,t[15]=P^~C&k,t[24]=B^~z&K,t[25]=j^~F&H,t[34]=J^~Q&Z,t[35]=Y^~X&tt,t[44]=st^~at&ut,t[45]=ot^~ht&ct,t[6]=_^~E&g,t[7]=A^~S&m,t[16]=R^~T&M,t[17]=C^~k&I,t[26]=z^~K&U,t[27]=F^~H&L,t[36]=Q^~Z&V,t[37]=X^~tt&G,t[46]=at^~ut&et,t[47]=ht^~ct&rt,t[8]=E^~g&y,t[9]=S^~m&v,t[18]=T^~M&x,t[19]=k^~I&N,t[28]=K^~U&q,t[29]=H^~L&D,t[38]=Z^~V&W,t[39]=tt^~G&$,t[48]=ut^~et&it,t[49]=ct^~rt&nt,t[0]^=u[i],t[1]^=u[i+1]};if(n)_i.exports=_;else for(E=0;E{try{if("test"!=="test".normalize(e))throw new Error("bad normalize")}catch{t.push(e)}})),t.length)throw new Error("missing "+t.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(t){return t.message}return null}();var Ri,Ci;!function(t){t.DEBUG="DEBUG",t.INFO="INFO",t.WARNING="WARNING",t.ERROR="ERROR",t.OFF="OFF"}(Ri||(Ri={})),function(t){t.UNKNOWN_ERROR="UNKNOWN_ERROR",t.NOT_IMPLEMENTED="NOT_IMPLEMENTED",t.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",t.NETWORK_ERROR="NETWORK_ERROR",t.SERVER_ERROR="SERVER_ERROR",t.TIMEOUT="TIMEOUT",t.BUFFER_OVERRUN="BUFFER_OVERRUN",t.NUMERIC_FAULT="NUMERIC_FAULT",t.MISSING_NEW="MISSING_NEW",t.INVALID_ARGUMENT="INVALID_ARGUMENT",t.MISSING_ARGUMENT="MISSING_ARGUMENT",t.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",t.CALL_EXCEPTION="CALL_EXCEPTION",t.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",t.NONCE_EXPIRED="NONCE_EXPIRED",t.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",t.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",t.TRANSACTION_REPLACED="TRANSACTION_REPLACED",t.ACTION_REJECTED="ACTION_REJECTED"}(Ci||(Ci={}));const Ti="0123456789abcdef";class ki{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const r=t.toLowerCase();null==xi[r]&&this.throwArgumentError("invalid log level name","logLevel",t),!(Ni>xi[r])&&console.log.apply(console,e)}debug(...t){this._log(ki.levels.DEBUG,t)}info(...t){this._log(ki.levels.INFO,t)}warn(...t){this._log(ki.levels.WARNING,t)}makeError(t,e,r){if(Ii)return this.makeError("censored error",e,{});e||(e=ki.errors.UNKNOWN_ERROR),r||(r={});const i=[];Object.keys(r).forEach((t=>{const e=r[t];try{if(e instanceof Uint8Array){let r="";for(let t=0;t>4],r+=Ti[15&e[t]];i.push(t+"=Uint8Array(0x"+r+")")}else i.push(t+"="+JSON.stringify(e))}catch{i.push(t+"="+JSON.stringify(r[t].toString()))}})),i.push(`code=${e}`),i.push(`version=${this.version}`);const n=t;let s="";switch(e){case Ci.NUMERIC_FAULT:{s="NUMERIC_FAULT";const e=t;switch(e){case"overflow":case"underflow":case"division-by-zero":s+="-"+e;break;case"negative-power":case"negative-width":s+="-unsupported";break;case"unbound-bitwise-result":s+="-unbound-result"}break}case Ci.CALL_EXCEPTION:case Ci.INSUFFICIENT_FUNDS:case Ci.MISSING_NEW:case Ci.NONCE_EXPIRED:case Ci.REPLACEMENT_UNDERPRICED:case Ci.TRANSACTION_REPLACED:case Ci.UNPREDICTABLE_GAS_LIMIT:s=e}s&&(t+=" [ See: https://links.ethers.org/v5-errors-"+s+" ]"),i.length&&(t+=" ("+i.join(", ")+")");const o=new Error(t);return o.reason=n,o.code=e,Object.keys(r).forEach((function(t){o[t]=r[t]})),o}throwError(t,e,r){throw this.makeError(t,e,r)}throwArgumentError(t,e,r){return this.throwError(t,ki.errors.INVALID_ARGUMENT,{argument:e,value:r})}assert(t,e,r,i){t||this.throwError(e,r,i)}assertArgument(t,e,r,i){t||this.throwArgumentError(e,r,i)}checkNormalize(t){Pi&&this.throwError("platform missing String.prototype.normalize",ki.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:Pi})}checkSafeUint53(t,e){"number"==typeof t&&(null==e&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,ki.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,ki.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,r){r=r?": "+r:"",te&&this.throwError("too many arguments"+r,ki.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){(t===Object||null==t)&&this.throwError("missing new",ki.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",ki.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):(t===Object||null==t)&&this.throwError("missing new",ki.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return Oi||(Oi=new ki("logger/5.7.0")),Oi}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",ki.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),Mi){if(!t)return;this.globalLogger().throwError("error censorship permanent",ki.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}Ii=!!t,Mi=!!e}static setLogLevel(t){const e=xi[t.toLowerCase()];null!=e?Ni=e:ki.globalLogger().warn("invalid log level - "+t)}static from(t){return new ki(t)}}ki.errors=Ci,ki.levels=Ri;const Ui=new ki("bytes/5.7.0");function Li(t){return!!t.toHexString}function qi(t){return t.slice||(t.slice=function(){const e=Array.prototype.slice.call(arguments);return qi(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}function Di(t){return"number"==typeof t&&t==t&&t%1==0}function Bi(t){if(null==t)return!1;if(t.constructor===Uint8Array)return!0;if("string"==typeof t||!Di(t.length)||t.length<0)return!1;for(let e=0;e=256)return!1}return!0}function ji(t,e){if(e||(e={}),"number"==typeof t){Ui.checkSafeUint53(t,"invalid arrayify value");const e=[];for(;t;)e.unshift(255&t),t=parseInt(String(t/256));return 0===e.length&&e.push(0),qi(new Uint8Array(e))}if(e.allowMissingPrefix&&"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),Li(t)&&(t=t.toHexString()),zi(t)){let r=t.substring(2);r.length%2&&("left"===e.hexPad?r="0"+r:"right"===e.hexPad?r+="0":Ui.throwArgumentError("hex data is odd-length","value",t));const i=[];for(let t=0;t>4]+Fi[15&i]}return e}return Ui.throwArgumentError("invalid hexlify value","value",t)}function Hi(t,e,r){return"string"!=typeof t?t=Ki(t):(!zi(t)||t.length%2)&&Ui.throwArgumentError("invalid hexData","value",t),e=2+2*e,null!=r?"0x"+t.substring(e,2+2*r):"0x"+t.substring(e)}function Vi(t,e){for("string"!=typeof t?t=Ki(t):zi(t)||Ui.throwArgumentError("invalid hex string","value",t),t.length>2*e+2&&Ui.throwArgumentError("value out of range","value",arguments[1]);t.length<2*e+2;)t="0x0"+t.substring(2);return t}function Gi(t){const e={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(function(t){return zi(t)&&!(t.length%2)||Bi(t)}(t)){let r=ji(t);64===r.length?(e.v=27+(r[32]>>7),r[32]&=127,e.r=Ki(r.slice(0,32)),e.s=Ki(r.slice(32,64))):65===r.length?(e.r=Ki(r.slice(0,32)),e.s=Ki(r.slice(32,64)),e.v=r[64]):Ui.throwArgumentError("invalid signature string","signature",t),e.v<27&&(0===e.v||1===e.v?e.v+=27:Ui.throwArgumentError("signature invalid v byte","signature",t)),e.recoveryParam=1-e.v%2,e.recoveryParam&&(r[32]|=128),e._vs=Ki(r.slice(32,64))}else{if(e.r=t.r,e.s=t.s,e.v=t.v,e.recoveryParam=t.recoveryParam,e._vs=t._vs,null!=e._vs){const r=function(t,e){(t=ji(t)).length>e&&Ui.throwArgumentError("value out of range","value",arguments[0]);const r=new Uint8Array(e);return r.set(t,e-t.length),qi(r)}(ji(e._vs),32);e._vs=Ki(r);const i=r[0]>=128?1:0;null==e.recoveryParam?e.recoveryParam=i:e.recoveryParam!==i&&Ui.throwArgumentError("signature recoveryParam mismatch _vs","signature",t),r[0]&=127;const n=Ki(r);null==e.s?e.s=n:e.s!==n&&Ui.throwArgumentError("signature v mismatch _vs","signature",t)}if(null==e.recoveryParam)null==e.v?Ui.throwArgumentError("signature missing v and recoveryParam","signature",t):0===e.v||1===e.v?e.recoveryParam=e.v:e.recoveryParam=1-e.v%2;else if(null==e.v)e.v=27+e.recoveryParam;else{const r=0===e.v||1===e.v?e.v:1-e.v%2;e.recoveryParam!==r&&Ui.throwArgumentError("signature recoveryParam mismatch v","signature",t)}null!=e.r&&zi(e.r)?e.r=Vi(e.r,32):Ui.throwArgumentError("signature missing or invalid r","signature",t),null!=e.s&&zi(e.s)?e.s=Vi(e.s,32):Ui.throwArgumentError("signature missing or invalid s","signature",t);const r=ji(e.s);r[0]>=128&&Ui.throwArgumentError("signature s out of range","signature",t),e.recoveryParam&&(r[0]|=128);const i=Ki(r);e._vs&&(zi(e._vs)||Ui.throwArgumentError("signature invalid _vs","signature",t),e._vs=Vi(e._vs,32)),null==e._vs?e._vs=i:e._vs!==i&&Ui.throwArgumentError("signature _vs mismatch v and s","signature",t)}return e.yParityAndS=e._vs,e.compact=e.r+e.yParityAndS.substring(2),e}function Wi(t){return"0x"+Si.keccak_256(ji(t))}var $i={exports:{}},Ji=function(t){var e=t.default;if("function"==typeof e){var r=function(){return e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})})),r}(Object.freeze({__proto__:null,default:{}}));!function(t,e){function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function n(t,e,r){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&(("le"===e||"be"===e)&&(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof $i?$i.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=typeof window<"u"&&typeof window.Buffer<"u"?window.Buffer:Ji.Buffer}catch{}function o(t,e){var i=t.charCodeAt(e);return i>=48&&i<=57?i-48:i>=65&&i<=70?i-55:i>=97&&i<=102?i-87:void r(!1,"Invalid character in "+t)}function a(t,e,r){var i=o(t,r);return r-1>=e&&(i|=o(t,r-1)<<4),i}function h(t,e,i,n){for(var s=0,o=0,a=Math.min(t.length,i),h=e;h=49?u-49+10:u>=17?u-17+10:u,r(u>=0&&o0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,i){if("number"==typeof t)return this._initNumber(t,e,i);if("object"==typeof t)return this._initArray(t,e,i);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===i)for(n=0,s=0;n>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},n.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i=e;i-=2)n=a(t,e,i)<=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;else for(i=(t.length-e)%2==0?e+1:e;i=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;this._strip()},n.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,u=0,c=r;c1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},typeof Symbol<"u"&&"function"==typeof Symbol.for)try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=c}catch{n.prototype.inspect=c}else n.prototype.inspect=c;function c(){return(this.red?""}var l=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],f=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],d=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function p(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,h=o/67108864|0;r.words[0]=a;for(var u=1;u>>26,l=67108863&h,f=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=f;d++){var p=u-d|0;c+=(o=(n=0|t.words[p])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o}r.words[u]=0|l,h=0|c}return 0!==h?r.words[u]=0|h:r.length--,r._strip()}n.prototype.toString=function(t,e){var i;if(e=0|e||1,16===(t=t||10)||"hex"===t){i="";for(var n=0,s=0,o=0;o>>24-n&16777215,(n+=2)>=26&&(n-=26,o--),i=0!==s||o!==this.length-1?l[6-h.length]+h+i:h+i}for(0!==s&&(i=s.toString(16)+i);i.length%e!=0;)i="0"+i;return 0!==this.negative&&(i="-"+i),i}if(t===(0|t)&&t>=2&&t<=36){var u=f[t],c=d[t];i="";var p=this.clone();for(p.negative=0;!p.isZero();){var g=p.modrn(c).toString(t);i=(p=p.idivn(c)).isZero()?g+i:l[u-g.length]+g+i}for(this.isZero()&&(i="0"+i);i.length%e!=0;)i="0"+i;return 0!==this.negative&&(i="-"+i),i}r(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16,2)},s&&(n.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,i){this._strip();var n=this.byteLength(),s=i||Math.max(1,n);r(n<=s,"byte array longer than desired length"),r(s>0,"Requested array length <= 0");var o=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,s);return this["_toArrayLike"+("le"===e?"LE":"BE")](o,n),o},n.prototype._toArrayLikeLE=function(t,e){for(var r=0,i=0,n=0,s=0;n>8&255),r>16&255),6===s?(r>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r=0&&(t[r--]=o>>8&255),r>=0&&(t[r--]=o>>16&255),6===s?(r>=0&&(t[r--]=o>>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r>=0)for(t[r--]=i;r>=0;)t[r--]=0},Math.clz32?n.prototype._countBits=function(t){return 32-Math.clz32(t)}:n.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},n.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;rt.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;it.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),i=t%26;this._expand(e),i>0&&e--;for(var n=0;n0&&(this.words[n]=~this.words[n]&67108863>>26-i),this._strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){r("number"==typeof t&&t>=0);var i=t/26|0,n=t%26;return this._expand(i+1),this.words[i]=e?this.words[i]|1<t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s>>26;for(;0!==n&&s>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;st.length?this.clone().iadd(t):t.clone().iadd(this)},n.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o>26,this.words[o]=67108863&e;for(;0!==s&&o>26,this.words[o]=67108863&e;if(0===s&&o>>13,d=0|o[1],p=8191&d,g=d>>>13,m=0|o[2],y=8191&m,v=m>>>13,w=0|o[3],b=8191&w,_=w>>>13,A=0|o[4],E=8191&A,S=A>>>13,M=0|o[5],I=8191&M,x=M>>>13,N=0|o[6],O=8191&N,P=N>>>13,R=0|o[7],C=8191&R,T=R>>>13,k=0|o[8],U=8191&k,L=k>>>13,q=0|o[9],D=8191&q,B=q>>>13,j=0|a[0],z=8191&j,F=j>>>13,K=0|a[1],H=8191&K,V=K>>>13,G=0|a[2],W=8191&G,$=G>>>13,J=0|a[3],Y=8191&J,Q=J>>>13,X=0|a[4],Z=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,ct=0|a[8],lt=8191&ct,ft=ct>>>13,dt=0|a[9],pt=8191&dt,gt=dt>>>13;r.negative=t.negative^e.negative,r.length=19;var mt=(u+(i=Math.imul(l,z))|0)+((8191&(n=(n=Math.imul(l,F))+Math.imul(f,z)|0))<<13)|0;u=((s=Math.imul(f,F))+(n>>>13)|0)+(mt>>>26)|0,mt&=67108863,i=Math.imul(p,z),n=(n=Math.imul(p,F))+Math.imul(g,z)|0,s=Math.imul(g,F);var yt=(u+(i=i+Math.imul(l,H)|0)|0)+((8191&(n=(n=n+Math.imul(l,V)|0)+Math.imul(f,H)|0))<<13)|0;u=((s=s+Math.imul(f,V)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(y,z),n=(n=Math.imul(y,F))+Math.imul(v,z)|0,s=Math.imul(v,F),i=i+Math.imul(p,H)|0,n=(n=n+Math.imul(p,V)|0)+Math.imul(g,H)|0,s=s+Math.imul(g,V)|0;var vt=(u+(i=i+Math.imul(l,W)|0)|0)+((8191&(n=(n=n+Math.imul(l,$)|0)+Math.imul(f,W)|0))<<13)|0;u=((s=s+Math.imul(f,$)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(b,z),n=(n=Math.imul(b,F))+Math.imul(_,z)|0,s=Math.imul(_,F),i=i+Math.imul(y,H)|0,n=(n=n+Math.imul(y,V)|0)+Math.imul(v,H)|0,s=s+Math.imul(v,V)|0,i=i+Math.imul(p,W)|0,n=(n=n+Math.imul(p,$)|0)+Math.imul(g,W)|0,s=s+Math.imul(g,$)|0;var wt=(u+(i=i+Math.imul(l,Y)|0)|0)+((8191&(n=(n=n+Math.imul(l,Q)|0)+Math.imul(f,Y)|0))<<13)|0;u=((s=s+Math.imul(f,Q)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(E,z),n=(n=Math.imul(E,F))+Math.imul(S,z)|0,s=Math.imul(S,F),i=i+Math.imul(b,H)|0,n=(n=n+Math.imul(b,V)|0)+Math.imul(_,H)|0,s=s+Math.imul(_,V)|0,i=i+Math.imul(y,W)|0,n=(n=n+Math.imul(y,$)|0)+Math.imul(v,W)|0,s=s+Math.imul(v,$)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,Q)|0;var bt=(u+(i=i+Math.imul(l,Z)|0)|0)+((8191&(n=(n=n+Math.imul(l,tt)|0)+Math.imul(f,Z)|0))<<13)|0;u=((s=s+Math.imul(f,tt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(I,z),n=(n=Math.imul(I,F))+Math.imul(x,z)|0,s=Math.imul(x,F),i=i+Math.imul(E,H)|0,n=(n=n+Math.imul(E,V)|0)+Math.imul(S,H)|0,s=s+Math.imul(S,V)|0,i=i+Math.imul(b,W)|0,n=(n=n+Math.imul(b,$)|0)+Math.imul(_,W)|0,s=s+Math.imul(_,$)|0,i=i+Math.imul(y,Y)|0,n=(n=n+Math.imul(y,Q)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,Q)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,tt)|0;var _t=(u+(i=i+Math.imul(l,rt)|0)|0)+((8191&(n=(n=n+Math.imul(l,it)|0)+Math.imul(f,rt)|0))<<13)|0;u=((s=s+Math.imul(f,it)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(O,z),n=(n=Math.imul(O,F))+Math.imul(P,z)|0,s=Math.imul(P,F),i=i+Math.imul(I,H)|0,n=(n=n+Math.imul(I,V)|0)+Math.imul(x,H)|0,s=s+Math.imul(x,V)|0,i=i+Math.imul(E,W)|0,n=(n=n+Math.imul(E,$)|0)+Math.imul(S,W)|0,s=s+Math.imul(S,$)|0,i=i+Math.imul(b,Y)|0,n=(n=n+Math.imul(b,Q)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,Q)|0,i=i+Math.imul(y,Z)|0,n=(n=n+Math.imul(y,tt)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(g,rt)|0,s=s+Math.imul(g,it)|0;var At=(u+(i=i+Math.imul(l,st)|0)|0)+((8191&(n=(n=n+Math.imul(l,ot)|0)+Math.imul(f,st)|0))<<13)|0;u=((s=s+Math.imul(f,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(C,z),n=(n=Math.imul(C,F))+Math.imul(T,z)|0,s=Math.imul(T,F),i=i+Math.imul(O,H)|0,n=(n=n+Math.imul(O,V)|0)+Math.imul(P,H)|0,s=s+Math.imul(P,V)|0,i=i+Math.imul(I,W)|0,n=(n=n+Math.imul(I,$)|0)+Math.imul(x,W)|0,s=s+Math.imul(x,$)|0,i=i+Math.imul(E,Y)|0,n=(n=n+Math.imul(E,Q)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,Q)|0,i=i+Math.imul(b,Z)|0,n=(n=n+Math.imul(b,tt)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,tt)|0,i=i+Math.imul(y,rt)|0,n=(n=n+Math.imul(y,it)|0)+Math.imul(v,rt)|0,s=s+Math.imul(v,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var Et=(u+(i=i+Math.imul(l,ht)|0)|0)+((8191&(n=(n=n+Math.imul(l,ut)|0)+Math.imul(f,ht)|0))<<13)|0;u=((s=s+Math.imul(f,ut)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(U,z),n=(n=Math.imul(U,F))+Math.imul(L,z)|0,s=Math.imul(L,F),i=i+Math.imul(C,H)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(T,H)|0,s=s+Math.imul(T,V)|0,i=i+Math.imul(O,W)|0,n=(n=n+Math.imul(O,$)|0)+Math.imul(P,W)|0,s=s+Math.imul(P,$)|0,i=i+Math.imul(I,Y)|0,n=(n=n+Math.imul(I,Q)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,Q)|0,i=i+Math.imul(E,Z)|0,n=(n=n+Math.imul(E,tt)|0)+Math.imul(S,Z)|0,s=s+Math.imul(S,tt)|0,i=i+Math.imul(b,rt)|0,n=(n=n+Math.imul(b,it)|0)+Math.imul(_,rt)|0,s=s+Math.imul(_,it)|0,i=i+Math.imul(y,st)|0,n=(n=n+Math.imul(y,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var St=(u+(i=i+Math.imul(l,lt)|0)|0)+((8191&(n=(n=n+Math.imul(l,ft)|0)+Math.imul(f,lt)|0))<<13)|0;u=((s=s+Math.imul(f,ft)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(D,z),n=(n=Math.imul(D,F))+Math.imul(B,z)|0,s=Math.imul(B,F),i=i+Math.imul(U,H)|0,n=(n=n+Math.imul(U,V)|0)+Math.imul(L,H)|0,s=s+Math.imul(L,V)|0,i=i+Math.imul(C,W)|0,n=(n=n+Math.imul(C,$)|0)+Math.imul(T,W)|0,s=s+Math.imul(T,$)|0,i=i+Math.imul(O,Y)|0,n=(n=n+Math.imul(O,Q)|0)+Math.imul(P,Y)|0,s=s+Math.imul(P,Q)|0,i=i+Math.imul(I,Z)|0,n=(n=n+Math.imul(I,tt)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,tt)|0,i=i+Math.imul(E,rt)|0,n=(n=n+Math.imul(E,it)|0)+Math.imul(S,rt)|0,s=s+Math.imul(S,it)|0,i=i+Math.imul(b,st)|0,n=(n=n+Math.imul(b,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,i=i+Math.imul(y,ht)|0,n=(n=n+Math.imul(y,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,i=i+Math.imul(p,lt)|0,n=(n=n+Math.imul(p,ft)|0)+Math.imul(g,lt)|0,s=s+Math.imul(g,ft)|0;var Mt=(u+(i=i+Math.imul(l,pt)|0)|0)+((8191&(n=(n=n+Math.imul(l,gt)|0)+Math.imul(f,pt)|0))<<13)|0;u=((s=s+Math.imul(f,gt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(D,H),n=(n=Math.imul(D,V))+Math.imul(B,H)|0,s=Math.imul(B,V),i=i+Math.imul(U,W)|0,n=(n=n+Math.imul(U,$)|0)+Math.imul(L,W)|0,s=s+Math.imul(L,$)|0,i=i+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,Q)|0)+Math.imul(T,Y)|0,s=s+Math.imul(T,Q)|0,i=i+Math.imul(O,Z)|0,n=(n=n+Math.imul(O,tt)|0)+Math.imul(P,Z)|0,s=s+Math.imul(P,tt)|0,i=i+Math.imul(I,rt)|0,n=(n=n+Math.imul(I,it)|0)+Math.imul(x,rt)|0,s=s+Math.imul(x,it)|0,i=i+Math.imul(E,st)|0,n=(n=n+Math.imul(E,ot)|0)+Math.imul(S,st)|0,s=s+Math.imul(S,ot)|0,i=i+Math.imul(b,ht)|0,n=(n=n+Math.imul(b,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,i=i+Math.imul(y,lt)|0,n=(n=n+Math.imul(y,ft)|0)+Math.imul(v,lt)|0,s=s+Math.imul(v,ft)|0;var It=(u+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(D,W),n=(n=Math.imul(D,$))+Math.imul(B,W)|0,s=Math.imul(B,$),i=i+Math.imul(U,Y)|0,n=(n=n+Math.imul(U,Q)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,Q)|0,i=i+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(T,Z)|0,s=s+Math.imul(T,tt)|0,i=i+Math.imul(O,rt)|0,n=(n=n+Math.imul(O,it)|0)+Math.imul(P,rt)|0,s=s+Math.imul(P,it)|0,i=i+Math.imul(I,st)|0,n=(n=n+Math.imul(I,ot)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,ot)|0,i=i+Math.imul(E,ht)|0,n=(n=n+Math.imul(E,ut)|0)+Math.imul(S,ht)|0,s=s+Math.imul(S,ut)|0,i=i+Math.imul(b,lt)|0,n=(n=n+Math.imul(b,ft)|0)+Math.imul(_,lt)|0,s=s+Math.imul(_,ft)|0;var xt=(u+(i=i+Math.imul(y,pt)|0)|0)+((8191&(n=(n=n+Math.imul(y,gt)|0)+Math.imul(v,pt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(D,Y),n=(n=Math.imul(D,Q))+Math.imul(B,Y)|0,s=Math.imul(B,Q),i=i+Math.imul(U,Z)|0,n=(n=n+Math.imul(U,tt)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,tt)|0,i=i+Math.imul(C,rt)|0,n=(n=n+Math.imul(C,it)|0)+Math.imul(T,rt)|0,s=s+Math.imul(T,it)|0,i=i+Math.imul(O,st)|0,n=(n=n+Math.imul(O,ot)|0)+Math.imul(P,st)|0,s=s+Math.imul(P,ot)|0,i=i+Math.imul(I,ht)|0,n=(n=n+Math.imul(I,ut)|0)+Math.imul(x,ht)|0,s=s+Math.imul(x,ut)|0,i=i+Math.imul(E,lt)|0,n=(n=n+Math.imul(E,ft)|0)+Math.imul(S,lt)|0,s=s+Math.imul(S,ft)|0;var Nt=(u+(i=i+Math.imul(b,pt)|0)|0)+((8191&(n=(n=n+Math.imul(b,gt)|0)+Math.imul(_,pt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,i=Math.imul(D,Z),n=(n=Math.imul(D,tt))+Math.imul(B,Z)|0,s=Math.imul(B,tt),i=i+Math.imul(U,rt)|0,n=(n=n+Math.imul(U,it)|0)+Math.imul(L,rt)|0,s=s+Math.imul(L,it)|0,i=i+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(T,st)|0,s=s+Math.imul(T,ot)|0,i=i+Math.imul(O,ht)|0,n=(n=n+Math.imul(O,ut)|0)+Math.imul(P,ht)|0,s=s+Math.imul(P,ut)|0,i=i+Math.imul(I,lt)|0,n=(n=n+Math.imul(I,ft)|0)+Math.imul(x,lt)|0,s=s+Math.imul(x,ft)|0;var Ot=(u+(i=i+Math.imul(E,pt)|0)|0)+((8191&(n=(n=n+Math.imul(E,gt)|0)+Math.imul(S,pt)|0))<<13)|0;u=((s=s+Math.imul(S,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,i=Math.imul(D,rt),n=(n=Math.imul(D,it))+Math.imul(B,rt)|0,s=Math.imul(B,it),i=i+Math.imul(U,st)|0,n=(n=n+Math.imul(U,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,i=i+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(T,ht)|0,s=s+Math.imul(T,ut)|0,i=i+Math.imul(O,lt)|0,n=(n=n+Math.imul(O,ft)|0)+Math.imul(P,lt)|0,s=s+Math.imul(P,ft)|0;var Pt=(u+(i=i+Math.imul(I,pt)|0)|0)+((8191&(n=(n=n+Math.imul(I,gt)|0)+Math.imul(x,pt)|0))<<13)|0;u=((s=s+Math.imul(x,gt)|0)+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(D,st),n=(n=Math.imul(D,ot))+Math.imul(B,st)|0,s=Math.imul(B,ot),i=i+Math.imul(U,ht)|0,n=(n=n+Math.imul(U,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,i=i+Math.imul(C,lt)|0,n=(n=n+Math.imul(C,ft)|0)+Math.imul(T,lt)|0,s=s+Math.imul(T,ft)|0;var Rt=(u+(i=i+Math.imul(O,pt)|0)|0)+((8191&(n=(n=n+Math.imul(O,gt)|0)+Math.imul(P,pt)|0))<<13)|0;u=((s=s+Math.imul(P,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(D,ht),n=(n=Math.imul(D,ut))+Math.imul(B,ht)|0,s=Math.imul(B,ut),i=i+Math.imul(U,lt)|0,n=(n=n+Math.imul(U,ft)|0)+Math.imul(L,lt)|0,s=s+Math.imul(L,ft)|0;var Ct=(u+(i=i+Math.imul(C,pt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(T,pt)|0))<<13)|0;u=((s=s+Math.imul(T,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,i=Math.imul(D,lt),n=(n=Math.imul(D,ft))+Math.imul(B,lt)|0,s=Math.imul(B,ft);var Tt=(u+(i=i+Math.imul(U,pt)|0)|0)+((8191&(n=(n=n+Math.imul(U,gt)|0)+Math.imul(L,pt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863;var kt=(u+(i=Math.imul(D,pt))|0)+((8191&(n=(n=Math.imul(D,gt))+Math.imul(B,pt)|0))<<13)|0;return u=((s=Math.imul(B,gt))+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h[0]=mt,h[1]=yt,h[2]=vt,h[3]=wt,h[4]=bt,h[5]=_t,h[6]=At,h[7]=Et,h[8]=St,h[9]=Mt,h[10]=It,h[11]=xt,h[12]=Nt,h[13]=Ot,h[14]=Pt,h[15]=Rt,h[16]=Ct,h[17]=Tt,h[18]=kt,0!==u&&(h[19]=u,r.length++),r};function m(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,s=0;s>>26)|0)>>>26,o&=67108863}r.words[s]=a,i=o,o=n}return 0!==i?r.words[s]=i:r.length--,r._strip()}function y(t,e,r){return m(t,e,r)}Math.imul||(g=p),n.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?p(this,t,e):r<1024?m(this,t,e):y(this,t,e)},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),y(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){var e=t<0;e&&(t=-t),r("number"==typeof t),r(t<67108864);for(var i=0,n=0;n>=26,i+=s/67108864|0,i+=o>>>26,this.words[n]=67108863&o}return 0!==i&&(this.words[n]=i,this.length++),e?this.ineg():this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r>>n&1}return e}(t);if(0===e.length)return new n(1);for(var r=this,i=0;i=0);var e,i=t%26,n=(t-i)/26,s=67108863>>>26-i<<26-i;if(0!==i){var o=0;for(e=0;e>>26-i}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<o)for(this.length-=o,u=0;u=0&&(0!==c||u>=n);u--){var l=0|this.words[u];this.words[u]=c<<26-s|l>>>s,c=l&a}return h&&0!==c&&(h.words[h.length++]=c),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(t,e,i){return r(0===this.negative),this.iushrn(t,e,i)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){r("number"==typeof t&&t>=0);var e=t%26,i=(t-e)/26,n=1<=0);var e=t%26,i=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=i)return this;if(0!==e&&i++,this.length=Math.min(i,this.length),0!==e){var n=67108863^67108863>>>e<=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},n.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e>26)-(h/67108864|0),this.words[n+i]=67108863&o}for(;n>26,this.words[n+i]=67108863&o;if(0===a)return this._strip();for(r(-1===a),a=0,n=0;n>26,this.words[n]=67108863&o;return this.negative=1,this._strip()},n.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),s=t,o=0|s.words[s.length-1];0!=(r=26-this._countBits(o))&&(s=s.ushln(r),i.iushln(r),o=0|s.words[s.length-1]);var a,h=i.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u=0;l--){var f=67108864*(0|i.words[s.length+l])+(0|i.words[s.length+l-1]);for(f=Math.min(f/o|0,67108863),i._ishlnsubmul(s,f,l);0!==i.negative;)f--,i.negative=0,i._ishlnsubmul(s,1,l),i.isZero()||(i.negative^=1);a&&(a.words[l]=f)}return a&&a._strip(),i._strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:a||null,mod:i}},n.prototype.divmod=function(t,e,i){return r(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),i&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):this.negative&t.negative?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),i&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modrn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),s=r.cmp(i);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modrn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var i=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(i*n+(0|this.words[s]))%t;return e?-n:n},n.prototype.modn=function(t){return this.modrn(t)},n.prototype.idivn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var s=(0|this.words[n])+67108864*i;this.words[n]=s/t|0,i=s%t}return this._strip(),e?this.ineg():this},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,i=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&i.isEven();)e.iushrn(1),i.iushrn(1),++u;for(var c=i.clone(),l=e.clone();!e.isZero();){for(var f=0,d=1;!(e.words[0]&d)&&f<26;++f,d<<=1);if(f>0)for(e.iushrn(f);f-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(c),o.isub(l)),s.iushrn(1),o.iushrn(1);for(var p=0,g=1;!(i.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(i.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(c),h.isub(l)),a.iushrn(1),h.iushrn(1);e.cmp(i)>=0?(e.isub(i),s.isub(a),o.isub(h)):(i.isub(e),a.isub(s),h.isub(o))}return{a,b:h,gcd:i.iushln(u)}},n.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e,i=this,s=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var o=new n(1),a=new n(0),h=s.clone();i.cmpn(1)>0&&s.cmpn(1)>0;){for(var u=0,c=1;!(i.words[0]&c)&&u<26;++u,c<<=1);if(u>0)for(i.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var l=0,f=1;!(s.words[0]&f)&&l<26;++l,f<<=1);if(l>0)for(s.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);i.cmp(s)>=0?(i.isub(s),o.isub(a)):(s.isub(i),a.isub(o))}return(e=0===i.cmpn(1)?o:a).cmpn(0)<0&&e.iadd(t),e},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var s=e;e=r,r=s}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return!(1&this.words[0])},n.prototype.isOdd=function(){return!(1&~this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){r("number"==typeof t);var e=t%26,i=(t-e)/26,n=1<>>26,a&=67108863,this.words[o]=a}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,i=t<0;if(0!==this.negative&&!i)return-1;if(0===this.negative&&i)return 1;if(this._strip(),this.length>1)e=1;else{i&&(t=-t),r(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:nt.length)return 1;if(this.length=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){in&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new S(t)},n.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var v={k256:null,p224:null,p192:null,p25519:null};function w(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function b(){w.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function _(){w.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){w.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function E(){w.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function S(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function M(t){S.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}w.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},w.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},w.prototype.split=function(t,e){t.iushrn(this.n,0,e)},w.prototype.imulK=function(t){return t.imul(this.k)},i(b,w),b.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n>>22,s=o}s>>>=22,t.words[n-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},b.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(v[t])return v[t];var e;if("k256"===t)e=new b;else if("p224"===t)e=new _;else if("p192"===t)e=new A;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new E}return v[t]=e,e},S.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},S.prototype._verify2=function(t,e){r(!(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},S.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(u(t,t.umod(this.m)._forceRed(this)),t)},S.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},S.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},S.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},S.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},S.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},S.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},S.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},S.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},S.prototype.isqr=function(t){return this.imul(t,t.clone())},S.prototype.sqr=function(t){return this.mul(t,t)},S.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var i=this.m.add(new n(1)).iushrn(2);return this.pow(t,i)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);r(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new n(2*c*c).toRed(this);0!==this.pow(c,u).cmp(h);)c.redIAdd(h);for(var l=this.pow(c,s),f=this.pow(t,s.addn(1).iushrn(1)),d=this.pow(t,s),p=o;0!==d.cmp(a);){for(var g=d,m=0;0!==g.cmp(a);m++)g=g.redSqr();r(m=0;i--){for(var u=e.words[i],c=h-1;c>=0;c--){var l=u>>c&1;s!==r[0]&&(s=this.sqr(s)),0!==l||0!==o?(o<<=1,o|=l,(4==++a||0===i&&0===c)&&(s=this.mul(s,r[o]),a=0,o=0)):a=0}h=26}return s},S.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},S.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new M(t)},i(M,S),M.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},M.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},M.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},M.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var r=t.mul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(i).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},M.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,Ai);var Yi=$i.exports;const Qi="bignumber/5.7.0";var Xi=Yi.BN;const Zi=new ki(Qi),tn={},en=9007199254740991;let rn=!1;class nn{constructor(t,e){t!==tn&&Zi.throwError("cannot call constructor directly; use BigNumber.from",ki.errors.UNSUPPORTED_OPERATION,{operation:"new (BigNumber)"}),this._hex=e,this._isBigNumber=!0,Object.freeze(this)}fromTwos(t){return on(an(this).fromTwos(t))}toTwos(t){return on(an(this).toTwos(t))}abs(){return"-"===this._hex[0]?nn.from(this._hex.substring(1)):this}add(t){return on(an(this).add(an(t)))}sub(t){return on(an(this).sub(an(t)))}div(t){return nn.from(t).isZero()&&hn("division-by-zero","div"),on(an(this).div(an(t)))}mul(t){return on(an(this).mul(an(t)))}mod(t){const e=an(t);return e.isNeg()&&hn("division-by-zero","mod"),on(an(this).umod(e))}pow(t){const e=an(t);return e.isNeg()&&hn("negative-power","pow"),on(an(this).pow(e))}and(t){const e=an(t);return(this.isNegative()||e.isNeg())&&hn("unbound-bitwise-result","and"),on(an(this).and(e))}or(t){const e=an(t);return(this.isNegative()||e.isNeg())&&hn("unbound-bitwise-result","or"),on(an(this).or(e))}xor(t){const e=an(t);return(this.isNegative()||e.isNeg())&&hn("unbound-bitwise-result","xor"),on(an(this).xor(e))}mask(t){return(this.isNegative()||t<0)&&hn("negative-width","mask"),on(an(this).maskn(t))}shl(t){return(this.isNegative()||t<0)&&hn("negative-width","shl"),on(an(this).shln(t))}shr(t){return(this.isNegative()||t<0)&&hn("negative-width","shr"),on(an(this).shrn(t))}eq(t){return an(this).eq(an(t))}lt(t){return an(this).lt(an(t))}lte(t){return an(this).lte(an(t))}gt(t){return an(this).gt(an(t))}gte(t){return an(this).gte(an(t))}isNegative(){return"-"===this._hex[0]}isZero(){return an(this).isZero()}toNumber(){try{return an(this).toNumber()}catch{hn("overflow","toNumber",this.toString())}return null}toBigInt(){try{return BigInt(this.toString())}catch{}return Zi.throwError("this platform does not support BigInt",ki.errors.UNSUPPORTED_OPERATION,{value:this.toString()})}toString(){return arguments.length>0&&(10===arguments[0]?rn||(rn=!0,Zi.warn("BigNumber.toString does not accept any parameters; base-10 is assumed")):16===arguments[0]?Zi.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()",ki.errors.UNEXPECTED_ARGUMENT,{}):Zi.throwError("BigNumber.toString does not accept parameters",ki.errors.UNEXPECTED_ARGUMENT,{})),an(this).toString(10)}toHexString(){return this._hex}toJSON(t){return{type:"BigNumber",hex:this.toHexString()}}static from(t){if(t instanceof nn)return t;if("string"==typeof t)return t.match(/^-?0x[0-9a-f]+$/i)?new nn(tn,sn(t)):t.match(/^-?[0-9]+$/)?new nn(tn,sn(new Xi(t))):Zi.throwArgumentError("invalid BigNumber string","value",t);if("number"==typeof t)return t%1&&hn("underflow","BigNumber.from",t),(t>=en||t<=-en)&&hn("overflow","BigNumber.from",t),nn.from(String(t));const e=t;if("bigint"==typeof e)return nn.from(e.toString());if(Bi(e))return nn.from(Ki(e));if(e)if(e.toHexString){const t=e.toHexString();if("string"==typeof t)return nn.from(t)}else{let t=e._hex;if(null==t&&"BigNumber"===e.type&&(t=e.hex),"string"==typeof t&&(zi(t)||"-"===t[0]&&zi(t.substring(1))))return nn.from(t)}return Zi.throwArgumentError("invalid BigNumber value","value",t)}static isBigNumber(t){return!(!t||!t._isBigNumber)}}function sn(t){if("string"!=typeof t)return sn(t.toString(16));if("-"===t[0])return"-"===(t=t.substring(1))[0]&&Zi.throwArgumentError("invalid hex","value",t),"0x00"===(t=sn(t))?t:"-"+t;if("0x"!==t.substring(0,2)&&(t="0x"+t),"0x"===t)return"0x00";for(t.length%2&&(t="0x0"+t.substring(2));t.length>4&&"0x00"===t.substring(0,4);)t="0x"+t.substring(4);return t}function on(t){return nn.from(sn(t))}function an(t){const e=nn.from(t).toHexString();return"-"===e[0]?new Xi("-"+e.substring(3),16):new Xi(e.substring(2),16)}function hn(t,e,r){const i={fault:t,operation:e};return null!=r&&(i.value=r),Zi.throwError(t,ki.errors.NUMERIC_FAULT,i)}const un=new ki(Qi),cn={},ln=nn.from(0),fn=nn.from(-1);function dn(t,e,r,i){const n={fault:e,operation:r};return void 0!==i&&(n.value=i),un.throwError(t,ki.errors.NUMERIC_FAULT,n)}let pn="0";for(;pn.length<256;)pn+=pn;function gn(t){if("number"!=typeof t)try{t=nn.from(t).toNumber()}catch{}return"number"==typeof t&&t>=0&&t<=256&&!(t%1)?"1"+pn.substring(0,t):un.throwArgumentError("invalid decimal size","decimals",t)}function mn(t,e){null==e&&(e=0);const r=gn(e),i=(t=nn.from(t)).lt(ln);i&&(t=t.mul(fn));let n=t.mod(r).toString();for(;n.length2&&un.throwArgumentError("too many decimal points","value",t);let s=n[0],o=n[1];for(s||(s="0"),o||(o="0");"0"===o[o.length-1];)o=o.substring(0,o.length-1);for(o.length>r.length-1&&dn("fractional component exceeds decimals","underflow","parseFixed"),""===o&&(o="0");o.lengthnull==t[e]?i:(typeof t[e]!==r&&un.throwArgumentError("invalid fixed format ("+e+" not "+r+")","format."+e,t[e]),t[e]);e=n("signed","boolean",e),r=n("width","number",r),i=n("decimals","number",i)}return r%8&&un.throwArgumentError("invalid fixed format width (not byte aligned)","format.width",r),i>80&&un.throwArgumentError("invalid fixed format (decimals too large)","format.decimals",i),new vn(cn,e,r,i)}}class wn{constructor(t,e,r,i){t!==cn&&un.throwError("cannot use FixedNumber constructor; use FixedNumber.from",ki.errors.UNSUPPORTED_OPERATION,{operation:"new FixedFormat"}),this.format=i,this._hex=e,this._value=r,this._isFixedNumber=!0,Object.freeze(this)}_checkFormat(t){this.format.name!==t.format.name&&un.throwArgumentError("incompatible format; use fixedNumber.toFormat","other",t)}addUnsafe(t){this._checkFormat(t);const e=yn(this._value,this.format.decimals),r=yn(t._value,t.format.decimals);return wn.fromValue(e.add(r),this.format.decimals,this.format)}subUnsafe(t){this._checkFormat(t);const e=yn(this._value,this.format.decimals),r=yn(t._value,t.format.decimals);return wn.fromValue(e.sub(r),this.format.decimals,this.format)}mulUnsafe(t){this._checkFormat(t);const e=yn(this._value,this.format.decimals),r=yn(t._value,t.format.decimals);return wn.fromValue(e.mul(r).div(this.format._multiplier),this.format.decimals,this.format)}divUnsafe(t){this._checkFormat(t);const e=yn(this._value,this.format.decimals),r=yn(t._value,t.format.decimals);return wn.fromValue(e.mul(this.format._multiplier).div(r),this.format.decimals,this.format)}floor(){const t=this.toString().split(".");1===t.length&&t.push("0");let e=wn.from(t[0],this.format);const r=!t[1].match(/^(0*)$/);return this.isNegative()&&r&&(e=e.subUnsafe(bn.toFormat(e.format))),e}ceiling(){const t=this.toString().split(".");1===t.length&&t.push("0");let e=wn.from(t[0],this.format);const r=!t[1].match(/^(0*)$/);return!this.isNegative()&&r&&(e=e.addUnsafe(bn.toFormat(e.format))),e}round(t){null==t&&(t=0);const e=this.toString().split(".");if(1===e.length&&e.push("0"),(t<0||t>80||t%1)&&un.throwArgumentError("invalid decimal count","decimals",t),e[1].length<=t)return this;const r=wn.from("1"+pn.substring(0,t),this.format),i=_n.toFormat(this.format);return this.mulUnsafe(r).addUnsafe(i).floor().divUnsafe(r)}isZero(){return"0.0"===this._value||"0"===this._value}isNegative(){return"-"===this._value[0]}toString(){return this._value}toHexString(t){return null==t?this._hex:(t%8&&un.throwArgumentError("invalid byte width","width",t),Vi(nn.from(this._hex).fromTwos(this.format.width).toTwos(t).toHexString(),t/8))}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(t){return wn.fromString(this._value,t)}static fromValue(t,e,r){return null==r&&null!=e&&!function(t){return null!=t&&(nn.isBigNumber(t)||"number"==typeof t&&t%1==0||"string"==typeof t&&!!t.match(/^-?[0-9]+$/)||zi(t)||"bigint"==typeof t||Bi(t))}(e)&&(r=e,e=null),null==e&&(e=0),null==r&&(r="fixed"),wn.fromString(mn(t,e),vn.from(r))}static fromString(t,e){null==e&&(e="fixed");const r=vn.from(e),i=yn(t,r.decimals);!r.signed&&i.lt(ln)&&dn("unsigned value cannot be negative","overflow","value",t);let n=null;r.signed?n=i.toTwos(r.width).toHexString():(n=i.toHexString(),n=Vi(n,r.width/8));const s=mn(i,r.decimals);return new wn(cn,n,s,r)}static fromBytes(t,e){null==e&&(e="fixed");const r=vn.from(e);if(ji(t).length>r.width/8)throw new Error("overflow");let i=nn.from(t);r.signed&&(i=i.fromTwos(r.width));const n=i.toTwos((r.signed?0:1)+r.width).toHexString(),s=mn(i,r.decimals);return new wn(cn,n,s,r)}static from(t,e){if("string"==typeof t)return wn.fromString(t,e);if(Bi(t))return wn.fromBytes(t,e);try{return wn.fromValue(t,0,e)}catch(t){if(t.code!==ki.errors.INVALID_ARGUMENT)throw t}return un.throwArgumentError("invalid FixedNumber value","value",t)}static isFixedNumber(t){return!(!t||!t._isFixedNumber)}}const bn=wn.from(1),_n=wn.from("0.5"),An=new ki("strings/5.7.0");var En,Sn;function Mn(t,e,r,i,n){if(t===Sn.BAD_PREFIX||t===Sn.UNEXPECTED_CONTINUE){let t=0;for(let i=e+1;i>6==2;i++)t++;return t}return t===Sn.OVERRUN?r.length-e-1:0}function In(t,e=En.current){e!=En.current&&(An.checkNormalize(),t=t.normalize(e));let r=[];for(let e=0;e>6|192),r.push(63&i|128);else if(55296==(64512&i)){e++;const n=t.charCodeAt(e);if(e>=t.length||56320!=(64512&n))throw new Error("invalid utf-8 string");const s=65536+((1023&i)<<10)+(1023&n);r.push(s>>18|240),r.push(s>>12&63|128),r.push(s>>6&63|128),r.push(63&s|128)}else r.push(i>>12|224),r.push(i>>6&63|128),r.push(63&i|128)}return ji(r)}function xn(t,e){e||(e=function(t){return[parseInt(t,16)]});let r=0,i={};return t.split(",").forEach((t=>{let n=t.split(":");r+=parseInt(n[0],16),i[r]=e(n[1])})),i}function Nn(t){let e=0;return t.split(",").map((t=>{let r=t.split("-");1===r.length?r[1]="0":""===r[1]&&(r[1]="1");let i=e+parseInt(r[0],16);return e=parseInt(r[1],16),{l:i,h:e}}))}!function(t){t.current="",t.NFC="NFC",t.NFD="NFD",t.NFKC="NFKC",t.NFKD="NFKD"}(En||(En={})),function(t){t.UNEXPECTED_CONTINUE="unexpected continuation byte",t.BAD_PREFIX="bad codepoint prefix",t.OVERRUN="string overrun",t.MISSING_CONTINUE="missing continuation byte",t.OUT_OF_RANGE="out of UTF-8 range",t.UTF16_SURROGATE="UTF-16 surrogate",t.OVERLONG="overlong representation"}(Sn||(Sn={})),Object.freeze({error:function(t,e,r,i,n){return An.throwArgumentError(`invalid codepoint at offset ${e}; ${t}`,"bytes",r)},ignore:Mn,replace:function(t,e,r,i,n){return t===Sn.OVERLONG?(i.push(n),0):(i.push(65533),Mn(t,e,r))}}),Nn("221,13-1b,5f-,40-10,51-f,11-3,3-3,2-2,2-4,8,2,15,2d,28-8,88,48,27-,3-5,11-20,27-,8,28,3-5,12,18,b-a,1c-4,6-16,2-d,2-2,2,1b-4,17-9,8f-,10,f,1f-2,1c-34,33-14e,4,36-,13-,6-2,1a-f,4,9-,3-,17,8,2-2,5-,2,8-,3-,4-8,2-3,3,6-,16-6,2-,7-3,3-,17,8,3,3,3-,2,6-3,3-,4-a,5,2-6,10-b,4,8,2,4,17,8,3,6-,b,4,4-,2-e,2-4,b-10,4,9-,3-,17,8,3-,5-,9-2,3-,4-7,3-3,3,4-3,c-10,3,7-2,4,5-2,3,2,3-2,3-2,4-2,9,4-3,6-2,4,5-8,2-e,d-d,4,9,4,18,b,6-3,8,4,5-6,3-8,3-3,b-11,3,9,4,18,b,6-3,8,4,5-6,3-6,2,3-3,b-11,3,9,4,18,11-3,7-,4,5-8,2-7,3-3,b-11,3,13-2,19,a,2-,8-2,2-3,7,2,9-11,4-b,3b-3,1e-24,3,2-,3,2-,2-5,5,8,4,2,2-,3,e,4-,6,2,7-,b-,3-21,49,23-5,1c-3,9,25,10-,2-2f,23,6,3,8-2,5-5,1b-45,27-9,2a-,2-3,5b-4,45-4,53-5,8,40,2,5-,8,2,5-,28,2,5-,20,2,5-,8,2,5-,8,8,18,20,2,5-,8,28,14-5,1d-22,56-b,277-8,1e-2,52-e,e,8-a,18-8,15-b,e,4,3-b,5e-2,b-15,10,b-5,59-7,2b-555,9d-3,5b-5,17-,7-,27-,7-,9,2,2,2,20-,36,10,f-,7,14-,4,a,54-3,2-6,6-5,9-,1c-10,13-1d,1c-14,3c-,10-6,32-b,240-30,28-18,c-14,a0,115-,3,66-,b-76,5,5-,1d,24,2,5-2,2,8-,35-2,19,f-10,1d-3,311-37f,1b,5a-b,d7-19,d-3,41,57-,68-4,29-3,5f,29-37,2e-2,25-c,2c-2,4e-3,30,78-3,64-,20,19b7-49,51a7-59,48e-2,38-738,2ba5-5b,222f-,3c-94,8-b,6-4,1b,6,2,3,3,6d-20,16e-f,41-,37-7,2e-2,11-f,5-b,18-,b,14,5-3,6,88-,2,bf-2,7-,7-,7-,4-2,8,8-9,8-2ff,20,5-b,1c-b4,27-,27-cbb1,f7-9,28-2,b5-221,56,48,3-,2-,3-,5,d,2,5,3,42,5-,9,8,1d,5,6,2-2,8,153-3,123-3,33-27fd,a6da-5128,21f-5df,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3,2-1d,61-ff7d"),"ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff".split(",").map((t=>parseInt(t,16))),xn("b5:3bc,c3:ff,7:73,2:253,5:254,3:256,1:257,5:259,1:25b,3:260,1:263,2:269,1:268,5:26f,1:272,2:275,7:280,3:283,5:288,3:28a,1:28b,5:292,3f:195,1:1bf,29:19e,125:3b9,8b:3b2,1:3b8,1:3c5,3:3c6,1:3c0,1a:3ba,1:3c1,1:3c3,2:3b8,1:3b5,1bc9:3b9,1c:1f76,1:1f77,f:1f7a,1:1f7b,d:1f78,1:1f79,1:1f7c,1:1f7d,107:63,5:25b,4:68,1:68,1:68,3:69,1:69,1:6c,3:6e,4:70,1:71,1:72,1:72,1:72,7:7a,2:3c9,2:7a,2:6b,1:e5,1:62,1:63,3:65,1:66,2:6d,b:3b3,1:3c0,6:64,1b574:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3"),xn("179:1,2:1,2:1,5:1,2:1,a:4f,a:1,8:1,2:1,2:1,3:1,5:1,3:1,4:1,2:1,3:1,4:1,8:2,1:1,2:2,1:1,2:2,27:2,195:26,2:25,1:25,1:25,2:40,2:3f,1:3f,33:1,11:-6,1:-9,1ac7:-3a,6d:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,b:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,c:-8,2:-8,2:-8,2:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,49:-8,1:-8,1:-4a,1:-4a,d:-56,1:-56,1:-56,1:-56,d:-8,1:-8,f:-8,1:-8,3:-7"),xn("df:00730073,51:00690307,19:02BC006E,a7:006A030C,18a:002003B9,16:03B903080301,20:03C503080301,1d7:05650582,190f:00680331,1:00740308,1:0077030A,1:0079030A,1:006102BE,b6:03C50313,2:03C503130300,2:03C503130301,2:03C503130342,2a:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,3:1F7003B9,1:03B103B9,1:03AC03B9,2:03B10342,1:03B1034203B9,5:03B103B9,6:1F7403B9,1:03B703B9,1:03AE03B9,2:03B70342,1:03B7034203B9,5:03B703B9,6:03B903080300,1:03B903080301,3:03B90342,1:03B903080342,b:03C503080300,1:03C503080301,1:03C10313,2:03C50342,1:03C503080342,b:1F7C03B9,1:03C903B9,1:03CE03B9,2:03C90342,1:03C9034203B9,5:03C903B9,ac:00720073,5b:00B00063,6:00B00066,d:006E006F,a:0073006D,1:00740065006C,1:0074006D,124f:006800700061,2:00610075,2:006F0076,b:00700061,1:006E0061,1:03BC0061,1:006D0061,1:006B0061,1:006B0062,1:006D0062,1:00670062,3:00700066,1:006E0066,1:03BC0066,4:0068007A,1:006B0068007A,1:006D0068007A,1:00670068007A,1:00740068007A,15:00700061,1:006B00700061,1:006D00700061,1:006700700061,8:00700076,1:006E0076,1:03BC0076,1:006D0076,1:006B0076,1:006D0076,1:00700077,1:006E0077,1:03BC0077,1:006D0077,1:006B0077,1:006D0077,1:006B03C9,1:006D03C9,2:00620071,3:00632215006B0067,1:0063006F002E,1:00640062,1:00670079,2:00680070,2:006B006B,1:006B006D,9:00700068,2:00700070006D,1:00700072,2:00730076,1:00770062,c723:00660066,1:00660069,1:0066006C,1:006600660069,1:00660066006C,1:00730074,1:00730074,d:05740576,1:05740565,1:0574056B,1:057E0576,1:0574056D",(function(t){if(t.length%4!=0)throw new Error("bad data");let e=[];for(let r=0;r0&&Array.isArray(t)?n(t,e-1):r.push(t)}))};return n(t,e),r}function Rn(t){return 1&t?~t>>1:t>>1}function Cn(t,e){let r=Array(t);for(let i=0,n=-1;ie[t])):r}function Un(t,e,r){let i=Array(t).fill(void 0).map((()=>[]));for(let n=0;ni[e].push(t)));return i}function Ln(t,e){let r=1+e(),i=e(),n=function(t){let e=[];for(;;){let r=t();if(0==r)break;e.push(r)}return e}(e);return Pn(Un(n.length,1+t,e).map(((t,e)=>{const s=t[0],o=t.slice(1);return Array(n[e]).fill(void 0).map(((t,e)=>{let n=e*i;return[s+e*r,o.map((t=>t+n))]}))})))}function qn(t,e){return Un(1+e(),1+t,e).map((t=>[t[0],t.slice(1)]))}const Dn=function(t){return function(t){let e=0;return()=>t[e++]}(function(t){let e=0;function r(){return t[e++]<<8|t[e++]}let i=r(),n=1,s=[0,1];for(let t=1;t>--h&1}const l=Math.pow(2,31),f=l>>>1,d=f>>1,p=l-1;let g=0;for(let t=0;t<31;t++)g=g<<1|c();let m=[],y=0,v=l;for(;;){let t=Math.floor(((g-y+1)*n-1)/v),e=0,r=i;for(;r-e>1;){let i=e+r>>>1;t>>1|c(),o=o<<1^f,a=(a^f)<<1|f|1;y=o,v=1+a-o}let w=i-4;return m.map((e=>{switch(e-w){case 3:return w+65792+(t[a++]<<16|t[a++]<<8|t[a++]);case 2:return w+256+(t[a++]<<8|t[a++]);case 1:return w+t[a++];default:return e-1}}))}(t))}(function(t){t=atob(t);const e=[];for(let r=0;rt-e));!function r(){let i=[];for(;;){let n=kn(t,e);if(0==n.length)break;i.push({set:new Set(n),node:r()})}i.sort(((t,e)=>e.set.size-t.set.size));let n=t(),s=n%3;n=n/3|0;let o=!!(1&n);return n>>=1,{branches:i,valid:s,fe0f:o,save:1==n,check:2==n}}()}(Dn),new ki(On),new Uint8Array(32).fill(0);const Bn="Ethereum Signed Message:\n";function jn(t){return"string"==typeof t&&(t=In(t)),Wi(function(t){const e=t.map((t=>ji(t))),r=e.reduce(((t,e)=>t+e.length),0),i=new Uint8Array(r);return e.reduce(((t,e)=>(i.set(e,t),t+e.length)),0),qi(i)}([In(Bn),In(String(t.length)),t]))}new ki("rlp/5.7.0");const zn=new ki("address/5.7.0");function Fn(t){zi(t,20)||zn.throwArgumentError("invalid address","address",t);const e=(t=t.toLowerCase()).substring(2).split(""),r=new Uint8Array(40);for(let t=0;t<40;t++)r[t]=e[t].charCodeAt(0);const i=ji(Wi(r));for(let t=0;t<40;t+=2)i[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&i[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const Kn={};for(let t=0;t<10;t++)Kn[String(t)]=String(t);for(let t=0;t<26;t++)Kn[String.fromCharCode(65+t)]=String(10+t);const Hn=Math.floor(function(t){return Math.log10?Math.log10(t):Math.log(t)/Math.LN10}(9007199254740991));function Vn(t,e,r){Object.defineProperty(t,e,{enumerable:!0,value:r,writable:!1})}new ki("properties/5.7.0"),new ki(On),new Uint8Array(32).fill(0),nn.from(-1);const Gn=nn.from(0),Wn=nn.from(1);nn.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Vi(Wn.toHexString(),32),Vi(Gn.toHexString(),32);var $n={},Jn={},Yn=Qn;function Qn(t,e){if(!t)throw new Error(e||"Assertion failed")}Qn.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var Xn={exports:{}};"function"==typeof Object.create?Xn.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:Xn.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}};var Zn=Yn,ts=Xn.exports;function es(t,e){return!(55296!=(64512&t.charCodeAt(e))||e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1))}function rs(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function is(t){return 1===t.length?"0"+t:t}function ns(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}Jn.inherits=ts,Jn.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),n=0;n>6|192,r[i++]=63&s|128):es(t,n)?(s=65536+((1023&s)<<10)+(1023&t.charCodeAt(++n)),r[i++]=s>>18|240,r[i++]=s>>12&63|128,r[i++]=s>>6&63|128,r[i++]=63&s|128):(r[i++]=s>>12|224,r[i++]=s>>6&63|128,r[i++]=63&s|128)}else for(n=0;n>>0}return s},Jn.split32=function(t,e){for(var r=new Array(4*t.length),i=0,n=0;i>>24,r[n+1]=s>>>16&255,r[n+2]=s>>>8&255,r[n+3]=255&s):(r[n+3]=s>>>24,r[n+2]=s>>>16&255,r[n+1]=s>>>8&255,r[n]=255&s)}return r},Jn.rotr32=function(t,e){return t>>>e|t<<32-e},Jn.rotl32=function(t,e){return t<>>32-e},Jn.sum32=function(t,e){return t+e>>>0},Jn.sum32_3=function(t,e,r){return t+e+r>>>0},Jn.sum32_4=function(t,e,r,i){return t+e+r+i>>>0},Jn.sum32_5=function(t,e,r,i,n){return t+e+r+i+n>>>0},Jn.sum64=function(t,e,r,i){var n=t[e],s=i+t[e+1]>>>0,o=(s>>0,t[e+1]=s},Jn.sum64_hi=function(t,e,r,i){return(e+i>>>0>>0},Jn.sum64_lo=function(t,e,r,i){return e+i>>>0},Jn.sum64_4_hi=function(t,e,r,i,n,s,o,a){var h=0,u=e;return h+=(u=u+i>>>0)>>0)>>0)>>0},Jn.sum64_4_lo=function(t,e,r,i,n,s,o,a){return e+i+s+a>>>0},Jn.sum64_5_hi=function(t,e,r,i,n,s,o,a,h,u){var c=0,l=e;return c+=(l=l+i>>>0)>>0)>>0)>>0)>>0},Jn.sum64_5_lo=function(t,e,r,i,n,s,o,a,h,u){return e+i+s+a+u>>>0},Jn.rotr64_hi=function(t,e,r){return(e<<32-r|t>>>r)>>>0},Jn.rotr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},Jn.shr64_hi=function(t,e,r){return t>>>r},Jn.shr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0};var ss={},os=Jn,as=Yn;function hs(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}ss.BlockHash=hs,hs.prototype.update=function(t,e){if(t=os.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=os.join32(t,0,t.length-r,this.endian);for(var i=0;i>>24&255,i[n++]=t>>>16&255,i[n++]=t>>>8&255,i[n++]=255&t}else for(i[n++]=255&t,i[n++]=t>>>8&255,i[n++]=t>>>16&255,i[n++]=t>>>24&255,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,s=8;s>>3},cs.g1_256=function(t){return ls(t,17)^ls(t,19)^t>>>10};var gs=Jn,ms=ss,ys=cs,vs=gs.rotl32,ws=gs.sum32,bs=gs.sum32_5,_s=ys.ft_1,As=ms.BlockHash,Es=[1518500249,1859775393,2400959708,3395469782];function Ss(){if(!(this instanceof Ss))return new Ss;As.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}gs.inherits(Ss,As);var Ms=Ss;Ss.blockSize=512,Ss.outSize=160,Ss.hmacStrength=80,Ss.padLength=64,Ss.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;ithis.blockSize&&(t=(new this.Hash).update(t).digest()),Vo(t.length<=this.blockSize);for(var e=t.length;e>8,o=255&n;s?r.push(s,o):r.push(o)}return r},r.zero2=i,r.toHex=n,r.encode=function(t,e){return"hex"===e?n(t):t}})),Zo=Jo((function(t,e){var r=e;r.assert=Yo,r.toArray=Xo.toArray,r.zero2=Xo.zero2,r.toHex=Xo.toHex,r.encode=Xo.encode,r.getNAF=function(t,e,r){var i=new Array(Math.max(t.bitLength(),r)+1);i.fill(0);for(var n=1<(n>>1)-1?(n>>1)-h:h,s.isubn(a)):a=0,i[o]=a,s.iushrn(1)}return i},r.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var i,n=0,s=0;t.cmpn(-n)>0||e.cmpn(-s)>0;){var o,a,h=t.andln(3)+n&3,u=e.andln(3)+s&3;3===h&&(h=-1),3===u&&(u=-1),o=1&h?3!=(i=t.andln(7)+n&7)&&5!==i||2!==u?h:-h:0,r[0].push(o),a=1&u?3!=(i=e.andln(7)+s&7)&&5!==i||2!==h?u:-u:0,r[1].push(a),2*n===o+1&&(n=1-n),2*s===a+1&&(s=1-s),t.iushrn(1),e.iushrn(1)}return r},r.cachedProperty=function(t,e,r){var i="_"+e;t.prototype[e]=function(){return void 0!==this[i]?this[i]:this[i]=r.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new Yi(t,"hex","le")}})),ta=Zo.getNAF,ea=Zo.getJSF,ra=Zo.assert;function ia(t,e){this.type=t,this.p=new Yi(e.p,16),this.red=e.prime?Yi.red(e.prime):Yi.mont(this.p),this.zero=new Yi(0).toRed(this.red),this.one=new Yi(1).toRed(this.red),this.two=new Yi(2).toRed(this.red),this.n=e.n&&new Yi(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var na=ia;function sa(t,e){this.curve=t,this.type=e,this.precomputed=null}ia.prototype.point=function(){throw new Error("Not implemented")},ia.prototype.validate=function(){throw new Error("Not implemented")},ia.prototype._fixedNafMul=function(t,e){ra(t.precomputed);var r=t._getDoubles(),i=ta(e,1,this._bitLength),n=(1<=s;h--)o=(o<<1)+i[h];a.push(o)}for(var u=this.jpoint(null,null,null),c=this.jpoint(null,null,null),l=n;l>0;l--){for(s=0;s=0;a--){for(var h=0;a>=0&&0===s[a];a--)h++;if(a>=0&&h++,o=o.dblp(h),a<0)break;var u=s[a];ra(0!==u),o="affine"===t.type?u>0?o.mixedAdd(n[u-1>>1]):o.mixedAdd(n[-u-1>>1].neg()):u>0?o.add(n[u-1>>1]):o.add(n[-u-1>>1].neg())}return"affine"===t.type?o.toP():o},ia.prototype._wnafMulAdd=function(t,e,r,i,n){var s,o,a,h=this._wnafT1,u=this._wnafT2,c=this._wnafT3,l=0;for(s=0;s=1;s-=2){var d=s-1,p=s;if(1===h[d]&&1===h[p]){var g=[e[d],null,null,e[p]];0===e[d].y.cmp(e[p].y)?(g[1]=e[d].add(e[p]),g[2]=e[d].toJ().mixedAdd(e[p].neg())):0===e[d].y.cmp(e[p].y.redNeg())?(g[1]=e[d].toJ().mixedAdd(e[p]),g[2]=e[d].add(e[p].neg())):(g[1]=e[d].toJ().mixedAdd(e[p]),g[2]=e[d].toJ().mixedAdd(e[p].neg()));var m=[-3,-1,-5,-7,0,7,5,1,3],y=ea(r[d],r[p]);for(l=Math.max(y[0].length,l),c[d]=new Array(l),c[p]=new Array(l),o=0;o=0;s--){for(var A=0;s>=0;){var E=!0;for(o=0;o=0&&A++,b=b.dblp(A),s<0)break;for(o=0;o0?a=u[o][S-1>>1]:S<0&&(a=u[o][-S-1>>1].neg()),b="affine"===a.type?b.mixedAdd(a):b.add(a))}}for(s=0;s=Math.ceil((t.bitLength()+1)/e.step)},sa.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],i=this,n=0;n=0&&(s=e,o=r),i.negative&&(i=i.neg(),n=n.neg()),s.negative&&(s=s.neg(),o=o.neg()),[{a:i,b:n},{a:s,b:o}]},ha.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],i=e[1],n=i.b.mul(t).divRound(this.n),s=r.b.neg().mul(t).divRound(this.n),o=n.mul(r.a),a=s.mul(i.a),h=n.mul(r.b),u=s.mul(i.b);return{k1:t.sub(o).sub(a),k2:h.add(u).neg()}},ha.prototype.pointFromX=function(t,e){(t=new Yi(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),i=r.redSqrt();if(0!==i.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var n=i.fromRed().isOdd();return(e&&!n||!e&&n)&&(i=i.redNeg()),this.point(t,i)},ha.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,i=this.a.redMul(e),n=e.redSqr().redMul(e).redIAdd(i).redIAdd(this.b);return 0===r.redSqr().redISub(n).cmpn(0)},ha.prototype._endoWnafMulAdd=function(t,e,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,s=0;s":""},ca.prototype.isInfinity=function(){return this.inf},ca.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),i=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,i)},ca.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),i=t.redInvm(),n=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(i),s=n.redSqr().redISub(this.x.redAdd(this.x)),o=n.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)},ca.prototype.getX=function(){return this.x.fromRed()},ca.prototype.getY=function(){return this.y.fromRed()},ca.prototype.mul=function(t){return t=new Yi(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},ca.prototype.mulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},ca.prototype.jmulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},ca.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},ca.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,i=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(i)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(i)}}}return e},ca.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},oa(la,na.BasePoint),ha.prototype.jpoint=function(t,e,r){return new la(this,t,e,r)},la.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),i=this.y.redMul(e).redMul(t);return this.curve.point(r,i)},la.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},la.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(e),n=t.x.redMul(r),s=this.y.redMul(e.redMul(t.z)),o=t.y.redMul(r.redMul(this.z)),a=i.redSub(n),h=s.redSub(o);if(0===a.cmpn(0))return 0!==h.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var u=a.redSqr(),c=u.redMul(a),l=i.redMul(u),f=h.redSqr().redIAdd(c).redISub(l).redISub(l),d=h.redMul(l.redISub(f)).redISub(s.redMul(c)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(f,d,p)},la.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,i=t.x.redMul(e),n=this.y,s=t.y.redMul(e).redMul(this.z),o=r.redSub(i),a=n.redSub(s);if(0===o.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var h=o.redSqr(),u=h.redMul(o),c=r.redMul(h),l=a.redSqr().redIAdd(u).redISub(c).redISub(c),f=a.redMul(c.redISub(l)).redISub(n.redMul(u)),d=this.z.redMul(o);return this.curve.jpoint(l,f,d)},la.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e=0)return!1;if(r.redIAdd(n),0===this.x.cmp(r))return!0}},la.prototype.inspect=function(){return this.isInfinity()?"":""},la.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var fa=Jo((function(t,e){var r=e;r.base=na,r.short=ua,r.mont=null,r.edwards=null})),da=Jo((function(t,e){var r,i=e,n=Zo.assert;function s(t){"short"===t.type?this.curve=new fa.short(t):"edwards"===t.type?this.curve=new fa.edwards(t):this.curve=new fa.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,n(this.g.validate(),"Invalid curve"),n(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function o(t,e){Object.defineProperty(i,t,{configurable:!0,enumerable:!0,get:function(){var r=new s(e);return Object.defineProperty(i,t,{configurable:!0,enumerable:!0,value:r}),r}})}i.PresetCurve=s,o("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:$n.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),o("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:$n.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),o("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:$n.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),o("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:$n.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),o("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:$n.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),o("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:$n.sha256,gRed:!1,g:["9"]}),o("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:$n.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{r=null.crash()}catch{r=void 0}o("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:$n.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",r]})}));function pa(t){if(!(this instanceof pa))return new pa(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=Xo.toArray(t.entropy,t.entropyEnc||"hex"),r=Xo.toArray(t.nonce,t.nonceEnc||"hex"),i=Xo.toArray(t.pers,t.persEnc||"hex");Yo(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}var ga=pa;pa.prototype._init=function(t,e,r){var i=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},pa.prototype.generate=function(t,e,r,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(i=r,r=e,e=null),r&&(r=Xo.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length"};var wa=Zo.assert;function ba(t,e){if(t instanceof ba)return t;this._importDER(t,e)||(wa(t.r&&t.s,"Signature without r or s"),this.r=new Yi(t.r,16),this.s=new Yi(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var _a=ba;function Aa(){this.place=0}function Ea(t,e){var r=t[e.place++];if(!(128&r))return r;var i=15&r;if(0===i||i>4)return!1;for(var n=0,s=0,o=e.place;s>>=0;return!(n<=127)&&(e.place=o,n)}function Sa(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}ba.prototype._importDER=function(t,e){t=Zo.toArray(t,e);var r=new Aa;if(48!==t[r.place++])return!1;var i=Ea(t,r);if(!1===i||i+r.place!==t.length||2!==t[r.place++])return!1;var n=Ea(t,r);if(!1===n)return!1;var s=t.slice(r.place,n+r.place);if(r.place+=n,2!==t[r.place++])return!1;var o=Ea(t,r);if(!1===o||t.length!==o+r.place)return!1;var a=t.slice(r.place,o+r.place);if(0===s[0]){if(!(128&s[1]))return!1;s=s.slice(1)}if(0===a[0]){if(!(128&a[1]))return!1;a=a.slice(1)}return this.r=new Yi(s),this.s=new Yi(a),this.recoveryParam=null,!0},ba.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=Sa(e),r=Sa(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];Ma(i,e.length),(i=i.concat(e)).push(2),Ma(i,r.length);var n=i.concat(r),s=[48];return Ma(s,n.length),s=s.concat(n),Zo.encode(s,t)};var Ia=function(){throw new Error("unsupported")},xa=Zo.assert;function Na(t){if(!(this instanceof Na))return new Na(t);"string"==typeof t&&(xa(Object.prototype.hasOwnProperty.call(da,t),"Unknown curve "+t),t=da[t]),t instanceof da.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}var Oa=Na;Na.prototype.keyPair=function(t){return new va(this,t)},Na.prototype.keyFromPrivate=function(t,e){return va.fromPrivate(this,t,e)},Na.prototype.keyFromPublic=function(t,e){return va.fromPublic(this,t,e)},Na.prototype.genKeyPair=function(t){t||(t={});for(var e=new ga({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||Ia(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),r=this.n.byteLength(),i=this.n.sub(new Yi(2));;){var n=new Yi(e.generate(r));if(!(n.cmp(i)>0))return n.iaddn(1),this.keyFromPrivate(n)}},Na.prototype._truncateToN=function(t,e){var r=8*t.byteLength()-this.n.bitLength();return r>0&&(t=t.ushrn(r)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},Na.prototype.sign=function(t,e,r,i){"object"==typeof r&&(i=r,r=null),i||(i={}),e=this.keyFromPrivate(e,r),t=this._truncateToN(new Yi(t,16));for(var n=this.n.byteLength(),s=e.getPrivate().toArray("be",n),o=t.toArray("be",n),a=new ga({hash:this.hash,entropy:s,nonce:o,pers:i.pers,persEnc:i.persEnc||"utf8"}),h=this.n.sub(new Yi(1)),u=0;;u++){var c=i.k?i.k(u):new Yi(a.generate(this.n.byteLength()));if(!((c=this._truncateToN(c,!0)).cmpn(1)<=0||c.cmp(h)>=0)){var l=this.g.mul(c);if(!l.isInfinity()){var f=l.getX(),d=f.umod(this.n);if(0!==d.cmpn(0)){var p=c.invm(this.n).mul(d.mul(e.getPrivate()).iadd(t));if(0!==(p=p.umod(this.n)).cmpn(0)){var g=(l.getY().isOdd()?1:0)|(0!==f.cmp(d)?2:0);return i.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),g^=1),new _a({r:d,s:p,recoveryParam:g})}}}}}},Na.prototype.verify=function(t,e,r,i){t=this._truncateToN(new Yi(t,16)),r=this.keyFromPublic(r,i);var n=(e=new _a(e,"hex")).r,s=e.s;if(n.cmpn(1)<0||n.cmp(this.n)>=0||s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;var o,a=s.invm(this.n),h=a.mul(t).umod(this.n),u=a.mul(n).umod(this.n);return this.curve._maxwellTrick?!(o=this.g.jmulAdd(h,r.getPublic(),u)).isInfinity()&&o.eqXToP(n):!(o=this.g.mulAdd(h,r.getPublic(),u)).isInfinity()&&0===o.getX().umod(this.n).cmp(n)},Na.prototype.recoverPubKey=function(t,e,r,i){xa((3&r)===r,"The recovery param is more than two bits"),e=new _a(e,i);var n=this.n,s=new Yi(t),o=e.r,a=e.s,h=1&r,u=r>>1;if(o.cmp(this.curve.p.umod(this.curve.n))>=0&&u)throw new Error("Unable to find sencond key candinate");o=u?this.curve.pointFromX(o.add(this.curve.n),h):this.curve.pointFromX(o,h);var c=e.r.invm(n),l=n.sub(s).mul(c).umod(n),f=a.mul(c).umod(n);return this.g.mulAdd(l,o,f)},Na.prototype.getKeyRecoveryParam=function(t,e,r,i){if(null!==(e=new _a(e,i)).recoveryParam)return e.recoveryParam;for(var n=0;n<4;n++){var s;try{s=this.recoverPubKey(t,e,n)}catch{continue}if(s.eq(r))return n}throw new Error("Unable to find valid recovery factor")};var Pa=Jo((function(t,e){var r=e;r.version="6.5.4",r.utils=Zo,r.rand=function(){throw new Error("unsupported")},r.curve=fa,r.curves=da,r.ec=Oa,r.eddsa=null})),Ra=Pa.ec;const Ca=new ki("signing-key/5.7.0");let Ta=null;function ka(){return Ta||(Ta=new Ra("secp256k1")),Ta}class Ua{constructor(t){Vn(this,"curve","secp256k1"),Vn(this,"privateKey",Ki(t)),32!==function(t){if("string"!=typeof t)t=Ki(t);else if(!zi(t)||t.length%2)return null;return(t.length-2)/2}(this.privateKey)&&Ca.throwArgumentError("invalid private key","privateKey","[[ REDACTED ]]");const e=ka().keyFromPrivate(ji(this.privateKey));Vn(this,"publicKey","0x"+e.getPublic(!1,"hex")),Vn(this,"compressedPublicKey","0x"+e.getPublic(!0,"hex")),Vn(this,"_isSigningKey",!0)}_addPoint(t){const e=ka().keyFromPublic(ji(this.publicKey)),r=ka().keyFromPublic(ji(t));return"0x"+e.pub.add(r.pub).encodeCompressed("hex")}signDigest(t){const e=ka().keyFromPrivate(ji(this.privateKey)),r=ji(t);32!==r.length&&Ca.throwArgumentError("bad digest length","digest",t);const i=e.sign(r,{canonical:!0});return Gi({recoveryParam:i.recoveryParam,r:Vi("0x"+i.r.toString(16),32),s:Vi("0x"+i.s.toString(16),32)})}computeSharedSecret(t){const e=ka().keyFromPrivate(ji(this.privateKey)),r=ka().keyFromPublic(ji(La(t)));return Vi("0x"+e.derive(r.getPublic()).toString(16),32)}static isSigningKey(t){return!(!t||!t._isSigningKey)}}function La(t,e){const r=ji(t);if(32===r.length){const t=new Ua(r);return e?"0x"+ka().keyFromPrivate(r).getPublic(!0,"hex"):t.publicKey}return 33===r.length?e?Ki(r):"0x"+ka().keyFromPublic(r).getPublic(!1,"hex"):65===r.length?e?"0x"+ka().keyFromPublic(r).getPublic(!0,"hex"):Ki(r):Ca.throwArgumentError("invalid public or private key","key","[REDACTED]")}var qa;function Da(t,e){return function(t){return function(t){let e=null;if("string"!=typeof t&&zn.throwArgumentError("invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==t.substring(0,2)&&(t="0x"+t),e=Fn(t),t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&e!==t&&zn.throwArgumentError("bad address checksum","address",t);else if(t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(t.substring(2,4)!==function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>Kn[t])).join("");for(;e.length>=Hn;){let t=e.substring(0,Hn);e=parseInt(t,10)%97+e.substring(t.length)}let r=String(98-parseInt(e,10)%97);for(;r.length<2;)r="0"+r;return r}(t)&&zn.throwArgumentError("bad icap checksum","address",t),e=function(t){return new Xi(t,36).toString(16)}(t.substring(4));e.length<40;)e="0"+e;e=Fn("0x"+e)}else zn.throwArgumentError("invalid address","address",t);return e}(Hi(Wi(Hi(La(t),1)),12))}(function(t,e){const r=Gi(e),i={r:ji(r.r),s:ji(r.s)};return"0x"+ka().recoverPubKey(ji(t),i,r.recoveryParam).encode("hex",!1)}(ji(t),e))}new ki("transactions/5.7.0"),function(t){t[t.legacy=0]="legacy",t[t.eip2930=1]="eip2930",t[t.eip1559=2]="eip1559"}(qa||(qa={}));const Ba="https://rpc.walletconnect.com/v1";var ja=Object.defineProperty,za=Object.defineProperties,Fa=Object.getOwnPropertyDescriptors,Ka=Object.getOwnPropertySymbols,Ha=Object.prototype.hasOwnProperty,Va=Object.prototype.propertyIsEnumerable,Ga=(t,e,r)=>e in t?ja(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;const Wa=t=>t?.split(":"),$a=t=>{const e=t&&Wa(t);if(e)return t.includes("did:pkh:")?e[3]:e[1]},Ja=t=>{const e=t&&Wa(t);if(e)return e[2]+":"+e[3]},Ya=t=>{const e=t&&Wa(t);if(e)return e.pop()};async function Qa(t){const{cacao:e,projectId:r}=t,{s:i,p:n}=e,s=Xa(n,n.iss),o=Ya(n.iss);return await async function(t,e,r,i,n,s){switch(r.t){case"eip191":return function(t,e,r){return Da(jn(e),r).toLowerCase()===t.toLowerCase()}(t,e,r.s);case"eip1271":return await async function(t,e,r,i,n,s){try{const o="0x1626ba7e",a="0000000000000000000000000000000000000000000000000000000000000040",h="0000000000000000000000000000000000000000000000000000000000000041",u=r.substring(2),c=o+jn(e).substring(2)+a+h+u,l=await fetch(`${s||Ba}/?chainId=${i}&projectId=${n}`,{method:"POST",body:JSON.stringify({id:Date.now()+Math.floor(1e3*Math.random()),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:c},"latest"]})}),{result:f}=await l.json();return!!f&&f.slice(0,o.length).toLowerCase()===o.toLowerCase()}catch(t){return console.error("isValidEip1271Signature: ",t),!1}}(t,e,r.s,i,n,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}(o,s,i,$a(n.iss),r)}const Xa=(t,e)=>{const r=`${t.domain} wants you to sign in with your Ethereum account:`,i=Ya(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let n=t.statement||void 0;const s=`URI: ${t.aud||t.uri}`,o=`Version: ${t.version}`,a=`Chain ID: ${$a(e)}`,h=`Nonce: ${t.nonce}`,u=`Issued At: ${t.iat}`,c=t.exp?`Expiration Time: ${t.exp}`:void 0,l=t.nbf?`Not Before: ${t.nbf}`:void 0,f=t.requestId?`Request ID: ${t.requestId}`:void 0,d=t.resources?`Resources:${t.resources.map((t=>`\n- ${t}`)).join("")}`:void 0,p=oh(t.resources);return p&&(n=function(t="",e){Za(e);const r="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(r))return t;const i=[];let n=0;return Object.keys(e.att).forEach((t=>{const r=Object.keys(e.att[t]).map((t=>({ability:t.split("/")[0],action:t.split("/")[1]})));r.sort(((t,e)=>t.action.localeCompare(e.action)));const s={};r.forEach((t=>{s[t.ability]||(s[t.ability]=[]),s[t.ability].push(t.action)}));const o=Object.keys(s).map((e=>(n++,`(${n}) '${e}': '${s[e].join("', '")}' for '${t}'.`)));i.push(o.join(", ").replace(".,","."))})),`${t?t+" ":""}${r}${i.join(" ")}`}(n,rh(p))),[r,i,"",n,"",s,o,a,h,u,c,l,f,d].filter((t=>null!=t)).join("\n")};function Za(t){if(!t)throw new Error("No recap provided, value is undefined");if(!t.att)throw new Error("No `att` property found");const e=Object.keys(t.att);if(null==e||!e.length)throw new Error("No resources found in `att` property");e.forEach((e=>{const r=t.att[e];if(Array.isArray(r))throw new Error(`Resource must be an object: ${e}`);if("object"!=typeof r)throw new Error(`Resource must be an object: ${e}`);if(!Object.keys(r).length)throw new Error(`Resource object is empty: ${e}`);Object.keys(r).forEach((t=>{const e=r[t];if(!Array.isArray(e))throw new Error(`Ability limits ${t} must be an array of objects, found: ${e}`);if(!e.length)throw new Error(`Value of ${t} is empty array, must be an array with objects`);e.forEach((e=>{if("object"!=typeof e)throw new Error(`Ability limits (${t}) must be an array of objects, found: ${e}`)}))}))}))}function th(t,e,r={}){e=e?.sort(((t,e)=>t.localeCompare(e)));const i=e.map((e=>({[`${t}/${e}`]:[r]})));return Object.assign({},...i)}function eh(t){return Za(t),`urn:recap:${function(t){return Buffer.from(JSON.stringify(t)).toString("base64")}(t).replace(/=/g,"")}`}function rh(t){const e=function(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}(t.replace("urn:recap:",""));return Za(e),e}function ih(t,e){const r=function(t,e){Za(t),Za(e);const r=Object.keys(t.att).concat(Object.keys(e.att)).sort(((t,e)=>t.localeCompare(e))),i={att:{}};return r.forEach((r=>{var n,s;Object.keys((null==(n=t.att)?void 0:n[r])||{}).concat(Object.keys((null==(s=e.att)?void 0:s[r])||{})).sort(((t,e)=>t.localeCompare(e))).forEach((n=>{var s,o;i.att[r]=((t,e)=>za(t,Fa(e)))(((t,e)=>{for(var r in e||(e={}))Ha.call(e,r)&&Ga(t,r,e[r]);if(Ka)for(var r of Ka(e))Va.call(e,r)&&Ga(t,r,e[r]);return t})({},i.att[r]),{[n]:(null==(s=t.att[r])?void 0:s[n])||(null==(o=e.att[r])?void 0:o[n])})}))})),i}(rh(t),rh(e));return eh(r)}function nh(t){var e;const r=rh(t);Za(r);const i=null==(e=r.att)?void 0:e.eip155;return i?Object.keys(i).map((t=>t.split("/")[1])):[]}function sh(t){const e=rh(t);Za(e);const r=[];return Object.values(e.att).forEach((t=>{Object.values(t).forEach((t=>{var e;null!=(e=t?.[0])&&e.chains&&r.push(t[0].chains)}))})),[...new Set(r.flat())]}function oh(t){if(!t)return;const e=t?.[t.length-1];return function(t){return t&&t.includes("urn:recap:")}(e)?e:void 0}const ah="base10",hh="base16",uh="base64pad",ch="utf8";function lh(){return Gr((0,Lt.randomBytes)(32),hh)}function fh(t){return Gr((0,qr.tW)(Vr(t,hh)),hh)}function dh(t){return Gr((0,qr.tW)(Vr(t,ch)),hh)}function ph(t){return Number(Gr(t,ah))}function gh(t){const e=Vr(t,uh),r=e.slice(0,1);if(1===ph(r)){const t=33,i=t+12,n=e.slice(1,t),s=e.slice(t,i);return{type:r,sealed:e.slice(i),iv:s,senderPublicKey:n}}const i=e.slice(1,13);return{type:r,sealed:e.slice(13),iv:i}}function mh(t){const e=t?.type||0;if(1===e){if(typeof t?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof t?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:e,senderPublicKey:t?.senderPublicKey,receiverPublicKey:t?.receiverPublicKey}}function yh(t){return 1===t.type&&"string"==typeof t.senderPublicKey&&"string"==typeof t.receiverPublicKey}function vh(t){return t?.relay||{protocol:"irn"}}function wh(t){const e=Wr[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}var bh=Object.defineProperty,_h=Object.defineProperties,Ah=Object.getOwnPropertyDescriptors,Eh=Object.getOwnPropertySymbols,Sh=Object.prototype.hasOwnProperty,Mh=Object.prototype.propertyIsEnumerable,Ih=(t,e,r)=>e in t?bh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xh=(t,e)=>{for(var r in e||(e={}))Sh.call(e,r)&&Ih(t,r,e[r]);if(Eh)for(var r of Eh(e))Mh.call(e,r)&&Ih(t,r,e[r]);return t};function Nh(t,e="-"){const r={},i="relay"+e;return Object.keys(t).forEach((e=>{if(e.startsWith(i)){const n=e.replace(i,""),s=t[e];r[n]=s}})),r}function Oh(t){const e=(t=(t=t.includes("wc://")?t.replace("wc://",""):t).includes("wc:")?t.replace("wc:",""):t).indexOf(":"),r=-1!==t.indexOf("?")?t.indexOf("?"):void 0,i=t.substring(0,e),n=t.substring(e+1,r).split("@"),s=typeof r<"u"?t.substring(r):"",o=kr.parse(s),a="string"==typeof o.methods?o.methods.split(","):void 0;return{protocol:i,topic:Ph(n[0]),version:parseInt(n[1],10),symKey:o.symKey,relay:Nh(o),methods:a,expiryTimestamp:o.expiryTimestamp?parseInt(o.expiryTimestamp,10):void 0}}function Ph(t){return t.startsWith("//")?t.substring(2):t}var Rh=Object.defineProperty,Ch=Object.defineProperties,Th=Object.getOwnPropertyDescriptors,kh=Object.getOwnPropertySymbols,Uh=Object.prototype.hasOwnProperty,Lh=Object.prototype.propertyIsEnumerable,qh=(t,e,r)=>e in t?Rh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Dh=(t,e)=>{for(var r in e||(e={}))Uh.call(e,r)&&qh(t,r,e[r]);if(kh)for(var r of kh(e))Lh.call(e,r)&&qh(t,r,e[r]);return t},Bh=(t,e)=>Ch(t,Th(e));function jh(t){const e=[];return t.forEach((t=>{const[r,i]=t.split(":");e.push(`${r}:${i}`)})),e}function zh(t){return t.includes(":")}function Fh(t){return zh(t)?t.split(":")[0]:t}function Kh(t){var e,r,i;const n={};if(!Yh(t))return n;for(const[s,o]of Object.entries(t)){const t=zh(s)?[s]:o.chains,a=o.methods||[],h=o.events||[],u=Fh(s);n[u]=Bh(Dh({},n[u]),{chains:bi(t,null==(e=n[u])?void 0:e.chains),methods:bi(a,null==(r=n[u])?void 0:r.methods),events:bi(h,null==(i=n[u])?void 0:i.events)})}return n}function Hh(t,e){e=e.map((t=>t.replace("did:pkh:","")));const r=function(t){const e={};return t?.forEach((t=>{const[r,i]=t.split(":");e[r]||(e[r]={accounts:[],chains:[],events:[]}),e[r].accounts.push(t),e[r].chains.push(`${r}:${i}`)})),e}(e);for(const[e,i]of Object.entries(r))i.methods?i.methods=bi(i.methods,t):i.methods=t,i.events=["chainChanged","accountsChanged"];return r}const Vh={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},Gh={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function Wh(t,e){const{message:r,code:i}=Gh[t];return{message:e?`${r} ${e}`:r,code:i}}function $h(t,e){const{message:r,code:i}=Vh[t];return{message:e?`${r} ${e}`:r,code:i}}function Jh(t,e){return!!Array.isArray(t)&&(!(typeof e<"u"&&t.length)||t.every(e))}function Yh(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function Qh(t){return typeof t>"u"}function Xh(t,e){return!(!e||!Qh(t))||"string"==typeof t&&!!t.trim().length}function Zh(t,e){return!(!e||!Qh(t))||"number"==typeof t&&!isNaN(t)}function tu(t){return!(!Xh(t,!1)||!t.includes(":"))&&2===t.split(":").length}function eu(t){if(Xh(t,!1))try{return typeof new URL(t)<"u"}catch{return!1}return!1}function ru(t){let e=!0;return Jh(t)?t.length&&(e=t.every((t=>Xh(t,!1)))):e=!1,e}function iu(t,e){let r=null;return Object.values(t).forEach((t=>{if(r)return;const i=function(t,e){let r=null;return ru(t?.methods)?ru(t?.events)||(r=$h("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):r=$h("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),r}(t,`${e}, namespace`);i&&(r=i)})),r}function nu(t,e){let r=null;if(t&&Yh(t)){const i=iu(t,e);i&&(r=i);const n=function(t,e){let r=null;return Object.values(t).forEach((t=>{if(r)return;const i=function(t,e){let r=null;return Jh(t)?t.forEach((t=>{r||function(t){if(Xh(t,!1)&&t.includes(":")){const e=t.split(":");if(3===e.length){const t=e[0]+":"+e[1];return!!e[2]&&tu(t)}}return!1}(t)||(r=$h("UNSUPPORTED_ACCOUNTS",`${e}, account ${t} should be a string and conform to "namespace:chainId:address" format`))})):r=$h("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),r}(t?.accounts,`${e} namespace`);i&&(r=i)})),r}(t,e);n&&(r=n)}else r=Wh("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return r}function su(t){return Xh(t.protocol,!0)}function ou(t){return typeof t<"u"&&null!==typeof t}function au(t,e){return!(!tu(e)||!function(t){const e=[];return Object.values(t).forEach((t=>{e.push(...jh(t.accounts))})),e}(t).includes(e))}function hu(t,e,r){let i=null;const n=function(t){const e={};return Object.keys(t).forEach((r=>{var i;r.includes(":")?e[r]=t[r]:null==(i=t[r].chains)||i.forEach((i=>{e[i]={methods:t[r].methods,events:t[r].events}}))})),e}(t),s=function(t){const e={};return Object.keys(t).forEach((r=>{if(r.includes(":"))e[r]=t[r];else{const i=jh(t[r].accounts);i?.forEach((i=>{e[i]={accounts:t[r].accounts.filter((t=>t.includes(`${i}:`))),methods:t[r].methods,events:t[r].events}}))}})),e}(e),o=Object.keys(n),a=Object.keys(s),h=uu(Object.keys(t)),u=uu(Object.keys(e)),c=h.filter((t=>!u.includes(t)));return c.length&&(i=Wh("NON_CONFORMING_NAMESPACES",`${r} namespaces keys don't satisfy requiredNamespaces.\n Required: ${c.toString()}\n Received: ${Object.keys(e).toString()}`)),ci(o,a)||(i=Wh("NON_CONFORMING_NAMESPACES",`${r} namespaces chains don't satisfy required namespaces.\n Required: ${o.toString()}\n Approved: ${a.toString()}`)),Object.keys(e).forEach((t=>{if(!t.includes(":")||i)return;const n=jh(e[t].accounts);n.includes(t)||(i=Wh("NON_CONFORMING_NAMESPACES",`${r} namespaces accounts don't satisfy namespace accounts for ${t}\n Required: ${t}\n Approved: ${n.toString()}`))})),o.forEach((t=>{i||(ci(n[t].methods,s[t].methods)?ci(n[t].events,s[t].events)||(i=Wh("NON_CONFORMING_NAMESPACES",`${r} namespaces events don't satisfy namespace events for ${t}`)):i=Wh("NON_CONFORMING_NAMESPACES",`${r} namespaces methods don't satisfy namespace methods for ${t}`))})),i}function uu(t){return[...new Set(t.map((t=>t.includes(":")?t.split(":")[0]:t)))]}function cu(t,e){return Zh(t,!1)&&t<=e.max&&t>=e.min}function lu(){const t=hi();return new Promise((e=>{switch(t){case ii.browser:e(ai()&&navigator?.onLine);break;case ii.reactNative:e(async function(){if(oi()&&typeof r.g<"u"&&null!=r.g&&r.g.NetInfo){const t=await(null==r.g?void 0:r.g.NetInfo.fetch());return t?.isConnected}return!0}());break;case ii.node:default:e(!0)}}))}const fu={};class du{static get(t){return fu[t]}static set(t,e){fu[t]=e}static delete(t){delete fu[t]}}function pu(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const gu=pu("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),mu=pu("ascii","a",(t=>{let e="a";for(let r=0;r{const e=function(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}((t=t.substring(1)).length);for(let r=0;re.code===t));return e||Mu[Iu]}(t.code)),t);var r}class Uu{}class Lu extends Uu{constructor(){super()}}class qu extends Lu{constructor(t){super()}}function Du(t){return function(t,e){const r=function(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(e&&e.length)return e[0]}(t);return void 0!==r&&new RegExp(e).test(r)}(t,"^wss?:")}function Bu(t){return"object"==typeof t&&"id"in t&&"jsonrpc"in t&&"2.0"===t.jsonrpc}function ju(t){return Bu(t)&&"method"in t}function zu(t){return Bu(t)&&(Fu(t)||Ku(t))}function Fu(t){return"result"in t}function Ku(t){return"error"in t}class Hu extends qu{constructor(t){super(t),this.events=new y.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(t),this.connection.connected&&this.registerEventListeners()}async connect(t=this.connection){await this.open(t)}async disconnect(){await this.close()}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async request(t,e){return this.requestStrict(Ru(t.method,t.params||[],t.id||Pu().toString()),e)}async requestStrict(t,e){return new Promise((async(r,i)=>{if(!this.connection.connected)try{await this.open()}catch(t){i(t)}this.events.on(`${t.id}`,(t=>{Ku(t)?i(t.error):r(t.result)}));try{await this.connection.send(t,e)}catch(t){i(t)}}))}setConnection(t=this.connection){return t}onPayload(t){this.events.emit("payload",t),zu(t)?this.events.emit(`${t.id}`,t):this.events.emit("message",{type:t.method,data:t.params})}onClose(t){t&&3e3===t.code&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${t.code} ${t.reason?`(${t.reason})`:""}`)),this.events.emit("disconnect")}async open(t=this.connection){this.connection===t&&this.connection.connected||(this.connection.connected&&this.close(),"string"==typeof t&&(await this.connection.open(t),t=this.connection),this.connection=this.setConnection(t),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",(t=>this.onPayload(t))),this.connection.on("close",(t=>this.onClose(t))),this.connection.on("error",(t=>this.events.emit("error",t))),this.connection.on("register_error",(t=>this.onClose())),this.hasRegisteredEventListeners=!0)}}const Vu=t=>t.split("?")[0],Gu=typeof WebSocket<"u"?WebSocket:typeof r.g<"u"&&typeof r.g.WebSocket<"u"?r.g.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:typeof self<"u"&&typeof self.WebSocket<"u"?self.WebSocket:r(1591);class Wu{constructor(t){if(this.url=t,this.events=new y.EventEmitter,this.registering=!1,!Du(t))throw new Error(`Provided URL is not compatible with WebSocket connection: ${t}`);this.url=t}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async open(t=this.url){await this.register(t)}async close(){return new Promise(((t,e)=>{typeof this.socket>"u"?e(new Error("Connection already closed")):(this.socket.onclose=e=>{this.onClose(e),t()},this.socket.close())}))}async send(t){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(F(t))}catch(e){this.onError(t.id,e)}}register(t=this.url){if(!Du(t))throw new Error(`Provided URL is not compatible with WebSocket connection: ${t}`);if(this.registering){const t=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=t||this.events.listenerCount("open")>=t)&&this.events.setMaxListeners(t+1),new Promise(((t,e)=>{this.events.once("register_error",(t=>{this.resetMaxListeners(),e(t)})),this.events.once("open",(()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return e(new Error("WebSocket connection is missing or invalid"));t(this.socket)}))}))}return this.url=t,this.registering=!0,new Promise(((e,i)=>{const n=new URLSearchParams(t).get("origin"),s=(0,Nu.isReactNative)()?{headers:{origin:n}}:{rejectUnauthorized:(a=t,!new RegExp("wss?://localhost(:d{2,5})?").test(a))},o=new Gu(t,[],s);var a;typeof WebSocket<"u"||typeof r.g<"u"&&typeof r.g.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u"?o.onerror=t=>{const e=t;i(this.emitError(e.error))}:o.on("error",(t=>{i(this.emitError(t))})),o.onopen=()=>{this.onOpen(o),e(o)}}))}onOpen(t){t.onmessage=t=>this.onPayload(t),t.onclose=t=>this.onClose(t),this.socket=t,this.registering=!1,this.events.emit("open")}onClose(t){this.socket=void 0,this.registering=!1,this.events.emit("close",t)}onPayload(t){if(typeof t.data>"u")return;const e="string"==typeof t.data?z(t.data):t.data;this.events.emit("payload",e)}onError(t,e){const r=this.parseError(e),i=Tu(t,r.message||r.toString());this.events.emit("payload",i)}parseError(t,e=this.url){return function(t,e,r){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable WS RPC url at ${e}`):t}(t,Vu(e))}resetMaxListeners(){this.events.getMaxListeners()>10&&this.events.setMaxListeners(10)}emitError(t){const e=this.parseError(new Error(t?.message||`WebSocket connection failed for host: ${Vu(this.url)}`));return this.events.emit("register_error",e),e}}var $u=r(8142),Ju=r.n($u),Yu=r(916),Qu=r.n(Yu),Xu=function(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i>>0,o=new Uint8Array(s);t[e];){var c=r[t.charCodeAt(e)];if(255===c)return;for(var l=0,f=s-1;(0!==c||l>>0,o[f]=c%256>>>0,c=c/256>>>0;if(0!==c)throw new Error("Non-zero carry");n=l,e++}if(" "!==t[e]){for(var d=s-n;d!==s&&0===o[d];)d++;for(var p=new Uint8Array(i+(s-d)),g=i;d!==s;)p[g++]=o[d++];return p}}}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,i=0,n=0,s=e.length;n!==s&&0===e[n];)n++,r++;for(var o=(s-n)*c+1>>>0,u=new Uint8Array(o);n!==s;){for(var l=e[n],f=0,d=o-1;(0!==l||f>>0,u[d]=l%a>>>0,l=l/a>>>0;if(0!==l)throw new Error("Non-zero carry");i=f,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var g=h.repeat(r);p{if(t instanceof Uint8Array&&"Uint8Array"===t.constructor.name)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};class tc{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class ec{constructor(t,e,r){if(this.name=t,this.prefix=e,void 0===e.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if("string"==typeof t){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(t){return ic(this,t)}}class rc{constructor(t){this.decoders=t}or(t){return ic(this,t)}decode(t){const e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const ic=(t,e)=>new rc({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class nc{constructor(t,e,r,i){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=i,this.encoder=new tc(t,e,r),this.decoder=new ec(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const sc=({name:t,prefix:e,encode:r,decode:i})=>new nc(t,e,r,i),oc=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=Xu(r,e);return sc({prefix:t,name:e,encode:i,decode:t=>Zu(n(t))})},ac=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>sc({prefix:e,name:t,encode:t=>((t,e,r)=>{const i="="===e[e.length-1],n=(1<r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<((t,e,r,i)=>{const n={};for(let t=0;t=8&&(a-=8,o[u++]=255&h>>a)}if(a>=r||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o})(e,i,r,t)}),hc=sc({prefix:"\0",name:"identity",encode:t=>(t=>(new TextDecoder).decode(t))(t),decode:t=>(t=>(new TextEncoder).encode(t))(t)});var uc=Object.freeze({__proto__:null,identity:hc});const cc=ac({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lc=Object.freeze({__proto__:null,base2:cc});const fc=ac({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var dc=Object.freeze({__proto__:null,base8:fc});const pc=oc({prefix:"9",name:"base10",alphabet:"0123456789"});var gc=Object.freeze({__proto__:null,base10:pc});const mc=ac({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yc=ac({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vc=Object.freeze({__proto__:null,base16:mc,base16upper:yc});const bc=ac({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_c=ac({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ac=ac({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ec=ac({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Sc=ac({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=ac({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ic=ac({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xc=ac({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Nc=ac({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Oc=Object.freeze({__proto__:null,base32:bc,base32upper:_c,base32pad:Ac,base32padupper:Ec,base32hex:Sc,base32hexupper:Mc,base32hexpad:Ic,base32hexpadupper:xc,base32z:Nc});const Pc=oc({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Rc=oc({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cc=Object.freeze({__proto__:null,base36:Pc,base36upper:Rc});const Tc=oc({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),kc=oc({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Uc=Object.freeze({__proto__:null,base58btc:Tc,base58flickr:kc});const Lc=ac({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qc=ac({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dc=ac({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bc=ac({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jc=Object.freeze({__proto__:null,base64:Lc,base64pad:qc,base64url:Dc,base64urlpad:Bc});const zc=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),Fc=zc.reduce(((t,e,r)=>(t[r]=e,t)),[]),Kc=zc.reduce(((t,e,r)=>(t[e.codePointAt(0)]=r,t)),[]),Hc=sc({prefix:"🚀",name:"base256emoji",encode:function(t){return t.reduce(((t,e)=>t+Fc[e]),"")},decode:function(t){const e=[];for(const r of t){const t=Kc[r.codePointAt(0)];if(void 0===t)throw new Error(`Non-base256emoji character: ${r}`);e.push(t)}return new Uint8Array(e)}});var Vc=Object.freeze({__proto__:null,base256emoji:Hc}),Gc=128,Wc=-128,$c=Math.pow(2,31),Jc=128,Yc=127,Qc=Math.pow(2,7),Xc=Math.pow(2,14),Zc=Math.pow(2,21),tl=Math.pow(2,28),el=Math.pow(2,35),rl=Math.pow(2,42),il=Math.pow(2,49),nl=Math.pow(2,56),sl=Math.pow(2,63),ol={encode:function t(e,r,i){r=r||[];for(var n=i=i||0;e>=$c;)r[i++]=255&e|Gc,e/=128;for(;e&Wc;)r[i++]=255&e|Gc,e>>>=7;return r[i]=0|e,t.bytes=i-n+1,r},decode:function t(e,r){var i,n=0,s=(r=r||0,0),o=r,a=e.length;do{if(o>=a)throw t.bytes=0,new RangeError("Could not decode varint");i=e[o++],n+=s<28?(i&Yc)<=Jc);return t.bytes=o-r,n},encodingLength:function(t){return t(al.encode(t,e,r),e),ul=t=>al.encodingLength(t),cl=(t,e)=>{const r=e.byteLength,i=ul(t),n=i+ul(r),s=new Uint8Array(n+r);return hl(t,s,0),hl(r,s,i),s.set(e,n),new ll(t,r,e,s)};class ll{constructor(t,e,r,i){this.code=t,this.size=e,this.digest=r,this.bytes=i}}const fl=({name:t,code:e,encode:r})=>new dl(t,e,r);class dl{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){const e=this.encode(t);return e instanceof Uint8Array?cl(this.code,e):e.then((t=>cl(this.code,t)))}throw Error("Unknown type, must be binary type")}}const pl=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),gl=fl({name:"sha2-256",code:18,encode:pl("SHA-256")}),ml=fl({name:"sha2-512",code:19,encode:pl("SHA-512")});Object.freeze({__proto__:null,sha256:gl,sha512:ml});const yl=Zu,vl={code:0,name:"identity",encode:yl,digest:t=>cl(0,yl(t))};Object.freeze({__proto__:null,identity:vl}),new TextEncoder,new TextDecoder;const wl={...uc,...lc,...dc,...gc,...vc,...Oc,...Cc,...Uc,...jc,...Vc};function bl(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const _l=bl("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),Al=bl("ascii","a",(t=>{let e="a";for(let r=0;r{const e=function(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}((t=t.substring(1)).length);for(let r=0;r{if(!this.initialized){const t=await this.getKeyChain();typeof t<"u"&&(this.keychain=t),this.initialized=!0}},this.has=t=>(this.isInitialized(),this.keychain.has(t)),this.set=async(t,e)=>{this.isInitialized(),this.keychain.set(t,e),await this.persist()},this.get=t=>{this.isInitialized();const e=this.keychain.get(t);if(typeof e>"u"){const{message:e}=Wh("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(e)}return e},this.del=async t=>{this.isInitialized(),this.keychain.delete(t),await this.persist()},this.core=t,this.logger=_t(e,this.name)}get context(){return bt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(t){await this.core.storage.setItem(this.storageKey,li(t))}async getKeyChain(){const t=await this.core.storage.getItem(this.storageKey);return typeof t<"u"?fi(t):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}}class rf{constructor(t,e,r){this.core=t,this.logger=e,this.name="crypto",this.randomSessionIdentifier=lh(),this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=t=>(this.isInitialized(),this.keychain.has(t)),this.getClientId=async()=>(this.isInitialized(),wr(br(await this.getClientSeed()).publicKey)),this.generateKeyPair=()=>{this.isInitialized();const t=function(){const t=Dr.TZ();return{privateKey:Gr(t.secretKey,hh),publicKey:Gr(t.publicKey,hh)}}();return this.setPrivateKey(t.publicKey,t.privateKey)},this.signJWT=async t=>{this.isInitialized();const e=br(await this.getClientSeed()),r=this.randomSessionIdentifier,i=Nl;return await async function(t,e,r,i,n=(0,Y.fromMiliseconds)(Date.now())){const s={alg:"EdDSA",typ:"JWT"},o={iss:wr(i.publicKey),sub:t,aud:e,iat:n,exp:n+r},a=yr([vr((h={header:s,payload:o}).header),vr(h.payload)].join("."),"utf8");var h;return function(t){return[vr(t.header),vr(t.payload),(e=t.signature,mr(e,qt))].join(".");var e}({header:s,payload:o,signature:Ut._S(i.secretKey,a)})}(r,t,i,e)},this.generateSharedKey=(t,e,r)=>{this.isInitialized();const i=function(t,e){const r=Dr.Tc(Vr(t,hh),Vr(e,hh),!0);return Gr(new Lr.i(qr.aD,r).expand(32),hh)}(this.getPrivateKey(t),e);return this.setSymKey(i,r)},this.setSymKey=async(t,e)=>{this.isInitialized();const r=e||fh(t);return await this.keychain.set(r,t),r},this.deleteKeyPair=async t=>{this.isInitialized(),await this.keychain.del(t)},this.deleteSymKey=async t=>{this.isInitialized(),await this.keychain.del(t)},this.encode=async(t,e,r)=>{this.isInitialized();const i=mh(r),n=F(e);if(yh(i)){const e=i.senderPublicKey,r=i.receiverPublicKey;t=await this.generateSharedKey(e,r)}const s=this.getSymKey(t),{type:o,senderPublicKey:a}=i;return function(t){const e=function(t){return Vr(`${t}`,ah)}(typeof t.type<"u"?t.type:0);if(1===ph(e)&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const r=typeof t.senderPublicKey<"u"?Vr(t.senderPublicKey,hh):void 0,i=typeof t.iv<"u"?Vr(t.iv,hh):(0,Lt.randomBytes)(12);return function(t){if(1===ph(t.type)){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return Gr(jr([t.type,t.senderPublicKey,t.iv,t.sealed]),uh)}return Gr(jr([t.type,t.iv,t.sealed]),uh)}({type:e,sealed:new Ur.g6(Vr(t.symKey,hh)).seal(i,Vr(t.message,ch)),iv:i,senderPublicKey:r})}({type:o,symKey:s,message:n,senderPublicKey:a})},this.decode=async(t,e,r)=>{this.isInitialized();const i=function(t,e){const r=gh(t);return mh({type:ph(r.type),senderPublicKey:typeof r.senderPublicKey<"u"?Gr(r.senderPublicKey,hh):void 0,receiverPublicKey:e?.receiverPublicKey})}(e,r);if(yh(i)){const e=i.receiverPublicKey,r=i.senderPublicKey;t=await this.generateSharedKey(e,r)}try{const r=function(t){const e=new Ur.g6(Vr(t.symKey,hh)),{sealed:r,iv:i}=gh(t.encoded),n=e.open(i,r);if(null===n)throw new Error("Failed to decrypt");return Gr(n,ch)}({symKey:this.getSymKey(t),encoded:e});return z(r)}catch(e){this.logger.error(`Failed to decode message from topic: '${t}', clientId: '${await this.getClientId()}'`),this.logger.error(e)}},this.getPayloadType=t=>ph(gh(t).type),this.getPayloadSenderPublicKey=t=>{const e=gh(t);return e.senderPublicKey?function(t,e="utf8"){const r=yu[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return"utf8"!==e&&"utf-8"!==e||null==globalThis.Buffer||null==globalThis.Buffer.from?r.encoder.encode(t).substring(1):globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8")}(e.senderPublicKey,hh):void 0},this.core=t,this.logger=_t(e,this.name),this.keychain=r||new ef(this.core,this.logger)}get context(){return bt(this.logger)}async setPrivateKey(t,e){return await this.keychain.set(t,e),t}getPrivateKey(t){return this.keychain.get(t)}async getClientSeed(){let t="";try{t=this.keychain.get(xl)}catch{t=lh(),await this.keychain.set(xl,t)}return function(t,e="utf8"){const r=El[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return"utf8"!==e&&"utf-8"!==e||null==globalThis.Buffer||null==globalThis.Buffer.from?r.decoder.decode(`${r.prefix}${t}`):globalThis.Buffer.from(t,"utf8")}(t,"base16")}getSymKey(t){return this.keychain.get(t)}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}}class nf extends Mt{constructor(t,e){super(t,e),this.logger=t,this.core=e,this.messages=new Map,this.name="messages",this.version="0.3",this.initialized=!1,this.storagePrefix=Ml,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const t=await this.getRelayerMessages();typeof t<"u"&&(this.messages=t),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(t){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(t)}finally{this.initialized=!0}}},this.set=async(t,e)=>{this.isInitialized();const r=dh(e);let i=this.messages.get(t);return typeof i>"u"&&(i={}),typeof i[r]<"u"||(i[r]=e,this.messages.set(t,i),await this.persist()),r},this.get=t=>{this.isInitialized();let e=this.messages.get(t);return typeof e>"u"&&(e={}),e},this.has=(t,e)=>(this.isInitialized(),typeof this.get(t)[dh(e)]<"u"),this.del=async t=>{this.isInitialized(),this.messages.delete(t),await this.persist()},this.logger=_t(t,this.name),this.core=e}get context(){return bt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setRelayerMessages(t){await this.core.storage.setItem(this.storageKey,li(t))}async getRelayerMessages(){const t=await this.core.storage.getItem(this.storageKey);return typeof t<"u"?fi(t):void 0}async persist(){await this.setRelayerMessages(this.messages)}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}}class sf extends It{constructor(t,e){super(t,e),this.relayer=t,this.logger=e,this.events=new y.EventEmitter,this.name="publisher",this.queue=new Map,this.publishTimeout=(0,Y.toMiliseconds)(Y.ONE_MINUTE),this.failedPublishTimeout=(0,Y.toMiliseconds)(Y.ONE_SECOND),this.needsTransportRestart=!1,this.publish=async(t,e,r)=>{var i;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:t,message:e,opts:r}});const n=r?.ttl||Ol,s=vh(r),o=r?.prompt||!1,a=r?.tag||0,h=r?.id||Pu().toString(),u={topic:t,message:e,opts:{ttl:n,relay:s,prompt:o,tag:a,id:h}},c=`Failed to publish payload, please try again. id:${h} tag:${a}`,l=Date.now();let f,d=1;try{for(;void 0===f;){if(Date.now()-l>this.publishTimeout)throw new Error(c);this.logger.trace({id:h,attempts:d},`publisher.publish - attempt ${d}`),f=await await pi(this.rpcPublish(t,e,n,s,o,a,h).catch((t=>this.logger.warn(t))),this.publishTimeout,c),d++,f||await new Promise((t=>setTimeout(t,this.failedPublishTimeout)))}this.relayer.events.emit(kl,u),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{id:h,topic:t,message:e,opts:r}})}catch(t){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(t),null!=(i=r?.internal)&&i.throwOnFailedPublish)throw t;this.queue.set(h,u)}},this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.relayer=t,this.logger=_t(e,this.name),this.registerEventListeners()}get context(){return bt(this.logger)}rpcPublish(t,e,r,i,n,s,o){var a,h,u,c;const l={method:wh(i.protocol).publish,params:{topic:t,message:e,ttl:r,prompt:n,tag:s},id:o};return Qh(null==(a=l.params)?void 0:a.prompt)&&(null==(h=l.params)||delete h.prompt),Qh(null==(u=l.params)?void 0:u.tag)&&(null==(c=l.params)||delete c.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:l}),this.relayer.request(l)}removeRequestFromQueue(t){this.queue.delete(t)}checkQueue(){this.queue.forEach((async t=>{const{topic:e,message:r,opts:i}=t;await this.publish(e,r,i)}))}registerEventListeners(){this.relayer.core.heartbeat.on(tt,(()=>{if(this.needsTransportRestart)return this.needsTransportRestart=!1,void this.relayer.events.emit(Tl);this.checkQueue()})),this.relayer.on(Cl,(t=>{this.removeRequestFromQueue(t.id.toString())}))}}class of{constructor(){this.map=new Map,this.set=(t,e)=>{const r=this.get(t);this.exists(t,e)||this.map.set(t,[...r,e])},this.get=t=>this.map.get(t)||[],this.exists=(t,e)=>this.get(t).includes(e),this.delete=(t,e)=>{if(typeof e>"u")return void this.map.delete(t);if(!this.map.has(t))return;const r=this.get(t);if(!this.exists(t,e))return;const i=r.filter((t=>t!==e));i.length?this.map.set(t,i):this.map.delete(t)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}}var af=Object.defineProperty,hf=Object.defineProperties,uf=Object.getOwnPropertyDescriptors,cf=Object.getOwnPropertySymbols,lf=Object.prototype.hasOwnProperty,ff=Object.prototype.propertyIsEnumerable,df=(t,e,r)=>e in t?af(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pf=(t,e)=>{for(var r in e||(e={}))lf.call(e,r)&&df(t,r,e[r]);if(cf)for(var r of cf(e))ff.call(e,r)&&df(t,r,e[r]);return t},gf=(t,e)=>hf(t,uf(e));class mf extends Ot{constructor(t,e){super(t,e),this.relayer=t,this.logger=e,this.subscriptions=new Map,this.topicMap=new of,this.events=new y.EventEmitter,this.name="subscription",this.version="0.3",this.pending=new Map,this.cached=[],this.initialized=!1,this.pendingSubscriptionWatchLabel="pending_sub_watch_label",this.pollingInterval=20,this.storagePrefix=Ml,this.subscribeTimeout=(0,Y.toMiliseconds)(Y.ONE_MINUTE),this.restartInProgress=!1,this.batchSubscribeTopicsLimit=500,this.pendingBatchMessages=[],this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),this.clientId=await this.relayer.core.crypto.getClientId())},this.subscribe=async(t,e)=>{await this.restartToComplete(),this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:t,opts:e}});try{const r=vh(e),i={topic:t,relay:r};this.pending.set(t,i);const n=await this.rpcSubscribe(t,r);return"string"==typeof n&&(this.onSubscribe(n,i),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:t,opts:e}})),n}catch(t){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(t),t}},this.unsubscribe=async(t,e)=>{await this.restartToComplete(),this.isInitialized(),typeof e?.id<"u"?await this.unsubscribeById(t,e.id,e):await this.unsubscribeByTopic(t,e)},this.isSubscribed=async t=>{if(this.topics.includes(t))return!0;const e=`${this.pendingSubscriptionWatchLabel}_${t}`;return await new Promise(((r,i)=>{const n=new Y.Watch;n.start(e);const s=setInterval((()=>{!this.pending.has(t)&&this.topics.includes(t)&&(clearInterval(s),n.stop(e),r(!0)),n.elapsed(e)>=zl&&(clearInterval(s),n.stop(e),i(new Error("Subscription resolution timeout")))}),this.pollingInterval)})).catch((()=>!1))},this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.start=async()=>{await this.onConnect()},this.stop=async()=>{await this.onDisconnect()},this.restart=async()=>{this.restartInProgress=!0,await this.restore(),await this.reset(),this.restartInProgress=!1},this.relayer=t,this.logger=_t(e,this.name),this.clientId=""}get context(){return bt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.relayer.core.customStoragePrefix+"//"+this.name}get length(){return this.subscriptions.size}get ids(){return Array.from(this.subscriptions.keys())}get values(){return Array.from(this.subscriptions.values())}get topics(){return this.topicMap.topics}hasSubscription(t,e){let r=!1;try{r=this.getSubscription(t).topic===e}catch{}return r}onEnable(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(t,e){const r=this.topicMap.get(t);await Promise.all(r.map((async r=>await this.unsubscribeById(t,r,e))))}async unsubscribeById(t,e,r){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:t,id:e,opts:r}});try{const i=vh(r);await this.rpcUnsubscribe(t,e,i);const n=$h("USER_DISCONNECTED",`${this.name}, ${t}`);await this.onUnsubscribe(t,e,n),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:t,id:e,opts:r}})}catch(t){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(t),t}}async rpcSubscribe(t,e){const r={method:wh(e.protocol).subscribe,params:{topic:t}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r});try{return await await pi(this.relayer.request(r).catch((t=>this.logger.warn(t))),this.subscribeTimeout)?dh(t+this.clientId):null}catch{this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Tl)}return null}async rpcBatchSubscribe(t){if(!t.length)return;const e={method:wh(t[0].relay.protocol).batchSubscribe,params:{topics:t.map((t=>t.topic))}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:e});try{return await await pi(this.relayer.request(e).catch((t=>this.logger.warn(t))),this.subscribeTimeout)}catch{this.relayer.events.emit(Tl)}}async rpcBatchFetchMessages(t){if(!t.length)return;const e={method:wh(t[0].relay.protocol).batchFetchMessages,params:{topics:t.map((t=>t.topic))}};let r;this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:e});try{r=await await pi(this.relayer.request(e).catch((t=>this.logger.warn(t))),this.subscribeTimeout)}catch{this.relayer.events.emit(Tl)}return r}rpcUnsubscribe(t,e,r){const i={method:wh(r.protocol).unsubscribe,params:{topic:t,id:e}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(t,e){this.setSubscription(t,gf(pf({},e),{id:t})),this.pending.delete(e.topic)}onBatchSubscribe(t){t.length&&t.forEach((t=>{this.setSubscription(t.id,pf({},t)),this.pending.delete(t.topic)}))}async onUnsubscribe(t,e,r){this.events.removeAllListeners(e),this.hasSubscription(e,t)&&this.deleteSubscription(e,r),await this.relayer.messages.del(t)}async setRelayerSubscriptions(t){await this.relayer.core.storage.setItem(this.storageKey,t)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(t,e){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:t,subscription:e}),this.addSubscription(t,e)}addSubscription(t,e){this.subscriptions.set(t,pf({},e)),this.topicMap.set(e.topic,t),this.events.emit(Bl,e)}getSubscription(t){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:t});const e=this.subscriptions.get(t);if(!e){const{message:e}=Wh("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(e)}return e}deleteSubscription(t,e){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:t,reason:e});const r=this.getSubscription(t);this.subscriptions.delete(t),this.topicMap.delete(r.topic,t),this.events.emit(jl,gf(pf({},r),{reason:e}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit("subscription_sync")}async reset(){if(this.cached.length){const t=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let e=0;e"u"||!t.length)return;if(this.subscriptions.size){const{message:t}=Wh("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(t){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(t)}}async batchSubscribe(t){if(!t.length)return;const e=await this.rpcBatchSubscribe(t);Jh(e)&&this.onBatchSubscribe(e.map(((e,r)=>gf(pf({},t[r]),{id:e}))))}async batchFetchMessages(t){if(!t.length)return;this.logger.trace(`Fetching batch messages for ${t.length} subscriptions`);const e=await this.rpcBatchFetchMessages(t);e&&e.messages&&(this.pendingBatchMessages=this.pendingBatchMessages.concat(e.messages))}async onConnect(){await this.restart(),this.onEnable()}onDisconnect(){this.onDisable()}async checkPending(){if(!this.initialized||!this.relayer.connected)return;const t=[];this.pending.forEach((e=>{t.push(e)})),await this.batchSubscribe(t),this.pendingBatchMessages.length&&(await this.relayer.handleBatchMessageEvents(this.pendingBatchMessages),this.pendingBatchMessages=[])}registerEventListeners(){this.relayer.core.heartbeat.on(tt,(async()=>{await this.checkPending()})),this.events.on(Bl,(async t=>{const e=Bl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),await this.persist()})),this.events.on(jl,(async t=>{const e=jl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),await this.persist()}))}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}async restartToComplete(){this.restartInProgress&&await new Promise((t=>{const e=setInterval((()=>{this.restartInProgress||(clearInterval(e),t())}),this.pollingInterval)}))}}var yf=Object.defineProperty,vf=Object.getOwnPropertySymbols,wf=Object.prototype.hasOwnProperty,bf=Object.prototype.propertyIsEnumerable,_f=(t,e,r)=>e in t?yf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;class Af extends xt{constructor(t){super(t),this.protocol="wc",this.version=2,this.events=new y.EventEmitter,this.name="relayer",this.transportExplicitlyClosed=!1,this.initialized=!1,this.connectionAttemptInProgress=!1,this.connectionStatusPollingInterval=20,this.staleConnectionErrors=["socket hang up","stalled","interrupted"],this.hasExperiencedNetworkDisruption=!1,this.requestsInFlight=new Map,this.heartBeatTimeout=(0,Y.toMiliseconds)(Y.THIRTY_SECONDS+Y.ONE_SECOND),this.request=async t=>{var e,r;this.logger.debug("Publishing Request Payload");const i=t.id||Pu().toString();await this.toEstablishConnection();try{const n=this.provider.request(t);this.requestsInFlight.set(i,{promise:n,request:t}),this.logger.trace({id:i,method:t.method,topic:null==(e=t.params)?void 0:e.topic},"relayer.request - attempt to publish...");const s=await new Promise((async(t,e)=>{const r=()=>{e(new Error(`relayer.request - publish interrupted, id: ${i}`))};this.provider.on(ql,r);const s=await n;this.provider.off(ql,r),t(s)}));return this.logger.trace({id:i,method:t.method,topic:null==(r=t.params)?void 0:r.topic},"relayer.request - published"),s}catch(t){throw this.logger.debug(`Failed to Publish Request: ${i}`),t}finally{this.requestsInFlight.delete(i)}},this.resetPingTimeout=()=>{if(si())try{clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout((()=>{var t,e,r;null==(r=null==(e=null==(t=this.provider)?void 0:t.connection)?void 0:e.socket)||r.terminate()}),this.heartBeatTimeout)}catch(t){this.logger.warn(t)}},this.onPayloadHandler=t=>{this.onProviderPayload(t),this.resetPingTimeout()},this.onConnectHandler=()=>{this.logger.trace("relayer connected"),this.startPingTimeout(),this.events.emit("relayer_connect")},this.onDisconnectHandler=()=>{this.logger.trace("relayer disconnected"),this.onProviderDisconnect()},this.onProviderErrorHandler=t=>{this.logger.error(t),this.events.emit("relayer_error",t),this.logger.info("Fatal socket error received, closing transport"),this.transportClose()},this.registerProviderListeners=()=>{this.provider.on(Ul,this.onPayloadHandler),this.provider.on(Ll,this.onConnectHandler),this.provider.on(ql,this.onDisconnectHandler),this.provider.on(Dl,this.onProviderErrorHandler)},this.core=t.core,this.logger=typeof t.logger<"u"&&"string"!=typeof t.logger?_t(t.logger,this.name):it()(wt({level:t.logger||"error"})),this.messages=new nf(this.logger,t.core),this.subscriber=new mf(this,this.logger),this.publisher=new sf(this,this.logger),this.relayUrl=t?.relayUrl||Pl,this.projectId=t.projectId,this.bundleId=function(){var t;try{return oi()&&typeof r.g<"u"&&typeof(null==r.g?void 0:r.g.Application)<"u"?null==(t=r.g.Application)?void 0:t.applicationId:void 0}catch{return}}(),this.provider={}}async init(){this.logger.trace("Initialized"),this.registerEventListeners(),await Promise.all([this.messages.init(),this.subscriber.init()]),await this.transportOpen(),this.initialized=!0,setTimeout((async()=>{0===this.subscriber.topics.length&&0===this.subscriber.pending.size&&(this.logger.info("No topics subscribed to after init, closing transport"),await this.transportClose(),this.transportExplicitlyClosed=!1)}),1e4)}get context(){return bt(this.logger)}get connected(){var t,e,r;return 1===(null==(r=null==(e=null==(t=this.provider)?void 0:t.connection)?void 0:e.socket)?void 0:r.readyState)}get connecting(){var t,e,r;return 0===(null==(r=null==(e=null==(t=this.provider)?void 0:t.connection)?void 0:e.socket)?void 0:r.readyState)}async publish(t,e,r){this.isInitialized(),await this.publisher.publish(t,e,r),await this.recordMessageEvent({topic:t,message:e,publishedAt:Date.now()})}async subscribe(t,e){var r;this.isInitialized();let i,n=(null==(r=this.subscriber.topicMap.get(t))?void 0:r[0])||"";const s=e=>{e.topic===t&&(this.subscriber.off(Bl,s),i())};return await Promise.all([new Promise((t=>{i=t,this.subscriber.on(Bl,s)})),new Promise((async r=>{n=await this.subscriber.subscribe(t,e)||n,r()}))]),n}async unsubscribe(t,e){this.isInitialized(),await this.subscriber.unsubscribe(t,e)}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async transportDisconnect(){if(!this.hasExperiencedNetworkDisruption&&this.connected&&this.requestsInFlight.size>0)try{await Promise.all(Array.from(this.requestsInFlight.values()).map((t=>t.promise)))}catch(t){this.logger.warn(t)}this.hasExperiencedNetworkDisruption||this.connected?await pi(this.provider.disconnect(),2e3,"provider.disconnect()").catch((()=>this.onProviderDisconnect())):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,await this.transportDisconnect()}async transportOpen(t){await this.confirmOnlineStateOrThrow(),t&&t!==this.relayUrl&&(this.relayUrl=t,await this.transportDisconnect()),await this.createProvider(),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;try{await new Promise((async(t,e)=>{const r=()=>{this.provider.off(ql,r),e(new Error("Connection interrupted while trying to subscribe"))};this.provider.on(ql,r),await pi(this.provider.connect(),(0,Y.toMiliseconds)(Y.ONE_MINUTE),`Socket stalled when trying to connect to ${this.relayUrl}`).catch((t=>{e(t)})),this.subscriber.start().catch((t=>{this.logger.error(t),this.onDisconnectHandler()})),this.hasExperiencedNetworkDisruption=!1,t()}))}catch(t){this.logger.error(t);const e=t;if(this.hasExperiencedNetworkDisruption=!0,!this.isConnectionStalled(e.message))throw t}finally{this.connectionAttemptInProgress=!1}}async restartTransport(t){this.connectionAttemptInProgress||(this.relayUrl=t||this.relayUrl,await this.confirmOnlineStateOrThrow(),await this.transportClose(),await this.transportOpen())}async confirmOnlineStateOrThrow(){if(!await lu())throw new Error("No internet connection detected. Please restart your network and try again.")}async handleBatchMessageEvents(t){if(0===t?.length)return void this.logger.trace("Batch message events is empty. Ignoring...");const e=t.sort(((t,e)=>t.publishedAt-e.publishedAt));this.logger.trace(`Batch of ${e.length} message events sorted`);for(const t of e)try{await this.onMessageEvent(t)}catch(t){this.logger.warn(t)}this.logger.trace(`Batch of ${e.length} message events processed`)}startPingTimeout(){var t,e,r,i,n;if(si())try{null!=(e=null==(t=this.provider)?void 0:t.connection)&&e.socket&&(null==(n=null==(i=null==(r=this.provider)?void 0:r.connection)?void 0:i.socket)||n.once("ping",(()=>{this.resetPingTimeout()}))),this.resetPingTimeout()}catch(t){this.logger.warn(t)}}isConnectionStalled(t){return this.staleConnectionErrors.some((e=>t.includes(e)))}async createProvider(){this.provider.connection&&this.unregisterProviderListeners();const t=await this.core.crypto.signJWT(this.relayUrl);this.provider=new Hu(new Wu(function({protocol:t,version:e,relayUrl:r,sdkVersion:i,auth:n,projectId:s,useOnCloseEvent:o,bundleId:a}){const h=r.split("?"),u={auth:n,ua:ui(t,e,i),projectId:s,useOnCloseEvent:o||void 0,origin:a||void 0},c=function(t,e){let r=kr.parse(t);return r=ei(ei({},r),e),kr.stringify(r)}(h[1]||"",u);return h[0]+"?"+c}({sdkVersion:"2.14.0",protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:t,useOnCloseEvent:!0,bundleId:this.bundleId}))),this.registerProviderListeners()}async recordMessageEvent(t){const{topic:e,message:r}=t;await this.messages.set(e,r)}async shouldIgnoreMessageEvent(t){const{topic:e,message:r}=t;if(!r||0===r.length)return this.logger.debug(`Ignoring invalid/empty message: ${r}`),!0;if(!await this.subscriber.isSubscribed(e))return this.logger.debug(`Ignoring message for non-subscribed topic ${e}`),!0;const i=this.messages.has(e,r);return i&&this.logger.debug(`Ignoring duplicate message: ${r}`),i}async onProviderPayload(t){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:t}),ju(t)){if(!t.method.endsWith("_subscription"))return;const e=t.params,{topic:r,message:i,publishedAt:n}=e.data,s={topic:r,message:i,publishedAt:n};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(((t,e)=>{for(var r in e||(e={}))wf.call(e,r)&&_f(t,r,e[r]);if(vf)for(var r of vf(e))bf.call(e,r)&&_f(t,r,e[r]);return t})({type:"event",event:e.id},s)),this.events.emit(e.id,s),await this.acknowledgePayload(t),await this.onMessageEvent(s)}else zu(t)&&this.events.emit(Cl,t)}async onMessageEvent(t){await this.shouldIgnoreMessageEvent(t)||(this.events.emit(Rl,t),await this.recordMessageEvent(t))}async acknowledgePayload(t){const e=Cu(t.id,!0);await this.provider.connection.send(e)}unregisterProviderListeners(){this.provider.off(Ul,this.onPayloadHandler),this.provider.off(Ll,this.onConnectHandler),this.provider.off(ql,this.onDisconnectHandler),this.provider.off(Dl,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let t=await lu();!function(t){switch(hi()){case ii.browser:!function(t){!oi()&&ai()&&(window.addEventListener("online",(()=>t(!0))),window.addEventListener("offline",(()=>t(!1))))}(t);break;case ii.reactNative:!function(t){oi()&&typeof r.g<"u"&&null!=r.g&&r.g.NetInfo&&r.g?.NetInfo.addEventListener((e=>t(e?.isConnected)))}(t);case ii.node:}}((async e=>{t!==e&&(t=e,e?await this.restartTransport().catch((t=>this.logger.error(t))):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))}))}async onProviderDisconnect(){await this.subscriber.stop(),this.requestsInFlight.clear(),clearTimeout(this.pingTimeout),this.events.emit("relayer_disconnect"),this.connectionAttemptInProgress=!1,!this.transportExplicitlyClosed&&setTimeout((async()=>{await this.transportOpen().catch((t=>this.logger.error(t)))}),(0,Y.toMiliseconds)(.1))}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}async toEstablishConnection(){await this.confirmOnlineStateOrThrow(),!this.connected&&(this.connectionAttemptInProgress&&await new Promise((t=>{const e=setInterval((()=>{this.connected&&(clearInterval(e),t())}),this.connectionStatusPollingInterval)})),await this.transportOpen())}}var Ef=Object.defineProperty,Sf=Object.getOwnPropertySymbols,Mf=Object.prototype.hasOwnProperty,If=Object.prototype.propertyIsEnumerable,xf=(t,e,r)=>e in t?Ef(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nf=(t,e)=>{for(var r in e||(e={}))Mf.call(e,r)&&xf(t,r,e[r]);if(Sf)for(var r of Sf(e))If.call(e,r)&&xf(t,r,e[r]);return t};class Of extends Nt{constructor(t,e,r,i=Ml,n=void 0){super(t,e,r,i),this.core=t,this.logger=e,this.name=r,this.map=new Map,this.version="0.3",this.cached=[],this.initialized=!1,this.storagePrefix=Ml,this.recentlyDeleted=[],this.recentlyDeletedLimit=200,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach((t=>{this.getKey&&null!==t&&!Qh(t)?this.map.set(this.getKey(t),t):function(t){var e;return null==(e=t?.proposer)?void 0:e.publicKey}(t)?this.map.set(t.id,t):function(t){return t?.topic}(t)&&this.map.set(t.topic,t)})),this.cached=[],this.initialized=!0)},this.set=async(t,e)=>{this.isInitialized(),this.map.has(t)?await this.update(t,e):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:t,value:e}),this.map.set(t,e),await this.persist())},this.get=t=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:t}),this.getData(t)),this.getAll=t=>(this.isInitialized(),t?this.values.filter((e=>Object.keys(t).every((r=>Ju()(e[r],t[r]))))):this.values),this.update=async(t,e)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:t,update:e});const r=Nf(Nf({},this.getData(t)),e);this.map.set(t,r),await this.persist()},this.delete=async(t,e)=>{this.isInitialized(),this.map.has(t)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:t,reason:e}),this.map.delete(t),this.addToRecentlyDeleted(t),await this.persist())},this.logger=_t(e,this.name),this.storagePrefix=i,this.getKey=n}get context(){return bt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.map.size}get keys(){return Array.from(this.map.keys())}get values(){return Array.from(this.map.values())}addToRecentlyDeleted(t){this.recentlyDeleted.push(t),this.recentlyDeleted.length>=this.recentlyDeletedLimit&&this.recentlyDeleted.splice(0,this.recentlyDeletedLimit/2)}async setDataStore(t){await this.core.storage.setItem(this.storageKey,t)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(t){const e=this.map.get(t);if(!e){if(this.recentlyDeleted.includes(t)){const{message:e}=Wh("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${t}`);throw this.logger.error(e),new Error(e)}const{message:e}=Wh("NO_MATCHING_KEY",`${this.name}: ${t}`);throw this.logger.error(e),new Error(e)}return e}async persist(){await this.setDataStore(this.values)}async restore(){try{const t=await this.getDataStore();if(typeof t>"u"||!t.length)return;if(this.map.size){const{message:t}=Wh("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(t){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(t)}}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Pf{constructor(t,e){this.core=t,this.logger=e,this.name="pairing",this.version="0.3",this.events=new(v()),this.initialized=!1,this.storagePrefix=Ml,this.ignoredPayloadTypes=[1],this.registeredMethods=[],this.init=async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))},this.register=({methods:t})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...t])]},this.create=async t=>{this.isInitialized();const e=lh(),r=await this.core.crypto.setSymKey(e),i=yi(Y.FIVE_MINUTES),n={protocol:"irn"},s={topic:r,expiry:i,relay:n,active:!1},o=function(t){return`${t.protocol}:${t.topic}@${t.version}?`+kr.stringify(xh(((t,e)=>_h(t,Ah(e)))(xh({symKey:t.symKey},function(t,e="-"){const r={};return Object.keys(t).forEach((i=>{const n="relay"+e+i;t[i]&&(r[n]=t[i])})),r}(t.relay)),{expiryTimestamp:t.expiryTimestamp}),t.methods?{methods:t.methods.join(",")}:{}))}({protocol:this.core.protocol,version:this.core.version,topic:r,symKey:e,relay:n,expiryTimestamp:i,methods:t?.methods});return this.core.expirer.set(r,i),await this.pairings.set(r,s),await this.core.relayer.subscribe(r),{topic:r,uri:o}},this.pair=async t=>{this.isInitialized(),this.isValidPair(t);const{topic:e,symKey:r,relay:i,expiryTimestamp:n,methods:s}=Oh(t.uri);let o;if(this.pairings.keys.includes(e)&&(o=this.pairings.get(e),o.active))throw new Error(`Pairing already exists: ${e}. Please try again with a new connection URI.`);const a=n||yi(Y.FIVE_MINUTES),h={topic:e,relay:i,expiry:a,active:!1,methods:s};return this.core.expirer.set(e,a),await this.pairings.set(e,h),t.activatePairing&&await this.activate({topic:e}),this.events.emit(Kl,h),this.core.crypto.keychain.has(e)||await this.core.crypto.setSymKey(r,e),await this.core.relayer.subscribe(e,{relay:i}),h},this.activate=async({topic:t})=>{this.isInitialized();const e=yi(Y.THIRTY_DAYS);this.core.expirer.set(t,e),await this.pairings.update(t,{active:!0,expiry:e})},this.ping=async t=>{this.isInitialized(),await this.isValidPing(t);const{topic:e}=t;if(this.pairings.keys.includes(e)){const t=await this.sendRequest(e,"wc_pairingPing",{}),{done:r,resolve:i,reject:n}=di();this.events.once(wi("pairing_ping",t),(({error:t})=>{t?n(t):i()})),await r()}},this.updateExpiry=async({topic:t,expiry:e})=>{this.isInitialized(),await this.pairings.update(t,{expiry:e})},this.updateMetadata=async({topic:t,metadata:e})=>{this.isInitialized(),await this.pairings.update(t,{peerMetadata:e})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async t=>{this.isInitialized(),await this.isValidDisconnect(t);const{topic:e}=t;this.pairings.keys.includes(e)&&(await this.sendRequest(e,"wc_pairingDelete",$h("USER_DISCONNECTED")),await this.deletePairing(e))},this.sendRequest=async(t,e,r)=>{const i=Ru(e,r),n=await this.core.crypto.encode(t,i),s=Fl[e].req;return this.core.history.set(t,i),this.core.relayer.publish(t,n,s),i.id},this.sendResult=async(t,e,r)=>{const i=Cu(t,r),n=await this.core.crypto.encode(e,i),s=await this.core.history.get(e,t),o=Fl[s.request.method].res;await this.core.relayer.publish(e,n,o),await this.core.history.resolve(i)},this.sendError=async(t,e,r)=>{const i=Tu(t,r),n=await this.core.crypto.encode(e,i),s=await this.core.history.get(e,t),o=Fl[s.request.method]?Fl[s.request.method].res:Fl.unregistered_method.res;await this.core.relayer.publish(e,n,o),await this.core.history.resolve(i)},this.deletePairing=async(t,e)=>{await this.core.relayer.unsubscribe(t),await Promise.all([this.pairings.delete(t,$h("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(t),e?Promise.resolve():this.core.expirer.del(t)])},this.cleanup=async()=>{const t=this.pairings.getAll().filter((t=>vi(t.expiry)));await Promise.all(t.map((t=>this.deletePairing(t.topic))))},this.onRelayEventRequest=t=>{const{topic:e,payload:r}=t;switch(r.method){case"wc_pairingPing":return this.onPairingPingRequest(e,r);case"wc_pairingDelete":return this.onPairingDeleteRequest(e,r);default:return this.onUnknownRpcMethodRequest(e,r)}},this.onRelayEventResponse=async t=>{const{topic:e,payload:r}=t,i=(await this.core.history.get(e,r.id)).request.method;return"wc_pairingPing"===i?this.onPairingPingResponse(e,r):this.onUnknownRpcMethodResponse(i)},this.onPairingPingRequest=async(t,e)=>{const{id:r}=e;try{this.isValidPing({topic:t}),await this.sendResult(r,t,!0),this.events.emit("pairing_ping",{id:r,topic:t})}catch(e){await this.sendError(r,t,e),this.logger.error(e)}},this.onPairingPingResponse=(t,e)=>{const{id:r}=e;setTimeout((()=>{Fu(e)?this.events.emit(wi("pairing_ping",r),{}):Ku(e)&&this.events.emit(wi("pairing_ping",r),{error:e.error})}),500)},this.onPairingDeleteRequest=async(t,e)=>{const{id:r}=e;try{this.isValidDisconnect({topic:t}),await this.deletePairing(t),this.events.emit(Hl,{id:r,topic:t})}catch(e){await this.sendError(r,t,e),this.logger.error(e)}},this.onUnknownRpcMethodRequest=async(t,e)=>{const{id:r,method:i}=e;try{if(this.registeredMethods.includes(i))return;const e=$h("WC_METHOD_UNSUPPORTED",i);await this.sendError(r,t,e),this.logger.error(e)}catch(e){await this.sendError(r,t,e),this.logger.error(e)}},this.onUnknownRpcMethodResponse=t=>{this.registeredMethods.includes(t)||this.logger.error($h("WC_METHOD_UNSUPPORTED",t))},this.isValidPair=t=>{var e;if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`pair() params: ${t}`);throw new Error(e)}if(!eu(t.uri)){const{message:e}=Wh("MISSING_OR_INVALID",`pair() uri: ${t.uri}`);throw new Error(e)}const r=Oh(t.uri);if(null==(e=r?.relay)||!e.protocol){const{message:t}=Wh("MISSING_OR_INVALID","pair() uri#relay-protocol");throw new Error(t)}if(null==r||!r.symKey){const{message:t}=Wh("MISSING_OR_INVALID","pair() uri#symKey");throw new Error(t)}if(null!=r&&r.expiryTimestamp&&(0,Y.toMiliseconds)(r?.expiryTimestamp){if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`ping() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidPairingTopic(e)},this.isValidDisconnect=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`disconnect() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidPairingTopic(e)},this.isValidPairingTopic=async t=>{if(!Xh(t,!1)){const{message:e}=Wh("MISSING_OR_INVALID",`pairing topic should be a string: ${t}`);throw new Error(e)}if(!this.pairings.keys.includes(t)){const{message:e}=Wh("NO_MATCHING_KEY",`pairing topic doesn't exist: ${t}`);throw new Error(e)}if(vi(this.pairings.get(t).expiry)){await this.deletePairing(t);const{message:e}=Wh("EXPIRED",`pairing topic: ${t}`);throw new Error(e)}},this.core=t,this.logger=_t(e,this.name),this.pairings=new Of(this.core,this.logger,this.name,this.storagePrefix)}get context(){return bt(this.logger)}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}registerRelayerEvents(){this.core.relayer.on(Rl,(async t=>{const{topic:e,message:r}=t;if(!this.pairings.keys.includes(e)||this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(r)))return;const i=await this.core.crypto.decode(e,r);try{ju(i)?(this.core.history.set(e,i),this.onRelayEventRequest({topic:e,payload:i})):zu(i)&&(await this.core.history.resolve(i),await this.onRelayEventResponse({topic:e,payload:i}),this.core.history.delete(e,i.id))}catch(t){this.logger.error(t)}}))}registerExpirerEvents(){this.core.expirer.on(Yl,(async t=>{const{topic:e}=mi(t.target);e&&this.pairings.keys.includes(e)&&(await this.deletePairing(e,!0),this.events.emit("pairing_expire",{topic:e}))}))}}class Rf extends St{constructor(t,e){super(t,e),this.core=t,this.logger=e,this.records=new Map,this.events=new y.EventEmitter,this.name="history",this.version="0.3",this.cached=[],this.initialized=!1,this.storagePrefix=Ml,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach((t=>this.records.set(t.id,t))),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(t,e,r)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:t,request:e,chainId:r}),this.records.has(e.id))return;const i={id:e.id,topic:t,request:{method:e.method,params:e.params||null},chainId:r,expiry:yi(Y.THIRTY_DAYS)};this.records.set(i.id,i),this.persist(),this.events.emit(Vl,i)},this.resolve=async t=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:t}),!this.records.has(t.id))return;const e=await this.getRecord(t.id);typeof e.response>"u"&&(e.response=Ku(t)?{error:t.error}:{result:t.result},this.records.set(e.id,e),this.persist(),this.events.emit(Gl,e))},this.get=async(t,e)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:t,id:e}),await this.getRecord(e)),this.delete=(t,e)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:e}),this.values.forEach((r=>{if(r.topic===t){if(typeof e<"u"&&r.id!==e)return;this.records.delete(r.id),this.events.emit(Wl,r)}})),this.persist()},this.exists=async(t,e)=>(this.isInitialized(),!!this.records.has(e)&&(await this.getRecord(e)).topic===t),this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.logger=_t(e,this.name)}get context(){return bt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get size(){return this.records.size}get keys(){return Array.from(this.records.keys())}get values(){return Array.from(this.records.values())}get pending(){const t=[];return this.values.forEach((e=>{if(typeof e.response<"u")return;const r={topic:e.topic,request:Ru(e.request.method,e.request.params,e.id),chainId:e.chainId};return t.push(r)})),t}async setJsonRpcRecords(t){await this.core.storage.setItem(this.storageKey,t)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(t){this.isInitialized();const e=this.records.get(t);if(!e){const{message:e}=Wh("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(e)}return e}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit("history_sync")}async restore(){try{const t=await this.getJsonRpcRecords();if(typeof t>"u"||!t.length)return;if(this.records.size){const{message:t}=Wh("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(t){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(t)}}registerEventListeners(){this.events.on(Vl,(t=>{const e=Vl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,record:t})})),this.events.on(Gl,(t=>{const e=Gl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,record:t})})),this.events.on(Wl,(t=>{const e=Wl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,record:t})})),this.core.heartbeat.on(tt,(()=>{this.cleanup()}))}cleanup(){try{this.isInitialized();let t=!1;this.records.forEach((e=>{(0,Y.toMiliseconds)(e.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${e.id}`),this.records.delete(e.id),this.events.emit(Wl,e,!1),t=!0)})),t&&this.persist()}catch(t){this.logger.warn(t)}}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Cf extends Pt{constructor(t,e){super(t,e),this.core=t,this.logger=e,this.expirations=new Map,this.events=new y.EventEmitter,this.name="expirer",this.version="0.3",this.cached=[],this.initialized=!1,this.storagePrefix=Ml,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach((t=>this.expirations.set(t.target,t))),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=t=>{try{const e=this.formatTarget(t);return typeof this.getExpiration(e)<"u"}catch{return!1}},this.set=(t,e)=>{this.isInitialized();const r=this.formatTarget(t),i={target:r,expiry:e};this.expirations.set(r,i),this.checkExpiry(r,i),this.events.emit($l,{target:r,expiration:i})},this.get=t=>{this.isInitialized();const e=this.formatTarget(t);return this.getExpiration(e)},this.del=t=>{if(this.isInitialized(),this.has(t)){const e=this.formatTarget(t),r=this.getExpiration(e);this.expirations.delete(e),this.events.emit(Jl,{target:e,expiration:r})}},this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.logger=_t(e,this.name)}get context(){return bt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.expirations.size}get keys(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}formatTarget(t){if("string"==typeof t)return function(t){return gi("topic",t)}(t);if("number"==typeof t)return function(t){return gi("id",t)}(t);const{message:e}=Wh("UNKNOWN_TYPE","Target type: "+typeof t);throw new Error(e)}async setExpirations(t){await this.core.storage.setItem(this.storageKey,t)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit("expirer_sync")}async restore(){try{const t=await this.getExpirations();if(typeof t>"u"||!t.length)return;if(this.expirations.size){const{message:t}=Wh("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(t){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(t)}}getExpiration(t){const e=this.expirations.get(t);if(!e){const{message:e}=Wh("NO_MATCHING_KEY",`${this.name}: ${t}`);throw this.logger.warn(e),new Error(e)}return e}checkExpiry(t,e){const{expiry:r}=e;(0,Y.toMiliseconds)(r)-Date.now()<=0&&this.expire(t,e)}expire(t,e){this.expirations.delete(t),this.events.emit(Yl,{target:t,expiration:e})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach(((t,e)=>this.checkExpiry(e,t)))}registerEventListeners(){this.core.heartbeat.on(tt,(()=>this.checkExpirations())),this.events.on($l,(t=>{const e=$l;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),this.persist()})),this.events.on(Yl,(t=>{const e=Yl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),this.persist()})),this.events.on(Jl,(t=>{const e=Jl;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),this.persist()}))}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Tf extends Rt{constructor(t,e){super(t,e),this.projectId=t,this.logger=e,this.name=Ql,this.initialized=!1,this.queue=[],this.verifyDisabled=!1,this.init=async t=>{if(this.verifyDisabled||oi()||!ai())return;const e=this.getVerifyUrl(t?.verifyUrl);this.verifyUrl!==e&&this.removeIframe(),this.verifyUrl=e;try{await this.createIframe()}catch(t){this.logger.info(`Verify iframe failed to load: ${this.verifyUrl}`),this.logger.info(t),this.verifyDisabled=!0}},this.register=async t=>{this.initialized?this.sendPost(t.attestationId):(this.addToQueue(t.attestationId),await this.init())},this.resolve=async t=>{if(this.isDevEnv)return"";const e=this.getVerifyUrl(t?.verifyUrl);return this.fetchAttestation(t.attestationId,e)},this.fetchAttestation=async(t,e)=>{this.logger.info(`resolving attestation: ${t} from url: ${e}`);const r=this.startAbortTimer(5*Y.ONE_SECOND),i=await fetch(`${e}/attestation/${t}`,{signal:this.abortController.signal});return clearTimeout(r),200===i.status?await i.json():void 0},this.addToQueue=t=>{this.queue.push(t)},this.processQueue=()=>{0!==this.queue.length&&(this.queue.forEach((t=>this.sendPost(t))),this.queue=[])},this.sendPost=t=>{var e;try{if(!this.iframe)return;null==(e=this.iframe.contentWindow)||e.postMessage(t,"*"),this.logger.info(`postMessage sent: ${t} ${this.verifyUrl}`)}catch{}},this.createIframe=async()=>{let t;const e=r=>{"verify_ready"===r.data&&(this.onInit(),window.removeEventListener("message",e),t())};await Promise.race([new Promise((r=>{const i=document.getElementById(Ql);if(i)return this.iframe=i,this.onInit(),r();window.addEventListener("message",e);const n=document.createElement("iframe");n.id=Ql,n.src=`${this.verifyUrl}/${this.projectId}`,n.style.display="none",document.body.append(n),this.iframe=n,t=r})),new Promise(((t,r)=>setTimeout((()=>{window.removeEventListener("message",e),r("verify iframe load timeout")}),(0,Y.toMiliseconds)(Y.FIVE_SECONDS))))])},this.onInit=()=>{this.initialized=!0,this.processQueue()},this.removeIframe=()=>{this.iframe&&(this.iframe.remove(),this.iframe=void 0,this.initialized=!1)},this.getVerifyUrl=t=>{let e=t||Zl;return tf.includes(e)||(this.logger.info(`verify url: ${e}, not included in trusted list, assigning default: ${Zl}`),e=Zl),e},this.logger=_t(e,this.name),this.verifyUrl=Zl,this.abortController=new AbortController,this.isDevEnv=si()&&process.env.IS_VITEST}get context(){return bt(this.logger)}startAbortTimer(t){return this.abortController=new AbortController,setTimeout((()=>this.abortController.abort()),(0,Y.toMiliseconds)(t))}}class kf extends Ct{constructor(t,e){super(t,e),this.projectId=t,this.logger=e,this.context="echo",this.registerDeviceToken=async t=>{const{clientId:e,token:r,notificationType:i,enableEncrypted:n=!1}=t,s=`https://echo.walletconnect.com/${this.projectId}/clients`;await Qu()(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:e,type:i,token:r,always_raw:n})})},this.logger=_t(e,this.context)}}var Uf=Object.defineProperty,Lf=Object.getOwnPropertySymbols,qf=Object.prototype.hasOwnProperty,Df=Object.prototype.propertyIsEnumerable,Bf=(t,e,r)=>e in t?Uf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jf=(t,e)=>{for(var r in e||(e={}))qf.call(e,r)&&Bf(t,r,e[r]);if(Lf)for(var r of Lf(e))Df.call(e,r)&&Bf(t,r,e[r]);return t};class zf extends Et{constructor(t){var e;super(t),this.protocol="wc",this.version=2,this.name=Sl,this.events=new y.EventEmitter,this.initialized=!1,this.on=(t,e)=>this.events.on(t,e),this.once=(t,e)=>this.events.once(t,e),this.off=(t,e)=>this.events.off(t,e),this.removeListener=(t,e)=>this.events.removeListener(t,e),this.projectId=t?.projectId,this.relayUrl=t?.relayUrl||Pl,this.customStoragePrefix=null!=t&&t.customStoragePrefix?`:${t.customStoragePrefix}`:"";const r=wt({level:"string"==typeof t?.logger&&t.logger?t.logger:"error"}),{logger:i,chunkLoggerController:n}=At({opts:r,maxSizeInBytes:t?.maxLogBlobSizeInBytes,loggerOverride:t?.logger});this.logChunkController=n,null!=(e=this.logChunkController)&&e.downloadLogsBlobInBrowser&&(window.downloadLogsBlobInBrowser=async()=>{var t,e;null!=(t=this.logChunkController)&&t.downloadLogsBlobInBrowser&&(null==(e=this.logChunkController)||e.downloadLogsBlobInBrowser({clientId:await this.crypto.getClientId()}))}),this.logger=_t(i,this.name),this.heartbeat=new et,this.crypto=new rf(this,this.logger,t?.keychain),this.history=new Rf(this,this.logger),this.expirer=new Cf(this,this.logger),this.storage=null!=t&&t.storage?t.storage:new J(jf(jf({},Il),t?.storageOptions)),this.relayer=new Af({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new Pf(this,this.logger),this.verify=new Tf(this.projectId||"",this.logger),this.echoClient=new kf(this.projectId||"",this.logger)}static async init(t){const e=new zf(t);await e.initialize();const r=await e.crypto.getClientId();return await e.storage.setItem("WALLETCONNECT_CLIENT_ID",r),e}get context(){return bt(this.logger)}async start(){this.initialized||await this.initialize()}async getLogsBlob(){var t;return null==(t=this.logChunkController)?void 0:t.logsToBlob({clientId:await this.crypto.getClientId()})}async initialize(){this.logger.trace("Initialized");try{await this.crypto.init(),await this.history.init(),await this.expirer.init(),await this.relayer.init(),await this.heartbeat.init(),await this.pairing.init(),this.initialized=!0,this.logger.info("Core Initialization Success")}catch(t){throw this.logger.warn(`Core Initialization Failure at epoch ${Date.now()}`,t),this.logger.error(t.message),t}}}const Ff=zf;let Kf=!1,Hf=!1;const Vf={debug:1,default:2,info:2,warning:3,error:4,off:5};let Gf=Vf.default,Wf=null;const $f=function(){try{const t=[];if(["NFD","NFC","NFKD","NFKC"].forEach((e=>{try{if("test"!=="test".normalize(e))throw new Error("bad normalize")}catch(r){t.push(e)}})),t.length)throw new Error("missing "+t.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(t){return t.message}return null}();var Jf,Yf;!function(t){t.DEBUG="DEBUG",t.INFO="INFO",t.WARNING="WARNING",t.ERROR="ERROR",t.OFF="OFF"}(Jf||(Jf={})),function(t){t.UNKNOWN_ERROR="UNKNOWN_ERROR",t.NOT_IMPLEMENTED="NOT_IMPLEMENTED",t.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",t.NETWORK_ERROR="NETWORK_ERROR",t.SERVER_ERROR="SERVER_ERROR",t.TIMEOUT="TIMEOUT",t.BUFFER_OVERRUN="BUFFER_OVERRUN",t.NUMERIC_FAULT="NUMERIC_FAULT",t.MISSING_NEW="MISSING_NEW",t.INVALID_ARGUMENT="INVALID_ARGUMENT",t.MISSING_ARGUMENT="MISSING_ARGUMENT",t.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",t.CALL_EXCEPTION="CALL_EXCEPTION",t.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",t.NONCE_EXPIRED="NONCE_EXPIRED",t.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",t.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",t.TRANSACTION_REPLACED="TRANSACTION_REPLACED",t.ACTION_REJECTED="ACTION_REJECTED"}(Yf||(Yf={}));const Qf="0123456789abcdef";class Xf{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const r=t.toLowerCase();null==Vf[r]&&this.throwArgumentError("invalid log level name","logLevel",t),Gf>Vf[r]||console.log.apply(console,e)}debug(...t){this._log(Xf.levels.DEBUG,t)}info(...t){this._log(Xf.levels.INFO,t)}warn(...t){this._log(Xf.levels.WARNING,t)}makeError(t,e,r){if(Hf)return this.makeError("censored error",e,{});e||(e=Xf.errors.UNKNOWN_ERROR),r||(r={});const i=[];Object.keys(r).forEach((t=>{const e=r[t];try{if(e instanceof Uint8Array){let r="";for(let t=0;t>4],r+=Qf[15&e[t]];i.push(t+"=Uint8Array(0x"+r+")")}else i.push(t+"="+JSON.stringify(e))}catch(e){i.push(t+"="+JSON.stringify(r[t].toString()))}})),i.push(`code=${e}`),i.push(`version=${this.version}`);const n=t;let s="";switch(e){case Yf.NUMERIC_FAULT:{s="NUMERIC_FAULT";const e=t;switch(e){case"overflow":case"underflow":case"division-by-zero":s+="-"+e;break;case"negative-power":case"negative-width":s+="-unsupported";break;case"unbound-bitwise-result":s+="-unbound-result"}break}case Yf.CALL_EXCEPTION:case Yf.INSUFFICIENT_FUNDS:case Yf.MISSING_NEW:case Yf.NONCE_EXPIRED:case Yf.REPLACEMENT_UNDERPRICED:case Yf.TRANSACTION_REPLACED:case Yf.UNPREDICTABLE_GAS_LIMIT:s=e}s&&(t+=" [ See: https://links.ethers.org/v5-errors-"+s+" ]"),i.length&&(t+=" ("+i.join(", ")+")");const o=new Error(t);return o.reason=n,o.code=e,Object.keys(r).forEach((function(t){o[t]=r[t]})),o}throwError(t,e,r){throw this.makeError(t,e,r)}throwArgumentError(t,e,r){return this.throwError(t,Xf.errors.INVALID_ARGUMENT,{argument:e,value:r})}assert(t,e,r,i){t||this.throwError(e,r,i)}assertArgument(t,e,r,i){t||this.throwArgumentError(e,r,i)}checkNormalize(t){null==t&&(t="platform missing String.prototype.normalize"),$f&&this.throwError("platform missing String.prototype.normalize",Xf.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:$f})}checkSafeUint53(t,e){"number"==typeof t&&(null==e&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,Xf.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,Xf.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,r){r=r?": "+r:"",te&&this.throwError("too many arguments"+r,Xf.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){t!==Object&&null!=t||this.throwError("missing new",Xf.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",Xf.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):t!==Object&&null!=t||this.throwError("missing new",Xf.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return Wf||(Wf=new Xf("logger/5.7.0")),Wf}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",Xf.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),Kf){if(!t)return;this.globalLogger().throwError("error censorship permanent",Xf.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}Hf=!!t,Kf=!!e}static setLogLevel(t){const e=Vf[t.toLowerCase()];null!=e?Gf=e:Xf.globalLogger().warn("invalid log level - "+t)}static from(t){return new Xf(t)}}Xf.errors=Yf,Xf.levels=Jf;const Zf=new Xf("bytes/5.7.0");function td(t){return!!t.toHexString}function ed(t){return t.slice||(t.slice=function(){const e=Array.prototype.slice.call(arguments);return ed(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}function rd(t){return"number"==typeof t&&t==t&&t%1==0}function id(t){if(null==t)return!1;if(t.constructor===Uint8Array)return!0;if("string"==typeof t)return!1;if(!rd(t.length)||t.length<0)return!1;for(let e=0;e=256)return!1}return!0}function nd(t,e){if(e||(e={}),"number"==typeof t){Zf.checkSafeUint53(t,"invalid arrayify value");const e=[];for(;t;)e.unshift(255&t),t=parseInt(String(t/256));return 0===e.length&&e.push(0),ed(new Uint8Array(e))}if(e.allowMissingPrefix&&"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),td(t)&&(t=t.toHexString()),sd(t)){let r=t.substring(2);r.length%2&&("left"===e.hexPad?r="0"+r:"right"===e.hexPad?r+="0":Zf.throwArgumentError("hex data is odd-length","value",t));const i=[];for(let t=0;t>4]+od[15&i]}return e}return Zf.throwArgumentError("invalid hexlify value","value",t)}function hd(t,e,r){return"string"!=typeof t?t=ad(t):(!sd(t)||t.length%2)&&Zf.throwArgumentError("invalid hexData","value",t),e=2+2*e,null!=r?"0x"+t.substring(e,2+2*r):"0x"+t.substring(e)}function ud(t,e){for("string"!=typeof t?t=ad(t):sd(t)||Zf.throwArgumentError("invalid hex string","value",t),t.length>2*e+2&&Zf.throwArgumentError("value out of range","value",arguments[1]);t.length<2*e+2;)t="0x0"+t.substring(2);return t}function cd(t){const e={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(sd(r=t)&&!(r.length%2)||id(r)){let r=nd(t);64===r.length?(e.v=27+(r[32]>>7),r[32]&=127,e.r=ad(r.slice(0,32)),e.s=ad(r.slice(32,64))):65===r.length?(e.r=ad(r.slice(0,32)),e.s=ad(r.slice(32,64)),e.v=r[64]):Zf.throwArgumentError("invalid signature string","signature",t),e.v<27&&(0===e.v||1===e.v?e.v+=27:Zf.throwArgumentError("signature invalid v byte","signature",t)),e.recoveryParam=1-e.v%2,e.recoveryParam&&(r[32]|=128),e._vs=ad(r.slice(32,64))}else{if(e.r=t.r,e.s=t.s,e.v=t.v,e.recoveryParam=t.recoveryParam,e._vs=t._vs,null!=e._vs){const r=function(t,e){(t=nd(t)).length>e&&Zf.throwArgumentError("value out of range","value",arguments[0]);const r=new Uint8Array(e);return r.set(t,e-t.length),ed(r)}(nd(e._vs),32);e._vs=ad(r);const i=r[0]>=128?1:0;null==e.recoveryParam?e.recoveryParam=i:e.recoveryParam!==i&&Zf.throwArgumentError("signature recoveryParam mismatch _vs","signature",t),r[0]&=127;const n=ad(r);null==e.s?e.s=n:e.s!==n&&Zf.throwArgumentError("signature v mismatch _vs","signature",t)}if(null==e.recoveryParam)null==e.v?Zf.throwArgumentError("signature missing v and recoveryParam","signature",t):0===e.v||1===e.v?e.recoveryParam=e.v:e.recoveryParam=1-e.v%2;else if(null==e.v)e.v=27+e.recoveryParam;else{const r=0===e.v||1===e.v?e.v:1-e.v%2;e.recoveryParam!==r&&Zf.throwArgumentError("signature recoveryParam mismatch v","signature",t)}null!=e.r&&sd(e.r)?e.r=ud(e.r,32):Zf.throwArgumentError("signature missing or invalid r","signature",t),null!=e.s&&sd(e.s)?e.s=ud(e.s,32):Zf.throwArgumentError("signature missing or invalid s","signature",t);const r=nd(e.s);r[0]>=128&&Zf.throwArgumentError("signature s out of range","signature",t),e.recoveryParam&&(r[0]|=128);const i=ad(r);e._vs&&(sd(e._vs)||Zf.throwArgumentError("signature invalid _vs","signature",t),e._vs=ud(e._vs,32)),null==e._vs?e._vs=i:e._vs!==i&&Zf.throwArgumentError("signature _vs mismatch v and s","signature",t)}var r;return e.yParityAndS=e._vs,e.compact=e.r+e.yParityAndS.substring(2),e}var ld=r(1176),fd=r.n(ld);function dd(t){return"0x"+fd().keccak_256(nd(t))}const pd=new Xf("strings/5.7.0");var gd,md;function yd(t,e,r,i,n){if(t===md.BAD_PREFIX||t===md.UNEXPECTED_CONTINUE){let t=0;for(let i=e+1;i>6==2;i++)t++;return t}return t===md.OVERRUN?r.length-e-1:0}function vd(t,e=gd.current){e!=gd.current&&(pd.checkNormalize(),t=t.normalize(e));let r=[];for(let e=0;e>6|192),r.push(63&i|128);else if(55296==(64512&i)){e++;const n=t.charCodeAt(e);if(e>=t.length||56320!=(64512&n))throw new Error("invalid utf-8 string");const s=65536+((1023&i)<<10)+(1023&n);r.push(s>>18|240),r.push(s>>12&63|128),r.push(s>>6&63|128),r.push(63&s|128)}else r.push(i>>12|224),r.push(i>>6&63|128),r.push(63&i|128)}return nd(r)}!function(t){t.current="",t.NFC="NFC",t.NFD="NFD",t.NFKC="NFKC",t.NFKD="NFKD"}(gd||(gd={})),function(t){t.UNEXPECTED_CONTINUE="unexpected continuation byte",t.BAD_PREFIX="bad codepoint prefix",t.OVERRUN="string overrun",t.MISSING_CONTINUE="missing continuation byte",t.OUT_OF_RANGE="out of UTF-8 range",t.UTF16_SURROGATE="UTF-16 surrogate",t.OVERLONG="overlong representation"}(md||(md={})),Object.freeze({error:function(t,e,r,i,n){return pd.throwArgumentError(`invalid codepoint at offset ${e}; ${t}`,"bytes",r)},ignore:yd,replace:function(t,e,r,i,n){return t===md.OVERLONG?(i.push(n),0):(i.push(65533),yd(t,e,r))}});const wd="Ethereum Signed Message:\n";function bd(t){return"string"==typeof t&&(t=vd(t)),dd(function(t){const e=t.map((t=>nd(t))),r=e.reduce(((t,e)=>t+e.length),0),i=new Uint8Array(r);return e.reduce(((t,e)=>(i.set(e,t),t+e.length)),0),ed(i)}([vd(wd),vd(String(t.length)),t]))}var _d=r(9404),Ad=r.n(_d),Ed=Ad().BN;new Xf("bignumber/5.7.0");const Sd=new Xf("address/5.7.0");function Md(t){sd(t,20)||Sd.throwArgumentError("invalid address","address",t);const e=(t=t.toLowerCase()).substring(2).split(""),r=new Uint8Array(40);for(let t=0;t<40;t++)r[t]=e[t].charCodeAt(0);const i=nd(dd(r));for(let t=0;t<40;t+=2)i[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&i[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const Id={};for(let t=0;t<10;t++)Id[String(t)]=String(t);for(let t=0;t<26;t++)Id[String.fromCharCode(65+t)]=String(10+t);const xd=Math.floor((Nd=9007199254740991,Math.log10?Math.log10(Nd):Math.log(Nd)/Math.LN10));var Nd;function Od(t){let e=null;if("string"!=typeof t&&Sd.throwArgumentError("invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==t.substring(0,2)&&(t="0x"+t),e=Md(t),t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&e!==t&&Sd.throwArgumentError("bad address checksum","address",t);else if(t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(t.substring(2,4)!==function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>Id[t])).join("");for(;e.length>=xd;){let t=e.substring(0,xd);e=parseInt(t,10)%97+e.substring(t.length)}let r=String(98-parseInt(e,10)%97);for(;r.length<2;)r="0"+r;return r}(t)&&Sd.throwArgumentError("bad icap checksum","address",t),r=t.substring(4),e=new Ed(r,36).toString(16);e.length<40;)e="0"+e;e=Md("0x"+e)}else Sd.throwArgumentError("invalid address","address",t);var r;return e}var Pd=r(7952),Rd=r.n(Pd);function Cd(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==r.g?r.g:"undefined"!=typeof self&&self;var Td=kd;function kd(t,e){if(!t)throw new Error(e||"Assertion failed")}kd.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var Ud=Cd((function(t,e){var r=e;function i(t){return 1===t.length?"0"+t:t}function n(t){for(var e="",r=0;r>8,o=255&n;s?r.push(s,o):r.push(o)}return r},r.zero2=i,r.toHex=n,r.encode=function(t,e){return"hex"===e?n(t):t}})),Ld=Cd((function(t,e){var r=e;r.assert=Td,r.toArray=Ud.toArray,r.zero2=Ud.zero2,r.toHex=Ud.toHex,r.encode=Ud.encode,r.getNAF=function(t,e,r){var i=new Array(Math.max(t.bitLength(),r)+1);i.fill(0);for(var n=1<(n>>1)-1?(n>>1)-h:h,s.isubn(a)):a=0,i[o]=a,s.iushrn(1)}return i},r.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var i,n=0,s=0;t.cmpn(-n)>0||e.cmpn(-s)>0;){var o,a,h=t.andln(3)+n&3,u=e.andln(3)+s&3;3===h&&(h=-1),3===u&&(u=-1),o=1&h?3!=(i=t.andln(7)+n&7)&&5!==i||2!==u?h:-h:0,r[0].push(o),a=1&u?3!=(i=e.andln(7)+s&7)&&5!==i||2!==h?u:-u:0,r[1].push(a),2*n===o+1&&(n=1-n),2*s===a+1&&(s=1-s),t.iushrn(1),e.iushrn(1)}return r},r.cachedProperty=function(t,e,r){var i="_"+e;t.prototype[e]=function(){return void 0!==this[i]?this[i]:this[i]=r.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new(Ad())(t,"hex","le")}})),qd=Ld.getNAF,Dd=Ld.getJSF,Bd=Ld.assert;function jd(t,e){this.type=t,this.p=new(Ad())(e.p,16),this.red=e.prime?Ad().red(e.prime):Ad().mont(this.p),this.zero=new(Ad())(0).toRed(this.red),this.one=new(Ad())(1).toRed(this.red),this.two=new(Ad())(2).toRed(this.red),this.n=e.n&&new(Ad())(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var zd=jd;function Fd(t,e){this.curve=t,this.type=e,this.precomputed=null}jd.prototype.point=function(){throw new Error("Not implemented")},jd.prototype.validate=function(){throw new Error("Not implemented")},jd.prototype._fixedNafMul=function(t,e){Bd(t.precomputed);var r=t._getDoubles(),i=qd(e,1,this._bitLength),n=(1<=s;h--)o=(o<<1)+i[h];a.push(o)}for(var u=this.jpoint(null,null,null),c=this.jpoint(null,null,null),l=n;l>0;l--){for(s=0;s=0;a--){for(var h=0;a>=0&&0===s[a];a--)h++;if(a>=0&&h++,o=o.dblp(h),a<0)break;var u=s[a];Bd(0!==u),o="affine"===t.type?u>0?o.mixedAdd(n[u-1>>1]):o.mixedAdd(n[-u-1>>1].neg()):u>0?o.add(n[u-1>>1]):o.add(n[-u-1>>1].neg())}return"affine"===t.type?o.toP():o},jd.prototype._wnafMulAdd=function(t,e,r,i,n){var s,o,a,h=this._wnafT1,u=this._wnafT2,c=this._wnafT3,l=0;for(s=0;s=1;s-=2){var d=s-1,p=s;if(1===h[d]&&1===h[p]){var g=[e[d],null,null,e[p]];0===e[d].y.cmp(e[p].y)?(g[1]=e[d].add(e[p]),g[2]=e[d].toJ().mixedAdd(e[p].neg())):0===e[d].y.cmp(e[p].y.redNeg())?(g[1]=e[d].toJ().mixedAdd(e[p]),g[2]=e[d].add(e[p].neg())):(g[1]=e[d].toJ().mixedAdd(e[p]),g[2]=e[d].toJ().mixedAdd(e[p].neg()));var m=[-3,-1,-5,-7,0,7,5,1,3],y=Dd(r[d],r[p]);for(l=Math.max(y[0].length,l),c[d]=new Array(l),c[p]=new Array(l),o=0;o=0;s--){for(var A=0;s>=0;){var E=!0;for(o=0;o=0&&A++,b=b.dblp(A),s<0)break;for(o=0;o0?a=u[o][S-1>>1]:S<0&&(a=u[o][-S-1>>1].neg()),b="affine"===a.type?b.mixedAdd(a):b.add(a))}}for(s=0;s=Math.ceil((t.bitLength()+1)/e.step)},Fd.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],i=this,n=0;n=0&&(s=e,o=r),i.negative&&(i=i.neg(),n=n.neg()),s.negative&&(s=s.neg(),o=o.neg()),[{a:i,b:n},{a:s,b:o}]},Vd.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],i=e[1],n=i.b.mul(t).divRound(this.n),s=r.b.neg().mul(t).divRound(this.n),o=n.mul(r.a),a=s.mul(i.a),h=n.mul(r.b),u=s.mul(i.b);return{k1:t.sub(o).sub(a),k2:h.add(u).neg()}},Vd.prototype.pointFromX=function(t,e){(t=new(Ad())(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),i=r.redSqrt();if(0!==i.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var n=i.fromRed().isOdd();return(e&&!n||!e&&n)&&(i=i.redNeg()),this.point(t,i)},Vd.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,i=this.a.redMul(e),n=e.redSqr().redMul(e).redIAdd(i).redIAdd(this.b);return 0===r.redSqr().redISub(n).cmpn(0)},Vd.prototype._endoWnafMulAdd=function(t,e,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,s=0;s":""},Wd.prototype.isInfinity=function(){return this.inf},Wd.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),i=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,i)},Wd.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),i=t.redInvm(),n=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(i),s=n.redSqr().redISub(this.x.redAdd(this.x)),o=n.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)},Wd.prototype.getX=function(){return this.x.fromRed()},Wd.prototype.getY=function(){return this.y.fromRed()},Wd.prototype.mul=function(t){return t=new(Ad())(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},Wd.prototype.mulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},Wd.prototype.jmulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},Wd.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},Wd.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,i=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(i)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(i)}}}return e},Wd.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},Kd($d,zd.BasePoint),Vd.prototype.jpoint=function(t,e,r){return new $d(this,t,e,r)},$d.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),i=this.y.redMul(e).redMul(t);return this.curve.point(r,i)},$d.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},$d.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(e),n=t.x.redMul(r),s=this.y.redMul(e.redMul(t.z)),o=t.y.redMul(r.redMul(this.z)),a=i.redSub(n),h=s.redSub(o);if(0===a.cmpn(0))return 0!==h.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var u=a.redSqr(),c=u.redMul(a),l=i.redMul(u),f=h.redSqr().redIAdd(c).redISub(l).redISub(l),d=h.redMul(l.redISub(f)).redISub(s.redMul(c)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(f,d,p)},$d.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,i=t.x.redMul(e),n=this.y,s=t.y.redMul(e).redMul(this.z),o=r.redSub(i),a=n.redSub(s);if(0===o.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var h=o.redSqr(),u=h.redMul(o),c=r.redMul(h),l=a.redSqr().redIAdd(u).redISub(c).redISub(c),f=a.redMul(c.redISub(l)).redISub(n.redMul(u)),d=this.z.redMul(o);return this.curve.jpoint(l,f,d)},$d.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e=0)return!1;if(r.redIAdd(n),0===this.x.cmp(r))return!0}},$d.prototype.inspect=function(){return this.isInfinity()?"":""},$d.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var Jd=Cd((function(t,e){var r=e;r.base=zd,r.short=Gd,r.mont=null,r.edwards=null})),Yd=Cd((function(t,e){var r,i=e,n=Ld.assert;function s(t){"short"===t.type?this.curve=new Jd.short(t):"edwards"===t.type?this.curve=new Jd.edwards(t):this.curve=new Jd.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,n(this.g.validate(),"Invalid curve"),n(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function o(t,e){Object.defineProperty(i,t,{configurable:!0,enumerable:!0,get:function(){var r=new s(e);return Object.defineProperty(i,t,{configurable:!0,enumerable:!0,value:r}),r}})}i.PresetCurve=s,o("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:Rd().sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),o("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:Rd().sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),o("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:Rd().sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),o("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:Rd().sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),o("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:Rd().sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),o("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:Rd().sha256,gRed:!1,g:["9"]}),o("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:Rd().sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{r=null.crash()}catch(t){r=void 0}o("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:Rd().sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",r]})}));function Qd(t){if(!(this instanceof Qd))return new Qd(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=Ud.toArray(t.entropy,t.entropyEnc||"hex"),r=Ud.toArray(t.nonce,t.nonceEnc||"hex"),i=Ud.toArray(t.pers,t.persEnc||"hex");Td(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}var Xd=Qd;Qd.prototype._init=function(t,e,r){var i=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},Qd.prototype.generate=function(t,e,r,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(i=r,r=e,e=null),r&&(r=Ud.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length"};var rp=Ld.assert;function ip(t,e){if(t instanceof ip)return t;this._importDER(t,e)||(rp(t.r&&t.s,"Signature without r or s"),this.r=new(Ad())(t.r,16),this.s=new(Ad())(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var np=ip;function sp(){this.place=0}function op(t,e){var r=t[e.place++];if(!(128&r))return r;var i=15&r;if(0===i||i>4)return!1;for(var n=0,s=0,o=e.place;s>>=0;return!(n<=127)&&(e.place=o,n)}function ap(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}ip.prototype._importDER=function(t,e){t=Ld.toArray(t,e);var r=new sp;if(48!==t[r.place++])return!1;var i=op(t,r);if(!1===i)return!1;if(i+r.place!==t.length)return!1;if(2!==t[r.place++])return!1;var n=op(t,r);if(!1===n)return!1;var s=t.slice(r.place,n+r.place);if(r.place+=n,2!==t[r.place++])return!1;var o=op(t,r);if(!1===o)return!1;if(t.length!==o+r.place)return!1;var a=t.slice(r.place,o+r.place);if(0===s[0]){if(!(128&s[1]))return!1;s=s.slice(1)}if(0===a[0]){if(!(128&a[1]))return!1;a=a.slice(1)}return this.r=new(Ad())(s),this.s=new(Ad())(a),this.recoveryParam=null,!0},ip.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=ap(e),r=ap(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];hp(i,e.length),(i=i.concat(e)).push(2),hp(i,r.length);var n=i.concat(r),s=[48];return hp(s,n.length),s=s.concat(n),Ld.encode(s,t)};var up=function(){throw new Error("unsupported")},cp=Ld.assert;function lp(t){if(!(this instanceof lp))return new lp(t);"string"==typeof t&&(cp(Object.prototype.hasOwnProperty.call(Yd,t),"Unknown curve "+t),t=Yd[t]),t instanceof Yd.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}var fp=lp;lp.prototype.keyPair=function(t){return new ep(this,t)},lp.prototype.keyFromPrivate=function(t,e){return ep.fromPrivate(this,t,e)},lp.prototype.keyFromPublic=function(t,e){return ep.fromPublic(this,t,e)},lp.prototype.genKeyPair=function(t){t||(t={});for(var e=new Xd({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||up(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),r=this.n.byteLength(),i=this.n.sub(new(Ad())(2));;){var n=new(Ad())(e.generate(r));if(!(n.cmp(i)>0))return n.iaddn(1),this.keyFromPrivate(n)}},lp.prototype._truncateToN=function(t,e){var r=8*t.byteLength()-this.n.bitLength();return r>0&&(t=t.ushrn(r)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},lp.prototype.sign=function(t,e,r,i){"object"==typeof r&&(i=r,r=null),i||(i={}),e=this.keyFromPrivate(e,r),t=this._truncateToN(new(Ad())(t,16));for(var n=this.n.byteLength(),s=e.getPrivate().toArray("be",n),o=t.toArray("be",n),a=new Xd({hash:this.hash,entropy:s,nonce:o,pers:i.pers,persEnc:i.persEnc||"utf8"}),h=this.n.sub(new(Ad())(1)),u=0;;u++){var c=i.k?i.k(u):new(Ad())(a.generate(this.n.byteLength()));if(!((c=this._truncateToN(c,!0)).cmpn(1)<=0||c.cmp(h)>=0)){var l=this.g.mul(c);if(!l.isInfinity()){var f=l.getX(),d=f.umod(this.n);if(0!==d.cmpn(0)){var p=c.invm(this.n).mul(d.mul(e.getPrivate()).iadd(t));if(0!==(p=p.umod(this.n)).cmpn(0)){var g=(l.getY().isOdd()?1:0)|(0!==f.cmp(d)?2:0);return i.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),g^=1),new np({r:d,s:p,recoveryParam:g})}}}}}},lp.prototype.verify=function(t,e,r,i){t=this._truncateToN(new(Ad())(t,16)),r=this.keyFromPublic(r,i);var n=(e=new np(e,"hex")).r,s=e.s;if(n.cmpn(1)<0||n.cmp(this.n)>=0)return!1;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;var o,a=s.invm(this.n),h=a.mul(t).umod(this.n),u=a.mul(n).umod(this.n);return this.curve._maxwellTrick?!(o=this.g.jmulAdd(h,r.getPublic(),u)).isInfinity()&&o.eqXToP(n):!(o=this.g.mulAdd(h,r.getPublic(),u)).isInfinity()&&0===o.getX().umod(this.n).cmp(n)},lp.prototype.recoverPubKey=function(t,e,r,i){cp((3&r)===r,"The recovery param is more than two bits"),e=new np(e,i);var n=this.n,s=new(Ad())(t),o=e.r,a=e.s,h=1&r,u=r>>1;if(o.cmp(this.curve.p.umod(this.curve.n))>=0&&u)throw new Error("Unable to find sencond key candinate");o=u?this.curve.pointFromX(o.add(this.curve.n),h):this.curve.pointFromX(o,h);var c=e.r.invm(n),l=n.sub(s).mul(c).umod(n),f=a.mul(c).umod(n);return this.g.mulAdd(l,o,f)},lp.prototype.getKeyRecoveryParam=function(t,e,r,i){if(null!==(e=new np(e,i)).recoveryParam)return e.recoveryParam;for(var n=0;n<4;n++){var s;try{s=this.recoverPubKey(t,e,n)}catch(t){continue}if(s.eq(r))return n}throw new Error("Unable to find valid recovery factor")};var dp=Cd((function(t,e){var r=e;r.version="6.5.4",r.utils=Ld,r.rand=function(){throw new Error("unsupported")},r.curve=Jd,r.curves=Yd,r.ec=fp,r.eddsa=null})).ec;function pp(t,e,r){Object.defineProperty(t,e,{enumerable:!0,value:r,writable:!1})}new Xf("properties/5.7.0");const gp=new Xf("signing-key/5.7.0");let mp=null;function yp(){return mp||(mp=new dp("secp256k1")),mp}class vp{constructor(t){pp(this,"curve","secp256k1"),pp(this,"privateKey",ad(t)),32!==function(t){if("string"!=typeof t)t=ad(t);else if(!sd(t)||t.length%2)return null;return(t.length-2)/2}(this.privateKey)&&gp.throwArgumentError("invalid private key","privateKey","[[ REDACTED ]]");const e=yp().keyFromPrivate(nd(this.privateKey));pp(this,"publicKey","0x"+e.getPublic(!1,"hex")),pp(this,"compressedPublicKey","0x"+e.getPublic(!0,"hex")),pp(this,"_isSigningKey",!0)}_addPoint(t){const e=yp().keyFromPublic(nd(this.publicKey)),r=yp().keyFromPublic(nd(t));return"0x"+e.pub.add(r.pub).encodeCompressed("hex")}signDigest(t){const e=yp().keyFromPrivate(nd(this.privateKey)),r=nd(t);32!==r.length&&gp.throwArgumentError("bad digest length","digest",t);const i=e.sign(r,{canonical:!0});return cd({recoveryParam:i.recoveryParam,r:ud("0x"+i.r.toString(16),32),s:ud("0x"+i.s.toString(16),32)})}computeSharedSecret(t){const e=yp().keyFromPrivate(nd(this.privateKey)),r=yp().keyFromPublic(nd(wp(t)));return ud("0x"+e.derive(r.getPublic()).toString(16),32)}static isSigningKey(t){return!(!t||!t._isSigningKey)}}function wp(t,e){const r=nd(t);if(32===r.length){const t=new vp(r);return e?"0x"+yp().keyFromPrivate(r).getPublic(!0,"hex"):t.publicKey}return 33===r.length?e?ad(r):"0x"+yp().keyFromPublic(r).getPublic(!1,"hex"):65===r.length?e?"0x"+yp().keyFromPublic(r).getPublic(!0,"hex"):ad(r):gp.throwArgumentError("invalid public or private key","key","[REDACTED]")}var bp;new Xf("transactions/5.7.0"),function(t){t[t.legacy=0]="legacy",t[t.eip2930=1]="eip2930",t[t.eip1559=2]="eip1559"}(bp||(bp={}));class _p{constructor(t){this.client=t}}class Ap{constructor(t){this.opts=t}}const Ep={wc_authRequest:{req:{ttl:Y.ONE_DAY,prompt:!0,tag:3e3},res:{ttl:Y.ONE_DAY,prompt:!1,tag:3001}}},Sp={min:Y.FIVE_MINUTES,max:Y.SEVEN_DAYS},Mp="authClient",Ip="wc@1:auth:",xp=`${Ip}:PUB_KEY`;function Np(t){return t?.split(":")}function Op(t){const e=t&&Np(t);if(e)return e.pop()}async function Pp(t,e,r,i,n){switch(r.t){case"eip191":return function(t,e,r){return function(t,e){return function(t){return Od(hd(dd(hd(wp(t),1)),12))}(function(t,e){const r=cd(e),i={r:nd(r.r),s:nd(r.s)};return"0x"+yp().recoverPubKey(nd(t),i,r.recoveryParam).encode("hex",!1)}(nd(t),e))}(bd(e),r).toLowerCase()===t.toLowerCase()}(t,e,r.s);case"eip1271":return await async function(t,e,r,i,n){try{const s="0x1626ba7e",o="0000000000000000000000000000000000000000000000000000000000000040",a="0000000000000000000000000000000000000000000000000000000000000041",h=r.substring(2),u=s+bd(e).substring(2)+o+a+h,c=await Qu()(`https://rpc.walletconnect.com/v1/?chainId=${i}&projectId=${n}`,{method:"POST",body:JSON.stringify({id:Date.now()+Math.floor(1e3*Math.random()),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:u},"latest"]})}),{result:l}=await c.json();return!!l&&l.slice(0,s.length).toLowerCase()===s.toLowerCase()}catch(t){return console.error("isValidEip1271Signature: ",t),!1}}(t,e,r.s,i,n);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}function Rp(t){return t.getAll().filter((t=>"requester"in t))}function Cp(t,e){return Rp(t).find((t=>t.id===e))}var Tp=function(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i>>0,o=new Uint8Array(s);t[e];){var c=r[t.charCodeAt(e)];if(255===c)return;for(var l=0,f=s-1;(0!==c||l>>0,o[f]=c%256>>>0,c=c/256>>>0;if(0!==c)throw new Error("Non-zero carry");n=l,e++}if(" "!==t[e]){for(var d=s-n;d!==s&&0===o[d];)d++;for(var p=new Uint8Array(i+(s-d)),g=i;d!==s;)p[g++]=o[d++];return p}}}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,i=0,n=0,s=e.length;n!==s&&0===e[n];)n++,r++;for(var o=(s-n)*c+1>>>0,u=new Uint8Array(o);n!==s;){for(var l=e[n],f=0,d=o-1;(0!==l||f>>0,u[d]=l%a>>>0,l=l/a>>>0;if(0!==l)throw new Error("Non-zero carry");i=f,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var g=h.repeat(r);p{if(t instanceof Uint8Array&&"Uint8Array"===t.constructor.name)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};class Up{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class Lp{constructor(t,e,r){if(this.name=t,this.prefix=e,void 0===e.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if("string"==typeof t){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(t){return Dp(this,t)}}class qp{constructor(t){this.decoders=t}or(t){return Dp(this,t)}decode(t){const e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Dp=(t,e)=>new qp({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Bp{constructor(t,e,r,i){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=i,this.encoder=new Up(t,e,r),this.decoder=new Lp(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const jp=({name:t,prefix:e,encode:r,decode:i})=>new Bp(t,e,r,i),zp=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=Tp(r,e);return jp({prefix:t,name:e,encode:i,decode:t=>kp(n(t))})},Fp=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>jp({prefix:e,name:t,encode:t=>((t,e,r)=>{const i="="===e[e.length-1],n=(1<r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<((t,e,r,i)=>{const n={};for(let t=0;t=8&&(a-=8,o[u++]=255&h>>a)}if(a>=r||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o})(e,i,r,t)}),Kp=jp({prefix:"\0",name:"identity",encode:t=>(t=>(new TextDecoder).decode(t))(t),decode:t=>(t=>(new TextEncoder).encode(t))(t)});var Hp=Object.freeze({__proto__:null,identity:Kp});const Vp=Fp({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gp=Object.freeze({__proto__:null,base2:Vp});const Wp=Fp({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $p=Object.freeze({__proto__:null,base8:Wp});const Jp=zp({prefix:"9",name:"base10",alphabet:"0123456789"});var Yp=Object.freeze({__proto__:null,base10:Jp});const Qp=Fp({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xp=Fp({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Zp=Object.freeze({__proto__:null,base16:Qp,base16upper:Xp});const tg=Fp({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),eg=Fp({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),rg=Fp({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ig=Fp({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ng=Fp({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sg=Fp({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),og=Fp({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ag=Fp({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hg=Fp({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ug=Object.freeze({__proto__:null,base32:tg,base32upper:eg,base32pad:rg,base32padupper:ig,base32hex:ng,base32hexupper:sg,base32hexpad:og,base32hexpadupper:ag,base32z:hg});const cg=zp({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),lg=zp({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var fg=Object.freeze({__proto__:null,base36:cg,base36upper:lg});const dg=zp({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pg=zp({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gg=Object.freeze({__proto__:null,base58btc:dg,base58flickr:pg});const mg=Fp({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yg=Fp({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vg=Fp({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wg=Fp({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bg=Object.freeze({__proto__:null,base64:mg,base64pad:yg,base64url:vg,base64urlpad:wg});const _g=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),Ag=_g.reduce(((t,e,r)=>(t[r]=e,t)),[]),Eg=_g.reduce(((t,e,r)=>(t[e.codePointAt(0)]=r,t)),[]),Sg=jp({prefix:"🚀",name:"base256emoji",encode:function(t){return t.reduce(((t,e)=>t+Ag[e]),"")},decode:function(t){const e=[];for(const r of t){const t=Eg[r.codePointAt(0)];if(void 0===t)throw new Error(`Non-base256emoji character: ${r}`);e.push(t)}return new Uint8Array(e)}});var Mg=Object.freeze({__proto__:null,base256emoji:Sg}),Ig=128,xg=-128,Ng=Math.pow(2,31),Og=128,Pg=127,Rg=Math.pow(2,7),Cg=Math.pow(2,14),Tg=Math.pow(2,21),kg=Math.pow(2,28),Ug=Math.pow(2,35),Lg=Math.pow(2,42),qg=Math.pow(2,49),Dg=Math.pow(2,56),Bg=Math.pow(2,63),jg={encode:function t(e,r,i){r=r||[];for(var n=i=i||0;e>=Ng;)r[i++]=255&e|Ig,e/=128;for(;e&xg;)r[i++]=255&e|Ig,e>>>=7;return r[i]=0|e,t.bytes=i-n+1,r},decode:function t(e,r){var i,n=0,s=(r=r||0,0),o=r,a=e.length;do{if(o>=a)throw t.bytes=0,new RangeError("Could not decode varint");i=e[o++],n+=s<28?(i&Pg)<=Og);return t.bytes=o-r,n},encodingLength:function(t){return t(zg.encode(t,e,r),e),Kg=t=>zg.encodingLength(t),Hg=(t,e)=>{const r=e.byteLength,i=Kg(t),n=i+Kg(r),s=new Uint8Array(n+r);return Fg(t,s,0),Fg(r,s,i),s.set(e,n),new Vg(t,r,e,s)};class Vg{constructor(t,e,r,i){this.code=t,this.size=e,this.digest=r,this.bytes=i}}const Gg=({name:t,code:e,encode:r})=>new Wg(t,e,r);class Wg{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){const e=this.encode(t);return e instanceof Uint8Array?Hg(this.code,e):e.then((t=>Hg(this.code,t)))}throw Error("Unknown type, must be binary type")}}const $g=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Jg=Gg({name:"sha2-256",code:18,encode:$g("SHA-256")}),Yg=Gg({name:"sha2-512",code:19,encode:$g("SHA-512")});Object.freeze({__proto__:null,sha256:Jg,sha512:Yg});const Qg=kp,Xg={code:0,name:"identity",encode:Qg,digest:t=>Hg(0,Qg(t))};Object.freeze({__proto__:null,identity:Xg}),new TextEncoder,new TextDecoder;const Zg={...Hp,...Gp,...$p,...Yp,...Zp,...ug,...fg,...gg,...bg,...Mg};function tm(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const em=tm("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),rm=tm("ascii","a",(t=>{let e="a";for(let r=0;r{const e=function(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}((t=t.substring(1)).length);for(let r=0;re in t?sm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fm=(t,e)=>{for(var r in e||(e={}))um.call(e,r)&&lm(t,r,e[r]);if(hm)for(var r of hm(e))cm.call(e,r)&&lm(t,r,e[r]);return t},dm=(t,e)=>om(t,am(e));class pm extends _p{constructor(t){super(t),this.initialized=!1,this.name="authEngine",this.init=()=>{this.initialized||(this.registerRelayerEvents(),this.registerPairingEvents(),this.client.core.pairing.register({methods:Object.keys(Ep)}),this.initialized=!0)},this.request=async(t,e)=>{if(this.isInitialized(),!function(t){const e=eu(t.aud),r=new RegExp(`${t.domain}`).test(t.aud),i=!!t.nonce,n=!t.type||"eip4361"===t.type,s=t.expiry;if(s&&!cu(s,Sp)){const{message:t}=Wh("MISSING_OR_INVALID",`request() expiry: ${s}. Expiry must be a number (in seconds) between ${Sp.min} and ${Sp.max}`);throw new Error(t)}return!!(e&&r&&i&&n)}(t))throw new Error("Invalid request");if(null!=e&&e.topic)return await this.requestOnKnownPairing(e.topic,t);const{chainId:r,statement:i,aud:n,domain:s,nonce:o,type:a,exp:h,nbf:u}=t,{topic:c,uri:l}=await this.client.core.pairing.create();this.client.logger.info({message:"Generated new pairing",pairing:{topic:c,uri:l}});const f=await this.client.core.crypto.generateKeyPair(),d=fh(f);await this.client.authKeys.set(xp,{responseTopic:d,publicKey:f}),await this.client.pairingTopics.set(d,{topic:d,pairingTopic:c}),await this.client.core.relayer.subscribe(d),this.client.logger.info(`sending request to new pairing topic: ${c}`);const p=await this.sendRequest(c,"wc_authRequest",{payloadParams:{type:a??"eip4361",chainId:r,statement:i,aud:n,domain:s,version:"1",nonce:o,iat:(new Date).toISOString(),exp:h,nbf:u},requester:{publicKey:f,metadata:this.client.metadata}},{},t.expiry);return this.client.logger.info(`sent request to new pairing topic: ${c}`),{uri:l,id:p}},this.respond=async(t,e)=>{if(this.isInitialized(),!function(t,e){return!!Cp(e,t.id)}(t,this.client.requests))throw new Error("Invalid response");const r=Cp(this.client.requests,t.id);if(!r)throw new Error(`Could not find pending auth request with id ${t.id}`);const i=r.requester.publicKey,n=await this.client.core.crypto.generateKeyPair(),s=fh(i),o={type:1,receiverPublicKey:i,senderPublicKey:n};if("error"in t)return void await this.sendError(r.id,s,t,o);const a={h:{t:"eip4361"},p:dm(fm({},r.cacaoPayload),{iss:e}),s:t.signature};await this.sendResult(r.id,s,a,o),await this.client.core.pairing.activate({topic:r.pairingTopic}),await this.client.requests.update(r.id,fm({},a))},this.getPendingRequests=()=>Rp(this.client.requests),this.formatMessage=(t,e)=>{this.client.logger.debug(`formatMessage, cacao is: ${JSON.stringify(t)}`);const r=`${t.domain} wants you to sign in with your Ethereum account:`,i=Op(e),n=t.statement,s=`URI: ${t.aud}`,o=`Version: ${t.version}`,a=`Chain ID: ${function(t){const e=t&&Np(t);if(e)return e[3]}(e)}`;return[r,i,"",n,"",s,o,a,`Nonce: ${t.nonce}`,`Issued At: ${t.iat}`,t.exp?`Expiry: ${t.exp}`:void 0,t.resources&&t.resources.length>0?`Resources:\n${t.resources.map((t=>`- ${t}`)).join("\n")}`:void 0].filter((t=>null!=t)).join("\n")},this.setExpiry=async(t,e)=>{this.client.core.pairing.pairings.keys.includes(t)&&await this.client.core.pairing.updateExpiry({topic:t,expiry:e}),this.client.core.expirer.set(t,e)},this.sendRequest=async(t,e,r,i,n)=>{const s=Ru(e,r),o=await this.client.core.crypto.encode(t,s,i),a=Ep[e].req;if(n&&(a.ttl=n),this.client.core.history.set(t,s),ai()){const t=nm(JSON.stringify(s));this.client.core.verify.register({attestationId:t})}return await this.client.core.relayer.publish(t,o,dm(fm({},a),{internal:{throwOnFailedPublish:!0}})),s.id},this.sendResult=async(t,e,r,i)=>{const n=Cu(t,r),s=await this.client.core.crypto.encode(e,n,i),o=await this.client.core.history.get(e,t),a=Ep[o.request.method].res;return await this.client.core.relayer.publish(e,s,dm(fm({},a),{internal:{throwOnFailedPublish:!0}})),await this.client.core.history.resolve(n),n.id},this.sendError=async(t,e,r,i)=>{const n=Tu(t,r.error),s=await this.client.core.crypto.encode(e,n,i),o=await this.client.core.history.get(e,t),a=Ep[o.request.method].res;return await this.client.core.relayer.publish(e,s,a),await this.client.core.history.resolve(n),n.id},this.requestOnKnownPairing=async(t,e)=>{const r=this.client.core.pairing.pairings.getAll({active:!0}).find((e=>e.topic===t));if(!r)throw new Error(`Could not find pairing for provided topic ${t}`);const{publicKey:i}=this.client.authKeys.get(xp),{chainId:n,statement:s,aud:o,domain:a,nonce:h,type:u}=e,c=await this.sendRequest(r.topic,"wc_authRequest",{payloadParams:{type:u??"eip4361",chainId:n,statement:s,aud:o,domain:a,version:"1",nonce:h,iat:(new Date).toISOString()},requester:{publicKey:i,metadata:this.client.metadata}},{},e.expiry);return this.client.logger.info(`sent request to known pairing topic: ${r.topic}`),{id:c}},this.onPairingCreated=t=>{const e=this.getPendingRequests();if(e){const r=Object.values(e).find((e=>e.pairingTopic===t.topic));r&&this.handleAuthRequest(r)}},this.onRelayEventRequest=t=>{const{topic:e,payload:r}=t,i=r.method;return"wc_authRequest"===i?this.onAuthRequest(e,r):this.client.logger.info(`Unsupported request method ${i}`)},this.onRelayEventResponse=async t=>{const{topic:e,payload:r}=t,i=(await this.client.core.history.get(e,r.id)).request.method;return"wc_authRequest"===i?this.onAuthResponse(e,r):this.client.logger.info(`Unsupported response method ${i}`)},this.onAuthRequest=async(t,e)=>{const{requester:r,payloadParams:i}=e.params;this.client.logger.info({type:"onAuthRequest",topic:t,payload:e});const n=nm(JSON.stringify(e)),s=await this.getVerifyContext(n,this.client.metadata),o={requester:r,pairingTopic:t,id:e.id,cacaoPayload:i,verifyContext:s};await this.client.requests.set(e.id,o),this.handleAuthRequest(o)},this.handleAuthRequest=async t=>{const{id:e,pairingTopic:r,requester:i,cacaoPayload:n,verifyContext:s}=t;try{this.client.emit("auth_request",{id:e,topic:r,params:{requester:i,cacaoPayload:n},verifyContext:s})}catch(e){await this.sendError(t.id,t.pairingTopic,e),this.client.logger.error(e)}},this.onAuthResponse=async(t,e)=>{const{id:r}=e;if(this.client.logger.info({type:"onAuthResponse",topic:t,response:e}),Fu(e)){const{pairingTopic:i}=this.client.pairingTopics.get(t);await this.client.core.pairing.activate({topic:i});const{s:n,p:s}=e.result;await this.client.requests.set(r,fm({id:r,pairingTopic:i},e.result));const o=this.formatMessage(s,s.iss);this.client.logger.debug("reconstructed message:\n",JSON.stringify(o)),this.client.logger.debug("payload.iss:",s.iss),this.client.logger.debug("signature:",n);const a=Op(s.iss),h=function(t){const e=t&&Np(t);if(e)return e[2]+":"+e[3]}(s.iss);if(!a)throw new Error("Could not derive address from `payload.iss`");if(!h)throw new Error("Could not derive chainId from `payload.iss`");this.client.logger.debug("walletAddress extracted from `payload.iss`:",a),await Pp(a,o,n,h,this.client.projectId)?this.client.emit("auth_response",{id:r,topic:t,params:e}):this.client.emit("auth_response",{id:r,topic:t,params:{message:"Invalid signature",code:-1}})}else Ku(e)&&this.client.emit("auth_response",{id:r,topic:t,params:e})},this.getVerifyContext=async(t,e)=>{const r={verified:{verifyUrl:e.verifyUrl||"",validation:"UNKNOWN",origin:e.url||""}};try{const i=await this.client.core.verify.resolve({attestationId:t,verifyUrl:e.verifyUrl});i&&(r.verified.origin=i.origin,r.verified.isScam=i.isScam,r.verified.validation=origin===new URL(e.url).origin?"VALID":"INVALID")}catch(t){this.client.logger.error(t)}return this.client.logger.info(`Verify context: ${JSON.stringify(r)}`),r}}isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}}registerRelayerEvents(){this.client.core.relayer.on(Rl,(async t=>{const{topic:e,message:r}=t,{responseTopic:i,publicKey:n}=this.client.authKeys.keys.includes(xp)?this.client.authKeys.get(xp):{responseTopic:void 0,publicKey:void 0};if(i&&e!==i)return void this.client.logger.debug("[Auth] Ignoring message from unknown topic",e);const s=await this.client.core.crypto.decode(e,r,{receiverPublicKey:n});ju(s)?(this.client.core.history.set(e,s),this.onRelayEventRequest({topic:e,payload:s})):zu(s)&&(await this.client.core.history.resolve(s),this.onRelayEventResponse({topic:e,payload:s}))}))}registerPairingEvents(){this.client.core.pairing.events.on(Kl,(t=>this.onPairingCreated(t)))}}class gm extends Ap{constructor(t){super(t),this.protocol="wc",this.version=1,this.name=Mp,this.events=new y.EventEmitter,this.emit=(t,e)=>this.events.emit(t,e),this.on=(t,e)=>this.events.on(t,e),this.once=(t,e)=>this.events.once(t,e),this.off=(t,e)=>this.events.off(t,e),this.removeListener=(t,e)=>this.events.removeListener(t,e),this.request=async(t,e)=>{try{return await this.engine.request(t,e)}catch(t){throw this.logger.error(t.message),t}},this.respond=async(t,e)=>{try{return await this.engine.respond(t,e)}catch(t){throw this.logger.error(t.message),t}},this.getPendingRequests=()=>{try{return this.engine.getPendingRequests()}catch(t){throw this.logger.error(t.message),t}},this.formatMessage=(t,e)=>{try{return this.engine.formatMessage(t,e)}catch(t){throw this.logger.error(t.message),t}};const e=typeof t.logger<"u"&&"string"!=typeof t.logger?t.logger:it()(wt({level:t.logger||"error"}));this.name=t?.name||Mp,this.metadata=t.metadata,this.projectId=t.projectId,this.core=t.core||new Ff(t),this.logger=_t(e,this.name),this.authKeys=new Of(this.core,this.logger,"authKeys",Ip,(()=>xp)),this.pairingTopics=new Of(this.core,this.logger,"pairingTopics",Ip),this.requests=new Of(this.core,this.logger,"requests",Ip,(t=>t.id)),this.engine=new pm(this)}static async init(t){const e=new gm(t);return await e.initialize(),e}get context(){return bt(this.logger)}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.authKeys.init(),await this.requests.init(),await this.pairingTopics.init(),await this.engine.init(),this.logger.info("AuthClient Initialization Success"),this.logger.info({authClient:this})}catch(t){throw this.logger.info("AuthClient Initialization Failure"),this.logger.error(t.message),t}}}const mm=gm,ym="client",vm=`wc@2:${ym}:`,wm=ym,bm="WALLETCONNECT_DEEPLINK_CHOICE",_m=Y.SEVEN_DAYS,Am={wc_sessionPropose:{req:{ttl:Y.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1104},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1106},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:Y.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:Y.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1112},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1114},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:Y.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:Y.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1119}}},Em={min:Y.FIVE_MINUTES,max:Y.SEVEN_DAYS},Sm="IDLE",Mm="ACTIVE",Im=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],xm="wc@1.5:auth:",Nm=`${xm}:PUB_KEY`;var Om=Object.defineProperty,Pm=Object.defineProperties,Rm=Object.getOwnPropertyDescriptors,Cm=Object.getOwnPropertySymbols,Tm=Object.prototype.hasOwnProperty,km=Object.prototype.propertyIsEnumerable,Um=(t,e,r)=>e in t?Om(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lm=(t,e)=>{for(var r in e||(e={}))Tm.call(e,r)&&Um(t,r,e[r]);if(Cm)for(var r of Cm(e))km.call(e,r)&&Um(t,r,e[r]);return t},qm=(t,e)=>Pm(t,Rm(e));class Dm extends kt{constructor(t){super(t),this.name="engine",this.events=new(v()),this.initialized=!1,this.requestQueue={state:Sm,queue:[]},this.sessionRequestQueue={state:Sm,queue:[]},this.requestQueueDelay=Y.ONE_SECOND,this.expectedPairingMethodMap=new Map,this.recentlyDeletedMap=new Map,this.recentlyDeletedLimit=200,this.relayMessageCache=[],this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.registerPairingEvents(),this.client.core.pairing.register({methods:Object.keys(Am)}),this.initialized=!0,setTimeout((()=>{this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()}),(0,Y.toMiliseconds)(this.requestQueueDelay)))},this.connect=async t=>{await this.isInitialized();const e=qm(Lm({},t),{requiredNamespaces:t.requiredNamespaces||{},optionalNamespaces:t.optionalNamespaces||{}});await this.isValidConnect(e);const{pairingTopic:r,requiredNamespaces:i,optionalNamespaces:n,sessionProperties:s,relays:o}=e;let a,h=r,u=!1;try{h&&(u=this.client.core.pairing.pairings.get(h).active)}catch(t){throw this.client.logger.error(`connect() -> pairing.get(${h}) failed`),t}if(!h||!u){const{topic:t,uri:e}=await this.client.core.pairing.create();h=t,a=e}if(!h){const{message:t}=Wh("NO_MATCHING_KEY",`connect() pairing topic: ${h}`);throw new Error(t)}const c=await this.client.core.crypto.generateKeyPair(),l=Am.wc_sessionPropose.req.ttl||Y.FIVE_MINUTES,f=yi(l),d=Lm({requiredNamespaces:i,optionalNamespaces:n,relays:o??[{protocol:"irn"}],proposer:{publicKey:c,metadata:this.client.metadata},expiryTimestamp:f,pairingTopic:h},s&&{sessionProperties:s}),{reject:p,resolve:g,done:m}=di(l,"Proposal expired");this.events.once(wi("session_connect"),(async({error:t,session:e})=>{if(t)p(t);else if(e){e.self.publicKey=c;const t=qm(Lm({},e),{pairingTopic:d.pairingTopic,requiredNamespaces:d.requiredNamespaces,optionalNamespaces:d.optionalNamespaces});await this.client.session.set(e.topic,t),await this.setExpiry(e.topic,e.expiry),h&&await this.client.core.pairing.updateMetadata({topic:h,metadata:e.peer.metadata}),this.cleanupDuplicatePairings(t),g(t)}}));const y=await this.sendRequest({topic:h,method:"wc_sessionPropose",params:d,throwOnFailedPublish:!0});return await this.setProposal(y,Lm({id:y},d)),{uri:a,approval:m}},this.pair=async t=>{await this.isInitialized();try{return await this.client.core.pairing.pair(t)}catch(t){throw this.client.logger.error("pair() failed"),t}},this.approve=async t=>{await this.isInitialized();try{await this.isValidApprove(t)}catch(t){throw this.client.logger.error("approve() -> isValidApprove() failed"),t}const{id:e,relayProtocol:r,namespaces:i,sessionProperties:n,sessionConfig:s}=t;let o;try{o=this.client.proposal.get(e)}catch(t){throw this.client.logger.error(`approve() -> proposal.get(${e}) failed`),t}const{pairingTopic:a,proposer:h,requiredNamespaces:u,optionalNamespaces:c}=o,l=await this.client.core.crypto.generateKeyPair(),f=h.publicKey,d=await this.client.core.crypto.generateSharedKey(l,f),p=Lm(Lm({relay:{protocol:r??"irn"},namespaces:i,controller:{publicKey:l,metadata:this.client.metadata},expiry:yi(_m)},n&&{sessionProperties:n}),s&&{sessionConfig:s});await this.client.core.relayer.subscribe(d);const g=qm(Lm({},p),{topic:d,requiredNamespaces:u,optionalNamespaces:c,pairingTopic:a,acknowledged:!1,self:p.controller,peer:{publicKey:h.publicKey,metadata:h.metadata},controller:l});await this.client.session.set(d,g);try{await this.sendResult({id:e,topic:a,result:{relay:{protocol:r??"irn"},responderPublicKey:l},throwOnFailedPublish:!0}),await this.sendRequest({topic:d,method:"wc_sessionSettle",params:p,throwOnFailedPublish:!0})}catch(t){throw this.client.logger.error(t),this.client.session.delete(d,$h("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(d),t}return await this.client.core.pairing.updateMetadata({topic:a,metadata:h.metadata}),await this.client.proposal.delete(e,$h("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:a}),await this.setExpiry(d,yi(_m)),{topic:d,acknowledged:()=>new Promise((t=>setTimeout((()=>t(this.client.session.get(d))),500)))}},this.reject=async t=>{await this.isInitialized();try{await this.isValidReject(t)}catch(t){throw this.client.logger.error("reject() -> isValidReject() failed"),t}const{id:e,reason:r}=t;let i;try{i=this.client.proposal.get(e).pairingTopic}catch(t){throw this.client.logger.error(`reject() -> proposal.get(${e}) failed`),t}i&&(await this.sendError({id:e,topic:i,error:r,rpcOpts:Am.wc_sessionPropose.reject}),await this.client.proposal.delete(e,$h("USER_DISCONNECTED")))},this.update=async t=>{await this.isInitialized();try{await this.isValidUpdate(t)}catch(t){throw this.client.logger.error("update() -> isValidUpdate() failed"),t}const{topic:e,namespaces:r}=t,{done:i,resolve:n,reject:s}=di(),o=Ou(),a=Pu().toString(),h=this.client.session.get(e).namespaces;return this.events.once(wi("session_update",o),(({error:t})=>{t?s(t):n()})),await this.client.session.update(e,{namespaces:r}),await this.sendRequest({topic:e,method:"wc_sessionUpdate",params:{namespaces:r},throwOnFailedPublish:!0,clientRpcId:o,relayRpcId:a}).catch((t=>{this.client.logger.error(t),this.client.session.update(e,{namespaces:h}),s(t)})),{acknowledged:i}},this.extend=async t=>{await this.isInitialized();try{await this.isValidExtend(t)}catch(t){throw this.client.logger.error("extend() -> isValidExtend() failed"),t}const{topic:e}=t,r=Ou(),{done:i,resolve:n,reject:s}=di();return this.events.once(wi("session_extend",r),(({error:t})=>{t?s(t):n()})),await this.setExpiry(e,yi(_m)),this.sendRequest({topic:e,method:"wc_sessionExtend",params:{},clientRpcId:r,throwOnFailedPublish:!0}).catch((t=>{s(t)})),{acknowledged:i}},this.request=async t=>{await this.isInitialized();try{await this.isValidRequest(t)}catch(t){throw this.client.logger.error("request() -> isValidRequest() failed"),t}const{chainId:e,request:i,topic:n,expiry:s=Am.wc_sessionRequest.req.ttl}=t,o=this.client.session.get(n),a=Ou(),h=Pu().toString(),{done:u,resolve:c,reject:l}=di(s,"Request expired. Please try again.");return this.events.once(wi("session_request",a),(({error:t,result:e})=>{t?l(t):c(e)})),await Promise.all([new Promise((async t=>{await this.sendRequest({clientRpcId:a,relayRpcId:h,topic:n,method:"wc_sessionRequest",params:{request:qm(Lm({},i),{expiryTimestamp:yi(s)}),chainId:e},expiry:s,throwOnFailedPublish:!0}).catch((t=>l(t))),this.client.events.emit("session_request_sent",{topic:n,request:i,chainId:e,id:a}),t()})),new Promise((async t=>{var e;if(null==(e=o.sessionConfig)||!e.disableDeepLink){const t=await async function(t,e){try{return await t.getItem(e)||(ai()?localStorage.getItem(e):void 0)}catch(t){console.error(t)}}(this.client.core.storage,bm);!async function({id:t,topic:e,wcDeepLink:i}){try{if(!i)return;const n="string"==typeof i?JSON.parse(i):i;let s=n?.href;if("string"!=typeof s)return;s.endsWith("/")&&(s=s.slice(0,-1));const o=`${s}/wc?requestId=${t}&sessionTopic=${e}`,a=hi();a===ii.browser?o.startsWith("https://")||o.startsWith("http://")?window.open(o,"_blank","noreferrer noopener"):window.open(o,"_self","noreferrer noopener"):a===ii.reactNative&&typeof(null==r.g?void 0:r.g.Linking)<"u"&&await r.g.Linking.openURL(o)}catch(t){console.error(t)}}({id:a,topic:n,wcDeepLink:t})}t()})),u()]).then((t=>t[2]))},this.respond=async t=>{await this.isInitialized(),await this.isValidRespond(t);const{topic:e,response:r}=t,{id:i}=r;Fu(r)?await this.sendResult({id:i,topic:e,result:r.result,throwOnFailedPublish:!0}):Ku(r)&&await this.sendError({id:i,topic:e,error:r.error}),this.cleanupAfterResponse(t)},this.ping=async t=>{await this.isInitialized();try{await this.isValidPing(t)}catch(t){throw this.client.logger.error("ping() -> isValidPing() failed"),t}const{topic:e}=t;if(this.client.session.keys.includes(e)){const t=Ou(),r=Pu().toString(),{done:i,resolve:n,reject:s}=di();this.events.once(wi("session_ping",t),(({error:t})=>{t?s(t):n()})),await Promise.all([this.sendRequest({topic:e,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:t,relayRpcId:r}),i()])}else this.client.core.pairing.pairings.keys.includes(e)&&await this.client.core.pairing.ping({topic:e})},this.emit=async t=>{await this.isInitialized(),await this.isValidEmit(t);const{topic:e,event:r,chainId:i}=t,n=Pu().toString();await this.sendRequest({topic:e,method:"wc_sessionEvent",params:{event:r,chainId:i},throwOnFailedPublish:!0,relayRpcId:n})},this.disconnect=async t=>{await this.isInitialized(),await this.isValidDisconnect(t);const{topic:e}=t;if(this.client.session.keys.includes(e))await this.sendRequest({topic:e,method:"wc_sessionDelete",params:$h("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:e,emitEvent:!1});else{if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:t}=Wh("MISMATCHED_TOPIC",`Session or pairing topic not found: ${e}`);throw new Error(t)}await this.client.core.pairing.disconnect({topic:e})}},this.find=t=>(this.isInitialized(),this.client.session.getAll().filter((e=>function(t,e){const{requiredNamespaces:r}=e,i=Object.keys(t.namespaces),n=Object.keys(r);let s=!0;return!!ci(n,i)&&(i.forEach((e=>{const{accounts:i,methods:n,events:o}=t.namespaces[e],a=jh(i),h=r[e];ci(Jr(e,h),a)&&ci(h.methods,n)&&ci(h.events,o)||(s=!1)})),s)}(e,t)))),this.getPendingSessionRequests=()=>this.client.pendingRequest.getAll(),this.authenticate=async t=>{this.isInitialized(),this.isValidAuthenticate(t);const{chains:e,statement:r="",uri:i,domain:n,nonce:s,type:o,exp:a,nbf:h,methods:u=[],expiry:c}=t,l=[...t.resources||[]],{topic:f,uri:d}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"]});this.client.logger.info({message:"Generated new pairing",pairing:{topic:f,uri:d}});const p=await this.client.core.crypto.generateKeyPair(),g=fh(p);if(await Promise.all([this.client.auth.authKeys.set(Nm,{responseTopic:g,publicKey:p}),this.client.auth.pairingTopics.set(g,{topic:g,pairingTopic:f})]),await this.client.core.relayer.subscribe(g),this.client.logger.info(`sending request to new pairing topic: ${f}`),u.length>0){const{namespace:t}=$r(e[0]);let r=function(t,e,r){const i=function(t,e,r,i={}){return r?.sort(((t,e)=>t.localeCompare(e))),{att:{[t]:th(e,r,i)}}}(t,e,r);return eh(i)}(t,"request",u);oh(l)&&(r=ih(r,l.pop())),l.push(r)}const m=c&&c>Am.wc_sessionAuthenticate.req.ttl?c:Am.wc_sessionAuthenticate.req.ttl,y={authPayload:{type:o??"caip122",chains:e,statement:r,aud:i,domain:n,version:"1",nonce:s,iat:(new Date).toISOString(),exp:a,nbf:h,resources:l},requester:{publicKey:p,metadata:this.client.metadata},expiryTimestamp:yi(m)},v={requiredNamespaces:{},optionalNamespaces:{eip155:{chains:e,methods:[...new Set(["personal_sign",...u])],events:["chainChanged","accountsChanged"]}},relays:[{protocol:"irn"}],pairingTopic:f,proposer:{publicKey:p,metadata:this.client.metadata},expiryTimestamp:yi(Am.wc_sessionPropose.req.ttl)},{done:w,resolve:b,reject:_}=di(m,"Request expired"),A=async({error:t,session:e})=>{if(this.events.off(wi("session_request",S),E),t)_(t);else if(e){e.self.publicKey=p,await this.client.session.set(e.topic,e),await this.setExpiry(e.topic,e.expiry),f&&await this.client.core.pairing.updateMetadata({topic:f,metadata:e.peer.metadata});const t=this.client.session.get(e.topic);await this.deleteProposal(M),b({session:t})}},E=async t=>{if(await this.deletePendingAuthRequest(S,{message:"fulfilled",code:0}),t.error){const e=$h("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return t.error.code===e.code?void 0:(this.events.off(wi("session_connect"),A),_(t.error.message))}await this.deleteProposal(M),this.events.off(wi("session_connect"),A);const{cacaos:e,responder:r}=t.result,i=[],n=[];for(const t of e){await Qa({cacao:t,projectId:this.client.core.projectId})||(this.client.logger.error(t,"Signature verification failed"),_($h("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:e}=t,r=oh(e.resources),s=[Ja(e.iss)],o=Ya(e.iss);if(r){const t=nh(r),e=sh(r);i.push(...t),s.push(...e)}for(const t of s)n.push(`${t}:${o}`)}const s=await this.client.core.crypto.generateSharedKey(p,r.publicKey);let o;i.length>0&&(o={topic:s,acknowledged:!0,self:{publicKey:p,metadata:this.client.metadata},peer:r,controller:r.publicKey,expiry:yi(_m),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:f,namespaces:Hh([...new Set(i)],[...new Set(n)])},await this.client.core.relayer.subscribe(s),await this.client.session.set(s,o),f&&await this.client.core.pairing.updateMetadata({topic:f,metadata:r.metadata}),o=this.client.session.get(s)),b({auths:e,session:o})},S=Ou(),M=Ou();this.events.once(wi("session_connect"),A),this.events.once(wi("session_request",S),E);try{await Promise.all([this.sendRequest({topic:f,method:"wc_sessionAuthenticate",params:y,expiry:t.expiry,throwOnFailedPublish:!0,clientRpcId:S}),this.sendRequest({topic:f,method:"wc_sessionPropose",params:v,expiry:Am.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:M})])}catch(t){throw this.events.off(wi("session_connect"),A),this.events.off(wi("session_request",S),E),t}return await this.setProposal(M,Lm({id:M},v)),await this.setAuthRequest(S,{request:qm(Lm({},y),{verifyContext:{}}),pairingTopic:f}),{uri:d,response:w}},this.approveSessionAuthenticate=async t=>{this.isInitialized();const{id:e,auths:r}=t,i=this.getPendingAuthRequest(e);if(!i)throw new Error(`Could not find pending auth request with id ${e}`);const n=i.requester.publicKey,s=await this.client.core.crypto.generateKeyPair(),o=fh(n),a={type:1,receiverPublicKey:n,senderPublicKey:s},h=[],u=[];for(const t of r){if(!await Qa({cacao:t,projectId:this.client.core.projectId})){const t=$h("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:e,topic:o,error:t,encodeOpts:a}),new Error(t.message)}const{p:r}=t,i=oh(r.resources),n=[Ja(r.iss)],s=Ya(r.iss);if(i){const t=nh(i),e=sh(i);h.push(...t),n.push(...e)}for(const t of n)u.push(`${t}:${s}`)}const c=await this.client.core.crypto.generateSharedKey(s,n);let l;return h?.length>0&&(l={topic:c,acknowledged:!0,self:{publicKey:s,metadata:this.client.metadata},peer:{publicKey:n,metadata:i.requester.metadata},controller:n,expiry:yi(_m),authentication:r,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:i.pairingTopic,namespaces:Hh([...new Set(h)],[...new Set(u)])},await this.client.core.relayer.subscribe(c),await this.client.session.set(c,l),await this.client.core.pairing.updateMetadata({topic:i.pairingTopic,metadata:i.requester.metadata})),await this.sendResult({topic:o,id:e,result:{cacaos:r,responder:{publicKey:s,metadata:this.client.metadata}},encodeOpts:a,throwOnFailedPublish:!0}),await this.client.auth.requests.delete(e,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:i.pairingTopic}),{session:l}},this.rejectSessionAuthenticate=async t=>{await this.isInitialized();const{id:e,reason:r}=t,i=this.getPendingAuthRequest(e);if(!i)throw new Error(`Could not find pending auth request with id ${e}`);const n=i.requester.publicKey,s=await this.client.core.crypto.generateKeyPair(),o=fh(n),a={type:1,receiverPublicKey:n,senderPublicKey:s};await this.sendError({id:e,topic:o,error:r,encodeOpts:a,rpcOpts:Am.wc_sessionAuthenticate.reject}),await this.client.auth.requests.delete(e,{message:"rejected",code:0}),await this.client.proposal.delete(e,$h("USER_DISCONNECTED"))},this.formatAuthMessage=t=>{this.isInitialized();const{request:e,iss:r}=t;return Xa(e,r)},this.processRelayMessageCache=()=>{setTimeout((async()=>{if(0!==this.relayMessageCache.length)for(;this.relayMessageCache.length>0;)try{const t=this.relayMessageCache.shift();t&&await this.onRelayMessage(t)}catch(t){this.client.logger.error(t)}}),50)},this.cleanupDuplicatePairings=async t=>{if(t.pairingTopic)try{const e=this.client.core.pairing.pairings.get(t.pairingTopic),r=this.client.core.pairing.pairings.getAll().filter((r=>{var i,n;return(null==(i=r.peerMetadata)?void 0:i.url)&&(null==(n=r.peerMetadata)?void 0:n.url)===t.peer.metadata.url&&r.topic&&r.topic!==e.topic}));if(0===r.length)return;this.client.logger.info(`Cleaning up ${r.length} duplicate pairing(s)`),await Promise.all(r.map((t=>this.client.core.pairing.disconnect({topic:t.topic})))),this.client.logger.info("Duplicate pairings clean up finished")}catch(t){this.client.logger.error(t)}},this.deleteSession=async t=>{var e;const{topic:r,expirerHasDeleted:i=!1,emitEvent:n=!0,id:s=0}=t,{self:o}=this.client.session.get(r);await this.client.core.relayer.unsubscribe(r),await this.client.session.delete(r,$h("USER_DISCONNECTED")),this.addToRecentlyDeleted(r,"session"),this.client.core.crypto.keychain.has(o.publicKey)&&await this.client.core.crypto.deleteKeyPair(o.publicKey),this.client.core.crypto.keychain.has(r)&&await this.client.core.crypto.deleteSymKey(r),i||this.client.core.expirer.del(r),this.client.core.storage.removeItem(bm).catch((t=>this.client.logger.warn(t))),this.getPendingSessionRequests().forEach((t=>{t.topic===r&&this.deletePendingSessionRequest(t.id,$h("USER_DISCONNECTED"))})),r===(null==(e=this.sessionRequestQueue.queue[0])?void 0:e.topic)&&(this.sessionRequestQueue.state=Sm),n&&this.client.events.emit("session_delete",{id:s,topic:r})},this.deleteProposal=async(t,e)=>{await Promise.all([this.client.proposal.delete(t,$h("USER_DISCONNECTED")),e?Promise.resolve():this.client.core.expirer.del(t)]),this.addToRecentlyDeleted(t,"proposal")},this.deletePendingSessionRequest=async(t,e,r=!1)=>{await Promise.all([this.client.pendingRequest.delete(t,e),r?Promise.resolve():this.client.core.expirer.del(t)]),this.addToRecentlyDeleted(t,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter((e=>e.id!==t)),r&&(this.sessionRequestQueue.state=Sm,this.client.events.emit("session_request_expire",{id:t}))},this.deletePendingAuthRequest=async(t,e,r=!1)=>{await Promise.all([this.client.auth.requests.delete(t,e),r?Promise.resolve():this.client.core.expirer.del(t)])},this.setExpiry=async(t,e)=>{this.client.session.keys.includes(t)&&(this.client.core.expirer.set(t,e),await this.client.session.update(t,{expiry:e}))},this.setProposal=async(t,e)=>{this.client.core.expirer.set(t,yi(Am.wc_sessionPropose.req.ttl)),await this.client.proposal.set(t,e)},this.setAuthRequest=async(t,e)=>{const{request:r,pairingTopic:i}=e;this.client.core.expirer.set(t,r.expiryTimestamp),await this.client.auth.requests.set(t,{authPayload:r.authPayload,requester:r.requester,expiryTimestamp:r.expiryTimestamp,id:t,pairingTopic:i,verifyContext:r.verifyContext})},this.setPendingSessionRequest=async t=>{const{id:e,topic:r,params:i,verifyContext:n}=t,s=i.request.expiryTimestamp||yi(Am.wc_sessionRequest.req.ttl);this.client.core.expirer.set(e,s),await this.client.pendingRequest.set(e,{id:e,topic:r,params:i,verifyContext:n})},this.sendRequest=async t=>{const{topic:e,method:r,params:i,expiry:n,relayRpcId:s,clientRpcId:o,throwOnFailedPublish:a}=t,h=Ru(r,i,o);if(ai()&&Im.includes(r)){const t=dh(JSON.stringify(h));this.client.core.verify.register({attestationId:t})}let u;try{u=await this.client.core.crypto.encode(e,h)}catch(t){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${e} failed`),t}const c=Am[r].req;return n&&(c.ttl=n),s&&(c.id=s),this.client.core.history.set(e,h),a?(c.internal=qm(Lm({},c.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(e,u,c)):this.client.core.relayer.publish(e,u,c).catch((t=>this.client.logger.error(t))),h.id},this.sendResult=async t=>{const{id:e,topic:r,result:i,throwOnFailedPublish:n,encodeOpts:s}=t,o=Cu(e,i);let a,h;try{a=await this.client.core.crypto.encode(r,o,s)}catch(t){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${r} failed`),t}try{h=await this.client.core.history.get(r,e)}catch(t){throw this.client.logger.error(`sendResult() -> history.get(${r}, ${e}) failed`),t}const u=Am[h.request.method].res;n?(u.internal=qm(Lm({},u.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(r,a,u)):this.client.core.relayer.publish(r,a,u).catch((t=>this.client.logger.error(t))),await this.client.core.history.resolve(o)},this.sendError=async t=>{const{id:e,topic:r,error:i,encodeOpts:n,rpcOpts:s}=t,o=Tu(e,i);let a,h;try{a=await this.client.core.crypto.encode(r,o,n)}catch(t){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${r} failed`),t}try{h=await this.client.core.history.get(r,e)}catch(t){throw this.client.logger.error(`sendError() -> history.get(${r}, ${e}) failed`),t}const u=s||Am[h.request.method].res;this.client.core.relayer.publish(r,a,u),await this.client.core.history.resolve(o)},this.cleanup=async()=>{const t=[],e=[];this.client.session.getAll().forEach((e=>{let r=!1;vi(e.expiry)&&(r=!0),this.client.core.crypto.keychain.has(e.topic)||(r=!0),r&&t.push(e.topic)})),this.client.proposal.getAll().forEach((t=>{vi(t.expiryTimestamp)&&e.push(t.id)})),await Promise.all([...t.map((t=>this.deleteSession({topic:t}))),...e.map((t=>this.deleteProposal(t)))])},this.onRelayEventRequest=async t=>{this.requestQueue.queue.push(t),await this.processRequestsQueue()},this.processRequestsQueue=async()=>{if(this.requestQueue.state!==Mm){for(this.client.logger.info(`Request queue starting with ${this.requestQueue.queue.length} requests`);this.requestQueue.queue.length>0;){this.requestQueue.state=Mm;const t=this.requestQueue.queue.shift();if(t)try{await this.processRequest(t)}catch(t){this.client.logger.warn(t)}}this.requestQueue.state=Sm}else this.client.logger.info("Request queue already active, skipping...")},this.processRequest=async t=>{const{topic:e,payload:r}=t,i=r.method;if(!this.shouldIgnorePairingRequest({topic:e,requestMethod:i}))switch(i){case"wc_sessionPropose":return await this.onSessionProposeRequest(e,r);case"wc_sessionSettle":return await this.onSessionSettleRequest(e,r);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(e,r);case"wc_sessionExtend":return await this.onSessionExtendRequest(e,r);case"wc_sessionPing":return await this.onSessionPingRequest(e,r);case"wc_sessionDelete":return await this.onSessionDeleteRequest(e,r);case"wc_sessionRequest":return await this.onSessionRequest(e,r);case"wc_sessionEvent":return await this.onSessionEventRequest(e,r);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest(e,r);default:return this.client.logger.info(`Unsupported request method ${i}`)}},this.onRelayEventResponse=async t=>{const{topic:e,payload:r}=t,i=(await this.client.core.history.get(e,r.id)).request.method;switch(i){case"wc_sessionPropose":return this.onSessionProposeResponse(e,r);case"wc_sessionSettle":return this.onSessionSettleResponse(e,r);case"wc_sessionUpdate":return this.onSessionUpdateResponse(e,r);case"wc_sessionExtend":return this.onSessionExtendResponse(e,r);case"wc_sessionPing":return this.onSessionPingResponse(e,r);case"wc_sessionRequest":return this.onSessionRequestResponse(e,r);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(e,r);default:return this.client.logger.info(`Unsupported response method ${i}`)}},this.onRelayEventUnknownPayload=t=>{const{topic:e}=t,{message:r}=Wh("MISSING_OR_INVALID",`Decoded payload on topic ${e} is not identifiable as a JSON-RPC request or a response.`);throw new Error(r)},this.shouldIgnorePairingRequest=t=>{const{topic:e,requestMethod:r}=t,i=this.expectedPairingMethodMap.get(e);return!(!i||i.includes(r)||!(i.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0))},this.onSessionProposeRequest=async(t,e)=>{const{params:r,id:i}=e;try{this.isValidConnect(Lm({},e.params));const n=r.expiryTimestamp||yi(Am.wc_sessionPropose.req.ttl),s=Lm({id:i,pairingTopic:t,expiryTimestamp:n},r);await this.setProposal(i,s);const o=dh(JSON.stringify(e)),a=await this.getVerifyContext(o,s.proposer.metadata);this.client.events.emit("session_proposal",{id:i,params:s,verifyContext:a})}catch(e){await this.sendError({id:i,topic:t,error:e,rpcOpts:Am.wc_sessionPropose.autoReject}),this.client.logger.error(e)}},this.onSessionProposeResponse=async(t,e)=>{const{id:r}=e;if(Fu(e)){const{result:i}=e;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:i});const n=this.client.proposal.get(r);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:n});const s=n.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:s});const o=i.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:o});const a=await this.client.core.crypto.generateSharedKey(s,o);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",sessionTopic:a});const h=await this.client.core.relayer.subscribe(a);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:h}),await this.client.core.pairing.activate({topic:t})}else if(Ku(e)){await this.client.proposal.delete(r,$h("USER_DISCONNECTED"));const t=wi("session_connect");if(0===this.events.listenerCount(t))throw new Error(`emitting ${t} without any listeners, 954`);this.events.emit(wi("session_connect"),{error:e.error})}},this.onSessionSettleRequest=async(t,e)=>{const{id:r,params:i}=e;try{this.isValidSessionSettleRequest(i);const{relay:r,controller:n,expiry:s,namespaces:o,sessionProperties:a,sessionConfig:h}=e.params,u=Lm(Lm({topic:t,relay:r,expiry:s,namespaces:o,acknowledged:!0,pairingTopic:"",requiredNamespaces:{},optionalNamespaces:{},controller:n.publicKey,self:{publicKey:"",metadata:this.client.metadata},peer:{publicKey:n.publicKey,metadata:n.metadata}},a&&{sessionProperties:a}),h&&{sessionConfig:h});await this.sendResult({id:e.id,topic:t,result:!0,throwOnFailedPublish:!0});const c=wi("session_connect");if(0===this.events.listenerCount(c))throw new Error(`emitting ${c} without any listeners 997`);this.events.emit(wi("session_connect"),{session:u})}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionSettleResponse=async(t,e)=>{const{id:r}=e;Fu(e)?(await this.client.session.update(t,{acknowledged:!0}),this.events.emit(wi("session_approve",r),{})):Ku(e)&&(await this.client.session.delete(t,$h("USER_DISCONNECTED")),this.events.emit(wi("session_approve",r),{error:e.error}))},this.onSessionUpdateRequest=async(t,e)=>{const{params:r,id:i}=e;try{const e=`${t}_session_update`,n=du.get(e);if(n&&this.isRequestOutOfSync(n,i))return this.client.logger.info(`Discarding out of sync request - ${i}`),void this.sendError({id:i,topic:t,error:$h("INVALID_UPDATE_REQUEST")});this.isValidUpdate(Lm({topic:t},r));try{du.set(e,i),await this.client.session.update(t,{namespaces:r.namespaces}),await this.sendResult({id:i,topic:t,result:!0,throwOnFailedPublish:!0})}catch(t){throw du.delete(e),t}this.client.events.emit("session_update",{id:i,topic:t,params:r})}catch(e){await this.sendError({id:i,topic:t,error:e}),this.client.logger.error(e)}},this.isRequestOutOfSync=(t,e)=>parseInt(e.toString().slice(0,-3))<=parseInt(t.toString().slice(0,-3)),this.onSessionUpdateResponse=(t,e)=>{const{id:r}=e,i=wi("session_update",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);Fu(e)?this.events.emit(wi("session_update",r),{}):Ku(e)&&this.events.emit(wi("session_update",r),{error:e.error})},this.onSessionExtendRequest=async(t,e)=>{const{id:r}=e;try{this.isValidExtend({topic:t}),await this.setExpiry(t,yi(_m)),await this.sendResult({id:r,topic:t,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_extend",{id:r,topic:t})}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionExtendResponse=(t,e)=>{const{id:r}=e,i=wi("session_extend",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);Fu(e)?this.events.emit(wi("session_extend",r),{}):Ku(e)&&this.events.emit(wi("session_extend",r),{error:e.error})},this.onSessionPingRequest=async(t,e)=>{const{id:r}=e;try{this.isValidPing({topic:t}),await this.sendResult({id:r,topic:t,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:r,topic:t})}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionPingResponse=(t,e)=>{const{id:r}=e,i=wi("session_ping",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);setTimeout((()=>{Fu(e)?this.events.emit(wi("session_ping",r),{}):Ku(e)&&this.events.emit(wi("session_ping",r),{error:e.error})}),500)},this.onSessionDeleteRequest=async(t,e)=>{const{id:r}=e;try{this.isValidDisconnect({topic:t,reason:e.params}),await Promise.all([new Promise((e=>{this.client.core.relayer.once(kl,(async()=>{e(await this.deleteSession({topic:t,id:r}))}))})),this.sendResult({id:r,topic:t,result:!0,throwOnFailedPublish:!0}),this.cleanupPendingSentRequestsForTopic({topic:t,error:$h("USER_DISCONNECTED")})])}catch(t){this.client.logger.error(t)}},this.onSessionRequest=async(t,e)=>{var r;const{id:i,params:n}=e;try{await this.isValidRequest(Lm({topic:t},n));const e=dh(JSON.stringify(Ru("wc_sessionRequest",n,i))),s=this.client.session.get(t),o={id:i,topic:t,params:n,verifyContext:await this.getVerifyContext(e,s.peer.metadata)};await this.setPendingSessionRequest(o),null!=(r=this.client.signConfig)&&r.disableRequestQueue?this.emitSessionRequest(o):(this.addSessionRequestToSessionRequestQueue(o),this.processSessionRequestQueue())}catch(e){await this.sendError({id:i,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionRequestResponse=(t,e)=>{const{id:r}=e,i=wi("session_request",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);Fu(e)?this.events.emit(wi("session_request",r),{result:e.result}):Ku(e)&&this.events.emit(wi("session_request",r),{error:e.error})},this.onSessionEventRequest=async(t,e)=>{const{id:r,params:i}=e;try{const e=`${t}_session_event_${i.event.name}`,n=du.get(e);if(n&&this.isRequestOutOfSync(n,r))return void this.client.logger.info(`Discarding out of sync request - ${r}`);this.isValidEmit(Lm({topic:t},i)),this.client.events.emit("session_event",{id:r,topic:t,params:i}),du.set(e,r)}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionAuthenticateResponse=(t,e)=>{const{id:r}=e;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:t,payload:e}),Fu(e)?this.events.emit(wi("session_request",r),{result:e.result}):Ku(e)&&this.events.emit(wi("session_request",r),{error:e.error})},this.onSessionAuthenticateRequest=async(t,e)=>{try{const{requester:r,authPayload:i,expiryTimestamp:n}=e.params,s=dh(JSON.stringify(e)),o=await this.getVerifyContext(s,this.client.metadata),a={requester:r,pairingTopic:t,id:e.id,authPayload:i,verifyContext:o,expiryTimestamp:n};await this.setAuthRequest(e.id,{request:a,pairingTopic:t}),this.client.events.emit("session_authenticate",{topic:t,params:e.params,id:e.id,verifyContext:o})}catch(r){this.client.logger.error(r);const i={type:1,receiverPublicKey:e.params.requester.publicKey,senderPublicKey:await this.client.core.crypto.generateKeyPair()};await this.sendError({id:e.id,topic:t,error:r,encodeOpts:i,rpcOpts:Am.wc_sessionAuthenticate.autoReject})}},this.addSessionRequestToSessionRequestQueue=t=>{this.sessionRequestQueue.queue.push(t)},this.cleanupAfterResponse=t=>{this.deletePendingSessionRequest(t.response.id,{message:"fulfilled",code:0}),setTimeout((()=>{this.sessionRequestQueue.state=Sm,this.processSessionRequestQueue()}),(0,Y.toMiliseconds)(this.requestQueueDelay))},this.cleanupPendingSentRequestsForTopic=({topic:t,error:e})=>{const r=this.client.core.history.pending;r.length>0&&r.filter((e=>e.topic===t&&"wc_sessionRequest"===e.request.method)).forEach((t=>{const r=wi("session_request",t.request.id);if(0===this.events.listenerCount(r))throw new Error(`emitting ${r} without any listeners`);this.events.emit(wi("session_request",t.request.id),{error:e})}))},this.processSessionRequestQueue=()=>{if(this.sessionRequestQueue.state===Mm)return void this.client.logger.info("session request queue is already active.");const t=this.sessionRequestQueue.queue[0];if(t)try{this.sessionRequestQueue.state=Mm,this.emitSessionRequest(t)}catch(t){this.client.logger.error(t)}else this.client.logger.info("session request queue is empty.")},this.emitSessionRequest=t=>{this.client.events.emit("session_request",t)},this.onPairingCreated=t=>{if(t.methods&&this.expectedPairingMethodMap.set(t.topic,t.methods),t.active)return;const e=this.client.proposal.getAll().find((e=>e.pairingTopic===t.topic));e&&this.onSessionProposeRequest(t.topic,Ru("wc_sessionPropose",{requiredNamespaces:e.requiredNamespaces,optionalNamespaces:e.optionalNamespaces,relays:e.relays,proposer:e.proposer,sessionProperties:e.sessionProperties},e.id))},this.isValidConnect=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(t)}`);throw new Error(e)}const{pairingTopic:e,requiredNamespaces:r,optionalNamespaces:i,sessionProperties:n,relays:s}=t;if(Qh(e)||await this.isValidPairingTopic(e),!function(t,e){let r=!1;return t?t&&Jh(t)&&t.length&&t.forEach((t=>{r=su(t)})):r=!0,r}(s)){const{message:t}=Wh("MISSING_OR_INVALID",`connect() relays: ${s}`);throw new Error(t)}!Qh(r)&&0!==Yh(r)&&this.validateNamespaces(r,"requiredNamespaces"),!Qh(i)&&0!==Yh(i)&&this.validateNamespaces(i,"optionalNamespaces"),Qh(n)||this.validateSessionProps(n,"sessionProperties")},this.validateNamespaces=(t,e)=>{const r=function(t,e,r){let i=null;if(t&&Yh(t)){const n=iu(t,e);n&&(i=n);const s=function(t,e,r){let i=null;return Object.entries(t).forEach((([t,n])=>{if(i)return;const s=function(t,e,r){let i=null;return Jh(e)&&e.length?e.forEach((t=>{i||tu(t)||(i=$h("UNSUPPORTED_CHAINS",`${r}, chain ${t} should be a string and conform to "namespace:chainId" format`))})):tu(t)||(i=$h("UNSUPPORTED_CHAINS",`${r}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),i}(t,Jr(t,n),`${e} ${r}`);s&&(i=s)})),i}(t,e,r);s&&(i=s)}else i=Wh("MISSING_OR_INVALID",`${e}, ${r} should be an object with data`);return i}(t,"connect()",e);if(r)throw new Error(r.message)},this.isValidApprove=async t=>{if(!ou(t))throw new Error(Wh("MISSING_OR_INVALID",`approve() params: ${t}`).message);const{id:e,namespaces:r,relayProtocol:i,sessionProperties:n}=t;this.checkRecentlyDeleted(e),await this.isValidProposalId(e);const s=this.client.proposal.get(e),o=nu(r,"approve()");if(o)throw new Error(o.message);const a=hu(s.requiredNamespaces,r,"approve()");if(a)throw new Error(a.message);if(!Xh(i,!0)){const{message:t}=Wh("MISSING_OR_INVALID",`approve() relayProtocol: ${i}`);throw new Error(t)}Qh(n)||this.validateSessionProps(n,"sessionProperties")},this.isValidReject=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`reject() params: ${t}`);throw new Error(e)}const{id:e,reason:r}=t;if(this.checkRecentlyDeleted(e),await this.isValidProposalId(e),!function(t){return!!(t&&"object"==typeof t&&t.code&&Zh(t.code,!1)&&t.message&&Xh(t.message,!1))}(r)){const{message:t}=Wh("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(r)}`);throw new Error(t)}},this.isValidSessionSettleRequest=t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${t}`);throw new Error(e)}const{relay:e,controller:r,namespaces:i,expiry:n}=t;if(!su(e)){const{message:t}=Wh("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(t)}const s=function(t,e){let r=null;return Xh(t?.publicKey,!1)||(r=Wh("MISSING_OR_INVALID","onSessionSettleRequest() controller public key should be a string")),r}(r);if(s)throw new Error(s.message);const o=nu(i,"onSessionSettleRequest()");if(o)throw new Error(o.message);if(vi(n)){const{message:t}=Wh("EXPIRED","onSessionSettleRequest()");throw new Error(t)}},this.isValidUpdate=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`update() params: ${t}`);throw new Error(e)}const{topic:e,namespaces:r}=t;this.checkRecentlyDeleted(e),await this.isValidSessionTopic(e);const i=this.client.session.get(e),n=nu(r,"update()");if(n)throw new Error(n.message);const s=hu(i.requiredNamespaces,r,"update()");if(s)throw new Error(s.message)},this.isValidExtend=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`extend() params: ${t}`);throw new Error(e)}const{topic:e}=t;this.checkRecentlyDeleted(e),await this.isValidSessionTopic(e)},this.isValidRequest=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`request() params: ${t}`);throw new Error(e)}const{topic:e,request:r,chainId:i,expiry:n}=t;this.checkRecentlyDeleted(e),await this.isValidSessionTopic(e);const{namespaces:s}=this.client.session.get(e);if(!au(s,i)){const{message:t}=Wh("MISSING_OR_INVALID",`request() chainId: ${i}`);throw new Error(t)}if(!function(t){return!(Qh(t)||!Xh(t.method,!1))}(r)){const{message:t}=Wh("MISSING_OR_INVALID",`request() ${JSON.stringify(r)}`);throw new Error(t)}if(!function(t,e,r){return!!Xh(r,!1)&&function(t,e){const r=[];return Object.values(t).forEach((t=>{jh(t.accounts).includes(e)&&r.push(...t.methods)})),r}(t,e).includes(r)}(s,i,r.method)){const{message:t}=Wh("MISSING_OR_INVALID",`request() method: ${r.method}`);throw new Error(t)}if(n&&!cu(n,Em)){const{message:t}=Wh("MISSING_OR_INVALID",`request() expiry: ${n}. Expiry must be a number (in seconds) between ${Em.min} and ${Em.max}`);throw new Error(t)}},this.isValidRespond=async t=>{var e;if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`respond() params: ${t}`);throw new Error(e)}const{topic:r,response:i}=t;try{await this.isValidSessionTopic(r)}catch(r){throw null!=(e=t?.response)&&e.id&&this.cleanupAfterResponse(t),r}if(!function(t){return!(Qh(t)||Qh(t.result)&&Qh(t.error)||!Zh(t.id,!1)||!Xh(t.jsonrpc,!1))}(i)){const{message:t}=Wh("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(i)}`);throw new Error(t)}},this.isValidPing=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`ping() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidSessionOrPairingTopic(e)},this.isValidEmit=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`emit() params: ${t}`);throw new Error(e)}const{topic:e,event:r,chainId:i}=t;await this.isValidSessionTopic(e);const{namespaces:n}=this.client.session.get(e);if(!au(n,i)){const{message:t}=Wh("MISSING_OR_INVALID",`emit() chainId: ${i}`);throw new Error(t)}if(!function(t){return!(Qh(t)||!Xh(t.name,!1))}(r)){const{message:t}=Wh("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(r)}`);throw new Error(t)}if(!function(t,e,r){return!!Xh(r,!1)&&function(t,e){const r=[];return Object.values(t).forEach((t=>{jh(t.accounts).includes(e)&&r.push(...t.events)})),r}(t,e).includes(r)}(n,i,r.name)){const{message:t}=Wh("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(r)}`);throw new Error(t)}},this.isValidDisconnect=async t=>{if(!ou(t)){const{message:e}=Wh("MISSING_OR_INVALID",`disconnect() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidSessionOrPairingTopic(e)},this.isValidAuthenticate=t=>{const{chains:e,uri:r,domain:i,nonce:n}=t;if(!Array.isArray(e)||0===e.length)throw new Error("chains is required and must be a non-empty array");if(!Xh(r,!1))throw new Error("uri is required parameter");if(!Xh(i,!1))throw new Error("domain is required parameter");if(!Xh(n,!1))throw new Error("nonce is required parameter");if([...new Set(e.map((t=>$r(t).namespace)))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:s}=$r(e[0]);if("eip155"!==s)throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")},this.getVerifyContext=async(t,e)=>{const r={verified:{verifyUrl:e.verifyUrl||Zl,validation:"UNKNOWN",origin:e.url||""}};try{const i=await this.client.core.verify.resolve({attestationId:t,verifyUrl:e.verifyUrl});i&&(r.verified.origin=i.origin,r.verified.isScam=i.isScam,r.verified.validation=i.origin===new URL(e.url).origin?"VALID":"INVALID")}catch(t){this.client.logger.info(t)}return this.client.logger.info(`Verify context: ${JSON.stringify(r)}`),r},this.validateSessionProps=(t,e)=>{Object.values(t).forEach((t=>{if(!Xh(t,!1)){const{message:r}=Wh("MISSING_OR_INVALID",`${e} must be in Record format. Received: ${JSON.stringify(t)}`);throw new Error(r)}}))},this.getPendingAuthRequest=t=>{const e=this.client.auth.requests.get(t);return"object"==typeof e?e:void 0},this.addToRecentlyDeleted=(t,e)=>{if(this.recentlyDeletedMap.set(t,e),this.recentlyDeletedMap.size>=this.recentlyDeletedLimit){let t=0;const e=this.recentlyDeletedLimit/2;for(const r of this.recentlyDeletedMap.keys()){if(t++>=e)break;this.recentlyDeletedMap.delete(r)}}},this.checkRecentlyDeleted=t=>{const e=this.recentlyDeletedMap.get(t);if(e){const{message:r}=Wh("MISSING_OR_INVALID",`Record was recently deleted - ${e}: ${t}`);throw new Error(r)}}}async isInitialized(){if(!this.initialized){const{message:t}=Wh("NOT_INITIALIZED",this.name);throw new Error(t)}await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Rl,(t=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(t):this.onRelayMessage(t)}))}async onRelayMessage(t){const{topic:e,message:r}=t,{publicKey:i}=this.client.auth.authKeys.keys.includes(Nm)?this.client.auth.authKeys.get(Nm):{responseTopic:void 0,publicKey:void 0},n=await this.client.core.crypto.decode(e,r,{receiverPublicKey:i});try{ju(n)?(this.client.core.history.set(e,n),this.onRelayEventRequest({topic:e,payload:n})):zu(n)?(await this.client.core.history.resolve(n),await this.onRelayEventResponse({topic:e,payload:n}),this.client.core.history.delete(e,n.id)):this.onRelayEventUnknownPayload({topic:e,payload:n})}catch(t){this.client.logger.error(t)}}registerExpirerEvents(){this.client.core.expirer.on(Yl,(async t=>{const{topic:e,id:r}=mi(t.target);return r&&this.client.pendingRequest.keys.includes(r)?await this.deletePendingSessionRequest(r,Wh("EXPIRED"),!0):r&&this.client.auth.requests.keys.includes(r)?await this.deletePendingAuthRequest(r,Wh("EXPIRED"),!0):void(e?this.client.session.keys.includes(e)&&(await this.deleteSession({topic:e,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:e})):r&&(await this.deleteProposal(r,!0),this.client.events.emit("proposal_expire",{id:r})))}))}registerPairingEvents(){this.client.core.pairing.events.on(Kl,(t=>this.onPairingCreated(t))),this.client.core.pairing.events.on(Hl,(t=>{this.addToRecentlyDeleted(t.topic,"pairing")}))}isValidPairingTopic(t){if(!Xh(t,!1)){const{message:e}=Wh("MISSING_OR_INVALID",`pairing topic should be a string: ${t}`);throw new Error(e)}if(!this.client.core.pairing.pairings.keys.includes(t)){const{message:e}=Wh("NO_MATCHING_KEY",`pairing topic doesn't exist: ${t}`);throw new Error(e)}if(vi(this.client.core.pairing.pairings.get(t).expiry)){const{message:e}=Wh("EXPIRED",`pairing topic: ${t}`);throw new Error(e)}}async isValidSessionTopic(t){if(!Xh(t,!1)){const{message:e}=Wh("MISSING_OR_INVALID",`session topic should be a string: ${t}`);throw new Error(e)}if(this.checkRecentlyDeleted(t),!this.client.session.keys.includes(t)){const{message:e}=Wh("NO_MATCHING_KEY",`session topic doesn't exist: ${t}`);throw new Error(e)}if(vi(this.client.session.get(t).expiry)){await this.deleteSession({topic:t});const{message:e}=Wh("EXPIRED",`session topic: ${t}`);throw new Error(e)}if(!this.client.core.crypto.keychain.has(t)){const{message:e}=Wh("MISSING_OR_INVALID",`session topic does not exist in keychain: ${t}`);throw await this.deleteSession({topic:t}),new Error(e)}}async isValidSessionOrPairingTopic(t){if(this.checkRecentlyDeleted(t),this.client.session.keys.includes(t))await this.isValidSessionTopic(t);else{if(!this.client.core.pairing.pairings.keys.includes(t)){if(Xh(t,!1)){const{message:e}=Wh("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${t}`);throw new Error(e)}{const{message:e}=Wh("MISSING_OR_INVALID",`session or pairing topic should be a string: ${t}`);throw new Error(e)}}this.isValidPairingTopic(t)}}async isValidProposalId(t){if(!function(t){return"number"==typeof t}(t)){const{message:e}=Wh("MISSING_OR_INVALID",`proposal id should be a number: ${t}`);throw new Error(e)}if(!this.client.proposal.keys.includes(t)){const{message:e}=Wh("NO_MATCHING_KEY",`proposal id doesn't exist: ${t}`);throw new Error(e)}if(vi(this.client.proposal.get(t).expiryTimestamp)){await this.deleteProposal(t);const{message:e}=Wh("EXPIRED",`proposal id: ${t}`);throw new Error(e)}}}class Bm extends Of{constructor(t,e){super(t,e,"proposal",vm),this.core=t,this.logger=e}}class jm extends Of{constructor(t,e){super(t,e,"session",vm),this.core=t,this.logger=e}}class zm extends Of{constructor(t,e){super(t,e,"request",vm,(t=>t.id)),this.core=t,this.logger=e}}class Fm extends Of{constructor(t,e){super(t,e,"authKeys",xm,(()=>Nm)),this.core=t,this.logger=e}}class Km extends Of{constructor(t,e){super(t,e,"pairingTopics",xm),this.core=t,this.logger=e}}class Hm extends Of{constructor(t,e){super(t,e,"requests",xm,(t=>t.id)),this.core=t,this.logger=e}}class Vm{constructor(t,e){this.core=t,this.logger=e,this.authKeys=new Fm(this.core,this.logger),this.pairingTopics=new Km(this.core,this.logger),this.requests=new Hm(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}class Gm extends Tt{constructor(t){super(t),this.protocol="wc",this.version=2,this.name=wm,this.events=new y.EventEmitter,this.on=(t,e)=>this.events.on(t,e),this.once=(t,e)=>this.events.once(t,e),this.off=(t,e)=>this.events.off(t,e),this.removeListener=(t,e)=>this.events.removeListener(t,e),this.removeAllListeners=t=>this.events.removeAllListeners(t),this.connect=async t=>{try{return await this.engine.connect(t)}catch(t){throw this.logger.error(t.message),t}},this.pair=async t=>{try{return await this.engine.pair(t)}catch(t){throw this.logger.error(t.message),t}},this.approve=async t=>{try{return await this.engine.approve(t)}catch(t){throw this.logger.error(t.message),t}},this.reject=async t=>{try{return await this.engine.reject(t)}catch(t){throw this.logger.error(t.message),t}},this.update=async t=>{try{return await this.engine.update(t)}catch(t){throw this.logger.error(t.message),t}},this.extend=async t=>{try{return await this.engine.extend(t)}catch(t){throw this.logger.error(t.message),t}},this.request=async t=>{try{return await this.engine.request(t)}catch(t){throw this.logger.error(t.message),t}},this.respond=async t=>{try{return await this.engine.respond(t)}catch(t){throw this.logger.error(t.message),t}},this.ping=async t=>{try{return await this.engine.ping(t)}catch(t){throw this.logger.error(t.message),t}},this.emit=async t=>{try{return await this.engine.emit(t)}catch(t){throw this.logger.error(t.message),t}},this.disconnect=async t=>{try{return await this.engine.disconnect(t)}catch(t){throw this.logger.error(t.message),t}},this.find=t=>{try{return this.engine.find(t)}catch(t){throw this.logger.error(t.message),t}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(t){throw this.logger.error(t.message),t}},this.authenticate=async t=>{try{return await this.engine.authenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.formatAuthMessage=t=>{try{return this.engine.formatAuthMessage(t)}catch(t){throw this.logger.error(t.message),t}},this.approveSessionAuthenticate=async t=>{try{return await this.engine.approveSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.rejectSessionAuthenticate=async t=>{try{return await this.engine.rejectSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.name=t?.name||wm,this.metadata=t?.metadata||(0,Tr.g)()||{name:"",description:"",url:"",icons:[""]},this.signConfig=t?.signConfig;const e=typeof t?.logger<"u"&&"string"!=typeof t?.logger?t.logger:it()(wt({level:t?.logger||"error"}));this.core=t?.core||new Ff(t),this.logger=_t(e,this.name),this.session=new jm(this.core,this.logger),this.proposal=new Bm(this.core,this.logger),this.pendingRequest=new zm(this.core,this.logger),this.engine=new Dm(this),this.auth=new Vm(this.core,this.logger)}static async init(t){const e=new Gm(t);return await e.initialize(),e}get context(){return bt(this.logger)}get pairing(){return this.core.pairing.pairings}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.session.init(),await this.proposal.init(),await this.pendingRequest.init(),await this.engine.init(),await this.auth.init(),this.core.verify.init({verifyUrl:this.metadata.verifyUrl}),this.logger.info("SignClient Initialization Success"),this.engine.processRelayMessageCache()}catch(t){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(t.message),t}}}const Wm=jm,$m=Gm;var Jm,Ym={exports:{}},Qm="object"==typeof Reflect?Reflect:null,Xm=Qm&&"function"==typeof Qm.apply?Qm.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};Jm=Qm&&"function"==typeof Qm.ownKeys?Qm.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var Zm=Number.isNaN||function(t){return t!=t};function ty(){ty.init.call(this)}Ym.exports=ty,Ym.exports.once=function(t,e){return new Promise((function(r,i){function n(r){t.removeListener(e,s),i(r)}function s(){"function"==typeof t.removeListener&&t.removeListener("error",n),r([].slice.call(arguments))}cy(t,e,s,{once:!0}),"error"!==e&&function(t,e,r){"function"==typeof t.on&&cy(t,"error",e,{once:!0})}(t,n)}))},ty.EventEmitter=ty,ty.prototype._events=void 0,ty.prototype._eventsCount=0,ty.prototype._maxListeners=void 0;var ey=10;function ry(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function iy(t){return void 0===t._maxListeners?ty.defaultMaxListeners:t._maxListeners}function ny(t,e,r,i){var n,s,o;if(ry(r),void 0===(s=t._events)?(s=t._events=Object.create(null),t._eventsCount=0):(void 0!==s.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),o=s[e]),void 0===o)o=s[e]=r,++t._eventsCount;else if("function"==typeof o?o=s[e]=i?[r,o]:[o,r]:i?o.unshift(r):o.push(r),(n=iy(t))>0&&o.length>n&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=o.length,function(t){console&&console.warn&&console.warn(t)}(a)}return t}function sy(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function oy(t,e,r){var i={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},n=sy.bind(i);return n.listener=r,i.wrapFn=n,n}function ay(t,e,r){var i=t._events;if(void 0===i)return[];var n=i[e];return void 0===n?[]:"function"==typeof n?r?[n.listener||n]:[n]:r?function(t){for(var e=new Array(t.length),r=0;r0&&(s=e[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var a=n[t];if(void 0===a)return!1;if("function"==typeof a)Xm(a,this,e);else{var h=a.length,u=uy(a,h);for(r=0;r=0;s--)if(r[s]===e||r[s].listener===e){o=r[s].listener,n=s;break}if(n<0)return this;0===n?r.shift():function(t,e){for(;e+1=0;i--)this.removeListener(t,e[i]);return this},ty.prototype.listeners=function(t){return ay(this,t,!0)},ty.prototype.rawListeners=function(t){return ay(this,t,!1)},ty.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):hy.call(t,e)},ty.prototype.listenerCount=hy,ty.prototype.eventNames=function(){return this._eventsCount>0?Jm(this._events):[]};Ym.exports;class ly{constructor(t){this.opts=t}}class fy{constructor(t){this.client=t}}var dy=Object.defineProperty,py=Object.defineProperties,gy=Object.getOwnPropertyDescriptors,my=Object.getOwnPropertySymbols,yy=Object.prototype.hasOwnProperty,vy=Object.prototype.propertyIsEnumerable,wy=(t,e,r)=>e in t?dy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;class by extends fy{constructor(t){super(t),this.init=async()=>{this.signClient=await $m.init({core:this.client.core,metadata:this.client.metadata,signConfig:this.client.signConfig}),this.authClient=await mm.init({core:this.client.core,projectId:"",metadata:this.client.metadata})},this.pair=async t=>{await this.client.core.pairing.pair(t)},this.approveSession=async t=>{const{topic:e,acknowledged:r}=await this.signClient.approve(((t,e)=>py(t,gy(e)))(((t,e)=>{for(var r in e||(e={}))yy.call(e,r)&&wy(t,r,e[r]);if(my)for(var r of my(e))vy.call(e,r)&&wy(t,r,e[r]);return t})({},t),{id:t.id,namespaces:t.namespaces,sessionProperties:t.sessionProperties,sessionConfig:t.sessionConfig}));return await r(),this.signClient.session.get(e)},this.rejectSession=async t=>await this.signClient.reject(t),this.updateSession=async t=>await this.signClient.update(t),this.extendSession=async t=>await this.signClient.extend(t),this.respondSessionRequest=async t=>await this.signClient.respond(t),this.disconnectSession=async t=>await this.signClient.disconnect(t),this.emitSessionEvent=async t=>await this.signClient.emit(t),this.getActiveSessions=()=>this.signClient.session.getAll().reduce(((t,e)=>(t[e.topic]=e,t)),{}),this.getPendingSessionProposals=()=>this.signClient.proposal.getAll(),this.getPendingSessionRequests=()=>this.signClient.getPendingSessionRequests(),this.respondAuthRequest=async(t,e)=>await this.authClient.respond(t,e),this.getPendingAuthRequests=()=>this.authClient.requests.getAll().filter((t=>"requester"in t)),this.formatMessage=(t,e)=>this.authClient.formatMessage(t,e),this.approveSessionAuthenticate=async t=>await this.signClient.approveSessionAuthenticate(t),this.rejectSessionAuthenticate=async t=>await this.signClient.rejectSessionAuthenticate(t),this.formatAuthMessage=t=>this.signClient.formatAuthMessage(t),this.registerDeviceToken=t=>this.client.core.echoClient.registerDeviceToken(t),this.on=(t,e)=>(this.setEvent(t,"off"),this.setEvent(t,"on"),this.client.events.on(t,e)),this.once=(t,e)=>(this.setEvent(t,"off"),this.setEvent(t,"once"),this.client.events.once(t,e)),this.off=(t,e)=>(this.setEvent(t,"off"),this.client.events.off(t,e)),this.removeListener=(t,e)=>(this.setEvent(t,"removeListener"),this.client.events.removeListener(t,e)),this.onSessionRequest=t=>{this.client.events.emit("session_request",t)},this.onSessionProposal=t=>{this.client.events.emit("session_proposal",t)},this.onSessionDelete=t=>{this.client.events.emit("session_delete",t)},this.onAuthRequest=t=>{this.client.events.emit("auth_request",t)},this.onProposalExpire=t=>{this.client.events.emit("proposal_expire",t)},this.onSessionRequestExpire=t=>{this.client.events.emit("session_request_expire",t)},this.onSessionRequestAuthenticate=t=>{this.client.events.emit("session_authenticate",t)},this.setEvent=(t,e)=>{switch(t){case"session_request":this.signClient.events[e]("session_request",this.onSessionRequest);break;case"session_proposal":this.signClient.events[e]("session_proposal",this.onSessionProposal);break;case"session_delete":this.signClient.events[e]("session_delete",this.onSessionDelete);break;case"auth_request":this.authClient[e]("auth_request",this.onAuthRequest);break;case"proposal_expire":this.signClient.events[e]("proposal_expire",this.onProposalExpire);break;case"session_request_expire":this.signClient.events[e]("session_request_expire",this.onSessionRequestExpire);break;case"session_authenticate":this.signClient.events[e]("session_authenticate",this.onSessionRequestAuthenticate)}},this.signClient={},this.authClient={}}}const _y={decryptMessage:async t=>{const e={core:new Ff({storageOptions:t.storageOptions,storage:t.storage})};await e.core.crypto.init();const r=e.core.crypto.decode(t.topic,t.encryptedMessage);return e.core=null,r},getMetadata:async t=>{const e={core:new Ff({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new Wm(e.core,e.core.logger),await e.sessionStore.init();const r=e.sessionStore.get(t.topic),i=r?.peer.metadata;return e.core=null,e.sessionStore=null,i}},Ay=class extends ly{constructor(t){super(t),this.events=new Ym.exports,this.on=(t,e)=>this.engine.on(t,e),this.once=(t,e)=>this.engine.once(t,e),this.off=(t,e)=>this.engine.off(t,e),this.removeListener=(t,e)=>this.engine.removeListener(t,e),this.pair=async t=>{try{return await this.engine.pair(t)}catch(t){throw this.logger.error(t.message),t}},this.approveSession=async t=>{try{return await this.engine.approveSession(t)}catch(t){throw this.logger.error(t.message),t}},this.rejectSession=async t=>{try{return await this.engine.rejectSession(t)}catch(t){throw this.logger.error(t.message),t}},this.updateSession=async t=>{try{return await this.engine.updateSession(t)}catch(t){throw this.logger.error(t.message),t}},this.extendSession=async t=>{try{return await this.engine.extendSession(t)}catch(t){throw this.logger.error(t.message),t}},this.respondSessionRequest=async t=>{try{return await this.engine.respondSessionRequest(t)}catch(t){throw this.logger.error(t.message),t}},this.disconnectSession=async t=>{try{return await this.engine.disconnectSession(t)}catch(t){throw this.logger.error(t.message),t}},this.emitSessionEvent=async t=>{try{return await this.engine.emitSessionEvent(t)}catch(t){throw this.logger.error(t.message),t}},this.getActiveSessions=()=>{try{return this.engine.getActiveSessions()}catch(t){throw this.logger.error(t.message),t}},this.getPendingSessionProposals=()=>{try{return this.engine.getPendingSessionProposals()}catch(t){throw this.logger.error(t.message),t}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(t){throw this.logger.error(t.message),t}},this.respondAuthRequest=async(t,e)=>{try{return await this.engine.respondAuthRequest(t,e)}catch(t){throw this.logger.error(t.message),t}},this.getPendingAuthRequests=()=>{try{return this.engine.getPendingAuthRequests()}catch(t){throw this.logger.error(t.message),t}},this.formatMessage=(t,e)=>{try{return this.engine.formatMessage(t,e)}catch(t){throw this.logger.error(t.message),t}},this.registerDeviceToken=t=>{try{return this.engine.registerDeviceToken(t)}catch(t){throw this.logger.error(t.message),t}},this.approveSessionAuthenticate=t=>{try{return this.engine.approveSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.rejectSessionAuthenticate=t=>{try{return this.engine.rejectSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.formatAuthMessage=t=>{try{return this.engine.formatAuthMessage(t)}catch(t){throw this.logger.error(t.message),t}},this.metadata=t.metadata,this.name=t.name||"Web3Wallet",this.signConfig=t.signConfig,this.core=t.core,this.logger=this.core.logger,this.engine=new by(this)}static async init(t){const e=new Ay(t);return await e.initialize(),e}async initialize(){this.logger.trace("Initialized");try{await this.engine.init(),this.logger.info("Web3Wallet Initialization Success")}catch(t){throw this.logger.info("Web3Wallet Initialization Failure"),this.logger.error(t.message),t}}};let Ey=Ay;Ey.notifications=_y;const Sy=Ey;window.wc={core:null,web3wallet:null,statusObject:null,init:function(t){return new Promise((async(e,r)=>{if(!window.statusq){const t='missing window.statusq! Forgot to execute "ui/app/AppLayouts/Wallet/services/dapps/helpers.js" first?';console.error(t),r(t)}if(window.statusq.error){const t="Failed initializing WebChannel: "+window.statusq.error;console.error(t),r(t)}if(wc.statusObject=window.statusq.channel.objects.statusObject,!wc.statusObject){const t="Failed initializing WebChannel or initialization not run";console.error(t),r(t)}try{const r=new Ff({projectId:t});window.wc.web3wallet=await Sy.init({core:r,metadata:{name:"Status",description:"Status Wallet",url:"http://localhost",icons:["https://avatars.githubusercontent.com/u/11767950"]}}),window.wc.core=r,window.wc.web3wallet.on("session_proposal",(t=>{wc.statusObject.onSessionProposal(t)})),window.wc.web3wallet.on("session_update",(t=>{wc.statusObject.onSessionUpdate(t)})),window.wc.web3wallet.on("session_extend",(t=>{wc.statusObject.onSessionExtend(t)})),window.wc.web3wallet.on("session_ping",(t=>{wc.statusObject.onSessionPing(t)})),window.wc.web3wallet.on("session_delete",(t=>{wc.statusObject.onSessionDelete(t)})),window.wc.web3wallet.on("session_expire",(t=>{wc.statusObject.onSessionExpire(t)})),window.wc.web3wallet.on("session_request",(t=>{wc.statusObject.onSessionRequest(t)})),window.wc.web3wallet.on("session_request_sent",(t=>{wc.statusObject.onSessionRequestSent(t)})),window.wc.web3wallet.on("session_event",(t=>{wc.statusObject.onSessionEvent(t)})),window.wc.web3wallet.on("proposal_expire",(t=>{wc.statusObject.onProposalExpire(t)})),window.wc.web3wallet.on("pairing_expire",(t=>{wc.statusObject.echo("debug",`WC unhandled event: "pairing_expire" ${JSON.stringify(t)}`)})),window.wc.web3wallet.on("session_request_expire",(t=>{wc.statusObject.echo("debug",`WC unhandled event: "session_request_expire" ${JSON.stringify(t)}`)})),window.wc.core.relayer.on("relayer_connect",(()=>{wc.statusObject.echo("debug",'WC unhandled event: "relayer_connect" connection to the relay server is established')})),window.wc.core.relayer.on("relayer_disconnect",(()=>{wc.statusObject.echo("debug",'WC unhandled event: "relayer_disconnect" connection to the relay server is lost')})),e("")}catch(t){r(t)}}))},pair:async function(t){await window.wc.web3wallet.pair({uri:t})},getPairings:function(){return window.wc.web3wallet.core.pairing.getPairings()},getActiveSessions:function(){return window.wc.web3wallet.getActiveSessions()},disconnect:async function(t){await window.wc.web3wallet.disconnectSession({topic:t,reason:$h("USER_DISCONNECTED")})},ping:async function(t){await window.wc.web3wallet.engine.signClient.ping({topic:t})},buildApprovedNamespaces:async function(t,e){return function(t){const{proposal:{requiredNamespaces:e,optionalNamespaces:r={}},supportedNamespaces:i}=t,n=Kh(e),s=Kh(r),o={};Object.keys(i).forEach((t=>{const e=i[t].chains,r=i[t].methods,n=i[t].events,s=i[t].accounts;e.forEach((e=>{if(!s.some((t=>t.includes(e))))throw new Error(`No accounts provided for chain ${e} in namespace ${t}`)})),o[t]={chains:e,methods:r,events:n,accounts:s}}));const a=hu(e,o,"approve()");if(a)throw new Error(a.message);const h={};return Object.keys(e).length||Object.keys(r).length?(Object.keys(n).forEach((t=>{const e=i[t].chains.filter((e=>{var r,i;return null==(i=null==(r=n[t])?void 0:r.chains)?void 0:i.includes(e)})),r=i[t].methods.filter((e=>{var r,i;return null==(i=null==(r=n[t])?void 0:r.methods)?void 0:i.includes(e)})),s=i[t].events.filter((e=>{var r,i;return null==(i=null==(r=n[t])?void 0:r.events)?void 0:i.includes(e)})),o=e.map((e=>i[t].accounts.filter((t=>t.includes(`${e}:`))))).flat();h[t]={chains:e,methods:r,events:s,accounts:o}})),Object.keys(s).forEach((t=>{var e,r,n,o,a,u;if(!i[t])return;const c=null==(r=null==(e=s[t])?void 0:e.chains)?void 0:r.filter((e=>i[t].chains.includes(e))),l=i[t].methods.filter((e=>{var r,i;return null==(i=null==(r=s[t])?void 0:r.methods)?void 0:i.includes(e)})),f=i[t].events.filter((e=>{var r,i;return null==(i=null==(r=s[t])?void 0:r.events)?void 0:i.includes(e)})),d=c?.map((e=>i[t].accounts.filter((t=>t.includes(`${e}:`))))).flat();h[t]={chains:bi(null==(n=h[t])?void 0:n.chains,c),methods:bi(null==(o=h[t])?void 0:o.methods,l),events:bi(null==(a=h[t])?void 0:a.events,f),accounts:bi(null==(u=h[t])?void 0:u.accounts,d)}})),h):o}({proposal:t,supportedNamespaces:e})},approveSession:async function(t,e){const{id:r,params:i}=t,{relays:n}=i;return await window.wc.web3wallet.approveSession({id:r,relayProtocol:n[0].protocol,namespaces:e})},rejectSession:async function(t){await window.wc.web3wallet.rejectSession({id:t,reason:$h("USER_REJECTED")})},respondSessionRequest:async function(t,e,r){const i=Cu(e,r);await window.wc.web3wallet.respondSessionRequest({topic:t,response:i})},rejectSessionRequest:async function(t,e,r=!1){const i=r?"SESSION_SETTLEMENT_FAILED":"USER_REJECTED";await window.wc.web3wallet.respondSessionRequest({topic:t,response:Tu(e,$h(i))})}}; \ No newline at end of file +var t={972:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(4512);function n(t,e,r){return void 0===e&&(e=new Uint8Array(2)),void 0===r&&(r=0),e[r+0]=t>>>8,e[r+1]=t>>>0,e}function s(t,e,r){return void 0===e&&(e=new Uint8Array(2)),void 0===r&&(r=0),e[r+0]=t>>>0,e[r+1]=t>>>8,e}function o(t,e){return void 0===e&&(e=0),t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3]}function a(t,e){return void 0===e&&(e=0),(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}function h(t,e){return void 0===e&&(e=0),t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function c(t,e){return void 0===e&&(e=0),(t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e])>>>0}function f(t,e,r){return void 0===e&&(e=new Uint8Array(4)),void 0===r&&(r=0),e[r+0]=t>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=t>>>0,e}function u(t,e,r){return void 0===e&&(e=new Uint8Array(4)),void 0===r&&(r=0),e[r+0]=t>>>0,e[r+1]=t>>>8,e[r+2]=t>>>16,e[r+3]=t>>>24,e}function d(t,e,r){return void 0===e&&(e=new Uint8Array(8)),void 0===r&&(r=0),f(t/4294967296>>>0,e,r),f(t>>>0,e,r+4),e}function l(t,e,r){return void 0===e&&(e=new Uint8Array(8)),void 0===r&&(r=0),u(t>>>0,e,r),u(t/4294967296>>>0,e,r+4),e}e.readInt16BE=function(t,e){return void 0===e&&(e=0),(t[e+0]<<8|t[e+1])<<16>>16},e.readUint16BE=function(t,e){return void 0===e&&(e=0),(t[e+0]<<8|t[e+1])>>>0},e.readInt16LE=function(t,e){return void 0===e&&(e=0),(t[e+1]<<8|t[e])<<16>>16},e.readUint16LE=function(t,e){return void 0===e&&(e=0),(t[e+1]<<8|t[e])>>>0},e.writeUint16BE=n,e.writeInt16BE=n,e.writeUint16LE=s,e.writeInt16LE=s,e.readInt32BE=o,e.readUint32BE=a,e.readInt32LE=h,e.readUint32LE=c,e.writeUint32BE=f,e.writeInt32BE=f,e.writeUint32LE=u,e.writeInt32LE=u,e.readInt64BE=function(t,e){void 0===e&&(e=0);var r=o(t,e),i=o(t,e+4);return 4294967296*r+i-4294967296*(i>>31)},e.readUint64BE=function(t,e){return void 0===e&&(e=0),4294967296*a(t,e)+a(t,e+4)},e.readInt64LE=function(t,e){void 0===e&&(e=0);var r=h(t,e);return 4294967296*h(t,e+4)+r-4294967296*(r>>31)},e.readUint64LE=function(t,e){void 0===e&&(e=0);var r=c(t,e);return 4294967296*c(t,e+4)+r},e.writeUint64BE=d,e.writeInt64BE=d,e.writeUint64LE=l,e.writeInt64LE=l,e.readUintBE=function(t,e,r){if(void 0===r&&(r=0),t%8!=0)throw new Error("readUintBE supports only bitLengths divisible by 8");if(t/8>e.length-r)throw new Error("readUintBE: array is too short for the given bitLength");for(var i=0,n=1,s=t/8+r-1;s>=r;s--)i+=e[s]*n,n*=256;return i},e.readUintLE=function(t,e,r){if(void 0===r&&(r=0),t%8!=0)throw new Error("readUintLE supports only bitLengths divisible by 8");if(t/8>e.length-r)throw new Error("readUintLE: array is too short for the given bitLength");for(var i=0,n=1,s=r;s=n;o--)r[o]=e/s&255,s*=256;return r},e.writeUintLE=function(t,e,r,n){if(void 0===r&&(r=new Uint8Array(t/8)),void 0===n&&(n=0),t%8!=0)throw new Error("writeUintLE supports only bitLengths divisible by 8");if(!i.isSafeInteger(e))throw new Error("writeUintLE value must be an integer");for(var s=1,o=n;o{Object.defineProperty(e,"__esModule",{value:!0});var i=r(972),n=r(6228),s=20;function o(t,e,r){for(var n=1634760805,o=857760878,a=2036477234,h=1797285236,c=r[3]<<24|r[2]<<16|r[1]<<8|r[0],f=r[7]<<24|r[6]<<16|r[5]<<8|r[4],u=r[11]<<24|r[10]<<16|r[9]<<8|r[8],d=r[15]<<24|r[14]<<16|r[13]<<8|r[12],l=r[19]<<24|r[18]<<16|r[17]<<8|r[16],p=r[23]<<24|r[22]<<16|r[21]<<8|r[20],g=r[27]<<24|r[26]<<16|r[25]<<8|r[24],m=r[31]<<24|r[30]<<16|r[29]<<8|r[28],b=e[3]<<24|e[2]<<16|e[1]<<8|e[0],y=e[7]<<24|e[6]<<16|e[5]<<8|e[4],v=e[11]<<24|e[10]<<16|e[9]<<8|e[8],w=e[15]<<24|e[14]<<16|e[13]<<8|e[12],_=n,A=o,M=a,S=h,E=c,I=f,x=u,O=d,N=l,P=p,R=g,T=m,C=b,k=y,L=v,q=w,U=0;U>>16|C<<16)|0)>>>20|E<<12,I=(I^=P=P+(k=(k^=A=A+I|0)>>>16|k<<16)|0)>>>20|I<<12,x=(x^=R=R+(L=(L^=M=M+x|0)>>>16|L<<16)|0)>>>20|x<<12,O=(O^=T=T+(q=(q^=S=S+O|0)>>>16|q<<16)|0)>>>20|O<<12,x=(x^=R=R+(L=(L^=M=M+x|0)>>>24|L<<8)|0)>>>25|x<<7,O=(O^=T=T+(q=(q^=S=S+O|0)>>>24|q<<8)|0)>>>25|O<<7,I=(I^=P=P+(k=(k^=A=A+I|0)>>>24|k<<8)|0)>>>25|I<<7,E=(E^=N=N+(C=(C^=_=_+E|0)>>>24|C<<8)|0)>>>25|E<<7,I=(I^=R=R+(q=(q^=_=_+I|0)>>>16|q<<16)|0)>>>20|I<<12,x=(x^=T=T+(C=(C^=A=A+x|0)>>>16|C<<16)|0)>>>20|x<<12,O=(O^=N=N+(k=(k^=M=M+O|0)>>>16|k<<16)|0)>>>20|O<<12,E=(E^=P=P+(L=(L^=S=S+E|0)>>>16|L<<16)|0)>>>20|E<<12,O=(O^=N=N+(k=(k^=M=M+O|0)>>>24|k<<8)|0)>>>25|O<<7,E=(E^=P=P+(L=(L^=S=S+E|0)>>>24|L<<8)|0)>>>25|E<<7,x=(x^=T=T+(C=(C^=A=A+x|0)>>>24|C<<8)|0)>>>25|x<<7,I=(I^=R=R+(q=(q^=_=_+I|0)>>>24|q<<8)|0)>>>25|I<<7;i.writeUint32LE(_+n|0,t,0),i.writeUint32LE(A+o|0,t,4),i.writeUint32LE(M+a|0,t,8),i.writeUint32LE(S+h|0,t,12),i.writeUint32LE(E+c|0,t,16),i.writeUint32LE(I+f|0,t,20),i.writeUint32LE(x+u|0,t,24),i.writeUint32LE(O+d|0,t,28),i.writeUint32LE(N+l|0,t,32),i.writeUint32LE(P+p|0,t,36),i.writeUint32LE(R+g|0,t,40),i.writeUint32LE(T+m|0,t,44),i.writeUint32LE(C+b|0,t,48),i.writeUint32LE(k+y|0,t,52),i.writeUint32LE(L+v|0,t,56),i.writeUint32LE(q+w|0,t,60)}function a(t,e,r,i,s){if(void 0===s&&(s=0),32!==t.length)throw new Error("ChaCha: key size must be 32 bytes");if(i.length>>=8,e++;if(i>0)throw new Error("ChaCha: counter overflow")}e.streamXOR=a,e.stream=function(t,e,r,i){return void 0===i&&(i=0),n.wipe(r),a(t,e,r,r,i)}},1612:(t,e,r)=>{var i=r(9918),n=r(7360),s=r(6228),o=r(972),a=r(6452);e.J4=32,e.PX=12,e.iW=16;var h=new Uint8Array(16),c=function(){function t(t){if(this.nonceLength=e.PX,this.tagLength=e.iW,t.length!==e.J4)throw new Error("ChaCha20Poly1305 needs 32-byte key");this._key=new Uint8Array(t)}return t.prototype.seal=function(t,e,r,n){if(t.length>16)throw new Error("ChaCha20Poly1305: incorrect nonce length");var o=new Uint8Array(16);o.set(t,o.length-t.length);var a=new Uint8Array(32);i.stream(this._key,o,a,4);var h,c=e.length+this.tagLength;if(n){if(n.length!==c)throw new Error("ChaCha20Poly1305: incorrect destination length");h=n}else h=new Uint8Array(c);return i.streamXOR(this._key,o,e,h,4),this._authenticate(h.subarray(h.length-this.tagLength,h.length),a,h.subarray(0,h.length-this.tagLength),r),s.wipe(o),h},t.prototype.open=function(t,e,r,n){if(t.length>16)throw new Error("ChaCha20Poly1305: incorrect nonce length");if(e.length0&&a.update(h.subarray(i.length%16))),a.update(r),r.length%16>0&&a.update(h.subarray(r.length%16));var c=new Uint8Array(8);i&&o.writeUint64LE(i.length,c),a.update(c),o.writeUint64LE(r.length,c),a.update(c);for(var f=a.digest(),u=0;u{function r(t,e){if(t.length!==e.length)return 0;for(var r=0,i=0;i>>8}Object.defineProperty(e,"__esModule",{value:!0}),e.select=function(t,e,r){return~(t-1)&e|t-1&r},e.lessOrEqual=function(t,e){return(0|t)-(0|e)-1>>>31&1},e.compare=r,e.equal=function(t,e){return 0!==t.length&&0!==e.length&&0!==r(t,e)}},4904:(t,e,r)=>{e._S=e.K=e.TP=e.wE=e.Ee=void 0;r(7052);const i=r(4974);r(6228);function n(t){const e=new Float64Array(16);if(t)for(let r=0;r>16&1),r[t-1]&=65535;r[15]=i[15]-32767-(r[14]>>16&1);const t=r[15]>>16&1;r[14]&=65535,d(i,r,1-t)}for(let e=0;e<16;e++)t[2*e]=255&i[e],t[2*e+1]=i[e]>>8}function p(t){const e=new Uint8Array(32);return l(e,t),1&e[0]}function g(t,e,r){for(let i=0;i<16;i++)t[i]=e[i]+r[i]}function m(t,e,r){for(let i=0;i<16;i++)t[i]=e[i]-r[i]}function b(t,e,r){let i,n,s=0,o=0,a=0,h=0,c=0,f=0,u=0,d=0,l=0,p=0,g=0,m=0,b=0,y=0,v=0,w=0,_=0,A=0,M=0,S=0,E=0,I=0,x=0,O=0,N=0,P=0,R=0,T=0,C=0,k=0,L=0,q=r[0],U=r[1],B=r[2],D=r[3],z=r[4],j=r[5],F=r[6],K=r[7],V=r[8],H=r[9],W=r[10],J=r[11],G=r[12],$=r[13],Y=r[14],Q=r[15];i=e[0],s+=i*q,o+=i*U,a+=i*B,h+=i*D,c+=i*z,f+=i*j,u+=i*F,d+=i*K,l+=i*V,p+=i*H,g+=i*W,m+=i*J,b+=i*G,y+=i*$,v+=i*Y,w+=i*Q,i=e[1],o+=i*q,a+=i*U,h+=i*B,c+=i*D,f+=i*z,u+=i*j,d+=i*F,l+=i*K,p+=i*V,g+=i*H,m+=i*W,b+=i*J,y+=i*G,v+=i*$,w+=i*Y,_+=i*Q,i=e[2],a+=i*q,h+=i*U,c+=i*B,f+=i*D,u+=i*z,d+=i*j,l+=i*F,p+=i*K,g+=i*V,m+=i*H,b+=i*W,y+=i*J,v+=i*G,w+=i*$,_+=i*Y,A+=i*Q,i=e[3],h+=i*q,c+=i*U,f+=i*B,u+=i*D,d+=i*z,l+=i*j,p+=i*F,g+=i*K,m+=i*V,b+=i*H,y+=i*W,v+=i*J,w+=i*G,_+=i*$,A+=i*Y,M+=i*Q,i=e[4],c+=i*q,f+=i*U,u+=i*B,d+=i*D,l+=i*z,p+=i*j,g+=i*F,m+=i*K,b+=i*V,y+=i*H,v+=i*W,w+=i*J,_+=i*G,A+=i*$,M+=i*Y,S+=i*Q,i=e[5],f+=i*q,u+=i*U,d+=i*B,l+=i*D,p+=i*z,g+=i*j,m+=i*F,b+=i*K,y+=i*V,v+=i*H,w+=i*W,_+=i*J,A+=i*G,M+=i*$,S+=i*Y,E+=i*Q,i=e[6],u+=i*q,d+=i*U,l+=i*B,p+=i*D,g+=i*z,m+=i*j,b+=i*F,y+=i*K,v+=i*V,w+=i*H,_+=i*W,A+=i*J,M+=i*G,S+=i*$,E+=i*Y,I+=i*Q,i=e[7],d+=i*q,l+=i*U,p+=i*B,g+=i*D,m+=i*z,b+=i*j,y+=i*F,v+=i*K,w+=i*V,_+=i*H,A+=i*W,M+=i*J,S+=i*G,E+=i*$,I+=i*Y,x+=i*Q,i=e[8],l+=i*q,p+=i*U,g+=i*B,m+=i*D,b+=i*z,y+=i*j,v+=i*F,w+=i*K,_+=i*V,A+=i*H,M+=i*W,S+=i*J,E+=i*G,I+=i*$,x+=i*Y,O+=i*Q,i=e[9],p+=i*q,g+=i*U,m+=i*B,b+=i*D,y+=i*z,v+=i*j,w+=i*F,_+=i*K,A+=i*V,M+=i*H,S+=i*W,E+=i*J,I+=i*G,x+=i*$,O+=i*Y,N+=i*Q,i=e[10],g+=i*q,m+=i*U,b+=i*B,y+=i*D,v+=i*z,w+=i*j,_+=i*F,A+=i*K,M+=i*V,S+=i*H,E+=i*W,I+=i*J,x+=i*G,O+=i*$,N+=i*Y,P+=i*Q,i=e[11],m+=i*q,b+=i*U,y+=i*B,v+=i*D,w+=i*z,_+=i*j,A+=i*F,M+=i*K,S+=i*V,E+=i*H,I+=i*W,x+=i*J,O+=i*G,N+=i*$,P+=i*Y,R+=i*Q,i=e[12],b+=i*q,y+=i*U,v+=i*B,w+=i*D,_+=i*z,A+=i*j,M+=i*F,S+=i*K,E+=i*V,I+=i*H,x+=i*W,O+=i*J,N+=i*G,P+=i*$,R+=i*Y,T+=i*Q,i=e[13],y+=i*q,v+=i*U,w+=i*B,_+=i*D,A+=i*z,M+=i*j,S+=i*F,E+=i*K,I+=i*V,x+=i*H,O+=i*W,N+=i*J,P+=i*G,R+=i*$,T+=i*Y,C+=i*Q,i=e[14],v+=i*q,w+=i*U,_+=i*B,A+=i*D,M+=i*z,S+=i*j,E+=i*F,I+=i*K,x+=i*V,O+=i*H,N+=i*W,P+=i*J,R+=i*G,T+=i*$,C+=i*Y,k+=i*Q,i=e[15],w+=i*q,_+=i*U,A+=i*B,M+=i*D,S+=i*z,E+=i*j,I+=i*F,x+=i*K,O+=i*V,N+=i*H,P+=i*W,R+=i*J,T+=i*G,C+=i*$,k+=i*Y,L+=i*Q,s+=38*_,o+=38*A,a+=38*M,h+=38*S,c+=38*E,f+=38*I,u+=38*x,d+=38*O,l+=38*N,p+=38*P,g+=38*R,m+=38*T,b+=38*C,y+=38*k,v+=38*L,n=1,i=s+n+65535,n=Math.floor(i/65536),s=i-65536*n,i=o+n+65535,n=Math.floor(i/65536),o=i-65536*n,i=a+n+65535,n=Math.floor(i/65536),a=i-65536*n,i=h+n+65535,n=Math.floor(i/65536),h=i-65536*n,i=c+n+65535,n=Math.floor(i/65536),c=i-65536*n,i=f+n+65535,n=Math.floor(i/65536),f=i-65536*n,i=u+n+65535,n=Math.floor(i/65536),u=i-65536*n,i=d+n+65535,n=Math.floor(i/65536),d=i-65536*n,i=l+n+65535,n=Math.floor(i/65536),l=i-65536*n,i=p+n+65535,n=Math.floor(i/65536),p=i-65536*n,i=g+n+65535,n=Math.floor(i/65536),g=i-65536*n,i=m+n+65535,n=Math.floor(i/65536),m=i-65536*n,i=b+n+65535,n=Math.floor(i/65536),b=i-65536*n,i=y+n+65535,n=Math.floor(i/65536),y=i-65536*n,i=v+n+65535,n=Math.floor(i/65536),v=i-65536*n,i=w+n+65535,n=Math.floor(i/65536),w=i-65536*n,s+=n-1+37*(n-1),n=1,i=s+n+65535,n=Math.floor(i/65536),s=i-65536*n,i=o+n+65535,n=Math.floor(i/65536),o=i-65536*n,i=a+n+65535,n=Math.floor(i/65536),a=i-65536*n,i=h+n+65535,n=Math.floor(i/65536),h=i-65536*n,i=c+n+65535,n=Math.floor(i/65536),c=i-65536*n,i=f+n+65535,n=Math.floor(i/65536),f=i-65536*n,i=u+n+65535,n=Math.floor(i/65536),u=i-65536*n,i=d+n+65535,n=Math.floor(i/65536),d=i-65536*n,i=l+n+65535,n=Math.floor(i/65536),l=i-65536*n,i=p+n+65535,n=Math.floor(i/65536),p=i-65536*n,i=g+n+65535,n=Math.floor(i/65536),g=i-65536*n,i=m+n+65535,n=Math.floor(i/65536),m=i-65536*n,i=b+n+65535,n=Math.floor(i/65536),b=i-65536*n,i=y+n+65535,n=Math.floor(i/65536),y=i-65536*n,i=v+n+65535,n=Math.floor(i/65536),v=i-65536*n,i=w+n+65535,n=Math.floor(i/65536),w=i-65536*n,s+=n-1+37*(n-1),t[0]=s,t[1]=o,t[2]=a,t[3]=h,t[4]=c,t[5]=f,t[6]=u,t[7]=d,t[8]=l,t[9]=p,t[10]=g,t[11]=m,t[12]=b,t[13]=y,t[14]=v,t[15]=w}function y(t,e){b(t,e,e)}function v(t,e){const r=n(),i=n(),s=n(),o=n(),h=n(),c=n(),f=n(),u=n(),d=n();m(r,t[1],t[0]),m(d,e[1],e[0]),b(r,r,d),g(i,t[0],t[1]),g(d,e[0],e[1]),b(i,i,d),b(s,t[3],e[3]),b(s,s,a),b(o,t[2],e[2]),g(o,o,o),m(h,i,r),m(c,o,s),g(f,o,s),g(u,i,r),b(t[0],h,c),b(t[1],u,f),b(t[2],f,c),b(t[3],h,u)}function w(t,e,r){for(let i=0;i<4;i++)d(t[i],e[i],r)}function _(t,e){const r=n(),i=n(),s=n();(function(t,e){const r=n();let i;for(i=0;i<16;i++)r[i]=e[i];for(i=253;i>=0;i--)y(r,r),2!==i&&4!==i&&b(r,r,e);for(i=0;i<16;i++)t[i]=r[i]})(s,e[2]),b(r,e[0],s),b(i,e[1],s),l(t,i),t[31]^=p(r)<<7}function A(t,e){const r=[n(),n(),n(),n()];f(r[0],h),f(r[1],c),f(r[2],o),b(r[3],h,c),function(t,e,r){f(t[0],s),f(t[1],o),f(t[2],o),f(t[3],s);for(let i=255;i>=0;--i){const n=r[i/8|0]>>(7&i)&1;w(t,e,n),v(e,t),v(t,t),w(t,e,n)}}(t,r,e)}e.K=function(t){if(t.length!==e.TP)throw new Error(`ed25519: seed must be ${e.TP} bytes`);const r=(0,i.hash)(t);r[0]&=248,r[31]&=127,r[31]|=64;const s=new Uint8Array(32),o=[n(),n(),n(),n()];A(o,r),_(s,o);const a=new Uint8Array(64);return a.set(t),a.set(s,32),{publicKey:s,secretKey:a}};const M=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function S(t,e){let r,i,n,s;for(i=63;i>=32;--i){for(r=0,n=i-32,s=i-12;n>4)*M[n],r=e[n]>>8,e[n]&=255;for(n=0;n<32;n++)e[n]-=r*M[n];for(i=0;i<32;i++)e[i+1]+=e[i]>>8,t[i]=255&e[i]}function E(t){const e=new Float64Array(64);for(let r=0;r<64;r++)e[r]=t[r];for(let e=0;e<64;e++)t[e]=0;S(t,e)}e._S=function(t,e){const r=new Float64Array(64),s=[n(),n(),n(),n()],o=(0,i.hash)(t.subarray(0,32));o[0]&=248,o[31]&=127,o[31]|=64;const a=new Uint8Array(64);a.set(o.subarray(32),32);const h=new i.SHA512;h.update(a.subarray(32)),h.update(e);const c=h.digest();h.clean(),E(c),A(s,c),_(a,s),h.reset(),h.update(a.subarray(0,32)),h.update(t.subarray(32)),h.update(e);const f=h.digest();E(f);for(let t=0;t<32;t++)r[t]=c[t];for(let t=0;t<32;t++)for(let e=0;e<32;e++)r[t+e]+=f[t]*o[e];return S(a.subarray(32),r),a}},2670:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isSerializableHash=function(t){return void 0!==t.saveState&&void 0!==t.restoreState&&void 0!==t.cleanSavedState}},6804:(t,e,r)=>{var i=r(2412),n=r(6228),s=function(){function t(t,e,r,n){void 0===r&&(r=new Uint8Array(0)),this._counter=new Uint8Array(1),this._hash=t,this._info=n;var s=i.hmac(this._hash,r,e);this._hmac=new i.HMAC(t,s),this._buffer=new Uint8Array(this._hmac.digestLength),this._bufpos=this._buffer.length}return t.prototype._fillBuffer=function(){this._counter[0]++;var t=this._counter[0];if(0===t)throw new Error("hkdf: cannot expand more");this._hmac.reset(),t>1&&this._hmac.update(this._buffer),this._info&&this._hmac.update(this._info),this._hmac.update(this._counter),this._hmac.finish(this._buffer),this._bufpos=0},t.prototype.expand=function(t){for(var e=new Uint8Array(t),r=0;r{Object.defineProperty(e,"__esModule",{value:!0});var i=r(2670),n=r(6452),s=r(6228),o=function(){function t(t,e){this._finished=!1,this._inner=new t,this._outer=new t,this.blockSize=this._outer.blockSize,this.digestLength=this._outer.digestLength;var r=new Uint8Array(this.blockSize);e.length>this.blockSize?this._inner.update(e).finish(r).clean():r.set(e);for(var n=0;n{Object.defineProperty(e,"__esModule",{value:!0}),e.mul=Math.imul||function(t,e){var r=65535&t,i=65535&e;return r*i+((t>>>16&65535)*i+r*(e>>>16&65535)<<16>>>0)|0},e.add=function(t,e){return t+e|0},e.sub=function(t,e){return t-e|0},e.rotl=function(t,e){return t<>>32-e},e.rotr=function(t,e){return t<<32-e|t>>>e},e.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},e.MAX_SAFE_INTEGER=9007199254740991,e.isSafeInteger=function(t){return e.isInteger(t)&&t>=-e.MAX_SAFE_INTEGER&&t<=e.MAX_SAFE_INTEGER}},7360:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(6452),n=r(6228);e.DIGEST_LENGTH=16;var s=function(){function t(t){this.digestLength=e.DIGEST_LENGTH,this._buffer=new Uint8Array(16),this._r=new Uint16Array(10),this._h=new Uint16Array(10),this._pad=new Uint16Array(8),this._leftover=0,this._fin=0,this._finished=!1;var r=t[0]|t[1]<<8;this._r[0]=8191&r;var i=t[2]|t[3]<<8;this._r[1]=8191&(r>>>13|i<<3);var n=t[4]|t[5]<<8;this._r[2]=7939&(i>>>10|n<<6);var s=t[6]|t[7]<<8;this._r[3]=8191&(n>>>7|s<<9);var o=t[8]|t[9]<<8;this._r[4]=255&(s>>>4|o<<12),this._r[5]=o>>>1&8190;var a=t[10]|t[11]<<8;this._r[6]=8191&(o>>>14|a<<2);var h=t[12]|t[13]<<8;this._r[7]=8065&(a>>>11|h<<5);var c=t[14]|t[15]<<8;this._r[8]=8191&(h>>>8|c<<8),this._r[9]=c>>>5&127,this._pad[0]=t[16]|t[17]<<8,this._pad[1]=t[18]|t[19]<<8,this._pad[2]=t[20]|t[21]<<8,this._pad[3]=t[22]|t[23]<<8,this._pad[4]=t[24]|t[25]<<8,this._pad[5]=t[26]|t[27]<<8,this._pad[6]=t[28]|t[29]<<8,this._pad[7]=t[30]|t[31]<<8}return t.prototype._blocks=function(t,e,r){for(var i=this._fin?0:2048,n=this._h[0],s=this._h[1],o=this._h[2],a=this._h[3],h=this._h[4],c=this._h[5],f=this._h[6],u=this._h[7],d=this._h[8],l=this._h[9],p=this._r[0],g=this._r[1],m=this._r[2],b=this._r[3],y=this._r[4],v=this._r[5],w=this._r[6],_=this._r[7],A=this._r[8],M=this._r[9];r>=16;){var S=t[e+0]|t[e+1]<<8;n+=8191&S;var E=t[e+2]|t[e+3]<<8;s+=8191&(S>>>13|E<<3);var I=t[e+4]|t[e+5]<<8;o+=8191&(E>>>10|I<<6);var x=t[e+6]|t[e+7]<<8;a+=8191&(I>>>7|x<<9);var O=t[e+8]|t[e+9]<<8;h+=8191&(x>>>4|O<<12),c+=O>>>1&8191;var N=t[e+10]|t[e+11]<<8;f+=8191&(O>>>14|N<<2);var P=t[e+12]|t[e+13]<<8;u+=8191&(N>>>11|P<<5);var R=t[e+14]|t[e+15]<<8,T=0,C=T;C+=n*p,C+=s*(5*M),C+=o*(5*A),C+=a*(5*_),T=(C+=h*(5*w))>>>13,C&=8191,C+=c*(5*v),C+=f*(5*y),C+=u*(5*b),C+=(d+=8191&(P>>>8|R<<8))*(5*m);var k=T+=(C+=(l+=R>>>5|i)*(5*g))>>>13;k+=n*g,k+=s*p,k+=o*(5*M),k+=a*(5*A),T=(k+=h*(5*_))>>>13,k&=8191,k+=c*(5*w),k+=f*(5*v),k+=u*(5*y),k+=d*(5*b),T+=(k+=l*(5*m))>>>13,k&=8191;var L=T;L+=n*m,L+=s*g,L+=o*p,L+=a*(5*M),T=(L+=h*(5*A))>>>13,L&=8191,L+=c*(5*_),L+=f*(5*w),L+=u*(5*v),L+=d*(5*y);var q=T+=(L+=l*(5*b))>>>13;q+=n*b,q+=s*m,q+=o*g,q+=a*p,T=(q+=h*(5*M))>>>13,q&=8191,q+=c*(5*A),q+=f*(5*_),q+=u*(5*w),q+=d*(5*v);var U=T+=(q+=l*(5*y))>>>13;U+=n*y,U+=s*b,U+=o*m,U+=a*g,T=(U+=h*p)>>>13,U&=8191,U+=c*(5*M),U+=f*(5*A),U+=u*(5*_),U+=d*(5*w);var B=T+=(U+=l*(5*v))>>>13;B+=n*v,B+=s*y,B+=o*b,B+=a*m,T=(B+=h*g)>>>13,B&=8191,B+=c*p,B+=f*(5*M),B+=u*(5*A),B+=d*(5*_);var D=T+=(B+=l*(5*w))>>>13;D+=n*w,D+=s*v,D+=o*y,D+=a*b,T=(D+=h*m)>>>13,D&=8191,D+=c*g,D+=f*p,D+=u*(5*M),D+=d*(5*A);var z=T+=(D+=l*(5*_))>>>13;z+=n*_,z+=s*w,z+=o*v,z+=a*y,T=(z+=h*b)>>>13,z&=8191,z+=c*m,z+=f*g,z+=u*p,z+=d*(5*M);var j=T+=(z+=l*(5*A))>>>13;j+=n*A,j+=s*_,j+=o*w,j+=a*v,T=(j+=h*y)>>>13,j&=8191,j+=c*b,j+=f*m,j+=u*g,j+=d*p;var F=T+=(j+=l*(5*M))>>>13;F+=n*M,F+=s*A,F+=o*_,F+=a*w,T=(F+=h*v)>>>13,F&=8191,F+=c*y,F+=f*b,F+=u*m,F+=d*g,n=C=8191&(T=(T=((T+=(F+=l*p)>>>13)<<2)+T|0)+(C&=8191)|0),s=k+=T>>>=13,o=L&=8191,a=q&=8191,h=U&=8191,c=B&=8191,f=D&=8191,u=z&=8191,d=j&=8191,l=F&=8191,e+=16,r-=16}this._h[0]=n,this._h[1]=s,this._h[2]=o,this._h[3]=a,this._h[4]=h,this._h[5]=c,this._h[6]=f,this._h[7]=u,this._h[8]=d,this._h[9]=l},t.prototype.finish=function(t,e){void 0===e&&(e=0);var r,i,n,s,o=new Uint16Array(10);if(this._leftover){for(s=this._leftover,this._buffer[s++]=1;s<16;s++)this._buffer[s]=0;this._fin=1,this._blocks(this._buffer,0,16)}for(r=this._h[1]>>>13,this._h[1]&=8191,s=2;s<10;s++)this._h[s]+=r,r=this._h[s]>>>13,this._h[s]&=8191;for(this._h[0]+=5*r,r=this._h[0]>>>13,this._h[0]&=8191,this._h[1]+=r,r=this._h[1]>>>13,this._h[1]&=8191,this._h[2]+=r,o[0]=this._h[0]+5,r=o[0]>>>13,o[0]&=8191,s=1;s<10;s++)o[s]=this._h[s]+r,r=o[s]>>>13,o[s]&=8191;for(o[9]-=8192,i=(1^r)-1,s=0;s<10;s++)o[s]&=i;for(i=~i,s=0;s<10;s++)this._h[s]=this._h[s]&i|o[s];for(this._h[0]=65535&(this._h[0]|this._h[1]<<13),this._h[1]=65535&(this._h[1]>>>3|this._h[2]<<10),this._h[2]=65535&(this._h[2]>>>6|this._h[3]<<7),this._h[3]=65535&(this._h[3]>>>9|this._h[4]<<4),this._h[4]=65535&(this._h[4]>>>12|this._h[5]<<1|this._h[6]<<14),this._h[5]=65535&(this._h[6]>>>2|this._h[7]<<11),this._h[6]=65535&(this._h[7]>>>5|this._h[8]<<8),this._h[7]=65535&(this._h[8]>>>8|this._h[9]<<5),n=this._h[0]+this._pad[0],this._h[0]=65535&n,s=1;s<8;s++)n=(this._h[s]+this._pad[s]|0)+(n>>>16)|0,this._h[s]=65535&n;return t[e+0]=this._h[0]>>>0,t[e+1]=this._h[0]>>>8,t[e+2]=this._h[1]>>>0,t[e+3]=this._h[1]>>>8,t[e+4]=this._h[2]>>>0,t[e+5]=this._h[2]>>>8,t[e+6]=this._h[3]>>>0,t[e+7]=this._h[3]>>>8,t[e+8]=this._h[4]>>>0,t[e+9]=this._h[4]>>>8,t[e+10]=this._h[5]>>>0,t[e+11]=this._h[5]>>>8,t[e+12]=this._h[6]>>>0,t[e+13]=this._h[6]>>>8,t[e+14]=this._h[7]>>>0,t[e+15]=this._h[7]>>>8,this._finished=!0,this},t.prototype.update=function(t){var e,r=0,i=t.length;if(this._leftover){(e=16-this._leftover)>i&&(e=i);for(var n=0;n=16&&(e=i-i%16,this._blocks(t,r,e),r+=e,i-=e),i){for(n=0;n{Object.defineProperty(e,"__esModule",{value:!0}),e.randomStringForEntropy=e.randomString=e.randomUint32=e.randomBytes=e.defaultRandomSource=void 0;const i=r(5492),n=r(972),s=r(6228);function o(t,r=e.defaultRandomSource){return r.randomBytes(t)}e.defaultRandomSource=new i.SystemRandomSource,e.randomBytes=o,e.randomUint32=function(t=e.defaultRandomSource){const r=o(4,t),i=(0,n.readUint32LE)(r);return(0,s.wipe)(r),i};const a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function h(t,r=a,i=e.defaultRandomSource){if(r.length<2)throw new Error("randomString charset is too short");if(r.length>256)throw new Error("randomString charset is too long");let n="";const h=r.length,c=256-256%h;for(;t>0;){const e=o(Math.ceil(256*t/c),i);for(let i=0;i0;i++){const s=e[i];s{Object.defineProperty(e,"__esModule",{value:!0}),e.BrowserRandomSource=void 0,e.BrowserRandomSource=class{constructor(){this.isAvailable=!1,this.isInstantiated=!1;const t="undefined"!=typeof self?self.crypto||self.msCrypto:null;t&&void 0!==t.getRandomValues&&(this._crypto=t,this.isAvailable=!0,this.isInstantiated=!0)}randomBytes(t){if(!this.isAvailable||!this._crypto)throw new Error("Browser random byte generator is not available.");const e=new Uint8Array(t);for(let t=0;t{Object.defineProperty(e,"__esModule",{value:!0}),e.NodeRandomSource=void 0;const i=r(6228);e.NodeRandomSource=class{constructor(){this.isAvailable=!1,this.isInstantiated=!1;{const t=r(9432);t&&t.randomBytes&&(this._crypto=t,this.isAvailable=!0,this.isInstantiated=!0)}}randomBytes(t){if(!this.isAvailable||!this._crypto)throw new Error("Node.js random byte generator is not available.");let e=this._crypto.randomBytes(t);if(e.length!==t)throw new Error("NodeRandomSource: got fewer bytes than requested");const r=new Uint8Array(t);for(let t=0;t{Object.defineProperty(e,"__esModule",{value:!0}),e.SystemRandomSource=void 0;const i=r(7029),n=r(5821);e.SystemRandomSource=class{constructor(){return this.isAvailable=!1,this.name="",this._source=new i.BrowserRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Browser")):(this._source=new n.NodeRandomSource,this._source.isAvailable?(this.isAvailable=!0,void(this.name="Node")):void 0)}randomBytes(t){if(!this.isAvailable)throw new Error("System random byte generator is not available.");return this._source.randomBytes(t)}}},204:(t,e,r)=>{var i=r(972),n=r(6228);e.On=32,e.cS=64;var s=function(){function t(){this.digestLength=e.On,this.blockSize=e.cS,this._state=new Int32Array(8),this._temp=new Int32Array(64),this._buffer=new Uint8Array(128),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this.reset()}return t.prototype._initState=function(){this._state[0]=1779033703,this._state[1]=3144134277,this._state[2]=1013904242,this._state[3]=2773480762,this._state[4]=1359893119,this._state[5]=2600822924,this._state[6]=528734635,this._state[7]=1541459225},t.prototype.reset=function(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this},t.prototype.clean=function(){n.wipe(this._buffer),n.wipe(this._temp),this.reset()},t.prototype.update=function(t,e){if(void 0===e&&(e=t.length),this._finished)throw new Error("SHA256: can't update because hash was finished.");var r=0;if(this._bytesHashed+=e,this._bufferLength>0){for(;this._bufferLength0;)this._buffer[this._bufferLength++]=t[r++],e--;this._bufferLength===this.blockSize&&(a(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(e>=this.blockSize&&(r=a(this._temp,this._state,t,r,e),e%=this.blockSize);e>0;)this._buffer[this._bufferLength++]=t[r++],e--;return this},t.prototype.finish=function(t){if(!this._finished){var e=this._bytesHashed,r=this._bufferLength,n=e/536870912|0,s=e<<3,o=e%64<56?64:128;this._buffer[r]=128;for(var h=r+1;h0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}},t.prototype.restoreState=function(t){return this._state.set(t.state),this._bufferLength=t.bufferLength,t.buffer&&this._buffer.set(t.buffer),this._bytesHashed=t.bytesHashed,this._finished=!1,this},t.prototype.cleanSavedState=function(t){n.wipe(t.state),t.buffer&&n.wipe(t.buffer),t.bufferLength=0,t.bytesHashed=0},t}();e.aD=s;var o=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function a(t,e,r,n,s){for(;s>=64;){for(var a=e[0],h=e[1],c=e[2],f=e[3],u=e[4],d=e[5],l=e[6],p=e[7],g=0;g<16;g++){var m=n+4*g;t[g]=i.readUint32BE(r,m)}for(g=16;g<64;g++){var b=t[g-2],y=(b>>>17|b<<15)^(b>>>19|b<<13)^b>>>10,v=((b=t[g-15])>>>7|b<<25)^(b>>>18|b<<14)^b>>>3;t[g]=(y+t[g-7]|0)+(v+t[g-16]|0)}for(g=0;g<64;g++)y=(((u>>>6|u<<26)^(u>>>11|u<<21)^(u>>>25|u<<7))+(u&d^~u&l)|0)+(p+(o[g]+t[g]|0)|0)|0,v=((a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10))+(a&h^a&c^h&c)|0,p=l,l=d,d=u,u=f+y|0,f=c,c=h,h=a,a=y+v|0;e[0]+=a,e[1]+=h,e[2]+=c,e[3]+=f,e[4]+=u,e[5]+=d,e[6]+=l,e[7]+=p,n+=64,s-=64}return n}e.tW=function(t){var e=new s;e.update(t);var r=e.digest();return e.clean(),r}},4974:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(972),n=r(6228);e.DIGEST_LENGTH=64,e.BLOCK_SIZE=128;var s=function(){function t(){this.digestLength=e.DIGEST_LENGTH,this.blockSize=e.BLOCK_SIZE,this._stateHi=new Int32Array(8),this._stateLo=new Int32Array(8),this._tempHi=new Int32Array(16),this._tempLo=new Int32Array(16),this._buffer=new Uint8Array(256),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this.reset()}return t.prototype._initState=function(){this._stateHi[0]=1779033703,this._stateHi[1]=3144134277,this._stateHi[2]=1013904242,this._stateHi[3]=2773480762,this._stateHi[4]=1359893119,this._stateHi[5]=2600822924,this._stateHi[6]=528734635,this._stateHi[7]=1541459225,this._stateLo[0]=4089235720,this._stateLo[1]=2227873595,this._stateLo[2]=4271175723,this._stateLo[3]=1595750129,this._stateLo[4]=2917565137,this._stateLo[5]=725511199,this._stateLo[6]=4215389547,this._stateLo[7]=327033209},t.prototype.reset=function(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this},t.prototype.clean=function(){n.wipe(this._buffer),n.wipe(this._tempHi),n.wipe(this._tempLo),this.reset()},t.prototype.update=function(t,r){if(void 0===r&&(r=t.length),this._finished)throw new Error("SHA512: can't update because hash was finished.");var i=0;if(this._bytesHashed+=r,this._bufferLength>0){for(;this._bufferLength0;)this._buffer[this._bufferLength++]=t[i++],r--;this._bufferLength===this.blockSize&&(a(this._tempHi,this._tempLo,this._stateHi,this._stateLo,this._buffer,0,this.blockSize),this._bufferLength=0)}for(r>=this.blockSize&&(i=a(this._tempHi,this._tempLo,this._stateHi,this._stateLo,t,i,r),r%=this.blockSize);r>0;)this._buffer[this._bufferLength++]=t[i++],r--;return this},t.prototype.finish=function(t){if(!this._finished){var e=this._bytesHashed,r=this._bufferLength,n=e/536870912|0,s=e<<3,o=e%128<112?128:256;this._buffer[r]=128;for(var h=r+1;h0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}},t.prototype.restoreState=function(t){return this._stateHi.set(t.stateHi),this._stateLo.set(t.stateLo),this._bufferLength=t.bufferLength,t.buffer&&this._buffer.set(t.buffer),this._bytesHashed=t.bytesHashed,this._finished=!1,this},t.prototype.cleanSavedState=function(t){n.wipe(t.stateHi),n.wipe(t.stateLo),t.buffer&&n.wipe(t.buffer),t.bufferLength=0,t.bytesHashed=0},t}();e.SHA512=s;var o=new Int32Array([1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591]);function a(t,e,r,n,s,a,h){for(var c,f,u,d,l,p,g,m,b=r[0],y=r[1],v=r[2],w=r[3],_=r[4],A=r[5],M=r[6],S=r[7],E=n[0],I=n[1],x=n[2],O=n[3],N=n[4],P=n[5],R=n[6],T=n[7];h>=128;){for(var C=0;C<16;C++){var k=8*C+a;t[C]=i.readUint32BE(s,k),e[C]=i.readUint32BE(s,k+4)}for(C=0;C<80;C++){var L,q,U=b,B=y,D=v,z=w,j=_,F=A,K=M,V=E,H=I,W=x,J=O,G=N,$=P,Y=R;if(l=65535&(f=T),p=f>>>16,g=65535&(c=S),m=c>>>16,l+=65535&(f=(N>>>14|_<<18)^(N>>>18|_<<14)^(_>>>9|N<<23)),p+=f>>>16,g+=65535&(c=(_>>>14|N<<18)^(_>>>18|N<<14)^(N>>>9|_<<23)),m+=c>>>16,l+=65535&(f=N&P^~N&R),p+=f>>>16,g+=65535&(c=_&A^~_&M),m+=c>>>16,c=o[2*C],l+=65535&(f=o[2*C+1]),p+=f>>>16,g+=65535&c,m+=c>>>16,c=t[C%16],p+=(f=e[C%16])>>>16,g+=65535&c,m+=c>>>16,g+=(p+=(l+=65535&f)>>>16)>>>16,l=65535&(f=d=65535&l|p<<16),p=f>>>16,g=65535&(c=u=65535&g|(m+=g>>>16)<<16),m=c>>>16,l+=65535&(f=(E>>>28|b<<4)^(b>>>2|E<<30)^(b>>>7|E<<25)),p+=f>>>16,g+=65535&(c=(b>>>28|E<<4)^(E>>>2|b<<30)^(E>>>7|b<<25)),m+=c>>>16,p+=(f=E&I^E&x^I&x)>>>16,g+=65535&(c=b&y^b&v^y&v),m+=c>>>16,L=65535&(g+=(p+=(l+=65535&f)>>>16)>>>16)|(m+=g>>>16)<<16,q=65535&l|p<<16,l=65535&(f=J),p=f>>>16,g=65535&(c=z),m=c>>>16,p+=(f=d)>>>16,g+=65535&(c=u),m+=c>>>16,y=U,v=B,w=D,_=z=65535&(g+=(p+=(l+=65535&f)>>>16)>>>16)|(m+=g>>>16)<<16,A=j,M=F,S=K,b=L,I=V,x=H,O=W,N=J=65535&l|p<<16,P=G,R=$,T=Y,E=q,C%16==15)for(k=0;k<16;k++)c=t[k],l=65535&(f=e[k]),p=f>>>16,g=65535&c,m=c>>>16,c=t[(k+9)%16],l+=65535&(f=e[(k+9)%16]),p+=f>>>16,g+=65535&c,m+=c>>>16,u=t[(k+1)%16],l+=65535&(f=((d=e[(k+1)%16])>>>1|u<<31)^(d>>>8|u<<24)^(d>>>7|u<<25)),p+=f>>>16,g+=65535&(c=(u>>>1|d<<31)^(u>>>8|d<<24)^u>>>7),m+=c>>>16,u=t[(k+14)%16],p+=(f=((d=e[(k+14)%16])>>>19|u<<13)^(u>>>29|d<<3)^(d>>>6|u<<26))>>>16,g+=65535&(c=(u>>>19|d<<13)^(d>>>29|u<<3)^u>>>6),m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,t[k]=65535&g|m<<16,e[k]=65535&l|p<<16}l=65535&(f=E),p=f>>>16,g=65535&(c=b),m=c>>>16,c=r[0],p+=(f=n[0])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[0]=b=65535&g|m<<16,n[0]=E=65535&l|p<<16,l=65535&(f=I),p=f>>>16,g=65535&(c=y),m=c>>>16,c=r[1],p+=(f=n[1])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[1]=y=65535&g|m<<16,n[1]=I=65535&l|p<<16,l=65535&(f=x),p=f>>>16,g=65535&(c=v),m=c>>>16,c=r[2],p+=(f=n[2])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[2]=v=65535&g|m<<16,n[2]=x=65535&l|p<<16,l=65535&(f=O),p=f>>>16,g=65535&(c=w),m=c>>>16,c=r[3],p+=(f=n[3])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[3]=w=65535&g|m<<16,n[3]=O=65535&l|p<<16,l=65535&(f=N),p=f>>>16,g=65535&(c=_),m=c>>>16,c=r[4],p+=(f=n[4])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[4]=_=65535&g|m<<16,n[4]=N=65535&l|p<<16,l=65535&(f=P),p=f>>>16,g=65535&(c=A),m=c>>>16,c=r[5],p+=(f=n[5])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[5]=A=65535&g|m<<16,n[5]=P=65535&l|p<<16,l=65535&(f=R),p=f>>>16,g=65535&(c=M),m=c>>>16,c=r[6],p+=(f=n[6])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[6]=M=65535&g|m<<16,n[6]=R=65535&l|p<<16,l=65535&(f=T),p=f>>>16,g=65535&(c=S),m=c>>>16,c=r[7],p+=(f=n[7])>>>16,g+=65535&c,m+=c>>>16,m+=(g+=(p+=(l+=65535&f)>>>16)>>>16)>>>16,r[7]=S=65535&g|m<<16,n[7]=T=65535&l|p<<16,a+=128,h-=128}return a}e.hash=function(t){var e=new s;e.update(t);var r=e.digest();return e.clean(),r}},6228:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.wipe=function(t){for(var e=0;e{e.Tc=e.TZ=e.wE=e.Xx=void 0;const i=r(7052),n=r(6228);function s(t){const e=new Float64Array(16);if(t)for(let r=0;r=0;--t){const e=r[t>>>3]>>>(7&t)&1;c(n,o,e),c(p,g,e),f(m,n,p),u(n,n,p),f(p,o,g),u(o,o,g),l(g,m),l(b,n),d(n,p,n),d(p,o,m),f(m,n,p),u(n,n,p),l(o,n),u(p,g,b),d(n,p,a),f(n,n,g),d(p,p,n),d(n,g,b),d(g,o,i),l(o,m),c(n,o,e),c(p,g,e)}for(let t=0;t<16;t++)i[t+16]=n[t],i[t+32]=p[t],i[t+48]=o[t],i[t+64]=g[t];const y=i.subarray(32),v=i.subarray(16);!function(t,e){const r=s();for(let t=0;t<16;t++)r[t]=e[t];for(let t=253;t>=0;t--)l(r,r),2!==t&&4!==t&&d(r,r,e);for(let e=0;e<16;e++)t[e]=r[e]}(y,y),d(v,v,y);const w=new Uint8Array(32);return function(t,e){const r=s(),i=s();for(let t=0;t<16;t++)i[t]=e[t];h(i),h(i),h(i);for(let t=0;t<2;t++){r[0]=i[0]-65517;for(let t=1;t<15;t++)r[t]=i[t]-65535-(r[t-1]>>16&1),r[t-1]&=65535;r[15]=i[15]-32767-(r[14]>>16&1);const t=r[15]>>16&1;r[14]&=65535,c(i,r,1-t)}for(let e=0;e<16;e++)t[2*e]=255&i[e],t[2*e+1]=i[e]>>8}(w,v),w}function g(t){return p(t,o)}e.TZ=function(t){const r=(0,i.randomBytes)(32,t),s=function(t){if(t.length!==e.wE)throw new Error(`x25519: seed must be ${e.wE} bytes`);const r=new Uint8Array(t);return{publicKey:g(r),secretKey:r}}(r);return(0,n.wipe)(r),s},e.Tc=function(t,r,i=!1){if(t.length!==e.Xx)throw new Error("X25519: incorrect secret key length");if(r.length!==e.Xx)throw new Error("X25519: incorrect public key length");const n=p(t,r);if(i){let t=0;for(let e=0;e{function i(){return(null===r.g||void 0===r.g?void 0:r.g.crypto)||(null===r.g||void 0===r.g?void 0:r.g.msCrypto)||{}}function n(){const t=i();return t.subtle||t.webkitSubtle}Object.defineProperty(e,"__esModule",{value:!0}),e.isBrowserCryptoAvailable=e.getSubtleCrypto=e.getBrowerCrypto=void 0,e.getBrowerCrypto=i,e.getSubtleCrypto=n,e.isBrowserCryptoAvailable=function(){return!!i()&&!!n()}},1089:(t,e)=>{function r(){return"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product}function i(){return"undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.versions.node}Object.defineProperty(e,"__esModule",{value:!0}),e.isBrowser=e.isNode=e.isReactNative=void 0,e.isReactNative=r,e.isNode=i,e.isBrowser=function(){return!r()&&!i()}},5682:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(7173),e),i.__exportStar(r(1089),e)},5665:()=>{},9026:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(9244),e),i.__exportStar(r(1861),e)},9244:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ONE_THOUSAND=e.ONE_HUNDRED=void 0,e.ONE_HUNDRED=100,e.ONE_THOUSAND=1e3},1861:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ONE_YEAR=e.FOUR_WEEKS=e.THREE_WEEKS=e.TWO_WEEKS=e.ONE_WEEK=e.THIRTY_DAYS=e.SEVEN_DAYS=e.FIVE_DAYS=e.THREE_DAYS=e.ONE_DAY=e.TWENTY_FOUR_HOURS=e.TWELVE_HOURS=e.SIX_HOURS=e.THREE_HOURS=e.ONE_HOUR=e.SIXTY_MINUTES=e.THIRTY_MINUTES=e.TEN_MINUTES=e.FIVE_MINUTES=e.ONE_MINUTE=e.SIXTY_SECONDS=e.THIRTY_SECONDS=e.TEN_SECONDS=e.FIVE_SECONDS=e.ONE_SECOND=void 0,e.ONE_SECOND=1,e.FIVE_SECONDS=5,e.TEN_SECONDS=10,e.THIRTY_SECONDS=30,e.SIXTY_SECONDS=60,e.ONE_MINUTE=e.SIXTY_SECONDS,e.FIVE_MINUTES=5*e.ONE_MINUTE,e.TEN_MINUTES=10*e.ONE_MINUTE,e.THIRTY_MINUTES=30*e.ONE_MINUTE,e.SIXTY_MINUTES=60*e.ONE_MINUTE,e.ONE_HOUR=e.SIXTY_MINUTES,e.THREE_HOURS=3*e.ONE_HOUR,e.SIX_HOURS=6*e.ONE_HOUR,e.TWELVE_HOURS=12*e.ONE_HOUR,e.TWENTY_FOUR_HOURS=24*e.ONE_HOUR,e.ONE_DAY=e.TWENTY_FOUR_HOURS,e.THREE_DAYS=3*e.ONE_DAY,e.FIVE_DAYS=5*e.ONE_DAY,e.SEVEN_DAYS=7*e.ONE_DAY,e.THIRTY_DAYS=30*e.ONE_DAY,e.ONE_WEEK=e.SEVEN_DAYS,e.TWO_WEEKS=2*e.ONE_WEEK,e.THREE_WEEKS=3*e.ONE_WEEK,e.FOUR_WEEKS=4*e.ONE_WEEK,e.ONE_YEAR=365*e.ONE_DAY},8900:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(9606),e),i.__exportStar(r(9883),e),i.__exportStar(r(2010),e),i.__exportStar(r(9026),e)},2010:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),r(5215).__exportStar(r(3093),e)},3093:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.IWatch=void 0,e.IWatch=class{}},221:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.fromMiliseconds=e.toMiliseconds=void 0;const i=r(9026);e.toMiliseconds=function(t){return t*i.ONE_THOUSAND},e.fromMiliseconds=function(t){return Math.floor(t/i.ONE_THOUSAND)}},2985:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.delay=void 0,e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e(!0)}),t)}))}},9606:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=r(5215);i.__exportStar(r(2985),e),i.__exportStar(r(221),e)},9883:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Watch=void 0;class r{constructor(){this.timestamps=new Map}start(t){if(this.timestamps.has(t))throw new Error(`Watch already started for label: ${t}`);this.timestamps.set(t,{started:Date.now()})}stop(t){const e=this.get(t);if(void 0!==e.elapsed)throw new Error(`Watch already stopped for label: ${t}`);const r=Date.now()-e.started;this.timestamps.set(t,{started:e.started,elapsed:r})}get(t){const e=this.timestamps.get(t);if(void 0===e)throw new Error(`No timestamp found for label: ${t}`);return e}elapsed(t){const e=this.get(t);return e.elapsed||Date.now()-e.started}}e.Watch=r,e.default=r},6455:function(t,e,r){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function s(t,e,r){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof t?t.exports=s:e.BN=s,s.BN=s,s.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r(9895).Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:r-48&15}function h(t,e,r){var i=a(t,r);return r-1>=e&&(i|=a(t,r-1)<<4),i}function c(t,e,r,i){for(var n=0,s=Math.min(t.length,r),o=e;o=49?a-49+10:a>=17?a-17+10:a}return n}s.isBN=function(t){return t instanceof s||null!==t&&"object"==typeof t&&t.constructor.wordSize===s.wordSize&&Array.isArray(t.words)},s.max=function(t,e){return t.cmp(e)>0?t:e},s.min=function(t,e){return t.cmp(e)<0?t:e},s.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},s.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i=e;i-=2)n=h(t,e,i)<=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;else for(i=(t.length-e)%2==0?e+1:e;i=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;this.strip()},s.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,h=0,f=r;f1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?""};var f=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],u=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],d=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function l(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,h=o/67108864|0;r.words[0]=a;for(var c=1;c>>26,u=67108863&h,d=Math.min(c,e.length-1),l=Math.max(0,c-t.length+1);l<=d;l++){var p=c-l|0;f+=(o=(n=0|t.words[p])*(s=0|e.words[l])+u)/67108864|0,u=67108863&o}r.words[c]=0|u,h=0|f}return 0!==h?r.words[c]=0|h:r.length--,r.strip()}s.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o>>24-n&16777215)||o!==this.length-1?f[6-h.length]+h+r:h+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=u[t],l=d[t];r="";var p=this.clone();for(p.negative=0;!p.isZero();){var g=p.modn(l).toString(t);r=(p=p.idivn(l)).isZero()?g+r:f[c-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(t,e){return i(void 0!==o),this.toArrayLike(o,t,e)},s.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},s.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,c=new t(s),f=this.clone();if(h){for(a=0;!f.isZero();a++)o=f.andln(255),f.iushrn(8),c[a]=o;for(;a=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},s.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},s.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;rt.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;it.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},s.prototype.notn=function(t){return this.clone().inotn(t)},s.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s>>26;for(;0!==n&&s>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;st.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o>26,this.words[o]=67108863&e;for(;0!==s&&o>26,this.words[o]=67108863&e;if(0===s&&o>>13,l=0|o[1],p=8191&l,g=l>>>13,m=0|o[2],b=8191&m,y=m>>>13,v=0|o[3],w=8191&v,_=v>>>13,A=0|o[4],M=8191&A,S=A>>>13,E=0|o[5],I=8191&E,x=E>>>13,O=0|o[6],N=8191&O,P=O>>>13,R=0|o[7],T=8191&R,C=R>>>13,k=0|o[8],L=8191&k,q=k>>>13,U=0|o[9],B=8191&U,D=U>>>13,z=0|a[0],j=8191&z,F=z>>>13,K=0|a[1],V=8191&K,H=K>>>13,W=0|a[2],J=8191&W,G=W>>>13,$=0|a[3],Y=8191&$,Q=$>>>13,X=0|a[4],Z=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ct=at>>>13,ft=0|a[8],ut=8191&ft,dt=ft>>>13,lt=0|a[9],pt=8191<,gt=lt>>>13;r.negative=t.negative^e.negative,r.length=19;var mt=(c+(i=Math.imul(u,j))|0)+((8191&(n=(n=Math.imul(u,F))+Math.imul(d,j)|0))<<13)|0;c=((s=Math.imul(d,F))+(n>>>13)|0)+(mt>>>26)|0,mt&=67108863,i=Math.imul(p,j),n=(n=Math.imul(p,F))+Math.imul(g,j)|0,s=Math.imul(g,F);var bt=(c+(i=i+Math.imul(u,V)|0)|0)+((8191&(n=(n=n+Math.imul(u,H)|0)+Math.imul(d,V)|0))<<13)|0;c=((s=s+Math.imul(d,H)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(b,j),n=(n=Math.imul(b,F))+Math.imul(y,j)|0,s=Math.imul(y,F),i=i+Math.imul(p,V)|0,n=(n=n+Math.imul(p,H)|0)+Math.imul(g,V)|0,s=s+Math.imul(g,H)|0;var yt=(c+(i=i+Math.imul(u,J)|0)|0)+((8191&(n=(n=n+Math.imul(u,G)|0)+Math.imul(d,J)|0))<<13)|0;c=((s=s+Math.imul(d,G)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(w,j),n=(n=Math.imul(w,F))+Math.imul(_,j)|0,s=Math.imul(_,F),i=i+Math.imul(b,V)|0,n=(n=n+Math.imul(b,H)|0)+Math.imul(y,V)|0,s=s+Math.imul(y,H)|0,i=i+Math.imul(p,J)|0,n=(n=n+Math.imul(p,G)|0)+Math.imul(g,J)|0,s=s+Math.imul(g,G)|0;var vt=(c+(i=i+Math.imul(u,Y)|0)|0)+((8191&(n=(n=n+Math.imul(u,Q)|0)+Math.imul(d,Y)|0))<<13)|0;c=((s=s+Math.imul(d,Q)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(M,j),n=(n=Math.imul(M,F))+Math.imul(S,j)|0,s=Math.imul(S,F),i=i+Math.imul(w,V)|0,n=(n=n+Math.imul(w,H)|0)+Math.imul(_,V)|0,s=s+Math.imul(_,H)|0,i=i+Math.imul(b,J)|0,n=(n=n+Math.imul(b,G)|0)+Math.imul(y,J)|0,s=s+Math.imul(y,G)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,Q)|0;var wt=(c+(i=i+Math.imul(u,Z)|0)|0)+((8191&(n=(n=n+Math.imul(u,tt)|0)+Math.imul(d,Z)|0))<<13)|0;c=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(I,j),n=(n=Math.imul(I,F))+Math.imul(x,j)|0,s=Math.imul(x,F),i=i+Math.imul(M,V)|0,n=(n=n+Math.imul(M,H)|0)+Math.imul(S,V)|0,s=s+Math.imul(S,H)|0,i=i+Math.imul(w,J)|0,n=(n=n+Math.imul(w,G)|0)+Math.imul(_,J)|0,s=s+Math.imul(_,G)|0,i=i+Math.imul(b,Y)|0,n=(n=n+Math.imul(b,Q)|0)+Math.imul(y,Y)|0,s=s+Math.imul(y,Q)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,tt)|0;var _t=(c+(i=i+Math.imul(u,rt)|0)|0)+((8191&(n=(n=n+Math.imul(u,it)|0)+Math.imul(d,rt)|0))<<13)|0;c=((s=s+Math.imul(d,it)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(N,j),n=(n=Math.imul(N,F))+Math.imul(P,j)|0,s=Math.imul(P,F),i=i+Math.imul(I,V)|0,n=(n=n+Math.imul(I,H)|0)+Math.imul(x,V)|0,s=s+Math.imul(x,H)|0,i=i+Math.imul(M,J)|0,n=(n=n+Math.imul(M,G)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,G)|0,i=i+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,Q)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,Q)|0,i=i+Math.imul(b,Z)|0,n=(n=n+Math.imul(b,tt)|0)+Math.imul(y,Z)|0,s=s+Math.imul(y,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(g,rt)|0,s=s+Math.imul(g,it)|0;var At=(c+(i=i+Math.imul(u,st)|0)|0)+((8191&(n=(n=n+Math.imul(u,ot)|0)+Math.imul(d,st)|0))<<13)|0;c=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(T,j),n=(n=Math.imul(T,F))+Math.imul(C,j)|0,s=Math.imul(C,F),i=i+Math.imul(N,V)|0,n=(n=n+Math.imul(N,H)|0)+Math.imul(P,V)|0,s=s+Math.imul(P,H)|0,i=i+Math.imul(I,J)|0,n=(n=n+Math.imul(I,G)|0)+Math.imul(x,J)|0,s=s+Math.imul(x,G)|0,i=i+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,Q)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,Q)|0,i=i+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,tt)|0,i=i+Math.imul(b,rt)|0,n=(n=n+Math.imul(b,it)|0)+Math.imul(y,rt)|0,s=s+Math.imul(y,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var Mt=(c+(i=i+Math.imul(u,ht)|0)|0)+((8191&(n=(n=n+Math.imul(u,ct)|0)+Math.imul(d,ht)|0))<<13)|0;c=((s=s+Math.imul(d,ct)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(L,j),n=(n=Math.imul(L,F))+Math.imul(q,j)|0,s=Math.imul(q,F),i=i+Math.imul(T,V)|0,n=(n=n+Math.imul(T,H)|0)+Math.imul(C,V)|0,s=s+Math.imul(C,H)|0,i=i+Math.imul(N,J)|0,n=(n=n+Math.imul(N,G)|0)+Math.imul(P,J)|0,s=s+Math.imul(P,G)|0,i=i+Math.imul(I,Y)|0,n=(n=n+Math.imul(I,Q)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,Q)|0,i=i+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(S,Z)|0,s=s+Math.imul(S,tt)|0,i=i+Math.imul(w,rt)|0,n=(n=n+Math.imul(w,it)|0)+Math.imul(_,rt)|0,s=s+Math.imul(_,it)|0,i=i+Math.imul(b,st)|0,n=(n=n+Math.imul(b,ot)|0)+Math.imul(y,st)|0,s=s+Math.imul(y,ot)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ct)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ct)|0;var St=(c+(i=i+Math.imul(u,ut)|0)|0)+((8191&(n=(n=n+Math.imul(u,dt)|0)+Math.imul(d,ut)|0))<<13)|0;c=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(B,j),n=(n=Math.imul(B,F))+Math.imul(D,j)|0,s=Math.imul(D,F),i=i+Math.imul(L,V)|0,n=(n=n+Math.imul(L,H)|0)+Math.imul(q,V)|0,s=s+Math.imul(q,H)|0,i=i+Math.imul(T,J)|0,n=(n=n+Math.imul(T,G)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,G)|0,i=i+Math.imul(N,Y)|0,n=(n=n+Math.imul(N,Q)|0)+Math.imul(P,Y)|0,s=s+Math.imul(P,Q)|0,i=i+Math.imul(I,Z)|0,n=(n=n+Math.imul(I,tt)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,tt)|0,i=i+Math.imul(M,rt)|0,n=(n=n+Math.imul(M,it)|0)+Math.imul(S,rt)|0,s=s+Math.imul(S,it)|0,i=i+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,i=i+Math.imul(b,ht)|0,n=(n=n+Math.imul(b,ct)|0)+Math.imul(y,ht)|0,s=s+Math.imul(y,ct)|0,i=i+Math.imul(p,ut)|0,n=(n=n+Math.imul(p,dt)|0)+Math.imul(g,ut)|0,s=s+Math.imul(g,dt)|0;var Et=(c+(i=i+Math.imul(u,pt)|0)|0)+((8191&(n=(n=n+Math.imul(u,gt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(B,V),n=(n=Math.imul(B,H))+Math.imul(D,V)|0,s=Math.imul(D,H),i=i+Math.imul(L,J)|0,n=(n=n+Math.imul(L,G)|0)+Math.imul(q,J)|0,s=s+Math.imul(q,G)|0,i=i+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,Q)|0)+Math.imul(C,Y)|0,s=s+Math.imul(C,Q)|0,i=i+Math.imul(N,Z)|0,n=(n=n+Math.imul(N,tt)|0)+Math.imul(P,Z)|0,s=s+Math.imul(P,tt)|0,i=i+Math.imul(I,rt)|0,n=(n=n+Math.imul(I,it)|0)+Math.imul(x,rt)|0,s=s+Math.imul(x,it)|0,i=i+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(S,st)|0,s=s+Math.imul(S,ot)|0,i=i+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ct)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ct)|0,i=i+Math.imul(b,ut)|0,n=(n=n+Math.imul(b,dt)|0)+Math.imul(y,ut)|0,s=s+Math.imul(y,dt)|0;var It=(c+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;c=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(B,J),n=(n=Math.imul(B,G))+Math.imul(D,J)|0,s=Math.imul(D,G),i=i+Math.imul(L,Y)|0,n=(n=n+Math.imul(L,Q)|0)+Math.imul(q,Y)|0,s=s+Math.imul(q,Q)|0,i=i+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(C,Z)|0,s=s+Math.imul(C,tt)|0,i=i+Math.imul(N,rt)|0,n=(n=n+Math.imul(N,it)|0)+Math.imul(P,rt)|0,s=s+Math.imul(P,it)|0,i=i+Math.imul(I,st)|0,n=(n=n+Math.imul(I,ot)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,ot)|0,i=i+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ct)|0)+Math.imul(S,ht)|0,s=s+Math.imul(S,ct)|0,i=i+Math.imul(w,ut)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(_,ut)|0,s=s+Math.imul(_,dt)|0;var xt=(c+(i=i+Math.imul(b,pt)|0)|0)+((8191&(n=(n=n+Math.imul(b,gt)|0)+Math.imul(y,pt)|0))<<13)|0;c=((s=s+Math.imul(y,gt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(B,Y),n=(n=Math.imul(B,Q))+Math.imul(D,Y)|0,s=Math.imul(D,Q),i=i+Math.imul(L,Z)|0,n=(n=n+Math.imul(L,tt)|0)+Math.imul(q,Z)|0,s=s+Math.imul(q,tt)|0,i=i+Math.imul(T,rt)|0,n=(n=n+Math.imul(T,it)|0)+Math.imul(C,rt)|0,s=s+Math.imul(C,it)|0,i=i+Math.imul(N,st)|0,n=(n=n+Math.imul(N,ot)|0)+Math.imul(P,st)|0,s=s+Math.imul(P,ot)|0,i=i+Math.imul(I,ht)|0,n=(n=n+Math.imul(I,ct)|0)+Math.imul(x,ht)|0,s=s+Math.imul(x,ct)|0,i=i+Math.imul(M,ut)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(S,ut)|0,s=s+Math.imul(S,dt)|0;var Ot=(c+(i=i+Math.imul(w,pt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(_,pt)|0))<<13)|0;c=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,i=Math.imul(B,Z),n=(n=Math.imul(B,tt))+Math.imul(D,Z)|0,s=Math.imul(D,tt),i=i+Math.imul(L,rt)|0,n=(n=n+Math.imul(L,it)|0)+Math.imul(q,rt)|0,s=s+Math.imul(q,it)|0,i=i+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(C,st)|0,s=s+Math.imul(C,ot)|0,i=i+Math.imul(N,ht)|0,n=(n=n+Math.imul(N,ct)|0)+Math.imul(P,ht)|0,s=s+Math.imul(P,ct)|0,i=i+Math.imul(I,ut)|0,n=(n=n+Math.imul(I,dt)|0)+Math.imul(x,ut)|0,s=s+Math.imul(x,dt)|0;var Nt=(c+(i=i+Math.imul(M,pt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(S,pt)|0))<<13)|0;c=((s=s+Math.imul(S,gt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,i=Math.imul(B,rt),n=(n=Math.imul(B,it))+Math.imul(D,rt)|0,s=Math.imul(D,it),i=i+Math.imul(L,st)|0,n=(n=n+Math.imul(L,ot)|0)+Math.imul(q,st)|0,s=s+Math.imul(q,ot)|0,i=i+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ct)|0)+Math.imul(C,ht)|0,s=s+Math.imul(C,ct)|0,i=i+Math.imul(N,ut)|0,n=(n=n+Math.imul(N,dt)|0)+Math.imul(P,ut)|0,s=s+Math.imul(P,dt)|0;var Pt=(c+(i=i+Math.imul(I,pt)|0)|0)+((8191&(n=(n=n+Math.imul(I,gt)|0)+Math.imul(x,pt)|0))<<13)|0;c=((s=s+Math.imul(x,gt)|0)+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(B,st),n=(n=Math.imul(B,ot))+Math.imul(D,st)|0,s=Math.imul(D,ot),i=i+Math.imul(L,ht)|0,n=(n=n+Math.imul(L,ct)|0)+Math.imul(q,ht)|0,s=s+Math.imul(q,ct)|0,i=i+Math.imul(T,ut)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(C,ut)|0,s=s+Math.imul(C,dt)|0;var Rt=(c+(i=i+Math.imul(N,pt)|0)|0)+((8191&(n=(n=n+Math.imul(N,gt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((s=s+Math.imul(P,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(B,ht),n=(n=Math.imul(B,ct))+Math.imul(D,ht)|0,s=Math.imul(D,ct),i=i+Math.imul(L,ut)|0,n=(n=n+Math.imul(L,dt)|0)+Math.imul(q,ut)|0,s=s+Math.imul(q,dt)|0;var Tt=(c+(i=i+Math.imul(T,pt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(C,pt)|0))<<13)|0;c=((s=s+Math.imul(C,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,i=Math.imul(B,ut),n=(n=Math.imul(B,dt))+Math.imul(D,ut)|0,s=Math.imul(D,dt);var Ct=(c+(i=i+Math.imul(L,pt)|0)|0)+((8191&(n=(n=n+Math.imul(L,gt)|0)+Math.imul(q,pt)|0))<<13)|0;c=((s=s+Math.imul(q,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863;var kt=(c+(i=Math.imul(B,pt))|0)+((8191&(n=(n=Math.imul(B,gt))+Math.imul(D,pt)|0))<<13)|0;return c=((s=Math.imul(D,gt))+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h[0]=mt,h[1]=bt,h[2]=yt,h[3]=vt,h[4]=wt,h[5]=_t,h[6]=At,h[7]=Mt,h[8]=St,h[9]=Et,h[10]=It,h[11]=xt,h[12]=Ot,h[13]=Nt,h[14]=Pt,h[15]=Rt,h[16]=Tt,h[17]=Ct,h[18]=kt,0!==c&&(h[19]=c,r.length++),r};function g(t,e,r){return(new m).mulp(t,e,r)}function m(t,e){this.x=t,this.y=e}Math.imul||(p=l),s.prototype.mulTo=function(t,e){var r,i=this.length+t.length;return r=10===this.length&&10===t.length?p(this,t,e):i<63?l(this,t,e):i<1024?function(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,s=0;s>>26)|0)>>>26,o&=67108863}r.words[s]=a,i=o,o=n}return 0!==i?r.words[s]=i:r.length--,r.strip()}(this,t,e):g(this,t,e),r},m.prototype.makeRBT=function(t){for(var e=new Array(t),r=s.prototype._countBits(t)-1,i=0;i>=1;return i},m.prototype.permute=function(t,e,r,i,n,s){for(var o=0;o>>=1)n++;return 1<>>=13,r[2*o+1]=8191&s,s>>>=13;for(o=2*e;o>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},s.prototype.muln=function(t){return this.clone().imuln(t)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r>>n}return e}(t);if(0===e.length)return new s(1);for(var r=this,i=0;i=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<o)for(this.length-=o,c=0;c=0&&(0!==f||c>=n);c--){var u=0|this.words[c];this.words[c]=f<<26-s|u>>>s,f=u&a}return h&&0!==f&&(h.words[h.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},s.prototype.shln=function(t){return this.clone().ishln(t)},s.prototype.ushln=function(t){return this.clone().iushln(t)},s.prototype.shrn=function(t){return this.clone().ishrn(t)},s.prototype.ushrn=function(t){return this.clone().iushrn(t)},s.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,n=1<=0);var e=t%26,r=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var n=67108863^67108863>>>e<=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},s.prototype.isubn=function(t){if(i("number"==typeof t),i(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e>26)-(h/67108864|0),this.words[n+r]=67108863&s}for(;n>26,this.words[n+r]=67108863&s;if(0===a)return this.strip();for(i(-1===a),a=0,n=0;n>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},s.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),n=t,o=0|n.words[n.length-1];0!=(r=26-this._countBits(o))&&(n=n.ushln(r),i.iushln(r),o=0|n.words[n.length-1]);var a,h=i.length-n.length;if("mod"!==e){(a=new s(null)).length=h+1,a.words=new Array(a.length);for(var c=0;c=0;u--){var d=67108864*(0|i.words[n.length+u])+(0|i.words[n.length+u-1]);for(d=Math.min(d/o|0,67108863),i._ishlnsubmul(n,d,u);0!==i.negative;)d--,i.negative=0,i._ishlnsubmul(n,1,u),i.isZero()||(i.negative^=1);a&&(a.words[u]=d)}return a&&a.strip(),i.strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:a||null,mod:i}},s.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(n=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:n,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(n=a.div.neg()),{div:n,mod:a.mod}):this.negative&t.negative?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new s(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new s(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new s(this.modn(t.words[0]))}:this._wordDiv(t,e);var n,o,a},s.prototype.div=function(t){return this.divmod(t,"div",!1).div},s.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},s.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},s.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),s=r.cmp(i);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},s.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},s.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},s.prototype.divn=function(t){return this.clone().idivn(t)},s.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n=new s(1),o=new s(0),a=new s(0),h=new s(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var f=r.clone(),u=e.clone();!e.isZero();){for(var d=0,l=1;!(e.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(n.isOdd()||o.isOdd())&&(n.iadd(f),o.isub(u)),n.iushrn(1),o.iushrn(1);for(var p=0,g=1;!(r.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(f),h.isub(u)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),n.isub(a),o.isub(h)):(r.isub(e),a.isub(n),h.isub(o))}return{a,b:h,gcd:r.iushln(c)}},s.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n,o=new s(1),a=new s(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,f=1;!(e.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(e.iushrn(c);c-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var u=0,d=1;!(r.words[0]&d)&&u<26;++u,d<<=1);if(u>0)for(r.iushrn(u);u-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(n=0===e.cmpn(1)?o:a).cmpn(0)<0&&n.iadd(t),n},s.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var s=e;e=r,r=s}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},s.prototype.invm=function(t){return this.egcd(t).a.umod(t)},s.prototype.isEven=function(){return!(1&this.words[0])},s.prototype.isOdd=function(){return!(1&~this.words[0])},s.prototype.andln=function(t){return this.words[0]&t},s.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<>>26,a&=67108863,this.words[o]=a}return 0!==s&&(this.words[o]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:nt.length)return 1;if(this.length=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){in&&(e=1);break}}return e},s.prototype.gtn=function(t){return 1===this.cmpn(t)},s.prototype.gt=function(t){return 1===this.cmp(t)},s.prototype.gten=function(t){return this.cmpn(t)>=0},s.prototype.gte=function(t){return this.cmp(t)>=0},s.prototype.ltn=function(t){return-1===this.cmpn(t)},s.prototype.lt=function(t){return-1===this.cmp(t)},s.prototype.lten=function(t){return this.cmpn(t)<=0},s.prototype.lte=function(t){return this.cmp(t)<=0},s.prototype.eqn=function(t){return 0===this.cmpn(t)},s.prototype.eq=function(t){return 0===this.cmp(t)},s.red=function(t){return new M(t)},s.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},s.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(t){return this.red=t,this},s.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},s.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},s.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},s.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},s.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},s.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},s.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},s.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},s.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function y(t,e){this.name=t,this.p=new s(e,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function v(){y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function w(){y.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function _(){y.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){y.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function M(t){if("string"==typeof t){var e=s._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function S(t){M.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}y.prototype._tmp=function(){var t=new s(null);return t.words=new Array(Math.ceil(this.n/13)),t},y.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},y.prototype.split=function(t,e){t.iushrn(this.n,0,e)},y.prototype.imulK=function(t){return t.imul(this.k)},n(v,y),v.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n>>22,s=o}s>>>=22,t.words[n-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},v.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},s._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new v;else if("p224"===t)e=new w;else if("p192"===t)e=new _;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return b[t]=e,e},M.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},M.prototype._verify2=function(t,e){i(!(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},M.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},M.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},M.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},M.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},M.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},M.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},M.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},M.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},M.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},M.prototype.isqr=function(t){return this.imul(t,t.clone())},M.prototype.sqr=function(t){return this.mul(t,t)},M.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new s(1)).iushrn(2);return this.pow(t,r)}for(var n=this.m.subn(1),o=0;!n.isZero()&&0===n.andln(1);)o++,n.iushrn(1);i(!n.isZero());var a=new s(1).toRed(this),h=a.redNeg(),c=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new s(2*f*f).toRed(this);0!==this.pow(f,c).cmp(h);)f.redIAdd(h);for(var u=this.pow(f,n),d=this.pow(t,n.addn(1).iushrn(1)),l=this.pow(t,n),p=o;0!==l.cmp(a);){for(var g=l,m=0;0!==g.cmp(a);m++)g=g.redSqr();i(m=0;i--){for(var c=e.words[i],f=h-1;f>=0;f--){var u=c>>f&1;n!==r[0]&&(n=this.sqr(n)),0!==u||0!==o?(o<<=1,o|=u,(4==++a||0===i&&0===f)&&(n=this.mul(n,r[o]),a=0,o=0)):a=0}h=26}return n},M.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},M.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},s.mont=function(t){return new S(t)},n(S,M),S.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},S.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},S.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},S.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new s(0)._forceRed(this);var r=t.mul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),o=n;return n.cmp(this.m)>=0?o=n.isub(this.m):n.cmpn(0)<0&&(o=n.iadd(this.m)),o._forceRed(this)},S.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t=r.nmd(t),this)},4112:(t,e,r)=>{var i=e;i.version=r(7559).rE,i.utils=r(8402),i.rand=r(5037),i.curve=r(7867),i.curves=r(7483),i.ec=r(2040),i.eddsa=r(6983)},4278:(t,e,r)=>{var i=r(6455),n=r(8402),s=n.getNAF,o=n.getJSF,a=n.assert;function h(t,e){this.type=t,this.p=new i(e.p,16),this.red=e.prime?i.red(e.prime):i.mont(this.p),this.zero=new i(0).toRed(this.red),this.one=new i(1).toRed(this.red),this.two=new i(2).toRed(this.red),this.n=e.n&&new i(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function c(t,e){this.curve=t,this.type=e,this.precomputed=null}t.exports=h,h.prototype.point=function(){throw new Error("Not implemented")},h.prototype.validate=function(){throw new Error("Not implemented")},h.prototype._fixedNafMul=function(t,e){a(t.precomputed);var r=t._getDoubles(),i=s(e,1,this._bitLength),n=(1<=o;f--)h=(h<<1)+i[f];c.push(h)}for(var u=this.jpoint(null,null,null),d=this.jpoint(null,null,null),l=n;l>0;l--){for(o=0;o=0;c--){for(var f=0;c>=0&&0===o[c];c--)f++;if(c>=0&&f++,h=h.dblp(f),c<0)break;var u=o[c];a(0!==u),h="affine"===t.type?u>0?h.mixedAdd(n[u-1>>1]):h.mixedAdd(n[-u-1>>1].neg()):u>0?h.add(n[u-1>>1]):h.add(n[-u-1>>1].neg())}return"affine"===t.type?h.toP():h},h.prototype._wnafMulAdd=function(t,e,r,i,n){var a,h,c,f=this._wnafT1,u=this._wnafT2,d=this._wnafT3,l=0;for(a=0;a=1;a-=2){var g=a-1,m=a;if(1===f[g]&&1===f[m]){var b=[e[g],null,null,e[m]];0===e[g].y.cmp(e[m].y)?(b[1]=e[g].add(e[m]),b[2]=e[g].toJ().mixedAdd(e[m].neg())):0===e[g].y.cmp(e[m].y.redNeg())?(b[1]=e[g].toJ().mixedAdd(e[m]),b[2]=e[g].add(e[m].neg())):(b[1]=e[g].toJ().mixedAdd(e[m]),b[2]=e[g].toJ().mixedAdd(e[m].neg()));var y=[-3,-1,-5,-7,0,7,5,1,3],v=o(r[g],r[m]);for(l=Math.max(v[0].length,l),d[g]=new Array(l),d[m]=new Array(l),h=0;h=0;a--){for(var S=0;a>=0;){var E=!0;for(h=0;h=0&&S++,A=A.dblp(S),a<0)break;for(h=0;h0?c=u[h][I-1>>1]:I<0&&(c=u[h][-I-1>>1].neg()),A="affine"===c.type?A.mixedAdd(c):A.add(c))}}for(a=0;a=Math.ceil((t.bitLength()+1)/e.step)},c.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],i=this,n=0;n{var i=r(8402),n=r(6455),s=r(6698),o=r(4278),a=i.assert;function h(t){this.twisted=1!=(0|t.a),this.mOneA=this.twisted&&-1==(0|t.a),this.extended=this.mOneA,o.call(this,"edwards",t),this.a=new n(t.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new n(t.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new n(t.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),a(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|t.c)}function c(t,e,r,i,s){o.BasePoint.call(this,t,"projective"),null===e&&null===r&&null===i?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new n(e,16),this.y=new n(r,16),this.z=i?new n(i,16):this.curve.one,this.t=s&&new n(s,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}s(h,o),t.exports=h,h.prototype._mulA=function(t){return this.mOneA?t.redNeg():this.a.redMul(t)},h.prototype._mulC=function(t){return this.oneC?t:this.c.redMul(t)},h.prototype.jpoint=function(t,e,r,i){return this.point(t,e,r,i)},h.prototype.pointFromX=function(t,e){(t=new n(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr(),i=this.c2.redSub(this.a.redMul(r)),s=this.one.redSub(this.c2.redMul(this.d).redMul(r)),o=i.redMul(s.redInvm()),a=o.redSqrt();if(0!==a.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");var h=a.fromRed().isOdd();return(e&&!h||!e&&h)&&(a=a.redNeg()),this.point(t,a)},h.prototype.pointFromY=function(t,e){(t=new n(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr(),i=r.redSub(this.c2),s=r.redMul(this.d).redMul(this.c2).redSub(this.a),o=i.redMul(s.redInvm());if(0===o.cmp(this.zero)){if(e)throw new Error("invalid point");return this.point(this.zero,t)}var a=o.redSqrt();if(0!==a.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");return a.fromRed().isOdd()!==e&&(a=a.redNeg()),this.point(a,t)},h.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();var e=t.x.redSqr(),r=t.y.redSqr(),i=e.redMul(this.a).redAdd(r),n=this.c2.redMul(this.one.redAdd(this.d.redMul(e).redMul(r)));return 0===i.cmp(n)},s(c,o.BasePoint),h.prototype.pointFromJSON=function(t){return c.fromJSON(this,t)},h.prototype.point=function(t,e,r,i){return new c(this,t,e,r,i)},c.fromJSON=function(t,e){return new c(t,e[0],e[1],e[2])},c.prototype.inspect=function(){return this.isInfinity()?"":""},c.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},c.prototype._extDbl=function(){var t=this.x.redSqr(),e=this.y.redSqr(),r=this.z.redSqr();r=r.redIAdd(r);var i=this.curve._mulA(t),n=this.x.redAdd(this.y).redSqr().redISub(t).redISub(e),s=i.redAdd(e),o=s.redSub(r),a=i.redSub(e),h=n.redMul(o),c=s.redMul(a),f=n.redMul(a),u=o.redMul(s);return this.curve.point(h,c,u,f)},c.prototype._projDbl=function(){var t,e,r,i,n,s,o=this.x.redAdd(this.y).redSqr(),a=this.x.redSqr(),h=this.y.redSqr();if(this.curve.twisted){var c=(i=this.curve._mulA(a)).redAdd(h);this.zOne?(t=o.redSub(a).redSub(h).redMul(c.redSub(this.curve.two)),e=c.redMul(i.redSub(h)),r=c.redSqr().redSub(c).redSub(c)):(n=this.z.redSqr(),s=c.redSub(n).redISub(n),t=o.redSub(a).redISub(h).redMul(s),e=c.redMul(i.redSub(h)),r=c.redMul(s))}else i=a.redAdd(h),n=this.curve._mulC(this.z).redSqr(),s=i.redSub(n).redSub(n),t=this.curve._mulC(o.redISub(i)).redMul(s),e=this.curve._mulC(i).redMul(a.redISub(h)),r=i.redMul(s);return this.curve.point(t,e,r)},c.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},c.prototype._extAdd=function(t){var e=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),r=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),i=this.t.redMul(this.curve.dd).redMul(t.t),n=this.z.redMul(t.z.redAdd(t.z)),s=r.redSub(e),o=n.redSub(i),a=n.redAdd(i),h=r.redAdd(e),c=s.redMul(o),f=a.redMul(h),u=s.redMul(h),d=o.redMul(a);return this.curve.point(c,f,d,u)},c.prototype._projAdd=function(t){var e,r,i=this.z.redMul(t.z),n=i.redSqr(),s=this.x.redMul(t.x),o=this.y.redMul(t.y),a=this.curve.d.redMul(s).redMul(o),h=n.redSub(a),c=n.redAdd(a),f=this.x.redAdd(this.y).redMul(t.x.redAdd(t.y)).redISub(s).redISub(o),u=i.redMul(h).redMul(f);return this.curve.twisted?(e=i.redMul(c).redMul(o.redSub(this.curve._mulA(s))),r=h.redMul(c)):(e=i.redMul(c).redMul(o.redSub(s)),r=this.curve._mulC(h).redMul(c)),this.curve.point(u,e,r)},c.prototype.add=function(t){return this.isInfinity()?t:t.isInfinity()?this:this.curve.extended?this._extAdd(t):this._projAdd(t)},c.prototype.mul=function(t){return this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve._wnafMul(this,t)},c.prototype.mulAdd=function(t,e,r){return this.curve._wnafMulAdd(1,[this,e],[t,r],2,!1)},c.prototype.jmulAdd=function(t,e,r){return this.curve._wnafMulAdd(1,[this,e],[t,r],2,!0)},c.prototype.normalize=function(){if(this.zOne)return this;var t=this.z.redInvm();return this.x=this.x.redMul(t),this.y=this.y.redMul(t),this.t&&(this.t=this.t.redMul(t)),this.z=this.curve.one,this.zOne=!0,this},c.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},c.prototype.getX=function(){return this.normalize(),this.x.fromRed()},c.prototype.getY=function(){return this.normalize(),this.y.fromRed()},c.prototype.eq=function(t){return this===t||0===this.getX().cmp(t.getX())&&0===this.getY().cmp(t.getY())},c.prototype.eqXToP=function(t){var e=t.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(e))return!0;for(var r=t.clone(),i=this.curve.redN.redMul(this.z);;){if(r.iadd(this.curve.n),r.cmp(this.curve.p)>=0)return!1;if(e.redIAdd(i),0===this.x.cmp(e))return!0}},c.prototype.toP=c.prototype.normalize,c.prototype.mixedAdd=c.prototype.add},7867:(t,e,r)=>{var i=e;i.base=r(4278),i.short=r(3461),i.mont=r(4397),i.edwards=r(6491)},4397:(t,e,r)=>{var i=r(6455),n=r(6698),s=r(4278),o=r(8402);function a(t){s.call(this,"mont",t),this.a=new i(t.a,16).toRed(this.red),this.b=new i(t.b,16).toRed(this.red),this.i4=new i(4).toRed(this.red).redInvm(),this.two=new i(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}function h(t,e,r){s.BasePoint.call(this,t,"projective"),null===e&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new i(e,16),this.z=new i(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}n(a,s),t.exports=a,a.prototype.validate=function(t){var e=t.normalize().x,r=e.redSqr(),i=r.redMul(e).redAdd(r.redMul(this.a)).redAdd(e);return 0===i.redSqrt().redSqr().cmp(i)},n(h,s.BasePoint),a.prototype.decodePoint=function(t,e){return this.point(o.toArray(t,e),1)},a.prototype.point=function(t,e){return new h(this,t,e)},a.prototype.pointFromJSON=function(t){return h.fromJSON(this,t)},h.prototype.precompute=function(){},h.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},h.fromJSON=function(t,e){return new h(t,e[0],e[1]||t.one)},h.prototype.inspect=function(){return this.isInfinity()?"":""},h.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},h.prototype.dbl=function(){var t=this.x.redAdd(this.z).redSqr(),e=this.x.redSub(this.z).redSqr(),r=t.redSub(e),i=t.redMul(e),n=r.redMul(e.redAdd(this.curve.a24.redMul(r)));return this.curve.point(i,n)},h.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},h.prototype.diffAdd=function(t,e){var r=this.x.redAdd(this.z),i=this.x.redSub(this.z),n=t.x.redAdd(t.z),s=t.x.redSub(t.z).redMul(r),o=n.redMul(i),a=e.z.redMul(s.redAdd(o).redSqr()),h=e.x.redMul(s.redISub(o).redSqr());return this.curve.point(a,h)},h.prototype.mul=function(t){for(var e=t.clone(),r=this,i=this.curve.point(null,null),n=[];0!==e.cmpn(0);e.iushrn(1))n.push(e.andln(1));for(var s=n.length-1;s>=0;s--)0===n[s]?(r=r.diffAdd(i,this),i=i.dbl()):(i=r.diffAdd(i,this),r=r.dbl());return i},h.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},h.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},h.prototype.eq=function(t){return 0===this.getX().cmp(t.getX())},h.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},h.prototype.getX=function(){return this.normalize(),this.x.fromRed()}},3461:(t,e,r)=>{var i=r(8402),n=r(6455),s=r(6698),o=r(4278),a=i.assert;function h(t){o.call(this,"short",t),this.a=new n(t.a,16).toRed(this.red),this.b=new n(t.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=0===this.a.fromRed().cmpn(0),this.threeA=0===this.a.fromRed().sub(this.p).cmpn(-3),this.endo=this._getEndomorphism(t),this._endoWnafT1=new Array(4),this._endoWnafT2=new Array(4)}function c(t,e,r,i){o.BasePoint.call(this,t,"affine"),null===e&&null===r?(this.x=null,this.y=null,this.inf=!0):(this.x=new n(e,16),this.y=new n(r,16),i&&(this.x.forceRed(this.curve.red),this.y.forceRed(this.curve.red)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.inf=!1)}function f(t,e,r,i){o.BasePoint.call(this,t,"jacobian"),null===e&&null===r&&null===i?(this.x=this.curve.one,this.y=this.curve.one,this.z=new n(0)):(this.x=new n(e,16),this.y=new n(r,16),this.z=new n(i,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}s(h,o),t.exports=h,h.prototype._getEndomorphism=function(t){if(this.zeroA&&this.g&&this.n&&1===this.p.modn(3)){var e,r;if(t.beta)e=new n(t.beta,16).toRed(this.red);else{var i=this._getEndoRoots(this.p);e=(e=i[0].cmp(i[1])<0?i[0]:i[1]).toRed(this.red)}if(t.lambda)r=new n(t.lambda,16);else{var s=this._getEndoRoots(this.n);0===this.g.mul(s[0]).x.cmp(this.g.x.redMul(e))?r=s[0]:(r=s[1],a(0===this.g.mul(r).x.cmp(this.g.x.redMul(e))))}return{beta:e,lambda:r,basis:t.basis?t.basis.map((function(t){return{a:new n(t.a,16),b:new n(t.b,16)}})):this._getEndoBasis(r)}}},h.prototype._getEndoRoots=function(t){var e=t===this.p?this.red:n.mont(t),r=new n(2).toRed(e).redInvm(),i=r.redNeg(),s=new n(3).toRed(e).redNeg().redSqrt().redMul(r);return[i.redAdd(s).fromRed(),i.redSub(s).fromRed()]},h.prototype._getEndoBasis=function(t){for(var e,r,i,s,o,a,h,c,f,u=this.n.ushrn(Math.floor(this.n.bitLength()/2)),d=t,l=this.n.clone(),p=new n(1),g=new n(0),m=new n(0),b=new n(1),y=0;0!==d.cmpn(0);){var v=l.div(d);c=l.sub(v.mul(d)),f=m.sub(v.mul(p));var w=b.sub(v.mul(g));if(!i&&c.cmp(u)<0)e=h.neg(),r=p,i=c.neg(),s=f;else if(i&&2==++y)break;h=c,l=d,d=c,m=p,p=f,b=g,g=w}o=c.neg(),a=f;var _=i.sqr().add(s.sqr());return o.sqr().add(a.sqr()).cmp(_)>=0&&(o=e,a=r),i.negative&&(i=i.neg(),s=s.neg()),o.negative&&(o=o.neg(),a=a.neg()),[{a:i,b:s},{a:o,b:a}]},h.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],i=e[1],n=i.b.mul(t).divRound(this.n),s=r.b.neg().mul(t).divRound(this.n),o=n.mul(r.a),a=s.mul(i.a),h=n.mul(r.b),c=s.mul(i.b);return{k1:t.sub(o).sub(a),k2:h.add(c).neg()}},h.prototype.pointFromX=function(t,e){(t=new n(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),i=r.redSqrt();if(0!==i.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var s=i.fromRed().isOdd();return(e&&!s||!e&&s)&&(i=i.redNeg()),this.point(t,i)},h.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,i=this.a.redMul(e),n=e.redSqr().redMul(e).redIAdd(i).redIAdd(this.b);return 0===r.redSqr().redISub(n).cmpn(0)},h.prototype._endoWnafMulAdd=function(t,e,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,s=0;s":""},c.prototype.isInfinity=function(){return this.inf},c.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),i=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,i)},c.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),i=t.redInvm(),n=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(i),s=n.redSqr().redISub(this.x.redAdd(this.x)),o=n.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)},c.prototype.getX=function(){return this.x.fromRed()},c.prototype.getY=function(){return this.y.fromRed()},c.prototype.mul=function(t){return t=new n(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},c.prototype.mulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},c.prototype.jmulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},c.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},c.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,i=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(i)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(i)}}}return e},c.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},s(f,o.BasePoint),h.prototype.jpoint=function(t,e,r){return new f(this,t,e,r)},f.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),i=this.y.redMul(e).redMul(t);return this.curve.point(r,i)},f.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},f.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(e),n=t.x.redMul(r),s=this.y.redMul(e.redMul(t.z)),o=t.y.redMul(r.redMul(this.z)),a=i.redSub(n),h=s.redSub(o);if(0===a.cmpn(0))return 0!==h.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=a.redSqr(),f=c.redMul(a),u=i.redMul(c),d=h.redSqr().redIAdd(f).redISub(u).redISub(u),l=h.redMul(u.redISub(d)).redISub(s.redMul(f)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(d,l,p)},f.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,i=t.x.redMul(e),n=this.y,s=t.y.redMul(e).redMul(this.z),o=r.redSub(i),a=n.redSub(s);if(0===o.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var h=o.redSqr(),c=h.redMul(o),f=r.redMul(h),u=a.redSqr().redIAdd(c).redISub(f).redISub(f),d=a.redMul(f.redISub(u)).redISub(n.redMul(c)),l=this.z.redMul(o);return this.curve.jpoint(u,d,l)},f.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e=0)return!1;if(r.redIAdd(n),0===this.x.cmp(r))return!0}},f.prototype.inspect=function(){return this.isInfinity()?"":""},f.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},7483:(t,e,r)=>{var i,n=e,s=r(7952),o=r(7867),a=r(8402).assert;function h(t){"short"===t.type?this.curve=new o.short(t):"edwards"===t.type?this.curve=new o.edwards(t):this.curve=new o.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,a(this.g.validate(),"Invalid curve"),a(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function c(t,e){Object.defineProperty(n,t,{configurable:!0,enumerable:!0,get:function(){var r=new h(e);return Object.defineProperty(n,t,{configurable:!0,enumerable:!0,value:r}),r}})}n.PresetCurve=h,c("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:s.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),c("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:s.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),c("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:s.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),c("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:s.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),c("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:s.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),c("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:s.sha256,gRed:!1,g:["9"]}),c("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:s.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{i=r(4674)}catch(t){i=void 0}c("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:s.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",i]})},2040:(t,e,r)=>{var i=r(6455),n=r(2723),s=r(8402),o=r(7483),a=r(5037),h=s.assert,c=r(4747),f=r(6390);function u(t){if(!(this instanceof u))return new u(t);"string"==typeof t&&(h(Object.prototype.hasOwnProperty.call(o,t),"Unknown curve "+t),t=o[t]),t instanceof o.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}t.exports=u,u.prototype.keyPair=function(t){return new c(this,t)},u.prototype.keyFromPrivate=function(t,e){return c.fromPrivate(this,t,e)},u.prototype.keyFromPublic=function(t,e){return c.fromPublic(this,t,e)},u.prototype.genKeyPair=function(t){t||(t={});for(var e=new n({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||a(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),r=this.n.byteLength(),s=this.n.sub(new i(2));;){var o=new i(e.generate(r));if(!(o.cmp(s)>0))return o.iaddn(1),this.keyFromPrivate(o)}},u.prototype._truncateToN=function(t,e){var r=8*t.byteLength()-this.n.bitLength();return r>0&&(t=t.ushrn(r)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},u.prototype.sign=function(t,e,r,s){"object"==typeof r&&(s=r,r=null),s||(s={}),e=this.keyFromPrivate(e,r),t=this._truncateToN(new i(t,16));for(var o=this.n.byteLength(),a=e.getPrivate().toArray("be",o),h=t.toArray("be",o),c=new n({hash:this.hash,entropy:a,nonce:h,pers:s.pers,persEnc:s.persEnc||"utf8"}),u=this.n.sub(new i(1)),d=0;;d++){var l=s.k?s.k(d):new i(c.generate(this.n.byteLength()));if(!((l=this._truncateToN(l,!0)).cmpn(1)<=0||l.cmp(u)>=0)){var p=this.g.mul(l);if(!p.isInfinity()){var g=p.getX(),m=g.umod(this.n);if(0!==m.cmpn(0)){var b=l.invm(this.n).mul(m.mul(e.getPrivate()).iadd(t));if(0!==(b=b.umod(this.n)).cmpn(0)){var y=(p.getY().isOdd()?1:0)|(0!==g.cmp(m)?2:0);return s.canonical&&b.cmp(this.nh)>0&&(b=this.n.sub(b),y^=1),new f({r:m,s:b,recoveryParam:y})}}}}}},u.prototype.verify=function(t,e,r,n){t=this._truncateToN(new i(t,16)),r=this.keyFromPublic(r,n);var s=(e=new f(e,"hex")).r,o=e.s;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;if(o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;var a,h=o.invm(this.n),c=h.mul(t).umod(this.n),u=h.mul(s).umod(this.n);return this.curve._maxwellTrick?!(a=this.g.jmulAdd(c,r.getPublic(),u)).isInfinity()&&a.eqXToP(s):!(a=this.g.mulAdd(c,r.getPublic(),u)).isInfinity()&&0===a.getX().umod(this.n).cmp(s)},u.prototype.recoverPubKey=function(t,e,r,n){h((3&r)===r,"The recovery param is more than two bits"),e=new f(e,n);var s=this.n,o=new i(t),a=e.r,c=e.s,u=1&r,d=r>>1;if(a.cmp(this.curve.p.umod(this.curve.n))>=0&&d)throw new Error("Unable to find sencond key candinate");a=d?this.curve.pointFromX(a.add(this.curve.n),u):this.curve.pointFromX(a,u);var l=e.r.invm(s),p=s.sub(o).mul(l).umod(s),g=c.mul(l).umod(s);return this.g.mulAdd(p,a,g)},u.prototype.getKeyRecoveryParam=function(t,e,r,i){if(null!==(e=new f(e,i)).recoveryParam)return e.recoveryParam;for(var n=0;n<4;n++){var s;try{s=this.recoverPubKey(t,e,n)}catch(t){continue}if(s.eq(r))return n}throw new Error("Unable to find valid recovery factor")}},4747:(t,e,r)=>{var i=r(6455),n=r(8402).assert;function s(t,e){this.ec=t,this.priv=null,this.pub=null,e.priv&&this._importPrivate(e.priv,e.privEnc),e.pub&&this._importPublic(e.pub,e.pubEnc)}t.exports=s,s.fromPublic=function(t,e,r){return e instanceof s?e:new s(t,{pub:e,pubEnc:r})},s.fromPrivate=function(t,e,r){return e instanceof s?e:new s(t,{priv:e,privEnc:r})},s.prototype.validate=function(){var t=this.getPublic();return t.isInfinity()?{result:!1,reason:"Invalid public key"}:t.validate()?t.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},s.prototype.getPublic=function(t,e){return"string"==typeof t&&(e=t,t=null),this.pub||(this.pub=this.ec.g.mul(this.priv)),e?this.pub.encode(e,t):this.pub},s.prototype.getPrivate=function(t){return"hex"===t?this.priv.toString(16,2):this.priv},s.prototype._importPrivate=function(t,e){this.priv=new i(t,e||16),this.priv=this.priv.umod(this.ec.curve.n)},s.prototype._importPublic=function(t,e){if(t.x||t.y)return"mont"===this.ec.curve.type?n(t.x,"Need x coordinate"):"short"!==this.ec.curve.type&&"edwards"!==this.ec.curve.type||n(t.x&&t.y,"Need both x and y coordinate"),void(this.pub=this.ec.curve.point(t.x,t.y));this.pub=this.ec.curve.decodePoint(t,e)},s.prototype.derive=function(t){return t.validate()||n(t.validate(),"public point not validated"),t.mul(this.priv).getX()},s.prototype.sign=function(t,e,r){return this.ec.sign(t,this,e,r)},s.prototype.verify=function(t,e){return this.ec.verify(t,e,this)},s.prototype.inspect=function(){return""}},6390:(t,e,r)=>{var i=r(6455),n=r(8402),s=n.assert;function o(t,e){if(t instanceof o)return t;this._importDER(t,e)||(s(t.r&&t.s,"Signature without r or s"),this.r=new i(t.r,16),this.s=new i(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}function a(){this.place=0}function h(t,e){var r=t[e.place++];if(!(128&r))return r;var i=15&r;if(0===i||i>4)return!1;if(0===t[e.place])return!1;for(var n=0,s=0,o=e.place;s>>=0;return!(n<=127)&&(e.place=o,n)}function c(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}t.exports=o,o.prototype._importDER=function(t,e){t=n.toArray(t,e);var r=new a;if(48!==t[r.place++])return!1;var s=h(t,r);if(!1===s)return!1;if(s+r.place!==t.length)return!1;if(2!==t[r.place++])return!1;var o=h(t,r);if(!1===o)return!1;if(128&t[r.place])return!1;var c=t.slice(r.place,o+r.place);if(r.place+=o,2!==t[r.place++])return!1;var f=h(t,r);if(!1===f)return!1;if(t.length!==f+r.place)return!1;if(128&t[r.place])return!1;var u=t.slice(r.place,f+r.place);if(0===c[0]){if(!(128&c[1]))return!1;c=c.slice(1)}if(0===u[0]){if(!(128&u[1]))return!1;u=u.slice(1)}return this.r=new i(c),this.s=new i(u),this.recoveryParam=null,!0},o.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=c(e),r=c(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];f(i,e.length),(i=i.concat(e)).push(2),f(i,r.length);var s=i.concat(r),o=[48];return f(o,s.length),o=o.concat(s),n.encode(o,t)}},6983:(t,e,r)=>{var i=r(7952),n=r(7483),s=r(8402),o=s.assert,a=s.parseBytes,h=r(6032),c=r(7681);function f(t){if(o("ed25519"===t,"only tested with ed25519 so far"),!(this instanceof f))return new f(t);t=n[t].curve,this.curve=t,this.g=t.g,this.g.precompute(t.n.bitLength()+1),this.pointClass=t.point().constructor,this.encodingLength=Math.ceil(t.n.bitLength()/8),this.hash=i.sha512}t.exports=f,f.prototype.sign=function(t,e){t=a(t);var r=this.keyFromSecret(e),i=this.hashInt(r.messagePrefix(),t),n=this.g.mul(i),s=this.encodePoint(n),o=this.hashInt(s,r.pubBytes(),t).mul(r.priv()),h=i.add(o).umod(this.curve.n);return this.makeSignature({R:n,S:h,Rencoded:s})},f.prototype.verify=function(t,e,r){if(t=a(t),(e=this.makeSignature(e)).S().gte(e.eddsa.curve.n)||e.S().isNeg())return!1;var i=this.keyFromPublic(r),n=this.hashInt(e.Rencoded(),i.pubBytes(),t),s=this.g.mul(e.S());return e.R().add(i.pub().mul(n)).eq(s)},f.prototype.hashInt=function(){for(var t=this.hash(),e=0;e{var i=r(8402),n=i.assert,s=i.parseBytes,o=i.cachedProperty;function a(t,e){this.eddsa=t,this._secret=s(e.secret),t.isPoint(e.pub)?this._pub=e.pub:this._pubBytes=s(e.pub)}a.fromPublic=function(t,e){return e instanceof a?e:new a(t,{pub:e})},a.fromSecret=function(t,e){return e instanceof a?e:new a(t,{secret:e})},a.prototype.secret=function(){return this._secret},o(a,"pubBytes",(function(){return this.eddsa.encodePoint(this.pub())})),o(a,"pub",(function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())})),o(a,"privBytes",(function(){var t=this.eddsa,e=this.hash(),r=t.encodingLength-1,i=e.slice(0,t.encodingLength);return i[0]&=248,i[r]&=127,i[r]|=64,i})),o(a,"priv",(function(){return this.eddsa.decodeInt(this.privBytes())})),o(a,"hash",(function(){return this.eddsa.hash().update(this.secret()).digest()})),o(a,"messagePrefix",(function(){return this.hash().slice(this.eddsa.encodingLength)})),a.prototype.sign=function(t){return n(this._secret,"KeyPair can only verify"),this.eddsa.sign(t,this)},a.prototype.verify=function(t,e){return this.eddsa.verify(t,e,this)},a.prototype.getSecret=function(t){return n(this._secret,"KeyPair is public only"),i.encode(this.secret(),t)},a.prototype.getPublic=function(t){return i.encode(this.pubBytes(),t)},t.exports=a},7681:(t,e,r)=>{var i=r(6455),n=r(8402),s=n.assert,o=n.cachedProperty,a=n.parseBytes;function h(t,e){this.eddsa=t,"object"!=typeof e&&(e=a(e)),Array.isArray(e)&&(s(e.length===2*t.encodingLength,"Signature has invalid size"),e={R:e.slice(0,t.encodingLength),S:e.slice(t.encodingLength)}),s(e.R&&e.S,"Signature without R or S"),t.isPoint(e.R)&&(this._R=e.R),e.S instanceof i&&(this._S=e.S),this._Rencoded=Array.isArray(e.R)?e.R:e.Rencoded,this._Sencoded=Array.isArray(e.S)?e.S:e.Sencoded}o(h,"S",(function(){return this.eddsa.decodeInt(this.Sencoded())})),o(h,"R",(function(){return this.eddsa.decodePoint(this.Rencoded())})),o(h,"Rencoded",(function(){return this.eddsa.encodePoint(this.R())})),o(h,"Sencoded",(function(){return this.eddsa.encodeInt(this.S())})),h.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},h.prototype.toHex=function(){return n.encode(this.toBytes(),"hex").toUpperCase()},t.exports=h},4674:t=>{t.exports={doubles:{step:4,points:[["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a","f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"],["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508","11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"],["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739","d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"],["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640","4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"],["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c","4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"],["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda","96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"],["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa","5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"],["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0","cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"],["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d","9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"],["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d","e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"],["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1","9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"],["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0","5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"],["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047","10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"],["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862","283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"],["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7","7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"],["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd","56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"],["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83","7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"],["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a","53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"],["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8","bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"],["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d","4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"],["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725","7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"],["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754","4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"],["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c","17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"],["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6","6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"],["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39","c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"],["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891","893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"],["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b","febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"],["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03","2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"],["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d","eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"],["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070","7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"],["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4","e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"],["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da","662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"],["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11","1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"],["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e","efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"],["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41","2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"],["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef","67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"],["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8","db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"],["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d","648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"],["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96","35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"],["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd","ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"],["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5","9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"],["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266","40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"],["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71","34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"],["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac","c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"],["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751","1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"],["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e","493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"],["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241","c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"],["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3","be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"],["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f","4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"],["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19","aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"],["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be","b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"],["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9","6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"],["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2","8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"],["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13","7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"],["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c","ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"],["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba","2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"],["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151","e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"],["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073","d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"],["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458","38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"],["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b","69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"],["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366","d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"],["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa","40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"],["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0","620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"],["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787","7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"],["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e","ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]]},naf:{wnd:7,points:[["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9","388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"],["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4","d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"],["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc","6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"],["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe","cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"],["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb","d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"],["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8","ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"],["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e","581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"],["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34","4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"],["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c","85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"],["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5","321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"],["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"],["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714","73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"],["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729","a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"],["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db","2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"],["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4","e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"],["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5","b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"],["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479","2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"],["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d","80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"],["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f","1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"],["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb","d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"],["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9","eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"],["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963","758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"],["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74","958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"],["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530","e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"],["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b","5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"],["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247","cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"],["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1","cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"],["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120","4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"],["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435","91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"],["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18","673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"],["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8","59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"],["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb","3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"],["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f","55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"],["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143","efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"],["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba","e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"],["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45","f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"],["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a","744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"],["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e","c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"],["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8","e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"],["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c","30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"],["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519","e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"],["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab","100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"],["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca","ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"],["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf","8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"],["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610","68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"],["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4","f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"],["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c","d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"],["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940","edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"],["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980","a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"],["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3","66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"],["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf","9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"],["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63","4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"],["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448","fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"],["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf","5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"],["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5","8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"],["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6","8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"],["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5","5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"],["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99","f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"],["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51","f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"],["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5","42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"],["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5","204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"],["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997","4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"],["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881","73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"],["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5","39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"],["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66","d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"],["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726","ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"],["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede","6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"],["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94","60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"],["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31","3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"],["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51","b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"],["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252","ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"],["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5","cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"],["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b","6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"],["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4","322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"],["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f","6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"],["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889","2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"],["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246","b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"],["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984","998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"],["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a","b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"],["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030","bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"],["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197","6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"],["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593","c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"],["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef","21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"],["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38","60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"],["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a","49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"],["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111","5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"],["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502","7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"],["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea","be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"],["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26","8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"],["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986","39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"],["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e","62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"],["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4","25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"],["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda","ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"],["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859","cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"],["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f","f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"],["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c","6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"],["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942","fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"],["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a","1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"],["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80","5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"],["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d","438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"],["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1","cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"],["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63","c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"],["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352","6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"],["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193","ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"],["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00","9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"],["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58","ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"],["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7","d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"],["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8","c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"],["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e","67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"],["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d","cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"],["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b","299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"],["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f","f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"],["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6","462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"],["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297","62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"],["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a","7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"],["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c","ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"],["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52","4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"],["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb","bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"],["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065","bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"],["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917","603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"],["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9","cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"],["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3","553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"],["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57","712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"],["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66","ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"],["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8","9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"],["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721","9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"],["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180","4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]]}}},8402:(t,e,r)=>{var i=e,n=r(6455),s=r(3349),o=r(4367);i.assert=s,i.toArray=o.toArray,i.zero2=o.zero2,i.toHex=o.toHex,i.encode=o.encode,i.getNAF=function(t,e,r){var i,n=new Array(Math.max(t.bitLength(),r)+1);for(i=0;i(s>>1)-1?(s>>1)-h:h,o.isubn(a)):a=0,n[i]=a,o.iushrn(1)}return n},i.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var i,n=0,s=0;t.cmpn(-n)>0||e.cmpn(-s)>0;){var o,a,h=t.andln(3)+n&3,c=e.andln(3)+s&3;3===h&&(h=-1),3===c&&(c=-1),o=1&h?3!=(i=t.andln(7)+n&7)&&5!==i||2!==c?h:-h:0,r[0].push(o),a=1&c?3!=(i=e.andln(7)+s&7)&&5!==i||2!==h?c:-c:0,r[1].push(a),2*n===o+1&&(n=1-n),2*s===a+1&&(s=1-s),t.iushrn(1),e.iushrn(1)}return r},i.cachedProperty=function(t,e,r){var i="_"+e;t.prototype[e]=function(){return void 0!==this[i]?this[i]:this[i]=r.call(this)}},i.parseBytes=function(t){return"string"==typeof t?i.toArray(t,"hex"):t},i.intFromLE=function(t){return new n(t,"hex","le")}},8196:(t,e)=>{function r(t){let e;return"undefined"!=typeof window&&void 0!==window[t]&&(e=window[t]),e}function i(t){const e=r(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}Object.defineProperty(e,"__esModule",{value:!0}),e.getLocalStorage=e.getLocalStorageOrThrow=e.getCrypto=e.getCryptoOrThrow=e.getLocation=e.getLocationOrThrow=e.getNavigator=e.getNavigatorOrThrow=e.getDocument=e.getDocumentOrThrow=e.getFromWindowOrThrow=e.getFromWindow=void 0,e.getFromWindow=r,e.getFromWindowOrThrow=i,e.getDocumentOrThrow=function(){return i("document")},e.getDocument=function(){return r("document")},e.getNavigatorOrThrow=function(){return i("navigator")},e.getNavigator=function(){return r("navigator")},e.getLocationOrThrow=function(){return i("location")},e.getLocation=function(){return r("location")},e.getCryptoOrThrow=function(){return i("crypto")},e.getCrypto=function(){return r("crypto")},e.getLocalStorageOrThrow=function(){return i("localStorage")},e.getLocalStorage=function(){return r("localStorage")}},2063:(t,e,r)=>{e.g=void 0;const i=r(8196);e.g=function(){let t,e;try{t=i.getDocumentOrThrow(),e=i.getLocationOrThrow()}catch(t){return null}function r(...e){const r=t.getElementsByTagName("meta");for(let t=0;ti.getAttribute(t))).filter((t=>!!t&&e.includes(t)));if(n.length&&n){const t=i.getAttribute("content");if(t)return t}}return""}const n=function(){let e=r("name","og:site_name","og:title","twitter:title");return e||(e=t.title),e}(),s=r("description","og:description","twitter:description","keywords"),o=e.origin,a=function(){const r=t.getElementsByTagName("link"),i=[];for(let t=0;t-1){const t=n.getAttribute("href");if(t)if(-1===t.toLowerCase().indexOf("https:")&&-1===t.toLowerCase().indexOf("http:")&&0!==t.indexOf("//")){let r=e.protocol+"//"+e.host;if(0===t.indexOf("/"))r+=t;else{const i=e.pathname.split("/");i.pop(),r+=i.join("/")+"/"+t}i.push(r)}else if(0===t.indexOf("//")){const r=e.protocol+t;i.push(r)}else i.push(t)}}return i}();return{description:s,url:o,icons:a,name:n}}},9404:function(t,e,r){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function s(t,e,r){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof t?t.exports=s:e.BN=s,s.BN=s,s.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:r(7790).Buffer}catch(t){}function a(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void i(!1,"Invalid character in "+t)}function h(t,e,r){var i=a(t,r);return r-1>=e&&(i|=a(t,r-1)<<4),i}function c(t,e,r,n){for(var s=0,o=0,a=Math.min(t.length,r),h=e;h=49?c-49+10:c>=17?c-17+10:c,i(c>=0&&o0?t:e},s.min=function(t,e){return t.cmp(e)<0?t:e},s.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},s.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i=e;i-=2)n=h(t,e,i)<=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;else for(i=(t.length-e)%2==0?e+1:e;i=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;this._strip()},s.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,h=0,f=r;f1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{s.prototype[Symbol.for("nodejs.util.inspect.custom")]=u}catch(t){s.prototype.inspect=u}else s.prototype.inspect=u;function u(){return(this.red?""}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],l=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],p=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function g(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,h=o/67108864|0;r.words[0]=a;for(var c=1;c>>26,u=67108863&h,d=Math.min(c,e.length-1),l=Math.max(0,c-t.length+1);l<=d;l++){var p=c-l|0;f+=(o=(n=0|t.words[p])*(s=0|e.words[l])+u)/67108864|0,u=67108863&o}r.words[c]=0|u,h=0|f}return 0!==h?r.words[c]=0|h:r.length--,r._strip()}s.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o>>24-n&16777215,(n+=2)>=26&&(n-=26,o--),r=0!==s||o!==this.length-1?d[6-h.length]+h+r:h+r}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=l[t],f=p[t];r="";var u=this.clone();for(u.negative=0;!u.isZero();){var g=u.modrn(f).toString(t);r=(u=u.idivn(f)).isZero()?g+r:d[c-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16,2)},o&&(s.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),s.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},s.prototype.toArrayLike=function(t,e,r){this._strip();var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0");var o=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,s);return this["_toArrayLike"+("le"===e?"LE":"BE")](o,n),o},s.prototype._toArrayLikeLE=function(t,e){for(var r=0,i=0,n=0,s=0;n>8&255),r>16&255),6===s?(r>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r=0&&(t[r--]=o>>8&255),r>=0&&(t[r--]=o>>16&255),6===s?(r>=0&&(t[r--]=o>>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r>=0)for(t[r--]=i;r>=0;)t[r--]=0},Math.clz32?s.prototype._countBits=function(t){return 32-Math.clz32(t)}:s.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},s.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},s.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;rt.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;it.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n0&&(this.words[n]=~this.words[n]&67108863>>26-r),this._strip()},s.prototype.notn=function(t){return this.clone().inotn(t)},s.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s>>26;for(;0!==n&&s>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;st.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o>26,this.words[o]=67108863&e;for(;0!==s&&o>26,this.words[o]=67108863&e;if(0===s&&o>>13,l=0|o[1],p=8191&l,g=l>>>13,m=0|o[2],b=8191&m,y=m>>>13,v=0|o[3],w=8191&v,_=v>>>13,A=0|o[4],M=8191&A,S=A>>>13,E=0|o[5],I=8191&E,x=E>>>13,O=0|o[6],N=8191&O,P=O>>>13,R=0|o[7],T=8191&R,C=R>>>13,k=0|o[8],L=8191&k,q=k>>>13,U=0|o[9],B=8191&U,D=U>>>13,z=0|a[0],j=8191&z,F=z>>>13,K=0|a[1],V=8191&K,H=K>>>13,W=0|a[2],J=8191&W,G=W>>>13,$=0|a[3],Y=8191&$,Q=$>>>13,X=0|a[4],Z=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ct=at>>>13,ft=0|a[8],ut=8191&ft,dt=ft>>>13,lt=0|a[9],pt=8191<,gt=lt>>>13;r.negative=t.negative^e.negative,r.length=19;var mt=(c+(i=Math.imul(u,j))|0)+((8191&(n=(n=Math.imul(u,F))+Math.imul(d,j)|0))<<13)|0;c=((s=Math.imul(d,F))+(n>>>13)|0)+(mt>>>26)|0,mt&=67108863,i=Math.imul(p,j),n=(n=Math.imul(p,F))+Math.imul(g,j)|0,s=Math.imul(g,F);var bt=(c+(i=i+Math.imul(u,V)|0)|0)+((8191&(n=(n=n+Math.imul(u,H)|0)+Math.imul(d,V)|0))<<13)|0;c=((s=s+Math.imul(d,H)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(b,j),n=(n=Math.imul(b,F))+Math.imul(y,j)|0,s=Math.imul(y,F),i=i+Math.imul(p,V)|0,n=(n=n+Math.imul(p,H)|0)+Math.imul(g,V)|0,s=s+Math.imul(g,H)|0;var yt=(c+(i=i+Math.imul(u,J)|0)|0)+((8191&(n=(n=n+Math.imul(u,G)|0)+Math.imul(d,J)|0))<<13)|0;c=((s=s+Math.imul(d,G)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(w,j),n=(n=Math.imul(w,F))+Math.imul(_,j)|0,s=Math.imul(_,F),i=i+Math.imul(b,V)|0,n=(n=n+Math.imul(b,H)|0)+Math.imul(y,V)|0,s=s+Math.imul(y,H)|0,i=i+Math.imul(p,J)|0,n=(n=n+Math.imul(p,G)|0)+Math.imul(g,J)|0,s=s+Math.imul(g,G)|0;var vt=(c+(i=i+Math.imul(u,Y)|0)|0)+((8191&(n=(n=n+Math.imul(u,Q)|0)+Math.imul(d,Y)|0))<<13)|0;c=((s=s+Math.imul(d,Q)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(M,j),n=(n=Math.imul(M,F))+Math.imul(S,j)|0,s=Math.imul(S,F),i=i+Math.imul(w,V)|0,n=(n=n+Math.imul(w,H)|0)+Math.imul(_,V)|0,s=s+Math.imul(_,H)|0,i=i+Math.imul(b,J)|0,n=(n=n+Math.imul(b,G)|0)+Math.imul(y,J)|0,s=s+Math.imul(y,G)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,Q)|0;var wt=(c+(i=i+Math.imul(u,Z)|0)|0)+((8191&(n=(n=n+Math.imul(u,tt)|0)+Math.imul(d,Z)|0))<<13)|0;c=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(I,j),n=(n=Math.imul(I,F))+Math.imul(x,j)|0,s=Math.imul(x,F),i=i+Math.imul(M,V)|0,n=(n=n+Math.imul(M,H)|0)+Math.imul(S,V)|0,s=s+Math.imul(S,H)|0,i=i+Math.imul(w,J)|0,n=(n=n+Math.imul(w,G)|0)+Math.imul(_,J)|0,s=s+Math.imul(_,G)|0,i=i+Math.imul(b,Y)|0,n=(n=n+Math.imul(b,Q)|0)+Math.imul(y,Y)|0,s=s+Math.imul(y,Q)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,tt)|0;var _t=(c+(i=i+Math.imul(u,rt)|0)|0)+((8191&(n=(n=n+Math.imul(u,it)|0)+Math.imul(d,rt)|0))<<13)|0;c=((s=s+Math.imul(d,it)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(N,j),n=(n=Math.imul(N,F))+Math.imul(P,j)|0,s=Math.imul(P,F),i=i+Math.imul(I,V)|0,n=(n=n+Math.imul(I,H)|0)+Math.imul(x,V)|0,s=s+Math.imul(x,H)|0,i=i+Math.imul(M,J)|0,n=(n=n+Math.imul(M,G)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,G)|0,i=i+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,Q)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,Q)|0,i=i+Math.imul(b,Z)|0,n=(n=n+Math.imul(b,tt)|0)+Math.imul(y,Z)|0,s=s+Math.imul(y,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(g,rt)|0,s=s+Math.imul(g,it)|0;var At=(c+(i=i+Math.imul(u,st)|0)|0)+((8191&(n=(n=n+Math.imul(u,ot)|0)+Math.imul(d,st)|0))<<13)|0;c=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(T,j),n=(n=Math.imul(T,F))+Math.imul(C,j)|0,s=Math.imul(C,F),i=i+Math.imul(N,V)|0,n=(n=n+Math.imul(N,H)|0)+Math.imul(P,V)|0,s=s+Math.imul(P,H)|0,i=i+Math.imul(I,J)|0,n=(n=n+Math.imul(I,G)|0)+Math.imul(x,J)|0,s=s+Math.imul(x,G)|0,i=i+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,Q)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,Q)|0,i=i+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,tt)|0,i=i+Math.imul(b,rt)|0,n=(n=n+Math.imul(b,it)|0)+Math.imul(y,rt)|0,s=s+Math.imul(y,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var Mt=(c+(i=i+Math.imul(u,ht)|0)|0)+((8191&(n=(n=n+Math.imul(u,ct)|0)+Math.imul(d,ht)|0))<<13)|0;c=((s=s+Math.imul(d,ct)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(L,j),n=(n=Math.imul(L,F))+Math.imul(q,j)|0,s=Math.imul(q,F),i=i+Math.imul(T,V)|0,n=(n=n+Math.imul(T,H)|0)+Math.imul(C,V)|0,s=s+Math.imul(C,H)|0,i=i+Math.imul(N,J)|0,n=(n=n+Math.imul(N,G)|0)+Math.imul(P,J)|0,s=s+Math.imul(P,G)|0,i=i+Math.imul(I,Y)|0,n=(n=n+Math.imul(I,Q)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,Q)|0,i=i+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(S,Z)|0,s=s+Math.imul(S,tt)|0,i=i+Math.imul(w,rt)|0,n=(n=n+Math.imul(w,it)|0)+Math.imul(_,rt)|0,s=s+Math.imul(_,it)|0,i=i+Math.imul(b,st)|0,n=(n=n+Math.imul(b,ot)|0)+Math.imul(y,st)|0,s=s+Math.imul(y,ot)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ct)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ct)|0;var St=(c+(i=i+Math.imul(u,ut)|0)|0)+((8191&(n=(n=n+Math.imul(u,dt)|0)+Math.imul(d,ut)|0))<<13)|0;c=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(B,j),n=(n=Math.imul(B,F))+Math.imul(D,j)|0,s=Math.imul(D,F),i=i+Math.imul(L,V)|0,n=(n=n+Math.imul(L,H)|0)+Math.imul(q,V)|0,s=s+Math.imul(q,H)|0,i=i+Math.imul(T,J)|0,n=(n=n+Math.imul(T,G)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,G)|0,i=i+Math.imul(N,Y)|0,n=(n=n+Math.imul(N,Q)|0)+Math.imul(P,Y)|0,s=s+Math.imul(P,Q)|0,i=i+Math.imul(I,Z)|0,n=(n=n+Math.imul(I,tt)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,tt)|0,i=i+Math.imul(M,rt)|0,n=(n=n+Math.imul(M,it)|0)+Math.imul(S,rt)|0,s=s+Math.imul(S,it)|0,i=i+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,i=i+Math.imul(b,ht)|0,n=(n=n+Math.imul(b,ct)|0)+Math.imul(y,ht)|0,s=s+Math.imul(y,ct)|0,i=i+Math.imul(p,ut)|0,n=(n=n+Math.imul(p,dt)|0)+Math.imul(g,ut)|0,s=s+Math.imul(g,dt)|0;var Et=(c+(i=i+Math.imul(u,pt)|0)|0)+((8191&(n=(n=n+Math.imul(u,gt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(B,V),n=(n=Math.imul(B,H))+Math.imul(D,V)|0,s=Math.imul(D,H),i=i+Math.imul(L,J)|0,n=(n=n+Math.imul(L,G)|0)+Math.imul(q,J)|0,s=s+Math.imul(q,G)|0,i=i+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,Q)|0)+Math.imul(C,Y)|0,s=s+Math.imul(C,Q)|0,i=i+Math.imul(N,Z)|0,n=(n=n+Math.imul(N,tt)|0)+Math.imul(P,Z)|0,s=s+Math.imul(P,tt)|0,i=i+Math.imul(I,rt)|0,n=(n=n+Math.imul(I,it)|0)+Math.imul(x,rt)|0,s=s+Math.imul(x,it)|0,i=i+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(S,st)|0,s=s+Math.imul(S,ot)|0,i=i+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ct)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ct)|0,i=i+Math.imul(b,ut)|0,n=(n=n+Math.imul(b,dt)|0)+Math.imul(y,ut)|0,s=s+Math.imul(y,dt)|0;var It=(c+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;c=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(B,J),n=(n=Math.imul(B,G))+Math.imul(D,J)|0,s=Math.imul(D,G),i=i+Math.imul(L,Y)|0,n=(n=n+Math.imul(L,Q)|0)+Math.imul(q,Y)|0,s=s+Math.imul(q,Q)|0,i=i+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(C,Z)|0,s=s+Math.imul(C,tt)|0,i=i+Math.imul(N,rt)|0,n=(n=n+Math.imul(N,it)|0)+Math.imul(P,rt)|0,s=s+Math.imul(P,it)|0,i=i+Math.imul(I,st)|0,n=(n=n+Math.imul(I,ot)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,ot)|0,i=i+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ct)|0)+Math.imul(S,ht)|0,s=s+Math.imul(S,ct)|0,i=i+Math.imul(w,ut)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(_,ut)|0,s=s+Math.imul(_,dt)|0;var xt=(c+(i=i+Math.imul(b,pt)|0)|0)+((8191&(n=(n=n+Math.imul(b,gt)|0)+Math.imul(y,pt)|0))<<13)|0;c=((s=s+Math.imul(y,gt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(B,Y),n=(n=Math.imul(B,Q))+Math.imul(D,Y)|0,s=Math.imul(D,Q),i=i+Math.imul(L,Z)|0,n=(n=n+Math.imul(L,tt)|0)+Math.imul(q,Z)|0,s=s+Math.imul(q,tt)|0,i=i+Math.imul(T,rt)|0,n=(n=n+Math.imul(T,it)|0)+Math.imul(C,rt)|0,s=s+Math.imul(C,it)|0,i=i+Math.imul(N,st)|0,n=(n=n+Math.imul(N,ot)|0)+Math.imul(P,st)|0,s=s+Math.imul(P,ot)|0,i=i+Math.imul(I,ht)|0,n=(n=n+Math.imul(I,ct)|0)+Math.imul(x,ht)|0,s=s+Math.imul(x,ct)|0,i=i+Math.imul(M,ut)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(S,ut)|0,s=s+Math.imul(S,dt)|0;var Ot=(c+(i=i+Math.imul(w,pt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(_,pt)|0))<<13)|0;c=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,i=Math.imul(B,Z),n=(n=Math.imul(B,tt))+Math.imul(D,Z)|0,s=Math.imul(D,tt),i=i+Math.imul(L,rt)|0,n=(n=n+Math.imul(L,it)|0)+Math.imul(q,rt)|0,s=s+Math.imul(q,it)|0,i=i+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(C,st)|0,s=s+Math.imul(C,ot)|0,i=i+Math.imul(N,ht)|0,n=(n=n+Math.imul(N,ct)|0)+Math.imul(P,ht)|0,s=s+Math.imul(P,ct)|0,i=i+Math.imul(I,ut)|0,n=(n=n+Math.imul(I,dt)|0)+Math.imul(x,ut)|0,s=s+Math.imul(x,dt)|0;var Nt=(c+(i=i+Math.imul(M,pt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(S,pt)|0))<<13)|0;c=((s=s+Math.imul(S,gt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,i=Math.imul(B,rt),n=(n=Math.imul(B,it))+Math.imul(D,rt)|0,s=Math.imul(D,it),i=i+Math.imul(L,st)|0,n=(n=n+Math.imul(L,ot)|0)+Math.imul(q,st)|0,s=s+Math.imul(q,ot)|0,i=i+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ct)|0)+Math.imul(C,ht)|0,s=s+Math.imul(C,ct)|0,i=i+Math.imul(N,ut)|0,n=(n=n+Math.imul(N,dt)|0)+Math.imul(P,ut)|0,s=s+Math.imul(P,dt)|0;var Pt=(c+(i=i+Math.imul(I,pt)|0)|0)+((8191&(n=(n=n+Math.imul(I,gt)|0)+Math.imul(x,pt)|0))<<13)|0;c=((s=s+Math.imul(x,gt)|0)+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(B,st),n=(n=Math.imul(B,ot))+Math.imul(D,st)|0,s=Math.imul(D,ot),i=i+Math.imul(L,ht)|0,n=(n=n+Math.imul(L,ct)|0)+Math.imul(q,ht)|0,s=s+Math.imul(q,ct)|0,i=i+Math.imul(T,ut)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(C,ut)|0,s=s+Math.imul(C,dt)|0;var Rt=(c+(i=i+Math.imul(N,pt)|0)|0)+((8191&(n=(n=n+Math.imul(N,gt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((s=s+Math.imul(P,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(B,ht),n=(n=Math.imul(B,ct))+Math.imul(D,ht)|0,s=Math.imul(D,ct),i=i+Math.imul(L,ut)|0,n=(n=n+Math.imul(L,dt)|0)+Math.imul(q,ut)|0,s=s+Math.imul(q,dt)|0;var Tt=(c+(i=i+Math.imul(T,pt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(C,pt)|0))<<13)|0;c=((s=s+Math.imul(C,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,i=Math.imul(B,ut),n=(n=Math.imul(B,dt))+Math.imul(D,ut)|0,s=Math.imul(D,dt);var Ct=(c+(i=i+Math.imul(L,pt)|0)|0)+((8191&(n=(n=n+Math.imul(L,gt)|0)+Math.imul(q,pt)|0))<<13)|0;c=((s=s+Math.imul(q,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863;var kt=(c+(i=Math.imul(B,pt))|0)+((8191&(n=(n=Math.imul(B,gt))+Math.imul(D,pt)|0))<<13)|0;return c=((s=Math.imul(D,gt))+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h[0]=mt,h[1]=bt,h[2]=yt,h[3]=vt,h[4]=wt,h[5]=_t,h[6]=At,h[7]=Mt,h[8]=St,h[9]=Et,h[10]=It,h[11]=xt,h[12]=Ot,h[13]=Nt,h[14]=Pt,h[15]=Rt,h[16]=Tt,h[17]=Ct,h[18]=kt,0!==c&&(h[19]=c,r.length++),r};function b(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,s=0;s>>26)|0)>>>26,o&=67108863}r.words[s]=a,i=o,o=n}return 0!==i?r.words[s]=i:r.length--,r._strip()}function y(t,e,r){return b(t,e,r)}function v(t,e){this.x=t,this.y=e}Math.imul||(m=g),s.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?m(this,t,e):r<63?g(this,t,e):r<1024?b(this,t,e):y(this,t,e)},v.prototype.makeRBT=function(t){for(var e=new Array(t),r=s.prototype._countBits(t)-1,i=0;i>=1;return i},v.prototype.permute=function(t,e,r,i,n,s){for(var o=0;o>>=1)n++;return 1<>>=13,r[2*o+1]=8191&s,s>>>=13;for(o=2*e;o>=26,r+=s/67108864|0,r+=o>>>26,this.words[n]=67108863&o}return 0!==r&&(this.words[n]=r,this.length++),e?this.ineg():this},s.prototype.muln=function(t){return this.clone().imuln(t)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r>>n&1}return e}(t);if(0===e.length)return new s(1);for(var r=this,i=0;i=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<o)for(this.length-=o,c=0;c=0&&(0!==f||c>=n);c--){var u=0|this.words[c];this.words[c]=f<<26-s|u>>>s,f=u&a}return h&&0!==f&&(h.words[h.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},s.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},s.prototype.shln=function(t){return this.clone().ishln(t)},s.prototype.ushln=function(t){return this.clone().iushln(t)},s.prototype.shrn=function(t){return this.clone().ishrn(t)},s.prototype.ushrn=function(t){return this.clone().iushrn(t)},s.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,n=1<=0);var e=t%26,r=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var n=67108863^67108863>>>e<=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},s.prototype.isubn=function(t){if(i("number"==typeof t),i(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e>26)-(h/67108864|0),this.words[n+r]=67108863&s}for(;n>26,this.words[n+r]=67108863&s;if(0===a)return this._strip();for(i(-1===a),a=0,n=0;n>26,this.words[n]=67108863&s;return this.negative=1,this._strip()},s.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),n=t,o=0|n.words[n.length-1];0!=(r=26-this._countBits(o))&&(n=n.ushln(r),i.iushln(r),o=0|n.words[n.length-1]);var a,h=i.length-n.length;if("mod"!==e){(a=new s(null)).length=h+1,a.words=new Array(a.length);for(var c=0;c=0;u--){var d=67108864*(0|i.words[n.length+u])+(0|i.words[n.length+u-1]);for(d=Math.min(d/o|0,67108863),i._ishlnsubmul(n,d,u);0!==i.negative;)d--,i.negative=0,i._ishlnsubmul(n,1,u),i.isZero()||(i.negative^=1);a&&(a.words[u]=d)}return a&&a._strip(),i._strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:a||null,mod:i}},s.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(n=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:n,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(n=a.div.neg()),{div:n,mod:a.mod}):this.negative&t.negative?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new s(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new s(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new s(this.modrn(t.words[0]))}:this._wordDiv(t,e);var n,o,a},s.prototype.div=function(t){return this.divmod(t,"div",!1).div},s.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},s.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},s.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),s=r.cmp(i);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},s.prototype.modrn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(r*n+(0|this.words[s]))%t;return e?-n:n},s.prototype.modn=function(t){return this.modrn(t)},s.prototype.idivn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=0,n=this.length-1;n>=0;n--){var s=(0|this.words[n])+67108864*r;this.words[n]=s/t|0,r=s%t}return this._strip(),e?this.ineg():this},s.prototype.divn=function(t){return this.clone().idivn(t)},s.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n=new s(1),o=new s(0),a=new s(0),h=new s(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var f=r.clone(),u=e.clone();!e.isZero();){for(var d=0,l=1;!(e.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(n.isOdd()||o.isOdd())&&(n.iadd(f),o.isub(u)),n.iushrn(1),o.iushrn(1);for(var p=0,g=1;!(r.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(f),h.isub(u)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),n.isub(a),o.isub(h)):(r.isub(e),a.isub(n),h.isub(o))}return{a,b:h,gcd:r.iushln(c)}},s.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n,o=new s(1),a=new s(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,f=1;!(e.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(e.iushrn(c);c-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var u=0,d=1;!(r.words[0]&d)&&u<26;++u,d<<=1);if(u>0)for(r.iushrn(u);u-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(n=0===e.cmpn(1)?o:a).cmpn(0)<0&&n.iadd(t),n},s.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var s=e;e=r,r=s}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},s.prototype.invm=function(t){return this.egcd(t).a.umod(t)},s.prototype.isEven=function(){return!(1&this.words[0])},s.prototype.isOdd=function(){return!(1&~this.words[0])},s.prototype.andln=function(t){return this.words[0]&t},s.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<>>26,a&=67108863,this.words[o]=a}return 0!==s&&(this.words[o]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:nt.length)return 1;if(this.length=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){in&&(e=1);break}}return e},s.prototype.gtn=function(t){return 1===this.cmpn(t)},s.prototype.gt=function(t){return 1===this.cmp(t)},s.prototype.gten=function(t){return this.cmpn(t)>=0},s.prototype.gte=function(t){return this.cmp(t)>=0},s.prototype.ltn=function(t){return-1===this.cmpn(t)},s.prototype.lt=function(t){return-1===this.cmp(t)},s.prototype.lten=function(t){return this.cmpn(t)<=0},s.prototype.lte=function(t){return this.cmp(t)<=0},s.prototype.eqn=function(t){return 0===this.cmpn(t)},s.prototype.eq=function(t){return 0===this.cmp(t)},s.red=function(t){return new I(t)},s.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},s.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(t){return this.red=t,this},s.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},s.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},s.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},s.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},s.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},s.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},s.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},s.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},s.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function _(t,e){this.name=t,this.p=new s(e,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function A(){_.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){_.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function S(){_.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function E(){_.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function I(t){if("string"==typeof t){var e=s._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function x(t){I.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}_.prototype._tmp=function(){var t=new s(null);return t.words=new Array(Math.ceil(this.n/13)),t},_.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},_.prototype.split=function(t,e){t.iushrn(this.n,0,e)},_.prototype.imulK=function(t){return t.imul(this.k)},n(A,_),A.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n>>22,s=o}s>>>=22,t.words[n-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},A.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},s._prime=function(t){if(w[t])return w[t];var e;if("k256"===t)e=new A;else if("p224"===t)e=new M;else if("p192"===t)e=new S;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new E}return w[t]=e,e},I.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},I.prototype._verify2=function(t,e){i(!(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},I.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(f(t,t.umod(this.m)._forceRed(this)),t)},I.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},I.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},I.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},I.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},I.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},I.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},I.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},I.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},I.prototype.isqr=function(t){return this.imul(t,t.clone())},I.prototype.sqr=function(t){return this.mul(t,t)},I.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new s(1)).iushrn(2);return this.pow(t,r)}for(var n=this.m.subn(1),o=0;!n.isZero()&&0===n.andln(1);)o++,n.iushrn(1);i(!n.isZero());var a=new s(1).toRed(this),h=a.redNeg(),c=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new s(2*f*f).toRed(this);0!==this.pow(f,c).cmp(h);)f.redIAdd(h);for(var u=this.pow(f,n),d=this.pow(t,n.addn(1).iushrn(1)),l=this.pow(t,n),p=o;0!==l.cmp(a);){for(var g=l,m=0;0!==g.cmp(a);m++)g=g.redSqr();i(m=0;i--){for(var c=e.words[i],f=h-1;f>=0;f--){var u=c>>f&1;n!==r[0]&&(n=this.sqr(n)),0!==u||0!==o?(o<<=1,o|=u,(4==++a||0===i&&0===f)&&(n=this.mul(n,r[o]),a=0,o=0)):a=0}h=26}return n},I.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},I.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},s.mont=function(t){return new x(t)},n(x,I),x.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},x.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},x.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},x.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new s(0)._forceRed(this);var r=t.mul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),o=n;return n.cmp(this.m)>=0?o=n.isub(this.m):n.cmpn(0)<0&&(o=n.iadd(this.m)),o._forceRed(this)},x.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t=r.nmd(t),this)},5037:(t,e,r)=>{var i;function n(t){this.rand=t}if(t.exports=function(t){return i||(i=new n(null)),i.generate(t)},t.exports.Rand=n,n.prototype.generate=function(t){return this._rand(t)},n.prototype._rand=function(t){if(this.rand.getBytes)return this.rand.getBytes(t);for(var e=new Uint8Array(t),r=0;r{var e="%[a-f0-9]{2}",r=new RegExp("("+e+")|([^%]+?)","gi"),i=new RegExp("("+e+")+","gi");function n(t,e){try{return[decodeURIComponent(t.join(""))]}catch(t){}if(1===t.length)return t;e=e||1;var r=t.slice(0,e),i=t.slice(e);return Array.prototype.concat.call([],n(r),n(i))}function s(t){try{return decodeURIComponent(t)}catch(s){for(var e=t.match(r)||[],i=1;i{var e,r="object"==typeof Reflect?Reflect:null,i=r&&"function"==typeof r.apply?r.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var n=Number.isNaN||function(t){return t!=t};function s(){s.init.call(this)}t.exports=s,t.exports.once=function(t,e){return new Promise((function(r,i){function n(r){t.removeListener(e,s),i(r)}function s(){"function"==typeof t.removeListener&&t.removeListener("error",n),r([].slice.call(arguments))}g(t,e,s,{once:!0}),"error"!==e&&function(t,e,r){"function"==typeof t.on&&g(t,"error",e,{once:!0})}(t,n)}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function a(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function h(t){return void 0===t._maxListeners?s.defaultMaxListeners:t._maxListeners}function c(t,e,r,i){var n,s,o,c;if(a(r),void 0===(s=t._events)?(s=t._events=Object.create(null),t._eventsCount=0):(void 0!==s.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),o=s[e]),void 0===o)o=s[e]=r,++t._eventsCount;else if("function"==typeof o?o=s[e]=i?[r,o]:[o,r]:i?o.unshift(r):o.push(r),(n=h(t))>0&&o.length>n&&!o.warned){o.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=t,f.type=e,f.count=o.length,c=f,console&&console.warn&&console.warn(c)}return t}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function u(t,e,r){var i={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},n=f.bind(i);return n.listener=r,i.wrapFn=n,n}function d(t,e,r){var i=t._events;if(void 0===i)return[];var n=i[e];return void 0===n?[]:"function"==typeof n?r?[n.listener||n]:[n]:r?function(t){for(var e=new Array(t.length),r=0;r0&&(o=e[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[t];if(void 0===h)return!1;if("function"==typeof h)i(h,this,e);else{var c=h.length,f=p(h,c);for(r=0;r=0;s--)if(r[s]===e||r[s].listener===e){o=r[s].listener,n=s;break}if(n<0)return this;0===n?r.shift():function(t,e){for(;e+1=0;i--)this.removeListener(t,e[i]);return this},s.prototype.listeners=function(t){return d(this,t,!0)},s.prototype.rawListeners=function(t){return d(this,t,!1)},s.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):l.call(t,e)},s.prototype.listenerCount=l,s.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]}},3055:t=>{t.exports=function(t,e){for(var r={},i=Object.keys(t),n=Array.isArray(e),s=0;s{var i=e;i.utils=r(7426),i.common=r(6166),i.sha=r(6229),i.ripemd=r(6784),i.hmac=r(8948),i.sha1=i.sha.sha1,i.sha256=i.sha.sha256,i.sha224=i.sha.sha224,i.sha384=i.sha.sha384,i.sha512=i.sha.sha512,i.ripemd160=i.ripemd.ripemd160},6166:(t,e,r)=>{var i=r(7426),n=r(3349);function s(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}e.BlockHash=s,s.prototype.update=function(t,e){if(t=i.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=i.join32(t,0,t.length-r,this.endian);for(var n=0;n>>24&255,i[n++]=t>>>16&255,i[n++]=t>>>8&255,i[n++]=255&t}else for(i[n++]=255&t,i[n++]=t>>>8&255,i[n++]=t>>>16&255,i[n++]=t>>>24&255,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,s=8;s{var i=r(7426),n=r(3349);function s(t,e,r){if(!(this instanceof s))return new s(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(i.toArray(e,r))}t.exports=s,s.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),n(t.length<=this.blockSize);for(var e=t.length;e{var i=r(7426),n=r(6166),s=i.rotl32,o=i.sum32,a=i.sum32_3,h=i.sum32_4,c=n.BlockHash;function f(){if(!(this instanceof f))return new f;c.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}function u(t,e,r,i){return t<=15?e^r^i:t<=31?e&r|~e&i:t<=47?(e|~r)^i:t<=63?e&i|r&~i:e^(r|~i)}function d(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function l(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}i.inherits(f,c),e.ripemd160=f,f.blockSize=512,f.outSize=160,f.hmacStrength=192,f.padLength=64,f.prototype._update=function(t,e){for(var r=this.h[0],i=this.h[1],n=this.h[2],c=this.h[3],f=this.h[4],y=r,v=i,w=n,_=c,A=f,M=0;M<80;M++){var S=o(s(h(r,u(M,i,n,c),t[p[M]+e],d(M)),m[M]),f);r=f,f=c,c=s(n,10),n=i,i=S,S=o(s(h(y,u(79-M,v,w,_),t[g[M]+e],l(M)),b[M]),A),y=A,A=_,_=s(w,10),w=v,v=S}S=a(this.h[1],n,_),this.h[1]=a(this.h[2],c,A),this.h[2]=a(this.h[3],f,y),this.h[3]=a(this.h[4],r,v),this.h[4]=a(this.h[0],i,w),this.h[0]=S},f.prototype._digest=function(t){return"hex"===t?i.toHex32(this.h,"little"):i.split32(this.h,"little")};var p=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],g=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],m=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],b=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]},6229:(t,e,r)=>{e.sha1=r(3917),e.sha224=r(7714),e.sha256=r(2287),e.sha384=r(1911),e.sha512=r(7766)},3917:(t,e,r)=>{var i=r(7426),n=r(6166),s=r(6225),o=i.rotl32,a=i.sum32,h=i.sum32_5,c=s.ft_1,f=n.BlockHash,u=[1518500249,1859775393,2400959708,3395469782];function d(){if(!(this instanceof d))return new d;f.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}i.inherits(d,f),t.exports=d,d.blockSize=512,d.outSize=160,d.hmacStrength=80,d.padLength=64,d.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;i{var i=r(7426),n=r(2287);function s(){if(!(this instanceof s))return new s;n.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}i.inherits(s,n),t.exports=s,s.blockSize=512,s.outSize=224,s.hmacStrength=192,s.padLength=64,s.prototype._digest=function(t){return"hex"===t?i.toHex32(this.h.slice(0,7),"big"):i.split32(this.h.slice(0,7),"big")}},2287:(t,e,r)=>{var i=r(7426),n=r(6166),s=r(6225),o=r(3349),a=i.sum32,h=i.sum32_4,c=i.sum32_5,f=s.ch32,u=s.maj32,d=s.s0_256,l=s.s1_256,p=s.g0_256,g=s.g1_256,m=n.BlockHash,b=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function y(){if(!(this instanceof y))return new y;m.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=b,this.W=new Array(64)}i.inherits(y,m),t.exports=y,y.blockSize=512,y.outSize=256,y.hmacStrength=192,y.padLength=64,y.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;i{var i=r(7426),n=r(7766);function s(){if(!(this instanceof s))return new s;n.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}i.inherits(s,n),t.exports=s,s.blockSize=1024,s.outSize=384,s.hmacStrength=192,s.padLength=128,s.prototype._digest=function(t){return"hex"===t?i.toHex32(this.h.slice(0,12),"big"):i.split32(this.h.slice(0,12),"big")}},7766:(t,e,r)=>{var i=r(7426),n=r(6166),s=r(3349),o=i.rotr64_hi,a=i.rotr64_lo,h=i.shr64_hi,c=i.shr64_lo,f=i.sum64,u=i.sum64_hi,d=i.sum64_lo,l=i.sum64_4_hi,p=i.sum64_4_lo,g=i.sum64_5_hi,m=i.sum64_5_lo,b=n.BlockHash,y=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function v(){if(!(this instanceof v))return new v;b.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=y,this.W=new Array(160)}function w(t,e,r,i,n){var s=t&r^~t&n;return s<0&&(s+=4294967296),s}function _(t,e,r,i,n,s){var o=e&i^~e&s;return o<0&&(o+=4294967296),o}function A(t,e,r,i,n){var s=t&r^t&n^r&n;return s<0&&(s+=4294967296),s}function M(t,e,r,i,n,s){var o=e&i^e&s^i&s;return o<0&&(o+=4294967296),o}function S(t,e){var r=o(t,e,28)^o(e,t,2)^o(e,t,7);return r<0&&(r+=4294967296),r}function E(t,e){var r=a(t,e,28)^a(e,t,2)^a(e,t,7);return r<0&&(r+=4294967296),r}function I(t,e){var r=a(t,e,14)^a(t,e,18)^a(e,t,9);return r<0&&(r+=4294967296),r}function x(t,e){var r=o(t,e,1)^o(t,e,8)^h(t,e,7);return r<0&&(r+=4294967296),r}function O(t,e){var r=a(t,e,1)^a(t,e,8)^c(t,e,7);return r<0&&(r+=4294967296),r}function N(t,e){var r=a(t,e,19)^a(e,t,29)^c(t,e,6);return r<0&&(r+=4294967296),r}i.inherits(v,b),t.exports=v,v.blockSize=1024,v.outSize=512,v.hmacStrength=192,v.padLength=128,v.prototype._prepareBlock=function(t,e){for(var r=this.W,i=0;i<32;i++)r[i]=t[e+i];for(;i{var i=r(7426).rotr32;function n(t,e,r){return t&e^~t&r}function s(t,e,r){return t&e^t&r^e&r}function o(t,e,r){return t^e^r}e.ft_1=function(t,e,r,i){return 0===t?n(e,r,i):1===t||3===t?o(e,r,i):2===t?s(e,r,i):void 0},e.ch32=n,e.maj32=s,e.p32=o,e.s0_256=function(t){return i(t,2)^i(t,13)^i(t,22)},e.s1_256=function(t){return i(t,6)^i(t,11)^i(t,25)},e.g0_256=function(t){return i(t,7)^i(t,18)^t>>>3},e.g1_256=function(t){return i(t,17)^i(t,19)^t>>>10}},7426:(t,e,r)=>{var i=r(3349),n=r(6698);function s(t,e){return 55296==(64512&t.charCodeAt(e))&&!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1))}function o(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function a(t){return 1===t.length?"0"+t:t}function h(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}e.inherits=n,e.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),n=0;n>6|192,r[i++]=63&o|128):s(t,n)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++n)),r[i++]=o>>18|240,r[i++]=o>>12&63|128,r[i++]=o>>6&63|128,r[i++]=63&o|128):(r[i++]=o>>12|224,r[i++]=o>>6&63|128,r[i++]=63&o|128)}else for(n=0;n>>0}return o},e.split32=function(t,e){for(var r=new Array(4*t.length),i=0,n=0;i>>24,r[n+1]=s>>>16&255,r[n+2]=s>>>8&255,r[n+3]=255&s):(r[n+3]=s>>>24,r[n+2]=s>>>16&255,r[n+1]=s>>>8&255,r[n]=255&s)}return r},e.rotr32=function(t,e){return t>>>e|t<<32-e},e.rotl32=function(t,e){return t<>>32-e},e.sum32=function(t,e){return t+e>>>0},e.sum32_3=function(t,e,r){return t+e+r>>>0},e.sum32_4=function(t,e,r,i){return t+e+r+i>>>0},e.sum32_5=function(t,e,r,i,n){return t+e+r+i+n>>>0},e.sum64=function(t,e,r,i){var n=t[e],s=i+t[e+1]>>>0,o=(s>>0,t[e+1]=s},e.sum64_hi=function(t,e,r,i){return(e+i>>>0>>0},e.sum64_lo=function(t,e,r,i){return e+i>>>0},e.sum64_4_hi=function(t,e,r,i,n,s,o,a){var h=0,c=e;return h+=(c=c+i>>>0)>>0)>>0)>>0},e.sum64_4_lo=function(t,e,r,i,n,s,o,a){return e+i+s+a>>>0},e.sum64_5_hi=function(t,e,r,i,n,s,o,a,h,c){var f=0,u=e;return f+=(u=u+i>>>0)>>0)>>0)>>0)>>0},e.sum64_5_lo=function(t,e,r,i,n,s,o,a,h,c){return e+i+s+a+c>>>0},e.rotr64_hi=function(t,e,r){return(e<<32-r|t>>>r)>>>0},e.rotr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},e.shr64_hi=function(t,e,r){return t>>>r},e.shr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0}},2723:(t,e,r)=>{var i=r(7952),n=r(4367),s=r(3349);function o(t){if(!(this instanceof o))return new o(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=n.toArray(t.entropy,t.entropyEnc||"hex"),r=n.toArray(t.nonce,t.nonceEnc||"hex"),i=n.toArray(t.pers,t.persEnc||"hex");s(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}t.exports=o,o.prototype._init=function(t,e,r){var i=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},o.prototype.generate=function(t,e,r,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(i=r,r=e,e=null),r&&(r=n.toArray(r,i||"hex"),this._update(r));for(var s=[];s.length{"function"==typeof Object.create?t.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},916:(t,e,r)=>{t.exports=self.fetch||(self.fetch=r(6782).default||r(6782))},1176:(t,e,r)=>{var i;!function(){var n="input is invalid type",s="object"==typeof window,o=s?window:{};o.JS_SHA3_NO_WINDOW&&(s=!1);var a=!s&&"object"==typeof self;!o.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?o=r.g:a&&(o=self);var h=!o.JS_SHA3_NO_COMMON_JS&&t.exports,c=r.amdO,f=!o.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,u="0123456789abcdef".split(""),d=[4,1024,262144,67108864],l=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],g=[224,256,384,512],m=[128,256],b=["hex","buffer","arrayBuffer","array","digest"],y={128:168,256:136};!o.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!f||!o.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var v=function(t,e,r){return function(i){return new k(t,e,t).update(i)[r]()}},w=function(t,e,r){return function(i,n){return new k(t,e,n).update(i)[r]()}},_=function(t,e,r){return function(e,i,n,s){return I["cshake"+t].update(e,i,n,s)[r]()}},A=function(t,e,r){return function(e,i,n,s){return I["kmac"+t].update(e,i,n,s)[r]()}},M=function(t,e,r,i){for(var n=0;n>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var i=0;i<50;++i)this.s[i]=0}function L(t,e,r){k.call(this,t,e,r)}k.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(n);if(null===t)throw new Error(n);if(f&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||f&&ArrayBuffer.isView(t)))throw new Error(n);e=!0}for(var i,s,o=this.blocks,a=this.byteCount,h=t.length,c=this.blockCount,u=0,d=this.s;u>2]|=t[u]<>2]|=s<>2]|=(192|s>>6)<>2]|=(128|63&s)<=57344?(o[i>>2]|=(224|s>>12)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<>2]|=(240|s>>18)<>2]|=(128|s>>12&63)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<=a){for(this.start=i-a,this.block=o[c],i=0;i>=8);r>0;)n.unshift(r),r=255&(t>>=8),++i;return e?n.push(i):n.unshift(i),this.update(n),n.length},k.prototype.encodeString=function(t){var e,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(n);if(null===t)throw new Error(n);if(f&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||f&&ArrayBuffer.isView(t)))throw new Error(n);e=!0}var i=0,s=t.length;if(e)i=s;else for(var o=0;o=57344?i+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),i+=4)}return i+=this.encode(8*i),this.update(t),i},k.prototype.bytepad=function(t,e){for(var r=this.encode(e),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>4&15]+u[15&t]+u[t>>12&15]+u[t>>8&15]+u[t>>20&15]+u[t>>16&15]+u[t>>28&15]+u[t>>24&15];o%e==0&&(q(r),s=0)}return n&&(t=r[s],a+=u[t>>4&15]+u[15&t],n>1&&(a+=u[t>>12&15]+u[t>>8&15]),n>2&&(a+=u[t>>20&15]+u[t>>16&15])),a},k.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,i=this.outputBlocks,n=this.extraBytes,s=0,o=0,a=this.outputBits>>3;t=n?new ArrayBuffer(i+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);o>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%r==0&&q(i)}return s&&(t=a<<2,e=i[o],h[t]=255&e,s>1&&(h[t+1]=e>>8&255),s>2&&(h[t+2]=e>>16&255)),h},L.prototype=new k,L.prototype.finalize=function(){return this.encode(this.outputBits,!0),k.prototype.finalize.call(this)};var q=function(t){var e,r,i,n,s,o,a,h,c,f,u,d,l,g,m,b,y,v,w,_,A,M,S,E,I,x,O,N,P,R,T,C,k,L,q,U,B,D,z,j,F,K,V,H,W,J,G,$,Y,Q,X,Z,tt,et,rt,it,nt,st,ot,at,ht,ct,ft;for(i=0;i<48;i+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],o=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],h=t[4]^t[14]^t[24]^t[34]^t[44],c=t[5]^t[15]^t[25]^t[35]^t[45],f=t[6]^t[16]^t[26]^t[36]^t[46],u=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|o>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=n^(h<<1|c>>>31),r=s^(c<<1|h>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=o^(f<<1|u>>>31),r=a^(u<<1|f>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=h^(d<<1|l>>>31),r=c^(l<<1|d>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=f^(n<<1|s>>>31),r=u^(s<<1|n>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,g=t[0],m=t[1],J=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,N=t[20]<<3|t[21]>>>29,P=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,K=t[40]<<18|t[41]>>>14,V=t[41]<<18|t[40]>>>14,L=t[2]<<1|t[3]>>>31,q=t[3]<<1|t[2]>>>31,b=t[13]<<12|t[12]>>>20,y=t[12]<<12|t[13]>>>20,$=t[22]<<10|t[23]>>>22,Y=t[23]<<10|t[22]>>>22,R=t[33]<<13|t[32]>>>19,T=t[32]<<13|t[33]>>>19,ct=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,U=t[14]<<6|t[15]>>>26,B=t[15]<<6|t[14]>>>26,v=t[25]<<11|t[24]>>>21,w=t[24]<<11|t[25]>>>21,Q=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,C=t[45]<<29|t[44]>>>3,k=t[44]<<29|t[45]>>>3,E=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,nt=t[16]<<23|t[17]>>>9,D=t[26]<<25|t[27]>>>7,z=t[27]<<25|t[26]>>>7,_=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Z=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,H=t[8]<<27|t[9]>>>5,W=t[9]<<27|t[8]>>>5,x=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,st=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,j=t[38]<<8|t[39]>>>24,F=t[39]<<8|t[38]>>>24,M=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=g^~b&v,t[1]=m^~y&w,t[10]=E^~x&N,t[11]=I^~O&P,t[20]=L^~U&D,t[21]=q^~B&z,t[30]=H^~J&$,t[31]=W^~G&Y,t[40]=et^~it&st,t[41]=rt^~nt&ot,t[2]=b^~v&_,t[3]=y^~w&A,t[12]=x^~N&R,t[13]=O^~P&T,t[22]=U^~D&j,t[23]=B^~z&F,t[32]=J^~$&Q,t[33]=G^~Y&X,t[42]=it^~st&at,t[43]=nt^~ot&ht,t[4]=v^~_&M,t[5]=w^~A&S,t[14]=N^~R&C,t[15]=P^~T&k,t[24]=D^~j&K,t[25]=z^~F&V,t[34]=$^~Q&Z,t[35]=Y^~X&tt,t[44]=st^~at&ct,t[45]=ot^~ht&ft,t[6]=_^~M&g,t[7]=A^~S&m,t[16]=R^~C&E,t[17]=T^~k&I,t[26]=j^~K&L,t[27]=F^~V&q,t[36]=Q^~Z&H,t[37]=X^~tt&W,t[46]=at^~ct&et,t[47]=ht^~ft&rt,t[8]=M^~g&b,t[9]=S^~m&y,t[18]=C^~E&x,t[19]=k^~I&O,t[28]=K^~L&U,t[29]=V^~q&B,t[38]=Z^~H&J,t[39]=tt^~W&G,t[48]=ct^~et&it,t[49]=ft^~rt&nt,t[0]^=p[i],t[1]^=p[i+1]};if(h)t.exports=I;else{for(O=0;O{t=r.nmd(t);var i="__lodash_hash_undefined__",n=1,s=2,o=9007199254740991,a="[object Arguments]",h="[object Array]",c="[object AsyncFunction]",f="[object Boolean]",u="[object Date]",d="[object Error]",l="[object Function]",p="[object GeneratorFunction]",g="[object Map]",m="[object Number]",b="[object Null]",y="[object Object]",v="[object Promise]",w="[object Proxy]",_="[object RegExp]",A="[object Set]",M="[object String]",S="[object Undefined]",E="[object WeakMap]",I="[object ArrayBuffer]",x="[object DataView]",O=/^\[object .+?Constructor\]$/,N=/^(?:0|[1-9]\d*)$/,P={};P["[object Float32Array]"]=P["[object Float64Array]"]=P["[object Int8Array]"]=P["[object Int16Array]"]=P["[object Int32Array]"]=P["[object Uint8Array]"]=P["[object Uint8ClampedArray]"]=P["[object Uint16Array]"]=P["[object Uint32Array]"]=!0,P[a]=P[h]=P[I]=P[f]=P[x]=P[u]=P[d]=P[l]=P[g]=P[m]=P[y]=P[_]=P[A]=P[M]=P[E]=!1;var R="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g,T="object"==typeof self&&self&&self.Object===Object&&self,C=R||T||Function("return this")(),k=e&&!e.nodeType&&e,L=k&&t&&!t.nodeType&&t,q=L&&L.exports===k,U=q&&R.process,B=function(){try{return U&&U.binding&&U.binding("util")}catch(t){}}(),D=B&&B.isTypedArray;function z(t,e){for(var r=-1,i=null==t?0:t.length;++rc))return!1;var u=a.get(t);if(u&&a.get(e))return u==e;var d=-1,l=!0,p=r&s?new xt:void 0;for(a.set(t,e),a.set(e,t);++d-1},Et.prototype.set=function(t,e){var r=this.__data__,i=Nt(r,t);return i<0?(++this.size,r.push([t,e])):r[i][1]=e,this},It.prototype.clear=function(){this.size=0,this.__data__={hash:new St,map:new(dt||Et),string:new St}},It.prototype.delete=function(t){var e=Lt(this,t).delete(t);return this.size-=e?1:0,e},It.prototype.get=function(t){return Lt(this,t).get(t)},It.prototype.has=function(t){return Lt(this,t).has(t)},It.prototype.set=function(t,e){var r=Lt(this,t),i=r.size;return r.set(t,e),this.size+=r.size==i?0:1,this},xt.prototype.add=xt.prototype.push=function(t){return this.__data__.set(t,i),this},xt.prototype.has=function(t){return this.__data__.has(t)},Ot.prototype.clear=function(){this.__data__=new Et,this.size=0},Ot.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Ot.prototype.get=function(t){return this.__data__.get(t)},Ot.prototype.has=function(t){return this.__data__.has(t)},Ot.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Et){var i=r.__data__;if(!dt||i.length<199)return i.push([t,e]),this.size=++r.size,this;r=this.__data__=new It(i)}return r.set(t,e),this.size=r.size,this};var Ut=ht?function(t){return null==t?[]:(t=Object(t),function(e,r){for(var i=-1,n=null==e?0:e.length,s=0,o=[];++i-1&&t%1==0&&t-1&&t%1==0&&t<=o}function Jt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Gt(t){return null!=t&&"object"==typeof t}var $t=D?function(t){return function(e){return t(e)}}(D):function(t){return Gt(t)&&Wt(t.length)&&!!P[Pt(t)]};function Yt(t){return null!=(e=t)&&Wt(e.length)&&!Ht(e)?function(t,e){var r=Kt(t),i=!r&&Ft(t),n=!r&&!i&&Vt(t),s=!r&&!i&&!n&&$t(t),o=r||i||n||s,a=o?function(t,e){for(var r=-1,i=Array(t);++r{function e(t,e){if(!t)throw new Error(e||"Assertion failed")}t.exports=e,e.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)}},4367:(t,e)=>{var r=e;function i(t){return 1===t.length?"0"+t:t}function n(t){for(var e="",r=0;r>8,o=255&n;s?r.push(s,o):r.push(o)}return r},r.zero2=i,r.toHex=n,r.encode=function(t,e){return"hex"===e?n(t):t}},6663:(t,e,r)=>{const i=r(4280),n=r(454),s=r(528),o=r(3055),a=Symbol("encodeFragmentIdentifier");function h(t){if("string"!=typeof t||1!==t.length)throw new TypeError("arrayFormatSeparator must be single character string")}function c(t,e){return e.encode?e.strict?i(t):encodeURIComponent(t):t}function f(t,e){return e.decode?n(t):t}function u(t){return Array.isArray(t)?t.sort():"object"==typeof t?u(Object.keys(t)).sort(((t,e)=>Number(t)-Number(e))).map((e=>t[e])):t}function d(t){const e=t.indexOf("#");return-1!==e&&(t=t.slice(0,e)),t}function l(t){const e=(t=d(t)).indexOf("?");return-1===e?"":t.slice(e+1)}function p(t,e){return e.parseNumbers&&!Number.isNaN(Number(t))&&"string"==typeof t&&""!==t.trim()?t=Number(t):!e.parseBooleans||null===t||"true"!==t.toLowerCase()&&"false"!==t.toLowerCase()||(t="true"===t.toLowerCase()),t}function g(t,e){h((e=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},e)).arrayFormatSeparator);const r=function(t){let e;switch(t.arrayFormat){case"index":return(t,r,i)=>{e=/\[(\d*)\]$/.exec(t),t=t.replace(/\[\d*\]$/,""),e?(void 0===i[t]&&(i[t]={}),i[t][e[1]]=r):i[t]=r};case"bracket":return(t,r,i)=>{e=/(\[\])$/.exec(t),t=t.replace(/\[\]$/,""),e?void 0!==i[t]?i[t]=[].concat(i[t],r):i[t]=[r]:i[t]=r};case"colon-list-separator":return(t,r,i)=>{e=/(:list)$/.exec(t),t=t.replace(/:list$/,""),e?void 0!==i[t]?i[t]=[].concat(i[t],r):i[t]=[r]:i[t]=r};case"comma":case"separator":return(e,r,i)=>{const n="string"==typeof r&&r.includes(t.arrayFormatSeparator),s="string"==typeof r&&!n&&f(r,t).includes(t.arrayFormatSeparator);r=s?f(r,t):r;const o=n||s?r.split(t.arrayFormatSeparator).map((e=>f(e,t))):null===r?r:f(r,t);i[e]=o};case"bracket-separator":return(e,r,i)=>{const n=/(\[\])$/.test(e);if(e=e.replace(/\[\]$/,""),!n)return void(i[e]=r?f(r,t):r);const s=null===r?[]:r.split(t.arrayFormatSeparator).map((e=>f(e,t)));void 0!==i[e]?i[e]=[].concat(i[e],s):i[e]=s};default:return(t,e,r)=>{void 0!==r[t]?r[t]=[].concat(r[t],e):r[t]=e}}}(e),i=Object.create(null);if("string"!=typeof t)return i;if(!(t=t.trim().replace(/^[?#&]/,"")))return i;for(const n of t.split("&")){if(""===n)continue;let[t,o]=s(e.decode?n.replace(/\+/g," "):n,"=");o=void 0===o?null:["comma","separator","bracket-separator"].includes(e.arrayFormat)?o:f(o,e),r(f(t,e),o,i)}for(const t of Object.keys(i)){const r=i[t];if("object"==typeof r&&null!==r)for(const t of Object.keys(r))r[t]=p(r[t],e);else i[t]=p(r,e)}return!1===e.sort?i:(!0===e.sort?Object.keys(i).sort():Object.keys(i).sort(e.sort)).reduce(((t,e)=>{const r=i[e];return Boolean(r)&&"object"==typeof r&&!Array.isArray(r)?t[e]=u(r):t[e]=r,t}),Object.create(null))}e.extract=l,e.parse=g,e.stringify=(t,e)=>{if(!t)return"";h((e=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},e)).arrayFormatSeparator);const r=r=>e.skipNull&&null==t[r]||e.skipEmptyString&&""===t[r],i=function(t){switch(t.arrayFormat){case"index":return e=>(r,i)=>{const n=r.length;return void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,[c(e,t),"[",n,"]"].join("")]:[...r,[c(e,t),"[",c(n,t),"]=",c(i,t)].join("")]};case"bracket":return e=>(r,i)=>void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,[c(e,t),"[]"].join("")]:[...r,[c(e,t),"[]=",c(i,t)].join("")];case"colon-list-separator":return e=>(r,i)=>void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,[c(e,t),":list="].join("")]:[...r,[c(e,t),":list=",c(i,t)].join("")];case"comma":case"separator":case"bracket-separator":{const e="bracket-separator"===t.arrayFormat?"[]=":"=";return r=>(i,n)=>void 0===n||t.skipNull&&null===n||t.skipEmptyString&&""===n?i:(n=null===n?"":n,0===i.length?[[c(r,t),e,c(n,t)].join("")]:[[i,c(n,t)].join(t.arrayFormatSeparator)])}default:return e=>(r,i)=>void 0===i||t.skipNull&&null===i||t.skipEmptyString&&""===i?r:null===i?[...r,c(e,t)]:[...r,[c(e,t),"=",c(i,t)].join("")]}}(e),n={};for(const e of Object.keys(t))r(e)||(n[e]=t[e]);const s=Object.keys(n);return!1!==e.sort&&s.sort(e.sort),s.map((r=>{const n=t[r];return void 0===n?"":null===n?c(r,e):Array.isArray(n)?0===n.length&&"bracket-separator"===e.arrayFormat?c(r,e)+"[]":n.reduce(i(r),[]).join("&"):c(r,e)+"="+c(n,e)})).filter((t=>t.length>0)).join("&")},e.parseUrl=(t,e)=>{e=Object.assign({decode:!0},e);const[r,i]=s(t,"#");return Object.assign({url:r.split("?")[0]||"",query:g(l(t),e)},e&&e.parseFragmentIdentifier&&i?{fragmentIdentifier:f(i,e)}:{})},e.stringifyUrl=(t,r)=>{r=Object.assign({encode:!0,strict:!0,[a]:!0},r);const i=d(t.url).split("?")[0]||"",n=e.extract(t.url),s=e.parse(n,{sort:!1}),o=Object.assign(s,t.query);let h=e.stringify(o,r);h&&(h=`?${h}`);let f=function(t){let e="";const r=t.indexOf("#");return-1!==r&&(e=t.slice(r)),e}(t.url);return t.fragmentIdentifier&&(f=`#${r[a]?c(t.fragmentIdentifier,r):t.fragmentIdentifier}`),`${i}${h}${f}`},e.pick=(t,r,i)=>{i=Object.assign({parseFragmentIdentifier:!0,[a]:!1},i);const{url:n,query:s,fragmentIdentifier:h}=e.parseUrl(t,i);return e.stringifyUrl({url:n,query:o(s,r),fragmentIdentifier:h},i)},e.exclude=(t,r,i)=>{const n=Array.isArray(r)?t=>!r.includes(t):(t,e)=>!r(t,e);return e.pick(t,n,i)}},793:t=>{function e(t){try{return JSON.stringify(t)}catch(t){return'"[Circular]"'}}t.exports=function(t,r,i){var n=i&&i.stringify||e;if("object"==typeof t&&null!==t){var s=r.length+1;if(1===s)return t;var o=new Array(s);o[0]=n(t);for(var a=1;a-1?u:0,t.charCodeAt(l+1)){case 100:case 102:if(f>=h)break;if(null==r[f])break;u=h)break;if(null==r[f])break;u=h)break;if(void 0===r[f])break;u",u=l+2,l++;break}c+=n(r[f]),u=l+2,l++;break;case 115:if(f>=h)break;u{t.exports=(t,e)=>{if("string"!=typeof t||"string"!=typeof e)throw new TypeError("Expected the arguments to be of type `string`");if(""===e)return[t];const r=t.indexOf(e);return-1===r?[t]:[t.slice(0,r),t.slice(r+e.length)]}},4280:t=>{t.exports=t=>encodeURIComponent(t).replace(/[!'()*]/g,(t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`))},5215:(t,e,r)=>{r.r(e),r.d(e,{__assign:()=>s,__asyncDelegator:()=>w,__asyncGenerator:()=>v,__asyncValues:()=>_,__await:()=>y,__awaiter:()=>f,__classPrivateFieldGet:()=>E,__classPrivateFieldSet:()=>I,__createBinding:()=>d,__decorate:()=>a,__exportStar:()=>l,__extends:()=>n,__generator:()=>u,__importDefault:()=>S,__importStar:()=>M,__makeTemplateObject:()=>A,__metadata:()=>c,__param:()=>h,__read:()=>g,__rest:()=>o,__spread:()=>m,__spreadArrays:()=>b,__values:()=>p});var i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},i(t,e)};function n(t,e){function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var s=function(){return s=Object.assign||function(t){for(var e,r=1,i=arguments.length;r=0;a--)(n=t[a])&&(o=(s<3?n(o):s>3?n(e,r,o):n(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o}function h(t,e){return function(r,i){e(r,i,t)}}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function f(t,e,r,i){return new(r||(r=Promise))((function(n,s){function o(t){try{h(i.next(t))}catch(t){s(t)}}function a(t){try{h(i.throw(t))}catch(t){s(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,a)}h((i=i.apply(t,e||[])).next())}))}function u(t,e){var r,i,n,s,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,i&&(n=2&s[0]?i.return:s[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,s[1])).done)return n;switch(i=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((n=(n=o.trys).length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function g(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var i,n,s=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(i=s.next()).done;)o.push(i.value)}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}return o}function m(){for(var t=[],e=0;e1||a(t,e)}))})}function a(t,e){try{(r=n[t](e)).value instanceof y?Promise.resolve(r.value.v).then(h,c):f(s[0][2],r)}catch(t){f(s[0][3],t)}var r}function h(t){a("next",t)}function c(t){a("throw",t)}function f(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}function w(t){var e,r;return e={},i("next"),i("throw",(function(t){throw t})),i("return"),e[Symbol.iterator]=function(){return this},e;function i(i,n){e[i]=t[i]?function(e){return(r=!r)?{value:y(t[i](e)),done:"return"===i}:n?n(e):e}:n}}function _(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=p(t),e={},i("next"),i("throw"),i("return"),e[Symbol.asyncIterator]=function(){return this},e);function i(r){e[r]=t[r]&&function(e){return new Promise((function(i,n){!function(t,e,r,i){Promise.resolve(i).then((function(e){t({value:e,done:r})}),e)}(i,n,(e=t[r](e)).done,e.value)}))}}}function A(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function M(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function S(t){return t&&t.__esModule?t:{default:t}}function E(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function I(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}},6782:(t,e,r)=>{function i(t,e){return e=e||{},new Promise((function(r,i){var n=new XMLHttpRequest,s=[],o=[],a={},h=function(){return{ok:2==(n.status/100|0),statusText:n.statusText,status:n.status,url:n.responseURL,text:function(){return Promise.resolve(n.responseText)},json:function(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([n.response]))},clone:h,headers:{keys:function(){return s},entries:function(){return o},get:function(t){return a[t.toLowerCase()]},has:function(t){return t.toLowerCase()in a}}}};for(var c in n.open(e.method||"get",t,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(t,e,r){s.push(e=e.toLowerCase()),o.push([e,r]),a[e]=a[e]?a[e]+","+r:r})),r(h())},n.onerror=i,n.withCredentials="include"==e.credentials,e.headers)n.setRequestHeader(c,e.headers[c]);n.send(e.body||null)}))}r.r(e),r.d(e,{default:()=>i})},1591:t=>{t.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},9432:()=>{},9895:()=>{},7790:()=>{},3776:()=>{},4874:(t,e,r)=>{const i=r(793);t.exports=o;const n=function(){function t(t){return void 0!==t&&t}try{return"undefined"!=typeof globalThis||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch(e){return t(self)||t(window)||t(this)||{}}}().console||{},s={mapHttpRequest:d,mapHttpResponse:d,wrapRequestSerializer:l,wrapResponseSerializer:l,wrapErrorSerializer:l,req:d,res:d,err:function(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const r in t)void 0===e[r]&&(e[r]=t[r]);return e}};function o(t){(t=t||{}).browser=t.browser||{};const e=t.browser.transmit;if(e&&"function"!=typeof e.send)throw Error("pino: transmit option must have a send function");const r=t.browser.write||n;t.browser.write&&(t.browser.asObject=!0);const i=t.serializers||{},s=function(t,e){if(Array.isArray(t)){const e=t.filter((function(t){return"!stdSerializers.err"!==t}));return e}return!0===t&&Object.keys(e)}(t.browser.serialize,i);let d=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(d=!1),"function"==typeof r&&(r.error=r.fatal=r.warn=r.info=r.debug=r.trace=r),!1===t.enabled&&(t.level="silent");const l=t.level||"info",g=Object.create(r);g.log||(g.log=p),Object.defineProperty(g,"levelVal",{get:function(){return"silent"===this.level?1/0:this.levels.values[this.level]}}),Object.defineProperty(g,"level",{get:function(){return this._level},set:function(t){if("silent"!==t&&!this.levels.values[t])throw Error("unknown level "+t);this._level=t,a(m,g,"error","log"),a(m,g,"fatal","error"),a(m,g,"warn","error"),a(m,g,"info","log"),a(m,g,"debug","log"),a(m,g,"trace","log")}});const m={transmit:e,serialize:s,asObject:t.browser.asObject,levels:["error","fatal","warn","info","debug","trace"],timestamp:u(t)};return g.levels=o.levels,g.level=l,g.setMaxListeners=g.getMaxListeners=g.emit=g.addListener=g.on=g.prependListener=g.once=g.prependOnceListener=g.removeListener=g.removeAllListeners=g.listeners=g.listenerCount=g.eventNames=g.write=g.flush=p,g.serializers=i,g._serialize=s,g._stdErrSerialize=d,g.child=function(r,n){if(!r)throw new Error("missing bindings for child Pino");n=n||{},s&&r.serializers&&(n.serializers=r.serializers);const o=n.serializers;if(s&&o){var a=Object.assign({},i,o),u=!0===t.browser.serialize?Object.keys(a):s;delete r.serializers,h([r],u,a,this._stdErrSerialize)}function d(t){this._childLevel=1+(0|t._childLevel),this.error=c(t,r,"error"),this.fatal=c(t,r,"fatal"),this.warn=c(t,r,"warn"),this.info=c(t,r,"info"),this.debug=c(t,r,"debug"),this.trace=c(t,r,"trace"),a&&(this.serializers=a,this._serialize=u),e&&(this._logEvent=f([].concat(t._logEvent.bindings,r)))}return d.prototype=this,new d(this)},e&&(g._logEvent=f()),g}function a(t,e,r,s){const a=Object.getPrototypeOf(e);e[r]=e.levelVal>e.levels.values[r]?p:a[r]?a[r]:n[r]||n[s]||p,function(t,e,r){var s;(t.transmit||e[r]!==p)&&(e[r]=(s=e[r],function(){const a=t.timestamp(),c=new Array(arguments.length),u=Object.getPrototypeOf&&Object.getPrototypeOf(this)===n?n:this;for(var d=0;d-1&&i in r&&(t[n][i]=r[i](t[n][i]))}function c(t,e,r){return function(){const i=new Array(1+arguments.length);i[0]=e;for(var n=1;n{t.exports={rE:"6.5.7"}}},e={};function r(i){var n=e[i];if(void 0!==n)return n.exports;var s=e[i]={id:i,loaded:!1,exports:{}};return t[i].call(s.exports,s,s.exports,r),s.loaded=!0,s.exports}r.amdO={},r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.nmd=t=>(t.paths=[],t.children||(t.children=[]),t);var i={};r.r(i),r.d(i,{identity:()=>oe});var n={};r.r(n),r.d(n,{base2:()=>ae});var s={};r.r(s),r.d(s,{base8:()=>he});var o={};r.r(o),r.d(o,{base10:()=>ce});var a={};r.r(a),r.d(a,{base16:()=>fe,base16upper:()=>ue});var h={};r.r(h),r.d(h,{base32:()=>de,base32hex:()=>me,base32hexpad:()=>ye,base32hexpadupper:()=>ve,base32hexupper:()=>be,base32pad:()=>pe,base32padupper:()=>ge,base32upper:()=>le,base32z:()=>we});var c={};r.r(c),r.d(c,{base36:()=>_e,base36upper:()=>Ae});var f={};r.r(f),r.d(f,{base58btc:()=>Me,base58flickr:()=>Se});var u={};r.r(u),r.d(u,{base64:()=>Ee,base64pad:()=>Ie,base64url:()=>xe,base64urlpad:()=>Oe});var d={};r.r(d),r.d(d,{base256emoji:()=>Te});var l={};r.r(l),r.d(l,{sha256:()=>tr,sha512:()=>er});var p={};r.r(p),r.d(p,{identity:()=>ir});var g={};r.r(g),r.d(g,{code:()=>sr,decode:()=>ar,encode:()=>or,name:()=>nr});var m={};r.r(m),r.d(m,{code:()=>ur,decode:()=>lr,encode:()=>dr,name:()=>fr});var b=r(7007),y=r.n(b);const v=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,w=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,_=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function A(t,e){if(!("__proto__"===t||"constructor"===t&&e&&"object"==typeof e&&"prototype"in e))return e;!function(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}(t)}function M(t,e={}){if("string"!=typeof t)return t;const r=t.trim();if('"'===t[0]&&'"'===t.at(-1)&&!t.includes("\\"))return r.slice(1,-1);if(r.length<=9){const t=r.toLowerCase();if("true"===t)return!0;if("false"===t)return!1;if("undefined"===t)return;if("null"===t)return null;if("nan"===t)return Number.NaN;if("infinity"===t)return Number.POSITIVE_INFINITY;if("-infinity"===t)return Number.NEGATIVE_INFINITY}if(!_.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(v.test(t)||w.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,A)}return JSON.parse(t)}catch(r){if(e.strict)throw r;return t}}function S(t,...e){try{return(r=t(...e))&&"function"==typeof r.then?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}var r}function E(t){if(function(t){const e=typeof t;return null===t||"object"!==e&&"function"!==e}(t))return String(t);if(function(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}(t)||Array.isArray(t))return JSON.stringify(t);if("function"==typeof t.toJSON)return E(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function I(){if(void 0===typeof Buffer)throw new TypeError("[unstorage] Buffer is not supported!")}const x="base64:";function O(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function N(...t){return O(t.join(":"))}function P(t){return(t=O(t))?t+":":""}const R=()=>{const t=new Map;return{name:"memory",options:{},hasItem:e=>t.has(e),getItem:e=>t.get(e)??null,getItemRaw:e=>t.get(e)??null,setItem(e,r){t.set(e,r)},setItemRaw(e,r){t.set(e,r)},removeItem(e){t.delete(e)},getKeys:()=>Array.from(t.keys()),clear(){t.clear()},dispose(){t.clear()}}};function T(t,e,r){return t.watch?t.watch(((t,i)=>e(t,r+i))):()=>{}}async function C(t){"function"==typeof t.dispose&&await S(t.dispose)}function k(t){return new Promise(((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)}))}function L(t,e){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(e);const i=k(r);return(t,r)=>i.then((i=>r(i.transaction(e,t).objectStore(e))))}let q;function U(){return q||(q=L("keyval-store","keyval")),q}function B(t,e=U()){return e("readonly",(e=>k(e.get(t))))}const D=t=>JSON.stringify(t,((t,e)=>"bigint"==typeof e?e.toString()+"n":e)),z=t=>{const e=t.replace(/([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g,'$1"$2n"$3');return JSON.parse(e,((t,e)=>"string"==typeof e&&e.match(/^\d+n$/)?BigInt(e.substring(0,e.length-1)):e))};function j(t){if("string"!=typeof t)throw new Error("Cannot safe json parse value of type "+typeof t);try{return z(t)}catch(e){return t}}function F(t){return"string"==typeof t?t:D(t)||""}var K=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",r=t=>e+t;let i;return t.dbName&&t.storeName&&(i=L(t.dbName,t.storeName)),{name:"idb-keyval",options:t,hasItem:async t=>!(typeof await B(r(t),i)>"u"),getItem:async t=>await B(r(t),i)??null,setItem:(t,e)=>function(t,e,r=U()){return r("readwrite",(r=>(r.put(e,t),k(r.transaction))))}(r(t),e,i),removeItem:t=>function(t,e=U()){return e("readwrite",(e=>(e.delete(t),k(e.transaction))))}(r(t),i),getKeys:()=>function(t=U()){return t("readonly",(t=>{if(t.getAllKeys)return k(t.getAllKeys());const e=[];return function(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},k(t.transaction)}(t,(t=>e.push(t.key))).then((()=>e))}))}(i),clear:()=>function(t=U()){return t("readwrite",(t=>(t.clear(),k(t.transaction))))}(i)}};class V{constructor(){this.indexedDb=function(t={}){const e={mounts:{"":t.driver||R()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},r=t=>{for(const r of e.mountpoints)if(t.startsWith(r))return{base:r,relativeKey:t.slice(r.length),driver:e.mounts[r]};return{base:"",relativeKey:t,driver:e.mounts[""]}},i=(t,r)=>e.mountpoints.filter((e=>e.startsWith(t)||r&&t.startsWith(e))).map((r=>({relativeBase:t.length>r.length?t.slice(r.length):void 0,mountpoint:r,driver:e.mounts[r]}))),n=(t,r)=>{if(e.watching){r=O(r);for(const i of e.watchListeners)i(t,r)}},s=async()=>{if(e.watching){for(const t in e.unwatch)await e.unwatch[t]();e.unwatch={},e.watching=!1}},o=(t,e,i)=>{const n=new Map,s=t=>{let e=n.get(t.base);return e||(e={driver:t.driver,base:t.base,items:[]},n.set(t.base,e)),e};for(const i of t){const t="string"==typeof i,n=O(t?i:i.key),o=t?void 0:i.value,a=t||!i.options?e:{...e,...i.options},h=r(n);s(h).items.push({key:n,value:o,relativeKey:h.relativeKey,options:a})}return Promise.all([...n.values()].map((t=>i(t)))).then((t=>t.flat()))},a={hasItem(t,e={}){t=O(t);const{relativeKey:i,driver:n}=r(t);return S(n.hasItem,i,e)},getItem(t,e={}){t=O(t);const{relativeKey:i,driver:n}=r(t);return S(n.getItem,i,e).then((t=>M(t)))},getItems:(t,e)=>o(t,e,(t=>t.driver.getItems?S(t.driver.getItems,t.items.map((t=>({key:t.relativeKey,options:t.options}))),e).then((e=>e.map((e=>({key:N(t.base,e.key),value:M(e.value)}))))):Promise.all(t.items.map((e=>S(t.driver.getItem,e.relativeKey,e.options).then((t=>({key:e.key,value:M(t)})))))))),getItemRaw(t,e={}){t=O(t);const{relativeKey:i,driver:n}=r(t);return n.getItemRaw?S(n.getItemRaw,i,e):S(n.getItem,i,e).then((t=>function(t){return"string"!=typeof t?t:t.startsWith(x)?(I(),Buffer.from(t.slice(7),"base64")):t}(t)))},async setItem(t,e,i={}){if(void 0===e)return a.removeItem(t);t=O(t);const{relativeKey:s,driver:o}=r(t);o.setItem&&(await S(o.setItem,s,E(e),i),o.watch||n("update",t))},async setItems(t,e){await o(t,e,(async t=>{t.driver.setItems&&await S(t.driver.setItems,t.items.map((t=>({key:t.relativeKey,value:E(t.value),options:t.options}))),e),t.driver.setItem&&await Promise.all(t.items.map((e=>S(t.driver.setItem,e.relativeKey,E(e.value),e.options))))}))},async setItemRaw(t,e,i={}){if(void 0===e)return a.removeItem(t,i);t=O(t);const{relativeKey:s,driver:o}=r(t);if(o.setItemRaw)await S(o.setItemRaw,s,e,i);else{if(!o.setItem)return;await S(o.setItem,s,function(t){if("string"==typeof t)return t;I();const e=Buffer.from(t).toString("base64");return x+e}(e),i)}o.watch||n("update",t)},async removeItem(t,e={}){"boolean"==typeof e&&(e={removeMeta:e}),t=O(t);const{relativeKey:i,driver:s}=r(t);s.removeItem&&(await S(s.removeItem,i,e),(e.removeMeta||e.removeMata)&&await S(s.removeItem,i+"$",e),s.watch||n("remove",t))},async getMeta(t,e={}){"boolean"==typeof e&&(e={nativeOnly:e}),t=O(t);const{relativeKey:i,driver:n}=r(t),s=Object.create(null);if(n.getMeta&&Object.assign(s,await S(n.getMeta,i,e)),!e.nativeOnly){const t=await S(n.getItem,i+"$",e).then((t=>M(t)));t&&"object"==typeof t&&("string"==typeof t.atime&&(t.atime=new Date(t.atime)),"string"==typeof t.mtime&&(t.mtime=new Date(t.mtime)),Object.assign(s,t))}return s},setMeta(t,e,r={}){return this.setItem(t+"$",e,r)},removeMeta(t,e={}){return this.removeItem(t+"$",e)},async getKeys(t,e={}){t=P(t);const r=i(t,!0);let n=[];const s=[];for(const t of r){const r=(await S(t.driver.getKeys,t.relativeBase,e)).map((e=>t.mountpoint+O(e))).filter((t=>!n.some((e=>t.startsWith(e)))));s.push(...r),n=[t.mountpoint,...n.filter((e=>!e.startsWith(t.mountpoint)))]}return t?s.filter((e=>e.startsWith(t)&&!e.endsWith("$"))):s.filter((t=>!t.endsWith("$")))},async clear(t,e={}){t=P(t),await Promise.all(i(t,!1).map((async t=>{if(t.driver.clear)return S(t.driver.clear,t.relativeBase,e);if(t.driver.removeItem){const r=await t.driver.getKeys(t.relativeBase||"",e);return Promise.all(r.map((r=>t.driver.removeItem(r,e))))}})))},async dispose(){await Promise.all(Object.values(e.mounts).map((t=>C(t))))},watch:async t=>(await(async()=>{if(!e.watching){e.watching=!0;for(const t in e.mounts)e.unwatch[t]=await T(e.mounts[t],n,t)}})(),e.watchListeners.push(t),async()=>{e.watchListeners=e.watchListeners.filter((e=>e!==t)),0===e.watchListeners.length&&await s()}),async unwatch(){e.watchListeners=[],await s()},mount(t,r){if((t=P(t))&&e.mounts[t])throw new Error(`already mounted at ${t}`);return t&&(e.mountpoints.push(t),e.mountpoints.sort(((t,e)=>e.length-t.length))),e.mounts[t]=r,e.watching&&Promise.resolve(T(r,n,t)).then((r=>{e.unwatch[t]=r})).catch(console.error),a},async unmount(t,r=!0){(t=P(t))&&e.mounts[t]&&(e.watching&&t in e.unwatch&&(e.unwatch[t](),delete e.unwatch[t]),r&&await C(e.mounts[t]),e.mountpoints=e.mountpoints.filter((e=>e!==t)),delete e.mounts[t])},getMount(t=""){t=O(t)+":";const e=r(t);return{driver:e.driver,base:e.base}},getMounts:(t="",e={})=>(t=O(t),i(t,e.parents).map((t=>({driver:t.driver,base:t.mountpoint}))))};return a}({driver:K({dbName:"WALLET_CONNECT_V2_INDEXED_DB",storeName:"keyvaluestorage"})})}async getKeys(){return this.indexedDb.getKeys()}async getEntries(){return(await this.indexedDb.getItems(await this.indexedDb.getKeys())).map((t=>[t.key,t.value]))}async getItem(t){const e=await this.indexedDb.getItem(t);if(null!==e)return e}async setItem(t,e){await this.indexedDb.setItem(t,F(e))}async removeItem(t){await this.indexedDb.removeItem(t)}}var H=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof r.g<"u"?r.g:typeof self<"u"?self:{},W={exports:{}};function J(t){var e;return[t[0],j(null!=(e=t[1])?e:"")]}!function(){let t;function e(){}t=e,t.prototype.getItem=function(t){return this.hasOwnProperty(t)?String(this[t]):null},t.prototype.setItem=function(t,e){this[t]=String(e)},t.prototype.removeItem=function(t){delete this[t]},t.prototype.clear=function(){const t=this;Object.keys(t).forEach((function(e){t[e]=void 0,delete t[e]}))},t.prototype.key=function(t){return t=t||0,Object.keys(this)[t]},t.prototype.__defineGetter__("length",(function(){return Object.keys(this).length})),typeof H<"u"&&H.localStorage?W.exports=H.localStorage:typeof window<"u"&&window.localStorage?W.exports=window.localStorage:W.exports=new e}();class G{constructor(){this.localStorage=W.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(J)}async getItem(t){const e=this.localStorage.getItem(t);if(null!==e)return j(e)}async setItem(t,e){this.localStorage.setItem(t,F(e))}async removeItem(t){this.localStorage.removeItem(t)}}class ${constructor(){this.initialized=!1,this.setInitialized=t=>{this.storage=t,this.initialized=!0};const t=new G;this.storage=t;try{(async(t,e,r)=>{const i="wc_storage_version",n=await e.getItem(i);if(n&&n>=1)return void r(e);const s=await t.getKeys();if(!s.length)return void r(e);const o=[];for(;s.length;){const r=s.shift();if(!r)continue;const i=r.toLowerCase();if(i.includes("wc@")||i.includes("walletconnect")||i.includes("wc_")||i.includes("wallet_connect")){const i=await t.getItem(r);await e.setItem(r,i),o.push(r)}}await e.setItem(i,1),r(e),(async(t,e)=>{e.length&&e.forEach((async e=>{await t.removeItem(e)}))})(t,o)})(t,new V,this.setInitialized)}catch{this.initialized=!0}}async getKeys(){return await this.initialize(),this.storage.getKeys()}async getEntries(){return await this.initialize(),this.storage.getEntries()}async getItem(t){return await this.initialize(),this.storage.getItem(t)}async setItem(t,e){return await this.initialize(),this.storage.setItem(t,e)}async removeItem(t){return await this.initialize(),this.storage.removeItem(t)}async initialize(){this.initialized||await new Promise((t=>{const e=setInterval((()=>{this.initialized&&(clearInterval(e),t())}),20)}))}}var Y=r(8900);class Q{}class X extends Q{constructor(t){super()}}const Z=Y.FIVE_SECONDS,tt="heartbeat_pulse";class et extends X{constructor(t){super(t),this.events=new b.EventEmitter,this.interval=Z,this.interval=t?.interval||Z}static async init(t){const e=new et(t);return await e.init(),e}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async initialize(){this.intervalRef=setInterval((()=>this.pulse()),(0,Y.toMiliseconds)(this.interval))}pulse(){this.events.emit(tt)}}var rt=r(4874),it=r.n(rt);const nt="custom_context";class st{constructor(t){this.nodeValue=t,this.sizeInBytes=(new TextEncoder).encode(this.nodeValue).length,this.next=null}get value(){return this.nodeValue}get size(){return this.sizeInBytes}}class ot{constructor(t){this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=t,this.sizeInBytes=0}append(t){const e=new st(t);if(e.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${t} with size ${e.size}`);for(;this.size+e.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=e),this.tail=e):(this.head=e,this.tail=e),this.lengthInNodes++,this.sizeInBytes+=e.size}shift(){if(!this.head)return;const t=this.head;this.head=this.head.next,this.head||(this.tail=null),this.lengthInNodes--,this.sizeInBytes-=t.size}toArray(){const t=[];let e=this.head;for(;null!==e;)t.push(e.value),e=e.next;return t}get length(){return this.lengthInNodes}get size(){return this.sizeInBytes}toOrderedArray(){return Array.from(this)}[Symbol.iterator](){let t=this.head;return{next:()=>{if(!t)return{done:!0,value:null};const e=t.value;return t=t.next,{done:!1,value:e}}}}}class at{constructor(t,e=1024e3){this.level=t??"error",this.levelValue=rt.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=e,this.logs=new ot(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(t,e){e===rt.levels.values.error?console.error(t):e===rt.levels.values.warn?console.warn(t):e===rt.levels.values.debug?console.debug(t):e===rt.levels.values.trace?console.trace(t):console.log(t)}appendToLogs(t){this.logs.append(F({timestamp:(new Date).toISOString(),log:t}));const e="string"==typeof t?JSON.parse(t).level:t.level;e>=this.levelValue&&this.forwardToConsole(t,e)}getLogs(){return this.logs}clearLogs(){this.logs=new ot(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(t){const e=this.getLogArray();return e.push(F({extraMetadata:t})),new Blob(e,{type:"application/json"})}}class ht{constructor(t,e=1024e3){this.baseChunkLogger=new at(t,e)}write(t){this.baseChunkLogger.appendToLogs(t)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(t){return this.baseChunkLogger.logsToBlob(t)}downloadLogsBlobInBrowser(t){const e=URL.createObjectURL(this.logsToBlob(t)),r=document.createElement("a");r.href=e,r.download=`walletconnect-logs-${(new Date).toISOString()}.txt`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(e)}}class ct{constructor(t,e=1024e3){this.baseChunkLogger=new at(t,e)}write(t){this.baseChunkLogger.appendToLogs(t)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(t){return this.baseChunkLogger.logsToBlob(t)}}var ft=Object.defineProperty,ut=Object.defineProperties,dt=Object.getOwnPropertyDescriptors,lt=Object.getOwnPropertySymbols,pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable,mt=(t,e,r)=>e in t?ft(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bt=(t,e)=>{for(var r in e||(e={}))pt.call(e,r)&&mt(t,r,e[r]);if(lt)for(var r of lt(e))gt.call(e,r)&&mt(t,r,e[r]);return t},yt=(t,e)=>ut(t,dt(e));function vt(t){return yt(bt({},t),{level:t?.level||"info"})}function wt(t,e=nt){let r="";return r=typeof t.bindings>"u"?function(t,e=nt){return t[e]||""}(t,e):t.bindings().context||"",r}function _t(t,e,r=nt){const i=function(t,e,r=nt){const i=wt(t,r);return i.trim()?`${i}/${e}`:e}(t,e,r);return function(t,e,r=nt){return t[r]=e,t}(t.child({context:i}),i,r)}function At(t){return typeof t.loggerOverride<"u"&&"string"!=typeof t.loggerOverride?{logger:t.loggerOverride,chunkLoggerController:null}:typeof window<"u"?function(t){var e,r;const i=new ht(null==(e=t.opts)?void 0:e.level,t.maxSizeInBytes);return{logger:it()(yt(bt({},t.opts),{level:"trace",browser:yt(bt({},null==(r=t.opts)?void 0:r.browser),{write:t=>i.write(t)})})),chunkLoggerController:i}}(t):function(t){var e;const r=new ct(null==(e=t.opts)?void 0:e.level,t.maxSizeInBytes);return{logger:it()(yt(bt({},t.opts),{level:"trace"}),r),chunkLoggerController:r}}(t)}class Mt extends Q{constructor(t){super(),this.opts=t,this.protocol="wc",this.version=2}}class St extends Q{constructor(t,e){super(),this.core=t,this.logger=e,this.records=new Map}}class Et{constructor(t,e){this.logger=t,this.core=e}}class It extends Q{constructor(t,e){super(),this.relayer=t,this.logger=e}}class xt extends Q{constructor(t){super()}}class Ot{constructor(t,e,r,i){this.core=t,this.logger=e,this.name=r}}class Nt extends Q{constructor(t,e){super(),this.relayer=t,this.logger=e}}class Pt extends Q{constructor(t,e){super(),this.core=t,this.logger=e}}class Rt{constructor(t,e,r){this.core=t,this.logger=e,this.store=r}}class Tt{constructor(t,e){this.projectId=t,this.logger=e}}class Ct{constructor(t,e,r){this.core=t,this.logger=e,this.telemetryEnabled=r}}y();class kt{constructor(t){this.opts=t,this.protocol="wc",this.version=2}}b.EventEmitter;class Lt{constructor(t){this.client=t}}var qt=r(4904),Ut=r(7052);const Bt=".",Dt="base64url",zt="utf8",jt="utf8",Ft=":",Kt="did",Vt="key",Ht="base58btc",Wt="z",Jt="K36";function Gt(t){return null!=globalThis.Buffer?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function $t(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?Gt(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}const Yt=function(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i>>0,o=new Uint8Array(s);t[e];){var f=r[t.charCodeAt(e)];if(255===f)return;for(var u=0,d=s-1;(0!==f||u>>0,o[d]=f%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");n=u,e++}if(" "!==t[e]){for(var l=s-n;l!==s&&0===o[l];)l++;for(var p=new Uint8Array(i+(s-l)),g=i;l!==s;)p[g++]=o[l++];return p}}}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,i=0,n=0,s=e.length;n!==s&&0===e[n];)n++,r++;for(var o=(s-n)*f+1>>>0,c=new Uint8Array(o);n!==s;){for(var u=e[n],d=0,l=o-1;(0!==u||d>>0,c[l]=u%a>>>0,u=u/a>>>0;if(0!==u)throw new Error("Non-zero carry");i=d,n++}for(var p=o-i;p!==o&&0===c[p];)p++;for(var g=h.repeat(r);p{if(t instanceof Uint8Array&&"Uint8Array"===t.constructor.name)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")});class Xt{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class Zt{constructor(t,e,r){if(this.name=t,this.prefix=e,void 0===e.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if("string"==typeof t){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(t){return ee(this,t)}}class te{constructor(t){this.decoders=t}or(t){return ee(this,t)}decode(t){const e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const ee=(t,e)=>new te({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class re{constructor(t,e,r,i){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=i,this.encoder=new Xt(t,e,r),this.decoder=new Zt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const ie=({name:t,prefix:e,encode:r,decode:i})=>new re(t,e,r,i),ne=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=Yt(r,e);return ie({prefix:t,name:e,encode:i,decode:t=>Qt(n(t))})},se=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>ie({prefix:e,name:t,encode:t=>((t,e,r)=>{const i="="===e[e.length-1],n=(1<r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<((t,e,r,i)=>{const n={};for(let t=0;t=8&&(a-=8,o[c++]=255&h>>a)}if(a>=r||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o})(e,i,r,t)}),oe=ie({prefix:"\0",name:"identity",encode:t=>{return e=t,(new TextDecoder).decode(e);var e},decode:t=>(t=>(new TextEncoder).encode(t))(t)}),ae=se({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1}),he=se({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3}),ce=ne({prefix:"9",name:"base10",alphabet:"0123456789"}),fe=se({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ue=se({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4}),de=se({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),le=se({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pe=se({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ge=se({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),me=se({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),be=se({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ye=se({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ve=se({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),we=se({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),_e=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ae=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),Me=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Se=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),Ee=se({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ie=se({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),xe=se({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Oe=se({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),Ne=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),Pe=Ne.reduce(((t,e,r)=>(t[r]=e,t)),[]),Re=Ne.reduce(((t,e,r)=>(t[e.codePointAt(0)]=r,t)),[]),Te=ie({prefix:"🚀",name:"base256emoji",encode:function(t){return t.reduce(((t,e)=>t+Pe[e]),"")},decode:function(t){const e=[];for(const r of t){const t=Re[r.codePointAt(0)];if(void 0===t)throw new Error(`Non-base256emoji character: ${r}`);e.push(t)}return new Uint8Array(e)}});var Ce=128,ke=-128,Le=Math.pow(2,31),qe=Math.pow(2,7),Ue=Math.pow(2,14),Be=Math.pow(2,21),De=Math.pow(2,28),ze=Math.pow(2,35),je=Math.pow(2,42),Fe=Math.pow(2,49),Ke=Math.pow(2,56),Ve=Math.pow(2,63);const He=function t(e,r,i){r=r||[];for(var n=i=i||0;e>=Le;)r[i++]=255&e|Ce,e/=128;for(;e&ke;)r[i++]=255&e|Ce,e>>>=7;return r[i]=0|e,t.bytes=i-n+1,r},We=function(t){return t(He(t,e,r),e),Ge=t=>We(t),$e=(t,e)=>{const r=e.byteLength,i=Ge(t),n=i+Ge(r),s=new Uint8Array(n+r);return Je(t,s,0),Je(r,s,i),s.set(e,n),new Ye(t,r,e,s)};class Ye{constructor(t,e,r,i){this.code=t,this.size=e,this.digest=r,this.bytes=i}}const Qe=({name:t,code:e,encode:r})=>new Xe(t,e,r);class Xe{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){const e=this.encode(t);return e instanceof Uint8Array?$e(this.code,e):e.then((t=>$e(this.code,t)))}throw Error("Unknown type, must be binary type")}}const Ze=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),tr=Qe({name:"sha2-256",code:18,encode:Ze("SHA-256")}),er=Qe({name:"sha2-512",code:19,encode:Ze("SHA-512")}),rr=Qt,ir={code:0,name:"identity",encode:rr,digest:t=>$e(0,rr(t))},nr="raw",sr=85,or=t=>Qt(t),ar=t=>Qt(t),hr=new TextEncoder,cr=new TextDecoder,fr="json",ur=512,dr=t=>hr.encode(JSON.stringify(t)),lr=t=>JSON.parse(cr.decode(t));Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"),Symbol.for("@ipld/js-cid/CID");const pr={...i,...n,...s,...o,...a,...h,...c,...f,...u,...d};function gr(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const mr=gr("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),br=gr("ascii","a",(t=>{let e="a";for(let r=0;r{const e=$t((t=t.substring(1)).length);for(let r=0;rt+e.length),0));const r=$t(e);let i=0;for(const e of t)r.set(e,i),i+=e.length;return Gt(r)}([e,t]),Ht);return[Kt,Vt,r].join(Ft)}function Sr(t){const e=t.split(Bt);return{header:_r(e[0]),payload:_r(e[1]),signature:wr(e[2],Dt),data:wr(e.slice(0,2).join(Bt),jt)}}function Er(t=(0,Ut.randomBytes)(32)){return qt.K(t)}r(5665);var Ir=function(t,e,r){if(r||2===arguments.length)for(var i,n=0,s=e.length;nt+e.length),0));const r=Vr(e);let i=0;for(const e of t)r.set(e,i),i+=e.length;return r}function Wr(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const Jr=Wr("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),Gr=Wr("ascii","a",(t=>{let e="a";for(let r=0;r{const e=Vr((t=t.substring(1)).length);for(let r=0;re in t?ri(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ai=(t,e)=>{for(var r in e||(e={}))ni.call(e,r)&&oi(t,r,e[r]);if(ii)for(var r of ii(e))si.call(e,r)&&oi(t,r,e[r]);return t};const hi="ReactNative",ci={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},fi="js";function ui(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function di(){return!(0,Ur.getDocument)()&&!!(0,Ur.getNavigator)()&&navigator.product===hi}function li(){return!ui()&&!!(0,Ur.getNavigator)()&&!!(0,Ur.getDocument)()}function pi(){return di()?ci.reactNative:ui()?ci.node:li()?ci.browser:ci.unknown}function gi(t,e,i){const n=function(){if(pi()===ci.reactNative&&typeof r.g<"u"&&typeof(null==r.g?void 0:r.g.Platform)<"u"){const{OS:t,Version:e}=r.g.Platform;return[t,e].join("-")}const t=e?qr(e):"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product?new Rr:"undefined"!=typeof navigator?qr(navigator.userAgent):"undefined"!=typeof process&&process.version?new Or(process.version.slice(1)):null;var e;if(null===t)return"unknown";const i=t.os?t.os.replace(" ","").toLowerCase():"unknown";return"browser"===t.type?[i,t.name,t.version].join("-"):[i,t.version].join("-")}(),s=function(){var t;const e=pi();return e===ci.browser?[e,(null==(t=(0,Ur.getLocation)())?void 0:t.host)||"unknown"].join(":"):e}();return[[t,e].join("-"),[fi,i].join("-"),n,s].join("/")}function mi(t,e){return t.filter((t=>e.includes(t))).length===t.length}function bi(t){return Object.fromEntries(t.entries())}function yi(t){return new Map(Object.entries(t))}function vi(t=Y.FIVE_MINUTES,e){const r=(0,Y.toMiliseconds)(t||Y.FIVE_MINUTES);let i,n,s;return{resolve:t=>{s&&i&&(clearTimeout(s),i(t))},reject:t=>{s&&n&&(clearTimeout(s),n(t))},done:()=>new Promise(((t,o)=>{s=setTimeout((()=>{o(new Error(e))}),r),i=t,n=o}))}}function wi(t,e,r){return new Promise((async(i,n)=>{const s=setTimeout((()=>n(new Error(r))),e);try{i(await t)}catch(t){n(t)}clearTimeout(s)}))}function _i(t,e){if("string"==typeof e&&e.startsWith(`${t}:`))return e;if("topic"===t.toLowerCase()){if("string"!=typeof e)throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}if("id"===t.toLowerCase()){if("number"!=typeof e)throw new Error('Value must be "number" for expirer target type: id');return`id:${e}`}throw new Error(`Unknown expirer target type: ${t}`)}function Ai(t){const[e,r]=t.split(":"),i={id:void 0,topic:void 0};if("topic"===e&&"string"==typeof r)i.topic=r;else{if("id"!==e||!Number.isInteger(Number(r)))throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${r}`);i.id=Number(r)}return i}function Mi(t,e){return(0,Y.fromMiliseconds)((e||Date.now())+(0,Y.toMiliseconds)(t))}function Si(t){return Date.now()>=(0,Y.toMiliseconds)(t)}function Ei(t,e){return`${t}${e?`:${e}`:""}`}function Ii(t=[],e=[]){return[...new Set([...t,...e])]}function xi(t,e){if(!t.includes(e))return null;const r=t.split(/([&,?,=])/),i=r.indexOf(e);return r[i+2]}var Oi,Ni=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof r.g<"u"?r.g:typeof self<"u"?self:{},Pi={exports:{}};Oi=Pi,function(){var t="input is invalid type",e="object"==typeof window,r=e?window:{};r.JS_SHA3_NO_WINDOW&&(e=!1);var i=!e&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?r=Ni:i&&(r=self);var n=!r.JS_SHA3_NO_COMMON_JS&&Oi.exports,s=!r.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",o="0123456789abcdef".split(""),a=[4,1024,262144,67108864],h=[0,8,16,24],c=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],f=[224,256,384,512],u=[128,256],d=["hex","buffer","arrayBuffer","array","digest"],l={128:168,256:136};(r.JS_SHA3_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),s&&(r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var p=function(t,e,r){return function(i){return new N(t,e,t).update(i)[r]()}},g=function(t,e,r){return function(i,n){return new N(t,e,n).update(i)[r]()}},m=function(t,e,r){return function(e,i,n,s){return _["cshake"+t].update(e,i,n,s)[r]()}},b=function(t,e,r){return function(e,i,n,s){return _["kmac"+t].update(e,i,n,s)[r]()}},y=function(t,e,r,i){for(var n=0;n>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var i=0;i<50;++i)this.s[i]=0}function P(t,e,r){N.call(this,t,e,r)}N.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var r,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(s&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||s&&ArrayBuffer.isView(e)))throw new Error(t);r=!0}for(var n,o,a=this.blocks,c=this.byteCount,f=e.length,u=this.blockCount,d=0,l=this.s;d>2]|=e[d]<>2]|=o<>2]|=(192|o>>6)<>2]|=(128|63&o)<=57344?(a[n>>2]|=(224|o>>12)<>2]|=(128|o>>6&63)<>2]|=(128|63&o)<>2]|=(240|o>>18)<>2]|=(128|o>>12&63)<>2]|=(128|o>>6&63)<>2]|=(128|63&o)<=c){for(this.start=n-c,this.block=a[u],n=0;n>=8);r>0;)n.unshift(r),r=255&(t>>=8),++i;return e?n.push(i):n.unshift(i),this.update(n),n.length},N.prototype.encodeString=function(e){var r,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(s&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||s&&ArrayBuffer.isView(e)))throw new Error(t);r=!0}var n=0,o=e.length;if(r)n=o;else for(var a=0;a=57344?n+=3:(h=65536+((1023&h)<<10|1023&e.charCodeAt(++a)),n+=4)}return n+=this.encode(8*n),this.update(e),n},N.prototype.bytepad=function(t,e){for(var r=this.encode(e),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>4&15]+o[15&t]+o[t>>12&15]+o[t>>8&15]+o[t>>20&15]+o[t>>16&15]+o[t>>28&15]+o[t>>24&15];a%e==0&&(R(r),s=0)}return n&&(t=r[s],h+=o[t>>4&15]+o[15&t],n>1&&(h+=o[t>>12&15]+o[t>>8&15]),n>2&&(h+=o[t>>20&15]+o[t>>16&15])),h},N.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,i=this.outputBlocks,n=this.extraBytes,s=0,o=0,a=this.outputBits>>3;t=n?new ArrayBuffer(i+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);o>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%r==0&&R(i)}return s&&(t=a<<2,e=i[o],h[t]=255&e,s>1&&(h[t+1]=e>>8&255),s>2&&(h[t+2]=e>>16&255)),h},P.prototype=new N,P.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var R=function(t){var e,r,i,n,s,o,a,h,f,u,d,l,p,g,m,b,y,v,w,_,A,M,S,E,I,x,O,N,P,R,T,C,k,L,q,U,B,D,z,j,F,K,V,H,W,J,G,$,Y,Q,X,Z,tt,et,rt,it,nt,st,ot,at,ht,ct,ft;for(i=0;i<48;i+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],o=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],h=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],u=t[6]^t[16]^t[26]^t[36]^t[46],d=t[7]^t[17]^t[27]^t[37]^t[47],e=(l=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),r=(p=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|o>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=n^(h<<1|f>>>31),r=s^(f<<1|h>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=o^(u<<1|d>>>31),r=a^(d<<1|u>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=h^(l<<1|p>>>31),r=f^(p<<1|l>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=u^(n<<1|s>>>31),r=d^(s<<1|n>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,g=t[0],m=t[1],J=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,N=t[20]<<3|t[21]>>>29,P=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,K=t[40]<<18|t[41]>>>14,V=t[41]<<18|t[40]>>>14,L=t[2]<<1|t[3]>>>31,q=t[3]<<1|t[2]>>>31,b=t[13]<<12|t[12]>>>20,y=t[12]<<12|t[13]>>>20,$=t[22]<<10|t[23]>>>22,Y=t[23]<<10|t[22]>>>22,R=t[33]<<13|t[32]>>>19,T=t[32]<<13|t[33]>>>19,ct=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,U=t[14]<<6|t[15]>>>26,B=t[15]<<6|t[14]>>>26,v=t[25]<<11|t[24]>>>21,w=t[24]<<11|t[25]>>>21,Q=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,C=t[45]<<29|t[44]>>>3,k=t[44]<<29|t[45]>>>3,E=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,nt=t[16]<<23|t[17]>>>9,D=t[26]<<25|t[27]>>>7,z=t[27]<<25|t[26]>>>7,_=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Z=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,H=t[8]<<27|t[9]>>>5,W=t[9]<<27|t[8]>>>5,x=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,st=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,j=t[38]<<8|t[39]>>>24,F=t[39]<<8|t[38]>>>24,M=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=g^~b&v,t[1]=m^~y&w,t[10]=E^~x&N,t[11]=I^~O&P,t[20]=L^~U&D,t[21]=q^~B&z,t[30]=H^~J&$,t[31]=W^~G&Y,t[40]=et^~it&st,t[41]=rt^~nt&ot,t[2]=b^~v&_,t[3]=y^~w&A,t[12]=x^~N&R,t[13]=O^~P&T,t[22]=U^~D&j,t[23]=B^~z&F,t[32]=J^~$&Q,t[33]=G^~Y&X,t[42]=it^~st&at,t[43]=nt^~ot&ht,t[4]=v^~_&M,t[5]=w^~A&S,t[14]=N^~R&C,t[15]=P^~T&k,t[24]=D^~j&K,t[25]=z^~F&V,t[34]=$^~Q&Z,t[35]=Y^~X&tt,t[44]=st^~at&ct,t[45]=ot^~ht&ft,t[6]=_^~M&g,t[7]=A^~S&m,t[16]=R^~C&E,t[17]=T^~k&I,t[26]=j^~K&L,t[27]=F^~V&q,t[36]=Q^~Z&H,t[37]=X^~tt&W,t[46]=at^~ct&et,t[47]=ht^~ft&rt,t[8]=M^~g&b,t[9]=S^~m&y,t[18]=C^~E&x,t[19]=k^~I&O,t[28]=K^~L&U,t[29]=V^~q&B,t[38]=Z^~H&J,t[39]=tt^~W&G,t[48]=ct^~et&it,t[49]=ft^~rt&nt,t[0]^=c[i],t[1]^=c[i+1]};if(n)Oi.exports=_;else for(M=0;M{try{if("test"!=="test".normalize(e))throw new Error("bad normalize")}catch{t.push(e)}})),t.length)throw new Error("missing "+t.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(t){return t.message}return null}();var Bi,Di;!function(t){t.DEBUG="DEBUG",t.INFO="INFO",t.WARNING="WARNING",t.ERROR="ERROR",t.OFF="OFF"}(Bi||(Bi={})),function(t){t.UNKNOWN_ERROR="UNKNOWN_ERROR",t.NOT_IMPLEMENTED="NOT_IMPLEMENTED",t.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",t.NETWORK_ERROR="NETWORK_ERROR",t.SERVER_ERROR="SERVER_ERROR",t.TIMEOUT="TIMEOUT",t.BUFFER_OVERRUN="BUFFER_OVERRUN",t.NUMERIC_FAULT="NUMERIC_FAULT",t.MISSING_NEW="MISSING_NEW",t.INVALID_ARGUMENT="INVALID_ARGUMENT",t.MISSING_ARGUMENT="MISSING_ARGUMENT",t.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",t.CALL_EXCEPTION="CALL_EXCEPTION",t.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",t.NONCE_EXPIRED="NONCE_EXPIRED",t.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",t.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",t.TRANSACTION_REPLACED="TRANSACTION_REPLACED",t.ACTION_REJECTED="ACTION_REJECTED"}(Di||(Di={}));const zi="0123456789abcdef";class ji{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const r=t.toLowerCase();null==ki[r]&&this.throwArgumentError("invalid log level name","logLevel",t),!(Li>ki[r])&&console.log.apply(console,e)}debug(...t){this._log(ji.levels.DEBUG,t)}info(...t){this._log(ji.levels.INFO,t)}warn(...t){this._log(ji.levels.WARNING,t)}makeError(t,e,r){if(Ci)return this.makeError("censored error",e,{});e||(e=ji.errors.UNKNOWN_ERROR),r||(r={});const i=[];Object.keys(r).forEach((t=>{const e=r[t];try{if(e instanceof Uint8Array){let r="";for(let t=0;t>4],r+=zi[15&e[t]];i.push(t+"=Uint8Array(0x"+r+")")}else i.push(t+"="+JSON.stringify(e))}catch{i.push(t+"="+JSON.stringify(r[t].toString()))}})),i.push(`code=${e}`),i.push(`version=${this.version}`);const n=t;let s="";switch(e){case Di.NUMERIC_FAULT:{s="NUMERIC_FAULT";const e=t;switch(e){case"overflow":case"underflow":case"division-by-zero":s+="-"+e;break;case"negative-power":case"negative-width":s+="-unsupported";break;case"unbound-bitwise-result":s+="-unbound-result"}break}case Di.CALL_EXCEPTION:case Di.INSUFFICIENT_FUNDS:case Di.MISSING_NEW:case Di.NONCE_EXPIRED:case Di.REPLACEMENT_UNDERPRICED:case Di.TRANSACTION_REPLACED:case Di.UNPREDICTABLE_GAS_LIMIT:s=e}s&&(t+=" [ See: https://links.ethers.org/v5-errors-"+s+" ]"),i.length&&(t+=" ("+i.join(", ")+")");const o=new Error(t);return o.reason=n,o.code=e,Object.keys(r).forEach((function(t){o[t]=r[t]})),o}throwError(t,e,r){throw this.makeError(t,e,r)}throwArgumentError(t,e,r){return this.throwError(t,ji.errors.INVALID_ARGUMENT,{argument:e,value:r})}assert(t,e,r,i){t||this.throwError(e,r,i)}assertArgument(t,e,r,i){t||this.throwArgumentError(e,r,i)}checkNormalize(t){Ui&&this.throwError("platform missing String.prototype.normalize",ji.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:Ui})}checkSafeUint53(t,e){"number"==typeof t&&(null==e&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,ji.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,ji.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,r){r=r?": "+r:"",te&&this.throwError("too many arguments"+r,ji.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){(t===Object||null==t)&&this.throwError("missing new",ji.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",ji.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):(t===Object||null==t)&&this.throwError("missing new",ji.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return qi||(qi=new ji("logger/5.7.0")),qi}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",ji.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),Ti){if(!t)return;this.globalLogger().throwError("error censorship permanent",ji.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}Ci=!!t,Ti=!!e}static setLogLevel(t){const e=ki[t.toLowerCase()];null!=e?Li=e:ji.globalLogger().warn("invalid log level - "+t)}static from(t){return new ji(t)}}ji.errors=Di,ji.levels=Bi;const Fi=new ji("bytes/5.7.0");function Ki(t){return!!t.toHexString}function Vi(t){return t.slice||(t.slice=function(){const e=Array.prototype.slice.call(arguments);return Vi(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}function Hi(t){return"number"==typeof t&&t==t&&t%1==0}function Wi(t){if(null==t)return!1;if(t.constructor===Uint8Array)return!0;if("string"==typeof t||!Hi(t.length)||t.length<0)return!1;for(let e=0;e=256)return!1}return!0}function Ji(t,e){if(e||(e={}),"number"==typeof t){Fi.checkSafeUint53(t,"invalid arrayify value");const e=[];for(;t;)e.unshift(255&t),t=parseInt(String(t/256));return 0===e.length&&e.push(0),Vi(new Uint8Array(e))}if(e.allowMissingPrefix&&"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),Ki(t)&&(t=t.toHexString()),Gi(t)){let r=t.substring(2);r.length%2&&("left"===e.hexPad?r="0"+r:"right"===e.hexPad?r+="0":Fi.throwArgumentError("hex data is odd-length","value",t));const i=[];for(let t=0;t>4]+$i[15&i]}return e}return Fi.throwArgumentError("invalid hexlify value","value",t)}function Qi(t,e,r){return"string"!=typeof t?t=Yi(t):(!Gi(t)||t.length%2)&&Fi.throwArgumentError("invalid hexData","value",t),e=2+2*e,null!=r?"0x"+t.substring(e,2+2*r):"0x"+t.substring(e)}function Xi(t,e){for("string"!=typeof t?t=Yi(t):Gi(t)||Fi.throwArgumentError("invalid hex string","value",t),t.length>2*e+2&&Fi.throwArgumentError("value out of range","value",arguments[1]);t.length<2*e+2;)t="0x0"+t.substring(2);return t}function Zi(t){const e={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(function(t){return Gi(t)&&!(t.length%2)||Wi(t)}(t)){let r=Ji(t);64===r.length?(e.v=27+(r[32]>>7),r[32]&=127,e.r=Yi(r.slice(0,32)),e.s=Yi(r.slice(32,64))):65===r.length?(e.r=Yi(r.slice(0,32)),e.s=Yi(r.slice(32,64)),e.v=r[64]):Fi.throwArgumentError("invalid signature string","signature",t),e.v<27&&(0===e.v||1===e.v?e.v+=27:Fi.throwArgumentError("signature invalid v byte","signature",t)),e.recoveryParam=1-e.v%2,e.recoveryParam&&(r[32]|=128),e._vs=Yi(r.slice(32,64))}else{if(e.r=t.r,e.s=t.s,e.v=t.v,e.recoveryParam=t.recoveryParam,e._vs=t._vs,null!=e._vs){const r=function(t,e){(t=Ji(t)).length>e&&Fi.throwArgumentError("value out of range","value",arguments[0]);const r=new Uint8Array(e);return r.set(t,e-t.length),Vi(r)}(Ji(e._vs),32);e._vs=Yi(r);const i=r[0]>=128?1:0;null==e.recoveryParam?e.recoveryParam=i:e.recoveryParam!==i&&Fi.throwArgumentError("signature recoveryParam mismatch _vs","signature",t),r[0]&=127;const n=Yi(r);null==e.s?e.s=n:e.s!==n&&Fi.throwArgumentError("signature v mismatch _vs","signature",t)}if(null==e.recoveryParam)null==e.v?Fi.throwArgumentError("signature missing v and recoveryParam","signature",t):0===e.v||1===e.v?e.recoveryParam=e.v:e.recoveryParam=1-e.v%2;else if(null==e.v)e.v=27+e.recoveryParam;else{const r=0===e.v||1===e.v?e.v:1-e.v%2;e.recoveryParam!==r&&Fi.throwArgumentError("signature recoveryParam mismatch v","signature",t)}null!=e.r&&Gi(e.r)?e.r=Xi(e.r,32):Fi.throwArgumentError("signature missing or invalid r","signature",t),null!=e.s&&Gi(e.s)?e.s=Xi(e.s,32):Fi.throwArgumentError("signature missing or invalid s","signature",t);const r=Ji(e.s);r[0]>=128&&Fi.throwArgumentError("signature s out of range","signature",t),e.recoveryParam&&(r[0]|=128);const i=Yi(r);e._vs&&(Gi(e._vs)||Fi.throwArgumentError("signature invalid _vs","signature",t),e._vs=Xi(e._vs,32)),null==e._vs?e._vs=i:e._vs!==i&&Fi.throwArgumentError("signature _vs mismatch v and s","signature",t)}return e.yParityAndS=e._vs,e.compact=e.r+e.yParityAndS.substring(2),e}function tn(t){return"0x"+Ri.keccak_256(Ji(t))}var en={exports:{}},rn=function(t){var e=t.default;if("function"==typeof e){var r=function(){return e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})})),r}(Object.freeze({__proto__:null,default:{}}));!function(t,e){function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function n(t,e,r){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&(("le"===e||"be"===e)&&(r=e,e=10),this._init(t||0,e||10,r||"be"))}var s;"object"==typeof en?en.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=typeof window<"u"&&typeof window.Buffer<"u"?window.Buffer:rn.Buffer}catch{}function o(t,e){var i=t.charCodeAt(e);return i>=48&&i<=57?i-48:i>=65&&i<=70?i-55:i>=97&&i<=102?i-87:void r(!1,"Invalid character in "+t)}function a(t,e,r){var i=o(t,r);return r-1>=e&&(i|=o(t,r-1)<<4),i}function h(t,e,i,n){for(var s=0,o=0,a=Math.min(t.length,i),h=e;h=49?c-49+10:c>=17?c-17+10:c,r(c>=0&&o0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,i){if("number"==typeof t)return this._initNumber(t,e,i);if("object"==typeof t)return this._initArray(t,e,i);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===i)for(n=0,s=0;n>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},n.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i=e;i-=2)n=a(t,e,i)<=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;else for(i=(t.length-e)%2==0?e+1:e;i=18?(s-=18,o+=1,this.words[o]|=n>>>26):s+=8;this._strip()},n.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,c=0,f=r;f1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},typeof Symbol<"u"&&"function"==typeof Symbol.for)try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=f}catch{n.prototype.inspect=f}else n.prototype.inspect=f;function f(){return(this.red?""}var u=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],l=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function p(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,h=o/67108864|0;r.words[0]=a;for(var c=1;c>>26,u=67108863&h,d=Math.min(c,e.length-1),l=Math.max(0,c-t.length+1);l<=d;l++){var p=c-l|0;f+=(o=(n=0|t.words[p])*(s=0|e.words[l])+u)/67108864|0,u=67108863&o}r.words[c]=0|u,h=0|f}return 0!==h?r.words[c]=0|h:r.length--,r._strip()}n.prototype.toString=function(t,e){var i;if(e=0|e||1,16===(t=t||10)||"hex"===t){i="";for(var n=0,s=0,o=0;o>>24-n&16777215,(n+=2)>=26&&(n-=26,o--),i=0!==s||o!==this.length-1?u[6-h.length]+h+i:h+i}for(0!==s&&(i=s.toString(16)+i);i.length%e!=0;)i="0"+i;return 0!==this.negative&&(i="-"+i),i}if(t===(0|t)&&t>=2&&t<=36){var c=d[t],f=l[t];i="";var p=this.clone();for(p.negative=0;!p.isZero();){var g=p.modrn(f).toString(t);i=(p=p.idivn(f)).isZero()?g+i:u[c-g.length]+g+i}for(this.isZero()&&(i="0"+i);i.length%e!=0;)i="0"+i;return 0!==this.negative&&(i="-"+i),i}r(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16,2)},s&&(n.prototype.toBuffer=function(t,e){return this.toArrayLike(s,t,e)}),n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,i){this._strip();var n=this.byteLength(),s=i||Math.max(1,n);r(n<=s,"byte array longer than desired length"),r(s>0,"Requested array length <= 0");var o=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,s);return this["_toArrayLike"+("le"===e?"LE":"BE")](o,n),o},n.prototype._toArrayLikeLE=function(t,e){for(var r=0,i=0,n=0,s=0;n>8&255),r>16&255),6===s?(r>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r=0&&(t[r--]=o>>8&255),r>=0&&(t[r--]=o>>16&255),6===s?(r>=0&&(t[r--]=o>>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r>=0)for(t[r--]=i;r>=0;)t[r--]=0},Math.clz32?n.prototype._countBits=function(t){return 32-Math.clz32(t)}:n.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},n.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;rt.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;it.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),i=t%26;this._expand(e),i>0&&e--;for(var n=0;n0&&(this.words[n]=~this.words[n]&67108863>>26-i),this._strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){r("number"==typeof t&&t>=0);var i=t/26|0,n=t%26;return this._expand(i+1),this.words[i]=e?this.words[i]|1<t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s>>26;for(;0!==n&&s>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;st.length?this.clone().iadd(t):t.clone().iadd(this)},n.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o>26,this.words[o]=67108863&e;for(;0!==s&&o>26,this.words[o]=67108863&e;if(0===s&&o>>13,l=0|o[1],p=8191&l,g=l>>>13,m=0|o[2],b=8191&m,y=m>>>13,v=0|o[3],w=8191&v,_=v>>>13,A=0|o[4],M=8191&A,S=A>>>13,E=0|o[5],I=8191&E,x=E>>>13,O=0|o[6],N=8191&O,P=O>>>13,R=0|o[7],T=8191&R,C=R>>>13,k=0|o[8],L=8191&k,q=k>>>13,U=0|o[9],B=8191&U,D=U>>>13,z=0|a[0],j=8191&z,F=z>>>13,K=0|a[1],V=8191&K,H=K>>>13,W=0|a[2],J=8191&W,G=W>>>13,$=0|a[3],Y=8191&$,Q=$>>>13,X=0|a[4],Z=8191&X,tt=X>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ct=at>>>13,ft=0|a[8],ut=8191&ft,dt=ft>>>13,lt=0|a[9],pt=8191<,gt=lt>>>13;r.negative=t.negative^e.negative,r.length=19;var mt=(c+(i=Math.imul(u,j))|0)+((8191&(n=(n=Math.imul(u,F))+Math.imul(d,j)|0))<<13)|0;c=((s=Math.imul(d,F))+(n>>>13)|0)+(mt>>>26)|0,mt&=67108863,i=Math.imul(p,j),n=(n=Math.imul(p,F))+Math.imul(g,j)|0,s=Math.imul(g,F);var bt=(c+(i=i+Math.imul(u,V)|0)|0)+((8191&(n=(n=n+Math.imul(u,H)|0)+Math.imul(d,V)|0))<<13)|0;c=((s=s+Math.imul(d,H)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(b,j),n=(n=Math.imul(b,F))+Math.imul(y,j)|0,s=Math.imul(y,F),i=i+Math.imul(p,V)|0,n=(n=n+Math.imul(p,H)|0)+Math.imul(g,V)|0,s=s+Math.imul(g,H)|0;var yt=(c+(i=i+Math.imul(u,J)|0)|0)+((8191&(n=(n=n+Math.imul(u,G)|0)+Math.imul(d,J)|0))<<13)|0;c=((s=s+Math.imul(d,G)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(w,j),n=(n=Math.imul(w,F))+Math.imul(_,j)|0,s=Math.imul(_,F),i=i+Math.imul(b,V)|0,n=(n=n+Math.imul(b,H)|0)+Math.imul(y,V)|0,s=s+Math.imul(y,H)|0,i=i+Math.imul(p,J)|0,n=(n=n+Math.imul(p,G)|0)+Math.imul(g,J)|0,s=s+Math.imul(g,G)|0;var vt=(c+(i=i+Math.imul(u,Y)|0)|0)+((8191&(n=(n=n+Math.imul(u,Q)|0)+Math.imul(d,Y)|0))<<13)|0;c=((s=s+Math.imul(d,Q)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(M,j),n=(n=Math.imul(M,F))+Math.imul(S,j)|0,s=Math.imul(S,F),i=i+Math.imul(w,V)|0,n=(n=n+Math.imul(w,H)|0)+Math.imul(_,V)|0,s=s+Math.imul(_,H)|0,i=i+Math.imul(b,J)|0,n=(n=n+Math.imul(b,G)|0)+Math.imul(y,J)|0,s=s+Math.imul(y,G)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,Q)|0;var wt=(c+(i=i+Math.imul(u,Z)|0)|0)+((8191&(n=(n=n+Math.imul(u,tt)|0)+Math.imul(d,Z)|0))<<13)|0;c=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(I,j),n=(n=Math.imul(I,F))+Math.imul(x,j)|0,s=Math.imul(x,F),i=i+Math.imul(M,V)|0,n=(n=n+Math.imul(M,H)|0)+Math.imul(S,V)|0,s=s+Math.imul(S,H)|0,i=i+Math.imul(w,J)|0,n=(n=n+Math.imul(w,G)|0)+Math.imul(_,J)|0,s=s+Math.imul(_,G)|0,i=i+Math.imul(b,Y)|0,n=(n=n+Math.imul(b,Q)|0)+Math.imul(y,Y)|0,s=s+Math.imul(y,Q)|0,i=i+Math.imul(p,Z)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,tt)|0;var _t=(c+(i=i+Math.imul(u,rt)|0)|0)+((8191&(n=(n=n+Math.imul(u,it)|0)+Math.imul(d,rt)|0))<<13)|0;c=((s=s+Math.imul(d,it)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(N,j),n=(n=Math.imul(N,F))+Math.imul(P,j)|0,s=Math.imul(P,F),i=i+Math.imul(I,V)|0,n=(n=n+Math.imul(I,H)|0)+Math.imul(x,V)|0,s=s+Math.imul(x,H)|0,i=i+Math.imul(M,J)|0,n=(n=n+Math.imul(M,G)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,G)|0,i=i+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,Q)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,Q)|0,i=i+Math.imul(b,Z)|0,n=(n=n+Math.imul(b,tt)|0)+Math.imul(y,Z)|0,s=s+Math.imul(y,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(g,rt)|0,s=s+Math.imul(g,it)|0;var At=(c+(i=i+Math.imul(u,st)|0)|0)+((8191&(n=(n=n+Math.imul(u,ot)|0)+Math.imul(d,st)|0))<<13)|0;c=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(T,j),n=(n=Math.imul(T,F))+Math.imul(C,j)|0,s=Math.imul(C,F),i=i+Math.imul(N,V)|0,n=(n=n+Math.imul(N,H)|0)+Math.imul(P,V)|0,s=s+Math.imul(P,H)|0,i=i+Math.imul(I,J)|0,n=(n=n+Math.imul(I,G)|0)+Math.imul(x,J)|0,s=s+Math.imul(x,G)|0,i=i+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,Q)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,Q)|0,i=i+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,tt)|0,i=i+Math.imul(b,rt)|0,n=(n=n+Math.imul(b,it)|0)+Math.imul(y,rt)|0,s=s+Math.imul(y,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var Mt=(c+(i=i+Math.imul(u,ht)|0)|0)+((8191&(n=(n=n+Math.imul(u,ct)|0)+Math.imul(d,ht)|0))<<13)|0;c=((s=s+Math.imul(d,ct)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(L,j),n=(n=Math.imul(L,F))+Math.imul(q,j)|0,s=Math.imul(q,F),i=i+Math.imul(T,V)|0,n=(n=n+Math.imul(T,H)|0)+Math.imul(C,V)|0,s=s+Math.imul(C,H)|0,i=i+Math.imul(N,J)|0,n=(n=n+Math.imul(N,G)|0)+Math.imul(P,J)|0,s=s+Math.imul(P,G)|0,i=i+Math.imul(I,Y)|0,n=(n=n+Math.imul(I,Q)|0)+Math.imul(x,Y)|0,s=s+Math.imul(x,Q)|0,i=i+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(S,Z)|0,s=s+Math.imul(S,tt)|0,i=i+Math.imul(w,rt)|0,n=(n=n+Math.imul(w,it)|0)+Math.imul(_,rt)|0,s=s+Math.imul(_,it)|0,i=i+Math.imul(b,st)|0,n=(n=n+Math.imul(b,ot)|0)+Math.imul(y,st)|0,s=s+Math.imul(y,ot)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ct)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ct)|0;var St=(c+(i=i+Math.imul(u,ut)|0)|0)+((8191&(n=(n=n+Math.imul(u,dt)|0)+Math.imul(d,ut)|0))<<13)|0;c=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(B,j),n=(n=Math.imul(B,F))+Math.imul(D,j)|0,s=Math.imul(D,F),i=i+Math.imul(L,V)|0,n=(n=n+Math.imul(L,H)|0)+Math.imul(q,V)|0,s=s+Math.imul(q,H)|0,i=i+Math.imul(T,J)|0,n=(n=n+Math.imul(T,G)|0)+Math.imul(C,J)|0,s=s+Math.imul(C,G)|0,i=i+Math.imul(N,Y)|0,n=(n=n+Math.imul(N,Q)|0)+Math.imul(P,Y)|0,s=s+Math.imul(P,Q)|0,i=i+Math.imul(I,Z)|0,n=(n=n+Math.imul(I,tt)|0)+Math.imul(x,Z)|0,s=s+Math.imul(x,tt)|0,i=i+Math.imul(M,rt)|0,n=(n=n+Math.imul(M,it)|0)+Math.imul(S,rt)|0,s=s+Math.imul(S,it)|0,i=i+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,i=i+Math.imul(b,ht)|0,n=(n=n+Math.imul(b,ct)|0)+Math.imul(y,ht)|0,s=s+Math.imul(y,ct)|0,i=i+Math.imul(p,ut)|0,n=(n=n+Math.imul(p,dt)|0)+Math.imul(g,ut)|0,s=s+Math.imul(g,dt)|0;var Et=(c+(i=i+Math.imul(u,pt)|0)|0)+((8191&(n=(n=n+Math.imul(u,gt)|0)+Math.imul(d,pt)|0))<<13)|0;c=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(B,V),n=(n=Math.imul(B,H))+Math.imul(D,V)|0,s=Math.imul(D,H),i=i+Math.imul(L,J)|0,n=(n=n+Math.imul(L,G)|0)+Math.imul(q,J)|0,s=s+Math.imul(q,G)|0,i=i+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,Q)|0)+Math.imul(C,Y)|0,s=s+Math.imul(C,Q)|0,i=i+Math.imul(N,Z)|0,n=(n=n+Math.imul(N,tt)|0)+Math.imul(P,Z)|0,s=s+Math.imul(P,tt)|0,i=i+Math.imul(I,rt)|0,n=(n=n+Math.imul(I,it)|0)+Math.imul(x,rt)|0,s=s+Math.imul(x,it)|0,i=i+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(S,st)|0,s=s+Math.imul(S,ot)|0,i=i+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ct)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ct)|0,i=i+Math.imul(b,ut)|0,n=(n=n+Math.imul(b,dt)|0)+Math.imul(y,ut)|0,s=s+Math.imul(y,dt)|0;var It=(c+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;c=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(B,J),n=(n=Math.imul(B,G))+Math.imul(D,J)|0,s=Math.imul(D,G),i=i+Math.imul(L,Y)|0,n=(n=n+Math.imul(L,Q)|0)+Math.imul(q,Y)|0,s=s+Math.imul(q,Q)|0,i=i+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(C,Z)|0,s=s+Math.imul(C,tt)|0,i=i+Math.imul(N,rt)|0,n=(n=n+Math.imul(N,it)|0)+Math.imul(P,rt)|0,s=s+Math.imul(P,it)|0,i=i+Math.imul(I,st)|0,n=(n=n+Math.imul(I,ot)|0)+Math.imul(x,st)|0,s=s+Math.imul(x,ot)|0,i=i+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ct)|0)+Math.imul(S,ht)|0,s=s+Math.imul(S,ct)|0,i=i+Math.imul(w,ut)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(_,ut)|0,s=s+Math.imul(_,dt)|0;var xt=(c+(i=i+Math.imul(b,pt)|0)|0)+((8191&(n=(n=n+Math.imul(b,gt)|0)+Math.imul(y,pt)|0))<<13)|0;c=((s=s+Math.imul(y,gt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(B,Y),n=(n=Math.imul(B,Q))+Math.imul(D,Y)|0,s=Math.imul(D,Q),i=i+Math.imul(L,Z)|0,n=(n=n+Math.imul(L,tt)|0)+Math.imul(q,Z)|0,s=s+Math.imul(q,tt)|0,i=i+Math.imul(T,rt)|0,n=(n=n+Math.imul(T,it)|0)+Math.imul(C,rt)|0,s=s+Math.imul(C,it)|0,i=i+Math.imul(N,st)|0,n=(n=n+Math.imul(N,ot)|0)+Math.imul(P,st)|0,s=s+Math.imul(P,ot)|0,i=i+Math.imul(I,ht)|0,n=(n=n+Math.imul(I,ct)|0)+Math.imul(x,ht)|0,s=s+Math.imul(x,ct)|0,i=i+Math.imul(M,ut)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(S,ut)|0,s=s+Math.imul(S,dt)|0;var Ot=(c+(i=i+Math.imul(w,pt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(_,pt)|0))<<13)|0;c=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,i=Math.imul(B,Z),n=(n=Math.imul(B,tt))+Math.imul(D,Z)|0,s=Math.imul(D,tt),i=i+Math.imul(L,rt)|0,n=(n=n+Math.imul(L,it)|0)+Math.imul(q,rt)|0,s=s+Math.imul(q,it)|0,i=i+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(C,st)|0,s=s+Math.imul(C,ot)|0,i=i+Math.imul(N,ht)|0,n=(n=n+Math.imul(N,ct)|0)+Math.imul(P,ht)|0,s=s+Math.imul(P,ct)|0,i=i+Math.imul(I,ut)|0,n=(n=n+Math.imul(I,dt)|0)+Math.imul(x,ut)|0,s=s+Math.imul(x,dt)|0;var Nt=(c+(i=i+Math.imul(M,pt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(S,pt)|0))<<13)|0;c=((s=s+Math.imul(S,gt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,i=Math.imul(B,rt),n=(n=Math.imul(B,it))+Math.imul(D,rt)|0,s=Math.imul(D,it),i=i+Math.imul(L,st)|0,n=(n=n+Math.imul(L,ot)|0)+Math.imul(q,st)|0,s=s+Math.imul(q,ot)|0,i=i+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ct)|0)+Math.imul(C,ht)|0,s=s+Math.imul(C,ct)|0,i=i+Math.imul(N,ut)|0,n=(n=n+Math.imul(N,dt)|0)+Math.imul(P,ut)|0,s=s+Math.imul(P,dt)|0;var Pt=(c+(i=i+Math.imul(I,pt)|0)|0)+((8191&(n=(n=n+Math.imul(I,gt)|0)+Math.imul(x,pt)|0))<<13)|0;c=((s=s+Math.imul(x,gt)|0)+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(B,st),n=(n=Math.imul(B,ot))+Math.imul(D,st)|0,s=Math.imul(D,ot),i=i+Math.imul(L,ht)|0,n=(n=n+Math.imul(L,ct)|0)+Math.imul(q,ht)|0,s=s+Math.imul(q,ct)|0,i=i+Math.imul(T,ut)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(C,ut)|0,s=s+Math.imul(C,dt)|0;var Rt=(c+(i=i+Math.imul(N,pt)|0)|0)+((8191&(n=(n=n+Math.imul(N,gt)|0)+Math.imul(P,pt)|0))<<13)|0;c=((s=s+Math.imul(P,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(B,ht),n=(n=Math.imul(B,ct))+Math.imul(D,ht)|0,s=Math.imul(D,ct),i=i+Math.imul(L,ut)|0,n=(n=n+Math.imul(L,dt)|0)+Math.imul(q,ut)|0,s=s+Math.imul(q,dt)|0;var Tt=(c+(i=i+Math.imul(T,pt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(C,pt)|0))<<13)|0;c=((s=s+Math.imul(C,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,i=Math.imul(B,ut),n=(n=Math.imul(B,dt))+Math.imul(D,ut)|0,s=Math.imul(D,dt);var Ct=(c+(i=i+Math.imul(L,pt)|0)|0)+((8191&(n=(n=n+Math.imul(L,gt)|0)+Math.imul(q,pt)|0))<<13)|0;c=((s=s+Math.imul(q,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863;var kt=(c+(i=Math.imul(B,pt))|0)+((8191&(n=(n=Math.imul(B,gt))+Math.imul(D,pt)|0))<<13)|0;return c=((s=Math.imul(D,gt))+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h[0]=mt,h[1]=bt,h[2]=yt,h[3]=vt,h[4]=wt,h[5]=_t,h[6]=At,h[7]=Mt,h[8]=St,h[9]=Et,h[10]=It,h[11]=xt,h[12]=Ot,h[13]=Nt,h[14]=Pt,h[15]=Rt,h[16]=Tt,h[17]=Ct,h[18]=kt,0!==c&&(h[19]=c,r.length++),r};function m(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,s=0;s>>26)|0)>>>26,o&=67108863}r.words[s]=a,i=o,o=n}return 0!==i?r.words[s]=i:r.length--,r._strip()}function b(t,e,r){return m(t,e,r)}Math.imul||(g=p),n.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?p(this,t,e):r<1024?m(this,t,e):b(this,t,e)},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),b(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){var e=t<0;e&&(t=-t),r("number"==typeof t),r(t<67108864);for(var i=0,n=0;n>=26,i+=s/67108864|0,i+=o>>>26,this.words[n]=67108863&o}return 0!==i&&(this.words[n]=i,this.length++),e?this.ineg():this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r>>n&1}return e}(t);if(0===e.length)return new n(1);for(var r=this,i=0;i=0);var e,i=t%26,n=(t-i)/26,s=67108863>>>26-i<<26-i;if(0!==i){var o=0;for(e=0;e>>26-i}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<o)for(this.length-=o,c=0;c=0&&(0!==f||c>=n);c--){var u=0|this.words[c];this.words[c]=f<<26-s|u>>>s,f=u&a}return h&&0!==f&&(h.words[h.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(t,e,i){return r(0===this.negative),this.iushrn(t,e,i)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){r("number"==typeof t&&t>=0);var e=t%26,i=(t-e)/26,n=1<=0);var e=t%26,i=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=i)return this;if(0!==e&&i++,this.length=Math.min(i,this.length),0!==e){var n=67108863^67108863>>>e<=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},n.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e>26)-(h/67108864|0),this.words[n+i]=67108863&o}for(;n>26,this.words[n+i]=67108863&o;if(0===a)return this._strip();for(r(-1===a),a=0,n=0;n>26,this.words[n]=67108863&o;return this.negative=1,this._strip()},n.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),s=t,o=0|s.words[s.length-1];0!=(r=26-this._countBits(o))&&(s=s.ushln(r),i.iushln(r),o=0|s.words[s.length-1]);var a,h=i.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var c=0;c=0;u--){var d=67108864*(0|i.words[s.length+u])+(0|i.words[s.length+u-1]);for(d=Math.min(d/o|0,67108863),i._ishlnsubmul(s,d,u);0!==i.negative;)d--,i.negative=0,i._ishlnsubmul(s,1,u),i.isZero()||(i.negative^=1);a&&(a.words[u]=d)}return a&&a._strip(),i._strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:a||null,mod:i}},n.prototype.divmod=function(t,e,i){return r(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),i&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):this.negative&t.negative?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),i&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modrn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),s=r.cmp(i);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modrn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var i=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(i*n+(0|this.words[s]))%t;return e?-n:n},n.prototype.modn=function(t){return this.modrn(t)},n.prototype.idivn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var s=(0|this.words[n])+67108864*i;this.words[n]=s/t|0,i=s%t}return this._strip(),e?this.ineg():this},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,i=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),c=0;e.isEven()&&i.isEven();)e.iushrn(1),i.iushrn(1),++c;for(var f=i.clone(),u=e.clone();!e.isZero();){for(var d=0,l=1;!(e.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(f),o.isub(u)),s.iushrn(1),o.iushrn(1);for(var p=0,g=1;!(i.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(i.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(f),h.isub(u)),a.iushrn(1),h.iushrn(1);e.cmp(i)>=0?(e.isub(i),s.isub(a),o.isub(h)):(i.isub(e),a.isub(s),h.isub(o))}return{a,b:h,gcd:i.iushln(c)}},n.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e,i=this,s=t.clone();i=0!==i.negative?i.umod(t):i.clone();for(var o=new n(1),a=new n(0),h=s.clone();i.cmpn(1)>0&&s.cmpn(1)>0;){for(var c=0,f=1;!(i.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(i.iushrn(c);c-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var u=0,d=1;!(s.words[0]&d)&&u<26;++u,d<<=1);if(u>0)for(s.iushrn(u);u-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);i.cmp(s)>=0?(i.isub(s),o.isub(a)):(s.isub(i),a.isub(o))}return(e=0===i.cmpn(1)?o:a).cmpn(0)<0&&e.iadd(t),e},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var s=e;e=r,r=s}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return!(1&this.words[0])},n.prototype.isOdd=function(){return!(1&~this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){r("number"==typeof t);var e=t%26,i=(t-e)/26,n=1<>>26,a&=67108863,this.words[o]=a}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,i=t<0;if(0!==this.negative&&!i)return-1;if(0===this.negative&&i)return 1;if(this._strip(),this.length>1)e=1;else{i&&(t=-t),r(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:nt.length)return 1;if(this.length=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){in&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new S(t)},n.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function _(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function S(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function E(t){S.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},i(w,v),w.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n>>22,s=o}s>>>=22,t.words[n-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(y[t])return y[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new _;else if("p192"===t)e=new A;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return y[t]=e,e},S.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},S.prototype._verify2=function(t,e){r(!(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},S.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(c(t,t.umod(this.m)._forceRed(this)),t)},S.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},S.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},S.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},S.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},S.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},S.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},S.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},S.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},S.prototype.isqr=function(t){return this.imul(t,t.clone())},S.prototype.sqr=function(t){return this.mul(t,t)},S.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var i=this.m.add(new n(1)).iushrn(2);return this.pow(t,i)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);r(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),c=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new n(2*f*f).toRed(this);0!==this.pow(f,c).cmp(h);)f.redIAdd(h);for(var u=this.pow(f,s),d=this.pow(t,s.addn(1).iushrn(1)),l=this.pow(t,s),p=o;0!==l.cmp(a);){for(var g=l,m=0;0!==g.cmp(a);m++)g=g.redSqr();r(m=0;i--){for(var c=e.words[i],f=h-1;f>=0;f--){var u=c>>f&1;s!==r[0]&&(s=this.sqr(s)),0!==u||0!==o?(o<<=1,o|=u,(4==++a||0===i&&0===f)&&(s=this.mul(s,r[o]),a=0,o=0)):a=0}h=26}return s},S.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},S.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new E(t)},i(E,S),E.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},E.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},E.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},E.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var r=t.mul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(i).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},E.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,Ni);var nn=en.exports;const sn="bignumber/5.7.0";var on=nn.BN;const an=new ji(sn),hn={},cn=9007199254740991;let fn=!1;class un{constructor(t,e){t!==hn&&an.throwError("cannot call constructor directly; use BigNumber.from",ji.errors.UNSUPPORTED_OPERATION,{operation:"new (BigNumber)"}),this._hex=e,this._isBigNumber=!0,Object.freeze(this)}fromTwos(t){return ln(pn(this).fromTwos(t))}toTwos(t){return ln(pn(this).toTwos(t))}abs(){return"-"===this._hex[0]?un.from(this._hex.substring(1)):this}add(t){return ln(pn(this).add(pn(t)))}sub(t){return ln(pn(this).sub(pn(t)))}div(t){return un.from(t).isZero()&&gn("division-by-zero","div"),ln(pn(this).div(pn(t)))}mul(t){return ln(pn(this).mul(pn(t)))}mod(t){const e=pn(t);return e.isNeg()&&gn("division-by-zero","mod"),ln(pn(this).umod(e))}pow(t){const e=pn(t);return e.isNeg()&&gn("negative-power","pow"),ln(pn(this).pow(e))}and(t){const e=pn(t);return(this.isNegative()||e.isNeg())&&gn("unbound-bitwise-result","and"),ln(pn(this).and(e))}or(t){const e=pn(t);return(this.isNegative()||e.isNeg())&&gn("unbound-bitwise-result","or"),ln(pn(this).or(e))}xor(t){const e=pn(t);return(this.isNegative()||e.isNeg())&&gn("unbound-bitwise-result","xor"),ln(pn(this).xor(e))}mask(t){return(this.isNegative()||t<0)&&gn("negative-width","mask"),ln(pn(this).maskn(t))}shl(t){return(this.isNegative()||t<0)&&gn("negative-width","shl"),ln(pn(this).shln(t))}shr(t){return(this.isNegative()||t<0)&&gn("negative-width","shr"),ln(pn(this).shrn(t))}eq(t){return pn(this).eq(pn(t))}lt(t){return pn(this).lt(pn(t))}lte(t){return pn(this).lte(pn(t))}gt(t){return pn(this).gt(pn(t))}gte(t){return pn(this).gte(pn(t))}isNegative(){return"-"===this._hex[0]}isZero(){return pn(this).isZero()}toNumber(){try{return pn(this).toNumber()}catch{gn("overflow","toNumber",this.toString())}return null}toBigInt(){try{return BigInt(this.toString())}catch{}return an.throwError("this platform does not support BigInt",ji.errors.UNSUPPORTED_OPERATION,{value:this.toString()})}toString(){return arguments.length>0&&(10===arguments[0]?fn||(fn=!0,an.warn("BigNumber.toString does not accept any parameters; base-10 is assumed")):16===arguments[0]?an.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()",ji.errors.UNEXPECTED_ARGUMENT,{}):an.throwError("BigNumber.toString does not accept parameters",ji.errors.UNEXPECTED_ARGUMENT,{})),pn(this).toString(10)}toHexString(){return this._hex}toJSON(t){return{type:"BigNumber",hex:this.toHexString()}}static from(t){if(t instanceof un)return t;if("string"==typeof t)return t.match(/^-?0x[0-9a-f]+$/i)?new un(hn,dn(t)):t.match(/^-?[0-9]+$/)?new un(hn,dn(new on(t))):an.throwArgumentError("invalid BigNumber string","value",t);if("number"==typeof t)return t%1&&gn("underflow","BigNumber.from",t),(t>=cn||t<=-cn)&&gn("overflow","BigNumber.from",t),un.from(String(t));const e=t;if("bigint"==typeof e)return un.from(e.toString());if(Wi(e))return un.from(Yi(e));if(e)if(e.toHexString){const t=e.toHexString();if("string"==typeof t)return un.from(t)}else{let t=e._hex;if(null==t&&"BigNumber"===e.type&&(t=e.hex),"string"==typeof t&&(Gi(t)||"-"===t[0]&&Gi(t.substring(1))))return un.from(t)}return an.throwArgumentError("invalid BigNumber value","value",t)}static isBigNumber(t){return!(!t||!t._isBigNumber)}}function dn(t){if("string"!=typeof t)return dn(t.toString(16));if("-"===t[0])return"-"===(t=t.substring(1))[0]&&an.throwArgumentError("invalid hex","value",t),"0x00"===(t=dn(t))?t:"-"+t;if("0x"!==t.substring(0,2)&&(t="0x"+t),"0x"===t)return"0x00";for(t.length%2&&(t="0x0"+t.substring(2));t.length>4&&"0x00"===t.substring(0,4);)t="0x"+t.substring(4);return t}function ln(t){return un.from(dn(t))}function pn(t){const e=un.from(t).toHexString();return"-"===e[0]?new on("-"+e.substring(3),16):new on(e.substring(2),16)}function gn(t,e,r){const i={fault:t,operation:e};return null!=r&&(i.value=r),an.throwError(t,ji.errors.NUMERIC_FAULT,i)}const mn=new ji(sn),bn={},yn=un.from(0),vn=un.from(-1);function wn(t,e,r,i){const n={fault:e,operation:r};return void 0!==i&&(n.value=i),mn.throwError(t,ji.errors.NUMERIC_FAULT,n)}let _n="0";for(;_n.length<256;)_n+=_n;function An(t){if("number"!=typeof t)try{t=un.from(t).toNumber()}catch{}return"number"==typeof t&&t>=0&&t<=256&&!(t%1)?"1"+_n.substring(0,t):mn.throwArgumentError("invalid decimal size","decimals",t)}function Mn(t,e){null==e&&(e=0);const r=An(e),i=(t=un.from(t)).lt(yn);i&&(t=t.mul(vn));let n=t.mod(r).toString();for(;n.length2&&mn.throwArgumentError("too many decimal points","value",t);let s=n[0],o=n[1];for(s||(s="0"),o||(o="0");"0"===o[o.length-1];)o=o.substring(0,o.length-1);for(o.length>r.length-1&&wn("fractional component exceeds decimals","underflow","parseFixed"),""===o&&(o="0");o.lengthnull==t[e]?i:(typeof t[e]!==r&&mn.throwArgumentError("invalid fixed format ("+e+" not "+r+")","format."+e,t[e]),t[e]);e=n("signed","boolean",e),r=n("width","number",r),i=n("decimals","number",i)}return r%8&&mn.throwArgumentError("invalid fixed format width (not byte aligned)","format.width",r),i>80&&mn.throwArgumentError("invalid fixed format (decimals too large)","format.decimals",i),new En(bn,e,r,i)}}class In{constructor(t,e,r,i){t!==bn&&mn.throwError("cannot use FixedNumber constructor; use FixedNumber.from",ji.errors.UNSUPPORTED_OPERATION,{operation:"new FixedFormat"}),this.format=i,this._hex=e,this._value=r,this._isFixedNumber=!0,Object.freeze(this)}_checkFormat(t){this.format.name!==t.format.name&&mn.throwArgumentError("incompatible format; use fixedNumber.toFormat","other",t)}addUnsafe(t){this._checkFormat(t);const e=Sn(this._value,this.format.decimals),r=Sn(t._value,t.format.decimals);return In.fromValue(e.add(r),this.format.decimals,this.format)}subUnsafe(t){this._checkFormat(t);const e=Sn(this._value,this.format.decimals),r=Sn(t._value,t.format.decimals);return In.fromValue(e.sub(r),this.format.decimals,this.format)}mulUnsafe(t){this._checkFormat(t);const e=Sn(this._value,this.format.decimals),r=Sn(t._value,t.format.decimals);return In.fromValue(e.mul(r).div(this.format._multiplier),this.format.decimals,this.format)}divUnsafe(t){this._checkFormat(t);const e=Sn(this._value,this.format.decimals),r=Sn(t._value,t.format.decimals);return In.fromValue(e.mul(this.format._multiplier).div(r),this.format.decimals,this.format)}floor(){const t=this.toString().split(".");1===t.length&&t.push("0");let e=In.from(t[0],this.format);const r=!t[1].match(/^(0*)$/);return this.isNegative()&&r&&(e=e.subUnsafe(xn.toFormat(e.format))),e}ceiling(){const t=this.toString().split(".");1===t.length&&t.push("0");let e=In.from(t[0],this.format);const r=!t[1].match(/^(0*)$/);return!this.isNegative()&&r&&(e=e.addUnsafe(xn.toFormat(e.format))),e}round(t){null==t&&(t=0);const e=this.toString().split(".");if(1===e.length&&e.push("0"),(t<0||t>80||t%1)&&mn.throwArgumentError("invalid decimal count","decimals",t),e[1].length<=t)return this;const r=In.from("1"+_n.substring(0,t),this.format),i=On.toFormat(this.format);return this.mulUnsafe(r).addUnsafe(i).floor().divUnsafe(r)}isZero(){return"0.0"===this._value||"0"===this._value}isNegative(){return"-"===this._value[0]}toString(){return this._value}toHexString(t){return null==t?this._hex:(t%8&&mn.throwArgumentError("invalid byte width","width",t),Xi(un.from(this._hex).fromTwos(this.format.width).toTwos(t).toHexString(),t/8))}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(t){return In.fromString(this._value,t)}static fromValue(t,e,r){return null==r&&null!=e&&!function(t){return null!=t&&(un.isBigNumber(t)||"number"==typeof t&&t%1==0||"string"==typeof t&&!!t.match(/^-?[0-9]+$/)||Gi(t)||"bigint"==typeof t||Wi(t))}(e)&&(r=e,e=null),null==e&&(e=0),null==r&&(r="fixed"),In.fromString(Mn(t,e),En.from(r))}static fromString(t,e){null==e&&(e="fixed");const r=En.from(e),i=Sn(t,r.decimals);!r.signed&&i.lt(yn)&&wn("unsigned value cannot be negative","overflow","value",t);let n=null;r.signed?n=i.toTwos(r.width).toHexString():(n=i.toHexString(),n=Xi(n,r.width/8));const s=Mn(i,r.decimals);return new In(bn,n,s,r)}static fromBytes(t,e){null==e&&(e="fixed");const r=En.from(e);if(Ji(t).length>r.width/8)throw new Error("overflow");let i=un.from(t);r.signed&&(i=i.fromTwos(r.width));const n=i.toTwos((r.signed?0:1)+r.width).toHexString(),s=Mn(i,r.decimals);return new In(bn,n,s,r)}static from(t,e){if("string"==typeof t)return In.fromString(t,e);if(Wi(t))return In.fromBytes(t,e);try{return In.fromValue(t,0,e)}catch(t){if(t.code!==ji.errors.INVALID_ARGUMENT)throw t}return mn.throwArgumentError("invalid FixedNumber value","value",t)}static isFixedNumber(t){return!(!t||!t._isFixedNumber)}}const xn=In.from(1),On=In.from("0.5"),Nn=new ji("strings/5.7.0");var Pn,Rn;function Tn(t,e,r,i,n){if(t===Rn.BAD_PREFIX||t===Rn.UNEXPECTED_CONTINUE){let t=0;for(let i=e+1;i>6==2;i++)t++;return t}return t===Rn.OVERRUN?r.length-e-1:0}function Cn(t,e=Pn.current){e!=Pn.current&&(Nn.checkNormalize(),t=t.normalize(e));let r=[];for(let e=0;e>6|192),r.push(63&i|128);else if(55296==(64512&i)){e++;const n=t.charCodeAt(e);if(e>=t.length||56320!=(64512&n))throw new Error("invalid utf-8 string");const s=65536+((1023&i)<<10)+(1023&n);r.push(s>>18|240),r.push(s>>12&63|128),r.push(s>>6&63|128),r.push(63&s|128)}else r.push(i>>12|224),r.push(i>>6&63|128),r.push(63&i|128)}return Ji(r)}function kn(t,e){e||(e=function(t){return[parseInt(t,16)]});let r=0,i={};return t.split(",").forEach((t=>{let n=t.split(":");r+=parseInt(n[0],16),i[r]=e(n[1])})),i}function Ln(t){let e=0;return t.split(",").map((t=>{let r=t.split("-");1===r.length?r[1]="0":""===r[1]&&(r[1]="1");let i=e+parseInt(r[0],16);return e=parseInt(r[1],16),{l:i,h:e}}))}!function(t){t.current="",t.NFC="NFC",t.NFD="NFD",t.NFKC="NFKC",t.NFKD="NFKD"}(Pn||(Pn={})),function(t){t.UNEXPECTED_CONTINUE="unexpected continuation byte",t.BAD_PREFIX="bad codepoint prefix",t.OVERRUN="string overrun",t.MISSING_CONTINUE="missing continuation byte",t.OUT_OF_RANGE="out of UTF-8 range",t.UTF16_SURROGATE="UTF-16 surrogate",t.OVERLONG="overlong representation"}(Rn||(Rn={})),Object.freeze({error:function(t,e,r,i,n){return Nn.throwArgumentError(`invalid codepoint at offset ${e}; ${t}`,"bytes",r)},ignore:Tn,replace:function(t,e,r,i,n){return t===Rn.OVERLONG?(i.push(n),0):(i.push(65533),Tn(t,e,r))}}),Ln("221,13-1b,5f-,40-10,51-f,11-3,3-3,2-2,2-4,8,2,15,2d,28-8,88,48,27-,3-5,11-20,27-,8,28,3-5,12,18,b-a,1c-4,6-16,2-d,2-2,2,1b-4,17-9,8f-,10,f,1f-2,1c-34,33-14e,4,36-,13-,6-2,1a-f,4,9-,3-,17,8,2-2,5-,2,8-,3-,4-8,2-3,3,6-,16-6,2-,7-3,3-,17,8,3,3,3-,2,6-3,3-,4-a,5,2-6,10-b,4,8,2,4,17,8,3,6-,b,4,4-,2-e,2-4,b-10,4,9-,3-,17,8,3-,5-,9-2,3-,4-7,3-3,3,4-3,c-10,3,7-2,4,5-2,3,2,3-2,3-2,4-2,9,4-3,6-2,4,5-8,2-e,d-d,4,9,4,18,b,6-3,8,4,5-6,3-8,3-3,b-11,3,9,4,18,b,6-3,8,4,5-6,3-6,2,3-3,b-11,3,9,4,18,11-3,7-,4,5-8,2-7,3-3,b-11,3,13-2,19,a,2-,8-2,2-3,7,2,9-11,4-b,3b-3,1e-24,3,2-,3,2-,2-5,5,8,4,2,2-,3,e,4-,6,2,7-,b-,3-21,49,23-5,1c-3,9,25,10-,2-2f,23,6,3,8-2,5-5,1b-45,27-9,2a-,2-3,5b-4,45-4,53-5,8,40,2,5-,8,2,5-,28,2,5-,20,2,5-,8,2,5-,8,8,18,20,2,5-,8,28,14-5,1d-22,56-b,277-8,1e-2,52-e,e,8-a,18-8,15-b,e,4,3-b,5e-2,b-15,10,b-5,59-7,2b-555,9d-3,5b-5,17-,7-,27-,7-,9,2,2,2,20-,36,10,f-,7,14-,4,a,54-3,2-6,6-5,9-,1c-10,13-1d,1c-14,3c-,10-6,32-b,240-30,28-18,c-14,a0,115-,3,66-,b-76,5,5-,1d,24,2,5-2,2,8-,35-2,19,f-10,1d-3,311-37f,1b,5a-b,d7-19,d-3,41,57-,68-4,29-3,5f,29-37,2e-2,25-c,2c-2,4e-3,30,78-3,64-,20,19b7-49,51a7-59,48e-2,38-738,2ba5-5b,222f-,3c-94,8-b,6-4,1b,6,2,3,3,6d-20,16e-f,41-,37-7,2e-2,11-f,5-b,18-,b,14,5-3,6,88-,2,bf-2,7-,7-,7-,4-2,8,8-9,8-2ff,20,5-b,1c-b4,27-,27-cbb1,f7-9,28-2,b5-221,56,48,3-,2-,3-,5,d,2,5,3,42,5-,9,8,1d,5,6,2-2,8,153-3,123-3,33-27fd,a6da-5128,21f-5df,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3,2-1d,61-ff7d"),"ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff".split(",").map((t=>parseInt(t,16))),kn("b5:3bc,c3:ff,7:73,2:253,5:254,3:256,1:257,5:259,1:25b,3:260,1:263,2:269,1:268,5:26f,1:272,2:275,7:280,3:283,5:288,3:28a,1:28b,5:292,3f:195,1:1bf,29:19e,125:3b9,8b:3b2,1:3b8,1:3c5,3:3c6,1:3c0,1a:3ba,1:3c1,1:3c3,2:3b8,1:3b5,1bc9:3b9,1c:1f76,1:1f77,f:1f7a,1:1f7b,d:1f78,1:1f79,1:1f7c,1:1f7d,107:63,5:25b,4:68,1:68,1:68,3:69,1:69,1:6c,3:6e,4:70,1:71,1:72,1:72,1:72,7:7a,2:3c9,2:7a,2:6b,1:e5,1:62,1:63,3:65,1:66,2:6d,b:3b3,1:3c0,6:64,1b574:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3"),kn("179:1,2:1,2:1,5:1,2:1,a:4f,a:1,8:1,2:1,2:1,3:1,5:1,3:1,4:1,2:1,3:1,4:1,8:2,1:1,2:2,1:1,2:2,27:2,195:26,2:25,1:25,1:25,2:40,2:3f,1:3f,33:1,11:-6,1:-9,1ac7:-3a,6d:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,b:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,c:-8,2:-8,2:-8,2:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,49:-8,1:-8,1:-4a,1:-4a,d:-56,1:-56,1:-56,1:-56,d:-8,1:-8,f:-8,1:-8,3:-7"),kn("df:00730073,51:00690307,19:02BC006E,a7:006A030C,18a:002003B9,16:03B903080301,20:03C503080301,1d7:05650582,190f:00680331,1:00740308,1:0077030A,1:0079030A,1:006102BE,b6:03C50313,2:03C503130300,2:03C503130301,2:03C503130342,2a:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,3:1F7003B9,1:03B103B9,1:03AC03B9,2:03B10342,1:03B1034203B9,5:03B103B9,6:1F7403B9,1:03B703B9,1:03AE03B9,2:03B70342,1:03B7034203B9,5:03B703B9,6:03B903080300,1:03B903080301,3:03B90342,1:03B903080342,b:03C503080300,1:03C503080301,1:03C10313,2:03C50342,1:03C503080342,b:1F7C03B9,1:03C903B9,1:03CE03B9,2:03C90342,1:03C9034203B9,5:03C903B9,ac:00720073,5b:00B00063,6:00B00066,d:006E006F,a:0073006D,1:00740065006C,1:0074006D,124f:006800700061,2:00610075,2:006F0076,b:00700061,1:006E0061,1:03BC0061,1:006D0061,1:006B0061,1:006B0062,1:006D0062,1:00670062,3:00700066,1:006E0066,1:03BC0066,4:0068007A,1:006B0068007A,1:006D0068007A,1:00670068007A,1:00740068007A,15:00700061,1:006B00700061,1:006D00700061,1:006700700061,8:00700076,1:006E0076,1:03BC0076,1:006D0076,1:006B0076,1:006D0076,1:00700077,1:006E0077,1:03BC0077,1:006D0077,1:006B0077,1:006D0077,1:006B03C9,1:006D03C9,2:00620071,3:00632215006B0067,1:0063006F002E,1:00640062,1:00670079,2:00680070,2:006B006B,1:006B006D,9:00700068,2:00700070006D,1:00700072,2:00730076,1:00770062,c723:00660066,1:00660069,1:0066006C,1:006600660069,1:00660066006C,1:00730074,1:00730074,d:05740576,1:05740565,1:0574056B,1:057E0576,1:0574056D",(function(t){if(t.length%4!=0)throw new Error("bad data");let e=[];for(let r=0;r0&&Array.isArray(t)?n(t,e-1):r.push(t)}))};return n(t,e),r}function Bn(t){return 1&t?~t>>1:t>>1}function Dn(t,e){let r=Array(t);for(let i=0,n=-1;ie[t])):r}function Fn(t,e,r){let i=Array(t).fill(void 0).map((()=>[]));for(let n=0;ni[e].push(t)));return i}function Kn(t,e){let r=1+e(),i=e(),n=function(t){let e=[];for(;;){let r=t();if(0==r)break;e.push(r)}return e}(e);return Un(Fn(n.length,1+t,e).map(((t,e)=>{const s=t[0],o=t.slice(1);return Array(n[e]).fill(void 0).map(((t,e)=>{let n=e*i;return[s+e*r,o.map((t=>t+n))]}))})))}function Vn(t,e){return Fn(1+e(),1+t,e).map((t=>[t[0],t.slice(1)]))}const Hn=function(t){return function(t){let e=0;return()=>t[e++]}(function(t){let e=0;function r(){return t[e++]<<8|t[e++]}let i=r(),n=1,s=[0,1];for(let t=1;t>--h&1}const u=Math.pow(2,31),d=u>>>1,l=d>>1,p=u-1;let g=0;for(let t=0;t<31;t++)g=g<<1|f();let m=[],b=0,y=u;for(;;){let t=Math.floor(((g-b+1)*n-1)/y),e=0,r=i;for(;r-e>1;){let i=e+r>>>1;t>>1|f(),o=o<<1^d,a=(a^d)<<1|d|1;b=o,y=1+a-o}let v=i-4;return m.map((e=>{switch(e-v){case 3:return v+65792+(t[a++]<<16|t[a++]<<8|t[a++]);case 2:return v+256+(t[a++]<<8|t[a++]);case 1:return v+t[a++];default:return e-1}}))}(t))}(function(t){t=atob(t);const e=[];for(let r=0;rt-e));!function r(){let i=[];for(;;){let n=jn(t,e);if(0==n.length)break;i.push({set:new Set(n),node:r()})}i.sort(((t,e)=>e.set.size-t.set.size));let n=t(),s=n%3;n=n/3|0;let o=!!(1&n);return n>>=1,{branches:i,valid:s,fe0f:o,save:1==n,check:2==n}}()}(Hn),new ji(qn),new Uint8Array(32).fill(0);const Wn="Ethereum Signed Message:\n";function Jn(t){return"string"==typeof t&&(t=Cn(t)),tn(function(t){const e=t.map((t=>Ji(t))),r=e.reduce(((t,e)=>t+e.length),0),i=new Uint8Array(r);return e.reduce(((t,e)=>(i.set(e,t),t+e.length)),0),Vi(i)}([Cn(Wn),Cn(String(t.length)),t]))}new ji("rlp/5.7.0");const Gn=new ji("address/5.7.0");function $n(t){Gi(t,20)||Gn.throwArgumentError("invalid address","address",t);const e=(t=t.toLowerCase()).substring(2).split(""),r=new Uint8Array(40);for(let t=0;t<40;t++)r[t]=e[t].charCodeAt(0);const i=Ji(tn(r));for(let t=0;t<40;t+=2)i[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&i[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const Yn={};for(let t=0;t<10;t++)Yn[String(t)]=String(t);for(let t=0;t<26;t++)Yn[String.fromCharCode(65+t)]=String(10+t);const Qn=Math.floor(function(t){return Math.log10?Math.log10(t):Math.log(t)/Math.LN10}(9007199254740991));function Xn(t,e,r){Object.defineProperty(t,e,{enumerable:!0,value:r,writable:!1})}new ji("properties/5.7.0"),new ji(qn),new Uint8Array(32).fill(0),un.from(-1);const Zn=un.from(0),ts=un.from(1);un.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Xi(ts.toHexString(),32),Xi(Zn.toHexString(),32);var es={},rs={},is=ns;function ns(t,e){if(!t)throw new Error(e||"Assertion failed")}ns.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var ss={exports:{}};"function"==typeof Object.create?ss.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:ss.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}};var os=is,as=ss.exports;function hs(t,e){return!(55296!=(64512&t.charCodeAt(e))||e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1))}function cs(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function fs(t){return 1===t.length?"0"+t:t}function us(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}rs.inherits=as,rs.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),n=0;n>6|192,r[i++]=63&s|128):hs(t,n)?(s=65536+((1023&s)<<10)+(1023&t.charCodeAt(++n)),r[i++]=s>>18|240,r[i++]=s>>12&63|128,r[i++]=s>>6&63|128,r[i++]=63&s|128):(r[i++]=s>>12|224,r[i++]=s>>6&63|128,r[i++]=63&s|128)}else for(n=0;n>>0}return s},rs.split32=function(t,e){for(var r=new Array(4*t.length),i=0,n=0;i>>24,r[n+1]=s>>>16&255,r[n+2]=s>>>8&255,r[n+3]=255&s):(r[n+3]=s>>>24,r[n+2]=s>>>16&255,r[n+1]=s>>>8&255,r[n]=255&s)}return r},rs.rotr32=function(t,e){return t>>>e|t<<32-e},rs.rotl32=function(t,e){return t<>>32-e},rs.sum32=function(t,e){return t+e>>>0},rs.sum32_3=function(t,e,r){return t+e+r>>>0},rs.sum32_4=function(t,e,r,i){return t+e+r+i>>>0},rs.sum32_5=function(t,e,r,i,n){return t+e+r+i+n>>>0},rs.sum64=function(t,e,r,i){var n=t[e],s=i+t[e+1]>>>0,o=(s>>0,t[e+1]=s},rs.sum64_hi=function(t,e,r,i){return(e+i>>>0>>0},rs.sum64_lo=function(t,e,r,i){return e+i>>>0},rs.sum64_4_hi=function(t,e,r,i,n,s,o,a){var h=0,c=e;return h+=(c=c+i>>>0)>>0)>>0)>>0},rs.sum64_4_lo=function(t,e,r,i,n,s,o,a){return e+i+s+a>>>0},rs.sum64_5_hi=function(t,e,r,i,n,s,o,a,h,c){var f=0,u=e;return f+=(u=u+i>>>0)>>0)>>0)>>0)>>0},rs.sum64_5_lo=function(t,e,r,i,n,s,o,a,h,c){return e+i+s+a+c>>>0},rs.rotr64_hi=function(t,e,r){return(e<<32-r|t>>>r)>>>0},rs.rotr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},rs.shr64_hi=function(t,e,r){return t>>>r},rs.shr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0};var ds={},ls=rs,ps=is;function gs(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}ds.BlockHash=gs,gs.prototype.update=function(t,e){if(t=ls.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=ls.join32(t,0,t.length-r,this.endian);for(var i=0;i>>24&255,i[n++]=t>>>16&255,i[n++]=t>>>8&255,i[n++]=255&t}else for(i[n++]=255&t,i[n++]=t>>>8&255,i[n++]=t>>>16&255,i[n++]=t>>>24&255,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,s=8;s>>3},bs.g1_256=function(t){return ys(t,17)^ys(t,19)^t>>>10};var As=rs,Ms=ds,Ss=bs,Es=As.rotl32,Is=As.sum32,xs=As.sum32_5,Os=Ss.ft_1,Ns=Ms.BlockHash,Ps=[1518500249,1859775393,2400959708,3395469782];function Rs(){if(!(this instanceof Rs))return new Rs;Ns.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}As.inherits(Rs,Ns);var Ts=Rs;Rs.blockSize=512,Rs.outSize=160,Rs.hmacStrength=80,Rs.padLength=64,Rs.prototype._update=function(t,e){for(var r=this.W,i=0;i<16;i++)r[i]=t[e+i];for(;ithis.blockSize&&(t=(new this.Hash).update(t).digest()),Xo(t.length<=this.blockSize);for(var e=t.length;e>8,o=255&n;s?r.push(s,o):r.push(o)}return r},r.zero2=i,r.toHex=n,r.encode=function(t,e){return"hex"===e?n(t):t}})),oa=ra((function(t,e){var r=e;r.assert=ia,r.toArray=sa.toArray,r.zero2=sa.zero2,r.toHex=sa.toHex,r.encode=sa.encode,r.getNAF=function(t,e,r){var i=new Array(Math.max(t.bitLength(),r)+1);i.fill(0);for(var n=1<(n>>1)-1?(n>>1)-h:h,s.isubn(a)):a=0,i[o]=a,s.iushrn(1)}return i},r.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var i,n=0,s=0;t.cmpn(-n)>0||e.cmpn(-s)>0;){var o,a,h=t.andln(3)+n&3,c=e.andln(3)+s&3;3===h&&(h=-1),3===c&&(c=-1),o=1&h?3!=(i=t.andln(7)+n&7)&&5!==i||2!==c?h:-h:0,r[0].push(o),a=1&c?3!=(i=e.andln(7)+s&7)&&5!==i||2!==h?c:-c:0,r[1].push(a),2*n===o+1&&(n=1-n),2*s===a+1&&(s=1-s),t.iushrn(1),e.iushrn(1)}return r},r.cachedProperty=function(t,e,r){var i="_"+e;t.prototype[e]=function(){return void 0!==this[i]?this[i]:this[i]=r.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new nn(t,"hex","le")}})),aa=oa.getNAF,ha=oa.getJSF,ca=oa.assert;function fa(t,e){this.type=t,this.p=new nn(e.p,16),this.red=e.prime?nn.red(e.prime):nn.mont(this.p),this.zero=new nn(0).toRed(this.red),this.one=new nn(1).toRed(this.red),this.two=new nn(2).toRed(this.red),this.n=e.n&&new nn(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var ua=fa;function da(t,e){this.curve=t,this.type=e,this.precomputed=null}fa.prototype.point=function(){throw new Error("Not implemented")},fa.prototype.validate=function(){throw new Error("Not implemented")},fa.prototype._fixedNafMul=function(t,e){ca(t.precomputed);var r=t._getDoubles(),i=aa(e,1,this._bitLength),n=(1<=s;h--)o=(o<<1)+i[h];a.push(o)}for(var c=this.jpoint(null,null,null),f=this.jpoint(null,null,null),u=n;u>0;u--){for(s=0;s=0;a--){for(var h=0;a>=0&&0===s[a];a--)h++;if(a>=0&&h++,o=o.dblp(h),a<0)break;var c=s[a];ca(0!==c),o="affine"===t.type?c>0?o.mixedAdd(n[c-1>>1]):o.mixedAdd(n[-c-1>>1].neg()):c>0?o.add(n[c-1>>1]):o.add(n[-c-1>>1].neg())}return"affine"===t.type?o.toP():o},fa.prototype._wnafMulAdd=function(t,e,r,i,n){var s,o,a,h=this._wnafT1,c=this._wnafT2,f=this._wnafT3,u=0;for(s=0;s=1;s-=2){var l=s-1,p=s;if(1===h[l]&&1===h[p]){var g=[e[l],null,null,e[p]];0===e[l].y.cmp(e[p].y)?(g[1]=e[l].add(e[p]),g[2]=e[l].toJ().mixedAdd(e[p].neg())):0===e[l].y.cmp(e[p].y.redNeg())?(g[1]=e[l].toJ().mixedAdd(e[p]),g[2]=e[l].add(e[p].neg())):(g[1]=e[l].toJ().mixedAdd(e[p]),g[2]=e[l].toJ().mixedAdd(e[p].neg()));var m=[-3,-1,-5,-7,0,7,5,1,3],b=ha(r[l],r[p]);for(u=Math.max(b[0].length,u),f[l]=new Array(u),f[p]=new Array(u),o=0;o=0;s--){for(var A=0;s>=0;){var M=!0;for(o=0;o=0&&A++,w=w.dblp(A),s<0)break;for(o=0;o0?a=c[o][S-1>>1]:S<0&&(a=c[o][-S-1>>1].neg()),w="affine"===a.type?w.mixedAdd(a):w.add(a))}}for(s=0;s=Math.ceil((t.bitLength()+1)/e.step)},da.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],i=this,n=0;n=0&&(s=e,o=r),i.negative&&(i=i.neg(),n=n.neg()),s.negative&&(s=s.neg(),o=o.neg()),[{a:i,b:n},{a:s,b:o}]},ga.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],i=e[1],n=i.b.mul(t).divRound(this.n),s=r.b.neg().mul(t).divRound(this.n),o=n.mul(r.a),a=s.mul(i.a),h=n.mul(r.b),c=s.mul(i.b);return{k1:t.sub(o).sub(a),k2:h.add(c).neg()}},ga.prototype.pointFromX=function(t,e){(t=new nn(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),i=r.redSqrt();if(0!==i.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var n=i.fromRed().isOdd();return(e&&!n||!e&&n)&&(i=i.redNeg()),this.point(t,i)},ga.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,i=this.a.redMul(e),n=e.redSqr().redMul(e).redIAdd(i).redIAdd(this.b);return 0===r.redSqr().redISub(n).cmpn(0)},ga.prototype._endoWnafMulAdd=function(t,e,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,s=0;s":""},ba.prototype.isInfinity=function(){return this.inf},ba.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),i=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,i)},ba.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),i=t.redInvm(),n=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(i),s=n.redSqr().redISub(this.x.redAdd(this.x)),o=n.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)},ba.prototype.getX=function(){return this.x.fromRed()},ba.prototype.getY=function(){return this.y.fromRed()},ba.prototype.mul=function(t){return t=new nn(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},ba.prototype.mulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},ba.prototype.jmulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},ba.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},ba.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,i=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(i)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(i)}}}return e},ba.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},la(ya,ua.BasePoint),ga.prototype.jpoint=function(t,e,r){return new ya(this,t,e,r)},ya.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),i=this.y.redMul(e).redMul(t);return this.curve.point(r,i)},ya.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},ya.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(e),n=t.x.redMul(r),s=this.y.redMul(e.redMul(t.z)),o=t.y.redMul(r.redMul(this.z)),a=i.redSub(n),h=s.redSub(o);if(0===a.cmpn(0))return 0!==h.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=a.redSqr(),f=c.redMul(a),u=i.redMul(c),d=h.redSqr().redIAdd(f).redISub(u).redISub(u),l=h.redMul(u.redISub(d)).redISub(s.redMul(f)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(d,l,p)},ya.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,i=t.x.redMul(e),n=this.y,s=t.y.redMul(e).redMul(this.z),o=r.redSub(i),a=n.redSub(s);if(0===o.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var h=o.redSqr(),c=h.redMul(o),f=r.redMul(h),u=a.redSqr().redIAdd(c).redISub(f).redISub(f),d=a.redMul(f.redISub(u)).redISub(n.redMul(c)),l=this.z.redMul(o);return this.curve.jpoint(u,d,l)},ya.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e=0)return!1;if(r.redIAdd(n),0===this.x.cmp(r))return!0}},ya.prototype.inspect=function(){return this.isInfinity()?"":""},ya.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var va=ra((function(t,e){var r=e;r.base=ua,r.short=ma,r.mont=null,r.edwards=null})),wa=ra((function(t,e){var r,i=e,n=oa.assert;function s(t){"short"===t.type?this.curve=new va.short(t):"edwards"===t.type?this.curve=new va.edwards(t):this.curve=new va.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,n(this.g.validate(),"Invalid curve"),n(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function o(t,e){Object.defineProperty(i,t,{configurable:!0,enumerable:!0,get:function(){var r=new s(e);return Object.defineProperty(i,t,{configurable:!0,enumerable:!0,value:r}),r}})}i.PresetCurve=s,o("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:es.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),o("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:es.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),o("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:es.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),o("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:es.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),o("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:es.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),o("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:es.sha256,gRed:!1,g:["9"]}),o("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:es.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{r=null.crash()}catch{r=void 0}o("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:es.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",r]})}));function _a(t){if(!(this instanceof _a))return new _a(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=sa.toArray(t.entropy,t.entropyEnc||"hex"),r=sa.toArray(t.nonce,t.nonceEnc||"hex"),i=sa.toArray(t.pers,t.persEnc||"hex");ia(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}var Aa=_a;_a.prototype._init=function(t,e,r){var i=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},_a.prototype.generate=function(t,e,r,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(i=r,r=e,e=null),r&&(r=sa.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length"};var Ia=oa.assert;function xa(t,e){if(t instanceof xa)return t;this._importDER(t,e)||(Ia(t.r&&t.s,"Signature without r or s"),this.r=new nn(t.r,16),this.s=new nn(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var Oa=xa;function Na(){this.place=0}function Pa(t,e){var r=t[e.place++];if(!(128&r))return r;var i=15&r;if(0===i||i>4)return!1;for(var n=0,s=0,o=e.place;s>>=0;return!(n<=127)&&(e.place=o,n)}function Ra(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}xa.prototype._importDER=function(t,e){t=oa.toArray(t,e);var r=new Na;if(48!==t[r.place++])return!1;var i=Pa(t,r);if(!1===i||i+r.place!==t.length||2!==t[r.place++])return!1;var n=Pa(t,r);if(!1===n)return!1;var s=t.slice(r.place,n+r.place);if(r.place+=n,2!==t[r.place++])return!1;var o=Pa(t,r);if(!1===o||t.length!==o+r.place)return!1;var a=t.slice(r.place,o+r.place);if(0===s[0]){if(!(128&s[1]))return!1;s=s.slice(1)}if(0===a[0]){if(!(128&a[1]))return!1;a=a.slice(1)}return this.r=new nn(s),this.s=new nn(a),this.recoveryParam=null,!0},xa.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=Ra(e),r=Ra(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];Ta(i,e.length),(i=i.concat(e)).push(2),Ta(i,r.length);var n=i.concat(r),s=[48];return Ta(s,n.length),s=s.concat(n),oa.encode(s,t)};var Ca=function(){throw new Error("unsupported")},ka=oa.assert;function La(t){if(!(this instanceof La))return new La(t);"string"==typeof t&&(ka(Object.prototype.hasOwnProperty.call(wa,t),"Unknown curve "+t),t=wa[t]),t instanceof wa.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}var qa=La;La.prototype.keyPair=function(t){return new Ea(this,t)},La.prototype.keyFromPrivate=function(t,e){return Ea.fromPrivate(this,t,e)},La.prototype.keyFromPublic=function(t,e){return Ea.fromPublic(this,t,e)},La.prototype.genKeyPair=function(t){t||(t={});for(var e=new Aa({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||Ca(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),r=this.n.byteLength(),i=this.n.sub(new nn(2));;){var n=new nn(e.generate(r));if(!(n.cmp(i)>0))return n.iaddn(1),this.keyFromPrivate(n)}},La.prototype._truncateToN=function(t,e){var r=8*t.byteLength()-this.n.bitLength();return r>0&&(t=t.ushrn(r)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},La.prototype.sign=function(t,e,r,i){"object"==typeof r&&(i=r,r=null),i||(i={}),e=this.keyFromPrivate(e,r),t=this._truncateToN(new nn(t,16));for(var n=this.n.byteLength(),s=e.getPrivate().toArray("be",n),o=t.toArray("be",n),a=new Aa({hash:this.hash,entropy:s,nonce:o,pers:i.pers,persEnc:i.persEnc||"utf8"}),h=this.n.sub(new nn(1)),c=0;;c++){var f=i.k?i.k(c):new nn(a.generate(this.n.byteLength()));if(!((f=this._truncateToN(f,!0)).cmpn(1)<=0||f.cmp(h)>=0)){var u=this.g.mul(f);if(!u.isInfinity()){var d=u.getX(),l=d.umod(this.n);if(0!==l.cmpn(0)){var p=f.invm(this.n).mul(l.mul(e.getPrivate()).iadd(t));if(0!==(p=p.umod(this.n)).cmpn(0)){var g=(u.getY().isOdd()?1:0)|(0!==d.cmp(l)?2:0);return i.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),g^=1),new Oa({r:l,s:p,recoveryParam:g})}}}}}},La.prototype.verify=function(t,e,r,i){t=this._truncateToN(new nn(t,16)),r=this.keyFromPublic(r,i);var n=(e=new Oa(e,"hex")).r,s=e.s;if(n.cmpn(1)<0||n.cmp(this.n)>=0||s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;var o,a=s.invm(this.n),h=a.mul(t).umod(this.n),c=a.mul(n).umod(this.n);return this.curve._maxwellTrick?!(o=this.g.jmulAdd(h,r.getPublic(),c)).isInfinity()&&o.eqXToP(n):!(o=this.g.mulAdd(h,r.getPublic(),c)).isInfinity()&&0===o.getX().umod(this.n).cmp(n)},La.prototype.recoverPubKey=function(t,e,r,i){ka((3&r)===r,"The recovery param is more than two bits"),e=new Oa(e,i);var n=this.n,s=new nn(t),o=e.r,a=e.s,h=1&r,c=r>>1;if(o.cmp(this.curve.p.umod(this.curve.n))>=0&&c)throw new Error("Unable to find sencond key candinate");o=c?this.curve.pointFromX(o.add(this.curve.n),h):this.curve.pointFromX(o,h);var f=e.r.invm(n),u=n.sub(s).mul(f).umod(n),d=a.mul(f).umod(n);return this.g.mulAdd(u,o,d)},La.prototype.getKeyRecoveryParam=function(t,e,r,i){if(null!==(e=new Oa(e,i)).recoveryParam)return e.recoveryParam;for(var n=0;n<4;n++){var s;try{s=this.recoverPubKey(t,e,n)}catch{continue}if(s.eq(r))return n}throw new Error("Unable to find valid recovery factor")};var Ua=ra((function(t,e){var r=e;r.version="6.5.4",r.utils=oa,r.rand=function(){throw new Error("unsupported")},r.curve=va,r.curves=wa,r.ec=qa,r.eddsa=null})),Ba=Ua.ec;const Da=new ji("signing-key/5.7.0");let za=null;function ja(){return za||(za=new Ba("secp256k1")),za}class Fa{constructor(t){Xn(this,"curve","secp256k1"),Xn(this,"privateKey",Yi(t)),32!==function(t){if("string"!=typeof t)t=Yi(t);else if(!Gi(t)||t.length%2)return null;return(t.length-2)/2}(this.privateKey)&&Da.throwArgumentError("invalid private key","privateKey","[[ REDACTED ]]");const e=ja().keyFromPrivate(Ji(this.privateKey));Xn(this,"publicKey","0x"+e.getPublic(!1,"hex")),Xn(this,"compressedPublicKey","0x"+e.getPublic(!0,"hex")),Xn(this,"_isSigningKey",!0)}_addPoint(t){const e=ja().keyFromPublic(Ji(this.publicKey)),r=ja().keyFromPublic(Ji(t));return"0x"+e.pub.add(r.pub).encodeCompressed("hex")}signDigest(t){const e=ja().keyFromPrivate(Ji(this.privateKey)),r=Ji(t);32!==r.length&&Da.throwArgumentError("bad digest length","digest",t);const i=e.sign(r,{canonical:!0});return Zi({recoveryParam:i.recoveryParam,r:Xi("0x"+i.r.toString(16),32),s:Xi("0x"+i.s.toString(16),32)})}computeSharedSecret(t){const e=ja().keyFromPrivate(Ji(this.privateKey)),r=ja().keyFromPublic(Ji(Ka(t)));return Xi("0x"+e.derive(r.getPublic()).toString(16),32)}static isSigningKey(t){return!(!t||!t._isSigningKey)}}function Ka(t,e){const r=Ji(t);if(32===r.length){const t=new Fa(r);return e?"0x"+ja().keyFromPrivate(r).getPublic(!0,"hex"):t.publicKey}return 33===r.length?e?Yi(r):"0x"+ja().keyFromPublic(r).getPublic(!1,"hex"):65===r.length?e?"0x"+ja().keyFromPublic(r).getPublic(!0,"hex"):Yi(r):Da.throwArgumentError("invalid public or private key","key","[REDACTED]")}var Va;function Ha(t,e){return function(t){return function(t){let e=null;if("string"!=typeof t&&Gn.throwArgumentError("invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==t.substring(0,2)&&(t="0x"+t),e=$n(t),t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&e!==t&&Gn.throwArgumentError("bad address checksum","address",t);else if(t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(t.substring(2,4)!==function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>Yn[t])).join("");for(;e.length>=Qn;){let t=e.substring(0,Qn);e=parseInt(t,10)%97+e.substring(t.length)}let r=String(98-parseInt(e,10)%97);for(;r.length<2;)r="0"+r;return r}(t)&&Gn.throwArgumentError("bad icap checksum","address",t),e=function(t){return new on(t,36).toString(16)}(t.substring(4));e.length<40;)e="0"+e;e=$n("0x"+e)}else Gn.throwArgumentError("invalid address","address",t);return e}(Qi(tn(Qi(Ka(t),1)),12))}(function(t,e){const r=Zi(e),i={r:Ji(r.r),s:Ji(r.s)};return"0x"+ja().recoverPubKey(Ji(t),i,r.recoveryParam).encode("hex",!1)}(Ji(t),e))}new ji("transactions/5.7.0"),function(t){t[t.legacy=0]="legacy",t[t.eip2930=1]="eip2930",t[t.eip1559=2]="eip1559"}(Va||(Va={}));const Wa="https://rpc.walletconnect.com/v1";var Ja=Object.defineProperty,Ga=Object.defineProperties,$a=Object.getOwnPropertyDescriptors,Ya=Object.getOwnPropertySymbols,Qa=Object.prototype.hasOwnProperty,Xa=Object.prototype.propertyIsEnumerable,Za=(t,e,r)=>e in t?Ja(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;const th=t=>t?.split(":"),eh=t=>{const e=t&&th(t);if(e)return t.includes("did:pkh:")?e[3]:e[1]},rh=t=>{const e=t&&th(t);if(e)return e[2]+":"+e[3]},ih=t=>{const e=t&&th(t);if(e)return e.pop()};async function nh(t){const{cacao:e,projectId:r}=t,{s:i,p:n}=e,s=sh(n,n.iss),o=ih(n.iss);return await async function(t,e,r,i,n,s){switch(r.t){case"eip191":return function(t,e,r){return Ha(Jn(e),r).toLowerCase()===t.toLowerCase()}(t,e,r.s);case"eip1271":return await async function(t,e,r,i,n,s){try{const o="0x1626ba7e",a="0000000000000000000000000000000000000000000000000000000000000040",h="0000000000000000000000000000000000000000000000000000000000000041",c=r.substring(2),f=o+Jn(e).substring(2)+a+h+c,u=await fetch(`${s||Wa}/?chainId=${i}&projectId=${n}`,{method:"POST",body:JSON.stringify({id:Date.now()+Math.floor(1e3*Math.random()),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:f},"latest"]})}),{result:d}=await u.json();return!!d&&d.slice(0,o.length).toLowerCase()===o.toLowerCase()}catch(t){return console.error("isValidEip1271Signature: ",t),!1}}(t,e,r.s,i,n,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}(o,s,i,eh(n.iss),r)}const sh=(t,e)=>{const r=`${t.domain} wants you to sign in with your Ethereum account:`,i=ih(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let n=t.statement||void 0;const s=`URI: ${t.aud||t.uri}`,o=`Version: ${t.version}`,a=`Chain ID: ${eh(e)}`,h=`Nonce: ${t.nonce}`,c=`Issued At: ${t.iat}`,f=t.exp?`Expiration Time: ${t.exp}`:void 0,u=t.nbf?`Not Before: ${t.nbf}`:void 0,d=t.requestId?`Request ID: ${t.requestId}`:void 0,l=t.resources?`Resources:${t.resources.map((t=>`\n- ${t}`)).join("")}`:void 0,p=lh(t.resources);return p&&(n=function(t="",e){oh(e);const r="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(r))return t;const i=[];let n=0;return Object.keys(e.att).forEach((t=>{const r=Object.keys(e.att[t]).map((t=>({ability:t.split("/")[0],action:t.split("/")[1]})));r.sort(((t,e)=>t.action.localeCompare(e.action)));const s={};r.forEach((t=>{s[t.ability]||(s[t.ability]=[]),s[t.ability].push(t.action)}));const o=Object.keys(s).map((e=>(n++,`(${n}) '${e}': '${s[e].join("', '")}' for '${t}'.`)));i.push(o.join(", ").replace(".,","."))})),`${t?t+" ":""}${r}${i.join(" ")}`}(n,ch(p))),[r,i,"",n,"",s,o,a,h,c,f,u,d,l].filter((t=>null!=t)).join("\n")};function oh(t){if(!t)throw new Error("No recap provided, value is undefined");if(!t.att)throw new Error("No `att` property found");const e=Object.keys(t.att);if(null==e||!e.length)throw new Error("No resources found in `att` property");e.forEach((e=>{const r=t.att[e];if(Array.isArray(r))throw new Error(`Resource must be an object: ${e}`);if("object"!=typeof r)throw new Error(`Resource must be an object: ${e}`);if(!Object.keys(r).length)throw new Error(`Resource object is empty: ${e}`);Object.keys(r).forEach((t=>{const e=r[t];if(!Array.isArray(e))throw new Error(`Ability limits ${t} must be an array of objects, found: ${e}`);if(!e.length)throw new Error(`Value of ${t} is empty array, must be an array with objects`);e.forEach((e=>{if("object"!=typeof e)throw new Error(`Ability limits (${t}) must be an array of objects, found: ${e}`)}))}))}))}function ah(t,e,r={}){e=e?.sort(((t,e)=>t.localeCompare(e)));const i=e.map((e=>({[`${t}/${e}`]:[r]})));return Object.assign({},...i)}function hh(t){return oh(t),`urn:recap:${function(t){return Buffer.from(JSON.stringify(t)).toString("base64")}(t).replace(/=/g,"")}`}function ch(t){const e=function(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}(t.replace("urn:recap:",""));return oh(e),e}function fh(t,e){const r=function(t,e){oh(t),oh(e);const r=Object.keys(t.att).concat(Object.keys(e.att)).sort(((t,e)=>t.localeCompare(e))),i={att:{}};return r.forEach((r=>{var n,s;Object.keys((null==(n=t.att)?void 0:n[r])||{}).concat(Object.keys((null==(s=e.att)?void 0:s[r])||{})).sort(((t,e)=>t.localeCompare(e))).forEach((n=>{var s,o;i.att[r]=((t,e)=>Ga(t,$a(e)))(((t,e)=>{for(var r in e||(e={}))Qa.call(e,r)&&Za(t,r,e[r]);if(Ya)for(var r of Ya(e))Xa.call(e,r)&&Za(t,r,e[r]);return t})({},i.att[r]),{[n]:(null==(s=t.att[r])?void 0:s[n])||(null==(o=e.att[r])?void 0:o[n])})}))})),i}(ch(t),ch(e));return hh(r)}function uh(t){var e;const r=ch(t);oh(r);const i=null==(e=r.att)?void 0:e.eip155;return i?Object.keys(i).map((t=>t.split("/")[1])):[]}function dh(t){const e=ch(t);oh(e);const r=[];return Object.values(e.att).forEach((t=>{Object.values(t).forEach((t=>{var e;null!=(e=t?.[0])&&e.chains&&r.push(t[0].chains)}))})),[...new Set(r.flat())]}function lh(t){if(!t)return;const e=t?.[t.length-1];return function(t){return t&&t.includes("urn:recap:")}(e)?e:void 0}const ph="base10",gh="base16",mh="base64pad",bh="base64url",yh="utf8";function vh(){return Qr((0,Ut.randomBytes)(32),gh)}function wh(t){return Qr((0,Fr.tW)(Yr(t,gh)),gh)}function _h(t){return Qr((0,Fr.tW)(Yr(t,yh)),gh)}function Ah(t){return Yr(`${t}`,ph)}function Mh(t){return Number(Qr(t,ph))}function Sh(t){const{encoding:e=mh}=t;if(2===Mh(t.type))return Qr(Hr([t.type,t.sealed]),e);if(1===Mh(t.type)){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return Qr(Hr([t.type,t.senderPublicKey,t.iv,t.sealed]),e)}return Qr(Hr([t.type,t.iv,t.sealed]),e)}function Eh(t){const{encoded:e,encoding:r=mh}=t,i=Yr(e,r),n=i.slice(0,1);if(1===Mh(n)){const t=33,e=t+12,r=i.slice(1,t),s=i.slice(t,e);return{type:n,sealed:i.slice(e),iv:s,senderPublicKey:r}}if(2===Mh(n))return{type:n,sealed:i.slice(1),iv:(0,Ut.randomBytes)(12)};const s=i.slice(1,13);return{type:n,sealed:i.slice(13),iv:s}}function Ih(t){const e=t?.type||0;if(1===e){if(typeof t?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof t?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:e,senderPublicKey:t?.senderPublicKey,receiverPublicKey:t?.receiverPublicKey}}function xh(t){return 1===t.type&&"string"==typeof t.senderPublicKey&&"string"==typeof t.receiverPublicKey}function Oh(t){return 2===t.type}function Nh(t){return t?.relay||{protocol:"irn"}}function Ph(t){const e=Zr[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}var Rh=Object.defineProperty,Th=Object.defineProperties,Ch=Object.getOwnPropertyDescriptors,kh=Object.getOwnPropertySymbols,Lh=Object.prototype.hasOwnProperty,qh=Object.prototype.propertyIsEnumerable,Uh=(t,e,r)=>e in t?Rh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Bh=(t,e)=>{for(var r in e||(e={}))Lh.call(e,r)&&Uh(t,r,e[r]);if(kh)for(var r of kh(e))qh.call(e,r)&&Uh(t,r,e[r]);return t};function Dh(t,e="-"){const r={},i="relay"+e;return Object.keys(t).forEach((e=>{if(e.startsWith(i)){const n=e.replace(i,""),s=t[e];r[n]=s}})),r}function zh(t){const e=(t=(t=t.includes("wc://")?t.replace("wc://",""):t).includes("wc:")?t.replace("wc:",""):t).indexOf(":"),r=-1!==t.indexOf("?")?t.indexOf("?"):void 0,i=t.substring(0,e),n=t.substring(e+1,r).split("@"),s=typeof r<"u"?t.substring(r):"",o=Dr.parse(s),a="string"==typeof o.methods?o.methods.split(","):void 0;return{protocol:i,topic:jh(n[0]),version:parseInt(n[1],10),symKey:o.symKey,relay:Dh(o),methods:a,expiryTimestamp:o.expiryTimestamp?parseInt(o.expiryTimestamp,10):void 0}}function jh(t){return t.startsWith("//")?t.substring(2):t}function Fh(t,e,r){return`${t}?wc_ev=${r}&topic=${e}`}var Kh=Object.defineProperty,Vh=Object.defineProperties,Hh=Object.getOwnPropertyDescriptors,Wh=Object.getOwnPropertySymbols,Jh=Object.prototype.hasOwnProperty,Gh=Object.prototype.propertyIsEnumerable,$h=(t,e,r)=>e in t?Kh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yh=(t,e)=>{for(var r in e||(e={}))Jh.call(e,r)&&$h(t,r,e[r]);if(Wh)for(var r of Wh(e))Gh.call(e,r)&&$h(t,r,e[r]);return t},Qh=(t,e)=>Vh(t,Hh(e));function Xh(t){const e=[];return t.forEach((t=>{const[r,i]=t.split(":");e.push(`${r}:${i}`)})),e}function Zh(t){return t.includes(":")}function tc(t){return Zh(t)?t.split(":")[0]:t}function ec(t){var e,r,i;const n={};if(!hc(t))return n;for(const[s,o]of Object.entries(t)){const t=Zh(s)?[s]:o.chains,a=o.methods||[],h=o.events||[],c=tc(s);n[c]=Qh(Yh({},n[c]),{chains:Ii(t,null==(e=n[c])?void 0:e.chains),methods:Ii(a,null==(r=n[c])?void 0:r.methods),events:Ii(h,null==(i=n[c])?void 0:i.events)})}return n}function rc(t,e){e=e.map((t=>t.replace("did:pkh:","")));const r=function(t){const e={};return t?.forEach((t=>{const[r,i]=t.split(":");e[r]||(e[r]={accounts:[],chains:[],events:[]}),e[r].accounts.push(t),e[r].chains.push(`${r}:${i}`)})),e}(e);for(const[e,i]of Object.entries(r))i.methods?i.methods=Ii(i.methods,t):i.methods=t,i.events=["chainChanged","accountsChanged"];return r}const ic={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},nc={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function sc(t,e){const{message:r,code:i}=nc[t];return{message:e?`${r} ${e}`:r,code:i}}function oc(t,e){const{message:r,code:i}=ic[t];return{message:e?`${r} ${e}`:r,code:i}}function ac(t,e){return!!Array.isArray(t)&&(!(typeof e<"u"&&t.length)||t.every(e))}function hc(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function cc(t){return typeof t>"u"}function fc(t,e){return!(!e||!cc(t))||"string"==typeof t&&!!t.trim().length}function uc(t,e){return!(!e||!cc(t))||"number"==typeof t&&!isNaN(t)}function dc(t){return!(!fc(t,!1)||!t.includes(":"))&&2===t.split(":").length}function lc(t){if(fc(t,!1))try{return typeof new URL(t)<"u"}catch{return!1}return!1}function pc(t){let e=!0;return ac(t)?t.length&&(e=t.every((t=>fc(t,!1)))):e=!1,e}function gc(t,e){let r=null;return Object.values(t).forEach((t=>{if(r)return;const i=function(t,e){let r=null;return pc(t?.methods)?pc(t?.events)||(r=oc("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):r=oc("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),r}(t,`${e}, namespace`);i&&(r=i)})),r}function mc(t,e){let r=null;if(t&&hc(t)){const i=gc(t,e);i&&(r=i);const n=function(t,e){let r=null;return Object.values(t).forEach((t=>{if(r)return;const i=function(t,e){let r=null;return ac(t)?t.forEach((t=>{r||function(t){if(fc(t,!1)&&t.includes(":")){const e=t.split(":");if(3===e.length){const t=e[0]+":"+e[1];return!!e[2]&&dc(t)}}return!1}(t)||(r=oc("UNSUPPORTED_ACCOUNTS",`${e}, account ${t} should be a string and conform to "namespace:chainId:address" format`))})):r=oc("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),r}(t?.accounts,`${e} namespace`);i&&(r=i)})),r}(t,e);n&&(r=n)}else r=sc("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return r}function bc(t){return fc(t.protocol,!0)}function yc(t){return typeof t<"u"&&null!==typeof t}function vc(t,e){return!(!dc(e)||!function(t){const e=[];return Object.values(t).forEach((t=>{e.push(...Xh(t.accounts))})),e}(t).includes(e))}function _c(t,e,r){let i=null;const n=function(t){const e={};return Object.keys(t).forEach((r=>{var i;r.includes(":")?e[r]=t[r]:null==(i=t[r].chains)||i.forEach((i=>{e[i]={methods:t[r].methods,events:t[r].events}}))})),e}(t),s=function(t){const e={};return Object.keys(t).forEach((r=>{if(r.includes(":"))e[r]=t[r];else{const i=Xh(t[r].accounts);i?.forEach((i=>{e[i]={accounts:t[r].accounts.filter((t=>t.includes(`${i}:`))),methods:t[r].methods,events:t[r].events}}))}})),e}(e),o=Object.keys(n),a=Object.keys(s),h=Ac(Object.keys(t)),c=Ac(Object.keys(e)),f=h.filter((t=>!c.includes(t)));return f.length&&(i=sc("NON_CONFORMING_NAMESPACES",`${r} namespaces keys don't satisfy requiredNamespaces.\n Required: ${f.toString()}\n Received: ${Object.keys(e).toString()}`)),mi(o,a)||(i=sc("NON_CONFORMING_NAMESPACES",`${r} namespaces chains don't satisfy required namespaces.\n Required: ${o.toString()}\n Approved: ${a.toString()}`)),Object.keys(e).forEach((t=>{if(!t.includes(":")||i)return;const n=Xh(e[t].accounts);n.includes(t)||(i=sc("NON_CONFORMING_NAMESPACES",`${r} namespaces accounts don't satisfy namespace accounts for ${t}\n Required: ${t}\n Approved: ${n.toString()}`))})),o.forEach((t=>{i||(mi(n[t].methods,s[t].methods)?mi(n[t].events,s[t].events)||(i=sc("NON_CONFORMING_NAMESPACES",`${r} namespaces events don't satisfy namespace events for ${t}`)):i=sc("NON_CONFORMING_NAMESPACES",`${r} namespaces methods don't satisfy namespace methods for ${t}`))})),i}function Ac(t){return[...new Set(t.map((t=>t.includes(":")?t.split(":")[0]:t)))]}function Mc(t,e){return uc(t,!1)&&t<=e.max&&t>=e.min}function Sc(){const t=pi();return new Promise((e=>{switch(t){case ci.browser:e(li()&&navigator?.onLine);break;case ci.reactNative:e(async function(){if(di()&&typeof r.g<"u"&&null!=r.g&&r.g.NetInfo){const t=await(null==r.g?void 0:r.g.NetInfo.fetch());return t?.isConnected}return!0}());break;case ci.node:default:e(!0)}}))}const Ec={};class Ic{static get(t){return Ec[t]}static set(t,e){Ec[t]=e}static delete(t){delete Ec[t]}}function xc(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const Oc=xc("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),Nc=xc("ascii","a",(t=>{let e="a";for(let r=0;r{const e=function(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}((t=t.substring(1)).length);for(let r=0;re.code===t));return e||Bc[Dc]}(t.code)),t);var r}class Gc{}class $c extends Gc{constructor(){super()}}class Yc extends $c{constructor(t){super()}}function Qc(t){return function(t,e){const r=function(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(e&&e.length)return e[0]}(t);return void 0!==r&&new RegExp(e).test(r)}(t,"^wss?:")}function Xc(t){return"object"==typeof t&&"id"in t&&"jsonrpc"in t&&"2.0"===t.jsonrpc}function Zc(t){return Xc(t)&&"method"in t}function tf(t){return Xc(t)&&(ef(t)||rf(t))}function ef(t){return"result"in t}function rf(t){return"error"in t}class nf extends Yc{constructor(t){super(t),this.events=new b.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(t),this.connection.connected&&this.registerEventListeners()}async connect(t=this.connection){await this.open(t)}async disconnect(){await this.close()}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async request(t,e){return this.requestStrict(Vc(t.method,t.params||[],t.id||Kc().toString()),e)}async requestStrict(t,e){return new Promise((async(r,i)=>{if(!this.connection.connected)try{await this.open()}catch(t){i(t)}this.events.on(`${t.id}`,(t=>{rf(t)?i(t.error):r(t.result)}));try{await this.connection.send(t,e)}catch(t){i(t)}}))}setConnection(t=this.connection){return t}onPayload(t){this.events.emit("payload",t),tf(t)?this.events.emit(`${t.id}`,t):this.events.emit("message",{type:t.method,data:t.params})}onClose(t){t&&3e3===t.code&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${t.code} ${t.reason?`(${t.reason})`:""}`)),this.events.emit("disconnect")}async open(t=this.connection){this.connection===t&&this.connection.connected||(this.connection.connected&&this.close(),"string"==typeof t&&(await this.connection.open(t),t=this.connection),this.connection=this.setConnection(t),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",(t=>this.onPayload(t))),this.connection.on("close",(t=>this.onClose(t))),this.connection.on("error",(t=>this.events.emit("error",t))),this.connection.on("register_error",(t=>this.onClose())),this.hasRegisteredEventListeners=!0)}}const sf=t=>t.split("?")[0],of=typeof WebSocket<"u"?WebSocket:typeof r.g<"u"&&typeof r.g.WebSocket<"u"?r.g.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:typeof self<"u"&&typeof self.WebSocket<"u"?self.WebSocket:r(1591);class af{constructor(t){if(this.url=t,this.events=new b.EventEmitter,this.registering=!1,!Qc(t))throw new Error(`Provided URL is not compatible with WebSocket connection: ${t}`);this.url=t}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async open(t=this.url){await this.register(t)}async close(){return new Promise(((t,e)=>{typeof this.socket>"u"?e(new Error("Connection already closed")):(this.socket.onclose=e=>{this.onClose(e),t()},this.socket.close())}))}async send(t){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(F(t))}catch(e){this.onError(t.id,e)}}register(t=this.url){if(!Qc(t))throw new Error(`Provided URL is not compatible with WebSocket connection: ${t}`);if(this.registering){const t=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=t||this.events.listenerCount("open")>=t)&&this.events.setMaxListeners(t+1),new Promise(((t,e)=>{this.events.once("register_error",(t=>{this.resetMaxListeners(),e(t)})),this.events.once("open",(()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return e(new Error("WebSocket connection is missing or invalid"));t(this.socket)}))}))}return this.url=t,this.registering=!0,new Promise(((e,i)=>{const n=new URLSearchParams(t).get("origin"),s=(0,jc.isReactNative)()?{headers:{origin:n}}:{rejectUnauthorized:(a=t,!new RegExp("wss?://localhost(:d{2,5})?").test(a))},o=new of(t,[],s);var a;typeof WebSocket<"u"||typeof r.g<"u"&&typeof r.g.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u"?o.onerror=t=>{const e=t;i(this.emitError(e.error))}:o.on("error",(t=>{i(this.emitError(t))})),o.onopen=()=>{this.onOpen(o),e(o)}}))}onOpen(t){t.onmessage=t=>this.onPayload(t),t.onclose=t=>this.onClose(t),this.socket=t,this.registering=!1,this.events.emit("open")}onClose(t){this.socket=void 0,this.registering=!1,this.events.emit("close",t)}onPayload(t){if(typeof t.data>"u")return;const e="string"==typeof t.data?j(t.data):t.data;this.events.emit("payload",e)}onError(t,e){const r=this.parseError(e),i=Wc(t,r.message||r.toString());this.events.emit("payload",i)}parseError(t,e=this.url){return function(t,e,r){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable WS RPC url at ${e}`):t}(t,sf(e))}resetMaxListeners(){this.events.getMaxListeners()>10&&this.events.setMaxListeners(10)}emitError(t){const e=this.parseError(new Error(t?.message||`WebSocket connection failed for host: ${sf(this.url)}`));return this.events.emit("register_error",e),e}}var hf=r(8142),cf=r.n(hf),ff=function(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i>>0,o=new Uint8Array(s);t[e];){var f=r[t.charCodeAt(e)];if(255===f)return;for(var u=0,d=s-1;(0!==f||u>>0,o[d]=f%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");n=u,e++}if(" "!==t[e]){for(var l=s-n;l!==s&&0===o[l];)l++;for(var p=new Uint8Array(i+(s-l)),g=i;l!==s;)p[g++]=o[l++];return p}}}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,i=0,n=0,s=e.length;n!==s&&0===e[n];)n++,r++;for(var o=(s-n)*f+1>>>0,c=new Uint8Array(o);n!==s;){for(var u=e[n],d=0,l=o-1;(0!==u||d>>0,c[l]=u%a>>>0,u=u/a>>>0;if(0!==u)throw new Error("Non-zero carry");i=d,n++}for(var p=o-i;p!==o&&0===c[p];)p++;for(var g=h.repeat(r);p{if(t instanceof Uint8Array&&"Uint8Array"===t.constructor.name)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};class df{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class lf{constructor(t,e,r){if(this.name=t,this.prefix=e,void 0===e.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if("string"==typeof t){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(t){return gf(this,t)}}class pf{constructor(t){this.decoders=t}or(t){return gf(this,t)}decode(t){const e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const gf=(t,e)=>new pf({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class mf{constructor(t,e,r,i){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=i,this.encoder=new df(t,e,r),this.decoder=new lf(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const bf=({name:t,prefix:e,encode:r,decode:i})=>new mf(t,e,r,i),yf=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=ff(r,e);return bf({prefix:t,name:e,encode:i,decode:t=>uf(n(t))})},vf=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>bf({prefix:e,name:t,encode:t=>((t,e,r)=>{const i="="===e[e.length-1],n=(1<r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<((t,e,r,i)=>{const n={};for(let t=0;t=8&&(a-=8,o[c++]=255&h>>a)}if(a>=r||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o})(e,i,r,t)}),wf=bf({prefix:"\0",name:"identity",encode:t=>(t=>(new TextDecoder).decode(t))(t),decode:t=>(t=>(new TextEncoder).encode(t))(t)});var _f=Object.freeze({__proto__:null,identity:wf});const Af=vf({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mf=Object.freeze({__proto__:null,base2:Af});const Sf=vf({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ef=Object.freeze({__proto__:null,base8:Sf});const If=yf({prefix:"9",name:"base10",alphabet:"0123456789"});var xf=Object.freeze({__proto__:null,base10:If});const Of=vf({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nf=vf({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pf=Object.freeze({__proto__:null,base16:Of,base16upper:Nf});const Rf=vf({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Tf=vf({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Cf=vf({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kf=vf({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lf=vf({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qf=vf({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uf=vf({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bf=vf({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Df=vf({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zf=Object.freeze({__proto__:null,base32:Rf,base32upper:Tf,base32pad:Cf,base32padupper:kf,base32hex:Lf,base32hexupper:qf,base32hexpad:Uf,base32hexpadupper:Bf,base32z:Df});const jf=yf({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ff=yf({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Kf=Object.freeze({__proto__:null,base36:jf,base36upper:Ff});const Vf=yf({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Hf=yf({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wf=Object.freeze({__proto__:null,base58btc:Vf,base58flickr:Hf});const Jf=vf({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gf=vf({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$f=vf({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yf=vf({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qf=Object.freeze({__proto__:null,base64:Jf,base64pad:Gf,base64url:$f,base64urlpad:Yf});const Xf=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),Zf=Xf.reduce(((t,e,r)=>(t[r]=e,t)),[]),tu=Xf.reduce(((t,e,r)=>(t[e.codePointAt(0)]=r,t)),[]),eu=bf({prefix:"🚀",name:"base256emoji",encode:function(t){return t.reduce(((t,e)=>t+Zf[e]),"")},decode:function(t){const e=[];for(const r of t){const t=tu[r.codePointAt(0)];if(void 0===t)throw new Error(`Non-base256emoji character: ${r}`);e.push(t)}return new Uint8Array(e)}});var ru=Object.freeze({__proto__:null,base256emoji:eu}),iu=128,nu=-128,su=Math.pow(2,31),ou=128,au=127,hu=Math.pow(2,7),cu=Math.pow(2,14),fu=Math.pow(2,21),uu=Math.pow(2,28),du=Math.pow(2,35),lu=Math.pow(2,42),pu=Math.pow(2,49),gu=Math.pow(2,56),mu=Math.pow(2,63),bu={encode:function t(e,r,i){r=r||[];for(var n=i=i||0;e>=su;)r[i++]=255&e|iu,e/=128;for(;eν)r[i++]=255&e|iu,e>>>=7;return r[i]=0|e,t.bytes=i-n+1,r},decode:function t(e,r){var i,n=0,s=(r=r||0,0),o=r,a=e.length;do{if(o>=a)throw t.bytes=0,new RangeError("Could not decode varint");i=e[o++],n+=s<28?(i&au)<=ou);return t.bytes=o-r,n},encodingLength:function(t){return t(yu.encode(t,e,r),e),wu=t=>yu.encodingLength(t),_u=(t,e)=>{const r=e.byteLength,i=wu(t),n=i+wu(r),s=new Uint8Array(n+r);return vu(t,s,0),vu(r,s,i),s.set(e,n),new Au(t,r,e,s)};class Au{constructor(t,e,r,i){this.code=t,this.size=e,this.digest=r,this.bytes=i}}const Mu=({name:t,code:e,encode:r})=>new Su(t,e,r);class Su{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){const e=this.encode(t);return e instanceof Uint8Array?_u(this.code,e):e.then((t=>_u(this.code,t)))}throw Error("Unknown type, must be binary type")}}const Eu=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Iu=Mu({name:"sha2-256",code:18,encode:Eu("SHA-256")}),xu=Mu({name:"sha2-512",code:19,encode:Eu("SHA-512")});Object.freeze({__proto__:null,sha256:Iu,sha512:xu});const Ou=uf,Nu={code:0,name:"identity",encode:Ou,digest:t=>_u(0,Ou(t))};Object.freeze({__proto__:null,identity:Nu}),new TextEncoder,new TextDecoder;const Pu={..._f,...Mf,...Ef,...xf,...Pf,...zf,...Kf,...Wf,...Qf,...ru};function Ru(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const Tu=Ru("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),Cu=Ru("ascii","a",(t=>{let e="a";for(let r=0;r{const e=function(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}((t=t.substring(1)).length);for(let r=0;r{if(!this.initialized){const t=await this.getKeyChain();typeof t<"u"&&(this.keychain=t),this.initialized=!0}},this.has=t=>(this.isInitialized(),this.keychain.has(t)),this.set=async(t,e)=>{this.isInitialized(),this.keychain.set(t,e),await this.persist()},this.get=t=>{this.isInitialized();const e=this.keychain.get(t);if(typeof e>"u"){const{message:e}=sc("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(e)}return e},this.del=async t=>{this.isInitialized(),this.keychain.delete(t),await this.persist()},this.core=t,this.logger=_t(e,this.name)}get context(){return wt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(t){await this.core.storage.setItem(this.storageKey,bi(t))}async getKeyChain(){const t=await this.core.storage.getItem(this.storageKey);return typeof t<"u"?yi(t):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}}class yd{constructor(t,e,r){this.core=t,this.logger=e,this.name="crypto",this.randomSessionIdentifier=vh(),this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=t=>(this.isInitialized(),this.keychain.has(t)),this.getClientId=async()=>(this.isInitialized(),Mr(Er(await this.getClientSeed()).publicKey)),this.generateKeyPair=()=>{this.isInitialized();const t=function(){const t=Kr.TZ();return{privateKey:Qr(t.secretKey,gh),publicKey:Qr(t.publicKey,gh)}}();return this.setPrivateKey(t.publicKey,t.privateKey)},this.signJWT=async t=>{this.isInitialized();const e=Er(await this.getClientSeed()),r=this.randomSessionIdentifier,i=Du;return await async function(t,e,r,i,n=(0,Y.fromMiliseconds)(Date.now())){const s={alg:"EdDSA",typ:"JWT"},o={iss:Mr(i.publicKey),sub:t,aud:e,iat:n,exp:n+r},a=wr([Ar((h={header:s,payload:o}).header),Ar(h.payload)].join(Bt),jt);var h;return function(t){return[Ar(t.header),Ar(t.payload),(e=t.signature,vr(e,Dt))].join(Bt);var e}({header:s,payload:o,signature:qt._S(i.secretKey,a)})}(r,t,i,e)},this.generateSharedKey=(t,e,r)=>{this.isInitialized();const i=function(t,e){const r=Kr.Tc(Yr(t,gh),Yr(e,gh),!0);return Qr(new jr.i(Fr.aD,r).expand(32),gh)}(this.getPrivateKey(t),e);return this.setSymKey(i,r)},this.setSymKey=async(t,e)=>{this.isInitialized();const r=e||wh(t);return await this.keychain.set(r,t),r},this.deleteKeyPair=async t=>{this.isInitialized(),await this.keychain.del(t)},this.deleteSymKey=async t=>{this.isInitialized(),await this.keychain.del(t)},this.encode=async(t,e,r)=>{this.isInitialized();const i=Ih(r),n=F(e);if(Oh(i))return function(t,e){const r=Ah(2),i=(0,Ut.randomBytes)(12);return Sh({type:r,sealed:Yr(t,yh),iv:i,encoding:e})}(n,r?.encoding);if(xh(i)){const e=i.senderPublicKey,r=i.receiverPublicKey;t=await this.generateSharedKey(e,r)}const s=this.getSymKey(t),{type:o,senderPublicKey:a}=i;return function(t){const e=Ah(typeof t.type<"u"?t.type:0);if(1===Mh(e)&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const r=typeof t.senderPublicKey<"u"?Yr(t.senderPublicKey,gh):void 0,i=typeof t.iv<"u"?Yr(t.iv,gh):(0,Ut.randomBytes)(12);return Sh({type:e,sealed:new zr.g6(Yr(t.symKey,gh)).seal(i,Yr(t.message,yh)),iv:i,senderPublicKey:r,encoding:t.encoding})}({type:o,symKey:s,message:n,senderPublicKey:a,encoding:r?.encoding})},this.decode=async(t,e,r)=>{this.isInitialized();const i=function(t,e){const r=Eh({encoded:t,encoding:e?.encoding});return Ih({type:Mh(r.type),senderPublicKey:typeof r.senderPublicKey<"u"?Qr(r.senderPublicKey,gh):void 0,receiverPublicKey:e?.receiverPublicKey})}(e,r);if(Oh(i)){const t=function(t,e){const{sealed:r}=Eh({encoded:t,encoding:e});return Qr(r,yh)}(e,r?.encoding);return j(t)}if(xh(i)){const e=i.receiverPublicKey,r=i.senderPublicKey;t=await this.generateSharedKey(e,r)}try{const i=function(t){const e=new zr.g6(Yr(t.symKey,gh)),{sealed:r,iv:i}=Eh({encoded:t.encoded,encoding:t?.encoding}),n=e.open(i,r);if(null===n)throw new Error("Failed to decrypt");return Qr(n,yh)}({symKey:this.getSymKey(t),encoded:e,encoding:r?.encoding});return j(i)}catch(e){this.logger.error(`Failed to decode message from topic: '${t}', clientId: '${await this.getClientId()}'`),this.logger.error(e)}},this.getPayloadType=(t,e=mh)=>Mh(Eh({encoded:t,encoding:e}).type),this.getPayloadSenderPublicKey=(t,e=mh)=>{const r=Eh({encoded:t,encoding:e});return r.senderPublicKey?function(t,e="utf8"){const r=Pc[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return"utf8"!==e&&"utf-8"!==e||null==globalThis.Buffer||null==globalThis.Buffer.from?r.encoder.encode(t).substring(1):globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8")}(r.senderPublicKey,gh):void 0},this.core=t,this.logger=_t(e,this.name),this.keychain=r||new bd(this.core,this.logger)}get context(){return wt(this.logger)}async setPrivateKey(t,e){return await this.keychain.set(t,e),t}getPrivateKey(t){return this.keychain.get(t)}async getClientSeed(){let t="";try{t=this.keychain.get(Bu)}catch{t=vh(),await this.keychain.set(Bu,t)}return function(t,e="utf8"){const r=ku[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return"utf8"!==e&&"utf-8"!==e||null==globalThis.Buffer||null==globalThis.Buffer.from?r.decoder.decode(`${r.prefix}${t}`):globalThis.Buffer.from(t,"utf8")}(t,"base16")}getSymKey(t){return this.keychain.get(t)}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}}class vd extends Et{constructor(t,e){super(t,e),this.logger=t,this.core=e,this.messages=new Map,this.name="messages",this.version="0.3",this.initialized=!1,this.storagePrefix=qu,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const t=await this.getRelayerMessages();typeof t<"u"&&(this.messages=t),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(t){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(t)}finally{this.initialized=!0}}},this.set=async(t,e)=>{this.isInitialized();const r=_h(e);let i=this.messages.get(t);return typeof i>"u"&&(i={}),typeof i[r]<"u"||(i[r]=e,this.messages.set(t,i),await this.persist()),r},this.get=t=>{this.isInitialized();let e=this.messages.get(t);return typeof e>"u"&&(e={}),e},this.has=(t,e)=>(this.isInitialized(),typeof this.get(t)[_h(e)]<"u"),this.del=async t=>{this.isInitialized(),this.messages.delete(t),await this.persist()},this.logger=_t(t,this.name),this.core=e}get context(){return wt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setRelayerMessages(t){await this.core.storage.setItem(this.storageKey,bi(t))}async getRelayerMessages(){const t=await this.core.storage.getItem(this.storageKey);return typeof t<"u"?yi(t):void 0}async persist(){await this.setRelayerMessages(this.messages)}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}}class wd extends It{constructor(t,e){super(t,e),this.relayer=t,this.logger=e,this.events=new b.EventEmitter,this.name="publisher",this.queue=new Map,this.publishTimeout=(0,Y.toMiliseconds)(Y.ONE_MINUTE),this.failedPublishTimeout=(0,Y.toMiliseconds)(Y.ONE_SECOND),this.needsTransportRestart=!1,this.publish=async(t,e,r)=>{var i;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:t,message:e,opts:r}});const n=r?.ttl||zu,s=Nh(r),o=r?.prompt||!1,a=r?.tag||0,h=r?.id||Kc().toString(),c={topic:t,message:e,opts:{ttl:n,relay:s,prompt:o,tag:a,id:h,attestation:r?.attestation}},f=`Failed to publish payload, please try again. id:${h} tag:${a}`,u=Date.now();let d,l=1;try{for(;void 0===d;){if(Date.now()-u>this.publishTimeout)throw new Error(f);this.logger.trace({id:h,attempts:l},`publisher.publish - attempt ${l}`),d=await await wi(this.rpcPublish(t,e,n,s,o,a,h,r?.attestation).catch((t=>this.logger.warn(t))),this.publishTimeout,f),l++,d||await new Promise((t=>setTimeout(t,this.failedPublishTimeout)))}this.relayer.events.emit(Hu,c),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{id:h,topic:t,message:e,opts:r}})}catch(t){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(t),null!=(i=r?.internal)&&i.throwOnFailedPublish)throw t;this.queue.set(h,c)}},this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.relayer=t,this.logger=_t(e,this.name),this.registerEventListeners()}get context(){return wt(this.logger)}rpcPublish(t,e,r,i,n,s,o,a){var h,c,f,u;const d={method:Ph(i.protocol).publish,params:{topic:t,message:e,ttl:r,prompt:n,tag:s,attestation:a},id:o};return cc(null==(h=d.params)?void 0:h.prompt)&&(null==(c=d.params)||delete c.prompt),cc(null==(f=d.params)?void 0:f.tag)&&(null==(u=d.params)||delete u.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:d}),this.relayer.request(d)}removeRequestFromQueue(t){this.queue.delete(t)}checkQueue(){this.queue.forEach((async t=>{const{topic:e,message:r,opts:i}=t;await this.publish(e,r,i)}))}registerEventListeners(){this.relayer.core.heartbeat.on(tt,(()=>{if(this.needsTransportRestart)return this.needsTransportRestart=!1,void this.relayer.events.emit(Vu);this.checkQueue()})),this.relayer.on(Ku,(t=>{this.removeRequestFromQueue(t.id.toString())}))}}class _d{constructor(){this.map=new Map,this.set=(t,e)=>{const r=this.get(t);this.exists(t,e)||this.map.set(t,[...r,e])},this.get=t=>this.map.get(t)||[],this.exists=(t,e)=>this.get(t).includes(e),this.delete=(t,e)=>{if(typeof e>"u")return void this.map.delete(t);if(!this.map.has(t))return;const r=this.get(t);if(!this.exists(t,e))return;const i=r.filter((t=>t!==e));i.length?this.map.set(t,i):this.map.delete(t)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}}var Ad=Object.defineProperty,Md=Object.defineProperties,Sd=Object.getOwnPropertyDescriptors,Ed=Object.getOwnPropertySymbols,Id=Object.prototype.hasOwnProperty,xd=Object.prototype.propertyIsEnumerable,Od=(t,e,r)=>e in t?Ad(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nd=(t,e)=>{for(var r in e||(e={}))Id.call(e,r)&&Od(t,r,e[r]);if(Ed)for(var r of Ed(e))xd.call(e,r)&&Od(t,r,e[r]);return t},Pd=(t,e)=>Md(t,Sd(e));class Rd extends Nt{constructor(t,e){super(t,e),this.relayer=t,this.logger=e,this.subscriptions=new Map,this.topicMap=new _d,this.events=new b.EventEmitter,this.name="subscription",this.version="0.3",this.pending=new Map,this.cached=[],this.initialized=!1,this.pendingSubscriptionWatchLabel="pending_sub_watch_label",this.pollingInterval=20,this.storagePrefix=qu,this.subscribeTimeout=(0,Y.toMiliseconds)(Y.ONE_MINUTE),this.restartInProgress=!1,this.batchSubscribeTopicsLimit=500,this.pendingBatchMessages=[],this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),this.clientId=await this.relayer.core.crypto.getClientId(),await this.restore()),this.initialized=!0},this.subscribe=async(t,e)=>{this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:t,opts:e}});try{const r=Nh(e),i={topic:t,relay:r,transportType:e?.transportType};this.pending.set(t,i);const n=await this.rpcSubscribe(t,r,e?.transportType);return"string"==typeof n&&(this.onSubscribe(n,i),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:t,opts:e}})),n}catch(t){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(t),t}},this.unsubscribe=async(t,e)=>{await this.restartToComplete(),this.isInitialized(),typeof e?.id<"u"?await this.unsubscribeById(t,e.id,e):await this.unsubscribeByTopic(t,e)},this.isSubscribed=async t=>{if(this.topics.includes(t))return!0;const e=`${this.pendingSubscriptionWatchLabel}_${t}`;return await new Promise(((r,i)=>{const n=new Y.Watch;n.start(e);const s=setInterval((()=>{!this.pending.has(t)&&this.topics.includes(t)&&(clearInterval(s),n.stop(e),r(!0)),n.elapsed(e)>=ed&&(clearInterval(s),n.stop(e),i(new Error("Subscription resolution timeout")))}),this.pollingInterval)})).catch((()=>!1))},this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.start=async()=>{await this.onConnect()},this.stop=async()=>{await this.onDisconnect()},this.restart=async()=>{this.restartInProgress=!0,await this.restore(),await this.reset(),this.restartInProgress=!1},this.relayer=t,this.logger=_t(e,this.name),this.clientId=""}get context(){return wt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.relayer.core.customStoragePrefix+"//"+this.name}get length(){return this.subscriptions.size}get ids(){return Array.from(this.subscriptions.keys())}get values(){return Array.from(this.subscriptions.values())}get topics(){return this.topicMap.topics}hasSubscription(t,e){let r=!1;try{r=this.getSubscription(t).topic===e}catch{}return r}onEnable(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(t,e){const r=this.topicMap.get(t);await Promise.all(r.map((async r=>await this.unsubscribeById(t,r,e))))}async unsubscribeById(t,e,r){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:t,id:e,opts:r}});try{const i=Nh(r);await this.rpcUnsubscribe(t,e,i);const n=oc("USER_DISCONNECTED",`${this.name}, ${t}`);await this.onUnsubscribe(t,e,n),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:t,id:e,opts:r}})}catch(t){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(t),t}}async rpcSubscribe(t,e,r=Qu.relay){r===Qu.relay&&await this.restartToComplete();const i={method:Ph(e.protocol).subscribe,params:{topic:t}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i});try{const e=_h(t+this.clientId);return r===Qu.link_mode?(setTimeout((()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(i).catch((t=>this.logger.warn(t)))}),(0,Y.toMiliseconds)(Y.ONE_SECOND)),e):await await wi(this.relayer.request(i).catch((t=>this.logger.warn(t))),this.subscribeTimeout)?e:null}catch{this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Vu)}return null}async rpcBatchSubscribe(t){if(!t.length)return;const e={method:Ph(t[0].relay.protocol).batchSubscribe,params:{topics:t.map((t=>t.topic))}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:e});try{return await await wi(this.relayer.request(e).catch((t=>this.logger.warn(t))),this.subscribeTimeout)}catch{this.relayer.events.emit(Vu)}}async rpcBatchFetchMessages(t){if(!t.length)return;const e={method:Ph(t[0].relay.protocol).batchFetchMessages,params:{topics:t.map((t=>t.topic))}};let r;this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:e});try{r=await await wi(this.relayer.request(e).catch((t=>this.logger.warn(t))),this.subscribeTimeout)}catch{this.relayer.events.emit(Vu)}return r}rpcUnsubscribe(t,e,r){const i={method:Ph(r.protocol).unsubscribe,params:{topic:t,id:e}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(t,e){this.setSubscription(t,Pd(Nd({},e),{id:t})),this.pending.delete(e.topic)}onBatchSubscribe(t){t.length&&t.forEach((t=>{this.setSubscription(t.id,Nd({},t)),this.pending.delete(t.topic)}))}async onUnsubscribe(t,e,r){this.events.removeAllListeners(e),this.hasSubscription(e,t)&&this.deleteSubscription(e,r),await this.relayer.messages.del(t)}async setRelayerSubscriptions(t){await this.relayer.core.storage.setItem(this.storageKey,t)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(t,e){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:t,subscription:e}),this.addSubscription(t,e)}addSubscription(t,e){this.subscriptions.set(t,Nd({},e)),this.topicMap.set(e.topic,t),this.events.emit(Zu,e)}getSubscription(t){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:t});const e=this.subscriptions.get(t);if(!e){const{message:e}=sc("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(e)}return e}deleteSubscription(t,e){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:t,reason:e});const r=this.getSubscription(t);this.subscriptions.delete(t),this.topicMap.delete(r.topic,t),this.events.emit(td,Pd(Nd({},r),{reason:e}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit("subscription_sync")}async reset(){if(this.cached.length){const t=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let e=0;e"u"||!t.length)return;if(this.subscriptions.size){const{message:t}=sc("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(t){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(t)}}async batchSubscribe(t){if(!t.length)return;const e=await this.rpcBatchSubscribe(t);ac(e)&&this.onBatchSubscribe(e.map(((e,r)=>Pd(Nd({},t[r]),{id:e}))))}async batchFetchMessages(t){if(!t.length)return;this.logger.trace(`Fetching batch messages for ${t.length} subscriptions`);const e=await this.rpcBatchFetchMessages(t);e&&e.messages&&(this.pendingBatchMessages=this.pendingBatchMessages.concat(e.messages))}async onConnect(){await this.restart(),this.onEnable()}onDisconnect(){this.onDisable()}async checkPending(){if(!this.initialized||!this.relayer.connected)return;const t=[];this.pending.forEach((e=>{t.push(e)})),await this.batchSubscribe(t),this.pendingBatchMessages.length&&(await this.relayer.handleBatchMessageEvents(this.pendingBatchMessages),this.pendingBatchMessages=[])}registerEventListeners(){this.relayer.core.heartbeat.on(tt,(async()=>{await this.checkPending()})),this.events.on(Zu,(async t=>{const e=Zu;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),await this.persist()})),this.events.on(td,(async t=>{const e=td;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),await this.persist()}))}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}async restartToComplete(){!this.relayer.connected&&!this.relayer.connecting&&await this.relayer.transportOpen(),this.restartInProgress&&await new Promise((t=>{const e=setInterval((()=>{this.restartInProgress||(clearInterval(e),t())}),this.pollingInterval)}))}}var Td=Object.defineProperty,Cd=Object.getOwnPropertySymbols,kd=Object.prototype.hasOwnProperty,Ld=Object.prototype.propertyIsEnumerable,qd=(t,e,r)=>e in t?Td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;class Ud extends xt{constructor(t){super(t),this.protocol="wc",this.version=2,this.events=new b.EventEmitter,this.name="relayer",this.transportExplicitlyClosed=!1,this.initialized=!1,this.connectionAttemptInProgress=!1,this.connectionStatusPollingInterval=20,this.staleConnectionErrors=["socket hang up","stalled","interrupted"],this.hasExperiencedNetworkDisruption=!1,this.requestsInFlight=new Map,this.heartBeatTimeout=(0,Y.toMiliseconds)(Y.THIRTY_SECONDS+Y.ONE_SECOND),this.request=async t=>{var e,r;this.logger.debug("Publishing Request Payload");const i=t.id||Kc().toString();await this.toEstablishConnection();try{const n=this.provider.request(t);this.requestsInFlight.set(i,{promise:n,request:t}),this.logger.trace({id:i,method:t.method,topic:null==(e=t.params)?void 0:e.topic},"relayer.request - attempt to publish...");const s=await new Promise((async(t,e)=>{const r=()=>{e(new Error(`relayer.request - publish interrupted, id: ${i}`))};this.provider.on(Gu,r);const s=await n;this.provider.off(Gu,r),t(s)}));return this.logger.trace({id:i,method:t.method,topic:null==(r=t.params)?void 0:r.topic},"relayer.request - published"),s}catch(t){throw this.logger.debug(`Failed to Publish Request: ${i}`),t}finally{this.requestsInFlight.delete(i)}},this.resetPingTimeout=()=>{if(ui())try{clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout((()=>{var t,e,r;null==(r=null==(e=null==(t=this.provider)?void 0:t.connection)?void 0:e.socket)||r.terminate()}),this.heartBeatTimeout)}catch(t){this.logger.warn(t)}},this.onPayloadHandler=t=>{this.onProviderPayload(t),this.resetPingTimeout()},this.onConnectHandler=()=>{this.logger.trace("relayer connected"),this.startPingTimeout(),this.events.emit("relayer_connect")},this.onDisconnectHandler=()=>{this.logger.trace("relayer disconnected"),this.onProviderDisconnect()},this.onProviderErrorHandler=t=>{this.logger.error(t),this.events.emit("relayer_error",t),this.logger.info("Fatal socket error received, closing transport"),this.transportClose()},this.registerProviderListeners=()=>{this.provider.on(Wu,this.onPayloadHandler),this.provider.on(Ju,this.onConnectHandler),this.provider.on(Gu,this.onDisconnectHandler),this.provider.on($u,this.onProviderErrorHandler)},this.core=t.core,this.logger=typeof t.logger<"u"&&"string"!=typeof t.logger?_t(t.logger,this.name):it()(vt({level:t.logger||"error"})),this.messages=new vd(this.logger,t.core),this.subscriber=new Rd(this,this.logger),this.publisher=new wd(this,this.logger),this.relayUrl=t?.relayUrl||ju,this.projectId=t.projectId,this.bundleId=function(){var t;try{return di()&&typeof r.g<"u"&&typeof(null==r.g?void 0:r.g.Application)<"u"?null==(t=r.g.Application)?void 0:t.applicationId:void 0}catch{return}}(),this.provider={}}async init(){if(this.logger.trace("Initialized"),this.registerEventListeners(),await Promise.all([this.messages.init(),this.subscriber.init()]),this.initialized=!0,this.subscriber.cached.length>0)try{await this.transportOpen()}catch(t){this.logger.warn(t)}}get context(){return wt(this.logger)}get connected(){var t,e,r;return 1===(null==(r=null==(e=null==(t=this.provider)?void 0:t.connection)?void 0:e.socket)?void 0:r.readyState)}get connecting(){var t,e,r;return 0===(null==(r=null==(e=null==(t=this.provider)?void 0:t.connection)?void 0:e.socket)?void 0:r.readyState)}async publish(t,e,r){this.isInitialized(),await this.publisher.publish(t,e,r),await this.recordMessageEvent({topic:t,message:e,publishedAt:Date.now(),transportType:Qu.relay})}async subscribe(t,e){var r;this.isInitialized(),"relay"===e?.transportType&&await this.toEstablishConnection();let i,n=(null==(r=this.subscriber.topicMap.get(t))?void 0:r[0])||"";const s=e=>{e.topic===t&&(this.subscriber.off(Zu,s),i())};return await Promise.all([new Promise((t=>{i=t,this.subscriber.on(Zu,s)})),new Promise((async r=>{n=await this.subscriber.subscribe(t,e)||n,r()}))]),n}async unsubscribe(t,e){this.isInitialized(),await this.subscriber.unsubscribe(t,e)}on(t,e){this.events.on(t,e)}once(t,e){this.events.once(t,e)}off(t,e){this.events.off(t,e)}removeListener(t,e){this.events.removeListener(t,e)}async transportDisconnect(){if(!this.hasExperiencedNetworkDisruption&&this.connected&&this.requestsInFlight.size>0)try{await Promise.all(Array.from(this.requestsInFlight.values()).map((t=>t.promise)))}catch(t){this.logger.warn(t)}this.hasExperiencedNetworkDisruption||this.connected?await wi(this.provider.disconnect(),2e3,"provider.disconnect()").catch((()=>this.onProviderDisconnect())):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,await this.transportDisconnect()}async transportOpen(t){await this.confirmOnlineStateOrThrow(),t&&t!==this.relayUrl&&(this.relayUrl=t,await this.transportDisconnect()),await this.createProvider(),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;try{await new Promise((async(t,e)=>{const r=()=>{this.provider.off(Gu,r),e(new Error("Connection interrupted while trying to subscribe"))};this.provider.on(Gu,r),await wi(this.provider.connect(),(0,Y.toMiliseconds)(Y.ONE_MINUTE),`Socket stalled when trying to connect to ${this.relayUrl}`).catch((t=>{e(t)})).finally((()=>{clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0})),this.subscriber.start().catch((t=>{this.logger.error(t),this.onDisconnectHandler()})),this.hasExperiencedNetworkDisruption=!1,t()}))}catch(t){this.logger.error(t);const e=t;if(this.hasExperiencedNetworkDisruption=!0,!this.isConnectionStalled(e.message))throw t}finally{this.connectionAttemptInProgress=!1}}async restartTransport(t){this.connectionAttemptInProgress||(this.relayUrl=t||this.relayUrl,await this.confirmOnlineStateOrThrow(),await this.transportClose(),await this.transportOpen())}async confirmOnlineStateOrThrow(){if(!await Sc())throw new Error("No internet connection detected. Please restart your network and try again.")}async handleBatchMessageEvents(t){if(0===t?.length)return void this.logger.trace("Batch message events is empty. Ignoring...");const e=t.sort(((t,e)=>t.publishedAt-e.publishedAt));this.logger.trace(`Batch of ${e.length} message events sorted`);for(const t of e)try{await this.onMessageEvent(t)}catch(t){this.logger.warn(t)}this.logger.trace(`Batch of ${e.length} message events processed`)}async onLinkMessageEvent(t,e){const{topic:r}=t;if(!e.sessionExists){const t={topic:r,expiry:Mi(Y.FIVE_MINUTES),relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(r,t)}this.events.emit(Fu,t),await this.recordMessageEvent(t)}startPingTimeout(){var t,e,r,i,n;if(ui())try{null!=(e=null==(t=this.provider)?void 0:t.connection)&&e.socket&&(null==(n=null==(i=null==(r=this.provider)?void 0:r.connection)?void 0:i.socket)||n.once("ping",(()=>{this.resetPingTimeout()}))),this.resetPingTimeout()}catch(t){this.logger.warn(t)}}isConnectionStalled(t){return this.staleConnectionErrors.some((e=>t.includes(e)))}async createProvider(){this.provider.connection&&this.unregisterProviderListeners();const t=await this.core.crypto.signJWT(this.relayUrl);this.provider=new nf(new af(function({protocol:t,version:e,relayUrl:r,sdkVersion:i,auth:n,projectId:s,useOnCloseEvent:o,bundleId:a}){const h=r.split("?"),c={auth:n,ua:gi(t,e,i),projectId:s,useOnCloseEvent:o||void 0,origin:a||void 0},f=function(t,e){let r=Dr.parse(t);return r=ai(ai({},r),e),Dr.stringify(r)}(h[1]||"",c);return h[0]+"?"+f}({sdkVersion:Yu,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:t,useOnCloseEvent:!0,bundleId:this.bundleId}))),this.registerProviderListeners()}async recordMessageEvent(t){const{topic:e,message:r}=t;await this.messages.set(e,r)}async shouldIgnoreMessageEvent(t){const{topic:e,message:r}=t;if(!r||0===r.length)return this.logger.debug(`Ignoring invalid/empty message: ${r}`),!0;if(!await this.subscriber.isSubscribed(e))return this.logger.debug(`Ignoring message for non-subscribed topic ${e}`),!0;const i=this.messages.has(e,r);return i&&this.logger.debug(`Ignoring duplicate message: ${r}`),i}async onProviderPayload(t){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:t}),Zc(t)){if(!t.method.endsWith("_subscription"))return;const e=t.params,{topic:r,message:i,publishedAt:n,attestation:s}=e.data,o={topic:r,message:i,publishedAt:n,transportType:Qu.relay,attestation:s};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(((t,e)=>{for(var r in e||(e={}))kd.call(e,r)&&qd(t,r,e[r]);if(Cd)for(var r of Cd(e))Ld.call(e,r)&&qd(t,r,e[r]);return t})({type:"event",event:e.id},o)),this.events.emit(e.id,o),await this.acknowledgePayload(t),await this.onMessageEvent(o)}else tf(t)&&this.events.emit(Ku,t)}async onMessageEvent(t){await this.shouldIgnoreMessageEvent(t)||(this.events.emit(Fu,t),await this.recordMessageEvent(t))}async acknowledgePayload(t){const e=Hc(t.id,!0);await this.provider.connection.send(e)}unregisterProviderListeners(){this.provider.off(Wu,this.onPayloadHandler),this.provider.off(Ju,this.onConnectHandler),this.provider.off(Gu,this.onDisconnectHandler),this.provider.off($u,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let t=await Sc();!function(t){switch(pi()){case ci.browser:!function(t){!di()&&li()&&(window.addEventListener("online",(()=>t(!0))),window.addEventListener("offline",(()=>t(!1))))}(t);break;case ci.reactNative:!function(t){di()&&typeof r.g<"u"&&null!=r.g&&r.g.NetInfo&&r.g?.NetInfo.addEventListener((e=>t(e?.isConnected)))}(t);case ci.node:}}((async e=>{t!==e&&(t=e,e?await this.restartTransport().catch((t=>this.logger.error(t))):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))}))}async onProviderDisconnect(){await this.subscriber.stop(),this.requestsInFlight.clear(),clearTimeout(this.pingTimeout),this.events.emit("relayer_disconnect"),this.connectionAttemptInProgress=!1,!this.transportExplicitlyClosed&&(this.reconnectTimeout||(this.reconnectTimeout=setTimeout((async()=>{await this.transportOpen().catch((t=>this.logger.error(t)))}),(0,Y.toMiliseconds)(.1))))}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}async toEstablishConnection(){await this.confirmOnlineStateOrThrow(),!this.connected&&(this.connectionAttemptInProgress&&await new Promise((t=>{const e=setInterval((()=>{this.connected&&(clearInterval(e),t())}),this.connectionStatusPollingInterval)})),await this.transportOpen())}}var Bd=Object.defineProperty,Dd=Object.getOwnPropertySymbols,zd=Object.prototype.hasOwnProperty,jd=Object.prototype.propertyIsEnumerable,Fd=(t,e,r)=>e in t?Bd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kd=(t,e)=>{for(var r in e||(e={}))zd.call(e,r)&&Fd(t,r,e[r]);if(Dd)for(var r of Dd(e))jd.call(e,r)&&Fd(t,r,e[r]);return t};class Vd extends Ot{constructor(t,e,r,i=qu,n=void 0){super(t,e,r,i),this.core=t,this.logger=e,this.name=r,this.map=new Map,this.version="0.3",this.cached=[],this.initialized=!1,this.storagePrefix=qu,this.recentlyDeleted=[],this.recentlyDeletedLimit=200,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach((t=>{this.getKey&&null!==t&&!cc(t)?this.map.set(this.getKey(t),t):function(t){var e;return null==(e=t?.proposer)?void 0:e.publicKey}(t)?this.map.set(t.id,t):function(t){return t?.topic}(t)&&this.map.set(t.topic,t)})),this.cached=[],this.initialized=!0)},this.set=async(t,e)=>{this.isInitialized(),this.map.has(t)?await this.update(t,e):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:t,value:e}),this.map.set(t,e),await this.persist())},this.get=t=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:t}),this.getData(t)),this.getAll=t=>(this.isInitialized(),t?this.values.filter((e=>Object.keys(t).every((r=>cf()(e[r],t[r]))))):this.values),this.update=async(t,e)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:t,update:e});const r=Kd(Kd({},this.getData(t)),e);this.map.set(t,r),await this.persist()},this.delete=async(t,e)=>{this.isInitialized(),this.map.has(t)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:t,reason:e}),this.map.delete(t),this.addToRecentlyDeleted(t),await this.persist())},this.logger=_t(e,this.name),this.storagePrefix=i,this.getKey=n}get context(){return wt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.map.size}get keys(){return Array.from(this.map.keys())}get values(){return Array.from(this.map.values())}addToRecentlyDeleted(t){this.recentlyDeleted.push(t),this.recentlyDeleted.length>=this.recentlyDeletedLimit&&this.recentlyDeleted.splice(0,this.recentlyDeletedLimit/2)}async setDataStore(t){await this.core.storage.setItem(this.storageKey,t)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(t){const e=this.map.get(t);if(!e){if(this.recentlyDeleted.includes(t)){const{message:e}=sc("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${t}`);throw this.logger.error(e),new Error(e)}const{message:e}=sc("NO_MATCHING_KEY",`${this.name}: ${t}`);throw this.logger.error(e),new Error(e)}return e}async persist(){await this.setDataStore(this.values)}async restore(){try{const t=await this.getDataStore();if(typeof t>"u"||!t.length)return;if(this.map.size){const{message:t}=sc("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(t){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(t)}}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Hd{constructor(t,e){this.core=t,this.logger=e,this.name="pairing",this.version="0.3",this.events=new(y()),this.initialized=!1,this.storagePrefix=qu,this.ignoredPayloadTypes=[1],this.registeredMethods=[],this.init=async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))},this.register=({methods:t})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...t])]},this.create=async t=>{this.isInitialized();const e=vh(),r=await this.core.crypto.setSymKey(e),i=Mi(Y.FIVE_MINUTES),n={protocol:"irn"},s={topic:r,expiry:i,relay:n,active:!1},o=function(t){return`${t.protocol}:${t.topic}@${t.version}?`+Dr.stringify(Bh(((t,e)=>Th(t,Ch(e)))(Bh({symKey:t.symKey},function(t,e="-"){const r={};return Object.keys(t).forEach((i=>{const n="relay"+e+i;t[i]&&(r[n]=t[i])})),r}(t.relay)),{expiryTimestamp:t.expiryTimestamp}),t.methods?{methods:t.methods.join(",")}:{}))}({protocol:this.core.protocol,version:this.core.version,topic:r,symKey:e,relay:n,expiryTimestamp:i,methods:t?.methods});return this.core.expirer.set(r,i),await this.pairings.set(r,s),await this.core.relayer.subscribe(r,{transportType:t?.transportType}),{topic:r,uri:o}},this.pair=async t=>{this.isInitialized();const e=this.core.eventClient.createEvent({properties:{topic:t?.uri,trace:["pairing_started"]}});this.isValidPair(t,e);const{topic:r,symKey:i,relay:n,expiryTimestamp:s,methods:o}=zh(t.uri);let a;if(e.props.properties.topic=r,e.addTrace("pairing_uri_validation_success"),e.addTrace("pairing_uri_not_expired"),this.pairings.keys.includes(r)){if(a=this.pairings.get(r),e.addTrace("existing_pairing"),a.active)throw e.setError("active_pairing_already_exists"),new Error(`Pairing already exists: ${r}. Please try again with a new connection URI.`);e.addTrace("pairing_not_expired")}const h=s||Mi(Y.FIVE_MINUTES),c={topic:r,relay:n,expiry:h,active:!1,methods:o};this.core.expirer.set(r,h),await this.pairings.set(r,c),e.addTrace("store_new_pairing"),t.activatePairing&&await this.activate({topic:r}),this.events.emit(id,c),e.addTrace("emit_inactive_pairing"),this.core.crypto.keychain.has(r)||await this.core.crypto.setSymKey(i,r),e.addTrace("subscribing_pairing_topic");try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{e.setError("no_internet_connection")}try{await this.core.relayer.subscribe(r,{relay:n})}catch(t){throw e.setError("subscribe_pairing_topic_failure"),t}return e.addTrace("subscribe_pairing_topic_success"),c},this.activate=async({topic:t})=>{this.isInitialized();const e=Mi(Y.THIRTY_DAYS);this.core.expirer.set(t,e),await this.pairings.update(t,{active:!0,expiry:e})},this.ping=async t=>{this.isInitialized(),await this.isValidPing(t);const{topic:e}=t;if(this.pairings.keys.includes(e)){const t=await this.sendRequest(e,"wc_pairingPing",{}),{done:r,resolve:i,reject:n}=vi();this.events.once(Ei("pairing_ping",t),(({error:t})=>{t?n(t):i()})),await r()}},this.updateExpiry=async({topic:t,expiry:e})=>{this.isInitialized(),await this.pairings.update(t,{expiry:e})},this.updateMetadata=async({topic:t,metadata:e})=>{this.isInitialized(),await this.pairings.update(t,{peerMetadata:e})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async t=>{this.isInitialized(),await this.isValidDisconnect(t);const{topic:e}=t;this.pairings.keys.includes(e)&&(await this.sendRequest(e,"wc_pairingDelete",oc("USER_DISCONNECTED")),await this.deletePairing(e))},this.sendRequest=async(t,e,r)=>{const i=Vc(e,r),n=await this.core.crypto.encode(t,i),s=rd[e].req;return this.core.history.set(t,i),this.core.relayer.publish(t,n,s),i.id},this.sendResult=async(t,e,r)=>{const i=Hc(t,r),n=await this.core.crypto.encode(e,i),s=await this.core.history.get(e,t),o=rd[s.request.method].res;await this.core.relayer.publish(e,n,o),await this.core.history.resolve(i)},this.sendError=async(t,e,r)=>{const i=Wc(t,r),n=await this.core.crypto.encode(e,i),s=await this.core.history.get(e,t),o=rd[s.request.method]?rd[s.request.method].res:rd.unregistered_method.res;await this.core.relayer.publish(e,n,o),await this.core.history.resolve(i)},this.deletePairing=async(t,e)=>{await this.core.relayer.unsubscribe(t),await Promise.all([this.pairings.delete(t,oc("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(t),e?Promise.resolve():this.core.expirer.del(t)])},this.cleanup=async()=>{const t=this.pairings.getAll().filter((t=>Si(t.expiry)));await Promise.all(t.map((t=>this.deletePairing(t.topic))))},this.onRelayEventRequest=t=>{const{topic:e,payload:r}=t;switch(r.method){case"wc_pairingPing":return this.onPairingPingRequest(e,r);case"wc_pairingDelete":return this.onPairingDeleteRequest(e,r);default:return this.onUnknownRpcMethodRequest(e,r)}},this.onRelayEventResponse=async t=>{const{topic:e,payload:r}=t,i=(await this.core.history.get(e,r.id)).request.method;return"wc_pairingPing"===i?this.onPairingPingResponse(e,r):this.onUnknownRpcMethodResponse(i)},this.onPairingPingRequest=async(t,e)=>{const{id:r}=e;try{this.isValidPing({topic:t}),await this.sendResult(r,t,!0),this.events.emit("pairing_ping",{id:r,topic:t})}catch(e){await this.sendError(r,t,e),this.logger.error(e)}},this.onPairingPingResponse=(t,e)=>{const{id:r}=e;setTimeout((()=>{ef(e)?this.events.emit(Ei("pairing_ping",r),{}):rf(e)&&this.events.emit(Ei("pairing_ping",r),{error:e.error})}),500)},this.onPairingDeleteRequest=async(t,e)=>{const{id:r}=e;try{this.isValidDisconnect({topic:t}),await this.deletePairing(t),this.events.emit(nd,{id:r,topic:t})}catch(e){await this.sendError(r,t,e),this.logger.error(e)}},this.onUnknownRpcMethodRequest=async(t,e)=>{const{id:r,method:i}=e;try{if(this.registeredMethods.includes(i))return;const e=oc("WC_METHOD_UNSUPPORTED",i);await this.sendError(r,t,e),this.logger.error(e)}catch(e){await this.sendError(r,t,e),this.logger.error(e)}},this.onUnknownRpcMethodResponse=t=>{this.registeredMethods.includes(t)||this.logger.error(oc("WC_METHOD_UNSUPPORTED",t))},this.isValidPair=(t,e)=>{var r;if(!yc(t)){const{message:r}=sc("MISSING_OR_INVALID",`pair() params: ${t}`);throw e.setError(gd),new Error(r)}if(!lc(t.uri)){const{message:r}=sc("MISSING_OR_INVALID",`pair() uri: ${t.uri}`);throw e.setError(gd),new Error(r)}const i=zh(t?.uri);if(null==(r=i?.relay)||!r.protocol){const{message:t}=sc("MISSING_OR_INVALID","pair() uri#relay-protocol");throw e.setError(gd),new Error(t)}if(null==i||!i.symKey){const{message:t}=sc("MISSING_OR_INVALID","pair() uri#symKey");throw e.setError(gd),new Error(t)}if(null!=i&&i.expiryTimestamp&&(0,Y.toMiliseconds)(i?.expiryTimestamp){if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`ping() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidPairingTopic(e)},this.isValidDisconnect=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`disconnect() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidPairingTopic(e)},this.isValidPairingTopic=async t=>{if(!fc(t,!1)){const{message:e}=sc("MISSING_OR_INVALID",`pairing topic should be a string: ${t}`);throw new Error(e)}if(!this.pairings.keys.includes(t)){const{message:e}=sc("NO_MATCHING_KEY",`pairing topic doesn't exist: ${t}`);throw new Error(e)}if(Si(this.pairings.get(t).expiry)){await this.deletePairing(t);const{message:e}=sc("EXPIRED",`pairing topic: ${t}`);throw new Error(e)}},this.core=t,this.logger=_t(e,this.name),this.pairings=new Vd(this.core,this.logger,this.name,this.storagePrefix)}get context(){return wt(this.logger)}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}registerRelayerEvents(){this.core.relayer.on(Fu,(async t=>{const{topic:e,message:r,transportType:i}=t;if(!this.pairings.keys.includes(e)||i===Qu.link_mode||this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(r)))return;const n=await this.core.crypto.decode(e,r);try{Zc(n)?(this.core.history.set(e,n),this.onRelayEventRequest({topic:e,payload:n})):tf(n)&&(await this.core.history.resolve(n),await this.onRelayEventResponse({topic:e,payload:n}),this.core.history.delete(e,n.id))}catch(t){this.logger.error(t)}}))}registerExpirerEvents(){this.core.expirer.on(fd,(async t=>{const{topic:e}=Ai(t.target);e&&this.pairings.keys.includes(e)&&(await this.deletePairing(e,!0),this.events.emit("pairing_expire",{topic:e}))}))}}class Wd extends St{constructor(t,e){super(t,e),this.core=t,this.logger=e,this.records=new Map,this.events=new b.EventEmitter,this.name="history",this.version="0.3",this.cached=[],this.initialized=!1,this.storagePrefix=qu,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach((t=>this.records.set(t.id,t))),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(t,e,r)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:t,request:e,chainId:r}),this.records.has(e.id))return;const i={id:e.id,topic:t,request:{method:e.method,params:e.params||null},chainId:r,expiry:Mi(Y.THIRTY_DAYS)};this.records.set(i.id,i),this.persist(),this.events.emit(sd,i)},this.resolve=async t=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:t}),!this.records.has(t.id))return;const e=await this.getRecord(t.id);typeof e.response>"u"&&(e.response=rf(t)?{error:t.error}:{result:t.result},this.records.set(e.id,e),this.persist(),this.events.emit(od,e))},this.get=async(t,e)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:t,id:e}),await this.getRecord(e)),this.delete=(t,e)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:e}),this.values.forEach((r=>{if(r.topic===t){if(typeof e<"u"&&r.id!==e)return;this.records.delete(r.id),this.events.emit(ad,r)}})),this.persist()},this.exists=async(t,e)=>(this.isInitialized(),!!this.records.has(e)&&(await this.getRecord(e)).topic===t),this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.logger=_t(e,this.name)}get context(){return wt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get size(){return this.records.size}get keys(){return Array.from(this.records.keys())}get values(){return Array.from(this.records.values())}get pending(){const t=[];return this.values.forEach((e=>{if(typeof e.response<"u")return;const r={topic:e.topic,request:Vc(e.request.method,e.request.params,e.id),chainId:e.chainId};return t.push(r)})),t}async setJsonRpcRecords(t){await this.core.storage.setItem(this.storageKey,t)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(t){this.isInitialized();const e=this.records.get(t);if(!e){const{message:e}=sc("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(e)}return e}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit("history_sync")}async restore(){try{const t=await this.getJsonRpcRecords();if(typeof t>"u"||!t.length)return;if(this.records.size){const{message:t}=sc("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(t){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(t)}}registerEventListeners(){this.events.on(sd,(t=>{const e=sd;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,record:t})})),this.events.on(od,(t=>{const e=od;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,record:t})})),this.events.on(ad,(t=>{const e=ad;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,record:t})})),this.core.heartbeat.on(tt,(()=>{this.cleanup()}))}cleanup(){try{this.isInitialized();let t=!1;this.records.forEach((e=>{(0,Y.toMiliseconds)(e.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${e.id}`),this.records.delete(e.id),this.events.emit(ad,e,!1),t=!0)})),t&&this.persist()}catch(t){this.logger.warn(t)}}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Jd extends Pt{constructor(t,e){super(t,e),this.core=t,this.logger=e,this.expirations=new Map,this.events=new b.EventEmitter,this.name="expirer",this.version="0.3",this.cached=[],this.initialized=!1,this.storagePrefix=qu,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach((t=>this.expirations.set(t.target,t))),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=t=>{try{const e=this.formatTarget(t);return typeof this.getExpiration(e)<"u"}catch{return!1}},this.set=(t,e)=>{this.isInitialized();const r=this.formatTarget(t),i={target:r,expiry:e};this.expirations.set(r,i),this.checkExpiry(r,i),this.events.emit(hd,{target:r,expiration:i})},this.get=t=>{this.isInitialized();const e=this.formatTarget(t);return this.getExpiration(e)},this.del=t=>{if(this.isInitialized(),this.has(t)){const e=this.formatTarget(t),r=this.getExpiration(e);this.expirations.delete(e),this.events.emit(cd,{target:e,expiration:r})}},this.on=(t,e)=>{this.events.on(t,e)},this.once=(t,e)=>{this.events.once(t,e)},this.off=(t,e)=>{this.events.off(t,e)},this.removeListener=(t,e)=>{this.events.removeListener(t,e)},this.logger=_t(e,this.name)}get context(){return wt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.expirations.size}get keys(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}formatTarget(t){if("string"==typeof t)return function(t){return _i("topic",t)}(t);if("number"==typeof t)return function(t){return _i("id",t)}(t);const{message:e}=sc("UNKNOWN_TYPE","Target type: "+typeof t);throw new Error(e)}async setExpirations(t){await this.core.storage.setItem(this.storageKey,t)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit("expirer_sync")}async restore(){try{const t=await this.getExpirations();if(typeof t>"u"||!t.length)return;if(this.expirations.size){const{message:t}=sc("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=t,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(t){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(t)}}getExpiration(t){const e=this.expirations.get(t);if(!e){const{message:e}=sc("NO_MATCHING_KEY",`${this.name}: ${t}`);throw this.logger.warn(e),new Error(e)}return e}checkExpiry(t,e){const{expiry:r}=e;(0,Y.toMiliseconds)(r)-Date.now()<=0&&this.expire(t,e)}expire(t,e){this.expirations.delete(t),this.events.emit(fd,{target:t,expiration:e})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach(((t,e)=>this.checkExpiry(e,t)))}registerEventListeners(){this.core.heartbeat.on(tt,(()=>this.checkExpirations())),this.events.on(hd,(t=>{const e=hd;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),this.persist()})),this.events.on(fd,(t=>{const e=fd;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),this.persist()})),this.events.on(cd,(t=>{const e=cd;this.logger.info(`Emitting ${e}`),this.logger.debug({type:"event",event:e,data:t}),this.persist()}))}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}}var Gd={};function $d(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}function Yd(t){const e=$d(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}Object.defineProperty(Gd,"__esModule",{value:!0}),Gd.getLocalStorage=Gd.getLocalStorageOrThrow=Gd.getCrypto=Gd.getCryptoOrThrow=Gd.getLocation=Gd.getLocationOrThrow=Gd.getNavigator=Gd.getNavigatorOrThrow=Qd=Gd.getDocument=Gd.getDocumentOrThrow=Gd.getFromWindowOrThrow=Gd.getFromWindow=void 0,Gd.getFromWindow=$d,Gd.getFromWindowOrThrow=Yd,Gd.getDocumentOrThrow=function(){return Yd("document")};var Qd=Gd.getDocument=function(){return $d("document")};Gd.getNavigatorOrThrow=function(){return Yd("navigator")},Gd.getNavigator=function(){return $d("navigator")},Gd.getLocationOrThrow=function(){return Yd("location")},Gd.getLocation=function(){return $d("location")},Gd.getCryptoOrThrow=function(){return Yd("crypto")},Gd.getCrypto=function(){return $d("crypto")},Gd.getLocalStorageOrThrow=function(){return Yd("localStorage")},Gd.getLocalStorage=function(){return $d("localStorage")};class Xd extends Rt{constructor(t,e,r){super(t,e,r),this.core=t,this.logger=e,this.store=r,this.name="verify-api",this.verifyUrlV3=ld,this.storagePrefix=qu,this.version=2,this.init=async()=>{var t;this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&(0,Y.toMiliseconds)(null==(t=this.publicKey)?void 0:t.expiresAt){if(!li()||this.isDevEnv)return;const e=window.location.origin,{id:r,decryptedId:i}=t,n=`${this.verifyUrlV3}/attestation?projectId=${this.core.projectId}&origin=${e}&id=${r}&decryptedId=${i}`;try{const t=Qd(),e=this.startAbortTimer(5*Y.ONE_SECOND),i=await new Promise(((i,s)=>{const o=()=>{window.removeEventListener("message",h),t.body.removeChild(a),s("attestation aborted")};this.abortController.signal.addEventListener("abort",o);const a=t.createElement("iframe");a.src=n,a.style.display="none",a.addEventListener("error",o,{signal:this.abortController.signal});const h=n=>{if(!n.data)return;const s=JSON.parse(n.data);if("verify_attestation"===s.type){if(Sr(s.attestation).payload.id!==r)return;clearInterval(e),t.body.removeChild(a),this.abortController.signal.removeEventListener("abort",o),window.removeEventListener("message",h),i(null===s.attestation?"":s.attestation)}};t.body.appendChild(a),window.addEventListener("message",h,{signal:this.abortController.signal})}));return this.logger.debug("jwt attestation",i),i}catch(t){this.logger.warn(t)}return""},this.resolve=async t=>{if(this.isDevEnv)return"";const{attestationId:e,hash:r,encryptedId:i}=t;if(""===e)return void this.logger.debug("resolve: attestationId is empty, skipping");if(e){if(Sr(e).payload.id!==i)return;const t=await this.isValidJwtAttestation(e);if(t)return t.isVerified?t:void this.logger.warn("resolve: jwt attestation: origin url not verified")}if(!r)return;const n=this.getVerifyUrl(t?.verifyUrl);return this.fetchAttestation(r,n)},this.fetchAttestation=async(t,e)=>{this.logger.debug(`resolving attestation: ${t} from url: ${e}`);const r=this.startAbortTimer(5*Y.ONE_SECOND),i=await fetch(`${e}/attestation/${t}?v2Supported=true`,{signal:this.abortController.signal});return clearTimeout(r),200===i.status?await i.json():void 0},this.getVerifyUrl=t=>{let e=t||dd;return pd.includes(e)||(this.logger.info(`verify url: ${e}, not included in trusted list, assigning default: ${dd}`),e=dd),e},this.fetchPublicKey=async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);const t=this.startAbortTimer(Y.FIVE_SECONDS),e=await fetch(`${this.verifyUrlV3}/public-key`,{signal:this.abortController.signal});return clearTimeout(t),await e.json()}catch(t){this.logger.warn(t)}},this.persistPublicKey=async t=>{this.logger.debug("persisting public key to local storage",t),await this.store.setItem(this.storeKey,t),this.publicKey=t},this.removePublicKey=async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0},this.isValidJwtAttestation=async t=>{const e=await this.getPublicKey();try{if(e)return this.validateAttestation(t,e)}catch(t){this.logger.error(t),this.logger.warn("error validating attestation")}const r=await this.fetchAndPersistPublicKey();try{if(r)return this.validateAttestation(t,r)}catch(t){this.logger.error(t),this.logger.warn("error validating attestation")}},this.getPublicKey=async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey(),this.fetchAndPersistPublicKey=async()=>{if(this.fetchPromise)return await this.fetchPromise,this.publicKey;this.fetchPromise=new Promise((async t=>{const e=await this.fetchPublicKey();e&&(await this.persistPublicKey(e),t(e))}));const t=await this.fetchPromise;return this.fetchPromise=void 0,t},this.validateAttestation=(t,e)=>{const r=function(t,e){const[r,i,n]=t.split("."),s=function(t){return Buffer.from(function(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");const r=e.length%4;return r>0&&(e+="=".repeat(4-r)),e}(t),"base64")}(n);if(64!==s.length)throw new Error("Invalid signature length");const o=s.slice(0,32).toString("hex"),a=s.slice(32,64).toString("hex"),h=`${r}.${i}`,c=(new Fr.aD).update(Buffer.from(h)).digest(),f=function(t){return new Xr.ec("p256").keyFromPublic({x:Buffer.from(t.x,"base64").toString("hex"),y:Buffer.from(t.y,"base64").toString("hex")},"hex")}(e),u=Buffer.from(c).toString("hex");if(!f.verify(u,{r:o,s:a}))throw new Error("Invalid signature");return Sr(t).payload}(t,e.publicKey),i={hasExpired:(0,Y.toMiliseconds)(r.exp)this.abortController.abort()),(0,Y.toMiliseconds)(t))}}class Zd extends Tt{constructor(t,e){super(t,e),this.projectId=t,this.logger=e,this.context="echo",this.registerDeviceToken=async t=>{const{clientId:e,token:r,notificationType:i,enableEncrypted:n=!1}=t,s=`https://echo.walletconnect.com/${this.projectId}/clients`;await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:e,type:i,token:r,always_raw:n})})},this.logger=_t(e,this.context)}}var tl=Object.defineProperty,el=Object.getOwnPropertySymbols,rl=Object.prototype.hasOwnProperty,il=Object.prototype.propertyIsEnumerable,nl=(t,e,r)=>e in t?tl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sl=(t,e)=>{for(var r in e||(e={}))rl.call(e,r)&&nl(t,r,e[r]);if(el)for(var r of el(e))il.call(e,r)&&nl(t,r,e[r]);return t};class ol extends Ct{constructor(t,e,r=!0){super(t,e,r),this.core=t,this.logger=e,this.context="event-client",this.storagePrefix=qu,this.storageVersion=.1,this.events=new Map,this.shouldPersist=!1,this.createEvent=t=>{const{event:e="ERROR",type:r="",properties:{topic:i,trace:n}}=t,s=typeof crypto<"u"&&null!=crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,(t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})),o=this.core.projectId||"",a=Date.now(),h=sl({eventId:s,bundleId:o,timestamp:a,props:{event:e,type:r,properties:{topic:i,trace:n}}},this.setMethods(s));return this.telemetryEnabled&&(this.events.set(s,h),this.shouldPersist=!0),h},this.getEvent=t=>{const{eventId:e,topic:r}=t;if(e)return this.events.get(e);const i=Array.from(this.events.values()).find((t=>t.props.properties.topic===r));return i?sl(sl({},i),this.setMethods(i.eventId)):void 0},this.deleteEvent=t=>{const{eventId:e}=t;this.events.delete(e),this.shouldPersist=!0},this.setEventListeners=()=>{this.core.heartbeat.on(tt,(async()=>{this.shouldPersist&&await this.persist(),this.events.forEach((t=>{(0,Y.fromMiliseconds)(Date.now())-(0,Y.fromMiliseconds)(t.timestamp)>86400&&(this.events.delete(t.eventId),this.shouldPersist=!0)}))}))},this.setMethods=t=>({addTrace:e=>this.addTrace(t,e),setError:e=>this.setError(t,e)}),this.addTrace=(t,e)=>{const r=this.events.get(t);r&&(r.props.properties.trace.push(e),this.events.set(t,r),this.shouldPersist=!0)},this.setError=(t,e)=>{const r=this.events.get(t);r&&(r.props.type=e,r.timestamp=Date.now(),this.events.set(t,r),this.shouldPersist=!0)},this.persist=async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1},this.restore=async()=>{try{const t=await this.core.storage.getItem(this.storageKey)||[];if(!t.length)return;t.forEach((t=>{this.events.set(t.eventId,sl(sl({},t),this.setMethods(t.eventId)))}))}catch(t){this.logger.warn(t)}},this.submit=async()=>{if(!this.telemetryEnabled||0===this.events.size)return;const t=[];for(const[e,r]of this.events)r.props.type&&t.push(r);if(0!==t.length)try{if((await fetch(`https://pulse.walletconnect.com/batch?projectId=${this.core.projectId}&st=events_sdk&sv=js-${Yu}`,{method:"POST",body:JSON.stringify(t)})).ok)for(const e of t)this.events.delete(e.eventId),this.shouldPersist=!0}catch(t){this.logger.warn(t)}},this.logger=_t(e,this.context),r?this.restore().then((async()=>{await this.submit(),this.setEventListeners()})):this.persist()}get storageKey(){return this.storagePrefix+this.storageVersion+this.core.customStoragePrefix+"//"+this.context}}var al=Object.defineProperty,hl=Object.getOwnPropertySymbols,cl=Object.prototype.hasOwnProperty,fl=Object.prototype.propertyIsEnumerable,ul=(t,e,r)=>e in t?al(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dl=(t,e)=>{for(var r in e||(e={}))cl.call(e,r)&&ul(t,r,e[r]);if(hl)for(var r of hl(e))fl.call(e,r)&&ul(t,r,e[r]);return t};class ll extends Mt{constructor(t){var e;super(t),this.protocol="wc",this.version=2,this.name=Lu,this.events=new b.EventEmitter,this.initialized=!1,this.on=(t,e)=>this.events.on(t,e),this.once=(t,e)=>this.events.once(t,e),this.off=(t,e)=>this.events.off(t,e),this.removeListener=(t,e)=>this.events.removeListener(t,e),this.dispatchEnvelope=({topic:t,message:e,sessionExists:r})=>{if(!t||!e)return;const i={topic:t,message:e,publishedAt:Date.now(),transportType:Qu.link_mode};this.relayer.onLinkMessageEvent(i,{sessionExists:r})},this.projectId=t?.projectId,this.relayUrl=t?.relayUrl||ju,this.customStoragePrefix=null!=t&&t.customStoragePrefix?`:${t.customStoragePrefix}`:"";const r=vt({level:"string"==typeof t?.logger&&t.logger?t.logger:"error"}),{logger:i,chunkLoggerController:n}=At({opts:r,maxSizeInBytes:t?.maxLogBlobSizeInBytes,loggerOverride:t?.logger});this.logChunkController=n,null!=(e=this.logChunkController)&&e.downloadLogsBlobInBrowser&&(window.downloadLogsBlobInBrowser=async()=>{var t,e;null!=(t=this.logChunkController)&&t.downloadLogsBlobInBrowser&&(null==(e=this.logChunkController)||e.downloadLogsBlobInBrowser({clientId:await this.crypto.getClientId()}))}),this.logger=_t(i,this.name),this.heartbeat=new et,this.crypto=new yd(this,this.logger,t?.keychain),this.history=new Wd(this,this.logger),this.expirer=new Jd(this,this.logger),this.storage=null!=t&&t.storage?t.storage:new $(dl(dl({},Uu),t?.storageOptions)),this.relayer=new Ud({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new Hd(this,this.logger),this.verify=new Xd(this,this.logger,this.storage),this.echoClient=new Zd(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new ol(this,this.logger,t?.telemetryEnabled)}static async init(t){const e=new ll(t);await e.initialize();const r=await e.crypto.getClientId();return await e.storage.setItem("WALLETCONNECT_CLIENT_ID",r),e}get context(){return wt(this.logger)}async start(){this.initialized||await this.initialize()}async getLogsBlob(){var t;return null==(t=this.logChunkController)?void 0:t.logsToBlob({clientId:await this.crypto.getClientId()})}async addLinkModeSupportedApp(t){this.linkModeSupportedApps.includes(t)||(this.linkModeSupportedApps.push(t),await this.storage.setItem(Xu,this.linkModeSupportedApps))}async initialize(){this.logger.trace("Initialized");try{await this.crypto.init(),await this.history.init(),await this.expirer.init(),await this.relayer.init(),await this.heartbeat.init(),await this.pairing.init(),this.linkModeSupportedApps=await this.storage.getItem(Xu)||[],this.initialized=!0,this.logger.info("Core Initialization Success")}catch(t){throw this.logger.warn(`Core Initialization Failure at epoch ${Date.now()}`,t),this.logger.error(t.message),t}}}const pl=ll;let gl=!1,ml=!1;const bl={debug:1,default:2,info:2,warning:3,error:4,off:5};let yl=bl.default,vl=null;const wl=function(){try{const t=[];if(["NFD","NFC","NFKD","NFKC"].forEach((e=>{try{if("test"!=="test".normalize(e))throw new Error("bad normalize")}catch(r){t.push(e)}})),t.length)throw new Error("missing "+t.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(t){return t.message}return null}();var _l,Al;!function(t){t.DEBUG="DEBUG",t.INFO="INFO",t.WARNING="WARNING",t.ERROR="ERROR",t.OFF="OFF"}(_l||(_l={})),function(t){t.UNKNOWN_ERROR="UNKNOWN_ERROR",t.NOT_IMPLEMENTED="NOT_IMPLEMENTED",t.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",t.NETWORK_ERROR="NETWORK_ERROR",t.SERVER_ERROR="SERVER_ERROR",t.TIMEOUT="TIMEOUT",t.BUFFER_OVERRUN="BUFFER_OVERRUN",t.NUMERIC_FAULT="NUMERIC_FAULT",t.MISSING_NEW="MISSING_NEW",t.INVALID_ARGUMENT="INVALID_ARGUMENT",t.MISSING_ARGUMENT="MISSING_ARGUMENT",t.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",t.CALL_EXCEPTION="CALL_EXCEPTION",t.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",t.NONCE_EXPIRED="NONCE_EXPIRED",t.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",t.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",t.TRANSACTION_REPLACED="TRANSACTION_REPLACED",t.ACTION_REJECTED="ACTION_REJECTED"}(Al||(Al={}));const Ml="0123456789abcdef";class Sl{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const r=t.toLowerCase();null==bl[r]&&this.throwArgumentError("invalid log level name","logLevel",t),yl>bl[r]||console.log.apply(console,e)}debug(...t){this._log(Sl.levels.DEBUG,t)}info(...t){this._log(Sl.levels.INFO,t)}warn(...t){this._log(Sl.levels.WARNING,t)}makeError(t,e,r){if(ml)return this.makeError("censored error",e,{});e||(e=Sl.errors.UNKNOWN_ERROR),r||(r={});const i=[];Object.keys(r).forEach((t=>{const e=r[t];try{if(e instanceof Uint8Array){let r="";for(let t=0;t>4],r+=Ml[15&e[t]];i.push(t+"=Uint8Array(0x"+r+")")}else i.push(t+"="+JSON.stringify(e))}catch(e){i.push(t+"="+JSON.stringify(r[t].toString()))}})),i.push(`code=${e}`),i.push(`version=${this.version}`);const n=t;let s="";switch(e){case Al.NUMERIC_FAULT:{s="NUMERIC_FAULT";const e=t;switch(e){case"overflow":case"underflow":case"division-by-zero":s+="-"+e;break;case"negative-power":case"negative-width":s+="-unsupported";break;case"unbound-bitwise-result":s+="-unbound-result"}break}case Al.CALL_EXCEPTION:case Al.INSUFFICIENT_FUNDS:case Al.MISSING_NEW:case Al.NONCE_EXPIRED:case Al.REPLACEMENT_UNDERPRICED:case Al.TRANSACTION_REPLACED:case Al.UNPREDICTABLE_GAS_LIMIT:s=e}s&&(t+=" [ See: https://links.ethers.org/v5-errors-"+s+" ]"),i.length&&(t+=" ("+i.join(", ")+")");const o=new Error(t);return o.reason=n,o.code=e,Object.keys(r).forEach((function(t){o[t]=r[t]})),o}throwError(t,e,r){throw this.makeError(t,e,r)}throwArgumentError(t,e,r){return this.throwError(t,Sl.errors.INVALID_ARGUMENT,{argument:e,value:r})}assert(t,e,r,i){t||this.throwError(e,r,i)}assertArgument(t,e,r,i){t||this.throwArgumentError(e,r,i)}checkNormalize(t){null==t&&(t="platform missing String.prototype.normalize"),wl&&this.throwError("platform missing String.prototype.normalize",Sl.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:wl})}checkSafeUint53(t,e){"number"==typeof t&&(null==e&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,Sl.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,Sl.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,r){r=r?": "+r:"",te&&this.throwError("too many arguments"+r,Sl.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){t!==Object&&null!=t||this.throwError("missing new",Sl.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",Sl.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):t!==Object&&null!=t||this.throwError("missing new",Sl.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return vl||(vl=new Sl("logger/5.7.0")),vl}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",Sl.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),gl){if(!t)return;this.globalLogger().throwError("error censorship permanent",Sl.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}ml=!!t,gl=!!e}static setLogLevel(t){const e=bl[t.toLowerCase()];null!=e?yl=e:Sl.globalLogger().warn("invalid log level - "+t)}static from(t){return new Sl(t)}}Sl.errors=Al,Sl.levels=_l;const El=new Sl("bytes/5.7.0");function Il(t){return!!t.toHexString}function xl(t){return t.slice||(t.slice=function(){const e=Array.prototype.slice.call(arguments);return xl(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}function Ol(t){return"number"==typeof t&&t==t&&t%1==0}function Nl(t){if(null==t)return!1;if(t.constructor===Uint8Array)return!0;if("string"==typeof t)return!1;if(!Ol(t.length)||t.length<0)return!1;for(let e=0;e=256)return!1}return!0}function Pl(t,e){if(e||(e={}),"number"==typeof t){El.checkSafeUint53(t,"invalid arrayify value");const e=[];for(;t;)e.unshift(255&t),t=parseInt(String(t/256));return 0===e.length&&e.push(0),xl(new Uint8Array(e))}if(e.allowMissingPrefix&&"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),Il(t)&&(t=t.toHexString()),Rl(t)){let r=t.substring(2);r.length%2&&("left"===e.hexPad?r="0"+r:"right"===e.hexPad?r+="0":El.throwArgumentError("hex data is odd-length","value",t));const i=[];for(let t=0;t>4]+Tl[15&i]}return e}return El.throwArgumentError("invalid hexlify value","value",t)}function kl(t,e,r){return"string"!=typeof t?t=Cl(t):(!Rl(t)||t.length%2)&&El.throwArgumentError("invalid hexData","value",t),e=2+2*e,null!=r?"0x"+t.substring(e,2+2*r):"0x"+t.substring(e)}function Ll(t,e){for("string"!=typeof t?t=Cl(t):Rl(t)||El.throwArgumentError("invalid hex string","value",t),t.length>2*e+2&&El.throwArgumentError("value out of range","value",arguments[1]);t.length<2*e+2;)t="0x0"+t.substring(2);return t}function ql(t){const e={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(Rl(r=t)&&!(r.length%2)||Nl(r)){let r=Pl(t);64===r.length?(e.v=27+(r[32]>>7),r[32]&=127,e.r=Cl(r.slice(0,32)),e.s=Cl(r.slice(32,64))):65===r.length?(e.r=Cl(r.slice(0,32)),e.s=Cl(r.slice(32,64)),e.v=r[64]):El.throwArgumentError("invalid signature string","signature",t),e.v<27&&(0===e.v||1===e.v?e.v+=27:El.throwArgumentError("signature invalid v byte","signature",t)),e.recoveryParam=1-e.v%2,e.recoveryParam&&(r[32]|=128),e._vs=Cl(r.slice(32,64))}else{if(e.r=t.r,e.s=t.s,e.v=t.v,e.recoveryParam=t.recoveryParam,e._vs=t._vs,null!=e._vs){const r=function(t,e){(t=Pl(t)).length>e&&El.throwArgumentError("value out of range","value",arguments[0]);const r=new Uint8Array(e);return r.set(t,e-t.length),xl(r)}(Pl(e._vs),32);e._vs=Cl(r);const i=r[0]>=128?1:0;null==e.recoveryParam?e.recoveryParam=i:e.recoveryParam!==i&&El.throwArgumentError("signature recoveryParam mismatch _vs","signature",t),r[0]&=127;const n=Cl(r);null==e.s?e.s=n:e.s!==n&&El.throwArgumentError("signature v mismatch _vs","signature",t)}if(null==e.recoveryParam)null==e.v?El.throwArgumentError("signature missing v and recoveryParam","signature",t):0===e.v||1===e.v?e.recoveryParam=e.v:e.recoveryParam=1-e.v%2;else if(null==e.v)e.v=27+e.recoveryParam;else{const r=0===e.v||1===e.v?e.v:1-e.v%2;e.recoveryParam!==r&&El.throwArgumentError("signature recoveryParam mismatch v","signature",t)}null!=e.r&&Rl(e.r)?e.r=Ll(e.r,32):El.throwArgumentError("signature missing or invalid r","signature",t),null!=e.s&&Rl(e.s)?e.s=Ll(e.s,32):El.throwArgumentError("signature missing or invalid s","signature",t);const r=Pl(e.s);r[0]>=128&&El.throwArgumentError("signature s out of range","signature",t),e.recoveryParam&&(r[0]|=128);const i=Cl(r);e._vs&&(Rl(e._vs)||El.throwArgumentError("signature invalid _vs","signature",t),e._vs=Ll(e._vs,32)),null==e._vs?e._vs=i:e._vs!==i&&El.throwArgumentError("signature _vs mismatch v and s","signature",t)}var r;return e.yParityAndS=e._vs,e.compact=e.r+e.yParityAndS.substring(2),e}var Ul=r(1176),Bl=r.n(Ul);function Dl(t){return"0x"+Bl().keccak_256(Pl(t))}const zl=new Sl("strings/5.7.0");var jl,Fl;function Kl(t,e,r,i,n){if(t===Fl.BAD_PREFIX||t===Fl.UNEXPECTED_CONTINUE){let t=0;for(let i=e+1;i>6==2;i++)t++;return t}return t===Fl.OVERRUN?r.length-e-1:0}function Vl(t,e=jl.current){e!=jl.current&&(zl.checkNormalize(),t=t.normalize(e));let r=[];for(let e=0;e>6|192),r.push(63&i|128);else if(55296==(64512&i)){e++;const n=t.charCodeAt(e);if(e>=t.length||56320!=(64512&n))throw new Error("invalid utf-8 string");const s=65536+((1023&i)<<10)+(1023&n);r.push(s>>18|240),r.push(s>>12&63|128),r.push(s>>6&63|128),r.push(63&s|128)}else r.push(i>>12|224),r.push(i>>6&63|128),r.push(63&i|128)}return Pl(r)}!function(t){t.current="",t.NFC="NFC",t.NFD="NFD",t.NFKC="NFKC",t.NFKD="NFKD"}(jl||(jl={})),function(t){t.UNEXPECTED_CONTINUE="unexpected continuation byte",t.BAD_PREFIX="bad codepoint prefix",t.OVERRUN="string overrun",t.MISSING_CONTINUE="missing continuation byte",t.OUT_OF_RANGE="out of UTF-8 range",t.UTF16_SURROGATE="UTF-16 surrogate",t.OVERLONG="overlong representation"}(Fl||(Fl={})),Object.freeze({error:function(t,e,r,i,n){return zl.throwArgumentError(`invalid codepoint at offset ${e}; ${t}`,"bytes",r)},ignore:Kl,replace:function(t,e,r,i,n){return t===Fl.OVERLONG?(i.push(n),0):(i.push(65533),Kl(t,e,r))}});const Hl="Ethereum Signed Message:\n";function Wl(t){return"string"==typeof t&&(t=Vl(t)),Dl(function(t){const e=t.map((t=>Pl(t))),r=e.reduce(((t,e)=>t+e.length),0),i=new Uint8Array(r);return e.reduce(((t,e)=>(i.set(e,t),t+e.length)),0),xl(i)}([Vl(Hl),Vl(String(t.length)),t]))}var Jl=r(9404),Gl=r.n(Jl),$l=Gl().BN;new Sl("bignumber/5.7.0");const Yl=new Sl("address/5.7.0");function Ql(t){Rl(t,20)||Yl.throwArgumentError("invalid address","address",t);const e=(t=t.toLowerCase()).substring(2).split(""),r=new Uint8Array(40);for(let t=0;t<40;t++)r[t]=e[t].charCodeAt(0);const i=Pl(Dl(r));for(let t=0;t<40;t+=2)i[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&i[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const Xl={};for(let t=0;t<10;t++)Xl[String(t)]=String(t);for(let t=0;t<26;t++)Xl[String.fromCharCode(65+t)]=String(10+t);const Zl=Math.floor((tp=9007199254740991,Math.log10?Math.log10(tp):Math.log(tp)/Math.LN10));var tp;function ep(t){let e=null;if("string"!=typeof t&&Yl.throwArgumentError("invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==t.substring(0,2)&&(t="0x"+t),e=Ql(t),t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&e!==t&&Yl.throwArgumentError("bad address checksum","address",t);else if(t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(t.substring(2,4)!==function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>Xl[t])).join("");for(;e.length>=Zl;){let t=e.substring(0,Zl);e=parseInt(t,10)%97+e.substring(t.length)}let r=String(98-parseInt(e,10)%97);for(;r.length<2;)r="0"+r;return r}(t)&&Yl.throwArgumentError("bad icap checksum","address",t),r=t.substring(4),e=new $l(r,36).toString(16);e.length<40;)e="0"+e;e=Ql("0x"+e)}else Yl.throwArgumentError("invalid address","address",t);var r;return e}var rp=r(7952),ip=r.n(rp);function np(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==r.g?r.g:"undefined"!=typeof self&&self;var sp=op;function op(t,e){if(!t)throw new Error(e||"Assertion failed")}op.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var ap=np((function(t,e){var r=e;function i(t){return 1===t.length?"0"+t:t}function n(t){for(var e="",r=0;r>8,o=255&n;s?r.push(s,o):r.push(o)}return r},r.zero2=i,r.toHex=n,r.encode=function(t,e){return"hex"===e?n(t):t}})),hp=np((function(t,e){var r=e;r.assert=sp,r.toArray=ap.toArray,r.zero2=ap.zero2,r.toHex=ap.toHex,r.encode=ap.encode,r.getNAF=function(t,e,r){var i=new Array(Math.max(t.bitLength(),r)+1);i.fill(0);for(var n=1<(n>>1)-1?(n>>1)-h:h,s.isubn(a)):a=0,i[o]=a,s.iushrn(1)}return i},r.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var i,n=0,s=0;t.cmpn(-n)>0||e.cmpn(-s)>0;){var o,a,h=t.andln(3)+n&3,c=e.andln(3)+s&3;3===h&&(h=-1),3===c&&(c=-1),o=1&h?3!=(i=t.andln(7)+n&7)&&5!==i||2!==c?h:-h:0,r[0].push(o),a=1&c?3!=(i=e.andln(7)+s&7)&&5!==i||2!==h?c:-c:0,r[1].push(a),2*n===o+1&&(n=1-n),2*s===a+1&&(s=1-s),t.iushrn(1),e.iushrn(1)}return r},r.cachedProperty=function(t,e,r){var i="_"+e;t.prototype[e]=function(){return void 0!==this[i]?this[i]:this[i]=r.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new(Gl())(t,"hex","le")}})),cp=hp.getNAF,fp=hp.getJSF,up=hp.assert;function dp(t,e){this.type=t,this.p=new(Gl())(e.p,16),this.red=e.prime?Gl().red(e.prime):Gl().mont(this.p),this.zero=new(Gl())(0).toRed(this.red),this.one=new(Gl())(1).toRed(this.red),this.two=new(Gl())(2).toRed(this.red),this.n=e.n&&new(Gl())(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var lp=dp;function pp(t,e){this.curve=t,this.type=e,this.precomputed=null}dp.prototype.point=function(){throw new Error("Not implemented")},dp.prototype.validate=function(){throw new Error("Not implemented")},dp.prototype._fixedNafMul=function(t,e){up(t.precomputed);var r=t._getDoubles(),i=cp(e,1,this._bitLength),n=(1<=s;h--)o=(o<<1)+i[h];a.push(o)}for(var c=this.jpoint(null,null,null),f=this.jpoint(null,null,null),u=n;u>0;u--){for(s=0;s=0;a--){for(var h=0;a>=0&&0===s[a];a--)h++;if(a>=0&&h++,o=o.dblp(h),a<0)break;var c=s[a];up(0!==c),o="affine"===t.type?c>0?o.mixedAdd(n[c-1>>1]):o.mixedAdd(n[-c-1>>1].neg()):c>0?o.add(n[c-1>>1]):o.add(n[-c-1>>1].neg())}return"affine"===t.type?o.toP():o},dp.prototype._wnafMulAdd=function(t,e,r,i,n){var s,o,a,h=this._wnafT1,c=this._wnafT2,f=this._wnafT3,u=0;for(s=0;s=1;s-=2){var l=s-1,p=s;if(1===h[l]&&1===h[p]){var g=[e[l],null,null,e[p]];0===e[l].y.cmp(e[p].y)?(g[1]=e[l].add(e[p]),g[2]=e[l].toJ().mixedAdd(e[p].neg())):0===e[l].y.cmp(e[p].y.redNeg())?(g[1]=e[l].toJ().mixedAdd(e[p]),g[2]=e[l].add(e[p].neg())):(g[1]=e[l].toJ().mixedAdd(e[p]),g[2]=e[l].toJ().mixedAdd(e[p].neg()));var m=[-3,-1,-5,-7,0,7,5,1,3],b=fp(r[l],r[p]);for(u=Math.max(b[0].length,u),f[l]=new Array(u),f[p]=new Array(u),o=0;o=0;s--){for(var A=0;s>=0;){var M=!0;for(o=0;o=0&&A++,w=w.dblp(A),s<0)break;for(o=0;o0?a=c[o][S-1>>1]:S<0&&(a=c[o][-S-1>>1].neg()),w="affine"===a.type?w.mixedAdd(a):w.add(a))}}for(s=0;s=Math.ceil((t.bitLength()+1)/e.step)},pp.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],i=this,n=0;n=0&&(s=e,o=r),i.negative&&(i=i.neg(),n=n.neg()),s.negative&&(s=s.neg(),o=o.neg()),[{a:i,b:n},{a:s,b:o}]},bp.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],i=e[1],n=i.b.mul(t).divRound(this.n),s=r.b.neg().mul(t).divRound(this.n),o=n.mul(r.a),a=s.mul(i.a),h=n.mul(r.b),c=s.mul(i.b);return{k1:t.sub(o).sub(a),k2:h.add(c).neg()}},bp.prototype.pointFromX=function(t,e){(t=new(Gl())(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),i=r.redSqrt();if(0!==i.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var n=i.fromRed().isOdd();return(e&&!n||!e&&n)&&(i=i.redNeg()),this.point(t,i)},bp.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,i=this.a.redMul(e),n=e.redSqr().redMul(e).redIAdd(i).redIAdd(this.b);return 0===r.redSqr().redISub(n).cmpn(0)},bp.prototype._endoWnafMulAdd=function(t,e,r){for(var i=this._endoWnafT1,n=this._endoWnafT2,s=0;s":""},vp.prototype.isInfinity=function(){return this.inf},vp.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),i=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,i)},vp.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),i=t.redInvm(),n=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(i),s=n.redSqr().redISub(this.x.redAdd(this.x)),o=n.redMul(this.x.redSub(s)).redISub(this.y);return this.curve.point(s,o)},vp.prototype.getX=function(){return this.x.fromRed()},vp.prototype.getY=function(){return this.y.fromRed()},vp.prototype.mul=function(t){return t=new(Gl())(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},vp.prototype.mulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},vp.prototype.jmulAdd=function(t,e,r){var i=[this,e],n=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},vp.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},vp.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,i=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(i)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(i)}}}return e},vp.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},gp(wp,lp.BasePoint),bp.prototype.jpoint=function(t,e,r){return new wp(this,t,e,r)},wp.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),i=this.y.redMul(e).redMul(t);return this.curve.point(r,i)},wp.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},wp.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(e),n=t.x.redMul(r),s=this.y.redMul(e.redMul(t.z)),o=t.y.redMul(r.redMul(this.z)),a=i.redSub(n),h=s.redSub(o);if(0===a.cmpn(0))return 0!==h.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=a.redSqr(),f=c.redMul(a),u=i.redMul(c),d=h.redSqr().redIAdd(f).redISub(u).redISub(u),l=h.redMul(u.redISub(d)).redISub(s.redMul(f)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(d,l,p)},wp.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,i=t.x.redMul(e),n=this.y,s=t.y.redMul(e).redMul(this.z),o=r.redSub(i),a=n.redSub(s);if(0===o.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var h=o.redSqr(),c=h.redMul(o),f=r.redMul(h),u=a.redSqr().redIAdd(c).redISub(f).redISub(f),d=a.redMul(f.redISub(u)).redISub(n.redMul(c)),l=this.z.redMul(o);return this.curve.jpoint(u,d,l)},wp.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e=0)return!1;if(r.redIAdd(n),0===this.x.cmp(r))return!0}},wp.prototype.inspect=function(){return this.isInfinity()?"":""},wp.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var _p=np((function(t,e){var r=e;r.base=lp,r.short=yp,r.mont=null,r.edwards=null})),Ap=np((function(t,e){var r,i=e,n=hp.assert;function s(t){"short"===t.type?this.curve=new _p.short(t):"edwards"===t.type?this.curve=new _p.edwards(t):this.curve=new _p.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,n(this.g.validate(),"Invalid curve"),n(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function o(t,e){Object.defineProperty(i,t,{configurable:!0,enumerable:!0,get:function(){var r=new s(e);return Object.defineProperty(i,t,{configurable:!0,enumerable:!0,value:r}),r}})}i.PresetCurve=s,o("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:ip().sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),o("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:ip().sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),o("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:ip().sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),o("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:ip().sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),o("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:ip().sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),o("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:ip().sha256,gRed:!1,g:["9"]}),o("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:ip().sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{r=null.crash()}catch(t){r=void 0}o("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:ip().sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",r]})}));function Mp(t){if(!(this instanceof Mp))return new Mp(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=ap.toArray(t.entropy,t.entropyEnc||"hex"),r=ap.toArray(t.nonce,t.nonceEnc||"hex"),i=ap.toArray(t.pers,t.persEnc||"hex");sp(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}var Sp=Mp;Mp.prototype._init=function(t,e,r){var i=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},Mp.prototype.generate=function(t,e,r,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(i=r,r=e,e=null),r&&(r=ap.toArray(r,i||"hex"),this._update(r));for(var n=[];n.length"};var Op=hp.assert;function Np(t,e){if(t instanceof Np)return t;this._importDER(t,e)||(Op(t.r&&t.s,"Signature without r or s"),this.r=new(Gl())(t.r,16),this.s=new(Gl())(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var Pp=Np;function Rp(){this.place=0}function Tp(t,e){var r=t[e.place++];if(!(128&r))return r;var i=15&r;if(0===i||i>4)return!1;for(var n=0,s=0,o=e.place;s>>=0;return!(n<=127)&&(e.place=o,n)}function Cp(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}Np.prototype._importDER=function(t,e){t=hp.toArray(t,e);var r=new Rp;if(48!==t[r.place++])return!1;var i=Tp(t,r);if(!1===i)return!1;if(i+r.place!==t.length)return!1;if(2!==t[r.place++])return!1;var n=Tp(t,r);if(!1===n)return!1;var s=t.slice(r.place,n+r.place);if(r.place+=n,2!==t[r.place++])return!1;var o=Tp(t,r);if(!1===o)return!1;if(t.length!==o+r.place)return!1;var a=t.slice(r.place,o+r.place);if(0===s[0]){if(!(128&s[1]))return!1;s=s.slice(1)}if(0===a[0]){if(!(128&a[1]))return!1;a=a.slice(1)}return this.r=new(Gl())(s),this.s=new(Gl())(a),this.recoveryParam=null,!0},Np.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=Cp(e),r=Cp(r);!(r[0]||128&r[1]);)r=r.slice(1);var i=[2];kp(i,e.length),(i=i.concat(e)).push(2),kp(i,r.length);var n=i.concat(r),s=[48];return kp(s,n.length),s=s.concat(n),hp.encode(s,t)};var Lp=function(){throw new Error("unsupported")},qp=hp.assert;function Up(t){if(!(this instanceof Up))return new Up(t);"string"==typeof t&&(qp(Object.prototype.hasOwnProperty.call(Ap,t),"Unknown curve "+t),t=Ap[t]),t instanceof Ap.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}var Bp=Up;Up.prototype.keyPair=function(t){return new xp(this,t)},Up.prototype.keyFromPrivate=function(t,e){return xp.fromPrivate(this,t,e)},Up.prototype.keyFromPublic=function(t,e){return xp.fromPublic(this,t,e)},Up.prototype.genKeyPair=function(t){t||(t={});for(var e=new Sp({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||Lp(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),r=this.n.byteLength(),i=this.n.sub(new(Gl())(2));;){var n=new(Gl())(e.generate(r));if(!(n.cmp(i)>0))return n.iaddn(1),this.keyFromPrivate(n)}},Up.prototype._truncateToN=function(t,e){var r=8*t.byteLength()-this.n.bitLength();return r>0&&(t=t.ushrn(r)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},Up.prototype.sign=function(t,e,r,i){"object"==typeof r&&(i=r,r=null),i||(i={}),e=this.keyFromPrivate(e,r),t=this._truncateToN(new(Gl())(t,16));for(var n=this.n.byteLength(),s=e.getPrivate().toArray("be",n),o=t.toArray("be",n),a=new Sp({hash:this.hash,entropy:s,nonce:o,pers:i.pers,persEnc:i.persEnc||"utf8"}),h=this.n.sub(new(Gl())(1)),c=0;;c++){var f=i.k?i.k(c):new(Gl())(a.generate(this.n.byteLength()));if(!((f=this._truncateToN(f,!0)).cmpn(1)<=0||f.cmp(h)>=0)){var u=this.g.mul(f);if(!u.isInfinity()){var d=u.getX(),l=d.umod(this.n);if(0!==l.cmpn(0)){var p=f.invm(this.n).mul(l.mul(e.getPrivate()).iadd(t));if(0!==(p=p.umod(this.n)).cmpn(0)){var g=(u.getY().isOdd()?1:0)|(0!==d.cmp(l)?2:0);return i.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),g^=1),new Pp({r:l,s:p,recoveryParam:g})}}}}}},Up.prototype.verify=function(t,e,r,i){t=this._truncateToN(new(Gl())(t,16)),r=this.keyFromPublic(r,i);var n=(e=new Pp(e,"hex")).r,s=e.s;if(n.cmpn(1)<0||n.cmp(this.n)>=0)return!1;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;var o,a=s.invm(this.n),h=a.mul(t).umod(this.n),c=a.mul(n).umod(this.n);return this.curve._maxwellTrick?!(o=this.g.jmulAdd(h,r.getPublic(),c)).isInfinity()&&o.eqXToP(n):!(o=this.g.mulAdd(h,r.getPublic(),c)).isInfinity()&&0===o.getX().umod(this.n).cmp(n)},Up.prototype.recoverPubKey=function(t,e,r,i){qp((3&r)===r,"The recovery param is more than two bits"),e=new Pp(e,i);var n=this.n,s=new(Gl())(t),o=e.r,a=e.s,h=1&r,c=r>>1;if(o.cmp(this.curve.p.umod(this.curve.n))>=0&&c)throw new Error("Unable to find sencond key candinate");o=c?this.curve.pointFromX(o.add(this.curve.n),h):this.curve.pointFromX(o,h);var f=e.r.invm(n),u=n.sub(s).mul(f).umod(n),d=a.mul(f).umod(n);return this.g.mulAdd(u,o,d)},Up.prototype.getKeyRecoveryParam=function(t,e,r,i){if(null!==(e=new Pp(e,i)).recoveryParam)return e.recoveryParam;for(var n=0;n<4;n++){var s;try{s=this.recoverPubKey(t,e,n)}catch(t){continue}if(s.eq(r))return n}throw new Error("Unable to find valid recovery factor")};var Dp=np((function(t,e){var r=e;r.version="6.5.4",r.utils=hp,r.rand=function(){throw new Error("unsupported")},r.curve=_p,r.curves=Ap,r.ec=Bp,r.eddsa=null})),zp=Dp.ec;function jp(t,e,r){Object.defineProperty(t,e,{enumerable:!0,value:r,writable:!1})}new Sl("properties/5.7.0");const Fp=new Sl("signing-key/5.7.0");let Kp=null;function Vp(){return Kp||(Kp=new zp("secp256k1")),Kp}class Hp{constructor(t){jp(this,"curve","secp256k1"),jp(this,"privateKey",Cl(t)),32!==function(t){if("string"!=typeof t)t=Cl(t);else if(!Rl(t)||t.length%2)return null;return(t.length-2)/2}(this.privateKey)&&Fp.throwArgumentError("invalid private key","privateKey","[[ REDACTED ]]");const e=Vp().keyFromPrivate(Pl(this.privateKey));jp(this,"publicKey","0x"+e.getPublic(!1,"hex")),jp(this,"compressedPublicKey","0x"+e.getPublic(!0,"hex")),jp(this,"_isSigningKey",!0)}_addPoint(t){const e=Vp().keyFromPublic(Pl(this.publicKey)),r=Vp().keyFromPublic(Pl(t));return"0x"+e.pub.add(r.pub).encodeCompressed("hex")}signDigest(t){const e=Vp().keyFromPrivate(Pl(this.privateKey)),r=Pl(t);32!==r.length&&Fp.throwArgumentError("bad digest length","digest",t);const i=e.sign(r,{canonical:!0});return ql({recoveryParam:i.recoveryParam,r:Ll("0x"+i.r.toString(16),32),s:Ll("0x"+i.s.toString(16),32)})}computeSharedSecret(t){const e=Vp().keyFromPrivate(Pl(this.privateKey)),r=Vp().keyFromPublic(Pl(Wp(t)));return Ll("0x"+e.derive(r.getPublic()).toString(16),32)}static isSigningKey(t){return!(!t||!t._isSigningKey)}}function Wp(t,e){const r=Pl(t);if(32===r.length){const t=new Hp(r);return e?"0x"+Vp().keyFromPrivate(r).getPublic(!0,"hex"):t.publicKey}return 33===r.length?e?Cl(r):"0x"+Vp().keyFromPublic(r).getPublic(!1,"hex"):65===r.length?e?"0x"+Vp().keyFromPublic(r).getPublic(!0,"hex"):Cl(r):Fp.throwArgumentError("invalid public or private key","key","[REDACTED]")}var Jp;new Sl("transactions/5.7.0"),function(t){t[t.legacy=0]="legacy",t[t.eip2930=1]="eip2930",t[t.eip1559=2]="eip1559"}(Jp||(Jp={}));var Gp=r(916),$p=r.n(Gp);class Yp{constructor(t){this.client=t}}class Qp{constructor(t){this.opts=t}}const Xp={wc_authRequest:{req:{ttl:Y.ONE_DAY,prompt:!0,tag:3e3},res:{ttl:Y.ONE_DAY,prompt:!1,tag:3001}}},Zp={min:Y.FIVE_MINUTES,max:Y.SEVEN_DAYS},tg="authClient",eg="wc@1:auth:",rg=`${eg}:PUB_KEY`;function ig(t){return t?.split(":")}function ng(t){const e=t&&ig(t);if(e)return e.pop()}async function sg(t,e,r,i,n){switch(r.t){case"eip191":return function(t,e,r){return function(t,e){return function(t){return ep(kl(Dl(kl(Wp(t),1)),12))}(function(t,e){const r=ql(e),i={r:Pl(r.r),s:Pl(r.s)};return"0x"+Vp().recoverPubKey(Pl(t),i,r.recoveryParam).encode("hex",!1)}(Pl(t),e))}(Wl(e),r).toLowerCase()===t.toLowerCase()}(t,e,r.s);case"eip1271":return await async function(t,e,r,i,n){try{const s="0x1626ba7e",o="0000000000000000000000000000000000000000000000000000000000000040",a="0000000000000000000000000000000000000000000000000000000000000041",h=r.substring(2),c=s+Wl(e).substring(2)+o+a+h,f=await $p()(`https://rpc.walletconnect.com/v1/?chainId=${i}&projectId=${n}`,{method:"POST",body:JSON.stringify({id:Date.now()+Math.floor(1e3*Math.random()),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:c},"latest"]})}),{result:u}=await f.json();return!!u&&u.slice(0,s.length).toLowerCase()===s.toLowerCase()}catch(t){return console.error("isValidEip1271Signature: ",t),!1}}(t,e,r.s,i,n);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}function og(t){return t.getAll().filter((t=>"requester"in t))}function ag(t,e){return og(t).find((t=>t.id===e))}var hg=function(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i>>0,o=new Uint8Array(s);t[e];){var f=r[t.charCodeAt(e)];if(255===f)return;for(var u=0,d=s-1;(0!==f||u>>0,o[d]=f%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");n=u,e++}if(" "!==t[e]){for(var l=s-n;l!==s&&0===o[l];)l++;for(var p=new Uint8Array(i+(s-l)),g=i;l!==s;)p[g++]=o[l++];return p}}}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var r=0,i=0,n=0,s=e.length;n!==s&&0===e[n];)n++,r++;for(var o=(s-n)*f+1>>>0,c=new Uint8Array(o);n!==s;){for(var u=e[n],d=0,l=o-1;(0!==u||d>>0,c[l]=u%a>>>0,u=u/a>>>0;if(0!==u)throw new Error("Non-zero carry");i=d,n++}for(var p=o-i;p!==o&&0===c[p];)p++;for(var g=h.repeat(r);p{if(t instanceof Uint8Array&&"Uint8Array"===t.constructor.name)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};class fg{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class ug{constructor(t,e,r){if(this.name=t,this.prefix=e,void 0===e.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if("string"==typeof t){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(t){return lg(this,t)}}class dg{constructor(t){this.decoders=t}or(t){return lg(this,t)}decode(t){const e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const lg=(t,e)=>new dg({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class pg{constructor(t,e,r,i){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=i,this.encoder=new fg(t,e,r),this.decoder=new ug(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const gg=({name:t,prefix:e,encode:r,decode:i})=>new pg(t,e,r,i),mg=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=hg(r,e);return gg({prefix:t,name:e,encode:i,decode:t=>cg(n(t))})},bg=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>gg({prefix:e,name:t,encode:t=>((t,e,r)=>{const i="="===e[e.length-1],n=(1<r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<((t,e,r,i)=>{const n={};for(let t=0;t=8&&(a-=8,o[c++]=255&h>>a)}if(a>=r||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o})(e,i,r,t)}),yg=gg({prefix:"\0",name:"identity",encode:t=>(t=>(new TextDecoder).decode(t))(t),decode:t=>(t=>(new TextEncoder).encode(t))(t)});var vg=Object.freeze({__proto__:null,identity:yg});const wg=bg({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _g=Object.freeze({__proto__:null,base2:wg});const Ag=bg({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mg=Object.freeze({__proto__:null,base8:Ag});const Sg=mg({prefix:"9",name:"base10",alphabet:"0123456789"});var Eg=Object.freeze({__proto__:null,base10:Sg});const Ig=bg({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xg=bg({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Og=Object.freeze({__proto__:null,base16:Ig,base16upper:xg});const Ng=bg({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pg=bg({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rg=bg({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tg=bg({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cg=bg({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),kg=bg({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lg=bg({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qg=bg({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ug=bg({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bg=Object.freeze({__proto__:null,base32:Ng,base32upper:Pg,base32pad:Rg,base32padupper:Tg,base32hex:Cg,base32hexupper:kg,base32hexpad:Lg,base32hexpadupper:qg,base32z:Ug});const Dg=mg({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zg=mg({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jg=Object.freeze({__proto__:null,base36:Dg,base36upper:zg});const Fg=mg({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kg=mg({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vg=Object.freeze({__proto__:null,base58btc:Fg,base58flickr:Kg});const Hg=bg({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wg=bg({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jg=bg({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gg=bg({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $g=Object.freeze({__proto__:null,base64:Hg,base64pad:Wg,base64url:Jg,base64urlpad:Gg});const Yg=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),Qg=Yg.reduce(((t,e,r)=>(t[r]=e,t)),[]),Xg=Yg.reduce(((t,e,r)=>(t[e.codePointAt(0)]=r,t)),[]),Zg=gg({prefix:"🚀",name:"base256emoji",encode:function(t){return t.reduce(((t,e)=>t+Qg[e]),"")},decode:function(t){const e=[];for(const r of t){const t=Xg[r.codePointAt(0)];if(void 0===t)throw new Error(`Non-base256emoji character: ${r}`);e.push(t)}return new Uint8Array(e)}});var tm=Object.freeze({__proto__:null,base256emoji:Zg}),em=128,rm=-128,im=Math.pow(2,31),nm=128,sm=127,om=Math.pow(2,7),am=Math.pow(2,14),hm=Math.pow(2,21),cm=Math.pow(2,28),fm=Math.pow(2,35),um=Math.pow(2,42),dm=Math.pow(2,49),lm=Math.pow(2,56),pm=Math.pow(2,63),gm={encode:function t(e,r,i){r=r||[];for(var n=i=i||0;e>=im;)r[i++]=255&e|em,e/=128;for(;e&rm;)r[i++]=255&e|em,e>>>=7;return r[i]=0|e,t.bytes=i-n+1,r},decode:function t(e,r){var i,n=0,s=(r=r||0,0),o=r,a=e.length;do{if(o>=a)throw t.bytes=0,new RangeError("Could not decode varint");i=e[o++],n+=s<28?(i&sm)<=nm);return t.bytes=o-r,n},encodingLength:function(t){return t(mm.encode(t,e,r),e),ym=t=>mm.encodingLength(t),vm=(t,e)=>{const r=e.byteLength,i=ym(t),n=i+ym(r),s=new Uint8Array(n+r);return bm(t,s,0),bm(r,s,i),s.set(e,n),new wm(t,r,e,s)};class wm{constructor(t,e,r,i){this.code=t,this.size=e,this.digest=r,this.bytes=i}}const _m=({name:t,code:e,encode:r})=>new Am(t,e,r);class Am{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){const e=this.encode(t);return e instanceof Uint8Array?vm(this.code,e):e.then((t=>vm(this.code,t)))}throw Error("Unknown type, must be binary type")}}const Mm=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Sm=_m({name:"sha2-256",code:18,encode:Mm("SHA-256")}),Em=_m({name:"sha2-512",code:19,encode:Mm("SHA-512")});Object.freeze({__proto__:null,sha256:Sm,sha512:Em});const Im=cg,xm={code:0,name:"identity",encode:Im,digest:t=>vm(0,Im(t))};Object.freeze({__proto__:null,identity:xm}),new TextEncoder,new TextDecoder;const Om={...vg,..._g,...Mg,...Eg,...Og,...Bg,...jg,...Vg,...$g,...tm};function Nm(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const Pm=Nm("utf8","u",(t=>"u"+new TextDecoder("utf8").decode(t)),(t=>(new TextEncoder).encode(t.substring(1)))),Rm=Nm("ascii","a",(t=>{let e="a";for(let r=0;r{const e=function(t=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}((t=t.substring(1)).length);for(let r=0;re in t?km(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jm=(t,e)=>{for(var r in e||(e={}))Bm.call(e,r)&&zm(t,r,e[r]);if(Um)for(var r of Um(e))Dm.call(e,r)&&zm(t,r,e[r]);return t},Fm=(t,e)=>Lm(t,qm(e));class Km extends Yp{constructor(t){super(t),this.initialized=!1,this.name="authEngine",this.init=()=>{this.initialized||(this.registerRelayerEvents(),this.registerPairingEvents(),this.client.core.pairing.register({methods:Object.keys(Xp)}),this.initialized=!0)},this.request=async(t,e)=>{if(this.isInitialized(),!function(t){const e=lc(t.aud),r=new RegExp(`${t.domain}`).test(t.aud),i=!!t.nonce,n=!t.type||"eip4361"===t.type,s=t.expiry;if(s&&!Mc(s,Zp)){const{message:t}=sc("MISSING_OR_INVALID",`request() expiry: ${s}. Expiry must be a number (in seconds) between ${Zp.min} and ${Zp.max}`);throw new Error(t)}return!!(e&&r&&i&&n)}(t))throw new Error("Invalid request");if(null!=e&&e.topic)return await this.requestOnKnownPairing(e.topic,t);const{chainId:r,statement:i,aud:n,domain:s,nonce:o,type:a,exp:h,nbf:c}=t,{topic:f,uri:u}=await this.client.core.pairing.create();this.client.logger.info({message:"Generated new pairing",pairing:{topic:f,uri:u}});const d=await this.client.core.crypto.generateKeyPair(),l=wh(d);await this.client.authKeys.set(rg,{responseTopic:l,publicKey:d}),await this.client.pairingTopics.set(l,{topic:l,pairingTopic:f}),await this.client.core.relayer.subscribe(l),this.client.logger.info(`sending request to new pairing topic: ${f}`);const p=await this.sendRequest(f,"wc_authRequest",{payloadParams:{type:a??"eip4361",chainId:r,statement:i,aud:n,domain:s,version:"1",nonce:o,iat:(new Date).toISOString(),exp:h,nbf:c},requester:{publicKey:d,metadata:this.client.metadata}},{},t.expiry);return this.client.logger.info(`sent request to new pairing topic: ${f}`),{uri:u,id:p}},this.respond=async(t,e)=>{if(this.isInitialized(),!function(t,e){return!!ag(e,t.id)}(t,this.client.requests))throw new Error("Invalid response");const r=ag(this.client.requests,t.id);if(!r)throw new Error(`Could not find pending auth request with id ${t.id}`);const i=r.requester.publicKey,n=await this.client.core.crypto.generateKeyPair(),s=wh(i),o={type:1,receiverPublicKey:i,senderPublicKey:n};if("error"in t)return void await this.sendError(r.id,s,t,o);const a={h:{t:"eip4361"},p:Fm(jm({},r.cacaoPayload),{iss:e}),s:t.signature};await this.sendResult(r.id,s,a,o),await this.client.core.pairing.activate({topic:r.pairingTopic}),await this.client.requests.update(r.id,jm({},a))},this.getPendingRequests=()=>og(this.client.requests),this.formatMessage=(t,e)=>{this.client.logger.debug(`formatMessage, cacao is: ${JSON.stringify(t)}`);const r=`${t.domain} wants you to sign in with your Ethereum account:`,i=ng(e),n=t.statement,s=`URI: ${t.aud}`,o=`Version: ${t.version}`,a=`Chain ID: ${function(t){const e=t&&ig(t);if(e)return e[3]}(e)}`;return[r,i,"",n,"",s,o,a,`Nonce: ${t.nonce}`,`Issued At: ${t.iat}`,t.exp?`Expiry: ${t.exp}`:void 0,t.resources&&t.resources.length>0?`Resources:\n${t.resources.map((t=>`- ${t}`)).join("\n")}`:void 0].filter((t=>null!=t)).join("\n")},this.setExpiry=async(t,e)=>{this.client.core.pairing.pairings.keys.includes(t)&&await this.client.core.pairing.updateExpiry({topic:t,expiry:e}),this.client.core.expirer.set(t,e)},this.sendRequest=async(t,e,r,i,n)=>{const s=Vc(e,r),o=await this.client.core.crypto.encode(t,s,i),a=Xp[e].req;if(n&&(a.ttl=n),this.client.core.history.set(t,s),li()){const t=Cm(JSON.stringify(s));this.client.core.verify.register({attestationId:t})}return await this.client.core.relayer.publish(t,o,Fm(jm({},a),{internal:{throwOnFailedPublish:!0}})),s.id},this.sendResult=async(t,e,r,i)=>{const n=Hc(t,r),s=await this.client.core.crypto.encode(e,n,i),o=await this.client.core.history.get(e,t),a=Xp[o.request.method].res;return await this.client.core.relayer.publish(e,s,Fm(jm({},a),{internal:{throwOnFailedPublish:!0}})),await this.client.core.history.resolve(n),n.id},this.sendError=async(t,e,r,i)=>{const n=Wc(t,r.error),s=await this.client.core.crypto.encode(e,n,i),o=await this.client.core.history.get(e,t),a=Xp[o.request.method].res;return await this.client.core.relayer.publish(e,s,a),await this.client.core.history.resolve(n),n.id},this.requestOnKnownPairing=async(t,e)=>{const r=this.client.core.pairing.pairings.getAll({active:!0}).find((e=>e.topic===t));if(!r)throw new Error(`Could not find pairing for provided topic ${t}`);const{publicKey:i}=this.client.authKeys.get(rg),{chainId:n,statement:s,aud:o,domain:a,nonce:h,type:c}=e,f=await this.sendRequest(r.topic,"wc_authRequest",{payloadParams:{type:c??"eip4361",chainId:n,statement:s,aud:o,domain:a,version:"1",nonce:h,iat:(new Date).toISOString()},requester:{publicKey:i,metadata:this.client.metadata}},{},e.expiry);return this.client.logger.info(`sent request to known pairing topic: ${r.topic}`),{id:f}},this.onPairingCreated=t=>{const e=this.getPendingRequests();if(e){const r=Object.values(e).find((e=>e.pairingTopic===t.topic));r&&this.handleAuthRequest(r)}},this.onRelayEventRequest=t=>{const{topic:e,payload:r}=t,i=r.method;return"wc_authRequest"===i?this.onAuthRequest(e,r):this.client.logger.info(`Unsupported request method ${i}`)},this.onRelayEventResponse=async t=>{const{topic:e,payload:r}=t,i=(await this.client.core.history.get(e,r.id)).request.method;return"wc_authRequest"===i?this.onAuthResponse(e,r):this.client.logger.info(`Unsupported response method ${i}`)},this.onAuthRequest=async(t,e)=>{const{requester:r,payloadParams:i}=e.params;this.client.logger.info({type:"onAuthRequest",topic:t,payload:e});const n=Cm(JSON.stringify(e)),s=await this.getVerifyContext(n,this.client.metadata),o={requester:r,pairingTopic:t,id:e.id,cacaoPayload:i,verifyContext:s};await this.client.requests.set(e.id,o),this.handleAuthRequest(o)},this.handleAuthRequest=async t=>{const{id:e,pairingTopic:r,requester:i,cacaoPayload:n,verifyContext:s}=t;try{this.client.emit("auth_request",{id:e,topic:r,params:{requester:i,cacaoPayload:n},verifyContext:s})}catch(e){await this.sendError(t.id,t.pairingTopic,e),this.client.logger.error(e)}},this.onAuthResponse=async(t,e)=>{const{id:r}=e;if(this.client.logger.info({type:"onAuthResponse",topic:t,response:e}),ef(e)){const{pairingTopic:i}=this.client.pairingTopics.get(t);await this.client.core.pairing.activate({topic:i});const{s:n,p:s}=e.result;await this.client.requests.set(r,jm({id:r,pairingTopic:i},e.result));const o=this.formatMessage(s,s.iss);this.client.logger.debug("reconstructed message:\n",JSON.stringify(o)),this.client.logger.debug("payload.iss:",s.iss),this.client.logger.debug("signature:",n);const a=ng(s.iss),h=function(t){const e=t&&ig(t);if(e)return e[2]+":"+e[3]}(s.iss);if(!a)throw new Error("Could not derive address from `payload.iss`");if(!h)throw new Error("Could not derive chainId from `payload.iss`");this.client.logger.debug("walletAddress extracted from `payload.iss`:",a),await sg(a,o,n,h,this.client.projectId)?this.client.emit("auth_response",{id:r,topic:t,params:e}):this.client.emit("auth_response",{id:r,topic:t,params:{message:"Invalid signature",code:-1}})}else rf(e)&&this.client.emit("auth_response",{id:r,topic:t,params:e})},this.getVerifyContext=async(t,e)=>{const r={verified:{verifyUrl:e.verifyUrl||"",validation:"UNKNOWN",origin:e.url||""}};try{const i=await this.client.core.verify.resolve({attestationId:t,verifyUrl:e.verifyUrl});i&&(r.verified.origin=i.origin,r.verified.isScam=i.isScam,r.verified.validation=origin===new URL(e.url).origin?"VALID":"INVALID")}catch(t){this.client.logger.error(t)}return this.client.logger.info(`Verify context: ${JSON.stringify(r)}`),r}}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}registerRelayerEvents(){this.client.core.relayer.on(Fu,(async t=>{const{topic:e,message:r}=t,{responseTopic:i,publicKey:n}=this.client.authKeys.keys.includes(rg)?this.client.authKeys.get(rg):{responseTopic:void 0,publicKey:void 0};if(i&&e!==i)return void this.client.logger.debug("[Auth] Ignoring message from unknown topic",e);const s=await this.client.core.crypto.decode(e,r,{receiverPublicKey:n});Zc(s)?(this.client.core.history.set(e,s),this.onRelayEventRequest({topic:e,payload:s})):tf(s)&&(await this.client.core.history.resolve(s),this.onRelayEventResponse({topic:e,payload:s}))}))}registerPairingEvents(){this.client.core.pairing.events.on(id,(t=>this.onPairingCreated(t)))}}class Vm extends Qp{constructor(t){super(t),this.protocol="wc",this.version=1,this.name=tg,this.events=new b.EventEmitter,this.emit=(t,e)=>this.events.emit(t,e),this.on=(t,e)=>this.events.on(t,e),this.once=(t,e)=>this.events.once(t,e),this.off=(t,e)=>this.events.off(t,e),this.removeListener=(t,e)=>this.events.removeListener(t,e),this.request=async(t,e)=>{try{return await this.engine.request(t,e)}catch(t){throw this.logger.error(t.message),t}},this.respond=async(t,e)=>{try{return await this.engine.respond(t,e)}catch(t){throw this.logger.error(t.message),t}},this.getPendingRequests=()=>{try{return this.engine.getPendingRequests()}catch(t){throw this.logger.error(t.message),t}},this.formatMessage=(t,e)=>{try{return this.engine.formatMessage(t,e)}catch(t){throw this.logger.error(t.message),t}};const e=typeof t.logger<"u"&&"string"!=typeof t.logger?t.logger:it()(vt({level:t.logger||"error"}));this.name=t?.name||tg,this.metadata=t.metadata,this.projectId=t.projectId,this.core=t.core||new pl(t),this.logger=_t(e,this.name),this.authKeys=new Vd(this.core,this.logger,"authKeys",eg,(()=>rg)),this.pairingTopics=new Vd(this.core,this.logger,"pairingTopics",eg),this.requests=new Vd(this.core,this.logger,"requests",eg,(t=>t.id)),this.engine=new Km(this)}static async init(t){const e=new Vm(t);return await e.initialize(),e}get context(){return wt(this.logger)}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.authKeys.init(),await this.requests.init(),await this.pairingTopics.init(),await this.engine.init(),this.logger.info("AuthClient Initialization Success"),this.logger.info({authClient:this})}catch(t){throw this.logger.info("AuthClient Initialization Failure"),this.logger.error(t.message),t}}}const Hm=Vm,Wm="client",Jm=`wc@2:${Wm}:`,Gm=Wm,$m="WALLETCONNECT_DEEPLINK_CHOICE",Ym=Y.SEVEN_DAYS,Qm={wc_sessionPropose:{req:{ttl:Y.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1104},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1106},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:Y.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:Y.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1112},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:Y.ONE_DAY,prompt:!1,tag:1114},res:{ttl:Y.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:Y.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:Y.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:Y.FIVE_MINUTES,prompt:!1,tag:1119}}},Xm={min:Y.FIVE_MINUTES,max:Y.SEVEN_DAYS},Zm="IDLE",tb="ACTIVE",eb=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],rb="wc@1.5:auth:",ib=`${rb}:PUB_KEY`;var nb=Object.defineProperty,sb=Object.defineProperties,ob=Object.getOwnPropertyDescriptors,ab=Object.getOwnPropertySymbols,hb=Object.prototype.hasOwnProperty,cb=Object.prototype.propertyIsEnumerable,fb=(t,e,r)=>e in t?nb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ub=(t,e)=>{for(var r in e||(e={}))hb.call(e,r)&&fb(t,r,e[r]);if(ab)for(var r of ab(e))cb.call(e,r)&&fb(t,r,e[r]);return t},db=(t,e)=>sb(t,ob(e));class lb extends Lt{constructor(t){super(t),this.name="engine",this.events=new(y()),this.initialized=!1,this.requestQueue={state:Zm,queue:[]},this.sessionRequestQueue={state:Zm,queue:[]},this.requestQueueDelay=Y.ONE_SECOND,this.expectedPairingMethodMap=new Map,this.recentlyDeletedMap=new Map,this.recentlyDeletedLimit=200,this.relayMessageCache=[],this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.registerPairingEvents(),await this.registerLinkModeListeners(),this.client.core.pairing.register({methods:Object.keys(Qm)}),this.initialized=!0,setTimeout((()=>{this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()}),(0,Y.toMiliseconds)(this.requestQueueDelay)))},this.connect=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();const e=db(ub({},t),{requiredNamespaces:t.requiredNamespaces||{},optionalNamespaces:t.optionalNamespaces||{}});await this.isValidConnect(e);const{pairingTopic:r,requiredNamespaces:i,optionalNamespaces:n,sessionProperties:s,relays:o}=e;let a,h=r,c=!1;try{h&&(c=this.client.core.pairing.pairings.get(h).active)}catch(t){throw this.client.logger.error(`connect() -> pairing.get(${h}) failed`),t}if(!h||!c){const{topic:t,uri:e}=await this.client.core.pairing.create();h=t,a=e}if(!h){const{message:t}=sc("NO_MATCHING_KEY",`connect() pairing topic: ${h}`);throw new Error(t)}const f=await this.client.core.crypto.generateKeyPair(),u=Qm.wc_sessionPropose.req.ttl||Y.FIVE_MINUTES,d=Mi(u),l=ub({requiredNamespaces:i,optionalNamespaces:n,relays:o??[{protocol:"irn"}],proposer:{publicKey:f,metadata:this.client.metadata},expiryTimestamp:d,pairingTopic:h},s&&{sessionProperties:s}),{reject:p,resolve:g,done:m}=vi(u,"Proposal expired");this.events.once(Ei("session_connect"),(async({error:t,session:e})=>{if(t)p(t);else if(e){e.self.publicKey=f;const t=db(ub({},e),{pairingTopic:l.pairingTopic,requiredNamespaces:l.requiredNamespaces,optionalNamespaces:l.optionalNamespaces,transportType:Qu.relay});await this.client.session.set(e.topic,t),await this.setExpiry(e.topic,e.expiry),h&&await this.client.core.pairing.updateMetadata({topic:h,metadata:e.peer.metadata}),this.cleanupDuplicatePairings(t),g(t)}}));const b=await this.sendRequest({topic:h,method:"wc_sessionPropose",params:l,throwOnFailedPublish:!0});return await this.setProposal(b,ub({id:b},l)),{uri:a,approval:m}},this.pair=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(t)}catch(t){throw this.client.logger.error("pair() failed"),t}},this.approve=async t=>{var e,r,i;const n=this.client.core.eventClient.createEvent({properties:{topic:null==(e=t?.id)?void 0:e.toString(),trace:[md]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(t){throw n.setError("no_internet_connection"),t}try{await this.isValidProposalId(t?.id)}catch(e){throw this.client.logger.error(`approve() -> proposal.get(${t?.id}) failed`),n.setError("proposal_not_found"),e}try{await this.isValidApprove(t)}catch(t){throw this.client.logger.error("approve() -> isValidApprove() failed"),n.setError("session_approve_namespace_validation_failure"),t}const{id:s,relayProtocol:o,namespaces:a,sessionProperties:h,sessionConfig:c}=t,f=this.client.proposal.get(s);this.client.core.eventClient.deleteEvent({eventId:n.eventId});const{pairingTopic:u,proposer:d,requiredNamespaces:l,optionalNamespaces:p}=f;let g=null==(r=this.client.core.eventClient)?void 0:r.getEvent({topic:u});g||(g=null==(i=this.client.core.eventClient)?void 0:i.createEvent({type:md,properties:{topic:u,trace:[md,"session_namespaces_validation_success"]}}));const m=await this.client.core.crypto.generateKeyPair(),b=d.publicKey,y=await this.client.core.crypto.generateSharedKey(m,b),v=ub(ub({relay:{protocol:o??"irn"},namespaces:a,controller:{publicKey:m,metadata:this.client.metadata},expiry:Mi(Ym)},h&&{sessionProperties:h}),c&&{sessionConfig:c}),w=Qu.relay;g.addTrace("subscribing_session_topic");try{await this.client.core.relayer.subscribe(y,{transportType:w})}catch(t){throw g.setError("subscribe_session_topic_failure"),t}g.addTrace("subscribe_session_topic_success");const _=db(ub({},v),{topic:y,requiredNamespaces:l,optionalNamespaces:p,pairingTopic:u,acknowledged:!1,self:v.controller,peer:{publicKey:d.publicKey,metadata:d.metadata},controller:m,transportType:Qu.relay});await this.client.session.set(y,_),g.addTrace("store_session");try{g.addTrace("publishing_session_settle"),await this.sendRequest({topic:y,method:"wc_sessionSettle",params:v,throwOnFailedPublish:!0}).catch((t=>{throw g?.setError("session_settle_publish_failure"),t})),g.addTrace("session_settle_publish_success"),g.addTrace("publishing_session_approve"),await this.sendResult({id:s,topic:u,result:{relay:{protocol:o??"irn"},responderPublicKey:m},throwOnFailedPublish:!0}).catch((t=>{throw g?.setError("session_approve_publish_failure"),t})),g.addTrace("session_approve_publish_success")}catch(t){throw this.client.logger.error(t),this.client.session.delete(y,oc("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(y),t}return this.client.core.eventClient.deleteEvent({eventId:g.eventId}),await this.client.core.pairing.updateMetadata({topic:u,metadata:d.metadata}),await this.client.proposal.delete(s,oc("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:u}),await this.setExpiry(y,Mi(Ym)),{topic:y,acknowledged:()=>Promise.resolve(this.client.session.get(y))}},this.reject=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(t)}catch(t){throw this.client.logger.error("reject() -> isValidReject() failed"),t}const{id:e,reason:r}=t;let i;try{i=this.client.proposal.get(e).pairingTopic}catch(t){throw this.client.logger.error(`reject() -> proposal.get(${e}) failed`),t}i&&(await this.sendError({id:e,topic:i,error:r,rpcOpts:Qm.wc_sessionPropose.reject}),await this.client.proposal.delete(e,oc("USER_DISCONNECTED")))},this.update=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(t)}catch(t){throw this.client.logger.error("update() -> isValidUpdate() failed"),t}const{topic:e,namespaces:r}=t,{done:i,resolve:n,reject:s}=vi(),o=Fc(),a=Kc().toString(),h=this.client.session.get(e).namespaces;return this.events.once(Ei("session_update",o),(({error:t})=>{t?s(t):n()})),await this.client.session.update(e,{namespaces:r}),await this.sendRequest({topic:e,method:"wc_sessionUpdate",params:{namespaces:r},throwOnFailedPublish:!0,clientRpcId:o,relayRpcId:a}).catch((t=>{this.client.logger.error(t),this.client.session.update(e,{namespaces:h}),s(t)})),{acknowledged:i}},this.extend=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(t)}catch(t){throw this.client.logger.error("extend() -> isValidExtend() failed"),t}const{topic:e}=t,r=Fc(),{done:i,resolve:n,reject:s}=vi();return this.events.once(Ei("session_extend",r),(({error:t})=>{t?s(t):n()})),await this.setExpiry(e,Mi(Ym)),this.sendRequest({topic:e,method:"wc_sessionExtend",params:{},clientRpcId:r,throwOnFailedPublish:!0}).catch((t=>{s(t)})),{acknowledged:i}},this.request=async t=>{this.isInitialized();try{await this.isValidRequest(t)}catch(t){throw this.client.logger.error("request() -> isValidRequest() failed"),t}const{chainId:e,request:i,topic:n,expiry:s=Qm.wc_sessionRequest.req.ttl}=t,o=this.client.session.get(n);o?.transportType===Qu.relay&&await this.confirmOnlineStateOrThrow();const a=Fc(),h=Kc().toString(),{done:c,resolve:f,reject:u}=vi(s,"Request expired. Please try again.");this.events.once(Ei("session_request",a),(({error:t,result:e})=>{t?u(t):f(e)}));const d=this.getAppLinkIfEnabled(o.peer.metadata,o.transportType);return d?(await this.sendRequest({clientRpcId:a,relayRpcId:h,topic:n,method:"wc_sessionRequest",params:{request:db(ub({},i),{expiryTimestamp:Mi(s)}),chainId:e},expiry:s,throwOnFailedPublish:!0,appLink:d}).catch((t=>u(t))),this.client.events.emit("session_request_sent",{topic:n,request:i,chainId:e,id:a}),await c()):await Promise.all([new Promise((async t=>{await this.sendRequest({clientRpcId:a,relayRpcId:h,topic:n,method:"wc_sessionRequest",params:{request:db(ub({},i),{expiryTimestamp:Mi(s)}),chainId:e},expiry:s,throwOnFailedPublish:!0}).catch((t=>u(t))),this.client.events.emit("session_request_sent",{topic:n,request:i,chainId:e,id:a}),t()})),new Promise((async t=>{var e;if(null==(e=o.sessionConfig)||!e.disableDeepLink){const t=await async function(t,e){try{return await t.getItem(e)||(li()?localStorage.getItem(e):void 0)}catch(t){console.error(t)}}(this.client.core.storage,$m);!async function({id:t,topic:e,wcDeepLink:i}){var n;try{if(!i)return;const s="string"==typeof i?JSON.parse(i):i;let o=s?.href;if("string"!=typeof o)return;o.endsWith("/")&&(o=o.slice(0,-1));const a=`${o}/wc?requestId=${t}&sessionTopic=${e}`,h=pi();if(h===ci.browser){if(null==(n=(0,Ur.getDocument)())||!n.hasFocus())return void console.warn("Document does not have focus, skipping deeplink.");a.startsWith("https://")||a.startsWith("http://")?window.open(a,"_blank","noreferrer noopener"):window.open(a,"_self","noreferrer noopener")}else h===ci.reactNative&&typeof(null==r.g?void 0:r.g.Linking)<"u"&&await r.g.Linking.openURL(a)}catch(t){console.error(t)}}({id:a,topic:n,wcDeepLink:t})}t()})),c()]).then((t=>t[2]))},this.respond=async t=>{this.isInitialized(),await this.isValidRespond(t);const{topic:e,response:r}=t,{id:i}=r,n=this.client.session.get(e);n.transportType===Qu.relay&&await this.confirmOnlineStateOrThrow();const s=this.getAppLinkIfEnabled(n.peer.metadata,n.transportType);ef(r)?await this.sendResult({id:i,topic:e,result:r.result,throwOnFailedPublish:!0,appLink:s}):rf(r)&&await this.sendError({id:i,topic:e,error:r.error,appLink:s}),this.cleanupAfterResponse(t)},this.ping=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(t)}catch(t){throw this.client.logger.error("ping() -> isValidPing() failed"),t}const{topic:e}=t;if(this.client.session.keys.includes(e)){const t=Fc(),r=Kc().toString(),{done:i,resolve:n,reject:s}=vi();this.events.once(Ei("session_ping",t),(({error:t})=>{t?s(t):n()})),await Promise.all([this.sendRequest({topic:e,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:t,relayRpcId:r}),i()])}else this.client.core.pairing.pairings.keys.includes(e)&&await this.client.core.pairing.ping({topic:e})},this.emit=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(t);const{topic:e,event:r,chainId:i}=t,n=Kc().toString();await this.sendRequest({topic:e,method:"wc_sessionEvent",params:{event:r,chainId:i},throwOnFailedPublish:!0,relayRpcId:n})},this.disconnect=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(t);const{topic:e}=t;if(this.client.session.keys.includes(e))await this.sendRequest({topic:e,method:"wc_sessionDelete",params:oc("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:e,emitEvent:!1});else{if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:t}=sc("MISMATCHED_TOPIC",`Session or pairing topic not found: ${e}`);throw new Error(t)}await this.client.core.pairing.disconnect({topic:e})}},this.find=t=>(this.isInitialized(),this.client.session.getAll().filter((e=>function(t,e){const{requiredNamespaces:r}=e,i=Object.keys(t.namespaces),n=Object.keys(r);let s=!0;return!!mi(n,i)&&(i.forEach((e=>{const{accounts:i,methods:n,events:o}=t.namespaces[e],a=Xh(i),h=r[e];mi(ei(e,h),a)&&mi(h.methods,n)&&mi(h.events,o)||(s=!1)})),s)}(e,t)))),this.getPendingSessionRequests=()=>this.client.pendingRequest.getAll(),this.authenticate=async(t,e)=>{var r;this.isInitialized(),this.isValidAuthenticate(t);const i=e&&this.client.core.linkModeSupportedApps.includes(e)&&(null==(r=this.client.metadata.redirect)?void 0:r.linkMode),n=i?Qu.link_mode:Qu.relay;n===Qu.relay&&await this.confirmOnlineStateOrThrow();const{chains:s,statement:o="",uri:a,domain:h,nonce:c,type:f,exp:u,nbf:d,methods:l=[],expiry:p}=t,g=[...t.resources||[]],{topic:m,uri:b}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:n});this.client.logger.info({message:"Generated new pairing",pairing:{topic:m,uri:b}});const y=await this.client.core.crypto.generateKeyPair(),v=wh(y);if(await Promise.all([this.client.auth.authKeys.set(ib,{responseTopic:v,publicKey:y}),this.client.auth.pairingTopics.set(v,{topic:v,pairingTopic:m})]),await this.client.core.relayer.subscribe(v,{transportType:n}),this.client.logger.info(`sending request to new pairing topic: ${m}`),l.length>0){const{namespace:t}=ti(s[0]);let e=function(t,e,r){const i=function(t,e,r,i={}){return r?.sort(((t,e)=>t.localeCompare(e))),{att:{[t]:ah(e,r,i)}}}(t,e,r);return hh(i)}(t,"request",l);lh(g)&&(e=fh(e,g.pop())),g.push(e)}const w=p&&p>Qm.wc_sessionAuthenticate.req.ttl?p:Qm.wc_sessionAuthenticate.req.ttl,_={authPayload:{type:f??"caip122",chains:s,statement:o,aud:a,domain:h,version:"1",nonce:c,iat:(new Date).toISOString(),exp:u,nbf:d,resources:g},requester:{publicKey:y,metadata:this.client.metadata},expiryTimestamp:Mi(w)},A={requiredNamespaces:{},optionalNamespaces:{eip155:{chains:s,methods:[...new Set(["personal_sign",...l])],events:["chainChanged","accountsChanged"]}},relays:[{protocol:"irn"}],pairingTopic:m,proposer:{publicKey:y,metadata:this.client.metadata},expiryTimestamp:Mi(Qm.wc_sessionPropose.req.ttl)},{done:M,resolve:S,reject:E}=vi(w,"Request expired"),I=async({error:t,session:e})=>{if(this.events.off(Ei("session_request",O),x),t)E(t);else if(e){e.self.publicKey=y,await this.client.session.set(e.topic,e),await this.setExpiry(e.topic,e.expiry),m&&await this.client.core.pairing.updateMetadata({topic:m,metadata:e.peer.metadata});const t=this.client.session.get(e.topic);await this.deleteProposal(N),S({session:t})}},x=async t=>{var r,i,s;if(await this.deletePendingAuthRequest(O,{message:"fulfilled",code:0}),t.error){const e=oc("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return t.error.code===e.code?void 0:(this.events.off(Ei("session_connect"),I),E(t.error.message))}await this.deleteProposal(N),this.events.off(Ei("session_connect"),I);const{cacaos:o,responder:a}=t.result,h=[],c=[];for(const t of o){await nh({cacao:t,projectId:this.client.core.projectId})||(this.client.logger.error(t,"Signature verification failed"),E(oc("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:e}=t,r=lh(e.resources),i=[rh(e.iss)],n=ih(e.iss);if(r){const t=uh(r),e=dh(r);h.push(...t),i.push(...e)}for(const t of i)c.push(`${t}:${n}`)}const f=await this.client.core.crypto.generateSharedKey(y,a.publicKey);let u;h.length>0&&(u={topic:f,acknowledged:!0,self:{publicKey:y,metadata:this.client.metadata},peer:a,controller:a.publicKey,expiry:Mi(Ym),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:m,namespaces:rc([...new Set(h)],[...new Set(c)]),transportType:n},await this.client.core.relayer.subscribe(f,{transportType:n}),await this.client.session.set(f,u),m&&await this.client.core.pairing.updateMetadata({topic:m,metadata:a.metadata}),u=this.client.session.get(f)),null!=(r=this.client.metadata.redirect)&&r.linkMode&&null!=(i=a.metadata.redirect)&&i.linkMode&&null!=(s=a.metadata.redirect)&&s.universal&&e&&(this.client.core.addLinkModeSupportedApp(a.metadata.redirect.universal),this.client.session.update(f,{transportType:Qu.link_mode})),S({auths:o,session:u})},O=Fc(),N=Fc();let P;this.events.once(Ei("session_connect"),I),this.events.once(Ei("session_request",O),x);try{if(i){const t=Vc("wc_sessionAuthenticate",_,O);this.client.core.history.set(m,t);const r=await this.client.core.crypto.encode("",t,{type:2,encoding:bh});P=Fh(e,m,r)}else await Promise.all([this.sendRequest({topic:m,method:"wc_sessionAuthenticate",params:_,expiry:t.expiry,throwOnFailedPublish:!0,clientRpcId:O}),this.sendRequest({topic:m,method:"wc_sessionPropose",params:A,expiry:Qm.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:N})])}catch(t){throw this.events.off(Ei("session_connect"),I),this.events.off(Ei("session_request",O),x),t}return await this.setProposal(N,ub({id:N},A)),await this.setAuthRequest(O,{request:db(ub({},_),{verifyContext:{}}),pairingTopic:m,transportType:n}),{uri:P??b,response:M}},this.approveSessionAuthenticate=async t=>{const{id:e,auths:r}=t,i=this.client.core.eventClient.createEvent({properties:{topic:e.toString(),trace:["authenticated_session_approve_started"]}});try{this.isInitialized()}catch(t){throw i.setError("no_internet_connection"),t}const n=this.getPendingAuthRequest(e);if(!n)throw i.setError("authenticated_session_pending_request_not_found"),new Error(`Could not find pending auth request with id ${e}`);const s=n.transportType||Qu.relay;s===Qu.relay&&await this.confirmOnlineStateOrThrow();const o=n.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),h=wh(o),c={type:1,receiverPublicKey:o,senderPublicKey:a},f=[],u=[];for(const t of r){if(!await nh({cacao:t,projectId:this.client.core.projectId})){i.setError("invalid_cacao");const t=oc("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:e,topic:h,error:t,encodeOpts:c}),new Error(t.message)}i.addTrace("cacaos_verified");const{p:r}=t,n=lh(r.resources),s=[rh(r.iss)],o=ih(r.iss);if(n){const t=uh(n),e=dh(n);f.push(...t),s.push(...e)}for(const t of s)u.push(`${t}:${o}`)}const d=await this.client.core.crypto.generateSharedKey(a,o);let l;if(i.addTrace("create_authenticated_session_topic"),f?.length>0){l={topic:d,acknowledged:!0,self:{publicKey:a,metadata:this.client.metadata},peer:{publicKey:o,metadata:n.requester.metadata},controller:o,expiry:Mi(Ym),authentication:r,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:n.pairingTopic,namespaces:rc([...new Set(f)],[...new Set(u)]),transportType:s},i.addTrace("subscribing_authenticated_session_topic");try{await this.client.core.relayer.subscribe(d,{transportType:s})}catch(t){throw i.setError("subscribe_authenticated_session_topic_failure"),t}i.addTrace("subscribe_authenticated_session_topic_success"),await this.client.session.set(d,l),i.addTrace("store_authenticated_session"),await this.client.core.pairing.updateMetadata({topic:n.pairingTopic,metadata:n.requester.metadata})}i.addTrace("publishing_authenticated_session_approve");try{await this.sendResult({topic:h,id:e,result:{cacaos:r,responder:{publicKey:a,metadata:this.client.metadata}},encodeOpts:c,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(n.requester.metadata,s)})}catch(t){throw i.setError("authenticated_session_approve_publish_failure"),t}return await this.client.auth.requests.delete(e,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:n.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:i.eventId}),{session:l}},this.rejectSessionAuthenticate=async t=>{this.isInitialized();const{id:e,reason:r}=t,i=this.getPendingAuthRequest(e);if(!i)throw new Error(`Could not find pending auth request with id ${e}`);i.transportType===Qu.relay&&await this.confirmOnlineStateOrThrow();const n=i.requester.publicKey,s=await this.client.core.crypto.generateKeyPair(),o=wh(n),a={type:1,receiverPublicKey:n,senderPublicKey:s};await this.sendError({id:e,topic:o,error:r,encodeOpts:a,rpcOpts:Qm.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(i.requester.metadata,i.transportType)}),await this.client.auth.requests.delete(e,{message:"rejected",code:0}),await this.client.proposal.delete(e,oc("USER_DISCONNECTED"))},this.formatAuthMessage=t=>{this.isInitialized();const{request:e,iss:r}=t;return sh(e,r)},this.processRelayMessageCache=()=>{setTimeout((async()=>{if(0!==this.relayMessageCache.length)for(;this.relayMessageCache.length>0;)try{const t=this.relayMessageCache.shift();t&&await this.onRelayMessage(t)}catch(t){this.client.logger.error(t)}}),50)},this.cleanupDuplicatePairings=async t=>{if(t.pairingTopic)try{const e=this.client.core.pairing.pairings.get(t.pairingTopic),r=this.client.core.pairing.pairings.getAll().filter((r=>{var i,n;return(null==(i=r.peerMetadata)?void 0:i.url)&&(null==(n=r.peerMetadata)?void 0:n.url)===t.peer.metadata.url&&r.topic&&r.topic!==e.topic}));if(0===r.length)return;this.client.logger.info(`Cleaning up ${r.length} duplicate pairing(s)`),await Promise.all(r.map((t=>this.client.core.pairing.disconnect({topic:t.topic})))),this.client.logger.info("Duplicate pairings clean up finished")}catch(t){this.client.logger.error(t)}},this.deleteSession=async t=>{var e;const{topic:r,expirerHasDeleted:i=!1,emitEvent:n=!0,id:s=0}=t,{self:o}=this.client.session.get(r);await this.client.core.relayer.unsubscribe(r),await this.client.session.delete(r,oc("USER_DISCONNECTED")),this.addToRecentlyDeleted(r,"session"),this.client.core.crypto.keychain.has(o.publicKey)&&await this.client.core.crypto.deleteKeyPair(o.publicKey),this.client.core.crypto.keychain.has(r)&&await this.client.core.crypto.deleteSymKey(r),i||this.client.core.expirer.del(r),this.client.core.storage.removeItem($m).catch((t=>this.client.logger.warn(t))),this.getPendingSessionRequests().forEach((t=>{t.topic===r&&this.deletePendingSessionRequest(t.id,oc("USER_DISCONNECTED"))})),r===(null==(e=this.sessionRequestQueue.queue[0])?void 0:e.topic)&&(this.sessionRequestQueue.state=Zm),n&&this.client.events.emit("session_delete",{id:s,topic:r})},this.deleteProposal=async(t,e)=>{if(e)try{const e=this.client.proposal.get(t),r=this.client.core.eventClient.getEvent({topic:e.pairingTopic});r?.setError("proposal_expired")}catch{}await Promise.all([this.client.proposal.delete(t,oc("USER_DISCONNECTED")),e?Promise.resolve():this.client.core.expirer.del(t)]),this.addToRecentlyDeleted(t,"proposal")},this.deletePendingSessionRequest=async(t,e,r=!1)=>{await Promise.all([this.client.pendingRequest.delete(t,e),r?Promise.resolve():this.client.core.expirer.del(t)]),this.addToRecentlyDeleted(t,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter((e=>e.id!==t)),r&&(this.sessionRequestQueue.state=Zm,this.client.events.emit("session_request_expire",{id:t}))},this.deletePendingAuthRequest=async(t,e,r=!1)=>{await Promise.all([this.client.auth.requests.delete(t,e),r?Promise.resolve():this.client.core.expirer.del(t)])},this.setExpiry=async(t,e)=>{this.client.session.keys.includes(t)&&(this.client.core.expirer.set(t,e),await this.client.session.update(t,{expiry:e}))},this.setProposal=async(t,e)=>{this.client.core.expirer.set(t,Mi(Qm.wc_sessionPropose.req.ttl)),await this.client.proposal.set(t,e)},this.setAuthRequest=async(t,e)=>{const{request:r,pairingTopic:i,transportType:n=Qu.relay}=e;this.client.core.expirer.set(t,r.expiryTimestamp),await this.client.auth.requests.set(t,{authPayload:r.authPayload,requester:r.requester,expiryTimestamp:r.expiryTimestamp,id:t,pairingTopic:i,verifyContext:r.verifyContext,transportType:n})},this.setPendingSessionRequest=async t=>{const{id:e,topic:r,params:i,verifyContext:n}=t,s=i.request.expiryTimestamp||Mi(Qm.wc_sessionRequest.req.ttl);this.client.core.expirer.set(e,s),await this.client.pendingRequest.set(e,{id:e,topic:r,params:i,verifyContext:n})},this.sendRequest=async t=>{const{topic:e,method:i,params:n,expiry:s,relayRpcId:o,clientRpcId:a,throwOnFailedPublish:h,appLink:c}=t,f=Vc(i,n,a);let u;const d=!!c;try{const t=d?bh:mh;u=await this.client.core.crypto.encode(e,f,{encoding:t})}catch(t){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${e} failed`),t}let l;if(eb.includes(i)){const t=_h(JSON.stringify(f)),e=_h(u);l=await this.client.core.verify.register({id:e,decryptedId:t})}const p=Qm[i].req;if(p.attestation=l,s&&(p.ttl=s),o&&(p.id=o),this.client.core.history.set(e,f),d){const t=Fh(c,e,u);await r.g.Linking.openURL(t,this.client.name)}else{const t=Qm[i].req;s&&(t.ttl=s),o&&(t.id=o),h?(t.internal=db(ub({},t.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(e,u,t)):this.client.core.relayer.publish(e,u,t).catch((t=>this.client.logger.error(t)))}return f.id},this.sendResult=async t=>{const{id:e,topic:i,result:n,throwOnFailedPublish:s,encodeOpts:o,appLink:a}=t,h=Hc(e,n);let c;const f=a&&typeof(null==r.g?void 0:r.g.Linking)<"u";try{const t=f?bh:mh;c=await this.client.core.crypto.encode(i,h,db(ub({},o||{}),{encoding:t}))}catch(t){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${i} failed`),t}let u;try{u=await this.client.core.history.get(i,e)}catch(t){throw this.client.logger.error(`sendResult() -> history.get(${i}, ${e}) failed`),t}if(f){const t=Fh(a,i,c);await r.g.Linking.openURL(t,this.client.name)}else{const t=Qm[u.request.method].res;s?(t.internal=db(ub({},t.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,c,t)):this.client.core.relayer.publish(i,c,t).catch((t=>this.client.logger.error(t)))}await this.client.core.history.resolve(h)},this.sendError=async t=>{const{id:e,topic:i,error:n,encodeOpts:s,rpcOpts:o,appLink:a}=t,h=Wc(e,n);let c;const f=a&&typeof(null==r.g?void 0:r.g.Linking)<"u";try{const t=f?bh:mh;c=await this.client.core.crypto.encode(i,h,db(ub({},s||{}),{encoding:t}))}catch(t){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${i} failed`),t}let u;try{u=await this.client.core.history.get(i,e)}catch(t){throw this.client.logger.error(`sendError() -> history.get(${i}, ${e}) failed`),t}if(f){const t=Fh(a,i,c);await r.g.Linking.openURL(t,this.client.name)}else{const t=o||Qm[u.request.method].res;this.client.core.relayer.publish(i,c,t)}await this.client.core.history.resolve(h)},this.cleanup=async()=>{const t=[],e=[];this.client.session.getAll().forEach((e=>{let r=!1;Si(e.expiry)&&(r=!0),this.client.core.crypto.keychain.has(e.topic)||(r=!0),r&&t.push(e.topic)})),this.client.proposal.getAll().forEach((t=>{Si(t.expiryTimestamp)&&e.push(t.id)})),await Promise.all([...t.map((t=>this.deleteSession({topic:t}))),...e.map((t=>this.deleteProposal(t)))])},this.onRelayEventRequest=async t=>{this.requestQueue.queue.push(t),await this.processRequestsQueue()},this.processRequestsQueue=async()=>{if(this.requestQueue.state!==tb){for(this.client.logger.info(`Request queue starting with ${this.requestQueue.queue.length} requests`);this.requestQueue.queue.length>0;){this.requestQueue.state=tb;const t=this.requestQueue.queue.shift();if(t)try{await this.processRequest(t)}catch(t){this.client.logger.warn(t)}}this.requestQueue.state=Zm}else this.client.logger.info("Request queue already active, skipping...")},this.processRequest=async t=>{const{topic:e,payload:r,attestation:i,transportType:n,encryptedId:s}=t,o=r.method;if(!this.shouldIgnorePairingRequest({topic:e,requestMethod:o}))switch(o){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:e,payload:r,attestation:i,encryptedId:s});case"wc_sessionSettle":return await this.onSessionSettleRequest(e,r);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(e,r);case"wc_sessionExtend":return await this.onSessionExtendRequest(e,r);case"wc_sessionPing":return await this.onSessionPingRequest(e,r);case"wc_sessionDelete":return await this.onSessionDeleteRequest(e,r);case"wc_sessionRequest":return await this.onSessionRequest({topic:e,payload:r,attestation:i,encryptedId:s,transportType:n});case"wc_sessionEvent":return await this.onSessionEventRequest(e,r);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:e,payload:r,attestation:i,encryptedId:s,transportType:n});default:return this.client.logger.info(`Unsupported request method ${o}`)}},this.onRelayEventResponse=async t=>{const{topic:e,payload:r,transportType:i}=t,n=(await this.client.core.history.get(e,r.id)).request.method;switch(n){case"wc_sessionPropose":return this.onSessionProposeResponse(e,r,i);case"wc_sessionSettle":return this.onSessionSettleResponse(e,r);case"wc_sessionUpdate":return this.onSessionUpdateResponse(e,r);case"wc_sessionExtend":return this.onSessionExtendResponse(e,r);case"wc_sessionPing":return this.onSessionPingResponse(e,r);case"wc_sessionRequest":return this.onSessionRequestResponse(e,r);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(e,r);default:return this.client.logger.info(`Unsupported response method ${n}`)}},this.onRelayEventUnknownPayload=t=>{const{topic:e}=t,{message:r}=sc("MISSING_OR_INVALID",`Decoded payload on topic ${e} is not identifiable as a JSON-RPC request or a response.`);throw new Error(r)},this.shouldIgnorePairingRequest=t=>{const{topic:e,requestMethod:r}=t,i=this.expectedPairingMethodMap.get(e);return!(!i||i.includes(r)||!(i.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0))},this.onSessionProposeRequest=async t=>{const{topic:e,payload:r,attestation:i,encryptedId:n}=t,{params:s,id:o}=r;try{const t=this.client.core.eventClient.getEvent({topic:e});this.isValidConnect(ub({},r.params));const a=s.expiryTimestamp||Mi(Qm.wc_sessionPropose.req.ttl),h=ub({id:o,pairingTopic:e,expiryTimestamp:a},s);await this.setProposal(o,h);const c=await this.getVerifyContext({attestationId:i,hash:_h(JSON.stringify(r)),encryptedId:n,metadata:h.proposer.metadata});0===this.client.events.listenerCount("session_proposal")&&(console.warn("No listener for session_proposal event"),t?.setError("proposal_listener_not_found")),t?.addTrace("emit_session_proposal"),this.client.events.emit("session_proposal",{id:o,params:h,verifyContext:c})}catch(t){await this.sendError({id:o,topic:e,error:t,rpcOpts:Qm.wc_sessionPropose.autoReject}),this.client.logger.error(t)}},this.onSessionProposeResponse=async(t,e,r)=>{const{id:i}=e;if(ef(e)){const{result:n}=e;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:n});const s=this.client.proposal.get(i);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:s});const o=s.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:o});const a=n.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:a});const h=await this.client.core.crypto.generateSharedKey(o,a);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",sessionTopic:h});const c=await this.client.core.relayer.subscribe(h,{transportType:r});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:c}),await this.client.core.pairing.activate({topic:t})}else if(rf(e)){await this.client.proposal.delete(i,oc("USER_DISCONNECTED"));const t=Ei("session_connect");if(0===this.events.listenerCount(t))throw new Error(`emitting ${t} without any listeners, 954`);this.events.emit(Ei("session_connect"),{error:e.error})}},this.onSessionSettleRequest=async(t,e)=>{const{id:r,params:i}=e;try{this.isValidSessionSettleRequest(i);const{relay:r,controller:n,expiry:s,namespaces:o,sessionProperties:a,sessionConfig:h}=e.params,c=db(ub(ub({topic:t,relay:r,expiry:s,namespaces:o,acknowledged:!0,pairingTopic:"",requiredNamespaces:{},optionalNamespaces:{},controller:n.publicKey,self:{publicKey:"",metadata:this.client.metadata},peer:{publicKey:n.publicKey,metadata:n.metadata}},a&&{sessionProperties:a}),h&&{sessionConfig:h}),{transportType:Qu.relay}),f=Ei("session_connect");if(0===this.events.listenerCount(f))throw new Error(`emitting ${f} without any listeners 997`);this.events.emit(Ei("session_connect"),{session:c}),await this.sendResult({id:e.id,topic:t,result:!0,throwOnFailedPublish:!0})}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionSettleResponse=async(t,e)=>{const{id:r}=e;ef(e)?(await this.client.session.update(t,{acknowledged:!0}),this.events.emit(Ei("session_approve",r),{})):rf(e)&&(await this.client.session.delete(t,oc("USER_DISCONNECTED")),this.events.emit(Ei("session_approve",r),{error:e.error}))},this.onSessionUpdateRequest=async(t,e)=>{const{params:r,id:i}=e;try{const e=`${t}_session_update`,n=Ic.get(e);if(n&&this.isRequestOutOfSync(n,i))return this.client.logger.info(`Discarding out of sync request - ${i}`),void this.sendError({id:i,topic:t,error:oc("INVALID_UPDATE_REQUEST")});this.isValidUpdate(ub({topic:t},r));try{Ic.set(e,i),await this.client.session.update(t,{namespaces:r.namespaces}),await this.sendResult({id:i,topic:t,result:!0,throwOnFailedPublish:!0})}catch(t){throw Ic.delete(e),t}this.client.events.emit("session_update",{id:i,topic:t,params:r})}catch(e){await this.sendError({id:i,topic:t,error:e}),this.client.logger.error(e)}},this.isRequestOutOfSync=(t,e)=>parseInt(e.toString().slice(0,-3))<=parseInt(t.toString().slice(0,-3)),this.onSessionUpdateResponse=(t,e)=>{const{id:r}=e,i=Ei("session_update",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);ef(e)?this.events.emit(Ei("session_update",r),{}):rf(e)&&this.events.emit(Ei("session_update",r),{error:e.error})},this.onSessionExtendRequest=async(t,e)=>{const{id:r}=e;try{this.isValidExtend({topic:t}),await this.setExpiry(t,Mi(Ym)),await this.sendResult({id:r,topic:t,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_extend",{id:r,topic:t})}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionExtendResponse=(t,e)=>{const{id:r}=e,i=Ei("session_extend",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);ef(e)?this.events.emit(Ei("session_extend",r),{}):rf(e)&&this.events.emit(Ei("session_extend",r),{error:e.error})},this.onSessionPingRequest=async(t,e)=>{const{id:r}=e;try{this.isValidPing({topic:t}),await this.sendResult({id:r,topic:t,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:r,topic:t})}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionPingResponse=(t,e)=>{const{id:r}=e,i=Ei("session_ping",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);setTimeout((()=>{ef(e)?this.events.emit(Ei("session_ping",r),{}):rf(e)&&this.events.emit(Ei("session_ping",r),{error:e.error})}),500)},this.onSessionDeleteRequest=async(t,e)=>{const{id:r}=e;try{this.isValidDisconnect({topic:t,reason:e.params}),Promise.all([new Promise((e=>{this.client.core.relayer.once(Hu,(async()=>{e(await this.deleteSession({topic:t,id:r}))}))})),this.sendResult({id:r,topic:t,result:!0,throwOnFailedPublish:!0}),this.cleanupPendingSentRequestsForTopic({topic:t,error:oc("USER_DISCONNECTED")})]).catch((t=>this.client.logger.error(t)))}catch(t){this.client.logger.error(t)}},this.onSessionRequest=async t=>{var e,r,i;const{topic:n,payload:s,attestation:o,encryptedId:a,transportType:h}=t,{id:c,params:f}=s;try{await this.isValidRequest(ub({topic:n},f));const t=this.client.session.get(n),s={id:c,topic:n,params:f,verifyContext:await this.getVerifyContext({attestationId:o,hash:_h(JSON.stringify(Vc("wc_sessionRequest",f,c))),encryptedId:a,metadata:t.peer.metadata,transportType:h})};await this.setPendingSessionRequest(s),h===Qu.link_mode&&null!=(e=t.peer.metadata.redirect)&&e.universal&&this.client.core.addLinkModeSupportedApp(null==(r=t.peer.metadata.redirect)?void 0:r.universal),null!=(i=this.client.signConfig)&&i.disableRequestQueue?this.emitSessionRequest(s):(this.addSessionRequestToSessionRequestQueue(s),this.processSessionRequestQueue())}catch(t){await this.sendError({id:c,topic:n,error:t}),this.client.logger.error(t)}},this.onSessionRequestResponse=(t,e)=>{const{id:r}=e,i=Ei("session_request",r);if(0===this.events.listenerCount(i))throw new Error(`emitting ${i} without any listeners`);ef(e)?this.events.emit(Ei("session_request",r),{result:e.result}):rf(e)&&this.events.emit(Ei("session_request",r),{error:e.error})},this.onSessionEventRequest=async(t,e)=>{const{id:r,params:i}=e;try{const e=`${t}_session_event_${i.event.name}`,n=Ic.get(e);if(n&&this.isRequestOutOfSync(n,r))return void this.client.logger.info(`Discarding out of sync request - ${r}`);this.isValidEmit(ub({topic:t},i)),this.client.events.emit("session_event",{id:r,topic:t,params:i}),Ic.set(e,r)}catch(e){await this.sendError({id:r,topic:t,error:e}),this.client.logger.error(e)}},this.onSessionAuthenticateResponse=(t,e)=>{const{id:r}=e;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:t,payload:e}),ef(e)?this.events.emit(Ei("session_request",r),{result:e.result}):rf(e)&&this.events.emit(Ei("session_request",r),{error:e.error})},this.onSessionAuthenticateRequest=async t=>{var e;const{topic:r,payload:i,attestation:n,encryptedId:s,transportType:o}=t;try{const{requester:t,authPayload:a,expiryTimestamp:h}=i.params,c=await this.getVerifyContext({attestationId:n,hash:_h(JSON.stringify(i)),encryptedId:s,metadata:t.metadata,transportType:o}),f={requester:t,pairingTopic:r,id:i.id,authPayload:a,verifyContext:c,expiryTimestamp:h};await this.setAuthRequest(i.id,{request:f,pairingTopic:r,transportType:o}),o===Qu.link_mode&&null!=(e=t.metadata.redirect)&&e.universal&&this.client.core.addLinkModeSupportedApp(t.metadata.redirect.universal),this.client.events.emit("session_authenticate",{topic:r,params:i.params,id:i.id,verifyContext:c})}catch(t){this.client.logger.error(t);const e=i.params.requester.publicKey,n=await this.client.core.crypto.generateKeyPair(),s=this.getAppLinkIfEnabled(i.params.requester.metadata,o),a={type:1,receiverPublicKey:e,senderPublicKey:n};await this.sendError({id:i.id,topic:r,error:t,encodeOpts:a,rpcOpts:Qm.wc_sessionAuthenticate.autoReject,appLink:s})}},this.addSessionRequestToSessionRequestQueue=t=>{this.sessionRequestQueue.queue.push(t)},this.cleanupAfterResponse=t=>{this.deletePendingSessionRequest(t.response.id,{message:"fulfilled",code:0}),setTimeout((()=>{this.sessionRequestQueue.state=Zm,this.processSessionRequestQueue()}),(0,Y.toMiliseconds)(this.requestQueueDelay))},this.cleanupPendingSentRequestsForTopic=({topic:t,error:e})=>{const r=this.client.core.history.pending;r.length>0&&r.filter((e=>e.topic===t&&"wc_sessionRequest"===e.request.method)).forEach((t=>{const r=Ei("session_request",t.request.id);if(0===this.events.listenerCount(r))throw new Error(`emitting ${r} without any listeners`);this.events.emit(Ei("session_request",t.request.id),{error:e})}))},this.processSessionRequestQueue=()=>{if(this.sessionRequestQueue.state===tb)return void this.client.logger.info("session request queue is already active.");const t=this.sessionRequestQueue.queue[0];if(t)try{this.sessionRequestQueue.state=tb,this.emitSessionRequest(t)}catch(t){this.client.logger.error(t)}else this.client.logger.info("session request queue is empty.")},this.emitSessionRequest=t=>{this.client.events.emit("session_request",t)},this.onPairingCreated=t=>{if(t.methods&&this.expectedPairingMethodMap.set(t.topic,t.methods),t.active)return;const e=this.client.proposal.getAll().find((e=>e.pairingTopic===t.topic));e&&this.onSessionProposeRequest({topic:t.topic,payload:Vc("wc_sessionPropose",{requiredNamespaces:e.requiredNamespaces,optionalNamespaces:e.optionalNamespaces,relays:e.relays,proposer:e.proposer,sessionProperties:e.sessionProperties},e.id)})},this.isValidConnect=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(t)}`);throw new Error(e)}const{pairingTopic:e,requiredNamespaces:r,optionalNamespaces:i,sessionProperties:n,relays:s}=t;if(cc(e)||await this.isValidPairingTopic(e),!function(t,e){let r=!1;return t?t&&ac(t)&&t.length&&t.forEach((t=>{r=bc(t)})):r=!0,r}(s)){const{message:t}=sc("MISSING_OR_INVALID",`connect() relays: ${s}`);throw new Error(t)}!cc(r)&&0!==hc(r)&&this.validateNamespaces(r,"requiredNamespaces"),!cc(i)&&0!==hc(i)&&this.validateNamespaces(i,"optionalNamespaces"),cc(n)||this.validateSessionProps(n,"sessionProperties")},this.validateNamespaces=(t,e)=>{const r=function(t,e,r){let i=null;if(t&&hc(t)){const n=gc(t,e);n&&(i=n);const s=function(t,e,r){let i=null;return Object.entries(t).forEach((([t,n])=>{if(i)return;const s=function(t,e,r){let i=null;return ac(e)&&e.length?e.forEach((t=>{i||dc(t)||(i=oc("UNSUPPORTED_CHAINS",`${r}, chain ${t} should be a string and conform to "namespace:chainId" format`))})):dc(t)||(i=oc("UNSUPPORTED_CHAINS",`${r}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),i}(t,ei(t,n),`${e} ${r}`);s&&(i=s)})),i}(t,e,r);s&&(i=s)}else i=sc("MISSING_OR_INVALID",`${e}, ${r} should be an object with data`);return i}(t,"connect()",e);if(r)throw new Error(r.message)},this.isValidApprove=async t=>{if(!yc(t))throw new Error(sc("MISSING_OR_INVALID",`approve() params: ${t}`).message);const{id:e,namespaces:r,relayProtocol:i,sessionProperties:n}=t;this.checkRecentlyDeleted(e),await this.isValidProposalId(e);const s=this.client.proposal.get(e),o=mc(r,"approve()");if(o)throw new Error(o.message);const a=_c(s.requiredNamespaces,r,"approve()");if(a)throw new Error(a.message);if(!fc(i,!0)){const{message:t}=sc("MISSING_OR_INVALID",`approve() relayProtocol: ${i}`);throw new Error(t)}cc(n)||this.validateSessionProps(n,"sessionProperties")},this.isValidReject=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`reject() params: ${t}`);throw new Error(e)}const{id:e,reason:r}=t;if(this.checkRecentlyDeleted(e),await this.isValidProposalId(e),!function(t){return!!(t&&"object"==typeof t&&t.code&&uc(t.code,!1)&&t.message&&fc(t.message,!1))}(r)){const{message:t}=sc("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(r)}`);throw new Error(t)}},this.isValidSessionSettleRequest=t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${t}`);throw new Error(e)}const{relay:e,controller:r,namespaces:i,expiry:n}=t;if(!bc(e)){const{message:t}=sc("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(t)}const s=function(t,e){let r=null;return fc(t?.publicKey,!1)||(r=sc("MISSING_OR_INVALID","onSessionSettleRequest() controller public key should be a string")),r}(r);if(s)throw new Error(s.message);const o=mc(i,"onSessionSettleRequest()");if(o)throw new Error(o.message);if(Si(n)){const{message:t}=sc("EXPIRED","onSessionSettleRequest()");throw new Error(t)}},this.isValidUpdate=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`update() params: ${t}`);throw new Error(e)}const{topic:e,namespaces:r}=t;this.checkRecentlyDeleted(e),await this.isValidSessionTopic(e);const i=this.client.session.get(e),n=mc(r,"update()");if(n)throw new Error(n.message);const s=_c(i.requiredNamespaces,r,"update()");if(s)throw new Error(s.message)},this.isValidExtend=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`extend() params: ${t}`);throw new Error(e)}const{topic:e}=t;this.checkRecentlyDeleted(e),await this.isValidSessionTopic(e)},this.isValidRequest=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`request() params: ${t}`);throw new Error(e)}const{topic:e,request:r,chainId:i,expiry:n}=t;this.checkRecentlyDeleted(e),await this.isValidSessionTopic(e);const{namespaces:s}=this.client.session.get(e);if(!vc(s,i)){const{message:t}=sc("MISSING_OR_INVALID",`request() chainId: ${i}`);throw new Error(t)}if(!function(t){return!(cc(t)||!fc(t.method,!1))}(r)){const{message:t}=sc("MISSING_OR_INVALID",`request() ${JSON.stringify(r)}`);throw new Error(t)}if(!function(t,e,r){return!!fc(r,!1)&&function(t,e){const r=[];return Object.values(t).forEach((t=>{Xh(t.accounts).includes(e)&&r.push(...t.methods)})),r}(t,e).includes(r)}(s,i,r.method)){const{message:t}=sc("MISSING_OR_INVALID",`request() method: ${r.method}`);throw new Error(t)}if(n&&!Mc(n,Xm)){const{message:t}=sc("MISSING_OR_INVALID",`request() expiry: ${n}. Expiry must be a number (in seconds) between ${Xm.min} and ${Xm.max}`);throw new Error(t)}},this.isValidRespond=async t=>{var e;if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`respond() params: ${t}`);throw new Error(e)}const{topic:r,response:i}=t;try{await this.isValidSessionTopic(r)}catch(r){throw null!=(e=t?.response)&&e.id&&this.cleanupAfterResponse(t),r}if(!function(t){return!(cc(t)||cc(t.result)&&cc(t.error)||!uc(t.id,!1)||!fc(t.jsonrpc,!1))}(i)){const{message:t}=sc("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(i)}`);throw new Error(t)}},this.isValidPing=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`ping() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidSessionOrPairingTopic(e)},this.isValidEmit=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`emit() params: ${t}`);throw new Error(e)}const{topic:e,event:r,chainId:i}=t;await this.isValidSessionTopic(e);const{namespaces:n}=this.client.session.get(e);if(!vc(n,i)){const{message:t}=sc("MISSING_OR_INVALID",`emit() chainId: ${i}`);throw new Error(t)}if(!function(t){return!(cc(t)||!fc(t.name,!1))}(r)){const{message:t}=sc("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(r)}`);throw new Error(t)}if(!function(t,e,r){return!!fc(r,!1)&&function(t,e){const r=[];return Object.values(t).forEach((t=>{Xh(t.accounts).includes(e)&&r.push(...t.events)})),r}(t,e).includes(r)}(n,i,r.name)){const{message:t}=sc("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(r)}`);throw new Error(t)}},this.isValidDisconnect=async t=>{if(!yc(t)){const{message:e}=sc("MISSING_OR_INVALID",`disconnect() params: ${t}`);throw new Error(e)}const{topic:e}=t;await this.isValidSessionOrPairingTopic(e)},this.isValidAuthenticate=t=>{const{chains:e,uri:r,domain:i,nonce:n}=t;if(!Array.isArray(e)||0===e.length)throw new Error("chains is required and must be a non-empty array");if(!fc(r,!1))throw new Error("uri is required parameter");if(!fc(i,!1))throw new Error("domain is required parameter");if(!fc(n,!1))throw new Error("nonce is required parameter");if([...new Set(e.map((t=>ti(t).namespace)))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:s}=ti(e[0]);if("eip155"!==s)throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")},this.getVerifyContext=async t=>{const{attestationId:e,hash:r,encryptedId:i,metadata:n,transportType:s}=t,o={verified:{verifyUrl:n.verifyUrl||dd,validation:"UNKNOWN",origin:n.url||""}};try{if(s===Qu.link_mode){const t=this.getAppLinkIfEnabled(n,s);return o.verified.validation=t&&new URL(t).origin===new URL(n.url).origin?"VALID":"INVALID",o}const t=await this.client.core.verify.resolve({attestationId:e,hash:r,encryptedId:i,verifyUrl:n.verifyUrl});t&&(o.verified.origin=t.origin,o.verified.isScam=t.isScam,o.verified.validation=t.origin===new URL(n.url).origin?"VALID":"INVALID")}catch(t){this.client.logger.warn(t)}return this.client.logger.debug(`Verify context: ${JSON.stringify(o)}`),o},this.validateSessionProps=(t,e)=>{Object.values(t).forEach((t=>{if(!fc(t,!1)){const{message:r}=sc("MISSING_OR_INVALID",`${e} must be in Record format. Received: ${JSON.stringify(t)}`);throw new Error(r)}}))},this.getPendingAuthRequest=t=>{const e=this.client.auth.requests.get(t);return"object"==typeof e?e:void 0},this.addToRecentlyDeleted=(t,e)=>{if(this.recentlyDeletedMap.set(t,e),this.recentlyDeletedMap.size>=this.recentlyDeletedLimit){let t=0;const e=this.recentlyDeletedLimit/2;for(const r of this.recentlyDeletedMap.keys()){if(t++>=e)break;this.recentlyDeletedMap.delete(r)}}},this.checkRecentlyDeleted=t=>{const e=this.recentlyDeletedMap.get(t);if(e){const{message:r}=sc("MISSING_OR_INVALID",`Record was recently deleted - ${e}: ${t}`);throw new Error(r)}},this.isLinkModeEnabled=(t,e)=>{var i,n,s,o,a,h,c,f,u;return!(!t||e!==Qu.link_mode)&&!0===(null==(n=null==(i=this.client.metadata)?void 0:i.redirect)?void 0:n.linkMode)&&void 0!==(null==(o=null==(s=this.client.metadata)?void 0:s.redirect)?void 0:o.universal)&&""!==(null==(h=null==(a=this.client.metadata)?void 0:a.redirect)?void 0:h.universal)&&void 0!==(null==(c=t?.redirect)?void 0:c.universal)&&""!==(null==(f=t?.redirect)?void 0:f.universal)&&!0===(null==(u=t?.redirect)?void 0:u.linkMode)&&this.client.core.linkModeSupportedApps.includes(t.redirect.universal)&&typeof(null==r.g?void 0:r.g.Linking)<"u"},this.getAppLinkIfEnabled=(t,e)=>{var r;return this.isLinkModeEnabled(t,e)?null==(r=t?.redirect)?void 0:r.universal:void 0},this.handleLinkModeMessage=({url:t})=>{if(!t||!t.includes("wc_ev")||!t.includes("topic"))return;const e=xi(t,"topic")||"",r=decodeURIComponent(xi(t,"wc_ev")||""),i=this.client.session.keys.includes(e);i&&this.client.session.update(e,{transportType:Qu.link_mode}),this.client.core.dispatchEnvelope({topic:e,message:r,sessionExists:i})},this.registerLinkModeListeners=async()=>{var t;if(typeof process<"u"&&process.env.IS_VITEST||di()&&null!=(t=this.client.metadata.redirect)&&t.linkMode){const t=null==r.g?void 0:r.g.Linking;if(typeof t<"u"){t.addEventListener("url",this.handleLinkModeMessage,this.client.name);const e=await t.getInitialURL();e&&setTimeout((()=>{this.handleLinkModeMessage({url:e})}),50)}}}}isInitialized(){if(!this.initialized){const{message:t}=sc("NOT_INITIALIZED",this.name);throw new Error(t)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Fu,(t=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(t):this.onRelayMessage(t)}))}async onRelayMessage(t){const{topic:e,message:r,attestation:i,transportType:n}=t,{publicKey:s}=this.client.auth.authKeys.keys.includes(ib)?this.client.auth.authKeys.get(ib):{responseTopic:void 0,publicKey:void 0},o=await this.client.core.crypto.decode(e,r,{receiverPublicKey:s,encoding:n===Qu.link_mode?bh:mh});try{Zc(o)?(this.client.core.history.set(e,o),this.onRelayEventRequest({topic:e,payload:o,attestation:i,transportType:n,encryptedId:_h(r)})):tf(o)?(await this.client.core.history.resolve(o),await this.onRelayEventResponse({topic:e,payload:o,transportType:n}),this.client.core.history.delete(e,o.id)):this.onRelayEventUnknownPayload({topic:e,payload:o,transportType:n})}catch(t){this.client.logger.error(t)}}registerExpirerEvents(){this.client.core.expirer.on(fd,(async t=>{const{topic:e,id:r}=Ai(t.target);return r&&this.client.pendingRequest.keys.includes(r)?await this.deletePendingSessionRequest(r,sc("EXPIRED"),!0):r&&this.client.auth.requests.keys.includes(r)?await this.deletePendingAuthRequest(r,sc("EXPIRED"),!0):void(e?this.client.session.keys.includes(e)&&(await this.deleteSession({topic:e,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:e})):r&&(await this.deleteProposal(r,!0),this.client.events.emit("proposal_expire",{id:r})))}))}registerPairingEvents(){this.client.core.pairing.events.on(id,(t=>this.onPairingCreated(t))),this.client.core.pairing.events.on(nd,(t=>{this.addToRecentlyDeleted(t.topic,"pairing")}))}isValidPairingTopic(t){if(!fc(t,!1)){const{message:e}=sc("MISSING_OR_INVALID",`pairing topic should be a string: ${t}`);throw new Error(e)}if(!this.client.core.pairing.pairings.keys.includes(t)){const{message:e}=sc("NO_MATCHING_KEY",`pairing topic doesn't exist: ${t}`);throw new Error(e)}if(Si(this.client.core.pairing.pairings.get(t).expiry)){const{message:e}=sc("EXPIRED",`pairing topic: ${t}`);throw new Error(e)}}async isValidSessionTopic(t){if(!fc(t,!1)){const{message:e}=sc("MISSING_OR_INVALID",`session topic should be a string: ${t}`);throw new Error(e)}if(this.checkRecentlyDeleted(t),!this.client.session.keys.includes(t)){const{message:e}=sc("NO_MATCHING_KEY",`session topic doesn't exist: ${t}`);throw new Error(e)}if(Si(this.client.session.get(t).expiry)){await this.deleteSession({topic:t});const{message:e}=sc("EXPIRED",`session topic: ${t}`);throw new Error(e)}if(!this.client.core.crypto.keychain.has(t)){const{message:e}=sc("MISSING_OR_INVALID",`session topic does not exist in keychain: ${t}`);throw await this.deleteSession({topic:t}),new Error(e)}}async isValidSessionOrPairingTopic(t){if(this.checkRecentlyDeleted(t),this.client.session.keys.includes(t))await this.isValidSessionTopic(t);else{if(!this.client.core.pairing.pairings.keys.includes(t)){if(fc(t,!1)){const{message:e}=sc("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${t}`);throw new Error(e)}{const{message:e}=sc("MISSING_OR_INVALID",`session or pairing topic should be a string: ${t}`);throw new Error(e)}}this.isValidPairingTopic(t)}}async isValidProposalId(t){if(!function(t){return"number"==typeof t}(t)){const{message:e}=sc("MISSING_OR_INVALID",`proposal id should be a number: ${t}`);throw new Error(e)}if(!this.client.proposal.keys.includes(t)){const{message:e}=sc("NO_MATCHING_KEY",`proposal id doesn't exist: ${t}`);throw new Error(e)}if(Si(this.client.proposal.get(t).expiryTimestamp)){await this.deleteProposal(t);const{message:e}=sc("EXPIRED",`proposal id: ${t}`);throw new Error(e)}}}class pb extends Vd{constructor(t,e){super(t,e,"proposal",Jm),this.core=t,this.logger=e}}class gb extends Vd{constructor(t,e){super(t,e,"session",Jm),this.core=t,this.logger=e}}class mb extends Vd{constructor(t,e){super(t,e,"request",Jm,(t=>t.id)),this.core=t,this.logger=e}}class bb extends Vd{constructor(t,e){super(t,e,"authKeys",rb,(()=>ib)),this.core=t,this.logger=e}}class yb extends Vd{constructor(t,e){super(t,e,"pairingTopics",rb),this.core=t,this.logger=e}}class vb extends Vd{constructor(t,e){super(t,e,"requests",rb,(t=>t.id)),this.core=t,this.logger=e}}class wb{constructor(t,e){this.core=t,this.logger=e,this.authKeys=new bb(this.core,this.logger),this.pairingTopics=new yb(this.core,this.logger),this.requests=new vb(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}class _b extends kt{constructor(t){super(t),this.protocol="wc",this.version=2,this.name=Gm,this.events=new b.EventEmitter,this.on=(t,e)=>this.events.on(t,e),this.once=(t,e)=>this.events.once(t,e),this.off=(t,e)=>this.events.off(t,e),this.removeListener=(t,e)=>this.events.removeListener(t,e),this.removeAllListeners=t=>this.events.removeAllListeners(t),this.connect=async t=>{try{return await this.engine.connect(t)}catch(t){throw this.logger.error(t.message),t}},this.pair=async t=>{try{return await this.engine.pair(t)}catch(t){throw this.logger.error(t.message),t}},this.approve=async t=>{try{return await this.engine.approve(t)}catch(t){throw this.logger.error(t.message),t}},this.reject=async t=>{try{return await this.engine.reject(t)}catch(t){throw this.logger.error(t.message),t}},this.update=async t=>{try{return await this.engine.update(t)}catch(t){throw this.logger.error(t.message),t}},this.extend=async t=>{try{return await this.engine.extend(t)}catch(t){throw this.logger.error(t.message),t}},this.request=async t=>{try{return await this.engine.request(t)}catch(t){throw this.logger.error(t.message),t}},this.respond=async t=>{try{return await this.engine.respond(t)}catch(t){throw this.logger.error(t.message),t}},this.ping=async t=>{try{return await this.engine.ping(t)}catch(t){throw this.logger.error(t.message),t}},this.emit=async t=>{try{return await this.engine.emit(t)}catch(t){throw this.logger.error(t.message),t}},this.disconnect=async t=>{try{return await this.engine.disconnect(t)}catch(t){throw this.logger.error(t.message),t}},this.find=t=>{try{return this.engine.find(t)}catch(t){throw this.logger.error(t.message),t}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(t){throw this.logger.error(t.message),t}},this.authenticate=async(t,e)=>{try{return await this.engine.authenticate(t,e)}catch(t){throw this.logger.error(t.message),t}},this.formatAuthMessage=t=>{try{return this.engine.formatAuthMessage(t)}catch(t){throw this.logger.error(t.message),t}},this.approveSessionAuthenticate=async t=>{try{return await this.engine.approveSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.rejectSessionAuthenticate=async t=>{try{return await this.engine.rejectSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.name=t?.name||Gm,this.metadata=t?.metadata||(0,Br.g)()||{name:"",description:"",url:"",icons:[""]},this.signConfig=t?.signConfig;const e=typeof t?.logger<"u"&&"string"!=typeof t?.logger?t.logger:it()(vt({level:t?.logger||"error"}));this.core=t?.core||new pl(t),this.logger=_t(e,this.name),this.session=new gb(this.core,this.logger),this.proposal=new pb(this.core,this.logger),this.pendingRequest=new mb(this.core,this.logger),this.engine=new lb(this),this.auth=new wb(this.core,this.logger)}static async init(t){const e=new _b(t);return await e.initialize(),e}get context(){return wt(this.logger)}get pairing(){return this.core.pairing.pairings}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.session.init(),await this.proposal.init(),await this.pendingRequest.init(),await this.auth.init(),await this.engine.init(),this.logger.info("SignClient Initialization Success"),this.engine.processRelayMessageCache()}catch(t){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(t.message),t}}}const Ab=gb,Mb=_b;var Sb,Eb={exports:{}},Ib="object"==typeof Reflect?Reflect:null,xb=Ib&&"function"==typeof Ib.apply?Ib.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};Sb=Ib&&"function"==typeof Ib.ownKeys?Ib.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var Ob=Number.isNaN||function(t){return t!=t};function Nb(){Nb.init.call(this)}Eb.exports=Nb,Eb.exports.once=function(t,e){return new Promise((function(r,i){function n(r){t.removeListener(e,s),i(r)}function s(){"function"==typeof t.removeListener&&t.removeListener("error",n),r([].slice.call(arguments))}Db(t,e,s,{once:!0}),"error"!==e&&function(t,e,r){"function"==typeof t.on&&Db(t,"error",e,{once:!0})}(t,n)}))},Nb.EventEmitter=Nb,Nb.prototype._events=void 0,Nb.prototype._eventsCount=0,Nb.prototype._maxListeners=void 0;var Pb=10;function Rb(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function Tb(t){return void 0===t._maxListeners?Nb.defaultMaxListeners:t._maxListeners}function Cb(t,e,r,i){var n,s,o;if(Rb(r),void 0===(s=t._events)?(s=t._events=Object.create(null),t._eventsCount=0):(void 0!==s.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),o=s[e]),void 0===o)o=s[e]=r,++t._eventsCount;else if("function"==typeof o?o=s[e]=i?[r,o]:[o,r]:i?o.unshift(r):o.push(r),(n=Tb(t))>0&&o.length>n&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=o.length,function(t){console&&console.warn&&console.warn(t)}(a)}return t}function kb(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Lb(t,e,r){var i={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},n=kb.bind(i);return n.listener=r,i.wrapFn=n,n}function qb(t,e,r){var i=t._events;if(void 0===i)return[];var n=i[e];return void 0===n?[]:"function"==typeof n?r?[n.listener||n]:[n]:r?function(t){for(var e=new Array(t.length),r=0;r0&&(s=e[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var a=n[t];if(void 0===a)return!1;if("function"==typeof a)xb(a,this,e);else{var h=a.length,c=Bb(a,h);for(r=0;r=0;s--)if(r[s]===e||r[s].listener===e){o=r[s].listener,n=s;break}if(n<0)return this;0===n?r.shift():function(t,e){for(;e+1=0;i--)this.removeListener(t,e[i]);return this},Nb.prototype.listeners=function(t){return qb(this,t,!0)},Nb.prototype.rawListeners=function(t){return qb(this,t,!1)},Nb.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):Ub.call(t,e)},Nb.prototype.listenerCount=Ub,Nb.prototype.eventNames=function(){return this._eventsCount>0?Sb(this._events):[]};Eb.exports;class zb{constructor(t){this.opts=t}}class jb{constructor(t){this.client=t}}var Fb=Object.defineProperty,Kb=Object.defineProperties,Vb=Object.getOwnPropertyDescriptors,Hb=Object.getOwnPropertySymbols,Wb=Object.prototype.hasOwnProperty,Jb=Object.prototype.propertyIsEnumerable,Gb=(t,e,r)=>e in t?Fb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;class $b extends jb{constructor(t){super(t),this.init=async()=>{this.signClient=await Mb.init({core:this.client.core,metadata:this.client.metadata,signConfig:this.client.signConfig}),this.authClient=await Hm.init({core:this.client.core,projectId:"",metadata:this.client.metadata})},this.pair=async t=>{await this.client.core.pairing.pair(t)},this.approveSession=async t=>{const{topic:e,acknowledged:r}=await this.signClient.approve(((t,e)=>Kb(t,Vb(e)))(((t,e)=>{for(var r in e||(e={}))Wb.call(e,r)&&Gb(t,r,e[r]);if(Hb)for(var r of Hb(e))Jb.call(e,r)&&Gb(t,r,e[r]);return t})({},t),{id:t.id,namespaces:t.namespaces,sessionProperties:t.sessionProperties,sessionConfig:t.sessionConfig}));return await r(),this.signClient.session.get(e)},this.rejectSession=async t=>await this.signClient.reject(t),this.updateSession=async t=>await this.signClient.update(t),this.extendSession=async t=>await this.signClient.extend(t),this.respondSessionRequest=async t=>await this.signClient.respond(t),this.disconnectSession=async t=>await this.signClient.disconnect(t),this.emitSessionEvent=async t=>await this.signClient.emit(t),this.getActiveSessions=()=>this.signClient.session.getAll().reduce(((t,e)=>(t[e.topic]=e,t)),{}),this.getPendingSessionProposals=()=>this.signClient.proposal.getAll(),this.getPendingSessionRequests=()=>this.signClient.getPendingSessionRequests(),this.respondAuthRequest=async(t,e)=>await this.authClient.respond(t,e),this.getPendingAuthRequests=()=>this.authClient.requests.getAll().filter((t=>"requester"in t)),this.formatMessage=(t,e)=>this.authClient.formatMessage(t,e),this.approveSessionAuthenticate=async t=>await this.signClient.approveSessionAuthenticate(t),this.rejectSessionAuthenticate=async t=>await this.signClient.rejectSessionAuthenticate(t),this.formatAuthMessage=t=>this.signClient.formatAuthMessage(t),this.registerDeviceToken=t=>this.client.core.echoClient.registerDeviceToken(t),this.on=(t,e)=>(this.setEvent(t,"off"),this.setEvent(t,"on"),this.client.events.on(t,e)),this.once=(t,e)=>(this.setEvent(t,"off"),this.setEvent(t,"once"),this.client.events.once(t,e)),this.off=(t,e)=>(this.setEvent(t,"off"),this.client.events.off(t,e)),this.removeListener=(t,e)=>(this.setEvent(t,"removeListener"),this.client.events.removeListener(t,e)),this.onSessionRequest=t=>{this.client.events.emit("session_request",t)},this.onSessionProposal=t=>{this.client.events.emit("session_proposal",t)},this.onSessionDelete=t=>{this.client.events.emit("session_delete",t)},this.onAuthRequest=t=>{this.client.events.emit("auth_request",t)},this.onProposalExpire=t=>{this.client.events.emit("proposal_expire",t)},this.onSessionRequestExpire=t=>{this.client.events.emit("session_request_expire",t)},this.onSessionRequestAuthenticate=t=>{this.client.events.emit("session_authenticate",t)},this.setEvent=(t,e)=>{switch(t){case"session_request":this.signClient.events[e]("session_request",this.onSessionRequest);break;case"session_proposal":this.signClient.events[e]("session_proposal",this.onSessionProposal);break;case"session_delete":this.signClient.events[e]("session_delete",this.onSessionDelete);break;case"auth_request":this.authClient[e]("auth_request",this.onAuthRequest);break;case"proposal_expire":this.signClient.events[e]("proposal_expire",this.onProposalExpire);break;case"session_request_expire":this.signClient.events[e]("session_request_expire",this.onSessionRequestExpire);break;case"session_authenticate":this.signClient.events[e]("session_authenticate",this.onSessionRequestAuthenticate)}},this.signClient={},this.authClient={}}}const Yb={decryptMessage:async t=>{const e={core:new pl({storageOptions:t.storageOptions,storage:t.storage})};await e.core.crypto.init();const r=e.core.crypto.decode(t.topic,t.encryptedMessage);return e.core=null,r},getMetadata:async t=>{const e={core:new pl({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new Ab(e.core,e.core.logger),await e.sessionStore.init();const r=e.sessionStore.get(t.topic),i=r?.peer.metadata;return e.core=null,e.sessionStore=null,i}},Qb=class extends zb{constructor(t){super(t),this.events=new Eb.exports,this.on=(t,e)=>this.engine.on(t,e),this.once=(t,e)=>this.engine.once(t,e),this.off=(t,e)=>this.engine.off(t,e),this.removeListener=(t,e)=>this.engine.removeListener(t,e),this.pair=async t=>{try{return await this.engine.pair(t)}catch(t){throw this.logger.error(t.message),t}},this.approveSession=async t=>{try{return await this.engine.approveSession(t)}catch(t){throw this.logger.error(t.message),t}},this.rejectSession=async t=>{try{return await this.engine.rejectSession(t)}catch(t){throw this.logger.error(t.message),t}},this.updateSession=async t=>{try{return await this.engine.updateSession(t)}catch(t){throw this.logger.error(t.message),t}},this.extendSession=async t=>{try{return await this.engine.extendSession(t)}catch(t){throw this.logger.error(t.message),t}},this.respondSessionRequest=async t=>{try{return await this.engine.respondSessionRequest(t)}catch(t){throw this.logger.error(t.message),t}},this.disconnectSession=async t=>{try{return await this.engine.disconnectSession(t)}catch(t){throw this.logger.error(t.message),t}},this.emitSessionEvent=async t=>{try{return await this.engine.emitSessionEvent(t)}catch(t){throw this.logger.error(t.message),t}},this.getActiveSessions=()=>{try{return this.engine.getActiveSessions()}catch(t){throw this.logger.error(t.message),t}},this.getPendingSessionProposals=()=>{try{return this.engine.getPendingSessionProposals()}catch(t){throw this.logger.error(t.message),t}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(t){throw this.logger.error(t.message),t}},this.respondAuthRequest=async(t,e)=>{try{return await this.engine.respondAuthRequest(t,e)}catch(t){throw this.logger.error(t.message),t}},this.getPendingAuthRequests=()=>{try{return this.engine.getPendingAuthRequests()}catch(t){throw this.logger.error(t.message),t}},this.formatMessage=(t,e)=>{try{return this.engine.formatMessage(t,e)}catch(t){throw this.logger.error(t.message),t}},this.registerDeviceToken=t=>{try{return this.engine.registerDeviceToken(t)}catch(t){throw this.logger.error(t.message),t}},this.approveSessionAuthenticate=t=>{try{return this.engine.approveSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.rejectSessionAuthenticate=t=>{try{return this.engine.rejectSessionAuthenticate(t)}catch(t){throw this.logger.error(t.message),t}},this.formatAuthMessage=t=>{try{return this.engine.formatAuthMessage(t)}catch(t){throw this.logger.error(t.message),t}},this.metadata=t.metadata,this.name=t.name||"Web3Wallet",this.signConfig=t.signConfig,this.core=t.core,this.logger=this.core.logger,this.engine=new $b(this)}static async init(t){const e=new Qb(t);return await e.initialize(),e}async initialize(){this.logger.trace("Initialized");try{await this.engine.init(),this.logger.info("Web3Wallet Initialization Success")}catch(t){throw this.logger.info("Web3Wallet Initialization Failure"),this.logger.error(t.message),t}}};let Xb=Qb;Xb.notifications=Yb;const Zb=Xb;window.wc={core:null,web3wallet:null,statusObject:null,init:function(t){return new Promise((async(e,r)=>{if(!window.statusq){const t='missing window.statusq! Forgot to execute "ui/app/AppLayouts/Wallet/services/dapps/helpers.js" first?';console.error(t),r(t)}if(window.statusq.error){const t="Failed initializing WebChannel: "+window.statusq.error;console.error(t),r(t)}if(wc.statusObject=window.statusq.channel.objects.statusObject,!wc.statusObject){const t="Failed initializing WebChannel or initialization not run";console.error(t),r(t)}try{const r=new pl({projectId:t});window.wc.web3wallet=await Zb.init({core:r,metadata:{name:"Status",description:"Status Wallet",url:"http://localhost",icons:["https://avatars.githubusercontent.com/u/11767950"]}}),window.wc.core=r,window.wc.web3wallet.on("session_proposal",(t=>{wc.statusObject.onSessionProposal(t)})),window.wc.web3wallet.on("session_update",(t=>{wc.statusObject.onSessionUpdate(t)})),window.wc.web3wallet.on("session_extend",(t=>{wc.statusObject.onSessionExtend(t)})),window.wc.web3wallet.on("session_ping",(t=>{wc.statusObject.onSessionPing(t)})),window.wc.web3wallet.on("session_delete",(t=>{wc.statusObject.onSessionDelete(t)})),window.wc.web3wallet.on("session_expire",(t=>{wc.statusObject.onSessionExpire(t)})),window.wc.web3wallet.on("session_request",(t=>{wc.statusObject.onSessionRequest(t)})),window.wc.web3wallet.on("session_request_sent",(t=>{wc.statusObject.onSessionRequestSent(t)})),window.wc.web3wallet.on("session_event",(t=>{wc.statusObject.onSessionEvent(t)})),window.wc.web3wallet.on("proposal_expire",(t=>{wc.statusObject.onProposalExpire(t)})),window.wc.web3wallet.on("pairing_expire",(t=>{wc.statusObject.echo("debug",`WC unhandled event: "pairing_expire" ${JSON.stringify(t)}`)})),window.wc.web3wallet.on("session_request_expire",(t=>{wc.statusObject.echo("debug",`WC unhandled event: "session_request_expire" ${JSON.stringify(t)}`);const{id:e}=t;wc.statusObject.onSessionRequestExpire(e)})),window.wc.core.relayer.on("relayer_connect",(()=>{wc.statusObject.echo("debug",'WC unhandled event: "relayer_connect" connection to the relay server is established')})),window.wc.core.relayer.on("relayer_disconnect",(()=>{wc.statusObject.echo("debug",'WC unhandled event: "relayer_disconnect" connection to the relay server is lost')})),e("")}catch(t){r(t)}}))},pair:async function(t){wc.statusObject.echo("debug",`Pairing with uri: ${t}`),await window.wc.web3wallet.pair({uri:t})},getPairings:function(){return window.wc.web3wallet.core.pairing.getPairings()},getActiveSessions:function(){return window.wc.web3wallet.getActiveSessions()},disconnect:async function(t){await window.wc.web3wallet.disconnectSession({topic:t,reason:oc("USER_DISCONNECTED")})},ping:async function(t){await window.wc.web3wallet.engine.signClient.ping({topic:t})},buildApprovedNamespaces:async function(t,e){return function(t){const{proposal:{requiredNamespaces:e,optionalNamespaces:r={}},supportedNamespaces:i}=t,n=ec(e),s=ec(r),o={};Object.keys(i).forEach((t=>{const e=i[t].chains,r=i[t].methods,n=i[t].events,s=i[t].accounts;e.forEach((e=>{if(!s.some((t=>t.includes(e))))throw new Error(`No accounts provided for chain ${e} in namespace ${t}`)})),o[t]={chains:e,methods:r,events:n,accounts:s}}));const a=_c(e,o,"approve()");if(a)throw new Error(a.message);const h={};return Object.keys(e).length||Object.keys(r).length?(Object.keys(n).forEach((t=>{const e=i[t].chains.filter((e=>{var r,i;return null==(i=null==(r=n[t])?void 0:r.chains)?void 0:i.includes(e)})),r=i[t].methods.filter((e=>{var r,i;return null==(i=null==(r=n[t])?void 0:r.methods)?void 0:i.includes(e)})),s=i[t].events.filter((e=>{var r,i;return null==(i=null==(r=n[t])?void 0:r.events)?void 0:i.includes(e)})),o=e.map((e=>i[t].accounts.filter((t=>t.includes(`${e}:`))))).flat();h[t]={chains:e,methods:r,events:s,accounts:o}})),Object.keys(s).forEach((t=>{var e,r,n,o,a,c;if(!i[t])return;const f=null==(r=null==(e=s[t])?void 0:e.chains)?void 0:r.filter((e=>i[t].chains.includes(e))),u=i[t].methods.filter((e=>{var r,i;return null==(i=null==(r=s[t])?void 0:r.methods)?void 0:i.includes(e)})),d=i[t].events.filter((e=>{var r,i;return null==(i=null==(r=s[t])?void 0:r.events)?void 0:i.includes(e)})),l=f?.map((e=>i[t].accounts.filter((t=>t.includes(`${e}:`))))).flat();h[t]={chains:Ii(null==(n=h[t])?void 0:n.chains,f),methods:Ii(null==(o=h[t])?void 0:o.methods,u),events:Ii(null==(a=h[t])?void 0:a.events,d),accounts:Ii(null==(c=h[t])?void 0:c.accounts,l)}})),h):o}({proposal:t,supportedNamespaces:e})},approveSession:async function(t,e){const{id:r,params:i}=t,{relays:n}=i;return await window.wc.web3wallet.approveSession({id:r,relayProtocol:n[0].protocol,namespaces:e})},rejectSession:async function(t){await window.wc.web3wallet.rejectSession({id:t,reason:oc("USER_REJECTED")})},respondSessionRequest:async function(t,e,r){const i=Hc(e,r);await window.wc.web3wallet.respondSessionRequest({topic:t,response:i})},rejectSessionRequest:async function(t,e,r=!1){const i=r?"SESSION_SETTLEMENT_FAILED":"USER_REJECTED";await window.wc.web3wallet.respondSessionRequest({topic:t,response:Wc(e,oc(i))})}}; \ No newline at end of file diff --git a/ui/app/AppLayouts/Wallet/services/dapps/sdk/package-lock.json b/ui/app/AppLayouts/Wallet/services/dapps/sdk/package-lock.json index cc2c97a596f..aff54d9bfd2 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/sdk/package-lock.json +++ b/ui/app/AppLayouts/Wallet/services/dapps/sdk/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "license": "MPL-2.0", "dependencies": { - "@walletconnect/web3wallet": "^1.13.0" + "@walletconnect/web3wallet": "^1.15.1" }, "devDependencies": { "webpack": "^5.93.0", @@ -1125,9 +1125,9 @@ } }, "node_modules/@walletconnect/core": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@walletconnect/core/-/core-2.14.0.tgz", - "integrity": "sha512-E/dgBM9q3judXnTfZQ5ILvDpeSdDpabBLsXtYXa3Nyc26cfNplfLJ2nXm9FgtTdhM1nZ7yx4+zDPiXawBRZl2g==", + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/@walletconnect/core/-/core-2.16.1.tgz", + "integrity": "sha512-UlsnEMT5wwFvmxEjX8s4oju7R3zadxNbZgsFeHEsjh7uknY2zgmUe1Lfc5XU6zyPb1Jx7Nqpdx1KN485ee8ogw==", "dependencies": { "@walletconnect/heartbeat": "1.2.2", "@walletconnect/jsonrpc-provider": "1.0.14", @@ -1136,16 +1136,18 @@ "@walletconnect/jsonrpc-ws-connection": "1.0.14", "@walletconnect/keyvaluestorage": "1.1.1", "@walletconnect/logger": "2.1.2", - "@walletconnect/relay-api": "1.0.10", + "@walletconnect/relay-api": "1.0.11", "@walletconnect/relay-auth": "1.0.4", "@walletconnect/safe-json": "1.0.2", "@walletconnect/time": "1.0.2", - "@walletconnect/types": "2.14.0", - "@walletconnect/utils": "2.14.0", + "@walletconnect/types": "2.16.1", + "@walletconnect/utils": "2.16.1", "events": "3.3.0", - "isomorphic-unfetch": "3.1.0", "lodash.isequal": "4.5.0", "uint8arrays": "3.1.0" + }, + "engines": { + "node": ">=18" } }, "node_modules/@walletconnect/core/node_modules/uint8arrays": { @@ -1251,9 +1253,9 @@ } }, "node_modules/@walletconnect/relay-api": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/@walletconnect/relay-api/-/relay-api-1.0.10.tgz", - "integrity": "sha512-tqrdd4zU9VBNqUaXXQASaexklv6A54yEyQQEXYOCr+Jz8Ket0dmPBDyg19LVSNUN2cipAghQc45/KVmfFJ0cYw==", + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@walletconnect/relay-api/-/relay-api-1.0.11.tgz", + "integrity": "sha512-tLPErkze/HmC9aCmdZOhtVmYZq1wKfWTJtygQHoWtgg722Jd4homo54Cs4ak2RUFUZIGO2RsOpIcWipaua5D5Q==", "dependencies": { "@walletconnect/jsonrpc-types": "^1.0.2" } @@ -1280,18 +1282,18 @@ } }, "node_modules/@walletconnect/sign-client": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@walletconnect/sign-client/-/sign-client-2.14.0.tgz", - "integrity": "sha512-UrB3S3eLjPYfBLCN3WJ5u7+WcZ8kFMe/QIDqLf76Jk6TaLwkSUy563LvnSw4KW/kA+/cY1KBSdUDfX1tzYJJXg==", + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/@walletconnect/sign-client/-/sign-client-2.16.1.tgz", + "integrity": "sha512-s2Tx2n2duxt+sHtuWXrN9yZVaHaYqcEcjwlTD+55/vs5NUPlISf+fFmZLwSeX1kUlrSBrAuxPUcqQuRTKcjLOA==", "dependencies": { - "@walletconnect/core": "2.14.0", + "@walletconnect/core": "2.16.1", "@walletconnect/events": "1.0.1", "@walletconnect/heartbeat": "1.2.2", "@walletconnect/jsonrpc-utils": "1.0.8", "@walletconnect/logger": "2.1.2", "@walletconnect/time": "1.0.2", - "@walletconnect/types": "2.14.0", - "@walletconnect/utils": "2.14.0", + "@walletconnect/types": "2.16.1", + "@walletconnect/utils": "2.16.1", "events": "3.3.0" } }, @@ -1304,9 +1306,9 @@ } }, "node_modules/@walletconnect/types": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@walletconnect/types/-/types-2.14.0.tgz", - "integrity": "sha512-vevMi4jZLJ55vLuFOicQFmBBbLyb+S0sZS4IsaBdZkQflfGIq34HkN13c/KPl4Ye0aoR4/cUcUSitmGIzEQM5g==", + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/@walletconnect/types/-/types-2.16.1.tgz", + "integrity": "sha512-9P4RG4VoDEF+yBF/n2TF12gsvT/aTaeZTVDb/AOayafqiPnmrQZMKmNCJJjq1sfdsDcHXFcZWMGsuCeSJCmrXA==", "dependencies": { "@walletconnect/events": "1.0.1", "@walletconnect/heartbeat": "1.2.2", @@ -1317,26 +1319,47 @@ } }, "node_modules/@walletconnect/utils": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@walletconnect/utils/-/utils-2.14.0.tgz", - "integrity": "sha512-vRVomYQEtEAyCK2c5bzzEvtgxaGGITF8mWuIL+WYSAMyEJLY97mirP2urDucNwcUczwxUgI+no9RiNFbUHreQQ==", + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/@walletconnect/utils/-/utils-2.16.1.tgz", + "integrity": "sha512-aoQirVoDoiiEtYeYDtNtQxFzwO/oCrz9zqeEEXYJaAwXlGVTS34KFe7W3/Rxd/pldTYKFOZsku2EzpISfH8Wsw==", "dependencies": { "@stablelib/chacha20poly1305": "1.0.1", "@stablelib/hkdf": "1.0.1", "@stablelib/random": "1.0.2", "@stablelib/sha256": "1.0.1", "@stablelib/x25519": "1.0.3", - "@walletconnect/relay-api": "1.0.10", + "@walletconnect/relay-api": "1.0.11", + "@walletconnect/relay-auth": "1.0.4", "@walletconnect/safe-json": "1.0.2", "@walletconnect/time": "1.0.2", - "@walletconnect/types": "2.14.0", + "@walletconnect/types": "2.16.1", "@walletconnect/window-getters": "1.0.1", "@walletconnect/window-metadata": "1.0.1", "detect-browser": "5.3.0", + "elliptic": "^6.5.7", "query-string": "7.1.3", "uint8arrays": "3.1.0" } }, + "node_modules/@walletconnect/utils/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" + }, + "node_modules/@walletconnect/utils/node_modules/elliptic": { + "version": "6.5.7", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.7.tgz", + "integrity": "sha512-ESVCtTwiA+XhY3wyh24QqRGBoP3rEdDUl3EDUUo9tft074fi19IrdpH7hLCMMP3CIj7jb3W96rn8lt/BqIlt5Q==", + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } + }, "node_modules/@walletconnect/utils/node_modules/uint8arrays": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.0.tgz", @@ -1346,18 +1369,18 @@ } }, "node_modules/@walletconnect/web3wallet": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/@walletconnect/web3wallet/-/web3wallet-1.13.0.tgz", - "integrity": "sha512-5fAe4rIe7B0Q8NpyEYfyYBjrbtC5H4/VZMSgg9LHxpChXIpjUX01hj7jdTPvE7EOzN1mt2w7hgnpI5jY883gXg==", + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/@walletconnect/web3wallet/-/web3wallet-1.15.1.tgz", + "integrity": "sha512-EgtdZUgtf0diU98x8Q8tiZslE0Z5comnxv3SqmAIgkdhpXDxaM/goo7BC1yC+Wey/IHOOVYg2SW+La2Txk+6hQ==", "dependencies": { "@walletconnect/auth-client": "2.1.2", - "@walletconnect/core": "2.14.0", + "@walletconnect/core": "2.16.1", "@walletconnect/jsonrpc-provider": "1.0.14", "@walletconnect/jsonrpc-utils": "1.0.8", "@walletconnect/logger": "2.1.2", - "@walletconnect/sign-client": "2.14.0", - "@walletconnect/types": "2.14.0", - "@walletconnect/utils": "2.14.0" + "@walletconnect/sign-client": "2.16.1", + "@walletconnect/types": "2.16.1", + "@walletconnect/utils": "2.16.1" } }, "node_modules/@walletconnect/window-getters": { diff --git a/ui/app/AppLayouts/Wallet/services/dapps/sdk/package.json b/ui/app/AppLayouts/Wallet/services/dapps/sdk/package.json index d339b2c4775..594b30b21ee 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/sdk/package.json +++ b/ui/app/AppLayouts/Wallet/services/dapps/sdk/package.json @@ -16,6 +16,6 @@ "start": "webpack serve --mode development --open" }, "dependencies": { - "@walletconnect/web3wallet": "^1.13.0" + "@walletconnect/web3wallet": "^1.15.1" } } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/sdk/src/index.js b/ui/app/AppLayouts/Wallet/services/dapps/sdk/src/index.js index c390a5a3b2f..e6833198d04 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/sdk/src/index.js +++ b/ui/app/AppLayouts/Wallet/services/dapps/sdk/src/index.js @@ -94,7 +94,8 @@ window.wc = { }); window.wc.web3wallet.on("session_request_expire", (event) => { wc.statusObject.echo("debug", `WC unhandled event: "session_request_expire" ${JSON.stringify(event)}`); - // const { id } = event + const { id } = event + wc.statusObject.onSessionRequestExpire(id) }); window.wc.core.relayer.on("relayer_connect", () => { wc.statusObject.echo("debug", `WC unhandled event: "relayer_connect" connection to the relay server is established`); @@ -112,6 +113,7 @@ window.wc = { // TODO: there is a corner case when attempting to pair with a link that is already paired or was rejected won't trigger any event back pair: async function (uri) { + wc.statusObject.echo("debug", `Pairing with uri: ${uri}`); await window.wc.web3wallet.pair({ uri }); }, diff --git a/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestResolved.qml b/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestResolved.qml index a5005414c5f..f33cb19e6d3 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestResolved.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestResolved.qml @@ -15,11 +15,15 @@ QObject { /// } required property var event + /// dApp request data required property string topic required property string id required property string method required property string accountAddress required property string chainId + required property double expirationTimestamp + // Maps to Constants.DAppConnectors values + required property int sourceId required property var data // Data prepared for display in a human readable format @@ -29,9 +33,20 @@ QObject { readonly property alias dappUrl: d.dappUrl readonly property alias dappIcon: d.dappIcon + /// extra data resolved from wallet property string maxFeesText: "" property string maxFeesEthText: "" - property bool enoughFunds: false + property bool haveEnoughFunds: false + property bool haveEnoughFees: false + + property var /* Big */ fiatMaxFees + property var /* Big */ ethMaxFees + property var feesInfo + + /// maps to Constants.TransactionEstimatedTime values + property int estimatedTimeCategory: 0 + + signal expired() function resolveDappInfoFromSession(session) { let meta = session.peer.metadata @@ -49,5 +64,14 @@ QObject { property string dappName property string dappUrl property url dappIcon + + readonly property Timer expiry: Timer { + interval: root.expirationTimestamp - Date.now() + running: true + repeat: false + onTriggered: { + root.expired() + } + } } } \ No newline at end of file diff --git a/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestsModel.qml b/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestsModel.qml index 05130d38de4..cce02bdad58 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestsModel.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/types/SessionRequestsModel.qml @@ -5,14 +5,14 @@ ListModel { id: root function enqueue(request) { - root.append(request); + root.append({requestItem: request}); } function dequeue() { if (root.count > 0) { var item = root.get(0); root.remove(0); - return item; + return item.requestItem; } return null; } @@ -20,8 +20,19 @@ ListModel { /// returns null if not found function findRequest(topic, id) { for (var i = 0; i < root.count; i++) { - let entry = root.get(i) - if (entry.topic === topic && entry.id === id) { + let entry = root.get(i).requestItem + if (entry.topic == topic && entry.id == id) { + return entry; + } + } + return null; + } + + // returns null if not found + function findById(id) { + for (var i = 0; i < root.count; i++) { + let entry = root.get(i).requestItem + if (entry.id == id) { return entry; } } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/types/qmldir b/ui/app/AppLayouts/Wallet/services/dapps/types/qmldir index ae2bf029da4..93a107d0503 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/types/qmldir +++ b/ui/app/AppLayouts/Wallet/services/dapps/types/qmldir @@ -1,3 +1,4 @@ SessionRequestResolved 1.0 SessionRequestResolved.qml +SessionRequestsModel 1.0 SessionRequestsModel.qml singleton SessionRequest 1.0 SessionRequest.qml singleton Pairing 1.0 Pairing.qml \ No newline at end of file diff --git a/ui/imports/shared/popups/walletconnect/ConnectDAppModal.qml b/ui/imports/shared/popups/walletconnect/ConnectDAppModal.qml index 7e5a8e346e1..6a69984a53d 100644 --- a/ui/imports/shared/popups/walletconnect/ConnectDAppModal.qml +++ b/ui/imports/shared/popups/walletconnect/ConnectDAppModal.qml @@ -79,10 +79,10 @@ StatusDialog { readonly property int connectionSuccessfulStatus: 1 readonly property int connectionFailedStatus: 2 - function pairSuccessful(session) { + function pairSuccessful() { d.connectionStatus = root.connectionSuccessfulStatus } - function pairFailed(session, err) { + function pairFailed() { d.connectionStatus = root.connectionFailedStatus } diff --git a/ui/imports/shared/popups/walletconnect/DAppSignRequestModal.qml b/ui/imports/shared/popups/walletconnect/DAppSignRequestModal.qml index d898d481ce6..32d07cd00f1 100644 --- a/ui/imports/shared/popups/walletconnect/DAppSignRequestModal.qml +++ b/ui/imports/shared/popups/walletconnect/DAppSignRequestModal.qml @@ -41,7 +41,7 @@ SignTransactionModalBase { property bool enoughFundsForTransaction: true property bool enoughFundsForFees: false - signButtonEnabled: enoughFundsForTransaction && enoughFundsForFees + signButtonEnabled: (!hasFees) || enoughFundsForTransaction && enoughFundsForFees title: qsTr("Sign Request") subtitle: SQUtils.StringUtils.extractDomainFromLink(root.dappUrl) headerIconComponent: RoundImageWithBadge { @@ -68,7 +68,7 @@ SignTransactionModalBase { infoTag.states: [ State { name: "insufficientFunds" - when: !root.enoughFundsForTransaction + when: root.hasFees && !root.enoughFundsForTransaction PropertyChanges { target: infoTag asset.color: Theme.palette.dangerColor1 @@ -96,8 +96,8 @@ SignTransactionModalBase { Layout.fillWidth: true objectName: "footerFiatFeesText" text: formatBigNumber(root.fiatFees, root.currentCurrency) - loading: root.feesLoading - customColor: root.enoughFundsForFees ? Theme.palette.directColor1 : Theme.palette.dangerColor1 + loading: root.feesLoading && root.hasFees + customColor: !root.hasFees || root.enoughFundsForFees ? Theme.palette.directColor1 : Theme.palette.dangerColor1 elide: Qt.ElideMiddle Binding on text { when: !root.hasFees diff --git a/ui/imports/utils/Constants.qml b/ui/imports/utils/Constants.qml index ce106b0c643..c79045bfc62 100644 --- a/ui/imports/utils/Constants.qml +++ b/ui/imports/utils/Constants.qml @@ -1464,4 +1464,9 @@ QtObject { } readonly property string navigationMetric: "navigation" + + enum DAppConnectors { + WalletConnect = 1, + StatusConnect = 2 + } }