@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.
Files changed (33) hide show
  1. package/README.md +9 -15
  2. package/dist/_cjs/actions/auth/registerWithPasskey.js +1 -2
  3. package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -1
  4. package/dist/_cjs/adapters/viem.js +4 -4
  5. package/dist/_cjs/adapters/viem.js.map +1 -1
  6. package/dist/_cjs/core/createZeroDevWallet.js +36 -10
  7. package/dist/_cjs/core/createZeroDevWallet.js.map +1 -1
  8. package/dist/_cjs/stampers/iframeStamper.js +3 -0
  9. package/dist/_cjs/stampers/iframeStamper.js.map +1 -1
  10. package/dist/_esm/actions/auth/registerWithPasskey.js +1 -3
  11. package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -1
  12. package/dist/_esm/adapters/viem.js +4 -4
  13. package/dist/_esm/adapters/viem.js.map +1 -1
  14. package/dist/_esm/core/createZeroDevWallet.js +37 -10
  15. package/dist/_esm/core/createZeroDevWallet.js.map +1 -1
  16. package/dist/_esm/stampers/iframeStamper.js +3 -0
  17. package/dist/_esm/stampers/iframeStamper.js.map +1 -1
  18. package/dist/_types/actions/auth/registerWithPasskey.d.ts +0 -3
  19. package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -1
  20. package/dist/_types/adapters/viem.d.ts +1 -1
  21. package/dist/_types/adapters/viem.d.ts.map +1 -1
  22. package/dist/_types/core/createZeroDevWallet.d.ts +10 -1
  23. package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -1
  24. package/dist/_types/stampers/iframeStamper.d.ts.map +1 -1
  25. package/dist/_types/stampers/types.d.ts +3 -0
  26. package/dist/_types/stampers/types.d.ts.map +1 -1
  27. package/dist/tsconfig.build.tsbuildinfo +1 -1
  28. package/package.json +1 -1
  29. package/src/actions/auth/registerWithPasskey.ts +1 -5
  30. package/src/adapters/viem.ts +5 -5
  31. package/src/core/createZeroDevWallet.ts +47 -11
  32. package/src/stampers/iframeStamper.ts +3 -0
  33. package/src/stampers/types.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-core",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.12",
4
4
  "description": "ZeroDev Wallet SDK built on Turnkey",
5
5
  "main": "./dist/_cjs/index.js",
6
6
  "module": "./dist/_esm/index.js",
@@ -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 { email, projectId, challenge, attestation, encodedPublicKey } = params
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,
@@ -24,13 +24,13 @@ export interface ToViemAccountParams {
24
24
  client: ZeroDevWalletClient
25
25
  organizationId: string
26
26
  projectId: string
27
- token: string
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, token } = params
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()}-${email}`
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
- const { type, mode } = params
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 (type === 'otp' && mode === 'sendOtp') {
348
- const { email, contact, emailCustomization } = params
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 (type === 'otp' && mode === 'verifyOtp') {
361
- const { otpId, otpCode } = params
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
- token: session.token ?? '',
476
+ getToken: async () => {
477
+ const activeSession = await sessionStorageManager.getActiveSession()
478
+ return activeSession?.token ?? ''
479
+ },
444
480
  })
445
481
  },
446
482
  }
@@ -45,5 +45,8 @@ export async function createIframeStamper(cfg: {
45
45
  keyFormat ? KeyFormat[keyFormat] : KeyFormat.Hexadecimal,
46
46
  )
47
47
  },
48
+ async applySettings(settings: { styles?: Record<string, string> }) {
49
+ return await inner.applySettings(settings)
50
+ },
48
51
  }
49
52
  }
@@ -27,6 +27,7 @@ export type IframeStamper = Stamper & {
27
27
  organizationId: string,
28
28
  keyFormat?: KeyFormat,
29
29
  ): Promise<boolean>
30
+ applySettings(settings: { styles?: Record<string, string> }): Promise<boolean>
30
31
  }
31
32
 
32
33
  export type IndexedDbStamper = Stamper & {