starknet 3.15.1 → 3.15.2

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,12 @@
1
+ ## [3.15.2](https://github.com/0xs34n/starknet.js/compare/v3.15.1...v3.15.2) (2022-06-18)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **cleanup:** cleanup ([a15b6c6](https://github.com/0xs34n/starknet.js/commit/a15b6c6bf13ce7af699c293d697b5136188388c3))
6
+ - **errorcode:** fixed error code >=400 instead of !=200 ([0f16595](https://github.com/0xs34n/starknet.js/commit/0f1659543ba95ce7cac31a5182dad2e33325d4c1))
7
+ - **fetchEndpoint:** error handling and test case fix ([629479f](https://github.com/0xs34n/starknet.js/commit/629479f877aa7d6f39c8d31b2c9449563aadd0e7))
8
+ - **verify:** return false when 500 returned from the gateway ([de3e004](https://github.com/0xs34n/starknet.js/commit/de3e00461730d6fa112046169470d7a603baa296))
9
+
1
10
  ## [3.15.1](https://github.com/0xs34n/starknet.js/compare/v3.15.0...v3.15.1) (2022-06-17)
2
11
 
3
12
  ### Bug Fixes
@@ -128,9 +128,15 @@ describe('deploy and test Wallet', () => {
128
128
  expect(toBN(response.number as string).toString()).toStrictEqual('57');
129
129
  });
130
130
 
131
- test('sign and verify offchain message', async () => {
131
+ test('sign and verify offchain message fail', async () => {
132
132
  const signature = await account.signMessage(typedDataExample);
133
+ // change the signature to make it invalid
134
+ signature[0] += '123';
135
+ expect(await account.verifyMessage(typedDataExample, signature)).toBe(false);
136
+ });
133
137
 
138
+ test('sign and verify offchain message', async () => {
139
+ const signature = await account.signMessage(typedDataExample);
134
140
  expect(await account.verifyMessage(typedDataExample, signature)).toBe(true);
135
141
  });
136
142
 
@@ -196,7 +196,12 @@ var Provider = /** @class */ (function () {
196
196
  body: (0, json_1.stringify)(request),
197
197
  headers: headers,
198
198
  })
199
- .then(function (res) { return res.text(); })
199
+ .then(function (res) {
200
+ if (res.status >= 400) {
201
+ throw Error(res.statusText);
202
+ }
203
+ return res.text();
204
+ })
200
205
  .then(function (res) {
201
206
  if (endpoint === 'estimate_fee') {
202
207
  return (0, json_1.parse)(res, function (_, v) {
@@ -207,6 +212,9 @@ var Provider = /** @class */ (function () {
207
212
  });
208
213
  }
209
214
  return (0, json_1.parse)(res);
215
+ })
216
+ .catch(function (err) {
217
+ throw Error("Could not ".concat(method, " from endpoint `").concat(url, "`: ").concat(err.message));
210
218
  })];
211
219
  });
212
220
  });
@@ -42,7 +42,7 @@ function getBlockIdentifier(blockIdentifier) {
42
42
  if (blockIdentifier === 'pending') {
43
43
  return { type: 'BLOCK_NUMBER', data: 'pending' };
44
44
  }
45
- if (typeof blockIdentifier === 'number') {
45
+ if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
46
46
  return { type: 'BLOCK_NUMBER', data: blockIdentifier };
47
47
  }
48
48
  if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.15.1",
3
+ "version": "3.15.2",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -314,6 +314,9 @@ var Provider = /** @class */ (function () {
314
314
  headers: headers,
315
315
  })
316
316
  .then(function (res) {
317
+ if (res.status >= 400) {
318
+ throw Error(res.statusText);
319
+ }
317
320
  return res.text();
318
321
  })
319
322
  .then(function (res) {
@@ -326,6 +329,14 @@ var Provider = /** @class */ (function () {
326
329
  });
327
330
  }
328
331
  return (0, json_1.parse)(res);
332
+ })
333
+ .catch(function (err) {
334
+ throw Error(
335
+ 'Could not '
336
+ .concat(method, ' from endpoint `')
337
+ .concat(url, '`: ')
338
+ .concat(err.message)
339
+ );
329
340
  }),
330
341
  ];
331
342
  });
package/provider/utils.js CHANGED
@@ -45,7 +45,7 @@ function getBlockIdentifier(blockIdentifier) {
45
45
  if (blockIdentifier === 'pending') {
46
46
  return { type: 'BLOCK_NUMBER', data: 'pending' };
47
47
  }
48
- if (typeof blockIdentifier === 'number') {
48
+ if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
49
49
  return { type: 'BLOCK_NUMBER', data: blockIdentifier };
50
50
  }
51
51
  if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
@@ -159,7 +159,12 @@ export class Provider implements ProviderInterface {
159
159
  body: stringify(request),
160
160
  headers,
161
161
  })
162
- .then((res) => res.text())
162
+ .then((res) => {
163
+ if (res.status >= 400) {
164
+ throw Error(res.statusText);
165
+ }
166
+ return res.text();
167
+ })
163
168
  .then((res) => {
164
169
  if (endpoint === 'estimate_fee') {
165
170
  return parse(res, (_, v) => {
@@ -170,6 +175,9 @@ export class Provider implements ProviderInterface {
170
175
  });
171
176
  }
172
177
  return parse(res) as Endpoints[T]['RESPONSE'];
178
+ })
179
+ .catch((err) => {
180
+ throw Error(`Could not ${method} from endpoint \`${url}\`: ${err.message}`);
173
181
  });
174
182
  }
175
183
 
@@ -49,7 +49,7 @@ export function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdent
49
49
  if (blockIdentifier === 'pending') {
50
50
  return { type: 'BLOCK_NUMBER', data: 'pending' };
51
51
  }
52
- if (typeof blockIdentifier === 'number') {
52
+ if (typeof blockIdentifier === 'number' || typeof blockIdentifier === 'bigint') {
53
53
  return { type: 'BLOCK_NUMBER', data: blockIdentifier };
54
54
  }
55
55
  if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {