@waiaas/daemon 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (480) hide show
  1. package/dist/api/error-hints.d.ts +15 -0
  2. package/dist/api/error-hints.d.ts.map +1 -0
  3. package/dist/api/error-hints.js +71 -0
  4. package/dist/api/error-hints.js.map +1 -0
  5. package/dist/api/index.d.ts +11 -0
  6. package/dist/api/index.d.ts.map +1 -0
  7. package/dist/api/index.js +14 -0
  8. package/dist/api/index.js.map +1 -0
  9. package/dist/api/middleware/address-validation.d.ts +38 -0
  10. package/dist/api/middleware/address-validation.d.ts.map +1 -0
  11. package/dist/api/middleware/address-validation.js +134 -0
  12. package/dist/api/middleware/address-validation.js.map +1 -0
  13. package/dist/api/middleware/csp.d.ts +17 -0
  14. package/dist/api/middleware/csp.d.ts.map +1 -0
  15. package/dist/api/middleware/csp.js +31 -0
  16. package/dist/api/middleware/csp.js.map +1 -0
  17. package/dist/api/middleware/error-handler.d.ts +16 -0
  18. package/dist/api/middleware/error-handler.d.ts.map +1 -0
  19. package/dist/api/middleware/error-handler.js +46 -0
  20. package/dist/api/middleware/error-handler.js.map +1 -0
  21. package/dist/api/middleware/host-guard.d.ts +11 -0
  22. package/dist/api/middleware/host-guard.d.ts.map +1 -0
  23. package/dist/api/middleware/host-guard.js +25 -0
  24. package/dist/api/middleware/host-guard.js.map +1 -0
  25. package/dist/api/middleware/index.d.ts +13 -0
  26. package/dist/api/middleware/index.d.ts.map +1 -0
  27. package/dist/api/middleware/index.js +13 -0
  28. package/dist/api/middleware/index.js.map +1 -0
  29. package/dist/api/middleware/kill-switch-guard.d.ts +19 -0
  30. package/dist/api/middleware/kill-switch-guard.d.ts.map +1 -0
  31. package/dist/api/middleware/kill-switch-guard.js +49 -0
  32. package/dist/api/middleware/kill-switch-guard.js.map +1 -0
  33. package/dist/api/middleware/master-auth.d.ts +15 -0
  34. package/dist/api/middleware/master-auth.d.ts.map +1 -0
  35. package/dist/api/middleware/master-auth.js +35 -0
  36. package/dist/api/middleware/master-auth.js.map +1 -0
  37. package/dist/api/middleware/owner-auth.d.ts +30 -0
  38. package/dist/api/middleware/owner-auth.d.ts.map +1 -0
  39. package/dist/api/middleware/owner-auth.js +133 -0
  40. package/dist/api/middleware/owner-auth.js.map +1 -0
  41. package/dist/api/middleware/request-id.d.ts +10 -0
  42. package/dist/api/middleware/request-id.d.ts.map +1 -0
  43. package/dist/api/middleware/request-id.js +18 -0
  44. package/dist/api/middleware/request-id.js.map +1 -0
  45. package/dist/api/middleware/request-logger.d.ts +9 -0
  46. package/dist/api/middleware/request-logger.d.ts.map +1 -0
  47. package/dist/api/middleware/request-logger.js +18 -0
  48. package/dist/api/middleware/request-logger.js.map +1 -0
  49. package/dist/api/middleware/session-auth.d.ts +21 -0
  50. package/dist/api/middleware/session-auth.d.ts.map +1 -0
  51. package/dist/api/middleware/session-auth.js +51 -0
  52. package/dist/api/middleware/session-auth.js.map +1 -0
  53. package/dist/api/middleware/siwe-verify.d.ts +31 -0
  54. package/dist/api/middleware/siwe-verify.d.ts.map +1 -0
  55. package/dist/api/middleware/siwe-verify.js +55 -0
  56. package/dist/api/middleware/siwe-verify.js.map +1 -0
  57. package/dist/api/routes/actions.d.ts +56 -0
  58. package/dist/api/routes/actions.d.ts.map +1 -0
  59. package/dist/api/routes/actions.js +291 -0
  60. package/dist/api/routes/actions.js.map +1 -0
  61. package/dist/api/routes/admin.d.ts +99 -0
  62. package/dist/api/routes/admin.d.ts.map +1 -0
  63. package/dist/api/routes/admin.js +1304 -0
  64. package/dist/api/routes/admin.js.map +1 -0
  65. package/dist/api/routes/display-currency-helper.d.ts +26 -0
  66. package/dist/api/routes/display-currency-helper.d.ts.map +1 -0
  67. package/dist/api/routes/display-currency-helper.js +47 -0
  68. package/dist/api/routes/display-currency-helper.js.map +1 -0
  69. package/dist/api/routes/health.d.ts +14 -0
  70. package/dist/api/routes/health.d.ts.map +1 -0
  71. package/dist/api/routes/health.js +47 -0
  72. package/dist/api/routes/health.js.map +1 -0
  73. package/dist/api/routes/index.d.ts +15 -0
  74. package/dist/api/routes/index.d.ts.map +1 -0
  75. package/dist/api/routes/index.js +15 -0
  76. package/dist/api/routes/index.js.map +1 -0
  77. package/dist/api/routes/mcp.d.ts +30 -0
  78. package/dist/api/routes/mcp.d.ts.map +1 -0
  79. package/dist/api/routes/mcp.js +156 -0
  80. package/dist/api/routes/mcp.js.map +1 -0
  81. package/dist/api/routes/nonce.d.ts +20 -0
  82. package/dist/api/routes/nonce.d.ts.map +1 -0
  83. package/dist/api/routes/nonce.js +48 -0
  84. package/dist/api/routes/nonce.js.map +1 -0
  85. package/dist/api/routes/openapi-schemas.d.ts +2281 -0
  86. package/dist/api/routes/openapi-schemas.d.ts.map +1 -0
  87. package/dist/api/routes/openapi-schemas.js +770 -0
  88. package/dist/api/routes/openapi-schemas.js.map +1 -0
  89. package/dist/api/routes/policies.d.ts +29 -0
  90. package/dist/api/routes/policies.d.ts.map +1 -0
  91. package/dist/api/routes/policies.js +332 -0
  92. package/dist/api/routes/policies.js.map +1 -0
  93. package/dist/api/routes/sessions.d.ts +35 -0
  94. package/dist/api/routes/sessions.d.ts.map +1 -0
  95. package/dist/api/routes/sessions.js +347 -0
  96. package/dist/api/routes/sessions.js.map +1 -0
  97. package/dist/api/routes/skills.d.ts +9 -0
  98. package/dist/api/routes/skills.d.ts.map +1 -0
  99. package/dist/api/routes/skills.js +59 -0
  100. package/dist/api/routes/skills.js.map +1 -0
  101. package/dist/api/routes/tokens.d.ts +25 -0
  102. package/dist/api/routes/tokens.d.ts.map +1 -0
  103. package/dist/api/routes/tokens.js +161 -0
  104. package/dist/api/routes/tokens.js.map +1 -0
  105. package/dist/api/routes/transactions.d.ts +68 -0
  106. package/dist/api/routes/transactions.d.ts.map +1 -0
  107. package/dist/api/routes/transactions.js +576 -0
  108. package/dist/api/routes/transactions.js.map +1 -0
  109. package/dist/api/routes/utils.d.ts +9 -0
  110. package/dist/api/routes/utils.d.ts.map +1 -0
  111. package/dist/api/routes/utils.js +52 -0
  112. package/dist/api/routes/utils.js.map +1 -0
  113. package/dist/api/routes/wallet.d.ts +36 -0
  114. package/dist/api/routes/wallet.d.ts.map +1 -0
  115. package/dist/api/routes/wallet.js +358 -0
  116. package/dist/api/routes/wallet.js.map +1 -0
  117. package/dist/api/routes/wallets.d.ts +43 -0
  118. package/dist/api/routes/wallets.d.ts.map +1 -0
  119. package/dist/api/routes/wallets.js +630 -0
  120. package/dist/api/routes/wallets.js.map +1 -0
  121. package/dist/api/routes/wc.d.ts +46 -0
  122. package/dist/api/routes/wc.d.ts.map +1 -0
  123. package/dist/api/routes/wc.js +354 -0
  124. package/dist/api/routes/wc.js.map +1 -0
  125. package/dist/api/routes/x402.d.ts +61 -0
  126. package/dist/api/routes/x402.d.ts.map +1 -0
  127. package/dist/api/routes/x402.js +493 -0
  128. package/dist/api/routes/x402.js.map +1 -0
  129. package/dist/api/server.d.ts +81 -0
  130. package/dist/api/server.d.ts.map +1 -0
  131. package/dist/api/server.js +406 -0
  132. package/dist/api/server.js.map +1 -0
  133. package/dist/index.d.ts +35 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +43 -0
  136. package/dist/index.js.map +1 -0
  137. package/dist/infrastructure/action/action-provider-registry.d.ts +77 -0
  138. package/dist/infrastructure/action/action-provider-registry.d.ts.map +1 -0
  139. package/dist/infrastructure/action/action-provider-registry.js +239 -0
  140. package/dist/infrastructure/action/action-provider-registry.js.map +1 -0
  141. package/dist/infrastructure/action/api-key-store.d.ts +60 -0
  142. package/dist/infrastructure/action/api-key-store.d.ts.map +1 -0
  143. package/dist/infrastructure/action/api-key-store.js +130 -0
  144. package/dist/infrastructure/action/api-key-store.js.map +1 -0
  145. package/dist/infrastructure/action/index.d.ts +10 -0
  146. package/dist/infrastructure/action/index.d.ts.map +1 -0
  147. package/dist/infrastructure/action/index.js +9 -0
  148. package/dist/infrastructure/action/index.js.map +1 -0
  149. package/dist/infrastructure/adapter-pool.d.ts +50 -0
  150. package/dist/infrastructure/adapter-pool.d.ts.map +1 -0
  151. package/dist/infrastructure/adapter-pool.js +110 -0
  152. package/dist/infrastructure/adapter-pool.js.map +1 -0
  153. package/dist/infrastructure/backup/backup-service.d.ts +53 -0
  154. package/dist/infrastructure/backup/backup-service.d.ts.map +1 -0
  155. package/dist/infrastructure/backup/backup-service.js +158 -0
  156. package/dist/infrastructure/backup/backup-service.js.map +1 -0
  157. package/dist/infrastructure/backup/index.d.ts +2 -0
  158. package/dist/infrastructure/backup/index.d.ts.map +1 -0
  159. package/dist/infrastructure/backup/index.js +2 -0
  160. package/dist/infrastructure/backup/index.js.map +1 -0
  161. package/dist/infrastructure/config/index.d.ts +8 -0
  162. package/dist/infrastructure/config/index.d.ts.map +1 -0
  163. package/dist/infrastructure/config/index.js +7 -0
  164. package/dist/infrastructure/config/index.js.map +1 -0
  165. package/dist/infrastructure/config/loader.d.ts +555 -0
  166. package/dist/infrastructure/config/loader.d.ts.map +1 -0
  167. package/dist/infrastructure/config/loader.js +311 -0
  168. package/dist/infrastructure/config/loader.js.map +1 -0
  169. package/dist/infrastructure/database/checks.d.ts +19 -0
  170. package/dist/infrastructure/database/checks.d.ts.map +1 -0
  171. package/dist/infrastructure/database/checks.js +27 -0
  172. package/dist/infrastructure/database/checks.js.map +1 -0
  173. package/dist/infrastructure/database/compatibility.d.ts +36 -0
  174. package/dist/infrastructure/database/compatibility.d.ts.map +1 -0
  175. package/dist/infrastructure/database/compatibility.js +75 -0
  176. package/dist/infrastructure/database/compatibility.js.map +1 -0
  177. package/dist/infrastructure/database/connection.d.ts +36 -0
  178. package/dist/infrastructure/database/connection.d.ts.map +1 -0
  179. package/dist/infrastructure/database/connection.js +47 -0
  180. package/dist/infrastructure/database/connection.js.map +1 -0
  181. package/dist/infrastructure/database/id.d.ts +17 -0
  182. package/dist/infrastructure/database/id.d.ts.map +1 -0
  183. package/dist/infrastructure/database/id.js +20 -0
  184. package/dist/infrastructure/database/id.js.map +1 -0
  185. package/dist/infrastructure/database/index.d.ts +15 -0
  186. package/dist/infrastructure/database/index.d.ts.map +1 -0
  187. package/dist/infrastructure/database/index.js +12 -0
  188. package/dist/infrastructure/database/index.js.map +1 -0
  189. package/dist/infrastructure/database/migrate.d.ts +76 -0
  190. package/dist/infrastructure/database/migrate.d.ts.map +1 -0
  191. package/dist/infrastructure/database/migrate.js +1214 -0
  192. package/dist/infrastructure/database/migrate.js.map +1 -0
  193. package/dist/infrastructure/database/schema.d.ts +2352 -0
  194. package/dist/infrastructure/database/schema.d.ts.map +1 -0
  195. package/dist/infrastructure/database/schema.js +288 -0
  196. package/dist/infrastructure/database/schema.js.map +1 -0
  197. package/dist/infrastructure/jwt/index.d.ts +2 -0
  198. package/dist/infrastructure/jwt/index.d.ts.map +1 -0
  199. package/dist/infrastructure/jwt/index.js +2 -0
  200. package/dist/infrastructure/jwt/index.js.map +1 -0
  201. package/dist/infrastructure/jwt/jwt-secret-manager.d.ts +58 -0
  202. package/dist/infrastructure/jwt/jwt-secret-manager.d.ts.map +1 -0
  203. package/dist/infrastructure/jwt/jwt-secret-manager.js +222 -0
  204. package/dist/infrastructure/jwt/jwt-secret-manager.js.map +1 -0
  205. package/dist/infrastructure/keystore/crypto.d.ts +62 -0
  206. package/dist/infrastructure/keystore/crypto.d.ts.map +1 -0
  207. package/dist/infrastructure/keystore/crypto.js +89 -0
  208. package/dist/infrastructure/keystore/crypto.js.map +1 -0
  209. package/dist/infrastructure/keystore/index.d.ts +4 -0
  210. package/dist/infrastructure/keystore/index.d.ts.map +1 -0
  211. package/dist/infrastructure/keystore/index.js +5 -0
  212. package/dist/infrastructure/keystore/index.js.map +1 -0
  213. package/dist/infrastructure/keystore/keystore.d.ts +115 -0
  214. package/dist/infrastructure/keystore/keystore.d.ts.map +1 -0
  215. package/dist/infrastructure/keystore/keystore.js +327 -0
  216. package/dist/infrastructure/keystore/keystore.js.map +1 -0
  217. package/dist/infrastructure/keystore/memory.d.ts +45 -0
  218. package/dist/infrastructure/keystore/memory.d.ts.map +1 -0
  219. package/dist/infrastructure/keystore/memory.js +105 -0
  220. package/dist/infrastructure/keystore/memory.js.map +1 -0
  221. package/dist/infrastructure/oracle/coingecko-forex.d.ts +35 -0
  222. package/dist/infrastructure/oracle/coingecko-forex.d.ts.map +1 -0
  223. package/dist/infrastructure/oracle/coingecko-forex.js +69 -0
  224. package/dist/infrastructure/oracle/coingecko-forex.js.map +1 -0
  225. package/dist/infrastructure/oracle/coingecko-oracle.d.ts +73 -0
  226. package/dist/infrastructure/oracle/coingecko-oracle.d.ts.map +1 -0
  227. package/dist/infrastructure/oracle/coingecko-oracle.js +199 -0
  228. package/dist/infrastructure/oracle/coingecko-oracle.js.map +1 -0
  229. package/dist/infrastructure/oracle/coingecko-platform-ids.d.ts +32 -0
  230. package/dist/infrastructure/oracle/coingecko-platform-ids.d.ts.map +1 -0
  231. package/dist/infrastructure/oracle/coingecko-platform-ids.js +30 -0
  232. package/dist/infrastructure/oracle/coingecko-platform-ids.js.map +1 -0
  233. package/dist/infrastructure/oracle/forex-currencies.d.ts +36 -0
  234. package/dist/infrastructure/oracle/forex-currencies.d.ts.map +1 -0
  235. package/dist/infrastructure/oracle/forex-currencies.js +71 -0
  236. package/dist/infrastructure/oracle/forex-currencies.js.map +1 -0
  237. package/dist/infrastructure/oracle/forex-rate-service.d.ts +51 -0
  238. package/dist/infrastructure/oracle/forex-rate-service.d.ts.map +1 -0
  239. package/dist/infrastructure/oracle/forex-rate-service.js +149 -0
  240. package/dist/infrastructure/oracle/forex-rate-service.js.map +1 -0
  241. package/dist/infrastructure/oracle/index.d.ts +18 -0
  242. package/dist/infrastructure/oracle/index.d.ts.map +1 -0
  243. package/dist/infrastructure/oracle/index.js +19 -0
  244. package/dist/infrastructure/oracle/index.js.map +1 -0
  245. package/dist/infrastructure/oracle/oracle-chain.d.ts +101 -0
  246. package/dist/infrastructure/oracle/oracle-chain.d.ts.map +1 -0
  247. package/dist/infrastructure/oracle/oracle-chain.js +163 -0
  248. package/dist/infrastructure/oracle/oracle-chain.js.map +1 -0
  249. package/dist/infrastructure/oracle/oracle-errors.d.ts +42 -0
  250. package/dist/infrastructure/oracle/oracle-errors.d.ts.map +1 -0
  251. package/dist/infrastructure/oracle/oracle-errors.js +53 -0
  252. package/dist/infrastructure/oracle/oracle-errors.js.map +1 -0
  253. package/dist/infrastructure/oracle/price-age.d.ts +38 -0
  254. package/dist/infrastructure/oracle/price-age.d.ts.map +1 -0
  255. package/dist/infrastructure/oracle/price-age.js +44 -0
  256. package/dist/infrastructure/oracle/price-age.js.map +1 -0
  257. package/dist/infrastructure/oracle/price-cache.d.ts +99 -0
  258. package/dist/infrastructure/oracle/price-cache.d.ts.map +1 -0
  259. package/dist/infrastructure/oracle/price-cache.js +173 -0
  260. package/dist/infrastructure/oracle/price-cache.js.map +1 -0
  261. package/dist/infrastructure/oracle/pyth-feed-ids.d.ts +31 -0
  262. package/dist/infrastructure/oracle/pyth-feed-ids.d.ts.map +1 -0
  263. package/dist/infrastructure/oracle/pyth-feed-ids.js +44 -0
  264. package/dist/infrastructure/oracle/pyth-feed-ids.js.map +1 -0
  265. package/dist/infrastructure/oracle/pyth-oracle.d.ts +69 -0
  266. package/dist/infrastructure/oracle/pyth-oracle.d.ts.map +1 -0
  267. package/dist/infrastructure/oracle/pyth-oracle.js +149 -0
  268. package/dist/infrastructure/oracle/pyth-oracle.js.map +1 -0
  269. package/dist/infrastructure/settings/hot-reload.d.ts +71 -0
  270. package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -0
  271. package/dist/infrastructure/settings/hot-reload.js +315 -0
  272. package/dist/infrastructure/settings/hot-reload.js.map +1 -0
  273. package/dist/infrastructure/settings/index.d.ts +13 -0
  274. package/dist/infrastructure/settings/index.d.ts.map +1 -0
  275. package/dist/infrastructure/settings/index.js +10 -0
  276. package/dist/infrastructure/settings/index.js.map +1 -0
  277. package/dist/infrastructure/settings/setting-keys.d.ts +28 -0
  278. package/dist/infrastructure/settings/setting-keys.d.ts.map +1 -0
  279. package/dist/infrastructure/settings/setting-keys.js +105 -0
  280. package/dist/infrastructure/settings/setting-keys.js.map +1 -0
  281. package/dist/infrastructure/settings/settings-crypto.d.ts +39 -0
  282. package/dist/infrastructure/settings/settings-crypto.d.ts.map +1 -0
  283. package/dist/infrastructure/settings/settings-crypto.js +73 -0
  284. package/dist/infrastructure/settings/settings-crypto.js.map +1 -0
  285. package/dist/infrastructure/settings/settings-service.d.ts +82 -0
  286. package/dist/infrastructure/settings/settings-service.d.ts.map +1 -0
  287. package/dist/infrastructure/settings/settings-service.js +267 -0
  288. package/dist/infrastructure/settings/settings-service.js.map +1 -0
  289. package/dist/infrastructure/telegram/index.d.ts +6 -0
  290. package/dist/infrastructure/telegram/index.d.ts.map +1 -0
  291. package/dist/infrastructure/telegram/index.js +5 -0
  292. package/dist/infrastructure/telegram/index.js.map +1 -0
  293. package/dist/infrastructure/telegram/telegram-api.d.ts +35 -0
  294. package/dist/infrastructure/telegram/telegram-api.d.ts.map +1 -0
  295. package/dist/infrastructure/telegram/telegram-api.js +82 -0
  296. package/dist/infrastructure/telegram/telegram-api.js.map +1 -0
  297. package/dist/infrastructure/telegram/telegram-auth.d.ts +57 -0
  298. package/dist/infrastructure/telegram/telegram-auth.d.ts.map +1 -0
  299. package/dist/infrastructure/telegram/telegram-auth.js +88 -0
  300. package/dist/infrastructure/telegram/telegram-auth.js.map +1 -0
  301. package/dist/infrastructure/telegram/telegram-bot-service.d.ts +95 -0
  302. package/dist/infrastructure/telegram/telegram-bot-service.d.ts.map +1 -0
  303. package/dist/infrastructure/telegram/telegram-bot-service.js +564 -0
  304. package/dist/infrastructure/telegram/telegram-bot-service.js.map +1 -0
  305. package/dist/infrastructure/telegram/telegram-keyboard.d.ts +27 -0
  306. package/dist/infrastructure/telegram/telegram-keyboard.d.ts.map +1 -0
  307. package/dist/infrastructure/telegram/telegram-keyboard.js +52 -0
  308. package/dist/infrastructure/telegram/telegram-keyboard.js.map +1 -0
  309. package/dist/infrastructure/telegram/telegram-types.d.ts +43 -0
  310. package/dist/infrastructure/telegram/telegram-types.d.ts.map +1 -0
  311. package/dist/infrastructure/telegram/telegram-types.js +8 -0
  312. package/dist/infrastructure/telegram/telegram-types.js.map +1 -0
  313. package/dist/infrastructure/token-registry/builtin-tokens.d.ts +39 -0
  314. package/dist/infrastructure/token-registry/builtin-tokens.d.ts.map +1 -0
  315. package/dist/infrastructure/token-registry/builtin-tokens.js +135 -0
  316. package/dist/infrastructure/token-registry/builtin-tokens.js.map +1 -0
  317. package/dist/infrastructure/token-registry/index.d.ts +8 -0
  318. package/dist/infrastructure/token-registry/index.d.ts.map +1 -0
  319. package/dist/infrastructure/token-registry/index.js +8 -0
  320. package/dist/infrastructure/token-registry/index.js.map +1 -0
  321. package/dist/infrastructure/token-registry/token-registry-service.d.ts +49 -0
  322. package/dist/infrastructure/token-registry/token-registry-service.d.ts.map +1 -0
  323. package/dist/infrastructure/token-registry/token-registry-service.js +93 -0
  324. package/dist/infrastructure/token-registry/token-registry-service.js.map +1 -0
  325. package/dist/infrastructure/version/index.d.ts +5 -0
  326. package/dist/infrastructure/version/index.d.ts.map +1 -0
  327. package/dist/infrastructure/version/index.js +5 -0
  328. package/dist/infrastructure/version/index.js.map +1 -0
  329. package/dist/infrastructure/version/version-check-service.d.ts +35 -0
  330. package/dist/infrastructure/version/version-check-service.d.ts.map +1 -0
  331. package/dist/infrastructure/version/version-check-service.js +92 -0
  332. package/dist/infrastructure/version/version-check-service.js.map +1 -0
  333. package/dist/lifecycle/daemon.d.ts +103 -0
  334. package/dist/lifecycle/daemon.d.ts.map +1 -0
  335. package/dist/lifecycle/daemon.js +934 -0
  336. package/dist/lifecycle/daemon.js.map +1 -0
  337. package/dist/lifecycle/index.d.ts +9 -0
  338. package/dist/lifecycle/index.d.ts.map +1 -0
  339. package/dist/lifecycle/index.js +9 -0
  340. package/dist/lifecycle/index.js.map +1 -0
  341. package/dist/lifecycle/signal-handler.d.ts +18 -0
  342. package/dist/lifecycle/signal-handler.d.ts.map +1 -0
  343. package/dist/lifecycle/signal-handler.js +37 -0
  344. package/dist/lifecycle/signal-handler.js.map +1 -0
  345. package/dist/lifecycle/workers.d.ts +46 -0
  346. package/dist/lifecycle/workers.d.ts.map +1 -0
  347. package/dist/lifecycle/workers.js +101 -0
  348. package/dist/lifecycle/workers.js.map +1 -0
  349. package/dist/notifications/channels/discord.d.ts +10 -0
  350. package/dist/notifications/channels/discord.d.ts.map +1 -0
  351. package/dist/notifications/channels/discord.js +54 -0
  352. package/dist/notifications/channels/discord.js.map +1 -0
  353. package/dist/notifications/channels/ntfy.d.ts +13 -0
  354. package/dist/notifications/channels/ntfy.d.ts.map +1 -0
  355. package/dist/notifications/channels/ntfy.js +58 -0
  356. package/dist/notifications/channels/ntfy.js.map +1 -0
  357. package/dist/notifications/channels/slack.d.ts +10 -0
  358. package/dist/notifications/channels/slack.d.ts.map +1 -0
  359. package/dist/notifications/channels/slack.js +55 -0
  360. package/dist/notifications/channels/slack.js.map +1 -0
  361. package/dist/notifications/channels/telegram.d.ts +10 -0
  362. package/dist/notifications/channels/telegram.d.ts.map +1 -0
  363. package/dist/notifications/channels/telegram.js +40 -0
  364. package/dist/notifications/channels/telegram.js.map +1 -0
  365. package/dist/notifications/index.d.ts +9 -0
  366. package/dist/notifications/index.d.ts.map +1 -0
  367. package/dist/notifications/index.js +7 -0
  368. package/dist/notifications/index.js.map +1 -0
  369. package/dist/notifications/notification-service.d.ts +75 -0
  370. package/dist/notifications/notification-service.d.ts.map +1 -0
  371. package/dist/notifications/notification-service.js +213 -0
  372. package/dist/notifications/notification-service.js.map +1 -0
  373. package/dist/notifications/templates/message-templates.d.ts +12 -0
  374. package/dist/notifications/templates/message-templates.d.ts.map +1 -0
  375. package/dist/notifications/templates/message-templates.js +22 -0
  376. package/dist/notifications/templates/message-templates.js.map +1 -0
  377. package/dist/pipeline/database-policy-engine.d.ts +286 -0
  378. package/dist/pipeline/database-policy-engine.d.ts.map +1 -0
  379. package/dist/pipeline/database-policy-engine.js +992 -0
  380. package/dist/pipeline/database-policy-engine.js.map +1 -0
  381. package/dist/pipeline/default-policy-engine.d.ts +26 -0
  382. package/dist/pipeline/default-policy-engine.d.ts.map +1 -0
  383. package/dist/pipeline/default-policy-engine.js +25 -0
  384. package/dist/pipeline/default-policy-engine.js.map +1 -0
  385. package/dist/pipeline/index.d.ts +9 -0
  386. package/dist/pipeline/index.d.ts.map +1 -0
  387. package/dist/pipeline/index.js +9 -0
  388. package/dist/pipeline/index.js.map +1 -0
  389. package/dist/pipeline/network-resolver.d.ts +22 -0
  390. package/dist/pipeline/network-resolver.d.ts.map +1 -0
  391. package/dist/pipeline/network-resolver.js +32 -0
  392. package/dist/pipeline/network-resolver.js.map +1 -0
  393. package/dist/pipeline/pipeline.d.ts +72 -0
  394. package/dist/pipeline/pipeline.d.ts.map +1 -0
  395. package/dist/pipeline/pipeline.js +87 -0
  396. package/dist/pipeline/pipeline.js.map +1 -0
  397. package/dist/pipeline/resolve-effective-amount-usd.d.ts +41 -0
  398. package/dist/pipeline/resolve-effective-amount-usd.d.ts.map +1 -0
  399. package/dist/pipeline/resolve-effective-amount-usd.js +208 -0
  400. package/dist/pipeline/resolve-effective-amount-usd.js.map +1 -0
  401. package/dist/pipeline/sign-only.d.ts +99 -0
  402. package/dist/pipeline/sign-only.d.ts.map +1 -0
  403. package/dist/pipeline/sign-only.js +267 -0
  404. package/dist/pipeline/sign-only.js.map +1 -0
  405. package/dist/pipeline/sleep.d.ts +6 -0
  406. package/dist/pipeline/sleep.d.ts.map +1 -0
  407. package/dist/pipeline/sleep.js +8 -0
  408. package/dist/pipeline/sleep.js.map +1 -0
  409. package/dist/pipeline/stages.d.ts +82 -0
  410. package/dist/pipeline/stages.d.ts.map +1 -0
  411. package/dist/pipeline/stages.js +784 -0
  412. package/dist/pipeline/stages.js.map +1 -0
  413. package/dist/services/autostop-rules.d.ts +79 -0
  414. package/dist/services/autostop-rules.d.ts.map +1 -0
  415. package/dist/services/autostop-rules.js +174 -0
  416. package/dist/services/autostop-rules.js.map +1 -0
  417. package/dist/services/autostop-service.d.ts +82 -0
  418. package/dist/services/autostop-service.d.ts.map +1 -0
  419. package/dist/services/autostop-service.js +223 -0
  420. package/dist/services/autostop-service.js.map +1 -0
  421. package/dist/services/kill-switch-service.d.ts +118 -0
  422. package/dist/services/kill-switch-service.d.ts.map +1 -0
  423. package/dist/services/kill-switch-service.js +291 -0
  424. package/dist/services/kill-switch-service.js.map +1 -0
  425. package/dist/services/monitoring/balance-monitor-service.d.ts +65 -0
  426. package/dist/services/monitoring/balance-monitor-service.d.ts.map +1 -0
  427. package/dist/services/monitoring/balance-monitor-service.js +207 -0
  428. package/dist/services/monitoring/balance-monitor-service.js.map +1 -0
  429. package/dist/services/wc-session-service.d.ts +123 -0
  430. package/dist/services/wc-session-service.d.ts.map +1 -0
  431. package/dist/services/wc-session-service.js +363 -0
  432. package/dist/services/wc-session-service.js.map +1 -0
  433. package/dist/services/wc-signing-bridge.d.ts +60 -0
  434. package/dist/services/wc-signing-bridge.d.ts.map +1 -0
  435. package/dist/services/wc-signing-bridge.js +334 -0
  436. package/dist/services/wc-signing-bridge.js.map +1 -0
  437. package/dist/services/wc-storage.d.ts +32 -0
  438. package/dist/services/wc-storage.d.ts.map +1 -0
  439. package/dist/services/wc-storage.js +64 -0
  440. package/dist/services/wc-storage.js.map +1 -0
  441. package/dist/services/x402/payment-signer.d.ts +88 -0
  442. package/dist/services/x402/payment-signer.d.ts.map +1 -0
  443. package/dist/services/x402/payment-signer.js +311 -0
  444. package/dist/services/x402/payment-signer.js.map +1 -0
  445. package/dist/services/x402/ssrf-guard.d.ts +27 -0
  446. package/dist/services/x402/ssrf-guard.d.ts.map +1 -0
  447. package/dist/services/x402/ssrf-guard.js +236 -0
  448. package/dist/services/x402/ssrf-guard.js.map +1 -0
  449. package/dist/services/x402/x402-domain-policy.d.ts +50 -0
  450. package/dist/services/x402/x402-domain-policy.d.ts.map +1 -0
  451. package/dist/services/x402/x402-domain-policy.js +78 -0
  452. package/dist/services/x402/x402-domain-policy.js.map +1 -0
  453. package/dist/services/x402/x402-handler.d.ts +71 -0
  454. package/dist/services/x402/x402-handler.d.ts.map +1 -0
  455. package/dist/services/x402/x402-handler.js +195 -0
  456. package/dist/services/x402/x402-handler.js.map +1 -0
  457. package/dist/services/x402/x402-usd-resolver.d.ts +26 -0
  458. package/dist/services/x402/x402-usd-resolver.d.ts.map +1 -0
  459. package/dist/services/x402/x402-usd-resolver.js +79 -0
  460. package/dist/services/x402/x402-usd-resolver.js.map +1 -0
  461. package/dist/workflow/approval-workflow.d.ts +103 -0
  462. package/dist/workflow/approval-workflow.d.ts.map +1 -0
  463. package/dist/workflow/approval-workflow.js +202 -0
  464. package/dist/workflow/approval-workflow.js.map +1 -0
  465. package/dist/workflow/delay-queue.d.ts +78 -0
  466. package/dist/workflow/delay-queue.d.ts.map +1 -0
  467. package/dist/workflow/delay-queue.js +174 -0
  468. package/dist/workflow/delay-queue.js.map +1 -0
  469. package/dist/workflow/index.d.ts +11 -0
  470. package/dist/workflow/index.d.ts.map +1 -0
  471. package/dist/workflow/index.js +9 -0
  472. package/dist/workflow/index.js.map +1 -0
  473. package/dist/workflow/owner-state.d.ts +97 -0
  474. package/dist/workflow/owner-state.d.ts.map +1 -0
  475. package/dist/workflow/owner-state.js +168 -0
  476. package/dist/workflow/owner-state.js.map +1 -0
  477. package/package.json +71 -0
  478. package/public/admin/assets/index-BPoUSH8W.css +1 -0
  479. package/public/admin/assets/index-CDi1qoXB.js +1 -0
  480. package/public/admin/index.html +13 -0
