@intentius/chant 0.124.86 → 0.124.88

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 (384) hide show
  1. package/dist/action-pins.d.ts +1 -0
  2. package/dist/action-pins.d.ts.map +1 -1
  3. package/dist/action-pins.js +2 -0
  4. package/dist/actor.d.ts +12 -0
  5. package/dist/actor.d.ts.map +1 -0
  6. package/dist/actor.js +18 -0
  7. package/dist/bundle-check.d.ts +20 -5
  8. package/dist/bundle-check.d.ts.map +1 -1
  9. package/dist/bundle-check.js +20 -5
  10. package/dist/chant-install.d.ts +98 -0
  11. package/dist/chant-install.d.ts.map +1 -1
  12. package/dist/chant-install.js +204 -2
  13. package/dist/ci-commit.d.ts.map +1 -1
  14. package/dist/ci-commit.js +1 -2
  15. package/dist/ci-control.d.ts +1 -1
  16. package/dist/ci-control.d.ts.map +1 -1
  17. package/dist/ci-control.js +1 -1
  18. package/dist/ci-evidence-claims.d.ts +59 -0
  19. package/dist/ci-evidence-claims.d.ts.map +1 -0
  20. package/dist/ci-evidence-claims.js +87 -0
  21. package/dist/ci-evidence-from-job.d.ts +103 -0
  22. package/dist/ci-evidence-from-job.d.ts.map +1 -0
  23. package/dist/ci-evidence-from-job.js +162 -0
  24. package/dist/ci-evidence-jobs.d.ts +69 -10
  25. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  26. package/dist/ci-evidence-jobs.js +72 -8
  27. package/dist/ci-handover.d.ts +12 -0
  28. package/dist/ci-handover.d.ts.map +1 -1
  29. package/dist/ci-handover.js +15 -3
  30. package/dist/ci-identity.d.ts +32 -6
  31. package/dist/ci-identity.d.ts.map +1 -1
  32. package/dist/ci-identity.js +40 -8
  33. package/dist/ci-image.d.ts +47 -9
  34. package/dist/ci-image.d.ts.map +1 -1
  35. package/dist/ci-image.js +45 -18
  36. package/dist/ci-jobs.d.ts +1 -1
  37. package/dist/ci-jobs.d.ts.map +1 -1
  38. package/dist/ci-jobs.js +7 -2
  39. package/dist/ci-login.d.ts +75 -13
  40. package/dist/ci-login.d.ts.map +1 -1
  41. package/dist/ci-login.js +89 -37
  42. package/dist/ci-product-words.d.ts +20 -1
  43. package/dist/ci-product-words.d.ts.map +1 -1
  44. package/dist/ci-product-words.js +27 -1
  45. package/dist/ci-product.d.ts +20 -1
  46. package/dist/ci-product.d.ts.map +1 -1
  47. package/dist/ci-product.js +21 -2
  48. package/dist/cli/handlers/approve-confirm.d.ts +14 -0
  49. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
  50. package/dist/cli/handlers/approve-confirm.js +46 -0
  51. package/dist/cli/handlers/build.d.ts +1 -1
  52. package/dist/cli/handlers/build.d.ts.map +1 -1
  53. package/dist/cli/handlers/build.js +22 -1
  54. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  55. package/dist/cli/handlers/ci-check.js +38 -14
  56. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  57. package/dist/cli/handlers/ci-evidence.js +238 -26
  58. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
  59. package/dist/cli/handlers/ci-forge-check.js +34 -17
  60. package/dist/cli/handlers/generated-check.d.ts +3 -0
  61. package/dist/cli/handlers/generated-check.d.ts.map +1 -0
  62. package/dist/cli/handlers/generated-check.js +41 -0
  63. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  64. package/dist/cli/handlers/lifecycle.js +3 -0
  65. package/dist/cli/handlers/local-chant.d.ts +13 -0
  66. package/dist/cli/handlers/local-chant.d.ts.map +1 -1
  67. package/dist/cli/handlers/local-chant.js +42 -1
  68. package/dist/cli/handlers/pr.d.ts.map +1 -1
  69. package/dist/cli/handlers/pr.js +42 -5
  70. package/dist/cli/handlers/run-wave.js +8 -0
  71. package/dist/cli/main.d.ts.map +1 -1
  72. package/dist/cli/main.js +38 -4
  73. package/dist/cli/parse-args.d.ts.map +1 -1
  74. package/dist/cli/parse-args.js +66 -0
  75. package/dist/cli/registry.d.ts +24 -0
  76. package/dist/cli/registry.d.ts.map +1 -1
  77. package/dist/components/check-hooks.d.ts +10 -0
  78. package/dist/components/check-hooks.d.ts.map +1 -1
  79. package/dist/components/check-hooks.js +21 -3
  80. package/dist/components/check-steps.js +1 -1
  81. package/dist/components/pr-checks.d.ts +105 -0
  82. package/dist/components/pr-checks.d.ts.map +1 -0
  83. package/dist/components/pr-checks.js +119 -0
  84. package/dist/components/pr-pipeline.d.ts +34 -0
  85. package/dist/components/pr-pipeline.d.ts.map +1 -1
  86. package/dist/components/pr-pipeline.js +14 -1
  87. package/dist/components/product-pipeline.d.ts +16 -1
  88. package/dist/components/product-pipeline.d.ts.map +1 -1
  89. package/dist/components/product-pipeline.js +17 -2
  90. package/dist/components/product-plan.d.ts +262 -3
  91. package/dist/components/product-plan.d.ts.map +1 -1
  92. package/dist/components/product-plan.js +243 -11
  93. package/dist/config.d.ts +10 -6
  94. package/dist/config.d.ts.map +1 -1
  95. package/dist/config.js +11 -6
  96. package/dist/control/consumers.d.ts +6 -0
  97. package/dist/control/consumers.d.ts.map +1 -1
  98. package/dist/control/consumers.js +6 -0
  99. package/dist/dead-guards.d.ts.map +1 -1
  100. package/dist/dead-guards.js +9 -6
  101. package/dist/discovery/files.d.ts +1 -1
  102. package/dist/discovery/files.js +1 -1
  103. package/dist/drift-issue.d.ts +20 -3
  104. package/dist/drift-issue.d.ts.map +1 -1
  105. package/dist/drift-issue.js +16 -0
  106. package/dist/drift-record.d.ts +45 -5
  107. package/dist/drift-record.d.ts.map +1 -1
  108. package/dist/drift-record.js +27 -6
  109. package/dist/floor-table.d.ts +6 -6
  110. package/dist/floor-table.d.ts.map +1 -1
  111. package/dist/floor-table.data.d.ts.map +1 -1
  112. package/dist/floor-table.data.js +58 -20
  113. package/dist/floor-table.js +10 -7
  114. package/dist/forge-check/contract.d.ts +8 -0
  115. package/dist/forge-check/contract.d.ts.map +1 -1
  116. package/dist/forge-check/contract.js +4 -1
  117. package/dist/forge-check/index.d.ts +2 -0
  118. package/dist/forge-check/index.d.ts.map +1 -1
  119. package/dist/forge-check/index.js +2 -0
  120. package/dist/forge-flags.d.ts +10 -0
  121. package/dist/forge-flags.d.ts.map +1 -1
  122. package/dist/forge-flags.js +31 -0
  123. package/dist/forge-remote.d.ts +47 -0
  124. package/dist/forge-remote.d.ts.map +1 -0
  125. package/dist/forge-remote.js +69 -0
  126. package/dist/generated-check.d.ts +74 -0
  127. package/dist/generated-check.d.ts.map +1 -0
  128. package/dist/generated-check.js +216 -0
  129. package/dist/lexicon.d.ts +16 -0
  130. package/dist/lexicon.d.ts.map +1 -1
  131. package/dist/lifecycle/publish-npm.d.ts +15 -0
  132. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  133. package/dist/lifecycle/publish-npm.js +49 -3
  134. package/dist/lifecycle/release-images.d.ts +22 -1
  135. package/dist/lifecycle/release-images.d.ts.map +1 -1
  136. package/dist/lifecycle/release-images.js +27 -3
  137. package/dist/lifecycle/release-ledger.d.ts +4 -3
  138. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  139. package/dist/lifecycle/release-ledger.js +3 -2
  140. package/dist/local-chant.d.ts +57 -3
  141. package/dist/local-chant.d.ts.map +1 -1
  142. package/dist/local-chant.js +122 -13
  143. package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
  144. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
  145. package/dist/op/op-waves-evidence-jobs.js +112 -0
  146. package/dist/op/op-waves-evidence.d.ts +17 -4
  147. package/dist/op/op-waves-evidence.d.ts.map +1 -1
  148. package/dist/op/op-waves-evidence.js +32 -10
  149. package/dist/op/op-waves-run.d.ts +12 -1
  150. package/dist/op/op-waves-run.d.ts.map +1 -1
  151. package/dist/op/op-waves-run.js +54 -3
  152. package/dist/op/op-waves.d.ts +8 -0
  153. package/dist/op/op-waves.d.ts.map +1 -1
  154. package/dist/op/op-waves.js +10 -0
  155. package/dist/op/schedule-overdue.d.ts +39 -2
  156. package/dist/op/schedule-overdue.d.ts.map +1 -1
  157. package/dist/op/schedule-overdue.js +89 -7
  158. package/dist/pr-forge-reads.d.ts +21 -1
  159. package/dist/pr-forge-reads.d.ts.map +1 -1
  160. package/dist/pr-forge-reads.js +19 -1
  161. package/dist/pr-forge.d.ts +7 -1
  162. package/dist/pr-forge.d.ts.map +1 -1
  163. package/dist/pr-forge.js +7 -2
  164. package/dist/pr-plan-note.d.ts +24 -0
  165. package/dist/pr-plan-note.d.ts.map +1 -1
  166. package/dist/pr-plan-note.js +11 -1
  167. package/dist/pr-plan-record.d.ts +47 -0
  168. package/dist/pr-plan-record.d.ts.map +1 -0
  169. package/dist/pr-plan-record.js +89 -0
  170. package/dist/pr-post.d.ts +40 -0
  171. package/dist/pr-post.d.ts.map +1 -1
  172. package/dist/pr-post.js +79 -6
  173. package/dist/pr-requires.d.ts +8 -0
  174. package/dist/pr-requires.d.ts.map +1 -1
  175. package/dist/pr-requires.js +3 -1
  176. package/dist/ref-gate-init.d.ts +76 -0
  177. package/dist/ref-gate-init.d.ts.map +1 -0
  178. package/dist/ref-gate-init.js +144 -0
  179. package/dist/ref-gate-rules.d.ts +19 -0
  180. package/dist/ref-gate-rules.d.ts.map +1 -0
  181. package/dist/ref-gate-rules.js +17 -0
  182. package/dist/release-floors.d.ts +51 -1
  183. package/dist/release-floors.d.ts.map +1 -1
  184. package/dist/release-floors.js +66 -16
  185. package/dist/state-migration.d.ts +23 -0
  186. package/dist/state-migration.d.ts.map +1 -1
  187. package/dist/state-migration.js +39 -3
  188. package/dist/state-unlock.d.ts +32 -1
  189. package/dist/state-unlock.d.ts.map +1 -1
  190. package/dist/state-unlock.js +31 -0
  191. package/dist/wave-runtime.mjs +310 -303
  192. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  193. package/dist/workspace/ci-green-cli.js +13 -7
  194. package/dist/workspace/ci-green.d.ts.map +1 -1
  195. package/dist/workspace/ci-green.js +4 -3
  196. package/dist/workspace/drift-cli.d.ts +1 -1
  197. package/dist/workspace/drift-cli.d.ts.map +1 -1
  198. package/dist/workspace/drift-cli.js +5 -12
  199. package/dist/workspace/forge-work.d.ts +3 -2
  200. package/dist/workspace/forge-work.d.ts.map +1 -1
  201. package/dist/workspace/forge-work.js +7 -17
  202. package/dist/workspace/lexicon-outputs.js +2 -2
  203. package/dist/workspace/release-workflow.d.ts +26 -3
  204. package/dist/workspace/release-workflow.d.ts.map +1 -1
  205. package/dist/workspace/release-workflow.js +48 -6
  206. package/dist/workspace/trust/check-evidence-report.d.ts +25 -0
  207. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  208. package/dist/workspace/trust/check-evidence-report.js +20 -0
  209. package/dist/workspace/trust/check-evidence.d.ts +59 -13
  210. package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
  211. package/dist/workspace/trust/check-evidence.js +101 -24
  212. package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
  213. package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
  214. package/dist/workspace/trust/dsse.d.ts +40 -2
  215. package/dist/workspace/trust/dsse.d.ts.map +1 -1
  216. package/dist/workspace/trust/dsse.js +34 -2
  217. package/dist/workspace/trust/evidence.d.ts +7 -2
  218. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  219. package/dist/workspace/trust/evidence.js +5 -0
  220. package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
  221. package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
  222. package/dist/workspace/trust/keyless-fixture.js +161 -0
  223. package/dist/workspace/trust/keyless.d.ts +202 -0
  224. package/dist/workspace/trust/keyless.d.ts.map +1 -0
  225. package/dist/workspace/trust/keyless.js +488 -0
  226. package/dist/workspace/trust/local-evidence.d.ts +3 -0
  227. package/dist/workspace/trust/local-evidence.d.ts.map +1 -1
  228. package/dist/workspace/trust/op-run-statement.d.ts +2 -2
  229. package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
  230. package/dist/workspace/trust/open-evidence.d.ts +67 -0
  231. package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
  232. package/dist/workspace/trust/open-evidence.js +92 -0
  233. package/dist/workspace/trust/policy.d.ts +56 -1
  234. package/dist/workspace/trust/policy.d.ts.map +1 -1
  235. package/dist/workspace/trust/policy.js +103 -2
  236. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  237. package/dist/workspace/trust/ref-gate-cli.js +65 -3
  238. package/dist/workspace/trust/ref-gate.d.ts +62 -3
  239. package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
  240. package/dist/workspace/trust/ref-gate.js +75 -8
  241. package/dist/workspace/trust/run-statement.d.ts +3 -3
  242. package/dist/workspace/trust/run-statement.d.ts.map +1 -1
  243. package/dist/workspace/trust/runner-identity.d.ts +56 -0
  244. package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
  245. package/dist/workspace/trust/runner-identity.js +65 -0
  246. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  247. package/dist/workspace/trust/trust-files.js +8 -1
  248. package/package.json +1 -1
  249. package/src/action-pins.ts +2 -0
  250. package/src/actor.test.ts +12 -0
  251. package/src/actor.ts +19 -0
  252. package/src/bundle-check.test.ts +22 -0
  253. package/src/bundle-check.ts +33 -5
  254. package/src/chant-install.test.ts +109 -1
  255. package/src/chant-install.ts +243 -2
  256. package/src/ci-commit.test.ts +51 -5
  257. package/src/ci-commit.ts +1 -2
  258. package/src/ci-control.ts +1 -0
  259. package/src/ci-evidence-claims.ts +102 -0
  260. package/src/ci-evidence-from-job.test.ts +147 -0
  261. package/src/ci-evidence-from-job.ts +195 -0
  262. package/src/ci-evidence-jobs.ts +85 -10
  263. package/src/ci-handover.ts +16 -3
  264. package/src/ci-identity.test.ts +3 -3
  265. package/src/ci-identity.ts +51 -11
  266. package/src/ci-image.test.ts +60 -10
  267. package/src/ci-image.ts +78 -19
  268. package/src/ci-jobs.ts +7 -2
  269. package/src/ci-login.test.ts +131 -3
  270. package/src/ci-login.token-drop.test.ts +204 -0
  271. package/src/ci-login.ts +137 -39
  272. package/src/ci-product-words.ts +30 -0
  273. package/src/ci-product.ts +26 -1
  274. package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
  275. package/src/cli/handlers/approve-confirm.test.ts +35 -0
  276. package/src/cli/handlers/approve-confirm.ts +44 -0
  277. package/src/cli/handlers/build-source-dir.test.ts +4 -0
  278. package/src/cli/handlers/build.ts +20 -2
  279. package/src/cli/handlers/ci-check.ts +35 -13
  280. package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
  281. package/src/cli/handlers/ci-evidence.ts +223 -24
  282. package/src/cli/handlers/ci-forge-check.ts +22 -9
  283. package/src/cli/handlers/generated-check.ts +39 -0
  284. package/src/cli/handlers/lifecycle.test.ts +20 -0
  285. package/src/cli/handlers/lifecycle.ts +4 -0
  286. package/src/cli/handlers/local-chant.ts +39 -1
  287. package/src/cli/handlers/pr.ts +43 -5
  288. package/src/cli/handlers/run-wave.ts +7 -0
  289. package/src/cli/main.ts +38 -4
  290. package/src/cli/parse-args.ts +46 -0
  291. package/src/cli/registry.ts +24 -0
  292. package/src/components/check-hooks.ts +25 -3
  293. package/src/components/check-report-summary.test.ts +78 -0
  294. package/src/components/check-steps.ts +1 -1
  295. package/src/components/pr-checks.ts +159 -0
  296. package/src/components/pr-pipeline.ts +41 -1
  297. package/src/components/product-pipeline.ts +25 -3
  298. package/src/components/product-plan.test.ts +102 -1
  299. package/src/components/product-plan.ts +419 -14
  300. package/src/config.ts +13 -8
  301. package/src/control/consumers.ts +7 -0
  302. package/src/dead-guards.test.ts +27 -5
  303. package/src/dead-guards.ts +9 -6
  304. package/src/discovery/files.ts +1 -1
  305. package/src/drift-issue.test.ts +29 -1
  306. package/src/drift-issue.ts +28 -3
  307. package/src/drift-record.test.ts +25 -0
  308. package/src/drift-record.ts +55 -6
  309. package/src/floor-table.data.ts +58 -20
  310. package/src/floor-table.ts +12 -9
  311. package/src/forge-check/contract.ts +11 -1
  312. package/src/forge-check/forge-check.test.ts +8 -0
  313. package/src/forge-check/index.ts +2 -0
  314. package/src/forge-flags.test.ts +25 -1
  315. package/src/forge-flags.ts +34 -0
  316. package/src/forge-remote.test.ts +37 -0
  317. package/src/forge-remote.ts +79 -0
  318. package/src/generated-check.e2e.test.ts +98 -0
  319. package/src/generated-check.test.ts +104 -0
  320. package/src/generated-check.ts +269 -0
  321. package/src/lexicon.ts +17 -0
  322. package/src/lifecycle/publish-npm.ts +56 -3
  323. package/src/lifecycle/release-catalog.test.ts +2 -2
  324. package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
  325. package/src/lifecycle/release-images.test.ts +44 -0
  326. package/src/lifecycle/release-images.ts +39 -3
  327. package/src/lifecycle/release-ledger.ts +4 -3
  328. package/src/local-chant.e2e.test.ts +81 -6
  329. package/src/local-chant.test.ts +22 -3
  330. package/src/local-chant.ts +130 -13
  331. package/src/op/op-waves-evidence-jobs.ts +134 -0
  332. package/src/op/op-waves-evidence.test.ts +37 -4
  333. package/src/op/op-waves-evidence.ts +32 -11
  334. package/src/op/op-waves-run.ts +57 -2
  335. package/src/op/op-waves.ts +11 -0
  336. package/src/op/schedule-overdue.test.ts +83 -1
  337. package/src/op/schedule-overdue.ts +107 -9
  338. package/src/pr-forge-reads-compare.test.ts +2 -1
  339. package/src/pr-forge-reads.ts +37 -1
  340. package/src/pr-forge.ts +14 -3
  341. package/src/pr-plan-note.ts +32 -3
  342. package/src/pr-plan-record.test.ts +75 -0
  343. package/src/pr-plan-record.ts +101 -0
  344. package/src/pr-post-plan-note.test.ts +60 -0
  345. package/src/pr-post.test.ts +30 -0
  346. package/src/pr-post.ts +110 -6
  347. package/src/pr-requires.test.ts +20 -0
  348. package/src/pr-requires.ts +10 -1
  349. package/src/ref-gate-init.ts +189 -0
  350. package/src/ref-gate-rules.ts +26 -0
  351. package/src/release-floors.ts +88 -16
  352. package/src/state-migration-record.test.ts +90 -0
  353. package/src/state-migration.test.ts +1 -1
  354. package/src/state-migration.ts +52 -3
  355. package/src/state-unlock.test.ts +33 -1
  356. package/src/state-unlock.ts +49 -1
  357. package/src/workspace/ci-green-cli.ts +12 -6
  358. package/src/workspace/ci-green.ts +4 -3
  359. package/src/workspace/drift-cli.ts +6 -18
  360. package/src/workspace/forge-work.ts +7 -14
  361. package/src/workspace/lexicon-outputs.ts +2 -2
  362. package/src/workspace/release-workflow.test.ts +70 -0
  363. package/src/workspace/release-workflow.ts +56 -8
  364. package/src/workspace/trust/check-evidence-report.ts +33 -0
  365. package/src/workspace/trust/check-evidence.test.ts +3 -3
  366. package/src/workspace/trust/check-evidence.ts +110 -28
  367. package/src/workspace/trust/ci-tag-statement.ts +2 -2
  368. package/src/workspace/trust/dsse.ts +48 -4
  369. package/src/workspace/trust/evidence.ts +7 -2
  370. package/src/workspace/trust/keyless-fixture.ts +214 -0
  371. package/src/workspace/trust/keyless.test.ts +220 -0
  372. package/src/workspace/trust/keyless.ts +557 -0
  373. package/src/workspace/trust/local-evidence.ts +3 -1
  374. package/src/workspace/trust/op-run-statement.ts +2 -2
  375. package/src/workspace/trust/open-evidence.ts +129 -0
  376. package/src/workspace/trust/policy.ts +129 -2
  377. package/src/workspace/trust/ref-gate-cli.ts +59 -3
  378. package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
  379. package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
  380. package/src/workspace/trust/ref-gate.ts +90 -8
  381. package/src/workspace/trust/run-statement.ts +3 -3
  382. package/src/workspace/trust/runner-identity.ts +92 -0
  383. package/src/workspace/trust/trust-files.test.ts +6 -0
  384. package/src/workspace/trust/trust-files.ts +14 -1
