@charterlabs/rhinestone-sdk 0.1.1 → 0.1.2

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 (194) hide show
  1. package/README.md +74 -181
  2. package/dist/src/accounts/error.d.ts +69 -0
  3. package/dist/src/accounts/error.d.ts.map +1 -0
  4. package/dist/src/accounts/error.js +109 -0
  5. package/dist/{accounts → src/accounts}/index.d.ts +14 -21
  6. package/dist/src/accounts/index.d.ts.map +1 -0
  7. package/dist/src/accounts/index.js +469 -0
  8. package/dist/src/accounts/index.test.d.ts +2 -0
  9. package/dist/src/accounts/index.test.d.ts.map +1 -0
  10. package/dist/src/accounts/index.test.js +36 -0
  11. package/dist/{accounts → src/accounts}/kernel.d.ts +7 -9
  12. package/dist/src/accounts/kernel.d.ts.map +1 -0
  13. package/dist/{accounts → src/accounts}/kernel.js +0 -8
  14. package/dist/src/accounts/kernel.test.d.ts +2 -0
  15. package/dist/src/accounts/kernel.test.d.ts.map +1 -0
  16. package/dist/src/accounts/kernel.test.js +105 -0
  17. package/dist/{accounts → src/accounts}/nexus.d.ts +14 -13
  18. package/dist/src/accounts/nexus.d.ts.map +1 -0
  19. package/dist/{accounts → src/accounts}/nexus.js +92 -88
  20. package/dist/src/accounts/nexus.test.d.ts +2 -0
  21. package/dist/src/accounts/nexus.test.d.ts.map +1 -0
  22. package/dist/src/accounts/nexus.test.js +87 -0
  23. package/dist/{accounts → src/accounts}/safe.d.ts +4 -6
  24. package/dist/src/accounts/safe.d.ts.map +1 -0
  25. package/dist/{accounts → src/accounts}/safe.js +20 -29
  26. package/dist/src/accounts/safe.test.d.ts +2 -0
  27. package/dist/src/accounts/safe.test.d.ts.map +1 -0
  28. package/dist/src/accounts/safe.test.js +87 -0
  29. package/dist/src/accounts/startale.d.ts +20 -0
  30. package/dist/src/accounts/startale.d.ts.map +1 -0
  31. package/dist/src/accounts/startale.js +100 -0
  32. package/dist/src/accounts/startale.test.d.ts +2 -0
  33. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  34. package/dist/src/accounts/startale.test.js +99 -0
  35. package/dist/{accounts → src/accounts}/utils.d.ts +4 -3
  36. package/dist/src/accounts/utils.d.ts.map +1 -0
  37. package/dist/{accounts → src/accounts}/utils.js +44 -0
  38. package/dist/src/accounts/utils.test.d.ts +2 -0
  39. package/dist/src/accounts/utils.test.d.ts.map +1 -0
  40. package/dist/src/accounts/utils.test.js +49 -0
  41. package/dist/src/actions/index.d.ts +39 -0
  42. package/dist/src/actions/index.d.ts.map +1 -0
  43. package/dist/{actions → src/actions}/index.js +108 -15
  44. package/dist/src/actions/index.test.d.ts +2 -0
  45. package/dist/src/actions/index.test.d.ts.map +1 -0
  46. package/dist/src/actions/index.test.js +302 -0
  47. package/dist/{actions → src/actions}/smart-session.d.ts +2 -2
  48. package/dist/src/actions/smart-session.d.ts.map +1 -0
  49. package/dist/src/execution/compact.d.ts +8 -0
  50. package/dist/src/execution/compact.d.ts.map +1 -0
  51. package/dist/src/execution/compact.js +105 -0
  52. package/dist/src/execution/error.d.ts +54 -0
  53. package/dist/src/execution/error.d.ts.map +1 -0
  54. package/dist/src/execution/error.js +78 -0
  55. package/dist/{execution → src/execution}/index.d.ts +7 -6
  56. package/dist/src/execution/index.d.ts.map +1 -0
  57. package/dist/src/execution/index.js +150 -0
  58. package/dist/src/execution/smart-session.d.ts +15 -0
  59. package/dist/src/execution/smart-session.d.ts.map +1 -0
  60. package/dist/{execution → src/execution}/smart-session.js +16 -77
  61. package/dist/src/execution/smart-session.test.d.ts +2 -0
  62. package/dist/src/execution/smart-session.test.d.ts.map +1 -0
  63. package/dist/src/execution/smart-session.test.js +34 -0
  64. package/dist/src/execution/utils.d.ts +45 -0
  65. package/dist/src/execution/utils.d.ts.map +1 -0
  66. package/dist/src/execution/utils.js +433 -0
  67. package/dist/src/index.d.ts +41 -0
  68. package/dist/src/index.d.ts.map +1 -0
  69. package/dist/src/index.js +154 -0
  70. package/dist/src/modules/abi/smart-sessions.d.ts.map +1 -0
  71. package/dist/src/modules/common.d.ts.map +1 -0
  72. package/dist/{modules → src/modules}/index.d.ts +3 -11
  73. package/dist/src/modules/index.d.ts.map +1 -0
  74. package/dist/{modules → src/modules}/index.js +3 -45
  75. package/dist/src/modules/index.test.d.ts +2 -0
  76. package/dist/src/modules/index.test.d.ts.map +1 -0
  77. package/dist/src/modules/index.test.js +107 -0
  78. package/dist/src/modules/omni-account.d.ts +7 -0
  79. package/dist/src/modules/omni-account.d.ts.map +1 -0
  80. package/dist/src/modules/omni-account.js +11 -0
  81. package/dist/src/modules/read.d.ts +9 -0
  82. package/dist/src/modules/read.d.ts.map +1 -0
  83. package/dist/{modules → src/modules}/read.js +6 -37
  84. package/dist/{modules → src/modules}/validators/core.d.ts +6 -7
  85. package/dist/src/modules/validators/core.d.ts.map +1 -0
  86. package/dist/{modules → src/modules}/validators/core.js +83 -8
  87. package/dist/src/modules/validators/core.test.d.ts +2 -0
  88. package/dist/src/modules/validators/core.test.d.ts.map +1 -0
  89. package/dist/src/modules/validators/core.test.js +108 -0
  90. package/dist/src/modules/validators/index.d.ts +4 -0
  91. package/dist/src/modules/validators/index.d.ts.map +1 -0
  92. package/dist/{modules → src/modules}/validators/index.js +1 -3
  93. package/dist/{modules → src/modules}/validators/smart-sessions.d.ts +4 -15
  94. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -0
  95. package/dist/{modules → src/modules}/validators/smart-sessions.js +7 -61
  96. package/dist/src/modules/validators/smart-sessions.test.d.ts +2 -0
  97. package/dist/src/modules/validators/smart-sessions.test.d.ts.map +1 -0
  98. package/dist/src/modules/validators/smart-sessions.test.js +226 -0
  99. package/dist/src/orchestrator/client.d.ts +21 -0
  100. package/dist/src/orchestrator/client.d.ts.map +1 -0
  101. package/dist/src/orchestrator/client.js +284 -0
  102. package/dist/src/orchestrator/consts.d.ts +5 -0
  103. package/dist/src/orchestrator/consts.d.ts.map +1 -0
  104. package/dist/src/orchestrator/consts.js +9 -0
  105. package/dist/src/orchestrator/error.d.ts +96 -0
  106. package/dist/src/orchestrator/error.d.ts.map +1 -0
  107. package/dist/src/orchestrator/error.js +132 -0
  108. package/dist/src/orchestrator/index.d.ts +11 -0
  109. package/dist/src/orchestrator/index.d.ts.map +1 -0
  110. package/dist/src/orchestrator/index.js +42 -0
  111. package/dist/src/orchestrator/registry.d.ts +39 -0
  112. package/dist/src/orchestrator/registry.d.ts.map +1 -0
  113. package/dist/src/orchestrator/registry.js +121 -0
  114. package/dist/src/orchestrator/registry.json +365 -0
  115. package/dist/src/orchestrator/registry.test.d.ts +2 -0
  116. package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
  117. package/dist/src/orchestrator/registry.test.js +137 -0
  118. package/dist/src/orchestrator/types.d.ts +275 -0
  119. package/dist/src/orchestrator/types.d.ts.map +1 -0
  120. package/dist/src/orchestrator/types.js +19 -0
  121. package/dist/src/orchestrator/utils.d.ts +5 -0
  122. package/dist/src/orchestrator/utils.d.ts.map +1 -0
  123. package/dist/src/orchestrator/utils.js +126 -0
  124. package/dist/{types.d.ts → src/types.d.ts} +42 -21
  125. package/dist/src/types.d.ts.map +1 -0
  126. package/dist/test/consts.d.ts +10 -0
  127. package/dist/test/consts.d.ts.map +1 -0
  128. package/dist/test/consts.js +22 -0
  129. package/package.json +11 -20
  130. package/dist/accounts/index.d.ts.map +0 -1
  131. package/dist/accounts/index.js +0 -419
  132. package/dist/accounts/kernel.d.ts.map +0 -1
  133. package/dist/accounts/nexus.d.ts.map +0 -1
  134. package/dist/accounts/safe.d.ts.map +0 -1
  135. package/dist/accounts/utils.d.ts.map +0 -1
  136. package/dist/actions/index.d.ts +0 -29
  137. package/dist/actions/index.d.ts.map +0 -1
  138. package/dist/actions/registry.d.ts +0 -7
  139. package/dist/actions/registry.d.ts.map +0 -1
  140. package/dist/actions/registry.js +0 -7
  141. package/dist/actions/smart-session.d.ts.map +0 -1
  142. package/dist/execution/index.d.ts.map +0 -1
  143. package/dist/execution/index.js +0 -149
  144. package/dist/execution/smart-session.d.ts +0 -23
  145. package/dist/execution/smart-session.d.ts.map +0 -1
  146. package/dist/execution/utils.d.ts +0 -68
  147. package/dist/execution/utils.d.ts.map +0 -1
  148. package/dist/execution/utils.js +0 -482
  149. package/dist/index.d.ts +0 -38
  150. package/dist/index.d.ts.map +0 -1
  151. package/dist/index.js +0 -119
  152. package/dist/modules/abi/smart-sessions.d.ts.map +0 -1
  153. package/dist/modules/common.d.ts.map +0 -1
  154. package/dist/modules/index.d.ts.map +0 -1
  155. package/dist/modules/omni-account.d.ts +0 -9
  156. package/dist/modules/omni-account.d.ts.map +0 -1
  157. package/dist/modules/omni-account.js +0 -15
  158. package/dist/modules/read.d.ts +0 -10
  159. package/dist/modules/read.d.ts.map +0 -1
  160. package/dist/modules/registry.d.ts +0 -9
  161. package/dist/modules/registry.d.ts.map +0 -1
  162. package/dist/modules/registry.js +0 -60
  163. package/dist/modules/validators/core.d.ts.map +0 -1
  164. package/dist/modules/validators/index.d.ts +0 -4
  165. package/dist/modules/validators/index.d.ts.map +0 -1
  166. package/dist/modules/validators/smart-sessions.d.ts.map +0 -1
  167. package/dist/orchestrator/client.d.ts +0 -29
  168. package/dist/orchestrator/client.d.ts.map +0 -1
  169. package/dist/orchestrator/client.js +0 -250
  170. package/dist/orchestrator/consts.d.ts +0 -5
  171. package/dist/orchestrator/consts.d.ts.map +0 -1
  172. package/dist/orchestrator/consts.js +0 -9
  173. package/dist/orchestrator/error.d.ts +0 -18
  174. package/dist/orchestrator/error.d.ts.map +0 -1
  175. package/dist/orchestrator/error.js +0 -33
  176. package/dist/orchestrator/index.d.ts +0 -11
  177. package/dist/orchestrator/index.d.ts.map +0 -1
  178. package/dist/orchestrator/index.js +0 -40
  179. package/dist/orchestrator/registry.d.ts +0 -20
  180. package/dist/orchestrator/registry.d.ts.map +0 -1
  181. package/dist/orchestrator/registry.js +0 -444
  182. package/dist/orchestrator/types.d.ts +0 -242
  183. package/dist/orchestrator/types.d.ts.map +0 -1
  184. package/dist/orchestrator/types.js +0 -19
  185. package/dist/orchestrator/utils.d.ts +0 -29
  186. package/dist/orchestrator/utils.d.ts.map +0 -1
  187. package/dist/orchestrator/utils.js +0 -319
  188. package/dist/types.d.ts.map +0 -1
  189. /package/dist/{actions → src/actions}/smart-session.js +0 -0
  190. /package/dist/{modules → src/modules}/abi/smart-sessions.d.ts +0 -0
  191. /package/dist/{modules → src/modules}/abi/smart-sessions.js +0 -0
  192. /package/dist/{modules → src/modules}/common.d.ts +0 -0
  193. /package/dist/{modules → src/modules}/common.js +0 -0
  194. /package/dist/{types.js → src/types.js} +0 -0
