starknet 3.12.0 → 3.12.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/.releaserc CHANGED
@@ -24,5 +24,5 @@
24
24
  ],
25
25
  "@semantic-release/github"
26
26
  ],
27
- "repositoryUrl": "https://github.com/seanjameshan/starknet.js"
27
+ "repositoryUrl": "https://github.com/0xs34n/starknet.js"
28
28
  }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [3.12.3](https://github.com/0xs34n/starknet.js/compare/v3.12.2...v3.12.3) (2022-05-30)
2
+
3
+ ### Bug Fixes
4
+
5
+ - remove superstruct ([6f13cf0](https://github.com/0xs34n/starknet.js/commit/6f13cf0ec740e715fcbdacf846cd9bcd653c1399))
6
+
7
+ ## [3.12.2](https://github.com/0xs34n/starknet.js/compare/v3.12.1...v3.12.2) (2022-05-30)
8
+
9
+ ### Bug Fixes
10
+
11
+ - allow starknet.js in service workers ([7a500d1](https://github.com/0xs34n/starknet.js/commit/7a500d198cffed43f98a669edac2dbb215884a3b))
12
+ - updated powered by starknet list ([aa36463](https://github.com/0xs34n/starknet.js/commit/aa36463e1adb281f79bf8462b2f0063801457782))
13
+
14
+ ## [3.12.1](https://github.com/0xs34n/starknet.js/compare/v3.12.0...v3.12.1) (2022-05-24)
15
+
16
+ ### Bug Fixes
17
+
18
+ - update repo url ([c1312c0](https://github.com/0xs34n/starknet.js/commit/c1312c0e00e3387a49d1d7edc33e584687d607ea))
19
+
1
20
  # [3.12.0](https://github.com/seanjameshan/starknet.js/compare/v3.11.0...v3.12.0) (2022-05-24)
2
21
 
3
22
  ### Bug Fixes
package/README.md CHANGED
@@ -57,8 +57,10 @@ Guides can be found [here](https://www.starknetjs.com/guides/intro)
57
57
  ## 🚀 Powered by Starknet.js
58
58
 
59
59
  - [Argent X - the first StarkNet wallet](https://github.com/argentlabs/argent-x)
60
+ - [Braavos - your new wallet on top of StarkNet](https://chrome.google.com/webstore/detail/braavos-wallet/jnlgamecbpmbajjfhmmmlhejkemejdma)
60
61
  - [React + Starknet.js boilerplate](https://github.com/fracek/starknet-react-example)
61
62
  - [AMM Demo](https://www.starknetswap.com/)
63
+ - [mySwap - the first DeFi app to launch on StarkNet](myswap.xyz)
62
64
 
63
65
  ## ✏️ Contributing
64
66
 
@@ -1,9 +1,28 @@
1
- import axios from 'axios';
2
- import * as AxiosLogger from 'axios-logger';
1
+ /* eslint-disable no-console */
2
+ import { register } from 'fetch-intercept';
3
3
 
4
4
  jest.setTimeout(50 * 60 * 1000);
5
5
 
6
6
  if (process.env.DEBUG === 'true') {
7
- axios.interceptors.request.use(AxiosLogger.requestLogger, AxiosLogger.errorLogger);
8
- axios.interceptors.response.use(AxiosLogger.responseLogger, AxiosLogger.errorLogger);
7
+ register({
8
+ request(url, config) {
9
+ console.log('[fetch.request]', [url, config]);
10
+ return [url, config];
11
+ },
12
+
13
+ requestError(error) {
14
+ console.log('[fetch.requestError]', error);
15
+ return Promise.reject(error);
16
+ },
17
+
18
+ response(response) {
19
+ console.log('[fetch.response]', response);
20
+ return response;
21
+ },
22
+
23
+ responseError(error) {
24
+ console.log('[fetch.responseError]', error);
25
+ return Promise.reject(error);
26
+ },
27
+ });
9
28
  }
@@ -67,7 +67,7 @@ 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 axios_1 = __importDefault(require("axios"));
70
+ var cross_fetch_1 = __importDefault(require("cross-fetch"));
71
71
  var url_join_1 = __importDefault(require("url-join"));
72
72
  var constants_1 = require("../constants");
73
73
  var hash_1 = require("../utils/hash");
@@ -164,9 +164,8 @@ var Provider = /** @class */ (function () {
164
164
  };
165
165
  // typesafe fetch
166
166
  Provider.prototype.fetchEndpoint = function (endpoint) {
167
- var _a;
168
167
  // typescript type magiuc to create a nice fitting function interface
169
- var _b = []; // when both query and request are needed, we cant omit anything
168
+ var _a = []; // when both query and request are needed, we cant omit anything
170
169
  for (
171
170
  // typescript type magiuc to create a nice fitting function interface
172
171
  var _i = 1 // when both query and request are needed, we cant omit anything
@@ -178,50 +177,35 @@ var Provider = /** @class */ (function () {
178
177
  _i++ // when both query and request are needed, we cant omit anything
179
178
  ) {
180
179
  // typescript type magiuc to create a nice fitting function interface
181
- _b[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
180
+ _a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
182
181
  }
183
182
  // typescript type magiuc to create a nice fitting function interface
184
- var _c = __read(_b, 2), query = _c[0], request = _c[1]; // when both query and request are needed, we cant omit anything
183
+ var _b = __read(_a, 2), query = _b[0], request = _b[1]; // when both query and request are needed, we cant omit anything
185
184
  return __awaiter(this, void 0, void 0, function () {
186
- var baseUrl, method, queryString, headers, data, error_1, data;
187
- return __generator(this, function (_d) {
188
- switch (_d.label) {
189
- case 0:
190
- baseUrl = this.getFetchUrl(endpoint);
191
- method = this.getFetchMethod(endpoint);
192
- queryString = this.getQueryString(query);
193
- headers = this.getHeaders(method);
194
- _d.label = 1;
195
- case 1:
196
- _d.trys.push([1, 3, , 4]);
197
- return [4 /*yield*/, axios_1.default.request({
198
- method: method,
199
- transformResponse: endpoint === 'estimate_fee'
200
- ? function (res) {
201
- return (0, json_1.parse)(res, function (_, v) {
202
- if (v && typeof v === 'bigint') {
203
- return (0, number_1.toBN)(v.toString());
204
- }
205
- return v;
206
- });
207
- }
208
- : axios_1.default.defaults.transformResponse,
209
- url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
210
- data: (0, json_1.stringify)(request),
211
- headers: headers,
212
- })];
213
- case 2:
214
- data = (_d.sent()).data;
215
- return [2 /*return*/, data];
216
- case 3:
217
- error_1 = _d.sent();
218
- data = (_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.data;
219
- if (data === null || data === void 0 ? void 0 : data.message) {
220
- throw new Error(data.code + ": " + data.message);
185
+ var baseUrl, method, queryString, headers, url;
186
+ return __generator(this, function (_c) {
187
+ baseUrl = this.getFetchUrl(endpoint);
188
+ method = this.getFetchMethod(endpoint);
189
+ queryString = this.getQueryString(query);
190
+ headers = this.getHeaders(method);
191
+ url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
192
+ return [2 /*return*/, (0, cross_fetch_1.default)(url, {
193
+ method: method,
194
+ body: (0, json_1.stringify)(request),
195
+ headers: headers,
196
+ })
197
+ .then(function (res) { return res.text(); })
198
+ .then(function (res) {
199
+ if (endpoint === 'estimate_fee') {
200
+ return (0, json_1.parse)(res, function (_, v) {
201
+ if (v && typeof v === 'bigint') {
202
+ return (0, number_1.toBN)(v.toString());
203
+ }
204
+ return v;
205
+ });
221
206
  }
222
- throw error_1;
223
- case 4: return [2 /*return*/];
224
- }
207
+ return (0, json_1.parse)(res);
208
+ })];
225
209
  });
226
210
  });
227
211
  };
@@ -35,24 +35,7 @@ export declare const getTypeHash: (typedData: TypedData, type: string) => string
35
35
  * @param {string} type
36
36
  * @param {Record<string, any>} data
37
37
  */
38
- export declare const encodeData: <T extends {
39
- types: {
40
- StarkNetDomain: {
41
- type: string;
42
- name: string;
43
- }[];
44
- } & Record<string, {
45
- type: string;
46
- name: string;
47
- }[]>;
48
- primaryType: string;
49
- domain: {
50
- version?: string | undefined;
51
- chainId?: string | number | undefined;
52
- name?: string | undefined;
53
- };
54
- message: Record<string, unknown>;
55
- }>(typedData: T, type: string, data: T["message"]) => string[][];
38
+ export declare const encodeData: <T extends TypedData>(typedData: T, type: string, data: T["message"]) => string[][];
56
39
  /**
57
40
  * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
58
41
  * types are automatically encoded.
@@ -62,24 +45,7 @@ export declare const encodeData: <T extends {
62
45
  * @param {Record<string, any>} data
63
46
  * @return {Buffer}
64
47
  */
65
- export declare const getStructHash: <T extends {
66
- types: {
67
- StarkNetDomain: {
68
- type: string;
69
- name: string;
70
- }[];
71
- } & Record<string, {
72
- type: string;
73
- name: string;
74
- }[]>;
75
- primaryType: string;
76
- domain: {
77
- version?: string | undefined;
78
- chainId?: string | number | undefined;
79
- name?: string | undefined;
80
- };
81
- message: Record<string, unknown>;
82
- }>(typedData: T, type: string, data: T["message"]) => string;
48
+ export declare const getStructHash: <T extends TypedData>(typedData: T, type: string, data: T["message"]) => string;
83
49
  /**
84
50
  * Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
85
51
  * with Keccak256.
@@ -1,82 +1,27 @@
1
- import { Infer } from 'superstruct';
2
- export declare const ATOMIC_TYPES: string[];
3
- /**
4
- * Checks if a type is valid with the given `typedData`. The following types are valid:
5
- * - Atomic types: felt, felt*
6
- * - Reference types: struct type (e.g. SomeStruct)
7
- *
8
- * @param {Record<string, unknown>} types
9
- * @param {string} type
10
- * @return {boolean}
11
- */
12
- export declare const isValidType: (types: Record<string, unknown>, type: string) => boolean;
13
- export declare const STARKNET_TYPE: import("superstruct").Struct<{
14
- type: string;
15
- name: string;
16
- }, {
17
- name: import("superstruct").Struct<string, null>;
18
- type: import("superstruct").Struct<string, null>;
19
- }>;
20
1
  /**
21
2
  * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
22
3
  *
23
4
  * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
24
5
  * standard.
25
6
  */
26
- export declare type StarkNetType = Infer<typeof STARKNET_TYPE>;
27
- export declare const STARKNET_DOMAIN_TYPE: import("superstruct").Struct<{
28
- version?: string | undefined;
29
- chainId?: string | number | undefined;
30
- name?: string | undefined;
31
- }, {
32
- name: import("superstruct").Struct<string | undefined, null>;
33
- version: import("superstruct").Struct<string | undefined, null>;
34
- chainId: import("superstruct").Struct<string | number | undefined, null>;
35
- }>;
7
+ export interface StarkNetType {
8
+ name: string;
9
+ type: 'felt' | 'felt*' | string;
10
+ }
36
11
  /**
37
12
  * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
38
13
  */
39
- export declare type StarkNetDomain = Infer<typeof STARKNET_DOMAIN_TYPE>;
40
- export declare const STARKNET_TYPED_DATA_TYPE: import("superstruct").Struct<{
41
- types: {
42
- StarkNetDomain: {
43
- type: string;
44
- name: string;
45
- }[];
46
- } & Record<string, {
47
- type: string;
48
- name: string;
49
- }[]>;
50
- primaryType: string;
51
- domain: {
52
- version?: string | undefined;
53
- chainId?: string | number | undefined;
54
- name?: string | undefined;
55
- };
56
- message: Record<string, unknown>;
57
- }, {
58
- types: import("superstruct").Struct<{
59
- StarkNetDomain: {
60
- type: string;
61
- name: string;
62
- }[];
63
- } & Record<string, {
64
- type: string;
65
- name: string;
66
- }[]>, null>;
67
- primaryType: import("superstruct").Struct<string, null>;
68
- domain: import("superstruct").Struct<{
69
- version?: string | undefined;
70
- chainId?: string | number | undefined;
71
- name?: string | undefined;
72
- }, {
73
- name: import("superstruct").Struct<string | undefined, null>;
74
- version: import("superstruct").Struct<string | undefined, null>;
75
- chainId: import("superstruct").Struct<string | number | undefined, null>;
76
- }>;
77
- message: import("superstruct").Struct<Record<string, unknown>, null>;
78
- }>;
14
+ export interface StarkNetDomain extends Record<string, unknown> {
15
+ name?: string;
16
+ version?: string;
17
+ chainId?: string | number;
18
+ }
79
19
  /**
80
20
  * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
81
21
  */
82
- export declare type TypedData = Infer<typeof STARKNET_TYPED_DATA_TYPE>;
22
+ export interface TypedData {
23
+ types: Record<string, StarkNetType[]>;
24
+ primaryType: string;
25
+ domain: StarkNetDomain;
26
+ message: Record<string, unknown>;
27
+ }
@@ -1,47 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STARKNET_TYPED_DATA_TYPE = exports.STARKNET_DOMAIN_TYPE = exports.STARKNET_TYPE = exports.isValidType = exports.ATOMIC_TYPES = void 0;
4
- var superstruct_1 = require("superstruct");
5
- exports.ATOMIC_TYPES = ['felt', 'felt*'];
6
- // Source: https://github.com/Mrtenz/eip-712/blob/master/src/eip-712.ts
7
- // and modified to support starknet types
8
- /**
9
- * Checks if a type is valid with the given `typedData`. The following types are valid:
10
- * - Atomic types: felt, felt*
11
- * - Reference types: struct type (e.g. SomeStruct)
12
- *
13
- * @param {Record<string, unknown>} types
14
- * @param {string} type
15
- * @return {boolean}
16
- */
17
- var isValidType = function (types, type) {
18
- if (exports.ATOMIC_TYPES.includes(type)) {
19
- return true;
20
- }
21
- if (types[type]) {
22
- return true;
23
- }
24
- return false;
25
- };
26
- exports.isValidType = isValidType;
27
- var TYPE = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Type', function (type, context) {
28
- return (0, exports.isValidType)(context.branch[0].types, type);
29
- });
30
- exports.STARKNET_TYPE = (0, superstruct_1.object)({
31
- name: (0, superstruct_1.string)(),
32
- type: TYPE,
33
- });
34
- exports.STARKNET_DOMAIN_TYPE = (0, superstruct_1.object)({
35
- name: (0, superstruct_1.optional)((0, superstruct_1.string)()),
36
- version: (0, superstruct_1.optional)((0, superstruct_1.string)()),
37
- chainId: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
38
- });
39
- exports.STARKNET_TYPED_DATA_TYPE = (0, superstruct_1.object)({
40
- types: (0, superstruct_1.intersection)([
41
- (0, superstruct_1.type)({ StarkNetDomain: (0, superstruct_1.array)(exports.STARKNET_TYPE) }),
42
- (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.array)(exports.STARKNET_TYPE)),
43
- ]),
44
- primaryType: (0, superstruct_1.string)(),
45
- domain: exports.STARKNET_DOMAIN_TYPE,
46
- message: (0, superstruct_1.object)(),
47
- });
@@ -1,24 +1,8 @@
1
+ import { TypedData } from './types';
1
2
  /**
2
3
  * Validates that `data` matches the EIP-712 JSON schema.
3
4
  *
4
5
  * @param {any} data
5
6
  * @return {boolean}
6
7
  */
7
- export declare const validateTypedData: (data: unknown) => data is {
8
- types: {
9
- StarkNetDomain: {
10
- type: string;
11
- name: string;
12
- }[];
13
- } & Record<string, {
14
- type: string;
15
- name: string;
16
- }[]>;
17
- primaryType: string;
18
- domain: {
19
- version?: string | undefined;
20
- chainId?: string | number | undefined;
21
- name?: string | undefined;
22
- };
23
- message: Record<string, unknown>;
24
- };
8
+ export declare const validateTypedData: (data: unknown) => data is TypedData;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateTypedData = void 0;
4
- var superstruct_1 = require("superstruct");
5
- var types_1 = require("./types");
6
4
  /**
7
5
  * Validates that `data` matches the EIP-712 JSON schema.
8
6
  *
@@ -10,6 +8,9 @@ var types_1 = require("./types");
10
8
  * @return {boolean}
11
9
  */
12
10
  var validateTypedData = function (data) {
13
- return (0, superstruct_1.is)(data, types_1.STARKNET_TYPED_DATA_TYPE);
11
+ var typedData = data;
12
+ // Validate that the data matches the EIP-712 JSON schema
13
+ var valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
14
+ return valid;
14
15
  };
15
16
  exports.validateTypedData = validateTypedData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.12.0",
3
+ "version": "3.12.3",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,7 +44,6 @@
44
44
  "@types/url-join": "^4.0.1",
45
45
  "@typescript-eslint/eslint-plugin": "^5.0.0",
46
46
  "@typescript-eslint/parser": "^5.0.0",
47
- "axios-logger": "^2.6.0",
48
47
  "eslint": "^7.32.0",
49
48
  "eslint-config-airbnb-base": "^14.2.1",
50
49
  "eslint-config-airbnb-typescript": "^14.0.1",
@@ -58,19 +57,20 @@
58
57
  "prettier": "^2.4.1",
59
58
  "prettier-plugin-import-sort": "^0.0.7",
60
59
  "typedoc": "^0.22.6",
61
- "typescript": "^4.4.4"
60
+ "typescript": "^4.4.4",
61
+ "whatwg-fetch": "^3.6.2"
62
62
  },
63
63
  "dependencies": {
64
64
  "@ethersproject/bytes": "^5.6.1",
65
- "axios": "^0.23.0",
66
65
  "bn.js": "^5.2.0",
66
+ "cross-fetch": "^3.1.5",
67
67
  "elliptic": "^6.5.4",
68
68
  "ethereum-cryptography": "^0.2.0",
69
+ "fetch-intercept": "^2.4.0",
69
70
  "hash.js": "^1.1.7",
70
71
  "json-bigint": "^1.0.0",
71
72
  "minimalistic-assert": "^1.0.1",
72
73
  "pako": "^2.0.4",
73
- "superstruct": "^0.15.3",
74
74
  "url-join": "^4.0.1"
75
75
  },
76
76
  "lint-staged": {
@@ -173,7 +173,7 @@ var __importDefault =
173
173
  };
174
174
  Object.defineProperty(exports, '__esModule', { value: true });
175
175
  exports.Provider = void 0;
176
- var axios_1 = __importDefault(require('axios'));
176
+ var cross_fetch_1 = __importDefault(require('cross-fetch'));
177
177
  var url_join_1 = __importDefault(require('url-join'));
178
178
  var constants_1 = require('../constants');
179
179
  var hash_1 = require('../utils/hash');
@@ -281,9 +281,8 @@ var Provider = /** @class */ (function () {
281
281
  };
282
282
  // typesafe fetch
283
283
  Provider.prototype.fetchEndpoint = function (endpoint) {
284
- var _a;
285
284
  // typescript type magiuc to create a nice fitting function interface
286
- var _b = []; // when both query and request are needed, we cant omit anything
285
+ var _a = []; // when both query and request are needed, we cant omit anything
287
286
  for (
288
287
  // typescript type magiuc to create a nice fitting function interface
289
288
  var _i = 1; // when both query and request are needed, we cant omit anything
@@ -293,61 +292,42 @@ var Provider = /** @class */ (function () {
293
292
  _i++ // when both query and request are needed, we cant omit anything
294
293
  ) {
295
294
  // typescript type magiuc to create a nice fitting function interface
296
- _b[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
295
+ _a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
297
296
  }
298
297
  // typescript type magiuc to create a nice fitting function interface
299
- var _c = __read(_b, 2),
300
- query = _c[0],
301
- request = _c[1]; // when both query and request are needed, we cant omit anything
298
+ var _b = __read(_a, 2),
299
+ query = _b[0],
300
+ request = _b[1]; // when both query and request are needed, we cant omit anything
302
301
  return __awaiter(this, void 0, void 0, function () {
303
- var baseUrl, method, queryString, headers, data, error_1, data;
304
- return __generator(this, function (_d) {
305
- switch (_d.label) {
306
- case 0:
307
- baseUrl = this.getFetchUrl(endpoint);
308
- method = this.getFetchMethod(endpoint);
309
- queryString = this.getQueryString(query);
310
- headers = this.getHeaders(method);
311
- _d.label = 1;
312
- case 1:
313
- _d.trys.push([1, 3, , 4]);
314
- return [
315
- 4 /*yield*/,
316
- axios_1.default.request({
317
- method: method,
318
- transformResponse:
319
- endpoint === 'estimate_fee'
320
- ? function (res) {
321
- return (0, json_1.parse)(res, function (_, v) {
322
- if (v && typeof v === 'bigint') {
323
- return (0, number_1.toBN)(v.toString());
324
- }
325
- return v;
326
- });
327
- }
328
- : axios_1.default.defaults.transformResponse,
329
- url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
330
- data: (0, json_1.stringify)(request),
331
- headers: headers,
332
- }),
333
- ];
334
- case 2:
335
- data = _d.sent().data;
336
- return [2 /*return*/, data];
337
- case 3:
338
- error_1 = _d.sent();
339
- data =
340
- (_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null ||
341
- _a === void 0
342
- ? void 0
343
- : _a.data;
344
- if (data === null || data === void 0 ? void 0 : data.message) {
345
- throw new Error(data.code + ': ' + data.message);
346
- }
347
- throw error_1;
348
- case 4:
349
- return [2 /*return*/];
350
- }
302
+ var baseUrl, method, queryString, headers, url;
303
+ return __generator(this, function (_c) {
304
+ baseUrl = this.getFetchUrl(endpoint);
305
+ method = this.getFetchMethod(endpoint);
306
+ queryString = this.getQueryString(query);
307
+ headers = this.getHeaders(method);
308
+ url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
309
+ return [
310
+ 2 /*return*/,
311
+ (0, cross_fetch_1.default)(url, {
312
+ method: method,
313
+ body: (0, json_1.stringify)(request),
314
+ headers: headers,
315
+ })
316
+ .then(function (res) {
317
+ return res.text();
318
+ })
319
+ .then(function (res) {
320
+ if (endpoint === 'estimate_fee') {
321
+ return (0, json_1.parse)(res, function (_, v) {
322
+ if (v && typeof v === 'bigint') {
323
+ return (0, number_1.toBN)(v.toString());
324
+ }
325
+ return v;
326
+ });
327
+ }
328
+ return (0, json_1.parse)(res);
329
+ }),
330
+ ];
351
331
  });
352
332
  });
353
333
  };
@@ -1,4 +1,4 @@
1
- import axios, { AxiosRequestHeaders } from 'axios';
1
+ import fetch from 'cross-fetch';
2
2
  import urljoin from 'url-join';
3
3
 
4
4
  import { StarknetChainId } from '../constants';
@@ -10,7 +10,6 @@ import {
10
10
  CompiledContract,
11
11
  DeployContractPayload,
12
12
  Endpoints,
13
- EstimateFeeResponse,
14
13
  GetBlockResponse,
15
14
  GetCodeResponse,
16
15
  GetContractAddressesResponse,
@@ -125,7 +124,7 @@ export class Provider implements ProviderInterface {
125
124
  return `?${queryString}`;
126
125
  }
127
126
 
128
- private getHeaders(method: 'POST' | 'GET'): AxiosRequestHeaders | undefined {
127
+ private getHeaders(method: 'POST' | 'GET'): Record<string, string> | undefined {
129
128
  if (method === 'POST') {
130
129
  return {
131
130
  'Content-Type': 'application/json',
@@ -150,33 +149,25 @@ export class Provider implements ProviderInterface {
150
149
  const method = this.getFetchMethod(endpoint);
151
150
  const queryString = this.getQueryString(query);
152
151
  const headers = this.getHeaders(method);
153
-
154
- try {
155
- const { data } = await axios.request<Endpoints[T]['RESPONSE']>({
156
- method,
157
- transformResponse:
158
- endpoint === 'estimate_fee'
159
- ? (res): EstimateFeeResponse => {
160
- return parse(res, (_, v) => {
161
- if (v && typeof v === 'bigint') {
162
- return toBN(v.toString());
163
- }
164
- return v;
165
- });
166
- }
167
- : axios.defaults.transformResponse,
168
- url: urljoin(baseUrl, endpoint, queryString),
169
- data: stringify(request),
170
- headers,
152
+ const url = urljoin(baseUrl, endpoint, queryString);
153
+
154
+ return fetch(url, {
155
+ method,
156
+ body: stringify(request),
157
+ headers,
158
+ })
159
+ .then((res) => res.text())
160
+ .then((res) => {
161
+ if (endpoint === 'estimate_fee') {
162
+ return parse(res, (_, v) => {
163
+ if (v && typeof v === 'bigint') {
164
+ return toBN(v.toString());
165
+ }
166
+ return v;
167
+ });
168
+ }
169
+ return parse(res) as Endpoints[T]['RESPONSE'];
171
170
  });
172
- return data;
173
- } catch (error: any) {
174
- const data = error?.response?.data;
175
- if (data?.message) {
176
- throw new Error(`${data.code}: ${data.message}`);
177
- }
178
- throw error;
179
- }
180
171
  }
181
172
 
182
173
  /**
@@ -1,82 +1,29 @@
1
- import {
2
- Infer,
3
- array,
4
- intersection,
5
- number,
6
- object,
7
- optional,
8
- record,
9
- refine,
10
- string,
11
- type as t,
12
- union,
13
- } from 'superstruct';
14
-
15
- export const ATOMIC_TYPES = ['felt', 'felt*'];
16
-
17
- // Source: https://github.com/Mrtenz/eip-712/blob/master/src/eip-712.ts
18
- // and modified to support starknet types
19
-
20
- /**
21
- * Checks if a type is valid with the given `typedData`. The following types are valid:
22
- * - Atomic types: felt, felt*
23
- * - Reference types: struct type (e.g. SomeStruct)
24
- *
25
- * @param {Record<string, unknown>} types
26
- * @param {string} type
27
- * @return {boolean}
28
- */
29
- export const isValidType = (types: Record<string, unknown>, type: string): boolean => {
30
- if (ATOMIC_TYPES.includes(type as string)) {
31
- return true;
32
- }
33
-
34
- if (types[type]) {
35
- return true;
36
- }
37
-
38
- return false;
39
- };
40
-
41
- const TYPE = refine(string(), 'Type', (type, context) => {
42
- return isValidType(context.branch[0].types, type);
43
- });
44
-
45
- export const STARKNET_TYPE = object({
46
- name: string(),
47
- type: TYPE,
48
- });
49
-
50
1
  /**
51
2
  * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
52
3
  *
53
4
  * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
54
5
  * standard.
55
6
  */
56
- export type StarkNetType = Infer<typeof STARKNET_TYPE>;
57
-
58
- export const STARKNET_DOMAIN_TYPE = object({
59
- name: optional(string()),
60
- version: optional(string()),
61
- chainId: optional(union([string(), number()])),
62
- });
7
+ export interface StarkNetType {
8
+ name: string;
9
+ type: 'felt' | 'felt*' | string;
10
+ }
63
11
 
64
12
  /**
65
13
  * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
66
14
  */
67
- export type StarkNetDomain = Infer<typeof STARKNET_DOMAIN_TYPE>;
68
-
69
- export const STARKNET_TYPED_DATA_TYPE = object({
70
- types: intersection([
71
- t({ StarkNetDomain: array(STARKNET_TYPE) }),
72
- record(string(), array(STARKNET_TYPE)),
73
- ]),
74
- primaryType: string(),
75
- domain: STARKNET_DOMAIN_TYPE,
76
- message: object(),
77
- });
15
+ export interface StarkNetDomain extends Record<string, unknown> {
16
+ name?: string;
17
+ version?: string;
18
+ chainId?: string | number;
19
+ }
78
20
 
79
21
  /**
80
22
  * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
81
23
  */
82
- export type TypedData = Infer<typeof STARKNET_TYPED_DATA_TYPE>;
24
+ export interface TypedData {
25
+ types: Record<string, StarkNetType[]>;
26
+ primaryType: string;
27
+ domain: StarkNetDomain;
28
+ message: Record<string, unknown>;
29
+ }
@@ -1,6 +1,4 @@
1
- import { is } from 'superstruct';
2
-
3
- import { STARKNET_TYPED_DATA_TYPE, TypedData } from './types';
1
+ import { TypedData } from './types';
4
2
 
5
3
  /**
6
4
  * Validates that `data` matches the EIP-712 JSON schema.
@@ -9,5 +7,10 @@ import { STARKNET_TYPED_DATA_TYPE, TypedData } from './types';
9
7
  * @return {boolean}
10
8
  */
11
9
  export const validateTypedData = (data: unknown): data is TypedData => {
12
- return is(data, STARKNET_TYPED_DATA_TYPE);
10
+ const typedData = data as TypedData;
11
+
12
+ // Validate that the data matches the EIP-712 JSON schema
13
+ const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
14
+
15
+ return valid;
13
16
  };
@@ -39,29 +39,7 @@ export declare const getTypeHash: (typedData: TypedData, type: string) => string
39
39
  * @param {string} type
40
40
  * @param {Record<string, any>} data
41
41
  */
42
- export declare const encodeData: <
43
- T extends {
44
- types: {
45
- StarkNetDomain: {
46
- type: string;
47
- name: string;
48
- }[];
49
- } & Record<
50
- string,
51
- {
52
- type: string;
53
- name: string;
54
- }[]
55
- >;
56
- primaryType: string;
57
- domain: {
58
- version?: string | undefined;
59
- chainId?: string | number | undefined;
60
- name?: string | undefined;
61
- };
62
- message: Record<string, unknown>;
63
- }
64
- >(
42
+ export declare const encodeData: <T extends TypedData>(
65
43
  typedData: T,
66
44
  type: string,
67
45
  data: T['message']
@@ -75,29 +53,7 @@ export declare const encodeData: <
75
53
  * @param {Record<string, any>} data
76
54
  * @return {Buffer}
77
55
  */
78
- export declare const getStructHash: <
79
- T extends {
80
- types: {
81
- StarkNetDomain: {
82
- type: string;
83
- name: string;
84
- }[];
85
- } & Record<
86
- string,
87
- {
88
- type: string;
89
- name: string;
90
- }[]
91
- >;
92
- primaryType: string;
93
- domain: {
94
- version?: string | undefined;
95
- chainId?: string | number | undefined;
96
- name?: string | undefined;
97
- };
98
- message: Record<string, unknown>;
99
- }
100
- >(
56
+ export declare const getStructHash: <T extends TypedData>(
101
57
  typedData: T,
102
58
  type: string,
103
59
  data: T['message']
@@ -1,103 +1,27 @@
1
- import { Infer } from 'superstruct';
2
- export declare const ATOMIC_TYPES: string[];
3
- /**
4
- * Checks if a type is valid with the given `typedData`. The following types are valid:
5
- * - Atomic types: felt, felt*
6
- * - Reference types: struct type (e.g. SomeStruct)
7
- *
8
- * @param {Record<string, unknown>} types
9
- * @param {string} type
10
- * @return {boolean}
11
- */
12
- export declare const isValidType: (types: Record<string, unknown>, type: string) => boolean;
13
- export declare const STARKNET_TYPE: import('superstruct').Struct<
14
- {
15
- type: string;
16
- name: string;
17
- },
18
- {
19
- name: import('superstruct').Struct<string, null>;
20
- type: import('superstruct').Struct<string, null>;
21
- }
22
- >;
23
1
  /**
24
2
  * A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types.
25
3
  *
26
4
  * Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
27
5
  * standard.
28
6
  */
29
- export declare type StarkNetType = Infer<typeof STARKNET_TYPE>;
30
- export declare const STARKNET_DOMAIN_TYPE: import('superstruct').Struct<
31
- {
32
- version?: string | undefined;
33
- chainId?: string | number | undefined;
34
- name?: string | undefined;
35
- },
36
- {
37
- name: import('superstruct').Struct<string | undefined, null>;
38
- version: import('superstruct').Struct<string | undefined, null>;
39
- chainId: import('superstruct').Struct<string | number | undefined, null>;
40
- }
41
- >;
7
+ export interface StarkNetType {
8
+ name: string;
9
+ type: 'felt' | 'felt*' | string;
10
+ }
42
11
  /**
43
12
  * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
44
13
  */
45
- export declare type StarkNetDomain = Infer<typeof STARKNET_DOMAIN_TYPE>;
46
- export declare const STARKNET_TYPED_DATA_TYPE: import('superstruct').Struct<
47
- {
48
- types: {
49
- StarkNetDomain: {
50
- type: string;
51
- name: string;
52
- }[];
53
- } & Record<
54
- string,
55
- {
56
- type: string;
57
- name: string;
58
- }[]
59
- >;
60
- primaryType: string;
61
- domain: {
62
- version?: string | undefined;
63
- chainId?: string | number | undefined;
64
- name?: string | undefined;
65
- };
66
- message: Record<string, unknown>;
67
- },
68
- {
69
- types: import('superstruct').Struct<
70
- {
71
- StarkNetDomain: {
72
- type: string;
73
- name: string;
74
- }[];
75
- } & Record<
76
- string,
77
- {
78
- type: string;
79
- name: string;
80
- }[]
81
- >,
82
- null
83
- >;
84
- primaryType: import('superstruct').Struct<string, null>;
85
- domain: import('superstruct').Struct<
86
- {
87
- version?: string | undefined;
88
- chainId?: string | number | undefined;
89
- name?: string | undefined;
90
- },
91
- {
92
- name: import('superstruct').Struct<string | undefined, null>;
93
- version: import('superstruct').Struct<string | undefined, null>;
94
- chainId: import('superstruct').Struct<string | number | undefined, null>;
95
- }
96
- >;
97
- message: import('superstruct').Struct<Record<string, unknown>, null>;
98
- }
99
- >;
14
+ export interface StarkNetDomain extends Record<string, unknown> {
15
+ name?: string;
16
+ version?: string;
17
+ chainId?: string | number;
18
+ }
100
19
  /**
101
20
  * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
102
21
  */
103
- export declare type TypedData = Infer<typeof STARKNET_TYPED_DATA_TYPE>;
22
+ export interface TypedData {
23
+ types: Record<string, StarkNetType[]>;
24
+ primaryType: string;
25
+ domain: StarkNetDomain;
26
+ message: Record<string, unknown>;
27
+ }
@@ -1,57 +1,2 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.STARKNET_TYPED_DATA_TYPE =
4
- exports.STARKNET_DOMAIN_TYPE =
5
- exports.STARKNET_TYPE =
6
- exports.isValidType =
7
- exports.ATOMIC_TYPES =
8
- void 0;
9
- var superstruct_1 = require('superstruct');
10
- exports.ATOMIC_TYPES = ['felt', 'felt*'];
11
- // Source: https://github.com/Mrtenz/eip-712/blob/master/src/eip-712.ts
12
- // and modified to support starknet types
13
- /**
14
- * Checks if a type is valid with the given `typedData`. The following types are valid:
15
- * - Atomic types: felt, felt*
16
- * - Reference types: struct type (e.g. SomeStruct)
17
- *
18
- * @param {Record<string, unknown>} types
19
- * @param {string} type
20
- * @return {boolean}
21
- */
22
- var isValidType = function (types, type) {
23
- if (exports.ATOMIC_TYPES.includes(type)) {
24
- return true;
25
- }
26
- if (types[type]) {
27
- return true;
28
- }
29
- return false;
30
- };
31
- exports.isValidType = isValidType;
32
- var TYPE = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Type', function (type, context) {
33
- return (0, exports.isValidType)(context.branch[0].types, type);
34
- });
35
- exports.STARKNET_TYPE = (0, superstruct_1.object)({
36
- name: (0, superstruct_1.string)(),
37
- type: TYPE,
38
- });
39
- exports.STARKNET_DOMAIN_TYPE = (0, superstruct_1.object)({
40
- name: (0, superstruct_1.optional)((0, superstruct_1.string)()),
41
- version: (0, superstruct_1.optional)((0, superstruct_1.string)()),
42
- chainId: (0, superstruct_1.optional)(
43
- (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])
44
- ),
45
- });
46
- exports.STARKNET_TYPED_DATA_TYPE = (0, superstruct_1.object)({
47
- types: (0, superstruct_1.intersection)([
48
- (0, superstruct_1.type)({ StarkNetDomain: (0, superstruct_1.array)(exports.STARKNET_TYPE) }),
49
- (0, superstruct_1.record)(
50
- (0, superstruct_1.string)(),
51
- (0, superstruct_1.array)(exports.STARKNET_TYPE)
52
- ),
53
- ]),
54
- primaryType: (0, superstruct_1.string)(),
55
- domain: exports.STARKNET_DOMAIN_TYPE,
56
- message: (0, superstruct_1.object)(),
57
- });
@@ -1,27 +1,8 @@
1
+ import { TypedData } from './types';
1
2
  /**
2
3
  * Validates that `data` matches the EIP-712 JSON schema.
3
4
  *
4
5
  * @param {any} data
5
6
  * @return {boolean}
6
7
  */
7
- export declare const validateTypedData: (data: unknown) => data is {
8
- types: {
9
- StarkNetDomain: {
10
- type: string;
11
- name: string;
12
- }[];
13
- } & Record<
14
- string,
15
- {
16
- type: string;
17
- name: string;
18
- }[]
19
- >;
20
- primaryType: string;
21
- domain: {
22
- version?: string | undefined;
23
- chainId?: string | number | undefined;
24
- name?: string | undefined;
25
- };
26
- message: Record<string, unknown>;
27
- };
8
+ export declare const validateTypedData: (data: unknown) => data is TypedData;
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, '__esModule', { value: true });
3
3
  exports.validateTypedData = void 0;
4
- var superstruct_1 = require('superstruct');
5
- var types_1 = require('./types');
6
4
  /**
7
5
  * Validates that `data` matches the EIP-712 JSON schema.
8
6
  *
@@ -10,6 +8,9 @@ var types_1 = require('./types');
10
8
  * @return {boolean}
11
9
  */
12
10
  var validateTypedData = function (data) {
13
- return (0, superstruct_1.is)(data, types_1.STARKNET_TYPED_DATA_TYPE);
11
+ var typedData = data;
12
+ // Validate that the data matches the EIP-712 JSON schema
13
+ var valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
14
+ return valid;
14
15
  };
15
16
  exports.validateTypedData = validateTypedData;