starknet 3.18.2 → 3.19.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/__tests__/account.test.ts +11 -56
  3. package/__tests__/contract.test.ts +11 -49
  4. package/__tests__/defaultProvider.test.ts +321 -0
  5. package/__tests__/fixtures.ts +32 -11
  6. package/__tests__/rpcProvider.test.ts +17 -0
  7. package/__tests__/sequencerProvider.test.ts +45 -0
  8. package/account/default.d.ts +54 -77
  9. package/account/default.js +271 -596
  10. package/account/index.js +18 -31
  11. package/account/interface.d.ts +66 -95
  12. package/account/interface.js +20 -30
  13. package/constants.d.ts +17 -19
  14. package/constants.js +2038 -2059
  15. package/contract/contractFactory.d.ts +25 -29
  16. package/contract/contractFactory.js +94 -210
  17. package/contract/default.d.ts +117 -146
  18. package/contract/default.js +582 -776
  19. package/contract/index.js +19 -32
  20. package/contract/interface.d.ts +72 -92
  21. package/contract/interface.js +6 -5
  22. package/dist/account/default.d.ts +5 -9
  23. package/dist/account/default.js +35 -169
  24. package/dist/account/interface.d.ts +3 -15
  25. package/dist/contract/contractFactory.js +4 -4
  26. package/dist/contract/default.d.ts +3 -3
  27. package/dist/contract/default.js +3 -2
  28. package/dist/contract/interface.d.ts +2 -2
  29. package/dist/provider/default.d.ts +18 -134
  30. package/dist/provider/default.js +47 -411
  31. package/dist/provider/index.d.ts +2 -0
  32. package/dist/provider/index.js +2 -0
  33. package/dist/provider/interface.d.ts +45 -50
  34. package/dist/provider/rpc.d.ts +57 -0
  35. package/dist/provider/rpc.js +364 -0
  36. package/dist/provider/sequencer.d.ts +66 -0
  37. package/dist/provider/sequencer.js +443 -0
  38. package/dist/types/account.d.ts +2 -3
  39. package/dist/types/api/index.d.ts +16 -0
  40. package/dist/types/api/index.js +18 -0
  41. package/dist/types/api/rpc.d.ts +221 -0
  42. package/dist/types/{api.js → api/rpc.js} +0 -0
  43. package/dist/types/api/sequencer.d.ts +289 -0
  44. package/dist/types/api/sequencer.js +2 -0
  45. package/dist/types/index.d.ts +3 -1
  46. package/dist/types/index.js +15 -1
  47. package/dist/types/lib.d.ts +3 -1
  48. package/dist/types/provider.d.ts +86 -0
  49. package/dist/types/provider.js +2 -0
  50. package/dist/utils/provider.d.ts +4 -0
  51. package/dist/utils/provider.js +38 -0
  52. package/dist/utils/responseParser/index.d.ts +11 -0
  53. package/dist/utils/responseParser/index.js +9 -0
  54. package/dist/utils/responseParser/rpc.d.ts +13 -0
  55. package/dist/utils/responseParser/rpc.js +96 -0
  56. package/dist/utils/responseParser/sequencer.d.ts +13 -0
  57. package/dist/utils/responseParser/sequencer.js +124 -0
  58. package/index.js +42 -75
  59. package/package.json +1 -1
  60. package/provider/default.d.ts +21 -175
  61. package/provider/default.js +139 -704
  62. package/provider/errors.d.ts +4 -4
  63. package/provider/errors.js +30 -40
  64. package/provider/index.d.ts +2 -0
  65. package/provider/index.js +22 -33
  66. package/provider/interface.d.ts +104 -131
  67. package/provider/interface.js +6 -5
  68. package/provider/rpc.d.ts +57 -0
  69. package/provider/rpc.js +364 -0
  70. package/provider/sequencer.d.ts +66 -0
  71. package/provider/sequencer.js +443 -0
  72. package/provider/utils.d.ts +7 -9
  73. package/provider/utils.js +39 -44
  74. package/signer/default.d.ts +5 -9
  75. package/signer/default.js +72 -177
  76. package/signer/index.js +18 -31
  77. package/signer/interface.d.ts +29 -33
  78. package/signer/interface.js +6 -5
  79. package/src/account/default.ts +26 -146
  80. package/src/account/interface.ts +5 -20
  81. package/src/contract/contractFactory.ts +3 -6
  82. package/src/contract/default.ts +6 -4
  83. package/src/contract/interface.ts +2 -2
  84. package/src/provider/default.ts +63 -395
  85. package/src/provider/index.ts +2 -0
  86. package/src/provider/interface.ts +68 -63
  87. package/src/provider/rpc.ts +300 -0
  88. package/src/provider/sequencer.ts +384 -0
  89. package/src/types/account.ts +2 -3
  90. package/src/types/api/index.ts +17 -0
  91. package/src/types/api/rpc.ts +247 -0
  92. package/src/types/api/sequencer.ts +331 -0
  93. package/src/types/index.ts +3 -1
  94. package/src/types/lib.ts +3 -1
  95. package/src/types/provider.ts +108 -0
  96. package/src/utils/provider.ts +28 -0
  97. package/src/utils/responseParser/index.ts +28 -0
  98. package/src/utils/responseParser/rpc.ts +93 -0
  99. package/src/utils/responseParser/sequencer.ts +127 -0
  100. package/types/account.d.ts +5 -7
  101. package/types/account.js +2 -2
  102. package/types/api/index.d.ts +16 -0
  103. package/types/api/index.js +18 -0
  104. package/types/api/rpc.d.ts +221 -0
  105. package/types/api/rpc.js +2 -0
  106. package/types/api/sequencer.d.ts +289 -0
  107. package/types/api/sequencer.js +2 -0
  108. package/types/contract.d.ts +1 -1
  109. package/types/contract.js +2 -2
  110. package/types/index.d.ts +3 -1
  111. package/types/index.js +35 -34
  112. package/types/lib.d.ts +36 -41
  113. package/types/lib.js +2 -2
  114. package/types/provider.d.ts +86 -0
  115. package/types/provider.js +2 -0
  116. package/types/signer.d.ts +2 -2
  117. package/types/signer.js +2 -2
  118. package/utils/address.js +26 -37
  119. package/utils/ellipticCurve.d.ts +1 -6
  120. package/utils/ellipticCurve.js +73 -137
  121. package/utils/encode.js +49 -85
  122. package/utils/hash.d.ts +4 -31
  123. package/utils/hash.js +76 -141
  124. package/utils/json.d.ts +13 -45
  125. package/utils/json.js +15 -22
  126. package/utils/number.d.ts +2 -9
  127. package/utils/number.js +47 -81
  128. package/utils/provider.d.ts +4 -0
  129. package/utils/provider.js +38 -0
  130. package/utils/responseParser/index.d.ts +11 -0
  131. package/utils/responseParser/index.js +9 -0
  132. package/utils/responseParser/rpc.d.ts +13 -0
  133. package/utils/responseParser/rpc.js +96 -0
  134. package/utils/responseParser/sequencer.d.ts +13 -0
  135. package/utils/responseParser/sequencer.js +124 -0
  136. package/utils/shortString.js +13 -21
  137. package/utils/stark.d.ts +0 -1
  138. package/utils/stark.js +59 -93
  139. package/utils/transaction.d.ts +3 -6
  140. package/utils/transaction.js +50 -81
  141. package/utils/typedData/index.d.ts +3 -15
  142. package/utils/typedData/index.js +109 -175
  143. package/utils/typedData/types.d.ts +9 -9
  144. package/utils/typedData/types.js +2 -2
  145. package/utils/typedData/utils.js +6 -6
  146. package/utils/uint256.d.ts +5 -5
  147. package/utils/uint256.js +16 -26
  148. package/www/docs/API/account.md +3 -4
  149. package/www/docs/API/contract.md +2 -2
  150. package/www/docs/API/contractFactory.md +2 -2
  151. package/www/docs/API/provider.md +185 -74
  152. package/www/guides/account.md +1 -8
  153. package/www/guides/erc20.md +3 -0
  154. package/__tests__/provider.test.ts +0 -168
  155. package/dist/types/api.d.ts +0 -261
  156. package/src/types/api.ts +0 -303
  157. package/types/api.d.ts +0 -287
  158. package/types/api.js +0 -2
