@rhinestone/sdk 1.0.0-alpha.8 → 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 (153) 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 +57 -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 +304 -138
  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 +14 -7
  24. package/dist/src/accounts/nexus.d.ts.map +1 -1
  25. package/dist/src/accounts/nexus.js +191 -34
  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 +20 -0
  47. package/dist/src/accounts/startale.d.ts.map +1 -0
  48. package/dist/src/accounts/startale.js +100 -0
  49. package/dist/src/accounts/startale.test.d.ts +2 -0
  50. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  51. package/dist/src/accounts/startale.test.js +92 -0
  52. package/dist/src/accounts/utils.d.ts +4 -4
  53. package/dist/src/accounts/utils.d.ts.map +1 -1
  54. package/dist/src/accounts/utils.js +3 -40
  55. package/dist/src/accounts/walletClient.d.ts +7 -0
  56. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  57. package/dist/src/accounts/walletClient.js +38 -0
  58. package/dist/src/actions/compact.d.ts +13 -0
  59. package/dist/src/actions/compact.d.ts.map +1 -0
  60. package/dist/src/actions/compact.js +210 -0
  61. package/dist/src/actions/ecdsa.d.ts +35 -0
  62. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  63. package/dist/src/actions/ecdsa.js +114 -0
  64. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  65. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  66. package/dist/src/actions/ecdsa.test.js +99 -0
  67. package/dist/src/actions/index.d.ts +23 -38
  68. package/dist/src/actions/index.d.ts.map +1 -1
  69. package/dist/src/actions/index.js +29 -294
  70. package/dist/src/actions/mfa.d.ts +37 -0
  71. package/dist/src/actions/mfa.d.ts.map +1 -0
  72. package/dist/src/actions/mfa.js +133 -0
  73. package/dist/src/actions/passkeys.d.ts +37 -0
  74. package/dist/src/actions/passkeys.d.ts.map +1 -0
  75. package/dist/src/actions/passkeys.js +129 -0
  76. package/dist/src/actions/passkeys.test.d.ts +2 -0
  77. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  78. package/dist/src/actions/passkeys.test.js +54 -0
  79. package/dist/src/actions/recovery.d.ts +33 -0
  80. package/dist/src/actions/recovery.d.ts.map +1 -0
  81. package/dist/src/actions/recovery.js +193 -0
  82. package/dist/src/actions/recovery.test.d.ts +2 -0
  83. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  84. package/dist/src/actions/recovery.test.js +168 -0
  85. package/dist/src/actions/smart-session.d.ts +6 -0
  86. package/dist/src/actions/smart-session.d.ts.map +1 -1
  87. package/dist/src/actions/smart-session.js +6 -0
  88. package/dist/src/errors/index.d.ts +5 -0
  89. package/dist/src/errors/index.d.ts.map +1 -0
  90. package/dist/src/errors/index.js +35 -0
  91. package/dist/src/execution/compact.d.ts +150 -7
  92. package/dist/src/execution/compact.d.ts.map +1 -1
  93. package/dist/src/execution/compact.js +112 -95
  94. package/dist/src/execution/error.d.ts +2 -9
  95. package/dist/src/execution/error.d.ts.map +1 -1
  96. package/dist/src/execution/error.js +4 -13
  97. package/dist/src/execution/index.d.ts +34 -22
  98. package/dist/src/execution/index.d.ts.map +1 -1
  99. package/dist/src/execution/index.js +62 -43
  100. package/dist/src/execution/permit2.d.ts +148 -0
  101. package/dist/src/execution/permit2.d.ts.map +1 -0
  102. package/dist/src/execution/permit2.js +282 -0
  103. package/dist/src/execution/smart-session.d.ts +3 -3
  104. package/dist/src/execution/smart-session.d.ts.map +1 -1
  105. package/dist/src/execution/types.d.ts +35 -0
  106. package/dist/src/execution/types.d.ts.map +1 -0
  107. package/dist/src/execution/types.js +2 -0
  108. package/dist/src/execution/utils.d.ts +36 -27
  109. package/dist/src/execution/utils.d.ts.map +1 -1
  110. package/dist/src/execution/utils.js +357 -103
  111. package/dist/src/index.d.ts +41 -22
  112. package/dist/src/index.d.ts.map +1 -1
  113. package/dist/src/index.js +199 -65
  114. package/dist/src/modules/common.d.ts +10 -4
  115. package/dist/src/modules/common.d.ts.map +1 -1
  116. package/dist/src/modules/common.js +22 -1
  117. package/dist/src/modules/index.d.ts +4 -18
  118. package/dist/src/modules/index.d.ts.map +1 -1
  119. package/dist/src/modules/index.js +15 -63
  120. package/dist/src/modules/index.test.js +9 -26
  121. package/dist/src/modules/omni-account.d.ts +2 -1
  122. package/dist/src/modules/omni-account.d.ts.map +1 -1
  123. package/dist/src/modules/omni-account.js +3 -1
  124. package/dist/src/modules/read.d.ts.map +1 -1
  125. package/dist/src/modules/read.js +5 -0
  126. package/dist/src/modules/validators/core.d.ts +5 -3
  127. package/dist/src/modules/validators/core.d.ts.map +1 -1
  128. package/dist/src/modules/validators/core.js +64 -41
  129. package/dist/src/modules/validators/core.test.js +7 -7
  130. package/dist/src/modules/validators/smart-sessions.js +3 -3
  131. package/dist/src/modules/validators/smart-sessions.test.js +4 -7
  132. package/dist/src/orchestrator/client.d.ts +4 -4
  133. package/dist/src/orchestrator/client.d.ts.map +1 -1
  134. package/dist/src/orchestrator/client.js +30 -15
  135. package/dist/src/orchestrator/index.d.ts +2 -3
  136. package/dist/src/orchestrator/index.d.ts.map +1 -1
  137. package/dist/src/orchestrator/index.js +1 -3
  138. package/dist/src/orchestrator/registry.d.ts +1 -23
  139. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  140. package/dist/src/orchestrator/registry.js +37 -33
  141. package/dist/src/orchestrator/registry.test.js +7 -7
  142. package/dist/src/orchestrator/types.d.ts +97 -29
  143. package/dist/src/orchestrator/types.d.ts.map +1 -1
  144. package/dist/src/orchestrator/utils.d.ts +1 -3
  145. package/dist/src/orchestrator/utils.d.ts.map +1 -1
  146. package/dist/src/orchestrator/utils.js +0 -102
  147. package/dist/src/types.d.ts +74 -10
  148. package/dist/src/types.d.ts.map +1 -1
  149. package/package.json +72 -1
  150. package/dist/src/actions/index.test.d.ts.map +0 -1
  151. package/dist/src/actions/index.test.js +0 -302
  152. package/dist/src/orchestrator/registry.json +0 -365
  153. /package/dist/src/{actions → accounts/json-rpc}/index.test.d.ts +0 -0
