@adea-ai/runtime-gateway-protocol 1.16.0 → 1.17.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/README.md +12 -23
- package/dist/device-relay.d.ts +2 -0
- package/dist/device-relay.js +14 -0
- package/dist/device-sync.d.ts +241 -0
- package/dist/device-sync.js +557 -0
- package/dist/index.d.ts +2 -6
- package/dist/index.js +2 -6
- package/package.json +12 -16
- package/dist/acp-remote-sealed-channel.d.ts +0 -12
- package/dist/acp-remote-sealed-channel.js +0 -1
- package/dist/authentication.d.ts +0 -45
- package/dist/authentication.js +0 -71
- package/dist/emulator.d.ts +0 -24
- package/dist/emulator.js +0 -137
- package/dist/fixtures.d.ts +0 -149
- package/dist/fixtures.js +0 -48
- package/dist/protocol.d.ts +0 -716
- package/dist/protocol.js +0 -522
- package/dist/public-identity-validation-compatibility.d.ts +0 -1
- package/dist/public-identity-validation-compatibility.js +0 -10
- package/fixtures/golden/envelopes.json +0 -153
- package/fixtures/index.mjs +0 -4
- package/fixtures/malformed/envelopes.json +0 -70
- package/schema/gateway-envelope.v1.json +0 -990
package/README.md
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
# @control-plane/runtime-gateway-protocol
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
| `./
|
|
29
|
-
|
|
|
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 {
|
|
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
|
package/dist/device-relay.d.ts
CHANGED
|
@@ -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;
|
package/dist/device-relay.js
CHANGED
|
@@ -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,241 @@
|
|
|
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 sealSyncBlobStream(dataKey: Uint8Array, binding: SyncBlobBinding, plaintextBytes: number, source: AsyncIterable<Uint8Array>): AsyncGenerator<Uint8Array>;
|
|
27
|
+
export declare function sealSyncBlob(dataKey: Uint8Array, binding: SyncBlobBinding, plaintext: Uint8Array): Promise<Uint8Array>;
|
|
28
|
+
export declare function openSyncBlobStream(dataKey: Uint8Array, binding: SyncBlobBinding, sealed: AsyncIterable<Uint8Array>): AsyncGenerator<Uint8Array>;
|
|
29
|
+
export declare function openSyncBlob(dataKey: Uint8Array, binding: SyncBlobBinding, sealed: Uint8Array): Promise<Uint8Array>;
|
|
30
|
+
export declare function sealSyncDataKey(contentKey: ContentKey, binding: SyncBlobBinding, dataKey: Uint8Array): Promise<{
|
|
31
|
+
ckv: number;
|
|
32
|
+
nonce: string;
|
|
33
|
+
ciphertext: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function openSyncDataKey(contentKey: ContentKey, binding: SyncBlobBinding, sealed: unknown): Promise<Uint8Array>;
|
|
36
|
+
export declare const SyncNamespaceSchema: z.ZodEnum<{
|
|
37
|
+
artifacts: "artifacts";
|
|
38
|
+
files: "files";
|
|
39
|
+
sessions: "sessions";
|
|
40
|
+
}>;
|
|
41
|
+
export type SyncNamespace = z.infer<typeof SyncNamespaceSchema>;
|
|
42
|
+
export declare const SyncHlcSchema: z.ZodObject<{
|
|
43
|
+
wallMs: z.ZodNumber;
|
|
44
|
+
counter: z.ZodNumber;
|
|
45
|
+
node: z.ZodString;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
export type SyncHlc = z.infer<typeof SyncHlcSchema>;
|
|
48
|
+
export declare function nextSyncHlc(previous: SyncHlc | undefined, nowMs: number, node: string): SyncHlc;
|
|
49
|
+
export declare function observeSyncHlc(local: SyncHlc | undefined, seen: SyncHlc): SyncHlc | undefined;
|
|
50
|
+
export declare function compareSyncHlc(left: SyncHlc, right: SyncHlc): number;
|
|
51
|
+
export declare const SyncPutEntrySchema: z.ZodObject<{
|
|
52
|
+
entryVersion: z.ZodLiteral<1>;
|
|
53
|
+
entryId: z.ZodString;
|
|
54
|
+
namespace: z.ZodEnum<{
|
|
55
|
+
artifacts: "artifacts";
|
|
56
|
+
files: "files";
|
|
57
|
+
sessions: "sessions";
|
|
58
|
+
}>;
|
|
59
|
+
itemId: z.ZodString;
|
|
60
|
+
hlc: z.ZodObject<{
|
|
61
|
+
wallMs: z.ZodNumber;
|
|
62
|
+
counter: z.ZodNumber;
|
|
63
|
+
node: z.ZodString;
|
|
64
|
+
}, z.core.$strict>;
|
|
65
|
+
kind: z.ZodLiteral<"put">;
|
|
66
|
+
path: z.ZodString;
|
|
67
|
+
objectId: z.ZodString;
|
|
68
|
+
dataKey: z.ZodObject<{
|
|
69
|
+
ckv: z.ZodNumber;
|
|
70
|
+
nonce: z.ZodString;
|
|
71
|
+
ciphertext: z.ZodString;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
plaintextSha256: z.ZodString;
|
|
74
|
+
size: z.ZodNumber;
|
|
75
|
+
contentType: z.ZodOptional<z.ZodString>;
|
|
76
|
+
mtimeMs: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
parents: z.ZodArray<z.ZodString>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
export declare const SyncDeleteEntrySchema: z.ZodObject<{
|
|
80
|
+
entryVersion: z.ZodLiteral<1>;
|
|
81
|
+
entryId: z.ZodString;
|
|
82
|
+
namespace: z.ZodEnum<{
|
|
83
|
+
artifacts: "artifacts";
|
|
84
|
+
files: "files";
|
|
85
|
+
sessions: "sessions";
|
|
86
|
+
}>;
|
|
87
|
+
itemId: z.ZodString;
|
|
88
|
+
hlc: z.ZodObject<{
|
|
89
|
+
wallMs: z.ZodNumber;
|
|
90
|
+
counter: z.ZodNumber;
|
|
91
|
+
node: z.ZodString;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
kind: z.ZodLiteral<"delete">;
|
|
94
|
+
parents: z.ZodArray<z.ZodString>;
|
|
95
|
+
}, z.core.$strict>;
|
|
96
|
+
export declare const SyncRewrapEntrySchema: z.ZodObject<{
|
|
97
|
+
entryVersion: z.ZodLiteral<1>;
|
|
98
|
+
entryId: z.ZodString;
|
|
99
|
+
namespace: z.ZodEnum<{
|
|
100
|
+
artifacts: "artifacts";
|
|
101
|
+
files: "files";
|
|
102
|
+
sessions: "sessions";
|
|
103
|
+
}>;
|
|
104
|
+
itemId: z.ZodString;
|
|
105
|
+
hlc: z.ZodObject<{
|
|
106
|
+
wallMs: z.ZodNumber;
|
|
107
|
+
counter: z.ZodNumber;
|
|
108
|
+
node: z.ZodString;
|
|
109
|
+
}, z.core.$strict>;
|
|
110
|
+
kind: z.ZodLiteral<"rewrap">;
|
|
111
|
+
objectId: z.ZodString;
|
|
112
|
+
dataKey: z.ZodObject<{
|
|
113
|
+
ckv: z.ZodNumber;
|
|
114
|
+
nonce: z.ZodString;
|
|
115
|
+
ciphertext: z.ZodString;
|
|
116
|
+
}, z.core.$strict>;
|
|
117
|
+
}, z.core.$strict>;
|
|
118
|
+
export declare const SyncEntrySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
119
|
+
entryVersion: z.ZodLiteral<1>;
|
|
120
|
+
entryId: z.ZodString;
|
|
121
|
+
namespace: z.ZodEnum<{
|
|
122
|
+
artifacts: "artifacts";
|
|
123
|
+
files: "files";
|
|
124
|
+
sessions: "sessions";
|
|
125
|
+
}>;
|
|
126
|
+
itemId: z.ZodString;
|
|
127
|
+
hlc: z.ZodObject<{
|
|
128
|
+
wallMs: z.ZodNumber;
|
|
129
|
+
counter: z.ZodNumber;
|
|
130
|
+
node: z.ZodString;
|
|
131
|
+
}, z.core.$strict>;
|
|
132
|
+
kind: z.ZodLiteral<"put">;
|
|
133
|
+
path: z.ZodString;
|
|
134
|
+
objectId: z.ZodString;
|
|
135
|
+
dataKey: z.ZodObject<{
|
|
136
|
+
ckv: z.ZodNumber;
|
|
137
|
+
nonce: z.ZodString;
|
|
138
|
+
ciphertext: z.ZodString;
|
|
139
|
+
}, z.core.$strict>;
|
|
140
|
+
plaintextSha256: z.ZodString;
|
|
141
|
+
size: z.ZodNumber;
|
|
142
|
+
contentType: z.ZodOptional<z.ZodString>;
|
|
143
|
+
mtimeMs: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
parents: z.ZodArray<z.ZodString>;
|
|
145
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
146
|
+
entryVersion: z.ZodLiteral<1>;
|
|
147
|
+
entryId: z.ZodString;
|
|
148
|
+
namespace: z.ZodEnum<{
|
|
149
|
+
artifacts: "artifacts";
|
|
150
|
+
files: "files";
|
|
151
|
+
sessions: "sessions";
|
|
152
|
+
}>;
|
|
153
|
+
itemId: z.ZodString;
|
|
154
|
+
hlc: z.ZodObject<{
|
|
155
|
+
wallMs: z.ZodNumber;
|
|
156
|
+
counter: z.ZodNumber;
|
|
157
|
+
node: z.ZodString;
|
|
158
|
+
}, z.core.$strict>;
|
|
159
|
+
kind: z.ZodLiteral<"delete">;
|
|
160
|
+
parents: z.ZodArray<z.ZodString>;
|
|
161
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
162
|
+
entryVersion: z.ZodLiteral<1>;
|
|
163
|
+
entryId: z.ZodString;
|
|
164
|
+
namespace: z.ZodEnum<{
|
|
165
|
+
artifacts: "artifacts";
|
|
166
|
+
files: "files";
|
|
167
|
+
sessions: "sessions";
|
|
168
|
+
}>;
|
|
169
|
+
itemId: z.ZodString;
|
|
170
|
+
hlc: z.ZodObject<{
|
|
171
|
+
wallMs: z.ZodNumber;
|
|
172
|
+
counter: z.ZodNumber;
|
|
173
|
+
node: z.ZodString;
|
|
174
|
+
}, z.core.$strict>;
|
|
175
|
+
kind: z.ZodLiteral<"rewrap">;
|
|
176
|
+
objectId: z.ZodString;
|
|
177
|
+
dataKey: z.ZodObject<{
|
|
178
|
+
ckv: z.ZodNumber;
|
|
179
|
+
nonce: z.ZodString;
|
|
180
|
+
ciphertext: z.ZodString;
|
|
181
|
+
}, z.core.$strict>;
|
|
182
|
+
}, z.core.$strict>], "kind">;
|
|
183
|
+
export type SyncEntry = z.infer<typeof SyncEntrySchema>;
|
|
184
|
+
export type SyncPutEntry = z.infer<typeof SyncPutEntrySchema>;
|
|
185
|
+
export declare function sealSyncEntry(input: {
|
|
186
|
+
readonly contentKey: ContentKey;
|
|
187
|
+
readonly workspaceId: string;
|
|
188
|
+
readonly entry: SyncEntry;
|
|
189
|
+
readonly author: RelaySigningKeyPair;
|
|
190
|
+
}): Promise<SignedSyncEntry>;
|
|
191
|
+
export declare function syncAuthor(keyring: AuthorizedSenderKeyring, workspaceId: string, keyId: string, at: number): AuthorizedSenderKey;
|
|
192
|
+
export declare function openSyncEntry(input: {
|
|
193
|
+
readonly workspaceId: string;
|
|
194
|
+
readonly keyring: AuthorizedSenderKeyring;
|
|
195
|
+
readonly entry: unknown;
|
|
196
|
+
readonly contentKey: (ckv: number) => Promise<ContentKey | undefined> | ContentKey | undefined;
|
|
197
|
+
}): Promise<SyncEntry & {
|
|
198
|
+
readonly authorKeyId: string;
|
|
199
|
+
}>;
|
|
200
|
+
export declare function assertSyncLogAdvances(lastSeenSeq: number, page: readonly {
|
|
201
|
+
seq: number;
|
|
202
|
+
}[]): void;
|
|
203
|
+
export interface SyncItemVersion {
|
|
204
|
+
readonly entryId: string;
|
|
205
|
+
readonly path: string;
|
|
206
|
+
readonly objectId: string;
|
|
207
|
+
readonly dataKey: z.infer<typeof ContentSealSchema>;
|
|
208
|
+
readonly plaintextSha256: string;
|
|
209
|
+
readonly size: number;
|
|
210
|
+
readonly contentType?: string;
|
|
211
|
+
readonly mtimeMs?: number;
|
|
212
|
+
readonly hlc: SyncHlc;
|
|
213
|
+
readonly authorKeyId: string;
|
|
214
|
+
}
|
|
215
|
+
export interface SyncItemState {
|
|
216
|
+
readonly itemId: string;
|
|
217
|
+
readonly namespace: SyncNamespace;
|
|
218
|
+
readonly current?: SyncItemVersion;
|
|
219
|
+
readonly conflicts: readonly SyncItemVersion[];
|
|
220
|
+
readonly missingParents: readonly string[];
|
|
221
|
+
}
|
|
222
|
+
type OpenedEntry = SyncEntry & {
|
|
223
|
+
readonly authorKeyId: string;
|
|
224
|
+
};
|
|
225
|
+
export declare function foldSyncItems(entries: Iterable<OpenedEntry>): Map<string, SyncItemState>;
|
|
226
|
+
export declare function signSyncRequest(input: {
|
|
227
|
+
readonly key: RelaySigningKeyPair;
|
|
228
|
+
readonly method: string;
|
|
229
|
+
readonly path: string;
|
|
230
|
+
readonly body: Uint8Array;
|
|
231
|
+
readonly now: Date;
|
|
232
|
+
}): Promise<string>;
|
|
233
|
+
export declare function verifySyncRequest(input: {
|
|
234
|
+
readonly header: string | null | undefined;
|
|
235
|
+
readonly method: string;
|
|
236
|
+
readonly path: string;
|
|
237
|
+
readonly body: Uint8Array;
|
|
238
|
+
readonly keyring: AuthorizedSenderKeyring;
|
|
239
|
+
readonly workspaceId: string;
|
|
240
|
+
readonly now: Date;
|
|
241
|
+
}): Promise<AuthorizedSenderKey>;
|