starknet 3.15.4 → 3.16.0

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,25 @@
1
+ # [3.16.0](https://github.com/0xs34n/starknet.js/compare/v3.15.6...v3.16.0) (2022-06-29)
2
+
3
+ ### Features
4
+
5
+ - **npm:** add npmignore file ([e6084dd](https://github.com/0xs34n/starknet.js/commit/e6084ddbb9ea305847a312cd3a3247b730cca9b5))
6
+
7
+ ## [3.15.6](https://github.com/0xs34n/starknet.js/compare/v3.15.5...v3.15.6) (2022-06-28)
8
+
9
+ ### Bug Fixes
10
+
11
+ - throw http error when parsing fails ([898574f](https://github.com/0xs34n/starknet.js/commit/898574f0087bf653b5d74bbe3dc52a0cb6efc432))
12
+
13
+ ## [3.15.5](https://github.com/0xs34n/starknet.js/compare/v3.15.4...v3.15.5) (2022-06-27)
14
+
15
+ ### Bug Fixes
16
+
17
+ - add return statement ([468a0bf](https://github.com/0xs34n/starknet.js/commit/468a0bfbbc1a9c88383ed2ba0f0bc02b0e5e3a9b))
18
+ - don't enforce bigInt ([efef507](https://github.com/0xs34n/starknet.js/commit/efef5071ebceb5247f5f1995d3c1006d422c02ee))
19
+ - **GatewayError:** export from index ([69addd5](https://github.com/0xs34n/starknet.js/commit/69addd5a2eb30816f5e43ffd71e190838ad5a409))
20
+ - **GatewayError:** use ts-custom-error to support "err instanceof GatewayError" ([092abbc](https://github.com/0xs34n/starknet.js/commit/092abbcff5f5270a0be0b79a8e87645637298c56))
21
+ - **test:** error 500 as number instead of bigInt ([b539144](https://github.com/0xs34n/starknet.js/commit/b5391448cf04d93c4d914ad52d850591a423fe42))
22
+
1
23
  ## [3.15.4](https://github.com/0xs34n/starknet.js/compare/v3.15.3...v3.15.4) (2022-06-20)
2
24
 
3
25
  ### Bug Fixes
@@ -46,8 +46,16 @@ describe('defaultProvider', () => {
46
46
  test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, () => {
47
47
  return expect(provider.getBlock(exampleBlockNumber)).resolves.not.toThrow();
48
48
  });
49
- test('getBlock(blockHash=undefined, blockNumber=null)', () => {
50
- return expect(provider.getBlock()).resolves.not.toThrow();
49
+ test('getBlock(blockHash=undefined, blockNumber=null)', async () => {
50
+ const block = await provider.getBlock();
51
+
52
+ expect(block).not.toBeNull();
53
+
54
+ const { block_number, timestamp } = block;
55
+
56
+ expect(typeof block_number).toEqual('number');
57
+
58
+ return expect(typeof timestamp).toEqual('number');
51
59
  });
52
60
  test('getBlock() -> { blockNumber }', async () => {
53
61
  const block = await provider.getBlock();
@@ -124,7 +132,7 @@ describe('defaultProvider', () => {
124
132
  await promise;
125
133
  } catch (e) {
126
134
  expect(e.errorCode).toMatchInlineSnapshot(
127
- IS_DEVNET ? `500n` : `"StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT"`
135
+ IS_DEVNET ? `500` : `"StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT"`
128
136
  );
129
137
  }
130
138
  });
@@ -73,6 +73,7 @@ var hash_1 = require("../utils/hash");
73
73
  var json_1 = require("../utils/json");
74
74
  var number_1 = require("../utils/number");
75
75
  var stark_1 = require("../utils/stark");
76
+ var errors_1 = require("./errors");
76
77
  var interface_1 = require("./interface");
77
78
  var utils_1 = require("./utils");
78
79
  function wait(delay) {
@@ -206,12 +207,19 @@ var Provider = /** @class */ (function () {
206
207
  case 3:
207
208
  textResponse = _c.sent();
208
209
  if (!res.ok) {
209
- responseBody = (0, json_1.parse)(textResponse);
210
+ responseBody = void 0;
211
+ try {
212
+ responseBody = (0, json_1.parse)(textResponse);
213
+ }
214
+ catch (_d) {
215
+ // if error parsing fails, return an http error
216
+ throw new errors_1.HttpError(res.statusText, res.status);
217
+ }
210
218
  errorCode = responseBody.code || (responseBody === null || responseBody === void 0 ? void 0 : responseBody.status_code);
211
- throw new utils_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
219
+ throw new errors_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
212
220
  }
213
221
  if (endpoint === 'estimate_fee') {
214
- return [2 /*return*/, (0, json_1.parse)(textResponse, function (_, v) {
222
+ return [2 /*return*/, (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
215
223
  if (v && typeof v === 'bigint') {
216
224
  return (0, number_1.toBN)(v.toString());
217
225
  }
@@ -221,7 +229,8 @@ var Provider = /** @class */ (function () {
221
229
  return [2 /*return*/, (0, json_1.parse)(textResponse)];
222
230
  case 4:
223
231
  err_1 = _c.sent();
224
- if (err_1 instanceof utils_1.GatewayError) {
232
+ // rethrow custom errors
233
+ if (err_1 instanceof errors_1.GatewayError || err_1 instanceof errors_1.HttpError) {
225
234
  throw err_1;
226
235
  }
227
236
  if (err_1 instanceof Error) {
@@ -0,0 +1,9 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export declare class GatewayError extends CustomError {
3
+ errorCode: string;
4
+ constructor(message: string, errorCode: string);
5
+ }
6
+ export declare class HttpError extends CustomError {
7
+ errorCode: number;
8
+ constructor(message: string, errorCode: number);
9
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HttpError = exports.GatewayError = void 0;
19
+ /* eslint-disable max-classes-per-file */
20
+ var ts_custom_error_1 = require("ts-custom-error");
21
+ var GatewayError = /** @class */ (function (_super) {
22
+ __extends(GatewayError, _super);
23
+ function GatewayError(message, errorCode) {
24
+ var _this = _super.call(this, message) || this;
25
+ _this.errorCode = errorCode;
26
+ return _this;
27
+ }
28
+ return GatewayError;
29
+ }(ts_custom_error_1.CustomError));
30
+ exports.GatewayError = GatewayError;
31
+ var HttpError = /** @class */ (function (_super) {
32
+ __extends(HttpError, _super);
33
+ function HttpError(message, errorCode) {
34
+ var _this = _super.call(this, message) || this;
35
+ _this.errorCode = errorCode;
36
+ return _this;
37
+ }
38
+ return HttpError;
39
+ }(ts_custom_error_1.CustomError));
40
+ exports.HttpError = HttpError;
@@ -1,4 +1,5 @@
1
1
  import { Provider } from './default';
2
2
  export * from './default';
3
+ export * from './errors';
3
4
  export * from './interface';
4
5
  export declare const defaultProvider: Provider;
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.defaultProvider = void 0;
18
18
  var default_1 = require("./default");
19
19
  __exportStar(require("./default"), exports);
20
+ __exportStar(require("./errors"), exports);
20
21
  __exportStar(require("./interface"), exports);
21
22
  exports.defaultProvider = new default_1.Provider();
@@ -39,8 +39,4 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
39
39
  * @returns block identifier for API request
40
40
  */
41
41
  export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
42
- export declare class GatewayError extends Error {
43
- errorCode: string;
44
- constructor(message: string, errorCode: string);
45
- }
46
42
  export {};
@@ -1,21 +1,6 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.GatewayError = exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
3
+ exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
19
4
  var number_1 = require("../utils/number");
20
5
  /**
21
6
  *
@@ -92,13 +77,3 @@ function getFormattedBlockIdentifier(blockIdentifier) {
92
77
  return "blockHash=".concat((0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data)));
93
78
  }
94
79
  exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
95
- var GatewayError = /** @class */ (function (_super) {
96
- __extends(GatewayError, _super);
97
- function GatewayError(message, errorCode) {
98
- var _this = _super.call(this, message) || this;
99
- _this.errorCode = errorCode;
100
- return _this;
101
- }
102
- return GatewayError;
103
- }(Error));
104
- exports.GatewayError = GatewayError;
@@ -1,8 +1,11 @@
1
- declare const parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any, stringify: {
1
+ export declare const parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any, stringify: {
2
+ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
3
+ (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
4
+ };
5
+ export declare const parseAlwaysAsBig: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any, stringifyAlwaysAsBig: {
2
6
  (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
3
7
  (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
4
8
  };
5
- export { parse, stringify };
6
9
  declare const _default: {
7
10
  parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
8
11
  stringify: {
@@ -2,15 +2,18 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a, _b;
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.stringify = exports.parse = void 0;
7
+ exports.stringifyAlwaysAsBig = exports.parseAlwaysAsBig = exports.stringify = exports.parse = void 0;
7
8
  var json_bigint_1 = __importDefault(require("json-bigint"));
8
- var _a = (0, json_bigint_1.default)({
9
- alwaysParseAsBig: true,
10
- useNativeBigInt: true,
11
- protoAction: 'preserve',
12
- constructorAction: 'preserve',
13
- }), parse = _a.parse, stringify = _a.stringify;
14
- exports.parse = parse;
15
- exports.stringify = stringify;
16
- exports.default = { parse: parse, stringify: stringify };
9
+ var json = function (alwaysParseAsBig) {
10
+ return (0, json_bigint_1.default)({
11
+ alwaysParseAsBig: alwaysParseAsBig,
12
+ useNativeBigInt: true,
13
+ protoAction: 'preserve',
14
+ constructorAction: 'preserve',
15
+ });
16
+ };
17
+ exports.parse = (_a = json(false), _a.parse), exports.stringify = _a.stringify;
18
+ exports.parseAlwaysAsBig = (_b = json(true), _b.parse), exports.stringifyAlwaysAsBig = _b.stringify;
19
+ exports.default = { parse: exports.parse, stringify: exports.stringify };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.15.4",
3
+ "version": "3.16.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -75,6 +75,7 @@
75
75
  "json-bigint": "^1.0.0",
76
76
  "minimalistic-assert": "^1.0.1",
77
77
  "pako": "^2.0.4",
78
+ "ts-custom-error": "^3.2.0",
78
79
  "url-join": "^4.0.1"
79
80
  },
80
81
  "lint-staged": {
@@ -179,6 +179,7 @@ var hash_1 = require('../utils/hash');
179
179
  var json_1 = require('../utils/json');
180
180
  var number_1 = require('../utils/number');
181
181
  var stark_1 = require('../utils/stark');
182
+ var errors_1 = require('./errors');
182
183
  var interface_1 = require('./interface');
183
184
  var utils_1 = require('./utils');
184
185
  function wait(delay) {
@@ -333,18 +334,24 @@ var Provider = /** @class */ (function () {
333
334
  case 3:
334
335
  textResponse = _c.sent();
335
336
  if (!res.ok) {
336
- responseBody = (0, json_1.parse)(textResponse);
337
+ responseBody = void 0;
338
+ try {
339
+ responseBody = (0, json_1.parse)(textResponse);
340
+ } catch (_d) {
341
+ // if error parsing fails, return an http error
342
+ throw new errors_1.HttpError(res.statusText, res.status);
343
+ }
337
344
  errorCode =
338
345
  responseBody.code ||
339
346
  (responseBody === null || responseBody === void 0
340
347
  ? void 0
341
348
  : responseBody.status_code);
342
- throw new utils_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
349
+ throw new errors_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
343
350
  }
344
351
  if (endpoint === 'estimate_fee') {
345
352
  return [
346
353
  2 /*return*/,
347
- (0, json_1.parse)(textResponse, function (_, v) {
354
+ (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
348
355
  if (v && typeof v === 'bigint') {
349
356
  return (0, number_1.toBN)(v.toString());
350
357
  }
@@ -355,7 +362,8 @@ var Provider = /** @class */ (function () {
355
362
  return [2 /*return*/, (0, json_1.parse)(textResponse)];
356
363
  case 4:
357
364
  err_1 = _c.sent();
358
- if (err_1 instanceof utils_1.GatewayError) {
365
+ // rethrow custom errors
366
+ if (err_1 instanceof errors_1.GatewayError || err_1 instanceof errors_1.HttpError) {
359
367
  throw err_1;
360
368
  }
361
369
  if (err_1 instanceof Error) {
@@ -0,0 +1,9 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export declare class GatewayError extends CustomError {
3
+ errorCode: string;
4
+ constructor(message: string, errorCode: string);
5
+ }
6
+ export declare class HttpError extends CustomError {
7
+ errorCode: number;
8
+ constructor(message: string, errorCode: number);
9
+ }
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+ var __extends =
3
+ (this && this.__extends) ||
4
+ (function () {
5
+ var extendStatics = function (d, b) {
6
+ extendStatics =
7
+ Object.setPrototypeOf ||
8
+ ({ __proto__: [] } instanceof Array &&
9
+ function (d, b) {
10
+ d.__proto__ = b;
11
+ }) ||
12
+ function (d, b) {
13
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
14
+ };
15
+ return extendStatics(d, b);
16
+ };
17
+ return function (d, b) {
18
+ if (typeof b !== 'function' && b !== null)
19
+ throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
20
+ extendStatics(d, b);
21
+ function __() {
22
+ this.constructor = d;
23
+ }
24
+ d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
25
+ };
26
+ })();
27
+ Object.defineProperty(exports, '__esModule', { value: true });
28
+ exports.HttpError = exports.GatewayError = void 0;
29
+ /* eslint-disable max-classes-per-file */
30
+ var ts_custom_error_1 = require('ts-custom-error');
31
+ var GatewayError = /** @class */ (function (_super) {
32
+ __extends(GatewayError, _super);
33
+ function GatewayError(message, errorCode) {
34
+ var _this = _super.call(this, message) || this;
35
+ _this.errorCode = errorCode;
36
+ return _this;
37
+ }
38
+ return GatewayError;
39
+ })(ts_custom_error_1.CustomError);
40
+ exports.GatewayError = GatewayError;
41
+ var HttpError = /** @class */ (function (_super) {
42
+ __extends(HttpError, _super);
43
+ function HttpError(message, errorCode) {
44
+ var _this = _super.call(this, message) || this;
45
+ _this.errorCode = errorCode;
46
+ return _this;
47
+ }
48
+ return HttpError;
49
+ })(ts_custom_error_1.CustomError);
50
+ exports.HttpError = HttpError;
@@ -1,4 +1,5 @@
1
1
  import { Provider } from './default';
2
2
  export * from './default';
3
+ export * from './errors';
3
4
  export * from './interface';
4
5
  export declare const defaultProvider: Provider;
package/provider/index.js CHANGED
@@ -30,5 +30,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
30
30
  exports.defaultProvider = void 0;
31
31
  var default_1 = require('./default');
32
32
  __exportStar(require('./default'), exports);
33
+ __exportStar(require('./errors'), exports);
33
34
  __exportStar(require('./interface'), exports);
34
35
  exports.defaultProvider = new default_1.Provider();
@@ -41,8 +41,4 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
41
41
  * @returns block identifier for API request
42
42
  */
43
43
  export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
44
- export declare class GatewayError extends Error {
45
- errorCode: string;
46
- constructor(message: string, errorCode: string);
47
- }
48
44
  export {};
package/provider/utils.js CHANGED
@@ -1,32 +1,6 @@
1
1
  'use strict';
2
- var __extends =
3
- (this && this.__extends) ||
4
- (function () {
5
- var extendStatics = function (d, b) {
6
- extendStatics =
7
- Object.setPrototypeOf ||
8
- ({ __proto__: [] } instanceof Array &&
9
- function (d, b) {
10
- d.__proto__ = b;
11
- }) ||
12
- function (d, b) {
13
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
14
- };
15
- return extendStatics(d, b);
16
- };
17
- return function (d, b) {
18
- if (typeof b !== 'function' && b !== null)
19
- throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
20
- extendStatics(d, b);
21
- function __() {
22
- this.constructor = d;
23
- }
24
- d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
25
- };
26
- })();
27
2
  Object.defineProperty(exports, '__esModule', { value: true });
28
- exports.GatewayError =
29
- exports.getFormattedBlockIdentifier =
3
+ exports.getFormattedBlockIdentifier =
30
4
  exports.getBlockIdentifier =
31
5
  exports.txIdentifier =
32
6
  exports.formatHash =
@@ -108,13 +82,3 @@ function getFormattedBlockIdentifier(blockIdentifier) {
108
82
  return 'blockHash='.concat((0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data)));
109
83
  }
110
84
  exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
111
- var GatewayError = /** @class */ (function (_super) {
112
- __extends(GatewayError, _super);
113
- function GatewayError(message, errorCode) {
114
- var _this = _super.call(this, message) || this;
115
- _this.errorCode = errorCode;
116
- return _this;
117
- }
118
- return GatewayError;
119
- })(Error);
120
- exports.GatewayError = GatewayError;
@@ -20,11 +20,12 @@ import {
20
20
  TransactionReceiptResponse,
21
21
  } from '../types';
22
22
  import { getSelectorFromName } from '../utils/hash';
23
- import { parse, stringify } from '../utils/json';
23
+ import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
24
24
  import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
25
25
  import { compressProgram, randomAddress } from '../utils/stark';
26
+ import { GatewayError, HttpError } from './errors';
26
27
  import { ProviderInterface } from './interface';
27
- import { BlockIdentifier, GatewayError, getFormattedBlockIdentifier } from './utils';
28
+ import { BlockIdentifier, getFormattedBlockIdentifier } from './utils';
28
29
 
29
30
  type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
30
31
 
@@ -162,14 +163,20 @@ export class Provider implements ProviderInterface {
162
163
  const textResponse = await res.text();
163
164
  if (!res.ok) {
164
165
  // This will allow user to handle contract errors
165
- const responseBody = parse(textResponse);
166
+ let responseBody: any;
167
+ try {
168
+ responseBody = parse(textResponse);
169
+ } catch {
170
+ // if error parsing fails, return an http error
171
+ throw new HttpError(res.statusText, res.status);
172
+ }
166
173
 
167
174
  const errorCode = responseBody.code || ((responseBody as any)?.status_code as string); // starknet-devnet uses status_code instead of code; They need to fix that
168
175
  throw new GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
169
176
  }
170
177
 
171
178
  if (endpoint === 'estimate_fee') {
172
- return parse(textResponse, (_, v) => {
179
+ return parseAlwaysAsBig(textResponse, (_, v) => {
173
180
  if (v && typeof v === 'bigint') {
174
181
  return toBN(v.toString());
175
182
  }
@@ -178,7 +185,8 @@ export class Provider implements ProviderInterface {
178
185
  }
179
186
  return parse(textResponse) as Endpoints[T]['RESPONSE'];
180
187
  } catch (err) {
181
- if (err instanceof GatewayError) {
188
+ // rethrow custom errors
189
+ if (err instanceof GatewayError || err instanceof HttpError) {
182
190
  throw err;
183
191
  }
184
192
  if (err instanceof Error) {
@@ -0,0 +1,14 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import { CustomError } from 'ts-custom-error';
3
+
4
+ export class GatewayError extends CustomError {
5
+ constructor(message: string, public errorCode: string) {
6
+ super(message);
7
+ }
8
+ }
9
+
10
+ export class HttpError extends CustomError {
11
+ constructor(message: string, public errorCode: number) {
12
+ super(message);
13
+ }
14
+ }
@@ -1,6 +1,7 @@
1
1
  import { Provider } from './default';
2
2
 
3
3
  export * from './default';
4
+ export * from './errors';
4
5
  export * from './interface';
5
6
 
6
7
  export const defaultProvider = new Provider();
@@ -82,9 +82,3 @@ export function getFormattedBlockIdentifier(blockIdentifier: BlockIdentifier = n
82
82
  }
83
83
  return `blockHash=${toHex(toBN(blockIdentifierObject.data))}`;
84
84
  }
85
-
86
- export class GatewayError extends Error {
87
- constructor(message: string, public errorCode: string) {
88
- super(message);
89
- }
90
- }
package/src/utils/json.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  import Json from 'json-bigint';
2
2
 
3
- const { parse, stringify } = Json({
4
- alwaysParseAsBig: true,
5
- useNativeBigInt: true,
6
- protoAction: 'preserve',
7
- constructorAction: 'preserve',
8
- });
3
+ const json = (alwaysParseAsBig: boolean) => {
4
+ return Json({
5
+ alwaysParseAsBig,
6
+ useNativeBigInt: true,
7
+ protoAction: 'preserve',
8
+ constructorAction: 'preserve',
9
+ });
10
+ };
11
+
12
+ export const { parse, stringify } = json(false);
13
+ export const { parse: parseAlwaysAsBig, stringify: stringifyAlwaysAsBig } = json(true);
9
14
 
10
- export { parse, stringify };
11
15
  export default { parse, stringify };
package/utils/json.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const parse: (
1
+ export declare const parse: (
2
2
  text: string,
3
3
  reviver?: ((this: any, key: string, value: any) => any) | undefined
4
4
  ) => any,
@@ -14,7 +14,22 @@ declare const parse: (
14
14
  space?: string | number | undefined
15
15
  ): string;
16
16
  };
17
- export { parse, stringify };
17
+ export declare const parseAlwaysAsBig: (
18
+ text: string,
19
+ reviver?: ((this: any, key: string, value: any) => any) | undefined
20
+ ) => any,
21
+ stringifyAlwaysAsBig: {
22
+ (
23
+ value: any,
24
+ replacer?: ((this: any, key: string, value: any) => any) | undefined,
25
+ space?: string | number | undefined
26
+ ): string;
27
+ (
28
+ value: any,
29
+ replacer?: (string | number)[] | null | undefined,
30
+ space?: string | number | undefined
31
+ ): string;
32
+ };
18
33
  declare const _default: {
19
34
  parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
20
35
  stringify: {
package/utils/json.js CHANGED
@@ -4,17 +4,23 @@ var __importDefault =
4
4
  function (mod) {
5
5
  return mod && mod.__esModule ? mod : { default: mod };
6
6
  };
7
+ var _a, _b;
7
8
  Object.defineProperty(exports, '__esModule', { value: true });
8
- exports.stringify = exports.parse = void 0;
9
+ exports.stringifyAlwaysAsBig =
10
+ exports.parseAlwaysAsBig =
11
+ exports.stringify =
12
+ exports.parse =
13
+ void 0;
9
14
  var json_bigint_1 = __importDefault(require('json-bigint'));
10
- var _a = (0, json_bigint_1.default)({
11
- alwaysParseAsBig: true,
15
+ var json = function (alwaysParseAsBig) {
16
+ return (0, json_bigint_1.default)({
17
+ alwaysParseAsBig: alwaysParseAsBig,
12
18
  useNativeBigInt: true,
13
19
  protoAction: 'preserve',
14
20
  constructorAction: 'preserve',
15
- }),
16
- parse = _a.parse,
17
- stringify = _a.stringify;
18
- exports.parse = parse;
19
- exports.stringify = stringify;
20
- exports.default = { parse: parse, stringify: stringify };
21
+ });
22
+ };
23
+ (exports.parse = ((_a = json(false)), _a.parse)), (exports.stringify = _a.stringify);
24
+ (exports.parseAlwaysAsBig = ((_b = json(true)), _b.parse)),
25
+ (exports.stringifyAlwaysAsBig = _b.stringify);
26
+ exports.default = { parse: exports.parse, stringify: exports.stringify };
@@ -31,7 +31,7 @@ You can also get a key pair from a private key using `getKeyPair(pk: BigNumberis
31
31
 
32
32
  ```javascript
33
33
  const starkKeyPair = ec.genKeyPair();
34
- const starkKeyPub = ec.getStarkKey(starkKeyPair);;
34
+ const starkKeyPub = ec.getStarkKey(starkKeyPair);
35
35
  ```
36
36
 
37
37
  ## Deploy Account Contract
@@ -1,28 +0,0 @@
1
- name: PR check
2
- on:
3
- pull_request:
4
- branches:
5
- - main
6
- - develop
7
-
8
- jobs:
9
- build-and-test:
10
- runs-on: ubuntu-latest
11
-
12
- env:
13
- TEST_PROVIDER_BASE_URL: http://127.0.0.1:5050/
14
- services:
15
- devnet:
16
- image: janek2601/starknet-devnet-patched
17
- ports:
18
- - 5050:5050
19
-
20
- steps:
21
- - uses: actions/checkout@v2
22
- - name: Use Node.js 14
23
- uses: actions/setup-node@v2
24
- with:
25
- node-version: lts/*
26
- - run: npm ci
27
- - run: npm run build --if-present
28
- - run: npm test
@@ -1,69 +0,0 @@
1
- name: Release
2
- on:
3
- push:
4
- branches:
5
- - main
6
- - develop
7
-
8
- jobs:
9
- build-and-test:
10
- runs-on: ubuntu-latest
11
-
12
- env:
13
- TEST_PROVIDER_BASE_URL: http://127.0.0.1:5050/
14
- services:
15
- devnet:
16
- image: janek2601/starknet-devnet-patched
17
- ports:
18
- - 5050:5050
19
-
20
- steps:
21
- - uses: actions/checkout@v2
22
- - name: Use Node.js 14
23
- uses: actions/setup-node@v2
24
- with:
25
- node-version: lts/*
26
- - run: npm ci
27
- - run: npm run build --if-present
28
- - run: npm test
29
-
30
- - uses: actions/upload-artifact@v2
31
- with:
32
- name: build
33
- path: dist
34
-
35
- integration-test:
36
- runs-on: ubuntu-latest
37
-
38
- env:
39
- TEST_PROVIDER_BASE_URL: https://alpha4.starknet.io
40
- TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}
41
- TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
42
- TEST_RPC_URL: ${{ secrets.TEST_RPC_URL }}
43
-
44
- steps:
45
- - uses: actions/checkout@v2
46
- - name: Use Node.js 14
47
- uses: actions/setup-node@v2
48
- with:
49
- node-version: lts/*
50
- - run: npm ci
51
- - run: npm test
52
-
53
- release:
54
- name: Release
55
- runs-on: ubuntu-latest
56
- needs: [build-and-test, integration-test]
57
- steps:
58
- - uses: actions/checkout@v2
59
- - uses: actions/setup-node@v2
60
- with:
61
- node-version: lts/*
62
- - run: npm ci
63
- - uses: actions/download-artifact@v2
64
- with:
65
- name: build
66
- - env:
67
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
69
- run: npx semantic-release
package/.husky/commit-msg DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npx --no-install commitlint --edit "$1"
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npx lint-staged
package/tsconfig.json DELETED
@@ -1,107 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Enable incremental compilation */
7
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
- "lib": [
16
- "es2017",
17
- "es7",
18
- "es6",
19
- "dom"
20
- ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
21
- // "jsx": "preserve", /* Specify what JSX code is generated. */
22
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
23
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
24
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
25
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
26
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
27
- // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
28
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
29
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
30
-
31
- /* Modules */
32
- "module": "commonjs" /* Specify what module code is generated. */,
33
- // "rootDir": "./", /* Specify the root folder within your source files. */
34
- // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
35
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
36
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
37
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
38
- // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
39
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
40
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
41
- // "resolveJsonModule": true, /* Enable importing .json files */
42
- // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
43
-
44
- /* JavaScript Support */
45
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
46
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
47
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
48
-
49
- /* Emit */
50
- "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
51
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
52
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
53
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
54
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
55
- "outDir": "dist" /* Specify an output folder for all emitted files. */,
56
- // "removeComments": true, /* Disable emitting comments. */
57
- // "noEmit": true, /* Disable emitting files from a compilation. */
58
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
59
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
60
- "downlevelIteration": true /* Emit more compliant, but verbose and less performant JavaScript for iteration. */,
61
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
62
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
63
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
64
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
65
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
66
- // "newLine": "crlf", /* Set the newline character for emitting files. */
67
- // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
68
- // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
69
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
70
- // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
71
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
72
-
73
- /* Interop Constraints */
74
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
75
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
76
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
77
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
78
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
79
-
80
- /* Type Checking */
81
- "strict": true /* Enable all strict type-checking options. */,
82
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
83
- // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
84
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
85
- // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
86
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
87
- // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
88
- // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
89
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
90
- // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
91
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
92
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
93
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
94
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
95
- // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
96
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
97
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
98
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
99
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
100
-
101
- /* Completeness */
102
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
103
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
104
- },
105
- "include": ["src/**/*"],
106
- "exclude": ["node_modules"]
107
- }
package/www/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- // This file is not used in compilation. It is here just for a nice editor experience.
3
- "extends": "@tsconfig/docusaurus/tsconfig.json",
4
- "compilerOptions": {
5
- "jsx": "react",
6
- "baseUrl": "."
7
- }
8
- }