@oracle-agent/oracle 0.13.1 → 0.14.0

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 (449) hide show
  1. package/CONTRIBUTING.md +99 -0
  2. package/README.md +20 -14
  3. package/SECURITY.md +6 -8
  4. package/SETUP.md +25 -27
  5. package/bin/desk-server.mjs +473 -0
  6. package/bin/oracle-data-mcp.mjs +1252 -0
  7. package/bin/oracle-equities.mjs +168 -0
  8. package/bin/oracle-init.mjs +525 -0
  9. package/bin/oracle-public-server.mjs +36 -0
  10. package/bin/oracle-route.mjs +254 -0
  11. package/bin/oracle-scan.mjs +192 -0
  12. package/bin/oracle-upgrade.mjs +42 -0
  13. package/bin/oracle.mjs +34 -0
  14. package/docs/adding-a-chain.md +229 -0
  15. package/docs/architecture.md +139 -0
  16. package/docs/buzz-integration.md +115 -0
  17. package/docs/cli.md +143 -0
  18. package/docs/connectors.md +13 -0
  19. package/docs/hyperliquid-builder-code.md +50 -0
  20. package/docs/locals-only-fee-waiver.md +34 -0
  21. package/docs/oracle-pack-standard.md +29 -0
  22. package/docs/profiles.md +151 -0
  23. package/docs/public-surface.md +206 -0
  24. package/examples/add-a-chain.mjs +65 -0
  25. package/examples/oracle-pack-template.mjs +38 -0
  26. package/examples/research-a-token.mjs +70 -0
  27. package/package.json +78 -32
  28. package/plugins/oracle-owner-gate/__init__.py +288 -0
  29. package/plugins/oracle-owner-gate/plugin.yaml +9 -0
  30. package/{dist/assets/profiles → profiles}/oracle/SOUL.md +0 -14
  31. package/protocols/templates/safe-erc20/SECURITY.md +16 -0
  32. package/protocols/templates/safe-erc20/foundry.toml +12 -0
  33. package/protocols/templates/safe-erc20/remappings.txt +2 -0
  34. package/protocols/templates/safe-erc20/src/SafeERC20.sol +53 -0
  35. package/protocols/templates/safe-erc20/test/SafeERC20.t.sol +72 -0
  36. package/public/oracle-splash/_variants/ice.html +3 -3
  37. package/public/oracle-splash/_variants/ivory.html +3 -3
  38. package/public/oracle-splash/downloads/index.html +34 -223
  39. package/public/oracle-splash/index.html +11 -11
  40. package/scripts/adversarial-bench.mjs +114 -0
  41. package/scripts/build-dist.mjs +119 -0
  42. package/scripts/build-inscription.py +230 -0
  43. package/scripts/check-doc-drift.mjs +123 -0
  44. package/scripts/check-test-count.mjs +105 -0
  45. package/scripts/e2e-hl-markets.mjs +21 -0
  46. package/scripts/e2e-hl-perps.mjs +48 -0
  47. package/scripts/e2e-hypercore-staking.mjs +128 -0
  48. package/scripts/e2e-solana-bitcoin.mjs +183 -0
  49. package/scripts/guard-publish.mjs +22 -0
  50. package/scripts/protocol-template-gate.mjs +15 -0
  51. package/scripts/public-api-scan.mjs +23 -0
  52. package/scripts/publish-dist.mjs +67 -0
  53. package/scripts/record-hero-cli.sh +80 -0
  54. package/scripts/secret-scan.mjs +168 -0
  55. package/scripts/smoke-dist-bins.mjs +89 -0
  56. package/scripts/verify-dist.mjs +29 -0
  57. package/scripts/verify-v3-venues.mjs +233 -0
  58. package/skins/oracle.yaml +56 -0
  59. package/src/action-receipts.mjs +265 -0
  60. package/src/action-semantics.mjs +62 -0
  61. package/src/address-book.mjs +208 -0
  62. package/src/agent-auth.mjs +206 -0
  63. package/src/approval-guard.mjs +282 -0
  64. package/src/attestation-secret.mjs +94 -0
  65. package/src/audit-log.mjs +196 -0
  66. package/src/auth/oauth.mjs +672 -0
  67. package/src/auto-slippage.mjs +378 -0
  68. package/src/capability-posture.mjs +125 -0
  69. package/src/cards.mjs +422 -0
  70. package/src/chains.mjs +62 -0
  71. package/src/cli/chain-catalog.mjs +215 -0
  72. package/src/cli/chain-state.mjs +74 -0
  73. package/src/cli/commands/auth.mjs +193 -0
  74. package/src/cli/commands/bootstrap.mjs +87 -0
  75. package/src/cli/commands/chain.mjs +143 -0
  76. package/src/cli/commands/chat.mjs +465 -0
  77. package/src/cli/commands/credential.mjs +9 -0
  78. package/src/cli/commands/data-mcp.mjs +18 -0
  79. package/src/cli/commands/data.mjs +75 -0
  80. package/src/cli/commands/doctor.mjs +136 -0
  81. package/src/cli/commands/equities.mjs +41 -0
  82. package/src/cli/commands/farm.mjs +129 -0
  83. package/src/cli/commands/fees.mjs +109 -0
  84. package/src/cli/commands/follow.mjs +130 -0
  85. package/src/cli/commands/harness.mjs +63 -0
  86. package/src/cli/commands/help.mjs +7 -0
  87. package/src/cli/commands/init.mjs +27 -0
  88. package/src/cli/commands/mcp.mjs +154 -0
  89. package/src/cli/commands/model.mjs +106 -0
  90. package/src/cli/commands/plugins.mjs +241 -0
  91. package/src/cli/commands/prepare.mjs +12 -0
  92. package/src/cli/commands/public.mjs +20 -0
  93. package/src/cli/commands/resolve.mjs +64 -0
  94. package/src/cli/commands/route.mjs +12 -0
  95. package/src/cli/commands/runner.mjs +9 -0
  96. package/src/cli/commands/scan.mjs +12 -0
  97. package/src/cli/commands/setup.mjs +294 -0
  98. package/src/cli/commands/sign.mjs +21 -0
  99. package/src/cli/commands/signer.mjs +9 -0
  100. package/src/cli/commands/swap.mjs +102 -0
  101. package/src/cli/commands/upgrade.mjs +12 -0
  102. package/src/cli/commands/vault.mjs +9 -0
  103. package/src/cli/commands/version.mjs +22 -0
  104. package/src/cli/first-run.mjs +23 -0
  105. package/src/cli/kernel.mjs +262 -0
  106. package/src/cli/mcp-targets/chatgpt.mjs +51 -0
  107. package/src/cli/mcp-targets/claude-code.mjs +39 -0
  108. package/src/cli/mcp-targets/claude-desktop.mjs +24 -0
  109. package/src/cli/mcp-targets/codex.mjs +41 -0
  110. package/src/cli/mcp-targets/cursor.mjs +32 -0
  111. package/src/cli/mcp-targets/shared.mjs +71 -0
  112. package/src/cli/mcp-targets/vscode.mjs +39 -0
  113. package/src/cli/messaging-platforms.mjs +217 -0
  114. package/src/cli/model-config.mjs +78 -0
  115. package/src/cli/operator-dispatch.mjs +257 -0
  116. package/src/cli/oracle-harness.py +415 -0
  117. package/src/cli/paths.mjs +107 -0
  118. package/src/cli/runtime.mjs +351 -0
  119. package/src/cli/setup-state.mjs +168 -0
  120. package/src/cli/spawn-child.mjs +43 -0
  121. package/src/data/catalog.mjs +858 -0
  122. package/src/data/desk-data.mjs +877 -0
  123. package/src/data/http.mjs +253 -0
  124. package/src/data/names.mjs +188 -0
  125. package/src/data/provider-endpoint.mjs +94 -0
  126. package/src/data/providers/aave-v3.mjs +139 -0
  127. package/src/data/providers/across-bridge.mjs +41 -0
  128. package/src/data/providers/aerodrome.mjs +245 -0
  129. package/src/data/providers/aevo.mjs +33 -0
  130. package/src/data/providers/approval-indexer.mjs +133 -0
  131. package/src/data/providers/approvals.mjs +594 -0
  132. package/src/data/providers/babylon-staking.mjs +149 -0
  133. package/src/data/providers/balancer.mjs +209 -0
  134. package/src/data/providers/beefy-yields.mjs +45 -0
  135. package/src/data/providers/birdeye-tokens.mjs +33 -0
  136. package/src/data/providers/bisq-markets.mjs +145 -0
  137. package/src/data/providers/bitcoin-esplora.mjs +216 -0
  138. package/src/data/providers/bitcoin-meta.mjs +378 -0
  139. package/src/data/providers/blockscout.mjs +14 -0
  140. package/src/data/providers/bob-rootstock.mjs +198 -0
  141. package/src/data/providers/braiins-insights.mjs +103 -0
  142. package/src/data/providers/bridge-aggregator.mjs +259 -0
  143. package/src/data/providers/bridges.mjs +242 -0
  144. package/src/data/providers/bungee.mjs +29 -0
  145. package/src/data/providers/celestia-da.mjs +38 -0
  146. package/src/data/providers/changenow.mjs +135 -0
  147. package/src/data/providers/compound.mjs +32 -0
  148. package/src/data/providers/connext.mjs +28 -0
  149. package/src/data/providers/convex.mjs +30 -0
  150. package/src/data/providers/cow-protocol.mjs +110 -0
  151. package/src/data/providers/cowswap.mjs +415 -0
  152. package/src/data/providers/curve.mjs +201 -0
  153. package/src/data/providers/das-assets.mjs +59 -0
  154. package/src/data/providers/debridge.mjs +109 -0
  155. package/src/data/providers/defillama.mjs +88 -0
  156. package/src/data/providers/dexscreener.mjs +43 -0
  157. package/src/data/providers/drift.mjs +32 -0
  158. package/src/data/providers/dydx.mjs +41 -0
  159. package/src/data/providers/evm-rpc.mjs +225 -0
  160. package/src/data/providers/farming.mjs +291 -0
  161. package/src/data/providers/geckoterminal.mjs +34 -0
  162. package/src/data/providers/gmx.mjs +496 -0
  163. package/src/data/providers/hiro-stacks.mjs +150 -0
  164. package/src/data/providers/hl-assets.mjs +165 -0
  165. package/src/data/providers/hl-info.mjs +108 -0
  166. package/src/data/providers/hl-markets.mjs +210 -0
  167. package/src/data/providers/hl-outcome.mjs +61 -0
  168. package/src/data/providers/hl-perps.mjs +419 -0
  169. package/src/data/providers/hl-staking.mjs +353 -0
  170. package/src/data/providers/hl-ws.mjs +119 -0
  171. package/src/data/providers/hyperevm-dex.mjs +49 -0
  172. package/src/data/providers/jito-mev.mjs +117 -0
  173. package/src/data/providers/jupiter-venues.mjs +119 -0
  174. package/src/data/providers/jupiter.mjs +315 -0
  175. package/src/data/providers/kamino-strategies.mjs +143 -0
  176. package/src/data/providers/l2beat-tvl.mjs +42 -0
  177. package/src/data/providers/lifi.mjs +166 -0
  178. package/src/data/providers/liquid-esplora.mjs +152 -0
  179. package/src/data/providers/magiceden-ordinals.mjs +141 -0
  180. package/src/data/providers/magiceden-sol.mjs +406 -0
  181. package/src/data/providers/mempool-lightning.mjs +144 -0
  182. package/src/data/providers/mempool-mining.mjs +142 -0
  183. package/src/data/providers/meteora-dlmm.mjs +168 -0
  184. package/src/data/providers/morpho.mjs +177 -0
  185. package/src/data/providers/nft-gallery.mjs +163 -0
  186. package/src/data/providers/nft-portfolio.mjs +494 -0
  187. package/src/data/providers/odos.mjs +156 -0
  188. package/src/data/providers/ondo.mjs +31 -0
  189. package/src/data/providers/oneinch.mjs +174 -0
  190. package/src/data/providers/opensea-multichain.mjs +136 -0
  191. package/src/data/providers/opensea-nft.mjs +371 -0
  192. package/src/data/providers/orca.mjs +29 -0
  193. package/src/data/providers/ordinals-runes.mjs +180 -0
  194. package/src/data/providers/pancakeswap.mjs +28 -0
  195. package/src/data/providers/paraswap.mjs +125 -0
  196. package/src/data/providers/pendle.mjs +188 -0
  197. package/src/data/providers/poly-clob.mjs +283 -0
  198. package/src/data/providers/poly-public.mjs +96 -0
  199. package/src/data/providers/poly-ws.mjs +103 -0
  200. package/src/data/providers/polygon-staking.mjs +227 -0
  201. package/src/data/providers/portfolio-history.mjs +394 -0
  202. package/src/data/providers/portfolio.mjs +600 -0
  203. package/src/data/providers/pyth-price-feeds.mjs +172 -0
  204. package/src/data/providers/raydium.mjs +35 -0
  205. package/src/data/providers/relayscan-mev.mjs +72 -0
  206. package/src/data/providers/rfq.mjs +15 -0
  207. package/src/data/providers/rh-agent.mjs +59 -0
  208. package/src/data/providers/sanctum-lst.mjs +180 -0
  209. package/src/data/providers/satflow.mjs +341 -0
  210. package/src/data/providers/signed-material-guard.mjs +108 -0
  211. package/src/data/providers/solana-rpc.mjs +197 -0
  212. package/src/data/providers/solend-lending.mjs +166 -0
  213. package/src/data/providers/spark-lend.mjs +42 -0
  214. package/src/data/providers/squid-router.mjs +29 -0
  215. package/src/data/providers/stargate.mjs +29 -0
  216. package/src/data/providers/sushiswap.mjs +30 -0
  217. package/src/data/providers/symbiotic-restaking.mjs +41 -0
  218. package/src/data/providers/thorchain.mjs +36 -0
  219. package/src/data/providers/traderjoe.mjs +28 -0
  220. package/src/data/providers/twap.mjs +152 -0
  221. package/src/data/providers/uniswap-v3.mjs +457 -0
  222. package/src/data/providers/uniswap-v4.mjs +414 -0
  223. package/src/data/providers/vertex.mjs +41 -0
  224. package/src/data/providers/wallet-watch.mjs +264 -0
  225. package/src/data/providers/wormhole.mjs +28 -0
  226. package/src/data/providers/yearn.mjs +31 -0
  227. package/src/data/providers/zerox.mjs +167 -0
  228. package/src/data/public-api-scan.mjs +61 -0
  229. package/src/data/quote-placeholder.mjs +31 -0
  230. package/src/desk/swap-prepare.mjs +194 -0
  231. package/src/equities/bridge.mjs +388 -0
  232. package/src/equities/fixtures/bridge_routes.json +159 -0
  233. package/src/equities/fixtures/dst_transitions.json +29 -0
  234. package/src/equities/fixtures/equity_dex_pools.json +154 -0
  235. package/src/equities/fixtures/hip3_l2books.json +2711 -0
  236. package/src/equities/fixtures/nyse_holidays.json +1 -0
  237. package/src/equities/fixtures/oracles.json +100 -0
  238. package/src/equities/fixtures/rh_pool_state.json +244 -0
  239. package/src/equities/fixtures/solana_xstocks.json +704 -0
  240. package/src/equities/fixtures/ton_xstocks.json +35 -0
  241. package/src/equities/fixtures/universe.json +411 -0
  242. package/src/equities/fixtures/venues.json +3542 -0
  243. package/src/equities/fixtures.mjs +405 -0
  244. package/src/equities/funding.mjs +142 -0
  245. package/src/equities/index.mjs +166 -0
  246. package/src/equities/liveness.mjs +148 -0
  247. package/src/equities/marketHours.mjs +249 -0
  248. package/src/equities/normalize.mjs +295 -0
  249. package/src/equities/num.mjs +146 -0
  250. package/src/equities/prepare.mjs +95 -0
  251. package/src/equities/rank.mjs +260 -0
  252. package/src/equities/sourceNum.mjs +69 -0
  253. package/src/equities/types.mjs +220 -0
  254. package/src/equities/venues/arcus-perp.mjs +84 -0
  255. package/src/equities/venues/arcus-spot.mjs +105 -0
  256. package/src/equities/venues/hyperliquid-hip3.mjs +224 -0
  257. package/src/equities/venues/rh-uniswap.mjs +216 -0
  258. package/src/equities/venues/solana-xstocks.mjs +139 -0
  259. package/src/equities/venues/ton-stonfi.mjs +139 -0
  260. package/src/exact-integer.mjs +72 -0
  261. package/src/exec-policy.mjs +419 -0
  262. package/src/flags.mjs +15 -0
  263. package/src/fresh-window.mjs +76 -0
  264. package/src/gmx-attestation.mjs +176 -0
  265. package/src/index.mjs +107 -0
  266. package/src/licensing/locals-only.mjs +25 -0
  267. package/src/nft-gas-war-guard.mjs +139 -0
  268. package/src/onboarding/agent-keys.mjs +161 -0
  269. package/src/onboarding/harness-configs.mjs +102 -0
  270. package/src/onboarding/index.mjs +18 -0
  271. package/src/onboarding/tiers.mjs +139 -0
  272. package/src/oracle-env.mjs +55 -0
  273. package/src/package-manifest.mjs +42 -0
  274. package/src/plugins/agent-plugin-loader.mjs +225 -0
  275. package/src/portfolio-risk.mjs +170 -0
  276. package/src/prepare-envelope.mjs +204 -0
  277. package/src/profile-upgrade.mjs +277 -0
  278. package/src/protocol-execution.mjs +84 -0
  279. package/src/protocol-templates/gate.mjs +179 -0
  280. package/src/protocol-templates/prepare-deploy.mjs +81 -0
  281. package/src/public-api/agent-grants.mjs +57 -0
  282. package/src/public-api/buzz-integration.mjs +267 -0
  283. package/src/public-api/connect-agent.mjs +424 -0
  284. package/src/public-api/grants.mjs +142 -0
  285. package/src/public-api/http.mjs +707 -0
  286. package/src/public-api/metering.mjs +111 -0
  287. package/src/public-control/aa-adapter.mjs +402 -0
  288. package/src/public-control/build-registry.mjs +227 -0
  289. package/src/public-control/bundler-client.mjs +357 -0
  290. package/src/public-control/grant-indexer.mjs +296 -0
  291. package/src/public-control/policy-render.mjs +69 -0
  292. package/src/public-control/policy-schema.mjs +322 -0
  293. package/src/public-control/runtime-config.mjs +275 -0
  294. package/src/public-control/session-key-model.mjs +379 -0
  295. package/src/public-control/session-orchestrator.mjs +418 -0
  296. package/src/rfq/intent.mjs +180 -0
  297. package/src/rfq/sources.mjs +181 -0
  298. package/src/route-attestation.mjs +132 -0
  299. package/src/router/best-execution.mjs +326 -0
  300. package/src/router/index.mjs +250 -0
  301. package/src/router/integrator-fee.mjs +135 -0
  302. package/src/router/prepare-bridge.mjs +293 -0
  303. package/src/router/prepare-route.mjs +398 -0
  304. package/src/router/proposal.mjs +311 -0
  305. package/src/router/risk-classifier.mjs +119 -0
  306. package/src/router/route-sources.mjs +364 -0
  307. package/src/scanner/chains.config.mjs +543 -0
  308. package/src/scanner/contract.mjs +270 -0
  309. package/src/scanner/evm-scanner.mjs +394 -0
  310. package/src/scanner/index.mjs +9 -0
  311. package/src/scanner/v2-venue.mjs +351 -0
  312. package/src/scanner/v3-venue.mjs +308 -0
  313. package/src/scopes.mjs +44 -0
  314. package/src/sell-simulation.mjs +167 -0
  315. package/src/signals/engine.mjs +146 -0
  316. package/src/signals/index.mjs +1 -0
  317. package/src/token-transfer-guard.mjs +188 -0
  318. package/src/tui/app.mjs +438 -0
  319. package/src/tui/backend.mjs +215 -0
  320. package/src/tui/format.mjs +272 -0
  321. package/src/tui/gateway-client.mjs +177 -0
  322. package/src/tui/input.mjs +501 -0
  323. package/src/tui/memory.mjs +105 -0
  324. package/src/tui/meta-learn.mjs +85 -0
  325. package/src/tui/renderer.mjs +443 -0
  326. package/src/tui/scheduler.mjs +205 -0
  327. package/src/tui/skills-loader.mjs +140 -0
  328. package/src/tui/standalone-client.mjs +752 -0
  329. package/src/tui/theme.mjs +81 -0
  330. package/src/vault-attestation.mjs +146 -0
  331. package/src/venues.mjs +206 -0
  332. package/src/watch-preferences.mjs +85 -0
  333. package/dist/action-receipts.mjs +0 -1
  334. package/dist/action-semantics.mjs +0 -1
  335. package/dist/address-book.mjs +0 -2
  336. package/dist/bin/desk-server.mjs +0 -59
  337. package/dist/bin/oracle-data-mcp.mjs +0 -8
  338. package/dist/bin/oracle-equities.mjs +0 -20
  339. package/dist/bin/oracle-init.mjs +0 -24
  340. package/dist/bin/oracle-public-server.mjs +0 -5
  341. package/dist/bin/oracle-route.mjs +0 -22
  342. package/dist/bin/oracle-scan.mjs +0 -18
  343. package/dist/bin/oracle-upgrade.mjs +0 -21
  344. package/dist/bin/oracle.mjs +0 -76
  345. package/dist/chains.mjs +0 -1
  346. package/dist/cli/commands/auth.mjs +0 -16
  347. package/dist/cli/commands/bootstrap.mjs +0 -18
  348. package/dist/cli/commands/chain.mjs +0 -21
  349. package/dist/cli/commands/chat.mjs +0 -45
  350. package/dist/cli/commands/credential.mjs +0 -1
  351. package/dist/cli/commands/data-mcp.mjs +0 -2
  352. package/dist/cli/commands/data.mjs +0 -12
  353. package/dist/cli/commands/doctor.mjs +0 -5
  354. package/dist/cli/commands/equities.mjs +0 -15
  355. package/dist/cli/commands/farm.mjs +0 -59
  356. package/dist/cli/commands/follow.mjs +0 -28
  357. package/dist/cli/commands/gate.mjs +0 -13
  358. package/dist/cli/commands/harness.mjs +0 -15
  359. package/dist/cli/commands/help.mjs +0 -1
  360. package/dist/cli/commands/init.mjs +0 -3
  361. package/dist/cli/commands/mcp.mjs +0 -60
  362. package/dist/cli/commands/model.mjs +0 -54
  363. package/dist/cli/commands/plugins.mjs +0 -38
  364. package/dist/cli/commands/prepare.mjs +0 -2
  365. package/dist/cli/commands/public.mjs +0 -3
  366. package/dist/cli/commands/resolve.mjs +0 -23
  367. package/dist/cli/commands/route.mjs +0 -2
  368. package/dist/cli/commands/runner.mjs +0 -1
  369. package/dist/cli/commands/scan.mjs +0 -2
  370. package/dist/cli/commands/setup.mjs +0 -34
  371. package/dist/cli/commands/sign.mjs +0 -21
  372. package/dist/cli/commands/signer.mjs +0 -1
  373. package/dist/cli/commands/swap.mjs +0 -36
  374. package/dist/cli/commands/upgrade.mjs +0 -2
  375. package/dist/cli/commands/vault.mjs +0 -1
  376. package/dist/cli/commands/version.mjs +0 -2
  377. package/dist/data/desk-data.mjs +0 -55
  378. package/dist/data/names.mjs +0 -2
  379. package/dist/data/providers/farming.mjs +0 -2
  380. package/dist/equities/index.mjs +0 -1
  381. package/dist/index.mjs +0 -60
  382. package/dist/nft-gas-war-guard.mjs +0 -1
  383. package/dist/onboarding/harness-configs.mjs +0 -4
  384. package/dist/portfolio-risk.mjs +0 -1
  385. package/dist/prepare-envelope.mjs +0 -1
  386. package/dist/public-api/agent-grants.mjs +0 -3
  387. package/dist/public-control/policy-schema.mjs +0 -1
  388. package/dist/router/index.mjs +0 -2
  389. package/dist/scanner/index.mjs +0 -4
  390. package/dist/signals/index.mjs +0 -1
  391. package/dist/watch-preferences.mjs +0 -1
  392. /package/{dist/assets/profiles → profiles}/_template/SOUL.md +0 -0
  393. /package/{dist/assets/profiles → profiles}/_template/profile.json +0 -0
  394. /package/{dist/assets/profiles → profiles}/bitcoin-agent/SOUL.md +0 -0
  395. /package/{dist/assets/profiles → profiles}/bitcoin-agent/profile.json +0 -0
  396. /package/{dist/assets/profiles → profiles}/hyperliquid-agent/SOUL.md +0 -0
  397. /package/{dist/assets/profiles → profiles}/hyperliquid-agent/profile.json +0 -0
  398. /package/{dist/assets/profiles → profiles}/oracle/profile.json +0 -0
  399. /package/{dist/assets/profiles → profiles}/polymarket-agent/SOUL.md +0 -0
  400. /package/{dist/assets/profiles → profiles}/polymarket-agent/profile.json +0 -0
  401. /package/{dist/assets/profiles → profiles}/profile.schema.json +0 -0
  402. /package/{dist/assets/profiles → profiles}/protocol-builder/SOUL.md +0 -0
  403. /package/{dist/assets/profiles → profiles}/protocol-builder/profile.json +0 -0
  404. /package/{dist/assets/profiles → profiles}/robinhood-agent/SOUL.md +0 -0
  405. /package/{dist/assets/profiles → profiles}/robinhood-agent/profile.json +0 -0
  406. /package/{dist/assets/profiles → profiles}/solana-agent/SOUL.md +0 -0
  407. /package/{dist/assets/profiles → profiles}/solana-agent/profile.json +0 -0
  408. /package/{dist/assets/profiles → profiles}/stable-agent/SOUL.md +0 -0
  409. /package/{dist/assets/profiles → profiles}/stable-agent/profile.json +0 -0
  410. /package/{dist/assets/skills → skills}/balance/SKILL.md +0 -0
  411. /package/{dist/assets/skills → skills}/bitcoin-l1.md +0 -0
  412. /package/{dist/assets/skills → skills}/chain-defi-ecosystem-profiling.md +0 -0
  413. /package/{dist/assets/skills → skills}/evm-contract-research.md +0 -0
  414. /package/{dist/assets/skills → skills}/hyperliquid.md +0 -0
  415. /package/{dist/assets/skills → skills}/multichain-exec-desk.md +0 -0
  416. /package/{dist/assets/skills → skills}/oracle-action-semantics/SKILL.md +0 -0
  417. /package/{dist/assets/skills → skills}/oracle-best-execution/SKILL.md +0 -0
  418. /package/{dist/assets/skills → skills}/oracle-best-execution.md +0 -0
  419. /package/{dist/assets/skills → skills}/oracle-bitcoin/SKILL.md +0 -0
  420. /package/{dist/assets/skills → skills}/oracle-chain-graphs-telegram-cards/SKILL.md +0 -0
  421. /package/{dist/assets/skills → skills}/oracle-chat/SKILL.md +0 -0
  422. /package/{dist/assets/skills → skills}/oracle-chat/chain.SKILL.md +0 -0
  423. /package/{dist/assets/skills → skills}/oracle-chat/setup.SKILL.md +0 -0
  424. /package/{dist/assets/skills → skills}/oracle-circuit-breaker/SKILL.md +0 -0
  425. /package/{dist/assets/skills → skills}/oracle-contract-research/SKILL.md +0 -0
  426. /package/{dist/assets/skills → skills}/oracle-desk/SKILL.md +0 -0
  427. /package/{dist/assets/skills → skills}/oracle-desk.md +0 -0
  428. /package/{dist/assets/skills → skills}/oracle-dex-launch/SKILL.md +0 -0
  429. /package/{dist/assets/skills → skills}/oracle-equities/SKILL.md +0 -0
  430. /package/{dist/assets/skills → skills}/oracle-grants/SKILL.md +0 -0
  431. /package/{dist/assets/skills → skills}/oracle-hypercore-staking/SKILL.md +0 -0
  432. /package/{dist/assets/skills → skills}/oracle-hyperliquid/SKILL.md +0 -0
  433. /package/{dist/assets/skills → skills}/oracle-meme-token-sniper/SKILL.md +0 -0
  434. /package/{dist/assets/skills → skills}/oracle-multichain-nft-launch/SKILL.md +0 -0
  435. /package/{dist/assets/skills → skills}/oracle-multichain-token-launch/SKILL.md +0 -0
  436. /package/{dist/assets/skills → skills}/oracle-nft-gacha-launch/SKILL.md +0 -0
  437. /package/{dist/assets/skills → skills}/oracle-nft-mint-gas-war/SKILL.md +0 -0
  438. /package/{dist/assets/skills → skills}/oracle-polymarket/SKILL.md +0 -0
  439. /package/{dist/assets/skills → skills}/oracle-protocol-builder/SKILL.md +0 -0
  440. /package/{dist/assets/skills → skills}/oracle-protocol-security/SKILL.md +0 -0
  441. /package/{dist/assets/skills → skills}/oracle-public-product/SKILL.md +0 -0
  442. /package/{dist/assets/skills → skills}/oracle-receipts/SKILL.md +0 -0
  443. /package/{dist/assets/skills → skills}/oracle-receipts.md +0 -0
  444. /package/{dist/assets/skills → skills}/oracle-rfq-tokenized-assets/SKILL.md +0 -0
  445. /package/{dist/assets/skills → skills}/oracle-smart-wallet-scanner/SKILL.md +0 -0
  446. /package/{dist/assets/skills → skills}/oracle-solana/SKILL.md +0 -0
  447. /package/{dist/assets/skills → skills}/oracle-solana-nft/SKILL.md +0 -0
  448. /package/{dist/assets/skills → skills}/oracle-token-research/SKILL.md +0 -0
  449. /package/{dist/assets/skills → skills}/solana.md +0 -0
