@rhinestone/sdk 2.0.0-beta.44 → 2.0.0-beta.46

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 (603) hide show
  1. package/dist/src/accounts/adapter.d.ts +31 -0
  2. package/dist/src/accounts/adapter.d.ts.map +1 -0
  3. package/dist/src/accounts/adapters/eoa.d.ts +4 -0
  4. package/dist/src/accounts/adapters/eoa.d.ts.map +1 -0
  5. package/dist/src/accounts/adapters/eoa.js +45 -0
  6. package/dist/src/accounts/adapters/hca.d.ts +5 -0
  7. package/dist/src/accounts/adapters/hca.d.ts.map +1 -0
  8. package/dist/src/accounts/adapters/hca.js +118 -0
  9. package/dist/src/accounts/adapters/kernel.d.ts +9 -0
  10. package/dist/src/accounts/adapters/kernel.d.ts.map +1 -0
  11. package/dist/src/accounts/adapters/kernel.js +159 -0
  12. package/dist/src/accounts/adapters/nexus.d.ts +17 -0
  13. package/dist/src/accounts/adapters/nexus.d.ts.map +1 -0
  14. package/dist/src/accounts/adapters/nexus.js +227 -0
  15. package/dist/src/accounts/adapters/safe.d.ts +6 -0
  16. package/dist/src/accounts/adapters/safe.d.ts.map +1 -0
  17. package/dist/src/accounts/adapters/safe.js +194 -0
  18. package/dist/src/accounts/adapters/shared.d.ts +9 -0
  19. package/dist/src/accounts/adapters/shared.d.ts.map +1 -0
  20. package/dist/src/accounts/adapters/shared.js +62 -0
  21. package/dist/src/accounts/adapters/startale.d.ts +14 -0
  22. package/dist/src/accounts/adapters/startale.d.ts.map +1 -0
  23. package/dist/src/accounts/adapters/startale.js +165 -0
  24. package/dist/src/accounts/construction.d.ts +25 -0
  25. package/dist/src/accounts/construction.d.ts.map +1 -0
  26. package/dist/src/accounts/construction.js +34 -0
  27. package/dist/src/accounts/deployment.d.ts +12 -0
  28. package/dist/src/accounts/deployment.d.ts.map +1 -0
  29. package/dist/src/accounts/deployment.js +33 -0
  30. package/dist/src/accounts/erc7579-calls.d.ts +4 -0
  31. package/dist/src/accounts/erc7579-calls.d.ts.map +1 -0
  32. package/dist/src/accounts/erc7579-calls.js +57 -0
  33. package/dist/src/accounts/error.d.ts +1 -1
  34. package/dist/src/accounts/error.d.ts.map +1 -1
  35. package/dist/src/accounts/legacy.d.ts +14 -0
  36. package/dist/src/accounts/legacy.d.ts.map +1 -0
  37. package/dist/src/accounts/legacy.js +40 -0
  38. package/dist/src/accounts/registry.d.ts +4 -0
  39. package/dist/src/accounts/registry.d.ts.map +1 -0
  40. package/dist/src/accounts/registry.js +22 -0
  41. package/dist/src/accounts/types.d.ts +131 -0
  42. package/dist/src/accounts/types.d.ts.map +1 -0
  43. package/dist/src/accounts/wallet-account.d.ts +3 -0
  44. package/dist/src/accounts/wallet-account.d.ts.map +1 -0
  45. package/dist/src/accounts/wallet-account.js +12 -0
  46. package/dist/src/actions/deploy.d.ts +4 -0
  47. package/dist/src/actions/deploy.d.ts.map +1 -0
  48. package/dist/src/actions/deploy.js +8 -0
  49. package/dist/src/actions/ecdsa.d.ts +1 -1
  50. package/dist/src/actions/ecdsa.d.ts.map +1 -1
  51. package/dist/src/actions/ecdsa.js +8 -8
  52. package/dist/src/actions/index.d.ts +2 -16
  53. package/dist/src/actions/index.d.ts.map +1 -1
  54. package/dist/src/actions/index.js +3 -49
  55. package/dist/src/actions/mfa.d.ts +1 -1
  56. package/dist/src/actions/mfa.d.ts.map +1 -1
  57. package/dist/src/actions/mfa.js +30 -10
  58. package/dist/src/actions/modules.d.ts +4 -0
  59. package/dist/src/actions/modules.d.ts.map +1 -0
  60. package/dist/src/actions/modules.js +22 -0
  61. package/dist/src/actions/passkeys.d.ts +2 -2
  62. package/dist/src/actions/passkeys.d.ts.map +1 -1
  63. package/dist/src/actions/passkeys.js +19 -14
  64. package/dist/src/actions/runtime.d.ts +12 -0
  65. package/dist/src/actions/runtime.d.ts.map +1 -0
  66. package/dist/src/actions/runtime.js +161 -0
  67. package/dist/src/actions/smart-sessions.d.ts +2 -2
  68. package/dist/src/actions/smart-sessions.d.ts.map +1 -1
  69. package/dist/src/actions/smart-sessions.js +35 -12
  70. package/dist/src/api/account.d.ts +265 -0
  71. package/dist/src/api/account.d.ts.map +1 -0
  72. package/dist/src/api/account.js +640 -0
  73. package/dist/src/api/accounts.d.ts +12 -0
  74. package/dist/src/api/accounts.d.ts.map +1 -0
  75. package/dist/src/api/accounts.js +17 -0
  76. package/dist/src/api/compose-types.d.ts +147 -0
  77. package/dist/src/api/compose-types.d.ts.map +1 -0
  78. package/dist/src/api/compose.d.ts +6 -0
  79. package/dist/src/api/compose.d.ts.map +1 -0
  80. package/dist/src/api/compose.js +766 -0
  81. package/dist/src/api/direct-signing.d.ts +27 -0
  82. package/dist/src/api/direct-signing.d.ts.map +1 -0
  83. package/dist/src/api/direct-signing.js +191 -0
  84. package/dist/src/api/project-mappers.d.ts +7 -0
  85. package/dist/src/api/project-mappers.d.ts.map +1 -0
  86. package/dist/src/api/project-mappers.js +23 -0
  87. package/dist/src/api/queries/app-fees.d.ts +4 -0
  88. package/dist/src/api/queries/app-fees.d.ts.map +1 -0
  89. package/dist/src/api/queries/app-fees.js +3 -0
  90. package/dist/src/api/queries/portfolio.d.ts +9 -0
  91. package/dist/src/api/queries/portfolio.d.ts.map +1 -0
  92. package/dist/src/api/queries/portfolio.js +28 -0
  93. package/dist/src/api/queries/session.d.ts +8 -0
  94. package/dist/src/api/queries/session.d.ts.map +1 -0
  95. package/dist/src/api/queries/session.js +15 -0
  96. package/dist/src/api/sdk.d.ts +80 -0
  97. package/dist/src/api/sdk.d.ts.map +1 -0
  98. package/dist/src/api/sdk.js +103 -0
  99. package/dist/src/api/signer-selection.d.ts +7 -0
  100. package/dist/src/api/signer-selection.d.ts.map +1 -0
  101. package/dist/src/api/signer-selection.js +109 -0
  102. package/dist/src/calls/normalize.d.ts +9 -0
  103. package/dist/src/calls/normalize.d.ts.map +1 -0
  104. package/dist/src/calls/normalize.js +17 -0
  105. package/dist/src/calls/resolve.d.ts +3 -0
  106. package/dist/src/calls/resolve.d.ts.map +1 -0
  107. package/dist/src/calls/resolve.js +15 -0
  108. package/dist/src/calls/types.d.ts +25 -0
  109. package/dist/src/calls/types.d.ts.map +1 -0
  110. package/dist/src/calls/types.js +1 -0
  111. package/dist/src/chains/caip2.d.ts +10 -0
  112. package/dist/src/chains/caip2.d.ts.map +1 -0
  113. package/dist/src/chains/caip2.js +85 -0
  114. package/dist/src/chains/catalog.d.ts +5 -0
  115. package/dist/src/chains/catalog.d.ts.map +1 -0
  116. package/dist/src/chains/catalog.js +41 -0
  117. package/dist/src/chains/errors.d.ts +15 -0
  118. package/dist/src/chains/errors.d.ts.map +1 -0
  119. package/dist/src/chains/errors.js +21 -0
  120. package/dist/src/{orchestrator/destinations.d.ts → chains/non-evm.d.ts} +7 -5
  121. package/dist/src/chains/non-evm.d.ts.map +1 -0
  122. package/dist/src/chains/non-evm.js +30 -0
  123. package/dist/src/chains/tokens.d.ts +4 -0
  124. package/dist/src/chains/tokens.d.ts.map +1 -0
  125. package/dist/src/chains/tokens.js +22 -0
  126. package/dist/src/chains/types.d.ts +25 -0
  127. package/dist/src/chains/types.d.ts.map +1 -0
  128. package/dist/src/chains/types.js +1 -0
  129. package/dist/src/clients/bundler/client.d.ts +10 -0
  130. package/dist/src/clients/bundler/client.d.ts.map +1 -0
  131. package/dist/src/clients/bundler/client.js +85 -0
  132. package/dist/src/clients/bundler/endpoints.d.ts +3 -0
  133. package/dist/src/clients/bundler/endpoints.d.ts.map +1 -0
  134. package/dist/src/clients/bundler/endpoints.js +18 -0
  135. package/dist/src/clients/bundler/port.d.ts +22 -0
  136. package/dist/src/clients/bundler/port.d.ts.map +1 -0
  137. package/dist/src/clients/bundler/port.js +1 -0
  138. package/dist/src/clients/json-rpc.d.ts +20 -0
  139. package/dist/src/clients/json-rpc.d.ts.map +1 -0
  140. package/dist/src/clients/json-rpc.js +56 -0
  141. package/dist/src/clients/orchestrator/auth.d.ts +7 -0
  142. package/dist/src/clients/orchestrator/auth.d.ts.map +1 -0
  143. package/dist/src/clients/orchestrator/auth.js +27 -0
  144. package/dist/src/{orchestrator → clients/orchestrator}/chain-catalog.d.ts +5 -3
  145. package/dist/src/clients/orchestrator/chain-catalog.d.ts.map +1 -0
  146. package/dist/src/{orchestrator → clients/orchestrator}/chain-catalog.js +24 -3
  147. package/dist/src/clients/orchestrator/client.d.ts +13 -0
  148. package/dist/src/clients/orchestrator/client.d.ts.map +1 -0
  149. package/dist/src/clients/orchestrator/client.js +97 -0
  150. package/dist/src/{orchestrator/error.d.ts → clients/orchestrator/errors.d.ts} +2 -16
  151. package/dist/src/clients/orchestrator/errors.d.ts.map +1 -0
  152. package/dist/src/{orchestrator/error.js → clients/orchestrator/errors.js} +1 -22
  153. package/dist/src/clients/orchestrator/fetch.d.ts +7 -0
  154. package/dist/src/clients/orchestrator/fetch.d.ts.map +1 -0
  155. package/dist/src/clients/orchestrator/fetch.js +37 -0
  156. package/dist/src/clients/orchestrator/mappers.d.ts +9 -0
  157. package/dist/src/clients/orchestrator/mappers.d.ts.map +1 -0
  158. package/dist/src/clients/orchestrator/mappers.js +198 -0
  159. package/dist/src/clients/orchestrator/port.d.ts +26 -0
  160. package/dist/src/clients/orchestrator/port.d.ts.map +1 -0
  161. package/dist/src/clients/orchestrator/port.js +1 -0
  162. package/dist/src/{orchestrator/types.d.ts → clients/orchestrator/public.d.ts} +16 -4
  163. package/dist/src/clients/orchestrator/public.d.ts.map +1 -0
  164. package/dist/src/{orchestrator/types.js → clients/orchestrator/public.js} +3 -0
  165. package/dist/src/clients/orchestrator/types.d.ts +144 -0
  166. package/dist/src/clients/orchestrator/types.d.ts.map +1 -0
  167. package/dist/src/clients/orchestrator/types.js +1 -0
  168. package/dist/src/clients/orchestrator/wire.d.ts +19 -0
  169. package/dist/src/clients/orchestrator/wire.d.ts.map +1 -0
  170. package/dist/src/{orchestrator → clients/orchestrator}/wire.gen.d.ts +1193 -499
  171. package/dist/src/clients/orchestrator/wire.gen.d.ts.map +1 -0
  172. package/dist/src/clients/orchestrator/wire.gen.js +1 -0
  173. package/dist/src/clients/orchestrator/wire.js +1 -0
  174. package/dist/src/clients/paymaster/client.d.ts +8 -0
  175. package/dist/src/clients/paymaster/client.d.ts.map +1 -0
  176. package/dist/src/clients/paymaster/client.js +38 -0
  177. package/dist/src/clients/paymaster/endpoints.d.ts +3 -0
  178. package/dist/src/clients/paymaster/endpoints.d.ts.map +1 -0
  179. package/dist/src/clients/paymaster/endpoints.js +16 -0
  180. package/dist/src/clients/paymaster/port.d.ts +17 -0
  181. package/dist/src/clients/paymaster/port.d.ts.map +1 -0
  182. package/dist/src/clients/paymaster/port.js +1 -0
  183. package/dist/src/clients/rpc/client.d.ts +6 -0
  184. package/dist/src/clients/rpc/client.d.ts.map +1 -0
  185. package/dist/src/clients/rpc/client.js +66 -0
  186. package/dist/src/clients/rpc/compatibility.d.ts +12 -0
  187. package/dist/src/clients/rpc/compatibility.d.ts.map +1 -0
  188. package/dist/src/clients/rpc/compatibility.js +16 -0
  189. package/dist/src/clients/rpc/port.d.ts +13 -0
  190. package/dist/src/clients/rpc/port.d.ts.map +1 -0
  191. package/dist/src/clients/rpc/port.js +1 -0
  192. package/dist/src/clients/rpc/providers.d.ts +3 -0
  193. package/dist/src/clients/rpc/providers.d.ts.map +1 -0
  194. package/dist/src/clients/rpc/providers.js +8 -0
  195. package/dist/src/clients/rpc/transport.d.ts +4 -0
  196. package/dist/src/clients/rpc/transport.d.ts.map +1 -0
  197. package/dist/src/clients/rpc/transport.js +5 -0
  198. package/dist/src/clients/rpc/types.d.ts +23 -0
  199. package/dist/src/clients/rpc/types.d.ts.map +1 -0
  200. package/dist/src/clients/rpc/types.js +1 -0
  201. package/dist/src/config/account-runtime.d.ts +7 -0
  202. package/dist/src/config/account-runtime.d.ts.map +1 -0
  203. package/dist/src/config/account-runtime.js +36 -0
  204. package/dist/src/{types.d.ts → config/account.d.ts} +37 -14
  205. package/dist/src/config/account.d.ts.map +1 -0
  206. package/dist/src/config/account.js +10 -0
  207. package/dist/src/config/defaults.d.ts +14 -0
  208. package/dist/src/config/defaults.d.ts.map +1 -0
  209. package/dist/src/config/defaults.js +26 -0
  210. package/dist/src/config/input.d.ts +54 -0
  211. package/dist/src/config/input.d.ts.map +1 -0
  212. package/dist/src/config/input.js +1 -0
  213. package/dist/src/config/legacy.d.ts +22 -0
  214. package/dist/src/config/legacy.d.ts.map +1 -0
  215. package/dist/src/config/legacy.js +23 -0
  216. package/dist/src/config/resolve.d.ts +13 -0
  217. package/dist/src/config/resolve.d.ts.map +1 -0
  218. package/dist/src/config/resolve.js +174 -0
  219. package/dist/src/config/resolved.d.ts +77 -0
  220. package/dist/src/config/resolved.d.ts.map +1 -0
  221. package/dist/src/config/resolved.js +1 -0
  222. package/dist/src/config/validate.d.ts +3 -0
  223. package/dist/src/config/validate.d.ts.map +1 -0
  224. package/dist/src/config/validate.js +6 -0
  225. package/dist/src/{execution/error.d.ts → errors/execution.d.ts} +2 -2
  226. package/dist/src/errors/execution.d.ts.map +1 -0
  227. package/dist/src/{execution/error.js → errors/execution.js} +1 -1
  228. package/dist/src/errors/index.d.ts +4 -4
  229. package/dist/src/errors/index.d.ts.map +1 -1
  230. package/dist/src/errors/index.js +4 -3
  231. package/dist/src/index.d.ts +13 -324
  232. package/dist/src/index.d.ts.map +1 -1
  233. package/dist/src/index.js +6 -286
  234. package/dist/src/modules/erc7579-abi.d.ts +4 -0
  235. package/dist/src/modules/erc7579-abi.d.ts.map +1 -0
  236. package/dist/src/modules/erc7579-abi.js +12 -0
  237. package/dist/src/modules/intent-executor.d.ts +6 -0
  238. package/dist/src/modules/intent-executor.d.ts.map +1 -0
  239. package/dist/src/modules/intent-executor.js +13 -0
  240. package/dist/src/modules/legacy-core.d.ts +29 -0
  241. package/dist/src/modules/legacy-core.d.ts.map +1 -0
  242. package/dist/src/modules/legacy-core.js +80 -0
  243. package/dist/src/modules/normalize.d.ts +4 -0
  244. package/dist/src/modules/normalize.d.ts.map +1 -0
  245. package/dist/src/modules/normalize.js +15 -0
  246. package/dist/src/modules/plan.d.ts +16 -0
  247. package/dist/src/modules/plan.d.ts.map +1 -0
  248. package/dist/src/modules/plan.js +51 -0
  249. package/dist/src/modules/read-core.d.ts +39 -0
  250. package/dist/src/modules/read-core.d.ts.map +1 -0
  251. package/dist/src/modules/read-core.js +149 -0
  252. package/dist/src/modules/types.d.ts +46 -0
  253. package/dist/src/modules/types.d.ts.map +1 -0
  254. package/dist/src/modules/types.js +1 -0
  255. package/dist/src/modules/validators/capabilities.d.ts +4 -0
  256. package/dist/src/modules/validators/capabilities.d.ts.map +1 -0
  257. package/dist/src/modules/validators/capabilities.js +58 -0
  258. package/dist/src/modules/validators/contribution.d.ts +4 -0
  259. package/dist/src/modules/validators/contribution.d.ts.map +1 -0
  260. package/dist/src/modules/validators/contribution.js +64 -0
  261. package/dist/src/modules/validators/definition.d.ts +3 -0
  262. package/dist/src/modules/validators/definition.d.ts.map +1 -0
  263. package/dist/src/modules/validators/definition.js +68 -0
  264. package/dist/src/modules/validators/ens.d.ts +5 -0
  265. package/dist/src/modules/validators/ens.d.ts.map +1 -0
  266. package/dist/src/modules/validators/ens.js +34 -0
  267. package/dist/src/modules/validators/k1.d.ts +2 -0
  268. package/dist/src/modules/validators/k1.d.ts.map +1 -0
  269. package/dist/src/modules/validators/k1.js +1 -0
  270. package/dist/src/modules/validators/multi-factor.d.ts +18 -0
  271. package/dist/src/modules/validators/multi-factor.d.ts.map +1 -0
  272. package/dist/src/modules/validators/multi-factor.js +79 -0
  273. package/dist/src/modules/validators/ownable.d.ts +26 -0
  274. package/dist/src/modules/validators/ownable.d.ts.map +1 -0
  275. package/dist/src/modules/validators/ownable.js +84 -0
  276. package/dist/src/modules/validators/permissions.d.ts +1 -1
  277. package/dist/src/modules/validators/permissions.d.ts.map +1 -1
  278. package/dist/src/modules/validators/policies/claim/arbiters.d.ts +1 -1
  279. package/dist/src/modules/validators/policies/claim/arbiters.d.ts.map +1 -1
  280. package/dist/src/modules/validators/policies/claim/arbiters.js +3 -1
  281. package/dist/src/modules/validators/resolve.d.ts +5 -0
  282. package/dist/src/modules/validators/resolve.d.ts.map +1 -0
  283. package/dist/src/modules/validators/resolve.js +22 -0
  284. package/dist/src/modules/validators/signer-id.d.ts +5 -0
  285. package/dist/src/modules/validators/signer-id.d.ts.map +1 -0
  286. package/dist/src/modules/validators/signer-id.js +8 -0
  287. package/dist/src/modules/validators/smart-session-signature-types.d.ts +35 -0
  288. package/dist/src/modules/validators/smart-session-signature-types.d.ts.map +1 -0
  289. package/dist/src/modules/validators/smart-session-signature-types.js +1 -0
  290. package/dist/src/modules/validators/smart-sessions/authorization.d.ts +99 -0
  291. package/dist/src/modules/validators/smart-sessions/authorization.d.ts.map +1 -0
  292. package/dist/src/modules/validators/smart-sessions/authorization.js +101 -0
  293. package/dist/src/modules/validators/smart-sessions/calls.d.ts +19 -0
  294. package/dist/src/modules/validators/smart-sessions/calls.d.ts.map +1 -0
  295. package/dist/src/modules/validators/smart-sessions/calls.js +85 -0
  296. package/dist/src/modules/validators/smart-sessions/cross-chain-permits.d.ts +4 -0
  297. package/dist/src/modules/validators/smart-sessions/cross-chain-permits.d.ts.map +1 -0
  298. package/dist/src/modules/validators/smart-sessions/cross-chain-permits.js +77 -0
  299. package/dist/src/modules/validators/smart-sessions/digest.d.ts +5 -0
  300. package/dist/src/modules/validators/smart-sessions/digest.d.ts.map +1 -0
  301. package/dist/src/modules/validators/smart-sessions/digest.js +30 -0
  302. package/dist/src/modules/validators/smart-sessions/mock-signature.d.ts +10 -0
  303. package/dist/src/modules/validators/smart-sessions/mock-signature.d.ts.map +1 -0
  304. package/dist/src/modules/validators/smart-sessions/mock-signature.js +31 -0
  305. package/dist/src/modules/validators/smart-sessions/module.d.ts +11 -0
  306. package/dist/src/modules/validators/smart-sessions/module.d.ts.map +1 -0
  307. package/dist/src/modules/validators/smart-sessions/module.js +18 -0
  308. package/dist/src/modules/validators/smart-sessions/policies/addresses.d.ts +23 -0
  309. package/dist/src/modules/validators/smart-sessions/policies/addresses.d.ts.map +1 -0
  310. package/dist/src/modules/validators/smart-sessions/policies/addresses.js +29 -0
  311. package/dist/src/modules/validators/smart-sessions/policies/claim.d.ts +10 -0
  312. package/dist/src/modules/validators/smart-sessions/policies/claim.d.ts.map +1 -0
  313. package/dist/src/modules/validators/smart-sessions/policies/claim.js +106 -0
  314. package/dist/src/modules/validators/smart-sessions/policies/encode.d.ts +4 -0
  315. package/dist/src/modules/validators/smart-sessions/policies/encode.d.ts.map +1 -0
  316. package/dist/src/modules/validators/smart-sessions/policies/encode.js +197 -0
  317. package/dist/src/modules/validators/smart-sessions/resolve.d.ts +16 -0
  318. package/dist/src/modules/validators/smart-sessions/resolve.d.ts.map +1 -0
  319. package/dist/src/modules/validators/smart-sessions/resolve.js +120 -0
  320. package/dist/src/modules/validators/smart-sessions/signature.d.ts +14 -0
  321. package/dist/src/modules/validators/smart-sessions/signature.d.ts.map +1 -0
  322. package/dist/src/modules/validators/smart-sessions/signature.js +167 -0
  323. package/dist/src/modules/validators/smart-sessions/state.d.ts +19 -0
  324. package/dist/src/modules/validators/smart-sessions/state.d.ts.map +1 -0
  325. package/dist/src/modules/validators/smart-sessions/state.js +42 -0
  326. package/dist/src/modules/validators/smart-sessions/types.d.ts +227 -0
  327. package/dist/src/modules/validators/smart-sessions/types.d.ts.map +1 -0
  328. package/dist/src/modules/validators/smart-sessions/types.js +1 -0
  329. package/dist/src/modules/validators/types.d.ts +143 -0
  330. package/dist/src/modules/validators/types.d.ts.map +1 -0
  331. package/dist/src/modules/validators/types.js +1 -0
  332. package/dist/src/modules/validators/webauthn.d.ts +54 -0
  333. package/dist/src/modules/validators/webauthn.d.ts.map +1 -0
  334. package/dist/src/modules/validators/webauthn.js +159 -0
  335. package/dist/src/signing/context.d.ts +25 -0
  336. package/dist/src/signing/context.d.ts.map +1 -0
  337. package/dist/src/signing/context.js +163 -0
  338. package/dist/src/signing/contribution.d.ts +13 -0
  339. package/dist/src/signing/contribution.d.ts.map +1 -0
  340. package/dist/src/signing/contribution.js +83 -0
  341. package/dist/src/signing/eip7702.d.ts +41 -0
  342. package/dist/src/signing/eip7702.d.ts.map +1 -0
  343. package/dist/src/signing/eip7702.js +215 -0
  344. package/dist/src/signing/error.d.ts +27 -0
  345. package/dist/src/signing/error.d.ts.map +1 -0
  346. package/dist/src/signing/error.js +25 -0
  347. package/dist/src/signing/execute.d.ts +17 -0
  348. package/dist/src/signing/execute.d.ts.map +1 -0
  349. package/dist/src/signing/execute.js +138 -0
  350. package/dist/src/signing/intent-plans/assemble.d.ts +15 -0
  351. package/dist/src/signing/intent-plans/assemble.d.ts.map +1 -0
  352. package/dist/src/signing/intent-plans/assemble.js +96 -0
  353. package/dist/src/signing/intent-plans/independent.d.ts +48 -0
  354. package/dist/src/signing/intent-plans/independent.d.ts.map +1 -0
  355. package/dist/src/signing/intent-plans/independent.js +150 -0
  356. package/dist/src/signing/intent-plans/plan.d.ts +14 -0
  357. package/dist/src/signing/intent-plans/plan.d.ts.map +1 -0
  358. package/dist/src/signing/intent-plans/plan.js +187 -0
  359. package/dist/src/signing/intent-plans/types.d.ts +63 -0
  360. package/dist/src/signing/intent-plans/types.d.ts.map +1 -0
  361. package/dist/src/signing/intent-plans/types.js +1 -0
  362. package/dist/src/signing/message.d.ts +28 -0
  363. package/dist/src/signing/message.d.ts.map +1 -0
  364. package/dist/src/signing/message.js +90 -0
  365. package/dist/src/signing/passkeys.d.ts +28 -0
  366. package/dist/src/signing/passkeys.d.ts.map +1 -0
  367. package/dist/src/signing/passkeys.js +17 -0
  368. package/dist/src/signing/plan.d.ts +35 -0
  369. package/dist/src/signing/plan.d.ts.map +1 -0
  370. package/dist/src/signing/plan.js +377 -0
  371. package/dist/src/signing/protocols/erc6492.d.ts +11 -0
  372. package/dist/src/signing/protocols/erc6492.d.ts.map +1 -0
  373. package/dist/src/signing/protocols/erc6492.js +24 -0
  374. package/dist/src/signing/protocols/erc7739.d.ts +17 -0
  375. package/dist/src/signing/protocols/erc7739.d.ts.map +1 -0
  376. package/dist/src/signing/protocols/erc7739.js +84 -0
  377. package/dist/src/signing/session-enable.d.ts +35 -0
  378. package/dist/src/signing/session-enable.d.ts.map +1 -0
  379. package/dist/src/signing/session-enable.js +62 -0
  380. package/dist/src/signing/signers/compatibility.d.ts +4 -0
  381. package/dist/src/signing/signers/compatibility.d.ts.map +1 -0
  382. package/dist/src/signing/signers/compatibility.js +51 -0
  383. package/dist/src/signing/signers/ecdsa.d.ts +14 -0
  384. package/dist/src/signing/signers/ecdsa.d.ts.map +1 -0
  385. package/dist/src/signing/signers/ecdsa.js +54 -0
  386. package/dist/src/signing/signers/registry.d.ts +7 -0
  387. package/dist/src/signing/signers/registry.d.ts.map +1 -0
  388. package/dist/src/signing/signers/registry.js +33 -0
  389. package/dist/src/signing/signers/types.d.ts +16 -0
  390. package/dist/src/signing/signers/types.d.ts.map +1 -0
  391. package/dist/src/signing/signers/types.js +1 -0
  392. package/dist/src/signing/signers/wallet-chain.d.ts +9 -0
  393. package/dist/src/signing/signers/wallet-chain.d.ts.map +1 -0
  394. package/dist/src/signing/signers/wallet-chain.js +15 -0
  395. package/dist/src/signing/signers/webauthn.d.ts +11 -0
  396. package/dist/src/signing/signers/webauthn.d.ts.map +1 -0
  397. package/dist/src/signing/signers/webauthn.js +14 -0
  398. package/dist/src/signing/typed-data.d.ts +39 -0
  399. package/dist/src/signing/typed-data.d.ts.map +1 -0
  400. package/dist/src/signing/typed-data.js +135 -0
  401. package/dist/src/signing/types.d.ts +346 -0
  402. package/dist/src/signing/types.d.ts.map +1 -0
  403. package/dist/src/signing/types.js +1 -0
  404. package/dist/src/signing/user-operation.d.ts +23 -0
  405. package/dist/src/signing/user-operation.d.ts.map +1 -0
  406. package/dist/src/signing/user-operation.js +61 -0
  407. package/dist/src/smart-sessions/index.d.ts +13 -3
  408. package/dist/src/smart-sessions/index.d.ts.map +1 -1
  409. package/dist/src/smart-sessions/index.js +44 -6
  410. package/dist/src/transactions/intents/account.d.ts +15 -0
  411. package/dist/src/transactions/intents/account.d.ts.map +1 -0
  412. package/dist/src/transactions/intents/account.js +48 -0
  413. package/dist/src/transactions/intents/compatibility.d.ts +4 -0
  414. package/dist/src/transactions/intents/compatibility.d.ts.map +1 -0
  415. package/dist/src/transactions/intents/compatibility.js +19 -0
  416. package/dist/src/transactions/intents/normalize.d.ts +5 -0
  417. package/dist/src/transactions/intents/normalize.d.ts.map +1 -0
  418. package/dist/src/transactions/intents/normalize.js +48 -0
  419. package/dist/src/transactions/intents/prepare.d.ts +7 -0
  420. package/dist/src/transactions/intents/prepare.d.ts.map +1 -0
  421. package/dist/src/transactions/intents/prepare.js +249 -0
  422. package/dist/src/transactions/intents/quotes.d.ts +3 -0
  423. package/dist/src/transactions/intents/quotes.d.ts.map +1 -0
  424. package/dist/src/transactions/intents/quotes.js +11 -0
  425. package/dist/src/transactions/intents/request.d.ts +11 -0
  426. package/dist/src/transactions/intents/request.d.ts.map +1 -0
  427. package/dist/src/transactions/intents/request.js +55 -0
  428. package/dist/src/transactions/intents/send.d.ts +3 -0
  429. package/dist/src/transactions/intents/send.d.ts.map +1 -0
  430. package/dist/src/transactions/intents/send.js +22 -0
  431. package/dist/src/transactions/intents/session-signing.d.ts +7 -0
  432. package/dist/src/transactions/intents/session-signing.d.ts.map +1 -0
  433. package/dist/src/transactions/intents/session-signing.js +363 -0
  434. package/dist/src/transactions/intents/sessions.d.ts +17 -0
  435. package/dist/src/transactions/intents/sessions.d.ts.map +1 -0
  436. package/dist/src/transactions/intents/sessions.js +85 -0
  437. package/dist/src/transactions/intents/sign-transaction.d.ts +10 -0
  438. package/dist/src/transactions/intents/sign-transaction.d.ts.map +1 -0
  439. package/dist/src/transactions/intents/sign-transaction.js +386 -0
  440. package/dist/src/transactions/intents/split.d.ts +13 -0
  441. package/dist/src/transactions/intents/split.d.ts.map +1 -0
  442. package/dist/src/transactions/intents/split.js +3 -0
  443. package/dist/src/transactions/intents/status-policy.d.ts +13 -0
  444. package/dist/src/transactions/intents/status-policy.d.ts.map +1 -0
  445. package/dist/src/transactions/intents/status-policy.js +39 -0
  446. package/dist/src/transactions/intents/status.d.ts +4 -0
  447. package/dist/src/transactions/intents/status.d.ts.map +1 -0
  448. package/dist/src/transactions/intents/status.js +50 -0
  449. package/dist/src/transactions/intents/submit.d.ts +3 -0
  450. package/dist/src/transactions/intents/submit.d.ts.map +1 -0
  451. package/dist/src/transactions/intents/submit.js +32 -0
  452. package/dist/src/transactions/intents/types.d.ts +136 -0
  453. package/dist/src/transactions/intents/types.d.ts.map +1 -0
  454. package/dist/src/transactions/intents/types.js +1 -0
  455. package/dist/src/transactions/user-operations/hash.d.ts +5 -0
  456. package/dist/src/transactions/user-operations/hash.d.ts.map +1 -0
  457. package/dist/src/transactions/user-operations/hash.js +9 -0
  458. package/dist/src/transactions/user-operations/nonce.d.ts +18 -0
  459. package/dist/src/transactions/user-operations/nonce.d.ts.map +1 -0
  460. package/dist/src/transactions/user-operations/nonce.js +43 -0
  461. package/dist/src/transactions/user-operations/prepare.d.ts +12 -0
  462. package/dist/src/transactions/user-operations/prepare.d.ts.map +1 -0
  463. package/dist/src/transactions/user-operations/prepare.js +138 -0
  464. package/dist/src/transactions/user-operations/reconstruct.d.ts +28 -0
  465. package/dist/src/transactions/user-operations/reconstruct.d.ts.map +1 -0
  466. package/dist/src/transactions/user-operations/reconstruct.js +52 -0
  467. package/dist/src/transactions/user-operations/send.d.ts +3 -0
  468. package/dist/src/transactions/user-operations/send.d.ts.map +1 -0
  469. package/dist/src/transactions/user-operations/send.js +8 -0
  470. package/dist/src/transactions/user-operations/sign.d.ts +3 -0
  471. package/dist/src/transactions/user-operations/sign.d.ts.map +1 -0
  472. package/dist/src/transactions/user-operations/sign.js +14 -0
  473. package/dist/src/transactions/user-operations/status.d.ts +4 -0
  474. package/dist/src/transactions/user-operations/status.d.ts.map +1 -0
  475. package/dist/src/transactions/user-operations/status.js +37 -0
  476. package/dist/src/transactions/user-operations/submit.d.ts +3 -0
  477. package/dist/src/transactions/user-operations/submit.d.ts.map +1 -0
  478. package/dist/src/transactions/user-operations/submit.js +8 -0
  479. package/dist/src/transactions/user-operations/types.d.ts +68 -0
  480. package/dist/src/transactions/user-operations/types.d.ts.map +1 -0
  481. package/dist/src/transactions/user-operations/types.js +1 -0
  482. package/dist/src/transactions/user-operations/validator-account.d.ts +5 -0
  483. package/dist/src/transactions/user-operations/validator-account.d.ts.map +1 -0
  484. package/dist/src/transactions/user-operations/validator-account.js +26 -0
  485. package/dist/src/utils/index.d.ts +9 -4
  486. package/dist/src/utils/index.d.ts.map +1 -1
  487. package/dist/src/utils/index.js +54 -51
  488. package/package.json +3 -3
  489. package/dist/src/accounts/hca.d.ts +0 -25
  490. package/dist/src/accounts/hca.d.ts.map +0 -1
  491. package/dist/src/accounts/hca.js +0 -148
  492. package/dist/src/accounts/index.d.ts +0 -64
  493. package/dist/src/accounts/index.d.ts.map +0 -1
  494. package/dist/src/accounts/index.js +0 -680
  495. package/dist/src/accounts/json-rpc/index.d.ts +0 -5
  496. package/dist/src/accounts/json-rpc/index.d.ts.map +0 -1
  497. package/dist/src/accounts/json-rpc/index.js +0 -13
  498. package/dist/src/accounts/json-rpc/providers.d.ts +0 -3
  499. package/dist/src/accounts/json-rpc/providers.d.ts.map +0 -1
  500. package/dist/src/accounts/json-rpc/providers.js +0 -4
  501. package/dist/src/accounts/kernel.d.ts +0 -26
  502. package/dist/src/accounts/kernel.d.ts.map +0 -1
  503. package/dist/src/accounts/kernel.js +0 -265
  504. package/dist/src/accounts/nexus.d.ts +0 -34
  505. package/dist/src/accounts/nexus.d.ts.map +0 -1
  506. package/dist/src/accounts/nexus.js +0 -520
  507. package/dist/src/accounts/safe.d.ts +0 -32
  508. package/dist/src/accounts/safe.d.ts.map +0 -1
  509. package/dist/src/accounts/safe.js +0 -337
  510. package/dist/src/accounts/signing/common.d.ts +0 -38
  511. package/dist/src/accounts/signing/common.d.ts.map +0 -1
  512. package/dist/src/accounts/signing/common.js +0 -186
  513. package/dist/src/accounts/signing/message.d.ts +0 -7
  514. package/dist/src/accounts/signing/message.d.ts.map +0 -1
  515. package/dist/src/accounts/signing/message.js +0 -42
  516. package/dist/src/accounts/signing/passkeys.d.ts +0 -36
  517. package/dist/src/accounts/signing/passkeys.d.ts.map +0 -1
  518. package/dist/src/accounts/signing/passkeys.js +0 -119
  519. package/dist/src/accounts/signing/typedData.d.ts +0 -5
  520. package/dist/src/accounts/signing/typedData.d.ts.map +0 -1
  521. package/dist/src/accounts/signing/typedData.js +0 -30
  522. package/dist/src/accounts/startale.d.ts +0 -25
  523. package/dist/src/accounts/startale.d.ts.map +0 -1
  524. package/dist/src/accounts/startale.js +0 -188
  525. package/dist/src/accounts/utils.d.ts +0 -33
  526. package/dist/src/accounts/utils.d.ts.map +0 -1
  527. package/dist/src/accounts/utils.js +0 -202
  528. package/dist/src/auth/provider.d.ts +0 -7
  529. package/dist/src/auth/provider.d.ts.map +0 -1
  530. package/dist/src/auth/provider.js +0 -38
  531. package/dist/src/execution/compact.d.ts +0 -5
  532. package/dist/src/execution/compact.d.ts.map +0 -1
  533. package/dist/src/execution/compact.js +0 -4
  534. package/dist/src/execution/error.d.ts.map +0 -1
  535. package/dist/src/execution/index.d.ts +0 -42
  536. package/dist/src/execution/index.d.ts.map +0 -1
  537. package/dist/src/execution/index.js +0 -186
  538. package/dist/src/execution/utils.d.ts +0 -167
  539. package/dist/src/execution/utils.d.ts.map +0 -1
  540. package/dist/src/execution/utils.js +0 -1603
  541. package/dist/src/modules/abi/smart-sessions.d.ts +0 -104
  542. package/dist/src/modules/abi/smart-sessions.d.ts.map +0 -1
  543. package/dist/src/modules/abi/smart-sessions.js +0 -128
  544. package/dist/src/modules/chain-abstraction.d.ts +0 -5
  545. package/dist/src/modules/chain-abstraction.d.ts.map +0 -1
  546. package/dist/src/modules/chain-abstraction.js +0 -3
  547. package/dist/src/modules/common.d.ts +0 -30
  548. package/dist/src/modules/common.d.ts.map +0 -1
  549. package/dist/src/modules/common.js +0 -30
  550. package/dist/src/modules/index.d.ts +0 -11
  551. package/dist/src/modules/index.d.ts.map +0 -1
  552. package/dist/src/modules/index.js +0 -85
  553. package/dist/src/modules/legacy.d.ts +0 -10
  554. package/dist/src/modules/legacy.d.ts.map +0 -1
  555. package/dist/src/modules/legacy.js +0 -62
  556. package/dist/src/modules/read.d.ts +0 -11
  557. package/dist/src/modules/read.d.ts.map +0 -1
  558. package/dist/src/modules/read.js +0 -219
  559. package/dist/src/modules/validators/core.d.ts +0 -31
  560. package/dist/src/modules/validators/core.d.ts.map +0 -1
  561. package/dist/src/modules/validators/core.js +0 -269
  562. package/dist/src/modules/validators/cross-chain-permits.d.ts +0 -22
  563. package/dist/src/modules/validators/cross-chain-permits.d.ts.map +0 -1
  564. package/dist/src/modules/validators/cross-chain-permits.js +0 -107
  565. package/dist/src/modules/validators/index.d.ts +0 -4
  566. package/dist/src/modules/validators/index.d.ts.map +0 -1
  567. package/dist/src/modules/validators/index.js +0 -3
  568. package/dist/src/modules/validators/smart-sessions.d.ts +0 -226
  569. package/dist/src/modules/validators/smart-sessions.d.ts.map +0 -1
  570. package/dist/src/modules/validators/smart-sessions.js +0 -1197
  571. package/dist/src/orchestrator/caip2.d.ts +0 -18
  572. package/dist/src/orchestrator/caip2.d.ts.map +0 -1
  573. package/dist/src/orchestrator/caip2.js +0 -58
  574. package/dist/src/orchestrator/chain-catalog.d.ts.map +0 -1
  575. package/dist/src/orchestrator/client.d.ts +0 -43
  576. package/dist/src/orchestrator/client.d.ts.map +0 -1
  577. package/dist/src/orchestrator/client.js +0 -336
  578. package/dist/src/orchestrator/consts.d.ts +0 -6
  579. package/dist/src/orchestrator/consts.d.ts.map +0 -1
  580. package/dist/src/orchestrator/consts.js +0 -5
  581. package/dist/src/orchestrator/destinations.d.ts.map +0 -1
  582. package/dist/src/orchestrator/destinations.js +0 -59
  583. package/dist/src/orchestrator/error.d.ts.map +0 -1
  584. package/dist/src/orchestrator/index.d.ts +0 -12
  585. package/dist/src/orchestrator/index.d.ts.map +0 -1
  586. package/dist/src/orchestrator/index.js +0 -9
  587. package/dist/src/orchestrator/registry.d.ts +0 -7
  588. package/dist/src/orchestrator/registry.d.ts.map +0 -1
  589. package/dist/src/orchestrator/registry.js +0 -46
  590. package/dist/src/orchestrator/types.d.ts.map +0 -1
  591. package/dist/src/orchestrator/utils.d.ts +0 -3
  592. package/dist/src/orchestrator/utils.d.ts.map +0 -1
  593. package/dist/src/orchestrator/utils.js +0 -22
  594. package/dist/src/orchestrator/wire.d.ts +0 -31
  595. package/dist/src/orchestrator/wire.d.ts.map +0 -1
  596. package/dist/src/orchestrator/wire.gen.d.ts.map +0 -1
  597. package/dist/src/types.d.ts.map +0 -1
  598. package/dist/src/utils/walletClient.d.ts +0 -34
  599. package/dist/src/utils/walletClient.d.ts.map +0 -1
  600. package/dist/src/utils/walletClient.js +0 -117
  601. /package/dist/src/{orchestrator/wire.gen.js → accounts/adapter.js} +0 -0
  602. /package/dist/src/{types.js → accounts/types.js} +0 -0
  603. /package/dist/src/{orchestrator/wire.js → api/compose-types.js} +0 -0
