@privy-io/expo 0.77.0 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/dist/cards.js +2 -2
- package/dist/chunk-3HF374LL.js +1 -0
- package/dist/{chunk-WFA766DT.js → chunk-6LJTXHKE.js} +2 -2
- package/dist/{chunk-IAMDR3V4.js → chunk-B42N35ZL.js} +1 -1
- package/dist/chunk-C5WYSLQF.js +1 -0
- package/dist/{chunk-FENAOPPV.js → chunk-CN53OAQW.js} +1 -1
- package/dist/chunk-F7DR7TVR.js +1 -0
- package/dist/connectors.js +1 -1
- package/dist/esm/cards.js +2 -2
- package/dist/esm/chunk-3HF374LL.js +1 -0
- package/dist/esm/{chunk-WFA766DT.js → chunk-6LJTXHKE.js} +2 -2
- package/dist/esm/{chunk-IAMDR3V4.js → chunk-B42N35ZL.js} +1 -1
- package/dist/esm/chunk-C5WYSLQF.js +1 -0
- package/dist/esm/{chunk-FENAOPPV.js → chunk-CN53OAQW.js} +1 -1
- package/dist/esm/chunk-F7DR7TVR.js +1 -0
- package/dist/esm/connectors.js +1 -1
- package/dist/esm/extended-chains.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/passkey.js +1 -1
- package/dist/esm/polyfills.js +1 -0
- package/dist/esm/smart-wallets.js +1 -1
- package/dist/esm/ui.js +1 -1
- package/dist/extended-chains.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/passkey.d.ts +2 -2
- package/dist/passkey.js +1 -1
- package/dist/polyfills.d.ts +2 -0
- package/dist/polyfills.js +1 -0
- package/dist/smart-wallets.js +1 -1
- package/dist/{types-045de424.d.ts → types-6515eff0.d.ts} +1 -1
- package/dist/ui.js +1 -1
- package/package.json +16 -6
- package/dist/chunk-K5SPDXVF.js +0 -1
- package/dist/esm/chunk-K5SPDXVF.js +0 -1
package/dist/esm/connectors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as M,c as z}from"./chunk-F7DR7TVR.js";import{b as D,c as q,e as m}from"./chunk-C5WYSLQF.js";import{base58 as u,base64 as N}from"@scure/base";import*as c from"expo-linking";import{useState as Z,useEffect as J,useRef as I,useCallback as ee}from"react";import C from"tweetnacl";import{createStore as ne}from"zustand";import{encoding as F}from"@privy-io/encoding";var E=M(z),v=(t,i,s)=>`${t}/ul/v1/${i}?${s.toString()}`,U=(t,i)=>{if(!i)throw new Error("missing shared secret");let s=C.randomBytes(24),h=C.box.after(F.utf8.toBytes(JSON.stringify(t)),s,i);return{nonce:u.encode(s),data:u.encode(h)}},K=(t,i,s)=>{if(!s)throw new Error("missing shared secret");let h=C.box.open.after(u.decode(t),u.decode(i),s);if(!h)throw new Error("Unable to decrypt data");return JSON.parse(F.utf8.fromBytes(h))},re=t=>JSON.stringify({publicKey:Array.from(t.publicKey),secretKey:Array.from(t.secretKey)}),te=t=>{let i=JSON.parse(t);return{publicKey:new Uint8Array(i.publicKey),secretKey:new Uint8Array(i.secretKey)}},B="wallet_keypair",x=6e4,W=({baseUrl:t,appUrl:i,redirectUri:s="/",autoReconnect:h=!0,encryptionPublicKeyName:l})=>{if(!t||!i||!s||!l)throw new Error("baseUrl, appUrl, redirectUri, and encryptionPublicKeyName are required");let{connection:p,setConnection:b,isConnected:P,sharedSecretRef:f}=oe({baseUrl:t,autoReconnect:h}),e=I(null),$=ee(a=>m(void 0,null,function*(){var w;if(!a)return;let n=new URL(a).searchParams,d=n.get("wallet_id");if(!d||d!==l)return;if(n.get("errorCode")){let r=Object.fromEntries([...n]),g=(w=r==null?void 0:r.errorMessage)!=null?w:JSON.stringify(Object.fromEntries([...n]),null,2);console.error("Error from wallet provider: ",g);return}switch(n.get("wallet_action")){case"onConnect":try{if(!n.get("data")||!n.get("nonce")||!n.get(l))throw console.error("missing required fields in response"),new Error("missing required fields in response");let r=yield L(),g=C.box.before(u.decode(n.get(l)),r.secretKey),y=K(n.get("data"),n.get("nonce"),g);f.current=g,b(y),yield E.put(`${t}-key`,N.encode(g)),yield E.put(`${t}-data`,JSON.stringify(y))}catch(r){console.error("Failed to process connect response:",r)}break;case"onSignMessage":try{if(!e.current||e.current.type!=="signMessage"){console.warn("Received signature response but no pending signature request");return}if(!n.get("data")||!n.get("nonce"))throw console.error("missing required fields in response"),new Error("missing required fields in response");let r=K(n.get("data"),n.get("nonce"),f.current);e.current.resolve(r),e.current=null}catch(r){console.error("Failed to process signature response:",r),e.current&&(e.current.reject(r),e.current=null)}break;case"onSignTransaction":try{if(!e.current||e.current.type!=="signTransaction"){console.warn("Received signature response but no pending signature request");return}if(!n.get("data")||!n.get("nonce"))throw console.error("missing required fields in response"),new Error("missing required fields in response");let r=K(n.get("data"),n.get("nonce"),f.current);e.current.resolve(r),e.current=null}catch(r){console.error("Failed to process transaction response:",r),e.current&&(e.current.reject(r),e.current=null)}break;case"onSignAndSendTransaction":try{if(!e.current||e.current.type!=="signAndSendTransaction"){console.warn("Received signature response but no pending signature request");return}if(!n.get("data")||!n.get("nonce"))throw console.error("missing required fields in response"),new Error("missing required fields in response");let r=K(n.get("data"),n.get("nonce"),f.current);e.current.resolve(r),e.current=null}catch(r){console.error("Failed to process transaction response:",r),e.current&&(e.current.reject(r),e.current=null)}break;case"onSignAllTransactions":try{if(!e.current||e.current.type!=="signAllTransactions"){console.warn("Received signature response but no pending signature request");return}if(!n.get("data")||!n.get("nonce"))throw console.error("missing required fields in response"),new Error("missing required fields in response");let r=K(n.get("data"),n.get("nonce"),f.current);e.current.resolve(r),e.current=null}catch(r){console.error("Failed to process transaction response:",r),e.current&&(e.current.reject(r),e.current=null)}break;case"onDisconnect":b(null);break}}),[t,l,b,f]);J(()=>{(()=>m(void 0,null,function*(){let n=yield c.getInitialURL();n&&$(n)}))();let o=c.addEventListener("url",({url:n})=>$(n).catch(d=>{e.current&&(e.current.reject(d),e.current=null)}));return()=>{o.remove()}},[l,$]);let Y=()=>m(void 0,null,function*(){try{let a=yield L();if(!a)throw new Error("No dapp key pair found");let o={session:p==null?void 0:p.session},{nonce:n,data:d}=U(o,f.current),S=new URLSearchParams({nonce:n,dapp_encryption_public_key:u.encode(a.publicKey),redirect_link:`${c.createURL(s)}?wallet_action=onDisconnect&wallet_id=${l}`,payload:d}),w=v(t,"disconnect",S);yield c.openURL(w)}catch(a){throw console.error("Failed to disconnect:",a),a}}),G=a=>m(void 0,null,function*(){if(!P||!p)throw new Error("Wallet not connected");try{let o=yield L();if(!o)throw new Error("No dapp key pair found");let n={session:p.session,message:u.encode(F.utf8.toBytes(a)),display:"utf8"},{nonce:d,data:S}=U(n,f.current),w=new URLSearchParams({dapp_encryption_public_key:u.encode(o.publicKey),nonce:d,payload:S,redirect_link:`${c.createURL(s)}?wallet_action=onSignMessage&wallet_id=${l}`}),r=v(t,"signMessage",w);return new Promise((g,y)=>{c.openURL(r);let T=setTimeout(()=>{e.current&&(y(new Error("Signature request timed out")),e.current=null)},x),k=R=>{clearTimeout(T),g(R)},A=R=>{clearTimeout(T),y(R)};e.current={type:"signMessage",payload:a,resolve:k,reject:A}})}catch(o){throw e.current=null,console.error("Failed to sign message:",o),o}}),H=(a,o)=>m(void 0,null,function*(){if(!P||!p)throw new Error("Wallet not connected");try{let n=yield L();if(!n)throw new Error("No dapp key pair found");let d=a.serialize({requireAllSignatures:!1}),S={session:p.session,transaction:u.encode(d),sendOptions:o},{nonce:w,data:r}=U(S,f.current),g=new URLSearchParams({nonce:w,dapp_encryption_public_key:u.encode(n.publicKey),redirect_link:`${c.createURL(s)}?wallet_action=onSignAndSendTransaction&wallet_id=${l}`,payload:r}),y=v(t,"signAndSendTransaction",g);return new Promise((T,k)=>{c.openURL(y);let A=setTimeout(()=>{e.current&&(k(new Error("Signature request timed out")),e.current=null)},x),R=O=>{clearTimeout(A),T(O)},_=O=>{clearTimeout(A),k(O)};e.current={type:"signAndSendTransaction",payload:a,resolve:R,reject:_}})}catch(n){throw e.current=null,console.error("Failed to sign and send transaction:",n),n}}),Q=a=>m(void 0,null,function*(){if(!P||!p)throw new Error("Wallet not connected");try{let o=yield L();if(!o)throw new Error("No dapp key pair found");let d={transactions:a.map(y=>u.encode(y.serialize({requireAllSignatures:!1}))),session:p.session},{nonce:S,data:w}=U(d,f.current),r=new URLSearchParams({nonce:S,dapp_encryption_public_key:u.encode(o.publicKey),redirect_link:`${c.createURL(s)}?wallet_action=onSignAllTransactions&wallet_id=${l}`,payload:w}),g=v(t,"signAllTransactions",r);return new Promise((y,T)=>{c.openURL(g);let k=setTimeout(()=>{e.current&&(T(new Error("Signature request timed out")),e.current=null)},x),A=_=>{clearTimeout(k),y(_)},R=_=>{clearTimeout(k),T(_)};e.current={type:"signAllTransactions",payload:a,resolve:A,reject:R}})}catch(o){throw e.current=null,console.error("Failed to sign all transactions:",o),o}}),V=a=>m(void 0,null,function*(){if(!P||!p)throw new Error("Wallet not connected");try{let o=yield L();if(!o)throw new Error("No dapp key pair found");let n=a.serialize({requireAllSignatures:!1}),d={session:p.session,transaction:u.encode(n)},{nonce:S,data:w}=U(d,f.current),r=new URLSearchParams({nonce:S,dapp_encryption_public_key:u.encode(o.publicKey),redirect_link:`${c.createURL(s)}?wallet_action=onSignTransaction&wallet_id=${l}`,payload:w}),g=v(t,"signTransaction",r);return new Promise((y,T)=>{c.openURL(g);let k=setTimeout(()=>{e.current&&(T(new Error("Signature request timed out")),e.current=null)},x),A=_=>{clearTimeout(k),y(_)},R=_=>{clearTimeout(k),T(_)};e.current={type:"signTransaction",payload:a,resolve:A,reject:R}})}catch(o){throw e.current=null,console.error("Failed to sign transaction:",o),o}}),X=()=>m(void 0,null,function*(){let a=yield L();if(!a)throw new Error("No dapp key pair found");try{let o=new URLSearchParams({dapp_encryption_public_key:u.encode(a.publicKey),app_url:i,redirect_link:`${c.createURL(s)}?wallet_action=onConnect&wallet_id=${l}`}),n=v(t,"connect",o);yield c.openURL(n)}catch(o){console.error("Failed to open wallet connection:",o)}});return{address:p==null?void 0:p.public_key,connect:X,signMessage:G,signTransaction:V,signAndSendTransaction:H,signAllTransactions:Q,disconnect:Y,isConnected:P}},oe=({autoReconnect:t,baseUrl:i})=>{let[s,h]=Z(null),l=I(null);return J(()=>{let p=()=>m(void 0,null,function*(){let b=yield E.get(`${i}-key`),P=yield E.get(`${i}-data`);b&&P&&(l.current=N.decode(b),h(JSON.parse(P)))});t&&!l.current&&p().catch(console.warn)},[t,i]),{connection:s,setConnection:h,isConnected:!!s,sharedSecretRef:l}},j=ne(()=>({dappKeyPair:null})),L=()=>m(void 0,null,function*(){let t=j.getState().dappKeyPair;if(t)return t;try{let i=yield E.get(B);if(i&&typeof i=="string"){let s=te(i);return j.setState({dappKeyPair:s}),s}else{let s=C.box.keyPair();return j.setState({dappKeyPair:s}),yield E.put(B,re(s)),s}}catch(i){throw console.error("Failed to initialize key pair:",i),i}});var ye=t=>W(q(D({},t),{baseUrl:"https://phantom.app",encryptionPublicKeyName:"phantom_encryption_public_key"}));var Se=t=>W(q(D({},t),{baseUrl:"https://backpack.app",encryptionPublicKeyName:"wallet_encryption_public_key"}));export{Se as useBackpackDeeplinkWalletConnector,W as useDeeplinkWalletConnector,ye as usePhantomDeeplinkWalletConnector};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as u,m as i}from"./chunk-
|
|
1
|
+
import{b as u,m as i}from"./chunk-6LJTXHKE.js";import"./chunk-F7DR7TVR.js";import"./chunk-3HF374LL.js";import{e as a}from"./chunk-C5WYSLQF.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};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Dt,b as Gt,c as jt,d as Et,e as _t,f as Bt,g as Mt,h as qt}from"./chunk-QSWCX5XI.js";import{a as f,b as I}from"./chunk-
|
|
1
|
+
import{a as Dt,b as Gt,c as jt,d as Et,e as _t,f as Bt,g as Mt,h as qt}from"./chunk-QSWCX5XI.js";import{a as f,b as I}from"./chunk-B42N35ZL.js";import{$ as It,A as et,B as ot,C as rt,D as nt,E as ut,F as it,G as pt,H as st,I as ht,J as at,K as ft,L as At,M as Ot,N as ct,O as mt,P as kt,Q as lt,R as yt,V as xt,W as dt,X as Ut,Y as Pt,Z as vt,_ as wt,aa as d,ba as Tt,ca as gt,da as Ft,e as y,ea as St,f as G,fa as Lt,ga as Wt,h as x,ha as Rt,ia as Ht,j as v,ja as Ct,k as j,ka as w,l as E,la as a,m as _,ma as Nt,n as B,na as bt,o as M,p as q,q as z,r as J,s as K,t as Q,u as V,v as X,w as Y,x as Z,y as $,z as tt}from"./chunk-6LJTXHKE.js";import{c as P}from"./chunk-F7DR7TVR.js";import"./chunk-3HF374LL.js";import{b as m,c as k,e as l}from"./chunk-C5WYSLQF.js";export*from"@privy-io/js-sdk-core";import r from"react";var Qt=({loading:t,error:e,unauthenticated:o,children:i})=>{let{isReady:u,error:p}=d(),U=y();if(!u)return r.createElement(r.Fragment,null,t);if(p&&e){let n=typeof e=="function"?e(p):e;return r.createElement(r.Fragment,null,n)}return U?r.createElement(r.Fragment,null,i):r.createElement(r.Fragment,null,o)};import{createDataSuffixPlugin as T}from"@privy-io/js-sdk-core";function g(t){return f(t)}function F(t){let{state:e,start:o}=f(k(m({},t),{action:"link"}));return{state:e,link:o}}import{useCallback as S,useContext as L,useEffect as W,useRef as R}from"react";var H=t=>{let{client:e}=L(a),o=R(t);return W(()=>{o.current=t},[t]),{unlinkOAuth:S(U=>l(void 0,[U],function*({provider:u,subject:p}){var n,A,s,O;try{let{user:h}=yield e.auth.oauth.unlink(u,p);return(A=(n=o.current)==null?void 0:n.onSuccess)==null||A.call(n,h),h}catch(h){let c=x(h);throw(O=(s=o.current)==null?void 0:s.onError)==null||O.call(s,c),c}}),[e.auth.oauth])}};import{useContext as C,useEffect as N,useRef as b}from"react";var D=t=>{let{client:e}=C(a),o=b(t.onOAuthTokenGrant);o.current=t.onOAuthTokenGrant,N(()=>{let{unsubscribe:i}=e.addOAuthTokensListener(u=>{o.current(u)});return i},[e])};export{Qt as AuthBoundary,a as PrivyContext,bt as PrivyProvider,P as SecureStorageAdapter,v as createPrivyClient,T as dataSuffix,Nt as getAccessToken,Mt as hasError,Dt as isConnected,jt as isConnecting,Bt as isCreating,Et as isDisconnected,_t as isNotCreated,Gt as isReconnecting,qt as needsRecovery,Tt as useAcceptTerms,gt as useAuthorizationSignature,lt as useCreateGuestAccount,et as useDepositAddress,It as useEmbeddedBitcoinWallet,vt as useEmbeddedEthereumWallet,wt as useEmbeddedSolanaWallet,ct as useEmbeddedWallet,mt as useEmbeddedWalletStateChange,Ft as useGetEncryptedAuthorizationKey,ot as useHeadlessCryptoDeposit,tt as useHeadlessDelegatedActions,kt as useIdentityToken,Pt as useImportWallet,z as useLinkEmail,Q as useLinkSMS,st as useLinkWithCrossApp,X as useLinkWithFarcaster,F as useLinkWithOAuth,j as useLinkWithSiwe,B as useLinkWithSiws,pt as useLoginWithCrossApp,K as useLoginWithEmail,Z as useLoginWithFarcaster,$ as useLoginWithFarcasterV2,I as useLoginWithOAuth,V as useLoginWithSMS,E as useLoginWithSiwe,M as useLoginWithSiws,xt as useMfa,dt as useMfaEnrollment,w as useMigrateWallets,g as useOAuthFlow,D as useOAuthTokens,G as useOnNeedsRecovery,d as usePrivy,_ as usePrivyClient,Ot as useRecoverEmbeddedWallet,yt as useRegisterMfaListener,ft as useSendTransactionWithCrossApp,rt as useSessionSigners,At as useSetEmbeddedWalletRecovery,St as useSign7702Authorization,ht as useSignMessageWithCrossApp,at as useSignTypedDataWithCrossApp,nt as useSigners,Ht as useStoredUsers,Ct as useSwitchUser,Lt as useTransfer,J as useUnlinkEmail,Y as useUnlinkFarcaster,H as useUnlinkOAuth,Ut as useUnlinkPasskey,q as useUnlinkWallet,ut as useUpdateEmail,it as useUpdatePhone,Wt as useUpdateWallet,Rt as useWalletActions};
|
package/dist/esm/passkey.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as K,b as N,c as V,d as D,e as F,f as T,g as M,h as j}from"./chunk-QSWCX5XI.js";import{S as _,T as x,U as b,a as w,b as g,h,la as P}from"./chunk-
|
|
1
|
+
import{a as K,b as N,c as V,d as D,e as F,f as T,g as M,h as j}from"./chunk-QSWCX5XI.js";import{S as _,T as x,U as b,a as w,b as g,h,la as P}from"./chunk-6LJTXHKE.js";import"./chunk-F7DR7TVR.js";import"./chunk-3HF374LL.js";import{e as p}from"./chunk-C5WYSLQF.js";import{useCallback as W,useContext as R}from"react";import{PrivyClientError as v}from"@privy-io/js-sdk-core";var Y=e=>{let{client:a,passkeyState:d,setPasskeyState:s}=R(P),c=W(o=>{var n;let t=h(o);return s({status:"error",error:t}),(n=e==null?void 0:e.onError)==null||n.call(e,t),t},[e==null?void 0:e.onError]);return{linkWithPasskey:W(n=>p(void 0,[n],function*({relyingParty:o,extra_options:t}){var u;try{if(!g())throw new v({code:"attempted_link_passkey_before_logged_in",error:"Must be logged in to link a passkey."});s({status:"generating-challenege"});let{options:k}=yield a.auth.passkey.generateRegistrationOptions(o);s({status:"awaiting-passkey"});let y=yield _(b(k),t);s({status:"submitting-response"});let{user:m}=yield a.auth.passkey.linkWithPasskey(y,o);return s({status:"done"}),(u=e==null?void 0:e.onSuccess)==null||u.call(e,m),m}catch(r){throw c(r)}}),[a,c,e==null?void 0:e.onSuccess]),state:d}};import{useCallback as O,useContext as H}from"react";import{PrivyClientError as I}from"@privy-io/js-sdk-core";var ie=e=>{let{client:a,passkeyState:d,setPasskeyState:s}=H(P),c=O(o=>{var n;let t=h(o);return s({status:"error",error:t}),(n=e==null?void 0:e.onError)==null||n.call(e,t),t},[e==null?void 0:e.onError]);return{loginWithPasskey:O(n=>p(void 0,[n],function*({relyingParty:o,extra_options:t}){var u,r,k,y;try{if(g())throw new I({code:"attempted_login_with_passkey_while_already_logged_in",error:"Already logged in, use `useLinkWithPasskey` if you are trying to link a passkey to an existing account"});s({status:"generating-challenege"});let{options:i}=yield a.auth.passkey.generateAuthenticationOptions(o);s({status:"awaiting-passkey"});let f=yield x({challenge:i.challenge,rpId:i.rp_id,extensions:{appid:(u=i.extensions)==null?void 0:u.app_id,credProps:(r=i.extensions)==null?void 0:r.cred_props,hmacCreateSecret:(k=i.extensions)==null?void 0:k.hmac_create_secret},timeout:i.timeout,allowCredentials:i.allow_credentials,userVerification:i.user_verification},t);s({status:"submitting-response"});let l=w(),C=yield a.auth.passkey.loginWithPasskey(f,i.challenge,o,{embedded:l==null?void 0:l.embedded});return s({status:"done"}),(y=e==null?void 0:e.onSuccess)==null||y.call(e,C.user,C.is_new_user),C.user}catch(m){throw c(m)}}),[a,c,e==null?void 0:e.onSuccess]),state:d}};import{useCallback as U,useContext as L,useEffect as A,useRef as q}from"react";import{PrivyClientError as J}from"@privy-io/js-sdk-core";var ge=e=>{let{client:a,passkeyState:d,setPasskeyState:s}=L(P),c=q(e);A(()=>{c.current=e},[e]);let S=U(t=>{var u,r;let n=h(t);return s({status:"error",error:n}),(r=(u=c.current)==null?void 0:u.onError)==null||r.call(u,n),n},[s]);return{signupWithPasskey:U(u=>p(void 0,[u],function*({relyingParty:t,extra_options:n}){var r,k;try{if(g())throw new J({code:"attempted_login_with_passkey_while_already_logged_in",error:"Already logged in, use `useLinkWithPasskey` if you are trying to link a passkey to an existing account"});s({status:"generating-challenege"});let{options:m}=yield a.auth.passkey.generateSignupOptions(t);s({status:"awaiting-passkey"});let i=yield _(b(m),n);s({status:"submitting-response"});let f=w(),l=yield a.auth.passkey.signupWithPasskey(i,t,{embedded:f==null?void 0:f.embedded});return s({status:"done"}),(k=(r=c.current)==null?void 0:r.onSuccess)==null||k.call(r,l.user,l.is_new_user),{user:l.user}}catch(y){throw S(y)}}),[a.auth.passkey,S,s]),state:d}};export{M as hasError,K as isConnected,V as isConnecting,T as isCreating,D as isDisconnected,F as isNotCreated,N as isReconnecting,j as needsRecovery,Y as useLinkWithPasskey,ie as useLoginWithPasskey,ge as useSignupWithPasskey};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"./chunk-3HF374LL.js";import"./chunk-C5WYSLQF.js";o();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as M}from"./chunk-QSWCX5XI.js";import{b as _,d as g,i as v,la as w,m as k}from"./chunk-
|
|
1
|
+
import{a as M}from"./chunk-QSWCX5XI.js";import{b as _,d as g,i as v,la as w,m as k}from"./chunk-6LJTXHKE.js";import"./chunk-F7DR7TVR.js";import"./chunk-3HF374LL.js";import{a as h,b as A,c as I,e as m}from"./chunk-C5WYSLQF.js";import p,{createContext as x,useCallback as Z,useContext as f,useEffect as T,useState as L}from"react";import{getDataSuffixPlugin as O,getUserSmartWallet as S,PrivyClientError as u}from"@privy-io/js-sdk-core";import{createPublicClient as Y,http as H}from"viem";import{getJsonRpcEndpointFromChain as X,getUserSmartWallet as j,PrivyClientError as N}from"@privy-io/js-sdk-core";import{signerToSmartAccountClient as J}from"@privy-io/js-sdk-core/smart-wallets";var P=y=>m(void 0,[y],function*({chain:t,privyAppId:e,user:a,embeddedWallet:r,smartWalletsConfig:n,client:i,dataSuffix:c}){if(!(n!=null&&n.enabled)||!r||!M(r))return;let s=yield i.embeddedWallet.getProvider(r.account),o=n==null?void 0:n.configured_networks.find(B=>B.chain_id===`eip155:${t.id}`);if(!o)throw new N({code:"chain_not_supported",error:`The chain ${t.name} (eip155:${t.id}) must be configured in the smart wallet configuration in your dashboard`});let l=j(a),C=l?l.smart_wallet_type:n.smart_wallet_type,W=l?l.smart_wallet_version:n.smart_wallet_version,F=X(t,{rpcUrls:[]},e),G=Y({chain:t,transport:H(F)}),E=yield J({owner:s,smartWalletType:C,smartWalletVersion:W,chain:t,publicClient:G,paymasterContext:Q(o.paymaster_url,o.paymaster_context),bundlerUrl:o.bundler_url,paymasterUrl:o.paymaster_url});if(!E)throw new N({code:"smart_wallet_client_error",error:`Failed to create smart wallet client for chain ${t.name} (eip155:${t.id})`});return K(E,c)});function K(t,e){return e?t.extend(a=>({sendTransaction:r=>a.sendTransaction(I(A({},r),{dataSuffix:e}))})):t}var V=/paymaster\.biconomy\.io\/api/i;function q(t){return V.test(t)}var z={mode:"SPONSORED",calculateGasLimits:!0,expiryDuration:300,sponsorshipInfo:{webhookData:{},smartAccountInfo:{name:"BICONOMY",version:"2.0.0"}}},Q=(t,e)=>{if(t&&q(t))return z;if(e&&e.policy_id)return{policyId:e.policy_id}};var U=3,tt=500,et=({children:t})=>p.createElement(at,null,p.createElement(it,null,p.createElement(lt,null,t))),D=x({config:void 0}),b=()=>{let{config:t}=f(D);return{config:t}},R=x({smartWalletClient:void 0}),rt=()=>{let{smartWalletClient:t}=f(R);return{smartWalletClient:t}},$=x({client:void 0}),nt=()=>{let{client:t}=f($),e=ot();return{client:t,getClientForChain:e}},at=({children:t})=>{let[e,a]=L(void 0),r=k();return T(()=>{!e&&r&&(()=>m(void 0,null,function*(){try{if(!r){console.warn("No client found");return}let i=yield r.app.getSmartWalletConfig();a(i)}catch(i){console.warn("Error generating smart wallet config: ",i)}}))()},[r,e]),p.createElement(D.Provider,{value:{config:e}},t)},it=({children:t})=>{let{config:e}=b(),{client:a,wallet:r}=f(w),n=g(),[i,c]=L();return T(()=>{(()=>m(void 0,null,function*(){var l;if(!n&&i&&c(void 0),!(e!=null&&e.enabled)||!n||r.status!=="connected"||n&&i&&r.status==="connected")return;let s=a.embeddedWallet.chains.find(C=>e.configured_networks.map(W=>W.chain_id).includes(`eip155:${C.id}`));if(!s)throw new u({error:"Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.",code:"chain_not_supported"});let o=yield P({chain:s,privyAppId:a.app.appId,user:n,embeddedWallet:r,smartWalletsConfig:e,client:a,dataSuffix:(l=O(a.plugins))==null?void 0:l.suffix});if(!o)throw new u({error:"Could not create smart wallet client",code:"smart_wallet_client_error"});c(o)}))()},[!!(e!=null&&e.enabled),!!a,!!n,r.status]),p.createElement(R.Provider,{value:{smartWalletClient:i}},t)},lt=({children:t})=>{let{client:e,wallet:a}=f(w),r=g(),{smartWalletClient:n}=rt(),{config:i}=b();return T(()=>{let c=!1;return(()=>m(void 0,null,function*(){var d;if(!(!n||!r||S(r)||!(i!=null&&i.enabled)||a.status!=="connected"))for(let s=0;s<U;s++){if(c||S((d=_())!=null?d:r))return;let o=!1;for(let l=0;l<5;l++){if(c)return;if(yield e.embeddedWallet.ping(tt)){o=!0;break}yield v(200*h(2,l))}if(o)try{let{message:l}=yield e.auth.smartWallet.init({address:n.account.address,chainId:`eip155:${n.chain.id}`}),C=yield n.signMessage({message:l});yield e.auth.smartWallet.link(l,C,i.smart_wallet_type,i.smart_wallet_version);return}catch(l){s===U-1?console.error("Error creating smart wallet:",l):yield v(500*h(2,s))}}}))(),()=>{c=!0}},[!!n,!!r,!!S(r),i,a.status]),p.createElement($.Provider,{value:{client:S(r)?n:void 0}},t)},ot=()=>{let{client:t,wallet:e}=f(w),{config:a}=b();return Z(n=>m(void 0,[n],function*({chainId:r}){var s;let i=_();if(!i)throw new u({error:"Must be logged in to get a smart wallet client",code:"smart_wallet_client_error"});if(!a||!a.enabled)throw new u({error:"Must have smart wallets enabled to get a smart wallet client",code:"smart_wallet_client_error"});let y=t.embeddedWallet.chains.find(o=>o.id===r);if(!y)throw new u({error:`Could not find chain with id: ${r}`,code:"chain_not_supported"});let d=yield P({chain:y,privyAppId:t.app.appId,user:i,embeddedWallet:e,smartWalletsConfig:a,client:t,dataSuffix:(s=O(t.plugins))==null?void 0:s.suffix});if(!d)throw new u({error:`Could not create smart wallet client for chain ${r}`,code:"smart_wallet_client_error"});return d}),[a,e,t])};export{et as SmartWalletsProvider,nt as useSmartWallets};
|