@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines (1 loc) • 2.09 kB
JavaScript
;var e=require("../../action/delegatedActions/utils.js"),t=require("../../wallet-api/get-wallet.js"),r=require("../../wallet-api/unified-wallet.js"),a=require("../../wallet-api/update-wallet.js");async function i(e){let{user:t}=await e.user.get();if(!t)throw Error("Could not refresh user");return{user:t}}function s(e){return(...t)=>e.embeddedWallet.signWithUserSigner(...t)}require("../../utils/getAllUserEmbeddedEthereumWallets.js"),require("../../utils/getAllUserEmbeddedSolanaWallets.js"),require("../../utils/getUserEmbeddedEthereumWallet.js"),require("../../utils/getUserEmbeddedSolanaWallet.js"),require("@privy-io/public-api"),require("../../wallet-api/generate-authorization-signature.js"),require("canonicalize"),require("../../Error.js"),exports.addSessionSigners=async function({client:l,wallet:d,signers:n}){if("ethereum"!==d.chain_type&&"solana"!==d.chain_type)throw Error("Session signers are only supported for Ethereum and Solana wallets");if(r.isUnifiedWallet(d)){if(0===n.length)throw Error("Must specify at least one signer to add.");let e={wallet_id:d.id},r=await t.getWallet(l,e);await a.updateWallet(l,e,s(l),{additional_signers:r.additional_signers.concat(n)})}else{if(d.delegated)return i(l);if(n.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 l.user.get(),r=e.getRootWalletForDelegation(d,t);if(!r)throw Error("Unable to determine root address for delegated address.");await l.embeddedWallet.delegateWallets({rootWallet:{address:r.address,chainType:r.chain_type,imported:r.imported},delegatedWallets:[{address:d.address,chainType:d.chain_type,walletIndex:d.wallet_index}]})}return i(l)},exports.removeSessionSigners=async function({client:e,wallet:t}){if(r.isUnifiedWallet(t)){let r={wallet_id:t.id};await a.updateWallet(e,r,s(e),{additional_signers:[]})}else await e.delegated.revoke();return i(e)};