@pnpm/crypto.shasums-file 1000.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 +22 -0
- package/README.md +13 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/package.json +48 -0
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-2025 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
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type FetchFromRegistry } from '@pnpm/fetching-types';
|
|
2
|
+
export declare function fetchShasumsFile(fetch: FetchFromRegistry, shasumsUrl: string, expectedVersionIntegrity?: string): Promise<string>;
|
|
3
|
+
export declare function pickFileChecksumFromShasumsFile(body: string, fileName: string): string;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchShasumsFile = fetchShasumsFile;
|
|
4
|
+
exports.pickFileChecksumFromShasumsFile = pickFileChecksumFromShasumsFile;
|
|
5
|
+
const crypto_hash_1 = require("@pnpm/crypto.hash");
|
|
6
|
+
const error_1 = require("@pnpm/error");
|
|
7
|
+
async function fetchShasumsFile(fetch, shasumsUrl, expectedVersionIntegrity) {
|
|
8
|
+
const res = await fetch(shasumsUrl);
|
|
9
|
+
if (!res.ok) {
|
|
10
|
+
throw new error_1.PnpmError('NODE_FETCH_INTEGRITY_FAILED', `Failed to fetch integrity file: ${shasumsUrl} (status: ${res.status})`);
|
|
11
|
+
}
|
|
12
|
+
const body = await res.text();
|
|
13
|
+
if (expectedVersionIntegrity) {
|
|
14
|
+
const actualVersionIntegrity = (0, crypto_hash_1.createHash)(body);
|
|
15
|
+
if (expectedVersionIntegrity !== actualVersionIntegrity) {
|
|
16
|
+
throw new error_1.PnpmError('NODE_VERSION_INTEGRITY_MISMATCH', `The integrity of ${shasumsUrl} failed. Expected: ${expectedVersionIntegrity}. Actual: ${actualVersionIntegrity}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return body;
|
|
20
|
+
}
|
|
21
|
+
const SHA256_REGEX = /^[a-f0-9]{64}$/;
|
|
22
|
+
function pickFileChecksumFromShasumsFile(body, fileName) {
|
|
23
|
+
const line = body.split('\n').find(line => line.trim().endsWith(` ${fileName}`));
|
|
24
|
+
if (!line) {
|
|
25
|
+
throw new error_1.PnpmError('NODE_INTEGRITY_HASH_NOT_FOUND', `SHA-256 hash not found in SHASUMS256.txt for: ${fileName}`);
|
|
26
|
+
}
|
|
27
|
+
const [sha256] = line.trim().split(/\s+/);
|
|
28
|
+
if (!SHA256_REGEX.test(sha256)) {
|
|
29
|
+
throw new error_1.PnpmError('NODE_MALFORMED_INTEGRITY_HASH', `Malformed SHA-256 for ${fileName}: ${sha256}`);
|
|
30
|
+
}
|
|
31
|
+
const buffer = Buffer.from(sha256, 'hex');
|
|
32
|
+
const base64 = buffer.toString('base64');
|
|
33
|
+
return `sha256-${base64}`;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAMA,4CAqBC;AAID,0EAqBC;AApDD,mDAA8C;AAC9C,uCAAuC;AAKhC,KAAK,UAAU,gBAAgB,CACpC,KAAwB,EACxB,UAAkB,EAClB,wBAAiC;IAEjC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,CAAA;IACnC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,iBAAS,CACjB,6BAA6B,EAC7B,mCAAmC,UAAU,aAAa,GAAG,CAAC,MAAM,GAAG,CACxE,CAAA;IACH,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;IAC7B,IAAI,wBAAwB,EAAE,CAAC;QAC7B,MAAM,sBAAsB,GAAG,IAAA,wBAAU,EAAC,IAAI,CAAC,CAAA;QAC/C,IAAI,wBAAwB,KAAK,sBAAsB,EAAE,CAAC;YACxD,MAAM,IAAI,iBAAS,CAAC,iCAAiC,EAAE,oBAAoB,UAAU,sBAAsB,wBAAwB,aAAa,sBAAsB,EAAE,CAAC,CAAA;QAC3K,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,YAAY,GAAG,gBAAgB,CAAA;AAErC,SAAgB,+BAA+B,CAAE,IAAY,EAAE,QAAgB;IAC7E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC,CAAA;IAEjF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,iBAAS,CACjB,+BAA+B,EAC/B,iDAAiD,QAAQ,EAAE,CAC5D,CAAA;IACH,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,iBAAS,CACjB,+BAA+B,EAC/B,yBAAyB,QAAQ,KAAK,MAAM,EAAE,CAC/C,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACxC,OAAO,UAAU,MAAM,EAAE,CAAA;AAC3B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/crypto.shasums-file",
|
|
3
|
+
"version": "1000.0.0",
|
|
4
|
+
"description": "Utils for working with shasums files",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm10",
|
|
8
|
+
"crypto",
|
|
9
|
+
"shasums-file"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"funding": "https://opencollective.com/pnpm",
|
|
13
|
+
"repository": "https://github.com/pnpm/pnpm/blob/main/crypto/shasums-file",
|
|
14
|
+
"homepage": "https://github.com/pnpm/pnpm/blob/main/crypto/shasums-file#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
17
|
+
},
|
|
18
|
+
"type": "commonjs",
|
|
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/crypto.hash": "1000.2.0",
|
|
30
|
+
"@pnpm/error": "1000.0.3",
|
|
31
|
+
"@pnpm/fetching-types": "1000.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@pnpm/crypto.shasums-file": "1000.0.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.12"
|
|
38
|
+
},
|
|
39
|
+
"jest": {
|
|
40
|
+
"preset": "@pnpm/jest-config"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
44
|
+
"_test": "jest",
|
|
45
|
+
"test": "pnpm run compile && pnpm run _test",
|
|
46
|
+
"compile": "tsc --build && pnpm run lint --fix"
|
|
47
|
+
}
|
|
48
|
+
}
|