@serve.zone/interfaces 32.116.0 → 32.118.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serve.zone/interfaces",
3
- "version": "32.116.0",
3
+ "version": "32.118.0",
4
4
  "private": false,
5
5
  "description": "Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.",
6
6
  "exports": {
@@ -40,10 +40,18 @@
40
40
  "types": "./dist_ts/data/dcstorage.d.ts",
41
41
  "default": "./dist_ts/data/dcstorage.js"
42
42
  },
43
+ "./data/diskencryption": {
44
+ "types": "./dist_ts/data/diskencryption.d.ts",
45
+ "default": "./dist_ts/data/diskencryption.js"
46
+ },
43
47
  "./data/gateway": {
44
48
  "types": "./dist_ts/data/gateway.d.ts",
45
49
  "default": "./dist_ts/data/gateway.js"
46
50
  },
51
+ "./data/locationlock": {
52
+ "types": "./dist_ts/data/locationlock.d.ts",
53
+ "default": "./dist_ts/data/locationlock.js"
54
+ },
47
55
  "./data/mail": {
48
56
  "types": "./dist_ts/data/mail.d.ts",
49
57
  "default": "./dist_ts/data/mail.js"
@@ -96,6 +104,10 @@
96
104
  "types": "./dist_ts/requests/dcstorage.d.ts",
97
105
  "default": "./dist_ts/requests/dcstorage.js"
98
106
  },
107
+ "./requests/diskencryption": {
108
+ "types": "./dist_ts/requests/diskencryption.d.ts",
109
+ "default": "./dist_ts/requests/diskencryption.js"
110
+ },
99
111
  "./requests/gateway": {
100
112
  "types": "./dist_ts/requests/gateway.d.ts",
101
113
  "default": "./dist_ts/requests/gateway.js"
@@ -112,6 +124,10 @@
112
124
  "types": "./dist_ts/requests/gatewayhealth.d.ts",
113
125
  "default": "./dist_ts/requests/gatewayhealth.js"
114
126
  },