@@ -0,0 +1,275 @@
1
+ // Oracle Control — public runtime config: chain/bundler/paymaster registry
2
+ // (Slice K).
3
+ //
4
+ // This module is pure config parsing. It never makes a live network call and
5
+ // never imports the private executor stack — its only job is to turn env
6
+ // vars into a validated, in-memory registry of PUBLIC endpoints (chain
7
+ // metadata, bundler URLs, paymaster URLs, and the public HTTP bind) that the
8
+ // rest of Oracle Control (aa-adapter.mjs, bundler-client.mjs, http.mjs) can
9
+ // read from.
10
+ //
11
+ // Hard boundaries for this file:
12
+ // - Imports ONLY from ./aa-adapter.mjs (ENTRYPOINT_V07 — the single source
13
+ // of truth for the deployed EntryPoint address this codebase targets)
14
+ // and node builtins. NEVER from the private executor stack
15
+ // (get-signer.mjs, keystore.mjs, exec-policy.mjs, local-signer/*,
16
+ // adapters/*, mint-capability.mjs) — this module must never be wired to
17
+ // private operator wallet, and holds no secrets of any kind.
18
+ // - bundlerUrl/paymasterUrl are treated as PUBLIC endpoints (the same way a
19
+ // public RPC URL is public) — but they are still scanned for anything
20
+ // secret-SHAPED (a bearer token, an api-key-looking query param, a raw
21
+ // private-key hex blob, a PEM block) and rejected outright if found.
22
+ // Fail closed: a config that looks like it's carrying a credential in a
23
+ // URL must never load.
24
+ // - resolveChain() fails closed on any chainId not in the registry — no
25
+ // silent fallback to a made-up chain.
26
+ // - entryPoint is never read from env or invented; it is always pinned to
27
+ // aa-adapter.mjs's ENTRYPOINT_V07 and asserted equal for every seeded
28
+ // chain, so a typo/drift in this file can never point a chain at the
29
+ // wrong EntryPoint deployment.
30
+ // - redactedConfig() strips the query string (and any embedded userinfo)
31
+ // off every bundler/paymaster URL before it is considered "safe to log"
32
+ // — even though the full URL already passed the secret-shape scan at
33
+ // load time, a log line is a wider blast radius than an in-memory
34
+ // config object, so this view is deliberately more conservative.
35
+
36
+ import { ENTRYPOINT_V07 } from "./aa-adapter.mjs";
37
+
38
+ export class RuntimeConfigError extends Error {
39
+ constructor(message) {
40
+ super(`runtime-config: ${message}`);
41
+ this.name = "RuntimeConfigError";
42
+ }
43
+ }
44
+
45
+ function fail(message) {
46
+ throw new RuntimeConfigError(message);
47
+ }
48
+
49
+ // ---------------------------------------------------------------------------
50
+ // Secret-shape guard for public endpoint URLs (fail closed)
51
+ // ---------------------------------------------------------------------------
52
+
53
+ /** String-value shapes that must never appear in a bundler/paymaster URL.
54
+ * Mirrors the posture of connect-agent.mjs's FORBIDDEN_VALUE_RULES /
55
+ * bundler-client.mjs's SecretLeakError checks, scoped to what a URL could
56
+ * plausibly carry (query-string credentials, embedded key material). */
57
+ const SECRET_URL_RULES = Object.freeze([
58
+ // 32-byte hex — the shape of a raw EVM private key / session secret.
59
+ { rule: "raw-32-byte-hex-key", re: /0x[0-9a-fA-F]{64}/ },
60
+ { rule: "bearer-token", re: /bearer\s+[A-Za-z0-9._~+/=-]+/i },
61
+ { rule: "pem-private-key", re: /-----BEGIN[A-Z ]*PRIVATE KEY-----/ },
62
+ { rule: "authorization-header", re: /authorization\s*:/i },
63
+ // Credential-shaped query/path segment: ?api_key=..., ?token=..., ?secret=...,
64
+ // ?password=..., ?auth=..., ?access_token=..., ?bearer=..., or userinfo
65
+ // (user:pass@host) embedded in the URL itself.
66
+ {
67
+ rule: "credential-shaped-param",
68
+ re: /[?&](api[_-]?key|apikey|key|token|access[_-]?token|secret|password|passwd|auth|bearer)=/i,
69
+ },
70
+ { rule: "embedded-userinfo", re: /^[a-z][a-z0-9+.-]*:\/\/[^/@\s]+:[^/@\s]+@/i },
71
+ ]);
72
+
73
+ function assertPublicUrlSafe(value, label) {
74
+ if (typeof value !== "string" || value.trim() === "") {
75
+ fail(`${label} must be a non-empty string URL`);
76
+ }
77
+ let parsed;
78
+ try {
79
+ parsed = new URL(value);
80
+ } catch {
81
+ fail(`${label} is not a valid URL: ${value}`);
82
+ }
83
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
84
+ fail(`${label} must be an http(s) URL, got scheme ${parsed.protocol}`);
85
+ }
86
+ for (const { rule, re } of SECRET_URL_RULES) {
87
+ if (re.test(value)) {
88
+ fail(`${label} looks like it carries secret material (rule: ${rule}) — refusing to load a credential-shaped public endpoint`);
89
+ }
90
+ }
91
+ return value;
92
+ }
93
+
94
+ // ---------------------------------------------------------------------------
95
+ // Chain registry seed
96
+ // ---------------------------------------------------------------------------
97
+
98
+ /** Base metadata for every chain Oracle Control's public runtime config
99
+ * knows about out of the box. entryPoint is intentionally NOT stored here —
100
+ * it is always ENTRYPOINT_V07, asserted below, so there is exactly one
101
+ * place (aa-adapter.mjs) that can ever define it. */
102
+ const CHAIN_SEEDS = Object.freeze([
103
+ { chainId: 8453, name: "Base" },
104
+ { chainId: 42161, name: "Arbitrum" },
105
+ ]);
106
+
107
+ export const DEFAULT_CHAIN_ID = 8453;
108
+ export const DEFAULT_PUBLIC_HOST = "127.0.0.1";
109
+ export const DEFAULT_PUBLIC_PORT = 8799;
110
+ const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
111
+
112
+ function buildChainEntry(seed, env) {
113
+ const entry = {
114
+ name: seed.name,
115
+ entryPoint: ENTRYPOINT_V07,
116
+ };
117
+ // entryPoint must always equal aa-adapter's ENTRYPOINT_V07 for every
118
+ // supported chain — asserted here (not just "set here") so a future edit
119
+ // that tries to override it per-chain is caught immediately.
120
+ if (entry.entryPoint !== ENTRYPOINT_V07) {
121
+ fail(`chain ${seed.chainId} entryPoint drifted from aa-adapter ENTRYPOINT_V07`);
122
+ }
123
+
124
+ const bundlerVar = `ORACLE_BUNDLER_URL_${seed.chainId}`;
125
+ const paymasterVar = `ORACLE_PAYMASTER_URL_${seed.chainId}`;
126
+ const bundlerRaw = env[bundlerVar];
127
+ const paymasterRaw = env[paymasterVar];
128
+
129
+ if (bundlerRaw != null && String(bundlerRaw).trim() !== "") {
130
+ entry.bundlerUrl = assertPublicUrlSafe(String(bundlerRaw), bundlerVar);
131
+ }
132
+ if (paymasterRaw != null && String(paymasterRaw).trim() !== "") {
133
+ entry.paymasterUrl = assertPublicUrlSafe(String(paymasterRaw), paymasterVar);
134
+ }
135
+
136
+ return entry;
137
+ }
138
+
139
+ function parsePort(raw, label) {
140
+ const n = Number(raw);
141
+ if (!Number.isInteger(n) || n < 0 || n > 65535) {
142
+ fail(`${label} must be an integer port 0-65535, got ${JSON.stringify(raw)}`);
143
+ }
144
+ return n;
145
+ }
146
+
147
+ function parsePublicHost(raw, label) {
148
+ const host = String(raw).trim();
149
+ const normalized = host.toLowerCase().replace(/^\[|\]$/g, "");
150
+ if (!LOOPBACK_HOSTS.has(normalized)) {
151
+ fail(`${label} must be a loopback host, got ${JSON.stringify(raw)}`);
152
+ }
153
+ return normalized === "::1" ? "::1" : host;
154
+ }
155
+
156
+ /**
157
+ * Parse the public runtime config (chain/bundler/paymaster registry + public
158
+ * HTTP bind) from an env-like object. Pure function, no I/O, no network.
159
+ *
160
+ * @param {object} [env] defaults to process.env; any plain object of
161
+ * string-ish values works (this is what makes it deterministically
162
+ * testable without touching real process.env).
163
+ * @returns {{
164
+ * chains: Record<string, {name:string, entryPoint:string, bundlerUrl?:string, paymasterUrl?:string}>,
165
+ * defaultChainId: number,
166
+ * publicHost: string,
167
+ * publicPort: number,
168
+ * }}
169
+ */
170
+ export function loadPublicConfig(env = process.env) {
171
+ if (env == null || typeof env !== "object") {
172
+ fail("env must be an object");
173
+ }
174
+
175
+ const chains = {};
176
+ for (const seed of CHAIN_SEEDS) {
177
+ chains[String(seed.chainId)] = buildChainEntry(seed, env);
178
+ }
179
+
180
+ const rawDefaultChainId = env.ORACLE_DEFAULT_CHAIN_ID;
181
+ let defaultChainId = DEFAULT_CHAIN_ID;
182
+ if (rawDefaultChainId != null && String(rawDefaultChainId).trim() !== "") {
183
+ const n = Number(rawDefaultChainId);
184
+ if (!Number.isInteger(n)) {
185
+ fail(`ORACLE_DEFAULT_CHAIN_ID must be an integer chain id, got ${JSON.stringify(rawDefaultChainId)}`);
186
+ }
187
+ if (chains[String(n)] == null) {
188
+ fail(`ORACLE_DEFAULT_CHAIN_ID ${n} is not a registered chain (known: ${Object.keys(chains).join(", ")})`);
189
+ }
190
+ defaultChainId = n;
191
+ }
192
+
193
+ const publicHost = (() => {
194
+ const v = env.ORACLE_PUBLIC_HOST ?? env.MAD_PUBLIC_HOST;
195
+ return v != null && String(v).trim() !== "" ? parsePublicHost(v, "ORACLE_PUBLIC_HOST") : DEFAULT_PUBLIC_HOST;
196
+ })();
197
+
198
+ const publicPort = (() => {
199
+ const v = env.ORACLE_PUBLIC_PORT ?? env.MAD_PUBLIC_PORT;
200
+ if (v == null || String(v).trim() === "") return DEFAULT_PUBLIC_PORT;
201
+ return parsePort(v, "ORACLE_PUBLIC_PORT");
202
+ })();
203
+
204
+ return Object.freeze({
205
+ chains: Object.freeze(chains),
206
+ defaultChainId,
207
+ publicHost,
208
+ publicPort,
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Resolve a single chain entry from a loaded config. Fails closed on any
214
+ * chainId not present in the registry — never falls back to a guessed/
215
+ * default chain.
216
+ *
217
+ * @param {ReturnType<typeof loadPublicConfig>} config
218
+ * @param {number|string} chainId
219
+ */
220
+ export function resolveChain(config, chainId) {
221
+ if (config == null || typeof config.chains !== "object") {
222
+ fail("resolveChain: config must be a loadPublicConfig() result");
223
+ }
224
+ const key = String(chainId);
225
+ const entry = config.chains[key];
226
+ if (entry == null) {
227
+ fail(`unsupported chainId ${key} (registered: ${Object.keys(config.chains).join(", ") || "none"})`);
228
+ }
229
+ return entry;
230
+ }
231
+
232
+ /** Drop the query string and any userinfo from a URL, keeping only
233
+ * scheme://host:port/path — safe to write to a log line even though the
234
+ * full URL already passed the load-time secret-shape scan. */
235
+ function redactUrl(value) {
236
+ try {
237
+ const u = new URL(value);
238
+ u.search = "";
239
+ u.username = "";
240
+ u.password = "";
241
+ return u.toString();
242
+ } catch {
243
+ return "[unparseable-url-redacted]";
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Safe-to-log view of a loaded config: chain names/entryPoints/host/port
249
+ * pass through unchanged (none of that is secret-shaped), bundler/paymaster
250
+ * URLs are stripped down to origin+path only.
251
+ *
252
+ * @param {ReturnType<typeof loadPublicConfig>} config
253
+ */
254
+ export function redactedConfig(config) {
255
+ if (config == null || typeof config.chains !== "object") {
256
+ fail("redactedConfig: config must be a loadPublicConfig() result");
257
+ }
258
+ const chains = {};
259
+ for (const [chainId, entry] of Object.entries(config.chains)) {
260
+ chains[chainId] = {
261
+ name: entry.name,
262
+ entryPoint: entry.entryPoint,
263
+ ...(entry.bundlerUrl != null ? { bundlerUrl: redactUrl(entry.bundlerUrl) } : {}),
264
+ ...(entry.paymasterUrl != null ? { paymasterUrl: redactUrl(entry.paymasterUrl) } : {}),
265
+ };
266
+ }
267
+ return Object.freeze({
268
+ chains: Object.freeze(chains),
269
+ defaultChainId: config.defaultChainId,
270
+ publicHost: config.publicHost,
271
+ publicPort: config.publicPort,
272
+ });
273
+ }
274
+
275
+ export const _internal = { assertPublicUrlSafe, SECRET_URL_RULES, CHAIN_SEEDS };
@@ -0,0 +1,379 @@
1
+ // Oracle Control — provider-neutral account-abstraction session-key model.
2
+ //
3
+ // This is a design spike (Slice B / Phase 2 of the Oracle public release plan,
4
+ // see artifacts/oracle-public-plan.md and docs/public-self-custody-aa.md).
5
+ // It defines the SHAPE of a public self-custody session-key grant and the
6
+ // deterministic policy checks that decide whether a proposed action is
7
+ // authorized by that grant — independent of which account-abstraction stack
8
+ // (Safe, Kernel/ZeroDev, Biconomy/Nexus, permissionless/viem) eventually
9
+ // enforces it on-chain.
10
+ //
11
+ // Hard boundaries for this file:
12
+ // - No wallet/AA SDK imports. No RPC calls. No live chain integration.
13
+ // - No import from the private executor stack (get-signer.mjs, keystore.mjs,
14
+ // exec-policy.mjs, local-signer/*, oracle-env.mjs, adapters/*). This model
15
+ // must stand alone so it can never be wired to a private operator wallet.
16
+ // - Deterministic, pure functions only — same input always produces the
17
+ // same session id and the same authorization verdict.
18
+ // - `owner` (the user's main wallet / smart-account) never signs a
19
+ // transaction here. This module only decides whether an already-proposed
20
+ // action fits inside an already-granted, bounded session.
21
+ //
22
+ // Terminology:
23
+ // grant — the bounded permission the owner signed (chain, actions,
24
+ // targets, value/gas caps, expiry). Provider-neutral; a real
25
+ // integration maps this onto a Safe allowance module, a ZeroDev
26
+ // session-key validator, a Biconomy Nexus session module, or a
27
+ // permissionless/viem session account.
28
+ // agent — the session key address the grant authorizes to act. Never the
29
+ // owner's main key.
30
+ // request — a single proposed action (action id, target, value, gas) that
31
+ // is checked against a grant before anything is prepared/signed.
32
+
33
+ import { createHash } from "node:crypto";
34
+ import { exactBigInt } from "../exact-integer.mjs";
35
+ import { isWindowOpen } from "../fresh-window.mjs";
36
+
37
+ /** Account-abstraction stacks this model is written to be portable across.
38
+ * Purely descriptive — no SDK behavior is implied or imported here. */
39
+ export const PROVIDERS = Object.freeze({
40
+ SAFE: "safe",
41
+ KERNEL_ZERODEV: "kernel-zerodev",
42
+ BICONOMY_NEXUS: "biconomy-nexus",
43
+ PERMISSIONLESS_VIEM: "permissionless-viem",
44
+ });
45
+
46
+ export const PROVIDER_IDS = Object.freeze(Object.values(PROVIDERS));
47
+
48
+ /** Session lifecycle states returned by sessionStatus(). */
49
+ export const SESSION_STATUS = Object.freeze({
50
+ ACTIVE: "active",
51
+ EXPIRED: "expired",
52
+ REVOKED: "revoked",
53
+ });
54
+
55
+ export const MAX_SESSION_TTL_MS = 24 * 60 * 60 * 1000;
56
+
57
+ /** Action-id prefixes that never move funds or touch a target contract and
58
+ * therefore never require a non-empty target allowlist. Matches the "empty
59
+ * target allowlist only allowed for read/simulate scopes" rule in the Oracle
60
+ * public policy schema (artifacts/oracle-public-plan.md Phase 1). */
61
+ const READ_ONLY_ACTION_PREFIXES = ["read:", "simulate:"];
62
+
63
+ const ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
64
+ const HEX32_RE = /^0x[0-9a-fA-F]{64}$/;
65
+
66
+ function isReadOnlyAction(action) {
67
+ const a = String(action || "");
68
+ return READ_ONLY_ACTION_PREFIXES.some((p) => a.startsWith(p));
69
+ }
70
+
71
+ function fail(message) {
72
+ throw new Error(`session: ${message}`);
73
+ }
74
+
75
+ function normalAddress(value, label) {
76
+ const text = String(value ?? "").trim().toLowerCase();
77
+ if (!ADDRESS_RE.test(text)) fail(`${label} must be a 0x-prefixed 20-byte address`);
78
+ return text;
79
+ }
80
+
81
+ function normalActionId(value) {
82
+ const text = String(value ?? "").trim().toLowerCase();
83
+ if (!text) fail("action ids must be non-empty strings");
84
+ if (text.length > 128) fail("action id too long");
85
+ return text;
86
+ }
87
+
88
+ function normalPositiveInt(value, label) {
89
+ const n = Number(value);
90
+ if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) fail(`${label} must be a positive integer`);
91
+ return n;
92
+ }
93
+
94
+ function normalBigString(value, label, { allowZero = true } = {}) {
95
+ if (value == null || value === "") return "0";
96
+ // Wei caps bound delegated spend. An unsafe JS number rounds UP here and
97
+ // stores a looser cap than the owner wrote, so refuse rather than coerce.
98
+ let n;
99
+ try {
100
+ n = exactBigInt(value, label);
101
+ } catch (e) {
102
+ fail(e.message);
103
+ }
104
+ if (n < 0n) fail(`${label} must not be negative`);
105
+ if (!allowZero && n === 0n) fail(`${label} must be greater than zero`);
106
+ return n.toString();
107
+ }
108
+
109
+ /** Deterministic JSON: object keys sorted recursively, matching the
110
+ * canonicalJson convention already used by audit-log.mjs / vault-attestation.mjs
111
+ * so the same fields hash identically everywhere. Self-contained here on
112
+ * purpose (no cross-file import) to keep this design-spike file standalone. */
113
+ export function canonicalJson(value) {
114
+ if (value === null || value === undefined) return "null";
115
+ if (typeof value !== "object") return JSON.stringify(value);
116
+ if (Array.isArray(value)) return "[" + value.map(canonicalJson).join(",") + "]";
117
+ const keys = Object.keys(value).sort();
118
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + canonicalJson(value[k])).join(",") + "}";
119
+ }
120
+
121
+ /**
122
+ * Deterministic session id: sha256 over the canonical JSON of the grant's
123
+ * identity fields, prefixed 0x. Two grants with identical owner/agent/chain/
124
+ * actions/targets/caps/expiry/nonce always produce the same id; changing any
125
+ * field (including the ordering-insensitive actions/targets arrays, which are
126
+ * sorted before hashing) changes the id.
127
+ */
128
+ export function computeSessionId(fields) {
129
+ const h = createHash("sha256");
130
+ h.update(canonicalJson(fields), "utf8");
131
+ return `0x${h.digest("hex")}`;
132
+ }
133
+
134
+ /**
135
+ * Build and validate a provider-neutral session grant. Throws on any
136
+ * malformed/unsafe input (fail-closed). Returns a deep-frozen record.
137
+ *
138
+ * @param {object} input
139
+ * @param {string} input.provider one of PROVIDERS (informational; which
140
+ * AA stack is expected to enforce this)
141
+ * @param {string} input.owner user's main wallet / smart-account address
142
+ * @param {string} input.agent session key address (must differ from owner)
143
+ * @param {number} input.chainId positive integer chain id
144
+ * @param {string[]} input.actions non-empty list of action ids (e.g.
145
+ * "erc20:transfer", "swap:exec", "read:balance")
146
+ * @param {string[]} [input.targets] allowed destination addresses. May be
147
+ * empty ONLY if every action is read/simulate.
148
+ * @param {string|number|bigint} [input.maxValueWei] native-value cap (default "0")
149
+ * @param {string|number|bigint} [input.maxGasWei] optional gas-fee cap (gasLimit*feePerGas)
150
+ * @param {number} input.expiresAtMs epoch ms the grant stops being valid
151
+ * @param {string|number} [input.nonce] uniqueness salt (default 0)
152
+ * @param {number} [input.issuedAtMs] epoch ms issuance time (default Date.now())
153
+ */
154
+ export function createSessionGrant({
155
+ provider,
156
+ owner,
157
+ agent,
158
+ chainId,
159
+ actions,
160
+ targets = [],
161
+ maxValueWei = "0",
162
+ maxGasWei,
163
+ expiresAtMs,
164
+ nonce = 0,
165
+ issuedAtMs = Date.now(),
166
+ } = {}) {
167
+ const normalizedProvider = String(provider ?? "").trim().toLowerCase();
168
+ if (!PROVIDER_IDS.includes(normalizedProvider)) {
169
+ fail(`provider must be one of ${PROVIDER_IDS.join(", ")}`);
170
+ }
171
+
172
+ const normalizedOwner = normalAddress(owner, "owner");
173
+ const normalizedAgent = normalAddress(agent, "agent");
174
+ if (normalizedOwner === normalizedAgent) fail("agent key must differ from owner wallet");
175
+
176
+ const normalizedChainId = normalPositiveInt(chainId, "chainId");
177
+
178
+ if (!Array.isArray(actions) || actions.length === 0) fail("actions must be a non-empty array");
179
+ const normalizedActions = [...new Set(actions.map(normalActionId))].sort();
180
+
181
+ if (!Array.isArray(targets)) fail("targets must be an array");
182
+ const normalizedTargets = [...new Set(targets.map((t) => normalAddress(t, "target")))].sort();
183
+
184
+ const allActionsReadOnly = normalizedActions.every(isReadOnlyAction);
185
+ if (normalizedTargets.length === 0 && !allActionsReadOnly) {
186
+ fail("empty target allowlist is only allowed when every action is read/simulate");
187
+ }
188
+
189
+ const normalizedMaxValueWei = normalBigString(maxValueWei, "maxValueWei");
190
+ const normalizedMaxGasWei = maxGasWei == null ? null : normalBigString(maxGasWei, "maxGasWei");
191
+
192
+ const normalizedIssuedAtMs = Number(issuedAtMs);
193
+ if (!Number.isFinite(normalizedIssuedAtMs)) fail("issuedAtMs must be a finite number");
194
+ const normalizedExpiresAtMs = Number(expiresAtMs);
195
+ if (!Number.isFinite(normalizedExpiresAtMs)) fail("expiresAtMs must be a finite number");
196
+ if (normalizedExpiresAtMs <= normalizedIssuedAtMs) fail("expiresAtMs must be after issuedAtMs");
197
+ if (normalizedExpiresAtMs - normalizedIssuedAtMs > MAX_SESSION_TTL_MS) {
198
+ fail(`session grant exceeds the hard 24-hour TTL (${MAX_SESSION_TTL_MS} ms)`);
199
+ }
200
+
201
+ const normalizedNonce = String(nonce ?? 0);
202
+
203
+ const identity = {
204
+ mode: "oracle-session-grant",
205
+ version: 1,
206
+ provider: normalizedProvider,
207
+ owner: normalizedOwner,
208
+ agent: normalizedAgent,
209
+ chainId: normalizedChainId,
210
+ actions: normalizedActions,
211
+ targets: normalizedTargets,
212
+ maxValueWei: normalizedMaxValueWei,
213
+ maxGasWei: normalizedMaxGasWei,
214
+ issuedAtMs: normalizedIssuedAtMs,
215
+ expiresAtMs: normalizedExpiresAtMs,
216
+ nonce: normalizedNonce,
217
+ };
218
+
219
+ const id = computeSessionId(identity);
220
+ const grant = { id, ...identity };
221
+ return Object.freeze(grant);
222
+ }
223
+
224
+ /** In-memory revocation registry. Deterministic, no chain dependency — a real
225
+ * integration backs this with an on-chain revoke (Safe module disable,
226
+ * ZeroDev/Biconomy session revoke) or an off-chain indexer; the interface
227
+ * here is what Oracle Control's policy check consumes either way. */
228
+ export function createRevocationRegistry() {
229
+ const revoked = new Map(); // sessionId -> { revokedAtMs, reason }
230
+ return {
231
+ revoke(sessionId, { nowMs = Date.now(), reason = null } = {}) {
232
+ if (!sessionId) fail("revoke requires a sessionId");
233
+ if (!revoked.has(sessionId)) revoked.set(sessionId, { revokedAtMs: Number(nowMs), reason });
234
+ return revoked.get(sessionId);
235
+ },
236
+ isRevoked(sessionId) {
237
+ return revoked.has(sessionId);
238
+ },
239
+ revokedAt(sessionId) {
240
+ return revoked.get(sessionId)?.revokedAtMs ?? null;
241
+ },
242
+ get size() {
243
+ return revoked.size;
244
+ },
245
+ };
246
+ }
247
+
248
+ function isRevokedGrant(grant, revocation) {
249
+ if (!revocation) return false;
250
+ if (typeof revocation.isRevoked === "function") return revocation.isRevoked(grant.id);
251
+ if (revocation instanceof Set) return revocation.has(grant.id);
252
+ if (Array.isArray(revocation)) return revocation.includes(grant.id);
253
+ return false;
254
+ }
255
+
256
+ /**
257
+ * Compute a grant's current lifecycle status. Revocation takes precedence
258
+ * over expiry (a revoked-then-expired grant still reports "revoked", which
259
+ * matters for audit trails downstream).
260
+ */
261
+ export function sessionStatus(grant, { nowMs = Date.now(), revocation } = {}) {
262
+ if (!grant || grant.mode !== "oracle-session-grant") fail("invalid session grant");
263
+ if (isRevokedGrant(grant, revocation)) return SESSION_STATUS.REVOKED;
264
+ // Fail CLOSED on an unusable clock. `Number(nowMs) >= expiresAtMs` is false
265
+ // for NaN / null / "later" / -Infinity, so a long-dead grant reported ACTIVE
266
+ // and authorized spending at its full cap. `null` is the sharp edge: it slips
267
+ // past the `= Date.now()` default because it is a supplied value, and
268
+ // Number(null) === 0.
269
+ if (!isWindowOpen({ expiresAtMs: grant.expiresAtMs }, nowMs, { inclusive: true })) return SESSION_STATUS.EXPIRED;
270
+ return SESSION_STATUS.ACTIVE;
271
+ }
272
+
273
+ export function isSessionActive(grant, opts = {}) {
274
+ return sessionStatus(grant, opts) === SESSION_STATUS.ACTIVE;
275
+ }
276
+
277
+ /**
278
+ * Authorize a single proposed action against a session grant. Throws a
279
+ * "session: ..." Error on any violation (fail-closed); returns true only when
280
+ * every check passes. This is a pure policy check — it does not sign,
281
+ * prepare, or broadcast anything.
282
+ *
283
+ * @param {object} grant output of createSessionGrant()
284
+ * @param {object} request
285
+ * @param {string} request.action action id being attempted
286
+ * @param {number} request.chainId chain the action targets
287
+ * @param {string} [request.target] destination address (required unless read/simulate)
288
+ * @param {string|number|bigint} [request.valueWei] native value moved (default 0)
289
+ * @param {string|number|bigint} [request.gasWei] gasLimit*feePerGas estimate
290
+ * @param {object} [opts]
291
+ * @param {number} [opts.nowMs]
292
+ * @param {object|Set|string[]} [opts.revocation] registry / set / array of revoked ids
293
+ */
294
+ export function assertSessionAuthorized(grant, request = {}, opts = {}) {
295
+ if (!grant || grant.mode !== "oracle-session-grant") fail("invalid session grant");
296
+
297
+ const status = sessionStatus(grant, opts);
298
+ if (status === SESSION_STATUS.REVOKED) fail(`session ${grant.id} is revoked`);
299
+ if (status === SESSION_STATUS.EXPIRED) fail(`session ${grant.id} expired at ${grant.expiresAtMs}`);
300
+
301
+ const requestedChainId = normalPositiveInt(request.chainId, "request.chainId");
302
+ if (requestedChainId !== grant.chainId) {
303
+ fail(`chain mismatch: session is scoped to ${grant.chainId}, request is ${requestedChainId}`);
304
+ }
305
+
306
+ const action = normalActionId(request.action);
307
+ if (!grant.actions.includes(action)) {
308
+ fail(`action "${action}" not permitted by session ${grant.id}`);
309
+ }
310
+
311
+ const readOnly = isReadOnlyAction(action);
312
+ if (!readOnly) {
313
+ if (request.target == null || request.target === "") fail("target required for a non-read action");
314
+ const target = normalAddress(request.target, "request.target");
315
+ if (grant.targets.length === 0) fail(`session ${grant.id} has no granted targets (fail-closed)`);
316
+ if (!grant.targets.includes(target)) {
317
+ fail(`target ${target} not permitted by session ${grant.id}`);
318
+ }
319
+ }
320
+
321
+ const valueWei = BigInt(normalBigString(request.valueWei ?? "0", "request.valueWei"));
322
+ const maxValueWei = BigInt(grant.maxValueWei);
323
+ if (valueWei > maxValueWei) {
324
+ fail(`value ${valueWei} exceeds session cap ${maxValueWei}`);
325
+ }
326
+
327
+ // A gas ceiling on the grant is a promise the grant makes. Honouring it only
328
+ // when the REQUEST volunteers a gasWei made it optional in practice: a
329
+ // requester could omit the field and satisfy a grant whose explicit ceiling
330
+ // would otherwise reject the transaction. If the grant bounds gas, the
331
+ // request must state it.
332
+ if (grant.maxGasWei != null) {
333
+ if (request.gasWei == null) {
334
+ fail("session grant bounds gas but the request omitted gasWei — refusing to authorize unbounded gas");
335
+ }
336
+ const gasWei = BigInt(normalBigString(request.gasWei, "request.gasWei"));
337
+ const maxGasWei = BigInt(grant.maxGasWei);
338
+ if (gasWei > maxGasWei) {
339
+ fail(`gas fee ${gasWei} exceeds session cap ${maxGasWei}`);
340
+ }
341
+ }
342
+
343
+ return true;
344
+ }
345
+
346
+ /** Convenience non-throwing wrapper: returns { ok, reason }. */
347
+ export function checkSessionAuthorized(grant, request = {}, opts = {}) {
348
+ try {
349
+ assertSessionAuthorized(grant, request, opts);
350
+ return { ok: true };
351
+ } catch (e) {
352
+ return { ok: false, reason: String(e?.message || e) };
353
+ }
354
+ }
355
+
356
+ /** Redacted view safe to log/index — drops nothing secret today (this model
357
+ * never carries key material) but exists so callers have one stable place to
358
+ * serialize a grant for an audit trail without hand-picking fields. */
359
+ export function toAuditRecord(grant) {
360
+ if (!grant || grant.mode !== "oracle-session-grant") fail("invalid session grant");
361
+ return {
362
+ id: grant.id,
363
+ provider: grant.provider,
364
+ owner: grant.owner,
365
+ agent: grant.agent,
366
+ chainId: grant.chainId,
367
+ actions: grant.actions,
368
+ targets: grant.targets,
369
+ maxValueWei: grant.maxValueWei,
370
+ maxGasWei: grant.maxGasWei,
371
+ issuedAtMs: grant.issuedAtMs,
372
+ expiresAtMs: grant.expiresAtMs,
373
+ nonce: grant.nonce,
374
+ };
375
+ }
376
+
377
+ // Exported for tests / callers that want the raw address/hash validators
378
+ // without re-implementing them.
379
+ export const _internal = { ADDRESS_RE, HEX32_RE, isReadOnlyAction };