@@ -18,26 +18,31 @@
18
18
  *
19
19
  * Who signs is an {@link EvidenceSigner}: today a runner key the policy at
20
20
  * base lists ({@link runnerKeyEvidenceSigner}, the key `CHANT_RUNNER_KEY`
21
- * holds, as for the tick's tags and the run records). #4869 adds a signer
22
- * that trades the job's OIDC token for a short-lived certificate and returns
23
- * the same envelope with the certificate in it; nothing that calls a signer
24
- * changes.
21
+ * holds, as for the tick's tags and the run records), or the job's OIDC
22
+ * identity ({@link keylessEvidenceSigner}, #4869), which trades the job's
23
+ * token for a short-lived certificate and returns the same envelope with
24
+ * the certificate and a timestamp in it. {@link runnerEvidenceSigner} picks
25
+ * one from the job's environment, the one place every signing step reads.
25
26
  *
26
27
  * Reading ({@link readCheckEvidence}) verifies each envelope against the
27
- * runner keys of `.chant/trust.json` at base, so evidence a change signs
28
- * with a key it adds itself does not count until that key is merged.
28
+ * runner keys and keyless identities of `.chant/trust.json` at base, so
29
+ * evidence a change signs with a key or identity it adds itself does not
30
+ * count until that is merged.
29
31
  */
30
32
 
31
33
  import { execFileSync } from "node:child_process";
32
34
  import { createHash } from "node:crypto";
33
35
  import { canonicalJson } from "../../effect-receipt";
34
36
  import { gitRevisionSource } from "../record-source";
35
- import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, signEnvelope, type DsseEnvelope } from "./dsse";
37
+ import { X509Certificate } from "node:crypto";
38
+ import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, pae, signEnvelope, type DsseEnvelope } from "./dsse";
36
39
  import { RUNNER_EVIDENCE_PREDICATE, STATEMENT_TYPE, verifyEvidence, type EvidenceStatement } from "./evidence";
