@charterlabs/rhinestone-sdk 0.2.7-dev.2 → 0.2.7-dev.4

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 (130) hide show
  1. package/dist/src/accounts/error.d.ts +38 -3
  2. package/dist/src/accounts/error.d.ts.map +1 -1
  3. package/dist/src/accounts/error.js +55 -7
  4. package/dist/src/accounts/index.d.ts +28 -20
  5. package/dist/src/accounts/index.d.ts.map +1 -1
  6. package/dist/src/accounts/index.js +196 -21
  7. package/dist/src/accounts/index.test.js +2 -4
  8. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -1
  9. package/dist/src/accounts/json-rpc/providers.js +42 -4
  10. package/dist/src/accounts/kernel.d.ts +1 -1
  11. package/dist/src/accounts/kernel.d.ts.map +1 -1
  12. package/dist/src/accounts/kernel.js +29 -1
  13. package/dist/src/accounts/kernel.test.js +35 -8
  14. package/dist/src/accounts/nexus.d.ts +4 -3
  15. package/dist/src/accounts/nexus.d.ts.map +1 -1
  16. package/dist/src/accounts/nexus.js +82 -14
  17. package/dist/src/accounts/nexus.test.js +33 -6
  18. package/dist/src/accounts/safe.d.ts.map +1 -1
  19. package/dist/src/accounts/safe.js +85 -53
  20. package/dist/src/accounts/safe.test.js +33 -6
  21. package/dist/src/accounts/signing/common.d.ts +4 -4
  22. package/dist/src/accounts/signing/common.d.ts.map +1 -1
  23. package/dist/src/accounts/signing/common.js +21 -9
  24. package/dist/src/accounts/signing/message.d.ts +1 -1
  25. package/dist/src/accounts/signing/message.d.ts.map +1 -1
  26. package/dist/src/accounts/signing/message.js +6 -6
  27. package/dist/src/accounts/signing/passkeys.d.ts +8 -1
  28. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -1
  29. package/dist/src/accounts/signing/passkeys.js +35 -0
  30. package/dist/src/accounts/signing/passkeys.test.js +15 -0
  31. package/dist/src/accounts/signing/typedData.d.ts.map +1 -1
  32. package/dist/src/accounts/signing/typedData.js +2 -2
  33. package/dist/src/accounts/startale.test.js +0 -4
  34. package/dist/src/accounts/utils.d.ts +2 -2
  35. package/dist/src/accounts/utils.d.ts.map +1 -1
  36. package/dist/src/accounts/walletClient.d.ts +7 -0
  37. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  38. package/dist/src/accounts/walletClient.js +38 -0
  39. package/dist/src/actions/compact.d.ts +13 -0
  40. package/dist/src/actions/compact.d.ts.map +1 -0
  41. package/dist/src/actions/compact.js +210 -0
  42. package/dist/src/actions/ecdsa.d.ts +35 -0
  43. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  44. package/dist/src/actions/ecdsa.js +114 -0
  45. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  46. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  47. package/dist/src/actions/ecdsa.test.js +99 -0
  48. package/dist/src/actions/index.d.ts +23 -166
  49. package/dist/src/actions/index.d.ts.map +1 -1
  50. package/dist/src/actions/index.js +25 -544
  51. package/dist/src/actions/mfa.d.ts +37 -0
  52. package/dist/src/actions/mfa.d.ts.map +1 -0
  53. package/dist/src/actions/mfa.js +133 -0
  54. package/dist/src/actions/passkeys.d.ts +37 -0
  55. package/dist/src/actions/passkeys.d.ts.map +1 -0
  56. package/dist/src/actions/passkeys.js +129 -0
  57. package/dist/src/actions/passkeys.test.d.ts +2 -0
  58. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  59. package/dist/src/actions/passkeys.test.js +54 -0
  60. package/dist/src/actions/recovery.d.ts +33 -0
  61. package/dist/src/actions/recovery.d.ts.map +1 -0
  62. package/dist/src/actions/recovery.js +193 -0
  63. package/dist/src/actions/recovery.test.d.ts +2 -0
  64. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  65. package/dist/src/actions/recovery.test.js +168 -0
  66. package/dist/src/errors/index.d.ts +5 -0
  67. package/dist/src/errors/index.d.ts.map +1 -0
  68. package/dist/src/errors/index.js +35 -0
  69. package/dist/src/execution/compact.d.ts +24 -8
  70. package/dist/src/execution/compact.d.ts.map +1 -1
  71. package/dist/src/execution/compact.js +29 -103
  72. package/dist/src/execution/error.d.ts +2 -9
  73. package/dist/src/execution/error.d.ts.map +1 -1
  74. package/dist/src/execution/error.js +4 -13
  75. package/dist/src/execution/index.d.ts +33 -22
  76. package/dist/src/execution/index.d.ts.map +1 -1
  77. package/dist/src/execution/index.js +60 -41
  78. package/dist/src/execution/permit2.d.ts +148 -0
  79. package/dist/src/execution/permit2.d.ts.map +1 -0
  80. package/dist/src/execution/permit2.js +282 -0
  81. package/dist/src/execution/smart-session.d.ts +3 -3
  82. package/dist/src/execution/smart-session.d.ts.map +1 -1
  83. package/dist/src/execution/types.d.ts +35 -0
  84. package/dist/src/execution/types.d.ts.map +1 -0
  85. package/dist/src/execution/types.js +2 -0
  86. package/dist/src/execution/utils.d.ts +36 -28
  87. package/dist/src/execution/utils.d.ts.map +1 -1
  88. package/dist/src/execution/utils.js +248 -91
  89. package/dist/src/index.d.ts +37 -19
  90. package/dist/src/index.d.ts.map +1 -1
  91. package/dist/src/index.js +130 -66
  92. package/dist/src/modules/common.d.ts +10 -4
  93. package/dist/src/modules/common.d.ts.map +1 -1
  94. package/dist/src/modules/common.js +22 -1
  95. package/dist/src/modules/index.d.ts +3 -2
  96. package/dist/src/modules/index.d.ts.map +1 -1
  97. package/dist/src/modules/index.js +16 -13
  98. package/dist/src/modules/index.test.js +8 -11
  99. package/dist/src/modules/read.d.ts.map +1 -1
  100. package/dist/src/modules/read.js +4 -0
  101. package/dist/src/modules/validators/core.d.ts +5 -3
  102. package/dist/src/modules/validators/core.d.ts.map +1 -1
  103. package/dist/src/modules/validators/core.js +29 -10
  104. package/dist/src/modules/validators/core.test.js +4 -4
  105. package/dist/src/modules/validators/smart-sessions.test.js +0 -3
  106. package/dist/src/modules/validators/webauthn-contract.d.ts.map +1 -1
  107. package/dist/src/orchestrator/client.d.ts +2 -1
  108. package/dist/src/orchestrator/client.d.ts.map +1 -1
  109. package/dist/src/orchestrator/client.js +36 -14
  110. package/dist/src/orchestrator/consts.d.ts +1 -2
  111. package/dist/src/orchestrator/consts.d.ts.map +1 -1
  112. package/dist/src/orchestrator/consts.js +1 -3
  113. package/dist/src/orchestrator/registry.d.ts +2 -2
  114. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  115. package/dist/src/orchestrator/registry.js +68 -30
  116. package/dist/src/orchestrator/registry.test.js +4 -4
  117. package/dist/src/orchestrator/types.d.ts +34 -25
  118. package/dist/src/orchestrator/types.d.ts.map +1 -1
  119. package/dist/src/types.d.ts +64 -9
  120. package/dist/src/types.d.ts.map +1 -1
  121. package/package.json +73 -2
  122. package/dist/src/accounts/json-rpc/index.test.d.ts +0 -2
  123. package/dist/src/accounts/json-rpc/index.test.d.ts.map +0 -1
  124. package/dist/src/accounts/json-rpc/index.test.js +0 -16
  125. package/dist/src/accounts/json-rpc/providers.test.d.ts +0 -2
  126. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +0 -1
  127. package/dist/src/accounts/json-rpc/providers.test.js +0 -15
  128. package/dist/src/actions/index.test.d.ts +0 -2
  129. package/dist/src/actions/index.test.d.ts.map +0 -1
  130. package/dist/src/actions/index.test.js +0 -302
