@mailwoman/core 11.1.0 → 11.3.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 (477) hide show
  1. package/README.md +2 -2
  2. package/lib/api/arcgis.ts +194 -0
  3. package/lib/api/ckan.ts +1 -1
  4. package/lib/api/disk-storage.ts +2 -2
  5. package/lib/api/ogc.ts +1 -1
  6. package/lib/api/retry.ts +7 -2
  7. package/lib/api/test/transport.ts +1 -1
  8. package/lib/{binary-frame.ts → asset/binary-frame.ts} +1 -1
  9. package/lib/async/abort.ts +100 -0
  10. package/lib/{memoize.ts → async/memoize.ts} +2 -2
  11. package/lib/{promises.ts → async/promises.ts} +1 -1
  12. package/lib/cloudflare/tokens.ts +1 -1
  13. package/lib/cloudflare/wrangler.ts +3 -3
  14. package/lib/crypto/digest.ts +1 -1
  15. package/lib/crypto/ed25519.ts +8 -0
  16. package/lib/crypto/node.ts +1 -1
  17. package/lib/data-root.ts +16 -3
  18. package/lib/decoder/containment.ts +4 -1
  19. package/lib/decoder/serialize/outline.ts +50 -0
  20. package/lib/decoder/types.ts +9 -1
  21. package/lib/decoder.ts +1 -0
  22. package/lib/env/schema.ts +5 -0
  23. package/lib/fs/deflate64.ts +1 -1
  24. package/lib/fs/lock.ts +183 -25
  25. package/lib/fs/readers.ts +1 -1
  26. package/lib/fs/writers.ts +1 -1
  27. package/lib/geocode/result.ts +50 -6
  28. package/lib/html/text.ts +2 -2
  29. package/lib/index.ts +0 -1
  30. package/lib/layers/artifact.ts +2 -2
  31. package/lib/layers/coverage.ts +1 -1
  32. package/lib/layers/manifest.ts +94 -2
  33. package/lib/layers/provenance.ts +246 -0
  34. package/lib/layers/publication.ts +4 -3
  35. package/lib/layers/selection.ts +2 -2
  36. package/lib/license/branch.ts +66 -0
  37. package/lib/license/configured.ts +4 -2
  38. package/lib/license/declaration.ts +1 -1
  39. package/lib/license/key/file.ts +1 -1
  40. package/lib/license/key.ts +148 -201
  41. package/lib/license/provenance.ts +193 -0
  42. package/lib/license/register.ts +7 -78
  43. package/lib/license/stamp.ts +8 -2
  44. package/lib/license/text-url.ts +55 -0
  45. package/lib/license/training.ts +67 -0
  46. package/lib/license.ts +7 -6
  47. package/lib/locale/registry.ts +1 -1
  48. package/lib/locale/zh-cn-units.ts +1 -1
  49. package/lib/module/workspace.ts +1 -1
  50. package/lib/{routing.ts → network/routing.ts} +1 -1
  51. package/lib/pipeline/result.ts +7 -27
  52. package/lib/pipeline/runtime-pipeline.ts +131 -152
  53. package/lib/pipeline/stage.ts +290 -0
  54. package/lib/pipeline/types.ts +154 -20
  55. package/lib/pipeline.ts +14 -2
  56. package/lib/{git.ts → repo/git.ts} +21 -1
  57. package/lib/{release-config.ts → repo/release-config.ts} +8 -0
  58. package/lib/{scope-config.ts → repo/scope-config.ts} +8 -36
  59. package/lib/{spdx-header.ts → repo/spdx-header.ts} +8 -0
  60. package/lib/{workspaces.ts → repo/workspaces.ts} +1 -1
  61. package/lib/resolver/lookup-types.ts +1 -1
  62. package/lib/resolver/region-database-provider.ts +33 -0
  63. package/lib/resolver/synthetic-id-ranges.ts +76 -4
  64. package/lib/resolver/types.ts +231 -6
  65. package/lib/resolver.ts +14 -1
  66. package/lib/state-machine.ts +1 -1
  67. package/lib/strings/python-json.ts +15 -5
  68. package/lib/tokenization/Span.ts +12 -0
  69. package/lib/utils/chunk-process.ts +2 -2
  70. package/lib/utils/geodatabase-archive.ts +1 -1
  71. package/lib/utils/time.ts +190 -6
  72. package/lib/utils.ts +4 -4
  73. package/out/api/arcgis.d.ts +76 -0
  74. package/out/api/arcgis.d.ts.map +1 -1
  75. package/out/api/arcgis.js +123 -0
  76. package/out/api/arcgis.js.map +1 -1
  77. package/out/api/ckan.js +1 -1
  78. package/out/api/ckan.js.map +1 -1
  79. package/out/api/disk-storage.d.ts.map +1 -1
  80. package/out/api/disk-storage.js +2 -2
  81. package/out/api/disk-storage.js.map +1 -1
  82. package/out/api/ogc.js +1 -1
  83. package/out/api/ogc.js.map +1 -1
  84. package/out/api/retry.d.ts.map +1 -1
  85. package/out/api/retry.js +6 -2
  86. package/out/api/retry.js.map +1 -1
  87. package/out/api/test/transport.js +1 -1
  88. package/out/api/test/transport.js.map +1 -1
  89. package/out/asset/binary-frame.d.ts.map +1 -0
  90. package/out/{binary-frame.js → asset/binary-frame.js} +1 -1
  91. package/out/asset/binary-frame.js.map +1 -0
  92. package/out/asset/load-ledger.d.ts.map +1 -0
  93. package/out/asset/load-ledger.js.map +1 -0
  94. package/out/asset/overture-pins.d.ts.map +1 -0
  95. package/out/asset/overture-pins.js.map +1 -0
  96. package/out/asset/postcode-prefix-files.d.ts.map +1 -0
  97. package/out/asset/postcode-prefix-files.js.map +1 -0
  98. package/out/async/abort.d.ts +57 -0
  99. package/out/async/abort.d.ts.map +1 -0
  100. package/out/async/abort.js +89 -0
  101. package/out/async/abort.js.map +1 -0
  102. package/out/async/memoize.d.ts.map +1 -0
  103. package/out/{memoize.js → async/memoize.js} +2 -2
  104. package/out/async/memoize.js.map +1 -0
  105. package/out/{promises.d.ts → async/promises.d.ts} +1 -1
  106. package/out/async/promises.d.ts.map +1 -0
  107. package/out/{promises.js → async/promises.js} +1 -1
  108. package/out/async/promises.js.map +1 -0
  109. package/out/cloudflare/tokens.js +1 -1
  110. package/out/cloudflare/tokens.js.map +1 -1
  111. package/out/cloudflare/wrangler.js +3 -3
  112. package/out/cloudflare/wrangler.js.map +1 -1
  113. package/out/crypto/digest.d.ts +1 -1
  114. package/out/crypto/digest.js +1 -1
  115. package/out/crypto/ed25519.d.ts +7 -0
  116. package/out/crypto/ed25519.d.ts.map +1 -1
  117. package/out/crypto/ed25519.js +7 -0
  118. package/out/crypto/ed25519.js.map +1 -1
  119. package/out/crypto/hash.d.ts.map +1 -0
  120. package/out/crypto/hash.js.map +1 -0
  121. package/out/crypto/node.js +1 -1
  122. package/out/crypto/node.js.map +1 -1
  123. package/out/data-root.d.ts +11 -3
  124. package/out/data-root.d.ts.map +1 -1
  125. package/out/data-root.js +14 -3
  126. package/out/data-root.js.map +1 -1
  127. package/out/decoder/containment.d.ts.map +1 -1
  128. package/out/decoder/containment.js +1 -1
  129. package/out/decoder/containment.js.map +1 -1
  130. package/out/decoder/serialize/outline.d.ts +25 -0
  131. package/out/decoder/serialize/outline.d.ts.map +1 -0
  132. package/out/decoder/serialize/outline.js +37 -0
  133. package/out/decoder/serialize/outline.js.map +1 -0
  134. package/out/decoder/types.d.ts +8 -0
  135. package/out/decoder/types.d.ts.map +1 -1
  136. package/out/decoder/types.js +1 -1
  137. package/out/decoder/types.js.map +1 -1
  138. package/out/decoder.d.ts +1 -0
  139. package/out/decoder.d.ts.map +1 -1
  140. package/out/decoder.js +1 -0
  141. package/out/decoder.js.map +1 -1
  142. package/out/env/schema.d.ts +1 -0
  143. package/out/env/schema.d.ts.map +1 -1
  144. package/out/env/schema.js +4 -0
  145. package/out/env/schema.js.map +1 -1
  146. package/out/env.d.ts +1 -0
  147. package/out/env.d.ts.map +1 -1
  148. package/out/fs/deflate64.js +1 -1
  149. package/out/fs/deflate64.js.map +1 -1
  150. package/out/fs/lock.d.ts +73 -4
  151. package/out/fs/lock.d.ts.map +1 -1
  152. package/out/fs/lock.js +96 -19
  153. package/out/fs/lock.js.map +1 -1
  154. package/out/fs/readers.js +1 -1
  155. package/out/fs/readers.js.map +1 -1
  156. package/out/fs/writers.d.ts +1 -1
  157. package/out/fs/writers.d.ts.map +1 -1
  158. package/out/fs/writers.js +1 -1
  159. package/out/fs/writers.js.map +1 -1
  160. package/out/geocode/result.d.ts +25 -1
  161. package/out/geocode/result.d.ts.map +1 -1
  162. package/out/geocode/result.js +49 -6
  163. package/out/geocode/result.js.map +1 -1
  164. package/out/html/text.js +2 -2
  165. package/out/html/trust-policies.d.ts.map +1 -0
  166. package/out/html/trust-policies.js.map +1 -0
  167. package/out/index.d.ts +0 -1
  168. package/out/index.d.ts.map +1 -1
  169. package/out/index.js +0 -1
  170. package/out/index.js.map +1 -1
  171. package/out/layers/artifact.js +2 -2
  172. package/out/layers/artifact.js.map +1 -1
  173. package/out/layers/coverage.d.ts.map +1 -1
  174. package/out/layers/coverage.js +1 -1
  175. package/out/layers/coverage.js.map +1 -1
  176. package/out/layers/manifest.d.ts +53 -0
  177. package/out/layers/manifest.d.ts.map +1 -1
  178. package/out/layers/manifest.js +68 -2
  179. package/out/layers/manifest.js.map +1 -1
  180. package/out/layers/provenance.d.ts +127 -0
  181. package/out/layers/provenance.d.ts.map +1 -0
  182. package/out/layers/provenance.js +122 -0
  183. package/out/layers/provenance.js.map +1 -0
  184. package/out/layers/publication.d.ts.map +1 -1
  185. package/out/layers/publication.js +3 -3
  186. package/out/layers/publication.js.map +1 -1
  187. package/out/layers/selection.d.ts.map +1 -1
  188. package/out/layers/selection.js +2 -2
  189. package/out/layers/selection.js.map +1 -1
  190. package/out/license/branch.d.ts +33 -0
  191. package/out/license/branch.d.ts.map +1 -0
  192. package/out/license/branch.js +52 -0
  193. package/out/license/branch.js.map +1 -0
  194. package/out/license/configured.d.ts +1 -1
  195. package/out/license/configured.d.ts.map +1 -1
  196. package/out/license/configured.js +1 -9
  197. package/out/license/configured.js.map +1 -1
  198. package/out/license/declaration.d.ts +1 -1
  199. package/out/license/declaration.d.ts.map +1 -1
  200. package/out/license/key/file.js +1 -1
  201. package/out/license/key/file.js.map +1 -1
  202. package/out/license/key.d.ts +27 -115
  203. package/out/license/key.d.ts.map +1 -1
  204. package/out/license/key.js +98 -164
  205. package/out/license/key.js.map +1 -1
  206. package/out/license/provenance.d.ts +47 -0
  207. package/out/license/provenance.d.ts.map +1 -0
  208. package/out/license/provenance.js +134 -0
  209. package/out/license/provenance.js.map +1 -0
  210. package/out/license/register.d.ts +6 -47
  211. package/out/license/register.d.ts.map +1 -1
  212. package/out/license/register.js +7 -58
  213. package/out/license/register.js.map +1 -1
  214. package/out/license/stamp.d.ts +7 -1
  215. package/out/license/stamp.d.ts.map +1 -1
  216. package/out/license/stamp.js +2 -2
  217. package/out/license/stamp.js.map +1 -1
  218. package/out/license/text-url.d.ts +9 -0
  219. package/out/license/text-url.d.ts.map +1 -0
  220. package/out/license/text-url.js +49 -0
  221. package/out/license/text-url.js.map +1 -0
  222. package/out/license/training.d.ts +29 -0
  223. package/out/license/training.d.ts.map +1 -0
  224. package/out/license/training.js +52 -0
  225. package/out/license/training.js.map +1 -0
  226. package/out/license.d.ts +7 -6
  227. package/out/license.d.ts.map +1 -1
  228. package/out/license.js +7 -6
  229. package/out/license.js.map +1 -1
  230. package/out/locale/registry.d.ts.map +1 -1
  231. package/out/locale/registry.js +1 -1
  232. package/out/locale/registry.js.map +1 -1
  233. package/out/locale/zh-cn-units.js +1 -1
  234. package/out/locale/zh-cn-units.js.map +1 -1
  235. package/out/math/numeric.d.ts.map +1 -0
  236. package/out/math/numeric.js.map +1 -0
  237. package/out/math/random.d.ts.map +1 -0
  238. package/out/math/random.js.map +1 -0
  239. package/out/math/stats.d.ts.map +1 -0
  240. package/out/math/stats.js.map +1 -0
  241. package/out/module/workspace.js +1 -1
  242. package/out/module/workspace.js.map +1 -1
  243. package/out/network/routing.d.ts.map +1 -0
  244. package/out/{routing.js → network/routing.js} +1 -1
  245. package/out/network/routing.js.map +1 -0
  246. package/out/pipeline/result.d.ts +7 -25
  247. package/out/pipeline/result.d.ts.map +1 -1
  248. package/out/pipeline/runtime-pipeline.d.ts +8 -4
  249. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  250. package/out/pipeline/runtime-pipeline.js +56 -109
  251. package/out/pipeline/runtime-pipeline.js.map +1 -1
  252. package/out/pipeline/stage.d.ts +180 -0
  253. package/out/pipeline/stage.d.ts.map +1 -0
  254. package/out/pipeline/stage.js +130 -0
  255. package/out/pipeline/stage.js.map +1 -0
  256. package/out/pipeline/types.d.ts +146 -20
  257. package/out/pipeline/types.d.ts.map +1 -1
  258. package/out/pipeline/types.js +24 -8
  259. package/out/pipeline/types.js.map +1 -1
  260. package/out/pipeline.d.ts +5 -3
  261. package/out/pipeline.d.ts.map +1 -1
  262. package/out/pipeline.js +2 -1
  263. package/out/pipeline.js.map +1 -1
  264. package/out/{git.d.ts → repo/git.d.ts} +10 -1
  265. package/out/repo/git.d.ts.map +1 -0
  266. package/out/{git.js → repo/git.js} +14 -1
  267. package/out/repo/git.js.map +1 -0
  268. package/out/{release-config.d.ts → repo/release-config.d.ts} +8 -0
  269. package/out/repo/release-config.d.ts.map +1 -0
  270. package/out/repo/release-config.js.map +1 -0
  271. package/out/{scope-config.d.ts → repo/scope-config.d.ts} +8 -23
  272. package/out/repo/scope-config.d.ts.map +1 -0
  273. package/out/{scope-config.js → repo/scope-config.js} +0 -17
  274. package/out/repo/scope-config.js.map +1 -0
  275. package/out/repo/spdx-header.d.ts.map +1 -0
  276. package/out/{spdx-header.js → repo/spdx-header.js} +7 -0
  277. package/out/repo/spdx-header.js.map +1 -0
  278. package/out/repo/vale.d.ts.map +1 -0
  279. package/out/repo/vale.js.map +1 -0
  280. package/out/repo/workspaces.d.ts.map +1 -0
  281. package/out/{workspaces.js → repo/workspaces.js} +1 -1
  282. package/out/repo/workspaces.js.map +1 -0
  283. package/out/resolver/lookup-types.d.ts +1 -1
  284. package/out/resolver/region-database-provider.d.ts +30 -0
  285. package/out/resolver/region-database-provider.d.ts.map +1 -1
  286. package/out/resolver/synthetic-id-ranges.d.ts +46 -4
  287. package/out/resolver/synthetic-id-ranges.d.ts.map +1 -1
  288. package/out/resolver/synthetic-id-ranges.js +66 -4
  289. package/out/resolver/synthetic-id-ranges.js.map +1 -1
  290. package/out/resolver/types.d.ts +201 -7
  291. package/out/resolver/types.d.ts.map +1 -1
  292. package/out/resolver/types.js +57 -0
  293. package/out/resolver/types.js.map +1 -1
  294. package/out/resolver.d.ts +3 -3
  295. package/out/resolver.d.ts.map +1 -1
  296. package/out/resolver.js +1 -1
  297. package/out/resolver.js.map +1 -1
  298. package/out/scripting/process.d.ts.map +1 -0
  299. package/out/scripting/process.js.map +1 -0
  300. package/out/scripting/workers.d.ts.map +1 -0
  301. package/out/scripting/workers.js.map +1 -0
  302. package/out/state-machine.d.ts +1 -1
  303. package/out/strings/python-json.d.ts +12 -1
  304. package/out/strings/python-json.d.ts.map +1 -1
  305. package/out/strings/python-json.js +9 -4
  306. package/out/strings/python-json.js.map +1 -1
  307. package/out/tokenization/Span.d.ts +11 -0
  308. package/out/tokenization/Span.d.ts.map +1 -1
  309. package/out/tokenization/Span.js.map +1 -1
  310. package/out/tools/build-deflate64-wasm.run.js +2 -2
  311. package/out/tools/build-deflate64-wasm.run.js.map +1 -1
  312. package/out/tools/coarse-placer/build/dataset.js +1 -1
  313. package/out/tools/coarse-placer/build/dataset.js.map +1 -1
  314. package/out/tools/coarse-placer/build/outlier/exposure.js +1 -1
  315. package/out/tools/coarse-placer/build/outlier/exposure.js.map +1 -1
  316. package/out/tools/coarse-placer/build/outlier/latin.d.ts.map +1 -1
  317. package/out/tools/coarse-placer/build/outlier/latin.js +5 -1
  318. package/out/tools/coarse-placer/build/outlier/latin.js.map +1 -1
  319. package/out/tools/coarse-placer/country-sets.d.ts +2 -2
  320. package/out/tools/coarse-placer/country-sets.js +2 -2
  321. package/out/tools/coarse-placer/outlier-rows.js +2 -2
  322. package/out/tools/coarse-placer/outlier-rows.js.map +1 -1
  323. package/out/tools/coarse-placer/train.js +1 -1
  324. package/out/tools/coarse-placer/train.js.map +1 -1
  325. package/out/tools/generate-language-types.js +2 -2
  326. package/out/tools/generate-language-types.js.map +1 -1
  327. package/out/tools/license/product-fixtures.run.d.ts +2 -0
  328. package/out/tools/license/product-fixtures.run.d.ts.map +1 -0
  329. package/out/tools/license/product-fixtures.run.js +350 -0
  330. package/out/tools/license/product-fixtures.run.js.map +1 -0
  331. package/out/utils/chunk-process.js +2 -2
  332. package/out/utils/chunk-process.js.map +1 -1
  333. package/out/utils/geodatabase-archive.js +1 -1
  334. package/out/utils/geodatabase-archive.js.map +1 -1
  335. package/out/utils/time.d.ts +46 -3
  336. package/out/utils/time.d.ts.map +1 -1
  337. package/out/utils/time.js +139 -6
  338. package/out/utils/time.js.map +1 -1
  339. package/out/utils.d.ts +4 -4
  340. package/out/utils.d.ts.map +1 -1
  341. package/out/utils.js +4 -4
  342. package/out/utils.js.map +1 -1
  343. package/out/values/identical.d.ts.map +1 -0
  344. package/out/values/identical.js.map +1 -0
  345. package/out/values/json.d.ts.map +1 -0
  346. package/out/values/json.js.map +1 -0
  347. package/out/values/objects.d.ts.map +1 -0
  348. package/out/values/objects.js.map +1 -0
  349. package/package.json +278 -243
  350. package/tools/build-deflate64-wasm.run.ts +2 -2
  351. package/tools/coarse-placer/build/dataset.ts +1 -1
  352. package/tools/coarse-placer/build/outlier/exposure.ts +1 -1
  353. package/tools/coarse-placer/build/outlier/latin.ts +5 -1
  354. package/tools/coarse-placer/country-sets.ts +2 -2
  355. package/tools/coarse-placer/outlier-rows.ts +2 -2
  356. package/tools/coarse-placer/train.ts +1 -1
  357. package/tools/generate-language-types.ts +2 -2
  358. package/tools/license/product-fixtures.run.ts +449 -0
  359. package/lib/collections.ts +0 -5
  360. package/lib/license/decision.ts +0 -329
  361. package/lib/license/obligations.ts +0 -256
  362. package/lib/license/record.ts +0 -277
  363. package/lib/scripting/ingest-chunk-script.ts +0 -87
  364. package/out/binary-frame.d.ts.map +0 -1
  365. package/out/binary-frame.js.map +0 -1
  366. package/out/collections.d.ts +0 -2
  367. package/out/collections.d.ts.map +0 -1
  368. package/out/collections.js +0 -5
  369. package/out/collections.js.map +0 -1
  370. package/out/git.d.ts.map +0 -1
  371. package/out/git.js.map +0 -1
  372. package/out/hash.d.ts.map +0 -1
  373. package/out/hash.js.map +0 -1
  374. package/out/identical.d.ts.map +0 -1
  375. package/out/identical.js.map +0 -1
  376. package/out/json.d.ts.map +0 -1
  377. package/out/json.js.map +0 -1
  378. package/out/license/decision.d.ts +0 -179
  379. package/out/license/decision.d.ts.map +0 -1
  380. package/out/license/decision.js +0 -169
  381. package/out/license/decision.js.map +0 -1
  382. package/out/license/obligations.d.ts +0 -102
  383. package/out/license/obligations.d.ts.map +0 -1
  384. package/out/license/obligations.js +0 -188
  385. package/out/license/obligations.js.map +0 -1
  386. package/out/license/record.d.ts +0 -136
  387. package/out/license/record.d.ts.map +0 -1
  388. package/out/license/record.js +0 -222
  389. package/out/license/record.js.map +0 -1
  390. package/out/load-ledger.d.ts.map +0 -1
  391. package/out/load-ledger.js.map +0 -1
  392. package/out/memoize.d.ts.map +0 -1
  393. package/out/memoize.js.map +0 -1
  394. package/out/numeric.d.ts.map +0 -1
  395. package/out/numeric.js.map +0 -1
  396. package/out/objects.d.ts.map +0 -1
  397. package/out/objects.js.map +0 -1
  398. package/out/overture-pins.d.ts.map +0 -1
  399. package/out/overture-pins.js.map +0 -1
  400. package/out/postcode-prefix-files.d.ts.map +0 -1
  401. package/out/postcode-prefix-files.js.map +0 -1
  402. package/out/process.d.ts.map +0 -1
  403. package/out/process.js.map +0 -1
  404. package/out/promises.d.ts.map +0 -1
  405. package/out/promises.js.map +0 -1
  406. package/out/random.d.ts.map +0 -1
  407. package/out/random.js.map +0 -1
  408. package/out/release-config.d.ts.map +0 -1
  409. package/out/release-config.js.map +0 -1
  410. package/out/routing.d.ts.map +0 -1
  411. package/out/routing.js.map +0 -1
  412. package/out/scope-config.d.ts.map +0 -1
  413. package/out/scope-config.js.map +0 -1
  414. package/out/scripting/ingest-chunk-script.d.ts +0 -58
  415. package/out/scripting/ingest-chunk-script.d.ts.map +0 -1
  416. package/out/scripting/ingest-chunk-script.js +0 -47
  417. package/out/scripting/ingest-chunk-script.js.map +0 -1
  418. package/out/spdx-header.d.ts.map +0 -1
  419. package/out/spdx-header.js.map +0 -1
  420. package/out/stats.d.ts.map +0 -1
  421. package/out/stats.js.map +0 -1
  422. package/out/trust-policies.d.ts.map +0 -1
  423. package/out/trust-policies.js.map +0 -1
  424. package/out/vale.d.ts.map +0 -1
  425. package/out/vale.js.map +0 -1
  426. package/out/workers.d.ts.map +0 -1
  427. package/out/workers.js.map +0 -1
  428. package/out/workspaces.d.ts.map +0 -1
  429. package/out/workspaces.js.map +0 -1
  430. /package/lib/{load-ledger.ts → asset/load-ledger.ts} +0 -0
  431. /package/lib/{overture-pins.ts → asset/overture-pins.ts} +0 -0
  432. /package/lib/{postcode-prefix-files.ts → asset/postcode-prefix-files.ts} +0 -0
  433. /package/lib/{hash.ts → crypto/hash.ts} +0 -0
  434. /package/lib/{trust-policies.ts → html/trust-policies.ts} +0 -0
  435. /package/lib/{numeric.ts → math/numeric.ts} +0 -0
  436. /package/lib/{random.ts → math/random.ts} +0 -0
  437. /package/lib/{stats.ts → math/stats.ts} +0 -0
  438. /package/lib/{vale.ts → repo/vale.ts} +0 -0
  439. /package/lib/{process.ts → scripting/process.ts} +0 -0
  440. /package/lib/{workers.ts → scripting/workers.ts} +0 -0
  441. /package/lib/{identical.ts → values/identical.ts} +0 -0
  442. /package/lib/{json.ts → values/json.ts} +0 -0
  443. /package/lib/{objects.ts → values/objects.ts} +0 -0
  444. /package/out/{binary-frame.d.ts → asset/binary-frame.d.ts} +0 -0
  445. /package/out/{load-ledger.d.ts → asset/load-ledger.d.ts} +0 -0
  446. /package/out/{load-ledger.js → asset/load-ledger.js} +0 -0
  447. /package/out/{overture-pins.d.ts → asset/overture-pins.d.ts} +0 -0
  448. /package/out/{overture-pins.js → asset/overture-pins.js} +0 -0
  449. /package/out/{postcode-prefix-files.d.ts → asset/postcode-prefix-files.d.ts} +0 -0
  450. /package/out/{postcode-prefix-files.js → asset/postcode-prefix-files.js} +0 -0
  451. /package/out/{memoize.d.ts → async/memoize.d.ts} +0 -0
  452. /package/out/{hash.d.ts → crypto/hash.d.ts} +0 -0
  453. /package/out/{hash.js → crypto/hash.js} +0 -0
  454. /package/out/{trust-policies.d.ts → html/trust-policies.d.ts} +0 -0
  455. /package/out/{trust-policies.js → html/trust-policies.js} +0 -0
  456. /package/out/{numeric.d.ts → math/numeric.d.ts} +0 -0
  457. /package/out/{numeric.js → math/numeric.js} +0 -0
  458. /package/out/{random.d.ts → math/random.d.ts} +0 -0
  459. /package/out/{random.js → math/random.js} +0 -0
  460. /package/out/{stats.d.ts → math/stats.d.ts} +0 -0
  461. /package/out/{stats.js → math/stats.js} +0 -0
  462. /package/out/{routing.d.ts → network/routing.d.ts} +0 -0
  463. /package/out/{release-config.js → repo/release-config.js} +0 -0
  464. /package/out/{spdx-header.d.ts → repo/spdx-header.d.ts} +0 -0
  465. /package/out/{vale.d.ts → repo/vale.d.ts} +0 -0
  466. /package/out/{vale.js → repo/vale.js} +0 -0
  467. /package/out/{workspaces.d.ts → repo/workspaces.d.ts} +0 -0
  468. /package/out/{process.d.ts → scripting/process.d.ts} +0 -0
  469. /package/out/{process.js → scripting/process.js} +0 -0
  470. /package/out/{workers.d.ts → scripting/workers.d.ts} +0 -0
  471. /package/out/{workers.js → scripting/workers.js} +0 -0
  472. /package/out/{identical.d.ts → values/identical.d.ts} +0 -0
  473. /package/out/{identical.js → values/identical.js} +0 -0
  474. /package/out/{json.d.ts → values/json.d.ts} +0 -0
  475. /package/out/{json.js → values/json.js} +0 -0
  476. /package/out/{objects.d.ts → values/objects.d.ts} +0 -0
  477. /package/out/{objects.js → values/objects.js} +0 -0