@@ -0,0 +1,469 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Eip7702NotSupportedForAccountError = exports.SignMessageNotSupportedByAccountError = exports.SigningNotSupportedForAccountError = exports.SmartSessionsNotEnabledError = exports.FactoryArgsNotAvailableError = exports.ExistingEip7702AccountsNotSupportedError = exports.Eip7702AccountMustHaveEoaError = exports.AccountError = exports.isAccountError = void 0;
4
+ exports.getModuleInstallationCalls = getModuleInstallationCalls;
5
+ exports.getModuleUninstallationCalls = getModuleUninstallationCalls;
6
+ exports.getAddress = getAddress;
7
+ exports.getAccountProvider = getAccountProvider;
8
+ exports.getInitCode = getInitCode;
9
+ exports.signEip7702InitData = signEip7702InitData;
10
+ exports.getEip7702InitCall = getEip7702InitCall;
11
+ exports.isDeployed = isDeployed;
12
+ exports.deploy = deploy;
13
+ exports.getSmartAccount = getSmartAccount;
14
+ exports.getSmartSessionSmartAccount = getSmartSessionSmartAccount;
15
+ exports.getGuardianSmartAccount = getGuardianSmartAccount;
16
+ exports.getPackedSignature = getPackedSignature;
17
+ const viem_1 = require("viem");
18
+ const execution_1 = require("../execution");
19
+ const smart_session_1 = require("../execution/smart-session");
20
+ const modules_1 = require("../modules");
21
+ const validators_1 = require("../modules/validators");
22
+ const core_1 = require("../modules/validators/core");
23
+ const error_1 = require("./error");
24
+ Object.defineProperty(exports, "AccountError", { enumerable: true, get: function () { return error_1.AccountError; } });
25
+ Object.defineProperty(exports, "Eip7702AccountMustHaveEoaError", { enumerable: true, get: function () { return error_1.Eip7702AccountMustHaveEoaError; } });
26
+ Object.defineProperty(exports, "Eip7702NotSupportedForAccountError", { enumerable: true, get: function () { return error_1.Eip7702NotSupportedForAccountError; } });
27
+ Object.defineProperty(exports, "ExistingEip7702AccountsNotSupportedError", { enumerable: true, get: function () { return error_1.ExistingEip7702AccountsNotSupportedError; } });
28
+ Object.defineProperty(exports, "FactoryArgsNotAvailableError", { enumerable: true, get: function () { return error_1.FactoryArgsNotAvailableError; } });
29
+ Object.defineProperty(exports, "isAccountError", { enumerable: true, get: function () { return error_1.isAccountError; } });
30
+ Object.defineProperty(exports, "SigningNotSupportedForAccountError", { enumerable: true, get: function () { return error_1.SigningNotSupportedForAccountError; } });
31
+ Object.defineProperty(exports, "SignMessageNotSupportedByAccountError", { enumerable: true, get: function () { return error_1.SignMessageNotSupportedByAccountError; } });
32
+ Object.defineProperty(exports, "SmartSessionsNotEnabledError", { enumerable: true, get: function () { return error_1.SmartSessionsNotEnabledError; } });
33
+ const kernel_1 = require("./kernel");
34
+ const nexus_1 = require("./nexus");
35
+ const safe_1 = require("./safe");
36
+ const startale_1 = require("./startale");
37
+ const utils_1 = require("./utils");
38
+ function getDeployArgs(config) {
39
+ const account = getAccountProvider(config);
40
+ switch (account.type) {
41
+ case 'safe': {
42
+ return (0, safe_1.getDeployArgs)(config);
43
+ }
44
+ case 'nexus': {
45
+ return (0, nexus_1.getDeployArgs)(config);
46
+ }
47
+ case 'kernel': {
48
+ return (0, kernel_1.getDeployArgs)(config);
49
+ }
50
+ case 'startale': {
51
+ return (0, startale_1.getDeployArgs)(config);
52
+ }
53
+ }
54
+ }
55
+ function getInitCode(config) {
56
+ if (is7702(config)) {
57
+ return undefined;
58
+ }
59
+ else {
60
+ const { factory, factoryData } = getDeployArgs(config);
61
+ if (!factory || !factoryData) {
62
+ throw new error_1.FactoryArgsNotAvailableError();
63
+ }
64
+ return {
65
+ factory,
66
+ factoryData,
67
+ };
68
+ }
69
+ }
70
+ async function signEip7702InitData(config) {
71
+ const eoa = config.eoa;
72
+ if (!eoa) {
73
+ throw new error_1.Eip7702AccountMustHaveEoaError();
74
+ }
75
+ const account = getAccountProvider(config);
76
+ switch (account.type) {
77
+ case 'nexus': {
78
+ return await (0, nexus_1.signEip7702InitData)(config, eoa);
79
+ }
80
+ case 'safe':
81
+ case 'kernel':
82
+ case 'startale': {
83
+ throw new Error(`7702 is not supported for account type ${account.type}`);
84
+ }
85
+ }
86
+ }
87
+ async function getEip7702InitCall(config, signature) {
88
+ const account = getAccountProvider(config);
89
+ switch (account.type) {
90
+ case 'nexus': {
91
+ return await (0, nexus_1.getEip7702InitCall)(config, signature);
92
+ }
93
+ case 'safe':
94
+ case 'kernel':
95
+ case 'startale': {
96
+ throw new Error(`7702 is not supported for account type ${account.type}`);
97
+ }
98
+ }
99
+ }
100
+ function getModuleInstallationCalls(config, module) {
101
+ const address = getAddress(config);
102
+ function getInstallData() {
103
+ const account = getAccountProvider(config);
104
+ switch (account.type) {
105
+ case 'safe': {
106
+ return [(0, safe_1.getInstallData)(module)];
107
+ }
108
+ case 'nexus': {
109
+ return [(0, nexus_1.getInstallData)(module)];
110
+ }
111
+ case 'kernel': {
112
+ return (0, kernel_1.getInstallData)(module);
113
+ }
114
+ case 'startale': {
115
+ return [(0, startale_1.getInstallData)(module)];
116
+ }
117
+ }
118
+ }
119
+ const installData = getInstallData();
120
+ return installData.map((data) => ({
121
+ to: address,
122
+ value: 0n,
123
+ data,
124
+ }));
125
+ }
126
+ function getModuleUninstallationCalls(config, module) {
127
+ const address = getAddress(config);
128
+ const data = (0, viem_1.encodeFunctionData)({
129
+ abi: [
130
+ {
131
+ type: 'function',
132
+ name: 'uninstallModule',
133
+ inputs: [
134
+ {
135
+ type: 'uint256',
136
+ name: 'moduleTypeId',
137
+ },
138
+ {
139
+ type: 'address',
140
+ name: 'module',
141
+ },
142
+ {
143
+ type: 'bytes',
144
+ name: 'deInitData',
145
+ },
146
+ ],
147
+ outputs: [],
148
+ stateMutability: 'nonpayable',
149
+ },
150
+ ],
151
+ functionName: 'uninstallModule',
152
+ args: [module.type, module.address, module.deInitData],
153
+ });
154
+ return [{ to: address, data, value: 0n }];
155
+ }
156
+ function getAddress(config) {
157
+ if (is7702(config)) {
158
+ if (!config.eoa) {
159
+ throw new error_1.Eip7702AccountMustHaveEoaError();
160
+ }
161
+ return config.eoa.address;
162
+ }
163
+ const account = getAccountProvider(config);
164
+ switch (account.type) {
165
+ case 'safe': {
166
+ return (0, safe_1.getAddress)(config);
167
+ }
168
+ case 'nexus': {
169
+ return (0, nexus_1.getAddress)(config);
170
+ }
171
+ case 'kernel': {
172
+ return (0, kernel_1.getAddress)(config);
173
+ }
174
+ case 'startale': {
175
+ return (0, startale_1.getAddress)(config);
176
+ }
177
+ }
178
+ }
179
+ // Signs and packs a signature to be EIP-1271 compatible
180
+ async function getPackedSignature(config, signers, chain, validator, hash, transformSignature = (signature) => signature) {
181
+ signers = signers ?? convertOwnerSetToSignerSet(config.owners);
182
+ const signFn = (hash) => sign(signers, chain, hash);
183
+ const account = getAccountProvider(config);
184
+ const address = getAddress(config);
185
+ switch (account.type) {
186
+ case 'safe': {
187
+ return (0, safe_1.getPackedSignature)(signFn, hash, validator, transformSignature);
188
+ }
189
+ case 'nexus': {
190
+ return (0, nexus_1.getPackedSignature)(signFn, hash, validator, transformSignature);
191
+ }
192
+ case 'kernel': {
193
+ return (0, kernel_1.getPackedSignature)(signFn, hash, validator, address, transformSignature);
194
+ }
195
+ case 'startale': {
196
+ return (0, startale_1.getPackedSignature)(signFn, hash, validator, transformSignature);
197
+ }
198
+ }
199
+ }
200
+ async function isDeployed(chain, config) {
201
+ const publicClient = (0, viem_1.createPublicClient)({
202
+ chain: chain,
203
+ transport: (0, utils_1.createTransport)(chain, config.provider),
204
+ });
205
+ const address = getAddress(config);
206
+ const code = await publicClient.getCode({
207
+ address,
208
+ });
209
+ if (!code) {
210
+ return false;
211
+ }
212
+ if (code.startsWith('0xef0100') && code.length === 48) {
213
+ // Defensive check to ensure there's no storage conflict; can be lifted in the future
214
+ throw new error_1.ExistingEip7702AccountsNotSupportedError();
215
+ }
216
+ return (0, viem_1.size)(code) > 0;
217
+ }
218
+ async function deploy(config, chain, session) {
219
+ await deployWithIntent(chain, config);
220
+ if (session) {
221
+ await (0, smart_session_1.enableSmartSession)(chain, config, session);
222
+ }
223
+ }
224
+ async function deployWithIntent(chain, config) {
225
+ const publicClient = (0, viem_1.createPublicClient)({
226
+ chain,
227
+ transport: (0, utils_1.createTransport)(chain, config.provider),
228
+ });
229
+ const address = getAddress(config);
230
+ const code = await publicClient.getCode({ address });
231
+ if (code) {
232
+ // Already deployed
233
+ return;
234
+ }
235
+ await (0, execution_1.sendTransaction)(config, {
236
+ targetChain: chain,
237
+ calls: [
238
+ {
239
+ to: viem_1.zeroAddress,
240
+ data: '0x',
241
+ },
242
+ ],
243
+ });
244
+ }
245
+ async function getSmartAccount(config, client, chain) {
246
+ const account = getAccountProvider(config);
247
+ const address = getAddress(config);
248
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
249
+ const signers = convertOwnerSetToSignerSet(config.owners);
250
+ const signFn = (hash) => sign(signers, chain, hash);
251
+ switch (account.type) {
252
+ case 'safe': {
253
+ return (0, safe_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
254
+ }
255
+ case 'nexus': {
256
+ return (0, nexus_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
257
+ }
258
+ case 'kernel': {
259
+ return (0, kernel_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
260
+ }
261
+ case 'startale': {
262
+ return (0, startale_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
263
+ }
264
+ }
265
+ }
266
+ async function getSmartSessionSmartAccount(config, client, chain, session, enableData) {
267
+ const address = getAddress(config);
268
+ const smartSessionValidator = (0, validators_1.getSmartSessionValidator)(config);
269
+ if (!smartSessionValidator) {
270
+ throw new error_1.SmartSessionsNotEnabledError();
271
+ }
272
+ const signers = {
273
+ type: 'session',
274
+ session,
275
+ enableData: enableData || undefined,
276
+ };
277
+ const signFn = (hash) => sign(signers, chain, hash);
278
+ const account = getAccountProvider(config);
279
+ switch (account.type) {
280
+ case 'safe': {
281
+ return (0, safe_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
282
+ }
283
+ case 'nexus': {
284
+ return (0, nexus_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
285
+ }
286
+ case 'kernel': {
287
+ return (0, kernel_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
288
+ }
289
+ case 'startale': {
290
+ return (0, startale_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
291
+ }
292
+ }
293
+ }
294
+ async function getGuardianSmartAccount(config, client, chain, guardians) {
295
+ const address = getAddress(config);
296
+ const accounts = guardians.type === 'ecdsa' ? guardians.accounts : [];
297
+ const socialRecoveryValidator = (0, core_1.getSocialRecoveryValidator)(accounts);
298
+ if (!socialRecoveryValidator) {
299
+ throw new Error('Social recovery is not available');
300
+ }
301
+ const signers = {
302
+ type: 'guardians',
303
+ guardians: accounts,
304
+ };
305
+ const signFn = (hash) => sign(signers, chain, hash);
306
+ const account = getAccountProvider(config);
307
+ switch (account.type) {
308
+ case 'safe': {
309
+ return (0, safe_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
310
+ }
311
+ case 'nexus': {
312
+ return (0, nexus_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
313
+ }
314
+ case 'kernel': {
315
+ return (0, kernel_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
316
+ }
317
+ case 'startale': {
318
+ return (0, startale_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
319
+ }
320
+ }
321
+ }
322
+ async function sign(signers, chain, hash) {
323
+ switch (signers.type) {
324
+ case 'owner': {
325
+ switch (signers.kind) {
326
+ case 'ecdsa': {
327
+ const signatures = await Promise.all(signers.accounts.map((account) => signEcdsa(account, hash)));
328
+ return (0, viem_1.concat)(signatures);
329
+ }
330
+ case 'passkey': {
331
+ // Convert OwnerSignerSet to WebauthnValidatorConfig
332
+ const webAuthnConfig = {
333
+ type: 'passkey',
334
+ account: signers.account,
335
+ credentialIds: [] // This should be passed from config
336
+ };
337
+ return await signPasskey(webAuthnConfig, chain, hash);
338
+ }
339
+ case 'multi-factor': {
340
+ const signatures = await Promise.all(signers.validators.map(async (validator) => {
341
+ if (validator === null) {
342
+ return '0x';
343
+ }
344
+ // Convert to proper validator format
345
+ const validatorConfig = validator.type === 'ecdsa'
346
+ ? { type: 'ecdsa', accounts: validator.accounts, threshold: 1 }
347
+ : { type: 'passkey', account: validator.account, credentialIds: [] };
348
+ const validatorSigners = convertOwnerSetToSignerSet(validatorConfig);
349
+ return sign(validatorSigners, chain, hash);
350
+ }));
351
+ const data = (0, viem_1.encodeAbiParameters)([
352
+ {
353
+ components: [
354
+ {
355
+ internalType: 'bytes32',
356
+ name: 'packedValidatorAndId',
357
+ type: 'bytes32',
358
+ },
359
+ { internalType: 'bytes', name: 'data', type: 'bytes' },
360
+ ],
361
+ name: 'validators',
362
+ type: 'tuple[]',
363
+ },
364
+ ], [
365
+ signers.validators.map((validator, index) => {
366
+ // Convert to proper validator format for getValidator
367
+ const validatorConfig = validator.type === 'ecdsa'
368
+ ? { type: 'ecdsa', accounts: validator.accounts, threshold: 1 }
369
+ : { type: 'passkey', account: validator.account, credentialIds: [] };
370
+ const validatorModule = (0, core_1.getValidator)(validatorConfig);
371
+ return {
372
+ packedValidatorAndId: (0, viem_1.concat)([
373
+ (0, viem_1.pad)((0, viem_1.toHex)(validator.id), {
374
+ size: 12,
375
+ }),
376
+ validatorModule.address,
377
+ ]),
378
+ data: signatures[index],
379
+ };
380
+ }),
381
+ ]);
382
+ return data;
383
+ }
384
+ default: {
385
+ throw new Error('Unsupported owner kind');
386
+ }
387
+ }
388
+ }
389
+ case 'session': {
390
+ const sessionSigners = convertOwnerSetToSignerSet(signers.session.owners);
391
+ return sign(sessionSigners, chain, hash);
392
+ }
393
+ case 'guardians': {
394
+ const signatures = await Promise.all(signers.guardians.map((account) => signEcdsa(account, hash)));
395
+ return (0, viem_1.concat)(signatures);
396
+ }
397
+ }
398
+ }
399
+ async function signEcdsa(account, hash) {
400
+ if (!account.signMessage) {
401
+ throw new error_1.SigningNotSupportedForAccountError();
402
+ }
403
+ return await account.signMessage({ message: { raw: hash } });
404
+ }
405
+ async function signPasskey(validators, chain, hash) {
406
+ const { account, credentialIds } = validators;
407
+ const { webauthn: rawWebauthn, signature } = await account.sign({ hash });
408
+ const { authenticatorData, clientDataJSON, challengeIndex, typeIndex } = rawWebauthn;
409
+ const usePrecompiled = (0, modules_1.isRip7212SupportedNetwork)(chain);
410
+ return (0, modules_1.getWebauthnValidatorSignature)({
411
+ credentialIds,
412
+ usePrecompiled,
413
+ webauthn: { authenticatorData, clientDataJSON, challengeIndex, typeIndex },
414
+ signature,
415
+ });
416
+ }
417
+ function is7702(config) {
418
+ return config.eoa !== undefined;
419
+ }
420
+ function getAccountProvider(config) {
421
+ if (config.account) {
422
+ return config.account;
423
+ }
424
+ return {
425
+ type: 'nexus',
426
+ };
427
+ }
428
+ function convertOwnerSetToSignerSet(owners) {
429
+ switch (owners.type) {
430
+ case 'ecdsa': {
431
+ return {
432
+ type: 'owner',
433
+ kind: 'ecdsa',
434
+ accounts: owners.accounts,
435
+ };
436
+ }
437
+ case 'passkey': {
438
+ return {
439
+ type: 'owner',
440
+ kind: 'passkey',
441
+ account: owners.account,
442
+ };
443
+ }
444
+ case 'multi-factor': {
445
+ return {
446
+ type: 'owner',
447
+ kind: 'multi-factor',
448
+ validators: owners.validators.map((validator, index) => {
449
+ switch (validator.type) {
450
+ case 'ecdsa': {
451
+ return {
452
+ type: 'ecdsa',
453
+ id: index,
454
+ accounts: validator.accounts,
455
+ };
456
+ }
457
+ case 'passkey': {
458
+ return {
459
+ type: 'passkey',
460
+ id: index,
461
+ account: validator.account,
462
+ };
463
+ }
464
+ }
465
+ }),
466
+ };
467
+ }
468
+ }
469
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../accounts/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const consts_1 = require("../../test/consts");
5
+ const _1 = require(".");
6
+ (0, vitest_1.describe)('Accounts', () => {
7
+ (0, vitest_1.describe)('Get Address', () => {
8
+ (0, vitest_1.test)('Nexus, ECDSA owner', () => {
9
+ const address = (0, _1.getAddress)({
10
+ owners: {
11
+ type: 'ecdsa',
12
+ accounts: [consts_1.accountA, consts_1.accountB],
13
+ threshold: 1,
14
+ },
15
+ rhinestoneApiKey: consts_1.MOCK_API_KEY,
16
+ });
17
+ (0, vitest_1.expect)(address).toEqual('0xa32fa78416f6c68ce4f75f702e07849a269feffb');
18
+ });
19
+ (0, vitest_1.test)('Safe, passkey owner with a session', () => {
20
+ const address = (0, _1.getAddress)({
21
+ owners: {
22
+ type: 'passkey',
23
+ account: consts_1.passkeyAccount,
24
+ credentialIds: ['0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'],
25
+ },
26
+ rhinestoneApiKey: consts_1.MOCK_API_KEY,
27
+ });
28
+ (0, vitest_1.expect)(address).toEqual('0xfbda4e576b2a300cd1b7e8748c9a7577ab3a503e');
29
+ });
30
+ });
31
+ (0, vitest_1.describe)('Sign', () => {
32
+ vitest_1.test.todo('With ECDSA, single key');
33
+ vitest_1.test.todo('With ECDSA, multisig');
34
+ vitest_1.test.todo('With Passkey');
35
+ });
36
+ });
@@ -1,9 +1,9 @@
1
- import { Abi, Address, Hex, PublicClient } from 'viem';
2
- import { SmartAccount, SmartAccountImplementation } from 'viem/account-abstraction';
3
- import { Module } from '../modules/common';
4
- import { EnableSessionData } from '../modules/validators/smart-sessions';
5
- import { OwnerSet, RhinestoneAccountConfig, Session } from '../types';
6
- import { ValidatorConfig } from './utils';
1
+ import { type Abi, type Address, type Hex, type PublicClient } from 'viem';
2
+ import { type SmartAccount, type SmartAccountImplementation } from 'viem/account-abstraction';
3
+ import { type Module } from '../modules/common';
4
+ import type { EnableSessionData } from '../modules/validators/smart-sessions';
5
+ import type { OwnerSet, RhinestoneAccountConfig, Session } from '../types';
6
+ import { type ValidatorConfig } from './utils';
7
7
  declare function getDeployArgs(config: RhinestoneAccountConfig): {
8
8
  factory: `0x${string}`;
9
9
  factoryData: `0x${string}`;
@@ -13,11 +13,9 @@ declare function getDeployArgs(config: RhinestoneAccountConfig): {
13
13
  };
14
14
  declare function getAddress(config: RhinestoneAccountConfig): `0x${string}`;
15
15
  declare function getInstallData(module: Module): Hex[];
16
- declare function get7702InitCalls(): never;
17
- declare function get7702SmartAccount(): never;
18
16
  declare function getPackedSignature(signFn: (message: Hex) => Promise<Hex>, hash: Hex, validator: ValidatorConfig, accountAddress: Address, transformSignature?: (signature: Hex) => Hex): Promise<`0x${string}`>;
19
17
  declare function getSmartAccount(client: PublicClient, address: Address, owners: OwnerSet, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
20
18
  declare function getSessionSmartAccount(client: PublicClient, address: Address, session: Session, validatorAddress: Address, enableData: EnableSessionData | null, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
21
19
  declare function getGuardianSmartAccount(client: PublicClient, address: Address, guardians: OwnerSet, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
22
- export { getInstallData, getAddress, getDeployArgs, getSmartAccount, getSessionSmartAccount, getGuardianSmartAccount, get7702InitCalls, get7702SmartAccount, getPackedSignature, };
20
+ export { getInstallData, getAddress, getDeployArgs, getSmartAccount, getSessionSmartAccount, getGuardianSmartAccount, getPackedSignature, };
23
21
  //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../accounts/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAAG,EACR,KAAK,OAAO,EAQZ,KAAK,GAAG,EAER,KAAK,YAAY,EAMlB,MAAM,MAAM,CAAA;AACb,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAEhC,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EAKL,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAA;AAQ1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC1E,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAgBhF,iBAAS,aAAa,CAAC,MAAM,EAAE,uBAAuB;;;;;;EA4CrD;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,uBAAuB,iBASlD;AAED,iBAAS,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,CAsE7C;AAED,iBAAe,kBAAkB,CAC/B,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EACtC,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,eAAe,EAC1B,cAAc,EAAE,OAAO,EACvB,kBAAkB,GAAE,CAAC,SAAS,EAAE,GAAG,KAAK,GAA8B,0BAevE;AAwBD,iBAAe,eAAe,CAC5B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,QAAQ,EAChB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAYlC;AAED,iBAAe,sBAAsB,CACnC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,OAAO,EACzB,UAAU,EAAE,iBAAiB,GAAG,IAAI,EACpC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEA0ClC;AAED,iBAAe,uBAAuB,CACpC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,QAAQ,EACnB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAclC;AA+ED,OAAO,EACL,cAAc,EACd,UAAU,EACV,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,GACnB,CAAA"}
@@ -6,8 +6,6 @@ exports.getDeployArgs = getDeployArgs;
6
6
  exports.getSmartAccount = getSmartAccount;
7
7
  exports.getSessionSmartAccount = getSessionSmartAccount;
8
8
  exports.getGuardianSmartAccount = getGuardianSmartAccount;
9
- exports.get7702InitCalls = get7702InitCalls;
10
- exports.get7702SmartAccount = get7702SmartAccount;
11
9
  exports.getPackedSignature = getPackedSignature;
12
10
  const viem_1 = require("viem");
13
11
  const account_abstraction_1 = require("viem/account-abstraction");
@@ -128,12 +126,6 @@ function getInstallData(module) {
128
126
  }
129
127
  }
130
128
  }
131
- function get7702InitCalls() {
132
- throw new Error('EIP-7702 is not yet supported for Kernel accounts');
133
- }
134
- function get7702SmartAccount() {
135
- throw new Error('EIP-7702 is not yet supported for Kernel accounts');
136
- }
137
129
  async function getPackedSignature(signFn, hash, validator, accountAddress, transformSignature = (signature) => signature) {
138
130
  const vId = validator.isRoot ? '0x00' : (0, viem_1.concat)(['0x01', validator.address]);
139
131
  const signature = validator.isRoot
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kernel.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.test.d.ts","sourceRoot":"","sources":["../../../accounts/kernel.test.ts"],"names":[],"mappings":""}