37
- import { readTrustPolicy } from "./policy";
40
+ import { certificateIssuer, certificateSubjects, keylessSignature, requestCertificate, signingToken, subjectPattern, verifyKeylessSignature } from "./keyless";
41
+ import { readTrustPolicy, runnersAt } from "./policy";
38
42
  import { attachEvidence, EVIDENCE_NOTES_REF, parseEvidenceNote } from "./ref-gate";
43
+ import { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV } from "./check-evidence-report";
39
44
 
40
- export { CHECK_EVIDENCE_KEY_ENV } from "./check-evidence-report";
45
+ export { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV };
41
46
 
42
47
  export { EVIDENCE_NOTES_REF };
43
48
 
@@ -46,13 +51,79 @@ export const PLAN_EVIDENCE_CHECKS = ["plan", "policy"] as const;
46
51
 
47
52
  /**
48
53
  * Who signs a check's statement (#4870). `sign` returns the DSSE envelope
49
- * of the in-toto payload it is given. The seam #4869's keyless signer plugs
50
- * into.
54
+ * of the in-toto payload it is given; a keyless signer (#4869) answers
55
+ * once its signature is timestamped.
51
56
  */
52
57
  export interface EvidenceSigner {
53
58
  /** The runner principal the statement names, as `.chant/trust.json` at base lists it. */
54
59
  principal: string;
55
- sign(payloadType: string, payload: Buffer): DsseEnvelope;
60
+ sign(payloadType: string, payload: Buffer): DsseEnvelope | Promise<DsseEnvelope>;
61
+ }
62
+
63
+ /**
64
+ * The signer of a job that signs keyless from its OIDC identity (#4869):
65
+ * it requests the job's token for the policy's audience, trades it at the
66
+ * policy's certificate authority for a certificate over a key made for this
67
+ * run, and signs each envelope with that key, each signature timestamped.
68
+ * The principal is the identity of `keyless.identities` at `base` the
69
+ * certificate matches. Throws when the policy at base lists no keyless
70
+ * identity, the job has no token, or the certificate names an identity the
71
+ * policy does not list, so a job never keeps evidence its readers would
72
+ * ignore. Each envelope is verified against the policy before it is
73
+ * returned.
74
+ */
75
+ export async function keylessEvidenceSigner(repo: string, base: string, opts: { env?: NodeJS.ProcessEnv; fetch?: typeof fetch } = {}): Promise<EvidenceSigner> {
76
+ const env = opts.env ?? process.env;
77
+ const fetchFn = opts.fetch ?? fetch;
78
+ const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
79
+ if (policy.problems.length > 0) throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
80
+ const identities = policy.runnerIdentities ?? [];
81
+ if (!policy.keyless || identities.length === 0) {
82
+ const why = policy.excludedRunners.map((r) => `${r.principal}: ${r.reason}`).join("; ");
83
+ throw new Error(`.chant/trust.json at ${base.slice(0, 12)} lists no keyless identity, so keyless evidence would be ignored. Add one under "keyless"${why ? ` (${why})` : ""}`);
84
+ }
85
+ const { fulcio, timestamp, audience } = policy.keyless;
86
+ const token = await signingToken(env, audience, fetchFn);
87
+ const cert = await requestCertificate(token, fulcio, fetchFn);
88
+ const leaf = new X509Certificate(Buffer.from(cert.certificates[0]!, "base64"));
89
+ const issuer = certificateIssuer(leaf);
90
+ const subjects = certificateSubjects(leaf);
91
+ const listed = identities.find((i) => i.issuer === issuer && subjects.some((s) => subjectPattern(i.subject).test(s)));
92
+ if (!listed) {
93
+ throw new Error(`.chant/trust.json at ${base.slice(0, 12)} lists no keyless identity for this job (issuer ${issuer ?? "none"}, subject ${subjects.join(", ") || "none"}), so the evidence would be ignored`);
94
+ }
95
+ return {
96
+ principal: listed.principal,
97
+ sign: async (payloadType, payload) => {
98
+ const message = pae(payloadType, payload);
99
+ const signature = await keylessSignature(message, cert, timestamp, fetchFn);
100
+ const v = verifyKeylessSignature(message, signature, [listed]);
101
+ if (!v.ok) throw new Error(`the keyless signature does not verify against the policy at ${base.slice(0, 12)}: ${v.reason}`);
102
+ return { payloadType, payload: payload.toString("base64"), signatures: [signature] };
103
+ },
104
+ };
105
+ }
106
+
107
+ /**
108
+ * The job's signer, read from its environment in one place (#4869): the
109
+ * runner key in `key` or `CHANT_RUNNER_KEY` ({@link runnerKeyEvidenceSigner}),
110
+ * else, with `CHANT_RUNNER_IDENTITY=oidc`, the job's OIDC identity
111
+ * ({@link keylessEvidenceSigner}). Undefined when the job has neither, so
112
+ * a project with no runner identity gets the job it had. Throws as those do.
113
+ */
114
+ export async function runnerEvidenceSigner(repo: string, base: string, opts: { env?: NodeJS.ProcessEnv; key?: string; fetch?: typeof fetch } = {}): Promise<EvidenceSigner | undefined> {
115
+ const env = opts.env ?? process.env;
116
+ const pem = opts.key ?? env[CHECK_EVIDENCE_KEY_ENV];
117
+ if (pem) return runnerKeyEvidenceSigner(repo, base, pem);
118
+ const identity = env[RUNNER_IDENTITY_ENV];
119
+ if (!identity) return undefined;
120
+ if (identity !== "oidc") throw new Error(`${RUNNER_IDENTITY_ENV} is ${JSON.stringify(identity)}; the one runner identity chant signs with is oidc`);
121
+ return keylessEvidenceSigner(repo, base, { env, ...(opts.fetch ? { fetch: opts.fetch } : {}) });
122
+ }
123
+
124
+ /** What {@link runnerEvidenceSigner} would sign with, for a line saying why nothing was signed. */
125
+ export function noRunnerIdentity(): string {
126
+ return `no runner identity: neither ${CHECK_EVIDENCE_KEY_ENV} nor ${RUNNER_IDENTITY_ENV}=oidc is set`;
56
127
  }
