@runeditrun/rer 0.2.80 → 0.2.82

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 (99) hide show
  1. package/README.md +12 -0
  2. package/cli/deploy-needs.mjs +4 -2
  3. package/cli/export.mjs +1 -1
  4. package/cli/ledger-refusal.mjs +18 -0
  5. package/cli/portability-migrations.mjs +30 -11
  6. package/cli/portability-worker.mjs +3 -1
  7. package/cli/portability.mjs +2 -0
  8. package/cli/release.mjs +4 -4
  9. package/cli/site-hosting.mjs +90 -0
  10. package/cli/site-render.mjs +3 -2
  11. package/cli/site.mjs +5 -2
  12. package/edition-authoring/base-copies.mjs +12 -1
  13. package/edition-authoring/copy-checkout.mjs +152 -1
  14. package/edition-authoring/files.mjs +1 -1
  15. package/edition-authoring/runtime-dependencies.mjs +108 -0
  16. package/global/CHANGELOG.md +25 -0
  17. package/global/README.md +12 -0
  18. package/modules/demo/README.md +8 -0
  19. package/modules/demo/navigation.mjs +131 -15
  20. package/modules/dependencies/auth.mjs +2 -2
  21. package/modules/deploy-kit/owner.mjs +8 -1
  22. package/modules/import-kit/src/d1/apply-effects.ts +33 -0
  23. package/modules/import-kit/src/d1/apply.ts +38 -10
  24. package/modules/import-kit/src/door/ADOPTING.md +452 -0
  25. package/modules/import-kit/src/door/README.md +553 -0
  26. package/modules/import-kit/src/door/admission.ts +45 -0
  27. package/modules/import-kit/src/door/archive.ts +129 -0
  28. package/modules/import-kit/src/door/authority.ts +107 -0
  29. package/modules/import-kit/src/door/failures.ts +70 -0
  30. package/modules/import-kit/src/door/grants.ts +162 -0
  31. package/modules/import-kit/src/door/handler.ts +90 -0
  32. package/modules/import-kit/src/door/index.ts +20 -0
  33. package/modules/import-kit/src/door/intake/csv.ts +74 -0
  34. package/modules/import-kit/src/door/intake/json.ts +182 -0
  35. package/modules/import-kit/src/door/intake/projection.ts +61 -0
  36. package/modules/import-kit/src/door/intake/types.ts +28 -0
  37. package/modules/import-kit/src/door/intake-policy.ts +38 -0
  38. package/modules/import-kit/src/door/intake-upload.ts +91 -0
  39. package/modules/import-kit/src/door/inventory.ts +68 -0
  40. package/modules/import-kit/src/door/jobs.ts +134 -0
  41. package/modules/import-kit/src/door/limits.ts +16 -0
  42. package/modules/import-kit/src/door/operator.ts +41 -0
  43. package/modules/import-kit/src/door/planning.ts +227 -0
  44. package/modules/import-kit/src/door/protocol.ts +38 -0
  45. package/modules/import-kit/src/door/refusals.ts +51 -0
  46. package/modules/import-kit/src/door/schema.ts +101 -0
  47. package/modules/import-kit/src/door/store.ts +152 -0
  48. package/modules/import-kit/src/door/types.ts +100 -0
  49. package/modules/import-kit/src/door/uploads.ts +98 -0
  50. package/modules/import-kit/src/provenance/numeric-credentials.ts +40 -0
  51. package/modules/import-kit/src/readers/README.md +139 -0
  52. package/modules/import-kit/src/readers/api-policy.ts +67 -0
  53. package/modules/import-kit/src/readers/api.ts +86 -0
  54. package/modules/import-kit/src/readers/bytes.ts +73 -0
  55. package/modules/import-kit/src/readers/errors.ts +33 -0
  56. package/modules/import-kit/src/readers/file.ts +74 -0
  57. package/modules/import-kit/src/readers/index.ts +3 -0
  58. package/modules/import-kit/src/readers/json.ts +29 -0
  59. package/modules/import-kit/src/readers/numeric-lexemes.ts +104 -0
  60. package/modules/import-kit/src/readers/original.ts +31 -0
  61. package/modules/import-kit/src/readers/records.ts +105 -0
  62. package/modules/import-kit/src/types.ts +3 -1
  63. package/modules/operator-auth/README.md +92 -3
  64. package/modules/operator-auth/accounts/admin.mjs +52 -20
  65. package/modules/operator-auth/accounts/audit.mjs +24 -0
  66. package/modules/operator-auth/accounts/business-team.mjs +91 -0
  67. package/modules/operator-auth/accounts/domain-audit.mjs +24 -0
  68. package/modules/operator-auth/accounts/native.mjs +3 -1
  69. package/modules/operator-auth/accounts/settings-page.mjs +15 -2
  70. package/modules/operator-auth/accounts/status.mjs +7 -2
  71. package/modules/operator-auth/accounts/store.mjs +32 -6
  72. package/modules/operator-auth/business-settings.mjs +40 -0
  73. package/modules/operator-auth/identity/email-link/index.mjs +1 -1
  74. package/modules/operator-auth/identity/oidc/admin-audit.mjs +31 -0
  75. package/modules/operator-auth/identity/oidc/index.mjs +12 -5
  76. package/modules/operator-auth/identity/oidc/store.mjs +2 -0
  77. package/modules/operator-auth/index.d.mts +40 -1
  78. package/modules/operator-auth/routes.mjs +11 -6
  79. package/modules/operator-auth/service.mjs +8 -3
  80. package/modules/operator-auth/signin/index.mjs +1 -1
  81. package/modules/portability/README.md +82 -1
  82. package/modules/portability/export.mjs +6 -4
  83. package/modules/portability/format.mjs +5 -0
  84. package/modules/portability/index.d.mts +10 -2
  85. package/modules/portability/index.mjs +3 -2
  86. package/modules/portability/ledgers.mjs +27 -4
  87. package/modules/release/README.md +74 -2
  88. package/modules/release/sign.mjs +4 -2
  89. package/modules/release/signature.mjs +14 -7
  90. package/modules/release/signing-cli.mjs +2 -1
  91. package/modules/release/statement.mjs +2 -2
  92. package/modules/release/vectors/generate.mjs +1 -0
  93. package/modules/release/vectors/publisher-projects.mjs +133 -0
  94. package/modules/release/vectors/release-signature-vectors.json +5195 -0
  95. package/modules/release/verify.mjs +5 -1
  96. package/onboarding/schema/SETUP.schema.json +43 -1
  97. package/onboarding/schema/business-field-inputs.mjs +0 -1
  98. package/onboarding/schema/setup-validation.mjs +3 -0
  99. package/package.json +3 -2
