@xemahq/biome-supply-chain 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/biome-supply-chain",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Shared cosign supply-chain verification for Xema biomes: the single cosign CLI exec + the signature/provenance verdict enums used by biome-fetcher-api (OCI bundle verification) and xema-store-api. Node-builtins only.",
5
5
  "license": "LicenseRef-Xema-BSL-1.1",
6
6
  "author": "Neuralchowder Inc. <developer@xema.dev> (https://xema.dev)",
@@ -29,8 +29,7 @@
29
29
  "main": "./dist/index.js",
30
30
  "types": "./dist/index.d.ts",
31
31
  "files": [
32
- "dist",
33
- "src"
32
+ "dist"
34
33
  ],
35
34
  "devDependencies": {
36
35
  "@types/node": "25.2.3",
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/verdicts';
2
- export * from './lib/cosign-exec';
@@ -1,188 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
-
3
- import { CosignVerifyOutcome } from './verdicts';
4
-
5
- /** Default cosign binary name (overridable per call). */
6
- const DEFAULT_COSIGN_BIN = 'cosign';
7
-
8
- interface CosignRunResult {
9
- readonly code: number;
10
- readonly stderr: string;
11
- }
12
-
13
- /**
14
- * The single canonical cosign invocation. Spawns the binary, captures stderr,
15
- * and resolves with the exit code (never rejects on a non-zero exit — the
16
- * caller decides whether a non-zero code is an error or a "failed" verdict).
17
- * Rejects only when the process cannot be spawned at all.
18
- */
19
- function runCosign(
20
- bin: string,
21
- args: readonly string[],
22
- ): Promise<CosignRunResult> {
23
- return new Promise((resolve, reject) => {
24
- const child = spawn(bin, [...args], {
25
- stdio: ['ignore', 'pipe', 'pipe'],
26
- });
27
- let stderr = '';
28
- child.stderr?.on('data', (chunk: Buffer) => {
29
- stderr += chunk.toString();
30
- });
31
- child.on('error', reject);
32
- child.on('close', (code) => {
33
- resolve({ code: code ?? 1, stderr });
34
- });
35
- });
36
- }
37
-
38
- /** Throws if the cosign CLI is not available on PATH. */
39
- export async function ensureCosignAvailable(
40
- bin: string = DEFAULT_COSIGN_BIN,
41
- ): Promise<void> {
42
- try {
43
- const { code, stderr } = await runCosign(bin, ['version']);
44
- if (code !== 0) {
45
- throw new Error(`\`${bin} version\` exited ${code}: ${stderr.slice(-200)}`);
46
- }
47
- } catch (cause) {
48
- throw new Error(
49
- `cosign CLI is not on PATH — install from https://github.com/sigstore/cosign ` +
50
- `(${cause instanceof Error ? cause.message : String(cause)})`,
51
- );
52
- }
53
- }
54
-
55
- export interface VerifyCosignSignatureInput {
56
- readonly ociRef: string;
57
- /** Exact keyless certificate-identity URIs (any one may match). */
58
- readonly trustedIdentities: readonly string[];
59
- readonly oidcIssuer?: string | undefined;
60
- /** Keyed verification: path to the public key (mutually exclusive w/ keyless). */
61
- readonly keyPath?: string | undefined;
62
- readonly bin?: string | undefined;
63
- }
64
-
65
- /**
66
- * Verify a signature on an OCI ref (keyless identity allowlist OR keyed).
67
- * Throws on non-verification; resolves on success. Mirrors the fetcher's
68
- * former inline behaviour.
69
- */
70
- export async function verifyCosignSignature(
71
- input: VerifyCosignSignatureInput,
72
- ): Promise<void> {
73
- const bin = input.bin ?? DEFAULT_COSIGN_BIN;
74
- const args: string[] = ['verify'];
75
- if (input.keyPath) {
76
- args.push('--key', input.keyPath);
77
- } else {
78
- if (input.trustedIdentities.length === 0) {
79
- throw new Error(
80
- 'verifyCosignSignature: keyless mode requires at least one trusted identity',
81
- );
82
- }
83
- for (const id of input.trustedIdentities) {
84
- args.push('--certificate-identity', id);
85
- }
86
- if (input.oidcIssuer) {
87
- args.push('--certificate-oidc-issuer', input.oidcIssuer);
88
- }
89
- }
90
- args.push(input.ociRef);
91
- const { code, stderr } = await runCosign(bin, args);
92
- if (code !== 0) {
93
- throw new Error(`${bin} verify failed (code=${code}): ${stderr.slice(-200)}`);
94
- }
95
- }
96
-
97
- export interface VerifyCosignAttestationInput {
98
- readonly ociRef: string;
99
- readonly predicateType: string;
100
- readonly trustedIdentities: readonly string[];
101
- readonly oidcIssuer?: string | undefined;
102
- readonly keyPath?: string | undefined;
103
- readonly bin?: string | undefined;
104
- }
105
-
106
- /**
107
- * Verify an in-toto/SLSA attestation on an OCI ref. Throws on
108
- * non-verification; resolves on success.
109
- */
110
- export async function verifyCosignAttestation(
111
- input: VerifyCosignAttestationInput,
112
- ): Promise<void> {
113
- const bin = input.bin ?? DEFAULT_COSIGN_BIN;
114
- const args: string[] = ['verify-attestation', '--type', input.predicateType];
115
- if (input.keyPath) {
116
- args.push('--key', input.keyPath);
117
- } else {
118
- if (input.trustedIdentities.length === 0) {
119
- throw new Error(
120
- 'verifyCosignAttestation: keyless mode requires at least one trusted identity',
121
- );
122
- }
123
- for (const id of input.trustedIdentities) {
124
- args.push('--certificate-identity', id);
125
- }
126
- if (input.oidcIssuer) {
127
- args.push('--certificate-oidc-issuer', input.oidcIssuer);
128
- }
129
- }
130
- args.push(input.ociRef);
131
- const { code, stderr } = await runCosign(bin, args);
132
- if (code !== 0) {
133
- throw new Error(
134
- `${bin} verify-attestation failed (code=${code}): ${stderr.slice(-200)}`,
135
- );
136
- }
137
- }
138
-
139
- export interface VerifyCosignBlobInput {
140
- /** Path to the artifact bytes on disk (caller owns fetch/temp-file lifecycle). */
141
- readonly artifactPath: string;
142
- /** Path to the detached signature bundle on disk. */
143
- readonly bundlePath: string;
144
- /** Keyless certificate-identity REGEXPS (any one may match). */
145
- readonly trustedIdentityRegexps: readonly string[];
146
- readonly oidcIssuer?: string | undefined;
147
- readonly bin?: string | undefined;
148
- }
149
-
150
- export interface VerifyCosignBlobResult {
151
- readonly outcome: CosignVerifyOutcome;
152
- /** The identity regexp that matched, when Verified. */
153
- readonly matchedIdentity?: string | undefined;
154
- }
155
-
156
- /**
157
- * Verify a detached signature over a blob (`cosign verify-blob --bundle`).
158
- * Tries each trusted identity regexp; the first that verifies wins. Returns a
159
- * neutral {@link CosignVerifyOutcome} (never throws on a failed verification —
160
- * an empty trust list or all-mismatch resolves to `Failed`). The caller owns
161
- * artifact/bundle materialisation on disk.
162
- */
163
- export async function verifyCosignBlob(
164
- input: VerifyCosignBlobInput,
165
- ): Promise<VerifyCosignBlobResult> {
166
- const bin = input.bin ?? DEFAULT_COSIGN_BIN;
167
- if (input.trustedIdentityRegexps.length === 0) {
168
- return { outcome: CosignVerifyOutcome.Failed };
169
- }
170
- for (const identity of input.trustedIdentityRegexps) {
171
- const args: string[] = [
172
- 'verify-blob',
173
- '--bundle',
174
- input.bundlePath,
175
- '--certificate-identity-regexp',
176
- identity,
177
- ];
178
- if (input.oidcIssuer) {
179
- args.push('--certificate-oidc-issuer', input.oidcIssuer);
180
- }
181
- args.push(input.artifactPath);
182
- const { code } = await runCosign(bin, args);
183
- if (code === 0) {
184
- return { outcome: CosignVerifyOutcome.Verified, matchedIdentity: identity };
185
- }
186
- }
187
- return { outcome: CosignVerifyOutcome.Failed };
188
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * Shared cosign supply-chain verdict vocabulary.
3
- *
4
- * This is the single source of truth for the lowercase verdict/error enums
5
- * that `biome-fetcher-api` (OCI bundle verification) previously duplicated
6
- * locally. They are value-identical to that former copy, so adopting this
7
- * package is a pure de-duplication with no wire/behaviour change.
8
- *
9
- * (`@xemahq/biome-package` was a second consumer until 2026-08-01, when it was
10
- * deleted: it emitted a 4-layer OCI artifact whose layers carry no
11
- * `org.opencontainers.image.title`, so the fetcher's `oras pull` skipped every
12
- * one of them and materialised nothing. `xema biome publish` is now the single
13
- * biome packager.)
14
- *
15
- * NOTE: `xema-store-api` keeps its OWN UPPERCASE `SignatureVerdict` /
16
- * `ProvenanceVerdict` (persisted + OpenAPI + cross-service event wire); it
17
- * consumes only the cosign EXEC + {@link CosignVerifyOutcome} from this
18
- * package, mapping the neutral outcome to its own wire enum.
19
- */
20
-
21
- /** Signature verification verdict. */
22
- export enum SignatureVerdict {
23
- Valid = 'valid',
24
- Invalid = 'invalid',
25
- Unsigned = 'unsigned',
26
- }
27
-
28
- /** SLSA attestation / provenance verdict. */
29
- export enum ProvenanceVerdict {
30
- Valid = 'valid',
31
- Invalid = 'invalid',
32
- Missing = 'missing',
33
- }
34
-
35
- /** Stable, typed reasons a cosign verification may reject an artifact. */
36
- export enum CosignErrorCode {
37
- SignatureMissing = 'BIOME_SIGNATURE_MISSING',
38
- SignatureInvalid = 'BIOME_SIGNATURE_INVALID',
39
- IdentityNotTrusted = 'BIOME_SIGNATURE_IDENTITY_NOT_TRUSTED',
40
- ProvenanceMissing = 'BIOME_PROVENANCE_MISSING',
41
- ProvenanceInvalid = 'BIOME_PROVENANCE_INVALID',
42
- CosignUnavailable = 'BIOME_COSIGN_UNAVAILABLE',
43
- }
44
-
45
- /**
46
- * Casing-neutral internal outcome of a detached-blob verification. The blob
47
- * path (store) maps this to its own UPPERCASE wire verdict; it deliberately
48
- * does not leak the wire casing into the shared exec layer.
49
- */
50
- export enum CosignVerifyOutcome {
51
- Verified = 'verified',
52
- Failed = 'failed',
53
- }
54
-
55
- /** Canonical SLSA provenance predicate type. */
56
- export const SLSA_PROVENANCE_PREDICATE_TYPE =
57
- 'https://slsa.dev/provenance/v1' as const;