lorisleiva / solana-wallets-vue

Solana wallet integration for Vue 3
https://solana-wallets-vue-demo.netlify.app/
173 stars 65 forks source link

wallet-adapter-mobile #24

Closed lmvdz closed 2 years ago

lmvdz commented 2 years ago

https://github.com/solana-mobile/mobile-wallet-adapter/tree/main/js/packages/wallet-adapter-mobile

Testing the wallet-adapter-mobile to use in my vuejs app.

Steps:

Click connect to wallet Select the "Default wallet app" Authorize Get directed back to the web app stuck on Connecting... Check the mobile wallet app, spinning icon Close the web app tab and open up the site, wallet is connected

image image image image image

image

watch(wallet, (newVal, oldVal) => {
  if (newVal !== null && newVal.connected && newVal.disconnecting) {
    console.log('wallet disconnected');
    clearInterval(updateInterval.value)
    unloadUserPredictions()
    unloadUser()
    unloadTokenAccounts()
    unloadUserClaimable()
  } else if (newVal !== null && !newVal.connected && newVal.connecting) {
    console.log('wallet connecting')
  } else if (newVal !== null && newVal.connected && !newVal.connecting && !newVal.disconnecting) {
    console.log('wallet conected');
    loadWallet();
  }
}, { deep: true })
lmvdz commented 2 years ago

The wallet connecting console output gets spammed, if that is any indication!

sdlaver commented 2 years ago

Yep, that helps. The failure is occurring either because the wallet app websocket server isn't running, or because the websocket server is denying the connection. My guess is the former, but logs will help confirm, as well as fix.

To collect logs from Android Studio:

  1. Launch fakewallet using the 'Run' button
  2. Find the 'logcat' tab along the bottom ribbon
  3. At the top of the logcat docked window, make sure the first dropdown has your emulator selected (it should by default), and the second dropdown is 'com.solana.mobilewalletadapter.fakewallet'
  4. Repro the failure
  5. Capture the contents of the logcat window, and of your JS console, and attach to this issue
  6. Mention me on this issue for further debugging
sdlaver commented 2 years ago

Also, is this the Android emulator, or an actual device? If it's a device, would you mind sharing the make and model?

lmvdz commented 2 years ago

Also, is this the Android emulator, or an actual device? If it's a device, would you mind sharing the make and model?

I tested on Both. API 33 was emulator

lmvdz commented 2 years ago

@sdlaver