@@ -497,7 +497,10 @@ not a complete anchor set. On success the PKCS#8 private key goes to stdout
497
497
  only when stdout is not a terminal. Pipe it directly to the owner's vault;
498
498
  never send private key bytes to a terminal, repository, log or evidence. The
499
499
  signer accepts `--artifact DIR` and exactly one of `--key-file FILE` or
500
- `--key-stdin`, with `--scope test|rer` (default `rer`). Read production
500
+ `--key-stdin`, with `--scope test|rer` (default `rer`) and optional
501
+ `--publisher NAMESPACE`. Without `--publisher`, the signing publisher remains
502
+ the project ID prefix before `/`. Supply the flag when the authenticating
503
+ publisher differs from that prefix. Read production
501
504
  signing material from the vault through `--key-stdin`; `sign` never echoes it.
502
505
  `--key-stdin` refuses terminal input; pipe the key from a vault or file instead.
503
506
 
@@ -533,6 +536,69 @@ Base receipt check always requires a signature and refuses a missing envelope
533
536
  with `SIGNATURE_MISSING`, even where site or service consumers accept a legacy
534
537
  unsigned listing.
535
538
 
539
+ ### Anchor manifest versions and project authorization
540
+
541
+ An anchor manifest has exactly the top-level fields `schemaVersion`,
542
+ `environment`, `serial`, `legacyUnsigned` and `keys`. Schema version 2 requires
543
+ `schemaVersion: 2` and a `projects` array on **every** entry in `keys`. Each array
544
+ must contain 1–1024 unique, well-formed project IDs. There is no top-level
545
+ `projects` field. All other anchor fields retain their existing meanings:
546
+
547
+ - Each key requires `keyId`, `publicKey`, `publisher`, `githubOwner`, `notBefore`,
548
+ `notAfter`, `status`, `enrolment` and `review`, plus `projects` in version 2.
549
+ The existing optional fields are `retiredAt`, `compromisedAt` and
550
+ `keepStatements`, subject to the existing key-status rules.
551
+ - `githubOwner` contains exactly `login` and `id`. The enrolment envelope retains
552
+ exactly `payloadType`, `payload` and `signatures`, with exactly `keyid` and
553
+ `sig` on its single signature. Its signed claim retains exactly
554
+ `schemaVersion`, `keyId`, `publicKey`, `publisher`, `githubOwner`, `notBefore`,
555
+ `notAfter`, `issuedAt` and `unsignedThrough`.
556
+ - Unknown fields are refused at every level. Malformed manifests, including a
557
+ version 2 key without `projects`, are refused with `ANCHORS_INVALID`.
558
+
559
+ Project IDs use the verifier's existing `validProject` grammar: exactly
560
+ `OWNER`, a slash, and `NAME`, where `OWNER` matches `[a-z0-9][a-z0-9-]{0,38}` and `NAME` is a
561
+ nonempty printable ASCII component (U+0020–U+007E), excluding `/`, `\` and the
562
+ whole components `.` and `..`. Names remain literal and case-sensitive; this
563
+ change introduces no name-length limit. Arrays containing duplicates or invalid
564
+ IDs are invalid manifests.
565
+
566
+ For version 2, only the signing key's own `projects` array authorizes the
567
+ statement's project. Membership is exact and case-sensitive, with no prefix,
568
+ namespace, repository-name or other-key inference. A well-formed project absent
569
+ from that array is refused with `PUBLISHER_MISMATCH`; a statement with malformed
570
+ project grammar is refused with `STATEMENT_INVALID`. The statement's publisher
571
+ must still match the signing key's authenticated publisher.
572
+
573
+ Version 1 requires the explicit numeric `schemaVersion: 1` and preserves the
574
+ existing namespace checks and refusal behavior: the statement's project must
575
+ start with its publisher followed by `/`, and that publisher must match the
576
+ signing key. `projects` is invalid both at the top level and on a key in a
577
+ version 1 manifest. Omitting a version or adding `projects` never opts a version
578
+ 1 manifest into version 2.
579
+
580
+ This version change applies only to the anchor manifest. Release statements and
581
+ key-enrolment claims remain at `schemaVersion: 1`, with the same DSSE payload
582
+ types. Revocation and compromise handling, retirement, expiry and validity,
583
+ serial freshness, unsigned-version floors and environment/scope checks remain
584
+ unchanged. In particular, `projects` does not change the enrolment's
585
+ `unsignedThrough` or the manifest's `legacyUnsigned` policy.
586
+
587
+ For example, to sign project `octocat/hello-world` using a key whose publisher is
588
+ `just-every`, use:
589
+
590
+ ```sh
591
+ rer release sign --artifact /path/to/release --key-stdin --publisher just-every
592
+ ```
593
+
594
+ Pipe the signing key from the vault into that command as described above. Its
595
+ version 2 anchor must list `octocat/hello-world` in that key's `projects`. Verify with
596
+ `rer release receipt --artifact /path/to/release --anchors /path/to/anchors-v2.json`.
597
+ The receipt check matches the signed project, repository and files against the
598
+ artifact while authenticating the publisher through the anchor; it does not
599
+ infer the publisher from the project owner component. The signer's temporary self-proof anchor
600
+ manifest uses version 2 and lists exactly the one project being signed.
601
+
536
602
  The dependency-free verifier source is `modules/release/signature.mjs`; it has
537
603
  no `node:` imports and is exported as
538
604
  `@runeditrun/rer/modules/release/signature`. Its default-seed portable copy is
@@ -541,5 +607,11 @@ generated byte-for-byte at
541
607
  test vectors live in `modules/release/vectors/release-signature-vectors.json`
542
608
  and are generated byte-for-byte at
543
609
  `default-seed/scripts/base-cli/modules/release/vectors/release-signature-vectors.json`.
544
- The vectors use the existing public Octocat example repository context with synthetic bundle bytes and throwaway test keys; they do not represent an actual release.
610
+ The vectors use public Octocat and just-every repository contexts with synthetic
611
+ bundle bytes and throwaway test keys; they do not represent actual releases.
612
+ `vectors/publisher-projects.mjs` regenerates only the appended publisher-project
613
+ cases while preserving the historical v1 vector bytes.
545
614
  Consumers vendor and pin the verifier source by Base commit and SHA-256.
615
+ Site and Platform adoption must copy `signature.mjs` and the shared vectors
616
+ byte-for-byte and repin them to the landed Base commit. Migration of their
617
+ anchor manifests to version 2 is separate from that source adoption.
@@ -26,6 +26,7 @@ export async function signArtifact(options) {
26
26
  if (privateKey.asymmetricKeyType !== 'ed25519') throw new Error();
27
27
  } catch { refuse('SIGNATURE_INVALID'); }
28
28
  const artifact = await readArtifact(options.artifact);
29
+ if (options.publisher !== undefined) artifact.subject.publisher = options.publisher;
29
30
  const tag = artifact.receipt.tag;
30
31
  if (artifact.receipt.status !== 'RELEASED' || !(tag?.created === true ||
31
32
  (tag?.adopted === true && tag.object === artifact.subject.tagObject))) refuse('SUBJECT_MISMATCH');
@@ -34,9 +35,10 @@ export async function signArtifact(options) {
34
35
  // consumer still needs a separately reviewed anchor with the real owner ID.
35
36
  const entry = await publicEntry(privateKey, { scope, publisher: artifact.subject.publisher,
36
37
  githubOwner: { login: artifact.subject.repository.split('/')[3], id: 1 }, ...validity(new Date(issuedAt)), issuedAt });
37
- const anchors = anchorSet(entry, scope);
38
+ const anchors = { ...anchorSet(entry, scope), schemaVersion: 2,
39
+ keys: [{ ...entry, projects: [artifact.subject.project] }] };
38
40
  const loaded = await loadAnchors(anchors, anchors.environment);
39
- const statement = statementFor(artifact, entry.keyId, issuedAt);
41
+ const statement = statementFor(artifact, entry.keyId, issuedAt, anchors.schemaVersion);
40
42
  const bytes = Buffer.from(JSON.stringify(envelope(privateKey, entry.keyId, PAYLOAD_TYPE, statement)) + '\n');
41
43
  await verifyArtifact(artifact, loaded, anchors.environment, bytes);
42
44
  const target = resolve(artifact.root, SIGNATURE_FILE);
@@ -1,7 +1,7 @@
1
1
  // Shared release authentication: dependency-free, with one WebCrypto code path.
2
2
  export const PAYLOAD_TYPE = 'application/vnd.runeditrun.release-statement.v1+json';
3
3
  export const ENROLMENT_TYPE = 'application/vnd.runeditrun.key-enrolment.v1+json';
4
- export const LIMITS = Object.freeze({ envelopeBytes: 65536, files: 256, fileBytes: 1073741824 });
4
+ export const LIMITS = Object.freeze({ envelopeBytes: 65536, files: 256, fileBytes: 1073741824, projectsPerKey: 1024 });
5
5
  const encoder = new TextEncoder();
6
6
  const trusted = new WeakMap();
7
7
  const codes = new Set(('SIGNATURE_MISSING INPUT_TOO_LARGE ENVELOPE_INVALID KEY_TEST_REFUSED KEY_UNKNOWN SIGNATURE_INVALID STATEMENT_NOT_CANONICAL STATEMENT_INVALID PUBLISHER_MISMATCH KEY_OUTSIDE_VALIDITY KEY_RETIRED KEY_REVOKED ISSUED_IN_FUTURE SUBJECT_MISMATCH FILE_MISSING FILE_UNDECLARED DIGEST_MISMATCH PATH_UNSAFE VERSION_ROLLBACK VERSION_REUSED ANCHORS_INVALID ANCHORS_STALE').split(' '));
@@ -110,11 +110,13 @@ const filePattern = /^(public-source\.tar|release-receipt\.json|publish-check\.j
110
110
  function safePath(path) {
111
111
  return validRelativePath(path) && matches(path, filePattern);
112
112
  }
113
- export function validateStatement(s) {
113
+ // V1 anchors retain their original namespace/schema refusal. V2 separates
114
+ // project grammar from the signing key's reviewed authority below.
115
+ export function validateStatement(s, anchorsVersion = 1) {
114
116
  try {
115
117
  if (!shape(s, ['schemaVersion', 'publisher', 'project', 'version', 'tag', 'repository', 'publicCommit', 'publicTree', 'tagObject', 'files', 'issuedAt', 'keyId'])
116
118
  || s.schemaVersion !== 1 || !matches(s.publisher, namespace) || !validProject(s.project)
117
- || !s.project.startsWith(s.publisher + '/') || !version(s.version) || s.tag !== 'v' + s.version
119
+ || (anchorsVersion === 1 && !s.project.startsWith(s.publisher + '/')) || !version(s.version) || s.tag !== 'v' + s.version
118
120
  || !matches(s.repository, repositoryPattern) || ['.', '..'].includes(s.repository.split('/')[4])
119
121
  || !matches(s.publicCommit, hex40) || !matches(s.publicTree, hex40) || !matches(s.tagObject, hex40)
120
122
  || !instant(s.issuedAt) || !matches(s.keyId, keyPattern) || !Array.isArray(s.files)) refuse('STATEMENT_INVALID');
@@ -173,17 +175,21 @@ export async function loadAnchors(raw, environment = 'production', options = {})
173
175
  || (Object.hasOwn(options, 'minimumSerial') && (!Number.isSafeInteger(options.minimumSerial) || options.minimumSerial < 0))) refuse('ANCHORS_INVALID');
174
176
  const anchors = raw instanceof Uint8Array ? parseJSON(raw, 'ANCHORS_INVALID')
175
177
  : typeof raw === 'string' ? JSON.parse(raw) : JSON.parse(canonical(raw));
176
- if (!shape(anchors, ['schemaVersion', 'environment', 'serial', 'legacyUnsigned', 'keys']) || anchors.schemaVersion !== 1
178
+ if (!shape(anchors, ['schemaVersion', 'environment', 'serial', 'legacyUnsigned', 'keys']) || ![1, 2].includes(anchors.schemaVersion)
177
179
  || anchors.environment !== environment || !Number.isSafeInteger(anchors.serial) || anchors.serial < 1
178
180
  || !Array.isArray(anchors.keys) || !floors(anchors.legacyUnsigned)) refuse('ANCHORS_INVALID');
179
181
  const lookup = new Map(), owners = new Map();
180
182
  for (const k of anchors.keys) {
181
- if (!shape(k, ['keyId', 'publicKey', 'publisher', 'githubOwner', 'notBefore', 'notAfter', 'status', 'enrolment', 'review'], ['retiredAt', 'compromisedAt', 'keepStatements'])
183
+ const projectFields = anchors.schemaVersion === 2 ? ['projects'] : [];
184
+ if (!shape(k, ['keyId', 'publicKey', 'publisher', 'githubOwner', 'notBefore', 'notAfter', 'status', 'enrolment', 'review', ...projectFields], ['retiredAt', 'compromisedAt', 'keepStatements'])
182
185
  || !matches(k.keyId, keyPattern) || lookup.has(k.keyId) || !matches(k.publisher, namespace)
183
186
  || !shape(k.githubOwner, ['login', 'id']) || !matches(k.githubOwner.login, namespace)
184
187
  || !Number.isSafeInteger(k.githubOwner.id) || k.githubOwner.id <= 0 || !ascii(k.review)
185
188
  || !instant(k.notBefore) || !instant(k.notAfter) || k.notBefore >= k.notAfter
186
189
  || !['active', 'retired', 'compromised'].includes(k.status)) refuse('ANCHORS_INVALID');
190
+ if (anchors.schemaVersion === 2 && (!Array.isArray(k.projects) || k.projects.length < 1
191
+ || k.projects.length > LIMITS.projectsPerKey || !k.projects.every(validProject)
192
+ || new Set(k.projects).size !== k.projects.length)) refuse('ANCHORS_INVALID');
187
193
  const maximum = new Date(k.notBefore); maximum.setUTCFullYear(maximum.getUTCFullYear() + 2);
188
194
  if (Date.parse(k.notAfter) > maximum.getTime()) refuse('ANCHORS_INVALID');
189
195
  if ((k.status === 'retired' && !Object.hasOwn(k, 'retiredAt'))
@@ -315,10 +321,11 @@ export async function verifyRelease(envelopeBytes, loadedAnchors, input = {}) {
315
321
  if (!found) refuse('KEY_UNKNOWN');
316
322
  await checkSignature(found.publicKey, PAYLOAD_TYPE, parts.payload, parts.signature);
317
323
  const statement = canonicalPayload(parts.payload);
318
- validateStatement(statement);
324
+ validateStatement(statement, loadedAnchors.schemaVersion);
319
325
  if (statement.keyId !== parts.keyid) refuse('STATEMENT_INVALID');
320
326
  const anchor = found.anchor;
321
- if (statement.publisher !== anchor.publisher || statement.repository.split('/')[3] !== anchor.githubOwner.login) refuse('PUBLISHER_MISMATCH');
327
+ if (statement.publisher !== anchor.publisher || statement.repository.split('/')[3] !== anchor.githubOwner.login
328
+ || (loadedAnchors.schemaVersion === 2 && !anchor.projects.includes(statement.project))) refuse('PUBLISHER_MISMATCH');
322
329
  const statementSha256 = await sha256(parts.payload);
323
330
  const now = context.now === undefined ? Date.now() : context.now;
324
331
  if (!Number.isSafeInteger(now) || Math.abs(now) > 8640000000000000) refuse('STATEMENT_INVALID');
@@ -4,7 +4,7 @@ const semver = '(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)';
4
4
  const versionOK = value => new RegExp(`^${semver}$`).test(value) && value.split('.').every(part => Number.isSafeInteger(Number(part)));
5
5
  const dateOK = value => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString() === value.replace('Z', '.000Z');
6
6
  function parse(verb, args) {
7
- const fields = { sign: ['artifact', 'key-file', 'scope'], receipt: ['artifact', 'anchors', 'environment', 'after'],
7
+ const fields = { sign: ['artifact', 'key-file', 'scope', 'publisher'], receipt: ['artifact', 'anchors', 'environment', 'after'],
8
8
  keygen: ['scope', 'publisher', 'github-owner', 'github-owner-id', 'anchor-out', 'not-before', 'not-after', 'unsigned-through'] }[verb];
9
9
  const options = { unsignedThrough: {} };
10
10
  const invalid = () => { throw new TypeError('ARGUMENT_INVALID'); };
@@ -23,6 +23,7 @@ function parse(verb, args) {
23
23
  if (options.scope !== undefined && !['test', 'rer'].includes(options.scope)) invalid();
24
24
  if (verb === 'receipt' && (!options.artifact || !options.anchors || (options.environment !== undefined && options.environment !== 'test') || (options.after && (!new RegExp(`^${semver}:[a-f0-9]{64}$`).test(options.after) || !versionOK(options.after.split(':')[0]))))) invalid();
25
25
  if (verb === 'sign' && (!options.artifact || Boolean(options['key-file']) === Boolean(options['key-stdin']))) invalid();
26
+ if (verb === 'sign' && options.publisher !== undefined && !/^[a-z0-9][a-z0-9-]{0,38}$/.test(options.publisher)) invalid();
26
27
  if (verb === 'keygen') {
27
28
  if (!options.scope || !options['anchor-out'] || !/^[a-z0-9][a-z0-9-]{0,38}$/.test(options.publisher ?? '') || !/^[a-z0-9][a-z0-9-]{0,38}$/.test(options['github-owner'] ?? '') || !/^[1-9]\d*$/.test(options['github-owner-id'] ?? '') || !Number.isSafeInteger(Number(options['github-owner-id']))) invalid();
28
29
  for (const name of ['not-before', 'not-after']) if (options[name] !== undefined && !dateOK(options[name])) invalid();
@@ -77,8 +77,8 @@ export async function readArtifact(directory) {
77
77
  return { root, receipt, subject, files, entries };
78
78
  }
79
79
 
80
- export function statementFor(artifact, keyId, issuedAt) {
80
+ export function statementFor(artifact, keyId, issuedAt, anchorsVersion = 1) {
81
81
  const statement = { schemaVersion: 1, ...artifact.subject, files: artifact.entries, issuedAt, keyId };
82
- validateStatement(statement);
82
+ validateStatement(statement, anchorsVersion);
83
83
  return statement;
84
84
  }
@@ -379,3 +379,4 @@ add('unsigned release outside every legacy floor', false, testAnchors,
379
379
  const output = new URL('./release-signature-vectors.json', import.meta.url);
380
380
  writeFileSync(output, JSON.stringify(vectors, null, 2) + '\n');
381
381
  console.log(`Wrote ${vectors.length} public release-signature vectors.`);
382
+ await import('./publisher-projects.mjs');
@@ -0,0 +1,133 @@
1
+ // Regenerate only the appended publisher-project vectors; historical v1 bytes stay intact.
2
+ import { readFileSync, writeFileSync } from 'node:fs';
3
+ import { generateKeyPairSync } from 'node:crypto';
4
+ import { publicEntry, envelope } from '../signing-key.mjs';
5
+ import { b64, canonicalBytes, ENROLMENT_TYPE, PAYLOAD_TYPE, sha256 } from '../signature.mjs';
6
+
7
+ const output = new URL('./release-signature-vectors.json', import.meta.url);
8
+ const original = readFileSync(output, 'utf8');
9
+ const historical = JSON.parse(original).filter(row => !/^(v2 |anchors v1 )/.test(row.name));
10
+ const template = historical[0];
11
+ const baseStatement = JSON.parse(Buffer.from(JSON.parse(Buffer.from(template.envelope, 'base64')).payload, 'base64'));
12
+ const copy = value => structuredClone(value);
13
+ const issuedAt = baseStatement.issuedAt;
14
+ const repository = 'https://github.com/just-every/run-beam';
15
+ const publisher = 'just-every';
16
+ const githubOwner = { login: 'just-every', id: 71005 };
17
+
18
+ async function ephemeralKey() {
19
+ // EPHEMERAL TEST-SCOPE ONLY: private keys stay in memory and are never serialized.
20
+ const { privateKey } = generateKeyPairSync('ed25519');
21
+ const entry = await publicEntry(privateKey, {
22
+ scope: 'test', publisher, githubOwner,
23
+ notBefore: '2026-10-01T00:00:00Z', notAfter: '2028-10-01T00:00:00Z',
24
+ issuedAt: '2026-10-01T00:00:00Z', unsignedThrough: { 'just-every/beam': '1.1.0' },
25
+ });
26
+ return { privateKey, entry: { ...entry, review: 'public synthetic conformance vector', projects: ['learning/beam', 'just-every/beam'] } };
27
+ }
28
+
29
+ const key = await ephemeralKey();
30
+ const otherKey = await ephemeralKey();
31
+ const anchors = {
32
+ schemaVersion: 2, environment: 'test', serial: 1,
33
+ legacyUnsigned: { 'never-enrolled/app': '0.1.0' }, keys: [key.entry],
34
+ };
35
+ function statement(project = 'learning/beam', fields = {}) {
36
+ return { ...copy(baseStatement), publisher, project, repository, keyId: key.entry.keyId, ...fields };
37
+ }
38
+ function signed(project, fields = {}) {
39
+ return b64(Buffer.from(JSON.stringify(envelope(key.privateKey, key.entry.keyId, PAYLOAD_TYPE, statement(project, fields)))));
40
+ }
41
+ function context(project = 'learning/beam') {
42
+ return { ...copy(template.context), expect: { ...template.context.expect, project, repository } };
43
+ }
44
+ function changedAnchor(change) {
45
+ const result = copy(anchors);
46
+ change(result.keys[0], result);
47
+ return result;
48
+ }
49
+ const rows = [];
50
+ function add(name, expected, { project = 'learning/beam', anchorSet = anchors, payload = signed(project), ctx = context(project) } = {}) {
51
+ rows.push({ name, envelope: payload, anchors: copy(anchorSet), context: copy(ctx), expected });
52
+ }
53
+
54
+ add('v2 listed external learning/beam signed by just-every', 'VERIFIED');
55
+ add('v2 listed own namespace', 'VERIFIED', { project: 'just-every/beam' });
56
+ for (const project of ['learning/not-listed', 'just-every/not-listed', 'learning/Beam']) {
57
+ add(`v2 unlisted exact project ${project}`, 'PUBLISHER_MISMATCH', { project });
58
+ }
59
+ add('v2 malformed statement trailing slash', 'STATEMENT_INVALID', { project: 'learning/beam/' });
60
+ add('v2 another key with same publisher and owner cannot widen signing key projects', 'PUBLISHER_MISMATCH', {
61
+ project: 'learning/not-listed',
62
+ anchorSet: { ...copy(anchors), keys: [copy(key.entry), { ...copy(otherKey.entry), projects: ['learning/not-listed'] }] },
63
+ });
64
+ add('v2 one project is sufficient', 'VERIFIED', { anchorSet: changedAnchor(entry => { entry.projects = ['learning/beam']; }) });
65
+ const maximumProjects = ['learning/beam', ...Array.from({ length: 1023 }, (_, i) => `learning/project-${i}`)];
66
+ add('v2 1024 projects allowed', 'VERIFIED', { anchorSet: changedAnchor(entry => { entry.projects = maximumProjects; }) });
67
+ for (const [label, projects] of [
68
+ ['duplicate', ['learning/beam', 'learning/beam']], ['empty list', []], ['empty string', ['']],
69
+ ['malformed project', ['learning/beam/extra']], ['trailing slash', ['learning/beam/']],
70
+ ['number member', [42]], ['null member', [null]], ['object member', [{}]], ['array member', [[]]],
71
+ ['number list', 42], ['null list', null], ['object list', {}], ['string list', 'learning/beam'],
72
+ ['1025 projects', [...maximumProjects, 'learning/overflow']],
73
+ ]) {
74
+ add(`v2 invalid projects ${label}`, 'ANCHORS_INVALID', {
75
+ anchorSet: changedAnchor(entry => { entry.projects = projects; }), payload: null,
76
+ });
77
+ }
78
+ add('v2 missing projects', 'ANCHORS_INVALID', { anchorSet: changedAnchor(entry => { delete entry.projects; }), payload: null });
79
+ add('v2 unknown top projects', 'ANCHORS_INVALID', { anchorSet: { ...copy(anchors), projects: ['learning/beam'] }, payload: null });
80
+ add('v2 unknown key field', 'ANCHORS_INVALID', { anchorSet: changedAnchor(entry => { entry.unreviewed = true; }), payload: null });
81
+ add('v2 unknown githubOwner field', 'ANCHORS_INVALID', { anchorSet: changedAnchor(entry => { entry.githubOwner.unreviewed = true; }), payload: null });
82
+ for (const [label, extra] of [['unknown field', { unreviewed: true }], ['projects field', { projects: ['learning/beam'] }]]) {
83
+ const claim = JSON.parse(Buffer.from(key.entry.enrolment.payload, 'base64'));
84
+ add(`v2 enrolment claim ${label} correctly signed`, 'ANCHORS_INVALID', {
85
+ anchorSet: changedAnchor(entry => { entry.enrolment = envelope(key.privateKey, key.entry.keyId, ENROLMENT_TYPE, { ...claim, ...extra }); }), payload: null,
86
+ });
87
+ }
88
+ add('v2 unknown enrolment envelope field', 'ANCHORS_INVALID', { anchorSet: changedAnchor(entry => { entry.enrolment.unreviewed = true; }), payload: null });
89
+ const extraEnvelope = JSON.parse(Buffer.from(signed(), 'base64'));
90
+ extraEnvelope.unreviewed = true;
91
+ add('v2 unknown release envelope field', 'ENVELOPE_INVALID', { payload: b64(Buffer.from(JSON.stringify(extraEnvelope))) });
92
+
93
+ const v1 = changedAnchor((entry, set) => { delete entry.projects; set.schemaVersion = 1; });
94
+ add('anchors v1 retains external prefix statement refusal', 'STATEMENT_INVALID', { anchorSet: v1 });
95
+ add('anchors v1 retains own namespace authority', 'VERIFIED', { anchorSet: v1, project: 'just-every/not-listed' });
96
+ add('anchors v1 refuses key projects', 'ANCHORS_INVALID', { anchorSet: { ...copy(anchors), schemaVersion: 1 }, payload: null });
97
+ add('anchors v1 refuses top projects', 'ANCHORS_INVALID', { anchorSet: { ...copy(v1), projects: ['learning/beam'] }, payload: null });
98
+
99
+ add('v2 compromised key without reviewed keep digest', 'KEY_REVOKED', { anchorSet: changedAnchor(entry => { Object.assign(entry, { status: 'compromised', compromisedAt: issuedAt, keepStatements: [] }); }) });
100
+ const statementDigest = await sha256(canonicalBytes(statement()));
101
+ add('v2 compromised key with reviewed keep digest', 'VERIFIED', { anchorSet: changedAnchor(entry => { Object.assign(entry, { status: 'compromised', compromisedAt: issuedAt, keepStatements: [statementDigest] }); }) });
102
+ for (const [label, retiredAt, expected] of [
103
+ ['before retirement', '2026-10-13T00:00:01Z', 'VERIFIED'], ['at retirement', issuedAt, 'KEY_RETIRED'],
104
+ ]) {
105
+ add(`v2 retired key ${label}`, expected, { anchorSet: changedAnchor(entry => { Object.assign(entry, { status: 'retired', retiredAt }); }) });
106
+ }
107
+ add('v2 statement before validity', 'KEY_OUTSIDE_VALIDITY', { payload: signed(undefined, { issuedAt: '2026-09-30T23:59:59Z' }) });
108
+ add('v2 statement at expiry', 'KEY_OUTSIDE_VALIDITY', { payload: signed(undefined, { issuedAt: key.entry.notAfter }), ctx: { ...context(), now: Date.parse(key.entry.notAfter) } });
109
+ add('v2 statement in future', 'ISSUED_IN_FUTURE', { payload: signed(undefined, { issuedAt: '2027-10-13T00:00:00Z' }) });
110
+ add('v2 environment mismatch', 'ANCHORS_INVALID', { anchorSet: { ...copy(anchors), environment: 'production' }, payload: null });
111
+ add('v2 production anchors refuse test key', 'ANCHORS_INVALID', { anchorSet: { ...copy(anchors), environment: 'production' }, payload: null, ctx: { environment: 'production' } });
112
+ add('v2 test key refused by production verifier', 'KEY_TEST_REFUSED', { anchorSet: { ...copy(anchors), environment: 'production', keys: [] }, ctx: { environment: 'production', now: template.context.now } });
113
+ add('v2 stale serial equal', 'ANCHORS_STALE', { ctx: { ...context(), minimumSerial: 1 }, payload: null });
114
+ add('v2 stale serial older', 'ANCHORS_STALE', { ctx: { ...context(), minimumSerial: 2 }, payload: null });
115
+ add('v2 legacy floor cannot overlap enrolled publisher', 'ANCHORS_INVALID', { anchorSet: { ...copy(anchors), legacyUnsigned: { 'just-every/beam': '1.1.0' } }, payload: null });
116
+ for (const [label, project, version, expected] of [
117
+ ['enrolled floor', 'just-every/beam', '1.1.0', 'UNSIGNED_LEGACY'],
118
+ ['above enrolled floor', 'just-every/beam', '1.2.0', 'SIGNATURE_MISSING'],
119
+ ['legacy floor', 'never-enrolled/app', '0.1.0', 'UNSIGNED_LEGACY'],
120
+ ['above legacy floor', 'never-enrolled/app', '0.2.0', 'SIGNATURE_MISSING'],
121
+ ['listing creates no unsigned floor', 'learning/beam', '1.1.0', 'SIGNATURE_MISSING'],
122
+ ]) {
123
+ add(`v2 unsigned ${label} unchanged`, expected, { payload: false, ctx: {
124
+ environment: 'test', now: template.context.now, expect: { project, version, tag: `v${version}` }, unsigned: { project, version },
125
+ } });
126
+ }
127
+
128
+ // Keep the historical JSON prefix verbatim, adding only its separating comma.
129
+ const generatedStart = original.search(/\n \{\n "name": "(?:v2 |anchors v1 )/);
130
+ const prefix = generatedStart < 0 ? original.slice(0, original.lastIndexOf('\n]')) : original.slice(0, generatedStart).replace(/,$/, '');
131
+ if (JSON.stringify(JSON.parse(prefix + '\n]')) !== JSON.stringify(historical)) throw new Error('Generated rows must follow all historical vectors.');
132
+ writeFileSync(output, prefix + ',' + JSON.stringify(rows, null, 2).slice(1, -1) + ']\n');
133
+ console.log(`Appended ${rows.length} publisher-project vectors.`);