ccxt 4.3.70 → 4.3.72
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 +6 -5
- package/dist/ccxt.browser.min.js +13 -10
- package/dist/cjs/ccxt.js +6 -1
- package/dist/cjs/src/abstract/paradex.js +9 -0
- package/dist/cjs/src/base/Exchange.js +49 -0
- package/dist/cjs/src/paradex.js +2075 -0
- package/dist/cjs/src/pro/bequant.js +4 -0
- package/dist/cjs/src/pro/paradex.js +365 -0
- package/dist/cjs/src/static_dependencies/noble-curves/abstract/poseidon.js +100 -0
- package/dist/cjs/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -0
- package/dist/cjs/src/static_dependencies/scure-starknet/index.js +284 -0
- package/dist/cjs/src/static_dependencies/starknet/constants.js +60 -0
- package/dist/cjs/src/static_dependencies/starknet/types/calldata.js +26 -0
- package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/abi.js +8 -0
- package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/index.js +13 -0
- package/dist/cjs/src/static_dependencies/starknet/types/lib/index.js +56 -0
- package/dist/cjs/src/static_dependencies/starknet/types/typedData.js +19 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/assert.js +15 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +44 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +122 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +137 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/byteArray.js +61 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/cairo.js +218 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/formatter.js +66 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/index.js +281 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/index.js +33 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +37 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +156 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/requestParser.js +250 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/responseParser.js +215 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/tuple.js +112 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/calldata/validate.js +206 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/encode.js +58 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/hash/classHash.js +57 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/merkle.js +76 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/num.js +92 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/selector.js +48 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/shortString.js +101 -0
- package/dist/cjs/src/static_dependencies/starknet/utils/typedData.js +334 -0
- package/dist/cjs/src/woo.js +4 -2
- package/examples/js/cli.js +8 -4
- package/js/ccxt.d.ts +8 -2
- package/js/ccxt.js +6 -2
- package/js/src/abstract/paradex.d.ts +43 -0
- package/js/src/abstract/paradex.js +11 -0
- package/js/src/base/Exchange.d.ts +7 -0
- package/js/src/base/Exchange.js +45 -0
- package/js/src/base/types.d.ts +10 -10
- package/js/src/paradex.d.ts +76 -0
- package/js/src/paradex.js +2075 -0
- package/js/src/pro/bequant.js +4 -0
- package/js/src/pro/paradex.d.ts +15 -0
- package/js/src/pro/paradex.js +366 -0
- package/js/src/static_dependencies/noble-curves/abstract/weierstrass.d.ts +24 -0
- package/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -1
- package/js/src/static_dependencies/scure-starknet/index.d.ts +79 -0
- package/js/src/static_dependencies/scure-starknet/index.js +323 -0
- package/js/src/static_dependencies/starknet/constants.d.ts +61 -0
- package/js/src/static_dependencies/starknet/constants.js +67 -0
- package/js/src/static_dependencies/starknet/index.d.ts +7 -0
- package/js/src/static_dependencies/starknet/index.js +50 -0
- package/js/src/static_dependencies/starknet/types/cairoEnum.d.ts +2 -0
- package/js/src/static_dependencies/starknet/types/cairoEnum.js +7 -0
- package/js/src/static_dependencies/starknet/types/calldata.d.ts +19 -0
- package/js/src/static_dependencies/starknet/types/calldata.js +28 -0
- package/js/src/static_dependencies/starknet/types/index.d.ts +13 -0
- package/js/src/static_dependencies/starknet/types/index.js +16 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/abi.d.ts +71 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/abi.js +13 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/index.d.ts +24 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/index.js +16 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/legacy.d.ts +33 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/legacy.js +7 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/sierra.d.ts +52 -0
- package/js/src/static_dependencies/starknet/types/lib/contract/sierra.js +7 -0
- package/js/src/static_dependencies/starknet/types/lib/index.d.ts +248 -0
- package/js/src/static_dependencies/starknet/types/lib/index.js +52 -0
- package/js/src/static_dependencies/starknet/types/typedData.d.ts +44 -0
- package/js/src/static_dependencies/starknet/types/typedData.js +19 -0
- package/js/src/static_dependencies/starknet/utils/address.d.ts +53 -0
- package/js/src/static_dependencies/starknet/utils/address.js +89 -0
- package/js/src/static_dependencies/starknet/utils/assert.d.ts +7 -0
- package/js/src/static_dependencies/starknet/utils/assert.js +17 -0
- package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.d.ts +6 -0
- package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +43 -0
- package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.d.ts +72 -0
- package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +117 -0
- package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.d.ts +76 -0
- package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +136 -0
- package/js/src/static_dependencies/starknet/utils/calldata/byteArray.d.ts +32 -0
- package/js/src/static_dependencies/starknet/utils/calldata/byteArray.js +59 -0
- package/js/src/static_dependencies/starknet/utils/calldata/cairo.d.ts +183 -0
- package/js/src/static_dependencies/starknet/utils/calldata/cairo.js +229 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.d.ts +35 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.d.ts +34 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/index.d.ts +3 -0
- package/js/src/static_dependencies/starknet/utils/calldata/enum/index.js +9 -0
- package/js/src/static_dependencies/starknet/utils/calldata/formatter.d.ts +9 -0
- package/js/src/static_dependencies/starknet/utils/calldata/formatter.js +67 -0
- package/js/src/static_dependencies/starknet/utils/calldata/index.d.ts +89 -0
- package/js/src/static_dependencies/starknet/utils/calldata/index.js +280 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/index.d.ts +5 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/index.js +30 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.d.ts +20 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.js +8 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +36 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
- package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
- package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.d.ts +2 -0
- package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +155 -0
- package/js/src/static_dependencies/starknet/utils/calldata/requestParser.d.ts +11 -0
- package/js/src/static_dependencies/starknet/utils/calldata/requestParser.js +248 -0
- package/js/src/static_dependencies/starknet/utils/calldata/responseParser.d.ts +11 -0
- package/js/src/static_dependencies/starknet/utils/calldata/responseParser.js +214 -0
- package/js/src/static_dependencies/starknet/utils/calldata/tuple.d.ts +6 -0
- package/js/src/static_dependencies/starknet/utils/calldata/tuple.js +113 -0
- package/js/src/static_dependencies/starknet/utils/calldata/validate.d.ts +6 -0
- package/js/src/static_dependencies/starknet/utils/calldata/validate.js +208 -0
- package/js/src/static_dependencies/starknet/utils/encode.d.ts +207 -0
- package/js/src/static_dependencies/starknet/utils/encode.js +282 -0
- package/js/src/static_dependencies/starknet/utils/hash/classHash.d.ts +57 -0
- package/js/src/static_dependencies/starknet/utils/hash/classHash.js +224 -0
- package/js/src/static_dependencies/starknet/utils/hash/index.d.ts +6 -0
- package/js/src/static_dependencies/starknet/utils/hash/index.js +13 -0
- package/js/src/static_dependencies/starknet/utils/json.d.ts +24 -0
- package/js/src/static_dependencies/starknet/utils/json.js +43 -0
- package/js/src/static_dependencies/starknet/utils/merkle.d.ts +35 -0
- package/js/src/static_dependencies/starknet/utils/merkle.js +84 -0
- package/js/src/static_dependencies/starknet/utils/num.d.ts +182 -0
- package/js/src/static_dependencies/starknet/utils/num.js +244 -0
- package/js/src/static_dependencies/starknet/utils/selector.d.ts +48 -0
- package/js/src/static_dependencies/starknet/utils/selector.js +85 -0
- package/js/src/static_dependencies/starknet/utils/shortString.d.ts +57 -0
- package/js/src/static_dependencies/starknet/utils/shortString.js +96 -0
- package/js/src/static_dependencies/starknet/utils/starknetId.d.ts +113 -0
- package/js/src/static_dependencies/starknet/utils/starknetId.js +265 -0
- package/js/src/static_dependencies/starknet/utils/typedData.d.ts +54 -0
- package/js/src/static_dependencies/starknet/utils/typedData.js +321 -0
- package/js/src/static_dependencies/starknet/utils/uint256.d.ts +21 -0
- package/js/src/static_dependencies/starknet/utils/uint256.js +32 -0
- package/js/src/static_dependencies/starknet/utils/url.d.ts +29 -0
- package/js/src/static_dependencies/starknet/utils/url.js +70 -0
- package/js/src/woo.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
export declare const IS_BROWSER: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Some functions recreated from https://github.com/pedrouid/enc-utils/blob/master/src/index.ts
|
|
4
|
+
* enc-utils is not a dependency to avoid using `Buffer` which only works in node and not browsers
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convert array buffer to string
|
|
8
|
+
*
|
|
9
|
+
* *[internal usage]*
|
|
10
|
+
*
|
|
11
|
+
* @param {ArrayBuffer} array The ArrayBuffer to convert to string.
|
|
12
|
+
* @returns {string} The converted string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const buffer = new ArrayBuffer(5);
|
|
17
|
+
* const view = new Uint8Array(buffer);
|
|
18
|
+
* [72, 101, 108, 108, 111].forEach((x, idx) => view[idx] = x);
|
|
19
|
+
* const result = encode.arrayBufferToString(buffer);
|
|
20
|
+
* // result = "Hello"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function arrayBufferToString(array: ArrayBuffer): string;
|
|
24
|
+
/**
|
|
25
|
+
* Convert utf8-string to Uint8Array
|
|
26
|
+
*
|
|
27
|
+
* *[internal usage]*
|
|
28
|
+
*
|
|
29
|
+
* @param {string} str The UTF-8 string to convert.
|
|
30
|
+
* @returns {Uint8Array} The encoded Uint8Array.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const myString = 'Hi';
|
|
35
|
+
* const result = encode.utf8ToArray(myString);
|
|
36
|
+
* // result = Uint8Array(2) [ 72, 105 ]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function utf8ToArray(str: string): Uint8Array;
|
|
40
|
+
/**
|
|
41
|
+
* Convert utf8-string to Uint8Array
|
|
42
|
+
*
|
|
43
|
+
* @deprecated equivalent to 'utf8ToArray', alias will be removed
|
|
44
|
+
*/
|
|
45
|
+
export declare function stringToArrayBuffer(str: string): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Convert string to array buffer (browser and node compatible)
|
|
48
|
+
*
|
|
49
|
+
* @param {string} a The Base64 encoded string to convert.
|
|
50
|
+
* @returns {Uint8Array} The decoded Uint8Array.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const base64String = 'SGVsbG8='; // 'Hello' in Base64
|
|
55
|
+
* const result = encode.atobUniversal(base64String);
|
|
56
|
+
* // result = Uint8Array(5) [ 72, 101, 108, 108, 111 ]
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function atobUniversal(a: string): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Convert array buffer to string (browser and node compatible)
|
|
62
|
+
*
|
|
63
|
+
* @param {ArrayBuffer} b The Array buffer.
|
|
64
|
+
* @returns {string} The Base64 encoded string.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const buffer = new Uint8Array([72, 101, 108, 108, 111]); // Array with ASCII values for 'Hello'
|
|
69
|
+
* const result = encode.btoaUniversal(buffer);
|
|
70
|
+
* // result = "SGVsbG8="
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function btoaUniversal(b: ArrayBuffer): string;
|
|
74
|
+
/**
|
|
75
|
+
* Convert array buffer to hex-string
|
|
76
|
+
*
|
|
77
|
+
* @param {Uint8Array} buffer The encoded Uint8Array.
|
|
78
|
+
* @returns {string} The hex-string
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const buffer = new Uint8Array([72, 101, 108, 108, 111]); // Array with ASCII values for 'Hello'
|
|
83
|
+
* const result = encode.buf2hex(buffer);
|
|
84
|
+
* // result = "48656c6c6f"
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function buf2hex(buffer: Uint8Array): string;
|
|
88
|
+
/**
|
|
89
|
+
* Remove hex prefix '0x' from hex-string
|
|
90
|
+
* @param hex hex-string
|
|
91
|
+
* @returns {string} The hex-string
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const hexStringWithPrefix = '0x48656c6c6f';
|
|
96
|
+
* const result = encode.removeHexPrefix(hexStringWithPrefix);
|
|
97
|
+
* // result: "48656c6c6f"
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function removeHexPrefix(hex: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Add hex prefix '0x' to base16-string
|
|
103
|
+
* @param hex base16-string
|
|
104
|
+
* @returns {string} The hex-string
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const plainHexString = '48656c6c6f';
|
|
109
|
+
* const result = encode.addHexPrefix(plainHexString);
|
|
110
|
+
* // result: "0x48656c6c6f"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function addHexPrefix(hex: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Prepend string (default with '0')
|
|
116
|
+
*
|
|
117
|
+
* Pads a string to a certain length with a specific string.
|
|
118
|
+
* The padding can be applied only to the left of the input string.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} str The string to pad.
|
|
121
|
+
* @param {number} length The target length for the padded string.
|
|
122
|
+
* @param {string} [padding='0'] The string to use for padding. Defaults to '0'.
|
|
123
|
+
* @returns {string} The padded string.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const myString = '1A3F';
|
|
128
|
+
* const result = encode.padLeft(myString, 10);
|
|
129
|
+
* // result: '0000001A3F'
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function padLeft(str: string, length: number, padding?: string): string;
|
|
133
|
+
/**
|
|
134
|
+
* Calculate byte length of string
|
|
135
|
+
*
|
|
136
|
+
* *[no internal usage]*
|
|
137
|
+
*
|
|
138
|
+
* Calculates the byte length of a string based on a specified byte size.
|
|
139
|
+
* The function rounds up the byte count to the nearest multiple of the specified byte size.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} str The string whose byte length is to be calculated.
|
|
142
|
+
* @param {number} [byteSize='8'] The size of the byte block to round up to. Defaults to 8.
|
|
143
|
+
* @returns {number} The calculated byte length, rounded to the nearest multiple of byteSize.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const myString = 'Hello';
|
|
148
|
+
* const result = encode.calcByteLength(myString, 4);
|
|
149
|
+
* // result = 8 (rounded up to the nearest multiple of 4)
|
|
150
|
+
*
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function calcByteLength(str: string, byteSize?: number): number;
|
|
154
|
+
/**
|
|
155
|
+
* Prepend '0' to string bytes
|
|
156
|
+
*
|
|
157
|
+
* *[no internal usage]*
|
|
158
|
+
*
|
|
159
|
+
*
|
|
160
|
+
* * Prepends padding to the left of a string to ensure it matches a specific byte length.
|
|
161
|
+
* The function uses a specified padding character and rounds up the string length to the nearest multiple of `byteSize`.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} str The string to be padded.
|
|
164
|
+
* @param {number} [byteSize='8'] The byte block size to which the string length should be rounded up. Defaults to 8.
|
|
165
|
+
* @param {string} [padding='0'] The character to use for padding. Defaults to '0'.
|
|
166
|
+
* @returns {string} The padded string.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const myString = '123';
|
|
171
|
+
* const result = encode.sanitizeBytes(myString);
|
|
172
|
+
* // result: '00000123' (padded to 8 characters)
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export declare function sanitizeBytes(str: string, byteSize?: number, padding?: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Sanitizes a hex-string by removing any existing '0x' prefix, padding the string with '0' to ensure it has even length,
|
|
178
|
+
* and then re-adding the '0x' prefix.
|
|
179
|
+
*
|
|
180
|
+
* *[no internal usage]*
|
|
181
|
+
* @param hex hex-string
|
|
182
|
+
* @returns format: hex-string
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const unevenHex = '0x23abc';
|
|
187
|
+
* const result = encode.sanitizeHex(unevenHex);
|
|
188
|
+
* // result = '0x023abc' (padded to ensure even length)
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare function sanitizeHex(hex: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* String transformation util
|
|
194
|
+
*
|
|
195
|
+
* Pascal case to screaming snake case
|
|
196
|
+
*
|
|
197
|
+
* @param {string} text The PascalCase string to convert.
|
|
198
|
+
* @returns {string} The converted snake_case string in uppercase.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const pascalString = 'PascalCaseExample';
|
|
203
|
+
* const result = encode.pascalToSnake(pascalString);
|
|
204
|
+
* // result: 'PASCAL_CASE_EXAMPLE'
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare const pascalToSnake: (text: string) => string;
|
|
@@ -0,0 +1,282 @@
|
|
|
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
|
+
import { base64 } from '../../scure-base/index.js';
|
|
8
|
+
/* eslint-disable no-param-reassign */
|
|
9
|
+
export const IS_BROWSER = typeof window !== 'undefined';
|
|
10
|
+
const STRING_ZERO = '0';
|
|
11
|
+
/**
|
|
12
|
+
* Some functions recreated from https://github.com/pedrouid/enc-utils/blob/master/src/index.ts
|
|
13
|
+
* enc-utils is not a dependency to avoid using `Buffer` which only works in node and not browsers
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Convert array buffer to string
|
|
17
|
+
*
|
|
18
|
+
* *[internal usage]*
|
|
19
|
+
*
|
|
20
|
+
* @param {ArrayBuffer} array The ArrayBuffer to convert to string.
|
|
21
|
+
* @returns {string} The converted string.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const buffer = new ArrayBuffer(5);
|
|
26
|
+
* const view = new Uint8Array(buffer);
|
|
27
|
+
* [72, 101, 108, 108, 111].forEach((x, idx) => view[idx] = x);
|
|
28
|
+
* const result = encode.arrayBufferToString(buffer);
|
|
29
|
+
* // result = "Hello"
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function arrayBufferToString(array) {
|
|
33
|
+
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), '');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert utf8-string to Uint8Array
|
|
37
|
+
*
|
|
38
|
+
* *[internal usage]*
|
|
39
|
+
*
|
|
40
|
+
* @param {string} str The UTF-8 string to convert.
|
|
41
|
+
* @returns {Uint8Array} The encoded Uint8Array.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const myString = 'Hi';
|
|
46
|
+
* const result = encode.utf8ToArray(myString);
|
|
47
|
+
* // result = Uint8Array(2) [ 72, 105 ]
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function utf8ToArray(str) {
|
|
51
|
+
return new TextEncoder().encode(str);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Convert utf8-string to Uint8Array
|
|
55
|
+
*
|
|
56
|
+
* @deprecated equivalent to 'utf8ToArray', alias will be removed
|
|
57
|
+
*/
|
|
58
|
+
export function stringToArrayBuffer(str) {
|
|
59
|
+
return utf8ToArray(str);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert string to array buffer (browser and node compatible)
|
|
63
|
+
*
|
|
64
|
+
* @param {string} a The Base64 encoded string to convert.
|
|
65
|
+
* @returns {Uint8Array} The decoded Uint8Array.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const base64String = 'SGVsbG8='; // 'Hello' in Base64
|
|
70
|
+
* const result = encode.atobUniversal(base64String);
|
|
71
|
+
* // result = Uint8Array(5) [ 72, 101, 108, 108, 111 ]
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function atobUniversal(a) {
|
|
75
|
+
return base64.decode(a);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert array buffer to string (browser and node compatible)
|
|
79
|
+
*
|
|
80
|
+
* @param {ArrayBuffer} b The Array buffer.
|
|
81
|
+
* @returns {string} The Base64 encoded string.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const buffer = new Uint8Array([72, 101, 108, 108, 111]); // Array with ASCII values for 'Hello'
|
|
86
|
+
* const result = encode.btoaUniversal(buffer);
|
|
87
|
+
* // result = "SGVsbG8="
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function btoaUniversal(b) {
|
|
91
|
+
return base64.encode(new Uint8Array(b));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Convert array buffer to hex-string
|
|
95
|
+
*
|
|
96
|
+
* @param {Uint8Array} buffer The encoded Uint8Array.
|
|
97
|
+
* @returns {string} The hex-string
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const buffer = new Uint8Array([72, 101, 108, 108, 111]); // Array with ASCII values for 'Hello'
|
|
102
|
+
* const result = encode.buf2hex(buffer);
|
|
103
|
+
* // result = "48656c6c6f"
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function buf2hex(buffer) {
|
|
107
|
+
return buffer.reduce((r, x) => r + x.toString(16).padStart(2, '0'), '');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Remove hex prefix '0x' from hex-string
|
|
111
|
+
* @param hex hex-string
|
|
112
|
+
* @returns {string} The hex-string
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const hexStringWithPrefix = '0x48656c6c6f';
|
|
117
|
+
* const result = encode.removeHexPrefix(hexStringWithPrefix);
|
|
118
|
+
* // result: "48656c6c6f"
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export function removeHexPrefix(hex) {
|
|
122
|
+
return hex.replace(/^0x/i, '');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Add hex prefix '0x' to base16-string
|
|
126
|
+
* @param hex base16-string
|
|
127
|
+
* @returns {string} The hex-string
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const plainHexString = '48656c6c6f';
|
|
132
|
+
* const result = encode.addHexPrefix(plainHexString);
|
|
133
|
+
* // result: "0x48656c6c6f"
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export function addHexPrefix(hex) {
|
|
137
|
+
return `0x${removeHexPrefix(hex)}`;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Prepend or append to string
|
|
141
|
+
*
|
|
142
|
+
* *[internal usage]*
|
|
143
|
+
*
|
|
144
|
+
* Pads a string to a certain length with a specific string.
|
|
145
|
+
* The padding can be applied either to the left or the right of the input string.
|
|
146
|
+
*
|
|
147
|
+
* @param {string} str The string to pad.
|
|
148
|
+
* @param {number} length The target length for the padded string.
|
|
149
|
+
* @param {boolean} left Set to true to add padding to the left, false to add it to the right.
|
|
150
|
+
* @param {string} [padding='0'] The string to use for padding. Defaults to '0'.
|
|
151
|
+
* @returns {string} The padded string.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const myString = 'hello';
|
|
156
|
+
* const result = padString(myString, 10, true);
|
|
157
|
+
* // result = '00000hello'
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
function padString(str, length, left, padding = STRING_ZERO) {
|
|
161
|
+
const diff = length - str.length;
|
|
162
|
+
let result = str;
|
|
163
|
+
if (diff > 0) {
|
|
164
|
+
const pad = padding.repeat(diff);
|
|
165
|
+
result = left ? pad + str : str + pad;
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Prepend string (default with '0')
|
|
171
|
+
*
|
|
172
|
+
* Pads a string to a certain length with a specific string.
|
|
173
|
+
* The padding can be applied only to the left of the input string.
|
|
174
|
+
*
|
|
175
|
+
* @param {string} str The string to pad.
|
|
176
|
+
* @param {number} length The target length for the padded string.
|
|
177
|
+
* @param {string} [padding='0'] The string to use for padding. Defaults to '0'.
|
|
178
|
+
* @returns {string} The padded string.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const myString = '1A3F';
|
|
183
|
+
* const result = encode.padLeft(myString, 10);
|
|
184
|
+
* // result: '0000001A3F'
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export function padLeft(str, length, padding = STRING_ZERO) {
|
|
188
|
+
return padString(str, length, true, padding);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Calculate byte length of string
|
|
192
|
+
*
|
|
193
|
+
* *[no internal usage]*
|
|
194
|
+
*
|
|
195
|
+
* Calculates the byte length of a string based on a specified byte size.
|
|
196
|
+
* The function rounds up the byte count to the nearest multiple of the specified byte size.
|
|
197
|
+
*
|
|
198
|
+
* @param {string} str The string whose byte length is to be calculated.
|
|
199
|
+
* @param {number} [byteSize='8'] The size of the byte block to round up to. Defaults to 8.
|
|
200
|
+
* @returns {number} The calculated byte length, rounded to the nearest multiple of byteSize.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const myString = 'Hello';
|
|
205
|
+
* const result = encode.calcByteLength(myString, 4);
|
|
206
|
+
* // result = 8 (rounded up to the nearest multiple of 4)
|
|
207
|
+
*
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export function calcByteLength(str, byteSize = 8) {
|
|
211
|
+
const { length } = str;
|
|
212
|
+
const remainder = length % byteSize;
|
|
213
|
+
return remainder ? ((length - remainder) / byteSize) * byteSize + byteSize : length;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Prepend '0' to string bytes
|
|
217
|
+
*
|
|
218
|
+
* *[no internal usage]*
|
|
219
|
+
*
|
|
220
|
+
*
|
|
221
|
+
* * Prepends padding to the left of a string to ensure it matches a specific byte length.
|
|
222
|
+
* The function uses a specified padding character and rounds up the string length to the nearest multiple of `byteSize`.
|
|
223
|
+
*
|
|
224
|
+
* @param {string} str The string to be padded.
|
|
225
|
+
* @param {number} [byteSize='8'] The byte block size to which the string length should be rounded up. Defaults to 8.
|
|
226
|
+
* @param {string} [padding='0'] The character to use for padding. Defaults to '0'.
|
|
227
|
+
* @returns {string} The padded string.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const myString = '123';
|
|
232
|
+
* const result = encode.sanitizeBytes(myString);
|
|
233
|
+
* // result: '00000123' (padded to 8 characters)
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export function sanitizeBytes(str, byteSize = 8, padding = STRING_ZERO) {
|
|
237
|
+
return padLeft(str, calcByteLength(str, byteSize), padding);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Sanitizes a hex-string by removing any existing '0x' prefix, padding the string with '0' to ensure it has even length,
|
|
241
|
+
* and then re-adding the '0x' prefix.
|
|
242
|
+
*
|
|
243
|
+
* *[no internal usage]*
|
|
244
|
+
* @param hex hex-string
|
|
245
|
+
* @returns format: hex-string
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const unevenHex = '0x23abc';
|
|
250
|
+
* const result = encode.sanitizeHex(unevenHex);
|
|
251
|
+
* // result = '0x023abc' (padded to ensure even length)
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export function sanitizeHex(hex) {
|
|
255
|
+
hex = removeHexPrefix(hex);
|
|
256
|
+
hex = sanitizeBytes(hex, 2);
|
|
257
|
+
if (hex) {
|
|
258
|
+
hex = addHexPrefix(hex);
|
|
259
|
+
}
|
|
260
|
+
return hex;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* String transformation util
|
|
264
|
+
*
|
|
265
|
+
* Pascal case to screaming snake case
|
|
266
|
+
*
|
|
267
|
+
* @param {string} text The PascalCase string to convert.
|
|
268
|
+
* @returns {string} The converted snake_case string in uppercase.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const pascalString = 'PascalCaseExample';
|
|
273
|
+
* const result = encode.pascalToSnake(pascalString);
|
|
274
|
+
* // result: 'PASCAL_CASE_EXAMPLE'
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
export const pascalToSnake = (text) => /[a-z]/.test(text)
|
|
278
|
+
? text
|
|
279
|
+
.split(/(?=[A-Z])/)
|
|
280
|
+
.join('_')
|
|
281
|
+
.toUpperCase()
|
|
282
|
+
: text;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class Hash
|
|
3
|
+
*/
|
|
4
|
+
import { BigNumberish, CompiledContract, CompiledSierra, CompiledSierraCasm, LegacyCompiledContract, RawArgs } from '../../types/index.js';
|
|
5
|
+
export declare function computePedersenHash(a: BigNumberish, b: BigNumberish): string;
|
|
6
|
+
export declare function computePoseidonHash(a: BigNumberish, b: BigNumberish): string;
|
|
7
|
+
/**
|
|
8
|
+
* Compute pedersen hash from data
|
|
9
|
+
* @returns format: hex-string - pedersen hash
|
|
10
|
+
*/
|
|
11
|
+
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
12
|
+
export declare const computePedersenHashOnElements: typeof computeHashOnElements;
|
|
13
|
+
export declare function computePoseidonHashOnElements(data: BigNumberish[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Calculate contract address from class hash
|
|
16
|
+
* @returns format: hex-string
|
|
17
|
+
*/
|
|
18
|
+
export declare function calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawArgs, deployerAddress: BigNumberish): string;
|
|
19
|
+
/**
|
|
20
|
+
* Format json-string to conform starknet json-string
|
|
21
|
+
* @param json json-string
|
|
22
|
+
* @returns format: json-string
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatSpaces(json: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Compute hinted class hash for legacy compiled contract (Cairo 0)
|
|
27
|
+
* @returns format: hex-string
|
|
28
|
+
*/
|
|
29
|
+
export default function computeHintedClassHash(compiledContract: LegacyCompiledContract): string;
|
|
30
|
+
/**
|
|
31
|
+
* Computes the class hash for legacy compiled contract (Cairo 0)
|
|
32
|
+
* @returns format: hex-string
|
|
33
|
+
*/
|
|
34
|
+
export declare function computeLegacyContractClassHash(contract: LegacyCompiledContract | string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Compute hash of the bytecode for Sierra v1.5.0 onwards (Cairo 2.6.0)
|
|
37
|
+
* Each segment is Poseidon hashed.
|
|
38
|
+
* The global hash is : 1 + PoseidonHash(len0, h0, len1, h1, ...)
|
|
39
|
+
* @param casm compiled Sierra CASM file content.
|
|
40
|
+
* @returns the bytecode hash as bigint.
|
|
41
|
+
*/
|
|
42
|
+
export declare function hashByteCodeSegments(casm: CompiledSierraCasm): bigint;
|
|
43
|
+
/**
|
|
44
|
+
* Compute compiled class hash for contract (Cairo 1)
|
|
45
|
+
* @returns format: hex-string
|
|
46
|
+
*/
|
|
47
|
+
export declare function computeCompiledClassHash(casm: CompiledSierraCasm): string;
|
|
48
|
+
/**
|
|
49
|
+
* Compute sierra contract class hash (Cairo 1)
|
|
50
|
+
* @returns format: hex-string
|
|
51
|
+
*/
|
|
52
|
+
export declare function computeSierraContractClassHash(sierra: CompiledSierra): string;
|
|
53
|
+
/**
|
|
54
|
+
* Compute ClassHash (sierra or legacy) based on provided contract
|
|
55
|
+
* @returns format: hex-string
|
|
56
|
+
*/
|
|
57
|
+
export declare function computeContractClassHash(contract: CompiledContract | string): string;
|