UNPKG

@privy-io/js-sdk-core

Version:

Vanilla JS client for the Privy Auth API

2 lines (1 loc) 1.16 kB
import{createPublicClient as r,http as e}from"viem";import{PrivyConnectorError as t}from"../errors.mjs";import"../types.mjs";const p=(p,i,c,s)=>{let l=Number(p),n=i.find((r=>r.id===l));if(!n)throw new t(`Unsupported chainId ${p}`,4901);return r({transport:e(o(n,c,s.appId)),chain:n})},o=(r,e,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(e.rpcUrls&&e.rpcUrls[c])o=e.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 t(`No RPC url found for ${i}`);return o};function i({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")}}export{o as getJsonRpcEndpointFromChain,p as getPublicClient,i as throwIfInvalidRecoveryUpgradePath};