@@ -1,17 +1,24 @@
1
1
  "use strict";
2
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;
3
+ exports.WalletClientNoConnectedAccountError = exports.SmartSessionsNotEnabledError = exports.SigningNotSupportedForAccountError = exports.OwnersFieldRequiredError = exports.ModuleInstallationNotSupportedError = exports.FactoryArgsNotAvailableError = exports.ExistingEip7702AccountsNotSupportedError = exports.EoaSigningNotSupportedError = exports.EoaSigningMethodNotConfiguredError = exports.Eip7702NotSupportedForAccountError = exports.Eip7702AccountMustHaveEoaError = exports.AccountConfigurationNotSupportedError = exports.AccountError = exports.isAccountError = void 0;
4
4
  exports.getModuleInstallationCalls = getModuleInstallationCalls;
5
5
  exports.getModuleUninstallationCalls = getModuleUninstallationCalls;
6
6
  exports.getAddress = getAddress;
7
+ exports.checkAddress = checkAddress;
7
8
  exports.getAccountProvider = getAccountProvider;
8
9
  exports.getInitCode = getInitCode;
10
+ exports.signEip7702InitData = signEip7702InitData;
11
+ exports.getEip7702InitCall = getEip7702InitCall;
12
+ exports.is7702 = is7702;
9
13
  exports.isDeployed = isDeployed;
10
14
  exports.deploy = deploy;
15
+ exports.setup = setup;
16
+ exports.toErc6492Signature = toErc6492Signature;
11
17
  exports.getSmartAccount = getSmartAccount;
12
18
  exports.getSmartSessionSmartAccount = getSmartSessionSmartAccount;
13
19
  exports.getGuardianSmartAccount = getGuardianSmartAccount;
14
20
  exports.getPackedSignature = getPackedSignature;
21
+ exports.getTypedDataPackedSignature = getTypedDataPackedSignature;
15
22
  const viem_1 = require("viem");
16
23
  const execution_1 = require("../execution");
17
24
  const smart_session_1 = require("../execution/smart-session");
@@ -19,18 +26,27 @@ const modules_1 = require("../modules");
19
26
  const validators_1 = require("../modules/validators");
