@7h3/protocol 0.5.3 → 0.5.6

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/keyRegistry.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export interface KeyRegistry {
2
2
  getPublicKey(senderId: string): Promise<string | null>;
3
- getSharedSecret?(keyId: string): Promise<string | null>;
3
+ getSharedSecret?(keyId: string, sender: string): Promise<string | null>;
4
4
  }
5
5
  export declare function createStaticKeyRegistry(keys: Record<string, string>): KeyRegistry;
6
6
  export declare function createCompositeKeyRegistry(...registries: KeyRegistry[]): KeyRegistry;
package/package.json CHANGED
@@ -1,24 +1,106 @@
1
1
  {
2
2
  "name": "@7h3/protocol",
3
- "version": "0.5.3",
3
+ "version": "0.5.6",
4
4
  "description": "7h3 Protocol: deterministic, signed, replay-safe AI-to-AI message envelopes (wire 7h3/0.1).",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./index.js",
11
- "types": "./index.d.ts"
10
+ "types": "./index.d.ts",
11
+ "import": "./index.js"
12
+ },
13
+ "./protocol": {
14
+ "types": "./index.d.ts",
15
+ "import": "./index.js"
16
+ },
17
+ "./http": {
18
+ "types": "./httpBinding.d.ts",
19
+ "import": "./index.js"
20
+ },
21
+ "./webhook": {
22
+ "types": "./webhookBinding.d.ts",
23
+ "import": "./index.js"
24
+ },
25
+ "./queue": {
26
+ "types": "./queueBinding.d.ts",
27
+ "import": "./index.js"
28
+ },
29
+ "./ws": {
30
+ "types": "./wsBinding.d.ts",
31
+ "import": "./index.js"
32
+ },
33
+ "./grpc": {
34
+ "types": "./grpcBinding.d.ts",
35
+ "import": "./index.js"
36
+ },
37
+ "./keys": {
38
+ "types": "./keyInfra.d.ts",
39
+ "import": "./index.js"
40
+ },
41
+ "./key-registry": {
42
+ "types": "./keyRegistry.d.ts",
43
+ "import": "./index.js"
44
+ },
45
+ "./gateway": {
46
+ "types": "./gateway.d.ts",
47
+ "import": "./index.js"
48
+ },
49
+ "./audit-log": {
50
+ "types": "./auditLog.d.ts",
51
+ "import": "./index.js"
52
+ },
53
+ "./signed-response": {
54
+ "types": "./signedResponse.d.ts",
55
+ "import": "./index.js"
56
+ },
57
+ "./rate-limiter": {
58
+ "types": "./rateLimiter.d.ts",
59
+ "import": "./index.js"
60
+ },
61
+ "./route-policy": {
62
+ "types": "./routePolicy.d.ts",
63
+ "import": "./index.js"
64
+ },
65
+ "./encryption": {
66
+ "types": "./encryption.d.ts",
67
+ "import": "./index.js"
68
+ },
69
+ "./capability": {
70
+ "types": "./capability.d.ts",
71
+ "import": "./index.js"
72
+ },
73
+ "./stream": {
74
+ "types": "./stream.d.ts",
75
+ "import": "./index.js"
76
+ },
77
+ "./telemetry": {
78
+ "types": "./telemetry.d.ts",
79
+ "import": "./index.js"
80
+ },
81
+ "./cbor": {
82
+ "types": "./envelopeCbor.d.ts",
83
+ "import": "./index.js"
84
+ },
85
+ "./replay": {
86
+ "types": "./replayStores.d.ts",
87
+ "import": "./index.js"
12
88
  }
13
89
  },
90
+ "bin": {
91
+ "7h3": "./bin/7h3.js"
92
+ },
14
93
  "files": [
15
94
  "index.js",
16
95
  "*.d.ts",
17
- "README.md"
96
+ "README.md",
97
+ "LICENSE",
98
+ "NOTICE",
99
+ "bin/7h3.js"
18
100
  ],
19
- "license": "MIT",
101
+ "license": "Apache-2.0",
20
102
  "repository": {
21
103
  "type": "git",
22
- "url": "https://github.com/IceMasterT/7h3-protocol-aip.git"
104
+ "url": "https://github.com/IceMasterT/7h3-protocol.git"
23
105
  }
24
106
  }