@@ -1,560 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeSmartSessionSignature = void 0;
4
- exports.enableEcdsa = enableEcdsa;
5
- exports.enablePasskeys = enablePasskeys;
6
- exports.disableEcdsa = disableEcdsa;
7
- exports.disablePasskeys = disablePasskeys;
8
- exports.addOwner = addOwner;
9
- exports.removeOwner = removeOwner;
10
- exports.changeThreshold = changeThreshold;
11
- exports.addPasskeyOwner = addPasskeyOwner;
12
- exports.removePasskeyOwner = removePasskeyOwner;
13
- exports.changePasskeyThreshold = changePasskeyThreshold;
14
- exports.recover = recover;
15
- exports.recoverEcdsaOwnership = recoverEcdsaOwnership;
16
- exports.recoverPasskeyOwnership = recoverPasskeyOwnership;
17
- exports.setUpRecovery = setUpRecovery;
18
- exports.enableMultiFactor = enableMultiFactor;
19
- exports.disableMultiFactor = disableMultiFactor;
20
- exports.changeMultiFactorThreshold = changeMultiFactorThreshold;
21
- exports.setSubValidator = setSubValidator;
22
- exports.removeSubValidator = removeSubValidator;
23
- const viem_1 = require("viem");
3
+ exports.installModule = installModule;
4
+ exports.uninstallModule = uninstallModule;
24
5
  const accounts_1 = require("../accounts");
