Skip to content

Commit b473983

Browse files
committed
Fix Windows npm checksum
1 parent 5c8132b commit b473983

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎scripts/install.ps1‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ function Copy-InstallerFile {
9393
Invoke-WebRequest -Uri $uri -OutFile $Destination -Headers $headers -UseBasicParsing
9494
}
9595

96+
function Get-SHA256FileHash {
97+
param([string]$Path)
98+
99+
$sha256 = [Security.Cryptography.SHA256]::Create()
100+
try {
101+
$stream = [IO.File]::OpenRead($Path)
102+
try {
103+
return ([BitConverter]::ToString($sha256.ComputeHash($stream))).Replace("-", "").ToLowerInvariant()
104+
}
105+
finally {
106+
$stream.Dispose()
107+
}
108+
}
109+
finally {
110+
$sha256.Dispose()
111+
}
112+
}
113+
96114
function Add-EtherscanToUserPath {
97115
param([string]$Directory)
98116

@@ -173,7 +191,7 @@ try {
173191
}
174192

175193
$expectedHash = $Matches[1].ToLowerInvariant()
176-
$actualHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
194+
$actualHash = Get-SHA256FileHash -Path $archivePath
177195
if ($actualHash -ne $expectedHash) {
178196
throw "Checksum verification failed for $archiveName. Expected $expectedHash, received $actualHash."
179197
}

‎scripts/test-npm.ps1‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ try {
5858
}
5959

6060
$env:ETHERSCAN_INSTALL_TEST_DOWNLOAD_BASE_URL = $fixtureDirectory
61-
Invoke-Checked npm.cmd @("install", "--global", "--prefix", $prefixDirectory, $tarball)
61+
$savedPSModulePath = $env:PSModulePath
62+
$env:PSModulePath = ""
63+
try {
64+
Invoke-Checked npm.cmd @("install", "--global", "--prefix", $prefixDirectory, $tarball)
65+
}
66+
finally {
67+
$env:PSModulePath = $savedPSModulePath
68+
}
6269
$globalOutput = & (Join-Path $prefixDirectory "etherscan.cmd") version
6370
if ($LASTEXITCODE -ne 0 -or ($globalOutput -join "`n").Trim() -ne $version) {
6471
throw "global npm installation returned unexpected version: $globalOutput"

0 commit comments

Comments
 (0)