@@ -2,216 +2,154 @@
2
2
  // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
3
 
4
4
  /**
5
- * Encodes and verifies offline commercial-license tokens of the form `mwl1.<payload>.<signature>`.
5
+ * Encodes and verifies Mailwoman's offline product tokens: platform license keys
6
+ * (`mwl1`) and commercial training grants (`mwt1`).
6
7
  *
7
- * Ed25519 signs the payload.
8
- * Verification checks the signature against trusted public keys.
8
+ * `@mailwoman/license/product/token` defines the wire format and payload schemas,
9
+ * and `@mailwoman/license/product/trust` holds the trusted public keys.
10
+ * This module adds the Ed25519 signatures, on WebCrypto, so it runs in Node, browsers and Workers.
9
11
  *
10
- * The module uses WebCrypto, so it runs in Node, browsers and Workers.
11
- */
12
-
13
- import { z } from "zod"
14
-
15
- import { fromBase64URL, toBase64URL, utf8Bytes, utf8Text } from "#crypto/base64url"
12
+ * The Rust verifier in `packages/license/crates/product-license` reads the
13
+ * same fixtures and returns the same statuses.
14
+ */
15
+
16
+ import {
17
+ LICENSE_KEY_PREFIX,
18
+ type LicenseKeyPayload,
19
+ LicenseKeyPayloadSchema,
20
+ type LicenseKeyVerification,
21
+ licenseExpiryInstant,
22
+ type ProductTokenParts,
23
+ type ProductTokenPrefix,
24
+ type ProductTokenVerification,
25
+ schemaIssue,
26
+ splitProductToken,
27
+ TRAINING_GRANT_PREFIX,
28
+ type TrainingGrantPayload,
29
+ TrainingGrantPayloadSchema,
30
+ type TrainingGrantVerification,
31
+ } from "@mailwoman/license/product/token"
32
+ import type { z } from "zod"
33
+
34
+ import { fromBase64URL, toBase64URL, utf8Bytes } from "#crypto/base64url"
16
35
  import { hexOf, sha256Bytes } from "#crypto/digest"
