@jini-ai/platform 0.7.3-next.2 → 0.7.4
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/CHANGELOG.md +7 -0
- package/README.md +13 -0
- package/dist/download-lock.d.ts +3 -1
- package/dist/download-lock.js +4 -6
- package/dist/download-maintenance.js +6 -6
- package/dist/download-state.js +17 -14
- package/dist/download-store.d.ts +34 -10
- package/dist/download-store.js +24 -20
- package/dist/download-target.d.ts +6 -2
- package/dist/download-target.js +7 -7
- package/dist/download-transfer.js +18 -12
- package/dist/download.js +4 -4
- package/dist/fetch-with-timeout.d.ts +0 -53
- package/dist/fetch-with-timeout.js +62 -13
- package/dist/fs/directory-running-lock.d.ts +4 -0
- package/dist/fs/directory-running-lock.js +8 -1
- package/dist/fs/directory-workspace.d.ts +2 -1
- package/dist/fs/directory-workspace.js +2 -2
- package/dist/fs/durable-json.d.ts +3 -16
- package/dist/fs/durable-json.js +4 -2
- package/dist/fs/guarded-reader.d.ts +10 -0
- package/dist/fs/guarded-reader.js +34 -1
- package/dist/fs/index.d.ts +4 -0
- package/dist/fs/index.js +4 -0
- package/dist/fs/leased-directory-move.d.ts +49 -0
- package/dist/fs/leased-directory-move.js +31 -0
- package/dist/fs/owned-temp-root.d.ts +74 -0
- package/dist/fs/owned-temp-root.js +203 -0
- package/dist/fs/recent-directories.d.ts +2 -1
- package/dist/fs/resolve-directory-target.d.ts +33 -0
- package/dist/fs/resolve-directory-target.js +58 -0
- package/dist/fs/staged-file.d.ts +40 -0
- package/dist/fs/staged-file.js +75 -0
- package/dist/fs/strict-containment.d.ts +14 -0
- package/dist/fs/strict-containment.js +14 -0
- package/dist/image/png-encode.d.ts +41 -0
- package/dist/image/png-encode.js +96 -0
- package/dist/index.d.ts +3 -1
- package/dist/mail/email-template-agent-tools.d.ts +150 -0
- package/dist/mail/email-template-agent-tools.js +86 -0
- package/dist/mail/email-template-tool-registrations.d.ts +73 -0
- package/dist/mail/email-template-tool-registrations.js +66 -0
- package/dist/mail/email-template.js +3 -7
- package/dist/mail/feedback-route.d.ts +50 -0
- package/dist/mail/feedback-route.js +46 -0
- package/dist/mail/feedback-setup.d.ts +44 -0
- package/dist/mail/feedback-setup.js +53 -0
- package/dist/mail/feedback-sources.d.ts +67 -0
- package/dist/mail/feedback-sources.js +42 -0
- package/dist/mail/index.d.ts +10 -1
- package/dist/mail/index.js +4 -0
- package/dist/mail/mail-status.d.ts +32 -0
- package/dist/mail/mail-status.js +2 -0
- package/dist/mail/positional-purpose-gate.d.ts +14 -0
- package/dist/mail/positional-purpose-gate.js +18 -0
- package/dist/mail/purpose-gate-probe.d.ts +18 -0
- package/dist/mail/purpose-gate-probe.js +22 -0
- package/dist/mail/purpose-scoped-mailer.d.ts +4 -0
- package/dist/mail/purpose-scoped-mailer.js +4 -3
- package/dist/mail/resolve-mailer.d.ts +13 -1
- package/dist/mail/resolve-mailer.js +11 -5
- package/dist/mail/sql/activity.repo.d.ts +20 -0
- package/dist/mail/sql/activity.repo.js +133 -0
- package/dist/mail/sql/attempts.repo.d.ts +17 -0
- package/dist/mail/sql/attempts.repo.js +32 -0
- package/dist/mail/sql/capture.repo.d.ts +69 -0
- package/dist/mail/sql/capture.repo.js +119 -0
- package/dist/mail/sql/feedback-inbox.repo.d.ts +12 -0
- package/dist/mail/sql/feedback-inbox.repo.js +32 -0
- package/dist/mail/sql/index.d.ts +12 -0
- package/dist/mail/sql/index.js +12 -0
- package/dist/mail/sql/ledger.repo.d.ts +29 -0
- package/dist/mail/sql/ledger.repo.js +57 -0
- package/dist/mail/sql/retention.d.ts +23 -0
- package/dist/mail/sql/retention.js +53 -0
- package/dist/mail/sql/site-feedback-route.d.ts +18 -0
- package/dist/mail/sql/site-feedback-route.js +22 -0
- package/dist/mail/sql/suppression-admin.repo.d.ts +11 -0
- package/dist/mail/sql/suppression-admin.repo.js +76 -0
- package/dist/mail/sql/suppression.repo.d.ts +10 -0
- package/dist/mail/sql/suppression.repo.js +33 -0
- package/dist/mail/test-send.d.ts +147 -0
- package/dist/mail/test-send.js +198 -0
- package/dist/mail/use-readiness.d.ts +104 -0
- package/dist/mail/use-readiness.js +140 -0
- package/dist/object-store/local-fs.js +34 -1
- package/dist/object-store/site/artifact-provider.d.ts +65 -0
- package/dist/object-store/site/artifact-provider.js +37 -0
- package/dist/object-store/site/registry.d.ts +110 -0
- package/dist/object-store/site/registry.js +93 -0
- package/dist/object-store/site/setting.d.ts +34 -0
- package/dist/object-store/site/setting.js +32 -0
- package/dist/process-probes.d.ts +11 -4
- package/dist/process-probes.js +3 -3
- package/dist/process-top-footprint.d.ts +1 -1
- package/dist/process-top-footprint.js +1 -3
- package/dist/process.d.ts +3 -17
- package/dist/process.js +3 -2
- package/dist/retention/index.d.ts +6 -0
- package/dist/retention/index.js +6 -0
- package/dist/retention/measure-tree.d.ts +68 -0
- package/dist/retention/measure-tree.js +205 -0
- package/dist/retention/preview-store.d.ts +12 -0
- package/dist/retention/preview-store.js +28 -0
- package/dist/retention/routes.d.ts +23 -0
- package/dist/retention/routes.js +24 -0
- package/dist/retention/runner.d.ts +103 -0
- package/dist/retention/runner.js +164 -0
- package/dist/secrets/credential-sets/index.d.ts +1 -0
- package/dist/secrets/credential-sets/index.js +1 -0
- package/dist/secrets/credential-sets/store-vault-guards.d.ts +26 -0
- package/dist/secrets/credential-sets/store-vault-guards.js +30 -0
- package/dist/secrets/credential-sets/vault.service.d.ts +1 -1
- package/dist/secrets/index.d.ts +1 -1
- package/dist/secrets/index.js +1 -1
- package/dist/secrets/keyring.env.d.ts +1 -1
- package/dist/secrets/keyring.env.js +3 -5
- package/dist/secrets/keyring.memory.d.ts +4 -1
- package/dist/secrets/keyring.memory.js +4 -1
- package/dist/secrets/legacy-codecs.d.ts +381 -0
- package/dist/secrets/legacy-codecs.js +468 -0
- package/dist/secrets/legacy-owner.d.ts +3 -11
- package/dist/secrets/root-key/ensure.d.ts +154 -0
- package/dist/secrets/root-key/ensure.js +328 -0
- package/dist/secrets/root-key/files.d.ts +104 -0
- package/dist/secrets/root-key/files.js +166 -0
- package/dist/secrets/root-key/material.d.ts +132 -0
- package/dist/secrets/root-key/material.js +116 -0
- package/dist/secrets/root-key/ordered-keyring.d.ts +157 -0
- package/dist/secrets/root-key/ordered-keyring.js +104 -0
- package/dist/secrets/root-key/reconcile.d.ts +50 -0
- package/dist/secrets/root-key/reconcile.js +147 -0
- package/dist/secrets/root-key/site-keyring-errors.d.ts +78 -0
- package/dist/secrets/root-key/site-keyring-errors.js +37 -0
- package/dist/secrets/root-key/sources.d.ts +79 -0
- package/dist/secrets/root-key/sources.js +119 -0
- package/dist/secrets/secret-sealer.aesgcm.d.ts +50 -2
- package/dist/secrets/secret-sealer.aesgcm.js +107 -19
- package/dist/web/tool-registrations.d.ts +67 -0
- package/dist/web/tool-registrations.js +44 -0
- package/package.json +138 -6
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { formatAad } from "./aad.js";
|
|
2
|
+
import { VaultError, } from "@jini-ai/core/contracts/vault";
|
|
3
|
+
/** @file Historical vault AAD formats, legacy-row decoders and payload normalization, moved from
|
|
4
|
+
* the host composition (formerly the host's `vault-legacy-codecs.ts`).
|
|
5
|
+
* The host injects its own owner key and vault policy (`formerCustomOwnerKey`, `policy`).
|
|
6
|
+
*
|
|
7
|
+
* Historical formats and their original rationale, copied verbatim for S2 recovery.
|
|
8
|
+
* Feature reads must use Jini buildVaultAad, never these builders. */
|
|
9
|
+
const AAD_VERSION = "v1";
|
|
10
|
+
// Original source: assistant/site-credential-aad.ts
|
|
11
|
+
/**
|
|
12
|
+
* @file The ONE place `site_assistant_credentials`' AES-GCM additional authenticated data (AAD)
|
|
13
|
+
* string is formatted — same convention as `legacy-codecs.ts` and its siblings:
|
|
14
|
+
* every `seal()`/`open()` call for this table MUST go through this function so sealing and opening
|
|
15
|
+
* can never drift onto two different formats (which would make every row in the table permanently
|
|
16
|
+
* unopenable, since AAD is authenticated but never stored — see
|
|
17
|
+
* `../features/webhooks/secret-sealer.aesgcm.ts`'s file header).
|
|
18
|
+
*
|
|
19
|
+
* Format: `site-assistant-credential:v1:${workspaceId}` — this table is single-row-per-workspace
|
|
20
|
+
* (`workspace_id` is the bare primary key, `db/schema.sqlite.ts`'s `siteAssistantCredentials` doc), so
|
|
21
|
+
* `workspaceId` is the whole row identity there is to bind. That single binding is still
|
|
22
|
+
* load-bearing: without it, an attacker (or a bad migration) with DB write access could copy one
|
|
23
|
+
* workspace's sealed visitor-assistant key onto another workspace's row and have it decrypt
|
|
24
|
+
* cleanly, since the underlying AES key is shared app-wide (`secret-sealer.aesgcm.ts`'s own
|
|
25
|
+
* header).
|
|
26
|
+
*
|
|
27
|
+
* Legacy no-AAD rows remain readable via `site_assistant_credentials.aad_version`; see its schema contract
|
|
28
|
+
* and the owning backfill script. Opening must use the version the row was sealed under.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Builds the AAD string for one `site_assistant_credentials` row. Deterministic — the same
|
|
32
|
+
* `workspaceId` always produces the same string, which is required: opening a sealed value must
|
|
33
|
+
* re-derive the byte-identical value sealing used, with no separate storage of the AAD itself.
|
|
34
|
+
*
|
|
35
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
36
|
+
*/
|
|
37
|
+
export function buildSiteAssistantCredentialAad(input, _options = {}) {
|
|
38
|
+
return `site-assistant-credential:${AAD_VERSION}:${input.workspaceId}`;
|
|
39
|
+
}
|
|
40
|
+
// Original source: assistant/execution-credential-aad.ts
|
|
41
|
+
/**
|
|
42
|
+
* @file The ONE place `admin_execution_credentials`' AES-GCM additional authenticated data (AAD)
|
|
43
|
+
* string is formatted — same convention as `legacy-codecs.ts` and its siblings:
|
|
44
|
+
* every `seal()`/`open()` call for this table MUST go through this function so sealing and opening
|
|
45
|
+
* can never drift onto two different formats (which would make every row in the table permanently
|
|
46
|
+
* unopenable, since AAD is authenticated but never stored — see
|
|
47
|
+
* `../features/webhooks/secret-sealer.aesgcm.ts`'s file header).
|
|
48
|
+
*
|
|
49
|
+
* Format: `admin-execution-credential:v1:${workspaceId}:${principalId}` — this table has no
|
|
50
|
+
* surrogate `id` column (`(workspace_id, principal_id)` IS the row's own primary key, per
|
|
51
|
+
* `db/schema.sqlite.ts`'s `adminExecutionCredentials` doc), so the AAD binds that composite PK directly.
|
|
52
|
+
* Binds both scoping dimensions this table actually has: a ciphertext sealed under one admin's own
|
|
53
|
+
* BYOK key fails auth-tag verification if presented as any other admin's ciphertext, even within
|
|
54
|
+
* the same workspace — which is exactly the property this table's own header requires ("two admins
|
|
55
|
+
* on the same install already carry independent keys").
|
|
56
|
+
*
|
|
57
|
+
* Legacy no-AAD rows remain readable via `admin_execution_credentials.aad_version`; see its schema contract
|
|
58
|
+
* and the owning backfill script. Opening must use the version the row was sealed under.
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Builds the AAD string for one `admin_execution_credentials` row. Deterministic — the same
|
|
62
|
+
* `(workspaceId, principalId)` always produces the same string, which is required: opening a
|
|
63
|
+
* sealed value must re-derive the byte-identical value sealing used, with no separate storage of
|
|
64
|
+
* the AAD itself.
|
|
65
|
+
*
|
|
66
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
67
|
+
*/
|
|
68
|
+
export function buildExecutionCredentialAad(input, _options = {}) {
|
|
69
|
+
return `admin-execution-credential:${AAD_VERSION}:${input.workspaceId}:${input.principalId}`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The current AAD version for newly sealed blobs. Rows still at `0` were sealed before AAD existed
|
|
73
|
+
* and are opened through the legacy no-AAD path — see the store's `open*` helpers.
|
|
74
|
+
*/
|
|
75
|
+
export const EXTERNAL_MCP_AAD_VERSION = 1;
|
|
76
|
+
/**
|
|
77
|
+
* Builds the AAD for a row's sealed **env block** (`sealed_*`).
|
|
78
|
+
*
|
|
79
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
80
|
+
*/
|
|
81
|
+
export function buildExternalMcpEnvAad(input, _options = {}) {
|
|
82
|
+
return `external-mcp-env:${AAD_VERSION}:${input.workspaceId}:${input.serverId}`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds the AAD for a row's sealed **OAuth blob** (`oauth_sealed_*`, holding `clientSecret` and
|
|
86
|
+
* `tokens`). Deliberately a different string from {@link buildExternalMcpEnvAad} for the same row.
|
|
87
|
+
*
|
|
88
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
89
|
+
*/
|
|
90
|
+
export function buildExternalMcpOAuthAad(input, _options = {}) {
|
|
91
|
+
return `external-mcp-oauth:${AAD_VERSION}:${input.workspaceId}:${input.serverId}`;
|
|
92
|
+
}
|
|
93
|
+
// Original source: features/media/aad.ts
|
|
94
|
+
/**
|
|
95
|
+
* @file The ONE place `media_provider_credentials`' AES-GCM additional authenticated data (AAD)
|
|
96
|
+
* string is formatted — mirrors `legacy-codecs.ts`/`features/custom-credentials/
|
|
97
|
+
* aad.ts`/`legacy-codecs.ts`/`legacy-codecs.ts`
|
|
98
|
+
* exactly, all four of whose file headers this one repeats verbatim: every `seal()`/`open()` call
|
|
99
|
+
* for this table MUST go through this function so sealing and opening can never drift onto two
|
|
100
|
+
* different formats (which would make every row in the table permanently unopenable, since AAD is
|
|
101
|
+
* authenticated but never stored — see `webhooks/secret-sealer.aesgcm.ts`'s file header).
|
|
102
|
+
*
|
|
103
|
+
* Format: `media-provider-credential:v1:${workspaceId}:${providerId}` — this table has no surrogate
|
|
104
|
+
* `id` column (`(workspace_id, provider_id)` IS the row's own primary key, per `db/schema.sqlite.ts`'s
|
|
105
|
+
* `mediaProviderCredentials` doc), so the AAD binds that composite PK directly rather than a third
|
|
106
|
+
* `id` component the row does not have. Binds both scoping dimensions this table actually has: a
|
|
107
|
+
* ciphertext sealed under one provider's AAD fails auth-tag verification if presented as any other
|
|
108
|
+
* provider's ciphertext, even within the same workspace.
|
|
109
|
+
*
|
|
110
|
+
* This table's rows predate AAD entirely (2026-09-02 gap closure) — see `media_provider_
|
|
111
|
+
* credentials.aad_version`'s own doc in `db/schema.sqlite.ts` and the media provider credential AAD
|
|
112
|
+
* backfill for how existing rows are migrated without becoming unreadable.
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Builds the AAD string for one `media_provider_credentials` row. Deterministic — the same
|
|
116
|
+
* `(workspaceId, providerId)` always produces the same string, which is required: opening a sealed
|
|
117
|
+
* value must re-derive the byte-identical value sealing used, with no separate storage of the AAD
|
|
118
|
+
* itself.
|
|
119
|
+
*
|
|
120
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
121
|
+
*/
|
|
122
|
+
export function buildMediaProviderCredentialAad(input, _options = {}) {
|
|
123
|
+
return `media-provider-credential:${AAD_VERSION}:${input.workspaceId}:${input.providerId}`;
|
|
124
|
+
}
|
|
125
|
+
// Original source: features/custom-credentials/aad.ts
|
|
126
|
+
/**
|
|
127
|
+
* @file The ONE place `custom_credential_sets`' AES-GCM additional authenticated data (AAD) string
|
|
128
|
+
* is formatted — mirrors `legacy-codecs.ts` exactly. Every `seal()`/`open()` call for
|
|
129
|
+
* this table MUST go through this function so sealing and opening can never drift onto two
|
|
130
|
+
* different formats (which would make every row in the table permanently unopenable, since AAD is
|
|
131
|
+
* authenticated but never stored — see `Jini packages/platform/src/secrets/secret-sealer.aesgcm.ts`'s file header).
|
|
132
|
+
*
|
|
133
|
+
* Format: `custom-credential-set:v1:${workspaceId}:${id}` — versioned (`v1`), and bound to both
|
|
134
|
+
* scoping dimensions this table actually has (no `providerId` — see `types.ts`'s own header for
|
|
135
|
+
* why this table has none to bind).
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Builds the AAD string for one `custom_credential_sets` row. Deterministic — the same
|
|
139
|
+
* `(workspaceId, id)` always produces the same string, which is required: opening a sealed value
|
|
140
|
+
* must re-derive the byte-identical value sealing used, with no separate storage of the AAD itself.
|
|
141
|
+
*
|
|
142
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
143
|
+
*/
|
|
144
|
+
export function buildCustomCredentialAad(input, _options = {}) {
|
|
145
|
+
return `custom-credential-set:${AAD_VERSION}:${input.workspaceId}:${input.id}`;
|
|
146
|
+
}
|
|
147
|
+
// Original source: features/source-control/aad.ts
|
|
148
|
+
/**
|
|
149
|
+
* @file The ONE place `source_control_credential_sets`' AES-GCM additional authenticated data
|
|
150
|
+
* (AAD) string is formatted — mirrors `legacy-codecs.ts` exactly.
|
|
151
|
+
* Every `seal()`/`open()` call for this table MUST go through this function so sealing and opening
|
|
152
|
+
* can never drift onto two different formats (which would make every row in the table permanently
|
|
153
|
+
* unopenable, since AAD is authenticated but never stored — see
|
|
154
|
+
* `Jini packages/platform/src/secrets/secret-sealer.aesgcm.ts`'s file header).
|
|
155
|
+
*
|
|
156
|
+
* Format: `source-control-credential-set:v1:${workspaceId}:${providerId}:${id}` — versioned (`v1`)
|
|
157
|
+
* so a future format change is an explicit, reviewed migration path rather than a silent
|
|
158
|
+
* redefinition that breaks every existing row without warning. Binds all three scoping dimensions:
|
|
159
|
+
* a ciphertext sealed under one credential set's AAD fails auth-tag verification if presented as
|
|
160
|
+
* any other credential set's ciphertext, even within the same workspace/provider.
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* Builds the AAD string for one `source_control_credential_sets` row. Deterministic — the same
|
|
164
|
+
* `(workspaceId, providerId, id)` always produces the same string, which is required: opening a
|
|
165
|
+
* sealed value must re-derive the byte-identical value sealing used, with no separate storage of
|
|
166
|
+
* the AAD itself.
|
|
167
|
+
*
|
|
168
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
169
|
+
*/
|
|
170
|
+
export function buildSourceControlCredentialAad(input, _options = {}) {
|
|
171
|
+
return `source-control-credential-set:${AAD_VERSION}:${input.workspaceId}:${input.providerId}:${input.id}`;
|
|
172
|
+
}
|
|
173
|
+
// Original source: features/vendor-credentials/aad.ts
|
|
174
|
+
// Generic formatter and rationale: Jini/packages/platform/src/secrets/aad.ts; the row namespace stays here.
|
|
175
|
+
/**
|
|
176
|
+
* @file The ONE place `vendor_credential_sets`' AES-GCM additional authenticated data (AAD) string
|
|
177
|
+
* is formatted — mirrors `legacy-codecs.ts` and
|
|
178
|
+
* `legacy-codecs.ts` exactly, both of whose file headers this one repeats verbatim:
|
|
179
|
+
* every `seal()`/`open()` call for this table MUST go through this function so sealing and opening
|
|
180
|
+
* can never drift onto two different formats (which would make every row in the table permanently
|
|
181
|
+
* unopenable, since AAD is authenticated but never stored — see
|
|
182
|
+
* `Jini packages/platform/src/secrets/secret-sealer.aesgcm.ts`'s file header).
|
|
183
|
+
*
|
|
184
|
+
* Format: `vendor-credential-set:v1:${workspaceId}:${vendorId}:${id}` — a FRESH `v1`, not a `v2` of
|
|
185
|
+
* either predecessor table's own format. This table is a new table with its own AAD lineage, not a
|
|
186
|
+
* versioned continuation of `publish-credential-set:v1:...`/`source-control-credential-set:v1:...`
|
|
187
|
+
* (those formats stay exactly as they are, still governing whatever rows remain in the two
|
|
188
|
+
* predecessor tables until they are cut over and dropped — see `../../db/schema.sqlite.ts`'s
|
|
189
|
+
* `vendorCredentialSets` doc). Binds all three scoping dimensions the predecessor tables' own AAD
|
|
190
|
+
* already bound, with `vendorId` standing in for `providerId`: a ciphertext sealed under one
|
|
191
|
+
* credential set's AAD fails auth-tag verification if presented as any other credential set's
|
|
192
|
+
* ciphertext, even within the same workspace/vendor.
|
|
193
|
+
*/
|
|
194
|
+
/**
|
|
195
|
+
* Builds the AAD string for one `vendor_credential_sets` row. Deterministic — the same
|
|
196
|
+
* `(workspaceId, vendorId, id)` always produces the same string, which is required: opening a
|
|
197
|
+
* sealed value must re-derive the byte-identical value sealing used, with no separate storage of
|
|
198
|
+
* the AAD itself.
|
|
199
|
+
*
|
|
200
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
201
|
+
*/
|
|
202
|
+
export function buildVendorCredentialAad(input, _options = {}) {
|
|
203
|
+
return formatAad({ kind: "vendor-credential-set", version: AAD_VERSION, parts: [input.workspaceId, input.vendorId, input.id] });
|
|
204
|
+
}
|
|
205
|
+
// Original source: features/publish-content/peer-aad.ts
|
|
206
|
+
/**
|
|
207
|
+
* @file Task 10 of the publish-content (Publish Content) feature —
|
|
208
|
+
* `ADS-memory/reports/2026-09-18-publish-feature-implementation-plan.md` §4 task 10.
|
|
209
|
+
*
|
|
210
|
+
* The ONE place `publish_content_peers`' AES-GCM additional authenticated data (AAD) string is
|
|
211
|
+
* formatted — every `seal()`/`open()` call for this table MUST go through this function, exactly as
|
|
212
|
+
* `legacy-codecs.ts` does for `publish_credential_sets`. AAD is
|
|
213
|
+
* authenticated but never stored, so if sealing and opening ever drift onto two different formats
|
|
214
|
+
* every row in the table becomes permanently unopenable.
|
|
215
|
+
*
|
|
216
|
+
* Format: `publish-content-peer:v1:${workspaceId}:${id}` — binds both scoping dimensions this table
|
|
217
|
+
* has (there is no `providerId` analogue here: a peer is identified by URL + credential, never by a
|
|
218
|
+
* platform identifier, per plan §0b's vendor-neutrality constraint). A ciphertext sealed under one
|
|
219
|
+
* peer's AAD fails auth-tag verification if presented as any other peer's ciphertext, even within
|
|
220
|
+
* the same workspace.
|
|
221
|
+
*
|
|
222
|
+
* Unlike the `publish_credential_sets` precedent, the version is ALSO persisted, in the table's own
|
|
223
|
+
* `aad_version` integer column — {@link PUBLISH_CONTENT_PEER_AAD_VERSION} is what a write stamps
|
|
224
|
+
* there. That makes a future `v2` a readable, row-by-row migration ("re-seal every row whose
|
|
225
|
+
* `aad_version` is 1") rather than a flag day, which is why the column exists.
|
|
226
|
+
*/
|
|
227
|
+
/** The AAD format version every row written by this feature is stamped with (`aad_version`). */
|
|
228
|
+
export const PUBLISH_CONTENT_PEER_AAD_VERSION = 1;
|
|
229
|
+
/**
|
|
230
|
+
* Builds the AAD string for one `publish_content_peers` row. Deterministic — the same
|
|
231
|
+
* `(workspaceId, id)` always produces the same string, which is required: `open()` must re-derive
|
|
232
|
+
* the byte-identical value `seal()` used, with no separate storage of the AAD itself.
|
|
233
|
+
*
|
|
234
|
+
* @param input.aadVersion - The version stamped on the row being opened; defaults to the current
|
|
235
|
+
* {@link PUBLISH_CONTENT_PEER_AAD_VERSION} for a fresh seal. Passing the row's OWN stored value is
|
|
236
|
+
* what lets a future `v2` writer coexist with `v1` rows that have not been re-sealed yet.
|
|
237
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
238
|
+
*/
|
|
239
|
+
export function buildPublishContentPeerAad(input, _options = {}) {
|
|
240
|
+
const version = input.aadVersion ?? PUBLISH_CONTENT_PEER_AAD_VERSION;
|
|
241
|
+
return `publish-content-peer:v${version}:${input.workspaceId}:${input.id}`;
|
|
242
|
+
}
|
|
243
|
+
// Original source: features/database-transfer/destination-aad.ts
|
|
244
|
+
/**
|
|
245
|
+
* @file The ONE place `database_transfer_destinations`' AES-GCM additional authenticated data (AAD) is
|
|
246
|
+
* formatted; sealing and opening both call it, so they can never drift apart (AAD is authenticated
|
|
247
|
+
* but never stored — `features/webhooks/secret-sealer.aesgcm.ts`'s header). It binds the sealed
|
|
248
|
+
* address to its workspace: a row copied onto another workspace does not open.
|
|
249
|
+
*/
|
|
250
|
+
/** Every row is sealed under this version (the table was born with AAD). */
|
|
251
|
+
export const DATABASE_DESTINATION_AAD_VERSION = 1;
|
|
252
|
+
/** @complexity O(1). */
|
|
253
|
+
export function buildDatabaseDestinationAad(input, _options = {}) {
|
|
254
|
+
return `database-transfer-destination:v${DATABASE_DESTINATION_AAD_VERSION}:${input.workspaceId}`;
|
|
255
|
+
}
|
|
256
|
+
// Original source: features/deployments/publish-credentials/aad.ts
|
|
257
|
+
/**
|
|
258
|
+
* @file The ONE place `publish_credential_sets`' AES-GCM additional authenticated data (AAD) string
|
|
259
|
+
* is formatted — every `seal()`/`open()` call for this table MUST go through this function so sealing
|
|
260
|
+
* and opening can never drift onto two different formats (which would make every row in the table
|
|
261
|
+
* permanently unopenable, since AAD is authenticated but never stored — see
|
|
262
|
+
* `Jini packages/platform/src/secrets/secret-sealer.aesgcm.ts`'s file header).
|
|
263
|
+
*
|
|
264
|
+
* Format: `publish-credential-set:v1:${workspaceId}:${providerId}:${id}` — versioned (`v1`) so a
|
|
265
|
+
* future format change is an explicit, reviewed migration path (bump to `v2`, re-seal every row under
|
|
266
|
+
* the new AAD) rather than a silent redefinition that breaks every existing row without warning.
|
|
267
|
+
* Binds all three scoping dimensions Terra's finding named: workspace, provider, and the specific
|
|
268
|
+
* credential-set row — a ciphertext sealed under one credential set's AAD fails auth-tag verification
|
|
269
|
+
* if presented as any other credential set's ciphertext, even within the same workspace/provider.
|
|
270
|
+
*/
|
|
271
|
+
/**
|
|
272
|
+
* Builds the AAD string for one `publish_credential_sets` row. Deterministic — the same
|
|
273
|
+
* `(workspaceId, providerId, id)` always produces the same string, which is required: `open()` must
|
|
274
|
+
* re-derive the byte-identical value `seal()` used, with no separate storage of the AAD itself.
|
|
275
|
+
*
|
|
276
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
277
|
+
*/
|
|
278
|
+
export function buildPublishCredentialAad(input, _options = {}) {
|
|
279
|
+
return `publish-credential-set:${AAD_VERSION}:${input.workspaceId}:${input.providerId}:${input.id}`;
|
|
280
|
+
}
|
|
281
|
+
/** Decode only known historical lineages; unknown versions fail closed instead of trying AADs.
|
|
282
|
+
* @complexity O(1); no crypto or I/O.
|
|
283
|
+
*/
|
|
284
|
+
export function legacyVaultAad({ record, legacy, formerCustomOwnerKey }, _options = {}) {
|
|
285
|
+
if (legacy.workspaceId !== record.workspaceId || !Number.isInteger(legacy.aadVersion) ||
|
|
286
|
+
legacy.aadVersion < 0 || legacy.aadVersion > 1)
|
|
287
|
+
throw new VaultError({ code: "context" });
|
|
288
|
+
const decode = legacyAadDecoders.get(legacy.table);
|
|
289
|
+
if (!decode)
|
|
290
|
+
throw new VaultError({ code: "context" });
|
|
291
|
+
return decode({ record, legacy, formerCustomOwnerKey });
|
|
292
|
+
}
|
|
293
|
+
function decodeSiteAssistantCredentials({ record, legacy }, _options = {}) {
|
|
294
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
295
|
+
if (record.kind === "site-assistant")
|
|
296
|
+
return legacy.aadVersion === 0 ? undefined : buildSiteAssistantCredentialAad(input);
|
|
297
|
+
throw new VaultError({ code: "context" });
|
|
298
|
+
}
|
|
299
|
+
function decodeAdminExecutionCredentials({ record, legacy }, _options = {}) {
|
|
300
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
301
|
+
if (record.kind === "personal-execution" && legacy.principalId === record.principalId && legacy.principalId !== null) {
|
|
302
|
+
return legacy.aadVersion === 0 ? undefined : buildExecutionCredentialAad({ ...input, principalId: legacy.principalId });
|
|
303
|
+
}
|
|
304
|
+
throw new VaultError({ code: "context" });
|
|
305
|
+
}
|
|
306
|
+
function decodeMediaProviderCredentials({ record, legacy }, _options = {}) {
|
|
307
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
308
|
+
if (record.kind === "media-provider" && legacy.provider === record.provider && legacy.provider !== null) {
|
|
309
|
+
return legacy.aadVersion === 0 ? undefined : buildMediaProviderCredentialAad({ ...input, providerId: legacy.provider });
|
|
310
|
+
}
|
|
311
|
+
throw new VaultError({ code: "context" });
|
|
312
|
+
}
|
|
313
|
+
function isFormerCustomVaultIdentity({ record, formerCustomOwnerKey }, _options = {}) {
|
|
314
|
+
return record.kind === "vendor" && record.meta.credentialType === "custom" && record.ownerKey === formerCustomOwnerKey && record.provider === null;
|
|
315
|
+
}
|
|
316
|
+
function decodeSecretsVaultCustomV1({ record, legacy, formerCustomOwnerKey }, _options = {}) {
|
|
317
|
+
if (!isFormerCustomVaultIdentity({ record, formerCustomOwnerKey }) || record.principalId !== null || record.binding !== null)
|
|
318
|
+
throw new VaultError({ code: "context" });
|
|
319
|
+
if (legacy.provider !== null || legacy.principalId !== null || legacy.serverId !== null)
|
|
320
|
+
throw new VaultError({ code: "context" });
|
|
321
|
+
if (legacy.id === record.id && legacy.aadVersion === 1) {
|
|
322
|
+
// Pin the former vault encoding, not the active builder's future version.
|
|
323
|
+
return formatAad({ kind: "secrets-vault", version: "v1", parts: [JSON.stringify([
|
|
324
|
+
record.workspaceId, record.id, "custom", formerCustomOwnerKey, null, null,
|
|
325
|
+
])] });
|
|
326
|
+
}
|
|
327
|
+
throw new VaultError({ code: "context" });
|
|
328
|
+
}
|
|
329
|
+
function decodeCustomCredentialSets({ record, legacy }, _options = {}) {
|
|
330
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
331
|
+
if ((record.kind === "custom" || (record.kind === "vendor" && record.meta.credentialType === "custom")) && legacy.aadVersion === 1)
|
|
332
|
+
return buildCustomCredentialAad(input);
|
|
333
|
+
throw new VaultError({ code: "context" });
|
|
334
|
+
}
|
|
335
|
+
function decodePublishContentPeers({ record, legacy }, _options = {}) {
|
|
336
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
337
|
+
if (record.kind === "publish-peer" && legacy.aadVersion === 1)
|
|
338
|
+
return buildPublishContentPeerAad({ ...input, aadVersion: legacy.aadVersion });
|
|
339
|
+
throw new VaultError({ code: "context" });
|
|
340
|
+
}
|
|
341
|
+
function decodeDatabaseTransferDestinations({ record, legacy }, _options = {}) {
|
|
342
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
343
|
+
if (record.kind === "database-destination" && legacy.aadVersion === 1)
|
|
344
|
+
return buildDatabaseDestinationAad(input);
|
|
345
|
+
throw new VaultError({ code: "context" });
|
|
346
|
+
}
|
|
347
|
+
function decodeVendorCredentialSets({ record, legacy }, _options = {}) {
|
|
348
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
349
|
+
if (record.kind === "vendor" && legacy.provider === record.provider && legacy.provider !== null && legacy.aadVersion === 1) {
|
|
350
|
+
return buildVendorCredentialAad({ ...input, vendorId: legacy.provider });
|
|
351
|
+
}
|
|
352
|
+
throw new VaultError({ code: "context" });
|
|
353
|
+
}
|
|
354
|
+
function decodeSourceControlCredentialSets({ record, legacy }, _options = {}) {
|
|
355
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
356
|
+
if (record.kind === "source-control" && legacy.provider === record.provider && legacy.provider !== null && legacy.aadVersion === 1) {
|
|
357
|
+
return buildSourceControlCredentialAad({ ...input, providerId: legacy.provider });
|
|
358
|
+
}
|
|
359
|
+
throw new VaultError({ code: "context" });
|
|
360
|
+
}
|
|
361
|
+
function decodePublishCredentialSets({ record, legacy }, _options = {}) {
|
|
362
|
+
const input = { workspaceId: legacy.workspaceId, id: legacy.id };
|
|
363
|
+
if (record.kind === "vendor" && legacy.provider !== null && legacy.aadVersion === 1)
|
|
364
|
+
return buildPublishCredentialAad({ ...input, providerId: legacy.provider });
|
|
365
|
+
throw new VaultError({ code: "context" });
|
|
366
|
+
}
|
|
367
|
+
function decodeExternalMcpServers({ record, legacy }, _options = {}) {
|
|
368
|
+
if (legacy.serverId === record.ownerKey && legacy.serverId !== null && (record.kind === "mcp-env" || record.kind === "mcp-auth")) {
|
|
369
|
+
if (legacy.aadVersion === 0)
|
|
370
|
+
return undefined;
|
|
371
|
+
const identity = { workspaceId: legacy.workspaceId, serverId: legacy.serverId };
|
|
372
|
+
return record.kind === "mcp-env" ? buildExternalMcpEnvAad(identity) : buildExternalMcpOAuthAad(identity);
|
|
373
|
+
}
|
|
374
|
+
throw new VaultError({ code: "context" });
|
|
375
|
+
}
|
|
376
|
+
const legacyAadDecoders = new Map(Object.entries({
|
|
377
|
+
site_assistant_credentials: decodeSiteAssistantCredentials,
|
|
378
|
+
admin_execution_credentials: decodeAdminExecutionCredentials,
|
|
379
|
+
media_provider_credentials: decodeMediaProviderCredentials,
|
|
380
|
+
secrets_vault_custom_v1: decodeSecretsVaultCustomV1,
|
|
381
|
+
custom_credential_sets: decodeCustomCredentialSets,
|
|
382
|
+
publish_content_peers: decodePublishContentPeers,
|
|
383
|
+
database_transfer_destinations: decodeDatabaseTransferDestinations,
|
|
384
|
+
vendor_credential_sets: decodeVendorCredentialSets,
|
|
385
|
+
source_control_credential_sets: decodeSourceControlCredentialSets,
|
|
386
|
+
publish_credential_sets: decodePublishCredentialSets,
|
|
387
|
+
external_mcp_servers: decodeExternalMcpServers,
|
|
388
|
+
}));
|
|
389
|
+
/** Resolve the target provider and legacy token field from the host catalog without crypto.
|
|
390
|
+
* Callers pass publish_credential_sets rows only.
|
|
391
|
+
* @throws Error("VAULT_CATALOG_UNAVAILABLE") when the legacy publish catalog has no spec.
|
|
392
|
+
* @complexity O(1) time/space plus one injected catalog lookup for publish rows; no I/O.
|
|
393
|
+
* @example const { provider } = legacyTargetProvider({ record, legacy, policy });
|
|
394
|
+
*/
|
|
395
|
+
export function legacyTargetProvider({ record, legacy, policy }, _options = {}) {
|
|
396
|
+
if (legacy.provider === undefined || legacy.provider === null)
|
|
397
|
+
throw new Error("legacy publish credential has no provider");
|
|
398
|
+
const spec = policy.legacyPublishCredential({ workspaceId: record.workspaceId, providerId: legacy.provider });
|
|
399
|
+
if (!spec)
|
|
400
|
+
throw new Error("VAULT_CATALOG_UNAVAILABLE");
|
|
401
|
+
return { provider: spec.vendorId, tokenField: spec.tokenField };
|
|
402
|
+
}
|
|
403
|
+
function parseLegacyPayload({ plaintext }, _options = {}) {
|
|
404
|
+
const payload = JSON.parse(plaintext);
|
|
405
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload))
|
|
406
|
+
throw new VaultError({ code: "invalid-record" });
|
|
407
|
+
return payload;
|
|
408
|
+
}
|
|
409
|
+
function isCustomPayload({ record, meta }, _options = {}) {
|
|
410
|
+
return record.kind === "custom" || (record.kind === "vendor" && meta.credentialType === "custom");
|
|
411
|
+
}
|
|
412
|
+
function moveCustomUsername({ payload, meta }, _options = {}) {
|
|
413
|
+
if (payload.username !== undefined) {
|
|
414
|
+
// A saved column value wins. A NULL column never meant a clear: the legacy clear re-sealed
|
|
415
|
+
// without the username, and the old read fell back to the sealed copy (`column ?? sealed`).
|
|
416
|
+
// NULL + sealed username is an un-backfilled row, so the sealed login moves to metadata.
|
|
417
|
+
if ((meta.username === undefined || meta.username === null) && typeof payload.username === "string" && payload.username !== "") {
|
|
418
|
+
meta.username = payload.username;
|
|
419
|
+
}
|
|
420
|
+
delete payload.username;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function legacyHint({ token, kind }, _options = {}) {
|
|
424
|
+
return typeof token === "string" && !["mcp-env", "mcp-auth"].includes(kind) ? { hintToken: token } : {};
|
|
425
|
+
}
|
|
426
|
+
/** Host-specific historical payload shapes. Plain tokens become sealed JSON; secrets remain sealed.
|
|
427
|
+
* Custom username is classified plain metadata; source-control's paired username stays sealed.
|
|
428
|
+
* Targets no hosting plugin declares are blocked, as the former backfill did; never guess a vendor.
|
|
429
|
+
* @throws On unsupported payloads or unavailable catalogs; boot flags the original row.
|
|
430
|
+
* @complexity O(payload size); no per-vendor branches, I/O or new crypto.
|
|
431
|
+
*/
|
|
432
|
+
export function normalizeLegacyVaultPayload({ record, legacy, plaintext, policy }, _options = {}) {
|
|
433
|
+
const { legacyAad: _legacy, normalization: _flag, ...meta } = record.meta;
|
|
434
|
+
let provider = record.provider;
|
|
435
|
+
if (plaintext === null)
|
|
436
|
+
return { payload: null, meta, provider };
|
|
437
|
+
if (["site-assistant", "personal-execution", "media-provider", "publish-peer"].includes(record.kind)) {
|
|
438
|
+
return { payload: { apiKey: plaintext }, meta, provider, hintToken: plaintext };
|
|
439
|
+
}
|
|
440
|
+
if (record.kind === "database-destination")
|
|
441
|
+
return { payload: { connectionString: plaintext }, meta, provider };
|
|
442
|
+
const payload = parseLegacyPayload({ plaintext });
|
|
443
|
+
const isCustom = isCustomPayload({ record, meta });
|
|
444
|
+
if (isCustom)
|
|
445
|
+
moveCustomUsername({ payload, meta });
|
|
446
|
+
let tokenField = isCustom ? "token" : policy.tokenField({ kind: record.kind, provider });
|
|
447
|
+
if (legacy.table === "publish_credential_sets") {
|
|
448
|
+
const target = legacyTargetProvider({ record, legacy, policy });
|
|
449
|
+
provider = target.provider;
|
|
450
|
+
tokenField = target.tokenField;
|
|
451
|
+
delete payload.providerId;
|
|
452
|
+
payload.vendorId = provider;
|
|
453
|
+
}
|
|
454
|
+
// JSON remains byte-equivalent in meaning for MCP (including schemaVersion), vendor and source
|
|
455
|
+
// payloads. Only the explicitly classified custom username and publish discriminator move.
|
|
456
|
+
const token = tokenField === undefined ? undefined : payload[tokenField];
|
|
457
|
+
return { payload, meta, provider, ...legacyHint({ token, kind: record.kind }) };
|
|
458
|
+
}
|
|
459
|
+
// Additional historical rationale retained during S5 retirement.
|
|
460
|
+
/**
|
|
461
|
+
* Builds the AAD string for one `publish_credential_sets` row. Deterministic — the same
|
|
462
|
+
* `(workspaceId, providerId, id)` always produces the same string, which is required: `open()` must
|
|
463
|
+
* re-derive the byte-identical value `seal()` used, with no separate storage of the AAD itself.
|
|
464
|
+
*
|
|
465
|
+
* @complexity O(1) — a fixed-shape string template.
|
|
466
|
+
* @overallScore 100
|
|
467
|
+
*/
|
|
468
|
+
//# sourceMappingURL=legacy-codecs.js.map
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { type VaultContext, type VaultKind, type VaultOptions, type VaultRepoPort } from "@jini-ai/core/contracts/vault";
|
|
2
2
|
import { SecretsVaultService, type VaultServiceDeps } from "./credential-sets/vault.service.js";
|
|
3
3
|
import type { VaultArchiveEntry } from "./credential-sets/vault-archive.js";
|
|
4
|
+
import type { LegacyOwnerStoreSnapshot } from "@jini-ai/core/contracts/site/legacy-owner-store";
|
|
4
5
|
/** @file Decoder for a legacy owner store's passphrase backup and the vault policy that reads its
|
|
5
6
|
* `owner.db` rows (keyring, authorization, recovery error). Shared keys are now project references,
|
|
6
7
|
* so nothing here writes, migrates or generates a key. The SQL reads live in
|
|
7
8
|
* `@jini-ai/db/owner-store`; the file wiring lives in `@jini-ai/server/owner-store`.
|
|
8
9
|
*/
|
|
9
10
|
export declare const OWNER_WORKSPACE_ID = "owner";
|
|
10
|
-
/**
|
|
11
|
-
export
|
|
12
|
-
entryId: string;
|
|
13
|
-
consumerId: string;
|
|
14
|
-
}
|
|
15
|
-
/** grants: active copies. revocations: revoked copies whose site cleanup never finished. */
|
|
16
|
-
export interface LegacyOwnerSnapshot {
|
|
17
|
-
entries: VaultArchiveEntry[];
|
|
18
|
-
grants: LegacyOwnerDestination[];
|
|
19
|
-
revocations: LegacyOwnerDestination[];
|
|
20
|
-
}
|
|
11
|
+
/** The decoded backup: the shared legacy-store snapshot over this package's archive entries. */
|
|
12
|
+
export type LegacyOwnerSnapshot = LegacyOwnerStoreSnapshot<VaultArchiveEntry>;
|
|
21
13
|
/** Safe recovery guidance never includes underlying key material or vault payloads. */
|
|
22
14
|
export declare class OwnerStoreRecoveryError extends Error {
|
|
23
15
|
constructor();
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { SiteKeyEnsureAction } from "./decide.js";
|
|
2
|
+
import type { RootKeyRejection as SiteKeyRejection } from "../keyring.env.js";
|
|
3
|
+
import type { createSiteKeySources } from "./sources.js";
|
|
4
|
+
import type { RuntimeMode } from "@jini-ai/core/contracts/site/core-runtime-mode";
|
|
5
|
+
/**
|
|
6
|
+
* @file Site-key plan (`ADS-memory/.local-artifacts/plan-site-key-2026-09-24.md`) §A.2 — the ONE
|
|
7
|
+
* writer for a site's key file. The CLI's old `host site-key ensure` command
|
|
8
|
+
* (`cli/commands/site-key.ts`) was absorbed into {@link ensureSiteKeyForBoot} and deleted outright
|
|
9
|
+
* (Stage A3b, `abc4807d5`) — `planSiteKeyEnsure`/`SiteKeyEnsurePlan` (that command's own pure
|
|
10
|
+
* decision table) went with it as dead code (site-key plan §A.6: zero callers once the CLI command
|
|
11
|
+
* was gone). `findSiteKeyDependentData` (the per-site scan `ensureSiteKey` uses, on every storage
|
|
12
|
+
* kind) lives in the host's dependent-data reader on the storage kernel; the admin site key
|
|
13
|
+
* route imports it there, and the boot callers inject it here ({@link KeyDependentDataScan}), so
|
|
14
|
+
* this feature never value-imports the host storage kernel.
|
|
15
|
+
*
|
|
16
|
+
* Purpose:
|
|
17
|
+
* `ensureSiteKey` runs once per server boot, local mode only (A.2): a per-site file already there
|
|
18
|
+
* and valid is a no-op; missing with an env/legacy-file key already in effect ADOPTS that exact
|
|
19
|
+
* material into the per-site file (never re-keys, never orphans); missing with nothing anywhere
|
|
20
|
+
* and no key-dependent data yet MINTS a fresh one; missing with key-dependent data already sealed
|
|
21
|
+
* REFUSES rather than silently starting a new key nothing can decrypt with. Production is always a
|
|
22
|
+
* no-op — it never had a per-site file to begin with (A.1's "why per-site rather than one key per
|
|
23
|
+
* OS user"; A.3's "production never mints").
|
|
24
|
+
*
|
|
25
|
+
* The write itself is race-safe with no single-instance lock (A.2's "atomic write, safe with many
|
|
26
|
+
* instances running at once"): a temp file is written and fsynced, then linked onto the final
|
|
27
|
+
* path — `link(2)` refuses `EEXIST` atomically, so at most one process's bytes ever become the
|
|
28
|
+
* file. Both the winner and every loser then read the FINAL file back rather than trusting their
|
|
29
|
+
* own in-memory candidate, so two instances racing (one adopting, one minting) always converge on
|
|
30
|
+
* the same key — see {@link atomicCreateSiteKeyFile}.
|
|
31
|
+
*
|
|
32
|
+
* Architectural role:
|
|
33
|
+
* Configured domain writer. Depends on `keyring.env.ts` (shared hex validator and
|
|
34
|
+
* fingerprint) and `site-key-sources.ts` (candidate ordering) — never the reverse: both keyrings
|
|
35
|
+
* stay readers (`allowFileAutoGenerate: false`), and this module is the only place `randomBytes`
|
|
36
|
+
* feeds a site key file. Nothing under `server/inbound/**` may import this module (site-key plan
|
|
37
|
+
* §A.3) — Stage A3a's own wiring test enforces that; this file does not import anything from
|
|
38
|
+
* `server/inbound` in either direction. The one request path that runs it, the admin site key
|
|
39
|
+
* `generate` (2026-09-29), receives {@link ensureSiteKeyForSite} from the composition root, so a
|
|
40
|
+
* request writes a key only by these same rules and never by a writer of its own.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createSiteKeyEnsurer(required: {
|
|
43
|
+
env: () => NodeJS.ProcessEnv;
|
|
44
|
+
resolveRuntimeMode: (required: {
|
|
45
|
+
env: NodeJS.ProcessEnv;
|
|
46
|
+
}) => RuntimeMode;
|
|
47
|
+
home: () => string;
|
|
48
|
+
cwd: () => string;
|
|
49
|
+
siteKeySources: ReturnType<typeof createSiteKeySources>["siteKeySources"];
|
|
50
|
+
readSiteKeySourceMaterial: ReturnType<typeof createSiteKeySources>["readSiteKeySourceMaterial"];
|
|
51
|
+
readSiteMetaJson: ReturnType<typeof createSiteKeySources>["readSiteMetaJson"];
|
|
52
|
+
resolveSiteKeyId: ReturnType<typeof createSiteKeySources>["resolveSiteKeyId"];
|
|
53
|
+
resolveSiteKeyFingerprint: ReturnType<typeof createSiteKeySources>["resolveSiteKeyFingerprint"];
|
|
54
|
+
findSiteKeyDependentData: KeyDependentDataScan;
|
|
55
|
+
randomUUID: () => string;
|
|
56
|
+
randomBytes: (size: number) => Buffer;
|
|
57
|
+
metadataFilename: string;
|
|
58
|
+
fields: {
|
|
59
|
+
siteKeyId: string;
|
|
60
|
+
fingerprint: string;
|
|
61
|
+
};
|
|
62
|
+
buildSiteMetaForNewKey: (required: {
|
|
63
|
+
dir: string;
|
|
64
|
+
siteKeyId: string;
|
|
65
|
+
}) => Promise<object | undefined>;
|
|
66
|
+
writeJsonFileAtomic: (required: {
|
|
67
|
+
filePath: string;
|
|
68
|
+
data: Record<string, unknown>;
|
|
69
|
+
}) => void;
|
|
70
|
+
logBootError: (required: {
|
|
71
|
+
siteDir: string;
|
|
72
|
+
error: unknown;
|
|
73
|
+
}) => void;
|
|
74
|
+
fs: Pick<typeof import("node:fs"), "chmodSync" | "closeSync" | "fsyncSync" | "linkSync" | "mkdirSync" | "openSync" | "readFileSync" | "renameSync" | "unlinkSync" | "writeFileSync" | "writeSync">;
|
|
75
|
+
nowIso: () => string;
|
|
76
|
+
pid: number;
|
|
77
|
+
directoryMode: number;
|
|
78
|
+
fileMode: number;
|
|
79
|
+
}, _optional?: {}): {
|
|
80
|
+
ensureSiteKey: (input: EnsureSiteKeyInput, _optional?: {}) => Promise<EnsureSiteKeyResult>;
|
|
81
|
+
ensureSiteKeyForBoot: (input: EnsureSiteKeyForBootInput, _optional?: {}) => Promise<EnsureSiteKeyResult | undefined>;
|
|
82
|
+
ensureSiteKeyForSite: (input: EnsureSiteKeyForBootInput, _optional?: {}) => Promise<EnsureSiteKeyResult | undefined>;
|
|
83
|
+
mintSiteKeyHex: (_required?: {}, _optional?: {}) => string;
|
|
84
|
+
installSiteKey: (input: InstallSiteKeyInput, _optional?: {}) => InstallSiteKeyResult | undefined;
|
|
85
|
+
atomicCreateSiteKeyFile: (input: {
|
|
86
|
+
filePath: string;
|
|
87
|
+
hex: string;
|
|
88
|
+
}, _optional?: {}) => string;
|
|
89
|
+
};
|
|
90
|
+
export interface EnsureSiteKeyInput {
|
|
91
|
+
/** This site's own directory — only this site's store is scanned for key-dependent data (A.2:
|
|
92
|
+
* per-site keys), never every sibling site the way the CLI's `host site-key ensure` did. */
|
|
93
|
+
readonly siteDir: string;
|
|
94
|
+
/** `.site-meta.json`'s `siteKeyId` (A.1/A.4). */
|
|
95
|
+
readonly siteKeyId: string;
|
|
96
|
+
/** Defaults to {@link resolveRuntimeMode}. Test-injected so a suite never depends on the real
|
|
97
|
+
* host runtime-mode env var. */
|
|
98
|
+
readonly mode?: RuntimeMode | undefined;
|
|
99
|
+
/** Defaults to `config.env()`. Test-injected so a suite never touches real env vars. */
|
|
100
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
101
|
+
/** Defaults to `config.home()`. Test-injected so a suite never touches the real the host home directory. */
|
|
102
|
+
readonly home?: string | undefined;
|
|
103
|
+
/** Defaults to `config.cwd()`. Only reaches {@link siteKeySources}'s production branch, which
|
|
104
|
+
* `ensureSiteKey` never takes (production is always `"production-noop"`) — kept for symmetry
|
|
105
|
+
* with {@link siteKeySources}'s own input shape and so a future caller has a real seam if that
|
|
106
|
+
* ever changes. */
|
|
107
|
+
readonly cwd?: string | undefined;
|
|
108
|
+
}
|
|
109
|
+
/** the host's dependent-data reader's `findSiteKeyDependentData`: whether the site in `siteDir`
|
|
110
|
+
* holds data only the current key can open, on whichever storage it runs (SQLite, PGlite,
|
|
111
|
+
* Postgres, or a sealed `.storage-secret.json`), failing closed. Injected by the boot callers. */
|
|
112
|
+
export type KeyDependentDataScan = (required: {
|
|
113
|
+
siteDir: string;
|
|
114
|
+
}) => Promise<boolean>;
|
|
115
|
+
export interface EnsureSiteKeyResult {
|
|
116
|
+
readonly action: SiteKeyEnsureAction;
|
|
117
|
+
/** Absent for `"production-noop"` — production has no per-site file to name. */
|
|
118
|
+
readonly perSiteFilePath?: string;
|
|
119
|
+
/** Present for `"noop"`, `"adopt"`, `"mint"`, and `"mismatch"` — the fingerprint of the key
|
|
120
|
+
* ACTUALLY in the per-site file right now (site-key plan §A.2's fingerprint stamp reuses this
|
|
121
|
+
* same value). For `"mismatch"` this is the file's real fingerprint, never the stale value still
|
|
122
|
+
* sitting in `.site-meta.json` — see {@link reconcileSiteKeyFingerprint}. */
|
|
123
|
+
readonly fingerprint?: string;
|
|
124
|
+
/** Present for `"invalid"` — which {@link SiteKeyRejection} the offending material failed. */
|
|
125
|
+
readonly reason?: SiteKeyRejection;
|
|
126
|
+
}
|
|
127
|
+
export interface EnsureSiteKeyForBootInput {
|
|
128
|
+
/** This site's own directory — same meaning as {@link EnsureSiteKeyInput.siteDir}. */
|
|
129
|
+
readonly siteDir: string;
|
|
130
|
+
readonly mode?: RuntimeMode | undefined;
|
|
131
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
132
|
+
readonly home?: string | undefined;
|
|
133
|
+
readonly cwd?: string | undefined;
|
|
134
|
+
}
|
|
135
|
+
export interface InstallSiteKeyInput {
|
|
136
|
+
readonly siteDir: string;
|
|
137
|
+
/** The key to install — a pasted old token already proven to open this site's data, or the key
|
|
138
|
+
* "Start fresh" keeps or mints. */
|
|
139
|
+
readonly hex: string;
|
|
140
|
+
readonly mode?: RuntimeMode | undefined;
|
|
141
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
142
|
+
readonly home?: string | undefined;
|
|
143
|
+
readonly cwd?: string | undefined;
|
|
144
|
+
}
|
|
145
|
+
/** `installed`: the key file now holds `hex` and the stamp names it. `env-key-set`: an env var
|
|
146
|
+
* holding a DIFFERENT key outranks every file (production), so nothing was written. */
|
|
147
|
+
export type InstallSiteKeyResult = {
|
|
148
|
+
readonly outcome: "installed";
|
|
149
|
+
readonly keyFilePath: string;
|
|
150
|
+
readonly fingerprint: string;
|
|
151
|
+
} | {
|
|
152
|
+
readonly outcome: "env-key-set";
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=ensure.d.ts.map
|