@adea-ai/runtime-gateway-protocol 1.12.0 → 1.13.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/dist/device-relay.d.ts +9 -0
- package/dist/device-relay.js +22 -0
- package/package.json +1 -1
package/dist/device-relay.d.ts
CHANGED
|
@@ -331,6 +331,15 @@ export declare function openAuthenticatedRelayResult(input: OpenAuthenticatedRel
|
|
|
331
331
|
readonly header: AuthenticatedRelayResultHeader;
|
|
332
332
|
readonly plaintext: Uint8Array;
|
|
333
333
|
}>;
|
|
334
|
+
export interface AttestAuthenticatedRelayResultInput {
|
|
335
|
+
readonly envelope: unknown;
|
|
336
|
+
readonly plaintext: Uint8Array;
|
|
337
|
+
readonly deviceId: string;
|
|
338
|
+
readonly workspaceId: string;
|
|
339
|
+
readonly keyring: AuthorizedSenderKeyring;
|
|
340
|
+
readonly now?: Date;
|
|
341
|
+
}
|
|
342
|
+
export declare function attestAuthenticatedRelayResult(input: AttestAuthenticatedRelayResultInput): Promise<AuthenticatedRelayResultHeader>;
|
|
334
343
|
export declare function relayReplayOutcome(existing: readonly (RelayReplayReservation | undefined)[], reservation: RelayReplayReservation): 'first' | 'duplicate';
|
|
335
344
|
export declare function sha256(value: Uint8Array): Promise<`sha256:${string}`>;
|
|
336
345
|
export declare function encodeBase64Url(value: Uint8Array): string;
|
package/dist/device-relay.js
CHANGED
|
@@ -347,6 +347,28 @@ export async function openAuthenticatedRelayResult(input) {
|
|
|
347
347
|
plaintext: await openSealed(header, encapsulatedKey, ciphertext, input.returnPrivateKey),
|
|
348
348
|
};
|
|
349
349
|
}
|
|
350
|
+
export async function attestAuthenticatedRelayResult(input) {
|
|
351
|
+
const parsed = AuthenticatedRelayResultEnvelopeSchema.safeParse(input.envelope);
|
|
352
|
+
if (!parsed.success)
|
|
353
|
+
throw new AuthenticatedRelayError('RELAY_ENVELOPE_INVALID');
|
|
354
|
+
const { encapsulatedKey, ciphertext, signature, ...header } = parsed.data;
|
|
355
|
+
if (header.targetDeviceId !== input.deviceId || header.workspaceId !== input.workspaceId) {
|
|
356
|
+
throw new AuthenticatedRelayError('RELAY_TARGET_MISMATCH');
|
|
357
|
+
}
|
|
358
|
+
const now = input.now ?? new Date();
|
|
359
|
+
validateLifetime(header, MAX_AUTHENTICATED_RELAY_RESULT_LIFETIME_MS, now);
|
|
360
|
+
const sender = authorizedSender(input.keyring, header, now);
|
|
361
|
+
if (sender.kind !== 'device' || sender.deviceId !== input.deviceId) {
|
|
362
|
+
throw new AuthenticatedRelayError('RELAY_SENDER_UNAUTHENTICATED');
|
|
363
|
+
}
|
|
364
|
+
if (!(await verify(sender.signingPublicKey, signature, await envelopeSigningInput(header, encapsulatedKey, ciphertext)))) {
|
|
365
|
+
throw new AuthenticatedRelayError('RELAY_SIGNATURE_INVALID');
|
|
366
|
+
}
|
|
367
|
+
if ((await sha256(input.plaintext)) !== header.contentDigest) {
|
|
368
|
+
throw new AuthenticatedRelayError('RELAY_ENVELOPE_DIGEST_MISMATCH');
|
|
369
|
+
}
|
|
370
|
+
return header;
|
|
371
|
+
}
|
|
350
372
|
function authorizedSender(keyring, header, now) {
|
|
351
373
|
const sender = keyring.entries.find((entry) => entry.senderKeyId === header.senderKeyId);
|
|
352
374
|
if (sender === undefined || sender.principalId !== header.senderPrincipalId) {
|
package/package.json
CHANGED