20
27
  const core_1 = require("../modules/validators/core");
21
28
  const error_1 = require("./error");
29
+ Object.defineProperty(exports, "AccountConfigurationNotSupportedError", { enumerable: true, get: function () { return error_1.AccountConfigurationNotSupportedError; } });
22
30
  Object.defineProperty(exports, "AccountError", { enumerable: true, get: function () { return error_1.AccountError; } });
23
31
  Object.defineProperty(exports, "Eip7702AccountMustHaveEoaError", { enumerable: true, get: function () { return error_1.Eip7702AccountMustHaveEoaError; } });
24
32
  Object.defineProperty(exports, "Eip7702NotSupportedForAccountError", { enumerable: true, get: function () { return error_1.Eip7702NotSupportedForAccountError; } });
33
+ Object.defineProperty(exports, "EoaSigningMethodNotConfiguredError", { enumerable: true, get: function () { return error_1.EoaSigningMethodNotConfiguredError; } });
34
+ Object.defineProperty(exports, "EoaSigningNotSupportedError", { enumerable: true, get: function () { return error_1.EoaSigningNotSupportedError; } });
25
35
  Object.defineProperty(exports, "ExistingEip7702AccountsNotSupportedError", { enumerable: true, get: function () { return error_1.ExistingEip7702AccountsNotSupportedError; } });
26
36
  Object.defineProperty(exports, "FactoryArgsNotAvailableError", { enumerable: true, get: function () { return error_1.FactoryArgsNotAvailableError; } });
27
37
  Object.defineProperty(exports, "isAccountError", { enumerable: true, get: function () { return error_1.isAccountError; } });
38
+ Object.defineProperty(exports, "ModuleInstallationNotSupportedError", { enumerable: true, get: function () { return error_1.ModuleInstallationNotSupportedError; } });
39
+ Object.defineProperty(exports, "OwnersFieldRequiredError", { enumerable: true, get: function () { return error_1.OwnersFieldRequiredError; } });
28
40
  Object.defineProperty(exports, "SigningNotSupportedForAccountError", { enumerable: true, get: function () { return error_1.SigningNotSupportedForAccountError; } });
29
- Object.defineProperty(exports, "SignMessageNotSupportedByAccountError", { enumerable: true, get: function () { return error_1.SignMessageNotSupportedByAccountError; } });
30
41
  Object.defineProperty(exports, "SmartSessionsNotEnabledError", { enumerable: true, get: function () { return error_1.SmartSessionsNotEnabledError; } });
42
+ Object.defineProperty(exports, "WalletClientNoConnectedAccountError", { enumerable: true, get: function () { return error_1.WalletClientNoConnectedAccountError; } });
31
43
  const kernel_1 = require("./kernel");
32
44
  const nexus_1 = require("./nexus");
33
45
  const safe_1 = require("./safe");
46
+ const common_1 = require("./signing/common");
47
+ const message_1 = require("./signing/message");
48
+ const typedData_1 = require("./signing/typedData");
49
+ const startale_1 = require("./startale");
34
50
  const utils_1 = require("./utils");
35
51
  function getDeployArgs(config) {
36
52
  const account = getAccountProvider(config);
@@ -44,12 +60,24 @@ function getDeployArgs(config) {
44
60
  case 'kernel': {
45
61
  return (0, kernel_1.getDeployArgs)(config);
46
62
  }
63
+ case 'startale': {
64
+ return (0, startale_1.getDeployArgs)(config);
65
+ }
66
+ case 'eoa': {
67
+ throw new Error('EOA accounts do not have deploy args');
68
+ }
47
69
  }
48
70
  }
