@rhinestone/sdk 1.0.0-alpha.9 → 1.0.0-beta.38

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 (151) 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 +30 -15
  5. package/dist/src/accounts/index.d.ts.map +1 -1
  6. package/dist/src/accounts/index.js +284 -140
  7. package/dist/src/accounts/index.test.js +3 -5
  8. package/dist/src/accounts/json-rpc/index.d.ts +5 -0
  9. package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
  10. package/dist/src/accounts/json-rpc/index.js +16 -0
  11. package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
  12. package/dist/src/accounts/json-rpc/index.test.js +16 -0
  13. package/dist/src/accounts/json-rpc/providers.d.ts +4 -0
  14. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
  15. package/dist/src/accounts/json-rpc/providers.js +14 -0
  16. package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
  17. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
  18. package/dist/src/accounts/json-rpc/providers.test.js +15 -0
  19. package/dist/src/accounts/kernel.d.ts +4 -3
  20. package/dist/src/accounts/kernel.d.ts.map +1 -1
  21. package/dist/src/accounts/kernel.js +32 -6
  22. package/dist/src/accounts/kernel.test.js +41 -19
  23. package/dist/src/accounts/nexus.d.ts +11 -4
  24. package/dist/src/accounts/nexus.d.ts.map +1 -1
  25. package/dist/src/accounts/nexus.js +182 -25
  26. package/dist/src/accounts/nexus.test.js +44 -18
  27. package/dist/src/accounts/safe.d.ts +2 -2
  28. package/dist/src/accounts/safe.d.ts.map +1 -1
  29. package/dist/src/accounts/safe.js +88 -58
  30. package/dist/src/accounts/safe.test.js +40 -14
  31. package/dist/src/accounts/signing/common.d.ts +27 -0
  32. package/dist/src/accounts/signing/common.d.ts.map +1 -0
  33. package/dist/src/accounts/signing/common.js +145 -0
  34. package/dist/src/accounts/signing/message.d.ts +5 -0
  35. package/dist/src/accounts/signing/message.d.ts.map +1 -0
  36. package/dist/src/accounts/signing/message.js +47 -0
  37. package/dist/src/accounts/signing/passkeys.d.ts +36 -0
  38. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
  39. package/dist/src/accounts/signing/passkeys.js +125 -0
  40. package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
  41. package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
  42. package/dist/src/accounts/signing/passkeys.test.js +88 -0
  43. package/dist/src/accounts/signing/typedData.d.ts +5 -0
  44. package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
  45. package/dist/src/accounts/signing/typedData.js +35 -0
  46. package/dist/src/accounts/startale.d.ts +2 -2
  47. package/dist/src/accounts/startale.d.ts.map +1 -1
  48. package/dist/src/accounts/startale.js +3 -3
  49. package/dist/src/accounts/startale.test.js +9 -14
  50. package/dist/src/accounts/utils.d.ts +4 -4
  51. package/dist/src/accounts/utils.d.ts.map +1 -1
  52. package/dist/src/accounts/utils.js +3 -40
  53. package/dist/src/accounts/walletClient.d.ts +7 -0
  54. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  55. package/dist/src/accounts/walletClient.js +38 -0
  56. package/dist/src/actions/compact.d.ts +13 -0
  57. package/dist/src/actions/compact.d.ts.map +1 -0
  58. package/dist/src/actions/compact.js +210 -0
  59. package/dist/src/actions/ecdsa.d.ts +35 -0
  60. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  61. package/dist/src/actions/ecdsa.js +114 -0
  62. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  63. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  64. package/dist/src/actions/ecdsa.test.js +99 -0
  65. package/dist/src/actions/index.d.ts +23 -38
  66. package/dist/src/actions/index.d.ts.map +1 -1
  67. package/dist/src/actions/index.js +29 -294
  68. package/dist/src/actions/mfa.d.ts +37 -0
  69. package/dist/src/actions/mfa.d.ts.map +1 -0
  70. package/dist/src/actions/mfa.js +133 -0
  71. package/dist/src/actions/passkeys.d.ts +37 -0
  72. package/dist/src/actions/passkeys.d.ts.map +1 -0
  73. package/dist/src/actions/passkeys.js +129 -0
  74. package/dist/src/actions/passkeys.test.d.ts +2 -0
  75. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  76. package/dist/src/actions/passkeys.test.js +54 -0
  77. package/dist/src/actions/recovery.d.ts +33 -0
  78. package/dist/src/actions/recovery.d.ts.map +1 -0
  79. package/dist/src/actions/recovery.js +193 -0
  80. package/dist/src/actions/recovery.test.d.ts +2 -0
  81. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  82. package/dist/src/actions/recovery.test.js +168 -0
  83. package/dist/src/actions/smart-session.d.ts +6 -0
  84. package/dist/src/actions/smart-session.d.ts.map +1 -1
  85. package/dist/src/actions/smart-session.js +6 -0
  86. package/dist/src/errors/index.d.ts +5 -0
  87. package/dist/src/errors/index.d.ts.map +1 -0
  88. package/dist/src/errors/index.js +35 -0
  89. package/dist/src/execution/compact.d.ts +150 -7
  90. package/dist/src/execution/compact.d.ts.map +1 -1
  91. package/dist/src/execution/compact.js +112 -95
  92. package/dist/src/execution/error.d.ts +2 -9
  93. package/dist/src/execution/error.d.ts.map +1 -1
  94. package/dist/src/execution/error.js +4 -13
  95. package/dist/src/execution/index.d.ts +34 -22
  96. package/dist/src/execution/index.d.ts.map +1 -1
  97. package/dist/src/execution/index.js +62 -42
  98. package/dist/src/execution/permit2.d.ts +148 -0
  99. package/dist/src/execution/permit2.d.ts.map +1 -0
  100. package/dist/src/execution/permit2.js +282 -0
  101. package/dist/src/execution/smart-session.d.ts +3 -3
  102. package/dist/src/execution/smart-session.d.ts.map +1 -1
  103. package/dist/src/execution/types.d.ts +35 -0
  104. package/dist/src/execution/types.d.ts.map +1 -0
  105. package/dist/src/execution/types.js +2 -0
  106. package/dist/src/execution/utils.d.ts +36 -27
  107. package/dist/src/execution/utils.d.ts.map +1 -1
  108. package/dist/src/execution/utils.js +357 -103
  109. package/dist/src/index.d.ts +41 -22
  110. package/dist/src/index.d.ts.map +1 -1
  111. package/dist/src/index.js +199 -65
  112. package/dist/src/modules/common.d.ts +10 -4
  113. package/dist/src/modules/common.d.ts.map +1 -1
  114. package/dist/src/modules/common.js +22 -1
  115. package/dist/src/modules/index.d.ts +4 -18
  116. package/dist/src/modules/index.d.ts.map +1 -1
  117. package/dist/src/modules/index.js +15 -63
  118. package/dist/src/modules/index.test.js +9 -26
  119. package/dist/src/modules/omni-account.d.ts +2 -1
  120. package/dist/src/modules/omni-account.d.ts.map +1 -1
  121. package/dist/src/modules/omni-account.js +3 -1
  122. package/dist/src/modules/read.d.ts.map +1 -1
  123. package/dist/src/modules/read.js +4 -0
  124. package/dist/src/modules/validators/core.d.ts +5 -3
  125. package/dist/src/modules/validators/core.d.ts.map +1 -1
  126. package/dist/src/modules/validators/core.js +64 -41
  127. package/dist/src/modules/validators/core.test.js +7 -7
  128. package/dist/src/modules/validators/smart-sessions.js +3 -3
  129. package/dist/src/modules/validators/smart-sessions.test.js +4 -7
  130. package/dist/src/orchestrator/client.d.ts +4 -4
  131. package/dist/src/orchestrator/client.d.ts.map +1 -1
  132. package/dist/src/orchestrator/client.js +30 -15
  133. package/dist/src/orchestrator/index.d.ts +2 -3
  134. package/dist/src/orchestrator/index.d.ts.map +1 -1
  135. package/dist/src/orchestrator/index.js +1 -3
  136. package/dist/src/orchestrator/registry.d.ts +1 -23
  137. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  138. package/dist/src/orchestrator/registry.js +37 -33
  139. package/dist/src/orchestrator/registry.test.js +7 -7
  140. package/dist/src/orchestrator/types.d.ts +97 -29
  141. package/dist/src/orchestrator/types.d.ts.map +1 -1
  142. package/dist/src/orchestrator/utils.d.ts +1 -3
  143. package/dist/src/orchestrator/utils.d.ts.map +1 -1
  144. package/dist/src/orchestrator/utils.js +0 -102
  145. package/dist/src/types.d.ts +74 -10
  146. package/dist/src/types.d.ts.map +1 -1
  147. package/package.json +72 -1
  148. package/dist/src/actions/index.test.d.ts.map +0 -1
  149. package/dist/src/actions/index.test.js +0 -302
  150. package/dist/src/orchestrator/registry.json +0 -365
  151. /package/dist/src/{actions → accounts/json-rpc}/index.test.d.ts +0 -0
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enable = enable;
4
+ exports.changeThreshold = changeThreshold;
5
+ exports.disable = disable;
6
+ exports.setSubValidator = setSubValidator;
7
+ exports.removeSubValidator = removeSubValidator;
8
+ const viem_1 = require("viem");
9
+ const accounts_1 = require("../accounts");
10
+ const core_1 = require("../modules/validators/core");
11
+ /**
12
+ * Enable multi-factor authentication
13
+ * @param validators List of validators to use
14
+ * @param threshold Threshold for the validators
15
+ * @returns Calls to enable multi-factor authentication
16
+ */
17
+ function enable(validators, threshold = 1) {
18
+ const module = (0, core_1.getMultiFactorValidator)(threshold, validators);
19
+ return {
20
+ async resolve({ config }) {
21
+ return (0, accounts_1.getModuleInstallationCalls)(config, module);
22
+ },
23
+ };
24
+ }
25
+ /**
26
+ * Change the multi-factor threshold
27
+ * @param newThreshold New threshold
28
+ * @returns Call to change the threshold
29
+ */
30
+ function changeThreshold(newThreshold) {
31
+ return {
32
+ to: core_1.MULTI_FACTOR_VALIDATOR_ADDRESS,
33
+ value: 0n,
34
+ data: (0, viem_1.encodeFunctionData)({
35
+ abi: [
36
+ {
37
+ inputs: [{ internalType: 'uint8', name: 'threshold', type: 'uint8' }],
38
+ name: 'setThreshold',
39
+ outputs: [],
40
+ stateMutability: 'nonpayable',
41
+ type: 'function',
42
+ },
43
+ ],
44
+ functionName: 'setThreshold',
45
+ args: [newThreshold],
46
+ }),
47
+ };
48
+ }
49
+ /**
50
+ * Disable multi-factor authentication
51
+ * @param rhinestoneAccount Account to disable multi-factor authentication on
52
+ * @returns Calls to disable multi-factor authentication
53
+ */
54
+ function disable() {
55
+ const module = (0, core_1.getMultiFactorValidator)(1, []);
56
+ return {
57
+ async resolve({ config }) {
58
+ return (0, accounts_1.getModuleUninstallationCalls)(config, module);
59
+ },
60
+ };
61
+ }
62
+ /**
63
+ * Set a sub-validator (multi-factor)
64
+ * @param id Validator ID
65
+ * @param validator Validator module
66
+ * @returns Call to set the sub-validator
67
+ */
68
+ function setSubValidator(id, validator) {
69
+ const validatorId = (0, viem_1.padHex)((0, viem_1.toHex)(id), { size: 12 });
70
+ const validatorModule = (0, core_1.getValidator)(validator);
71
+ return {
72
+ to: core_1.MULTI_FACTOR_VALIDATOR_ADDRESS,
73
+ value: 0n,
74
+ data: (0, viem_1.encodeFunctionData)({
75
+ abi: [
76
+ {
77
+ type: 'function',
78
+ name: 'setValidator',
79
+ inputs: [
80
+ {
81
+ type: 'address',
82
+ name: 'validatorAddress',
83
+ },
84
+ {
85
+ type: 'bytes12',
86
+ name: 'validatorId',
87
+ },
88
+ {
89
+ type: 'bytes',
90
+ name: 'newValidatorData',
91
+ },
92
+ ],
93
+ },
94
+ ],
95
+ functionName: 'setValidator',
96
+ args: [validatorModule.address, validatorId, validatorModule.initData],
97
+ }),
98
+ };
99
+ }
100
+ /**
101
+ * Remove a sub-validator (multi-factor)
102
+ * @param id Validator ID
103
+ * @param validator Validator module
104
+ * @returns Call to remove the sub-validator
105
+ */
106
+ function removeSubValidator(id, validator) {
107
+ const validatorId = (0, viem_1.padHex)((0, viem_1.toHex)(id), { size: 12 });
108
+ const validatorModule = (0, core_1.getValidator)(validator);
109
+ return {
110
+ to: core_1.MULTI_FACTOR_VALIDATOR_ADDRESS,
111
+ value: 0n,
112
+ data: (0, viem_1.encodeFunctionData)({
113
+ abi: [
114
+ {
115
+ type: 'function',
116
+ name: 'removeValidator',
117
+ inputs: [
118
+ {
119
+ type: 'address',
120
+ name: 'validatorAddress',
121
+ },
122
+ {
123
+ type: 'bytes12',
124
+ name: 'validatorId',
125
+ },
126
+ ],
127
+ },
128
+ ],
129
+ functionName: 'removeValidator',
130
+ args: [validatorModule.address, validatorId],
131
+ }),
132
+ };
133
+ }
@@ -0,0 +1,37 @@
1
+ import { type WebauthnCredential } from '../modules/validators/core';
2
+ import type { CalldataInput, LazyCallInput } from '../types';
3
+ /**
4
+ * Enable passkeys authentication
5
+ * @param pubKey Public key for the passkey
6
+ * @param authenticatorId Authenticator ID for the passkey
7
+ * @returns Calls to enable passkeys authentication
8
+ */
9
+ declare function enable(credential: WebauthnCredential): LazyCallInput;
10
+ /**
11
+ * Disable passkeys (WebAuthn) authentication
12
+ * @returns Calls to disable passkeys authentication
13
+ */
14
+ declare function disable(): LazyCallInput;
15
+ /**
16
+ * Add a passkey owner
17
+ * @param pubKeyX Public key X
18
+ * @param pubKeyY Public key Y
19
+ * @param requireUserVerification Whether to require user verification
20
+ * @returns Call to add the passkey owner
21
+ */
22
+ declare function addOwner(pubKeyX: bigint, pubKeyY: bigint, requireUserVerification: boolean): CalldataInput;
23
+ /**
24
+ * Remove a passkey owner
25
+ * @param pubKeyX Public key X
26
+ * @param pubKeyY Public key Y
27
+ * @returns Call to remove the passkey owner
28
+ */
29
+ declare function removeOwner(pubKeyX: bigint, pubKeyY: bigint): CalldataInput;
30
+ /**
31
+ * Change an account's signer threshold (passkey)
32
+ * @param newThreshold New threshold
33
+ * @returns Call to change the threshold
34
+ */
35
+ declare function changeThreshold(newThreshold: number): CalldataInput;
36
+ export { addOwner, removeOwner, changeThreshold, disable, enable };
37
+ //# sourceMappingURL=passkeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passkeys.d.ts","sourceRoot":"","sources":["../../../actions/passkeys.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE5D;;;;;GAKG;AACH,iBAAS,MAAM,CAAC,UAAU,EAAE,kBAAkB,GAAG,aAAa,CAO7D;AAED;;;GAGG;AACH,iBAAS,OAAO,IAAI,aAAa,CAchC;AAED;;;;;;GAMG;AACH,iBAAS,QAAQ,CACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,uBAAuB,EAAE,OAAO,GAC/B,aAAa,CAyBf;AAED;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAqBpE;AAED;;;;GAIG;AACH,iBAAS,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAoB5D;AAED,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addOwner = addOwner;
4
+ exports.removeOwner = removeOwner;
5
+ exports.changeThreshold = changeThreshold;
6
+ exports.disable = disable;
7
+ exports.enable = enable;
8
+ const viem_1 = require("viem");
9
+ const accounts_1 = require("../accounts");
10
+ const core_1 = require("../modules/validators/core");
11
+ /**
12
+ * Enable passkeys authentication
13
+ * @param pubKey Public key for the passkey
14
+ * @param authenticatorId Authenticator ID for the passkey
15
+ * @returns Calls to enable passkeys authentication
16
+ */
17
+ function enable(credential) {
18
+ const module = (0, core_1.getWebAuthnValidator)(1, [credential]);
19
+ return {
20
+ async resolve({ config }) {
21
+ return (0, accounts_1.getModuleInstallationCalls)(config, module);
22
+ },
23
+ };
24
+ }
25
+ /**
26
+ * Disable passkeys (WebAuthn) authentication
27
+ * @returns Calls to disable passkeys authentication
28
+ */
29
+ function disable() {
30
+ const module = (0, core_1.getWebAuthnValidator)(1, [
31
+ {
32
+ // Mocked values
33
+ pubKey: '0x580a9af0569ad3905b26a703201b358aa0904236642ebe79b22a19d00d3737637d46f725a5427ae45a9569259bf67e1e16b187d7b3ad1ed70138c4f0409677d1',
34
+ authenticatorId: '0x',
35
+ },
36
+ ]);
37
+ return {
38
+ async resolve({ config }) {
39
+ return (0, accounts_1.getModuleUninstallationCalls)(config, module);
40
+ },
41
+ };
42
+ }
43
+ /**
44
+ * Add a passkey owner
45
+ * @param pubKeyX Public key X
46
+ * @param pubKeyY Public key Y
47
+ * @param requireUserVerification Whether to require user verification
48
+ * @returns Call to add the passkey owner
49
+ */
50
+ function addOwner(pubKeyX, pubKeyY, requireUserVerification) {
51
+ return {
52
+ to: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
53
+ value: 0n,
54
+ data: (0, viem_1.encodeFunctionData)({
55
+ abi: [
56
+ {
57
+ inputs: [
58
+ { name: 'pubKeyX', type: 'uint256' },
59
+ { name: 'pubKeyY', type: 'uint256' },
60
+ {
61
+ name: 'requireUserVerification',
62
+ type: 'bool',
63
+ },
64
+ ],
65
+ name: 'addCredential',
66
+ outputs: [],
67
+ stateMutability: 'nonpayable',
68
+ type: 'function',
69
+ },
70
+ ],
71
+ functionName: 'addCredential',
72
+ args: [pubKeyX, pubKeyY, requireUserVerification],
73
+ }),
74
+ };
75
+ }
76
+ /**
77
+ * Remove a passkey owner
78
+ * @param pubKeyX Public key X
79
+ * @param pubKeyY Public key Y
80
+ * @returns Call to remove the passkey owner
81
+ */
82
+ function removeOwner(pubKeyX, pubKeyY) {
83
+ return {
84
+ to: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
85
+ value: 0n,
86
+ data: (0, viem_1.encodeFunctionData)({
87
+ abi: [
88
+ {
89
+ inputs: [
90
+ { name: 'pubKeyX', type: 'uint256' },
91
+ { name: 'pubKeyY', type: 'uint256' },
92
+ ],
93
+ name: 'removeCredential',
94
+ outputs: [],
95
+ stateMutability: 'nonpayable',
96
+ type: 'function',
97
+ },
98
+ ],
99
+ functionName: 'removeCredential',
100
+ args: [pubKeyX, pubKeyY],
101
+ }),
102
+ };
103
+ }
104
+ /**
105
+ * Change an account's signer threshold (passkey)
106
+ * @param newThreshold New threshold
107
+ * @returns Call to change the threshold
108
+ */
109
+ function changeThreshold(newThreshold) {
110
+ return {
111
+ to: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
112
+ value: 0n,
113
+ data: (0, viem_1.encodeFunctionData)({
114
+ abi: [
115
+ {
116
+ inputs: [
117
+ { internalType: 'uint256', name: '_threshold', type: 'uint256' },
118
+ ],
119
+ name: 'setThreshold',
120
+ outputs: [],
121
+ stateMutability: 'nonpayable',
122
+ type: 'function',
123
+ },
124
+ ],
125
+ functionName: 'setThreshold',
126
+ args: [BigInt(newThreshold)],
127
+ }),
128
+ };
129
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=passkeys.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passkeys.test.d.ts","sourceRoot":"","sources":["../../../actions/passkeys.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chains_1 = require("viem/chains");
4
+ const vitest_1 = require("vitest");
5
+ const consts_1 = require("../../test/consts");
6
+ const __1 = require("..");
7
+ const utils_1 = require("../execution/utils");
8
+ const passkeys_1 = require("./passkeys");
9
+ const accountAddress = '0x36C03e7D593F7B2C6b06fC18B5f4E9a4A29C99b0';
10
+ (0, vitest_1.describe)('Passkeys Actions', () => {
11
+ (0, vitest_1.describe)('Install WebAuthn Validator', async () => {
12
+ const rhinestone = new __1.RhinestoneSDK();
13
+ const rhinestoneAccount = await rhinestone.createAccount({
14
+ owners: {
15
+ type: 'ecdsa',
16
+ accounts: [consts_1.accountA],
17
+ },
18
+ });
19
+ (0, vitest_1.test)('', async () => {
20
+ const calls = await (0, utils_1.resolveCallInputs)([
21
+ (0, passkeys_1.enable)({
22
+ pubKey: consts_1.passkeyAccount.publicKey,
23
+ authenticatorId: consts_1.passkeyAccount.id,
24
+ }),
25
+ ], rhinestoneAccount.config, chains_1.base, accountAddress);
26
+ (0, vitest_1.expect)(calls).toEqual([
27
+ {
28
+ to: accountAddress,
29
+ value: 0n,
30
+ data: '0x9517e29f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000578c4cb0e472a5462da43c495c3f33000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001580a9af0569ad3905b26a703201b358aa0904236642ebe79b22a19d00d3737637d46f725a5427ae45a9569259bf67e1e16b187d7b3ad1ed70138c4f0409677d10000000000000000000000000000000000000000000000000000000000000000',
31
+ },
32
+ ]);
33
+ });
34
+ });
35
+ (0, vitest_1.describe)('Uninstall WebAuthn Validator', async () => {
36
+ const rhinestone = new __1.RhinestoneSDK();
37
+ const rhinestoneAccount = await rhinestone.createAccount({
38
+ owners: {
39
+ type: 'ecdsa',
40
+ accounts: [consts_1.accountA],
41
+ },
42
+ });
43
+ (0, vitest_1.test)('', async () => {
44
+ const calls = await (0, utils_1.resolveCallInputs)([(0, passkeys_1.disable)()], rhinestoneAccount.config, chains_1.base, accountAddress);
45
+ (0, vitest_1.expect)(calls).toEqual([
46
+ {
47
+ to: accountAddress,
48
+ value: 0n,
49
+ data: '0xa71763a800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000578c4cb0e472a5462da43c495c3f3300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000',
50
+ },
51
+ ]);
52
+ });
53
+ });
54
+ });
@@ -0,0 +1,33 @@
1
+ import { type Account, type Address, type Chain } from 'viem';
2
+ import type { CalldataInput, LazyCallInput, OwnableValidatorConfig, RhinestoneConfig, WebauthnValidatorConfig } from '../types';
3
+ /**
4
+ * Set up social recovery
5
+ * @param guardians Guardians to use for recovery
6
+ * @param threshold Threshold for the guardians
7
+ * @returns Calls to set up social recovery
8
+ */
9
+ declare function enable(guardians: Account[], threshold?: number): LazyCallInput;
10
+ /**
11
+ * Recover an account's ownership (ECDSA)
12
+ * @param address Account address
13
+ * @param newOwners New owners
14
+ * @param chain Chain to recover ownership on
15
+ * @param provider Provider to use for the recovery
16
+ * @returns Calls to recover ownership
17
+ */
18
+ declare function recoverEcdsaOwnership(address: Address, newOwners: OwnableValidatorConfig, chain: Chain, config: RhinestoneConfig): Promise<CalldataInput[]>;
19
+ /**
20
+ * Recover an account's ownership (Passkey)
21
+ * @param address Account address
22
+ * @param oldCredentials Old credentials to be replaced (with pubKeyX, pubKeyY)
23
+ * @param newOwners New passkey owners
24
+ * @param chain Chain to recover ownership on
25
+ * @param provider Provider to use for the recovery
26
+ * @returns Calls to recover ownership
27
+ */
28
+ declare function recoverPasskeyOwnership(address: Address, oldCredentials: {
29
+ pubKeyX: bigint;
30
+ pubKeyY: bigint;
31
+ }[], newOwners: WebauthnValidatorConfig, chain: Chain, config: RhinestoneConfig): Promise<CalldataInput[]>;
32
+ export { enable, recoverEcdsaOwnership, recoverPasskeyOwnership };
33
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../actions/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,KAAK,EAEX,MAAM,MAAM,CAAA;AASb,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,UAAU,CAAA;AAQjB;;;;;GAKG;AACH,iBAAS,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,SAAS,SAAI,GAAG,aAAa,CAOlE;AAED;;;;;;;GAOG;AACH,iBAAe,qBAAqB,CAClC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,sBAAsB,EACjC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CAwG1B;AAED;;;;;;;;GAQG;AACH,iBAAe,uBAAuB,CACpC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,EACtD,SAAS,EAAE,uBAAuB,EAClC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CA0F1B;AAED,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,CAAA"}
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enable = enable;
4
+ exports.recoverEcdsaOwnership = recoverEcdsaOwnership;
5
+ exports.recoverPasskeyOwnership = recoverPasskeyOwnership;
6
+ const viem_1 = require("viem");
7
+ const accounts_1 = require("../accounts");
8
+ const json_rpc_1 = require("../accounts/json-rpc");
9
+ const utils_1 = require("../execution/utils");
10
+ const core_1 = require("../modules/validators/core");
11
+ const ecdsa_1 = require("./ecdsa");
12
+ const passkeys_1 = require("./passkeys");
13
+ /**
14
+ * Set up social recovery
15
+ * @param guardians Guardians to use for recovery
16
+ * @param threshold Threshold for the guardians
17
+ * @returns Calls to set up social recovery
18
+ */
19
+ function enable(guardians, threshold = 1) {
20
+ const module = (0, core_1.getSocialRecoveryValidator)(guardians, threshold);
21
+ return {
22
+ async resolve({ config }) {
23
+ return (0, accounts_1.getModuleInstallationCalls)(config, module);
24
+ },
25
+ };
26
+ }
27
+ /**
28
+ * Recover an account's ownership (ECDSA)
29
+ * @param address Account address
30
+ * @param newOwners New owners
31
+ * @param chain Chain to recover ownership on
32
+ * @param provider Provider to use for the recovery
33
+ * @returns Calls to recover ownership
34
+ */
35
+ async function recoverEcdsaOwnership(address, newOwners, chain, config) {
36
+ const publicClient = (0, viem_1.createPublicClient)({
37
+ chain,
38
+ transport: (0, json_rpc_1.createTransport)(chain, config.provider),
39
+ });
40
+ // Read the existing config
41
+ const results = await publicClient.multicall({
42
+ contracts: [
43
+ {
44
+ address: core_1.OWNABLE_VALIDATOR_ADDRESS,
45
+ abi: [
46
+ {
47
+ inputs: [
48
+ { internalType: 'address', name: 'account', type: 'address' },
49
+ ],
50
+ name: 'getOwners',
51
+ outputs: [
52
+ {
53
+ internalType: 'address[]',
54
+ name: 'ownersArray',
55
+ type: 'address[]',
56
+ },
57
+ ],
58
+ stateMutability: 'view',
59
+ type: 'function',
60
+ },
61
+ ],
62
+ functionName: 'getOwners',
63
+ args: [address],
64
+ },
65
+ {
66
+ address: core_1.OWNABLE_VALIDATOR_ADDRESS,
67
+ abi: [
68
+ {
69
+ inputs: [
70
+ { internalType: 'address', name: 'account', type: 'address' },
71
+ ],
72
+ name: 'threshold',
73
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
74
+ stateMutability: 'view',
75
+ type: 'function',
76
+ },
77
+ ],
78
+ functionName: 'threshold',
79
+ args: [address],
80
+ },
81
+ ],
82
+ });
83
+ const existingOwnersResult = results[0];
84
+ const existingThresholdResult = results[1];
85
+ if (existingOwnersResult.error || existingThresholdResult.error) {
86
+ throw new Error('Failed to read existing owners or threshold');
87
+ }
88
+ const existingOwners = existingOwnersResult.result;
89
+ const existingThreshold = existingThresholdResult.result;
90
+ const normalizedExistingOwners = existingOwners.map((owner) => owner.toLowerCase());
91
+ const callInputs = [];
92
+ // Convert new owners config to addresses and threshold
93
+ const newOwnerAddresses = newOwners.accounts
94
+ .map((account) => account.address.toLowerCase())
95
+ .sort();
96
+ const newThreshold = newOwners.threshold ?? 1;
97
+ // Check if threshold needs to be updated
98
+ if (Number(existingThreshold) !== newThreshold) {
99
+ callInputs.push((0, ecdsa_1.changeThreshold)(newThreshold));
100
+ }
101
+ const ownersToAdd = newOwnerAddresses.filter((owner) => !normalizedExistingOwners.includes(owner));
102
+ const ownersToRemove = normalizedExistingOwners.filter((owner) => !newOwnerAddresses.includes(owner));
103
+ // Maintain the list as making changes to keep track of the previous owner for removals
104
+ // Note: new owners are added to the START of the linked list
105
+ let currentOwners = [...normalizedExistingOwners];
106
+ for (const owner of ownersToAdd) {
107
+ callInputs.push((0, ecdsa_1.addOwner)(owner));
108
+ currentOwners.unshift(owner);
109
+ }
110
+ for (const ownerToRemove of ownersToRemove) {
111
+ const ownerIndex = currentOwners.indexOf(ownerToRemove);
112
+ let prevOwner;
113
+ if (ownerIndex === 0) {
114
+ // If it's the first owner, use the sentinel address
115
+ prevOwner = '0x0000000000000000000000000000000000000001';
116
+ }
117
+ else {
118
+ prevOwner = currentOwners[ownerIndex - 1];
119
+ }
120
+ callInputs.push((0, ecdsa_1.removeOwner)(prevOwner, ownerToRemove));
121
+ currentOwners = currentOwners.filter((owner) => owner !== ownerToRemove);
122
+ }
123
+ const calls = await (0, utils_1.resolveCallInputs)(callInputs, config, chain, address);
124
+ return calls;
125
+ }
126
+ /**
127
+ * Recover an account's ownership (Passkey)
128
+ * @param address Account address
129
+ * @param oldCredentials Old credentials to be replaced (with pubKeyX, pubKeyY)
130
+ * @param newOwners New passkey owners
131
+ * @param chain Chain to recover ownership on
132
+ * @param provider Provider to use for the recovery
133
+ * @returns Calls to recover ownership
134
+ */
135
+ async function recoverPasskeyOwnership(address, oldCredentials, newOwners, chain, config) {
136
+ const publicClient = (0, viem_1.createPublicClient)({
137
+ chain,
138
+ transport: (0, json_rpc_1.createTransport)(chain, config.provider),
139
+ });
140
+ const existingThreshold = await publicClient.readContract({
141
+ address: core_1.WEBAUTHN_VALIDATOR_ADDRESS,
142
+ abi: [
143
+ {
144
+ inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
145
+ name: 'threshold',
146
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
147
+ stateMutability: 'view',
148
+ type: 'function',
149
+ },
150
+ ],
151
+ functionName: 'threshold',
152
+ args: [address],
153
+ });
154
+ const callInputs = [];
155
+ // Convert new owners config to credentials and threshold
156
+ const newCredentials = newOwners.accounts.map((account) => {
157
+ const publicKey = account.publicKey;
158
+ // Parse the public key hex string to extract x and y coordinates
159
+ const publicKeyBytes = publicKey.startsWith('0x')
160
+ ? publicKey.slice(2)
161
+ : publicKey;
162
+ // The public key is 64 bytes: 32 bytes for x, 32 bytes for y
163
+ const x = BigInt(`0x${publicKeyBytes.slice(0, 64)}`);
164
+ const y = BigInt(`0x${publicKeyBytes.slice(64, 128)}`);
165
+ return {
166
+ pubKeyX: x,
167
+ pubKeyY: y,
168
+ requireUV: false, // Default to false for now
169
+ };
170
+ });
171
+ const newThreshold = newOwners.threshold ?? 1;
172
+ // Check if threshold needs to be updated
173
+ if (Number(existingThreshold) !== newThreshold) {
174
+ callInputs.push((0, passkeys_1.changeThreshold)(newThreshold));
175
+ }
176
+ // Compare existing and new credentials to determine what to add/remove
177
+ const existingCredentialKeys = oldCredentials.map((cred) => `${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`);
178
+ const newCredentialKeys = newCredentials.map((cred) => `${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`);
179
+ // Find credentials to add (new ones not in existing)
180
+ const credentialsToAdd = newCredentials.filter((cred) => !existingCredentialKeys.includes(`${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`));
181
+ // Find credentials to remove (existing ones not in new)
182
+ const credentialsToRemove = oldCredentials.filter((cred) => !newCredentialKeys.includes(`${cred.pubKeyX.toString()}-${cred.pubKeyY.toString()}`));
183
+ // Remove old credentials first (important for security in recovery scenarios)
184
+ for (const credential of credentialsToRemove) {
185
+ callInputs.push((0, passkeys_1.removeOwner)(credential.pubKeyX, credential.pubKeyY));
186
+ }
187
+ // Then add new credentials
188
+ for (const credential of credentialsToAdd) {
189
+ callInputs.push((0, passkeys_1.addOwner)(credential.pubKeyX, credential.pubKeyY, credential.requireUV));
190
+ }
191
+ const calls = await (0, utils_1.resolveCallInputs)(callInputs, config, chain, address);
192
+ return calls;
193
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=recovery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.test.d.ts","sourceRoot":"","sources":["../../../actions/recovery.test.ts"],"names":[],"mappings":""}