@@ -10,11 +10,7 @@ export * from './types';
10
10
  * @param {string[]} [dependencies]
11
11
  * @return {string[]}
12
12
  */
13
- export declare const getDependencies: (
14
- typedData: TypedData,
15
- type: string,
16
- dependencies?: string[]
17
- ) => string[];
13
+ export declare const getDependencies: (typedData: TypedData, type: string, dependencies?: string[]) => string[];
18
14
  /**
19
15
  * Encode a type to a string. All dependant types are alphabetically sorted.
20
16
  *
@@ -39,11 +35,7 @@ export declare const getTypeHash: (typedData: TypedData, type: string) => string
39
35
  * @param {string} type
40
36
  * @param {Record<string, any>} data
41
37
  */
42
- export declare const encodeData: <T extends TypedData>(
43
- typedData: T,
44
- type: string,
45
- data: T['message']
46
- ) => string[][];
38
+ export declare const encodeData: <T extends TypedData>(typedData: T, type: string, data: T["message"]) => string[][];
47
39
  /**
48
40
  * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
49
41
  * types are automatically encoded.
@@ -53,11 +45,7 @@ export declare const encodeData: <T extends TypedData>(
53
45
  * @param {Record<string, any>} data
54
46
  * @return {Buffer}
55
47
  */
