trustbase-seller-backend 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1195) hide show
  1. package/.agents/skills/wechatpay-payment-integration/SKILL.md +165 -0
  2. package/.agents/skills/wechatpay-payment-integration/references/APIv3/346/216/245/345/217/243/345/212/250/346/200/201/346/216/222/351/232/234.md +234 -0
  3. package/.agents/skills/wechatpay-payment-integration/references/wechatpay-dev-cli/344/275/277/347/224/250/350/257/264/346/230/216.md +74 -0
  4. package/.agents/skills/wechatpay-payment-integration/references//345/237/272/347/241/200/346/246/202/345/277/265/345/217/212/344/270/232/345/212/241/344/273/213/347/273/215.md +109 -0
  5. package/.agents/skills/wechatpay-payment-integration/references//345/246/202/344/275/225/347/220/206/350/247/243/347/224/250/346/210/267/351/227/256/351/242/230.md +55 -0
  6. package/.agents/skills/wechatpay-payment-integration/references//346/216/245/345/205/245/350/264/250/351/207/217/346/243/200/346/237/245/346/270/205/345/215/225.md +70 -0
  7. package/.agents/skills/wechatpay-payment-integration/references//346/226/207/346/241/243/346/243/200/347/264/242/344/270/216/351/227/256/347/255/224.md +99 -0
  8. package/.agents/skills/wechatpay-payment-integration/scripts/bash/extract_and_sign.sh +231 -0
  9. package/.agents/skills/wechatpay-payment-integration/scripts/powershell/extract_and_sign.ps1 +199 -0
  10. package/.agents/skills/wechatpay-payment-integration/scripts/wechatpay-resource-sync.py +646 -0
  11. package/.env.example +70 -0
  12. package/MERCHANT-EDITION.md +56 -0
  13. package/README.md +99 -0
  14. package/api/__tests__/test-utils.d.ts +33 -0
  15. package/api/__tests__/test-utils.d.ts.map +1 -0
  16. package/api/__tests__/test-utils.js +90 -0
  17. package/api/__tests__/test-utils.js.map +1 -0
  18. package/api/db/case-library-types.d.ts +47 -0
  19. package/api/db/case-library-types.d.ts.map +1 -0
  20. package/api/db/case-library-types.js +105 -0
  21. package/api/db/case-library-types.js.map +1 -0
  22. package/api/db/case-library.db.d.ts +5 -0
  23. package/api/db/case-library.db.d.ts.map +1 -0
  24. package/api/db/case-library.db.js +127 -0
  25. package/api/db/case-library.db.js.map +1 -0
  26. package/api/email.d.ts +56 -0
  27. package/api/email.d.ts.map +1 -0
  28. package/api/email.js +307 -0
  29. package/api/email.js.map +1 -0
  30. package/api/index.d.ts +22 -0
  31. package/api/index.d.ts.map +1 -0
  32. package/api/index.js +41 -0
  33. package/api/index.js.map +1 -0
  34. package/api/integration-helpers.d.ts +153 -0
  35. package/api/integration-helpers.d.ts.map +1 -0
  36. package/api/integration-helpers.js +361 -0
  37. package/api/integration-helpers.js.map +1 -0
  38. package/api/lib/case-summary.d.ts +10 -0
  39. package/api/lib/case-summary.d.ts.map +1 -0
  40. package/api/lib/case-summary.js +30 -0
  41. package/api/lib/case-summary.js.map +1 -0
  42. package/api/middleware/p2p-auth.d.ts +140 -0
  43. package/api/middleware/p2p-auth.d.ts.map +1 -0
  44. package/api/middleware/p2p-auth.js +510 -0
  45. package/api/middleware/p2p-auth.js.map +1 -0
  46. package/api/middleware/tool-policy.d.ts +47 -0
  47. package/api/middleware/tool-policy.d.ts.map +1 -0
  48. package/api/middleware/tool-policy.js +156 -0
  49. package/api/middleware/tool-policy.js.map +1 -0
  50. package/api/oauth-adapters.d.ts +192 -0
  51. package/api/oauth-adapters.d.ts.map +1 -0
  52. package/api/oauth-adapters.js +456 -0
  53. package/api/oauth-adapters.js.map +1 -0
  54. package/api/oauth-bridge.d.ts +56 -0
  55. package/api/oauth-bridge.d.ts.map +1 -0
  56. package/api/oauth-bridge.js +624 -0
  57. package/api/oauth-bridge.js.map +1 -0
  58. package/api/oauth-router.d.ts +36 -0
  59. package/api/oauth-router.d.ts.map +1 -0
  60. package/api/oauth-router.js +54 -0
  61. package/api/oauth-router.js.map +1 -0
  62. package/api/p2p-mcp.d.ts +69 -0
  63. package/api/p2p-mcp.d.ts.map +1 -0
  64. package/api/p2p-mcp.js +286 -0
  65. package/api/p2p-mcp.js.map +1 -0
  66. package/api/payment-store.d.ts +56 -0
  67. package/api/payment-store.d.ts.map +1 -0
  68. package/api/payment-store.js +163 -0
  69. package/api/payment-store.js.map +1 -0
  70. package/api/payment.d.ts +14 -0
  71. package/api/payment.d.ts.map +1 -0
  72. package/api/payment.js +216 -0
  73. package/api/payment.js.map +1 -0
  74. package/api/pwa-stats.d.ts +67 -0
  75. package/api/pwa-stats.d.ts.map +1 -0
  76. package/api/pwa-stats.js +269 -0
  77. package/api/pwa-stats.js.map +1 -0
  78. package/api/riskcontrol-adapters.d.ts +114 -0
  79. package/api/riskcontrol-adapters.d.ts.map +1 -0
  80. package/api/riskcontrol-adapters.js +210 -0
  81. package/api/riskcontrol-adapters.js.map +1 -0
  82. package/api/riskcontrol-event-whitelist.d.ts +81 -0
  83. package/api/riskcontrol-event-whitelist.d.ts.map +1 -0
  84. package/api/riskcontrol-event-whitelist.js +181 -0
  85. package/api/riskcontrol-event-whitelist.js.map +1 -0
  86. package/api/riskcontrol-rules.d.ts +105 -0
  87. package/api/riskcontrol-rules.d.ts.map +1 -0
  88. package/api/riskcontrol-rules.js +399 -0
  89. package/api/riskcontrol-rules.js.map +1 -0
  90. package/api/riskcontrol-scoring.d.ts +72 -0
  91. package/api/riskcontrol-scoring.d.ts.map +1 -0
  92. package/api/riskcontrol-scoring.js +335 -0
  93. package/api/riskcontrol-scoring.js.map +1 -0
  94. package/api/riskcontrol-service.d.ts +60 -0
  95. package/api/riskcontrol-service.d.ts.map +1 -0
  96. package/api/riskcontrol-service.js +206 -0
  97. package/api/riskcontrol-service.js.map +1 -0
  98. package/api/riskcontrol-stream.d.ts +112 -0
  99. package/api/riskcontrol-stream.d.ts.map +1 -0
  100. package/api/riskcontrol-stream.js +230 -0
  101. package/api/riskcontrol-stream.js.map +1 -0
  102. package/api/riskcontrol-v5-e2e-test.d.ts +15 -0
  103. package/api/riskcontrol-v5-e2e-test.d.ts.map +1 -0
  104. package/api/riskcontrol-v5-e2e-test.js +204 -0
  105. package/api/riskcontrol-v5-e2e-test.js.map +1 -0
  106. package/api/riskcontrol-v5-router.d.ts +48 -0
  107. package/api/riskcontrol-v5-router.d.ts.map +1 -0
  108. package/api/riskcontrol-v5-router.js +226 -0
  109. package/api/riskcontrol-v5-router.js.map +1 -0
  110. package/api/riskcontrol-webhook.d.ts +88 -0
  111. package/api/riskcontrol-webhook.d.ts.map +1 -0
  112. package/api/riskcontrol-webhook.js +326 -0
  113. package/api/riskcontrol-webhook.js.map +1 -0
  114. package/api/routes/case-library.d.ts +4 -0
  115. package/api/routes/case-library.d.ts.map +1 -0
  116. package/api/routes/case-library.js +91 -0
  117. package/api/routes/case-library.js.map +1 -0
  118. package/api/seller-earnings.d.ts +23 -0
  119. package/api/seller-earnings.d.ts.map +1 -0
  120. package/api/seller-earnings.js +258 -0
  121. package/api/seller-earnings.js.map +1 -0
  122. package/api/seller-orders.d.ts +25 -0
  123. package/api/seller-orders.d.ts.map +1 -0
  124. package/api/seller-orders.js +398 -0
  125. package/api/seller-orders.js.map +1 -0
  126. package/api/seller-products-chain.d.ts +31 -0
  127. package/api/seller-products-chain.d.ts.map +1 -0
  128. package/api/seller-products-chain.js +308 -0
  129. package/api/seller-products-chain.js.map +1 -0
  130. package/api/seller-products.d.ts +30 -0
  131. package/api/seller-products.d.ts.map +1 -0
  132. package/api/seller-products.js +453 -0
  133. package/api/seller-products.js.map +1 -0
  134. package/api/seller-reputation.d.ts +21 -0
  135. package/api/seller-reputation.d.ts.map +1 -0
  136. package/api/seller-reputation.js +204 -0
  137. package/api/seller-reputation.js.map +1 -0
  138. package/api/seller-router.d.ts +33 -0
  139. package/api/seller-router.d.ts.map +1 -0
  140. package/api/seller-router.js +53 -0
  141. package/api/seller-router.js.map +1 -0
  142. package/api/seller-settings.d.ts +23 -0
  143. package/api/seller-settings.d.ts.map +1 -0
  144. package/api/seller-settings.js +279 -0
  145. package/api/seller-settings.js.map +1 -0
  146. package/api/shipping-store.d.ts +44 -0
  147. package/api/shipping-store.d.ts.map +1 -0
  148. package/api/shipping-store.js +154 -0
  149. package/api/shipping-store.js.map +1 -0
  150. package/api/shipping.d.ts +16 -0
  151. package/api/shipping.d.ts.map +1 -0
  152. package/api/shipping.js +239 -0
  153. package/api/shipping.js.map +1 -0
  154. package/api/social-endpoint-verify.d.ts +8 -0
  155. package/api/social-endpoint-verify.d.ts.map +1 -0
  156. package/api/social-endpoint-verify.js +152 -0
  157. package/api/social-endpoint-verify.js.map +1 -0
  158. package/api/social-posts.d.ts +65 -0
  159. package/api/social-posts.d.ts.map +1 -0
  160. package/api/social-posts.js +534 -0
  161. package/api/social-posts.js.map +1 -0
  162. package/api/social-router.d.ts +36 -0
  163. package/api/social-router.d.ts.map +1 -0
  164. package/api/social-router.js +56 -0
  165. package/api/social-router.js.map +1 -0
  166. package/api/social-shares.d.ts +40 -0
  167. package/api/social-shares.d.ts.map +1 -0
  168. package/api/social-shares.js +379 -0
  169. package/api/social-shares.js.map +1 -0
  170. package/api/social-whitelist.d.ts +41 -0
  171. package/api/social-whitelist.d.ts.map +1 -0
  172. package/api/social-whitelist.js +261 -0
  173. package/api/social-whitelist.js.map +1 -0
  174. package/api/storefront-orders.d.ts +23 -0
  175. package/api/storefront-orders.d.ts.map +1 -0
  176. package/api/storefront-orders.js +349 -0
  177. package/api/storefront-orders.js.map +1 -0
  178. package/api/storefront-products.d.ts +21 -0
  179. package/api/storefront-products.d.ts.map +1 -0
  180. package/api/storefront-products.js +181 -0
  181. package/api/storefront-products.js.map +1 -0
  182. package/api/storefront-router.d.ts +33 -0
  183. package/api/storefront-router.d.ts.map +1 -0
  184. package/api/storefront-router.js +47 -0
  185. package/api/storefront-router.js.map +1 -0
  186. package/api/storefront-user.d.ts +23 -0
  187. package/api/storefront-user.d.ts.map +1 -0
  188. package/api/storefront-user.js +336 -0
  189. package/api/storefront-user.js.map +1 -0
  190. package/api/test-db-helper.d.ts +29 -0
  191. package/api/test-db-helper.d.ts.map +1 -0
  192. package/api/test-db-helper.js +107 -0
  193. package/api/test-db-helper.js.map +1 -0
  194. package/api/traffic.d.ts +22 -0
  195. package/api/traffic.d.ts.map +1 -0
  196. package/api/traffic.js +112 -0
  197. package/api/traffic.js.map +1 -0
  198. package/api/wc-credentials.d.ts +34 -0
  199. package/api/wc-credentials.d.ts.map +1 -0
  200. package/api/wc-credentials.js +296 -0
  201. package/api/wc-credentials.js.map +1 -0
  202. package/api/wc-tracker-receiver.d.ts +47 -0
  203. package/api/wc-tracker-receiver.d.ts.map +1 -0
  204. package/api/wc-tracker-receiver.js +264 -0
  205. package/api/wc-tracker-receiver.js.map +1 -0
  206. package/api/wc-v3.d.ts +40 -0
  207. package/api/wc-v3.d.ts.map +1 -0
  208. package/api/wc-v3.js +694 -0
  209. package/api/wc-v3.js.map +1 -0
  210. package/bin/tb-doctor.js +32 -0
  211. package/bin/tb-seller-backend.js +42 -0
  212. package/check.d.ts +2 -0
  213. package/check.d.ts.map +1 -0
  214. package/check.js +19 -0
  215. package/check.js.map +1 -0
  216. package/config/export-import.d.ts +108 -0
  217. package/config/export-import.d.ts.map +1 -0
  218. package/config/export-import.js +234 -0
  219. package/config/export-import.js.map +1 -0
  220. package/config/manager.d.ts +73 -0
  221. package/config/manager.d.ts.map +1 -0
  222. package/config/manager.js +246 -0
  223. package/config/manager.js.map +1 -0
  224. package/config/profile.d.ts +42 -0
  225. package/config/profile.d.ts.map +1 -0
  226. package/config/profile.js +111 -0
  227. package/config/profile.js.map +1 -0
  228. package/core/address.js +23 -0
  229. package/core/advanced-performance.d.ts +149 -0
  230. package/core/advanced-performance.d.ts.map +1 -0
  231. package/core/advanced-performance.js +374 -0
  232. package/core/advanced-performance.js.map +1 -0
  233. package/core/alerting.d.ts +91 -0
  234. package/core/alerting.d.ts.map +1 -0
  235. package/core/alerting.js +379 -0
  236. package/core/alerting.js.map +1 -0
  237. package/core/app-store.d.ts +77 -0
  238. package/core/app-store.d.ts.map +1 -0
  239. package/core/app-store.js +207 -0
  240. package/core/app-store.js.map +1 -0
  241. package/core/boot-env.js +39 -0
  242. package/core/business-scope-schema.d.ts +60 -0
  243. package/core/business-scope-schema.d.ts.map +1 -0
  244. package/core/business-scope-schema.js +165 -0
  245. package/core/business-scope-schema.js.map +1 -0
  246. package/core/cache.d.ts +53 -0
  247. package/core/cache.d.ts.map +1 -0
  248. package/core/cache.js +130 -0
  249. package/core/cache.js.map +1 -0
  250. package/core/chain-listener.d.ts +47 -0
  251. package/core/chain-listener.d.ts.map +1 -0
  252. package/core/chain-listener.js +254 -0
  253. package/core/chain-listener.js.map +1 -0
  254. package/core/chain-reject.js +107 -0
  255. package/core/chain-signer.js +258 -0
  256. package/core/cleanup.d.ts +42 -0
  257. package/core/cleanup.d.ts.map +1 -0
  258. package/core/cleanup.js +144 -0
  259. package/core/cleanup.js.map +1 -0
  260. package/core/cluster.d.ts +78 -0
  261. package/core/cluster.d.ts.map +1 -0
  262. package/core/cluster.js +215 -0
  263. package/core/cluster.js.map +1 -0
  264. package/core/community-review.d.ts +82 -0
  265. package/core/community-review.d.ts.map +1 -0
  266. package/core/community-review.js +201 -0
  267. package/core/community-review.js.map +1 -0
  268. package/core/connection-pool.d.ts +72 -0
  269. package/core/connection-pool.d.ts.map +1 -0
  270. package/core/connection-pool.js +173 -0
  271. package/core/connection-pool.js.map +1 -0
  272. package/core/consistency.d.ts +130 -0
  273. package/core/consistency.d.ts.map +1 -0
  274. package/core/consistency.js +340 -0
  275. package/core/consistency.js.map +1 -0
  276. package/core/content-ai.d.ts +303 -0
  277. package/core/content-ai.d.ts.map +1 -0
  278. package/core/content-ai.js +344 -0
  279. package/core/content-ai.js.map +1 -0
  280. package/core/content-backfill.d.ts +55 -0
  281. package/core/content-backfill.d.ts.map +1 -0
  282. package/core/content-backfill.js +174 -0
  283. package/core/content-backfill.js.map +1 -0
  284. package/core/conversion-rate-sync.d.ts +97 -0
  285. package/core/conversion-rate-sync.d.ts.map +1 -0
  286. package/core/conversion-rate-sync.js +195 -0
  287. package/core/conversion-rate-sync.js.map +1 -0
  288. package/core/coverage-backup.d.ts +87 -0
  289. package/core/coverage-backup.d.ts.map +1 -0
  290. package/core/coverage-backup.js +265 -0
  291. package/core/coverage-backup.js.map +1 -0
  292. package/core/db-installer.d.ts +108 -0
  293. package/core/db-installer.d.ts.map +1 -0
  294. package/core/db-installer.js +414 -0
  295. package/core/db-installer.js.map +1 -0
  296. package/core/device-analyzer.d.ts +96 -0
  297. package/core/device-analyzer.d.ts.map +1 -0
  298. package/core/device-analyzer.js +235 -0
  299. package/core/device-analyzer.js.map +1 -0
  300. package/core/discovery.d.ts +165 -0
  301. package/core/discovery.d.ts.map +1 -0
  302. package/core/discovery.js +363 -0
  303. package/core/discovery.js.map +1 -0
  304. package/core/distributed.d.ts +172 -0
  305. package/core/distributed.d.ts.map +1 -0
  306. package/core/distributed.js +422 -0
  307. package/core/distributed.js.map +1 -0
  308. package/core/doctor.js +249 -0
  309. package/core/enforcement.d.ts +57 -0
  310. package/core/enforcement.d.ts.map +1 -0
  311. package/core/enforcement.js +115 -0
  312. package/core/enforcement.js.map +1 -0
  313. package/core/error-handler.d.ts +131 -0
  314. package/core/error-handler.d.ts.map +1 -0
  315. package/core/error-handler.js +291 -0
  316. package/core/error-handler.js.map +1 -0
  317. package/core/federated-learning.d.ts +124 -0
  318. package/core/federated-learning.d.ts.map +1 -0
  319. package/core/federated-learning.js +338 -0
  320. package/core/federated-learning.js.map +1 -0
  321. package/core/fingerprint.d.ts +95 -0
  322. package/core/fingerprint.d.ts.map +1 -0
  323. package/core/fingerprint.js +313 -0
  324. package/core/fingerprint.js.map +1 -0
  325. package/core/geoip.d.ts +67 -0
  326. package/core/geoip.d.ts.map +1 -0
  327. package/core/geoip.js +174 -0
  328. package/core/geoip.js.map +1 -0
  329. package/core/gossip.d.ts +141 -0
  330. package/core/gossip.d.ts.map +1 -0
  331. package/core/gossip.js +372 -0
  332. package/core/gossip.js.map +1 -0
  333. package/core/governance.d.ts +147 -0
  334. package/core/governance.d.ts.map +1 -0
  335. package/core/governance.js +351 -0
  336. package/core/governance.js.map +1 -0
  337. package/core/indexer-enhancements.d.ts +164 -0
  338. package/core/indexer-enhancements.d.ts.map +1 -0
  339. package/core/indexer-enhancements.js +429 -0
  340. package/core/indexer-enhancements.js.map +1 -0
  341. package/core/intrusion-detection.d.ts +79 -0
  342. package/core/intrusion-detection.d.ts.map +1 -0
  343. package/core/intrusion-detection.js +322 -0
  344. package/core/intrusion-detection.js.map +1 -0
  345. package/core/lifecycle.d.ts +118 -0
  346. package/core/lifecycle.d.ts.map +1 -0
  347. package/core/lifecycle.js +310 -0
  348. package/core/lifecycle.js.map +1 -0
  349. package/core/location.d.ts +99 -0
  350. package/core/location.d.ts.map +1 -0
  351. package/core/location.js +219 -0
  352. package/core/location.js.map +1 -0
  353. package/core/maxmind-integration.d.ts +68 -0
  354. package/core/maxmind-integration.d.ts.map +1 -0
  355. package/core/maxmind-integration.js +245 -0
  356. package/core/maxmind-integration.js.map +1 -0
  357. package/core/migration.d.ts +58 -0
  358. package/core/migration.d.ts.map +1 -0
  359. package/core/migration.js +223 -0
  360. package/core/migration.js.map +1 -0
  361. package/core/monitoring.d.ts +153 -0
  362. package/core/monitoring.d.ts.map +1 -0
  363. package/core/monitoring.js +406 -0
  364. package/core/monitoring.js.map +1 -0
  365. package/core/offsite-backup.d.ts +71 -0
  366. package/core/offsite-backup.d.ts.map +1 -0
  367. package/core/offsite-backup.js +341 -0
  368. package/core/offsite-backup.js.map +1 -0
  369. package/core/order-intent-store.js +83 -0
  370. package/core/order-intent.js +273 -0
  371. package/core/paths.js +116 -0
  372. package/core/performance.d.ts +173 -0
  373. package/core/performance.d.ts.map +1 -0
  374. package/core/performance.js +386 -0
  375. package/core/performance.js.map +1 -0
  376. package/core/product-flag.d.ts +364 -0
  377. package/core/product-flag.d.ts.map +1 -0
  378. package/core/product-flag.js +465 -0
  379. package/core/product-flag.js.map +1 -0
  380. package/core/protection.d.ts +139 -0
  381. package/core/protection.d.ts.map +1 -0
  382. package/core/protection.js +327 -0
  383. package/core/protection.js.map +1 -0
  384. package/core/region-adapter.d.ts +152 -0
  385. package/core/region-adapter.d.ts.map +1 -0
  386. package/core/region-adapter.js +505 -0
  387. package/core/region-adapter.js.map +1 -0
  388. package/core/region-configs.d.ts +12 -0
  389. package/core/region-configs.d.ts.map +1 -0
  390. package/core/region-configs.js +907 -0
  391. package/core/region-configs.js.map +1 -0
  392. package/core/review-antifraud.d.ts +80 -0
  393. package/core/review-antifraud.d.ts.map +1 -0
  394. package/core/review-antifraud.js +193 -0
  395. package/core/review-antifraud.js.map +1 -0
  396. package/core/rules-updater.d.ts +89 -0
  397. package/core/rules-updater.d.ts.map +1 -0
  398. package/core/rules-updater.js +261 -0
  399. package/core/rules-updater.js.map +1 -0
  400. package/core/runtime-data.js +203 -0
  401. package/core/security.d.ts +144 -0
  402. package/core/security.d.ts.map +1 -0
  403. package/core/security.js +390 -0
  404. package/core/security.js.map +1 -0
  405. package/core/seller-identity.js +78 -0
  406. package/core/session-manager.d.ts +93 -0
  407. package/core/session-manager.d.ts.map +1 -0
  408. package/core/session-manager.js +262 -0
  409. package/core/session-manager.js.map +1 -0
  410. package/core/state-sync.d.ts +121 -0
  411. package/core/state-sync.d.ts.map +1 -0
  412. package/core/state-sync.js +287 -0
  413. package/core/state-sync.js.map +1 -0
  414. package/core/testing.d.ts +97 -0
  415. package/core/testing.d.ts.map +1 -0
  416. package/core/testing.js +361 -0
  417. package/core/testing.js.map +1 -0
  418. package/core/trust-score.d.ts +51 -0
  419. package/core/trust-score.d.ts.map +1 -0
  420. package/core/trust-score.js +188 -0
  421. package/core/trust-score.js.map +1 -0
  422. package/core/trustworthiness.d.ts +140 -0
  423. package/core/trustworthiness.d.ts.map +1 -0
  424. package/core/trustworthiness.js +375 -0
  425. package/core/trustworthiness.js.map +1 -0
  426. package/core/types.d.ts +258 -0
  427. package/core/types.d.ts.map +1 -0
  428. package/core/types.js +9 -0
  429. package/core/types.js.map +1 -0
  430. package/core/upgrade-manager.d.ts +114 -0
  431. package/core/upgrade-manager.d.ts.map +1 -0
  432. package/core/upgrade-manager.js +264 -0
  433. package/core/upgrade-manager.js.map +1 -0
  434. package/core/upgrader.d.ts +107 -0
  435. package/core/upgrader.d.ts.map +1 -0
  436. package/core/upgrader.js +389 -0
  437. package/core/upgrader.js.map +1 -0
  438. package/core/websocket.d.ts +78 -0
  439. package/core/websocket.d.ts.map +1 -0
  440. package/core/websocket.js +292 -0
  441. package/core/websocket.js.map +1 -0
  442. package/council/hidden-weight.d.ts +45 -0
  443. package/council/hidden-weight.d.ts.map +1 -0
  444. package/council/hidden-weight.js +135 -0
  445. package/council/hidden-weight.js.map +1 -0
  446. package/db/email-migrations.sql +31 -0
  447. package/db/oauth-migrate.d.ts +39 -0
  448. package/db/oauth-migrate.d.ts.map +1 -0
  449. package/db/oauth-migrate.js +201 -0
  450. package/db/oauth-migrate.js.map +1 -0
  451. package/db/oauth-migrations.sql +92 -0
  452. package/db/social-migrate.d.ts +12 -0
  453. package/db/social-migrate.d.ts.map +1 -0
  454. package/db/social-migrate.js +102 -0
  455. package/db/social-migrate.js.map +1 -0
  456. package/db/social-migrations.sql +94 -0
  457. package/db/store-migrate.d.ts +33 -0
  458. package/db/store-migrate.d.ts.map +1 -0
  459. package/db/store-migrate.js +149 -0
  460. package/db/store-migrate.js.map +1 -0
  461. package/db/store-migrations.sql +242 -0
  462. package/debug.d.ts +2 -0
  463. package/debug.d.ts.map +1 -0
  464. package/debug.js +18 -0
  465. package/debug.js.map +1 -0
  466. package/event-listener.d.ts +93 -0
  467. package/event-listener.d.ts.map +1 -0
  468. package/event-listener.js +321 -0
  469. package/event-listener.js.map +1 -0
  470. package/event-whitelist.d.ts +79 -0
  471. package/event-whitelist.d.ts.map +1 -0
  472. package/event-whitelist.js +533 -0
  473. package/event-whitelist.js.map +1 -0
  474. package/index.d.ts +45 -0
  475. package/index.d.ts.map +1 -0
  476. package/index.js +361 -0
  477. package/index.js.map +1 -0
  478. package/init-node.d.ts +9 -0
  479. package/init-node.d.ts.map +1 -0
  480. package/init-node.js +230 -0
  481. package/init-node.js.map +1 -0
  482. package/mcp/ai-tools.d.ts +2 -0
  483. package/mcp/ai-tools.d.ts.map +1 -0
  484. package/mcp/ai-tools.js +266 -0
  485. package/mcp/ai-tools.js.map +1 -0
  486. package/mcp/auto-dispatch-tools.d.ts +2 -0
  487. package/mcp/auto-dispatch-tools.d.ts.map +1 -0
  488. package/mcp/auto-dispatch-tools.js +348 -0
  489. package/mcp/auto-dispatch-tools.js.map +1 -0
  490. package/mcp/business-scope-tools.d.ts +11 -0
  491. package/mcp/business-scope-tools.d.ts.map +1 -0
  492. package/mcp/business-scope-tools.js +179 -0
  493. package/mcp/business-scope-tools.js.map +1 -0
  494. package/mcp/buyer-tools.d.ts +67 -0
  495. package/mcp/buyer-tools.d.ts.map +1 -0
  496. package/mcp/buyer-tools.js +445 -0
  497. package/mcp/buyer-tools.js.map +1 -0
  498. package/mcp/interfaces.d.ts +1058 -0
  499. package/mcp/interfaces.d.ts.map +1 -0
  500. package/mcp/interfaces.js +13 -0
  501. package/mcp/interfaces.js.map +1 -0
  502. package/mcp/m2m-chat-tool.d.ts +50 -0
  503. package/mcp/m2m-chat-tool.d.ts.map +1 -0
  504. package/mcp/m2m-chat-tool.js +432 -0
  505. package/mcp/m2m-chat-tool.js.map +1 -0
  506. package/mcp/migrations.d.ts +30 -0
  507. package/mcp/migrations.d.ts.map +1 -0
  508. package/mcp/migrations.js +391 -0
  509. package/mcp/migrations.js.map +1 -0
  510. package/mcp/peer-tools.d.ts +163 -0
  511. package/mcp/peer-tools.d.ts.map +1 -0
  512. package/mcp/peer-tools.js +532 -0
  513. package/mcp/peer-tools.js.map +1 -0
  514. package/mcp/plugin-management-tools.d.ts +2 -0
  515. package/mcp/plugin-management-tools.d.ts.map +1 -0
  516. package/mcp/plugin-management-tools.js +327 -0
  517. package/mcp/plugin-management-tools.js.map +1 -0
  518. package/mcp/product-type-tools.d.ts +2 -0
  519. package/mcp/product-type-tools.d.ts.map +1 -0
  520. package/mcp/product-type-tools.js +470 -0
  521. package/mcp/product-type-tools.js.map +1 -0
  522. package/mcp/security-tools.d.ts +2 -0
  523. package/mcp/security-tools.d.ts.map +1 -0
  524. package/mcp/security-tools.js +313 -0
  525. package/mcp/security-tools.js.map +1 -0
  526. package/mcp/seller-query-tools.d.ts +2 -0
  527. package/mcp/seller-query-tools.d.ts.map +1 -0
  528. package/mcp/seller-query-tools.js +179 -0
  529. package/mcp/seller-query-tools.js.map +1 -0
  530. package/mcp/server.d.ts +11 -0
  531. package/mcp/server.d.ts.map +1 -0
  532. package/mcp/server.js +68 -0
  533. package/mcp/server.js.map +1 -0
  534. package/mcp/standalone-server.d.ts +34 -0
  535. package/mcp/standalone-server.d.ts.map +1 -0
  536. package/mcp/standalone-server.js +261 -0
  537. package/mcp/standalone-server.js.map +1 -0
  538. package/mcp/tools-integration.d.ts +31 -0
  539. package/mcp/tools-integration.d.ts.map +1 -0
  540. package/mcp/tools-integration.js +288 -0
  541. package/mcp/tools-integration.js.map +1 -0
  542. package/mcp/web-panel.d.ts +18 -0
  543. package/mcp/web-panel.d.ts.map +1 -0
  544. package/mcp/web-panel.js +1657 -0
  545. package/mcp/web-panel.js.map +1 -0
  546. package/middleware/api-key-auth.d.ts +64 -0
  547. package/middleware/api-key-auth.d.ts.map +1 -0
  548. package/middleware/api-key-auth.js +255 -0
  549. package/middleware/api-key-auth.js.map +1 -0
  550. package/middleware/scope-auth.d.ts +54 -0
  551. package/middleware/scope-auth.d.ts.map +1 -0
  552. package/middleware/scope-auth.js +153 -0
  553. package/middleware/scope-auth.js.map +1 -0
  554. package/middleware/security.d.ts +48 -0
  555. package/middleware/security.d.ts.map +1 -0
  556. package/middleware/security.js +217 -0
  557. package/middleware/security.js.map +1 -0
  558. package/middleware/wallet-auth.d.ts +54 -0
  559. package/middleware/wallet-auth.d.ts.map +1 -0
  560. package/middleware/wallet-auth.js +158 -0
  561. package/middleware/wallet-auth.js.map +1 -0
  562. package/oauth/chain-revocation-sink.d.ts +24 -0
  563. package/oauth/chain-revocation-sink.d.ts.map +1 -0
  564. package/oauth/chain-revocation-sink.js +47 -0
  565. package/oauth/chain-revocation-sink.js.map +1 -0
  566. package/oauth/gossip-sync.d.ts +25 -0
  567. package/oauth/gossip-sync.d.ts.map +1 -0
  568. package/oauth/gossip-sync.js +62 -0
  569. package/oauth/gossip-sync.js.map +1 -0
  570. package/oauth/issuer-keys.d.ts +31 -0
  571. package/oauth/issuer-keys.d.ts.map +1 -0
  572. package/oauth/issuer-keys.js +117 -0
  573. package/oauth/issuer-keys.js.map +1 -0
  574. package/oauth/peer-resolver.d.ts +25 -0
  575. package/oauth/peer-resolver.d.ts.map +1 -0
  576. package/oauth/peer-resolver.js +81 -0
  577. package/oauth/peer-resolver.js.map +1 -0
  578. package/oauth/revocation-store.d.ts +58 -0
  579. package/oauth/revocation-store.d.ts.map +1 -0
  580. package/oauth/revocation-store.js +86 -0
  581. package/oauth/revocation-store.js.map +1 -0
  582. package/oauth/token-v2.d.ts +101 -0
  583. package/oauth/token-v2.d.ts.map +1 -0
  584. package/oauth/token-v2.js +167 -0
  585. package/oauth/token-v2.js.map +1 -0
  586. package/oracle/c5-glue.js +603 -0
  587. package/oracle/ops-console.js +623 -0
  588. package/oracle/oracle-sync.d.ts +29 -0
  589. package/oracle/oracle-sync.d.ts.map +1 -0
  590. package/oracle/oracle-sync.js +445 -0
  591. package/oracle/oracle-sync.js.map +1 -0
  592. package/oracle/registry.d.ts +30 -0
  593. package/oracle/registry.d.ts.map +1 -0
  594. package/oracle/registry.js +62 -0
  595. package/oracle/registry.js.map +1 -0
  596. package/p2p/availability.d.ts +188 -0
  597. package/p2p/availability.d.ts.map +1 -0
  598. package/p2p/availability.js +574 -0
  599. package/p2p/availability.js.map +1 -0
  600. package/p2p/bootstrap.d.ts +42 -0
  601. package/p2p/bootstrap.d.ts.map +1 -0
  602. package/p2p/bootstrap.js +146 -0
  603. package/p2p/bootstrap.js.map +1 -0
  604. package/p2p/buyer-client.d.ts +98 -0
  605. package/p2p/buyer-client.d.ts.map +1 -0
  606. package/p2p/buyer-client.js +199 -0
  607. package/p2p/buyer-client.js.map +1 -0
  608. package/p2p/cdn-ddns.d.ts +208 -0
  609. package/p2p/cdn-ddns.d.ts.map +1 -0
  610. package/p2p/cdn-ddns.js +500 -0
  611. package/p2p/cdn-ddns.js.map +1 -0
  612. package/p2p/cluster-sync.d.ts +115 -0
  613. package/p2p/cluster-sync.d.ts.map +1 -0
  614. package/p2p/cluster-sync.js +330 -0
  615. package/p2p/cluster-sync.js.map +1 -0
  616. package/p2p/consistency-check.d.ts +30 -0
  617. package/p2p/consistency-check.d.ts.map +1 -0
  618. package/p2p/consistency-check.js +168 -0
  619. package/p2p/consistency-check.js.map +1 -0
  620. package/p2p/endpoint-registry.d.ts +41 -0
  621. package/p2p/endpoint-registry.d.ts.map +1 -0
  622. package/p2p/endpoint-registry.js +128 -0
  623. package/p2p/endpoint-registry.js.map +1 -0
  624. package/p2p/ipv6.d.ts +120 -0
  625. package/p2p/ipv6.d.ts.map +1 -0
  626. package/p2p/ipv6.js +425 -0
  627. package/p2p/ipv6.js.map +1 -0
  628. package/p2p/protocol.d.ts +100 -0
  629. package/p2p/protocol.d.ts.map +1 -0
  630. package/p2p/protocol.js +330 -0
  631. package/p2p/protocol.js.map +1 -0
  632. package/p2p/reliability.d.ts +56 -0
  633. package/p2p/reliability.d.ts.map +1 -0
  634. package/p2p/reliability.js +240 -0
  635. package/p2p/reliability.js.map +1 -0
  636. package/p2p/seller-service.d.ts +53 -0
  637. package/p2p/seller-service.d.ts.map +1 -0
  638. package/p2p/seller-service.js +276 -0
  639. package/p2p/seller-service.js.map +1 -0
  640. package/p2p/signing.d.ts +31 -0
  641. package/p2p/signing.d.ts.map +1 -0
  642. package/p2p/signing.js +95 -0
  643. package/p2p/signing.js.map +1 -0
  644. package/package.json +73 -0
  645. package/payment/api.d.ts +9 -0
  646. package/payment/api.d.ts.map +1 -0
  647. package/payment/api.js +141 -0
  648. package/payment/api.js.map +1 -0
  649. package/payment/gateway.d.ts +114 -0
  650. package/payment/gateway.d.ts.map +1 -0
  651. package/payment/gateway.js +231 -0
  652. package/payment/gateway.js.map +1 -0
  653. package/payments/alipay/index.d.ts +18 -0
  654. package/payments/alipay/index.d.ts.map +1 -0
  655. package/payments/alipay/index.js +55 -0
  656. package/payments/alipay/index.js.map +1 -0
  657. package/payments/base.d.ts +13 -0
  658. package/payments/base.d.ts.map +1 -0
  659. package/payments/base.js +28 -0
  660. package/payments/base.js.map +1 -0
  661. package/payments/index.d.ts +18 -0
  662. package/payments/index.d.ts.map +1 -0
  663. package/payments/index.js +66 -0
  664. package/payments/index.js.map +1 -0
  665. package/payments/template/index.d.ts +18 -0
  666. package/payments/template/index.d.ts.map +1 -0
  667. package/payments/template/index.js +57 -0
  668. package/payments/template/index.js.map +1 -0
  669. package/payments/types.d.ts +42 -0
  670. package/payments/types.d.ts.map +1 -0
  671. package/payments/types.js +3 -0
  672. package/payments/types.js.map +1 -0
  673. package/payments/wechat/index.d.ts +18 -0
  674. package/payments/wechat/index.d.ts.map +1 -0
  675. package/payments/wechat/index.js +54 -0
  676. package/payments/wechat/index.js.map +1 -0
  677. package/peer/chain-signer.d.ts +74 -0
  678. package/peer/chain-signer.d.ts.map +1 -0
  679. package/peer/chain-signer.js +149 -0
  680. package/peer/chain-signer.js.map +1 -0
  681. package/peer/config.d.ts +71 -0
  682. package/peer/config.d.ts.map +1 -0
  683. package/peer/config.js +61 -0
  684. package/peer/config.js.map +1 -0
  685. package/peer/index.d.ts +12 -0
  686. package/peer/index.d.ts.map +1 -0
  687. package/peer/index.js +46 -0
  688. package/peer/index.js.map +1 -0
  689. package/peer/key-store.d.ts +66 -0
  690. package/peer/key-store.d.ts.map +1 -0
  691. package/peer/key-store.js +163 -0
  692. package/peer/key-store.js.map +1 -0
  693. package/peer/proto-codec.d.ts +103 -0
  694. package/peer/proto-codec.d.ts.map +1 -0
  695. package/peer/proto-codec.js +423 -0
  696. package/peer/proto-codec.js.map +1 -0
  697. package/peer/registrar.d.ts +88 -0
  698. package/peer/registrar.d.ts.map +1 -0
  699. package/peer/registrar.js +271 -0
  700. package/peer/registrar.js.map +1 -0
  701. package/peer/registry.d.ts +31 -0
  702. package/peer/registry.d.ts.map +1 -0
  703. package/peer/registry.js +143 -0
  704. package/peer/registry.js.map +1 -0
  705. package/plugins/auth.d.ts +193 -0
  706. package/plugins/auth.d.ts.map +1 -0
  707. package/plugins/auth.js +923 -0
  708. package/plugins/auth.js.map +1 -0
  709. package/plugins/manager.d.ts +37 -0
  710. package/plugins/manager.d.ts.map +1 -0
  711. package/plugins/manager.js +83 -0
  712. package/plugins/manager.js.map +1 -0
  713. package/plugins/oauth.d.ts +249 -0
  714. package/plugins/oauth.d.ts.map +1 -0
  715. package/plugins/oauth.js +979 -0
  716. package/plugins/oauth.js.map +1 -0
  717. package/plugins/p2p-message.d.ts +133 -0
  718. package/plugins/p2p-message.d.ts.map +1 -0
  719. package/plugins/p2p-message.js +443 -0
  720. package/plugins/p2p-message.js.map +1 -0
  721. package/plugins/postgresql.d.ts +54 -0
  722. package/plugins/postgresql.d.ts.map +1 -0
  723. package/plugins/postgresql.js +743 -0
  724. package/plugins/postgresql.js.map +1 -0
  725. package/plugins/relationship.d.ts +141 -0
  726. package/plugins/relationship.d.ts.map +1 -0
  727. package/plugins/relationship.js +395 -0
  728. package/plugins/relationship.js.map +1 -0
  729. package/plugins/sqlite.d.ts +200 -0
  730. package/plugins/sqlite.d.ts.map +1 -0
  731. package/plugins/sqlite.js +2412 -0
  732. package/plugins/sqlite.js.map +1 -0
  733. package/port-manager/disguise/ssh.d.ts +19 -0
  734. package/port-manager/disguise/ssh.d.ts.map +1 -0
  735. package/port-manager/disguise/ssh.js +104 -0
  736. package/port-manager/disguise/ssh.js.map +1 -0
  737. package/port-manager/port-manager.d.ts +65 -0
  738. package/port-manager/port-manager.d.ts.map +1 -0
  739. package/port-manager/port-manager.js +164 -0
  740. package/port-manager/port-manager.js.map +1 -0
  741. package/port-manager/port-scanner.d.ts +22 -0
  742. package/port-manager/port-scanner.d.ts.map +1 -0
  743. package/port-manager/port-scanner.js +187 -0
  744. package/port-manager/port-scanner.js.map +1 -0
  745. package/port-manager/types.d.ts +51 -0
  746. package/port-manager/types.d.ts.map +1 -0
  747. package/port-manager/types.js +6 -0
  748. package/port-manager/types.js.map +1 -0
  749. package/proto/amino/amino.proto +84 -0
  750. package/proto/cosmos/base/v1beta1/coin.proto +61 -0
  751. package/proto/cosmos/msg/v1/msg.proto +30 -0
  752. package/proto/cosmos_proto/cosmos.proto +112 -0
  753. package/proto/gogoproto/gogo.proto +145 -0
  754. package/proto/google/protobuf/descriptor.proto +1218 -0
  755. package/proto/trustchain/economy/v1/params.proto +133 -0
  756. package/proto/trustchain/economy/v1/tx.proto +162 -0
  757. package/proto/trustchain/marketplace/v1/params.proto +64 -0
  758. package/proto/trustchain/marketplace/v1/product.proto +21 -0
  759. package/proto/trustchain/marketplace/v1/tx.proto +131 -0
  760. package/proto/trustchain/order/v1/params.proto +94 -0
  761. package/proto/trustchain/order/v1/tx.proto +156 -0
  762. package/proto/trustchain/serviceprovider/v1/paymentfact.proto +32 -0
  763. package/proto/trustchain/serviceprovider/v1/serviceprovider.proto +38 -0
  764. package/proto/trustchain/serviceprovider/v1/tx.proto +106 -0
  765. package/proto/trustchain/subchain/v1/params.proto +26 -0
  766. package/proto/trustchain/subchain/v1/pool.proto +53 -0
  767. package/proto/trustchain/subchain/v1/tx.proto +159 -0
  768. package/proto/trustchain/trustcoin/v1/business_scope.proto +126 -0
  769. package/proto/trustchain/trustcoin/v1/genesis.proto +33 -0
  770. package/proto/trustchain/trustcoin/v1/params.proto +86 -0
  771. package/proto/trustchain/trustcoin/v1/query.proto +95 -0
  772. package/proto/trustchain/trustcoin/v1/tx.proto +160 -0
  773. package/proto/trustchain/verification/v1/params.proto +46 -0
  774. package/proto/trustchain/verification/v1/tx.proto +126 -0
  775. package/proto/trustchain/verification/v1/verification.proto +105 -0
  776. package/relationship-chain-api.d.ts +13 -0
  777. package/relationship-chain-api.d.ts.map +1 -0
  778. package/relationship-chain-api.js +139 -0
  779. package/relationship-chain-api.js.map +1 -0
  780. package/relationship-chain.d.ts +90 -0
  781. package/relationship-chain.d.ts.map +1 -0
  782. package/relationship-chain.js +201 -0
  783. package/relationship-chain.js.map +1 -0
  784. package/routes/agent-pay.js +419 -0
  785. package/routes/agent-serviceprovider.js +183 -0
  786. package/routes/ai.d.ts +54 -0
  787. package/routes/ai.d.ts.map +1 -0
  788. package/routes/ai.js +293 -0
  789. package/routes/ai.js.map +1 -0
  790. package/routes/api-keys.d.ts +12 -0
  791. package/routes/api-keys.d.ts.map +1 -0
  792. package/routes/api-keys.js +163 -0
  793. package/routes/api-keys.js.map +1 -0
  794. package/routes/app-store.d.ts +12 -0
  795. package/routes/app-store.d.ts.map +1 -0
  796. package/routes/app-store.js +207 -0
  797. package/routes/app-store.js.map +1 -0
  798. package/routes/auth-management.d.ts +17 -0
  799. package/routes/auth-management.d.ts.map +1 -0
  800. package/routes/auth-management.js +257 -0
  801. package/routes/auth-management.js.map +1 -0
  802. package/routes/auth.d.ts +9 -0
  803. package/routes/auth.d.ts.map +1 -0
  804. package/routes/auth.js +846 -0
  805. package/routes/auth.js.map +1 -0
  806. package/routes/brand.d.ts +3 -0
  807. package/routes/brand.d.ts.map +1 -0
  808. package/routes/brand.js +109 -0
  809. package/routes/brand.js.map +1 -0
  810. package/routes/chain-registry.d.ts +11 -0
  811. package/routes/chain-registry.d.ts.map +1 -0
  812. package/routes/chain-registry.js +51 -0
  813. package/routes/chain-registry.js.map +1 -0
  814. package/routes/chain-writes-insurance.d.ts +17 -0
  815. package/routes/chain-writes-insurance.d.ts.map +1 -0
  816. package/routes/chain-writes-insurance.js +69 -0
  817. package/routes/chain-writes-insurance.js.map +1 -0
  818. package/routes/chain-writes-pledge.d.ts +34 -0
  819. package/routes/chain-writes-pledge.d.ts.map +1 -0
  820. package/routes/chain-writes-pledge.js +206 -0
  821. package/routes/chain-writes-pledge.js.map +1 -0
  822. package/routes/chain-writes-products.d.ts +66 -0
  823. package/routes/chain-writes-products.d.ts.map +1 -0
  824. package/routes/chain-writes-products.js +394 -0
  825. package/routes/chain-writes-products.js.map +1 -0
  826. package/routes/chain-writes.d.ts +78 -0
  827. package/routes/chain-writes.d.ts.map +1 -0
  828. package/routes/chain-writes.js +658 -0
  829. package/routes/chain-writes.js.map +1 -0
  830. package/routes/chain.d.ts +10 -0
  831. package/routes/chain.d.ts.map +1 -0
  832. package/routes/chain.js +45 -0
  833. package/routes/chain.js.map +1 -0
  834. package/routes/compliance.d.ts +3 -0
  835. package/routes/compliance.d.ts.map +1 -0
  836. package/routes/compliance.js +53 -0
  837. package/routes/compliance.js.map +1 -0
  838. package/routes/council.d.ts +3 -0
  839. package/routes/council.d.ts.map +1 -0
  840. package/routes/council.js +477 -0
  841. package/routes/council.js.map +1 -0
  842. package/routes/crosschain.d.ts +11 -0
  843. package/routes/crosschain.d.ts.map +1 -0
  844. package/routes/crosschain.js +39 -0
  845. package/routes/crosschain.js.map +1 -0
  846. package/routes/device.d.ts +3 -0
  847. package/routes/device.d.ts.map +1 -0
  848. package/routes/device.js +73 -0
  849. package/routes/device.js.map +1 -0
  850. package/routes/devreward.d.ts +54 -0
  851. package/routes/devreward.d.ts.map +1 -0
  852. package/routes/devreward.js +129 -0
  853. package/routes/devreward.js.map +1 -0
  854. package/routes/economy.d.ts +50 -0
  855. package/routes/economy.d.ts.map +1 -0
  856. package/routes/economy.js +273 -0
  857. package/routes/economy.js.map +1 -0
  858. package/routes/flowback.d.ts +32 -0
  859. package/routes/flowback.d.ts.map +1 -0
  860. package/routes/flowback.js +97 -0
  861. package/routes/flowback.js.map +1 -0
  862. package/routes/insurance.d.ts +10 -0
  863. package/routes/insurance.d.ts.map +1 -0
  864. package/routes/insurance.js +70 -0
  865. package/routes/insurance.js.map +1 -0
  866. package/routes/m2m-viewer.js +195 -0
  867. package/routes/m2m.d.ts +10 -0
  868. package/routes/m2m.d.ts.map +1 -0
  869. package/routes/m2m.js +31 -0
  870. package/routes/m2m.js.map +1 -0
  871. package/routes/marketplace.d.ts +15 -0
  872. package/routes/marketplace.d.ts.map +1 -0
  873. package/routes/marketplace.js +396 -0
  874. package/routes/marketplace.js.map +1 -0
  875. package/routes/node-config.d.ts +6 -0
  876. package/routes/node-config.d.ts.map +1 -0
  877. package/routes/node-config.js +500 -0
  878. package/routes/node-config.js.map +1 -0
  879. package/routes/oauth-revocation.d.ts +42 -0
  880. package/routes/oauth-revocation.d.ts.map +1 -0
  881. package/routes/oauth-revocation.js +99 -0
  882. package/routes/oauth-revocation.js.map +1 -0
  883. package/routes/oauth.d.ts +17 -0
  884. package/routes/oauth.d.ts.map +1 -0
  885. package/routes/oauth.js +700 -0
  886. package/routes/oauth.js.map +1 -0
  887. package/routes/onboard.html +352 -0
  888. package/routes/onboard.js +435 -0
  889. package/routes/order.d.ts +8 -0
  890. package/routes/order.d.ts.map +1 -0
  891. package/routes/order.js +607 -0
  892. package/routes/order.js.map +1 -0
  893. package/routes/p2p-api.d.ts +33 -0
  894. package/routes/p2p-api.d.ts.map +1 -0
  895. package/routes/p2p-api.js +274 -0
  896. package/routes/p2p-api.js.map +1 -0
  897. package/routes/p2p-message.d.ts +20 -0
  898. package/routes/p2p-message.d.ts.map +1 -0
  899. package/routes/p2p-message.js +237 -0
  900. package/routes/p2p-message.js.map +1 -0
  901. package/routes/peer.d.ts +22 -0
  902. package/routes/peer.d.ts.map +1 -0
  903. package/routes/peer.js +220 -0
  904. package/routes/peer.js.map +1 -0
  905. package/routes/plugins.d.ts +4 -0
  906. package/routes/plugins.d.ts.map +1 -0
  907. package/routes/plugins.js +138 -0
  908. package/routes/plugins.js.map +1 -0
  909. package/routes/port-manager.d.ts +6 -0
  910. package/routes/port-manager.d.ts.map +1 -0
  911. package/routes/port-manager.js +212 -0
  912. package/routes/port-manager.js.map +1 -0
  913. package/routes/relationship.d.ts +7 -0
  914. package/routes/relationship.d.ts.map +1 -0
  915. package/routes/relationship.js +314 -0
  916. package/routes/relationship.js.map +1 -0
  917. package/routes/relay.d.ts +3 -0
  918. package/routes/relay.d.ts.map +1 -0
  919. package/routes/relay.js +182 -0
  920. package/routes/relay.js.map +1 -0
  921. package/routes/reputation.d.ts +10 -0
  922. package/routes/reputation.d.ts.map +1 -0
  923. package/routes/reputation.js +141 -0
  924. package/routes/reputation.js.map +1 -0
  925. package/routes/reward.d.ts +3 -0
  926. package/routes/reward.d.ts.map +1 -0
  927. package/routes/reward.js +130 -0
  928. package/routes/reward.js.map +1 -0
  929. package/routes/security-monitoring.d.ts +12 -0
  930. package/routes/security-monitoring.d.ts.map +1 -0
  931. package/routes/security-monitoring.js +373 -0
  932. package/routes/security-monitoring.js.map +1 -0
  933. package/routes/shop.d.ts +8 -0
  934. package/routes/shop.d.ts.map +1 -0
  935. package/routes/shop.js +164 -0
  936. package/routes/shop.js.map +1 -0
  937. package/routes/social.d.ts +22 -0
  938. package/routes/social.d.ts.map +1 -0
  939. package/routes/social.js +95 -0
  940. package/routes/social.js.map +1 -0
  941. package/routes/subchain.d.ts +18 -0
  942. package/routes/subchain.d.ts.map +1 -0
  943. package/routes/subchain.js +106 -0
  944. package/routes/subchain.js.map +1 -0
  945. package/routes/trustcoin.d.ts +17 -0
  946. package/routes/trustcoin.d.ts.map +1 -0
  947. package/routes/trustcoin.js +149 -0
  948. package/routes/trustcoin.js.map +1 -0
  949. package/routes/twofa.d.ts +7 -0
  950. package/routes/twofa.d.ts.map +1 -0
  951. package/routes/twofa.js +105 -0
  952. package/routes/twofa.js.map +1 -0
  953. package/routes/verification.d.ts +8 -0
  954. package/routes/verification.d.ts.map +1 -0
  955. package/routes/verification.js +234 -0
  956. package/routes/verification.js.map +1 -0
  957. package/routes/wallet.d.ts +4 -0
  958. package/routes/wallet.d.ts.map +1 -0
  959. package/routes/wallet.js +770 -0
  960. package/routes/wallet.js.map +1 -0
  961. package/run-auth.d.ts +8 -0
  962. package/run-auth.d.ts.map +1 -0
  963. package/run-auth.js +82 -0
  964. package/run-auth.js.map +1 -0
  965. package/run-p2p-message.d.ts +8 -0
  966. package/run-p2p-message.d.ts.map +1 -0
  967. package/run-p2p-message.js +82 -0
  968. package/run-p2p-message.js.map +1 -0
  969. package/run-relationship.d.ts +12 -0
  970. package/run-relationship.d.ts.map +1 -0
  971. package/run-relationship.js +182 -0
  972. package/run-relationship.js.map +1 -0
  973. package/run-unified.d.ts +13 -0
  974. package/run-unified.d.ts.map +1 -0
  975. package/run-unified.js +1067 -0
  976. package/run-unified.js.map +1 -0
  977. package/run.d.ts +12 -0
  978. package/run.d.ts.map +1 -0
  979. package/run.js +889 -0
  980. package/run.js.map +1 -0
  981. package/search/ranking.d.ts +55 -0
  982. package/search/ranking.d.ts.map +1 -0
  983. package/search/ranking.js +67 -0
  984. package/search/ranking.js.map +1 -0
  985. package/shipping/base.d.ts +15 -0
  986. package/shipping/base.d.ts.map +1 -0
  987. package/shipping/base.js +39 -0
  988. package/shipping/base.js.map +1 -0
  989. package/shipping/index.d.ts +19 -0
  990. package/shipping/index.d.ts.map +1 -0
  991. package/shipping/index.js +72 -0
  992. package/shipping/index.js.map +1 -0
  993. package/shipping/sf-express/index.d.ts +23 -0
  994. package/shipping/sf-express/index.d.ts.map +1 -0
  995. package/shipping/sf-express/index.js +71 -0
  996. package/shipping/sf-express/index.js.map +1 -0
  997. package/shipping/template/index.d.ts +20 -0
  998. package/shipping/template/index.d.ts.map +1 -0
  999. package/shipping/template/index.js +74 -0
  1000. package/shipping/template/index.js.map +1 -0
  1001. package/shipping/types.d.ts +71 -0
  1002. package/shipping/types.d.ts.map +1 -0
  1003. package/shipping/types.js +6 -0
  1004. package/shipping/types.js.map +1 -0
  1005. package/shipping/virtual/index.d.ts +19 -0
  1006. package/shipping/virtual/index.d.ts.map +1 -0
  1007. package/shipping/virtual/index.js +54 -0
  1008. package/shipping/virtual/index.js.map +1 -0
  1009. package/shipping/yto/index.d.ts +18 -0
  1010. package/shipping/yto/index.d.ts.map +1 -0
  1011. package/shipping/yto/index.js +59 -0
  1012. package/shipping/yto/index.js.map +1 -0
  1013. package/shipping/zto/index.d.ts +18 -0
  1014. package/shipping/zto/index.d.ts.map +1 -0
  1015. package/shipping/zto/index.js +59 -0
  1016. package/shipping/zto/index.js.map +1 -0
  1017. package/skills-lock.json +11 -0
  1018. package/src/db/email-migrations.sql +31 -0
  1019. package/src/db/oauth-migrations.sql +92 -0
  1020. package/src/db/social-migrations.sql +94 -0
  1021. package/src/db/store-migrations.sql +242 -0
  1022. package/test-api-key-revoke.js +167 -0
  1023. package/test-auth-register-ratelimit.js +132 -0
  1024. package/test-auth-tv2.d.ts +2 -0
  1025. package/test-auth-tv2.d.ts.map +1 -0
  1026. package/test-auth-tv2.js +174 -0
  1027. package/test-auth-tv2.js.map +1 -0
  1028. package/test-canonsign-cross.d.ts +2 -0
  1029. package/test-canonsign-cross.d.ts.map +1 -0
  1030. package/test-canonsign-cross.js +32 -0
  1031. package/test-canonsign-cross.js.map +1 -0
  1032. package/test-chain-signer.js +127 -0
  1033. package/test-env-truthy.js +50 -0
  1034. package/test-onboard-contract.js +94 -0
  1035. package/test-ops-console-boundary.js +147 -0
  1036. package/test-oracle-glue.js +232 -0
  1037. package/test-order-create-v394.js +358 -0
  1038. package/test-order-intent.js +245 -0
  1039. package/test-order-lifecycle-v394.js +528 -0
  1040. package/test-p2p-message.d.ts +13 -0
  1041. package/test-p2p-message.d.ts.map +1 -0
  1042. package/test-p2p-message.js +106 -0
  1043. package/test-p2p-message.js.map +1 -0
  1044. package/test-relationship-chain.d.ts +13 -0
  1045. package/test-relationship-chain.d.ts.map +1 -0
  1046. package/test-relationship-chain.js +103 -0
  1047. package/test-relationship-chain.js.map +1 -0
  1048. package/test-runtime-data-path.js +217 -0
  1049. package/test-seller-identity.js +74 -0
  1050. package/test-signing-paths.js +104 -0
  1051. package/test-token-v2.d.ts +2 -0
  1052. package/test-token-v2.d.ts.map +1 -0
  1053. package/test-token-v2.js +172 -0
  1054. package/test-token-v2.js.map +1 -0
  1055. package/test-wallet-auth-nonce.d.ts +12 -0
  1056. package/test-wallet-auth-nonce.d.ts.map +1 -0
  1057. package/test-wallet-auth-nonce.js +126 -0
  1058. package/test-wallet-auth-nonce.js.map +1 -0
  1059. package/test-wallet-submatch.d.ts +13 -0
  1060. package/test-wallet-submatch.d.ts.map +1 -0
  1061. package/test-wallet-submatch.js +86 -0
  1062. package/test-wallet-submatch.js.map +1 -0
  1063. package/tls/self-signed.d.ts +12 -0
  1064. package/tls/self-signed.d.ts.map +1 -0
  1065. package/tls/self-signed.js +63 -0
  1066. package/tls/self-signed.js.map +1 -0
  1067. package/tools/brand.d.ts +11 -0
  1068. package/tools/brand.d.ts.map +1 -0
  1069. package/tools/brand.js +75 -0
  1070. package/tools/brand.js.map +1 -0
  1071. package/tools/chainregistry.d.ts +18 -0
  1072. package/tools/chainregistry.d.ts.map +1 -0
  1073. package/tools/chainregistry.js +175 -0
  1074. package/tools/chainregistry.js.map +1 -0
  1075. package/tools/compliance.d.ts +14 -0
  1076. package/tools/compliance.d.ts.map +1 -0
  1077. package/tools/compliance.js +45 -0
  1078. package/tools/compliance.js.map +1 -0
  1079. package/tools/council.d.ts +17 -0
  1080. package/tools/council.d.ts.map +1 -0
  1081. package/tools/council.js +75 -0
  1082. package/tools/council.js.map +1 -0
  1083. package/tools/device.d.ts +13 -0
  1084. package/tools/device.d.ts.map +1 -0
  1085. package/tools/device.js +45 -0
  1086. package/tools/device.js.map +1 -0
  1087. package/tools/devreward.d.ts +15 -0
  1088. package/tools/devreward.d.ts.map +1 -0
  1089. package/tools/devreward.js +190 -0
  1090. package/tools/devreward.js.map +1 -0
  1091. package/tools/economy.d.ts +14 -0
  1092. package/tools/economy.d.ts.map +1 -0
  1093. package/tools/economy.js +172 -0
  1094. package/tools/economy.js.map +1 -0
  1095. package/tools/flowback.d.ts +14 -0
  1096. package/tools/flowback.d.ts.map +1 -0
  1097. package/tools/flowback.js +146 -0
  1098. package/tools/flowback.js.map +1 -0
  1099. package/tools/insurance.d.ts +13 -0
  1100. package/tools/insurance.d.ts.map +1 -0
  1101. package/tools/insurance.js +45 -0
  1102. package/tools/insurance.js.map +1 -0
  1103. package/tools/marketplace.d.ts +12 -0
  1104. package/tools/marketplace.d.ts.map +1 -0
  1105. package/tools/marketplace.js +124 -0
  1106. package/tools/marketplace.js.map +1 -0
  1107. package/tools/order.d.ts +12 -0
  1108. package/tools/order.d.ts.map +1 -0
  1109. package/tools/order.js +94 -0
  1110. package/tools/order.js.map +1 -0
  1111. package/tools/recovery.d.ts +14 -0
  1112. package/tools/recovery.d.ts.map +1 -0
  1113. package/tools/recovery.js +158 -0
  1114. package/tools/recovery.js.map +1 -0
  1115. package/tools/relay.d.ts +15 -0
  1116. package/tools/relay.d.ts.map +1 -0
  1117. package/tools/relay.js +152 -0
  1118. package/tools/relay.js.map +1 -0
  1119. package/tools/reputation.d.ts +20 -0
  1120. package/tools/reputation.d.ts.map +1 -0
  1121. package/tools/reputation.js +50 -0
  1122. package/tools/reputation.js.map +1 -0
  1123. package/tools/reputation_seller_credit.d.ts +16 -0
  1124. package/tools/reputation_seller_credit.d.ts.map +1 -0
  1125. package/tools/reputation_seller_credit.js +106 -0
  1126. package/tools/reputation_seller_credit.js.map +1 -0
  1127. package/tools/reward.d.ts +14 -0
  1128. package/tools/reward.d.ts.map +1 -0
  1129. package/tools/reward.js +76 -0
  1130. package/tools/reward.js.map +1 -0
  1131. package/tools/shop.d.ts +14 -0
  1132. package/tools/shop.d.ts.map +1 -0
  1133. package/tools/shop.js +95 -0
  1134. package/tools/shop.js.map +1 -0
  1135. package/tools/verification.d.ts +12 -0
  1136. package/tools/verification.d.ts.map +1 -0
  1137. package/tools/verification.js +89 -0
  1138. package/tools/verification.js.map +1 -0
  1139. package/types/store.d.ts +255 -0
  1140. package/types/store.d.ts.map +1 -0
  1141. package/types/store.js +19 -0
  1142. package/types/store.js.map +1 -0
  1143. package/utils/aes-gcm.d.ts +63 -0
  1144. package/utils/aes-gcm.d.ts.map +1 -0
  1145. package/utils/aes-gcm.js +179 -0
  1146. package/utils/aes-gcm.js.map +1 -0
  1147. package/utils/api-response.d.ts +51 -0
  1148. package/utils/api-response.d.ts.map +1 -0
  1149. package/utils/api-response.js +65 -0
  1150. package/utils/api-response.js.map +1 -0
  1151. package/utils/base32.d.ts +5 -0
  1152. package/utils/base32.d.ts.map +1 -0
  1153. package/utils/base32.js +20 -0
  1154. package/utils/base32.js.map +1 -0
  1155. package/utils/crypto.d.ts +77 -0
  1156. package/utils/crypto.d.ts.map +1 -0
  1157. package/utils/crypto.js +164 -0
  1158. package/utils/crypto.js.map +1 -0
  1159. package/utils/encryption.d.ts +81 -0
  1160. package/utils/encryption.d.ts.map +1 -0
  1161. package/utils/encryption.js +247 -0
  1162. package/utils/encryption.js.map +1 -0
  1163. package/utils/env.js +20 -0
  1164. package/utils/jwt.d.ts +110 -0
  1165. package/utils/jwt.d.ts.map +1 -0
  1166. package/utils/jwt.js +275 -0
  1167. package/utils/jwt.js.map +1 -0
  1168. package/utils/qrcode-reader.d.ts +22 -0
  1169. package/utils/qrcode-reader.d.ts.map +1 -0
  1170. package/utils/qrcode-reader.js +90 -0
  1171. package/utils/qrcode-reader.js.map +1 -0
  1172. package/utils/qrcode.d.ts +26 -0
  1173. package/utils/qrcode.d.ts.map +1 -0
  1174. package/utils/qrcode.js +92 -0
  1175. package/utils/qrcode.js.map +1 -0
  1176. package/utils/totp.d.ts +3 -0
  1177. package/utils/totp.d.ts.map +1 -0
  1178. package/utils/totp.js +58 -0
  1179. package/utils/totp.js.map +1 -0
  1180. package/utils/two-factor-auth.d.ts +16 -0
  1181. package/utils/two-factor-auth.d.ts.map +1 -0
  1182. package/utils/two-factor-auth.js +150 -0
  1183. package/utils/two-factor-auth.js.map +1 -0
  1184. package/verifyer/hsm.d.ts +70 -0
  1185. package/verifyer/hsm.d.ts.map +1 -0
  1186. package/verifyer/hsm.js +482 -0
  1187. package/verifyer/hsm.js.map +1 -0
  1188. package/verifyer/index.d.ts +81 -0
  1189. package/verifyer/index.d.ts.map +1 -0
  1190. package/verifyer/index.js +372 -0
  1191. package/verifyer/index.js.map +1 -0
  1192. package/ws/peer-monitor-broadcaster.d.ts +24 -0
  1193. package/ws/peer-monitor-broadcaster.d.ts.map +1 -0
  1194. package/ws/peer-monitor-broadcaster.js +56 -0
  1195. package/ws/peer-monitor-broadcaster.js.map +1 -0
