starknet 3.18.0 → 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.
- package/CHANGELOG.md +65 -0
- package/README.md +1 -0
- package/__mocks__/typedDataStructArrayExample.json +44 -0
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/__tests__/utils/typedData.test.ts +24 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -410
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +443 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/dist/utils/typedData/index.js +14 -0
- package/index.js +42 -75
- package/package.json +1 -1
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -703
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +443 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -394
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +300 -0
- package/src/provider/sequencer.ts +384 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/src/utils/typedData/index.ts +18 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -157
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- 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.
|
package/utils/typedData/index.js
CHANGED
|
@@ -1,87 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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,
|
|
64
|
-
exports.getMessageHash =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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,36 +66,25 @@ function getHex(value) {
|
|
|
93
66
|
* @return {string[]}
|
|
94
67
|
*/
|
|
95
68
|
var getDependencies = function (typedData, type, dependencies) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
__read(
|
|
116
|
-
(0, exports.getDependencies)(typedData, t.type, previous).filter(function (dependency) {
|
|
117
|
-
return !previous.includes(dependency);
|
|
118
|
-
})
|
|
119
|
-
),
|
|
120
|
-
false
|
|
121
|
-
);
|
|
122
|
-
}, [])
|
|
123
|
-
),
|
|
124
|
-
false
|
|
125
|
-
);
|
|
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);
|
|
126
88
|
};
|
|
127
89
|
exports.getDependencies = getDependencies;
|
|
128
90
|
/**
|
|
@@ -133,20 +95,13 @@ exports.getDependencies = getDependencies;
|
|
|
133
95
|
* @return {string}
|
|
134
96
|
*/
|
|
135
97
|
var encodeType = function (typedData, type) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.map(function (dependency) {
|
|
142
|
-
return ''.concat(dependency, '(').concat(
|
|
143
|
-
typedData.types[dependency].map(function (t) {
|
|
144
|
-
return ''.concat(t.name, ':').concat(t.type);
|
|
145
|
-
}),
|
|
146
|
-
')'
|
|
147
|
-
);
|
|
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); }), ")");
|
|
148
103
|
})
|
|
149
|
-
|
|
104
|
+
.join('');
|
|
150
105
|
};
|
|
151
106
|
exports.encodeType = encodeType;
|
|
152
107
|
/**
|
|
@@ -157,7 +112,7 @@ exports.encodeType = encodeType;
|
|
|
157
112
|
* @return {string}
|
|
158
113
|
*/
|
|
159
114
|
var getTypeHash = function (typedData, type) {
|
|
160
|
-
|
|
115
|
+
return (0, hash_1.getSelectorFromName)((0, exports.encodeType)(typedData, type));
|
|
161
116
|
};
|
|
162
117
|
exports.getTypeHash = getTypeHash;
|
|
163
118
|
/**
|
|
@@ -170,14 +125,23 @@ exports.getTypeHash = getTypeHash;
|
|
|
170
125
|
* @returns {[string, string]}
|
|
171
126
|
*/
|
|
172
127
|
var encodeValue = function (typedData, type, data) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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)];
|
|
181
145
|
};
|
|
182
146
|
/**
|
|
183
147
|
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
|
|
@@ -188,31 +152,19 @@ var encodeValue = function (typedData, type, data) {
|
|
|
188
152
|
* @param {Record<string, any>} data
|
|
189
153
|
*/
|
|
190
154
|
var encodeData = function (typedData, type, data) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
var _b = __read(_a, 2),
|
|
195
|
-
ts = _b[0],
|
|
196
|
-
vs = _b[1];
|
|
197
|
-
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) {
|
|
198
158
|
throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
encodedValue = _c[1];
|
|
204
|
-
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 [
|
|
205
163
|
__spreadArray(__spreadArray([], __read(ts), false), [t], false),
|
|
206
164
|
__spreadArray(__spreadArray([], __read(vs), false), [encodedValue], false),
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
),
|
|
211
|
-
2
|
|
212
|
-
),
|
|
213
|
-
types = _a[0],
|
|
214
|
-
values = _a[1];
|
|
215
|
-
return [types, values];
|
|
165
|
+
];
|
|
166
|
+
}, [['felt'], [(0, exports.getTypeHash)(typedData, type)]]), 2), types = _a[0], values = _a[1];
|
|
167
|
+
return [types, values];
|
|
216
168
|
};
|
|
217
169
|
exports.encodeData = encodeData;
|
|
218
170
|
/**
|
|
@@ -225,7 +177,7 @@ exports.encodeData = encodeData;
|
|
|
225
177
|
* @return {Buffer}
|
|
226
178
|
*/
|
|
227
179
|
var getStructHash = function (typedData, type, data) {
|
|
228
|
-
|
|
180
|
+
return (0, hash_1.computeHashOnElements)((0, exports.encodeData)(typedData, type, data)[1]);
|
|
229
181
|
};
|
|
230
182
|
exports.getStructHash = getStructHash;
|
|
231
183
|
/**
|
|
@@ -237,12 +189,12 @@ exports.getStructHash = getStructHash;
|
|
|
237
189
|
* @return {string}
|
|
238
190
|
*/
|
|
239
191
|
var getMessageHash = function (typedData, account) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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);
|
|
247
199
|
};
|
|
248
200
|
exports.getMessageHash = getMessageHash;
|
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
* standard.
|
|
6
6
|
*/
|
|
7
7
|
export interface StarkNetType {
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
types: Record<string, StarkNetType[]>;
|
|
24
|
+
primaryType: string;
|
|
25
|
+
domain: StarkNetDomain;
|
|
26
|
+
message: Record<string, unknown>;
|
|
27
27
|
}
|
package/utils/typedData/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/utils/typedData/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
package/utils/uint256.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { BigNumberish } from './number';
|
|
3
3
|
export interface Uint256 {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
low: BigNumberish;
|
|
5
|
+
high: BigNumberish;
|
|
6
6
|
}
|
|
7
|
-
export declare function uint256ToBN(uint256: Uint256): import(
|
|
8
|
-
export declare const UINT_128_MAX: import(
|
|
9
|
-
export declare const UINT_256_MAX: import(
|
|
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
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.bnToUint256 =
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
package/www/docs/API/account.md
CHANGED
|
@@ -43,8 +43,9 @@ The _options_ object may include any of:
|
|
|
43
43
|
|
|
44
44
|
```
|
|
45
45
|
{
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
package/www/docs/API/contract.md
CHANGED
|
@@ -22,9 +22,9 @@ contract.**address** => _string_
|
|
|
22
22
|
|
|
23
23
|
The address the contract was constructed/connected with
|
|
24
24
|
|
|
25
|
-
contract.**providerOrAcount** =>
|
|
25
|
+
contract.**providerOrAcount** => ProviderInterface | AccountInterface_
|
|
26
26
|
|
|
27
|
-
Provider or
|
|
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** =>
|
|
29
|
+
contractFactory.**providerOrAccount** => _ProviderInterface | AccountInterface_;
|
|
30
30
|
|
|
31
|
-
Provider or
|
|
31
|
+
Provider or account that are used to interact with the network
|
|
32
32
|
|
|
33
33
|
## Methods
|
|
34
34
|
|