@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,53 @@
|
|
|
1
|
+
import type { Hex } from 'viem'
|
|
2
|
+
import type { Client } from '../../client/types.js'
|
|
3
|
+
|
|
4
|
+
export type GetUserWalletParameters = {
|
|
5
|
+
/** The organization ID */
|
|
6
|
+
organizationId: string
|
|
7
|
+
/** The project ID for the request */
|
|
8
|
+
projectId: string
|
|
9
|
+
/** The token for the request */
|
|
10
|
+
token: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type GetUserWalletReturnType = {
|
|
14
|
+
/** The wallet address */
|
|
15
|
+
walletAddresses: Hex[]
|
|
16
|
+
/** The user ID */
|
|
17
|
+
userId?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Gets the user's wallet information
|
|
22
|
+
*
|
|
23
|
+
* @param client - The ZeroDev Wallet client
|
|
24
|
+
* @param params - The parameters for getting wallet info
|
|
25
|
+
* @returns The wallet information
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const wallet = await getUserWallet(client, {
|
|
30
|
+
* organizationId: 'org_123',
|
|
31
|
+
* projectId: 'proj_456'
|
|
32
|
+
* });
|
|
33
|
+
* console.log(wallet.walletAddresses); // ['0x...', '0x...']
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function getUserWallet(
|
|
37
|
+
client: Client,
|
|
38
|
+
params: GetUserWalletParameters,
|
|
39
|
+
): Promise<GetUserWalletReturnType> {
|
|
40
|
+
const { organizationId, projectId, token } = params
|
|
41
|
+
|
|
42
|
+
return await client.request({
|
|
43
|
+
path: `${projectId}/user-wallet`,
|
|
44
|
+
body: {
|
|
45
|
+
organizationId,
|
|
46
|
+
},
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: `Bearer ${token}`,
|
|
49
|
+
},
|
|
50
|
+
stamp: true,
|
|
51
|
+
stampPostion: 'headers',
|
|
52
|
+
})
|
|
53
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export {
|
|
2
|
+
type GetUserWalletParameters,
|
|
3
|
+
type GetUserWalletReturnType,
|
|
4
|
+
getUserWallet,
|
|
5
|
+
} from './getUserWallet.js'
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
type SignRawPayloadParameters,
|
|
9
|
+
type SignRawPayloadReturnType,
|
|
10
|
+
signRawPayload,
|
|
11
|
+
} from './signRawPayload.js'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
type SignTransactionParameters,
|
|
15
|
+
type SignTransactionReturnType,
|
|
16
|
+
signTransaction,
|
|
17
|
+
} from './signTransaction.js'
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Hex } from 'viem'
|
|
2
|
+
import type { Client } from '../../client/types.js'
|
|
3
|
+
|
|
4
|
+
export type SignRawPayloadParameters = {
|
|
5
|
+
/** The organization ID */
|
|
6
|
+
organizationId: string
|
|
7
|
+
/** The project ID for the request */
|
|
8
|
+
projectId: string
|
|
9
|
+
/** The session token for authorization */
|
|
10
|
+
token: string
|
|
11
|
+
/** The address to sign with */
|
|
12
|
+
address: Hex
|
|
13
|
+
/** The payload hash to sign (without 0x prefix) */
|
|
14
|
+
payload: string
|
|
15
|
+
/** The encoding type */
|
|
16
|
+
encoding?: 'PAYLOAD_ENCODING_HEXADECIMAL' | 'PAYLOAD_ENCODING_EIP712'
|
|
17
|
+
/** The hash function type */
|
|
18
|
+
hashFunction?: 'HASH_FUNCTION_NO_OP'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type SignRawPayloadReturnType = Hex
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Signs a raw payload with the user's wallet
|
|
25
|
+
*
|
|
26
|
+
* @param client - The ZeroDev Wallet client
|
|
27
|
+
* @param params - The parameters for signing
|
|
28
|
+
* @returns The signature
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const result = await signRawPayload(client, {
|
|
33
|
+
* organizationId: 'org_123',
|
|
34
|
+
* projectId: 'proj_456',
|
|
35
|
+
* address: '0x123...',
|
|
36
|
+
* payload: 'abc123...',
|
|
37
|
+
* });
|
|
38
|
+
* console.log(result.signature); // '0x...'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export async function signRawPayload(
|
|
42
|
+
client: Client,
|
|
43
|
+
params: SignRawPayloadParameters,
|
|
44
|
+
): Promise<SignRawPayloadReturnType> {
|
|
45
|
+
const {
|
|
46
|
+
organizationId,
|
|
47
|
+
projectId,
|
|
48
|
+
token,
|
|
49
|
+
address,
|
|
50
|
+
payload,
|
|
51
|
+
encoding = 'PAYLOAD_ENCODING_HEXADECIMAL',
|
|
52
|
+
hashFunction = 'HASH_FUNCTION_NO_OP',
|
|
53
|
+
} = params
|
|
54
|
+
|
|
55
|
+
const { signature } = await client.request({
|
|
56
|
+
path: `${projectId}/sign/raw-payload`,
|
|
57
|
+
body: {
|
|
58
|
+
type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',
|
|
59
|
+
timestampMs: Date.now().toString(),
|
|
60
|
+
organizationId,
|
|
61
|
+
parameters: {
|
|
62
|
+
signWith: address,
|
|
63
|
+
payload,
|
|
64
|
+
encoding,
|
|
65
|
+
hashFunction,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: `Bearer ${token}`,
|
|
70
|
+
},
|
|
71
|
+
stamp: true,
|
|
72
|
+
stampPostion: 'headers',
|
|
73
|
+
})
|
|
74
|
+
return signature as Hex
|
|
75
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Hex } from 'viem'
|
|
2
|
+
import type { Client } from '../../client/types.js'
|
|
3
|
+
|
|
4
|
+
export type SignTransactionParameters = {
|
|
5
|
+
/** The organization ID */
|
|
6
|
+
organizationId: string
|
|
7
|
+
/** The project ID for the request */
|
|
8
|
+
projectId: string
|
|
9
|
+
/** The session token for authorization */
|
|
10
|
+
token: string
|
|
11
|
+
/** The address to sign with */
|
|
12
|
+
address: Hex
|
|
13
|
+
/** The unsigned transaction to sign */
|
|
14
|
+
unsignedTransaction: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SignTransactionReturnType = Hex
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Signs a raw transaction with the user's wallet
|
|
21
|
+
*
|
|
22
|
+
* @param client - The ZeroDev Wallet client
|
|
23
|
+
* @param params - The parameters for signing
|
|
24
|
+
* @returns The signature
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const result = await signTransaction(client, {
|
|
29
|
+
* organizationId: 'org_123',
|
|
30
|
+
* projectId: 'proj_456',
|
|
31
|
+
* address: '0x123...',
|
|
32
|
+
* unsignedTransaction: 'abc123...',
|
|
33
|
+
* });
|
|
34
|
+
* console.log(result.signature); // '0x...'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export async function signTransaction(
|
|
38
|
+
client: Client,
|
|
39
|
+
params: SignTransactionParameters,
|
|
40
|
+
): Promise<SignTransactionReturnType> {
|
|
41
|
+
const { organizationId, projectId, token, address, unsignedTransaction } =
|
|
42
|
+
params
|
|
43
|
+
|
|
44
|
+
const { signature } = await client.request({
|
|
45
|
+
path: `${projectId}/sign/transaction`,
|
|
46
|
+
body: {
|
|
47
|
+
type: 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2',
|
|
48
|
+
timestampMs: Date.now().toString(),
|
|
49
|
+
organizationId,
|
|
50
|
+
parameters: {
|
|
51
|
+
signWith: address,
|
|
52
|
+
type: 'TRANSACTION_TYPE_ETHEREUM',
|
|
53
|
+
unsignedTransaction,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: `Bearer ${token}`,
|
|
58
|
+
},
|
|
59
|
+
stamp: true,
|
|
60
|
+
stampPostion: 'headers',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return `0x${signature}` as Hex
|
|
64
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Hex,
|
|
3
|
+
hashMessage,
|
|
4
|
+
type LocalAccount,
|
|
5
|
+
parseSignature,
|
|
6
|
+
parseTransaction,
|
|
7
|
+
type SerializeTransactionFn,
|
|
8
|
+
type SignableMessage,
|
|
9
|
+
serializeTransaction,
|
|
10
|
+
serializeTypedData,
|
|
11
|
+
type TransactionSerializable,
|
|
12
|
+
zeroAddress,
|
|
13
|
+
} from 'viem'
|
|
14
|
+
import type {
|
|
15
|
+
SignAuthorizationParameters,
|
|
16
|
+
SignAuthorizationReturnType,
|
|
17
|
+
} from 'viem/accounts'
|
|
18
|
+
import { toAccount } from 'viem/accounts'
|
|
19
|
+
import { hashAuthorization } from 'viem/utils'
|
|
20
|
+
import type { signRawPayload } from '../actions/index.js'
|
|
21
|
+
import type { ZeroDevWalletClient } from '../client/index.js'
|
|
22
|
+
|
|
23
|
+
export interface ToViemAccountParams {
|
|
24
|
+
client: ZeroDevWalletClient
|
|
25
|
+
organizationId: string
|
|
26
|
+
projectId: string
|
|
27
|
+
token: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function toViemAccount(
|
|
31
|
+
params: ToViemAccountParams,
|
|
32
|
+
): Promise<LocalAccount> {
|
|
33
|
+
const { client, organizationId, projectId, token } = params
|
|
34
|
+
|
|
35
|
+
let address: Hex = zeroAddress
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const walletResponse = await client.getUserWallet({
|
|
39
|
+
organizationId,
|
|
40
|
+
projectId,
|
|
41
|
+
token,
|
|
42
|
+
})
|
|
43
|
+
address = walletResponse.walletAddresses[0]
|
|
44
|
+
} catch {
|
|
45
|
+
address = zeroAddress
|
|
46
|
+
}
|
|
47
|
+
const signRawPayloadInternal = async (
|
|
48
|
+
payload: string,
|
|
49
|
+
encoding: Parameters<
|
|
50
|
+
typeof signRawPayload
|
|
51
|
+
>[1]['encoding'] = 'PAYLOAD_ENCODING_HEXADECIMAL',
|
|
52
|
+
) => {
|
|
53
|
+
return await client.signRawPayload({
|
|
54
|
+
organizationId,
|
|
55
|
+
projectId,
|
|
56
|
+
token,
|
|
57
|
+
address,
|
|
58
|
+
payload,
|
|
59
|
+
encoding,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Modified from: https://github.com/tkhq/sdk/blob/4e439bf2973ea13b51d981d7c24a4841d4e5fd5f/packages/viem/src/index.ts#L419-L461
|
|
64
|
+
const signTransactionInternal = async <
|
|
65
|
+
TTransactionSerializable extends TransactionSerializable,
|
|
66
|
+
>(
|
|
67
|
+
transaction: TTransactionSerializable,
|
|
68
|
+
serializer: SerializeTransactionFn<TTransactionSerializable>,
|
|
69
|
+
): Promise<Hex> => {
|
|
70
|
+
// Note: for Type 3 transactions, we are specifically handling parsing for payloads containing only the transaction payload body, without any wrappers around blobs, commitments, or proofs.
|
|
71
|
+
// See more: https://github.com/wevm/viem/blob/3ef19eac4963014fb20124d1e46d1715bed5509f/src/accounts/utils/signTransaction.ts#L54-L55
|
|
72
|
+
const signableTransaction =
|
|
73
|
+
transaction.type === 'eip4844'
|
|
74
|
+
? { ...transaction, sidecars: false }
|
|
75
|
+
: transaction
|
|
76
|
+
|
|
77
|
+
const serializedTx = await serializer(signableTransaction)
|
|
78
|
+
const nonHexPrefixedSerializedTx = serializedTx.replace(/^0x/, '')
|
|
79
|
+
const signature = await client.signTransaction({
|
|
80
|
+
organizationId,
|
|
81
|
+
projectId,
|
|
82
|
+
token,
|
|
83
|
+
address,
|
|
84
|
+
unsignedTransaction: nonHexPrefixedSerializedTx,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
if (transaction.type === 'eip4844') {
|
|
88
|
+
// Grab components of the signature
|
|
89
|
+
const { r, s, v } = parseTransaction(signature)
|
|
90
|
+
|
|
91
|
+
// Recombine with the original transaction
|
|
92
|
+
return serializeTransaction(transaction, {
|
|
93
|
+
r: r!,
|
|
94
|
+
s: s!,
|
|
95
|
+
v: v!,
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return signature
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return toAccount({
|
|
103
|
+
address,
|
|
104
|
+
|
|
105
|
+
async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {
|
|
106
|
+
const hashedMessage = hashMessage(message)
|
|
107
|
+
return signRawPayloadInternal(hashedMessage)
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
signTransaction: async <
|
|
111
|
+
TTransactionSerializable extends TransactionSerializable,
|
|
112
|
+
>(
|
|
113
|
+
transaction: TTransactionSerializable,
|
|
114
|
+
options?: {
|
|
115
|
+
serializer?:
|
|
116
|
+
| SerializeTransactionFn<TTransactionSerializable>
|
|
117
|
+
| undefined
|
|
118
|
+
},
|
|
119
|
+
) => {
|
|
120
|
+
const serializer: SerializeTransactionFn<TTransactionSerializable> =
|
|
121
|
+
options?.serializer ??
|
|
122
|
+
(serializeTransaction as SerializeTransactionFn<TTransactionSerializable>)
|
|
123
|
+
return signTransactionInternal(transaction, serializer)
|
|
124
|
+
},
|
|
125
|
+
signTypedData: async (typedData) => {
|
|
126
|
+
const serializedTypedData = serializeTypedData(typedData)
|
|
127
|
+
return signRawPayloadInternal(
|
|
128
|
+
serializedTypedData,
|
|
129
|
+
'PAYLOAD_ENCODING_EIP712',
|
|
130
|
+
)
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
async signAuthorization(
|
|
134
|
+
parameters: Omit<SignAuthorizationParameters, 'privateKey'>,
|
|
135
|
+
): Promise<SignAuthorizationReturnType> {
|
|
136
|
+
const { chainId, nonce } = parameters
|
|
137
|
+
const authAddress = parameters.contractAddress ?? parameters.address
|
|
138
|
+
|
|
139
|
+
if (!authAddress) {
|
|
140
|
+
throw new Error('Unable to sign authorization: address is undefined')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const hashedAuthorization = hashAuthorization({
|
|
144
|
+
address: authAddress,
|
|
145
|
+
chainId,
|
|
146
|
+
nonce,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const signature = await signRawPayloadInternal(hashedAuthorization)
|
|
150
|
+
|
|
151
|
+
const parsedSignature = parseSignature(signature)
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
address: authAddress,
|
|
155
|
+
chainId,
|
|
156
|
+
nonce,
|
|
157
|
+
...parsedSignature,
|
|
158
|
+
yParity: parsedSignature.v === BigInt(27) ? 0 : 1,
|
|
159
|
+
} as SignAuthorizationReturnType
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const AUTH_PROXY_BASE_URL = 'https://authproxy.turnkey.com'
|
|
2
|
+
|
|
3
|
+
export type AuthProxyClientConfig = {
|
|
4
|
+
/** The Auth Proxy Config ID from the backend */
|
|
5
|
+
authProxyConfigId: string
|
|
6
|
+
/** Optional base URL override (for testing) */
|
|
7
|
+
baseUrl?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type AuthProxyVerifyOtpRequest = {
|
|
11
|
+
/** The OTP ID from registration */
|
|
12
|
+
otpId: string
|
|
13
|
+
/** The OTP code entered by the user */
|
|
14
|
+
otpCode: string
|
|
15
|
+
/** The public key to associate with the verification */
|
|
16
|
+
public_key: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type AuthProxyVerifyOtpResponse = {
|
|
20
|
+
/** The verification token to use for login */
|
|
21
|
+
verificationToken: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates an Auth Proxy client for making requests to Turnkey's Auth Proxy
|
|
26
|
+
*
|
|
27
|
+
* Note: This client only handles OTP verification. The actual OTP login
|
|
28
|
+
* is handled by the backend (/auth/login/otp) which manages sub-organization
|
|
29
|
+
* creation and session handling.
|
|
30
|
+
*/
|
|
31
|
+
export function createAuthProxyClient(config: AuthProxyClientConfig) {
|
|
32
|
+
const { authProxyConfigId, baseUrl = AUTH_PROXY_BASE_URL } = config
|
|
33
|
+
|
|
34
|
+
async function request<T>(
|
|
35
|
+
path: string,
|
|
36
|
+
body: unknown,
|
|
37
|
+
method: 'POST' | 'GET' = 'POST',
|
|
38
|
+
): Promise<T> {
|
|
39
|
+
const fetchOptions: RequestInit = {
|
|
40
|
+
method,
|
|
41
|
+
headers: {
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
'X-Auth-Proxy-Config-Id': authProxyConfigId,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (method !== 'GET') {
|
|
48
|
+
fetchOptions.body = JSON.stringify(body)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const response = await fetch(`${baseUrl}${path}`, fetchOptions)
|
|
52
|
+
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const errorText = await response.text()
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Auth Proxy request failed: ${response.status} ${response.statusText} - ${errorText}`,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return response.json()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
/**
|
|
65
|
+
* Verifies an OTP code with Turnkey's Auth Proxy
|
|
66
|
+
*
|
|
67
|
+
* Returns a verificationToken that should be passed to the backend's
|
|
68
|
+
* /auth/login/otp endpoint along with a client signature.
|
|
69
|
+
*/
|
|
70
|
+
async verifyOtp(
|
|
71
|
+
params: AuthProxyVerifyOtpRequest,
|
|
72
|
+
): Promise<AuthProxyVerifyOtpResponse> {
|
|
73
|
+
return request<AuthProxyVerifyOtpResponse>('/v1/otp_verify', params)
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type AuthProxyClient = ReturnType<typeof createAuthProxyClient>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ZeroDevWalletActions,
|
|
3
|
+
zeroDevWalletActions,
|
|
4
|
+
} from './decorators/client.js'
|
|
5
|
+
import type { Client, ClientConfig } from './types.js'
|
|
6
|
+
|
|
7
|
+
let clientId = 0
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a base ZeroDev Wallet client.
|
|
11
|
+
* This is the foundation client without any pre-loaded actions.
|
|
12
|
+
* Use createClient() for a client with ZeroDev Wallet actions pre-loaded.
|
|
13
|
+
*/
|
|
14
|
+
export function createBaseClient<
|
|
15
|
+
extended extends Record<string, unknown> | undefined = undefined,
|
|
16
|
+
>(config: ClientConfig): Client<extended> {
|
|
17
|
+
const {
|
|
18
|
+
transport,
|
|
19
|
+
indexedDbStamper,
|
|
20
|
+
webauthnStamper,
|
|
21
|
+
organizationId,
|
|
22
|
+
key = 'zeroDevWallet',
|
|
23
|
+
name = 'ZeroDev Wallet Client',
|
|
24
|
+
} = config
|
|
25
|
+
|
|
26
|
+
// Initialize the transport with stamper
|
|
27
|
+
const {
|
|
28
|
+
config: transportConfig,
|
|
29
|
+
request,
|
|
30
|
+
value,
|
|
31
|
+
} = transport({
|
|
32
|
+
indexedDbStamper,
|
|
33
|
+
webauthnStamper,
|
|
34
|
+
})
|
|
35
|
+
const transportInstance = { ...transportConfig, ...value }
|
|
36
|
+
|
|
37
|
+
const uid = `${key}-${++clientId}`
|
|
38
|
+
|
|
39
|
+
const client = {
|
|
40
|
+
transport: transportInstance,
|
|
41
|
+
request,
|
|
42
|
+
indexedDbStamper,
|
|
43
|
+
webauthnStamper,
|
|
44
|
+
organizationId,
|
|
45
|
+
key,
|
|
46
|
+
name,
|
|
47
|
+
type: 'zeroDevWallet',
|
|
48
|
+
uid,
|
|
49
|
+
} as const
|
|
50
|
+
|
|
51
|
+
function extend(base: typeof client) {
|
|
52
|
+
type ExtendFn = (base: typeof client) => Record<string, unknown>
|
|
53
|
+
return (extendFn: ExtendFn) => {
|
|
54
|
+
const extended = extendFn(base) as Record<string, unknown>
|
|
55
|
+
|
|
56
|
+
// Remove base properties from extended to avoid conflicts
|
|
57
|
+
for (const key in client) {
|
|
58
|
+
delete extended[key]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Combine base client with extensions
|
|
62
|
+
const combined = { ...base, ...extended }
|
|
63
|
+
|
|
64
|
+
// Return new client with updated extend function
|
|
65
|
+
return Object.assign(combined, { extend: extend(combined as any) })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return Object.assign(client, {
|
|
70
|
+
extend: extend(client) as any,
|
|
71
|
+
}) as Client<extended>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type ZeroDevWalletClient = Client<ZeroDevWalletActions>
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Creates a ZeroDev Wallet client with ZeroDev Wallet actions pre-loaded.
|
|
78
|
+
* This is equivalent to calling createBaseClient(config).extend(zeroDevWalletActions).
|
|
79
|
+
*
|
|
80
|
+
* For a client without pre-loaded actions, use createBaseClient().
|
|
81
|
+
*/
|
|
82
|
+
export function createClient(config: ClientConfig): ZeroDevWalletClient {
|
|
83
|
+
const { key = 'zeroDevWallet', name = 'ZeroDev Wallet Client' } = config
|
|
84
|
+
const client = createBaseClient({
|
|
85
|
+
...config,
|
|
86
|
+
key,
|
|
87
|
+
name,
|
|
88
|
+
})
|
|
89
|
+
return client.extend(zeroDevWalletActions) as ZeroDevWalletClient
|
|
90
|
+
}
|