@rhinestone/sdk 1.0.41-alpha.0 → 1.0.41

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 (208) hide show
  1. package/dist/src/accounts/error.d.ts +114 -0
  2. package/dist/src/accounts/error.d.ts.map +1 -0
  3. package/dist/src/accounts/error.js +174 -0
  4. package/dist/src/accounts/index.d.ts +50 -0
  5. package/dist/src/accounts/index.d.ts.map +1 -0
  6. package/dist/src/accounts/index.js +669 -0
  7. package/dist/src/accounts/index.test.d.ts +2 -0
  8. package/dist/src/accounts/index.test.d.ts.map +1 -0
  9. package/dist/src/accounts/index.test.js +33 -0
  10. package/dist/src/accounts/json-rpc/index.d.ts +5 -0
  11. package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
  12. package/dist/src/accounts/json-rpc/index.js +20 -0
  13. package/dist/src/accounts/json-rpc/index.test.d.ts +2 -0
  14. package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
  15. package/dist/src/accounts/json-rpc/index.test.js +33 -0
  16. package/dist/src/accounts/json-rpc/providers.d.ts +5 -0
  17. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
  18. package/dist/src/accounts/json-rpc/providers.js +22 -0
  19. package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
  20. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
  21. package/dist/src/accounts/json-rpc/providers.test.js +43 -0
  22. package/dist/src/accounts/kernel.d.ts +29 -0
  23. package/dist/src/accounts/kernel.d.ts.map +1 -0
  24. package/dist/src/accounts/kernel.js +297 -0
  25. package/dist/src/accounts/kernel.test.d.ts +2 -0
  26. package/dist/src/accounts/kernel.test.d.ts.map +1 -0
  27. package/dist/src/accounts/kernel.test.js +132 -0
  28. package/dist/src/accounts/nexus.d.ts +35 -0
  29. package/dist/src/accounts/nexus.d.ts.map +1 -0
  30. package/dist/src/accounts/nexus.js +471 -0
  31. package/dist/src/accounts/nexus.test.d.ts +2 -0
  32. package/dist/src/accounts/nexus.test.d.ts.map +1 -0
  33. package/dist/src/accounts/nexus.test.js +118 -0
  34. package/dist/src/accounts/passport.d.ts +12 -0
  35. package/dist/src/accounts/passport.d.ts.map +1 -0
  36. package/dist/src/accounts/passport.js +173 -0
  37. package/dist/src/accounts/safe.d.ts +35 -0
  38. package/dist/src/accounts/safe.d.ts.map +1 -0
  39. package/dist/src/accounts/safe.js +365 -0
  40. package/dist/src/accounts/safe.test.d.ts +2 -0
  41. package/dist/src/accounts/safe.test.d.ts.map +1 -0
  42. package/dist/src/accounts/safe.test.js +118 -0
  43. package/dist/src/accounts/signing/common.d.ts +27 -0
  44. package/dist/src/accounts/signing/common.d.ts.map +1 -0
  45. package/dist/src/accounts/signing/common.js +183 -0
  46. package/dist/src/accounts/signing/message.d.ts +5 -0
  47. package/dist/src/accounts/signing/message.d.ts.map +1 -0
  48. package/dist/src/accounts/signing/message.js +47 -0
  49. package/dist/src/accounts/signing/passkeys.d.ts +36 -0
  50. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
  51. package/dist/src/accounts/signing/passkeys.js +125 -0
  52. package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
  53. package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
  54. package/dist/src/accounts/signing/passkeys.test.js +88 -0
  55. package/dist/src/accounts/signing/typedData.d.ts +5 -0
  56. package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
  57. package/dist/src/accounts/signing/typedData.js +35 -0
  58. package/dist/src/accounts/startale.d.ts +27 -0
  59. package/dist/src/accounts/startale.d.ts.map +1 -0
  60. package/dist/src/accounts/startale.js +116 -0
  61. package/dist/src/accounts/startale.test.d.ts +2 -0
  62. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  63. package/dist/src/accounts/startale.test.js +92 -0
  64. package/dist/src/accounts/utils.d.ts +33 -0
  65. package/dist/src/accounts/utils.d.ts.map +1 -0
  66. package/dist/src/accounts/utils.js +208 -0
  67. package/dist/src/accounts/utils.test.d.ts +2 -0
  68. package/dist/src/accounts/utils.test.d.ts.map +1 -0
  69. package/dist/src/accounts/utils.test.js +49 -0
  70. package/dist/src/accounts/walletClient.d.ts +34 -0
  71. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  72. package/dist/src/accounts/walletClient.js +121 -0
  73. package/dist/src/actions/compact.d.ts +13 -0
  74. package/dist/src/actions/compact.d.ts.map +1 -0
  75. package/dist/src/actions/compact.js +210 -0
  76. package/dist/src/actions/deployment.d.ts +19 -0
  77. package/dist/src/actions/deployment.d.ts.map +1 -0
  78. package/dist/src/actions/deployment.js +78 -0
  79. package/dist/src/actions/ecdsa.d.ts +35 -0
  80. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  81. package/dist/src/actions/ecdsa.js +114 -0
  82. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  83. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  84. package/dist/src/actions/ecdsa.test.js +99 -0
  85. package/dist/src/actions/index.d.ts +17 -0
  86. package/dist/src/actions/index.d.ts.map +1 -0
  87. package/dist/src/actions/index.js +53 -0
  88. package/dist/src/actions/mfa.d.ts +37 -0
  89. package/dist/src/actions/mfa.d.ts.map +1 -0
  90. package/dist/src/actions/mfa.js +133 -0
  91. package/dist/src/actions/passkeys.d.ts +37 -0
  92. package/dist/src/actions/passkeys.d.ts.map +1 -0
  93. package/dist/src/actions/passkeys.js +129 -0
  94. package/dist/src/actions/passkeys.test.d.ts +2 -0
  95. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  96. package/dist/src/actions/passkeys.test.js +54 -0
  97. package/dist/src/actions/recovery.d.ts +33 -0
  98. package/dist/src/actions/recovery.d.ts.map +1 -0
  99. package/dist/src/actions/recovery.js +193 -0
  100. package/dist/src/actions/recovery.test.d.ts +2 -0
  101. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  102. package/dist/src/actions/recovery.test.js +168 -0
  103. package/dist/src/actions/smart-sessions.d.ts +14 -0
  104. package/dist/src/actions/smart-sessions.d.ts.map +1 -0
  105. package/dist/src/actions/smart-sessions.js +16 -0
  106. package/dist/src/errors/index.d.ts +5 -0
  107. package/dist/src/errors/index.d.ts.map +1 -0
  108. package/dist/src/errors/index.js +53 -0
  109. package/dist/src/execution/compact.d.ts +151 -0
  110. package/dist/src/execution/compact.d.ts.map +1 -0
  111. package/dist/src/execution/compact.js +122 -0
  112. package/dist/src/execution/error.d.ts +61 -0
  113. package/dist/src/execution/error.d.ts.map +1 -0
  114. package/dist/src/execution/error.js +87 -0
  115. package/dist/src/execution/index.d.ts +41 -0
  116. package/dist/src/execution/index.d.ts.map +1 -0
  117. package/dist/src/execution/index.js +233 -0
  118. package/dist/src/execution/permit2.d.ts +148 -0
  119. package/dist/src/execution/permit2.d.ts.map +1 -0
  120. package/dist/src/execution/permit2.js +291 -0
  121. package/dist/src/execution/singleChainOps.d.ts +28 -0
  122. package/dist/src/execution/singleChainOps.d.ts.map +1 -0
  123. package/dist/src/execution/singleChainOps.js +32 -0
  124. package/dist/src/execution/smart-session.d.ts +13 -0
  125. package/dist/src/execution/smart-session.d.ts.map +1 -0
  126. package/dist/src/execution/smart-session.js +178 -0
  127. package/dist/src/execution/types.d.ts +36 -0
  128. package/dist/src/execution/types.d.ts.map +1 -0
  129. package/dist/src/execution/types.js +2 -0
  130. package/dist/src/execution/utils.d.ts +83 -0
  131. package/dist/src/execution/utils.d.ts.map +1 -0
  132. package/dist/src/execution/utils.js +705 -0
  133. package/dist/src/index.d.ts +74 -0
  134. package/dist/src/index.d.ts.map +1 -0
  135. package/dist/src/index.js +317 -0
  136. package/dist/src/modules/abi/smart-sessions.d.ts +104 -0
  137. package/dist/src/modules/abi/smart-sessions.d.ts.map +1 -0
  138. package/dist/src/modules/abi/smart-sessions.js +131 -0
  139. package/dist/src/modules/chain-abstraction.d.ts +5 -0
  140. package/dist/src/modules/chain-abstraction.d.ts.map +1 -0
  141. package/dist/src/modules/chain-abstraction.js +7 -0
  142. package/dist/src/modules/common.d.ts +30 -0
  143. package/dist/src/modules/common.d.ts.map +1 -0
  144. package/dist/src/modules/common.js +42 -0
  145. package/dist/src/modules/index.d.ts +10 -0
  146. package/dist/src/modules/index.d.ts.map +1 -0
  147. package/dist/src/modules/index.js +94 -0
  148. package/dist/src/modules/index.test.d.ts +2 -0
  149. package/dist/src/modules/index.test.d.ts.map +1 -0
  150. package/dist/src/modules/index.test.js +81 -0
  151. package/dist/src/modules/legacy.d.ts +10 -0
  152. package/dist/src/modules/legacy.d.ts.map +1 -0
  153. package/dist/src/modules/legacy.js +65 -0
  154. package/dist/src/modules/read.d.ts +9 -0
  155. package/dist/src/modules/read.d.ts.map +1 -0
  156. package/dist/src/modules/read.js +125 -0
  157. package/dist/src/modules/validators/core.d.ts +29 -0
  158. package/dist/src/modules/validators/core.d.ts.map +1 -0
  159. package/dist/src/modules/validators/core.js +278 -0
  160. package/dist/src/modules/validators/core.test.d.ts +2 -0
  161. package/dist/src/modules/validators/core.test.d.ts.map +1 -0
  162. package/dist/src/modules/validators/core.test.js +101 -0
  163. package/dist/src/modules/validators/index.d.ts +4 -0
  164. package/dist/src/modules/validators/index.d.ts.map +1 -0
  165. package/dist/src/modules/validators/index.js +15 -0
  166. package/dist/src/modules/validators/smart-sessions.d.ts +96 -0
  167. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -0
  168. package/dist/src/modules/validators/smart-sessions.js +497 -0
  169. package/dist/src/modules/validators/smart-sessions.test.d.ts +2 -0
  170. package/dist/src/modules/validators/smart-sessions.test.d.ts.map +1 -0
  171. package/dist/src/modules/validators/smart-sessions.test.js +219 -0
  172. package/dist/src/orchestrator/client.d.ts +27 -0
  173. package/dist/src/orchestrator/client.d.ts.map +1 -0
  174. package/dist/src/orchestrator/client.js +354 -0
  175. package/dist/src/orchestrator/consts.d.ts +5 -0
  176. package/dist/src/orchestrator/consts.d.ts.map +1 -0
  177. package/dist/src/orchestrator/consts.js +9 -0
  178. package/dist/src/orchestrator/error.d.ts +232 -0
  179. package/dist/src/orchestrator/error.d.ts.map +1 -0
  180. package/dist/src/orchestrator/error.js +268 -0
  181. package/dist/src/orchestrator/index.d.ts +10 -0
  182. package/dist/src/orchestrator/index.d.ts.map +1 -0
  183. package/dist/src/orchestrator/index.js +57 -0
  184. package/dist/src/orchestrator/registry.d.ts +22 -0
  185. package/dist/src/orchestrator/registry.d.ts.map +1 -0
  186. package/dist/src/orchestrator/registry.js +121 -0
  187. package/dist/src/orchestrator/registry.test.d.ts +2 -0
  188. package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
  189. package/dist/src/orchestrator/registry.test.js +150 -0
  190. package/dist/src/orchestrator/types.d.ts +295 -0
  191. package/dist/src/orchestrator/types.d.ts.map +1 -0
  192. package/dist/src/orchestrator/types.js +17 -0
  193. package/dist/src/orchestrator/utils.d.ts +3 -0
  194. package/dist/src/orchestrator/utils.d.ts.map +1 -0
  195. package/dist/src/orchestrator/utils.js +24 -0
  196. package/dist/src/types.d.ts +284 -0
  197. package/dist/src/types.d.ts.map +1 -0
  198. package/dist/src/types.js +2 -0
  199. package/dist/src/utils/index.d.ts +26 -0
  200. package/dist/src/utils/index.d.ts.map +1 -0
  201. package/dist/src/utils/index.js +63 -0
  202. package/dist/test/consts.d.ts +10 -0
  203. package/dist/test/consts.d.ts.map +1 -0
  204. package/dist/test/consts.js +22 -0
  205. package/dist/test/utils/utils.d.ts +5 -0
  206. package/dist/test/utils/utils.d.ts.map +1 -0
  207. package/dist/test/utils/utils.js +20 -0
  208. package/package.json +1 -1
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const viem_1 = require("viem");
4
+ const vitest_1 = require("vitest");
5
+ const consts_1 = require("../../../test/consts");
6
+ const smart_sessions_1 = require("../abi/smart-sessions");
7
+ const common_1 = require("../common");
8
+ const smart_sessions_2 = require("./smart-sessions");
9
+ (0, vitest_1.describe)('Smart Sessions', () => {
10
+ (0, vitest_1.describe)('Permission ID', () => {
11
+ (0, vitest_1.test)('default', () => {
12
+ (0, vitest_1.expect)((0, smart_sessions_2.getPermissionId)({
13
+ owners: {
14
+ type: 'ecdsa',
15
+ accounts: [consts_1.accountA, consts_1.accountB],
16
+ },
17
+ })).toBe('0xd3b39024e437b4cac278e33965b9a9326e81ee46bd45d890adbfc8eb45412fa1');
18
+ });
19
+ (0, vitest_1.test)('with salt', () => {
20
+ (0, vitest_1.expect)((0, smart_sessions_2.getPermissionId)({
21
+ owners: {
22
+ type: 'ecdsa',
23
+ accounts: [consts_1.accountA, consts_1.accountB],
24
+ },
25
+ salt: '0x97340e1cfff3319c76ef22b2bc9d3231071d550125d68c9d4a8972823f166320',
26
+ })).toBe('0xeb47b4699298a847a0f6fb7365e56aefcc95630e7d0e3d9ca5917620c7dc3d08');
27
+ });
28
+ });
29
+ (0, vitest_1.describe)('Smart Session Validator', () => {
30
+ (0, vitest_1.test)('no session', () => {
31
+ (0, vitest_1.expect)((0, smart_sessions_2.getSmartSessionValidator)({
32
+ owners: {
33
+ type: 'ecdsa',
34
+ accounts: [consts_1.accountA],
35
+ },
36
+ })).toBeNull();
37
+ });
38
+ (0, vitest_1.test)('empty session list', () => {
39
+ (0, vitest_1.expect)((0, smart_sessions_2.getSmartSessionValidator)({
40
+ owners: {
41
+ type: 'ecdsa',
42
+ accounts: [consts_1.accountA],
43
+ },
44
+ experimental_sessions: {
45
+ enabled: true,
46
+ },
47
+ })).not.toBeNull();
48
+ });
49
+ (0, vitest_1.test)('single session', () => {
50
+ const validator = (0, smart_sessions_2.getSmartSessionValidator)({
51
+ owners: {
52
+ type: 'ecdsa',
53
+ accounts: [consts_1.accountA],
54
+ },
55
+ experimental_sessions: {
56
+ enabled: true,
57
+ },
58
+ });
59
+ (0, vitest_1.expect)(validator).not.toBeNull();
60
+ (0, vitest_1.expect)(validator?.type).toEqual(common_1.MODULE_TYPE_ID_VALIDATOR);
61
+ (0, vitest_1.expect)(validator && (0, viem_1.isAddress)(validator.address)).toEqual(true);
62
+ });
63
+ });
64
+ (0, vitest_1.describe)('Enable Session Call', () => {
65
+ vitest_1.vi.mock('viem', async (importOriginal) => {
66
+ const actual = await importOriginal();
67
+ return {
68
+ // @ts-ignore
69
+ ...actual,
70
+ createPublicClient: vitest_1.vi.fn().mockReturnValue({
71
+ readContract: vitest_1.vi.fn(),
72
+ }),
73
+ };
74
+ });
75
+ const client = viem_1.createPublicClient;
76
+ client.mockImplementation((_) => {
77
+ return {
78
+ readContract: (params) => {
79
+ if (params.functionName === 'DOMAIN_SEPARATOR') {
80
+ return '0xf5f6dfa751763cc5278cba45d03ea9797c1660b2cb7f5ffd188fa3e8523abdca';
81
+ }
82
+ throw new Error('Unknown function call');
83
+ },
84
+ };
85
+ });
86
+ const TARGET = '0x063DFbDb1610EC7BbfA1fFBE603Ac5aA1B67a935';
87
+ const SELECTOR = '0x12345678';
88
+ const FALLBACK_TARGET = '0x0000000000000000000000000000000000000001';
89
+ const FALLBACK_SELECTOR = '0x00000001';
90
+ (0, vitest_1.test)('default', async () => {
91
+ const call = await (0, smart_sessions_2.getEnableSessionCall)({
92
+ owners: {
93
+ type: 'ecdsa',
94
+ accounts: [consts_1.accountA],
95
+ },
96
+ });
97
+ const sessionData = toSessionData(call);
98
+ // Should have a fallback action
99
+ (0, vitest_1.expect)(sessionData.actions.some((action) => action.actionTarget === FALLBACK_TARGET &&
100
+ action.actionTargetSelector === FALLBACK_SELECTOR)).toEqual(true);
101
+ });
102
+ (0, vitest_1.test)('with action', async () => {
103
+ const call = await (0, smart_sessions_2.getEnableSessionCall)({
104
+ owners: {
105
+ type: 'ecdsa',
106
+ accounts: [consts_1.accountA],
107
+ },
108
+ actions: [
109
+ {
110
+ target: TARGET,
111
+ selector: SELECTOR,
112
+ },
113
+ ],
114
+ });
115
+ const sessionData = toSessionData(call);
116
+ // Should have the action
117
+ (0, vitest_1.expect)(sessionData.actions.some((action) => action.actionTarget === TARGET &&
118
+ action.actionTargetSelector === SELECTOR)).toEqual(true);
119
+ // Should not have the fallback action
120
+ (0, vitest_1.expect)(sessionData.actions.some((action) => action.actionTarget === FALLBACK_TARGET &&
121
+ action.actionTargetSelector === FALLBACK_SELECTOR)).toEqual(false);
122
+ });
123
+ (0, vitest_1.test)('with policy', async () => {
124
+ const call = await (0, smart_sessions_2.getEnableSessionCall)({
125
+ owners: {
126
+ type: 'ecdsa',
127
+ accounts: [consts_1.accountA],
128
+ },
129
+ policies: [
130
+ {
131
+ type: 'sudo',
132
+ },
133
+ {
134
+ type: 'universal-action',
135
+ rules: [
136
+ {
137
+ condition: 'equal',
138
+ calldataOffset: 0n,
139
+ referenceValue: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
140
+ },
141
+ ],
142
+ },
143
+ ],
144
+ });
145
+ const sessionData = toSessionData(call);
146
+ // Should have two policies
147
+ (0, vitest_1.expect)(sessionData.userOpPolicies.length).toEqual(2);
148
+ (0, vitest_1.expect)((0, viem_1.isAddress)(sessionData.userOpPolicies[0].policy)).toEqual(true);
149
+ (0, vitest_1.expect)((0, viem_1.isHex)(sessionData.userOpPolicies[0].initData)).toEqual(true);
150
+ (0, vitest_1.expect)((0, viem_1.isAddress)(sessionData.userOpPolicies[1].policy)).toEqual(true);
151
+ (0, vitest_1.expect)((0, viem_1.isHex)(sessionData.userOpPolicies[1].initData)).toEqual(true);
152
+ });
153
+ (0, vitest_1.test)('with action policy', async () => {
154
+ const call = await (0, smart_sessions_2.getEnableSessionCall)({
155
+ owners: {
156
+ type: 'ecdsa',
157
+ accounts: [consts_1.accountA],
158
+ },
159
+ actions: [
160
+ {
161
+ target: TARGET,
162
+ selector: SELECTOR,
163
+ policies: [
164
+ {
165
+ type: 'sudo',
166
+ },
167
+ {
168
+ type: 'universal-action',
169
+ rules: [
170
+ {
171
+ condition: 'equal',
172
+ calldataOffset: 0n,
173
+ referenceValue: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
174
+ },
175
+ ],
176
+ },
177
+ ],
178
+ },
179
+ ],
180
+ });
181
+ const sessionData = toSessionData(call);
182
+ // Should have the action
183
+ const action = sessionData.actions.find((action) => action.actionTarget === TARGET &&
184
+ action.actionTargetSelector === SELECTOR);
185
+ (0, vitest_1.expect)(action).toBeDefined();
186
+ if (!action) {
187
+ throw new Error('No action');
188
+ }
189
+ // Should have 2 policies
190
+ const actionPolicies = action.actionPolicies;
191
+ (0, vitest_1.expect)(actionPolicies.length).toEqual(2);
192
+ (0, vitest_1.expect)((0, viem_1.isAddress)(actionPolicies[0].policy)).toEqual(true);
193
+ (0, vitest_1.expect)((0, viem_1.isHex)(actionPolicies[0].initData)).toEqual(true);
194
+ (0, vitest_1.expect)((0, viem_1.isAddress)(actionPolicies[1].policy)).toEqual(true);
195
+ (0, vitest_1.expect)((0, viem_1.isHex)(actionPolicies[1].initData)).toEqual(true);
196
+ });
197
+ function toSessionData(call) {
198
+ (0, vitest_1.expect)((0, viem_1.isHex)(call.data)).toEqual(true);
199
+ (0, vitest_1.expect)((0, viem_1.isAddress)(call.to)).toEqual(true);
200
+ const decoded = (0, viem_1.decodeFunctionData)({
201
+ abi: smart_sessions_1.enableSessionsAbi,
202
+ data: call.data,
203
+ });
204
+ (0, vitest_1.expect)(decoded.functionName).toEqual('enableSessions');
205
+ (0, vitest_1.expect)(decoded.args.length).toEqual(1);
206
+ (0, vitest_1.expect)(decoded.args[0].length).toEqual(1);
207
+ const session = decoded.args[0][0];
208
+ return session;
209
+ }
210
+ });
211
+ (0, vitest_1.describe)('Encode Smart Session Signature', () => {
212
+ (0, vitest_1.test)('use mode', () => {
213
+ const permissionId = '0xd3b39024e437b4cac278e33965b9a9326e81ee46bd45d890adbfc8eb45412fa1';
214
+ const signature = '0xabcdef';
215
+ const sessionSignature = (0, smart_sessions_2.encodeSmartSessionSignature)(smart_sessions_2.SMART_SESSION_MODE_USE, permissionId, signature);
216
+ (0, vitest_1.expect)(sessionSignature).toEqual('0x00d3b39024e437b4cac278e33965b9a9326e81ee46bd45d890adbfc8eb45412fa1abcdef');
217
+ });
218
+ });
219
+ });
@@ -0,0 +1,27 @@
1
+ import type { Address } from 'viem';
2
+ import type { AccountType, Execution, IntentCost, IntentInput, IntentOpStatus, IntentResult, IntentRoute, Portfolio, SignedIntentOp } from './types';
3
+ export declare class Orchestrator {
4
+ private serverUrl;
5
+ private apiKey?;
6
+ constructor(serverUrl: string, apiKey?: string);
7
+ getPortfolio(userAddress: Address, filter?: {
8
+ chainIds?: number[];
9
+ tokens?: {
10
+ [chainId: number]: Address[];
11
+ };
12
+ }): Promise<Portfolio>;
13
+ getMaxTokenAmount(account: {
14
+ address: Address;
15
+ accountType: AccountType;
16
+ setupOps: Pick<Execution, 'to' | 'data'>[];
17
+ }, destinationChainId: number, destinationTokenAddress: Address, destinationGasUnits: bigint, sponsored: boolean): Promise<bigint>;
18
+ getIntentCost(input: IntentInput): Promise<IntentCost>;
19
+ getIntentRoute(input: IntentInput): Promise<IntentRoute>;
20
+ submitIntent(signedIntentOpUnformatted: SignedIntentOp, dryRun: boolean): Promise<IntentResult>;
21
+ getIntentOpStatus(intentId: bigint): Promise<IntentOpStatus>;
22
+ private getHeaders;
23
+ private fetch;
24
+ private parseError;
25
+ private parseErrorMessage;
26
+ }
27
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../orchestrator/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAyBnC,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,WAAW,EACX,SAAS,EAET,cAAc,EACf,MAAM,SAAS,CAAA;AAGhB,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,MAAM,CAAC,CAAQ;gBAEX,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAKxC,YAAY,CAChB,WAAW,EAAE,OAAO,EACpB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;QACnB,MAAM,CAAC,EAAE;YACP,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;SAC7B,CAAA;KACF,GACA,OAAO,CAAC,SAAS,CAAC;IA+Cf,iBAAiB,CACrB,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAA;QAChB,WAAW,EAAE,WAAW,CAAA;QACxB,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC,EAAE,CAAA;KAC3C,EACD,kBAAkB,EAAE,MAAM,EAC1B,uBAAuB,EAAE,OAAO,EAChC,mBAAmB,EAAE,MAAM,EAC3B,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,MAAM,CAAC;IA4CZ,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAQtD,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAQxD,YAAY,CAChB,yBAAyB,EAAE,cAAc,EACzC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,YAAY,CAAC;IAgBlB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IASlE,OAAO,CAAC,UAAU;YAUJ,KAAK;IA4BnB,OAAO,CAAC,UAAU;IA6GlB,OAAO,CAAC,iBAAiB;CAmG1B"}
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Orchestrator = void 0;
4
+ const error_1 = require("./error");
5
+ const utils_1 = require("./utils");
6
+ class Orchestrator {
7
+ serverUrl;
8
+ apiKey;
9
+ constructor(serverUrl, apiKey) {
10
+ this.serverUrl = serverUrl;
11
+ this.apiKey = apiKey;
12
+ }
13
+ async getPortfolio(userAddress, filter) {
14
+ const params = new URLSearchParams();
15
+ if (filter?.chainIds) {
16
+ params.set('chainIds', filter.chainIds.join(','));
17
+ }
18
+ if (filter?.tokens) {
19
+ params.set('tokens', Object.entries(filter.tokens)
20
+ .flatMap(([chainId, tokens]) => tokens.map((token) => `${chainId}:${token}`))
21
+ .join(','));
22
+ }
23
+ const url = new URL(`${this.serverUrl}/accounts/${userAddress}/portfolio`);
24
+ url.search = params.toString();
25
+ const json = await this.fetch(url.toString(), {
26
+ headers: this.getHeaders(),
27
+ });
28
+ const portfolioResponse = json.portfolio;
29
+ const portfolio = portfolioResponse.map((tokenResponse) => ({
30
+ symbol: tokenResponse.tokenName,
31
+ decimals: tokenResponse.tokenDecimals,
32
+ balances: {
33
+ locked: BigInt(tokenResponse.balance.locked),
34
+ unlocked: BigInt(tokenResponse.balance.unlocked),
35
+ },
36
+ chains: tokenResponse.tokenChainBalance.map((chainBalance) => ({
37
+ chain: chainBalance.chainId,
38
+ address: chainBalance.tokenAddress,
39
+ locked: BigInt(chainBalance.balance.locked),
40
+ unlocked: BigInt(chainBalance.balance.unlocked),
41
+ })),
42
+ }));
43
+ return portfolio;
44
+ }
45
+ async getMaxTokenAmount(account, destinationChainId, destinationTokenAddress, destinationGasUnits, sponsored) {
46
+ const intentCost = await this.getIntentCost({
47
+ account,
48
+ destinationExecutions: [],
49
+ destinationChainId,
50
+ destinationGasUnits,
51
+ tokenRequests: [
52
+ {
53
+ tokenAddress: destinationTokenAddress,
54
+ },
55
+ ],
56
+ options: {
57
+ topupCompact: false,
58
+ sponsorSettings: {
59
+ gasSponsored: sponsored,
60
+ bridgeFeesSponsored: sponsored,
61
+ swapFeesSponsored: sponsored,
62
+ },
63
+ },
64
+ });
65
+ if (!intentCost.hasFulfilledAll) {
66
+ return 0n;
67
+ }
68
+ const tokenReceived = intentCost.tokensReceived.find((token) => token.tokenAddress.toLowerCase() ===
69
+ destinationTokenAddress.toLowerCase());
70
+ if (!tokenReceived) {
71
+ return 0n;
72
+ }
73
+ const tokenAmount = tokenReceived.destinationAmount;
74
+ if (BigInt(tokenAmount) < 0n) {
75
+ throw new Error(`Balance not available. Make sure the account is deployed`);
76
+ }
77
+ // `sponsorSettings` is not taken into account in the API response for now
78
+ // As a workaround, we use the `amountSpent` if the transaction is sponsored
79
+ return sponsored
80
+ ? BigInt(tokenReceived.amountSpent)
81
+ : BigInt(tokenReceived.destinationAmount);
82
+ }
83
+ async getIntentCost(input) {
84
+ return await this.fetch(`${this.serverUrl}/intents/cost`, {
85
+ method: 'POST',
86
+ headers: this.getHeaders(),
87
+ body: JSON.stringify((0, utils_1.convertBigIntFields)(input)),
88
+ });
89
+ }
90
+ async getIntentRoute(input) {
91
+ return await this.fetch(`${this.serverUrl}/intents/route`, {
92
+ method: 'POST',
93
+ headers: this.getHeaders(),
94
+ body: JSON.stringify((0, utils_1.convertBigIntFields)(input)),
95
+ });
96
+ }
97
+ async submitIntent(signedIntentOpUnformatted, dryRun) {
98
+ const signedIntentOp = (0, utils_1.convertBigIntFields)(signedIntentOpUnformatted);
99
+ if (dryRun) {
100
+ signedIntentOp.options = {
101
+ dryRun: true,
102
+ };
103
+ }
104
+ return await this.fetch(`${this.serverUrl}/intent-operations`, {
105
+ method: 'POST',
106
+ headers: this.getHeaders(),
107
+ body: JSON.stringify({
108
+ signedIntentOp,
109
+ }),
110
+ });
111
+ }
112
+ async getIntentOpStatus(intentId) {
113
+ return await this.fetch(`${this.serverUrl}/intent-operation/${intentId.toString()}`, {
114
+ headers: this.getHeaders(),
115
+ });
116
+ }
117
+ getHeaders() {
118
+ const headers = {
119
+ 'Content-Type': 'application/json',
120
+ };
121
+ if (this.apiKey) {
122
+ headers['x-api-key'] = this.apiKey;
123
+ }
124
+ return headers;
125
+ }
126
+ async fetch(url, options) {
127
+ const response = await fetch(url, options);
128
+ if (!response.ok) {
129
+ let errorData = {};
130
+ try {
131
+ errorData = await response.json();
132
+ }
133
+ catch {
134
+ try {
135
+ const text = await response.text();
136
+ errorData = { message: text };
137
+ }
138
+ catch { }
139
+ }
140
+ const retryAfterHeader = response.headers?.get?.('retry-after') || undefined;
141
+ this.parseError({
142
+ response: {
143
+ status: response.status,
144
+ data: errorData,
145
+ headers: {
146
+ retryAfter: retryAfterHeader,
147
+ },
148
+ },
149
+ });
150
+ }
151
+ return response.json();
152
+ }
153
+ parseError(error) {
154
+ if (error.response) {
155
+ const status = error.response.status;
156
+ const { headers } = error.response;
157
+ const { errors = [], traceId, message } = error.response.data || {};
158
+ let errorType = 'Unknown';
159
+ switch (status) {
160
+ case 400:
161
+ errorType = 'Bad Request';
162
+ break;
163
+ case 401:
164
+ errorType = 'Unauthorized';
165
+ break;
166
+ case 403:
167
+ errorType = 'Forbidden';
168
+ break;
169
+ case 404:
170
+ errorType = 'Not Found';
171
+ break;
172
+ case 409:
173
+ errorType = 'Conflict';
174
+ break;
175
+ case 422:
176
+ errorType = 'Unprocessable Entity';
177
+ break;
178
+ case 429:
179
+ errorType = 'Too Many Requests';
180
+ break;
181
+ case 500:
182
+ errorType = 'Internal Server Error';
183
+ break;
184
+ case 503:
185
+ errorType = 'Service Unavailable';
186
+ break;
187
+ default:
188
+ errorType = 'Unknown';
189
+ }
190
+ const baseParams = {
191
+ context: { traceId },
192
+ errorType,
193
+ traceId,
194
+ statusCode: status,
195
+ };
196
+ if (status === 429) {
197
+ const retryAfter = headers?.retryAfter;
198
+ const context = { traceId, retryAfter };
199
+ throw new error_1.RateLimitedError({
200
+ ...baseParams,
201
+ context,
202
+ });
203
+ }
204
+ if (status === 503) {
205
+ throw new error_1.ServiceUnavailableError(baseParams);
206
+ }
207
+ if (message) {
208
+ this.parseErrorMessage(message, baseParams);
209
+ }
210
+ for (const err of errors) {
211
+ const mergedParams = {
212
+ ...baseParams,
213
+ context: { ...err.context, traceId },
214
+ };
215
+ this.parseErrorMessage(err.message, mergedParams);
216
+ }
217
+ switch (status) {
218
+ case 400:
219
+ throw new error_1.BadRequestError({
220
+ ...baseParams,
221
+ context: { traceId, errors },
222
+ message: message,
223
+ });
224
+ case 401:
225
+ if (message === 'Authentication is required') {
226
+ throw new error_1.AuthenticationRequiredError(baseParams);
227
+ }
228
+ throw new error_1.UnauthorizedError(baseParams);
229
+ case 403:
230
+ throw new error_1.ForbiddenError(baseParams);
231
+ case 404:
232
+ throw new error_1.ResourceNotFoundError(baseParams);
233
+ case 409:
234
+ throw new error_1.ConflictError(baseParams);
235
+ case 500:
236
+ if (errors && errors.length > 0) {
237
+ const mergedParams = {
238
+ ...baseParams,
239
+ context: { ...errors[0].context, traceId },
240
+ };
241
+ throw new error_1.OrchestratorError({
242
+ ...mergedParams,
243
+ message: errors[0].message || 'Internal Server Error',
244
+ });
245
+ }
246
+ throw new error_1.InternalServerError(baseParams);
247
+ default:
248
+ throw new error_1.OrchestratorError({
249
+ ...baseParams,
250
+ message: message || errorType,
251
+ });
252
+ }
253
+ }
254
+ }
255
+ parseErrorMessage(message, errorParams) {
256
+ if (message === 'Insufficient balance') {
257
+ throw new error_1.InsufficientBalanceError(errorParams);
258
+ }
259
+ else if (message === 'Unsupported chain id' ||
260
+ message === 'Unsupported chain ids') {
261
+ throw new error_1.UnsupportedChainIdError(errorParams);
262
+ }
263
+ else if (message.startsWith('Unsupported chain ')) {
264
+ const chainIdMatch = message.match(/Unsupported chain (\d+)/);
265
+ if (chainIdMatch) {
266
+ const chainId = parseInt(chainIdMatch[1], 10);
267
+ throw new error_1.UnsupportedChainError(chainId, errorParams);
268
+ }
269
+ throw new error_1.UnsupportedChainIdError(errorParams);
270
+ }
271
+ else if (message.includes('Unsupported token') &&
272
+ message.includes('for chain')) {
273
+ const tokenMatch = message.match(/Unsupported token (\w+) for chain (\d+)/);
274
+ if (tokenMatch) {
275
+ const tokenSymbol = tokenMatch[1];
276
+ const chainId = parseInt(tokenMatch[2], 10);
277
+ throw new error_1.UnsupportedTokenError(tokenSymbol, chainId, errorParams);
278
+ }
279
+ throw new error_1.OrchestratorError({ message, ...errorParams });
280
+ }
281
+ else if (message === 'Unsupported token addresses') {
282
+ // generic unsupported tokens without specific symbol/chain context
283
+ throw new error_1.BadRequestError({ message, ...errorParams });
284
+ }
285
+ else if (message.includes('not supported on chain')) {
286
+ const tokenMatch = message.match(/Token (.+) not supported on chain (\d+)/);
287
+ if (tokenMatch) {
288
+ const tokenAddress = tokenMatch[1];
289
+ const chainId = parseInt(tokenMatch[2], 10);
290
+ throw new error_1.TokenNotSupportedError(tokenAddress, chainId, errorParams);
291
+ }
292
+ throw new error_1.OrchestratorError({ message, ...errorParams });
293
+ }
294
+ else if (message === 'Authentication is required') {
295
+ throw new error_1.AuthenticationRequiredError(errorParams);
296
+ }
297
+ else if (message === 'Invalid API key') {
298
+ throw new error_1.InvalidApiKeyError(errorParams);
299
+ }
300
+ else if (message === 'Insufficient permissions') {
301
+ throw new error_1.ForbiddenError(errorParams);
302
+ }
303
+ else if (message === 'Invalid bundle signature') {
304
+ throw new error_1.InvalidIntentSignatureError(errorParams);
305
+ }
306
+ else if (message === 'Invalid checksum signature') {
307
+ throw new error_1.InvalidIntentSignatureError(errorParams);
308
+ }
309
+ else if (message === 'Only one target token amount can be unset' ||
310
+ message === 'Only one max-out transfer is allowed') {
311
+ throw new error_1.OnlyOneTargetTokenAmountCanBeUnsetError(errorParams);
312
+ }
313
+ else if (message === 'No valid settlement plan found for the given transfers' ||
314
+ message === 'No valid transfers sent for settlement quotes' ||
315
+ message === 'No Path Found') {
316
+ throw new error_1.NoPathFoundError(errorParams);
317
+ }
318
+ else if (message === 'Emissary is not enabled' ||
319
+ message === 'Emissary is not the expected address') {
320
+ throw new error_1.ForbiddenError(errorParams);
321
+ }
322
+ else if (message.includes('No such intent with nonce') ||
323
+ message === 'Order bundle not found') {
324
+ throw new error_1.IntentNotFoundError(errorParams);
325
+ }
326
+ else if (message === 'Could not retrieve a valid quote from any aggregator') {
327
+ throw new error_1.NoPathFoundError(errorParams);
328
+ }
329
+ else if (message === 'No aggregators available for swap') {
330
+ throw new error_1.InternalServerError(errorParams);
331
+ }
332
+ else if (message === 'entity.parse.failed' ||
333
+ message === 'entity.too.large' ||
334
+ message === 'encoding.unsupported') {
335
+ throw new error_1.BodyParserError({ message, ...errorParams });
336
+ }
337
+ else if (message === 'Bundle simulation failed') {
338
+ const simulations = errorParams.context.error.simulations;
339
+ const { traceId, errorType, statusCode, context } = errorParams;
340
+ throw new error_1.SimulationFailedError({
341
+ message,
342
+ context,
343
+ errorType,
344
+ traceId,
345
+ statusCode,
346
+ simulations,
347
+ });
348
+ }
349
+ else {
350
+ throw new error_1.OrchestratorError({ message, ...errorParams });
351
+ }
352
+ }
353
+ }
354
+ exports.Orchestrator = Orchestrator;
@@ -0,0 +1,5 @@
1
+ declare const PROD_ORCHESTRATOR_URL = "https://v1.orchestrator.rhinestone.dev";
2
+ declare const STAGING_ORCHESTRATOR_URL = "https://staging.v1.orchestrator.rhinestone.dev";
3
+ declare const RHINESTONE_SPOKE_POOL_ADDRESS = "0x000000000060f6e853447881951574cdd0663530";
4
+ export { PROD_ORCHESTRATOR_URL, STAGING_ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS, };
5
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../orchestrator/consts.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,qBAAqB,2CAA2C,CAAA;AACtE,QAAA,MAAM,wBAAwB,mDACoB,CAAA;AAClD,QAAA,MAAM,6BAA6B,+CACW,CAAA;AAE9C,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,GAC9B,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RHINESTONE_SPOKE_POOL_ADDRESS = exports.STAGING_ORCHESTRATOR_URL = exports.PROD_ORCHESTRATOR_URL = void 0;
4
+ const PROD_ORCHESTRATOR_URL = 'https://v1.orchestrator.rhinestone.dev';
5
+ exports.PROD_ORCHESTRATOR_URL = PROD_ORCHESTRATOR_URL;
6
+ const STAGING_ORCHESTRATOR_URL = 'https://staging.v1.orchestrator.rhinestone.dev';
7
+ exports.STAGING_ORCHESTRATOR_URL = STAGING_ORCHESTRATOR_URL;
8
+ const RHINESTONE_SPOKE_POOL_ADDRESS = '0x000000000060f6e853447881951574cdd0663530';
9
+ exports.RHINESTONE_SPOKE_POOL_ADDRESS = RHINESTONE_SPOKE_POOL_ADDRESS;