2022-07-12 00:44:10.895 18427-18427/com.solana.mobilewalletadapter.fakewallet I/pter.fakewalle: failed to find target package for overlay /system/product/overlay/ProductOverlay-oneplus-framework-res.apk
2022-07-12 00:44:10.895 18427-18427/com.solana.mobilewalletadapter.fakewallet I/pter.fakewalle: failed to find target package for overlay /system/system_ext/overlay/CommonOverlay-oneplus-framework-res.apk
2022-07-12 00:44:10.895 18427-18427/com.solana.mobilewalletadapter.fakewallet I/pter.fakewalle: failed to find target package for overlay /odm/overlay/OdmOverlay-oneplus-framework-res.apk
2022-07-12 00:44:11.017 18427-18427/com.solana.mobilewalletadapter.fakewallet I/LocalWebSocketServer: Starting local mobile-wallet-adapter WebSocket server on port 61970
2022-07-12 00:44:11.058 18427-18427/com.solana.mobilewalletadapter.fakewallet D/ViewRootImpl: support adaptive color gamut feature!
2022-07-12 00:44:11.059 18427-18427/com.solana.mobilewalletadapter.fakewallet V/ViewRootImpl: The specified message queue synchronization  barrier token has not been posted or has already been removed
2022-07-12 00:44:11.114 18427-18427/com.solana.mobilewalletadapter.fakewallet D/ActivityThread: pid:18427 tid:18427 doframe Callback
2022-07-12 00:44:11.138 18427-18427/com.solana.mobilewalletadapter.fakewallet D/DecorView: onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@215055d[MobileWalletAdapterActivity]
2022-07-12 00:44:11.140 18427-18427/com.solana.mobilewalletadapter.fakewallet D/ViewRootImpl[MobileWalletAdapterActivity]: windowFocusChanged hasFocus=true inTouchMode=true
2022-07-12 00:44:11.165 18427-25700/com.solana.mobilewalletadapter.fakewallet D/LocalWebSocketServer: mobile-wallet-adapter WebSocket opened
2022-07-12 00:44:11.188 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: receiverConnected
2022-07-12 00:44:11.221 18427-25700/com.solana.mobilewalletadapter.fakewallet D/LocalWebSocketServer: mobile-wallet-adapter WebSocket recv (binary)
2022-07-12 00:44:11.221 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: receiverMessageReceived: size=129
2022-07-12 00:44:11.221 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSession: handleSessionEstablishmentMessage
2022-07-12 00:44:11.223 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSession: Received public key 76261343410792218991834290748441390856366077684351249347545062449014329887349/44675637325601791631595241190260230502873928194094434016556780996701473150870
2022-07-12 00:44:11.223 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: generateSessionECDHKeyPair
2022-07-12 00:44:11.224 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: generateSessionECDHSecret
2022-07-12 00:44:11.226 18427-25700/com.solana.mobilewalletadapter.fakewallet I/MobileWalletAdapterSessionCommon: Encrypted session established
2022-07-12 00:44:11.226 18427-25700/com.solana.mobilewalletadapter.fakewallet V/JsonRpc20Server: JSON-RPC 2.0 server connected
2022-07-12 00:44:11.226 18427-25700/com.solana.mobilewalletadapter.fakewallet D/Scenario: MobileWalletAdapter session established
2022-07-12 00:44:11.226 18427-25700/com.solana.mobilewalletadapter.fakewallet D/LocalWebSocketServer: mobile-wallet-adapter WebSocket send
2022-07-12 00:44:11.226 18427-25697/com.solana.mobilewalletadapter.fakewallet V/AuthRepository: Starting AuthRepository
2022-07-12 00:44:11.235 18427-25697/com.solana.mobilewalletadapter.fakewallet E/sqlite3_android: [IKR-38846] ONEPLUS_NAME_PARTS_MATCH SQLITE_OK
2022-07-12 00:44:11.266 18427-25700/com.solana.mobilewalletadapter.fakewallet D/LocalWebSocketServer: mobile-wallet-adapter WebSocket recv (binary)
2022-07-12 00:44:11.266 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: receiverMessageReceived: size=182
2022-07-12 00:44:11.266 18427-25700/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: handleEncryptedSessionMessage
2022-07-12 00:44:11.266 18427-25700/com.solana.mobilewalletadapter.fakewallet V/JsonRpc20Server: JSON-RPC 2.0 message received
2022-07-12 00:44:11.310 18427-18427/com.solana.mobilewalletadapter.fakewallet I/TetheringManager: registerTetheringEventCallback:com.solana.mobilewalletadapter.fakewallet
2022-07-12 00:44:11.760 18427-25705/com.solana.mobilewalletadapter.fakewallet D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-07-12 00:44:11.760 18427-25705/com.solana.mobilewalletadapter.fakewallet D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-07-12 00:44:13.167 18427-18427/com.solana.mobilewalletadapter.fakewallet I/AuthorizeDappFragment: Authorizing dapp
2022-07-12 00:44:13.202 18427-25705/com.solana.mobilewalletadapter.fakewallet E/sqlite3_android: [IKR-38846] ONEPLUS_NAME_PARTS_MATCH SQLITE_OK
2022-07-12 00:44:13.206 18427-25705/com.solana.mobilewalletadapter.fakewallet E/sqlite3_android: [IKR-38846] ONEPLUS_NAME_PARTS_MATCH SQLITE_OK
2022-07-12 00:44:13.211 18427-25705/com.solana.mobilewalletadapter.fakewallet D/Ed25519KeyRepository: Inserted key entry with id=14 for 1tWCJi+FaCtHSoZ8tAEie/wkwe8cxo6zG4aidHX/EcY
2022-07-12 00:44:13.212 18427-18427/com.solana.mobilewalletadapter.fakewallet D/MobileWalletAdapterViewModel: Generated a new keypair (pub=[-42, -43, -126, 38, 47, -123, 104, 43, 71, 74, -122, 124, -76, 1, 34, 123, -4, 36, -63, -17, 28, -58, -114, -77, 27, -122, -94, 116, 117, -1, 17, -58]) for authorize request
2022-07-12 00:44:13.225 18427-25697/com.solana.mobilewalletadapter.fakewallet D/AuthorizeRequest: Authorize request completed successfully; issued auth: AuthRecord{id=17, identity=IdentityRecord{id=3, name='SolPredict', uri=https://devnet.solpredict.io/, relativeIconUri=./assets/logo.svg}, publicKey=[-42, -43, -126, 38, 47, -123, 104, 43, 71, 74, -122, 124, -76, 1, 34, 123, -4, 36, -63, -17, 28, -58, -114, -77, 27, -122, -94, 116, 117, -1, 17, -58], scope=[], issued=1657604653219, expires=1657608253219, mRevoked=false}
2022-07-12 00:44:13.243 18427-25697/com.solana.mobilewalletadapter.fakewallet V/AuthRepository: Returning auth token for AuthRecord: AuthRecord{id=17, identity=IdentityRecord{id=3, name='SolPredict', uri=https://devnet.solpredict.io/, relativeIconUri=./assets/logo.svg}, publicKey=[-42, -43, -126, 38, 47, -123, 104, 43, 71, 74, -122, 124, -76, 1, 34, 123, -4, 36, -63, -17, 28, -58, -114, -77, 27, -122, -94, 116, 117, -1, 17, -58], scope=[], issued=1657604653219, expires=1657608253219, mRevoked=false}
2022-07-12 00:44:13.243 18427-25697/com.solana.mobilewalletadapter.fakewallet D/JsonRpc20Server: Responding with result for id=1
2022-07-12 00:44:13.243 18427-25697/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: send
2022-07-12 00:44:13.244 18427-25697/com.solana.mobilewalletadapter.fakewallet D/LocalWebSocketServer: mobile-wallet-adapter WebSocket send
2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet D/LocalWebSocketServer: mobile-wallet-adapter WebSocket closed
2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet V/MobileWalletAdapterSessionCommon: receiverDisconnected
2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet V/JsonRpc20Server: JSON-RPC 2.0 server disconnected
2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet I/MobileWalletAdapterSessionCommon: mobile-wallet-adapter session closed
2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet D/Scenario: MobileWalletAdapter session terminated
2022-07-12 00:44:13.400 18427-25697/com.solana.mobilewalletadapter.fakewallet V/AuthRepository: Stopping AuthRepository
2022-07-12 00:44:13.400 18427-25697/com.solana.mobilewalletadapter.fakewallet I/LocalWebSocketServer: Stopping local mobile-wallet-adapter WebSocket server
2022-07-12 00:44:13.502 18427-18427/com.solana.mobilewalletadapter.fakewallet D/ViewRootImpl[MobileWalletAdapterActivity]: windowFocusChanged hasFocus=false inTouchMode=true
lmvdz commented 2 years ago

WebSocket connection to 'ws://localhost:63042/solana-wallet' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED F @ index.e64ce6e5.js:27 (anonymous) @ index.e64ce6e5.js:27 (anonymous) @ index.e64ce6e5.js:27 m @ index.e64ce6e5.js:27

this is line 27 (prettified)

let activePinia;
const setActivePinia = e => activePinia = e,
    piniaSymbol = Symbol();

function isPlainObject(e) {
    return e && typeof e == "object" && Object.prototype.toString.call(e) === "[object Object]" && typeof e.toJSON != "function"
}
var MutationType;
(function(e) {
    e.direct = "direct", e.patchObject = "patch object", e.patchFunction = "patch function"
})(MutationType || (MutationType = {}));

function createPinia() {
    const e = effectScope(!0),
        t = e.run(() => ref({}));
    let o = [],
        n = [];
    const a = markRaw({
        install(c) {
            setActivePinia(a), a._a = c, c.provide(piniaSymbol, a), c.config.globalProperties.$pinia = a, n.forEach(l => o.push(l)), n = []
        },
        use(c) {
            return !this._a && !isVue2 ? n.push(c) : o.push(c), this
        },
        _p: o,
        _a: null,
        _e: e,
        _s: new Map,
        state: t
    });
    return a
}
const noop = () => {};

function addSubscription(e, t, o, n = noop) {
    e.push(t);
    const a = () => {
        const c = e.indexOf(t);
        c > -1 && (e.splice(c, 1), n())
    };
    return !o && getCurrentInstance$1() && onUnmounted(a), a
}

function triggerSubscriptions(e, ...t) {
    e.slice().forEach(o => {
        o(...t)
    })
}

function mergeReactiveObjects(e, t) {
    for (const o in t) {
        if (!t.hasOwnProperty(o)) continue;
        const n = t[o],
            a = e[o];
        isPlainObject(a) && isPlainObject(n) && e.hasOwnProperty(o) && !isRef(n) && !isReactive(n) ? e[o] = mergeReactiveObjects(a, n) : e[o] = n
    }
    return e
}
const skipHydrateSymbol = Symbol();

function shouldHydrate(e) {
    return !isPlainObject(e) || !e.hasOwnProperty(skipHydrateSymbol)
}
const {
    assign
} = Object;

function isComputed(e) {
    return !!(isRef(e) && e.effect)
}

function createOptionsStore(e, t, o, n) {
    const {
        state: a,
        actions: c,
        getters: l
    } = t, m = o.state.value[e];
    let d;

    function g() {
        m || (o.state.value[e] = a ? a() : {});
        const w = toRefs(o.state.value[e]);
        return assign(w, c, Object.keys(l || {}).reduce((S, C) => (S[C] = markRaw(computed(() => {
            setActivePinia(o);
            const A = o._s.get(e);
            return l[C].call(A, A)
        })), S), {}))
    }
    return d = createSetupStore(e, g, t, o, n, !0), d.$reset = function() {
        const S = a ? a() : {};
        this.$patch(C => {
            assign(C, S)
        })
    }, d
}

function createSetupStore(e, t, o = {}, n, a, c) {
    let l;
    const m = assign({
            actions: {}
        }, o),
        d = {
            deep: !0
        };
    let g, w, S = markRaw([]),
        C = markRaw([]),
        A;
    const P = n.state.value[e];
    !c && !P && (n.state.value[e] = {}), ref({});
    let G;

    function X(q) {
        let Q;
        g = w = !1, typeof q == "function" ? (q(n.state.value[e]), Q = {
            type: MutationType.patchFunction,
            storeId: e,
            events: A
        }) : (mergeReactiveObjects(n.state.value[e], q), Q = {
            type: MutationType.patchObject,
            payload: q,
            storeId: e,
            events: A
        });
        const at = G = Symbol();
        nextTick().then(() => {
            G === at && (g = !0)
        }), w = !0, triggerSubscriptions(S, Q, n.state.value[e])
    }
    const M = noop;

    function F() {
        l.stop(), S = [], C = [], n._s.delete(e)
    }

    function B(q, Q) {
        return function() {
            setActivePinia(n);
            const at = Array.from(arguments),
                pt = [],
                _ = [];

            function k(T) {
                pt.push(T)
            }

            function U(T) {
                _.push(T)
            }
            triggerSubscriptions(C, {
                args: at,
                name: q,
                store: V,
                after: k,
                onError: U
            });
            let b;
            try {
                b = Q.apply(this && this.$id === e ? this : V, at)
            } catch (T) {
                throw triggerSubscriptions(_, T), T
            }
            return b instanceof Promise ? b.then(T => (triggerSubscriptions(pt, T), T)).catch(T => (triggerSubscriptions(_, T), Promise.reject(T))) : (triggerSubscriptions(pt, b), b)
        }
    }
    const z = {
            _p: n,
            $id: e,
            $onAction: addSubscription.bind(null, C),
            $patch: X,
            $reset: M,
            $subscribe(q, Q = {}) {
                const at = addSubscription(S, q, Q.detached, () => pt()),
                    pt = l.run(() => watch(() => n.state.value[e], _ => {
                        (Q.flush === "sync" ? w : g) && q({
                            storeId: e,
                            type: MutationType.direct,
                            events: A
                        }, _)
                    }, assign({}, d, Q)));
                return at
            },
            $dispose: F
        },
        V = reactive(assign({}, z));
    n._s.set(e, V);
    const J = n._e.run(() => (l = effectScope(), l.run(() => t())));
    for (const q in J) {
        const Q = J[q];
        if (isRef(Q) && !isComputed(Q) || isReactive(Q)) c || (P && shouldHydrate(Q) && (isRef(Q) ? Q.value = P[q] : mergeReactiveObjects(Q, P[q])), n.state.value[e][q] = Q);
        else if (typeof Q == "function") {
            const at = B(q, Q);
            J[q] = at, m.actions[q] = Q
        }
    }
    return assign(V, J), assign(toRaw(V), J), Object.defineProperty(V, "$state", {
        get: () => n.state.value[e],
        set: q => {
            X(Q => {
                assign(Q, q)
            })
        }
    }), n._p.forEach(q => {
        assign(V, l.run(() => q({
            store: V,
            app: n._a,
            pinia: n,
            options: m
        })))
    }), P && c && o.hydrate && o.hydrate(V.$state, P), g = !0, w = !0, V
}

function defineStore(e, t, o) {
    let n, a;
    const c = typeof t == "function";
    typeof e == "string" ? (n = e, a = c ? o : t) : (a = e, n = e.id);

    function l(m, d) {
        const g = getCurrentInstance$1();
        return m = m || g && inject(piniaSymbol), m && setActivePinia(m), m = activePinia, m._s.has(n) || (c ? createSetupStore(n, t, a, m) : createOptionsStore(n, a, m)), m._s.get(n)
    }
    return l.$id = n, l
}

function storeToRefs(e) {
    {
        e = toRaw(e);
        const t = {};
        for (const o in e) {
            const n = e[o];
            (isRef(n) || isReactive(n)) && (t[o] = toRef(e, o))
        }
        return t
    }
}
var styles = "";

function __awaiter$1(e, t, o, n) {
    function a(c) {
        return c instanceof o ? c : new o(function(l) {
            l(c)
        })
    }
    return new(o || (o = Promise))(function(c, l) {
        function m(w) {
            try {
                g(n.next(w))
            } catch (S) {
                l(S)
            }
        }

        function d(w) {
            try {
                g(n.throw(w))
            } catch (S) {
                l(S)
            }
        }

        function g(w) {
            w.done ? c(w.value) : a(w.value).then(m, d)
        }
        g((n = n.apply(e, t || [])).next())
    })
}

function createHelloReq(e, t) {
    return __awaiter$1(this, void 0, void 0, function*() {
        const o = yield crypto.subtle.exportKey("raw", e), n = yield crypto.subtle.sign({
            hash: "SHA-256",
            name: "ECDSA"
        }, t, o), a = new Uint8Array(o.byteLength + n.byteLength);
        return a.set(new Uint8Array(o), 0), a.set(new Uint8Array(n), o.byteLength), a
    })
}
class SolanaMobileWalletAdapterSecureContextRequiredError extends Error {
    constructor() {
        super("The mobile wallet adapter protocol must be used in a secure context (`https`)."), this.name = "SolanaMobileWalletAdapterSecureContextRequiredError"
    }
}
class SolanaMobileWalletAdapterForbiddenWalletBaseURLError extends Error {
    constructor() {
        super("Base URLs supplied by wallets must be valid `https` URLs"), this.name = "SolanaMobileWalletAdapterForbiddenWalletBaseURLError"
    }
}
class SolanaMobileWalletAdapterWalletNotInstalledError extends Error {
    constructor() {
        super("Found no installed wallet that supports the mobile wallet protocol."), this.name = "SolanaMobileWalletAdapterWalletNotInstalledError"
    }
}
class SolanaMobileWalletAdapterProtocolSessionEstablishmentError extends Error {
    constructor(t) {
        super(`Failed to connect to the wallet websocket on port ${t}.`), this.name = "SolanaMobileWalletAdapterProtocolSessionEstablishmentError"
    }
}
class SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError extends Error {
    constructor(t) {
        super(`Association port number must be between 49152 and 65535. ${t} given.`), this.name = "SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError"
    }
}
class SolanaMobileWalletAdapterProtocolSessionClosedError extends Error {
    constructor(t, o) {
        super(`The wallet session dropped unexpectedly (${t}: ${o}).`), this.name = "SolanaMobileWalletAdapterProtocolSessionClosedError"
    }
}
class SolanaMobileWalletAdapterProtocolJsonRpcError extends Error {
    constructor(...t) {
        const [o, n, a, c] = t;
        super(a), this.code = n, this.data = c, this.jsonRpcMessageId = o, this.name = "SolanaNativeWalletAdapterJsonRpcError"
    }
}

function generateAssociationKeypair() {
    return __awaiter$1(this, void 0, void 0, function*() {
        return yield crypto.subtle.generateKey({
            name: "ECDSA",
            namedCurve: "P-256"
        }, !1, ["sign"])
    })
}

function generateECDHKeypair() {
    return __awaiter$1(this, void 0, void 0, function*() {
        return yield crypto.subtle.generateKey({
            name: "ECDH",
            namedCurve: "P-256"
        }, !1, ["deriveKey", "deriveBits"])
    })
}
const INITIALIZATION_VECTOR_BYTES = 12;

function encryptJsonRpcMessage(e, t) {
    return __awaiter$1(this, void 0, void 0, function*() {
        const o = JSON.stringify(e),
            n = new Uint8Array(INITIALIZATION_VECTOR_BYTES);
        crypto.getRandomValues(n);
        const a = yield crypto.subtle.encrypt(getAlgorithmParams(n), t, Buffer.from(o)), c = new Uint8Array(n.byteLength + a.byteLength);
        return c.set(new Uint8Array(n), 0), c.set(new Uint8Array(a), n.byteLength), c
    })
}

function decryptJsonRpcMessage(e, t) {
    return __awaiter$1(this, void 0, void 0, function*() {
        const o = e.slice(0, INITIALIZATION_VECTOR_BYTES),
            n = e.slice(INITIALIZATION_VECTOR_BYTES),
            a = yield crypto.subtle.decrypt(getAlgorithmParams(o), t, n), c = getUtf8Decoder().decode(a), l = JSON.parse(c);
        if (Object.hasOwnProperty.call(l, "error")) throw new SolanaMobileWalletAdapterProtocolJsonRpcError(l.id, l.error.code, l.error.message);
        return l
    })
}

function getAlgorithmParams(e) {
    return {
        iv: e,
        name: "AES-GCM",
        tagLength: 128
    }
}
let _utf8Decoder;

function getUtf8Decoder() {
    return _utf8Decoder === void 0 && (_utf8Decoder = new TextDecoder("utf-8")), _utf8Decoder
}

function parseHelloRsp(e, t, o) {
    return __awaiter$1(this, void 0, void 0, function*() {
        const [n, a] = yield Promise.all([crypto.subtle.exportKey("raw", t), crypto.subtle.importKey("raw", e, {
            name: "ECDH",
            namedCurve: "P-256"
        }, !1, [])]), c = yield crypto.subtle.deriveBits({
            name: "ECDH",
            public: a
        }, o, 256), l = yield crypto.subtle.importKey("raw", c, "HKDF", !1, ["deriveKey"]);
        return yield crypto.subtle.deriveKey({
            name: "HKDF",
            hash: "SHA-256",
            salt: new Uint8Array(n),
            info: new Uint8Array
        }, l, {
            name: "AES-GCM",
            length: 128
        }, !1, ["encrypt", "decrypt"])
    })
}

function getRandomAssociationPort() {
    return assertAssociationPort(49152 + Math.floor(Math.random() * (65535 - 49152 + 1)))
}

function assertAssociationPort(e) {
    if (e < 49152 || e > 65535) throw new SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError(e);
    return e
}

function arrayBufferToBase64String(e) {
    let t = "";
    const o = new Uint8Array(e),
        n = o.byteLength;
    for (let a = 0; a < n; a++) t += String.fromCharCode(o[a]);
    return window.btoa(t)
}

function getStringWithURLUnsafeCharactersReplaced(e) {
    return e.replace(/[/+=]/g, t => ({
        "/": "_",
        "+": "-",
        "=": "."
    })[t])
}
const INTENT_NAME = "solana-wallet";

function getPathParts(e) {
    return e.replace(/(^\/+|\/+$)/g, "").split("/")
}

function getIntentURL(e, t) {
    let o = null;
    if (t) {
        try {
            o = new URL(t)
        } catch {}
        if ((o == null ? void 0 : o.protocol) !== "https:") throw new SolanaMobileWalletAdapterForbiddenWalletBaseURLError
    }
    o || (o = new URL(`${INTENT_NAME}:/`));
    const n = e.startsWith("/") ? e : [...getPathParts(o.pathname), ...getPathParts(e)].join("/");
    return new URL(n, o)
}

function getAssociateAndroidIntentURL(e, t, o) {
    return __awaiter$1(this, void 0, void 0, function*() {
        const n = assertAssociationPort(t),
            a = yield crypto.subtle.exportKey("raw", e), c = arrayBufferToBase64String(a), l = getIntentURL("v1/associate/local", o);
        return l.searchParams.set("association", getStringWithURLUnsafeCharactersReplaced(c)), l.searchParams.set("port", `${n}`), l
    })
}
const Browser = {
    Firefox: 0,
    Other: 1
};

function assertUnreachable(e) {
    return e
}

function getBrowser() {
    return navigator.userAgent.indexOf("Firefox/") !== -1 ? Browser.Firefox : Browser.Other
}

function getDetectionPromise() {
    return new Promise((e, t) => {
        function o() {
            clearTimeout(a), window.removeEventListener("blur", n)
        }

        function n() {
            o(), e()
        }
        window.addEventListener("blur", n);
        const a = setTimeout(() => {
            o(), t()
        }, 2e3)
    })
}
let _frame = null;

function launchUrlThroughHiddenFrame(e) {
    _frame == null && (_frame = document.createElement("iframe"), _frame.style.display = "none", document.body.appendChild(_frame)), _frame.contentWindow.location.href = e.toString()
}

function startSession(e, t) {
    return __awaiter$1(this, void 0, void 0, function*() {
        const o = getRandomAssociationPort(),
            n = yield getAssociateAndroidIntentURL(e, o, t);
        if (n.protocol === "https:") window.location.assign(n);
        else try {
            const a = getBrowser();
            switch (a) {
                case Browser.Firefox:
                    launchUrlThroughHiddenFrame(n);
                    break;
                case Browser.Other: {
                    const c = getDetectionPromise();
                    window.location.assign(n), yield c;
                    break
                }
                default:
            }
        } catch {
            throw new SolanaMobileWalletAdapterWalletNotInstalledError
        }
        return o
    })
}
const WEBSOCKET_CONNECTION_CONFIG = {
        maxAttempts: 34,
        retryDelayMs: 150
    },
    WEBSOCKET_PROTOCOL = "com.solana.mobilewalletadapter.v1";

function assertSecureContext() {
    if (typeof window == "undefined" || window.isSecureContext !== !0) throw new SolanaMobileWalletAdapterSecureContextRequiredError
}

function withLocalWallet(e, t) {
    return __awaiter$1(this, void 0, void 0, function*() {
        assertSecureContext();
        const o = yield generateAssociationKeypair(), n = yield startSession(o.publicKey, t == null ? void 0 : t.baseUri), a = `ws://localhost:${n}/solana-wallet`;
        let c = 1,
            l = {
                __type: "disconnected"
            };
        return new Promise((m, d) => {
            let g = 0,
                w;
            const S = {},
                C = () => __awaiter$1(this, void 0, void 0, function*() {
                    if (l.__type !== "connecting") {
                        console.warn(`Expected adapter state to be \`connecting\` at the moment the websocket opens. Got \`${l.__type}\`.`);
                        return
                    }
                    const {
                        associationKeypair: B
                    } = l;
                    w.removeEventListener("open", C);
                    const z = yield generateECDHKeypair();
                    w.send(yield createHelloReq(z.publicKey, B.privateKey)), l = {
                        __type: "hello_req_sent",
                        associationPublicKey: B.publicKey,
                        ecdhPrivateKey: z.privateKey
                    }
                }),
                A = B => {
                    B.wasClean ? l = {
                        __type: "disconnected"
                    } : d(new SolanaMobileWalletAdapterProtocolSessionClosedError(B.code, B.reason)), X()
                },
                P = B => __awaiter$1(this, void 0, void 0, function*() {
                    X(), ++g >= WEBSOCKET_CONNECTION_CONFIG.maxAttempts ? d(new SolanaMobileWalletAdapterProtocolSessionEstablishmentError(n)) : (yield new Promise(z => {
                        M = window.setTimeout(z, WEBSOCKET_CONNECTION_CONFIG.retryDelayMs)
                    }), F())
                }),
                G = B => __awaiter$1(this, void 0, void 0, function*() {
                    const z = yield B.data.arrayBuffer();
                    switch (l.__type) {
                        case "connected":
                            try {
                                const V = yield decryptJsonRpcMessage(z, l.sharedSecret), J = S[V.id];
                                delete S[V.id], J.resolve(V.result)
                            } catch (V) {
                                if (V instanceof SolanaMobileWalletAdapterProtocolJsonRpcError) {
                                    const J = S[V.jsonRpcMessageId];
                                    delete S[V.jsonRpcMessageId], J.reject(V)
                                } else throw V
                            }
                            break;
                        case "hello_req_sent": {
                            const V = yield parseHelloRsp(z, l.associationPublicKey, l.ecdhPrivateKey);
                            l = {
                                __type: "connected",
                                sharedSecret: V
                            };
                            const J = (q, Q) => __awaiter$1(this, void 0, void 0, function*() {
                                const at = c++;
                                return w.send(yield encryptJsonRpcMessage({
                                    id: at,
                                    jsonrpc: "2.0",
                                    method: q,
                                    params: Q
                                }, V)), new Promise((pt, _) => {
                                    S[at] = {
                                        resolve: pt,
                                        reject: _
                                    }
                                })
                            });
                            try {
                                m(yield e(J))
                            } catch (q) {
                                d(q)
                            } finally {
                                X(), w.close()
                            }
                            break
                        }
                    }
                });
            let X, M;
            const F = () => {
                X && X(), l = {
                    __type: "connecting",
                    associationKeypair: o
                }, w = new WebSocket(a, [WEBSOCKET_PROTOCOL]), w.addEventListener("open", C), w.addEventListener("close", A), w.addEventListener("error", P), w.addEventListener("message", G), X = () => {
                    window.clearTimeout(M), w.removeEventListener("open", C), w.removeEventListener("close", A), w.removeEventListener("error", P), w.removeEventListener("message", G)
                }
            };
            F()
        })
    })
}
var naclFast = {
        exports: {}
    },
    __viteBrowserExternal = {},
    __viteBrowserExternal$1 = Object.freeze(Object.defineProperty({
        __proto__: null,
        default: __viteBrowserExternal
    }, Symbol.toStringTag, {
        value: "Module"
    })),
    require$$1 = getAugmentedNamespace(__viteBrowserExternal$1);
(function(e) {
    (function(t) {
        var o = function(O) {
                var et, st = new Float64Array(16);
                if (O)
                    for (et = 0; et < O.length; et++) st[et] = O[et];
                return st
            },
            n = function() {
                throw new Error("no PRNG")
            },
            a = new Uint8Array(16),
            c = new Uint8Array(32);
        c[0] = 9;
        var l = o(),
            m = o([1]),
            d = o([56129, 1]),
            g = o([30883, 4953, 19914, 30187, 55467, 16705, 2637, 112, 59544, 30585, 16505, 36039, 65139, 11119, 27886, 20995]),
            w = o([61785, 9906, 39828, 60374, 45398, 33411, 5274, 224, 53552, 61171, 33010, 6542, 64743, 22239, 55772, 9222]),
            S = o([54554, 36645, 11616, 51542, 42930, 38181, 51040, 26924, 56412, 64982, 57905, 49316, 21502, 52590, 14035, 8553]),
            C = o([26200, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214]),
            A = o([41136, 18958, 6951, 50414, 58488, 44335, 6150, 12099, 55207, 15867, 153, 11085, 57099, 20417, 9344, 11139]);

        function P(O, et, st, j) {
            O[et] = st >> 24 & 255, O[et + 1] = st >> 16 & 255, O[et + 2] = st >> 8 & 255, O[et + 3] = st & 255, O[et + 4] = j >> 24 & 255, O[et + 5] = j >> 16 & 255, O[et + 6] = j >> 8 & 255, O[et + 7] = j & 255
        }

        function G(O, et, st, j, nt) {
            var ut, wt = 0;
            for (ut = 0; ut < nt; ut++) wt |= O[et + ut] ^ st[j + ut];
            return (1 & wt - 1 >>> 8) - 1
        }

        function X(O, et, st, j) {
            return G(O, et, st, j, 16)
        }

        function M(O, et, st, j) {
            return G(O, et, st, j, 32)
        }

        function F(O, et, st, j) {
            for (var nt = j[0] & 255 | (j[1] & 255) << 8 | (j[2] & 255) << 16 | (j[3] & 255) << 24, ut = st[0] & 255 | (st[1] & 255) << 8 | (st[2] & 255) << 16 | (st[3] & 255) << 24, wt = st[4] & 255 | (st[5] & 255) << 8 | (st[6] & 255) << 16 | (st[7] & 255) << 24, ft = st[8] & 255 | (st[9] & 255) << 8 | (st[10] & 255) << 16 | (st[11] & 255) << 24, Lt = st[12] & 255 | (st[13] & 255) << 8 | (st[14] & 255) << 16 | (st[15] & 255) << 24, Yt = j[4] & 255 | (j[5] & 255) << 8 | (j[6] & 255) << 16 | (j[7] & 255) << 24, Ht = et[0] & 255 | (et[1] & 255) << 8 | (et[2] & 255) << 16 | (et[3] & 255) << 24, pe = et[4] & 255 | (et[5] & 255) << 8 | (et[6] & 255) << 16 | (et[7] & 255) << 24, qt = et[8] & 255 | (et[9] & 255) << 8 | (et[10] & 255) << 16 | (et[11] & 255) << 24, se = et[12] & 255 | (et[13] & 255) << 8 | (et[14] & 255) << 16 | (et[15] & 255) << 24, oe = j[8] & 255 | (j[9] & 255) << 8 | (j[10] & 255) << 16 | (j[11] & 255) << 24, ne = st[16] & 255 | (st[17] & 255) << 8 | (st[18] & 255) << 16 | (st[19] & 255) << 24, de = st[20] & 255 | (st[21] & 255) << 8 | (st[22] & 255) << 16 | (st[23] & 255) << 24, ie = st[24] & 255 | (st[25] & 255) << 8 | (st[26] & 255) << 16 | (st[27] & 255) << 24, ce = st[28] & 255 | (st[29] & 255) << 8 | (st[30] & 255) << 16 | (st[31] & 255) << 24, re = j[12] & 255 | (j[13] & 255) << 8 | (j[14] & 255) << 16 | (j[15] & 255) << 24, Ot = nt, te = ut, Qt = wt, _t = ft, $t = Lt, Jt = Yt, Ut = Ht, St = pe, Kt = qt, Pt = se, Gt = oe, zt = ne, me = de, ue = ie, we = ce, be = re, dt, ke = 0; ke < 20; ke += 2) dt = Ot + me | 0, $t ^= dt << 7 | dt >>> 32 - 7, dt = $t + Ot | 0, Kt ^= dt << 9 | dt >>> 32 - 9, dt = Kt + $t | 0, me ^= dt << 13 | dt >>> 32 - 13, dt = me + Kt | 0, Ot ^= dt << 18 | dt >>> 32 - 18, dt = Jt + te | 0, Pt ^= dt << 7 | dt >>> 32 - 7, dt = Pt + Jt | 0, ue ^= dt << 9 | dt >>> 32 - 9, dt = ue + Pt | 0, te ^= dt << 13 | dt >>> 32 - 13, dt = te + ue | 0, Jt ^= dt << 18 | dt >>> 32 - 18, dt = Gt + Ut | 0, we ^= dt << 7 | dt >>> 32 - 7, dt = we + Gt | 0, Qt ^= dt << 9 | dt >>> 32 - 9, dt = Qt + we | 0, Ut ^= dt << 13 | dt >>> 32 - 13, dt = Ut + Qt | 0, Gt ^= dt << 18 | dt >>> 32 - 18, dt = be + zt | 0, _t ^= dt << 7 | dt >>> 32 - 7, dt = _t + be | 0, St ^= dt << 9 | dt >>> 32 - 9, dt = St + _t | 0, zt ^= dt << 13 | dt >>> 32 - 13, dt = zt + St | 0, be ^= dt << 18 | dt >>> 32 - 18, dt = Ot + _t | 0, te ^= dt << 7 | dt >>> 32 - 7, dt = te + Ot | 0, Qt ^= dt << 9 | dt >>> 32 - 9, dt = Qt + te | 0, _t ^= dt << 13 | dt >>> 32 - 13, dt = _t + Qt | 0, Ot ^= dt << 18 | dt >>> 32 - 18, dt = Jt + $t | 0, Ut ^= dt << 7 | dt >>> 32 - 7, dt = Ut + Jt | 0, St ^= dt << 9 | dt >>> 32 - 9, dt = St + Ut | 0, $t ^= dt << 13 | dt >>> 32 - 13, dt = $t + St | 0, Jt ^= dt << 18 | dt >>> 32 - 18, dt = Gt + Pt | 0, zt ^= dt << 7 | dt >>> 32 - 7, dt = zt + Gt | 0, Kt ^= dt << 9 | dt >>> 32 - 9, dt = Kt + zt | 0, Pt ^= dt << 13 | dt >>> 32 - 13, dt = Pt + Kt | 0, Gt ^= dt << 18 | dt >>> 32 - 18, dt = be + we | 0, me ^= dt << 7 | dt >>> 32 - 7, dt = me + be | 0, ue ^= dt << 9 | dt >>> 32 - 9, dt = ue + me | 0, we ^= dt << 13 | dt >>> 32 - 13, dt = we + ue | 0, be ^= dt << 18 | dt >>> 32 - 18;
            Ot = Ot + nt | 0, te = te + ut | 0, Qt = Qt + wt | 0, _t = _t + ft | 0, $t = $t + Lt | 0, Jt = Jt + Yt | 0, Ut = Ut + Ht | 0, St = St + pe | 0, Kt = Kt + qt | 0, Pt = Pt + se | 0, Gt = Gt + oe | 0, zt = zt + ne | 0, me = me + de | 0, ue = ue + ie | 0, we = we + ce | 0, be = be + re | 0, O[0] = Ot >>> 0 & 255, O[1] = Ot >>> 8 & 255, O[2] = Ot >>> 16 & 255, O[3] = Ot >>> 24 & 255, O[4] = te >>> 0 & 255, O[5] = te >>> 8 & 255, O[6] = te >>> 16 & 255, O[7] = te >>> 24 & 255, O[8] = Qt >>> 0 & 255, O[9] = Qt >>> 8 & 255, O[10] = Qt >>> 16 & 255, O[11] = Qt >>> 24 & 255, O[12] = _t >>> 0 & 255, O[13] = _t >>> 8 & 255, O[14] = _t >>> 16 & 255, O[15] = _t >>> 24 & 255, O[16] = $t >>> 0 & 255, O[17] = $t >>> 8 & 255, O[18] = $t >>> 16 & 255, O[19] = $t >>> 24 & 255, O[20] = Jt >>> 0 & 255, O[21] = Jt >>> 8 & 255, O[22] = Jt >>> 16 & 255, O[23] = Jt >>> 24 & 255, O[24] = Ut >>> 0 & 255, O[25] = Ut >>> 8 & 255, O[26] = Ut >>> 16 & 255, O[27] = Ut >>> 24 & 255, O[28] = St >>> 0 & 255, O[29] = St >>> 8 & 255, O[30] = St >>> 16 & 255, O[31] = St >>> 24 & 255, O[32] = Kt >>> 0 & 255, O[33] = Kt >>> 8 & 255, O[34] = Kt >>> 16 & 255, O[35] = Kt >>> 24 & 255, O[36] = Pt >>> 0 & 255, O[37] = Pt >>> 8 & 255, O[38] = Pt >>> 16 & 255, O[39] = Pt >>> 24 & 255, O[40] = Gt >>> 0 & 255, O[41] = Gt >>> 8 & 255, O[42] = Gt >>> 16 & 255, O[43] = Gt >>> 24 & 255, O[44] = zt >>> 0 & 255, O[45] = zt >>> 8 & 255, O[46] = zt >>> 16 & 255, O[47] = zt >>> 24 & 255, O[48] = me >>> 0 & 255, O[49] = me >>> 8 & 255, O[50] = me >>> 16 & 255, O[51] = me >>> 24 & 255, O[52] = ue >>> 0 & 255, O[53] = ue >>> 8 & 255, O[54] = ue >>> 16 & 255, O[55] = ue >>> 24 & 255, O[56] = we >>> 0 & 255, O[57] = we >>> 8 & 255, O[58] = we >>> 16 & 255, O[59] = we >>> 24 & 255, O[60] = be >>> 0 & 255, O[61] = be >>> 8 & 255, O[62] = be >>> 16 & 255, O[63] = be >>> 24 & 255
        }

        function B(O, et, st, j) {
            for (var nt = j[0] & 255 | (j[1] & 255) << 8 | (j[2] & 255) << 16 | (j[3] & 255) << 24, ut = st[0] & 255 | (st[1] & 255) << 8 | (st[2] & 255) << 16 | (st[3] & 255) << 24, wt = st[4] & 255 | (st[5] & 255) << 8 | (st[6] & 255) << 16 | (st[7] & 255) << 24, ft = st[8] & 255 | (st[9] & 255) << 8 | (st[10] & 255) << 16 | (st[11] & 255) << 24, Lt = st[12] & 255 | (st[13] & 255) << 8 | (st[14] & 255) << 16 | (st[15] & 255) << 24, Yt = j[4] & 255 | (j[5] & 255) << 8 | (j[6] & 255) << 16 | (j[7] & 255) << 24, Ht = et[0] & 255 | (et[1] & 255) << 8 | (et[2] & 255) << 16 | (et[3] & 255) << 24, pe = et[4] & 255 | (et[5] & 255) << 8 | (et[6] & 255) << 16 | (et[7] & 255) << 24, qt = et[8] & 255 | (et[9] & 255) << 8 | (et[10] & 255) << 16 | (et[11] & 255) << 24, se = et[12] & 255 | (et[13] & 255) << 8 | (et[14] & 255) << 16 | (et[15] & 255) << 24, oe = j[8] & 255 | (j[9] & 255) << 8 | (j[10] & 255) << 16 | (j[11] & 255) << 24, ne = st[16] & 255 | (st[17] & 255) << 8 | (st[18] & 255) << 16 | (st[19] & 255) << 24, de = st[20] & 255 | (st[21] & 255) << 8 | (st[22] & 255) << 16 | (st[23] & 255) << 24, ie = st[24] & 255 | (st[25] & 255) << 8 | (st[26] & 255) << 16 | (st[27] & 255) << 24, ce = st[28] & 255 | (st[29] & 255) << 8 | (st[30] & 255) << 16 | (st[31] & 255) << 24, re = j[12] & 255 | (j[13] & 255) << 8 | (j[14] & 255) << 16 | (j[15] & 255) << 24, Ot = nt, te = ut, Qt = wt, _t = ft, $t = Lt, Jt = Yt, Ut = Ht, St = pe, Kt = qt, Pt = se, Gt = oe, zt = ne, me = de, ue = ie, we = ce, be = re, dt, ke = 0; ke < 20; ke += 2) dt = Ot + me | 0, $t ^= dt << 7 | dt >>> 32 - 7, dt = $t + Ot | 0, Kt ^= dt << 9 | dt >>> 32 - 9, dt = Kt + $t | 0, me ^= dt << 13 | dt >>> 32 - 13, dt = me + Kt | 0, Ot ^= dt << 18 | dt >>> 32 - 18, dt = Jt + te | 0, Pt ^= dt << 7 | dt >>> 32 - 7, dt = Pt + Jt | 0, ue ^= dt << 9 | dt >>> 32 - 9, dt = ue + Pt | 0, te ^= dt << 13 | dt >>> 32 - 13, dt = te + ue | 0, Jt ^= dt << 18 | dt >>> 32 - 18, dt = Gt + Ut | 0, we ^= dt << 7 | dt >>> 32 - 7, dt = we + Gt | 0, Qt ^= dt << 9 | dt >>> 32 - 9, dt = Qt + we | 0, Ut ^= dt << 13 | dt >>> 32 - 13, dt = Ut + Qt | 0, Gt ^= dt << 18 | dt >>> 32 - 18, dt = be + zt | 0, _t ^= dt << 7 | dt >>> 32 - 7, dt = _t + be | 0, St ^= dt << 9 | dt >>> 32 - 9, dt = St + _t | 0, zt ^= dt << 13 | dt >>> 32 - 13, dt = zt + St | 0, be ^= dt << 18 | dt >>> 32 - 18, dt = Ot + _t | 0, te ^= dt << 7 | dt >>> 32 - 7, dt = te + Ot | 0, Qt ^= dt << 9 | dt >>> 32 - 9, dt = Qt + te | 0, _t ^= dt << 13 | dt >>> 32 - 13, dt = _t + Qt | 0, Ot ^= dt << 18 | dt >>> 32 - 18, dt = Jt + $t | 0, Ut ^= dt << 7 | dt >>> 32 - 7, dt = Ut + Jt | 0, St ^= dt << 9 | dt >>> 32 - 9, dt = St + Ut | 0, $t ^= dt << 13 | dt >>> 32 - 13, dt = $t + St | 0, Jt ^= dt << 18 | dt >>> 32 - 18, dt = Gt + Pt | 0, zt ^= dt << 7 | dt >>> 32 - 7, dt = zt + Gt | 0, Kt ^= dt << 9 | dt >>> 32 - 9, dt = Kt + zt | 0, Pt ^= dt << 13 | dt >>> 32 - 13, dt = Pt + Kt | 0, Gt ^= dt << 18 | dt >>> 32 - 18, dt = be + we | 0, me ^= dt << 7 | dt >>> 32 - 7, dt = me + be | 0, ue ^= dt << 9 | dt >>> 32 - 9, dt = ue + me | 0, we ^= dt << 13 | dt >>> 32 - 13, dt = we + ue | 0, be ^= dt << 18 | dt >>> 32 - 18;
            O[0] = Ot >>> 0 & 255, O[1] = Ot >>> 8 & 255, O[2] = Ot >>> 16 & 255, O[3] = Ot >>> 24 & 255, O[4] = Jt >>> 0 & 255, O[5] = Jt >>> 8 & 255, O[6] = Jt >>> 16 & 255, O[7] = Jt >>> 24 & 255, O[8] = Gt >>> 0 & 255, O[9] = Gt >>> 8 & 255, O[10] = Gt >>> 16 & 255, O[11] = Gt >>> 24 & 255, O[12] = be >>> 0 & 255, O[13] = be >>> 8 & 255, O[14] = be >>> 16 & 255, O[15] = be >>> 24 & 255, O[16] = Ut >>> 0 & 255, O[17] = Ut >>> 8 & 255, O[18] = Ut >>> 16 & 255, O[19] = Ut >>> 24 & 255, O[20] = St >>> 0 & 255, O[21] = St >>> 8 & 255, O[22] = St >>> 16 & 255, O[23] = St >>> 24 & 255, O[24] = Kt >>> 0 & 255, O[25] = Kt >>> 8 & 255, O[26] = Kt >>> 16 & 255, O[27] = Kt >>> 24 & 255, O[28] = Pt >>> 0 & 255, O[29] = Pt >>> 8 & 255, O[30] = Pt >>> 16 & 255, O[31] = Pt >>> 24 & 255
        }

        function z(O, et, st, j) {
            F(O, et, st, j)
        }

        function V(O, et, st, j) {
            B(O, et, st, j)
        }
        var J = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);

        function q(O, et, st, j, nt, ut, wt) {
            var ft = new Uint8Array(16),
                Lt = new Uint8Array(64),
                Yt, Ht;
            for (Ht = 0; Ht < 16; Ht++) ft[Ht] = 0;
            for (Ht = 0; Ht < 8; Ht++) ft[Ht] = ut[Ht];
            for (; nt >= 64;) {
                for (z(Lt, ft, wt, J), Ht = 0; Ht < 64; Ht++) O[et + Ht] = st[j + Ht] ^ Lt[Ht];
                for (Yt = 1, Ht = 8; Ht < 16; Ht++) Yt = Yt + (ft[Ht] & 255) | 0, ft[Ht] = Yt & 255, Yt >>>= 8;
                nt -= 64, et += 64, j += 64
            }
            if (nt > 0)
                for (z(Lt, ft, wt, J), Ht = 0; Ht < nt; Ht++) O[et + Ht] = st[j + Ht] ^ Lt[Ht];
            return 0
        }

        function Q(O, et, st, j, nt) {
            var ut = new Uint8Array(16),
                wt = new Uint8Array(64),
                ft, Lt;
            for (Lt = 0; Lt < 16; Lt++) ut[Lt] = 0;
            for (Lt = 0; Lt < 8; Lt++) ut[Lt] = j[Lt];
            for (; st >= 64;) {
                for (z(wt, ut, nt, J), Lt = 0; Lt < 64; Lt++) O[et + Lt] = wt[Lt];
                for (ft = 1, Lt = 8; Lt < 16; Lt++) ft = ft + (ut[Lt] & 255) | 0, ut[Lt] = ft & 255, ft >>>= 8;
                st -= 64, et += 64
            }
            if (st > 0)
                for (z(wt, ut, nt, J), Lt = 0; Lt < st; Lt++) O[et + Lt] = wt[Lt];
            return 0
        }

        function at(O, et, st, j, nt) {
            var ut = new Uint8Array(32);
            V(ut, j, nt, J);
            for (var wt = new Uint8Array(8), ft = 0; ft < 8; ft++) wt[ft] = j[ft + 16];
            return Q(O, et, st, wt, ut)
        }

        function pt(O, et, st, j, nt, ut, wt) {
            var ft = new Uint8Array(32);
            V(ft, ut, wt, J);
            for (var Lt = new Uint8Array(8), Yt = 0; Yt < 8; Yt++) Lt[Yt] = ut[Yt + 16];
            return q(O, et, st, j, nt, Lt, ft)
        }
        var _ = function(O) {
            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;
            var et, st, j, nt, ut, wt, ft, Lt;
            et = O[0] & 255 | (O[1] & 255) << 8, this.r[0] = et & 8191, st = O[2] & 255 | (O[3] & 255) << 8, this.r[1] = (et >>> 13 | st << 3) & 8191, j = O[4] & 255 | (O[5] & 255) << 8, this.r[2] = (st >>> 10 | j << 6) & 7939, nt = O[6] & 255 | (O[7] & 255) << 8, this.r[3] = (j >>> 7 | nt << 9) & 8191, ut = O[8] & 255 | (O[9] & 255) << 8, this.r[4] = (nt >>> 4 | ut << 12) & 255, this.r[5] = ut >>> 1 & 8190, wt = O[10] & 255 | (O[11] & 255) << 8, this.r[6] = (ut >>> 14 | wt << 2) & 8191, ft = O[12] & 255 | (O[13] & 255) << 8, this.r[7] = (wt >>> 11 | ft << 5) & 8065, Lt = O[14] & 255 | (O[15] & 255) << 8, this.r[8] = (ft >>> 8 | Lt << 8) & 8191, this.r[9] = Lt >>> 5 & 127, this.pad[0] = O[16] & 255 | (O[17] & 255) << 8, this.pad[1] = O[18] & 255 | (O[19] & 255) << 8, this.pad[2] = O[20] & 255 | (O[21] & 255) << 8, this.pad[3] = O[22] & 255 | (O[23] & 255) << 8, this.pad[4] = O[24] & 255 | (O[25] & 255) << 8, this.pad[5] = O[26] & 255 | (O[27] & 255) << 8, this.pad[6] = O[28] & 255 | (O[29] & 255) << 8, this.pad[7] = O[30] & 255 | (O[31] & 255) << 8
        };
        _.prototype.blocks = function(O, et, st) {
            for (var j = this.fin ? 0 : 2048, nt, ut, wt, ft, Lt, Yt, Ht, pe, qt, se, oe, ne, de, ie, ce, re, Ot, te, Qt, _t = this.h[0], $t = this.h[1], Jt = this.h[2], Ut = this.h[3], St = this.h[4], Kt = this.h[5], Pt = this.h[6], Gt = this.h[7], zt = this.h[8], me = this.h[9], ue = this.r[0], we = this.r[1], be = this.r[2], dt = this.r[3], ke = this.r[4], Ue = this.r[5], Te = this.r[6], ye = this.r[7], Ie = this.r[8], Ce = this.r[9]; st >= 16;) nt = O[et + 0] & 255 | (O[et + 1] & 255) << 8, _t += nt & 8191, ut = O[et + 2] & 255 | (O[et + 3] & 255) << 8, $t += (nt >>> 13 | ut << 3) & 8191, wt = O[et + 4] & 255 | (O[et + 5] & 255) << 8, Jt += (ut >>> 10 | wt << 6) & 8191, ft = O[et + 6] & 255 | (O[et + 7] & 255) << 8, Ut += (wt >>> 7 | ft << 9) & 8191, Lt = O[et + 8] & 255 | (O[et + 9] & 255) << 8, St += (ft >>> 4 | Lt << 12) & 8191, Kt += Lt >>> 1 & 8191, Yt = O[et + 10] & 255 | (O[et + 11] & 255) << 8, Pt += (Lt >>> 14 | Yt << 2) & 8191, Ht = O[et + 12] & 255 | (O[et + 13] & 255) << 8, Gt += (Yt >>> 11 | Ht << 5) & 8191, pe = O[et + 14] & 255 | (O[et + 15] & 255) << 8, zt += (Ht >>> 8 | pe << 8) & 8191, me += pe >>> 5 | j, qt = 0, se = qt, se += _t * ue, se += $t * (5 * Ce), se += Jt * (5 * Ie), se += Ut * (5 * ye), se += St * (5 * Te), qt = se >>> 13, se &= 8191, se += Kt * (5 * Ue), se += Pt * (5 * ke), se += Gt * (5 * dt), se += zt * (5 * be), se += me * (5 * we), qt += se >>> 13, se &= 8191, oe = qt, oe += _t * we, oe += $t * ue, oe += Jt * (5 * Ce), oe += Ut * (5 * Ie), oe += St * (5 * ye), qt = oe >>> 13, oe &= 8191, oe += Kt * (5 * Te), oe += Pt * (5 * Ue), oe += Gt * (5 * ke), oe += zt * (5 * dt), oe += me * (5 * be), qt += oe >>> 13, oe &= 8191, ne = qt, ne += _t * be, ne += $t * we, ne += Jt * ue, ne += Ut * (5 * Ce), ne += St * (5 * Ie), qt = ne >>> 13, ne &= 8191, ne += Kt * (5 * ye), ne += Pt * (5 * Te), ne += Gt * (5 * Ue), ne += zt * (5 * ke), ne += me * (5 * dt), qt += ne >>> 13, ne &= 8191, de = qt, de += _t * dt, de += $t * be, de += Jt * we, de += Ut * ue, de += St * (5 * Ce), qt = de >>> 13, de &= 8191, de += Kt * (5 * Ie), de += Pt * (5 * ye), de += Gt * (5 * Te), de += zt * (5 * Ue), de += me * (5 * ke), qt += de >>> 13, de &= 8191, ie = qt, ie += _t * ke, ie += $t * dt, ie += Jt * be, ie += Ut * we, ie += St * ue, qt = ie >>> 13, ie &= 8191, ie += Kt * (5 * Ce), ie += Pt * (5 * Ie), ie += Gt * (5 * ye), ie += zt * (5 * Te), ie += me * (5 * Ue), qt += ie >>> 13, ie &= 8191, ce = qt, ce += _t * Ue, ce += $t * ke, ce += Jt * dt, ce += Ut * be, ce += St * we, qt = ce >>> 13, ce &= 8191, ce += Kt * ue, ce += Pt * (5 * Ce), ce += Gt * (5 * Ie), ce += zt * (5 * ye), ce += me * (5 * Te), qt += ce >>> 13, ce &= 8191, re = qt, re += _t * Te, re += $t * Ue, re += Jt * ke, re += Ut * dt, re += St * be, qt = re >>> 13, re &= 8191, re += Kt * we, re += Pt * ue, re += Gt * (5 * Ce), re += zt * (5 * Ie), re += me * (5 * ye), qt += re >>> 13, re &= 8191, Ot = qt, Ot += _t * ye, Ot += $t * Te, Ot += Jt * Ue, Ot += Ut * ke, Ot += St * dt, qt = Ot >>> 13, Ot &= 8191, Ot += Kt * be, Ot += Pt * we, Ot += Gt * ue, Ot += zt * (5 * Ce), Ot += me * (5 * Ie), qt += Ot >>> 13, Ot &= 8191, te = qt, te += _t * Ie, te += $t * ye, te += Jt * Te, te += Ut * Ue, te += St * ke, qt = te >>> 13, te &= 8191, te += Kt * dt, te += Pt * be, te += Gt * we, te += zt * ue, te += me * (5 * Ce), qt += te >>> 13, te &= 8191, Qt = qt, Qt += _t * Ce, Qt += $t * Ie, Qt += Jt * ye, Qt += Ut * Te, Qt += St * Ue, qt = Qt >>> 13, Qt &= 8191, Qt += Kt * ke, Qt += Pt * dt, Qt += Gt * be, Qt += zt * we, Qt += me * ue, qt += Qt >>> 13, Qt &= 8191, qt = (qt << 2) + qt | 0, qt = qt + se | 0, se = qt & 8191, qt = qt >>> 13, oe += qt, _t = se, $t = oe, Jt = ne, Ut = de, St = ie, Kt = ce, Pt = re, Gt = Ot, zt = te, me = Qt, et += 16, st -= 16;
            this.h[0] = _t, this.h[1] = $t, this.h[2] = Jt, this.h[3] = Ut, this.h[4] = St, this.h[5] = Kt, this.h[6] = Pt, this.h[7] = Gt, this.h[8] = zt, this.h[9] = me
        }, _.prototype.finish = function(O, et) {
            var st = new Uint16Array(10),
                j, nt, ut, wt;
            if (this.leftover) {
                for (wt = this.leftover, this.buffer[wt++] = 1; wt < 16; wt++) this.buffer[wt] = 0;
                this.fin = 1, this.blocks(this.buffer, 0, 16)
            }
            for (j = this.h[1] >>> 13, this.h[1] &= 8191, wt = 2; wt < 10; wt++) this.h[wt] += j, j = this.h[wt] >>> 13, this.h[wt] &= 8191;
            for (this.h[0] += j * 5, j = this.h[0] >>> 13, this.h[0] &= 8191, this.h[1] += j, j = this.h[1] >>> 13, this.h[1] &= 8191, this.h[2] += j, st[0] = this.h[0] + 5, j = st[0] >>> 13, st[0] &= 8191, wt = 1; wt < 10; wt++) st[wt] = this.h[wt] + j, j = st[wt] >>> 13, st[wt] &= 8191;
            for (st[9] -= 1 << 13, nt = (j ^ 1) - 1, wt = 0; wt < 10; wt++) st[wt] &= nt;
            for (nt = ~nt, wt = 0; wt < 10; wt++) this.h[wt] = this.h[wt] & nt | st[wt];
            for (this.h[0] = (this.h[0] | this.h[1] << 13) & 65535, this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535, this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535, this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535, this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535, this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535, this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535, this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535, ut = this.h[0] + this.pad[0], this.h[0] = ut & 65535, wt = 1; wt < 8; wt++) ut = (this.h[wt] + this.pad[wt] | 0) + (ut >>> 16) | 0, this.h[wt] = ut & 65535;
            O[et + 0] = this.h[0] >>> 0 & 255, O[et + 1] = this.h[0] >>> 8 & 255, O[et + 2] = this.h[1] >>> 0 & 255, O[et + 3] = this.h[1] >>> 8 & 255, O[et + 4] = this.h[2] >>> 0 & 255, O[et + 5] = this.h[2] >>> 8 & 255, O[et + 6] = this.h[3] >>> 0 & 255, O[et + 7] = this.h[3] >>> 8 & 255, O[et + 8] = this.h[4] >>> 0 & 255, O[et + 9] = this.h[4] >>> 8 & 255, O[et + 10] = this.h[5] >>> 0 & 255, O[et + 11] = this.h[5] >>> 8 & 255, O[et + 12] = this.h[6] >>> 0 & 255, O[et + 13] = this.h[6] >>> 8 & 255, O[et + 14] = this.h[7] >>> 0 & 255, O[et + 15] = this.h[7] >>> 8 & 255
        }, _.prototype.update = function(O, et, st) {
            var j, nt;
            if (this.leftover) {
                for (nt = 16 - this.leftover, nt > st && (nt = st), j = 0; j < nt; j++) this.buffer[this.leftover + j] = O[et + j];
                if (st -= nt, et += nt, this.leftover += nt, this.leftover < 16) return;
                this.blocks(this.buffer, 0, 16), this.leftover = 0
            }
            if (st >= 16 && (nt = st - st % 16, this.blocks(O, et, nt), et += nt, st -= nt), st) {
                for (j = 0; j < st; j++) this.buffer[this.leftover + j] = O[et + j];
                this.leftover += st
            }
        };

        function k(O, et, st, j, nt, ut) {
            var wt = new _(ut);
            return wt.update(st, j, nt), wt.finish(O, et), 0
        }

        function U(O, et, st, j, nt, ut) {
            var wt = new Uint8Array(16);
            return k(wt, 0, st, j, nt, ut), X(O, et, wt, 0)
        }

        function b(O, et, st, j, nt) {
            var ut;
            if (st < 32) return -1;
            for (pt(O, 0, et, 0, st, j, nt), k(O, 16, O, 32, st - 32, O), ut = 0; ut < 16; ut++) O[ut] = 0;
            return 0
        }

        function T(O, et, st, j, nt) {
            var ut, wt = new Uint8Array(32);
            if (st < 32 || (at(wt, 0, 32, j, nt), U(et, 16, et, 32, st - 32, wt) !== 0)) return -1;
            for (pt(O, 0, et, 0, st, j, nt), ut = 0; ut < 32; ut++) O[ut] = 0;
            return 0
        }

        function x(O, et) {
            var st;
            for (st = 0; st < 16; st++) O[st] = et[st] | 0
        }

        function v(O) {
            var et, st, j = 1;
            for (et = 0; et < 16; et++) st = O[et] + j + 65535, j = Math.floor(st / 65536), O[et] = st - j * 65536;
            O[0] += j - 1 + 37 * (j - 1)
        }

        function E(O, et, st) {
            for (var j, nt = ~(st - 1), ut = 0; ut < 16; ut++) j = nt & (O[ut] ^ et[ut]), O[ut] ^= j, et[ut] ^= j
        }

        function N(O, et) {
            var st, j, nt, ut = o(),
                wt = o();
            for (st = 0; st < 16; st++) wt[st] = et[st];
            for (v(wt), v(wt), v(wt), j = 0; j < 2; j++) {
                for (ut[0] = wt[0] - 65517, st = 1; st < 15; st++) ut[st] = wt[st] - 65535 - (ut[st - 1] >> 16 & 1), ut[st - 1] &= 65535;
                ut[15] = wt[15] - 32767 - (ut[14] >> 16 & 1), nt = ut[15] >> 16 & 1, ut[14] &= 65535, E(wt, ut, 1 - nt)
            }
            for (st = 0; st < 16; st++) O[2 * st] = wt[st] & 255, O[2 * st + 1] = wt[st] >> 8
        }

        function D(O, et) {
            var st = new Uint8Array(32),
                j = new Uint8Array(32);
            return N(st, O), N(j, et), M(st, 0, j, 0)
        }

        function W(O) {
            var et = new Uint8Array(32);
            return N(et, O), et[0] & 1
        }

        function H(O, et) {
            var st;
            for (st = 0; st < 16; st++) O[st] = et[2 * st] + (et[2 * st + 1] << 8);
            O[15] &= 32767
        }

        function tt(O, et, st) {
            for (var j = 0; j < 16; j++) O[j] = et[j] + st[j]
        }

        function bt(O, et, st) {
            for (var j = 0; j < 16; j++) O[j] = et[j] - st[j]
        }

        function Y(O, et, st) {
            var j, nt, ut = 0,
                wt = 0,
                ft = 0,
                Lt = 0,
                Yt = 0,
                Ht = 0,
                pe = 0,
                qt = 0,
                se = 0,
                oe = 0,
                ne = 0,
                de = 0,
                ie = 0,
                ce = 0,
                re = 0,
                Ot = 0,
                te = 0,
                Qt = 0,
                _t = 0,
                $t = 0,
                Jt = 0,
                Ut = 0,
                St = 0,
                Kt = 0,
                Pt = 0,
                Gt = 0,
                zt = 0,
                me = 0,
                ue = 0,
                we = 0,
                be = 0,
                dt = st[0],
                ke = st[1],
                Ue = st[2],
                Te = st[3],
                ye = st[4],
                Ie = st[5],
                Ce = st[6],
                Fe = st[7],
                Le = st[8],
                Be = st[9],
                Pe = st[10],
                Ne = st[11],
                Ge = st[12],
                Ke = st[13],
                We = st[14],
                He = st[15];
            j = et[0], ut += j * dt, wt += j * ke, ft += j * Ue, Lt += j * Te, Yt += j * ye, Ht += j * Ie, pe += j * Ce, qt += j * Fe, se += j * Le, oe += j * Be, ne += j * Pe, de += j * Ne, ie += j * Ge, ce += j * Ke, re += j * We, Ot += j * He, j = et[1], wt += j * dt, ft += j * ke, Lt += j * Ue, Yt += j * Te, Ht += j * ye, pe += j * Ie, qt += j * Ce, se += j * Fe, oe += j * Le, ne += j * Be, de += j * Pe, ie += j * Ne, ce += j * Ge, re += j * Ke, Ot += j * We, te += j * He, j = et[2], ft += j * dt, Lt += j * ke, Yt += j * Ue, Ht += j * Te, pe += j * ye, qt += j * Ie, se += j * Ce, oe += j * Fe, ne += j * Le, de += j * Be, ie += j * Pe, ce += j * Ne, re += j * Ge, Ot += j * Ke, te += j * We, Qt += j * He, j = et[3], Lt += j * dt, Yt += j * ke, Ht += j * Ue, pe += j * Te, qt += j * ye, se += j * Ie, oe += j * Ce, ne += j * Fe, de += j * Le, ie += j * Be, ce += j * Pe, re += j * Ne, Ot += j * Ge, te += j * Ke, Qt += j * We, _t += j * He, j = et[4], Yt += j * dt, Ht += j * ke, pe += j * Ue, qt += j * Te, se += j * ye, oe += j * Ie, ne += j * Ce, de += j * Fe, ie += j * Le, ce += j * Be, re += j * Pe, Ot += j * Ne, te += j * Ge, Qt += j * Ke, _t += j * We, $t += j * He, j = et[5], Ht += j * dt, pe += j * ke, qt += j * Ue, se += j * Te, oe += j * ye, ne += j * Ie, de += j * Ce, ie += j * Fe, ce += j * Le, re += j * Be, Ot += j * Pe, te += j * Ne, Qt += j * Ge, _t += j * Ke, $t += j * We, Jt += j * He, j = et[6], pe += j * dt, qt += j * ke, se += j * Ue, oe += j * Te, ne += j * ye, de += j * Ie, ie += j * Ce, ce += j * Fe, re += j * Le, Ot += j * Be, te += j * Pe, Qt += j * Ne, _t += j * Ge, $t += j * Ke, Jt += j * We, Ut += j * He, j = et[7], qt += j * dt, se += j * ke, oe += j * Ue, ne += j * Te, de += j * ye, ie += j * Ie, ce += j * Ce, re += j * Fe, Ot += j * Le, te += j * Be, Qt += j * Pe, _t += j * Ne, $t += j * Ge, Jt += j * Ke, Ut += j * We, St += j * He, j = et[8], se += j * dt, oe += j * ke, ne += j * Ue, de += j * Te, ie += j * ye, ce += j * Ie, re += j * Ce, Ot += j * Fe, te += j * Le, Qt += j * Be, _t += j * Pe, $t += j * Ne, Jt += j * Ge, Ut += j * Ke, St += j * We, Kt += j * He, j = et[9], oe += j * dt, ne += j * ke, de += j * Ue, ie += j * Te, ce += j * ye, re += j * Ie, Ot += j * Ce, te += j * Fe, Qt += j * Le, _t += j * Be, $t += j * Pe, Jt += j * Ne, Ut += j * Ge, St += j * Ke, Kt += j * We, Pt += j * He, j = et[10], ne += j * dt, de += j * ke, ie += j * Ue, ce += j * Te, re += j * ye, Ot += j * Ie, te += j * Ce, Qt += j * Fe, _t += j * Le, $t += j * Be, Jt += j * Pe, Ut += j * Ne, St += j * Ge, Kt += j * Ke, Pt += j * We, Gt += j * He, j = et[11], de += j * dt, ie += j * ke, ce += j * Ue, re += j * Te, Ot += j * ye, te += j * Ie, Qt += j * Ce, _t += j * Fe, $t += j * Le, Jt += j * Be, Ut += j * Pe, St += j * Ne, Kt += j * Ge, Pt += j * Ke, Gt += j * We, zt += j * He, j = et[12], ie += j * dt, ce += j * ke, re += j * Ue, Ot += j * Te, te += j * ye, Qt += j * Ie, _t += j * Ce, $t += j * Fe, Jt += j * Le, Ut += j * Be, St += j * Pe, Kt += j * Ne, Pt += j * Ge, Gt += j * Ke, zt += j * We, me += j * He, j = et[13], ce += j * dt, re += j * ke, Ot += j * Ue, te += j * Te, Qt += j * ye, _t += j * Ie, $t += j * Ce, Jt += j * Fe, Ut += j * Le, St += j * Be, Kt += j * Pe, Pt += j * Ne, Gt += j * Ge, zt += j * Ke, me += j * We, ue += j * He, j = et[14], re += j * dt, Ot += j * ke, te += j * Ue, Qt += j * Te, _t += j * ye, $t += j * Ie, Jt += j * Ce, Ut += j * Fe, St += j * Le, Kt += j * Be, Pt += j * Pe, Gt += j * Ne, zt += j * Ge, me += j * Ke, ue += j * We, we += j * He, j = et[15], Ot += j * dt, te += j * ke, Qt += j * Ue, _t += j * Te, $t += j * ye, Jt += j * Ie, Ut += j * Ce, St += j * Fe, Kt += j * Le, Pt += j * Be, Gt += j * Pe, zt += j * Ne, me += j * Ge, ue += j * Ke, we += j * We, be += j * He, ut += 38 * te, wt += 38 * Qt, ft += 38 * _t, Lt += 38 * $t, Yt += 38 * Jt, Ht += 38 * Ut, pe += 38 * St, qt += 38 * Kt, se += 38 * Pt, oe += 38 * Gt, ne += 38 * zt, de += 38 * me, ie += 38 * ue, ce += 38 * we, re += 38 * be, nt = 1, j = ut + nt + 65535, nt = Math.floor(j / 65536), ut = j - nt * 65536, j = wt + nt + 65535, nt = Math.floor(j / 65536), wt = j - nt * 65536, j = ft + nt + 65535, nt = Math.floor(j / 65536), ft = j - nt * 65536, j = Lt + nt + 65535, nt = Math.floor(j / 65536), Lt = j - nt * 65536, j = Yt + nt + 65535, nt = Math.floor(j / 65536), Yt = j - nt * 65536, j = Ht + nt + 65535, nt = Math.floor(j / 65536), Ht = j - nt * 65536, j = pe + nt + 65535, nt = Math.floor(j / 65536), pe = j - nt * 65536, j = qt + nt + 65535, nt = Math.floor(j / 65536), qt = j - nt * 65536, j = se + nt + 65535, nt = Math.floor(j / 65536), se = j - nt * 65536, j = oe + nt + 65535, nt = Math.floor(j / 65536), oe = j - nt * 65536, j = ne + nt + 65535, nt = Math.floor(j / 65536), ne = j - nt * 65536, j = de + nt + 65535, nt = Math.floor(j / 65536), de = j - nt * 65536, j = ie + nt + 65535, nt = Math.floor(j / 65536), ie = j - nt * 65536, j = ce + nt + 65535, nt = Math.floor(j / 65536), ce = j - nt * 65536, j = re + nt + 65535, nt = Math.floor(j / 65536), re = j - nt * 65536, j = Ot + nt + 65535, nt = Math.floor(j / 65536), Ot = j - nt * 65536, ut += nt - 1 + 37 * (nt - 1), nt = 1, j = ut + nt + 65535, nt = Math.floor(j / 65536), ut = j - nt * 65536, j = wt + nt + 65535, nt = Math.floor(j / 65536), wt = j - nt * 65536, j = ft + nt + 65535, nt = Math.floor(j / 65536), ft = j - nt * 65536, j = Lt + nt + 65535, nt = Math.floor(j / 65536), Lt = j - nt * 65536, j = Yt + nt + 65535, nt = Math.floor(j / 65536), Yt = j - nt * 65536, j = Ht + nt + 65535, nt = Math.floor(j / 65536), Ht = j - nt * 65536, j = pe + nt + 65535, nt = Math.floor(j / 65536), pe = j - nt * 65536, j = qt + nt + 65535, nt = Math.floor(j / 65536), qt = j - nt * 65536, j = se + nt + 65535, nt = Math.floor(j / 65536), se = j - nt * 65536, j = oe + nt + 65535, nt = Math.floor(j / 65536), oe = j - nt * 65536, j = ne + nt + 65535, nt = Math.floor(j / 65536), ne = j - nt * 65536, j = de + nt + 65535, nt = Math.floor(j / 65536), de = j - nt * 65536, j = ie + nt + 65535, nt = Math.floor(j / 65536), ie = j - nt * 65536, j = ce + nt + 65535, nt = Math.floor(j / 65536), ce = j - nt * 65536, j = re + nt + 65535, nt = Math.floor(j / 65536), re = j - nt * 65536, j = Ot + nt + 65535, nt = Math.floor(j / 65536), Ot = j - nt * 65536, ut += nt - 1 + 37 * (nt - 1), O[0] = ut, O[1] = wt, O[2] = ft, O[3] = Lt, O[4] = Yt, O[5] = Ht, O[6] = pe, O[7] = qt, O[8] = se, O[9] = oe, O[10] = ne, O[11] = de, O[12] = ie, O[13] = ce, O[14] = re, O[15] = Ot
        }

        function ct(O, et) {
            Y(O, et, et)
        }

        function mt(O, et) {
            var st = o(),
                j;
            for (j = 0; j < 16; j++) st[j] = et[j];
            for (j = 253; j >= 0; j--) ct(st, st), j !== 2 && j !== 4 && Y(st, st, et);
            for (j = 0; j < 16; j++) O[j] = st[j]
        }

        function ht(O, et) {
            var st = o(),
                j;
            for (j = 0; j < 16; j++) st[j] = et[j];
            for (j = 250; j >= 0; j--) ct(st, st), j !== 1 && Y(st, st, et);
            for (j = 0; j < 16; j++) O[j] = st[j]
        }

        function yt(O, et, st) {
            var j = new Uint8Array(32),
                nt = new Float64Array(80),
                ut, wt, ft = o(),
                Lt = o(),
                Yt = o(),
                Ht = o(),
                pe = o(),
                qt = o();
            for (wt = 0; wt < 31; wt++) j[wt] = et[wt];
            for (j[31] = et[31] & 127 | 64, j[0] &= 248, H(nt, st), wt = 0; wt < 16; wt++) Lt[wt] = nt[wt], Ht[wt] = ft[wt] = Yt[wt] = 0;
            for (ft[0] = Ht[0] = 1, wt = 254; wt >= 0; --wt) ut = j[wt >>> 3] >>> (wt & 7) & 1, E(ft, Lt, ut), E(Yt, Ht, ut), tt(pe, ft, Yt), bt(ft, ft, Yt), tt(Yt, Lt, Ht), bt(Lt, Lt, Ht), ct(Ht, pe), ct(qt, ft), Y(ft, Yt, ft), Y(Yt, Lt, pe), tt(pe, ft, Yt), bt(ft, ft, Yt), ct(Lt, ft), bt(Yt, Ht, qt), Y(ft, Yt, d), tt(ft, ft, Ht), Y(Yt, Yt, ft), Y(ft, Ht, qt), Y(Ht, Lt, nt), ct(Lt, pe), E(ft, Lt, ut), E(Yt, Ht, ut);
            for (wt = 0; wt < 16; wt++) nt[wt + 16] = ft[wt], nt[wt + 32] = Yt[wt], nt[wt + 48] = Lt[wt], nt[wt + 64] = Ht[wt];
            var se = nt.subarray(32),
                oe = nt.subarray(16);
            return mt(se, se), Y(oe, oe, se), N(O, oe), 0
        }

        function Et(O, et) {
            return yt(O, et, c)
        }

        function vt(O, et) {
            return n(et, 32), Et(O, et)
        }

        function kt(O, et, st) {
            var j = new Uint8Array(32);
            return yt(j, st, et), V(O, a, j, J)
        }
        var ot = b,
            rt = T;

        function gt(O, et, st, j, nt, ut) {
            var wt = new Uint8Array(32);
            return kt(wt, nt, ut), ot(O, et, st, j, wt)
        }

        function xt(O, et, st, j, nt, ut) {
            var wt = new Uint8Array(32);
            return kt(wt, nt, ut), rt(O, et, st, j, wt)
        }
        var Ct = [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 Tt(O, et, st, j) {
            for (var nt = new Int32Array(16), ut = new Int32Array(16), wt, ft, Lt, Yt, Ht, pe, qt, se, oe, ne, de, ie, ce, re, Ot, te, Qt, _t, $t, Jt, Ut, St, Kt, Pt, Gt, zt, me = O[0], ue = O[1], we = O[2], be = O[3], dt = O[4], ke = O[5], Ue = O[6], Te = O[7], ye = et[0], Ie = et[1], Ce = et[2], Fe = et[3], Le = et[4], Be = et[5], Pe = et[6], Ne = et[7], Ge = 0; j >= 128;) {
                for ($t = 0; $t < 16; $t++) Jt = 8 * $t + Ge, nt[$t] = st[Jt + 0] << 24 | st[Jt + 1] << 16 | st[Jt + 2] << 8 | st[Jt + 3], ut[$t] = st[Jt + 4] << 24 | st[Jt + 5] << 16 | st[Jt + 6] << 8 | st[Jt + 7];
                for ($t = 0; $t < 80; $t++)
                    if (wt = me, ft = ue, Lt = we, Yt = be, Ht = dt, pe = ke, qt = Ue, se = Te, oe = ye, ne = Ie, de = Ce, ie = Fe, ce = Le, re = Be, Ot = Pe, te = Ne, Ut = Te, St = Ne, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = (dt >>> 14 | Le << 32 - 14) ^ (dt >>> 18 | Le << 32 - 18) ^ (Le >>> 41 - 32 | dt << 32 - (41 - 32)), St = (Le >>> 14 | dt << 32 - 14) ^ (Le >>> 18 | dt << 32 - 18) ^ (dt >>> 41 - 32 | Le << 32 - (41 - 32)), Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Ut = dt & ke ^ ~dt & Ue, St = Le & Be ^ ~Le & Pe, Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Ut = Ct[$t * 2], St = Ct[$t * 2 + 1], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Ut = nt[$t % 16], St = ut[$t % 16], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, Qt = Gt & 65535 | zt << 16, _t = Kt & 65535 | Pt << 16, Ut = Qt, St = _t, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = (me >>> 28 | ye << 32 - 28) ^ (ye >>> 34 - 32 | me << 32 - (34 - 32)) ^ (ye >>> 39 - 32 | me << 32 - (39 - 32)), St = (ye >>> 28 | me << 32 - 28) ^ (me >>> 34 - 32 | ye << 32 - (34 - 32)) ^ (me >>> 39 - 32 | ye << 32 - (39 - 32)), Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Ut = me & ue ^ me & we ^ ue & we, St = ye & Ie ^ ye & Ce ^ Ie & Ce, Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, se = Gt & 65535 | zt << 16, te = Kt & 65535 | Pt << 16, Ut = Yt, St = ie, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = Qt, St = _t, Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, Yt = Gt & 65535 | zt << 16, ie = Kt & 65535 | Pt << 16, ue = wt, we = ft, be = Lt, dt = Yt, ke = Ht, Ue = pe, Te = qt, me = se, Ie = oe, Ce = ne, Fe = de, Le = ie, Be = ce, Pe = re, Ne = Ot, ye = te, $t % 16 === 15)
                        for (Jt = 0; Jt < 16; Jt++) Ut = nt[Jt], St = ut[Jt], Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = nt[(Jt + 9) % 16], St = ut[(Jt + 9) % 16], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Qt = nt[(Jt + 1) % 16], _t = ut[(Jt + 1) % 16], Ut = (Qt >>> 1 | _t << 32 - 1) ^ (Qt >>> 8 | _t << 32 - 8) ^ Qt >>> 7, St = (_t >>> 1 | Qt << 32 - 1) ^ (_t >>> 8 | Qt << 32 - 8) ^ (_t >>> 7 | Qt << 32 - 7), Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Qt = nt[(Jt + 14) % 16], _t = ut[(Jt + 14) % 16], Ut = (Qt >>> 19 | _t << 32 - 19) ^ (_t >>> 61 - 32 | Qt << 32 - (61 - 32)) ^ Qt >>> 6, St = (_t >>> 19 | Qt << 32 - 19) ^ (Qt >>> 61 - 32 | _t << 32 - (61 - 32)) ^ (_t >>> 6 | Qt << 32 - 6), Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, nt[Jt] = Gt & 65535 | zt << 16, ut[Jt] = Kt & 65535 | Pt << 16;
                Ut = me, St = ye, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[0], St = et[0], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[0] = me = Gt & 65535 | zt << 16, et[0] = ye = Kt & 65535 | Pt << 16, Ut = ue, St = Ie, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[1], St = et[1], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[1] = ue = Gt & 65535 | zt << 16, et[1] = Ie = Kt & 65535 | Pt << 16, Ut = we, St = Ce, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[2], St = et[2], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[2] = we = Gt & 65535 | zt << 16, et[2] = Ce = Kt & 65535 | Pt << 16, Ut = be, St = Fe, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[3], St = et[3], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[3] = be = Gt & 65535 | zt << 16, et[3] = Fe = Kt & 65535 | Pt << 16, Ut = dt, St = Le, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[4], St = et[4], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[4] = dt = Gt & 65535 | zt << 16, et[4] = Le = Kt & 65535 | Pt << 16, Ut = ke, St = Be, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[5], St = et[5], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[5] = ke = Gt & 65535 | zt << 16, et[5] = Be = Kt & 65535 | Pt << 16, Ut = Ue, St = Pe, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[6], St = et[6], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[6] = Ue = Gt & 65535 | zt << 16, et[6] = Pe = Kt & 65535 | Pt << 16, Ut = Te, St = Ne, Kt = St & 65535, Pt = St >>> 16, Gt = Ut & 65535, zt = Ut >>> 16, Ut = O[7], St = et[7], Kt += St & 65535, Pt += St >>> 16, Gt += Ut & 65535, zt += Ut >>> 16, Pt += Kt >>> 16, Gt += Pt >>> 16, zt += Gt >>> 16, O[7] = Te = Gt & 65535 | zt << 16, et[7] = Ne = Kt & 65535 | Pt << 16, Ge += 128, j -= 128
            }
            return j
        }

        function Mt(O, et, st) {
            var j = new Int32Array(8),
                nt = new Int32Array(8),
                ut = new Uint8Array(256),
                wt, ft = st;
            for (j[0] = 1779033703, j[1] = 3144134277, j[2] = 1013904242, j[3] = 2773480762, j[4] = 1359893119, j[5] = 2600822924, j[6] = 528734635, j[7] = 1541459225, nt[0] = 4089235720, nt[1] = 2227873595, nt[2] = 4271175723, nt[3] = 1595750129, nt[4] = 2917565137, nt[5] = 725511199, nt[6] = 4215389547, nt[7] = 327033209, Tt(j, nt, et, st), st %= 128, wt = 0; wt < st; wt++) ut[wt] = et[ft - st + wt];
            for (ut[st] = 128, st = 256 - 128 * (st < 112 ? 1 : 0), ut[st - 9] = 0, P(ut, st - 8, ft / 536870912 | 0, ft << 3), Tt(j, nt, ut, st), wt = 0; wt < 8; wt++) P(O, 8 * wt, j[wt], nt[wt]);
            return 0
        }

        function At(O, et) {
            var st = o(),
                j = o(),
                nt = o(),
                ut = o(),
                wt = o(),
                ft = o(),
                Lt = o(),
                Yt = o(),
                Ht = o();
            bt(st, O[1], O[0]), bt(Ht, et[1], et[0]), Y(st, st, Ht), tt(j, O[0], O[1]), tt(Ht, et[0], et[1]), Y(j, j, Ht), Y(nt, O[3], et[3]), Y(nt, nt, w), Y(ut, O[2], et[2]), tt(ut, ut, ut), bt(wt, j, st), bt(ft, ut, nt), tt(Lt, ut, nt), tt(Yt, j, st), Y(O[0], wt, ft), Y(O[1], Yt, Lt), Y(O[2], Lt, ft), Y(O[3], wt, Yt)
        }

        function It(O, et, st) {
            var j;
            for (j = 0; j < 4; j++) E(O[j], et[j], st)
        }

        function Rt(O, et) {
            var st = o(),
                j = o(),
                nt = o();
            mt(nt, et[2]), Y(st, et[0], nt), Y(j, et[1], nt), N(O, j), O[31] ^= W(st) << 7
        }

        function Wt(O, et, st) {
            var j, nt;
            for (x(O[0], l), x(O[1], m), x(O[2], m), x(O[3], l), nt = 255; nt >= 0; --nt) j = st[nt / 8 | 0] >> (nt & 7) & 1, It(O, et, j), At(et, O), At(O, O), It(O, et, j)
        }

        function Dt(O, et) {
            var st = [o(), o(), o(), o()];
            x(st[0], S), x(st[1], C), x(st[2], m), Y(st[3], S, C), Wt(O, st, et)
        }

        function Ft(O, et, st) {
            var j = new Uint8Array(64),
                nt = [o(), o(), o(), o()],
                ut;
            for (st || n(et, 32), Mt(j, et, 32), j[0] &= 248, j[31] &= 127, j[31] |= 64, Dt(nt, j), Rt(O, nt), ut = 0; ut < 32; ut++) et[ut + 32] = O[ut];
            return 0
        }
        var jt = 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 L(O, et) {
            var st, j, nt, ut;
            for (j = 63; j >= 32; --j) {
                for (st = 0, nt = j - 32, ut = j - 12; nt < ut; ++nt) et[nt] += st - 16 * et[j] * jt[nt - (j - 32)], st = Math.floor((et[nt] + 128) / 256), et[nt] -= st * 256;
                et[nt] += st, et[j] = 0
            }
            for (st = 0, nt = 0; nt < 32; nt++) et[nt] += st - (et[31] >> 4) * jt[nt], st = et[nt] >> 8, et[nt] &= 255;
            for (nt = 0; nt < 32; nt++) et[nt] -= st * jt[nt];
            for (j = 0; j < 32; j++) et[j + 1] += et[j] >> 8, O[j] = et[j] & 255
        }

        function u(O) {
            var et = new Float64Array(64),
                st;
            for (st = 0; st < 64; st++) et[st] = O[st];
            for (st = 0; st < 64; st++) O[st] = 0;
            L(O, et)
        }

        function y(O, et, st, j) {
            var nt = new Uint8Array(64),
                ut = new Uint8Array(64),
                wt = new Uint8Array(64),
                ft, Lt, Yt = new Float64Array(64),
                Ht = [o(), o(), o(), o()];
            Mt(nt, j, 32), nt[0] &= 248, nt[31] &= 127, nt[31] |= 64;
            var pe = st + 64;
            for (ft = 0; ft < st; ft++) O[64 + ft] = et[ft];
            for (ft = 0; ft < 32; ft++) O[32 + ft] = nt[32 + ft];
            for (Mt(wt, O.subarray(32), st + 32), u(wt), Dt(Ht, wt), Rt(O, Ht), ft = 32; ft < 64; ft++) O[ft] = j[ft];
            for (Mt(ut, O, st + 64), u(ut), ft = 0; ft < 64; ft++) Yt[ft] = 0;
            for (ft = 0; ft < 32; ft++) Yt[ft] = wt[ft];
            for (ft = 0; ft < 32; ft++)
                for (Lt = 0; Lt < 32; Lt++) Yt[ft + Lt] += ut[ft] * nt[Lt];
            return L(O.subarray(32), Yt), pe
        }

        function Z(O, et) {
            var st = o(),
                j = o(),
                nt = o(),
                ut = o(),
                wt = o(),
                ft = o(),
                Lt = o();
            return x(O[2], m), H(O[1], et), ct(nt, O[1]), Y(ut, nt, g), bt(nt, nt, O[2]), tt(ut, O[2], ut), ct(wt, ut), ct(ft, wt), Y(Lt, ft, wt), Y(st, Lt, nt), Y(st, st, ut), ht(st, st), Y(st, st, nt), Y(st, st, ut), Y(st, st, ut), Y(O[0], st, ut), ct(j, O[0]), Y(j, j, ut), D(j, nt) && Y(O[0], O[0], A), ct(j, O[0]), Y(j, j, ut), D(j, nt) ? -1 : (W(O[0]) === et[31] >> 7 && bt(O[0], l, O[0]), Y(O[3], O[0], O[1]), 0)
        }

        function $(O, et, st, j) {
            var nt, ut = new Uint8Array(32),
                wt = new Uint8Array(64),
                ft = [o(), o(), o(), o()],
                Lt = [o(), o(), o(), o()];
            if (st < 64 || Z(Lt, j)) return -1;
            for (nt = 0; nt < st; nt++) O[nt] = et[nt];
            for (nt = 0; nt < 32; nt++) O[nt + 32] = j[nt];
            if (Mt(wt, O, st), u(wt), Wt(ft, Lt, wt), Dt(Lt, et.subarray(32)), At(ft, Lt), Rt(ut, ft), st -= 64, M(et, 0, ut, 0)) {
                for (nt = 0; nt < st; nt++) O[nt] = 0;
                return -1
            }
            for (nt = 0; nt < st; nt++) O[nt] = et[nt + 64];
            return st
        }
        var it = 32,
            lt = 24,
            Bt = 32,
            Xt = 16,
            Nt = 32,
            Zt = 32,
            Vt = 32,
            le = 32,
            Se = 32,
            ve = lt,
            he = Bt,
            De = Xt,
            fe = 64,
            ae = 32,
            Re = 64,
            xe = 32,
            ge = 64;
        t.lowlevel = {
            crypto_core_hsalsa20: V,
            crypto_stream_xor: pt,
            crypto_stream: at,
            crypto_stream_salsa20_xor: q,
            crypto_stream_salsa20: Q,
            crypto_onetimeauth: k,
            crypto_onetimeauth_verify: U,
            crypto_verify_16: X,
            crypto_verify_32: M,
            crypto_secretbox: b,
            crypto_secretbox_open: T,
            crypto_scalarmult: yt,
            crypto_scalarmult_base: Et,
            crypto_box_beforenm: kt,
            crypto_box_afternm: ot,
            crypto_box: gt,
            crypto_box_open: xt,
            crypto_box_keypair: vt,
            crypto_hash: Mt,
            crypto_sign: y,
            crypto_sign_keypair: Ft,
            crypto_sign_open: $,
            crypto_secretbox_KEYBYTES: it,
            crypto_secretbox_NONCEBYTES: lt,
            crypto_secretbox_ZEROBYTES: Bt,
            crypto_secretbox_BOXZEROBYTES: Xt,
            crypto_scalarmult_BYTES: Nt,
            crypto_scalarmult_SCALARBYTES: Zt,
            crypto_box_PUBLICKEYBYTES: Vt,
            crypto_box_SECRETKEYBYTES: le,
            crypto_box_BEFORENMBYTES: Se,
            crypto_box_NONCEBYTES: ve,
            crypto_box_ZEROBYTES: he,
            crypto_box_BOXZEROBYTES: De,
            crypto_sign_BYTES: fe,
            crypto_sign_PUBLICKEYBYTES: ae,
            crypto_sign_SECRETKEYBYTES: Re,
            crypto_sign_SEEDBYTES: xe,
            crypto_hash_BYTES: ge,
            gf: o,
            D: g,
            L: jt,
            pack25519: N,
            unpack25519: H,
            M: Y,
            A: tt,
            S: ct,
            Z: bt,
            pow2523: ht,
            add: At,
            set25519: x,
            modL: L,
            scalarmult: Wt,
            scalarbase: Dt
        };

        function Ae(O, et) {
            if (O.length !== it) throw new Error("bad key size");
            if (et.length !== lt) throw new Error("bad nonce size")
        }

        function Me(O, et) {
            if (O.length !== Vt) throw new Error("bad public key size");
            if (et.length !== le) throw new Error("bad secret key size")
        }

        function ee() {
            for (var O = 0; O < arguments.length; O++)
                if (!(arguments[O] instanceof Uint8Array)) throw new TypeError("unexpected type, use Uint8Array")
        }

        function Ee(O) {
            for (var et = 0; et < O.length; et++) O[et] = 0
        }
        t.randomBytes = function(O) {
                var et = new Uint8Array(O);
                return n(et, O), et
            }, t.secretbox = function(O, et, st) {
                ee(O, et, st), Ae(st, et);
                for (var j = new Uint8Array(Bt + O.length), nt = new Uint8Array(j.length), ut = 0; ut < O.length; ut++) j[ut + Bt] = O[ut];
                return b(nt, j, j.length, et, st), nt.subarray(Xt)
            }, t.secretbox.open = function(O, et, st) {
                ee(O, et, st), Ae(st, et);
                for (var j = new Uint8Array(Xt + O.length), nt = new Uint8Array(j.length), ut = 0; ut < O.length; ut++) j[ut + Xt] = O[ut];
                return j.length < 32 || T(nt, j, j.length, et, st) !== 0 ? null : nt.subarray(Bt)
            }, t.secretbox.keyLength = it, t.secretbox.nonceLength = lt, t.secretbox.overheadLength = Xt, t.scalarMult = function(O, et) {
                if (ee(O, et), O.length !== Zt) throw new Error("bad n size");
                if (et.length !== Nt) throw new Error("bad p size");
                var st = new Uint8Array(Nt);
                return yt(st, O, et), st
            }, t.scalarMult.base = function(O) {
                if (ee(O), O.length !== Zt) throw new Error("bad n size");
                var et = new Uint8Array(Nt);
                return Et(et, O), et
            }, t.scalarMult.scalarLength = Zt, t.scalarMult.groupElementLength = Nt, t.box = function(O, et, st, j) {
                var nt = t.box.before(st, j);
                return t.secretbox(O, et, nt)
            }, t.box.before = function(O, et) {
                ee(O, et), Me(O, et);
                var st = new Uint8Array(Se);
                return kt(st, O, et), st
            }, t.box.after = t.secretbox, t.box.open = function(O, et, st, j) {
                var nt = t.box.before(st, j);
                return t.secretbox.open(O, et, nt)
            }, t.box.open.after = t.secretbox.open, t.box.keyPair = function() {
                var O = new Uint8Array(Vt),
                    et = new Uint8Array(le);
                return vt(O, et), {
                    publicKey: O,
                    secretKey: et
                }
            }, t.box.keyPair.fromSecretKey = function(O) {
                if (ee(O), O.length !== le) throw new Error("bad secret key size");
                var et = new Uint8Array(Vt);
                return Et(et, O), {
                    publicKey: et,
                    secretKey: new Uint8Array(O)
                }
            }, t.box.publicKeyLength = Vt, t.box.secretKeyLength = le, t.box.sharedKeyLength = Se, t.box.nonceLength = ve, t.box.overheadLength = t.secretbox.overheadLength, t.sign = function(O, et) {
                if (ee(O, et), et.length !== Re) throw new Error("bad secret key size");
                var st = new Uint8Array(fe + O.length);
                return y(st, O, O.length, et), st
            }, t.sign.open = function(O, et) {
                if (ee(O, et), et.length !== ae) throw new Error("bad public key size");
                var st = new Uint8Array(O.length),
                    j = $(st, O, O.length, et);
                if (j < 0) return null;
                for (var nt = new Uint8Array(j), ut = 0; ut < nt.length; ut++) nt[ut] = st[ut];
                return nt
            }, t.sign.detached = function(O, et) {
                for (var st = t.sign(O, et), j = new Uint8Array(fe), nt = 0; nt < j.length; nt++) j[nt] = st[nt];
                return j
            }, t.sign.detached.verify = function(O, et, st) {
                if (ee(O, et, st), et.length !== fe) throw new Error("bad signature size");
                if (st.length !== ae) throw new Error("bad public key size");
                var j = new Uint8Array(fe + O.length),
                    nt = new Uint8Array(fe + O.length),
                    ut;
                for (ut = 0; ut < fe; ut++) j[ut] = et[ut];
                for (ut = 0; ut < O.length; ut++) j[ut + fe] = O[ut];
                return $(nt, j, j.length, st) >= 0
            }, t.sign.keyPair = function() {
                var O = new Uint8Array(ae),
                    et = new Uint8Array(Re);
                return Ft(O, et), {
                    publicKey: O,
                    secretKey: et
                }
            }, t.sign.keyPair.fromSecretKey = function(O) {
                if (ee(O), O.length !== Re) throw new Error("bad secret key size");
                for (var et = new Uint8Array(ae), st = 0; st < et.length; st++) et[st] = O[32 + st];
                return {
                    publicKey: et,
                    secretKey: new Uint8Array(O)
                }
            }, t.sign.keyPair.fromSeed = function(O) {
                if (ee(O), O.length !== xe) throw new Error("bad seed size");
                for (var et = new Uint8Array(ae), st = new Uint8Array(Re), j = 0; j < 32; j++) st[j] = O[j];
                return Ft(et, st, !0), {
                    publicKey: et,
                    secretKey: st
                }
            }, t.sign.publicKeyLength = ae, t.sign.secretKeyLength = Re, t.sign.seedLength = xe, t.sign.signatureLength = fe, t.hash = function(O) {
                ee(O);
                var et = new Uint8Array(ge);
                return Mt(et, O, O.length), et
            }, t.hash.hashLength = ge, t.verify = function(O, et) {
                return ee(O, et), O.length === 0 || et.length === 0 || O.length !== et.length ? !1 : G(O, 0, et, 0, O.length) === 0
            }, t.setPRNG = function(O) {
                n = O
            },
            function() {
                var O = typeof self != "undefined" ? self.crypto || self.msCrypto : null;
                if (O && O.getRandomValues) {
                    var et = 65536;
                    t.setPRNG(function(st, j) {
                        var nt, ut = new Uint8Array(j);
                        for (nt = 0; nt < j; nt += et) O.getRandomValues(ut.subarray(nt, nt + Math.min(j - nt, et)));
                        for (nt = 0; nt < j; nt++) st[nt] = ut[nt];
                        Ee(ut)
                    })
                } else typeof commonjsRequire != "undefined" && (O = require$$1, O && O.randomBytes && t.setPRNG(function(st, j) {
                    var nt, ut = O.randomBytes(j);
                    for (nt = 0; nt < j; nt++) st[nt] = ut[nt];
                    Ee(ut)
                }))
            }()
    })(e.exports ? e.exports : self.nacl = self.nacl || {})
})(naclFast);
var nacl = naclFast.exports,
    buffer = {};
sdlaver commented 2 years ago

Thanks.

From the FakeWallet logs, I can see that one connection was successful, and an auth token was returned by the wallet to the dapp:

2022-07-12 00:44:13.243 18427-25697/com.solana.mobilewalletadapter.fakewallet V/AuthRepository: Returning auth token for AuthRecord: AuthRecord{id=17, identity=IdentityRecord{id=3, name='SolPredict', uri=https://devnet.solpredict.io/, relativeIconUri=./assets/logo.svg}, publicKey=[-42, -43, -126, 38, 47, -123, 104, 43, 71, 74, -122, 124, -76, 1, 34, 123, -4, 36, -63, -17, 28, -58, -114, -77, 27, -122, -94, 116, 117, -1, 17, -58], scope=[], issued=1657604653219, expires=1657608253219, mRevoked=false}

followed by a connection close:

2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet I/MobileWalletAdapterSessionCommon: mobile-wallet-adapter session closed
2022-07-12 00:44:13.398 18427-25698/com.solana.mobilewalletadapter.fakewallet D/Scenario: MobileWalletAdapter session terminated

Question: does your dapp immediately then try and connect back to the wallet, to perform another action? We have an open issue, https://github.com/solana-mobile/mobile-wallet-adapter/issues/94, that causes that to sometimes fail. If so, you can add a short delay (250ms) as a strictly temporary workaround until we fix the issue.

lmvdz commented 2 years ago

Question: does your dapp immediately then try and connect back to the wallet, to perform another action? We have an open issue, solana-mobile/mobile-wallet-adapter#94, that causes that to sometimes fail. If so, you can add a short delay (250ms) as a strictly temporary workaround until we fix the issue.

No this is strictly on Selecting the Wallet for connecting to the site. Perhaps I am misinterpreting the question. The wallet is being deep reference watched, so once the value of the wallet changes (connected, connecting) the function gets called.

lmvdz commented 2 years ago

I will spin up a fresh project to see if the issue is localized to my project specifically. https://devnet.solpredict.io if you want to test it yourself.

lmvdz commented 2 years ago

@sdlaver is it normal for the websocket connection to fail on the website?

sdlaver commented 2 years ago

Nope, it's not a failure mode I've seen elsewhere. I've tried repro'ing this a couple of times locally - both with the emulator and with a Pixel 6. I've been in meetings most of the day today, but I plan to spend another hour and try repro'ing this afternoon.

lmvdz commented 2 years ago

I think it's something to do with this solana-wallets-vue package

image

lmvdz commented 2 years ago

image

SolanaMobileWalletAdapter object gets called on setWallet() https://github.com/lorisleiva/solana-wallets-vue/blob/main/src/createWalletStore.ts#L89 ( console.log(newWallet.value) )

But after connecting, wallet connecting, and authorizing and getting sent back to the web app, the setWallet() doesn't get called @lorisleiva

So either this.emit('connect') is not getting sent or the shallowRef is not getting updated ?

steveluscher commented 2 years ago

The failed websocket logs are a red herring. There are always failed connection logs between the time the web app starts to scan for the socket and the time the mobile wallet opens the socket server. Your problem is definitely that the app isn't updating after you get the response.

steveluscher commented 2 years ago

After I click ‘authorize’ in the fake wallet, I see the connect event being emitted from the Solana Mobile wallet adapter:

image

So yeah, for now it seems like Vue isn't picking up on that update to re-render. Let me know what you find!

lmvdz commented 2 years ago

~It does look like the readyState is 'Installed' before the auth response is received and publicKey is null.~ Oh I see Installed doesn't mean connected.

lmvdz commented 2 years ago

@steveluscher @sdlaver

https://github.com/lorisleiva/solana-wallets-vue/blob/main/src/createWalletStore.ts#L152

event listeners for wallet were getting removed because of the use of beforeunload instead of unload

when connecting to the mobile wallet, the chrome tab gets put in the freeze state instead of unload.

This worked for me, after authorizing the connect, the wallet was connected.

image

steveluscher commented 2 years ago

Mmm… there you go. That's interesting. That's a problem that didn't exist before the mobile wallet adapter, because typically connecting to a wallet doesn't cause an app switch. Nice find.

lmvdz commented 2 years ago

Mmm… there you go. That's interesting. That's a problem that didn't exist before the mobile wallet adapter, because typically connecting to a wallet doesn't cause an app switch. Nice find.

Thank you, and thanks for helping debug! Hopefully this gets merged ASAP so I can continue development on SolPredict

lmvdz commented 2 years ago

@lorisleiva bump maintainer

lorisleiva commented 2 years ago

Hey all 👋 Sorry I couldn't help figure this out, I'm trying to allocate as much time as possible on the Metaplex JS SDK at the moment.

Thank you for writing a PR that fixes this! I'll merge it and release a new version right now. 🍺

lorisleiva commented 2 years ago

Merged and published as v0.4.2. 🚀