@openllmsh/sdk 0.0.0-stage → 2.10.12-alpha.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/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/handoff.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device handoff: an unlocked device seals the DEK (and, when it holds one,
|
|
3
|
+
* the recovery phrase) to a NEW device's ephemeral X25519 key, so the new
|
|
4
|
+
* device unlocks without the phrase being typed. The server relays only the
|
|
5
|
+
* public keys and the ciphertext. Design: `docs/plans/vault-device-handoff.md`.
|
|
6
|
+
*
|
|
7
|
+
* Construction:
|
|
8
|
+
* shared = X25519(approver_eph, requester_pub)
|
|
9
|
+
* key = HKDF-SHA256(shared, salt = utf8(request_id), info = binding, 32)
|
|
10
|
+
* sealed = AES-256-GCM(key, nonce, JSON{ v, user_id, request_id,
|
|
11
|
+
* vault_version, dek, phrase? })
|
|
12
|
+
* where `binding` names the account, the request, the vault generation and
|
|
13
|
+
* BOTH public keys, so a ciphertext moved onto any other request, account,
|
|
14
|
+
* generation or key pair derives a different key and fails its auth tag.
|
|
15
|
+
*
|
|
16
|
+
* Pure WebCrypto, bytes-in/bytes-out — runs in the browser and in Bun alike,
|
|
17
|
+
* like the rest of this package. X25519 is the same primitive the browser
|
|
18
|
+
* already relies on for daemon sealing (`./cred-seal.ts`).
|
|
19
|
+
*/
|
|
20
|
+
import {
|
|
21
|
+
aesGcmDecrypt,
|
|
22
|
+
aesGcmEncrypt,
|
|
23
|
+
fromB64,
|
|
24
|
+
hkdfSha256,
|
|
25
|
+
randomBytes,
|
|
26
|
+
toB64,
|
|
27
|
+
zero,
|
|
28
|
+
} from "./crypto";
|
|
29
|
+
import { unlockDek } from "./derive";
|
|
30
|
+
import {
|
|
31
|
+
deriveVaultDek,
|
|
32
|
+
deriveVaultKeyId,
|
|
33
|
+
SEED_BYTES,
|
|
34
|
+
seedToPhrase,
|
|
35
|
+
} from "./seed";
|
|
36
|
+
|
|
37
|
+
export const HANDOFF_HKDF_INFO = "openllm-vault-handoff-v1";
|
|
38
|
+
export const HANDOFF_CODE_INFO = "openllm-vault-handoff-code-v1";
|
|
39
|
+
/** Digits in the verification code both screens show. */
|
|
40
|
+
export const HANDOFF_CODE_DIGITS = 6;
|
|
41
|
+
|
|
42
|
+
const NONCE_BYTES = 12;
|
|
43
|
+
/** v2 carries the vault seed only; v1 (DEK + phrase) is refused. */
|
|
44
|
+
const PAYLOAD_VERSION = 2;
|
|
45
|
+
|
|
46
|
+
const subtle = (): SubtleCrypto => {
|
|
47
|
+
const s = globalThis.crypto?.subtle;
|
|
48
|
+
if (s === undefined) {
|
|
49
|
+
throw new Error("WebCrypto SubtleCrypto is not available in this runtime");
|
|
50
|
+
}
|
|
51
|
+
return s;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** An X25519 key pair whose private half cannot leave this runtime. */
|
|
55
|
+
export type TX25519Keypair = {
|
|
56
|
+
/** SPKI DER, base64. */
|
|
57
|
+
readonly publicKeyB64: string;
|
|
58
|
+
/** Non-extractable; held in memory only. */
|
|
59
|
+
readonly privateKey: CryptoKey;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Mint an ephemeral X25519 key pair. `generateKey`'s extractable flag covers
|
|
64
|
+
* both halves, so the public SPKI is exported first and the private half is
|
|
65
|
+
* re-imported non-extractable: nothing on this page can read its bytes back.
|
|
66
|
+
*/
|
|
67
|
+
export const generateX25519Keypair = async (): Promise<TX25519Keypair> => {
|
|
68
|
+
const pair = (await subtle().generateKey({ name: "X25519" }, true, [
|
|
69
|
+
"deriveBits",
|
|
70
|
+
])) as CryptoKeyPair;
|
|
71
|
+
const spki = new Uint8Array(await subtle().exportKey("spki", pair.publicKey));
|
|
72
|
+
const pkcs8 = new Uint8Array(
|
|
73
|
+
await subtle().exportKey("pkcs8", pair.privateKey),
|
|
74
|
+
);
|
|
75
|
+
try {
|
|
76
|
+
const privateKey = await importX25519PrivateKey(toB64(pkcs8));
|
|
77
|
+
return { publicKeyB64: toB64(spki), privateKey };
|
|
78
|
+
} finally {
|
|
79
|
+
zero(pkcs8);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Re-import a PKCS#8 X25519 private key as non-extractable. */
|
|
84
|
+
export const importX25519PrivateKey = async (
|
|
85
|
+
pkcs8B64: string,
|
|
86
|
+
): Promise<CryptoKey> => {
|
|
87
|
+
const pkcs8 = fromB64(pkcs8B64);
|
|
88
|
+
try {
|
|
89
|
+
return await subtle().importKey(
|
|
90
|
+
"pkcs8",
|
|
91
|
+
pkcs8 as BufferSource,
|
|
92
|
+
{ name: "X25519" },
|
|
93
|
+
false,
|
|
94
|
+
["deriveBits"],
|
|
95
|
+
);
|
|
96
|
+
} finally {
|
|
97
|
+
zero(pkcs8);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* X25519 key pair for resume flows: the private half is also returned as
|
|
103
|
+
* PKCS#8 base64 so the caller can persist it (0600) and re-import later. The
|
|
104
|
+
* in-memory key stays non-extractable.
|
|
105
|
+
*/
|
|
106
|
+
export const generateResumableX25519Keypair = async (): Promise<
|
|
107
|
+
TX25519Keypair & { readonly privateKeyPkcs8B64: string }
|
|
108
|
+
> => {
|
|
109
|
+
const pair = (await subtle().generateKey({ name: "X25519" }, true, [
|
|
110
|
+
"deriveBits",
|
|
111
|
+
])) as CryptoKeyPair;
|
|
112
|
+
const spki = new Uint8Array(await subtle().exportKey("spki", pair.publicKey));
|
|
113
|
+
const pkcs8 = new Uint8Array(
|
|
114
|
+
await subtle().exportKey("pkcs8", pair.privateKey),
|
|
115
|
+
);
|
|
116
|
+
try {
|
|
117
|
+
const privateKeyPkcs8B64 = toB64(pkcs8);
|
|
118
|
+
return {
|
|
119
|
+
publicKeyB64: toB64(spki),
|
|
120
|
+
privateKey: await importX25519PrivateKey(privateKeyPkcs8B64),
|
|
121
|
+
privateKeyPkcs8B64,
|
|
122
|
+
};
|
|
123
|
+
} finally {
|
|
124
|
+
zero(pkcs8);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** What the ciphertext is bound to. Every field is checked on open. */
|
|
129
|
+
export type THandoffBinding = {
|
|
130
|
+
readonly userId: string;
|
|
131
|
+
readonly requestId: string;
|
|
132
|
+
readonly vaultVersion: number;
|
|
133
|
+
/** The new device's public key, SPKI DER base64. */
|
|
134
|
+
readonly requesterPublicKeyB64: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* What travels: the vault seed, and nothing else — the new device derives the
|
|
139
|
+
* vault key (and the device-control key) from it, exactly as an unlock does
|
|
140
|
+
* (docs/plans/seed-only-vault.md).
|
|
141
|
+
*/
|
|
142
|
+
export type THandoffPayload = {
|
|
143
|
+
readonly seed: Uint8Array;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** The wire form of a sealed handoff — three base64 strings. */
|
|
147
|
+
export type TSealedHandoff = {
|
|
148
|
+
/** The approver's ephemeral X25519 public key, SPKI DER base64. */
|
|
149
|
+
readonly approver_pubkey: string;
|
|
150
|
+
readonly nonce: string;
|
|
151
|
+
/** AES-GCM ciphertext with its 16-byte tag appended. */
|
|
152
|
+
readonly ciphertext: string;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* HKDF `info`: a JSON array, so no field can bleed into its neighbour the
|
|
157
|
+
* way a separator-joined string could (`"a|b" + "c"` vs `"a" + "b|c"`).
|
|
158
|
+
*/
|
|
159
|
+
const bindingInfo = (
|
|
160
|
+
binding: THandoffBinding,
|
|
161
|
+
approverPublicKeyB64: string,
|
|
162
|
+
): string =>
|
|
163
|
+
JSON.stringify([
|
|
164
|
+
HANDOFF_HKDF_INFO,
|
|
165
|
+
binding.userId,
|
|
166
|
+
binding.requestId,
|
|
167
|
+
binding.vaultVersion,
|
|
168
|
+
binding.requesterPublicKeyB64,
|
|
169
|
+
approverPublicKeyB64,
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
const importX25519Public = (spkiB64: string): Promise<CryptoKey> =>
|
|
173
|
+
subtle().importKey(
|
|
174
|
+
"spki",
|
|
175
|
+
fromB64(spkiB64) as BufferSource,
|
|
176
|
+
{ name: "X25519" },
|
|
177
|
+
false,
|
|
178
|
+
[],
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const deriveHandoffKey = async (
|
|
182
|
+
privateKey: CryptoKey,
|
|
183
|
+
peerPublicKeyB64: string,
|
|
184
|
+
binding: THandoffBinding,
|
|
185
|
+
approverPublicKeyB64: string,
|
|
186
|
+
): Promise<Uint8Array> => {
|
|
187
|
+
const peer = await importX25519Public(peerPublicKeyB64);
|
|
188
|
+
const shared = new Uint8Array(
|
|
189
|
+
await subtle().deriveBits(
|
|
190
|
+
{ name: "X25519", public: peer },
|
|
191
|
+
privateKey,
|
|
192
|
+
256,
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
try {
|
|
196
|
+
return await hkdfSha256(
|
|
197
|
+
shared,
|
|
198
|
+
new TextEncoder().encode(binding.requestId),
|
|
199
|
+
bindingInfo(binding, approverPublicKeyB64),
|
|
200
|
+
32,
|
|
201
|
+
);
|
|
202
|
+
} finally {
|
|
203
|
+
zero(shared);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Seal the vault seed to the requester. Run on the APPROVING device. The
|
|
209
|
+
* caller keeps ownership of `payload.seed` — it is copied into the plaintext,
|
|
210
|
+
* and the plaintext buffer is zeroed here.
|
|
211
|
+
*/
|
|
212
|
+
export const sealHandoff = async (
|
|
213
|
+
binding: THandoffBinding,
|
|
214
|
+
payload: THandoffPayload,
|
|
215
|
+
): Promise<TSealedHandoff> => {
|
|
216
|
+
if (payload.seed.length !== SEED_BYTES) {
|
|
217
|
+
throw new Error(`handoff seed must be ${SEED_BYTES} bytes`);
|
|
218
|
+
}
|
|
219
|
+
const eph = await generateX25519Keypair();
|
|
220
|
+
const key = await deriveHandoffKey(
|
|
221
|
+
eph.privateKey,
|
|
222
|
+
binding.requesterPublicKeyB64,
|
|
223
|
+
binding,
|
|
224
|
+
eph.publicKeyB64,
|
|
225
|
+
);
|
|
226
|
+
const plaintext = new TextEncoder().encode(
|
|
227
|
+
JSON.stringify({
|
|
228
|
+
v: PAYLOAD_VERSION,
|
|
229
|
+
user_id: binding.userId,
|
|
230
|
+
request_id: binding.requestId,
|
|
231
|
+
vault_version: binding.vaultVersion,
|
|
232
|
+
seed: toB64(payload.seed),
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
try {
|
|
236
|
+
const nonce = randomBytes(NONCE_BYTES);
|
|
237
|
+
const ciphertext = await aesGcmEncrypt(key, nonce, plaintext);
|
|
238
|
+
return {
|
|
239
|
+
approver_pubkey: eph.publicKeyB64,
|
|
240
|
+
nonce: toB64(nonce),
|
|
241
|
+
ciphertext: toB64(ciphertext),
|
|
242
|
+
};
|
|
243
|
+
} finally {
|
|
244
|
+
zero(key);
|
|
245
|
+
zero(plaintext);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
250
|
+
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Open a sealed handoff with the requester's private key. Run on the NEW
|
|
254
|
+
* device. Throws on any failure — a wrong key, a tampered byte, a ciphertext
|
|
255
|
+
* bound to another request/account/generation, or a malformed payload. The
|
|
256
|
+
* caller owns (and must eventually `zero()`) the seed.
|
|
257
|
+
*/
|
|
258
|
+
export const openHandoff = async (
|
|
259
|
+
binding: THandoffBinding,
|
|
260
|
+
sealed: TSealedHandoff,
|
|
261
|
+
requesterPrivateKey: CryptoKey,
|
|
262
|
+
): Promise<THandoffPayload> => {
|
|
263
|
+
const key = await deriveHandoffKey(
|
|
264
|
+
requesterPrivateKey,
|
|
265
|
+
sealed.approver_pubkey,
|
|
266
|
+
binding,
|
|
267
|
+
sealed.approver_pubkey,
|
|
268
|
+
);
|
|
269
|
+
let plaintext: Uint8Array;
|
|
270
|
+
try {
|
|
271
|
+
plaintext = await aesGcmDecrypt(
|
|
272
|
+
key,
|
|
273
|
+
fromB64(sealed.nonce),
|
|
274
|
+
fromB64(sealed.ciphertext),
|
|
275
|
+
);
|
|
276
|
+
} finally {
|
|
277
|
+
zero(key);
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
const parsed: unknown = JSON.parse(new TextDecoder().decode(plaintext));
|
|
281
|
+
if (isRecord(parsed) && parsed.v !== PAYLOAD_VERSION) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
"handoff payload version is outdated: reload the approving tab",
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
if (
|
|
287
|
+
!isRecord(parsed) ||
|
|
288
|
+
parsed.user_id !== binding.userId ||
|
|
289
|
+
parsed.request_id !== binding.requestId ||
|
|
290
|
+
parsed.vault_version !== binding.vaultVersion ||
|
|
291
|
+
typeof parsed.seed !== "string"
|
|
292
|
+
) {
|
|
293
|
+
throw new Error("handoff payload does not match its binding");
|
|
294
|
+
}
|
|
295
|
+
const seed = fromB64(parsed.seed);
|
|
296
|
+
if (seed.length !== SEED_BYTES) {
|
|
297
|
+
zero(seed);
|
|
298
|
+
throw new Error("handoff payload did not contain a vault seed");
|
|
299
|
+
}
|
|
300
|
+
return { seed };
|
|
301
|
+
} finally {
|
|
302
|
+
zero(plaintext);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* What the new device checks a handed-off seed against — the server-side
|
|
308
|
+
* anchor of the account's vault, by its format:
|
|
309
|
+
*
|
|
310
|
+
* - `seed`: the public `users.vault_key_id` — the seed must derive it;
|
|
311
|
+
* - `legacy` (until the sunset): `wrap_salt` + `wrapped_dek` — the seed's
|
|
312
|
+
* phrase must open them, and the vault key is the one inside.
|
|
313
|
+
*
|
|
314
|
+
* Neither anchor can be swapped by a session-cookie holder without a full,
|
|
315
|
+
* visible vault reset, so a seed that matches is this vault's seed.
|
|
316
|
+
*/
|
|
317
|
+
export type THandoffAnchor =
|
|
318
|
+
| { readonly kind: "seed"; readonly vaultKeyId: string }
|
|
319
|
+
| {
|
|
320
|
+
readonly kind: "legacy";
|
|
321
|
+
readonly wrapSaltB64: string;
|
|
322
|
+
readonly wrappedDekB64: string;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
/** An opened handoff the new device may install. The caller zeroes both. */
|
|
326
|
+
export type TAcceptedHandoff = {
|
|
327
|
+
readonly seed: Uint8Array;
|
|
328
|
+
readonly dek: Uint8Array;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Check an opened seed against the vault's anchor before the session gets it,
|
|
333
|
+
* and return the vault key it opens. Throws (the seed zeroed) when the seed
|
|
334
|
+
* belongs to another vault — an approval from somebody who does not hold this
|
|
335
|
+
* one.
|
|
336
|
+
*/
|
|
337
|
+
export const acceptHandoff = async (
|
|
338
|
+
opened: THandoffPayload,
|
|
339
|
+
anchor: THandoffAnchor,
|
|
340
|
+
): Promise<TAcceptedHandoff> => {
|
|
341
|
+
const { seed } = opened;
|
|
342
|
+
try {
|
|
343
|
+
if (anchor.kind === "seed") {
|
|
344
|
+
if ((await deriveVaultKeyId(seed)) !== anchor.vaultKeyId) {
|
|
345
|
+
throw new Error("handoff seed does not match this vault");
|
|
346
|
+
}
|
|
347
|
+
return { seed, dek: await deriveVaultDek(seed) };
|
|
348
|
+
}
|
|
349
|
+
let dek: Uint8Array;
|
|
350
|
+
try {
|
|
351
|
+
dek = await unlockDek(
|
|
352
|
+
seedToPhrase(seed),
|
|
353
|
+
anchor.wrapSaltB64,
|
|
354
|
+
anchor.wrappedDekB64,
|
|
355
|
+
);
|
|
356
|
+
} catch {
|
|
357
|
+
throw new Error("handoff seed does not open this vault");
|
|
358
|
+
}
|
|
359
|
+
return { seed, dek };
|
|
360
|
+
} catch (err) {
|
|
361
|
+
zero(seed);
|
|
362
|
+
throw err;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* The six-digit code both screens show. Derived from the request id AND the
|
|
368
|
+
* requester's public key: the key is posted before the server picks the id,
|
|
369
|
+
* so a client cannot grind a key pair whose code matches someone else's —
|
|
370
|
+
* each attempt costs a (rate-limited) new request.
|
|
371
|
+
*/
|
|
372
|
+
export const handoffVerificationCode = async (
|
|
373
|
+
requestId: string,
|
|
374
|
+
requesterPublicKeyB64: string,
|
|
375
|
+
): Promise<string> => {
|
|
376
|
+
const enc = new TextEncoder();
|
|
377
|
+
const label = enc.encode(HANDOFF_CODE_INFO);
|
|
378
|
+
const id = enc.encode(requestId);
|
|
379
|
+
const pub = fromB64(requesterPublicKeyB64);
|
|
380
|
+
const input = new Uint8Array(label.length + 1 + id.length + 1 + pub.length);
|
|
381
|
+
input.set(label, 0);
|
|
382
|
+
input.set(id, label.length + 1);
|
|
383
|
+
input.set(pub, label.length + 1 + id.length + 1);
|
|
384
|
+
const digest = new Uint8Array(
|
|
385
|
+
await subtle().digest("SHA-256", input as BufferSource),
|
|
386
|
+
);
|
|
387
|
+
const n =
|
|
388
|
+
(((digest[0] as number) << 24) |
|
|
389
|
+
((digest[1] as number) << 16) |
|
|
390
|
+
((digest[2] as number) << 8) |
|
|
391
|
+
(digest[3] as number)) >>>
|
|
392
|
+
0;
|
|
393
|
+
return (n % 10 ** HANDOFF_CODE_DIGITS)
|
|
394
|
+
.toString()
|
|
395
|
+
.padStart(HANDOFF_CODE_DIGITS, "0");
|
|
396
|
+
};
|
package/vault/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from "./api-key";
|
|
2
|
+
export * from "./argon2";
|
|
3
|
+
export * from "./cli-auth-seal";
|
|
4
|
+
export * from "./cred-seal";
|
|
5
|
+
export * from "./credential";
|
|
6
|
+
export * from "./crypto";
|
|
7
|
+
export * from "./daemon-attest";
|
|
8
|
+
export * from "./derive";
|
|
9
|
+
export * from "./device-access";
|
|
10
|
+
export * from "./device-anchor";
|
|
11
|
+
export * from "./device-control";
|
|
12
|
+
export * from "./handoff";
|
|
13
|
+
export * from "./passkey";
|
|
14
|
+
export * from "./phrase";
|
|
15
|
+
export * from "./pin";
|
|
16
|
+
export * from "./public-key-seal";
|
|
17
|
+
export * from "./seed";
|
|
18
|
+
export * from "./team";
|
|
19
|
+
export * from "./vault-item";
|
|
20
|
+
export * from "./vault-migrate-digest";
|
|
21
|
+
export * from "./wrapped";
|
package/vault/passkey.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aesGcmDecrypt,
|
|
3
|
+
aesGcmEncrypt,
|
|
4
|
+
fromB64,
|
|
5
|
+
hkdfSha256,
|
|
6
|
+
randomBytes,
|
|
7
|
+
toB64,
|
|
8
|
+
zero,
|
|
9
|
+
} from "./crypto";
|
|
10
|
+
import { joinSealed, splitSealed } from "./wrapped";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The third DEK wrapper, beside the recovery phrase (`./derive.ts`) and the PIN
|
|
14
|
+
* (`./pin.ts`): a passkey's WebAuthn PRF output.
|
|
15
|
+
*
|
|
16
|
+
* Pure bytes-in/bytes-out, like every other module here — no WebAuthn import.
|
|
17
|
+
* The ceremony that PRODUCES the PRF output is browser glue
|
|
18
|
+
* (`lib/vault/passkey-ceremony.ts`); this file only turns 32 bytes the
|
|
19
|
+
* authenticator returned into a wrap key and seals the DEK under it.
|
|
20
|
+
*
|
|
21
|
+
* Why HKDF and not Argon2id: the PRF output is the authenticator's
|
|
22
|
+
* HMAC-SHA-256 over a per-credential salt, keyed by a secret that never leaves
|
|
23
|
+
* the authenticator — 256 bits of entropy. A slow KDF buys nothing against a
|
|
24
|
+
* search that cannot be mounted, so unlock is instant. The PIN needs Argon2id
|
|
25
|
+
* because its keyspace is 10^4–10^6; this one is 2^256.
|
|
26
|
+
*
|
|
27
|
+
* Why the blob can live on the SERVER (`user_passkeys.wrapped_dek`) when the
|
|
28
|
+
* PIN blob never may (`docs/plans/vault-pin-unlock.md` §2): without the
|
|
29
|
+
* authenticator there is no PRF output, and without the PRF output the blob is
|
|
30
|
+
* as opaque as `users.wrapped_dek` is without the phrase. A database leak hands
|
|
31
|
+
* an attacker ciphertext and a public salt, nothing to guess.
|
|
32
|
+
*
|
|
33
|
+
* The blob is BOUND to the public facts its row is filed under — the
|
|
34
|
+
* credential id and the vault generation — as AES-GCM additional data. A row
|
|
35
|
+
* relabelled with another `vault_version` (a stale wrap passed off as current)
|
|
36
|
+
* or moved under another credential id fails its auth tag instead of handing
|
|
37
|
+
* back a DEK the session would then stamp with the wrong generation.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
export const PASSKEY_HKDF_INFO = "openllm-vault-passkey-v1";
|
|
41
|
+
/** `prf.eval.first` input — random per credential, public, stored on the row. */
|
|
42
|
+
export const PASSKEY_PRF_SALT_BYTES = 32;
|
|
43
|
+
/** The WebAuthn PRF extension always yields a 32-byte HMAC-SHA-256 output. */
|
|
44
|
+
const PRF_OUTPUT_BYTES = 32;
|
|
45
|
+
const NONCE_BYTES = 12;
|
|
46
|
+
const DEK_BYTES = 32;
|
|
47
|
+
|
|
48
|
+
/** What a passkey wrap is bound to — see the module comment. */
|
|
49
|
+
export type TPasskeyBinding = {
|
|
50
|
+
/** base64url credential id, exactly as stored in `user_passkeys.id`. */
|
|
51
|
+
readonly credentialId: string;
|
|
52
|
+
/** The `users.vault_version` the wrapped DEK belongs to. */
|
|
53
|
+
readonly vaultVersion: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** A fresh `prf.eval.first` salt for a credential being enrolled. */
|
|
57
|
+
export const newPasskeyPrfSalt = (): Uint8Array =>
|
|
58
|
+
randomBytes(PASSKEY_PRF_SALT_BYTES);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* HKDF info for the recovery phrase sealed under a passkey
|
|
62
|
+
* (`user_passkeys.sealed_phrase`, docs/plans/vault-phrase-sync.md). A separate
|
|
63
|
+
* info from {@link PASSKEY_HKDF_INFO}, so the phrase key and the DEK wrap key
|
|
64
|
+
* are independent although one PRF evaluation feeds both.
|
|
65
|
+
*/
|
|
66
|
+
export const PASSKEY_PHRASE_HKDF_INFO = "openllm-vault-passkey-phrase-v1";
|
|
67
|
+
|
|
68
|
+
const bindingAad = (
|
|
69
|
+
binding: TPasskeyBinding,
|
|
70
|
+
info: string = PASSKEY_HKDF_INFO,
|
|
71
|
+
): Uint8Array =>
|
|
72
|
+
new TextEncoder().encode(
|
|
73
|
+
`${info}|${binding.credentialId}|${binding.vaultVersion}`,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const requireLength = (
|
|
77
|
+
bytes: Uint8Array,
|
|
78
|
+
length: number,
|
|
79
|
+
label: string,
|
|
80
|
+
): void => {
|
|
81
|
+
if (bytes.length !== length) {
|
|
82
|
+
throw new Error(`${label} must be ${length} bytes`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* `HKDF-SHA256(prfOutput, salt = prfSalt, info = PASSKEY_HKDF_INFO, 32)`.
|
|
88
|
+
*
|
|
89
|
+
* The salt is the same bytes the authenticator was asked to evaluate, so the
|
|
90
|
+
* wrap key is tied to this credential's salt twice over: once inside the
|
|
91
|
+
* authenticator's HMAC, once here.
|
|
92
|
+
*/
|
|
93
|
+
const derivePasskeyWrapKey = (
|
|
94
|
+
prfOutput: Uint8Array,
|
|
95
|
+
prfSalt: Uint8Array,
|
|
96
|
+
info: string = PASSKEY_HKDF_INFO,
|
|
97
|
+
): Promise<Uint8Array> => {
|
|
98
|
+
requireLength(prfOutput, PRF_OUTPUT_BYTES, "PRF output");
|
|
99
|
+
requireLength(prfSalt, PASSKEY_PRF_SALT_BYTES, "PRF salt");
|
|
100
|
+
return hkdfSha256(prfOutput, prfSalt, info, 32);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Seal `dek` under a passkey's PRF output. Returns base64 `IV || ct+tag` — the
|
|
105
|
+
* shared layout (`./wrapped.ts`), without a `v<n>:` KDF stamp because there is
|
|
106
|
+
* no Argon2 parameter set to record; the HKDF info string carries the version.
|
|
107
|
+
*
|
|
108
|
+
* Never zeroes its inputs: the caller owns the DEK and the PRF output, and
|
|
109
|
+
* zeroes them in its own `finally`.
|
|
110
|
+
*/
|
|
111
|
+
export const wrapDekWithPrf = async (
|
|
112
|
+
dek: Uint8Array,
|
|
113
|
+
prfOutput: Uint8Array,
|
|
114
|
+
prfSalt: Uint8Array,
|
|
115
|
+
binding: TPasskeyBinding,
|
|
116
|
+
): Promise<string> => {
|
|
117
|
+
requireLength(dek, DEK_BYTES, "DEK");
|
|
118
|
+
const wrapKey = await derivePasskeyWrapKey(prfOutput, prfSalt);
|
|
119
|
+
try {
|
|
120
|
+
const nonce = randomBytes(NONCE_BYTES);
|
|
121
|
+
const ciphertext = await aesGcmEncrypt(
|
|
122
|
+
wrapKey,
|
|
123
|
+
nonce,
|
|
124
|
+
dek,
|
|
125
|
+
bindingAad(binding),
|
|
126
|
+
);
|
|
127
|
+
return toB64(joinSealed(nonce, ciphertext));
|
|
128
|
+
} finally {
|
|
129
|
+
zero(wrapKey);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Open a passkey wrap. Throws on a bad auth tag — a different PRF output (the
|
|
135
|
+
* wrong credential, or an authenticator whose PRF value diverged), another
|
|
136
|
+
* salt, or a row whose binding was changed. Callers degrade to PIN / phrase.
|
|
137
|
+
*/
|
|
138
|
+
export const unwrapDekWithPrf = async (
|
|
139
|
+
wrappedB64: string,
|
|
140
|
+
prfOutput: Uint8Array,
|
|
141
|
+
prfSalt: Uint8Array,
|
|
142
|
+
binding: TPasskeyBinding,
|
|
143
|
+
): Promise<Uint8Array> => {
|
|
144
|
+
const { nonce, ciphertext } = splitSealed(
|
|
145
|
+
fromB64(wrappedB64),
|
|
146
|
+
"passkey wrap",
|
|
147
|
+
);
|
|
148
|
+
const wrapKey = await derivePasskeyWrapKey(prfOutput, prfSalt);
|
|
149
|
+
try {
|
|
150
|
+
const dek = await aesGcmDecrypt(
|
|
151
|
+
wrapKey,
|
|
152
|
+
nonce,
|
|
153
|
+
ciphertext,
|
|
154
|
+
bindingAad(binding),
|
|
155
|
+
);
|
|
156
|
+
if (dek.length !== DEK_BYTES) {
|
|
157
|
+
zero(dek);
|
|
158
|
+
throw new Error("passkey wrap did not contain a 32-byte key");
|
|
159
|
+
}
|
|
160
|
+
return dek;
|
|
161
|
+
} finally {
|
|
162
|
+
zero(wrapKey);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Seal the recovery phrase under a passkey's PRF output, for
|
|
168
|
+
* `user_passkeys.sealed_phrase` (docs/plans/vault-phrase-sync.md).
|
|
169
|
+
*
|
|
170
|
+
* Why the PRF and never the DEK: the server holds the DEK transiently on every
|
|
171
|
+
* `sk-llm` request (`dek_for_key`), so a server-side copy under the DEK would
|
|
172
|
+
* be one the server can open — and the phrase is more than the DEK, it also
|
|
173
|
+
* derives the device-control seed the server must never reach. The PRF output
|
|
174
|
+
* never leaves the browser.
|
|
175
|
+
*
|
|
176
|
+
* Same layout and binding as {@link wrapDekWithPrf}, under
|
|
177
|
+
* {@link PASSKEY_PHRASE_HKDF_INFO}. The phrase is stored normalised (trimmed,
|
|
178
|
+
* as `sealPhraseKeep` does). Never zeroes its inputs.
|
|
179
|
+
*/
|
|
180
|
+
export const sealPhraseWithPrf = async (
|
|
181
|
+
phrase: string,
|
|
182
|
+
prfOutput: Uint8Array,
|
|
183
|
+
prfSalt: Uint8Array,
|
|
184
|
+
binding: TPasskeyBinding,
|
|
185
|
+
): Promise<string> => {
|
|
186
|
+
const plaintext = new TextEncoder().encode(phrase.trim());
|
|
187
|
+
if (plaintext.length === 0) throw new Error("phrase must not be empty");
|
|
188
|
+
const key = await derivePasskeyWrapKey(
|
|
189
|
+
prfOutput,
|
|
190
|
+
prfSalt,
|
|
191
|
+
PASSKEY_PHRASE_HKDF_INFO,
|
|
192
|
+
);
|
|
193
|
+
try {
|
|
194
|
+
const nonce = randomBytes(NONCE_BYTES);
|
|
195
|
+
const ciphertext = await aesGcmEncrypt(
|
|
196
|
+
key,
|
|
197
|
+
nonce,
|
|
198
|
+
plaintext,
|
|
199
|
+
bindingAad(binding, PASSKEY_PHRASE_HKDF_INFO),
|
|
200
|
+
);
|
|
201
|
+
return toB64(joinSealed(nonce, ciphertext));
|
|
202
|
+
} finally {
|
|
203
|
+
zero(key);
|
|
204
|
+
zero(plaintext);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Open a {@link sealPhraseWithPrf} copy. Throws on a bad auth tag — another
|
|
210
|
+
* credential's PRF, a diverged PRF value, another vault generation, or a DEK
|
|
211
|
+
* wrap passed off as a phrase copy (the info strings differ).
|
|
212
|
+
*/
|
|
213
|
+
export const openPhraseWithPrf = async (
|
|
214
|
+
sealedB64: string,
|
|
215
|
+
prfOutput: Uint8Array,
|
|
216
|
+
prfSalt: Uint8Array,
|
|
217
|
+
binding: TPasskeyBinding,
|
|
218
|
+
): Promise<string> => {
|
|
219
|
+
const { nonce, ciphertext } = splitSealed(
|
|
220
|
+
fromB64(sealedB64),
|
|
221
|
+
"passkey phrase",
|
|
222
|
+
);
|
|
223
|
+
const key = await derivePasskeyWrapKey(
|
|
224
|
+
prfOutput,
|
|
225
|
+
prfSalt,
|
|
226
|
+
PASSKEY_PHRASE_HKDF_INFO,
|
|
227
|
+
);
|
|
228
|
+
try {
|
|
229
|
+
const plaintext = await aesGcmDecrypt(
|
|
230
|
+
key,
|
|
231
|
+
nonce,
|
|
232
|
+
ciphertext,
|
|
233
|
+
bindingAad(binding, PASSKEY_PHRASE_HKDF_INFO),
|
|
234
|
+
);
|
|
235
|
+
try {
|
|
236
|
+
return new TextDecoder().decode(plaintext);
|
|
237
|
+
} finally {
|
|
238
|
+
zero(plaintext);
|
|
239
|
+
}
|
|
240
|
+
} finally {
|
|
241
|
+
zero(key);
|
|
242
|
+
}
|
|
243
|
+
};
|