@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,148 @@
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 Op: 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 Mandate: readonly [{
50
+ readonly name: "target";
51
+ readonly type: "Target";
52
+ }, {
53
+ readonly name: "v";
54
+ readonly type: "uint8";
55
+ }, {
56
+ readonly name: "minGas";
57
+ readonly type: "uint128";
58
+ }, {
59
+ readonly name: "originOps";
60
+ readonly type: "Op[]";
61
+ }, {
62
+ readonly name: "destOps";
63
+ readonly type: "Op[]";
64
+ }, {
65
+ readonly name: "q";
66
+ readonly type: "bytes32";
67
+ }];
68
+ readonly PermitBatchWitnessTransferFrom: readonly [{
69
+ readonly name: "permitted";
70
+ readonly type: "TokenPermissions[]";
71
+ }, {
72
+ readonly name: "spender";
73
+ readonly type: "address";
74
+ }, {
75
+ readonly name: "nonce";
76
+ readonly type: "uint256";
77
+ }, {
78
+ readonly name: "deadline";
79
+ readonly type: "uint256";
80
+ }, {
81
+ readonly name: "mandate";
82
+ readonly type: "Mandate";
83
+ }];
84
+ };
85
+ readonly primaryType: "PermitBatchWitnessTransferFrom";
86
+ readonly message: {
87
+ readonly permitted: TokenPermissions[];
88
+ readonly spender: `0x${string}`;
89
+ readonly nonce: bigint;
90
+ readonly deadline: bigint;
91
+ readonly mandate: {
92
+ readonly target: {
93
+ readonly recipient: `0x${string}`;
94
+ readonly tokenOut: {
95
+ token: `0x${string}`;
96
+ amount: bigint;
97
+ }[];
98
+ readonly targetChain: bigint;
99
+ readonly fillExpiry: bigint;
100
+ };
101
+ readonly v: number;
102
+ readonly minGas: bigint;
103
+ readonly originOps: {
104
+ to: `0x${string}`;
105
+ value: bigint;
106
+ data: `0x${string}`;
107
+ }[];
108
+ readonly destOps: {
109
+ to: `0x${string}`;
110
+ value: bigint;
111
+ data: `0x${string}`;
112
+ }[];
113
+ readonly q: `0x${string}`;
114
+ };
115
+ };
116
+ };
117
+ declare function checkERC20AllowanceDirect(owner: Address, spender: Address, tokenAddress: Address, publicClient: any): Promise<bigint>;
118
+ declare function checkERC20Allowance(tokenAddress: Address, chain: Chain, config: RhinestoneConfig): Promise<bigint>;
119
+ /**
120
+ * Get the Permit2 contract address
121
+ * @returns The Permit2 contract address
122
+ */
123
+ declare function getPermit2Address(): Address;
124
+ /**
125
+ * Signs permit2 calls across multiple chains using batch approach.
126
+ * Collects all signatures first, then returns them all at once.
127
+ *
128
+ * This approach is efficient for backend signers but may be memory-intensive
129
+ * for frontend applications with many chains.
130
+ *
131
+ * @param configs - Array of permit2 signing configurations for different chains
132
+ * @returns Promise<BatchPermit2Result> - All signatures collected
133
+ */
134
+ declare function signPermit2Batch(configs: MultiChainPermit2Config[]): Promise<BatchPermit2Result>;
135
+ /**
136
+ * Signs permit2 calls across multiple chains sequentially.
137
+ * Signs one by one, useful for frontend applications to avoid memory issues.
138
+ *
139
+ * This approach is more memory-efficient for frontend applications but slower
140
+ * due to sequential processing.
141
+ *
142
+ * @param configs - Array of permit2 signing configurations for different chains
143
+ * @param onProgress - Optional callback for progress updates
144
+ * @returns Promise<BatchPermit2Result> - All signatures collected
145
+ */
146
+ declare function signPermit2Sequential(configs: MultiChainPermit2Config[], onProgress?: (completed: number, total: number, current: MultiChainPermit2Result) => void): Promise<BatchPermit2Result>;
147
+ export { getTypedData, checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address, signPermit2Batch, signPermit2Sequential, type MultiChainPermit2Config, type MultiChainPermit2Result, type BatchPermit2Result, };
148
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8FhB;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,291 @@
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
+ Op: [
51
+ { name: 'to', type: 'address' },
52
+ { name: 'value', type: 'uint256' },
53
+ { name: 'data', type: 'bytes' },
54
+ ],
55
+ Mandate: [
56
+ { name: 'target', type: 'Target' },
57
+ { name: 'v', type: 'uint8' },
58
+ { name: 'minGas', type: 'uint128' },
59
+ { name: 'originOps', type: 'Op[]' },
60
+ { name: 'destOps', type: 'Op[]' },
61
+ { name: 'q', type: 'bytes32' },
62
+ ],
63
+ PermitBatchWitnessTransferFrom: [
64
+ { name: 'permitted', type: 'TokenPermissions[]' },
65
+ { name: 'spender', type: 'address' },
66
+ { name: 'nonce', type: 'uint256' },
67
+ { name: 'deadline', type: 'uint256' },
68
+ { name: 'mandate', type: 'Mandate' },
69
+ ],
70
+ },
71
+ primaryType: 'PermitBatchWitnessTransferFrom',
72
+ message: {
73
+ permitted: tokenPermissions,
74
+ spender: spender,
75
+ nonce: nonce,
76
+ deadline: expires,
77
+ mandate: {
78
+ target: {
79
+ recipient: mandate.recipient,
80
+ tokenOut: mandate.tokenOut.map((token) => ({
81
+ token: toToken(BigInt(token[0])),
82
+ amount: BigInt(token[1]),
83
+ })),
84
+ targetChain: BigInt(mandate.destinationChainId),
85
+ fillExpiry: BigInt(mandate.fillDeadline),
86
+ },
87
+ v: mandate.v,
88
+ minGas: BigInt(mandate.minGas),
89
+ originOps: mandate.preClaimOps.map((op) => ({
90
+ to: op.to,
91
+ value: BigInt(op.value),
92
+ data: op.data,
93
+ })),
94
+ destOps: mandate.destinationOps.map((op) => ({
95
+ to: op.to,
96
+ value: BigInt(op.value),
97
+ data: op.data,
98
+ })),
99
+ q: (0, viem_1.keccak256)(mandate.qualifier.encodedVal),
100
+ },
101
+ },
102
+ };
103
+ return typedData;
104
+ }
105
+ async function checkERC20AllowanceDirect(owner, spender, tokenAddress, publicClient) {
106
+ try {
107
+ const allowance = await publicClient.readContract({
108
+ address: tokenAddress,
109
+ abi: [
110
+ {
111
+ name: 'allowance',
112
+ type: 'function',
113
+ stateMutability: 'view',
114
+ inputs: [
115
+ { name: 'owner', type: 'address' },
116
+ { name: 'spender', type: 'address' },
117
+ ],
118
+ outputs: [{ name: '', type: 'uint256' }],
119
+ },
120
+ ],
121
+ functionName: 'allowance',
122
+ args: [owner, spender],
123
+ });
124
+ return BigInt(allowance.toString());
125
+ }
126
+ catch (error) {
127
+ console.error('Error checking ERC20 allowance:', error);
128
+ throw new Error('Failed to check ERC20 allowance');
129
+ }
130
+ }
131
+ async function checkERC20Allowance(tokenAddress, chain, config) {
132
+ try {
133
+ const publicClient = (0, viem_1.createPublicClient)({
134
+ chain,
135
+ transport: (0, utils_1.createTransport)(chain, config.provider),
136
+ });
137
+ // Get the account owner from the config
138
+ const owner = config.eoa?.address;
139
+ if (!owner) {
140
+ throw new Error('No EOA address found in account config');
141
+ }
142
+ return await checkERC20AllowanceDirect(owner, PERMIT2_ADDRESS, tokenAddress, publicClient);
143
+ }
144
+ catch (error) {
145
+ console.error('Error checking ERC20 allowance:', error);
146
+ throw new Error('Failed to check ERC20 allowance');
147
+ }
148
+ }
149
+ /**
150
+ * Get the Permit2 contract address
151
+ * @returns The Permit2 contract address
152
+ */
153
+ function getPermit2Address() {
154
+ return PERMIT2_ADDRESS;
155
+ }
156
+ /**
157
+ * Signs permit2 calls across multiple chains using batch approach.
158
+ * Collects all signatures first, then returns them all at once.
159
+ *
160
+ * This approach is efficient for backend signers but may be memory-intensive
161
+ * for frontend applications with many chains.
162
+ *
163
+ * @param configs - Array of permit2 signing configurations for different chains
164
+ * @returns Promise<BatchPermit2Result> - All signatures collected
165
+ */
166
+ async function signPermit2Batch(configs) {
167
+ const results = [];
168
+ let successfulSignatures = 0;
169
+ let failedSignatures = 0;
170
+ // Process all signing operations in parallel
171
+ const signingPromises = configs.map(async (config) => {
172
+ try {
173
+ // sign each element individually for this chain sequentially to preserve order
174
+ if (!config.eoaAccount.signTypedData) {
175
+ throw new Error('EOA account does not support typed data signing');
176
+ }
177
+ const originSignatures = [];
178
+ for (const element of config.intentOp.elements) {
179
+ const typedData = getTypedData(element, BigInt(config.intentOp.nonce), BigInt(config.intentOp.expires));
180
+ const sig = await config.eoaAccount.signTypedData(typedData);
181
+ originSignatures.push(sig);
182
+ }
183
+ const result = {
184
+ chainId: config.chain.id,
185
+ originSignatures,
186
+ destinationSignature: originSignatures[0] ?? '0x',
187
+ success: true,
188
+ };
189
+ successfulSignatures++;
190
+ return result;
191
+ }
192
+ catch (error) {
193
+ const result = {
194
+ chainId: config.chain.id,
195
+ originSignatures: [],
196
+ destinationSignature: '0x',
197
+ success: false,
198
+ error: error instanceof Error ? error : new Error(String(error)),
199
+ };
200
+ failedSignatures++;
201
+ return result;
202
+ }
203
+ });
204
+ // Wait for all signing operations to complete
205
+ const signingResults = await Promise.allSettled(signingPromises);
206
+ for (const result of signingResults) {
207
+ if (result.status === 'fulfilled') {
208
+ results.push(result.value);
209
+ }
210
+ else {
211
+ // This shouldn't happen since we catch errors in the promise
212
+ failedSignatures++;
213
+ results.push({
214
+ chainId: 0,
215
+ originSignatures: [],
216
+ destinationSignature: '0x',
217
+ success: false,
218
+ error: result.reason,
219
+ });
220
+ }
221
+ }
222
+ return {
223
+ results,
224
+ totalChains: configs.length,
225
+ successfulSignatures,
226
+ failedSignatures,
227
+ allSuccessful: failedSignatures === 0,
228
+ };
229
+ }
230
+ /**
231
+ * Signs permit2 calls across multiple chains sequentially.
232
+ * Signs one by one, useful for frontend applications to avoid memory issues.
233
+ *
234
+ * This approach is more memory-efficient for frontend applications but slower
235
+ * due to sequential processing.
236
+ *
237
+ * @param configs - Array of permit2 signing configurations for different chains
238
+ * @param onProgress - Optional callback for progress updates
239
+ * @returns Promise<BatchPermit2Result> - All signatures collected
240
+ */
241
+ async function signPermit2Sequential(configs, onProgress) {
242
+ const results = [];
243
+ let successfulSignatures = 0;
244
+ let failedSignatures = 0;
245
+ // Process signing operations sequentially
246
+ for (let i = 0; i < configs.length; i++) {
247
+ const config = configs[i];
248
+ try {
249
+ // sign each element for this chain sequentially to preserve order
250
+ if (!config.eoaAccount.signTypedData) {
251
+ throw new Error('EOA account does not support typed data signing');
252
+ }
253
+ const originSignatures = [];
254
+ for (const element of config.intentOp.elements) {
255
+ const typedData = getTypedData(element, BigInt(config.intentOp.nonce), BigInt(config.intentOp.expires));
256
+ const sig = await config.eoaAccount.signTypedData(typedData);
257
+ originSignatures.push(sig);
258
+ }
259
+ const result = {
260
+ chainId: config.chain.id,
261
+ originSignatures,
262
+ destinationSignature: originSignatures[0] ?? '0x',
263
+ success: true,
264
+ };
265
+ results.push(result);
266
+ successfulSignatures++;
267
+ // Call progress callback if provided
268
+ onProgress?.(i + 1, configs.length, result);
269
+ }
270
+ catch (error) {
271
+ const result = {
272
+ chainId: config.chain.id,
273
+ originSignatures: [],
274
+ destinationSignature: '0x',
275
+ success: false,
276
+ error: error instanceof Error ? error : new Error(String(error)),
277
+ };
278
+ results.push(result);
279
+ failedSignatures++;
280
+ // Call progress callback if provided
281
+ onProgress?.(i + 1, configs.length, result);
282
+ }
283
+ }
284
+ return {
285
+ results,
286
+ totalChains: configs.length,
287
+ successfulSignatures,
288
+ failedSignatures,
289
+ allSuccessful: failedSignatures === 0,
290
+ };
291
+ }
@@ -0,0 +1,28 @@
1
+ import type { Address } from 'viem';
2
+ import type { Execution, 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
+ };
20
+ primaryType: "SingleChainOps";
21
+ message: {
22
+ account: `0x${string}`;
23
+ nonce: bigint;
24
+ ops: Execution[];
25
+ };
26
+ };
27
+ export { getTypedData };
28
+ //# sourceMappingURL=singleChainOps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleChainOps.d.ts","sourceRoot":"","sources":["../../../execution/singleChainOps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvE,iBAAS,YAAY,CACnB,OAAO,EAAE,OAAO,EAChB,qBAAqB,EAAE,OAAO,EAC9B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;EA8Bd;AACD,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypedData = getTypedData;
4
+ function getTypedData(account, intentExecutorAddress, element, nonce) {
5
+ const ops = element.mandate.destinationOps;
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: 'ops', type: 'Op[]' },
18
+ ],
19
+ Op: [
20
+ { name: 'to', type: 'address' },
21
+ { name: 'value', type: 'uint256' },
22
+ { name: 'data', type: 'bytes' },
23
+ ],
24
+ },
25
+ primaryType: 'SingleChainOps',
26
+ message: {
27
+ account,
28
+ nonce,
29
+ ops,
30
+ },
31
+ };
32
+ }
@@ -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"}