@adea-ai/runtime-gateway-protocol 1.16.0 → 1.16.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 CHANGED
@@ -1,18 +1,10 @@
1
1
  # @control-plane/runtime-gateway-protocol
2
2
 
3
- Versioned wire protocol between the Control Plane and external runtimes
4
- (gateways, adapters, emulators). Pure Zod schemas plus a protocol emulator and
5
- deterministic fixtures — no transport, no credentials, no secrets.
6
-
7
- ## What's inside
8
-
9
- - **Protocol schemas** — manifests, capabilities, deprecation records, and
10
- envelope schemas for runtime discovery, health, sessions, and routing.
11
- - **Protocol version manifest** — the current and supported
12
- (`major.minor`) protocol versions with deprecation metadata.
13
- - **Emulator** — an in-memory protocol peer for testing gateways without a
14
- live runtime.
15
- - **Authentication helpers** — gateway credential schemas and validation.
3
+ End-to-end device relay envelopes and workspace content keys. A browser, phone
4
+ or device seals a payload to the target device with HPKE and signs it with
5
+ Ed25519; the relay stores and forwards envelopes it cannot read. Pure WebCrypto,
6
+ `@hpke` and Zod, so the same modules run in pi-host, the browser, the phone and
7
+ the relay worker — no transport, no credentials, no secrets.
16
8
 
17
9
  ## Install
18
10
 
@@ -22,22 +14,19 @@ bun add @adea-ai/runtime-gateway-protocol
22
14
 
23
15
  ## Subpath exports
24
16
 
25
- | Path | Contents |
26
- | ----------------------------------- | ---------------------------------------------------------- |
27
- | `.` | Protocol schemas, emulator, fixtures, authentication |
28
- | `./fixtures` | Golden and malformed fixture files for conformance testing |
29
- | `./schema/gateway-envelope.v1.json` | JSON Schema for gateway envelopes |
17
+ | Path | Contents |
18
+ | ---------------- | ----------------------------------------------------------------------- |
19
+ | `./device-relay` | Authenticated relay envelopes, signed sender keyrings and replay checks |
20
+ | `./content-key` | Workspace content keys: derivation, sealing and signed key wraps |
21
+ | `.` | Both of the above |
30
22
 
31
23
  ## Usage
32
24
 
33
25
  ```ts
34
- import { GatewayProtocolManifest, GatewayEnvelopeSchemas } from '@adea-ai/runtime-gateway-protocol'
26
+ import { sealAuthenticatedRelayCommand } from '@adea-ai/runtime-gateway-protocol/device-relay'
27
+ import { sealContent } from '@adea-ai/runtime-gateway-protocol/content-key'
35
28
  ```
36
29
 
37
- Protocol compatibility: the package currently speaks protocol `1.x`; see the
38
- `GatewayProtocolManifest` export for the supported version window and
39
- deprecation records.
40
-
41
30
  ## License
42
31
 
43
32
  Apache-2.0