package/protocol.d.ts CHANGED
@@ -56,6 +56,7 @@ export declare function signEnvelopeEd25519(envelope: Omit<ProtocolEnvelope, 'si
56
56
  export declare function verifyEnvelopeEd25519(envelope: ProtocolEnvelope, publicKeySpkiBase64Url: string): Promise<boolean>;
57
57
  export declare function verifyEnvelopeSignature(envelope: ProtocolEnvelope, material: SignatureVerificationMaterial): Promise<boolean>;
58
58
  export declare function verifyCanonicalPayloadSignature(payload: string, signature: ProtocolSignature | undefined, material: SignatureVerificationMaterial): Promise<boolean>;
59
+ export declare const MAX_TTL_MS = 86400000;
59
60
  export declare function validateEnvelope(envelope: ProtocolEnvelope, nowMs?: number): ProtocolDiagnostic[];
60
61
  export declare function createEnvelope(input: {
61
62
  sender: string;
package/queueBinding.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type ProtocolEnvelope } from './protocol';
2
+ import type { ReplayCache } from './protocolReplay';
2
3
  export interface QueueSignOptions {
3
4
  privateKey: string;
4
5
  sender: string;
@@ -8,6 +9,17 @@ export interface QueueSignOptions {
8
9
  }
9
10
  export interface QueueVerifyOptions {
10
11
  publicKey: string;
12
+ /** Reject expired or malformed envelopes (missing nonce, bad TTL, etc). Default true. */
13
+ strictTtl?: boolean;
14
+ /**
15
+ * Optional replay/dedup cache (e.g. `new InMemoryReplayCache()` from
16
+ * `./protocolReplay`). Construct ONE instance per consumer process and pass
17
+ * the same instance to every verifyQueueMessage/verifyQueueBatch call — a
18
+ * fresh cache per call provides no protection at all, since a replayed
19
+ * message would never be recognized as already-seen.
20
+ */
21
+ replayCache?: ReplayCache;
22
+ nowMs?: number;
11
23
  }
12
24
  export type SignedEnvelope = ProtocolEnvelope;
13
25
  export interface QueueMessage<T> {
package/rateLimiter.d.ts CHANGED
@@ -7,8 +7,23 @@ export type RateLimitResult = {
7
7
  remaining: number;
8
8
  resetMs: number;
9
9
  };
10
+ /**
11
+ * Persistent rate-limit store — required for correct rate limiting in any
12
+ * environment where the gateway/limiter instance doesn't live for the
13
+ * lifetime of the traffic it's limiting (e.g. a serverless function that
14
+ * rebuilds its gateway on every invocation). Without one, SlidingWindowRateLimiter's
15
+ * in-memory Map resets whenever the process/instance does, silently
16
+ * defeating the limit.
17
+ */
18
+ export interface RateLimitStore {
19
+ consume(key: string, policy: RateLimitPolicy, nowMs?: number): Promise<RateLimitResult>;
20
+ }
10
21
  declare class SlidingWindowRateLimiter {
11
22
  private windows;
23
+ private readonly maxKeys;
24
+ constructor(opts?: {
25
+ maxKeys?: number;
26
+ });
12
27
  check(key: string, policy: RateLimitPolicy, nowMs?: number): RateLimitResult;
13
28
  consume(key: string, policy: RateLimitPolicy, nowMs?: number): RateLimitResult;
14
29
  reset(key: string): void;
@@ -2,6 +2,26 @@ import { generateEd25519KeypairBase64Url } from './protocol';
2
2
  export declare const WEBHOOK_SIG_HEADER = "x-7h3-sig";
3
3
  export declare const WEBHOOK_TS_HEADER = "x-7h3-ts";
4
4
  export declare const WEBHOOK_DEFAULT_TTL_MS = 300000;
5
+ /**
6
+ * A verified webhook signature is otherwise valid to replay any number of
7
+ * times until it ages out of maxAgeMs — the signature+timestamp cover
8
+ * authenticity and freshness, but nothing dedupes delivery. A replayCache
9
+ * closes that gap. The Ed25519/HMAC signature is deterministic per
10
+ * (timestampMs, body, key), so it doubles as a stable dedup key — no wire
11
+ * format change needed.
12
+ */
13
+ export interface WebhookReplayCache {
14
+ /** Returns true if this key was successfully reserved (first use), false if already seen. */
15
+ consume(key: string, expiresAtMs: number, nowMs: number): boolean | Promise<boolean>;
16
+ }
17
+ /** Bounded in-memory WebhookReplayCache — single process only, does not survive a restart. */
18
+ export declare class InMemoryWebhookReplayCache implements WebhookReplayCache {
19
+ private readonly seen;
20
+ private readonly maxEntries;
21
+ constructor(maxEntries?: number);
22
+ private prune;
23
+ consume(key: string, expiresAtMs: number, nowMs: number): boolean;
24
+ }
5
25
  export interface WebhookSignOptions {
6
26
  privateKey: string;
7
27
  ttlMs?: number;
@@ -13,10 +33,14 @@ export interface WebhookSignHmacOptions {
13
33
  export interface WebhookVerifyOptions {
14
34
  publicKey: string;
15
35
  maxAgeMs?: number;
36
+ /** Optional — rejects a signature that's already been consumed within its TTL window. */
37
+ replayCache?: WebhookReplayCache;
16
38
  }
17
39
  export interface WebhookVerifyHmacOptions {
18
40
  secret: string;
19
41
  maxAgeMs?: number;
42
+ /** Optional — rejects a signature that's already been consumed within its TTL window. */
43
+ replayCache?: WebhookReplayCache;
20
44
  }
21
45
  export interface WebhookHeaders {
22
46
  [WEBHOOK_SIG_HEADER]: string;
package/wsBinding.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { generateEd25519KeypairBase64Url, type ProtocolEnvelope } from './protocol';
2
2
  import type { KeyRegistry } from './keyRegistry';
3
+ import type { ReplayCache } from './protocolReplay';
3
4
  import { SignedStreamWriter, type StreamSignerOpts, type StreamVerifierOpts, type StreamVerifyResult, type StreamChunk } from './stream';
4
5
  export { type KeyRegistry, generateEd25519KeypairBase64Url };
5
6
  export type { StreamSignerOpts, StreamVerifierOpts, StreamVerifyResult, StreamChunk };
@@ -21,6 +22,13 @@ export interface WsBindingOptions {
21
22
  keyRegistry: KeyRegistry;
22
23
  ttlMs?: number;
23
24
  onVerifyFail?: (err: Error, rawData: string) => void;
25
+ /**
26
+ * Optional — signature+TTL alone don't stop a captured frame from being
27
+ * replayed verbatim any number of times within its TTL window. Pass an
28
+ * InMemoryReplayCache (or a distributed one) to dedupe incoming frames by
29
+ * sender/messageId/nonce, same as the HTTP gateway does.
30
+ */
31
+ replayCache?: ReplayCache;
24
32
  }
25
33
  export interface ProtectedWebSocket {
26
34
  send(payload: unknown): Promise<void>;