starknet 3.15.2 → 3.15.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.15.3](https://github.com/0xs34n/starknet.js/compare/v3.15.2...v3.15.3) (2022-06-20)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **dev:** regenerated package-lock.json ([849cb1e](https://github.com/0xs34n/starknet.js/commit/849cb1ea3ffd7ba10b40b232d0ebc46b6599c7ea))
6
+ - use cross-fetch only for jest ([83be37a](https://github.com/0xs34n/starknet.js/commit/83be37a9e3328a44abd9583b8167c3cb8d882790))
7
+
1
8
  ## [3.15.2](https://github.com/0xs34n/starknet.js/compare/v3.15.1...v3.15.2) (2022-06-18)
2
9
 
3
10
  ### Bug Fixes
@@ -1,6 +1,9 @@
1
1
  /* eslint-disable no-console */
2
+ import fetch from 'cross-fetch';
2
3
  import { register } from 'fetch-intercept';
3
4
 
5
+ global.fetch = fetch;
6
+
4
7
  jest.setTimeout(50 * 60 * 1000);
5
8
 
6
9
  if (process.env.DEBUG === 'true') {
@@ -67,7 +67,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
67
67
  };
68
68
  Object.defineProperty(exports, "__esModule", { value: true });
69
69
  exports.Provider = void 0;
70
- var cross_fetch_1 = __importDefault(require("cross-fetch"));
71
70
  var url_join_1 = __importDefault(require("url-join"));
72
71
  var constants_1 = require("../constants");
73
72
  var hash_1 = require("../utils/hash");
@@ -191,7 +190,7 @@ var Provider = /** @class */ (function () {
191
190
  queryString = this.getQueryString(query);
192
191
  headers = this.getHeaders(method);
193
192
  url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
194
- return [2 /*return*/, (0, cross_fetch_1.default)(url, {
193
+ return [2 /*return*/, fetch(url, {
195
194
  method: method,
196
195
  body: (0, json_1.stringify)(request),
197
196
  headers: headers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.15.2",
3
+ "version": "3.15.3",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,14 +43,17 @@
43
43
  "@types/minimalistic-assert": "^1.0.1",
44
44
  "@types/pako": "^2.0.0",
45
45
  "@types/url-join": "^4.0.1",
46
+ "@types/whatwg-fetch": "^0.0.33",
46
47
  "@typescript-eslint/eslint-plugin": "^5.28.0",
47
48
  "@typescript-eslint/parser": "^5.28.0",
49
+ "cross-fetch": "^3.1.5",
48
50
  "eslint": "^8.17.0",
49
51
  "eslint-config-airbnb-base": "^15.0.0",
50
52
  "eslint-config-airbnb-typescript": "^17.0.0",
51
53
  "eslint-config-prettier": "^8.5.0",
52
54
  "eslint-plugin-import": "^2.26.0",
53
55
  "eslint-plugin-prettier": "^4.0.0",
56
+ "fetch-intercept": "^2.4.0",
54
57
  "husky": "^8.0.1",
55
58
  "import-sort-style-module": "^6.0.0",
56
59
  "jest": "^28.1.1",
@@ -68,7 +71,6 @@
68
71
  "cross-fetch": "^3.1.5",
69
72
  "elliptic": "^6.5.4",
70
73
  "ethereum-cryptography": "^1.0.3",
71
- "fetch-intercept": "^2.4.0",
72
74
  "hash.js": "^1.1.7",
73
75
  "json-bigint": "^1.0.0",
74
76
  "minimalistic-assert": "^1.0.1",
@@ -173,7 +173,6 @@ var __importDefault =
173
173
  };
174
174
  Object.defineProperty(exports, '__esModule', { value: true });
175
175
  exports.Provider = void 0;
176
- var cross_fetch_1 = __importDefault(require('cross-fetch'));
177
176
  var url_join_1 = __importDefault(require('url-join'));
178
177
  var constants_1 = require('../constants');
179
178
  var hash_1 = require('../utils/hash');
@@ -308,7 +307,7 @@ var Provider = /** @class */ (function () {
308
307
  url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
309
308
  return [
310
309
  2 /*return*/,
311
- (0, cross_fetch_1.default)(url, {
310
+ fetch(url, {
312
311
  method: method,
313
312
  body: (0, json_1.stringify)(request),
314
313
  headers: headers,
@@ -1,4 +1,3 @@
1
- import fetch from 'cross-fetch';
2
1
  import urljoin from 'url-join';
3
2
 
4
3
  import { ONE, StarknetChainId, ZERO } from '../constants';
@@ -14,6 +14,8 @@ the address helpers can be imported using:
14
14
  import { address } from 'starknet.js';
15
15
  ```
16
16
 
17
+ <br/>
18
+
17
19
  ### `getChecksumAddress(address: BigNumberish): string`
18
20
 
19
21
  This function accepts an address as a `BigNumberish` and returns the checksummed address as a string.
@@ -29,6 +31,235 @@ const checksummedAddress = address.getChecksumAddress(addressToCheck);
29
31
  console.log(checksummedAddress); // 0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914
30
32
  ```
31
33
 
34
+ <br/>
35
+
32
36
  ### `validateChecksumAddress(address: string): boolean`
33
37
 
34
38
  This function validates the checksum address. It returns true if the address is valid, false otherwise.
39
+
40
+ <hr />
41
+
42
+ ## `stark`
43
+
44
+ Functions for stark specific manipulations.
45
+
46
+ <br/>
47
+
48
+ ### `compressProgram(jsonProgram: Program | string): CompressedProgram`
49
+
50
+ Function to compress compiled cairo program. Accepts a json file representing the compiled cairo program and returns a compressed cairo program.
51
+
52
+ <br/>
53
+
54
+ ### `randomAddress(): string`
55
+
56
+ Function that generates a random contract address.
57
+
58
+ <br/>
59
+
60
+ ### `makeAddress(input: string): string`
61
+
62
+ Function that turns an incompatible address string into stark address format. Returns a string.
63
+
64
+ Example: `0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5` -> `0xdfd0f27fce99b50909de0bdd328aed6eabe76bc5`
65
+
66
+ <br/>
67
+
68
+ ### `formatSignature(sig?: Signature): string[]`
69
+
70
+ Function that formats a Signature to BigNum and then to string array. Returns a string array.
71
+
72
+ <br/>
73
+
74
+ ### `compileCalldata(args: RawArgs): Calldata`
75
+
76
+ Function that creates calldata that gets sent to the contract.
77
+
78
+ ```js
79
+ await this.callContract({
80
+ contractAddress: this.address,
81
+ entrypoint: 'is_valid_signature',
82
+ calldata: compileCalldata({
83
+ hash: toBN(hash).toString(),
84
+ signature: signature.map((x) => toBN(x).toString()),
85
+ }),
86
+ });
87
+ ```
88
+
89
+ <br/>
90
+
91
+ ### `estimatedFeeToMaxFee(estimatedFee: BigNumberish, overhead: number = 0.5): BN`
92
+
93
+ Function that calculates and returns maximum fee based on the previously estimated one.
94
+
95
+ Returns a BN.
96
+
97
+ <hr />
98
+
99
+ ## `number`
100
+
101
+ Various number formatting functions.
102
+
103
+ `BN` is the `BigNum` representation imported from `bn.js` library.
104
+
105
+ ```js
106
+ export type BigNumberish = string | number | BN;
107
+ ```
108
+
109
+ <br/>
110
+
111
+ ### `isHex(hex: string): boolean`
112
+
113
+ Check if number is in hex format.
114
+
115
+ <br/>
116
+
117
+ ### `toBN(number: BigNumberish, base?: number | 'hex'): BN`
118
+
119
+ Converts BigNumberish to BN. Returns a BN.
120
+
121
+ <br/>
122
+
123
+ ### `toHex(number: BN): string`
124
+
125
+ Converts BN to hex. Returns a string.
126
+
127
+ <br/>
128
+
129
+ ### `hexToDecimalString(hex: string): string`
130
+
131
+ Converts hex string to decimal string.
132
+
133
+ <br/>
134
+
135
+ ### `toFelt(num: BigNumberish): string`
136
+
137
+ Converts BN to Felt. Returns a string.
138
+
139
+ <br/>
140
+
141
+ ### `assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName = '')`
142
+
143
+ Asserts input is equal to or greater then `lowerBound` and lower then `upperBound`. Assert message specifies inputName.
144
+ `input`, `lowerBound`, and `upperBound` should be of type BN.
145
+ `inputName` should be a string.
146
+
147
+ <br/>
148
+
149
+ ### `bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[]`
150
+
151
+ Convert BigNumberish array to decimal array. Used for signature conversion.
152
+
153
+ ``` js
154
+ const signature = await this.signer.signTransaction(transactions, signerDetails);
155
+
156
+ {
157
+ contract_address: this.address,
158
+ entry_point_selector: getSelectorFromName('__execute__'),
159
+ calldata,
160
+ version: toHex(version),
161
+ signature: bigNumberishArrayToDecimalStringArray(signature),
162
+ }
163
+ ```
164
+
165
+ <hr />
166
+
167
+ ## `uint256`
168
+
169
+ ```js
170
+ // Represents an integer in the range [0, 2^256).
171
+ export interface Uint256 {
172
+ // The low 128 bits of the value.
173
+ low: BigNumberish;
174
+ // The high 128 bits of the value.
175
+ high: BigNumberish;
176
+ }
177
+ ```
178
+
179
+ <br/>
180
+
181
+ ### `uint256ToBN(uint256: Uint256): BN`
182
+
183
+ Function to convert `Uint256` to `BN` (big number), which uses the `bn.js` library.
184
+
185
+ <br/>
186
+
187
+ ### `isUint256(bn: BigNumberish): boolean`
188
+
189
+ Function to check if `BN` is smaller or equal to `2**256-1`.
190
+
191
+ <br/>
192
+
193
+ ### `bnToUint256(bignumber: BigNumberish): Uint256`
194
+
195
+ Function to convert `BN` to `Uint256`.
196
+
197
+ <hr />
198
+
199
+ ## `hash`
200
+
201
+ Various hashing helpers.
202
+
203
+ ### `starknetKeccak(value: string): BN`
204
+
205
+ Function to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
206
+ nction to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
207
+
208
+ <br/>
209
+
210
+ ### `getSelectorFromName(funcName: string)`
211
+
212
+ Function to get the hex selector from a given function name. Returns hex selector of given abi function name.
213
+
214
+ <br/>
215
+
216
+ ### `pedersen(input: [BigNumberish, BigNumberish])`
217
+
218
+ <br/>
219
+
220
+ Function to get the Pedersen hash for two arguments. Returns a string.
221
+
222
+ ### `computeHashOnElements(data: BigNumberish[])`
223
+
224
+ <br/>
225
+
226
+ Function to compute a Pedersen hash on a array of elements. Returns a string.
227
+
228
+ <br/>
229
+
230
+ ### `calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish,contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData: BigNumberish[] = []): string`
231
+
232
+ Calculates the transaction hash in the StarkNet network - a unique identifier of the transaction.
233
+
234
+ Called internally in `calculateDeployTransactionHash` and `calculcateTransactionHash`.
235
+
236
+ <br/>
237
+
238
+ ### `calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string`
239
+
240
+ Function that calculates the deployment transaction hash in the StarkNet network.
241
+
242
+ Internally calls `calculateTransactionHashCommon` with `TransactionHashPrefix.DEPLOY`.
243
+
244
+ <br/>
245
+
246
+ ### `calculcateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId): string`
247
+
248
+ Function that internally calls `calculateTransactionHashCommon`, with `TransactionHashPrefix.INVOKE`.
249
+
250
+ ```js
251
+ const hashMsg = calculcateTransactionHash(
252
+ account,
253
+ transactionVersion,
254
+ getSelectorFromName('__execute__'),
255
+ calldata,
256
+ maxFee,
257
+ StarknetChainId.TESTNET
258
+ );
259
+ ```
260
+
261
+ <br/>
262
+
263
+ ### `calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawCalldata, deployerAddress: BigNumberish)`
264
+
265
+ Function that calculates contract address from hash. Returns a string.