1616import { constants , chmodSync , createWriteStream , existsSync , mkdirSync } from 'node:fs'
1717import https from 'node:https'
1818import { arch , exit , platform } from 'node:process'
19- import { DEFAULT_CACHE_FOLDER , DEFAULT_EXECUTABLE_PATH , USER_EXECUTABLE_PATH } from './utils'
19+ import {
20+ DEFAULT_CACHE_FOLDER ,
21+ DEFAULT_EXECUTABLE_PATH ,
22+ USER_EXECUTABLE_PATH ,
23+ checksumFile ,
24+ } from './utils'
25+
26+ type GH_ASSET = {
27+ name : string
28+ digest : string
29+ }
2030
2131const PLATFORMS = {
2232 darwin : {
@@ -66,6 +76,25 @@ export const download = async (): Promise<void> => {
6676 return new Promise ( ( resolve , reject ) => get ( url , resolve , reject ) )
6777 }
6878
79+ const getGithubHash = async ( path : string ) => {
80+ try {
81+ const f = await fetch ( path )
82+ const data = await f . json ( )
83+
84+ const asset : GH_ASSET = data . assets . find (
85+ ( a : GH_ASSET ) => a . name === `lightpanda-${ platformPath } ` ,
86+ )
87+
88+ if ( asset ) {
89+ return asset . digest
90+ }
91+
92+ return ''
93+ } catch ( e ) {
94+ throw new Error ( e )
95+ }
96+ }
97+
6998 if ( platformPath ) {
7099 if ( USER_EXECUTABLE_PATH ) {
71100 console . info ( '$LIGHTPANDA_EXECUTABLE_PATH found, skipping binary download…' )
@@ -78,6 +107,15 @@ export const download = async (): Promise<void> => {
78107 await downloadBinary (
79108 `https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-${ platformPath } ` ,
80109 )
110+ const ghChecksum = await getGithubHash (
111+ 'https://api.github.com/repos/lightpanda-io/browser/releases/tags/nightly' ,
112+ )
113+ const lpChecksum = await checksumFile ( DEFAULT_EXECUTABLE_PATH )
114+
115+ if ( ghChecksum !== lpChecksum ) {
116+ throw new Error ( "Checksums don't match!" )
117+ }
118+
81119 chmodSync ( DEFAULT_EXECUTABLE_PATH , constants . S_IRWXU )
82120
83121 console . info ( '✅ Done!' )
0 commit comments