@mailwoman/core 11.2.0 → 11.4.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.
- package/README.md +2 -2
- package/lib/api/ckan.ts +1 -1
- package/lib/api/disk-storage.ts +2 -2
- package/lib/api/ogc.ts +1 -1
- package/lib/api/retry.ts +7 -2
- package/lib/api/test/transport.ts +1 -1
- package/lib/{binary-frame.ts → asset/binary-frame.ts} +1 -1
- package/lib/async/abort.ts +100 -0
- package/lib/{memoize.ts → async/memoize.ts} +2 -2
- package/lib/{promises.ts → async/promises.ts} +1 -1
- package/lib/cloudflare/tokens.ts +1 -1
- package/lib/cloudflare/wrangler.ts +3 -3
- package/lib/crypto/digest.ts +1 -1
- package/lib/crypto/ed25519.ts +8 -0
- package/lib/{hash.ts → crypto/hash.ts} +16 -1
- package/lib/crypto/node.ts +1 -1
- package/lib/data-root.ts +16 -3
- package/lib/decoder/containment.ts +4 -1
- package/lib/decoder/serialize/outline.ts +19 -6
- package/lib/decoder/types.ts +9 -1
- package/lib/env/schema.ts +5 -0
- package/lib/fs/deflate64.ts +1 -1
- package/lib/fs/lock.ts +183 -25
- package/lib/fs/readers.ts +1 -1
- package/lib/fs/writers.ts +18 -1
- package/lib/geocode/result.ts +50 -6
- package/lib/html/text.ts +2 -2
- package/lib/index.ts +0 -1
- package/lib/layers/artifact.ts +2 -2
- package/lib/layers/coverage.ts +1 -1
- package/lib/layers/manifest.ts +94 -2
- package/lib/layers/provenance.ts +246 -0
- package/lib/layers/publication.ts +4 -3
- package/lib/layers/selection.ts +2 -2
- package/lib/license/branch.ts +66 -0
- package/lib/license/configured.ts +4 -2
- package/lib/license/declaration.ts +1 -1
- package/lib/license/key/file.ts +1 -1
- package/lib/license/key.ts +148 -201
- package/lib/license/provenance.ts +193 -0
- package/lib/license/register.ts +7 -78
- package/lib/license/stamp.ts +8 -2
- package/lib/license/text-url.ts +55 -0
- package/lib/license/training.ts +67 -0
- package/lib/license.ts +7 -6
- package/lib/locale/registry.ts +1 -1
- package/lib/locale/zh-cn-units.ts +1 -1
- package/lib/module/workspace.ts +1 -1
- package/lib/{routing.ts → network/routing.ts} +1 -1
- package/lib/pipeline/result.ts +6 -25
- package/lib/pipeline/runtime-pipeline.ts +129 -144
- package/lib/pipeline/stage.ts +290 -0
- package/lib/pipeline/types.ts +33 -14
- package/lib/pipeline.ts +14 -2
- package/lib/{git.ts → repo/git.ts} +21 -1
- package/lib/{release-config.ts → repo/release-config.ts} +8 -0
- package/lib/{spdx-header.ts → repo/spdx-header.ts} +8 -0
- package/lib/{workspaces.ts → repo/workspaces.ts} +1 -1
- package/lib/resolver/lookup-types.ts +1 -1
- package/lib/resolver/region-database-provider.ts +33 -0
- package/lib/resolver/synthetic-id-ranges.ts +19 -9
- package/lib/resolver/types.ts +220 -7
- package/lib/resolver.ts +14 -1
- package/lib/state-machine.ts +1 -1
- package/lib/strings/python-json.ts +3 -2
- package/lib/utils/chunk-process.ts +2 -2
- package/lib/utils/geodatabase-archive.ts +1 -1
- package/lib/utils/time.ts +136 -12
- package/lib/utils.ts +4 -4
- package/out/api/ckan.js +1 -1
- package/out/api/ckan.js.map +1 -1
- package/out/api/disk-storage.d.ts.map +1 -1
- package/out/api/disk-storage.js +2 -2
- package/out/api/disk-storage.js.map +1 -1
- package/out/api/ogc.js +1 -1
- package/out/api/ogc.js.map +1 -1
- package/out/api/retry.d.ts.map +1 -1
- package/out/api/retry.js +6 -2
- package/out/api/retry.js.map +1 -1
- package/out/api/test/transport.js +1 -1
- package/out/api/test/transport.js.map +1 -1
- package/out/asset/binary-frame.d.ts.map +1 -0
- package/out/{binary-frame.js → asset/binary-frame.js} +1 -1
- package/out/asset/binary-frame.js.map +1 -0
- package/out/asset/load-ledger.d.ts.map +1 -0
- package/out/asset/load-ledger.js.map +1 -0
- package/out/asset/overture-pins.d.ts.map +1 -0
- package/out/asset/overture-pins.js.map +1 -0
- package/out/asset/postcode-prefix-files.d.ts.map +1 -0
- package/out/asset/postcode-prefix-files.js.map +1 -0
- package/out/async/abort.d.ts +57 -0
- package/out/async/abort.d.ts.map +1 -0
- package/out/async/abort.js +89 -0
- package/out/async/abort.js.map +1 -0
- package/out/async/memoize.d.ts.map +1 -0
- package/out/{memoize.js → async/memoize.js} +2 -2
- package/out/async/memoize.js.map +1 -0
- package/out/{promises.d.ts → async/promises.d.ts} +1 -1
- package/out/async/promises.d.ts.map +1 -0
- package/out/{promises.js → async/promises.js} +1 -1
- package/out/async/promises.js.map +1 -0
- package/out/cloudflare/tokens.js +1 -1
- package/out/cloudflare/tokens.js.map +1 -1
- package/out/cloudflare/wrangler.js +3 -3
- package/out/cloudflare/wrangler.js.map +1 -1
- package/out/crypto/digest.d.ts +1 -1
- package/out/crypto/digest.js +1 -1
- package/out/crypto/ed25519.d.ts +7 -0
- package/out/crypto/ed25519.d.ts.map +1 -1
- package/out/crypto/ed25519.js +7 -0
- package/out/crypto/ed25519.js.map +1 -1
- package/out/{hash.d.ts → crypto/hash.d.ts} +12 -0
- package/out/crypto/hash.d.ts.map +1 -0
- package/out/{hash.js → crypto/hash.js} +15 -1
- package/out/crypto/hash.js.map +1 -0
- package/out/crypto/node.js +1 -1
- package/out/crypto/node.js.map +1 -1
- package/out/data-root.d.ts +11 -3
- package/out/data-root.d.ts.map +1 -1
- package/out/data-root.js +14 -3
- package/out/data-root.js.map +1 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +1 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/serialize/outline.d.ts +9 -0
- package/out/decoder/serialize/outline.d.ts.map +1 -1
- package/out/decoder/serialize/outline.js +16 -6
- package/out/decoder/serialize/outline.js.map +1 -1
- package/out/decoder/types.d.ts +8 -0
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/types.js +1 -1
- package/out/decoder/types.js.map +1 -1
- package/out/env/schema.d.ts +1 -0
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +4 -0
- package/out/env/schema.js.map +1 -1
- package/out/env.d.ts +1 -0
- package/out/env.d.ts.map +1 -1
- package/out/fs/deflate64.js +1 -1
- package/out/fs/deflate64.js.map +1 -1
- package/out/fs/lock.d.ts +73 -4
- package/out/fs/lock.d.ts.map +1 -1
- package/out/fs/lock.js +96 -19
- package/out/fs/lock.js.map +1 -1
- package/out/fs/readers.js +1 -1
- package/out/fs/readers.js.map +1 -1
- package/out/fs/writers.d.ts +9 -1
- package/out/fs/writers.d.ts.map +1 -1
- package/out/fs/writers.js +15 -2
- package/out/fs/writers.js.map +1 -1
- package/out/geocode/result.d.ts +25 -1
- package/out/geocode/result.d.ts.map +1 -1
- package/out/geocode/result.js +49 -6
- package/out/geocode/result.js.map +1 -1
- package/out/html/text.js +2 -2
- package/out/html/trust-policies.d.ts.map +1 -0
- package/out/html/trust-policies.js.map +1 -0
- package/out/index.d.ts +0 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +0 -1
- package/out/index.js.map +1 -1
- package/out/layers/artifact.js +2 -2
- package/out/layers/artifact.js.map +1 -1
- package/out/layers/coverage.d.ts.map +1 -1
- package/out/layers/coverage.js +1 -1
- package/out/layers/coverage.js.map +1 -1
- package/out/layers/manifest.d.ts +53 -0
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +68 -2
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/provenance.d.ts +127 -0
- package/out/layers/provenance.d.ts.map +1 -0
- package/out/layers/provenance.js +122 -0
- package/out/layers/provenance.js.map +1 -0
- package/out/layers/publication.d.ts.map +1 -1
- package/out/layers/publication.js +3 -3
- package/out/layers/publication.js.map +1 -1
- package/out/layers/selection.d.ts.map +1 -1
- package/out/layers/selection.js +2 -2
- package/out/layers/selection.js.map +1 -1
- package/out/license/branch.d.ts +33 -0
- package/out/license/branch.d.ts.map +1 -0
- package/out/license/branch.js +52 -0
- package/out/license/branch.js.map +1 -0
- package/out/license/configured.d.ts +1 -1
- package/out/license/configured.d.ts.map +1 -1
- package/out/license/configured.js +1 -9
- package/out/license/configured.js.map +1 -1
- package/out/license/declaration.d.ts +1 -1
- package/out/license/declaration.d.ts.map +1 -1
- package/out/license/key/file.js +1 -1
- package/out/license/key/file.js.map +1 -1
- package/out/license/key.d.ts +27 -115
- package/out/license/key.d.ts.map +1 -1
- package/out/license/key.js +98 -164
- package/out/license/key.js.map +1 -1
- package/out/license/provenance.d.ts +47 -0
- package/out/license/provenance.d.ts.map +1 -0
- package/out/license/provenance.js +134 -0
- package/out/license/provenance.js.map +1 -0
- package/out/license/register.d.ts +6 -47
- package/out/license/register.d.ts.map +1 -1
- package/out/license/register.js +7 -58
- package/out/license/register.js.map +1 -1
- package/out/license/stamp.d.ts +7 -1
- package/out/license/stamp.d.ts.map +1 -1
- package/out/license/stamp.js +2 -2
- package/out/license/stamp.js.map +1 -1
- package/out/license/text-url.d.ts +9 -0
- package/out/license/text-url.d.ts.map +1 -0
- package/out/license/text-url.js +49 -0
- package/out/license/text-url.js.map +1 -0
- package/out/license/training.d.ts +29 -0
- package/out/license/training.d.ts.map +1 -0
- package/out/license/training.js +52 -0
- package/out/license/training.js.map +1 -0
- package/out/license.d.ts +7 -6
- package/out/license.d.ts.map +1 -1
- package/out/license.js +7 -6
- package/out/license.js.map +1 -1
- package/out/locale/registry.d.ts.map +1 -1
- package/out/locale/registry.js +1 -1
- package/out/locale/registry.js.map +1 -1
- package/out/locale/zh-cn-units.js +1 -1
- package/out/locale/zh-cn-units.js.map +1 -1
- package/out/math/numeric.d.ts.map +1 -0
- package/out/math/numeric.js.map +1 -0
- package/out/math/random.d.ts.map +1 -0
- package/out/math/random.js.map +1 -0
- package/out/math/stats.d.ts.map +1 -0
- package/out/math/stats.js.map +1 -0
- package/out/module/workspace.js +1 -1
- package/out/module/workspace.js.map +1 -1
- package/out/network/routing.d.ts.map +1 -0
- package/out/{routing.js → network/routing.js} +1 -1
- package/out/network/routing.js.map +1 -0
- package/out/pipeline/result.d.ts +7 -24
- package/out/pipeline/result.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +7 -2
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +56 -103
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/stage.d.ts +180 -0
- package/out/pipeline/stage.d.ts.map +1 -0
- package/out/pipeline/stage.js +130 -0
- package/out/pipeline/stage.js.map +1 -0
- package/out/pipeline/types.d.ts +31 -12
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +0 -8
- package/out/pipeline/types.js.map +1 -1
- package/out/pipeline.d.ts +5 -3
- package/out/pipeline.d.ts.map +1 -1
- package/out/pipeline.js +2 -1
- package/out/pipeline.js.map +1 -1
- package/out/{git.d.ts → repo/git.d.ts} +10 -1
- package/out/repo/git.d.ts.map +1 -0
- package/out/{git.js → repo/git.js} +14 -1
- package/out/repo/git.js.map +1 -0
- package/out/{release-config.d.ts → repo/release-config.d.ts} +8 -0
- package/out/repo/release-config.d.ts.map +1 -0
- package/out/repo/release-config.js.map +1 -0
- package/out/repo/scope-config.d.ts.map +1 -0
- package/out/repo/scope-config.js.map +1 -0
- package/out/repo/spdx-header.d.ts.map +1 -0
- package/out/{spdx-header.js → repo/spdx-header.js} +7 -0
- package/out/repo/spdx-header.js.map +1 -0
- package/out/repo/vale.d.ts.map +1 -0
- package/out/repo/vale.js.map +1 -0
- package/out/repo/workspaces.d.ts.map +1 -0
- package/out/{workspaces.js → repo/workspaces.js} +1 -1
- package/out/repo/workspaces.js.map +1 -0
- package/out/resolver/lookup-types.d.ts +1 -1
- package/out/resolver/region-database-provider.d.ts +30 -0
- package/out/resolver/region-database-provider.d.ts.map +1 -1
- package/out/resolver/synthetic-id-ranges.d.ts +15 -8
- package/out/resolver/synthetic-id-ranges.d.ts.map +1 -1
- package/out/resolver/synthetic-id-ranges.js +18 -9
- package/out/resolver/synthetic-id-ranges.js.map +1 -1
- package/out/resolver/types.d.ts +192 -8
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +56 -0
- package/out/resolver/types.js.map +1 -1
- package/out/resolver.d.ts +3 -3
- package/out/resolver.d.ts.map +1 -1
- package/out/resolver.js +1 -1
- package/out/resolver.js.map +1 -1
- package/out/scripting/process.d.ts.map +1 -0
- package/out/scripting/process.js.map +1 -0
- package/out/scripting/workers.d.ts.map +1 -0
- package/out/scripting/workers.js.map +1 -0
- package/out/state-machine.d.ts +1 -1
- package/out/strings/python-json.d.ts +2 -1
- package/out/strings/python-json.d.ts.map +1 -1
- package/out/strings/python-json.js +1 -1
- package/out/strings/python-json.js.map +1 -1
- package/out/tools/build-deflate64-wasm.run.js +2 -2
- package/out/tools/build-deflate64-wasm.run.js.map +1 -1
- package/out/tools/coarse-placer/build/dataset.js +1 -1
- package/out/tools/coarse-placer/build/dataset.js.map +1 -1
- package/out/tools/coarse-placer/build/outlier/exposure.js +1 -1
- package/out/tools/coarse-placer/build/outlier/exposure.js.map +1 -1
- package/out/tools/coarse-placer/build/outlier/latin.d.ts.map +1 -1
- package/out/tools/coarse-placer/build/outlier/latin.js +5 -1
- package/out/tools/coarse-placer/build/outlier/latin.js.map +1 -1
- package/out/tools/coarse-placer/country-sets.d.ts +2 -2
- package/out/tools/coarse-placer/country-sets.js +2 -2
- package/out/tools/coarse-placer/outlier-rows.js +2 -2
- package/out/tools/coarse-placer/outlier-rows.js.map +1 -1
- package/out/tools/coarse-placer/train.js +1 -1
- package/out/tools/coarse-placer/train.js.map +1 -1
- package/out/tools/generate-language-types.js +2 -2
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/tools/license/product-fixtures.run.d.ts +2 -0
- package/out/tools/license/product-fixtures.run.d.ts.map +1 -0
- package/out/tools/license/product-fixtures.run.js +350 -0
- package/out/tools/license/product-fixtures.run.js.map +1 -0
- package/out/utils/chunk-process.js +2 -2
- package/out/utils/chunk-process.js.map +1 -1
- package/out/utils/geodatabase-archive.js +1 -1
- package/out/utils/geodatabase-archive.js.map +1 -1
- package/out/utils/time.d.ts +15 -4
- package/out/utils/time.d.ts.map +1 -1
- package/out/utils/time.js +114 -12
- package/out/utils/time.js.map +1 -1
- package/out/utils.d.ts +4 -4
- package/out/utils.d.ts.map +1 -1
- package/out/utils.js +4 -4
- package/out/utils.js.map +1 -1
- package/out/values/identical.d.ts.map +1 -0
- package/out/values/identical.js.map +1 -0
- package/out/values/json.d.ts.map +1 -0
- package/out/values/json.js.map +1 -0
- package/out/values/objects.d.ts.map +1 -0
- package/out/values/objects.js.map +1 -0
- package/package.json +278 -243
- package/tools/build-deflate64-wasm.run.ts +2 -2
- package/tools/coarse-placer/build/dataset.ts +1 -1
- package/tools/coarse-placer/build/outlier/exposure.ts +1 -1
- package/tools/coarse-placer/build/outlier/latin.ts +5 -1
- package/tools/coarse-placer/country-sets.ts +2 -2
- package/tools/coarse-placer/outlier-rows.ts +2 -2
- package/tools/coarse-placer/train.ts +1 -1
- package/tools/generate-language-types.ts +2 -2
- package/tools/license/product-fixtures.run.ts +449 -0
- package/lib/collections.ts +0 -5
- package/lib/license/decision.ts +0 -329
- package/lib/license/obligations.ts +0 -256
- package/lib/license/record.ts +0 -277
- package/lib/scripting/ingest-chunk-script.ts +0 -87
- package/out/binary-frame.d.ts.map +0 -1
- package/out/binary-frame.js.map +0 -1
- package/out/collections.d.ts +0 -2
- package/out/collections.d.ts.map +0 -1
- package/out/collections.js +0 -5
- package/out/collections.js.map +0 -1
- package/out/git.d.ts.map +0 -1
- package/out/git.js.map +0 -1
- package/out/hash.d.ts.map +0 -1
- package/out/hash.js.map +0 -1
- package/out/identical.d.ts.map +0 -1
- package/out/identical.js.map +0 -1
- package/out/json.d.ts.map +0 -1
- package/out/json.js.map +0 -1
- package/out/license/decision.d.ts +0 -179
- package/out/license/decision.d.ts.map +0 -1
- package/out/license/decision.js +0 -169
- package/out/license/decision.js.map +0 -1
- package/out/license/obligations.d.ts +0 -102
- package/out/license/obligations.d.ts.map +0 -1
- package/out/license/obligations.js +0 -188
- package/out/license/obligations.js.map +0 -1
- package/out/license/record.d.ts +0 -136
- package/out/license/record.d.ts.map +0 -1
- package/out/license/record.js +0 -222
- package/out/license/record.js.map +0 -1
- package/out/load-ledger.d.ts.map +0 -1
- package/out/load-ledger.js.map +0 -1
- package/out/memoize.d.ts.map +0 -1
- package/out/memoize.js.map +0 -1
- package/out/numeric.d.ts.map +0 -1
- package/out/numeric.js.map +0 -1
- package/out/objects.d.ts.map +0 -1
- package/out/objects.js.map +0 -1
- package/out/overture-pins.d.ts.map +0 -1
- package/out/overture-pins.js.map +0 -1
- package/out/postcode-prefix-files.d.ts.map +0 -1
- package/out/postcode-prefix-files.js.map +0 -1
- package/out/process.d.ts.map +0 -1
- package/out/process.js.map +0 -1
- package/out/promises.d.ts.map +0 -1
- package/out/promises.js.map +0 -1
- package/out/random.d.ts.map +0 -1
- package/out/random.js.map +0 -1
- package/out/release-config.d.ts.map +0 -1
- package/out/release-config.js.map +0 -1
- package/out/routing.d.ts.map +0 -1
- package/out/routing.js.map +0 -1
- package/out/scope-config.d.ts.map +0 -1
- package/out/scope-config.js.map +0 -1
- package/out/scripting/ingest-chunk-script.d.ts +0 -58
- package/out/scripting/ingest-chunk-script.d.ts.map +0 -1
- package/out/scripting/ingest-chunk-script.js +0 -47
- package/out/scripting/ingest-chunk-script.js.map +0 -1
- package/out/spdx-header.d.ts.map +0 -1
- package/out/spdx-header.js.map +0 -1
- package/out/stats.d.ts.map +0 -1
- package/out/stats.js.map +0 -1
- package/out/trust-policies.d.ts.map +0 -1
- package/out/trust-policies.js.map +0 -1
- package/out/vale.d.ts.map +0 -1
- package/out/vale.js.map +0 -1
- package/out/workers.d.ts.map +0 -1
- package/out/workers.js.map +0 -1
- package/out/workspaces.d.ts.map +0 -1
- package/out/workspaces.js.map +0 -1
- /package/lib/{load-ledger.ts → asset/load-ledger.ts} +0 -0
- /package/lib/{overture-pins.ts → asset/overture-pins.ts} +0 -0
- /package/lib/{postcode-prefix-files.ts → asset/postcode-prefix-files.ts} +0 -0
- /package/lib/{trust-policies.ts → html/trust-policies.ts} +0 -0
- /package/lib/{numeric.ts → math/numeric.ts} +0 -0
- /package/lib/{random.ts → math/random.ts} +0 -0
- /package/lib/{stats.ts → math/stats.ts} +0 -0
- /package/lib/{scope-config.ts → repo/scope-config.ts} +0 -0
- /package/lib/{vale.ts → repo/vale.ts} +0 -0
- /package/lib/{process.ts → scripting/process.ts} +0 -0
- /package/lib/{workers.ts → scripting/workers.ts} +0 -0
- /package/lib/{identical.ts → values/identical.ts} +0 -0
- /package/lib/{json.ts → values/json.ts} +0 -0
- /package/lib/{objects.ts → values/objects.ts} +0 -0
- /package/out/{binary-frame.d.ts → asset/binary-frame.d.ts} +0 -0
- /package/out/{load-ledger.d.ts → asset/load-ledger.d.ts} +0 -0
- /package/out/{load-ledger.js → asset/load-ledger.js} +0 -0
- /package/out/{overture-pins.d.ts → asset/overture-pins.d.ts} +0 -0
- /package/out/{overture-pins.js → asset/overture-pins.js} +0 -0
- /package/out/{postcode-prefix-files.d.ts → asset/postcode-prefix-files.d.ts} +0 -0
- /package/out/{postcode-prefix-files.js → asset/postcode-prefix-files.js} +0 -0
- /package/out/{memoize.d.ts → async/memoize.d.ts} +0 -0
- /package/out/{trust-policies.d.ts → html/trust-policies.d.ts} +0 -0
- /package/out/{trust-policies.js → html/trust-policies.js} +0 -0
- /package/out/{numeric.d.ts → math/numeric.d.ts} +0 -0
- /package/out/{numeric.js → math/numeric.js} +0 -0
- /package/out/{random.d.ts → math/random.d.ts} +0 -0
- /package/out/{random.js → math/random.js} +0 -0
- /package/out/{stats.d.ts → math/stats.d.ts} +0 -0
- /package/out/{stats.js → math/stats.js} +0 -0
- /package/out/{routing.d.ts → network/routing.d.ts} +0 -0
- /package/out/{release-config.js → repo/release-config.js} +0 -0
- /package/out/{scope-config.d.ts → repo/scope-config.d.ts} +0 -0
- /package/out/{scope-config.js → repo/scope-config.js} +0 -0
- /package/out/{spdx-header.d.ts → repo/spdx-header.d.ts} +0 -0
- /package/out/{vale.d.ts → repo/vale.d.ts} +0 -0
- /package/out/{vale.js → repo/vale.js} +0 -0
- /package/out/{workspaces.d.ts → repo/workspaces.d.ts} +0 -0
- /package/out/{process.d.ts → scripting/process.d.ts} +0 -0
- /package/out/{process.js → scripting/process.js} +0 -0
- /package/out/{workers.d.ts → scripting/workers.d.ts} +0 -0
- /package/out/{workers.js → scripting/workers.js} +0 -0
- /package/out/{identical.d.ts → values/identical.d.ts} +0 -0
- /package/out/{identical.js → values/identical.js} +0 -0
- /package/out/{json.d.ts → values/json.d.ts} +0 -0
- /package/out/{json.js → values/json.js} +0 -0
- /package/out/{objects.d.ts → values/objects.d.ts} +0 -0
- /package/out/{objects.js → values/objects.js} +0 -0
package/lib/license/key.ts
CHANGED
|
@@ -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
|
|
5
|
+
* Encodes and verifies Mailwoman's offline product tokens: platform license keys
|
|
6
|
+
* (`mwl1`) and commercial training grants (`mwt1`).
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 {
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
48
|
+
export interface LicenseSigningKeyPair {
|
|
49
|
+
privateKeyPEM: string
|
|
50
|
+
publicKeyPEM: string
|
|
51
|
+
}
|
|
35
52
|
|
|
36
53
|
/**
|
|
37
|
-
*
|
|
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
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
69
|
+
return `${use}${majorVersion}-${digest}`
|
|
70
|
+
}
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
|
-
* The
|
|
73
|
+
* The key ID of a license signing key: `v<major>-<eight hex digits>`.
|
|
69
74
|
*/
|
|
70
|
-
export
|
|
75
|
+
export function licenseKeyID(publicKeyPEM: string, majorVersion: number): Promise<string> {
|
|
76
|
+
return keyID(publicKeyPEM, majorVersion, "v")
|
|
77
|
+
}
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
|
-
* The
|
|
80
|
+
* The key ID of a provenance signing key: `p<major>-<eight hex digits>`.
|
|
74
81
|
*/
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
154
|
-
return
|
|
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
|
-
*
|
|
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
|
|
162
|
-
return
|
|
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
|
-
*
|
|
110
|
+
* A token read as far as its signature: its parts and its validated payload, or the reason it's malformed.
|
|
177
111
|
*/
|
|
178
|
-
|
|
179
|
-
privateKeyPEM: string
|
|
180
|
-
publicKeyPEM: string
|
|
181
|
-
}
|
|
112
|
+
type ProductTokenReading<P> = { parts: ProductTokenParts; payload: P } | { reason: string }
|
|
182
113
|
|
|
183
114
|
/**
|
|
184
|
-
*
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
120
|
+
function readProductToken<P>(token: string, prefix: ProductTokenPrefix, schema: z.ZodType<P>): ProductTokenReading<P> {
|
|
121
|
+
const parts = splitProductToken(token)
|
|
189
122
|
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
|
160
|
+
const reading = readProductToken(token, LICENSE_KEY_PREFIX, LicenseKeyPayloadSchema)
|
|
223
161
|
|
|
224
|
-
|
|
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<
|
|
242
|
-
const
|
|
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
|
-
|
|
252
|
-
|
|
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
|
|
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
|
|
198
|
+
const expires = payload.expires
|
|
199
|
+
const expired = expires != null && licenseExpiryInstant(expires) < (options.now ?? new Date())
|
|
274
200
|
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
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
|
+
}
|