17
- import { generateEd25519KeyPair, publicKeyDER, signEd25519, verifyEd25519 } from "#crypto/ed25519"
18
- import { errorMessage } from "#errors/schema"
19
- import { parseJSONStrict, stringifyJSON } from "#json"
36
+ import {
37
+ ED25519_SIGNATURE_BYTES,
38
+ generateEd25519KeyPair,
39
+ publicKeyDER,
40
+ signEd25519,
41
+ verifyEd25519,
42
+ } from "#crypto/ed25519"
43
+ import { stringifyJSON } from "#values/json"
20
44
 
21
45
  /**
22
- * The token format's version prefix.
23
- */
24
- export const LICENSE_KEY_PREFIX = "mwl1"
25
-
26
- /**
27
- * The number of dot-separated parts in a token.
28
- */
29
- const LICENSE_KEY_PARTS = 3
30
-
31
- /**
32
- * A calendar date in `YYYY-MM-DD` format.
46
+ * An Ed25519 signing key pair with both keys PEM-encoded.
33
47
  */
34
- const CalendarDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/u, "expected YYYY-MM-DD")
48
+ export interface LicenseSigningKeyPair {
49
+ privateKeyPEM: string
50
+ publicKeyPEM: string
51
+ }
35
52
 
36
53
  /**
37
- * The two branches of the dual license a token can grant.
38
- *
39
- * A commercial token releases the holder from the AGPL source offer.
40
- * An open-source token grants artifact access and leaves every AGPL obligation in place.
54
+ * Generates a new Ed25519 signing key pair.
41
55
  */
