Format
A Package Integrity build is one or more integrity digests appended as build metadata:
<version>+<algorithm>.<digest> ( .<algorithm>.<digest> )*<algorithm>: one ofsha256,sha384,sha512. The set is extensible; consumers MUST ignore digests whose algorithm they don't recognise and MUST NOT treat that as a failure by itself.<digest>: the raw hash encoded as lowercase hex (canonical,[0-9a-f]+) or compact Base62 ([0-9A-Za-z]+). Both are valid build identifiers.- Algorithm and digest are two dot-separated build identifiers, so the pair tokenises trivially.
- Multiple digests MAY be present and SHOULD be ordered weakest-to-strongest.
Canonical hex lengths: sha256 → 64, sha384 → 96, sha512 → 128 characters.
Precedence
Package Integrity relies on Semantic Versions precedence: build identifiers are compared, so a digest-bearing version is ordered and distinguishable rather than collapsed away. Integrity is advisory to precedence but authoritative to trust: the digest doesn't change what a version means, but a mismatch MUST cause the artifact to be rejected.
Verification
- Resolve
name@versionfrom the named source (npm:→ the registry). - Obtain the artifact (for npm, the version's tarball).
- Compute the digest of the artifact bytes with
<algorithm>. - Transcode and compare to
<digest>. It satisfies the identity iff every listed algorithm the consumer supports matches, and at least one supported algorithm was present. - A mismatch MUST be a fatal integrity error.
The transcoding is lossless: npm's sha512-<base64> is the same bytes as sha512.<hex> here.
vs. Dependency Locks
Dependency Locks capture integrity for an
entire resolved subgraph in a digest table. Package Integrity is the single-artifact,
inline form for one identity. They compose: a lock pins the graph; an inline digest
pins one package where a full lock is unnecessary. A digest also composes with a
Build Variant:
1.0.0+linux.x64.musl.sha512.… pins the exact bytes of one target.
Grammar (BNF)
Building on VERSION.bnf's <build>:
<integrity build> ::= <integrity> ( "." <integrity> )*
<integrity> ::= <algorithm> "." <digest>
<algorithm> ::= "sha256" | "sha384" | "sha512"
<digest> ::= <hex digest> | <base62 digest>
<hex digest> ::= <hex> <hex>+
<base62 digest> ::= <base62 char> <base62 char>+
<hex> ::= "0" … "9" | "a" … "f"
<base62 char> ::= "0" … "9" | "A" … "Z" | "a" … "z"