@zerodev/wallet-core 0.0.1-alpha.10 → 0.0.1-alpha.12
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 +9 -15
- package/dist/_cjs/actions/auth/registerWithPasskey.js +1 -2
- package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -1
- package/dist/_cjs/adapters/viem.js +4 -4
- package/dist/_cjs/adapters/viem.js.map +1 -1
- package/dist/_cjs/core/createZeroDevWallet.js +36 -10
- package/dist/_cjs/core/createZeroDevWallet.js.map +1 -1
- package/dist/_cjs/stampers/iframeStamper.js +3 -0
- package/dist/_cjs/stampers/iframeStamper.js.map +1 -1
- package/dist/_esm/actions/auth/registerWithPasskey.js +1 -3
- package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -1
- package/dist/_esm/adapters/viem.js +4 -4
- package/dist/_esm/adapters/viem.js.map +1 -1
- package/dist/_esm/core/createZeroDevWallet.js +37 -10
- package/dist/_esm/core/createZeroDevWallet.js.map +1 -1
- package/dist/_esm/stampers/iframeStamper.js +3 -0
- package/dist/_esm/stampers/iframeStamper.js.map +1 -1
- package/dist/_types/actions/auth/registerWithPasskey.d.ts +0 -3
- package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -1
- package/dist/_types/adapters/viem.d.ts +1 -1
- package/dist/_types/adapters/viem.d.ts.map +1 -1
- package/dist/_types/core/createZeroDevWallet.d.ts +10 -1
- package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -1
- package/dist/_types/stampers/iframeStamper.d.ts.map +1 -1
- package/dist/_types/stampers/types.d.ts +3 -0
- package/dist/_types/stampers/types.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/actions/auth/registerWithPasskey.ts +1 -5
- package/src/adapters/viem.ts +5 -5
- package/src/core/createZeroDevWallet.ts +47 -11
- package/src/stampers/iframeStamper.ts +3 -0
- package/src/stampers/types.ts +1 -0
package/package.json
CHANGED
|
@@ -6,8 +6,6 @@ export type EmailCustomization = {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export type RegisterWithPasskeyParameters = {
|
|
9
|
-
/** The email address to authenticate */
|
|
10
|
-
email: string
|
|
11
9
|
/** The project ID for the request */
|
|
12
10
|
projectId: string
|
|
13
11
|
/** The challenge for the request */
|
|
@@ -41,7 +39,6 @@ export type RegisterWithPasskeyReturnType = {
|
|
|
41
39
|
* @example
|
|
42
40
|
* ```ts
|
|
43
41
|
* const result = await registerWithPasskey(client, {
|
|
44
|
-
* email: 'user@example.com',
|
|
45
42
|
* projectId: 'proj_456',
|
|
46
43
|
* challenge: 'challenge',
|
|
47
44
|
* attestation: {
|
|
@@ -57,13 +54,12 @@ export async function registerWithPasskey(
|
|
|
57
54
|
client: Client,
|
|
58
55
|
params: RegisterWithPasskeyParameters,
|
|
59
56
|
): Promise<RegisterWithPasskeyReturnType> {
|
|
60
|
-
const {
|
|
57
|
+
const { projectId, challenge, attestation, encodedPublicKey } = params
|
|
61
58
|
|
|
62
59
|
return client.request({
|
|
63
60
|
path: `${projectId}/auth/register/passkey`,
|
|
64
61
|
method: 'POST',
|
|
65
62
|
body: {
|
|
66
|
-
email,
|
|
67
63
|
attestation,
|
|
68
64
|
challenge,
|
|
69
65
|
encodedPublicKey,
|
package/src/adapters/viem.ts
CHANGED
|
@@ -24,13 +24,13 @@ export interface ToViemAccountParams {
|
|
|
24
24
|
client: ZeroDevWalletClient
|
|
25
25
|
organizationId: string
|
|
26
26
|
projectId: string
|
|
27
|
-
|
|
27
|
+
getToken: () => string | Promise<string>
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export async function toViemAccount(
|
|
31
31
|
params: ToViemAccountParams,
|
|
32
32
|
): Promise<LocalAccount> {
|
|
33
|
-
const { client, organizationId, projectId,
|
|
33
|
+
const { client, organizationId, projectId, getToken } = params
|
|
34
34
|
|
|
35
35
|
let address: Hex = zeroAddress
|
|
36
36
|
|
|
@@ -38,7 +38,7 @@ export async function toViemAccount(
|
|
|
38
38
|
const walletResponse = await client.getUserWallet({
|
|
39
39
|
organizationId,
|
|
40
40
|
projectId,
|
|
41
|
-
token,
|
|
41
|
+
token: await getToken(),
|
|
42
42
|
})
|
|
43
43
|
address = walletResponse.walletAddresses[0]
|
|
44
44
|
} catch {
|
|
@@ -53,7 +53,7 @@ export async function toViemAccount(
|
|
|
53
53
|
return await client.signRawPayload({
|
|
54
54
|
organizationId,
|
|
55
55
|
projectId,
|
|
56
|
-
token,
|
|
56
|
+
token: await getToken(),
|
|
57
57
|
address,
|
|
58
58
|
payload,
|
|
59
59
|
encoding,
|
|
@@ -79,7 +79,7 @@ export async function toViemAccount(
|
|
|
79
79
|
const signature = await client.signTransaction({
|
|
80
80
|
organizationId,
|
|
81
81
|
projectId,
|
|
82
|
-
token,
|
|
82
|
+
token: await getToken(),
|
|
83
83
|
address,
|
|
84
84
|
unsignedTransaction: nonHexPrefixedSerializedTx,
|
|
85
85
|
})
|
|
@@ -50,7 +50,6 @@ export type AuthParams =
|
|
|
50
50
|
}
|
|
51
51
|
| {
|
|
52
52
|
type: 'passkey'
|
|
53
|
-
email: string
|
|
54
53
|
mode: 'register' | 'login'
|
|
55
54
|
}
|
|
56
55
|
| {
|
|
@@ -69,6 +68,18 @@ export type AuthParams =
|
|
|
69
68
|
otpId: string
|
|
70
69
|
otpCode: string
|
|
71
70
|
}
|
|
71
|
+
| {
|
|
72
|
+
type: 'magicLink'
|
|
73
|
+
mode: 'send'
|
|
74
|
+
email: string
|
|
75
|
+
redirectURL: string
|
|
76
|
+
}
|
|
77
|
+
| {
|
|
78
|
+
type: 'magicLink'
|
|
79
|
+
mode: 'verify'
|
|
80
|
+
otpId: string
|
|
81
|
+
code: string
|
|
82
|
+
}
|
|
72
83
|
|
|
73
84
|
export interface ZeroDevWalletSDK {
|
|
74
85
|
client: ZeroDevWalletClient
|
|
@@ -236,7 +247,6 @@ export async function createZeroDevWallet(
|
|
|
236
247
|
'mode' in params &&
|
|
237
248
|
params.mode === 'register'
|
|
238
249
|
) {
|
|
239
|
-
const { email } = params
|
|
240
250
|
await client.indexedDbStamper.resetKeyPair()
|
|
241
251
|
const tempPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
242
252
|
if (!tempPublicKey) {
|
|
@@ -245,7 +255,7 @@ export async function createZeroDevWallet(
|
|
|
245
255
|
const challenge = generateRandomBuffer()
|
|
246
256
|
const encodedChallenge = base64UrlEncode(challenge)
|
|
247
257
|
const authenticatorUserId = generateRandomBuffer()
|
|
248
|
-
const name = `ZeroDevWallet-${humanReadableDateTime()}
|
|
258
|
+
const name = `ZeroDevWallet-${humanReadableDateTime()}`
|
|
249
259
|
const attestation = await getWebAuthnAttestation({
|
|
250
260
|
publicKey: {
|
|
251
261
|
rp: { id: rpId, name: '' },
|
|
@@ -268,7 +278,6 @@ export async function createZeroDevWallet(
|
|
|
268
278
|
},
|
|
269
279
|
})
|
|
270
280
|
const data = await client.registerWithPasskey({
|
|
271
|
-
email,
|
|
272
281
|
attestation,
|
|
273
282
|
challenge: encodedChallenge,
|
|
274
283
|
projectId,
|
|
@@ -341,11 +350,35 @@ export async function createZeroDevWallet(
|
|
|
341
350
|
}
|
|
342
351
|
throw new Error('Passkey authentication requires passkey parameter')
|
|
343
352
|
}
|
|
344
|
-
case 'otp':
|
|
345
|
-
|
|
353
|
+
case 'otp':
|
|
354
|
+
case 'magicLink': {
|
|
355
|
+
// Normalize magicLink params into OTP params
|
|
356
|
+
let otpParams: Extract<AuthParams, { type: 'otp' }>
|
|
357
|
+
if (params.type === 'magicLink') {
|
|
358
|
+
if (params.mode === 'send') {
|
|
359
|
+
otpParams = {
|
|
360
|
+
type: 'otp',
|
|
361
|
+
mode: 'sendOtp',
|
|
362
|
+
email: params.email,
|
|
363
|
+
contact: { type: 'email', contact: params.email },
|
|
364
|
+
emailCustomization: {
|
|
365
|
+
magicLinkTemplate: `${params.redirectURL}${params.redirectURL.includes('?') ? '&' : '?'}code=%s`,
|
|
366
|
+
},
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
otpParams = {
|
|
370
|
+
type: 'otp',
|
|
371
|
+
mode: 'verifyOtp',
|
|
372
|
+
otpId: params.otpId,
|
|
373
|
+
otpCode: params.code,
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
otpParams = params
|
|
378
|
+
}
|
|
346
379
|
|
|
347
|
-
if (
|
|
348
|
-
const { email, contact, emailCustomization } =
|
|
380
|
+
if (otpParams.mode === 'sendOtp') {
|
|
381
|
+
const { email, contact, emailCustomization } = otpParams
|
|
349
382
|
|
|
350
383
|
const data = await client.registerWithOTP({
|
|
351
384
|
email,
|
|
@@ -357,8 +390,8 @@ export async function createZeroDevWallet(
|
|
|
357
390
|
return data
|
|
358
391
|
}
|
|
359
392
|
|
|
360
|
-
if (
|
|
361
|
-
const { otpId, otpCode } =
|
|
393
|
+
if (otpParams.mode === 'verifyOtp') {
|
|
394
|
+
const { otpId, otpCode } = otpParams
|
|
362
395
|
|
|
363
396
|
// Step 1: Generate new key pair
|
|
364
397
|
await client.indexedDbStamper.resetKeyPair()
|
|
@@ -440,7 +473,10 @@ export async function createZeroDevWallet(
|
|
|
440
473
|
client,
|
|
441
474
|
organizationId: session.organizationId,
|
|
442
475
|
projectId,
|
|
443
|
-
|
|
476
|
+
getToken: async () => {
|
|
477
|
+
const activeSession = await sessionStorageManager.getActiveSession()
|
|
478
|
+
return activeSession?.token ?? ''
|
|
479
|
+
},
|
|
444
480
|
})
|
|
445
481
|
},
|
|
446
482
|
}
|
package/src/stampers/types.ts
CHANGED