42
- export const LicenseTerms = {
43
- Commercial: "LicenseRef-Commercial",
44
- OpenSource: "AGPL-3.0-only",
45
- } as const
46
-
47
- export type LicenseTerms = (typeof LicenseTerms)[keyof typeof LicenseTerms]
56
+ export function generateLicenseSigningKeyPair(): Promise<LicenseSigningKeyPair> {
57
+ return generateEd25519KeyPair()
58
+ }
48
59
 
49
60
  /**
50
- * The route that issued a token.
61
+ * Builds a key ID from a one-letter use, the product major version and the first
62
+ * eight hex digits of the DER key's SHA-256.
51
63
  *
52
- * `commercial` is a purchase.
53
- * `evaluation` is the thirty-day route.
54
- * The other four are declarations of intent.
64
+ * A license key's use is `v`, a provenance key's `p`.
55
65
  */
56
- export const LicenseIntent = {
57
- OpenSource: "open-source",
58
- NonProfit: "non-profit",
59
- Academic: "academic",
60
- Student: "student",
61
- Evaluation: "evaluation",
62
- Commercial: "commercial",
63
- } as const
66
+ async function keyID(publicKeyPEM: string, majorVersion: number, use: "v" | "p"): Promise<string> {
67
+ const digest = hexOf(await sha256Bytes(publicKeyDER(publicKeyPEM))).slice(0, 8)
64
68
 
65
- export type LicenseIntent = (typeof LicenseIntent)[keyof typeof LicenseIntent]
69
+ return `${use}${majorVersion}-${digest}`
70
+ }
66
71
 