56
- export declare const getStructHash: <T extends TypedData>(
57
- typedData: T,
58
- type: string,
59
- data: T['message']
60
- ) => string;
48
+ export declare const getStructHash: <T extends TypedData>(typedData: T, type: string, data: T["message"]) => string;
61
49
  /**
62
50
  * Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
63
51
  * with Keccak256.
@@ -1,87 +1,60 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __exportStar =
23
- (this && this.__exportStar) ||
24
- function (m, exports) {
25
- for (var p in m)
26
- if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
27
- __createBinding(exports, m, p);
28
- };
29
- var __read =
30
- (this && this.__read) ||
31
- function (o, n) {
32
- var m = typeof Symbol === 'function' && o[Symbol.iterator];
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __read = (this && this.__read) || function (o, n) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
33
18
  if (!m) return o;
34
- var i = m.call(o),
35
- r,
36
- ar = [],
37
- e;
19
+ var i = m.call(o), r, ar = [], e;
38
20
  try {
39
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
40
- } catch (error) {
41
- e = { error: error };
42
- } finally {
43
- try {
44
- if (r && !r.done && (m = i['return'])) m.call(i);
45
- } finally {
46
- if (e) throw e.error;
47
- }
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ }
23
+ catch (error) { e = { error: error }; }
24
+ finally {
25
+ try {
26
+ if (r && !r.done && (m = i["return"])) m.call(i);
27
+ }
28
+ finally { if (e) throw e.error; }
48
29
  }
49
30
  return ar;
50
- };
51
- var __spreadArray =
52
- (this && this.__spreadArray) ||
53
- function (to, from, pack) {
54
- if (pack || arguments.length === 2)
55
- for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ };
32
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
33
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
56
34
  if (ar || !(i in from)) {
57
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
58
- ar[i] = from[i];
35
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
36
+ ar[i] = from[i];
59
37
  }
60
- }
38
+ }
61
39
  return to.concat(ar || Array.prototype.slice.call(from));
62
- };
63
- Object.defineProperty(exports, '__esModule', { value: true });
64
- exports.getMessageHash =
65
- exports.getStructHash =
66
- exports.encodeData =
67
- exports.getTypeHash =
68
- exports.encodeType =
69
- exports.getDependencies =
70
- void 0;
71
- var hash_1 = require('../hash');
72
- var number_1 = require('../number');
73
- var shortString_1 = require('../shortString');
74
- var utils_1 = require('./utils');
75
- __exportStar(require('./types'), exports);
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.getMessageHash = exports.getStructHash = exports.encodeData = exports.getTypeHash = exports.encodeType = exports.getDependencies = void 0;
43
+ var hash_1 = require("../hash");
44
+ var number_1 = require("../number");
45
+ var shortString_1 = require("../shortString");
46
+ var utils_1 = require("./utils");
47
+ __exportStar(require("./types"), exports);
76
48
  function getHex(value) {
77
- try {
78
- return (0, number_1.toHex)((0, number_1.toBN)(value));
79
- } catch (e) {
80
- if (typeof value === 'string') {
81
- return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
49
+ try {
50
+ return (0, number_1.toHex)((0, number_1.toBN)(value));
51
+ }
52
+ catch (e) {
53
+ if (typeof value === 'string') {
54
+ return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
55
+ }
56
+ throw new Error("Invalid BigNumberish: ".concat(value));
82
57
  }
83
- throw new Error('Invalid BigNumberish: '.concat(value));
84
- }
85
58
  }
86
59
  /**
87
60
  * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
@@ -93,41 +66,25 @@ function getHex(value) {
93
66
  * @return {string[]}
94
67
  */
