@7h3/protocol 0.1.2 → 0.5.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.
- package/.dockerignore +19 -0
- package/.github/dependabot.yml +32 -0
- package/.github/workflows/ci.yml +31 -0
- package/.github/workflows/publish.yml +59 -0
- package/.github/workflows/scorecard.yml +37 -0
- package/7h3.example.yaml +125 -0
- package/CHANGELOG.md +152 -0
- package/CONTRIBUTING.md +82 -0
- package/Dockerfile +73 -0
- package/GOVERNANCE.md +62 -0
- package/README.md +1317 -6
- package/SECURITY.md +70 -0
- package/bench-results/replay-cache-full-1777891033256.json +10 -0
- package/bench-results/replay-cache-full-1777896317488.json +10 -0
- package/bench-results/replay-cache-full-1777900993184.json +10 -0
- package/bench-results/replay-cache-full-1777901019285.json +10 -0
- package/bench-results/replay-cache-quick-1777870170126.json +10 -0
- package/bench-results/signature-profiles-quick-1775875160079.json +85 -0
- package/bench-results/signature-profiles-quick-1775983539716.json +85 -0
- package/bench-results/signature-profiles-quick-1776237913190.json +85 -0
- package/bench-results/wire-codecs-full-1777891019803.json +93 -0
- package/bench-results/wire-codecs-full-1777896260964.json +93 -0
- package/bench-results/wire-codecs-full-1777901004247.json +93 -0
- package/bench-results/wire-codecs-quick-1775972879056.json +93 -0
- package/bench-results/wire-codecs-quick-1775983541111.json +93 -0
- package/bench-results/wire-codecs-quick-1776237914299.json +93 -0
- package/bench-results/wire-codecs-quick-1777841285236.json +93 -0
- package/bench-results/wire-codecs-quick-1777841321772.json +93 -0
- package/bench-results/wire-codecs-quick-1777841330408.json +93 -0
- package/bench-results/wire-codecs-quick-1777852886082.json +93 -0
- package/bench-results/wire-codecs-quick-1777852988773.json +93 -0
- package/bench-results/wire-codecs-quick-1777870188095.json +93 -0
- package/bench-results/wire-codecs-quick-1777870263918.json +93 -0
- package/bench-results/wire-codecs-quick-1777870455034.json +93 -0
- package/bench-results/wire-codecs-quick-1778816163081.json +93 -0
- package/bench-results/wire-codecs-quick-1778843936130.json +93 -0
- package/bin/7h3.ts +406 -0
- package/conformance/7h3_v0_1.json +77 -0
- package/conformance/7h3_v0_1_binary.json +20 -0
- package/conformance/aip_v0_1_binary.json +20 -0
- package/docker-compose.yaml +77 -0
- package/docs/ADOPTION_PLAN.md +120 -0
- package/docs/AGENTS.md +77 -0
- package/docs/AIP_RFC_v0.1.md +97 -0
- package/docs/AI_DECISION_CARD.md +122 -0
- package/docs/AI_RUNTIME_POLICY.json +126 -0
- package/docs/AI_RUNTIME_POLICY.yaml +110 -0
- package/docs/BACKPRESSURE_TUNING.md +65 -0
- package/docs/BENCHMARK_CLAIM_MATRIX.md +42 -0
- package/docs/BENCHMARK_REPORT_TEMPLATE.md +169 -0
- package/docs/BINARY_CODEC_BENCH.md +23 -0
- package/docs/CLEAN_CLONE_RUNBOOK.md +36 -0
- package/docs/CLOCK_SKEW_POLICY.md +30 -0
- package/docs/DISTRIBUTED_REPLAY.md +142 -0
- package/docs/FUZZ_CAMPAIGN.md +121 -0
- package/docs/GATEWAY.md +195 -0
- package/docs/KEY_MANAGEMENT_POLICY.md +53 -0
- package/docs/KEY_REVOCATION.md +69 -0
- package/docs/MCP_WRAPPER.md +159 -0
- package/docs/MIGRATION_GUIDE.md +40 -0
- package/docs/OPERATORS.md +184 -0
- package/docs/PERF_REGRESSION_POLICY.md +34 -0
- package/docs/PROJECT_EXAMINATION_2026-05-31.md +219 -0
- package/docs/RELEASE_BENCHMARK_REPORT_2026-05-15.md +135 -0
- package/docs/RELEASE_GATE.md +25 -0
- package/docs/RELEASE_NOTES_v0.1.0.md +54 -0
- package/docs/SECURITY_REVIEW_2026-06-05.md +165 -0
- package/docs/TELEMETRY.md +41 -0
- package/docs/THREAT_MODEL.md +89 -0
- package/docs/VERSIONING_POLICY.md +30 -0
- package/docs/assets/banner-github.png +0 -0
- package/docs/assets/banner.png +0 -0
- package/docs/assets/banner.svg +123 -0
- package/eslint.config.js +15 -0
- package/fuzz/ts/harness-decode.ts +136 -0
- package/fuzz/ts/harness-verify.ts +121 -0
- package/fuzz/ts/run.ts +35 -0
- package/mcp-server/README.md +38 -0
- package/mcp-server/package-lock.json +1187 -0
- package/mcp-server/package.json +35 -0
- package/mcp-server/src/index.ts +236 -0
- package/mcp-server/tsconfig.json +14 -0
- package/package.json +121 -13
- package/scripts/aip-framework-quickstart.ts +110 -0
- package/scripts/aip-mcp-gateway.ts +38 -0
- package/scripts/aip-mcp-wrap-demo.ts +72 -0
- package/scripts/aip-quickstart.ts +60 -0
- package/scripts/bench-diff.ts +118 -0
- package/scripts/bench-protocol-e2e.ts +937 -0
- package/scripts/bench-protocol-openloop.ts +1397 -0
- package/scripts/bench-replay-cache.ts +76 -0
- package/scripts/bench-signature-profiles.ts +180 -0
- package/scripts/bench-wire-codecs.ts +161 -0
- package/scripts/build-binary-conformance.ts +36 -0
- package/scripts/build-release-dashboard.ts +175 -0
- package/scripts/canary-rollout.ts +38 -0
- package/scripts/mcpGatewayCli.test.ts +116 -0
- package/scripts/prepare-aip-package.ts +88 -0
- package/scripts/regen-conformance-sigs.ts +18 -0
- package/scripts/release-gate.ts +19 -0
- package/scripts/validate-runtime-policy.ts +18 -0
- package/sdk/browser/index.test.ts +162 -0
- package/sdk/browser/index.ts +257 -0
- package/sdk/browser/package.json +13 -0
- package/sdk/go/cbor.go +551 -0
- package/sdk/go/cbor_test.go +232 -0
- package/sdk/go/encryption.go +280 -0
- package/sdk/go/encryption_test.go +318 -0
- package/sdk/go/go.mod +7 -0
- package/sdk/go/go.sum +4 -0
- package/sdk/go/http.go +135 -0
- package/sdk/go/protocol.go +324 -0
- package/sdk/go/protocol_test.go +334 -0
- package/sdk/go/replay.go +121 -0
- package/sdk/go/replay_test.go +149 -0
- package/sdk/go/webhook.go +136 -0
- package/sdk/pq/package-lock.json +1358 -0
- package/sdk/pq/package.json +42 -0
- package/sdk/pq/src/index.test.ts +143 -0
- package/sdk/pq/src/index.ts +166 -0
- package/sdk/pq/tsconfig.json +14 -0
- package/sdk/pq/vitest.config.ts +7 -0
- package/sdk/python/README.md +18 -0
- package/sdk/python/protocol_7h3/__init__.py +46 -0
- package/sdk/python/protocol_7h3/encryption.py +252 -0
- package/sdk/python/protocol_7h3/http.py +212 -0
- package/sdk/python/protocol_7h3/keys.py +149 -0
- package/sdk/python/protocol_7h3/pq.py +244 -0
- package/sdk/python/protocol_7h3/protocol.py +525 -0
- package/sdk/python/protocol_7h3/queue.py +118 -0
- package/sdk/python/protocol_7h3/replay.py +98 -0
- package/sdk/python/protocol_7h3/webhook.py +116 -0
- package/sdk/python/pyproject.toml +40 -0
- package/sdk/python/tests/test_conformance.py +110 -0
- package/sdk/python/tests/test_encryption.py +206 -0
- package/sdk/python/tests/test_http.py +305 -0
- package/sdk/python/tests/test_keys.py +417 -0
- package/sdk/python/tests/test_queue.py +120 -0
- package/sdk/python/tests/test_webhook.py +345 -0
- package/sdk/rust/Cargo.lock +371 -0
- package/sdk/rust/Cargo.toml +25 -0
- package/sdk/rust/README.md +31 -0
- package/sdk/rust/fuzz/Cargo.toml +29 -0
- package/sdk/rust/fuzz/fuzz_targets/fuzz_canonicalize.rs +46 -0
- package/sdk/rust/fuzz/fuzz_targets/fuzz_decode.rs +11 -0
- package/sdk/rust/src/bin/aip_mcp_gateway.rs +59 -0
- package/sdk/rust/src/http.rs +145 -0
- package/sdk/rust/src/keys.rs +161 -0
- package/sdk/rust/src/lib.rs +688 -0
- package/sdk/rust/src/queue.rs +79 -0
- package/sdk/rust/src/webhook.rs +86 -0
- package/sdk/rust/tests/conformance.rs +148 -0
- package/sdk/rust/tests/gateway.rs +130 -0
- package/sdk/rust/tests/http_webhook_queue.rs +201 -0
- package/sdk/rust/tests/keys.rs +189 -0
- package/sdk/threshold/index.d.ts +68 -0
- package/sdk/threshold/index.d.ts.map +1 -0
- package/sdk/threshold/index.js +254 -0
- package/sdk/threshold/package-lock.json +1361 -0
- package/sdk/threshold/package.json +39 -0
- package/sdk/threshold/src/index.d.ts +68 -0
- package/sdk/threshold/src/index.d.ts.map +1 -0
- package/sdk/threshold/src/index.js +254 -0
- package/sdk/threshold/src/index.test.ts +238 -0
- package/sdk/threshold/src/index.ts +355 -0
- package/sdk/threshold/tsconfig.json +19 -0
- package/sdk/threshold/vitest.config.ts +12 -0
- package/src/agentAdapter.test.ts +48 -0
- package/src/agentAdapter.ts +56 -0
- package/src/auditLog.test.ts +145 -0
- package/src/auditLog.ts +147 -0
- package/src/capability.test.ts +504 -0
- package/src/capability.ts +380 -0
- package/src/cborCodec.test.ts +263 -0
- package/src/cborCodec.ts +339 -0
- package/src/conformance.test.ts +136 -0
- package/src/conformanceVectors.ts +99 -0
- package/src/encryption.test.ts +206 -0
- package/src/encryption.ts +245 -0
- package/src/envelopeCbor.ts +140 -0
- package/src/frameworkAdapters.test.ts +290 -0
- package/src/frameworkAdapters.ts +261 -0
- package/src/gateway.test.ts +343 -0
- package/src/gateway.ts +246 -0
- package/src/grpcBinding.test.ts +211 -0
- package/src/grpcBinding.ts +103 -0
- package/src/httpBinding.test.ts +376 -0
- package/src/httpBinding.ts +189 -0
- package/src/index.ts +39 -0
- package/src/keyInfra.test.ts +278 -0
- package/src/keyInfra.ts +228 -0
- package/src/keyRegistry.ts +59 -0
- package/src/keyRotation.test.ts +78 -0
- package/src/keyRotation.ts +72 -0
- package/src/mcpGateway.test.ts +129 -0
- package/src/mcpGateway.ts +250 -0
- package/src/mcpTransports.test.ts +92 -0
- package/src/mcpTransports.ts +169 -0
- package/src/mcpWrapper.test.ts +179 -0
- package/src/mcpWrapper.ts +206 -0
- package/src/otel.ts +136 -0
- package/src/policyEnforcer.test.ts +99 -0
- package/src/policyEnforcer.ts +169 -0
- package/src/policyTelemetryFeedback.test.ts +25 -0
- package/src/policyTelemetryFeedback.ts +38 -0
- package/src/protocol.bench.ts +37 -0
- package/{protocol.d.ts → src/protocol.d.ts} +2 -1
- package/src/protocol.d.ts.map +1 -0
- package/src/protocol.js +294 -0
- package/src/protocol.test.ts +155 -0
- package/src/protocol.ts +414 -0
- package/src/protocolAgent.test.ts +105 -0
- package/src/protocolAgent.ts +169 -0
- package/src/protocolBinary.test.ts +165 -0
- package/src/protocolBinary.ts +312 -0
- package/src/protocolCapabilities.ts +70 -0
- package/src/protocolFuzz.advanced.test.ts +235 -0
- package/src/protocolFuzz.test.ts +111 -0
- package/src/protocolNegative.test.ts +97 -0
- package/src/protocolReplay.test.ts +71 -0
- package/src/protocolReplay.ts +194 -0
- package/src/protocolTransport.test.ts +556 -0
- package/src/protocolTransport.ts +483 -0
- package/src/queueBinding.test.ts +130 -0
- package/src/queueBinding.ts +102 -0
- package/src/rateLimiter.test.ts +96 -0
- package/src/rateLimiter.ts +46 -0
- package/src/redisClient.ts +140 -0
- package/src/redisIntegration.test.ts +134 -0
- package/src/replayStores.test.ts +273 -0
- package/src/replayStores.ts +215 -0
- package/src/revocation.test.ts +98 -0
- package/src/revocation.ts +0 -0
- package/src/routePolicy.test.ts +87 -0
- package/src/routePolicy.ts +72 -0
- package/src/runtimePolicy.test.ts +49 -0
- package/src/runtimePolicy.ts +81 -0
- package/src/runtimePolicyManager.test.ts +29 -0
- package/src/runtimePolicyManager.ts +50 -0
- package/src/runtimePolicyPresets.ts +43 -0
- package/src/signedResponse.test.ts +111 -0
- package/src/signedResponse.ts +83 -0
- package/src/stream.test.ts +254 -0
- package/src/stream.ts +417 -0
- package/src/telemetry.test.ts +251 -0
- package/src/telemetry.ts +299 -0
- package/src/webhookBinding.test.ts +144 -0
- package/src/webhookBinding.ts +115 -0
- package/src/wsBinding.test.ts +221 -0
- package/src/wsBinding.ts +200 -0
- package/tsconfig.json +15 -0
- package/tsconfig.lib.json +23 -0
- package/vite.lib.config.ts +16 -0
- package/vitest.config.ts +11 -0
- package/agentAdapter.d.ts +0 -26
- package/conformanceVectors.d.ts +0 -20
- package/frameworkAdapters.d.ts +0 -72
- package/index.d.ts +0 -20
- package/index.js +0 -1702
- package/keyRotation.d.ts +0 -20
- package/mcpGateway.d.ts +0 -37
- package/mcpTransports.d.ts +0 -62
- package/mcpWrapper.d.ts +0 -83
- package/policyEnforcer.d.ts +0 -50
- package/policyTelemetryFeedback.d.ts +0 -11
- package/protocolAgent.d.ts +0 -58
- package/protocolBinary.d.ts +0 -8
- package/protocolCapabilities.d.ts +0 -24
- package/protocolReplay.d.ts +0 -35
- package/protocolTransport.d.ts +0 -73
- package/redisClient.d.ts +0 -49
- package/replayStores.d.ts +0 -32
- package/revocation.d.ts +0 -71
- package/runtimePolicy.d.ts +0 -24
- package/runtimePolicyManager.d.ts +0 -15
- package/runtimePolicyPresets.d.ts +0 -11
package/bin/7h3.ts
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
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>] [--metrics-port <n>]
|
|
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
|
+
'metrics-port': { type: 'string' },
|
|
214
|
+
},
|
|
215
|
+
strict: false,
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
const upstream = values['upstream'] as string | undefined
|
|
219
|
+
if (!upstream) die('--upstream is required')
|
|
220
|
+
|
|
221
|
+
const port = parseInt((values['port'] as string | undefined) ?? '8080', 10)
|
|
222
|
+
const publicKey = values['public-key'] as string | undefined
|
|
223
|
+
const requireMode = (values['require'] as string | undefined) ?? (publicKey ? 'ed25519' : 'none')
|
|
224
|
+
const signResponses = !!(values['sign-responses'])
|
|
225
|
+
const privateKey = values['private-key'] as string | undefined
|
|
226
|
+
const sender = values['sender'] as string | undefined
|
|
227
|
+
const metricsPortRaw = values['metrics-port'] as string | undefined
|
|
228
|
+
const metricsPort = metricsPortRaw ? parseInt(metricsPortRaw, 10) : undefined
|
|
229
|
+
|
|
230
|
+
const { createGateway } = await import('../src/gateway.js')
|
|
231
|
+
const { createStaticKeyRegistry } = await import('../src/keyRegistry.js')
|
|
232
|
+
|
|
233
|
+
const keys: Record<string, string> = {}
|
|
234
|
+
if (publicKey && sender) keys[sender] = publicKey
|
|
235
|
+
const keyRegistry = createStaticKeyRegistry(keys)
|
|
236
|
+
|
|
237
|
+
const gateway = createGateway({
|
|
238
|
+
upstream: upstream!,
|
|
239
|
+
keyRegistry,
|
|
240
|
+
signResponses: signResponses && !!privateKey,
|
|
241
|
+
privateKey,
|
|
242
|
+
sender,
|
|
243
|
+
defaultPolicy: requireMode === 'none' ? 'allow' : 'deny',
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
const server = createServer(async (req, res) => {
|
|
247
|
+
const chunks: Buffer[] = []
|
|
248
|
+
req.on('data', (chunk: Buffer) => chunks.push(chunk))
|
|
249
|
+
req.on('end', async () => {
|
|
250
|
+
const body = Buffer.concat(chunks)
|
|
251
|
+
|
|
252
|
+
// Flatten headers: string | string[] => string
|
|
253
|
+
const headers: Record<string, string> = {}
|
|
254
|
+
for (const [k, v] of Object.entries(req.headers)) {
|
|
255
|
+
if (v === undefined) continue
|
|
256
|
+
headers[k] = Array.isArray(v) ? v.join(', ') : v
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
const result = await gateway.handle({
|
|
261
|
+
method: req.method ?? 'GET',
|
|
262
|
+
path: req.url ?? '/',
|
|
263
|
+
headers,
|
|
264
|
+
body: body.length > 0 ? body.toString('utf8') : undefined,
|
|
265
|
+
})
|
|
266
|
+
res.writeHead(result.status, result.headers)
|
|
267
|
+
res.end(result.body)
|
|
268
|
+
} catch (err) {
|
|
269
|
+
res.writeHead(502, { 'content-type': 'text/plain' })
|
|
270
|
+
res.end(`Gateway error: ${String(err)}`)
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
server.listen(port, () => {
|
|
276
|
+
process.stderr.write(`7h3 gateway listening on port ${port}\n`)
|
|
277
|
+
process.stderr.write(` upstream : ${upstream}\n`)
|
|
278
|
+
process.stderr.write(` verify mode : ${requireMode}\n`)
|
|
279
|
+
process.stderr.write(` sign-responses: ${signResponses && !!privateKey}\n`)
|
|
280
|
+
if (sender) process.stderr.write(` sender : ${sender}\n`)
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
// Optional: dedicated metrics server
|
|
284
|
+
if (metricsPort !== undefined) {
|
|
285
|
+
const { metrics: globalMetrics, renderPrometheusText } = await import('../src/telemetry.js')
|
|
286
|
+
const metricsServer = createServer((req, res) => {
|
|
287
|
+
if (req.url === '/metrics' && req.method === 'GET') {
|
|
288
|
+
const body = renderPrometheusText(globalMetrics)
|
|
289
|
+
res.writeHead(200, { 'content-type': 'text/plain; version=0.0.4; charset=utf-8' })
|
|
290
|
+
res.end(body)
|
|
291
|
+
} else {
|
|
292
|
+
res.writeHead(404, { 'content-type': 'text/plain' })
|
|
293
|
+
res.end('Not Found')
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
metricsServer.listen(metricsPort, () => {
|
|
297
|
+
process.stderr.write(`7h3 metrics listening on :${metricsPort}/metrics\n`)
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async function cmdKeysServe(argv: string[]): Promise<void> {
|
|
303
|
+
const { values } = parseArgs({
|
|
304
|
+
args: argv,
|
|
305
|
+
options: {
|
|
306
|
+
'public-key': { type: 'string' },
|
|
307
|
+
'key-id': { type: 'string' },
|
|
308
|
+
port: { type: 'string' },
|
|
309
|
+
},
|
|
310
|
+
strict: false,
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
const publicKey = values['public-key'] as string | undefined
|
|
314
|
+
const keyId = (values['key-id'] as string | undefined) ?? 'default'
|
|
315
|
+
const port = parseInt((values['port'] as string | undefined) ?? '8081', 10)
|
|
316
|
+
|
|
317
|
+
const { serveWellKnownKeys } = await import('../src/keyInfra.js')
|
|
318
|
+
|
|
319
|
+
const doc = {
|
|
320
|
+
version: '7h3/0.1' as const,
|
|
321
|
+
updated: Date.now(),
|
|
322
|
+
keys: publicKey
|
|
323
|
+
? [
|
|
324
|
+
{
|
|
325
|
+
id: keyId,
|
|
326
|
+
algorithm: 'Ed25519' as const,
|
|
327
|
+
publicKey,
|
|
328
|
+
created: Date.now(),
|
|
329
|
+
},
|
|
330
|
+
]
|
|
331
|
+
: [],
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const body = serveWellKnownKeys(doc)
|
|
335
|
+
|
|
336
|
+
const server = createServer((req, res) => {
|
|
337
|
+
if (req.url === '/.well-known/7h3-keys') {
|
|
338
|
+
res.writeHead(200, { 'content-type': 'application/json' })
|
|
339
|
+
res.end(body)
|
|
340
|
+
} else {
|
|
341
|
+
res.writeHead(404, { 'content-type': 'text/plain' })
|
|
342
|
+
res.end('Not Found')
|
|
343
|
+
}
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
server.listen(port, () => {
|
|
347
|
+
process.stderr.write(`7h3 key server listening on port ${port}\n`)
|
|
348
|
+
process.stderr.write(` GET /.well-known/7h3-keys\n`)
|
|
349
|
+
if (publicKey) process.stderr.write(` key-id: ${keyId}\n`)
|
|
350
|
+
else process.stderr.write(` (no keys configured — empty document)\n`)
|
|
351
|
+
})
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async function main(): Promise<void> {
|
|
355
|
+
const args = process.argv.slice(2)
|
|
356
|
+
const command = args[0] ?? 'help'
|
|
357
|
+
const rest = args.slice(1)
|
|
358
|
+
|
|
359
|
+
switch (command) {
|
|
360
|
+
case 'keygen':
|
|
361
|
+
await cmdKeygen(rest)
|
|
362
|
+
break
|
|
363
|
+
|
|
364
|
+
case 'sign':
|
|
365
|
+
await cmdSign(rest)
|
|
366
|
+
break
|
|
367
|
+
|
|
368
|
+
case 'verify':
|
|
369
|
+
await cmdVerify(rest)
|
|
370
|
+
break
|
|
371
|
+
|
|
372
|
+
case 'inspect':
|
|
373
|
+
await cmdInspect(rest)
|
|
374
|
+
break
|
|
375
|
+
|
|
376
|
+
case 'gateway':
|
|
377
|
+
await cmdGateway(rest)
|
|
378
|
+
break
|
|
379
|
+
|
|
380
|
+
case 'keys': {
|
|
381
|
+
const sub = rest[0]
|
|
382
|
+
if (sub === 'serve') {
|
|
383
|
+
await cmdKeysServe(rest.slice(1))
|
|
384
|
+
} else {
|
|
385
|
+
die(`Unknown subcommand 'keys ${sub ?? ''}'. Did you mean 'keys serve'?`)
|
|
386
|
+
}
|
|
387
|
+
break
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
case 'help':
|
|
391
|
+
case '--help':
|
|
392
|
+
case '-h':
|
|
393
|
+
process.stdout.write(USAGE)
|
|
394
|
+
break
|
|
395
|
+
|
|
396
|
+
default:
|
|
397
|
+
process.stderr.write(`Unknown command: ${command}\n`)
|
|
398
|
+
process.stdout.write(USAGE)
|
|
399
|
+
process.exit(1)
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
main().catch(err => {
|
|
404
|
+
process.stderr.write(`Fatal: ${String(err)}\n`)
|
|
405
|
+
process.exit(1)
|
|
406
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|