@jini-ai/registry 0.6.12 → 0.6.15-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 0.6.13
2
+
3
+ ### Patch Changes
4
+
5
+ - Updated dependencies [7479159]
6
+ - Updated dependencies [c31264d]
7
+ - Updated dependencies [0728914]
8
+ - Updated dependencies [cbce255]
9
+ - Updated dependencies [6ecbdb2]
10
+ - Updated dependencies [63bacc5]
11
+ - @jini-ai/core@0.6.13
12
+ - @jini-ai/protocol@0.6.13
13
+
1
14
  ## 0.6.12
2
15
 
3
16
  ### Patch Changes
@@ -29,7 +29,18 @@ export class DatabaseRegistryBackend extends StaticRegistryBackend {
29
29
  if (parsed.dryRun) {
30
30
  return { ok: true, dryRun: true, changedFiles, warnings: [] };
31
31
  }
32
- upsertRegistryEntry({ db: this.db, backendId: this.id, entry: parsed.entry }, { now: this.clock.nowMs() });
32
+ // Like yank, publishing now reads before writing. Lock before reading so
33
+ // concurrent publishers cannot overwrite each other's version history.
34
+ const runPublish = this.db.transaction(() => {
35
+ const row = this.db
36
+ .prepare(`SELECT entry_json FROM registry_entries WHERE backend_id = ? AND name = ?`)
37
+ .get(this.id, parsed.entry.name);
38
+ const entry = row
39
+ ? mergePublishedVersions({ previous: parseStoredEntry(row.entry_json, `${this.id}/${parsed.entry.name}`), entry: parsed.entry })
40
+ : parsed.entry;
41
+ upsertRegistryEntry({ db: this.db, backendId: this.id, entry }, { now: this.clock.nowMs() });
42
+ });
43
+ runPublish.immediate();
33
44
  return { ok: true, dryRun: false, changedFiles, warnings: [] };
34
45
  }
35
46
  async yank({ name, version, reason }) {
@@ -73,6 +84,24 @@ export class DatabaseRegistryBackend extends StaticRegistryBackend {
73
84
  return manifestFromDb(this.db, this.id);
74
85
  }
75
86
  }
87
+ /**
88
+ * Preserve stored releases while accepting incoming version records by version.
89
+ * Pure; neither input is mutated. Map replacement keeps the merge linear in
90
+ * the combined ledger size instead of searching the old ledger per release.
91
+ */
92
+ function mergePublishedVersions({ previous, entry }, _options = {}) {
93
+ const versions = new Map([...publishedVersionRecords({ entry: previous }), ...publishedVersionRecords({ entry })]
94
+ .map((record) => [record.version, record]));
95
+ return { ...entry, versions: [...versions.values()] };
96
+ }
97
+ /** Include a single-version entry's artifact metadata without copying its ledger into itself. Explicit records take precedence. */
98
+ function publishedVersionRecords({ entry }, _options = {}) {
99
+ const { version, source, ref, dist, integrity, manifestDigest, deprecated, yanked, yankedAt, yankReason } = entry;
100
+ return [
101
+ { version, source, ref, dist, integrity, manifestDigest, deprecated, yanked, yankedAt, yankReason },
102
+ ...(entry.versions ?? []),
103
+ ];
104
+ }
76
105
  /**
77
106
  * Create the `registry_entries` table if it does not already exist.
78
107
  *
@@ -56,7 +56,15 @@ export class StaticRegistryBackend {
56
56
  // as before. A backend with no `trustRoot` configured (the unchanged
57
57
  // default) always resolves `verified: false` here without attempting
58
58
  // any cryptographic work — see `trust.ts`'s `verifyRegistryEntrySignatures`.
59
- const verification = verifyRegistryEntrySignatures({ entry }, { trustRoot: this.trustRoot });
59
+ // Verification must cover the version and digest returned to the caller,
60
+ // rather than letting an older version inherit the top-level signature.
61
+ const verification = verifyRegistryEntrySignatures({ entry: {
62
+ ...entry,
63
+ version: resolvedVersion.version,
64
+ integrity: resolvedVersion.archiveIntegrity,
65
+ manifestDigest: resolvedVersion.manifestDigest,
66
+ dist: undefined,
67
+ } }, { trustRoot: this.trustRoot });
60
68
  return {
61
69
  backendId: this.id,
62
70
  backendKind: this.kind,
package/dist/trust.d.ts CHANGED
@@ -50,7 +50,7 @@ export interface SignatureVerificationResult {
50
50
  reason?: string;
51
51
  /** Present when `verified` is `true` — the signature's self-reported `issuer` field. */