25
- const utils_1 = require("../accounts/utils");
26
- const core_1 = require("../modules/validators/core");
27
- const smart_session_1 = require("./smart-session");
28
- Object.defineProperty(exports, "encodeSmartSessionSignature", { enumerable: true, get: function () { return smart_session_1.encodeSmartSessionSignature; } });
6
+ const common_1 = require("../modules/common");
29
7
  /**
30
- * Set up social recovery
31
- * @param rhinestoneAccount Account to set up social recovery on
32
- * @param guardians Guardians to use for recovery
33
- * @param threshold Threshold for the guardians
34
- * @returns Calls to set up social recovery
8
+ * Install a custom module
9
+ * @param module Module to install
10
+ * @returns Calls to install the module
35
11
  */
36
- function setUpRecovery({ rhinestoneAccount, guardians, threshold = 1, }) {
37
- const module = (0, core_1.getSocialRecoveryValidator)(guardians, threshold);
38
- const calls = (0, accounts_1.getModuleInstallationCalls)(rhinestoneAccount.config, module);
39
- return calls;
40
- }
41
- /**
42
- * Recover an account's ownership
43
- * @param address Account address
44
- * @param newOwners New owners
45
- * @param chain Chain to recover ownership on
46
- * @param provider Provider to use for the recovery
47
- * @returns Calls to recover ownership
48
- * @deprecated Use `recoverEcdsaOwnership` or `recoverPasskeyOwnership` instead
49
- */
50
- async function recover(address, newOwners, chain, provider) {
51
- switch (newOwners.type) {
52
- case 'ecdsa': {
53
- return recoverEcdsaOwnership(address, newOwners, chain, provider);
54
- }
55
- case 'passkey': {
56
- throw new Error('Passkey ownership recovery is not yet supported');
57
- }
58
- case 'multi-factor': {
59
- throw new Error('Multi-factor ownership recovery is not yet supported');
60
- }
61
- }
62
- }
63
- /**
64
- * Enable ECDSA authentication
65
- * @param rhinestoneAccount Account to enable ECDSA authentication on
66
- * @param owners Owners to use for authentication
67
- * @param threshold Threshold for the owners
68
- * @returns Calls to enable ECDSA authentication
69
- */
70
- function enableEcdsa({ rhinestoneAccount, owners, threshold = 1, }) {
71
- const module = (0, core_1.getOwnableValidator)(threshold, owners);
72
- const calls = (0, accounts_1.getModuleInstallationCalls)(rhinestoneAccount.config, module);
73
- return calls;
74
- }
75
- /**
76
- * Enable passkeys authentication
77
- * @param rhinestoneAccount Account to enable passkeys authentication on
78
- * @param pubKey Public key for the passkey
79
- * @param authenticatorId Authenticator ID for the passkey
80
- * @returns Calls to enable passkeys authentication
81
- */
82
- function enablePasskeys({ rhinestoneAccount, pubKey, authenticatorId, }) {
83
- const module = (0, core_1.getWebAuthnValidator)(1, [{ pubKey, authenticatorId }]);
84
- const calls = (0, accounts_1.getModuleInstallationCalls)(rhinestoneAccount.config, module);
85
- return calls;
86
- }
87
- /**
88
- * Disable ECDSA authentication
89
- * @param rhinestoneAccount Account to disable ECDSA authentication on
90
- * @returns Calls to disable ECDSA authentication
91
- */
92
- function disableEcdsa({ rhinestoneAccount, }) {
93
- const module = (0, core_1.getOwnableValidator)(1, []);
94
- const calls = (0, accounts_1.getModuleUninstallationCalls)(rhinestoneAccount.config, module);
95
- return calls;
96
- }
97
- /**
98
- * Disable passkeys (WebAuthn) authentication
99
- * @param rhinestoneAccount Account to disable passkeys authentication on
100
- * @returns Calls to disable passkeys authentication
101
- */
102
- function disablePasskeys({ rhinestoneAccount, }) {
103
- const module = (0, core_1.getWebAuthnValidator)(1, [
104
- {
105
- // Mocked values
106
- pubKey: '0x580a9af0569ad3905b26a703201b358aa0904236642ebe79b22a19d00d3737637d46f725a5427ae45a9569259bf67e1e16b187d7b3ad1ed70138c4f0409677d1',
107
- authenticatorId: '0x',
108
- },
109
- ]);
110
- const calls = (0, accounts_1.getModuleUninstallationCalls)(rhinestoneAccount.config, module);
111
- return calls;
112
- }
113
- /**
114
- * Add an ECDSA owner
115
- * @param owner Owner address
116
- * @returns Call to add the owner
117
- */
118
- function addOwner(owner) {
119
- return {
120
- to: core_1.OWNABLE_VALIDATOR_ADDRESS,
121
- value: 0n,
122
- data: (0, viem_1.encodeFunctionData)({
123
- abi: [
124
- {
125
- inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
126
- name: 'addOwner',
127
- outputs: [],
128
- stateMutability: 'nonpayable',
129
- type: 'function',
130
- },
131
- ],
132
- functionName: 'addOwner',
133
- args: [owner],
134
- }),
135
- };
136
- }
137
- /**
138
- * Remove an ECDSA owner
139
- * @param prevOwner Previous owner address
140
- * @param ownerToRemove Owner to remove
141
- * @returns Call to remove the owner
142
- */
143
- function removeOwner(prevOwner, ownerToRemove) {
144
- return {
145
- to: core_1.OWNABLE_VALIDATOR_ADDRESS,
146
- value: 0n,
147
- data: (0, viem_1.encodeFunctionData)({
148
- abi: [
149
- {
150
- inputs: [
151
- { internalType: 'address', name: 'prevOwner', type: 'address' },
152
- { internalType: 'address', name: 'owner', type: 'address' },
153
- ],
154
- name: 'removeOwner',
155
- outputs: [],
156
- stateMutability: 'nonpayable',
157
- type: 'function',
158
- },
159
- ],
160
- functionName: 'removeOwner',
161
- args: [prevOwner, ownerToRemove],
162
- }),
163
- };
164
- }
165
- /**
166
- * Change an account's signer threshold (ECDSA)
167
- * @param newThreshold New threshold
168
- * @returns Call to change the threshold
169
- */
170
- function changeThreshold(newThreshold) {
12
+ function installModule(module) {
13
+ const moduleData = getModule(module);
171
14
  return {
172
- to: core_1.OWNABLE_VALIDATOR_ADDRESS,
173
- value: 0n,
174
- data: (0, viem_1.encodeFunctionData)({
175
- abi: [
176
- {
177
- inputs: [
178
- { internalType: 'uint256', name: '_threshold', type: 'uint256' },
179
- ],
180
- name: 'setThreshold',
181
- outputs: [],
182
- stateMutability: 'nonpayable',
183
- type: 'function',
184
- },
185
- ],
186
- functionName: 'setThreshold',
187
- args: [BigInt(newThreshold)],
188
- }),
189
- };
190
- }
191
- /**
192
- * Add a passkey owner
193
- * @param pubKeyX Public key X
194
- * @param pubKeyY Public key Y
195
- * @param requireUserVerification Whether to require user verification
196
- * @returns Call to add the passkey owner
197
- */
198
- function addPasskeyOwner(pubKeyX, pubKeyY, requireUserVerification) {
199
- return {
200
- to: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
201
- value: 0n,
202
- data: (0, viem_1.encodeFunctionData)({
203
- abi: [
204
- {
205
- inputs: [
206
- { name: 'pubKeyX', type: 'uint256' },
207
- { name: 'pubKeyY', type: 'uint256' },
208
- {
209
- name: 'requireUserVerification',
210
- type: 'bool',
211
- },
212
- ],
213
- name: 'addCredential',
214
- outputs: [],
215
- stateMutability: 'nonpayable',
216
- type: 'function',
217
- },
218
- ],
219
- functionName: 'addCredential',
220
- args: [pubKeyX, pubKeyY, requireUserVerification],
221
- }),
222
- };
223
- }
224
- /**
225
- * Remove a passkey owner
226
- * @param pubKeyX Public key X
227
- * @param pubKeyY Public key Y
228
- * @returns Call to remove the passkey owner
229
- */
230
- function removePasskeyOwner(pubKeyX, pubKeyY) {
231
- return {
232
- to: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
233
- value: 0n,
234
- data: (0, viem_1.encodeFunctionData)({
235
- abi: [
236
- {
237
- inputs: [
238
- { name: 'pubKeyX', type: 'uint256' },
239
- { name: 'pubKeyY', type: 'uint256' },
240
- ],
241
- name: 'removeCredential',
242
- outputs: [],
243
- stateMutability: 'nonpayable',
244
- type: 'function',
245
- },
246
- ],
247
- functionName: 'removeCredential',
248
- args: [pubKeyX, pubKeyY],
249
- }),
250
- };
251
- }
252
- /**
253
- * Change an account's signer threshold (passkey)
254
- * @param newThreshold New threshold
255
- * @returns Call to change the threshold
256
- */
257
- function changePasskeyThreshold(newThreshold) {
258
- return {
259
- to: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
260
- value: 0n,
261
- data: (0, viem_1.encodeFunctionData)({
262
- abi: [
263
- {
264
- inputs: [
265
- { internalType: 'uint256', name: '_threshold', type: 'uint256' },
266
- ],
267
- name: 'setThreshold',
268
- outputs: [],
269
- stateMutability: 'nonpayable',
270
- type: 'function',
271
- },
272
- ],
273
- functionName: 'setThreshold',
274
- args: [BigInt(newThreshold)],
275
- }),
276
- };
277
- }
278
- /**
279
- * Recover an account's ownership (ECDSA)
280
- * @param address Account address
281
- * @param newOwners New owners
282
- * @param chain Chain to recover ownership on
283
- * @param provider Provider to use for the recovery
284
- * @returns Calls to recover ownership
285
- */
286
- async function recoverEcdsaOwnership(address, newOwners, chain, provider) {
287
- const publicClient = (0, viem_1.createPublicClient)({
288
- chain,
289
- transport: (0, utils_1.createTransport)(chain, provider),
290
- });
291
- // Read the existing config
292
- const results = await publicClient.multicall({
293
- contracts: [
294
- {
295
- address: core_1.OWNABLE_VALIDATOR_ADDRESS,
296
- abi: [
297
- {
298
- inputs: [
299
- { internalType: 'address', name: 'account', type: 'address' },
300
- ],
301
- name: 'getOwners',
302
- outputs: [
303
- {
304
- internalType: 'address[]',
305
- name: 'ownersArray',
306
- type: 'address[]',
307
- },
308
- ],
309
- stateMutability: 'view',
310
- type: 'function',
311
- },
312
- ],
313
- functionName: 'getOwners',
314
- args: [address],
315
- },
316
- {
317
- address: core_1.OWNABLE_VALIDATOR_ADDRESS,
318
- abi: [
319
- {
320
- inputs: [
321
- { internalType: 'address', name: 'account', type: 'address' },
322
- ],
323
- name: 'threshold',
324
- outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
325
- stateMutability: 'view',
326
- type: 'function',
327
- },
328
- ],
329
- functionName: 'threshold',
330
- args: [address],
331
- },
332
- ],
333
- });
334
- const existingOwnersResult = results[0];
335
- const existingThresholdResult = results[1];
336
- if (existingOwnersResult.error || existingThresholdResult.error) {
337
- throw new Error('Failed to read existing owners or threshold');
338
- }
339
- const existingOwners = existingOwnersResult.result;
340
- const existingThreshold = existingThresholdResult.result;
341
- const normalizedExistingOwners = existingOwners.map((owner) => owner.toLowerCase());
342
- const calls = [];
343
- // Convert new owners config to addresses and threshold
344
- const newOwnerAddresses = newOwners.accounts
345
- .map((account) => account.address.toLowerCase())
346
- .sort();
347
- const newThreshold = newOwners.threshold ?? 1;
348
- // Check if threshold needs to be updated
349
- if (Number(existingThreshold) !== newThreshold) {
350
- calls.push(changeThreshold(newThreshold));
351
- }
352
- const ownersToAdd = newOwnerAddresses.filter((owner) => !normalizedExistingOwners.includes(owner));
353
- const ownersToRemove = normalizedExistingOwners.filter((owner) => !newOwnerAddresses.includes(owner));
354
- // Maintain the list as making changes to keep track of the previous owner for removals
355
- // Note: new owners are added to the START of the linked list
356
- let currentOwners = [...normalizedExistingOwners];
357
- for (const owner of ownersToAdd) {
358
- calls.push(addOwner(owner));
359
- currentOwners.unshift(owner);
360
- }
361
- for (const ownerToRemove of ownersToRemove) {
362
- const ownerIndex = currentOwners.indexOf(ownerToRemove);
363
- let prevOwner;
364
- if (ownerIndex === 0) {
365
- // If it's the first owner, use the sentinel address
366
- prevOwner = '0x0000000000000000000000000000000000000001';
367
- }
368
- else {
369
- prevOwner = currentOwners[ownerIndex - 1];
370
- }
371
- calls.push(removeOwner(prevOwner, ownerToRemove));
372
- currentOwners = currentOwners.filter((owner) => owner !== ownerToRemove);
373
- }
374
- return calls;
375
- }
376
- /**
377
- * Recover an account's ownership (Passkey)
378
- * @param address Account address
379
- * @param oldCredentials Old credentials to be replaced (with pubKeyX, pubKeyY)
380
- * @param newOwners New passkey owners
381
- * @param chain Chain to recover ownership on
382
- * @param provider Provider to use for the recovery
383
- * @returns Calls to recover ownership
384
- */
385
- async function recoverPasskeyOwnership(address, oldCredentials, newOwners, chain, provider) {
386
- const publicClient = (0, viem_1.createPublicClient)({
387
- chain,
388
- transport: (0, utils_1.createTransport)(chain, provider),
389
- });
390
- const existingThreshold = await publicClient.readContract({
391
- address: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
392
- abi: [
393
- {
394
- inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
395
- name: 'threshold',
396
- outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
397
- stateMutability: 'view',
398
- type: 'function',
399
- },
400
- ],
401
- functionName: 'threshold',
402
- args: [address],
403
- });
404
- const calls = [];
405
- // Convert new owners config to credentials and threshold
406
- const newCredentials = newOwners.accounts.map((account) => {
407
- const publicKey = account.publicKey;
408
- // Parse the public key hex string to extract x and y coordinates
409
- const publicKeyBytes = publicKey.startsWith('0x')
410
- ? publicKey.slice(2)
411
- : publicKey;
412
- // The public key is 64 bytes: 32 bytes for x, 32 bytes for y
413
- const x = BigInt(`0x${publicKeyBytes.slice(0, 64)}`);
414
- const y = BigInt(`0x${publicKeyBytes.slice(64, 128)}`);
415
- return {
416
- pubKeyX: x,
417
- pubKeyY: y,
418
- requireUV: false, // Default to false for now
419
- };
420
- });
421
- const newThreshold = newOwners.threshold ?? 1;
422
- // Check if threshold needs to be updated
423
- if (Number(existingThreshold) !== newThreshold) {
424
- calls.push(changePasskeyThreshold(newThreshold));
425
- }
426
- // Compare existing and new credentials to determine what to add/remove
427
- const existingCredentialKeys = oldCredentials.map((cred) => `${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`);
428
- const newCredentialKeys = newCredentials.map((cred) => `${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`);
429
- // Find credentials to add (new ones not in existing)
430
- const credentialsToAdd = newCredentials.filter((cred) => !existingCredentialKeys.includes(`${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`));
431
- // Find credentials to remove (existing ones not in new)
432
- const credentialsToRemove = oldCredentials.filter((cred) => !newCredentialKeys.includes(`${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`));
433
- // Remove old credentials first (important for security in recovery scenarios)
434
- for (const credential of credentialsToRemove) {
435
- calls.push(removePasskeyOwner(credential.pubKeyX, credential.pubKeyY));
436
- }
437
- // Then add new credentials
438
- for (const credential of credentialsToAdd) {
439
- calls.push(addPasskeyOwner(credential.pubKeyX, credential.pubKeyY, credential.requireUV));
440
- }
441
- return calls;
442
- }
443
- /**
444
- * Enable multi-factor authentication
445
- * @param rhinestoneAccount Account to enable multi-factor authentication on
446
- * @param validators List of validators to use
447
- * @param threshold Threshold for the validators
448
- * @returns Calls to enable multi-factor authentication
449
- */
450
- function enableMultiFactor({ rhinestoneAccount, validators, threshold = 1, }) {
451
- const module = (0, core_1.getMultiFactorValidator)(threshold, validators);
452
- const calls = (0, accounts_1.getModuleInstallationCalls)(rhinestoneAccount.config, module);
453
- return calls;
454
- }
455
- /**
456
- * Disable multi-factor authentication
457
- * @param rhinestoneAccount Account to disable multi-factor authentication on
458
- * @returns Calls to disable multi-factor authentication
459
- */
460
- function disableMultiFactor({ rhinestoneAccount, }) {
461
- const module = (0, core_1.getMultiFactorValidator)(1, []);
462
- const calls = (0, accounts_1.getModuleUninstallationCalls)(rhinestoneAccount.config, module);
463
- return calls;
464
- }
465
- /**
466
- * Change the multi-factor threshold
467
- * @param newThreshold New threshold
468
- * @returns Call to change the threshold
469
- */
470
- function changeMultiFactorThreshold(newThreshold) {
471
- return {
472
- to: core_1.MULTI_FACTOR_VALIDATOR_ADDRESS,
473
- value: 0n,
474
- data: (0, viem_1.encodeFunctionData)({
475
- abi: [
476
- {
477
- inputs: [{ internalType: 'uint8', name: 'threshold', type: 'uint8' }],
478
- name: 'setThreshold',
479
- outputs: [],
480
- stateMutability: 'nonpayable',
481
- type: 'function',
482
- },
483
- ],
484
- functionName: 'setThreshold',
485
- args: [newThreshold],
486
- }),
15
+ async resolve({ config }) {
16
+ return (0, accounts_1.getModuleInstallationCalls)(config, moduleData);
17
+ },
487
18
  };
488
19
  }
489
20
  /**
490
- * Set a sub-validator (multi-factor)
491
- * @param id Validator ID
492
- * @param validator Validator module
493
- * @returns Call to set the sub-validator
21
+ * Uninstall a custom module
22
+ * @param module Module to uninstall
23
+ * @returns Calls to uninstall the module
494
24
  */
495
- function setSubValidator(id, validator) {
496
- const validatorId = (0, viem_1.padHex)((0, viem_1.toHex)(id), { size: 12 });
497
- const validatorModule = (0, core_1.getValidator)(validator);
25
+ function uninstallModule(module) {
26
+ const moduleData = getModule(module);
498
27
  return {
499
- to: core_1.MULTI_FACTOR_VALIDATOR_ADDRESS,
500
- value: 0n,
501
- data: (0, viem_1.encodeFunctionData)({
502
- abi: [
503
- {
504
- type: 'function',
505
- name: 'setValidator',
506
- inputs: [
507
- {
508
- type: 'address',
509
- name: 'validatorAddress',
510
- },
511
- {
512
- type: 'bytes12',
513
- name: 'validatorId',
514
- },
515
- {
516
- type: 'bytes',
517
- name: 'newValidatorData',
518
- },
519
- ],
520
- },
521
- ],
522
- functionName: 'setValidator',
523
- args: [validatorModule.address, validatorId, validatorModule.initData],
524
- }),
28
+ async resolve({ config }) {
29
+ return (0, accounts_1.getModuleUninstallationCalls)(config, moduleData);
30
+ },
525
31
  };
526
32
  }
527
- /**
528
- * Remove a sub-validator (multi-factor)
529
- * @param id Validator ID
530
- * @param validator Validator module
531
- * @returns Call to remove the sub-validator
532
- */
533
- function removeSubValidator(id, validator) {
534
- const validatorId = (0, viem_1.padHex)((0, viem_1.toHex)(id), { size: 12 });
535
- const validatorModule = (0, core_1.getValidator)(validator);
33
+ function getModule(module) {
536
34
  return {
537
- to: core_1.MULTI_FACTOR_VALIDATOR_ADDRESS,
538
- value: 0n,
539
- data: (0, viem_1.encodeFunctionData)({
540
- abi: [
541
- {
542
- type: 'function',
543
- name: 'removeValidator',
544
- inputs: [
545
- {
546
- type: 'address',
547
- name: 'validatorAddress',
548
- },
549
- {
550
- type: 'bytes12',
551
- name: 'validatorId',
552
- },
553
- ],
554
- },
555
- ],
556
- functionName: 'removeValidator',
557
- args: [validatorModule.address, validatorId],
558
- }),
35
+ type: (0, common_1.toModuleTypeId)(module.type),
36
+ address: module.address,
37
+ initData: module.initData ?? '0x',
38
+ deInitData: module.deInitData ?? '0x',
39
+ additionalContext: module.additionalContext ?? '0x',
559
40
  };
560
41
  }
@@ -0,0 +1,37 @@
1
+ import { type Hex } from 'viem';
2
+ import type { CalldataInput, LazyCallInput, OwnableValidatorConfig, WebauthnValidatorConfig } from '../types';
3
+ /**
4
+ * Enable multi-factor authentication
5
+ * @param validators List of validators to use
6
+ * @param threshold Threshold for the validators
7
+ * @returns Calls to enable multi-factor authentication
8
+ */
9
+ declare function enable(validators: (OwnableValidatorConfig | WebauthnValidatorConfig | null)[], threshold?: number): LazyCallInput;
10
+ /**
11
+ * Change the multi-factor threshold
12
+ * @param newThreshold New threshold
13
+ * @returns Call to change the threshold
14
+ */
15
+ declare function changeThreshold(newThreshold: number): CalldataInput;
16
+ /**
17
+ * Disable multi-factor authentication
18
+ * @param rhinestoneAccount Account to disable multi-factor authentication on
19
+ * @returns Calls to disable multi-factor authentication
20
+ */
21
+ declare function disable(): LazyCallInput;
22
+ /**
23
+ * Set a sub-validator (multi-factor)
24
+ * @param id Validator ID
25
+ * @param validator Validator module
26
+ * @returns Call to set the sub-validator
27
+ */
28
+ declare function setSubValidator(id: Hex | number, validator: OwnableValidatorConfig | WebauthnValidatorConfig): CalldataInput;
29
+ /**
30
+ * Remove a sub-validator (multi-factor)
31
+ * @param id Validator ID
32
+ * @param validator Validator module
33
+ * @returns Call to remove the sub-validator
34
+ */
35
+ declare function removeSubValidator(id: Hex | number, validator: OwnableValidatorConfig | WebauthnValidatorConfig): CalldataInput;
36
+ export { enable, changeThreshold, disable, setSubValidator, removeSubValidator };
37
+ //# sourceMappingURL=mfa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mfa.d.ts","sourceRoot":"","sources":["../../../actions/mfa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,GAAG,EAAiB,MAAM,MAAM,CAAA;AAUlE,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,UAAU,CAAA;AAEjB;;;;;GAKG;AACH,iBAAS,MAAM,CACb,UAAU,EAAE,CAAC,sBAAsB,GAAG,uBAAuB,GAAG,IAAI,CAAC,EAAE,EACvE,SAAS,SAAI,GACZ,aAAa,CAOf;AAED;;;;GAIG;AACH,iBAAS,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAkB5D;AAED;;;;GAIG;AACH,iBAAS,OAAO,IAAI,aAAa,CAOhC;AAED;;;;;GAKG;AACH,iBAAS,eAAe,CACtB,EAAE,EAAE,GAAG,GAAG,MAAM,EAChB,SAAS,EAAE,sBAAsB,GAAG,uBAAuB,GAC1D,aAAa,CA+Bf;AAED;;;;;GAKG;AACH,iBAAS,kBAAkB,CACzB,EAAE,EAAE,GAAG,GAAG,MAAM,EAChB,SAAS,EAAE,sBAAsB,GAAG,uBAAuB,GAC1D,aAAa,CA2Bf;AAED,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAA"}