ddan-js 2.9.3 → 2.9.5
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/bin/ddan-js.browser.js +1 -1
- package/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/types/browser.d.ts +3 -3
- package/bin/types/index.d.ts +4 -3
- package/bin/types/modules/fetch.d.ts +1 -1
- package/bin/types/modules/node/index.d.ts +2 -0
- package/package.json +18 -13
- package/bin/lib/browser.js +0 -111
- package/bin/lib/class/event.js +0 -104
- package/bin/lib/class/getset.js +0 -12
- package/bin/lib/class/icon.js +0 -94
- package/bin/lib/class/joker.js +0 -121
- package/bin/lib/class/kvalue.js +0 -29
- package/bin/lib/class/mapping.js +0 -82
- package/bin/lib/class/persist.js +0 -65
- package/bin/lib/class/pipeTask.js +0 -42
- package/bin/lib/class/pipeparallel.js +0 -24
- package/bin/lib/class/store.js +0 -87
- package/bin/lib/class/tracker.js +0 -125
- package/bin/lib/class/watermark.js +0 -63
- package/bin/lib/common/_Symbol.js +0 -5
- package/bin/lib/common/_freeGlobal.js +0 -5
- package/bin/lib/common/_object.js +0 -40
- package/bin/lib/common/_root.js +0 -10
- package/bin/lib/common/internal/asciiToArray.js +0 -13
- package/bin/lib/common/internal/castSlice.js +0 -18
- package/bin/lib/common/internal/createCaseFirst.js +0 -30
- package/bin/lib/common/internal/hasUnicode.js +0 -26
- package/bin/lib/common/internal/nodeTypes.js +0 -26
- package/bin/lib/common/internal/slice.js +0 -46
- package/bin/lib/common/internal/stringToArray.js +0 -18
- package/bin/lib/common/internal/unicodeToArray.js +0 -40
- package/bin/lib/common/internal/unicodeWords.js +0 -67
- package/bin/lib/index.js +0 -114
- package/bin/lib/modules/browser/ecdh.js +0 -124
- package/bin/lib/modules/browser/index.js +0 -4
- package/bin/lib/modules/cdn.js +0 -62
- package/bin/lib/modules/convert/base.js +0 -125
- package/bin/lib/modules/convert/base64.js +0 -114
- package/bin/lib/modules/convert/index.js +0 -99
- package/bin/lib/modules/convert/md5.js +0 -222
- package/bin/lib/modules/convert/pkcs.js +0 -16
- package/bin/lib/modules/convert/utf8.js +0 -106
- package/bin/lib/modules/crypto/base64.js +0 -14
- package/bin/lib/modules/crypto/const.js +0 -7
- package/bin/lib/modules/crypto/index.js +0 -30
- package/bin/lib/modules/crypto/rsa.js +0 -143
- package/bin/lib/modules/crypto/tea.js +0 -79
- package/bin/lib/modules/crypto/uuid.js +0 -34
- package/bin/lib/modules/css.js +0 -137
- package/bin/lib/modules/decorator.js +0 -14
- package/bin/lib/modules/fetch.js +0 -82
- package/bin/lib/modules/gbk.js +0 -46
- package/bin/lib/modules/hook/base.js +0 -60
- package/bin/lib/modules/hook/hooker.js +0 -39
- package/bin/lib/modules/hook/index.js +0 -49
- package/bin/lib/modules/hook/log.js +0 -54
- package/bin/lib/modules/hook/modules/bezier.js +0 -121
- package/bin/lib/modules/hook/modules/debounce.js +0 -127
- package/bin/lib/modules/hook/modules/mutex.js +0 -22
- package/bin/lib/modules/hook/modules/pipeline.js +0 -59
- package/bin/lib/modules/hook/modules/polling.js +0 -20
- package/bin/lib/modules/hook/modules/safeTask.js +0 -25
- package/bin/lib/modules/hook/modules/throttle.js +0 -30
- package/bin/lib/modules/html.js +0 -293
- package/bin/lib/modules/http/index.js +0 -171
- package/bin/lib/modules/http/interceptor.js +0 -22
- package/bin/lib/modules/list/base.js +0 -37
- package/bin/lib/modules/list/index.js +0 -90
- package/bin/lib/modules/logger.js +0 -55
- package/bin/lib/modules/math/index.js +0 -118
- package/bin/lib/modules/mini/diff.js +0 -97
- package/bin/lib/modules/mini/http/index.js +0 -155
- package/bin/lib/modules/mini/index.js +0 -71
- package/bin/lib/modules/node/aliyun.js +0 -156
- package/bin/lib/modules/node/brotli.js +0 -46
- package/bin/lib/modules/node/child.js +0 -18
- package/bin/lib/modules/node/ecdh-web.js +0 -11
- package/bin/lib/modules/node/ecdh.js +0 -115
- package/bin/lib/modules/node/file.js +0 -25
- package/bin/lib/modules/node/index.js +0 -11
- package/bin/lib/modules/node/proxy.js +0 -147
- package/bin/lib/modules/node/rsa-web.js +0 -19
- package/bin/lib/modules/node/socks5.js +0 -424
- package/bin/lib/modules/obj/index.js +0 -184
- package/bin/lib/modules/qs/base.js +0 -5
- package/bin/lib/modules/qs/decode.js +0 -45
- package/bin/lib/modules/qs/encode.js +0 -53
- package/bin/lib/modules/qs/index.js +0 -114
- package/bin/lib/modules/regex.js +0 -16
- package/bin/lib/modules/rsa.js +0 -18
- package/bin/lib/modules/rule/async-validator/index.js +0 -306
- package/bin/lib/modules/rule/async-validator/interface.js +0 -2
- package/bin/lib/modules/rule/async-validator/messages.js +0 -59
- package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
- package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
- package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
- package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
- package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
- package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
- package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
- package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
- package/bin/lib/modules/rule/async-validator/util.js +0 -255
- package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
- package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
- package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
- package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
- package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
- package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
- package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
- package/bin/lib/modules/rule/index.js +0 -67
- package/bin/lib/modules/string/index.js +0 -121
- package/bin/lib/modules/string/words.js +0 -33
- package/bin/lib/modules/time/const.js +0 -11
- package/bin/lib/modules/time/dtime.js +0 -132
- package/bin/lib/modules/time/frame.js +0 -49
- package/bin/lib/modules/time/index.js +0 -84
- package/bin/lib/typings/index.js +0 -2
- package/bin/lib/util/function.js +0 -33
- package/bin/lib/util/includes.js +0 -96
- package/bin/lib/util/index.js +0 -26
- package/bin/lib/util/is.js +0 -148
- package/bin/lib/util/to.js +0 -47
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const convert_1 = require("../convert");
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
class Ecdh {
|
|
6
|
-
publicKey = '';
|
|
7
|
-
privateKey = '';
|
|
8
|
-
sharedSecret;
|
|
9
|
-
iv = '';
|
|
10
|
-
__curve;
|
|
11
|
-
__algorithm;
|
|
12
|
-
__ecdh;
|
|
13
|
-
constructor(curve = 'prime256v1', algorithm = 'aes-256-gcm') {
|
|
14
|
-
this.__curve = curve;
|
|
15
|
-
this.__algorithm = algorithm;
|
|
16
|
-
this.generateKeys();
|
|
17
|
-
}
|
|
18
|
-
generateKeys() {
|
|
19
|
-
// 使用 P-256 曲线
|
|
20
|
-
const ecdh = crypto_1.default.createECDH('prime256v1');
|
|
21
|
-
ecdh.generateKeys();
|
|
22
|
-
// 公钥以 base64 格式导出
|
|
23
|
-
this.publicKey = ecdh.getPublicKey('base64');
|
|
24
|
-
// 私钥以 base64 格式导出
|
|
25
|
-
this.privateKey = ecdh.getPrivateKey('base64');
|
|
26
|
-
this.__ecdh = ecdh;
|
|
27
|
-
}
|
|
28
|
-
setPrivateKey(privateBase64) {
|
|
29
|
-
if (!privateBase64)
|
|
30
|
-
return false;
|
|
31
|
-
if (!this.__ecdh)
|
|
32
|
-
return false;
|
|
33
|
-
this.__ecdh.setPrivateKey(privateBase64, 'base64');
|
|
34
|
-
this.publicKey = this.__ecdh.getPublicKey('base64');
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
setSharedSecret(secretBase64) {
|
|
38
|
-
if (!secretBase64)
|
|
39
|
-
return false;
|
|
40
|
-
this.sharedSecret = secretBase64;
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
deriveSharedSecret(otherPublicKey, iv) {
|
|
44
|
-
if (!otherPublicKey)
|
|
45
|
-
return false;
|
|
46
|
-
this.sharedSecret = this.__ecdh.computeSecret(otherPublicKey, 'base64').toString('base64');
|
|
47
|
-
this.iv = iv || '';
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
encode(data, iv) {
|
|
51
|
-
if (!this.sharedSecret)
|
|
52
|
-
return '';
|
|
53
|
-
const _iv = iv || this.iv;
|
|
54
|
-
if (!_iv)
|
|
55
|
-
return '';
|
|
56
|
-
const ivBytes = convert_1.default.base64ToBytes(_iv);
|
|
57
|
-
const cipher = crypto_1.default.createCipheriv('aes-256-gcm', convert_1.default.base64ToBytes(this.sharedSecret), ivBytes);
|
|
58
|
-
const encrypted = Buffer.concat([
|
|
59
|
-
new Uint8Array(cipher.update(data, 'utf8')),
|
|
60
|
-
new Uint8Array(cipher.final()),
|
|
61
|
-
]);
|
|
62
|
-
const tagBuf = cipher.getAuthTag();
|
|
63
|
-
const combined = Buffer.concat([new Uint8Array(encrypted), new Uint8Array(tagBuf)]);
|
|
64
|
-
return combined.toString('base64');
|
|
65
|
-
}
|
|
66
|
-
encodeiv(data, iv) {
|
|
67
|
-
if (!this.sharedSecret)
|
|
68
|
-
return '';
|
|
69
|
-
const _iv = iv || this.iv;
|
|
70
|
-
const ivBytes = _iv ? convert_1.default.base64ToBytes(_iv) : convert_1.default.getRandomBytes(12);
|
|
71
|
-
const cipher = crypto_1.default.createCipheriv('aes-256-gcm', convert_1.default.base64ToBytes(this.sharedSecret), ivBytes);
|
|
72
|
-
const encrypted = Buffer.concat([
|
|
73
|
-
new Uint8Array(cipher.update(data, 'utf8')),
|
|
74
|
-
new Uint8Array(cipher.final()),
|
|
75
|
-
]);
|
|
76
|
-
const authTagBuf = cipher.getAuthTag();
|
|
77
|
-
const combined = Buffer.concat([new Uint8Array(encrypted), new Uint8Array(authTagBuf), ivBytes]);
|
|
78
|
-
return combined.toString('base64');
|
|
79
|
-
}
|
|
80
|
-
decode(encrypted, iv) {
|
|
81
|
-
if (!encrypted || !this.sharedSecret)
|
|
82
|
-
return '';
|
|
83
|
-
const _iv = iv || this.iv;
|
|
84
|
-
if (!_iv)
|
|
85
|
-
return '';
|
|
86
|
-
const decipher = crypto_1.default.createDecipheriv('aes-256-gcm', convert_1.default.base64ToBytes(this.sharedSecret), convert_1.default.base64ToBytes(_iv));
|
|
87
|
-
const allBytes = convert_1.default.base64ToBytes(encrypted);
|
|
88
|
-
const authTagBytes = allBytes.slice(allBytes.length - 16);
|
|
89
|
-
decipher.setAuthTag(authTagBytes);
|
|
90
|
-
const encryptedBytes = allBytes.slice(0, allBytes.length - 16);
|
|
91
|
-
const decrypted = Buffer.concat([
|
|
92
|
-
new Uint8Array(decipher.update(encryptedBytes)),
|
|
93
|
-
new Uint8Array(decipher.final()),
|
|
94
|
-
]);
|
|
95
|
-
return decrypted.toString('utf-8');
|
|
96
|
-
}
|
|
97
|
-
decodeiv(encrypted) {
|
|
98
|
-
if (!encrypted || !this.sharedSecret)
|
|
99
|
-
return '';
|
|
100
|
-
const allBytes = convert_1.default.base64ToBytes(encrypted);
|
|
101
|
-
if (allBytes.length < 28)
|
|
102
|
-
return '';
|
|
103
|
-
const ivBytes = allBytes.slice(allBytes.length - 12);
|
|
104
|
-
const tagBytes = allBytes.slice(allBytes.length - 28, allBytes.length - 12);
|
|
105
|
-
const decipher = crypto_1.default.createDecipheriv('aes-256-gcm', convert_1.default.base64ToBytes(this.sharedSecret), ivBytes);
|
|
106
|
-
decipher.setAuthTag(tagBytes);
|
|
107
|
-
const encryptedBytes = allBytes.slice(0, allBytes.length - 28);
|
|
108
|
-
const decrypted = Buffer.concat([
|
|
109
|
-
new Uint8Array(decipher.update(encryptedBytes)),
|
|
110
|
-
new Uint8Array(decipher.final()),
|
|
111
|
-
]);
|
|
112
|
-
return decrypted.toString('utf-8');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.default = Ecdh;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs_1 = require("fs");
|
|
4
|
-
const readDirectory = (dir, callback) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
fs_1.default.readdir(dir, async (err, files) => {
|
|
7
|
-
if (err) {
|
|
8
|
-
return reject(err);
|
|
9
|
-
}
|
|
10
|
-
resolve(readFiles(dir, files, callback));
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
const readFiles = async (dir, files, callback) => {
|
|
15
|
-
for (let file of files) {
|
|
16
|
-
const localname = `${dir}\\${file}`;
|
|
17
|
-
if (fs_1.default.lstatSync(localname).isDirectory()) {
|
|
18
|
-
await readDirectory(`${localname}`, callback);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
callback && (await callback(localname));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
exports.default = { readDirectory, readFiles };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const brotli_1 = require("./brotli");
|
|
4
|
-
const ecdh_1 = require("./ecdh");
|
|
5
|
-
const socks5_1 = require("./socks5");
|
|
6
|
-
const child_1 = require("./child");
|
|
7
|
-
const proxy_1 = require("./proxy");
|
|
8
|
-
const ecdh_web_1 = require("./ecdh-web");
|
|
9
|
-
const rsa_web_1 = require("./rsa-web");
|
|
10
|
-
const file_1 = require("./file");
|
|
11
|
-
exports.default = { ...file_1.default, ...brotli_1.default, ...child_1.default, ...proxy_1.default, Ecdh: ecdh_1.default, EcdhWeb: ecdh_web_1.default, Socks5: socks5_1.Socks5, rsa: rsa_web_1.default };
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const child_1 = require("./child");
|
|
4
|
-
const convert_1 = require("../convert");
|
|
5
|
-
const getSystemProxy = () => {
|
|
6
|
-
try {
|
|
7
|
-
if (process.platform === 'win32') {
|
|
8
|
-
return getWindowsSystemProxy();
|
|
9
|
-
}
|
|
10
|
-
else if (process.platform === 'darwin') {
|
|
11
|
-
return getMacOSSystemProxy();
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const getWindowsSystemProxy = async () => {
|
|
22
|
-
do {
|
|
23
|
-
let err, text;
|
|
24
|
-
[err, text] = await child_1.default.child_exec(`reg query "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"`);
|
|
25
|
-
if (err)
|
|
26
|
-
break;
|
|
27
|
-
const proxyEnabledLine = text.split('\n').find((line) => line.includes('ProxyEnable'));
|
|
28
|
-
const ProxyEnable = proxyEnabledLine && proxyEnabledLine.trim().endsWith('1');
|
|
29
|
-
if (!ProxyEnable)
|
|
30
|
-
break;
|
|
31
|
-
const proxyServerLine = text.split('\n').find((line) => line.includes('ProxyServer'));
|
|
32
|
-
const proxyServer = proxyServerLine ? proxyServerLine.split(' ').filter(Boolean).pop() : '';
|
|
33
|
-
if (!proxyServer)
|
|
34
|
-
break;
|
|
35
|
-
// 解析 IP 和端口
|
|
36
|
-
const proxyParts = proxyServer.split(':');
|
|
37
|
-
if (proxyParts.length <= 1)
|
|
38
|
-
break;
|
|
39
|
-
const ipaddress = proxyParts[0];
|
|
40
|
-
const port = +(proxyParts[1] || '');
|
|
41
|
-
if (!ipaddress || !port)
|
|
42
|
-
break;
|
|
43
|
-
return { ipaddress, port };
|
|
44
|
-
} while (false);
|
|
45
|
-
return undefined;
|
|
46
|
-
};
|
|
47
|
-
const getMacOSSystemProxy = async () => {
|
|
48
|
-
do {
|
|
49
|
-
let err, text;
|
|
50
|
-
[err, text] = await child_1.default.child_exec(`networksetup -getwebproxy "Wi-Fi"`);
|
|
51
|
-
if (err)
|
|
52
|
-
break;
|
|
53
|
-
const outputLines = text.split('\n');
|
|
54
|
-
const proxyEnabledLine = outputLines.find((line) => line.includes('Enabled'));
|
|
55
|
-
const isEnabled = proxyEnabledLine && proxyEnabledLine.includes('Yes');
|
|
56
|
-
if (!isEnabled)
|
|
57
|
-
break;
|
|
58
|
-
const proxyServerLine = outputLines.find((line) => line.includes('Server'));
|
|
59
|
-
const proxyPortLine = outputLines.find((line) => line.includes('Port'));
|
|
60
|
-
const ipaddress = proxyServerLine ? proxyServerLine.split(':')[1]?.trim() : null;
|
|
61
|
-
const proxyPort = proxyPortLine ? proxyPortLine.split(':')[1]?.trim() : null;
|
|
62
|
-
const port = +(proxyPort || '');
|
|
63
|
-
if (!ipaddress || !port)
|
|
64
|
-
break;
|
|
65
|
-
return { ipaddress, port };
|
|
66
|
-
} while (false);
|
|
67
|
-
return undefined;
|
|
68
|
-
};
|
|
69
|
-
// { proxy = 'DIRECT'; default = 'DIRECT', rules: string[]
|
|
70
|
-
const toPacScript = (proxy, rules = ['*'], defaultProxy = 'DIRECT') => {
|
|
71
|
-
const _proxy = proxy || defaultProxy || 'DIRECT';
|
|
72
|
-
const _default = defaultProxy || 'DIRECT';
|
|
73
|
-
const content = `
|
|
74
|
-
function FindProxyForURL(url, host) {
|
|
75
|
-
if (host === "127.0.0.1" || host === "localhost") {
|
|
76
|
-
return "DIRECT";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (isInNet(host, "10.0.0.0", "255.0.0.0") ||
|
|
80
|
-
isInNet(host, "172.16.0.0", "255.240.0.0") ||
|
|
81
|
-
isInNet(host, "192.168.0.0", "255.255.0.0")) {
|
|
82
|
-
return "DIRECT";
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
var _rules = ${JSON.stringify(rules)};
|
|
86
|
-
var _proxy = "${_proxy}";
|
|
87
|
-
var _default = "${_default}";
|
|
88
|
-
|
|
89
|
-
for (var i = 0; i < _rules.length; i++) {
|
|
90
|
-
if (shExpMatch(host, _rules[i])) {
|
|
91
|
-
return _proxy;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return _default;
|
|
96
|
-
}
|
|
97
|
-
`;
|
|
98
|
-
return convert_1.default.toDataUrl(content, 'application/x-ns-proxy-autoconfig');
|
|
99
|
-
};
|
|
100
|
-
const toPacProxy = (ipaddress, port, options) => {
|
|
101
|
-
if (!ipaddress || !port)
|
|
102
|
-
return '';
|
|
103
|
-
const { type = 'ALL', direct = false } = options || {};
|
|
104
|
-
let text = '';
|
|
105
|
-
const _type = type ? type.toUpperCase() : '';
|
|
106
|
-
switch (_type) {
|
|
107
|
-
case 'ALL':
|
|
108
|
-
text = `SOCKS5 ${ipaddress}:${port};PROXY ${ipaddress}:${port}`;
|
|
109
|
-
break;
|
|
110
|
-
case 'PROXY':
|
|
111
|
-
text = `PROXY ${ipaddress}:${port}`;
|
|
112
|
-
break;
|
|
113
|
-
case 'SOCKS5':
|
|
114
|
-
text = `SOCKS5 ${ipaddress}:${port}`;
|
|
115
|
-
break;
|
|
116
|
-
default:
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
if (!text && !direct)
|
|
120
|
-
return '';
|
|
121
|
-
const temps = [];
|
|
122
|
-
text && temps.push(text);
|
|
123
|
-
direct && temps.push('DIRECT');
|
|
124
|
-
return temps.join(';');
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* 生成 pac script 内容
|
|
128
|
-
* @param host
|
|
129
|
-
* @param port
|
|
130
|
-
* @param options
|
|
131
|
-
* @returns
|
|
132
|
-
*/
|
|
133
|
-
const pacScript = async (host, port, options) => {
|
|
134
|
-
const { type = "SOCKS5", rules = ['*'], useSystem } = options || {};
|
|
135
|
-
const pac_proxy = toPacProxy(host, port, { type });
|
|
136
|
-
if (!pac_proxy)
|
|
137
|
-
return "";
|
|
138
|
-
let pac_default = undefined;
|
|
139
|
-
if (useSystem) {
|
|
140
|
-
const sysproxy = await getSystemProxy();
|
|
141
|
-
if (sysproxy) {
|
|
142
|
-
pac_default = toPacProxy(sysproxy?.ipaddress || '', sysproxy?.port || 0, { direct: true });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return toPacScript(pac_proxy, rules || [], pac_default);
|
|
146
|
-
};
|
|
147
|
-
exports.default = { getSystemProxy, toPacScript, toPacProxy, pacScript };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rsa_1 = require("../crypto/rsa");
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
const getSubtle = () => crypto_1.default.webcrypto.subtle;
|
|
6
|
-
const generateKeys = () => rsa_1.default.generateKeys(getSubtle());
|
|
7
|
-
// SHA256: 256 - 2 - 2*32 = 190
|
|
8
|
-
// SHA1: 256 - 2 - 2*20 = 214
|
|
9
|
-
const encrypt = async (data, publicKey) => rsa_1.default.encrypt(getSubtle(), data, publicKey);
|
|
10
|
-
const decrypt = async (encryptedBase64, privateKey) => rsa_1.default.decrypt(getSubtle(), encryptedBase64, privateKey);
|
|
11
|
-
const encode = async (data) => rsa_1.default.encrypt(getSubtle(), data, rsa_1.default.RSAPublicKey);
|
|
12
|
-
const decode = async (encryptedBase64) => rsa_1.default.decrypt(getSubtle(), encryptedBase64, rsa_1.default.RSAPrivateKey);
|
|
13
|
-
exports.default = {
|
|
14
|
-
generateKeys,
|
|
15
|
-
encrypt,
|
|
16
|
-
decrypt,
|
|
17
|
-
encode,
|
|
18
|
-
decode,
|
|
19
|
-
};
|