@serve.zone/interfaces 32.115.0 → 32.117.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.
Files changed (38) hide show
  1. package/changelog.md +16 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/controlledtakeover.d.ts +125 -0
  4. package/dist_ts/data/controlledtakeover.js +217 -0
  5. package/dist_ts/data/corestorereplication.d.ts +13 -0
  6. package/dist_ts/data/corestorereplication.js +27 -4
  7. package/dist_ts/data/diskencryption.d.ts +100 -0
  8. package/dist_ts/data/diskencryption.js +176 -0
  9. package/dist_ts/data/gatewayarearows.d.ts +17 -7
  10. package/dist_ts/data/gatewayarearows.js +31 -14
  11. package/dist_ts/data/index.d.ts +3 -0
  12. package/dist_ts/data/index.js +4 -1
  13. package/dist_ts/data/locationlock.d.ts +98 -0
  14. package/dist_ts/data/locationlock.js +175 -0
  15. package/dist_ts/index.d.ts +2 -0
  16. package/dist_ts/index.js +3 -1
  17. package/dist_ts/requests/controlledtakeover.d.ts +78 -0
  18. package/dist_ts/requests/controlledtakeover.js +45 -0
  19. package/dist_ts/requests/diskencryption.d.ts +73 -0
  20. package/dist_ts/requests/diskencryption.js +2 -0
  21. package/dist_ts/requests/index.d.ts +3 -0
  22. package/dist_ts/requests/index.js +4 -1
  23. package/dist_ts/requests/locationlock.d.ts +104 -0
  24. package/dist_ts/requests/locationlock.js +2 -0
  25. package/package.json +25 -1
  26. package/readme.md +34 -3
  27. package/ts/00_commitinfo_data.ts +1 -1
  28. package/ts/data/controlledtakeover.ts +338 -0
  29. package/ts/data/corestorereplication.ts +37 -3
  30. package/ts/data/diskencryption.ts +275 -0
  31. package/ts/data/gatewayarearows.ts +49 -18
  32. package/ts/data/index.ts +3 -0
  33. package/ts/data/locationlock.ts +280 -0
  34. package/ts/index.ts +2 -0
  35. package/ts/requests/controlledtakeover.ts +167 -0
  36. package/ts/requests/diskencryption.ts +81 -0
  37. package/ts/requests/index.ts +3 -0
  38. package/ts/requests/locationlock.ts +119 -0
@@ -1,8 +1,9 @@
1
1
  import { validateControllerIdentifier, validateControllerOrigin } from '../private/controllercontract.js';
2
- import { isPlainRecord, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
2
+ import { hasExactKeys, isPlainRecord, readDataProperties, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
3
3
  import { isClusterNodeId } from '../private/nodeidentifier.js';
4
4
  import { isBoundedInteger } from '../private/runtimepolicy.js';
5
5
  import { validateServiceId } from './coremail.runtime.js';
6
+ import { isSha256Digest, type TSha256Digest } from './immutableimage.js';
6
7
 
7
8
  export type TCorestoreReplicationRole = 'primary' | 'replica' | 'standalone';
8
9
 
@@ -59,6 +60,16 @@ export interface ICorestoreReplicationFence {
59
60
  timeline: ICorestoreReplicationTimeline;
60
61
  }
61
62
 
63
+ /** Rate limits, authenticated peer certificate pin and connection timers for the direct route. */
64
+ export interface ICorestoreReplicationTransportPolicy {
65
+ maxBytesPerSecond: number;
66
+ burstBytes: number;
67
+ peerCertificateSha256: TSha256Digest;
68
+ keepaliveIntervalMs: number;
69
+ reconnectBackoffMaxMs: number;
70
+ connectTimeoutMs: number;
71
+ }
72
+
62
73
  /**
63
74
  * Cloudly authorizes this directed binding and both Corestores persist the metadata. Replication
64
75
  * proceeds directly between authenticated peers during Cloudly downtime. Each peer compares the
@@ -69,6 +80,8 @@ export interface ICorestoreReplicationGrant {
69
80
  fence: ICorestoreReplicationFence;
70
81
  primary: ICorestoreReplicationPeer;
71
82
  replica: ICorestoreReplicationPeer;
83
+ /** Omit for peers whose exact grant reader predates the transport policy. */
84
+ transportPolicy?: ICorestoreReplicationTransportPolicy;
72
85
  }
73
86
 
74
87
  /** An authenticated, durable source receipt for a planned switchover. */
@@ -187,15 +200,36 @@ export const snapshotCorestoreReplicationFence = (value: unknown): ICorestoreRep
187
200
  };
188
201
  };
189
202
 
