@zerodev/wallet-core 0.0.1-alpha.11 → 0.0.1-alpha.13
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 +37 -16
- package/dist/_cjs/actions/auth/index.js.map +1 -1
- package/dist/_cjs/actions/auth/registerWithOTP.js +6 -1
- package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -1
- package/dist/_cjs/actions/auth/registerWithPasskey.js +1 -2
- package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -1
- package/dist/_cjs/core/createZeroDevWallet.js +36 -9
- 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/index.js.map +1 -1
- package/dist/_esm/actions/auth/registerWithOTP.js +6 -1
- package/dist/_esm/actions/auth/registerWithOTP.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/core/createZeroDevWallet.js +37 -9
- 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/index.d.ts +1 -1
- package/dist/_types/actions/auth/index.d.ts.map +1 -1
- package/dist/_types/actions/auth/registerWithOTP.d.ts +8 -0
- package/dist/_types/actions/auth/registerWithOTP.d.ts.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/core/createZeroDevWallet.d.ts +13 -2
- 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/index.ts +1 -0
- package/src/actions/auth/registerWithOTP.ts +24 -1
- package/src/actions/auth/registerWithPasskey.ts +1 -5
- package/src/core/createZeroDevWallet.ts +54 -11
- package/src/stampers/iframeStamper.ts +3 -0
- package/src/stampers/types.ts +1 -0
package/package.json
CHANGED
|
@@ -8,6 +8,13 @@ export type OtpContact = {
|
|
|
8
8
|
contact: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export type OtpCodeCustomization = {
|
|
12
|
+
/** The length of the OTP code (must be between 6 and 9 inclusive) */
|
|
13
|
+
length: 6 | 7 | 8 | 9
|
|
14
|
+
/** Whether the OTP code should be alphanumeric */
|
|
15
|
+
alphanumeric: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
export type RegisterWithOTPParameters = {
|
|
12
19
|
/** The email address to register */
|
|
13
20
|
email: string
|
|
@@ -17,6 +24,8 @@ export type RegisterWithOTPParameters = {
|
|
|
17
24
|
projectId: string
|
|
18
25
|
/** Optional email customization settings */
|
|
19
26
|
emailCustomization?: EmailCustomization
|
|
27
|
+
/** Optional OTP code customization settings */
|
|
28
|
+
otpCodeCustomization?: OtpCodeCustomization
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
export type RegisterWithOTPReturnType = {
|
|
@@ -50,7 +59,20 @@ export async function registerWithOTP(
|
|
|
50
59
|
client: Client,
|
|
51
60
|
params: RegisterWithOTPParameters,
|
|
52
61
|
): Promise<RegisterWithOTPReturnType> {
|
|
53
|
-
const {
|
|
62
|
+
const {
|
|
63
|
+
email,
|
|
64
|
+
contact,
|
|
65
|
+
projectId,
|
|
66
|
+
emailCustomization,
|
|
67
|
+
otpCodeCustomization,
|
|
68
|
+
} = params
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
otpCodeCustomization &&
|
|
72
|
+
(otpCodeCustomization.length < 6 || otpCodeCustomization.length > 9)
|
|
73
|
+
) {
|
|
74
|
+
throw new Error('OTP code length must be between 6 and 9')
|
|
75
|
+
}
|
|
54
76
|
|
|
55
77
|
return await client.request({
|
|
56
78
|
path: `${projectId}/auth/init/otp`,
|
|
@@ -59,6 +81,7 @@ export async function registerWithOTP(
|
|
|
59
81
|
email,
|
|
60
82
|
contact,
|
|
61
83
|
emailCustomization,
|
|
84
|
+
otpCodeCustomization,
|
|
62
85
|
},
|
|
63
86
|
})
|
|
64
87
|
}
|
|
@@ -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,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { getWebAuthnAttestation } from '@turnkey/http'
|
|
2
2
|
import type { LocalAccount } from 'viem/accounts'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
EmailCustomization,
|
|
5
|
+
OtpCodeCustomization,
|
|
6
|
+
} from '../actions/auth/index.js'
|
|
4
7
|
import { toViemAccount } from '../adapters/viem.js'
|
|
5
8
|
import {
|
|
6
9
|
createAuthProxyClient,
|
|
@@ -50,7 +53,6 @@ export type AuthParams =
|
|
|
50
53
|
}
|
|
51
54
|
| {
|
|
52
55
|
type: 'passkey'
|
|
53
|
-
email: string
|
|
54
56
|
mode: 'register' | 'login'
|
|
55
57
|
}
|
|
56
58
|
| {
|
|
@@ -62,6 +64,7 @@ export type AuthParams =
|
|
|
62
64
|
contact: string
|
|
63
65
|
}
|
|
64
66
|
emailCustomization?: EmailCustomization
|
|
67
|
+
otpCodeCustomization?: OtpCodeCustomization
|
|
65
68
|
}
|
|
66
69
|
| {
|
|
67
70
|
type: 'otp'
|
|
@@ -69,6 +72,19 @@ export type AuthParams =
|
|
|
69
72
|
otpId: string
|
|
70
73
|
otpCode: string
|
|
71
74
|
}
|
|
75
|
+
| {
|
|
76
|
+
type: 'magicLink'
|
|
77
|
+
mode: 'send'
|
|
78
|
+
email: string
|
|
79
|
+
redirectURL: string
|
|
80
|
+
otpCodeCustomization?: OtpCodeCustomization
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
type: 'magicLink'
|
|
84
|
+
mode: 'verify'
|
|
85
|
+
otpId: string
|
|
86
|
+
code: string
|
|
87
|
+
}
|
|
72
88
|
|
|
73
89
|
export interface ZeroDevWalletSDK {
|
|
74
90
|
client: ZeroDevWalletClient
|
|
@@ -236,7 +252,6 @@ export async function createZeroDevWallet(
|
|
|
236
252
|
'mode' in params &&
|
|
237
253
|
params.mode === 'register'
|
|
238
254
|
) {
|
|
239
|
-
const { email } = params
|
|
240
255
|
await client.indexedDbStamper.resetKeyPair()
|
|
241
256
|
const tempPublicKey = await client.indexedDbStamper.getPublicKey()
|
|
242
257
|
if (!tempPublicKey) {
|
|
@@ -245,7 +260,7 @@ export async function createZeroDevWallet(
|
|
|
245
260
|
const challenge = generateRandomBuffer()
|
|
246
261
|
const encodedChallenge = base64UrlEncode(challenge)
|
|
247
262
|
const authenticatorUserId = generateRandomBuffer()
|
|
248
|
-
const name = `ZeroDevWallet-${humanReadableDateTime()}
|
|
263
|
+
const name = `ZeroDevWallet-${humanReadableDateTime()}`
|
|
249
264
|
const attestation = await getWebAuthnAttestation({
|
|
250
265
|
publicKey: {
|
|
251
266
|
rp: { id: rpId, name: '' },
|
|
@@ -268,7 +283,6 @@ export async function createZeroDevWallet(
|
|
|
268
283
|
},
|
|
269
284
|
})
|
|
270
285
|
const data = await client.registerWithPasskey({
|
|
271
|
-
email,
|
|
272
286
|
attestation,
|
|
273
287
|
challenge: encodedChallenge,
|
|
274
288
|
projectId,
|
|
@@ -341,24 +355,53 @@ export async function createZeroDevWallet(
|
|
|
341
355
|
}
|
|
342
356
|
throw new Error('Passkey authentication requires passkey parameter')
|
|
343
357
|
}
|
|
344
|
-
case 'otp':
|
|
345
|
-
|
|
358
|
+
case 'otp':
|
|
359
|
+
case 'magicLink': {
|
|
360
|
+
// Normalize magicLink params into OTP params
|
|
361
|
+
let otpParams: Extract<AuthParams, { type: 'otp' }>
|
|
362
|
+
if (params.type === 'magicLink') {
|
|
363
|
+
if (params.mode === 'send') {
|
|
364
|
+
otpParams = {
|
|
365
|
+
type: 'otp',
|
|
366
|
+
mode: 'sendOtp',
|
|
367
|
+
email: params.email,
|
|
368
|
+
contact: { type: 'email', contact: params.email },
|
|
369
|
+
emailCustomization: {
|
|
370
|
+
magicLinkTemplate: `${params.redirectURL}${params.redirectURL.includes('?') ? '&' : '?'}code=%s`,
|
|
371
|
+
},
|
|
372
|
+
...(params.otpCodeCustomization && {
|
|
373
|
+
otpCodeCustomization: params.otpCodeCustomization,
|
|
374
|
+
}),
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
otpParams = {
|
|
378
|
+
type: 'otp',
|
|
379
|
+
mode: 'verifyOtp',
|
|
380
|
+
otpId: params.otpId,
|
|
381
|
+
otpCode: params.code,
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
otpParams = params
|
|
386
|
+
}
|
|
346
387
|
|
|
347
|
-
if (
|
|
348
|
-
const { email, contact, emailCustomization } =
|
|
388
|
+
if (otpParams.mode === 'sendOtp') {
|
|
389
|
+
const { email, contact, emailCustomization, otpCodeCustomization } =
|
|
390
|
+
otpParams
|
|
349
391
|
|
|
350
392
|
const data = await client.registerWithOTP({
|
|
351
393
|
email,
|
|
352
394
|
contact,
|
|
353
395
|
projectId,
|
|
354
396
|
...(emailCustomization && { emailCustomization }),
|
|
397
|
+
...(otpCodeCustomization && { otpCodeCustomization }),
|
|
355
398
|
})
|
|
356
399
|
|
|
357
400
|
return data
|
|
358
401
|
}
|
|
359
402
|
|
|
360
|
-
if (
|
|
361
|
-
const { otpId, otpCode } =
|
|
403
|
+
if (otpParams.mode === 'verifyOtp') {
|
|
404
|
+
const { otpId, otpCode } = otpParams
|
|
362
405
|
|
|
363
406
|
// Step 1: Generate new key pair
|
|
364
407
|
await client.indexedDbStamper.resetKeyPair()
|
package/src/stampers/types.ts
CHANGED