import{useMemo as e}from"react";import{create as t,rawSign as r}from"@privy-io/js-sdk-core";import{u as a}from"./internal-context-dfitw7Ot.mjs";import{u as i,f as o,a as s,k as n}from"./privy-context-Bi6vqCPc.mjs";import{u as d}from"./context-BKnOUECq.mjs";import{P as l}from"./errors-Dd6zfYtp.mjs";import{u as c}from"./modal-context-DBwfUxD-.mjs";import{u as p}from"./use-sign-with-user-signer-CQI6hUH7.mjs";import"@privy-io/are-addresses-equal";import"react/jsx-runtime";import"tinycolor2";import"ofetch";const m=()=>{let{refreshSessionAndUser:r,privy:i}=a();return e((()=>({async createWallet(e){let a=await t(i,{request:{chain_type:e.chainType}}),o=await r();if(!o)throw Error("User must be authenticated before creating a Privy wallet");return{user:o,wallet:a}}})),[r,i])};function u(){let{user:t,getAccessToken:r}=i(),{walletProxy:n,openModal:p,client:m}=a(),{setModalData:u}=c(),h=d();return e((()=>({exportWallet:e=>new Promise((async(a,i)=>{if(!t)return void i(new l("User must be authenticated before exporting their Privy wallet"));let d=o(t,e.address);d?s(d)?await r()?n?(u({connectWallet:{recoveryMethod:d.recoveryMethod,connectingWalletAddress:d.address,isUnifiedWallet:!0,onCompleteNavigateTo:"EmbeddedWalletKeyExportScreen",onFailure:i,shouldForceMFA:!0},keyExport:{appId:h.id,appClientId:h.appClientId,origin:m.apiUrl,address:d.address,uiOptions:e.uiOptions,hdWalletIndex:d.walletIndex,chainType:d.chainType,walletId:d.id,isUnifiedWallet:!0,imported:d.imported,onSuccess:a,onFailure:i}}),p("EmbeddedWalletConnectingScreen")):i(new l("Wallet not ready for export")):i(new l("Must have valid access token.")):i(Error("Export via extended-chains is only supported for unified stack wallets")):i(new l("User must have an embedded wallet."))}))})),[t,r,n,p,m,u,h])}const h=()=>{let{user:t}=i(),{privy:o}=a(),{signWithUserSigner:d}=p();return e((()=>({async signRawHash({address:e,chainType:a,hash:i}){if(!t)throw Error("User must be authenticated before signing");let l=n(t,a).filter((e=>s(e))).find((t=>t.address===e));if(!l)throw Error("Wallet not found");let c=await r(o,d,{wallet_id:l.id,params:{hash:i}});if(c.data&&"signature"in c.data&&"hex"===c.data.encoding)return{signature:c.data.signature};throw Error("Failed to sign")}})),[o,d,t])};export{m as useCreateWallet,u as useExportWallet,h as useSignRawHash};
//# sourceMappingURL=extended-chains.mjs.map
