trustbase-seller-backend 0.7.0 → 0.7.2
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/.claude/skills/wechatpay-payment-integration/SKILL.md +165 -0
- package/.claude/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/.claude/skills/wechatpay-payment-integration/references/wechatpay-dev-cli/344/275/277/347/224/250/350/257/264/346/230/216.md +74 -0
- package/.claude/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/.claude/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/.claude/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/.claude/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/.claude/skills/wechatpay-payment-integration/scripts/bash/extract_and_sign.sh +231 -0
- package/.claude/skills/wechatpay-payment-integration/scripts/powershell/extract_and_sign.ps1 +199 -0
- package/.claude/skills/wechatpay-payment-integration/scripts/wechatpay-resource-sync.py +646 -0
- package/MERCHANT-EDITION.md +56 -56
- package/README.md +99 -99
- package/api/__tests__/test-utils.d.ts +32 -32
- package/api/__tests__/test-utils.js +89 -89
- package/api/db/case-library-types.d.ts +46 -46
- package/api/db/case-library-types.js +79 -79
- package/api/db/case-library.db.d.ts +4 -4
- package/api/db/case-library.db.js +70 -70
- package/api/email.d.ts +55 -55
- package/api/email.js +305 -305
- package/api/index.d.ts +21 -21
- package/api/index.js +40 -40
- package/api/integration-helpers.d.ts +152 -152
- package/api/integration-helpers.js +354 -354
- package/api/lib/case-summary.d.ts +9 -9
- package/api/lib/case-summary.js +29 -29
- package/api/middleware/p2p-auth.d.ts +139 -139
- package/api/middleware/p2p-auth.js +506 -506
- package/api/middleware/tool-policy.d.ts +46 -46
- package/api/middleware/tool-policy.js +155 -155
- package/api/oauth-adapters.d.ts +191 -191
- package/api/oauth-adapters.js +455 -455
- package/api/oauth-bridge.d.ts +55 -55
- package/api/oauth-bridge.js +615 -615
- package/api/oauth-router.d.ts +35 -35
- package/api/oauth-router.js +53 -53
- package/api/p2p-mcp.d.ts +68 -68
- package/api/p2p-mcp.js +285 -285
- package/api/payment-store.d.ts +55 -55
- package/api/payment-store.js +122 -122
- package/api/payment.d.ts +13 -13
- package/api/payment.js +215 -215
- package/api/pwa-stats.d.ts +66 -66
- package/api/pwa-stats.js +259 -259
- package/api/riskcontrol-adapters.d.ts +113 -113
- package/api/riskcontrol-adapters.js +209 -209
- package/api/riskcontrol-event-whitelist.d.ts +80 -80
- package/api/riskcontrol-event-whitelist.js +180 -180
- package/api/riskcontrol-rules.d.ts +104 -104
- package/api/riskcontrol-rules.js +381 -381
- package/api/riskcontrol-scoring.d.ts +71 -71
- package/api/riskcontrol-scoring.js +324 -324
- package/api/riskcontrol-service.d.ts +59 -59
- package/api/riskcontrol-service.js +200 -200
- package/api/riskcontrol-stream.d.ts +111 -111
- package/api/riskcontrol-stream.js +229 -229
- package/api/riskcontrol-v5-e2e-test.d.ts +14 -14
- package/api/riskcontrol-v5-e2e-test.js +203 -203
- package/api/riskcontrol-v5-router.d.ts +47 -47
- package/api/riskcontrol-v5-router.js +223 -223
- package/api/riskcontrol-webhook.d.ts +87 -87
- package/api/riskcontrol-webhook.js +282 -282
- package/api/routes/case-library.d.ts +3 -3
- package/api/routes/case-library.js +86 -86
- package/api/seller-earnings.d.ts +22 -22
- package/api/seller-earnings.js +244 -244
- package/api/seller-orders.d.ts +24 -24
- package/api/seller-orders.js +393 -393
- package/api/seller-products-chain.d.ts +30 -30
- package/api/seller-products-chain.js +303 -303
- package/api/seller-products.d.ts +29 -29
- package/api/seller-products.js +496 -444
- package/api/seller-reputation.d.ts +20 -20
- package/api/seller-reputation.js +202 -202
- package/api/seller-router.d.ts +32 -32
- package/api/seller-router.js +52 -52
- package/api/seller-settings.d.ts +22 -22
- package/api/seller-settings.js +270 -270
- package/api/shipping-store.d.ts +43 -43
- package/api/shipping-store.js +112 -112
- package/api/shipping.d.ts +15 -15
- package/api/shipping.js +238 -238
- package/api/social-endpoint-verify.d.ts +7 -7
- package/api/social-endpoint-verify.js +151 -151
- package/api/social-posts.d.ts +64 -64
- package/api/social-posts.js +510 -510
- package/api/social-router.d.ts +35 -35
- package/api/social-router.js +55 -55
- package/api/social-shares.d.ts +39 -39
- package/api/social-shares.js +364 -364
- package/api/social-whitelist.d.ts +40 -40
- package/api/social-whitelist.js +251 -251
- package/api/storefront-orders.d.ts +22 -22
- package/api/storefront-orders.js +344 -344
- package/api/storefront-products.d.ts +20 -20
- package/api/storefront-products.js +176 -176
- package/api/storefront-router.d.ts +32 -32
- package/api/storefront-router.js +46 -46
- package/api/storefront-user.d.ts +22 -22
- package/api/storefront-user.js +325 -325
- package/api/test-db-helper.d.ts +28 -28
- package/api/test-db-helper.js +106 -106
- package/api/traffic.d.ts +21 -21
- package/api/traffic.js +111 -111
- package/api/wc-credentials.d.ts +33 -33
- package/api/wc-credentials.js +273 -273
- package/api/wc-tracker-receiver.d.ts +46 -46
- package/api/wc-tracker-receiver.js +257 -257
- package/api/wc-v3.d.ts +39 -39
- package/api/wc-v3.js +665 -665
- package/audit-page-scripts.js +61 -61
- package/bin/tb-doctor.js +32 -32
- package/check.d.ts +1 -1
- package/check.js +18 -18
- package/config/export-import.d.ts +107 -107
- package/config/export-import.js +233 -233
- package/config/manager.d.ts +72 -72
- package/config/manager.js +245 -245
- package/config/profile.d.ts +41 -41
- package/config/profile.js +110 -110
- package/core/address.js +23 -23
- package/core/advanced-performance.d.ts +148 -148
- package/core/advanced-performance.js +323 -323
- package/core/alerting.d.ts +90 -90
- package/core/alerting.js +362 -362
- package/core/app-store.d.ts +76 -76
- package/core/app-store.js +206 -206
- package/core/boot-env.js +39 -39
- package/core/business-scope-schema.d.ts +59 -59
- package/core/business-scope-schema.js +119 -119
- package/core/cache.d.ts +52 -52
- package/core/cache.js +129 -129
- package/core/chain-listener.d.ts +46 -46
- package/core/chain-listener.js +253 -253
- package/core/chain-reject.js +107 -107
- package/core/chain-signer.js +268 -268
- package/core/chain-write-log.js +94 -0
- package/core/cleanup.d.ts +41 -41
- package/core/cleanup.js +143 -143
- package/core/cluster.d.ts +77 -77
- package/core/cluster.js +214 -214
- package/core/community-review.d.ts +81 -81
- package/core/community-review.js +200 -200
- package/core/connection-pool.d.ts +71 -71
- package/core/connection-pool.js +172 -172
- package/core/consistency.d.ts +129 -129
- package/core/consistency.js +339 -339
- package/core/content-ai.d.ts +302 -302
- package/core/content-ai.js +343 -343
- package/core/content-backfill.d.ts +54 -54
- package/core/content-backfill.js +173 -173
- package/core/conversion-rate-sync.d.ts +96 -96
- package/core/conversion-rate-sync.js +194 -194
- package/core/coverage-backup.d.ts +86 -86
- package/core/coverage-backup.js +264 -264
- package/core/db-installer.d.ts +107 -107
- package/core/db-installer.js +406 -406
- package/core/device-analyzer.d.ts +95 -95
- package/core/device-analyzer.js +234 -234
- package/core/discovery.d.ts +164 -164
- package/core/discovery.js +362 -362
- package/core/distributed.d.ts +171 -171
- package/core/distributed.js +421 -421
- package/core/doctor.js +249 -249
- package/core/enforcement.d.ts +56 -56
- package/core/enforcement.js +114 -114
- package/core/error-handler.d.ts +130 -130
- package/core/error-handler.js +290 -290
- package/core/federated-learning.d.ts +123 -123
- package/core/federated-learning.js +337 -337
- package/core/fingerprint.d.ts +94 -94
- package/core/fingerprint.js +312 -312
- package/core/geoip.d.ts +66 -66
- package/core/geoip.js +173 -173
- package/core/gossip.d.ts +140 -140
- package/core/gossip.js +371 -371
- package/core/governance.d.ts +146 -146
- package/core/governance.js +350 -350
- package/core/indexer-enhancements.d.ts +163 -163
- package/core/indexer-enhancements.js +428 -428
- package/core/intrusion-detection.d.ts +78 -78
- package/core/intrusion-detection.js +321 -321
- package/core/lifecycle.d.ts +117 -117
- package/core/lifecycle.js +295 -295
- package/core/location.d.ts +98 -98
- package/core/location.js +218 -218
- package/core/maxmind-integration.d.ts +67 -67
- package/core/maxmind-integration.js +244 -244
- package/core/migration.d.ts +57 -57
- package/core/migration.js +219 -219
- package/core/monitoring.d.ts +152 -152
- package/core/monitoring.js +405 -405
- package/core/offsite-backup.d.ts +70 -70
- package/core/offsite-backup.js +340 -340
- package/core/order-intent-store.js +83 -83
- package/core/order-intent.js +273 -273
- package/core/paths.js +116 -116
- package/core/performance.d.ts +172 -172
- package/core/performance.js +385 -385
- package/core/product-flag.d.ts +363 -363
- package/core/product-flag.js +464 -464
- package/core/protection.d.ts +138 -138
- package/core/protection.js +326 -326
- package/core/region-adapter.d.ts +151 -151
- package/core/region-adapter.js +504 -504
- package/core/region-configs.d.ts +11 -11
- package/core/region-configs.js +906 -906
- package/core/review-antifraud.d.ts +79 -79
- package/core/review-antifraud.js +192 -192
- package/core/rules-updater.d.ts +88 -88
- package/core/rules-updater.js +260 -260
- package/core/runtime-data.js +203 -203
- package/core/security.d.ts +143 -143
- package/core/security.js +389 -389
- package/core/seller-identity.js +78 -78
- package/core/session-manager.d.ts +92 -92
- package/core/session-manager.js +261 -261
- package/core/state-sync.d.ts +120 -120
- package/core/state-sync.js +286 -286
- package/core/testing.d.ts +96 -96
- package/core/testing.js +360 -360
- package/core/trust-score.d.ts +50 -50
- package/core/trust-score.js +187 -187
- package/core/trustworthiness.d.ts +139 -139
- package/core/trustworthiness.js +374 -374
- package/core/types.d.ts +257 -257
- package/core/types.js +8 -8
- package/core/upgrade-manager.d.ts +113 -113
- package/core/upgrade-manager.js +263 -263
- package/core/upgrader.d.ts +106 -106
- package/core/upgrader.js +386 -386
- package/core/websocket.d.ts +77 -77
- package/core/websocket.js +291 -291
- package/council/hidden-weight.d.ts +44 -44
- package/council/hidden-weight.js +134 -134
- package/db/email-migrations.sql +31 -31
- package/db/oauth-migrate.d.ts +38 -38
- package/db/oauth-migrate.js +169 -169
- package/db/oauth-migrations.sql +92 -92
- package/db/social-migrate.d.ts +11 -11
- package/db/social-migrate.js +8 -8
- package/db/social-migrations.sql +93 -93
- package/db/store-migrate.d.ts +32 -32
- package/db/store-migrate.js +150 -150
- package/db/store-migrations.sql +241 -241
- package/debug.d.ts +1 -1
- package/debug.js +17 -17
- package/docs/DEPLOYMENT.md +42 -42
- package/event-listener.d.ts +92 -92
- package/event-listener.js +320 -320
- package/event-whitelist.d.ts +78 -78
- package/event-whitelist.js +532 -532
- package/index.d.ts +44 -44
- package/index.js +360 -360
- package/init-node.d.ts +8 -8
- package/init-node.js +212 -212
- package/mcp/ai-tools.d.ts +1 -1
- package/mcp/ai-tools.js +222 -222
- package/mcp/auto-dispatch-tools.d.ts +1 -1
- package/mcp/auto-dispatch-tools.js +296 -296
- package/mcp/business-scope-tools.d.ts +10 -10
- package/mcp/business-scope-tools.js +178 -178
- package/mcp/buyer-tools.d.ts +66 -66
- package/mcp/buyer-tools.js +415 -415
- package/mcp/interfaces.d.ts +1057 -1057
- package/mcp/interfaces.js +12 -12
- package/mcp/m2m-chat-tool.d.ts +49 -49
- package/mcp/m2m-chat-tool.js +411 -411
- package/mcp/migrations.d.ts +29 -29
- package/mcp/migrations.js +103 -103
- package/mcp/peer-tools.d.ts +162 -162
- package/mcp/peer-tools.js +523 -523
- package/mcp/plugin-management-tools.d.ts +1 -1
- package/mcp/plugin-management-tools.js +279 -279
- package/mcp/product-type-tools.d.ts +1 -1
- package/mcp/product-type-tools.js +412 -412
- package/mcp/security-tools.d.ts +1 -1
- package/mcp/security-tools.js +281 -281
- package/mcp/seller-query-tools.d.ts +1 -1
- package/mcp/seller-query-tools.js +162 -162
- package/mcp/server.d.ts +10 -10
- package/mcp/server.js +67 -67
- package/mcp/standalone-server.d.ts +33 -33
- package/mcp/standalone-server.js +231 -231
- package/mcp/tools-integration.d.ts +30 -30
- package/mcp/tools-integration.js +287 -287
- package/mcp/web-panel.d.ts +17 -17
- package/mcp/web-panel.js +965 -965
- package/middleware/api-key-auth.d.ts +63 -63
- package/middleware/api-key-auth.js +280 -274
- package/middleware/scope-auth.d.ts +53 -53
- package/middleware/scope-auth.js +152 -152
- package/middleware/security.d.ts +47 -47
- package/middleware/security.js +216 -216
- package/middleware/wallet-auth.d.ts +53 -53
- package/middleware/wallet-auth.js +157 -157
- package/oauth/chain-revocation-sink.d.ts +23 -23
- package/oauth/chain-revocation-sink.js +46 -46
- package/oauth/gossip-sync.d.ts +24 -24
- package/oauth/gossip-sync.js +61 -61
- package/oauth/issuer-keys.d.ts +30 -30
- package/oauth/issuer-keys.js +116 -116
- package/oauth/peer-resolver.d.ts +24 -24
- package/oauth/peer-resolver.js +80 -80
- package/oauth/revocation-store.d.ts +57 -57
- package/oauth/revocation-store.js +64 -64
- package/oauth/token-v2.d.ts +100 -100
- package/oauth/token-v2.js +166 -166
- package/oracle/c5-glue.js +795 -795
- package/oracle/ops-console.js +654 -654
- package/oracle/oracle-sync.d.ts +28 -28
- package/oracle/oracle-sync.js +444 -444
- package/oracle/registry.d.ts +29 -29
- package/oracle/registry.js +61 -61
- package/p2p/availability.d.ts +187 -187
- package/p2p/availability.js +573 -573
- package/p2p/bootstrap.d.ts +41 -41
- package/p2p/bootstrap.js +145 -145
- package/p2p/buyer-client.d.ts +97 -97
- package/p2p/buyer-client.js +198 -198
- package/p2p/cdn-ddns.d.ts +207 -207
- package/p2p/cdn-ddns.js +499 -499
- package/p2p/cluster-sync.d.ts +114 -114
- package/p2p/cluster-sync.js +329 -329
- package/p2p/consistency-check.d.ts +29 -29
- package/p2p/consistency-check.js +167 -167
- package/p2p/endpoint-registry.d.ts +40 -40
- package/p2p/endpoint-registry.js +127 -127
- package/p2p/ipv6.d.ts +119 -119
- package/p2p/ipv6.js +424 -424
- package/p2p/protocol.d.ts +99 -99
- package/p2p/protocol.js +329 -329
- package/p2p/reliability.d.ts +55 -55
- package/p2p/reliability.js +239 -239
- package/p2p/seller-service.d.ts +52 -52
- package/p2p/seller-service.js +275 -275
- package/p2p/signing.d.ts +30 -30
- package/p2p/signing.js +94 -94
- package/package.json +73 -73
- package/payment/api.d.ts +8 -8
- package/payment/api.js +140 -140
- package/payment/gateway.d.ts +113 -113
- package/payment/gateway.js +230 -230
- package/payments/alipay/index.d.ts +17 -17
- package/payments/alipay/index.js +54 -54
- package/payments/base.d.ts +12 -12
- package/payments/base.js +27 -27
- package/payments/index.d.ts +17 -17
- package/payments/index.js +65 -65
- package/payments/template/index.d.ts +17 -17
- package/payments/template/index.js +56 -56
- package/payments/types.d.ts +41 -41
- package/payments/types.js +2 -2
- package/payments/wechat/index.d.ts +17 -17
- package/payments/wechat/index.js +53 -53
- package/payments/wechat/profitsharing.js +231 -231
- package/peer/chain-signer.d.ts +73 -73
- package/peer/chain-signer.js +148 -148
- package/peer/config.d.ts +70 -70
- package/peer/config.js +60 -60
- package/peer/index.d.ts +11 -11
- package/peer/index.js +45 -45
- package/peer/key-store.d.ts +65 -65
- package/peer/key-store.js +162 -162
- package/peer/proto-codec.d.ts +102 -102
- package/peer/proto-codec.js +422 -422
- package/peer/registrar.d.ts +87 -87
- package/peer/registrar.js +270 -270
- package/peer/registry.d.ts +30 -30
- package/peer/registry.js +142 -142
- package/plugins/auth.d.ts +192 -192
- package/plugins/auth.js +818 -818
- package/plugins/manager.d.ts +36 -36
- package/plugins/manager.js +82 -82
- package/plugins/oauth.d.ts +248 -248
- package/plugins/oauth.js +806 -806
- package/plugins/p2p-message.d.ts +132 -132
- package/plugins/p2p-message.js +349 -349
- package/plugins/postgresql.d.ts +53 -53
- package/plugins/postgresql.js +596 -596
- package/plugins/relationship.d.ts +140 -140
- package/plugins/relationship.js +290 -290
- package/plugins/sqlite.d.ts +199 -199
- package/plugins/sqlite.js +1532 -1532
- package/port-manager/disguise/ssh.d.ts +18 -18
- package/port-manager/disguise/ssh.js +103 -103
- package/port-manager/port-manager.d.ts +64 -64
- package/port-manager/port-manager.js +163 -163
- package/port-manager/port-scanner.d.ts +21 -21
- package/port-manager/port-scanner.js +186 -186
- package/port-manager/types.d.ts +50 -50
- package/port-manager/types.js +5 -5
- package/proto/amino/amino.proto +83 -83
- package/proto/cosmos/base/v1beta1/coin.proto +61 -61
- package/proto/cosmos/msg/v1/msg.proto +30 -30
- package/proto/cosmos_proto/cosmos.proto +111 -111
- package/proto/gogoproto/gogo.proto +145 -145
- package/proto/google/protobuf/descriptor.proto +1218 -1218
- package/proto/trustchain/marketplace/v1/product.proto +20 -20
- package/proto/trustchain/order/v1/tx.proto +156 -156
- package/proto/trustchain/reward/v1/tx.proto +62 -62
- package/proto/trustchain/serviceprovider/v1/paymentfact.proto +32 -32
- package/proto/trustchain/serviceprovider/v1/serviceprovider.proto +38 -38
- package/proto/trustchain/serviceprovider/v1/tx.proto +106 -106
- package/proto/trustchain/subchain/v1/params.proto +26 -26
- package/proto/trustchain/subchain/v1/tx.proto +33 -33
- package/proto/trustchain/verification/v1/params.proto +46 -46
- package/proto/trustchain/verification/v1/tx.proto +126 -126
- package/proto/trustchain/verification/v1/verification.proto +105 -105
- package/relationship-chain-api.d.ts +12 -12
- package/relationship-chain-api.js +138 -138
- package/relationship-chain.d.ts +89 -89
- package/relationship-chain.js +200 -200
- package/routes/agent-pay.js +13 -13
- package/routes/agent-serviceprovider.js +183 -183
- package/routes/ai.d.ts +53 -53
- package/routes/ai.js +289 -289
- package/routes/api-keys.d.ts +11 -11
- package/routes/api-keys.js +162 -162
- package/routes/app-store.d.ts +11 -11
- package/routes/app-store.js +206 -206
- package/routes/auth-management.d.ts +16 -16
- package/routes/auth-management.js +256 -256
- package/routes/auth.d.ts +8 -8
- package/routes/auth.js +845 -845
- package/routes/brand.d.ts +2 -2
- package/routes/brand.js +108 -108
- package/routes/buyer-shop.js +470 -470
- package/routes/chain-registry.d.ts +10 -10
- package/routes/chain-registry.js +50 -50
- package/routes/chain-writes-insurance.d.ts +16 -16
- package/routes/chain-writes-insurance.js +58 -58
- package/routes/chain-writes-pledge.d.ts +33 -33
- package/routes/chain-writes-pledge.js +204 -204
- package/routes/chain-writes-products.d.ts +65 -65
- package/routes/chain-writes-products.js +438 -392
- package/routes/chain-writes.d.ts +77 -77
- package/routes/chain-writes.js +669 -661
- package/routes/chain.d.ts +9 -9
- package/routes/chain.js +44 -44
- package/routes/compliance.d.ts +2 -2
- package/routes/compliance.js +52 -52
- package/routes/council.d.ts +2 -2
- package/routes/council.js +476 -476
- package/routes/crosschain.d.ts +10 -10
- package/routes/crosschain.js +38 -38
- package/routes/device.d.ts +2 -2
- package/routes/device.js +72 -72
- package/routes/devreward.d.ts +53 -53
- package/routes/devreward.js +111 -111
- package/routes/economy.d.ts +49 -49
- package/routes/economy.js +269 -269
- package/routes/flowback.d.ts +31 -31
- package/routes/flowback.js +81 -81
- package/routes/insurance.d.ts +9 -9
- package/routes/insurance.js +69 -69
- package/routes/m2m.d.ts +9 -9
- package/routes/m2m.js +29 -29
- package/routes/marketplace.d.ts +14 -14
- package/routes/marketplace.js +395 -395
- package/routes/node-config.d.ts +5 -5
- package/routes/node-config.js +499 -499
- package/routes/oauth-revocation.d.ts +41 -41
- package/routes/oauth-revocation.js +98 -98
- package/routes/oauth.d.ts +16 -16
- package/routes/oauth.js +699 -699
- package/routes/onboard.html +1483 -1483
- package/routes/onboard.js +944 -944
- package/routes/order.d.ts +7 -7
- package/routes/order.js +591 -591
- package/routes/p2p-api.d.ts +32 -32
- package/routes/p2p-api.js +268 -268
- package/routes/p2p-message.d.ts +19 -19
- package/routes/p2p-message.js +236 -236
- package/routes/peer.d.ts +21 -21
- package/routes/peer.js +210 -210
- package/routes/plugins.d.ts +3 -3
- package/routes/plugins.js +137 -137
- package/routes/port-manager.d.ts +5 -5
- package/routes/port-manager.js +211 -211
- package/routes/relationship.d.ts +6 -6
- package/routes/relationship.js +313 -313
- package/routes/relay.d.ts +2 -2
- package/routes/relay.js +181 -181
- package/routes/reputation.d.ts +9 -9
- package/routes/reputation.js +140 -140
- package/routes/reward.d.ts +2 -2
- package/routes/reward.js +129 -129
- package/routes/security-monitoring.d.ts +11 -11
- package/routes/security-monitoring.js +372 -372
- package/routes/shop.d.ts +7 -7
- package/routes/shop.js +163 -163
- package/routes/social.d.ts +21 -21
- package/routes/social.js +94 -94
- package/routes/sp-admin.js +32 -32
- package/routes/sp-applyment.js +285 -285
- package/routes/sp-commission.js +119 -119
- package/routes/sp-notify.js +424 -424
- package/routes/sp-tunnel.js +354 -354
- package/routes/subchain.d.ts +17 -17
- package/routes/subchain.js +105 -105
- package/routes/trustcoin.d.ts +16 -16
- package/routes/trustcoin.js +148 -148
- package/routes/twofa.d.ts +6 -6
- package/routes/twofa.js +104 -104
- package/routes/verification.d.ts +7 -7
- package/routes/verification.js +233 -233
- package/routes/wallet.d.ts +3 -3
- package/routes/wallet.js +763 -763
- package/run-auth.d.ts +7 -7
- package/run-auth.js +81 -81
- package/run-p2p-message.d.ts +7 -7
- package/run-p2p-message.js +81 -81
- package/run-relationship.d.ts +11 -11
- package/run-relationship.js +181 -181
- package/run-unified.d.ts +12 -12
- package/run-unified.js +3 -0
- package/run.d.ts +11 -11
- package/run.js +888 -888
- package/search/ranking.d.ts +54 -54
- package/search/ranking.js +66 -66
- package/shipping/base.d.ts +14 -14
- package/shipping/base.js +38 -38
- package/shipping/index.d.ts +18 -18
- package/shipping/index.js +71 -71
- package/shipping/sf-express/index.d.ts +22 -22
- package/shipping/sf-express/index.js +70 -70
- package/shipping/template/index.d.ts +19 -19
- package/shipping/template/index.js +73 -73
- package/shipping/types.d.ts +70 -70
- package/shipping/types.js +5 -5
- package/shipping/virtual/index.d.ts +18 -18
- package/shipping/virtual/index.js +53 -53
- package/shipping/yto/index.d.ts +17 -17
- package/shipping/yto/index.js +58 -58
- package/shipping/zto/index.d.ts +17 -17
- package/shipping/zto/index.js +58 -58
- package/skills-lock.json +11 -11
- package/src/db/email-migrations.sql +31 -31
- package/src/db/oauth-migrations.sql +92 -92
- package/src/db/social-migrations.sql +93 -93
- package/src/db/store-migrations.sql +241 -241
- package/test-agent-pay-lifecycle.js +186 -186
- package/test-agent-pay-wechat.js +291 -291
- package/test-api-key-auth-exempt.js +121 -0
- package/test-api-key-revoke.js +167 -167
- package/test-auth-register-ratelimit.js +132 -132
- package/test-auth-tv2.d.ts +1 -1
- package/test-auth-tv2.js +173 -173
- package/test-buyer-shop-ps.js +238 -238
- package/test-buyer-shop.js +334 -334
- package/test-canonsign-cross.d.ts +1 -1
- package/test-canonsign-cross.js +31 -31
- package/test-chain-signer.js +188 -188
- package/test-chain-write-log.js +76 -0
- package/test-chain-writes-audit-integration.js +36 -0
- package/test-env-truthy.js +50 -50
- package/test-laneC.js +85 -85
- package/test-onboard-applyment.js +823 -823
- package/test-onboard-backup.js +208 -208
- package/test-onboard-contract.js +94 -94
- package/test-ops-console-boundary.js +147 -147
- package/test-oracle-glue.js +354 -354
- package/test-oracle-pool-refill.js +171 -171
- package/test-order-create-v394.js +358 -358
- package/test-order-intent.js +245 -245
- package/test-order-lifecycle-v394.js +528 -528
- package/test-p2p-message.d.ts +12 -12
- package/test-p2p-message.js +105 -105
- package/test-product-type-chain.js +73 -0
- package/test-product-type-write.js +211 -0
- package/test-product-type.js +173 -173
- package/test-relationship-chain.d.ts +12 -12
- package/test-relationship-chain.js +102 -102
- package/test-runtime-data-path.js +217 -217
- package/test-seller-identity.js +74 -74
- package/test-signing-paths.js +104 -104
- package/test-sp-admin.js +289 -289
- package/test-sp-applyment.js +583 -583
- package/test-sp-gateway.js +435 -435
- package/test-sp-tunnel.js +311 -311
- package/test-token-v2.d.ts +1 -1
- package/test-token-v2.js +170 -170
- package/test-wallet-auth-nonce.d.ts +11 -11
- package/test-wallet-auth-nonce.js +125 -125
- package/test-wallet-submatch.d.ts +12 -12
- package/test-wallet-submatch.js +85 -85
- package/tls/self-signed.d.ts +11 -11
- package/tls/self-signed.js +62 -62
- package/tools/brand.d.ts +10 -10
- package/tools/brand.js +74 -74
- package/tools/chainregistry.d.ts +17 -17
- package/tools/chainregistry.js +155 -155
- package/tools/compliance.d.ts +13 -13
- package/tools/compliance.js +44 -44
- package/tools/council.d.ts +16 -16
- package/tools/council.js +74 -74
- package/tools/device.d.ts +12 -12
- package/tools/device.js +44 -44
- package/tools/devreward.d.ts +14 -14
- package/tools/devreward.js +175 -175
- package/tools/economy.d.ts +13 -13
- package/tools/economy.js +168 -168
- package/tools/flowback.d.ts +13 -13
- package/tools/flowback.js +132 -132
- package/tools/insurance.d.ts +12 -12
- package/tools/insurance.js +44 -44
- package/tools/marketplace.d.ts +11 -11
- package/tools/marketplace.js +112 -112
- package/tools/mock-tunnel-merchant.js +25 -25
- package/tools/order.d.ts +11 -11
- package/tools/order.js +87 -87
- package/tools/recovery.d.ts +13 -13
- package/tools/recovery.js +151 -151
- package/tools/relay.d.ts +14 -14
- package/tools/relay.js +129 -129
- package/tools/reputation.d.ts +19 -19
- package/tools/reputation.js +49 -49
- package/tools/reputation_seller_credit.d.ts +15 -15
- package/tools/reputation_seller_credit.js +99 -99
- package/tools/reward.d.ts +13 -13
- package/tools/reward.js +70 -70
- package/tools/shop.d.ts +13 -13
- package/tools/shop.js +82 -82
- package/tools/tunnel-e2e-check.sh +20 -20
- package/tools/verification.d.ts +11 -11
- package/tools/verification.js +83 -83
- package/types/store.d.ts +254 -254
- package/types/store.js +18 -18
- package/utils/aes-gcm.d.ts +62 -62
- package/utils/aes-gcm.js +178 -178
- package/utils/api-response.d.ts +50 -50
- package/utils/api-response.js +64 -64
- package/utils/base32.d.ts +4 -4
- package/utils/base32.js +19 -19
- package/utils/crypto.d.ts +76 -76
- package/utils/crypto.js +163 -163
- package/utils/encryption.d.ts +80 -80
- package/utils/encryption.js +246 -246
- package/utils/env.js +20 -20
- package/utils/jwt.d.ts +109 -109
- package/utils/jwt.js +274 -274
- package/utils/qrcode-reader.d.ts +21 -21
- package/utils/qrcode.d.ts +25 -25
- package/utils/qrcode.js +91 -91
- package/utils/totp.d.ts +2 -2
- package/utils/totp.js +57 -57
- package/utils/two-factor-auth.d.ts +15 -15
- package/utils/two-factor-auth.js +149 -149
- package/verifyer/hsm.d.ts +69 -69
- package/verifyer/hsm.js +481 -481
- package/verifyer/index.d.ts +80 -80
- package/verifyer/index.js +371 -371
- package/ws/peer-monitor-broadcaster.d.ts +23 -23
- package/ws/peer-monitor-broadcaster.js +55 -55
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scope Auth Middleware — 数据租客原则的核心执行层 (PRD-NEW §27.6/§27.7)
|
|
3
|
-
*
|
|
4
|
-
* 用户是房东,应用是租客。requireScope 是「检查租客有没有这把钥匙」的门卫。
|
|
5
|
-
*
|
|
6
|
-
* Token 优先级:
|
|
7
|
-
* 1. 第三方 OAuth token (OAuthPlugin.validateAccessToken) → 严格 scope 强制
|
|
8
|
-
* 2. 第一方登录 token (AuthPlugin.verifyToken) → 隐式全权限(用户自己的 session)
|
|
9
|
-
*
|
|
10
|
-
* 第一方 = 隐式全权限:用户自己登录操作自己的数据,不受 scope 限制。
|
|
11
|
-
* 第三方 = 严格 scope:App 只能访问用户授权的 scope(逐项 toggle 的子集)。
|
|
12
|
-
*/
|
|
13
|
-
import { Request, Response, NextFunction } from 'express';
|
|
14
|
-
import type { OAuthPlugin } from '../plugins/oauth';
|
|
15
|
-
import type { AuthPlugin } from '../plugins/auth';
|
|
16
|
-
import type { IssuerKeyCache } from '../oauth/issuer-keys';
|
|
17
|
-
import type { RevocationStore } from '../oauth/revocation-store';
|
|
18
|
-
export interface OAuthUser {
|
|
19
|
-
userId: string;
|
|
20
|
-
address: string;
|
|
21
|
-
scopes: string[];
|
|
22
|
-
isOAuth: boolean;
|
|
23
|
-
clientId?: string;
|
|
24
|
-
tokenV2?: boolean;
|
|
25
|
-
}
|
|
26
|
-
/** R2-1: tv2 离线验证依赖(注入即启用;不注入则 tv2 token 一律 401) */
|
|
27
|
-
export interface ScopeAuthV2Deps {
|
|
28
|
-
issuerKeys: IssuerKeyCache;
|
|
29
|
-
revocations: RevocationStore;
|
|
30
|
-
}
|
|
31
|
-
declare module 'express-serve-static-core' {
|
|
32
|
-
interface Request {
|
|
33
|
-
oauthUser?: OAuthUser;
|
|
34
|
-
walletAddress?: string;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 写操作钱包挑战(R2-1 设计 §4 + R2-2 预研方案 B):写/高危操作必须叠加 walletAuth,
|
|
39
|
-
* 且签名者 === token 当事人(tv2=sub;第一方=用户地址)。token 丢了没有用户私钥
|
|
40
|
-
* 照样用不了写操作。
|
|
41
|
-
* 用法:router.post('/write-op', walletAuth(), requireScope('x:write'), requireWalletSubMatch(), handler)
|
|
42
|
-
* (walletAuth 在前,requireScope 在后。)
|
|
43
|
-
*
|
|
44
|
-
* 管辖范围(R2-2 方案 B,预研实现,待 kimi 拍板):
|
|
45
|
-
* - tv2 token(tokenV2=true)→ 强制 walletAuth + signer===sub(R2-1 已有)
|
|
46
|
-
* - 第一方登录 token(isOAuth=false)→ 强制 walletAuth + signer===address
|
|
47
|
-
* 收口"隐式全权限":第三方 App 即使拿到第一方 token 也做不了写操作。
|
|
48
|
-
* 不做 scope 检查——第一方默认 scopes 只有 profile/email,加检查会破坏
|
|
49
|
-
* 所有依赖第一方全权限的现有端点(orders/marketplace 等)。
|
|
50
|
-
* - v1 第三方 OAuth token(isOAuth=true 非 tv2)→ 保持豁免(本就有严格 scope 制)
|
|
51
|
-
*/
|
|
52
|
-
export declare function requireWalletSubMatch(): (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
53
|
-
export declare function createScopeAuth(oauthPlugin: OAuthPlugin, authPlugin: AuthPlugin, v2Deps?: ScopeAuthV2Deps): (scope: string) => (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
1
|
+
/**
|
|
2
|
+
* Scope Auth Middleware — 数据租客原则的核心执行层 (PRD-NEW §27.6/§27.7)
|
|
3
|
+
*
|
|
4
|
+
* 用户是房东,应用是租客。requireScope 是「检查租客有没有这把钥匙」的门卫。
|
|
5
|
+
*
|
|
6
|
+
* Token 优先级:
|
|
7
|
+
* 1. 第三方 OAuth token (OAuthPlugin.validateAccessToken) → 严格 scope 强制
|
|
8
|
+
* 2. 第一方登录 token (AuthPlugin.verifyToken) → 隐式全权限(用户自己的 session)
|
|
9
|
+
*
|
|
10
|
+
* 第一方 = 隐式全权限:用户自己登录操作自己的数据,不受 scope 限制。
|
|
11
|
+
* 第三方 = 严格 scope:App 只能访问用户授权的 scope(逐项 toggle 的子集)。
|
|
12
|
+
*/
|
|
13
|
+
import { Request, Response, NextFunction } from 'express';
|
|
14
|
+
import type { OAuthPlugin } from '../plugins/oauth';
|
|
15
|
+
import type { AuthPlugin } from '../plugins/auth';
|
|
16
|
+
import type { IssuerKeyCache } from '../oauth/issuer-keys';
|
|
17
|
+
import type { RevocationStore } from '../oauth/revocation-store';
|
|
18
|
+
export interface OAuthUser {
|
|
19
|
+
userId: string;
|
|
20
|
+
address: string;
|
|
21
|
+
scopes: string[];
|
|
22
|
+
isOAuth: boolean;
|
|
23
|
+
clientId?: string;
|
|
24
|
+
tokenV2?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** R2-1: tv2 离线验证依赖(注入即启用;不注入则 tv2 token 一律 401) */
|
|
27
|
+
export interface ScopeAuthV2Deps {
|
|
28
|
+
issuerKeys: IssuerKeyCache;
|
|
29
|
+
revocations: RevocationStore;
|
|
30
|
+
}
|
|
31
|
+
declare module 'express-serve-static-core' {
|
|
32
|
+
interface Request {
|
|
33
|
+
oauthUser?: OAuthUser;
|
|
34
|
+
walletAddress?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 写操作钱包挑战(R2-1 设计 §4 + R2-2 预研方案 B):写/高危操作必须叠加 walletAuth,
|
|
39
|
+
* 且签名者 === token 当事人(tv2=sub;第一方=用户地址)。token 丢了没有用户私钥
|
|
40
|
+
* 照样用不了写操作。
|
|
41
|
+
* 用法:router.post('/write-op', walletAuth(), requireScope('x:write'), requireWalletSubMatch(), handler)
|
|
42
|
+
* (walletAuth 在前,requireScope 在后。)
|
|
43
|
+
*
|
|
44
|
+
* 管辖范围(R2-2 方案 B,预研实现,待 kimi 拍板):
|
|
45
|
+
* - tv2 token(tokenV2=true)→ 强制 walletAuth + signer===sub(R2-1 已有)
|
|
46
|
+
* - 第一方登录 token(isOAuth=false)→ 强制 walletAuth + signer===address
|
|
47
|
+
* 收口"隐式全权限":第三方 App 即使拿到第一方 token 也做不了写操作。
|
|
48
|
+
* 不做 scope 检查——第一方默认 scopes 只有 profile/email,加检查会破坏
|
|
49
|
+
* 所有依赖第一方全权限的现有端点(orders/marketplace 等)。
|
|
50
|
+
* - v1 第三方 OAuth token(isOAuth=true 非 tv2)→ 保持豁免(本就有严格 scope 制)
|
|
51
|
+
*/
|
|
52
|
+
export declare function requireWalletSubMatch(): (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
53
|
+
export declare function createScopeAuth(oauthPlugin: OAuthPlugin, authPlugin: AuthPlugin, v2Deps?: ScopeAuthV2Deps): (scope: string) => (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
54
54
|
//# sourceMappingURL=scope-auth.d.ts.map
|
package/middleware/scope-auth.js
CHANGED
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireWalletSubMatch = requireWalletSubMatch;
|
|
4
|
-
exports.createScopeAuth = createScopeAuth;
|
|
5
|
-
const token_v2_1 = require("../oauth/token-v2");
|
|
6
|
-
/**
|
|
7
|
-
* 写操作钱包挑战(R2-1 设计 §4 + R2-2 预研方案 B):写/高危操作必须叠加 walletAuth,
|
|
8
|
-
* 且签名者 === token 当事人(tv2=sub;第一方=用户地址)。token 丢了没有用户私钥
|
|
9
|
-
* 照样用不了写操作。
|
|
10
|
-
* 用法:router.post('/write-op', walletAuth(), requireScope('x:write'), requireWalletSubMatch(), handler)
|
|
11
|
-
* (walletAuth 在前,requireScope 在后。)
|
|
12
|
-
*
|
|
13
|
-
* 管辖范围(R2-2 方案 B,预研实现,待 kimi 拍板):
|
|
14
|
-
* - tv2 token(tokenV2=true)→ 强制 walletAuth + signer===sub(R2-1 已有)
|
|
15
|
-
* - 第一方登录 token(isOAuth=false)→ 强制 walletAuth + signer===address
|
|
16
|
-
* 收口"隐式全权限":第三方 App 即使拿到第一方 token 也做不了写操作。
|
|
17
|
-
* 不做 scope 检查——第一方默认 scopes 只有 profile/email,加检查会破坏
|
|
18
|
-
* 所有依赖第一方全权限的现有端点(orders/marketplace 等)。
|
|
19
|
-
* - v1 第三方 OAuth token(isOAuth=true 非 tv2)→ 保持豁免(本就有严格 scope 制)
|
|
20
|
-
*/
|
|
21
|
-
function requireWalletSubMatch() {
|
|
22
|
-
return (req, res, next) => {
|
|
23
|
-
const ou = req.oauthUser;
|
|
24
|
-
if (!ou)
|
|
25
|
-
return next();
|
|
26
|
-
// 豁免: v1 第三方 token (严格 scope 制已管), 不在本中间件管辖
|
|
27
|
-
if (ou.isOAuth && !ou.tokenV2)
|
|
28
|
-
return next();
|
|
29
|
-
if (!req.walletAddress) {
|
|
30
|
-
return res.status(401).json({
|
|
31
|
-
error: 'wallet-challenge-required',
|
|
32
|
-
message: ou.tokenV2 ? 'write op with tv2 token requires walletAuth headers' : 'write op with first-party token requires walletAuth headers',
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (req.walletAddress !== ou.address) {
|
|
36
|
-
return res.status(403).json({ error: 'wallet-sub-mismatch', message: 'signer must equal token subject' });
|
|
37
|
-
}
|
|
38
|
-
next();
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function createScopeAuth(oauthPlugin, authPlugin, v2Deps) {
|
|
42
|
-
/**
|
|
43
|
-
* requireScope(scope) — 路由级中间件,校验 token 是否持有指定 scope。
|
|
44
|
-
*
|
|
45
|
-
* 第一方 token 隐式通过(用户自己 = 全权限)。
|
|
46
|
-
* 第三方 token 必须 scopes.includes(scope),否则 403 insufficient_scope。
|
|
47
|
-
*/
|
|
48
|
-
return function requireScope(scope) {
|
|
49
|
-
return async (req, res, next) => {
|
|
50
|
-
const authHeader = req.headers.authorization;
|
|
51
|
-
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
52
|
-
return res.status(401).json({ error: 'missing_token', message: 'Authorization Bearer token required' });
|
|
53
|
-
}
|
|
54
|
-
const token = authHeader.substring(7);
|
|
55
|
-
// 0. tv2 结构化令牌 → 跨索引器离线验证(R2-1)
|
|
56
|
-
// 不查本地用户表(B 节点没有该用户行),sub 即身份。
|
|
57
|
-
if (token.startsWith(token_v2_1.TOKEN_V2_PREFIX)) {
|
|
58
|
-
if (!v2Deps) {
|
|
59
|
-
return res.status(401).json({ error: 'token-v2-not-enabled' });
|
|
60
|
-
}
|
|
61
|
-
let issuerPubkey;
|
|
62
|
-
const parsed = (0, token_v2_1.parseTokenV2)(token);
|
|
63
|
-
if (!parsed) {
|
|
64
|
-
return res.status(401).json({ error: 'invalid_token', message: 'malformed tv2 token' });
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
issuerPubkey = await v2Deps.issuerKeys.get(parsed.payload.iss);
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
return res.status(503).json({ error: 'issuer-key-unavailable', message: 'chain query failed and no cached key' });
|
|
71
|
-
}
|
|
72
|
-
if (!issuerPubkey) {
|
|
73
|
-
return res.status(401).json({ error: 'unknown-issuer' });
|
|
74
|
-
}
|
|
75
|
-
const verdict = await (0, token_v2_1.verifyTokenV2Offline)(token, issuerPubkey, v2Deps.revocations);
|
|
76
|
-
if (!verdict.ok) {
|
|
77
|
-
return res.status(401).json({ error: 'invalid_token', reason: verdict.reason });
|
|
78
|
-
}
|
|
79
|
-
const p = verdict.payload;
|
|
80
|
-
if (!p.scopes.includes(scope)) {
|
|
81
|
-
return res.status(403).json({ error: 'insufficient_scope', required: scope, granted: p.scopes });
|
|
82
|
-
}
|
|
83
|
-
req.oauthUser = {
|
|
84
|
-
userId: p.sub,
|
|
85
|
-
address: p.sub,
|
|
86
|
-
scopes: p.scopes,
|
|
87
|
-
isOAuth: true,
|
|
88
|
-
clientId: p.client_id,
|
|
89
|
-
tokenV2: true,
|
|
90
|
-
};
|
|
91
|
-
res.on('finish', () => {
|
|
92
|
-
oauthPlugin.logAccess({
|
|
93
|
-
appName: '', clientId: p.client_id,
|
|
94
|
-
userId: p.sub, userAddress: p.sub,
|
|
95
|
-
endpoint: req.path, method: req.method,
|
|
96
|
-
scopeUsed: scope, responseStatus: res.statusCode,
|
|
97
|
-
}).catch(() => { });
|
|
98
|
-
});
|
|
99
|
-
return next();
|
|
100
|
-
}
|
|
101
|
-
// 1. 先试第三方 OAuth token
|
|
102
|
-
const oauthInfo = await oauthPlugin.validateAccessToken(token);
|
|
103
|
-
if (oauthInfo) {
|
|
104
|
-
// 第三方 → 严格 scope 强制
|
|
105
|
-
if (!oauthInfo.scopes.includes(scope)) {
|
|
106
|
-
return res.status(403).json({ error: 'insufficient_scope', required: scope, granted: oauthInfo.scopes });
|
|
107
|
-
}
|
|
108
|
-
// 解析 address
|
|
109
|
-
const user = await authPlugin.getUser(oauthInfo.userId);
|
|
110
|
-
if (!user) {
|
|
111
|
-
return res.status(401).json({ error: 'invalid_token', message: 'User not found' });
|
|
112
|
-
}
|
|
113
|
-
req.oauthUser = {
|
|
114
|
-
userId: oauthInfo.userId,
|
|
115
|
-
address: user.address,
|
|
116
|
-
scopes: oauthInfo.scopes,
|
|
117
|
-
isOAuth: true,
|
|
118
|
-
clientId: oauthInfo.clientId,
|
|
119
|
-
};
|
|
120
|
-
// 访问日志(PRD §27.9):仅第三方 OAuth token 记录,第一方不记
|
|
121
|
-
const appName = ''; // app_name 需要 JOIN 查,这里只记 endpoint/scope
|
|
122
|
-
res.on('finish', () => {
|
|
123
|
-
oauthPlugin.logAccess({
|
|
124
|
-
appName, clientId: oauthInfo.clientId,
|
|
125
|
-
userId: oauthInfo.userId, userAddress: user.address,
|
|
126
|
-
endpoint: req.path, method: req.method,
|
|
127
|
-
scopeUsed: scope, responseStatus: res.statusCode,
|
|
128
|
-
}).catch(() => { });
|
|
129
|
-
});
|
|
130
|
-
return next();
|
|
131
|
-
}
|
|
132
|
-
// 2. 后试第一方登录 token
|
|
133
|
-
const sessionInfo = await authPlugin.verifyToken(token);
|
|
134
|
-
if (sessionInfo) {
|
|
135
|
-
// 第一方 → 隐式全权限(用户自己的 session)
|
|
136
|
-
const user = await authPlugin.getUser(sessionInfo.userId);
|
|
137
|
-
if (!user) {
|
|
138
|
-
return res.status(401).json({ error: 'invalid_token', message: 'User not found' });
|
|
139
|
-
}
|
|
140
|
-
req.oauthUser = {
|
|
141
|
-
userId: sessionInfo.userId,
|
|
142
|
-
address: user.address,
|
|
143
|
-
scopes: sessionInfo.scopes,
|
|
144
|
-
isOAuth: false,
|
|
145
|
-
};
|
|
146
|
-
return next();
|
|
147
|
-
}
|
|
148
|
-
// 3. 都不匹配 → 无效 token
|
|
149
|
-
return res.status(401).json({ error: 'invalid_token', message: 'Token not recognized or expired' });
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireWalletSubMatch = requireWalletSubMatch;
|
|
4
|
+
exports.createScopeAuth = createScopeAuth;
|
|
5
|
+
const token_v2_1 = require("../oauth/token-v2");
|
|
6
|
+
/**
|
|
7
|
+
* 写操作钱包挑战(R2-1 设计 §4 + R2-2 预研方案 B):写/高危操作必须叠加 walletAuth,
|
|
8
|
+
* 且签名者 === token 当事人(tv2=sub;第一方=用户地址)。token 丢了没有用户私钥
|
|
9
|
+
* 照样用不了写操作。
|
|
10
|
+
* 用法:router.post('/write-op', walletAuth(), requireScope('x:write'), requireWalletSubMatch(), handler)
|
|
11
|
+
* (walletAuth 在前,requireScope 在后。)
|
|
12
|
+
*
|
|
13
|
+
* 管辖范围(R2-2 方案 B,预研实现,待 kimi 拍板):
|
|
14
|
+
* - tv2 token(tokenV2=true)→ 强制 walletAuth + signer===sub(R2-1 已有)
|
|
15
|
+
* - 第一方登录 token(isOAuth=false)→ 强制 walletAuth + signer===address
|
|
16
|
+
* 收口"隐式全权限":第三方 App 即使拿到第一方 token 也做不了写操作。
|
|
17
|
+
* 不做 scope 检查——第一方默认 scopes 只有 profile/email,加检查会破坏
|
|
18
|
+
* 所有依赖第一方全权限的现有端点(orders/marketplace 等)。
|
|
19
|
+
* - v1 第三方 OAuth token(isOAuth=true 非 tv2)→ 保持豁免(本就有严格 scope 制)
|
|
20
|
+
*/
|
|
21
|
+
function requireWalletSubMatch() {
|
|
22
|
+
return (req, res, next) => {
|
|
23
|
+
const ou = req.oauthUser;
|
|
24
|
+
if (!ou)
|
|
25
|
+
return next();
|
|
26
|
+
// 豁免: v1 第三方 token (严格 scope 制已管), 不在本中间件管辖
|
|
27
|
+
if (ou.isOAuth && !ou.tokenV2)
|
|
28
|
+
return next();
|
|
29
|
+
if (!req.walletAddress) {
|
|
30
|
+
return res.status(401).json({
|
|
31
|
+
error: 'wallet-challenge-required',
|
|
32
|
+
message: ou.tokenV2 ? 'write op with tv2 token requires walletAuth headers' : 'write op with first-party token requires walletAuth headers',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (req.walletAddress !== ou.address) {
|
|
36
|
+
return res.status(403).json({ error: 'wallet-sub-mismatch', message: 'signer must equal token subject' });
|
|
37
|
+
}
|
|
38
|
+
next();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createScopeAuth(oauthPlugin, authPlugin, v2Deps) {
|
|
42
|
+
/**
|
|
43
|
+
* requireScope(scope) — 路由级中间件,校验 token 是否持有指定 scope。
|
|
44
|
+
*
|
|
45
|
+
* 第一方 token 隐式通过(用户自己 = 全权限)。
|
|
46
|
+
* 第三方 token 必须 scopes.includes(scope),否则 403 insufficient_scope。
|
|
47
|
+
*/
|
|
48
|
+
return function requireScope(scope) {
|
|
49
|
+
return async (req, res, next) => {
|
|
50
|
+
const authHeader = req.headers.authorization;
|
|
51
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
52
|
+
return res.status(401).json({ error: 'missing_token', message: 'Authorization Bearer token required' });
|
|
53
|
+
}
|
|
54
|
+
const token = authHeader.substring(7);
|
|
55
|
+
// 0. tv2 结构化令牌 → 跨索引器离线验证(R2-1)
|
|
56
|
+
// 不查本地用户表(B 节点没有该用户行),sub 即身份。
|
|
57
|
+
if (token.startsWith(token_v2_1.TOKEN_V2_PREFIX)) {
|
|
58
|
+
if (!v2Deps) {
|
|
59
|
+
return res.status(401).json({ error: 'token-v2-not-enabled' });
|
|
60
|
+
}
|
|
61
|
+
let issuerPubkey;
|
|
62
|
+
const parsed = (0, token_v2_1.parseTokenV2)(token);
|
|
63
|
+
if (!parsed) {
|
|
64
|
+
return res.status(401).json({ error: 'invalid_token', message: 'malformed tv2 token' });
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
issuerPubkey = await v2Deps.issuerKeys.get(parsed.payload.iss);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return res.status(503).json({ error: 'issuer-key-unavailable', message: 'chain query failed and no cached key' });
|
|
71
|
+
}
|
|
72
|
+
if (!issuerPubkey) {
|
|
73
|
+
return res.status(401).json({ error: 'unknown-issuer' });
|
|
74
|
+
}
|
|
75
|
+
const verdict = await (0, token_v2_1.verifyTokenV2Offline)(token, issuerPubkey, v2Deps.revocations);
|
|
76
|
+
if (!verdict.ok) {
|
|
77
|
+
return res.status(401).json({ error: 'invalid_token', reason: verdict.reason });
|
|
78
|
+
}
|
|
79
|
+
const p = verdict.payload;
|
|
80
|
+
if (!p.scopes.includes(scope)) {
|
|
81
|
+
return res.status(403).json({ error: 'insufficient_scope', required: scope, granted: p.scopes });
|
|
82
|
+
}
|
|
83
|
+
req.oauthUser = {
|
|
84
|
+
userId: p.sub,
|
|
85
|
+
address: p.sub,
|
|
86
|
+
scopes: p.scopes,
|
|
87
|
+
isOAuth: true,
|
|
88
|
+
clientId: p.client_id,
|
|
89
|
+
tokenV2: true,
|
|
90
|
+
};
|
|
91
|
+
res.on('finish', () => {
|
|
92
|
+
oauthPlugin.logAccess({
|
|
93
|
+
appName: '', clientId: p.client_id,
|
|
94
|
+
userId: p.sub, userAddress: p.sub,
|
|
95
|
+
endpoint: req.path, method: req.method,
|
|
96
|
+
scopeUsed: scope, responseStatus: res.statusCode,
|
|
97
|
+
}).catch(() => { });
|
|
98
|
+
});
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
// 1. 先试第三方 OAuth token
|
|
102
|
+
const oauthInfo = await oauthPlugin.validateAccessToken(token);
|
|
103
|
+
if (oauthInfo) {
|
|
104
|
+
// 第三方 → 严格 scope 强制
|
|
105
|
+
if (!oauthInfo.scopes.includes(scope)) {
|
|
106
|
+
return res.status(403).json({ error: 'insufficient_scope', required: scope, granted: oauthInfo.scopes });
|
|
107
|
+
}
|
|
108
|
+
// 解析 address
|
|
109
|
+
const user = await authPlugin.getUser(oauthInfo.userId);
|
|
110
|
+
if (!user) {
|
|
111
|
+
return res.status(401).json({ error: 'invalid_token', message: 'User not found' });
|
|
112
|
+
}
|
|
113
|
+
req.oauthUser = {
|
|
114
|
+
userId: oauthInfo.userId,
|
|
115
|
+
address: user.address,
|
|
116
|
+
scopes: oauthInfo.scopes,
|
|
117
|
+
isOAuth: true,
|
|
118
|
+
clientId: oauthInfo.clientId,
|
|
119
|
+
};
|
|
120
|
+
// 访问日志(PRD §27.9):仅第三方 OAuth token 记录,第一方不记
|
|
121
|
+
const appName = ''; // app_name 需要 JOIN 查,这里只记 endpoint/scope
|
|
122
|
+
res.on('finish', () => {
|
|
123
|
+
oauthPlugin.logAccess({
|
|
124
|
+
appName, clientId: oauthInfo.clientId,
|
|
125
|
+
userId: oauthInfo.userId, userAddress: user.address,
|
|
126
|
+
endpoint: req.path, method: req.method,
|
|
127
|
+
scopeUsed: scope, responseStatus: res.statusCode,
|
|
128
|
+
}).catch(() => { });
|
|
129
|
+
});
|
|
130
|
+
return next();
|
|
131
|
+
}
|
|
132
|
+
// 2. 后试第一方登录 token
|
|
133
|
+
const sessionInfo = await authPlugin.verifyToken(token);
|
|
134
|
+
if (sessionInfo) {
|
|
135
|
+
// 第一方 → 隐式全权限(用户自己的 session)
|
|
136
|
+
const user = await authPlugin.getUser(sessionInfo.userId);
|
|
137
|
+
if (!user) {
|
|
138
|
+
return res.status(401).json({ error: 'invalid_token', message: 'User not found' });
|
|
139
|
+
}
|
|
140
|
+
req.oauthUser = {
|
|
141
|
+
userId: sessionInfo.userId,
|
|
142
|
+
address: user.address,
|
|
143
|
+
scopes: sessionInfo.scopes,
|
|
144
|
+
isOAuth: false,
|
|
145
|
+
};
|
|
146
|
+
return next();
|
|
147
|
+
}
|
|
148
|
+
// 3. 都不匹配 → 无效 token
|
|
149
|
+
return res.status(401).json({ error: 'invalid_token', message: 'Token not recognized or expired' });
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
153
|
//# sourceMappingURL=scope-auth.js.map
|
package/middleware/security.d.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security Middleware - 安全中间件
|
|
3
|
-
*
|
|
4
|
-
* 功能:
|
|
5
|
-
* 1. IP 白名单验证
|
|
6
|
-
* 2. CORS 限制
|
|
7
|
-
* 3. 请求日志审计
|
|
8
|
-
* 4. 安全头部
|
|
9
|
-
*/
|
|
10
|
-
import { Request, Response, NextFunction } from 'express';
|
|
11
|
-
/**
|
|
12
|
-
* IP 白名单中间件
|
|
13
|
-
*/
|
|
14
|
-
export declare function ipWhitelist(allowedIPs: string[]): (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
15
|
-
/**
|
|
16
|
-
* 动态 CORS 配置
|
|
17
|
-
*/
|
|
18
|
-
export declare function createCorsOptions(allowedOrigins: string[]): {
|
|
19
|
-
origin: (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => void;
|
|
20
|
-
credentials: boolean;
|
|
21
|
-
methods: string[];
|
|
22
|
-
allowedHeaders: string[];
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* 审计日志中间件
|
|
26
|
-
*/
|
|
27
|
-
export declare function auditLog(): (req: Request, res: Response, next: NextFunction) => void;
|
|
28
|
-
/**
|
|
29
|
-
* 安全头部中间件
|
|
30
|
-
*/
|
|
31
|
-
export declare function securityHeaders(): (req: Request, res: Response, next: NextFunction) => void;
|
|
32
|
-
/**
|
|
33
|
-
* 请求体大小限制
|
|
34
|
-
*/
|
|
35
|
-
export declare const requestSizeLimit: {
|
|
36
|
-
json: {
|
|
37
|
-
limit: string;
|
|
38
|
-
};
|
|
39
|
-
urlencoded: {
|
|
40
|
-
limit: string;
|
|
41
|
-
extended: boolean;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* 验证必需的环境变量
|
|
46
|
-
*/
|
|
47
|
-
export declare function validateEnv(): void;
|
|
1
|
+
/**
|
|
2
|
+
* Security Middleware - 安全中间件
|
|
3
|
+
*
|
|
4
|
+
* 功能:
|
|
5
|
+
* 1. IP 白名单验证
|
|
6
|
+
* 2. CORS 限制
|
|
7
|
+
* 3. 请求日志审计
|
|
8
|
+
* 4. 安全头部
|
|
9
|
+
*/
|
|
10
|
+
import { Request, Response, NextFunction } from 'express';
|
|
11
|
+
/**
|
|
12
|
+
* IP 白名单中间件
|
|
13
|
+
*/
|
|
14
|
+
export declare function ipWhitelist(allowedIPs: string[]): (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
15
|
+
/**
|
|
16
|
+
* 动态 CORS 配置
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCorsOptions(allowedOrigins: string[]): {
|
|
19
|
+
origin: (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => void;
|
|
20
|
+
credentials: boolean;
|
|
21
|
+
methods: string[];
|
|
22
|
+
allowedHeaders: string[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 审计日志中间件
|
|
26
|
+
*/
|
|
27
|
+
export declare function auditLog(): (req: Request, res: Response, next: NextFunction) => void;
|
|
28
|
+
/**
|
|
29
|
+
* 安全头部中间件
|
|
30
|
+
*/
|
|
31
|
+
export declare function securityHeaders(): (req: Request, res: Response, next: NextFunction) => void;
|
|
32
|
+
/**
|
|
33
|
+
* 请求体大小限制
|
|
34
|
+
*/
|
|
35
|
+
export declare const requestSizeLimit: {
|
|
36
|
+
json: {
|
|
37
|
+
limit: string;
|
|
38
|
+
};
|
|
39
|
+
urlencoded: {
|
|
40
|
+
limit: string;
|
|
41
|
+
extended: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 验证必需的环境变量
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateEnv(): void;
|
|
48
48
|
//# sourceMappingURL=security.d.ts.map
|