@zerodev/wallet-core 0.0.1-alpha.3 → 0.0.1-alpha.4
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/dist/_cjs/actions/auth/loginWithStamp.js +11 -2
- package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -1
- package/dist/_cjs/adapters/viem.js +1 -1
- package/dist/_cjs/adapters/viem.js.map +1 -1
- package/dist/_cjs/client/createClient.js +8 -4
- package/dist/_cjs/client/createClient.js.map +1 -1
- package/dist/_cjs/client/transports/createTransport.js +5 -3
- package/dist/_cjs/client/transports/createTransport.js.map +1 -1
- package/dist/_cjs/client/transports/rest.js +13 -3
- package/dist/_cjs/client/transports/rest.js.map +1 -1
- package/dist/_cjs/core/createZeroDevWallet.js +26 -66
- package/dist/_cjs/core/createZeroDevWallet.js.map +1 -1
- package/dist/_cjs/utils/exportWallet.js +6 -6
- package/dist/_cjs/utils/exportWallet.js.map +1 -1
- package/dist/_esm/actions/auth/loginWithStamp.js +11 -2
- package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -1
- package/dist/_esm/adapters/viem.js +1 -1
- package/dist/_esm/adapters/viem.js.map +1 -1
- package/dist/_esm/client/createClient.js +8 -4
- package/dist/_esm/client/createClient.js.map +1 -1
- package/dist/_esm/client/transports/createTransport.js +5 -3
- package/dist/_esm/client/transports/createTransport.js.map +1 -1
- package/dist/_esm/client/transports/rest.js +13 -3
- package/dist/_esm/client/transports/rest.js.map +1 -1
- package/dist/_esm/core/createZeroDevWallet.js +26 -68
- package/dist/_esm/core/createZeroDevWallet.js.map +1 -1
- package/dist/_esm/utils/exportWallet.js +6 -6
- package/dist/_esm/utils/exportWallet.js.map +1 -1
- package/dist/_types/actions/auth/loginWithStamp.d.ts +2 -0
- package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -1
- package/dist/_types/client/createClient.d.ts +3 -4
- package/dist/_types/client/createClient.d.ts.map +1 -1
- package/dist/_types/client/transports/createTransport.d.ts.map +1 -1
- package/dist/_types/client/transports/rest.d.ts +5 -3
- package/dist/_types/client/transports/rest.d.ts.map +1 -1
- package/dist/_types/client/types.d.ts +11 -12
- package/dist/_types/client/types.d.ts.map +1 -1
- package/dist/_types/core/createZeroDevWallet.d.ts +1 -1
- package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -1
- package/dist/_types/utils/exportWallet.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/actions/auth/loginWithStamp.ts +12 -2
- package/src/adapters/viem.ts +1 -1
- package/src/client/createClient.ts +13 -18
- package/src/client/transports/createTransport.ts +5 -3
- package/src/client/transports/rest.ts +16 -9
- package/src/client/types.ts +13 -15
- package/src/core/createZeroDevWallet.ts +27 -76
- package/src/utils/exportWallet.ts +12 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodev/wallet-core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
4
4
|
"description": "ZeroDev Wallet SDK built on Turnkey",
|
|
5
5
|
"main": "./dist/_cjs/index.js",
|
|
6
6
|
"module": "./dist/_esm/index.js",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"@turnkey/webauthn-stamper": "^0.6.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"viem": "2.
|
|
58
|
+
"viem": "^2.38.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^20.0.0",
|
|
62
|
-
"typescript": "
|
|
62
|
+
"typescript": "5.9.3"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Client } from '../../client/types.js'
|
|
2
|
+
import type { Stamp } from '../../stampers/types.js'
|
|
2
3
|
|
|
3
4
|
export type EmailCustomization = {
|
|
4
5
|
/** A template for the URL to be used in a magic link button, e.g. `https://dapp.xyz/%s`. The auth bundle will be interpolated into the `%s`. */
|
|
@@ -12,6 +13,8 @@ export type LoginWithStampParameters = {
|
|
|
12
13
|
organizationId: string
|
|
13
14
|
/** The encoded public key for the request */
|
|
14
15
|
targetPublicKey: string
|
|
16
|
+
/** The stamper type for the request */
|
|
17
|
+
stampWith?: 'indexedDb' | 'webauthn'
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export type LoginWithStampReturnType = {
|
|
@@ -39,7 +42,7 @@ export async function loginWithStamp(
|
|
|
39
42
|
client: Client,
|
|
40
43
|
params: LoginWithStampParameters,
|
|
41
44
|
): Promise<LoginWithStampReturnType> {
|
|
42
|
-
const { projectId, targetPublicKey, organizationId } = params
|
|
45
|
+
const { projectId, targetPublicKey, organizationId, stampWith } = params
|
|
43
46
|
|
|
44
47
|
const timestampMs = Date.now()
|
|
45
48
|
const timestampMsString = timestampMs.toString()
|
|
@@ -53,7 +56,14 @@ export async function loginWithStamp(
|
|
|
53
56
|
timestampMs: timestampMsString,
|
|
54
57
|
type: 'ACTIVITY_TYPE_STAMP_LOGIN',
|
|
55
58
|
})}\n`
|
|
56
|
-
|
|
59
|
+
let stamp: Stamp
|
|
60
|
+
if (stampWith === 'indexedDb') {
|
|
61
|
+
stamp = await client.indexedDbStamper.stamp(stampPayload)
|
|
62
|
+
} else if (stampWith === 'webauthn') {
|
|
63
|
+
stamp = await client.webauthnStamper.stamp(stampPayload)
|
|
64
|
+
} else {
|
|
65
|
+
stamp = await client.indexedDbStamper.stamp(stampPayload)
|
|
66
|
+
}
|
|
57
67
|
|
|
58
68
|
return client.request({
|
|
59
69
|
path: `${projectId}/auth/login/passkey`,
|
package/src/adapters/viem.ts
CHANGED
|
@@ -71,7 +71,7 @@ export async function toViemAccount(
|
|
|
71
71
|
? { ...transaction, sidecars: false }
|
|
72
72
|
: transaction
|
|
73
73
|
|
|
74
|
-
const serializedTx = serializer(signableTransaction)
|
|
74
|
+
const serializedTx = await serializer(signableTransaction)
|
|
75
75
|
const nonHexPrefixedSerializedTx = serializedTx.replace(/^0x/, '')
|
|
76
76
|
const signature = await client.signTransaction({
|
|
77
77
|
organizationId,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Stamper } from '../stampers/types.js'
|
|
2
1
|
import {
|
|
3
2
|
type ZeroDevWalletActions,
|
|
4
3
|
zeroDevWalletActions,
|
|
@@ -14,11 +13,11 @@ let clientId = 0
|
|
|
14
13
|
*/
|
|
15
14
|
export function createBaseClient<
|
|
16
15
|
extended extends Record<string, unknown> | undefined = undefined,
|
|
17
|
-
|
|
18
|
-
>(config: ClientConfig): Client<extended, TStamper> {
|
|
16
|
+
>(config: ClientConfig): Client<extended> {
|
|
19
17
|
const {
|
|
20
18
|
transport,
|
|
21
|
-
|
|
19
|
+
indexedDbStamper,
|
|
20
|
+
webauthnStamper,
|
|
22
21
|
organizationId,
|
|
23
22
|
key = 'zeroDevWallet',
|
|
24
23
|
name = 'ZeroDev Wallet Client',
|
|
@@ -30,7 +29,8 @@ export function createBaseClient<
|
|
|
30
29
|
request,
|
|
31
30
|
value,
|
|
32
31
|
} = transport({
|
|
33
|
-
|
|
32
|
+
indexedDbStamper,
|
|
33
|
+
webauthnStamper,
|
|
34
34
|
})
|
|
35
35
|
const transportInstance = { ...transportConfig, ...value }
|
|
36
36
|
|
|
@@ -39,7 +39,8 @@ export function createBaseClient<
|
|
|
39
39
|
const client = {
|
|
40
40
|
transport: transportInstance,
|
|
41
41
|
request,
|
|
42
|
-
|
|
42
|
+
indexedDbStamper,
|
|
43
|
+
webauthnStamper,
|
|
43
44
|
organizationId,
|
|
44
45
|
key,
|
|
45
46
|
name,
|
|
@@ -65,16 +66,12 @@ export function createBaseClient<
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
return Object.assign(client, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
>
|
|
69
|
+
return Object.assign(client, {
|
|
70
|
+
extend: extend(client) as any,
|
|
71
|
+
}) as Client<extended>
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export type ZeroDevWalletClient
|
|
75
|
-
ZeroDevWalletActions,
|
|
76
|
-
TStamper
|
|
77
|
-
>
|
|
74
|
+
export type ZeroDevWalletClient = Client<ZeroDevWalletActions>
|
|
78
75
|
|
|
79
76
|
/**
|
|
80
77
|
* Creates a ZeroDev Wallet client with ZeroDev Wallet actions pre-loaded.
|
|
@@ -82,14 +79,12 @@ export type ZeroDevWalletClient<TStamper extends Stamper = Stamper> = Client<
|
|
|
82
79
|
*
|
|
83
80
|
* For a client without pre-loaded actions, use createBaseClient().
|
|
84
81
|
*/
|
|
85
|
-
export function createClient
|
|
86
|
-
config: ClientConfig<TStamper>,
|
|
87
|
-
): ZeroDevWalletClient<TStamper> {
|
|
82
|
+
export function createClient(config: ClientConfig): ZeroDevWalletClient {
|
|
88
83
|
const { key = 'zeroDevWallet', name = 'ZeroDev Wallet Client' } = config
|
|
89
84
|
const client = createBaseClient({
|
|
90
85
|
...config,
|
|
91
86
|
key,
|
|
92
87
|
name,
|
|
93
88
|
})
|
|
94
|
-
return client.extend(zeroDevWalletActions) as ZeroDevWalletClient
|
|
89
|
+
return client.extend(zeroDevWalletActions) as ZeroDevWalletClient
|
|
95
90
|
}
|
|
@@ -26,13 +26,14 @@ export function zeroDevWalletTransport(
|
|
|
26
26
|
name = 'ZeroDev Wallet Transport',
|
|
27
27
|
} = options
|
|
28
28
|
|
|
29
|
-
return ({
|
|
29
|
+
return ({ indexedDbStamper, webauthnStamper }) => {
|
|
30
30
|
// Create REST transport with stamper
|
|
31
31
|
const transport = rest(baseUrl, {
|
|
32
32
|
timeoutMs,
|
|
33
33
|
key,
|
|
34
34
|
name,
|
|
35
|
-
|
|
35
|
+
indexedDbStamper,
|
|
36
|
+
webauthnStamper,
|
|
36
37
|
})
|
|
37
38
|
|
|
38
39
|
return {
|
|
@@ -45,7 +46,8 @@ export function zeroDevWalletTransport(
|
|
|
45
46
|
},
|
|
46
47
|
request: transport.request,
|
|
47
48
|
value: {
|
|
48
|
-
|
|
49
|
+
indexedDbStamper,
|
|
50
|
+
webauthnStamper,
|
|
49
51
|
},
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { RestRequestError, RestTimeoutError } from '../../errors/request.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type { IndexedDbStamper, WebauthnStamper } from '../../stampers/types.js'
|
|
3
3
|
|
|
4
4
|
export type RestRequestArgs = {
|
|
5
5
|
path: string
|
|
6
6
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
7
7
|
body?: any
|
|
8
8
|
headers?: Record<string, string>
|
|
9
|
-
stamp?: boolean
|
|
9
|
+
stamp?: boolean
|
|
10
|
+
stampWith?: 'indexedDb' | 'webAuthn'
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export type RestRequestFn = <T = any>(args: RestRequestArgs) => Promise<T>
|
|
@@ -27,13 +28,11 @@ export type RestTransportConfig = {
|
|
|
27
28
|
timeoutMs?: number
|
|
28
29
|
key?: string
|
|
29
30
|
name?: string
|
|
30
|
-
|
|
31
|
+
indexedDbStamper: IndexedDbStamper
|
|
32
|
+
webauthnStamper: WebauthnStamper
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export function rest(
|
|
34
|
-
url: string,
|
|
35
|
-
cfg: RestTransportConfig = {},
|
|
36
|
-
): RestTransport {
|
|
35
|
+
export function rest(url: string, cfg: RestTransportConfig): RestTransport {
|
|
37
36
|
const timeoutMs = cfg.timeoutMs ?? 10_000
|
|
38
37
|
const key = cfg.key ?? 'rest'
|
|
39
38
|
const name = cfg.name ?? 'HTTP REST'
|
|
@@ -52,10 +51,18 @@ export function rest(
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
// Handle stamping if requested
|
|
55
|
-
if (args.stamp
|
|
54
|
+
if (args.stamp) {
|
|
55
|
+
let stamper: IndexedDbStamper | WebauthnStamper
|
|
56
|
+
if (args.stampWith === 'indexedDb') {
|
|
57
|
+
stamper = cfg.indexedDbStamper
|
|
58
|
+
} else if (args.stampWith === 'webAuthn') {
|
|
59
|
+
stamper = cfg.webauthnStamper
|
|
60
|
+
} else {
|
|
61
|
+
stamper = cfg.indexedDbStamper
|
|
62
|
+
}
|
|
56
63
|
const { body, apiUrl } = args.body
|
|
57
64
|
const bodyString = `${JSON.stringify(body ?? args.body)}\n`
|
|
58
|
-
const stamp = await
|
|
65
|
+
const stamp = await stamper.stamp(bodyString)
|
|
59
66
|
|
|
60
67
|
// Restructure request body to match backend expectation
|
|
61
68
|
if (body) {
|
package/src/client/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IndexedDbStamper, WebauthnStamper } from '../stampers/types.js'
|
|
2
2
|
import type { RestRequestFn } from './transports/rest.js'
|
|
3
3
|
|
|
4
4
|
export type TransportConfig = {
|
|
@@ -16,35 +16,33 @@ export type TransportConfig = {
|
|
|
16
16
|
type: string
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export type Transport = (options: {
|
|
19
|
+
export type Transport = (options: {
|
|
20
|
+
indexedDbStamper: IndexedDbStamper
|
|
21
|
+
webauthnStamper: WebauthnStamper
|
|
22
|
+
}) => {
|
|
20
23
|
config: TransportConfig
|
|
21
24
|
request: RestRequestFn
|
|
22
25
|
value?: Record<string, unknown>
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
export type ClientConfig
|
|
26
|
-
/** Transport for the client */
|
|
28
|
+
export type ClientConfig = {
|
|
27
29
|
transport: Transport
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** Organization ID */
|
|
30
|
+
indexedDbStamper: IndexedDbStamper
|
|
31
|
+
webauthnStamper: WebauthnStamper
|
|
31
32
|
organizationId?: string
|
|
32
|
-
/** A key for the client. */
|
|
33
33
|
key?: string
|
|
34
|
-
/** A name for the client. */
|
|
35
34
|
name?: string
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
export type Client<
|
|
39
|
-
extended extends Extended | undefined = undefined,
|
|
40
|
-
TStamper extends Stamper = Stamper,
|
|
41
|
-
> = {
|
|
37
|
+
export type Client<extended extends Extended | undefined = undefined> = {
|
|
42
38
|
/** Transport configuration */
|
|
43
39
|
transport: TransportConfig & Record<string, unknown>
|
|
44
40
|
/** Request function from transport */
|
|
45
41
|
request: RestRequestFn
|
|
46
|
-
/** Stamper for authenticated requests */
|
|
47
|
-
|
|
42
|
+
/** IndexedDB Stamper for authenticated requests */
|
|
43
|
+
indexedDbStamper: IndexedDbStamper
|
|
44
|
+
/** WebAuthn Stamper for authenticated requests */
|
|
45
|
+
webauthnStamper: WebauthnStamper
|
|
48
46
|
/** Organization ID */
|
|
49
47
|
organizationId?: string
|
|
50
48
|
/** A key for the client */
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
KMS_SERVER_URL,
|
|
14
14
|
} from '../constants.js'
|
|
15
15
|
import { createIndexedDbStamper } from '../stampers/indexedDbStamper.js'
|
|
16
|
-
import type { IndexedDbStamper } from '../stampers/types.js'
|
|
17
16
|
import { createWebauthnStamper } from '../stampers/webauthnStamper.js'
|
|
18
17
|
import { createWebStorageAdapter } from '../storage/adapters.js'
|
|
19
18
|
import {
|
|
@@ -73,7 +72,7 @@ export type AuthParams =
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
export interface ZeroDevWalletSDK {
|
|
76
|
-
client:
|
|
75
|
+
client: ZeroDevWalletClient
|
|
77
76
|
auth: (params: AuthParams) => Promise<any>
|
|
78
77
|
|
|
79
78
|
getPublicKey: () => Promise<string | null>
|
|
@@ -112,42 +111,19 @@ export async function createZeroDevWallet(
|
|
|
112
111
|
|
|
113
112
|
const webauthnStamper = await createWebauthnStamper({ rpId })
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
stamper: indexedDbStamper,
|
|
119
|
-
transport: zeroDevWalletTransport({
|
|
120
|
-
baseUrl: config.proxyBaseUrl || `${KMS_SERVER_URL}/api/v1`,
|
|
121
|
-
}),
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
const passkeyClient = createClient({
|
|
125
|
-
stamper: webauthnStamper,
|
|
114
|
+
const client = createClient({
|
|
115
|
+
indexedDbStamper,
|
|
116
|
+
webauthnStamper,
|
|
126
117
|
transport: zeroDevWalletTransport({
|
|
127
118
|
baseUrl: config.proxyBaseUrl || `${KMS_SERVER_URL}/api/v1`,
|
|
128
119
|
}),
|
|
129
120
|
})
|
|
130
121
|
|
|
131
|
-
// Restore active session on initialization
|
|
132
|
-
const activeSession = await sessionStorageManager.getActiveSession()
|
|
133
|
-
|
|
134
|
-
if (activeSession) {
|
|
135
|
-
try {
|
|
136
|
-
if (activeSession.stamperType === 'indexedDb') {
|
|
137
|
-
currentClient = indexedDbClient
|
|
138
|
-
}
|
|
139
|
-
} catch (_error) {}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const getClient = () => {
|
|
143
|
-
return currentClient
|
|
144
|
-
}
|
|
145
|
-
|
|
146
122
|
return {
|
|
147
|
-
client
|
|
123
|
+
client,
|
|
148
124
|
async getPublicKey() {
|
|
149
|
-
await
|
|
150
|
-
const compressedPublicKey = await
|
|
125
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
126
|
+
const compressedPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
151
127
|
return compressedPublicKey
|
|
152
128
|
},
|
|
153
129
|
|
|
@@ -168,23 +144,6 @@ export async function createZeroDevWallet(
|
|
|
168
144
|
await sessionStorageManager.setActiveSession(sessionId)
|
|
169
145
|
const session = await sessionStorageManager.getActiveSession()
|
|
170
146
|
|
|
171
|
-
if (session) {
|
|
172
|
-
// Update current client based on session's stamper type
|
|
173
|
-
let stamper: IndexedDbStamper | undefined
|
|
174
|
-
if (session.stamperType === 'indexedDb') {
|
|
175
|
-
stamper = indexedDbStamper
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (stamper) {
|
|
179
|
-
currentClient = createClient({
|
|
180
|
-
stamper,
|
|
181
|
-
transport: zeroDevWalletTransport({
|
|
182
|
-
baseUrl: config.proxyBaseUrl || `${KMS_SERVER_URL}/api/v1`,
|
|
183
|
-
}),
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
147
|
return session
|
|
189
148
|
},
|
|
190
149
|
|
|
@@ -194,7 +153,6 @@ export async function createZeroDevWallet(
|
|
|
194
153
|
|
|
195
154
|
async clearAllSessions() {
|
|
196
155
|
await sessionStorageManager.clearAllSessions()
|
|
197
|
-
currentClient = null
|
|
198
156
|
},
|
|
199
157
|
|
|
200
158
|
async refreshSession(sessionId?: string) {
|
|
@@ -215,12 +173,13 @@ export async function createZeroDevWallet(
|
|
|
215
173
|
)
|
|
216
174
|
const compressedPublicKeyHex =
|
|
217
175
|
await generateCompressedPublicKeyFromKeyPair(newKeyPair)
|
|
218
|
-
const data = await
|
|
176
|
+
const data = await client.loginWithStamp({
|
|
219
177
|
targetPublicKey: compressedPublicKeyHex,
|
|
220
178
|
projectId,
|
|
221
179
|
organizationId: activeSession.organizationId,
|
|
180
|
+
stampWith: 'indexedDb',
|
|
222
181
|
})
|
|
223
|
-
await
|
|
182
|
+
await client.indexedDbStamper.resetKeyPair(newKeyPair)
|
|
224
183
|
const parsedSession = parseSession(data.session)
|
|
225
184
|
const session: ZeroDevWalletSession = {
|
|
226
185
|
id: `session_indexedDb_${Date.now()}`,
|
|
@@ -234,7 +193,6 @@ export async function createZeroDevWallet(
|
|
|
234
193
|
}
|
|
235
194
|
await sessionStorageManager.clearSession(activeSession.id)
|
|
236
195
|
await sessionStorageManager.storeSession(session, session.id)
|
|
237
|
-
currentClient = indexedDbClient
|
|
238
196
|
return session
|
|
239
197
|
}
|
|
240
198
|
throw new Error('Invalid session type')
|
|
@@ -245,13 +203,13 @@ export async function createZeroDevWallet(
|
|
|
245
203
|
switch (params.type) {
|
|
246
204
|
case 'oauth': {
|
|
247
205
|
const { credential } = params
|
|
248
|
-
const targetPublicKey = await
|
|
206
|
+
const targetPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
249
207
|
|
|
250
208
|
if (!targetPublicKey) {
|
|
251
209
|
throw new Error('Failed to get public key')
|
|
252
210
|
}
|
|
253
211
|
|
|
254
|
-
const data = await
|
|
212
|
+
const data = await client.authenticateWithOAuth({
|
|
255
213
|
oidcToken: credential,
|
|
256
214
|
provider: 'google',
|
|
257
215
|
targetPublicKey,
|
|
@@ -274,7 +232,6 @@ export async function createZeroDevWallet(
|
|
|
274
232
|
}
|
|
275
233
|
await sessionStorageManager.storeSession(session, session.id)
|
|
276
234
|
}
|
|
277
|
-
currentClient = indexedDbClient
|
|
278
235
|
return data
|
|
279
236
|
}
|
|
280
237
|
case 'passkey': {
|
|
@@ -285,8 +242,8 @@ export async function createZeroDevWallet(
|
|
|
285
242
|
params.mode === 'register'
|
|
286
243
|
) {
|
|
287
244
|
const { email } = params
|
|
288
|
-
await
|
|
289
|
-
const tempPublicKey = await
|
|
245
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
246
|
+
const tempPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
290
247
|
if (!tempPublicKey) {
|
|
291
248
|
throw new Error('Failed to get public key')
|
|
292
249
|
}
|
|
@@ -315,7 +272,7 @@ export async function createZeroDevWallet(
|
|
|
315
272
|
},
|
|
316
273
|
},
|
|
317
274
|
})
|
|
318
|
-
const data = await
|
|
275
|
+
const data = await client.registerWithPasskey({
|
|
319
276
|
email,
|
|
320
277
|
attestation,
|
|
321
278
|
challenge: encodedChallenge,
|
|
@@ -332,12 +289,12 @@ export async function createZeroDevWallet(
|
|
|
332
289
|
)
|
|
333
290
|
const compressedPublicKeyHex =
|
|
334
291
|
await generateCompressedPublicKeyFromKeyPair(newKeyPair)
|
|
335
|
-
const loginData = await
|
|
292
|
+
const loginData = await client.loginWithStamp({
|
|
336
293
|
projectId,
|
|
337
294
|
targetPublicKey: compressedPublicKeyHex,
|
|
338
295
|
organizationId: data.subOrganizationId,
|
|
339
296
|
})
|
|
340
|
-
await
|
|
297
|
+
await client.indexedDbStamper.resetKeyPair(newKeyPair)
|
|
341
298
|
const parsedSession = parseSession(loginData.session)
|
|
342
299
|
const session: ZeroDevWalletSession = {
|
|
343
300
|
id: `session_indexedDb_${Date.now()}`,
|
|
@@ -352,7 +309,6 @@ export async function createZeroDevWallet(
|
|
|
352
309
|
token: loginData.session,
|
|
353
310
|
}
|
|
354
311
|
await sessionStorageManager.storeSession(session, session.id)
|
|
355
|
-
currentClient = indexedDbClient
|
|
356
312
|
return data
|
|
357
313
|
}
|
|
358
314
|
if (
|
|
@@ -360,16 +316,17 @@ export async function createZeroDevWallet(
|
|
|
360
316
|
'mode' in params &&
|
|
361
317
|
params.mode === 'login'
|
|
362
318
|
) {
|
|
363
|
-
await
|
|
319
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
364
320
|
const generatedPublicKey =
|
|
365
|
-
await
|
|
321
|
+
await client.indexedDbStamper.getPublicKey()
|
|
366
322
|
if (!generatedPublicKey) {
|
|
367
323
|
throw new Error('Failed to get public key')
|
|
368
324
|
}
|
|
369
|
-
const loginData = await
|
|
325
|
+
const loginData = await client.loginWithStamp({
|
|
370
326
|
targetPublicKey: generatedPublicKey,
|
|
371
327
|
projectId,
|
|
372
328
|
organizationId,
|
|
329
|
+
stampWith: 'webauthn',
|
|
373
330
|
})
|
|
374
331
|
const parsedSession = parseSession(loginData.session)
|
|
375
332
|
const session: ZeroDevWalletSession = {
|
|
@@ -385,7 +342,6 @@ export async function createZeroDevWallet(
|
|
|
385
342
|
token: loginData.session,
|
|
386
343
|
}
|
|
387
344
|
await sessionStorageManager.storeSession(session, session.id)
|
|
388
|
-
currentClient = indexedDbClient
|
|
389
345
|
return loginData
|
|
390
346
|
}
|
|
391
347
|
throw new Error('Passkey authentication requires passkey parameter')
|
|
@@ -396,7 +352,7 @@ export async function createZeroDevWallet(
|
|
|
396
352
|
if (type === 'otp' && mode === 'sendOtp') {
|
|
397
353
|
const { email, contact, emailCustomization } = params
|
|
398
354
|
|
|
399
|
-
const data = await
|
|
355
|
+
const data = await client.registerWithOTP({
|
|
400
356
|
email,
|
|
401
357
|
contact,
|
|
402
358
|
projectId,
|
|
@@ -408,14 +364,14 @@ export async function createZeroDevWallet(
|
|
|
408
364
|
|
|
409
365
|
if (type === 'otp' && mode === 'verifyOtp') {
|
|
410
366
|
const { otpId, otpCode, subOrganizationId } = params
|
|
411
|
-
await
|
|
412
|
-
const targetPublicKey = await
|
|
367
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
368
|
+
const targetPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
413
369
|
|
|
414
370
|
if (!targetPublicKey) {
|
|
415
371
|
throw new Error('Failed to get public key')
|
|
416
372
|
}
|
|
417
373
|
|
|
418
|
-
const data = await
|
|
374
|
+
const data = await client.loginWithOTP({
|
|
419
375
|
otpId,
|
|
420
376
|
otpCode,
|
|
421
377
|
subOrganizationId,
|
|
@@ -440,7 +396,6 @@ export async function createZeroDevWallet(
|
|
|
440
396
|
}
|
|
441
397
|
await sessionStorageManager.storeSession(session, session.id)
|
|
442
398
|
}
|
|
443
|
-
currentClient = indexedDbClient
|
|
444
399
|
return data
|
|
445
400
|
}
|
|
446
401
|
|
|
@@ -453,8 +408,7 @@ export async function createZeroDevWallet(
|
|
|
453
408
|
|
|
454
409
|
async logout() {
|
|
455
410
|
await sessionStorageManager.clearAllSessions()
|
|
456
|
-
|
|
457
|
-
await indexedDbClient.stamper.resetKeyPair()
|
|
411
|
+
await client.indexedDbStamper.resetKeyPair()
|
|
458
412
|
return true
|
|
459
413
|
},
|
|
460
414
|
|
|
@@ -463,12 +417,9 @@ export async function createZeroDevWallet(
|
|
|
463
417
|
if (!session) {
|
|
464
418
|
throw new Error('No active session')
|
|
465
419
|
}
|
|
466
|
-
if (!currentClient) {
|
|
467
|
-
throw new Error('No client')
|
|
468
|
-
}
|
|
469
420
|
|
|
470
421
|
return toViemAccount({
|
|
471
|
-
client
|
|
422
|
+
client,
|
|
472
423
|
organizationId: session.organizationId,
|
|
473
424
|
projectId,
|
|
474
425
|
})
|
|
@@ -54,9 +54,12 @@ export async function exportWallet(
|
|
|
54
54
|
organizationId,
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
const listWalletsStamp =
|
|
58
|
-
.client
|
|
59
|
-
|
|
57
|
+
const listWalletsStamp =
|
|
58
|
+
await wallet.client[
|
|
59
|
+
session.stamperType === 'indexedDb'
|
|
60
|
+
? 'indexedDbStamper'
|
|
61
|
+
: 'webauthnStamper'
|
|
62
|
+
].stamp(listWalletsBody)
|
|
60
63
|
if (!listWalletsStamp) {
|
|
61
64
|
throw new Error('Failed to stamp list wallets body')
|
|
62
65
|
}
|
|
@@ -88,9 +91,12 @@ export async function exportWallet(
|
|
|
88
91
|
language: 'MNEMONIC_LANGUAGE_ENGLISH',
|
|
89
92
|
},
|
|
90
93
|
})
|
|
91
|
-
const exportWalletStamp =
|
|
92
|
-
.client
|
|
93
|
-
|
|
94
|
+
const exportWalletStamp =
|
|
95
|
+
await wallet.client[
|
|
96
|
+
session.stamperType === 'indexedDb'
|
|
97
|
+
? 'indexedDbStamper'
|
|
98
|
+
: 'webauthnStamper'
|
|
99
|
+
].stamp(exportWalletBody)
|
|
94
100
|
if (!exportWalletStamp) {
|
|
95
101
|
throw new Error('Failed to stamp export wallet body')
|
|
96
102
|
}
|