57
128
 
58
129
  /**
@@ -88,8 +159,19 @@ export function commitAndTree(repo: string, rev: string): { commit: string; tree
88
159
  return { commit, tree: git(repo, ["rev-parse", `${commit}^{tree}`]) };
89
160
  }
90
161
 
91
- /** The check's statement over `commit`, with the digest of what it said when given. */
92
- export function checkStatement(input: { commit: string; tree: string; check: string; runner: string; claim?: Buffer | string }): EvidenceStatement {
162
+ /** Where a check's pass was read from (#4926): the forge's run and job ids, and the step whose conclusion said so. */
163
+ export interface CheckSource {
164
+ run: number;
165
+ job: number;
166
+ step?: string;
167
+ }
168
+
169
+ /**
170
+ * The check's statement over `commit`, with the digest of what it said when
171
+ * given, and (#4926) the run, job and step a signer outside the check's job
172
+ * read its pass from, so a verifier can look them up.
173
+ */
174
+ export function checkStatement(input: { commit: string; tree: string; check: string; runner: string; claim?: Buffer | string; source?: CheckSource }): EvidenceStatement {
93
175
  if (!input.check.trim()) throw new Error("a check's evidence needs the check's name");
94
176
  return {
95
177
  _type: STATEMENT_TYPE,
@@ -101,6 +183,7 @@ export function checkStatement(input: { commit: string; tree: string; check: str
101
183
  tree: input.tree,
102
184
  check: input.check,
103
185
  ...(input.claim !== undefined ? { claim: { sha256: createHash("sha256").update(input.claim).digest("hex") } } : {}),
186
+ ...(input.source ? { source: { run: input.source.run, job: input.source.job, ...(input.source.step ? { step: input.source.step } : {}) } } : {}),
104
187
  },
105
188
  };
106
189
  }
@@ -115,18 +198,14 @@ export interface SignedCheck {
115
198
  }
116
199
 
117
200
  /** Sign each of `checks` over `at` with `signer`. Writes nothing. */
118
- export function signChecks(repo: string, at: string, checks: readonly { check: string; claim?: Buffer | string }[], signer: EvidenceSigner): SignedCheck[] {
201
+ export async function signChecks(repo: string, at: string, checks: readonly { check: string; claim?: Buffer | string; source?: CheckSource }[], signer: EvidenceSigner): Promise<SignedCheck[]> {
119
202
  const { commit, tree } = commitAndTree(repo, at);
120
- return checks.map(({ check, claim }) => {
121
- const statement = checkStatement({ commit, tree, check, runner: signer.principal, ...(claim !== undefined ? { claim } : {}) });
122
- return {
123
- check,
124
- commit,
125
- tree,
126
- runner: signer.principal,
127
- envelope: signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")),
128
- };
129
- });
203
+ const out: SignedCheck[] = [];
204
+ for (const { check, claim, source } of checks) {
205
+ const statement = checkStatement({ commit, tree, check, runner: signer.principal, ...(claim !== undefined ? { claim } : {}), ...(source ? { source } : {}) });
206
+ out.push({ check, commit, tree, runner: signer.principal, envelope: await signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")) });
207
+ }
208
+ return out;
130
209
  }
131
210
 
132
211
  /** How many times {@link recordChecks} fetches, attaches and pushes when another job pushed the notes first. */
@@ -200,20 +279,23 @@ export type CheckEvidenceVerdict =
200
279
 
201
280
  /**
202
281
  * Read and verify the evidence for each of `checks` at `at`'s tree, against
203
- * the runner keys `.chant/trust.json` lists at `base`. `missing`: nothing is
282
+ * the runner keys and keyless identities `.chant/trust.json` lists at
283
+ * `base` (#4869). `missing`: nothing is
204
284
  * kept for the tree. `untrusted`: an envelope is kept, and no runner key at
205
285
  * base signed it, or it is not a check statement for that tree.
206
286
  */
207
287
  export async function readCheckEvidence(repo: string, at: string, base: string, checks: readonly string[]): Promise<CheckEvidenceVerdict[]> {
208
288
  const { tree, commit } = commitAndTree(repo, at);
209
289
  const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
290
+ // #4869: the keys and the keyless identities; under keyless.since, the keys only for a commit before it.
291
+ const runners = runnersAt(policy, { repo, commit });
210
292
  const envelopes = envelopesForTree(repo, commit, tree);
211
293
  return checks.map((check): CheckEvidenceVerdict => {
212
294
  let untrusted: string | undefined;
213
295
  for (const envelope of envelopes) {
214
- const v = verifyEvidence(envelope, policy.runners, repo, commit);
296
+ const v = verifyEvidence(envelope, runners, repo, commit);
215
297
  if (!v.ok) {
216
- if (claimedCheck(envelope) === check) untrusted ??= `the evidence attached for check ${check} does not verify against the runner keys at ${base.slice(0, 12)}: ${v.reason}`;
298
+ if (claimedCheck(envelope) === check) untrusted ??= `the evidence attached for check ${check} does not verify against the runners at ${base.slice(0, 12)}: ${v.reason}`;
217
299
  continue;
218
300
  }
219
301
  if (v.statement.predicate.check !== check || v.statement.predicate.tree !== tree) continue;
@@ -32,7 +32,7 @@ import { canonicalJson } from "../../effect-receipt";
32
32
  import { IN_TOTO_PAYLOAD_TYPE, signEnvelope, verifyEnvelope, type DsseEnvelope } from "./dsse";
33
33
  import { STATEMENT_TYPE } from "./evidence";
34
34
  import type { KeyObject } from "node:crypto";
35
- import type { RunnerKey } from "./policy";
35
+ import type { Runner, RunnerKey } from "./policy";
36
36
 
37
37
  export const CI_TAG_PREDICATE = "https://intentius.io/chant/ci-tag/v1";
38
38
 
@@ -114,7 +114,7 @@ const normalise = (name: string): string => name.normalize("NFKC").trim().toLowe
114
114
  export function verifyCiTagStatement(
115
115
  record: Record<string, unknown> | null,
116
116
  expect: { sha: string; kind: "green" | "revoked"; branch: string; lane?: string },
117
- runners: readonly RunnerKey[],
117
+ runners: readonly Runner[],
118
118
  roles: Readonly<Record<string, readonly string[]>>,
119
119
  ): CiTagVerdict {
120
120
  const tag = `ci/${expect.kind}${expect.lane !== undefined ? `-${expect.lane}` : ""}/${expect.sha}`;
@@ -10,6 +10,12 @@
10
10
  * Public keys are written the way ssh writes them (`ssh-ed25519 AAAA...`), so
11
11
  * the runner keys in `.chant/trust.json` read like the signers file beside
12
12
  * them, and a key id is the key's ssh fingerprint (`SHA256:...`).
13
+ *
14
+ * A signature can instead be keyless (#4869, ./keyless.ts): it carries the
15
+ * short-lived certificate of a CI job's OIDC identity and a timestamp, and
16
+ * verifies against an identity the policy lists rather than a key. The
17
+ * identity brings its own verifier, so this file, which bundles such as the
18
+ * runner-start verifier carry, holds no certificate code.
13
19
  */
14
20
 
15
21
  import { createHash, createPrivateKey, createPublicKey, sign, verify, type KeyObject } from "node:crypto";
@@ -19,6 +25,10 @@ export const IN_TOTO_PAYLOAD_TYPE = "application/vnd.in-toto+json";
19
25
  export interface DsseSignature {
20
26
  keyid: string;
21
27
  sig: string;
28
+ /** Keyless (#4869): the certificate chain, base64 DER, the signing certificate first. */
29
+ certificates?: string[];
30
+ /** Keyless (#4869): the RFC 3161 timestamp token over the signature, base64 DER. */
31
+ timestamp?: string;
22
32
  }
23
33
 
24
34
  export interface DsseEnvelope {
@@ -96,18 +106,51 @@ export interface TrustedKey {
96
106
  key: string;
97
107
  }
98
108
 
109
+ /** What a keyless identity says of one signature (#4869). `named`: the certificate is this identity's, and something else failed. */
110
+ export type KeylessCheck = { ok: true; keyid: string; issuer: string; subject: string; signedAt: string } | { ok: false; named: boolean; reason: string };
111
+
112
+ /** A CI identity that signs keyless (#4869), as the policy at base reads it, with the verifier for its trusted root. */
113
+ export interface TrustedIdentity {
114
+ principal: string;
115
+ issuer: string;
116
+ verifyKeyless(message: Buffer, signature: DsseSignature): KeylessCheck;
117
+ }
118
+
119
+ /** Who may sign: a runner key, or a CI identity that signs keyless (#4869). */
120
+ export type TrustedSigner = TrustedKey | TrustedIdentity;
121
+
122
+ const isKeyless = (s: DsseSignature): boolean => Array.isArray(s.certificates) && typeof s.timestamp === "string";
123
+
99
124
  export type EnvelopeVerdict =
100
- | { ok: true; principal: string; keyid: string; payloadType: string; payload: Buffer }
125
+ | { ok: true; principal: string; keyid: string; payloadType: string; payload: Buffer; keyless?: { issuer: string; subject: string; signedAt: string } }
101
126
  | { ok: false; code: "envelope-invalid" | "envelope-untrusted"; reason: string };
102
127
 
103
- /** Verify an envelope against `trusted`. One valid signature by a trusted key is enough. */
104
- export function verifyEnvelope(envelope: unknown, trusted: readonly TrustedKey[]): EnvelopeVerdict {
128
+ /**
129
+ * Verify an envelope against `trusted`. One valid signature by a trusted
130
+ * key, or one keyless signature by a trusted identity (#4869), is enough.
131
+ */
132
+ export function verifyEnvelope(envelope: unknown, trusted: readonly TrustedSigner[]): EnvelopeVerdict {
105
133
  if (!isEnvelope(envelope)) return { ok: false, code: "envelope-invalid", reason: "not a DSSE envelope: it needs payloadType, payload and signatures" };
106
134
  const payload = Buffer.from(envelope.payload, "base64");
107
135
  if (payload.toString("base64") !== envelope.payload) return { ok: false, code: "envelope-invalid", reason: "the payload is not canonical base64" };
108
136
  const message = pae(envelope.payloadType, payload);
109
- const byId = new Map(trusted.map((t) => [sshFingerprint(t.key), t]));
137
+ const keys = trusted.filter((t): t is TrustedKey => typeof (t as TrustedKey).key === "string");
138
+ const identities = trusted.filter((t): t is TrustedIdentity => typeof (t as TrustedIdentity).verifyKeyless === "function");
139
+ const byId = new Map(keys.map((t) => [sshFingerprint(t.key), t]));
140
+ let keyless: string | undefined;
110
141
  for (const s of envelope.signatures) {
142
+ if (isKeyless(s)) {
143
+ if (identities.length === 0) keyless ??= "the signature is keyless, and the policy at base lists no keyless identity";
144
+ let named: string | undefined;
145
+ for (const id of identities) {
146
+ const k = id.verifyKeyless(message, s);
147
+ if (k.ok) return { ok: true, principal: id.principal, keyid: k.keyid, payloadType: envelope.payloadType, payload, keyless: { issuer: k.issuer, subject: k.subject, signedAt: k.signedAt } };
148
+ if (k.named) named ??= k.reason;
149
+ else keyless ??= k.reason;
150
+ }
151
+ if (named) keyless = named;
152
+ continue;
153
+ }
111
154
  const t = byId.get(s.keyid);
112
155
  if (!t) continue;
113
156
  let good = false;
@@ -119,6 +162,7 @@ export function verifyEnvelope(envelope: unknown, trusted: readonly TrustedKey[]
119
162
  if (good) return { ok: true, principal: t.principal, keyid: s.keyid, payloadType: envelope.payloadType, payload };
120
163
  }
121
164
  const ids = envelope.signatures.map((s) => s.keyid).join(", ") || "none";
165
+ if (keyless) return { ok: false, code: "envelope-untrusted", reason: keyless };
122
166
  return { ok: false, code: "envelope-untrusted", reason: `no signature verifies against a runner key the policy at base lists (key ids: ${ids})` };
123
167
  }
124
168
 
@@ -21,7 +21,7 @@ import { canonicalJson } from "../../effect-receipt";
21
21
  import type { ReasonCode } from "../reason-codes";
22
22
  import { IN_TOTO_PAYLOAD_TYPE, signEnvelope, verifyEnvelope, type DsseEnvelope } from "./dsse";
23
23
  import type { KeyObject } from "node:crypto";
24
- import type { RunnerKey } from "./policy";
24
+ import type { Runner, RunnerKey } from "./policy";
25
25
 
26
26
  export const STATEMENT_TYPE = "https://in-toto.io/Statement/v1";
27
27
  export const RUNNER_EVIDENCE_PREDICATE = "https://intentius.io/chant/runner-evidence/v1";
@@ -81,6 +81,11 @@ export const evidenceStatementSchema = z
81
81
  check: z.string().min(1),
82
82
  claim: z.object({ sha256: sha256Hex }).strict().optional(),
83
83
  environment: z.object({ sha256: sha256Hex }).strict().optional(),
84
+ // #4926: the forge's record the signer relied on: the run, the job, and the step whose conclusion it read.
85
+ source: z
86
+ .object({ run: z.number().int().nonnegative(), job: z.number().int().nonnegative(), step: z.string().min(1).optional() })
87
+ .strict()
88
+ .optional(),
84
89
  })
85
90
  .strict(),
86
91
  })
@@ -169,7 +174,7 @@ export type EvidenceVerdict =
169
174
  * Verify an envelope against the runner keys at base, then compare each
170
175
  * subject with the record as committed at `at`.
171
176
  */
172
- export function verifyEvidence(envelope: unknown, runners: readonly RunnerKey[], repo: string, at: string): EvidenceVerdict {
177
+ export function verifyEvidence(envelope: unknown, runners: readonly Runner[], repo: string, at: string): EvidenceVerdict {
173
178
  const v = verifyEnvelope(envelope, runners);
174
179
  if (!v.ok) return v;
175
180
  if (v.payloadType !== IN_TOTO_PAYLOAD_TYPE) return { ok: false, code: "evidence-payload-type", reason: `payload type ${v.payloadType} is not ${IN_TOTO_PAYLOAD_TYPE}` };
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Test support for keyless runner statements (#4869): a fake forge token
3
+ * service, a fake Fulcio certificate authority and a fake RFC 3161
4
+ * timestamp authority, all answered by one `fetch` that never leaves the
5
+ * process. The certificates and timestamps are real DER, signed with keys
6
+ * made here, so ./keyless.ts verifies them as it would sigstore's. The
7
+ * clock is the fixture's, so a test can sign in the past and verify after
8
+ * the certificate expired.
9
+ */
10
+
11
+ import { createHash, createPublicKey, generateKeyPairSync, randomBytes, sign, verify, X509Certificate, type KeyObject } from "node:crypto";
12
+ import { DER, der, derChildren, derInt, derOid, derRead, OID } from "./keyless";
13
+
14
+ const ECDSA_SHA256 = "1.2.840.10045.4.3.2";
15
+ const CN = "2.5.4.3";
16
+
17
+ const name = (cn: string): Buffer => der(DER.SEQUENCE, der(DER.SET, der(DER.SEQUENCE, derOid(CN), der(DER.UTF8, Buffer.from(cn)))));
18
+ const algId = (oid: string, withNull = false): Buffer => der(DER.SEQUENCE, derOid(oid), ...(withNull ? [der(DER.NULL)] : []));
19
+ const ext = (oid: string, critical: boolean, value: Buffer): Buffer => der(DER.SEQUENCE, derOid(oid), ...(critical ? [der(DER.BOOLEAN, Buffer.from([0xff]))] : []), der(DER.OCTET_STRING, value));
20
+
21
+ function utcTime(d: Date): Buffer {
22
+ const iso = d.toISOString();
23
+ return der(DER.UTC_TIME, Buffer.from(`${iso.slice(2, 4)}${iso.slice(5, 7)}${iso.slice(8, 10)}${iso.slice(11, 13)}${iso.slice(14, 16)}${iso.slice(17, 19)}Z`));
24
+ }
25
+
26
+ function generalized(d: Date): Buffer {
27
+ const iso = d.toISOString();
28
+ return der(DER.GENERALIZED_TIME, Buffer.from(`${iso.slice(0, 4)}${iso.slice(5, 7)}${iso.slice(8, 10)}${iso.slice(11, 13)}${iso.slice(14, 16)}${iso.slice(17, 19)}Z`));
29
+ }
30
+
31
+ interface Issued {
32
+ cert: X509Certificate;
33
+ der: Buffer;
34
+ key?: KeyObject;
35
+ cn: string;
36
+ }
37
+
38
+ /** A certificate for `publicKey`, signed by `issuer` (or by `selfKey`, self-signed). */
39
+ function certificate(opts: { cn: string; publicKey: KeyObject; issuer?: Issued; signKey: KeyObject; notBefore: Date; notAfter: Date; extensions: Buffer[] }): Buffer {
40
+ const tbs = der(
41
+ DER.SEQUENCE,
42
+ der(0xa0, derInt(2)),
43
+ derInt(randomBytes(8)),
44
+ algId(ECDSA_SHA256),
45
+ name(opts.issuer?.cn ?? opts.cn),
46
+ der(DER.SEQUENCE, utcTime(opts.notBefore), utcTime(opts.notAfter)),
47
+ name(opts.cn),
48
+ opts.publicKey.export({ format: "der", type: "spki" }) as Buffer,
49
+ der(0xa3, der(DER.SEQUENCE, ...opts.extensions)),
50
+ );
51
+ return der(DER.SEQUENCE, tbs, algId(ECDSA_SHA256), der(DER.BIT_STRING, Buffer.from([0]), sign("sha256", tbs, opts.signKey)));
52
+ }
53
+
54
+ const CA_EXTENSIONS = [ext("2.5.29.19", true, der(DER.SEQUENCE, der(DER.BOOLEAN, Buffer.from([0xff])))), ext("2.5.29.15", true, der(DER.BIT_STRING, Buffer.from([1, 0x06])))];
55
+
56
+ function authority(cn: string, notBefore: Date): Issued {
57
+ const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
58
+ const bytes = certificate({ cn, publicKey, signKey: privateKey, notBefore, notAfter: new Date(notBefore.getTime() + 30 * 365 * 86400_000), extensions: CA_EXTENSIONS });
59
+ return { cert: new X509Certificate(bytes), der: bytes, key: privateKey, cn };
60
+ }
61
+
62
+ /** A fake forge OIDC token with `claims`: a JWT whose signature nothing checks but the fake authority. */
63
+ export function fakeToken(claims: Record<string, unknown>): string {
64
+ const part = (o: unknown) => Buffer.from(JSON.stringify(o)).toString("base64url");
65
+ return `${part({ alg: "RS256", typ: "JWT" })}.${part(claims)}.fake-signature-4869`;
66
+ }
67
+
68
+ /** The claims of a GitHub Actions job's token for `workflow` of `repository` at `ref`. */
69
+ export function githubClaims(repository: string, workflow: string, ref: string): Record<string, unknown> {
70
+ return {
71
+ iss: FAKE_GITHUB_ISSUER,
72
+ sub: `repo:${repository}:ref:${ref}`,
73
+ aud: "sigstore",
74
+ repository,
75
+ ref,
76
+ job_workflow_ref: `${repository}/.github/workflows/${workflow}@${ref}`,
77
+ };
78
+ }
79
+
80
+ /** The issuer the fake authority accepts GitHub-shaped tokens from. */
81
+ export const FAKE_GITHUB_ISSUER = "https://token.actions.githubusercontent.com";
82
+
83
+ export const FAKE_FULCIO_URL = "https://fulcio.fake.test";
84
+ export const FAKE_TSA_URL = "https://tsa.fake.test/api/v1/timestamp";
85
+ export const FAKE_TOKEN_URL = "https://forge.fake.test/oidc/token?api-version=2.0";
86
+ export const FAKE_REQUEST_TOKEN = "fake-request-token-4869";
87
+
88
+ /** What the fakes were asked. */
89
+ export interface SigstoreFakeLog {
90
+ tokens: string[];
91
+ certificates: string[];
92
+ timestamps: number;
93
+ }
94
+
95
+ export interface SigstoreFake {
96
+ /** Answers the forge's token URL, Fulcio and the timestamp authority. Anything else is refused. */
97
+ fetch: typeof fetch;
98
+ /** The trusted root, in sigstore's `trusted_root.json` format. */
99
+ trustedRoot: string;
100
+ /** The environment of a GitHub job with `id-token: write`, whose token carries `claims`. */
101
+ jobEnv(claims: Record<string, unknown>): NodeJS.ProcessEnv;
102
+ log: SigstoreFakeLog;
103
+ /** Sets the time the authorities issue and stamp at. */
104
+ setNow(d: Date): void;
105
+ }
106
+
107
+ /** Start the fakes. `now` is the authorities' clock; the authorities' own certificates are valid from 2020 for 30 years. */
108
+ export function sigstoreFake(opts: { now?: Date } = {}): SigstoreFake {
109
+ let now = opts.now ?? new Date();
110
+ const epoch = new Date("2020-01-01T00:00:00Z");
111
+ const ca = authority("fake fulcio root 4869", epoch);
112
+ const tsaRoot = authority("fake tsa root 4869", epoch);
113
+ const tsaPair = generateKeyPairSync("ec", { namedCurve: "P-256" });
114
+ const tsaDer = certificate({
115
+ cn: "fake tsa 4869",
116
+ publicKey: tsaPair.publicKey,
117
+ issuer: tsaRoot,
118
+ signKey: tsaRoot.key!,
119
+ notBefore: epoch,
120
+ notAfter: new Date(epoch.getTime() + 30 * 365 * 86400_000),
121
+ extensions: [ext("2.5.29.37", true, der(DER.SEQUENCE, derOid(OID.timeStamping)))],
122
+ });
123
+ const tsa: Issued = { cert: new X509Certificate(tsaDer), der: tsaDer, key: tsaPair.privateKey, cn: "fake tsa 4869" };
124
+ const log: SigstoreFakeLog = { tokens: [], certificates: [], timestamps: 0 };
125
+ const pending = new Map<string, string>();
126
+
127
+ const pem = (b: Buffer) => `-----BEGIN CERTIFICATE-----\n${b.toString("base64").replace(/(.{64})/g, "$1\n")}\n-----END CERTIFICATE-----\n`;
128
+
129
+ const issueLeaf = (body: string): Response => {
130
+ const req = JSON.parse(body) as { credentials: { oidcIdentityToken: string }; publicKeyRequest: { publicKey: { content: string }; proofOfPossession: string } };
131
+ const token = req.credentials.oidcIdentityToken;
132
+ const claims = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString()) as Record<string, string>;
133
+ if (claims.iss !== FAKE_GITHUB_ISSUER || claims.aud !== "sigstore") return new Response("token refused", { status: 401 });
134
+ const publicKey = createPublicKey(req.publicKeyRequest.publicKey.content);
135
+ if (!verify("sha256", Buffer.from(claims.sub!), publicKey, Buffer.from(req.publicKeyRequest.proofOfPossession, "base64"))) return new Response("no proof of possession", { status: 400 });
136
+ const san = `https://github.com/${claims.job_workflow_ref}`;
137
+ log.certificates.push(san);
138
+ const leaf = certificate({
139
+ cn: "sigstore",
140
+ publicKey,
141
+ issuer: ca,
142
+ signKey: ca.key!,
143
+ notBefore: now,
144
+ notAfter: new Date(now.getTime() + 10 * 60_000),
145
+ extensions: [
146
+ ext("2.5.29.15", true, der(DER.BIT_STRING, Buffer.from([7, 0x80]))),
147
+ ext("2.5.29.37", false, der(DER.SEQUENCE, derOid(OID.codeSigning))),
148
+ ext("2.5.29.17", true, der(DER.SEQUENCE, der(0x86, Buffer.from(san)))),
149
+ ext(OID.fulcioIssuerV1, false, Buffer.from(claims.iss!)),
150
+ ext(OID.fulcioIssuerV2, false, der(DER.UTF8, Buffer.from(claims.iss!))),
151
+ ],
152
+ });
153
+ return Response.json({ signedCertificateEmbeddedSct: { chain: { certificates: [pem(leaf), pem(ca.der)] } } });
154
+ };
155
+
156
+ const stamp = (body: Buffer): Response => {
157
+ const req = derChildren(derRead(body));
158
+ const imprint = derChildren(req[1]!);
159
+ const hashed = imprint[1]!.value;
160
+ log.timestamps++;
161
+ const tstInfo = der(DER.SEQUENCE, derInt(1), derOid("1.2.3.4.4869"), der(DER.SEQUENCE, algId(OID.sha256, true), der(DER.OCTET_STRING, hashed)), derInt(randomBytes(8)), generalized(now));
162
+ const attrs = [
163
+ der(DER.SEQUENCE, derOid(OID.contentType), der(DER.SET, derOid(OID.tstInfo))),
164
+ der(DER.SEQUENCE, derOid(OID.messageDigest), der(DER.SET, der(DER.OCTET_STRING, createHash("sha256").update(tstInfo).digest()))),
165
+ ];
166
+ const signature = sign("sha256", der(DER.SET, ...attrs), tsa.key!);
167
+ const issuerSerial = derChildren(derChildren(derRead(tsa.der))[0]!);
168
+ const signerInfo = der(DER.SEQUENCE, derInt(1), der(DER.SEQUENCE, issuerSerial[3]!.raw, issuerSerial[1]!.raw), algId(OID.sha256), der(0xa0, ...attrs), algId(ECDSA_SHA256), der(DER.OCTET_STRING, signature));
169
+ const signedData = der(DER.SEQUENCE, derInt(3), der(DER.SET, algId(OID.sha256)), der(DER.SEQUENCE, derOid(OID.tstInfo), der(0xa0, der(DER.OCTET_STRING, tstInfo))), der(0xa0, tsa.der), der(DER.SET, signerInfo));
170
+ const token = der(DER.SEQUENCE, derOid(OID.signedData), der(0xa0, signedData));
171
+ return new Response(new Uint8Array(der(DER.SEQUENCE, der(DER.SEQUENCE, derInt(0)), token)), { headers: { "content-type": "application/timestamp-reply" } });
172
+ };
173
+
174
+ const fakeFetch = (async (input: string | URL | Request, init?: RequestInit): Promise<Response> => {
175
+ const url = String(input instanceof Request ? input.url : input);
176
+ const headers = new Headers(init?.headers);
177
+ if (url.startsWith(FAKE_TOKEN_URL)) {
178
+ if (headers.get("authorization") !== `bearer ${FAKE_REQUEST_TOKEN}`) return new Response("no", { status: 403 });
179
+ const id = new URL(url).searchParams.get("job") ?? "";
180
+ const claims = pending.get(id);
181
+ if (!claims) return new Response("unknown job", { status: 404 });
182
+ const audience = new URL(url).searchParams.get("audience");
183
+ log.tokens.push(audience ?? "");
184
+ return Response.json({ value: fakeToken({ ...JSON.parse(claims), aud: audience }) });
185
+ }
186
+ if (url === `${FAKE_FULCIO_URL}/api/v2/signingCert`) return issueLeaf(String(init?.body));
187
+ if (url === FAKE_TSA_URL) return stamp(Buffer.from(init?.body as Uint8Array));
188
+ throw new Error(`the sigstore fake refuses ${url}: a test never reaches a real service`);
189
+ }) as typeof fetch;
190
+
191
+ const trustedRoot = JSON.stringify(
192
+ {
193
+ mediaType: "application/vnd.dev.sigstore.trustedroot+json;version=0.1",
194
+ certificateAuthorities: [{ uri: FAKE_FULCIO_URL, certChain: { certificates: [{ rawBytes: ca.der.toString("base64") }] }, validFor: { start: epoch.toISOString() } }],
195
+ timestampAuthorities: [{ uri: FAKE_TSA_URL, certChain: { certificates: [{ rawBytes: tsa.der.toString("base64") }, { rawBytes: tsaRoot.der.toString("base64") }] }, validFor: { start: epoch.toISOString() } }],
196
+ },
197
+ null,
198
+ 2,
199
+ );
200
+
201
+ return {
202
+ fetch: fakeFetch,
203
+ trustedRoot,
204
+ log,
205
+ setNow: (d) => {
206
+ now = d;
207
+ },
208
+ jobEnv: (claims) => {
209
+ const id = String(pending.size + 1);
210
+ pending.set(id, JSON.stringify(claims));
211
+ return { ACTIONS_ID_TOKEN_REQUEST_URL: `${FAKE_TOKEN_URL}&job=${id}`, ACTIONS_ID_TOKEN_REQUEST_TOKEN: FAKE_REQUEST_TOKEN };
212
+ },
213
+ };
214
+ }