trustbase-seller-backend 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (650) hide show
  1. package/MERCHANT-EDITION.md +56 -56
  2. package/README.md +99 -99
  3. package/api/__tests__/test-utils.d.ts +32 -32
  4. package/api/__tests__/test-utils.js +89 -89
  5. package/api/db/case-library-types.d.ts +46 -46
  6. package/api/db/case-library-types.js +79 -79
  7. package/api/db/case-library.db.d.ts +4 -4
  8. package/api/db/case-library.db.js +70 -70
  9. package/api/email.d.ts +55 -55
  10. package/api/email.js +305 -305
  11. package/api/index.d.ts +21 -21
  12. package/api/index.js +40 -40
  13. package/api/integration-helpers.d.ts +152 -152
  14. package/api/integration-helpers.js +354 -354
  15. package/api/lib/case-summary.d.ts +9 -9
  16. package/api/lib/case-summary.js +29 -29
  17. package/api/middleware/p2p-auth.d.ts +139 -139
  18. package/api/middleware/p2p-auth.js +506 -506
  19. package/api/middleware/tool-policy.d.ts +46 -46
  20. package/api/middleware/tool-policy.js +155 -155
  21. package/api/oauth-adapters.d.ts +191 -191
  22. package/api/oauth-adapters.js +455 -455
  23. package/api/oauth-bridge.d.ts +55 -55
  24. package/api/oauth-bridge.js +615 -615
  25. package/api/oauth-router.d.ts +35 -35
  26. package/api/oauth-router.js +53 -53
  27. package/api/p2p-mcp.d.ts +68 -68
  28. package/api/p2p-mcp.js +285 -285
  29. package/api/payment-store.d.ts +55 -55
  30. package/api/payment-store.js +122 -122
  31. package/api/payment.d.ts +13 -13
  32. package/api/payment.js +215 -215
  33. package/api/pwa-stats.d.ts +66 -66
  34. package/api/pwa-stats.js +259 -259
  35. package/api/riskcontrol-adapters.d.ts +113 -113
  36. package/api/riskcontrol-adapters.js +209 -209
  37. package/api/riskcontrol-event-whitelist.d.ts +80 -80
  38. package/api/riskcontrol-event-whitelist.js +180 -180
  39. package/api/riskcontrol-rules.d.ts +104 -104
  40. package/api/riskcontrol-rules.js +381 -381
  41. package/api/riskcontrol-scoring.d.ts +71 -71
  42. package/api/riskcontrol-scoring.js +324 -324
  43. package/api/riskcontrol-service.d.ts +59 -59
  44. package/api/riskcontrol-service.js +200 -200
  45. package/api/riskcontrol-stream.d.ts +111 -111
  46. package/api/riskcontrol-stream.js +229 -229
  47. package/api/riskcontrol-v5-e2e-test.d.ts +14 -14
  48. package/api/riskcontrol-v5-e2e-test.js +203 -203
  49. package/api/riskcontrol-v5-router.d.ts +47 -47
  50. package/api/riskcontrol-v5-router.js +223 -223
  51. package/api/riskcontrol-webhook.d.ts +87 -87
  52. package/api/riskcontrol-webhook.js +282 -282
  53. package/api/routes/case-library.d.ts +3 -3
  54. package/api/routes/case-library.js +86 -86
  55. package/api/seller-earnings.d.ts +22 -22
  56. package/api/seller-earnings.js +244 -244
  57. package/api/seller-orders.d.ts +24 -24
  58. package/api/seller-orders.js +393 -393
  59. package/api/seller-products-chain.d.ts +30 -30
  60. package/api/seller-products-chain.js +303 -303
  61. package/api/seller-products.d.ts +29 -29
  62. package/api/seller-products.js +494 -494
  63. package/api/seller-reputation.d.ts +20 -20
  64. package/api/seller-reputation.js +202 -202
  65. package/api/seller-router.d.ts +32 -32
  66. package/api/seller-router.js +52 -52
  67. package/api/seller-settings.d.ts +22 -22
  68. package/api/seller-settings.js +270 -270
  69. package/api/shipping-store.d.ts +43 -43
  70. package/api/shipping-store.js +112 -112
  71. package/api/shipping.d.ts +15 -15
  72. package/api/shipping.js +238 -238
  73. package/api/social-endpoint-verify.d.ts +7 -7
  74. package/api/social-endpoint-verify.js +151 -151
  75. package/api/social-posts.d.ts +64 -64
  76. package/api/social-posts.js +510 -510
  77. package/api/social-router.d.ts +35 -35
  78. package/api/social-router.js +55 -55
  79. package/api/social-shares.d.ts +39 -39
  80. package/api/social-shares.js +364 -364
  81. package/api/social-whitelist.d.ts +40 -40
  82. package/api/social-whitelist.js +251 -251
  83. package/api/storefront-orders.d.ts +22 -22
  84. package/api/storefront-orders.js +344 -344
  85. package/api/storefront-products.d.ts +20 -20
  86. package/api/storefront-products.js +176 -176
  87. package/api/storefront-router.d.ts +32 -32
  88. package/api/storefront-router.js +46 -46
  89. package/api/storefront-user.d.ts +22 -22
  90. package/api/storefront-user.js +325 -325
  91. package/api/test-db-helper.d.ts +28 -28
  92. package/api/test-db-helper.js +106 -106
  93. package/api/traffic.d.ts +21 -21
  94. package/api/traffic.js +111 -111
  95. package/api/wc-credentials.d.ts +33 -33
  96. package/api/wc-credentials.js +273 -273
  97. package/api/wc-tracker-receiver.d.ts +46 -46
  98. package/api/wc-tracker-receiver.js +257 -257
  99. package/api/wc-v3.d.ts +39 -39
  100. package/api/wc-v3.js +665 -665
  101. package/audit-page-scripts.js +61 -61
  102. package/bin/tb-doctor.js +32 -32
  103. package/check.d.ts +1 -1
  104. package/check.js +18 -18
  105. package/config/export-import.d.ts +107 -107
  106. package/config/export-import.js +233 -233
  107. package/config/manager.d.ts +72 -72
  108. package/config/manager.js +245 -245
  109. package/config/profile.d.ts +41 -41
  110. package/config/profile.js +110 -110
  111. package/core/address.js +23 -23
  112. package/core/advanced-performance.d.ts +148 -148
  113. package/core/advanced-performance.js +323 -323
  114. package/core/alerting.d.ts +90 -90
  115. package/core/alerting.js +362 -362
  116. package/core/app-store.d.ts +76 -76
  117. package/core/app-store.js +206 -206
  118. package/core/boot-env.js +39 -39
  119. package/core/business-scope-schema.d.ts +59 -59
  120. package/core/business-scope-schema.js +119 -119
  121. package/core/cache.d.ts +52 -52
  122. package/core/cache.js +129 -129
  123. package/core/chain-listener.d.ts +46 -46
  124. package/core/chain-listener.js +253 -253
  125. package/core/chain-reconcile.js +156 -156
  126. package/core/chain-reject.js +107 -107
  127. package/core/chain-signer.js +269 -268
  128. package/core/cleanup.d.ts +41 -41
  129. package/core/cleanup.js +143 -143
  130. package/core/cluster.d.ts +77 -77
  131. package/core/cluster.js +214 -214
  132. package/core/community-review.d.ts +81 -81
  133. package/core/community-review.js +200 -200
  134. package/core/connection-pool.d.ts +71 -71
  135. package/core/connection-pool.js +172 -172
  136. package/core/consistency.d.ts +129 -129
  137. package/core/consistency.js +339 -339
  138. package/core/content-ai.d.ts +302 -302
  139. package/core/content-ai.js +343 -343
  140. package/core/content-backfill.d.ts +54 -54
  141. package/core/content-backfill.js +173 -173
  142. package/core/conversion-rate-sync.d.ts +96 -96
  143. package/core/conversion-rate-sync.js +194 -194
  144. package/core/coverage-backup.d.ts +86 -86
  145. package/core/coverage-backup.js +264 -264
  146. package/core/db-installer.d.ts +107 -107
  147. package/core/db-installer.js +406 -406
  148. package/core/device-analyzer.d.ts +95 -95
  149. package/core/device-analyzer.js +234 -234
  150. package/core/discovery.d.ts +164 -164
  151. package/core/discovery.js +362 -362
  152. package/core/distributed.d.ts +171 -171
  153. package/core/distributed.js +421 -421
  154. package/core/doctor.js +249 -249
  155. package/core/enforcement.d.ts +56 -56
  156. package/core/enforcement.js +114 -114
  157. package/core/error-handler.d.ts +130 -130
  158. package/core/error-handler.js +290 -290
  159. package/core/federated-learning.d.ts +123 -123
  160. package/core/federated-learning.js +337 -337
  161. package/core/fingerprint.d.ts +94 -94
  162. package/core/fingerprint.js +312 -312
  163. package/core/geoip.d.ts +66 -66
  164. package/core/geoip.js +173 -173
  165. package/core/gossip.d.ts +140 -140
  166. package/core/gossip.js +371 -371
  167. package/core/governance.d.ts +146 -146
  168. package/core/governance.js +350 -350
  169. package/core/indexer-enhancements.d.ts +163 -163
  170. package/core/indexer-enhancements.js +428 -428
  171. package/core/intrusion-detection.d.ts +78 -78
  172. package/core/intrusion-detection.js +321 -321
  173. package/core/lifecycle.d.ts +117 -117
  174. package/core/lifecycle.js +295 -295
  175. package/core/location.d.ts +98 -98
  176. package/core/location.js +218 -218
  177. package/core/maxmind-integration.d.ts +67 -67
  178. package/core/maxmind-integration.js +244 -244
  179. package/core/migration.d.ts +57 -57
  180. package/core/migration.js +219 -219
  181. package/core/monitoring.d.ts +152 -152
  182. package/core/monitoring.js +405 -405
  183. package/core/offsite-backup.d.ts +70 -70
  184. package/core/offsite-backup.js +340 -340
  185. package/core/order-intent-store.js +83 -83
  186. package/core/order-intent.js +273 -273
  187. package/core/paths.js +116 -116
  188. package/core/performance.d.ts +172 -172
  189. package/core/performance.js +385 -385
  190. package/core/product-flag.d.ts +363 -363
  191. package/core/product-flag.js +464 -464
  192. package/core/protection.d.ts +138 -138
  193. package/core/protection.js +326 -326
  194. package/core/region-adapter.d.ts +151 -151
  195. package/core/region-adapter.js +504 -504
  196. package/core/region-configs.d.ts +11 -11
  197. package/core/region-configs.js +906 -906
  198. package/core/review-antifraud.d.ts +79 -79
  199. package/core/review-antifraud.js +192 -192
  200. package/core/rules-updater.d.ts +88 -88
  201. package/core/rules-updater.js +260 -260
  202. package/core/runtime-data.js +203 -203
  203. package/core/security.d.ts +143 -143
  204. package/core/security.js +389 -389
  205. package/core/seller-identity.js +78 -78
  206. package/core/session-manager.d.ts +92 -92
  207. package/core/session-manager.js +261 -261
  208. package/core/state-sync.d.ts +120 -120
  209. package/core/state-sync.js +286 -286
  210. package/core/testing.d.ts +96 -96
  211. package/core/testing.js +360 -360
  212. package/core/trust-score.d.ts +50 -50
  213. package/core/trust-score.js +187 -187
  214. package/core/trustworthiness.d.ts +139 -139
  215. package/core/trustworthiness.js +374 -374
  216. package/core/types.d.ts +257 -257
  217. package/core/types.js +8 -8
  218. package/core/upgrade-manager.d.ts +113 -113
  219. package/core/upgrade-manager.js +263 -263
  220. package/core/upgrader.d.ts +106 -106
  221. package/core/upgrader.js +386 -386
  222. package/core/websocket.d.ts +77 -77
  223. package/core/websocket.js +291 -291
  224. package/council/hidden-weight.d.ts +44 -44
  225. package/council/hidden-weight.js +134 -134
  226. package/db/email-migrations.sql +31 -31
  227. package/db/oauth-migrate.d.ts +38 -38
  228. package/db/oauth-migrate.js +169 -169
  229. package/db/oauth-migrations.sql +92 -92
  230. package/db/social-migrate.d.ts +11 -11
  231. package/db/social-migrate.js +8 -8
  232. package/db/social-migrations.sql +93 -93
  233. package/db/store-migrate.d.ts +32 -32
  234. package/db/store-migrate.js +150 -150
  235. package/db/store-migrations.sql +241 -241
  236. package/debug.d.ts +1 -1
  237. package/debug.js +17 -17
  238. package/docs/DEPLOYMENT.md +42 -42
  239. package/event-listener.d.ts +92 -92
  240. package/event-listener.js +320 -320
  241. package/event-whitelist.d.ts +78 -78
  242. package/event-whitelist.js +532 -532
  243. package/index.d.ts +44 -44
  244. package/index.js +360 -360
  245. package/init-node.d.ts +8 -8
  246. package/init-node.js +212 -212
  247. package/mcp/ai-tools.d.ts +1 -1
  248. package/mcp/ai-tools.js +222 -222
  249. package/mcp/auto-dispatch-tools.d.ts +1 -1
  250. package/mcp/auto-dispatch-tools.js +296 -296
  251. package/mcp/business-scope-tools.d.ts +10 -10
  252. package/mcp/business-scope-tools.js +178 -178
  253. package/mcp/buyer-tools.d.ts +66 -66
  254. package/mcp/buyer-tools.js +415 -415
  255. package/mcp/interfaces.d.ts +1057 -1057
  256. package/mcp/interfaces.js +12 -12
  257. package/mcp/m2m-chat-tool.d.ts +49 -49
  258. package/mcp/m2m-chat-tool.js +411 -411
  259. package/mcp/migrations.d.ts +29 -29
  260. package/mcp/migrations.js +103 -103
  261. package/mcp/peer-tools.d.ts +162 -162
  262. package/mcp/peer-tools.js +523 -523
  263. package/mcp/plugin-management-tools.d.ts +1 -1
  264. package/mcp/plugin-management-tools.js +279 -279
  265. package/mcp/product-type-tools.d.ts +1 -1
  266. package/mcp/product-type-tools.js +412 -412
  267. package/mcp/security-tools.d.ts +1 -1
  268. package/mcp/security-tools.js +281 -281
  269. package/mcp/seller-query-tools.d.ts +1 -1
  270. package/mcp/seller-query-tools.js +162 -162
  271. package/mcp/server.d.ts +10 -10
  272. package/mcp/server.js +67 -67
  273. package/mcp/standalone-server.d.ts +33 -33
  274. package/mcp/standalone-server.js +231 -231
  275. package/mcp/tools-integration.d.ts +30 -30
  276. package/mcp/tools-integration.js +287 -287
  277. package/mcp/web-panel.d.ts +17 -17
  278. package/mcp/web-panel.js +965 -965
  279. package/middleware/api-key-auth.d.ts +63 -63
  280. package/middleware/api-key-auth.js +18 -18
  281. package/middleware/scope-auth.d.ts +53 -53
  282. package/middleware/scope-auth.js +152 -152
  283. package/middleware/security.d.ts +47 -47
  284. package/middleware/security.js +216 -216
  285. package/middleware/wallet-auth.d.ts +53 -53
  286. package/middleware/wallet-auth.js +157 -157
  287. package/oauth/chain-revocation-sink.d.ts +23 -23
  288. package/oauth/chain-revocation-sink.js +46 -46
  289. package/oauth/gossip-sync.d.ts +24 -24
  290. package/oauth/gossip-sync.js +61 -61
  291. package/oauth/issuer-keys.d.ts +30 -30
  292. package/oauth/issuer-keys.js +116 -116
  293. package/oauth/peer-resolver.d.ts +24 -24
  294. package/oauth/peer-resolver.js +80 -80
  295. package/oauth/revocation-store.d.ts +57 -57
  296. package/oauth/revocation-store.js +64 -64
  297. package/oauth/token-v2.d.ts +100 -100
  298. package/oauth/token-v2.js +166 -166
  299. package/oracle/c5-glue.js +795 -795
  300. package/oracle/ops-console.js +654 -654
  301. package/oracle/oracle-sync.d.ts +28 -28
  302. package/oracle/oracle-sync.js +444 -444
  303. package/oracle/registry.d.ts +29 -29
  304. package/oracle/registry.js +61 -61
  305. package/p2p/availability.d.ts +187 -187
  306. package/p2p/availability.js +573 -573
  307. package/p2p/bootstrap.d.ts +41 -41
  308. package/p2p/bootstrap.js +145 -145
  309. package/p2p/buyer-client.d.ts +97 -97
  310. package/p2p/buyer-client.js +198 -198
  311. package/p2p/cdn-ddns.d.ts +207 -207
  312. package/p2p/cdn-ddns.js +499 -499
  313. package/p2p/cluster-sync.d.ts +114 -114
  314. package/p2p/cluster-sync.js +329 -329
  315. package/p2p/consistency-check.d.ts +29 -29
  316. package/p2p/consistency-check.js +167 -167
  317. package/p2p/endpoint-registry.d.ts +40 -40
  318. package/p2p/endpoint-registry.js +127 -127
  319. package/p2p/ipv6.d.ts +119 -119
  320. package/p2p/ipv6.js +424 -424
  321. package/p2p/protocol.d.ts +99 -99
  322. package/p2p/protocol.js +329 -329
  323. package/p2p/reliability.d.ts +55 -55
  324. package/p2p/reliability.js +239 -239
  325. package/p2p/seller-service.d.ts +52 -52
  326. package/p2p/seller-service.js +275 -275
  327. package/p2p/signing.d.ts +30 -30
  328. package/p2p/signing.js +94 -94
  329. package/package.json +1 -1
  330. package/payment/api.d.ts +8 -8
  331. package/payment/api.js +140 -140
  332. package/payment/gateway.d.ts +113 -113
  333. package/payment/gateway.js +230 -230
  334. package/payments/alipay/index.d.ts +17 -17
  335. package/payments/alipay/index.js +54 -54
  336. package/payments/base.d.ts +12 -12
  337. package/payments/base.js +27 -27
  338. package/payments/index.d.ts +17 -17
  339. package/payments/index.js +65 -65
  340. package/payments/template/index.d.ts +17 -17
  341. package/payments/template/index.js +56 -56
  342. package/payments/types.d.ts +41 -41
  343. package/payments/types.js +2 -2
  344. package/payments/wechat/index.d.ts +17 -17
  345. package/payments/wechat/index.js +53 -53
  346. package/payments/wechat/profitsharing.js +231 -231
  347. package/peer/chain-signer.d.ts +73 -73
  348. package/peer/chain-signer.js +148 -148
  349. package/peer/config.d.ts +70 -70
  350. package/peer/config.js +60 -60
  351. package/peer/index.d.ts +11 -11
  352. package/peer/index.js +45 -45
  353. package/peer/key-store.d.ts +65 -65
  354. package/peer/key-store.js +162 -162
  355. package/peer/proto-codec.d.ts +102 -102
  356. package/peer/proto-codec.js +422 -422
  357. package/peer/registrar.d.ts +87 -87
  358. package/peer/registrar.js +270 -270
  359. package/peer/registry.d.ts +30 -30
  360. package/peer/registry.js +142 -142
  361. package/plugins/auth.d.ts +192 -192
  362. package/plugins/auth.js +818 -818
  363. package/plugins/manager.d.ts +36 -36
  364. package/plugins/manager.js +82 -82
  365. package/plugins/oauth.d.ts +248 -248
  366. package/plugins/oauth.js +806 -806
  367. package/plugins/p2p-message.d.ts +132 -132
  368. package/plugins/p2p-message.js +349 -349
  369. package/plugins/postgresql.d.ts +53 -53
  370. package/plugins/postgresql.js +596 -596
  371. package/plugins/relationship.d.ts +140 -140
  372. package/plugins/relationship.js +290 -290
  373. package/plugins/sqlite.d.ts +199 -199
  374. package/port-manager/disguise/ssh.d.ts +18 -18
  375. package/port-manager/disguise/ssh.js +103 -103
  376. package/port-manager/port-manager.d.ts +64 -64
  377. package/port-manager/port-manager.js +163 -163
  378. package/port-manager/port-scanner.d.ts +21 -21
  379. package/port-manager/port-scanner.js +186 -186
  380. package/port-manager/types.d.ts +50 -50
  381. package/port-manager/types.js +5 -5
  382. package/proto/amino/amino.proto +83 -83
  383. package/proto/cosmos/base/v1beta1/coin.proto +61 -61
  384. package/proto/cosmos/msg/v1/msg.proto +30 -30
  385. package/proto/cosmos_proto/cosmos.proto +111 -111
  386. package/proto/gogoproto/gogo.proto +145 -145
  387. package/proto/google/protobuf/descriptor.proto +1218 -1218
  388. package/proto/trustchain/marketplace/v1/product.proto +20 -20
  389. package/proto/trustchain/order/v1/tx.proto +156 -156
  390. package/proto/trustchain/reward/v1/tx.proto +62 -62
  391. package/proto/trustchain/serviceprovider/v1/paymentfact.proto +32 -32
  392. package/proto/trustchain/serviceprovider/v1/serviceprovider.proto +38 -38
  393. package/proto/trustchain/serviceprovider/v1/tx.proto +106 -106
  394. package/proto/trustchain/subchain/v1/params.proto +26 -26
  395. package/proto/trustchain/subchain/v1/tx.proto +33 -33
  396. package/proto/trustchain/verification/v1/params.proto +46 -46
  397. package/proto/trustchain/verification/v1/tx.proto +126 -126
  398. package/proto/trustchain/verification/v1/verification.proto +105 -105
  399. package/relationship-chain-api.d.ts +12 -12
  400. package/relationship-chain-api.js +138 -138
  401. package/relationship-chain.d.ts +89 -89
  402. package/relationship-chain.js +200 -200
  403. package/routes/agent-pay.js +13 -13
  404. package/routes/agent-serviceprovider.js +183 -183
  405. package/routes/ai.d.ts +53 -53
  406. package/routes/ai.js +289 -289
  407. package/routes/api-keys.d.ts +11 -11
  408. package/routes/api-keys.js +162 -162
  409. package/routes/app-store.d.ts +11 -11
  410. package/routes/app-store.js +206 -206
  411. package/routes/auth-management.d.ts +16 -16
  412. package/routes/auth-management.js +256 -256
  413. package/routes/auth.d.ts +8 -8
  414. package/routes/auth.js +845 -845
  415. package/routes/brand.d.ts +2 -2
  416. package/routes/brand.js +108 -108
  417. package/routes/chain-registry.d.ts +10 -10
  418. package/routes/chain-registry.js +50 -50
  419. package/routes/chain-writes-insurance.d.ts +16 -16
  420. package/routes/chain-writes-insurance.js +58 -58
  421. package/routes/chain-writes-pledge.d.ts +33 -33
  422. package/routes/chain-writes-pledge.js +204 -204
  423. package/routes/chain-writes-products.d.ts +65 -65
  424. package/routes/chain-writes-products.js +438 -438
  425. package/routes/chain-writes.d.ts +77 -77
  426. package/routes/chain.d.ts +9 -9
  427. package/routes/chain.js +44 -44
  428. package/routes/compliance.d.ts +2 -2
  429. package/routes/compliance.js +52 -52
  430. package/routes/council.d.ts +2 -2
  431. package/routes/council.js +476 -476
  432. package/routes/crosschain.d.ts +10 -10
  433. package/routes/crosschain.js +38 -38
  434. package/routes/device.d.ts +2 -2
  435. package/routes/device.js +72 -72
  436. package/routes/devreward.d.ts +53 -53
  437. package/routes/devreward.js +111 -111
  438. package/routes/economy.d.ts +49 -49
  439. package/routes/economy.js +269 -269
  440. package/routes/flowback.d.ts +31 -31
  441. package/routes/flowback.js +81 -81
  442. package/routes/insurance.d.ts +9 -9
  443. package/routes/insurance.js +69 -69
  444. package/routes/m2m.d.ts +9 -9
  445. package/routes/m2m.js +29 -29
  446. package/routes/marketplace.d.ts +14 -14
  447. package/routes/marketplace.js +395 -395
  448. package/routes/node-config.d.ts +5 -5
  449. package/routes/node-config.js +499 -499
  450. package/routes/oauth-revocation.d.ts +41 -41
  451. package/routes/oauth-revocation.js +98 -98
  452. package/routes/oauth.d.ts +16 -16
  453. package/routes/oauth.js +699 -699
  454. package/routes/onboard.html +1483 -1483
  455. package/routes/onboard.js +944 -944
  456. package/routes/order.d.ts +7 -7
  457. package/routes/order.js +591 -591
  458. package/routes/p2p-api.d.ts +32 -32
  459. package/routes/p2p-api.js +268 -268
  460. package/routes/p2p-message.d.ts +19 -19
  461. package/routes/p2p-message.js +236 -236
  462. package/routes/peer.d.ts +21 -21
  463. package/routes/peer.js +210 -210
  464. package/routes/plugins.d.ts +3 -3
  465. package/routes/plugins.js +137 -137
  466. package/routes/port-manager.d.ts +5 -5
  467. package/routes/port-manager.js +211 -211
  468. package/routes/relationship.d.ts +6 -6
  469. package/routes/relationship.js +313 -313
  470. package/routes/relay.d.ts +2 -2
  471. package/routes/relay.js +181 -181
  472. package/routes/reputation.d.ts +9 -9
  473. package/routes/reputation.js +140 -140
  474. package/routes/reward.d.ts +2 -2
  475. package/routes/reward.js +129 -129
  476. package/routes/security-monitoring.d.ts +11 -11
  477. package/routes/security-monitoring.js +372 -372
  478. package/routes/shop.d.ts +7 -7
  479. package/routes/shop.js +163 -163
  480. package/routes/social.d.ts +21 -21
  481. package/routes/social.js +94 -94
  482. package/routes/sp-admin.js +32 -32
  483. package/routes/sp-applyment.js +285 -285
  484. package/routes/sp-commission.js +119 -119
  485. package/routes/sp-notify.js +424 -424
  486. package/routes/sp-tunnel.js +354 -354
  487. package/routes/subchain.d.ts +17 -17
  488. package/routes/subchain.js +105 -105
  489. package/routes/trustcoin.d.ts +16 -16
  490. package/routes/trustcoin.js +148 -148
  491. package/routes/twofa.d.ts +6 -6
  492. package/routes/twofa.js +104 -104
  493. package/routes/verification.d.ts +7 -7
  494. package/routes/verification.js +233 -233
  495. package/routes/wallet.d.ts +3 -3
  496. package/routes/wallet.js +763 -763
  497. package/run-auth.d.ts +7 -7
  498. package/run-auth.js +81 -81
  499. package/run-p2p-message.d.ts +7 -7
  500. package/run-p2p-message.js +81 -81
  501. package/run-relationship.d.ts +11 -11
  502. package/run-relationship.js +181 -181
  503. package/run-unified.d.ts +12 -12
  504. package/run-unified.js +4 -0
  505. package/run.d.ts +11 -11
  506. package/run.js +888 -888
  507. package/search/ranking.d.ts +54 -54
  508. package/search/ranking.js +66 -66
  509. package/shipping/base.d.ts +14 -14
  510. package/shipping/base.js +38 -38
  511. package/shipping/index.d.ts +18 -18
  512. package/shipping/index.js +71 -71
  513. package/shipping/sf-express/index.d.ts +22 -22
  514. package/shipping/sf-express/index.js +70 -70
  515. package/shipping/template/index.d.ts +19 -19
  516. package/shipping/template/index.js +73 -73
  517. package/shipping/types.d.ts +70 -70
  518. package/shipping/types.js +5 -5
  519. package/shipping/virtual/index.d.ts +18 -18
  520. package/shipping/virtual/index.js +53 -53
  521. package/shipping/yto/index.d.ts +17 -17
  522. package/shipping/yto/index.js +58 -58
  523. package/shipping/zto/index.d.ts +17 -17
  524. package/shipping/zto/index.js +58 -58
  525. package/skills-lock.json +11 -11
  526. package/src/db/email-migrations.sql +31 -31
  527. package/src/db/oauth-migrations.sql +92 -92
  528. package/src/db/social-migrations.sql +93 -93
  529. package/src/db/store-migrations.sql +241 -241
  530. package/test-agent-pay-lifecycle.js +186 -186
  531. package/test-agent-pay-wechat.js +291 -291
  532. package/test-api-key-revoke.js +167 -167
  533. package/test-auth-register-ratelimit.js +132 -132
  534. package/test-auth-tv2.d.ts +1 -1
  535. package/test-auth-tv2.js +173 -173
  536. package/test-buyer-shop-ps.js +238 -238
  537. package/test-buyer-shop.js +334 -334
  538. package/test-canonsign-cross.d.ts +1 -1
  539. package/test-canonsign-cross.js +31 -31
  540. package/test-chain-reconcile.js +132 -132
  541. package/test-chain-signer.js +188 -188
  542. package/test-env-truthy.js +50 -50
  543. package/test-laneC.js +85 -85
  544. package/test-onboard-applyment.js +823 -823
  545. package/test-onboard-backup.js +208 -208
  546. package/test-onboard-contract.js +94 -94
  547. package/test-ops-console-boundary.js +147 -147
  548. package/test-oracle-glue.js +354 -354
  549. package/test-oracle-pool-refill.js +171 -171
  550. package/test-order-create-v394.js +358 -358
  551. package/test-order-intent.js +245 -245
  552. package/test-order-lifecycle-v394.js +528 -528
  553. package/test-p2p-message.d.ts +12 -12
  554. package/test-p2p-message.js +105 -105
  555. package/test-product-type-chain.js +72 -72
  556. package/test-product-type-write.js +210 -210
  557. package/test-relationship-chain.d.ts +12 -12
  558. package/test-relationship-chain.js +102 -102
  559. package/test-runtime-data-path.js +217 -217
  560. package/test-seller-identity.js +74 -74
  561. package/test-signing-paths.js +104 -104
  562. package/test-sp-admin.js +289 -289
  563. package/test-sp-applyment.js +583 -583
  564. package/test-sp-gateway.js +435 -435
  565. package/test-sp-tunnel.js +311 -311
  566. package/test-sqlite-product-type-preserve.js +64 -64
  567. package/test-token-v2.d.ts +1 -1
  568. package/test-token-v2.js +170 -170
  569. package/test-wallet-auth-nonce.d.ts +11 -11
  570. package/test-wallet-auth-nonce.js +125 -125
  571. package/test-wallet-submatch.d.ts +12 -12
  572. package/test-wallet-submatch.js +85 -85
  573. package/tls/self-signed.d.ts +11 -11
  574. package/tls/self-signed.js +62 -62
  575. package/tools/brand.d.ts +10 -10
  576. package/tools/brand.js +74 -74
  577. package/tools/chainregistry.d.ts +17 -17
  578. package/tools/chainregistry.js +155 -155
  579. package/tools/compliance.d.ts +13 -13
  580. package/tools/compliance.js +44 -44
  581. package/tools/council.d.ts +16 -16
  582. package/tools/council.js +74 -74
  583. package/tools/device.d.ts +12 -12
  584. package/tools/device.js +44 -44
  585. package/tools/devreward.d.ts +14 -14
  586. package/tools/devreward.js +175 -175
  587. package/tools/economy.d.ts +13 -13
  588. package/tools/economy.js +168 -168
  589. package/tools/flowback.d.ts +13 -13
  590. package/tools/flowback.js +132 -132
  591. package/tools/insurance.d.ts +12 -12
  592. package/tools/insurance.js +44 -44
  593. package/tools/marketplace.d.ts +11 -11
  594. package/tools/marketplace.js +112 -112
  595. package/tools/mock-tunnel-merchant.js +25 -25
  596. package/tools/order.d.ts +11 -11
  597. package/tools/order.js +87 -87
  598. package/tools/recovery.d.ts +13 -13
  599. package/tools/recovery.js +151 -151
  600. package/tools/relay.d.ts +14 -14
  601. package/tools/relay.js +129 -129
  602. package/tools/reputation.d.ts +19 -19
  603. package/tools/reputation.js +49 -49
  604. package/tools/reputation_seller_credit.d.ts +15 -15
  605. package/tools/reputation_seller_credit.js +99 -99
  606. package/tools/reward.d.ts +13 -13
  607. package/tools/reward.js +70 -70
  608. package/tools/shop.d.ts +13 -13
  609. package/tools/shop.js +82 -82
  610. package/tools/tunnel-e2e-check.sh +20 -20
  611. package/tools/verification.d.ts +11 -11
  612. package/tools/verification.js +83 -83
  613. package/types/store.d.ts +254 -254
  614. package/types/store.js +18 -18
  615. package/utils/aes-gcm.d.ts +62 -62
  616. package/utils/aes-gcm.js +178 -178
  617. package/utils/api-response.d.ts +50 -50
  618. package/utils/api-response.js +64 -64
  619. package/utils/base32.d.ts +4 -4
  620. package/utils/base32.js +19 -19
  621. package/utils/crypto.d.ts +76 -76
  622. package/utils/crypto.js +163 -163
  623. package/utils/encryption.d.ts +80 -80
  624. package/utils/encryption.js +246 -246
  625. package/utils/env.js +20 -20
  626. package/utils/jwt.d.ts +109 -109
  627. package/utils/jwt.js +274 -274
  628. package/utils/qrcode-reader.d.ts +21 -21
  629. package/utils/qrcode.d.ts +25 -25
  630. package/utils/qrcode.js +91 -91
  631. package/utils/totp.d.ts +2 -2
  632. package/utils/totp.js +57 -57
  633. package/utils/two-factor-auth.d.ts +15 -15
  634. package/utils/two-factor-auth.js +149 -149
  635. package/verifyer/hsm.d.ts +69 -69
  636. package/verifyer/hsm.js +481 -481
  637. package/verifyer/index.d.ts +80 -80
  638. package/verifyer/index.js +371 -371
  639. package/ws/peer-monitor-broadcaster.d.ts +23 -23
  640. package/ws/peer-monitor-broadcaster.js +55 -55
  641. package/.claude/skills/wechatpay-payment-integration/SKILL.md +0 -165
  642. 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 +0 -234
  643. package/.claude/skills/wechatpay-payment-integration/references/wechatpay-dev-cli/344/275/277/347/224/250/350/257/264/346/230/216.md +0 -74
  644. 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 +0 -109
  645. 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 +0 -55
  646. 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 +0 -70
  647. 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 +0 -99
  648. package/.claude/skills/wechatpay-payment-integration/scripts/bash/extract_and_sign.sh +0 -231
  649. package/.claude/skills/wechatpay-payment-integration/scripts/powershell/extract_and_sign.ps1 +0 -199
  650. package/.claude/skills/wechatpay-payment-integration/scripts/wechatpay-resource-sync.py +0 -646
