@dk/hipp 0.1.14 → 0.1.15
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/README.md +3 -3
- package/hipp.js +32 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -175,8 +175,8 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
175
175
|
```json
|
|
176
176
|
{
|
|
177
177
|
"origin": "git@github.com:dmytri/hipp.git",
|
|
178
|
-
"tag": "v0.1.
|
|
179
|
-
"hash": "
|
|
180
|
-
"signature": "
|
|
178
|
+
"tag": "v0.1.15",
|
|
179
|
+
"hash": "cee8b863e598809fe8a194c1f102c857a0698e8158bef9e39493b31da6411226",
|
|
180
|
+
"signature": "Hc5fpg5Kg67ztJBdbtM3DvdrccL1e0KEyYwenwVIHLqcCNadXT9oatpgkO9dFaaGkCMUfttMGtWv8iJtYy+tBg=="
|
|
181
181
|
}
|
|
182
182
|
```
|
package/hipp.js
CHANGED
|
@@ -160,12 +160,24 @@ function findLastJsonBlock(readmeContent) {
|
|
|
160
160
|
return lastValid;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
function
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
function packAndHash(stageDir) {
|
|
164
|
+
const result = spawnSync('npm', ['pack'], {
|
|
165
|
+
cwd: stageDir,
|
|
166
|
+
encoding: 'utf8',
|
|
167
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (result.status !== 0) {
|
|
171
|
+
throw new Error(`npm pack failed: ${result.stderr}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const tarballName = result.stdout.trim().split('\n').pop();
|
|
175
|
+
const tarballPath = path.join(stageDir, tarballName);
|
|
176
|
+
|
|
177
|
+
const tarballContent = fs.readFileSync(tarballPath);
|
|
178
|
+
fs.unlinkSync(tarballPath);
|
|
179
|
+
|
|
180
|
+
return { tarballName, tarballHash: sha256(tarballContent) };
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
function safeStageName(name) {
|
|
@@ -484,14 +496,10 @@ async function runVerify(packageSpec) {
|
|
|
484
496
|
const trackedFiles = getTrackedFilesFromDir(tmpDir);
|
|
485
497
|
copyTrackedFilesFromDir(stageDir, tmpDir, trackedFiles);
|
|
486
498
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
fail(`❌ README.md not found in git at tag ${tag}`);
|
|
490
|
-
}
|
|
499
|
+
log.info(`📦 Packing to verify content hash...`);
|
|
500
|
+
const { tarballHash } = packAndHash(stageDir);
|
|
491
501
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (stagedHash !== npmHash) {
|
|
502
|
+
if (tarballHash !== npmHash) {
|
|
495
503
|
fail(`❌ Hash mismatch: git content does not match npm manifest`);
|
|
496
504
|
}
|
|
497
505
|
|
|
@@ -595,10 +603,9 @@ async function run() {
|
|
|
595
603
|
|
|
596
604
|
const { privateKey } = loadOrGenerateKeys();
|
|
597
605
|
|
|
598
|
-
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
fs.writeFileSync(stagedPkgPath, JSON.stringify(stagedPkg, null, 2) + '\n');
|
|
606
|
+
log.info(`📦 Packing to compute content hash...`);
|
|
607
|
+
const { tarballHash } = packAndHash(stageDir);
|
|
608
|
+
log.success(`🔒 Content hash: ${tarballHash.slice(0, 12)}...`);
|
|
602
609
|
|
|
603
610
|
const stagedReadmePath = path.join(stageDir, 'README.md');
|
|
604
611
|
let stagedReadme = '';
|
|
@@ -606,23 +613,24 @@ async function run() {
|
|
|
606
613
|
stagedReadme = fs.readFileSync(stagedReadmePath, 'utf8');
|
|
607
614
|
}
|
|
608
615
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const readmeHash = sha256(stagedReadme);
|
|
612
|
-
const dataToSign = buildSignData(readmeHash, provenance.remoteUrl, rawTag);
|
|
616
|
+
const dataToSign = buildSignData(tarballHash, provenance.remoteUrl, rawTag);
|
|
613
617
|
const signature = signContent(dataToSign, privateKey);
|
|
614
618
|
|
|
615
619
|
const manifestJson = {
|
|
616
620
|
origin: provenance.remoteUrl,
|
|
617
621
|
tag: rawTag,
|
|
618
|
-
hash:
|
|
622
|
+
hash: tarballHash,
|
|
619
623
|
signature: signature,
|
|
620
624
|
};
|
|
621
625
|
|
|
622
|
-
stagedReadme
|
|
623
|
-
|
|
626
|
+
stagedReadme = stagedReadme.trimEnd() + '\n\n```json\n' + JSON.stringify(manifestJson, null, 2) + '\n```\n';
|
|
624
627
|
fs.writeFileSync(stagedReadmePath, stagedReadme);
|
|
625
628
|
|
|
629
|
+
const stagedPkgPath = path.join(stageDir, 'package.json');
|
|
630
|
+
const stagedPkg = JSON.parse(fs.readFileSync(stagedPkgPath, 'utf8'));
|
|
631
|
+
stagedPkg.version = version;
|
|
632
|
+
fs.writeFileSync(stagedPkgPath, JSON.stringify(stagedPkg, null, 2) + '\n');
|
|
633
|
+
|
|
626
634
|
log.success('🔏 Manifest signed.');
|
|
627
635
|
|
|
628
636
|
log.info('🔥 Ignition...');
|