import{isTempoTransactionRequest as t}from"@privy-io/ethereum";import{toWalletApiUnsignedEthTransaction as a,rpc as e}from"@privy-io/js-sdk-core";import{s,q as r,a as i,r as n}from"./toViemAccount-4iGGrW4w.mjs";export{m as toViemAccount}from"./toViemAccount-4iGGrW4w.mjs";import{u as o,f as c,a as d}from"./privy-context-Bi6vqCPc.mjs";import{i as p,g as l}from"./getPublicClient-D4yNgeGy.mjs";import{u as h}from"./internal-context-dfitw7Ot.mjs";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"react";import"zustand";import"./context-BKnOUECq.mjs";import"react/jsx-runtime";import"tinycolor2";import"viem";import"viem/utils";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"./wallet-connect-58EobR5U.mjs";import"react-device-detect";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"viem/accounts";import"@privy-io/are-addresses-equal";import"viem/chains";const u=()=>{let{privy:m,walletProxy:u,rpcConfig:w,chains:g,appId:y}=h(),{user:f,sendTransaction:v}=o();return{sendTransaction:async({transaction:o,wallet:h},T)=>{let j=o;if(p(o.chainId)&&s(o)&&(j=r(o)),!t(j))return await v(j,{address:h.address,...void 0!==T?.sponsor?{sponsor:T.sponsor}:{},uiOptions:{showWalletUIs:!1}});let _=await i();if(!_||!u)throw Error("Must have valid access token and Privy wallet to send transaction");let x=c(f,h.address);if(!x||!d(x))throw Error("Tempo (type 118) transactions are only supported on Unified embedded wallets");let U=j.chainId;if(!U||!p(U))throw Error(`Cannot send a Tempo (type 118) transaction on chain ${U}`);let k=l(U,g,w,{appId:y}),b={transaction:a(await n(j,k,h.address))};if(T?.sponsor){let t=await e(m,(async({message:t})=>u.signWithUserSigner({accessToken:_,message:t})),{chain_type:"ethereum",method:"eth_sendTransaction",wallet_id:x.id,caip2:`eip155:${U}`,sponsor:!0,params:b});if("eth_sendTransaction"!==t.method||!("hash"in t.data))throw Error("Unable to send transaction");return{hash:t.data.hash}}let E=await e(m,(async({message:t})=>u.signWithUserSigner({accessToken:_,message:t})),{chain_type:"ethereum",method:"eth_signTransaction",wallet_id:x.id,params:b});if("eth_signTransaction"!==E.method||!("signed_transaction"in E.data))throw Error("Unable to sign transaction");return{hash:await k.request({method:"eth_sendRawTransaction",params:[E.data.signed_transaction]})}}}},w=()=>{let{privy:n,walletProxy:m}=h(),{user:l,signTransaction:u}=o();return{signTransaction:async({transaction:o,wallet:h})=>{let w=o;if(p(o.chainId)&&s(o)&&(w=r(o)),!t(w)){let{signature:t}=await u(w,{address:h.address,uiOptions:{showWalletUIs:!1}});return{signedTransaction:t}}let g=await i();if(!g||!m)throw Error("Must have valid access token and Privy wallet to sign transaction");let y=c(l,h.address);if(!y||!d(y))throw Error("Tempo (type 118) transactions are only supported on Unified embedded wallets");let f=await e(n,(async({message:t})=>m.signWithUserSigner({accessToken:g,message:t})),{chain_type:"ethereum",method:"eth_signTransaction",wallet_id:y.id,params:{transaction:a(w)}});if("eth_signTransaction"!==f.method||!("signed_transaction"in f.data))throw Error("Unable to sign transaction");return{signedTransaction:f.data.signed_transaction}}}};export{u as useSendTransaction,w as useSignTransaction};
//# sourceMappingURL=tempo.mjs.map
