starknet 2.3.1 → 2.7.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 +43 -0
- package/__tests__/account.test.ts +3 -3
- package/__tests__/provider.test.ts +24 -13
- package/__tests__/signer.test.ts +17 -0
- package/__tests__/utils/ellipticalCurve.test.ts +1 -1
- package/__tests__/utils/typedData.test.ts +72 -0
- package/contract.d.ts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +26 -22
- package/dist/provider/default.js +64 -47
- package/dist/provider/interface.d.ts +25 -21
- package/dist/provider/utils.d.ts +27 -0
- package/dist/provider/utils.js +37 -0
- package/dist/signer/default.d.ts +20 -3
- package/dist/signer/default.js +61 -20
- package/dist/signer/interface.d.ts +22 -3
- package/dist/types.d.ts +10 -7
- package/dist/utils/ellipticCurve.d.ts +8 -1
- package/dist/utils/ellipticCurve.js +48 -9
- package/dist/utils/stark.d.ts +2 -3
- package/dist/utils/typedData/index.d.ts +91 -0
- package/dist/utils/typedData/index.js +183 -0
- package/dist/utils/typedData/types.d.ts +82 -0
- package/dist/utils/typedData/types.js +47 -0
- package/dist/utils/typedData/utils.d.ts +24 -0
- package/dist/utils/typedData/utils.js +15 -0
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +3 -1
- package/provider/default.d.ts +40 -21
- package/provider/default.js +85 -53
- package/provider/interface.d.ts +37 -21
- package/provider/utils.d.ts +30 -0
- package/provider/utils.js +39 -0
- package/signer/default.d.ts +20 -3
- package/signer/default.js +60 -17
- package/signer/interface.d.ts +22 -3
- package/src/contract.ts +2 -2
- package/src/index.ts +1 -0
- package/src/provider/default.ts +65 -40
- package/src/provider/interface.ts +36 -21
- package/src/provider/utils.ts +38 -0
- package/src/signer/default.ts +49 -17
- package/src/signer/interface.ts +26 -3
- package/src/types.ts +16 -7
- package/src/utils/ellipticCurve.ts +31 -9
- package/src/utils/stark.ts +4 -4
- package/src/utils/typedData/index.ts +176 -0
- package/src/utils/typedData/types.ts +82 -0
- package/src/utils/typedData/utils.ts +13 -0
- package/types.d.ts +12 -8
- package/utils/ellipticCurve.d.ts +12 -1
- package/utils/ellipticCurve.js +72 -23
- package/utils/stark.d.ts +2 -3
- package/utils/typedData/index.d.ts +113 -0
- package/utils/typedData/index.js +247 -0
- package/utils/typedData/types.d.ts +103 -0
- package/utils/typedData/types.js +57 -0
- package/utils/typedData/utils.d.ts +27 -0
- package/utils/typedData/utils.js +15 -0
package/dist/provider/default.js
CHANGED
|
@@ -56,12 +56,13 @@ var url_join_1 = __importDefault(require("url-join"));
|
|
|
56
56
|
var json_1 = require("../utils/json");
|
|
57
57
|
var number_1 = require("../utils/number");
|
|
58
58
|
var stark_1 = require("../utils/stark");
|
|
59
|
+
var utils_1 = require("./utils");
|
|
59
60
|
function wait(delay) {
|
|
60
61
|
return new Promise(function (res) { return setTimeout(res, delay); });
|
|
61
62
|
}
|
|
62
63
|
var Provider = /** @class */ (function () {
|
|
63
64
|
function Provider(optionsOrProvider) {
|
|
64
|
-
if (optionsOrProvider === void 0) { optionsOrProvider = { network: '
|
|
65
|
+
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
65
66
|
if (optionsOrProvider instanceof Provider) {
|
|
66
67
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
67
68
|
this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
|
|
@@ -80,7 +81,7 @@ var Provider = /** @class */ (function () {
|
|
|
80
81
|
switch (name) {
|
|
81
82
|
case 'mainnet-alpha':
|
|
82
83
|
return 'https://alpha-mainnet.starknet.io';
|
|
83
|
-
case '
|
|
84
|
+
case 'goerli-alpha':
|
|
84
85
|
default:
|
|
85
86
|
return 'https://alpha4.starknet.io';
|
|
86
87
|
}
|
|
@@ -107,18 +108,22 @@ var Provider = /** @class */ (function () {
|
|
|
107
108
|
/**
|
|
108
109
|
* Calls a function on the StarkNet contract.
|
|
109
110
|
*
|
|
110
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
111
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
111
112
|
*
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
113
|
+
* @param invokeTransaction - transaction to be invoked
|
|
114
|
+
* @param blockHash
|
|
115
|
+
* @param blockNumber
|
|
114
116
|
* @returns the result of the function on the smart contract.
|
|
115
117
|
*/
|
|
116
|
-
Provider.prototype.callContract = function (
|
|
118
|
+
Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
|
|
119
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
117
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var data;
|
|
121
|
+
var formattedBlockIdentifier, data;
|
|
119
122
|
return __generator(this, function (_a) {
|
|
120
123
|
switch (_a.label) {
|
|
121
|
-
case 0:
|
|
124
|
+
case 0:
|
|
125
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
126
|
+
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier), __assign({ signature: [], calldata: [] }, invokeTransaction))];
|
|
122
127
|
case 1:
|
|
123
128
|
data = (_a.sent()).data;
|
|
124
129
|
return [2 /*return*/, data];
|
|
@@ -127,19 +132,23 @@ var Provider = /** @class */ (function () {
|
|
|
127
132
|
});
|
|
128
133
|
};
|
|
129
134
|
/**
|
|
130
|
-
* Gets the block information
|
|
135
|
+
* Gets the block information
|
|
131
136
|
*
|
|
132
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
137
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
133
138
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @
|
|
139
|
+
* @param blockHash
|
|
140
|
+
* @param blockNumber
|
|
141
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
136
142
|
*/
|
|
137
|
-
Provider.prototype.getBlock = function (
|
|
143
|
+
Provider.prototype.getBlock = function (blockHash, blockNumber) {
|
|
144
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
138
145
|
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
var data;
|
|
146
|
+
var formattedBlockIdentifier, data;
|
|
140
147
|
return __generator(this, function (_a) {
|
|
141
148
|
switch (_a.label) {
|
|
142
|
-
case 0:
|
|
149
|
+
case 0:
|
|
150
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
151
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier))];
|
|
143
152
|
case 1:
|
|
144
153
|
data = (_a.sent()).data;
|
|
145
154
|
return [2 /*return*/, data];
|
|
@@ -150,18 +159,22 @@ var Provider = /** @class */ (function () {
|
|
|
150
159
|
/**
|
|
151
160
|
* Gets the code of the deployed contract.
|
|
152
161
|
*
|
|
153
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
162
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
154
163
|
*
|
|
155
164
|
* @param contractAddress
|
|
156
|
-
* @param
|
|
165
|
+
* @param blockHash
|
|
166
|
+
* @param blockNumber
|
|
157
167
|
* @returns Bytecode and ABI of compiled contract
|
|
158
168
|
*/
|
|
159
|
-
Provider.prototype.getCode = function (contractAddress,
|
|
169
|
+
Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
|
|
170
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
160
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
-
var data;
|
|
172
|
+
var formattedBlockIdentifier, data;
|
|
162
173
|
return __generator(this, function (_a) {
|
|
163
174
|
switch (_a.label) {
|
|
164
|
-
case 0:
|
|
175
|
+
case 0:
|
|
176
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
177
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&" + formattedBlockIdentifier))];
|
|
165
178
|
case 1:
|
|
166
179
|
data = (_a.sent()).data;
|
|
167
180
|
return [2 /*return*/, data];
|
|
@@ -173,19 +186,23 @@ var Provider = /** @class */ (function () {
|
|
|
173
186
|
/**
|
|
174
187
|
* Gets the contract's storage variable at a specific key.
|
|
175
188
|
*
|
|
176
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
189
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
177
190
|
*
|
|
178
191
|
* @param contractAddress
|
|
179
192
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
180
|
-
* @param
|
|
193
|
+
* @param blockHash
|
|
194
|
+
* @param blockNumber
|
|
181
195
|
* @returns the value of the storage variable
|
|
182
196
|
*/
|
|
183
|
-
Provider.prototype.getStorageAt = function (contractAddress, key,
|
|
197
|
+
Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
|
|
198
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
184
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var data;
|
|
200
|
+
var formattedBlockIdentifier, data;
|
|
186
201
|
return __generator(this, function (_a) {
|
|
187
202
|
switch (_a.label) {
|
|
188
|
-
case 0:
|
|
203
|
+
case 0:
|
|
204
|
+
formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
|
|
205
|
+
return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&" + formattedBlockIdentifier))];
|
|
189
206
|
case 1:
|
|
190
207
|
data = (_a.sent()).data;
|
|
191
208
|
return [2 /*return*/, data];
|
|
@@ -199,7 +216,7 @@ var Provider = /** @class */ (function () {
|
|
|
199
216
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
200
217
|
*
|
|
201
218
|
* @param txHash
|
|
202
|
-
* @returns the transaction status object {
|
|
219
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
203
220
|
*/
|
|
204
221
|
Provider.prototype.getTransactionStatus = function (txHash) {
|
|
205
222
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -222,7 +239,7 @@ var Provider = /** @class */ (function () {
|
|
|
222
239
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
223
240
|
*
|
|
224
241
|
* @param txHash
|
|
225
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
242
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
226
243
|
*/
|
|
227
244
|
Provider.prototype.getTransaction = function (txHash) {
|
|
228
245
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -244,18 +261,18 @@ var Provider = /** @class */ (function () {
|
|
|
244
261
|
*
|
|
245
262
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
246
263
|
*
|
|
247
|
-
* @param
|
|
264
|
+
* @param transaction - transaction to be invoked
|
|
248
265
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
249
266
|
*/
|
|
250
|
-
Provider.prototype.addTransaction = function (
|
|
267
|
+
Provider.prototype.addTransaction = function (transaction) {
|
|
251
268
|
return __awaiter(this, void 0, void 0, function () {
|
|
252
269
|
var signature, contract_address_salt, data;
|
|
253
270
|
return __generator(this, function (_a) {
|
|
254
271
|
switch (_a.label) {
|
|
255
272
|
case 0:
|
|
256
|
-
signature =
|
|
257
|
-
contract_address_salt =
|
|
258
|
-
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({},
|
|
273
|
+
signature = transaction.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(transaction.signature);
|
|
274
|
+
contract_address_salt = transaction.type === 'DEPLOY' && (0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
|
|
275
|
+
return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({}, transaction), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
|
|
259
276
|
case 1:
|
|
260
277
|
data = (_a.sent()).data;
|
|
261
278
|
return [2 /*return*/, data];
|
|
@@ -303,35 +320,35 @@ var Provider = /** @class */ (function () {
|
|
|
303
320
|
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|
|
304
321
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
305
322
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var onchain, res;
|
|
323
|
+
var onchain, res, error;
|
|
307
324
|
return __generator(this, function (_a) {
|
|
308
325
|
switch (_a.label) {
|
|
309
326
|
case 0:
|
|
310
327
|
onchain = false;
|
|
311
|
-
|
|
328
|
+
return [4 /*yield*/, wait(retryInterval)];
|
|
312
329
|
case 1:
|
|
313
|
-
|
|
330
|
+
_a.sent();
|
|
331
|
+
_a.label = 2;
|
|
332
|
+
case 2:
|
|
333
|
+
if (!!onchain) return [3 /*break*/, 5];
|
|
314
334
|
// eslint-disable-next-line no-await-in-loop
|
|
315
335
|
return [4 /*yield*/, wait(retryInterval)];
|
|
316
|
-
case
|
|
336
|
+
case 3:
|
|
317
337
|
// eslint-disable-next-line no-await-in-loop
|
|
318
338
|
_a.sent();
|
|
319
339
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
320
|
-
case
|
|
340
|
+
case 4:
|
|
321
341
|
res = _a.sent();
|
|
322
|
-
if (res.tx_status === '
|
|
323
|
-
(res.tx_status === 'PENDING' && res.block_hash !== 'pending') // This is needed as of today. In the future there will be a different status for pending transactions.
|
|
324
|
-
) {
|
|
342
|
+
if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
|
|
325
343
|
onchain = true;
|
|
326
344
|
}
|
|
327
|
-
else if (res.tx_status === 'REJECTED') {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
throw Error('NOT_RECEIVED');
|
|
345
|
+
else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
|
|
346
|
+
error = Error(res.tx_status);
|
|
347
|
+
error.response = res;
|
|
348
|
+
throw error;
|
|
332
349
|
}
|
|
333
|
-
return [3 /*break*/,
|
|
334
|
-
case
|
|
350
|
+
return [3 /*break*/, 2];
|
|
351
|
+
case 5: return [2 /*return*/];
|
|
335
352
|
}
|
|
336
353
|
});
|
|
337
354
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction } from '../types';
|
|
1
|
+
import type { AddTransactionResponse, BlockNumber, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
|
|
2
2
|
import type { BigNumberish } from '../utils/number';
|
|
3
3
|
export declare abstract class ProviderInterface {
|
|
4
4
|
abstract baseUrl: string;
|
|
@@ -14,50 +14,54 @@ export declare abstract class ProviderInterface {
|
|
|
14
14
|
/**
|
|
15
15
|
* Calls a function on the StarkNet contract.
|
|
16
16
|
*
|
|
17
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
17
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
|
|
18
18
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
19
|
+
* @param invokeTransaction - transaction to be invoked
|
|
20
|
+
* @param blockHash
|
|
21
|
+
* @param blockNumber
|
|
21
22
|
* @returns the result of the function on the smart contract.
|
|
22
23
|
*/
|
|
23
|
-
abstract callContract(
|
|
24
|
+
abstract callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
|
|
24
25
|
/**
|
|
25
|
-
* Gets the block information
|
|
26
|
+
* Gets the block information
|
|
26
27
|
*
|
|
27
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
28
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
|
|
28
29
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
30
|
+
* @param blockHash
|
|
31
|
+
* @param blockNumber
|
|
32
|
+
* @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
|
|
31
33
|
*/
|
|
32
|
-
abstract getBlock(
|
|
34
|
+
abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
|
|
33
35
|
/**
|
|
34
36
|
* Gets the code of the deployed contract.
|
|
35
37
|
*
|
|
36
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
38
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
|
|
37
39
|
*
|
|
38
40
|
* @param contractAddress
|
|
39
|
-
* @param
|
|
41
|
+
* @param blockHash
|
|
42
|
+
* @param blockNumber
|
|
40
43
|
* @returns Bytecode and ABI of compiled contract
|
|
41
44
|
*/
|
|
42
|
-
abstract getCode(contractAddress: string,
|
|
45
|
+
abstract getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
|
|
43
46
|
/**
|
|
44
47
|
* Gets the contract's storage variable at a specific key.
|
|
45
48
|
*
|
|
46
|
-
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/
|
|
49
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
|
|
47
50
|
*
|
|
48
51
|
* @param contractAddress
|
|
49
52
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
50
|
-
* @param
|
|
53
|
+
* @param blockHash
|
|
54
|
+
* @param blockNumber
|
|
51
55
|
* @returns the value of the storage variable
|
|
52
56
|
*/
|
|
53
|
-
abstract getStorageAt(contractAddress: string, key: number,
|
|
57
|
+
abstract getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
|
|
54
58
|
/**
|
|
55
59
|
* Gets the status of a transaction.
|
|
56
60
|
*
|
|
57
61
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
58
62
|
*
|
|
59
63
|
* @param txHash
|
|
60
|
-
* @returns the transaction status object {
|
|
64
|
+
* @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
61
65
|
*/
|
|
62
66
|
abstract getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
|
|
63
67
|
/**
|
|
@@ -66,7 +70,7 @@ export declare abstract class ProviderInterface {
|
|
|
66
70
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
|
|
67
71
|
*
|
|
68
72
|
* @param txHash
|
|
69
|
-
* @returns the transacton object { transaction_id, status, transaction,
|
|
73
|
+
* @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
70
74
|
*/
|
|
71
75
|
abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
72
76
|
/**
|
|
@@ -74,10 +78,10 @@ export declare abstract class ProviderInterface {
|
|
|
74
78
|
*
|
|
75
79
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
76
80
|
*
|
|
77
|
-
* @param
|
|
81
|
+
* @param transaction - transaction to be invoked
|
|
78
82
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
79
83
|
*/
|
|
80
|
-
abstract addTransaction(
|
|
84
|
+
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
81
85
|
/**
|
|
82
86
|
* Deploys a given compiled contract (json) to starknet
|
|
83
87
|
*
|
|
@@ -95,6 +99,6 @@ export declare abstract class ProviderInterface {
|
|
|
95
99
|
* @param signature - (optional) signature to send along
|
|
96
100
|
* @returns response from addTransaction
|
|
97
101
|
*/
|
|
98
|
-
abstract invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?:
|
|
102
|
+
abstract invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?: Signature): Promise<AddTransactionResponse>;
|
|
99
103
|
abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
100
104
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BlockNumber } from '../types';
|
|
2
|
+
import { BigNumberish } from '../utils/number';
|
|
3
|
+
/**
|
|
4
|
+
* TODO
|
|
5
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
|
|
6
|
+
*
|
|
7
|
+
* @param hashValue
|
|
8
|
+
* @param hashField
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatHash(): void;
|
|
11
|
+
/**
|
|
12
|
+
* TODO
|
|
13
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
|
|
14
|
+
* @param txHash
|
|
15
|
+
* @param txId
|
|
16
|
+
*/
|
|
17
|
+
export declare function txIdentifier(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the block identifier for API request
|
|
20
|
+
*
|
|
21
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
22
|
+
*
|
|
23
|
+
* @param blockNumber
|
|
24
|
+
* @param blockHash
|
|
25
|
+
* @returns block identifier for API request
|
|
26
|
+
*/
|
|
27
|
+
export declare function getFormattedBlockIdentifier(blockHash?: BigNumberish, blockNumber?: BlockNumber): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFormattedBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TODO
|
|
6
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
|
|
7
|
+
*
|
|
8
|
+
* @param hashValue
|
|
9
|
+
* @param hashField
|
|
10
|
+
*/
|
|
11
|
+
function formatHash() { }
|
|
12
|
+
exports.formatHash = formatHash;
|
|
13
|
+
/**
|
|
14
|
+
* TODO
|
|
15
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
|
|
16
|
+
* @param txHash
|
|
17
|
+
* @param txId
|
|
18
|
+
*/
|
|
19
|
+
function txIdentifier() { }
|
|
20
|
+
exports.txIdentifier = txIdentifier;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the block identifier for API request
|
|
23
|
+
*
|
|
24
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
25
|
+
*
|
|
26
|
+
* @param blockNumber
|
|
27
|
+
* @param blockHash
|
|
28
|
+
* @returns block identifier for API request
|
|
29
|
+
*/
|
|
30
|
+
function getFormattedBlockIdentifier(blockHash, blockNumber) {
|
|
31
|
+
if (blockNumber === void 0) { blockNumber = null; }
|
|
32
|
+
if (blockHash) {
|
|
33
|
+
return "?blockHash=" + blockHash;
|
|
34
|
+
}
|
|
35
|
+
return "?blockNumber=" + blockNumber;
|
|
36
|
+
}
|
|
37
|
+
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|
package/dist/signer/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import { AddTransactionResponse, KeyPair, Transaction } from '../types';
|
|
2
|
+
import { AddTransactionResponse, KeyPair, Signature, Transaction } from '../types';
|
|
3
|
+
import { TypedData } from '../utils/typedData';
|
|
3
4
|
import { SignerInterface } from './interface';
|
|
4
5
|
export declare class Signer extends Provider implements SignerInterface {
|
|
5
6
|
address: string;
|
|
@@ -10,8 +11,24 @@ export declare class Signer extends Provider implements SignerInterface {
|
|
|
10
11
|
*
|
|
11
12
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
12
13
|
*
|
|
13
|
-
* @param
|
|
14
|
+
* @param transaction - transaction to be invoked
|
|
14
15
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
15
16
|
*/
|
|
16
|
-
addTransaction(
|
|
17
|
+
addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Sign an JSON object with the starknet private key and return the signature
|
|
20
|
+
*
|
|
21
|
+
* @param json - JSON object to be signed
|
|
22
|
+
* @returns the signature of the JSON object
|
|
23
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
24
|
+
*/
|
|
25
|
+
signMessage(typedData: TypedData): Promise<Signature>;
|
|
26
|
+
/**
|
|
27
|
+
* Hash a JSON object with pederson hash and return the hash
|
|
28
|
+
*
|
|
29
|
+
* @param json - JSON object to be hashed
|
|
30
|
+
* @returns the hash of the JSON object
|
|
31
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
32
|
+
*/
|
|
33
|
+
hashMessage(typedData: TypedData): Promise<string>;
|
|
17
34
|
}
|
package/dist/signer/default.js
CHANGED
|
@@ -87,6 +87,7 @@ var encode_1 = require("../utils/encode");
|
|
|
87
87
|
var hash_1 = require("../utils/hash");
|
|
88
88
|
var number_1 = require("../utils/number");
|
|
89
89
|
var stark_1 = require("../utils/stark");
|
|
90
|
+
var typedData_1 = require("../utils/typedData");
|
|
90
91
|
var Signer = /** @class */ (function (_super) {
|
|
91
92
|
__extends(Signer, _super);
|
|
92
93
|
function Signer(provider, address, keyPair) {
|
|
@@ -100,45 +101,85 @@ var Signer = /** @class */ (function (_super) {
|
|
|
100
101
|
*
|
|
101
102
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
102
103
|
*
|
|
103
|
-
* @param
|
|
104
|
+
* @param transaction - transaction to be invoked
|
|
104
105
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
105
106
|
*/
|
|
106
|
-
Signer.prototype.addTransaction = function (
|
|
107
|
+
Signer.prototype.addTransaction = function (transaction) {
|
|
107
108
|
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
-
var
|
|
109
|
-
return __generator(this, function (
|
|
110
|
-
switch (
|
|
109
|
+
var nonceBn, result, calldataDecimal, msgHash, signature;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
111
112
|
case 0:
|
|
112
|
-
if (
|
|
113
|
-
return [2 /*return*/, _super.prototype.addTransaction.call(this,
|
|
114
|
-
(0, minimalistic_assert_1.default)(!
|
|
115
|
-
return [
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
if (transaction.type === 'DEPLOY')
|
|
114
|
+
return [2 /*return*/, _super.prototype.addTransaction.call(this, transaction)];
|
|
115
|
+
(0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
116
|
+
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
117
|
+
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
|
118
|
+
return [3 /*break*/, 3];
|
|
119
|
+
case 1: return [4 /*yield*/, this.callContract({
|
|
120
|
+
contract_address: this.address,
|
|
121
|
+
entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
|
|
122
|
+
})];
|
|
123
|
+
case 2:
|
|
124
|
+
result = (_a.sent()).result;
|
|
121
125
|
nonceBn = (0, number_1.toBN)(result[0]);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
_a.label = 3;
|
|
127
|
+
case 3:
|
|
128
|
+
calldataDecimal = (transaction.calldata || []).map(function (x) { return (0, number_1.toBN)(x).toString(); });
|
|
129
|
+
msgHash = (0, encode_1.addHexPrefix)((0, hash_1.hashMessage)(this.address, transaction.contract_address, transaction.entry_point_selector, calldataDecimal, nonceBn.toString()));
|
|
130
|
+
signature = (0, ellipticCurve_1.sign)(this.keyPair, msgHash);
|
|
125
131
|
return [2 /*return*/, _super.prototype.addTransaction.call(this, {
|
|
126
132
|
type: 'INVOKE_FUNCTION',
|
|
127
133
|
entry_point_selector: (0, stark_1.getSelectorFromName)('execute'),
|
|
128
134
|
calldata: __spreadArray(__spreadArray([
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
transaction.contract_address,
|
|
136
|
+
transaction.entry_point_selector,
|
|
131
137
|
calldataDecimal.length.toString()
|
|
132
138
|
], __read(calldataDecimal), false), [
|
|
133
139
|
nonceBn.toString(),
|
|
134
140
|
], false).map(function (x) { return (0, number_1.toBN)(x).toString(); }),
|
|
135
141
|
contract_address: this.address,
|
|
136
|
-
signature:
|
|
142
|
+
signature: signature,
|
|
137
143
|
})];
|
|
138
144
|
}
|
|
139
145
|
});
|
|
140
146
|
});
|
|
141
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Sign an JSON object with the starknet private key and return the signature
|
|
150
|
+
*
|
|
151
|
+
* @param json - JSON object to be signed
|
|
152
|
+
* @returns the signature of the JSON object
|
|
153
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
154
|
+
*/
|
|
155
|
+
Signer.prototype.signMessage = function (typedData) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
var _a, _b;
|
|
158
|
+
return __generator(this, function (_c) {
|
|
159
|
+
switch (_c.label) {
|
|
160
|
+
case 0:
|
|
161
|
+
_a = ellipticCurve_1.sign;
|
|
162
|
+
_b = [this.keyPair];
|
|
163
|
+
return [4 /*yield*/, this.hashMessage(typedData)];
|
|
164
|
+
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Hash a JSON object with pederson hash and return the hash
|
|
171
|
+
*
|
|
172
|
+
* @param json - JSON object to be hashed
|
|
173
|
+
* @returns the hash of the JSON object
|
|
174
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
175
|
+
*/
|
|
176
|
+
Signer.prototype.hashMessage = function (typedData) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
};
|
|
142
183
|
return Signer;
|
|
143
184
|
}(provider_1.Provider));
|
|
144
185
|
exports.Signer = Signer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import { AddTransactionResponse, Transaction } from '../types';
|
|
2
|
+
import { AddTransactionResponse, Signature, Transaction } from '../types';
|
|
3
|
+
import { TypedData } from '../utils/typedData/types';
|
|
3
4
|
export declare abstract class SignerInterface extends Provider {
|
|
4
5
|
abstract address: string;
|
|
5
6
|
/**
|
|
@@ -7,8 +8,26 @@ export declare abstract class SignerInterface extends Provider {
|
|
|
7
8
|
*
|
|
8
9
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
|
|
9
10
|
*
|
|
10
|
-
* @param
|
|
11
|
+
* @param transaction - transaction to be invoked
|
|
11
12
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
12
13
|
*/
|
|
13
|
-
abstract addTransaction(
|
|
14
|
+
abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
17
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
18
|
+
*
|
|
19
|
+
* @param json - JSON object to be signed
|
|
20
|
+
* @returns the signature of the JSON object
|
|
21
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
22
|
+
*/
|
|
23
|
+
abstract signMessage(typedData: TypedData): Promise<Signature>;
|
|
24
|
+
/**
|
|
25
|
+
* Hash a JSON object with pederson hash and return the hash
|
|
26
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
27
|
+
*
|
|
28
|
+
* @param json - JSON object to be hashed
|
|
29
|
+
* @returns the hash of the JSON object
|
|
30
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
31
|
+
*/
|
|
32
|
+
abstract hashMessage(typedData: TypedData): Promise<string>;
|
|
14
33
|
}
|