@countinghouse/ch-local 0.0.0-stage → 1.0.0

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.
Files changed (262) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +361 -2
  3. package/bin/ch-local.js +472 -0
  4. package/clients/claude-code/.claude-plugin/plugin.json +6 -0
  5. package/clients/claude-code/.mcp.json +11 -0
  6. package/clients/claude-code/bin/launch.js +235 -0
  7. package/clients/claude-code/bin/win-acl.js +420 -0
  8. package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
  9. package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
  10. package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
  11. package/lib/allowlist.js +65 -0
  12. package/lib/aside.js +16 -0
  13. package/lib/atomic.js +45 -0
  14. package/lib/auto-apply.js +245 -0
  15. package/lib/auto-upgrade.js +98 -0
  16. package/lib/availability.js +307 -0
  17. package/lib/ceiling.js +280 -0
  18. package/lib/clean-text.js +20 -0
  19. package/lib/cli-change.js +38 -0
  20. package/lib/client-conditions-fixtures.js +143 -0
  21. package/lib/client-conditions.js +656 -0
  22. package/lib/clients.js +179 -0
  23. package/lib/command-line.js +202 -0
  24. package/lib/conditions-command.js +116 -0
  25. package/lib/control.js +134 -0
  26. package/lib/credential-store.js +414 -0
  27. package/lib/credentials-command.js +344 -0
  28. package/lib/daemon-requests.js +137 -0
  29. package/lib/daemon.js +888 -0
  30. package/lib/describe-module.js +137 -0
  31. package/lib/description-check.js +175 -0
  32. package/lib/failed-json.js +43 -0
  33. package/lib/gc.js +274 -0
  34. package/lib/github-token.js +57 -0
  35. package/lib/handoff-io.js +73 -0
  36. package/lib/held-back.js +116 -0
  37. package/lib/hidden-input.js +64 -0
  38. package/lib/history.js +49 -0
  39. package/lib/home.js +372 -0
  40. package/lib/in-place.js +1036 -0
  41. package/lib/install-plan.js +142 -0
  42. package/lib/install.js +846 -0
  43. package/lib/installed-description.js +153 -0
  44. package/lib/integrity.js +7 -0
  45. package/lib/lock.js +456 -0
  46. package/lib/lockfile-rules.js +98 -0
  47. package/lib/machine.js +20 -0
  48. package/lib/module-credentials.js +403 -0
  49. package/lib/module-record.js +298 -0
  50. package/lib/module-roles.js +44 -0
  51. package/lib/module-seams.js +26 -0
  52. package/lib/module-store.js +202 -0
  53. package/lib/module-values.js +334 -0
  54. package/lib/names.js +31 -0
  55. package/lib/next-steps.js +8 -0
  56. package/lib/node-check.js +56 -0
  57. package/lib/npm-fetch.js +123 -0
  58. package/lib/npm-release.js +99 -0
  59. package/lib/npm-upgrade.js +146 -0
  60. package/lib/npm.js +41 -0
  61. package/lib/outside-edits.js +162 -0
  62. package/lib/own-applied.js +175 -0
  63. package/lib/own-command.js +380 -0
  64. package/lib/own-file.js +120 -0
  65. package/lib/own-record.js +96 -0
  66. package/lib/own-tree.js +336 -0
  67. package/lib/pack-table.js +290 -0
  68. package/lib/packs-command.js +570 -0
  69. package/lib/packs.js +219 -0
  70. package/lib/pins.js +64 -0
  71. package/lib/pipe-probe.js +82 -0
  72. package/lib/plain-read.js +63 -0
  73. package/lib/private-file.js +90 -0
  74. package/lib/private-write.js +33 -0
  75. package/lib/provenance.js +234 -0
  76. package/lib/record.js +82 -0
  77. package/lib/registry.js +22 -0
  78. package/lib/release-pins.js +350 -0
  79. package/lib/release-pins.json +4225 -0
  80. package/lib/release-tags.js +12 -0
  81. package/lib/release.js +36 -0
  82. package/lib/restart-command.js +161 -0
  83. package/lib/rollback.js +227 -0
  84. package/lib/run-liveness.js +15 -0
  85. package/lib/runtime-log.js +287 -0
  86. package/lib/sandbox-support.js +17 -0
  87. package/lib/semver-order.js +40 -0
  88. package/lib/session-socket.js +69 -0
  89. package/lib/session-table.js +238 -0
  90. package/lib/session.js +281 -0
  91. package/lib/settings-command.js +82 -0
  92. package/lib/settings.js +564 -0
  93. package/lib/shim-binary.js +152 -0
  94. package/lib/shim-config.js +159 -0
  95. package/lib/shim-install.js +365 -0
  96. package/lib/sigstore/README.md +44 -0
  97. package/lib/sigstore/npm-keys.json +18 -0
  98. package/lib/sigstore/trusted-root.json +126 -0
  99. package/lib/snippets.js +76 -0
  100. package/lib/start.js +721 -0
  101. package/lib/store-files.js +48 -0
  102. package/lib/store-paths.js +33 -0
  103. package/lib/swap-preload.js +38 -0
  104. package/lib/tar.js +220 -0
  105. package/lib/uninstall.js +314 -0
  106. package/lib/unpack.js +41 -0
  107. package/lib/upgrade-stamp.js +63 -0
  108. package/lib/upgrade.js +281 -0
  109. package/lib/watch.js +40 -0
  110. package/lib/win-acl.js +420 -0
  111. package/node_modules/@sigstore/bundle/LICENSE +202 -0
  112. package/node_modules/@sigstore/bundle/README.md +19 -0
  113. package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
  114. package/node_modules/@sigstore/bundle/dist/build.js +100 -0
  115. package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
  116. package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
  117. package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
  118. package/node_modules/@sigstore/bundle/dist/error.js +25 -0
  119. package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
  120. package/node_modules/@sigstore/bundle/dist/index.js +43 -0
  121. package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
  122. package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
  123. package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
  124. package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
  125. package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
  126. package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
  127. package/node_modules/@sigstore/bundle/package.json +35 -0
  128. package/node_modules/@sigstore/core/LICENSE +202 -0
  129. package/node_modules/@sigstore/core/README.md +10 -0
  130. package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
  131. package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
  132. package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
  133. package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
  134. package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
  135. package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
  136. package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
  137. package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
  138. package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
  139. package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
  140. package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
  141. package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
  142. package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
  143. package/node_modules/@sigstore/core/dist/crypto.js +69 -0
  144. package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
  145. package/node_modules/@sigstore/core/dist/dsse.js +29 -0
  146. package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
  147. package/node_modules/@sigstore/core/dist/encoding.js +27 -0
  148. package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
  149. package/node_modules/@sigstore/core/dist/index.js +66 -0
  150. package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
  151. package/node_modules/@sigstore/core/dist/json.js +60 -0
  152. package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
  153. package/node_modules/@sigstore/core/dist/oid.js +20 -0
  154. package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
  155. package/node_modules/@sigstore/core/dist/pem.js +43 -0
  156. package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
  157. package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
  158. package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
  159. package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
  160. package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
  161. package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
  162. package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
  163. package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
  164. package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
  165. package/node_modules/@sigstore/core/dist/stream.js +117 -0
  166. package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
  167. package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
  168. package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
  169. package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
  170. package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
  171. package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
  172. package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
  173. package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
  174. package/node_modules/@sigstore/core/package.json +31 -0
  175. package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
  176. package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
  177. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
  178. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
  179. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
  180. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
  181. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
  182. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
  183. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
  184. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
  185. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
  186. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
  187. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
  188. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
  189. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
  190. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
  191. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
  192. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
  193. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
  194. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
  195. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
  196. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
  197. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
  198. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
  199. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
  200. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
  201. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
  202. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
  203. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
  204. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
  205. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
  206. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
  207. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
  208. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
  209. package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
  210. package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
  211. package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
  212. package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
  213. package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
  214. package/node_modules/@sigstore/verify/README.md +9 -0
  215. package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
  216. package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
  217. package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
  218. package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
  219. package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
  220. package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
  221. package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
  222. package/node_modules/@sigstore/verify/dist/error.js +34 -0
  223. package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
  224. package/node_modules/@sigstore/verify/dist/index.js +28 -0
  225. package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
  226. package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
  227. package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
  228. package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
  229. package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
  230. package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
  231. package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
  232. package/node_modules/@sigstore/verify/dist/policy.js +50 -0
  233. package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
  234. package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
  235. package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
  236. package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
  237. package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
  238. package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
  239. package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
  240. package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
  241. package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
  242. package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
  243. package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
  244. package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
  245. package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
  246. package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
  247. package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
  248. package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
  249. package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
  250. package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
  251. package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
  252. package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
  253. package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
  254. package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
  255. package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
  256. package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
  257. package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
  258. package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
  259. package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
  260. package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
  261. package/node_modules/@sigstore/verify/package.json +36 -0
  262. package/package.json +37 -4
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogCheckpoint = void 0;
4
+ exports.verifyCheckpoint = verifyCheckpoint;
5
+ /*
6
+ Copyright 2025 The Sigstore Authors.
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+ */
20
+ const core_1 = require("@sigstore/core");
21
+ const error_1 = require("../error");
22
+ // Separator between the note and the signatures in a checkpoint
23
+ const CHECKPOINT_SEPARATOR = '\n\n';
24
+ // Checkpoint signatures are of the following form:
25
+ // "– <identity> <key_hint+signature_bytes>\n"
26
+ // where:
27
+ // - the prefix is an emdash (U+2014).
28
+ // - <identity> gives a human-readable representation of the signing ID.
29
+ // - <key_hint+signature_bytes> is the first 4 bytes of the SHA256 hash of the
30
+ // associated public key followed by the signature bytes.
31
+ const SIGNATURE_REGEX = /\u2014 (\S+) (\S+)\n/g;
32
+ // Verifies the checkpoint value in the given tlog entry. There are two steps
33
+ // to the verification:
34
+ // 1. Verify that all signatures in the checkpoint can be verified against a
35
+ // trusted public key
36
+ // 2. Verify that the root hash in the checkpoint matches the root hash in the
37
+ // inclusion proof
38
+ // See: https://github.com/transparency-dev/formats/blob/main/log/README.md
39
+ function verifyCheckpoint(entry, tlogs) {
40
+ const inclusionProof = entry.inclusionProof;
41
+ const signedNote = SignedNote.fromString(inclusionProof.checkpoint.envelope);
42
+ const checkpoint = LogCheckpoint.fromString(signedNote.note);
43
+ // Verify that the signatures in the checkpoint are all valid
44
+ if (!verifySignedNote(signedNote, tlogs)) {
45
+ throw new error_1.VerificationError({
46
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
47
+ message: 'invalid checkpoint signature',
48
+ });
49
+ }
50
+ return checkpoint;
51
+ }
52
+ // Verifies the signatures in the SignedNote. For each signature, the
53
+ // corresponding transparency log is looked up by the key hint and the
54
+ // signature is verified against the public key in the transparency log.
55
+ // Throws an error if any of the signatures are invalid.
56
+ function verifySignedNote(signedNote, tlogs) {
57
+ const data = Buffer.from(signedNote.note, 'utf-8');
58
+ return signedNote.signatures.some((signature) => {
59
+ // Find the transparency log instance with the matching key hint
60
+ const tlog = tlogs.find((tlog) => core_1.crypto.bufferEqual(tlog.logID.subarray(0, 4), signature.keyHint) &&
61
+ tlog.baseURL.match(signature.name) // Match the name to the base URL of the tlog
62
+ );
63
+ if (!tlog) {
64
+ return false;
65
+ }
66
+ return core_1.crypto.verify(data, tlog.publicKey, signature.signature);
67
+ });
68
+ }
69
+ // SignedNote represents a signed note from a transparency log checkpoint. Consists
70
+ // of a body (or note) and one more signatures calculated over the body. See
71
+ // https://github.com/transparency-dev/formats/blob/main/log/README.md#signed-envelope
72
+ class SignedNote {
73
+ note;
74
+ signatures;
75
+ constructor(note, signatures) {
76
+ this.note = note;
77
+ this.signatures = signatures;
78
+ }
79
+ // Deserialize a SignedNote from a string
80
+ static fromString(envelope) {
81
+ if (!envelope.includes(CHECKPOINT_SEPARATOR)) {
82
+ throw new error_1.VerificationError({
83
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
84
+ message: 'missing checkpoint separator',
85
+ });
86
+ }
87
+ // Split the note into the header and the data portions at the separator
88
+ const split = envelope.indexOf(CHECKPOINT_SEPARATOR);
89
+ const header = envelope.slice(0, split + 1);
90
+ const data = envelope.slice(split + CHECKPOINT_SEPARATOR.length);
91
+ // Find all the signature lines in the data portion
92
+ const matches = data.matchAll(SIGNATURE_REGEX);
93
+ // Parse each of the matched signature lines into the name and signature.
94
+ // The first four bytes of the signature are the key hint (should match the
95
+ // first four bytes of the log ID), and the rest is the signature itself.
96
+ const signatures = Array.from(matches, (match) => {
97
+ const [, name, signature] = match;
98
+ const sigBytes = Buffer.from(signature, 'base64');
99
+ if (sigBytes.length < 5) {
100
+ throw new error_1.VerificationError({
101
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
102
+ message: 'malformed checkpoint signature',
103
+ });
104
+ }
105
+ return {
106
+ name,
107
+ keyHint: sigBytes.subarray(0, 4),
108
+ signature: sigBytes.subarray(4),
109
+ };
110
+ });
111
+ if (signatures.length === 0) {
112
+ throw new error_1.VerificationError({
113
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
114
+ message: 'no signatures found in checkpoint',
115
+ });
116
+ }
117
+ return new SignedNote(header, signatures);
118
+ }
119
+ }
120
+ // LogCheckpoint represents a transparency log checkpoint. Consists of the
121
+ // following:
122
+ // - origin: the name of the transparency log
123
+ // - logSize: the size of the log at the time of the checkpoint
124
+ // - logHash: the root hash of the log at the time of the checkpoint
125
+ // - rest: the rest of the checkpoint body, which is a list of log entries
126
+ // See:
127
+ // https://github.com/transparency-dev/formats/blob/main/log/README.md#checkpoint-body
128
+ class LogCheckpoint {
129
+ origin;
130
+ logSize;
131
+ logHash;
132
+ rest;
133
+ constructor(origin, logSize, logHash, rest) {
134
+ this.origin = origin;
135
+ this.logSize = logSize;
136
+ this.logHash = logHash;
137
+ this.rest = rest;
138
+ }
139
+ static fromString(note) {
140
+ const lines = note.trimEnd().split('\n');
141
+ if (lines.length < 3) {
142
+ throw new error_1.VerificationError({
143
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
144
+ message: 'too few lines in checkpoint header',
145
+ });
146
+ }
147
+ const origin = lines[0];
148
+ const logSize = BigInt(lines[1]);
149
+ const rootHash = Buffer.from(lines[2], 'base64');
150
+ const rest = lines.slice(3);
151
+ return new LogCheckpoint(origin, logSize, rootHash, rest);
152
+ }
153
+ }
154
+ exports.LogCheckpoint = LogCheckpoint;
@@ -0,0 +1,6 @@
1
+ import type { Entry } from '@sigstore/protobuf-specs/rekor/v2';
2
+ import type { ProposedDSSEEntry } from '@sigstore/rekor-types';
3
+ import type { SignatureContent } from '../shared.types';
4
+ export declare const DSSE_API_VERSION_V1 = "0.0.1";
5
+ export declare function verifyDSSETLogBody(tlogEntry: ProposedDSSEEntry, content: SignatureContent): void;
6
+ export declare function verifyDSSETLogBodyV2(tlogEntry: Entry, content: SignatureContent): void;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DSSE_API_VERSION_V1 = void 0;
4
+ exports.verifyDSSETLogBody = verifyDSSETLogBody;
5
+ exports.verifyDSSETLogBodyV2 = verifyDSSETLogBodyV2;
6
+ /*
7
+ Copyright 2025 The Sigstore Authors.
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the License is distributed on an "AS IS" BASIS,
17
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ See the License for the specific language governing permissions and
19
+ limitations under the License.
20
+ */
21
+ const error_1 = require("../error");
22
+ exports.DSSE_API_VERSION_V1 = '0.0.1';
23
+ // Compare the given dsse tlog entry to the given bundle
24
+ function verifyDSSETLogBody(tlogEntry, content) {
25
+ switch (tlogEntry.apiVersion) {
26
+ case exports.DSSE_API_VERSION_V1:
27
+ return verifyDSSE001TLogBody(tlogEntry, content);
28
+ default:
29
+ throw new error_1.VerificationError({
30
+ code: 'TLOG_BODY_ERROR',
31
+ message: `unsupported dsse version: ${tlogEntry.apiVersion}`,
32
+ });
33
+ }
34
+ }
35
+ // Compare the given dsse tlog entry to the given bundle. This function is
36
+ // specifically for Rekor V2 entries.
37
+ function verifyDSSETLogBodyV2(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 'dsseV002':
47
+ return verifyDSSE002TLogBody(spec.dsseV002, 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 dsse v0.0.1 tlog entry to the given DSSE envelope.
56
+ function verifyDSSE001TLogBody(tlogEntry, content) {
57
+ // Ensure the bundle's DSSE only contains a single signature
58
+ if (tlogEntry.spec.signatures?.length !== 1) {
59
+ throw new error_1.VerificationError({
60
+ code: 'TLOG_BODY_ERROR',
61
+ message: 'signature count mismatch',
62
+ });
63
+ }
64
+ const tlogSig = tlogEntry.spec.signatures[0].signature;
65
+ // Ensure that the signature in the bundle's DSSE matches tlog entry
66
+ if (!content.compareSignature(Buffer.from(tlogSig, 'base64')))
67
+ throw new error_1.VerificationError({
68
+ code: 'TLOG_BODY_ERROR',
69
+ message: 'tlog entry signature mismatch',
70
+ });
71
+ // Ensure the digest of the bundle's DSSE payload matches the digest in the
72
+ // tlog entry
73
+ const tlogHash = tlogEntry.spec.payloadHash?.value || '';
74
+ if (!content.compareDigest(Buffer.from(tlogHash, 'hex'))) {
75
+ throw new error_1.VerificationError({
76
+ code: 'TLOG_BODY_ERROR',
77
+ message: 'DSSE payload hash mismatch',
78
+ });
79
+ }
80
+ }
81
+ // Compare the given dsse v0.0.2 tlog entry to the given DSSE envelope.
82
+ function verifyDSSE002TLogBody(spec, content) {
83
+ // Ensure the bundle's DSSE only contains a single signature
84
+ if (spec.signatures?.length !== 1) {
85
+ throw new error_1.VerificationError({
86
+ code: 'TLOG_BODY_ERROR',
87
+ message: 'signature count mismatch',
88
+ });
89
+ }
90
+ const tlogSig = spec.signatures[0].content;
91
+ // Ensure that the signature in the bundle's DSSE matches tlog entry
92
+ if (!content.compareSignature(tlogSig))
93
+ throw new error_1.VerificationError({
94
+ code: 'TLOG_BODY_ERROR',
95
+ message: 'tlog entry signature mismatch',
96
+ });
97
+ // Ensure the digest of the bundle's DSSE payload matches the digest in the
98
+ // tlog entry
99
+ const tlogHash = spec.payloadHash?.digest || Buffer.from('');
100
+ if (!content.compareDigest(tlogHash)) {
101
+ throw new error_1.VerificationError({
102
+ code: 'TLOG_BODY_ERROR',
103
+ message: 'DSSE payload hash mismatch',
104
+ });
105
+ }
106
+ }
@@ -0,0 +1,6 @@
1
+ import { Entry } from '@sigstore/protobuf-specs/rekor/v2';
2
+ import type { ProposedHashedRekordEntry } from '@sigstore/rekor-types';
3
+ import type { SignatureContent } from '../shared.types';
4
+ export declare const HASHEDREKORD_API_VERSION_V1 = "0.0.1";
5
+ export declare function verifyHashedRekordTLogBody(tlogEntry: ProposedHashedRekordEntry, content: SignatureContent): void;
6
+ export declare function verifyHashedRekordTLogBodyV2(tlogEntry: Entry, content: SignatureContent): void;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HASHEDREKORD_API_VERSION_V1 = void 0;
4
+ exports.verifyHashedRekordTLogBody = verifyHashedRekordTLogBody;
5
+ exports.verifyHashedRekordTLogBodyV2 = verifyHashedRekordTLogBodyV2;
6
+ /*
7
+ Copyright 2025 The Sigstore Authors.
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the License is distributed on an "AS IS" BASIS,
17
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ See the License for the specific language governing permissions and
19
+ limitations under the License.
20
+ */
21
+ const error_1 = require("../error");
22
+ exports.HASHEDREKORD_API_VERSION_V1 = '0.0.1';
23
+ // Compare the given hashedrekord tlog entry to the given bundle
24
+ function 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.
37
+ function 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
57
+ function 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
77
+ function 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
+ }
@@ -0,0 +1,5 @@
1
+ import type { TransparencyLogEntry } from '@sigstore/bundle';
2
+ import type { SignatureContent } from '../shared.types';
3
+ import { TLogAuthority } from '../trust';
4
+ export declare function verifyTLogBody(entry: TransparencyLogEntry, sigContent: SignatureContent): void;
5
+ export declare function verifyTLogInclusion(entry: TransparencyLogEntry, tlogAuthorities: TLogAuthority[]): void;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyTLogBody = verifyTLogBody;
4
+ exports.verifyTLogInclusion = verifyTLogInclusion;
5
+ /*
6
+ Copyright 2023 The Sigstore Authors.
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+ */
20
+ const v2_1 = require("@sigstore/protobuf-specs/rekor/v2");
21
+ const error_1 = require("../error");
22
+ const dsse_1 = require("./dsse");
23
+ const hashedrekord_1 = require("./hashedrekord");
24
+ const intoto_1 = require("./intoto");
25
+ const checkpoint_1 = require("./checkpoint");
26
+ const merkle_1 = require("./merkle");
27
+ const set_1 = require("./set");
28
+ // Verifies that the given tlog entry matches the supplied signature content.
29
+ function verifyTLogBody(entry, sigContent) {
30
+ const { kind, version } = entry.kindVersion;
31
+ const body = JSON.parse(entry.canonicalizedBody.toString('utf8'));
32
+ // validate body
33
+ if (kind !== body.kind || version !== body.apiVersion) {
34
+ throw new error_1.VerificationError({
35
+ code: 'TLOG_BODY_ERROR',
36
+ message: `kind/version mismatch - expected: ${kind}/${version}, received: ${body.kind}/${body.apiVersion}`,
37
+ });
38
+ }
39
+ switch (kind) {
40
+ case 'dsse':
41
+ // Rekor V1 and V2 use incompatible types so we need to branch here based on version
42
+ if (version == dsse_1.DSSE_API_VERSION_V1) {
43
+ return (0, dsse_1.verifyDSSETLogBody)(body, sigContent);
44
+ }
45
+ else {
46
+ const entryRekorV2 = v2_1.Entry.fromJSON(body);
47
+ return (0, dsse_1.verifyDSSETLogBodyV2)(entryRekorV2, sigContent);
48
+ }
49
+ case 'intoto':
50
+ return (0, intoto_1.verifyIntotoTLogBody)(body, sigContent);
51
+ case 'hashedrekord':
52
+ // Rekor V1 and V2 use incompatible types so we need to branch here based on version
53
+ if (version == hashedrekord_1.HASHEDREKORD_API_VERSION_V1) {
54
+ return (0, hashedrekord_1.verifyHashedRekordTLogBody)(body, sigContent);
55
+ }
56
+ else {
57
+ const entryRekorV2 = v2_1.Entry.fromJSON(body);
58
+ return (0, hashedrekord_1.verifyHashedRekordTLogBodyV2)(entryRekorV2, sigContent);
59
+ }
60
+ /* istanbul ignore next */
61
+ default:
62
+ throw new error_1.VerificationError({
63
+ code: 'TLOG_BODY_ERROR',
64
+ message: `unsupported kind: ${kind}`,
65
+ });
66
+ }
67
+ }
68
+ function verifyTLogInclusion(entry, tlogAuthorities) {
69
+ let inclusionVerified = false;
70
+ if (isTLogEntryWithInclusionPromise(entry)) {
71
+ (0, set_1.verifyTLogSET)(entry, tlogAuthorities);
72
+ inclusionVerified = true;
73
+ }
74
+ if (isTLogEntryWithInclusionProof(entry)) {
75
+ const checkpoint = (0, checkpoint_1.verifyCheckpoint)(entry, tlogAuthorities);
76
+ (0, merkle_1.verifyMerkleInclusion)(entry, checkpoint);
77
+ inclusionVerified = true;
78
+ }
79
+ if (!inclusionVerified) {
80
+ throw new error_1.VerificationError({
81
+ code: 'TLOG_MISSING_INCLUSION_ERROR',
82
+ message: 'inclusion could not be verified',
83
+ });
84
+ }
85
+ return;
86
+ }
87
+ function isTLogEntryWithInclusionPromise(entry) {
88
+ return entry.inclusionPromise !== undefined;
89
+ }
90
+ function isTLogEntryWithInclusionProof(entry) {
91
+ return entry.inclusionProof !== undefined;
92
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProposedIntotoEntry } from '@sigstore/rekor-types';
2
+ import type { SignatureContent } from '../shared.types';
3
+ export declare function verifyIntotoTLogBody(tlogEntry: ProposedIntotoEntry, content: SignatureContent): void;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyIntotoTLogBody = verifyIntotoTLogBody;
4
+ /*
5
+ Copyright 2023 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 error_1 = require("../error");
20
+ // Compare the given intoto tlog entry to the given bundle
21
+ function verifyIntotoTLogBody(tlogEntry, content) {
22
+ switch (tlogEntry.apiVersion) {
23
+ case '0.0.2':
24
+ return verifyIntoto002TLogBody(tlogEntry, content);
25
+ default:
26
+ throw new error_1.VerificationError({
27
+ code: 'TLOG_BODY_ERROR',
28
+ message: `unsupported intoto version: ${tlogEntry.apiVersion}`,
29
+ });
30
+ }
31
+ }
32
+ // Compare the given intoto v0.0.2 tlog entry to the given DSSE envelope.
33
+ function verifyIntoto002TLogBody(tlogEntry, content) {
34
+ // Ensure the bundle's DSSE contains a single signature
35
+ if (tlogEntry.spec.content.envelope.signatures?.length !== 1) {
36
+ throw new error_1.VerificationError({
37
+ code: 'TLOG_BODY_ERROR',
38
+ message: 'signature count mismatch',
39
+ });
40
+ }
41
+ // Signature is double-base64-encoded in the tlog entry
42
+ const tlogSig = base64Decode(tlogEntry.spec.content.envelope.signatures[0].sig);
43
+ // Ensure that the signature in the bundle's DSSE matches tlog entry
44
+ if (!content.compareSignature(Buffer.from(tlogSig, 'base64'))) {
45
+ throw new error_1.VerificationError({
46
+ code: 'TLOG_BODY_ERROR',
47
+ message: 'tlog entry signature mismatch',
48
+ });
49
+ }
50
+ // Ensure the digest of the bundle's DSSE payload matches the digest in the
51
+ // tlog entry
52
+ const tlogHash = tlogEntry.spec.content.payloadHash?.value || '';
53
+ if (!content.compareDigest(Buffer.from(tlogHash, 'hex'))) {
54
+ throw new error_1.VerificationError({
55
+ code: 'TLOG_BODY_ERROR',
56
+ message: 'DSSE payload hash mismatch',
57
+ });
58
+ }
59
+ }
60
+ function base64Decode(str) {
61
+ return Buffer.from(str, 'base64').toString('utf-8');
62
+ }
@@ -0,0 +1,3 @@
1
+ import { LogCheckpoint } from './checkpoint';
2
+ import type { TLogEntryWithInclusionProof } from '@sigstore/bundle';
3
+ export declare function verifyMerkleInclusion(entry: TLogEntryWithInclusionProof, checkpoint: LogCheckpoint): void;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyMerkleInclusion = verifyMerkleInclusion;
4
+ /*
5
+ Copyright 2023 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 core_1 = require("@sigstore/core");
20
+ const error_1 = require("../error");
21
+ const RFC6962_LEAF_HASH_PREFIX = Buffer.from([0x00]);
22
+ const RFC6962_NODE_HASH_PREFIX = Buffer.from([0x01]);
23
+ function verifyMerkleInclusion(entry, checkpoint) {
24
+ const inclusionProof = entry.inclusionProof;
25
+ const logIndex = BigInt(inclusionProof.logIndex);
26
+ const treeSize = BigInt(checkpoint.logSize);
27
+ if (logIndex < 0n || logIndex >= treeSize) {
28
+ throw new error_1.VerificationError({
29
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
30
+ message: `invalid index: ${logIndex}`,
31
+ });
32
+ }
33
+ // Figure out which subset of hashes corresponds to the inner and border
34
+ // nodes
35
+ const { inner, border } = decompInclProof(logIndex, treeSize);
36
+ if (inclusionProof.hashes.length !== inner + border) {
37
+ throw new error_1.VerificationError({
38
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
39
+ message: 'invalid hash count',
40
+ });
41
+ }
42
+ const innerHashes = inclusionProof.hashes.slice(0, inner);
43
+ const borderHashes = inclusionProof.hashes.slice(inner);
44
+ // The entry's hash is the leaf hash
45
+ const leafHash = hashLeaf(entry.canonicalizedBody);
46
+ // Chain the hashes belonging to the inner and border portions
47
+ const calculatedHash = chainBorderRight(chainInner(leafHash, innerHashes, logIndex), borderHashes);
48
+ // Calculated hash should match the root hash in the inclusion proof
49
+ if (!core_1.crypto.bufferEqual(calculatedHash, checkpoint.logHash)) {
50
+ throw new error_1.VerificationError({
51
+ code: 'TLOG_INCLUSION_PROOF_ERROR',
52
+ message: 'calculated root hash does not match inclusion proof',
53
+ });
54
+ }
55
+ }
56
+ // Breaks down inclusion proof for a leaf at the specified index in a tree of
57
+ // the specified size. The split point is where paths to the index leaf and
58
+ // the (size - 1) leaf diverge. Returns lengths of the bottom and upper proof
59
+ // parts.
60
+ function decompInclProof(index, size) {
61
+ const inner = innerProofSize(index, size);
62
+ const border = onesCount(index >> BigInt(inner));
63
+ return { inner, border };
64
+ }
65
+ // Computes a subtree hash for a node on or below the tree's right border.
66
+ // Assumes the provided proof hashes are ordered from lower to higher levels
67
+ // and seed is the initial hash of the node specified by the index.
68
+ function chainInner(seed, hashes, index) {
69
+ return hashes.reduce((acc, h, i) => {
70
+ if ((index >> BigInt(i)) & BigInt(1)) {
71
+ return hashChildren(h, acc);
72
+ }
73
+ else {
74
+ return hashChildren(acc, h);
75
+ }
76
+ }, seed);
77
+ }
78
+ // Computes a subtree hash for nodes along the tree's right border.
79
+ function chainBorderRight(seed, hashes) {
80
+ return hashes.reduce((acc, h) => hashChildren(h, acc), seed);
81
+ }
82
+ function innerProofSize(index, size) {
83
+ return bitLength(index ^ (size - BigInt(1)));
84
+ }
85
+ // Counts the number of ones in the binary representation of the given number.
86
+ // https://en.wikipedia.org/wiki/Hamming_weight
87
+ function onesCount(num) {
88
+ return num.toString(2).split('1').length - 1;
89
+ }
90
+ // Returns the number of bits necessary to represent an integer in binary.
91
+ function bitLength(n) {
92
+ if (n === 0n) {
93
+ return 0;
94
+ }
95
+ return n.toString(2).length;
96
+ }
97
+ // Hashing logic according to RFC6962.
98
+ // https://datatracker.ietf.org/doc/html/rfc6962#section-2
99
+ function hashChildren(left, right) {
100
+ return core_1.crypto.digest('sha256', RFC6962_NODE_HASH_PREFIX, left, right);
101
+ }
102
+ function hashLeaf(leaf) {
103
+ return core_1.crypto.digest('sha256', RFC6962_LEAF_HASH_PREFIX, leaf);
104
+ }
@@ -0,0 +1,3 @@
1
+ import { TLogAuthority } from '../trust';
2
+ import type { TLogEntryWithInclusionPromise } from '@sigstore/bundle';
3
+ export declare function verifyTLogSET(entry: TLogEntryWithInclusionPromise, tlogs: TLogAuthority[]): void;