@0xsequence/wallet-wdk 3.0.3 → 3.0.5
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +24 -0
- package/dist/dbs/auth-commitments.d.ts +21 -3
- package/dist/dbs/auth-commitments.d.ts.map +1 -1
- package/dist/dbs/index.d.ts +1 -1
- package/dist/dbs/index.d.ts.map +1 -1
- package/dist/sequence/handlers/authcode-pkce.d.ts +2 -1
- package/dist/sequence/handlers/authcode-pkce.d.ts.map +1 -1
- package/dist/sequence/handlers/authcode-pkce.js +15 -9
- package/dist/sequence/handlers/authcode.d.ts +2 -1
- package/dist/sequence/handlers/authcode.d.ts.map +1 -1
- package/dist/sequence/handlers/authcode.js +19 -10
- package/dist/sequence/handlers/idtoken.d.ts +3 -3
- package/dist/sequence/handlers/idtoken.d.ts.map +1 -1
- package/dist/sequence/handlers/idtoken.js +3 -0
- package/dist/sequence/index.d.ts +1 -1
- package/dist/sequence/index.d.ts.map +1 -1
- package/dist/sequence/manager.d.ts +3 -0
- package/dist/sequence/manager.d.ts.map +1 -1
- package/dist/sequence/manager.js +7 -1
- package/dist/sequence/types/signature-request.d.ts +4 -0
- package/dist/sequence/types/signature-request.d.ts.map +1 -1
- package/dist/sequence/types/signature-request.js +2 -0
- package/dist/sequence/wallets.d.ts +84 -2
- package/dist/sequence/wallets.d.ts.map +1 -1
- package/dist/sequence/wallets.js +180 -24
- package/package.json +8 -8
- package/src/dbs/auth-commitments.ts +6 -3
- package/src/dbs/index.ts +1 -1
- package/src/sequence/handlers/authcode-pkce.ts +16 -10
- package/src/sequence/handlers/authcode.ts +20 -11
- package/src/sequence/handlers/idtoken.ts +8 -2
- package/src/sequence/index.ts +3 -0
- package/src/sequence/manager.ts +32 -14
- package/src/sequence/types/signature-request.ts +4 -0
- package/src/sequence/wallets.ts +315 -27
- package/test/authcode-pkce.test.ts +27 -18
- package/test/authcode.test.ts +24 -19
- package/test/identity-auth-dbs.test.ts +44 -7
- package/test/idtoken.test.ts +16 -0
- package/test/sessions-idtoken.test.ts +1 -0
- package/test/wallets.test.ts +62 -1
package/test/authcode.test.ts
CHANGED
|
@@ -113,7 +113,7 @@ describe('AuthCodeHandler', () => {
|
|
|
113
113
|
kind: 'google-pkce',
|
|
114
114
|
metadata: {},
|
|
115
115
|
target: '/test-target',
|
|
116
|
-
|
|
116
|
+
type: 'reauth',
|
|
117
117
|
signer: testWallet,
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -247,20 +247,17 @@ describe('AuthCodeHandler', () => {
|
|
|
247
247
|
|
|
248
248
|
it('Should create auth commitment and return OAuth URL', async () => {
|
|
249
249
|
const target = '/test-target'
|
|
250
|
-
const isSignUp = true
|
|
251
|
-
const signer = testWallet
|
|
252
250
|
|
|
253
|
-
const result = await authCodeHandler.commitAuth(target,
|
|
251
|
+
const result = await authCodeHandler.commitAuth(target, { type: 'auth' })
|
|
254
252
|
|
|
255
253
|
// Verify commitment was saved
|
|
256
254
|
expect(mockAuthCommitmentsSet).toHaveBeenCalledOnce()
|
|
257
255
|
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
|
|
258
256
|
|
|
259
257
|
expect(commitmentCall.kind).toBe('google-pkce')
|
|
260
|
-
expect(commitmentCall.signer).toBe(signer)
|
|
261
258
|
expect(commitmentCall.target).toBe(target)
|
|
262
259
|
expect(commitmentCall.metadata).toEqual({})
|
|
263
|
-
expect(commitmentCall.
|
|
260
|
+
expect(commitmentCall.type).toBe('auth')
|
|
264
261
|
expect(commitmentCall.id).toBeDefined()
|
|
265
262
|
expect(typeof commitmentCall.id).toBe('string')
|
|
266
263
|
|
|
@@ -276,7 +273,11 @@ describe('AuthCodeHandler', () => {
|
|
|
276
273
|
it('Should use provided state parameter', async () => {
|
|
277
274
|
const customState = 'custom-state-123'
|
|
278
275
|
|
|
279
|
-
const result = await authCodeHandler.commitAuth('/target',
|
|
276
|
+
const result = await authCodeHandler.commitAuth('/target', {
|
|
277
|
+
type: 'reauth',
|
|
278
|
+
state: customState,
|
|
279
|
+
signer: testWallet,
|
|
280
|
+
})
|
|
280
281
|
|
|
281
282
|
// Verify commitment uses custom state
|
|
282
283
|
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
|
|
@@ -285,7 +286,7 @@ describe('AuthCodeHandler', () => {
|
|
|
285
286
|
})
|
|
286
287
|
|
|
287
288
|
it('Should generate random state when not provided', async () => {
|
|
288
|
-
await authCodeHandler.commitAuth('/target',
|
|
289
|
+
await authCodeHandler.commitAuth('/target', { type: 'auth' })
|
|
289
290
|
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
|
|
290
291
|
expect(commitmentCall.id).toBeDefined()
|
|
291
292
|
expect(typeof commitmentCall.id).toBe('string')
|
|
@@ -306,7 +307,7 @@ describe('AuthCodeHandler', () => {
|
|
|
306
307
|
)
|
|
307
308
|
appleHandler.setRedirectUri('https://example.com/callback')
|
|
308
309
|
|
|
309
|
-
const result = await appleHandler.commitAuth('/target',
|
|
310
|
+
const result = await appleHandler.commitAuth('/target', { type: 'auth' })
|
|
310
311
|
|
|
311
312
|
expect(result).toContain('https://appleid.apple.com/auth/authorize?')
|
|
312
313
|
expect(result).toContain('client_id=apple-client-id')
|
|
@@ -315,10 +316,10 @@ describe('AuthCodeHandler', () => {
|
|
|
315
316
|
})
|
|
316
317
|
|
|
317
318
|
it('Should create commitment without signer', async () => {
|
|
318
|
-
await authCodeHandler.commitAuth('/target',
|
|
319
|
+
await authCodeHandler.commitAuth('/target', { type: 'auth' })
|
|
319
320
|
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
|
|
320
321
|
expect(commitmentCall.signer).toBeUndefined()
|
|
321
|
-
expect(commitmentCall.
|
|
322
|
+
expect(commitmentCall.type).toBe('auth')
|
|
322
323
|
})
|
|
323
324
|
})
|
|
324
325
|
|
|
@@ -492,7 +493,7 @@ describe('AuthCodeHandler', () => {
|
|
|
492
493
|
|
|
493
494
|
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
|
|
494
495
|
expect(commitmentCall.target).toBe(window.location.pathname)
|
|
495
|
-
expect(commitmentCall.
|
|
496
|
+
expect(commitmentCall.type).toBe('reauth')
|
|
496
497
|
expect(commitmentCall.signer).toBe(testWallet)
|
|
497
498
|
})
|
|
498
499
|
})
|
|
@@ -654,7 +655,7 @@ describe('AuthCodeHandler', () => {
|
|
|
654
655
|
it('Should handle auth commitments database errors', async () => {
|
|
655
656
|
mockAuthCommitmentsSet.mockRejectedValueOnce(new Error('Database error'))
|
|
656
657
|
|
|
657
|
-
await expect(authCodeHandler.commitAuth('/target',
|
|
658
|
+
await expect(authCodeHandler.commitAuth('/target', { type: 'auth' })).rejects.toThrow('Database error')
|
|
658
659
|
})
|
|
659
660
|
|
|
660
661
|
it('Should handle auth keys database errors', async () => {
|
|
@@ -671,7 +672,11 @@ describe('AuthCodeHandler', () => {
|
|
|
671
672
|
authCodeHandler.setRedirectUri('https://example.com/callback')
|
|
672
673
|
|
|
673
674
|
// Step 1: Commit auth
|
|
674
|
-
const commitUrl = await authCodeHandler.commitAuth('/test-target',
|
|
675
|
+
const commitUrl = await authCodeHandler.commitAuth('/test-target', {
|
|
676
|
+
type: 'reauth',
|
|
677
|
+
state: 'test-state',
|
|
678
|
+
signer: testWallet,
|
|
679
|
+
})
|
|
675
680
|
|
|
676
681
|
expect(commitUrl).toContain('state=test-state')
|
|
677
682
|
expect(mockAuthCommitmentsSet).toHaveBeenCalledWith(
|
|
@@ -679,7 +684,7 @@ describe('AuthCodeHandler', () => {
|
|
|
679
684
|
id: 'test-state',
|
|
680
685
|
kind: 'google-pkce',
|
|
681
686
|
target: '/test-target',
|
|
682
|
-
|
|
687
|
+
type: 'reauth',
|
|
683
688
|
signer: testWallet,
|
|
684
689
|
}),
|
|
685
690
|
)
|
|
@@ -709,17 +714,17 @@ describe('AuthCodeHandler', () => {
|
|
|
709
714
|
authCodeHandler.setRedirectUri('https://example.com/callback')
|
|
710
715
|
|
|
711
716
|
// Test signup flow
|
|
712
|
-
await authCodeHandler.commitAuth('/signup-target',
|
|
717
|
+
await authCodeHandler.commitAuth('/signup-target', { type: 'auth', state: 'signup-state' })
|
|
713
718
|
|
|
714
719
|
const signupCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
|
|
715
|
-
expect(signupCall.
|
|
720
|
+
expect(signupCall.type).toBe('auth')
|
|
716
721
|
expect(signupCall.target).toBe('/signup-target')
|
|
717
722
|
|
|
718
723
|
// Test login flow
|
|
719
|
-
await authCodeHandler.commitAuth('/login-target',
|
|
724
|
+
await authCodeHandler.commitAuth('/login-target', { type: 'reauth', state: 'login-state', signer: testWallet })
|
|
720
725
|
|
|
721
726
|
const loginCall = mockAuthCommitmentsSet.mock.calls[1]![0]!
|
|
722
|
-
expect(loginCall.
|
|
727
|
+
expect(loginCall.type).toBe('reauth')
|
|
723
728
|
expect(loginCall.target).toBe('/login-target')
|
|
724
729
|
})
|
|
725
730
|
})
|
|
@@ -34,7 +34,7 @@ describe('Identity Authentication Databases', () => {
|
|
|
34
34
|
verifier: 'test-verifier-code',
|
|
35
35
|
challenge: 'test-challenge-hash',
|
|
36
36
|
target: 'test-target-url',
|
|
37
|
-
|
|
37
|
+
type: 'reauth',
|
|
38
38
|
signer: '0x1234567890123456789012345678901234567890',
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -66,7 +66,7 @@ describe('Identity Authentication Databases', () => {
|
|
|
66
66
|
response_mode: 'form_post',
|
|
67
67
|
},
|
|
68
68
|
target: 'apple-redirect-url',
|
|
69
|
-
|
|
69
|
+
type: 'auth',
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
await authCommitmentsDb.set(appleCommitment)
|
|
@@ -74,7 +74,7 @@ describe('Identity Authentication Databases', () => {
|
|
|
74
74
|
|
|
75
75
|
expect(retrieved).toBeDefined()
|
|
76
76
|
expect(retrieved!.kind).toBe('apple')
|
|
77
|
-
expect(retrieved!.
|
|
77
|
+
expect(retrieved!.type).toBe('auth')
|
|
78
78
|
expect(retrieved!.metadata.response_type).toBe('code id_token')
|
|
79
79
|
})
|
|
80
80
|
|
|
@@ -85,21 +85,22 @@ describe('Identity Authentication Databases', () => {
|
|
|
85
85
|
kind: 'google-pkce',
|
|
86
86
|
metadata: {},
|
|
87
87
|
target: 'target-1',
|
|
88
|
-
|
|
88
|
+
type: 'auth',
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
id: 'commit-2',
|
|
92
92
|
kind: 'apple',
|
|
93
93
|
metadata: {},
|
|
94
94
|
target: 'target-2',
|
|
95
|
-
|
|
95
|
+
type: 'reauth',
|
|
96
|
+
signer: '0x1234567890123456789012345678901234567890',
|
|
96
97
|
},
|
|
97
98
|
{
|
|
98
99
|
id: 'commit-3',
|
|
99
100
|
kind: 'google-pkce',
|
|
100
101
|
metadata: {},
|
|
101
102
|
target: 'target-3',
|
|
102
|
-
|
|
103
|
+
type: 'auth',
|
|
103
104
|
},
|
|
104
105
|
]
|
|
105
106
|
|
|
@@ -129,7 +130,7 @@ describe('Identity Authentication Databases', () => {
|
|
|
129
130
|
kind: 'google-pkce',
|
|
130
131
|
metadata: {},
|
|
131
132
|
target: 'init-target',
|
|
132
|
-
|
|
133
|
+
type: 'auth',
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
await freshDb.set(testCommitment)
|
|
@@ -395,6 +396,42 @@ describe('Identity Authentication Databases', () => {
|
|
|
395
396
|
expect(handlers.has('login-google-pkce')).toBe(false)
|
|
396
397
|
})
|
|
397
398
|
|
|
399
|
+
it('Should register the Apple ID token handler when configured explicitly', async () => {
|
|
400
|
+
manager = new Manager({
|
|
401
|
+
stateProvider: new State.Local.Provider(new State.Local.IndexedDbStore(`manager-apple-idtoken-${Date.now()}`)),
|
|
402
|
+
networks: [
|
|
403
|
+
{
|
|
404
|
+
name: 'Test Network',
|
|
405
|
+
type: Network.NetworkType.MAINNET,
|
|
406
|
+
rpcUrl: LOCAL_RPC_URL,
|
|
407
|
+
chainId: Network.ChainId.ARBITRUM,
|
|
408
|
+
blockExplorer: { url: 'https://arbiscan.io' },
|
|
409
|
+
nativeCurrency: {
|
|
410
|
+
name: 'Ether',
|
|
411
|
+
symbol: 'ETH',
|
|
412
|
+
decimals: 18,
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
relayers: [],
|
|
417
|
+
authCommitmentsDb,
|
|
418
|
+
authKeysDb,
|
|
419
|
+
identity: {
|
|
420
|
+
url: 'https://dev-identity.sequence-dev.app',
|
|
421
|
+
fetch: window.fetch,
|
|
422
|
+
apple: {
|
|
423
|
+
enabled: true,
|
|
424
|
+
clientId: 'test-apple-client-id',
|
|
425
|
+
authMethod: 'id-token',
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
const handlers = (manager as any).shared.handlers
|
|
431
|
+
expect(handlers.has('login-apple-id-token')).toBe(false)
|
|
432
|
+
expect(handlers.has('login-apple')).toBe(true)
|
|
433
|
+
})
|
|
434
|
+
|
|
398
435
|
it('Should use auth databases when email authentication is enabled', async () => {
|
|
399
436
|
manager = new Manager({
|
|
400
437
|
stateProvider: new State.Local.Provider(new State.Local.IndexedDbStore(`manager-email-${Date.now()}`)),
|
package/test/idtoken.test.ts
CHANGED
|
@@ -101,6 +101,22 @@ describe('IdTokenHandler', () => {
|
|
|
101
101
|
expect(handler.kind).toBe(Kinds.LoginGoogle)
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
+
it('Should normalize apple-id-token handlers to login-apple', () => {
|
|
105
|
+
const handler = new IdTokenHandler(
|
|
106
|
+
'apple-id-token',
|
|
107
|
+
'https://appleid.apple.com',
|
|
108
|
+
'test-apple-client-id',
|
|
109
|
+
mockNitroInstrument,
|
|
110
|
+
mockSignatures,
|
|
111
|
+
mockAuthKeys,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
expect(handler.signupKind).toBe('apple-id-token')
|
|
115
|
+
expect(handler.issuer).toBe('https://appleid.apple.com')
|
|
116
|
+
expect(handler.audience).toBe('test-apple-client-id')
|
|
117
|
+
expect(handler.kind).toBe(Kinds.LoginApple)
|
|
118
|
+
})
|
|
119
|
+
|
|
104
120
|
it('Should initialize without a registered UI callback', () => {
|
|
105
121
|
expect(idTokenHandler['onPromptIdToken']).toBeUndefined()
|
|
106
122
|
})
|
package/test/wallets.test.ts
CHANGED
|
@@ -71,6 +71,48 @@ describe('Wallets', () => {
|
|
|
71
71
|
expect(configuration.login[0]!.kind).toBe(Kinds.LoginGoogle)
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
+
it('Should create a new wallet using apple-id-token when Apple ID token auth is enabled', async () => {
|
|
75
|
+
manager = newManager({
|
|
76
|
+
identity: {
|
|
77
|
+
apple: {
|
|
78
|
+
enabled: true,
|
|
79
|
+
clientId: 'test-apple-client-id',
|
|
80
|
+
authMethod: 'id-token',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const handler = (manager as any).shared.handlers.get(Kinds.LoginApple) as IdTokenHandler
|
|
86
|
+
const loginMnemonic = Mnemonic.random(Mnemonic.english)
|
|
87
|
+
const loginSigner = MnemonicHandler.toSigner(loginMnemonic)
|
|
88
|
+
if (!loginSigner) {
|
|
89
|
+
throw new Error('Failed to create login signer for test')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const completeAuthSpy = vi
|
|
93
|
+
.spyOn(handler, 'completeAuth')
|
|
94
|
+
.mockResolvedValue([loginSigner as unknown as IdentitySigner, { email: 'apple-user@example.com' }])
|
|
95
|
+
|
|
96
|
+
const wallet = await manager.wallets.signUp({
|
|
97
|
+
kind: 'apple-id-token',
|
|
98
|
+
idToken: 'eyJhbGciOiJub25lIn0.eyJleHAiOjQxMDI0NDQ4MDB9.',
|
|
99
|
+
noGuard: true,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
expect(wallet).toBeDefined()
|
|
103
|
+
expect(completeAuthSpy).toHaveBeenCalledWith('eyJhbGciOiJub25lIn0.eyJleHAiOjQxMDI0NDQ4MDB9.')
|
|
104
|
+
await expect(manager.wallets.has(wallet!)).resolves.toBeTruthy()
|
|
105
|
+
|
|
106
|
+
const walletEntry = await manager.wallets.get(wallet!)
|
|
107
|
+
expect(walletEntry).toBeDefined()
|
|
108
|
+
expect(walletEntry!.loginType).toBe(Kinds.LoginApple)
|
|
109
|
+
expect(walletEntry!.loginEmail).toBe('apple-user@example.com')
|
|
110
|
+
|
|
111
|
+
const configuration = await manager.wallets.getConfiguration(wallet!)
|
|
112
|
+
expect(configuration.login).toHaveLength(1)
|
|
113
|
+
expect(configuration.login[0]!.kind).toBe(Kinds.LoginApple)
|
|
114
|
+
})
|
|
115
|
+
|
|
74
116
|
it('Should register and unregister Google ID token UI callbacks through the manager', async () => {
|
|
75
117
|
manager = newManager({
|
|
76
118
|
identity: {
|
|
@@ -118,7 +160,7 @@ describe('Wallets', () => {
|
|
|
118
160
|
})
|
|
119
161
|
|
|
120
162
|
expect(url).toBe('https://accounts.google.com/o/oauth2/v2/auth?state=test-state')
|
|
121
|
-
expect(commitAuthSpy).toHaveBeenCalledWith('/auth/return',
|
|
163
|
+
expect(commitAuthSpy).toHaveBeenCalledWith('/auth/return', { type: 'auth' })
|
|
122
164
|
})
|
|
123
165
|
|
|
124
166
|
it('Should reject google-id-token signup when Google is configured for redirect auth', async () => {
|
|
@@ -140,6 +182,25 @@ describe('Wallets', () => {
|
|
|
140
182
|
).rejects.toThrow('handler-does-not-support-id-token')
|
|
141
183
|
})
|
|
142
184
|
|
|
185
|
+
it('Should reject apple-id-token signup when Apple is configured for redirect auth', async () => {
|
|
186
|
+
manager = newManager({
|
|
187
|
+
identity: {
|
|
188
|
+
apple: {
|
|
189
|
+
enabled: true,
|
|
190
|
+
clientId: 'test-apple-client-id',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
await expect(
|
|
196
|
+
manager.wallets.signUp({
|
|
197
|
+
kind: 'apple-id-token',
|
|
198
|
+
idToken: 'eyJhbGciOiJub25lIn0.eyJleHAiOjQxMDI0NDQ4MDB9.',
|
|
199
|
+
noGuard: true,
|
|
200
|
+
}),
|
|
201
|
+
).rejects.toThrow('handler-does-not-support-id-token')
|
|
202
|
+
})
|
|
203
|
+
|
|
143
204
|
it('Should reject custom ID token signup when the provider uses redirect auth', async () => {
|
|
144
205
|
manager = newManager({
|
|
145
206
|
identity: {
|