starknet 3.17.0 → 3.18.2
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/README.md +1 -0
- package/__mocks__/typedDataStructArrayExample.json +44 -0
- package/__tests__/utils/typedData.test.ts +24 -0
- package/dist/provider/default.js +2 -1
- package/dist/types/api.d.ts +1 -0
- package/dist/utils/typedData/index.js +14 -0
- package/package.json +1 -1
- package/provider/default.js +2 -1
- package/src/provider/default.ts +1 -0
- package/src/types/api.ts +1 -0
- package/src/utils/typedData/index.ts +18 -0
- package/types/api.d.ts +1 -0
- 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.2](https://github.com/0xs34n/starknet.js/compare/v3.18.1...v3.18.2) (2022-07-25)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- release to [@next](https://github.com/next) ([12e37ce](https://github.com/0xs34n/starknet.js/commit/12e37cef78bc0e9d97d25c44d0dcf576969cb182))
|
|
6
|
+
|
|
7
|
+
## [3.18.1](https://github.com/0xs34n/starknet.js/compare/v3.18.0...v3.18.1) (2022-07-23)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- struct array hashing ([e1f82df](https://github.com/0xs34n/starknet.js/commit/e1f82dfd575be4c84b291c33f8169bf367493603))
|
|
12
|
+
|
|
13
|
+
# [3.18.0](https://github.com/0xs34n/starknet.js/compare/v3.17.0...v3.18.0) (2022-07-23)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- **cairo-0.9.1:** starknet_version in block response ([e88154d](https://github.com/0xs34n/starknet.js/commit/e88154d5f6fcd6695dca5d29da04d18d0a65cdf6))
|
|
18
|
+
|
|
1
19
|
# [3.17.0](https://github.com/0xs34n/starknet.js/compare/v3.16.3...v3.17.0) (2022-07-15)
|
|
2
20
|
|
|
3
21
|
### Features
|
package/README.md
CHANGED
|
@@ -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/dist/provider/default.js
CHANGED
|
@@ -68,6 +68,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
68
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
69
|
exports.Provider = void 0;
|
|
70
70
|
var url_join_1 = __importDefault(require("url-join"));
|
|
71
|
+
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
71
72
|
var constants_1 = require("../constants");
|
|
72
73
|
var hash_1 = require("../utils/hash");
|
|
73
74
|
var json_1 = require("../utils/json");
|
|
@@ -196,7 +197,7 @@ var Provider = /** @class */ (function () {
|
|
|
196
197
|
_c.label = 1;
|
|
197
198
|
case 1:
|
|
198
199
|
_c.trys.push([1, 4, , 5]);
|
|
199
|
-
return [4 /*yield*/,
|
|
200
|
+
return [4 /*yield*/, (0, cross_fetch_1.default)(url, {
|
|
200
201
|
method: method,
|
|
201
202
|
body: (0, json_1.stringify)(request),
|
|
202
203
|
headers: headers,
|
package/dist/types/api.d.ts
CHANGED
|
@@ -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/provider/default.js
CHANGED
|
@@ -174,6 +174,7 @@ var __importDefault =
|
|
|
174
174
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
175
175
|
exports.Provider = void 0;
|
|
176
176
|
var url_join_1 = __importDefault(require('url-join'));
|
|
177
|
+
var cross_fetch_1 = __importDefault(require('cross-fetch'));
|
|
177
178
|
var constants_1 = require('../constants');
|
|
178
179
|
var hash_1 = require('../utils/hash');
|
|
179
180
|
var json_1 = require('../utils/json');
|
|
@@ -322,7 +323,7 @@ var Provider = /** @class */ (function () {
|
|
|
322
323
|
_c.trys.push([1, 4, , 5]);
|
|
323
324
|
return [
|
|
324
325
|
4 /*yield*/,
|
|
325
|
-
|
|
326
|
+
(0, cross_fetch_1.default)(url, {
|
|
326
327
|
method: method,
|
|
327
328
|
body: (0, json_1.stringify)(request),
|
|
328
329
|
headers: headers,
|
package/src/provider/default.ts
CHANGED
package/src/types/api.ts
CHANGED
|
@@ -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/api.d.ts
CHANGED
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
|
}
|