67
72
  /**
68
- * The prefix of a scope entry that's an atlas tier rather than a package.
73
+ * The key ID of a license signing key: `v<major>-<eight hex digits>`.
69
74
  */
70
- export const TIER_SCOPE_PREFIX = "tier:"
75
+ export function licenseKeyID(publicKeyPEM: string, majorVersion: number): Promise<string> {
76
+ return keyID(publicKeyPEM, majorVersion, "v")
77
+ }
71
78
 
72
79
  /**
73
- * The schema of a license-key payload.
80
+ * The key ID of a provenance signing key: `p<major>-<eight hex digits>`.
74
81
  */
75
- export const LicenseKeyPayloadSchema = z.object({
76
- /**
77
- * The payload format version.
78
- */
79
- v: z.literal(1),
80
- /**
81
- * The signing key ID selects the trusted public key.
82
- */
83
- kid: z.string().min(1),
84
- /**
85
- * The license holder's name appears in `doctor` output.
86
- */
87
- licensee: z.string().min(1),
88
- issued: CalendarDate,
89
- /**
90
- * The last valid date, inclusive.
91
- * A key without it doesn't expire.
92
- */
93
- expires: CalendarDate.nullable().optional(),
94
- /**
95
- * Either `all` or the list of packages and `tier:<name>` entries the token may download.
96
- */
97
- scope: z.union([z.literal("all"), z.array(z.string().min(1)).min(1)]),
98
- /**
99
- * The license branch that the key grants.
100
- */
101
- terms: z.enum([LicenseTerms.Commercial, LicenseTerms.OpenSource]),
102
- /**
103
- * An opaque serial for checking the license status online.
104
- */
105
- lid: z.string().min(1).nullable().optional(),
106
- /**
107
- * The version of the terms that the licensee accepted.
108
- * A declared token has none.
109
- */
110
- agreement: z.string().min(1).nullable().optional(),
111
- /**
112
- * The route that issued the token.
113
- * A hand-issued token has none.
114
- */
115
- intent: z
116
- .enum([
117
- LicenseIntent.OpenSource,
118
- LicenseIntent.NonProfit,
119
- LicenseIntent.Academic,
120
- LicenseIntent.Student,
121
- LicenseIntent.Evaluation,
122
- LicenseIntent.Commercial,
123
- ])
124
- .optional(),
125
- /**
126
- * The issuance ordinal within the license, 1 for the first token.
127
- */
128
- seq: z.number().int().min(1).optional(),
129
- /**
130
- * The installation id the requesting CLI reported.
131
- * The token is never bound to it.
132
- */
133
- install: z.uuid().optional(),
134
- })
82
+ export function provenanceKeyID(publicKeyPEM: string, majorVersion: number): Promise<string> {
83
+ return keyID(publicKeyPEM, majorVersion, "p")
84
+ }
135
85
 
