Debian Codegraph @

node_modules/@sigstore/sign/dist/witness/tlog/index.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.RekorWitness = exports.DEFAULT_REKOR_URL = void 0;
4 /*
5 Copyright 2025 The Sigstore Authors.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 */
19 const util_1 = require("../../util");
20 const client_1 = require("./client");
21 const entry_1 = require("./entry");
22 exports.DEFAULT_REKOR_URL = 'https://rekor.sigstore.dev';
23 class RekorWitness {
24 tlogV1;
25 tlogV2;
26 entryType;
27 majorApiVersion;
28 constructor(options) {
29 this.entryType = options.entryType;
30 this.majorApiVersion = options.majorApiVersion || 1;
31 this.tlogV1 = new client_1.TLogClient({
32 ...options,
33 rekorBaseURL: options.rekorBaseURL || /* istanbul ignore next */ exports.DEFAULT_REKOR_URL,
34 });
35 this.tlogV2 = new client_1.TLogV2Client({
36 ...options,
37 rekorBaseURL: options.rekorBaseURL || /* istanbul ignore next */ exports.DEFAULT_REKOR_URL,
38 });
39 }
40 async testify(content, publicKey) {
41 let tlogEntry;
42 if (this.majorApiVersion === 2) {
43 const request = (0, entry_1.toCreateEntryRequest)(content, publicKey);
44 tlogEntry = await this.tlogV2.createEntry(request);
45 }
46 else {
47 const proposedEntry = (0, entry_1.toProposedEntry)(content, publicKey, this.entryType);
48 const entry = await this.tlogV1.createEntry(proposedEntry);
49 tlogEntry = toTransparencyLogEntry(entry);
50 }
51 return { tlogEntries: [tlogEntry] };
52 }
53 }
54 exports.RekorWitness = RekorWitness;
55 function toTransparencyLogEntry(entry) {
56 const logID = Buffer.from(entry.logID, 'hex');
57 // Parse entry body so we can extract the kind and version.
58 const bodyJSON = util_1.encoding.base64Decode(entry.body);
59 const entryBody = JSON.parse(bodyJSON);
60 const promise = entry?.verification?.signedEntryTimestamp
61 ? inclusionPromise(entry.verification.signedEntryTimestamp)
62 : undefined;
63 const proof = entry?.verification?.inclusionProof
64 ? inclusionProof(entry.verification.inclusionProof)
65 : undefined;
66 const tlogEntry = {
67 logIndex: entry.logIndex.toString(),
68 logId: {
69 keyId: logID,
70 },
71 integratedTime: entry.integratedTime.toString(),
72 kindVersion: {
73 kind: entryBody.kind,
74 version: entryBody.apiVersion,
75 },
76 inclusionPromise: promise,
77 inclusionProof: proof,
78 canonicalizedBody: Buffer.from(entry.body, 'base64'),
79 };
80 return tlogEntry;
81 }
82 function inclusionPromise(promise) {
83 return {
84 signedEntryTimestamp: Buffer.from(promise, 'base64'),
85 };
86 }
87 function inclusionProof(proof) {
88 return {
89 logIndex: proof.logIndex.toString(),
90 treeSize: proof.treeSize.toString(),
91 rootHash: Buffer.from(proof.rootHash, 'hex'),
92 hashes: proof.hashes.map((h) => Buffer.from(h, 'hex')),
93 checkpoint: {
94 envelope: proof.checkpoint,
95 },
96 };
97 }