@7h3/protocol 0.1.2 → 0.4.0

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 (230) hide show
  1. package/.dockerignore +19 -0
  2. package/.github/dependabot.yml +32 -0
  3. package/.github/workflows/ci.yml +31 -0
  4. package/.github/workflows/publish.yml +59 -0
  5. package/.github/workflows/scorecard.yml +37 -0
  6. package/7h3.example.yaml +125 -0
  7. package/CHANGELOG.md +92 -0
  8. package/CONTRIBUTING.md +82 -0
  9. package/Dockerfile +73 -0
  10. package/GOVERNANCE.md +62 -0
  11. package/README.md +323 -6
  12. package/SECURITY.md +70 -0
  13. package/bench-results/replay-cache-full-1777891033256.json +10 -0
  14. package/bench-results/replay-cache-full-1777896317488.json +10 -0
  15. package/bench-results/replay-cache-full-1777900993184.json +10 -0
  16. package/bench-results/replay-cache-full-1777901019285.json +10 -0
  17. package/bench-results/replay-cache-quick-1777870170126.json +10 -0
  18. package/bench-results/signature-profiles-quick-1775875160079.json +85 -0
  19. package/bench-results/signature-profiles-quick-1775983539716.json +85 -0
  20. package/bench-results/signature-profiles-quick-1776237913190.json +85 -0
  21. package/bench-results/wire-codecs-full-1777891019803.json +93 -0
  22. package/bench-results/wire-codecs-full-1777896260964.json +93 -0
  23. package/bench-results/wire-codecs-full-1777901004247.json +93 -0
  24. package/bench-results/wire-codecs-quick-1775972879056.json +93 -0
  25. package/bench-results/wire-codecs-quick-1775983541111.json +93 -0
  26. package/bench-results/wire-codecs-quick-1776237914299.json +93 -0
  27. package/bench-results/wire-codecs-quick-1777841285236.json +93 -0
  28. package/bench-results/wire-codecs-quick-1777841321772.json +93 -0
  29. package/bench-results/wire-codecs-quick-1777841330408.json +93 -0
  30. package/bench-results/wire-codecs-quick-1777852886082.json +93 -0
  31. package/bench-results/wire-codecs-quick-1777852988773.json +93 -0
  32. package/bench-results/wire-codecs-quick-1777870188095.json +93 -0
  33. package/bench-results/wire-codecs-quick-1777870263918.json +93 -0
  34. package/bench-results/wire-codecs-quick-1777870455034.json +93 -0
  35. package/bench-results/wire-codecs-quick-1778816163081.json +93 -0
  36. package/bench-results/wire-codecs-quick-1778843936130.json +93 -0
  37. package/bin/7h3.ts +385 -0
  38. package/conformance/7h3_v0_1.json +77 -0
  39. package/conformance/7h3_v0_1_binary.json +20 -0
  40. package/conformance/aip_v0_1_binary.json +20 -0
  41. package/docker-compose.yaml +77 -0
  42. package/docs/ADOPTION_PLAN.md +120 -0
  43. package/docs/AGENTS.md +77 -0
  44. package/docs/AIP_RFC_v0.1.md +97 -0
  45. package/docs/AI_DECISION_CARD.md +122 -0
  46. package/docs/AI_RUNTIME_POLICY.json +126 -0
  47. package/docs/AI_RUNTIME_POLICY.yaml +110 -0
  48. package/docs/BACKPRESSURE_TUNING.md +65 -0
  49. package/docs/BENCHMARK_CLAIM_MATRIX.md +42 -0
  50. package/docs/BENCHMARK_REPORT_TEMPLATE.md +169 -0
  51. package/docs/BINARY_CODEC_BENCH.md +23 -0
  52. package/docs/CLEAN_CLONE_RUNBOOK.md +36 -0
  53. package/docs/CLOCK_SKEW_POLICY.md +30 -0
  54. package/docs/DISTRIBUTED_REPLAY.md +142 -0
  55. package/docs/FUZZ_CAMPAIGN.md +121 -0
  56. package/docs/GATEWAY.md +195 -0
  57. package/docs/KEY_MANAGEMENT_POLICY.md +53 -0
  58. package/docs/KEY_REVOCATION.md +69 -0
  59. package/docs/MCP_WRAPPER.md +159 -0
  60. package/docs/MIGRATION_GUIDE.md +40 -0
  61. package/docs/OPERATORS.md +184 -0
  62. package/docs/PERF_REGRESSION_POLICY.md +34 -0
  63. package/docs/PROJECT_EXAMINATION_2026-05-31.md +219 -0
  64. package/docs/RELEASE_BENCHMARK_REPORT_2026-05-15.md +135 -0
  65. package/docs/RELEASE_GATE.md +25 -0
  66. package/docs/RELEASE_NOTES_v0.1.0.md +54 -0
  67. package/docs/SECURITY_REVIEW_2026-06-05.md +165 -0
  68. package/docs/TELEMETRY.md +41 -0
  69. package/docs/THREAT_MODEL.md +89 -0
  70. package/docs/VERSIONING_POLICY.md +30 -0
  71. package/docs/assets/banner.png +0 -0
  72. package/eslint.config.js +15 -0
  73. package/fuzz/ts/harness-decode.ts +136 -0
  74. package/fuzz/ts/harness-verify.ts +121 -0
  75. package/fuzz/ts/run.ts +35 -0
  76. package/mcp-server/README.md +38 -0
  77. package/mcp-server/package-lock.json +1187 -0
  78. package/mcp-server/package.json +35 -0
  79. package/mcp-server/src/index.ts +236 -0
  80. package/mcp-server/tsconfig.json +14 -0
  81. package/package.json +79 -13
  82. package/scripts/aip-framework-quickstart.ts +110 -0
  83. package/scripts/aip-mcp-gateway.ts +38 -0
  84. package/scripts/aip-mcp-wrap-demo.ts +72 -0
  85. package/scripts/aip-quickstart.ts +60 -0
  86. package/scripts/bench-diff.ts +118 -0
  87. package/scripts/bench-protocol-e2e.ts +937 -0
  88. package/scripts/bench-protocol-openloop.ts +1397 -0
  89. package/scripts/bench-replay-cache.ts +76 -0
  90. package/scripts/bench-signature-profiles.ts +180 -0
  91. package/scripts/bench-wire-codecs.ts +161 -0
  92. package/scripts/build-binary-conformance.ts +36 -0
  93. package/scripts/build-release-dashboard.ts +175 -0
  94. package/scripts/canary-rollout.ts +38 -0
  95. package/scripts/mcpGatewayCli.test.ts +116 -0
  96. package/scripts/prepare-aip-package.ts +88 -0
  97. package/scripts/regen-conformance-sigs.ts +18 -0
  98. package/scripts/release-gate.ts +19 -0
  99. package/scripts/validate-runtime-policy.ts +18 -0
  100. package/sdk/browser/index.test.ts +162 -0
  101. package/sdk/browser/index.ts +257 -0
  102. package/sdk/browser/package.json +13 -0
  103. package/sdk/go/go.mod +3 -0
  104. package/sdk/go/http.go +135 -0
  105. package/sdk/go/protocol.go +324 -0
  106. package/sdk/go/protocol_test.go +334 -0
  107. package/sdk/go/webhook.go +136 -0
  108. package/sdk/python/README.md +18 -0
  109. package/sdk/python/protocol_7h3/__init__.py +46 -0
  110. package/sdk/python/protocol_7h3/http.py +212 -0
  111. package/sdk/python/protocol_7h3/keys.py +149 -0
  112. package/sdk/python/protocol_7h3/protocol.py +525 -0
  113. package/sdk/python/protocol_7h3/queue.py +118 -0
  114. package/sdk/python/protocol_7h3/webhook.py +116 -0
  115. package/sdk/python/pyproject.toml +40 -0
  116. package/sdk/python/tests/test_conformance.py +110 -0
  117. package/sdk/python/tests/test_http.py +305 -0
  118. package/sdk/python/tests/test_keys.py +417 -0
  119. package/sdk/python/tests/test_queue.py +120 -0
  120. package/sdk/python/tests/test_webhook.py +345 -0
  121. package/sdk/rust/Cargo.lock +371 -0
  122. package/sdk/rust/Cargo.toml +25 -0
  123. package/sdk/rust/README.md +31 -0
  124. package/sdk/rust/fuzz/Cargo.toml +29 -0
  125. package/sdk/rust/fuzz/fuzz_targets/fuzz_canonicalize.rs +46 -0
  126. package/sdk/rust/fuzz/fuzz_targets/fuzz_decode.rs +11 -0
  127. package/sdk/rust/src/bin/aip_mcp_gateway.rs +59 -0
  128. package/sdk/rust/src/http.rs +145 -0
  129. package/sdk/rust/src/keys.rs +161 -0
  130. package/sdk/rust/src/lib.rs +688 -0
  131. package/sdk/rust/src/queue.rs +79 -0
  132. package/sdk/rust/src/webhook.rs +86 -0
  133. package/sdk/rust/tests/conformance.rs +148 -0
  134. package/sdk/rust/tests/gateway.rs +130 -0
  135. package/sdk/rust/tests/http_webhook_queue.rs +201 -0
  136. package/sdk/rust/tests/keys.rs +189 -0
  137. package/src/agentAdapter.test.ts +48 -0
  138. package/src/agentAdapter.ts +56 -0
  139. package/src/auditLog.test.ts +145 -0
  140. package/src/auditLog.ts +147 -0
  141. package/src/conformance.test.ts +136 -0
  142. package/src/conformanceVectors.ts +99 -0
  143. package/src/frameworkAdapters.test.ts +290 -0
  144. package/src/frameworkAdapters.ts +261 -0
  145. package/src/gateway.test.ts +343 -0
  146. package/src/gateway.ts +171 -0
  147. package/src/grpcBinding.test.ts +211 -0
  148. package/src/grpcBinding.ts +103 -0
  149. package/src/httpBinding.test.ts +376 -0
  150. package/src/httpBinding.ts +163 -0
  151. package/src/index.ts +32 -0
  152. package/src/keyInfra.test.ts +278 -0
  153. package/src/keyInfra.ts +228 -0
  154. package/src/keyRegistry.ts +59 -0
  155. package/src/keyRotation.test.ts +78 -0
  156. package/src/keyRotation.ts +72 -0
  157. package/src/mcpGateway.test.ts +129 -0
  158. package/src/mcpGateway.ts +250 -0
  159. package/src/mcpTransports.test.ts +92 -0
  160. package/src/mcpTransports.ts +169 -0
  161. package/src/mcpWrapper.test.ts +179 -0
  162. package/src/mcpWrapper.ts +206 -0
  163. package/src/policyEnforcer.test.ts +99 -0
  164. package/src/policyEnforcer.ts +169 -0
  165. package/src/policyTelemetryFeedback.test.ts +25 -0
  166. package/src/policyTelemetryFeedback.ts +38 -0
  167. package/src/protocol.bench.ts +37 -0
  168. package/src/protocol.test.ts +155 -0
  169. package/src/protocol.ts +413 -0
  170. package/src/protocolAgent.test.ts +105 -0
  171. package/src/protocolAgent.ts +169 -0
  172. package/src/protocolBinary.test.ts +165 -0
  173. package/src/protocolBinary.ts +312 -0
  174. package/src/protocolCapabilities.ts +70 -0
  175. package/src/protocolFuzz.advanced.test.ts +235 -0
  176. package/src/protocolFuzz.test.ts +111 -0
  177. package/src/protocolNegative.test.ts +97 -0
  178. package/src/protocolReplay.test.ts +71 -0
  179. package/src/protocolReplay.ts +194 -0
  180. package/src/protocolTransport.test.ts +556 -0
  181. package/src/protocolTransport.ts +483 -0
  182. package/src/queueBinding.test.ts +130 -0
  183. package/src/queueBinding.ts +102 -0
  184. package/src/rateLimiter.test.ts +96 -0
  185. package/src/rateLimiter.ts +46 -0
  186. package/src/redisClient.ts +140 -0
  187. package/src/redisIntegration.test.ts +134 -0
  188. package/src/replayStores.test.ts +141 -0
  189. package/src/replayStores.ts +82 -0
  190. package/src/revocation.test.ts +98 -0
  191. package/src/revocation.ts +0 -0
  192. package/src/routePolicy.test.ts +87 -0
  193. package/src/routePolicy.ts +72 -0
  194. package/src/runtimePolicy.test.ts +49 -0
  195. package/src/runtimePolicy.ts +81 -0
  196. package/src/runtimePolicyManager.test.ts +29 -0
  197. package/src/runtimePolicyManager.ts +50 -0
  198. package/src/runtimePolicyPresets.ts +43 -0
  199. package/src/signedResponse.test.ts +111 -0
  200. package/src/signedResponse.ts +83 -0
  201. package/src/webhookBinding.test.ts +144 -0
  202. package/src/webhookBinding.ts +115 -0
  203. package/src/wsBinding.test.ts +221 -0
  204. package/src/wsBinding.ts +100 -0
  205. package/tsconfig.json +15 -0
  206. package/tsconfig.lib.json +23 -0
  207. package/vite.lib.config.ts +16 -0
  208. package/agentAdapter.d.ts +0 -26
  209. package/conformanceVectors.d.ts +0 -20
  210. package/frameworkAdapters.d.ts +0 -72
  211. package/index.d.ts +0 -20
  212. package/index.js +0 -1702
  213. package/keyRotation.d.ts +0 -20
  214. package/mcpGateway.d.ts +0 -37
  215. package/mcpTransports.d.ts +0 -62
  216. package/mcpWrapper.d.ts +0 -83
  217. package/policyEnforcer.d.ts +0 -50
  218. package/policyTelemetryFeedback.d.ts +0 -11
  219. package/protocol.d.ts +0 -66
  220. package/protocolAgent.d.ts +0 -58
  221. package/protocolBinary.d.ts +0 -8
  222. package/protocolCapabilities.d.ts +0 -24
  223. package/protocolReplay.d.ts +0 -35
  224. package/protocolTransport.d.ts +0 -73
  225. package/redisClient.d.ts +0 -49
  226. package/replayStores.d.ts +0 -32
  227. package/revocation.d.ts +0 -71
  228. package/runtimePolicy.d.ts +0 -24
  229. package/runtimePolicyManager.d.ts +0 -15
  230. package/runtimePolicyPresets.d.ts +0 -11
