-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import urlJoin from "url-join"; | ||
import { z } from "zod"; | ||
import { fetchData } from "./fetch-data"; | ||
import { npmRegistryUrl } from "./npm-registry"; | ||
|
||
/** | ||
Zod schema for the registry signing keys. | ||
*/ | ||
export const registrySigningKeysSchema = z | ||
.object({ | ||
keys: z.array( | ||
z | ||
.object({ | ||
/** | ||
String in the simplified extended ISO 8601 format: `YYYY-MM-DDTHH:mm:ss.sssZ` or `null`. | ||
*/ | ||
expires: z.string().nullable(), | ||
|
||
/** SHA256 fingerprint of the public key. */ | ||
keyid: z.string(), | ||
|
||
/** Key type; only `ecdsa-sha2-nistp256` is currently supported by the npm CLI. */ | ||
keytype: z.string(), | ||
|
||
/** Key scheme; only `ecdsa-sha2-nistp256` is currently supported by the npm CLI. */ | ||
scheme: z.string(), | ||
|
||
/** Public key encoded in base64. */ | ||
key: z.string(), | ||
}) | ||
.passthrough(), | ||
), | ||
}) | ||
.passthrough(); | ||
|
||
/** | ||
`RegistrySigningKeys` describes the signing keys used by the registry. | ||
@see {@link https://docs.npmjs.com/about-registry-signatures} | ||
*/ | ||
export type RegistrySigningKeys = z.infer<typeof registrySigningKeysSchema>; | ||
|
||
/** | ||
`getRegistrySigningKeys` returns the public signing keys used by the registry. | ||
@param registry - URL of the registry (default: npm registry) | ||
*/ | ||
export const getRegistrySigningKeys = async ( | ||
registry = npmRegistryUrl, | ||
): Promise<RegistrySigningKeys> => | ||
fetchData(registrySigningKeysSchema, urlJoin(registry, "-/npm/v1/keys")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters