electron-incremental-update 0.5.1 → 0.6.1
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 +13 -12
- package/dist/{chunk-OBERMV66.mjs → chunk-VADH6AZA.mjs} +12 -21
- package/dist/index.cjs +220 -173
- package/dist/index.d.ts +27 -15
- package/dist/index.mjs +204 -150
- package/dist/vite.cjs +72 -49
- package/dist/vite.d.ts +25 -3
- package/dist/vite.mjs +64 -33
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -58,15 +58,15 @@ src
|
|
|
58
58
|
import { createUpdater, getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
59
59
|
import { name, repository } from '../package.json'
|
|
60
60
|
|
|
61
|
-
const
|
|
61
|
+
const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
62
62
|
|
|
63
63
|
// create updater when init, no need to set productName
|
|
64
|
-
initApp({ name }, {
|
|
64
|
+
initApp({ name }, { SIGNATURE_CERT, repository })
|
|
65
65
|
|
|
66
66
|
// or create updater manually
|
|
67
67
|
const { cdnPrefix } = getGithubReleaseCdnGroup()[0]
|
|
68
68
|
const updater = createUpdater({
|
|
69
|
-
|
|
69
|
+
SIGNATURE_CERT,
|
|
70
70
|
productName: name,
|
|
71
71
|
repository,
|
|
72
72
|
updateJsonURL: parseGithubCdnURL(repository, 'fastly.jsdelivr.net/gh', 'version.json'),
|
|
@@ -76,20 +76,25 @@ const updater = createUpdater({
|
|
|
76
76
|
initApp({ name }).setUpdater(updater)
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
###
|
|
79
|
+
### usage in main process
|
|
80
|
+
|
|
81
|
+
To utilize the electron `net` module for requesting update information, the `checkUpdate` and `downloadAndInstall` functions must be called after the app is ready by default.
|
|
82
|
+
|
|
83
|
+
However, you have the option to customize the download function when creating the updater.
|
|
80
84
|
|
|
81
85
|
```ts
|
|
82
86
|
// electron/main/index.ts
|
|
83
87
|
import type { Updater } from 'electron-incremental-update'
|
|
84
|
-
import {
|
|
88
|
+
import { getEntryVersion, getProductAsarPath, getProductVersion } from 'electron-incremental-update'
|
|
85
89
|
import { app } from 'electron'
|
|
86
90
|
import { name } from '../../package.json'
|
|
87
91
|
|
|
88
92
|
export default function (updater: Updater) {
|
|
93
|
+
await app.whenReady()
|
|
89
94
|
console.log('\ncurrent:')
|
|
90
|
-
console.log(`\tasar path: ${
|
|
95
|
+
console.log(`\tasar path: ${getProductAsarPath(name)}`)
|
|
91
96
|
console.log(`\tentry: ${getEntryVersion()}`)
|
|
92
|
-
console.log(`\tapp: ${
|
|
97
|
+
console.log(`\tapp: ${getProductVersion(name)}`)
|
|
93
98
|
let size = 0
|
|
94
99
|
updater.on('downloading', (progress) => {
|
|
95
100
|
console.log(`${(progress / size).toFixed(2)}%`)
|
|
@@ -108,13 +113,9 @@ export default function (updater: Updater) {
|
|
|
108
113
|
buttons: ['Download', 'Later'],
|
|
109
114
|
message: 'Application update available!',
|
|
110
115
|
})
|
|
111
|
-
response === 0 && console.log(await updater.
|
|
116
|
+
response === 0 && console.log(await updater.downloadAndInstall())
|
|
112
117
|
}
|
|
113
118
|
})
|
|
114
|
-
// app logics
|
|
115
|
-
app.whenReady().then(() => {
|
|
116
|
-
// ...
|
|
117
|
-
})
|
|
118
119
|
}
|
|
119
120
|
```
|
|
120
121
|
|
|
@@ -7,46 +7,38 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
// src/crypto.ts
|
|
10
|
-
import { constants, createCipheriv, createDecipheriv, createHash, createSign, createVerify
|
|
10
|
+
import { constants, createCipheriv, createDecipheriv, createHash, createSign, createVerify } from "node:crypto";
|
|
11
11
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
12
12
|
var aesEncode = "base64url";
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
const privateKey = pair.privateKey.export({ type: "pkcs1", format: "pem" });
|
|
16
|
-
const publicKey = pair.publicKey.export({ type: "pkcs1", format: "pem" });
|
|
17
|
-
return {
|
|
18
|
-
privateKey,
|
|
19
|
-
publicKey
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function encrypt(plainText, key, iv) {
|
|
23
|
-
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
13
|
+
function encrypt(plainText, key2, iv) {
|
|
14
|
+
const cipher = createCipheriv("aes-256-cbc", key2, iv);
|
|
24
15
|
let encrypted = cipher.update(plainText, "utf8", aesEncode);
|
|
25
16
|
encrypted += cipher.final(aesEncode);
|
|
26
17
|
return encrypted;
|
|
27
18
|
}
|
|
28
|
-
function decrypt(encryptedText,
|
|
29
|
-
const decipher = createDecipheriv("aes-256-cbc",
|
|
19
|
+
function decrypt(encryptedText, key2, iv) {
|
|
20
|
+
const decipher = createDecipheriv("aes-256-cbc", key2, iv);
|
|
30
21
|
let decrypted = decipher.update(encryptedText, aesEncode, "utf8");
|
|
31
22
|
decrypted += decipher.final("utf8");
|
|
32
23
|
return decrypted;
|
|
33
24
|
}
|
|
34
|
-
function
|
|
25
|
+
function key(data, length) {
|
|
35
26
|
const hash = createHash("SHA256").update(data).digest("binary");
|
|
36
27
|
return Buffer2.from(hash).subarray(0, length);
|
|
37
28
|
}
|
|
38
|
-
function signature(buffer, privateKey,
|
|
29
|
+
function signature(buffer, privateKey, cert, version) {
|
|
39
30
|
const sig = createSign("RSA-SHA256").update(buffer).sign({
|
|
40
31
|
key: privateKey,
|
|
41
32
|
padding: constants.RSA_PKCS1_PADDING,
|
|
42
33
|
saltLength: constants.RSA_PSS_SALTLEN_DIGEST
|
|
43
34
|
}, "base64");
|
|
44
|
-
return encrypt(sig
|
|
35
|
+
return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
|
|
45
36
|
}
|
|
46
|
-
function verify(buffer, signature2,
|
|
37
|
+
function verify(buffer, signature2, cert) {
|
|
47
38
|
try {
|
|
48
|
-
const sig = decrypt(signature2,
|
|
49
|
-
|
|
39
|
+
const [sig, version] = decrypt(signature2, key(cert, 32), key(buffer, 16)).split("%");
|
|
40
|
+
const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
41
|
+
return result ? version : false;
|
|
50
42
|
} catch (error) {
|
|
51
43
|
return false;
|
|
52
44
|
}
|
|
@@ -54,7 +46,6 @@ function verify(buffer, signature2, publicKey) {
|
|
|
54
46
|
|
|
55
47
|
export {
|
|
56
48
|
__require,
|
|
57
|
-
generateRSA,
|
|
58
49
|
signature,
|
|
59
50
|
verify
|
|
60
51
|
};
|