@@ -1,56 +1,56 @@
1
- # 商户版裁剪清单 (MERCHANT-EDITION)
2
-
3
- 目标: 把全量 indexer (`run-unified.js`) 裁成商户自托管后端 —
4
- 只保留"卖家写链 + 商品查询"所需, 减小攻击面/依赖/内存。
5
-
6
- 状态: **未裁剪** (0.1.0 直搬全量, 先跑通安装器)。裁剪按本清单分批做,
7
- 每批裁完跑 `test/e2e-contract.md` 全量回归再发版。
8
-
9
- ## KEEP (必须保留)
10
-
11
- | 路由/模块 | 用途 |
12
- |---|---|
13
- | `routes/chain-writes.js` | 订单 /api/orders /api/payments |
14
- | `routes/chain-writes-products.js` | 商品 /api/products (+pause/resume/delete/stock) |
15
- | `routes/chain-writes-pledge.js` | 国库质押 (进件用) |
16
- | `api/seller-products-chain.js` | update-pledge / list-on-chain |
17
- | `routes/marketplace.js` | 商品搜索/详情 (未质押不可见) |
18
- | `middleware/security.js` + API key 鉴权 | 访问控制 |
19
- | `db` / `plugins/sqlite.js` | SQLite 存储 |
20
- | 健康检查 + `/api/wallet/resolve` | 安装器自检 |
21
-
22
- ## TRIM (商户版去掉)
23
-
24
- - `council/` `oracle/` `search/` `shipping/` `tools/` `oauth/` `verifyer/`
25
- - `p2p/` `peer/` `mcp/` `ws/` (P2P/M2M/MCP 是平台侧协作件)
26
- - `payments/` `payment/` (PSP 平台聚合支付; 商户收款在各自微信商户号)
27
- - `routes/economy.js` `routes/council.js` `routes/chain-registry.js` 等平台路由
28
- - TLS/port-manager (安装器交给 nginx/caddy)
29
-
30
- ## 依赖裁剪对照
31
-
32
- KEEP 后可去掉: `@modelcontextprotocol/sdk` `http-proxy-middleware` `qrcode`
33
- `bcrypt`(若 oauth 走) `axios`(多数平台路由用) — 以 TRIM 批次实测为准。
34
-
35
- ## 回归口径 (每批 TRIM 后必过)
36
-
37
- 1. POST /api/products (sxo- 前缀) → 链上入块, slot 可查
38
- 2. 重复 POST 同 sku → 转 AddStock 语义
39
- 3. PUT update-pledge (完整 sku) → code 0
40
- 4. POST /api/orders 多 items → chain_order_ids 对齐
41
- 5. POST /api/payments (链上单号) → code 0
42
- 6. 15s 未入块 → 502 tx_delivery_timeout
43
- 7. 同账户 burst 8 连发 → 全部入块 (串行化生效)
44
-
45
- ## 身份与签名 (2026-09-21 起)
46
-
47
- - **身份生成**: `core/seller-identity.js` 内置实现 (BIP39 24 词 → `m/44'/118'/0'/0/0`
48
- → secp256k1 → bech32 tct 地址, 全部走项目已有 @cosmjs 依赖, 派生正确性由
49
- `test-seller-identity.js` 的 cosmos 测试向量保证)。入驻页提交时幂等生成,
50
- 落盘 `<cwd>/tb-keyring/mnemonic.txt` + `address.txt` (Unix 0600)。
51
- - **交易签名**: **JS 直签已上线** (2026-09-21, `core/chain-signer.js`) — tb-keyring 助记词
52
- → DirectSecp256k1HdWallet → SigningStargateClient (protobufjs 反射 Registry, vendor proto/)
53
- → RPC broadcast_tx_sync → LCD 轮询 DeliverTx, 语义与 CLI 路径逐一对齐。`SIGN_MODE=js|trustchaind|auto`
54
- (默认 auto: js 优先, 失败降级 CLI)。CLI 路径 (trustchaind) 保留作 fallback。
55
- - **后续 (未做)**: gas simulate (当前固定 CHAIN_TX_GAS=300000 与 CLI 等价); serviceprovider
56
- 消息端到端 (等 v3.9.3 上舰队); CLI 路径淘汰评估 (直签稳定跑一个版本后)。
1
+ # 商户版裁剪清单 (MERCHANT-EDITION)
2
+
3
+ 目标: 把全量 indexer (`run-unified.js`) 裁成商户自托管后端 —
4
+ 只保留"卖家写链 + 商品查询"所需, 减小攻击面/依赖/内存。
5
+
6
+ 状态: **未裁剪** (0.1.0 直搬全量, 先跑通安装器)。裁剪按本清单分批做,
7
+ 每批裁完跑 `test/e2e-contract.md` 全量回归再发版。
8
+
9
+ ## KEEP (必须保留)
10
+
11
+ | 路由/模块 | 用途 |
12
+ |---|---|
13
+ | `routes/chain-writes.js` | 订单 /api/orders /api/payments |
14
+ | `routes/chain-writes-products.js` | 商品 /api/products (+pause/resume/delete/stock) |
15
+ | `routes/chain-writes-pledge.js` | 国库质押 (进件用) |
16
+ | `api/seller-products-chain.js` | update-pledge / list-on-chain |
17
+ | `routes/marketplace.js` | 商品搜索/详情 (未质押不可见) |
18
+ | `middleware/security.js` + API key 鉴权 | 访问控制 |
19
+ | `db` / `plugins/sqlite.js` | SQLite 存储 |
20
+ | 健康检查 + `/api/wallet/resolve` | 安装器自检 |
21
+
22
+ ## TRIM (商户版去掉)
23
+
24
+ - `council/` `oracle/` `search/` `shipping/` `tools/` `oauth/` `verifyer/`
25
+ - `p2p/` `peer/` `mcp/` `ws/` (P2P/M2M/MCP 是平台侧协作件)
26
+ - `payments/` `payment/` (PSP 平台聚合支付; 商户收款在各自微信商户号)
27
+ - `routes/economy.js` `routes/council.js` `routes/chain-registry.js` 等平台路由
28
+ - TLS/port-manager (安装器交给 nginx/caddy)
29
+
30
+ ## 依赖裁剪对照
31
+
32
+ KEEP 后可去掉: `@modelcontextprotocol/sdk` `http-proxy-middleware` `qrcode`
33
+ `bcrypt`(若 oauth 走) `axios`(多数平台路由用) — 以 TRIM 批次实测为准。
34
+
35
+ ## 回归口径 (每批 TRIM 后必过)
36
+
37
+ 1. POST /api/products (sxo- 前缀) → 链上入块, slot 可查
38
+ 2. 重复 POST 同 sku → 转 AddStock 语义
39
+ 3. PUT update-pledge (完整 sku) → code 0
40
+ 4. POST /api/orders 多 items → chain_order_ids 对齐
41
+ 5. POST /api/payments (链上单号) → code 0
42
+ 6. 15s 未入块 → 502 tx_delivery_timeout
43
+ 7. 同账户 burst 8 连发 → 全部入块 (串行化生效)
44
+
45
+ ## 身份与签名 (2026-09-21 起)
46
+
47
+ - **身份生成**: `core/seller-identity.js` 内置实现 (BIP39 24 词 → `m/44'/118'/0'/0/0`
48
+ → secp256k1 → bech32 tct 地址, 全部走项目已有 @cosmjs 依赖, 派生正确性由
49
+ `test-seller-identity.js` 的 cosmos 测试向量保证)。入驻页提交时幂等生成,
50
+ 落盘 `<cwd>/tb-keyring/mnemonic.txt` + `address.txt` (Unix 0600)。
51
+ - **交易签名**: **JS 直签已上线** (2026-09-21, `core/chain-signer.js`) — tb-keyring 助记词
52
+ → DirectSecp256k1HdWallet → SigningStargateClient (protobufjs 反射 Registry, vendor proto/)
53
+ → RPC broadcast_tx_sync → LCD 轮询 DeliverTx, 语义与 CLI 路径逐一对齐。`SIGN_MODE=js|trustchaind|auto`
54
+ (默认 auto: js 优先, 失败降级 CLI)。CLI 路径 (trustchaind) 保留作 fallback。
55
+ - **后续 (未做)**: gas simulate (当前固定 CHAIN_TX_GAS=300000 与 CLI 等价); serviceprovider
56
+ 消息端到端 (等 v3.9.3 上舰队); CLI 路径淘汰评估 (直签稳定跑一个版本后)。
package/README.md CHANGED
@@ -1,99 +1,99 @@
1
- # trustbase-seller-backend (商户版)
2
-
3
- TrustBase 保障链生态的卖家自托管后端: 商品上链 / 订单 / 支付确认 / 单件质押 的写入口。
4
- **单卖家形态** — 签名 key 即卖家身份, 私钥不出本机。
5
-
6
- 给「`npx trustbase-shop-init` 一键安装器」当依赖用, 也可以独立运行。
7
-
8
- ## 快速开始
9
-
10
- ```bash
11
- npm install -g trustbase-seller-backend
12
- cp .env.example .env # 编辑链端点与卖家 key
13
- tb-seller-backend
14
- ```
15
-
16
- 前置条件:
17
-
18
- - Node.js >= 18
19
- - 卖家身份: **内置生成** (入驻页或首次提交时自动生成, BIP39 24 词 → `m/44'/118'/0'/0/0` → tct1 地址,
20
- 助记词落盘 `tb-keyring/mnemonic.txt`, 只存本机)。也可继续用 trustchaind 生成:
21
- `trustchaind keys add seller --keyring-backend test --home ./tb-keyring`
22
- (生产建议 keyring-backend=file + 强口令)
23
- - 卖家地址需要 TCT: 上链列表费 (0.5 TCT/条) + 单件质押 (>=1 TCT/件)
24
-
25
- > ✅ 2026-09-21 更新: **JS 直签已上线** (`core/chain-signer.js`)。`SIGN_MODE` 三态:
26
- > - `js` — cosmjs 直签 (tb-keyring 助记词 → secp256k1 → 广播), 不需要 trustchaind 二进制
27
- > - `trustchaind` — 原 CLI 路径 (保留)
28
- > - `auto` (默认) — 有助记词走 js, 缺失或 js 签名失败自动降级 CLI
29
- >
30
- > Windows 商家机默认 auto, 装好即用, 无需 trustchaind。
31
-
32
- > 🔧 2026-09-22 更新: **路径不再依赖进程 cwd** (`core/paths.js`)。安装目录 = `TB_BASE_DIR`
33
- > → `<base>/node_modules/trustbase-seller-backend` 包布局 → 启动 cwd, 启动时解析一次并冻结;
34
- > `CHAIN_HOME` 相对值一律按安装目录解析成绝对路径 (历史故障: `cd /` 启动 → `trustchaind
35
- > tx sign --home /tb-keyring` 空 keyring → 签名失败)。
36
- > 一条命令自检 (路径/身份/签名通道/链上账户):
37
- >
38
- > ```bash
39
- > tb-seller-doctor # 或 tb-seller-backend doctor / npm run doctor
40
- > ```
41
- >
42
- > 启动日志会打印一行 `[boot] base=... keyring=... mnemonic=yes/no signMode=js|trustchaind`。
43
-
44
- > 🔧 2026-09-23 更新: **运行时数据 (api-keys.json / .encryption-key / auth-sessions.json 等)
45
- > 迁出 node_modules** — 原来落在 `<base>/node_modules/data/`, `npm install <tgz>` 升级会把
46
- > node_modules 下非声明目录清掉 → **升级即清空全部 API key 和加密密钥** (.215 实际发生过)。
47
- > 现在统一由 `core/runtime-data.js` 解析: 默认 `<安装目录>/data` (node_modules 同级, npm 碰不到),
48
- > 启动时自动把旧 `node_modules/data/` 的数据搬迁过来 (rename 优先, 失败 copy+校验+删,
49
- > 新目录同名文件先备份 `.bak-<ts>`); 环境变量 `TRUSTBASE_DATA_DIR` 可显式覆盖 (优先级最高,
50
- > doctor 会打印实际目录)。
51
-
52
- ## 与插件/安装器的契约
53
-
54
- | 端点 | 用途 | 备注 |
55
- |---|---|---|
56
- | `POST /api/products` | 商品上架 (sku_prefix=sxo) | wp_post_id=小整数 goods_id |
57
- | `PUT /api/seller/products/{sku}/update-pledge` | 改单件质押 | sku 支持完整 `sxo-{id}` |
58
- | `POST /api/orders` | 订单上链 | **v3.9.4**: `buyer_address` 必填 (真实买家 tct1, 不再回填卖家); 响应带 `chain_order_ids` + `order_intent_hash`/`order_intent_memo` |
59
- | `POST /api/order/ship` | 发货 | 仅 `PAID` 可发; `MsgShipOrder.seller` = 签名者; 字段是 `tracking_info` |
60
- | `POST /api/order/confirm` | 确认收货 (+评分) | 仅 `SHIPPED`; signer=**submitter**=本机卖家, `buyer` 取链上订单; 响应带 `submit_path` |
61
- | `POST /api/order/cancel` | 取消订单 | 仅 `PENDING`; signer=**seller**; `canceller` 缺省记卖家, `initiator:"buyer"` 记买家; 链上**无 reason 字段** |
62
- | `POST /api/order/dispute` | 发起争议 | `SHIPPED`/`CONFIRMED` 且未结算; signer=**submitter**; memo=`tb-auth:<sha256(申诉意愿)>` + 原文落 `order_intent_log` |
63
- | `POST /api/order/create` | ⛔ 410 停用 | 下单走 `POST /api/orders` (不做第二套) |
64
- | `POST /api/payments` | 支付确认 | order_id 用链上单号 |
65
- | `GET /api/marketplace/*` | 商品搜索/详情 | 未质押不可见 |
66
-
67
- > `/api/order/{ship,confirm,cancel,dispute}` 沿用 `Bearer JWT` 操作员鉴权 (与同文件既有 GET 一致);
68
- > 签名者恒为**本机卖家 key**, 与调用方是谁无关 —— 这是"卖家代买家提交"的实现方式。
69
-
70
- 安全语义 (2026-09-20 起): 订单/支付的 seller/authority 强制取签名 key;
71
- 广播后 15s 未入块返回 502 `tx_delivery_timeout` (调用方走重试); 同账户发送串行化。
72
-
73
- v3.9.4 卖家代建单 (2026-09 起, 必须与链升级同批上线): `MsgCreateOrder` 的 signer = **seller**
74
- (买家不装节点、浏览器不持私钥), `buyer` 必须由调用方给真实买家 tct1 地址
75
- (非空/合法 bech32/≠卖家, 且该买家已注册 trustcoin 账户); 买家意愿走 tx
76
- memo `tb-auth:<sha256(整批订单意愿)>`, 原文落本地 `order_intent_log` 备查。
77
- 详见 `core/order-intent.js` 与 `POST /api/orders` 注释。
78
-
79
- v3.9.4 / D2 订单生命周期 (同一批上线, 剧本 §7 的上线顺序):
80
-
81
- | 消息 | signer (proto 注解) | "实际发起方"记录字段 | 备注 |
82
- |---|---|---|---|
83
- | `MsgShipOrder` | `seller` | — | 语义未变 |
84
- | `MsgConfirmOrder` | **`submitter`** | `buyer` (keeper 校验 = 订单买家) | 白名单: 订单卖家 / `params.dispute_authority` / 超时兜底 |
85
- | `MsgCancelOrder` | **`seller`** | `canceller` (buyer 或 seller) | 仅 PENDING; keeper 校验 `seller` = 订单卖家 |
86
- | `MsgDisputeOrder` | **`submitter`** | `disputer` (buyer 或 seller) | 白名单同 Confirm |
87
-
88
- > ⚠️ **上线顺序 (硬约束): 先发本后端, 再换链。**
89
- > 链升级后旧后端发出的 tx 会全部被链拒 (缺 `submitter`/`seller` 字段, 或 `buyer == seller`);
90
- > 而本后端不发新语义的 Confirm/Cancel/Dispute, 则"确认收货 / 取消 / 争议"在链上不可用 (订单死锁)。
91
- > 本仓的 vendored proto (`proto/trustchain/order/v1/tx.proto`) 已按 trustchain-relmerge 对齐;
92
- > 再同步链侧 proto 时**必须一起 vendor** —— protobufjs 对未知字段是**静默丢弃**,
93
- > 漏 vendor 的症状是链上 `submitter is required`, 而不是本地报错。
94
-
95
- ## 商户版裁剪 (路线)
96
-
97
- 当前包是全量 indexer 的直搬 (跑 `run-unified.js`)。商户版裁剪目标:
98
- 只留 chain-writes / marketplace / seller 三组路由 + 健康检查, 去掉
99
- council/oracle/p2p/m2m/mcp 等平台侧组件。裁剪清单见 `MERCHANT-EDITION.md`。
1
+ # trustbase-seller-backend (商户版)
2
+
3
+ TrustBase 保障链生态的卖家自托管后端: 商品上链 / 订单 / 支付确认 / 单件质押 的写入口。
4
+ **单卖家形态** — 签名 key 即卖家身份, 私钥不出本机。
5
+
6
+ 给「`npx trustbase-shop-init` 一键安装器」当依赖用, 也可以独立运行。
7
+
8
+ ## 快速开始
9
+
10
+ ```bash
11
+ npm install -g trustbase-seller-backend
12
+ cp .env.example .env # 编辑链端点与卖家 key
13
+ tb-seller-backend
14
+ ```
15
+
16
+ 前置条件:
17
+
18
+ - Node.js >= 18
19
+ - 卖家身份: **内置生成** (入驻页或首次提交时自动生成, BIP39 24 词 → `m/44'/118'/0'/0/0` → tct1 地址,
20
+ 助记词落盘 `tb-keyring/mnemonic.txt`, 只存本机)。也可继续用 trustchaind 生成:
21
+ `trustchaind keys add seller --keyring-backend test --home ./tb-keyring`
22
+ (生产建议 keyring-backend=file + 强口令)
23
+ - 卖家地址需要 TCT: 上链列表费 (0.5 TCT/条) + 单件质押 (>=1 TCT/件)
24
+
25
+ > ✅ 2026-09-21 更新: **JS 直签已上线** (`core/chain-signer.js`)。`SIGN_MODE` 三态:
26
+ > - `js` — cosmjs 直签 (tb-keyring 助记词 → secp256k1 → 广播), 不需要 trustchaind 二进制
27
+ > - `trustchaind` — 原 CLI 路径 (保留)
28
+ > - `auto` (默认) — 有助记词走 js, 缺失或 js 签名失败自动降级 CLI
29
+ >
30
+ > Windows 商家机默认 auto, 装好即用, 无需 trustchaind。
31
+
32
+ > 🔧 2026-09-22 更新: **路径不再依赖进程 cwd** (`core/paths.js`)。安装目录 = `TB_BASE_DIR`
33
+ > → `<base>/node_modules/trustbase-seller-backend` 包布局 → 启动 cwd, 启动时解析一次并冻结;
34
+ > `CHAIN_HOME` 相对值一律按安装目录解析成绝对路径 (历史故障: `cd /` 启动 → `trustchaind
35
+ > tx sign --home /tb-keyring` 空 keyring → 签名失败)。
36
+ > 一条命令自检 (路径/身份/签名通道/链上账户):
37
+ >
38
+ > ```bash
39
+ > tb-seller-doctor # 或 tb-seller-backend doctor / npm run doctor
40
+ > ```
41
+ >
42
+ > 启动日志会打印一行 `[boot] base=... keyring=... mnemonic=yes/no signMode=js|trustchaind`。
43
+
44
+ > 🔧 2026-09-23 更新: **运行时数据 (api-keys.json / .encryption-key / auth-sessions.json 等)
45
+ > 迁出 node_modules** — 原来落在 `<base>/node_modules/data/`, `npm install <tgz>` 升级会把
46
+ > node_modules 下非声明目录清掉 → **升级即清空全部 API key 和加密密钥** (.215 实际发生过)。
47
+ > 现在统一由 `core/runtime-data.js` 解析: 默认 `<安装目录>/data` (node_modules 同级, npm 碰不到),
48
+ > 启动时自动把旧 `node_modules/data/` 的数据搬迁过来 (rename 优先, 失败 copy+校验+删,
49
+ > 新目录同名文件先备份 `.bak-<ts>`); 环境变量 `TRUSTBASE_DATA_DIR` 可显式覆盖 (优先级最高,
50
+ > doctor 会打印实际目录)。
51
+
52
+ ## 与插件/安装器的契约
53
+
54
+ | 端点 | 用途 | 备注 |
55
+ |---|---|---|
56
+ | `POST /api/products` | 商品上架 (sku_prefix=sxo) | wp_post_id=小整数 goods_id |
57
+ | `PUT /api/seller/products/{sku}/update-pledge` | 改单件质押 | sku 支持完整 `sxo-{id}` |
58
+ | `POST /api/orders` | 订单上链 | **v3.9.4**: `buyer_address` 必填 (真实买家 tct1, 不再回填卖家); 响应带 `chain_order_ids` + `order_intent_hash`/`order_intent_memo` |
59
+ | `POST /api/order/ship` | 发货 | 仅 `PAID` 可发; `MsgShipOrder.seller` = 签名者; 字段是 `tracking_info` |
60
+ | `POST /api/order/confirm` | 确认收货 (+评分) | 仅 `SHIPPED`; signer=**submitter**=本机卖家, `buyer` 取链上订单; 响应带 `submit_path` |
61
+ | `POST /api/order/cancel` | 取消订单 | 仅 `PENDING`; signer=**seller**; `canceller` 缺省记卖家, `initiator:"buyer"` 记买家; 链上**无 reason 字段** |
62
+ | `POST /api/order/dispute` | 发起争议 | `SHIPPED`/`CONFIRMED` 且未结算; signer=**submitter**; memo=`tb-auth:<sha256(申诉意愿)>` + 原文落 `order_intent_log` |
63
+ | `POST /api/order/create` | ⛔ 410 停用 | 下单走 `POST /api/orders` (不做第二套) |
64
+ | `POST /api/payments` | 支付确认 | order_id 用链上单号 |
65
+ | `GET /api/marketplace/*` | 商品搜索/详情 | 未质押不可见 |
66
+
67
+ > `/api/order/{ship,confirm,cancel,dispute}` 沿用 `Bearer JWT` 操作员鉴权 (与同文件既有 GET 一致);
68
+ > 签名者恒为**本机卖家 key**, 与调用方是谁无关 —— 这是"卖家代买家提交"的实现方式。
69
+
70
+ 安全语义 (2026-09-20 起): 订单/支付的 seller/authority 强制取签名 key;
71
+ 广播后 15s 未入块返回 502 `tx_delivery_timeout` (调用方走重试); 同账户发送串行化。
72
+
73
+ v3.9.4 卖家代建单 (2026-09 起, 必须与链升级同批上线): `MsgCreateOrder` 的 signer = **seller**
74
+ (买家不装节点、浏览器不持私钥), `buyer` 必须由调用方给真实买家 tct1 地址
75
+ (非空/合法 bech32/≠卖家, 且该买家已注册 trustcoin 账户); 买家意愿走 tx
76
+ memo `tb-auth:<sha256(整批订单意愿)>`, 原文落本地 `order_intent_log` 备查。
77
+ 详见 `core/order-intent.js` 与 `POST /api/orders` 注释。
78
+
79
+ v3.9.4 / D2 订单生命周期 (同一批上线, 剧本 §7 的上线顺序):
80
+
81
+ | 消息 | signer (proto 注解) | "实际发起方"记录字段 | 备注 |
82
+ |---|---|---|---|
83
+ | `MsgShipOrder` | `seller` | — | 语义未变 |
84
+ | `MsgConfirmOrder` | **`submitter`** | `buyer` (keeper 校验 = 订单买家) | 白名单: 订单卖家 / `params.dispute_authority` / 超时兜底 |
85
+ | `MsgCancelOrder` | **`seller`** | `canceller` (buyer 或 seller) | 仅 PENDING; keeper 校验 `seller` = 订单卖家 |
86
+ | `MsgDisputeOrder` | **`submitter`** | `disputer` (buyer 或 seller) | 白名单同 Confirm |
87
+
88
+ > ⚠️ **上线顺序 (硬约束): 先发本后端, 再换链。**
89
+ > 链升级后旧后端发出的 tx 会全部被链拒 (缺 `submitter`/`seller` 字段, 或 `buyer == seller`);
90
+ > 而本后端不发新语义的 Confirm/Cancel/Dispute, 则"确认收货 / 取消 / 争议"在链上不可用 (订单死锁)。
91
+ > 本仓的 vendored proto (`proto/trustchain/order/v1/tx.proto`) 已按 trustchain-relmerge 对齐;
92
+ > 再同步链侧 proto 时**必须一起 vendor** —— protobufjs 对未知字段是**静默丢弃**,
93
+ > 漏 vendor 的症状是链上 `submitter is required`, 而不是本地报错。
94
+
95
+ ## 商户版裁剪 (路线)
96
+
97
+ 当前包是全量 indexer 的直搬 (跑 `run-unified.js`)。商户版裁剪目标:
98
+ 只留 chain-writes / marketplace / seller 三组路由 + 健康检查, 去掉
99
+ council/oracle/p2p/m2m/mcp 等平台侧组件。裁剪清单见 `MERCHANT-EDITION.md`。
@@ -1,33 +1,33 @@
1
- /**
2
- * Minimal supertest replacement for HTTP route tests.
3
- *
4
- * Why we don't depend on supertest:
5
- * - The project doesn't already have it; adding a new devDep on Windows
6
- * risks npm install failure (per [[trustchain-cgo-windows]]).
7
- * - All we need is: spin up the express app on an ephemeral port, fire
8
- * a request, return { status, body, headers }. ~30 LOC.
9
- *
10
- * Usage:
11
- * const server = await startTestServer(app);
12
- * const res = await post(server, '/foo', { hello: 'world' }, { 'X-Foo': 'bar' });
13
- * expect(res.status).toBe(200);
14
- * await server.close();
15
- */
16
- import http from 'http';
17
- import type { Express } from 'express';
18
- export interface TestServer {
19
- url: string;
20
- port: number;
21
- close: () => Promise<void>;
22
- }
23
- export declare function startTestServer(app: Express): Promise<TestServer>;
24
- export interface TestResponse {
25
- status: number;
26
- body: any;
27
- headers: http.IncomingHttpHeaders;
28
- raw: string;
29
- }
30
- export declare const get: (server: TestServer, path: string, headers?: Record<string, string>) => Promise<TestResponse>;
31
- export declare const post: (server: TestServer, path: string, body: object | null, headers?: Record<string, string>) => Promise<TestResponse>;
32
- export declare const put: (server: TestServer, path: string, body: object | null, headers?: Record<string, string>) => Promise<TestResponse>;
1
+ /**
2
+ * Minimal supertest replacement for HTTP route tests.
3
+ *
4
+ * Why we don't depend on supertest:
5
+ * - The project doesn't already have it; adding a new devDep on Windows
6
+ * risks npm install failure (per [[trustchain-cgo-windows]]).
7
+ * - All we need is: spin up the express app on an ephemeral port, fire
8
+ * a request, return { status, body, headers }. ~30 LOC.
9
+ *
10
+ * Usage:
11
+ * const server = await startTestServer(app);
12
+ * const res = await post(server, '/foo', { hello: 'world' }, { 'X-Foo': 'bar' });
13
+ * expect(res.status).toBe(200);
14
+ * await server.close();
15
+ */
16
+ import http from 'http';
17
+ import type { Express } from 'express';
18
+ export interface TestServer {
19
+ url: string;
20
+ port: number;
21
+ close: () => Promise<void>;
22
+ }
23
+ export declare function startTestServer(app: Express): Promise<TestServer>;
24
+ export interface TestResponse {
25
+ status: number;
26
+ body: any;
27
+ headers: http.IncomingHttpHeaders;
28
+ raw: string;
29
+ }
30
+ export declare const get: (server: TestServer, path: string, headers?: Record<string, string>) => Promise<TestResponse>;
31
+ export declare const post: (server: TestServer, path: string, body: object | null, headers?: Record<string, string>) => Promise<TestResponse>;
32
+ export declare const put: (server: TestServer, path: string, body: object | null, headers?: Record<string, string>) => Promise<TestResponse>;
33
33
  //# sourceMappingURL=test-utils.d.ts.map
