electron-incremental-update 2.2.1 → 2.2.3

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/dist/vite.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import { readableSize, copyAndSkipIfExist } from './chunk-TPTWE33H.js';
2
- import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-7JCGLFGU.js';
3
- export { convertLiteral } from './chunk-7JCGLFGU.js';
2
+ import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-LR7LR5WG.js';
3
+ export { convertLiteral } from './chunk-LR7LR5WG.js';
4
4
  import { log, id } from './chunk-5NKEXGI3.js';
5
- import path3 from 'node:path';
6
5
  import fs2 from 'node:fs';
6
+ import path3 from 'node:path';
7
+ import { isCI } from 'ci-info';
8
+ export { isCI } from 'ci-info';
7
9
  import { loadPackageJSON, getPackageInfoSync } from 'local-pkg';
8
10
  export { getPackageInfo, getPackageInfoSync, loadPackageJSON, resolveModule } from 'local-pkg';
9
11
  import { normalizePath, mergeConfig } from 'vite';
10
- import ElectronSimple from 'vite-plugin-electron/simple';
11
12
  import { startup, build } from 'vite-plugin-electron';
12
13
  import { notBundle } from 'vite-plugin-electron/plugin';
13
- import { isCI } from 'ci-info';
14
- export { isCI } from 'ci-info';
14
+ import ElectronSimple from 'vite-plugin-electron/simple';
15
15
  import Asar from '@electron/asar';
16
- import zlib from 'node:zlib';
17
16
  import crypto from 'node:crypto';
17
+ import zlib from 'node:zlib';
18
18
  import { generate } from 'selfsigned';
19
19
 
