"use strict";var e=require("@privy-io/ethereum"),t=require("@privy-io/js-sdk-core"),r=require("./toViemAccount-CopJpCYv.js"),a=require("./privy-context-UTJouJ1x.js"),s=require("./getPublicClient-CFd_sHBk.js"),i=require("./internal-context-CdsQ3LEl.js");require("jose"),require("eventemitter3"),require("./index-Ub4KpwSY.js"),require("react"),require("zustand"),require("./context-rs-ygOK2.js"),require("react/jsx-runtime"),require("tinycolor2"),require("viem"),require("viem/utils"),require("./errors-CBapWvRs.js"),require("ofetch"),require("./wallet-connect-BuohfvHK.js"),require("react-device-detect"),require("@coinbase/wallet-sdk"),require("@walletconnect/ethereum-provider"),require("./pkce-CmuJlEgn.js"),require("./paths-DizMb-lU.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("js-cookie"),require("viem/accounts"),require("@privy-io/are-addresses-equal"),require("viem/chains");exports.toViemAccount=r.toViemAccount,exports.useSendTransaction=()=>{let{privy:n,walletProxy:o,rpcConfig:c,chains:d,appId:l}=i.usePrivyInternal(),{user:u,sendTransaction:p}=a.usePrivyContext();return{sendTransaction:async({transaction:i,wallet:h},T)=>{let m=i;if(s.isTempoChainId(i.chainId)&&r.shouldDefaultTempoTransactionType(i)&&(m=r.defaultTempoTransactionTypeForTransaction(i)),!e.isTempoTransactionRequest(m))return await p(m,{address:h.address,...void 0!==T?.sponsor?{sponsor:T.sponsor}:{},uiOptions:{showWalletUIs:!1}});let g=await r.getAccessToken();if(!g||!o)throw Error("Must have valid access token and Privy wallet to send transaction");let y=a.getPrivyWalletWithAddress(u,h.address);if(!y||!a.getIsUnifiedWallet(y))throw Error("Tempo (type 118) transactions are only supported on Unified embedded wallets");let q=m.chainId;if(!q||!s.isTempoChainId(q))throw Error(`Cannot send a Tempo (type 118) transaction on chain ${q}`);let w=s.getPublicClient(q,d,c,{appId:l}),v={transaction:t.toWalletApiUnsignedEthTransaction(await r.prepareTempoTransactionRequest(m,w,h.address))};if(T?.sponsor){let e=await t.rpc(n,(async({message:e})=>o.signWithUserSigner({accessToken:g,message:e})),{chain_type:"ethereum",method:"eth_sendTransaction",wallet_id:y.id,caip2:`eip155:${q}`,sponsor:!0,params:v});if("eth_sendTransaction"!==e.method||!("hash"in e.data))throw Error("Unable to send transaction");return{hash:e.data.hash}}let f=await t.rpc(n,(async({message:e})=>o.signWithUserSigner({accessToken:g,message:e})),{chain_type:"ethereum",method:"eth_signTransaction",wallet_id:y.id,params:v});if("eth_signTransaction"!==f.method||!("signed_transaction"in f.data))throw Error("Unable to sign transaction");return{hash:await w.request({method:"eth_sendRawTransaction",params:[f.data.signed_transaction]})}}}},exports.useSignTransaction=()=>{let{privy:n,walletProxy:o}=i.usePrivyInternal(),{user:c,signTransaction:d}=a.usePrivyContext();return{signTransaction:async({transaction:i,wallet:l})=>{let u=i;if(s.isTempoChainId(i.chainId)&&r.shouldDefaultTempoTransactionType(i)&&(u=r.defaultTempoTransactionTypeForTransaction(i)),!e.isTempoTransactionRequest(u)){let{signature:e}=await d(u,{address:l.address,uiOptions:{showWalletUIs:!1}});return{signedTransaction:e}}let p=await r.getAccessToken();if(!p||!o)throw Error("Must have valid access token and Privy wallet to sign transaction");let h=a.getPrivyWalletWithAddress(c,l.address);if(!h||!a.getIsUnifiedWallet(h))throw Error("Tempo (type 118) transactions are only supported on Unified embedded wallets");let T=await t.rpc(n,(async({message:e})=>o.signWithUserSigner({accessToken:p,message:e})),{chain_type:"ethereum",method:"eth_signTransaction",wallet_id:h.id,params:{transaction:t.toWalletApiUnsignedEthTransaction(u)}});if("eth_signTransaction"!==T.method||!("signed_transaction"in T.data))throw Error("Unable to sign transaction");return{signedTransaction:T.data.signed_transaction}}}};
//# sourceMappingURL=tempo.js.map