95
68
  var getDependencies = function (typedData, type, dependencies) {
96
- if (dependencies === void 0) {
97
- dependencies = [];
98
- }
99
- // `getDependencies` is called by most other functions, so we validate the JSON schema here
100
- if (!(0, utils_1.validateTypedData)(typedData)) {
101
- throw new Error('Typed data does not match JSON schema');
102
- }
103
- // Include pointers (struct arrays)
104
- if (type[type.length - 1] === '*') {
105
- // eslint-disable-next-line no-param-reassign
106
- type = type.slice(0, -1);
107
- }
108
- if (dependencies.includes(type)) {
109
- return dependencies;
110
- }
111
- if (!typedData.types[type]) {
112
- return dependencies;
113
- }
114
- return __spreadArray(
115
- [type],
116
- __read(
117
- typedData.types[type].reduce(function (previous, t) {
118
- return __spreadArray(
119
- __spreadArray([], __read(previous), false),
120
- __read(
121
- (0, exports.getDependencies)(typedData, t.type, previous).filter(function (dependency) {
122
- return !previous.includes(dependency);
123
- })
124
- ),
125
- false
126
- );
127
- }, [])
128
- ),
129
- false
130
- );
69
+ if (dependencies === void 0) { dependencies = []; }
70
+ // `getDependencies` is called by most other functions, so we validate the JSON schema here
71
+ if (!(0, utils_1.validateTypedData)(typedData)) {
72
+ throw new Error('Typed data does not match JSON schema');
73
+ }
74
+ // Include pointers (struct arrays)
75
+ if (type[type.length - 1] === '*') {
76
+ // eslint-disable-next-line no-param-reassign
77
+ type = type.slice(0, -1);
78
+ }
79
+ if (dependencies.includes(type)) {
80
+ return dependencies;
81
+ }
82
+ if (!typedData.types[type]) {
83
+ return dependencies;
84
+ }
85
+ return __spreadArray([
86
+ type
87
+ ], __read(typedData.types[type].reduce(function (previous, t) { return __spreadArray(__spreadArray([], __read(previous), false), __read((0, exports.getDependencies)(typedData, t.type, previous).filter(function (dependency) { return !previous.includes(dependency); })), false); }, [])), false);
131
88
  };
132
89
  exports.getDependencies = getDependencies;
133
90
  /**
@@ -138,20 +95,13 @@ exports.getDependencies = getDependencies;
138
95
  * @return {string}
139
96
  */
140
97
  var encodeType = function (typedData, type) {
141
- var _a = __read((0, exports.getDependencies)(typedData, type)),
142
- primary = _a[0],
143
- dependencies = _a.slice(1);
144
- var types = __spreadArray([primary], __read(dependencies.sort()), false);
145
- return types
146
- .map(function (dependency) {
147
- return ''.concat(dependency, '(').concat(
148
- typedData.types[dependency].map(function (t) {
149
- return ''.concat(t.name, ':').concat(t.type);
150
- }),
151
- ')'
152
- );
98
+ var _a = __read((0, exports.getDependencies)(typedData, type)), primary = _a[0], dependencies = _a.slice(1);
99
+ var types = __spreadArray([primary], __read(dependencies.sort()), false);
100
+ return types
101
+ .map(function (dependency) {
102
+ return "".concat(dependency, "(").concat(typedData.types[dependency].map(function (t) { return "".concat(t.name, ":").concat(t.type); }), ")");
153
103
  })
154
- .join('');
104
+ .join('');
155
105
  };
156
106
  exports.encodeType = encodeType;
157
107
  /**
@@ -162,7 +112,7 @@ exports.encodeType = encodeType;
162
112
  * @return {string}
163
113
  */
164
114
  var getTypeHash = function (typedData, type) {
165
- return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(typedData, type));
115
+ return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(typedData, type));
166
116
  };