@@ -268,6 +268,7 @@ export interface SealAuthenticatedRelayCommandInput {
268
268
  readonly payloadSchemaVersion: number;
269
269
  readonly issuedAt: string;
270
270
  readonly expiresAt: string;
271
+ readonly ownerExpiresAt?: string;
271
272
  readonly plaintext: Uint8Array;
272
273
  readonly returnKey: {
273
274
  readonly keyId: string;
@@ -279,6 +280,7 @@ export interface SealAuthenticatedRelayCommandInput {
279
280
  readonly privateKey: CryptoKey;
280
281
  };
281
282
  }
283
+ export declare function relayCommandExpiresAt(issuedAt: string, ownerExpiresAt?: string): string;
282
284
  export declare function sealAuthenticatedRelayCommand(input: SealAuthenticatedRelayCommandInput): Promise<AuthenticatedRelayCommandEnvelope>;
283
285
  export interface RelayReplayReservation {
284
286
  readonly senderKeyId: string;
@@ -231,8 +231,22 @@ export async function verifyAuthorizedSenderKeyring(input) {
231
231
  }
232
232
  return keyring;
233
233
  }
234
+ export function relayCommandExpiresAt(issuedAt, ownerExpiresAt) {
235
+ const issued = Date.parse(issuedAt);
236
+ const bound = issued + MAX_AUTHENTICATED_RELAY_COMMAND_LIFETIME_MS;
237
+ const owner = ownerExpiresAt === undefined ? bound : Date.parse(ownerExpiresAt);
238
+ if (!Number.isFinite(issued) || !Number.isFinite(owner) || owner <= issued) {
239
+ throw new AuthenticatedRelayError('RELAY_ENVELOPE_LIFETIME_INVALID');
240
+ }
241
+ return new Date(Math.min(bound, owner)).toISOString();
242
+ }
234
243
  export async function sealAuthenticatedRelayCommand(input) {
235
244
  validateDuration(input.issuedAt, input.expiresAt, MAX_AUTHENTICATED_RELAY_COMMAND_LIFETIME_MS);
245
+ if (input.ownerExpiresAt !== undefined &&
246
+ Date.parse(input.expiresAt) >
247
+ Date.parse(relayCommandExpiresAt(input.issuedAt, input.ownerExpiresAt))) {
248
+ throw new AuthenticatedRelayError('RELAY_ENVELOPE_LIFETIME_INVALID');
249
+ }
236
250
  const header = AuthenticatedRelayCommandHeaderSchema.parse({
237
251
  envelopeVersion: AUTHENTICATED_RELAY_ENVELOPE_VERSION,
238
252
  suite: RELAY_HPKE_SUITE,
@@ -0,0 +1,239 @@
1
+ import { z } from 'zod';
2
+ import { type DeviceSyncErrorCode, type SignedSyncEntry } from '@adea-ai/contracts/device-sync';
3
+ import { ContentSealSchema, type ContentKey } from './content-key.js';
4
+ import { type AuthorizedSenderKey, type AuthorizedSenderKeyring, type RelaySigningKeyPair } from './device-relay.js';
5
+ export { DeviceSyncErrorCodeSchema, MAX_SYNC_BATCH, MAX_SYNC_CIPHERTEXT_BYTES, MAX_SYNC_ENTRY_BYTES, MAX_SYNC_LOG_PAGE, MIN_SYNC_CIPHERTEXT_BYTES, SignedSyncEntrySchema, StoredSyncEntrySchema, SyncAppendRequestSchema, SyncAppendResponseSchema, SyncCommitResponseSchema, SyncDownloadRequestSchema, SyncDownloadResponseSchema, SyncEntryIdSchema, SyncLogPageSchema, SyncLogRequestSchema, SyncObjectIdSchema, SyncObjectRequestSchema, SyncReleaseResponseSchema, SyncUploadRequestSchema, SyncUploadResponseSchema, SyncUsageSchema, type DeviceSyncErrorCode, type SignedSyncEntry, type StoredSyncEntry, } from '@adea-ai/contracts/device-sync';
6
+ export declare const SYNC_BLOB_VERSION: 1;
7
+ export declare const SYNC_ENTRY_VERSION: 1;
8
+ export declare const SYNC_CHUNK_BYTES: number;
9
+ export declare const MAX_SYNC_OBJECT_BYTES: number;
10
+ export declare const SYNC_REQUEST_HEADER = "adea-sync-signature";
11
+ export declare class DeviceSyncError extends Error {
12
+ readonly code: DeviceSyncErrorCode;
13
+ constructor(code: DeviceSyncErrorCode);
14
+ }
15
+ export declare const SyncItemIdSchema: z.ZodString;
16
+ export declare const newSyncObjectId: () => string;
17
+ export declare const newSyncEntryId: () => string;
18
+ export declare const newSyncItemId: () => string;
19
+ export declare function padmeLength(length: number): number;
20
+ export declare function sealedBlobLength(plaintextBytes: number): number;
21
+ export interface SyncBlobBinding {
22
+ readonly workspaceId: string;
23
+ readonly objectId: string;
24
+ }
25
+ export declare function generateSyncDataKey(): Uint8Array;
26
+ export declare function sealSyncBlob(dataKey: Uint8Array, binding: SyncBlobBinding, plaintext: Uint8Array): Promise<Uint8Array>;
27
+ export declare function openSyncBlob(dataKey: Uint8Array, binding: SyncBlobBinding, sealed: Uint8Array): Promise<Uint8Array>;
28
+ export declare function sealSyncDataKey(contentKey: ContentKey, binding: SyncBlobBinding, dataKey: Uint8Array): Promise<{
29
+ ckv: number;
30
+ nonce: string;
31
+ ciphertext: string;
32
+ }>;
33
+ export declare function openSyncDataKey(contentKey: ContentKey, binding: SyncBlobBinding, sealed: unknown): Promise<Uint8Array>;
34
+ export declare const SyncNamespaceSchema: z.ZodEnum<{
35
+ artifacts: "artifacts";
36
+ files: "files";
37
+ sessions: "sessions";
38
+ }>;
39
+ export type SyncNamespace = z.infer<typeof SyncNamespaceSchema>;
40
+ export declare const SyncHlcSchema: z.ZodObject<{
41
+ wallMs: z.ZodNumber;
42
+ counter: z.ZodNumber;
43
+ node: z.ZodString;
44
+ }, z.core.$strict>;
45
+ export type SyncHlc = z.infer<typeof SyncHlcSchema>;
46
+ export declare function nextSyncHlc(previous: SyncHlc | undefined, nowMs: number, node: string): SyncHlc;
47
+ export declare function observeSyncHlc(local: SyncHlc | undefined, seen: SyncHlc): SyncHlc | undefined;
48
+ export declare function compareSyncHlc(left: SyncHlc, right: SyncHlc): number;
49
+ export declare const SyncPutEntrySchema: z.ZodObject<{
50
+ entryVersion: z.ZodLiteral<1>;
51
+ entryId: z.ZodString;
52
+ namespace: z.ZodEnum<{
53
+ artifacts: "artifacts";
54
+ files: "files";
55
+ sessions: "sessions";
56
+ }>;
57
+ itemId: z.ZodString;
58
+ hlc: z.ZodObject<{
59
+ wallMs: z.ZodNumber;
60
+ counter: z.ZodNumber;
61
+ node: z.ZodString;
62
+ }, z.core.$strict>;
63
+ kind: z.ZodLiteral<"put">;
64
+ path: z.ZodString;
65
+ objectId: z.ZodString;
66
+ dataKey: z.ZodObject<{
67
+ ckv: z.ZodNumber;
68
+ nonce: z.ZodString;
69
+ ciphertext: z.ZodString;
70
+ }, z.core.$strict>;
71
+ plaintextSha256: z.ZodString;
72
+ size: z.ZodNumber;
73
+ contentType: z.ZodOptional<z.ZodString>;
74
+ mtimeMs: z.ZodOptional<z.ZodNumber>;
75
+ parents: z.ZodArray<z.ZodString>;
76
+ }, z.core.$strict>;
77
+ export declare const SyncDeleteEntrySchema: z.ZodObject<{
78
+ entryVersion: z.ZodLiteral<1>;
79
+ entryId: z.ZodString;
80
+ namespace: z.ZodEnum<{
81
+ artifacts: "artifacts";
82
+ files: "files";
83
+ sessions: "sessions";
84
+ }>;
85
+ itemId: z.ZodString;
86
+ hlc: z.ZodObject<{
87
+ wallMs: z.ZodNumber;
88
+ counter: z.ZodNumber;
89
+ node: z.ZodString;
90
+ }, z.core.$strict>;
91
+ kind: z.ZodLiteral<"delete">;
92
+ parents: z.ZodArray<z.ZodString>;
93
+ }, z.core.$strict>;
94
+ export declare const SyncRewrapEntrySchema: z.ZodObject<{
95
+ entryVersion: z.ZodLiteral<1>;
96
+ entryId: z.ZodString;
97
+ namespace: z.ZodEnum<{
98
+ artifacts: "artifacts";
99
+ files: "files";
100
+ sessions: "sessions";
101
+ }>;
102
+ itemId: z.ZodString;
103
+ hlc: z.ZodObject<{
104
+ wallMs: z.ZodNumber;
105
+ counter: z.ZodNumber;
106
+ node: z.ZodString;
107
+ }, z.core.$strict>;
108
+ kind: z.ZodLiteral<"rewrap">;
109
+ objectId: z.ZodString;
110
+ dataKey: z.ZodObject<{
111
+ ckv: z.ZodNumber;
112
+ nonce: z.ZodString;
113
+ ciphertext: z.ZodString;
114
+ }, z.core.$strict>;
115
+ }, z.core.$strict>;
116
+ export declare const SyncEntrySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
117
+ entryVersion: z.ZodLiteral<1>;
118
+ entryId: z.ZodString;
119
+ namespace: z.ZodEnum<{
120
+ artifacts: "artifacts";
121
+ files: "files";
122
+ sessions: "sessions";
123
+ }>;
124
+ itemId: z.ZodString;
125
+ hlc: z.ZodObject<{
126
+ wallMs: z.ZodNumber;
127
+ counter: z.ZodNumber;
128
+ node: z.ZodString;
129
+ }, z.core.$strict>;
130
+ kind: z.ZodLiteral<"put">;
131
+ path: z.ZodString;
132
+ objectId: z.ZodString;
133
+ dataKey: z.ZodObject<{
134
+ ckv: z.ZodNumber;
135
+ nonce: z.ZodString;
136
+ ciphertext: z.ZodString;
137
+ }, z.core.$strict>;
138
+ plaintextSha256: z.ZodString;
139
+ size: z.ZodNumber;
140
+ contentType: z.ZodOptional<z.ZodString>;
141
+ mtimeMs: z.ZodOptional<z.ZodNumber>;
142
+ parents: z.ZodArray<z.ZodString>;
143
+ }, z.core.$strict>, z.ZodObject<{
144
+ entryVersion: z.ZodLiteral<1>;
145
+ entryId: z.ZodString;
146
+ namespace: z.ZodEnum<{
147
+ artifacts: "artifacts";
148
+ files: "files";
149
+ sessions: "sessions";
150
+ }>;
151
+ itemId: z.ZodString;
152
+ hlc: z.ZodObject<{
153
+ wallMs: z.ZodNumber;
154
+ counter: z.ZodNumber;
155
+ node: z.ZodString;
156
+ }, z.core.$strict>;
157
+ kind: z.ZodLiteral<"delete">;
158
+ parents: z.ZodArray<z.ZodString>;
159
+ }, z.core.$strict>, z.ZodObject<{
160
+ entryVersion: z.ZodLiteral<1>;
161
+ entryId: z.ZodString;
162
+ namespace: z.ZodEnum<{
163
+ artifacts: "artifacts";
164
+ files: "files";
165
+ sessions: "sessions";
166
+ }>;
167
+ itemId: z.ZodString;
168
+ hlc: z.ZodObject<{
169
+ wallMs: z.ZodNumber;
170
+ counter: z.ZodNumber;
171
+ node: z.ZodString;
172
+ }, z.core.$strict>;
173
+ kind: z.ZodLiteral<"rewrap">;
174
+ objectId: z.ZodString;
175
+ dataKey: z.ZodObject<{
176
+ ckv: z.ZodNumber;
177
+ nonce: z.ZodString;
178
+ ciphertext: z.ZodString;
179
+ }, z.core.$strict>;
180
+ }, z.core.$strict>], "kind">;
181
+ export type SyncEntry = z.infer<typeof SyncEntrySchema>;
182
+ export type SyncPutEntry = z.infer<typeof SyncPutEntrySchema>;
183
+ export declare function sealSyncEntry(input: {
184
+ readonly contentKey: ContentKey;
185
+ readonly workspaceId: string;
186
+ readonly entry: SyncEntry;
187
+ readonly author: RelaySigningKeyPair;
188
+ }): Promise<SignedSyncEntry>;
189
+ export declare function syncAuthor(keyring: AuthorizedSenderKeyring, workspaceId: string, keyId: string, at: number): AuthorizedSenderKey;
190
+ export declare function openSyncEntry(input: {
191
+ readonly workspaceId: string;
192
+ readonly keyring: AuthorizedSenderKeyring;
193
+ readonly entry: unknown;
194
+ readonly contentKey: (ckv: number) => Promise<ContentKey | undefined> | ContentKey | undefined;
195
+ }): Promise<SyncEntry & {
196
+ readonly authorKeyId: string;
197
+ }>;
198
+ export declare function assertSyncLogAdvances(lastSeenSeq: number, page: readonly {
199
+ seq: number;
200
+ }[]): void;
201
+ export interface SyncItemVersion {
202
+ readonly entryId: string;
203
+ readonly path: string;
204
+ readonly objectId: string;
205
+ readonly dataKey: z.infer<typeof ContentSealSchema>;
206
+ readonly plaintextSha256: string;
207
+ readonly size: number;
208
+ readonly contentType?: string;
209
+ readonly mtimeMs?: number;
210
+ readonly hlc: SyncHlc;
211
+ readonly authorKeyId: string;
212
+ }
213
+ export interface SyncItemState {
214
+ readonly itemId: string;
215
+ readonly namespace: SyncNamespace;
216
+ readonly current?: SyncItemVersion;
217
+ readonly conflicts: readonly SyncItemVersion[];
218
+ readonly missingParents: readonly string[];
219
+ }
220
+ type OpenedEntry = SyncEntry & {
221
+ readonly authorKeyId: string;
222
+ };
223
+ export declare function foldSyncItems(entries: Iterable<OpenedEntry>): Map<string, SyncItemState>;
224
+ export declare function signSyncRequest(input: {
225
+ readonly key: RelaySigningKeyPair;
226
+ readonly method: string;
227
+ readonly path: string;
228
+ readonly body: Uint8Array;
229
+ readonly now: Date;
230
+ }): Promise<string>;
231
+ export declare function verifySyncRequest(input: {
232
+ readonly header: string | null | undefined;
233
+ readonly method: string;
234
+ readonly path: string;
235
+ readonly body: Uint8Array;
236
+ readonly keyring: AuthorizedSenderKeyring;
237
+ readonly workspaceId: string;
238
+ readonly now: Date;
239
+ }): Promise<AuthorizedSenderKey>;