starknet 3.18.2 → 4.0.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 +70 -0
- package/README.md +1 -2
- 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__/jest.setup.ts +2 -3
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -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 -411
- 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 +444 -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/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -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/index.js +42 -75
- package/package.json +2 -3
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- 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 +444 -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 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +299 -0
- package/src/provider/sequencer.ts +385 -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/fetchPonyfill.ts +4 -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/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/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- 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 -175
- 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
package/utils/hash.js
CHANGED
|
@@ -1,69 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
var __read =
|
|
3
|
-
|
|
4
|
-
function (o, n) {
|
|
5
|
-
var m = typeof Symbol === 'function' && o[Symbol.iterator];
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
6
4
|
if (!m) return o;
|
|
7
|
-
var i = m.call(o),
|
|
8
|
-
r,
|
|
9
|
-
ar = [],
|
|
10
|
-
e;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
11
6
|
try {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (e) throw e.error;
|
|
20
|
-
}
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
21
15
|
}
|
|
22
16
|
return ar;
|
|
23
|
-
|
|
24
|
-
var __spreadArray =
|
|
25
|
-
|
|
26
|
-
function (to, from, pack) {
|
|
27
|
-
if (pack || arguments.length === 2)
|
|
28
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
20
|
if (ar || !(i in from)) {
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
32
23
|
}
|
|
33
|
-
|
|
24
|
+
}
|
|
34
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
-
|
|
36
|
-
var __importDefault =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
exports.pedersen =
|
|
48
|
-
exports.getSelectorFromName =
|
|
49
|
-
exports.starknetKeccak =
|
|
50
|
-
exports.feeTransactionVersion =
|
|
51
|
-
exports.transactionVersion =
|
|
52
|
-
void 0;
|
|
53
|
-
var keccak_1 = require('ethereum-cryptography/keccak');
|
|
54
|
-
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
55
|
-
var constants_1 = require('../constants');
|
|
56
|
-
var ellipticCurve_1 = require('./ellipticCurve');
|
|
57
|
-
var encode_1 = require('./encode');
|
|
58
|
-
var number_1 = require('./number');
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.calculateContractAddressFromHash = exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
|
+
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
|
+
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
34
|
+
var constants_1 = require("../constants");
|
|
35
|
+
var ellipticCurve_1 = require("./ellipticCurve");
|
|
36
|
+
var encode_1 = require("./encode");
|
|
37
|
+
var number_1 = require("./number");
|
|
59
38
|
exports.transactionVersion = 0;
|
|
60
|
-
exports.feeTransactionVersion = (0, number_1.toBN)(2)
|
|
61
|
-
.pow((0, number_1.toBN)(128))
|
|
62
|
-
.add((0, number_1.toBN)(exports.transactionVersion));
|
|
39
|
+
exports.feeTransactionVersion = (0, number_1.toBN)(2).pow((0, number_1.toBN)(128)).add((0, number_1.toBN)(exports.transactionVersion));
|
|
63
40
|
function keccakHex(value) {
|
|
64
|
-
|
|
65
|
-
(0, encode_1.buf2hex)((0, keccak_1.keccak256)((0, encode_1.utf8ToArray)(value)))
|
|
66
|
-
);
|
|
41
|
+
return (0, encode_1.addHexPrefix)((0, encode_1.buf2hex)((0, keccak_1.keccak256)((0, encode_1.utf8ToArray)(value))));
|
|
67
42
|
}
|
|
68
43
|
/**
|
|
69
44
|
* Function to get the starknet keccak hash from a string
|
|
@@ -73,7 +48,7 @@ function keccakHex(value) {
|
|
|
73
48
|
* @returns starknet keccak hash as BigNumber
|
|
74
49
|
*/
|
|
75
50
|
function starknetKeccak(value) {
|
|
76
|
-
|
|
51
|
+
return (0, number_1.toBN)(keccakHex(value)).and(constants_1.MASK_250);
|
|
77
52
|
}
|
|
78
53
|
exports.starknetKeccak = starknetKeccak;
|
|
79
54
|
/**
|
|
@@ -84,109 +59,69 @@ exports.starknetKeccak = starknetKeccak;
|
|
|
84
59
|
* @returns hex selector of given abi function name
|
|
85
60
|
*/
|
|
86
61
|
function getSelectorFromName(funcName) {
|
|
87
|
-
|
|
88
|
-
|
|
62
|
+
// sometimes BigInteger pads the hex string with zeros, which isnt allowed in the starknet api
|
|
63
|
+
return (0, number_1.toHex)(starknetKeccak(funcName));
|
|
89
64
|
}
|
|
90
65
|
exports.getSelectorFromName = getSelectorFromName;
|
|
91
66
|
var constantPoints = constants_1.CONSTANT_POINTS.map(function (coords) {
|
|
92
|
-
|
|
67
|
+
return ellipticCurve_1.ec.curve.point(coords[0], coords[1]);
|
|
93
68
|
});
|
|
94
69
|
function pedersen(input) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
point = point.add(pt);
|
|
108
|
-
}
|
|
109
|
-
x = x.shrn(1);
|
|
70
|
+
var point = constantPoints[0];
|
|
71
|
+
for (var i = 0; i < input.length; i += 1) {
|
|
72
|
+
var x = (0, number_1.toBN)(input[i]);
|
|
73
|
+
(0, minimalistic_assert_1.default)(x.gte(constants_1.ZERO) && x.lt((0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.FIELD_PRIME))), "Invalid input: ".concat(input[i]));
|
|
74
|
+
for (var j = 0; j < 252; j += 1) {
|
|
75
|
+
var pt = constantPoints[2 + i * 252 + j];
|
|
76
|
+
(0, minimalistic_assert_1.default)(!point.getX().eq(pt.getX()));
|
|
77
|
+
if (x.and(constants_1.ONE).toNumber() !== 0) {
|
|
78
|
+
point = point.add(pt);
|
|
79
|
+
}
|
|
80
|
+
x = x.shrn(1);
|
|
81
|
+
}
|
|
110
82
|
}
|
|
111
|
-
|
|
112
|
-
return (0, encode_1.addHexPrefix)(point.getX().toString(16));
|
|
83
|
+
return (0, encode_1.addHexPrefix)(point.getX().toString(16));
|
|
113
84
|
}
|
|
114
85
|
exports.pedersen = pedersen;
|
|
115
86
|
function computeHashOnElements(data) {
|
|
116
|
-
|
|
117
|
-
.reduce(function (x, y) {
|
|
118
|
-
return pedersen([x, y]);
|
|
119
|
-
}, 0)
|
|
120
|
-
.toString();
|
|
87
|
+
return __spreadArray(__spreadArray([], __read(data), false), [data.length], false).reduce(function (x, y) { return pedersen([x, y]); }, 0).toString();
|
|
121
88
|
}
|
|
122
89
|
exports.computeHashOnElements = computeHashOnElements;
|
|
123
90
|
// following implementation is based on this python implementation:
|
|
124
91
|
// https://github.com/starkware-libs/cairo-lang/blob/b614d1867c64f3fb2cf4a4879348cfcf87c3a5a7/src/starkware/starknet/core/os/transaction_hash/transaction_hash.py
|
|
125
|
-
function calculateTransactionHashCommon(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
additionalData
|
|
137
|
-
|
|
138
|
-
var calldataHash = computeHashOnElements(calldata);
|
|
139
|
-
var dataToHash = __spreadArray(
|
|
140
|
-
[txHashPrefix, version, contractAddress, entryPointSelector, calldataHash, maxFee, chainId],
|
|
141
|
-
__read(additionalData),
|
|
142
|
-
false
|
|
143
|
-
);
|
|
144
|
-
return computeHashOnElements(dataToHash);
|
|
92
|
+
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData) {
|
|
93
|
+
if (additionalData === void 0) { additionalData = []; }
|
|
94
|
+
var calldataHash = computeHashOnElements(calldata);
|
|
95
|
+
var dataToHash = __spreadArray([
|
|
96
|
+
txHashPrefix,
|
|
97
|
+
version,
|
|
98
|
+
contractAddress,
|
|
99
|
+
entryPointSelector,
|
|
100
|
+
calldataHash,
|
|
101
|
+
maxFee,
|
|
102
|
+
chainId
|
|
103
|
+
], __read(additionalData), false);
|
|
104
|
+
return computeHashOnElements(dataToHash);
|
|
145
105
|
}
|
|
146
106
|
exports.calculateTransactionHashCommon = calculateTransactionHashCommon;
|
|
147
107
|
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
148
|
-
|
|
149
|
-
constants_1.TransactionHashPrefix.DEPLOY,
|
|
150
|
-
version,
|
|
151
|
-
contractAddress,
|
|
152
|
-
getSelectorFromName('constructor'),
|
|
153
|
-
constructorCalldata,
|
|
154
|
-
constants_1.ZERO,
|
|
155
|
-
chainId
|
|
156
|
-
);
|
|
108
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DEPLOY, version, contractAddress, getSelectorFromName('constructor'), constructorCalldata, constants_1.ZERO, chainId);
|
|
157
109
|
}
|
|
158
110
|
exports.calculateDeployTransactionHash = calculateDeployTransactionHash;
|
|
159
|
-
function calculcateTransactionHash(
|
|
160
|
-
|
|
161
|
-
version,
|
|
162
|
-
entryPointSelector,
|
|
163
|
-
calldata,
|
|
164
|
-
maxFee,
|
|
165
|
-
chainId
|
|
166
|
-
) {
|
|
167
|
-
return calculateTransactionHashCommon(
|
|
168
|
-
constants_1.TransactionHashPrefix.INVOKE,
|
|
169
|
-
version,
|
|
170
|
-
contractAddress,
|
|
171
|
-
entryPointSelector,
|
|
172
|
-
calldata,
|
|
173
|
-
maxFee,
|
|
174
|
-
chainId
|
|
175
|
-
);
|
|
111
|
+
function calculcateTransactionHash(contractAddress, version, entryPointSelector, calldata, maxFee, chainId) {
|
|
112
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress, entryPointSelector, calldata, maxFee, chainId);
|
|
176
113
|
}
|
|
177
114
|
exports.calculcateTransactionHash = calculcateTransactionHash;
|
|
178
115
|
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
];
|
|
190
|
-
return computeHashOnElements(dataToHash);
|
|
116
|
+
var constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
117
|
+
var CONTRACT_ADDRESS_PREFIX = (0, number_1.toFelt)('0x535441524b4e45545f434f4e54524143545f41444452455353'); // Equivalent to 'STARKNET_CONTRACT_ADDRESS'
|
|
118
|
+
var dataToHash = [
|
|
119
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
120
|
+
deployerAddress,
|
|
121
|
+
salt,
|
|
122
|
+
classHash,
|
|
123
|
+
constructorCalldataHash,
|
|
124
|
+
];
|
|
125
|
+
return computeHashOnElements(dataToHash);
|
|
191
126
|
}
|
|
192
127
|
exports.calculateContractAddressFromHash = calculateContractAddressFromHash;
|
package/utils/json.d.ts
CHANGED
|
@@ -1,48 +1,16 @@
|
|
|
1
|
-
export declare const parse: (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
space?: string | number | undefined
|
|
10
|
-
): string;
|
|
11
|
-
(
|
|
12
|
-
value: any,
|
|
13
|
-
replacer?: (string | number)[] | null | undefined,
|
|
14
|
-
space?: string | number | undefined
|
|
15
|
-
): string;
|
|
16
|
-
};
|
|
17
|
-
export declare const parseAlwaysAsBig: (
|
|
18
|
-
text: string,
|
|
19
|
-
reviver?: ((this: any, key: string, value: any) => any) | undefined
|
|
20
|
-
) => any,
|
|
21
|
-
stringifyAlwaysAsBig: {
|
|
22
|
-
(
|
|
23
|
-
value: any,
|
|
24
|
-
replacer?: ((this: any, key: string, value: any) => any) | undefined,
|
|
25
|
-
space?: string | number | undefined
|
|
26
|
-
): string;
|
|
27
|
-
(
|
|
28
|
-
value: any,
|
|
29
|
-
replacer?: (string | number)[] | null | undefined,
|
|
30
|
-
space?: string | number | undefined
|
|
31
|
-
): string;
|
|
32
|
-
};
|
|
1
|
+
export declare const parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any, stringify: {
|
|
2
|
+
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
3
|
+
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
4
|
+
};
|
|
5
|
+
export declare const parseAlwaysAsBig: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any, stringifyAlwaysAsBig: {
|
|
6
|
+
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
7
|
+
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
8
|
+
};
|
|
33
9
|
declare const _default: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
space?: string | number | undefined
|
|
40
|
-
): string;
|
|
41
|
-
(
|
|
42
|
-
value: any,
|
|
43
|
-
replacer?: (string | number)[] | null | undefined,
|
|
44
|
-
space?: string | number | undefined
|
|
45
|
-
): string;
|
|
46
|
-
};
|
|
10
|
+
parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
|
|
11
|
+
stringify: {
|
|
12
|
+
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
13
|
+
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
14
|
+
};
|
|
47
15
|
};
|
|
48
16
|
export default _default;
|
package/utils/json.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
7
5
|
var _a, _b;
|
|
8
|
-
Object.defineProperty(exports,
|
|
9
|
-
exports.stringifyAlwaysAsBig =
|
|
10
|
-
|
|
11
|
-
exports.stringify =
|
|
12
|
-
exports.parse =
|
|
13
|
-
void 0;
|
|
14
|
-
var json_bigint_1 = __importDefault(require('json-bigint'));
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.stringifyAlwaysAsBig = exports.parseAlwaysAsBig = exports.stringify = exports.parse = void 0;
|
|
8
|
+
var json_bigint_1 = __importDefault(require("json-bigint"));
|
|
15
9
|
var json = function (alwaysParseAsBig) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
return (0, json_bigint_1.default)({
|
|
11
|
+
alwaysParseAsBig: alwaysParseAsBig,
|
|
12
|
+
useNativeBigInt: true,
|
|
13
|
+
protoAction: 'preserve',
|
|
14
|
+
constructorAction: 'preserve',
|
|
15
|
+
});
|
|
22
16
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(exports.stringifyAlwaysAsBig = _b.stringify);
|
|
17
|
+
exports.parse = (_a = json(false), _a.parse), exports.stringify = _a.stringify;
|
|
18
|
+
exports.parseAlwaysAsBig = (_b = json(true), _b.parse), exports.stringifyAlwaysAsBig = _b.stringify;
|
|
26
19
|
exports.default = { parse: exports.parse, stringify: exports.stringify };
|
package/utils/number.d.ts
CHANGED
|
@@ -5,12 +5,5 @@ export declare function toBN(number: BigNumberish, base?: number | 'hex'): BN;
|
|
|
5
5
|
export declare function toHex(number: BN): string;
|
|
6
6
|
export declare function hexToDecimalString(hex: string): string;
|
|
7
7
|
export declare function toFelt(num: BigNumberish): string;
|
|
8
|
-
export declare function assertInRange(
|
|
9
|
-
|
|
10
|
-
lowerBound: BigNumberish,
|
|
11
|
-
upperBound: BigNumberish,
|
|
12
|
-
inputName?: string
|
|
13
|
-
): void;
|
|
14
|
-
export declare function bigNumberishArrayToDecimalStringArray(
|
|
15
|
-
rawCalldata: BigNumberish[]
|
|
16
|
-
): string[];
|
|
8
|
+
export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
|
|
9
|
+
export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
|
package/utils/number.js
CHANGED
|
@@ -1,89 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
});
|
|
22
|
-
var __setModuleDefault =
|
|
23
|
-
(this && this.__setModuleDefault) ||
|
|
24
|
-
(Object.create
|
|
25
|
-
? function (o, v) {
|
|
26
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
27
|
-
}
|
|
28
|
-
: function (o, v) {
|
|
29
|
-
o['default'] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar =
|
|
32
|
-
(this && this.__importStar) ||
|
|
33
|
-
function (mod) {
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
19
|
if (mod && mod.__esModule) return mod;
|
|
35
20
|
var result = {};
|
|
36
|
-
if (mod != null)
|
|
37
|
-
for (var k in mod)
|
|
38
|
-
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
39
|
-
__createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
40
22
|
__setModuleDefault(result, mod);
|
|
41
23
|
return result;
|
|
42
|
-
|
|
43
|
-
var __importDefault =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
exports.toFelt =
|
|
52
|
-
exports.hexToDecimalString =
|
|
53
|
-
exports.toHex =
|
|
54
|
-
exports.toBN =
|
|
55
|
-
exports.isHex =
|
|
56
|
-
void 0;
|
|
57
|
-
var bn_js_1 = __importStar(require('bn.js'));
|
|
58
|
-
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
59
|
-
var encode_1 = require('./encode');
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
|
|
30
|
+
var bn_js_1 = __importStar(require("bn.js"));
|
|
31
|
+
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
32
|
+
var encode_1 = require("./encode");
|
|
60
33
|
function isHex(hex) {
|
|
61
|
-
|
|
34
|
+
return hex.startsWith('0x');
|
|
62
35
|
}
|
|
63
36
|
exports.isHex = isHex;
|
|
64
37
|
function toBN(number, base) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
if (typeof number === 'string') {
|
|
39
|
+
// eslint-disable-next-line no-param-reassign
|
|
40
|
+
number = number.toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
if (typeof number === 'string' && isHex(number) && !base)
|
|
43
|
+
return new bn_js_1.default((0, encode_1.removeHexPrefix)(number), 'hex');
|
|
44
|
+
return new bn_js_1.default(number, base);
|
|
72
45
|
}
|
|
73
46
|
exports.toBN = toBN;
|
|
74
47
|
function toHex(number) {
|
|
75
|
-
|
|
48
|
+
return (0, encode_1.addHexPrefix)(number.toString('hex'));
|
|
76
49
|
}
|
|
77
50
|
exports.toHex = toHex;
|
|
78
51
|
function hexToDecimalString(hex) {
|
|
79
|
-
|
|
52
|
+
return toBN("0x".concat(hex.replace(/^0x/, ''))).toString();
|
|
80
53
|
}
|
|
81
54
|
exports.hexToDecimalString = hexToDecimalString;
|
|
82
55
|
function toFelt(num) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
56
|
+
if ((0, bn_js_1.isBN)(num)) {
|
|
57
|
+
return num.toString();
|
|
58
|
+
}
|
|
59
|
+
return toBN(num).toString();
|
|
87
60
|
}
|
|
88
61
|
exports.toFelt = toFelt;
|
|
89
62
|
/*
|
|
@@ -93,20 +66,13 @@ exports.toFelt = toFelt;
|
|
|
93
66
|
inputName should be a string.
|
|
94
67
|
*/
|
|
95
68
|
function assertInRange(input, lowerBound, upperBound, inputName) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var inputBn = toBN(input);
|
|
101
|
-
(0, minimalistic_assert_1.default)(
|
|
102
|
-
inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)),
|
|
103
|
-
'Message not signable, '.concat(messageSuffix, '.')
|
|
104
|
-
);
|
|
69
|
+
if (inputName === void 0) { inputName = ''; }
|
|
70
|
+
var messageSuffix = inputName === '' ? 'invalid length' : "invalid ".concat(inputName, " length");
|
|
71
|
+
var inputBn = toBN(input);
|
|
72
|
+
(0, minimalistic_assert_1.default)(inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)), "Message not signable, ".concat(messageSuffix, "."));
|
|
105
73
|
}
|
|
106
74
|
exports.assertInRange = assertInRange;
|
|
107
75
|
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
108
|
-
|
|
109
|
-
return toBN(x).toString(10);
|
|
110
|
-
});
|
|
76
|
+
return rawCalldata.map(function (x) { return toBN(x).toString(10); });
|
|
111
77
|
}
|
|
112
78
|
exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CompiledContract, ContractClass, RawCalldata } from '../types';
|
|
2
|
+
export declare function wait(delay: number): Promise<unknown>;
|
|
3
|
+
export declare function parseCalldata(calldata?: RawCalldata): string[];
|
|
4
|
+
export declare function parseContract(contract: CompiledContract | string): ContractClass;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.parseContract = exports.parseCalldata = exports.wait = void 0;
|
|
15
|
+
var json_1 = require("./json");
|
|
16
|
+
var number_1 = require("./number");
|
|
17
|
+
var stark_1 = require("./stark");
|
|
18
|
+
function wait(delay) {
|
|
19
|
+
return new Promise(function (res) {
|
|
20
|
+
setTimeout(res, delay);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.wait = wait;
|
|
24
|
+
function parseCalldata(calldata) {
|
|
25
|
+
if (calldata === void 0) { calldata = []; }
|
|
26
|
+
return calldata.map(function (data) {
|
|
27
|
+
if (typeof data === 'string' && (0, number_1.isHex)(data)) {
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
return (0, number_1.toHex)((0, number_1.toBN)(data));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.parseCalldata = parseCalldata;
|
|
34
|
+
function parseContract(contract) {
|
|
35
|
+
var parsedContract = typeof contract === 'string' ? (0, json_1.parse)(contract) : contract;
|
|
36
|
+
return __assign(__assign({}, parsedContract), { program: (0, stark_1.compressProgram)(parsedContract.program) });
|
|
37
|
+
}
|
|
38
|
+
exports.parseContract = parseContract;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
|
|
2
|
+
export declare abstract class ResponseParser {
|
|
3
|
+
abstract parseGetBlockResponse(res: any): GetBlockResponse;
|
|
4
|
+
abstract parseGetTransactionResponse(res: any): GetTransactionResponse;
|
|
5
|
+
abstract parseGetTransactionReceiptResponse(res: any): GetTransactionReceiptResponse;
|
|
6
|
+
abstract parseFeeEstimateResponse(res: any): EstimateFeeResponse;
|
|
7
|
+
abstract parseCallContractResponse(res: any): CallContractResponse;
|
|
8
|
+
abstract parseInvokeFunctionResponse(res: any): InvokeFunctionResponse;
|
|
9
|
+
abstract parseDeployContractResponse(res: any): DeployContractResponse;
|
|
10
|
+
abstract parseDeclareContractResponse(res: any): DeclareContractResponse;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseParser = void 0;
|
|
4
|
+
var ResponseParser = /** @class */ (function () {
|
|
5
|
+
function ResponseParser() {
|
|
6
|
+
}
|
|
7
|
+
return ResponseParser;
|
|
8
|
+
}());
|
|
9
|
+
exports.ResponseParser = ResponseParser;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
|
|
2
|
+
import { RPC } from '../../types/api';
|
|
3
|
+
import { ResponseParser } from '.';
|
|
4
|
+
export declare class RPCResponseParser extends ResponseParser {
|
|
5
|
+
parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse;
|
|
6
|
+
parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse;
|
|
7
|
+
parseGetTransactionReceiptResponse(res: RPC.GetTransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
|
+
parseCallContractResponse(res: Array<string>): CallContractResponse;
|
|
10
|
+
parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse;
|
|
11
|
+
parseDeployContractResponse(res: RPC.DeployContractResponse): DeployContractResponse;
|
|
12
|
+
parseDeclareContractResponse(res: RPC.DeclareResponse): DeclareContractResponse;
|
|
13
|
+
}
|