167
117
  exports.getTypeHash = getTypeHash;
168
118
  /**
@@ -175,27 +125,23 @@ exports.getTypeHash = getTypeHash;
175
125
  * @returns {[string, string]}
176
126
  */
177
127
  var encodeValue = function (typedData, type, data) {
178
- if (typedData.types[type]) {
179
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
180
- return [type, (0, exports.getStructHash)(typedData, type, data)];
181
- }
182
- if (
183
- Object.keys(typedData.types)
184
- .map(function (x) {
185
- return ''.concat(x, '*');
186
- })
187
- .includes(type)
188
- ) {
189
- var structHashes = data.map(function (struct) {
190
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
191
- return (0, exports.getStructHash)(typedData, type.slice(0, -1), struct);
192
- });
193
- return [type, (0, hash_1.computeHashOnElements)(structHashes)];
194
- }
195
- if (type === 'felt*') {
196
- return ['felt*', (0, hash_1.computeHashOnElements)(data)];
197
- }
198
- return [type, getHex(data)];
128
+ if (typedData.types[type]) {
129
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
130
+ return [type, (0, exports.getStructHash)(typedData, type, data)];
131
+ }
132
+ if (Object.keys(typedData.types)
133
+ .map(function (x) { return "".concat(x, "*"); })
134
+ .includes(type)) {
135
+ var structHashes = data.map(function (struct) {
136
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
137
+ return (0, exports.getStructHash)(typedData, type.slice(0, -1), struct);
138
+ });
139
+ return [type, (0, hash_1.computeHashOnElements)(structHashes)];
140
+ }
141
+ if (type === 'felt*') {
142
+ return ['felt*', (0, hash_1.computeHashOnElements)(data)];
143
+ }
144
+ return [type, getHex(data)];
199
145
  };
200
146
  /**
201
147
  * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
@@ -206,31 +152,19 @@ var encodeValue = function (typedData, type, data) {
206
152
  * @param {Record<string, any>} data
207
153
  */
208
154
  var encodeData = function (typedData, type, data) {
209
- var _a = __read(
210
- typedData.types[type].reduce(
211
- function (_a, field) {
212
- var _b = __read(_a, 2),
213
- ts = _b[0],
214
- vs = _b[1];
215
- if (data[field.name] === undefined || data[field.name] === null) {
155
+ var _a = __read(typedData.types[type].reduce(function (_a, field) {
156
+ var _b = __read(_a, 2), ts = _b[0], vs = _b[1];
157
+ if (data[field.name] === undefined || data[field.name] === null) {
216
158
  throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
217
- }
218
- var value = data[field.name];
219
- var _c = __read(encodeValue(typedData, field.type, value), 2),
220
- t = _c[0],
221
- encodedValue = _c[1];
222
- return [
159
+ }
160
+ var value = data[field.name];
161
+ var _c = __read(encodeValue(typedData, field.type, value), 2), t = _c[0], encodedValue = _c[1];
162
+ return [
223
163
  __spreadArray(__spreadArray([], __read(ts), false), [t], false),
224
164
  __spreadArray(__spreadArray([], __read(vs), false), [encodedValue], false),
225
- ];
226
- },
227
- [['felt'], [(0, exports.getTypeHash)(typedData, type)]]
228
- ),
229
- 2
230
- ),
231
- types = _a[0],
232
- values = _a[1];
233
- return [types, values];
165
+ ];
166
+ }, [['felt'], [(0, exports.getTypeHash)(typedData, type)]]), 2), types = _a[0], values = _a[1];
167
+ return [types, values];
234
168
  };
