# Arcverin Windows Authenticated Installer (Private Azure Blob SAS · resolves latest release dynamically) function Install-Arcverin { [CmdletBinding()] param( [string]$InstallDir = '.\arcverin', [string]$Version = 'latest', [string]$LicenseKey = $env:ARCVERIN_LICENSE_KEY, [string]$LicenseFile = $env:ARCVERIN_ENTITLEMENT_PATH, [string]$Email = $env:ARCVERIN_EMAIL, [string]$LicenseId = $env:ARCVERIN_LICENSE_ID, [string]$ApiBaseUrl = $(if ($env:ARCVERIN_API_BASE_URL) { $env:ARCVERIN_API_BASE_URL } else { 'https://www.arcverin.com' }), [string]$ReleasePublicKeyHex = $(if ($env:ARCVERIN_RELEASE_PUBLIC_KEY_HEX) { $env:ARCVERIN_RELEASE_PUBLIC_KEY_HEX } else { 'fb28df886d803b2c6476fb933ada1ef54245963de4146069d0e0e7b25690f8f0' }), [switch]$Start, [switch]$Help ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' if ($Help) { Write-Host @" Arcverin Windows Authenticated Installer (Private Azure Blob Distribution) Usage: `$env:ARCVERIN_LICENSE_KEY = "" irm https://www.arcverin.com/install-arcverin.ps1 | iex .\install-arcverin.ps1 -LicenseFile ".\license.arcverin" [-InstallDir ".\arcverin"] [-Version "latest"|] [-Start] .\install-arcverin.ps1 -Email "you@company.com" -LicenseId "arcverin-personal-..." [-InstallDir ".\arcverin"] Options: -LicenseKey Inline ARCVERIN-... activation key (or env ARCVERIN_LICENSE_KEY) -LicenseFile Path to signed license.arcverin file (or env ARCVERIN_ENTITLEMENT_PATH) -Email Purchase email address (paired with -LicenseId or env ARCVERIN_EMAIL) -LicenseId Arcverin License ID (paired with -Email or env ARCVERIN_LICENSE_ID) -InstallDir Parent directory for extraction (default: .\arcverin) -Version Release version to install (default: latest) -ReleasePublicKeyHex <64hex> Ed25519 release public key hex (or env ARCVERIN_RELEASE_PUBLIC_KEY_HEX) -Start Start Arcverin Studio immediately after installation -Help Show this help message "@ return } if ($Version -ne 'latest' -and $Version -notmatch '^\d+\.\d+\.\d+(?:-[A-Za-z0-9.]+)?$') { throw "Invalid version format '$Version'. Expected semantic version (X.Y.Z) or 'latest'." } if ([string]::IsNullOrWhiteSpace($InstallDir)) { throw 'InstallDir must not be empty.' } $normalizedReleasePublicKeyHex = if ($null -eq $ReleasePublicKeyHex) { '' } else { $ReleasePublicKeyHex.Trim().ToLowerInvariant() } if ($normalizedReleasePublicKeyHex -notmatch '^[0-9a-f]{64}$') { throw "Invalid ReleasePublicKeyHex '$ReleasePublicKeyHex'. Expected exactly 64 hexadecimal characters (32-byte Ed25519 public key)." } $authBody = @{} $resolvedLicenseFile = '' if (-not [string]::IsNullOrWhiteSpace($LicenseFile)) { if (-not (Test-Path -LiteralPath $LicenseFile -PathType Leaf)) { throw "License file not found: $LicenseFile" } $resolvedLicenseFile = (Resolve-Path -LiteralPath $LicenseFile).Path $authBody['licenseKey'] = (Get-Content -LiteralPath $resolvedLicenseFile -Raw -Encoding UTF8).Trim() } elseif (-not [string]::IsNullOrWhiteSpace($LicenseKey)) { $authBody['licenseKey'] = $LicenseKey.Trim() } elseif (-not [string]::IsNullOrWhiteSpace($Email) -and -not [string]::IsNullOrWhiteSpace($LicenseId)) { $authBody['email'] = $Email.Trim() $authBody['licenseId'] = $LicenseId.Trim() } else { throw "Authentication required. Provide -LicenseKey (or env ARCVERIN_LICENSE_KEY), -LicenseFile (or env ARCVERIN_ENTITLEMENT_PATH), or -Email + -LicenseId. Download your license at https://www.arcverin.com/downloads/." } function Initialize-ArcverinEd25519Verifier { if ('Arcverin.Crypto.Ed25519Verifier' -as [type]) { return } Add-Type -AssemblyName System.Numerics $refList = [System.Collections.Generic.List[string]]::new() $numLoc = [System.Numerics.BigInteger].Assembly.Location if (-not [string]::IsNullOrWhiteSpace($numLoc)) { $refList.Add($numLoc) } $shaLoc = [System.Security.Cryptography.SHA512].Assembly.Location if (-not [string]::IsNullOrWhiteSpace($shaLoc) -and -not $shaLoc.EndsWith('mscorlib.dll', [StringComparison]::OrdinalIgnoreCase) -and -not $refList.Contains($shaLoc)) { $refList.Add($shaLoc) } $ed25519Source = @' using System; using System.Numerics; using System.Security.Cryptography; namespace Arcverin.Crypto { public static class Ed25519Verifier { private static readonly BigInteger P = (BigInteger.One << 255) - 19; private static readonly BigInteger L = (BigInteger.One << 252) + BigInteger.Parse("27742317777372353535851937790883648493"); private static readonly BigInteger D = ModP(new BigInteger(-121665) * ModInvP(new BigInteger(121666))); private static readonly BigInteger TwoD = ModP(D * 2); private static readonly BigInteger SqrtM1 = BigInteger.ModPow(2, (P - 1) / 4, P); private static readonly BigInteger ExpP58 = (P - 5) / 8; private static readonly BigInteger Bx = BigInteger.Parse("15112221349535400772501151409588531511454012693041857206046113283949847762202"); private static readonly BigInteger By = BigInteger.Parse("46316835694926478169428394003475163141307993866256225615783033603165251855960"); private static readonly ExtPoint BasePoint = new ExtPoint(Bx, By, BigInteger.One, ModP(Bx * By)); private static readonly ExtPoint IdentityPoint = new ExtPoint(BigInteger.Zero, BigInteger.One, BigInteger.One, BigInteger.Zero); private struct ExtPoint { public BigInteger X; public BigInteger Y; public BigInteger Z; public BigInteger T; public ExtPoint(BigInteger x, BigInteger y, BigInteger z, BigInteger t) { X = x; Y = y; Z = z; T = t; } } private static BigInteger ModP(BigInteger x) { BigInteger r = x % P; return r.Sign < 0 ? r + P : r; } private static BigInteger ModInvP(BigInteger x) { return BigInteger.ModPow(ModP(x), P - 2, P); } private static BigInteger FromLittleEndianUnsigned(byte[] bytes, int offset, int length) { byte[] buf = new byte[length + 1]; Buffer.BlockCopy(bytes, offset, buf, 0, length); buf[length] = 0; return new BigInteger(buf); } private static int HexVal(char c) { if (c >= '0' && c <= '9') return c - '0'; if (c >= 'a' && c <= 'f') return c - 'a' + 10; if (c >= 'A' && c <= 'F') return c - 'A' + 10; return -1; } private static bool TryDecodeHex(string hex, int expectedBytes, out byte[] result) { result = null; if (hex == null) return false; string s = hex.Trim(); if (s.Length != expectedBytes * 2) return false; byte[] bytes = new byte[expectedBytes]; for (int i = 0; i < expectedBytes; i++) { int hi = HexVal(s[i * 2]); int lo = HexVal(s[i * 2 + 1]); if (hi < 0 || lo < 0) return false; bytes[i] = (byte)((hi << 4) | lo); } result = bytes; return true; } private static bool TryDecompressPoint(byte[] enc, int offset, out ExtPoint point) { point = IdentityPoint; if (enc == null || enc.Length - offset < 32) return false; byte[] yBytes = new byte[32]; Buffer.BlockCopy(enc, offset, yBytes, 0, 32); int sign = (yBytes[31] >> 7) & 1; yBytes[31] &= 0x7F; BigInteger y = FromLittleEndianUnsigned(yBytes, 0, 32); if (y >= P) return false; BigInteger y2 = ModP(y * y); BigInteger u = ModP(y2 - BigInteger.One); BigInteger v = ModP(D * y2 + BigInteger.One); if (v.IsZero) return false; BigInteger v3 = ModP(ModP(v * v) * v); BigInteger v7 = ModP(ModP(v3 * v3) * v); BigInteger uv7 = ModP(u * v7); BigInteger x = ModP(ModP(u * v3) * BigInteger.ModPow(uv7, ExpP58, P)); BigInteger vx2 = ModP(v * ModP(x * x)); if (vx2 != u) { if (vx2 == ModP(-u)) { x = ModP(x * SqrtM1); } else { return false; } } if (ModP(v * ModP(x * x)) != u) return false; if (x.IsZero && sign == 1) return false; if ((x.IsEven ? 0 : 1) != sign) { x = P - x; } BigInteger x2 = ModP(x * x); BigInteger lhs = ModP(y2 - x2); BigInteger rhs = ModP(BigInteger.One + ModP(D * ModP(x2 * y2))); if (lhs != rhs) return false; point = new ExtPoint(x, y, BigInteger.One, ModP(x * y)); return true; } private static ExtPoint PointAdd(ExtPoint p1, ExtPoint p2) { BigInteger a = ModP((p1.Y - p1.X) * (p2.Y - p2.X)); BigInteger b = ModP((p1.Y + p1.X) * (p2.Y + p2.X)); BigInteger c = ModP(ModP(p1.T * TwoD) * p2.T); BigInteger d = ModP(ModP(p1.Z * 2) * p2.Z); BigInteger e = ModP(b - a); BigInteger f = ModP(d - c); BigInteger g = ModP(d + c); BigInteger h = ModP(b + a); return new ExtPoint(ModP(e * f), ModP(g * h), ModP(f * g), ModP(e * h)); } private static ExtPoint ScalarMult(ExtPoint point, BigInteger scalar) { ExtPoint result = IdentityPoint; ExtPoint addend = point; BigInteger k = scalar; while (k.Sign > 0) { if (!k.IsEven) { result = PointAdd(result, addend); } addend = PointAdd(addend, addend); k >>= 1; } return result; } private static bool PointEquals(ExtPoint p1, ExtPoint p2) { if (ModP(p1.X * p2.Z - p2.X * p1.Z) != BigInteger.Zero) return false; if (ModP(p1.Y * p2.Z - p2.Y * p1.Z) != BigInteger.Zero) return false; return true; } public static bool Verify(byte[] publicKey, byte[] message, byte[] signature) { if (publicKey == null || publicKey.Length != 32) return false; if (message == null) return false; if (signature == null || signature.Length != 64) return false; BigInteger s = FromLittleEndianUnsigned(signature, 32, 32); if (s.Sign < 0 || s >= L) return false; ExtPoint aPoint; if (!TryDecompressPoint(publicKey, 0, out aPoint)) return false; ExtPoint rPoint; if (!TryDecompressPoint(signature, 0, out rPoint)) return false; byte[] hashInput = new byte[64 + message.Length]; Buffer.BlockCopy(signature, 0, hashInput, 0, 32); Buffer.BlockCopy(publicKey, 0, hashInput, 32, 32); Buffer.BlockCopy(message, 0, hashInput, 64, message.Length); byte[] digest; using (SHA512 sha512 = SHA512.Create()) { digest = sha512.ComputeHash(hashInput); } BigInteger k = FromLittleEndianUnsigned(digest, 0, 64) % L; if (k.Sign < 0) k += L; ExtPoint lhs = ScalarMult(BasePoint, s); ExtPoint rhs = PointAdd(rPoint, ScalarMult(aPoint, k)); return PointEquals(lhs, rhs); } public static bool VerifyHex(string publicKeyHex, byte[] message, string signatureHex) { byte[] pubBytes; byte[] sigBytes; if (!TryDecodeHex(publicKeyHex, 32, out pubBytes)) return false; if (!TryDecodeHex(signatureHex, 64, out sigBytes)) return false; return Verify(pubBytes, message, sigBytes); } } } '@ try { Add-Type -TypeDefinition $ed25519Source -ReferencedAssemblies $refList.ToArray() } catch { throw "Unable to compile inline Ed25519 verifier (this can happen under Windows PowerShell Constrained Language Mode or AppLocker policies). Download the signed ZIP and private SHA256SUMS.txt directly from https://www.arcverin.com/downloads/ and verify SHA-256 manually with Get-FileHash. Underlying error: $($_.Exception.Message)" } } function Test-ArcverinEd25519Signature { param( [Parameter(Mandatory)][byte[]]$MessageBytes, [Parameter(Mandatory)][string]$SignatureHex, [Parameter(Mandatory)][string]$PublicKeyHex ) $cleanSig = if ($null -eq $SignatureHex) { '' } else { $SignatureHex.Trim() } if ($cleanSig -notmatch '^[0-9a-fA-F]{128}$') { return $false } Initialize-ArcverinEd25519Verifier return [Arcverin.Crypto.Ed25519Verifier]::VerifyHex($PublicKeyHex, $MessageBytes, $cleanSig) } [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $base = $ApiBaseUrl.TrimEnd('/') $downloadEndpoint = "$base/api/download" function Request-SignedDownload { param( [Parameter(Mandatory)][string]$AssetKey, [Parameter(Mandatory)][string]$TargetVersion ) $payload = @{} foreach ($k in $authBody.Keys) { $payload[$k] = $authBody[$k] } $payload['asset'] = $AssetKey $payload['version'] = $TargetVersion $payload['format'] = 'json' $json = $payload | ConvertTo-Json -Depth 4 -Compress $resp = Invoke-RestMethod -Uri $downloadEndpoint -Method Post -ContentType 'application/json' -Body $json -TimeoutSec 30 if (-not $resp -or -not $resp.ok -or -not $resp.url) { throw "Download broker rejected request for $AssetKey." } return $resp } function Invoke-ArcverinDownload { param( [Parameter(Mandatory)][string]$Uri, [Parameter(Mandatory)][string]$Destination ) $curl = Get-Command 'curl.exe' -ErrorAction SilentlyContinue if ($null -ne $curl) { & $curl.Source -fsSL --retry 2 --connect-timeout 20 -o $Destination $Uri if ($LASTEXITCODE -eq 0 -and (Test-Path -LiteralPath $Destination -PathType Leaf)) { return } if (Test-Path -LiteralPath $Destination -PathType Leaf) { Remove-Item -LiteralPath $Destination -Force -ErrorAction SilentlyContinue } } Invoke-WebRequest -Uri $Uri -OutFile $Destination -UseBasicParsing } Write-Host "Authenticating active Arcverin license against $downloadEndpoint ..." $archiveGrant = Request-SignedDownload -AssetKey 'windows-x64' -TargetVersion $Version $resolvedVersion = [string]$archiveGrant.version if ($resolvedVersion -notmatch '^\d+\.\d+\.\d+(?:-[A-Za-z0-9.]+)?$') { throw "Download broker returned invalid semantic version: '$resolvedVersion'." } $archiveName = [string]$archiveGrant.filename if ([string]::IsNullOrWhiteSpace($archiveName) -or $archiveName -match '[\\/]' -or $archiveName -eq '.' -or $archiveName -eq '..') { throw "Download broker returned invalid archive filename: '$archiveName'." } $checksumsGrant = Request-SignedDownload -AssetKey 'sha256sums' -TargetVersion $resolvedVersion $checksumsSigGrant = Request-SignedDownload -AssetKey 'sha256sums-sig' -TargetVersion $resolvedVersion $currentLocation = (Get-Location).Path $winDir = $env:WINDIR if (-not $PSBoundParameters.ContainsKey('InstallDir') -and -not [string]::IsNullOrWhiteSpace($winDir) -and $currentLocation.StartsWith($winDir, [StringComparison]::OrdinalIgnoreCase)) { $InstallDir = Join-Path $HOME 'arcverin' Write-Host "Notice: Current directory is inside $winDir; defaulting -InstallDir to $InstallDir." -ForegroundColor Yellow } $resolvedInstallDir = if ([IO.Path]::IsPathRooted($InstallDir)) { [IO.Path]::GetFullPath($InstallDir) } else { [IO.Path]::GetFullPath((Join-Path $currentLocation $InstallDir)) } $appFolderName = "arcverin-verified-work-platform-$resolvedVersion" $targetAppRoot = Join-Path $resolvedInstallDir $appFolderName if (Test-Path -LiteralPath $targetAppRoot) { throw "Target directory already exists: $targetAppRoot. Choose a different -InstallDir or upgrade using arcverin-update.exe." } $tempDir = Join-Path ([IO.Path]::GetTempPath()) ("arcverin-install-" + [guid]::NewGuid().ToString('N').Substring(0, 8)) New-Item -ItemType Directory -Path $tempDir -Force | Out-Null try { try { $telemetryUri = "$base/api/track?event=cli_install_windows&asset=$([Uri]::EscapeDataString($archiveName))&path=/install-arcverin.ps1" Invoke-WebRequest -Uri $telemetryUri -Method Get -TimeoutSec 2 -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null } catch {} $checksumsPath = Join-Path $tempDir 'SHA256SUMS.txt' $checksumsSigPath = Join-Path $tempDir 'SHA256SUMS.txt.sig' $zipPath = Join-Path $tempDir $archiveName Write-Host "Downloading private SHA256SUMS.txt and Ed25519 signature (Azure Blob SAS) ..." Invoke-ArcverinDownload -Uri ([string]$checksumsGrant.url) -Destination $checksumsPath Invoke-ArcverinDownload -Uri ([string]$checksumsSigGrant.url) -Destination $checksumsSigPath Write-Host "Verifying Ed25519 detached signature on SHA256SUMS.txt ..." $checksumsBytes = [System.IO.File]::ReadAllBytes($checksumsPath) if ($checksumsBytes.Length -eq 0) { throw 'Downloaded SHA256SUMS.txt is empty.' } $sigHex = ([System.IO.File]::ReadAllText($checksumsSigPath, [System.Text.Encoding]::UTF8)).Trim() if ($sigHex -notmatch '^[0-9a-fA-F]{128}$') { throw "Invalid SHA256SUMS.txt.sig format: expected 128 hexadecimal characters (64-byte Ed25519 signature)." } if (-not (Test-ArcverinEd25519Signature -MessageBytes $checksumsBytes -SignatureHex $sigHex -PublicKeyHex $normalizedReleasePublicKeyHex)) { throw "Ed25519 detached signature verification FAILED for SHA256SUMS.txt (key=$($normalizedReleasePublicKeyHex.Substring(0, 16))...). Aborting installation before downloading archive." } Write-Host "Ed25519 detached signature verified for SHA256SUMS.txt." -ForegroundColor Green $matchedHashes = [System.Collections.Generic.List[string]]::new() foreach ($line in (Get-Content -LiteralPath $checksumsPath)) { if ([string]::IsNullOrWhiteSpace($line)) { continue } if ($line -match '^([a-fA-F0-9]{64})\s+\*?(.+)$') { $entryPath = $Matches[2].Trim() -replace '\\', '/' if ($entryPath -ceq $archiveName -or $entryPath -ceq "personal/$archiveName") { $matchedHashes.Add($Matches[1].ToLowerInvariant()) } } } if ($matchedHashes.Count -ne 1) { throw "Private SHA256SUMS.txt must contain exactly one entry for $archiveName (found $($matchedHashes.Count))." } $expectedHash = $matchedHashes[0] Write-Host "Downloading $archiveName (Azure Blob SAS) ..." Invoke-ArcverinDownload -Uri ([string]$archiveGrant.url) -Destination $zipPath Write-Host "Verifying SHA-256 checksum..." $actualHash = (Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() if ($actualHash -ne $expectedHash) { throw "SHA-256 verification failed for $archiveName. Expected $expectedHash, got $actualHash." } New-Item -ItemType Directory -Path $resolvedInstallDir -Force | Out-Null Write-Host "Extracting to $resolvedInstallDir ..." Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $resolvedInstallDir) $studioExe = Join-Path $targetAppRoot 'arcverin-studio.exe' if (-not (Test-Path -LiteralPath $studioExe -PathType Leaf)) { throw "Extraction completed but expected executable was not found: $studioExe" } $licenseInstalled = $false if (-not [string]::IsNullOrWhiteSpace($resolvedLicenseFile)) { $outDir = Join-Path $targetAppRoot 'output' New-Item -ItemType Directory -Path $outDir -Force | Out-Null Copy-Item -LiteralPath $resolvedLicenseFile -Destination (Join-Path $outDir 'license.arcverin') -Force $licenseInstalled = $true Write-Host "Installed signed license.arcverin into $outDir\license.arcverin" -ForegroundColor Green } elseif (-not [string]::IsNullOrWhiteSpace($LicenseKey)) { $trimmedKey = $LicenseKey.Trim() $licensePayloadToWrite = $null if ($trimmedKey.StartsWith('{') -and $trimmedKey.EndsWith('}')) { $licensePayloadToWrite = $trimmedKey } elseif ($trimmedKey -match '^ARCVERIN-(?:(?:PERSONAL|TEAM|ENTERPRISE)-)?([A-Za-z0-9+/=_-]+)$') { $b64 = $Matches[1].Replace('-', '+').Replace('_', '/') $pad = (4 - ($b64.Length % 4)) % 4 if ($pad -gt 0) { $b64 = $b64 + ('=' * $pad) } try { $decodedText = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($b64)).Trim() if ($decodedText.StartsWith('{') -and $decodedText.EndsWith('}')) { $licensePayloadToWrite = $decodedText } else { $licensePayloadToWrite = $trimmedKey } } catch { $licensePayloadToWrite = $trimmedKey } } if (-not [string]::IsNullOrWhiteSpace($licensePayloadToWrite)) { $outDir = Join-Path $targetAppRoot 'output' New-Item -ItemType Directory -Path $outDir -Force | Out-Null $destLicensePath = Join-Path $outDir 'license.arcverin' [System.IO.File]::WriteAllText($destLicensePath, ($licensePayloadToWrite + "`n"), [System.Text.UTF8Encoding]::new($false)) $licenseInstalled = $true Write-Host "Installed signed license from ARCVERIN_LICENSE_KEY into $destLicensePath" -ForegroundColor Green } } $displayPath = $targetAppRoot $prefix = $currentLocation.TrimEnd('\', '/') + '\' if ($targetAppRoot.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase)) { $displayPath = '.\' + $targetAppRoot.Substring($prefix.Length) } Write-Host "" Write-Host "Arcverin $resolvedVersion is ready!" -ForegroundColor Green Write-Host " cd `"$displayPath`"" if (-not $licenseInstalled) { Write-Host " # Note: -Email + -LicenseId authenticated your download, so activate your signed license.arcverin before starting:" -ForegroundColor Yellow Write-Host " # (Download license.arcverin from https://www.arcverin.com/billing/ or pass -LicenseKey / -LicenseFile next time.)" -ForegroundColor Yellow Write-Host " .\arcverin.exe upgrade --license \license.arcverin" } Write-Host " .\start-arcverin.cmd" if ($Start) { Write-Host "" Write-Host "Starting Arcverin Studio $resolvedVersion on http://127.0.0.1:3002 ..." if (-not $licenseInstalled -and $authBody.ContainsKey('licenseKey')) { $env:ARCVERIN_LICENSE_KEY = [string]$authBody['licenseKey'] } Push-Location -LiteralPath $targetAppRoot try { & $studioExe serve } finally { Pop-Location } } } finally { if (Test-Path -LiteralPath $tempDir) { Remove-Item -LiteralPath $tempDir -Recurse -Force -ErrorAction SilentlyContinue } } } if ($MyInvocation.InvocationName -ne '.') { Install-Arcverin @args }