136
- /**
137
- * A validated license-key payload.
138
- */
139
- export type LicenseKeyPayload = z.infer<typeof LicenseKeyPayloadSchema>
86
+ async function encodeProductToken(prefix: ProductTokenPrefix, payload: object, privateKeyPEM: string): Promise<string> {
87
+ const body = `${prefix}.${toBase64URL(utf8Bytes(stringifyJSON(payload)))}`
88
+ const signature = await signEd25519(utf8Bytes(body), privateKeyPEM)
140
89
 
141
- /**
142
- * A payload the worker issued, identified by its serial.
143
- *
144
- * A purchased token also has `agreement`.
145
- * A declared token has none.
146
- */
147
- export type SelfServiceLicenseKeyPayload = LicenseKeyPayload & { lid: string }
90
+ return `${body}.${toBase64URL(signature)}`
91
+ }
148
92
 
149
93
  /**
150
- * Returns whether a payload has a `lid`.
151
- * The online status routes are keyed by it.
94
+ * Validates a platform key payload and signs it with the issuer's private key.
152
95
  */
153
- export function isSelfServicePayload(payload: LicenseKeyPayload): payload is SelfServiceLicenseKeyPayload {
154
- return typeof payload.lid === "string"
96
+ export async function encodeLicenseKey(payload: LicenseKeyPayload, privateKeyPEM: string): Promise<string> {
97
+ return encodeProductToken(LICENSE_KEY_PREFIX, LicenseKeyPayloadSchema.parse(payload), privateKeyPEM)
155
98
  }
156
99
 
157
100
  /**
158
- * Returns whether a scope admits an artifact.
159
- * An artifact is a package name or a `tier:<name>` entry.
101
+ * Validates a training grant payload and signs it with the issuer's private key.
160
102
  */
161
- export function scopeAdmits(scope: LicenseKeyPayload["scope"], artifact: string): boolean {
162
- return scope === "all" || scope.includes(artifact)
103
+ export async function encodeTrainingGrant(payload: TrainingGrantPayload, privateKeyPEM: string): Promise<string> {
104
+ return encodeProductToken(TRAINING_GRANT_PREFIX, TrainingGrantPayloadSchema.parse(payload), privateKeyPEM)
163
105
  }
164
106
 
165
- /**
166
- * The result of verifying a token.
167
- * Every failure status includes a reason.
168
- */
169
- export type LicenseKeyVerification =
170
- | { status: "valid"; kid: string; payload: LicenseKeyPayload }
171
- | { status: "expired"; kid: string; payload: LicenseKeyPayload }
172
- | { status: "unknown_key"; kid: string; reason: string }
173
- | { status: "invalid"; reason: string }
107
+ const STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true })
174
108
 
175
109
  /**
176
- * An Ed25519 signing key pair with both keys PEM-encoded.
110
+ * A token read as far as its signature: its parts and its validated payload, or the reason it's malformed.
177
111
  */
178
- export interface LicenseSigningKeyPair {
179
- privateKeyPEM: string
180
- publicKeyPEM: string
181
- }
112
+ type ProductTokenReading<P> = { parts: ProductTokenParts; payload: P } | { reason: string }
182
113
 
183
114
  /**
184
- * Generates a new Ed25519 signing key pair.
115
+ * Reads a token of one prefix without checking its signature.
116
+ *
117
+ * It checks the three parts, the payload's base64url, UTF-8 and JSON, and the payload schema, in that order.
118
+ * The first step that fails gives the reason.
185
119
  */