52
52
  issuer?: string;
53
- /** Present when `verified` is `true` — the signature's self-reported `subject` field, falling back to the certificate's own first SAN identity when the signature didn't declare one. */
53
+ /** Present when `verified` is `true` and the certificate has a SAN URI — the certificate's own first SAN identity. */
54
54
  subject?: string;
55
55
  }
56
56
  /**
@@ -64,10 +64,11 @@ export interface SignatureVerificationResult {
64
64
  *
65
65
  * @param entry - The registry entry the signature is claimed to cover.
66
66
  * @returns The canonical UTF-8 string the signature must be a valid signature over.
67
+ * @throws When the version or digest is missing or blank; a signature must bind to artifact bytes.
67
68
  */
68
69
  export declare function canonicalRegistrySigningPayload({ entry }: {
69
70
  entry: RegistryEntry;
70
- }): string;
71
+ }, _options?: Record<string, never>): string;
71
72
  /**
72
73
  * Verify one {@link RegistrySignature} against a host-configured
73
74
  * {@link RegistryTrustRoot}. Never throws — a malformed certificate,
package/dist/trust.js CHANGED
@@ -91,9 +91,15 @@ export const GITHUB_ACTIONS_OIDC_ISSUER = 'https://token.actions.githubuserconte
91
91
  *
92
92
  * @param entry - The registry entry the signature is claimed to cover.
93
93
  * @returns The canonical UTF-8 string the signature must be a valid signature over.
94
+ * @throws When the version or digest is missing or blank; a signature must bind to artifact bytes.
94
95
  */
