@rhinestone/sdk 1.0.41-alpha.0 → 1.0.41-alpha.1

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 +422 -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 +201 -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 +146 -0
  110. package/dist/src/execution/compact.d.ts.map +1 -0
  111. package/dist/src/execution/compact.js +116 -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 +143 -0
  119. package/dist/src/execution/permit2.d.ts.map +1 -0
  120. package/dist/src/execution/permit2.js +285 -0
  121. package/dist/src/execution/singleChainOps.d.ts +40 -0
  122. package/dist/src/execution/singleChainOps.d.ts.map +1 -0
  123. package/dist/src/execution/singleChainOps.js +46 -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 +701 -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 +298 -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 +278 -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,143 @@
1
+ import { type Address, type Chain } from 'viem';
2
+ import type { IntentOpElement } from '../orchestrator/types';
3
+ import type { RhinestoneConfig } from '../types';
4
+ import type { BatchPermit2Result, MultiChainPermit2Config, MultiChainPermit2Result, TokenPermissions } from './types';
5
+ declare function getTypedData(element: IntentOpElement, nonce: bigint, expires: bigint): {
6
+ readonly domain: {
7
+ readonly name: "Permit2";
8
+ readonly chainId: number;
9
+ readonly verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
10
+ };
11
+ readonly types: {
12
+ readonly TokenPermissions: readonly [{
13
+ readonly name: "token";
14
+ readonly type: "address";
15
+ }, {
16
+ readonly name: "amount";
17
+ readonly type: "uint256";
18
+ }];
19
+ readonly Token: readonly [{
20
+ readonly name: "token";
21
+ readonly type: "address";
22
+ }, {
23
+ readonly name: "amount";
24
+ readonly type: "uint256";
25
+ }];
26
+ readonly Target: readonly [{
27
+ readonly name: "recipient";
28
+ readonly type: "address";
29
+ }, {
30
+ readonly name: "tokenOut";
31
+ readonly type: "Token[]";
32
+ }, {
33
+ readonly name: "targetChain";
34
+ readonly type: "uint256";
35
+ }, {
36
+ readonly name: "fillExpiry";
37
+ readonly type: "uint256";
38
+ }];
39
+ readonly Ops: readonly [{
40
+ readonly name: "to";
41
+ readonly type: "address";
42
+ }, {
43
+ readonly name: "value";
44
+ readonly type: "uint256";
45
+ }, {
46
+ readonly name: "data";
47
+ readonly type: "bytes";
48
+ }];
49
+ readonly Op: readonly [{
50
+ readonly name: "vt";
51
+ readonly type: "bytes32";
52
+ }, {
53
+ readonly name: "ops";
54
+ readonly type: "Ops[]";
55
+ }];
56
+ readonly Mandate: readonly [{
57
+ readonly name: "target";
58
+ readonly type: "Target";
59
+ }, {
60
+ readonly name: "minGas";
61
+ readonly type: "uint128";
62
+ }, {
63
+ readonly name: "originOps";
64
+ readonly type: "Op";
65
+ }, {
66
+ readonly name: "destOps";
67
+ readonly type: "Op";
68
+ }, {
69
+ readonly name: "q";
70
+ readonly type: "bytes32";
71
+ }];
72
+ readonly PermitBatchWitnessTransferFrom: readonly [{
73
+ readonly name: "permitted";
74
+ readonly type: "TokenPermissions[]";
75
+ }, {
76
+ readonly name: "spender";
77
+ readonly type: "address";
78
+ }, {
79
+ readonly name: "nonce";
80
+ readonly type: "uint256";
81
+ }, {
82
+ readonly name: "deadline";
83
+ readonly type: "uint256";
84
+ }, {
85
+ readonly name: "mandate";
86
+ readonly type: "Mandate";
87
+ }];
88
+ };
89
+ readonly primaryType: "PermitBatchWitnessTransferFrom";
90
+ readonly message: {
91
+ readonly permitted: TokenPermissions[];
92
+ readonly spender: `0x${string}`;
93
+ readonly nonce: bigint;
94
+ readonly deadline: bigint;
95
+ readonly mandate: {
96
+ readonly target: {
97
+ readonly recipient: `0x${string}`;
98
+ readonly tokenOut: {
99
+ token: `0x${string}`;
100
+ amount: bigint;
101
+ }[];
102
+ readonly targetChain: bigint;
103
+ readonly fillExpiry: bigint;
104
+ };
105
+ readonly minGas: bigint;
106
+ readonly originOps: import("../orchestrator/types").Op;
107
+ readonly destOps: import("../orchestrator/types").Op;
108
+ readonly q: `0x${string}`;
109
+ };
110
+ };
111
+ };
112
+ declare function checkERC20AllowanceDirect(owner: Address, spender: Address, tokenAddress: Address, publicClient: any): Promise<bigint>;
113
+ declare function checkERC20Allowance(tokenAddress: Address, chain: Chain, config: RhinestoneConfig): Promise<bigint>;
114
+ /**
115
+ * Get the Permit2 contract address
116
+ * @returns The Permit2 contract address
117
+ */
118
+ declare function getPermit2Address(): Address;
119
+ /**
120
+ * Signs permit2 calls across multiple chains using batch approach.
121
+ * Collects all signatures first, then returns them all at once.
122
+ *
123
+ * This approach is efficient for backend signers but may be memory-intensive
124
+ * for frontend applications with many chains.
125
+ *
126
+ * @param configs - Array of permit2 signing configurations for different chains
127
+ * @returns Promise<BatchPermit2Result> - All signatures collected
128
+ */
129
+ declare function signPermit2Batch(configs: MultiChainPermit2Config[]): Promise<BatchPermit2Result>;
130
+ /**
131
+ * Signs permit2 calls across multiple chains sequentially.
132
+ * Signs one by one, useful for frontend applications to avoid memory issues.
133
+ *
134
+ * This approach is more memory-efficient for frontend applications but slower
135
+ * due to sequential processing.
136
+ *
137
+ * @param configs - Array of permit2 signing configurations for different chains
138
+ * @param onProgress - Optional callback for progress updates
139
+ * @returns Promise<BatchPermit2Result> - All signatures collected
140
+ */
141
+ declare function signPermit2Sequential(configs: MultiChainPermit2Config[], onProgress?: (completed: number, total: number, current: MultiChainPermit2Result) => void): Promise<BatchPermit2Result>;
142
+ export { getTypedData, checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address, signPermit2Batch, signPermit2Sequential, type MultiChainPermit2Config, type MultiChainPermit2Result, type BatchPermit2Result, };
143
+ //# sourceMappingURL=permit2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["../../../execution/permit2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,KAAK,EAIX,MAAM,MAAM,CAAA;AAEb,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAQhB,iBAAS,YAAY,CACnB,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwFhB;AAED,iBAAe,yBAAyB,CACtC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,OAAO,EACrB,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,iBAAe,mBAAmB,CAChC,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED;;;GAGG;AACH,iBAAS,iBAAiB,IAAI,OAAO,CAEpC;AAED;;;;;;;;;GASG;AACH,iBAAe,gBAAgB,CAC7B,OAAO,EAAE,uBAAuB,EAAE,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAyE7B;AAED;;;;;;;;;;GAUG;AACH,iBAAe,qBAAqB,CAClC,OAAO,EAAE,uBAAuB,EAAE,EAClC,UAAU,CAAC,EAAE,CACX,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,KAC7B,IAAI,GACR,OAAO,CAAC,kBAAkB,CAAC,CA8D7B;AAED,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,gBAAgB,EAChB,qBAAqB,EAErB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,GACxB,CAAA"}
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypedData = getTypedData;
4
+ exports.checkERC20Allowance = checkERC20Allowance;
5
+ exports.checkERC20AllowanceDirect = checkERC20AllowanceDirect;
6
+ exports.getPermit2Address = getPermit2Address;
7
+ exports.signPermit2Batch = signPermit2Batch;
8
+ exports.signPermit2Sequential = signPermit2Sequential;
9
+ const viem_1 = require("viem");
10
+ const utils_1 = require("../accounts/utils");
11
+ const PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
12
+ function toToken(id) {
13
+ return `0x${(id & ((1n << 160n) - 1n)).toString(16).padStart(40, '0')}`;
14
+ }
15
+ function getTypedData(element, nonce, expires) {
16
+ const tokens = element.idsAndAmounts.map(([id, amount]) => [
17
+ BigInt(id),
18
+ BigInt(amount),
19
+ ]);
20
+ const tokenPermissions = tokens.reduce((permissions, [id, amountIn]) => {
21
+ const token = toToken(BigInt(id));
22
+ const amount = BigInt(amountIn);
23
+ const permission = { token, amount };
24
+ permissions.push(permission);
25
+ return permissions;
26
+ }, []);
27
+ const spender = element.arbiter;
28
+ const mandate = element.mandate;
29
+ const typedData = {
30
+ domain: {
31
+ name: 'Permit2',
32
+ chainId: Number(element.chainId),
33
+ verifyingContract: PERMIT2_ADDRESS,
34
+ },
35
+ types: {
36
+ TokenPermissions: [
37
+ { name: 'token', type: 'address' },
38
+ { name: 'amount', type: 'uint256' },
39
+ ],
40
+ Token: [
41
+ { name: 'token', type: 'address' },
42
+ { name: 'amount', type: 'uint256' },
43
+ ],
44
+ Target: [
45
+ { name: 'recipient', type: 'address' },
46
+ { name: 'tokenOut', type: 'Token[]' },
47
+ { name: 'targetChain', type: 'uint256' },
48
+ { name: 'fillExpiry', type: 'uint256' },
49
+ ],
50
+ Ops: [
51
+ { name: 'to', type: 'address' },
52
+ { name: 'value', type: 'uint256' },
53
+ { name: 'data', type: 'bytes' },
54
+ ],
55
+ Op: [
56
+ { name: 'vt', type: 'bytes32' },
57
+ { name: 'ops', type: 'Ops[]' },
58
+ ],
59
+ Mandate: [
60
+ { name: 'target', type: 'Target' },
61
+ { name: 'minGas', type: 'uint128' },
62
+ { name: 'originOps', type: 'Op' },
63
+ { name: 'destOps', type: 'Op' },
64
+ { name: 'q', type: 'bytes32' },
65
+ ],
66
+ PermitBatchWitnessTransferFrom: [
67
+ { name: 'permitted', type: 'TokenPermissions[]' },
68
+ { name: 'spender', type: 'address' },
69
+ { name: 'nonce', type: 'uint256' },
70
+ { name: 'deadline', type: 'uint256' },
71
+ { name: 'mandate', type: 'Mandate' },
72
+ ],
73
+ },
74
+ primaryType: 'PermitBatchWitnessTransferFrom',
75
+ message: {
76
+ permitted: tokenPermissions,
77
+ spender: spender,
78
+ nonce: nonce,
79
+ deadline: expires,
80
+ mandate: {
81
+ target: {
82
+ recipient: mandate.recipient,
83
+ tokenOut: mandate.tokenOut.map((token) => ({
84
+ token: toToken(BigInt(token[0])),
85
+ amount: BigInt(token[1]),
86
+ })),
87
+ targetChain: BigInt(mandate.destinationChainId),
88
+ fillExpiry: BigInt(mandate.fillDeadline),
89
+ },
90
+ minGas: BigInt(mandate.minGas),
91
+ originOps: mandate.preClaimOps,
92
+ destOps: mandate.destinationOps,
93
+ q: (0, viem_1.keccak256)(mandate.qualifier.encodedVal),
94
+ },
95
+ },
96
+ };
97
+ return typedData;
98
+ }
99
+ async function checkERC20AllowanceDirect(owner, spender, tokenAddress, publicClient) {
100
+ try {
101
+ const allowance = await publicClient.readContract({
102
+ address: tokenAddress,
103
+ abi: [
104
+ {
105
+ name: 'allowance',
106
+ type: 'function',
107
+ stateMutability: 'view',
108
+ inputs: [
109
+ { name: 'owner', type: 'address' },
110
+ { name: 'spender', type: 'address' },
111
+ ],
112
+ outputs: [{ name: '', type: 'uint256' }],
113
+ },
114
+ ],
115
+ functionName: 'allowance',
116
+ args: [owner, spender],
117
+ });
118
+ return BigInt(allowance.toString());
119
+ }
120
+ catch (error) {
121
+ console.error('Error checking ERC20 allowance:', error);
122
+ throw new Error('Failed to check ERC20 allowance');
123
+ }
124
+ }
125
+ async function checkERC20Allowance(tokenAddress, chain, config) {
126
+ try {
127
+ const publicClient = (0, viem_1.createPublicClient)({
128
+ chain,
129
+ transport: (0, utils_1.createTransport)(chain, config.provider),
130
+ });
131
+ // Get the account owner from the config
132
+ const owner = config.eoa?.address;
133
+ if (!owner) {
134
+ throw new Error('No EOA address found in account config');
135
+ }
136
+ return await checkERC20AllowanceDirect(owner, PERMIT2_ADDRESS, tokenAddress, publicClient);
137
+ }
138
+ catch (error) {
139
+ console.error('Error checking ERC20 allowance:', error);
140
+ throw new Error('Failed to check ERC20 allowance');
141
+ }
142
+ }
143
+ /**
144
+ * Get the Permit2 contract address
145
+ * @returns The Permit2 contract address
146
+ */
147
+ function getPermit2Address() {
148
+ return PERMIT2_ADDRESS;
149
+ }
150
+ /**
151
+ * Signs permit2 calls across multiple chains using batch approach.
152
+ * Collects all signatures first, then returns them all at once.
153
+ *
154
+ * This approach is efficient for backend signers but may be memory-intensive
155
+ * for frontend applications with many chains.
156
+ *
157
+ * @param configs - Array of permit2 signing configurations for different chains
158
+ * @returns Promise<BatchPermit2Result> - All signatures collected
159
+ */
160
+ async function signPermit2Batch(configs) {
161
+ const results = [];
162
+ let successfulSignatures = 0;
163
+ let failedSignatures = 0;
164
+ // Process all signing operations in parallel
165
+ const signingPromises = configs.map(async (config) => {
166
+ try {
167
+ // sign each element individually for this chain sequentially to preserve order
168
+ if (!config.eoaAccount.signTypedData) {
169
+ throw new Error('EOA account does not support typed data signing');
170
+ }
171
+ const originSignatures = [];
172
+ for (const element of config.intentOp.elements) {
173
+ const typedData = getTypedData(element, BigInt(config.intentOp.nonce), BigInt(config.intentOp.expires));
174
+ const sig = await config.eoaAccount.signTypedData(typedData);
175
+ originSignatures.push(sig);
176
+ }
177
+ const result = {
178
+ chainId: config.chain.id,
179
+ originSignatures,
180
+ destinationSignature: originSignatures[0] ?? '0x',
181
+ success: true,
182
+ };
183
+ successfulSignatures++;
184
+ return result;
185
+ }
186
+ catch (error) {
187
+ const result = {
188
+ chainId: config.chain.id,
189
+ originSignatures: [],
190
+ destinationSignature: '0x',
191
+ success: false,
192
+ error: error instanceof Error ? error : new Error(String(error)),
193
+ };
194
+ failedSignatures++;
195
+ return result;
196
+ }
197
+ });
198
+ // Wait for all signing operations to complete
199
+ const signingResults = await Promise.allSettled(signingPromises);
200
+ for (const result of signingResults) {
201
+ if (result.status === 'fulfilled') {
202
+ results.push(result.value);
203
+ }
204
+ else {
205
+ // This shouldn't happen since we catch errors in the promise
206
+ failedSignatures++;
207
+ results.push({
208
+ chainId: 0,
209
+ originSignatures: [],
210
+ destinationSignature: '0x',
211
+ success: false,
212
+ error: result.reason,
213
+ });
214
+ }
215
+ }
216
+ return {
217
+ results,
218
+ totalChains: configs.length,
219
+ successfulSignatures,
220
+ failedSignatures,
221
+ allSuccessful: failedSignatures === 0,
222
+ };
223
+ }
224
+ /**
225
+ * Signs permit2 calls across multiple chains sequentially.
226
+ * Signs one by one, useful for frontend applications to avoid memory issues.
227
+ *
228
+ * This approach is more memory-efficient for frontend applications but slower
229
+ * due to sequential processing.
230
+ *
231
+ * @param configs - Array of permit2 signing configurations for different chains
232
+ * @param onProgress - Optional callback for progress updates
233
+ * @returns Promise<BatchPermit2Result> - All signatures collected
234
+ */
235
+ async function signPermit2Sequential(configs, onProgress) {
236
+ const results = [];
237
+ let successfulSignatures = 0;
238
+ let failedSignatures = 0;
239
+ // Process signing operations sequentially
240
+ for (let i = 0; i < configs.length; i++) {
241
+ const config = configs[i];
242
+ try {
243
+ // sign each element for this chain sequentially to preserve order
244
+ if (!config.eoaAccount.signTypedData) {
245
+ throw new Error('EOA account does not support typed data signing');
246
+ }
247
+ const originSignatures = [];
248
+ for (const element of config.intentOp.elements) {
249
+ const typedData = getTypedData(element, BigInt(config.intentOp.nonce), BigInt(config.intentOp.expires));
250
+ const sig = await config.eoaAccount.signTypedData(typedData);
251
+ originSignatures.push(sig);
252
+ }
253
+ const result = {
254
+ chainId: config.chain.id,
255
+ originSignatures,
256
+ destinationSignature: originSignatures[0] ?? '0x',
257
+ success: true,
258
+ };
259
+ results.push(result);
260
+ successfulSignatures++;
261
+ // Call progress callback if provided
262
+ onProgress?.(i + 1, configs.length, result);
263
+ }
264
+ catch (error) {
265
+ const result = {
266
+ chainId: config.chain.id,
267
+ originSignatures: [],
268
+ destinationSignature: '0x',
269
+ success: false,
270
+ error: error instanceof Error ? error : new Error(String(error)),
271
+ };
272
+ results.push(result);
273
+ failedSignatures++;
274
+ // Call progress callback if provided
275
+ onProgress?.(i + 1, configs.length, result);
276
+ }
277
+ }
278
+ return {
279
+ results,
280
+ totalChains: configs.length,
281
+ successfulSignatures,
282
+ failedSignatures,
283
+ allSuccessful: failedSignatures === 0,
284
+ };
285
+ }
@@ -0,0 +1,40 @@
1
+ import { type Address } from 'viem';
2
+ import type { IntentOpElement } from '../orchestrator/types';
3
+ declare function getTypedData(account: Address, intentExecutorAddress: Address, element: IntentOpElement, nonce: bigint): {
4
+ domain: {
5
+ name: string;
6
+ version: string;
7
+ chainId: number;
8
+ verifyingContract: `0x${string}`;
9
+ };
10
+ types: {
11
+ SingleChainOps: {
12
+ name: string;
13
+ type: string;
14
+ }[];
15
+ Op: {
16
+ name: string;
17
+ type: string;
18
+ }[];
19
+ GasRefund: {
20
+ name: string;
21
+ type: string;
22
+ }[];
23
+ Ops: {
24
+ name: string;
25
+ type: string;
26
+ }[];
27
+ };
28
+ primaryType: "SingleChainOps";
29
+ message: {
30
+ account: `0x${string}`;
31
+ nonce: bigint;
32
+ op: import("../orchestrator/types").Op;
33
+ gasRefund: {
34
+ token: "0x0000000000000000000000000000000000000000";
35
+ exchangeRate: bigint;
36
+ };
37
+ };
38
+ };
39
+ export { getTypedData };
40
+ //# sourceMappingURL=singleChainOps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleChainOps.d.ts","sourceRoot":"","sources":["../../../execution/singleChainOps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAe,MAAM,MAAM,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,iBAAS,YAAY,CACnB,OAAO,EAAE,OAAO,EAChB,qBAAqB,EAAE,OAAO,EAC9B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0Cd;AACD,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypedData = getTypedData;
4
+ const viem_1 = require("viem");
5
+ function getTypedData(account, intentExecutorAddress, element, nonce) {
6
+ return {
7
+ domain: {
8
+ name: 'IntentExecutor',
9
+ version: 'v0.0.1',
10
+ chainId: Number(element.mandate.destinationChainId),
11
+ verifyingContract: intentExecutorAddress,
12
+ },
13
+ types: {
14
+ SingleChainOps: [
15
+ { name: 'account', type: 'address' },
16
+ { name: 'nonce', type: 'uint256' },
17
+ { name: 'op', type: 'Op' },
18
+ { name: 'gasRefund', type: 'GasRefund' },
19
+ ],
20
+ Op: [
21
+ { name: 'vt', type: 'bytes32' },
22
+ { name: 'ops', type: 'Ops[]' },
23
+ ],
24
+ GasRefund: [
25
+ { name: 'token', type: 'address' },
26
+ { name: 'exchangeRate', type: 'uint256' },
27
+ ],
28
+ Ops: [
29
+ { name: 'to', type: 'address' },
30
+ { name: 'value', type: 'uint256' },
31
+ { name: 'data', type: 'bytes' },
32
+ ],
33
+ },
34
+ primaryType: 'SingleChainOps',
35
+ message: {
36
+ account,
37
+ nonce,
38
+ op: element.mandate.destinationOps,
39
+ // todo
40
+ gasRefund: {
41
+ token: viem_1.zeroAddress,
42
+ exchangeRate: 0n,
43
+ },
44
+ },
45
+ };
46
+ }
@@ -0,0 +1,13 @@
1
+ import { type Chain, type Hex } from 'viem';
2
+ import { type EnableSessionData } from '../modules/validators/smart-sessions';
3
+ import type { RhinestoneConfig, Session } from '../types';
4
+ interface SessionDetails {
5
+ signature: Hex;
6
+ nonces: bigint[];
7
+ enableSessionData: EnableSessionData;
8
+ }
9
+ declare function getSessionDetails(config: RhinestoneConfig, sessions: Session[], sessionIndex: number, initialNonces?: bigint[], signature?: Hex): Promise<SessionDetails>;
10
+ declare function enableSmartSession(chain: Chain, config: RhinestoneConfig, session: Session): Promise<void>;
11
+ export { enableSmartSession, getSessionDetails };
12
+ export type { SessionDetails };
13
+ //# sourceMappingURL=smart-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-session.d.ts","sourceRoot":"","sources":["../../../execution/smart-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAEV,KAAK,GAAG,EAIT,MAAM,MAAM,CAAA;AAiBb,OAAO,EACL,KAAK,iBAAiB,EAKvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGzD,UAAU,cAAc;IACtB,SAAS,EAAE,GAAG,CAAA;IACd,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,iBAAiB,EAAE,iBAAiB,CAAA;CACrC;AA6CD,iBAAe,iBAAiB,CAC9B,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,cAAc,CAAC,CAiHzB;AA+BD,iBAAe,kBAAkB,CAC/B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,OAAO,iBA2BjB;AAED,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,CAAA"}