@adea-ai/runtime-gateway-protocol 1.14.0 → 1.15.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/content-key.d.ts +8 -1
- package/dist/content-key.js +32 -3
- package/package.json +2 -2
package/dist/content-key.d.ts
CHANGED
|
@@ -31,13 +31,20 @@ export interface ContentBinding {
|
|
|
31
31
|
export interface ContentKey {
|
|
32
32
|
readonly ckv: number;
|
|
33
33
|
readonly key: CryptoKey;
|
|
34
|
+
readonly nonceKey?: CryptoKey;
|
|
34
35
|
}
|
|
36
|
+
export declare const CONTENT_KEY_SEED_BYTES = 32;
|
|
37
|
+
export declare function deriveContentKey(seed: Uint8Array, workspaceId: string, ckv: number): Promise<ContentKey & {
|
|
38
|
+
readonly raw: Uint8Array;
|
|
39
|
+
}>;
|
|
35
40
|
export declare function generateContentKey(ckv: number): Promise<{
|
|
36
41
|
readonly ckv: number;
|
|
37
42
|
readonly raw: Uint8Array;
|
|
38
43
|
}>;
|
|
39
44
|
export declare function importContentKey(ckv: number, raw: Uint8Array): Promise<ContentKey>;
|
|
40
|
-
export declare function sealContent(key: ContentKey, binding: ContentBinding, plaintext: string
|
|
45
|
+
export declare function sealContent(key: ContentKey, binding: ContentBinding, plaintext: string, options?: {
|
|
46
|
+
readonly deterministic?: boolean;
|
|
47
|
+
}): Promise<ContentSeal>;
|
|
41
48
|
export declare function openContent(key: ContentKey, binding: ContentBinding, sealed: unknown): Promise<string>;
|
|
42
49
|
export declare const ContentKeyWrapBodySchema: z.ZodObject<{
|
|
43
50
|
wrapVersion: z.ZodLiteral<1>;
|
package/dist/content-key.js
CHANGED
|
@@ -52,6 +52,23 @@ export const ContentSealSchema = z
|
|
|
52
52
|
const ContentBindingSchema = z
|
|
53
53
|
.object({ workspaceId: IdentifierSchema, messageId: IdentifierSchema, field: IdentifierSchema })
|
|
54
54
|
.strict();
|
|
55
|
+
export const CONTENT_KEY_SEED_BYTES = 32;
|
|
56
|
+
export async function deriveContentKey(seed, workspaceId, ckv) {
|
|
57
|
+
if (seed.byteLength !== CONTENT_KEY_SEED_BYTES)
|
|
58
|
+
throw new ContentKeyError('CONTENT_KEY_WRAP_INVALID');
|
|
59
|
+
const version = VersionSchema.parse(ckv);
|
|
60
|
+
const root = await globalThis.crypto.subtle.importKey('raw', Uint8Array.from(seed), 'HKDF', false, ['deriveBits']);
|
|
61
|
+
const expand = async (info) => new Uint8Array(await globalThis.crypto.subtle.deriveBits({
|
|
62
|
+
name: 'HKDF',
|
|
63
|
+
hash: 'SHA-256',
|
|
64
|
+
salt: new Uint8Array(0),
|
|
65
|
+
info: new TextEncoder().encode(info),
|
|
66
|
+
}, root, CONTENT_KEY_BYTES * 8));
|
|
67
|
+
const info = `adea-content-key:${IdentifierSchema.parse(workspaceId)}:${version}`;
|
|
68
|
+
const raw = await expand(info);
|
|
69
|
+
const nonceKey = await globalThis.crypto.subtle.importKey('raw', await expand(`${info}:nonce`), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
70
|
+
return { ...(await importContentKey(version, raw)), nonceKey, raw };
|
|
71
|
+
}
|
|
55
72
|
export async function generateContentKey(ckv) {
|
|
56
73
|
return {
|
|
57
74
|
ckv: VersionSchema.parse(ckv),
|
|
@@ -64,12 +81,24 @@ export async function importContentKey(ckv, raw) {
|
|
|
64
81
|
const key = await globalThis.crypto.subtle.importKey('raw', Uint8Array.from(raw), { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']);
|
|
65
82
|
return { ckv: VersionSchema.parse(ckv), key };
|
|
66
83
|
}
|
|
67
|
-
export async function sealContent(key, binding, plaintext) {
|
|
84
|
+
export async function sealContent(key, binding, plaintext, options = {}) {
|
|
68
85
|
const bytes = new TextEncoder().encode(plaintext);
|
|
69
86
|
if (bytes.byteLength > MAX_CONTENT_PLAINTEXT_BYTES)
|
|
70
87
|
throw new ContentKeyError('CONTENT_TOO_LARGE');
|
|
71
|
-
const
|
|
72
|
-
|
|
88
|
+
const aad = contentAad(binding, key.ckv);
|
|
89
|
+
let nonce;
|
|
90
|
+
if (options.deterministic) {
|
|
91
|
+
if (!key.nonceKey)
|
|
92
|
+
throw new ContentKeyError('CONTENT_SEAL_INVALID');
|
|
93
|
+
const input = new Uint8Array(4 + aad.byteLength + bytes.byteLength);
|
|
94
|
+
new DataView(input.buffer).setUint32(0, aad.byteLength);
|
|
95
|
+
input.set(aad, 4);
|
|
96
|
+
input.set(bytes, 4 + aad.byteLength);
|
|
97
|
+
nonce = new Uint8Array(await globalThis.crypto.subtle.sign('HMAC', key.nonceKey, input)).slice(0, CONTENT_NONCE_BYTES);
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
nonce = globalThis.crypto.getRandomValues(new Uint8Array(CONTENT_NONCE_BYTES));
|
|
101
|
+
const ciphertext = new Uint8Array(await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv: nonce, additionalData: aad }, key.key, bytes));
|
|
73
102
|
return { ckv: key.ckv, nonce: encodeBase64Url(nonce), ciphertext: encodeBase64Url(ciphertext) };
|
|
74
103
|
}
|
|
75
104
|
export async function openContent(key, binding, sealed) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/runtime-gateway-protocol",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Versioned wire protocol between the Control Plane and external runtimes: schemas, emulator, fixtures, and authentication.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"test": "bun scripts/schema.ts --check && bun test src"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@adea-ai/contracts": "^2.
|
|
59
|
+
"@adea-ai/contracts": "^2.2.0",
|
|
60
60
|
"@adea-ai/runtime-sdk": "^1.22.0",
|
|
61
61
|
"@hpke/core": "1.9.0",
|
|
62
62
|
"@hpke/dhkem-x25519": "1.8.0",
|