@zerodev/wallet-core 0.0.1-alpha.10
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 +310 -0
- package/dist/_cjs/actions/auth/authenticateWithEmail.js +17 -0
- package/dist/_cjs/actions/auth/authenticateWithEmail.js.map +1 -0
- package/dist/_cjs/actions/auth/authenticateWithOAuth.js +13 -0
- package/dist/_cjs/actions/auth/authenticateWithOAuth.js.map +1 -0
- package/dist/_cjs/actions/auth/getAuthProxyConfigId.js +10 -0
- package/dist/_cjs/actions/auth/getAuthProxyConfigId.js.map +1 -0
- package/dist/_cjs/actions/auth/getUserEmail.js +19 -0
- package/dist/_cjs/actions/auth/getUserEmail.js.map +1 -0
- package/dist/_cjs/actions/auth/getWhoami.js +15 -0
- package/dist/_cjs/actions/auth/getWhoami.js.map +1 -0
- package/dist/_cjs/actions/auth/index.js +22 -0
- package/dist/_cjs/actions/auth/index.js.map +1 -0
- package/dist/_cjs/actions/auth/loginWithOTP.js +15 -0
- package/dist/_cjs/actions/auth/loginWithOTP.js.map +1 -0
- package/dist/_cjs/actions/auth/loginWithStamp.js +39 -0
- package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -0
- package/dist/_cjs/actions/auth/registerWithOTP.js +16 -0
- package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -0
- package/dist/_cjs/actions/auth/registerWithPasskey.js +17 -0
- package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -0
- package/dist/_cjs/actions/index.js +17 -0
- package/dist/_cjs/actions/index.js.map +1 -0
- package/dist/_cjs/actions/wallet/getUserWallet.js +18 -0
- package/dist/_cjs/actions/wallet/getUserWallet.js.map +1 -0
- package/dist/_cjs/actions/wallet/index.js +10 -0
- package/dist/_cjs/actions/wallet/index.js.map +1 -0
- package/dist/_cjs/actions/wallet/signRawPayload.js +27 -0
- package/dist/_cjs/actions/wallet/signRawPayload.js.map +1 -0
- package/dist/_cjs/actions/wallet/signTransaction.js +26 -0
- package/dist/_cjs/actions/wallet/signTransaction.js.map +1 -0
- package/dist/_cjs/adapters/viem.js +92 -0
- package/dist/_cjs/adapters/viem.js.map +1 -0
- package/dist/_cjs/client/authProxy.js +31 -0
- package/dist/_cjs/client/authProxy.js.map +1 -0
- package/dist/_cjs/client/createClient.js +49 -0
- package/dist/_cjs/client/createClient.js.map +1 -0
- package/dist/_cjs/client/decorators/client.js +23 -0
- package/dist/_cjs/client/decorators/client.js.map +1 -0
- package/dist/_cjs/client/index.js +11 -0
- package/dist/_cjs/client/index.js.map +1 -0
- package/dist/_cjs/client/transports/createTransport.js +31 -0
- package/dist/_cjs/client/transports/createTransport.js.map +1 -0
- package/dist/_cjs/client/transports/rest.js +104 -0
- package/dist/_cjs/client/transports/rest.js.map +1 -0
- package/dist/_cjs/client/types.js +3 -0
- package/dist/_cjs/client/types.js.map +1 -0
- package/dist/_cjs/constants.js +9 -0
- package/dist/_cjs/constants.js.map +1 -0
- package/dist/_cjs/core/createZeroDevWallet.js +302 -0
- package/dist/_cjs/core/createZeroDevWallet.js.map +1 -0
- package/dist/_cjs/errors/request.js +61 -0
- package/dist/_cjs/errors/request.js.map +1 -0
- package/dist/_cjs/index.js +35 -0
- package/dist/_cjs/index.js.map +1 -0
- package/dist/_cjs/package.json +1 -0
- package/dist/_cjs/polyfills/window.js +26 -0
- package/dist/_cjs/polyfills/window.js.map +1 -0
- package/dist/_cjs/stampers/iframeStamper.js +35 -0
- package/dist/_cjs/stampers/iframeStamper.js.map +1 -0
- package/dist/_cjs/stampers/index.js +10 -0
- package/dist/_cjs/stampers/index.js.map +1 -0
- package/dist/_cjs/stampers/indexedDbStamper.js +23 -0
- package/dist/_cjs/stampers/indexedDbStamper.js.map +1 -0
- package/dist/_cjs/stampers/types.js +3 -0
- package/dist/_cjs/stampers/types.js.map +1 -0
- package/dist/_cjs/stampers/webauthnStamper.js +17 -0
- package/dist/_cjs/stampers/webauthnStamper.js.map +1 -0
- package/dist/_cjs/storage/adapters.js +18 -0
- package/dist/_cjs/storage/adapters.js.map +1 -0
- package/dist/_cjs/storage/manager.js +108 -0
- package/dist/_cjs/storage/manager.js.map +1 -0
- package/dist/_cjs/types/session.js +9 -0
- package/dist/_cjs/types/session.js.map +1 -0
- package/dist/_cjs/utils/buildClientSignature.js +39 -0
- package/dist/_cjs/utils/buildClientSignature.js.map +1 -0
- package/dist/_cjs/utils/derToRawSignature.js +63 -0
- package/dist/_cjs/utils/derToRawSignature.js.map +1 -0
- package/dist/_cjs/utils/exportPrivateKey.js +55 -0
- package/dist/_cjs/utils/exportPrivateKey.js.map +1 -0
- package/dist/_cjs/utils/exportWallet.js +70 -0
- package/dist/_cjs/utils/exportWallet.js.map +1 -0
- package/dist/_cjs/utils/utils.js +75 -0
- package/dist/_cjs/utils/utils.js.map +1 -0
- package/dist/_esm/actions/auth/authenticateWithEmail.js +18 -0
- package/dist/_esm/actions/auth/authenticateWithEmail.js.map +1 -0
- package/dist/_esm/actions/auth/authenticateWithOAuth.js +29 -0
- package/dist/_esm/actions/auth/authenticateWithOAuth.js.map +1 -0
- package/dist/_esm/actions/auth/getAuthProxyConfigId.js +13 -0
- package/dist/_esm/actions/auth/getAuthProxyConfigId.js.map +1 -0
- package/dist/_esm/actions/auth/getUserEmail.js +33 -0
- package/dist/_esm/actions/auth/getUserEmail.js.map +1 -0
- package/dist/_esm/actions/auth/getWhoami.js +28 -0
- package/dist/_esm/actions/auth/getWhoami.js.map +1 -0
- package/dist/_esm/actions/auth/index.js +10 -0
- package/dist/_esm/actions/auth/index.js.map +1 -0
- package/dist/_esm/actions/auth/loginWithOTP.js +38 -0
- package/dist/_esm/actions/auth/loginWithOTP.js.map +1 -0
- package/dist/_esm/actions/auth/loginWithStamp.js +52 -0
- package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -0
- package/dist/_esm/actions/auth/registerWithOTP.js +35 -0
- package/dist/_esm/actions/auth/registerWithOTP.js.map +1 -0
- package/dist/_esm/actions/auth/registerWithPasskey.js +36 -0
- package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -0
- package/dist/_esm/actions/index.js +5 -0
- package/dist/_esm/actions/index.js.map +1 -0
- package/dist/_esm/actions/wallet/getUserWallet.js +31 -0
- package/dist/_esm/actions/wallet/getUserWallet.js.map +1 -0
- package/dist/_esm/actions/wallet/index.js +4 -0
- package/dist/_esm/actions/wallet/index.js.map +1 -0
- package/dist/_esm/actions/wallet/signRawPayload.js +42 -0
- package/dist/_esm/actions/wallet/signRawPayload.js.map +1 -0
- package/dist/_esm/actions/wallet/signTransaction.js +41 -0
- package/dist/_esm/actions/wallet/signTransaction.js.map +1 -0
- package/dist/_esm/adapters/viem.js +94 -0
- package/dist/_esm/adapters/viem.js.map +1 -0
- package/dist/_esm/client/authProxy.js +41 -0
- package/dist/_esm/client/authProxy.js.map +1 -0
- package/dist/_esm/client/createClient.js +60 -0
- package/dist/_esm/client/createClient.js.map +1 -0
- package/dist/_esm/client/decorators/client.js +44 -0
- package/dist/_esm/client/decorators/client.js.map +1 -0
- package/dist/_esm/client/index.js +4 -0
- package/dist/_esm/client/index.js.map +1 -0
- package/dist/_esm/client/transports/createTransport.js +33 -0
- package/dist/_esm/client/transports/createTransport.js.map +1 -0
- package/dist/_esm/client/transports/rest.js +103 -0
- package/dist/_esm/client/transports/rest.js.map +1 -0
- package/dist/_esm/client/types.js +2 -0
- package/dist/_esm/client/types.js.map +1 -0
- package/dist/_esm/constants.js +6 -0
- package/dist/_esm/constants.js.map +1 -0
- package/dist/_esm/core/createZeroDevWallet.js +308 -0
- package/dist/_esm/core/createZeroDevWallet.js.map +1 -0
- package/dist/_esm/errors/request.js +60 -0
- package/dist/_esm/errors/request.js.map +1 -0
- package/dist/_esm/index.js +23 -0
- package/dist/_esm/index.js.map +1 -0
- package/dist/_esm/package.json +1 -0
- package/dist/_esm/polyfills/window.js +24 -0
- package/dist/_esm/polyfills/window.js.map +1 -0
- package/dist/_esm/stampers/iframeStamper.js +32 -0
- package/dist/_esm/stampers/iframeStamper.js.map +1 -0
- package/dist/_esm/stampers/index.js +4 -0
- package/dist/_esm/stampers/index.js.map +1 -0
- package/dist/_esm/stampers/indexedDbStamper.js +20 -0
- package/dist/_esm/stampers/indexedDbStamper.js.map +1 -0
- package/dist/_esm/stampers/types.js +2 -0
- package/dist/_esm/stampers/types.js.map +1 -0
- package/dist/_esm/stampers/webauthnStamper.js +15 -0
- package/dist/_esm/stampers/webauthnStamper.js.map +1 -0
- package/dist/_esm/storage/adapters.js +15 -0
- package/dist/_esm/storage/adapters.js.map +1 -0
- package/dist/_esm/storage/manager.js +118 -0
- package/dist/_esm/storage/manager.js.map +1 -0
- package/dist/_esm/types/session.js +6 -0
- package/dist/_esm/types/session.js.map +1 -0
- package/dist/_esm/utils/buildClientSignature.js +64 -0
- package/dist/_esm/utils/buildClientSignature.js.map +1 -0
- package/dist/_esm/utils/derToRawSignature.js +89 -0
- package/dist/_esm/utils/derToRawSignature.js.map +1 -0
- package/dist/_esm/utils/exportPrivateKey.js +83 -0
- package/dist/_esm/utils/exportPrivateKey.js.map +1 -0
- package/dist/_esm/utils/exportWallet.js +98 -0
- package/dist/_esm/utils/exportWallet.js.map +1 -0
- package/dist/_esm/utils/utils.js +105 -0
- package/dist/_esm/utils/utils.js.map +1 -0
- package/dist/_types/actions/auth/authenticateWithEmail.d.ts +33 -0
- package/dist/_types/actions/auth/authenticateWithEmail.d.ts.map +1 -0
- package/dist/_types/actions/auth/authenticateWithOAuth.d.ts +38 -0
- package/dist/_types/actions/auth/authenticateWithOAuth.d.ts.map +1 -0
- package/dist/_types/actions/auth/getAuthProxyConfigId.d.ts +12 -0
- package/dist/_types/actions/auth/getAuthProxyConfigId.d.ts.map +1 -0
- package/dist/_types/actions/auth/getUserEmail.d.ts +32 -0
- package/dist/_types/actions/auth/getUserEmail.d.ts.map +1 -0
- package/dist/_types/actions/auth/getWhoami.d.ts +35 -0
- package/dist/_types/actions/auth/getWhoami.d.ts.map +1 -0
- package/dist/_types/actions/auth/index.d.ts +10 -0
- package/dist/_types/actions/auth/index.d.ts.map +1 -0
- package/dist/_types/actions/auth/loginWithOTP.d.ts +41 -0
- package/dist/_types/actions/auth/loginWithOTP.d.ts.map +1 -0
- package/dist/_types/actions/auth/loginWithStamp.d.ts +37 -0
- package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -0
- package/dist/_types/actions/auth/registerWithOTP.d.ts +46 -0
- package/dist/_types/actions/auth/registerWithOTP.d.ts.map +1 -0
- package/dist/_types/actions/auth/registerWithPasskey.d.ts +53 -0
- package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -0
- package/dist/_types/actions/index.d.ts +3 -0
- package/dist/_types/actions/index.d.ts.map +1 -0
- package/dist/_types/actions/wallet/getUserWallet.d.ts +34 -0
- package/dist/_types/actions/wallet/getUserWallet.d.ts.map +1 -0
- package/dist/_types/actions/wallet/index.d.ts +4 -0
- package/dist/_types/actions/wallet/index.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signRawPayload.d.ts +39 -0
- package/dist/_types/actions/wallet/signRawPayload.d.ts.map +1 -0
- package/dist/_types/actions/wallet/signTransaction.d.ts +35 -0
- package/dist/_types/actions/wallet/signTransaction.d.ts.map +1 -0
- package/dist/_types/adapters/viem.d.ts +10 -0
- package/dist/_types/adapters/viem.d.ts.map +1 -0
- package/dist/_types/client/authProxy.d.ts +36 -0
- package/dist/_types/client/authProxy.d.ts.map +1 -0
- package/dist/_types/client/createClient.d.ts +17 -0
- package/dist/_types/client/createClient.d.ts.map +1 -0
- package/dist/_types/client/decorators/client.d.ts +81 -0
- package/dist/_types/client/decorators/client.d.ts.map +1 -0
- package/dist/_types/client/index.d.ts +5 -0
- package/dist/_types/client/index.d.ts.map +1 -0
- package/dist/_types/client/transports/createTransport.d.ts +17 -0
- package/dist/_types/client/transports/createTransport.d.ts.map +1 -0
- package/dist/_types/client/transports/rest.d.ts +35 -0
- package/dist/_types/client/transports/rest.d.ts.map +1 -0
- package/dist/_types/client/types.d.ts +59 -0
- package/dist/_types/client/types.d.ts.map +1 -0
- package/dist/_types/constants.d.ts +6 -0
- package/dist/_types/constants.d.ts.map +1 -0
- package/dist/_types/core/createZeroDevWallet.d.ts +52 -0
- package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -0
- package/dist/_types/errors/request.d.ts +12 -0
- package/dist/_types/errors/request.d.ts.map +1 -0
- package/dist/_types/index.d.ts +20 -0
- package/dist/_types/index.d.ts.map +1 -0
- package/dist/_types/polyfills/window.d.ts +15 -0
- package/dist/_types/polyfills/window.d.ts.map +1 -0
- package/dist/_types/stampers/iframeStamper.d.ts +7 -0
- package/dist/_types/stampers/iframeStamper.d.ts.map +1 -0
- package/dist/_types/stampers/index.d.ts +5 -0
- package/dist/_types/stampers/index.d.ts.map +1 -0
- package/dist/_types/stampers/indexedDbStamper.d.ts +3 -0
- package/dist/_types/stampers/indexedDbStamper.d.ts.map +1 -0
- package/dist/_types/stampers/types.d.ts +25 -0
- package/dist/_types/stampers/types.d.ts.map +1 -0
- package/dist/_types/stampers/webauthnStamper.d.ts +5 -0
- package/dist/_types/stampers/webauthnStamper.d.ts.map +1 -0
- package/dist/_types/storage/adapters.d.ts +3 -0
- package/dist/_types/storage/adapters.d.ts.map +1 -0
- package/dist/_types/storage/manager.d.ts +19 -0
- package/dist/_types/storage/manager.d.ts.map +1 -0
- package/dist/_types/types/session.d.ts +17 -0
- package/dist/_types/types/session.d.ts.map +1 -0
- package/dist/_types/utils/buildClientSignature.d.ts +25 -0
- package/dist/_types/utils/buildClientSignature.d.ts.map +1 -0
- package/dist/_types/utils/derToRawSignature.d.ts +11 -0
- package/dist/_types/utils/derToRawSignature.d.ts.map +1 -0
- package/dist/_types/utils/exportPrivateKey.d.ts +47 -0
- package/dist/_types/utils/exportPrivateKey.d.ts.map +1 -0
- package/dist/_types/utils/exportWallet.d.ts +44 -0
- package/dist/_types/utils/exportWallet.d.ts.map +1 -0
- package/dist/_types/utils/utils.d.ts +52 -0
- package/dist/_types/utils/utils.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +74 -0
- package/src/actions/auth/authenticateWithEmail.ts +52 -0
- package/src/actions/auth/authenticateWithOAuth.ts +52 -0
- package/src/actions/auth/getAuthProxyConfigId.ts +20 -0
- package/src/actions/auth/getUserEmail.ts +52 -0
- package/src/actions/auth/getWhoami.ts +51 -0
- package/src/actions/auth/index.ts +47 -0
- package/src/actions/auth/loginWithOTP.ts +57 -0
- package/src/actions/auth/loginWithStamp.ts +79 -0
- package/src/actions/auth/registerWithOTP.ts +64 -0
- package/src/actions/auth/registerWithPasskey.ts +72 -0
- package/src/actions/index.ts +41 -0
- package/src/actions/wallet/getUserWallet.ts +53 -0
- package/src/actions/wallet/index.ts +17 -0
- package/src/actions/wallet/signRawPayload.ts +75 -0
- package/src/actions/wallet/signTransaction.ts +64 -0
- package/src/adapters/viem.ts +162 -0
- package/src/client/authProxy.ts +78 -0
- package/src/client/createClient.ts +90 -0
- package/src/client/decorators/client.ts +171 -0
- package/src/client/index.ts +19 -0
- package/src/client/transports/createTransport.ts +54 -0
- package/src/client/transports/rest.ts +138 -0
- package/src/client/types.ts +64 -0
- package/src/constants.ts +5 -0
- package/src/core/createZeroDevWallet.ts +447 -0
- package/src/errors/request.ts +36 -0
- package/src/index.ts +79 -0
- package/src/polyfills/window.ts +24 -0
- package/src/stampers/iframeStamper.ts +49 -0
- package/src/stampers/index.ts +8 -0
- package/src/stampers/indexedDbStamper.ts +22 -0
- package/src/stampers/types.ts +35 -0
- package/src/stampers/webauthnStamper.ts +21 -0
- package/src/storage/adapters.ts +20 -0
- package/src/storage/manager.ts +170 -0
- package/src/types/session.ts +18 -0
- package/src/utils/buildClientSignature.ts +86 -0
- package/src/utils/derToRawSignature.ts +103 -0
- package/src/utils/exportPrivateKey.ts +116 -0
- package/src/utils/exportWallet.ts +130 -0
- package/src/utils/utils.ts +136 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LoginWithStampParameters,
|
|
3
|
+
type LoginWithStampReturnType,
|
|
4
|
+
loginWithStamp,
|
|
5
|
+
} from '../../actions/auth/loginWithStamp.js'
|
|
6
|
+
import {
|
|
7
|
+
type AuthenticateWithEmailParameters,
|
|
8
|
+
type AuthenticateWithEmailReturnType,
|
|
9
|
+
type AuthenticateWithOAuthParameters,
|
|
10
|
+
type AuthenticateWithOAuthReturnType,
|
|
11
|
+
authenticateWithEmail,
|
|
12
|
+
authenticateWithOAuth,
|
|
13
|
+
type GetAuthProxyConfigIdReturnType,
|
|
14
|
+
type GetUserEmailParameters,
|
|
15
|
+
type GetUserEmailReturnType,
|
|
16
|
+
type GetUserWalletParameters,
|
|
17
|
+
type GetUserWalletReturnType,
|
|
18
|
+
type GetWhoamiParameters,
|
|
19
|
+
type GetWhoamiReturnType,
|
|
20
|
+
getAuthProxyConfigId,
|
|
21
|
+
getUserEmail,
|
|
22
|
+
getUserWallet,
|
|
23
|
+
getWhoami,
|
|
24
|
+
type LoginWithOTPParameters,
|
|
25
|
+
type LoginWithOTPReturnType,
|
|
26
|
+
loginWithOTP,
|
|
27
|
+
type RegisterWithOTPParameters,
|
|
28
|
+
type RegisterWithOTPReturnType,
|
|
29
|
+
type RegisterWithPasskeyParameters,
|
|
30
|
+
type RegisterWithPasskeyReturnType,
|
|
31
|
+
registerWithOTP,
|
|
32
|
+
registerWithPasskey,
|
|
33
|
+
type SignRawPayloadParameters,
|
|
34
|
+
type SignRawPayloadReturnType,
|
|
35
|
+
signRawPayload,
|
|
36
|
+
} from '../../actions/index.js'
|
|
37
|
+
import {
|
|
38
|
+
type SignTransactionParameters,
|
|
39
|
+
type SignTransactionReturnType,
|
|
40
|
+
signTransaction,
|
|
41
|
+
} from '../../actions/wallet/signTransaction.js'
|
|
42
|
+
import type { Client } from '../types.js'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ZeroDev Wallet client actions that can be performed with a client
|
|
46
|
+
*/
|
|
47
|
+
export type ZeroDevWalletActions = {
|
|
48
|
+
// Auth actions
|
|
49
|
+
/**
|
|
50
|
+
* Authenticates a user with their email address
|
|
51
|
+
*/
|
|
52
|
+
authenticateWithEmail: (
|
|
53
|
+
params: AuthenticateWithEmailParameters,
|
|
54
|
+
) => Promise<AuthenticateWithEmailReturnType>
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Authenticates a user with OAuth credentials
|
|
58
|
+
*/
|
|
59
|
+
authenticateWithOAuth: (
|
|
60
|
+
params: AuthenticateWithOAuthParameters,
|
|
61
|
+
) => Promise<AuthenticateWithOAuthReturnType>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets the current user information
|
|
65
|
+
*/
|
|
66
|
+
getWhoami: (params: GetWhoamiParameters) => Promise<GetWhoamiReturnType>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets the user's email address
|
|
70
|
+
*/
|
|
71
|
+
getUserEmail: (
|
|
72
|
+
params: GetUserEmailParameters,
|
|
73
|
+
) => Promise<GetUserEmailReturnType>
|
|
74
|
+
|
|
75
|
+
// Wallet actions
|
|
76
|
+
/**
|
|
77
|
+
* Gets the user's wallet information
|
|
78
|
+
*/
|
|
79
|
+
getUserWallet: (
|
|
80
|
+
params: GetUserWalletParameters,
|
|
81
|
+
) => Promise<GetUserWalletReturnType>
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Signs a raw payload with the user's wallet
|
|
85
|
+
*/
|
|
86
|
+
signRawPayload: (
|
|
87
|
+
params: SignRawPayloadParameters,
|
|
88
|
+
) => Promise<SignRawPayloadReturnType>
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Signs a transaction with the user's wallet
|
|
92
|
+
*/
|
|
93
|
+
signTransaction: (
|
|
94
|
+
params: SignTransactionParameters,
|
|
95
|
+
) => Promise<SignTransactionReturnType>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Registers a passkey with the user's wallet
|
|
99
|
+
*/
|
|
100
|
+
registerWithPasskey: (
|
|
101
|
+
params: RegisterWithPasskeyParameters,
|
|
102
|
+
) => Promise<RegisterWithPasskeyReturnType>
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Logs in a user with a stamp
|
|
106
|
+
*/
|
|
107
|
+
loginWithStamp: (
|
|
108
|
+
params: LoginWithStampParameters,
|
|
109
|
+
) => Promise<LoginWithStampReturnType>
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Registers a user with OTP (One-Time Password) authentication
|
|
113
|
+
*/
|
|
114
|
+
registerWithOTP: (
|
|
115
|
+
params: RegisterWithOTPParameters,
|
|
116
|
+
) => Promise<RegisterWithOTPReturnType>
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Logs in a user with OTP (One-Time Password) authentication
|
|
120
|
+
*/
|
|
121
|
+
loginWithOTP: (
|
|
122
|
+
params: LoginWithOTPParameters,
|
|
123
|
+
) => Promise<LoginWithOTPReturnType>
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Gets the auth proxy config ID from the backend
|
|
127
|
+
*/
|
|
128
|
+
getAuthProxyConfigId: () => Promise<GetAuthProxyConfigIdReturnType>
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Decorator function that adds ZeroDev Wallet client actions to a client
|
|
133
|
+
*
|
|
134
|
+
* @param client - The base client to extend
|
|
135
|
+
* @returns An object containing all ZeroDev Wallet client actions bound to the client
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { createClient, zeroDevWalletTransport, zeroDevWalletActions } from '@zerodev/wallet-core';
|
|
140
|
+
*
|
|
141
|
+
* const client = createClient({
|
|
142
|
+
* transport: zeroDevWalletTransport({ baseUrl: 'https://api.example.com' }),
|
|
143
|
+
* stamper: myStamper,
|
|
144
|
+
* }).extend(zeroDevWalletActions);
|
|
145
|
+
*
|
|
146
|
+
* // Now you can use actions directly on the client
|
|
147
|
+
* const userInfo = await client.getWhoami({
|
|
148
|
+
* organizationId: 'org_123',
|
|
149
|
+
* projectId: 'proj_456'
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export function zeroDevWalletActions(client: Client): ZeroDevWalletActions {
|
|
154
|
+
return {
|
|
155
|
+
// Auth actions
|
|
156
|
+
authenticateWithEmail: (params) => authenticateWithEmail(client, params),
|
|
157
|
+
authenticateWithOAuth: (params) => authenticateWithOAuth(client, params),
|
|
158
|
+
getWhoami: (params) => getWhoami(client, params),
|
|
159
|
+
getUserEmail: (params) => getUserEmail(client, params),
|
|
160
|
+
|
|
161
|
+
// Wallet actions
|
|
162
|
+
getUserWallet: (params) => getUserWallet(client, params),
|
|
163
|
+
signRawPayload: (params) => signRawPayload(client, params),
|
|
164
|
+
signTransaction: (params) => signTransaction(client, params),
|
|
165
|
+
registerWithPasskey: (params) => registerWithPasskey(client, params),
|
|
166
|
+
loginWithStamp: (params) => loginWithStamp(client, params),
|
|
167
|
+
registerWithOTP: (params) => registerWithOTP(client, params),
|
|
168
|
+
loginWithOTP: (params) => loginWithOTP(client, params),
|
|
169
|
+
getAuthProxyConfigId: () => getAuthProxyConfigId(client),
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export {
|
|
2
|
+
type AuthProxyClient,
|
|
3
|
+
type AuthProxyClientConfig,
|
|
4
|
+
type AuthProxyVerifyOtpRequest,
|
|
5
|
+
type AuthProxyVerifyOtpResponse,
|
|
6
|
+
createAuthProxyClient,
|
|
7
|
+
} from './authProxy.js'
|
|
8
|
+
export {
|
|
9
|
+
createBaseClient,
|
|
10
|
+
createClient,
|
|
11
|
+
type ZeroDevWalletClient,
|
|
12
|
+
} from './createClient.js'
|
|
13
|
+
export { zeroDevWalletTransport } from './transports/createTransport.js'
|
|
14
|
+
export type {
|
|
15
|
+
Client,
|
|
16
|
+
ClientConfig,
|
|
17
|
+
Transport,
|
|
18
|
+
TransportConfig,
|
|
19
|
+
} from './types.js'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Transport } from '../types.js'
|
|
2
|
+
import { rest } from './rest.js'
|
|
3
|
+
|
|
4
|
+
export type CreateTransportOptions = {
|
|
5
|
+
/** Base URL for the API */
|
|
6
|
+
baseUrl: string
|
|
7
|
+
/** Request timeout in milliseconds */
|
|
8
|
+
timeoutMs?: number
|
|
9
|
+
/** Transport key identifier */
|
|
10
|
+
key?: string
|
|
11
|
+
/** Transport name */
|
|
12
|
+
name?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a transport for the ZeroDev Wallet client.
|
|
17
|
+
* Requires a stamper for authenticated requests.
|
|
18
|
+
*/
|
|
19
|
+
export function zeroDevWalletTransport(
|
|
20
|
+
options: CreateTransportOptions,
|
|
21
|
+
): Transport {
|
|
22
|
+
const {
|
|
23
|
+
baseUrl,
|
|
24
|
+
timeoutMs = 10_000,
|
|
25
|
+
key = 'zeroDevWallet',
|
|
26
|
+
name = 'ZeroDev Wallet Transport',
|
|
27
|
+
} = options
|
|
28
|
+
|
|
29
|
+
return ({ indexedDbStamper, webauthnStamper }) => {
|
|
30
|
+
// Create REST transport with stamper
|
|
31
|
+
const transport = rest(baseUrl, {
|
|
32
|
+
timeoutMs,
|
|
33
|
+
key,
|
|
34
|
+
name,
|
|
35
|
+
indexedDbStamper,
|
|
36
|
+
webauthnStamper,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
config: {
|
|
41
|
+
name,
|
|
42
|
+
key,
|
|
43
|
+
url: baseUrl,
|
|
44
|
+
timeoutMs,
|
|
45
|
+
type: 'zeroDevWallet',
|
|
46
|
+
},
|
|
47
|
+
request: transport.request,
|
|
48
|
+
value: {
|
|
49
|
+
indexedDbStamper,
|
|
50
|
+
webauthnStamper,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { canonicalizeEx } from 'json-canonicalize'
|
|
2
|
+
import { RestRequestError, RestTimeoutError } from '../../errors/request.js'
|
|
3
|
+
import type { IndexedDbStamper, WebauthnStamper } from '../../stampers/types.js'
|
|
4
|
+
|
|
5
|
+
export type RestRequestArgs = {
|
|
6
|
+
path: string
|
|
7
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
8
|
+
body?: any
|
|
9
|
+
headers?: Record<string, string>
|
|
10
|
+
stamp?: boolean
|
|
11
|
+
stampWith?: 'indexedDb' | 'webAuthn'
|
|
12
|
+
stampPostion?: 'body' | 'headers'
|
|
13
|
+
/** Include credentials (cookies) in the request */
|
|
14
|
+
credentials?: RequestCredentials
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type RestRequestFn = <T = any>(args: RestRequestArgs) => Promise<T>
|
|
18
|
+
|
|
19
|
+
export type RestTransport = {
|
|
20
|
+
config: { key: string; name: string; url: string; timeoutMs: number }
|
|
21
|
+
request: RestRequestFn
|
|
22
|
+
value: Record<string, unknown>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type RestTransportConfig = {
|
|
26
|
+
fetchOptions?: Omit<RequestInit, 'body' | 'method' | 'signal'>
|
|
27
|
+
onRequest?: (
|
|
28
|
+
url: string,
|
|
29
|
+
init: RequestInit,
|
|
30
|
+
) => Promise<RequestInit | undefined> | RequestInit | undefined
|
|
31
|
+
onResponse?: (res: Response) => Promise<void> | void
|
|
32
|
+
timeoutMs?: number
|
|
33
|
+
key?: string
|
|
34
|
+
name?: string
|
|
35
|
+
indexedDbStamper: IndexedDbStamper
|
|
36
|
+
webauthnStamper: WebauthnStamper
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function rest(url: string, cfg: RestTransportConfig): RestTransport {
|
|
40
|
+
const timeoutMs = cfg.timeoutMs ?? 10_000
|
|
41
|
+
const key = cfg.key ?? 'rest'
|
|
42
|
+
const name = cfg.name ?? 'HTTP REST'
|
|
43
|
+
|
|
44
|
+
const request: RestRequestFn = async (args) => {
|
|
45
|
+
const fullUrl = `${url}/${args.path}`
|
|
46
|
+
const controller = new AbortController()
|
|
47
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
let requestBody = args.body
|
|
51
|
+
let requestHeaders = {
|
|
52
|
+
'content-type': 'application/json',
|
|
53
|
+
...(args.headers ?? {}),
|
|
54
|
+
...(cfg.fetchOptions?.headers ?? {}),
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Handle stamping if requested
|
|
58
|
+
if (args.stamp) {
|
|
59
|
+
let stamper: IndexedDbStamper | WebauthnStamper
|
|
60
|
+
if (args.stampWith === 'indexedDb') {
|
|
61
|
+
stamper = cfg.indexedDbStamper
|
|
62
|
+
} else if (args.stampWith === 'webAuthn') {
|
|
63
|
+
stamper = cfg.webauthnStamper
|
|
64
|
+
} else {
|
|
65
|
+
stamper = cfg.indexedDbStamper
|
|
66
|
+
}
|
|
67
|
+
const { body, apiUrl } = args.body
|
|
68
|
+
const bodyString = canonicalizeEx(body ?? args.body)
|
|
69
|
+
const stamp = await stamper.stamp(bodyString)
|
|
70
|
+
|
|
71
|
+
// Restructure request body to match backend expectation
|
|
72
|
+
if (args.stampPostion === 'headers') {
|
|
73
|
+
requestHeaders = {
|
|
74
|
+
...requestHeaders,
|
|
75
|
+
[stamp.stampHeaderName]: stamp.stampHeaderValue,
|
|
76
|
+
}
|
|
77
|
+
} else if (body) {
|
|
78
|
+
requestBody = {
|
|
79
|
+
body: bodyString,
|
|
80
|
+
stamp: {
|
|
81
|
+
stampHeaderName: stamp.stampHeaderName,
|
|
82
|
+
stampHeaderValue: stamp.stampHeaderValue,
|
|
83
|
+
},
|
|
84
|
+
apiUrl: apiUrl,
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
requestBody = {
|
|
88
|
+
...args.body,
|
|
89
|
+
stamp: {
|
|
90
|
+
stampHeaderName: stamp.stampHeaderName,
|
|
91
|
+
stampHeaderValue: stamp.stampHeaderValue,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const init: RequestInit = {
|
|
98
|
+
...cfg.fetchOptions,
|
|
99
|
+
method: args.method ?? 'POST',
|
|
100
|
+
headers: requestHeaders,
|
|
101
|
+
body: requestBody != null ? JSON.stringify(requestBody) : null,
|
|
102
|
+
signal: controller.signal,
|
|
103
|
+
...(args.credentials && { credentials: args.credentials }),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const finalInit = (await cfg.onRequest?.(fullUrl, init)) ?? init
|
|
107
|
+
const res = await fetch(fullUrl, finalInit)
|
|
108
|
+
|
|
109
|
+
await cfg.onResponse?.(res)
|
|
110
|
+
|
|
111
|
+
let data: any
|
|
112
|
+
const ct = res.headers.get('content-type') ?? ''
|
|
113
|
+
if (ct.startsWith('application/json')) data = await res.json()
|
|
114
|
+
else {
|
|
115
|
+
const text = await res.text()
|
|
116
|
+
try {
|
|
117
|
+
data = text ? JSON.parse(text) : {}
|
|
118
|
+
} catch {
|
|
119
|
+
data = text
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!res.ok) throw new RestRequestError(fullUrl, res.status, data)
|
|
124
|
+
return data as any
|
|
125
|
+
} catch (err: any) {
|
|
126
|
+
if (err.name === 'AbortError') throw new RestTimeoutError(fullUrl)
|
|
127
|
+
throw err
|
|
128
|
+
} finally {
|
|
129
|
+
clearTimeout(timer)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
config: { key, name, url, timeoutMs },
|
|
135
|
+
request,
|
|
136
|
+
value: {},
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { IndexedDbStamper, WebauthnStamper } from '../stampers/types.js'
|
|
2
|
+
import type { RestRequestFn } from './transports/rest.js'
|
|
3
|
+
|
|
4
|
+
export type TransportConfig = {
|
|
5
|
+
/** The name of the transport. */
|
|
6
|
+
name: string
|
|
7
|
+
/** The key of the transport. */
|
|
8
|
+
key: string
|
|
9
|
+
/** Base URL for the API */
|
|
10
|
+
url: string
|
|
11
|
+
/** Proxy base URL for auth requests */
|
|
12
|
+
proxyBaseUrl?: string
|
|
13
|
+
/** Request timeout in milliseconds */
|
|
14
|
+
timeoutMs: number
|
|
15
|
+
/** The type of the transport. */
|
|
16
|
+
type: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type Transport = (options: {
|
|
20
|
+
indexedDbStamper: IndexedDbStamper
|
|
21
|
+
webauthnStamper: WebauthnStamper
|
|
22
|
+
}) => {
|
|
23
|
+
config: TransportConfig
|
|
24
|
+
request: RestRequestFn
|
|
25
|
+
value?: Record<string, unknown>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ClientConfig = {
|
|
29
|
+
transport: Transport
|
|
30
|
+
indexedDbStamper: IndexedDbStamper
|
|
31
|
+
webauthnStamper: WebauthnStamper
|
|
32
|
+
organizationId?: string
|
|
33
|
+
key?: string
|
|
34
|
+
name?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type Client<extended extends Extended | undefined = undefined> = {
|
|
38
|
+
/** Transport configuration */
|
|
39
|
+
transport: TransportConfig & Record<string, unknown>
|
|
40
|
+
/** Request function from transport */
|
|
41
|
+
request: RestRequestFn
|
|
42
|
+
/** IndexedDB Stamper for authenticated requests */
|
|
43
|
+
indexedDbStamper: IndexedDbStamper
|
|
44
|
+
/** WebAuthn Stamper for authenticated requests */
|
|
45
|
+
webauthnStamper: WebauthnStamper
|
|
46
|
+
/** Organization ID */
|
|
47
|
+
organizationId?: string
|
|
48
|
+
/** A key for the client */
|
|
49
|
+
key: string
|
|
50
|
+
/** A name for the client */
|
|
51
|
+
name: string
|
|
52
|
+
/** The type of client */
|
|
53
|
+
type: string
|
|
54
|
+
/** A unique ID for the client */
|
|
55
|
+
uid: string
|
|
56
|
+
/** Extend the client with additional functionality */
|
|
57
|
+
extend: <const client extends Extended>(
|
|
58
|
+
fn: (client: Client<extended>) => client,
|
|
59
|
+
) => Client<client & (extended extends Extended ? extended : unknown)>
|
|
60
|
+
} & (extended extends Extended ? extended : unknown)
|
|
61
|
+
|
|
62
|
+
type Extended = {
|
|
63
|
+
[key: string]: unknown
|
|
64
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const DEFAULT_SESSION_EXPIRATION_IN_SECONDS = '900' // default to 15 minutes
|
|
2
|
+
export const DEFAULT_IFRAME_CONTAINER_ID = 'turnkey-auth-iframe-container-id'
|
|
3
|
+
export const DEFAULT_IFRAME_ELEMENT_ID = 'turnkey-default-iframe-element-id'
|
|
4
|
+
export const DEFAULT_ORGANIZATION_ID = '0d98e826-dd8f-44ca-a585-3afcd27d4002'
|
|
5
|
+
export const KMS_SERVER_URL = 'https://kms.staging.zerodev.app'
|