@@ -1,90 +1,90 @@
1
- "use strict";
2
- /**
3
- * Minimal supertest replacement for HTTP route tests.
4
- *
5
- * Why we don't depend on supertest:
6
- * - The project doesn't already have it; adding a new devDep on Windows
7
- * risks npm install failure (per [[trustchain-cgo-windows]]).
8
- * - All we need is: spin up the express app on an ephemeral port, fire
9
- * a request, return { status, body, headers }. ~30 LOC.
10
- *
11
- * Usage:
12
- * const server = await startTestServer(app);
13
- * const res = await post(server, '/foo', { hello: 'world' }, { 'X-Foo': 'bar' });
14
- * expect(res.status).toBe(200);
15
- * await server.close();
16
- */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.put = exports.post = exports.get = void 0;
22
- exports.startTestServer = startTestServer;
23
- const http_1 = __importDefault(require("http"));
24
- async function startTestServer(app) {
25
- return new Promise((resolve, reject) => {
26
- const server = app.listen(0, '127.0.0.1');
27
- server.once('error', reject);
28
- server.once('listening', () => {
29
- const addr = server.address();
30
- resolve({
31
- url: `http://127.0.0.1:${addr.port}`,
32
- port: addr.port,
33
- close: () => new Promise((res, rej) => {
34
- server.close((err) => (err ? rej(err) : res()));
35
- }),
36
- });
37
- });
38
- });
39
- }
40
- function makeRequest(method, baseUrl, path, body, headers) {
41
- return new Promise((resolve, reject) => {
42
- const url = new URL(path, baseUrl);
43
- const data = body !== undefined && body !== null ? Buffer.from(JSON.stringify(body)) : null;
44
- const reqHeaders = {
45
- Accept: 'application/json',
46
- ...(headers ?? {}),
47
- };
48
- if (data) {
49
- reqHeaders['Content-Type'] = reqHeaders['Content-Type'] ?? 'application/json';
50
- reqHeaders['Content-Length'] = String(data.length);
51
- }
52
- const req = http_1.default.request({
53
- method,
54
- hostname: url.hostname,
55
- port: url.port,
56
- path: url.pathname + url.search,
57
- headers: reqHeaders,
58
- }, (res) => {
59
- const chunks = [];
60
- res.on('data', (c) => chunks.push(c));
61
- res.on('end', () => {
62
- const raw = Buffer.concat(chunks).toString('utf8');
63
- let parsed = raw;
64
- try {
65
- parsed = JSON.parse(raw);
66
- }
67
- catch {
68
- /* leave as raw string */
69
- }
70
- resolve({
71
- status: res.statusCode ?? 0,
72
- body: parsed,
73
- headers: res.headers,
74
- raw,
75
- });
76
- });
77
- });
78
- req.on('error', reject);
79
- if (data)
80
- req.write(data);
81
- req.end();
82
- });
83
- }
84
- const get = (server, path, headers) => makeRequest('GET', server.url, path, null, headers);
85
- exports.get = get;
86
- const post = (server, path, body, headers) => makeRequest('POST', server.url, path, body, headers);
87
- exports.post = post;
88
- const put = (server, path, body, headers) => makeRequest('PUT', server.url, path, body, headers);
89
- exports.put = put;
1
+ "use strict";
2
+ /**
3
+ * Minimal supertest replacement for HTTP route tests.
4
+ *
5
+ * Why we don't depend on supertest:
6
+ * - The project doesn't already have it; adding a new devDep on Windows
7
+ * risks npm install failure (per [[trustchain-cgo-windows]]).
8
+ * - All we need is: spin up the express app on an ephemeral port, fire
9
+ * a request, return { status, body, headers }. ~30 LOC.
10
+ *
11
+ * Usage:
12
+ * const server = await startTestServer(app);
13
+ * const res = await post(server, '/foo', { hello: 'world' }, { 'X-Foo': 'bar' });
14
+ * expect(res.status).toBe(200);
15
+ * await server.close();
16
+ */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.put = exports.post = exports.get = void 0;
22
+ exports.startTestServer = startTestServer;
23
+ const http_1 = __importDefault(require("http"));
24
+ async function startTestServer(app) {
25
+ return new Promise((resolve, reject) => {
26
+ const server = app.listen(0, '127.0.0.1');
27
+ server.once('error', reject);
28
+ server.once('listening', () => {
29
+ const addr = server.address();
30
+ resolve({
31
+ url: `http://127.0.0.1:${addr.port}`,
32
+ port: addr.port,
33
+ close: () => new Promise((res, rej) => {
34
+ server.close((err) => (err ? rej(err) : res()));
35
+ }),
36
+ });
37
+ });
38
+ });
39
+ }
40
+ function makeRequest(method, baseUrl, path, body, headers) {
41
+ return new Promise((resolve, reject) => {
42
+ const url = new URL(path, baseUrl);
43
+ const data = body !== undefined && body !== null ? Buffer.from(JSON.stringify(body)) : null;
44
+ const reqHeaders = {
45
+ Accept: 'application/json',
46
+ ...(headers ?? {}),
47
+ };
48
+ if (data) {
49
+ reqHeaders['Content-Type'] = reqHeaders['Content-Type'] ?? 'application/json';
50
+ reqHeaders['Content-Length'] = String(data.length);
51
+ }
52
+ const req = http_1.default.request({
53
+ method,
54
+ hostname: url.hostname,
55
+ port: url.port,
56
+ path: url.pathname + url.search,
57
+ headers: reqHeaders,
58
+ }, (res) => {
59
+ const chunks = [];
60
+ res.on('data', (c) => chunks.push(c));
61
+ res.on('end', () => {
62
+ const raw = Buffer.concat(chunks).toString('utf8');
63
+ let parsed = raw;
64
+ try {
65
+ parsed = JSON.parse(raw);
66
+ }
67
+ catch {
68
+ /* leave as raw string */
69
+ }
70
+ resolve({
71
+ status: res.statusCode ?? 0,
72
+ body: parsed,
73
+ headers: res.headers,
74
+ raw,
75
+ });
76
+ });
77
+ });
78
+ req.on('error', reject);
79
+ if (data)
80
+ req.write(data);
81
+ req.end();
82
+ });
83
+ }
84
+ const get = (server, path, headers) => makeRequest('GET', server.url, path, null, headers);
85
+ exports.get = get;
86
+ const post = (server, path, body, headers) => makeRequest('POST', server.url, path, body, headers);
87
+ exports.post = post;
88
+ const put = (server, path, body, headers) => makeRequest('PUT', server.url, path, body, headers);
89
+ exports.put = put;
90
90
  //# sourceMappingURL=test-utils.js.map