20
20
  async function buildAsar({
@@ -33,14 +33,14 @@ async function buildAsar({
33
33
  log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
34
34
  return buf;
35
35
  }
36
- async function buildVersion({
36
+ async function buildUpdateJson({
37
37
  versionPath,
38
38
  privateKey,
39
39
  cert,
40
40
  version,
41
41
  minimumVersion,
42
42
  generateSignature,
43
- generateVersionJson
43
+ generateUpdateJson
44
44
  }, asarBuffer) {
45
45
  let _json = {
46
46
  beta: {
@@ -64,12 +64,12 @@ async function buildVersion({
64
64
  }
65
65
  }
66
66
  const sig = await generateSignature(asarBuffer, privateKey, cert, version);
67
- _json = await generateVersionJson(_json, sig, version, minimumVersion);
67
+ _json = await generateUpdateJson(_json, sig, version, minimumVersion);
68
68
  if (!isUpdateJSON(_json)) {
69
- throw new Error("Invalid version info");
69
+ throw new Error("Invalid update json");
70
70
  }
71
71
  fs2.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
72
- log.info(`build version info to '${versionPath}'`, { timestamp: true });
72
+ log.info(`build update json to '${versionPath}'`, { timestamp: true });
73
73
  }
74
74
  async function buildEntry({
75
75
  sourcemap,
@@ -88,8 +88,8 @@ async function buildEntry({
88
88
  },
89
89
  vite: mergeConfig({
90
90
  plugins: [
91
- isESM && await import('./esm-UJAQJA65.js').then((m) => m.esm()),
92
- bytecodeOptions && await import('./bytecode-7V24FFYI.js').then((m) => m.bytecodePlugin("main", bytecodeOptions))
91
+ isESM && await import('./esm-4S4XCVEW.js').then((m) => m.esm()),
92
+ bytecodeOptions && await import('./bytecode-R2B4KTMV.js').then((m) => m.bytecodePlugin("main", bytecodeOptions))
93
93
  ],
94
94
  build: {
95
95
  sourcemap,
@@ -102,11 +102,6 @@ async function buildEntry({
102
102
  }, overrideViteOptions ?? {})
103
103
  });
104
104
  }
105
- async function defaultZipFile(buffer) {
106
- return new Promise((resolve, reject) => {
107
- zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
108
- });
109
- }
110
105
  function hashBuffer(data, length) {
111
106
  const hash = crypto.createHash("SHA256").update(data).digest("binary");
112
107
  return Buffer.from(hash).subarray(0, length);
@@ -119,6 +114,11 @@ function defaultSignature(buffer, privateKey, cert, version) {
119
114
  const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
120
115
  return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
121
116
  }
117
+ async function defaultZipFile(buffer) {
118
+ return new Promise((resolve, reject) => {
119
+ zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
120
+ });
121
+ }
122
122
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
123
123
  const privateKeyDir = path3.dirname(privateKeyPath);
124
124
  if (!fs2.existsSync(privateKeyDir)) {
@@ -202,7 +202,7 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
202
202
  overrideGenerator: {
203
203
  generateGzipFile = defaultZipFile,
204
204
  generateSignature = defaultSignature,
205
- generateVersionJson = defaultVersionJsonGenerator
205
+ generateUpdateJson = defaultVersionJsonGenerator
206
206
  } = {}
207
207
  } = options;
208
208
  const buildAsarOption = {
@@ -251,16 +251,24 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
251
251
  cert,
252
252
  versionPath,
253
253
  generateSignature,
254
- generateVersionJson
254
+ generateUpdateJson
255
255
  };
256
256
  return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
257
257
  }
258
- function debugStartup(args) {
258
+ var debugStartup = (args) => {
259
259
  if (process.env.VSCODE_DEBUG) {
260
260
  console.log("[startup] Electron App");
261
261
  } else {
262
262
  args.startup();
263
263
  }
264
+ };
265
+ function fixWinCharEncoding(fn) {
266
+ return async (...args) => {
267
+ if (process.platform === "win32") {
268
+ (await import('node:child_process')).spawnSync("chcp", ["65001"]);
269
+ }
270
+ await fn(...args);
271
+ };
264
272
  }
265
273
  function getMainFileBaseName(options) {
266
274
  let mainFilePath;
@@ -332,6 +340,7 @@ async function electronWithUpdater(options) {
332
340
  throw new Error(`Wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
333
341
  }
334
342
  const define = {
343
+ __EIU_ASAR_BASE_NAME__: JSON.stringify(path3.basename(buildAsarOption.asarOutputPath)),
335
344
  __EIU_ELECTRON_DIST_PATH__: JSON.stringify(normalizePath(buildAsarOption.electronDistPath)),
336
345
  __EIU_ENTRY_DIST_PATH__: JSON.stringify(normalizePath(buildEntryOption.entryOutputDirPath)),
337
346
  __EIU_IS_DEV__: JSON.stringify(!isBuild),
@@ -379,7 +388,7 @@ async function electronWithUpdater(options) {
379
388
  external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src) || src === "original-fs",
380
389
  treeshake: true
381
390
  };
382
- const esmShimPlugin = isESM ? (await import('./esm-UJAQJA65.js')).esm() : void 0;
391
+ const esmShimPlugin = isESM ? (await import('./esm-4S4XCVEW.js')).esm() : void 0;
383
392
  const electronPluginOptions = {
384
393
  main: {
385
394
  entry: _main.files,
@@ -399,7 +408,7 @@ async function electronWithUpdater(options) {
399
408
  {
400
409
  plugins: [
401
410
  !isBuild && useNotBundle ? notBundle() : void 0,
402
- bytecodeOptions && await import('./bytecode-7V24FFYI.js').then((m) => m.bytecodePlugin("main", bytecodeOptions)),
411
+ bytecodeOptions && await import('./bytecode-R2B4KTMV.js').then((m) => m.bytecodePlugin("main", bytecodeOptions)),
403
412
  esmShimPlugin
404
413
  ],
405
414
  build: {
@@ -419,7 +428,7 @@ async function electronWithUpdater(options) {
419
428
  vite: mergeConfig(
420
429
  {
421
430
  plugins: [
422
- bytecodeOptions && (await import('./bytecode-7V24FFYI.js')).bytecodePlugin("preload", bytecodeOptions),
431
+ bytecodeOptions && (await import('./bytecode-R2B4KTMV.js')).bytecodePlugin("preload", bytecodeOptions),
423
432
  esmShimPlugin,
424
433
  {
425
434
  name: `${id}-build`,
@@ -434,7 +443,7 @@ async function electronWithUpdater(options) {
434
443
  if (!buildVersionJson && !isCI) {
435
444
  log.warn("No `buildVersionJson` option setup, skip build version json. Only build in CI by default", { timestamp: true });
436
445
  } else {
437
- await buildVersion(buildVersionOption, buffer);
446
+ await buildUpdateJson(buildVersionOption, buffer);
438
447
  }
439
448
  }
440
449
  }
@@ -491,4 +500,4 @@ async function electronWithUpdater(options) {
491
500
  }
492
501
  var vite_default = electronWithUpdater;
493
502
 
494
- export { debugStartup, vite_default as default, electronWithUpdater };
503
+ export { debugStartup, vite_default as default, electronWithUpdater, fixWinCharEncoding };
@@ -0,0 +1,70 @@
1
+ import { Arrayable } from '@subframe7536/type-utils';
2
+ import { a as UpdateJSON, D as DownloadingInfo } from './types-C5M2xRjF.cjs';
3
+ import { IncomingMessage } from 'electron';
4
+
5
+ declare function hashBuffer(data: string | Buffer, length: number): Buffer;
6
+ declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
7
+ /**
8
+ * Default function to generate asar signature, returns generated signature
9
+ * @param buffer file buffer
10
+ * @param privateKey primary key
11
+ * @param cert certificate
12
+ * @param version target version
13
+ */
14
+ declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
15
+ declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
16
+ /**
17
+ * Default function to verify asar signature,
18
+ * if signature is valid, returns the version, otherwise returns `undefined`
19
+ * @param buffer file buffer
20
+ * @param version target version
21
+ * @param signature signature
22
+ * @param cert certificate
23
+ */
24
+ declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
25
+
26
+ /**
27
+ * Safe get value from header
28
+ * @param headers response header
29
+ * @param key target header key
30
+ */
31
+ declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
32
+ declare function downloadUtil<T>(url: string, headers: Record<string, any>, signal: AbortSignal, onResponse: (resp: IncomingMessage, resolve: (data: T) => void, reject: (e: any) => void) => void): Promise<T>;
33
+ type ResolveDataFn = (data: string, resolve: (data: any) => void, reject: (e: any) => void) => void;
34
+ /**
35
+ * Default function to download json and parse to UpdateJson
36
+ * @param url target url
37
+ * @param headers extra headers
38
+ * @param signal abort signal
39
+ * @param resolveData on resolve
40
+ */
41
+ declare function defaultDownloadJSON<T>(url: string, headers: Record<string, any>, signal: AbortSignal, resolveData?: ResolveDataFn): Promise<T>;
42
+ /**
43
+ * Default function to download json and parse to UpdateJson
44
+ * @param url target url
45
+ * @param headers extra headers
46
+ * @param signal abort signal
47
+ */
48
+ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
49
+ /**
50
+ * Default function to download asar buffer,
51
+ * get total size from `Content-Length` header
52
+ * @param url target url
53
+ * @param headers extra headers
54
+ * @param signal abort signal
55
+ * @param onDownloading on downloading callback
56
+ */
57
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: (progress: DownloadingInfo) => void): Promise<Buffer>;
58
+
59
+ /**
60
+ * Default function to compress file using brotli
61
+ * @param buffer uncompressed file buffer
62
+ */
63
+ declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
64
+ /**
65
+ * Default function to decompress file using brotli
66
+ * @param buffer compressed file buffer
67
+ */
68
+ declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
69
+
70
+ export { aesEncrypt as a, aesDecrypt as b, defaultVerifySignature as c, defaultSignature as d, downloadUtil as e, defaultDownloadJSON as f, getHeader as g, hashBuffer as h, defaultDownloadUpdateJSON as i, defaultDownloadAsar as j, defaultZipFile as k, defaultUnzipFile as l };
@@ -0,0 +1,70 @@
1
+ import { Arrayable } from '@subframe7536/type-utils';
2
+ import { a as UpdateJSON, D as DownloadingInfo } from './types-C5M2xRjF.js';
3
+ import { IncomingMessage } from 'electron';
4
+
5
+ declare function hashBuffer(data: string | Buffer, length: number): Buffer;
6
+ declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
7
+ /**
8
+ * Default function to generate asar signature, returns generated signature
9
+ * @param buffer file buffer
10
+ * @param privateKey primary key
11
+ * @param cert certificate
12
+ * @param version target version
13
+ */
14
+ declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
15
+ declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
16
+ /**
17
+ * Default function to verify asar signature,
18
+ * if signature is valid, returns the version, otherwise returns `undefined`
19
+ * @param buffer file buffer
20
+ * @param version target version
21
+ * @param signature signature
22
+ * @param cert certificate
23
+ */
24
+ declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
25
+
26
+ /**
27
+ * Safe get value from header
28
+ * @param headers response header
29
+ * @param key target header key
30
+ */
31
+ declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
32
+ declare function downloadUtil<T>(url: string, headers: Record<string, any>, signal: AbortSignal, onResponse: (resp: IncomingMessage, resolve: (data: T) => void, reject: (e: any) => void) => void): Promise<T>;
33
+ type ResolveDataFn = (data: string, resolve: (data: any) => void, reject: (e: any) => void) => void;
34
+ /**
35
+ * Default function to download json and parse to UpdateJson
36
+ * @param url target url
37
+ * @param headers extra headers
38
+ * @param signal abort signal
39
+ * @param resolveData on resolve
40
+ */
41
+ declare function defaultDownloadJSON<T>(url: string, headers: Record<string, any>, signal: AbortSignal, resolveData?: ResolveDataFn): Promise<T>;
42
+ /**
43
+ * Default function to download json and parse to UpdateJson
44
+ * @param url target url
45
+ * @param headers extra headers
46
+ * @param signal abort signal
47
+ */
48
+ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
49
+ /**
50
+ * Default function to download asar buffer,
51
+ * get total size from `Content-Length` header
52
+ * @param url target url
53
+ * @param headers extra headers
54
+ * @param signal abort signal
55
+ * @param onDownloading on downloading callback
56
+ */
57
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: (progress: DownloadingInfo) => void): Promise<Buffer>;
58
+
59
+ /**
60
+ * Default function to compress file using brotli
61
+ * @param buffer uncompressed file buffer
62
+ */
63
+ declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
64
+ /**
65
+ * Default function to decompress file using brotli
66
+ * @param buffer compressed file buffer
67
+ */
68
+ declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
69
+
70
+ export { aesEncrypt as a, aesDecrypt as b, defaultVerifySignature as c, defaultSignature as d, downloadUtil as e, defaultDownloadJSON as f, getHeader as g, hashBuffer as h, defaultDownloadUpdateJSON as i, defaultDownloadAsar as j, defaultZipFile as k, defaultUnzipFile as l };
package/package.json CHANGED
@@ -1,87 +1,86 @@
1
- {
2
- "name": "electron-incremental-update",
3
- "type": "module",
4
- "version": "2.2.1",
5
- "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
- "author": "subframe7536",
7
- "license": "MIT",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/subframe7536/electron-incremental-update.git"
11
- },
12
- "keywords": [
13
- "electron",
14
- "incremental update",
15
- "updater",
16
- "bytecode"
17
- ],
18
- "exports": {
19
- ".": {
20
- "import": "./dist/index.js",
21
- "require": "./dist/index.cjs"
22
- },
23
- "./vite": {
24
- "import": "./dist/vite.js"
25
- },
26
- "./utils": {
27
- "import": "./dist/utils.js",
28
- "require": "./dist/utils.cjs"
29
- },
30
- "./provider": {
31
- "import": "./dist/provider.js",
32
- "require": "./dist/provider.cjs"
33
- }
34
- },
35
- "main": "dist/index.cjs",
36
- "module": "dist/index.js",
37
- "files": [
38
- "dist",
39
- "provider.d.ts",
40
- "provider.js",
41
- "utils.d.ts",
42
- "utils.js",
43
- "vite.d.ts",
44
- "vite.js"
45
- ],
46
- "scripts": {
47
- "dev": "tsup --watch",
48
- "build": "tsup && esno fix-module.cjs",
49
- "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
50
- "test": "vitest --run",
51
- "test:dev": "vitest",
52
- "format": "eslint . --fix"
53
- },
54
- "publishConfig": {
55
- "access": "public",
56
- "registry": "https://registry.npmjs.org/"
57
- },
58
- "peerDependencies": {
59
- "@electron/asar": "*",
60
- "esbuild": "*"
61
- },
62
- "dependencies": {
63
- "@babel/core": "^7.25.2",
64
- "@babel/plugin-transform-arrow-functions": "^7.24.7",
65
- "@babel/plugin-transform-template-literals": "^7.24.7",
66
- "@subframe7536/type-utils": "^0.1.6",
67
- "ci-info": "^4.0.0",
68
- "local-pkg": "^0.5.0",
69
- "magic-string": "^0.30.11",
70
- "selfsigned": "^2.4.1",
71
- "vite-plugin-electron": "^0.28.7"
72
- },
73
- "devDependencies": {
74
- "@subframe7536/eslint-config": "^0.9.0",
75
- "@types/babel__core": "^7.20.5",
76
- "@types/node": "^20.16.5",
77
- "bumpp": "^9.5.2",
78
- "electron": "28.2.10",
79
- "eslint": "^9.9.1",
80
- "esno": "^4.7.0",
81
- "tsup": "^8.2.4",
82
- "typescript": "^5.5.4",
83
- "vite": "^5.4.3",
84
- "vite-plugin-electron": "^0.28.7",
85
- "vitest": "^2.0.5"
86
- }
87
- }
1
+ {
2
+ "name": "electron-incremental-update",
3
+ "type": "module",
4
+ "version": "2.2.3",
5
+ "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
+ "author": "subframe7536",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/subframe7536/electron-incremental-update.git"
11
+ },
12
+ "keywords": [
13
+ "electron",
14
+ "incremental update",
15
+ "updater",
16
+ "bytecode"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ },
23
+ "./vite": {
24
+ "import": "./dist/vite.js"
25
+ },
26
+ "./utils": {
27
+ "import": "./dist/utils.js",
28
+ "require": "./dist/utils.cjs"
29
+ },
30
+ "./provider": {
31
+ "import": "./dist/provider.js",
32
+ "require": "./dist/provider.cjs"
33
+ }
34
+ },
35
+ "main": "dist/index.cjs",
36
+ "module": "dist/index.js",
37
+ "files": [
38
+ "dist",
39
+ "provider.d.ts",
40
+ "provider.js",
41
+ "utils.d.ts",
42
+ "utils.js",
43
+ "vite.d.ts",
44
+ "vite.js"
45
+ ],
46
+ "scripts": {
47
+ "dev": "tsup --watch",
48
+ "build": "tsup && node fix-module.cjs",
49
+ "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
50
+ "test": "vitest --run",
51
+ "test:dev": "vitest",
52
+ "format": "eslint . --fix"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public",
56
+ "registry": "https://registry.npmjs.org/"
57
+ },
58
+ "peerDependencies": {
59
+ "@electron/asar": "*",
60
+ "esbuild": "*"
61
+ },
62
+ "dependencies": {
63
+ "@babel/core": "^7.26.0",
64
+ "@babel/plugin-transform-arrow-functions": "^7.25.9",
65
+ "@babel/plugin-transform-template-literals": "^7.25.9",
66
+ "@subframe7536/type-utils": "^0.1.6",
67
+ "ci-info": "^4.1.0",
68
+ "local-pkg": "^0.5.1",
69
+ "magic-string": "^0.30.14",
70
+ "selfsigned": "^2.4.1",
71
+ "vite-plugin-electron": "^0.29.0"
72
+ },
73
+ "devDependencies": {
74
+ "@subframe7536/eslint-config": "^0.9.7",
75
+ "@types/babel__core": "^7.20.5",
76
+ "@types/node": "^20.17.9",
77
+ "bumpp": "^9.8.1",
78
+ "electron": "32.2.6",
79
+ "eslint": "^9.15.0",
80
+ "tsup": "^8.3.5",
81
+ "typescript": "^5.7.2",
82
+ "vite": "^6.0.1",
83
+ "vite-plugin-electron": "^0.29.0",
84
+ "vitest": "^2.1.6"
85
+ }
86
+ }
@@ -1,43 +0,0 @@
1
- import zlib from 'node:zlib';
2
- import crypto from 'node:crypto';
3
-
4
- // src/utils/zip.ts
5
- async function defaultZipFile(buffer) {
6
- return new Promise((resolve, reject) => {
7
- zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
8
- });
9
- }
10
- async function defaultUnzipFile(buffer) {
11
- return new Promise((resolve, reject) => {
12
- zlib.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
13
- });
14
- }
15
- function hashBuffer(data, length) {
16
- const hash = crypto.createHash("SHA256").update(data).digest("binary");
17
- return Buffer.from(hash).subarray(0, length);
18
- }
19
- function aesEncrypt(plainText, key, iv) {
20
- const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
21
- return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
22
- }
23
- function defaultSignature(buffer, privateKey, cert, version) {
24
- const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
25
- return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
26
- }
27
- function aesDecrypt(encryptedText, key, iv) {
28
- const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
29
- return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
30
- }
31
- function defaultVerifySignature(buffer, version, signature, cert) {
32
- try {
33
- const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
34
- if (ver !== version) {
35
- return false;
36
- }
37
- return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
38
- } catch {
39
- return false;
40
- }
41
- }
42
-
43
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer };
@@ -1,33 +0,0 @@
1
- /**
2
- * Default function to compress file using brotli
3
- * @param buffer uncompressed file buffer
4
- */
5
- declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
6
- /**
7
- * Default function to decompress file using brotli
8
- * @param buffer compressed file buffer
9
- */
10
- declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
11
-
12
- declare function hashBuffer(data: string | Buffer, length: number): Buffer;
13
- declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
14
- /**
15
- * Default function to generate asar signature, returns generated signature
16
- * @param buffer file buffer
17
- * @param privateKey primary key
18
- * @param cert certificate
19
- * @param version target version
20
- */
21
- declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
22
- declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
23
- /**
24
- * Default function to verify asar signature,
25
- * if signature is valid, returns the version, otherwise returns `undefined`
26
- * @param buffer file buffer
27
- * @param version target version
28
- * @param signature signature
29
- * @param cert certificate
30
- */
31
- declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
32
-
33
- export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
@@ -1,33 +0,0 @@
1
- /**
2
- * Default function to compress file using brotli
3
- * @param buffer uncompressed file buffer
4
- */
5
- declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
6
- /**
7
- * Default function to decompress file using brotli
8
- * @param buffer compressed file buffer
9
- */
10
- declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
11
-
12
- declare function hashBuffer(data: string | Buffer, length: number): Buffer;
13
- declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
14
- /**
15
- * Default function to generate asar signature, returns generated signature
16
- * @param buffer file buffer
17
- * @param privateKey primary key
18
- * @param cert certificate
19
- * @param version target version
20
- */
21
- declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
22
- declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
23
- /**
24
- * Default function to verify asar signature,
25
- * if signature is valid, returns the version, otherwise returns `undefined`
26
- * @param buffer file buffer
27
- * @param version target version
28
- * @param signature signature
29
- * @param cert certificate
30
- */
31
- declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
32
-
33
- export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
@@ -1,62 +0,0 @@
1
- interface Version {
2
- /**
3
- * `4` of `4.3.2-beta.1`
4
- */
5
- major: number;
6
- /**
7
- * `3` of `4.3.2-beta.1`
8
- */
9
- minor: number;
10
- /**
11
- * `2` of `4.3.2-beta.1`
12
- */
13
- patch: number;
14
- /**
15
- * `beta` of `4.3.2-beta.1`
16
- */
17
- stage: string;
18
- /**
19
- * `1` of `4.3.2-beta.1`
20
- */
21
- stageVersion: number;
22
- }
23
- /**
24
- * Parse version string to {@link Version}, like `0.2.0-beta.1`
25
- * @param version version string
26
- */
27
- declare function parseVersion(version: string): Version;
28
- /**
29
- * Default function to check the old version is less than new version
30
- * @param oldVer old version string
31
- * @param newVer new version string
32
- */
33
- declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
34
- /**
35
- * Update info json
36
- */
37
- type UpdateInfo = {
38
- signature: string;
39
- minimumVersion: string;
40
- version: string;
41
- };
42
- /**
43
- * {@link UpdateInfo} with beta
44
- */
45
- type UpdateJSON = UpdateInfo & {
46
- beta: UpdateInfo;
47
- };
48
- /**
49
- * Check is `UpdateJSON`
50
- * @param json any variable
51
- */
52
- declare function isUpdateJSON(json: any): json is UpdateJSON;
53
- /**
54
- * Default function to generate `UpdateJSON`
55
- * @param existingJson exising update json
56
- * @param signature sigature
57
- * @param version target version
58
- * @param minimumVersion minimum version
59
- */
60
- declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
61
-
62
- export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };