@rhinestone/sdk 0.0.0-dev-20260204114155

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 (206) hide show
  1. package/README.md +83 -0
  2. package/dist/src/accounts/error.d.ts +114 -0
  3. package/dist/src/accounts/error.d.ts.map +1 -0
  4. package/dist/src/accounts/error.js +174 -0
  5. package/dist/src/accounts/index.d.ts +48 -0
  6. package/dist/src/accounts/index.d.ts.map +1 -0
  7. package/dist/src/accounts/index.js +643 -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 +33 -0
  11. package/dist/src/accounts/json-rpc/index.d.ts +5 -0
  12. package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
  13. package/dist/src/accounts/json-rpc/index.js +20 -0
  14. package/dist/src/accounts/json-rpc/index.test.d.ts +2 -0
  15. package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
  16. package/dist/src/accounts/json-rpc/index.test.js +33 -0
  17. package/dist/src/accounts/json-rpc/providers.d.ts +5 -0
  18. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
  19. package/dist/src/accounts/json-rpc/providers.js +22 -0
  20. package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
  21. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
  22. package/dist/src/accounts/json-rpc/providers.test.js +43 -0
  23. package/dist/src/accounts/kernel.d.ts +27 -0
  24. package/dist/src/accounts/kernel.d.ts.map +1 -0
  25. package/dist/src/accounts/kernel.js +281 -0
  26. package/dist/src/accounts/kernel.test.d.ts +2 -0
  27. package/dist/src/accounts/kernel.test.d.ts.map +1 -0
  28. package/dist/src/accounts/kernel.test.js +132 -0
  29. package/dist/src/accounts/nexus.d.ts +33 -0
  30. package/dist/src/accounts/nexus.d.ts.map +1 -0
  31. package/dist/src/accounts/nexus.js +455 -0
  32. package/dist/src/accounts/nexus.test.d.ts +2 -0
  33. package/dist/src/accounts/nexus.test.d.ts.map +1 -0
  34. package/dist/src/accounts/nexus.test.js +118 -0
  35. package/dist/src/accounts/passport.d.ts +9 -0
  36. package/dist/src/accounts/passport.d.ts.map +1 -0
  37. package/dist/src/accounts/passport.js +82 -0
  38. package/dist/src/accounts/safe.d.ts +33 -0
  39. package/dist/src/accounts/safe.d.ts.map +1 -0
  40. package/dist/src/accounts/safe.js +349 -0
  41. package/dist/src/accounts/safe.test.d.ts +2 -0
  42. package/dist/src/accounts/safe.test.d.ts.map +1 -0
  43. package/dist/src/accounts/safe.test.js +118 -0
  44. package/dist/src/accounts/signing/common.d.ts +27 -0
  45. package/dist/src/accounts/signing/common.d.ts.map +1 -0
  46. package/dist/src/accounts/signing/common.js +190 -0
  47. package/dist/src/accounts/signing/message.d.ts +5 -0
  48. package/dist/src/accounts/signing/message.d.ts.map +1 -0
  49. package/dist/src/accounts/signing/message.js +47 -0
  50. package/dist/src/accounts/signing/passkeys.d.ts +36 -0
  51. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
  52. package/dist/src/accounts/signing/passkeys.js +125 -0
  53. package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
  54. package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
  55. package/dist/src/accounts/signing/passkeys.test.js +88 -0
  56. package/dist/src/accounts/signing/typedData.d.ts +5 -0
  57. package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
  58. package/dist/src/accounts/signing/typedData.js +35 -0
  59. package/dist/src/accounts/startale.d.ts +25 -0
  60. package/dist/src/accounts/startale.d.ts.map +1 -0
  61. package/dist/src/accounts/startale.js +112 -0
  62. package/dist/src/accounts/startale.test.d.ts +2 -0
  63. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  64. package/dist/src/accounts/startale.test.js +92 -0
  65. package/dist/src/accounts/utils.d.ts +33 -0
  66. package/dist/src/accounts/utils.d.ts.map +1 -0
  67. package/dist/src/accounts/utils.js +208 -0
  68. package/dist/src/accounts/utils.test.d.ts +2 -0
  69. package/dist/src/accounts/utils.test.d.ts.map +1 -0
  70. package/dist/src/accounts/utils.test.js +49 -0
  71. package/dist/src/accounts/walletClient.d.ts +34 -0
  72. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  73. package/dist/src/accounts/walletClient.js +121 -0
  74. package/dist/src/actions/compact.d.ts +15 -0
  75. package/dist/src/actions/compact.d.ts.map +1 -0
  76. package/dist/src/actions/compact.js +213 -0
  77. package/dist/src/actions/deployment.d.ts +19 -0
  78. package/dist/src/actions/deployment.d.ts.map +1 -0
  79. package/dist/src/actions/deployment.js +78 -0
  80. package/dist/src/actions/ecdsa.d.ts +35 -0
  81. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  82. package/dist/src/actions/ecdsa.js +114 -0
  83. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  84. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  85. package/dist/src/actions/ecdsa.test.js +99 -0
  86. package/dist/src/actions/index.d.ts +17 -0
  87. package/dist/src/actions/index.d.ts.map +1 -0
  88. package/dist/src/actions/index.js +53 -0
  89. package/dist/src/actions/mfa.d.ts +37 -0
  90. package/dist/src/actions/mfa.d.ts.map +1 -0
  91. package/dist/src/actions/mfa.js +133 -0
  92. package/dist/src/actions/passkeys.d.ts +37 -0
  93. package/dist/src/actions/passkeys.d.ts.map +1 -0
  94. package/dist/src/actions/passkeys.js +129 -0
  95. package/dist/src/actions/passkeys.test.d.ts +2 -0
  96. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  97. package/dist/src/actions/passkeys.test.js +54 -0
  98. package/dist/src/actions/recovery.d.ts +33 -0
  99. package/dist/src/actions/recovery.d.ts.map +1 -0
  100. package/dist/src/actions/recovery.js +193 -0
  101. package/dist/src/actions/recovery.test.d.ts +2 -0
  102. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  103. package/dist/src/actions/recovery.test.js +168 -0
  104. package/dist/src/actions/smart-sessions.d.ts +23 -0
  105. package/dist/src/actions/smart-sessions.d.ts.map +1 -0
  106. package/dist/src/actions/smart-sessions.js +52 -0
  107. package/dist/src/errors/index.d.ts +5 -0
  108. package/dist/src/errors/index.d.ts.map +1 -0
  109. package/dist/src/errors/index.js +54 -0
  110. package/dist/src/execution/compact.d.ts +148 -0
  111. package/dist/src/execution/compact.d.ts.map +1 -0
  112. package/dist/src/execution/compact.js +120 -0
  113. package/dist/src/execution/error.d.ts +55 -0
  114. package/dist/src/execution/error.d.ts.map +1 -0
  115. package/dist/src/execution/error.js +78 -0
  116. package/dist/src/execution/index.d.ts +41 -0
  117. package/dist/src/execution/index.d.ts.map +1 -0
  118. package/dist/src/execution/index.js +230 -0
  119. package/dist/src/execution/permit2.d.ts +143 -0
  120. package/dist/src/execution/permit2.d.ts.map +1 -0
  121. package/dist/src/execution/permit2.js +285 -0
  122. package/dist/src/execution/singleChainOps.d.ts +40 -0
  123. package/dist/src/execution/singleChainOps.d.ts.map +1 -0
  124. package/dist/src/execution/singleChainOps.js +46 -0
  125. package/dist/src/execution/types.d.ts +36 -0
  126. package/dist/src/execution/types.d.ts.map +1 -0
  127. package/dist/src/execution/types.js +2 -0
  128. package/dist/src/execution/utils.d.ts +87 -0
  129. package/dist/src/execution/utils.d.ts.map +1 -0
  130. package/dist/src/execution/utils.js +783 -0
  131. package/dist/src/index.d.ts +76 -0
  132. package/dist/src/index.d.ts.map +1 -0
  133. package/dist/src/index.js +319 -0
  134. package/dist/src/modules/abi/smart-session-emissary.d.ts +696 -0
  135. package/dist/src/modules/abi/smart-session-emissary.d.ts.map +1 -0
  136. package/dist/src/modules/abi/smart-session-emissary.js +565 -0
  137. package/dist/src/modules/abi/smart-sessions.d.ts +104 -0
  138. package/dist/src/modules/abi/smart-sessions.d.ts.map +1 -0
  139. package/dist/src/modules/abi/smart-sessions.js +131 -0
  140. package/dist/src/modules/chain-abstraction.d.ts +5 -0
  141. package/dist/src/modules/chain-abstraction.d.ts.map +1 -0
  142. package/dist/src/modules/chain-abstraction.js +7 -0
  143. package/dist/src/modules/common.d.ts +30 -0
  144. package/dist/src/modules/common.d.ts.map +1 -0
  145. package/dist/src/modules/common.js +42 -0
  146. package/dist/src/modules/index.d.ts +11 -0
  147. package/dist/src/modules/index.d.ts.map +1 -0
  148. package/dist/src/modules/index.js +97 -0
  149. package/dist/src/modules/index.test.d.ts +2 -0
  150. package/dist/src/modules/index.test.d.ts.map +1 -0
  151. package/dist/src/modules/index.test.js +81 -0
  152. package/dist/src/modules/legacy.d.ts +10 -0
  153. package/dist/src/modules/legacy.d.ts.map +1 -0
  154. package/dist/src/modules/legacy.js +65 -0
  155. package/dist/src/modules/read.d.ts +9 -0
  156. package/dist/src/modules/read.d.ts.map +1 -0
  157. package/dist/src/modules/read.js +125 -0
  158. package/dist/src/modules/validators/core.d.ts +31 -0
  159. package/dist/src/modules/validators/core.d.ts.map +1 -0
  160. package/dist/src/modules/validators/core.js +284 -0
  161. package/dist/src/modules/validators/core.test.d.ts +2 -0
  162. package/dist/src/modules/validators/core.test.d.ts.map +1 -0
  163. package/dist/src/modules/validators/core.test.js +101 -0
  164. package/dist/src/modules/validators/index.d.ts +4 -0
  165. package/dist/src/modules/validators/index.d.ts.map +1 -0
  166. package/dist/src/modules/validators/index.js +10 -0
  167. package/dist/src/modules/validators/smart-sessions.d.ts +185 -0
  168. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -0
  169. package/dist/src/modules/validators/smart-sessions.js +624 -0
  170. package/dist/src/orchestrator/client.d.ts +22 -0
  171. package/dist/src/orchestrator/client.d.ts.map +1 -0
  172. package/dist/src/orchestrator/client.js +360 -0
  173. package/dist/src/orchestrator/consts.d.ts +5 -0
  174. package/dist/src/orchestrator/consts.d.ts.map +1 -0
  175. package/dist/src/orchestrator/consts.js +9 -0
  176. package/dist/src/orchestrator/error.d.ts +242 -0
  177. package/dist/src/orchestrator/error.d.ts.map +1 -0
  178. package/dist/src/orchestrator/error.js +283 -0
  179. package/dist/src/orchestrator/index.d.ts +10 -0
  180. package/dist/src/orchestrator/index.d.ts.map +1 -0
  181. package/dist/src/orchestrator/index.js +58 -0
  182. package/dist/src/orchestrator/registry.d.ts +22 -0
  183. package/dist/src/orchestrator/registry.d.ts.map +1 -0
  184. package/dist/src/orchestrator/registry.js +116 -0
  185. package/dist/src/orchestrator/registry.test.d.ts +2 -0
  186. package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
  187. package/dist/src/orchestrator/registry.test.js +154 -0
  188. package/dist/src/orchestrator/types.d.ts +322 -0
  189. package/dist/src/orchestrator/types.d.ts.map +1 -0
  190. package/dist/src/orchestrator/types.js +31 -0
  191. package/dist/src/orchestrator/utils.d.ts +3 -0
  192. package/dist/src/orchestrator/utils.d.ts.map +1 -0
  193. package/dist/src/orchestrator/utils.js +24 -0
  194. package/dist/src/types.d.ts +296 -0
  195. package/dist/src/types.d.ts.map +1 -0
  196. package/dist/src/types.js +2 -0
  197. package/dist/src/utils/index.d.ts +26 -0
  198. package/dist/src/utils/index.d.ts.map +1 -0
  199. package/dist/src/utils/index.js +63 -0
  200. package/dist/test/consts.d.ts +10 -0
  201. package/dist/test/consts.d.ts.map +1 -0
  202. package/dist/test/consts.js +22 -0
  203. package/dist/test/utils/utils.d.ts +5 -0
  204. package/dist/test/utils/utils.d.ts.map +1 -0
  205. package/dist/test/utils/utils.js +20 -0
  206. package/package.json +161 -0