@@ -0,0 +1,979 @@
1
+ "use strict";
2
+ /**
3
+ * OAuth 2.0 Plugin - OAuth 授权插件
4
+ *
5
+ * 功能:
6
+ * 1. 授权码流程
7
+ * 2. 令牌端点
8
+ * 3. 用户信息端点
9
+ * 4. 权限验证
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.OAuthPlugin = void 0;
49
+ exports.computePkceChallenge = computePkceChallenge;
50
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
51
+ const events_1 = require("events");
52
+ const crypto = __importStar(require("crypto"));
53
+ /**
54
+ * PKCE code_challenge 计算(RFC 7636)
55
+ * @param verifier code_verifier(43-128 字符 [A-Z a-z 0-9 - . _ ~])
56
+ * @param method 'S256' 或 'plain'(默认 S256,SHA256 + base64url)
57
+ */
58
+ function computePkceChallenge(verifier, method = 'S256') {
59
+ if (method === 'plain') {
60
+ return verifier;
61
+ }
62
+ return crypto.createHash('sha256').update(verifier).digest('base64url');
63
+ }
64
+ /**
65
+ * OAuthPlugin - OAuth 2.0 插件
66
+ */
67
+ class OAuthPlugin extends events_1.EventEmitter {
68
+ db;
69
+ config;
70
+ initialized = false;
71
+ constructor(config = {}) {
72
+ super();
73
+ this.config = {
74
+ authorizationCodeExpiry: 600, // 10 分钟
75
+ accessTokenExpiry: 3600, // 1 小时
76
+ ...config
77
+ };
78
+ }
79
+ /**
80
+ * 初始化插件
81
+ */
82
+ async init(dbPath = './data/oauth.db') {
83
+ if (this.initialized)
84
+ return;
85
+ this.db = new better_sqlite3_1.default(dbPath);
86
+ this.createTables();
87
+ this.initialized = true;
88
+ console.log('[OAuthPlugin] Initialized');
89
+ }
90
+ /**
91
+ * 创建数据库表
92
+ */
93
+ createTables() {
94
+ // OAuth 应用表
95
+ this.db.exec(`
96
+ CREATE TABLE IF NOT EXISTS oauth_apps (
97
+ id TEXT PRIMARY KEY,
98
+ name TEXT NOT NULL,
99
+ description TEXT,
100
+ client_id TEXT UNIQUE NOT NULL,
101
+ client_secret_hash TEXT NOT NULL,
102
+ redirect_uris TEXT NOT NULL,
103
+ scopes TEXT NOT NULL,
104
+ owner_address TEXT NOT NULL,
105
+ created_at INTEGER NOT NULL,
106
+ updated_at INTEGER NOT NULL,
107
+ is_active BOOLEAN DEFAULT true,
108
+ require_pkce BOOLEAN DEFAULT false
109
+ );
110
+
111
+ CREATE INDEX IF NOT EXISTS idx_oauth_apps_client_id ON oauth_apps(client_id);
112
+ CREATE INDEX IF NOT EXISTS idx_oauth_apps_owner ON oauth_apps(owner_address);
113
+ `);
114
+ // 迁移(幂等):为已存在的旧 oauth_apps 表添加 require_pkce 列
115
+ try {
116
+ this.db.exec('ALTER TABLE oauth_apps ADD COLUMN require_pkce BOOLEAN DEFAULT false');
117
+ }
118
+ catch (_) { /* 列已存在,忽略 */ }
119
+ // 授权码表
120
+ this.db.exec(`
121
+ CREATE TABLE IF NOT EXISTS authorization_codes (
122
+ id TEXT PRIMARY KEY,
123
+ code TEXT UNIQUE NOT NULL,
124
+ client_id TEXT NOT NULL,
125
+ user_id TEXT NOT NULL,
126
+ user_address TEXT NOT NULL,
127
+ redirect_uri TEXT NOT NULL,
128
+ scopes TEXT NOT NULL,
129
+ expires_at INTEGER NOT NULL,
130
+ used BOOLEAN DEFAULT false,
131
+ created_at INTEGER NOT NULL,
132
+ code_challenge TEXT,
133
+ code_challenge_method TEXT
134
+ );
135
+
136
+ CREATE INDEX IF NOT EXISTS idx_authorization_codes_code ON authorization_codes(code);
137
+ CREATE INDEX IF NOT EXISTS idx_authorization_codes_user ON authorization_codes(user_id);
138
+ `);
139
+ // 迁移(幂等):为已存在的旧 authorization_codes 表添加 PKCE 列
140
+ try {
141
+ this.db.exec('ALTER TABLE authorization_codes ADD COLUMN code_challenge TEXT');
142
+ }
143
+ catch (_) { /* 忽略 */ }
144
+ try {
145
+ this.db.exec('ALTER TABLE authorization_codes ADD COLUMN code_challenge_method TEXT');
146
+ }
147
+ catch (_) { /* 忽略 */ }
148
+ // 访问令牌表
149
+ this.db.exec(`
150
+ CREATE TABLE IF NOT EXISTS access_tokens (
151
+ id TEXT PRIMARY KEY,
152
+ access_token TEXT UNIQUE NOT NULL,
153
+ refresh_token TEXT UNIQUE NOT NULL,
154
+ client_id TEXT NOT NULL,
155
+ user_id TEXT NOT NULL,
156
+ user_address TEXT NOT NULL,
157
+ scopes TEXT NOT NULL,
158
+ expires_at INTEGER NOT NULL,
159
+ created_at INTEGER NOT NULL,
160
+ revoked BOOLEAN DEFAULT false
161
+ );
162
+
163
+ CREATE INDEX IF NOT EXISTS idx_access_tokens_access ON access_tokens(access_token);
164
+ CREATE INDEX IF NOT EXISTS idx_access_tokens_refresh ON access_tokens(refresh_token);
165
+ CREATE INDEX IF NOT EXISTS idx_access_tokens_user ON access_tokens(user_id);
166
+
167
+ -- R2-3a (kimi 设计稿 2026-08-12): grant 落库 — tv2 refresh 需要 grant_sig 重建新 tv2 (S4 只存 access hash, grant_sig 是公钥签名可落库)
168
+ CREATE TABLE IF NOT EXISTS oauth_grants (
169
+ grant_id TEXT PRIMARY KEY, -- sha256(grant canonical) 前 32 hex
170
+ sub TEXT NOT NULL,
171
+ client_id TEXT NOT NULL,
172
+ iss TEXT NOT NULL,
173
+ scopes TEXT NOT NULL, -- JSON array
174
+ grant_sig TEXT NOT NULL, -- 用户钱包签名 (公钥公开, 不违 S4)
175
+ grant_exp INTEGER NOT NULL, -- ms, 授权总寿命
176
+ nonce TEXT NOT NULL, -- grant nonce (issueTokenV2 需要完整 TokenV2Grant)
177
+ user_pubkey TEXT NOT NULL, -- base64 33B 压缩公钥 (issueTokenV2 需要)
178
+ created_at INTEGER NOT NULL
179
+ );
180
+ CREATE INDEX IF NOT EXISTS idx_oauth_grants_sub_client ON oauth_grants(sub, client_id);
181
+ `);
182
+ // 用户授权记录表
183
+ this.db.exec(`
184
+ CREATE TABLE IF NOT EXISTS oauth_authorizations (
185
+ id TEXT PRIMARY KEY,
186
+ app_id TEXT NOT NULL,
187
+ user_id TEXT NOT NULL,
188
+ user_address TEXT NOT NULL,
189
+ client_id TEXT NOT NULL,
190
+ scopes TEXT NOT NULL,
191
+ created_at INTEGER NOT NULL,
192
+ updated_at INTEGER NOT NULL,
193
+ last_used_at INTEGER,
194
+ is_active BOOLEAN DEFAULT true
195
+ );
196
+
197
+ CREATE INDEX IF NOT EXISTS idx_oauth_auth_user ON oauth_authorizations(user_address, is_active);
198
+ CREATE INDEX IF NOT EXISTS idx_oauth_auth_app ON oauth_authorizations(app_id);
199
+ CREATE INDEX IF NOT EXISTS idx_oauth_auth_client ON oauth_authorizations(client_id, user_address);
200
+ `);
201
+ // Phase 2 迁移:app_type + 授权有效期 + 访问日志(幂等 ALTER TABLE)
202
+ try {
203
+ this.db.exec('ALTER TABLE oauth_apps ADD COLUMN app_type TEXT DEFAULT \'human\'');
204
+ }
205
+ catch { /* exists */ }
206
+ try {
207
+ this.db.exec('ALTER TABLE oauth_authorizations ADD COLUMN expires_at INTEGER');
208
+ }
209
+ catch { /* exists */ }
210
+ try {
211
+ this.db.exec('ALTER TABLE authorization_codes ADD COLUMN auth_expires_at INTEGER');
212
+ }
213
+ catch { /* exists */ }
214
+ // Issue #1 (Stage 3.2): revoked_scopes 审计列 (JSON array of {scope, revoked_at})
215
+ try {
216
+ this.db.exec('ALTER TABLE oauth_authorizations ADD COLUMN revoked_scopes TEXT DEFAULT \'[]\'');
217
+ }
218
+ catch { /* exists */ }
219
+ // 访问日志表(PRD §27.9)
220
+ this.db.exec(`
221
+ CREATE TABLE IF NOT EXISTS oauth_access_logs (
222
+ id TEXT PRIMARY KEY,
223
+ app_name TEXT,
224
+ client_id TEXT,
225
+ user_id TEXT NOT NULL,
226
+ user_address TEXT NOT NULL,
227
+ endpoint TEXT NOT NULL,
228
+ method TEXT NOT NULL,
229
+ scope_used TEXT,
230
+ response_status INTEGER,
231
+ created_at INTEGER NOT NULL
232
+ );
233
+ CREATE INDEX IF NOT EXISTS idx_oauth_logs_user ON oauth_access_logs(user_address, created_at DESC);
234
+ CREATE INDEX IF NOT EXISTS idx_oauth_logs_created ON oauth_access_logs(created_at);
235
+ `);
236
+ // 清理 90 天以上旧日志
237
+ this.db.prepare('DELETE FROM oauth_access_logs WHERE created_at < ?').run(Date.now() - 90 * 24 * 3600 * 1000);
238
+ }
239
+ /**
240
+ * 创建 OAuth 应用
241
+ */
242
+ async createApp(name, description, redirectUris, scopes, ownerAddress, appType = 'human', requirePkce = false) {
243
+ const id = crypto.randomUUID();
244
+ const clientId = crypto.randomBytes(16).toString('hex');
245
+ // PKCE 公开客户端:不生成 client_secret(留空串),仍存一个占位 hash 满足 NOT NULL 约束
246
+ const clientSecret = requirePkce ? '' : crypto.randomBytes(32).toString('hex');
247
+ const clientSecretHash = requirePkce ? '' : crypto.createHash('sha256').update(clientSecret).digest('hex');
248
+ const now = Date.now();
249
+ const stmt = this.db.prepare(`
250
+ INSERT INTO oauth_apps (
251
+ id, name, description, client_id, client_secret_hash,
252
+ redirect_uris, scopes, owner_address, app_type, created_at, updated_at, is_active, require_pkce
253
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, true, ?)
254
+ `);
255
+ stmt.run(id, name, description, clientId, clientSecretHash, JSON.stringify(redirectUris), JSON.stringify(scopes), ownerAddress, appType, now, now, requirePkce ? 1 : 0);
256
+ const app = {
257
+ id,
258
+ name,
259
+ description,
260
+ clientId,
261
+ clientSecretHash: clientSecretHash || '',
262
+ redirectUris,
263
+ scopes,
264
+ ownerAddress,
265
+ appType,
266
+ createdAt: now,
267
+ updatedAt: now,
268
+ isActive: true
269
+ };
270
+ this.emit('app:created', app);
271
+ // P3-6 修复:返回类型用 CreatedOAuthApp(明文 clientSecret 单独字段),不再用 `as any` 把 secret 塞进 clientSecretHash
272
+ const createdApp = { ...app, clientSecret };
273
+ return createdApp;
274
+ }
275
+ /**
276
+ * 验证客户端
277
+ */
278
+ async validateClient(clientId, clientSecret) {
279
+ const stmt = this.db.prepare(`
280
+ SELECT * FROM oauth_apps WHERE client_id = ? AND is_active = true
281
+ `);
282
+ const row = stmt.get(clientId);
283
+ if (!row) {
284
+ return null;
285
+ }
286
+ const clientSecretHash = crypto.createHash('sha256').update(clientSecret).digest('hex');
287
+ if (clientSecretHash !== row.client_secret_hash) {
288
+ return null;
289
+ }
290
+ return {
291
+ id: row.id,
292
+ name: row.name,
293
+ description: row.description,
294
+ clientId: row.client_id,
295
+ clientSecretHash: row.client_secret_hash,
296
+ redirectUris: JSON.parse(row.redirect_uris),
297
+ scopes: JSON.parse(row.scopes),
298
+ ownerAddress: row.owner_address,
299
+ appType: row.app_type || 'human',
300
+ createdAt: row.created_at,
301
+ updatedAt: row.updated_at,
302
+ isActive: row.is_active
303
+ };
304
+ }
305
+ /**
306
+ * 创建授权码
307
+ */
308
+ async createAuthorizationCode(clientId, userId, userAddress, redirectUri, scopes, authExpiresAt, codeChallenge, codeChallengeMethod) {
309
+ // 验证 redirect_uri
310
+ const app = await this.getApp(clientId);
311
+ if (!app) {
312
+ throw new Error('Invalid client_id');
313
+ }
314
+ if (!app.redirectUris.includes(redirectUri)) {
315
+ throw new Error('Invalid redirect_uri');
316
+ }
317
+ // 验证 scopes
318
+ const invalidScopes = scopes.filter(s => !app.scopes.includes(s));
319
+ if (invalidScopes.length > 0) {
320
+ throw new Error(`Invalid scopes: ${invalidScopes.join(', ')}`);
321
+ }
322
+ // PKCE 校验:PKCE App 必须传 code_challenge(S256),method 必须是 S256 或 plain
323
+ if (app.requirePkce && !codeChallenge) {
324
+ throw new Error('PKCE required: missing code_challenge');
325
+ }
326
+ if (codeChallenge && codeChallengeMethod && !['S256', 'plain'].includes(codeChallengeMethod)) {
327
+ throw new Error('Invalid code_challenge_method (only S256 or plain)');
328
+ }
329
+ const code = crypto.randomBytes(32).toString('hex');
330
+ const now = Date.now();
331
+ const expiresAt = now + (this.config.authorizationCodeExpiry * 1000);
332
+ const stmt = this.db.prepare(`
333
+ INSERT INTO authorization_codes (
334
+ id, code, client_id, user_id, user_address, redirect_uri, scopes, expires_at, used, created_at, auth_expires_at, code_challenge, code_challenge_method
335
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, false, ?, ?, ?, ?)
336
+ `);
337
+ stmt.run(crypto.randomUUID(), code, clientId, userId, userAddress, redirectUri, JSON.stringify(scopes), expiresAt, now, authExpiresAt ?? null, codeChallenge ?? null, codeChallengeMethod ?? null);
338
+ this.emit('code:created', { code, clientId, userId });
339
+ return code;
340
+ }
341
+ /**
342
+ * 使用授权码换取访问令牌
343
+ */
344
+ async exchangeCodeForToken(code, clientId, clientSecret, redirectUri, codeVerifier, tokenV2Grant // R2-1: 用户 grant 签名(授权时钱包签)
345
+ ) {
346
+ // 查询授权码(必须在客户端校验前,因为 PKCE App 没有 client_secret)
347
+ const codeStmt = this.db.prepare(`
348
+ SELECT * FROM authorization_codes
349
+ WHERE code = ? AND client_id = ? AND redirect_uri = ? AND used = false AND expires_at > ?
350
+ `);
351
+ const row = codeStmt.get(code, clientId, redirectUri, Date.now());
352
+ if (!row) {
353
+ throw new Error('Invalid or expired authorization code');
354
+ }
355
+ // 查询 App(必须在客户端校验前,因为 PKCE App client_secret 为空)
356
+ const app = this.db.prepare('SELECT * FROM oauth_apps WHERE client_id = ? AND is_active = true').get(clientId);
357
+ if (!app) {
358
+ throw new Error('Invalid client_id');
359
+ }
360
+ // 客户端校验:PKCE App(client_secret_hash 为空)只校验 code_verifier;
361
+ // 非 PKCE App 校验 client_secret。
362
+ if (app.require_pkce) {
363
+ if (!codeVerifier) {
364
+ throw new Error('PKCE required: missing code_verifier');
365
+ }
366
+ if (!row.code_challenge) {
367
+ throw new Error('PKCE mismatch: code_challenge not registered for this code');
368
+ }
369
+ const method = row.code_challenge_method || 'plain';
370
+ const challenge = computePkceChallenge(codeVerifier, method);
371
+ if (challenge !== row.code_challenge) {
372
+ throw new Error('PKCE verification failed: code_verifier mismatch');
373
+ }
374
+ }
375
+ else {
376
+ // 非 PKCE App:要求传 client_secret
377
+ const clientSecretHash = crypto.createHash('sha256').update(clientSecret).digest('hex');
378
+ if (!app.client_secret_hash || clientSecretHash !== app.client_secret_hash) {
379
+ throw new Error('Invalid client credentials');
380
+ }
381
+ }
382
+ // 标记授权码已使用
383
+ this.db.prepare(`
384
+ UPDATE authorization_codes SET used = true WHERE id = ?
385
+ `).run(row.id);
386
+ // 生成访问令牌
387
+ const refreshToken = crypto.randomBytes(32).toString('hex');
388
+ const now = Date.now();
389
+ const scopes = JSON.parse(row.scopes);
390
+ // 有效期:用户选的 auth_expires_at(7d/30d/permanent),否则默认 1h
391
+ let tokenExpiresAt;
392
+ if (row.auth_expires_at !== null && row.auth_expires_at !== undefined) {
393
+ tokenExpiresAt = row.auth_expires_at; // 用户选的有效期(绝对时间戳)
394
+ }
395
+ else {
396
+ tokenExpiresAt = now + (this.config.accessTokenExpiry * 1000); // 默认 1h
397
+ }
398
+ // R2-1: 配置了 tokenV2 且客户端带来用户 grant 签名 → 发 tv2 结构化令牌
399
+ let accessToken;
400
+ if (this.config.tokenV2 && tokenV2Grant) {
401
+ const { issueTokenV2, verifyGrantSig, tokenV2Hash } = await Promise.resolve().then(() => __importStar(require('../oauth/token-v2')));
402
+ const g = tokenV2Grant.grant;
403
+ // grant 与授权码记录的一致性断言(防张冠李戴)
404
+ const userAddress = row.user_address || row.user_id;
405
+ if (g.sub !== userAddress)
406
+ throw new Error('grant.sub 与授权用户不一致');
407
+ if (g.client_id !== clientId)
408
+ throw new Error('grant.client_id 与请求不一致');
409
+ if (g.iss !== this.config.tokenV2.issuerNodeId)
410
+ throw new Error('grant.iss 不是本节点');
411
+ if (JSON.stringify([...g.scopes].sort()) !== JSON.stringify([...scopes].sort())) {
412
+ throw new Error('grant.scopes 与授权范围不一致');
413
+ }
414
+ if (!(await verifyGrantSig(g, tokenV2Grant.grant_sig))) {
415
+ throw new Error('grant_sig 验签失败');
416
+ }
417
+ const issued = await issueTokenV2(g, tokenV2Grant.grant_sig, this.config.tokenV2.issuerPrivkey, {
418
+ requestedExp: tokenExpiresAt,
419
+ });
420
+ accessToken = issued.token;
421
+ tokenExpiresAt = issued.payload.exp; // 可能被 24h 上限钳短
422
+ // S4: v2 token 库里只存哈希('tv2h:' 前缀),明文不落盘
423
+ this.db.prepare(`
424
+ INSERT INTO access_tokens (
425
+ id, access_token, refresh_token, client_id, user_id, user_address, scopes, expires_at, created_at, revoked
426
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, false)
427
+ `).run(crypto.randomUUID(), 'tv2h:' + tokenV2Hash(accessToken), this.refreshTokenHash(refreshToken), // R2-3 阻断1: 落库存 sha256, 明文不落盘
428
+ clientId, row.user_id, userAddress, JSON.stringify(scopes), tokenExpiresAt, now);
429
+ // R2-3a: grant 落库 (tv2 refresh 需要 grant_sig 重建新 tv2). grant_id = sha256(canonical grant) 前 32 hex
430
+ try {
431
+ const { canonicalize } = await Promise.resolve().then(() => __importStar(require('../p2p/signing')));
432
+ const grantJson = canonicalize(g);
433
+ const grantId = crypto.createHash('sha256').update(grantJson).digest('hex').slice(0, 32);
434
+ this.db.prepare(`
435
+ INSERT OR REPLACE INTO oauth_grants (
436
+ grant_id, sub, client_id, iss, scopes, grant_sig, grant_exp, nonce, user_pubkey, created_at
437
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
438
+ `).run(grantId, g.sub, g.client_id, g.iss, JSON.stringify(g.scopes), tokenV2Grant.grant_sig, g.grant_exp || (tokenExpiresAt + 7 * 86400_000), g.nonce, g.user_pubkey, now);
439
+ }
440
+ catch (e) {
441
+ console.warn('[OAuthPlugin] grant 落库失败 (refresh 将受限):', e?.message ?? e);
442
+ }
443
+ }
444
+ else {
445
+ accessToken = crypto.randomBytes(32).toString('hex');
446
+ this.db.prepare(`
447
+ INSERT INTO access_tokens (
448
+ id, access_token, refresh_token, client_id, user_id, user_address, scopes, expires_at, created_at, revoked
449
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, false)
450
+ `).run(crypto.randomUUID(), accessToken, this.refreshTokenHash(refreshToken), // R2-3 阻断1: 落库存 sha256, 明文不落盘
451
+ clientId, row.user_id, row.user_address || row.user_id, // fallback
452
+ JSON.stringify(scopes), tokenExpiresAt, now);
453
+ }
454
+ // 创建或更新授权记录
455
+ try {
456
+ const appRow = this.db.prepare('SELECT id FROM oauth_apps WHERE client_id = ?').get(clientId);
457
+ if (appRow) {
458
+ await this.upsertAuthorization(appRow.id, row.user_id, row.user_address || row.user_id, clientId, scopes, row.auth_expires_at ?? null);
459
+ }
460
+ }
461
+ catch (e) {
462
+ console.error('[OAuthPlugin] Failed to create authorization record:', e);
463
+ }
464
+ this.emit('token:created', { accessToken, clientId, userId: row.user_id });
465
+ return {
466
+ accessToken,
467
+ refreshToken,
468
+ expiresIn: Math.max(0, Math.floor((tokenExpiresAt - now) / 1000)),
469
+ scopes
470
+ };
471
+ }
472
+ /**
473
+ * 验证访问令牌
474
+ */
475
+ async validateAccessToken(accessToken) {
476
+ const stmt = this.db.prepare(`
477
+ SELECT * FROM access_tokens
478
+ WHERE access_token = ? AND revoked = false AND expires_at > ?
479
+ `);
480
+ const row = stmt.get(accessToken, Date.now());
481
+ if (!row) {
482
+ return null;
483
+ }
484
+ return {
485
+ userId: row.user_id,
486
+ clientId: row.client_id,
487
+ scopes: JSON.parse(row.scopes)
488
+ };
489
+ }
490
+ /**
491
+ * S4 同款 (tv2h 前缀镜像): refresh_token 库存 sha256 哈希, 明文不落盘 (R2-3 阻断1 修复)。
492
+ * 返回 'rth:' 前缀哈希 — 自我描述且与 'tv2h:' access hash 区分, 避免明文/哈希歧义。
493
+ */
494
+ refreshTokenHash(rt) {
495
+ return 'rth:' + crypto.createHash('sha256').update(rt, 'utf8').digest('hex');
496
+ }
497
+ /**
498
+ * 刷新访问令牌
499
+ */
500
+ async refreshAccessToken(refreshToken) {
501
+ // R2-3 阻断1: rt 库存 sha256 ('rth:' 前缀), 查询同步哈希. 兼容 S4 改造前的明文遗留行 (迁移期).
502
+ let row = this.db.prepare('SELECT * FROM access_tokens WHERE refresh_token = ?')
503
+ .get(this.refreshTokenHash(refreshToken));
504
+ if (!row) {
505
+ const legacy = this.db.prepare('SELECT * FROM access_tokens WHERE refresh_token = ?')
506
+ .get(refreshToken);
507
+ if (legacy) {
508
+ console.warn('[OAuthPlugin] 命中明文 refresh_token 遗留行 (S4 迁移, 建议重签):', legacy.id);
509
+ row = legacy;
510
+ }
511
+ }
512
+ if (!row) {
513
+ throw new Error('Invalid refresh token'); // 非签发方 → /token 端点转 refresh-via-issuer
514
+ }
515
+ // R2-3 阻断2: rt 重放 (row 已 revoked = 已被一次性轮换用掉/撤销) = 泄漏信号
516
+ // → revoke-all(sub, client_id) + 广播 (宁可误杀, 不给重放窗口; kimi #15324 修法)。
517
+ // 注意: 这里不抛 'Invalid refresh token' — 那条会让端点误判为非签发方转 refresh-via-issuer,
518
+ // 必须用独立错误码, 且撤销动作不能因异常丢失。
519
+ if (row.revoked) {
520
+ const sub = row.user_address || row.user_id;
521
+ try {
522
+ if (this.config.onRefreshTokenReplayed) {
523
+ await this.config.onRefreshTokenReplayed({ sub, client_id: row.client_id });
524
+ }
525
+ }
526
+ catch (e) {
527
+ console.warn('[OAuthPlugin] refresh 重放 revoke-all 回调失败:', e?.message ?? e);
528
+ }
529
+ throw new Error('refresh-token-replayed');
530
+ }
531
+ // R2-3a (kimi 设计稿 2026-08-12): tv2 refresh — 一次性轮换 + grant 校验 + 发新 tv2.
532
+ // 非签发方: access_tokens 无此 rt 行 → 上面 throw Invalid refresh token (由 /token 端点转 refresh-via-issuer).
533
+ // 签发方: 本表有行 → 从 oauth_grants 重建 grant → 校验 → 轮换 rt → 发新 tv2.
534
+ if (typeof row.access_token === 'string' && row.access_token.startsWith('tv2h:')) {
535
+ return await this.refreshTv2Token(row, refreshToken);
536
+ }
537
+ // ★ 修复(P1-1):查询 oauth_authorizations 的当前 scopes,避免换发已撤销 scope 的新 token
538
+ // 用户通过 revokeScope() 撤销某个 scope 后,旧 refresh_token 若直接复制旧 scopes 换新 token,
539
+ // 会绕过撤销(数据主权核心漏洞)。
540
+ const auth = this.db.prepare(`
541
+ SELECT scopes FROM oauth_authorizations
542
+ WHERE client_id = ? AND user_address = ? AND is_active = 1
543
+ `).get(row.client_id, row.user_address || row.user_id);
544
+ let currentScopes;
545
+ try {
546
+ currentScopes = auth ? JSON.parse(auth.scopes) : JSON.parse(row.scopes);
547
+ }
548
+ catch {
549
+ currentScopes = JSON.parse(row.scopes);
550
+ }
551
+ // 旧 token scopes 与当前 auth scopes 取交集
552
+ const oldScopes = JSON.parse(row.scopes);
553
+ const newScopes = oldScopes.filter((s) => currentScopes.includes(s));
554
+ if (newScopes.length === 0) {
555
+ // 所有 scope 都被撤销了 → 撤销此 refresh_token 链,拒绝刷新
556
+ this.db.prepare('UPDATE access_tokens SET revoked = 1 WHERE id = ?').run(row.id);
557
+ throw new Error('All scopes have been revoked');
558
+ }
559
+ // 撤销旧令牌
560
+ this.db.prepare(`
561
+ UPDATE access_tokens SET revoked = true WHERE id = ?
562
+ `).run(row.id);
563
+ // 生成新令牌(用交集 scopes)
564
+ const accessToken = crypto.randomBytes(32).toString('hex');
565
+ const newRefreshToken = crypto.randomBytes(32).toString('hex');
566
+ const now = Date.now();
567
+ const expiresAt = now + (this.config.accessTokenExpiry * 1000);
568
+ this.db.prepare(`
569
+ INSERT INTO access_tokens (
570
+ id, access_token, refresh_token, client_id, user_id, user_address, scopes, expires_at, created_at, revoked
571
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
572
+ `).run(crypto.randomUUID(), accessToken, this.refreshTokenHash(newRefreshToken), // R2-3 阻断1: 落库存 sha256, 明文不落盘
573
+ row.client_id, row.user_id, row.user_address || row.user_id, JSON.stringify(newScopes), expiresAt, now);
574
+ return {
575
+ accessToken,
576
+ refreshToken: newRefreshToken,
577
+ expiresIn: this.config.accessTokenExpiry,
578
+ scopes: newScopes
579
+ };
580
+ }
581
+ /**
582
+ * R2-3a tv2 refresh (签发方): 一次性轮换 + grant 校验 + 发新 tv2.
583
+ * 非签发方走 /token 端点转 refresh-via-issuer (本表无 rt 行 → Invalid refresh token → 端点转).
584
+ */
585
+ async refreshTv2Token(row, oldRefreshToken) {
586
+ // 1. 查 grant (oauth_grants) — R2-3 附带: ORDER BY created_at DESC 取最新授权 (无排序可能拿旧 grant)
587
+ const grantRow = this.db.prepare('SELECT * FROM oauth_grants WHERE sub = ? AND client_id = ? ORDER BY created_at DESC LIMIT 1').get(row.user_address || row.user_id, row.client_id);
588
+ if (!grantRow) {
589
+ throw new Error('tv2-refresh-grant-missing: grant 未落库, 请重新授权');
590
+ }
591
+ // 2. 校验 grant_exp 未过期
592
+ if (grantRow.grant_exp && Date.now() > grantRow.grant_exp) {
593
+ throw new Error('grant_expired');
594
+ }
595
+ // 3. R2-3 阻断3: revoke-all 边界 — 用户"退出所有设备"后旧授权禁止续期 (R2-3b 核心场景, kimi #15324)。
596
+ // beforeIat 非空且 grant 创建早于边界 → 拒; grant 晚于边界 = 撤销后重新授权, 放行。
597
+ // (未注入 revocations 时跳过 — v1-only 模式无 tv2 撤销语义)
598
+ if (this.config.revocations) {
599
+ const beforeIat = this.config.revocations.getRevokeAllBeforeIat(grantRow.sub, grantRow.client_id);
600
+ if (beforeIat !== null && grantRow.created_at < beforeIat) {
601
+ throw new Error('revoked-all');
602
+ }
603
+ }
604
+ // 4. 一次性轮换: 作废旧 rt (重放旧 rt → refreshAccessToken 顶部 revoked 判定 → revoke-all)
605
+ this.db.prepare('UPDATE access_tokens SET revoked = 1 WHERE id = ?').run(row.id);
606
+ // 5. 生成新 tv2 access + 新 rt (rt 存 sha256, S4 同款)
607
+ const { issueTokenV2, tokenV2Hash } = await Promise.resolve().then(() => __importStar(require('../oauth/token-v2')));
608
+ const grant = {
609
+ sub: grantRow.sub,
610
+ client_id: grantRow.client_id,
611
+ scopes: JSON.parse(grantRow.scopes),
612
+ iss: grantRow.iss,
613
+ grant_exp: grantRow.grant_exp,
614
+ nonce: grantRow.nonce,
615
+ user_pubkey: grantRow.user_pubkey,
616
+ };
617
+ const issued = await issueTokenV2(grant, grantRow.grant_sig, this.config.tokenV2.issuerPrivkey, {});
618
+ const newRt = crypto.randomBytes(32).toString('hex');
619
+ const now = Date.now();
620
+ const expiresAt = issued.payload.exp;
621
+ this.db.prepare(`
622
+ INSERT INTO access_tokens (
623
+ id, access_token, refresh_token, client_id, user_id, user_address, scopes, expires_at, created_at, revoked
624
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0)
625
+ `).run(crypto.randomUUID(), 'tv2h:' + tokenV2Hash(issued.token), this.refreshTokenHash(newRt), // R2-3 阻断1: 落库存 sha256 (注释不再是空话, S4 同款)
626
+ row.client_id, row.user_id, row.user_address || row.user_id, JSON.stringify(grant.scopes), expiresAt, now);
627
+ return {
628
+ accessToken: issued.token,
629
+ refreshToken: newRt,
630
+ expiresIn: Math.floor((expiresAt - now) / 1000),
631
+ scopes: grant.scopes,
632
+ };
633
+ }
634
+ /**
635
+ * 撤销令牌 — RFC 7009:支持 access_token / refresh_token,可选校验 clientId 归属
636
+ */
637
+ async revokeToken(token, clientId) {
638
+ // 先按 access_token 找(v1 明文)
639
+ let row = this.db.prepare('SELECT id, client_id FROM access_tokens WHERE access_token = ? AND revoked = 0').get(token);
640
+ if (!row && token.startsWith('tv2.')) {
641
+ // kimi 复核 P2: tv2 库存的是哈希, 撤销 tv2 要走 'tv2h:'+sha256(token) 匹配
642
+ const { tokenV2Hash } = await Promise.resolve().then(() => __importStar(require('../oauth/token-v2')));
643
+ row = this.db.prepare('SELECT id, client_id FROM access_tokens WHERE access_token = ? AND revoked = 0').get('tv2h:' + tokenV2Hash(token));
644
+ }
645
+ if (!row) {
646
+ // 再按 refresh_token 找 (R2-3 阻断1: 库存 sha256 'rth:' 哈希匹配; 兼容明文遗留行)
647
+ row = this.db.prepare('SELECT id, client_id FROM access_tokens WHERE refresh_token = ? AND revoked = 0').get(this.refreshTokenHash(token));
648
+ if (!row) {
649
+ row = this.db.prepare('SELECT id, client_id FROM access_tokens WHERE refresh_token = ? AND revoked = 0').get(token);
650
+ }
651
+ }
652
+ if (!row)
653
+ return; // token 不存在(或已撤销),静默忽略(RFC 7009:不暴露)
654
+ if (clientId && row.client_id !== clientId)
655
+ return; // 不属于该 client,静默忽略
656
+ this.db.prepare('UPDATE access_tokens SET revoked = 1 WHERE id = ?').run(row.id);
657
+ // tv2 实际生效: jti 进撤销缓存(离线验证不查 access_tokens 表, 只改 revoked 标志没用)
658
+ if (token.startsWith('tv2.') && this.config.onTokenV2Revoked) {
659
+ try {
660
+ const { parseTokenV2 } = await Promise.resolve().then(() => __importStar(require('../oauth/token-v2')));
661
+ const parsed = parseTokenV2(token);
662
+ if (parsed) {
663
+ const p = parsed.payload;
664
+ this.config.onTokenV2Revoked({ jti: p.jti, iss: p.iss, exp: p.exp, sub: p.sub, client_id: p.client_id, iat: p.iat });
665
+ }
666
+ }
667
+ catch (e) {
668
+ console.error('[OAuthPlugin] onTokenV2Revoked hook error:', e?.message ?? e);
669
+ }
670
+ }
671
+ }
672
+ /**
673
+ * 获取应用信息
674
+ */
675
+ async getApp(clientId) {
676
+ const stmt = this.db.prepare(`
677
+ SELECT * FROM oauth_apps WHERE client_id = ? AND is_active = true
678
+ `);
679
+ const row = stmt.get(clientId);
680
+ if (!row) {
681
+ return null;
682
+ }
683
+ return {
684
+ id: row.id,
685
+ name: row.name,
686
+ description: row.description,
687
+ clientId: row.client_id,
688
+ clientSecretHash: row.client_secret_hash,
689
+ redirectUris: JSON.parse(row.redirect_uris),
690
+ scopes: JSON.parse(row.scopes),
691
+ ownerAddress: row.owner_address,
692
+ appType: row.app_type || 'human',
693
+ createdAt: row.created_at,
694
+ updatedAt: row.updated_at,
695
+ isActive: row.is_active
696
+ };
697
+ }
698
+ /**
699
+ * 获取用户授权的应用列表
700
+ */
701
+ async getUserApps(userId) {
702
+ const stmt = this.db.prepare(`
703
+ SELECT DISTINCT a.*, t.scopes, t.created_at as authorized_at
704
+ FROM oauth_apps a
705
+ JOIN access_tokens t ON a.client_id = t.client_id
706
+ WHERE t.user_id = ? AND t.revoked = false
707
+ ORDER BY t.created_at DESC
708
+ `);
709
+ const rows = stmt.all(userId);
710
+ return rows.map(row => ({
711
+ id: row.id,
712
+ name: row.name,
713
+ description: row.description,
714
+ clientId: row.client_id,
715
+ scopes: JSON.parse(row.scopes),
716
+ authorizedAt: row.authorized_at
717
+ }));
718
+ }
719
+ /**
720
+ * 撤销用户对应用的授权
721
+ */
722
+ async revokeUserApp(userId, clientId) {
723
+ this.db.prepare(`
724
+ UPDATE access_tokens SET revoked = true WHERE user_id = ? AND client_id = ?
725
+ `).run(userId, clientId);
726
+ }
727
+ /**
728
+ * 创建或更新用户授权记录(授权码流程中调用)
729
+ */
730
+ async upsertAuthorization(appId, userId, userAddress, clientId, scopes, expiresAt) {
731
+ const now = Date.now();
732
+ // 检查是否已有授权
733
+ const existing = this.db.prepare('SELECT * FROM oauth_authorizations WHERE app_id = ? AND user_address = ? AND is_active = true').get(appId, userAddress);
734
+ if (existing) {
735
+ // 更新 scopes + 有效期 + 时间
736
+ this.db.prepare(`
737
+ UPDATE oauth_authorizations SET scopes = ?, expires_at = ?, updated_at = ?, last_used_at = ?
738
+ WHERE id = ?
739
+ `).run(JSON.stringify(scopes), expiresAt ?? null, now, now, existing.id);
740
+ return { ...existing, scopes, expires_at: expiresAt ?? null, updated_at: now, last_used_at: now };
741
+ }
742
+ // 创建新授权记录
743
+ const id = crypto.randomUUID();
744
+ this.db.prepare(`
745
+ INSERT INTO oauth_authorizations (id, app_id, user_id, user_address, client_id, scopes, expires_at, created_at, updated_at, last_used_at, is_active)
746
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, true)
747
+ `).run(id, appId, userId, userAddress, clientId, JSON.stringify(scopes), expiresAt ?? null, now, now, now);
748
+ return { id, app_id: appId, user_id: userId, user_address: userAddress, client_id: clientId, scopes, created_at: now, updated_at: now, last_used_at: now, is_active: true };
749
+ }
750
+ /**
751
+ * 获取用户的所有授权列表
752
+ */
753
+ async getUserAuthorizations(userAddress) {
754
+ const stmt = this.db.prepare(`
755
+ SELECT auth.*, app.name as app_name, app.description as app_description
756
+ FROM oauth_authorizations auth
757
+ LEFT JOIN oauth_apps app ON auth.app_id = app.id
758
+ WHERE auth.user_address = ? AND auth.is_active = true
759
+ ORDER BY auth.updated_at DESC
760
+ `);
761
+ const rows = stmt.all(userAddress);
762
+ return rows.map(row => ({
763
+ id: row.id,
764
+ app_id: row.app_id,
765
+ app_name: row.app_name,
766
+ app_description: row.app_description,
767
+ user_address: row.user_address,
768
+ client_id: row.client_id,
769
+ scopes: JSON.parse(row.scopes),
770
+ created_at: row.created_at,
771
+ updated_at: row.updated_at,
772
+ last_used_at: row.last_used_at,
773
+ is_active: row.is_active
774
+ }));
775
+ }
776
+ /**
777
+ * 获取单个授权记录
778
+ */
779
+ async getAuthorization(authId, userAddress) {
780
+ const stmt = this.db.prepare('SELECT * FROM oauth_authorizations WHERE id = ? AND user_address = ? AND is_active = true');
781
+ return stmt.get(authId, userAddress);
782
+ }
783
+ /**
784
+ * 撤销单条授权
785
+ */
786
+ async revokeAuthorization(authId, userAddress) {
787
+ const result = this.db.prepare('UPDATE oauth_authorizations SET is_active = false, updated_at = ? WHERE id = ? AND user_address = ? AND is_active = true').run(Date.now(), authId, userAddress);
788
+ // 同时撤销该应用的所有 access_token
789
+ const auth = this.db.prepare('SELECT client_id FROM oauth_authorizations WHERE id = ?').get(authId);
790
+ if (auth) {
791
+ this.db.prepare('UPDATE access_tokens SET revoked = true WHERE client_id = ? AND user_id = (SELECT user_id FROM oauth_authorizations WHERE id = ?)').run(auth.client_id, authId);
792
+ }
793
+ return result.changes > 0;
794
+ }
795
+ /**
796
+ * 逐项撤销:从授权中移除一个 scope(PRD §27.13)
797
+ * 如果移除后 scopes 为空 → 自动调 revokeAuthorization(整个撤销)
798
+ * 同时撤销含该 scope 的 access_tokens
799
+ */
800
+ async revokeScope(authId, userAddress, scope) {
801
+ const auth = this.db.prepare('SELECT * FROM oauth_authorizations WHERE id = ? AND user_address = ? AND is_active = true').get(authId, userAddress);
802
+ if (!auth)
803
+ return 'not_found';
804
+ let currentScopes = [];
805
+ try {
806
+ currentScopes = JSON.parse(auth.scopes);
807
+ }
808
+ catch {
809
+ return 'not_found';
810
+ }
811
+ // Issue #2 (Stage 3.2): wildcard JS 层批量展开.
812
+ // 'wallet:*' / 'wallet' / '*' -> 匹配 currentScopes 里所有 wallet: 前缀 (或全部).
813
+ let scopesToRevoke;
814
+ if (scope === '*') {
815
+ scopesToRevoke = [...currentScopes];
816
+ }
817
+ else if (scope.endsWith(':*')) {
818
+ const prefix = scope.slice(0, -1); // 'wallet:'
819
+ scopesToRevoke = currentScopes.filter(s => s.startsWith(prefix));
820
+ }
821
+ else if (scope.endsWith('*')) {
822
+ const prefix = scope.slice(0, -1);
823
+ scopesToRevoke = currentScopes.filter(s => s.startsWith(prefix));
824
+ }
825
+ else {
826
+ scopesToRevoke = currentScopes.includes(scope) ? [scope] : [];
827
+ }
828
+ if (scopesToRevoke.length === 0)
829
+ return 'no_match';
830
+ const newScopes = currentScopes.filter(s => !scopesToRevoke.includes(s));
831
+ // Issue #1 (Stage 3.2): revoked_scopes 审计 - 记录撤销历史 (scope + revoked_at).
832
+ // 不只是改 scopes 数组, 留审计 trail (谁/何时/撤了什么).
833
+ let revokedHistory = [];
834
+ try {
835
+ revokedHistory = auth.revoked_scopes ? JSON.parse(auth.revoked_scopes) : [];
836
+ }
837
+ catch { /* */ }
838
+ const now = Date.now();
839
+ for (const sc of scopesToRevoke) {
840
+ revokedHistory.push({ scope: sc, revoked_at: now });
841
+ }
842
+ if (newScopes.length === 0) {
843
+ // 全部 scope 撤销 -> 整 authorization 撤销 (但先记 revoked_scopes 审计)
844
+ this.db.prepare('UPDATE oauth_authorizations SET scopes = ?, revoked_scopes = ?, updated_at = ? WHERE id = ?').run(JSON.stringify(newScopes), JSON.stringify(revokedHistory), now, authId);
845
+ await this.revokeAuthorization(authId, userAddress);
846
+ return 'full_revoked';
847
+ }
848
+ this.db.prepare('UPDATE oauth_authorizations SET scopes = ?, revoked_scopes = ?, updated_at = ? WHERE id = ?').run(JSON.stringify(newScopes), JSON.stringify(revokedHistory), now, authId);
849
+ // 撤销含被撤 scope 的 access_tokens (wildcard 批量)
850
+ const tokens = this.db.prepare('SELECT access_token, scopes FROM access_tokens WHERE client_id = ? AND user_id = ? AND revoked = false').all(auth.client_id, auth.user_id);
851
+ for (const t of tokens) {
852
+ try {
853
+ const tokenScopes = JSON.parse(t.scopes);
854
+ if (tokenScopes.some(s => scopesToRevoke.includes(s))) {
855
+ this.db.prepare('UPDATE access_tokens SET revoked = true WHERE access_token = ?').run(t.access_token);
856
+ }
857
+ }
858
+ catch { /* */ }
859
+ }
860
+ return 'revoked';
861
+ }
862
+ /**
863
+ * 撤销用户所有授权
864
+ */
865
+ async revokeAllAuthorizations(userAddress) {
866
+ // 获取所有活跃授权的 client_id
867
+ const auths = this.db.prepare('SELECT client_id FROM oauth_authorizations WHERE user_address = ? AND is_active = true').all(userAddress);
868
+ // 撤销所有 access_token
869
+ for (const auth of auths) {
870
+ this.db.prepare('UPDATE access_tokens SET revoked = true WHERE client_id = ?').run(auth.client_id);
871
+ }
872
+ // 标记所有授权为不活跃
873
+ const result = this.db.prepare('UPDATE oauth_authorizations SET is_active = false, updated_at = ? WHERE user_address = ? AND is_active = true').run(Date.now(), userAddress);
874
+ return result.changes;
875
+ }
876
+ /**
877
+ * 获取应用信息(通过数据库 id)
878
+ */
879
+ async getAppById(appId) {
880
+ const stmt = this.db.prepare('SELECT * FROM oauth_apps WHERE id = ?');
881
+ return stmt.get(appId);
882
+ }
883
+ /**
884
+ * 更新应用信息
885
+ */
886
+ async updateApp(appId, ownerAddress, data) {
887
+ // 验证所有权
888
+ const app = this.db.prepare('SELECT * FROM oauth_apps WHERE id = ? AND owner_address = ?').get(appId, ownerAddress);
889
+ if (!app)
890
+ return null;
891
+ const now = Date.now();
892
+ const updates = ['updated_at = ?'];
893
+ const values = [now];
894
+ if (data.name !== undefined) {
895
+ updates.push('name = ?');
896
+ values.push(data.name);
897
+ }
898
+ if (data.description !== undefined) {
899
+ updates.push('description = ?');
900
+ values.push(data.description);
901
+ }
902
+ if (data.redirect_uris !== undefined) {
903
+ updates.push('redirect_uris = ?');
904
+ values.push(JSON.stringify(data.redirect_uris));
905
+ }
906
+ if (data.scopes !== undefined) {
907
+ updates.push('scopes = ?');
908
+ values.push(JSON.stringify(data.scopes));
909
+ }
910
+ values.push(appId);
911
+ this.db.prepare(`UPDATE oauth_apps SET ${updates.join(', ')} WHERE id = ?`).run(...values);
912
+ return this.db.prepare('SELECT * FROM oauth_apps WHERE id = ?').get(appId);
913
+ }
914
+ /**
915
+ * 删除应用
916
+ */
917
+ async deleteApp(appId, ownerAddress) {
918
+ const result = this.db.prepare('DELETE FROM oauth_apps WHERE id = ? AND owner_address = ?').run(appId, ownerAddress);
919
+ return result.changes > 0;
920
+ }
921
+ /**
922
+ * 获取用户拥有的应用列表
923
+ */
924
+ async getOwnedApps(ownerAddress) {
925
+ const stmt = this.db.prepare('SELECT * FROM oauth_apps WHERE owner_address = ? ORDER BY created_at DESC');
926
+ return stmt.all(ownerAddress);
927
+ }
928
+ /**
929
+ * 关闭数据库
930
+ */
931
+ async close() {
932
+ if (this.db) {
933
+ this.db.close();
934
+ this.initialized = false;
935
+ }
936
+ }
937
+ // ===== Phase 2: 访问日志 (PRD §27.9) =====
938
+ async logAccess(params) {
939
+ // Issue #3 (Stage 3.2): fire-and-forget async - access-log 写入不阻塞请求.
940
+ // setImmediate 把 INSERT 推到事件循环下一轮, 调用方立即返回.
941
+ setImmediate(() => {
942
+ try {
943
+ // ★ P2-4 修复:用 clientId JOIN oauth_apps 查真实 app_name(之前永远空字符串)
944
+ let appName = params.appName || '';
945
+ if (!appName && params.clientId) {
946
+ try {
947
+ const app = this.db.prepare('SELECT name FROM oauth_apps WHERE client_id = ?').get(params.clientId);
948
+ if (app?.name)
949
+ appName = app.name;
950
+ }
951
+ catch { /* JOIN 失败回退到空串 */ }
952
+ }
953
+ this.db.prepare(`
954
+ INSERT INTO oauth_access_logs (id, app_name, client_id, user_id, user_address, endpoint, method, scope_used, response_status, created_at)
955
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
956
+ `).run(crypto.randomUUID(), appName, params.clientId || '', params.userId, params.userAddress, params.endpoint, params.method, params.scopeUsed || '', params.responseStatus || 0, Date.now());
957
+ }
958
+ catch { /* 日志失败不影响请求 */ }
959
+ });
960
+ }
961
+ async getUserAccessLogs(userAddress, limit = 50, offset = 0) {
962
+ const rows = this.db.prepare(`
963
+ SELECT * FROM oauth_access_logs WHERE user_address = ? AND created_at > ?
964
+ ORDER BY created_at DESC LIMIT ? OFFSET ?
965
+ `).all(userAddress, Date.now() - 90 * 24 * 3600 * 1000, limit, offset);
966
+ const total = this.db.prepare('SELECT COUNT(*) as n FROM oauth_access_logs WHERE user_address = ? AND created_at > ?')
967
+ .get(userAddress, Date.now() - 90 * 24 * 3600 * 1000)?.n || 0;
968
+ return {
969
+ logs: rows.map(r => ({
970
+ id: r.id, appName: r.app_name, clientId: r.client_id,
971
+ endpoint: r.endpoint, method: r.method, scopeUsed: r.scope_used,
972
+ responseStatus: r.response_status, createdAt: r.created_at,
973
+ })),
974
+ total,
975
+ };
976
+ }
977
+ }
978
+ exports.OAuthPlugin = OAuthPlugin;
979
+ //# sourceMappingURL=oauth.js.map