ddan-js 2.9.4 → 2.9.6

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.
Files changed (131) hide show
  1. package/bin/types/browser.d.ts +1 -1
  2. package/bin/types/index.d.ts +1 -1
  3. package/bin/types/modules/node/aliyun.d.ts +1 -1
  4. package/bin/types/upload.d.ts +2 -0
  5. package/bin/upload.js +1 -0
  6. package/package.json +18 -13
  7. package/bin/lib/browser.js +0 -111
  8. package/bin/lib/class/event.js +0 -104
  9. package/bin/lib/class/getset.js +0 -12
  10. package/bin/lib/class/icon.js +0 -94
  11. package/bin/lib/class/joker.js +0 -121
  12. package/bin/lib/class/kvalue.js +0 -29
  13. package/bin/lib/class/mapping.js +0 -82
  14. package/bin/lib/class/persist.js +0 -65
  15. package/bin/lib/class/pipeTask.js +0 -42
  16. package/bin/lib/class/pipeparallel.js +0 -24
  17. package/bin/lib/class/store.js +0 -87
  18. package/bin/lib/class/tracker.js +0 -125
  19. package/bin/lib/class/watermark.js +0 -63
  20. package/bin/lib/common/_Symbol.js +0 -5
  21. package/bin/lib/common/_freeGlobal.js +0 -5
  22. package/bin/lib/common/_object.js +0 -40
  23. package/bin/lib/common/_root.js +0 -10
  24. package/bin/lib/common/internal/asciiToArray.js +0 -13
  25. package/bin/lib/common/internal/castSlice.js +0 -18
  26. package/bin/lib/common/internal/createCaseFirst.js +0 -30
  27. package/bin/lib/common/internal/hasUnicode.js +0 -26
  28. package/bin/lib/common/internal/nodeTypes.js +0 -26
  29. package/bin/lib/common/internal/slice.js +0 -46
  30. package/bin/lib/common/internal/stringToArray.js +0 -18
  31. package/bin/lib/common/internal/unicodeToArray.js +0 -40
  32. package/bin/lib/common/internal/unicodeWords.js +0 -67
  33. package/bin/lib/index.js +0 -114
  34. package/bin/lib/modules/browser/ecdh.js +0 -124
  35. package/bin/lib/modules/browser/index.js +0 -4
  36. package/bin/lib/modules/cdn.js +0 -62
  37. package/bin/lib/modules/convert/base.js +0 -125
  38. package/bin/lib/modules/convert/base64.js +0 -114
  39. package/bin/lib/modules/convert/index.js +0 -99
  40. package/bin/lib/modules/convert/md5.js +0 -222
  41. package/bin/lib/modules/convert/pkcs.js +0 -16
  42. package/bin/lib/modules/convert/utf8.js +0 -106
  43. package/bin/lib/modules/crypto/base64.js +0 -14
  44. package/bin/lib/modules/crypto/const.js +0 -7
  45. package/bin/lib/modules/crypto/index.js +0 -30
  46. package/bin/lib/modules/crypto/rsa.js +0 -143
  47. package/bin/lib/modules/crypto/tea.js +0 -79
  48. package/bin/lib/modules/crypto/uuid.js +0 -34
  49. package/bin/lib/modules/css.js +0 -137
  50. package/bin/lib/modules/decorator.js +0 -14
  51. package/bin/lib/modules/fetch.js +0 -82
  52. package/bin/lib/modules/gbk.js +0 -46
  53. package/bin/lib/modules/hook/base.js +0 -60
  54. package/bin/lib/modules/hook/hooker.js +0 -39
  55. package/bin/lib/modules/hook/index.js +0 -49
  56. package/bin/lib/modules/hook/log.js +0 -54
  57. package/bin/lib/modules/hook/modules/bezier.js +0 -121
  58. package/bin/lib/modules/hook/modules/debounce.js +0 -127
  59. package/bin/lib/modules/hook/modules/mutex.js +0 -22
  60. package/bin/lib/modules/hook/modules/pipeline.js +0 -59
  61. package/bin/lib/modules/hook/modules/polling.js +0 -20
  62. package/bin/lib/modules/hook/modules/safeTask.js +0 -25
  63. package/bin/lib/modules/hook/modules/throttle.js +0 -30
  64. package/bin/lib/modules/html.js +0 -293
  65. package/bin/lib/modules/http/index.js +0 -171
  66. package/bin/lib/modules/http/interceptor.js +0 -22
  67. package/bin/lib/modules/list/base.js +0 -37
  68. package/bin/lib/modules/list/index.js +0 -90
  69. package/bin/lib/modules/logger.js +0 -55
  70. package/bin/lib/modules/math/index.js +0 -118
  71. package/bin/lib/modules/mini/diff.js +0 -97
  72. package/bin/lib/modules/mini/http/index.js +0 -155
  73. package/bin/lib/modules/mini/index.js +0 -71
  74. package/bin/lib/modules/node/aliyun.js +0 -156
  75. package/bin/lib/modules/node/brotli.js +0 -46
  76. package/bin/lib/modules/node/child.js +0 -18
  77. package/bin/lib/modules/node/ecdh-web.js +0 -11
  78. package/bin/lib/modules/node/ecdh.js +0 -115
  79. package/bin/lib/modules/node/file.js +0 -25
  80. package/bin/lib/modules/node/index.js +0 -11
  81. package/bin/lib/modules/node/proxy.js +0 -147
  82. package/bin/lib/modules/node/rsa-web.js +0 -19
  83. package/bin/lib/modules/node/socks5.js +0 -424
  84. package/bin/lib/modules/obj/index.js +0 -184
  85. package/bin/lib/modules/qs/base.js +0 -5
  86. package/bin/lib/modules/qs/decode.js +0 -45
  87. package/bin/lib/modules/qs/encode.js +0 -53
  88. package/bin/lib/modules/qs/index.js +0 -152
  89. package/bin/lib/modules/regex.js +0 -16
  90. package/bin/lib/modules/rsa.js +0 -18
  91. package/bin/lib/modules/rule/async-validator/index.js +0 -306
  92. package/bin/lib/modules/rule/async-validator/interface.js +0 -2
  93. package/bin/lib/modules/rule/async-validator/messages.js +0 -59
  94. package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
  95. package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
  96. package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
  97. package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
  98. package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
  99. package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
  100. package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
  101. package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
  102. package/bin/lib/modules/rule/async-validator/util.js +0 -255
  103. package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
  104. package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
  105. package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
  106. package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
  107. package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
  108. package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
  109. package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
  110. package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
  111. package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
  112. package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
  113. package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
  114. package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
  115. package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
  116. package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
  117. package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
  118. package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
  119. package/bin/lib/modules/rule/index.js +0 -67
  120. package/bin/lib/modules/string/index.js +0 -121
  121. package/bin/lib/modules/string/words.js +0 -33
  122. package/bin/lib/modules/time/const.js +0 -11
  123. package/bin/lib/modules/time/dtime.js +0 -132
  124. package/bin/lib/modules/time/frame.js +0 -49
  125. package/bin/lib/modules/time/index.js +0 -84
  126. package/bin/lib/typings/index.js +0 -2
  127. package/bin/lib/util/function.js +0 -33
  128. package/bin/lib/util/includes.js +0 -96
  129. package/bin/lib/util/index.js +0 -26
  130. package/bin/lib/util/is.js +0 -148
  131. package/bin/lib/util/to.js +0 -47
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const obj_1 = require("../../obj");
4
- const interceptor_1 = require("../../http/interceptor");
5
- class MiniHttp {
6
- // 接口配置
7
- reqConfig = {};
8
- handleRequest;
9
- handleEncrypt;
10
- handleDecrypt;
11
- handleError;
12
- // 拦截器
13
- interceptors = {
14
- request: new interceptor_1.default(),
15
- response: new interceptor_1.default(),
16
- };
17
- constructor(options) {
18
- const { reqConfig = {}, requestEncrypt, responseDecrypt, handleError, api } = options;
19
- this.reqConfig = reqConfig;
20
- this.handleEncrypt = requestEncrypt;
21
- this.handleDecrypt = responseDecrypt;
22
- this.handleError = handleError;
23
- this.handleRequest = api;
24
- }
25
- // 阻塞请求的锁id
26
- static blockId = "blockid";
27
- // 请求锁字典
28
- static requestLock = {};
29
- /**
30
- * 加锁
31
- * @param {string} id
32
- * @param {function} func
33
- */
34
- lockR(id, func) {
35
- MiniHttp.requestLock[id] = {
36
- lock: true,
37
- request: func(),
38
- };
39
- }
40
- /**
41
- * 解锁
42
- * @param {string} id
43
- */
44
- unlockR(id) {
45
- delete MiniHttp.requestLock[id];
46
- }
47
- /**
48
- * 根据URL和请求参数构造唯一标识符
49
- * @param {object} req
50
- */
51
- getIdFromReq(req) {
52
- const { url, data = {} } = req;
53
- return url + JSON.stringify(data);
54
- }
55
- /**
56
- * 根据URL构造唯一标识符
57
- * @param {object} req
58
- */
59
- getIdFromReqUrl(req) {
60
- return req.url || "";
61
- }
62
- /**
63
- * 请求函数
64
- * @param {object} _payload 小程序 wx.request 可用参数
65
- * @param {boolean} hasEncrypt 是否需要加密
66
- */
67
- _fetch(_payload, hasEncrypt) {
68
- let payload = _payload;
69
- if (hasEncrypt && this.handleEncrypt) {
70
- payload = this.handleEncrypt(_payload);
71
- }
72
- return new Promise((resolve, reject) => {
73
- this.handleRequest({
74
- ...payload,
75
- success: (_res) => {
76
- let res = _res;
77
- if (hasEncrypt && this.handleDecrypt) {
78
- res = this.handleDecrypt(_res);
79
- }
80
- resolve(res);
81
- },
82
- fail: (err) => {
83
- reject(err);
84
- },
85
- });
86
- });
87
- }
88
- /**
89
- * 请求{name}接口
90
- * @param {string} name
91
- * @param {object} payload
92
- */
93
- async request(name, payload) {
94
- const config = obj_1.default.copy(this.reqConfig[name]); // JSON.parse(JSON.stringify();
95
- // 进行请求参数的处理
96
- const { config: _, ...req } = await this.interceptors.request.invoke({
97
- url: config.url,
98
- data: payload || {},
99
- header: { "content-type": "application/json" },
100
- method: config.method ? config.method : "POST",
101
- responseType: "text",
102
- config,
103
- });
104
- let result;
105
- try {
106
- // 处理阻塞/去抖/普通请求
107
- if (_.model === "block") {
108
- this.lockR(MiniHttp.blockId, () => this._fetch(req, _.hasEncrypt));
109
- result = await MiniHttp.requestLock[MiniHttp.blockId].request;
110
- // note: 在具体的回调函数中主动 unlock
111
- }
112
- else {
113
- if (MiniHttp.requestLock[MiniHttp.blockId] &&
114
- MiniHttp.requestLock[MiniHttp.blockId].lock) {
115
- await MiniHttp.requestLock[MiniHttp.blockId].request;
116
- }
117
- //去抖模式
118
- if (_.model === "debounce" || _.model === "debounceUrl") {
119
- let id;
120
- if (_.model === "debounceUrl") {
121
- // 仅针对url去抖的临时方案
122
- id = this.getIdFromReqUrl(req);
123
- }
124
- else {
125
- id = this.getIdFromReq(req);
126
- }
127
- if (!MiniHttp.requestLock[id]) {
128
- this.lockR(id, () => this._fetch(req, _.hasEncrypt));
129
- }
130
- result = await MiniHttp.requestLock[id].request;
131
- this.unlockR(id);
132
- }
133
- else {
134
- result = await this._fetch(req, _.hasEncrypt);
135
- }
136
- }
137
- }
138
- catch (error) {
139
- this.handleError && this.handleError(error);
140
- }
141
- // 抛出response 拦截器 (由原来的直接抛出result改为抛出包含res、reqId、refetch的对象)
142
- // const res = this.interceptors.response.invoke(result);
143
- const res = this.interceptors.response.invoke({
144
- res: result,
145
- config,
146
- reqId: this.getIdFromReq(req),
147
- refetch: () => {
148
- // 重新请求
149
- return { sig: "REFETCH", result: this.request(name, payload || {}) };
150
- },
151
- });
152
- return res;
153
- }
154
- }
155
- exports.default = MiniHttp;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const diff_1 = require("./diff");
4
- const hook_1 = require("../hook");
5
- const http_1 = require("./http");
6
- const obj_1 = require("../obj");
7
- /**
8
- * promise 化 wx 异步函数
9
- * @param miniapi
10
- * @returns
11
- */
12
- const promixify = (miniapi) => {
13
- if (typeof miniapi !== "function")
14
- return miniapi;
15
- return (args = {}) => new Promise((resolve, reject) => {
16
- miniapi(Object.assign(args, { success: resolve, fail: reject }));
17
- });
18
- };
19
- /**
20
- * 执行 wx 异步函数
21
- * @param func
22
- * @param args
23
- * @returns
24
- */
25
- const run = (func, args = {}) => {
26
- if (!func)
27
- return hook_1.default.run(func);
28
- return hook_1.default.run(promixify(func)(args));
29
- };
30
- /**
31
- * 格式化列表
32
- * @param lists
33
- * @param start
34
- * @param name
35
- * @returns
36
- */
37
- const formatList = (lists, start, name) => {
38
- return (lists || []).reduce((res, val, index) => ({ ...res, [`${name}[${start + index}]`]: val }), {});
39
- };
40
- /**
41
- * 字段简易规则
42
- * @param _
43
- * @param value
44
- * @returns
45
- */
46
- const ruleValidator = (_, value) => {
47
- if (!value)
48
- return false;
49
- if (Array.isArray(value)) {
50
- if (value.length <= 0)
51
- return false;
52
- return value.every((e) => !!e);
53
- }
54
- return true;
55
- };
56
- const setWatcher = (page) => {
57
- let data = page.data;
58
- let watch = page.watch;
59
- Object.keys(watch).forEach((item) => {
60
- let targetData = data;
61
- let keys = item.split(".");
62
- for (let i = 0; i < keys.length - 1; i++) {
63
- targetData = targetData[keys[i]];
64
- }
65
- let targetKey = keys[keys.length - 1];
66
- let watchFun = watch[item].handler || watch[item];
67
- let deep = watch[item].deep;
68
- obj_1.default.observe(targetData, targetKey, watchFun, page, deep);
69
- });
70
- };
71
- exports.default = { diff: diff_1.default, promixify, run, formatList, ruleValidator, Http: http_1.default, setWatcher };
@@ -1,156 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ali_oss_1 = require("ali-oss");
4
- const pop_core_1 = require("@alicloud/pop-core");
5
- class Aliyun {
6
- bucket;
7
- accessKeyId;
8
- accessKeySecret;
9
- region;
10
- __oss;
11
- __cdn;
12
- constructor({ bucket, accessKeyId, accessKeySecret, region }) {
13
- this.bucket = bucket;
14
- this.accessKeyId = accessKeyId;
15
- this.accessKeySecret = accessKeySecret;
16
- this.region = region;
17
- this.__oss = this._getOSS();
18
- }
19
- get client() {
20
- if (!this.__oss) {
21
- this.__oss = this._getOSS();
22
- }
23
- return this.__oss;
24
- }
25
- _getOSS() {
26
- return new ali_oss_1.default({
27
- region: this.region,
28
- accessKeyId: this.accessKeyId,
29
- accessKeySecret: this.accessKeySecret,
30
- bucket: this.bucket,
31
- });
32
- }
33
- async read(name) {
34
- try {
35
- if (!(await this.exist(name)))
36
- return '';
37
- const result = await this.client.get(name);
38
- return result.content?.toString() || '';
39
- }
40
- catch (err) {
41
- console.log(`aliyun read ${name} error`, err);
42
- return undefined;
43
- }
44
- }
45
- async delete(name) {
46
- try {
47
- await this.client.delete(name);
48
- return true;
49
- }
50
- catch (err) {
51
- console.log(`aliyun delete ${name} error`, err);
52
- return false;
53
- }
54
- }
55
- async exist(name, options = {}) {
56
- try {
57
- await this.client.head(name, options);
58
- return true;
59
- }
60
- catch (err) {
61
- return false;
62
- }
63
- }
64
- async upload(name, localname) {
65
- try {
66
- if (!name || !localname)
67
- return false;
68
- await this.client.put(name, localname);
69
- return true;
70
- }
71
- catch (err) {
72
- console.log(`aliyun upload ${localname} error`, err);
73
- return false;
74
- }
75
- }
76
- async put(name, content) {
77
- try {
78
- if (!name || !content)
79
- return false;
80
- await this.client.put(name, Buffer.from(content));
81
- return true;
82
- }
83
- catch (err) {
84
- console.log(`aliyun put content ${name} error`, err);
85
- return false;
86
- }
87
- }
88
- async putSymlink(symlinkName, sourceName) {
89
- try {
90
- if (!symlinkName || !sourceName)
91
- return false;
92
- // @ts-ignore
93
- const res = await this.client.putSymlink(symlinkName, sourceName);
94
- return res;
95
- }
96
- catch (error) {
97
- return false;
98
- }
99
- }
100
- async browse(name, cb) {
101
- let token = undefined;
102
- let flag = false;
103
- const maxKeys = "50";
104
- const prefix = name.endsWith('/') ? name : `${name}/`;
105
- try {
106
- do {
107
- const result = await this.client.listV2({
108
- prefix,
109
- 'continuation-token': token,
110
- 'max-keys': maxKeys,
111
- }, {});
112
- for (let item of result.objects || []) {
113
- cb && (await cb(item.name));
114
- }
115
- // @ts-ignore
116
- token = result.nextContinuationToken;
117
- flag = result.isTruncated;
118
- } while (flag);
119
- return true;
120
- }
121
- catch (err) {
122
- console.log(`aliyun browse ${name} error`, err);
123
- return false;
124
- }
125
- }
126
- get cdn() {
127
- if (this.__cdn)
128
- return this.__cdn;
129
- this.__cdn = new pop_core_1.default({
130
- accessKeyId: this.accessKeyId,
131
- accessKeySecret: this.accessKeySecret,
132
- endpoint: 'https://cdn.aliyuncs.com',
133
- apiVersion: '2018-05-10',
134
- });
135
- return this.__cdn;
136
- }
137
- async refreshCDN(url, type = 'File') {
138
- try {
139
- let params = {
140
- ObjectPath: url,
141
- ObjectType: type,
142
- };
143
- const requestOption = {
144
- method: 'POST',
145
- formatParams: false,
146
- };
147
- await this.cdn.request('RefreshObjectCaches', params, requestOption);
148
- return true;
149
- }
150
- catch (err) {
151
- console.log(`aliyun refreshCDN ${url} err`, err);
152
- return false;
153
- }
154
- }
155
- }
156
- exports.default = Aliyun;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.brotliDecompress = exports.brotliCompress = void 0;
4
- const zlib_1 = require("zlib");
5
- const convert_1 = require("../convert");
6
- /**
7
- * brotli 压缩
8
- * @param data
9
- * @returns
10
- */
11
- function brotliCompress(data, quality = zlib_1.default.constants.BROTLI_DEFAULT_QUALITY) {
12
- try {
13
- if (!data)
14
- return '';
15
- const uint8Array = convert_1.default.toUtf8Bytes(data);
16
- const compressBuff = zlib_1.default.brotliCompressSync(uint8Array, {
17
- params: {
18
- [zlib_1.default.constants.BROTLI_PARAM_QUALITY]: quality,
19
- },
20
- });
21
- return compressBuff.toString('base64');
22
- }
23
- catch (error) {
24
- return data || '';
25
- }
26
- }
27
- exports.brotliCompress = brotliCompress;
28
- /**
29
- * brotli 解压
30
- * @param data
31
- * @returns
32
- */
33
- function brotliDecompress(data) {
34
- try {
35
- if (!data)
36
- return '';
37
- const buff = convert_1.default.base64ToBytes(data);
38
- const decomporessBuff = zlib_1.default.brotliDecompressSync(buff);
39
- return decomporessBuff.toString('utf-8');
40
- }
41
- catch (error) {
42
- return data || '';
43
- }
44
- }
45
- exports.brotliDecompress = brotliDecompress;
46
- exports.default = { brotliCompress, brotliDecompress };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
- const child_exec = (cmd) => {
5
- return new Promise((resolve) => {
6
- if (!cmd)
7
- return resolve([null, '']);
8
- (0, child_process_1.exec)(cmd, (err, stdout) => {
9
- if (err) {
10
- resolve([err || 'error', '']);
11
- }
12
- else {
13
- resolve([null, stdout || '']);
14
- }
15
- });
16
- });
17
- };
18
- exports.default = { child_exec };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const crypto_1 = require("crypto");
4
- const ecdh_1 = require("../browser/ecdh");
5
- class EcdhWeb extends ecdh_1.default {
6
- constructor(curve = "P-256", keyFormat = "raw") {
7
- super(curve, keyFormat);
8
- this.__subtle = crypto_1.default.webcrypto.subtle;
9
- }
10
- }
11
- exports.default = EcdhWeb;
@@ -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 };