235
169
  exports.encodeData = encodeData;
236
170
  /**
@@ -243,7 +177,7 @@ exports.encodeData = encodeData;
243
177
  * @return {Buffer}
244
178
  */
245
179
  var getStructHash = function (typedData, type, data) {
246
- return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(typedData, type, data)[1]);
180
+ return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(typedData, type, data)[1]);
247
181
  };
248
182
  exports.getStructHash = getStructHash;
249
183
  /**
@@ -255,12 +189,12 @@ exports.getStructHash = getStructHash;
255
189
  * @return {string}
256
190
  */
257
191
  var getMessageHash = function (typedData, account) {
258
- var message = [
259
- (0, shortString_1.encodeShortString)('StarkNet Message'),
260
- (0, exports.getStructHash)(typedData, 'StarkNetDomain', typedData.domain),
261
- account,
262
- (0, exports.getStructHash)(typedData, typedData.primaryType, typedData.message),
263
- ];
264
- return (0, hash_1.computeHashOnElements)(message);
192
+ var message = [
193
+ (0, shortString_1.encodeShortString)('StarkNet Message'),
194
+ (0, exports.getStructHash)(typedData, 'StarkNetDomain', typedData.domain),
195
+ account,
196
+ (0, exports.getStructHash)(typedData, typedData.primaryType, typedData.message),
197
+ ];
198
+ return (0, hash_1.computeHashOnElements)(message);
265
199
  };
266
200
  exports.getMessageHash = getMessageHash;
@@ -5,23 +5,23 @@
5
5
  * standard.
6
6
  */
7
7
  export interface StarkNetType {
8
- name: string;
9
- type: 'felt' | 'felt*' | string;
8
+ name: string;
9
+ type: 'felt' | 'felt*' | string;
10
10
  }
11
11
  /**
12
12
  * The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
13
13
  */
14
14
  export interface StarkNetDomain extends Record<string, unknown> {
15
- name?: string;
16
- version?: string;
17
- chainId?: string | number;
15
+ name?: string;
16
+ version?: string;
17
+ chainId?: string | number;
18
18
  }
19
19
  /**
20
20
  * The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
21
21
  */
22
22
  export interface TypedData {
23
- types: Record<string, StarkNetType[]>;
24
- primaryType: string;
25
- domain: StarkNetDomain;
26
- message: Record<string, unknown>;
23
+ types: Record<string, StarkNetType[]>;
24
+ primaryType: string;
25
+ domain: StarkNetDomain;
26
+ message: Record<string, unknown>;
27
27
  }
@@ -1,2 +1,2 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateTypedData = void 0;
4
4
  /**
5
5
  * Validates that `data` matches the EIP-712 JSON schema.
@@ -8,9 +8,9 @@ exports.validateTypedData = void 0;
8
8
  * @return {boolean}
9
9
  */
10
10
  var validateTypedData = function (data) {
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;
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;
15
15
  };
16
16
  exports.validateTypedData = validateTypedData;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { BigNumberish } from './number';
3
3
  export interface Uint256 {
4
- low: BigNumberish;
5
- high: BigNumberish;
4
+ low: BigNumberish;
5
+ high: BigNumberish;
6
6
  }
7
- export declare function uint256ToBN(uint256: Uint256): import('bn.js');
8
- export declare const UINT_128_MAX: import('bn.js');
9
- export declare const UINT_256_MAX: import('bn.js');
7
+ export declare function uint256ToBN(uint256: Uint256): import("bn.js");
8
+ export declare const UINT_128_MAX: import("bn.js");
9
+ export declare const UINT_256_MAX: import("bn.js");
10
10
  export declare function isUint256(bn: BigNumberish): boolean;
11
11
  export declare function bnToUint256(bignumber: BigNumberish): Uint256;
package/utils/uint256.js CHANGED
@@ -1,38 +1,28 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.bnToUint256 =
4
- exports.isUint256 =
5
- exports.UINT_256_MAX =
6
- exports.UINT_128_MAX =
7
- exports.uint256ToBN =
8
- void 0;
9
- var encode_1 = require('./encode');
10
- var number_1 = require('./number');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bnToUint256 = exports.isUint256 = exports.UINT_256_MAX = exports.UINT_128_MAX = exports.uint256ToBN = void 0;
4
+ var encode_1 = require("./encode");
5
+ var number_1 = require("./number");
11
6
  // function to convert Uint256 to BN
