"use strict";var e=require("react-device-detect"),r=require("./errors-CBapWvRs.js"),t=require("jose"),n=require("./context-rs-ygOK2.js"),i=require("./wallet-connect-BuohfvHK.js");function o(e){return{name:e.metadata?.shortName||e.name||"",universalLink:e.mobile.universal,deepLink:e.mobile.native}}let a="WALLETCONNECT_DEEPLINK_CHOICE";function l(e){return e.startsWith("http://")||e.startsWith("https://")}function u(e,r){if(l(e))return c(e,r);let t=e;return t.includes("://")||(t=e.replaceAll("/","").replaceAll(":",""),t=`${t}://`),t.endsWith("/")||(t=`${t}/`),{redirect:`${t}wc?uri=${encodeURIComponent(r)}`,href:t}}function c(e,r){if(!l(e))return u(e,r);let t=e;return t.endsWith("/")||(t=`${t}/`),{redirect:`${t}wc?uri=${encodeURIComponent(r)}`,href:t}}function s(e){return crypto.getRandomValues(new Uint8Array(e))}function d(){return t.base64url.encode(s(36))}exports.buildTargetUrl=function(t,n){let i=o(n);if(e.isMobile&&e.isAndroid&&i.universalLink)return c(i.universalLink,t);if(i.deepLink)return u(i.deepLink,t);if(i.universalLink)return c(i.universalLink,t);throw new r.PrivyClientError(`Unsupported wallet ${n.id}`)},exports.buildUniversalFallbackUrl=function(e,r){let t=o(r);if(t.universalLink)return c(t.universalLink,e)},exports.createCodeVerifier=d,exports.createStateCode=function(){return d()},exports.deleteWalletConnectDeepLink=function(){try{localStorage.removeItem(a)}catch{}},exports.deriveCodeChallengeFromCodeVerifier=async function(e,r="S256"){if("S256"!=r)return e;{let r=await async function(e){let r=(new TextEncoder).encode(e);return new Uint8Array(await crypto.subtle.digest("SHA-256",r))}(e);return t.base64url.encode(r)}},exports.getCodeVerifier=function(){let e=i.s.get(n.CODE_VERIFIER_KEY);if(!e)throw new r.PrivyClientError("Authentication error.");return e},exports.openHref=function(e,r){window.open(e,r,"noreferrer noopener")},exports.randomBytes=s,exports.removeWalletConnectDeepLink=function(){try{localStorage.removeItem(a)}catch{}},exports.setWalletConnectDeepLink=function({href:e,name:r}){try{localStorage.setItem(a,JSON.stringify({href:e,name:r}))}catch{}};
//# sourceMappingURL=pkce-CmuJlEgn.js.map
