@openplanr/protocol 0.6.1 → 0.7.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 (58) hide show
  1. package/README.md +10 -0
  2. package/lib/dashboard/closed-json-contract.mjs +99 -109
  3. package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
  4. package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
  5. package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
  6. package/lib/dashboard/operate-experience-display-contract.mjs +777 -831
  7. package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
  8. package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
  9. package/lib/dashboard/operate-review-contract.d.mts +7 -14
  10. package/lib/dashboard/operate-review-contract.mjs +46 -42
  11. package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
  12. package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
  13. package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
  14. package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
  15. package/lib/protocol/index.d.ts +2647 -543
  16. package/package.json +1 -1
  17. package/registries/artifact-theme.json +64 -0
  18. package/registries/commands.json +40 -40
  19. package/registries/skills.json +5 -5
  20. package/schemas/v1.14.0/artifact-theme.schema.json +316 -0
  21. package/src/browser-contracts.d.mts +4 -1
  22. package/src/browser-contracts.mjs +16 -5
  23. package/src/canonical-json.d.mts +6 -1
  24. package/src/canonical-json.mjs +100 -22
  25. package/src/compat/live-evidence-v2.mjs +1611 -485
  26. package/src/compat/operate-experience-live-patch.mjs +67 -15
  27. package/src/compat/operating-planning-contracts.mjs +183 -51
  28. package/src/contracts.d.mts +54 -13
  29. package/src/contracts.mjs +635 -343
  30. package/src/design-contracts.mjs +58 -21
  31. package/src/design-handoff-contracts.d.mts +67 -11
  32. package/src/design-handoff-contracts.mjs +236 -119
  33. package/src/design-publication-contracts.mjs +98 -33
  34. package/src/diagram-authoring-contracts.d.mts +422 -78
  35. package/src/diagram-authoring-contracts.mjs +1715 -335
  36. package/src/diagram-contracts.d.mts +4 -1
  37. package/src/diagram-contracts.mjs +16 -4
  38. package/src/enterprise-contracts.d.mts +211 -46
  39. package/src/enterprise-contracts.mjs +738 -184
  40. package/src/errors.mjs +4 -0
  41. package/src/generated/canonical-registries.mjs +45 -45
  42. package/src/index.d.mts +8 -8
  43. package/src/index.mjs +36 -20
  44. package/src/json-schema.d.mts +21 -6
  45. package/src/json-schema.mjs +66 -18
  46. package/src/planning-contracts.d.mts +8 -2
  47. package/src/planning-contracts.mjs +33 -7
  48. package/src/registries.d.mts +11 -3
  49. package/src/registries.mjs +369 -87
  50. package/src/review-experience-contracts.d.mts +7 -2
  51. package/src/review-experience-contracts.mjs +198 -49
  52. package/src/semver.mjs +5 -1
  53. package/src/skill-source-contracts.d.mts +36 -16
  54. package/src/skill-source-contracts.mjs +25 -6
  55. package/src/task-contracts.d.mts +13 -3
  56. package/src/task-contracts.mjs +181 -40
  57. package/src/workspace-contracts.d.mts +38 -10
  58. package/src/workspace-contracts.mjs +147 -33
