@7h3/protocol 0.4.0 → 0.5.1

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 (248) hide show
  1. package/README.md +6 -323
  2. package/agentAdapter.d.ts +26 -0
  3. package/auditLog.d.ts +54 -0
  4. package/capability.d.ts +67 -0
  5. package/cborCodec.d.ts +34 -0
  6. package/conformanceVectors.d.ts +20 -0
  7. package/encryption.d.ts +85 -0
  8. package/envelopeCbor.d.ts +33 -0
  9. package/frameworkAdapters.d.ts +72 -0
  10. package/gateway.d.ts +53 -0
  11. package/grpcBinding.d.ts +29 -0
  12. package/httpBinding.d.ts +50 -0
  13. package/index.d.ts +39 -0
  14. package/index.js +3662 -0
  15. package/keyInfra.d.ts +64 -0
  16. package/keyRegistry.d.ts +9 -0
  17. package/keyRotation.d.ts +20 -0
  18. package/mcpGateway.d.ts +37 -0
  19. package/mcpTransports.d.ts +62 -0
  20. package/mcpWrapper.d.ts +83 -0
  21. package/otel.d.ts +65 -0
  22. package/package.json +13 -79
  23. package/policyEnforcer.d.ts +50 -0
  24. package/policyTelemetryFeedback.d.ts +11 -0
  25. package/protocol.d.ts +66 -0
  26. package/protocolAgent.d.ts +58 -0
  27. package/protocolBinary.d.ts +8 -0
  28. package/protocolCapabilities.d.ts +24 -0
  29. package/protocolReplay.d.ts +35 -0
  30. package/protocolTransport.d.ts +73 -0
  31. package/queueBinding.d.ts +43 -0
  32. package/rateLimiter.d.ts +18 -0
  33. package/{src/redisClient.ts → redisClient.d.ts} +25 -75
  34. package/replayStores.d.ts +98 -0
  35. package/revocation.d.ts +71 -0
  36. package/routePolicy.d.ts +30 -0
  37. package/runtimePolicy.d.ts +24 -0
  38. package/runtimePolicyManager.d.ts +15 -0
  39. package/runtimePolicyPresets.d.ts +11 -0
  40. package/signedResponse.d.ts +21 -0
  41. package/stream.d.ts +59 -0
  42. package/telemetry.d.ts +79 -0
  43. package/webhookBinding.d.ts +30 -0
  44. package/wsBinding.d.ts +52 -0
  45. package/.dockerignore +0 -19
  46. package/.github/dependabot.yml +0 -32
  47. package/.github/workflows/ci.yml +0 -31
  48. package/.github/workflows/publish.yml +0 -59
  49. package/.github/workflows/scorecard.yml +0 -37
  50. package/7h3.example.yaml +0 -125
  51. package/CHANGELOG.md +0 -92
  52. package/CONTRIBUTING.md +0 -82
  53. package/Dockerfile +0 -73
  54. package/GOVERNANCE.md +0 -62
  55. package/SECURITY.md +0 -70
  56. package/bench-results/replay-cache-full-1777891033256.json +0 -10
  57. package/bench-results/replay-cache-full-1777896317488.json +0 -10
  58. package/bench-results/replay-cache-full-1777900993184.json +0 -10
  59. package/bench-results/replay-cache-full-1777901019285.json +0 -10
  60. package/bench-results/replay-cache-quick-1777870170126.json +0 -10
  61. package/bench-results/signature-profiles-quick-1775875160079.json +0 -85
  62. package/bench-results/signature-profiles-quick-1775983539716.json +0 -85
  63. package/bench-results/signature-profiles-quick-1776237913190.json +0 -85
  64. package/bench-results/wire-codecs-full-1777891019803.json +0 -93
  65. package/bench-results/wire-codecs-full-1777896260964.json +0 -93
  66. package/bench-results/wire-codecs-full-1777901004247.json +0 -93
  67. package/bench-results/wire-codecs-quick-1775972879056.json +0 -93
  68. package/bench-results/wire-codecs-quick-1775983541111.json +0 -93
  69. package/bench-results/wire-codecs-quick-1776237914299.json +0 -93
  70. package/bench-results/wire-codecs-quick-1777841285236.json +0 -93
  71. package/bench-results/wire-codecs-quick-1777841321772.json +0 -93
  72. package/bench-results/wire-codecs-quick-1777841330408.json +0 -93
  73. package/bench-results/wire-codecs-quick-1777852886082.json +0 -93
  74. package/bench-results/wire-codecs-quick-1777852988773.json +0 -93
  75. package/bench-results/wire-codecs-quick-1777870188095.json +0 -93
  76. package/bench-results/wire-codecs-quick-1777870263918.json +0 -93
  77. package/bench-results/wire-codecs-quick-1777870455034.json +0 -93
  78. package/bench-results/wire-codecs-quick-1778816163081.json +0 -93
  79. package/bench-results/wire-codecs-quick-1778843936130.json +0 -93
  80. package/bin/7h3.ts +0 -385
  81. package/conformance/7h3_v0_1.json +0 -77
  82. package/conformance/7h3_v0_1_binary.json +0 -20
  83. package/conformance/aip_v0_1_binary.json +0 -20
  84. package/docker-compose.yaml +0 -77
  85. package/docs/ADOPTION_PLAN.md +0 -120
  86. package/docs/AGENTS.md +0 -77
  87. package/docs/AIP_RFC_v0.1.md +0 -97
  88. package/docs/AI_DECISION_CARD.md +0 -122
  89. package/docs/AI_RUNTIME_POLICY.json +0 -126
  90. package/docs/AI_RUNTIME_POLICY.yaml +0 -110
  91. package/docs/BACKPRESSURE_TUNING.md +0 -65
  92. package/docs/BENCHMARK_CLAIM_MATRIX.md +0 -42
  93. package/docs/BENCHMARK_REPORT_TEMPLATE.md +0 -169
  94. package/docs/BINARY_CODEC_BENCH.md +0 -23
  95. package/docs/CLEAN_CLONE_RUNBOOK.md +0 -36
  96. package/docs/CLOCK_SKEW_POLICY.md +0 -30
  97. package/docs/DISTRIBUTED_REPLAY.md +0 -142
  98. package/docs/FUZZ_CAMPAIGN.md +0 -121
  99. package/docs/GATEWAY.md +0 -195
  100. package/docs/KEY_MANAGEMENT_POLICY.md +0 -53
  101. package/docs/KEY_REVOCATION.md +0 -69
  102. package/docs/MCP_WRAPPER.md +0 -159
  103. package/docs/MIGRATION_GUIDE.md +0 -40
  104. package/docs/OPERATORS.md +0 -184
  105. package/docs/PERF_REGRESSION_POLICY.md +0 -34
  106. package/docs/PROJECT_EXAMINATION_2026-05-31.md +0 -219
  107. package/docs/RELEASE_BENCHMARK_REPORT_2026-05-15.md +0 -135
  108. package/docs/RELEASE_GATE.md +0 -25
  109. package/docs/RELEASE_NOTES_v0.1.0.md +0 -54
  110. package/docs/SECURITY_REVIEW_2026-06-05.md +0 -165
  111. package/docs/TELEMETRY.md +0 -41
  112. package/docs/THREAT_MODEL.md +0 -89
  113. package/docs/VERSIONING_POLICY.md +0 -30
  114. package/docs/assets/banner.png +0 -0
  115. package/eslint.config.js +0 -15
  116. package/fuzz/ts/harness-decode.ts +0 -136
  117. package/fuzz/ts/harness-verify.ts +0 -121
  118. package/fuzz/ts/run.ts +0 -35
  119. package/mcp-server/README.md +0 -38
  120. package/mcp-server/package-lock.json +0 -1187
  121. package/mcp-server/package.json +0 -35
  122. package/mcp-server/src/index.ts +0 -236
  123. package/mcp-server/tsconfig.json +0 -14
  124. package/scripts/aip-framework-quickstart.ts +0 -110
  125. package/scripts/aip-mcp-gateway.ts +0 -38
  126. package/scripts/aip-mcp-wrap-demo.ts +0 -72
  127. package/scripts/aip-quickstart.ts +0 -60
  128. package/scripts/bench-diff.ts +0 -118
  129. package/scripts/bench-protocol-e2e.ts +0 -937
  130. package/scripts/bench-protocol-openloop.ts +0 -1397
  131. package/scripts/bench-replay-cache.ts +0 -76
  132. package/scripts/bench-signature-profiles.ts +0 -180
  133. package/scripts/bench-wire-codecs.ts +0 -161
  134. package/scripts/build-binary-conformance.ts +0 -36
  135. package/scripts/build-release-dashboard.ts +0 -175
  136. package/scripts/canary-rollout.ts +0 -38
  137. package/scripts/mcpGatewayCli.test.ts +0 -116
  138. package/scripts/prepare-aip-package.ts +0 -88
  139. package/scripts/regen-conformance-sigs.ts +0 -18
  140. package/scripts/release-gate.ts +0 -19
  141. package/scripts/validate-runtime-policy.ts +0 -18
  142. package/sdk/browser/index.test.ts +0 -162
  143. package/sdk/browser/index.ts +0 -257
  144. package/sdk/browser/package.json +0 -13
  145. package/sdk/go/go.mod +0 -3
  146. package/sdk/go/http.go +0 -135
  147. package/sdk/go/protocol.go +0 -324
  148. package/sdk/go/protocol_test.go +0 -334
  149. package/sdk/go/webhook.go +0 -136
  150. package/sdk/python/README.md +0 -18
  151. package/sdk/python/protocol_7h3/__init__.py +0 -46
  152. package/sdk/python/protocol_7h3/http.py +0 -212
  153. package/sdk/python/protocol_7h3/keys.py +0 -149
  154. package/sdk/python/protocol_7h3/protocol.py +0 -525
  155. package/sdk/python/protocol_7h3/queue.py +0 -118
  156. package/sdk/python/protocol_7h3/webhook.py +0 -116
  157. package/sdk/python/pyproject.toml +0 -40
  158. package/sdk/python/tests/test_conformance.py +0 -110
  159. package/sdk/python/tests/test_http.py +0 -305
  160. package/sdk/python/tests/test_keys.py +0 -417
  161. package/sdk/python/tests/test_queue.py +0 -120
  162. package/sdk/python/tests/test_webhook.py +0 -345
  163. package/sdk/rust/Cargo.lock +0 -371
  164. package/sdk/rust/Cargo.toml +0 -25
  165. package/sdk/rust/README.md +0 -31
  166. package/sdk/rust/fuzz/Cargo.toml +0 -29
  167. package/sdk/rust/fuzz/fuzz_targets/fuzz_canonicalize.rs +0 -46
  168. package/sdk/rust/fuzz/fuzz_targets/fuzz_decode.rs +0 -11
  169. package/sdk/rust/src/bin/aip_mcp_gateway.rs +0 -59
  170. package/sdk/rust/src/http.rs +0 -145
  171. package/sdk/rust/src/keys.rs +0 -161
  172. package/sdk/rust/src/lib.rs +0 -688
  173. package/sdk/rust/src/queue.rs +0 -79
  174. package/sdk/rust/src/webhook.rs +0 -86
  175. package/sdk/rust/tests/conformance.rs +0 -148
  176. package/sdk/rust/tests/gateway.rs +0 -130
  177. package/sdk/rust/tests/http_webhook_queue.rs +0 -201
  178. package/sdk/rust/tests/keys.rs +0 -189
  179. package/src/agentAdapter.test.ts +0 -48
  180. package/src/agentAdapter.ts +0 -56
  181. package/src/auditLog.test.ts +0 -145
  182. package/src/auditLog.ts +0 -147
  183. package/src/conformance.test.ts +0 -136
  184. package/src/conformanceVectors.ts +0 -99
  185. package/src/frameworkAdapters.test.ts +0 -290
  186. package/src/frameworkAdapters.ts +0 -261
  187. package/src/gateway.test.ts +0 -343
  188. package/src/gateway.ts +0 -171
  189. package/src/grpcBinding.test.ts +0 -211
  190. package/src/grpcBinding.ts +0 -103
  191. package/src/httpBinding.test.ts +0 -376
  192. package/src/httpBinding.ts +0 -163
  193. package/src/index.ts +0 -32
  194. package/src/keyInfra.test.ts +0 -278
  195. package/src/keyInfra.ts +0 -228
  196. package/src/keyRegistry.ts +0 -59
  197. package/src/keyRotation.test.ts +0 -78
  198. package/src/keyRotation.ts +0 -72
  199. package/src/mcpGateway.test.ts +0 -129
  200. package/src/mcpGateway.ts +0 -250
  201. package/src/mcpTransports.test.ts +0 -92
  202. package/src/mcpTransports.ts +0 -169
  203. package/src/mcpWrapper.test.ts +0 -179
  204. package/src/mcpWrapper.ts +0 -206
  205. package/src/policyEnforcer.test.ts +0 -99
  206. package/src/policyEnforcer.ts +0 -169
  207. package/src/policyTelemetryFeedback.test.ts +0 -25
  208. package/src/policyTelemetryFeedback.ts +0 -38
  209. package/src/protocol.bench.ts +0 -37
  210. package/src/protocol.test.ts +0 -155
  211. package/src/protocol.ts +0 -413
  212. package/src/protocolAgent.test.ts +0 -105
  213. package/src/protocolAgent.ts +0 -169
  214. package/src/protocolBinary.test.ts +0 -165
  215. package/src/protocolBinary.ts +0 -312
  216. package/src/protocolCapabilities.ts +0 -70
  217. package/src/protocolFuzz.advanced.test.ts +0 -235
  218. package/src/protocolFuzz.test.ts +0 -111
  219. package/src/protocolNegative.test.ts +0 -97
  220. package/src/protocolReplay.test.ts +0 -71
  221. package/src/protocolReplay.ts +0 -194
  222. package/src/protocolTransport.test.ts +0 -556
  223. package/src/protocolTransport.ts +0 -483
  224. package/src/queueBinding.test.ts +0 -130
  225. package/src/queueBinding.ts +0 -102
  226. package/src/rateLimiter.test.ts +0 -96
  227. package/src/rateLimiter.ts +0 -46
  228. package/src/redisIntegration.test.ts +0 -134
  229. package/src/replayStores.test.ts +0 -141
  230. package/src/replayStores.ts +0 -82
  231. package/src/revocation.test.ts +0 -98
  232. package/src/revocation.ts +0 -0
  233. package/src/routePolicy.test.ts +0 -87
  234. package/src/routePolicy.ts +0 -72
  235. package/src/runtimePolicy.test.ts +0 -49
  236. package/src/runtimePolicy.ts +0 -81
  237. package/src/runtimePolicyManager.test.ts +0 -29
  238. package/src/runtimePolicyManager.ts +0 -50
  239. package/src/runtimePolicyPresets.ts +0 -43
  240. package/src/signedResponse.test.ts +0 -111
  241. package/src/signedResponse.ts +0 -83
  242. package/src/webhookBinding.test.ts +0 -144
  243. package/src/webhookBinding.ts +0 -115
  244. package/src/wsBinding.test.ts +0 -221
  245. package/src/wsBinding.ts +0 -100
  246. package/tsconfig.json +0 -15
  247. package/tsconfig.lib.json +0 -23
  248. package/vite.lib.config.ts +0 -16
