Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
hashedrekord.js95 linesDownload Raw Back to tlog
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.HASHEDREKORD_API_VERSION_V1 = void 0;
4exports.verifyHashedRekordTLogBody = verifyHashedRekordTLogBody;
5exports.verifyHashedRekordTLogBodyV2 = verifyHashedRekordTLogBodyV2;
6/*
7Copyright 2025 The Sigstore Authors.
8
9Licensed under the Apache License, Version 2.0 (the "License");
10you may not use this file except in compliance with the License.
11You may obtain a copy of the License at
12
13    http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing, software
16distributed under the License is distributed on an "AS IS" BASIS,
17WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18See the License for the specific language governing permissions and
19limitations under the License.
20*/
21const error_1 = require("../error");
22exports.HASHEDREKORD_API_VERSION_V1 = '0.0.1';
23// Compare the given hashedrekord tlog entry to the given bundle
24function verifyHashedRekordTLogBody(tlogEntry, content) {
25    switch (tlogEntry.apiVersion) {
26        case exports.HASHEDREKORD_API_VERSION_V1:
27            return verifyHashedrekord001TLogBody(tlogEntry, content);
28        default:
29            throw new error_1.VerificationError({
30                code: 'TLOG_BODY_ERROR',
31                message: `unsupported hashedrekord version: ${tlogEntry.apiVersion}`,
32            });
33    }
34}
35// Compare the given hashedrekor tlog entry to the given bundle. This function is
36// specifically for Rekor V2 entries.
37function verifyHashedRekordTLogBodyV2(tlogEntry, content) {
38    const spec = tlogEntry.spec?.spec;
39    if (!spec) {
40        throw new error_1.VerificationError({
41            code: 'TLOG_BODY_ERROR',
42            message: `missing dsse spec`,
43        });
44    }
45    switch (spec.$case) {
46        case 'hashedRekordV002':
47            return verifyHashedrekord002TLogBody(spec.hashedRekordV002, content);
48        default:
49            throw new error_1.VerificationError({
50                code: 'TLOG_BODY_ERROR',
51                message: `unsupported version: ${spec.$case}`,
52            });
53    }
54}
55// Compare the given hashedrekord v0.0.1 tlog entry to the given message
56// signature
57function verifyHashedrekord001TLogBody(tlogEntry, content) {
58    // Ensure that the bundles message signature matches the tlog entry
59    const tlogSig = tlogEntry.spec.signature.content || '';
60    if (!content.compareSignature(Buffer.from(tlogSig, 'base64'))) {
61        throw new error_1.VerificationError({
62            code: 'TLOG_BODY_ERROR',
63            message: 'signature mismatch',
64        });
65    }
66    // Ensure that the bundle's message digest matches the tlog entry
67    const tlogDigest = tlogEntry.spec.data.hash?.value || '';
68    if (!content.compareDigest(Buffer.from(tlogDigest, 'hex'))) {
69        throw new error_1.VerificationError({
70            code: 'TLOG_BODY_ERROR',
71            message: 'digest mismatch',
72        });
73    }
74}
75// Compare the given hashedrekord v0.0.2 tlog entry to the given message
76// signature
77function verifyHashedrekord002TLogBody(spec, content) {
78    // Ensure that the bundles message signature matches the tlog entry
79    const tlogSig = spec.signature?.content || Buffer.from('');
80    if (!content.compareSignature(tlogSig)) {
81        throw new error_1.VerificationError({
82            code: 'TLOG_BODY_ERROR',
83            message: 'signature mismatch',
84        });
85    }
86    // Ensure that the bundle's message digest matches the tlog entry
87    const tlogHash = spec.data?.digest || Buffer.from('');
88    if (!content.compareDigest(tlogHash)) {
89        throw new error_1.VerificationError({
90            code: 'TLOG_BODY_ERROR',
91            message: 'digest mismatch',
92        });
93    }
94}
95 
codekingpro/portable-devtools · Team Ai