mirror of
https://github.com/actions/attest-build-provenance.git
synced 2025-12-14 03:12:20 +00:00
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.generateSBOMPredicate = void 0;
|
|
const generateSBOMPredicate = (sbom) => {
|
|
if (sbom.type === 'spdx') {
|
|
return generateSPDXIntoto(sbom.object);
|
|
}
|
|
if (sbom.type === 'cyclonedx') {
|
|
return generateCycloneDXIntoto(sbom.object);
|
|
}
|
|
throw new Error('Unsupported SBOM format');
|
|
};
|
|
exports.generateSBOMPredicate = generateSBOMPredicate;
|
|
// ref: https://github.com/in-toto/attestation/blob/main/spec/predicates/spdx.md
|
|
const generateSPDXIntoto = (sbom) => {
|
|
const spdxVersion = sbom?.['spdxVersion'];
|
|
if (!spdxVersion) {
|
|
throw new Error('Cannot find spdxVersion in the SBOM');
|
|
}
|
|
const version = spdxVersion.split('-')[1];
|
|
return {
|
|
type: `https://spdx.dev/Document/v${version}`,
|
|
params: sbom
|
|
};
|
|
};
|
|
// ref: https://github.com/in-toto/attestation/blob/main/spec/predicates/cyclonedx.md
|
|
const generateCycloneDXIntoto = (sbom) => {
|
|
return {
|
|
type: 'https://cyclonedx.org/bom',
|
|
params: sbom
|
|
};
|
|
};
|