203
+ export const snapshotCorestoreReplicationTransportPolicy = (value: unknown): ICorestoreReplicationTransportPolicy => {
204
+ const policy = exact(value, [
205
+ 'maxBytesPerSecond', 'burstBytes', 'peerCertificateSha256',
206
+ 'keepaliveIntervalMs', 'reconnectBackoffMaxMs', 'connectTimeoutMs',
207
+ ]);
208
+ const { peerCertificateSha256 } = policy;
209
+ if (typeof peerCertificateSha256 !== 'string' || !isSha256Digest(peerCertificateSha256)) return invalid();
210
+ return {
211
+ maxBytesPerSecond: counter(policy.maxBytesPerSecond, 1),
212
+ burstBytes: counter(policy.burstBytes, 1),
213
+ peerCertificateSha256,
214
+ keepaliveIntervalMs: counter(policy.keepaliveIntervalMs, 1),
215
+ reconnectBackoffMaxMs: counter(policy.reconnectBackoffMaxMs, 1),
216
+ connectTimeoutMs: counter(policy.connectTimeoutMs, 1),
217
+ };
218
+ };
219
+
190
220
  /** Check the grant shape. Consumers resolve both peer/binding identities from trusted records. */
191
221
  export const snapshotCorestoreReplicationGrant = (value: unknown): ICorestoreReplicationGrant => {
192
- const grant = exact(value, ['fence', 'primary', 'replica']);
222
+ const grant = readDataProperties(value) ?? invalid();
223
+ if (!hasExactKeys(grant, ['fence', 'primary', 'replica'], ['transportPolicy'])) return invalid();
193
224
  const primary = peerOf(grant.primary);
194
225
  const replica = peerOf(grant.replica);
195
226
  if (primary.locationId === replica.locationId || primary.clusterId === replica.clusterId
196
227
  || primary.nodeId === replica.nodeId || primary.peerIdentityId === replica.peerIdentityId
197
228
  || primary.directOrigin === replica.directOrigin) return invalid();
198
- return { fence: snapshotCorestoreReplicationFence(grant.fence), primary, replica };
229
+ const snapshot = { fence: snapshotCorestoreReplicationFence(grant.fence), primary, replica };
230
+ return Object.hasOwn(grant, 'transportPolicy')
231
+ ? { ...snapshot, transportPolicy: snapshotCorestoreReplicationTransportPolicy(grant.transportPolicy) }
232
+ : snapshot;
199
233
  };
200
234
 