12
7
  function uint256ToBN(uint256) {
13
- return (0, number_1.toBN)(uint256.high)
14
- .shln(128)
15
- .add((0, number_1.toBN)(uint256.low));
8
+ return (0, number_1.toBN)(uint256.high).shln(128).add((0, number_1.toBN)(uint256.low));
16
9
  }
17
10
  exports.uint256ToBN = uint256ToBN;
18
- exports.UINT_128_MAX = (0, number_1.toBN)(1)
19
- .shln(128)
20
- .sub((0, number_1.toBN)(1));
21
- exports.UINT_256_MAX = (0, number_1.toBN)(1)
22
- .shln(256)
23
- .sub((0, number_1.toBN)(1));
11
+ exports.UINT_128_MAX = (0, number_1.toBN)(1).shln(128).sub((0, number_1.toBN)(1));
12
+ exports.UINT_256_MAX = (0, number_1.toBN)(1).shln(256).sub((0, number_1.toBN)(1));
24
13
  // function to check if BN is smaller or equal 2**256-1
25
14
  function isUint256(bn) {
26
- return (0, number_1.toBN)(bn).lte(exports.UINT_256_MAX);
15
+ return (0, number_1.toBN)(bn).lte(exports.UINT_256_MAX);
27
16
  }
28
17
  exports.isUint256 = isUint256;
29
18
  // function to convert BN to Uint256
30
19
  function bnToUint256(bignumber) {
31
- var bn = (0, number_1.toBN)(bignumber);
32
- if (!isUint256(bn)) throw new Error('Number is too large');
33
- return {
34
- low: (0, encode_1.addHexPrefix)(bn.maskn(128).toString(16)),
35
- high: (0, encode_1.addHexPrefix)(bn.shrn(128).toString(16)),
36
- };
20
+ var bn = (0, number_1.toBN)(bignumber);
21
+ if (!isUint256(bn))
22
+ throw new Error('Number is too large');
23
+ return {
24
+ low: (0, encode_1.addHexPrefix)(bn.maskn(128).toString(16)),
25
+ high: (0, encode_1.addHexPrefix)(bn.shrn(128).toString(16)),
26
+ };
37
27
  }
38
28
  exports.bnToUint256 = bnToUint256;
@@ -43,8 +43,9 @@ The _options_ object may include any of:
43
43
 
44
44
  ```
45
45
  {
46
- amount: number;
47
- unit: string;
46
+ overall_fee: BN;
47
+ gas_consumed?: BN;
48
+ gas_price?: BN;
48
49
  }
49
50
  ```
50
51
 
@@ -64,9 +65,7 @@ The _transactionsDetail_ object may include any of:
64
65
 
65
66
  ```
66
67
  {
67
- code: 'TRANSACTION_RECEIVED';
68
68
  transaction_hash: string;
69
- address?: string;
70
69
  };
71
70
  ```
72
71
 
@@ -22,9 +22,9 @@ contract.**address** => _string_
22
22
 
23
23
  The address the contract was constructed/connected with
24
24
 
25
- contract.**providerOrAcount** => _Provider | Account_
25
+ contract.**providerOrAcount** => ProviderInterface | AccountInterface_
26
26
 
27
- Provider or Account that are used to interact with the network
27
+ Provider or account that are used to interact with the network
28
28
 
29
29
  contract.**deployTransactionHash** => _string | null_
30
30
 
@@ -26,9 +26,9 @@ contractFactory.**compiledContract** => _CompiledContract_;
26
26
 
27
27
  The compiled contract the contractFactory was constructed with
28
28
 
29
- contractFactory.**providerOrAccount** => _Provider | Account_;
29
+ contractFactory.**providerOrAccount** => _ProviderInterface | AccountInterface_;
30
30
 
31
- Provider or Account that are used to interact with the network
31
+ Provider or account that are used to interact with the network
32
32
 
33
33
  ## Methods
34
34