Skip to content

npm: typed access to dist.attestations and dist.signatures#26

Merged
andrew merged 1 commit into
mainfrom
npm-provenance-metadata
May 12, 2026
Merged

npm: typed access to dist.attestations and dist.signatures#26
andrew merged 1 commit into
mainfrom
npm-provenance-metadata

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 12, 2026

Summary

npm exposes two metadata signals alongside each published version when the publisher used trusted publishing: a `dist.attestations` pointer at the separately-fetched sigstore bundle, and a `dist.signatures` array of ECDSA-P256 signatures over `{name}@{version}:{integrity}`. Both were silently dropped during JSON decode because `distInfo` only carried `shasum`/`tarball`/`integrity`.

This PR captures and exposes them.

Changes

  • `internal/npm.distInfo` gains `Attestations *AttestationRef` and `Signatures []Signature` fields. New exported types `AttestationRef` and `Signature` mirror npm's JSON shape.
  • `FetchVersions` populates the per-version `Metadata` map with two new keys, `npm:attestations` (`*AttestationRef`) and `npm:signatures` (`[]Signature`).
  • Top-level `registries` package exports type aliases `NPMAttestationRef` / `NPMSignature` plus a `NPMProvenance(*Version) (*NPMAttestationRef, []NPMSignature)` helper so callers don't have to cast through `map[string]any`.

Tests

`TestFetchVersions_Provenance` asserts both fields round-trip with the expected typed shapes. `TestFetchVersions_NoProvenance` asserts the no-provenance case returns nil / empty without panic.

Why

Consumers that want to verify the registry-published signatures or fetch the sigstore bundle from `dist.attestations.url` can do so without re-parsing the version document themselves.

When a publisher uses trusted publishing, npm exposes two metadata
signals alongside each version: a dist.attestations pointer at the
separately-fetched sigstore bundle, and a dist.signatures array of
ECDSA-P256 signatures over '{name}@{version}:{integrity}'. Both were
silently dropped during JSON decode because distInfo only carried
shasum/tarball/integrity.

Adds typed structs (npm.AttestationRef, npm.Signature) and populates
them through to Version.Metadata under 'npm:attestations' and
'npm:signatures' keys. Top-level registries package exports type
aliases NPMAttestationRef / NPMSignature plus a NPMProvenance helper
so callers can read the typed values without re-casting through
map[string]any.

Callers that want to validate the registry-published signatures or
fetch the sigstore bundle from dist.attestations.url can now do so
without re-parsing the version document themselves.
@andrew andrew merged commit d54f633 into main May 12, 2026
5 checks passed
@andrew andrew deleted the npm-provenance-metadata branch May 12, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant