@pnpm/crypto.integrity 1100.0.0-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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @pnpm/crypto.integrity
2
+
3
+ > Parse and format integrity strings
4
+
5
+ Utilities for working with single-hash integrity strings in the format `algorithm-base64hash` (e.g., `sha512-abc123...`). This is the format used in pnpm lockfiles.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @pnpm/crypto.integrity
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { parseIntegrity } from '@pnpm/crypto.integrity'
17
+
18
+ const { algorithm, hexDigest } = parseIntegrity('sha512-9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuKCxBvl5CVNiCB3LFUYosWowMf37aGVlKfrU5RT4e1w==')
19
+
20
+ console.log(algorithm) // 'sha512'
21
+ console.log(hexDigest) // 'f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7'
22
+ ```
23
+
24
+ ## API
25
+
26
+ ### `parseIntegrity(integrity: string): ParsedIntegrity`
27
+
28
+ Parses an integrity string and returns the algorithm and hex-encoded digest.
29
+
30
+ Throws `PnpmError` with code `INVALID_INTEGRITY` if:
31
+ - The format is invalid (must be `algorithm-base64hash`)
32
+ - The base64 hash decodes to an empty digest
33
+
34
+ ### `formatIntegrity(algorithm: string, hexDigest: string): string`
35
+
36
+ Formats a hex digest into an integrity string.
37
+
38
+ ```ts
39
+ import { formatIntegrity } from '@pnpm/crypto.integrity'
40
+
41
+ const integrity = formatIntegrity('sha512', 'f7fbba6e...')
42
+ // 'sha512-9/u6bgY2+JDlb7vzKD5STG+...'
43
+ ```
44
+
45
+ ## License
46
+
47
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface ParsedIntegrity {
2
+ algorithm: string;
3
+ hexDigest: string;
4
+ }
5
+ /**
6
+ * Parses an integrity string (e.g., "sha512-base64hash") into its components.
7
+ * @throws PnpmError if the integrity format is invalid
8
+ */
9
+ export declare function parseIntegrity(integrity: string): ParsedIntegrity;
10
+ /**
11
+ * Formats a hex digest into an integrity string (e.g., "sha512-base64hash").
12
+ */
13
+ export declare function formatIntegrity(algorithm: string, hexDigest: string): string;
package/lib/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { PnpmError } from '@pnpm/error';
2
+ // Matches the integrity format "algo-base64hash"
3
+ const INTEGRITY_REGEX = /^([^-]+)-([a-z0-9+/=]+)$/i;
4
+ /**
5
+ * Parses an integrity string (e.g., "sha512-base64hash") into its components.
6
+ * @throws PnpmError if the integrity format is invalid
7
+ */
8
+ export function parseIntegrity(integrity) {
9
+ const match = integrity.match(INTEGRITY_REGEX);
10
+ if (!match) {
11
+ throw new PnpmError('INVALID_INTEGRITY', `Invalid integrity format: expected "algo-base64hash", got "${integrity}"`);
12
+ }
13
+ const hexDigest = Buffer.from(match[2], 'base64').toString('hex');
14
+ if (hexDigest.length === 0) {
15
+ throw new PnpmError('INVALID_INTEGRITY', 'Invalid integrity: base64 hash decoded to empty digest');
16
+ }
17
+ return { algorithm: match[1], hexDigest };
18
+ }
19
+ /**
20
+ * Formats a hex digest into an integrity string (e.g., "sha512-base64hash").
21
+ */
22
+ export function formatIntegrity(algorithm, hexDigest) {
23
+ return `${algorithm}-${Buffer.from(hexDigest, 'hex').toString('base64')}`;
24
+ }
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,iDAAiD;AACjD,MAAM,eAAe,GAAG,2BAA2B,CAAA;AAOnD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAE,SAAiB,EAAmB;IAClE,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,SAAS,CAAC,mBAAmB,EAAE,8DAA8D,SAAS,GAAG,CAAC,CAAA;IACtH,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACjE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,SAAS,CAAC,mBAAmB,EAAE,wDAAwD,CAAC,CAAA;IACpG,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAA;AAAA,CAC1C;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAE,SAAiB,EAAE,SAAiB,EAAU;IAC7E,OAAO,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAA;AAAA,CAC1E"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@pnpm/crypto.integrity",
3
+ "version": "1100.0.0-0",
4
+ "description": "Parse and validate integrity strings",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "crypto",
9
+ "integrity"
10
+ ],
11
+ "license": "MIT",
12
+ "funding": "https://opencollective.com/pnpm",
13
+ "repository": "https://github.com/pnpm/pnpm/tree/main/crypto/integrity",
14
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/crypto/integrity#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/pnpm/pnpm/issues"
17
+ },
18
+ "type": "module",
19
+ "main": "lib/index.js",
20
+ "types": "lib/index.d.ts",
21
+ "exports": {
22
+ ".": "./lib/index.js"
23
+ },
24
+ "files": [
25
+ "lib",
26
+ "!*.map"
27
+ ],
28
+ "dependencies": {
29
+ "@pnpm/error": "1000.0.5"
30
+ },
31
+ "devDependencies": {
32
+ "@pnpm/crypto.integrity": "1100.0.0-0"
33
+ },
34
+ "engines": {
35
+ "node": ">=22.12"
36
+ },
37
+ "jest": {
38
+ "preset": "@pnpm/jest-config"
39
+ },
40
+ "scripts": {
41
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
42
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
43
+ "test": "pnpm run compile && pnpm run _test",
44
+ "compile": "tsgo --build && pnpm run lint --fix"
45
+ }
46
+ }