@openllmsh/sdk 0.0.0-stage → 2.10.12-alpha.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/ARCHITECTURE.md +43 -0
- package/LICENSE +202 -0
- package/README.md +142 -2
- package/assets/openllm-light.svg +18 -0
- package/assets/openllm.svg +18 -0
- package/client/chat.ts +140 -0
- package/client/devices.ts +269 -0
- package/client/http.ts +72 -0
- package/client/index.ts +129 -0
- package/client/relay-mux.ts +547 -0
- package/client/types.ts +51 -0
- package/client/vault.ts +239 -0
- package/connect/chat.ts +58 -0
- package/connect/client.ts +240 -0
- package/connect/config.ts +47 -0
- package/connect/errors.ts +121 -0
- package/connect/index.ts +23 -0
- package/connect/oauth.ts +265 -0
- package/connect/routes.ts +234 -0
- package/connect/store.ts +107 -0
- package/mcp/handle.ts +24 -0
- package/mcp/index.ts +76 -0
- package/mcp/server.ts +319 -0
- package/mcp/tools/marketplace.ts +439 -0
- package/mcp/tools/memory-client.ts +297 -0
- package/mcp/tools/memory-config.ts +32 -0
- package/mcp/tools/memory.ts +369 -0
- package/mcp/tools/model-priority.ts +88 -0
- package/mcp/tools/openllm.ts +883 -0
- package/mcp/types.ts +28 -0
- package/openapi/call.ts +90 -0
- package/openapi/index.ts +8 -0
- package/openapi/openapi.json +80213 -0
- package/openapi/operations.ts +2075 -0
- package/package.json +39 -4
- package/protocol/CONTRIBUTING.md +21 -0
- package/protocol/README.md +134 -0
- package/protocol/access.ts +186 -0
- package/protocol/agent-prompt-text.ts +32 -0
- package/protocol/agent.ts +991 -0
- package/protocol/api-key-syntax.ts +105 -0
- package/protocol/assets/openllm-light.svg +18 -0
- package/protocol/assets/openllm.svg +18 -0
- package/protocol/audio.ts +29 -0
- package/protocol/auth.ts +142 -0
- package/protocol/changelog.ts +155 -0
- package/protocol/chat.ts +458 -0
- package/protocol/client-registry.ts +356 -0
- package/protocol/config.ts +345 -0
- package/protocol/control-channel.ts +115 -0
- package/protocol/cooldown-reason.ts +78 -0
- package/protocol/cost.ts +10 -0
- package/protocol/daemon-port.ts +31 -0
- package/protocol/daemon.ts +1524 -0
- package/protocol/default-chains.ts +66 -0
- package/protocol/device-state.ts +85 -0
- package/protocol/doctor-report-local.ts +443 -0
- package/protocol/doctor-report-policy.ts +119 -0
- package/protocol/doctor-report.ts +947 -0
- package/protocol/errors.ts +14 -0
- package/protocol/execution-selection.ts +141 -0
- package/protocol/hop-grant.ts +33 -0
- package/protocol/image-edit-parse.ts +263 -0
- package/protocol/images.ts +298 -0
- package/protocol/index.ts +74 -0
- package/protocol/inference-headers.ts +3 -0
- package/protocol/keepalive.ts +69 -0
- package/protocol/local-auth.ts +300 -0
- package/protocol/local-device-control.ts +133 -0
- package/protocol/local-provider.ts +288 -0
- package/protocol/local-session.ts +118 -0
- package/protocol/marketplace.ts +187 -0
- package/protocol/media-attempt.ts +81 -0
- package/protocol/media-bytes.ts +28 -0
- package/protocol/media-default.ts +357 -0
- package/protocol/media-dimensions.ts +132 -0
- package/protocol/media-input.ts +61 -0
- package/protocol/media-model.ts +142 -0
- package/protocol/media-option-issue.ts +90 -0
- package/protocol/media-types.ts +70 -0
- package/protocol/model-match.ts +1051 -0
- package/protocol/model-settings.ts +327 -0
- package/protocol/models.ts +767 -0
- package/protocol/mux.ts +722 -0
- package/protocol/plan-surface.ts +59 -0
- package/protocol/provider-models.ts +16 -0
- package/protocol/provider-status.ts +206 -0
- package/protocol/provider-tier.ts +67 -0
- package/protocol/provider-usage.ts +263 -0
- package/protocol/providers.ts +901 -0
- package/protocol/public-usage-index.ts +354 -0
- package/protocol/realtime-generated.ts +31 -0
- package/protocol/realtime.ts +324 -0
- package/protocol/registry-pointer.ts +118 -0
- package/protocol/relay.ts +702 -0
- package/protocol/replay-session.ts +11 -0
- package/protocol/responses.ts +280 -0
- package/protocol/semver.ts +182 -0
- package/protocol/setup-mode.ts +22 -0
- package/protocol/sha256-hex.ts +98 -0
- package/protocol/stats.ts +406 -0
- package/protocol/streaming.ts +19 -0
- package/protocol/subscription-daemon-floors.ts +33 -0
- package/protocol/subscription-provider-compat.ts +104 -0
- package/protocol/subscription-provider.ts +32 -0
- package/protocol/team-grant.ts +17 -0
- package/protocol/team-shareable.ts +61 -0
- package/protocol/transcription-encoding.ts +76 -0
- package/protocol/url-locality-dns.ts +37 -0
- package/protocol/url-locality.ts +288 -0
- package/protocol/usage-snapshots.ts +9 -0
- package/protocol/vendor-cli-install.ts +29 -0
- package/protocol/video-job-plan.ts +50 -0
- package/protocol/videos.ts +227 -0
- package/tsconfig.json +14 -0
- package/tunnel/ARCHITECTURE.md +111 -0
- package/tunnel/LICENSE +33 -0
- package/tunnel/README.md +45 -0
- package/tunnel/assets/openllm-light.svg +18 -0
- package/tunnel/assets/openllm.svg +18 -0
- package/tunnel/channel-envelope.ts +139 -0
- package/tunnel/codec.ts +191 -0
- package/tunnel/device-anchor.ts +229 -0
- package/tunnel/device-control.ts +118 -0
- package/tunnel/device-grant.ts +173 -0
- package/tunnel/fleet.ts +77 -0
- package/tunnel/index.ts +22 -0
- package/tunnel/mux.ts +580 -0
- package/tunnel/peer-link.ts +390 -0
- package/tunnel/rtc-auth.ts +415 -0
- package/tunnel/rtc-duplex.ts +187 -0
- package/tunnel/rtc-ice.ts +136 -0
- package/tunnel/secure.ts +1298 -0
- package/tunnel/stream-reset-error.ts +14 -0
- package/tunnel/streams.ts +1430 -0
- package/tunnel/team-grant.ts +302 -0
- package/tunnel/wire-bytes.ts +102 -0
- package/vault/ARCHITECTURE.md +470 -0
- package/vault/LICENSE +33 -0
- package/vault/api-key.ts +190 -0
- package/vault/argon2.ts +106 -0
- package/vault/cli-auth-seal.ts +157 -0
- package/vault/cred-seal.ts +146 -0
- package/vault/credential.ts +55 -0
- package/vault/crypto.ts +210 -0
- package/vault/daemon-attest.ts +229 -0
- package/vault/derive.ts +113 -0
- package/vault/device-access.ts +87 -0
- package/vault/device-anchor.ts +185 -0
- package/vault/device-control.ts +174 -0
- package/vault/handoff.ts +396 -0
- package/vault/index.ts +21 -0
- package/vault/passkey.ts +243 -0
- package/vault/phrase.ts +65 -0
- package/vault/pin.ts +153 -0
- package/vault/public-key-seal.ts +131 -0
- package/vault/seed.ts +272 -0
- package/vault/team.ts +355 -0
- package/vault/vault-item.ts +131 -0
- package/vault/vault-migrate-digest.ts +29 -0
- package/vault/wrapped.ts +77 -0
- package/wire/ARCHITECTURE.md +90 -0
- package/wire/CONTRIBUTING.md +19 -0
- package/wire/LICENSE +33 -0
- package/wire/README.md +51 -0
- package/wire/adapters/messages/anthropic-map.ts +37 -0
- package/wire/adapters/messages/index.ts +7 -0
- package/wire/adapters/messages/reasoning-from-items.ts +38 -0
- package/wire/adapters/messages/reasoning-signature.ts +243 -0
- package/wire/adapters/messages/request.ts +574 -0
- package/wire/adapters/messages/response.ts +215 -0
- package/wire/adapters/messages/streaming.ts +1027 -0
- package/wire/adapters/messages/usage.ts +43 -0
- package/wire/adapters/responses/index.ts +3 -0
- package/wire/adapters/responses/request.ts +395 -0
- package/wire/adapters/responses/response.ts +88 -0
- package/wire/adapters/responses/streaming.ts +344 -0
- package/wire/assets/openllm-light.svg +18 -0
- package/wire/assets/openllm.svg +18 -0
- package/wire/features/account-rank.ts +166 -0
- package/wire/features/compaction/compact-request.ts +862 -0
- package/wire/features/compaction/compaction-text.ts +43 -0
- package/wire/features/context-demote.ts +47 -0
- package/wire/features/context-overflow-strategy.ts +26 -0
- package/wire/features/context-skip.ts +170 -0
- package/wire/features/conversation-affinity.ts +144 -0
- package/wire/features/max-tokens-backfill.ts +141 -0
- package/wire/features/model-caps.ts +53 -0
- package/wire/features/model-settings.ts +24 -0
- package/wire/features/output-limit-clamp.ts +64 -0
- package/wire/features/quota-gate.ts +85 -0
- package/wire/index.ts +44 -0
- package/wire/lib/attempt-outcome.ts +43 -0
- package/wire/lib/canonical/content-part.ts +38 -0
- package/wire/lib/canonical/count-tokens-capability.ts +138 -0
- package/wire/lib/canonical/encoding-select.ts +82 -0
- package/wire/lib/canonical/image-signature.ts +202 -0
- package/wire/lib/canonical/image-sse.ts +216 -0
- package/wire/lib/canonical/message.ts +43 -0
- package/wire/lib/canonical/token-estimate.ts +266 -0
- package/wire/lib/encrypted-content.ts +66 -0
- package/wire/lib/error-class.ts +154 -0
- package/wire/lib/error-envelope.ts +56 -0
- package/wire/lib/forwarded-headers.ts +180 -0
- package/wire/lib/provider-error-rules.ts +48 -0
- package/wire/lib/refusal.ts +38 -0
- package/wire/lib/responses-apply-patch.ts +104 -0
- package/wire/lib/responses-namespace.ts +53 -0
- package/wire/lib/secret-scrub.ts +101 -0
- package/wire/lib/streaming/accumulate.ts +221 -0
- package/wire/lib/streaming/finish-reason.ts +33 -0
- package/wire/lib/streaming/peek.ts +154 -0
- package/wire/lib/streaming/provider-decode.ts +259 -0
- package/wire/lib/streaming/response-stream.ts +71 -0
- package/wire/lib/streaming/sse.ts +699 -0
- package/wire/lib/streaming/strip-tool-calls.ts +95 -0
- package/wire/lib/streaming/upstream-error.ts +58 -0
- package/wire/lib/strip-subagent-isolation.ts +284 -0
- package/wire/lib/thinking-signature.ts +156 -0
- package/wire/lib/token-ruler/bpe-core.ts +426 -0
- package/wire/lib/token-ruler/index.ts +2 -0
- package/wire/lib/token-ruler/ruler.ts +79 -0
- package/wire/lib/token-ruler/vocab/claude-ranks.ts +16 -0
- package/wire/lib/token-ruler/vocab/claude.ts +22 -0
- package/wire/lib/token-ruler/vocab/o200k-ranks.ts +18 -0
- package/wire/lib/token-ruler/vocab/o200k.ts +19 -0
- package/wire/lib/tool-name-map.ts +271 -0
- package/wire/lib/tool-schema.ts +353 -0
- package/wire/lib/usage-observer.ts +125 -0
- package/wire/providers/anthropic/adaptive-thinking.ts +291 -0
- package/wire/providers/anthropic/beta-headers.ts +165 -0
- package/wire/providers/anthropic/index.ts +10 -0
- package/wire/providers/anthropic/request.ts +607 -0
- package/wire/providers/anthropic/response.ts +155 -0
- package/wire/providers/anthropic/streaming.ts +315 -0
- package/wire/providers/anthropic/web-search-domains.ts +49 -0
- package/wire/providers/chatgpt/common.ts +136 -0
- package/wire/providers/chatgpt/index.ts +9 -0
- package/wire/providers/chatgpt/request.ts +959 -0
- package/wire/providers/chatgpt/streaming.ts +1007 -0
- package/wire/providers/chatgpt/web-search.ts +63 -0
- package/wire/providers/grok/web-search.ts +87 -0
- package/wire/providers/kimi/web-search.ts +145 -0
- package/wire/providers/upstream-deny.ts +355 -0
- package/wire/providers/upstream-request.ts +619 -0
package/vault/api-key.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isOpenllmApiKeySyntax,
|
|
3
|
+
OPENLLM_API_KEY_ID_BYTES,
|
|
4
|
+
OPENLLM_API_KEY_PREFIX,
|
|
5
|
+
OPENLLM_API_KEY_SECRET_BYTES,
|
|
6
|
+
} from "@openllmsh/sdk/protocol";
|
|
7
|
+
import {
|
|
8
|
+
aesGcmDecrypt,
|
|
9
|
+
aesGcmEncrypt,
|
|
10
|
+
fromB64,
|
|
11
|
+
fromB64Url,
|
|
12
|
+
hkdfSha256,
|
|
13
|
+
randomBytes,
|
|
14
|
+
toB64,
|
|
15
|
+
toB64Url,
|
|
16
|
+
} from "./crypto";
|
|
17
|
+
import { sealVaultText } from "./vault-item";
|
|
18
|
+
import { joinSealed, splitSealed } from "./wrapped";
|
|
19
|
+
|
|
20
|
+
const DEK_BYTES = 32;
|
|
21
|
+
const HKDF_INFO = "api-key-v1";
|
|
22
|
+
const NONCE_BYTES = 12;
|
|
23
|
+
|
|
24
|
+
export { OPENLLM_API_KEY_PREFIX as API_KEY_PREFIX };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `sk-llm-{id}.{secret}` parser. The id is the api_keys row primary
|
|
28
|
+
* key (base64url, no padding); the secret is 32 random bytes
|
|
29
|
+
* base64url-encoded. Returns null on any shape mismatch — the proxy
|
|
30
|
+
* auth path treats null as "no key supplied".
|
|
31
|
+
*/
|
|
32
|
+
export const parseApiKey = (
|
|
33
|
+
raw: string,
|
|
34
|
+
): { readonly id: string; readonly secret: Uint8Array } | null => {
|
|
35
|
+
if (!isOpenllmApiKeySyntax(raw)) return null;
|
|
36
|
+
const rest = raw.slice(OPENLLM_API_KEY_PREFIX.length);
|
|
37
|
+
const dot = rest.indexOf(".");
|
|
38
|
+
if (dot <= 0 || dot === rest.length - 1) return null;
|
|
39
|
+
const id = rest.slice(0, dot);
|
|
40
|
+
try {
|
|
41
|
+
const secret = fromB64Url(rest.slice(dot + 1));
|
|
42
|
+
if (secret.length !== OPENLLM_API_KEY_SECRET_BYTES) return null;
|
|
43
|
+
return { id, secret };
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Derive the per-key AES wrap key from the secret half of the
|
|
51
|
+
* `sk-llm-...` token. Same on both sides of the handshake — the
|
|
52
|
+
* browser uses it to wrap the DEK at mint time, the server uses it
|
|
53
|
+
* to unwrap on every request.
|
|
54
|
+
*/
|
|
55
|
+
export const deriveApiWrapKey = (
|
|
56
|
+
apiKeySecret: Uint8Array,
|
|
57
|
+
apiKeyId: string,
|
|
58
|
+
): Promise<Uint8Array> => {
|
|
59
|
+
return hkdfSha256(apiKeySecret, fromB64Url(apiKeyId), HKDF_INFO, 32);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Unwrap a `dek_for_key` row column. The stored layout is
|
|
64
|
+
* `IV (12) || ciphertext+tag`, base64-encoded.
|
|
65
|
+
*
|
|
66
|
+
* Unversioned on purpose, unlike the phrase and PIN wraps: this key comes from
|
|
67
|
+
* HKDF over the API-key secret, which has no cost parameters to re-tune, so
|
|
68
|
+
* there is nothing a stamp could ever select between.
|
|
69
|
+
*/
|
|
70
|
+
export const unwrapDekForKey = async (
|
|
71
|
+
dekForKeyB64: string,
|
|
72
|
+
apiWrapKey: Uint8Array,
|
|
73
|
+
): Promise<Uint8Array> => {
|
|
74
|
+
const { nonce, ciphertext } = splitSealed(
|
|
75
|
+
fromB64(dekForKeyB64),
|
|
76
|
+
"dek_for_key blob",
|
|
77
|
+
);
|
|
78
|
+
const dek = await aesGcmDecrypt(apiWrapKey, nonce, ciphertext);
|
|
79
|
+
// This runs on the proxy hot path for every `/v1/*` request. A DEK of the
|
|
80
|
+
// wrong size would otherwise surface several frames later as an opaque
|
|
81
|
+
// WebCrypto key-length error on whichever credential happened to decrypt first.
|
|
82
|
+
if (dek.length !== DEK_BYTES) {
|
|
83
|
+
dek.fill(0);
|
|
84
|
+
throw new Error("dek_for_key did not contain a 32-byte key");
|
|
85
|
+
}
|
|
86
|
+
return dek;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type TMintedApiKey = {
|
|
90
|
+
/** Body for `POST /api/keys` — server persists row keyed by id. */
|
|
91
|
+
readonly row: {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly dek_for_key: string;
|
|
94
|
+
readonly secret_ciphertext: string;
|
|
95
|
+
readonly secret_nonce: string;
|
|
96
|
+
readonly vault_version: number;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The `sk-llm-{id}.{secret}` string shown ONCE. The server never
|
|
100
|
+
* sees this in plaintext; an AES-GCM(sk-llm, DEK) copy ships with
|
|
101
|
+
* the row so the dashboard can re-display it when the vault is
|
|
102
|
+
* unlocked.
|
|
103
|
+
*/
|
|
104
|
+
readonly sk_llm: string;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const newApiKeyId = (): string =>
|
|
108
|
+
toB64Url(randomBytes(OPENLLM_API_KEY_ID_BYTES));
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Mint a new API key client-side. The browser:
|
|
112
|
+
* 1. picks `(api_key_id, api_key_secret)`,
|
|
113
|
+
* 2. derives `api_wrap_key = HKDF(secret, id)`,
|
|
114
|
+
* 3. wraps the user's DEK under it,
|
|
115
|
+
* 4. ALSO encrypts the full sk-llm string under the user's DEK so
|
|
116
|
+
* the dashboard can re-display it when unlocked,
|
|
117
|
+
* 5. POSTs `{ id, dek_for_key, secret_ciphertext, secret_nonce,
|
|
118
|
+
* vault_version }` to `/api/keys`,
|
|
119
|
+
* 6. shows `sk-llm-{id}.{secret_b64url}` once.
|
|
120
|
+
*/
|
|
121
|
+
export const mintApiKey = async (
|
|
122
|
+
dek: Uint8Array,
|
|
123
|
+
vaultVersion: number,
|
|
124
|
+
): Promise<TMintedApiKey> => {
|
|
125
|
+
const apiKeyId = newApiKeyId();
|
|
126
|
+
const apiKeySecret = randomBytes(OPENLLM_API_KEY_SECRET_BYTES);
|
|
127
|
+
const wrapKey = await deriveApiWrapKey(apiKeySecret, apiKeyId);
|
|
128
|
+
try {
|
|
129
|
+
const nonce = randomBytes(NONCE_BYTES);
|
|
130
|
+
const ct = await aesGcmEncrypt(wrapKey, nonce, dek);
|
|
131
|
+
const dekForKey = joinSealed(nonce, ct);
|
|
132
|
+
const skLlm = `${OPENLLM_API_KEY_PREFIX}${apiKeyId}.${toB64Url(apiKeySecret)}`;
|
|
133
|
+
// Wrap the full token under the `keys` branch so the dashboard can
|
|
134
|
+
// re-display it later. Distinct from `dek_for_key` (still under the
|
|
135
|
+
// API-key wrap key — the server needs the root).
|
|
136
|
+
const sealedSecret = await sealVaultText(dek, { branch: "keys" }, skLlm);
|
|
137
|
+
return {
|
|
138
|
+
row: {
|
|
139
|
+
id: apiKeyId,
|
|
140
|
+
dek_for_key: toB64(dekForKey),
|
|
141
|
+
secret_ciphertext: sealedSecret.ciphertext,
|
|
142
|
+
secret_nonce: sealedSecret.nonce,
|
|
143
|
+
vault_version: vaultVersion,
|
|
144
|
+
},
|
|
145
|
+
sk_llm: skLlm,
|
|
146
|
+
};
|
|
147
|
+
} finally {
|
|
148
|
+
wrapKey.fill(0);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/** The secret columns of an `api_keys` row re-wrapped under a new DEK. */
|
|
153
|
+
export type TRewrappedApiKey = {
|
|
154
|
+
readonly dek_for_key: string;
|
|
155
|
+
readonly secret_ciphertext: string;
|
|
156
|
+
readonly secret_nonce: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Re-wrap an existing API key for a new DEK (the seed-only vault's one-time
|
|
161
|
+
* migration, docs/plans/seed-only-vault.md). The browser opens the key's
|
|
162
|
+
* `secret_ciphertext` with the OLD DEK to get the `sk-llm` token, then calls
|
|
163
|
+
* this with the NEW DEK: the token itself is unchanged, so every daemon and
|
|
164
|
+
* client holding it keeps working. Never zeroes its inputs.
|
|
165
|
+
*/
|
|
166
|
+
export const rewrapApiKey = async (
|
|
167
|
+
skLlm: string,
|
|
168
|
+
newDek: Uint8Array,
|
|
169
|
+
): Promise<TRewrappedApiKey> => {
|
|
170
|
+
if (newDek.length !== DEK_BYTES) throw new Error("DEK must be 32 bytes");
|
|
171
|
+
const parsed = parseApiKey(skLlm);
|
|
172
|
+
if (parsed === null) throw new Error("not an OpenLLM API key");
|
|
173
|
+
const wrapKey = await deriveApiWrapKey(parsed.secret, parsed.id);
|
|
174
|
+
try {
|
|
175
|
+
const nonce = randomBytes(NONCE_BYTES);
|
|
176
|
+
const dekForKey = joinSealed(
|
|
177
|
+
nonce,
|
|
178
|
+
await aesGcmEncrypt(wrapKey, nonce, newDek),
|
|
179
|
+
);
|
|
180
|
+
const sealedSecret = await sealVaultText(newDek, { branch: "keys" }, skLlm);
|
|
181
|
+
return {
|
|
182
|
+
dek_for_key: toB64(dekForKey),
|
|
183
|
+
secret_ciphertext: sealedSecret.ciphertext,
|
|
184
|
+
secret_nonce: sealedSecret.nonce,
|
|
185
|
+
};
|
|
186
|
+
} finally {
|
|
187
|
+
wrapKey.fill(0);
|
|
188
|
+
parsed.secret.fill(0);
|
|
189
|
+
}
|
|
190
|
+
};
|
package/vault/argon2.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { argon2id } from "hash-wasm";
|
|
2
|
+
|
|
3
|
+
export type TArgon2Params = {
|
|
4
|
+
readonly parallelism: number;
|
|
5
|
+
readonly iterations: number;
|
|
6
|
+
readonly memorySize: number;
|
|
7
|
+
readonly hashLength: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Every set of Argon2id parameters this build knows how to derive with,
|
|
12
|
+
* keyed by the version stamped into the blob that was wrapped with them.
|
|
13
|
+
*
|
|
14
|
+
* READ THIS BEFORE TOUCHING A PARAMETER. Changing any value changes the
|
|
15
|
+
* derived `wrap_key`, which makes every AES-GCM auth tag produced under the
|
|
16
|
+
* old value fail. Because the design is zero-knowledge there is no
|
|
17
|
+
* server-side escape hatch: editing a row here in place would ship as an
|
|
18
|
+
* instant, PERMANENT lock-out of every existing vault — the correct recovery
|
|
19
|
+
* phrase included — and every provider credential in them.
|
|
20
|
+
*
|
|
21
|
+
* So parameters are append-only. To re-tune:
|
|
22
|
+
*
|
|
23
|
+
* 1. add a NEW version key with the new numbers, leaving every existing
|
|
24
|
+
* entry byte-identical forever;
|
|
25
|
+
* 2. bump {@link CURRENT_KDF_VERSION} so fresh wraps use it;
|
|
26
|
+
* 3. leave the old entries in place — they are the only way the blobs
|
|
27
|
+
* already on disk can ever be opened again.
|
|
28
|
+
*
|
|
29
|
+
* Version 1 is the original, and is also what an UNSTAMPED blob means: every
|
|
30
|
+
* blob written before stamping existed was produced with exactly these
|
|
31
|
+
* numbers. See `./wrapped.ts` for the on-disk encoding.
|
|
32
|
+
*
|
|
33
|
+
* v1 — conservative-but-tolerable on mobile browsers in 2026:
|
|
34
|
+
* memorySize 64 MiB — high enough to make GPU attacks expensive
|
|
35
|
+
* iterations 3 — recommended baseline
|
|
36
|
+
* parallelism 1 — single-thread to keep WASM portable
|
|
37
|
+
* hashLength 32 bytes — direct AES-GCM key
|
|
38
|
+
*/
|
|
39
|
+
export const KDF_PARAMS_BY_VERSION = {
|
|
40
|
+
1: {
|
|
41
|
+
parallelism: 1,
|
|
42
|
+
iterations: 3,
|
|
43
|
+
memorySize: 64 * 1024,
|
|
44
|
+
hashLength: 32,
|
|
45
|
+
},
|
|
46
|
+
} as const satisfies Record<number, TArgon2Params>;
|
|
47
|
+
|
|
48
|
+
export type TKdfVersion = keyof typeof KDF_PARAMS_BY_VERSION;
|
|
49
|
+
|
|
50
|
+
/** The version fresh wraps are produced under. */
|
|
51
|
+
export const CURRENT_KDF_VERSION: TKdfVersion = 1;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The version an unstamped blob is from. Not a guess — stamping was
|
|
55
|
+
* introduced alongside version 2's *possibility*, so everything unstamped
|
|
56
|
+
* predates it and was necessarily derived with v1 parameters.
|
|
57
|
+
*/
|
|
58
|
+
export const LEGACY_KDF_VERSION: TKdfVersion = 1;
|
|
59
|
+
|
|
60
|
+
export const isKdfVersion = (n: number): n is TKdfVersion =>
|
|
61
|
+
Object.hasOwn(KDF_PARAMS_BY_VERSION, n);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Narrow a declared version to one this build can derive, or fail loudly.
|
|
65
|
+
*
|
|
66
|
+
* A blob stamped with a version this build doesn't carry means the browser is
|
|
67
|
+
* older than the vault — an app-update problem with a clear answer, not the
|
|
68
|
+
* silent "wrong password" an unknown-params derivation would masquerade as.
|
|
69
|
+
*/
|
|
70
|
+
export const requireKdfVersion = (version: number): TKdfVersion => {
|
|
71
|
+
if (!isKdfVersion(version)) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`vault blob was wrapped with unknown KDF version ${version} — this build is too old to open it`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return version;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const kdfParamsFor = (version: number): TArgon2Params =>
|
|
80
|
+
KDF_PARAMS_BY_VERSION[requireKdfVersion(version)];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Derive a 32-byte wrap key from a secret (recovery phrase or PIN) and a salt.
|
|
84
|
+
*
|
|
85
|
+
* `version` MUST be the version the blob being opened declares — never
|
|
86
|
+
* "whatever is current". Passing the current version to an old blob is the
|
|
87
|
+
* brick this module exists to prevent. Lazy-loaded WASM (~50 KB); the first
|
|
88
|
+
* call pays the cold start.
|
|
89
|
+
*/
|
|
90
|
+
export const deriveWrapKey = async (
|
|
91
|
+
secret: string,
|
|
92
|
+
saltBytes: Uint8Array,
|
|
93
|
+
version: TKdfVersion = CURRENT_KDF_VERSION,
|
|
94
|
+
): Promise<Uint8Array> => {
|
|
95
|
+
const params = kdfParamsFor(version);
|
|
96
|
+
const hash = await argon2id({
|
|
97
|
+
password: secret,
|
|
98
|
+
salt: saltBytes,
|
|
99
|
+
parallelism: params.parallelism,
|
|
100
|
+
iterations: params.iterations,
|
|
101
|
+
memorySize: params.memorySize,
|
|
102
|
+
hashLength: params.hashLength,
|
|
103
|
+
outputType: "binary",
|
|
104
|
+
});
|
|
105
|
+
return hash;
|
|
106
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal an ordinary `sk-llm` API key to a CLI caller's ephemeral X25519
|
|
3
|
+
* public key during OpenLLM CLI OAuth login handover
|
|
4
|
+
* (`docs/plan/2026-11-01-cli-install-onboarding.md` §2).
|
|
5
|
+
*
|
|
6
|
+
* Same envelope shape as the connector seal, but a distinct domain and AAD
|
|
7
|
+
* so connector and CLI ciphertext are not interchangeable. The server is a
|
|
8
|
+
* mailbox: it stores only the JSON envelope.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
aesGcmDecrypt,
|
|
13
|
+
aesGcmEncrypt,
|
|
14
|
+
fromB64,
|
|
15
|
+
hkdfSha256,
|
|
16
|
+
randomBytes,
|
|
17
|
+
toB64,
|
|
18
|
+
zero,
|
|
19
|
+
} from "./crypto";
|
|
20
|
+
import type { TX25519Keypair } from "./handoff";
|
|
21
|
+
import {
|
|
22
|
+
generateResumableX25519Keypair,
|
|
23
|
+
generateX25519Keypair,
|
|
24
|
+
importX25519PrivateKey,
|
|
25
|
+
} from "./handoff";
|
|
26
|
+
|
|
27
|
+
export const CLI_AUTH_SEAL_DOMAIN = "openllm-cli-auth-seal-v1";
|
|
28
|
+
|
|
29
|
+
export type TCliAuthSealBinding = {
|
|
30
|
+
readonly userId: string;
|
|
31
|
+
readonly authorizationId: string;
|
|
32
|
+
/** Recipient (CLI) X25519 public key, base64 SPKI DER. */
|
|
33
|
+
readonly recipientPublicKeyB64: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type TCliAuthSealed = {
|
|
37
|
+
readonly v: 1;
|
|
38
|
+
readonly epk: string;
|
|
39
|
+
readonly nonce: string;
|
|
40
|
+
readonly ct: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const aad = (binding: TCliAuthSealBinding): Uint8Array =>
|
|
44
|
+
new TextEncoder().encode(
|
|
45
|
+
JSON.stringify([
|
|
46
|
+
CLI_AUTH_SEAL_DOMAIN,
|
|
47
|
+
binding.userId,
|
|
48
|
+
binding.authorizationId,
|
|
49
|
+
binding.recipientPublicKeyB64,
|
|
50
|
+
]),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const decode = (value: unknown): Uint8Array => {
|
|
54
|
+
if (
|
|
55
|
+
typeof value !== "string" ||
|
|
56
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
|
|
57
|
+
value,
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
throw new Error("Invalid sealed envelope encoding");
|
|
61
|
+
const bytes = fromB64(value);
|
|
62
|
+
if (toB64(bytes) !== value)
|
|
63
|
+
throw new Error("Invalid sealed envelope encoding");
|
|
64
|
+
return bytes;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const deriveKey = async (
|
|
68
|
+
privateKey: CryptoKey,
|
|
69
|
+
peerB64: string,
|
|
70
|
+
epk: string,
|
|
71
|
+
recipient: string,
|
|
72
|
+
): Promise<Uint8Array> => {
|
|
73
|
+
const peer = await crypto.subtle.importKey(
|
|
74
|
+
"spki",
|
|
75
|
+
decode(peerB64) as BufferSource,
|
|
76
|
+
{ name: "X25519" },
|
|
77
|
+
false,
|
|
78
|
+
[],
|
|
79
|
+
);
|
|
80
|
+
const shared = new Uint8Array(
|
|
81
|
+
await crypto.subtle.deriveBits(
|
|
82
|
+
{ name: "X25519", public: peer },
|
|
83
|
+
privateKey,
|
|
84
|
+
256,
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
return await hkdfSha256(
|
|
89
|
+
shared,
|
|
90
|
+
new Uint8Array(0),
|
|
91
|
+
JSON.stringify([CLI_AUTH_SEAL_DOMAIN, epk, recipient]),
|
|
92
|
+
32,
|
|
93
|
+
);
|
|
94
|
+
} finally {
|
|
95
|
+
zero(shared);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Caller retains ownership of plaintext; the temporary copy is wiped. */
|
|
100
|
+
export const sealCliAuth = async (
|
|
101
|
+
binding: TCliAuthSealBinding,
|
|
102
|
+
plaintext: Uint8Array,
|
|
103
|
+
): Promise<TCliAuthSealed> => {
|
|
104
|
+
const eph = await generateX25519Keypair();
|
|
105
|
+
const key = await deriveKey(
|
|
106
|
+
eph.privateKey,
|
|
107
|
+
binding.recipientPublicKeyB64,
|
|
108
|
+
eph.publicKeyB64,
|
|
109
|
+
binding.recipientPublicKeyB64,
|
|
110
|
+
);
|
|
111
|
+
const copy = new Uint8Array(plaintext);
|
|
112
|
+
try {
|
|
113
|
+
const nonce = randomBytes(12);
|
|
114
|
+
return {
|
|
115
|
+
v: 1,
|
|
116
|
+
epk: eph.publicKeyB64,
|
|
117
|
+
nonce: toB64(nonce),
|
|
118
|
+
ct: toB64(await aesGcmEncrypt(key, nonce, copy, aad(binding))),
|
|
119
|
+
};
|
|
120
|
+
} finally {
|
|
121
|
+
zero(key);
|
|
122
|
+
zero(copy);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Caller owns the returned plaintext and must wipe it when finished. */
|
|
127
|
+
export const openCliAuth = async (
|
|
128
|
+
binding: TCliAuthSealBinding,
|
|
129
|
+
sealed: TCliAuthSealed,
|
|
130
|
+
privateKey: CryptoKey,
|
|
131
|
+
): Promise<Uint8Array> => {
|
|
132
|
+
if (typeof sealed !== "object" || sealed === null || sealed.v !== 1)
|
|
133
|
+
throw new Error("Invalid sealed envelope");
|
|
134
|
+
const nonce = decode(sealed.nonce);
|
|
135
|
+
const ct = decode(sealed.ct);
|
|
136
|
+
if (nonce.length !== 12 || ct.length < 16 || typeof sealed.epk !== "string")
|
|
137
|
+
throw new Error("Invalid sealed envelope");
|
|
138
|
+
const key = await deriveKey(
|
|
139
|
+
privateKey,
|
|
140
|
+
sealed.epk,
|
|
141
|
+
sealed.epk,
|
|
142
|
+
binding.recipientPublicKeyB64,
|
|
143
|
+
);
|
|
144
|
+
try {
|
|
145
|
+
return await aesGcmDecrypt(key, nonce, ct, aad(binding));
|
|
146
|
+
} finally {
|
|
147
|
+
zero(key);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/** Alias kept for CLI call-site parity with the old `cli-auth-crypto` names. */
|
|
152
|
+
export const generateCliAuthKeypair = generateX25519Keypair;
|
|
153
|
+
/** Alias kept for CLI call-site parity with the old `cli-auth-crypto` names. */
|
|
154
|
+
export const openCliAuthSealed = openCliAuth;
|
|
155
|
+
export const importCliAuthPrivateKey = importX25519PrivateKey;
|
|
156
|
+
export const generateResumableCliAuthKeypair = generateResumableX25519Keypair;
|
|
157
|
+
export type TCliAuthKeypair = TX25519Keypair;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X25519 sealed-box for daemon credentials (browser ↔ daemon).
|
|
3
|
+
*
|
|
4
|
+
* Wire: `base64(JSON{ epk, iv, ct })` where `epk` is the ephemeral X25519
|
|
5
|
+
* public key (SPKI DER, base64), `iv` is a 12-byte AES-GCM nonce, and `ct` is
|
|
6
|
+
* ciphertext‖tag. Scheme: ephemeral X25519 → ECDH → HKDF-SHA256(salt = ∅,
|
|
7
|
+
* info = "openllm-cred-seal-v1", 32 bytes) → AES-256-GCM.
|
|
8
|
+
*
|
|
9
|
+
* Byte-identical with the historical `lib/daemon-seal.ts` /
|
|
10
|
+
* `packages/cli/daemon/src/keypair.ts` sealed-box so cloud-relayed blobs stay
|
|
11
|
+
* interoperable.
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
aesGcmDecrypt,
|
|
15
|
+
aesGcmEncrypt,
|
|
16
|
+
fromB64,
|
|
17
|
+
hkdfSha256,
|
|
18
|
+
randomBytes,
|
|
19
|
+
toB64,
|
|
20
|
+
zero,
|
|
21
|
+
} from "./crypto";
|
|
22
|
+
import type { TX25519Keypair } from "./handoff";
|
|
23
|
+
import { generateX25519Keypair } from "./handoff";
|
|
24
|
+
|
|
25
|
+
export const CRED_SEAL_HKDF_INFO = "openllm-cred-seal-v1";
|
|
26
|
+
|
|
27
|
+
/** Ephemeral X25519 pair used as an RTC answer seal recipient. */
|
|
28
|
+
export type TEphKeypair = TX25519Keypair;
|
|
29
|
+
|
|
30
|
+
export const generateEphKeypair = generateX25519Keypair;
|
|
31
|
+
|
|
32
|
+
const deriveCredKey = async (
|
|
33
|
+
privateKey: CryptoKey,
|
|
34
|
+
peerSpkiB64: string,
|
|
35
|
+
): Promise<Uint8Array> => {
|
|
36
|
+
const peer = await crypto.subtle.importKey(
|
|
37
|
+
"spki",
|
|
38
|
+
fromB64(peerSpkiB64) as BufferSource,
|
|
39
|
+
{ name: "X25519" },
|
|
40
|
+
false,
|
|
41
|
+
[],
|
|
42
|
+
);
|
|
43
|
+
const shared = new Uint8Array(
|
|
44
|
+
await crypto.subtle.deriveBits(
|
|
45
|
+
{ name: "X25519", public: peer },
|
|
46
|
+
privateKey,
|
|
47
|
+
256,
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
try {
|
|
51
|
+
return await hkdfSha256(shared, new Uint8Array(0), CRED_SEAL_HKDF_INFO, 32);
|
|
52
|
+
} finally {
|
|
53
|
+
zero(shared);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Seal `plaintext` to a recipient's X25519 public key (SPKI DER, base64). */
|
|
58
|
+
export const sealToDaemon = async (
|
|
59
|
+
recipientPubB64SpkiDer: string,
|
|
60
|
+
plaintext: string,
|
|
61
|
+
): Promise<string> => {
|
|
62
|
+
const subtle = globalThis.crypto.subtle;
|
|
63
|
+
const recipient = await subtle.importKey(
|
|
64
|
+
"spki",
|
|
65
|
+
fromB64(recipientPubB64SpkiDer) as BufferSource,
|
|
66
|
+
{ name: "X25519" },
|
|
67
|
+
false,
|
|
68
|
+
[],
|
|
69
|
+
);
|
|
70
|
+
// Ephemeral keypair — extractable so we can publish its public key as `epk`.
|
|
71
|
+
const eph = (await subtle.generateKey({ name: "X25519" }, true, [
|
|
72
|
+
"deriveBits",
|
|
73
|
+
])) as CryptoKeyPair;
|
|
74
|
+
const shared = new Uint8Array(
|
|
75
|
+
await subtle.deriveBits(
|
|
76
|
+
{ name: "X25519", public: recipient },
|
|
77
|
+
eph.privateKey,
|
|
78
|
+
256,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
let key: Uint8Array;
|
|
82
|
+
try {
|
|
83
|
+
key = await hkdfSha256(shared, new Uint8Array(0), CRED_SEAL_HKDF_INFO, 32);
|
|
84
|
+
} finally {
|
|
85
|
+
zero(shared);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const iv = randomBytes(12);
|
|
89
|
+
const ct = await aesGcmEncrypt(
|
|
90
|
+
key,
|
|
91
|
+
iv,
|
|
92
|
+
new TextEncoder().encode(plaintext),
|
|
93
|
+
);
|
|
94
|
+
const epk = new Uint8Array(await subtle.exportKey("spki", eph.publicKey));
|
|
95
|
+
const packed = { epk: toB64(epk), iv: toB64(iv), ct: toB64(ct) };
|
|
96
|
+
return toB64(new TextEncoder().encode(JSON.stringify(packed)));
|
|
97
|
+
} finally {
|
|
98
|
+
zero(key);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Open a cred-seal blob with any X25519 private key (daemon identity or eph).
|
|
104
|
+
* Null on any failure.
|
|
105
|
+
*/
|
|
106
|
+
export const openCredSealed = async (
|
|
107
|
+
sealedB64: string,
|
|
108
|
+
privateKey: CryptoKey,
|
|
109
|
+
): Promise<string | null> => {
|
|
110
|
+
try {
|
|
111
|
+
const packed: unknown = JSON.parse(
|
|
112
|
+
new TextDecoder().decode(fromB64(sealedB64)),
|
|
113
|
+
);
|
|
114
|
+
if (packed === null || typeof packed !== "object") return null;
|
|
115
|
+
const { epk, iv, ct } = packed as {
|
|
116
|
+
epk?: unknown;
|
|
117
|
+
iv?: unknown;
|
|
118
|
+
ct?: unknown;
|
|
119
|
+
};
|
|
120
|
+
if (
|
|
121
|
+
typeof epk !== "string" ||
|
|
122
|
+
typeof iv !== "string" ||
|
|
123
|
+
typeof ct !== "string"
|
|
124
|
+
) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const key = await deriveCredKey(privateKey, epk);
|
|
128
|
+
try {
|
|
129
|
+
const plain = await aesGcmDecrypt(key, fromB64(iv), fromB64(ct));
|
|
130
|
+
return new TextDecoder().decode(plain);
|
|
131
|
+
} finally {
|
|
132
|
+
zero(key);
|
|
133
|
+
}
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Open a sealed blob with an in-memory ephemeral private key (RTC answer path).
|
|
141
|
+
* Alias of {@link openCredSealed}.
|
|
142
|
+
*/
|
|
143
|
+
export const openSealedFromEph = (
|
|
144
|
+
sealedB64: string,
|
|
145
|
+
ephPrivateKey: CryptoKey,
|
|
146
|
+
): Promise<string | null> => openCredSealed(sealedB64, ephPrivateKey);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aesGcmDecrypt,
|
|
3
|
+
aesGcmEncrypt,
|
|
4
|
+
fromB64,
|
|
5
|
+
randomBytes,
|
|
6
|
+
toB64,
|
|
7
|
+
} from "./crypto";
|
|
8
|
+
|
|
9
|
+
const NONCE_BYTES = 12;
|
|
10
|
+
|
|
11
|
+
export type TEncryptedCredential = {
|
|
12
|
+
readonly ciphertext: string;
|
|
13
|
+
readonly nonce: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Encrypt a credential plaintext under the user's DEK (root key).
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Seal vault data with {@link sealVaultText} /
|
|
20
|
+
* {@link sealVaultBytes} from `./vault-item` under the matching branch
|
|
21
|
+
* (`credentials`, `memory`, `chats`, `apps`, `keys`, `teams`). Kept for
|
|
22
|
+
* legacy-path tests and the one-week read sunset of untagged rows.
|
|
23
|
+
*/
|
|
24
|
+
export const encryptCredential = async (
|
|
25
|
+
dek: Uint8Array,
|
|
26
|
+
plaintext: string,
|
|
27
|
+
): Promise<TEncryptedCredential> => {
|
|
28
|
+
const nonce = randomBytes(NONCE_BYTES);
|
|
29
|
+
const ct = await aesGcmEncrypt(
|
|
30
|
+
dek,
|
|
31
|
+
nonce,
|
|
32
|
+
new TextEncoder().encode(plaintext),
|
|
33
|
+
);
|
|
34
|
+
return { ciphertext: toB64(ct), nonce: toB64(nonce) };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Decrypt a credential row sealed directly under the DEK.
|
|
39
|
+
*
|
|
40
|
+
* @deprecated Open vault data with {@link openVaultText} /
|
|
41
|
+
* {@link openVaultBytes} from `./vault-item` (handles both tree-tagged
|
|
42
|
+
* and legacy untagged items). Kept for legacy-path tests.
|
|
43
|
+
*/
|
|
44
|
+
export const decryptCredential = async (
|
|
45
|
+
dek: Uint8Array,
|
|
46
|
+
ciphertextB64: string,
|
|
47
|
+
nonceB64: string,
|
|
48
|
+
): Promise<string> => {
|
|
49
|
+
const pt = await aesGcmDecrypt(
|
|
50
|
+
dek,
|
|
51
|
+
fromB64(nonceB64),
|
|
52
|
+
fromB64(ciphertextB64),
|
|
53
|
+
);
|
|
54
|
+
return new TextDecoder().decode(pt);
|
|
55
|
+
};
|