starknet 3.16.3 → 3.18.1
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 +18 -0
- package/__mocks__/typedDataStructArrayExample.json +44 -0
- package/__tests__/utils/typedData.test.ts +24 -0
- package/account/default.js +28 -29
- package/dist/account/default.js +21 -23
- package/dist/types/account.d.ts +3 -2
- package/dist/types/api.d.ts +5 -1
- package/dist/utils/typedData/index.js +14 -0
- package/package.json +1 -1
- package/src/account/default.ts +7 -2
- package/src/types/account.ts +3 -2
- package/src/types/api.ts +6 -1
- package/src/utils/typedData/index.ts +18 -0
- package/types/account.d.ts +3 -2
- package/types/api.d.ts +5 -1
- package/utils/typedData/index.js +18 -0
- package/www/docs/API/provider.md +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [3.18.1](https://github.com/0xs34n/starknet.js/compare/v3.18.0...v3.18.1) (2022-07-23)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- struct array hashing ([e1f82df](https://github.com/0xs34n/starknet.js/commit/e1f82dfd575be4c84b291c33f8169bf367493603))
|
|
6
|
+
|
|
7
|
+
# [3.18.0](https://github.com/0xs34n/starknet.js/compare/v3.17.0...v3.18.0) (2022-07-23)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- **cairo-0.9.1:** starknet_version in block response ([e88154d](https://github.com/0xs34n/starknet.js/commit/e88154d5f6fcd6695dca5d29da04d18d0a65cdf6))
|
|
12
|
+
|
|
13
|
+
# [3.17.0](https://github.com/0xs34n/starknet.js/compare/v3.16.3...v3.17.0) (2022-07-15)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- support SN 0.9.1 estimate_fee response ([9302aab](https://github.com/0xs34n/starknet.js/commit/9302aab9cbbe5eaa3a9933b19f8f46b2dd6d6a1d))
|
|
18
|
+
|
|
1
19
|
## [3.16.3](https://github.com/0xs34n/starknet.js/compare/v3.16.2...v3.16.3) (2022-07-15)
|
|
2
20
|
|
|
3
21
|
### Bug Fixes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"types": {
|
|
3
|
+
"StarkNetDomain": [
|
|
4
|
+
{ "name": "name", "type": "felt" },
|
|
5
|
+
{ "name": "version", "type": "felt" },
|
|
6
|
+
{ "name": "chainId", "type": "felt" }
|
|
7
|
+
],
|
|
8
|
+
"Person": [
|
|
9
|
+
{ "name": "name", "type": "felt" },
|
|
10
|
+
{ "name": "wallet", "type": "felt" }
|
|
11
|
+
],
|
|
12
|
+
"Post": [
|
|
13
|
+
{ "name": "title", "type": "felt" },
|
|
14
|
+
{ "name": "content", "type": "felt" }
|
|
15
|
+
],
|
|
16
|
+
"Mail": [
|
|
17
|
+
{ "name": "from", "type": "Person" },
|
|
18
|
+
{ "name": "to", "type": "Person" },
|
|
19
|
+
{ "name": "posts_len", "type": "felt" },
|
|
20
|
+
{ "name": "posts", "type": "Post*" }
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"primaryType": "Mail",
|
|
24
|
+
"domain": {
|
|
25
|
+
"name": "StarkNet Mail",
|
|
26
|
+
"version": "1",
|
|
27
|
+
"chainId": 1
|
|
28
|
+
},
|
|
29
|
+
"message": {
|
|
30
|
+
"from": {
|
|
31
|
+
"name": "Cow",
|
|
32
|
+
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
|
|
33
|
+
},
|
|
34
|
+
"to": {
|
|
35
|
+
"name": "Bob",
|
|
36
|
+
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
|
|
37
|
+
},
|
|
38
|
+
"posts_len": 2,
|
|
39
|
+
"posts": [
|
|
40
|
+
{ "title": "Greeting", "content": "Hello, Bob!" },
|
|
41
|
+
{ "title": "Farewell", "content": "Goodbye, Bob!" }
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import typedDataExample from '../../__mocks__/typedDataExample.json';
|
|
2
|
+
import typedDataStructArrayExample from '../../__mocks__/typedDataStructArrayExample.json';
|
|
2
3
|
import { number } from '../../src';
|
|
3
4
|
import { BigNumberish } from '../../src/utils/number';
|
|
4
5
|
import { encodeType, getMessageHash, getStructHash, getTypeHash } from '../../src/utils/typedData';
|
|
@@ -9,7 +10,12 @@ describe('typedData', () => {
|
|
|
9
10
|
expect(typeEncoding).toMatchInlineSnapshot(
|
|
10
11
|
`"Mail(from:Person,to:Person,contents:felt)Person(name:felt,wallet:felt)"`
|
|
11
12
|
);
|
|
13
|
+
const typeEncodingStructArr = encodeType(typedDataStructArrayExample, 'Mail');
|
|
14
|
+
expect(typeEncodingStructArr).toMatchInlineSnapshot(
|
|
15
|
+
`"Mail(from:Person,to:Person,posts_len:felt,posts:Post*)Person(name:felt,wallet:felt)Post(title:felt,content:felt)"`
|
|
16
|
+
);
|
|
12
17
|
});
|
|
18
|
+
|
|
13
19
|
test('should get right type hash', () => {
|
|
14
20
|
const typeHashDomain = getTypeHash(typedDataExample, 'StarkNetDomain');
|
|
15
21
|
expect(typeHashDomain).toMatchInlineSnapshot(
|
|
@@ -23,18 +29,36 @@ describe('typedData', () => {
|
|
|
23
29
|
expect(typeHashMail).toMatchInlineSnapshot(
|
|
24
30
|
`"0x13d89452df9512bf750f539ba3001b945576243288137ddb6c788457d4b2f79"`
|
|
25
31
|
);
|
|
32
|
+
const typeHashPost = getTypeHash(typedDataStructArrayExample, 'Post');
|
|
33
|
+
expect(typeHashPost).toMatchInlineSnapshot(
|
|
34
|
+
`"0x1d71e69bf476486b43cdcfaf5a85c00bb2d954c042b281040e513080388356d"`
|
|
35
|
+
);
|
|
36
|
+
const typeHashMailWithStructArray = getTypeHash(typedDataStructArrayExample, 'Mail');
|
|
37
|
+
expect(typeHashMailWithStructArray).toMatchInlineSnapshot(
|
|
38
|
+
`"0x873b878e35e258fc99e3085d5aaad3a81a0c821f189c08b30def2cde55ff27"`
|
|
39
|
+
);
|
|
26
40
|
});
|
|
41
|
+
|
|
27
42
|
test('should get right hash for StarkNetDomain', () => {
|
|
28
43
|
const hash = getStructHash(typedDataExample, 'StarkNetDomain', typedDataExample.domain as any);
|
|
29
44
|
expect(hash).toMatchInlineSnapshot(
|
|
30
45
|
`"0x54833b121883a3e3aebff48ec08a962f5742e5f7b973469c1f8f4f55d470b07"`
|
|
31
46
|
);
|
|
32
47
|
});
|
|
48
|
+
|
|
33
49
|
test('should get right hash for entire message', () => {
|
|
34
50
|
const hash = getMessageHash(typedDataExample, '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826');
|
|
35
51
|
expect(hash).toMatchInlineSnapshot(
|
|
36
52
|
`"0x6fcff244f63e38b9d88b9e3378d44757710d1b244282b435cb472053c8d78d0"`
|
|
37
53
|
);
|
|
54
|
+
|
|
55
|
+
const hashStructArr = getMessageHash(
|
|
56
|
+
typedDataStructArrayExample,
|
|
57
|
+
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'
|
|
58
|
+
);
|
|
59
|
+
expect(hashStructArr).toMatchInlineSnapshot(
|
|
60
|
+
`"0x5914ed2764eca2e6a41eb037feefd3d2e33d9af6225a9e7fe31ac943ff712c"`
|
|
61
|
+
);
|
|
38
62
|
});
|
|
39
63
|
|
|
40
64
|
interface StringStruct {
|
package/account/default.js
CHANGED
|
@@ -24,20 +24,6 @@ var __extends =
|
|
|
24
24
|
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
|
|
25
25
|
};
|
|
26
26
|
})();
|
|
27
|
-
var __assign =
|
|
28
|
-
(this && this.__assign) ||
|
|
29
|
-
function () {
|
|
30
|
-
__assign =
|
|
31
|
-
Object.assign ||
|
|
32
|
-
function (t) {
|
|
33
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
|
-
s = arguments[i];
|
|
35
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
36
|
-
}
|
|
37
|
-
return t;
|
|
38
|
-
};
|
|
39
|
-
return __assign.apply(this, arguments);
|
|
40
|
-
};
|
|
41
27
|
var __awaiter =
|
|
42
28
|
(this && this.__awaiter) ||
|
|
43
29
|
function (thisArg, _arguments, P, generator) {
|
|
@@ -251,34 +237,36 @@ var Account = /** @class */ (function (_super) {
|
|
|
251
237
|
});
|
|
252
238
|
};
|
|
253
239
|
Account.prototype.estimateFee = function (calls, _a) {
|
|
254
|
-
var _b
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
var _b;
|
|
241
|
+
var _c = _a === void 0 ? {} : _a,
|
|
242
|
+
providedNonce = _c.nonce,
|
|
243
|
+
_d = _c.blockIdentifier,
|
|
244
|
+
blockIdentifier = _d === void 0 ? 'pending' : _d;
|
|
258
245
|
return __awaiter(this, void 0, void 0, function () {
|
|
259
246
|
var transactions,
|
|
260
247
|
nonce,
|
|
261
|
-
|
|
248
|
+
_e,
|
|
262
249
|
version,
|
|
263
250
|
signerDetails,
|
|
264
251
|
signature,
|
|
265
252
|
calldata,
|
|
266
253
|
fetchedEstimate,
|
|
254
|
+
fee,
|
|
267
255
|
suggestedMaxFee;
|
|
268
|
-
return __generator(this, function (
|
|
269
|
-
switch (
|
|
256
|
+
return __generator(this, function (_f) {
|
|
257
|
+
switch (_f.label) {
|
|
270
258
|
case 0:
|
|
271
259
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
272
260
|
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
273
|
-
|
|
261
|
+
_e = providedNonce;
|
|
274
262
|
return [3 /*break*/, 3];
|
|
275
263
|
case 1:
|
|
276
264
|
return [4 /*yield*/, this.getNonce()];
|
|
277
265
|
case 2:
|
|
278
|
-
|
|
279
|
-
|
|
266
|
+
_e = _f.sent();
|
|
267
|
+
_f.label = 3;
|
|
280
268
|
case 3:
|
|
281
|
-
nonce =
|
|
269
|
+
nonce = _e;
|
|
282
270
|
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
283
271
|
signerDetails = {
|
|
284
272
|
walletAddress: this.address,
|
|
@@ -289,7 +277,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
289
277
|
};
|
|
290
278
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
291
279
|
case 4:
|
|
292
|
-
signature =
|
|
280
|
+
signature = _f.sent();
|
|
293
281
|
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
294
282
|
return [
|
|
295
283
|
4 /*yield*/,
|
|
@@ -306,11 +294,22 @@ var Account = /** @class */ (function (_super) {
|
|
|
306
294
|
),
|
|
307
295
|
];
|
|
308
296
|
case 5:
|
|
309
|
-
fetchedEstimate =
|
|
310
|
-
|
|
297
|
+
fetchedEstimate = _f.sent();
|
|
298
|
+
fee =
|
|
299
|
+
(_b = fetchedEstimate.overall_fee) !== null && _b !== void 0
|
|
300
|
+
? _b
|
|
301
|
+
: fetchedEstimate.amount;
|
|
302
|
+
if (fee === undefined) {
|
|
303
|
+
throw new Error('Expected either amount or overall_fee in estimate_fee response');
|
|
304
|
+
}
|
|
305
|
+
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fee);
|
|
311
306
|
return [
|
|
312
307
|
2 /*return*/,
|
|
313
|
-
|
|
308
|
+
{
|
|
309
|
+
amount: fee,
|
|
310
|
+
unit: fetchedEstimate.unit,
|
|
311
|
+
suggestedMaxFee: suggestedMaxFee,
|
|
312
|
+
},
|
|
314
313
|
];
|
|
315
314
|
}
|
|
316
315
|
});
|
package/dist/account/default.js
CHANGED
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -128,22 +117,23 @@ var Account = /** @class */ (function (_super) {
|
|
|
128
117
|
});
|
|
129
118
|
};
|
|
130
119
|
Account.prototype.estimateFee = function (calls, _a) {
|
|
131
|
-
var _b
|
|
120
|
+
var _b;
|
|
121
|
+
var _c = _a === void 0 ? {} : _a, providedNonce = _c.nonce, _d = _c.blockIdentifier, blockIdentifier = _d === void 0 ? 'pending' : _d;
|
|
132
122
|
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var transactions, nonce,
|
|
134
|
-
return __generator(this, function (
|
|
135
|
-
switch (
|
|
123
|
+
var transactions, nonce, _e, version, signerDetails, signature, calldata, fetchedEstimate, fee, suggestedMaxFee;
|
|
124
|
+
return __generator(this, function (_f) {
|
|
125
|
+
switch (_f.label) {
|
|
136
126
|
case 0:
|
|
137
127
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
138
128
|
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
139
|
-
|
|
129
|
+
_e = providedNonce;
|
|
140
130
|
return [3 /*break*/, 3];
|
|
141
131
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
142
132
|
case 2:
|
|
143
|
-
|
|
144
|
-
|
|
133
|
+
_e = (_f.sent());
|
|
134
|
+
_f.label = 3;
|
|
145
135
|
case 3:
|
|
146
|
-
nonce =
|
|
136
|
+
nonce = _e;
|
|
147
137
|
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
148
138
|
signerDetails = {
|
|
149
139
|
walletAddress: this.address,
|
|
@@ -154,7 +144,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
154
144
|
};
|
|
155
145
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
156
146
|
case 4:
|
|
157
|
-
signature =
|
|
147
|
+
signature = _f.sent();
|
|
158
148
|
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
159
149
|
return [4 /*yield*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
160
150
|
contract_address: this.address,
|
|
@@ -164,9 +154,17 @@ var Account = /** @class */ (function (_super) {
|
|
|
164
154
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
165
155
|
})];
|
|
166
156
|
case 5:
|
|
167
|
-
fetchedEstimate =
|
|
168
|
-
|
|
169
|
-
|
|
157
|
+
fetchedEstimate = _f.sent();
|
|
158
|
+
fee = (_b = fetchedEstimate.overall_fee) !== null && _b !== void 0 ? _b : fetchedEstimate.amount;
|
|
159
|
+
if (fee === undefined) {
|
|
160
|
+
throw new Error('Expected either amount or overall_fee in estimate_fee response');
|
|
161
|
+
}
|
|
162
|
+
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(fee);
|
|
163
|
+
return [2 /*return*/, {
|
|
164
|
+
amount: fee,
|
|
165
|
+
unit: fetchedEstimate.unit,
|
|
166
|
+
suggestedMaxFee: suggestedMaxFee,
|
|
167
|
+
}];
|
|
170
168
|
}
|
|
171
169
|
});
|
|
172
170
|
});
|
package/dist/types/account.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
2
|
import { BlockIdentifier } from '../provider/utils';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export interface EstimateFee {
|
|
5
|
+
amount: BN;
|
|
6
|
+
unit: string;
|
|
6
7
|
suggestedMaxFee: BN;
|
|
7
8
|
}
|
|
8
9
|
export interface EstimateFeeDetails {
|
package/dist/types/api.d.ts
CHANGED
|
@@ -167,6 +167,7 @@ export declare type GetBlockResponse = {
|
|
|
167
167
|
parent_block_hash: string;
|
|
168
168
|
status: Status;
|
|
169
169
|
gas_price: string;
|
|
170
|
+
starknet_version?: string;
|
|
170
171
|
};
|
|
171
172
|
export declare type GetCodeResponse = {
|
|
172
173
|
bytecode: string[];
|
|
@@ -240,8 +241,11 @@ export declare type FailedTransactionReceiptResponse = {
|
|
|
240
241
|
};
|
|
241
242
|
export declare type TransactionReceiptResponse = SuccessfulTransactionReceiptResponse | FailedTransactionReceiptResponse;
|
|
242
243
|
export declare type EstimateFeeResponse = {
|
|
243
|
-
|
|
244
|
+
overall_fee?: BN;
|
|
245
|
+
amount?: BN;
|
|
244
246
|
unit: string;
|
|
247
|
+
gas_price?: BN;
|
|
248
|
+
gas_usage?: BigNumberish;
|
|
245
249
|
};
|
|
246
250
|
export declare type RawArgs = {
|
|
247
251
|
[inputName: string]: string | string[] | {
|
|
@@ -71,6 +71,11 @@ var getDependencies = function (typedData, type, dependencies) {
|
|
|
71
71
|
if (!(0, utils_1.validateTypedData)(typedData)) {
|
|
72
72
|
throw new Error('Typed data does not match JSON schema');
|
|
73
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
|
+
}
|
|
74
79
|
if (dependencies.includes(type)) {
|
|
75
80
|
return dependencies;
|
|
76
81
|
}
|
|
@@ -124,6 +129,15 @@ var encodeValue = function (typedData, type, data) {
|
|
|
124
129
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
125
130
|
return [type, (0, exports.getStructHash)(typedData, type, data)];
|
|
126
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
|
+
}
|
|
127
141
|
if (type === 'felt*') {
|
|
128
142
|
return ['felt*', (0, hash_1.computeHashOnElements)(data)];
|
|
129
143
|
}
|
package/package.json
CHANGED
package/src/account/default.ts
CHANGED
|
@@ -83,10 +83,15 @@ export class Account extends Provider implements AccountInterface {
|
|
|
83
83
|
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
84
84
|
}
|
|
85
85
|
);
|
|
86
|
-
const
|
|
86
|
+
const fee = fetchedEstimate.overall_fee ?? fetchedEstimate.amount;
|
|
87
|
+
if (fee === undefined) {
|
|
88
|
+
throw new Error('Expected either amount or overall_fee in estimate_fee response');
|
|
89
|
+
}
|
|
90
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(fee);
|
|
87
91
|
|
|
88
92
|
return {
|
|
89
|
-
|
|
93
|
+
amount: fee,
|
|
94
|
+
unit: fetchedEstimate.unit,
|
|
90
95
|
suggestedMaxFee,
|
|
91
96
|
};
|
|
92
97
|
}
|
package/src/types/account.ts
CHANGED
|
@@ -2,9 +2,10 @@ import BN from 'bn.js';
|
|
|
2
2
|
|
|
3
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
|
-
import { EstimateFeeResponse } from './api';
|
|
6
5
|
|
|
7
|
-
export interface EstimateFee
|
|
6
|
+
export interface EstimateFee {
|
|
7
|
+
amount: BN;
|
|
8
|
+
unit: string;
|
|
8
9
|
suggestedMaxFee: BN;
|
|
9
10
|
}
|
|
10
11
|
|
package/src/types/api.ts
CHANGED
|
@@ -195,6 +195,7 @@ export type GetBlockResponse = {
|
|
|
195
195
|
parent_block_hash: string;
|
|
196
196
|
status: Status;
|
|
197
197
|
gas_price: string;
|
|
198
|
+
starknet_version?: string;
|
|
198
199
|
};
|
|
199
200
|
|
|
200
201
|
export type GetCodeResponse = {
|
|
@@ -280,9 +281,13 @@ export type TransactionReceiptResponse =
|
|
|
280
281
|
| SuccessfulTransactionReceiptResponse
|
|
281
282
|
| FailedTransactionReceiptResponse;
|
|
282
283
|
|
|
284
|
+
// Support 0.9.1 changes in a backward-compatible way
|
|
283
285
|
export type EstimateFeeResponse = {
|
|
284
|
-
|
|
286
|
+
overall_fee?: BN;
|
|
287
|
+
amount?: BN;
|
|
285
288
|
unit: string;
|
|
289
|
+
gas_price?: BN;
|
|
290
|
+
gas_usage?: BigNumberish;
|
|
286
291
|
};
|
|
287
292
|
|
|
288
293
|
export type RawArgs = {
|
|
@@ -36,6 +36,12 @@ export const getDependencies = (
|
|
|
36
36
|
throw new Error('Typed data does not match JSON schema');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// Include pointers (struct arrays)
|
|
40
|
+
if (type[type.length - 1] === '*') {
|
|
41
|
+
// eslint-disable-next-line no-param-reassign
|
|
42
|
+
type = type.slice(0, -1);
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
if (dependencies.includes(type)) {
|
|
40
46
|
return dependencies;
|
|
41
47
|
}
|
|
@@ -102,6 +108,18 @@ const encodeValue = (typedData: TypedData, type: string, data: unknown): [string
|
|
|
102
108
|
return [type, getStructHash(typedData, type, data as Record<string, unknown>)];
|
|
103
109
|
}
|
|
104
110
|
|
|
111
|
+
if (
|
|
112
|
+
Object.keys(typedData.types)
|
|
113
|
+
.map((x) => `${x}*`)
|
|
114
|
+
.includes(type)
|
|
115
|
+
) {
|
|
116
|
+
const structHashes: string[] = (data as unknown[]).map((struct) => {
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
118
|
+
return getStructHash(typedData, type.slice(0, -1), struct as Record<string, unknown>);
|
|
119
|
+
});
|
|
120
|
+
return [type, computeHashOnElements(structHashes)];
|
|
121
|
+
}
|
|
122
|
+
|
|
105
123
|
if (type === 'felt*') {
|
|
106
124
|
return ['felt*', computeHashOnElements(data as string[])];
|
|
107
125
|
}
|
package/types/account.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import BN from 'bn.js';
|
|
|
2
2
|
|
|
3
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export interface EstimateFee {
|
|
6
|
+
amount: BN;
|
|
7
|
+
unit: string;
|
|
7
8
|
suggestedMaxFee: BN;
|
|
8
9
|
}
|
|
9
10
|
export interface EstimateFeeDetails {
|
package/types/api.d.ts
CHANGED
|
@@ -186,6 +186,7 @@ export declare type GetBlockResponse = {
|
|
|
186
186
|
parent_block_hash: string;
|
|
187
187
|
status: Status;
|
|
188
188
|
gas_price: string;
|
|
189
|
+
starknet_version?: string;
|
|
189
190
|
};
|
|
190
191
|
export declare type GetCodeResponse = {
|
|
191
192
|
bytecode: string[];
|
|
@@ -263,8 +264,11 @@ export declare type TransactionReceiptResponse =
|
|
|
263
264
|
| SuccessfulTransactionReceiptResponse
|
|
264
265
|
| FailedTransactionReceiptResponse;
|
|
265
266
|
export declare type EstimateFeeResponse = {
|
|
266
|
-
|
|
267
|
+
overall_fee?: BN;
|
|
268
|
+
amount?: BN;
|
|
267
269
|
unit: string;
|
|
270
|
+
gas_price?: BN;
|
|
271
|
+
gas_usage?: BigNumberish;
|
|
268
272
|
};
|
|
269
273
|
export declare type RawArgs = {
|
|
270
274
|
[inputName: string]:
|
package/utils/typedData/index.js
CHANGED
|
@@ -100,6 +100,11 @@ var getDependencies = function (typedData, type, dependencies) {
|
|
|
100
100
|
if (!(0, utils_1.validateTypedData)(typedData)) {
|
|
101
101
|
throw new Error('Typed data does not match JSON schema');
|
|
102
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
|
+
}
|
|
103
108
|
if (dependencies.includes(type)) {
|
|
104
109
|
return dependencies;
|
|
105
110
|
}
|
|
@@ -174,6 +179,19 @@ var encodeValue = function (typedData, type, data) {
|
|
|
174
179
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
175
180
|
return [type, (0, exports.getStructHash)(typedData, type, data)];
|
|
176
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
|
+
}
|
|
177
195
|
if (type === 'felt*') {
|
|
178
196
|
return ['felt*', (0, hash_1.computeHashOnElements)(data)];
|
|
179
197
|
}
|