trustbase-seller-backend 0.1.5
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/.agents/skills/wechatpay-payment-integration/SKILL.md +165 -0
- package/.agents/skills/wechatpay-payment-integration/references/APIv3/346/216/245/345/217/243/345/212/250/346/200/201/346/216/222/351/232/234.md +234 -0
- package/.agents/skills/wechatpay-payment-integration/references/wechatpay-dev-cli/344/275/277/347/224/250/350/257/264/346/230/216.md +74 -0
- package/.agents/skills/wechatpay-payment-integration/references//345/237/272/347/241/200/346/246/202/345/277/265/345/217/212/344/270/232/345/212/241/344/273/213/347/273/215.md +109 -0
- package/.agents/skills/wechatpay-payment-integration/references//345/246/202/344/275/225/347/220/206/350/247/243/347/224/250/346/210/267/351/227/256/351/242/230.md +55 -0
- package/.agents/skills/wechatpay-payment-integration/references//346/216/245/345/205/245/350/264/250/351/207/217/346/243/200/346/237/245/346/270/205/345/215/225.md +70 -0
- package/.agents/skills/wechatpay-payment-integration/references//346/226/207/346/241/243/346/243/200/347/264/242/344/270/216/351/227/256/347/255/224.md +99 -0
- package/.agents/skills/wechatpay-payment-integration/scripts/bash/extract_and_sign.sh +231 -0
- package/.agents/skills/wechatpay-payment-integration/scripts/powershell/extract_and_sign.ps1 +199 -0
- package/.agents/skills/wechatpay-payment-integration/scripts/wechatpay-resource-sync.py +646 -0
- package/.env.example +70 -0
- package/MERCHANT-EDITION.md +56 -0
- package/README.md +99 -0
- package/api/__tests__/test-utils.d.ts +33 -0
- package/api/__tests__/test-utils.d.ts.map +1 -0
- package/api/__tests__/test-utils.js +90 -0
- package/api/__tests__/test-utils.js.map +1 -0
- package/api/db/case-library-types.d.ts +47 -0
- package/api/db/case-library-types.d.ts.map +1 -0
- package/api/db/case-library-types.js +105 -0
- package/api/db/case-library-types.js.map +1 -0
- package/api/db/case-library.db.d.ts +5 -0
- package/api/db/case-library.db.d.ts.map +1 -0
- package/api/db/case-library.db.js +127 -0
- package/api/db/case-library.db.js.map +1 -0
- package/api/email.d.ts +56 -0
- package/api/email.d.ts.map +1 -0
- package/api/email.js +307 -0
- package/api/email.js.map +1 -0
- package/api/index.d.ts +22 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +41 -0
- package/api/index.js.map +1 -0
- package/api/integration-helpers.d.ts +153 -0
- package/api/integration-helpers.d.ts.map +1 -0
- package/api/integration-helpers.js +361 -0
- package/api/integration-helpers.js.map +1 -0
- package/api/lib/case-summary.d.ts +10 -0
- package/api/lib/case-summary.d.ts.map +1 -0
- package/api/lib/case-summary.js +30 -0
- package/api/lib/case-summary.js.map +1 -0
- package/api/middleware/p2p-auth.d.ts +140 -0
- package/api/middleware/p2p-auth.d.ts.map +1 -0
- package/api/middleware/p2p-auth.js +510 -0
- package/api/middleware/p2p-auth.js.map +1 -0
- package/api/middleware/tool-policy.d.ts +47 -0
- package/api/middleware/tool-policy.d.ts.map +1 -0
- package/api/middleware/tool-policy.js +156 -0
- package/api/middleware/tool-policy.js.map +1 -0
- package/api/oauth-adapters.d.ts +192 -0
- package/api/oauth-adapters.d.ts.map +1 -0
- package/api/oauth-adapters.js +456 -0
- package/api/oauth-adapters.js.map +1 -0
- package/api/oauth-bridge.d.ts +56 -0
- package/api/oauth-bridge.d.ts.map +1 -0
- package/api/oauth-bridge.js +624 -0
- package/api/oauth-bridge.js.map +1 -0
- package/api/oauth-router.d.ts +36 -0
- package/api/oauth-router.d.ts.map +1 -0
- package/api/oauth-router.js +54 -0
- package/api/oauth-router.js.map +1 -0
- package/api/p2p-mcp.d.ts +69 -0
- package/api/p2p-mcp.d.ts.map +1 -0
- package/api/p2p-mcp.js +286 -0
- package/api/p2p-mcp.js.map +1 -0
- package/api/payment-store.d.ts +56 -0
- package/api/payment-store.d.ts.map +1 -0
- package/api/payment-store.js +163 -0
- package/api/payment-store.js.map +1 -0
- package/api/payment.d.ts +14 -0
- package/api/payment.d.ts.map +1 -0
- package/api/payment.js +216 -0
- package/api/payment.js.map +1 -0
- package/api/pwa-stats.d.ts +67 -0
- package/api/pwa-stats.d.ts.map +1 -0
- package/api/pwa-stats.js +269 -0
- package/api/pwa-stats.js.map +1 -0
- package/api/riskcontrol-adapters.d.ts +114 -0
- package/api/riskcontrol-adapters.d.ts.map +1 -0
- package/api/riskcontrol-adapters.js +210 -0
- package/api/riskcontrol-adapters.js.map +1 -0
- package/api/riskcontrol-event-whitelist.d.ts +81 -0
- package/api/riskcontrol-event-whitelist.d.ts.map +1 -0
- package/api/riskcontrol-event-whitelist.js +181 -0
- package/api/riskcontrol-event-whitelist.js.map +1 -0
- package/api/riskcontrol-rules.d.ts +105 -0
- package/api/riskcontrol-rules.d.ts.map +1 -0
- package/api/riskcontrol-rules.js +399 -0
- package/api/riskcontrol-rules.js.map +1 -0
- package/api/riskcontrol-scoring.d.ts +72 -0
- package/api/riskcontrol-scoring.d.ts.map +1 -0
- package/api/riskcontrol-scoring.js +335 -0
- package/api/riskcontrol-scoring.js.map +1 -0
- package/api/riskcontrol-service.d.ts +60 -0
- package/api/riskcontrol-service.d.ts.map +1 -0
- package/api/riskcontrol-service.js +206 -0
- package/api/riskcontrol-service.js.map +1 -0
- package/api/riskcontrol-stream.d.ts +112 -0
- package/api/riskcontrol-stream.d.ts.map +1 -0
- package/api/riskcontrol-stream.js +230 -0
- package/api/riskcontrol-stream.js.map +1 -0
- package/api/riskcontrol-v5-e2e-test.d.ts +15 -0
- package/api/riskcontrol-v5-e2e-test.d.ts.map +1 -0
- package/api/riskcontrol-v5-e2e-test.js +204 -0
- package/api/riskcontrol-v5-e2e-test.js.map +1 -0
- package/api/riskcontrol-v5-router.d.ts +48 -0
- package/api/riskcontrol-v5-router.d.ts.map +1 -0
- package/api/riskcontrol-v5-router.js +226 -0
- package/api/riskcontrol-v5-router.js.map +1 -0
- package/api/riskcontrol-webhook.d.ts +88 -0
- package/api/riskcontrol-webhook.d.ts.map +1 -0
- package/api/riskcontrol-webhook.js +326 -0
- package/api/riskcontrol-webhook.js.map +1 -0
- package/api/routes/case-library.d.ts +4 -0
- package/api/routes/case-library.d.ts.map +1 -0
- package/api/routes/case-library.js +91 -0
- package/api/routes/case-library.js.map +1 -0
- package/api/seller-earnings.d.ts +23 -0
- package/api/seller-earnings.d.ts.map +1 -0
- package/api/seller-earnings.js +258 -0
- package/api/seller-earnings.js.map +1 -0
- package/api/seller-orders.d.ts +25 -0
- package/api/seller-orders.d.ts.map +1 -0
- package/api/seller-orders.js +398 -0
- package/api/seller-orders.js.map +1 -0
- package/api/seller-products-chain.d.ts +31 -0
- package/api/seller-products-chain.d.ts.map +1 -0
- package/api/seller-products-chain.js +308 -0
- package/api/seller-products-chain.js.map +1 -0
- package/api/seller-products.d.ts +30 -0
- package/api/seller-products.d.ts.map +1 -0
- package/api/seller-products.js +453 -0
- package/api/seller-products.js.map +1 -0
- package/api/seller-reputation.d.ts +21 -0
- package/api/seller-reputation.d.ts.map +1 -0
- package/api/seller-reputation.js +204 -0
- package/api/seller-reputation.js.map +1 -0
- package/api/seller-router.d.ts +33 -0
- package/api/seller-router.d.ts.map +1 -0
- package/api/seller-router.js +53 -0
- package/api/seller-router.js.map +1 -0
- package/api/seller-settings.d.ts +23 -0
- package/api/seller-settings.d.ts.map +1 -0
- package/api/seller-settings.js +279 -0
- package/api/seller-settings.js.map +1 -0
- package/api/shipping-store.d.ts +44 -0
- package/api/shipping-store.d.ts.map +1 -0
- package/api/shipping-store.js +154 -0
- package/api/shipping-store.js.map +1 -0
- package/api/shipping.d.ts +16 -0
- package/api/shipping.d.ts.map +1 -0
- package/api/shipping.js +239 -0
- package/api/shipping.js.map +1 -0
- package/api/social-endpoint-verify.d.ts +8 -0
- package/api/social-endpoint-verify.d.ts.map +1 -0
- package/api/social-endpoint-verify.js +152 -0
- package/api/social-endpoint-verify.js.map +1 -0
- package/api/social-posts.d.ts +65 -0
- package/api/social-posts.d.ts.map +1 -0
- package/api/social-posts.js +534 -0
- package/api/social-posts.js.map +1 -0
- package/api/social-router.d.ts +36 -0
- package/api/social-router.d.ts.map +1 -0
- package/api/social-router.js +56 -0
- package/api/social-router.js.map +1 -0
- package/api/social-shares.d.ts +40 -0
- package/api/social-shares.d.ts.map +1 -0
- package/api/social-shares.js +379 -0
- package/api/social-shares.js.map +1 -0
- package/api/social-whitelist.d.ts +41 -0
- package/api/social-whitelist.d.ts.map +1 -0
- package/api/social-whitelist.js +261 -0
- package/api/social-whitelist.js.map +1 -0
- package/api/storefront-orders.d.ts +23 -0
- package/api/storefront-orders.d.ts.map +1 -0
- package/api/storefront-orders.js +349 -0
- package/api/storefront-orders.js.map +1 -0
- package/api/storefront-products.d.ts +21 -0
- package/api/storefront-products.d.ts.map +1 -0
- package/api/storefront-products.js +181 -0
- package/api/storefront-products.js.map +1 -0
- package/api/storefront-router.d.ts +33 -0
- package/api/storefront-router.d.ts.map +1 -0
- package/api/storefront-router.js +47 -0
- package/api/storefront-router.js.map +1 -0
- package/api/storefront-user.d.ts +23 -0
- package/api/storefront-user.d.ts.map +1 -0
- package/api/storefront-user.js +336 -0
- package/api/storefront-user.js.map +1 -0
- package/api/test-db-helper.d.ts +29 -0
- package/api/test-db-helper.d.ts.map +1 -0
- package/api/test-db-helper.js +107 -0
- package/api/test-db-helper.js.map +1 -0
- package/api/traffic.d.ts +22 -0
- package/api/traffic.d.ts.map +1 -0
- package/api/traffic.js +112 -0
- package/api/traffic.js.map +1 -0
- package/api/wc-credentials.d.ts +34 -0
- package/api/wc-credentials.d.ts.map +1 -0
- package/api/wc-credentials.js +296 -0
- package/api/wc-credentials.js.map +1 -0
- package/api/wc-tracker-receiver.d.ts +47 -0
- package/api/wc-tracker-receiver.d.ts.map +1 -0
- package/api/wc-tracker-receiver.js +264 -0
- package/api/wc-tracker-receiver.js.map +1 -0
- package/api/wc-v3.d.ts +40 -0
- package/api/wc-v3.d.ts.map +1 -0
- package/api/wc-v3.js +694 -0
- package/api/wc-v3.js.map +1 -0
- package/bin/tb-doctor.js +32 -0
- package/bin/tb-seller-backend.js +42 -0
- package/check.d.ts +2 -0
- package/check.d.ts.map +1 -0
- package/check.js +19 -0
- package/check.js.map +1 -0
- package/config/export-import.d.ts +108 -0
- package/config/export-import.d.ts.map +1 -0
- package/config/export-import.js +234 -0
- package/config/export-import.js.map +1 -0
- package/config/manager.d.ts +73 -0
- package/config/manager.d.ts.map +1 -0
- package/config/manager.js +246 -0
- package/config/manager.js.map +1 -0
- package/config/profile.d.ts +42 -0
- package/config/profile.d.ts.map +1 -0
- package/config/profile.js +111 -0
- package/config/profile.js.map +1 -0
- package/core/address.js +23 -0
- package/core/advanced-performance.d.ts +149 -0
- package/core/advanced-performance.d.ts.map +1 -0
- package/core/advanced-performance.js +374 -0
- package/core/advanced-performance.js.map +1 -0
- package/core/alerting.d.ts +91 -0
- package/core/alerting.d.ts.map +1 -0
- package/core/alerting.js +379 -0
- package/core/alerting.js.map +1 -0
- package/core/app-store.d.ts +77 -0
- package/core/app-store.d.ts.map +1 -0
- package/core/app-store.js +207 -0
- package/core/app-store.js.map +1 -0
- package/core/boot-env.js +39 -0
- package/core/business-scope-schema.d.ts +60 -0
- package/core/business-scope-schema.d.ts.map +1 -0
- package/core/business-scope-schema.js +165 -0
- package/core/business-scope-schema.js.map +1 -0
- package/core/cache.d.ts +53 -0
- package/core/cache.d.ts.map +1 -0
- package/core/cache.js +130 -0
- package/core/cache.js.map +1 -0
- package/core/chain-listener.d.ts +47 -0
- package/core/chain-listener.d.ts.map +1 -0
- package/core/chain-listener.js +254 -0
- package/core/chain-listener.js.map +1 -0
- package/core/chain-reject.js +107 -0
- package/core/chain-signer.js +258 -0
- package/core/cleanup.d.ts +42 -0
- package/core/cleanup.d.ts.map +1 -0
- package/core/cleanup.js +144 -0
- package/core/cleanup.js.map +1 -0
- package/core/cluster.d.ts +78 -0
- package/core/cluster.d.ts.map +1 -0
- package/core/cluster.js +215 -0
- package/core/cluster.js.map +1 -0
- package/core/community-review.d.ts +82 -0
- package/core/community-review.d.ts.map +1 -0
- package/core/community-review.js +201 -0
- package/core/community-review.js.map +1 -0
- package/core/connection-pool.d.ts +72 -0
- package/core/connection-pool.d.ts.map +1 -0
- package/core/connection-pool.js +173 -0
- package/core/connection-pool.js.map +1 -0
- package/core/consistency.d.ts +130 -0
- package/core/consistency.d.ts.map +1 -0
- package/core/consistency.js +340 -0
- package/core/consistency.js.map +1 -0
- package/core/content-ai.d.ts +303 -0
- package/core/content-ai.d.ts.map +1 -0
- package/core/content-ai.js +344 -0
- package/core/content-ai.js.map +1 -0
- package/core/content-backfill.d.ts +55 -0
- package/core/content-backfill.d.ts.map +1 -0
- package/core/content-backfill.js +174 -0
- package/core/content-backfill.js.map +1 -0
- package/core/conversion-rate-sync.d.ts +97 -0
- package/core/conversion-rate-sync.d.ts.map +1 -0
- package/core/conversion-rate-sync.js +195 -0
- package/core/conversion-rate-sync.js.map +1 -0
- package/core/coverage-backup.d.ts +87 -0
- package/core/coverage-backup.d.ts.map +1 -0
- package/core/coverage-backup.js +265 -0
- package/core/coverage-backup.js.map +1 -0
- package/core/db-installer.d.ts +108 -0
- package/core/db-installer.d.ts.map +1 -0
- package/core/db-installer.js +414 -0
- package/core/db-installer.js.map +1 -0
- package/core/device-analyzer.d.ts +96 -0
- package/core/device-analyzer.d.ts.map +1 -0
- package/core/device-analyzer.js +235 -0
- package/core/device-analyzer.js.map +1 -0
- package/core/discovery.d.ts +165 -0
- package/core/discovery.d.ts.map +1 -0
- package/core/discovery.js +363 -0
- package/core/discovery.js.map +1 -0
- package/core/distributed.d.ts +172 -0
- package/core/distributed.d.ts.map +1 -0
- package/core/distributed.js +422 -0
- package/core/distributed.js.map +1 -0
- package/core/doctor.js +249 -0
- package/core/enforcement.d.ts +57 -0
- package/core/enforcement.d.ts.map +1 -0
- package/core/enforcement.js +115 -0
- package/core/enforcement.js.map +1 -0
- package/core/error-handler.d.ts +131 -0
- package/core/error-handler.d.ts.map +1 -0
- package/core/error-handler.js +291 -0
- package/core/error-handler.js.map +1 -0
- package/core/federated-learning.d.ts +124 -0
- package/core/federated-learning.d.ts.map +1 -0
- package/core/federated-learning.js +338 -0
- package/core/federated-learning.js.map +1 -0
- package/core/fingerprint.d.ts +95 -0
- package/core/fingerprint.d.ts.map +1 -0
- package/core/fingerprint.js +313 -0
- package/core/fingerprint.js.map +1 -0
- package/core/geoip.d.ts +67 -0
- package/core/geoip.d.ts.map +1 -0
- package/core/geoip.js +174 -0
- package/core/geoip.js.map +1 -0
- package/core/gossip.d.ts +141 -0
- package/core/gossip.d.ts.map +1 -0
- package/core/gossip.js +372 -0
- package/core/gossip.js.map +1 -0
- package/core/governance.d.ts +147 -0
- package/core/governance.d.ts.map +1 -0
- package/core/governance.js +351 -0
- package/core/governance.js.map +1 -0
- package/core/indexer-enhancements.d.ts +164 -0
- package/core/indexer-enhancements.d.ts.map +1 -0
- package/core/indexer-enhancements.js +429 -0
- package/core/indexer-enhancements.js.map +1 -0
- package/core/intrusion-detection.d.ts +79 -0
- package/core/intrusion-detection.d.ts.map +1 -0
- package/core/intrusion-detection.js +322 -0
- package/core/intrusion-detection.js.map +1 -0
- package/core/lifecycle.d.ts +118 -0
- package/core/lifecycle.d.ts.map +1 -0
- package/core/lifecycle.js +310 -0
- package/core/lifecycle.js.map +1 -0
- package/core/location.d.ts +99 -0
- package/core/location.d.ts.map +1 -0
- package/core/location.js +219 -0
- package/core/location.js.map +1 -0
- package/core/maxmind-integration.d.ts +68 -0
- package/core/maxmind-integration.d.ts.map +1 -0
- package/core/maxmind-integration.js +245 -0
- package/core/maxmind-integration.js.map +1 -0
- package/core/migration.d.ts +58 -0
- package/core/migration.d.ts.map +1 -0
- package/core/migration.js +223 -0
- package/core/migration.js.map +1 -0
- package/core/monitoring.d.ts +153 -0
- package/core/monitoring.d.ts.map +1 -0
- package/core/monitoring.js +406 -0
- package/core/monitoring.js.map +1 -0
- package/core/offsite-backup.d.ts +71 -0
- package/core/offsite-backup.d.ts.map +1 -0
- package/core/offsite-backup.js +341 -0
- package/core/offsite-backup.js.map +1 -0
- package/core/order-intent-store.js +83 -0
- package/core/order-intent.js +273 -0
- package/core/paths.js +116 -0
- package/core/performance.d.ts +173 -0
- package/core/performance.d.ts.map +1 -0
- package/core/performance.js +386 -0
- package/core/performance.js.map +1 -0
- package/core/product-flag.d.ts +364 -0
- package/core/product-flag.d.ts.map +1 -0
- package/core/product-flag.js +465 -0
- package/core/product-flag.js.map +1 -0
- package/core/protection.d.ts +139 -0
- package/core/protection.d.ts.map +1 -0
- package/core/protection.js +327 -0
- package/core/protection.js.map +1 -0
- package/core/region-adapter.d.ts +152 -0
- package/core/region-adapter.d.ts.map +1 -0
- package/core/region-adapter.js +505 -0
- package/core/region-adapter.js.map +1 -0
- package/core/region-configs.d.ts +12 -0
- package/core/region-configs.d.ts.map +1 -0
- package/core/region-configs.js +907 -0
- package/core/region-configs.js.map +1 -0
- package/core/review-antifraud.d.ts +80 -0
- package/core/review-antifraud.d.ts.map +1 -0
- package/core/review-antifraud.js +193 -0
- package/core/review-antifraud.js.map +1 -0
- package/core/rules-updater.d.ts +89 -0
- package/core/rules-updater.d.ts.map +1 -0
- package/core/rules-updater.js +261 -0
- package/core/rules-updater.js.map +1 -0
- package/core/runtime-data.js +203 -0
- package/core/security.d.ts +144 -0
- package/core/security.d.ts.map +1 -0
- package/core/security.js +390 -0
- package/core/security.js.map +1 -0
- package/core/seller-identity.js +78 -0
- package/core/session-manager.d.ts +93 -0
- package/core/session-manager.d.ts.map +1 -0
- package/core/session-manager.js +262 -0
- package/core/session-manager.js.map +1 -0
- package/core/state-sync.d.ts +121 -0
- package/core/state-sync.d.ts.map +1 -0
- package/core/state-sync.js +287 -0
- package/core/state-sync.js.map +1 -0
- package/core/testing.d.ts +97 -0
- package/core/testing.d.ts.map +1 -0
- package/core/testing.js +361 -0
- package/core/testing.js.map +1 -0
- package/core/trust-score.d.ts +51 -0
- package/core/trust-score.d.ts.map +1 -0
- package/core/trust-score.js +188 -0
- package/core/trust-score.js.map +1 -0
- package/core/trustworthiness.d.ts +140 -0
- package/core/trustworthiness.d.ts.map +1 -0
- package/core/trustworthiness.js +375 -0
- package/core/trustworthiness.js.map +1 -0
- package/core/types.d.ts +258 -0
- package/core/types.d.ts.map +1 -0
- package/core/types.js +9 -0
- package/core/types.js.map +1 -0
- package/core/upgrade-manager.d.ts +114 -0
- package/core/upgrade-manager.d.ts.map +1 -0
- package/core/upgrade-manager.js +264 -0
- package/core/upgrade-manager.js.map +1 -0
- package/core/upgrader.d.ts +107 -0
- package/core/upgrader.d.ts.map +1 -0
- package/core/upgrader.js +389 -0
- package/core/upgrader.js.map +1 -0
- package/core/websocket.d.ts +78 -0
- package/core/websocket.d.ts.map +1 -0
- package/core/websocket.js +292 -0
- package/core/websocket.js.map +1 -0
- package/council/hidden-weight.d.ts +45 -0
- package/council/hidden-weight.d.ts.map +1 -0
- package/council/hidden-weight.js +135 -0
- package/council/hidden-weight.js.map +1 -0
- package/db/email-migrations.sql +31 -0
- package/db/oauth-migrate.d.ts +39 -0
- package/db/oauth-migrate.d.ts.map +1 -0
- package/db/oauth-migrate.js +201 -0
- package/db/oauth-migrate.js.map +1 -0
- package/db/oauth-migrations.sql +92 -0
- package/db/social-migrate.d.ts +12 -0
- package/db/social-migrate.d.ts.map +1 -0
- package/db/social-migrate.js +102 -0
- package/db/social-migrate.js.map +1 -0
- package/db/social-migrations.sql +94 -0
- package/db/store-migrate.d.ts +33 -0
- package/db/store-migrate.d.ts.map +1 -0
- package/db/store-migrate.js +149 -0
- package/db/store-migrate.js.map +1 -0
- package/db/store-migrations.sql +242 -0
- package/debug.d.ts +2 -0
- package/debug.d.ts.map +1 -0
- package/debug.js +18 -0
- package/debug.js.map +1 -0
- package/event-listener.d.ts +93 -0
- package/event-listener.d.ts.map +1 -0
- package/event-listener.js +321 -0
- package/event-listener.js.map +1 -0
- package/event-whitelist.d.ts +79 -0
- package/event-whitelist.d.ts.map +1 -0
- package/event-whitelist.js +533 -0
- package/event-whitelist.js.map +1 -0
- package/index.d.ts +45 -0
- package/index.d.ts.map +1 -0
- package/index.js +361 -0
- package/index.js.map +1 -0
- package/init-node.d.ts +9 -0
- package/init-node.d.ts.map +1 -0
- package/init-node.js +230 -0
- package/init-node.js.map +1 -0
- package/mcp/ai-tools.d.ts +2 -0
- package/mcp/ai-tools.d.ts.map +1 -0
- package/mcp/ai-tools.js +266 -0
- package/mcp/ai-tools.js.map +1 -0
- package/mcp/auto-dispatch-tools.d.ts +2 -0
- package/mcp/auto-dispatch-tools.d.ts.map +1 -0
- package/mcp/auto-dispatch-tools.js +348 -0
- package/mcp/auto-dispatch-tools.js.map +1 -0
- package/mcp/business-scope-tools.d.ts +11 -0
- package/mcp/business-scope-tools.d.ts.map +1 -0
- package/mcp/business-scope-tools.js +179 -0
- package/mcp/business-scope-tools.js.map +1 -0
- package/mcp/buyer-tools.d.ts +67 -0
- package/mcp/buyer-tools.d.ts.map +1 -0
- package/mcp/buyer-tools.js +445 -0
- package/mcp/buyer-tools.js.map +1 -0
- package/mcp/interfaces.d.ts +1058 -0
- package/mcp/interfaces.d.ts.map +1 -0
- package/mcp/interfaces.js +13 -0
- package/mcp/interfaces.js.map +1 -0
- package/mcp/m2m-chat-tool.d.ts +50 -0
- package/mcp/m2m-chat-tool.d.ts.map +1 -0
- package/mcp/m2m-chat-tool.js +432 -0
- package/mcp/m2m-chat-tool.js.map +1 -0
- package/mcp/migrations.d.ts +30 -0
- package/mcp/migrations.d.ts.map +1 -0
- package/mcp/migrations.js +391 -0
- package/mcp/migrations.js.map +1 -0
- package/mcp/peer-tools.d.ts +163 -0
- package/mcp/peer-tools.d.ts.map +1 -0
- package/mcp/peer-tools.js +532 -0
- package/mcp/peer-tools.js.map +1 -0
- package/mcp/plugin-management-tools.d.ts +2 -0
- package/mcp/plugin-management-tools.d.ts.map +1 -0
- package/mcp/plugin-management-tools.js +327 -0
- package/mcp/plugin-management-tools.js.map +1 -0
- package/mcp/product-type-tools.d.ts +2 -0
- package/mcp/product-type-tools.d.ts.map +1 -0
- package/mcp/product-type-tools.js +470 -0
- package/mcp/product-type-tools.js.map +1 -0
- package/mcp/security-tools.d.ts +2 -0
- package/mcp/security-tools.d.ts.map +1 -0
- package/mcp/security-tools.js +313 -0
- package/mcp/security-tools.js.map +1 -0
- package/mcp/seller-query-tools.d.ts +2 -0
- package/mcp/seller-query-tools.d.ts.map +1 -0
- package/mcp/seller-query-tools.js +179 -0
- package/mcp/seller-query-tools.js.map +1 -0
- package/mcp/server.d.ts +11 -0
- package/mcp/server.d.ts.map +1 -0
- package/mcp/server.js +68 -0
- package/mcp/server.js.map +1 -0
- package/mcp/standalone-server.d.ts +34 -0
- package/mcp/standalone-server.d.ts.map +1 -0
- package/mcp/standalone-server.js +261 -0
- package/mcp/standalone-server.js.map +1 -0
- package/mcp/tools-integration.d.ts +31 -0
- package/mcp/tools-integration.d.ts.map +1 -0
- package/mcp/tools-integration.js +288 -0
- package/mcp/tools-integration.js.map +1 -0
- package/mcp/web-panel.d.ts +18 -0
- package/mcp/web-panel.d.ts.map +1 -0
- package/mcp/web-panel.js +1657 -0
- package/mcp/web-panel.js.map +1 -0
- package/middleware/api-key-auth.d.ts +64 -0
- package/middleware/api-key-auth.d.ts.map +1 -0
- package/middleware/api-key-auth.js +255 -0
- package/middleware/api-key-auth.js.map +1 -0
- package/middleware/scope-auth.d.ts +54 -0
- package/middleware/scope-auth.d.ts.map +1 -0
- package/middleware/scope-auth.js +153 -0
- package/middleware/scope-auth.js.map +1 -0
- package/middleware/security.d.ts +48 -0
- package/middleware/security.d.ts.map +1 -0
- package/middleware/security.js +217 -0
- package/middleware/security.js.map +1 -0
- package/middleware/wallet-auth.d.ts +54 -0
- package/middleware/wallet-auth.d.ts.map +1 -0
- package/middleware/wallet-auth.js +158 -0
- package/middleware/wallet-auth.js.map +1 -0
- package/oauth/chain-revocation-sink.d.ts +24 -0
- package/oauth/chain-revocation-sink.d.ts.map +1 -0
- package/oauth/chain-revocation-sink.js +47 -0
- package/oauth/chain-revocation-sink.js.map +1 -0
- package/oauth/gossip-sync.d.ts +25 -0
- package/oauth/gossip-sync.d.ts.map +1 -0
- package/oauth/gossip-sync.js +62 -0
- package/oauth/gossip-sync.js.map +1 -0
- package/oauth/issuer-keys.d.ts +31 -0
- package/oauth/issuer-keys.d.ts.map +1 -0
- package/oauth/issuer-keys.js +117 -0
- package/oauth/issuer-keys.js.map +1 -0
- package/oauth/peer-resolver.d.ts +25 -0
- package/oauth/peer-resolver.d.ts.map +1 -0
- package/oauth/peer-resolver.js +81 -0
- package/oauth/peer-resolver.js.map +1 -0
- package/oauth/revocation-store.d.ts +58 -0
- package/oauth/revocation-store.d.ts.map +1 -0
- package/oauth/revocation-store.js +86 -0
- package/oauth/revocation-store.js.map +1 -0
- package/oauth/token-v2.d.ts +101 -0
- package/oauth/token-v2.d.ts.map +1 -0
- package/oauth/token-v2.js +167 -0
- package/oauth/token-v2.js.map +1 -0
- package/oracle/c5-glue.js +603 -0
- package/oracle/ops-console.js +623 -0
- package/oracle/oracle-sync.d.ts +29 -0
- package/oracle/oracle-sync.d.ts.map +1 -0
- package/oracle/oracle-sync.js +445 -0
- package/oracle/oracle-sync.js.map +1 -0
- package/oracle/registry.d.ts +30 -0
- package/oracle/registry.d.ts.map +1 -0
- package/oracle/registry.js +62 -0
- package/oracle/registry.js.map +1 -0
- package/p2p/availability.d.ts +188 -0
- package/p2p/availability.d.ts.map +1 -0
- package/p2p/availability.js +574 -0
- package/p2p/availability.js.map +1 -0
- package/p2p/bootstrap.d.ts +42 -0
- package/p2p/bootstrap.d.ts.map +1 -0
- package/p2p/bootstrap.js +146 -0
- package/p2p/bootstrap.js.map +1 -0
- package/p2p/buyer-client.d.ts +98 -0
- package/p2p/buyer-client.d.ts.map +1 -0
- package/p2p/buyer-client.js +199 -0
- package/p2p/buyer-client.js.map +1 -0
- package/p2p/cdn-ddns.d.ts +208 -0
- package/p2p/cdn-ddns.d.ts.map +1 -0
- package/p2p/cdn-ddns.js +500 -0
- package/p2p/cdn-ddns.js.map +1 -0
- package/p2p/cluster-sync.d.ts +115 -0
- package/p2p/cluster-sync.d.ts.map +1 -0
- package/p2p/cluster-sync.js +330 -0
- package/p2p/cluster-sync.js.map +1 -0
- package/p2p/consistency-check.d.ts +30 -0
- package/p2p/consistency-check.d.ts.map +1 -0
- package/p2p/consistency-check.js +168 -0
- package/p2p/consistency-check.js.map +1 -0
- package/p2p/endpoint-registry.d.ts +41 -0
- package/p2p/endpoint-registry.d.ts.map +1 -0
- package/p2p/endpoint-registry.js +128 -0
- package/p2p/endpoint-registry.js.map +1 -0
- package/p2p/ipv6.d.ts +120 -0
- package/p2p/ipv6.d.ts.map +1 -0
- package/p2p/ipv6.js +425 -0
- package/p2p/ipv6.js.map +1 -0
- package/p2p/protocol.d.ts +100 -0
- package/p2p/protocol.d.ts.map +1 -0
- package/p2p/protocol.js +330 -0
- package/p2p/protocol.js.map +1 -0
- package/p2p/reliability.d.ts +56 -0
- package/p2p/reliability.d.ts.map +1 -0
- package/p2p/reliability.js +240 -0
- package/p2p/reliability.js.map +1 -0
- package/p2p/seller-service.d.ts +53 -0
- package/p2p/seller-service.d.ts.map +1 -0
- package/p2p/seller-service.js +276 -0
- package/p2p/seller-service.js.map +1 -0
- package/p2p/signing.d.ts +31 -0
- package/p2p/signing.d.ts.map +1 -0
- package/p2p/signing.js +95 -0
- package/p2p/signing.js.map +1 -0
- package/package.json +73 -0
- package/payment/api.d.ts +9 -0
- package/payment/api.d.ts.map +1 -0
- package/payment/api.js +141 -0
- package/payment/api.js.map +1 -0
- package/payment/gateway.d.ts +114 -0
- package/payment/gateway.d.ts.map +1 -0
- package/payment/gateway.js +231 -0
- package/payment/gateway.js.map +1 -0
- package/payments/alipay/index.d.ts +18 -0
- package/payments/alipay/index.d.ts.map +1 -0
- package/payments/alipay/index.js +55 -0
- package/payments/alipay/index.js.map +1 -0
- package/payments/base.d.ts +13 -0
- package/payments/base.d.ts.map +1 -0
- package/payments/base.js +28 -0
- package/payments/base.js.map +1 -0
- package/payments/index.d.ts +18 -0
- package/payments/index.d.ts.map +1 -0
- package/payments/index.js +66 -0
- package/payments/index.js.map +1 -0
- package/payments/template/index.d.ts +18 -0
- package/payments/template/index.d.ts.map +1 -0
- package/payments/template/index.js +57 -0
- package/payments/template/index.js.map +1 -0
- package/payments/types.d.ts +42 -0
- package/payments/types.d.ts.map +1 -0
- package/payments/types.js +3 -0
- package/payments/types.js.map +1 -0
- package/payments/wechat/index.d.ts +18 -0
- package/payments/wechat/index.d.ts.map +1 -0
- package/payments/wechat/index.js +54 -0
- package/payments/wechat/index.js.map +1 -0
- package/peer/chain-signer.d.ts +74 -0
- package/peer/chain-signer.d.ts.map +1 -0
- package/peer/chain-signer.js +149 -0
- package/peer/chain-signer.js.map +1 -0
- package/peer/config.d.ts +71 -0
- package/peer/config.d.ts.map +1 -0
- package/peer/config.js +61 -0
- package/peer/config.js.map +1 -0
- package/peer/index.d.ts +12 -0
- package/peer/index.d.ts.map +1 -0
- package/peer/index.js +46 -0
- package/peer/index.js.map +1 -0
- package/peer/key-store.d.ts +66 -0
- package/peer/key-store.d.ts.map +1 -0
- package/peer/key-store.js +163 -0
- package/peer/key-store.js.map +1 -0
- package/peer/proto-codec.d.ts +103 -0
- package/peer/proto-codec.d.ts.map +1 -0
- package/peer/proto-codec.js +423 -0
- package/peer/proto-codec.js.map +1 -0
- package/peer/registrar.d.ts +88 -0
- package/peer/registrar.d.ts.map +1 -0
- package/peer/registrar.js +271 -0
- package/peer/registrar.js.map +1 -0
- package/peer/registry.d.ts +31 -0
- package/peer/registry.d.ts.map +1 -0
- package/peer/registry.js +143 -0
- package/peer/registry.js.map +1 -0
- package/plugins/auth.d.ts +193 -0
- package/plugins/auth.d.ts.map +1 -0
- package/plugins/auth.js +923 -0
- package/plugins/auth.js.map +1 -0
- package/plugins/manager.d.ts +37 -0
- package/plugins/manager.d.ts.map +1 -0
- package/plugins/manager.js +83 -0
- package/plugins/manager.js.map +1 -0
- package/plugins/oauth.d.ts +249 -0
- package/plugins/oauth.d.ts.map +1 -0
- package/plugins/oauth.js +979 -0
- package/plugins/oauth.js.map +1 -0
- package/plugins/p2p-message.d.ts +133 -0
- package/plugins/p2p-message.d.ts.map +1 -0
- package/plugins/p2p-message.js +443 -0
- package/plugins/p2p-message.js.map +1 -0
- package/plugins/postgresql.d.ts +54 -0
- package/plugins/postgresql.d.ts.map +1 -0
- package/plugins/postgresql.js +743 -0
- package/plugins/postgresql.js.map +1 -0
- package/plugins/relationship.d.ts +141 -0
- package/plugins/relationship.d.ts.map +1 -0
- package/plugins/relationship.js +395 -0
- package/plugins/relationship.js.map +1 -0
- package/plugins/sqlite.d.ts +200 -0
- package/plugins/sqlite.d.ts.map +1 -0
- package/plugins/sqlite.js +2412 -0
- package/plugins/sqlite.js.map +1 -0
- package/port-manager/disguise/ssh.d.ts +19 -0
- package/port-manager/disguise/ssh.d.ts.map +1 -0
- package/port-manager/disguise/ssh.js +104 -0
- package/port-manager/disguise/ssh.js.map +1 -0
- package/port-manager/port-manager.d.ts +65 -0
- package/port-manager/port-manager.d.ts.map +1 -0
- package/port-manager/port-manager.js +164 -0
- package/port-manager/port-manager.js.map +1 -0
- package/port-manager/port-scanner.d.ts +22 -0
- package/port-manager/port-scanner.d.ts.map +1 -0
- package/port-manager/port-scanner.js +187 -0
- package/port-manager/port-scanner.js.map +1 -0
- package/port-manager/types.d.ts +51 -0
- package/port-manager/types.d.ts.map +1 -0
- package/port-manager/types.js +6 -0
- package/port-manager/types.js.map +1 -0
- package/proto/amino/amino.proto +84 -0
- package/proto/cosmos/base/v1beta1/coin.proto +61 -0
- package/proto/cosmos/msg/v1/msg.proto +30 -0
- package/proto/cosmos_proto/cosmos.proto +112 -0
- package/proto/gogoproto/gogo.proto +145 -0
- package/proto/google/protobuf/descriptor.proto +1218 -0
- package/proto/trustchain/economy/v1/params.proto +133 -0
- package/proto/trustchain/economy/v1/tx.proto +162 -0
- package/proto/trustchain/marketplace/v1/params.proto +64 -0
- package/proto/trustchain/marketplace/v1/product.proto +21 -0
- package/proto/trustchain/marketplace/v1/tx.proto +131 -0
- package/proto/trustchain/order/v1/params.proto +94 -0
- package/proto/trustchain/order/v1/tx.proto +156 -0
- package/proto/trustchain/serviceprovider/v1/paymentfact.proto +32 -0
- package/proto/trustchain/serviceprovider/v1/serviceprovider.proto +38 -0
- package/proto/trustchain/serviceprovider/v1/tx.proto +106 -0
- package/proto/trustchain/subchain/v1/params.proto +26 -0
- package/proto/trustchain/subchain/v1/pool.proto +53 -0
- package/proto/trustchain/subchain/v1/tx.proto +159 -0
- package/proto/trustchain/trustcoin/v1/business_scope.proto +126 -0
- package/proto/trustchain/trustcoin/v1/genesis.proto +33 -0
- package/proto/trustchain/trustcoin/v1/params.proto +86 -0
- package/proto/trustchain/trustcoin/v1/query.proto +95 -0
- package/proto/trustchain/trustcoin/v1/tx.proto +160 -0
- package/proto/trustchain/verification/v1/params.proto +46 -0
- package/proto/trustchain/verification/v1/tx.proto +126 -0
- package/proto/trustchain/verification/v1/verification.proto +105 -0
- package/relationship-chain-api.d.ts +13 -0
- package/relationship-chain-api.d.ts.map +1 -0
- package/relationship-chain-api.js +139 -0
- package/relationship-chain-api.js.map +1 -0
- package/relationship-chain.d.ts +90 -0
- package/relationship-chain.d.ts.map +1 -0
- package/relationship-chain.js +201 -0
- package/relationship-chain.js.map +1 -0
- package/routes/agent-pay.js +419 -0
- package/routes/agent-serviceprovider.js +183 -0
- package/routes/ai.d.ts +54 -0
- package/routes/ai.d.ts.map +1 -0
- package/routes/ai.js +293 -0
- package/routes/ai.js.map +1 -0
- package/routes/api-keys.d.ts +12 -0
- package/routes/api-keys.d.ts.map +1 -0
- package/routes/api-keys.js +163 -0
- package/routes/api-keys.js.map +1 -0
- package/routes/app-store.d.ts +12 -0
- package/routes/app-store.d.ts.map +1 -0
- package/routes/app-store.js +207 -0
- package/routes/app-store.js.map +1 -0
- package/routes/auth-management.d.ts +17 -0
- package/routes/auth-management.d.ts.map +1 -0
- package/routes/auth-management.js +257 -0
- package/routes/auth-management.js.map +1 -0
- package/routes/auth.d.ts +9 -0
- package/routes/auth.d.ts.map +1 -0
- package/routes/auth.js +846 -0
- package/routes/auth.js.map +1 -0
- package/routes/brand.d.ts +3 -0
- package/routes/brand.d.ts.map +1 -0
- package/routes/brand.js +109 -0
- package/routes/brand.js.map +1 -0
- package/routes/chain-registry.d.ts +11 -0
- package/routes/chain-registry.d.ts.map +1 -0
- package/routes/chain-registry.js +51 -0
- package/routes/chain-registry.js.map +1 -0
- package/routes/chain-writes-insurance.d.ts +17 -0
- package/routes/chain-writes-insurance.d.ts.map +1 -0
- package/routes/chain-writes-insurance.js +69 -0
- package/routes/chain-writes-insurance.js.map +1 -0
- package/routes/chain-writes-pledge.d.ts +34 -0
- package/routes/chain-writes-pledge.d.ts.map +1 -0
- package/routes/chain-writes-pledge.js +206 -0
- package/routes/chain-writes-pledge.js.map +1 -0
- package/routes/chain-writes-products.d.ts +66 -0
- package/routes/chain-writes-products.d.ts.map +1 -0
- package/routes/chain-writes-products.js +394 -0
- package/routes/chain-writes-products.js.map +1 -0
- package/routes/chain-writes.d.ts +78 -0
- package/routes/chain-writes.d.ts.map +1 -0
- package/routes/chain-writes.js +658 -0
- package/routes/chain-writes.js.map +1 -0
- package/routes/chain.d.ts +10 -0
- package/routes/chain.d.ts.map +1 -0
- package/routes/chain.js +45 -0
- package/routes/chain.js.map +1 -0
- package/routes/compliance.d.ts +3 -0
- package/routes/compliance.d.ts.map +1 -0
- package/routes/compliance.js +53 -0
- package/routes/compliance.js.map +1 -0
- package/routes/council.d.ts +3 -0
- package/routes/council.d.ts.map +1 -0
- package/routes/council.js +477 -0
- package/routes/council.js.map +1 -0
- package/routes/crosschain.d.ts +11 -0
- package/routes/crosschain.d.ts.map +1 -0
- package/routes/crosschain.js +39 -0
- package/routes/crosschain.js.map +1 -0
- package/routes/device.d.ts +3 -0
- package/routes/device.d.ts.map +1 -0
- package/routes/device.js +73 -0
- package/routes/device.js.map +1 -0
- package/routes/devreward.d.ts +54 -0
- package/routes/devreward.d.ts.map +1 -0
- package/routes/devreward.js +129 -0
- package/routes/devreward.js.map +1 -0
- package/routes/economy.d.ts +50 -0
- package/routes/economy.d.ts.map +1 -0
- package/routes/economy.js +273 -0
- package/routes/economy.js.map +1 -0
- package/routes/flowback.d.ts +32 -0
- package/routes/flowback.d.ts.map +1 -0
- package/routes/flowback.js +97 -0
- package/routes/flowback.js.map +1 -0
- package/routes/insurance.d.ts +10 -0
- package/routes/insurance.d.ts.map +1 -0
- package/routes/insurance.js +70 -0
- package/routes/insurance.js.map +1 -0
- package/routes/m2m-viewer.js +195 -0
- package/routes/m2m.d.ts +10 -0
- package/routes/m2m.d.ts.map +1 -0
- package/routes/m2m.js +31 -0
- package/routes/m2m.js.map +1 -0
- package/routes/marketplace.d.ts +15 -0
- package/routes/marketplace.d.ts.map +1 -0
- package/routes/marketplace.js +396 -0
- package/routes/marketplace.js.map +1 -0
- package/routes/node-config.d.ts +6 -0
- package/routes/node-config.d.ts.map +1 -0
- package/routes/node-config.js +500 -0
- package/routes/node-config.js.map +1 -0
- package/routes/oauth-revocation.d.ts +42 -0
- package/routes/oauth-revocation.d.ts.map +1 -0
- package/routes/oauth-revocation.js +99 -0
- package/routes/oauth-revocation.js.map +1 -0
- package/routes/oauth.d.ts +17 -0
- package/routes/oauth.d.ts.map +1 -0
- package/routes/oauth.js +700 -0
- package/routes/oauth.js.map +1 -0
- package/routes/onboard.html +352 -0
- package/routes/onboard.js +435 -0
- package/routes/order.d.ts +8 -0
- package/routes/order.d.ts.map +1 -0
- package/routes/order.js +607 -0
- package/routes/order.js.map +1 -0
- package/routes/p2p-api.d.ts +33 -0
- package/routes/p2p-api.d.ts.map +1 -0
- package/routes/p2p-api.js +274 -0
- package/routes/p2p-api.js.map +1 -0
- package/routes/p2p-message.d.ts +20 -0
- package/routes/p2p-message.d.ts.map +1 -0
- package/routes/p2p-message.js +237 -0
- package/routes/p2p-message.js.map +1 -0
- package/routes/peer.d.ts +22 -0
- package/routes/peer.d.ts.map +1 -0
- package/routes/peer.js +220 -0
- package/routes/peer.js.map +1 -0
- package/routes/plugins.d.ts +4 -0
- package/routes/plugins.d.ts.map +1 -0
- package/routes/plugins.js +138 -0
- package/routes/plugins.js.map +1 -0
- package/routes/port-manager.d.ts +6 -0
- package/routes/port-manager.d.ts.map +1 -0
- package/routes/port-manager.js +212 -0
- package/routes/port-manager.js.map +1 -0
- package/routes/relationship.d.ts +7 -0
- package/routes/relationship.d.ts.map +1 -0
- package/routes/relationship.js +314 -0
- package/routes/relationship.js.map +1 -0
- package/routes/relay.d.ts +3 -0
- package/routes/relay.d.ts.map +1 -0
- package/routes/relay.js +182 -0
- package/routes/relay.js.map +1 -0
- package/routes/reputation.d.ts +10 -0
- package/routes/reputation.d.ts.map +1 -0
- package/routes/reputation.js +141 -0
- package/routes/reputation.js.map +1 -0
- package/routes/reward.d.ts +3 -0
- package/routes/reward.d.ts.map +1 -0
- package/routes/reward.js +130 -0
- package/routes/reward.js.map +1 -0
- package/routes/security-monitoring.d.ts +12 -0
- package/routes/security-monitoring.d.ts.map +1 -0
- package/routes/security-monitoring.js +373 -0
- package/routes/security-monitoring.js.map +1 -0
- package/routes/shop.d.ts +8 -0
- package/routes/shop.d.ts.map +1 -0
- package/routes/shop.js +164 -0
- package/routes/shop.js.map +1 -0
- package/routes/social.d.ts +22 -0
- package/routes/social.d.ts.map +1 -0
- package/routes/social.js +95 -0
- package/routes/social.js.map +1 -0
- package/routes/subchain.d.ts +18 -0
- package/routes/subchain.d.ts.map +1 -0
- package/routes/subchain.js +106 -0
- package/routes/subchain.js.map +1 -0
- package/routes/trustcoin.d.ts +17 -0
- package/routes/trustcoin.d.ts.map +1 -0
- package/routes/trustcoin.js +149 -0
- package/routes/trustcoin.js.map +1 -0
- package/routes/twofa.d.ts +7 -0
- package/routes/twofa.d.ts.map +1 -0
- package/routes/twofa.js +105 -0
- package/routes/twofa.js.map +1 -0
- package/routes/verification.d.ts +8 -0
- package/routes/verification.d.ts.map +1 -0
- package/routes/verification.js +234 -0
- package/routes/verification.js.map +1 -0
- package/routes/wallet.d.ts +4 -0
- package/routes/wallet.d.ts.map +1 -0
- package/routes/wallet.js +770 -0
- package/routes/wallet.js.map +1 -0
- package/run-auth.d.ts +8 -0
- package/run-auth.d.ts.map +1 -0
- package/run-auth.js +82 -0
- package/run-auth.js.map +1 -0
- package/run-p2p-message.d.ts +8 -0
- package/run-p2p-message.d.ts.map +1 -0
- package/run-p2p-message.js +82 -0
- package/run-p2p-message.js.map +1 -0
- package/run-relationship.d.ts +12 -0
- package/run-relationship.d.ts.map +1 -0
- package/run-relationship.js +182 -0
- package/run-relationship.js.map +1 -0
- package/run-unified.d.ts +13 -0
- package/run-unified.d.ts.map +1 -0
- package/run-unified.js +1067 -0
- package/run-unified.js.map +1 -0
- package/run.d.ts +12 -0
- package/run.d.ts.map +1 -0
- package/run.js +889 -0
- package/run.js.map +1 -0
- package/search/ranking.d.ts +55 -0
- package/search/ranking.d.ts.map +1 -0
- package/search/ranking.js +67 -0
- package/search/ranking.js.map +1 -0
- package/shipping/base.d.ts +15 -0
- package/shipping/base.d.ts.map +1 -0
- package/shipping/base.js +39 -0
- package/shipping/base.js.map +1 -0
- package/shipping/index.d.ts +19 -0
- package/shipping/index.d.ts.map +1 -0
- package/shipping/index.js +72 -0
- package/shipping/index.js.map +1 -0
- package/shipping/sf-express/index.d.ts +23 -0
- package/shipping/sf-express/index.d.ts.map +1 -0
- package/shipping/sf-express/index.js +71 -0
- package/shipping/sf-express/index.js.map +1 -0
- package/shipping/template/index.d.ts +20 -0
- package/shipping/template/index.d.ts.map +1 -0
- package/shipping/template/index.js +74 -0
- package/shipping/template/index.js.map +1 -0
- package/shipping/types.d.ts +71 -0
- package/shipping/types.d.ts.map +1 -0
- package/shipping/types.js +6 -0
- package/shipping/types.js.map +1 -0
- package/shipping/virtual/index.d.ts +19 -0
- package/shipping/virtual/index.d.ts.map +1 -0
- package/shipping/virtual/index.js +54 -0
- package/shipping/virtual/index.js.map +1 -0
- package/shipping/yto/index.d.ts +18 -0
- package/shipping/yto/index.d.ts.map +1 -0
- package/shipping/yto/index.js +59 -0
- package/shipping/yto/index.js.map +1 -0
- package/shipping/zto/index.d.ts +18 -0
- package/shipping/zto/index.d.ts.map +1 -0
- package/shipping/zto/index.js +59 -0
- package/shipping/zto/index.js.map +1 -0
- package/skills-lock.json +11 -0
- package/src/db/email-migrations.sql +31 -0
- package/src/db/oauth-migrations.sql +92 -0
- package/src/db/social-migrations.sql +94 -0
- package/src/db/store-migrations.sql +242 -0
- package/test-api-key-revoke.js +167 -0
- package/test-auth-register-ratelimit.js +132 -0
- package/test-auth-tv2.d.ts +2 -0
- package/test-auth-tv2.d.ts.map +1 -0
- package/test-auth-tv2.js +174 -0
- package/test-auth-tv2.js.map +1 -0
- package/test-canonsign-cross.d.ts +2 -0
- package/test-canonsign-cross.d.ts.map +1 -0
- package/test-canonsign-cross.js +32 -0
- package/test-canonsign-cross.js.map +1 -0
- package/test-chain-signer.js +127 -0
- package/test-env-truthy.js +50 -0
- package/test-onboard-contract.js +94 -0
- package/test-ops-console-boundary.js +147 -0
- package/test-oracle-glue.js +232 -0
- package/test-order-create-v394.js +358 -0
- package/test-order-intent.js +245 -0
- package/test-order-lifecycle-v394.js +528 -0
- package/test-p2p-message.d.ts +13 -0
- package/test-p2p-message.d.ts.map +1 -0
- package/test-p2p-message.js +106 -0
- package/test-p2p-message.js.map +1 -0
- package/test-relationship-chain.d.ts +13 -0
- package/test-relationship-chain.d.ts.map +1 -0
- package/test-relationship-chain.js +103 -0
- package/test-relationship-chain.js.map +1 -0
- package/test-runtime-data-path.js +217 -0
- package/test-seller-identity.js +74 -0
- package/test-signing-paths.js +104 -0
- package/test-token-v2.d.ts +2 -0
- package/test-token-v2.d.ts.map +1 -0
- package/test-token-v2.js +172 -0
- package/test-token-v2.js.map +1 -0
- package/test-wallet-auth-nonce.d.ts +12 -0
- package/test-wallet-auth-nonce.d.ts.map +1 -0
- package/test-wallet-auth-nonce.js +126 -0
- package/test-wallet-auth-nonce.js.map +1 -0
- package/test-wallet-submatch.d.ts +13 -0
- package/test-wallet-submatch.d.ts.map +1 -0
- package/test-wallet-submatch.js +86 -0
- package/test-wallet-submatch.js.map +1 -0
- package/tls/self-signed.d.ts +12 -0
- package/tls/self-signed.d.ts.map +1 -0
- package/tls/self-signed.js +63 -0
- package/tls/self-signed.js.map +1 -0
- package/tools/brand.d.ts +11 -0
- package/tools/brand.d.ts.map +1 -0
- package/tools/brand.js +75 -0
- package/tools/brand.js.map +1 -0
- package/tools/chainregistry.d.ts +18 -0
- package/tools/chainregistry.d.ts.map +1 -0
- package/tools/chainregistry.js +175 -0
- package/tools/chainregistry.js.map +1 -0
- package/tools/compliance.d.ts +14 -0
- package/tools/compliance.d.ts.map +1 -0
- package/tools/compliance.js +45 -0
- package/tools/compliance.js.map +1 -0
- package/tools/council.d.ts +17 -0
- package/tools/council.d.ts.map +1 -0
- package/tools/council.js +75 -0
- package/tools/council.js.map +1 -0
- package/tools/device.d.ts +13 -0
- package/tools/device.d.ts.map +1 -0
- package/tools/device.js +45 -0
- package/tools/device.js.map +1 -0
- package/tools/devreward.d.ts +15 -0
- package/tools/devreward.d.ts.map +1 -0
- package/tools/devreward.js +190 -0
- package/tools/devreward.js.map +1 -0
- package/tools/economy.d.ts +14 -0
- package/tools/economy.d.ts.map +1 -0
- package/tools/economy.js +172 -0
- package/tools/economy.js.map +1 -0
- package/tools/flowback.d.ts +14 -0
- package/tools/flowback.d.ts.map +1 -0
- package/tools/flowback.js +146 -0
- package/tools/flowback.js.map +1 -0
- package/tools/insurance.d.ts +13 -0
- package/tools/insurance.d.ts.map +1 -0
- package/tools/insurance.js +45 -0
- package/tools/insurance.js.map +1 -0
- package/tools/marketplace.d.ts +12 -0
- package/tools/marketplace.d.ts.map +1 -0
- package/tools/marketplace.js +124 -0
- package/tools/marketplace.js.map +1 -0
- package/tools/order.d.ts +12 -0
- package/tools/order.d.ts.map +1 -0
- package/tools/order.js +94 -0
- package/tools/order.js.map +1 -0
- package/tools/recovery.d.ts +14 -0
- package/tools/recovery.d.ts.map +1 -0
- package/tools/recovery.js +158 -0
- package/tools/recovery.js.map +1 -0
- package/tools/relay.d.ts +15 -0
- package/tools/relay.d.ts.map +1 -0
- package/tools/relay.js +152 -0
- package/tools/relay.js.map +1 -0
- package/tools/reputation.d.ts +20 -0
- package/tools/reputation.d.ts.map +1 -0
- package/tools/reputation.js +50 -0
- package/tools/reputation.js.map +1 -0
- package/tools/reputation_seller_credit.d.ts +16 -0
- package/tools/reputation_seller_credit.d.ts.map +1 -0
- package/tools/reputation_seller_credit.js +106 -0
- package/tools/reputation_seller_credit.js.map +1 -0
- package/tools/reward.d.ts +14 -0
- package/tools/reward.d.ts.map +1 -0
- package/tools/reward.js +76 -0
- package/tools/reward.js.map +1 -0
- package/tools/shop.d.ts +14 -0
- package/tools/shop.d.ts.map +1 -0
- package/tools/shop.js +95 -0
- package/tools/shop.js.map +1 -0
- package/tools/verification.d.ts +12 -0
- package/tools/verification.d.ts.map +1 -0
- package/tools/verification.js +89 -0
- package/tools/verification.js.map +1 -0
- package/types/store.d.ts +255 -0
- package/types/store.d.ts.map +1 -0
- package/types/store.js +19 -0
- package/types/store.js.map +1 -0
- package/utils/aes-gcm.d.ts +63 -0
- package/utils/aes-gcm.d.ts.map +1 -0
- package/utils/aes-gcm.js +179 -0
- package/utils/aes-gcm.js.map +1 -0
- package/utils/api-response.d.ts +51 -0
- package/utils/api-response.d.ts.map +1 -0
- package/utils/api-response.js +65 -0
- package/utils/api-response.js.map +1 -0
- package/utils/base32.d.ts +5 -0
- package/utils/base32.d.ts.map +1 -0
- package/utils/base32.js +20 -0
- package/utils/base32.js.map +1 -0
- package/utils/crypto.d.ts +77 -0
- package/utils/crypto.d.ts.map +1 -0
- package/utils/crypto.js +164 -0
- package/utils/crypto.js.map +1 -0
- package/utils/encryption.d.ts +81 -0
- package/utils/encryption.d.ts.map +1 -0
- package/utils/encryption.js +247 -0
- package/utils/encryption.js.map +1 -0
- package/utils/env.js +20 -0
- package/utils/jwt.d.ts +110 -0
- package/utils/jwt.d.ts.map +1 -0
- package/utils/jwt.js +275 -0
- package/utils/jwt.js.map +1 -0
- package/utils/qrcode-reader.d.ts +22 -0
- package/utils/qrcode-reader.d.ts.map +1 -0
- package/utils/qrcode-reader.js +90 -0
- package/utils/qrcode-reader.js.map +1 -0
- package/utils/qrcode.d.ts +26 -0
- package/utils/qrcode.d.ts.map +1 -0
- package/utils/qrcode.js +92 -0
- package/utils/qrcode.js.map +1 -0
- package/utils/totp.d.ts +3 -0
- package/utils/totp.d.ts.map +1 -0
- package/utils/totp.js +58 -0
- package/utils/totp.js.map +1 -0
- package/utils/two-factor-auth.d.ts +16 -0
- package/utils/two-factor-auth.d.ts.map +1 -0
- package/utils/two-factor-auth.js +150 -0
- package/utils/two-factor-auth.js.map +1 -0
- package/verifyer/hsm.d.ts +70 -0
- package/verifyer/hsm.d.ts.map +1 -0
- package/verifyer/hsm.js +482 -0
- package/verifyer/hsm.js.map +1 -0
- package/verifyer/index.d.ts +81 -0
- package/verifyer/index.d.ts.map +1 -0
- package/verifyer/index.js +372 -0
- package/verifyer/index.js.map +1 -0
- package/ws/peer-monitor-broadcaster.d.ts +24 -0
- package/ws/peer-monitor-broadcaster.d.ts.map +1 -0
- package/ws/peer-monitor-broadcaster.js +56 -0
- package/ws/peer-monitor-broadcaster.js.map +1 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peer-to-Peer Auth Middleware (PRD-F Phase 2 §6)
|
|
3
|
+
*
|
|
4
|
+
* Four composable middlewares for protecting /api/p2p/mcp/* endpoints:
|
|
5
|
+
*
|
|
6
|
+
* 1. verifyPeerSignature
|
|
7
|
+
* Pulls X-Node-ID, X-Signature, X-Nonce, X-Timestamp from the headers,
|
|
8
|
+
* looks up the caller's public key on-chain (peer.discover by node_id),
|
|
9
|
+
* rebuilds the canonical envelope, and verifies the secp256k1 signature.
|
|
10
|
+
* On success, attaches `req.peer = { node_id, public_key }`.
|
|
11
|
+
*
|
|
12
|
+
* 2. requireTrustLevel(level)
|
|
13
|
+
* Reads `peer_trust.trust_level` from the local SQLite whitelist. If the
|
|
14
|
+
* caller's trust_level is < `level`, returns 403.
|
|
15
|
+
*
|
|
16
|
+
* 3. preventReplay
|
|
17
|
+
* LRU+TTL cache of `(node_id, nonce)` pairs. Same nonce from the same
|
|
18
|
+
* caller within the 5-minute window is rejected. Also enforces the
|
|
19
|
+
* timestamp window (±5 minutes) before the nonce check.
|
|
20
|
+
*
|
|
21
|
+
* 4. rateLimitPerPeer
|
|
22
|
+
* Per-peer token-bucket rate limiter (10 req/min, configurable). Pairs
|
|
23
|
+
* with a global IP rate limiter mounted at the /api/p2p/ root.
|
|
24
|
+
*
|
|
25
|
+
* Design notes:
|
|
26
|
+
* - All middlewares are pure factory functions that return an Express
|
|
27
|
+
* RequestHandler. Easy to test in isolation with `supertest`.
|
|
28
|
+
* - The chain RPC lookup is delegated to `discoverEndpoints` so tests can
|
|
29
|
+
* inject a fake via `setChainClientFactory` (already exported from
|
|
30
|
+
* peer-tools.ts).
|
|
31
|
+
* - Nonce cache and rate limiter are module-level singletons. They grow
|
|
32
|
+
* with traffic; the TTL on the nonce cache bounds memory to a few MB
|
|
33
|
+
* even at 100k unique nonces/min.
|
|
34
|
+
* - No new npm deps. LRU is a Map + lazy TTL eviction; rate limiter is a
|
|
35
|
+
* Map + sliding window. Both are tested in __tests__/.
|
|
36
|
+
*/
|
|
37
|
+
import type { Request, RequestHandler } from 'express';
|
|
38
|
+
import Database from 'better-sqlite3';
|
|
39
|
+
import { discoverEndpoints } from '../../mcp/peer-tools';
|
|
40
|
+
declare module 'express-serve-static-core' {
|
|
41
|
+
interface Request {
|
|
42
|
+
/** Populated by verifyPeerSignature once the signature passes. */
|
|
43
|
+
peer?: {
|
|
44
|
+
node_id: string;
|
|
45
|
+
public_key: Uint8Array;
|
|
46
|
+
/** Trust level from peer_trust table, if any. */
|
|
47
|
+
trust_level?: 'read' | 'write' | 'admin' | null;
|
|
48
|
+
};
|
|
49
|
+
/** Raw bytes of the request body, captured by express.json({ verify }). */
|
|
50
|
+
rawBody?: Buffer;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export type TrustLevel = 'read' | 'write' | 'admin';
|
|
54
|
+
export interface VerifyPeerSignatureOptions {
|
|
55
|
+
/**
|
|
56
|
+
* How to obtain the SQLite db handle. Default: `(req) => req.app.locals.db`.
|
|
57
|
+
* Not used for the chain lookup, but kept for parity / future extension.
|
|
58
|
+
*/
|
|
59
|
+
resolveDb?: (req: Request) => Database.Database | null;
|
|
60
|
+
/**
|
|
61
|
+
* How to obtain the chain RPC client. Default: use `discoverEndpoints` from
|
|
62
|
+
* peer-tools.ts (which itself is mockable via setChainClientFactory).
|
|
63
|
+
*/
|
|
64
|
+
discover?: typeof discoverEndpoints;
|
|
65
|
+
/**
|
|
66
|
+
* Optional override for the canonical digest. The default rebuilds the
|
|
67
|
+
* same envelope shape used by sendRequest: method || path || body || nonce || ts.
|
|
68
|
+
*/
|
|
69
|
+
buildDigest?: (req: Request) => Uint8Array;
|
|
70
|
+
/** Skip the chain lookup (useful for tests that inject req.peer directly). */
|
|
71
|
+
skipChainLookup?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare function verifyPeerSignature(opts?: VerifyPeerSignatureOptions): RequestHandler;
|
|
74
|
+
export interface RequireTrustLevelOptions {
|
|
75
|
+
/** Resolver for the SQLite db handle. Default: req.app.locals.db. */
|
|
76
|
+
resolveDb?: (req: Request) => Database.Database | null;
|
|
77
|
+
}
|
|
78
|
+
export declare function requireTrustLevel(level: TrustLevel, opts?: RequireTrustLevelOptions): RequestHandler;
|
|
79
|
+
export interface PreventReplayOptions {
|
|
80
|
+
/** Allowed clock skew, in seconds. Default 300 (±5 min, matches PRD §6.2). */
|
|
81
|
+
windowSeconds?: number;
|
|
82
|
+
/** Max nonce cache size. Default 10000. */
|
|
83
|
+
maxNonces?: number;
|
|
84
|
+
/** TTL for nonces, ms. Default 10 minutes (matches ±5 min window). */
|
|
85
|
+
ttlMs?: number;
|
|
86
|
+
/** Test seam: provide a custom clock (ms). */
|
|
87
|
+
nowMs?: () => number;
|
|
88
|
+
}
|
|
89
|
+
declare class NonceCache {
|
|
90
|
+
private readonly maxSize;
|
|
91
|
+
private readonly ttlMs;
|
|
92
|
+
private readonly map;
|
|
93
|
+
constructor(maxSize: number, ttlMs: number);
|
|
94
|
+
/** Returns true if the nonce was fresh (i.e. not seen before, or was seen but expired). */
|
|
95
|
+
reserve(key: string, nowMs: number): boolean;
|
|
96
|
+
has(key: string): boolean;
|
|
97
|
+
size(): number;
|
|
98
|
+
clear(): void;
|
|
99
|
+
private sweep;
|
|
100
|
+
}
|
|
101
|
+
export declare function preventReplay(opts?: PreventReplayOptions): RequestHandler;
|
|
102
|
+
/** Exposed for tests. */
|
|
103
|
+
export declare const __testing__: {
|
|
104
|
+
NonceCache: typeof NonceCache;
|
|
105
|
+
};
|
|
106
|
+
export interface RateLimitPerPeerOptions {
|
|
107
|
+
/** Max requests per window. Default 10. */
|
|
108
|
+
points?: number;
|
|
109
|
+
/** Window length, seconds. Default 60. */
|
|
110
|
+
duration?: number;
|
|
111
|
+
/** Test seam: clock in ms. */
|
|
112
|
+
nowMs?: () => number;
|
|
113
|
+
}
|
|
114
|
+
declare class PerPeerLimiter {
|
|
115
|
+
private readonly points;
|
|
116
|
+
private readonly windowMs;
|
|
117
|
+
private readonly nowFn;
|
|
118
|
+
private readonly buckets;
|
|
119
|
+
constructor(points: number, windowMs: number, nowFn: () => number);
|
|
120
|
+
/** Returns ms until the next request would be allowed, or 0 if allowed. */
|
|
121
|
+
consume(key: string): {
|
|
122
|
+
allowed: boolean;
|
|
123
|
+
retryAfterMs: number;
|
|
124
|
+
remaining: number;
|
|
125
|
+
};
|
|
126
|
+
size(): number;
|
|
127
|
+
clear(): void;
|
|
128
|
+
}
|
|
129
|
+
export declare function rateLimitPerPeer(opts?: RateLimitPerPeerOptions): RequestHandler;
|
|
130
|
+
/** Exposed for tests. */
|
|
131
|
+
export declare const __testing2__: {
|
|
132
|
+
PerPeerLimiter: typeof PerPeerLimiter;
|
|
133
|
+
};
|
|
134
|
+
export interface IpRateLimitOptions extends RateLimitPerPeerOptions {
|
|
135
|
+
/** Key extractor — default uses req.ip with ::ffff: prefix stripped. */
|
|
136
|
+
keyFn?: (req: Request) => string;
|
|
137
|
+
}
|
|
138
|
+
export declare function ipRateLimit(opts?: IpRateLimitOptions): RequestHandler;
|
|
139
|
+
export {};
|
|
140
|
+
//# sourceMappingURL=p2p-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p2p-auth.d.ts","sourceRoot":"","sources":["../../../src/api/middleware/p2p-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAA0B,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAOzD,OAAO,QAAQ,2BAA2B,CAAC;IACzC,UAAU,OAAO;QACf,kEAAkE;QAClE,IAAI,CAAC,EAAE;YACL,OAAO,EAAE,MAAM,CAAC;YAChB,UAAU,EAAE,UAAU,CAAC;YACvB,iDAAiD;YACjD,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;SACjD,CAAC;QACF,2EAA2E;QAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;CACF;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAYpD,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IAEvD;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,iBAAiB,CAAC;IAEpC;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,CAAC;IAE3C,8EAA8E;IAC9E,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA0BD,wBAAgB,mBAAmB,CACjC,IAAI,GAAE,0BAA+B,GACpC,cAAc,CAkOhB;AAMD,MAAM,WAAW,wBAAwB;IACvC,qEAAqE;IACrE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;CACxD;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,wBAA6B,GAClC,cAAc,CAyChB;AAMD,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;CACtB;AAED,cAAM,UAAU;IAEF,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,KAAK;IADpE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA6B;gBACpB,OAAO,EAAE,MAAM,EAAmB,KAAK,EAAE,MAAM;IAE5E,2FAA2F;IAC3F,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAe5C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,IAAI,IAAI,MAAM;IAId,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,KAAK;CAed;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,oBAAyB,GAAG,cAAc,CAuC7E;AAED,yBAAyB;AACzB,eAAO,MAAM,WAAW;;CAAiB,CAAC;AAM1C,MAAM,WAAW,uBAAuB;IACtC,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;CACtB;AAOD,cAAM,cAAc;IAGhB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;gBAElC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,MAAM;IAGtC,2EAA2E;IAC3E,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAenF,IAAI,IAAI,MAAM;IAId,KAAK,IAAI,IAAI;CAGd;AAED,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,uBAA4B,GAAG,cAAc,CA0BnF;AAED,yBAAyB;AACzB,eAAO,MAAM,YAAY;;CAAqB,CAAC;AAM/C,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IACjE,wEAAwE;IACxE,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;CAClC;AAED,wBAAgB,WAAW,CAAC,IAAI,GAAE,kBAAuB,GAAG,cAAc,CAwBzE"}
|
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Peer-to-Peer Auth Middleware (PRD-F Phase 2 §6)
|
|
4
|
+
*
|
|
5
|
+
* Four composable middlewares for protecting /api/p2p/mcp/* endpoints:
|
|
6
|
+
*
|
|
7
|
+
* 1. verifyPeerSignature
|
|
8
|
+
* Pulls X-Node-ID, X-Signature, X-Nonce, X-Timestamp from the headers,
|
|
9
|
+
* looks up the caller's public key on-chain (peer.discover by node_id),
|
|
10
|
+
* rebuilds the canonical envelope, and verifies the secp256k1 signature.
|
|
11
|
+
* On success, attaches `req.peer = { node_id, public_key }`.
|
|
12
|
+
*
|
|
13
|
+
* 2. requireTrustLevel(level)
|
|
14
|
+
* Reads `peer_trust.trust_level` from the local SQLite whitelist. If the
|
|
15
|
+
* caller's trust_level is < `level`, returns 403.
|
|
16
|
+
*
|
|
17
|
+
* 3. preventReplay
|
|
18
|
+
* LRU+TTL cache of `(node_id, nonce)` pairs. Same nonce from the same
|
|
19
|
+
* caller within the 5-minute window is rejected. Also enforces the
|
|
20
|
+
* timestamp window (±5 minutes) before the nonce check.
|
|
21
|
+
*
|
|
22
|
+
* 4. rateLimitPerPeer
|
|
23
|
+
* Per-peer token-bucket rate limiter (10 req/min, configurable). Pairs
|
|
24
|
+
* with a global IP rate limiter mounted at the /api/p2p/ root.
|
|
25
|
+
*
|
|
26
|
+
* Design notes:
|
|
27
|
+
* - All middlewares are pure factory functions that return an Express
|
|
28
|
+
* RequestHandler. Easy to test in isolation with `supertest`.
|
|
29
|
+
* - The chain RPC lookup is delegated to `discoverEndpoints` so tests can
|
|
30
|
+
* inject a fake via `setChainClientFactory` (already exported from
|
|
31
|
+
* peer-tools.ts).
|
|
32
|
+
* - Nonce cache and rate limiter are module-level singletons. They grow
|
|
33
|
+
* with traffic; the TTL on the nonce cache bounds memory to a few MB
|
|
34
|
+
* even at 100k unique nonces/min.
|
|
35
|
+
* - No new npm deps. LRU is a Map + lazy TTL eviction; rate limiter is a
|
|
36
|
+
* Map + sliding window. Both are tested in __tests__/.
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.__testing2__ = exports.__testing__ = void 0;
|
|
40
|
+
exports.verifyPeerSignature = verifyPeerSignature;
|
|
41
|
+
exports.requireTrustLevel = requireTrustLevel;
|
|
42
|
+
exports.preventReplay = preventReplay;
|
|
43
|
+
exports.rateLimitPerPeer = rateLimitPerPeer;
|
|
44
|
+
exports.ipRateLimit = ipRateLimit;
|
|
45
|
+
const encoding_1 = require("@cosmjs/encoding");
|
|
46
|
+
const signing_1 = require("../../p2p/signing");
|
|
47
|
+
const peer_tools_1 = require("../../mcp/peer-tools");
|
|
48
|
+
const peer_monitor_broadcaster_1 = require("../../ws/peer-monitor-broadcaster");
|
|
49
|
+
const TRUST_RANK = {
|
|
50
|
+
read: 1,
|
|
51
|
+
write: 2,
|
|
52
|
+
admin: 3,
|
|
53
|
+
};
|
|
54
|
+
const DEFAULT_DIGEST = (req) => {
|
|
55
|
+
const ts = req.header('X-Timestamp') ?? '';
|
|
56
|
+
const nonce = req.header('X-Nonce') ?? '';
|
|
57
|
+
const sig = req.header('X-Signature') ?? '';
|
|
58
|
+
const nid = req.header('X-Node-ID') ?? '';
|
|
59
|
+
// Canonical envelope: { method, path, body, nonce, timestamp, node_id }
|
|
60
|
+
// signing.ts canonicalize() strips any `signature` field, so we can include
|
|
61
|
+
// a `signature: sig` here without poisoning the digest.
|
|
62
|
+
const envelope = {
|
|
63
|
+
method: req.method,
|
|
64
|
+
// 宝贝 2026-06-23: Express sub-router 下 req.path 会 strip 掉 mount path
|
|
65
|
+
// (如 "/api/p2p/tools/invoke" 会 变 "/tools/invoke"),但客户端签名时用
|
|
66
|
+
// 的是完整路径。不加 baseUrl 反面会导致 envelope canonicalize 两端不一致。
|
|
67
|
+
path: (req.baseUrl || '') + req.path,
|
|
68
|
+
body: req.body ?? null,
|
|
69
|
+
nonce,
|
|
70
|
+
timestamp: ts,
|
|
71
|
+
node_id: nid,
|
|
72
|
+
signature: sig,
|
|
73
|
+
};
|
|
74
|
+
const json = (0, signing_1.canonicalize)(envelope);
|
|
75
|
+
return new TextEncoder().encode(json);
|
|
76
|
+
};
|
|
77
|
+
function verifyPeerSignature(opts = {}) {
|
|
78
|
+
const discover = opts.discover ?? peer_tools_1.discoverEndpoints;
|
|
79
|
+
const buildDigest = opts.buildDigest ?? DEFAULT_DIGEST;
|
|
80
|
+
const skipChainLookup = opts.skipChainLookup ?? false;
|
|
81
|
+
return async (req, res, next) => {
|
|
82
|
+
// PRD-F Phase 2 §6 — inbound P2P call log埋点。req start + res.finish 写一条
|
|
83
|
+
// peer_call_log。失败路径(401/403/500)也必须记录,所以埋点放在最外层 try 之前。
|
|
84
|
+
const callStartMs = Date.now();
|
|
85
|
+
const remoteIp = (req.ip ?? req.socket.remoteAddress ?? '').toString().replace(/^::ffff:/, '');
|
|
86
|
+
const headerNodeId = req.header('X-Node-ID') || null;
|
|
87
|
+
const reqPath = (req.baseUrl || '') + req.path;
|
|
88
|
+
const reqMethod = req.method;
|
|
89
|
+
let toolName = null;
|
|
90
|
+
try {
|
|
91
|
+
// 仅对 /api/p2p/mcp/tools/invoke 解析 body.tool_name
|
|
92
|
+
if (reqPath.endsWith('/tools/invoke') && req.body && typeof req.body === 'object') {
|
|
93
|
+
const tn = req.body.tool_name;
|
|
94
|
+
if (typeof tn === 'string')
|
|
95
|
+
toolName = tn;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch { /* ignore body parse issues */ }
|
|
99
|
+
// PRD-F Phase 2 §6.1 (扩展): 捕获响应体存 peer_call_log,便于 Web 端展开查看。
|
|
100
|
+
// 包装 res.json / res.send 而不破坏原有行为,body 落入 res.locals._responseBody。
|
|
101
|
+
// 截断 10KB,防止大 payload 撑爆 SQLite。
|
|
102
|
+
const MAX_BODY_BYTES = 10 * 1024;
|
|
103
|
+
const originalJson = res.json.bind(res);
|
|
104
|
+
const originalSend = res.send.bind(res);
|
|
105
|
+
let capturedResponseBody = null;
|
|
106
|
+
res.json = ((body) => {
|
|
107
|
+
try {
|
|
108
|
+
capturedResponseBody = body;
|
|
109
|
+
res.locals._responseBody = body;
|
|
110
|
+
}
|
|
111
|
+
catch { /* swallow — capture is best-effort */ }
|
|
112
|
+
return originalJson(body);
|
|
113
|
+
});
|
|
114
|
+
res.send = ((body) => {
|
|
115
|
+
try {
|
|
116
|
+
if (capturedResponseBody === null) {
|
|
117
|
+
capturedResponseBody = body;
|
|
118
|
+
res.locals._responseBody = body;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch { /* swallow */ }
|
|
122
|
+
return originalSend(body);
|
|
123
|
+
});
|
|
124
|
+
const truncateBody = (v) => {
|
|
125
|
+
try {
|
|
126
|
+
if (v === undefined || v === null)
|
|
127
|
+
return null;
|
|
128
|
+
const json = typeof v === 'string' ? v : JSON.stringify(v);
|
|
129
|
+
if (json.length <= MAX_BODY_BYTES)
|
|
130
|
+
return json;
|
|
131
|
+
return json.slice(0, MAX_BODY_BYTES);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const captureRequestBody = () => {
|
|
138
|
+
try {
|
|
139
|
+
if (req.body === undefined || req.body === null)
|
|
140
|
+
return null;
|
|
141
|
+
if (Buffer.isBuffer(req.body))
|
|
142
|
+
return req.body.toString('utf8').slice(0, MAX_BODY_BYTES);
|
|
143
|
+
const json = typeof req.body === 'string' ? req.body : JSON.stringify(req.body);
|
|
144
|
+
if (json.length <= MAX_BODY_BYTES)
|
|
145
|
+
return json;
|
|
146
|
+
return json.slice(0, MAX_BODY_BYTES);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const writeCallLog = (status, error, trustLevel) => {
|
|
153
|
+
try {
|
|
154
|
+
const db = req.app?.locals?.db ?? null;
|
|
155
|
+
if (!db)
|
|
156
|
+
return; // 无 DB handle 时静默跳过,不影响主流程
|
|
157
|
+
const rtt = Date.now() - callStartMs;
|
|
158
|
+
const finalNodeId = req.peer?.node_id || headerNodeId;
|
|
159
|
+
const finalTrustLevel = trustLevel || req.peer?.trust_level || null;
|
|
160
|
+
// 捕获时尽量晚拿 —— res.finish 钩子里 res.locals 已有最终 body
|
|
161
|
+
const responseBodyStr = truncateBody(res.locals?._responseBody ?? capturedResponseBody);
|
|
162
|
+
const requestBodyStr = captureRequestBody();
|
|
163
|
+
const info = db.prepare(`INSERT INTO peer_call_log
|
|
164
|
+
(ts, direction, remote_node_id, remote_ip, method, path, tool_name,
|
|
165
|
+
status, error, rtt_ms, trust_level, request_body, response_body)
|
|
166
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(callStartMs, 'inbound', finalNodeId, remoteIp, reqMethod, reqPath, toolName, status, error, rtt, finalTrustLevel, requestBodyStr, responseBodyStr);
|
|
167
|
+
// 实时推送给 /ws/peer-monitor 订阅者
|
|
168
|
+
const row = {
|
|
169
|
+
id: Number(info.lastInsertRowid),
|
|
170
|
+
ts: callStartMs,
|
|
171
|
+
direction: 'inbound',
|
|
172
|
+
remote_node_id: finalNodeId,
|
|
173
|
+
remote_ip: remoteIp,
|
|
174
|
+
method: reqMethod,
|
|
175
|
+
path: reqPath,
|
|
176
|
+
tool_name: toolName,
|
|
177
|
+
status,
|
|
178
|
+
error,
|
|
179
|
+
rtt_ms: rtt,
|
|
180
|
+
trust_level: finalTrustLevel,
|
|
181
|
+
request_body: requestBodyStr,
|
|
182
|
+
response_body: responseBodyStr,
|
|
183
|
+
};
|
|
184
|
+
try {
|
|
185
|
+
peer_monitor_broadcaster_1.peerMonitorBroadcaster.broadcast({ type: 'peer-call', payload: row });
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
// 广播失败不应当影响主流程
|
|
189
|
+
console.error('[p2p-auth] peer-monitor broadcast failed:', e?.message ?? e);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
// 写日志失败不应当阻塞响应;用 console.error 留痕
|
|
194
|
+
console.error('[p2p-auth] peer_call_log write failed:', e?.message ?? e);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
// res.finish 钩子:响应真正写完后异步落库(覆盖成功 + 失败路径)
|
|
198
|
+
res.on('finish', () => {
|
|
199
|
+
// 此时 req.peer?.trust_level 可能已被 requireTrustLevel 写入
|
|
200
|
+
// 但 verifyPeerSignature 自身直接返回的错误(missing-headers / 401)也必须写
|
|
201
|
+
writeCallLog(res.statusCode, null, null);
|
|
202
|
+
});
|
|
203
|
+
try {
|
|
204
|
+
const nodeId = req.header('X-Node-ID');
|
|
205
|
+
const sigB64 = req.header('X-Signature');
|
|
206
|
+
const nonce = req.header('X-Nonce');
|
|
207
|
+
const ts = req.header('X-Timestamp');
|
|
208
|
+
if (!nodeId || !sigB64 || !nonce || !ts) {
|
|
209
|
+
return res.status(401).json({
|
|
210
|
+
error: 'missing-headers',
|
|
211
|
+
required: ['X-Node-ID', 'X-Signature', 'X-Nonce', 'X-Timestamp'],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
let sigBytes;
|
|
215
|
+
try {
|
|
216
|
+
sigBytes = (0, encoding_1.fromBase64)(sigB64);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return res.status(401).json({ error: 'invalid-signature-encoding' });
|
|
220
|
+
}
|
|
221
|
+
if (sigBytes.length !== 64) {
|
|
222
|
+
return res.status(401).json({ error: 'invalid-signature-length', expected: 64, got: sigBytes.length });
|
|
223
|
+
}
|
|
224
|
+
let publicKey;
|
|
225
|
+
if (skipChainLookup) {
|
|
226
|
+
// Tests can pre-populate req.peer via a custom resolver.
|
|
227
|
+
publicKey = (req.peer?.public_key) ?? new Uint8Array(33);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// Lesson #167: chain lookup 失败必须 fail-closed。
|
|
231
|
+
// discover() 抛错(本机 RPC 无 x/indexer 模块 / 节点不可达 / 查询超时)
|
|
232
|
+
// 时绝不能放行——显式 401 chain-lookup-failed,与签名错误区分开,
|
|
233
|
+
// 让运维一眼看出是"链查询挂了"而不是"签名不对"。
|
|
234
|
+
let discovered;
|
|
235
|
+
try {
|
|
236
|
+
discovered = await discover({ by: 'node_id', value: nodeId });
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
return res.status(401).json({
|
|
240
|
+
error: 'chain-lookup-failed',
|
|
241
|
+
node_id: nodeId,
|
|
242
|
+
hint: 'IndexerEndpoint query failed; check that the local chain node has x/indexer and is reachable',
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (discovered.endpoints.length === 0) {
|
|
246
|
+
return res.status(401).json({
|
|
247
|
+
error: 'unknown-peer',
|
|
248
|
+
node_id: nodeId,
|
|
249
|
+
hint: 'no IndexerEndpoint on chain; caller must register first',
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
publicKey = (0, encoding_1.fromBase64)(discovered.endpoints[0].public_key);
|
|
253
|
+
}
|
|
254
|
+
const digest = buildDigest(req);
|
|
255
|
+
const envelope = {
|
|
256
|
+
method: req.method,
|
|
257
|
+
// 宝贝 2026-06-23: 包含 mount path,否则与客户端签名时 path 不一致
|
|
258
|
+
path: (req.baseUrl || '') + req.path,
|
|
259
|
+
body: req.body ?? null,
|
|
260
|
+
nonce,
|
|
261
|
+
timestamp: ts,
|
|
262
|
+
node_id: nodeId,
|
|
263
|
+
signature: sigB64,
|
|
264
|
+
};
|
|
265
|
+
const ok = await (0, signing_1.verifySignature)(envelope, publicKey);
|
|
266
|
+
if (!ok) {
|
|
267
|
+
return res.status(401).json({
|
|
268
|
+
error: 'signature-verification-failed',
|
|
269
|
+
node_id: nodeId,
|
|
270
|
+
hint: 'check that headers/body match what was signed',
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
// Surface for downstream middlewares / handlers.
|
|
274
|
+
req.peer = {
|
|
275
|
+
node_id: nodeId,
|
|
276
|
+
public_key: publicKey,
|
|
277
|
+
trust_level: null,
|
|
278
|
+
};
|
|
279
|
+
next();
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
console.error('[p2p-auth] verifyPeerSignature error:', err?.message ?? err);
|
|
283
|
+
// Treat any unexpected failure as auth failure — never leak internal
|
|
284
|
+
// errors to the caller IN PRODUCTION. Dev mode surfaces a truncated hint.
|
|
285
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
286
|
+
const message = { error: 'signature-verification-error' };
|
|
287
|
+
if (!isProd) {
|
|
288
|
+
const hint = (err?.message ?? String(err)).slice(0, 240);
|
|
289
|
+
message.hint = `[dev] ${hint}`;
|
|
290
|
+
}
|
|
291
|
+
res.status(401).json(message);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function requireTrustLevel(level, opts = {}) {
|
|
296
|
+
const resolveDb = opts.resolveDb ?? ((req) => req.app.locals?.db ?? null);
|
|
297
|
+
return (req, res, next) => {
|
|
298
|
+
const peer = req.peer;
|
|
299
|
+
if (!peer) {
|
|
300
|
+
// Should be unreachable if verifyPeerSignature runs first, but guard
|
|
301
|
+
// anyway so a misconfigured chain fails closed.
|
|
302
|
+
return res.status(401).json({ error: 'no-peer-context' });
|
|
303
|
+
}
|
|
304
|
+
const db = resolveDb(req);
|
|
305
|
+
if (!db) {
|
|
306
|
+
return res.status(500).json({ error: 'no-database-handle' });
|
|
307
|
+
}
|
|
308
|
+
const row = db
|
|
309
|
+
.prepare('SELECT trust_level FROM peer_trust WHERE peer_node_id = ?')
|
|
310
|
+
.get(peer.node_id);
|
|
311
|
+
if (!row) {
|
|
312
|
+
return res.status(403).json({
|
|
313
|
+
error: 'peer-not-in-whitelist',
|
|
314
|
+
node_id: peer.node_id,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (row.trust_level !== 'read' && row.trust_level !== 'write' && row.trust_level !== 'admin') {
|
|
318
|
+
return res.status(500).json({
|
|
319
|
+
error: 'corrupt-trust-level',
|
|
320
|
+
node_id: peer.node_id,
|
|
321
|
+
stored: row.trust_level,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
peer.trust_level = row.trust_level;
|
|
325
|
+
if (TRUST_RANK[peer.trust_level] < TRUST_RANK[level]) {
|
|
326
|
+
return res.status(403).json({
|
|
327
|
+
error: 'insufficient-trust-level',
|
|
328
|
+
node_id: peer.node_id,
|
|
329
|
+
required: level,
|
|
330
|
+
actual: peer.trust_level,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
next();
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
class NonceCache {
|
|
337
|
+
maxSize;
|
|
338
|
+
ttlMs;
|
|
339
|
+
map = new Map(); // key → expiryMs
|
|
340
|
+
constructor(maxSize, ttlMs) {
|
|
341
|
+
this.maxSize = maxSize;
|
|
342
|
+
this.ttlMs = ttlMs;
|
|
343
|
+
}
|
|
344
|
+
/** Returns true if the nonce was fresh (i.e. not seen before, or was seen but expired). */
|
|
345
|
+
reserve(key, nowMs) {
|
|
346
|
+
// Sweep expired entries when we approach capacity (cheap amortized).
|
|
347
|
+
if (this.map.size >= this.maxSize) {
|
|
348
|
+
this.sweep(nowMs);
|
|
349
|
+
}
|
|
350
|
+
const existing = this.map.get(key);
|
|
351
|
+
if (existing !== undefined && existing > nowMs) {
|
|
352
|
+
// Still within TTL — duplicate.
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
// Either never seen, or expired → treat as fresh.
|
|
356
|
+
this.map.set(key, nowMs + this.ttlMs);
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
has(key) {
|
|
360
|
+
return this.map.has(key);
|
|
361
|
+
}
|
|
362
|
+
size() {
|
|
363
|
+
return this.map.size;
|
|
364
|
+
}
|
|
365
|
+
clear() {
|
|
366
|
+
this.map.clear();
|
|
367
|
+
}
|
|
368
|
+
sweep(nowMs) {
|
|
369
|
+
for (const [k, exp] of this.map) {
|
|
370
|
+
if (exp <= nowMs)
|
|
371
|
+
this.map.delete(k);
|
|
372
|
+
}
|
|
373
|
+
// Hard cap as last resort if everything is fresh.
|
|
374
|
+
if (this.map.size >= this.maxSize) {
|
|
375
|
+
const drop = Math.floor(this.maxSize / 4);
|
|
376
|
+
const iter = this.map.keys();
|
|
377
|
+
for (let i = 0; i < drop; i++) {
|
|
378
|
+
const k = iter.next().value;
|
|
379
|
+
if (k === undefined)
|
|
380
|
+
break;
|
|
381
|
+
this.map.delete(k);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function preventReplay(opts = {}) {
|
|
387
|
+
const windowSeconds = opts.windowSeconds ?? 300;
|
|
388
|
+
const maxNonces = opts.maxNonces ?? 10_000;
|
|
389
|
+
const ttlMs = opts.ttlMs ?? windowSeconds * 2 * 1000; // 2× window so the cache outlives any in-flight request
|
|
390
|
+
const nowMs = opts.nowMs ?? (() => Date.now());
|
|
391
|
+
const cache = new NonceCache(maxNonces, ttlMs);
|
|
392
|
+
return (req, res, next) => {
|
|
393
|
+
const nonce = req.header('X-Nonce');
|
|
394
|
+
const tsMs = parseInt(req.header('X-Timestamp') ?? '', 10);
|
|
395
|
+
if (!nonce || !Number.isFinite(tsMs)) {
|
|
396
|
+
return res.status(401).json({ error: 'missing-replay-headers' });
|
|
397
|
+
}
|
|
398
|
+
// 宝贝 2026-06-23: 客户端发 X-Timestamp 是毫秒(Date.now()),
|
|
399
|
+
// 但 windowSeconds 上下文是秒,这里必须换算为秒再比较,否则总是
|
|
400
|
+
// 报 timestamp-out-of-range (毫秒 vs 秒 差 1000× 超出任何合理窗口)
|
|
401
|
+
const ts = Math.floor(tsMs / 1000);
|
|
402
|
+
const now = Math.floor(nowMs() / 1000);
|
|
403
|
+
if (Math.abs(now - ts) > windowSeconds) {
|
|
404
|
+
return res.status(401).json({
|
|
405
|
+
error: 'timestamp-out-of-range',
|
|
406
|
+
now,
|
|
407
|
+
provided: ts,
|
|
408
|
+
window_seconds: windowSeconds,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
const peer = req.peer;
|
|
412
|
+
if (!peer) {
|
|
413
|
+
return res.status(401).json({ error: 'no-peer-context' });
|
|
414
|
+
}
|
|
415
|
+
const key = `${peer.node_id}:${nonce}`;
|
|
416
|
+
if (!cache.reserve(key, nowMs())) {
|
|
417
|
+
return res.status(401).json({
|
|
418
|
+
error: 'nonce-already-used',
|
|
419
|
+
node_id: peer.node_id,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
next();
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
/** Exposed for tests. */
|
|
426
|
+
exports.__testing__ = { NonceCache };
|
|
427
|
+
class PerPeerLimiter {
|
|
428
|
+
points;
|
|
429
|
+
windowMs;
|
|
430
|
+
nowFn;
|
|
431
|
+
buckets = new Map();
|
|
432
|
+
constructor(points, windowMs, nowFn) {
|
|
433
|
+
this.points = points;
|
|
434
|
+
this.windowMs = windowMs;
|
|
435
|
+
this.nowFn = nowFn;
|
|
436
|
+
}
|
|
437
|
+
/** Returns ms until the next request would be allowed, or 0 if allowed. */
|
|
438
|
+
consume(key) {
|
|
439
|
+
const now = this.nowFn();
|
|
440
|
+
let b = this.buckets.get(key);
|
|
441
|
+
if (!b || b.resetAtMs <= now) {
|
|
442
|
+
b = { count: 1, resetAtMs: now + this.windowMs };
|
|
443
|
+
this.buckets.set(key, b);
|
|
444
|
+
return { allowed: true, retryAfterMs: 0, remaining: this.points - 1 };
|
|
445
|
+
}
|
|
446
|
+
if (b.count >= this.points) {
|
|
447
|
+
return { allowed: false, retryAfterMs: b.resetAtMs - now, remaining: 0 };
|
|
448
|
+
}
|
|
449
|
+
b.count++;
|
|
450
|
+
return { allowed: true, retryAfterMs: 0, remaining: this.points - b.count };
|
|
451
|
+
}
|
|
452
|
+
size() {
|
|
453
|
+
return this.buckets.size;
|
|
454
|
+
}
|
|
455
|
+
clear() {
|
|
456
|
+
this.buckets.clear();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function rateLimitPerPeer(opts = {}) {
|
|
460
|
+
const points = opts.points ?? 10;
|
|
461
|
+
const duration = opts.duration ?? 60;
|
|
462
|
+
const windowMs = duration * 1000;
|
|
463
|
+
const nowFn = opts.nowMs ?? (() => Date.now());
|
|
464
|
+
const limiter = new PerPeerLimiter(points, windowMs, nowFn);
|
|
465
|
+
return (req, res, next) => {
|
|
466
|
+
const peer = req.peer;
|
|
467
|
+
if (!peer) {
|
|
468
|
+
return res.status(401).json({ error: 'no-peer-context' });
|
|
469
|
+
}
|
|
470
|
+
const verdict = limiter.consume(peer.node_id);
|
|
471
|
+
res.setHeader('X-RateLimit-Limit', String(points));
|
|
472
|
+
if (!verdict.allowed) {
|
|
473
|
+
const retrySec = Math.max(1, Math.ceil(verdict.retryAfterMs / 1000));
|
|
474
|
+
res.setHeader('Retry-After', String(retrySec));
|
|
475
|
+
return res.status(429).json({
|
|
476
|
+
error: 'rate-limit-exceeded',
|
|
477
|
+
retry_after_seconds: retrySec,
|
|
478
|
+
peer: peer.node_id,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
res.setHeader('X-RateLimit-Remaining', String(verdict.remaining));
|
|
482
|
+
next();
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
/** Exposed for tests. */
|
|
486
|
+
exports.__testing2__ = { PerPeerLimiter };
|
|
487
|
+
function ipRateLimit(opts = {}) {
|
|
488
|
+
const points = opts.points ?? 100;
|
|
489
|
+
const duration = opts.duration ?? 60;
|
|
490
|
+
const windowMs = duration * 1000;
|
|
491
|
+
const nowFn = opts.nowMs ?? (() => Date.now());
|
|
492
|
+
const keyFn = opts.keyFn ??
|
|
493
|
+
((req) => (req.ip ?? req.socket.remoteAddress ?? 'unknown').replace(/^::ffff:/, ''));
|
|
494
|
+
const limiter = new PerPeerLimiter(points, windowMs, nowFn);
|
|
495
|
+
return (req, res, next) => {
|
|
496
|
+
const verdict = limiter.consume(keyFn(req));
|
|
497
|
+
res.setHeader('X-RateLimit-Limit', String(points));
|
|
498
|
+
if (!verdict.allowed) {
|
|
499
|
+
const retrySec = Math.max(1, Math.ceil(verdict.retryAfterMs / 1000));
|
|
500
|
+
res.setHeader('Retry-After', String(retrySec));
|
|
501
|
+
return res.status(429).json({
|
|
502
|
+
error: 'ip-rate-limit-exceeded',
|
|
503
|
+
retry_after_seconds: retrySec,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
res.setHeader('X-RateLimit-Remaining', String(verdict.remaining));
|
|
507
|
+
next();
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
//# sourceMappingURL=p2p-auth.js.map
|