@runeditrun/rer 0.2.80 → 0.2.81

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 (57) hide show
  1. package/cli/deploy-needs.mjs +4 -2
  2. package/cli/export.mjs +1 -1
  3. package/cli/ledger-refusal.mjs +18 -0
  4. package/cli/portability-migrations.mjs +30 -11
  5. package/cli/portability-worker.mjs +3 -1
  6. package/cli/portability.mjs +2 -0
  7. package/cli/release.mjs +4 -4
  8. package/cli/site-hosting.mjs +90 -0
  9. package/cli/site-render.mjs +3 -2
  10. package/cli/site.mjs +5 -2
  11. package/edition-authoring/base-copies.mjs +9 -0
  12. package/edition-authoring/runtime-dependencies.mjs +108 -0
  13. package/global/CHANGELOG.md +12 -0
  14. package/modules/demo/README.md +8 -0
  15. package/modules/demo/navigation.mjs +131 -15
  16. package/modules/dependencies/auth.mjs +2 -2
  17. package/modules/deploy-kit/owner.mjs +8 -1
  18. package/modules/import-kit/src/d1/apply-effects.ts +33 -0
  19. package/modules/import-kit/src/d1/apply.ts +38 -10
  20. package/modules/import-kit/src/types.ts +3 -1
  21. package/modules/operator-auth/README.md +92 -3
  22. package/modules/operator-auth/accounts/admin.mjs +52 -20
  23. package/modules/operator-auth/accounts/audit.mjs +24 -0
  24. package/modules/operator-auth/accounts/business-team.mjs +91 -0
  25. package/modules/operator-auth/accounts/domain-audit.mjs +24 -0
  26. package/modules/operator-auth/accounts/native.mjs +3 -1
  27. package/modules/operator-auth/accounts/settings-page.mjs +15 -2
  28. package/modules/operator-auth/accounts/status.mjs +7 -2
  29. package/modules/operator-auth/accounts/store.mjs +32 -6
  30. package/modules/operator-auth/business-settings.mjs +40 -0
  31. package/modules/operator-auth/identity/email-link/index.mjs +1 -1
  32. package/modules/operator-auth/identity/oidc/admin-audit.mjs +31 -0
  33. package/modules/operator-auth/identity/oidc/index.mjs +12 -5
  34. package/modules/operator-auth/identity/oidc/store.mjs +2 -0
  35. package/modules/operator-auth/index.d.mts +40 -1
  36. package/modules/operator-auth/routes.mjs +11 -6
  37. package/modules/operator-auth/service.mjs +8 -3
  38. package/modules/operator-auth/signin/index.mjs +1 -1
  39. package/modules/portability/README.md +82 -1
  40. package/modules/portability/export.mjs +6 -4
  41. package/modules/portability/format.mjs +5 -0
  42. package/modules/portability/index.d.mts +10 -2
  43. package/modules/portability/index.mjs +3 -2
  44. package/modules/portability/ledgers.mjs +27 -4
  45. package/modules/release/README.md +74 -2
  46. package/modules/release/sign.mjs +4 -2
  47. package/modules/release/signature.mjs +14 -7
  48. package/modules/release/signing-cli.mjs +2 -1
  49. package/modules/release/statement.mjs +2 -2
  50. package/modules/release/vectors/generate.mjs +1 -0
  51. package/modules/release/vectors/publisher-projects.mjs +133 -0
  52. package/modules/release/vectors/release-signature-vectors.json +5195 -0
  53. package/modules/release/verify.mjs +5 -1
  54. package/onboarding/schema/SETUP.schema.json +43 -1
  55. package/onboarding/schema/business-field-inputs.mjs +0 -1
  56. package/onboarding/schema/setup-validation.mjs +3 -0
  57. package/package.json +1 -1
