@7h3/protocol 0.5.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.
- package/README.md +6 -1317
- package/agentAdapter.d.ts +26 -0
- package/auditLog.d.ts +54 -0
- package/capability.d.ts +67 -0
- package/cborCodec.d.ts +34 -0
- package/conformanceVectors.d.ts +20 -0
- package/encryption.d.ts +85 -0
- package/envelopeCbor.d.ts +33 -0
- package/frameworkAdapters.d.ts +72 -0
- package/gateway.d.ts +53 -0
- package/grpcBinding.d.ts +29 -0
- package/httpBinding.d.ts +50 -0
- package/index.d.ts +39 -0
- package/index.js +3662 -0
- package/keyInfra.d.ts +64 -0
- package/keyRegistry.d.ts +9 -0
- package/keyRotation.d.ts +20 -0
- package/mcpGateway.d.ts +37 -0
- package/mcpTransports.d.ts +62 -0
- package/mcpWrapper.d.ts +83 -0
- package/otel.d.ts +65 -0
- package/package.json +13 -121
- package/policyEnforcer.d.ts +50 -0
- package/policyTelemetryFeedback.d.ts +11 -0
- package/{src/protocol.d.ts → protocol.d.ts} +1 -2
- package/protocolAgent.d.ts +58 -0
- package/protocolBinary.d.ts +8 -0
- package/protocolCapabilities.d.ts +24 -0
- package/protocolReplay.d.ts +35 -0
- package/protocolTransport.d.ts +73 -0
- package/queueBinding.d.ts +43 -0
- package/rateLimiter.d.ts +18 -0
- package/{src/redisClient.ts → redisClient.d.ts} +25 -75
- package/replayStores.d.ts +98 -0
- package/revocation.d.ts +71 -0
- package/routePolicy.d.ts +30 -0
- package/runtimePolicy.d.ts +24 -0
- package/runtimePolicyManager.d.ts +15 -0
- package/runtimePolicyPresets.d.ts +11 -0
- package/signedResponse.d.ts +21 -0
- package/stream.d.ts +59 -0
- package/telemetry.d.ts +79 -0
- package/webhookBinding.d.ts +30 -0
- package/wsBinding.d.ts +52 -0
- package/.dockerignore +0 -19
- package/.github/dependabot.yml +0 -32
- package/.github/workflows/ci.yml +0 -31
- package/.github/workflows/publish.yml +0 -59
- package/.github/workflows/scorecard.yml +0 -37
- package/7h3.example.yaml +0 -125
- package/CHANGELOG.md +0 -152
- package/CONTRIBUTING.md +0 -82
- package/Dockerfile +0 -73
- package/GOVERNANCE.md +0 -62
- package/SECURITY.md +0 -70
- package/bench-results/replay-cache-full-1777891033256.json +0 -10
- package/bench-results/replay-cache-full-1777896317488.json +0 -10
- package/bench-results/replay-cache-full-1777900993184.json +0 -10
- package/bench-results/replay-cache-full-1777901019285.json +0 -10
- package/bench-results/replay-cache-quick-1777870170126.json +0 -10
- package/bench-results/signature-profiles-quick-1775875160079.json +0 -85
- package/bench-results/signature-profiles-quick-1775983539716.json +0 -85
- package/bench-results/signature-profiles-quick-1776237913190.json +0 -85
- package/bench-results/wire-codecs-full-1777891019803.json +0 -93
- package/bench-results/wire-codecs-full-1777896260964.json +0 -93
- package/bench-results/wire-codecs-full-1777901004247.json +0 -93
- package/bench-results/wire-codecs-quick-1775972879056.json +0 -93
- package/bench-results/wire-codecs-quick-1775983541111.json +0 -93
- package/bench-results/wire-codecs-quick-1776237914299.json +0 -93
- package/bench-results/wire-codecs-quick-1777841285236.json +0 -93
- package/bench-results/wire-codecs-quick-1777841321772.json +0 -93
- package/bench-results/wire-codecs-quick-1777841330408.json +0 -93
- package/bench-results/wire-codecs-quick-1777852886082.json +0 -93
- package/bench-results/wire-codecs-quick-1777852988773.json +0 -93
- package/bench-results/wire-codecs-quick-1777870188095.json +0 -93
- package/bench-results/wire-codecs-quick-1777870263918.json +0 -93
- package/bench-results/wire-codecs-quick-1777870455034.json +0 -93
- package/bench-results/wire-codecs-quick-1778816163081.json +0 -93
- package/bench-results/wire-codecs-quick-1778843936130.json +0 -93
- package/bin/7h3.ts +0 -406
- package/conformance/7h3_v0_1.json +0 -77
- package/conformance/7h3_v0_1_binary.json +0 -20
- package/conformance/aip_v0_1_binary.json +0 -20
- package/docker-compose.yaml +0 -77
- package/docs/ADOPTION_PLAN.md +0 -120
- package/docs/AGENTS.md +0 -77
- package/docs/AIP_RFC_v0.1.md +0 -97
- package/docs/AI_DECISION_CARD.md +0 -122
- package/docs/AI_RUNTIME_POLICY.json +0 -126
- package/docs/AI_RUNTIME_POLICY.yaml +0 -110
- package/docs/BACKPRESSURE_TUNING.md +0 -65
- package/docs/BENCHMARK_CLAIM_MATRIX.md +0 -42
- package/docs/BENCHMARK_REPORT_TEMPLATE.md +0 -169
- package/docs/BINARY_CODEC_BENCH.md +0 -23
- package/docs/CLEAN_CLONE_RUNBOOK.md +0 -36
- package/docs/CLOCK_SKEW_POLICY.md +0 -30
- package/docs/DISTRIBUTED_REPLAY.md +0 -142
- package/docs/FUZZ_CAMPAIGN.md +0 -121
- package/docs/GATEWAY.md +0 -195
- package/docs/KEY_MANAGEMENT_POLICY.md +0 -53
- package/docs/KEY_REVOCATION.md +0 -69
- package/docs/MCP_WRAPPER.md +0 -159
- package/docs/MIGRATION_GUIDE.md +0 -40
- package/docs/OPERATORS.md +0 -184
- package/docs/PERF_REGRESSION_POLICY.md +0 -34
- package/docs/PROJECT_EXAMINATION_2026-05-31.md +0 -219
- package/docs/RELEASE_BENCHMARK_REPORT_2026-05-15.md +0 -135
- package/docs/RELEASE_GATE.md +0 -25
- package/docs/RELEASE_NOTES_v0.1.0.md +0 -54
- package/docs/SECURITY_REVIEW_2026-06-05.md +0 -165
- package/docs/TELEMETRY.md +0 -41
- package/docs/THREAT_MODEL.md +0 -89
- package/docs/VERSIONING_POLICY.md +0 -30
- package/docs/assets/banner-github.png +0 -0
- package/docs/assets/banner.png +0 -0
- package/docs/assets/banner.svg +0 -123
- package/eslint.config.js +0 -15
- package/fuzz/ts/harness-decode.ts +0 -136
- package/fuzz/ts/harness-verify.ts +0 -121
- package/fuzz/ts/run.ts +0 -35
- package/mcp-server/README.md +0 -38
- package/mcp-server/package-lock.json +0 -1187
- package/mcp-server/package.json +0 -35
- package/mcp-server/src/index.ts +0 -236
- package/mcp-server/tsconfig.json +0 -14
- package/scripts/aip-framework-quickstart.ts +0 -110
- package/scripts/aip-mcp-gateway.ts +0 -38
- package/scripts/aip-mcp-wrap-demo.ts +0 -72
- package/scripts/aip-quickstart.ts +0 -60
- package/scripts/bench-diff.ts +0 -118
- package/scripts/bench-protocol-e2e.ts +0 -937
- package/scripts/bench-protocol-openloop.ts +0 -1397
- package/scripts/bench-replay-cache.ts +0 -76
- package/scripts/bench-signature-profiles.ts +0 -180
- package/scripts/bench-wire-codecs.ts +0 -161
- package/scripts/build-binary-conformance.ts +0 -36
- package/scripts/build-release-dashboard.ts +0 -175
- package/scripts/canary-rollout.ts +0 -38
- package/scripts/mcpGatewayCli.test.ts +0 -116
- package/scripts/prepare-aip-package.ts +0 -88
- package/scripts/regen-conformance-sigs.ts +0 -18
- package/scripts/release-gate.ts +0 -19
- package/scripts/validate-runtime-policy.ts +0 -18
- package/sdk/browser/index.test.ts +0 -162
- package/sdk/browser/index.ts +0 -257
- package/sdk/browser/package.json +0 -13
- package/sdk/go/cbor.go +0 -551
- package/sdk/go/cbor_test.go +0 -232
- package/sdk/go/encryption.go +0 -280
- package/sdk/go/encryption_test.go +0 -318
- package/sdk/go/go.mod +0 -7
- package/sdk/go/go.sum +0 -4
- package/sdk/go/http.go +0 -135
- package/sdk/go/protocol.go +0 -324
- package/sdk/go/protocol_test.go +0 -334
- package/sdk/go/replay.go +0 -121
- package/sdk/go/replay_test.go +0 -149
- package/sdk/go/webhook.go +0 -136
- package/sdk/pq/package-lock.json +0 -1358
- package/sdk/pq/package.json +0 -42
- package/sdk/pq/src/index.test.ts +0 -143
- package/sdk/pq/src/index.ts +0 -166
- package/sdk/pq/tsconfig.json +0 -14
- package/sdk/pq/vitest.config.ts +0 -7
- package/sdk/python/README.md +0 -18
- package/sdk/python/protocol_7h3/__init__.py +0 -46
- package/sdk/python/protocol_7h3/encryption.py +0 -252
- package/sdk/python/protocol_7h3/http.py +0 -212
- package/sdk/python/protocol_7h3/keys.py +0 -149
- package/sdk/python/protocol_7h3/pq.py +0 -244
- package/sdk/python/protocol_7h3/protocol.py +0 -525
- package/sdk/python/protocol_7h3/queue.py +0 -118
- package/sdk/python/protocol_7h3/replay.py +0 -98
- package/sdk/python/protocol_7h3/webhook.py +0 -116
- package/sdk/python/pyproject.toml +0 -40
- package/sdk/python/tests/test_conformance.py +0 -110
- package/sdk/python/tests/test_encryption.py +0 -206
- package/sdk/python/tests/test_http.py +0 -305
- package/sdk/python/tests/test_keys.py +0 -417
- package/sdk/python/tests/test_queue.py +0 -120
- package/sdk/python/tests/test_webhook.py +0 -345
- package/sdk/rust/Cargo.lock +0 -371
- package/sdk/rust/Cargo.toml +0 -25
- package/sdk/rust/README.md +0 -31
- package/sdk/rust/fuzz/Cargo.toml +0 -29
- package/sdk/rust/fuzz/fuzz_targets/fuzz_canonicalize.rs +0 -46
- package/sdk/rust/fuzz/fuzz_targets/fuzz_decode.rs +0 -11
- package/sdk/rust/src/bin/aip_mcp_gateway.rs +0 -59
- package/sdk/rust/src/http.rs +0 -145
- package/sdk/rust/src/keys.rs +0 -161
- package/sdk/rust/src/lib.rs +0 -688
- package/sdk/rust/src/queue.rs +0 -79
- package/sdk/rust/src/webhook.rs +0 -86
- package/sdk/rust/tests/conformance.rs +0 -148
- package/sdk/rust/tests/gateway.rs +0 -130
- package/sdk/rust/tests/http_webhook_queue.rs +0 -201
- package/sdk/rust/tests/keys.rs +0 -189
- package/sdk/threshold/index.d.ts +0 -68
- package/sdk/threshold/index.d.ts.map +0 -1
- package/sdk/threshold/index.js +0 -254
- package/sdk/threshold/package-lock.json +0 -1361
- package/sdk/threshold/package.json +0 -39
- package/sdk/threshold/src/index.d.ts +0 -68
- package/sdk/threshold/src/index.d.ts.map +0 -1
- package/sdk/threshold/src/index.js +0 -254
- package/sdk/threshold/src/index.test.ts +0 -238
- package/sdk/threshold/src/index.ts +0 -355
- package/sdk/threshold/tsconfig.json +0 -19
- package/sdk/threshold/vitest.config.ts +0 -12
- package/src/agentAdapter.test.ts +0 -48
- package/src/agentAdapter.ts +0 -56
- package/src/auditLog.test.ts +0 -145
- package/src/auditLog.ts +0 -147
- package/src/capability.test.ts +0 -504
- package/src/capability.ts +0 -380
- package/src/cborCodec.test.ts +0 -263
- package/src/cborCodec.ts +0 -339
- package/src/conformance.test.ts +0 -136
- package/src/conformanceVectors.ts +0 -99
- package/src/encryption.test.ts +0 -206
- package/src/encryption.ts +0 -245
- package/src/envelopeCbor.ts +0 -140
- package/src/frameworkAdapters.test.ts +0 -290
- package/src/frameworkAdapters.ts +0 -261
- package/src/gateway.test.ts +0 -343
- package/src/gateway.ts +0 -246
- package/src/grpcBinding.test.ts +0 -211
- package/src/grpcBinding.ts +0 -103
- package/src/httpBinding.test.ts +0 -376
- package/src/httpBinding.ts +0 -189
- package/src/index.ts +0 -39
- package/src/keyInfra.test.ts +0 -278
- package/src/keyInfra.ts +0 -228
- package/src/keyRegistry.ts +0 -59
- package/src/keyRotation.test.ts +0 -78
- package/src/keyRotation.ts +0 -72
- package/src/mcpGateway.test.ts +0 -129
- package/src/mcpGateway.ts +0 -250
- package/src/mcpTransports.test.ts +0 -92
- package/src/mcpTransports.ts +0 -169
- package/src/mcpWrapper.test.ts +0 -179
- package/src/mcpWrapper.ts +0 -206
- package/src/otel.ts +0 -136
- package/src/policyEnforcer.test.ts +0 -99
- package/src/policyEnforcer.ts +0 -169
- package/src/policyTelemetryFeedback.test.ts +0 -25
- package/src/policyTelemetryFeedback.ts +0 -38
- package/src/protocol.bench.ts +0 -37
- package/src/protocol.d.ts.map +0 -1
- package/src/protocol.js +0 -294
- package/src/protocol.test.ts +0 -155
- package/src/protocol.ts +0 -414
- package/src/protocolAgent.test.ts +0 -105
- package/src/protocolAgent.ts +0 -169
- package/src/protocolBinary.test.ts +0 -165
- package/src/protocolBinary.ts +0 -312
- package/src/protocolCapabilities.ts +0 -70
- package/src/protocolFuzz.advanced.test.ts +0 -235
- package/src/protocolFuzz.test.ts +0 -111
- package/src/protocolNegative.test.ts +0 -97
- package/src/protocolReplay.test.ts +0 -71
- package/src/protocolReplay.ts +0 -194
- package/src/protocolTransport.test.ts +0 -556
- package/src/protocolTransport.ts +0 -483
- package/src/queueBinding.test.ts +0 -130
- package/src/queueBinding.ts +0 -102
- package/src/rateLimiter.test.ts +0 -96
- package/src/rateLimiter.ts +0 -46
- package/src/redisIntegration.test.ts +0 -134
- package/src/replayStores.test.ts +0 -273
- package/src/replayStores.ts +0 -215
- package/src/revocation.test.ts +0 -98
- package/src/revocation.ts +0 -0
- package/src/routePolicy.test.ts +0 -87
- package/src/routePolicy.ts +0 -72
- package/src/runtimePolicy.test.ts +0 -49
- package/src/runtimePolicy.ts +0 -81
- package/src/runtimePolicyManager.test.ts +0 -29
- package/src/runtimePolicyManager.ts +0 -50
- package/src/runtimePolicyPresets.ts +0 -43
- package/src/signedResponse.test.ts +0 -111
- package/src/signedResponse.ts +0 -83
- package/src/stream.test.ts +0 -254
- package/src/stream.ts +0 -417
- package/src/telemetry.test.ts +0 -251
- package/src/telemetry.ts +0 -299
- package/src/webhookBinding.test.ts +0 -144
- package/src/webhookBinding.ts +0 -115
- package/src/wsBinding.test.ts +0 -221
- package/src/wsBinding.ts +0 -200
- package/tsconfig.json +0 -15
- package/tsconfig.lib.json +0 -23
- package/vite.lib.config.ts +0 -16
- package/vitest.config.ts +0 -11
package/src/protocol.bench.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { bench, describe } from 'vitest'
|
|
2
|
-
import { canonicalizeEnvelope, createEnvelope, signEnvelopeHmac, verifyEnvelopeHmac } from './protocol'
|
|
3
|
-
import { decodeEnvelope, encodeEnvelope } from './protocolTransport'
|
|
4
|
-
|
|
5
|
-
const unsigned = createEnvelope({
|
|
6
|
-
sender: 'agent.alpha',
|
|
7
|
-
recipient: 'agent.beta',
|
|
8
|
-
intent: 'TASK',
|
|
9
|
-
content: 'route-optimize:alpha-beta',
|
|
10
|
-
capability: 'task.plan',
|
|
11
|
-
correlationId: 'corr-1',
|
|
12
|
-
messageId: 'bench-1',
|
|
13
|
-
nonce: 'bench-nonce',
|
|
14
|
-
nowMs: 1_000,
|
|
15
|
-
ttlMs: 120_000,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
describe('protocol throughput', () => {
|
|
19
|
-
bench('canonicalize envelope', () => {
|
|
20
|
-
canonicalizeEnvelope(unsigned)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
bench('encode/decode envelope json', () => {
|
|
24
|
-
const encoded = encodeEnvelope({ ...unsigned })
|
|
25
|
-
decodeEnvelope(encoded)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
bench('encode/decode envelope compact', () => {
|
|
29
|
-
const encoded = encodeEnvelope({ ...unsigned }, 'compact')
|
|
30
|
-
decodeEnvelope(encoded)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
bench('sign + verify envelope', async () => {
|
|
34
|
-
const signed = await signEnvelopeHmac(unsigned, 'bench-secret', 'bench-k1')
|
|
35
|
-
await verifyEnvelopeHmac(signed, 'bench-secret')
|
|
36
|
-
})
|
|
37
|
-
})
|
package/src/protocol.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["protocol.ts"],"names":[],"mappings":"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"}
|
package/src/protocol.js
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
const textEncoder = new TextEncoder();
|
|
2
|
-
const HMAC_KEY_CACHE_LIMIT = 256;
|
|
3
|
-
const hmacKeyCache = new Map();
|
|
4
|
-
const ED25519_KEY_CACHE_LIMIT = 256;
|
|
5
|
-
const ed25519PrivateKeyCache = new Map();
|
|
6
|
-
const ed25519PublicKeyCache = new Map();
|
|
7
|
-
function getBufferLike() {
|
|
8
|
-
const candidate = globalThis;
|
|
9
|
-
return candidate.Buffer ?? null;
|
|
10
|
-
}
|
|
11
|
-
function serializeHeaderCanonical(header) {
|
|
12
|
-
const parts = [
|
|
13
|
-
`"messageId":${JSON.stringify(header.messageId)}`,
|
|
14
|
-
`"nonce":${JSON.stringify(header.nonce)}`,
|
|
15
|
-
];
|
|
16
|
-
if (header.recipient !== undefined) {
|
|
17
|
-
parts.push(`"recipient":${JSON.stringify(header.recipient)}`);
|
|
18
|
-
}
|
|
19
|
-
parts.push(`"sender":${JSON.stringify(header.sender)}`);
|
|
20
|
-
parts.push(`"timestampMs":${header.timestampMs}`);
|
|
21
|
-
parts.push(`"ttlMs":${header.ttlMs}`);
|
|
22
|
-
parts.push(`"version":${JSON.stringify(header.version)}`);
|
|
23
|
-
return `{${parts.join(',')}}`;
|
|
24
|
-
}
|
|
25
|
-
function serializeBodyCanonical(body) {
|
|
26
|
-
const parts = [];
|
|
27
|
-
if (body.capability !== undefined) {
|
|
28
|
-
parts.push(`"capability":${JSON.stringify(body.capability)}`);
|
|
29
|
-
}
|
|
30
|
-
parts.push(`"content":${JSON.stringify(body.content)}`);
|
|
31
|
-
if (body.correlationId !== undefined) {
|
|
32
|
-
parts.push(`"correlationId":${JSON.stringify(body.correlationId)}`);
|
|
33
|
-
}
|
|
34
|
-
parts.push(`"intent":${JSON.stringify(body.intent)}`);
|
|
35
|
-
return `{${parts.join(',')}}`;
|
|
36
|
-
}
|
|
37
|
-
function getCachedHmacKey(secret) {
|
|
38
|
-
const cacheKey = `hs256:${secret}`;
|
|
39
|
-
const cached = hmacKeyCache.get(cacheKey);
|
|
40
|
-
if (cached)
|
|
41
|
-
return cached;
|
|
42
|
-
if (hmacKeyCache.size >= HMAC_KEY_CACHE_LIMIT) {
|
|
43
|
-
hmacKeyCache.clear();
|
|
44
|
-
}
|
|
45
|
-
const subtle = requireCryptoSubtle();
|
|
46
|
-
const imported = subtle
|
|
47
|
-
.importKey('raw', textEncoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign', 'verify'])
|
|
48
|
-
.catch((error) => {
|
|
49
|
-
hmacKeyCache.delete(cacheKey);
|
|
50
|
-
throw error;
|
|
51
|
-
});
|
|
52
|
-
hmacKeyCache.set(cacheKey, imported);
|
|
53
|
-
return imported;
|
|
54
|
-
}
|
|
55
|
-
function getCachedEd25519PrivateKey(privateKeyPkcs8Base64Url) {
|
|
56
|
-
const cacheKey = `ed25519:pkcs8:${privateKeyPkcs8Base64Url}`;
|
|
57
|
-
const cached = ed25519PrivateKeyCache.get(cacheKey);
|
|
58
|
-
if (cached)
|
|
59
|
-
return cached;
|
|
60
|
-
if (ed25519PrivateKeyCache.size >= ED25519_KEY_CACHE_LIMIT) {
|
|
61
|
-
ed25519PrivateKeyCache.clear();
|
|
62
|
-
}
|
|
63
|
-
const subtle = requireCryptoSubtle();
|
|
64
|
-
const imported = subtle
|
|
65
|
-
.importKey('pkcs8', toArrayBuffer(fromBase64Url(privateKeyPkcs8Base64Url)), { name: 'Ed25519' }, false, ['sign'])
|
|
66
|
-
.catch((error) => {
|
|
67
|
-
ed25519PrivateKeyCache.delete(cacheKey);
|
|
68
|
-
throw error;
|
|
69
|
-
});
|
|
70
|
-
ed25519PrivateKeyCache.set(cacheKey, imported);
|
|
71
|
-
return imported;
|
|
72
|
-
}
|
|
73
|
-
function getCachedEd25519PublicKey(publicKeySpkiBase64Url) {
|
|
74
|
-
const cacheKey = `ed25519:spki:${publicKeySpkiBase64Url}`;
|
|
75
|
-
const cached = ed25519PublicKeyCache.get(cacheKey);
|
|
76
|
-
if (cached)
|
|
77
|
-
return cached;
|
|
78
|
-
if (ed25519PublicKeyCache.size >= ED25519_KEY_CACHE_LIMIT) {
|
|
79
|
-
ed25519PublicKeyCache.clear();
|
|
80
|
-
}
|
|
81
|
-
const subtle = requireCryptoSubtle();
|
|
82
|
-
const imported = subtle
|
|
83
|
-
.importKey('spki', toArrayBuffer(fromBase64Url(publicKeySpkiBase64Url)), { name: 'Ed25519' }, false, ['verify'])
|
|
84
|
-
.catch((error) => {
|
|
85
|
-
ed25519PublicKeyCache.delete(cacheKey);
|
|
86
|
-
throw error;
|
|
87
|
-
});
|
|
88
|
-
ed25519PublicKeyCache.set(cacheKey, imported);
|
|
89
|
-
return imported;
|
|
90
|
-
}
|
|
91
|
-
function toBase64Url(bytes) {
|
|
92
|
-
const bufferLike = getBufferLike();
|
|
93
|
-
const base64 = bufferLike ? bufferLike.from(bytes).toString('base64') : btoa(String.fromCharCode(...bytes));
|
|
94
|
-
return base64
|
|
95
|
-
.replace(/\+/g, '-')
|
|
96
|
-
.replace(/\//g, '_')
|
|
97
|
-
.replace(/=+$/g, '');
|
|
98
|
-
}
|
|
99
|
-
function fromBase64Url(value) {
|
|
100
|
-
const padded = value
|
|
101
|
-
.replace(/-/g, '+')
|
|
102
|
-
.replace(/_/g, '/')
|
|
103
|
-
.padEnd(Math.ceil(value.length / 4) * 4, '=');
|
|
104
|
-
const bufferLike = getBufferLike();
|
|
105
|
-
if (bufferLike) {
|
|
106
|
-
return new Uint8Array(bufferLike.from(padded, 'base64'));
|
|
107
|
-
}
|
|
108
|
-
const binary = atob(padded);
|
|
109
|
-
const bytes = new Uint8Array(binary.length);
|
|
110
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
111
|
-
bytes[i] = binary.charCodeAt(i);
|
|
112
|
-
}
|
|
113
|
-
return bytes;
|
|
114
|
-
}
|
|
115
|
-
function toArrayBuffer(bytes) {
|
|
116
|
-
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
117
|
-
}
|
|
118
|
-
export function canonicalizeEnvelope(envelope) {
|
|
119
|
-
return `{"body":${serializeBodyCanonical(envelope.body)},"header":${serializeHeaderCanonical(envelope.header)}}`;
|
|
120
|
-
}
|
|
121
|
-
function requireCryptoSubtle() {
|
|
122
|
-
if (typeof crypto === 'undefined' || !crypto.subtle) {
|
|
123
|
-
throw new Error('Web Crypto API is not available in this runtime');
|
|
124
|
-
}
|
|
125
|
-
return crypto.subtle;
|
|
126
|
-
}
|
|
127
|
-
async function hmacSign(payload, secret) {
|
|
128
|
-
const subtle = requireCryptoSubtle();
|
|
129
|
-
const key = await getCachedHmacKey(secret);
|
|
130
|
-
const signature = await subtle.sign('HMAC', key, textEncoder.encode(payload));
|
|
131
|
-
return toBase64Url(new Uint8Array(signature));
|
|
132
|
-
}
|
|
133
|
-
async function hmacVerify(payload, signature, secret) {
|
|
134
|
-
const subtle = requireCryptoSubtle();
|
|
135
|
-
const key = await getCachedHmacKey(secret);
|
|
136
|
-
const signatureBytes = fromBase64Url(signature);
|
|
137
|
-
return subtle.verify('HMAC', key, signatureBytes.buffer, textEncoder.encode(payload));
|
|
138
|
-
}
|
|
139
|
-
async function ed25519Sign(payload, privateKeyPkcs8Base64Url) {
|
|
140
|
-
const subtle = requireCryptoSubtle();
|
|
141
|
-
const key = await getCachedEd25519PrivateKey(privateKeyPkcs8Base64Url);
|
|
142
|
-
const signature = await subtle.sign('Ed25519', key, textEncoder.encode(payload));
|
|
143
|
-
return toBase64Url(new Uint8Array(signature));
|
|
144
|
-
}
|
|
145
|
-
async function ed25519Verify(payload, signature, publicKeySpkiBase64Url) {
|
|
146
|
-
const subtle = requireCryptoSubtle();
|
|
147
|
-
const key = await getCachedEd25519PublicKey(publicKeySpkiBase64Url);
|
|
148
|
-
const signatureBytes = fromBase64Url(signature);
|
|
149
|
-
return subtle.verify('Ed25519', key, signatureBytes.buffer, textEncoder.encode(payload));
|
|
150
|
-
}
|
|
151
|
-
export async function signCanonicalPayloadHmac(payload, secret) {
|
|
152
|
-
return hmacSign(payload, secret);
|
|
153
|
-
}
|
|
154
|
-
export async function verifyCanonicalPayloadHmac(payload, signature, secret) {
|
|
155
|
-
return hmacVerify(payload, signature, secret);
|
|
156
|
-
}
|
|
157
|
-
export async function generateEd25519KeypairBase64Url() {
|
|
158
|
-
const subtle = requireCryptoSubtle();
|
|
159
|
-
const pair = await subtle.generateKey({ name: 'Ed25519' }, true, ['sign', 'verify']);
|
|
160
|
-
const privateKeyRaw = await subtle.exportKey('pkcs8', pair.privateKey);
|
|
161
|
-
const publicKeyRaw = await subtle.exportKey('spki', pair.publicKey);
|
|
162
|
-
return {
|
|
163
|
-
privateKey: toBase64Url(new Uint8Array(privateKeyRaw)),
|
|
164
|
-
publicKey: toBase64Url(new Uint8Array(publicKeyRaw)),
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export async function signCanonicalPayloadEd25519(payload, privateKeyPkcs8Base64Url) {
|
|
168
|
-
return ed25519Sign(payload, privateKeyPkcs8Base64Url);
|
|
169
|
-
}
|
|
170
|
-
export async function verifyCanonicalPayloadEd25519(payload, signature, publicKeySpkiBase64Url) {
|
|
171
|
-
return ed25519Verify(payload, signature, publicKeySpkiBase64Url);
|
|
172
|
-
}
|
|
173
|
-
export async function signEnvelopeHmac(envelope, secret, keyId = 'local-dev-key') {
|
|
174
|
-
const payload = canonicalizeEnvelope(envelope);
|
|
175
|
-
const signature = await hmacSign(payload, secret);
|
|
176
|
-
return {
|
|
177
|
-
...envelope,
|
|
178
|
-
signature: {
|
|
179
|
-
alg: 'HS256',
|
|
180
|
-
keyId,
|
|
181
|
-
value: signature,
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
export async function verifyEnvelopeHmac(envelope, secret) {
|
|
186
|
-
if (!envelope.signature)
|
|
187
|
-
return false;
|
|
188
|
-
if (envelope.signature.alg !== 'HS256')
|
|
189
|
-
return false;
|
|
190
|
-
const unsigned = {
|
|
191
|
-
header: envelope.header,
|
|
192
|
-
body: envelope.body,
|
|
193
|
-
};
|
|
194
|
-
const payload = canonicalizeEnvelope(unsigned);
|
|
195
|
-
return hmacVerify(payload, envelope.signature.value, secret);
|
|
196
|
-
}
|
|
197
|
-
export async function signEnvelopeEd25519(envelope, privateKeyPkcs8Base64Url, keyId = 'local-ed25519-key') {
|
|
198
|
-
const payload = canonicalizeEnvelope(envelope);
|
|
199
|
-
const signature = await ed25519Sign(payload, privateKeyPkcs8Base64Url);
|
|
200
|
-
return {
|
|
201
|
-
...envelope,
|
|
202
|
-
signature: {
|
|
203
|
-
alg: 'ED25519',
|
|
204
|
-
keyId,
|
|
205
|
-
value: signature,
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
export async function verifyEnvelopeEd25519(envelope, publicKeySpkiBase64Url) {
|
|
210
|
-
if (!envelope.signature)
|
|
211
|
-
return false;
|
|
212
|
-
if (envelope.signature.alg !== 'ED25519')
|
|
213
|
-
return false;
|
|
214
|
-
const unsigned = {
|
|
215
|
-
header: envelope.header,
|
|
216
|
-
body: envelope.body,
|
|
217
|
-
};
|
|
218
|
-
const payload = canonicalizeEnvelope(unsigned);
|
|
219
|
-
return ed25519Verify(payload, envelope.signature.value, publicKeySpkiBase64Url);
|
|
220
|
-
}
|
|
221
|
-
export async function verifyEnvelopeSignature(envelope, material) {
|
|
222
|
-
if (!envelope.signature)
|
|
223
|
-
return false;
|
|
224
|
-
if (envelope.signature.alg !== material.alg)
|
|
225
|
-
return false;
|
|
226
|
-
if (material.alg === 'HS256') {
|
|
227
|
-
return verifyEnvelopeHmac(envelope, material.secret);
|
|
228
|
-
}
|
|
229
|
-
return verifyEnvelopeEd25519(envelope, material.publicKey);
|
|
230
|
-
}
|
|
231
|
-
export async function verifyCanonicalPayloadSignature(payload, signature, material) {
|
|
232
|
-
if (!signature)
|
|
233
|
-
return false;
|
|
234
|
-
if (signature.alg !== material.alg)
|
|
235
|
-
return false;
|
|
236
|
-
if (material.alg === 'HS256') {
|
|
237
|
-
return verifyCanonicalPayloadHmac(payload, signature.value, material.secret);
|
|
238
|
-
}
|
|
239
|
-
return verifyCanonicalPayloadEd25519(payload, signature.value, material.publicKey);
|
|
240
|
-
}
|
|
241
|
-
export function validateEnvelope(envelope, nowMs = Date.now()) {
|
|
242
|
-
const diagnostics = [];
|
|
243
|
-
const header = envelope.header ?? {};
|
|
244
|
-
const body = envelope.body ?? {};
|
|
245
|
-
const version = typeof header.version === 'string' ? header.version : '';
|
|
246
|
-
const messageId = typeof header.messageId === 'string' ? header.messageId : '';
|
|
247
|
-
const sender = typeof header.sender === 'string' ? header.sender : '';
|
|
248
|
-
const nonce = typeof header.nonce === 'string' ? header.nonce : '';
|
|
249
|
-
const timestampMs = typeof header.timestampMs === 'number' ? header.timestampMs : 0;
|
|
250
|
-
const ttlMs = typeof header.ttlMs === 'number' ? header.ttlMs : 0;
|
|
251
|
-
const content = typeof body.content === 'string' ? body.content : '';
|
|
252
|
-
if (version !== '7h3/0.1') {
|
|
253
|
-
diagnostics.push({ level: 'error', message: `Unsupported protocol version '${version}'` });
|
|
254
|
-
}
|
|
255
|
-
if (!messageId.trim()) {
|
|
256
|
-
diagnostics.push({ level: 'error', message: 'Missing messageId' });
|
|
257
|
-
}
|
|
258
|
-
if (!sender.trim()) {
|
|
259
|
-
diagnostics.push({ level: 'error', message: 'Missing sender identity' });
|
|
260
|
-
}
|
|
261
|
-
if (!nonce.trim()) {
|
|
262
|
-
diagnostics.push({ level: 'error', message: 'Missing nonce — replay protection requires a unique nonce per message' });
|
|
263
|
-
}
|
|
264
|
-
if (ttlMs <= 0) {
|
|
265
|
-
diagnostics.push({ level: 'error', message: 'ttlMs must be greater than zero' });
|
|
266
|
-
}
|
|
267
|
-
if (timestampMs + ttlMs < nowMs) {
|
|
268
|
-
diagnostics.push({ level: 'error', message: 'Message TTL expired' });
|
|
269
|
-
}
|
|
270
|
-
if (!content.trim()) {
|
|
271
|
-
diagnostics.push({ level: 'warning', message: 'Empty content payload' });
|
|
272
|
-
}
|
|
273
|
-
return diagnostics;
|
|
274
|
-
}
|
|
275
|
-
export function createEnvelope(input) {
|
|
276
|
-
const nowMs = input.nowMs ?? Date.now();
|
|
277
|
-
return {
|
|
278
|
-
header: {
|
|
279
|
-
version: '7h3/0.1',
|
|
280
|
-
messageId: input.messageId ?? `msg-${nowMs}-${Math.random().toString(36).slice(2, 10)}`,
|
|
281
|
-
timestampMs: nowMs,
|
|
282
|
-
ttlMs: input.ttlMs ?? 60_000,
|
|
283
|
-
sender: input.sender,
|
|
284
|
-
recipient: input.recipient,
|
|
285
|
-
nonce: input.nonce ?? Math.random().toString(36).slice(2, 12),
|
|
286
|
-
},
|
|
287
|
-
body: {
|
|
288
|
-
intent: input.intent,
|
|
289
|
-
content: input.content,
|
|
290
|
-
capability: input.capability,
|
|
291
|
-
correlationId: input.correlationId,
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
}
|
package/src/protocol.test.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
canonicalizeEnvelope,
|
|
4
|
-
createEnvelope,
|
|
5
|
-
generateEd25519KeypairBase64Url,
|
|
6
|
-
signCanonicalPayloadHmac,
|
|
7
|
-
signEnvelopeEd25519,
|
|
8
|
-
signEnvelopeHmac,
|
|
9
|
-
verifyCanonicalPayloadEd25519,
|
|
10
|
-
validateEnvelope,
|
|
11
|
-
verifyCanonicalPayloadHmac,
|
|
12
|
-
verifyEnvelopeEd25519,
|
|
13
|
-
verifyEnvelopeHmac,
|
|
14
|
-
} from './protocol'
|
|
15
|
-
|
|
16
|
-
describe('GLUV AIP protocol', () => {
|
|
17
|
-
it('uses stable canonical field order', () => {
|
|
18
|
-
const envelope = createEnvelope({
|
|
19
|
-
sender: 'agent.alpha',
|
|
20
|
-
recipient: 'agent.beta',
|
|
21
|
-
intent: 'TASK',
|
|
22
|
-
content: 'compute route',
|
|
23
|
-
capability: 'task.plan',
|
|
24
|
-
correlationId: 'c-1',
|
|
25
|
-
messageId: 'm0',
|
|
26
|
-
nonce: 'n0',
|
|
27
|
-
nowMs: 500,
|
|
28
|
-
ttlMs: 10_000,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
expect(canonicalizeEnvelope(envelope)).toBe(
|
|
32
|
-
'{"body":{"capability":"task.plan","content":"compute route","correlationId":"c-1","intent":"TASK"},"header":{"messageId":"m0","nonce":"n0","recipient":"agent.beta","sender":"agent.alpha","timestampMs":500,"ttlMs":10000,"version":"7h3/0.1"}}',
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('canonicalizes envelopes deterministically', () => {
|
|
37
|
-
const envelope = createEnvelope({
|
|
38
|
-
sender: 'agent.alpha',
|
|
39
|
-
recipient: 'agent.beta',
|
|
40
|
-
intent: 'TASK',
|
|
41
|
-
content: 'compute route',
|
|
42
|
-
messageId: 'm1',
|
|
43
|
-
nonce: 'n1',
|
|
44
|
-
nowMs: 1000,
|
|
45
|
-
ttlMs: 10000,
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const c1 = canonicalizeEnvelope(envelope)
|
|
49
|
-
const c2 = canonicalizeEnvelope({ header: envelope.header, body: envelope.body })
|
|
50
|
-
expect(c1).toBe(c2)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('signs and verifies with HMAC', async () => {
|
|
54
|
-
const unsigned = createEnvelope({
|
|
55
|
-
sender: 'agent.alpha',
|
|
56
|
-
intent: 'PING',
|
|
57
|
-
content: 'hello',
|
|
58
|
-
messageId: 'm2',
|
|
59
|
-
nonce: 'n2',
|
|
60
|
-
nowMs: 2000,
|
|
61
|
-
ttlMs: 10000,
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const signed = await signEnvelopeHmac(unsigned, 'secret-key', 'dev-1')
|
|
65
|
-
const ok = await verifyEnvelopeHmac(signed, 'secret-key')
|
|
66
|
-
expect(ok).toBe(true)
|
|
67
|
-
|
|
68
|
-
const tampered = {
|
|
69
|
-
...signed,
|
|
70
|
-
body: {
|
|
71
|
-
...signed.body,
|
|
72
|
-
content: 'tampered',
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
const bad = await verifyEnvelopeHmac(tampered, 'secret-key')
|
|
76
|
-
expect(bad).toBe(false)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('signs and verifies canonical payload directly', async () => {
|
|
80
|
-
const unsigned = createEnvelope({
|
|
81
|
-
sender: 'agent.alpha',
|
|
82
|
-
intent: 'PING',
|
|
83
|
-
content: 'hello',
|
|
84
|
-
messageId: 'm2b',
|
|
85
|
-
nonce: 'n2b',
|
|
86
|
-
nowMs: 2000,
|
|
87
|
-
ttlMs: 10000,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const payload = canonicalizeEnvelope(unsigned)
|
|
91
|
-
const sig = await signCanonicalPayloadHmac(payload, 'secret-key')
|
|
92
|
-
expect(await verifyCanonicalPayloadHmac(payload, sig, 'secret-key')).toBe(true)
|
|
93
|
-
expect(await verifyCanonicalPayloadHmac(`${payload}x`, sig, 'secret-key')).toBe(false)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('signs and verifies with Ed25519', async () => {
|
|
97
|
-
const keys = await generateEd25519KeypairBase64Url()
|
|
98
|
-
const unsigned = createEnvelope({
|
|
99
|
-
sender: 'agent.alpha',
|
|
100
|
-
intent: 'TASK',
|
|
101
|
-
content: 'route:ed25519',
|
|
102
|
-
messageId: 'm-ed1',
|
|
103
|
-
nonce: 'n-ed1',
|
|
104
|
-
nowMs: 3000,
|
|
105
|
-
ttlMs: 10000,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const signed = await signEnvelopeEd25519(unsigned, keys.privateKey, 'ed-1')
|
|
109
|
-
const ok = await verifyEnvelopeEd25519(signed, keys.publicKey)
|
|
110
|
-
expect(ok).toBe(true)
|
|
111
|
-
|
|
112
|
-
const tampered = {
|
|
113
|
-
...signed,
|
|
114
|
-
body: {
|
|
115
|
-
...signed.body,
|
|
116
|
-
content: 'tampered',
|
|
117
|
-
},
|
|
118
|
-
}
|
|
119
|
-
const bad = await verifyEnvelopeEd25519(tampered, keys.publicKey)
|
|
120
|
-
expect(bad).toBe(false)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('signs and verifies Ed25519 canonical payload directly', async () => {
|
|
124
|
-
const keys = await generateEd25519KeypairBase64Url()
|
|
125
|
-
const unsigned = createEnvelope({
|
|
126
|
-
sender: 'agent.alpha',
|
|
127
|
-
intent: 'PING',
|
|
128
|
-
content: 'hello-ed25519',
|
|
129
|
-
messageId: 'm-ed2',
|
|
130
|
-
nonce: 'n-ed2',
|
|
131
|
-
nowMs: 3100,
|
|
132
|
-
ttlMs: 10000,
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
const payload = canonicalizeEnvelope(unsigned)
|
|
136
|
-
const sig = await signEnvelopeEd25519(unsigned, keys.privateKey, 'ed-2')
|
|
137
|
-
expect(sig.signature?.alg).toBe('ED25519')
|
|
138
|
-
expect(await verifyCanonicalPayloadEd25519(payload, sig.signature?.value ?? '', keys.publicKey)).toBe(true)
|
|
139
|
-
expect(await verifyCanonicalPayloadEd25519(`${payload}x`, sig.signature?.value ?? '', keys.publicKey)).toBe(false)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('flags expired messages', () => {
|
|
143
|
-
const unsigned = createEnvelope({
|
|
144
|
-
sender: 'agent.alpha',
|
|
145
|
-
intent: 'RESULT',
|
|
146
|
-
content: 'done',
|
|
147
|
-
messageId: 'm3',
|
|
148
|
-
nonce: 'n3',
|
|
149
|
-
nowMs: 0,
|
|
150
|
-
ttlMs: 100,
|
|
151
|
-
})
|
|
152
|
-
const diagnostics = validateEnvelope({ ...unsigned }, 500)
|
|
153
|
-
expect(diagnostics.some((d) => d.message === 'Message TTL expired')).toBe(true)
|
|
154
|
-
})
|
|
155
|
-
})
|