@7h3/protocol 0.5.2 → 0.5.4
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/bin/7h3.js +663 -0
- package/gateway.d.ts +17 -1
- package/index.js +536 -529
- package/keyRegistry.d.ts +1 -1
- package/package.json +88 -6
- package/protocol.d.ts +1 -0
- package/queueBinding.d.ts +12 -0
- package/rateLimiter.d.ts +11 -0
- package/replayStores.d.ts +2 -2
- package/wsBinding.d.ts +7 -5
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
|
+
"version": "0.5.4",
|
|
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
|
-
"
|
|
11
|
-
"
|
|
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": "
|
|
101
|
+
"license": "Apache-2.0",
|
|
20
102
|
"repository": {
|
|
21
103
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/IceMasterT/7h3-protocol
|
|
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,6 +7,17 @@ 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;
|
|
12
23
|
check(key: string, policy: RateLimitPolicy, nowMs?: number): RateLimitResult;
|
package/replayStores.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export interface RedisClientLike {
|
|
|
14
14
|
px?: number;
|
|
15
15
|
}): Promise<string | null>;
|
|
16
16
|
get(key: string): Promise<string | null>;
|
|
17
|
-
del(key: string): Promise<number |
|
|
18
|
-
quit(): Promise<
|
|
17
|
+
del(key: string): Promise<number | unknown>;
|
|
18
|
+
quit(): Promise<unknown>;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Gateway-facing replay store interface.
|
package/wsBinding.d.ts
CHANGED
|
@@ -3,13 +3,15 @@ import type { KeyRegistry } from './keyRegistry';
|
|
|
3
3
|
import { SignedStreamWriter, type StreamSignerOpts, type StreamVerifierOpts, type StreamVerifyResult, type StreamChunk } from './stream';
|
|
4
4
|
export { type KeyRegistry, generateEd25519KeypairBase64Url };
|
|
5
5
|
export type { StreamSignerOpts, StreamVerifierOpts, StreamVerifyResult, StreamChunk };
|
|
6
|
+
export type WsMessageHandler = (e: {
|
|
7
|
+
data: string | Buffer;
|
|
8
|
+
}) => void;
|
|
9
|
+
export type WsCloseHandler = () => void;
|
|
6
10
|
export interface WebSocketLike {
|
|
7
11
|
send(data: string): void;
|
|
8
|
-
addEventListener(event: 'message', handler:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
addEventListener(event: 'close', handler: () => void): void;
|
|
12
|
-
removeEventListener(event: string, handler: (...args: unknown[]) => void): void;
|
|
12
|
+
addEventListener(event: 'message', handler: WsMessageHandler): void;
|
|
13
|
+
addEventListener(event: 'close', handler: WsCloseHandler): void;
|
|
14
|
+
removeEventListener(event: 'message' | 'close', handler: WsMessageHandler | WsCloseHandler): void;
|
|
13
15
|
readyState?: number;
|
|
14
16
|
}
|
|
15
17
|
export interface WsBindingOptions {
|