@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,202 @@
1
+ /**
2
+ * ApprovalWorkflow - APPROVAL tier owner sign-off management.
3
+ *
4
+ * Manages APPROVAL tier transactions through their approval lifecycle:
5
+ * - requestApproval: creates pending_approvals record, sets tx QUEUED
6
+ * - approve: owner signs off, sets tx EXECUTING
7
+ * - reject: owner rejects, sets tx CANCELLED
8
+ * - processExpiredApprovals: batch-expire timed-out approvals
9
+ *
10
+ * Timeout resolution follows 3-level priority:
11
+ * 1. Policy-specific approval_timeout (from rules)
12
+ * 2. Config policy_defaults_approval_timeout (global config)
13
+ * 3. 3600s hardcoded fallback
14
+ *
15
+ * Uses BEGIN IMMEDIATE for atomic approve/reject/expire to prevent
16
+ * concurrent race conditions.
17
+ *
18
+ * @see docs/33-time-lock-approval-mechanism.md
19
+ */
20
+ import { WAIaaSError } from '@waiaas/core';
21
+ import { generateId } from '../infrastructure/database/id.js';
22
+ // ---------------------------------------------------------------------------
23
+ // Constants
24
+ // ---------------------------------------------------------------------------
25
+ /** Hardcoded fallback approval timeout in seconds */
26
+ const DEFAULT_APPROVAL_TIMEOUT = 3600;
27
+ // ---------------------------------------------------------------------------
28
+ // ApprovalWorkflow
29
+ // ---------------------------------------------------------------------------
30
+ export class ApprovalWorkflow {
31
+ sqlite;
32
+ configTimeout;
33
+ constructor(deps) {
34
+ this.sqlite = deps.sqlite;
35
+ this.configTimeout = deps.config.policy_defaults_approval_timeout;
36
+ }
37
+ // -------------------------------------------------------------------------
38
+ // requestApproval
39
+ // -------------------------------------------------------------------------
40
+ /**
41
+ * Create a pending approval for an APPROVAL tier transaction.
42
+ *
43
+ * Sets the transaction status to QUEUED and creates a pending_approvals
44
+ * record with an expiration time based on the 3-level timeout priority.
45
+ *
46
+ * @param txId - The transaction ID
47
+ * @param options - Optional policy-specific timeout
48
+ * @returns The approval ID and expiration timestamp
49
+ */
50
+ requestApproval(txId, options) {
51
+ const approvalId = generateId();
52
+ const now = Math.floor(Date.now() / 1000);
53
+ const timeout = this.resolveTimeout(options?.policyTimeoutSeconds);
54
+ const expiresAt = now + timeout;
55
+ const txn = this.sqlite.transaction(() => {
56
+ // Set transaction status to QUEUED
57
+ this.sqlite
58
+ .prepare('UPDATE transactions SET status = ? WHERE id = ?')
59
+ .run('QUEUED', txId);
60
+ // Create pending_approvals record
61
+ this.sqlite
62
+ .prepare(`INSERT INTO pending_approvals (id, tx_id, required_by, expires_at, created_at)
63
+ VALUES (?, ?, ?, ?, ?)`)
64
+ .run(approvalId, txId, now, expiresAt, now);
65
+ });
66
+ txn.immediate();
67
+ return { approvalId, expiresAt };
68
+ }
69
+ // -------------------------------------------------------------------------
70
+ // approve
71
+ // -------------------------------------------------------------------------
72
+ /**
73
+ * Approve a pending APPROVAL transaction with owner signature.
74
+ *
75
+ * Atomically validates the approval, sets approvedAt + ownerSignature,
76
+ * transitions the transaction to EXECUTING, and clears reserved_amount.
77
+ *
78
+ * @param txId - The transaction ID
79
+ * @param ownerSignature - The owner's cryptographic signature
80
+ * @returns The transaction ID and approval timestamp
81
+ * @throws WAIaaSError APPROVAL_NOT_FOUND if no pending approval exists
82
+ * @throws WAIaaSError APPROVAL_TIMEOUT if the approval has expired
83
+ */
84
+ approve(txId, ownerSignature) {
85
+ const txn = this.sqlite.transaction(() => {
86
+ // Find pending approval
87
+ const approval = this.sqlite
88
+ .prepare(`SELECT id, tx_id, expires_at, approved_at, rejected_at
89
+ FROM pending_approvals
90
+ WHERE tx_id = ? AND approved_at IS NULL AND rejected_at IS NULL`)
91
+ .get(txId);
92
+ if (!approval) {
93
+ throw new WAIaaSError('APPROVAL_NOT_FOUND');
94
+ }
95
+ // Check expiration
96
+ const now = Math.floor(Date.now() / 1000);
97
+ if (approval.expires_at <= now) {
98
+ throw new WAIaaSError('APPROVAL_TIMEOUT');
99
+ }
100
+ // Set approvedAt + ownerSignature
101
+ this.sqlite
102
+ .prepare('UPDATE pending_approvals SET approved_at = ?, owner_signature = ? WHERE id = ?')
103
+ .run(now, ownerSignature, approval.id);
104
+ // Transition transaction to EXECUTING and clear reserved_amount + reserved_amount_usd
105
+ this.sqlite
106
+ .prepare('UPDATE transactions SET status = ?, reserved_amount = NULL, reserved_amount_usd = NULL WHERE id = ?')
107
+ .run('EXECUTING', txId);
108
+ return { txId, approvedAt: now };
109
+ });
110
+ return txn.immediate();
111
+ }
112
+ // -------------------------------------------------------------------------
113
+ // reject
114
+ // -------------------------------------------------------------------------
115
+ /**
116
+ * Reject a pending APPROVAL transaction.
117
+ *
118
+ * Atomically sets rejectedAt, transitions the transaction to CANCELLED,
119
+ * and clears reserved_amount.
120
+ *
121
+ * @param txId - The transaction ID
122
+ * @returns The transaction ID and rejection timestamp
123
+ * @throws WAIaaSError APPROVAL_NOT_FOUND if no pending approval exists
124
+ */
125
+ reject(txId) {
126
+ const txn = this.sqlite.transaction(() => {
127
+ // Find pending approval
128
+ const approval = this.sqlite
129
+ .prepare(`SELECT id, tx_id, expires_at, approved_at, rejected_at
130
+ FROM pending_approvals
131
+ WHERE tx_id = ? AND approved_at IS NULL AND rejected_at IS NULL`)
132
+ .get(txId);
133
+ if (!approval) {
134
+ throw new WAIaaSError('APPROVAL_NOT_FOUND');
135
+ }
136
+ const now = Math.floor(Date.now() / 1000);
137
+ // Set rejectedAt
138
+ this.sqlite
139
+ .prepare('UPDATE pending_approvals SET rejected_at = ? WHERE id = ?')
140
+ .run(now, approval.id);
141
+ // Transition transaction to CANCELLED and clear reserved_amount + reserved_amount_usd
142
+ this.sqlite
143
+ .prepare('UPDATE transactions SET status = ?, reserved_amount = NULL, reserved_amount_usd = NULL WHERE id = ?')
144
+ .run('CANCELLED', txId);
145
+ return { txId, rejectedAt: now };
146
+ });
147
+ return txn.immediate();
148
+ }
149
+ // -------------------------------------------------------------------------
150
+ // processExpiredApprovals
151
+ // -------------------------------------------------------------------------
152
+ /**
153
+ * Batch-expire pending approvals that have exceeded their timeout.
154
+ *
155
+ * For each expired approval: sets the transaction status to EXPIRED and
156
+ * clears reserved_amount. Does NOT set rejectedAt (expired != rejected).
157
+ *
158
+ * @param now - Current Unix epoch seconds
159
+ * @returns Count of expired approvals
160
+ */
161
+ processExpiredApprovals(now) {
162
+ const txn = this.sqlite.transaction(() => {
163
+ // Find expired approvals
164
+ const expired = this.sqlite
165
+ .prepare(`SELECT id, tx_id
166
+ FROM pending_approvals
167
+ WHERE expires_at <= ? AND approved_at IS NULL AND rejected_at IS NULL`)
168
+ .all(now);
169
+ if (expired.length === 0) {
170
+ return 0;
171
+ }
172
+ // Batch update: set transaction EXPIRED + clear reserved_amount + reserved_amount_usd
173
+ const updateTx = this.sqlite.prepare('UPDATE transactions SET status = ?, reserved_amount = NULL, reserved_amount_usd = NULL WHERE id = ?');
174
+ for (const row of expired) {
175
+ updateTx.run('EXPIRED', row.tx_id);
176
+ }
177
+ // Note: We intentionally do NOT set rejectedAt on the approval records.
178
+ // Expired != rejected. The approval simply timed out.
179
+ return expired.length;
180
+ });
181
+ return txn.immediate();
182
+ }
183
+ // -------------------------------------------------------------------------
184
+ // Private: Timeout resolution
185
+ // -------------------------------------------------------------------------
186
+ /**
187
+ * Resolve approval timeout with 3-level priority:
188
+ * 1. Policy-specific timeout (from options)
189
+ * 2. Config timeout (policy_defaults_approval_timeout)
190
+ * 3. 3600 hardcoded fallback
191
+ */
192
+ resolveTimeout(policyTimeoutSeconds) {
193
+ if (policyTimeoutSeconds !== undefined && policyTimeoutSeconds > 0) {
194
+ return policyTimeoutSeconds;
195
+ }
196
+ if (this.configTimeout !== undefined && this.configTimeout > 0) {
197
+ return this.configTimeout;
198
+ }
199
+ return DEFAULT_APPROVAL_TIMEOUT;
200
+ }
201
+ }
202
+ //# sourceMappingURL=approval-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-workflow.js","sourceRoot":"","sources":["../../src/workflow/approval-workflow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAG9D,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,qDAAqD;AACrD,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAyCtC,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,OAAO,gBAAgB;IACV,MAAM,CAAiB;IACvB,aAAa,CAAS;IAEvC,YA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4EAA4E;IAE5E;;;;;OAKG;IACK,cAAc,CAAC,oBAA6B;QAClD,IAAI,oBAAoB,KAAK,SAAS,IAAI,oBAAoB,GAAG,CAAC,EAAE,CAAC;YACnE,OAAO,oBAAoB,CAAC;QAC9B,CAAC;QACD,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC,aAAa,CAAC;QAC5B,CAAC;QACD,OAAO,wBAAwB,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * DelayQueue - manages DELAY tier transaction cooldown lifecycle.
3
+ *
4
+ * The DELAY tier is the second layer of the 3-tier security model.
5
+ * Transactions above a configurable threshold must wait before execution,
6
+ * giving the owner time to cancel suspicious activity.
7
+ *
8
+ * Lifecycle: PENDING -> QUEUED (with cooldown) -> EXECUTING (auto-execute after expiry)
9
+ * -> CANCELLED (owner cancels during cooldown)
10
+ *
11
+ * Uses BEGIN IMMEDIATE for processExpired to prevent concurrent processing
12
+ * of the same transaction.
13
+ *
14
+ * @see docs/33-time-lock-approval-mechanism.md
15
+ */
16
+ import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
17
+ import type { Database as SQLiteDatabase } from 'better-sqlite3';
18
+ import type * as schema from '../infrastructure/database/schema.js';
19
+ export interface DelayQueueDeps {
20
+ db: BetterSQLite3Database<typeof schema>;
21
+ sqlite: SQLiteDatabase;
22
+ }
23
+ export interface QueueResult {
24
+ queuedAt: number;
25
+ expiresAt: number;
26
+ }
27
+ export interface ExpiredTransaction {
28
+ txId: string;
29
+ walletId: string;
30
+ }
31
+ /**
32
+ * Manages DELAY tier transaction cooldown: queue, cancel, auto-execute.
33
+ *
34
+ * Constructor takes dual DB pattern (Drizzle + raw better-sqlite3) same as
35
+ * DatabasePolicyEngine for BEGIN IMMEDIATE support.
36
+ */
37
+ export declare class DelayQueue {
38
+ private readonly sqlite;
39
+ constructor(deps: DelayQueueDeps);
40
+ /**
41
+ * Queue a transaction for DELAY tier cooldown.
42
+ *
43
+ * Sets status to QUEUED, records queuedAt timestamp and delaySeconds in metadata.
44
+ *
45
+ * @param txId - Transaction ID to queue
46
+ * @param delaySeconds - Cooldown duration in seconds
47
+ * @returns { queuedAt, expiresAt } timestamps (Unix seconds)
48
+ */
49
+ queueDelay(txId: string, delaySeconds: number): QueueResult;
50
+ /**
51
+ * Cancel a QUEUED transaction during its cooldown window.
52
+ *
53
+ * Sets status to CANCELLED and clears reserved_amount.
54
+ *
55
+ * @param txId - Transaction ID to cancel
56
+ * @throws WAIaaSError TX_NOT_FOUND if transaction doesn't exist
57
+ * @throws WAIaaSError TX_ALREADY_PROCESSED if transaction is not QUEUED
58
+ */
59
+ cancelDelay(txId: string): void;
60
+ /**
61
+ * Find and transition expired QUEUED transactions to EXECUTING.
62
+ *
63
+ * Uses BEGIN IMMEDIATE to prevent concurrent processing of the same transaction.
64
+ * Reads delaySeconds from metadata JSON to calculate expiry.
65
+ *
66
+ * @param now - Current time in Unix seconds
67
+ * @returns Array of { txId, walletId } for pipeline to execute stages 5-6
68
+ */
69
+ processExpired(now: number): ExpiredTransaction[];
70
+ /**
71
+ * Check if a QUEUED transaction's cooldown has elapsed.
72
+ *
73
+ * @param txId - Transaction ID to check
74
+ * @returns true if cooldown has elapsed, false otherwise
75
+ */
76
+ isExpired(txId: string): boolean;
77
+ }
78
+ //# sourceMappingURL=delay-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay-queue.d.ts","sourceRoot":"","sources":["../../src/workflow/delay-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,KAAK,MAAM,MAAM,sCAAsC,CAAC;AAMpE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;gBAE5B,IAAI,EAAE,cAAc;IAQhC;;;;;;;;OAQG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,WAAW;IAkC3D;;;;;;;;OAQG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IA8B/B;;;;;;;;OAQG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,EAAE;IA+CjD;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAwBjC"}
@@ -0,0 +1,174 @@
1
+ /**
2
+ * DelayQueue - manages DELAY tier transaction cooldown lifecycle.
3
+ *
4
+ * The DELAY tier is the second layer of the 3-tier security model.
5
+ * Transactions above a configurable threshold must wait before execution,
6
+ * giving the owner time to cancel suspicious activity.
7
+ *
8
+ * Lifecycle: PENDING -> QUEUED (with cooldown) -> EXECUTING (auto-execute after expiry)
9
+ * -> CANCELLED (owner cancels during cooldown)
10
+ *
11
+ * Uses BEGIN IMMEDIATE for processExpired to prevent concurrent processing
12
+ * of the same transaction.
13
+ *
14
+ * @see docs/33-time-lock-approval-mechanism.md
15
+ */
16
+ import { WAIaaSError } from '@waiaas/core';
17
+ // ---------------------------------------------------------------------------
18
+ // DelayQueue
19
+ // ---------------------------------------------------------------------------
20
+ /**
21
+ * Manages DELAY tier transaction cooldown: queue, cancel, auto-execute.
22
+ *
23
+ * Constructor takes dual DB pattern (Drizzle + raw better-sqlite3) same as
24
+ * DatabasePolicyEngine for BEGIN IMMEDIATE support.
25
+ */
26
+ export class DelayQueue {
27
+ sqlite;
28
+ constructor(deps) {
29
+ this.sqlite = deps.sqlite;
30
+ }
31
+ // -------------------------------------------------------------------------
32
+ // queueDelay
33
+ // -------------------------------------------------------------------------
34
+ /**
35
+ * Queue a transaction for DELAY tier cooldown.
36
+ *
37
+ * Sets status to QUEUED, records queuedAt timestamp and delaySeconds in metadata.
38
+ *
39
+ * @param txId - Transaction ID to queue
40
+ * @param delaySeconds - Cooldown duration in seconds
41
+ * @returns { queuedAt, expiresAt } timestamps (Unix seconds)
42
+ */
43
+ queueDelay(txId, delaySeconds) {
44
+ const queuedAt = Math.floor(Date.now() / 1000);
45
+ const expiresAt = queuedAt + delaySeconds;
46
+ // Read existing metadata and merge delaySeconds
47
+ const existing = this.sqlite
48
+ .prepare('SELECT metadata FROM transactions WHERE id = ?')
49
+ .get(txId);
50
+ let metadata = {};
51
+ if (existing?.metadata) {
52
+ try {
53
+ metadata = JSON.parse(existing.metadata);
54
+ }
55
+ catch {
56
+ // ignore parse errors, start fresh
57
+ }
58
+ }
59
+ metadata.delaySeconds = delaySeconds;
60
+ this.sqlite
61
+ .prepare(`UPDATE transactions
62
+ SET status = 'QUEUED', queued_at = ?, metadata = ?
63
+ WHERE id = ?`)
64
+ .run(queuedAt, JSON.stringify(metadata), txId);
65
+ return { queuedAt, expiresAt };
66
+ }
67
+ // -------------------------------------------------------------------------
68
+ // cancelDelay
69
+ // -------------------------------------------------------------------------
70
+ /**
71
+ * Cancel a QUEUED transaction during its cooldown window.
72
+ *
73
+ * Sets status to CANCELLED and clears reserved_amount.
74
+ *
75
+ * @param txId - Transaction ID to cancel
76
+ * @throws WAIaaSError TX_NOT_FOUND if transaction doesn't exist
77
+ * @throws WAIaaSError TX_ALREADY_PROCESSED if transaction is not QUEUED
78
+ */
79
+ cancelDelay(txId) {
80
+ const row = this.sqlite
81
+ .prepare('SELECT id, status FROM transactions WHERE id = ?')
82
+ .get(txId);
83
+ if (!row) {
84
+ throw new WAIaaSError('TX_NOT_FOUND', {
85
+ message: `Transaction ${txId} not found`,
86
+ });
87
+ }
88
+ if (row.status !== 'QUEUED') {
89
+ throw new WAIaaSError('TX_ALREADY_PROCESSED', {
90
+ message: `Transaction ${txId} is ${row.status}, not QUEUED`,
91
+ });
92
+ }
93
+ this.sqlite
94
+ .prepare(`UPDATE transactions
95
+ SET status = 'CANCELLED', reserved_amount = NULL
96
+ WHERE id = ?`)
97
+ .run(txId);
98
+ }
99
+ // -------------------------------------------------------------------------
100
+ // processExpired
101
+ // -------------------------------------------------------------------------
102
+ /**
103
+ * Find and transition expired QUEUED transactions to EXECUTING.
104
+ *
105
+ * Uses BEGIN IMMEDIATE to prevent concurrent processing of the same transaction.
106
+ * Reads delaySeconds from metadata JSON to calculate expiry.
107
+ *
108
+ * @param now - Current time in Unix seconds
109
+ * @returns Array of { txId, walletId } for pipeline to execute stages 5-6
110
+ */
111
+ processExpired(now) {
112
+ const sqlite = this.sqlite;
113
+ const txn = sqlite.transaction(() => {
114
+ // Select QUEUED transactions whose cooldown has elapsed.
115
+ // delaySeconds is stored in metadata JSON.
116
+ // Expiry check: queued_at + JSON_EXTRACT(metadata, '$.delaySeconds') <= now
117
+ const rows = sqlite
118
+ .prepare(`SELECT id, wallet_id
119
+ FROM transactions
120
+ WHERE status = 'QUEUED'
121
+ AND queued_at IS NOT NULL
122
+ AND metadata IS NOT NULL
123
+ AND (queued_at + CAST(JSON_EXTRACT(metadata, '$.delaySeconds') AS INTEGER)) <= ?`)
124
+ .all(now);
125
+ if (rows.length === 0) {
126
+ return [];
127
+ }
128
+ // Transition each expired transaction to EXECUTING
129
+ const updateStmt = sqlite.prepare(`UPDATE transactions SET status = 'EXECUTING' WHERE id = ? AND status = 'QUEUED'`);
130
+ const result = [];
131
+ for (const row of rows) {
132
+ const changes = updateStmt.run(row.id);
133
+ // Only include if we actually updated (guard against concurrent processing)
134
+ if (changes.changes > 0) {
135
+ result.push({ txId: row.id, walletId: row.wallet_id });
136
+ }
137
+ }
138
+ return result;
139
+ });
140
+ // Execute with IMMEDIATE isolation
141
+ return txn.immediate();
142
+ }
143
+ // -------------------------------------------------------------------------
144
+ // isExpired
145
+ // -------------------------------------------------------------------------
146
+ /**
147
+ * Check if a QUEUED transaction's cooldown has elapsed.
148
+ *
149
+ * @param txId - Transaction ID to check
150
+ * @returns true if cooldown has elapsed, false otherwise
151
+ */
152
+ isExpired(txId) {
153
+ const row = this.sqlite
154
+ .prepare('SELECT queued_at, metadata FROM transactions WHERE id = ? AND status = ?')
155
+ .get(txId, 'QUEUED');
156
+ if (!row || !row.queued_at || !row.metadata) {
157
+ return false;
158
+ }
159
+ let metadata;
160
+ try {
161
+ metadata = JSON.parse(row.metadata);
162
+ }
163
+ catch {
164
+ return false;
165
+ }
166
+ const delaySeconds = metadata.delaySeconds;
167
+ if (typeof delaySeconds !== 'number') {
168
+ return false;
169
+ }
170
+ const now = Math.floor(Date.now() / 1000);
171
+ return (row.queued_at + delaySeconds) <= now;
172
+ }
173
+ }
174
+ //# sourceMappingURL=delay-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay-queue.js","sourceRoot":"","sources":["../../src/workflow/delay-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAsB3C,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACJ,MAAM,CAAiB;IAExC,YAAY,IAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,4EAA4E;IAC5E,aAAa;IACb,4EAA4E;IAE5E;;;;;;;;OAQG;IACH,UAAU,CAAC,IAAY,EAAE,YAAoB;QAC3C,MAAM,QAAQ,GAA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H,SAAS,CAAC,IAAY;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM;aACpB,OAAO,CAAC,0EAA0E,CAAC;aACnF,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAsE,CAAC;QAE5F,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,QAAiC,CAAC;QACtC,IAAI,CAAC;YACH,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAA4B,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAsB,CAAC;QACrD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,YAAY,CAAC,IAAI,GAAG,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Workflow module barrel export.
3
+ *
4
+ * Exports workflow services for DELAY and APPROVAL tier management.
5
+ */
6
+ export { DelayQueue } from './delay-queue.js';
7
+ export type { DelayQueueDeps, QueueResult, ExpiredTransaction } from './delay-queue.js';
8
+ export { ApprovalWorkflow } from './approval-workflow.js';
9
+ export { resolveOwnerState, OwnerLifecycleService, downgradeIfNoOwner, } from './owner-state.js';
10
+ export type { OwnerState, OwnerLifecycleDeps } from './owner-state.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Workflow module barrel export.
3
+ *
4
+ * Exports workflow services for DELAY and APPROVAL tier management.
5
+ */
6
+ export { DelayQueue } from './delay-queue.js';
7
+ export { ApprovalWorkflow } from './approval-workflow.js';
8
+ export { resolveOwnerState, OwnerLifecycleService, downgradeIfNoOwner, } from './owner-state.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Owner 3-State Machine: NONE -> GRACE -> LOCKED.
3
+ *
4
+ * Manages the Owner lifecycle for wallets:
5
+ * - NONE: No owner registered. APPROVAL tier auto-downgrades to DELAY.
6
+ * - GRACE: Owner address set but not yet verified via signature.
7
+ * Owner can be changed/removed with masterAuth only.
8
+ * - LOCKED: Owner verified via ownerAuth signature.
9
+ * Owner change requires ownerAuth; removal blocked entirely.
10
+ *
11
+ * Provides:
12
+ * - resolveOwnerState(): pure function to determine state from wallet fields
13
+ * - OwnerLifecycleService: setOwner/removeOwner/markOwnerVerified with DB ops
14
+ * - downgradeIfNoOwner(): APPROVAL -> DELAY when no owner registered
15
+ *
16
+ * @see docs/34-owner-wallet-design.md
17
+ */
18
+ import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
19
+ import type { Database as SQLiteDatabase } from 'better-sqlite3';
20
+ import type * as schema from '../infrastructure/database/schema.js';
21
+ export type OwnerState = 'NONE' | 'GRACE' | 'LOCKED';
22
+ interface WalletOwnerFields {
23
+ ownerAddress: string | null;
24
+ ownerVerified: boolean;
25
+ }
26
+ export interface OwnerLifecycleDeps {
27
+ db: BetterSQLite3Database<typeof schema>;
28
+ sqlite: SQLiteDatabase;
29
+ }
30
+ interface DowngradeResult {
31
+ tier: string;
32
+ downgraded: boolean;
33
+ }
34
+ /**
35
+ * Determine the Owner state from wallet fields.
36
+ *
37
+ * Pure function, no DB access, no side effects.
38
+ *
39
+ * @param wallet - Wallet fields { ownerAddress, ownerVerified }
40
+ * @returns 'NONE' | 'GRACE' | 'LOCKED'
41
+ */
42
+ export declare function resolveOwnerState(wallet: WalletOwnerFields): OwnerState;
43
+ /**
44
+ * Service managing Owner state transitions with DB persistence.
45
+ */
46
+ export declare class OwnerLifecycleService {
47
+ private readonly sqlite;
48
+ constructor(deps: OwnerLifecycleDeps);
49
+ /**
50
+ * Set the owner address for a wallet.
51
+ *
52
+ * - NONE or GRACE: sets ownerAddress, ownerVerified = false
53
+ * - LOCKED: throws OWNER_ALREADY_CONNECTED
54
+ *
55
+ * @param walletId - Wallet ID
56
+ * @param ownerAddress - Owner wallet address to set
57
+ * @throws WAIaaSError OWNER_ALREADY_CONNECTED if in LOCKED state
58
+ */
59
+ setOwner(walletId: string, ownerAddress: string): void;
60
+ /**
61
+ * Remove the owner from a wallet.
62
+ *
63
+ * - GRACE: clears ownerAddress, ownerVerified = false
64
+ * - LOCKED: throws OWNER_ALREADY_CONNECTED
65
+ * - NONE: no-op (already no owner)
66
+ *
67
+ * @param walletId - Wallet ID
68
+ * @throws WAIaaSError OWNER_ALREADY_CONNECTED if in LOCKED state
69
+ */
70
+ removeOwner(walletId: string): void;
71
+ /**
72
+ * Mark the owner as verified (GRACE -> LOCKED transition).
73
+ *
74
+ * Called when ownerAuth middleware succeeds on any ownerAuth-protected route.
75
+ *
76
+ * - GRACE: sets ownerVerified = true
77
+ * - LOCKED: no-op (already verified)
78
+ * - NONE: throws OWNER_NOT_CONNECTED
79
+ *
80
+ * @param walletId - Wallet ID
81
+ * @throws WAIaaSError OWNER_NOT_CONNECTED if in NONE state
82
+ */
83
+ markOwnerVerified(walletId: string): void;
84
+ private getWalletRow;
85
+ }
86
+ /**
87
+ * If tier is APPROVAL and owner state is NONE, downgrade to DELAY.
88
+ *
89
+ * The caller should log a TX_DOWNGRADED_DELAY audit event when downgraded=true.
90
+ *
91
+ * @param wallet - Wallet fields for resolveOwnerState
92
+ * @param tier - Current policy tier
93
+ * @returns { tier, downgraded }
94
+ */
95
+ export declare function downgradeIfNoOwner(wallet: WalletOwnerFields, tier: string): DowngradeResult;
96
+ export {};
97
+ //# sourceMappingURL=owner-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-state.d.ts","sourceRoot":"","sources":["../../src/workflow/owner-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,KAAK,MAAM,MAAM,sCAAsC,CAAC;AAMpE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErD,UAAU,iBAAiB;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC;I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