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.
Files changed (149) hide show
  1. package/README.md +2 -1
  2. package/dist/_cjs/abi/GuardianRecoveryModule.js +767 -0
  3. package/dist/_cjs/abi/GuardianRecoveryModule.js.map +1 -0
  4. package/dist/_cjs/abi/OidcKeyRegistry.js +492 -0
  5. package/dist/_cjs/abi/OidcKeyRegistry.js.map +1 -0
  6. package/dist/_cjs/abi/OidcRecoveryValidator.js +528 -0
  7. package/dist/_cjs/abi/OidcRecoveryValidator.js.map +1 -0
  8. package/dist/_cjs/abi/WebAuthModule.js +301 -0
  9. package/dist/_cjs/abi/WebAuthModule.js.map +1 -0
  10. package/dist/_cjs/abi/index.js +9 -1
  11. package/dist/_cjs/abi/index.js.map +1 -1
  12. package/dist/_cjs/client/oidc/account.js +43 -0
  13. package/dist/_cjs/client/oidc/account.js.map +1 -0
  14. package/dist/_cjs/client/oidc/actions/addNewPasskeyViaOidc.js +28 -0
  15. package/dist/_cjs/client/oidc/actions/addNewPasskeyViaOidc.js.map +1 -0
  16. package/dist/_cjs/client/oidc/actions/index.js +12 -0
  17. package/dist/_cjs/client/oidc/actions/index.js.map +1 -0
  18. package/dist/_cjs/client/oidc/client.js +46 -0
  19. package/dist/_cjs/client/oidc/client.js.map +1 -0
  20. package/dist/_cjs/client/oidc/decorators/actions.js +3 -0
  21. package/dist/_cjs/client/oidc/decorators/actions.js.map +1 -0
  22. package/dist/_cjs/client/oidc/index.js +20 -0
  23. package/dist/_cjs/client/oidc/index.js.map +1 -0
  24. package/dist/_cjs/client/oidc/serialize.js +3 -0
  25. package/dist/_cjs/client/oidc/serialize.js.map +1 -0
  26. package/dist/_cjs/client/passkey/actions/account.js +5 -1
  27. package/dist/_cjs/client/passkey/actions/account.js.map +1 -1
  28. package/dist/_cjs/client/passkey/decorators/passkey.js +12 -0
  29. package/dist/_cjs/client/passkey/decorators/passkey.js.map +1 -1
  30. package/dist/_cjs/client/recovery/actions/oidc.js +55 -0
  31. package/dist/_cjs/client/recovery/actions/oidc.js.map +1 -0
  32. package/dist/_cjs/client/session/index.js +19 -0
  33. package/dist/_cjs/client/session/index.js.map +1 -0
  34. package/dist/_cjs/client-auth-server/Signer.js +4 -2
  35. package/dist/_cjs/client-auth-server/Signer.js.map +1 -1
  36. package/dist/_cjs/client-auth-server/WalletProvider.js +3 -2
  37. package/dist/_cjs/client-auth-server/WalletProvider.js.map +1 -1
  38. package/dist/_cjs/communicator/PopupCommunicator.js +30 -5
  39. package/dist/_cjs/communicator/PopupCommunicator.js.map +1 -1
  40. package/dist/_cjs/connector/index.js +1 -0
  41. package/dist/_cjs/connector/index.js.map +1 -1
  42. package/dist/_esm/abi/GuardianRecoveryModule.js +764 -0
  43. package/dist/_esm/abi/GuardianRecoveryModule.js.map +1 -0
  44. package/dist/_esm/abi/OidcKeyRegistry.js +489 -0
  45. package/dist/_esm/abi/OidcKeyRegistry.js.map +1 -0
  46. package/dist/_esm/abi/OidcRecoveryValidator.js +525 -0
  47. package/dist/_esm/abi/OidcRecoveryValidator.js.map +1 -0
  48. package/dist/_esm/abi/WebAuthModule.js +298 -0
  49. package/dist/_esm/abi/WebAuthModule.js.map +1 -0
  50. package/dist/_esm/abi/index.js +4 -0
  51. package/dist/_esm/abi/index.js.map +1 -1
  52. package/dist/_esm/client/oidc/account.js +40 -0
  53. package/dist/_esm/client/oidc/account.js.map +1 -0
  54. package/dist/_esm/client/oidc/actions/addNewPasskeyViaOidc.js +26 -0
  55. package/dist/_esm/client/oidc/actions/addNewPasskeyViaOidc.js.map +1 -0
  56. package/dist/_esm/client/oidc/actions/index.js +9 -0
  57. package/dist/_esm/client/oidc/actions/index.js.map +1 -0
  58. package/dist/_esm/client/oidc/client.js +41 -0
  59. package/dist/_esm/client/oidc/client.js.map +1 -0
  60. package/dist/_esm/client/oidc/decorators/actions.js +2 -0
  61. package/dist/_esm/client/oidc/decorators/actions.js.map +1 -0
  62. package/dist/_esm/client/oidc/index.js +4 -0
  63. package/dist/_esm/client/oidc/index.js.map +1 -0
  64. package/dist/_esm/client/oidc/serialize.js +2 -0
  65. package/dist/_esm/client/oidc/serialize.js.map +1 -0
  66. package/dist/_esm/client/passkey/actions/account.js +5 -1
  67. package/dist/_esm/client/passkey/actions/account.js.map +1 -1
  68. package/dist/_esm/client/passkey/decorators/passkey.js +12 -0
  69. package/dist/_esm/client/passkey/decorators/passkey.js.map +1 -1
  70. package/dist/_esm/client/recovery/actions/oidc.js +52 -0
  71. package/dist/_esm/client/recovery/actions/oidc.js.map +1 -0
  72. package/dist/_esm/client/session/index.js +3 -0
  73. package/dist/_esm/client/session/index.js.map +1 -0
  74. package/dist/_esm/client-auth-server/Signer.js +4 -2
  75. package/dist/_esm/client-auth-server/Signer.js.map +1 -1
  76. package/dist/_esm/client-auth-server/WalletProvider.js +3 -2
  77. package/dist/_esm/client-auth-server/WalletProvider.js.map +1 -1
  78. package/dist/_esm/communicator/PopupCommunicator.js +30 -5
  79. package/dist/_esm/communicator/PopupCommunicator.js.map +1 -1
  80. package/dist/_esm/connector/index.js +1 -0
  81. package/dist/_esm/connector/index.js.map +1 -1
  82. package/dist/_types/abi/GuardianRecoveryModule.d.ts +590 -0
  83. package/dist/_types/abi/GuardianRecoveryModule.d.ts.map +1 -0
  84. package/dist/_types/abi/OidcKeyRegistry.d.ts +375 -0
  85. package/dist/_types/abi/OidcKeyRegistry.d.ts.map +1 -0
  86. package/dist/_types/abi/OidcRecoveryValidator.d.ts +404 -0
  87. package/dist/_types/abi/OidcRecoveryValidator.d.ts.map +1 -0
  88. package/dist/_types/abi/WebAuthModule.d.ts +228 -0
  89. package/dist/_types/abi/WebAuthModule.d.ts.map +1 -0
  90. package/dist/_types/abi/index.d.ts +4 -0
  91. package/dist/_types/abi/index.d.ts.map +1 -1
  92. package/dist/_types/client/oidc/account.d.ts +13 -0
  93. package/dist/_types/client/oidc/account.d.ts.map +1 -0
  94. package/dist/_types/client/oidc/actions/addNewPasskeyViaOidc.d.ts +12 -0
  95. package/dist/_types/client/oidc/actions/addNewPasskeyViaOidc.d.ts.map +1 -0
  96. package/dist/_types/client/oidc/actions/index.d.ts +5 -0
  97. package/dist/_types/client/oidc/actions/index.d.ts.map +1 -0
  98. package/dist/_types/client/oidc/client.d.ts +24 -0
  99. package/dist/_types/client/oidc/client.d.ts.map +1 -0
  100. package/dist/_types/client/oidc/decorators/actions.d.ts +5 -0
  101. package/dist/_types/client/oidc/decorators/actions.d.ts.map +1 -0
  102. package/dist/_types/client/oidc/index.d.ts +4 -0
  103. package/dist/_types/client/oidc/index.d.ts.map +1 -0
  104. package/dist/_types/client/oidc/serialize.d.ts +10 -0
  105. package/dist/_types/client/oidc/serialize.d.ts.map +1 -0
  106. package/dist/_types/client/passkey/actions/account.d.ts +1 -0
  107. package/dist/_types/client/passkey/actions/account.d.ts.map +1 -1
  108. package/dist/_types/client/passkey/client.d.ts +2 -0
  109. package/dist/_types/client/passkey/client.d.ts.map +1 -1
  110. package/dist/_types/client/passkey/decorators/passkey.d.ts +4 -1
  111. package/dist/_types/client/passkey/decorators/passkey.d.ts.map +1 -1
  112. package/dist/_types/client/recovery/actions/oidc.d.ts +24 -0
  113. package/dist/_types/client/recovery/actions/oidc.d.ts.map +1 -0
  114. package/dist/_types/client/session/index.d.ts +3 -0
  115. package/dist/_types/client/session/index.d.ts.map +1 -0
  116. package/dist/_types/client-auth-server/Signer.d.ts +3 -1
  117. package/dist/_types/client-auth-server/Signer.d.ts.map +1 -1
  118. package/dist/_types/client-auth-server/WalletProvider.d.ts +5 -1
  119. package/dist/_types/client-auth-server/WalletProvider.d.ts.map +1 -1
  120. package/dist/_types/communicator/PopupCommunicator.d.ts +13 -1
  121. package/dist/_types/communicator/PopupCommunicator.d.ts.map +1 -1
  122. package/dist/_types/connector/index.d.ts +2 -0
  123. package/dist/_types/connector/index.d.ts.map +1 -1
  124. package/dist/_types/utils/storage.d.ts +1 -1
  125. package/dist/_types/utils/storage.d.ts.map +1 -1
  126. package/package.json +8 -2
  127. package/project.json +3 -0
  128. package/src/abi/GuardianRecoveryModule.ts +763 -0
  129. package/src/abi/OidcKeyRegistry.ts +488 -0
  130. package/src/abi/OidcRecoveryValidator.ts +524 -0
  131. package/src/abi/WebAuthModule.ts +297 -0
  132. package/src/abi/index.ts +4 -0
  133. package/src/client/oidc/account.ts +65 -0
  134. package/src/client/oidc/actions/addNewPasskeyViaOidc.ts +54 -0
  135. package/src/client/oidc/actions/index.ts +16 -0
  136. package/src/client/oidc/client.ts +122 -0
  137. package/src/client/oidc/decorators/actions.ts +5 -0
  138. package/src/client/oidc/index.ts +3 -0
  139. package/src/client/oidc/serialize.ts +10 -0
  140. package/src/client/passkey/actions/account.ts +7 -1
  141. package/src/client/passkey/client.ts +2 -0
  142. package/src/client/passkey/decorators/passkey.ts +20 -1
  143. package/src/client/recovery/actions/oidc.ts +103 -0
  144. package/src/client/session/index.ts +2 -0
  145. package/src/client-auth-server/Signer.ts +6 -3
  146. package/src/client-auth-server/WalletProvider.ts +7 -2
  147. package/src/communicator/PopupCommunicator.ts +24 -5
  148. package/src/connector/index.ts +3 -0
  149. 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
+ }
@@ -0,0 +1,5 @@
1
+ import { addNewPasskeyViaOidc, type AddNewPasskeyViaOidcArgs } from "../actions/addNewPasskeyViaOidc.js";
2
+
3
+ export type ZksyncSsoOidcActions = {
4
+ addNewPasskeyViaOidc: (args: Omit<AddNewPasskeyViaOidcArgs, "contracts">) => ReturnType<typeof addNewPasskeyViaOidc>;
5
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./account.js";
2
+ export * from "./client.js";
3
+ export * from "./serialize.js";
@@ -0,0 +1,10 @@
1
+ import type { Hex } from "viem";
2
+
3
+ export type OidcData = {
4
+ oidcDigest: Hex;
5
+ iss: string;
6
+ readyToRecover: boolean;
7
+ pendingPasskeyHash: Hex;
8
+ recoverNonce: bigint;
9
+ addedOn: bigint;
10
+ };
@@ -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
  }