starknet 3.15.4 → 3.15.5

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,13 @@
1
+ ## [3.15.5](https://github.com/0xs34n/starknet.js/compare/v3.15.4...v3.15.5) (2022-06-27)
2
+
3
+ ### Bug Fixes
4
+
5
+ - add return statement ([468a0bf](https://github.com/0xs34n/starknet.js/commit/468a0bfbbc1a9c88383ed2ba0f0bc02b0e5e3a9b))
6
+ - don't enforce bigInt ([efef507](https://github.com/0xs34n/starknet.js/commit/efef5071ebceb5247f5f1995d3c1006d422c02ee))
7
+ - **GatewayError:** export from index ([69addd5](https://github.com/0xs34n/starknet.js/commit/69addd5a2eb30816f5e43ffd71e190838ad5a409))
8
+ - **GatewayError:** use ts-custom-error to support "err instanceof GatewayError" ([092abbc](https://github.com/0xs34n/starknet.js/commit/092abbcff5f5270a0be0b79a8e87645637298c56))
9
+ - **test:** error 500 as number instead of bigInt ([b539144](https://github.com/0xs34n/starknet.js/commit/b5391448cf04d93c4d914ad52d850591a423fe42))
10
+
1
11
  ## [3.15.4](https://github.com/0xs34n/starknet.js/compare/v3.15.3...v3.15.4) (2022-06-20)
2
12
 
3
13
  ### 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
  });
@@ -211,7 +211,7 @@ var Provider = /** @class */ (function () {
211
211
  throw new utils_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
212
212
  }
213
213
  if (endpoint === 'estimate_fee') {
214
- return [2 /*return*/, (0, json_1.parse)(textResponse, function (_, v) {
214
+ return [2 /*return*/, (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
215
215
  if (v && typeof v === 'bigint') {
216
216
  return (0, number_1.toBN)(v.toString());
217
217
  }
@@ -1,4 +1,5 @@
1
1
  import { Provider } from './default';
2
2
  export * from './default';
3
+ export { GatewayError } from './utils';
3
4
  export * from './interface';
4
5
  export declare const defaultProvider: Provider;
@@ -14,8 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.defaultProvider = void 0;
17
+ exports.defaultProvider = exports.GatewayError = void 0;
18
18
  var default_1 = require("./default");
19
19
  __exportStar(require("./default"), exports);
20
+ var utils_1 = require("./utils");
21
+ Object.defineProperty(exports, "GatewayError", { enumerable: true, get: function () { return utils_1.GatewayError; } });
20
22
  __exportStar(require("./interface"), exports);
21
23
  exports.defaultProvider = new default_1.Provider();
@@ -1,3 +1,4 @@
1
+ import { CustomError } from 'ts-custom-error';
1
2
  import type { BlockNumber } from '../types';
2
3
  import { BigNumberish } from '../utils/number';
3
4
  /**
@@ -39,7 +40,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
39
40
  * @returns block identifier for API request
40
41
  */
41
42
  export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
42
- export declare class GatewayError extends Error {
43
+ export declare class GatewayError extends CustomError {
43
44
  errorCode: string;
44
45
  constructor(message: string, errorCode: string);
45
46
  }
@@ -16,6 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.GatewayError = exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
19
+ var ts_custom_error_1 = require("ts-custom-error");
19
20
  var number_1 = require("../utils/number");
20
21
  /**
21
22
  *
@@ -100,5 +101,5 @@ var GatewayError = /** @class */ (function (_super) {
100
101
  return _this;
101
102
  }
102
103
  return GatewayError;
103
- }(Error));
104
+ }(ts_custom_error_1.CustomError));
104
105
  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.15.5",
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": {
@@ -344,7 +344,7 @@ var Provider = /** @class */ (function () {
344
344
  if (endpoint === 'estimate_fee') {
345
345
  return [
346
346
  2 /*return*/,
347
- (0, json_1.parse)(textResponse, function (_, v) {
347
+ (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
348
348
  if (v && typeof v === 'bigint') {
349
349
  return (0, number_1.toBN)(v.toString());
350
350
  }
@@ -1,4 +1,5 @@
1
1
  import { Provider } from './default';
2
2
  export * from './default';
3
+ export { GatewayError } from './utils';
3
4
  export * from './interface';
4
5
  export declare const defaultProvider: Provider;
package/provider/index.js CHANGED
@@ -27,8 +27,15 @@ var __exportStar =
27
27
  __createBinding(exports, m, p);
28
28
  };
29
29
  Object.defineProperty(exports, '__esModule', { value: true });
30
- exports.defaultProvider = void 0;
30
+ exports.defaultProvider = exports.GatewayError = void 0;
31
31
  var default_1 = require('./default');
32
32
  __exportStar(require('./default'), exports);
33
+ var utils_1 = require('./utils');
34
+ Object.defineProperty(exports, 'GatewayError', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return utils_1.GatewayError;
38
+ },
39
+ });
33
40
  __exportStar(require('./interface'), exports);
34
41
  exports.defaultProvider = new default_1.Provider();
@@ -1,3 +1,5 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+
1
3
  import type { BlockNumber } from '../types';
2
4
  import { BigNumberish } from '../utils/number';
3
5
  /**
@@ -41,7 +43,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
41
43
  * @returns block identifier for API request
42
44
  */
43
45
  export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
44
- export declare class GatewayError extends Error {
46
+ export declare class GatewayError extends CustomError {
45
47
  errorCode: string;
46
48
  constructor(message: string, errorCode: string);
47
49
  }
package/provider/utils.js CHANGED
@@ -31,6 +31,7 @@ exports.GatewayError =
31
31
  exports.txIdentifier =
32
32
  exports.formatHash =
33
33
  void 0;
34
+ var ts_custom_error_1 = require('ts-custom-error');
34
35
  var number_1 = require('../utils/number');
35
36
  /**
36
37
  *
@@ -116,5 +117,5 @@ var GatewayError = /** @class */ (function (_super) {
116
117
  return _this;
117
118
  }
118
119
  return GatewayError;
119
- })(Error);
120
+ })(ts_custom_error_1.CustomError);
120
121
  exports.GatewayError = GatewayError;
@@ -20,7 +20,7 @@ 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
26
  import { ProviderInterface } from './interface';
@@ -169,7 +169,7 @@ export class Provider implements ProviderInterface {
169
169
  }
170
170
 
171
171
  if (endpoint === 'estimate_fee') {
172
- return parse(textResponse, (_, v) => {
172
+ return parseAlwaysAsBig(textResponse, (_, v) => {
173
173
  if (v && typeof v === 'bigint') {
174
174
  return toBN(v.toString());
175
175
  }
@@ -1,6 +1,7 @@
1
1
  import { Provider } from './default';
2
2
 
3
3
  export * from './default';
4
+ export { GatewayError } from './utils';
4
5
  export * from './interface';
5
6
 
6
7
  export const defaultProvider = new Provider();
@@ -1,3 +1,5 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+
1
3
  import type { BlockNumber } from '../types';
2
4
  import { BigNumberish, toBN, toHex } from '../utils/number';
3
5
 
@@ -83,7 +85,7 @@ export function getFormattedBlockIdentifier(blockIdentifier: BlockIdentifier = n
83
85
  return `blockHash=${toHex(toBN(blockIdentifierObject.data))}`;
84
86
  }
85
87
 
86
- export class GatewayError extends Error {
88
+ export class GatewayError extends CustomError {
87
89
  constructor(message: string, public errorCode: string) {
88
90
  super(message);
89
91
  }
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