201
235
  export const snapshotCorestoreReplicationQuiescence = (value: unknown): ICorestoreReplicationQuiescence => {
@@ -0,0 +1,275 @@
1
+ import { isCanonicalBase64url32 } from '../private/bearerencoding.js';
2
+ import { validateControllerIdentifier } from '../private/controllercontract.js';
3
+ import { readExactDataRecord } from '../private/dataproperties.js';
4
+ import { isClusterNodeId } from '../private/nodeidentifier.js';
5
+ import { isBoundedInteger } from '../private/runtimepolicy.js';
6
+ import { isSha256Digest, type TSha256Digest } from './immutableimage.js';
7
+
8
+ export const diskEncryptionContract = Object.freeze({
9
+ defaultSilenceLimitMs: 3_600_000,
10
+ minimumSilenceLimitMs: 60_000,
11
+ maximumSilenceLimitMs: 86_400_000,
12
+ challengeTtlMs: 60_000,
13
+ digestDomain: 'serve.zone/disk-encryption-key-release',
14
+ });
15
+
16
+ const machineKinds = ['node', 'dcrouter', 'oneboxHost'] as const;
17
+ const keyAlgorithms = ['ecdsa-p256', 'ed25519'] as const;
18
+
19
+ export type TDiskEncryptionMachineKind = typeof machineKinds[number];
20
+ export type TDiskEncryptionKeyAlgorithm = typeof keyAlgorithms[number];
21
+
22
+ export const diskEncryptionRefusals = Object.freeze([
23
+ 'machine-not-enrolled', 'machine-revoked', 'location-locked', 'location-destroyed', 'challenge-invalid',
24
+ 'challenge-expired', 'signature-invalid', 'silence-limit-exceeded', 'approval-not-found', 'approval-expired',
25
+ 'location-not-found', 'fresh-passkey-required', 'conflict', 'request-invalid',
26
+ ] as const);
27
+
28
+ export type TDiskEncryptionRefusal = typeof diskEncryptionRefusals[number];
29
+
30
+ /** Public metadata only. Cloudly verifies TPM binding before recording an identity. */
31
+ export interface IDiskEncryptionNodeIdentity {
32
+ machineId: string;
33
+ machineKind: TDiskEncryptionMachineKind;
34
+ locationId: string;
35
+ keyAlgorithm: TDiskEncryptionKeyAlgorithm;
36
+ publicKeyPem: string;
37
+ publicKeySha256: TSha256Digest;
38
+ tpmBound: true;
39
+ tpmAttestationDigest: TSha256Digest | null;
40
+ enrolledAt: number;
41
+ enrolledBy: string;
42
+ lastSeenAt: number | null;
43
+ revokedAt: number | null;
44
+ revision: number;
45
+ }
46
+
47
+ export interface IDiskEncryptionKeyReleaseChallenge {
48
+ challengeId: string;
49
+ machineId: string;
50
+ /** Canonical unpadded base64url of a 32-byte nonce. */
51
+ nonceBase64Url: string;
52
+ controllerId: string;
53
+ controllerEpoch: number;
54
+ issuedAt: number;
55
+ expiresAt: number;
56
+ }
57
+
58
+ export interface IDiskEncryptionKeyReleaseProof {
59
+ challengeId: string;
60
+ machineId: string;
61
+ ephemeralPublicKeyPem: string;
62
+ signatureBase64Url: string;
63
+ }
64
+
65
+ /** Only the released variant carries a wrapped disk key. Keep it out of logs and status reads. */
66
+ export type TDiskEncryptionKeyReleaseOutcome =
67
+ | {
68
+ status: 'released';
69
+ wrappedKeyBase64: string;
70
+ wrappingAlgorithm: 'ecdh-p256-hkdf-sha256-aes-256-gcm';
71
+ controllerPublicKeyPem: string;
72
+ /** Canonical base64 of the 96-bit AES-GCM IV. */
73
+ ivBase64: string;
74
+ /** Canonical base64 of the 128-bit AES-GCM authentication tag. */
75
+ authTagBase64: string;
76
+ keyVersion: number;
77
+ issuedAt: number;
78
+ }
79
+ | {
80
+ status: 'approval-required';
81
+ approvalId: string;
82
+ reason: 'silence-limit-exceeded';
83
+ silenceMs: number;
84
+ silenceLimitMs: number;
85
+ expiresAt: number;
86
+ }
87
+ | { status: 'refused'; code: TDiskEncryptionRefusal };
88
+
89
+ /** An offline recovery key's metadata. The recovery key itself never crosses this wire. */
90
+ export interface IDiskEncryptionLocationRecoveryKey {
91
+ locationId: string;
92
+ recoveryKeyId: string;
93
+ keyFingerprintSha256: TSha256Digest;
94
+ createdAt: number;
95
+ createdBy: string;
96
+ destroyedAt: number | null;
97
+ revision: number;
98
+ }
99
+
100
+ export interface IDiskEncryptionUnlockApproval {
101
+ approvalId: string;
102
+ machineId: string;
103
+ locationId: string;
104
+ requestedAt: number;
105
+ silenceMs: number;
106
+ status: 'pending' | 'approved' | 'consumed' | 'expired' | 'denied';
107
+ approvedBy: string | null;
108
+ approvedAt: number | null;
109
+ expiresAt: number;
110
+ }
111
+
112
+ const invalid = (): never => { throw new Error('Disk encryption contract rejected.'); };
113
+
114
+ const exact = (value: unknown, keys: readonly string[]) => readExactDataRecord(value, keys) ?? invalid();
115
+ const isIdentifier = (value: unknown): value is string => validateControllerIdentifier(value, 'identifier').length === 0;
116
+ const identifier = (value: unknown): string => isIdentifier(value) ? value : invalid();
117
+ const machineIdOf = (value: unknown): string => isClusterNodeId(value) ? value : identifier(value);
118
+ const integer = (value: unknown, minimum: number): number =>
119
+ isBoundedInteger(value, minimum, Number.MAX_SAFE_INTEGER) ? value : invalid();
120
+ const timestamp = (value: unknown, minimum: number): number | null =>
121
+ value === null ? null : integer(value, minimum);
122
+ const digest = (value: unknown): TSha256Digest =>
123
+ typeof value === 'string' && isSha256Digest(value) ? value : invalid();
124
+ const choice = <T extends string>(value: unknown, choices: readonly T[]): T =>
125
+ choices.find((candidate) => candidate === value) ?? invalid();
126
+
127
+ const base64Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
128
+ const base64UrlAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
129
+
130
+ const assertZeroPadBits = (lastSextet: string, remainder: number, alphabet: string): void => {
131
+ if (remainder === 1 || (remainder === 2 && alphabet.indexOf(lastSextet) % 16 !== 0)
132
+ || (remainder === 3 && alphabet.indexOf(lastSextet) % 4 !== 0)) invalid();
133
+ };
134
+
135
+ const base64Of = (value: unknown, expectedBytes?: number): string => {
136
+ if (typeof value !== 'string' || value.length === 0 || value.length > 1024 || value.length % 4 !== 0
137
+ || !/^[A-Za-z0-9+/]+={0,2}$/.test(value)) return invalid();
138
+ const padding = value.endsWith('==') ? 2 : value.endsWith('=') ? 1 : 0;
139
+ assertZeroPadBits(value[value.length - padding - 1], (4 - padding) % 4, base64Alphabet);
140
+ if (expectedBytes !== undefined && value.length / 4 * 3 - padding !== expectedBytes) return invalid();
141
+ return value;
142
+ };
143
+
144
+ const signatureOf = (value: unknown): string => {
145
+ if (typeof value !== 'string' || value.length === 0 || value.length > 128
146
+ || !/^[A-Za-z0-9_-]+$/.test(value)) return invalid();
147
+ assertZeroPadBits(value[value.length - 1], value.length % 4, base64UrlAlphabet);
148
+ return value;
149
+ };
150
+
151
+ /** Check the public-key envelope. Cryptographic key parsing and algorithm checks belong to the owner. */
152
+ const publicKeyOf = (value: unknown): string => {
153
+ if (typeof value !== 'string' || value.length > 1024) return invalid();
154
+ const pem = /^-----BEGIN PUBLIC KEY-----\r?\n([A-Za-z0-9+/=\r\n]+)\r?\n-----END PUBLIC KEY-----(?:\r?\n)?$/.exec(value);
155
+ if (!pem) return invalid();
156
+ base64Of(pem[1].replace(/\r?\n/g, ''));
157
+ return value;
158
+ };
159
+
160
+ export const snapshotDiskEncryptionRefusal = (value: unknown): TDiskEncryptionRefusal => choice(value, diskEncryptionRefusals);
161
+
162
+ export const snapshotDiskEncryptionSilenceLimitMs = (value: unknown): number =>
163
+ isBoundedInteger(value, diskEncryptionContract.minimumSilenceLimitMs, diskEncryptionContract.maximumSilenceLimitMs)
164
+ ? value : invalid();
165
+
166
+ export const snapshotDiskEncryptionNodeIdentity = (value: unknown): IDiskEncryptionNodeIdentity => {
167
+ const identity = exact(value, [
168
+ 'machineId', 'machineKind', 'locationId', 'keyAlgorithm', 'publicKeyPem', 'publicKeySha256', 'tpmBound',
169
+ 'tpmAttestationDigest', 'enrolledAt', 'enrolledBy', 'lastSeenAt', 'revokedAt', 'revision',
170
+ ]);
171
+ if (identity.tpmBound !== true) return invalid();
172
+ const machineKind = choice(identity.machineKind, machineKinds);
173
+ const machineId = machineKind === 'node'
174
+ ? (isClusterNodeId(identity.machineId) ? identity.machineId : invalid())
175
+ : identifier(identity.machineId);
176
+ const enrolledAt = integer(identity.enrolledAt, 1);
177
+ const lastSeenAt = timestamp(identity.lastSeenAt, enrolledAt);
178
+ const revokedAt = timestamp(identity.revokedAt, lastSeenAt ?? enrolledAt);
179
+ return {
180
+ machineId, machineKind, locationId: identifier(identity.locationId),
181
+ keyAlgorithm: choice(identity.keyAlgorithm, keyAlgorithms), publicKeyPem: publicKeyOf(identity.publicKeyPem),
182
+ publicKeySha256: digest(identity.publicKeySha256), tpmBound: true,
183
+ tpmAttestationDigest: identity.tpmAttestationDigest === null ? null : digest(identity.tpmAttestationDigest),
184
+ enrolledAt, enrolledBy: identifier(identity.enrolledBy), lastSeenAt, revokedAt, revision: integer(identity.revision, 1),
185
+ };
186
+ };
187
+
188
+ export const snapshotDiskEncryptionKeyReleaseChallenge = (value: unknown): IDiskEncryptionKeyReleaseChallenge => {
189
+ const challenge = exact(value, [
190
+ 'challengeId', 'machineId', 'nonceBase64Url', 'controllerId', 'controllerEpoch', 'issuedAt', 'expiresAt',
191
+ ]);
192
+ const { nonceBase64Url } = challenge;
193
+ if (typeof nonceBase64Url !== 'string' || nonceBase64Url.length !== 43 || !isCanonicalBase64url32(nonceBase64Url)) {
194
+ return invalid();
195
+ }
196
+ const issuedAt = integer(challenge.issuedAt, 1);
197
+ const expiresAt = integer(challenge.expiresAt, 1);
198
+ if (expiresAt <= issuedAt || expiresAt - issuedAt > diskEncryptionContract.challengeTtlMs) return invalid();
199
+ return {
200
+ challengeId: identifier(challenge.challengeId), machineId: machineIdOf(challenge.machineId), nonceBase64Url,
201
+ controllerId: identifier(challenge.controllerId), controllerEpoch: integer(challenge.controllerEpoch, 1),
202
+ issuedAt, expiresAt,
203
+ };
204
+ };
205
+
206
+ export const snapshotDiskEncryptionKeyReleaseProof = (value: unknown): IDiskEncryptionKeyReleaseProof => {
207
+ const proof = exact(value, ['challengeId', 'machineId', 'ephemeralPublicKeyPem', 'signatureBase64Url']);
208
+ return {
209
+ challengeId: identifier(proof.challengeId), machineId: machineIdOf(proof.machineId),
210
+ ephemeralPublicKeyPem: publicKeyOf(proof.ephemeralPublicKeyPem), signatureBase64Url: signatureOf(proof.signatureBase64Url),
211
+ };
212
+ };
213
+
214
+ /** Reads the wire shape. Key possession, signatures, expiry and authorization are verified by Cloudly. */
215
+ export const snapshotDiskEncryptionKeyReleaseOutcome = (value: unknown): TDiskEncryptionKeyReleaseOutcome => {
216
+ const released = readExactDataRecord(value, [
217
+ 'status', 'wrappedKeyBase64', 'wrappingAlgorithm', 'controllerPublicKeyPem', 'ivBase64', 'authTagBase64',
218
+ 'keyVersion', 'issuedAt',
219
+ ]);
220
+ if (released?.status === 'released' && released.wrappingAlgorithm === 'ecdh-p256-hkdf-sha256-aes-256-gcm') {
221
+ return {
222
+ status: 'released', wrappedKeyBase64: base64Of(released.wrappedKeyBase64), wrappingAlgorithm: released.wrappingAlgorithm,
223
+ controllerPublicKeyPem: publicKeyOf(released.controllerPublicKeyPem), ivBase64: base64Of(released.ivBase64, 12),
224
+ authTagBase64: base64Of(released.authTagBase64, 16), keyVersion: integer(released.keyVersion, 1),
225
+ issuedAt: integer(released.issuedAt, 1),
226
+ };
227
+ }
228
+ const approval = readExactDataRecord(value, ['status', 'approvalId', 'reason', 'silenceMs', 'silenceLimitMs', 'expiresAt']);
229
+ if (approval?.status === 'approval-required' && approval.reason === 'silence-limit-exceeded') {
230
+ const silenceLimitMs = snapshotDiskEncryptionSilenceLimitMs(approval.silenceLimitMs);
231
+ const silenceMs = integer(approval.silenceMs, 1);
232
+ if (silenceMs <= silenceLimitMs) return invalid();
233
+ return {
234
+ status: 'approval-required', approvalId: identifier(approval.approvalId), reason: approval.reason,
235
+ silenceMs, silenceLimitMs, expiresAt: integer(approval.expiresAt, 1),
236
+ };
237
+ }
238
+ const refused = exact(value, ['status', 'code']);
239
+ if (refused.status !== 'refused') return invalid();
240
+ return { status: 'refused', code: snapshotDiskEncryptionRefusal(refused.code) };
241
+ };
242
+
243
+ export const snapshotDiskEncryptionLocationRecoveryKey = (value: unknown): IDiskEncryptionLocationRecoveryKey => {
244
+ const key = exact(value, [
245
+ 'locationId', 'recoveryKeyId', 'keyFingerprintSha256', 'createdAt', 'createdBy', 'destroyedAt', 'revision',
246
+ ]);
247
+ const createdAt = integer(key.createdAt, 1);
248
+ return {
249
+ locationId: identifier(key.locationId), recoveryKeyId: identifier(key.recoveryKeyId),
250
+ keyFingerprintSha256: digest(key.keyFingerprintSha256), createdAt, createdBy: identifier(key.createdBy),
251
+ destroyedAt: timestamp(key.destroyedAt, createdAt), revision: integer(key.revision, 1),
252
+ };
253
+ };
254
+
255
+ const approvalStatuses = ['pending', 'approved', 'consumed', 'expired', 'denied'] as const;
256
+
257
+ export const snapshotDiskEncryptionUnlockApproval = (value: unknown): IDiskEncryptionUnlockApproval => {
258
+ const approval = exact(value, [
259
+ 'approvalId', 'machineId', 'locationId', 'requestedAt', 'silenceMs', 'status', 'approvedBy', 'approvedAt', 'expiresAt',
260
+ ]);
261
+ const requestedAt = integer(approval.requestedAt, 1);
262
+ const expiresAt = integer(approval.expiresAt, 1);
263
+ const status = choice(approval.status, approvalStatuses);
264
+ const approvedBy = approval.approvedBy === null ? null : identifier(approval.approvedBy);
265
+ const approvedAt = timestamp(approval.approvedAt, requestedAt);
266
+ if (expiresAt <= requestedAt || (approvedBy === null) !== (approvedAt === null)
267
+ || (approvedAt !== null && approvedAt >= expiresAt)
268
+ || ((status === 'approved' || status === 'consumed') && approvedBy === null)
269
+ || ((status === 'pending' || status === 'denied') && approvedBy !== null)) return invalid();
270
+ return {
271
+ approvalId: identifier(approval.approvalId), machineId: machineIdOf(approval.machineId),
272
+ locationId: identifier(approval.locationId), requestedAt, silenceMs: integer(approval.silenceMs, 0),
273
+ status, approvedBy, approvedAt, expiresAt,
274
+ };
275
+ };
@@ -8,10 +8,12 @@
8
8
  * A row is addressed by area, member and id: a list member's row by its `id`, a singleton member
9
9
  * (`gatewayAreaSingletonMembers`) by `id: null`. Its write form (`IGatewayAreaRowWrites`) is its
10
10
  * table type (`gatewayareas.ts`) except that every secret-class member (`gatewayAreaSecretPaths`) is
11
- * a keep-or-set choice: a read answers every secret as `keep` (a sealed member with its version, a
11
+ * a keep-or-set choice, with an explicit promotion for the active edge secret. A read answers
12
+ * every secret as `keep` (a sealed member with its version, a
12
13
  * verifier without anything), so a row read and sent back unchanged writes nothing, and a write
13
14
  * states a new secret only as `set`. A sealed value's version is minted by the controller that
14
15
  * resolves the write (Linus ruling 121 Q9: by every write that sets a secret), never by the request.
16
+ * Promotion preserves the version of the staged secret it moves.
15
17
  * Nothing here carries a stored secret value: reads and answers name versions, never values.
16
18
  *
17
19
  * Both requests are for a human administrator who signed in within the last five minutes, with
@@ -84,6 +86,9 @@ export type TGatewaySealedValueWrite =
84
86
  /** A new value; the controller mints its version. */
85
87
  | { kind: 'set'; value: string };
86
88
 
89
+ /** Moves the observed staged version into the active slot and clears the staged slot. */
90
+ export type TGatewayEdgeSecretWrite = TGatewaySealedValueWrite | { kind: 'promoteStaged'; version: string };
91
+
87
92
  /** A verifier member in a row's write form; the secret it verifies never travels. */
88
93
  export type TGatewayVerifierWrite<TVerifier> =
89
94
  /**
@@ -152,14 +157,17 @@ export interface IGatewayCoreMailPeerRowWrite extends Omit<IGatewayCoreMailPeerR
152
157
  credentials: TGatewayVerifierWrite<IGatewayCoreMailCredentialVerifier[]>;
153
158
  }
154
159
 
155
- /** `IGatewayEdgeRow` with its tunnel secrets as keep-or-set choices. */
160
+ /** `IGatewayEdgeRow` in write form. A `promoteStaged` active secret requires `stagedSecret: null`. */
156
161
  export interface IGatewayEdgeRowWrite extends Omit<IGatewayEdgeRow, 'secret' | 'stagedSecret'> {
157
- secret: TGatewaySealedValueWrite;
162
+ secret: TGatewayEdgeSecretWrite;
158
163
  stagedSecret: TGatewaySealedValueWrite | null;
159
164
  }
160
165
 
161
166
  /** The row write form for an edge that still uses the pre-rotation table shape. */
162
- export type TGatewayLegacyEdgeRowWrite = Omit<IGatewayEdgeRowWrite, 'stagedSecret'> & { stagedSecret?: never };
167
+ export type TGatewayLegacyEdgeRowWrite = Omit<IGatewayEdgeRowWrite, 'secret' | 'stagedSecret'> & {
168
+ secret: TGatewaySealedValueWrite;
169
+ stagedSecret?: never;
170
+ };
163
171
 
164
172
  /**
165
173
  * The write form of one row of every member, by area and member: a list member's row, or a
@@ -325,6 +333,7 @@ const failRowDigest = (reasonArg: string): never => {
325
333
  * input (the read answers the row and the versions) cannot test a guess at a sealed value against
326
334
  * it. Throws, naming no value, for an unknown area or member, an `id` that is not `null` exactly
327
335
  * for a singleton, and a row that is not strict JSON or lacks a required sealed member or its version.
336
+ * A promotion write form must be resolved before computing the stored row's token.
328
337
  * Legacy edges rows have no `stagedSecret` member and retain their original digest input.
329
338
  */
330
339
  export const createGatewayAreaRowDigestInput = (inputArg: {
@@ -338,8 +347,11 @@ export const createGatewayAreaRowDigestInput = (inputArg: {
338
347
  if ((id === null) !== isGatewayAreaSingletonMember(area, member)) failRowDigest(`${area} ${member} takes ${id === null ? 'a row id' : 'id null'}`);
339
348
  const row = (copyStrictJson(inputArg.row) ?? failRowDigest(`the ${area} ${member} row is not strict JSON`)).value;
340
349
  for (const secret of secretPathsOf(area, member)) {
341
- if (secret.secretClass !== 'sealed') continue;
342
350
  const place = parentOf(row, splitPath(secret.path));
351
+ if (place !== null && readDataProperty(place.parent[place.key], 'kind')?.value === 'promoteStaged') {
352
+ failRowDigest(`the ${area} ${member} row's ${secret.path} is an unresolved promotion`);
353
+ }
354
+ if (secret.secretClass !== 'sealed') continue;
343
355
  if (place === null) {
344
356
  if (allowsLegacySecretOmission(area, member, secret.path)) continue;
345
357
  return failRowDigest(`the ${area} ${member} row has no member ${secret.path}`);
@@ -488,21 +500,34 @@ export type TGatewayAreaRowWriteReport =
488
500
  | { ok: true; written: IGatewayAreaRowWritten }
489
501
  | { ok: false; code: TGatewayAreaRowWriteRefusal; problems: string[] };
490
502
 
491
- /** One secret member of a write form as written: `null`, a keep or a set; `null` itself for a malformed form. */
503
+ /** One parsed secret write choice. `null` itself denotes a malformed form. */
492
504
  type TSecretWriteForm =
493
505
  | { form: 'null' }
494
506
  | { form: 'keep'; version: string | null }
507
+ | { form: 'promoteStaged'; version: string }
495
508
  | { form: 'set'; value: unknown };
496
509
 
497
- const readSecretWriteForm = (valueArg: unknown, secretClassArg: TGatewayAreaSecretClass): TSecretWriteForm | null => {
510
+ const permitsStagedPromotion = (
511
+ areaArg: TGatewayConfigArea, memberArg: string, pathArg: string, rowArg: unknown,
512
+ ): boolean => areaArg === 'edges' && memberArg === 'edges' && pathArg === 'secret'
513
+ && readDataProperty(rowArg, 'stagedSecret')?.value === null;
514
+
515
+ const readSecretWriteForm = (
516
+ valueArg: unknown, secretClassArg: TGatewayAreaSecretClass, permitsPromotionArg: boolean,
517
+ ): TSecretWriteForm | null => {
498
518
  if (valueArg === null) return { form: 'null' };
499
519
  if (secretClassArg === 'verifier') {
500
520
  if (readExactDataRecord(valueArg, ['kind'])?.kind === 'keep') return { form: 'keep', version: null };
501
521
  const set = readExactDataRecord(valueArg, ['kind', 'verifier']);
502
522
  return set?.kind === 'set' ? { form: 'set', value: set.verifier } : null;
503
523
  }
504
- const keep = readExactDataRecord(valueArg, ['kind', 'version']);
505
- if (keep?.kind === 'keep' && typeof keep.version === 'string') return { form: 'keep', version: keep.version };
524
+ const choice = readExactDataRecord(valueArg, ['kind', 'version']);
525
+ if (choice !== null && typeof choice.version === 'string') {
526
+ if (choice.kind === 'keep') return { form: 'keep', version: choice.version };
527
+ if (choice.kind === 'promoteStaged' && permitsPromotionArg) {
528
+ return { form: 'promoteStaged', version: choice.version };
529
+ }
530
+ }
506
531
  const set = readExactDataRecord(valueArg, ['kind', 'value']);
507
532
  return set?.kind === 'set' && typeof set.value === 'string' ? { form: 'set', value: set.value } : null;
508
533
  };
@@ -538,7 +563,8 @@ const rowWriteKeys = Object.freeze({
538
563
  * deleted) and a row id (`isGatewayAreaRowId`) for a list member, a `sha256:` `expectedDigest`
539
564
  * (`null` only for a put), and for a put a strict JSON row whose `id` is the address's (a list
540
565
  * member) and whose every secret member (`gatewayAreaSecretPaths`) is `null` or one of its
541
- * keep-or-set forms. A legacy edges row omits `stagedSecret`. A put of a `security` `apiTokens` row
566
+ * keep-or-set forms. Only `edges.edges.secret` may use `promoteStaged`, with an explicit
567
+ * `stagedSecret: null`. A legacy edges row omits `stagedSecret`. A put of a `security` `apiTokens` row
542
568
  * whose policy binds a gateway client (`isGatewayClientBoundApiTokenPolicy`) is refused naming the row (Linus ruling 376
543
569
  * item 6): the controller is the one author of the tables and compiles no gateway-client token, so
544
570
  * such a write would vanish at the next compile and a gateway from dcrouter 35 refuses it. The
@@ -582,8 +608,10 @@ export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'
582
608
  for (const secret of secretPathsOf(area, member)) {
583
609
  const place = parentOf(row, splitPath(secret.path));
584
610
  if (place === null && allowsLegacySecretOmission(area, member, secret.path)) continue;
585
- if (place === null || readSecretWriteForm(place.parent[place.key], secret.secretClass) === null) {
586
- problems.push(`${pathArg} row ${secret.path} must be null or a ${secret.secretClass} keep-or-set form`);
611
+ const permitsPromotion = permitsStagedPromotion(area, member, secret.path, row);
612
+ if (place === null || readSecretWriteForm(place.parent[place.key], secret.secretClass, permitsPromotion) === null) {
613
+ problems.push(`${pathArg} row ${secret.path} must be null or a ${secret.secretClass} keep-or-set form${
614
+ permitsPromotion ? ' or a staged promotion' : ''}`);
587
615
  }
588
616
  }
589
617
  return problems;
@@ -626,8 +654,8 @@ export const projectGatewayAreaRow = <TArea extends TGatewayConfigArea, TMember
626
654
 
627
655
  /**
628
656
  * Why a row's write form cannot be resolved, by the secret's path: `invalid-write-form` for a
629
- * secret member that is not one of its keep-or-set forms (a write `validateGatewayAreaRowWrite`
630
- * refuses), or `kept-secret-unknown` for a `keep` the stored row does not hold there. Never a value.
657
+ * secret member whose write form `validateGatewayAreaRowWrite` refuses, or `kept-secret-unknown`
658
+ * when the stored row lacks the referenced keep or promotion source. Never a value.
631
659
  */
632
660
  export interface IGatewayAreaRowWriteFormRefusal {
633
661
  /** The secret's dotted path inside the row; `''` for the row as a whole. */
@@ -646,7 +674,9 @@ export type TGatewayAreaRowResolution =
646
674
  * when the stored row holds that version there, a verifier `keep` the stored verifier when the row
647
675
  * holds one; a sealed `set` becomes `{ version: mintVersionArg(), value }`, a verifier `set` the
648
676
  * stated verifier; `null` stays `null`. A legacy write can omit `stagedSecret` only when the stored
649
- * row also omits it or the write creates a row. Every other member is copied as written. The area
677
+ * row also omits it or the write creates a row. `promoteStaged` moves the stored staged value and
678
+ * version to the active slot when the version matches, without minting a version. Every other
679
+ * member is copied as written. The area
650
680
  * validator judges the resolved row as part of its table. Judges the forms with the rule
651
681
  * `validateGatewayAreaRowWrite` applies and never reads a value into a refusal. The minted
652
682
  * versions are answered ascending by path. `mintVersionArg` is the writer's
@@ -669,7 +699,8 @@ export const resolveGatewayAreaRowWrite = (inputArg: {
669
699
  const place = parentOf(row, keys);
670
700
  if (place === null && allowsLegacySecretOmission(inputArg.area, inputArg.member, secret.path)
671
701
  && parentOf(inputArg.stored, keys) === null) continue;
672
- const form = place === null ? null : readSecretWriteForm(place.parent[place.key], secret.secretClass);
702
+ const form = place === null ? null : readSecretWriteForm(place.parent[place.key], secret.secretClass,
703
+ permitsStagedPromotion(inputArg.area, inputArg.member, secret.path, row));
673
704
  if (place === null || form === null) {
674
705
  refusals.push({ path: secret.path, code: 'invalid-write-form' });
675
706
  continue;
@@ -685,8 +716,8 @@ export const resolveGatewayAreaRowWrite = (inputArg: {
685
716
  minted.push({ path: secret.path, version });
686
717
  continue;
687
718
  }
688
- const storedPlace = inputArg.stored === null ? null : parentOf(inputArg.stored, keys);
689
- const storedValue = storedPlace === null ? null : storedPlace.parent[storedPlace.key] ?? null;
719
+ const storedPlace = parentOf(inputArg.stored, form.form === 'promoteStaged' ? ['stagedSecret'] : keys);
720
+ const storedValue = storedPlace === null ? null : readDataProperty(storedPlace.parent, storedPlace.key)?.value ?? null;
690
721
  if (secret.secretClass === 'verifier') {
691
722
  if (storedValue === null) refusals.push({ path: secret.path, code: 'kept-secret-unknown' });
692
723
  else place.parent[place.key] = copyStrictJson(storedValue)?.value ?? null;
package/ts/data/index.ts CHANGED
@@ -8,11 +8,13 @@ export * from './clusteringressdesignation.js';
8
8
  export * from './clusterrelaycredential.js';
9
9
  export * from './config.js';
10
10
  export * from './controller.js';
11
+ export * from './controlledtakeover.js';
11
12
  export * from './corestore.js';
12
13
  export * from './corestorecontroltoken.js';
13
14
  export * from './corestorelegacyadoption.js';
14
15
  export * from './corestorereplication.js';
15
16
  export * from './delegatedadmintoken.js';
17
+ export * from './diskencryption.js';
16
18
  export * from './coremail.js';
17
19
  export * from './coremail.runtime.js';
18
20
  export * from './deployment.js';
@@ -103,6 +105,7 @@ export * from './serviceports.js';
103
105
  export * from './serviceruntime.js';
104
106
  export * from './launchersecretowner.js';
105
107
  export * from './location.js';
108
+ export * from './locationlock.js';
106
109
  export * from './log.js';
107
110
  export * from './servicevolumeinitialization.js';
108
111
  export * from './status.js';