@@ -0,0 +1,316 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://openplanr.dev/schemas/v1.14.0/artifact-theme.schema.json",
4
+ "x-openplanr-contract": {
5
+ "id": "artifact-theme",
6
+ "version": "1.14.0"
7
+ },
8
+ "title": "OpenPlanr artifact review theme registry",
9
+ "type": "object",
10
+ "additionalProperties": false,
11
+ "required": [
12
+ "kind",
13
+ "schemaVersion",
14
+ "protocolVersion",
15
+ "name",
16
+ "typography",
17
+ "layout",
18
+ "themes"
19
+ ],
20
+ "properties": {
21
+ "kind": {
22
+ "const": "artifact-theme"
23
+ },
24
+ "schemaVersion": {
25
+ "const": "1.1.0"
26
+ },
27
+ "protocolVersion": {
28
+ "const": "1.14.0"
29
+ },
30
+ "name": {
31
+ "const": "OpenPlanr Artifact Review"
32
+ },
33
+ "typography": {
34
+ "type": "object",
35
+ "additionalProperties": false,
36
+ "required": [
37
+ "display",
38
+ "body",
39
+ "mono"
40
+ ],
41
+ "properties": {
42
+ "display": {
43
+ "const": "Outfit"
44
+ },
45
+ "body": {
46
+ "const": "DM Sans"
47
+ },
48
+ "mono": {
49
+ "const": "Source Code Pro"
50
+ }
51
+ }
52
+ },
53
+ "layout": {
54
+ "type": "object",
55
+ "additionalProperties": false,
56
+ "required": [
57
+ "toolbarHeight",
58
+ "reviewRailWidth",
59
+ "radiusSmall",
60
+ "radiusMedium",
61
+ "radiusLarge",
62
+ "motionFastMs",
63
+ "motionBaseMs"
64
+ ],
65
+ "properties": {
66
+ "toolbarHeight": {
67
+ "const": 48
68
+ },
69
+ "reviewRailWidth": {
70
+ "const": 344
71
+ },
72
+ "radiusSmall": {
73
+ "type": "integer",
74
+ "minimum": 0,
75
+ "maximum": 32
76
+ },
77
+ "radiusMedium": {
78
+ "type": "integer",
79
+ "minimum": 0,
80
+ "maximum": 32
81
+ },
82
+ "radiusLarge": {
83
+ "type": "integer",
84
+ "minimum": 0,
85
+ "maximum": 32
86
+ },
87
+ "motionFastMs": {
88
+ "type": "integer",
89
+ "minimum": 120,
90
+ "maximum": 200
91
+ },
92
+ "motionBaseMs": {
93
+ "type": "integer",
94
+ "minimum": 120,
95
+ "maximum": 200
96
+ }
97
+ }
98
+ },
99
+ "themes": {
100
+ "type": "object",
101
+ "additionalProperties": false,
102
+ "required": [
103
+ "dark",
104
+ "light"
105
+ ],
106
+ "properties": {
107
+ "dark": {
108
+ "type": "object",
109
+ "additionalProperties": false,
110
+ "required": [
111
+ "background",
112
+ "chrome",
113
+ "panel",
114
+ "raised",
115
+ "stage",
116
+ "rule",
117
+ "text",
118
+ "textMuted",
119
+ "primary",
120
+ "primaryStrong",
121
+ "onPrimary",
122
+ "warning",
123
+ "danger",
124
+ "onDanger",
125
+ "question",
126
+ "onQuestion",
127
+ "resolved",
128
+ "onResolved",
129
+ "onImprove"
130
+ ],
131
+ "properties": {
132
+ "background": {
133
+ "type": "string",
134
+ "pattern": "^#[0-9A-Fa-f]{6}$"
135
+ },
136
+ "chrome": {
137
+ "type": "string",
138
+ "pattern": "^#[0-9A-Fa-f]{6}$"
139
+ },
140
+ "panel": {
141
+ "type": "string",
142
+ "pattern": "^#[0-9A-Fa-f]{6}$"
143
+ },
144
+ "raised": {
145
+ "type": "string",
146
+ "pattern": "^#[0-9A-Fa-f]{6}$"
147
+ },
148
+ "stage": {
149
+ "type": "string",
150
+ "pattern": "^#[0-9A-Fa-f]{6}$"
151
+ },
152
+ "rule": {
153
+ "type": "string",
154
+ "pattern": "^#[0-9A-Fa-f]{6}$"
155
+ },
156
+ "text": {
157
+ "type": "string",
158
+ "pattern": "^#[0-9A-Fa-f]{6}$"
159
+ },
160
+ "textMuted": {
161
+ "type": "string",
162
+ "pattern": "^#[0-9A-Fa-f]{6}$"
163
+ },
164
+ "primary": {
165
+ "type": "string",
166
+ "pattern": "^#[0-9A-Fa-f]{6}$"
167
+ },
168
+ "primaryStrong": {
169
+ "type": "string",
170
+ "pattern": "^#[0-9A-Fa-f]{6}$"
171
+ },
172
+ "onPrimary": {
173
+ "type": "string",
174
+ "pattern": "^#[0-9A-Fa-f]{6}$"
175
+ },
176
+ "warning": {
177
+ "type": "string",
178
+ "pattern": "^#[0-9A-Fa-f]{6}$"
179
+ },
180
+ "danger": {
181
+ "type": "string",
182
+ "pattern": "^#[0-9A-Fa-f]{6}$"
183
+ },
184
+ "onDanger": {
185
+ "type": "string",
186
+ "pattern": "^#[0-9A-Fa-f]{6}$"
187
+ },
188
+ "question": {
189
+ "type": "string",
190
+ "pattern": "^#[0-9A-Fa-f]{6}$"
191
+ },
192
+ "onQuestion": {
193
+ "type": "string",
194
+ "pattern": "^#[0-9A-Fa-f]{6}$"
195
+ },
196
+ "resolved": {
197
+ "type": "string",
198
+ "pattern": "^#[0-9A-Fa-f]{6}$"
199
+ },
200
+ "onResolved": {
201
+ "type": "string",
202
+ "pattern": "^#[0-9A-Fa-f]{6}$"
203
+ },
204
+ "onImprove": {
205
+ "type": "string",
206
+ "pattern": "^#[0-9A-Fa-f]{6}$"
207
+ }
208
+ }
209
+ },
210
+ "light": {
211
+ "type": "object",
212
+ "additionalProperties": false,
213
+ "required": [
214
+ "background",
215
+ "chrome",
216
+ "panel",
217
+ "raised",
218
+ "stage",
219
+ "rule",
220
+ "text",
221
+ "textMuted",
222
+ "primary",
223
+ "primaryStrong",
224
+ "onPrimary",
225
+ "warning",
226
+ "danger",
227
+ "onDanger",
228
+ "question",
229
+ "onQuestion",
230
+ "resolved",
231
+ "onResolved",
232
+ "onImprove"
233
+ ],
234
+ "properties": {
235
+ "background": {
236
+ "type": "string",
237
+ "pattern": "^#[0-9A-Fa-f]{6}$"
238
+ },
239
+ "chrome": {
240
+ "type": "string",
241
+ "pattern": "^#[0-9A-Fa-f]{6}$"
242
+ },
243
+ "panel": {
244
+ "type": "string",
245
+ "pattern": "^#[0-9A-Fa-f]{6}$"
246
+ },
247
+ "raised": {
248
+ "type": "string",
249
+ "pattern": "^#[0-9A-Fa-f]{6}$"
250
+ },
251
+ "stage": {
252
+ "type": "string",
253
+ "pattern": "^#[0-9A-Fa-f]{6}$"
254
+ },
255
+ "rule": {
256
+ "type": "string",
257
+ "pattern": "^#[0-9A-Fa-f]{6}$"
258
+ },
259
+ "text": {
260
+ "type": "string",
261
+ "pattern": "^#[0-9A-Fa-f]{6}$"
262
+ },
263
+ "textMuted": {
264
+ "type": "string",
265
+ "pattern": "^#[0-9A-Fa-f]{6}$"
266
+ },
267
+ "primary": {
268
+ "type": "string",
269
+ "pattern": "^#[0-9A-Fa-f]{6}$"
270
+ },
271
+ "primaryStrong": {
272
+ "type": "string",
273
+ "pattern": "^#[0-9A-Fa-f]{6}$"
274
+ },
275
+ "onPrimary": {
276
+ "type": "string",
277
+ "pattern": "^#[0-9A-Fa-f]{6}$"
278
+ },
279
+ "warning": {
280
+ "type": "string",
281
+ "pattern": "^#[0-9A-Fa-f]{6}$"
282
+ },
283
+ "danger": {
284
+ "type": "string",
285
+ "pattern": "^#[0-9A-Fa-f]{6}$"
286
+ },
287
+ "onDanger": {
288
+ "type": "string",
289
+ "pattern": "^#[0-9A-Fa-f]{6}$"
290
+ },
291
+ "question": {
292
+ "type": "string",
293
+ "pattern": "^#[0-9A-Fa-f]{6}$"
294
+ },
295
+ "onQuestion": {
296
+ "type": "string",
297
+ "pattern": "^#[0-9A-Fa-f]{6}$"
298
+ },
299
+ "resolved": {
300
+ "type": "string",
301
+ "pattern": "^#[0-9A-Fa-f]{6}$"
302
+ },
303
+ "onResolved": {
304
+ "type": "string",
305
+ "pattern": "^#[0-9A-Fa-f]{6}$"
306
+ },
307
+ "onImprove": {
308
+ "type": "string",
309
+ "pattern": "^#[0-9A-Fa-f]{6}$"
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
@@ -3,5 +3,8 @@ export declare const PROTOCOL_V16_CONTRACTS: Readonly<Record<string, string>>;
3
3
  export declare const PROTOCOL_V17_CONTRACTS: Readonly<Record<string, string>>;
4
4
  export declare const PROTOCOL_V18_CONTRACTS: Readonly<Record<string, string>>;
5
5
  export declare const PROTOCOL_V111_CONTRACTS: Readonly<Record<string, string>>;
6
- export declare function protocolAssetUrl(kind: string, options?: { protocolVersion?: '1.5.0' | '1.6.0' | '1.7.0' | '1.8.0' | '1.11.0' | '1.13.0' }): URL;
6
+ export declare function protocolAssetUrl(
7
+ kind: string,
8
+ options?: { protocolVersion?: '1.5.0' | '1.6.0' | '1.7.0' | '1.8.0' | '1.11.0' | '1.13.0' },
9
+ ): URL;
7
10
  export declare const PROTOCOL_V113_CONTRACTS: Readonly<Record<string, string>>;
@@ -1,11 +1,13 @@
1
+ // @ts-check
2
+ import { DESIGN_HANDOFF_CONTRACT_FILES } from './design-handoff-contracts.mjs';
3
+ import { DIAGRAM_AUTHORING_CONTRACT_FILES } from './diagram-authoring-contracts.mjs';
1
4
  import {
2
5
  PROTOCOL_V16_CONTRACT_FILES,
3
6
  PROTOCOL_V17_CONTRACT_FILES,
4
7
  PROTOCOL_V18_CONTRACT_FILES,
5
8
  } from './skill-source-contracts.mjs';
6
- import { DESIGN_HANDOFF_CONTRACT_FILES } from './design-handoff-contracts.mjs';
7
- import { DIAGRAM_AUTHORING_CONTRACT_FILES } from './diagram-authoring-contracts.mjs';
8
9
 
10
+ /** @type {typeof import('./browser-contracts.d.mts').PROTOCOL_V15_CONTRACTS} */
9
11
  export const PROTOCOL_V15_CONTRACTS = Object.freeze({
10
12
  'command-catalog': 'command-catalog.schema.json',
11
13
  'generated-asset-manifest': 'generated-asset-manifest.schema.json',
@@ -18,17 +20,22 @@ export const PROTOCOL_V15_CONTRACTS = Object.freeze({
18
20
  'skill-catalog': 'skill-catalog.schema.json',
19
21
  'task-kind-registry': 'task-kind-registry.schema.json',
20
22
  'task-manifest': 'task-manifest.schema.json',
21
- 'task-output-manifest': 'task-output-manifest.schema.json'
23
+ 'task-output-manifest': 'task-output-manifest.schema.json',
22
24
  });
23
25
 
26
+ /** @type {typeof import('./browser-contracts.d.mts').PROTOCOL_V16_CONTRACTS} */
24
27
  export const PROTOCOL_V16_CONTRACTS = PROTOCOL_V16_CONTRACT_FILES;
28
+ /** @type {typeof import('./browser-contracts.d.mts').PROTOCOL_V17_CONTRACTS} */
25
29
  export const PROTOCOL_V17_CONTRACTS = PROTOCOL_V17_CONTRACT_FILES;
30
+ /** @type {typeof import('./browser-contracts.d.mts').PROTOCOL_V18_CONTRACTS} */
26
31
  export const PROTOCOL_V18_CONTRACTS = PROTOCOL_V18_CONTRACT_FILES;
32
+ /** @type {typeof import('./browser-contracts.d.mts').PROTOCOL_V111_CONTRACTS} */
27
33
  export const PROTOCOL_V111_CONTRACTS = Object.freeze({
28
34
  'design-review-metadata-payload': 'design-review-metadata-payload.schema.json',
29
35
  ...DESIGN_HANDOFF_CONTRACT_FILES,
30
36
  });
31
37
 
38
+ /** @type {typeof import('./browser-contracts.d.mts').PROTOCOL_V113_CONTRACTS} */
32
39
  export const PROTOCOL_V113_CONTRACTS = DIAGRAM_AUTHORING_CONTRACT_FILES;
33
40
 
34
41
  const PROTOCOL_CONTRACTS_BY_VERSION = Object.freeze({
@@ -40,10 +47,14 @@ const PROTOCOL_CONTRACTS_BY_VERSION = Object.freeze({
40
47
  '1.13.0': PROTOCOL_V113_CONTRACTS,
41
48
  });
42
49
 
43
- /** Resolve a packaged schema asset without a source checkout or Node-only API. */
50
+ /**
51
+ * Resolve a packaged schema asset without a source checkout or Node-only API.
52
+ * @type {typeof import('./browser-contracts.d.mts').protocolAssetUrl}
53
+ */
44
54
  export function protocolAssetUrl(kind, { protocolVersion = '1.5.0' } = {}) {
45
55
  const contracts = Object.hasOwn(PROTOCOL_CONTRACTS_BY_VERSION, protocolVersion)
46
- ? PROTOCOL_CONTRACTS_BY_VERSION[protocolVersion] : null;
56
+ ? PROTOCOL_CONTRACTS_BY_VERSION[protocolVersion]
57
+ : null;
47
58
  const filename = contracts && Object.hasOwn(contracts, kind) ? contracts[kind] : null;
48
59
  if (!filename) {
49
60
  throw new RangeError(`Unknown browser-safe Protocol contract: ${kind}@${protocolVersion}`);
@@ -1,5 +1,10 @@
1
1
  export declare function canonicalizeJson(value: unknown): string;
2
2
  export declare function sha256Hex(value: string | Uint8Array): string;
3
3
  export declare function sha256Jcs(value: unknown): `sha256:${string}`;
4
- export declare function withDocumentDigest<T extends Record<string, unknown>>(value: T): T & { documentDigest: `sha256:${string}` };
4
+ export declare function withDocumentDigest<T extends Record<string, unknown>>(
5
+ value: T,
6
+ ): T & { documentDigest: `sha256:${string}` };
5
7
  export declare function verifyDocumentDigest(value: unknown): boolean;
8
+ /** Already-frozen objects are not descended into, and a cyclic value overflows the stack. */
9
+ export declare function deepFreeze<T>(value: T): T;
10
+ export declare function assertPlainData(value: unknown, label: string): void;
@@ -1,4 +1,5 @@
1
- const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
1
+ // @ts-check
2
+ const hasOwn = (value, key) => Object.hasOwn(value, key);
2
3
 
3
4
  function assertUnicodeScalarString(value, path) {
4
5
  for (let index = 0; index < value.length; index += 1) {
@@ -26,14 +27,16 @@ function serialize(value, path, seen) {
26
27
  if (!Number.isFinite(value)) throw new TypeError(`JCS requires a finite number at ${path}.`);
27
28
  return JSON.stringify(value);
28
29
  }
29
- if (typeof value !== 'object') throw new TypeError(`JCS cannot canonicalize ${typeof value} at ${path}.`);
30
+ if (typeof value !== 'object')
31
+ throw new TypeError(`JCS cannot canonicalize ${typeof value} at ${path}.`);
30
32
  if (seen.has(value)) throw new TypeError(`JCS cannot canonicalize a cycle at ${path}.`);
31
33
  seen.add(value);
32
34
  try {
33
35
  if (Array.isArray(value)) {
34
36
  const entries = [];
35
37
  for (let index = 0; index < value.length; index += 1) {
36
- if (!hasOwn(value, index)) throw new TypeError(`JCS cannot canonicalize a sparse array at ${path}[${index}].`);
38
+ if (!hasOwn(value, index))
39
+ throw new TypeError(`JCS cannot canonicalize a sparse array at ${path}[${index}].`);
37
40
  entries.push(serialize(value[index], `${path}[${index}]`, seen));
38
41
  }
39
42
  return `[${entries.join(',')}]`;
@@ -42,22 +45,27 @@ function serialize(value, path, seen) {
42
45
  if (prototype !== Object.prototype && prototype !== null) {
43
46
  throw new TypeError(`JCS requires a plain JSON object at ${path}.`);
44
47
  }
45
- const entries = Object.keys(value).sort().map((key) => {
46
- assertUnicodeScalarString(key, `${path} key`);
47
- return `${JSON.stringify(key)}:${serialize(value[key], `${path}.${key}`, seen)}`;
48
- });
48
+ const entries = Object.keys(value)
49
+ .sort()
50
+ .map((key) => {
51
+ assertUnicodeScalarString(key, `${path} key`);
52
+ return `${JSON.stringify(key)}:${serialize(value[key], `${path}.${key}`, seen)}`;
53
+ });
49
54
  return `{${entries.join(',')}}`;
50
55
  } finally {
51
56
  seen.delete(value);
52
57
  }
53
58
  }
54
59
 
55
- /** RFC 8785 JSON canonicalization for already parsed JSON values. */
60
+ /**
61
+ * RFC 8785 JSON canonicalization for already parsed JSON values.
62
+ * @type {typeof import('./canonical-json.d.mts').canonicalizeJson}
63
+ */
56
64
  export function canonicalizeJson(value) {
57
65
  return serialize(value, '$', new Set());
58
66
  }
59
67
 
60
- const SHA256_K = new Uint32Array([
68
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
61
69
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
62
70
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
63
71
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -70,10 +78,16 @@ const SHA256_K = new Uint32Array([
70
78
 
71
79
  const rotr = (value, bits) => (value >>> bits) | (value << (32 - bits));
72
80
 
73
- /** Dependency-free synchronous SHA-256 for browser and Node runtimes. */
81
+ /**
82
+ * Dependency-free synchronous SHA-256 for browser and Node runtimes.
83
+ * @type {typeof import('./canonical-json.d.mts').sha256Hex}
84
+ */
74
85
  export function sha256Hex(value) {
75
86
  const candidate = typeof value === 'string' ? new TextEncoder().encode(value) : value;
76
- if (!ArrayBuffer.isView(candidate) || Object.prototype.toString.call(candidate) !== '[object Uint8Array]') {
87
+ if (
88
+ !ArrayBuffer.isView(candidate) ||
89
+ Object.prototype.toString.call(candidate) !== '[object Uint8Array]'
90
+ ) {
77
91
  throw new TypeError('sha256Hex expects a string or Uint8Array.');
78
92
  }
79
93
  const input = new Uint8Array(candidate.buffer, candidate.byteOffset, candidate.byteLength);
@@ -99,12 +113,20 @@ export function sha256Hex(value) {
99
113
  for (let offset = 0; offset < bytes.length; offset += 64) {
100
114
  for (let index = 0; index < 16; index += 1) words[index] = view.getUint32(offset + index * 4);
101
115
  for (let index = 16; index < 64; index += 1) {
102
- const s0 = rotr(words[index - 15], 7) ^ rotr(words[index - 15], 18) ^ (words[index - 15] >>> 3);
103
- const s1 = rotr(words[index - 2], 17) ^ rotr(words[index - 2], 19) ^ (words[index - 2] >>> 10);
116
+ const s0 =
117
+ rotr(words[index - 15], 7) ^ rotr(words[index - 15], 18) ^ (words[index - 15] >>> 3);
118
+ const s1 =
119
+ rotr(words[index - 2], 17) ^ rotr(words[index - 2], 19) ^ (words[index - 2] >>> 10);
104
120
  words[index] = (words[index - 16] + s0 + words[index - 7] + s1) >>> 0;
105
121
  }
106
- let a = h0; let b = h1; let c = h2; let d = h3;
107
- let e = h4; let f = h5; let g = h6; let h = h7;
122
+ let a = h0;
123
+ let b = h1;
124
+ let c = h2;
125
+ let d = h3;
126
+ let e = h4;
127
+ let f = h5;
128
+ let g = h6;
129
+ let h = h7;
108
130
  for (let index = 0; index < 64; index += 1) {
109
131
  const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
110
132
  const choice = (e & f) ^ (~e & g);
@@ -112,27 +134,42 @@ export function sha256Hex(value) {
112
134
  const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
113
135
  const majority = (a & b) ^ (a & c) ^ (b & c);
114
136
  const temp2 = (s0 + majority) >>> 0;
115
- h = g; g = f; f = e; e = (d + temp1) >>> 0;
116
- d = c; c = b; b = a; a = (temp1 + temp2) >>> 0;
137
+ h = g;
138
+ g = f;
139
+ f = e;
140
+ e = (d + temp1) >>> 0;
141
+ d = c;
142
+ c = b;
143
+ b = a;
144
+ a = (temp1 + temp2) >>> 0;
117
145
  }
118
- h0 = (h0 + a) >>> 0; h1 = (h1 + b) >>> 0;
119
- h2 = (h2 + c) >>> 0; h3 = (h3 + d) >>> 0;
120
- h4 = (h4 + e) >>> 0; h5 = (h5 + f) >>> 0;
121
- h6 = (h6 + g) >>> 0; h7 = (h7 + h) >>> 0;
146
+ h0 = (h0 + a) >>> 0;
147
+ h1 = (h1 + b) >>> 0;
148
+ h2 = (h2 + c) >>> 0;
149
+ h3 = (h3 + d) >>> 0;
150
+ h4 = (h4 + e) >>> 0;
151
+ h5 = (h5 + f) >>> 0;
152
+ h6 = (h6 + g) >>> 0;
153
+ h7 = (h7 + h) >>> 0;
122
154
  }
123
- return [h0, h1, h2, h3, h4, h5, h6, h7].map((part) => part.toString(16).padStart(8, '0')).join('');
155
+ return [h0, h1, h2, h3, h4, h5, h6, h7]
156
+ .map((part) => part.toString(16).padStart(8, '0'))
157
+ .join('');
124
158
  }
125
159
 
160
+ /** @type {typeof import('./canonical-json.d.mts').sha256Jcs} */
126
161
  export function sha256Jcs(value) {
127
162
  return `sha256:${sha256Hex(canonicalizeJson(value))}`;
128
163
  }
129
164
 
165
+ /** @type {typeof import('./canonical-json.d.mts').withDocumentDigest} */
130
166
  export function withDocumentDigest(value) {
131
167
  const copy = { ...value };
132
168
  delete copy.documentDigest;
133
169
  return { ...copy, documentDigest: sha256Jcs(copy) };
134
170
  }
135
171
 
172
+ /** @type {typeof import('./canonical-json.d.mts').verifyDocumentDigest} */
136
173
  export function verifyDocumentDigest(value) {
137
174
  if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
138
175
  const copy = { ...value };
@@ -140,3 +177,44 @@ export function verifyDocumentDigest(value) {
140
177
  delete copy.documentDigest;
141
178
  return actual === sha256Jcs(copy);
142
179
  }
180
+
181
+ /**
182
+ * Freeze a value and every nested object reached through an unfrozen parent.
183
+ * @type {typeof import('./canonical-json.d.mts').deepFreeze}
184
+ */
185
+ export function deepFreeze(value) {
186
+ if (value && typeof value === 'object' && !Object.isFrozen(value)) {
187
+ for (const nested of Object.values(value)) deepFreeze(nested);
188
+ Object.freeze(value);
189
+ }
190
+ return value;
191
+ }
192
+
193
+ function assertPlainDataAt(value, label, depth, seen) {
194
+ if (depth > 64) throw new TypeError(`${label} exceeds the maximum nesting depth.`);
195
+ if (value === null || ['string', 'boolean'].includes(typeof value)) return;
196
+ if (typeof value === 'number' && Number.isFinite(value)) return;
197
+ if (typeof value !== 'object' || seen.has(value))
198
+ throw new TypeError(`${label} must be finite, acyclic JSON.`);
199
+ if (!Array.isArray(value) && ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
200
+ throw new TypeError(`${label} must contain only plain JSON objects.`);
201
+ seen.add(value);
202
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
203
+ if (
204
+ ['__proto__', 'prototype', 'constructor'].includes(key) ||
205
+ !Object.hasOwn(descriptor, 'value')
206
+ )
207
+ throw new TypeError(`${label} contains a forbidden property.`);
208
+ assertPlainDataAt(descriptor.value, label, depth + 1, seen);
209
+ }
210
+ seen.delete(value);
211
+ }
212
+
213
+ /**
214
+ * Throw a TypeError whose message starts with `label` unless the value is finite, acyclic,
215
+ * plain JSON data made of data properties and nested at most 64 levels deep.
216
+ * @type {typeof import('./canonical-json.d.mts').assertPlainData}
217
+ */
218
+ export function assertPlainData(value, label) {
219
+ assertPlainDataAt(value, label, 0, new Set());
220
+ }