UNPKG

@privy-io/expo

Version:

Expo client for the Privy Auth API

2 lines (1 loc) 1.28 kB
import{b as u,l as i}from"./chunk-WWWQIJT5.js";import{d as a}from"./chunk-QTVIWU3N.js";import{useMemo as d}from"react";import{create as g}from"@privy-io/js-sdk-core";var f=()=>{let e=i();return d(()=>({createWallet(n){return a(this,null,function*(){let s=yield g(e,{request:{chain_type:n.chainType}}),{user:o}=yield e.user.get();return{user:o,wallet:s}})}}),[e])};import{useMemo as h}from"react";import{isEmbeddedWalletAccount as m,isUnifiedWallet as w,PrivyClientError as c,rawSign as y}from"@privy-io/js-sdk-core";var C=()=>{let e=i();return h(()=>({signRawHash(k){return a(this,arguments,function*({address:n,chainType:s,hash:o}){let l=u();if(!l)throw new c({code:"embedded_wallet_before_logged_in",error:"User must be authenticated before signing a raw hash"});let p=l.linked_accounts.filter(m).filter(w).filter(t=>t.chain_type===s).find(t=>t.address===n);if(!p)throw new c({code:"embedded_wallet_does_not_exist",error:"No embedded wallet found for the given address and chain type"});let r=yield y(e,(...t)=>e.embeddedWallet.signWithUserSigner(...t),{wallet_id:p.id,params:{hash:o}});if(r.data&&"signature"in r.data&&r.data.encoding==="hex")return{signature:r.data.signature};throw new Error("Failed to sign")})}}),[e])};export{f as useCreateWallet,C as useSignRawHash};