49
71
  function getInitCode(config) {
50
72
  if (is7702(config)) {
51
73
  return undefined;
52
74
  }
75
+ else if (config.account?.type === 'eoa') {
76
+ return undefined;
77
+ }
78
+ else if (config.initData) {
79
+ return config.initData;
80
+ }
53
81
  else {
54
82
  const { factory, factoryData } = getDeployArgs(config);
55
83
  if (!factory || !factoryData) {
@@ -61,6 +89,45 @@ function getInitCode(config) {
61
89
  };
62
90
  }
63
91
  }
92
+ async function signEip7702InitData(config) {
93
+ const eoa = config.eoa;
94
+ if (!eoa) {
95
+ throw new error_1.Eip7702AccountMustHaveEoaError();
96
+ }
97
+ const account = getAccountProvider(config);
98
+ switch (account.type) {
99
+ case 'nexus': {
100
+ return await (0, nexus_1.signEip7702InitData)(config, eoa);
101
+ }
102
+ case 'eoa': {
103
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
104
+ }
105
+ case 'safe':
106
+ case 'kernel':
107
+ case 'startale': {
108
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
109
+ }
110
+ default: {
111
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
112
+ }
113
+ }
114
+ }
115
+ async function getEip7702InitCall(config, signature) {
116
+ const account = getAccountProvider(config);
117
+ switch (account.type) {
118
+ case 'nexus': {
119
+ return await (0, nexus_1.getEip7702InitCall)(config, signature);
120
+ }
121
+ case 'safe':
122
+ case 'kernel':
123
+ case 'startale': {
124
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
125
+ }
126
+ default: {
127
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
128
+ }
129
+ }
130
+ }
64
131
  function getModuleInstallationCalls(config, module) {
65
132
  const address = getAddress(config);
66
133
  function getInstallData() {
@@ -75,6 +142,12 @@ function getModuleInstallationCalls(config, module) {
75
142
  case 'kernel': {
76
143
  return (0, kernel_1.getInstallData)(module);
77
144
  }
145
+ case 'startale': {
146
+ return [(0, startale_1.getInstallData)(module)];
147
+ }
148
+ case 'eoa': {
149
+ throw new error_1.ModuleInstallationNotSupportedError(account.type);
150
+ }
78
151
  }
79
152
  }
80
153
  const installData = getInstallData();
@@ -132,27 +205,96 @@ function getAddress(config) {
132
205
  case 'kernel': {
133
206
  return (0, kernel_1.getAddress)(config);
134
207
  }
208
+ case 'startale': {
209
+ return (0, startale_1.getAddress)(config);
210
+ }
211
+ case 'eoa': {
212
+ if (!config.eoa) {
213
+ throw new error_1.AccountError({
214
+ message: 'EOA account must have an EOA configured',
215
+ });
216
+ }
217
+ return config.eoa.address;
218
+ }
219
+ }
220
+ }
221
+ function checkAddress(config) {
222
+ if (!config.initData) {
223
+ return true;
135
224
  }
225
+ return (config.initData.address.toLowerCase() === getAddress(config).toLowerCase());
136
226
  }
137
227
  // Signs and packs a signature to be EIP-1271 compatible
138
228
  async function getPackedSignature(config, signers, chain, validator, hash, transformSignature = (signature) => signature) {
139
- signers = signers ?? convertOwnerSetToSignerSet(config.owners);
140
- const signFn = (hash) => sign(signers, chain, hash);
229
+ if (config.account?.type === 'eoa') {
230
+ throw new error_1.EoaSigningNotSupportedError('packed signatures');
231
+ }
232
+ signers = signers ?? (0, common_1.convertOwnerSetToSignerSet)(config.owners);
233
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, false);
141
234
  const account = getAccountProvider(config);
142
235
  const address = getAddress(config);
143
236
  switch (account.type) {
144
237
  case 'safe': {
145
- return (0, safe_1.getPackedSignature)(signFn, hash, validator, transformSignature);
238
+ const signature = await signFn(hash);
239
+ return (0, safe_1.packSignature)(signature, validator, transformSignature);
146
240
  }
147
241
  case 'nexus': {
148
- return (0, nexus_1.getPackedSignature)(signFn, hash, validator, transformSignature);
242
+ const signature = await signFn(hash);
243
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
244
+ return (0, nexus_1.packSignature)(signature, validator, transformSignature, defaultValidatorAddress);
149
245
  }
150
246
  case 'kernel': {
151
- return (0, kernel_1.getPackedSignature)(signFn, hash, validator, address, transformSignature);
247
+ const signature = await signFn((0, kernel_1.wrapMessageHash)(hash, address));
248
+ return (0, kernel_1.packSignature)(signature, validator, transformSignature);
249
+ }
250
+ case 'startale': {
251
+ const signature = await signFn(hash);
252
+ return (0, startale_1.packSignature)(signature, validator, transformSignature);
253
+ }
254
+ default: {
255
+ throw new Error(`Unsupported account type: ${account.type}`);
152
256
  }
153
257
  }
154
258
  }
