Skip to content

Commit 10809df

Browse files
committed
fix: Update docs for audit signatures cmd
Update command documentation for `npm audit signatures` added in this PR: #4827
1 parent 0c209ff commit 10809df

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

docs/content/commands/npm-audit.md

+49-8
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,55 @@ output, it simply changes the command's failure threshold.
4343

4444
### Audit Signatures
4545

46-
This command can also audit the integrity values of the packages in your
47-
tree against any signatures present in the registry they were downloaded
48-
from. npm will attempt to download the keys from `/-/npm/v1/keys` on
49-
each the registry used to download any given package. It will then
50-
check the `dist.signatures` object in the package itself, and verify the
51-
`sig` present there using the `keyid` there, matching it with a key
52-
returned from the registry. The command for this is `npm audit
53-
signatures`
46+
To ensure the integrity of packages you download from the public npm registry, or any registry that supports signatures, you can verify the registry signatures of downloaded packages using the npm CLI.
47+
48+
Registry signatures can be verified using the following `audit` command:
49+
50+
```bash
51+
$ npm audit signatures
52+
```
53+
54+
The npm CLI supports registry signatures and signing keys provided by any registry if the following conventions are followed:
55+
56+
1. Signatures are provided in the package's `packument` in each published version within the `dist` object:
57+
58+
```json
59+
"dist":{
60+
"..omitted..": "..omitted..",
61+
"signatures": [{
62+
"keyid": "SHA256:{{SHA256_PUBLIC_KEY}}",
63+
"sig": "a312b9c3cb4a1b693e8ebac5ee1ca9cc01f2661c14391917dcb111517f72370809..."
64+
}]
65+
}
66+
```
67+
68+
See this [example](https://registry.npmjs.org/light-cycle/1.4.3) of a signed package from the public npm registry.
69+
70+
The `sig` is generated using the following template: `${package.name}@${package.version}:${package.dist.integrity}` and the `keyid` has to match one of the public signing keys below.
71+
72+
2. Public signing keys are provided at `registry-host.tld/-/npm/v1/keys` in the following format:
73+
74+
```
75+
{
76+
"keys": [{
77+
"expires": null,
78+
"keyid": "SHA256:{{SHA256_PUBLIC_KEY}}",
79+
"keytype": "ecdsa-sha2-nistp256",
80+
"scheme": "ecdsa-sha2-nistp256",
81+
"key": "{{B64_PUBLIC_KEY}}"
82+
}]
83+
}
84+
```
85+
86+
Keys response:
87+
88+
- `expires`: null or a simplified extended <a href="https://en.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601 format</a>: `YYYY-MM-DDTHH:mm:ss.sssZ`
89+
- `keydid`: sha256 fingerprint of the public key
90+
- `keytype`: only `ecdsa-sha2-nistp256` is currently supported by the npm CLI
91+
- `scheme`: only `ecdsa-sha2-nistp256` is currently supported by the npm CLI
92+
- `key`: base64 encoded public key
93+
94+
See this <a href="https://registry.npmjs.org/-/npm/v1/keys" target="_blank">example key's response from the public npm registry</a>.
5495

5596
### Audit Endpoints
5697

0 commit comments

Comments
 (0)