127
+ "./requests/locationlock": {
128
+ "types": "./dist_ts/requests/locationlock.d.ts",
129
+ "default": "./dist_ts/requests/locationlock.js"
130
+ },
115
131
  "./requests/mail": {
116
132
  "types": "./dist_ts/requests/mail.d.ts",
117
133
  "default": "./dist_ts/requests/mail.js"
package/readme.md CHANGED
@@ -38,14 +38,16 @@ and provides TypeScript declarations.
38
38
  | `/platformservice` | Legacy platform-service contracts. |
39
39
  | `/protocol` | Session offers, peer compatibility, and protocol refusals. |
40
40
  | `/data/backup`, `/requests/backup` | Backup and restore payloads, refusal helpers, and RPC types. |
41
- | `/data/controlledtakeover`, `/requests/controlledtakeover` | Controlled takeover operation snapshots and administrator RPC types for takeover and nupst webhook metadata. |
41
+ | `/data/controlledtakeover`, `/requests/controlledtakeover` | Controlled takeover snapshots and administrator RPCs for nupst webhook metadata and one-time HTTP credential disclosure. |
42
42
  | `/data/coremail`, `/requests/coremail`, `/requests/coremail-admin` | CoreMail data, validators, service RPC types, and administrator RPC types. |
43
43
  | `/data/corestore`, `/requests/corestore` | Corestore database allocation references, inventory, and control-plane RPC contracts. |
44
- | `/data/corestorereplication`, `/requests/corestorereplication` | Per-binding replication roles, lag, link grants, and administrator RPC types. |
44
+ | `/data/corestorereplication`, `/requests/corestorereplication` | Per-binding replication roles, lag, link grants with optional transport policy, and administrator RPC types. |
45
45
  | `/data/dcstorage`, `/requests/dcstorage` | Storage-node enrollment, pinned volume, pool membership and telemetry contracts. |
46
+ | `/data/diskencryption`, `/requests/diskencryption` | TPM-bound machine identities, key release challenges and outcomes, unlock approvals, and offline recovery key metadata. |
46
47
  | `/data/gateway`, `/requests/gateway`, `/requests/gatewayconnector` | Gateway client data and validators, client RPC types, and controller connector RPC types. |
47
48
  | `/requests/gatewaycertificatestore` | Gateway certificate store inventory, import, private export, and delete contracts. |
48
49
  | `/requests/gatewayhealth` | Capability-gated service health snapshots and Cloudly administrator RPC contracts. |
50
+ | `/data/locationlock`, `/requests/locationlock` | Location Lock and direct-only, two-administrator Destroy plans, operation snapshots, and administrator RPC types. |
49
51
  | `/data/mail`, `/requests/mail` | Service mail data and mail RPC types. |
50
52
  | `/data/preparedimages`, `/requests/preparedimages` | Pallet prepared-image lists, observations, and pull credential RPC types. |
51
53
  | `/runtime` | Node-only cryptographic and runtime helpers. |
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.116.0',
6
+ version: '32.118.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
@@ -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,331 @@
1
+ import { isCanonicalBase64url32 } from '../private/bearerencoding.js';
2
+ import { canonicalizeStrictJson } from '../private/canonicaljson.js';
3
+ import { validateControllerIdentifier } from '../private/controllercontract.js';
4
+ import { readExactDataRecord } from '../private/dataproperties.js';
5
+ import { isClusterNodeId } from '../private/nodeidentifier.js';
6
+ import { isBoundedInteger } from '../private/runtimepolicy.js';
7
+ import { isSha256Digest, type TSha256Digest } from './immutableimage.js';
8
+
9
+ export const diskEncryptionContract = Object.freeze({
10
+ defaultSilenceLimitMs: 3_600_000,
11
+ minimumSilenceLimitMs: 60_000,
12
+ maximumSilenceLimitMs: 86_400_000,
13
+ challengeTtlMs: 60_000,
14
+ digestDomain: 'serve.zone/disk-encryption-key-release',
15
+ /** HKDF-SHA256 `info` of a released key's wrap (`TDiskEncryptionKeyReleaseOutcome`). */
16
+ wrapInfo: 'serve.zone/disk-encryption-key-release/aes-256-gcm',
17
+ /** Both algorithms' signatures: `ecdsa-p256` as IEEE P1363 `r || s`, `ed25519` as RFC 8032. */
18
+ signatureBytes: 64,
19
+ });
20
+
21
+ const machineKinds = ['node', 'dcrouter', 'oneboxHost'] as const;
22
+ const keyAlgorithms = ['ecdsa-p256', 'ed25519'] as const;
23
+
24
+ export type TDiskEncryptionMachineKind = typeof machineKinds[number];
25
+ export type TDiskEncryptionKeyAlgorithm = typeof keyAlgorithms[number];
26
+
27
+ export const diskEncryptionRefusals = Object.freeze([
28
+ 'machine-not-enrolled', 'machine-revoked', 'location-locked', 'location-destroyed', 'challenge-invalid',
29
+ 'challenge-expired', 'signature-invalid', 'silence-limit-exceeded', 'approval-not-found', 'approval-expired',
30
+ 'location-not-found', 'fresh-passkey-required', 'conflict', 'request-invalid',
31
+ ] as const);
32
+
33
+ export type TDiskEncryptionRefusal = typeof diskEncryptionRefusals[number];
34
+
35
+ /** Public metadata only. Cloudly verifies TPM binding before recording an identity. */
36
+ export interface IDiskEncryptionNodeIdentity {
37
+ machineId: string;
38
+ machineKind: TDiskEncryptionMachineKind;
39
+ locationId: string;
40
+ keyAlgorithm: TDiskEncryptionKeyAlgorithm;
41
+ publicKeyPem: string;
42
+ publicKeySha256: TSha256Digest;
43
+ tpmBound: true;
44
+ tpmAttestationDigest: TSha256Digest | null;
45
+ enrolledAt: number;
46
+ enrolledBy: string;
47
+ lastSeenAt: number | null;
48
+ revokedAt: number | null;
49
+ revision: number;
50
+ }
51
+
52
+ export interface IDiskEncryptionKeyReleaseChallenge {
53
+ challengeId: string;
54
+ machineId: string;
55
+ /** Canonical unpadded base64url of a 32-byte nonce. */
56
+ nonceBase64Url: string;
57
+ controllerId: string;
58
+ controllerEpoch: number;
59
+ issuedAt: number;
60
+ expiresAt: number;
61
+ }
62
+
63
+ export interface IDiskEncryptionKeyReleaseProof {
64
+ challengeId: string;
65
+ machineId: string;
66
+ ephemeralPublicKeyPem: string;
67
+ signatureBase64Url: string;
68
+ }
69
+
70
+ /** Only the released variant carries a wrapped disk key. Keep it out of logs and status reads. */
71
+ export type TDiskEncryptionKeyReleaseOutcome =
72
+ | {
73
+ status: 'released';
74
+ wrappedKeyBase64: string;
75
+ wrappingAlgorithm: 'ecdh-p256-hkdf-sha256-aes-256-gcm';
76
+ controllerPublicKeyPem: string;
77
+ /** Canonical base64 of the 96-bit AES-GCM IV. */
78
+ ivBase64: string;
79
+ /** Canonical base64 of the 128-bit AES-GCM authentication tag. */
80
+ authTagBase64: string;
81
+ keyVersion: number;
82
+ issuedAt: number;
83
+ }
84
+ | {
85
+ status: 'approval-required';
86
+ approvalId: string;
87
+ reason: 'silence-limit-exceeded';
88
+ silenceMs: number;
89
+ silenceLimitMs: number;
90
+ expiresAt: number;
91
+ }
92
+ | { status: 'refused'; code: TDiskEncryptionRefusal };
93
+
94
+ /** An offline recovery key's metadata. The recovery key itself never crosses this wire. */
95
+ export interface IDiskEncryptionLocationRecoveryKey {
96
+ locationId: string;
97
+ recoveryKeyId: string;
98
+ keyFingerprintSha256: TSha256Digest;
99
+ createdAt: number;
100
+ createdBy: string;
101
+ destroyedAt: number | null;
102
+ revision: number;
103
+ }
104
+
105
+ export interface IDiskEncryptionUnlockApproval {
106
+ approvalId: string;
107
+ machineId: string;
108
+ locationId: string;
109
+ requestedAt: number;
110
+ silenceMs: number;
111
+ status: 'pending' | 'approved' | 'consumed' | 'expired' | 'denied';
112
+ approvedBy: string | null;
113
+ approvedAt: number | null;
114
+ expiresAt: number;
115
+ }
116
+
117
+ const invalid = (): never => { throw new Error('Disk encryption contract rejected.'); };
118
+
119
+ const exact = (value: unknown, keys: readonly string[]) => readExactDataRecord(value, keys) ?? invalid();
120
+ const isIdentifier = (value: unknown): value is string => validateControllerIdentifier(value, 'identifier').length === 0;
121
+ const identifier = (value: unknown): string => isIdentifier(value) ? value : invalid();
122
+ const machineIdOf = (value: unknown): string => isClusterNodeId(value) ? value : identifier(value);
123
+ const integer = (value: unknown, minimum: number): number =>
124
+ isBoundedInteger(value, minimum, Number.MAX_SAFE_INTEGER) ? value : invalid();
125
+ const timestamp = (value: unknown, minimum: number): number | null =>
126
+ value === null ? null : integer(value, minimum);
127
+ const digest = (value: unknown): TSha256Digest =>
128
+ typeof value === 'string' && isSha256Digest(value) ? value : invalid();
129
+ const choice = <T extends string>(value: unknown, choices: readonly T[]): T =>
130
+ choices.find((candidate) => candidate === value) ?? invalid();
131
+
132
+ const base64Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
133
+ const base64UrlAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
134
+
135
+ const assertZeroPadBits = (lastSextet: string, remainder: number, alphabet: string): void => {
136
+ if (remainder === 1 || (remainder === 2 && alphabet.indexOf(lastSextet) % 16 !== 0)
137
+ || (remainder === 3 && alphabet.indexOf(lastSextet) % 4 !== 0)) invalid();
138
+ };
139
+
140
+ const base64Of = (value: unknown, expectedBytes?: number): string => {
141
+ if (typeof value !== 'string' || value.length === 0 || value.length > 1024 || value.length % 4 !== 0
142
+ || !/^[A-Za-z0-9+/]+={0,2}$/.test(value)) return invalid();
143
+ const padding = value.endsWith('==') ? 2 : value.endsWith('=') ? 1 : 0;
144
+ assertZeroPadBits(value[value.length - padding - 1], (4 - padding) % 4, base64Alphabet);
145
+ if (expectedBytes !== undefined && value.length / 4 * 3 - padding !== expectedBytes) return invalid();
146
+ return value;
147
+ };
148
+
149
+ const signatureOf = (value: unknown): string => {
150
+ if (typeof value !== 'string' || value.length === 0 || value.length > 128
151
+ || !/^[A-Za-z0-9_-]+$/.test(value)) return invalid();
152
+ assertZeroPadBits(value[value.length - 1], value.length % 4, base64UrlAlphabet);
153
+ return value;
154
+ };
155
+
156
+ /** Check the public-key envelope. Cryptographic key parsing and algorithm checks belong to the owner. */
157
+ const publicKeyOf = (value: unknown): string => {
158
+ if (typeof value !== 'string' || value.length > 1024) return invalid();
159
+ const pem = /^-----BEGIN PUBLIC KEY-----\r?\n([A-Za-z0-9+/=\r\n]+)\r?\n-----END PUBLIC KEY-----(?:\r?\n)?$/.exec(value);
160
+ if (!pem) return invalid();
161
+ base64Of(pem[1].replace(/\r?\n/g, ''));
162
+ return value;
163
+ };
164
+
165
+ /** The members of a key release proof its signature covers, with the challenge's nonce. */
166
+ export interface IDiskEncryptionKeyReleaseSignedFields {
167
+ challengeId: string;
168
+ nonceBase64Url: string;
169
+ machineId: string;
170
+ ephemeralPublicKeyPem: string;
171
+ }
172
+
173
+ /**
174
+ * The exact bytes a machine signs to release its disk key, and Cloudly verifies: the UTF-8 strict
175
+ * canonical JSON (keys in UTF-16 code unit order) of `{ domain, challengeId, nonceBase64Url,
176
+ * machineId, ephemeralPublicKeyPem }`, with `domain` = `diskEncryptionContract.digestDomain`. The
177
+ * ephemeral public key is the PEM string exactly as the proof carries it, never re-encoded, so a
178
+ * `\r\n` PEM signs other bytes than a `\n` one.
179
+ *
180
+ * The proof digest is the SHA-256 of these bytes (`computeDiskEncryptionKeyReleaseDigest`). Both
181
+ * algorithms sign that 32-byte digest and encode a `signatureBytes` signature as unpadded base64url:
182
+ * `ecdsa-p256` is ECDSA over the digest as a prehashed SHA-256 value (a TPM2_Sign of the digest,
183
+ * which verifies as ECDSA-SHA256 over these bytes), `r || s` (IEEE P1363); `ed25519` is PureEdDSA
184
+ * with the 32-byte digest as its message.
185
+ *
186
+ * A released key is wrapped to the proof's ephemeral P-256 key: the raw ECDH shared secret of a
187
+ * fresh controller P-256 key pair (`controllerPublicKeyPem`), HKDF-SHA256 with salt = proof digest,
188
+ * info = `diskEncryptionContract.wrapInfo` and 32 output bytes, then AES-256-GCM with the 96-bit IV
189
+ * and the proof digest as additional authenticated data.
190
+ */
191
+ export const createDiskEncryptionKeyReleaseMessage = (fieldsArg: IDiskEncryptionKeyReleaseSignedFields): Uint8Array => {
192
+ const fields = exact(fieldsArg, ['challengeId', 'nonceBase64Url', 'machineId', 'ephemeralPublicKeyPem']);
193
+ const { nonceBase64Url } = fields;
194
+ if (typeof nonceBase64Url !== 'string' || nonceBase64Url.length !== 43 || !isCanonicalBase64url32(nonceBase64Url)) {
195
+ return invalid();
196
+ }
197
+ return new TextEncoder().encode(canonicalizeStrictJson({
198
+ domain: diskEncryptionContract.digestDomain,
199
+ challengeId: identifier(fields.challengeId),
200
+ nonceBase64Url,
201
+ machineId: machineIdOf(fields.machineId),
202
+ ephemeralPublicKeyPem: publicKeyOf(fields.ephemeralPublicKeyPem),
203
+ }, invalid, 'disk encryption key release'));
204
+ };
205
+
206
+ /** The 32-byte proof digest: SHA-256 of `createDiskEncryptionKeyReleaseMessage`, through Web Crypto. */
207
+ export const computeDiskEncryptionKeyReleaseDigest = async (
208
+ fieldsArg: IDiskEncryptionKeyReleaseSignedFields,
209
+ ): Promise<Uint8Array> => {
210
+ const message = createDiskEncryptionKeyReleaseMessage(fieldsArg);
211
+ const subtle = globalThis.crypto?.subtle;
212
+ if (!subtle) throw new Error('Web Crypto SHA-256 is unavailable in this runtime.');
213
+ return new Uint8Array(await subtle.digest('SHA-256', new Uint8Array(message)));
214
+ };
215
+
216
+ export const snapshotDiskEncryptionRefusal = (value: unknown): TDiskEncryptionRefusal => choice(value, diskEncryptionRefusals);
217
+
218
+ export const snapshotDiskEncryptionSilenceLimitMs = (value: unknown): number =>
219
+ isBoundedInteger(value, diskEncryptionContract.minimumSilenceLimitMs, diskEncryptionContract.maximumSilenceLimitMs)
220
+ ? value : invalid();
221
+
222
+ export const snapshotDiskEncryptionNodeIdentity = (value: unknown): IDiskEncryptionNodeIdentity => {
223
+ const identity = exact(value, [
224
+ 'machineId', 'machineKind', 'locationId', 'keyAlgorithm', 'publicKeyPem', 'publicKeySha256', 'tpmBound',
225
+ 'tpmAttestationDigest', 'enrolledAt', 'enrolledBy', 'lastSeenAt', 'revokedAt', 'revision',
226
+ ]);
227
+ if (identity.tpmBound !== true) return invalid();
228
+ const machineKind = choice(identity.machineKind, machineKinds);
229
+ const machineId = machineKind === 'node'
230
+ ? (isClusterNodeId(identity.machineId) ? identity.machineId : invalid())
231
+ : identifier(identity.machineId);
232
+ const enrolledAt = integer(identity.enrolledAt, 1);
233
+ const lastSeenAt = timestamp(identity.lastSeenAt, enrolledAt);
234
+ const revokedAt = timestamp(identity.revokedAt, lastSeenAt ?? enrolledAt);
235
+ return {
236
+ machineId, machineKind, locationId: identifier(identity.locationId),
237
+ keyAlgorithm: choice(identity.keyAlgorithm, keyAlgorithms), publicKeyPem: publicKeyOf(identity.publicKeyPem),
238
+ publicKeySha256: digest(identity.publicKeySha256), tpmBound: true,
239
+ tpmAttestationDigest: identity.tpmAttestationDigest === null ? null : digest(identity.tpmAttestationDigest),
240
+ enrolledAt, enrolledBy: identifier(identity.enrolledBy), lastSeenAt, revokedAt, revision: integer(identity.revision, 1),
241
+ };
242
+ };
243
+
244
+ export const snapshotDiskEncryptionKeyReleaseChallenge = (value: unknown): IDiskEncryptionKeyReleaseChallenge => {
245
+ const challenge = exact(value, [
246
+ 'challengeId', 'machineId', 'nonceBase64Url', 'controllerId', 'controllerEpoch', 'issuedAt', 'expiresAt',
247
+ ]);
248
+ const { nonceBase64Url } = challenge;
249
+ if (typeof nonceBase64Url !== 'string' || nonceBase64Url.length !== 43 || !isCanonicalBase64url32(nonceBase64Url)) {
250
+ return invalid();
251
+ }
252
+ const issuedAt = integer(challenge.issuedAt, 1);
253
+ const expiresAt = integer(challenge.expiresAt, 1);
254
+ if (expiresAt <= issuedAt || expiresAt - issuedAt > diskEncryptionContract.challengeTtlMs) return invalid();
255
+ return {
256
+ challengeId: identifier(challenge.challengeId), machineId: machineIdOf(challenge.machineId), nonceBase64Url,
257
+ controllerId: identifier(challenge.controllerId), controllerEpoch: integer(challenge.controllerEpoch, 1),
258
+ issuedAt, expiresAt,
259
+ };
260
+ };
261
+
262
+ export const snapshotDiskEncryptionKeyReleaseProof = (value: unknown): IDiskEncryptionKeyReleaseProof => {
263
+ const proof = exact(value, ['challengeId', 'machineId', 'ephemeralPublicKeyPem', 'signatureBase64Url']);
264
+ return {
265
+ challengeId: identifier(proof.challengeId), machineId: machineIdOf(proof.machineId),
266
+ ephemeralPublicKeyPem: publicKeyOf(proof.ephemeralPublicKeyPem), signatureBase64Url: signatureOf(proof.signatureBase64Url),
267
+ };
268
+ };
269
+
270
+ /** Reads the wire shape. Key possession, signatures, expiry and authorization are verified by Cloudly. */
271
+ export const snapshotDiskEncryptionKeyReleaseOutcome = (value: unknown): TDiskEncryptionKeyReleaseOutcome => {
272
+ const released = readExactDataRecord(value, [
273
+ 'status', 'wrappedKeyBase64', 'wrappingAlgorithm', 'controllerPublicKeyPem', 'ivBase64', 'authTagBase64',
274
+ 'keyVersion', 'issuedAt',
275
+ ]);
276
+ if (released?.status === 'released' && released.wrappingAlgorithm === 'ecdh-p256-hkdf-sha256-aes-256-gcm') {
277
+ return {
278
+ status: 'released', wrappedKeyBase64: base64Of(released.wrappedKeyBase64), wrappingAlgorithm: released.wrappingAlgorithm,
279
+ controllerPublicKeyPem: publicKeyOf(released.controllerPublicKeyPem), ivBase64: base64Of(released.ivBase64, 12),
280
+ authTagBase64: base64Of(released.authTagBase64, 16), keyVersion: integer(released.keyVersion, 1),
281
+ issuedAt: integer(released.issuedAt, 1),
282
+ };
283
+ }
284
+ const approval = readExactDataRecord(value, ['status', 'approvalId', 'reason', 'silenceMs', 'silenceLimitMs', 'expiresAt']);
285
+ if (approval?.status === 'approval-required' && approval.reason === 'silence-limit-exceeded') {
286
+ const silenceLimitMs = snapshotDiskEncryptionSilenceLimitMs(approval.silenceLimitMs);
287
+ const silenceMs = integer(approval.silenceMs, 1);
288
+ if (silenceMs <= silenceLimitMs) return invalid();
289
+ return {
290
+ status: 'approval-required', approvalId: identifier(approval.approvalId), reason: approval.reason,
291
+ silenceMs, silenceLimitMs, expiresAt: integer(approval.expiresAt, 1),
292
+ };
293
+ }
294
+ const refused = exact(value, ['status', 'code']);
295
+ if (refused.status !== 'refused') return invalid();
296
+ return { status: 'refused', code: snapshotDiskEncryptionRefusal(refused.code) };
297
+ };
298
+
299
+ export const snapshotDiskEncryptionLocationRecoveryKey = (value: unknown): IDiskEncryptionLocationRecoveryKey => {
300
+ const key = exact(value, [
301
+ 'locationId', 'recoveryKeyId', 'keyFingerprintSha256', 'createdAt', 'createdBy', 'destroyedAt', 'revision',
302
+ ]);
303
+ const createdAt = integer(key.createdAt, 1);
304
+ return {
305
+ locationId: identifier(key.locationId), recoveryKeyId: identifier(key.recoveryKeyId),
306
+ keyFingerprintSha256: digest(key.keyFingerprintSha256), createdAt, createdBy: identifier(key.createdBy),
307
+ destroyedAt: timestamp(key.destroyedAt, createdAt), revision: integer(key.revision, 1),
308
+ };
309
+ };
310
+
311
+ const approvalStatuses = ['pending', 'approved', 'consumed', 'expired', 'denied'] as const;
312
+
313
+ export const snapshotDiskEncryptionUnlockApproval = (value: unknown): IDiskEncryptionUnlockApproval => {
314
+ const approval = exact(value, [
315
+ 'approvalId', 'machineId', 'locationId', 'requestedAt', 'silenceMs', 'status', 'approvedBy', 'approvedAt', 'expiresAt',
316
+ ]);
317
+ const requestedAt = integer(approval.requestedAt, 1);
318
+ const expiresAt = integer(approval.expiresAt, 1);
319
+ const status = choice(approval.status, approvalStatuses);
320
+ const approvedBy = approval.approvedBy === null ? null : identifier(approval.approvedBy);
321
+ const approvedAt = timestamp(approval.approvedAt, requestedAt);
322
+ if (expiresAt <= requestedAt || (approvedBy === null) !== (approvedAt === null)
323
+ || (approvedAt !== null && approvedAt >= expiresAt)
324
+ || ((status === 'approved' || status === 'consumed') && approvedBy === null)
325
+ || ((status === 'pending' || status === 'denied') && approvedBy !== null)) return invalid();
326
+ return {
327
+ approvalId: identifier(approval.approvalId), machineId: machineIdOf(approval.machineId),
328
+ locationId: identifier(approval.locationId), requestedAt, silenceMs: integer(approval.silenceMs, 0),
329
+ status, approvedBy, approvedAt, expiresAt,
330
+ };
331
+ };
package/ts/data/index.ts CHANGED
@@ -14,6 +14,7 @@ export * from './corestorecontroltoken.js';
14
14
  export * from './corestorelegacyadoption.js';
15
15
  export * from './corestorereplication.js';
16
16
  export * from './delegatedadmintoken.js';
17
+ export * from './diskencryption.js';
17
18
  export * from './coremail.js';
18
19
  export * from './coremail.runtime.js';
19
20
  export * from './deployment.js';
@@ -104,6 +105,7 @@ export * from './serviceports.js';
104
105
  export * from './serviceruntime.js';
105
106
  export * from './launchersecretowner.js';
106
107
  export * from './location.js';
108
+ export * from './locationlock.js';
107
109
  export * from './log.js';
108
110
  export * from './servicevolumeinitialization.js';
109
111
  export * from './status.js';