155
- async function isDeployed(chain, config) {
259
+ // Signs and packs a signature to be EIP-1271 compatible
260
+ async function getTypedDataPackedSignature(config, signers, chain, validator, parameters, transformSignature = (signature) => signature) {
261
+ if (config.account?.type === 'eoa') {
262
+ throw new error_1.EoaSigningNotSupportedError('packed signatures');
263
+ }
264
+ const address = getAddress(config);
265
+ signers = signers ?? (0, common_1.convertOwnerSetToSignerSet)(config.owners);
266
+ const signFn = (parameters) => (0, typedData_1.sign)(signers, chain, address, parameters);
267
+ const account = getAccountProvider(config);
268
+ switch (account.type) {
269
+ case 'safe': {
270
+ const signature = await signFn(parameters);
271
+ return (0, safe_1.packSignature)(signature, validator, transformSignature);
272
+ }
273
+ case 'nexus': {
274
+ const signature = await signFn(parameters);
275
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
276
+ return (0, nexus_1.packSignature)(signature, validator, transformSignature, defaultValidatorAddress);
277
+ }
278
+ case 'kernel': {
279
+ const address = getAddress(config);
280
+ const signMessageFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, false);
281
+ const signature = await signMessageFn((0, kernel_1.wrapMessageHash)((0, viem_1.hashTypedData)(parameters), address));
282
+ return (0, kernel_1.packSignature)(signature, validator, transformSignature);
283
+ }
284
+ case 'startale': {
285
+ const signature = await signFn(parameters);
286
+ return (0, startale_1.packSignature)(signature, validator, transformSignature);
287
+ }
288
+ default: {
289
+ throw new Error(`Unsupported account type: ${account.type}`);
290
+ }
291
+ }
292
+ }
293
+ async function isDeployed(config, chain) {
294
+ const account = getAccountProvider(config);
295
+ if (account.type === 'eoa') {
296
+ return true;
297
+ }
156
298
  const publicClient = (0, viem_1.createPublicClient)({
157
299
  chain: chain,
158
300
  transport: (0, utils_1.createTransport)(chain, config.provider),
@@ -171,10 +313,89 @@ async function isDeployed(chain, config) {
171
313
  return (0, viem_1.size)(code) > 0;
172
314
  }
173
315
  async function deploy(config, chain, session) {
174
- await deployWithIntent(chain, config);
316
+ const account = getAccountProvider(config);
317
+ if (account.type === 'eoa') {
318
+ return false;
319
+ }
320
+ const deployed = await isDeployed(config, chain);
321
+ if (deployed) {
322
+ return false;
323
+ }
324
+ const asUserOp = config.initData && !config.initData.intentExecutorInstalled;
325
+ if (asUserOp) {
326
+ await deployWithBundler(chain, config);
327
+ }
328
+ else {
329
+ await deployWithIntent(chain, config);
330
+ }
175
331
  if (session) {
176
332
  await (0, smart_session_1.enableSmartSession)(chain, config, session);
177
333
  }
334
+ return true;
335
+ }
336
+ // Installs the missing modules
337
+ // Checks if the provided modules are already installed
338
+ // Useful for existing (already deployed) accounts
339
+ async function setup(config, chain) {
340
+ const account = getAccountProvider(config);
341
+ if (account.type === 'eoa') {
342
+ return false;
343
+ }
344
+ const modules = (0, modules_1.getSetup)(config);
345
+ const publicClient = (0, viem_1.createPublicClient)({
346
+ chain,
347
+ transport: (0, utils_1.createTransport)(chain, config.provider),
348
+ });
349
+ const address = getAddress(config);
350
+ const allModules = [
351
+ ...modules.validators,
352
+ ...modules.executors,
353
+ ...modules.fallbacks,
354
+ ...modules.hooks,
355
+ ];
356
+ // Check if the modules are already installed
357
+ const installedResults = await publicClient.multicall({
358
+ contracts: allModules.map((module) => ({
359
+ address: address,
360
+ abi: [
361
+ {
362
+ type: 'function',
363
+ name: 'isModuleInstalled',
364
+ inputs: [
365
+ { type: 'uint256', name: 'moduleTypeId' },
366
+ { type: 'address', name: 'module' },
367
+ { type: 'bytes', name: 'additionalContext' },
368
+ ],
369
+ outputs: [{ type: 'bool', name: 'isInstalled' }],
370
+ stateMutability: 'view',
371
+ },
372
+ ],
373
+ functionName: 'isModuleInstalled',
374
+ args: [module.type, module.address, module.additionalContext],
375
+ })),
376
+ });
377
+ const isInstalled = installedResults.map((result) => result.result);
378
+ const modulesToInstall = allModules.filter((_, index) => !isInstalled[index]);
379
+ if (modulesToInstall.length === 0) {
380
+ // Nothing to install
381
+ return false;
382
+ }
383
+ const calls = [];
384
+ for (const module of modulesToInstall) {
385
+ calls.push(...getModuleInstallationCalls(config, module));
386
+ }
387
+ // Select the transaction infra layer based on the intent executor status
388
+ const intentExecutor = (0, modules_1.getIntentExecutor)(config);
389
+ const hasIntentExecutor = modulesToInstall.every((module) => module.address !== intentExecutor.address);
390
+ let result;
391
+ if (hasIntentExecutor) {
392
+ result = await (0, execution_1.sendTransactionInternal)(config, [chain], chain, calls, {});
393
+ }
394
+ else {
395
+ result = await (0, execution_1.sendUserOperationInternal)(config, chain, calls);
396
+ }
397
+ await (0, execution_1.waitForExecution)(config, result, true);
398
+ return true;
178
399
  }
179
400
  async function deployWithIntent(chain, config) {
180
401
  const publicClient = (0, viem_1.createPublicClient)({
@@ -187,7 +408,7 @@ async function deployWithIntent(chain, config) {
187
408
  // Already deployed
188
409
  return;
189
410
  }
190
- await (0, execution_1.sendTransaction)(config, {
411
+ const result = await (0, execution_1.sendTransaction)(config, {
191
412
  targetChain: chain,
192
413
  calls: [
193
414
  {
@@ -196,23 +417,80 @@ async function deployWithIntent(chain, config) {
196
417
  },
197
418
  ],
198
419
  });
420
+ await (0, execution_1.waitForExecution)(config, result, true);
421
+ }
422
+ async function deployWithBundler(chain, config) {
423
+ const publicClient = (0, viem_1.createPublicClient)({
424
+ chain,
425
+ transport: (0, utils_1.createTransport)(chain, config.provider),
426
+ });
427
+ const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
428
+ const smartAccount = await getSmartAccount(config, publicClient, chain);
429
+ const { factory, factoryData } = getDeployArgs(config);
430
+ const opHash = await bundlerClient.sendUserOperation({
431
+ account: smartAccount,
432
+ factory,
433
+ factoryData,
434
+ calls: [
435
+ {
436
+ to: viem_1.zeroAddress,
437
+ value: 0n,
438
+ data: '0x',
439
+ },
440
+ ],
441
+ });
442
+ await bundlerClient.waitForUserOperationReceipt({
443
+ hash: opHash,
444
+ });
445
+ }
446
+ async function toErc6492Signature(config, signature, chain) {
447
+ const deployed = await isDeployed(config, chain);
448
+ if (deployed) {
449
+ return signature;
450
+ }
451
+ // Account is not deployed, use ERC-6492
452
+ const initCode = getInitCode(config);
453
+ if (!initCode) {
454
+ throw new error_1.FactoryArgsNotAvailableError();
455
+ }
456
+ const { factory, factoryData } = initCode;
457
+ const magicBytes = '0x6492649264926492649264926492649264926492649264926492649264926492';
458
+ return (0, viem_1.concat)([
459
+ (0, viem_1.encodeAbiParameters)([
460
+ { name: 'create2Factory', type: 'address' },
461
+ { name: 'factoryCalldata', type: 'bytes' },
462
+ { name: 'originalERC1271Signature', type: 'bytes' },
463
+ ], [factory, factoryData, signature]),
464
+ magicBytes,
465
+ ]);
199
466
  }
200
467
  async function getSmartAccount(config, client, chain) {
468
+ // EOA accounts don't need smart account functionality
469
+ if (config.account?.type === 'eoa') {
470
+ throw new Error('getSmartAccount is not supported for EOA accounts');
471
+ }
472
+ if (!config.owners) {
473
+ throw new error_1.OwnersFieldRequiredError();
474
+ }
201
475
  const account = getAccountProvider(config);
202
476
  const address = getAddress(config);
203
477
  const ownerValidator = (0, validators_1.getOwnerValidator)(config);
204
- const signers = convertOwnerSetToSignerSet(config.owners);
205
- const signFn = (hash) => sign(signers, chain, hash);
478
+ const signers = (0, common_1.convertOwnerSetToSignerSet)(config.owners);
479
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, true);
206
480
  switch (account.type) {
207
481
  case 'safe': {
208
482
  return (0, safe_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
209
483
  }
210
484
  case 'nexus': {
211
- return (0, nexus_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
485
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
486
+ return (0, nexus_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn, defaultValidatorAddress);
212
487
  }
213
488
  case 'kernel': {
214
489
  return (0, kernel_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
215
490
  }
491
+ case 'startale': {
492
+ return (0, startale_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
493
+ }
216
494
  }
217
495
  }
218
496
  async function getSmartSessionSmartAccount(config, client, chain, session, enableData) {
@@ -226,18 +504,22 @@ async function getSmartSessionSmartAccount(config, client, chain, session, enabl
226
504
  session,
227
505
  enableData: enableData || undefined,
228
506
  };
229
- const signFn = (hash) => sign(signers, chain, hash);
507
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, true);
230
508
  const account = getAccountProvider(config);
231
509
  switch (account.type) {
232
510
  case 'safe': {
233
511
  return (0, safe_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
234
512
  }
235
513
  case 'nexus': {
236
- return (0, nexus_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
514
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
515
+ return (0, nexus_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn, defaultValidatorAddress);
237
516
  }
238
517
  case 'kernel': {
239
518
  return (0, kernel_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
240
519
  }
520
+ case 'startale': {
521
+ return (0, startale_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, enableData, signFn);
522
+ }
241
523
  }
242
524
  }
243
525
  async function getGuardianSmartAccount(config, client, chain, guardians) {
@@ -251,101 +533,27 @@ async function getGuardianSmartAccount(config, client, chain, guardians) {
251
533
  type: 'guardians',
252
534
  guardians: accounts,
253
535
  };
254
- const signFn = (hash) => sign(signers, chain, hash);
536
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, true);
255
537
  const account = getAccountProvider(config);
256
538
  switch (account.type) {
257
539
  case 'safe': {
258
540
  return (0, safe_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
259
541
  }
260
542
  case 'nexus': {
261
- return (0, nexus_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
543
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
544
+ return (0, nexus_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn, defaultValidatorAddress);
262
545
  }
263
546
  case 'kernel': {
264
547
  return (0, kernel_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
265
548
  }
266
- }
267
- }
268
- async function sign(signers, chain, hash) {
269
- switch (signers.type) {
270
- case 'owner': {
271
- switch (signers.kind) {
272
- case 'ecdsa': {
273
- const signatures = await Promise.all(signers.accounts.map((account) => signEcdsa(account, hash)));
274
- return (0, viem_1.concat)(signatures);
275
- }
276
- case 'passkey': {
277
- return await signPasskey(signers.account, chain, hash);
278
- }
279
- case 'multi-factor': {
280
- const signatures = await Promise.all(signers.validators.map(async (validator) => {
281
- if (validator === null) {
282
- return '0x';
283
- }
284
- const validatorSigners = convertOwnerSetToSignerSet(validator);
285
- return sign(validatorSigners, chain, hash);
286
- }));
287
- const data = (0, viem_1.encodeAbiParameters)([
288
- {
289
- components: [
290
- {
291
- internalType: 'bytes32',
292
- name: 'packedValidatorAndId',
293
- type: 'bytes32',
294
- },
295
- { internalType: 'bytes', name: 'data', type: 'bytes' },
296
- ],
297
- name: 'validators',
298
- type: 'tuple[]',
299
- },
300
- ], [
301
- signers.validators.map((validator, index) => {
302
- const validatorModule = (0, core_1.getValidator)(validator);
303
- return {
304
- packedValidatorAndId: (0, viem_1.concat)([
305
- (0, viem_1.pad)((0, viem_1.toHex)(validator.id), {
306
- size: 12,
307
- }),
308
- validatorModule.address,
309
- ]),
310
- data: signatures[index],
311
- };
312
- }),
313
- ]);
314
- return data;
315
- }
316
- default: {
317
- throw new Error('Unsupported owner kind');
318
- }
319
- }
320
- }
321
- case 'session': {
322
- const sessionSigners = convertOwnerSetToSignerSet(signers.session.owners);
323
- return sign(sessionSigners, chain, hash);
549
+ case 'startale': {
550
+ return (0, startale_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
324
551
  }
325
- case 'guardians': {
326
- const signatures = await Promise.all(signers.guardians.map((account) => signEcdsa(account, hash)));
327
- return (0, viem_1.concat)(signatures);
328
- }
329
- }
330
- }
331
- async function signEcdsa(account, hash) {
332
- if (!account.signMessage) {
333
- throw new error_1.SigningNotSupportedForAccountError();
334
552
  }
335
- return await account.signMessage({ message: { raw: hash } });
336
- }
337
- async function signPasskey(account, chain, hash) {
338
- const { webauthn, signature } = await account.sign({ hash });
339
- const usePrecompiled = (0, modules_1.isRip7212SupportedNetwork)(chain);
340
- const encodedSignature = (0, modules_1.getWebauthnValidatorSignature)({
341
- webauthn,
342
- signature,
343
- usePrecompiled,
344
- });
345
- return encodedSignature;
346
553
  }
347
554
  function is7702(config) {
348
- return config.eoa !== undefined;
555
+ const account = getAccountProvider(config);
556
+ return account.type !== 'eoa' && config.eoa !== undefined;
349
557
  }
350
558
  function getAccountProvider(config) {
351
559
  if (config.account) {
@@ -355,45 +563,3 @@ function getAccountProvider(config) {
355
563
  type: 'nexus',
356
564
  };
357
565
  }
358
- function convertOwnerSetToSignerSet(owners) {
359
- switch (owners.type) {
360
- case 'ecdsa': {
361
- return {
362
- type: 'owner',
363
- kind: 'ecdsa',
364
- accounts: owners.accounts,
365
- };
366
- }
367
- case 'passkey': {
368
- return {
369
- type: 'owner',
370
- kind: 'passkey',
371
- account: owners.account,
372
- };
373
- }
374
- case 'multi-factor': {
375
- return {
376
- type: 'owner',
377
- kind: 'multi-factor',
378
- validators: owners.validators.map((validator, index) => {
379
- switch (validator.type) {
380
- case 'ecdsa': {
381
- return {
382
- type: 'ecdsa',
383
- id: index,
384
- accounts: validator.accounts,
385
- };
386
- }
387
- case 'passkey': {
388
- return {
389
- type: 'passkey',
390
- id: index,
391
- account: validator.account,
392
- };
393
- }
394
- }
395
- }),
396
- };
397
- }
398
- }
399
- }
@@ -12,19 +12,17 @@ const _1 = require(".");
12
12
  accounts: [consts_1.accountA, consts_1.accountB],
13
13
  threshold: 1,
14
14
  },
15
- rhinestoneApiKey: consts_1.MOCK_API_KEY,
16
15
  });
17
- (0, vitest_1.expect)(address).toEqual('0x0cd1c38d4cdffdbbd4ac192babf70110ad250668');
16
+ (0, vitest_1.expect)(address).toEqual('0x0681de31e060b384F0b08A3bAC99E9bDFf302474');
18
17
  });
19
18
  (0, vitest_1.test)('Safe, passkey owner with a session', () => {
20
19
  const address = (0, _1.getAddress)({
21
20
  owners: {
22
21
  type: 'passkey',
23
- account: consts_1.passkeyAccount,
22
+ accounts: [consts_1.passkeyAccount],
24
23
  },
25
- rhinestoneApiKey: consts_1.MOCK_API_KEY,
26
24
  });
27
- (0, vitest_1.expect)(address).toEqual('0x35e1c3f1ded30246aa2ca361342c3ee0d0749293');
25
+ (0, vitest_1.expect)(address).toEqual('0x894b88C04B4DE6AbDdcE81E8bdc91927E37d6ceD');
28
26
  });
29
27
  });
30
28
  (0, vitest_1.describe)('Sign', () => {
@@ -0,0 +1,5 @@
1
+ import { type Chain, type Transport } from 'viem';
2
+ import type { ProviderConfig } from '../../types';
3
+ declare function createTransport(chain: Chain, provider?: ProviderConfig): Transport;
4
+ export { createTransport };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../accounts/json-rpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAQ,KAAK,SAAS,EAAE,MAAM,MAAM,CAAA;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGjD,iBAAS,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,SAAS,CAc3E;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTransport = createTransport;
4
+ const viem_1 = require("viem");
5
+ const providers_1 = require("./providers");
6
+ function createTransport(chain, provider) {
7
+ if (!provider) {
8
+ return (0, viem_1.http)();
9
+ }
10
+ switch (provider.type) {
11
+ case 'alchemy': {
12
+ const alchemyUrl = (0, providers_1.getAlchemyUrl)(chain.id, provider.apiKey);
13
+ return (0, viem_1.http)(alchemyUrl);
14
+ }
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../../accounts/json-rpc/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
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 index_1 = require("./index");
6
+ (0, vitest_1.describe)('JSON-RPC', () => {
7
+ (0, vitest_1.describe)('createTransport', () => {
8
+ (0, vitest_1.test)('Alchemy', () => {
9
+ const transport = (0, index_1.createTransport)(chains_1.base, {
10
+ type: 'alchemy',
11
+ apiKey: '123',
12
+ });
13
+ (0, vitest_1.expect)(transport).toBeDefined();
14
+ });
15
+ });
16
+ });