@@ -0,0 +1,643 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletClientNoConnectedAccountError = exports.SmartSessionsNotEnabledError = exports.SigningNotSupportedForAccountError = exports.OwnersFieldRequiredError = exports.ModuleInstallationNotSupportedError = exports.FactoryArgsNotAvailableError = exports.ExistingEip7702AccountsNotSupportedError = exports.EoaSigningNotSupportedError = exports.EoaSigningMethodNotConfiguredError = exports.EoaAccountMustHaveAccountError = exports.Eip7702NotSupportedForAccountError = exports.Eip7702AccountMustHaveEoaError = exports.Eip712DomainNotAvailableError = exports.AccountConfigurationNotSupportedError = exports.AccountError = exports.isAccountError = void 0;
4
+ exports.getEip712Domain = getEip712Domain;
5
+ exports.getModuleInstallationCalls = getModuleInstallationCalls;
6
+ exports.getModuleUninstallationCalls = getModuleUninstallationCalls;
7
+ exports.getAddress = getAddress;
8
+ exports.checkAddress = checkAddress;
9
+ exports.getAccountProvider = getAccountProvider;
10
+ exports.getInitCode = getInitCode;
11
+ exports.getV0InitCode = getV0InitCode;
12
+ exports.signEip7702InitData = signEip7702InitData;
13
+ exports.getEip7702InitCall = getEip7702InitCall;
14
+ exports.is7702 = is7702;
15
+ exports.isDeployed = isDeployed;
16
+ exports.deploy = deploy;
17
+ exports.setup = setup;
18
+ exports.toErc6492Signature = toErc6492Signature;
19
+ exports.getSmartAccount = getSmartAccount;
20
+ exports.getGuardianSmartAccount = getGuardianSmartAccount;
21
+ exports.getEip1271Signature = getEip1271Signature;
22
+ exports.getEmissarySignature = getEmissarySignature;
23
+ exports.getTypedDataPackedSignature = getTypedDataPackedSignature;
24
+ const viem_1 = require("viem");
25
+ const execution_1 = require("../execution");
26
+ const modules_1 = require("../modules");
27
+ const validators_1 = require("../modules/validators");
28
+ const core_1 = require("../modules/validators/core");
29
+ const error_1 = require("./error");
30
+ Object.defineProperty(exports, "AccountConfigurationNotSupportedError", { enumerable: true, get: function () { return error_1.AccountConfigurationNotSupportedError; } });
31
+ Object.defineProperty(exports, "AccountError", { enumerable: true, get: function () { return error_1.AccountError; } });
32
+ Object.defineProperty(exports, "Eip712DomainNotAvailableError", { enumerable: true, get: function () { return error_1.Eip712DomainNotAvailableError; } });
33
+ Object.defineProperty(exports, "Eip7702AccountMustHaveEoaError", { enumerable: true, get: function () { return error_1.Eip7702AccountMustHaveEoaError; } });
34
+ Object.defineProperty(exports, "Eip7702NotSupportedForAccountError", { enumerable: true, get: function () { return error_1.Eip7702NotSupportedForAccountError; } });
35
+ Object.defineProperty(exports, "EoaAccountMustHaveAccountError", { enumerable: true, get: function () { return error_1.EoaAccountMustHaveAccountError; } });
36
+ Object.defineProperty(exports, "EoaSigningMethodNotConfiguredError", { enumerable: true, get: function () { return error_1.EoaSigningMethodNotConfiguredError; } });
37
+ Object.defineProperty(exports, "EoaSigningNotSupportedError", { enumerable: true, get: function () { return error_1.EoaSigningNotSupportedError; } });
38
+ Object.defineProperty(exports, "ExistingEip7702AccountsNotSupportedError", { enumerable: true, get: function () { return error_1.ExistingEip7702AccountsNotSupportedError; } });
39
+ Object.defineProperty(exports, "FactoryArgsNotAvailableError", { enumerable: true, get: function () { return error_1.FactoryArgsNotAvailableError; } });
40
+ Object.defineProperty(exports, "isAccountError", { enumerable: true, get: function () { return error_1.isAccountError; } });
41
+ Object.defineProperty(exports, "ModuleInstallationNotSupportedError", { enumerable: true, get: function () { return error_1.ModuleInstallationNotSupportedError; } });
42
+ Object.defineProperty(exports, "OwnersFieldRequiredError", { enumerable: true, get: function () { return error_1.OwnersFieldRequiredError; } });
43
+ Object.defineProperty(exports, "SigningNotSupportedForAccountError", { enumerable: true, get: function () { return error_1.SigningNotSupportedForAccountError; } });
44
+ Object.defineProperty(exports, "SmartSessionsNotEnabledError", { enumerable: true, get: function () { return error_1.SmartSessionsNotEnabledError; } });
45
+ Object.defineProperty(exports, "WalletClientNoConnectedAccountError", { enumerable: true, get: function () { return error_1.WalletClientNoConnectedAccountError; } });
46
+ const kernel_1 = require("./kernel");
47
+ const nexus_1 = require("./nexus");
48
+ const passport_1 = require("./passport");
49
+ const safe_1 = require("./safe");
50
+ const common_1 = require("./signing/common");
51
+ const message_1 = require("./signing/message");
52
+ const typedData_1 = require("./signing/typedData");
53
+ const startale_1 = require("./startale");
54
+ const utils_1 = require("./utils");
55
+ function getDeployArgs(config) {
56
+ const account = getAccountProvider(config);
57
+ switch (account.type) {
58
+ case 'safe': {
59
+ return (0, safe_1.getDeployArgs)(config);
60
+ }
61
+ case 'nexus': {
62
+ return (0, nexus_1.getDeployArgs)(config);
63
+ }
64
+ case 'kernel': {
65
+ return (0, kernel_1.getDeployArgs)(config);
66
+ }
67
+ case 'startale': {
68
+ return (0, startale_1.getDeployArgs)(config);
69
+ }
70
+ case 'passport': {
71
+ // Mocked data; will be overridden by the actual deploy args
72
+ return {
73
+ factory: viem_1.zeroAddress,
74
+ factoryData: viem_1.zeroHash,
75
+ salt: viem_1.zeroHash,
76
+ implementation: viem_1.zeroAddress,
77
+ initializationCallData: '0x',
78
+ initData: '0x',
79
+ };
80
+ }
81
+ case 'eoa': {
82
+ throw new Error('EOA accounts do not have deploy args');
83
+ }
84
+ }
85
+ }
86
+ function getV0DeployArgs(config) {
87
+ const account = getAccountProvider(config);
88
+ switch (account.type) {
89
+ case 'safe': {
90
+ return (0, safe_1.getV0DeployArgs)(config);
91
+ }
92
+ default: {
93
+ throw new Error(`Unsupported account type: ${account.type}`);
94
+ }
95
+ }
96
+ }
97
+ function getInitCode(config) {
98
+ if (is7702(config)) {
99
+ return undefined;
100
+ }
101
+ else if (config.account?.type === 'eoa') {
102
+ return undefined;
103
+ }
104
+ else if (config.initData) {
105
+ return config.initData;
106
+ }
107
+ else {
108
+ const deployArgs = getDeployArgs(config);
109
+ if (!deployArgs) {
110
+ throw new error_1.FactoryArgsNotAvailableError();
111
+ }
112
+ const { factory, factoryData } = deployArgs;
113
+ return {
114
+ factory,
115
+ factoryData,
116
+ };
117
+ }
118
+ }
119
+ function getV0InitCode(config) {
120
+ if (is7702(config)) {
121
+ return undefined;
122
+ }
123
+ else if (config.account?.type === 'eoa') {
124
+ return undefined;
125
+ }
126
+ else if (config.initData) {
127
+ return config.initData;
128
+ }
129
+ else {
130
+ const deployArgs = getV0DeployArgs(config);
131
+ if (!deployArgs) {
132
+ throw new error_1.FactoryArgsNotAvailableError();
133
+ }
134
+ const { factory, factoryData } = deployArgs;
135
+ return {
136
+ factory,
137
+ factoryData,
138
+ };
139
+ }
140
+ }
141
+ async function signEip7702InitData(config) {
142
+ const eoa = config.eoa;
143
+ if (!eoa) {
144
+ throw new error_1.Eip7702AccountMustHaveEoaError();
145
+ }
146
+ const account = getAccountProvider(config);
147
+ switch (account.type) {
148
+ case 'nexus': {
149
+ return await (0, nexus_1.signEip7702InitData)(config, eoa);
150
+ }
151
+ case 'eoa': {
152
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
153
+ }
154
+ case 'safe':
155
+ case 'kernel':
156
+ case 'startale': {
157
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
158
+ }
159
+ default: {
160
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
161
+ }
162
+ }
163
+ }
164
+ function getEip7702InitCall(config, signature) {
165
+ const account = getAccountProvider(config);
166
+ switch (account.type) {
167
+ case 'nexus': {
168
+ return (0, nexus_1.getEip7702InitCall)(config, signature);
169
+ }
170
+ case 'safe':
171
+ case 'kernel':
172
+ case 'startale': {
173
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
174
+ }
175
+ default: {
176
+ throw new error_1.Eip7702NotSupportedForAccountError(account.type);
177
+ }
178
+ }
179
+ }
180
+ function getEip712Domain(config, chain) {
181
+ const account = getAccountProvider(config);
182
+ switch (account.type) {
183
+ case 'nexus': {
184
+ return (0, nexus_1.getEip712Domain)(config, chain);
185
+ }
186
+ case 'safe': {
187
+ return (0, safe_1.getEip712Domain)(config, chain);
188
+ }
189
+ case 'kernel': {
190
+ return (0, kernel_1.getEip712Domain)(config, chain);
191
+ }
192
+ case 'startale': {
193
+ return (0, startale_1.getEip712Domain)(config, chain);
194
+ }
195
+ case 'eoa': {
196
+ throw new error_1.Eip712DomainNotAvailableError('EOA accounts do not have an EIP-712 domain');
197
+ }
198
+ default: {
199
+ throw new error_1.Eip712DomainNotAvailableError(`Account type ${account.type} not yet supported`);
200
+ }
201
+ }
202
+ }
203
+ function getModuleInstallationCalls(config, module) {
204
+ const address = getAddress(config);
205
+ function getInstallData() {
206
+ const account = getAccountProvider(config);
207
+ switch (account.type) {
208
+ case 'safe': {
209
+ return [(0, safe_1.getInstallData)(module)];
210
+ }
211
+ case 'nexus': {
212
+ return [(0, nexus_1.getInstallData)(module)];
213
+ }
214
+ case 'kernel': {
215
+ return (0, kernel_1.getInstallData)(module);
216
+ }
217
+ case 'startale': {
218
+ return [(0, startale_1.getInstallData)(module)];
219
+ }
220
+ case 'passport': {
221
+ return [(0, passport_1.getInstallData)(module)];
222
+ }
223
+ case 'eoa': {
224
+ throw new error_1.ModuleInstallationNotSupportedError(account.type);
225
+ }
226
+ }
227
+ }
228
+ const installData = getInstallData();
229
+ return installData.map((data) => ({
230
+ to: address,
231
+ value: 0n,
232
+ data,
233
+ }));
234
+ }
235
+ function getModuleUninstallationCalls(config, module) {
236
+ const address = getAddress(config);
237
+ const data = (0, viem_1.encodeFunctionData)({
238
+ abi: [
239
+ {
240
+ type: 'function',
241
+ name: 'uninstallModule',
242
+ inputs: [
243
+ {
244
+ type: 'uint256',
245
+ name: 'moduleTypeId',
246
+ },
247
+ {
248
+ type: 'address',
249
+ name: 'module',
250
+ },
251
+ {
252
+ type: 'bytes',
253
+ name: 'deInitData',
254
+ },
255
+ ],
256
+ outputs: [],
257
+ stateMutability: 'nonpayable',
258
+ },
259
+ ],
260
+ functionName: 'uninstallModule',
261
+ args: [module.type, module.address, module.deInitData],
262
+ });
263
+ return [{ to: address, data, value: 0n }];
264
+ }
265
+ function getAddress(config) {
266
+ if (is7702(config)) {
267
+ if (!config.eoa) {
268
+ throw new error_1.Eip7702AccountMustHaveEoaError();
269
+ }
270
+ return config.eoa.address;
271
+ }
272
+ const account = getAccountProvider(config);
273
+ switch (account.type) {
274
+ case 'safe': {
275
+ return (0, safe_1.getAddress)(config);
276
+ }
277
+ case 'nexus': {
278
+ return (0, nexus_1.getAddress)(config);
279
+ }
280
+ case 'kernel': {
281
+ return (0, kernel_1.getAddress)(config);
282
+ }
283
+ case 'startale': {
284
+ return (0, startale_1.getAddress)(config);
285
+ }
286
+ case 'passport': {
287
+ return (0, passport_1.getAddress)(config);
288
+ }
289
+ case 'eoa': {
290
+ if (!config.eoa) {
291
+ throw new error_1.AccountError({
292
+ message: 'EOA account must have an EOA configured',
293
+ });
294
+ }
295
+ return config.eoa.address;
296
+ }
297
+ }
298
+ }
299
+ function checkAddress(config) {
300
+ if (!config.initData) {
301
+ return true;
302
+ }
303
+ return (config.initData.address.toLowerCase() === getAddress(config).toLowerCase());
304
+ }
305
+ // Signs and packs a signature to be EIP-1271 compatible
306
+ async function getEip1271Signature(config, signers, chain, validator, hash, transformSignature = (signature) => signature) {
307
+ if (config.account?.type === 'eoa') {
308
+ throw new error_1.EoaSigningNotSupportedError('packed signatures');
309
+ }
310
+ signers = signers ?? (0, common_1.convertOwnerSetToSignerSet)(config.owners);
311
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, false);
312
+ const account = getAccountProvider(config);
313
+ const address = getAddress(config);
314
+ switch (account.type) {
315
+ case 'safe': {
316
+ const signature = await signFn(hash);
317
+ return (0, safe_1.packSignature)(signature, validator, transformSignature);
318
+ }
319
+ case 'nexus': {
320
+ const signature = await signFn(hash);
321
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
322
+ return (0, nexus_1.packSignature)(signature, validator, transformSignature, defaultValidatorAddress);
323
+ }
324
+ case 'passport': {
325
+ const signature = await signFn(hash);
326
+ return (0, passport_1.packSignature)(signature, validator, transformSignature);
327
+ }
328
+ case 'kernel': {
329
+ const signature = await signFn((0, kernel_1.wrapMessageHash)(hash, address));
330
+ return (0, kernel_1.packSignature)(signature, validator, transformSignature);
331
+ }
332
+ case 'startale': {
333
+ const signature = await signFn(hash);
334
+ return (0, startale_1.packSignature)(signature, validator, transformSignature);
335
+ }
336
+ default: {
337
+ throw new Error(`Unsupported account type: ${account.type}`);
338
+ }
339
+ }
340
+ }
341
+ // Signs and packs a signature to be used by the emissary validator
342
+ async function getEmissarySignature(config, signers, chain, hash, transformSignature = (signature) => signature) {
343
+ if (config.account?.type === 'eoa') {
344
+ throw new error_1.EoaSigningNotSupportedError('packed signatures');
345
+ }
346
+ signers = signers ?? (0, common_1.convertOwnerSetToSignerSet)(config.owners);
347
+ const address = getAddress(config);
348
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, false);
349
+ const signature = await signFn(hash);
350
+ return transformSignature(signature);
351
+ }
352
+ // Signs and packs a signature to be EIP-1271 compatible
353
+ async function getTypedDataPackedSignature(config, signers, chain, validator, parameters, transformSignature = (signature) => signature) {
354
+ if (config.account?.type === 'eoa') {
355
+ throw new error_1.EoaSigningNotSupportedError('packed signatures');
356
+ }
357
+ const address = getAddress(config);
358
+ signers = signers ?? (0, common_1.convertOwnerSetToSignerSet)(config.owners);
359
+ const signFn = (parameters) => (0, typedData_1.sign)(signers, chain, address, parameters);
360
+ const account = getAccountProvider(config);
361
+ switch (account.type) {
362
+ case 'safe': {
363
+ const signature = await signFn(parameters);
364
+ return (0, safe_1.packSignature)(signature, validator, transformSignature);
365
+ }
366
+ case 'nexus': {
367
+ const signature = await signFn(parameters);
368
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
369
+ return (0, nexus_1.packSignature)(signature, validator, transformSignature, defaultValidatorAddress);
370
+ }
371
+ case 'passport': {
372
+ const signature = await signFn(parameters);
373
+ return (0, passport_1.packSignature)(signature, validator, transformSignature);
374
+ }
375
+ case 'kernel': {
376
+ const address = getAddress(config);
377
+ const signMessageFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, false);
378
+ const signature = await signMessageFn((0, kernel_1.wrapMessageHash)((0, viem_1.hashTypedData)(parameters), address));
379
+ return (0, kernel_1.packSignature)(signature, validator, transformSignature);
380
+ }
381
+ case 'startale': {
382
+ const signature = await signFn(parameters);
383
+ return (0, startale_1.packSignature)(signature, validator, transformSignature);
384
+ }
385
+ default: {
386
+ throw new Error(`Unsupported account type: ${account.type}`);
387
+ }
388
+ }
389
+ }
390
+ async function isDeployed(config, chain) {
391
+ const account = getAccountProvider(config);
392
+ if (account.type === 'eoa') {
393
+ return true;
394
+ }
395
+ const publicClient = (0, viem_1.createPublicClient)({
396
+ chain: chain,
397
+ transport: (0, utils_1.createTransport)(chain, config.provider),
398
+ });
399
+ const address = getAddress(config);
400
+ const code = await publicClient.getCode({
401
+ address,
402
+ });
403
+ if (!code) {
404
+ return false;
405
+ }
406
+ return (0, viem_1.size)(code) > 0;
407
+ }
408
+ async function deploy(config, chain, params) {
409
+ const account = getAccountProvider(config);
410
+ const deployArgs = getDeployArgs(config);
411
+ if (!deployArgs) {
412
+ throw new error_1.FactoryArgsNotAvailableError();
413
+ }
414
+ if (account.type === 'eoa') {
415
+ return false;
416
+ }
417
+ const deployed = await isDeployed(config, chain);
418
+ if (deployed) {
419
+ return false;
420
+ }
421
+ const intentExecutorInstalled = 'intentExecutorInstalled' in deployArgs
422
+ ? deployArgs.intentExecutorInstalled
423
+ : false;
424
+ // Use bundler directly when:
425
+ // (account has initData and intent executor is not installed) || (custom bundler is configured)
426
+ const useCustomBundler = config.bundler?.type === 'custom';
427
+ const asUserOp = (config.initData && !intentExecutorInstalled) || useCustomBundler;
428
+ if (asUserOp) {
429
+ await deployWithBundler(chain, config);
430
+ }
431
+ else {
432
+ await deployWithIntent(chain, config, params?.sponsored ?? false);
433
+ }
434
+ return true;
435
+ }
436
+ // Installs the missing modules
437
+ // Checks if the provided modules are already installed
438
+ // Useful for existing (already deployed) accounts
439
+ async function setup(config, chain) {
440
+ const account = getAccountProvider(config);
441
+ if (account.type === 'eoa') {
442
+ return false;
443
+ }
444
+ const modules = (0, modules_1.getSetup)(config);
445
+ const publicClient = (0, viem_1.createPublicClient)({
446
+ chain,
447
+ transport: (0, utils_1.createTransport)(chain, config.provider),
448
+ });
449
+ const address = getAddress(config);
450
+ const allModules = [
451
+ ...modules.validators,
452
+ ...modules.executors,
453
+ ...modules.fallbacks,
454
+ ...modules.hooks,
455
+ ];
456
+ // Check if the modules are already installed
457
+ const installedResults = await publicClient.multicall({
458
+ contracts: allModules.map((module) => ({
459
+ address: address,
460
+ abi: [
461
+ {
462
+ type: 'function',
463
+ name: 'isModuleInstalled',
464
+ inputs: [
465
+ { type: 'uint256', name: 'moduleTypeId' },
466
+ { type: 'address', name: 'module' },
467
+ { type: 'bytes', name: 'additionalContext' },
468
+ ],
469
+ outputs: [{ type: 'bool', name: 'isInstalled' }],
470
+ stateMutability: 'view',
471
+ },
472
+ ],
473
+ functionName: 'isModuleInstalled',
474
+ args: [module.type, module.address, module.additionalContext],
475
+ })),
476
+ });
477
+ const isInstalled = installedResults.map((result) => result.result);
478
+ const modulesToInstall = allModules.filter((_, index) => !isInstalled[index]);
479
+ if (modulesToInstall.length === 0) {
480
+ // Nothing to install
481
+ return false;
482
+ }
483
+ const calls = [];
484
+ for (const module of modulesToInstall) {
485
+ calls.push(...getModuleInstallationCalls(config, module));
486
+ }
487
+ // Select the transaction infra layer based on the intent executor status
488
+ const intentExecutor = (0, modules_1.getIntentExecutor)(config);
489
+ const hasIntentExecutor = modulesToInstall.every((module) => module.address !== intentExecutor.address);
490
+ let result;
491
+ if (hasIntentExecutor) {
492
+ result = await (0, execution_1.sendTransactionInternal)(config, [chain], chain, {
493
+ callInputs: calls,
494
+ });
495
+ }
496
+ else {
497
+ result = await (0, execution_1.sendUserOperationInternal)(config, chain, calls);
498
+ }
499
+ await (0, execution_1.waitForExecution)(config, result, true);
500
+ return true;
501
+ }
502
+ async function deployWithIntent(chain, config, sponsored) {
503
+ const publicClient = (0, viem_1.createPublicClient)({
504
+ chain,
505
+ transport: (0, utils_1.createTransport)(chain, config.provider),
506
+ });
507
+ const address = getAddress(config);
508
+ const code = await publicClient.getCode({ address });
509
+ if (code) {
510
+ // Already deployed
511
+ return;
512
+ }
513
+ const result = await (0, execution_1.sendTransaction)(config, {
514
+ sourceChains: [chain],
515
+ targetChain: chain,
516
+ calls: [],
517
+ sponsored,
518
+ });
519
+ await (0, execution_1.waitForExecution)(config, result, true);
520
+ }
521
+ async function deployWithBundler(chain, config) {
522
+ const publicClient = (0, viem_1.createPublicClient)({
523
+ chain,
524
+ transport: (0, utils_1.createTransport)(chain, config.provider),
525
+ });
526
+ const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
527
+ const smartAccount = await getSmartAccount(config, publicClient, chain);
528
+ const deployArgs = getDeployArgs(config);
529
+ if (!deployArgs) {
530
+ throw new error_1.FactoryArgsNotAvailableError();
531
+ }
532
+ const { factory, factoryData } = deployArgs;
533
+ const opHash = await bundlerClient.sendUserOperation({
534
+ account: smartAccount,
535
+ factory,
536
+ factoryData,
537
+ calls: [
538
+ {
539
+ to: viem_1.zeroAddress,
540
+ value: 0n,
541
+ data: '0x',
542
+ },
543
+ ],
544
+ });
545
+ await bundlerClient.waitForUserOperationReceipt({
546
+ hash: opHash,
547
+ });
548
+ }
549
+ async function toErc6492Signature(config, signature, chain) {
550
+ const deployed = await isDeployed(config, chain);
551
+ if (deployed) {
552
+ return signature;
553
+ }
554
+ // Account is not deployed, use ERC-6492
555
+ const initCode = getInitCode(config);
556
+ if (!initCode) {
557
+ throw new error_1.FactoryArgsNotAvailableError();
558
+ }
559
+ const deployArgs = getDeployArgs(config);
560
+ if (!deployArgs) {
561
+ throw new error_1.FactoryArgsNotAvailableError();
562
+ }
563
+ const { factory, factoryData } = deployArgs;
564
+ const magicBytes = '0x6492649264926492649264926492649264926492649264926492649264926492';
565
+ return (0, viem_1.concat)([
566
+ (0, viem_1.encodeAbiParameters)([
567
+ { name: 'create2Factory', type: 'address' },
568
+ { name: 'factoryCalldata', type: 'bytes' },
569
+ { name: 'originalERC1271Signature', type: 'bytes' },
570
+ ], [factory, factoryData, signature]),
571
+ magicBytes,
572
+ ]);
573
+ }
574
+ async function getSmartAccount(config, client, chain) {
575
+ // EOA accounts don't need smart account functionality
576
+ if (config.account?.type === 'eoa') {
577
+ throw new Error('getSmartAccount is not supported for EOA accounts');
578
+ }
579
+ if (!config.owners) {
580
+ throw new error_1.OwnersFieldRequiredError();
581
+ }
582
+ const account = getAccountProvider(config);
583
+ const address = getAddress(config);
584
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
585
+ const signers = (0, common_1.convertOwnerSetToSignerSet)(config.owners);
586
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, true);
587
+ switch (account.type) {
588
+ case 'safe': {
589
+ return (0, safe_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
590
+ }
591
+ case 'nexus': {
592
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
593
+ return (0, nexus_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn, defaultValidatorAddress);
594
+ }
595
+ case 'kernel': {
596
+ return (0, kernel_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
597
+ }
598
+ case 'startale': {
599
+ return (0, startale_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
600
+ }
601
+ }
602
+ }
603
+ async function getGuardianSmartAccount(config, client, chain, guardians) {
604
+ const address = getAddress(config);
605
+ const accounts = guardians.type === 'ecdsa' ? guardians.accounts : [];
606
+ const socialRecoveryValidator = (0, core_1.getSocialRecoveryValidator)(accounts);
607
+ if (!socialRecoveryValidator) {
608
+ throw new Error('Social recovery is not available');
609
+ }
610
+ const signers = {
611
+ type: 'guardians',
612
+ guardians: accounts,
613
+ };
614
+ const signFn = (hash) => (0, message_1.sign)(signers, chain, address, hash, true);
615
+ const account = getAccountProvider(config);
616
+ switch (account.type) {
617
+ case 'safe': {
618
+ return (0, safe_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
619
+ }
620
+ case 'nexus': {
621
+ const defaultValidatorAddress = (0, nexus_1.getDefaultValidatorAddress)(account.version);
622
+ return (0, nexus_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn, defaultValidatorAddress);
623
+ }
624
+ case 'kernel': {
625
+ return (0, kernel_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
626
+ }
627
+ case 'startale': {
628
+ return (0, startale_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
629
+ }
630
+ }
631
+ }
632
+ function is7702(config) {
633
+ const account = getAccountProvider(config);
634
+ return account.type !== 'eoa' && config.eoa !== undefined;
635
+ }
636
+ function getAccountProvider(config) {
637
+ if (config.account) {
638
+ return config.account;
639
+ }
640
+ return {
641
+ type: 'nexus',
642
+ };
643
+ }
@@ -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,33 @@
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
+ });
16
+ (0, vitest_1.expect)(address).toEqual('0x0681de31e060b384F0b08A3bAC99E9bDFf302474');
17
+ });
18
+ (0, vitest_1.test)('Safe, passkey owner with a session', () => {
19
+ const address = (0, _1.getAddress)({
20
+ owners: {
21
+ type: 'passkey',
22
+ accounts: [consts_1.passkeyAccount],
23
+ },
24
+ });
25
+ (0, vitest_1.expect)(address).toEqual('0x894b88C04B4DE6AbDdcE81E8bdc91927E37d6ceD');
26
+ });
27
+ });
28
+ (0, vitest_1.describe)('Sign', () => {
29
+ vitest_1.test.todo('With ECDSA, single key');
30
+ vitest_1.test.todo('With ECDSA, multisig');
31
+ vitest_1.test.todo('With Passkey');
32
+ });
33
+ });
@@ -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,CAkB3E;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}