@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines (1 loc) • 1.18 kB
JavaScript
;var r=require("viem"),e=require("../errors.js");require("../types.js");const t=(r,t,p)=>{let o,i=r.id,c=Number(r.id);if(r.rpcUrls.privyWalletOverride&&r.rpcUrls.privyWalletOverride.http[0])o=r.rpcUrls.privyWalletOverride.http[0];else if(t.rpcUrls&&t.rpcUrls[c])o=t.rpcUrls[c];else if(r.rpcUrls.privy?.http[0]){let e=new URL(r.rpcUrls.privy.http[0]);e.searchParams.append("privyAppId",p),o=e.toString()}else o=r.rpcUrls.public?.http[0]?r.rpcUrls.public.http[0]:r.rpcUrls.default?.http[0];if(!o)throw new e.PrivyConnectorError(`No RPC url found for ${i}`);return o};exports.getJsonRpcEndpointFromChain=t,exports.getPublicClient=(p,o,i,c)=>{let s=Number(p),n=o.find((r=>r.id===s));if(!n)throw new e.PrivyConnectorError(`Unsupported chainId ${p}`,4901);return r.createPublicClient({transport:r.http(t(n,i,c.appId)),chain:n})},exports.throwIfInvalidRecoveryUpgradePath=function({currentRecoveryMethod:r,upgradeToRecoveryMethod:e}){switch(r){case"privy":case"user-passcode":case"recovery-encryption-key":return!0;case"icloud":case"google-drive":if(r===e)throw Error("Cannot upgrade to the existing cloud platform");return!0;default:throw Error("Unknown recovery method")}};