95
- export function canonicalRegistrySigningPayload({ entry }) {
96
- const digest = entry.integrity ?? entry.manifestDigest ?? entry.dist?.integrity ?? entry.dist?.manifestDigest ?? '';
96
+ export function canonicalRegistrySigningPayload({ entry }, _options = {}) {
97
+ if (!entry.version?.trim())
98
+ throw new Error('Registry signing payload requires a version');
99
+ const dist = entry.dist ?? {};
100
+ const digest = entry.integrity ?? entry.manifestDigest ?? dist.integrity ?? dist.manifestDigest;
101
+ if (!digest?.trim())
102
+ throw new Error('Registry signing payload requires a digest');
97
103
  return `${entry.name}@${entry.version}:${digest}`;
98
104
  }
99
105
  /**
@@ -115,7 +121,7 @@ export function verifyRegistrySignature({ entry, signature }, { trustRoot } = {}
115
121
  // report "unsupported", never silently pass and never throw.
116
122
  return { verified: false, kind: signature.kind, reason: `unsupported signature kind: ${signature.kind}` };
117
123
  }
118
- const outcome = verifyGithubOidcSignature(entry, signature, trustRoot?.githubOidc);
124
+ const outcome = verifyGithubOidcSignature({ entry, signature }, { root: trustRoot?.githubOidc });
119
125
  if ('reason' in outcome)
120
126
  return { verified: false, kind: signature.kind, reason: outcome.reason };
121
127
  return { verified: true, kind: signature.kind, issuer: outcome.issuer, ...(outcome.subject !== undefined ? { subject: outcome.subject } : {}) };
@@ -126,7 +132,7 @@ const fail = (reason) => ({ reason });
126
132
  * reason is the one reported: trust root, signature fields, certificate
127
133
  * chain + validity window, identity allowlist, signature bytes.
128
134
  */
129
- function verifyGithubOidcSignature(entry, signature, root) {
135
+ function verifyGithubOidcSignature({ entry, signature }, { root } = {}) {
130
136
  if (!root || root.caCertificates.length === 0) {
131
137
  // Decision 4: a backend with no configured trust root gets no
132
138
  // verification at all — current (pre-this-task) behavior, unchanged.
@@ -142,10 +148,10 @@ function verifyGithubOidcSignature(entry, signature, root) {
142
148
  if (!identityAllowed(identities, root.allowedIdentities)) {
143
149
  return fail('signer identity is not in the configured allowlist');
144
150
  }
145
- const signatureFailure = checkSignatureBytes(entry, signature.signature, leaf);
151
+ const signatureFailure = checkSignatureBytes({ entry, signature: signature.signature, leaf });
146
152
  if (signatureFailure)
147
153
  return signatureFailure;
148
- return { issuer: fields.issuer, subject: signature.subject ?? identities[0] };
154
+ return { issuer: fields.issuer, subject: identities[0] };
149
155
  }
150
156
  /** Presence of certificate/issuer/signedAt, the issuer allowlist, and a parseable `signedAt`. */
151
157
  function checkSignatureFields(signature, root) {
@@ -196,8 +202,8 @@ function identityAllowed(identities, allowedIdentities) {
196
202
  return true;
197
203
  return identities.some((identity) => allowedIdentities.some((pattern) => (typeof pattern === 'string' ? pattern === identity : pattern.test(identity))));
198
204
  }
199
- /** Verify `signature` (base64) over {@link canonicalRegistrySigningPayload} with the leaf's public key; `undefined` when it verifies. */
200
- function checkSignatureBytes(entry, signature, leaf) {
205
+ /** Verify `signature` (base64) over {@link canonicalRegistrySigningPayload} with the leaf's public key; `undefined` on success, a failure for invalid payloads or signatures. Never throws. */
206
+ function checkSignatureBytes({ entry, signature, leaf }, _options = {}) {
201
207
  // `Buffer.from(str, 'base64')` never throws (Node's base64 decoder is
202
208
  // lenient about invalid input, silently dropping bad characters) — a
203
209
  // malformed encoding surfaces as an empty/garbage buffer that then fails
@@ -205,9 +211,9 @@ function checkSignatureBytes(entry, signature, leaf) {
205
211
  const signatureBytes = Buffer.from(signature, 'base64');
206
212
  if (signatureBytes.length === 0)
207
213
  return fail('signature is empty after base64 decoding');
208
- const payload = Buffer.from(canonicalRegistrySigningPayload({ entry }), 'utf8');
209
214
  let signatureValid;
210
215
  try {
216
+ const payload = Buffer.from(canonicalRegistrySigningPayload({ entry }), 'utf8');
211
217
  // `crypto.verify()` CAN throw (not just return false) for a
212
218
  // structurally-incompatible key/algorithm pairing — e.g. an Ed25519
213
219
  // certificate's key does not accept an explicit 'sha256' digest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/registry",
3
- "version": "0.6.12",
3
+ "version": "0.6.15-rc.1",
4
4
  "description": "Pluggable content-registry backends (static, GitHub, database) and semver specifier resolution over @jini-ai/protocol’s registry wire types.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -74,13 +74,13 @@
74
74
  "registry": "https://registry.npmjs.org"
75
75
  },
76
76
  "dependencies": {
77
- "@jini-ai/protocol": "^0.6.12",
78
- "@jini-ai/core": "^0.6.12"
77
+ "@jini-ai/protocol": "^0.6.15-rc.1",
78
+ "@jini-ai/core": "^0.6.15-rc.1"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "better-sqlite3": "^13.0.0",
82
- "@jini-ai/db": "^0.6.10",
83
- "@jini-ai/platform": "^0.6.10"
82
+ "@jini-ai/db": "^0.6.15-rc.1",
83
+ "@jini-ai/platform": "^0.6.15-rc.1"
84
84
  },
85
85
  "peerDependenciesMeta": {
86
86
  "better-sqlite3": {
@@ -96,10 +96,10 @@
96
96
  "devDependencies": {
97
97
  "@types/better-sqlite3": "^7.6.11",
98
98
  "better-sqlite3": "^13.0.0",
99
- "@jini-ai/core": "^0.6.12",
100
- "@jini-ai/platform": "^0.6.12",
101
- "@jini-ai/db": "0.6.12",
102
- "@jini-ai/protocol": "^0.6.12"
99
+ "@jini-ai/db": "0.6.15-rc.1",
100
+ "@jini-ai/platform": "^0.6.15-rc.1",
101
+ "@jini-ai/protocol": "^0.6.15-rc.1",
102
+ "@jini-ai/core": "^0.6.15-rc.1"
103
103
  },
104
104
  "scripts": {
105
105
  "build": "tsc -p tsconfig.json",