@@ -10,7 +10,7 @@ export interface AuthPresentation { readonly productName: string; readonly accen
10
10
  export interface LinkPreview { kind: 'magic' | 'invite' | 'step_up' | 'owner'; expiresInMinutes: number }
11
11
  /** A step-up confirmation proves the session's operator again; it issues no new session. */
12
12
  export interface StepUpConfirmed { stepUp: StepUpAction; returnTo: string; cookie?: undefined }
13
- export type StepUpAction = 'providers:unlink' | 'providers:relink' | 'domains:change' | 'owner:transfer' | 'export' | 'delete' | 'credentials:mint' | 'email:change';
13
+ export type StepUpAction = 'providers:unlink' | 'providers:relink' | 'domains:change' | 'owner:transfer' | 'export' | 'delete' | 'credentials:mint' | 'email:change' | 'business:stop';
14
14
  export const STEP_UP_ACTIONS: readonly StepUpAction[];
15
15
  export type ProviderPreset = 'auth' | 'google' | 'microsoft' | 'okta' | 'legacy-rs256';
16
16
  /** One identity provider. Secrets and the private key are server bindings, never source text. */
@@ -84,14 +84,47 @@ export interface VerifiedIdentity extends VerifiedPrincipal { email: string; ema
84
84
  /** Deployment-owned association, never populated from token claims or HTTP input. */
85
85
  export interface IdentityAdmissionConfig { issuer: string; subjectEmails?: Record<string, string> }
86
86
  export type IdentityAdmission<R extends string = Role> = (request: Request, identity: VerifiedPrincipal, input?: { returnTo?: string }) => Promise<CompletedSession<R>>;
87
+ export type AuthAuditAction = 'operators.invite' | 'operators.cancel-invite' | 'operators.deactivate' | 'operators.reactivate' | 'operators.role' | 'sessions.revoke' | 'domains.rule.set' | 'domains.rule.lift' | 'providers.unlink' | 'providers.relink';
88
+ /** OA administrative mutation metadata only; no private identity, record or file data. */
89
+ export interface AuthAuditEvent {
90
+ action: AuthAuditAction;
91
+ /** Opaque oa_operators.id of the authenticated actor. */
92
+ actorId: string;
93
+ /** Target oa_operators.id; null for domain and provider actions. */
94
+ subjectId: string | null;
95
+ /** New role/status, normalized domain, provider id, or null for session revocation. */
96
+ detail: string | null;
97
+ /** Action clock time in milliseconds since the Unix epoch. */
98
+ now: number;
99
+ }
100
+ export type AuthAuditStatement = [sql: string, args: unknown[]];
87
101
  export interface AuthHooks<R extends string = Role> {
88
102
  /** Before an email link is sent to an active operator. Return false to send nothing; the public answer is unchanged. */
89
103
  beforeMagicLink?(input: { request: Request; email: string; operator: Operator<R> }): boolean | void | Promise<boolean | void>;
90
104
  /** After an email-link or provider sign-in completes. Return a returnTo to redirect; throw to refuse (the new session is revoked). */
91
105
  afterConfirm?(input: { request: Request; operator: Operator<R>; session: CompletedSession<R>['session']; method: 'email' | 'oidc'; returnTo: string }): void | { returnTo?: string } | Promise<void | { returnTo?: string }>;
106
+ /** OA administration only: pure SQL generation for the same mutation batch. Failure refuses the action; no external writes. */
107
+ audit?(input: AuthAuditEvent): AuthAuditStatement[] | Promise<AuthAuditStatement[]>;
92
108
  }
93
109
  export type { ScheduledPolicy, ScheduledPolicyDoor, PolicyApproval, PolicyRun } from './scheduled/index.mjs';
110
+ export interface BusinessSettingsIntegration {
111
+ publicBrand(): Promise<{ displayName?: string; logo?: string }>;
112
+ read(): Promise<{ document: { business: string } | null; rev: number; appliedAt: string | null; stopped: boolean }>;
113
+ /** The OA actor fence is supplied for an atomic owner-authority check. */
114
+ stop(actor: string, guard?: { sql: string; args: unknown[] }): Promise<void>;
115
+ }
116
+ export interface BusinessTeamRow { email: string; operatorId: string | null; invite: number; state: 'invited' | 'active' | 'inactive' | 'conflict' }
117
+ export interface BusinessTeamAdapter {
118
+ ownerEmail(): Promise<string | null>;
119
+ prepare(input: {
120
+ members: Array<{ email: string; name: string; role: 'admin' | 'member'; invite: number }>;
121
+ managed: BusinessTeamRow[]; ownerEmail: string; roles: { admin: string; member: string };
122
+ /** Evaluated after the Business revision/nonce CAS in the same D1 batch. */
123
+ guard: { sql: string; args: unknown[] };
124
+ }): Promise<{ statements: Statement[]; rows: BusinessTeamRow[]; afterCommit(): Promise<void> }>;
125
+ }
94
126
  export interface AuthOptions<R extends string = Role> {
127
+ businessSettings?: BusinessSettingsIntegration;
95
128
  /** OA store only: trusted source, re-read at approval/run/action time. */
96
129
  scheduledPolicies?: () => import('./scheduled/index.mjs').ScheduledPolicy[];
97
130
  db: Database; config: AuthConfig; mailSender?: MailSender; clientIp: (request: Request) => string | Promise<string>; rolePolicy?: RolePolicy; clock?: () => number;
@@ -145,6 +178,12 @@ export interface IdentityProviders {
145
178
  }
146
179
  export interface DomainRule { domain: string; providerId: string; createdAt: number }
147
180
  export interface OperatorAuth<R extends string = Role> {
181
+ /** OA accounts only. Signed Business documents must be verified before calling. */
182
+ readonly businessTeam?: BusinessTeamAdapter;
183
+ readonly businessSettings?: BusinessSettingsIntegration;
184
+ publicPresentation?(): Promise<AuthPresentation>;
185
+ businessSettingsInfo?(request: Request): Promise<{ business: string | null; rev: number; appliedAt: string | null; stopped: boolean }>;
186
+ stopBusinessSettings?(request: Request): Promise<{ stopped: true }>;
148
187
  readonly scheduledPolicies?: import('./scheduled/index.mjs').ScheduledPolicyDoor;
149
188
  /** Key-gated local development or an isolated hosted demo; unavailable in production. */
150
189
  readonly oneClick?: {
@@ -67,14 +67,14 @@ export function createAuthHandler(auth) {
67
67
  if (path === '/auth/sessions' && request.method === 'GET') return json(await auth.listSessions(request, readParameters(url.searchParams).operatorId));
68
68
  if (path === '/auth/domain-rules' && request.method === 'GET') return json(await auth.listDomainRules(request));
69
69
  if (path === '/auth/settings/identity' && ['GET', 'HEAD'].includes(request.method)) {
70
- const value = await auth.identitySettings(request);
70
+ const value = { ...await auth.identitySettings(request), ...(auth.businessSettingsInfo ? { business: await auth.businessSettingsInfo(request) } : {}) };
71
71
  return representation(request) === 'html'
72
- ? await identitySettingsPage(value, auth.presentation, { saved: url.searchParams.get('saved') === '1', method: request.method })
72
+ ? await identitySettingsPage(value, auth.publicPresentation ? await auth.publicPresentation() : auth.presentation, { saved: url.searchParams.get('saved') === '1', method: request.method })
73
73
  : request.method === 'HEAD' ? new Response(null, { headers: { ...securityHeaders(), 'content-type': 'application/json' } }) : json(value);
74
74
  }
75
75
  if (path === '/auth/providers' && request.method === 'GET') return json(await auth.listProviders(request));
76
76
  const posts = new Set(['/auth/bootstrap', '/auth/magic-link', '/auth/confirm', '/auth/signout', '/auth/invite', '/auth/invite/cancel', '/auth/review-session',
77
- '/auth/policy/approve', '/auth/policy/revoke', '/auth/operator/status', '/auth/operator/role', '/auth/session/revoke', '/auth/step-up', '/auth/domain-rules', '/auth/providers/unlink', '/auth/providers/relink', '/auth/settings/identity', '/auth/setup-complete', OWNER_SIGNIN_PATH, '/auth/email', '/auth/display-name']);
77
+ '/auth/policy/approve', '/auth/policy/revoke', '/auth/operator/status', '/auth/operator/role', '/auth/session/revoke', '/auth/step-up', '/auth/domain-rules', '/auth/providers/unlink', '/auth/providers/relink', '/auth/settings/identity', '/auth/settings/business', '/auth/setup-complete', OWNER_SIGNIN_PATH, '/auth/email', '/auth/display-name']);
78
78
  if (!posts.has(path)) return json({ error: 'not_found' }, 404);
79
79
  if (request.method !== 'POST') return json({ error: 'method_not_allowed' }, 405);
80
80
  const query = readParameters(url.searchParams);
@@ -91,6 +91,11 @@ export function createAuthHandler(auth) {
91
91
  const value = await auth.setIdentitySettings(request, formPost(request) ? { idpSignIn: input.idpSignIn === 'true' } : input);
92
92
  return formPost(request) ? seeOther('/auth/settings/identity?saved=1') : json(value);
93
93
  }
94
+ case '/auth/settings/business': {
95
+ if (!auth.stopBusinessSettings) return json({ error: 'not_found' }, 404);
96
+ const value = await auth.stopBusinessSettings(request);
97
+ return formPost(request) ? seeOther('/auth/settings/identity') : json(value);
98
+ }
94
99
  case '/auth/setup-complete': return json(await auth.completeLocalSetup(request));
95
100
  case '/auth/bootstrap': { const value = await auth.bootstrap(request, input); return seeOther(value.returnTo, value.cookie); }
96
101
  case '/auth/magic-link': {
@@ -128,11 +133,11 @@ export function createAuthHandler(auth) {
128
133
  case '/auth/providers/relink': return json(await auth.relinkProvider(request, input));
129
134
  }
130
135
  } catch (error) {
131
- if (path === '/auth/settings/identity' && representation(request) === 'html') {
136
+ if (['/auth/settings/identity', '/auth/settings/business'].includes(path) && representation(request) === 'html') {
132
137
  const code = error instanceof AuthError ? error.code : 'auth_unavailable';
133
138
  const status = error instanceof AuthError ? error.status : 503;
134
- if (code === 'provider_unlinked') {
135
- try { return await identitySettingsPage(await auth.identitySettings(request), auth.presentation, { error: code, status, method: request.method }); }
139
+ if (code === 'provider_unlinked' || code === 'step_up_required') {
140
+ try { return await identitySettingsPage({ ...await auth.identitySettings(request), ...(auth.businessSettingsInfo ? { business: await auth.businessSettingsInfo(request) } : {}) }, auth.publicPresentation ? await auth.publicPresentation() : auth.presentation, { error: code, status, method: request.method }); }
136
141
  catch { return settingsRefusalPage(request, auth.presentation, 'auth_unavailable', 503); }
137
142
  }
138
143
  return settingsRefusalPage(request, auth.presentation, code, status);
@@ -1,5 +1,7 @@
1
1
  // Composed identity over Base's OA accounts, or an explicitly paired native
2
2
  // accounts/proof adapter. Native composition never constructs the OA store.
3
+ import { businessSettingsControls } from './business-settings.mjs';
4
+ import { businessTeam } from './accounts/business-team.mjs';
3
5
  import { scheduledPolicies } from './scheduled/index.mjs';
4
6
  import { fencedCredentials } from './accounts/credentials.mjs';
5
7
  import { providerControl } from './accounts/provider-control.mjs';
@@ -29,8 +31,8 @@ export function createOperatorAuth(options) {
29
31
  const { db, config: input, mailSender, clientIp, rolePolicy = defaultRolePolicy, clock = Date.now, hooks = {}, fetch, waitUntil, accounts: nativeAccounts, proofs } = options;
30
32
  const config = configure(input);
31
33
  if (typeof clientIp !== 'function') throw new AuthError('client_ip_required', 503);
32
- if (!hooks || typeof hooks !== 'object' || ['beforeMagicLink', 'afterConfirm'].some(name => hooks[name] !== undefined && typeof hooks[name] !== 'function')) throw new AuthError('invalid_configuration', 503);
33
- if (Object.hasOwn(options, 'accounts') || Object.hasOwn(options, 'proofs')) return createNativeAuth({ db, config, accounts: nativeAccounts, proofs, mailSender, clientIp, clock, hooks, fetch, waitUntil });
34
+ if (!hooks || typeof hooks !== 'object' || ['beforeMagicLink', 'afterConfirm', 'audit'].some(name => hooks[name] !== undefined && typeof hooks[name] !== 'function')) throw new AuthError('invalid_configuration', 503);
35
+ if (Object.hasOwn(options, 'accounts') || Object.hasOwn(options, 'proofs')) return createNativeAuth({ db, config, accounts: nativeAccounts, proofs, mailSender, clientIp, clock, hooks, fetch, waitUntil, businessSettings: options.businessSettings });
34
36
  const store = new AuthStore(db);
35
37
  const sessions = oaSessions({ config, store, clock });
36
38
  const { hash, newSession, completed, authenticate } = sessions;
@@ -73,10 +75,13 @@ export function createOperatorAuth(options) {
73
75
  },
74
76
  } });
75
77
  const { limit, newToken, sendLink, requireFreshProof } = email;
76
- const admin = administration({ config, store, clock, authorize: rolePolicy, authenticate, newToken, sendLink, limit, requireFreshProof, providers });
78
+ const adminContext = { config, store, clock, authorize: rolePolicy, authenticate, newToken, sendLink, limit, requireFreshProof, providers, accounts, audit: hooks.audit };
79
+ const { prepareInvitation: _prepareInvitation, ...admin } = administration(adminContext);
77
80
  const external = legacyAdmission({ admission, config });
78
81
  return Object.freeze({
79
82
  ...admin,
83
+ businessTeam: businessTeam(adminContext),
84
+ ...businessSettingsControls({ businessSettings: options.businessSettings, config, accounts, authenticate, requireFreshProof, store, clock }),
80
85
  ...(options.scheduledPolicies ? { scheduledPolicies: scheduledPolicies({ definitions: options.scheduledPolicies, store, config, clock, authenticate, requireFreshProof, rolePolicy }) } : {}),
81
86
  ...providerControl({ store, accounts, authenticate, config, clock }),
82
87
  ...fencedCredentials({store,authenticate,requireFreshProof,config,clock,hash}),
@@ -48,7 +48,7 @@ export function createSignInHandler(auth, { setup, links, defaultReturnTo = '/ap
48
48
  return async function signIn(request) {
49
49
  const url = new URL(request.url);
50
50
  if (url.pathname !== path || !['GET', 'HEAD'].includes(request.method)) return null;
51
- const branding = auth.presentation;
51
+ const branding = auth.publicPresentation ? await auth.publicPresentation() : auth.presentation;
52
52
  const returnTo = safeReturnTo(url.searchParams.get('returnTo'), defaultReturnTo);
53
53
  const hint = emailHint(url.searchParams.get('login_hint'));
54
54
  const providers = auth.providers ? (await auth.providers.list()).filter(p => p.visible) : [];
@@ -133,6 +133,39 @@ Custom replay runners can supply each plan entry's `aliases` and pass
133
133
  `{dataOnly}` as `migrationReplay`'s third argument. Verified archive ledger
134
134
  hashes take precedence over name-only placement where available.
135
135
 
136
+ ### Leaving RER Managed: the Platform ledger rule
137
+
138
+ A Managed installation's D1 keeps its history in `rer_migrations`, which the
139
+ Platform runner writes; a native installation uses `d1_migrations`. The ledger
140
+ is deployment history, never product schema or data. Base maps it by migration
141
+ identity, name and SHA-256 of the file:
142
+
143
+ - Export from a Platform-ledger source records `manifest.migrationLedger` (see
144
+ "Migration history" below) and never archives `rer_migrations` as a table.
145
+ - Import into a native installation matches every entry to exactly one
146
+ checkout file by hash; a name may confirm that file but cannot point at
147
+ another. A file the checkout does not have or whose content differs refuses
148
+ as `migration_ledger:unknown:<name>`, a name on one file with the hash of
149
+ another as `migration_ledger:conflict:<name>`, and the CLI prints the fix.
150
+ A checkout file the Platform history lacks refuses at the preflight as
151
+ `migration_ledger:unapplied`, naming the file; apply it with Platform first.
152
+ - Adapters with their own archive format (not Base's) call `mapMigrationLedger`
153
+ instead of comparing ledger controllers: it returns the entries named by the
154
+ checkout's files, or refuses with the same constant codes.
155
+
156
+ ```js
157
+ import { mapMigrationLedger } from '@runeditrun/rer/portability-migrations';
158
+
159
+ // Export: the source's ledger rows (rer_migrations or not), as native identities.
160
+ const ledger = await mapMigrationLedger({ root, binding: 'DB', platformMigrations, entries: rows });
161
+ // Import: the archive's entries must map without refusal; write no ledger rows.
162
+ await mapMigrationLedger({ root, binding: 'DB', platformMigrations, entries: archive.ledger });
163
+ ```
164
+
165
+ Call `nativeMigrationPreflight` before each native apply as below: a sole,
166
+ fully applied `rer_migrations` returns `{nativeApply:false}` for export and
167
+ import alike, so a seed's own guard must not require `d1_migrations`.
168
+
136
169
  ### Before an adapter's native migrations
137
170
 
138
171
  Seed adapters sometimes prepare schema before calling `localPortability`.
@@ -192,7 +225,7 @@ provider operation.
192
225
  | Compatible `d1_migrations`, every recorded name exactly equal to its checkout filename | `{nativeApply:true}`; Wrangler may apply its pending files. Plain Wrangler names remain supported; tracked history must also match hashes and applied states. |
193
226
  | Native alias-only or hash-only relocation, or an unmapped native data-only row | `migration_ledger:incompatible`; restore the matching checkout or reconcile through the owning runner before native apply. |
194
227
  | Sole, fully applied matching `rer_migrations` | `{nativeApply:false}`; preserve Platform's ledger and skip Wrangler. |
195
- | Any pending checkout file with Platform history | `migration_ledger:unapplied`; apply it through the owning runner first. |
228
+ | Any pending checkout file with Platform history | `migration_ledger:unapplied`, naming the file (`error.migration`); apply it through the owning runner first. |
196
229
  | Multiple ledgers, even empty | `migration_ledger:multiple`; reconcile history through its owning runner. |
197
230
  | Legacy `_rer_deploy_migrations` alone | `migration_ledger:runner`; use its owning runner, which can adopt the history. |
198
231
  | Invalid ledger shape, row or binding | `migration_ledger:incompatible` or `migration_ledger:binding`. |
@@ -440,6 +473,18 @@ them into a scratch database to find the archive's place in that history:
440
473
  - Archives record the applied migration names in `manifest.migrations` (since
441
474
  additive restore). Every recorded migration must be applied here, and
442
475
  replaying exactly those must give the archive's schema identity.
476
+ - Archives exported from an installation RER Platform migrated (a Managed
477
+ installation leaving for native) also carry `manifest.migrationLedger`:
478
+ `{origin:'rer_migrations',entries:[{name,sha256}]}` in application order,
479
+ each entry named by the exporting checkout's file with that SHA-256, so
480
+ `manifest.migrations` lists native file names whatever prefix Platform
481
+ recorded. Where the exporter has no checkout files (a hosted export), the
482
+ ledger's own names are kept beside their hashes. Import resolves each entry
483
+ by hash exactly as it does an archived ledger table (next item), so a
484
+ Platform prefix needs no declaration and a changed file refuses. Platform's
485
+ ledger is never imported as product tables. Native sources record no
486
+ `migrationLedger`; their archives are unchanged, and v1 and earlier v2
487
+ archives remain importable.
443
488
  - Older archives that still carry their source's migration ledger as a table
444
489
  (`rer_migrations` and the other ledgers above, from before they became
445
490
  bookkeeping) are placed by it. Every name it records must be applied here,
@@ -643,6 +688,42 @@ its v2 output succeeds; do not reset the recovered installation to retry.
643
688
  `exports.create(actor?)` copies all tables in one D1 batch. Product writes may
644
689
  continue after that snapshot. R2 listing records size and etag; changes or missing
645
690
  objects fail subsequent reads. D1 and R2 do not share a cross-binding transaction.
691
+
692
+ The direct service factory `createPortability` accepts an optional synchronous
693
+ `onExport({id, actor, scope})` callback returning `[sql, args][]`. Its SQL is
694
+ appended to that same snapshot/job-creating D1 batch. A thrown callback or failed
695
+ statement refuses creation; failed SQL rolls back the job, snapshots and audit
696
+ rows together. With no hook, export behavior is unchanged. This records job
697
+ creation, not successful download: a later build, file-write or download failure
698
+ does not erase a committed creation audit.
699
+
700
+ This hook applies to exports created through that service, including the file
701
+ adapter used by CLI exports. `createPortabilityHandler` does not accept or
702
+ forward `onExport`; the HTTP export handler has no audit hook.
703
+
704
+ `id` is the export job id, `scope` is the constant `'installation'`, and `actor`
705
+ is the opaque caller id, with the direct/CLI sentinel `'direct'` normalized to
706
+ `null`. Job ownership still stores `'direct'` for existing direct callers.
707
+ The callback receives no names, emails, IdP identifiers, tokens, record data,
708
+ object keys or file paths. Pass only opaque operator ids as authenticated actors.
709
+ The seed owns audit storage, migrations, retention, erasure and archive policy;
710
+ Base adds no audit table. For a CLI installation export, wire the seed's existing
711
+ `operation_audit` schema to action `installation.export`, actor_id `NULL` and
712
+ feature `rer export`, for example:
713
+
714
+ ```js
715
+ const service = await createPortability({db, buckets, policy,
716
+ onExport: ({id, actor}) => [[
717
+ 'INSERT INTO operation_audit(id,action,actor_id,feature) VALUES(?,?,?,?)',
718
+ [id, 'installation.export', actor, 'rer export'],
719
+ ]],
720
+ });
721
+ ```
722
+
723
+ Adapt the statement to the seed's schema and use the service in its existing
724
+ export adapter. Hooks return SQL only; external side effects cannot share the
725
+ D1 transaction. Do not write these events to the erasure tombstone journal.
726
+
646
727
  Transfer bookkeeping lives in sidecar tables, so product tables up to D1's
647
728
  100-column limit retain the full column and binding capacity. A keyless table
648
729
  with 100 columns or generated columns restores its rowids with two updates in
@@ -5,7 +5,7 @@ import { createCopy,readCopy,normalizeCopy } from './copies.mjs';
5
5
  import { canonicalJson, utf8, base64, StreamHash } from './hash.mjs';
6
6
  import { FORMAT, makePart, checkPart, ContentVerifier, ArchiveVerifier } from './format.mjs';
7
7
  import { journal } from './journal.mjs';
8
- import { appliedMigrations } from './bridge.mjs';
8
+ import { readLedger, platformOrigin } from './ledgers.mjs';
9
9
  import { capturePayload, payloadRange } from './payloads.mjs';
10
10
  import { dropProviderData } from './provider-data.mjs';
11
11
  import { dropDevData } from './dev-data.mjs';
@@ -23,11 +23,13 @@ export async function createExport(context,actor='direct') {
23
23
  }
24
24
  objects.sort((a,b)=>a.bucket<b.bucket?-1:a.bucket>b.bucket?1:a.key<b.key?-1:a.key>b.key?1:0);
25
25
  const copies=Object.fromEntries(cat.tables.map((t,i)=>[t.name,'rer_portability_snap_'+id.replaceAll('-','')+'_'+i]));
26
- const migrations=await appliedMigrations(db);
27
- const manifest={kind:'manifest',format:FORMAT,version:2,product:config.product,exportedAt:new Date().toISOString(),sourceIdentity:s.source_identity,schema:cat.identity,tables:cat.tables,schemaObjects:cat.schemaObjects,objects,payloads:[],excludedTables:cat.excludedTables,excludedColumns:config.secretColumns,requiredConfiguration:config.requiredConfiguration,partCount:0,epoch:s.epoch,journal:await journal(db,s.source_identity),...(migrations?{migrations}:{})};
26
+ const ledger=await readLedger(db),origin=await platformOrigin(ledger,context.migrations),migrations=origin?origin.entries.map(entry=>entry.name):ledger?.entries.map(entry=>entry.name);
27
+ const manifest={kind:'manifest',format:FORMAT,version:2,product:config.product,exportedAt:new Date().toISOString(),sourceIdentity:s.source_identity,schema:cat.identity,tables:cat.tables,schemaObjects:cat.schemaObjects,objects,payloads:[],excludedTables:cat.excludedTables,excludedColumns:config.secretColumns,requiredConfiguration:config.requiredConfiguration,partCount:0,epoch:s.epoch,journal:await journal(db,s.source_identity),...(migrations?{migrations}:{}),...(origin?{migrationLedger:origin}:{})};
28
28
  const row={id,kind:'export',actor,phase:'building',completed:0,metadata:{manifest,copies,cursor:{table:0,row:0,binary:0,offset:0},partBytes:config.partBytes}};
29
+ const audit=context.onExport?context.onExport({id,actor:actor==='direct'?null:actor,scope:'installation'}):[];
29
30
  await db.batch([guard(db,'EXISTS(SELECT 1 FROM rer_portability_state WHERE id=1 AND applying=0 AND source_identity=? AND epoch=?)',s.source_identity,s.epoch),
30
- ...cat.tables.flatMap(t=>createCopy(db,t,copies[t.name],true)),statement(db,'INSERT INTO rer_portability_jobs(id,kind,actor,phase,metadata) VALUES(?,?,?,?,?)',id,'export',actor,row.phase,canonicalJson(row.metadata)),db.prepare('DELETE FROM rer_portability_guard')]);
31
+ ...cat.tables.flatMap(t=>createCopy(db,t,copies[t.name],true)),statement(db,'INSERT INTO rer_portability_jobs(id,kind,actor,phase,metadata) VALUES(?,?,?,?,?)',id,'export',actor,row.phase,canonicalJson(row.metadata)),db.prepare('DELETE FROM rer_portability_guard'),
32
+ ...audit.map(([sql,args])=>statement(db,sql,...args))]);
31
33
  try {
32
34
  await dropDevData(db,cat.tables,copies);
33
35
  await dropProviderData(db,cat.tables,copies);
@@ -38,6 +38,11 @@ async function checkManifestFields(m) {
38
38
  insist(Array.isArray(m.tables) && Array.isArray(m.objects) && Array.isArray(m.payloads) && Array.isArray(m.journal) && Array.isArray(m.requiredConfiguration),'manifest_inventory');
39
39
  // Applied product migrations, recorded by archives since additive restore.
40
40
  insist(m.migrations===undefined || (Array.isArray(m.migrations) && m.migrations.every(x=>typeof x==='string')),'manifest_inventory');
41
+ // The ledger an export from a RER Platform installation records, by migration identity.
42
+ const ledger=m.migrationLedger;
43
+ insist(ledger===undefined || (ledger && typeof ledger==='object' && Object.keys(ledger).sort().join()==='entries,origin' && ledger.origin==='rer_migrations' && Array.isArray(ledger.entries)
44
+ && ledger.entries.every(e=>e && typeof e==='object' && Object.keys(e).sort().join()==='name,sha256' && typeof e.name==='string' && /^[a-f0-9]{64}$/.test(e.sha256))
45
+ && canonicalJson(m.migrations)===canonicalJson(ledger.entries.map(e=>e.name)) && new Set(m.migrations).size===m.migrations.length),'manifest_inventory');
41
46
  insist(m.tables.every((t,i)=>typeof t.name==='string' && typeof t.sql==='string' && Array.isArray(t.columns) && Array.isArray(t.dependencies) && Number.isSafeInteger(t.count) && t.count>=0 && (!i || m.tables[i-1].name<t.name)),'table_inventory');
42
47
  insist(m.schemaObjects===undefined || (Array.isArray(m.schemaObjects) && m.schemaObjects.every((o,i)=>
43
48
  o && typeof o.name==='string' && ['index','view','trigger'].includes(o.type) && typeof o.table==='string' && typeof o.sql==='string'
@@ -13,6 +13,8 @@ export interface Manifest {
13
13
  excludedTables: string[]; excludedColumns: Record<string,string[]>; requiredConfiguration: string[]; partCount: number; epoch: number; journal: string[];
14
14
  /** Applied product migrations; absent from archives made before additive restore. */
15
15
  migrations?: string[];
16
+ /** Present when RER Platform's runner migrated the source: each applied migration by native file name and SHA-256, in application order. */
17
+ migrationLedger?: {origin:'rer_migrations';entries:{name:string;sha256:string}[]};
16
18
  }
17
19
  export type Item = {kind:'row';table:string;index:number;row:Row;rowid?:number} | {kind:'object';bucket:string;key:string;offset:number;data:string} | {kind:'payload';name:string;offset:number;data:string};
18
20
  export interface Part {kind:'part';index:number;items:Item[];sha256:string}
@@ -42,7 +44,13 @@ export interface Status {id:string;kind:'export'|'import';phase:'building'|'stag
42
44
  export interface Bridge {fromSchema:string;toSchema:string;migrations:string[];tables:string[];columns:Record<string,string[]>;/** Later backfills of tables the archive lacks, replayed at finalize in this order; rows is null until the apply commits. */replayed?:{migration:string;statement:number;table:string;rows:number|null}[]}
43
45
  /** A runner's replay of the destination's applied migrations: the archive schema identity after a chosen set, and each migration's statements. */
44
46
  export interface MigrationReplay {names:string[];/** Seed-declared data-only Platform entries without migration files. */dataOnly?:string[];/** Names generated by the seed's deployment specification for this file. */aliases?(name:string):string[]|undefined;statements(name:string):string[];/** The migration file's SHA-256 hex, where the runner read the file. */sha256?(name:string):string|undefined;schemaAfter(names:string[]):Promise<string>}
45
- export interface PortabilityOptions {db:D1Database;buckets?:Record<string,R2Bucket>;policy:ArchivePolicy;migrations?:()=>Promise<MigrationReplay>}
47
+ /** Export job creation only; no record data, object keys or file paths. */
48
+ export interface ExportEvent {id:string;/** Opaque caller id; the direct/CLI sentinel is normalized to null. */actor:string|null;scope:'installation'}
49
+ export interface PortabilityOptions {
50
+ db:D1Database;buckets?:Record<string,R2Bucket>;policy:ArchivePolicy;migrations?:()=>Promise<MigrationReplay>;
51
+ /** Seed-owned audit SQL, appended to the snapshot/job batch. Throwing or SQL failure refuses creation. */
52
+ onExport?:(event:ExportEvent)=>[sql:string,args:unknown[]][];
53
+ }
46
54
  export interface Portability {
47
55
  exports: {create(actor?:string):Promise<string>;advance(id:string,options?:{expectedPart?:number;maxParts?:number}):Promise<Status>;status(id:string):Promise<Status>;download(id:string):Promise<ReadableStream<Uint8Array>>;abort(id:string):Promise<Status>};
48
56
  imports: {active(actor?:string):Promise<Status|null>;/** ledgers: the rows of each migration ledger table an old archive carries, as read from it; they place it in the destination's history and must equal its parts. */create(manifest:Manifest,actor?:string,options?:{ledgers?:Record<string,Row[]>}):Promise<string>;uploadPart(id:string,index:number,part:Part):Promise<Status>;finalize(id:string,options:{archiveHash:string;contentHash?:string;laterJournal?:LaterJournal}):Promise<Status>;status(id:string):Promise<Status>;abort(id:string):Promise<Status>;/** Aborts the import left staged by a crashed restore and returns its id; call only as the destination's sole operator. */abortAbandoned():Promise<string|null>};
@@ -52,7 +60,7 @@ export interface Portability {
52
60
  invalidateTransfersStatements():Promise<D1PreparedStatement[]>;
53
61
  }
54
62
  export function createPortability(options:PortabilityOptions):Promise<Portability>;
55
- export interface HandlerOptions extends PortabilityOptions {
63
+ export interface HandlerOptions extends Omit<PortabilityOptions,'onExport'> {
56
64
  appOrigin:string;basePath?:string;maxBodyBytes?:number;
57
65
  authorize:(request:Request,context:{operation:'export'|'import'|'unknown';jobId:string|null})=>string|null|Promise<string|null>;
58
66
  }
@@ -11,12 +11,13 @@ export { readArchive, makePart, MAX_LINE_BYTES, MAX_PART_BYTES } from './format.
11
11
  export { canonicalJson, sha256 } from './hash.mjs';
12
12
  export { PortabilityError } from './storage.mjs';
13
13
  export { createPortabilityHandler } from './http.mjs';
14
- export async function createPortability({db,buckets={},policy:input,migrations}) {
14
+ export async function createPortability({db,buckets={},policy:input,migrations,onExport}) {
15
+ insist(onExport===undefined || typeof onExport==='function','invalid_on_export');
15
16
  db=wireDatabase(db);
16
17
  const config=policy(input);await catalogue(db,config);
17
18
  for(const name of Object.keys(config.buckets))insist(buckets[name] && typeof buckets[name].get==='function','missing_bucket:'+name);
18
19
  await ensureImportLeases(db);
19
- const context={db,buckets,config,migrations};
20
+ const context={db,buckets,config,migrations,onExport};
20
21
  return {
21
22
  exports:{create:actor=>createExport(context,actor),advance:(id,options)=>advanceExport(context,id,options),status:id=>exportStatus(context,id),download:id=>downloadExport(context,id),abort:id=>abortExport(context,id)},
22
23
  imports:{active:actor=>activeImport(context,actor),create:(manifest,actor,options={})=>createImport(context,manifest,actor,undefined,options.ledgers),uploadPart:(id,index,part)=>uploadPart(context,id,index,part),finalize:(id,options)=>finalizeImport(context,id,options),status:id=>importStatus(context,id),abort:id=>abortImport(context,id),abortAbandoned:()=>abortAbandonedImport(context)},
@@ -18,8 +18,12 @@ const partial=name=>name.includes('#');
18
18
 
19
19
  /** The destination's applied product migrations, [{name,sha256?}] in the ledger's own order, or undefined without a ledger. */
20
20
  export async function destinationLedger(db) {
21
+ return (await readLedger(db))?.entries;
22
+ }
23
+ /** The ledger table in use and its applied migrations, {table,entries}, or undefined without a ledger. */
24
+ export async function readLedger(db) {
21
25
  const found=(await all(db,`SELECT name FROM sqlite_master WHERE type='table' AND name IN (${ledgerNames.map(n=>`'${n}'`).join(',')})`)).map(x=>x.name);
22
- if(found.includes('_rer_deploy_migrations'))return (await all(db,"SELECT * FROM _rer_deploy_migrations WHERE state='applied' ORDER BY name")).map(entry);
26
+ if(found.includes('_rer_deploy_migrations'))return {table:'_rer_deploy_migrations',entries:(await all(db,"SELECT * FROM _rer_deploy_migrations WHERE state='applied' ORDER BY name")).map(entry)};
23
27
  if(found.includes('d1_migrations')) {
24
28
  const columns=(await all(db,'PRAGMA table_info(d1_migrations)')).map(x=>x.name);
25
29
  insist(['id','name','applied_at'].every(name=>columns.includes(name)),'schema_mismatch:migration_history',409);
@@ -29,7 +33,7 @@ export async function destinationLedger(db) {
29
33
  insist(rows.every(row=>typeof row.name==='string') && new Set(rows.map(row=>row.name)).size===rows.length,'schema_mismatch:migration_history',409);
30
34
  if(tracked)insist(rows.every(row=>row.state==='applied'),'schema_mismatch:uncertain_migrations',409);
31
35
  if(tracked)insist(rows.every(row=>typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)),'schema_mismatch:migration_history',409);
32
- return rows.map(entry);
36
+ return {table:'d1_migrations',entries:rows.map(entry)};
33
37
  }
34
38
  if(!found.includes('rer_migrations'))return;
35
39
  // Platform applies pending files in its plan's order and inserts each ledger
@@ -39,7 +43,7 @@ export async function destinationLedger(db) {
39
43
  const rows=await all(db,'SELECT name,sha256 FROM rer_migrations ORDER BY rowid');
40
44
  insist(rows.every(row=>typeof row.name==='string' && typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)) && new Set(rows.map(row=>row.name)).size===rows.length,'schema_mismatch:migration_history',409);
41
45
  insist(!rows.some(row=>partial(row.name)),'schema_mismatch:uncertain_migrations',409);
42
- return rows.map(entry);
46
+ return {table:'rer_migrations',entries:rows.map(entry)};
43
47
  }
44
48
  const entry=row=>({name:row.name,...(typeof row.sha256==='string'?{sha256:row.sha256}:{})});
45
49
 
@@ -67,6 +71,23 @@ export function matchMigrationLedger(entries,files,{dataOnly=[]}={}) {
67
71
  return matched;
68
72
  }
69
73
 
74
+ /**
75
+ * What an export records when its source was migrated by RER Platform:
76
+ * {origin:'rer_migrations',entries:[{name,sha256}]} in application order, each
77
+ * entry named by the checkout file with that hash (the native identity) where
78
+ * the exporter can read the checkout's files. Declared data-only entries and
79
+ * hosted exporters, which have no files, keep the ledger's own names. Native
80
+ * sources record nothing here, so their archives are unchanged.
81
+ */
82
+ export async function platformOrigin(ledger,migrations) {
83
+ if(ledger?.table!=='rer_migrations')return;
84
+ const replay=await migrations?.();
85
+ const files=replay?.names.map(name=>({name,sha256:replay.sha256?.(name),aliases:replay.aliases?.(name)}));
86
+ const entries=ledger.entries.map(({name,sha256})=>({name:files?(matchMigrationLedger([{name,sha256}],files,replay)[0]??name):name,sha256}));
87
+ insist(new Set(entries.map(entry=>entry.name)).size===entries.length,'migration_ledger:ambiguous',409);
88
+ return {origin:'rer_migrations',entries};
89
+ }
90
+
70
91
  /** The ledger tables an archive carries (old archives carried rer_migrations before it became bookkeeping). */
71
92
  export const archivedLedgerTables=manifest=>manifest.tables.filter(t=>ledgerNames.includes(identifier(t.name)));
72
93
 
@@ -96,7 +117,9 @@ export function checkArchivedLedgers(manifest,ledgers) {
96
117
  /** The applied migrations an archive's own ledger records, [{name,sha256?}]; undefined when it carries no ledger. */
97
118
  export function archivedHistory(manifest,ledgers) {
98
119
  const tables=archivedLedgerTables(manifest);
99
- if(!tables.length)return;
120
+ // A Platform-origin export records its ledger in the manifest, never as a table.
121
+ if(manifest.migrationLedger)insist(!tables.length,'schema_mismatch:migration_history');
122
+ if(!tables.length)return manifest.migrationLedger?.entries.map(entry);
100
123
  insist(tables.length===1 && ledgers?.[tables[0].name],'schema_mismatch:migration_history');
101
124
  const [table]=tables,rows=ledgers[table.name],columns=table.columns.map(c=>c.name);
102
125
  if(identifier(table.name)==='rer_migrations') {
@@ -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);