@@ -1,93 +0,0 @@
1
- {
2
- "generatedAt": "2026-05-15T11:18:56.130Z",
3
- "profile": "quick",
4
- "iterations": 10000,
5
- "payloadSizes": [
6
- 256,
7
- 1024,
8
- 4096,
9
- 16384
10
- ],
11
- "results": [
12
- {
13
- "profile": "quick",
14
- "payloadBytes": 256,
15
- "format": "compact-json",
16
- "encodedBytes": 498,
17
- "encodeUsPerOp": 0.861,
18
- "decodeUsPerOp": 0.93,
19
- "encodeOpsPerSecond": 1161370.719,
20
- "decodeOpsPerSecond": 1075066.173
21
- },
22
- {
23
- "profile": "quick",
24
- "payloadBytes": 256,
25
- "format": "binary",
26
- "encodedBytes": 426,
27
- "encodeUsPerOp": 6.016,
28
- "decodeUsPerOp": 2.499,
29
- "encodeOpsPerSecond": 166209.883,
30
- "decodeOpsPerSecond": 400117.683
31
- },
32
- {
33
- "profile": "quick",
34
- "payloadBytes": 1024,
35
- "format": "compact-json",
36
- "encodedBytes": 1269,
37
- "encodeUsPerOp": 0.963,
38
- "decodeUsPerOp": 0.904,
39
- "encodeOpsPerSecond": 1038530.737,
40
- "decodeOpsPerSecond": 1105743.219
41
- },
42
- {
43
- "profile": "quick",
44
- "payloadBytes": 1024,
45
- "format": "binary",
46
- "encodedBytes": 1197,
47
- "encodeUsPerOp": 6.58,
48
- "decodeUsPerOp": 2.551,
49
- "encodeOpsPerSecond": 151983.004,
50
- "decodeOpsPerSecond": 391961.804
51
- },
52
- {
53
- "profile": "quick",
54
- "payloadBytes": 4096,
55
- "format": "compact-json",
56
- "encodedBytes": 4341,
57
- "encodeUsPerOp": 2.29,
58
- "decodeUsPerOp": 1.706,
59
- "encodeOpsPerSecond": 436690.681,
60
- "decodeOpsPerSecond": 586132.045
61
- },
62
- {
63
- "profile": "quick",
64
- "payloadBytes": 4096,
65
- "format": "binary",
66
- "encodedBytes": 4269,
67
- "encodeUsPerOp": 8.274,
68
- "decodeUsPerOp": 2.81,
69
- "encodeOpsPerSecond": 120859.221,
70
- "decodeOpsPerSecond": 355922.792
71
- },
72
- {
73
- "profile": "quick",
74
- "payloadBytes": 16384,
75
- "format": "compact-json",
76
- "encodedBytes": 16632,
77
- "encodeUsPerOp": 6.953,
78
- "decodeUsPerOp": 3.802,
79
- "encodeOpsPerSecond": 143830.843,
80
- "decodeOpsPerSecond": 263020.978
81
- },
82
- {
83
- "profile": "quick",
84
- "payloadBytes": 16384,
85
- "format": "binary",
86
- "encodedBytes": 16560,
87
- "encodeUsPerOp": 13.34,
88
- "decodeUsPerOp": 3.786,
89
- "encodeOpsPerSecond": 74962.159,
90
- "decodeOpsPerSecond": 264160.181
91
- }
92
- ]
93
- }
package/bin/7h3.ts DELETED
@@ -1,385 +0,0 @@
1
- #!/usr/bin/env node
2
- import { parseArgs } from 'node:util'
3
- import { createServer } from 'node:http'
4
- import { writeFileSync } from 'node:fs'
5
-
6
- const USAGE = `
7
- 7h3 — Aurelion Interaction Protocol CLI (wire version 7h3/0.1)
8
-
9
- Usage:
10
- 7h3 keygen [--output <file>]
11
- 7h3 sign --private-key <key> --sender <id> [--recipient <id>] [--payload <str>] [--ttl <ms>]
12
- 7h3 verify --public-key <key> --envelope <json>
13
- 7h3 inspect --envelope <json>
14
- 7h3 gateway --upstream <url> [--port <n>] [--public-key <key>] [--require ed25519|none]
15
- [--sign-responses] [--private-key <key>] [--sender <id>]
16
- 7h3 keys serve [--public-key <key>] [--key-id <id>] [--port <n>]
17
- 7h3 help
18
-
19
- Commands:
20
- keygen Generate an Ed25519 keypair (PKCS8/SPKI, base64url-encoded)
21
- sign Create and sign an AIP envelope
22
- verify Verify an AIP envelope signature
23
- inspect Pretty-print an AIP envelope fields
24
- gateway Run a verifying HTTP proxy gateway
25
- keys serve Serve a /.well-known/7h3-keys endpoint
26
- help Show this usage table
27
- `
28
-
29
- function die(msg: string): never {
30
- process.stderr.write(`Error: ${msg}\n`)
31
- process.exit(1)
32
- }
33
-
34
- async function cmdKeygen(argv: string[]): Promise<void> {
35
- const { values } = parseArgs({
36
- args: argv,
37
- options: {
38
- output: { type: 'string', short: 'o' },
39
- },
40
- strict: false,
41
- })
42
-
43
- const { generateEd25519KeypairBase64Url } = await import('../src/protocol.js')
44
- const { publicKey, privateKey } = await generateEd25519KeypairBase64Url()
45
-
46
- const result = {
47
- algorithm: 'Ed25519',
48
- wireVersion: '7h3/0.1',
49
- publicKey,
50
- privateKey,
51
- createdAt: new Date().toISOString(),
52
- warning: 'Keep privateKey secret — it grants signing authority over your agent identity.',
53
- }
54
-
55
- const json = JSON.stringify(result, null, 2)
56
-
57
- if (values.output) {
58
- writeFileSync(values.output as string, json, 'utf8')
59
- process.stdout.write(`Keypair written to ${values.output}\n`)
60
- process.stdout.write(` algorithm : Ed25519\n`)
61
- process.stdout.write(` publicKey : ${publicKey}\n`)
62
- process.stdout.write(` createdAt : ${result.createdAt}\n`)
63
- } else {
64
- process.stdout.write(json + '\n')
65
- }
66
- }
67
-
68
- async function cmdSign(argv: string[]): Promise<void> {
69
- const { values } = parseArgs({
70
- args: argv,
71
- options: {
72
- 'private-key': { type: 'string' },
73
- sender: { type: 'string' },
74
- recipient: { type: 'string' },
75
- payload: { type: 'string' },
76
- ttl: { type: 'string' },
77
- },
78
- strict: false,
79
- })
80
-
81
- const privateKey = values['private-key'] as string | undefined
82
- const sender = values['sender'] as string | undefined
83
-
84
- if (!privateKey) die('--private-key is required')
85
- if (!sender) die('--sender is required')
86
-
87
- const { createEnvelope, signEnvelopeEd25519 } = await import('../src/protocol.js')
88
-
89
- const envelope = createEnvelope({
90
- sender: sender!,
91
- recipient: values['recipient'] as string | undefined,
92
- intent: 'PING',
93
- content: (values['payload'] as string | undefined) ?? '',
94
- ttlMs: values['ttl'] ? parseInt(values['ttl'] as string, 10) : 60_000,
95
- })
96
-
97
- const signed = await signEnvelopeEd25519(envelope, privateKey!)
98
- process.stdout.write(JSON.stringify(signed) + '\n')
99
- }
100
-
101
- async function cmdVerify(argv: string[]): Promise<void> {
102
- const { values } = parseArgs({
103
- args: argv,
104
- options: {
105
- 'public-key': { type: 'string' },
106
- envelope: { type: 'string' },
107
- },
108
- strict: false,
109
- })
110
-
111
- const publicKey = values['public-key'] as string | undefined
112
- const envelopeJson = values['envelope'] as string | undefined
113
-
114
- if (!publicKey) die('--public-key is required')
115
- if (!envelopeJson) die('--envelope is required')
116
-
117
- const { validateEnvelope, verifyEnvelopeEd25519 } = await import('../src/protocol.js')
118
-
119
- let envelope: ReturnType<typeof JSON.parse>
120
- try {
121
- envelope = JSON.parse(envelopeJson!)
122
- } catch {
123
- die('--envelope is not valid JSON')
124
- }
125
-
126
- const diagnostics = validateEnvelope(envelope)
127
- const errors = diagnostics.filter(d => d.level === 'error')
128
- const warnings = diagnostics.filter(d => d.level === 'warning')
129
-
130
- if (errors.length > 0) {
131
- process.stdout.write('INVALID — envelope validation errors:\n')
132
- for (const e of errors) process.stdout.write(` [error] ${e.message}\n`)
133
- for (const w of warnings) process.stdout.write(` [warning] ${w.message}\n`)
134
- process.exit(1)
135
- }
136
-
137
- const valid = await verifyEnvelopeEd25519(envelope, publicKey!)
138
-
139
- if (valid) {
140
- process.stdout.write('Signature valid\n')
141
- if (warnings.length > 0) {
142
- for (const w of warnings) process.stdout.write(` [warning] ${w.message}\n`)
143
- }
144
- } else {
145
- process.stdout.write('INVALID — signature verification failed\n')
146
- process.stdout.write(` alg : ${envelope.signature?.alg ?? 'none'}\n`)
147
- process.stdout.write(` keyId : ${envelope.signature?.keyId ?? 'none'}\n`)
148
- process.exit(1)
149
- }
150
- }
151
-
152
- async function cmdInspect(argv: string[]): Promise<void> {
153
- const { values } = parseArgs({
154
- args: argv,
155
- options: {
156
- envelope: { type: 'string' },
157
- },
158
- strict: false,
159
- })
160
-
161
- const envelopeJson = values['envelope'] as string | undefined
162
- if (!envelopeJson) die('--envelope is required')
163
-
164
- let envelope: ReturnType<typeof JSON.parse>
165
- try {
166
- envelope = JSON.parse(envelopeJson!)
167
- } catch {
168
- die('--envelope is not valid JSON')
169
- }
170
-
171
- const h = envelope.header ?? {}
172
- const b = envelope.body ?? {}
173
- const s = envelope.signature
174
-
175
- const nowMs = Date.now()
176
- const expiresMs = (h.timestampMs ?? 0) + (h.ttlMs ?? 0)
177
- const expired = expiresMs < nowMs
178
- const expiresStatus = expired
179
- ? `EXPIRED (${new Date(expiresMs).toISOString()})`
180
- : `OK — expires ${new Date(expiresMs).toISOString()}`
181
-
182
- const content: string = typeof b.content === 'string' ? b.content : ''
183
- const contentPreview = content.length > 80 ? content.slice(0, 77) + '...' : content
184
-
185
- process.stdout.write(`Wire Version : ${h.version ?? '(none)'}\n`)
186
- process.stdout.write(`Message ID : ${h.messageId ?? '(none)'}\n`)
187
- process.stdout.write(`Sender : ${h.sender ?? '(none)'}\n`)
188
- process.stdout.write(`Recipient : ${h.recipient ?? '(none)'}\n`)
189
- process.stdout.write(`Timestamp : ${h.timestampMs ? new Date(h.timestampMs).toISOString() : '(none)'}\n`)
190
- process.stdout.write(`TTL : ${h.ttlMs ?? '(none)'} ms\n`)
191
- process.stdout.write(`Expires : ${expiresStatus}\n`)
192
- process.stdout.write(`Intent : ${b.intent ?? '(none)'}\n`)
193
- process.stdout.write(`Content : ${contentPreview || '(empty)'}\n`)
194
- if (s) {
195
- process.stdout.write(`Sig alg : ${s.alg}\n`)
196
- process.stdout.write(`Sig keyId : ${s.keyId}\n`)
197
- } else {
198
- process.stdout.write(`Signature : (none)\n`)
199
- }
200
- }
201
-
202
- async function cmdGateway(argv: string[]): Promise<void> {
203
- const { values } = parseArgs({
204
- args: argv,
205
- options: {
206
- upstream: { type: 'string' },
207
- port: { type: 'string' },
208
- 'public-key': { type: 'string' },
209
- require: { type: 'string' },
210
- 'sign-responses': { type: 'boolean' },
211
- 'private-key': { type: 'string' },
212
- sender: { type: 'string' },
213
- },
214
- strict: false,
215
- })
216
-
217
- const upstream = values['upstream'] as string | undefined
218
- if (!upstream) die('--upstream is required')
219
-
220
- const port = parseInt((values['port'] as string | undefined) ?? '8080', 10)
221
- const publicKey = values['public-key'] as string | undefined
222
- const requireMode = (values['require'] as string | undefined) ?? (publicKey ? 'ed25519' : 'none')
223
- const signResponses = !!(values['sign-responses'])
224
- const privateKey = values['private-key'] as string | undefined
225
- const sender = values['sender'] as string | undefined
226
-
227
- const { createGateway } = await import('../src/gateway.js')
228
- const { createStaticKeyRegistry } = await import('../src/keyRegistry.js')
229
-
230
- const keys: Record<string, string> = {}
231
- if (publicKey && sender) keys[sender] = publicKey
232
- const keyRegistry = createStaticKeyRegistry(keys)
233
-
234
- const gateway = createGateway({
235
- upstream: upstream!,
236
- keyRegistry,
237
- signResponses: signResponses && !!privateKey,
238
- privateKey,
239
- sender,
240
- defaultPolicy: requireMode === 'none' ? 'allow' : 'deny',
241
- })
242
-
243
- const server = createServer(async (req, res) => {
244
- const chunks: Buffer[] = []
245
- req.on('data', (chunk: Buffer) => chunks.push(chunk))
246
- req.on('end', async () => {
247
- const body = Buffer.concat(chunks)
248
-
249
- // Flatten headers: string | string[] => string
250
- const headers: Record<string, string> = {}
251
- for (const [k, v] of Object.entries(req.headers)) {
252
- if (v === undefined) continue
253
- headers[k] = Array.isArray(v) ? v.join(', ') : v
254
- }
255
-
256
- try {
257
- const result = await gateway.handle({
258
- method: req.method ?? 'GET',
259
- path: req.url ?? '/',
260
- headers,
261
- body: body.length > 0 ? body.toString('utf8') : undefined,
262
- })
263
- res.writeHead(result.status, result.headers)
264
- res.end(result.body)
265
- } catch (err) {
266
- res.writeHead(502, { 'content-type': 'text/plain' })
267
- res.end(`Gateway error: ${String(err)}`)
268
- }
269
- })
270
- })
271
-
272
- server.listen(port, () => {
273
- process.stderr.write(`7h3 gateway listening on port ${port}\n`)
274
- process.stderr.write(` upstream : ${upstream}\n`)
275
- process.stderr.write(` verify mode : ${requireMode}\n`)
276
- process.stderr.write(` sign-responses: ${signResponses && !!privateKey}\n`)
277
- if (sender) process.stderr.write(` sender : ${sender}\n`)
278
- })
279
- }
280
-
281
- async function cmdKeysServe(argv: string[]): Promise<void> {
282
- const { values } = parseArgs({
283
- args: argv,
284
- options: {
285
- 'public-key': { type: 'string' },
286
- 'key-id': { type: 'string' },
287
- port: { type: 'string' },
288
- },
289
- strict: false,
290
- })
291
-
292
- const publicKey = values['public-key'] as string | undefined
293
- const keyId = (values['key-id'] as string | undefined) ?? 'default'
294
- const port = parseInt((values['port'] as string | undefined) ?? '8081', 10)
295
-
296
- const { serveWellKnownKeys } = await import('../src/keyInfra.js')
297
-
298
- const doc = {
299
- version: '7h3/0.1' as const,
300
- updated: Date.now(),
301
- keys: publicKey
302
- ? [
303
- {
304
- id: keyId,
305
- algorithm: 'Ed25519' as const,
306
- publicKey,
307
- created: Date.now(),
308
- },
309
- ]
310
- : [],
311
- }
312
-
313
- const body = serveWellKnownKeys(doc)
314
-
315
- const server = createServer((req, res) => {
316
- if (req.url === '/.well-known/7h3-keys') {
317
- res.writeHead(200, { 'content-type': 'application/json' })
318
- res.end(body)
319
- } else {
320
- res.writeHead(404, { 'content-type': 'text/plain' })
321
- res.end('Not Found')
322
- }
323
- })
324
-
325
- server.listen(port, () => {
326
- process.stderr.write(`7h3 key server listening on port ${port}\n`)
327
- process.stderr.write(` GET /.well-known/7h3-keys\n`)
328
- if (publicKey) process.stderr.write(` key-id: ${keyId}\n`)
329
- else process.stderr.write(` (no keys configured — empty document)\n`)
330
- })
331
- }
332
-
333
- async function main(): Promise<void> {
334
- const args = process.argv.slice(2)
335
- const command = args[0] ?? 'help'
336
- const rest = args.slice(1)
337
-
338
- switch (command) {
339
- case 'keygen':
340
- await cmdKeygen(rest)
341
- break
342
-
343
- case 'sign':
344
- await cmdSign(rest)
345
- break
346
-
347
- case 'verify':
348
- await cmdVerify(rest)
349
- break
350
-
351
- case 'inspect':
352
- await cmdInspect(rest)
353
- break
354
-
355
- case 'gateway':
356
- await cmdGateway(rest)
357
- break
358
-
359
- case 'keys': {
360
- const sub = rest[0]
361
- if (sub === 'serve') {
362
- await cmdKeysServe(rest.slice(1))
363
- } else {
364
- die(`Unknown subcommand 'keys ${sub ?? ''}'. Did you mean 'keys serve'?`)
365
- }
366
- break
367
- }
368
-
369
- case 'help':
370
- case '--help':
371
- case '-h':
372
- process.stdout.write(USAGE)
373
- break
374
-
375
- default:
376
- process.stderr.write(`Unknown command: ${command}\n`)
377
- process.stdout.write(USAGE)
378
- process.exit(1)
379
- }
380
- }
381
-
382
- main().catch(err => {
383
- process.stderr.write(`Fatal: ${String(err)}\n`)
384
- process.exit(1)
385
- })
@@ -1,77 +0,0 @@
1
- {
2
- "version": "7h3/0.1",
3
- "vectors": [
4
- {
5
- "id": "task-with-capability-and-recipient",
6
- "secret": "vector-secret-1",
7
- "keyId": "vector-key-1",
8
- "envelope": {
9
- "header": {
10
- "version": "7h3/0.1",
11
- "messageId": "vec-1",
12
- "timestampMs": 1712500000000,
13
- "ttlMs": 60000,
14
- "sender": "agent.alpha",
15
- "recipient": "agent.beta",
16
- "nonce": "nonce-vec-1"
17
- },
18
- "body": {
19
- "intent": "TASK",
20
- "content": "route:alpha->beta",
21
- "capability": "task.plan",
22
- "correlationId": "corr-1"
23
- }
24
- },
25
- "canonical": "{\"body\":{\"capability\":\"task.plan\",\"content\":\"route:alpha->beta\",\"correlationId\":\"corr-1\",\"intent\":\"TASK\"},\"header\":{\"messageId\":\"vec-1\",\"nonce\":\"nonce-vec-1\",\"recipient\":\"agent.beta\",\"sender\":\"agent.alpha\",\"timestampMs\":1712500000000,\"ttlMs\":60000,\"version\":\"7h3/0.1\"}}",
26
- "signature": "bZP1N1f4w4RGSKw6pfdcA6dQjvpv9nIHAQCttjNCZyI"
27
- },
28
- {
29
- "id": "result-with-minimal-fields",
30
- "secret": "vector-secret-2",
31
- "keyId": "vector-key-2",
32
- "envelope": {
33
- "header": {
34
- "version": "7h3/0.1",
35
- "messageId": "vec-2",
36
- "timestampMs": 1712500005000,
37
- "ttlMs": 30000,
38
- "sender": "memory.agent",
39
- "nonce": "nonce-vec-2"
40
- },
41
- "body": {
42
- "intent": "RESULT",
43
- "content": "memory:ok"
44
- }
45
- },
46
- "canonical": "{\"body\":{\"content\":\"memory:ok\",\"intent\":\"RESULT\"},\"header\":{\"messageId\":\"vec-2\",\"nonce\":\"nonce-vec-2\",\"sender\":\"memory.agent\",\"timestampMs\":1712500005000,\"ttlMs\":30000,\"version\":\"7h3/0.1\"}}",
47
- "signature": "_soWM4GZS8qWZDWyXEeXPaQp7Diyp2SQua9mKy2q0BQ"
48
- }
49
- ],
50
- "ed25519Vectors": [
51
- {
52
- "id": "task-ed25519-with-recipient",
53
- "keyId": "ed-vector-key-1",
54
- "publicKey": "MCowBQYDK2VwAyEA-mUFiTQtcKN4nnD19V_-Wyy4q19OivnAutRUPhOcC78",
55
- "privateKey": "MC4CAQAwBQYDK2VwBCIEICheZbQGuDVb6hezIlcs0QnCHGxz6IhiLkC9M0qr8OOZ",
56
- "envelope": {
57
- "header": {
58
- "version": "7h3/0.1",
59
- "messageId": "vec-ed-1",
60
- "timestampMs": 1712500010000,
61
- "ttlMs": 45000,
62
- "sender": "agent.ed",
63
- "recipient": "agent.verify",
64
- "nonce": "nonce-ed-1"
65
- },
66
- "body": {
67
- "intent": "TASK",
68
- "content": "route:ed25519",
69
- "capability": "task.sign",
70
- "correlationId": "corr-ed-1"
71
- }
72
- },
73
- "canonical": "{\"body\":{\"capability\":\"task.sign\",\"content\":\"route:ed25519\",\"correlationId\":\"corr-ed-1\",\"intent\":\"TASK\"},\"header\":{\"messageId\":\"vec-ed-1\",\"nonce\":\"nonce-ed-1\",\"recipient\":\"agent.verify\",\"sender\":\"agent.ed\",\"timestampMs\":1712500010000,\"ttlMs\":45000,\"version\":\"7h3/0.1\"}}",
74
- "signature": "AAWu-6pp7NQZ-NtWKrgREWlMBx-kMZZzZ5dIiBqOdT-zdr-u4HtS6upE79yX7UUNPYUfyKs7lfssi0EeOvIxAA"
75
- }
76
- ]
77
- }
@@ -1,20 +0,0 @@
1
- {
2
- "generatedAt": "2026-06-28T00:56:52.383Z",
3
- "vectors": [
4
- {
5
- "id": "task-with-capability-and-recipient",
6
- "alg": "HS256",
7
- "binaryHex": "41495042010f0000018eb8f445000000ea60000000073768332f302e31000000057665632d310000000b6167656e742e616c7068610000000b6e6f6e63652d7665632d31000000045441534b00000011726f7574653a616c7068612d3e626574610000000a6167656e742e62657461000000097461736b2e706c616e00000006636f72722d31010000000c766563746f722d6b65792d310000002b625a50314e31663477345247534b773670666463413664516a767076396e494841514374746a4e435a7949"
8
- },
9
- {
10
- "id": "result-with-minimal-fields",
11
- "alg": "HS256",
12
- "binaryHex": "4149504201080000018eb8f4588800007530000000073768332f302e31000000057665632d320000000c6d656d6f72792e6167656e740000000b6e6f6e63652d7665632d3200000006524553554c54000000096d656d6f72793a6f6b010000000c766563746f722d6b65792d320000002b5f736f574d34475a533871575a445779584565585061517037446979703253517561396d4b793271304251"
13
- },
14
- {
15
- "id": "task-ed25519-with-recipient",
16
- "alg": "ED25519",
17
- "binaryHex": "41495042010f0000018eb8f46c100000afc8000000073768332f302e31000000087665632d65642d31000000086167656e742e65640000000a6e6f6e63652d65642d31000000045441534b0000000d726f7574653a656432353531390000000c6167656e742e766572696679000000097461736b2e7369676e00000009636f72722d65642d31020000000f65642d766563746f722d6b65792d3100000056414157752d367070374e515a2d4e74574b72675245576c4d42782d6b4d5a5a7a5a3564496942714f64542d7a64722d753448745336757045373979583755554e50595566794b73376c667373693045654f7649784141"
18
- }
19
- ]
20
- }
@@ -1,20 +0,0 @@
1
- {
2
- "generatedAt": "2026-05-04T04:49:29.647Z",
3
- "vectors": [
4
- {
5
- "id": "task-with-capability-and-recipient",
6
- "alg": "HS256",
7
- "binaryHex": "41495042010f0000018eb8f445000000ea60000000076169702f302e31000000057665632d310000000b6167656e742e616c7068610000000b6e6f6e63652d7665632d31000000045441534b00000011726f7574653a616c7068612d3e626574610000000a6167656e742e62657461000000097461736b2e706c616e00000006636f72722d31010000000c766563746f722d6b65792d310000002b4f6c376c516b5259336c52534961303576686b43795a32336f705973525139416250774670326378324430"
8
- },
9
- {
10
- "id": "result-with-minimal-fields",
11
- "alg": "HS256",
12
- "binaryHex": "4149504201080000018eb8f4588800007530000000076169702f302e31000000057665632d320000000c6d656d6f72792e6167656e740000000b6e6f6e63652d7665632d3200000006524553554c54000000096d656d6f72793a6f6b010000000c766563746f722d6b65792d320000002b5a57775a5045787732646341416c354278507a33313337386d4351352d674768395566587536705a4b646f"
13
- },
14
- {
15
- "id": "task-ed25519-with-recipient",
16
- "alg": "ED25519",
17
- "binaryHex": "41495042010f0000018eb8f46c100000afc8000000076169702f302e31000000087665632d65642d31000000086167656e742e65640000000a6e6f6e63652d65642d31000000045441534b0000000d726f7574653a656432353531390000000c6167656e742e766572696679000000097461736b2e7369676e00000009636f72722d65642d31020000000f65642d766563746f722d6b65792d310000005677787941674e494b6f66344d563478487757697a73623366366b326a574168325a7a7132703967684153456b5f464a4157346774366239317a76327a363344506b73416f485a365135334a64656a486f6150316f4251"
18
- }
19
- ]
20
- }
@@ -1,77 +0,0 @@
1
- # 7h3 Protocol — Docker Compose development stack
2
- # Brings up:
3
- # gateway — verifying AIP proxy (port 8080)
4
- # api — minimal example upstream (port 3000, internal only)
5
- #
6
- # Quick start:
7
- # docker compose up --build
8
-
9
- services:
10
-
11
- # ---------------------------------------------------------------------------
12
- # gateway — 7h3 Protocol verifying HTTP proxy
13
- # ---------------------------------------------------------------------------
14
- gateway:
15
- build:
16
- context: .
17
- dockerfile: Dockerfile
18
- ports:
19
- - "8080:8080"
20
- command:
21
- - "--port"
22
- - "8080"
23
- - "--upstream"
24
- - "http://api:3000"
25
- - "--require"
26
- - "ed25519"
27
- environment:
28
- # Override these at runtime to enable response signing:
29
- # GATEWAY_PRIVATE_KEY=<base64url private key>
30
- # GATEWAY_SENDER=gateway@my-service.example.com
31
- NODE_ENV: production
32
- depends_on:
33
- api:
34
- condition: service_started
35
- restart: unless-stopped
36
- healthcheck:
37
- test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
38
- interval: 30s
39
- timeout: 5s
40
- start_period: 10s
41
- retries: 3
42
-
43
- # ---------------------------------------------------------------------------
44
- # api — minimal example upstream service
45
- #
46
- # This is a self-contained inline Node.js server that demonstrates the
47
- # headers the gateway injects after successful envelope verification:
48
- # x-7h3-sender — verified sender identity from the AIP envelope
49
- # x-7h3-verified — always "true" when the gateway passed the request
50
- #
51
- # Replace this service with your actual application in production.
52
- # ---------------------------------------------------------------------------
53
- api:
54
- image: node:22-alpine
55
- command: >
56
- node -e "
57
- const http = require('http');
58
- const server = http.createServer((req, res) => {
59
- const sender = req.headers['x-7h3-sender'] || null;
60
- const verified = req.headers['x-7h3-verified'] === 'true';
61
- const body = JSON.stringify({
62
- ok: true,
63
- path: req.url,
64
- sender,
65
- verified,
66
- method: req.method,
67
- });
68
- res.writeHead(200, { 'content-type': 'application/json' });
69
- res.end(body);
70
- });
71
- server.listen(3000, () => {
72
- process.stderr.write('example api listening on port 3000\n');
73
- });
74
- "
75
- expose:
76
- - "3000"
77
- restart: unless-stopped