@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.
- package/dist/api/error-hints.d.ts +15 -0
- package/dist/api/error-hints.d.ts.map +1 -0
- package/dist/api/error-hints.js +71 -0
- package/dist/api/error-hints.js.map +1 -0
- package/dist/api/index.d.ts +11 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +14 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middleware/address-validation.d.ts +38 -0
- package/dist/api/middleware/address-validation.d.ts.map +1 -0
- package/dist/api/middleware/address-validation.js +134 -0
- package/dist/api/middleware/address-validation.js.map +1 -0
- package/dist/api/middleware/csp.d.ts +17 -0
- package/dist/api/middleware/csp.d.ts.map +1 -0
- package/dist/api/middleware/csp.js +31 -0
- package/dist/api/middleware/csp.js.map +1 -0
- package/dist/api/middleware/error-handler.d.ts +16 -0
- package/dist/api/middleware/error-handler.d.ts.map +1 -0
- package/dist/api/middleware/error-handler.js +46 -0
- package/dist/api/middleware/error-handler.js.map +1 -0
- package/dist/api/middleware/host-guard.d.ts +11 -0
- package/dist/api/middleware/host-guard.d.ts.map +1 -0
- package/dist/api/middleware/host-guard.js +25 -0
- package/dist/api/middleware/host-guard.js.map +1 -0
- package/dist/api/middleware/index.d.ts +13 -0
- package/dist/api/middleware/index.d.ts.map +1 -0
- package/dist/api/middleware/index.js +13 -0
- package/dist/api/middleware/index.js.map +1 -0
- package/dist/api/middleware/kill-switch-guard.d.ts +19 -0
- package/dist/api/middleware/kill-switch-guard.d.ts.map +1 -0
- package/dist/api/middleware/kill-switch-guard.js +49 -0
- package/dist/api/middleware/kill-switch-guard.js.map +1 -0
- package/dist/api/middleware/master-auth.d.ts +15 -0
- package/dist/api/middleware/master-auth.d.ts.map +1 -0
- package/dist/api/middleware/master-auth.js +35 -0
- package/dist/api/middleware/master-auth.js.map +1 -0
- package/dist/api/middleware/owner-auth.d.ts +30 -0
- package/dist/api/middleware/owner-auth.d.ts.map +1 -0
- package/dist/api/middleware/owner-auth.js +133 -0
- package/dist/api/middleware/owner-auth.js.map +1 -0
- package/dist/api/middleware/request-id.d.ts +10 -0
- package/dist/api/middleware/request-id.d.ts.map +1 -0
- package/dist/api/middleware/request-id.js +18 -0
- package/dist/api/middleware/request-id.js.map +1 -0
- package/dist/api/middleware/request-logger.d.ts +9 -0
- package/dist/api/middleware/request-logger.d.ts.map +1 -0
- package/dist/api/middleware/request-logger.js +18 -0
- package/dist/api/middleware/request-logger.js.map +1 -0
- package/dist/api/middleware/session-auth.d.ts +21 -0
- package/dist/api/middleware/session-auth.d.ts.map +1 -0
- package/dist/api/middleware/session-auth.js +51 -0
- package/dist/api/middleware/session-auth.js.map +1 -0
- package/dist/api/middleware/siwe-verify.d.ts +31 -0
- package/dist/api/middleware/siwe-verify.d.ts.map +1 -0
- package/dist/api/middleware/siwe-verify.js +55 -0
- package/dist/api/middleware/siwe-verify.js.map +1 -0
- package/dist/api/routes/actions.d.ts +56 -0
- package/dist/api/routes/actions.d.ts.map +1 -0
- package/dist/api/routes/actions.js +291 -0
- package/dist/api/routes/actions.js.map +1 -0
- package/dist/api/routes/admin.d.ts +99 -0
- package/dist/api/routes/admin.d.ts.map +1 -0
- package/dist/api/routes/admin.js +1304 -0
- package/dist/api/routes/admin.js.map +1 -0
- package/dist/api/routes/display-currency-helper.d.ts +26 -0
- package/dist/api/routes/display-currency-helper.d.ts.map +1 -0
- package/dist/api/routes/display-currency-helper.js +47 -0
- package/dist/api/routes/display-currency-helper.js.map +1 -0
- package/dist/api/routes/health.d.ts +14 -0
- package/dist/api/routes/health.d.ts.map +1 -0
- package/dist/api/routes/health.js +47 -0
- package/dist/api/routes/health.js.map +1 -0
- package/dist/api/routes/index.d.ts +15 -0
- package/dist/api/routes/index.d.ts.map +1 -0
- package/dist/api/routes/index.js +15 -0
- package/dist/api/routes/index.js.map +1 -0
- package/dist/api/routes/mcp.d.ts +30 -0
- package/dist/api/routes/mcp.d.ts.map +1 -0
- package/dist/api/routes/mcp.js +156 -0
- package/dist/api/routes/mcp.js.map +1 -0
- package/dist/api/routes/nonce.d.ts +20 -0
- package/dist/api/routes/nonce.d.ts.map +1 -0
- package/dist/api/routes/nonce.js +48 -0
- package/dist/api/routes/nonce.js.map +1 -0
- package/dist/api/routes/openapi-schemas.d.ts +2281 -0
- package/dist/api/routes/openapi-schemas.d.ts.map +1 -0
- package/dist/api/routes/openapi-schemas.js +770 -0
- package/dist/api/routes/openapi-schemas.js.map +1 -0
- package/dist/api/routes/policies.d.ts +29 -0
- package/dist/api/routes/policies.d.ts.map +1 -0
- package/dist/api/routes/policies.js +332 -0
- package/dist/api/routes/policies.js.map +1 -0
- package/dist/api/routes/sessions.d.ts +35 -0
- package/dist/api/routes/sessions.d.ts.map +1 -0
- package/dist/api/routes/sessions.js +347 -0
- package/dist/api/routes/sessions.js.map +1 -0
- package/dist/api/routes/skills.d.ts +9 -0
- package/dist/api/routes/skills.d.ts.map +1 -0
- package/dist/api/routes/skills.js +59 -0
- package/dist/api/routes/skills.js.map +1 -0
- package/dist/api/routes/tokens.d.ts +25 -0
- package/dist/api/routes/tokens.d.ts.map +1 -0
- package/dist/api/routes/tokens.js +161 -0
- package/dist/api/routes/tokens.js.map +1 -0
- package/dist/api/routes/transactions.d.ts +68 -0
- package/dist/api/routes/transactions.d.ts.map +1 -0
- package/dist/api/routes/transactions.js +576 -0
- package/dist/api/routes/transactions.js.map +1 -0
- package/dist/api/routes/utils.d.ts +9 -0
- package/dist/api/routes/utils.d.ts.map +1 -0
- package/dist/api/routes/utils.js +52 -0
- package/dist/api/routes/utils.js.map +1 -0
- package/dist/api/routes/wallet.d.ts +36 -0
- package/dist/api/routes/wallet.d.ts.map +1 -0
- package/dist/api/routes/wallet.js +358 -0
- package/dist/api/routes/wallet.js.map +1 -0
- package/dist/api/routes/wallets.d.ts +43 -0
- package/dist/api/routes/wallets.d.ts.map +1 -0
- package/dist/api/routes/wallets.js +630 -0
- package/dist/api/routes/wallets.js.map +1 -0
- package/dist/api/routes/wc.d.ts +46 -0
- package/dist/api/routes/wc.d.ts.map +1 -0
- package/dist/api/routes/wc.js +354 -0
- package/dist/api/routes/wc.js.map +1 -0
- package/dist/api/routes/x402.d.ts +61 -0
- package/dist/api/routes/x402.d.ts.map +1 -0
- package/dist/api/routes/x402.js +493 -0
- package/dist/api/routes/x402.js.map +1 -0
- package/dist/api/server.d.ts +81 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +406 -0
- package/dist/api/server.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/action/action-provider-registry.d.ts +77 -0
- package/dist/infrastructure/action/action-provider-registry.d.ts.map +1 -0
- package/dist/infrastructure/action/action-provider-registry.js +239 -0
- package/dist/infrastructure/action/action-provider-registry.js.map +1 -0
- package/dist/infrastructure/action/api-key-store.d.ts +60 -0
- package/dist/infrastructure/action/api-key-store.d.ts.map +1 -0
- package/dist/infrastructure/action/api-key-store.js +130 -0
- package/dist/infrastructure/action/api-key-store.js.map +1 -0
- package/dist/infrastructure/action/index.d.ts +10 -0
- package/dist/infrastructure/action/index.d.ts.map +1 -0
- package/dist/infrastructure/action/index.js +9 -0
- package/dist/infrastructure/action/index.js.map +1 -0
- package/dist/infrastructure/adapter-pool.d.ts +50 -0
- package/dist/infrastructure/adapter-pool.d.ts.map +1 -0
- package/dist/infrastructure/adapter-pool.js +110 -0
- package/dist/infrastructure/adapter-pool.js.map +1 -0
- package/dist/infrastructure/backup/backup-service.d.ts +53 -0
- package/dist/infrastructure/backup/backup-service.d.ts.map +1 -0
- package/dist/infrastructure/backup/backup-service.js +158 -0
- package/dist/infrastructure/backup/backup-service.js.map +1 -0
- package/dist/infrastructure/backup/index.d.ts +2 -0
- package/dist/infrastructure/backup/index.d.ts.map +1 -0
- package/dist/infrastructure/backup/index.js +2 -0
- package/dist/infrastructure/backup/index.js.map +1 -0
- package/dist/infrastructure/config/index.d.ts +8 -0
- package/dist/infrastructure/config/index.d.ts.map +1 -0
- package/dist/infrastructure/config/index.js +7 -0
- package/dist/infrastructure/config/index.js.map +1 -0
- package/dist/infrastructure/config/loader.d.ts +555 -0
- package/dist/infrastructure/config/loader.d.ts.map +1 -0
- package/dist/infrastructure/config/loader.js +311 -0
- package/dist/infrastructure/config/loader.js.map +1 -0
- package/dist/infrastructure/database/checks.d.ts +19 -0
- package/dist/infrastructure/database/checks.d.ts.map +1 -0
- package/dist/infrastructure/database/checks.js +27 -0
- package/dist/infrastructure/database/checks.js.map +1 -0
- package/dist/infrastructure/database/compatibility.d.ts +36 -0
- package/dist/infrastructure/database/compatibility.d.ts.map +1 -0
- package/dist/infrastructure/database/compatibility.js +75 -0
- package/dist/infrastructure/database/compatibility.js.map +1 -0
- package/dist/infrastructure/database/connection.d.ts +36 -0
- package/dist/infrastructure/database/connection.d.ts.map +1 -0
- package/dist/infrastructure/database/connection.js +47 -0
- package/dist/infrastructure/database/connection.js.map +1 -0
- package/dist/infrastructure/database/id.d.ts +17 -0
- package/dist/infrastructure/database/id.d.ts.map +1 -0
- package/dist/infrastructure/database/id.js +20 -0
- package/dist/infrastructure/database/id.js.map +1 -0
- package/dist/infrastructure/database/index.d.ts +15 -0
- package/dist/infrastructure/database/index.d.ts.map +1 -0
- package/dist/infrastructure/database/index.js +12 -0
- package/dist/infrastructure/database/index.js.map +1 -0
- package/dist/infrastructure/database/migrate.d.ts +76 -0
- package/dist/infrastructure/database/migrate.d.ts.map +1 -0
- package/dist/infrastructure/database/migrate.js +1214 -0
- package/dist/infrastructure/database/migrate.js.map +1 -0
- package/dist/infrastructure/database/schema.d.ts +2352 -0
- package/dist/infrastructure/database/schema.d.ts.map +1 -0
- package/dist/infrastructure/database/schema.js +288 -0
- package/dist/infrastructure/database/schema.js.map +1 -0
- package/dist/infrastructure/jwt/index.d.ts +2 -0
- package/dist/infrastructure/jwt/index.d.ts.map +1 -0
- package/dist/infrastructure/jwt/index.js +2 -0
- package/dist/infrastructure/jwt/index.js.map +1 -0
- package/dist/infrastructure/jwt/jwt-secret-manager.d.ts +58 -0
- package/dist/infrastructure/jwt/jwt-secret-manager.d.ts.map +1 -0
- package/dist/infrastructure/jwt/jwt-secret-manager.js +222 -0
- package/dist/infrastructure/jwt/jwt-secret-manager.js.map +1 -0
- package/dist/infrastructure/keystore/crypto.d.ts +62 -0
- package/dist/infrastructure/keystore/crypto.d.ts.map +1 -0
- package/dist/infrastructure/keystore/crypto.js +89 -0
- package/dist/infrastructure/keystore/crypto.js.map +1 -0
- package/dist/infrastructure/keystore/index.d.ts +4 -0
- package/dist/infrastructure/keystore/index.d.ts.map +1 -0
- package/dist/infrastructure/keystore/index.js +5 -0
- package/dist/infrastructure/keystore/index.js.map +1 -0
- package/dist/infrastructure/keystore/keystore.d.ts +115 -0
- package/dist/infrastructure/keystore/keystore.d.ts.map +1 -0
- package/dist/infrastructure/keystore/keystore.js +327 -0
- package/dist/infrastructure/keystore/keystore.js.map +1 -0
- package/dist/infrastructure/keystore/memory.d.ts +45 -0
- package/dist/infrastructure/keystore/memory.d.ts.map +1 -0
- package/dist/infrastructure/keystore/memory.js +105 -0
- package/dist/infrastructure/keystore/memory.js.map +1 -0
- package/dist/infrastructure/oracle/coingecko-forex.d.ts +35 -0
- package/dist/infrastructure/oracle/coingecko-forex.d.ts.map +1 -0
- package/dist/infrastructure/oracle/coingecko-forex.js +69 -0
- package/dist/infrastructure/oracle/coingecko-forex.js.map +1 -0
- package/dist/infrastructure/oracle/coingecko-oracle.d.ts +73 -0
- package/dist/infrastructure/oracle/coingecko-oracle.d.ts.map +1 -0
- package/dist/infrastructure/oracle/coingecko-oracle.js +199 -0
- package/dist/infrastructure/oracle/coingecko-oracle.js.map +1 -0
- package/dist/infrastructure/oracle/coingecko-platform-ids.d.ts +32 -0
- package/dist/infrastructure/oracle/coingecko-platform-ids.d.ts.map +1 -0
- package/dist/infrastructure/oracle/coingecko-platform-ids.js +30 -0
- package/dist/infrastructure/oracle/coingecko-platform-ids.js.map +1 -0
- package/dist/infrastructure/oracle/forex-currencies.d.ts +36 -0
- package/dist/infrastructure/oracle/forex-currencies.d.ts.map +1 -0
- package/dist/infrastructure/oracle/forex-currencies.js +71 -0
- package/dist/infrastructure/oracle/forex-currencies.js.map +1 -0
- package/dist/infrastructure/oracle/forex-rate-service.d.ts +51 -0
- package/dist/infrastructure/oracle/forex-rate-service.d.ts.map +1 -0
- package/dist/infrastructure/oracle/forex-rate-service.js +149 -0
- package/dist/infrastructure/oracle/forex-rate-service.js.map +1 -0
- package/dist/infrastructure/oracle/index.d.ts +18 -0
- package/dist/infrastructure/oracle/index.d.ts.map +1 -0
- package/dist/infrastructure/oracle/index.js +19 -0
- package/dist/infrastructure/oracle/index.js.map +1 -0
- package/dist/infrastructure/oracle/oracle-chain.d.ts +101 -0
- package/dist/infrastructure/oracle/oracle-chain.d.ts.map +1 -0
- package/dist/infrastructure/oracle/oracle-chain.js +163 -0
- package/dist/infrastructure/oracle/oracle-chain.js.map +1 -0
- package/dist/infrastructure/oracle/oracle-errors.d.ts +42 -0
- package/dist/infrastructure/oracle/oracle-errors.d.ts.map +1 -0
- package/dist/infrastructure/oracle/oracle-errors.js +53 -0
- package/dist/infrastructure/oracle/oracle-errors.js.map +1 -0
- package/dist/infrastructure/oracle/price-age.d.ts +38 -0
- package/dist/infrastructure/oracle/price-age.d.ts.map +1 -0
- package/dist/infrastructure/oracle/price-age.js +44 -0
- package/dist/infrastructure/oracle/price-age.js.map +1 -0
- package/dist/infrastructure/oracle/price-cache.d.ts +99 -0
- package/dist/infrastructure/oracle/price-cache.d.ts.map +1 -0
- package/dist/infrastructure/oracle/price-cache.js +173 -0
- package/dist/infrastructure/oracle/price-cache.js.map +1 -0
- package/dist/infrastructure/oracle/pyth-feed-ids.d.ts +31 -0
- package/dist/infrastructure/oracle/pyth-feed-ids.d.ts.map +1 -0
- package/dist/infrastructure/oracle/pyth-feed-ids.js +44 -0
- package/dist/infrastructure/oracle/pyth-feed-ids.js.map +1 -0
- package/dist/infrastructure/oracle/pyth-oracle.d.ts +69 -0
- package/dist/infrastructure/oracle/pyth-oracle.d.ts.map +1 -0
- package/dist/infrastructure/oracle/pyth-oracle.js +149 -0
- package/dist/infrastructure/oracle/pyth-oracle.js.map +1 -0
- package/dist/infrastructure/settings/hot-reload.d.ts +71 -0
- package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -0
- package/dist/infrastructure/settings/hot-reload.js +315 -0
- package/dist/infrastructure/settings/hot-reload.js.map +1 -0
- package/dist/infrastructure/settings/index.d.ts +13 -0
- package/dist/infrastructure/settings/index.d.ts.map +1 -0
- package/dist/infrastructure/settings/index.js +10 -0
- package/dist/infrastructure/settings/index.js.map +1 -0
- package/dist/infrastructure/settings/setting-keys.d.ts +28 -0
- package/dist/infrastructure/settings/setting-keys.d.ts.map +1 -0
- package/dist/infrastructure/settings/setting-keys.js +105 -0
- package/dist/infrastructure/settings/setting-keys.js.map +1 -0
- package/dist/infrastructure/settings/settings-crypto.d.ts +39 -0
- package/dist/infrastructure/settings/settings-crypto.d.ts.map +1 -0
- package/dist/infrastructure/settings/settings-crypto.js +73 -0
- package/dist/infrastructure/settings/settings-crypto.js.map +1 -0
- package/dist/infrastructure/settings/settings-service.d.ts +82 -0
- package/dist/infrastructure/settings/settings-service.d.ts.map +1 -0
- package/dist/infrastructure/settings/settings-service.js +267 -0
- package/dist/infrastructure/settings/settings-service.js.map +1 -0
- package/dist/infrastructure/telegram/index.d.ts +6 -0
- package/dist/infrastructure/telegram/index.d.ts.map +1 -0
- package/dist/infrastructure/telegram/index.js +5 -0
- package/dist/infrastructure/telegram/index.js.map +1 -0
- package/dist/infrastructure/telegram/telegram-api.d.ts +35 -0
- package/dist/infrastructure/telegram/telegram-api.d.ts.map +1 -0
- package/dist/infrastructure/telegram/telegram-api.js +82 -0
- package/dist/infrastructure/telegram/telegram-api.js.map +1 -0
- package/dist/infrastructure/telegram/telegram-auth.d.ts +57 -0
- package/dist/infrastructure/telegram/telegram-auth.d.ts.map +1 -0
- package/dist/infrastructure/telegram/telegram-auth.js +88 -0
- package/dist/infrastructure/telegram/telegram-auth.js.map +1 -0
- package/dist/infrastructure/telegram/telegram-bot-service.d.ts +95 -0
- package/dist/infrastructure/telegram/telegram-bot-service.d.ts.map +1 -0
- package/dist/infrastructure/telegram/telegram-bot-service.js +564 -0
- package/dist/infrastructure/telegram/telegram-bot-service.js.map +1 -0
- package/dist/infrastructure/telegram/telegram-keyboard.d.ts +27 -0
- package/dist/infrastructure/telegram/telegram-keyboard.d.ts.map +1 -0
- package/dist/infrastructure/telegram/telegram-keyboard.js +52 -0
- package/dist/infrastructure/telegram/telegram-keyboard.js.map +1 -0
- package/dist/infrastructure/telegram/telegram-types.d.ts +43 -0
- package/dist/infrastructure/telegram/telegram-types.d.ts.map +1 -0
- package/dist/infrastructure/telegram/telegram-types.js +8 -0
- package/dist/infrastructure/telegram/telegram-types.js.map +1 -0
- package/dist/infrastructure/token-registry/builtin-tokens.d.ts +39 -0
- package/dist/infrastructure/token-registry/builtin-tokens.d.ts.map +1 -0
- package/dist/infrastructure/token-registry/builtin-tokens.js +135 -0
- package/dist/infrastructure/token-registry/builtin-tokens.js.map +1 -0
- package/dist/infrastructure/token-registry/index.d.ts +8 -0
- package/dist/infrastructure/token-registry/index.d.ts.map +1 -0
- package/dist/infrastructure/token-registry/index.js +8 -0
- package/dist/infrastructure/token-registry/index.js.map +1 -0
- package/dist/infrastructure/token-registry/token-registry-service.d.ts +49 -0
- package/dist/infrastructure/token-registry/token-registry-service.d.ts.map +1 -0
- package/dist/infrastructure/token-registry/token-registry-service.js +93 -0
- package/dist/infrastructure/token-registry/token-registry-service.js.map +1 -0
- package/dist/infrastructure/version/index.d.ts +5 -0
- package/dist/infrastructure/version/index.d.ts.map +1 -0
- package/dist/infrastructure/version/index.js +5 -0
- package/dist/infrastructure/version/index.js.map +1 -0
- package/dist/infrastructure/version/version-check-service.d.ts +35 -0
- package/dist/infrastructure/version/version-check-service.d.ts.map +1 -0
- package/dist/infrastructure/version/version-check-service.js +92 -0
- package/dist/infrastructure/version/version-check-service.js.map +1 -0
- package/dist/lifecycle/daemon.d.ts +103 -0
- package/dist/lifecycle/daemon.d.ts.map +1 -0
- package/dist/lifecycle/daemon.js +934 -0
- package/dist/lifecycle/daemon.js.map +1 -0
- package/dist/lifecycle/index.d.ts +9 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +9 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/lifecycle/signal-handler.d.ts +18 -0
- package/dist/lifecycle/signal-handler.d.ts.map +1 -0
- package/dist/lifecycle/signal-handler.js +37 -0
- package/dist/lifecycle/signal-handler.js.map +1 -0
- package/dist/lifecycle/workers.d.ts +46 -0
- package/dist/lifecycle/workers.d.ts.map +1 -0
- package/dist/lifecycle/workers.js +101 -0
- package/dist/lifecycle/workers.js.map +1 -0
- package/dist/notifications/channels/discord.d.ts +10 -0
- package/dist/notifications/channels/discord.d.ts.map +1 -0
- package/dist/notifications/channels/discord.js +54 -0
- package/dist/notifications/channels/discord.js.map +1 -0
- package/dist/notifications/channels/ntfy.d.ts +13 -0
- package/dist/notifications/channels/ntfy.d.ts.map +1 -0
- package/dist/notifications/channels/ntfy.js +58 -0
- package/dist/notifications/channels/ntfy.js.map +1 -0
- package/dist/notifications/channels/slack.d.ts +10 -0
- package/dist/notifications/channels/slack.d.ts.map +1 -0
- package/dist/notifications/channels/slack.js +55 -0
- package/dist/notifications/channels/slack.js.map +1 -0
- package/dist/notifications/channels/telegram.d.ts +10 -0
- package/dist/notifications/channels/telegram.d.ts.map +1 -0
- package/dist/notifications/channels/telegram.js +40 -0
- package/dist/notifications/channels/telegram.js.map +1 -0
- package/dist/notifications/index.d.ts +9 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +7 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/notification-service.d.ts +75 -0
- package/dist/notifications/notification-service.d.ts.map +1 -0
- package/dist/notifications/notification-service.js +213 -0
- package/dist/notifications/notification-service.js.map +1 -0
- package/dist/notifications/templates/message-templates.d.ts +12 -0
- package/dist/notifications/templates/message-templates.d.ts.map +1 -0
- package/dist/notifications/templates/message-templates.js +22 -0
- package/dist/notifications/templates/message-templates.js.map +1 -0
- package/dist/pipeline/database-policy-engine.d.ts +286 -0
- package/dist/pipeline/database-policy-engine.d.ts.map +1 -0
- package/dist/pipeline/database-policy-engine.js +992 -0
- package/dist/pipeline/database-policy-engine.js.map +1 -0
- package/dist/pipeline/default-policy-engine.d.ts +26 -0
- package/dist/pipeline/default-policy-engine.d.ts.map +1 -0
- package/dist/pipeline/default-policy-engine.js +25 -0
- package/dist/pipeline/default-policy-engine.js.map +1 -0
- package/dist/pipeline/index.d.ts +9 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +9 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/network-resolver.d.ts +22 -0
- package/dist/pipeline/network-resolver.d.ts.map +1 -0
- package/dist/pipeline/network-resolver.js +32 -0
- package/dist/pipeline/network-resolver.js.map +1 -0
- package/dist/pipeline/pipeline.d.ts +72 -0
- package/dist/pipeline/pipeline.d.ts.map +1 -0
- package/dist/pipeline/pipeline.js +87 -0
- package/dist/pipeline/pipeline.js.map +1 -0
- package/dist/pipeline/resolve-effective-amount-usd.d.ts +41 -0
- package/dist/pipeline/resolve-effective-amount-usd.d.ts.map +1 -0
- package/dist/pipeline/resolve-effective-amount-usd.js +208 -0
- package/dist/pipeline/resolve-effective-amount-usd.js.map +1 -0
- package/dist/pipeline/sign-only.d.ts +99 -0
- package/dist/pipeline/sign-only.d.ts.map +1 -0
- package/dist/pipeline/sign-only.js +267 -0
- package/dist/pipeline/sign-only.js.map +1 -0
- package/dist/pipeline/sleep.d.ts +6 -0
- package/dist/pipeline/sleep.d.ts.map +1 -0
- package/dist/pipeline/sleep.js +8 -0
- package/dist/pipeline/sleep.js.map +1 -0
- package/dist/pipeline/stages.d.ts +82 -0
- package/dist/pipeline/stages.d.ts.map +1 -0
- package/dist/pipeline/stages.js +784 -0
- package/dist/pipeline/stages.js.map +1 -0
- package/dist/services/autostop-rules.d.ts +79 -0
- package/dist/services/autostop-rules.d.ts.map +1 -0
- package/dist/services/autostop-rules.js +174 -0
- package/dist/services/autostop-rules.js.map +1 -0
- package/dist/services/autostop-service.d.ts +82 -0
- package/dist/services/autostop-service.d.ts.map +1 -0
- package/dist/services/autostop-service.js +223 -0
- package/dist/services/autostop-service.js.map +1 -0
- package/dist/services/kill-switch-service.d.ts +118 -0
- package/dist/services/kill-switch-service.d.ts.map +1 -0
- package/dist/services/kill-switch-service.js +291 -0
- package/dist/services/kill-switch-service.js.map +1 -0
- package/dist/services/monitoring/balance-monitor-service.d.ts +65 -0
- package/dist/services/monitoring/balance-monitor-service.d.ts.map +1 -0
- package/dist/services/monitoring/balance-monitor-service.js +207 -0
- package/dist/services/monitoring/balance-monitor-service.js.map +1 -0
- package/dist/services/wc-session-service.d.ts +123 -0
- package/dist/services/wc-session-service.d.ts.map +1 -0
- package/dist/services/wc-session-service.js +363 -0
- package/dist/services/wc-session-service.js.map +1 -0
- package/dist/services/wc-signing-bridge.d.ts +60 -0
- package/dist/services/wc-signing-bridge.d.ts.map +1 -0
- package/dist/services/wc-signing-bridge.js +334 -0
- package/dist/services/wc-signing-bridge.js.map +1 -0
- package/dist/services/wc-storage.d.ts +32 -0
- package/dist/services/wc-storage.d.ts.map +1 -0
- package/dist/services/wc-storage.js +64 -0
- package/dist/services/wc-storage.js.map +1 -0
- package/dist/services/x402/payment-signer.d.ts +88 -0
- package/dist/services/x402/payment-signer.d.ts.map +1 -0
- package/dist/services/x402/payment-signer.js +311 -0
- package/dist/services/x402/payment-signer.js.map +1 -0
- package/dist/services/x402/ssrf-guard.d.ts +27 -0
- package/dist/services/x402/ssrf-guard.d.ts.map +1 -0
- package/dist/services/x402/ssrf-guard.js +236 -0
- package/dist/services/x402/ssrf-guard.js.map +1 -0
- package/dist/services/x402/x402-domain-policy.d.ts +50 -0
- package/dist/services/x402/x402-domain-policy.d.ts.map +1 -0
- package/dist/services/x402/x402-domain-policy.js +78 -0
- package/dist/services/x402/x402-domain-policy.js.map +1 -0
- package/dist/services/x402/x402-handler.d.ts +71 -0
- package/dist/services/x402/x402-handler.d.ts.map +1 -0
- package/dist/services/x402/x402-handler.js +195 -0
- package/dist/services/x402/x402-handler.js.map +1 -0
- package/dist/services/x402/x402-usd-resolver.d.ts +26 -0
- package/dist/services/x402/x402-usd-resolver.d.ts.map +1 -0
- package/dist/services/x402/x402-usd-resolver.js +79 -0
- package/dist/services/x402/x402-usd-resolver.js.map +1 -0
- package/dist/workflow/approval-workflow.d.ts +103 -0
- package/dist/workflow/approval-workflow.d.ts.map +1 -0
- package/dist/workflow/approval-workflow.js +202 -0
- package/dist/workflow/approval-workflow.js.map +1 -0
- package/dist/workflow/delay-queue.d.ts +78 -0
- package/dist/workflow/delay-queue.d.ts.map +1 -0
- package/dist/workflow/delay-queue.js +174 -0
- package/dist/workflow/delay-queue.js.map +1 -0
- package/dist/workflow/index.d.ts +11 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +9 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow/owner-state.d.ts +97 -0
- package/dist/workflow/owner-state.d.ts.map +1 -0
- package/dist/workflow/owner-state.js +168 -0
- package/dist/workflow/owner-state.js.map +1 -0
- package/package.json +71 -0
- package/public/admin/assets/index-BPoUSH8W.css +1 -0
- package/public/admin/assets/index-CDi1qoXB.js +1 -0
- package/public/admin/index.html +13 -0
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// matchDomain
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/**
|
|
20
|
+
* Match a domain pattern against a target domain.
|
|
21
|
+
*
|
|
22
|
+
* Rules:
|
|
23
|
+
* - "api.example.com" -> exact match only
|
|
24
|
+
* - "*.example.com" -> matches sub.example.com, a.b.example.com
|
|
25
|
+
* does NOT match example.com (dot-boundary)
|
|
26
|
+
* - Case-insensitive comparison
|
|
27
|
+
*
|
|
28
|
+
* @param pattern - Domain pattern (exact or wildcard like "*.example.com")
|
|
29
|
+
* @param target - Target domain to match against
|
|
30
|
+
* @returns true if pattern matches target
|
|
31
|
+
*/
|
|
32
|
+
export function matchDomain(pattern, target) {
|
|
33
|
+
const p = pattern.toLowerCase();
|
|
34
|
+
const t = target.toLowerCase();
|
|
35
|
+
// Exact match
|
|
36
|
+
if (p === t)
|
|
37
|
+
return true;
|
|
38
|
+
// Wildcard match: *.example.com
|
|
39
|
+
if (p.startsWith('*.')) {
|
|
40
|
+
const suffix = p.slice(1); // ".example.com"
|
|
41
|
+
// target must end with suffix AND be longer (dot-boundary: excludes root domain)
|
|
42
|
+
return t.endsWith(suffix) && t.length > suffix.length;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// evaluateX402Domain
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
/**
|
|
50
|
+
* Evaluate X402_ALLOWED_DOMAINS policy against a target domain.
|
|
51
|
+
*
|
|
52
|
+
* @param resolved - Resolved policy rows (after override resolution)
|
|
53
|
+
* @param targetDomain - The domain to evaluate (e.g., "api.example.com")
|
|
54
|
+
* @returns PolicyEvaluation with allowed=false if denied, null if allowed (continue to next evaluation)
|
|
55
|
+
*/
|
|
56
|
+
export function evaluateX402Domain(resolved, targetDomain) {
|
|
57
|
+
const policy = resolved.find((p) => p.type === 'X402_ALLOWED_DOMAINS');
|
|
58
|
+
// No policy -> default deny (same pattern as ALLOWED_TOKENS)
|
|
59
|
+
if (!policy) {
|
|
60
|
+
return {
|
|
61
|
+
allowed: false,
|
|
62
|
+
tier: 'INSTANT',
|
|
63
|
+
reason: 'x402 payments disabled: no X402_ALLOWED_DOMAINS policy configured',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const rules = JSON.parse(policy.rules);
|
|
67
|
+
// Check if domain is in allowed list
|
|
68
|
+
const isAllowed = rules.domains.some((domainPattern) => matchDomain(domainPattern, targetDomain));
|
|
69
|
+
if (!isAllowed) {
|
|
70
|
+
return {
|
|
71
|
+
allowed: false,
|
|
72
|
+
tier: 'INSTANT',
|
|
73
|
+
reason: `Domain '${targetDomain}' not in allowed x402 domains list`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return null; // Domain allowed, continue to next evaluation
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=x402-domain-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-domain-policy.js","sourceRoot":"","sources":["../../../src/services/x402/x402-domain-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwBH,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,MAAc;IACzD,MAAM,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,WAAW,YAAY,oCAAoC;SACpE,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,8CAA8C;AAC7D,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 Handler -- orchestrates SSRF guard + payment signing + 402 response handling.
|
|
3
|
+
*
|
|
4
|
+
* Independent pipeline (does NOT extend 6-stage pipeline):
|
|
5
|
+
* 1. SSRF guard (validateUrlSafety)
|
|
6
|
+
* 2. HTTP request (safeFetchWithRedirects)
|
|
7
|
+
* 3. Non-402 passthrough
|
|
8
|
+
* 4. 402 response parsing (PAYMENT-REQUIRED header -> PaymentRequired V2)
|
|
9
|
+
* 5. (scheme, network) auto-selection from accepts array
|
|
10
|
+
* 6. Payment signing (signPayment)
|
|
11
|
+
* 7. Re-request with PAYMENT-SIGNATURE header
|
|
12
|
+
* 8. Retry limit: 1 retry after payment, then X402_PAYMENT_REJECTED
|
|
13
|
+
*
|
|
14
|
+
* @module x402-handler
|
|
15
|
+
*/
|
|
16
|
+
import type { X402FetchRequest, X402FetchResponse, PaymentRequirements } from '@waiaas/core';
|
|
17
|
+
/** Dependencies injected into the x402 handler. */
|
|
18
|
+
export interface X402HandlerDeps {
|
|
19
|
+
keyStore: {
|
|
20
|
+
decryptPrivateKey(walletId: string, masterPassword: string): Promise<Uint8Array>;
|
|
21
|
+
releaseKey(key: Uint8Array): void;
|
|
22
|
+
};
|
|
23
|
+
walletId: string;
|
|
24
|
+
walletAddress: string;
|
|
25
|
+
masterPassword: string;
|
|
26
|
+
supportedNetworks: Set<string>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Fetch a URL with x402 payment handling.
|
|
30
|
+
*
|
|
31
|
+
* Flow:
|
|
32
|
+
* 1. Validate URL safety (SSRF guard)
|
|
33
|
+
* 2. Make initial request
|
|
34
|
+
* 3. If non-402: return passthrough response
|
|
35
|
+
* 4. If 402: parse payment requirements, select best option, sign, re-request
|
|
36
|
+
* 5. If re-request returns 402: throw X402_PAYMENT_REJECTED (1 retry max)
|
|
37
|
+
* 6. If re-request returns non-ok: throw X402_SERVER_ERROR
|
|
38
|
+
* 7. If re-request returns ok: return payment response
|
|
39
|
+
*/
|
|
40
|
+
export declare function handleX402Fetch(request: X402FetchRequest, deps: X402HandlerDeps): Promise<X402FetchResponse>;
|
|
41
|
+
/** Parsed PaymentRequired V2 structure. */
|
|
42
|
+
interface ParsedPaymentRequired {
|
|
43
|
+
x402Version: number;
|
|
44
|
+
accepts: PaymentRequirements[];
|
|
45
|
+
resource: {
|
|
46
|
+
url: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse a 402 response into PaymentRequired V2 structure.
|
|
51
|
+
*
|
|
52
|
+
* Attempts to parse from:
|
|
53
|
+
* 1. PAYMENT-REQUIRED header (base64-encoded JSON)
|
|
54
|
+
* 2. Response body (JSON)
|
|
55
|
+
*
|
|
56
|
+
* Validates against PaymentRequiredV2Schema (Zod).
|
|
57
|
+
*/
|
|
58
|
+
export declare function parse402Response(response: Response): Promise<ParsedPaymentRequired>;
|
|
59
|
+
/**
|
|
60
|
+
* Select the best PaymentRequirements from an accepts array.
|
|
61
|
+
*
|
|
62
|
+
* Criteria:
|
|
63
|
+
* 1. scheme must be 'exact' (streaming/other schemes not supported)
|
|
64
|
+
* 2. network must be in supportedNetworks AND resolvable via resolveX402Network
|
|
65
|
+
* 3. Among matching items, select the one with lowest amount
|
|
66
|
+
*
|
|
67
|
+
* @throws WAIaaSError('X402_UNSUPPORTED_SCHEME') if no matching requirement found
|
|
68
|
+
*/
|
|
69
|
+
export declare function selectPaymentRequirement(accepts: PaymentRequirements[], supportedNetworks: Set<string>): PaymentRequirements;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=x402-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-handler.d.ts","sourceRoot":"","sources":["../../../src/services/x402/x402-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAEjB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAQtB,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE;QACR,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACjF,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,CAAC;KACnC,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAChC;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAmE5B;AAMD,2CAA2C;AAC3C,UAAU,qBAAqB;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,qBAAqB,CAAC,CAoBhC;AAMD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,mBAAmB,EAAE,EAC9B,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,GAC7B,mBAAmB,CA6BrB"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 Handler -- orchestrates SSRF guard + payment signing + 402 response handling.
|
|
3
|
+
*
|
|
4
|
+
* Independent pipeline (does NOT extend 6-stage pipeline):
|
|
5
|
+
* 1. SSRF guard (validateUrlSafety)
|
|
6
|
+
* 2. HTTP request (safeFetchWithRedirects)
|
|
7
|
+
* 3. Non-402 passthrough
|
|
8
|
+
* 4. 402 response parsing (PAYMENT-REQUIRED header -> PaymentRequired V2)
|
|
9
|
+
* 5. (scheme, network) auto-selection from accepts array
|
|
10
|
+
* 6. Payment signing (signPayment)
|
|
11
|
+
* 7. Re-request with PAYMENT-SIGNATURE header
|
|
12
|
+
* 8. Retry limit: 1 retry after payment, then X402_PAYMENT_REJECTED
|
|
13
|
+
*
|
|
14
|
+
* @module x402-handler
|
|
15
|
+
*/
|
|
16
|
+
import { WAIaaSError, PaymentRequiredV2Schema, resolveX402Network, } from '@waiaas/core';
|
|
17
|
+
import { validateUrlSafety, safeFetchWithRedirects } from './ssrf-guard.js';
|
|
18
|
+
import { signPayment } from './payment-signer.js';
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Base64 JSON encode/decode (equivalent to @x402/core/http helpers)
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Encode a PaymentPayload as a base64 header value.
|
|
24
|
+
* Equivalent to @x402/core/http encodePaymentSignatureHeader.
|
|
25
|
+
*/
|
|
26
|
+
function encodePaymentSignatureHeader(paymentPayload) {
|
|
27
|
+
const json = JSON.stringify(paymentPayload);
|
|
28
|
+
return Buffer.from(json, 'utf-8').toString('base64');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decode a base64 PAYMENT-REQUIRED header into a PaymentRequired object.
|
|
32
|
+
* Equivalent to @x402/core/http decodePaymentRequiredHeader.
|
|
33
|
+
*/
|
|
34
|
+
function decodePaymentRequiredHeader(headerValue) {
|
|
35
|
+
const decoded = Buffer.from(headerValue, 'base64').toString('utf-8');
|
|
36
|
+
return JSON.parse(decoded);
|
|
37
|
+
}
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// handleX402Fetch -- main entry point
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
/**
|
|
42
|
+
* Fetch a URL with x402 payment handling.
|
|
43
|
+
*
|
|
44
|
+
* Flow:
|
|
45
|
+
* 1. Validate URL safety (SSRF guard)
|
|
46
|
+
* 2. Make initial request
|
|
47
|
+
* 3. If non-402: return passthrough response
|
|
48
|
+
* 4. If 402: parse payment requirements, select best option, sign, re-request
|
|
49
|
+
* 5. If re-request returns 402: throw X402_PAYMENT_REJECTED (1 retry max)
|
|
50
|
+
* 6. If re-request returns non-ok: throw X402_SERVER_ERROR
|
|
51
|
+
* 7. If re-request returns ok: return payment response
|
|
52
|
+
*/
|
|
53
|
+
export async function handleX402Fetch(request, deps) {
|
|
54
|
+
// Step 1: SSRF guard
|
|
55
|
+
const validatedUrl = await validateUrlSafety(request.url);
|
|
56
|
+
// Step 2: Initial request
|
|
57
|
+
const response = await safeFetchWithRedirects(validatedUrl, request.method ?? 'GET', request.headers, request.body);
|
|
58
|
+
// Step 3: Non-402 passthrough
|
|
59
|
+
if (response.status !== 402) {
|
|
60
|
+
return buildPassthroughResponse(response);
|
|
61
|
+
}
|
|
62
|
+
// Step 4: Parse 402 response
|
|
63
|
+
const paymentRequired = await parse402Response(response);
|
|
64
|
+
// Step 5: Select best (scheme, network) from accepts
|
|
65
|
+
const selected = selectPaymentRequirement(paymentRequired.accepts, deps.supportedNetworks);
|
|
66
|
+
// Step 6: Sign payment
|
|
67
|
+
const paymentPayload = await signPayment(selected, deps.keyStore, deps.walletId, deps.walletAddress, deps.masterPassword);
|
|
68
|
+
// Fill resource.url in the payment payload
|
|
69
|
+
paymentPayload.resource = { url: request.url };
|
|
70
|
+
// Step 7: Encode and re-request with PAYMENT-SIGNATURE header
|
|
71
|
+
const encodedSignature = encodePaymentSignatureHeader(paymentPayload);
|
|
72
|
+
const retryHeaders = {
|
|
73
|
+
...(request.headers ?? {}),
|
|
74
|
+
'PAYMENT-SIGNATURE': encodedSignature,
|
|
75
|
+
};
|
|
76
|
+
const retryResponse = await safeFetchWithRedirects(validatedUrl, request.method ?? 'GET', retryHeaders, request.body);
|
|
77
|
+
// Step 8: Handle retry response
|
|
78
|
+
if (retryResponse.status === 402) {
|
|
79
|
+
throw new WAIaaSError('X402_PAYMENT_REJECTED', {
|
|
80
|
+
message: 'Payment was rejected by the resource server after retry',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!retryResponse.ok) {
|
|
84
|
+
throw new WAIaaSError('X402_SERVER_ERROR', {
|
|
85
|
+
message: `Resource server returned ${retryResponse.status} after payment`,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Step 9: Build success response with payment info
|
|
89
|
+
return buildPaymentResponse(retryResponse, selected);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse a 402 response into PaymentRequired V2 structure.
|
|
93
|
+
*
|
|
94
|
+
* Attempts to parse from:
|
|
95
|
+
* 1. PAYMENT-REQUIRED header (base64-encoded JSON)
|
|
96
|
+
* 2. Response body (JSON)
|
|
97
|
+
*
|
|
98
|
+
* Validates against PaymentRequiredV2Schema (Zod).
|
|
99
|
+
*/
|
|
100
|
+
export async function parse402Response(response) {
|
|
101
|
+
let raw;
|
|
102
|
+
// Try header first
|
|
103
|
+
const headerValue = response.headers.get('payment-required');
|
|
104
|
+
if (headerValue) {
|
|
105
|
+
raw = decodePaymentRequiredHeader(headerValue);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Fallback: JSON body
|
|
109
|
+
raw = await response.json();
|
|
110
|
+
}
|
|
111
|
+
// Validate with Zod
|
|
112
|
+
const parsed = PaymentRequiredV2Schema.parse(raw);
|
|
113
|
+
return {
|
|
114
|
+
x402Version: parsed.x402Version,
|
|
115
|
+
accepts: parsed.accepts,
|
|
116
|
+
resource: parsed.resource,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// selectPaymentRequirement
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
/**
|
|
123
|
+
* Select the best PaymentRequirements from an accepts array.
|
|
124
|
+
*
|
|
125
|
+
* Criteria:
|
|
126
|
+
* 1. scheme must be 'exact' (streaming/other schemes not supported)
|
|
127
|
+
* 2. network must be in supportedNetworks AND resolvable via resolveX402Network
|
|
128
|
+
* 3. Among matching items, select the one with lowest amount
|
|
129
|
+
*
|
|
130
|
+
* @throws WAIaaSError('X402_UNSUPPORTED_SCHEME') if no matching requirement found
|
|
131
|
+
*/
|
|
132
|
+
export function selectPaymentRequirement(accepts, supportedNetworks) {
|
|
133
|
+
// Filter for exact scheme + supported network
|
|
134
|
+
const candidates = accepts.filter((req) => {
|
|
135
|
+
if (req.scheme !== 'exact')
|
|
136
|
+
return false;
|
|
137
|
+
if (!supportedNetworks.has(req.network))
|
|
138
|
+
return false;
|
|
139
|
+
// Verify network is known to WAIaaS
|
|
140
|
+
try {
|
|
141
|
+
resolveX402Network(req.network);
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (candidates.length === 0) {
|
|
149
|
+
throw new WAIaaSError('X402_UNSUPPORTED_SCHEME', {
|
|
150
|
+
message: 'No supported (scheme=exact, network) pair found in accepts',
|
|
151
|
+
details: {
|
|
152
|
+
available: accepts.map((a) => ({ scheme: a.scheme, network: a.network })),
|
|
153
|
+
supported: [...supportedNetworks],
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// Select lowest amount
|
|
158
|
+
return candidates.reduce((min, req) => BigInt(req.amount) < BigInt(min.amount) ? req : min);
|
|
159
|
+
}
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Response builders
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
/**
|
|
164
|
+
* Build a passthrough X402FetchResponse from a non-402 response.
|
|
165
|
+
*/
|
|
166
|
+
async function buildPassthroughResponse(response) {
|
|
167
|
+
const body = await response.text();
|
|
168
|
+
const headers = {};
|
|
169
|
+
response.headers.forEach((value, key) => {
|
|
170
|
+
headers[key] = value;
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
status: response.status,
|
|
174
|
+
headers,
|
|
175
|
+
body,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Build a payment X402FetchResponse from a successful retry response.
|
|
180
|
+
*/
|
|
181
|
+
async function buildPaymentResponse(response, requirement) {
|
|
182
|
+
const base = await buildPassthroughResponse(response);
|
|
183
|
+
const payment = {
|
|
184
|
+
amount: requirement.amount,
|
|
185
|
+
asset: requirement.asset,
|
|
186
|
+
network: requirement.network,
|
|
187
|
+
payTo: requirement.payTo,
|
|
188
|
+
txId: '', // Not yet available -- facilitator settles asynchronously
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
...base,
|
|
192
|
+
payment,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=x402-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-handler.js","sourceRoot":"","sources":["../../../src/services/x402/x402-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAkBlD,8EAA8E;AAC9E,oEAAoE;AACpE,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,4BAA4B,CAAC,cAAuC;IAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvD,CAA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AC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CACpD,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E;;GAEG;AACH,KAAK,UAAU,wBAAwB,CACrC,QAAkB;IAElB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,oBAAoB,CACjC,QAAkB,EAClB,WAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAEtD,MAAM,OAAO,GAAoB;QAC/B,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,IAAI,EAAE,EAAE,EAAE,0DAA0D;KACrE,CAAC;IAEF,OAAO;QACL,GAAG,IAAI;QACP,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 payment amount USD resolution.
|
|
3
|
+
*
|
|
4
|
+
* Converts x402 PaymentRequirements amounts to USD for SPENDING_LIMIT policy evaluation.
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* - USDC (6 decimals, $1 peg): Direct conversion without oracle call.
|
|
8
|
+
* USDC addresses come from USDC_DOMAINS (EVM) and SOLANA_USDC_ADDRESSES (Solana).
|
|
9
|
+
* - Non-USDC tokens: IPriceOracle.getPrice() with chain-appropriate default decimals.
|
|
10
|
+
* - No oracle / oracle error: Returns 0 (safe fallback, allows INSTANT tier pass).
|
|
11
|
+
*
|
|
12
|
+
* @see packages/daemon/src/pipeline/resolve-effective-amount-usd.ts (5-type pattern)
|
|
13
|
+
* @see packages/daemon/src/services/x402/payment-signer.ts (USDC_DOMAINS)
|
|
14
|
+
*/
|
|
15
|
+
import type { IPriceOracle } from '@waiaas/core';
|
|
16
|
+
/**
|
|
17
|
+
* Resolve x402 payment amount to USD value.
|
|
18
|
+
*
|
|
19
|
+
* @param amount - Raw token amount (string, integer units)
|
|
20
|
+
* @param asset - Token contract/mint address
|
|
21
|
+
* @param caip2Network - CAIP-2 network identifier (e.g., "eip155:8453", "solana:5eykt4...")
|
|
22
|
+
* @param priceOracle - Optional IPriceOracle for non-USDC tokens
|
|
23
|
+
* @returns USD amount (number). Returns 0 if price cannot be determined (safe fallback).
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveX402UsdAmount(amount: string, asset: string, caip2Network: string, priceOracle?: IPriceOracle): Promise<number>;
|
|
26
|
+
//# sourceMappingURL=x402-usd-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-usd-resolver.d.ts","sourceRoot":"","sources":["../../../src/services/x402/x402-usd-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAwBjD;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,MAAM,CAAC,CAoCjB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 payment amount USD resolution.
|
|
3
|
+
*
|
|
4
|
+
* Converts x402 PaymentRequirements amounts to USD for SPENDING_LIMIT policy evaluation.
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* - USDC (6 decimals, $1 peg): Direct conversion without oracle call.
|
|
8
|
+
* USDC addresses come from USDC_DOMAINS (EVM) and SOLANA_USDC_ADDRESSES (Solana).
|
|
9
|
+
* - Non-USDC tokens: IPriceOracle.getPrice() with chain-appropriate default decimals.
|
|
10
|
+
* - No oracle / oracle error: Returns 0 (safe fallback, allows INSTANT tier pass).
|
|
11
|
+
*
|
|
12
|
+
* @see packages/daemon/src/pipeline/resolve-effective-amount-usd.ts (5-type pattern)
|
|
13
|
+
* @see packages/daemon/src/services/x402/payment-signer.ts (USDC_DOMAINS)
|
|
14
|
+
*/
|
|
15
|
+
import { USDC_DOMAINS } from './payment-signer.js';
|
|
16
|
+
import { parseCaip2 } from '@waiaas/core';
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Solana USDC addresses (not in USDC_DOMAINS which is EVM-only EIP-712)
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Known Solana USDC token mint addresses by CAIP-2 network.
|
|
22
|
+
*
|
|
23
|
+
* Circle native USDC on Solana uses SPL Token, not EIP-3009,
|
|
24
|
+
* so these are separate from USDC_DOMAINS (which stores EIP-712 domain separators).
|
|
25
|
+
*/
|
|
26
|
+
const SOLANA_USDC_ADDRESSES = {
|
|
27
|
+
// Solana Mainnet (Circle native USDC)
|
|
28
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
29
|
+
// Solana Devnet (Circle USDC devnet)
|
|
30
|
+
'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1': '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',
|
|
31
|
+
};
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// resolveX402UsdAmount
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/**
|
|
36
|
+
* Resolve x402 payment amount to USD value.
|
|
37
|
+
*
|
|
38
|
+
* @param amount - Raw token amount (string, integer units)
|
|
39
|
+
* @param asset - Token contract/mint address
|
|
40
|
+
* @param caip2Network - CAIP-2 network identifier (e.g., "eip155:8453", "solana:5eykt4...")
|
|
41
|
+
* @param priceOracle - Optional IPriceOracle for non-USDC tokens
|
|
42
|
+
* @returns USD amount (number). Returns 0 if price cannot be determined (safe fallback).
|
|
43
|
+
*/
|
|
44
|
+
export async function resolveX402UsdAmount(amount, asset, caip2Network, priceOracle) {
|
|
45
|
+
// 1. Check EVM USDC (USDC_DOMAINS has verifyingContract for 7 EVM chains)
|
|
46
|
+
const usdcDomain = USDC_DOMAINS[caip2Network];
|
|
47
|
+
if (usdcDomain && usdcDomain.verifyingContract.toLowerCase() === asset.toLowerCase()) {
|
|
48
|
+
// USDC: 6 decimals, $1 direct conversion
|
|
49
|
+
return Number(amount) / 1_000_000;
|
|
50
|
+
}
|
|
51
|
+
// 2. Check Solana USDC (separate address table, case-sensitive for base58)
|
|
52
|
+
const solanaUsdcAddress = SOLANA_USDC_ADDRESSES[caip2Network];
|
|
53
|
+
if (solanaUsdcAddress && solanaUsdcAddress === asset) {
|
|
54
|
+
// Solana USDC: 6 decimals, $1 direct conversion
|
|
55
|
+
return Number(amount) / 1_000_000;
|
|
56
|
+
}
|
|
57
|
+
// 3. Non-USDC: use IPriceOracle (if available)
|
|
58
|
+
if (!priceOracle)
|
|
59
|
+
return 0;
|
|
60
|
+
const { namespace } = parseCaip2(caip2Network);
|
|
61
|
+
const chain = namespace === 'eip155' ? 'ethereum' : 'solana';
|
|
62
|
+
try {
|
|
63
|
+
// x402 PaymentRequirements does not include decimals, use chain defaults
|
|
64
|
+
// EVM: 18 (most common), Solana: 9 (most common)
|
|
65
|
+
const decimals = chain === 'ethereum' ? 18 : 9;
|
|
66
|
+
const priceInfo = await priceOracle.getPrice({
|
|
67
|
+
address: asset,
|
|
68
|
+
decimals,
|
|
69
|
+
chain: chain,
|
|
70
|
+
});
|
|
71
|
+
const humanAmount = Number(amount) / Math.pow(10, decimals);
|
|
72
|
+
return humanAmount * priceInfo.usdPrice;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Safe fallback: unknown price -> 0 (INSTANT tier pass)
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=x402-usd-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-usd-resolver.js","sourceRoot":"","sources":["../../../src/services/x402/x402-usd-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,qBAAqB,GAA2B;IACpD,sCAAsC;IACtC,yCAAyC,EAAE,8CAA8C;IACzF,qCAAqC;IACrC,yCAAyC,EAAE,8CAA8C;CAC1F,CAAC;AAEF,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,KAAa,EACb,YAAoB,EACpB,WAA0B;IAE1B,0EAA0E;IAC1E,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC9C,IAAI,UAAU,IAAI,UAAU,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;QACrF,yCAAyC;QACzC,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACpC,CAAC;IAED,2EAA2E;IAC3E,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAC9D,IAAI,iBAAiB,IAAI,iBAAiB,KAAK,KAAK,EAAE,CAAC;QACrD,gDAAgD;QAChD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACpC,CAAC;IAED,+CAA+C;IAC/C,IAAI,CAAC,WAAW;QAAE,OAAO,CAAC,CAAC;IAE3B,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE7D,IAAI,CAAC;QACH,yEAAyE;QACzE,iDAAiD;QACjD,MAAM,QAAQ,GAAG,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC;YAC3C,OAAO,EAAE,KAAK;YACd,QAAQ;YACR,KAAK,EAAE,KAA8B;SACtC,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC5D,OAAO,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,wDAAwD;QACxD,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
21
|
+
import type { Database as SQLiteDatabase } from 'better-sqlite3';
|
|
22
|
+
import type * as schema from '../infrastructure/database/schema.js';
|
|
23
|
+
interface ApprovalWorkflowDeps {
|
|
24
|
+
db: BetterSQLite3Database<typeof schema>;
|
|
25
|
+
sqlite: SQLiteDatabase;
|
|
26
|
+
config: {
|
|
27
|
+
policy_defaults_approval_timeout: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface RequestApprovalOptions {
|
|
31
|
+
policyTimeoutSeconds?: number;
|
|
32
|
+
}
|
|
33
|
+
interface RequestApprovalResult {
|
|
34
|
+
approvalId: string;
|
|
35
|
+
expiresAt: number;
|
|
36
|
+
}
|
|
37
|
+
interface ApproveResult {
|
|
38
|
+
txId: string;
|
|
39
|
+
approvedAt: number;
|
|
40
|
+
}
|
|
41
|
+
interface RejectResult {
|
|
42
|
+
txId: string;
|
|
43
|
+
rejectedAt: number;
|
|
44
|
+
}
|
|
45
|
+
export declare class ApprovalWorkflow {
|
|
46
|
+
private readonly sqlite;
|
|
47
|
+
private readonly configTimeout;
|
|
48
|
+
constructor(deps: ApprovalWorkflowDeps);
|
|
49
|
+
/**
|
|
50
|
+
* Create a pending approval for an APPROVAL tier transaction.
|
|
51
|
+
*
|
|
52
|
+
* Sets the transaction status to QUEUED and creates a pending_approvals
|
|
53
|
+
* record with an expiration time based on the 3-level timeout priority.
|
|
54
|
+
*
|
|
55
|
+
* @param txId - The transaction ID
|
|
56
|
+
* @param options - Optional policy-specific timeout
|
|
57
|
+
* @returns The approval ID and expiration timestamp
|
|
58
|
+
*/
|
|
59
|
+
requestApproval(txId: string, options?: RequestApprovalOptions): RequestApprovalResult;
|
|
60
|
+
/**
|
|
61
|
+
* Approve a pending APPROVAL transaction with owner signature.
|
|
62
|
+
*
|
|
63
|
+
* Atomically validates the approval, sets approvedAt + ownerSignature,
|
|
64
|
+
* transitions the transaction to EXECUTING, and clears reserved_amount.
|
|
65
|
+
*
|
|
66
|
+
* @param txId - The transaction ID
|
|
67
|
+
* @param ownerSignature - The owner's cryptographic signature
|
|
68
|
+
* @returns The transaction ID and approval timestamp
|
|
69
|
+
* @throws WAIaaSError APPROVAL_NOT_FOUND if no pending approval exists
|
|
70
|
+
* @throws WAIaaSError APPROVAL_TIMEOUT if the approval has expired
|
|
71
|
+
*/
|
|
72
|
+
approve(txId: string, ownerSignature: string): ApproveResult;
|
|
73
|
+
/**
|
|
74
|
+
* Reject a pending APPROVAL transaction.
|
|
75
|
+
*
|
|
76
|
+
* Atomically sets rejectedAt, transitions the transaction to CANCELLED,
|
|
77
|
+
* and clears reserved_amount.
|
|
78
|
+
*
|
|
79
|
+
* @param txId - The transaction ID
|
|
80
|
+
* @returns The transaction ID and rejection timestamp
|
|
81
|
+
* @throws WAIaaSError APPROVAL_NOT_FOUND if no pending approval exists
|
|
82
|
+
*/
|
|
83
|
+
reject(txId: string): RejectResult;
|
|
84
|
+
/**
|
|
85
|
+
* Batch-expire pending approvals that have exceeded their timeout.
|
|
86
|
+
*
|
|
87
|
+
* For each expired approval: sets the transaction status to EXPIRED and
|
|
88
|
+
* clears reserved_amount. Does NOT set rejectedAt (expired != rejected).
|
|
89
|
+
*
|
|
90
|
+
* @param now - Current Unix epoch seconds
|
|
91
|
+
* @returns Count of expired approvals
|
|
92
|
+
*/
|
|
93
|
+
processExpiredApprovals(now: number): number;
|
|
94
|
+
/**
|
|
95
|
+
* Resolve approval timeout with 3-level priority:
|
|
96
|
+
* 1. Policy-specific timeout (from options)
|
|
97
|
+
* 2. Config timeout (policy_defaults_approval_timeout)
|
|
98
|
+
* 3. 3600 hardcoded fallback
|
|
99
|
+
*/
|
|
100
|
+
private resolveTimeout;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=approval-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-workflow.d.ts","sourceRoot":"","sources":["../../src/workflow/approval-workflow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGjE,OAAO,KAAK,KAAK,MAAM,MAAM,sCAAsC,CAAC;AAapE,UAAU,oBAAoB;IAC5B,EAAE,EAAE,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE;QACN,gCAAgC,EAAE,MAAM,CAAC;KAC1C,CAAC;CACH;AAED,UAAU,sBAAsB;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,UAAU,qBAAqB;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAcD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,IAAI,EAAE,oBAAoB;IAStC;;;;;;;;;OASG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