186
- export function generateLicenseSigningKeyPair(): Promise<LicenseSigningKeyPair> {
187
- return generateEd25519KeyPair()
188
- }
120
+ function readProductToken<P>(token: string, prefix: ProductTokenPrefix, schema: z.ZodType<P>): ProductTokenReading<P> {
121
+ const parts = splitProductToken(token)
189
122
 
190
- /**
191
- * Builds a key ID from the product major version and the first eight hex digits of the DER key's SHA-256.
192
- */
193
- export async function licenseKeyID(publicKeyPEM: string, majorVersion: number): Promise<string> {
194
- const digest = hexOf(await sha256Bytes(publicKeyDER(publicKeyPEM))).slice(0, 8)
123
+ if ("reason" in parts) {
124
+ return parts
125
+ }
195
126
 
196
- return `v${majorVersion}-${digest}`
197
- }
127
+ if (parts.prefix !== prefix) {
128
+ return { reason: `a ${parts.prefix} token, not a ${prefix} token` }
129
+ }
198
130
 
199
- /**
200
- * Validates a payload and signs it with the issuer's private key.
201
- */
202
- export async function encodeLicenseKey(payload: LicenseKeyPayload, privateKeyPEM: string): Promise<string> {
203
- const checked = LicenseKeyPayloadSchema.parse(payload)
204
- const body = `${LICENSE_KEY_PREFIX}.${toBase64URL(utf8Bytes(stringifyJSON(checked)))}`
205
- const signature = await signEd25519(utf8Bytes(body), privateKeyPEM)
131
+ let text: string
206
132
 
207
- return `${body}.${toBase64URL(signature)}`
208
- }
133
+ try {
134
+ text = STRICT_UTF8.decode(fromBase64URL(parts.payload))
135
+ } catch {
136
+ return { reason: "payload unreadable: not base64url-encoded UTF-8" }
137
+ }
209
138
 
210
- /**
211
- * Returns the last UTC millisecond of the expiration date.
212
- */
213
- export function licenseExpiryInstant(expires: string): Date {
214
- return new Date(`${expires}T23:59:59.999Z`)
139
+ let value: unknown
140
+
141
+ try {
142
+ // oxlint-disable-next-line no-restricted-properties -- `parseJSONStrict` wraps the error and loses the reason the fixtures record.
143
+ value = JSON.parse(text)
144
+ } catch {
145
+ return { reason: "payload unreadable: not JSON" }
146
+ }
147
+
148
+ const parsed = schema.safeParse(value)
149
+
150
+ return parsed.success
151
+ ? { parts, payload: parsed.data }
152
+ : { reason: `payload unreadable: ${schemaIssue(parsed.error)}` }
215
153
  }
216
154
 
217
155
  /**
@@ -219,41 +157,24 @@ export function licenseExpiryInstant(expires: string): Date {
219
157
  * Use the result only for display.
220
158
  */
221
159
  export function decodeLicenseKeyPayload(token: string): LicenseKeyPayload | null {
222
- const parts = token.trim().split(".")
160
+ const reading = readProductToken(token, LICENSE_KEY_PREFIX, LicenseKeyPayloadSchema)
223
161
 
224
- if (parts.length !== LICENSE_KEY_PARTS || parts[0] !== LICENSE_KEY_PREFIX) return null
225
-
226
- try {
227
- return LicenseKeyPayloadSchema.parse(parseJSONStrict(utf8Text(fromBase64URL(parts[1] ?? ""))))
228
- } catch {
229
- return null
230
- }
162
+ return "payload" in reading ? reading.payload : null
231
163
  }
232
164
 
233
- /**
234
- * Verifies a token offline against trusted public keys keyed by key ID.
235
- *
236
- * Tests pass `now` to get a fixed clock.
237
- */
238
- export async function verifyLicenseKey(
165
+ async function verifyProductToken<P extends { kid: string; expires?: string | null }>(
239
166
  token: string,
167
+ prefix: ProductTokenPrefix,
168
+ schema: z.ZodType<P>,
240
169
  options: { trustedKeys: Readonly<Record<string, string>>; now?: Date }
241
- ): Promise<LicenseKeyVerification> {
242
- const parts = token.trim().split(".")
243
-
244
- if (parts.length !== LICENSE_KEY_PARTS || parts[0] !== LICENSE_KEY_PREFIX) {
245
- return { status: "invalid", reason: `not a ${LICENSE_KEY_PREFIX} token (expected three dot-separated parts)` }
246
- }
247
-
248
- const [prefix, payloadPart, signaturePart] = parts as [string, string, string]
249
- let payload: LicenseKeyPayload
170
+ ): Promise<ProductTokenVerification<P>> {
171
+ const reading = readProductToken(token, prefix, schema)
250
172
 
251
- try {
252
- payload = LicenseKeyPayloadSchema.parse(parseJSONStrict(utf8Text(fromBase64URL(payloadPart))))
253
- } catch (error) {
254
- return { status: "invalid", reason: `payload unreadable: ${errorMessage(error)}` }
173
+ if ("reason" in reading) {
174
+ return { status: "invalid", reason: reading.reason }
255
175
  }
256
176
 
177
+ const { parts, payload } = reading
257
178
  const publicKeyPEM = options.trustedKeys[payload.kid]
258
179
 
259
180
  if (!publicKeyPEM) {
@@ -264,17 +185,43 @@ export async function verifyLicenseKey(
264
185
  }
265
186
  }
266
187
 
267
- const signed = await verifyEd25519(utf8Bytes(`${prefix}.${payloadPart}`), publicKeyPEM, fromBase64URL(signaturePart))
188
+ const signature = fromBase64URL(parts.signature)
189
+
190
+ const signed =
191
+ signature.length === ED25519_SIGNATURE_BYTES &&
192
+ (await verifyEd25519(utf8Bytes(parts.signed), publicKeyPEM, signature))
268
193
 
269
194
  if (!signed) {
270
195
  return { status: "invalid", reason: `signature does not verify under key id ${payload.kid}` }
271
196
  }
272
197
 
273
- const now = options.now ?? new Date()
198
+ const expires = payload.expires
199
+ const expired = expires != null && licenseExpiryInstant(expires) < (options.now ?? new Date())
274
200
 
275
- if (payload.expires && licenseExpiryInstant(payload.expires) < now) {
276
- return { status: "expired", kid: payload.kid, payload }
277
- }
201
+ return { status: expired ? "expired" : "valid", kid: payload.kid, payload }
202
+ }
203
+
204
+ /**
205
+ * Verifies a platform license key offline against trusted public keys keyed by key ID.
206
+ *
207
+ * Tests pass `now` to get a fixed clock.
208
+ */
209
+ export function verifyLicenseKey(
210
+ token: string,
211
+ options: { trustedKeys: Readonly<Record<string, string>>; now?: Date }
212
+ ): Promise<LicenseKeyVerification> {
213
+ return verifyProductToken(token, LICENSE_KEY_PREFIX, LicenseKeyPayloadSchema, options)
214
+ }
278
215
 
279
- return { status: "valid", kid: payload.kid, payload }
216
+ /**
217
+ * Verifies a commercial training grant offline against trusted public keys keyed by key ID.
218
+ *
219
+ * A valid grant still needs its permissions checked: {@linkcode trainingAdmission} in
220
+ * `@mailwoman/license/product/entitlement` checks that it permits training.
221
+ */
222
+ export function verifyTrainingGrant(
223
+ token: string,
224
+ options: { trustedKeys: Readonly<Record<string, string>>; now?: Date }
225
+ ): Promise<TrainingGrantVerification> {
226
+ return verifyProductToken(token, TRAINING_GRANT_PREFIX, TrainingGrantPayloadSchema, options)
280
227
  }
@@ -0,0 +1,193 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * Signs and verifies model provenance manifests (`<graph>.provenance.json`).
6
+ *
7
+ * `@mailwoman/license/product/provenance` defines the manifest, its payload and the refusal codes.
8
+ * `trainer-export` writes and signs the manifest in Rust when it exports a graph.
9
+ *
10
+ * This module verifies it against the files beside it and the provenance keys in the shared
11
+ * trust register, and it signs the manifest the issuer writes for a customer-submitted model.
12
+ * That signature attests only to the submitted bytes.
13
+ *
14
+ * A provenance key is separate from a license key: the trust register keeps them in
15
+ * separate lists, and a manifest verifies only under a provenance key.
16
+ */
17
+
18
+ import {
19
+ type BoundArtifact,
20
+ PROVENANCE_PREFIX,
21
+ type ProvenanceManifest,
22
+ ProvenanceManifestSchema,
23
+ type ProvenancePayload,
24
+ ProvenancePayloadSchema,
25
+ ProvenanceRefusal,
26
+ type ProvenanceVerification,
27
+ } from "@mailwoman/license/product/provenance"
28
+ import { schemaIssue } from "@mailwoman/license/product/token"
29
+ import { trustedProvenanceSigningKeys } from "@mailwoman/license/product/trust"
30
+ import { dirname, type PathBuilderLike, resolvePath } from "path-ts"
31
+
32
+ import { fromBase64URL, toBase64URL, utf8Bytes } from "#crypto/base64url"
33
+ import { ED25519_SIGNATURE_BYTES, signEd25519, verifyEd25519 } from "#crypto/ed25519"
34
+ import { sha256Hex } from "#crypto/hash"
35
+ import { readLocalBuffer, readLocalTextFile } from "#fs/readers"
36
+ import { stringifyJSON } from "#values/json"
37
+
38
+ /**
39
+ * A provenance signing key: its key ID and its PKCS8 private half.
40
+ */
41
+ export interface ProvenanceSigner {
42
+ kid: string
43
+ privateKeyPEM: string
44
+ }
45
+
46
+ /**
47
+ * Hashes each file under `directory` and returns the entries a manifest binds, in the order given.
48
+ *
49
+ * @throws When a file can't be read.
50
+ */
51
+ export async function bindArtifacts(directory: PathBuilderLike, paths: readonly string[]): Promise<BoundArtifact[]> {
52
+ const bound: BoundArtifact[] = []
53
+
54
+ for (const path of paths) {
55
+ const bytes = await readLocalBuffer(resolvePath(directory, path))
56
+
57
+ bound.push({ path, sha256: sha256Hex(bytes), bytes: bytes.length })
58
+ }
59
+
60
+ return bound
61
+ }
62
+
63
+ /**
64
+ * Validates a payload and returns its manifest, signed when a signer is given.
65
+ *
66
+ * An unsigned manifest must declare the `unattested` attestation, and a signed one must declare another.
67
+ */
68
+ export async function encodeProvenanceManifest(
69
+ payload: ProvenancePayload,
70
+ signer: ProvenanceSigner | null
71
+ ): Promise<ProvenanceManifest> {
72
+ const checked = ProvenancePayloadSchema.parse(payload)
73
+
74
+ if ((checked.attestation === "unattested") !== (signer == null)) {
75
+ throw new Error(`a manifest with attestation ${checked.attestation} must ${signer ? "not " : ""}be signed`)
76
+ }
77
+
78
+ const encoded = toBase64URL(utf8Bytes(stringifyJSON(checked)))
79
+
80
+ if (!signer) return { format: "mailwoman-model-provenance/1", payload: encoded, kid: null, signature: null }
81
+
82
+ const signature = await signEd25519(utf8Bytes(`${PROVENANCE_PREFIX}.${encoded}`), signer.privateKeyPEM)
83
+
84
+ return {
85
+ format: "mailwoman-model-provenance/1",
86
+ payload: encoded,
87
+ kid: signer.kid,
88
+ signature: toBase64URL(signature),
89
+ }
90
+ }
91
+
92
+ function manifestRefusal(refusal: ProvenanceRefusal, reason: string): ProvenanceVerification {
93
+ return { status: "refused", refusal, reason }
94
+ }
95
+
96
+ const STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true })
97
+
98
+ function manifestJSON(text: string): unknown {
99
+ try {
100
+ // oxlint-disable-next-line no-restricted-properties -- an unreadable manifest is a refusal with a reason.
101
+ return JSON.parse(text)
102
+ } catch {
103
+ return undefined
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Verifies a manifest file against the files beside it.
109
+ *
110
+ * It checks the manifest and payload schemas, the signature under a trusted provenance key,
111
+ * and each bound file's length and sha256.
112
+ * `requireSignature` refuses an unattested manifest.
113
+ * The commercial production path sets it.
114
+ */
115
+ export async function verifyProvenanceManifest(
116
+ manifestPath: PathBuilderLike,
117
+ options: { trustedKeys?: Readonly<Record<string, string>>; requireSignature?: boolean } = {}
118
+ ): Promise<ProvenanceVerification> {
119
+ const manifest = ProvenanceManifestSchema.safeParse(manifestJSON(await readLocalTextFile(manifestPath)))
120
+
121
+ if (!manifest.success) return manifestRefusal(ProvenanceRefusal.Malformed, `manifest: ${schemaIssue(manifest.error)}`)
122
+
123
+ let payloadText: string
124
+
125
+ try {
126
+ payloadText = STRICT_UTF8.decode(fromBase64URL(manifest.data.payload))
127
+ } catch {
128
+ return manifestRefusal(ProvenanceRefusal.Malformed, "payload is not base64url-encoded UTF-8")
129
+ }
130
+
131
+ const payload = ProvenancePayloadSchema.safeParse(manifestJSON(payloadText))
132
+
133
+ if (!payload.success) return manifestRefusal(ProvenanceRefusal.Malformed, `payload: ${schemaIssue(payload.error)}`)
134
+
135
+ const { kid, signature } = manifest.data
136
+
137
+ if (kid == null || signature == null) {
138
+ if (kid != null || signature != null) {
139
+ return manifestRefusal(ProvenanceRefusal.Malformed, "kid and signature must be both present or both null")
140
+ }
141
+
142
+ if (payload.data.attestation !== "unattested") {
143
+ return manifestRefusal(
144
+ ProvenanceRefusal.Unsigned,
145
+ `an unsigned manifest declares attestation ${payload.data.attestation}`
146
+ )
147
+ }
148
+
149
+ if (options.requireSignature) return manifestRefusal(ProvenanceRefusal.Unsigned, "the manifest is unsigned")
150
+ } else {
151
+ const publicKeyPEM = (options.trustedKeys ?? trustedProvenanceSigningKeys())[kid]
152
+
153
+ if (!publicKeyPEM) {
154
+ return manifestRefusal(
155
+ ProvenanceRefusal.UnknownKey,
156
+ `signed by provenance key id ${kid}, which this build does not trust`
157
+ )
158
+ }
159
+
160
+ const signatureBytes = fromBase64URL(signature)
161
+
162
+ const signed =
163
+ signatureBytes.length === ED25519_SIGNATURE_BYTES &&
164
+ (await verifyEd25519(utf8Bytes(`${PROVENANCE_PREFIX}.${manifest.data.payload}`), publicKeyPEM, signatureBytes))
165
+
166
+ if (!signed) return manifestRefusal(ProvenanceRefusal.BadSignature, `signature does not verify under key id ${kid}`)
167
+
168
+ if (payload.data.attestation === "unattested") {
169
+ return manifestRefusal(ProvenanceRefusal.Malformed, "a signed manifest declares attestation unattested")
170
+ }
171
+ }
172
+
173
+ const directory = dirname(resolvePath(manifestPath))
174
+
175
+ for (const artifact of payload.data.artifacts) {
176
+ let bytes: Buffer
177
+
178
+ try {
179
+ bytes = await readLocalBuffer(resolvePath(directory, artifact.path))
180
+ } catch {
181
+ return manifestRefusal(ProvenanceRefusal.ArtifactMismatch, `${artifact.path} is missing beside the manifest`)
182
+ }
183
+
184
+ if (bytes.length !== artifact.bytes || sha256Hex(bytes) !== artifact.sha256) {
185
+ return manifestRefusal(
186
+ ProvenanceRefusal.ArtifactMismatch,
187
+ `${artifact.path} differs from the bytes the manifest binds`
188
+ )
189
+ }
190
+ }
191
+
192
+ return { status: "verified", kid, payload: payload.data }
193
+ }