@@ -0,0 +1,135 @@
1
+ # Release Benchmark Report (2026-05-15)
2
+
3
+ ## 1) Metadata
4
+
5
+ - Report ID: `gluv-release-bench-2026-05-15`
6
+ - Date/Time (UTC): 2026-05-15 (updated 2026-05-18)
7
+ - Branch/Commit: `bbcd960` (Fix inFlight counter leak in HTTP batch bench server handler)
8
+ - Runtime: Node.js `v24.10.0`
9
+ - Machine: local benchmark host (same environment used for prior release-gate runs)
10
+
11
+ ## 2) Scope
12
+
13
+ - Profile: `full` (segmented mode-by-mode to avoid timeout)
14
+ - Modes tested:
15
+ - `ws`, `ws-batch`, `ws-binary`, `ws-binary-batch`
16
+ - `http-binary`
17
+ - `http-batch` (concurrency 10 lanes complete; concurrency 100 unstable/timeout)
18
+ - `http-binary-batch` (concurrency 10 lanes complete; concurrency 100 incomplete)
19
+ - Payload sizes: `256`, `1024`, `4096` bytes
20
+ - Concurrency levels targeted: `10`, `100`
21
+
22
+ ## 3) Security Configuration Matrix
23
+
24
+ | Check | Full Secure Protocol |
25
+ |---|---:|
26
+ | Signature verification | enabled |
27
+ | Canonicalization | enabled |
28
+ | Replay defense | enabled |
29
+ | TTL/clock-skew enforcement | enabled |
30
+ | Policy checks/guardrails | enabled |
31
+
32
+ Notes:
33
+ - Guardrail for unsafe plain `http` high-concurrency was enforced.
34
+ - No benchmark run in this report used invariant-bypass settings.
35
+
36
+ ## 4) Commands Executed (Representative)
37
+
38
+ ```bash
39
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --ci --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes ws
40
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --ci --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes ws-batch
41
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --ci --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes ws-binary
42
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --ci --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes ws-binary-batch
43
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --ci --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes http-binary
44
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes http-batch --payloads 256,1024,4096 --concurrency 10
45
+ npx tsx scripts/bench-protocol-openloop.ts --profile full --adaptive --p99-threshold 250 --drop-threshold-pct 2 --adaptive-max-doublings 6 --adaptive-binary-steps 8 --modes http-binary-batch --payloads 256,1024,4096 --concurrency 10
46
+ ```
47
+
48
+ ## 5) Results Summary (Best observed per lane)
49
+
50
+ ### Full Secure Protocol (authoritative)
51
+
52
+ | Mode | Payload | Concurrency | Ops/s | Drop % | p99 ms | Sustainable |
53
+ |---|---:|---:|---:|---:|---:|---|
54
+ | ws | 256 | 100 | 6548.375 | 0.000 | 49.669 | yes |
55
+ | ws | 1024 | 100 | 5887.500 | 0.000 | 53.772 | yes |
56
+ | ws | 4096 | 100 | 3887.500 | 0.000 | 66.011 | yes |
57
+ | ws-batch | 256 | 100 | 7649.000 | 0.000 | 30.971 | yes |
58
+ | ws-batch | 1024 | 100 | 6749.500 | 0.000 | 37.306 | yes |
59
+ | ws-batch | 4096 | 100 | 3850.000 | 0.000 | 49.455 | yes |
60
+ | ws-binary | 256 | 100 | 7261.000 | 0.000 | 53.193 | yes |
61
+ | ws-binary | 1024 | 100 | 5087.375 | 0.000 | 73.307 | yes |
62
+ | ws-binary | 4096 | 100 | 3662.500 | 0.000 | 77.854 | yes |
63
+ | ws-binary-batch | 256 | 100 | 5750.000 | 0.000 | 36.134 | yes |
64
+ | ws-binary-batch | 1024 | 100 | 6499.000 | 0.000 | 35.508 | yes |
65
+ | ws-binary-batch | 4096 | 100 | 4246.000 | 0.000 | 63.565 | yes |
66
+ | http-binary | 256 | 100 | 2699.875 | 0.000 | 129.755 | yes |
67
+ | http-binary | 1024 | 100 | 2385.000 | 0.000 | 119.438 | yes |
68
+ | http-binary | 4096 | 100 | 11993.750 | 0.000 | 17.647 | yes |
69
+ | http-batch | 256 | 10 | 399.125 | 1.359 | 0.867 | yes |
70
+ | http-batch | 1024 | 10 | 291.625 | 1.686 | 0.939 | yes |
71
+ | http-batch | 4096 | 10 | 320.500 | 1.536 | 1.259 | yes |
72
+ | http-binary-batch | 256 | 10 | 276.000 | 1.779 | 0.979 | yes |
73
+ | http-binary-batch | 1024 | 10 | 260.000 | 1.887 | 0.983 | yes |
74
+ | http-binary-batch | 4096 | 10 | 447.500 | 1.214 | 1.260 | yes |
75
+
76
+ ### Updated results after bug fix (2026-05-18, commit `bbcd960`)
77
+
78
+ Root cause identified and fixed: the `inFlight` counter in the HTTP batch bench server handler was never decremented for batch requests, causing it to accumulate until the server began 503-ing all traffic. Fix: added `finally { this.inFlight -= 1 }` to the batch path.
79
+
80
+ | Mode | Payload | Concurrency | Ops/s | Drop % | p99 ms | Sustainable |
81
+ |---|---:|---:|---:|---:|---:|---|
82
+ | http-batch | 256 | 100 | 34940.000 | 0.000 | 7.877 | yes |
83
+ | http-batch | 1024 | 100 | 21460.000 | 0.000 | 11.470 | yes |
84
+ | http-batch | 4096 | 100 | 17886.667 | 0.000 | 13.683 | yes |
85
+ | http-binary-batch | 256 | 100 | 28238.000 | 0.000 | 8.551 | yes |
86
+ | http-binary-batch | 1024 | 100 | 19056.000 | 0.000 | 22.214 | yes |
87
+ | http-binary-batch | 4096 | 100 | 11096.000 | 0.000 | 20.675 | yes |
88
+
89
+ Evidence: `dist/bench/protocol-openloop.quick.2026-05-18T09-23-51-852Z.json`
90
+
91
+ ## 6) SLO Gate Status
92
+
93
+ Defined gates used in this closure cycle:
94
+
95
+ - Interactive lanes: `p99 <= 25ms`, `drop <= 2%`
96
+ - High-throughput lanes: `p99 <= 250ms`, `drop <= 2%`
97
+
98
+ Current status:
99
+
100
+ - WS lanes (`ws*`): PASS on completed lanes.
101
+ - `http-binary`: PASS on completed lanes.
102
+ - `http-batch` and `http-binary-batch`: PASS at concurrency `100` after `bbcd960` bug fix (0% drop, all p99 within gate).
103
+
104
+ Overall decision: `GO (all lanes pass SLO gates as of 2026-05-18)`
105
+
106
+ ## 7) Reliability Hardening Applied During Benchmarking
107
+
108
+ - Added HTTP/2 server stream `error` handling in bench harness.
109
+ - Added HTTP/2 client session `error` handling in bench harness.
110
+ - These are benchmark resilience fixes and do not alter protocol invariants.
111
+
112
+ ## 8) Evidence Artifacts
113
+
114
+ - `dist/bench/protocol-openloop.full.2026-05-15T08-33-35-118Z.json`
115
+ - `dist/bench/protocol-openloop.full.2026-05-15T08-48-39-773Z.json`
116
+ - `dist/bench/protocol-openloop.full.2026-05-15T09-03-28-317Z.json`
117
+ - `dist/bench/protocol-openloop.full.2026-05-15T09-18-35-320Z.json`
118
+ - `dist/bench/protocol-openloop.full.2026-05-15T09-33-32-306Z.json`
119
+ - `dist/bench/protocol-openloop.full.2026-05-15T10-48-40-452Z.json`
120
+ - `dist/bench/protocol-openloop.full.2026-05-15T11-18-47-746Z.json`
121
+
122
+ ## 9) Security Review Checklist
123
+
124
+ - [x] Signature verification enabled
125
+ - [x] Replay defense enabled
126
+ - [x] TTL/clock-skew checks enabled
127
+ - [x] Canonicalization enabled
128
+ - [x] Policy validation run (`npm run policy:validate`)
129
+ - [x] Release gate re-run after harness changes (`npm run release:gate`)
130
+
131
+ ## 10) Next Actions for Full Closure
132
+
133
+ - ~~Rework HTTP batch transport path before re-qualification at concurrency `100`.~~ Resolved by `bbcd960`.
134
+ - All transport modes qualified. No further bench gate blockers.
135
+ - Proceed with `@7h3/protocol` publish from `dist/npm-aip/` via release automation.
@@ -0,0 +1,25 @@
1
+ # GLUV Release Gate
2
+
3
+ Run this gate before publishing protocol performance claims or changing transport defaults.
4
+
5
+ ```bash
6
+ npm run release:gate
7
+ ```
8
+
9
+ The gate runs tests, AIP build, lint, wire benchmarks, and adaptive open-loop CI checks. For release candidates, also run:
10
+
11
+ ```bash
12
+ npm run bench:wire:full
13
+ npm run bench:replay:full
14
+ npm run bench:openloop:full
15
+ npm run conformance:binary
16
+ npm run conformance:python
17
+ npm run conformance:rust
18
+ ```
19
+
20
+ ## Rollout Rules
21
+
22
+ - Compact JSON remains the default wire format for `aip/0.1` compatibility.
23
+ - Binary wire and binary WebSocket modes are opt-in until negotiated through `CAPS`.
24
+ - Signature verification, replay defense, TTL validation, and canonicalization must stay enabled in all benchmark claims.
25
+ - README performance numbers must come from fresh benchmark artifacts committed or attached to the release.
@@ -0,0 +1,54 @@
1
+ # v0.1.0 — First public release
2
+
3
+ > **The signing-and-replay layer your agent protocol forgot.**
4
+
5
+ MCP sends JSON-RPC unsigned. A2A signs the identity card, not the traffic.
6
+ `@7h3/protocol` puts a signed, TTL-bounded, replay-checked AIP envelope around every message — without touching your handler.
7
+
8
+ ## What's included
9
+
10
+ **Core AIP (`aip/0.1`)**
11
+ Real WebCrypto HMAC-SHA256 + Ed25519 over a deterministic canonical form. Byte-identical signatures in TypeScript, Python, and Rust via a shared conformance fixture.
12
+
13
+ **Distributed replay protection**
14
+ Redis-backed `SET NX PX` atomic reserve. Client-agnostic (`RedisLikeClient`) — works with ioredis, node-redis, or any adapter. Graceful degradation to local store on Redis outage; `onDegraded` hook for observability.
15
+
16
+ **Fleet-wide key revocation**
17
+ Cached reads, fail-closed default. Wraps any `SignatureResolver` — one line to add revocation to an existing verify path.
18
+
19
+ **MCP hardening wrapper**
20
+ Drop `wrapMcpServer` around your handler. Add `wrapMcpClient` on the caller. Four threat bindings enforced out of the box:
21
+
22
+ | Binding | Defends against |
23
+ |---|---|
24
+ | Recipient | Cross-server replay |
25
+ | Sender | Response spoofing |
26
+ | Correlation | Response substitution |
27
+ | Replay (default on) | Duplicate execution |
28
+
29
+ **Transport adapters**
30
+ `serveMcpOverStdio` + `createHttpMcpHandler` — real transports, no new npm deps.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ npm install @7h3/protocol
36
+ ```
37
+
38
+ ## Quick demo
39
+
40
+ ```bash
41
+ git clone https://github.com/IceMasterT/7h3-protocol-aip
42
+ cd 7h3-protocol-aip && npm install
43
+ npm run aip:mcp:wrap # proves tamper + replay rejection
44
+ ```
45
+
46
+ ## Honest caveats
47
+
48
+ - No independent security audit yet — reproductions and findings welcome.
49
+ - Distributed stores require a Redis (or equivalent) control plane; operators own HA and clock sync.
50
+ - Wire version `aip/0.1` is stable; the TypeScript API is pre-1.0 (minor version may bring breaking changes).
51
+
52
+ ## License
53
+
54
+ MIT.
@@ -0,0 +1,165 @@
1
+ # Internal Security Review — AIP v0.1.2
2
+
3
+ **Date:** 2026-06-05
4
+ **Reviewer:** Claude Code (AI-assisted internal review)
5
+ **Scope:** `@7h3/protocol` v0.1.2 — TypeScript sources, Python SDK, Rust SDK
6
+ **Status:** ⚠️ NOT an independent third-party audit. This review was performed by the same AI assistant that co-developed parts of the codebase. It is published for transparency; it does not substitute for an independent cryptographic audit.
7
+
8
+ ---
9
+
10
+ ## Summary
11
+
12
+ The core cryptographic choices are sound: WebCrypto primitives for both HMAC-SHA256 and Ed25519, constant-time verification, algorithm-confusion guards, and fail-closed revocation. Two real bugs were found and fixed in this review pass. No signature-forgery or authentication-bypass paths were identified.
13
+
14
+ | Finding | Severity | Status |
15
+ |---|---|---|
16
+ | Replay key collision via unescaped `\|` separator | Medium | **Fixed** — `encodeURIComponent` applied |
17
+ | Empty nonce not rejected by `validateEnvelope` | Low | **Fixed** — error diagnostic added |
18
+ | Rust cargo-fuzz targets uncompiled (README overclaim) | Low | **Corrected in README** |
19
+ | `recipient: null` vs `undefined` — cross-language parity gap | Low | Documented accepted risk |
20
+ | Revocation key space-separator (minor variant of #1) | Low | Documented accepted risk |
21
+
22
+ ---
23
+
24
+ ## Finding 1 — Replay Key Collision (Medium, Fixed)
25
+
26
+ **File:** `src/protocolReplay.ts` — `InMemoryReplayCache.makeKey` and `DistributedReplayCache.makeKey`
27
+
28
+ **Before:**
29
+ ```ts
30
+ return `${envelope.header.sender}|${envelope.header.messageId}|${envelope.header.nonce}`
31
+ ```
32
+
33
+ **Problem:** The `|` separator is unescaped. A sender named `"a|b"` with messageId `"c"` produces the same composite key as sender `"a"` with messageId `"b|c"`. If an attacker controls their own agent ID and can observe or predict a target agent's messageId, they can send a message first that "claims" the target's replay key, causing the legitimate message to be rejected as a replay.
34
+
35
+ **Security impact:** This is a **false-rejection DoS**, not a forgery or auth bypass. Signatures still cover the full, unencoded field values — an attacker cannot craft a message that validates under a victim's key. The worst they can achieve is having a legitimate message silently dropped.
36
+
37
+ **Fix applied:**
38
+ ```ts
39
+ return `${encodeURIComponent(envelope.header.sender)}|${encodeURIComponent(envelope.header.messageId)}|${encodeURIComponent(envelope.header.nonce)}`
40
+ ```
41
+
42
+ `encodeURIComponent` maps `|` → `%7C`, making cross-boundary collisions impossible. For typical agent IDs containing only word characters and hyphens, the output is byte-identical to the old format — no Redis key migration required for standard deployments.
43
+
44
+ **Note on deployed keys:** If your Redis instance already contains replay keys with agent IDs containing `|`, `%`, or other URI-reserved characters, those keys will have a different format after this fix. Existing entries will expire naturally via their TTL; no manual migration is needed.
45
+
46
+ ---
47
+
48
+ ## Finding 2 — Empty Nonce Not Validated (Low, Fixed)
49
+
50
+ **File:** `src/protocol.ts` — `validateEnvelope`
51
+
52
+ **Problem:** `validateEnvelope` checked `messageId`, `sender`, `ttlMs`, `timestampMs`, and `content` but did not validate `nonce`. A missing or empty nonce produces a replay key of the form `sender||messageId`. While this doesn't defeat replay protection outright (the composite key still covers sender + messageId), it eliminates the entropy contribution of the nonce and allows any two messages with identical sender + messageId to collide in the replay cache, regardless of time.
53
+
54
+ **Fix applied:** Added `if (!nonce.trim()) diagnostics.push({ level: 'error', message: 'Missing nonce — replay protection requires a unique nonce per message' })`.
55
+
56
+ ---
57
+
58
+ ## Finding 3 — Rust cargo-fuzz Targets Uncompiled (Low, Corrected)
59
+
60
+ **File:** `sdk/rust/fuzz/`, `README.md` status table
61
+
62
+ **Problem:** `cargo-fuzz` is not installed in the development environment. The Rust fuzz targets (`fuzz_decode.rs`, `fuzz_canonicalize.rs`) were authored and reviewed but have never been compiled or run. The prior README entry claimed "✅ cargo-fuzz targets" without this qualification.
63
+
64
+ **Correction:** The README status now reads: "TypeScript harnesses run clean (50k/20k rounds); Rust targets authored, not yet executed (`cargo-fuzz` not installed)."
65
+
66
+ The targets themselves look structurally correct:
67
+ - `fuzz_decode`: feeds arbitrary bytes through `decode_envelope` under a no-panic invariant — correct
68
+ - `fuzz_canonicalize`: constructs `ProtocolEnvelope` from fuzz bytes, asserts `canonicalize_envelope` is idempotent — correct
69
+
70
+ To run:
71
+ ```bash
72
+ rustup toolchain install nightly
73
+ cargo install cargo-fuzz
74
+ cargo +nightly fuzz run fuzz_decode --manifest-path sdk/rust/fuzz/Cargo.toml
75
+ cargo +nightly fuzz run fuzz_canonicalize --manifest-path sdk/rust/fuzz/Cargo.toml
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Finding 4 — `recipient: null` vs Absent (Low, Accepted Risk)
81
+
82
+ **File:** `src/protocol.ts` — `serializeHeaderCanonical`
83
+
84
+ ```ts
85
+ if (header.recipient !== undefined) {
86
+ parts.push(`"recipient":${JSON.stringify(header.recipient)}`)
87
+ }
88
+ ```
89
+
90
+ If a JSON message arrives with `"recipient": null`, JavaScript parses this as `null`, which passes the `!== undefined` check. `JSON.stringify(null)` produces `"null"`, so the canonical form includes `"recipient":null` — different from a message where `recipient` is absent entirely.
91
+
92
+ In the TypeScript type system, `ProtocolHeader.recipient` is typed as `string | undefined`. A `null` value is a type violation but not rejected at runtime.
93
+
94
+ **Cross-language risk:** The Rust SDK uses `Option<String>` for `recipient`, which serializes `None` as absent (the field is skipped). If a TS caller writes `recipient: null` and the Rust verifier receives it, the canonical forms diverge → signature mismatch.
95
+
96
+ **Status:** Accepted risk. The correct mitigation is to normalise `null` → `undefined` in the wire decoder. This is tracked as a future improvement. In practice, `null` recipients do not appear in protocol-generated envelopes (`createEnvelope` leaves `recipient` undefined when not supplied).
97
+
98
+ ---
99
+
100
+ ## Finding 5 — Revocation Key Space Separator (Low, Accepted Risk)
101
+
102
+ **File:** `src/revocation.ts` — `InMemoryRevocationStore.makeKey` and `createRedisRevocationStore`
103
+
104
+ The revocation key format `"${sender} ${keyId}"` uses a space as separator. If a sender ID contains a space (e.g., `"agent one"`) and a keyId starts with something that continues the pattern, a collision is theoretically possible. However:
105
+
106
+ 1. Key IDs in practice are short tokens like `"k1"`, `"prod-key-2026"` — not containing spaces
107
+ 2. Agent IDs with spaces are unusual enough to warrant operator documentation
108
+ 3. The collision would cause a revocation miss (treating a non-revoked key as revoked, or vice versa) — not an auth bypass
109
+
110
+ **Status:** Accepted risk. Documented in this review. Consider changing to `${encodeURIComponent(sender)}:${encodeURIComponent(keyId)}` in a future patch.
111
+
112
+ ---
113
+
114
+ ## Positive Findings
115
+
116
+ ### Constant-time HMAC verification
117
+
118
+ `hmacVerify` delegates to `crypto.subtle.verify` (WebCrypto), which is specified to run in constant time. There is no string `===` comparison of signature bytes anywhere on the verify hot path.
119
+
120
+ ### Algorithm confusion rejected
121
+
122
+ `verifyEnvelopeSignature` checks `signature.alg !== material.alg` before dispatching. An envelope signed with Ed25519 cannot be verified with HMAC material and vice versa — the check is at the dispatch level, before any cryptographic operation.
123
+
124
+ `verifyEnvelopeHmac` checks `envelope.signature.alg !== 'HS256'` explicitly before calling `hmacVerify`. Same for `verifyEnvelopeEd25519` / `'ED25519'`. Downgrade attacks via algorithm confusion are blocked at two independent points.
125
+
126
+ ### Revocation fail-closed
127
+
128
+ `createRedisRevocationStore` defaults to `errorBehavior: 'reject'`. A Redis outage causes the store to treat the key as revoked. Cached stale-revoked entries serve during brief outages without allowing a previously-revoked key through.
129
+
130
+ ### MCP wrapper — all four bindings present
131
+
132
+ Code review confirms all four claimed bindings in `src/mcpWrapper.ts`:
133
+
134
+ | Binding | Code location | Enforcement |
135
+ |---|---|---|
136
+ | Recipient | line 120: `envelope.header.recipient !== options.selfAgentId` | Returns 32600 error; handler does not run |
137
+ | Sender | line 176: `received.envelope.header.sender !== options.peerAgentId` | Throws; response discarded |
138
+ | Correlation | line 181: `body.correlationId !== decodeOptions.expectCorrelationId` | Throws; response discarded |
139
+ | Replay | `InMemoryReplayCache` injected by default in `wrapMcpServer` | Replay → `consume()` returns `{ok: false}` |
140
+
141
+ ### Cross-language parity (within tested scope)
142
+
143
+ The three conformance vectors in `conformance/aip_v0_1.json` produce byte-identical signatures in TypeScript, Python, and Rust. The canonicalization format is simple string concatenation with fixed key order; there is no runtime type ambiguity within the tested input set.
144
+
145
+ **Caveat:** Three vectors are a narrow coverage set. Cross-language divergence on edge cases (very large integers, Unicode normalization, `NaN`/`Infinity` in numeric fields) is not covered by the current conformance suite.
146
+
147
+ ---
148
+
149
+ ## Scope Not Covered
150
+
151
+ | Area | Reason not covered |
152
+ |---|---|
153
+ | WebCrypto Ed25519 implementation | Browser/Node built-in; outside reviewable scope |
154
+ | Binary wire format (protocolBinary.ts) | Not reviewed in this pass — fuzz coverage via `protocolFuzz.advanced.test.ts` exists |
155
+ | Framework adapters (LangChain, LlamaIndex) | Translation adapters; lower security surface |
156
+ | Policy enforcer | Logic review only; not cryptographic |
157
+ | Python pure-Ed25519 implementation | Correctness verified against conformance vector; not audited for side channels |
158
+
159
+ ---
160
+
161
+ ## Conclusion
162
+
163
+ The cryptographic architecture is well-chosen: standard primitives, no custom crypto, constant-time comparison, fail-closed defaults. The two bugs fixed in this review (replay key collision, empty nonce) were low-to-medium severity and have been patched. No authentication bypass, signature forgery, or replay-protection bypass paths were found.
164
+
165
+ **This review does not substitute for an independent third-party audit by a qualified cryptographer.** The parsing, canonicalization, and replay-cache logic remain unaudited by an external reviewer. Treat accordingly for high-stakes deployments.
@@ -0,0 +1,41 @@
1
+ # Telemetry Events
2
+
3
+ Transport-level telemetry can be attached to `receiveEnvelope` via `telemetry` callback.
4
+
5
+ ## Event phases
6
+
7
+ - `decoded`
8
+ - `rejected_clock_skew`
9
+ - `rejected_validation`
10
+ - `rejected_replay`
11
+ - `rejected_missing_signature`
12
+ - `rejected_missing_material`
13
+ - `rejected_bad_signature`
14
+ - `accepted`
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { receiveEnvelope } from './src/protocolTransport'
20
+
21
+ await receiveEnvelope(rawEnvelope, {
22
+ nowMs: Date.now(),
23
+ replayCache,
24
+ secretResolver: async () => sharedSecret,
25
+ telemetry: async (event) => {
26
+ console.log(event.phase, event.sender, event.messageId, event.reason)
27
+ },
28
+ })
29
+ ```
30
+
31
+ ## Gateway audit events
32
+
33
+ `createAipMcpGatewayRuntime` supports `onAuditEvent` for request/policy traces.
34
+
35
+ Phases:
36
+
37
+ - `request_received`
38
+ - `policy`
39
+ - `verification_failed`
40
+ - `request_success`
41
+ - `request_error`
@@ -0,0 +1,89 @@
1
+ # 7h3 Protocol AIP Threat Model (v1.0 draft)
2
+
3
+ ## Scope
4
+
5
+ This model covers `aip/0.1` envelope transport and verification paths in:
6
+
7
+ - `src/protocol.ts`
8
+ - `src/protocolTransport.ts`
9
+ - `src/mcpGateway.ts`
10
+ - `sdk/rust/src/lib.rs`
11
+
12
+ ## Assets
13
+
14
+ - Message integrity and authenticity
15
+ - Agent identity binding (`sender`, `keyId`, signature material)
16
+ - Freshness (TTL + replay resistance)
17
+ - Gateway policy decisions (allowlist/auth/rate-limit)
18
+
19
+ ## Assumptions
20
+
21
+ - Clocks are roughly synchronized within deployment skew limits.
22
+ - Secret/private-key material is provisioned securely outside protocol logic.
23
+ - Transport channel can be observed/modified by adversaries; protocol must detect tamper.
24
+
25
+ ## Threats and controls
26
+
27
+ ## Tampering
28
+
29
+ - Threat: attacker modifies envelope body/header in transit.
30
+ - Controls:
31
+ - canonical payload signing (`HS256` / `ED25519`)
32
+ - signature verification before acceptance
33
+ - canonical key order fixed to prevent ambiguous signing forms
34
+
35
+ ## Replay
36
+
37
+ - Threat: attacker replays previously valid signed envelopes.
38
+ - Controls:
39
+ - TTL checks (`timestampMs + ttlMs`)
40
+ - replay cache consumption (`messageId` + `sender` + `nonce` semantics)
41
+
42
+ ## Sender impersonation
43
+
44
+ - Threat: attacker signs as trusted sender with incorrect key material.
45
+ - Controls:
46
+ - verifier resolves material by `(keyId, sender)` context
47
+ - `signatureResolver`/`secretResolver` mapping policy in transport layer
48
+
49
+ ## Algorithm confusion / downgrade
50
+
51
+ - Threat: attacker swaps `alg` or relies on omitted compact alg fields.
52
+ - Controls:
53
+ - explicit algorithm field in canonical signature object
54
+ - compact wire supports `sig.a`; default compatibility path only for legacy HS256
55
+ - verifier rejects material when resolved algorithm does not match envelope signature
56
+
57
+ ## Gateway abuse
58
+
59
+ - Threat: unauthorized or abusive JSON-RPC method calls.
60
+ - Controls:
61
+ - method allowlist
62
+ - authorization policy hook
63
+ - rate-limit policy hook with context-aware keys
64
+
65
+ ## Mitigated risks
66
+
67
+ - **Distributed replay** — a Redis-backed `DistributedReplayStore` is shipped
68
+ (`createRedisReplayStore`, `src/replayStores.ts`). It uses atomic `SET NX PX`,
69
+ batches via pipeline (`reserveMany`), and degrades to a local store on a Redis
70
+ outage so a node never blindly accepts replays and never hard-stops. See
71
+ `DISTRIBUTED_REPLAY.md`.
72
+ - **Fleet-wide key revocation** — a shared `RevocationStore`
73
+ (`createRedisRevocationStore`, `src/revocation.ts`) is consulted on the verify
74
+ path via `withRevocationCheck`. A key revoked on one node is rejected on all
75
+ nodes; reads are cached and fail **closed** by default. See `KEY_REVOCATION.md`.
76
+
77
+ ## Remaining risks (open)
78
+
79
+ - No formal fuzz campaign yet for parser/canonicalization boundaries.
80
+ - Revocation/replay stores rely on a correctly provisioned, available Redis (or
81
+ equivalent) control plane; operators own its HA and clock synchronization.
82
+ - No third-party cryptographic audit yet.
83
+
84
+ ## Required production mitigations
85
+
86
+ - Keep signature verification enabled by default in production paths.
87
+ - Deploy a shared replay store (`createRedisReplayStore`) for horizontally scaled gateways.
88
+ - Wire a shared revocation store (`createRedisRevocationStore` + `withRevocationCheck`)
89
+ and enforce key lifecycle policy (rotation, expiry, revocation) in the control plane.
@@ -0,0 +1,30 @@
1
+ # AIP Versioning Policy
2
+
3
+ ## Protocol versions
4
+
5
+ - Protocol version is declared in `header.version` (for example `aip/0.1`).
6
+ - New major protocol versions must not silently alter canonicalization or signature semantics.
7
+ - Backward-incompatible wire or verification changes require a new minor/major protocol tag.
8
+
9
+ ## Compatibility rules
10
+
11
+ - Patch releases: bug fixes only, no wire-format or canonicalization changes.
12
+ - Minor releases: additive changes only (new optional fields/capabilities, no required-field breakage).
13
+ - Major releases: allowed to remove or alter semantics with explicit migration documentation.
14
+
15
+ ## Signature profile policy
16
+
17
+ - Supported profiles are explicitly declared by `signature.alg`.
18
+ - Adding a new signature profile is a minor release only if existing profiles continue to verify unchanged.
19
+ - Removing a profile requires a major release.
20
+
21
+ ## SDK versioning
22
+
23
+ - TypeScript, Python, and Rust SDKs follow semver independently.
24
+ - Conformance fixture changes require SDK conformance updates in the same release train.
25
+
26
+ ## Release evidence requirements
27
+
28
+ - Conformance suites (TS/Python/Rust) pass.
29
+ - Bench regression checks attached for performance-sensitive changes.
30
+ - Migration guide updated for any behavior change that impacts consumers.
Binary file
@@ -0,0 +1,15 @@
1
+ import js from '@eslint/js'
2
+ import globals from 'globals'
3
+ import tseslint from 'typescript-eslint'
4
+
5
+ export default tseslint.config(
6
+ { ignores: ['dist', 'node_modules', 'sdk/rust/target'] },
7
+ {
8
+ extends: [js.configs.recommended, ...tseslint.configs.recommended],
9
+ files: ['**/*.ts'],
10
+ languageOptions: {
11
+ ecmaVersion: 2022,
12
+ globals: { ...globals.node, ...globals.browser },
13
+ },
14
+ },
15
+ )