@@ -0,0 +1,311 @@
1
+ /**
2
+ * Payment Signer -- x402 chain-specific payment signature generation.
3
+ *
4
+ * Provides signPayment() which delegates to:
5
+ * - signEip3009() for EVM chains (EIP-3009 transferWithAuthorization via EIP-712 signTypedData)
6
+ * - signSolanaTransferChecked() for Solana chains (SPL TransferChecked partial signing)
7
+ *
8
+ * Key management follows the decrypt -> sign -> finally release pattern
9
+ * from sign-only.ts Step 9 and stages.ts Stage 5c.
10
+ *
11
+ * Does NOT go through IChainAdapter -- EIP-3009 is typed data signing (not tx),
12
+ * and Solana partial signing uses a different feePayer (facilitator, not wallet).
13
+ *
14
+ * @see packages/daemon/src/pipeline/sign-only.ts (Step 9)
15
+ * @see docs/32-pipeline-design.md
16
+ */
17
+ import { randomBytes } from 'node:crypto';
18
+ import { privateKeyToAccount } from 'viem/accounts';
19
+ import { address, createNoopSigner, createTransactionMessage, setTransactionMessageFeePayer, appendTransactionMessageInstruction, setTransactionMessageLifetimeUsingBlockhash, compileTransaction, getTransactionEncoder, signBytes, createKeyPairFromBytes, createKeyPairFromPrivateKeyBytes, getAddressFromPublicKey, pipe, } from '@solana/kit';
20
+ import { findAssociatedTokenPda, getTransferCheckedInstruction, TOKEN_PROGRAM_ADDRESS, } from '@solana-program/token';
21
+ import { parseCaip2, WAIaaSError } from '@waiaas/core';
22
+ // ---------------------------------------------------------------------------
23
+ // USDC Domain Table (EIP-3009 EIP-712 domain separators)
24
+ // ---------------------------------------------------------------------------
25
+ /**
26
+ * USDC v2 contract domain separators by CAIP-2 network identifier.
27
+ *
28
+ * Each EVM chain has a unique USDC contract with its own EIP-712 domain separator.
29
+ * These are the Circle native USDC v2 contracts that support EIP-3009.
30
+ *
31
+ * Source: USDC v2 contracts + EIP-3009 standard + x402 reference implementation.
32
+ */
33
+ export const USDC_DOMAINS = {
34
+ // Base Mainnet
35
+ 'eip155:8453': {
36
+ name: 'USD Coin',
37
+ version: '2',
38
+ chainId: 8453,
39
+ verifyingContract: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
40
+ },
41
+ // Base Sepolia (testnet) — on-chain eip712Domain() returns 'USDC' (not 'USD Coin')
42
+ 'eip155:84532': {
43
+ name: 'USDC',
44
+ version: '2',
45
+ chainId: 84532,
46
+ verifyingContract: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
47
+ },
48
+ // Ethereum Mainnet
49
+ 'eip155:1': {
50
+ name: 'USD Coin',
51
+ version: '2',
52
+ chainId: 1,
53
+ verifyingContract: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
54
+ },
55
+ // Ethereum Sepolia
56
+ 'eip155:11155111': {
57
+ name: 'USD Coin',
58
+ version: '2',
59
+ chainId: 11155111,
60
+ verifyingContract: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
61
+ },
62
+ // Polygon Mainnet
63
+ 'eip155:137': {
64
+ name: 'USD Coin',
65
+ version: '2',
66
+ chainId: 137,
67
+ verifyingContract: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
68
+ },
69
+ // Arbitrum One
70
+ 'eip155:42161': {
71
+ name: 'USD Coin',
72
+ version: '2',
73
+ chainId: 42161,
74
+ verifyingContract: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
75
+ },
76
+ // Optimism
77
+ 'eip155:10': {
78
+ name: 'USD Coin',
79
+ version: '2',
80
+ chainId: 10,
81
+ verifyingContract: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',
82
+ },
83
+ };
84
+ // ---------------------------------------------------------------------------
85
+ // EIP-712 TransferWithAuthorization types (EIP-3009)
86
+ // ---------------------------------------------------------------------------
87
+ const TRANSFER_WITH_AUTHORIZATION_TYPES = {
88
+ TransferWithAuthorization: [
89
+ { name: 'from', type: 'address' },
90
+ { name: 'to', type: 'address' },
91
+ { name: 'value', type: 'uint256' },
92
+ { name: 'validAfter', type: 'uint256' },
93
+ { name: 'validBefore', type: 'uint256' },
94
+ { name: 'nonce', type: 'bytes32' },
95
+ ],
96
+ };
97
+ // ---------------------------------------------------------------------------
98
+ // Solana transaction encoder (stateless, safe to share)
99
+ // ---------------------------------------------------------------------------
100
+ const txEncoder = getTransactionEncoder();
101
+ // ---------------------------------------------------------------------------
102
+ // signPayment -- entry point with key management
103
+ // ---------------------------------------------------------------------------
104
+ /**
105
+ * Sign a payment based on chain-specific strategy.
106
+ *
107
+ * Key management pattern (identical to sign-only.ts Step 9):
108
+ * 1. Decrypt private key from keystore
109
+ * 2. Sign using chain-specific strategy
110
+ * 3. Finally block: release key (sodium_memzero)
111
+ *
112
+ * @param requirements - x402 PaymentRequirements from 402 response
113
+ * @param keyStore - Keystore for key decrypt/release
114
+ * @param walletId - Wallet ID for key lookup
115
+ * @param walletAddress - Wallet public address
116
+ * @param masterPassword - Master password for key decryption
117
+ * @param rpc - Solana RPC client (required for Solana chains)
118
+ * @returns PaymentPayload compatible with @x402/core PaymentPayloadV2Schema
119
+ */
120
+ export async function signPayment(requirements, keyStore, walletId, walletAddress, masterPassword, rpc) {
121
+ let privateKey = null;
122
+ try {
123
+ privateKey = await keyStore.decryptPrivateKey(walletId, masterPassword);
124
+ const { namespace } = parseCaip2(requirements.network);
125
+ if (namespace === 'eip155') {
126
+ return await signEip3009(requirements, privateKey, walletAddress);
127
+ }
128
+ else if (namespace === 'solana') {
129
+ return await signSolanaTransferChecked(requirements, privateKey, walletAddress, rpc);
130
+ }
131
+ else {
132
+ throw new WAIaaSError('X402_UNSUPPORTED_SCHEME', {
133
+ message: `Unsupported chain namespace: ${namespace}`,
134
+ });
135
+ }
136
+ }
137
+ finally {
138
+ if (privateKey) {
139
+ keyStore.releaseKey(privateKey);
140
+ }
141
+ }
142
+ }
143
+ // ---------------------------------------------------------------------------
144
+ // signEip3009 -- EVM EIP-3009 transferWithAuthorization
145
+ // ---------------------------------------------------------------------------
146
+ /**
147
+ * Sign EVM EIP-3009 transferWithAuthorization via EIP-712 signTypedData.
148
+ *
149
+ * Uses viem's privateKeyToAccount + account.signTypedData for the EIP-712
150
+ * structured data signature. The signature authorizes a USDC transfer
151
+ * without requiring an on-chain transaction from the payer.
152
+ *
153
+ * @param requirements - Payment requirements (network, asset, amount, payTo)
154
+ * @param privateKey - Raw private key bytes (32 bytes for secp256k1)
155
+ * @param walletAddress - EVM wallet address (0x-prefixed EIP-55)
156
+ * @returns PaymentPayload with signature and authorization object
157
+ */
158
+ export async function signEip3009(requirements, privateKey, walletAddress) {
159
+ const { reference: chainIdStr } = parseCaip2(requirements.network);
160
+ const chainId = parseInt(chainIdStr, 10);
161
+ // Resolve EIP-712 domain: prefer server-provided extra.name/version (x402 v2 spec),
162
+ // fall back to USDC_DOMAINS table for backward compatibility.
163
+ const extra = requirements.extra;
164
+ const domainName = extra?.name ?? USDC_DOMAINS[requirements.network]?.name;
165
+ const domainVersion = extra?.version ?? USDC_DOMAINS[requirements.network]?.version;
166
+ if (!domainName || !domainVersion) {
167
+ throw new WAIaaSError('X402_UNSUPPORTED_SCHEME', {
168
+ message: `No EIP-712 domain (name/version) for network: ${requirements.network}`,
169
+ });
170
+ }
171
+ // Generate 32-byte random nonce (EIP-3009 requirement)
172
+ const nonce = `0x${randomBytes(32).toString('hex')}`;
173
+ // validBefore = now + 5 minutes (300 seconds) -- minimizes attack window
174
+ // See Pitfall 3 in research: too long validBefore creates security gap
175
+ const validBefore = BigInt(Math.floor(Date.now() / 1000) + 300);
176
+ // Create viem account from private key
177
+ const privateKeyHex = `0x${Buffer.from(privateKey).toString('hex')}`;
178
+ const account = privateKeyToAccount(privateKeyHex);
179
+ // Sign EIP-712 TransferWithAuthorization
180
+ // verifyingContract = asset address (USDC contract) from requirements
181
+ const signature = await account.signTypedData({
182
+ domain: {
183
+ name: domainName,
184
+ version: domainVersion,
185
+ chainId: BigInt(chainId),
186
+ verifyingContract: requirements.asset,
187
+ },
188
+ types: TRANSFER_WITH_AUTHORIZATION_TYPES,
189
+ primaryType: 'TransferWithAuthorization',
190
+ message: {
191
+ from: walletAddress,
192
+ to: requirements.payTo,
193
+ value: BigInt(requirements.amount),
194
+ validAfter: 0n,
195
+ validBefore,
196
+ nonce,
197
+ },
198
+ });
199
+ // Build PaymentPayload (compatible with PaymentPayloadV2Schema)
200
+ return {
201
+ x402Version: 2,
202
+ resource: { url: '' }, // handler fills this in
203
+ accepted: requirements,
204
+ payload: {
205
+ signature,
206
+ authorization: {
207
+ from: walletAddress,
208
+ to: requirements.payTo,
209
+ value: requirements.amount,
210
+ validAfter: '0',
211
+ validBefore: validBefore.toString(),
212
+ nonce,
213
+ },
214
+ },
215
+ };
216
+ }
217
+ // ---------------------------------------------------------------------------
218
+ // signSolanaTransferChecked -- Solana SPL TransferChecked partial signing
219
+ // ---------------------------------------------------------------------------
220
+ /**
221
+ * Sign Solana SPL TransferChecked as partial signature.
222
+ *
223
+ * The feePayer is the facilitator (from requirements.extra.feePayer), set as
224
+ * noopSigner so only a signature slot is created. The wallet signs the
225
+ * transaction message with its private key.
226
+ *
227
+ * The resulting base64-encoded transaction contains:
228
+ * - feePayer = facilitator address (noopSigner, unsigned)
229
+ * - authority = wallet (signed)
230
+ * - TransferChecked instruction for SPL token transfer
231
+ *
232
+ * @param requirements - Payment requirements with extra.feePayer and extra.decimals
233
+ * @param privateKey - Raw private key bytes (32 or 64 bytes)
234
+ * @param walletAddress - Solana wallet address (base58)
235
+ * @param rpc - Solana RPC client with getLatestBlockhash method
236
+ * @returns PaymentPayload with base64-encoded partial-signed transaction
237
+ */
238
+ export async function signSolanaTransferChecked(requirements, privateKey, _walletAddress, rpc) {
239
+ // Extract facilitator feePayer from requirements.extra
240
+ const feePayerStr = requirements.extra?.feePayer;
241
+ if (!feePayerStr) {
242
+ throw new WAIaaSError('X402_UNSUPPORTED_SCHEME', {
243
+ message: 'Missing feePayer in PaymentRequirements.extra',
244
+ });
245
+ }
246
+ const feePayerAddress = address(feePayerStr);
247
+ // Create key pair from raw bytes (64-byte or 32-byte detection)
248
+ const keyPair = privateKey.length === 64
249
+ ? await createKeyPairFromBytes(privateKey)
250
+ : await createKeyPairFromPrivateKeyBytes(privateKey.slice(0, 32));
251
+ const walletAddr = await getAddressFromPublicKey(keyPair.publicKey);
252
+ // Get latest blockhash from RPC
253
+ const solanaRpc = rpc;
254
+ const { value: blockhashInfo } = await solanaRpc.getLatestBlockhash().send();
255
+ // Derive token accounts (ATAs)
256
+ const mint = address(requirements.asset);
257
+ const payTo = address(requirements.payTo);
258
+ const decimals = requirements.extra?.decimals ?? 6;
259
+ const [sourceAta] = await findAssociatedTokenPda({
260
+ owner: walletAddr,
261
+ tokenProgram: address(TOKEN_PROGRAM_ADDRESS),
262
+ mint,
263
+ });
264
+ const [destAta] = await findAssociatedTokenPda({
265
+ owner: payTo,
266
+ tokenProgram: address(TOKEN_PROGRAM_ADDRESS),
267
+ mint,
268
+ });
269
+ // Build TransferChecked instruction
270
+ // Use noopSigner for feePayer (facilitator signs later)
271
+ const walletSigner = createNoopSigner(walletAddr);
272
+ const transferIx = getTransferCheckedInstruction({
273
+ source: sourceAta,
274
+ mint,
275
+ destination: destAta,
276
+ authority: walletSigner,
277
+ amount: BigInt(requirements.amount),
278
+ decimals,
279
+ }, { programAddress: address(TOKEN_PROGRAM_ADDRESS) });
280
+ // Build transaction message using pipe pattern
281
+ const txMessage = pipe(createTransactionMessage({ version: 0 }), (msg) => setTransactionMessageFeePayer(feePayerAddress, msg), (msg) => setTransactionMessageLifetimeUsingBlockhash(
282
+ // RPC blockhash is untyped (from mock/dynamic source), cast to satisfy branded type
283
+ blockhashInfo, // eslint-disable-line @typescript-eslint/no-explicit-any
284
+ msg),
285
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
286
+ (msg) => appendTransactionMessageInstruction(transferIx, msg));
287
+ // Compile transaction and sign with wallet private key (partial signing)
288
+ const compiled = compileTransaction(txMessage);
289
+ const walletSignature = await signBytes(keyPair.privateKey, compiled.messageBytes);
290
+ // Place wallet signature in the correct slot
291
+ const partiallySignedTx = {
292
+ ...compiled,
293
+ signatures: {
294
+ ...compiled.signatures,
295
+ [walletAddr]: walletSignature,
296
+ },
297
+ };
298
+ // Encode to base64
299
+ const serialized = new Uint8Array(txEncoder.encode(partiallySignedTx));
300
+ const base64Tx = Buffer.from(serialized).toString('base64');
301
+ // Build PaymentPayload
302
+ return {
303
+ x402Version: 2,
304
+ resource: { url: '' }, // handler fills this in
305
+ accepted: requirements,
306
+ payload: {
307
+ transaction: base64Tx,
308
+ },
309
+ };
310
+ }
311
+ //# sourceMappingURL=payment-signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-signer.js","sourceRoot":"","sources":["../../../src/services/x402/payment-signer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,wBAAwB,EACxB,6BAA6B,EAC7B,mCAAmC,EACnC,2CAA2C,EAC3C,kBAAkB,EAClB,qBAAqB,EACrB,SAAS,EACT,sBAAsB,EACtB,gCAAgC,EAChC,uBAAuB,EACvB,IAAI,GACL,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAqBvD,8EAA8E;AAC9E,yDAAyD;AACzD,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAiC;IACxD,eAAe;IACf,aAAa,EAAE;QACb,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,IAAI;QACb,iBAAiB,EAAE,4CAA4C;KAChE;IACD,mFAAmF;IACnF,cAAc,EAAE;QACd,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,KAAK;QACd,iBAAiB,EAAE,4CAA4C;KAChE;IACD,mBAAmB;IACnB,UAAU,EAAE;QACV,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,CAAC;QACV,iBAAiB,EAAE,4CAA4C;KAChE;IACD,mBAAmB;IACnB,iBAAiB,EAAE;QACjB,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE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,EAAE,EAAE,CAAC,mCAAmC,CAAC,UAAiB,EAAE,GAAG,CAAC,CACrE,CAAC;IAEF,yEAAyE;IACzE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAEnF,6CAA6C;IAC7C,MAAM,iBAAiB,GAAG;QACxB,GAAG,QAAQ;QACX,UAAU,EAAE;YACV,GAAG,QAAQ,CAAC,UAAU;YACtB,CAAC,UAAU,CAAC,EAAE,eAAe;SAC9B;KACF,CAAC;IAEF,mBAAmB;IACnB,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE5D,uBAAuB;IACvB,OAAO;QACL,WAAW,EAAE,CAAC;QACd,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,wBAAwB;QAC/C,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE;YACP,WAAW,EAAE,QAAQ;SACtB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * SSRF Guard for x402 HTTP proxy.
3
+ *
4
+ * Defense layers:
5
+ * 1. URL normalization (trailing dot, lowercase, userinfo rejection, port 443 only)
6
+ * 2. Protocol enforcement (HTTPS only)
7
+ * 3. DNS pre-resolution + private IP blocking (RFC 5735/6890)
8
+ * 4. IPv4-mapped IPv6 bypass vector blocking
9
+ * 5. Redirect re-validation (max 3 hops)
10
+ *
11
+ * @module ssrf-guard
12
+ */
13
+ /**
14
+ * Validate URL safety against SSRF attacks.
15
+ * Performs DNS resolution and validates all resolved IPs are public.
16
+ *
17
+ * @throws WAIaaSError('X402_SSRF_BLOCKED') if URL targets private/reserved IP
18
+ */
19
+ export declare function validateUrlSafety(urlString: string): Promise<URL>;
20
+ /**
21
+ * Fetch with manual redirect handling and SSRF re-validation per hop.
22
+ * Max 3 redirects. After redirect, method becomes GET and body is dropped.
23
+ *
24
+ * @throws WAIaaSError('X402_SSRF_BLOCKED') on private IP redirect or too many redirects
25
+ */
26
+ export declare function safeFetchWithRedirects(url: URL, method: string, headers?: Record<string, string>, body?: string, timeout?: number): Promise<Response>;
27
+ //# sourceMappingURL=ssrf-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrf-guard.d.ts","sourceRoot":"","sources":["../../../src/services/x402/ssrf-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAiBH;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAuCvE;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,GAAE,MAA2B,GACnC,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
@@ -0,0 +1,236 @@
1
+ /**
2
+ * SSRF Guard for x402 HTTP proxy.
3
+ *
4
+ * Defense layers:
5
+ * 1. URL normalization (trailing dot, lowercase, userinfo rejection, port 443 only)
6
+ * 2. Protocol enforcement (HTTPS only)
7
+ * 3. DNS pre-resolution + private IP blocking (RFC 5735/6890)
8
+ * 4. IPv4-mapped IPv6 bypass vector blocking
9
+ * 5. Redirect re-validation (max 3 hops)
10
+ *
11
+ * @module ssrf-guard
12
+ */
13
+ import { lookup } from 'node:dns/promises';
14
+ import { isIP } from 'node:net';
15
+ import { WAIaaSError } from '@waiaas/core';
16
+ // ---------------------------------------------------------------------------
17
+ // Constants
18
+ // ---------------------------------------------------------------------------
19
+ const MAX_REDIRECTS = 3;
20
+ const DEFAULT_TIMEOUT_MS = 30_000;
21
+ // ---------------------------------------------------------------------------
22
+ // Public API
23
+ // ---------------------------------------------------------------------------
24
+ /**
25
+ * Validate URL safety against SSRF attacks.
26
+ * Performs DNS resolution and validates all resolved IPs are public.
27
+ *
28
+ * @throws WAIaaSError('X402_SSRF_BLOCKED') if URL targets private/reserved IP
29
+ */
30
+ export async function validateUrlSafety(urlString) {
31
+ const url = normalizeUrl(urlString);
32
+ // Protocol enforcement: HTTPS only
33
+ if (url.protocol !== 'https:') {
34
+ throw new WAIaaSError('X402_SSRF_BLOCKED', {
35
+ message: `Only HTTPS URLs are allowed, got ${url.protocol}`,
36
+ });
37
+ }
38
+ // Reject userinfo
39
+ if (url.username || url.password) {
40
+ throw new WAIaaSError('X402_SSRF_BLOCKED', {
41
+ message: 'URLs with userinfo (@) are not allowed',
42
+ });
43
+ }
44
+ // Port validation: only 443 (or default empty)
45
+ if (url.port && url.port !== '443') {
46
+ throw new WAIaaSError('X402_SSRF_BLOCKED', {
47
+ message: `Non-standard port ${url.port} is not allowed`,
48
+ });
49
+ }
50
+ const hostname = url.hostname;
51
+ // Direct IP in hostname
52
+ if (isIP(hostname)) {
53
+ assertPublicIP(hostname);
54
+ return url;
55
+ }
56
+ // DNS pre-resolution: resolve all A + AAAA records
57
+ const addresses = await lookup(hostname, { all: true });
58
+ for (const { address } of addresses) {
59
+ assertPublicIP(address);
60
+ }
61
+ return url;
62
+ }
63
+ /**
64
+ * Fetch with manual redirect handling and SSRF re-validation per hop.
65
+ * Max 3 redirects. After redirect, method becomes GET and body is dropped.
66
+ *
67
+ * @throws WAIaaSError('X402_SSRF_BLOCKED') on private IP redirect or too many redirects
68
+ */
69
+ export async function safeFetchWithRedirects(url, method, headers, body, timeout = DEFAULT_TIMEOUT_MS) {
70
+ let currentUrl = url;
71
+ for (let i = 0; i <= MAX_REDIRECTS; i++) {
72
+ const controller = new AbortController();
73
+ const timer = setTimeout(() => controller.abort(), timeout);
74
+ try {
75
+ const response = await fetch(currentUrl.toString(), {
76
+ method: i === 0 ? method : 'GET',
77
+ headers: i === 0 ? headers : undefined,
78
+ body: i === 0 && method !== 'GET' ? body : undefined,
79
+ signal: controller.signal,
80
+ redirect: 'manual',
81
+ });
82
+ // Non-redirect response: return as-is
83
+ if (response.status < 300 || response.status >= 400) {
84
+ return response;
85
+ }
86
+ // Redirect: extract and validate Location
87
+ const location = response.headers.get('Location');
88
+ if (!location) {
89
+ return response;
90
+ }
91
+ // SSRF re-validation on redirect target
92
+ currentUrl = await validateUrlSafety(new URL(location, currentUrl).toString());
93
+ }
94
+ finally {
95
+ clearTimeout(timer);
96
+ }
97
+ }
98
+ throw new WAIaaSError('X402_SSRF_BLOCKED', {
99
+ message: `Too many redirects (max ${MAX_REDIRECTS})`,
100
+ });
101
+ }
102
+ // ---------------------------------------------------------------------------
103
+ // Internal: URL normalization
104
+ // ---------------------------------------------------------------------------
105
+ function normalizeUrl(urlString) {
106
+ const url = new URL(urlString);
107
+ // Remove trailing dot (FQDN normalization)
108
+ if (url.hostname.endsWith('.')) {
109
+ url.hostname = url.hostname.slice(0, -1);
110
+ }
111
+ return url;
112
+ }
113
+ // ---------------------------------------------------------------------------
114
+ // Internal: IP validation
115
+ // ---------------------------------------------------------------------------
116
+ /**
117
+ * Assert that an IP address is public (not private/reserved).
118
+ * Handles IPv4-mapped IPv6 normalization before checking.
119
+ *
120
+ * @throws WAIaaSError('X402_SSRF_BLOCKED') if IP is private/reserved
121
+ */
122
+ function assertPublicIP(ip) {
123
+ const normalized = normalizeIPv6Mapped(ip);
124
+ if (isPrivateIP(normalized)) {
125
+ throw new WAIaaSError('X402_SSRF_BLOCKED', {
126
+ message: `Resolved IP ${ip} is private/reserved`,
127
+ });
128
+ }
129
+ }
130
+ /**
131
+ * Normalize IPv4-mapped IPv6 addresses to their IPv4 equivalents.
132
+ * - ::ffff:A.B.C.D -> A.B.C.D (dotted format)
133
+ * - ::ffff:HHHH:HHHH -> A.B.C.D (hex-encoded format)
134
+ */
135
+ function normalizeIPv6Mapped(ip) {
136
+ const lower = ip.toLowerCase();
137
+ // ::ffff:A.B.C.D format (dotted decimal)
138
+ if (lower.startsWith('::ffff:') && lower.includes('.')) {
139
+ return lower.slice(7);
140
+ }
141
+ // ::ffff:HHHH:HHHH format (hex-encoded IPv4)
142
+ const match = lower.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
143
+ if (match) {
144
+ const hi = parseInt(match[1], 16);
145
+ const lo = parseInt(match[2], 16);
146
+ return `${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`;
147
+ }
148
+ return ip;
149
+ }
150
+ /**
151
+ * Check if an IP (already normalized from IPv4-mapped IPv6) is private/reserved.
152
+ */
153
+ function isPrivateIP(ip) {
154
+ // Try IPv4 first, then IPv6
155
+ if (ip.includes('.')) {
156
+ return isPrivateIPv4(ip);
157
+ }
158
+ return isPrivateIPv6(ip);
159
+ }
160
+ /**
161
+ * RFC 5735/6890 private/reserved IPv4 ranges.
162
+ */
163
+ function isPrivateIPv4(ip) {
164
+ const parts = ip.split('.');
165
+ if (parts.length !== 4)
166
+ return false;
167
+ const a = Number(parts[0]);
168
+ const b = Number(parts[1]);
169
+ const c = Number(parts[2]);
170
+ // 0.0.0.0/8 - This network
171
+ if (a === 0)
172
+ return true;
173
+ // 10.0.0.0/8 - Private
174
+ if (a === 10)
175
+ return true;
176
+ // 100.64.0.0/10 - Shared address space (CGNAT)
177
+ if (a === 100 && b >= 64 && b <= 127)
178
+ return true;
179
+ // 127.0.0.0/8 - Loopback
180
+ if (a === 127)
181
+ return true;
182
+ // 169.254.0.0/16 - Link-local
183
+ if (a === 169 && b === 254)
184
+ return true;
185
+ // 172.16.0.0/12 - Private
186
+ if (a === 172 && b >= 16 && b <= 31)
187
+ return true;
188
+ // 192.0.0.0/24 - IETF Protocol Assignments
189
+ if (a === 192 && b === 0 && c === 0)
190
+ return true;
191
+ // 192.0.2.0/24 - Documentation (TEST-NET-1)
192
+ if (a === 192 && b === 0 && c === 2)
193
+ return true;
194
+ // 192.168.0.0/16 - Private
195
+ if (a === 192 && b === 168)
196
+ return true;
197
+ // 198.18.0.0/15 - Benchmarking
198
+ if (a === 198 && (b === 18 || b === 19))
199
+ return true;
200
+ // 198.51.100.0/24 - Documentation (TEST-NET-2)
201
+ if (a === 198 && b === 51 && c === 100)
202
+ return true;
203
+ // 203.0.113.0/24 - Documentation (TEST-NET-3)
204
+ if (a === 203 && b === 0 && c === 113)
205
+ return true;
206
+ // 224.0.0.0/4 - Multicast
207
+ if (a >= 224 && a <= 239)
208
+ return true;
209
+ // 240.0.0.0/4 - Reserved + 255.255.255.255 broadcast
210
+ if (a >= 240)
211
+ return true;
212
+ return false;
213
+ }
214
+ /**
215
+ * Private/reserved IPv6 ranges.
216
+ */
217
+ function isPrivateIPv6(ip) {
218
+ const lower = ip.toLowerCase();
219
+ // ::1 - Loopback
220
+ if (lower === '::1')
221
+ return true;
222
+ // :: - Unspecified
223
+ if (lower === '::')
224
+ return true;
225
+ // fe80::/10 - Link-local
226
+ if (lower.startsWith('fe80:') || lower === 'fe80')
227
+ return true;
228
+ // fc00::/7 - Unique local (fc00::/8 + fd00::/8)
229
+ if (lower.startsWith('fc') || lower.startsWith('fd'))
230
+ return true;
231
+ // ff00::/8 - Multicast
232
+ if (lower.startsWith('ff'))
233
+ return true;
234
+ return false;
235
+ }
236
+ //# sourceMappingURL=ssrf-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrf-guard.js","sourceRoot":"","sources":["../../../src/services/x402/ssrf-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,8EAA8E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;IAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IACtC,qDAAqD;IACrD,IAAI,CAAC,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IAE1B,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,EAAU;IAC/B,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAE/B,iBAAiB;IACjB,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACjC,mBAAmB;IACnB,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,yBAAyB;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAC/D,gDAAgD;IAChD,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAClE,uBAAuB;IACvB,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAExC,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * X402_ALLOWED_DOMAINS domain policy evaluation.
3
+ *
4
+ * Evaluates whether a target domain is allowed for x402 payments based on
5
+ * the X402_ALLOWED_DOMAINS policy in the policies table.
6
+ *
7
+ * Design principle: Default deny -- if no X402_ALLOWED_DOMAINS policy is
8
+ * configured, x402 payments are disabled entirely.
9
+ *
10
+ * This module is separate from DatabasePolicyEngine because X402_ALLOWED_DOMAINS
11
+ * is a domain-level policy, not a transaction-level policy. The evaluate() method
12
+ * in DatabasePolicyEngine operates on TransactionParam which has no URL/domain field.
13
+ *
14
+ * @see Research Pitfall 1: X402_ALLOWED_DOMAINS evaluation location
15
+ */
16
+ import type { PolicyEvaluation } from '@waiaas/core';
17
+ /** Policy row shape matching DatabasePolicyEngine's internal PolicyRow. */
18
+ interface PolicyRow {
19
+ id: string;
20
+ walletId: string | null;
21
+ type: string;
22
+ rules: string;
23
+ priority: number;
24
+ enabled: boolean | null;
25
+ network: string | null;
26
+ }
27
+ /**
28
+ * Match a domain pattern against a target domain.
29
+ *
30
+ * Rules:
31
+ * - "api.example.com" -> exact match only
32
+ * - "*.example.com" -> matches sub.example.com, a.b.example.com
33
+ * does NOT match example.com (dot-boundary)
34
+ * - Case-insensitive comparison
35
+ *
36
+ * @param pattern - Domain pattern (exact or wildcard like "*.example.com")
37
+ * @param target - Target domain to match against
38
+ * @returns true if pattern matches target
39
+ */
40
+ export declare function matchDomain(pattern: string, target: string): boolean;
41
+ /**
42
+ * Evaluate X402_ALLOWED_DOMAINS policy against a target domain.
43
+ *
44
+ * @param resolved - Resolved policy rows (after override resolution)
45
+ * @param targetDomain - The domain to evaluate (e.g., "api.example.com")
46
+ * @returns PolicyEvaluation with allowed=false if denied, null if allowed (continue to next evaluation)
47
+ */
48
+ export declare function evaluateX402Domain(resolved: PolicyRow[], targetDomain: string): PolicyEvaluation | null;
49
+ export {};
50
+ //# sourceMappingURL=x402-domain-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-domain-policy.d.ts","sourceRoot":"","sources":["../../../src/services/x402/x402-domain-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,cAAc,CAAC;AAMjE,2EAA2E;AAC3E,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAWD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAepE;AAMD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,EAAE,EACrB,YAAY,EAAE,MAAM,GACnB,gBAAgB,GAAG,IAAI,CA4BzB"}