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,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /** Used to compose unicode character classes. */
4
- const rsAstralRange = '\\ud800-\\udfff';
5
- const rsComboMarksRange = '\\u0300-\\u036f';
6
- const reComboHalfMarksRange = '\\ufe20-\\ufe2f';
7
- const rsComboSymbolsRange = '\\u20d0-\\u20ff';
8
- const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff';
9
- const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff';
10
- const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange;
11
- const rsVarRange = '\\ufe0e\\ufe0f';
12
- /** Used to compose unicode capture groups. */
13
- const rsAstral = `[${rsAstralRange}]`;
14
- const rsCombo = `[${rsComboRange}]`;
15
- const rsFitz = '\\ud83c[\\udffb-\\udfff]';
16
- const rsModifier = `(?:${rsCombo}|${rsFitz})`;
17
- const rsNonAstral = `[^${rsAstralRange}]`;
18
- const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
19
- const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
20
- const rsZWJ = '\\u200d';
21
- /** Used to compose unicode regexes. */
22
- const reOptMod = `${rsModifier}?`;
23
- const rsOptVar = `[${rsVarRange}]?`;
24
- const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`;
25
- const rsSeq = rsOptVar + reOptMod + rsOptJoin;
26
- const rsNonAstralCombo = `${rsNonAstral}${rsCombo}?`;
27
- const rsSymbol = `(?:${[rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|')})`;
28
- /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
29
- const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, 'g');
30
- /**
31
- * Converts a Unicode `string` to an array.
32
- *
33
- * @private
34
- * @param {string} string The string to convert.
35
- * @returns {Array} Returns the converted array.
36
- */
37
- function unicodeToArray(string) {
38
- return string.match(reUnicode) || [];
39
- }
40
- exports.default = unicodeToArray;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /** Used to compose unicode character classes. */
4
- const rsAstralRange = '\\ud800-\\udfff';
5
- const rsComboMarksRange = '\\u0300-\\u036f';
6
- const reComboHalfMarksRange = '\\ufe20-\\ufe2f';
7
- const rsComboSymbolsRange = '\\u20d0-\\u20ff';
8
- const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff';
9
- const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff';
10
- const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange;
11
- const rsDingbatRange = '\\u2700-\\u27bf';
12
- const rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff';
13
- const rsMathOpRange = '\\xac\\xb1\\xd7\\xf7';
14
- const rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
15
- const rsPunctuationRange = '\\u2000-\\u206f';
16
- const rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000';
17
- const rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
18
- const rsVarRange = '\\ufe0e\\ufe0f';
19
- const rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
20
- /** Used to compose unicode capture groups. */
21
- const rsApos = "['\u2019]";
22
- const rsBreak = `[${rsBreakRange}]`;
23
- const rsCombo = `[${rsComboRange}]`;
24
- const rsDigit = '\\d';
25
- const rsDingbat = `[${rsDingbatRange}]`;
26
- const rsLower = `[${rsLowerRange}]`;
27
- const rsMisc = `[^${rsAstralRange}${rsBreakRange + rsDigit + rsDingbatRange + rsLowerRange + rsUpperRange}]`;
28
- const rsFitz = '\\ud83c[\\udffb-\\udfff]';
29
- const rsModifier = `(?:${rsCombo}|${rsFitz})`;
30
- const rsNonAstral = `[^${rsAstralRange}]`;
31
- const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
32
- const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
33
- const rsUpper = `[${rsUpperRange}]`;
34
- const rsZWJ = '\\u200d';
35
- /** Used to compose unicode regexes. */
36
- const rsMiscLower = `(?:${rsLower}|${rsMisc})`;
37
- const rsMiscUpper = `(?:${rsUpper}|${rsMisc})`;
38
- const rsOptContrLower = `(?:${rsApos}(?:d|ll|m|re|s|t|ve))?`;
39
- const rsOptContrUpper = `(?:${rsApos}(?:D|LL|M|RE|S|T|VE))?`;
40
- const reOptMod = `${rsModifier}?`;
41
- const rsOptVar = `[${rsVarRange}]?`;
42
- const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`;
43
- const rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
44
- const rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
45
- const rsSeq = rsOptVar + reOptMod + rsOptJoin;
46
- const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}`;
47
- const reUnicodeWords = RegExp([
48
- `${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`,
49
- `${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`,
50
- `${rsUpper}?${rsMiscLower}+${rsOptContrLower}`,
51
- `${rsUpper}+${rsOptContrUpper}`,
52
- rsOrdUpper,
53
- rsOrdLower,
54
- `${rsDigit}+`,
55
- rsEmoji
56
- ].join('|'), 'g');
57
- /**
58
- * Splits a Unicode `string` into an array of its words.
59
- *
60
- * @private
61
- * @param {string} The string to inspect.
62
- * @returns {Array} Returns the words of `string`.
63
- */
64
- function unicodeWords(string) {
65
- return string.match(reUnicodeWords);
66
- }
67
- exports.default = unicodeWords;
package/bin/lib/index.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mapping = exports.KValue = exports.Event = exports.dNode = exports.dLogger = exports.dTracker = exports.dJoker = exports.dStore = exports.dCdn = exports.dMini = exports.dWeb = exports.dHook = exports.dUtil = void 0;
4
- const gbk_1 = require("./modules/gbk");
5
- const time_1 = require("./modules/time");
6
- const hook_1 = require("./modules/hook");
7
- const math_1 = require("./modules/math");
8
- const util_1 = require("./util");
9
- const list_1 = require("./modules/list");
10
- const mini_1 = require("./modules/mini");
11
- const qs_1 = require("./modules/qs");
12
- const rule_1 = require("./modules/rule");
13
- const regex_1 = require("./modules/regex");
14
- const string_1 = require("./modules/string");
15
- const obj_1 = require("./modules/obj");
16
- const crypto_1 = require("./modules/crypto");
17
- const css_1 = require("./modules/css");
18
- const html_1 = require("./modules/html");
19
- const cdn_1 = require("./modules/cdn");
20
- const convert_1 = require("./modules/convert");
21
- const http_1 = require("./modules/http");
22
- const logger_1 = require("./modules/logger");
23
- const fetch_1 = require("./modules/fetch");
24
- const icon_1 = require("./class/icon");
25
- const event_1 = require("./class/event");
26
- exports.Event = event_1.default;
27
- const store_1 = require("./class/store");
28
- const persist_1 = require("./class/persist");
29
- const watermark_1 = require("./class/watermark");
30
- const joker_1 = require("./class/joker");
31
- const tracker_1 = require("./class/tracker");
32
- const rsa_1 = require("./modules/rsa");
33
- const node_1 = require("./modules/node");
34
- const browser_1 = require("./modules/browser");
35
- const kvalue_1 = require("./class/kvalue");
36
- exports.KValue = kvalue_1.default;
37
- const mapping_1 = require("./class/mapping");
38
- exports.Mapping = mapping_1.default;
39
- const dUtil = {
40
- gbk: gbk_1.default,
41
- math: math_1.default,
42
- list: list_1.default,
43
- string: string_1.default,
44
- time: time_1.default,
45
- obj: obj_1.default,
46
- rule: rule_1.default,
47
- regex: regex_1.default,
48
- ...convert_1.default,
49
- ...crypto_1.default,
50
- ...util_1.default,
51
- Event: event_1.default,
52
- };
53
- exports.dUtil = dUtil;
54
- const singleton = util_1.default.singleton;
55
- const dHook = {
56
- ...convert_1.default,
57
- ...crypto_1.default,
58
- ...hook_1.default,
59
- ...string_1.default,
60
- ...math_1.default,
61
- qs: qs_1.default,
62
- singleton,
63
- };
64
- exports.dHook = dHook;
65
- const dMini = { mini: mini_1.default, css: css_1.default, qs: qs_1.default, icon: icon_1.default, html: html_1.default };
66
- exports.dMini = dMini;
67
- const dCdn = { cdn: cdn_1.default, watermark: watermark_1.default };
68
- exports.dCdn = dCdn;
69
- const dStore = { Store: store_1.default, storeRef: store_1.storeRef, Persist: persist_1.default, persistConfig: persist_1.persistConfig };
70
- exports.dStore = dStore;
71
- const dJoker = joker_1.default;
72
- exports.dJoker = dJoker;
73
- const dTracker = tracker_1.default;
74
- exports.dTracker = dTracker;
75
- const dLogger = logger_1.default;
76
- exports.dLogger = dLogger;
77
- const dWeb = { fetch: fetch_1.default, Http: http_1.default, css: css_1.default, qs: qs_1.default, icon: icon_1.default, html: html_1.default, rsa: rsa_1.default, ...browser_1.default };
78
- exports.dWeb = dWeb;
79
- const dNode = { ...node_1.default };
80
- exports.dNode = dNode;
81
- exports.default = {
82
- gbk: gbk_1.default,
83
- time: time_1.default,
84
- hook: hook_1.default,
85
- math: math_1.default,
86
- util: util_1.default,
87
- list: list_1.default,
88
- string: string_1.default,
89
- obj: obj_1.default,
90
- crypto: crypto_1.default,
91
- mini: mini_1.default,
92
- qs: qs_1.default,
93
- css: css_1.default,
94
- cdn: cdn_1.default,
95
- html: html_1.default,
96
- icon: icon_1.default,
97
- rule: rule_1.default,
98
- regex: regex_1.default,
99
- convert: convert_1.default,
100
- KValue: kvalue_1.default,
101
- Mapping: mapping_1.default,
102
- Event: event_1.default,
103
- Http: http_1.default,
104
- Store: store_1.default,
105
- storeRef: store_1.storeRef,
106
- Persist: persist_1.default,
107
- persistConfig: persist_1.persistConfig,
108
- watermark: watermark_1.default,
109
- joker: joker_1.default,
110
- tracker: tracker_1.default,
111
- logger: logger_1.default,
112
- fetch: fetch_1.default,
113
- rsa: rsa_1.default,
114
- };
@@ -1,124 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const convert_1 = require("../convert");
4
- class Ecdh {
5
- publicKey = '';
6
- privateKey = '';
7
- iv = '';
8
- __privateCryptoKey;
9
- __sharedSecret;
10
- __curve;
11
- __keyFormat;
12
- __subtle;
13
- constructor(curve = 'P-256', keyFormat = 'raw') {
14
- this.__curve = curve;
15
- this.__keyFormat = keyFormat || 'raw';
16
- if (typeof window !== 'undefined')
17
- this.__subtle = window.crypto.subtle;
18
- else
19
- this.__subtle = {};
20
- }
21
- async generateKeys() {
22
- const keyPair = await this.__subtle.generateKey({
23
- name: 'ECDH',
24
- namedCurve: this.__curve, // 使用 P-256 椭圆曲线
25
- }, true, // 可以导出
26
- ['deriveKey', 'deriveBits']);
27
- this.__privateCryptoKey = keyPair.privateKey;
28
- this.publicKey = await this.exportKey(keyPair.publicKey);
29
- this.privateKey = await this.exportKey(keyPair.privateKey, 'pkcs8');
30
- return this;
31
- }
32
- async exportKey(cryptoKey, keyFormat = 'raw') {
33
- const exportKey = await this.__subtle.exportKey(keyFormat || this.__keyFormat, cryptoKey);
34
- return convert_1.default.ab2str(exportKey, true);
35
- }
36
- async importKey(keyBase64, keyFormat = 'raw', usages = []) {
37
- const bytes = convert_1.default.base64ToBytes(keyBase64);
38
- const publicKey = await this.__subtle.importKey(keyFormat || this.__keyFormat || 'raw', bytes, {
39
- name: 'ECDH',
40
- namedCurve: this.__curve,
41
- }, true, usages);
42
- return publicKey;
43
- }
44
- async setPrivateKey(privateBase64) {
45
- if (!privateBase64)
46
- return false;
47
- const cryptoKey = await this.importKey(privateBase64, 'pkcs8', ['deriveKey', 'deriveBits']);
48
- this.privateKey = await this.exportKey(cryptoKey, 'pkcs8');
49
- this.__privateCryptoKey = cryptoKey;
50
- return true;
51
- }
52
- async deriveSharedSecret(publicKeyBase64, iv) {
53
- if (!this.__privateCryptoKey)
54
- return false;
55
- const cryptoKey = await this.importKey(publicKeyBase64);
56
- const sharedSecret = await this.__subtle.deriveKey({
57
- name: 'ECDH',
58
- public: cryptoKey, // 对方的公钥
59
- }, this.__privateCryptoKey, // 自己的私钥
60
- { name: 'AES-GCM', length: 256 }, // 派生出的共享密钥用于 AES 加密
61
- true, // 可以导出
62
- ['encrypt', 'decrypt'] // 用于加密和解密
63
- );
64
- this.__sharedSecret = sharedSecret;
65
- this.iv = iv || '';
66
- return true;
67
- }
68
- async encode(data, iv) {
69
- if (!this.__sharedSecret)
70
- return '';
71
- const _iv = iv || this.iv;
72
- if (!_iv)
73
- return '';
74
- const ivBytes = convert_1.default.base64ToBytes(_iv);
75
- const dataBytes = convert_1.default.textEncode(data);
76
- const encrypted = await this.__subtle.encrypt({
77
- name: 'AES-GCM',
78
- iv: ivBytes,
79
- }, this.__sharedSecret, dataBytes);
80
- return convert_1.default.ab2str(encrypted, true);
81
- }
82
- async encodeiv(data, iv) {
83
- if (!this.__sharedSecret)
84
- return '';
85
- const _iv = iv || this.iv;
86
- const ivBytes = _iv ? convert_1.default.base64ToBytes(_iv) : convert_1.default.getRandomBytes(12);
87
- const dataBytes = convert_1.default.textEncode(data);
88
- const encrypted = await this.__subtle.encrypt({
89
- name: 'AES-GCM',
90
- iv: ivBytes,
91
- }, this.__sharedSecret, dataBytes);
92
- const bytes = convert_1.default.concatBytes(new Uint8Array(encrypted), ivBytes);
93
- return convert_1.default.bytesToBase64(bytes);
94
- }
95
- async decode(encrypted, iv) {
96
- if (!this.__sharedSecret)
97
- return '';
98
- const _iv = iv || this.iv;
99
- if (!_iv)
100
- return '';
101
- const dataBytes = convert_1.default.base64ToBytes(encrypted);
102
- const ivBytes = convert_1.default.base64ToBytes(_iv);
103
- const decrypted = await this.__subtle.decrypt({
104
- name: 'AES-GCM',
105
- iv: ivBytes,
106
- }, this.__sharedSecret, dataBytes);
107
- return convert_1.default.textDecode(decrypted);
108
- }
109
- async decodeiv(encrypted) {
110
- if (!this.__sharedSecret)
111
- return '';
112
- const bytes = convert_1.default.base64ToBytes(encrypted);
113
- if (bytes.length < 12)
114
- return '';
115
- const ivBytes = bytes.slice(bytes.length - 12);
116
- const dataBytes = bytes.slice(0, bytes.length - 12);
117
- const decrypted = await this.__subtle.decrypt({
118
- name: 'AES-GCM',
119
- iv: ivBytes,
120
- }, this.__sharedSecret, dataBytes);
121
- return convert_1.default.textDecode(decrypted);
122
- }
123
- }
124
- exports.default = Ecdh;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ecdh_1 = require("./ecdh");
4
- exports.default = { Ecdh: ecdh_1.default };
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const qs_1 = require("./qs");
4
- const list_1 = require("./list");
5
- const base64_1 = require("./convert/base64");
6
- const ossImage = (url, options = {}) => {
7
- if (!url)
8
- return url;
9
- const _map = qs_1.default.parseUrl(url);
10
- const _url = _map.url;
11
- if (options.domain) {
12
- if (!url.startsWith("http"))
13
- return url;
14
- const domains = list_1.default.toList(options.domain || "");
15
- const host = url.match(/^http[s]?:\/\/([\w.]+)[\w\W]+/)[1] || "";
16
- // const host = url.match(/((?<=http:\/\/)|(?<=https:\/\/)).+?(?=\/)/g)![0]||"";
17
- if (!host || !domains.includes(host))
18
- return url;
19
- }
20
- const arr = [];
21
- if (options.webp && !_url.endsWith(".gif")) {
22
- arr.push("format,webp");
23
- }
24
- if (options.resize) {
25
- arr.push(`resize,s_${options.resize}`);
26
- }
27
- if (options.interlace) {
28
- arr.push(`interlace,1`);
29
- if (arr.every(e => !e.startsWith("format")) && !_url.endsWith(".gif") && !_url.endsWith(".jpg")) {
30
- arr.push("format,jpg");
31
- }
32
- }
33
- if (arr.length <= 0)
34
- return url;
35
- return `${_url}?x-oss-process=image/${arr.join("/")}`;
36
- };
37
- /**
38
- * 视频截帧
39
- * @param url
40
- * @param options t: 截图时间ms
41
- * @returns
42
- */
43
- const ossSnapshot = (url, options = {}) => {
44
- if (!url)
45
- return url;
46
- const _map = qs_1.default.parseUrl(url);
47
- const _url = _map.url;
48
- const arr = ["snapshot"];
49
- const { m = "fast", f = "jpg" } = options;
50
- (options.t || options.t === 0) && arr.push(`t_${options.t}`);
51
- options.w && arr.push(`w_${options.w}`);
52
- options.h && arr.push(`h_${options.h}`);
53
- m && arr.push(`m_${m}`);
54
- f && arr.push(`f_${f}`);
55
- options.ar && arr.push(`ar_${options.ar}`);
56
- return `${_url}?x-oss-process=video/${arr.join(",")}`;
57
- };
58
- const ossBase64 = (input) => {
59
- // base64编码并部分替换
60
- return base64_1.default.toBase64(input).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
61
- };
62
- exports.default = { ossImage, ossSnapshot, ossBase64 };
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const is_1 = require("../../util/is");
4
- const bytes2str = (bytes) => {
5
- if (!bytes || !is_1.default.isArrayLike(bytes))
6
- return '';
7
- const str = bytes.reduce((str, byte) => str + String.fromCharCode(byte), '');
8
- return str;
9
- };
10
- const str2bytes = (str = '') => {
11
- const content = str;
12
- const bufView = new Uint8Array(content.length);
13
- for (let i = 0, strLen = content.length; i < strLen; i++) {
14
- bufView[i] = content.charCodeAt(i);
15
- }
16
- return bufView;
17
- };
18
- const str2hex = (str) => {
19
- let hexString = '';
20
- for (let i = 0; i < str.length; i++) {
21
- hexString += str.charCodeAt(i).toString(16).padStart(2, '0');
22
- }
23
- return hexString;
24
- };
25
- const hex2str = (hexstr) => {
26
- let str = '';
27
- for (let i = 0; i < hexstr.length; i += 2) {
28
- str += String.fromCharCode(parseInt(hexstr.substr(i, 2), 16));
29
- }
30
- return str;
31
- };
32
- const concatBytes = (...args) => {
33
- // 计算所有 Uint8Array 的总长度
34
- const totalLength = args.reduce((sum, arr) => sum + arr.length, 0);
35
- // 创建一个新的 Uint8Array
36
- const combined = new Uint8Array(totalLength);
37
- // 当前写入的位置
38
- let offset = 0;
39
- // 将每个 Uint8Array 复制到新的数组中
40
- for (const arr of args) {
41
- combined.set(arr, offset);
42
- offset += arr.length;
43
- }
44
- return combined;
45
- };
46
- const uint32ToBytes = (uint32) => {
47
- const bytes = new Uint8Array(8);
48
- bytes[0] = (uint32[0] >>> 24) & 0xff;
49
- bytes[1] = (uint32[0] >>> 16) & 0xff;
50
- bytes[2] = (uint32[0] >>> 8) & 0xff;
51
- bytes[3] = uint32[0] & 0xff;
52
- bytes[4] = (uint32[1] >>> 24) & 0xff;
53
- bytes[5] = (uint32[1] >>> 16) & 0xff;
54
- bytes[6] = (uint32[1] >>> 8) & 0xff;
55
- bytes[7] = uint32[1] & 0xff;
56
- return bytes;
57
- };
58
- const bytesToUint32 = (bytes) => {
59
- const unit32 = new Uint32Array(2);
60
- unit32[0] = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
61
- unit32[1] = (bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7];
62
- return unit32;
63
- };
64
- const toUint32 = (str) => {
65
- const length = Math.ceil(str.length / 4);
66
- const uint32Array = new Uint32Array(length);
67
- for (let i = 0; i < length; i++) {
68
- uint32Array[i] =
69
- (str.charCodeAt(i * 4) << 24) |
70
- (str.charCodeAt(i * 4 + 1) << 16) |
71
- (str.charCodeAt(i * 4 + 2) << 8) |
72
- str.charCodeAt(i * 4 + 3);
73
- }
74
- return uint32Array;
75
- };
76
- const fromUint32 = (uint32) => {
77
- let result = '';
78
- for (let i = 0; i < uint32.length; i++) {
79
- result += String.fromCharCode((uint32[i] >>> 24) & 0xff, // 提取最高 8 位
80
- (uint32[i] >>> 16) & 0xff, // 提取次高 8 位
81
- (uint32[i] >>> 8) & 0xff, // 提取次低 8 位
82
- uint32[i] & 0xff // 提取最低 8 位
83
- );
84
- }
85
- // 去掉可能因字符串长度不是4的倍数导致的填充字符
86
- return result.replace(/\0+$/, '');
87
- };
88
- const hex2bytes = (hex) => {
89
- let bytes = new Uint8Array(hex.length / 2);
90
- for (let i = 0; i < bytes.length; i++) {
91
- bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
92
- }
93
- return bytes;
94
- };
95
- const bytes2hex = (bytes) => {
96
- return Array.from(bytes)
97
- .map((b) => b.toString(16).padStart(2, '0'))
98
- .join('');
99
- };
100
- function flatten(data, recursive = false, list = []) {
101
- for (let i = 0; i < data.length; i += 1) {
102
- const record = data[i];
103
- if (recursive && Array.isArray(record)) {
104
- flatten(record, recursive, list);
105
- }
106
- else {
107
- list.push(record);
108
- }
109
- }
110
- return list;
111
- }
112
- exports.default = {
113
- bytes2str,
114
- str2bytes,
115
- str2hex,
116
- hex2str,
117
- concatBytes,
118
- uint32ToBytes,
119
- bytesToUint32,
120
- hex2bytes,
121
- bytes2hex,
122
- toUint32,
123
- fromUint32,
124
- flatten,
125
- };
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utf8_1 = require("./utf8");
4
- const is_1 = require("../../util/is");
5
- const BaseKey = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
6
- const bytesToBase64 = (bytes) => {
7
- let output = '';
8
- let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
9
- let i = 0;
10
- if (!bytes || !is_1.default.isArrayLike(bytes) || !is_1.default.isUint8Array(bytes))
11
- return '';
12
- while (i < bytes.length) {
13
- chr1 = bytes[i++];
14
- chr2 = bytes[i++];
15
- chr3 = bytes[i++];
16
- enc1 = chr1 >> 2;
17
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
18
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
19
- enc4 = chr3 & 63;
20
- if (isNaN(chr2)) {
21
- enc3 = enc4 = 64;
22
- }
23
- else if (isNaN(chr3)) {
24
- enc4 = 64;
25
- }
26
- output =
27
- output +
28
- BaseKey.charAt(enc1) +
29
- BaseKey.charAt(enc2) +
30
- BaseKey.charAt(enc3) +
31
- BaseKey.charAt(enc4);
32
- }
33
- return output;
34
- };
35
- const toBase64 = (input = "") => {
36
- let output = '';
37
- let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
38
- let i = 0;
39
- input = utf8_1.default.toUtf8(input);
40
- while (i < input.length) {
41
- chr1 = input.charCodeAt(i++);
42
- chr2 = input.charCodeAt(i++);
43
- chr3 = input.charCodeAt(i++);
44
- enc1 = chr1 >> 2;
45
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
46
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
47
- enc4 = chr3 & 63;
48
- if (isNaN(chr2)) {
49
- enc3 = enc4 = 64;
50
- }
51
- else if (isNaN(chr3)) {
52
- enc4 = 64;
53
- }
54
- output =
55
- output +
56
- BaseKey.charAt(enc1) +
57
- BaseKey.charAt(enc2) +
58
- BaseKey.charAt(enc3) +
59
- BaseKey.charAt(enc4);
60
- }
61
- return output;
62
- };
63
- const base64ToBytes = (input = "") => {
64
- let output = [];
65
- let chr1, chr2, chr3;
66
- let enc1, enc2, enc3, enc4;
67
- let i = 0;
68
- // Remove any characters that are not valid Base64
69
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
70
- while (i < input.length) {
71
- enc1 = BaseKey.indexOf(input.charAt(i++));
72
- enc2 = BaseKey.indexOf(input.charAt(i++));
73
- enc3 = BaseKey.indexOf(input.charAt(i++));
74
- enc4 = BaseKey.indexOf(input.charAt(i++));
75
- chr1 = (enc1 << 2) | (enc2 >> 4);
76
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
77
- chr3 = ((enc3 & 3) << 6) | enc4;
78
- output.push(chr1);
79
- if (enc3 != 64) {
80
- output.push(chr2);
81
- }
82
- if (enc4 != 64) {
83
- output.push(chr3);
84
- }
85
- }
86
- // Convert the array to Uint8Array and return
87
- return new Uint8Array(output);
88
- };
89
- const fromBase64 = (input = "") => {
90
- let output = '';
91
- let chr1, chr2, chr3;
92
- let enc1, enc2, enc3, enc4;
93
- let i = 0;
94
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
95
- while (i < input.length) {
96
- enc1 = BaseKey.indexOf(input.charAt(i++));
97
- enc2 = BaseKey.indexOf(input.charAt(i++));
98
- enc3 = BaseKey.indexOf(input.charAt(i++));
99
- enc4 = BaseKey.indexOf(input.charAt(i++));
100
- chr1 = (enc1 << 2) | (enc2 >> 4);
101
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
102
- chr3 = ((enc3 & 3) << 6) | enc4;
103
- output = output + String.fromCharCode(chr1);
104
- if (enc3 != 64) {
105
- output = output + String.fromCharCode(chr2);
106
- }
107
- if (enc4 != 64) {
108
- output = output + String.fromCharCode(chr3);
109
- }
110
- }
111
- output = utf8_1.default.fromUtf8(output);
112
- return output;
113
- };
114
- exports.default = { toBase64, fromBase64, bytesToBase64, base64ToBytes };