ccxt 4.2.60 → 4.2.61
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 +103 -102
- package/build.sh +1 -1
- package/dist/ccxt.browser.js +107943 -100121
- package/dist/ccxt.browser.min.js +7 -7
- package/dist/cjs/ccxt.js +4 -1
- package/dist/cjs/src/abstract/hyperliquid.js +9 -0
- package/dist/cjs/src/base/Exchange.js +22 -1
- package/dist/cjs/src/base/functions/encode.js +5 -0
- package/dist/cjs/src/base/functions.js +1 -0
- package/dist/cjs/src/bitfinex2.js +1 -1
- package/dist/cjs/src/coinbase.js +108 -103
- package/dist/cjs/src/coinex.js +61 -1
- package/dist/cjs/src/hyperliquid.js +2035 -0
- package/dist/cjs/src/kraken.js +8 -2
- package/dist/cjs/src/krakenfutures.js +28 -0
- package/dist/cjs/src/kucoinfutures.js +2 -2
- package/dist/cjs/src/okx.js +1 -1
- package/dist/cjs/src/phemex.js +2 -2
- package/dist/cjs/src/pro/bingx.js +1 -0
- package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
- package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
- package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
- package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
- package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
- package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
- package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
- package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
- package/dist/cjs/src/tokocrypto.js +22 -2
- package/dist/cjs/src/wazirx.js +308 -3
- package/js/ccxt.d.ts +5 -2
- package/js/ccxt.js +4 -2
- package/js/src/abstract/coinbase.d.ts +3 -3
- package/js/src/abstract/hyperliquid.d.ts +9 -0
- package/js/src/abstract/hyperliquid.js +11 -0
- package/js/src/base/Exchange.d.ts +4 -0
- package/js/src/base/Exchange.js +13 -1
- package/js/src/base/functions/encode.d.ts +2 -1
- package/js/src/base/functions/encode.js +5 -1
- package/js/src/bitfinex2.js +1 -1
- package/js/src/coinbase.js +108 -103
- package/js/src/coinex.d.ts +3 -1
- package/js/src/coinex.js +61 -1
- package/js/src/hyperliquid.d.ts +83 -0
- package/js/src/hyperliquid.js +2036 -0
- package/js/src/kraken.js +8 -2
- package/js/src/krakenfutures.d.ts +2 -1
- package/js/src/krakenfutures.js +28 -0
- package/js/src/kucoinfutures.js +2 -2
- package/js/src/okx.js +1 -1
- package/js/src/phemex.js +2 -2
- package/js/src/pro/bingx.js +1 -0
- package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
- package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
- package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
- package/js/src/static_dependencies/ethers/address/address.js +162 -0
- package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
- package/js/src/static_dependencies/ethers/address/checks.js +119 -0
- package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
- package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
- package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
- package/js/src/static_dependencies/ethers/address/index.js +24 -0
- package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
- package/js/src/static_dependencies/ethers/bytes32.js +45 -0
- package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
- package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
- package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/address.js +34 -0
- package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
- package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
- package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
- package/js/src/static_dependencies/ethers/coders/array.js +162 -0
- package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
- package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
- package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
- package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
- package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
- package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
- package/js/src/static_dependencies/ethers/coders/null.js +29 -0
- package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
- package/js/src/static_dependencies/ethers/coders/number.js +48 -0
- package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/string.js +26 -0
- package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
- package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
- package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
- package/js/src/static_dependencies/ethers/fragments.js +1252 -0
- package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
- package/js/src/static_dependencies/ethers/hash/index.js +15 -0
- package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
- package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
- package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
- package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
- package/js/src/static_dependencies/ethers/index.d.ts +19 -0
- package/js/src/static_dependencies/ethers/index.js +22 -0
- package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
- package/js/src/static_dependencies/ethers/interface.js +990 -0
- package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
- package/js/src/static_dependencies/ethers/typed.js +608 -0
- package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
- package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
- package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
- package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
- package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
- package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
- package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
- package/js/src/static_dependencies/ethers/utils/data.js +175 -0
- package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
- package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
- package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
- package/js/src/static_dependencies/ethers/utils/events.js +52 -0
- package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
- package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
- package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
- package/js/src/static_dependencies/ethers/utils/index.js +38 -0
- package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
- package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
- package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
- package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
- package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
- package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
- package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
- package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
- package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
- package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
- package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
- package/js/src/static_dependencies/ethers/utils/units.js +88 -0
- package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
- package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
- package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
- package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
- package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
- package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
- package/js/src/tokocrypto.js +22 -2
- package/js/src/wazirx.d.ts +12 -1
- package/js/src/wazirx.js +308 -3
- package/package.json +1 -1
- package/skip-tests.json +18 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { BytesLike } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The stanard normalization forms.
|
|
4
|
+
*/
|
|
5
|
+
export declare type UnicodeNormalizationForm = "NFC" | "NFD" | "NFKC" | "NFKD";
|
|
6
|
+
/**
|
|
7
|
+
* When using the UTF-8 error API the following errors can be intercepted
|
|
8
|
+
* and processed as the %%reason%% passed to the [[Utf8ErrorFunc]].
|
|
9
|
+
*
|
|
10
|
+
* **``"UNEXPECTED_CONTINUE"``** - a continuation byte was present where there
|
|
11
|
+
* was nothing to continue.
|
|
12
|
+
*
|
|
13
|
+
* **``"BAD_PREFIX"``** - an invalid (non-continuation) byte to start a
|
|
14
|
+
* UTF-8 codepoint was found.
|
|
15
|
+
*
|
|
16
|
+
* **``"OVERRUN"``** - the string is too short to process the expected
|
|
17
|
+
* codepoint length.
|
|
18
|
+
*
|
|
19
|
+
* **``"MISSING_CONTINUE"``** - a missing continuation byte was expected but
|
|
20
|
+
* not found. The %%offset%% indicates the index the continuation byte
|
|
21
|
+
* was expected at.
|
|
22
|
+
*
|
|
23
|
+
* **``"OUT_OF_RANGE"``** - the computed code point is outside the range
|
|
24
|
+
* for UTF-8. The %%badCodepoint%% indicates the computed codepoint, which was
|
|
25
|
+
* outside the valid UTF-8 range.
|
|
26
|
+
*
|
|
27
|
+
* **``"UTF16_SURROGATE"``** - the UTF-8 strings contained a UTF-16 surrogate
|
|
28
|
+
* pair. The %%badCodepoint%% is the computed codepoint, which was inside the
|
|
29
|
+
* UTF-16 surrogate range.
|
|
30
|
+
*
|
|
31
|
+
* **``"OVERLONG"``** - the string is an overlong representation. The
|
|
32
|
+
* %%badCodepoint%% indicates the computed codepoint, which has already
|
|
33
|
+
* been bounds checked.
|
|
34
|
+
*
|
|
35
|
+
*
|
|
36
|
+
* @returns string
|
|
37
|
+
*/
|
|
38
|
+
export declare type Utf8ErrorReason = "UNEXPECTED_CONTINUE" | "BAD_PREFIX" | "OVERRUN" | "MISSING_CONTINUE" | "OUT_OF_RANGE" | "UTF16_SURROGATE" | "OVERLONG";
|
|
39
|
+
/**
|
|
40
|
+
* A callback that can be used with [[toUtf8String]] to analysis or
|
|
41
|
+
* recovery from invalid UTF-8 data.
|
|
42
|
+
*
|
|
43
|
+
* Parsing UTF-8 data is done through a simple Finite-State Machine (FSM)
|
|
44
|
+
* which calls the ``Utf8ErrorFunc`` if a fault is detected.
|
|
45
|
+
*
|
|
46
|
+
* The %%reason%% indicates where in the FSM execution the fault
|
|
47
|
+
* occurred and the %%offset%% indicates where the input failed.
|
|
48
|
+
*
|
|
49
|
+
* The %%bytes%% represents the raw UTF-8 data that was provided and
|
|
50
|
+
* %%output%% is the current array of UTF-8 code-points, which may
|
|
51
|
+
* be updated by the ``Utf8ErrorFunc``.
|
|
52
|
+
*
|
|
53
|
+
* The value of the %%badCodepoint%% depends on the %%reason%%. See
|
|
54
|
+
* [[Utf8ErrorReason]] for details.
|
|
55
|
+
*
|
|
56
|
+
* The function should return the number of bytes that should be skipped
|
|
57
|
+
* when control resumes to the FSM.
|
|
58
|
+
*/
|
|
59
|
+
export declare type Utf8ErrorFunc = (reason: Utf8ErrorReason, offset: number, bytes: Uint8Array, output: Array<number>, badCodepoint?: number) => number;
|
|
60
|
+
/**
|
|
61
|
+
* A handful of popular, built-in UTF-8 error handling strategies.
|
|
62
|
+
*
|
|
63
|
+
* **``"error"``** - throws on ANY illegal UTF-8 sequence or
|
|
64
|
+
* non-canonical (overlong) codepoints (this is the default)
|
|
65
|
+
*
|
|
66
|
+
* **``"ignore"``** - silently drops any illegal UTF-8 sequence
|
|
67
|
+
* and accepts non-canonical (overlong) codepoints
|
|
68
|
+
*
|
|
69
|
+
* **``"replace"``** - replace any illegal UTF-8 sequence with the
|
|
70
|
+
* UTF-8 replacement character (i.e. ``"\\ufffd"``) and accepts
|
|
71
|
+
* non-canonical (overlong) codepoints
|
|
72
|
+
*
|
|
73
|
+
* @returns: Record<"error" | "ignore" | "replace", Utf8ErrorFunc>
|
|
74
|
+
*/
|
|
75
|
+
export declare const Utf8ErrorFuncs: Readonly<Record<"error" | "ignore" | "replace", Utf8ErrorFunc>>;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the UTF-8 byte representation of %%str%%.
|
|
78
|
+
*
|
|
79
|
+
* If %%form%% is specified, the string is normalized.
|
|
80
|
+
*/
|
|
81
|
+
export declare function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8Array;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the string represented by the UTF-8 data %%bytes%%.
|
|
84
|
+
*
|
|
85
|
+
* When %%onError%% function is specified, it is called on UTF-8
|
|
86
|
+
* errors allowing recovery using the [[Utf8ErrorFunc]] API.
|
|
87
|
+
* (default: [error](Utf8ErrorFuncs))
|
|
88
|
+
*/
|
|
89
|
+
export declare function toUtf8String(bytes: BytesLike, onError?: Utf8ErrorFunc): string;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the UTF-8 code-points for %%str%%.
|
|
92
|
+
*
|
|
93
|
+
* If %%form%% is specified, the string is normalized.
|
|
94
|
+
*/
|
|
95
|
+
export declare function toUtf8CodePoints(str: string, form?: UnicodeNormalizationForm): Array<number>;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// ----------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
|
4
|
+
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
|
5
|
+
// EDIT THE CORRESPONDENT .ts FILE INSTEAD
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Using strings in Ethereum (or any security-basd system) requires
|
|
9
|
+
* additional care. These utilities attempt to mitigate some of the
|
|
10
|
+
* safety issues as well as provide the ability to recover and analyse
|
|
11
|
+
* strings.
|
|
12
|
+
*
|
|
13
|
+
* @_subsection api/utils:Strings and UTF-8 [about-strings]
|
|
14
|
+
*/
|
|
15
|
+
import { getBytes } from "./data.js";
|
|
16
|
+
import { assertArgument, assertNormalize } from "./errors.js";
|
|
17
|
+
function errorFunc(reason, offset, bytes, output, badCodepoint) {
|
|
18
|
+
assertArgument(false, `invalid codepoint at offset ${offset}; ${reason}`, "bytes", bytes);
|
|
19
|
+
}
|
|
20
|
+
function ignoreFunc(reason, offset, bytes, output, badCodepoint) {
|
|
21
|
+
// If there is an invalid prefix (including stray continuation), skip any additional continuation bytes
|
|
22
|
+
if (reason === "BAD_PREFIX" || reason === "UNEXPECTED_CONTINUE") {
|
|
23
|
+
let i = 0;
|
|
24
|
+
for (let o = offset + 1; o < bytes.length; o++) {
|
|
25
|
+
if (bytes[o] >> 6 !== 0x02) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
i++;
|
|
29
|
+
}
|
|
30
|
+
return i;
|
|
31
|
+
}
|
|
32
|
+
// This byte runs us past the end of the string, so just jump to the end
|
|
33
|
+
// (but the first byte was read already read and therefore skipped)
|
|
34
|
+
if (reason === "OVERRUN") {
|
|
35
|
+
return bytes.length - offset - 1;
|
|
36
|
+
}
|
|
37
|
+
// Nothing to skip
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
function replaceFunc(reason, offset, bytes, output, badCodepoint) {
|
|
41
|
+
// Overlong representations are otherwise "valid" code points; just non-deistingtished
|
|
42
|
+
if (reason === "OVERLONG") {
|
|
43
|
+
assertArgument(typeof (badCodepoint) === "number", "invalid bad code point for replacement", "badCodepoint", badCodepoint);
|
|
44
|
+
output.push(badCodepoint);
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
// Put the replacement character into the output
|
|
48
|
+
output.push(0xfffd);
|
|
49
|
+
// Otherwise, process as if ignoring errors
|
|
50
|
+
return ignoreFunc(reason, offset, bytes, output, badCodepoint);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A handful of popular, built-in UTF-8 error handling strategies.
|
|
54
|
+
*
|
|
55
|
+
* **``"error"``** - throws on ANY illegal UTF-8 sequence or
|
|
56
|
+
* non-canonical (overlong) codepoints (this is the default)
|
|
57
|
+
*
|
|
58
|
+
* **``"ignore"``** - silently drops any illegal UTF-8 sequence
|
|
59
|
+
* and accepts non-canonical (overlong) codepoints
|
|
60
|
+
*
|
|
61
|
+
* **``"replace"``** - replace any illegal UTF-8 sequence with the
|
|
62
|
+
* UTF-8 replacement character (i.e. ``"\\ufffd"``) and accepts
|
|
63
|
+
* non-canonical (overlong) codepoints
|
|
64
|
+
*
|
|
65
|
+
* @returns: Record<"error" | "ignore" | "replace", Utf8ErrorFunc>
|
|
66
|
+
*/
|
|
67
|
+
export const Utf8ErrorFuncs = Object.freeze({
|
|
68
|
+
error: errorFunc,
|
|
69
|
+
ignore: ignoreFunc,
|
|
70
|
+
replace: replaceFunc
|
|
71
|
+
});
|
|
72
|
+
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
|
73
|
+
function getUtf8CodePoints(_bytes, onError) {
|
|
74
|
+
if (onError == null) {
|
|
75
|
+
onError = Utf8ErrorFuncs.error;
|
|
76
|
+
}
|
|
77
|
+
const bytes = getBytes(_bytes, "bytes");
|
|
78
|
+
const result = [];
|
|
79
|
+
let i = 0;
|
|
80
|
+
// Invalid bytes are ignored
|
|
81
|
+
while (i < bytes.length) {
|
|
82
|
+
const c = bytes[i++];
|
|
83
|
+
// 0xxx xxxx
|
|
84
|
+
if (c >> 7 === 0) {
|
|
85
|
+
result.push(c);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
// Multibyte; how many bytes left for this character?
|
|
89
|
+
let extraLength = null;
|
|
90
|
+
let overlongMask = null;
|
|
91
|
+
// 110x xxxx 10xx xxxx
|
|
92
|
+
if ((c & 0xe0) === 0xc0) {
|
|
93
|
+
extraLength = 1;
|
|
94
|
+
overlongMask = 0x7f;
|
|
95
|
+
// 1110 xxxx 10xx xxxx 10xx xxxx
|
|
96
|
+
}
|
|
97
|
+
else if ((c & 0xf0) === 0xe0) {
|
|
98
|
+
extraLength = 2;
|
|
99
|
+
overlongMask = 0x7ff;
|
|
100
|
+
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
|
|
101
|
+
}
|
|
102
|
+
else if ((c & 0xf8) === 0xf0) {
|
|
103
|
+
extraLength = 3;
|
|
104
|
+
overlongMask = 0xffff;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if ((c & 0xc0) === 0x80) {
|
|
108
|
+
i += onError("UNEXPECTED_CONTINUE", i - 1, bytes, result);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
i += onError("BAD_PREFIX", i - 1, bytes, result);
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
// Do we have enough bytes in our data?
|
|
116
|
+
if (i - 1 + extraLength >= bytes.length) {
|
|
117
|
+
i += onError("OVERRUN", i - 1, bytes, result);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
// Remove the length prefix from the char
|
|
121
|
+
let res = c & ((1 << (8 - extraLength - 1)) - 1);
|
|
122
|
+
for (let j = 0; j < extraLength; j++) {
|
|
123
|
+
let nextChar = bytes[i];
|
|
124
|
+
// Invalid continuation byte
|
|
125
|
+
if ((nextChar & 0xc0) != 0x80) {
|
|
126
|
+
i += onError("MISSING_CONTINUE", i, bytes, result);
|
|
127
|
+
res = null;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
;
|
|
131
|
+
res = (res << 6) | (nextChar & 0x3f);
|
|
132
|
+
i++;
|
|
133
|
+
}
|
|
134
|
+
// See above loop for invalid continuation byte
|
|
135
|
+
if (res === null) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
// Maximum code point
|
|
139
|
+
if (res > 0x10ffff) {
|
|
140
|
+
i += onError("OUT_OF_RANGE", i - 1 - extraLength, bytes, result, res);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
// Reserved for UTF-16 surrogate halves
|
|
144
|
+
if (res >= 0xd800 && res <= 0xdfff) {
|
|
145
|
+
i += onError("UTF16_SURROGATE", i - 1 - extraLength, bytes, result, res);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
// Check for overlong sequences (more bytes than needed)
|
|
149
|
+
if (res <= overlongMask) {
|
|
150
|
+
i += onError("OVERLONG", i - 1 - extraLength, bytes, result, res);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
result.push(res);
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
|
|
158
|
+
/**
|
|
159
|
+
* Returns the UTF-8 byte representation of %%str%%.
|
|
160
|
+
*
|
|
161
|
+
* If %%form%% is specified, the string is normalized.
|
|
162
|
+
*/
|
|
163
|
+
export function toUtf8Bytes(str, form) {
|
|
164
|
+
if (form != null) {
|
|
165
|
+
assertNormalize(form);
|
|
166
|
+
str = str.normalize(form);
|
|
167
|
+
}
|
|
168
|
+
let result = [];
|
|
169
|
+
for (let i = 0; i < str.length; i++) {
|
|
170
|
+
const c = str.charCodeAt(i);
|
|
171
|
+
if (c < 0x80) {
|
|
172
|
+
result.push(c);
|
|
173
|
+
}
|
|
174
|
+
else if (c < 0x800) {
|
|
175
|
+
result.push((c >> 6) | 0xc0);
|
|
176
|
+
result.push((c & 0x3f) | 0x80);
|
|
177
|
+
}
|
|
178
|
+
else if ((c & 0xfc00) == 0xd800) {
|
|
179
|
+
i++;
|
|
180
|
+
const c2 = str.charCodeAt(i);
|
|
181
|
+
assertArgument(i < str.length && ((c2 & 0xfc00) === 0xdc00), "invalid surrogate pair", "str", str);
|
|
182
|
+
// Surrogate Pair
|
|
183
|
+
const pair = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff);
|
|
184
|
+
result.push((pair >> 18) | 0xf0);
|
|
185
|
+
result.push(((pair >> 12) & 0x3f) | 0x80);
|
|
186
|
+
result.push(((pair >> 6) & 0x3f) | 0x80);
|
|
187
|
+
result.push((pair & 0x3f) | 0x80);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
result.push((c >> 12) | 0xe0);
|
|
191
|
+
result.push(((c >> 6) & 0x3f) | 0x80);
|
|
192
|
+
result.push((c & 0x3f) | 0x80);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return new Uint8Array(result);
|
|
196
|
+
}
|
|
197
|
+
;
|
|
198
|
+
//export
|
|
199
|
+
function _toUtf8String(codePoints) {
|
|
200
|
+
return codePoints.map((codePoint) => {
|
|
201
|
+
if (codePoint <= 0xffff) {
|
|
202
|
+
return String.fromCharCode(codePoint);
|
|
203
|
+
}
|
|
204
|
+
codePoint -= 0x10000;
|
|
205
|
+
return String.fromCharCode((((codePoint >> 10) & 0x3ff) + 0xd800), ((codePoint & 0x3ff) + 0xdc00));
|
|
206
|
+
}).join("");
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Returns the string represented by the UTF-8 data %%bytes%%.
|
|
210
|
+
*
|
|
211
|
+
* When %%onError%% function is specified, it is called on UTF-8
|
|
212
|
+
* errors allowing recovery using the [[Utf8ErrorFunc]] API.
|
|
213
|
+
* (default: [error](Utf8ErrorFuncs))
|
|
214
|
+
*/
|
|
215
|
+
export function toUtf8String(bytes, onError) {
|
|
216
|
+
return _toUtf8String(getUtf8CodePoints(bytes, onError));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns the UTF-8 code-points for %%str%%.
|
|
220
|
+
*
|
|
221
|
+
* If %%form%% is specified, the string is normalized.
|
|
222
|
+
*/
|
|
223
|
+
export function toUtf8CodePoints(str, form) {
|
|
224
|
+
return getUtf8CodePoints(toUtf8Bytes(str, form));
|
|
225
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// ----------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
|
4
|
+
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
|
5
|
+
// EDIT THE CORRESPONDENT .ts FILE INSTEAD
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Explain UUID and link to RFC here.
|
|
9
|
+
*
|
|
10
|
+
* @_subsection: api/utils:UUID [about-uuid]
|
|
11
|
+
*/
|
|
12
|
+
import { getBytes, hexlify } from "./data.js";
|
|
13
|
+
/**
|
|
14
|
+
* Returns the version 4 [[link-uuid]] for the %%randomBytes%%.
|
|
15
|
+
*
|
|
16
|
+
* @see: https://www.ietf.org/rfc/rfc4122.txt (Section 4.4)
|
|
17
|
+
*/
|
|
18
|
+
export function uuidV4(randomBytes) {
|
|
19
|
+
const bytes = getBytes(randomBytes, "randomBytes");
|
|
20
|
+
// Section: 4.1.3:
|
|
21
|
+
// - time_hi_and_version[12:16] = 0b0100
|
|
22
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
23
|
+
// Section 4.4
|
|
24
|
+
// - clock_seq_hi_and_reserved[6] = 0b0
|
|
25
|
+
// - clock_seq_hi_and_reserved[7] = 0b1
|
|
26
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
27
|
+
const value = hexlify(bytes);
|
|
28
|
+
return [
|
|
29
|
+
value.substring(2, 10),
|
|
30
|
+
value.substring(10, 14),
|
|
31
|
+
value.substring(14, 18),
|
|
32
|
+
value.substring(18, 22),
|
|
33
|
+
value.substring(22, 34),
|
|
34
|
+
].join("-");
|
|
35
|
+
}
|