zksync-sso 0.3.2 → 0.4.0-beta.0
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 +2 -1
- package/dist/_cjs/abi/GuardianRecoveryModule.js +767 -0
- package/dist/_cjs/abi/GuardianRecoveryModule.js.map +1 -0
- package/dist/_cjs/abi/OidcKeyRegistry.js +492 -0
- package/dist/_cjs/abi/OidcKeyRegistry.js.map +1 -0
- package/dist/_cjs/abi/OidcRecoveryValidator.js +528 -0
- package/dist/_cjs/abi/OidcRecoveryValidator.js.map +1 -0
- package/dist/_cjs/abi/WebAuthModule.js +301 -0
- package/dist/_cjs/abi/WebAuthModule.js.map +1 -0
- package/dist/_cjs/abi/index.js +9 -1
- package/dist/_cjs/abi/index.js.map +1 -1
- package/dist/_cjs/client/oidc/account.js +43 -0
- package/dist/_cjs/client/oidc/account.js.map +1 -0
- package/dist/_cjs/client/oidc/actions/addNewPasskeyViaOidc.js +28 -0
- package/dist/_cjs/client/oidc/actions/addNewPasskeyViaOidc.js.map +1 -0
- package/dist/_cjs/client/oidc/actions/index.js +12 -0
- package/dist/_cjs/client/oidc/actions/index.js.map +1 -0
- package/dist/_cjs/client/oidc/client.js +46 -0
- package/dist/_cjs/client/oidc/client.js.map +1 -0
- package/dist/_cjs/client/oidc/decorators/actions.js +3 -0
- package/dist/_cjs/client/oidc/decorators/actions.js.map +1 -0
- package/dist/_cjs/client/oidc/index.js +20 -0
- package/dist/_cjs/client/oidc/index.js.map +1 -0
- package/dist/_cjs/client/oidc/serialize.js +3 -0
- package/dist/_cjs/client/oidc/serialize.js.map +1 -0
- package/dist/_cjs/client/passkey/actions/account.js +5 -1
- package/dist/_cjs/client/passkey/actions/account.js.map +1 -1
- package/dist/_cjs/client/passkey/decorators/passkey.js +12 -0
- package/dist/_cjs/client/passkey/decorators/passkey.js.map +1 -1
- package/dist/_cjs/client/recovery/actions/oidc.js +55 -0
- package/dist/_cjs/client/recovery/actions/oidc.js.map +1 -0
- package/dist/_cjs/client/session/index.js +19 -0
- package/dist/_cjs/client/session/index.js.map +1 -0
- package/dist/_cjs/client-auth-server/Signer.js +4 -2
- package/dist/_cjs/client-auth-server/Signer.js.map +1 -1
- package/dist/_cjs/client-auth-server/WalletProvider.js +3 -2
- package/dist/_cjs/client-auth-server/WalletProvider.js.map +1 -1
- package/dist/_cjs/communicator/PopupCommunicator.js +30 -5
- package/dist/_cjs/communicator/PopupCommunicator.js.map +1 -1
- package/dist/_cjs/connector/index.js +1 -0
- package/dist/_cjs/connector/index.js.map +1 -1
- package/dist/_esm/abi/GuardianRecoveryModule.js +764 -0
- package/dist/_esm/abi/GuardianRecoveryModule.js.map +1 -0
- package/dist/_esm/abi/OidcKeyRegistry.js +489 -0
- package/dist/_esm/abi/OidcKeyRegistry.js.map +1 -0
- package/dist/_esm/abi/OidcRecoveryValidator.js +525 -0
- package/dist/_esm/abi/OidcRecoveryValidator.js.map +1 -0
- package/dist/_esm/abi/WebAuthModule.js +298 -0
- package/dist/_esm/abi/WebAuthModule.js.map +1 -0
- package/dist/_esm/abi/index.js +4 -0
- package/dist/_esm/abi/index.js.map +1 -1
- package/dist/_esm/client/oidc/account.js +40 -0
- package/dist/_esm/client/oidc/account.js.map +1 -0
- package/dist/_esm/client/oidc/actions/addNewPasskeyViaOidc.js +26 -0
- package/dist/_esm/client/oidc/actions/addNewPasskeyViaOidc.js.map +1 -0
- package/dist/_esm/client/oidc/actions/index.js +9 -0
- package/dist/_esm/client/oidc/actions/index.js.map +1 -0
- package/dist/_esm/client/oidc/client.js +41 -0
- package/dist/_esm/client/oidc/client.js.map +1 -0
- package/dist/_esm/client/oidc/decorators/actions.js +2 -0
- package/dist/_esm/client/oidc/decorators/actions.js.map +1 -0
- package/dist/_esm/client/oidc/index.js +4 -0
- package/dist/_esm/client/oidc/index.js.map +1 -0
- package/dist/_esm/client/oidc/serialize.js +2 -0
- package/dist/_esm/client/oidc/serialize.js.map +1 -0
- package/dist/_esm/client/passkey/actions/account.js +5 -1
- package/dist/_esm/client/passkey/actions/account.js.map +1 -1
- package/dist/_esm/client/passkey/decorators/passkey.js +12 -0
- package/dist/_esm/client/passkey/decorators/passkey.js.map +1 -1
- package/dist/_esm/client/recovery/actions/oidc.js +52 -0
- package/dist/_esm/client/recovery/actions/oidc.js.map +1 -0
- package/dist/_esm/client/session/index.js +3 -0
- package/dist/_esm/client/session/index.js.map +1 -0
- package/dist/_esm/client-auth-server/Signer.js +4 -2
- package/dist/_esm/client-auth-server/Signer.js.map +1 -1
- package/dist/_esm/client-auth-server/WalletProvider.js +3 -2
- package/dist/_esm/client-auth-server/WalletProvider.js.map +1 -1
- package/dist/_esm/communicator/PopupCommunicator.js +30 -5
- package/dist/_esm/communicator/PopupCommunicator.js.map +1 -1
- package/dist/_esm/connector/index.js +1 -0
- package/dist/_esm/connector/index.js.map +1 -1
- package/dist/_types/abi/GuardianRecoveryModule.d.ts +590 -0
- package/dist/_types/abi/GuardianRecoveryModule.d.ts.map +1 -0
- package/dist/_types/abi/OidcKeyRegistry.d.ts +375 -0
- package/dist/_types/abi/OidcKeyRegistry.d.ts.map +1 -0
- package/dist/_types/abi/OidcRecoveryValidator.d.ts +404 -0
- package/dist/_types/abi/OidcRecoveryValidator.d.ts.map +1 -0
- package/dist/_types/abi/WebAuthModule.d.ts +228 -0
- package/dist/_types/abi/WebAuthModule.d.ts.map +1 -0
- package/dist/_types/abi/index.d.ts +4 -0
- package/dist/_types/abi/index.d.ts.map +1 -1
- package/dist/_types/client/oidc/account.d.ts +13 -0
- package/dist/_types/client/oidc/account.d.ts.map +1 -0
- package/dist/_types/client/oidc/actions/addNewPasskeyViaOidc.d.ts +12 -0
- package/dist/_types/client/oidc/actions/addNewPasskeyViaOidc.d.ts.map +1 -0
- package/dist/_types/client/oidc/actions/index.d.ts +5 -0
- package/dist/_types/client/oidc/actions/index.d.ts.map +1 -0
- package/dist/_types/client/oidc/client.d.ts +24 -0
- package/dist/_types/client/oidc/client.d.ts.map +1 -0
- package/dist/_types/client/oidc/decorators/actions.d.ts +5 -0
- package/dist/_types/client/oidc/decorators/actions.d.ts.map +1 -0
- package/dist/_types/client/oidc/index.d.ts +4 -0
- package/dist/_types/client/oidc/index.d.ts.map +1 -0
- package/dist/_types/client/oidc/serialize.d.ts +10 -0
- package/dist/_types/client/oidc/serialize.d.ts.map +1 -0
- package/dist/_types/client/passkey/actions/account.d.ts +1 -0
- package/dist/_types/client/passkey/actions/account.d.ts.map +1 -1
- package/dist/_types/client/passkey/client.d.ts +2 -0
- package/dist/_types/client/passkey/client.d.ts.map +1 -1
- package/dist/_types/client/passkey/decorators/passkey.d.ts +4 -1
- package/dist/_types/client/passkey/decorators/passkey.d.ts.map +1 -1
- package/dist/_types/client/recovery/actions/oidc.d.ts +24 -0
- package/dist/_types/client/recovery/actions/oidc.d.ts.map +1 -0
- package/dist/_types/client/session/index.d.ts +3 -0
- package/dist/_types/client/session/index.d.ts.map +1 -0
- package/dist/_types/client-auth-server/Signer.d.ts +3 -1
- package/dist/_types/client-auth-server/Signer.d.ts.map +1 -1
- package/dist/_types/client-auth-server/WalletProvider.d.ts +5 -1
- package/dist/_types/client-auth-server/WalletProvider.d.ts.map +1 -1
- package/dist/_types/communicator/PopupCommunicator.d.ts +13 -1
- package/dist/_types/communicator/PopupCommunicator.d.ts.map +1 -1
- package/dist/_types/connector/index.d.ts +2 -0
- package/dist/_types/connector/index.d.ts.map +1 -1
- package/dist/_types/utils/storage.d.ts +1 -1
- package/dist/_types/utils/storage.d.ts.map +1 -1
- package/package.json +8 -2
- package/project.json +3 -0
- package/src/abi/GuardianRecoveryModule.ts +763 -0
- package/src/abi/OidcKeyRegistry.ts +488 -0
- package/src/abi/OidcRecoveryValidator.ts +524 -0
- package/src/abi/WebAuthModule.ts +297 -0
- package/src/abi/index.ts +4 -0
- package/src/client/oidc/account.ts +65 -0
- package/src/client/oidc/actions/addNewPasskeyViaOidc.ts +54 -0
- package/src/client/oidc/actions/index.ts +16 -0
- package/src/client/oidc/client.ts +122 -0
- package/src/client/oidc/decorators/actions.ts +5 -0
- package/src/client/oidc/index.ts +3 -0
- package/src/client/oidc/serialize.ts +10 -0
- package/src/client/passkey/actions/account.ts +7 -1
- package/src/client/passkey/client.ts +2 -0
- package/src/client/passkey/decorators/passkey.ts +20 -1
- package/src/client/recovery/actions/oidc.ts +103 -0
- package/src/client/session/index.ts +2 -0
- package/src/client-auth-server/Signer.ts +6 -3
- package/src/client-auth-server/WalletProvider.ts +7 -2
- package/src/communicator/PopupCommunicator.ts +24 -5
- package/src/connector/index.ts +3 -0
- package/src/utils/storage.ts +1 -1
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
export const WebAuthModuleAbi = [
|
|
2
|
+
{
|
|
3
|
+
anonymous: false,
|
|
4
|
+
inputs: [
|
|
5
|
+
{
|
|
6
|
+
indexed: true,
|
|
7
|
+
internalType: "address",
|
|
8
|
+
name: "keyOwner",
|
|
9
|
+
type: "address",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
indexed: false,
|
|
13
|
+
internalType: "string",
|
|
14
|
+
name: "originDomain",
|
|
15
|
+
type: "string",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
name: "PasskeyCreated",
|
|
19
|
+
type: "event",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
inputs: [
|
|
23
|
+
{
|
|
24
|
+
internalType: "bytes",
|
|
25
|
+
name: "key",
|
|
26
|
+
type: "bytes",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
name: "addValidationKey",
|
|
30
|
+
outputs: [
|
|
31
|
+
{
|
|
32
|
+
internalType: "bool",
|
|
33
|
+
name: "",
|
|
34
|
+
type: "bool",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
stateMutability: "nonpayable",
|
|
38
|
+
type: "function",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
inputs: [
|
|
42
|
+
{
|
|
43
|
+
internalType: "string",
|
|
44
|
+
name: "originDomain",
|
|
45
|
+
type: "string",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
internalType: "address",
|
|
49
|
+
name: "accountAddress",
|
|
50
|
+
type: "address",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
name: "lowerKeyHalf",
|
|
54
|
+
outputs: [
|
|
55
|
+
{
|
|
56
|
+
internalType: "bytes32",
|
|
57
|
+
name: "",
|
|
58
|
+
type: "bytes32",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
stateMutability: "view",
|
|
62
|
+
type: "function",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
inputs: [
|
|
66
|
+
{
|
|
67
|
+
internalType: "bytes",
|
|
68
|
+
name: "data",
|
|
69
|
+
type: "bytes",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
name: "onInstall",
|
|
73
|
+
outputs: [],
|
|
74
|
+
stateMutability: "nonpayable",
|
|
75
|
+
type: "function",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
inputs: [
|
|
79
|
+
{
|
|
80
|
+
internalType: "bytes",
|
|
81
|
+
name: "data",
|
|
82
|
+
type: "bytes",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
name: "onUninstall",
|
|
86
|
+
outputs: [],
|
|
87
|
+
stateMutability: "nonpayable",
|
|
88
|
+
type: "function",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
inputs: [
|
|
92
|
+
{
|
|
93
|
+
internalType: "bytes32",
|
|
94
|
+
name: "message",
|
|
95
|
+
type: "bytes32",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
internalType: "bytes32[2]",
|
|
99
|
+
name: "rs",
|
|
100
|
+
type: "bytes32[2]",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
internalType: "bytes32[2]",
|
|
104
|
+
name: "pubKey",
|
|
105
|
+
type: "bytes32[2]",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
name: "rawVerify",
|
|
109
|
+
outputs: [
|
|
110
|
+
{
|
|
111
|
+
internalType: "bool",
|
|
112
|
+
name: "valid",
|
|
113
|
+
type: "bool",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
stateMutability: "view",
|
|
117
|
+
type: "function",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
inputs: [
|
|
121
|
+
{
|
|
122
|
+
internalType: "bytes4",
|
|
123
|
+
name: "interfaceId",
|
|
124
|
+
type: "bytes4",
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
name: "supportsInterface",
|
|
128
|
+
outputs: [
|
|
129
|
+
{
|
|
130
|
+
internalType: "bool",
|
|
131
|
+
name: "",
|
|
132
|
+
type: "bool",
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
stateMutability: "pure",
|
|
136
|
+
type: "function",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
inputs: [
|
|
140
|
+
{
|
|
141
|
+
internalType: "string",
|
|
142
|
+
name: "originDomain",
|
|
143
|
+
type: "string",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
internalType: "address",
|
|
147
|
+
name: "accountAddress",
|
|
148
|
+
type: "address",
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
name: "upperKeyHalf",
|
|
152
|
+
outputs: [
|
|
153
|
+
{
|
|
154
|
+
internalType: "bytes32",
|
|
155
|
+
name: "",
|
|
156
|
+
type: "bytes32",
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
stateMutability: "view",
|
|
160
|
+
type: "function",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
inputs: [
|
|
164
|
+
{
|
|
165
|
+
internalType: "bytes32",
|
|
166
|
+
name: "signedHash",
|
|
167
|
+
type: "bytes32",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
internalType: "bytes",
|
|
171
|
+
name: "signature",
|
|
172
|
+
type: "bytes",
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
name: "validateSignature",
|
|
176
|
+
outputs: [
|
|
177
|
+
{
|
|
178
|
+
internalType: "bool",
|
|
179
|
+
name: "",
|
|
180
|
+
type: "bool",
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
stateMutability: "view",
|
|
184
|
+
type: "function",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
inputs: [
|
|
188
|
+
{
|
|
189
|
+
internalType: "bytes32",
|
|
190
|
+
name: "signedHash",
|
|
191
|
+
type: "bytes32",
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
internalType: "bytes",
|
|
195
|
+
name: "signature",
|
|
196
|
+
type: "bytes",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
components: [
|
|
200
|
+
{
|
|
201
|
+
internalType: "uint256",
|
|
202
|
+
name: "txType",
|
|
203
|
+
type: "uint256",
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
internalType: "uint256",
|
|
207
|
+
name: "from",
|
|
208
|
+
type: "uint256",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
internalType: "uint256",
|
|
212
|
+
name: "to",
|
|
213
|
+
type: "uint256",
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
internalType: "uint256",
|
|
217
|
+
name: "gasLimit",
|
|
218
|
+
type: "uint256",
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
internalType: "uint256",
|
|
222
|
+
name: "gasPerPubdataByteLimit",
|
|
223
|
+
type: "uint256",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
internalType: "uint256",
|
|
227
|
+
name: "maxFeePerGas",
|
|
228
|
+
type: "uint256",
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
internalType: "uint256",
|
|
232
|
+
name: "maxPriorityFeePerGas",
|
|
233
|
+
type: "uint256",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
internalType: "uint256",
|
|
237
|
+
name: "paymaster",
|
|
238
|
+
type: "uint256",
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
internalType: "uint256",
|
|
242
|
+
name: "nonce",
|
|
243
|
+
type: "uint256",
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
internalType: "uint256",
|
|
247
|
+
name: "value",
|
|
248
|
+
type: "uint256",
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
internalType: "uint256[4]",
|
|
252
|
+
name: "reserved",
|
|
253
|
+
type: "uint256[4]",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
internalType: "bytes",
|
|
257
|
+
name: "data",
|
|
258
|
+
type: "bytes",
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
internalType: "bytes",
|
|
262
|
+
name: "signature",
|
|
263
|
+
type: "bytes",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
internalType: "bytes32[]",
|
|
267
|
+
name: "factoryDeps",
|
|
268
|
+
type: "bytes32[]",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
internalType: "bytes",
|
|
272
|
+
name: "paymasterInput",
|
|
273
|
+
type: "bytes",
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
internalType: "bytes",
|
|
277
|
+
name: "reservedDynamic",
|
|
278
|
+
type: "bytes",
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
internalType: "struct Transaction",
|
|
282
|
+
name: "",
|
|
283
|
+
type: "tuple",
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
name: "validateTransaction",
|
|
287
|
+
outputs: [
|
|
288
|
+
{
|
|
289
|
+
internalType: "bool",
|
|
290
|
+
name: "",
|
|
291
|
+
type: "bool",
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
stateMutability: "view",
|
|
295
|
+
type: "function",
|
|
296
|
+
},
|
|
297
|
+
] as const;
|
package/src/abi/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { AAFactoryAbi } from "./AAFactory.js";
|
|
2
|
+
export { GuardianRecoveryModuleAbi } from "./GuardianRecoveryModule.js";
|
|
2
3
|
export { GuardianRecoveryValidatorAbi } from "./GuardianRecoveryValidator.js";
|
|
4
|
+
export { OidcKeyRegistryAbi } from "./OidcKeyRegistry.js";
|
|
5
|
+
export { OidcRecoveryValidatorAbi } from "./OidcRecoveryValidator.js";
|
|
3
6
|
export { SessionKeyValidatorAbi } from "./SessionKeyValidator.js";
|
|
4
7
|
export { SsoAccountAbi } from "./SsoAccount.js";
|
|
8
|
+
export { WebAuthModuleAbi } from "./WebAuthModule.js";
|
|
5
9
|
export { WebAuthValidatorAbi } from "./WebAuthValidator.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Address } from "abitype";
|
|
2
|
+
import {
|
|
3
|
+
type CustomSource,
|
|
4
|
+
type Hash,
|
|
5
|
+
hashTypedData,
|
|
6
|
+
type Hex,
|
|
7
|
+
type LocalAccount,
|
|
8
|
+
} from "viem";
|
|
9
|
+
import { toAccount } from "viem/accounts";
|
|
10
|
+
import { serializeTransaction, type ZksyncTransactionSerializableEIP712 } from "viem/zksync";
|
|
11
|
+
|
|
12
|
+
import { getEip712Domain } from "../utils/getEip712Domain.js";
|
|
13
|
+
|
|
14
|
+
export type ToOidcAccountParameters = {
|
|
15
|
+
address: Address;
|
|
16
|
+
signTransaction: (parameters: {
|
|
17
|
+
hash: Hash;
|
|
18
|
+
}) => Promise<Hex>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type OidcAccount = LocalAccount<"ssoOidcAccount"> & {
|
|
22
|
+
sign: NonNullable<CustomSource["sign"]>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function toOidcAccount(
|
|
26
|
+
parameters: ToOidcAccountParameters,
|
|
27
|
+
): OidcAccount {
|
|
28
|
+
const { address, signTransaction } = parameters;
|
|
29
|
+
|
|
30
|
+
const account = toAccount({
|
|
31
|
+
address,
|
|
32
|
+
async signTransaction(transaction) {
|
|
33
|
+
const signableTransaction = {
|
|
34
|
+
...transaction,
|
|
35
|
+
from: this.address!,
|
|
36
|
+
type: "eip712",
|
|
37
|
+
} as ZksyncTransactionSerializableEIP712;
|
|
38
|
+
|
|
39
|
+
const eip712DomainAndMessage = getEip712Domain(signableTransaction);
|
|
40
|
+
const digest = hashTypedData(eip712DomainAndMessage);
|
|
41
|
+
|
|
42
|
+
return serializeTransaction({
|
|
43
|
+
...signableTransaction,
|
|
44
|
+
customSignature: await signTransaction({
|
|
45
|
+
hash: digest,
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
async signMessage() {
|
|
50
|
+
throw new Error("Oidc account cannot sign messages");
|
|
51
|
+
},
|
|
52
|
+
async signTypedData(typedData) {
|
|
53
|
+
const digest = hashTypedData(typedData);
|
|
54
|
+
return signTransaction({
|
|
55
|
+
hash: digest,
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
...account,
|
|
62
|
+
source: "ssoOidcAccount",
|
|
63
|
+
type: "local",
|
|
64
|
+
} as OidcAccount;
|
|
65
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client, encodeFunctionData, type Hex,
|
|
6
|
+
type Prettify, type TransactionReceipt,
|
|
7
|
+
type Transport,
|
|
8
|
+
} from "viem";
|
|
9
|
+
import { waitForTransactionReceipt } from "viem/actions";
|
|
10
|
+
import { sendTransaction } from "viem/zksync";
|
|
11
|
+
|
|
12
|
+
import { WebAuthValidatorAbi } from "../../../abi/index.js";
|
|
13
|
+
|
|
14
|
+
export type AddNewPasskeyViaOidcArgs = {
|
|
15
|
+
credentialId: Hex;
|
|
16
|
+
passkeyPubKey: [Hex, Hex];
|
|
17
|
+
passkeyDomain: string;
|
|
18
|
+
contracts: {
|
|
19
|
+
recoveryOidc: Address; // oidc recovery module
|
|
20
|
+
passkey: Address;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export async function addNewPasskeyViaOidc<
|
|
25
|
+
transport extends Transport,
|
|
26
|
+
chain extends Chain,
|
|
27
|
+
account extends Account,
|
|
28
|
+
|
|
29
|
+
>(client: Client<transport, chain, account>, args: Prettify<AddNewPasskeyViaOidcArgs>): Promise<TransactionReceipt> {
|
|
30
|
+
const callData = encodeFunctionData({
|
|
31
|
+
abi: WebAuthValidatorAbi,
|
|
32
|
+
functionName: "addValidationKey",
|
|
33
|
+
args: [args.credentialId, args.passkeyPubKey, args.passkeyDomain],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const sendTransactionArgs = {
|
|
37
|
+
account: client.account,
|
|
38
|
+
to: args.contracts.passkey,
|
|
39
|
+
data: callData,
|
|
40
|
+
gas: 10_000_000n, // TODO: Remove when gas estimation is fixed
|
|
41
|
+
type: "eip712",
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
} as any;
|
|
44
|
+
|
|
45
|
+
const transactionHash = await sendTransaction(client, sendTransactionArgs);
|
|
46
|
+
|
|
47
|
+
const transactionReceipt = await waitForTransactionReceipt(client, { hash: transactionHash });
|
|
48
|
+
|
|
49
|
+
if (transactionReceipt.status !== "success") {
|
|
50
|
+
throw new Error("Add passkey via oidc reverted");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return transactionReceipt;
|
|
54
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Chain, Transport } from "viem";
|
|
2
|
+
|
|
3
|
+
import type { ClientWithOidcData } from "../client.js";
|
|
4
|
+
import type { ZksyncSsoOidcActions } from "../decorators/actions.js";
|
|
5
|
+
import { addNewPasskeyViaOidc, type AddNewPasskeyViaOidcArgs } from "./addNewPasskeyViaOidc.js";
|
|
6
|
+
|
|
7
|
+
export function zksyncSsoOidcActions<
|
|
8
|
+
transport extends Transport,
|
|
9
|
+
chain extends Chain,
|
|
10
|
+
>(client: ClientWithOidcData<transport, chain>): ZksyncSsoOidcActions {
|
|
11
|
+
return {
|
|
12
|
+
addNewPasskeyViaOidc: async (args: Omit<AddNewPasskeyViaOidcArgs, "contracts">) => {
|
|
13
|
+
return addNewPasskeyViaOidc(client, { ...args, contracts: client.contracts });
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
createClient,
|
|
7
|
+
encodeAbiParameters,
|
|
8
|
+
getAddress,
|
|
9
|
+
type Prettify,
|
|
10
|
+
publicActions,
|
|
11
|
+
type PublicRpcSchema,
|
|
12
|
+
type RpcSchema,
|
|
13
|
+
type Transport,
|
|
14
|
+
type WalletClientConfig,
|
|
15
|
+
type WalletRpcSchema,
|
|
16
|
+
} from "viem";
|
|
17
|
+
|
|
18
|
+
import { type ZksyncSsoWalletActions, zksyncSsoWalletActions } from "../recovery/decorators/wallet.js";
|
|
19
|
+
import { type OidcAccount, toOidcAccount } from "./account.js";
|
|
20
|
+
import { zksyncSsoOidcActions } from "./actions/index.js";
|
|
21
|
+
import type { ZksyncSsoOidcActions } from "./decorators/actions.js";
|
|
22
|
+
|
|
23
|
+
export const signOidcTransaction = (
|
|
24
|
+
recoveryValidatorAddress: Address,
|
|
25
|
+
) => {
|
|
26
|
+
return encodeAbiParameters(
|
|
27
|
+
[
|
|
28
|
+
{ type: "bytes", name: "signature" },
|
|
29
|
+
{ type: "address", name: "recoveryContract" },
|
|
30
|
+
{ type: "bytes[]", name: "validatorData" },
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
"0x",
|
|
34
|
+
recoveryValidatorAddress,
|
|
35
|
+
["0x"],
|
|
36
|
+
],
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface SsoClientConfig<
|
|
41
|
+
transport extends Transport = Transport,
|
|
42
|
+
chain extends Chain = Chain,
|
|
43
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
44
|
+
> extends Omit<WalletClientConfig<transport, chain, Account, rpcSchema>, "account"> {
|
|
45
|
+
chain: NonNullable<chain>;
|
|
46
|
+
address: Address;
|
|
47
|
+
contracts: OidcRequiredContracts;
|
|
48
|
+
key?: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type OidcRequiredContracts = {
|
|
53
|
+
passkey: Address; // Passkey
|
|
54
|
+
recovery: Address;
|
|
55
|
+
recoveryOidc: Address; // Oidc
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type ZKsyncSsoOidcData = {
|
|
59
|
+
contracts: OidcRequiredContracts;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type ZkSyncSsoClient<
|
|
63
|
+
transport extends Transport = Transport,
|
|
64
|
+
chain extends Chain = Chain,
|
|
65
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
66
|
+
> = Prettify<
|
|
67
|
+
Client<
|
|
68
|
+
transport,
|
|
69
|
+
chain,
|
|
70
|
+
OidcAccount,
|
|
71
|
+
rpcSchema extends RpcSchema
|
|
72
|
+
? [...PublicRpcSchema, ...WalletRpcSchema, ...rpcSchema]
|
|
73
|
+
: [...PublicRpcSchema, ...WalletRpcSchema],
|
|
74
|
+
ZksyncSsoWalletActions<chain, OidcAccount> & ZksyncSsoOidcActions
|
|
75
|
+
> & ZKsyncSsoOidcData
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
export type ClientWithOidcData<
|
|
79
|
+
transport extends Transport = Transport,
|
|
80
|
+
chain extends Chain = Chain,
|
|
81
|
+
account extends Account = Account,
|
|
82
|
+
> = Client<transport, chain, account> & ZKsyncSsoOidcData;
|
|
83
|
+
|
|
84
|
+
export function createZkSyncOidcClient<
|
|
85
|
+
transport extends Transport,
|
|
86
|
+
chain extends Chain,
|
|
87
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
88
|
+
>(givenParams: SsoClientConfig<transport, chain, rpcSchema>): ZkSyncSsoClient<
|
|
89
|
+
transport,
|
|
90
|
+
chain,
|
|
91
|
+
rpcSchema
|
|
92
|
+
> {
|
|
93
|
+
type WalletClientParameters = typeof givenParams;
|
|
94
|
+
const parameters: WalletClientParameters & {
|
|
95
|
+
key: NonNullable<WalletClientParameters["key"]>;
|
|
96
|
+
name: NonNullable<WalletClientParameters["name"]>;
|
|
97
|
+
} = {
|
|
98
|
+
...givenParams,
|
|
99
|
+
address: getAddress(givenParams.address),
|
|
100
|
+
key: givenParams.key || "zksync-sso-oidc-wallet",
|
|
101
|
+
name: givenParams.name || "ZKsync SSO OIDC Client",
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const account = toOidcAccount({
|
|
105
|
+
address: parameters.address,
|
|
106
|
+
signTransaction: async () => {
|
|
107
|
+
return signOidcTransaction(parameters.contracts.recoveryOidc);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return createClient<transport, chain, OidcAccount, rpcSchema>({
|
|
112
|
+
...parameters,
|
|
113
|
+
account,
|
|
114
|
+
type: "walletClient",
|
|
115
|
+
})
|
|
116
|
+
.extend(() => ({
|
|
117
|
+
contracts: parameters.contracts,
|
|
118
|
+
}))
|
|
119
|
+
.extend(publicActions)
|
|
120
|
+
.extend(zksyncSsoWalletActions)
|
|
121
|
+
.extend(zksyncSsoOidcActions);
|
|
122
|
+
}
|
|
@@ -52,6 +52,7 @@ export type DeployAccountArgs = {
|
|
|
52
52
|
passkey: Address;
|
|
53
53
|
session: Address;
|
|
54
54
|
recovery: Address;
|
|
55
|
+
recoveryOidc: Address;
|
|
55
56
|
};
|
|
56
57
|
initialSession?: SessionConfig;
|
|
57
58
|
onTransactionSent?: (hash: Hash) => void;
|
|
@@ -117,6 +118,11 @@ export const deployAccount = async <
|
|
|
117
118
|
parameters: "0x",
|
|
118
119
|
});
|
|
119
120
|
|
|
121
|
+
const encodedOidcRecoveryModuleData = encodeModuleData({
|
|
122
|
+
address: args.contracts.recoveryOidc,
|
|
123
|
+
parameters: "0x",
|
|
124
|
+
});
|
|
125
|
+
|
|
120
126
|
let deployProxyArgs = {
|
|
121
127
|
account: client.account!,
|
|
122
128
|
chain: client.chain!,
|
|
@@ -125,7 +131,7 @@ export const deployAccount = async <
|
|
|
125
131
|
functionName: "deployProxySsoAccount",
|
|
126
132
|
args: [
|
|
127
133
|
keccak256(toHex(accountId)),
|
|
128
|
-
[encodedPasskeyModuleData, encodedSessionKeyModuleData, encodedGuardianRecoveryModuleData],
|
|
134
|
+
[encodedPasskeyModuleData, encodedSessionKeyModuleData, encodedGuardianRecoveryModuleData, encodedOidcRecoveryModuleData],
|
|
129
135
|
[],
|
|
130
136
|
],
|
|
131
137
|
} as any;
|
|
@@ -62,9 +62,11 @@ export function createZksyncPasskeyClient<
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export type PasskeyRequiredContracts = {
|
|
65
|
+
oidcKeyRegistry: Address; // Oidc key registry
|
|
65
66
|
session: Address; // Session, spend limit, etc.
|
|
66
67
|
passkey: Address; // Validator for passkey signature
|
|
67
68
|
recovery: Address; // Validator for account recovery
|
|
69
|
+
recoveryOidc: Address; // Validator for account recovery with OIDC
|
|
68
70
|
accountFactory?: Address; // For account creation
|
|
69
71
|
};
|
|
70
72
|
type ZksyncSsoPasskeyData = {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { type Chain, type Transport } from "viem";
|
|
1
|
+
import { type Chain, type TransactionReceipt, type Transport } from "viem";
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
addOidcAccount,
|
|
5
|
+
type AddOidcAccountArgs,
|
|
6
|
+
type AddOidcAccountReturnType,
|
|
7
|
+
removeOidcAccount,
|
|
8
|
+
} from "../../recovery/actions/oidc.js";
|
|
3
9
|
import {
|
|
4
10
|
confirmGuardian, type ConfirmGuardianArgs, type ConfirmGuardianReturnType,
|
|
5
11
|
proposeGuardian, type ProposeGuardianArgs, type ProposeGuardianReturnType,
|
|
@@ -17,6 +23,8 @@ export type ZksyncSsoPasskeyActions = {
|
|
|
17
23
|
proposeGuardian: (args: Omit<ProposeGuardianArgs, "contracts">) => Promise<ProposeGuardianReturnType>;
|
|
18
24
|
confirmGuardian: (args: Omit<ConfirmGuardianArgs, "contracts">) => Promise<ConfirmGuardianReturnType>;
|
|
19
25
|
removeGuardian: (args: Omit<RemoveGuardianArgs, "contracts">) => Promise<RemoveGuardianReturnType>;
|
|
26
|
+
addOidcAccount: (args: Omit<AddOidcAccountArgs, "contracts">) => Promise<AddOidcAccountReturnType>;
|
|
27
|
+
removeOidcAccount: () => Promise<TransactionReceipt>;
|
|
20
28
|
};
|
|
21
29
|
|
|
22
30
|
export function zksyncSsoPasskeyActions<
|
|
@@ -54,5 +62,16 @@ export function zksyncSsoPasskeyActions<
|
|
|
54
62
|
contracts: client.contracts,
|
|
55
63
|
});
|
|
56
64
|
},
|
|
65
|
+
addOidcAccount: async (args: Omit<AddOidcAccountArgs, "contracts">) => {
|
|
66
|
+
return await addOidcAccount(client, {
|
|
67
|
+
...args,
|
|
68
|
+
contracts: client.contracts,
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
removeOidcAccount: async () => {
|
|
72
|
+
return await removeOidcAccount(client, {
|
|
73
|
+
contracts: client.contracts,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
57
76
|
};
|
|
58
77
|
}
|