@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines (1 loc) • 2.06 kB
JavaScript
import{getRootWalletForDelegation as e}from"../../action/delegatedActions/utils.mjs";import{getWallet as t}from"../../wallet-api/get-wallet.mjs";import{isUnifiedWallet as r}from"../../wallet-api/unified-wallet.mjs";import{updateWallet as a}from"../../wallet-api/update-wallet.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";import"@privy-io/public-api";import"../../wallet-api/generate-authorization-signature.mjs";import"canonicalize";import"../../Error.mjs";async function i({client:i,wallet:s,signers:d}){if("ethereum"!==s.chain_type&&"solana"!==s.chain_type)throw Error("Session signers are only supported for Ethereum and Solana wallets");if(r(s)){if(0===d.length)throw Error("Must specify at least one signer to add.");let e={wallet_id:s.id},r=await t(i,e);await a(i,e,o(i),{additional_signers:r.additional_signers.concat(d)})}else{if(s.delegated)return l(i);if(d.length>0)throw Error("addSessionSigners is only supported for TEE execution and this app uses On-device execution. Use the useHeadlessDelegatedActions hook to manage server side access on behalf of your users. Learn more https://docs.privy.io/recipes/tee-wallet-migration-guide");let{user:t}=await i.user.get(),r=e(s,t);if(!r)throw Error("Unable to determine root address for delegated address.");await i.embeddedWallet.delegateWallets({rootWallet:{address:r.address,chainType:r.chain_type,imported:r.imported},delegatedWallets:[{address:s.address,chainType:s.chain_type,walletIndex:s.wallet_index}]})}return l(i)}async function s({client:e,wallet:t}){if(r(t)){let r={wallet_id:t.id};await a(e,r,o(e),{additional_signers:[]})}else await e.delegated.revoke();return l(e)}async function l(e){let{user:t}=await e.user.get();if(!t)throw Error("Could not refresh user");return{user:t}}function o(e){return(...t)=>e.embeddedWallet.signWithUserSigner(...t)}export{i as addSessionSigners,s as removeSessionSigners};