@@ -1,1197 +0,0 @@
1
- import { LibZip } from 'solady';
2
- import { concat, createPublicClient, encodeAbiParameters, encodeFunctionData, encodePacked, hashStruct, isAddressEqual, isHex, keccak256, maxUint256, padHex, size, toFunctionSelector, toHex, zeroAddress, zeroHash, } from 'viem';
3
- import { mainnet } from 'viem/chains';
4
- import { getAccountProvider } from '../../accounts/index.js';
5
- import { K1_DEFAULT_VALIDATOR_ADDRESS } from '../../accounts/startale.js';
6
- import { createTransport } from '../../accounts/utils.js';
7
- import { RESET_PERIOD_ONE_WEEK, SCOPE_MULTICHAIN, } from '../../execution/compact.js';
8
- import { signTypedData } from '../../execution/utils.js';
9
- import { getChainById } from '../../orchestrator/registry.js';
10
- import smartSessionEmissaryAbi from '../abi/smart-session-emissary.js';
11
- import { MODULE_TYPE_ID_VALIDATOR } from '../common.js';
12
- import { getOwnerValidator, getValidator, ownerSetUsesEns, SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV, } from './core.js';
13
- import { resolveCrossChainPermission } from './cross-chain-permits.js';
14
- import { FAR_FUTURE_MS, resolvePermissions } from './permissions.js';
15
- import { getArbitersForSettlementLayers } from './policies/claim/arbiters.js';
16
- import { encodePermit2ClaimPolicyInitData, PERMIT2_CLAIM_POLICY_ADDRESS, } from './policies/claim/permit2.js';
17
- const types = {
18
- PolicyData: [
19
- { name: 'policy', type: 'address' },
20
- { name: 'initData', type: 'bytes' },
21
- ],
22
- ActionData: [
23
- { name: 'actionTargetSelector', type: 'bytes4' },
24
- { name: 'actionTarget', type: 'address' },
25
- { name: 'actionPolicies', type: 'PolicyData[]' },
26
- ],
27
- ERC7739Context: [
28
- { name: 'appDomainSeparator', type: 'bytes32' },
29
- { name: 'contentName', type: 'string[]' },
30
- ],
31
- ERC7739Data: [
32
- { name: 'allowedERC7739Content', type: 'ERC7739Context[]' },
33
- { name: 'erc1271Policies', type: 'PolicyData[]' },
34
- ],
35
- LockTagData: [
36
- { name: 'lockTag', type: 'bytes12' },
37
- { name: 'claimPolicies', type: 'PolicyData[]' },
38
- ],
39
- SignedPermissions: [
40
- { name: 'actions', type: 'ActionData[]' },
41
- { name: 'erc7739Policies', type: 'ERC7739Data' },
42
- { name: 'lockTagPolicies', type: 'LockTagData' },
43
- { name: 'permitGenericPolicy', type: 'bool' },
44
- ],
45
- SignedSession: [
46
- { name: 'account', type: 'address' },
47
- { name: 'expires', type: 'uint256' },
48
- { name: 'nonce', type: 'uint256' },
49
- { name: 'permissions', type: 'SignedPermissions' },
50
- { name: 'salt', type: 'bytes32' },
51
- { name: 'sessionValidator', type: 'address' },
52
- { name: 'sessionValidatorInitData', type: 'bytes' },
53
- { name: 'smartSessionEmissary', type: 'address' },
54
- ],
55
- ChainSession: [
56
- { name: 'chainId', type: 'uint64' },
57
- { name: 'session', type: 'SignedSession' },
58
- ],
59
- MultiChainSession: [{ name: 'sessionsAndChainIds', type: 'ChainSession[]' }],
60
- };
61
- const SMART_SESSION_MODE_USE = '0x00';
62
- const SMART_SESSION_MODE_ENABLE = '0x01';
63
- const SMART_SESSIONS_FALLBACK_TARGET_FLAG = '0x0000000000000000000000000000000000000001';
64
- const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = '0x00000001';
65
- const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = '0x00000002';
66
- // Dummy preclaimop action injected into every session so that the filler can trigger
67
- // verifyExecution (ENABLE mode) using an injected dummy preclaimop when there are no
68
- // real preclaimops. Target 0x...0420 is the ecRecover precompile; calls to it fail
69
- // silently because preclaimops are failure-tolerant. Selector 0x69123456 is
70
- // intentionally uncommon.
71
- const DUMMY_PRECLAIMOP_TARGET = '0x0000000000000000000000000000000000000420';
72
- const DUMMY_PRECLAIMOP_SELECTOR = '0x69123456';
73
- const SPENDING_LIMITS_POLICY_ADDRESS = '0x000000000033212E272655D8a22402Db819477A6';
74
- const TIME_FRAME_POLICY_ADDRESS = '0x0000000000D30f611fA3bf652ac6879428586930';
75
- const SUDO_POLICY_ADDRESS = '0x0000000000FEEc8D74e3143fBaBbca515358d869';
76
- const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000000000714Cf48FcF88A0bFBa70d313415032';
77
- const ARG_POLICY_ADDRESS = '0x0000000000167edE64D8751daACDdC0312565a73';
78
- const USAGE_LIMIT_POLICY_ADDRESS = '0x00000000001d4479FA2A947026204d0283ceDe4B';
79
- const VALUE_LIMIT_POLICY_ADDRESS = '0x000000000021dC45451291BCDfc9f0B46d6f0278';
80
- const INTENT_EXECUTION_POLICY_ADDRESS = '0xe9eA54d063975cDee9e06b7636d5563d95a7A23C';
81
- const INTENT_EXECUTION_POLICY_ADDRESS_DEV = '0xa09b47de6e510cbdc18b97e9239bedcb44fb4901';
82
- const ACTION_CONDITION_EQUAL = 0;
83
- const ACTION_CONDITION_GREATER_THAN = 1;
84
- const ACTION_CONDITION_LESS_THAN = 2;
85
- const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
86
- const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
87
- const ACTION_CONDITION_NOT_EQUAL = 5;
88
- const ACTION_CONDITION_IN_RANGE = 6;
89
- // ArgPolicy expression-tree node packing — must match ArgPolicyTreeLib.sol:
90
- // bits 0..1 : node type (0=rule, 1=NOT, 2=AND, 3=OR)
91
- // bits 2..9 : rule index (rule nodes only)
92
- // bits 10..17 : left/only child index
93
- // bits 18..25 : right child index (AND/OR only)
94
- const ARG_NODE_TYPE_RULE = 0n;
95
- const ARG_NODE_TYPE_NOT = 1n;
96
- const ARG_NODE_TYPE_AND = 2n;
97
- const ARG_NODE_TYPE_OR = 3n;
98
- const ARG_RULE_INDEX_SHIFT = 2n;
99
- const ARG_LEFT_CHILD_SHIFT = 10n;
100
- const ARG_RIGHT_CHILD_SHIFT = 18n;
101
- // On-chain caps from ArgPolicyTreeLib.sol; fail early instead of letting
102
- // the deployment revert with `TooManyRules` / `TooManyNodes`.
103
- const ARG_MAX_RULES = 128;
104
- const ARG_MAX_NODES = 256;
105
- const DEFAULT_POLICY_ADDRESSES = {
106
- sudo: SUDO_POLICY_ADDRESS,
107
- universalAction: UNIVERSAL_ACTION_POLICY_ADDRESS,
108
- argPolicy: ARG_POLICY_ADDRESS,
109
- spendingLimits: SPENDING_LIMITS_POLICY_ADDRESS,
110
- timeFrame: TIME_FRAME_POLICY_ADDRESS,
111
- usageLimit: USAGE_LIMIT_POLICY_ADDRESS,
112
- valueLimit: VALUE_LIMIT_POLICY_ADDRESS,
113
- };
114
- function resolvePolicyAddresses(overrides) {
115
- if (!overrides)
116
- return DEFAULT_POLICY_ADDRESSES;
117
- return {
118
- sudo: overrides.sudo ?? DEFAULT_POLICY_ADDRESSES.sudo,
119
- universalAction: overrides.universalAction ?? DEFAULT_POLICY_ADDRESSES.universalAction,
120
- argPolicy: overrides.argPolicy ?? DEFAULT_POLICY_ADDRESSES.argPolicy,
121
- spendingLimits: overrides.spendingLimits ?? DEFAULT_POLICY_ADDRESSES.spendingLimits,
122
- timeFrame: overrides.timeFrame ?? DEFAULT_POLICY_ADDRESSES.timeFrame,
123
- usageLimit: overrides.usageLimit ?? DEFAULT_POLICY_ADDRESSES.usageLimit,
124
- valueLimit: overrides.valueLimit ?? DEFAULT_POLICY_ADDRESSES.valueLimit,
125
- };
126
- }
127
- function packSignature(signers, validatorSignature) {
128
- const session = signers.session;
129
- const permissionId = getPermissionId(session);
130
- if (signers.verifyExecutions) {
131
- const smartSessionMode = signers.enableData
132
- ? SMART_SESSION_MODE_ENABLE
133
- : SMART_SESSION_MODE_USE;
134
- const sessionData = getSessionData(signers.session);
135
- const packedSignature = signers.enableData
136
- ? LibZip.flzCompress(encodeAbiParameters([
137
- {
138
- type: 'tuple',
139
- name: 'enableData',
140
- components: [
141
- { type: 'bytes', name: 'allocatorSig' },
142
- { type: 'bytes', name: 'userSig' },
143
- { type: 'uint256', name: 'expires' },
144
- {
145
- type: 'tuple',
146
- name: 'enableSession',
147
- components: [
148
- {
149
- type: 'uint8',
150
- name: 'chainDigestIndex',
151
- },
152
- {
153
- type: 'tuple[]',
154
- name: 'hashesAndChainIds',
155
- components: [
156
- { type: 'uint64', name: 'chainId' },
157
- { type: 'bytes32', name: 'sessionDigest' },
158
- ],
159
- },
160
- {
161
- type: 'tuple',
162
- name: 'session',
163
- components: [
164
- { type: 'address', name: 'sessionValidator' },
165
- { type: 'bytes', name: 'sessionValidatorInitData' },
166
- { type: 'bytes32', name: 'salt' },
167
- {
168
- type: 'tuple[]',
169
- name: 'actions',
170
- components: [
171
- { type: 'bytes4', name: 'actionTargetSelector' },
172
- { type: 'address', name: 'actionTarget' },
173
- {
174
- type: 'tuple[]',
175
- name: 'actionPolicies',
176
- components: [
177
- { type: 'address', name: 'policy' },
178
- { type: 'bytes', name: 'initData' },
179
- ],
180
- },
181
- ],
182
- },
183
- {
184
- type: 'tuple[]',
185
- name: 'claimPolicies',
186
- components: [
187
- { type: 'address', name: 'policy' },
188
- { type: 'bytes', name: 'initData' },
189
- ],
190
- },
191
- {
192
- type: 'tuple',
193
- name: 'erc7739Policies',
194
- components: [
195
- {
196
- type: 'tuple[]',
197
- name: 'allowedERC7739Content',
198
- components: [
199
- {
200
- type: 'bytes32',
201
- name: 'appDomainSeparator',
202
- },
203
- { type: 'string[]', name: 'contentNames' },
204
- ],
205
- },
206
- {
207
- type: 'tuple[]',
208
- name: 'erc1271Policies',
209
- components: [
210
- { type: 'address', name: 'policy' },
211
- { type: 'bytes', name: 'initData' },
212
- ],
213
- },
214
- ],
215
- },
216
- ],
217
- },
218
- ],
219
- },
220
- ],
221
- },
222
- {
223
- type: 'tuple',
224
- name: 'config',
225
- components: [
226
- { type: 'uint8', name: 'scope' },
227
- { type: 'uint8', name: 'resetPeriod' },
228
- { type: 'address', name: 'allocator' },
229
- { type: 'bytes32', name: 'permissionId' },
230
- ],
231
- },
232
- { type: 'bytes' },
233
- ], [
234
- {
235
- allocatorSig: zeroHash,
236
- userSig: signers.enableData.userSignature,
237
- expires: maxUint256,
238
- enableSession: {
239
- chainDigestIndex: signers.enableData.sessionToEnableIndex,
240
- hashesAndChainIds: signers.enableData.hashesAndChainIds,
241
- session: sessionData,
242
- },
243
- },
244
- {
245
- scope: SCOPE_MULTICHAIN,
246
- resetPeriod: RESET_PERIOD_ONE_WEEK,
247
- allocator: zeroAddress,
248
- permissionId: getPermissionId(signers.session),
249
- },
250
- validatorSignature,
251
- ]))
252
- : validatorSignature;
253
- return signers.enableData
254
- ? encodePacked(['bytes1', 'bytes'], [smartSessionMode, packedSignature])
255
- : encodePacked(['bytes1', 'bytes32', 'bytes'], [smartSessionMode, permissionId, packedSignature]);
256
- }
257
- else {
258
- const SIGNATURE_IS_VALID_SIG_1271 = '0x00';
259
- const policyDataOffset = BigInt(64 + size(validatorSignature));
260
- const mode = SIGNATURE_IS_VALID_SIG_1271;
261
- const policySpecificData = signers.claimPolicyData ?? '0x';
262
- const signature = encodePacked(['bytes1', 'bytes32', 'uint256', 'bytes', 'bytes'], [
263
- mode,
264
- permissionId,
265
- policyDataOffset,
266
- validatorSignature,
267
- policySpecificData,
268
- ]);
269
- return signature;
270
- }
271
- }
272
- async function getSessionDetails(account, sessions, provider, useDevContracts) {
273
- const lockTag = '0x000000000000000000000000';
274
- const sessionNonces = await Promise.all(sessions.map((session) => getSessionNonce(account, session, lockTag, provider, useDevContracts)));
275
- const sessionDatas = sessions.map((session) => getSessionData(session));
276
- const signedSessions = sessionDatas.map((session, index) => getSignedSession(account, lockTag, session, sessionNonces[index], useDevContracts));
277
- const chains = sessions.map((session) => session.chain);
278
- const hashesAndChainIds = signedSessions.map((session, index) => ({
279
- chainId: BigInt(chains[index].id),
280
- sessionDigest: hashStruct({
281
- types,
282
- primaryType: 'SignedSession',
283
- data: session,
284
- }),
285
- }));
286
- const data = {
287
- domain: {
288
- name: 'SmartSessionEmissary',
289
- version: '1',
290
- },
291
- types: types,
292
- primaryType: 'MultiChainSession',
293
- message: {
294
- sessionsAndChainIds: signedSessions.map((session, index) => ({
295
- chainId: BigInt(chains[index].id),
296
- session,
297
- })),
298
- },
299
- };
300
- return {
301
- nonces: sessionNonces,
302
- hashesAndChainIds,
303
- data,
304
- };
305
- }
306
- async function isSessionEnabled(account, provider, session, useDevContracts) {
307
- const publicClient = createPublicClient({
308
- chain: session.chain,
309
- transport: createTransport(session.chain, provider),
310
- });
311
- const isEnabled = await publicClient.readContract({
312
- address: getSmartSessionEmissaryAddress(useDevContracts),
313
- abi: [
314
- {
315
- type: 'function',
316
- name: 'isPermissionEnabled',
317
- inputs: [
318
- { name: 'account', type: 'address' },
319
- { name: 'permissionId', type: 'bytes32' },
320
- ],
321
- outputs: [{ name: 'isEnabled', type: 'bool' }],
322
- stateMutability: 'view',
323
- },
324
- ],
325
- functionName: 'isPermissionEnabled',
326
- args: [account, getPermissionId(session)],
327
- });
328
- return isEnabled;
329
- }
330
- async function signEnableSession(config, details) {
331
- const account = getAccountProvider(config);
332
- const validator = getOwnerValidator(config);
333
- const isStartaleK1 = account.type === 'startale' &&
334
- validator.address.toLowerCase() ===
335
- K1_DEFAULT_VALIDATOR_ADDRESS.toLowerCase();
336
- if (isStartaleK1) {
337
- const chainIds = details.hashesAndChainIds.map((h) => h.chainId);
338
- const uniqueChainIds = [...new Set(chainIds.map((c) => c.toString()))];
339
- if (uniqueChainIds.length > 1) {
340
- throw new Error('Startale accounts with K1 validator do not support multi-chain session enable');
341
- }
342
- const chain = getChainById(Number(chainIds[0]));
343
- return signTypedData(config, details.data, chain, undefined, {
344
- skipErc6492: true,
345
- });
346
- }
347
- return signTypedData(config, details.data, mainnet, undefined, {
348
- skipErc6492: true,
349
- });
350
- }
351
- async function getSessionNonce(account, session, lockTag, provider, useDevContracts) {
352
- const publicClient = createPublicClient({
353
- chain: session.chain,
354
- transport: createTransport(session.chain, provider),
355
- });
356
- const nonce = await publicClient.readContract({
357
- address: getSmartSessionEmissaryAddress(useDevContracts),
358
- abi: [
359
- {
360
- type: 'function',
361
- name: 'getNonce',
362
- inputs: [
363
- { name: 'sponsor', type: 'address', internalType: 'address' },
364
- { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
365
- ],
366
- outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
367
- stateMutability: 'view',
368
- },
369
- ],
370
- functionName: 'getNonce',
371
- args: [account, lockTag],
372
- });
373
- return nonce;
374
- }
375
- function getSignedSession(account, lockTag, session, nonce, useDevContracts) {
376
- return {
377
- account,
378
- permissions: {
379
- permitGenericPolicy: session.actions.some((action) => action.actionTarget === SMART_SESSIONS_FALLBACK_TARGET_FLAG &&
380
- action.actionTargetSelector ===
381
- SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG),
382
- lockTagPolicies: {
383
- lockTag,
384
- claimPolicies: session.claimPolicies,
385
- },
386
- erc7739Policies: {
387
- allowedERC7739Content: session.erc7739Policies.allowedERC7739Content.map((content) => ({
388
- contentName: content.contentNames,
389
- appDomainSeparator: content.appDomainSeparator,
390
- })),
391
- erc1271Policies: session.erc7739Policies.erc1271Policies,
392
- },
393
- actions: session.actions,
394
- },
395
- sessionValidator: session.sessionValidator,
396
- sessionValidatorInitData: session.sessionValidatorInitData,
397
- salt: session.salt,
398
- smartSessionEmissary: getSmartSessionEmissaryAddress(useDevContracts),
399
- expires: maxUint256,
400
- nonce,
401
- };
402
- }
403
- async function getEnableSessionCall(account, session, enableSessionSignature, hashesAndChainIds, sessionToEnableIndex, useDevContracts) {
404
- const sessionData = getSessionData(session);
405
- const permissionId = getPermissionId(session);
406
- return {
407
- to: getSmartSessionEmissaryAddress(useDevContracts),
408
- data: encodeFunctionData({
409
- abi: smartSessionEmissaryAbi,
410
- functionName: 'setConfig',
411
- args: [
412
- account,
413
- {
414
- scope: SCOPE_MULTICHAIN,
415
- resetPeriod: RESET_PERIOD_ONE_WEEK,
416
- allocator: zeroAddress,
417
- permissionId,
418
- },
419
- {
420
- allocatorSig: zeroHash,
421
- userSig: enableSessionSignature,
422
- expires: maxUint256,
423
- session: {
424
- chainDigestIndex: sessionToEnableIndex,
425
- hashesAndChainIds,
426
- sessionToEnable: sessionData,
427
- },
428
- },
429
- ],
430
- }),
431
- };
432
- }
433
- // SignedPermissionDisable(address account,bytes32 permissionId,bytes12 lockTag,uint256 expires,uint256 nonce)
434
- // Vendored from contracts/smart-sessions-v2/src/lib/HashLibV2.sol.
435
- const SIGNED_PERMISSION_DISABLE_TYPEHASH = '0x098b3120e60a8adc9d970dec9c1f8796974a3ab6154f995ad56ee7b9a38d8836';
436
- // Builds a `removeConfig` call that disables a single smart session.
437
- //
438
- // The disable user-signature (`disableData.userSig`) is left empty: the
439
- // emissary only verifies it when `msg.sender != account`
440
- // (SignatureLib.verifySignatures), and here the account itself executes the
441
- // call, so the disable is authorized by the outer transaction the user signs
442
- // normally. The `disableDigest` leaf still has to match on-chain, so we build
443
- // it from the current emissary nonce + `expires`. No-allocator flow only
444
- // (`allocator == zeroAddress`), matching how enable is used today.
445
- async function getDisableSessionCall(account, session, expires, provider, useDevContracts) {
446
- const lockTag = '0x000000000000000000000000';
447
- const permissionId = getPermissionId(session);
448
- const nonce = await getSessionNonce(account, session, lockTag, provider, useDevContracts);
449
- // SmartSessionLens reuses the session multichain wrapper for the disable
450
- // digest, plugging this leaf in as `sessionDigest` (HashLibV2.disableDigest).
451
- const disableDigest = keccak256(encodeAbiParameters([
452
- { type: 'bytes32' },
453
- { type: 'address' },
454
- { type: 'bytes32' },
455
- { type: 'bytes12' },
456
- { type: 'uint256' },
457
- { type: 'uint256' },
458
- ], [
459
- SIGNED_PERMISSION_DISABLE_TYPEHASH,
460
- account,
461
- permissionId,
462
- lockTag,
463
- expires,
464
- nonce,
465
- ]));
466
- const hashesAndChainIds = [
467
- { chainId: BigInt(session.chain.id), sessionDigest: disableDigest },
468
- ];
469
- return {
470
- to: getSmartSessionEmissaryAddress(useDevContracts),
471
- data: encodeFunctionData({
472
- abi: smartSessionEmissaryAbi,
473
- functionName: 'removeConfig',
474
- args: [
475
- account,
476
- {
477
- scope: SCOPE_MULTICHAIN,
478
- resetPeriod: RESET_PERIOD_ONE_WEEK,
479
- allocator: zeroAddress,
480
- permissionId,
481
- },
482
- {
483
- allocatorSig: '0x',
484
- userSig: '0x',
485
- expires,
486
- session: {
487
- chainDigestIndex: 0,
488
- hashesAndChainIds,
489
- },
490
- },
491
- ],
492
- }),
493
- };
494
- }
495
- function toSession(definition, options = {}) {
496
- const addresses = resolvePolicyAddresses(definition.policyAddresses);
497
- const sessionData = resolveSessionData(definition, options.useDevContracts, addresses, options.wrappedNativeToken);
498
- // Cross-chain permits add synthesized claim policies that must appear
499
- // on the returned `Session` too — `getSessionData(session)` re-encodes
500
- // from `session.claimPolicies` at signing time, so missing entries
501
- // here would diverge from what `resolveSessionData` already baked
502
- // into `sessionData.claimPolicies` for the permission-ID hash.
503
- const expandedCrossChainClaims = (definition.crossChainPermits ?? []).map((p) => expandCrossChainPermit(p, options.useDevContracts).claim);
504
- return {
505
- chain: definition.chain,
506
- owners: definition.owners,
507
- hasExplicitPermissions: !!definition.permissions?.length,
508
- permissionId: getPermissionIdFromData(sessionData),
509
- sessionValidator: sessionData.sessionValidator,
510
- sessionValidatorInitData: sessionData.sessionValidatorInitData,
511
- salt: sessionData.salt,
512
- erc7739Policies: sessionData.erc7739Policies,
513
- actions: sessionData.actions,
514
- claimPolicies: [
515
- ...(definition.claimPolicies ?? []),
516
- ...expandedCrossChainClaims,
517
- ],
518
- };
519
- }
520
- /**
521
- * Expands one {@link CrossChainPermit} into:
522
- *
523
- * - a {@link Permit2ClaimPolicy} for `SessionDefinition.claimPolicies`
524
- * (gates Permit2 arbiter settlement) — settlement layers are resolved
525
- * to canonical arbiter addresses via
526
- * {@link getArbitersForSettlementLayers}.
527
- * - optional {@link SpendingLimitsPolicy} / {@link TimeFramePolicy}
528
- * entries for the session's fallback action — the claim policy itself
529
- * doesn't enforce amounts or expiry on-chain, so we lift those
530
- * guarantees into action-level policies that do.
531
- *
532
- * An Intent Executor policy is intentionally NOT synthesized: the
533
- * params-bearing on-chain contract is still being designed in
534
- * smart-sessions-v2 (PR #46). Once it lands, this helper grows a second
535
- * branch that emits matching constraints there.
536
- */
537
- function expandCrossChainPermit(input, useDevContracts) {
538
- const permit = resolveCrossChainPermission(input);
539
- // `from`/`to` are optional: an absent leg list means "no token/chain
540
- // restriction on that side" — we emit `undefined` so the underlying
541
- // Permit2 policy skips the check entirely (matching how every other
542
- // policy field treats undefined as unrestricted).
543
- const sourceTokens = permit.from?.length
544
- ? permit.from.map(({ chain, token }) => ({ chain, address: token }))
545
- : undefined;
546
- const destinationTokens = permit.to?.length
547
- ? permit.to.map(({ chain, token }) => ({ chain, address: token }))
548
- : undefined;
549
- // Only emit a `recipients` whitelist when at least one destination
550
- // leg pins a concrete recipient (or the explicit `'any'` sentinel).
551
- // Leaving the field undefined disables the on-chain recipient check
552
- // entirely; emitting `['any', ...]` would force the contract into
553
- // recipient-check mode without actually restricting anything.
554
- const recipientsList = (permit.to ?? [])
555
- .filter((t) => t.recipient !== undefined)
556
- .map((t) => ({
557
- chain: t.chain,
558
- address: t.recipient,
559
- }));
560
- const recipients = recipientsList.length ? recipientsList : undefined;
561
- const permitDeadline = permit.validAfter !== undefined || permit.validUntil !== undefined
562
- ? { min: permit.validAfter, max: permit.validUntil }
563
- : undefined;
564
- // Resolve the dev-friendly settlement-layer selectors into the actual
565
- // Permit2 arbiter addresses the on-chain policy enforces. Empty or
566
- // undefined ⇒ union of all supported layers (never an empty
567
- // whitelist that disables the on-chain check).
568
- const spenders = getArbitersForSettlementLayers(permit.settlementLayers, useDevContracts);
569
- const claim = {
570
- type: 'permit2',
571
- spenders,
572
- sourceTokens,
573
- destinationTokens,
574
- recipients,
575
- recipientIsAccount: permit.recipientIsAccount,
576
- permitDeadline,
577
- fillDeadline: permit.fillDeadline,
578
- };
579
- const fallbackPolicies = [];
580
- // Per-origin amount caps: the Permit2 claim policy doesn't enforce
581
- // amounts on-chain, so we lift those caps into a separate
582
- // `SpendingLimitsPolicy` on the fallback action. This keeps the
583
- // user-facing promise ("at most X of token Y") honest.
584
- const limits = (permit.from ?? [])
585
- .filter((f) => f.maxAmount !== undefined)
586
- .map((f) => ({ token: f.token, amount: f.maxAmount }));
587
- if (limits.length) {
588
- fallbackPolicies.push({ type: 'spending-limits', limits });
589
- }
590
- // Time-frame: the on-chain TimeFramePolicy expects millisecond inputs
591
- // (see `case 'time-frame'` in getPolicyData), while CrossChainPermit
592
- // uses unix-seconds bigints — matching the Permit2 deadline
593
- // convention. We convert at the boundary so both encoders see their
594
- // preferred unit.
595
- //
596
- // One-sided bounds get always-passing defaults, mirroring the
597
- // permission resolver: an unset `validUntil` defaults to the year-2100
598
- // sentinel (NOT 0 — that would make the policy expired the moment
599
- // `validAfter` is reached), and an unset `validAfter` defaults to 0.
600
- if (permitDeadline) {
601
- const validUntilMs = permit.validUntil !== undefined
602
- ? Number(permit.validUntil * 1000n)
603
- : FAR_FUTURE_MS;
604
- const validAfterMs = permit.validAfter !== undefined ? Number(permit.validAfter * 1000n) : 0;
605
- fallbackPolicies.push({
606
- type: 'time-frame',
607
- validUntil: validUntilMs,
608
- validAfter: validAfterMs,
609
- });
610
- }
611
- return { claim, fallbackPolicies };
612
- }
613
- /**
614
- * True when `message` satisfies every dimension `policy` constrains. Used to
615
- * pick the correct claim policy at Permit2-signing time when a session holds
616
- * more than one (e.g. a user claim policy plus one or more cross-chain
617
- * permits).
618
- *
619
- * The on-chain emissary validates a Permit2 claim against the matching claim
620
- * policy, and `buildPermit2ClaimPolicyCalldata` expands the message
621
- * differently per policy (the calldata layout depends on which mode bits a
622
- * policy enables). Signing calldata for the wrong policy decodes incorrectly
623
- * on-chain and fails ERC-1271 validation — hence we must match.
624
- *
625
- * Only constrained dimensions are checked; an unset policy field imposes no
626
- * requirement (mirrors the contract's "skip the check" semantics). Source
627
- * tokens are matched by address alone because the Permit2 message carries no
628
- * origin chain id; destination tokens / recipients are scoped to the
629
- * mandate's `targetChain`.
630
- */
631
- function permit2ClaimPolicyMatchesMessage(policy, message) {
632
- // Spender (arbiter) — the primary discriminator between settlement layers.
633
- if (policy.spenders?.length) {
634
- if (!policy.spenders.some((s) => isAddressEqual(s, message.spender))) {
635
- return false;
636
- }
637
- }
638
- // Source tokens: every permitted token must be allow-listed (by address).
639
- if (policy.sourceTokens?.length) {
640
- const allowed = new Set(policy.sourceTokens.map((t) => t.address.toLowerCase()));
641
- if (!message.permitted.every((p) => allowed.has(p.token.toLowerCase()))) {
642
- return false;
643
- }
644
- }
645
- const targetChain = message.mandate.target.targetChain;
646
- // Destination tokens: every mandate output token must be allow-listed for
647
- // the destination chain.
648
- if (policy.destinationTokens?.length) {
649
- const allowed = new Set(policy.destinationTokens
650
- .filter((t) => BigInt(t.chain.id) === targetChain)
651
- .map((t) => t.address.toLowerCase()));
652
- if (!message.mandate.target.tokenOut.every((o) => allowed.has(o.token.toLowerCase()))) {
653
- return false;
654
- }
655
- }
656
- // Recipient: scoped to the destination chain. An `'any'` entry for that
657
- // chain accepts any recipient.
658
- if (policy.recipients?.length) {
659
- const entries = policy.recipients.filter((r) => BigInt(r.chain.id) === targetChain);
660
- if (entries.length) {
661
- const recipient = message.mandate.target.recipient;
662
- const matches = entries.some((r) => r.address === 'any' || isAddressEqual(r.address, recipient));
663
- if (!matches)
664
- return false;
665
- }
666
- }
667
- return true;
668
- }
669
- /**
670
- * Selects the claim policy whose constraints the given Permit2 message
671
- * satisfies. With 0–1 policies the choice is trivial; with several, returns
672
- * the first match in list order (aligns with the contract iterating its
673
- * stored claim policies). Falls back to the first policy when nothing matches
674
- * so behaviour is never worse than the previous always-`[0]` logic — the
675
- * resulting on-chain failure is then identical to before.
676
- */
677
- function selectPermit2ClaimPolicyForMessage(claimPolicies, message) {
678
- if (claimPolicies.length <= 1)
679
- return claimPolicies[0];
680
- return (claimPolicies.find((p) => permit2ClaimPolicyMatchesMessage(p, message)) ??
681
- claimPolicies[0]);
682
- }
683
- function resolvePermit2ClaimPolicy(policy) {
684
- return {
685
- type: 'permit2-claim',
686
- arbiters: policy.spenders,
687
- tokensIn: policy.sourceTokens?.map(({ chain, address }) => ({
688
- chainId: chain.id,
689
- token: address,
690
- })),
691
- tokensOut: policy.destinationTokens?.map(({ chain, address }) => ({
692
- chainId: chain.id,
693
- token: address,
694
- })),
695
- recipients: policy.recipients?.map(({ chain, address }) => ({
696
- chainId: chain.id,
697
- recipient: address,
698
- })),
699
- recipientIsSponsor: policy.recipientIsAccount,
700
- expiryBounds: policy.permitDeadline,
701
- fillExpiryBounds: policy.fillDeadline?.map(({ chain, min, max }) => ({
702
- chainId: chain.id,
703
- min,
704
- max,
705
- })),
706
- };
707
- }
708
- function resolveSessionData(session, useDevContracts, addresses = DEFAULT_POLICY_ADDRESSES, wrappedNativeToken) {
709
- // ENS validation is HCA-only, and HCA accounts cannot install the smart
710
- // session validator, so an ENS session owner would silently resolve to the
711
- // HCA module and sign/enable against a validator the account does not have.
712
- if (ownerSetUsesEns(session.owners)) {
713
- throw new Error('ENS owners are not supported for smart sessions');
714
- }
715
- const validator = getValidator(session.owners);
716
- const allowedContent = [
717
- {
718
- contentNames: [''],
719
- appDomainSeparator: zeroHash,
720
- },
721
- ];
722
- const erc7739Data = {
723
- allowedERC7739Content: allowedContent,
724
- erc1271Policies: [
725
- {
726
- policy: addresses.sudo,
727
- initData: '0x',
728
- },
729
- ],
730
- };
731
- const sudoAction = {
732
- actionTargetSelector: SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
733
- actionTarget: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
734
- actionPolicies: [
735
- {
736
- policy: addresses.sudo,
737
- initData: '0x',
738
- },
739
- ],
740
- };
741
- const userActions = session.permissions?.length
742
- ? resolvePermissions(session.permissions)
743
- : [];
744
- // Expand every cross-chain permit into a (claim, fallbackPolicies)
745
- // pair. The claim policies go onto `session.claimPolicies` (Permit2
746
- // settlement); the fallback policies (SpendingLimits / TimeFrame
747
- // derived from maxAmount / validUntil) are appended to the injected
748
- // fallback action below.
749
- const expandedPermits = (session.crossChainPermits ?? []).map((p) => expandCrossChainPermit(p, useDevContracts));
750
- const extraClaimPolicies = expandedPermits.map((e) => e.claim);
751
- const permitFallbackPolicies = expandedPermits.flatMap((e) => e.fallbackPolicies);
752
- // Native-token wrapping: permit `deposit()` on the chain's wrapped-native
753
- // token. Only injected when the wrapped-native address is known — supplied by
754
- // `RhinestoneSDK.createSession` (resolved from `/chains`). Direct `toSession`
755
- // callers pass `wrappedNativeToken` to opt in.
756
- const nativeWrapActions = wrappedNativeToken
757
- ? [
758
- {
759
- target: wrappedNativeToken,
760
- selector: toFunctionSelector({
761
- type: 'function',
762
- name: 'deposit',
763
- inputs: [],
764
- outputs: [],
765
- stateMutability: 'payable',
766
- }),
767
- },
768
- ]
769
- : [];
770
- const injectedActions = [
771
- ...nativeWrapActions,
772
- // Intent-execution fallback for any non-scoped call. Cross-chain
773
- // permits attach their synthesized SpendingLimits / TimeFrame
774
- // guardrails to this same fallback so the on-chain emissary applies
775
- // them when the orchestrator drives a bridge through the fallback
776
- // action path.
777
- {
778
- policies: [
779
- { type: 'intent-execution' },
780
- ...permitFallbackPolicies,
781
- ],
782
- },
783
- // Dummy action: allows the filler to call verifyExecution in ENABLE mode using
784
- // an injected dummy preclaimop so any session can be enabled on-chain without
785
- // a separate UserOp, regardless of whether it has claim or action policies.
786
- {
787
- target: DUMMY_PRECLAIMOP_TARGET,
788
- selector: DUMMY_PRECLAIMOP_SELECTOR,
789
- policies: [{ type: 'sudo' }],
790
- },
791
- ];
792
- const allActions = [...userActions, ...injectedActions];
793
- // When there are cross-chain permits but no explicit user actions, we
794
- // still want the injected fallback (with its synthesized guardrails)
795
- // to land on-chain — otherwise the legacy `[sudoAction]` path drops
796
- // the SpendingLimits / TimeFrame the user explicitly asked for.
797
- const needsInjection = userActions.length || permitFallbackPolicies.length;
798
- const actions = needsInjection
799
- ? allActions.map((action) => ({
800
- actionTargetSelector: 'selector' in action
801
- ? action.selector
802
- : SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
803
- actionTarget: 'target' in action
804
- ? action.target
805
- : SMART_SESSIONS_FALLBACK_TARGET_FLAG,
806
- actionPolicies: action.policies?.map((policy) => getPolicyData(policy, useDevContracts, addresses)) ?? [
807
- {
808
- policy: addresses.sudo,
809
- initData: '0x',
810
- },
811
- ],
812
- }))
813
- : [sudoAction];
814
- // Concatenate user-supplied claim policies with the ones synthesized
815
- // from cross-chain permits. Order is not security-sensitive — the
816
- // on-chain contract iterates the full list — but we keep user
817
- // policies first for deterministic permission IDs across SDK
818
- // releases that add permit expansion.
819
- const allClaimPolicies = [
820
- ...(session.claimPolicies ?? []),
821
- ...extraClaimPolicies,
822
- ];
823
- return {
824
- sessionValidator: validator.address,
825
- salt: zeroHash,
826
- sessionValidatorInitData: validator.initData,
827
- erc7739Policies: erc7739Data,
828
- actions,
829
- claimPolicies: allClaimPolicies.map((policy) => ({
830
- policy: PERMIT2_CLAIM_POLICY_ADDRESS,
831
- initData: encodePermit2ClaimPolicyInitData(resolvePermit2ClaimPolicy(policy)),
832
- })),
833
- };
834
- }
835
- function getSessionData(session) {
836
- return {
837
- sessionValidator: session.sessionValidator,
838
- salt: session.salt,
839
- sessionValidatorInitData: session.sessionValidatorInitData,
840
- erc7739Policies: session.erc7739Policies,
841
- actions: session.actions,
842
- claimPolicies: session.claimPolicies.map((policy) => ({
843
- policy: PERMIT2_CLAIM_POLICY_ADDRESS,
844
- initData: encodePermit2ClaimPolicyInitData(resolvePermit2ClaimPolicy(policy)),
845
- })),
846
- };
847
- }
848
- function getPermissionId(session) {
849
- return session.permissionId;
850
- }
851
- function getPermissionIdFromData(sessionData) {
852
- return keccak256(encodeAbiParameters([
853
- {
854
- type: 'address',
855
- name: 'sessionValidator',
856
- },
857
- {
858
- type: 'bytes',
859
- name: 'sessionValidatorInitData',
860
- },
861
- {
862
- type: 'bytes32',
863
- name: 'salt',
864
- },
865
- ], [
866
- sessionData.sessionValidator,
867
- sessionData.sessionValidatorInitData,
868
- sessionData.salt,
869
- ]));
870
- }
871
- function getActionConditionId(condition) {
872
- switch (condition) {
873
- case 'equal':
874
- return ACTION_CONDITION_EQUAL;
875
- case 'greaterThan':
876
- return ACTION_CONDITION_GREATER_THAN;
877
- case 'lessThan':
878
- return ACTION_CONDITION_LESS_THAN;
879
- case 'greaterThanOrEqual':
880
- return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
881
- case 'lessThanOrEqual':
882
- return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
883
- case 'notEqual':
884
- return ACTION_CONDITION_NOT_EQUAL;
885
- case 'inRange':
886
- return ACTION_CONDITION_IN_RANGE;
887
- }
888
- }
889
- function encodeActionParamRule(rule) {
890
- const ref = isHex(rule.referenceValue)
891
- ? padHex(rule.referenceValue)
892
- : toHex(rule.referenceValue, { size: 32 });
893
- return {
894
- condition: getActionConditionId(rule.condition),
895
- offset: rule.calldataOffset,
896
- isLimited: rule.usageLimit !== undefined,
897
- ref,
898
- usage: {
899
- limit: rule.usageLimit ?? 0n,
900
- used: 0n,
901
- },
902
- };
903
- }
904
- // Compile an ArgPolicyExpression AST into the on-chain wire format
905
- // (flat rules[] + bit-packed nodes[] + rootNodeIndex). Post-order walk:
906
- // children get appended before their parent so a parent's child indices
907
- // always reference earlier slots.
908
- function compileArgPolicyExpression(expr) {
909
- const rules = [];
910
- const nodes = [];
911
- function walk(e) {
912
- switch (e.type) {
913
- case 'rule': {
914
- const ruleIdx = rules.length;
915
- rules.push(encodeActionParamRule(e.rule));
916
- const nodeIdx = nodes.length;
917
- nodes.push(ARG_NODE_TYPE_RULE | (BigInt(ruleIdx) << ARG_RULE_INDEX_SHIFT));
918
- return nodeIdx;
919
- }
920
- case 'not': {
921
- const childIdx = walk(e.child);
922
- const nodeIdx = nodes.length;
923
- nodes.push(ARG_NODE_TYPE_NOT | (BigInt(childIdx) << ARG_LEFT_CHILD_SHIFT));
924
- return nodeIdx;
925
- }
926
- case 'and':
927
- case 'or': {
928
- const leftIdx = walk(e.left);
929
- const rightIdx = walk(e.right);
930
- const nodeIdx = nodes.length;
931
- const nodeType = e.type === 'and' ? ARG_NODE_TYPE_AND : ARG_NODE_TYPE_OR;
932
- nodes.push(nodeType |
933
- (BigInt(leftIdx) << ARG_LEFT_CHILD_SHIFT) |
934
- (BigInt(rightIdx) << ARG_RIGHT_CHILD_SHIFT));
935
- return nodeIdx;
936
- }
937
- }
938
- }
939
- const rootNodeIndex = walk(expr);
940
- if (rules.length > ARG_MAX_RULES) {
941
- throw new Error(`ArgPolicy expression has ${rules.length} rules, max is ${ARG_MAX_RULES}`);
942
- }
943
- if (nodes.length > ARG_MAX_NODES) {
944
- throw new Error(`ArgPolicy expression has ${nodes.length} nodes, max is ${ARG_MAX_NODES}`);
945
- }
946
- return { rules, packedNodes: nodes, rootNodeIndex };
947
- }
948
- function getPolicyData(policy, useDevContracts, addresses = DEFAULT_POLICY_ADDRESSES) {
949
- switch (policy.type) {
950
- case 'sudo':
951
- return {
952
- policy: addresses.sudo,
953
- initData: '0x',
954
- };
955
- case 'intent-execution':
956
- return {
957
- policy: useDevContracts
958
- ? INTENT_EXECUTION_POLICY_ADDRESS_DEV
959
- : INTENT_EXECUTION_POLICY_ADDRESS,
960
- initData: '0x',
961
- };
962
- case 'universal-action': {
963
- const MAX_RULES = 16;
964
- const rules = createFixedArray(MAX_RULES, () => ({
965
- condition: ACTION_CONDITION_EQUAL,
966
- offset: 0n,
967
- isLimited: false,
968
- ref: zeroHash,
969
- usage: { limit: 0n, used: 0n },
970
- }));
971
- for (let i = 0; i < policy.rules.length; i++) {
972
- rules[i] = encodeActionParamRule(policy.rules[i]);
973
- }
974
- return {
975
- policy: addresses.universalAction,
976
- initData: encodeAbiParameters([
977
- {
978
- components: [
979
- {
980
- name: 'valueLimitPerUse',
981
- type: 'uint256',
982
- },
983
- {
984
- components: [
985
- {
986
- name: 'length',
987
- type: 'uint256',
988
- },
989
- {
990
- components: [
991
- {
992
- name: 'condition',
993
- type: 'uint8',
994
- },
995
- {
996
- name: 'offset',
997
- type: 'uint64',
998
- },
999
- {
1000
- name: 'isLimited',
1001
- type: 'bool',
1002
- },
1003
- {
1004
- name: 'ref',
1005
- type: 'bytes32',
1006
- },
1007
- {
1008
- components: [
1009
- {
1010
- name: 'limit',
1011
- type: 'uint256',
1012
- },
1013
- {
1014
- name: 'used',
1015
- type: 'uint256',
1016
- },
1017
- ],
1018
- name: 'usage',
1019
- type: 'tuple',
1020
- },
1021
- ],
1022
- name: 'rules',
1023
- type: 'tuple[16]',
1024
- },
1025
- ],
1026
- name: 'paramRules',
1027
- type: 'tuple',
1028
- },
1029
- ],
1030
- name: 'ActionConfig',
1031
- type: 'tuple',
1032
- },
1033
- ], [
1034
- {
1035
- valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
1036
- paramRules: {
1037
- length: BigInt(policy.rules.length),
1038
- rules: rules,
1039
- },
1040
- },
1041
- ]),
1042
- };
1043
- }
1044
- case 'arg-policy': {
1045
- const { rules, packedNodes, rootNodeIndex } = compileArgPolicyExpression(policy.expression);
1046
- return {
1047
- policy: addresses.argPolicy,
1048
- initData: encodeAbiParameters([
1049
- {
1050
- components: [
1051
- { name: 'valueLimitPerUse', type: 'uint256' },
1052
- {
1053
- components: [
1054
- { name: 'rootNodeIndex', type: 'uint8' },
1055
- {
1056
- components: [
1057
- { name: 'condition', type: 'uint8' },
1058
- { name: 'offset', type: 'uint64' },
1059
- { name: 'isLimited', type: 'bool' },
1060
- { name: 'ref', type: 'bytes32' },
1061
- {
1062
- components: [
1063
- { name: 'limit', type: 'uint256' },
1064
- { name: 'used', type: 'uint256' },
1065
- ],
1066
- name: 'usage',
1067
- type: 'tuple',
1068
- },
1069
- ],
1070
- name: 'rules',
1071
- type: 'tuple[]',
1072
- },
1073
- { name: 'packedNodes', type: 'uint256[]' },
1074
- ],
1075
- name: 'paramRules',
1076
- type: 'tuple',
1077
- },
1078
- ],
1079
- name: 'ActionConfig',
1080
- type: 'tuple',
1081
- },
1082
- ], [
1083
- {
1084
- valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
1085
- paramRules: {
1086
- rootNodeIndex,
1087
- rules,
1088
- packedNodes,
1089
- },
1090
- },
1091
- ]),
1092
- };
1093
- }
1094
- case 'spending-limits': {
1095
- const tokens = policy.limits.map(({ token }) => token);
1096
- const limits = policy.limits.map(({ amount }) => amount);
1097
- return {
1098
- policy: addresses.spendingLimits,
1099
- initData: encodeAbiParameters([{ type: 'address[]' }, { type: 'uint256[]' }], [tokens, limits]),
1100
- };
1101
- }
1102
- case 'time-frame': {
1103
- // Deployed TimeFramePolicy slices initData[0:12] and unpacks as
1104
- // uint48 validUntil || uint48 validAfter (high 48 bits || low 48 bits).
1105
- return {
1106
- policy: addresses.timeFrame,
1107
- initData: encodePacked(['uint48', 'uint48'], [
1108
- Math.floor(policy.validUntil / 1000),
1109
- Math.floor(policy.validAfter / 1000),
1110
- ]),
1111
- };
1112
- }
1113
- case 'usage-limit': {
1114
- return {
1115
- policy: addresses.usageLimit,
1116
- initData: encodePacked(['uint128'], [policy.limit]),
1117
- };
1118
- }
1119
- case 'value-limit': {
1120
- return {
1121
- policy: addresses.valueLimit,
1122
- initData: encodeAbiParameters([{ type: 'uint256' }], [policy.limit]),
1123
- };
1124
- }
1125
- }
1126
- }
1127
- function getSmartSessionValidator(config) {
1128
- if (!config.experimental_sessions) {
1129
- return null;
1130
- }
1131
- const { enabled, module } = config.experimental_sessions;
1132
- if (!enabled) {
1133
- return null;
1134
- }
1135
- return {
1136
- address: module ?? getSmartSessionEmissaryAddress(config.useDevContracts),
1137
- initData: '0x',
1138
- deInitData: '0x',
1139
- additionalContext: '0x',
1140
- type: MODULE_TYPE_ID_VALIDATOR,
1141
- };
1142
- }
1143
- function getSmartSessionEmissaryAddress(useDevContracts) {
1144
- return useDevContracts === true
1145
- ? SMART_SESSION_EMISSARY_ADDRESS_DEV
1146
- : SMART_SESSION_EMISSARY_ADDRESS;
1147
- }
1148
- function buildMockSignature(session, useDevContracts, chainCount = 1, targetChainId,
1149
- // Defaults to the historical first-use ENABLE shape.
1150
- shape = 'enable') {
1151
- // packSignature keys ENABLE vs USE on enableData *presence* within the
1152
- // verifyExecutions branch, and takes the ERC-1271 branch when verifyExecutions
1153
- // is false — so derive both from the requested shape.
1154
- const verifyExecutions = shape !== 'erc1271';
1155
- const includeEnableData = shape === 'enable';
1156
- const emissaryAddress = getSmartSessionEmissaryAddress(useDevContracts);
1157
- // Include enableData only when the session is actually being enabled (ENABLE
1158
- // shape) — its presence is what makes packSignature emit 0x01 vs 0x00, and it's
1159
- // ignored entirely by the USE / ERC-1271 shapes. Built lazily so steady-state
1160
- // shapes skip the chainId-entry allocation.
1161
- let enableData;
1162
- if (includeEnableData) {
1163
- // Use targetChainId when provided (per-chain mockSignatures path) so the mock
1164
- // emissary's chainId check passes on the correct chain. Falls back to
1165
- // session.chain.id for the global mockSignature (single-chain path).
1166
- const primaryChainId = targetChainId ?? session.chain.id;
1167
- // Normalize chainCount to a finite positive integer — guards against NaN/
1168
- // undefined from callers (e.g. `sourceChains?.length`) that would otherwise
1169
- // produce an empty array and silently drop the ChainId check.
1170
- const safeChainCount = Number.isFinite(chainCount) && chainCount > 0 ? Math.floor(chainCount) : 1;
1171
- // First entry is the real chain ID (for the ChainId check), the rest are
1172
- // chainId 0 placeholders. Hash mismatch is skipped by the mock emissary, so
1173
- // sessionDigest can be zeroHash throughout.
1174
- const hashesAndChainIds = Array.from({ length: safeChainCount }, (_, i) => ({
1175
- chainId: i === 0 ? BigInt(primaryChainId) : 0n,
1176
- sessionDigest: zeroHash,
1177
- }));
1178
- enableData = {
1179
- userSignature: `0x${'00'.repeat(65)}`,
1180
- hashesAndChainIds,
1181
- sessionToEnableIndex: 0,
1182
- };
1183
- }
1184
- const dummySigners = {
1185
- type: 'experimental_session',
1186
- session,
1187
- verifyExecutions,
1188
- ...(enableData && { enableData }),
1189
- };
1190
- const dummyValidatorSignature = `0x${'00'.repeat(65)}`;
1191
- const sigData = packSignature(dummySigners, dummyValidatorSignature);
1192
- return concat([emissaryAddress, sigData]);
1193
- }
1194
- function createFixedArray(length, getValue) {
1195
- return Array.from({ length }, (_, i) => getValue(i));
1196
- }
1197
- export { SMART_SESSION_EMISSARY_ADDRESS, SMART_SESSION_EMISSARY_ADDRESS_DEV, SMART_SESSIONS_FALLBACK_TARGET_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION, DUMMY_PRECLAIMOP_TARGET, DUMMY_PRECLAIMOP_SELECTOR, SPENDING_LIMITS_POLICY_ADDRESS, TIME_FRAME_POLICY_ADDRESS, SUDO_POLICY_ADDRESS, UNIVERSAL_ACTION_POLICY_ADDRESS, ARG_POLICY_ADDRESS, USAGE_LIMIT_POLICY_ADDRESS, VALUE_LIMIT_POLICY_ADDRESS, INTENT_EXECUTION_POLICY_ADDRESS, packSignature, toSession, resolvePermit2ClaimPolicy, selectPermit2ClaimPolicyForMessage, getSessionData, getPolicyData, getEnableSessionCall, getDisableSessionCall, getPermissionId, getSmartSessionValidator, getSessionDetails, isSessionEnabled, signEnableSession, buildMockSignature, };