@openllmsh/sdk 2.10.19-alpha.0 → 2.10.19-alpha.2
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/openapi/openapi.json +116 -158
- package/dist/openapi/operations.js +18 -18
- package/dist/protocol/daemon.d.ts +1 -1
- package/dist/protocol/daemon.js +1 -1
- package/dist/protocol/index.d.ts +1 -1
- package/dist/protocol/index.js +1 -1
- package/dist/protocol/local-device-control.d.ts +5 -5
- package/dist/protocol/local-device-control.js +5 -5
- package/dist/protocol/mux.js +1 -1
- package/dist/protocol/routebox.d.ts +7 -0
- package/dist/protocol/routebox.js +7 -0
- package/dist/vault/cli-auth-seal.js +22 -47
- package/dist/vault/device-control.d.ts +1 -1
- package/dist/vault/device-control.js +3 -4
- package/dist/vault/public-key-seal.js +22 -49
- package/dist/vault/routebox-key.d.ts +3 -0
- package/dist/vault/{routing-box-key.js → routebox-key.js} +5 -5
- package/dist/vault/{routing-box-seal.d.ts → routebox-seal.d.ts} +10 -10
- package/dist/vault/routebox-seal.js +91 -0
- package/dist/vault/x25519-seal.d.ts +48 -0
- package/dist/vault/x25519-seal.js +78 -0
- package/package.json +1 -1
- package/dist/protocol/routing-box.d.ts +0 -7
- package/dist/protocol/routing-box.js +0 -7
- package/dist/vault/routing-box-key.d.ts +0 -3
- package/dist/vault/routing-box-seal.js +0 -93
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Seal a routing box's unlock to the one-time token its current boot made.
|
|
3
|
-
*
|
|
4
|
-
* The box generates a fresh X25519 keypair on every boot and keeps the
|
|
5
|
-
* private half in RAM (`/run`, tmpfs). The browser seals to the public half:
|
|
6
|
-
* an ephemeral X25519 exchange, HKDF-SHA-256 and AES-256-GCM, the same
|
|
7
|
-
* construction as `public-key-seal.ts`, so the box can open it with Python's
|
|
8
|
-
* `cryptography` (cloud-init's own dependency) and no OpenLLM binary change.
|
|
9
|
-
*
|
|
10
|
-
* The associated data binds the envelope to the user, box, the box's API key
|
|
11
|
-
* id, boot generation, boot public key and challenge, so an envelope sealed for one
|
|
12
|
-
* boot can't be replayed into another, and the server, which only stores and
|
|
13
|
-
* forwards the ciphertext, can't redirect it.
|
|
14
|
-
*
|
|
15
|
-
* Deliberately NOT re-exported from `vault/index.ts` (the `openllm` binary
|
|
16
|
-
* imports that barrel). Import by subpath:
|
|
17
|
-
* `@openllmsh/sdk/vault/routing-box-seal`.
|
|
18
|
-
*
|
|
19
|
-
* The box side mirrors `open_unlock` in
|
|
20
|
-
* `packages/api/lib/routing-box/box-agent.ts` (Python).
|
|
21
|
-
*/
|
|
22
|
-
import { aesGcmDecrypt, aesGcmEncrypt, fromB64, hkdfSha256, randomBytes, toB64, zero, } from "./crypto.js";
|
|
23
|
-
export const ROUTING_BOX_SEAL_DOMAIN = "openllm-routing-box-seal-v1";
|
|
24
|
-
const encoder = new TextEncoder();
|
|
25
|
-
/** Canonical associated data; the Python side builds the same bytes. */
|
|
26
|
-
export const routingBoxSealAad = (binding) => encoder.encode(JSON.stringify([
|
|
27
|
-
ROUTING_BOX_SEAL_DOMAIN,
|
|
28
|
-
binding.userId,
|
|
29
|
-
binding.boxId,
|
|
30
|
-
binding.keyId,
|
|
31
|
-
binding.bootGeneration,
|
|
32
|
-
binding.bootPubkeyB64,
|
|
33
|
-
binding.challengeB64,
|
|
34
|
-
]));
|
|
35
|
-
const raw32 = (b64, what) => {
|
|
36
|
-
const bytes = fromB64(b64);
|
|
37
|
-
if (bytes.length !== 32 || toB64(bytes) !== b64) {
|
|
38
|
-
throw new Error(`${what} must be base64 of 32 bytes`);
|
|
39
|
-
}
|
|
40
|
-
return bytes;
|
|
41
|
-
};
|
|
42
|
-
const deriveKey = async (privateKey, peerRaw, epkB64, recipientB64) => {
|
|
43
|
-
const peer = await crypto.subtle.importKey("raw", peerRaw, { name: "X25519" }, false, []);
|
|
44
|
-
const shared = new Uint8Array(await crypto.subtle.deriveBits({ name: "X25519", public: peer }, privateKey, 256));
|
|
45
|
-
try {
|
|
46
|
-
return await hkdfSha256(shared, new Uint8Array(0), JSON.stringify([ROUTING_BOX_SEAL_DOMAIN, epkB64, recipientB64]), 32);
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
zero(shared);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/** Seal `unlock` to the boot in `binding`. */
|
|
53
|
-
export const sealRoutingBoxUnlock = async (binding, unlock) => {
|
|
54
|
-
raw32(binding.challengeB64, "challenge");
|
|
55
|
-
const recipient = raw32(binding.bootPubkeyB64, "boot public key");
|
|
56
|
-
const eph = (await crypto.subtle.generateKey({ name: "X25519" }, true, [
|
|
57
|
-
"deriveBits",
|
|
58
|
-
]));
|
|
59
|
-
const epkB64 = toB64(new Uint8Array(await crypto.subtle.exportKey("raw", eph.publicKey)));
|
|
60
|
-
const key = await deriveKey(eph.privateKey, recipient, epkB64, binding.bootPubkeyB64);
|
|
61
|
-
const plaintext = encoder.encode(JSON.stringify(unlock));
|
|
62
|
-
try {
|
|
63
|
-
const nonce = randomBytes(12);
|
|
64
|
-
return {
|
|
65
|
-
v: 1,
|
|
66
|
-
epk: epkB64,
|
|
67
|
-
nonce: toB64(nonce),
|
|
68
|
-
ct: toB64(await aesGcmEncrypt(key, nonce, plaintext, routingBoxSealAad(binding))),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
zero(key);
|
|
73
|
-
zero(plaintext);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/** Open an envelope with the boot's private key (tests; the box uses Python). */
|
|
77
|
-
export const openRoutingBoxUnlock = async (binding, envelope, bootPrivateKey) => {
|
|
78
|
-
if (envelope.v !== 1)
|
|
79
|
-
throw new Error("unknown envelope version");
|
|
80
|
-
const key = await deriveKey(bootPrivateKey, raw32(envelope.epk, "ephemeral key"), envelope.epk, binding.bootPubkeyB64);
|
|
81
|
-
try {
|
|
82
|
-
const plaintext = await aesGcmDecrypt(key, fromB64(envelope.nonce), fromB64(envelope.ct), routingBoxSealAad(binding));
|
|
83
|
-
try {
|
|
84
|
-
return JSON.parse(new TextDecoder().decode(plaintext));
|
|
85
|
-
}
|
|
86
|
-
finally {
|
|
87
|
-
zero(plaintext);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
finally {
|
|
91
|
-
zero(key);
|
|
92
|
-
}
|
|
93
|
-
};
|