starknet 3.7.0 → 3.10.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 +38 -0
- package/README.md +18 -53
- package/__mocks__/ArgentAccount.json +32022 -38726
- package/__tests__/accountContract.test.ts +42 -32
- package/__tests__/contract.test.ts +20 -6
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
- package/__tests__/utils/ellipticalCurve.test.ts +26 -8
- package/__tests__/utils/transactionHash.test.ts +17 -0
- package/__tests__/utils/utils.test.ts +10 -0
- package/account/default.d.ts +11 -1
- package/account/default.js +58 -50
- package/constants.d.ts +9 -0
- package/constants.js +13 -0
- package/contract/default.d.ts +12 -2
- package/contract/default.js +27 -20
- package/contract/interface.d.ts +21 -3
- package/dist/account/default.d.ts +5 -1
- package/dist/account/default.js +46 -30
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -1
- package/dist/contract/default.d.ts +6 -3
- package/dist/contract/default.js +23 -20
- package/dist/contract/interface.d.ts +9 -4
- package/dist/provider/default.d.ts +5 -2
- package/dist/provider/default.js +36 -19
- package/dist/provider/interface.d.ts +2 -0
- package/dist/provider/utils.d.ts +1 -2
- package/dist/provider/utils.js +7 -8
- package/dist/signer/default.js +4 -2
- package/dist/signer/ledger.js +4 -2
- package/dist/types/api.d.ts +4 -1
- package/dist/types/lib.d.ts +1 -0
- package/dist/types/signer.d.ts +2 -0
- package/dist/utils/hash.d.ts +5 -3
- package/dist/utils/hash.js +25 -23
- package/dist/utils/stark.d.ts +3 -0
- package/dist/utils/stark.js +8 -1
- package/dist/utils/transaction.d.ts +2 -0
- package/dist/utils/transaction.js +5 -1
- package/dist/utils/typedData/index.d.ts +2 -2
- package/dist/utils/typedData/types.d.ts +3 -3
- package/dist/utils/typedData/utils.d.ts +1 -1
- package/package.json +1 -1
- package/provider/default.d.ts +7 -2
- package/provider/default.js +49 -27
- package/provider/interface.d.ts +2 -0
- package/provider/utils.d.ts +1 -2
- package/provider/utils.js +7 -8
- package/signer/default.js +12 -5
- package/signer/ledger.js +12 -5
- package/src/account/default.ts +47 -18
- package/src/constants.ts +10 -0
- package/src/contract/default.ts +32 -19
- package/src/contract/interface.ts +21 -3
- package/src/provider/default.ts +37 -12
- package/src/provider/interface.ts +3 -0
- package/src/provider/utils.ts +7 -8
- package/src/signer/default.ts +10 -5
- package/src/signer/ledger.ts +10 -5
- package/src/types/api.ts +4 -1
- package/src/types/lib.ts +1 -0
- package/src/types/signer.ts +2 -0
- package/src/utils/hash.ts +70 -26
- package/src/utils/stark.ts +8 -1
- package/src/utils/transaction.ts +7 -0
- package/types/api.d.ts +4 -1
- package/types/lib.d.ts +1 -0
- package/types/signer.d.ts +2 -0
- package/utils/hash.d.ts +25 -7
- package/utils/hash.js +60 -26
- package/utils/stark.d.ts +4 -0
- package/utils/stark.js +13 -1
- package/utils/transaction.d.ts +5 -0
- package/utils/transaction.js +12 -1
- package/utils/typedData/index.d.ts +2 -2
- package/utils/typedData/types.d.ts +3 -3
- package/utils/typedData/utils.d.ts +1 -1
- package/__tests__/constancts.ts +0 -2
package/dist/account/default.js
CHANGED
|
@@ -81,11 +81,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
81
81
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
82
|
exports.Account = void 0;
|
|
83
83
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
84
|
+
var constants_1 = require("../constants");
|
|
84
85
|
var provider_1 = require("../provider");
|
|
85
86
|
var signer_1 = require("../signer");
|
|
86
87
|
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
87
88
|
var hash_1 = require("../utils/hash");
|
|
88
89
|
var number_1 = require("../utils/number");
|
|
90
|
+
var shortString_1 = require("../utils/shortString");
|
|
89
91
|
var stark_1 = require("../utils/stark");
|
|
90
92
|
var transaction_1 = require("../utils/transaction");
|
|
91
93
|
var typedData_1 = require("../utils/typedData");
|
|
@@ -114,29 +116,40 @@ var Account = /** @class */ (function (_super) {
|
|
|
114
116
|
});
|
|
115
117
|
});
|
|
116
118
|
};
|
|
117
|
-
Account.prototype.estimateFee = function (calls) {
|
|
119
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
120
|
+
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
118
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var transactions, nonce, signerDetails, signature, calldata;
|
|
120
|
-
return __generator(this, function (
|
|
121
|
-
switch (
|
|
122
|
+
var transactions, nonce, _d, version, signerDetails, signature, calldata;
|
|
123
|
+
return __generator(this, function (_e) {
|
|
124
|
+
switch (_e.label) {
|
|
122
125
|
case 0:
|
|
123
126
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
124
|
-
return [
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
128
|
+
_d = providedNonce;
|
|
129
|
+
return [3 /*break*/, 3];
|
|
130
|
+
case 1: return [4 /*yield*/, this.getNonce()];
|
|
131
|
+
case 2:
|
|
132
|
+
_d = (_e.sent());
|
|
133
|
+
_e.label = 3;
|
|
134
|
+
case 3:
|
|
135
|
+
nonce = _d;
|
|
136
|
+
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
127
137
|
signerDetails = {
|
|
128
138
|
walletAddress: this.address,
|
|
129
139
|
nonce: (0, number_1.toBN)(nonce),
|
|
130
|
-
maxFee:
|
|
140
|
+
maxFee: constants_1.ZERO,
|
|
141
|
+
version: version,
|
|
142
|
+
chainId: this.chainId,
|
|
131
143
|
};
|
|
132
144
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
133
|
-
case
|
|
134
|
-
signature =
|
|
135
|
-
calldata =
|
|
136
|
-
return [2 /*return*/, this.fetchEndpoint('estimate_fee',
|
|
145
|
+
case 4:
|
|
146
|
+
signature = _e.sent();
|
|
147
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
148
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
137
149
|
contract_address: this.address,
|
|
138
150
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
139
151
|
calldata: calldata,
|
|
152
|
+
version: (0, number_1.toHex)(version),
|
|
140
153
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
141
154
|
})];
|
|
142
155
|
}
|
|
@@ -152,43 +165,46 @@ var Account = /** @class */ (function (_super) {
|
|
|
152
165
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
153
166
|
*/
|
|
154
167
|
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
155
|
-
var _a
|
|
168
|
+
var _a;
|
|
156
169
|
if (abis === void 0) { abis = undefined; }
|
|
157
170
|
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
158
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
-
var transactions, nonce,
|
|
160
|
-
return __generator(this, function (
|
|
161
|
-
switch (
|
|
172
|
+
var transactions, nonce, _b, _c, maxFee, estimatedFee, signerDetails, signature, calldata;
|
|
173
|
+
return __generator(this, function (_d) {
|
|
174
|
+
switch (_d.label) {
|
|
162
175
|
case 0:
|
|
163
176
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
164
|
-
|
|
177
|
+
_b = number_1.toBN;
|
|
165
178
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
166
|
-
|
|
179
|
+
_c = _a;
|
|
167
180
|
return [3 /*break*/, 3];
|
|
168
181
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
169
182
|
case 2:
|
|
170
|
-
|
|
171
|
-
|
|
183
|
+
_c = (_d.sent());
|
|
184
|
+
_d.label = 3;
|
|
172
185
|
case 3:
|
|
173
|
-
nonce =
|
|
174
|
-
|
|
175
|
-
|
|
186
|
+
nonce = _b.apply(void 0, [_c]);
|
|
187
|
+
maxFee = '0';
|
|
188
|
+
if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0)) return [3 /*break*/, 4];
|
|
189
|
+
maxFee = transactionsDetail.maxFee;
|
|
176
190
|
return [3 /*break*/, 6];
|
|
177
|
-
case 4: return [4 /*yield*/, this.estimateFee(transactions)];
|
|
191
|
+
case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
178
192
|
case 5:
|
|
179
|
-
|
|
180
|
-
|
|
193
|
+
estimatedFee = (_d.sent()).amount;
|
|
194
|
+
maxFee = (0, stark_1.estimatedFeeToMaxFee)(estimatedFee).toString();
|
|
195
|
+
_d.label = 6;
|
|
181
196
|
case 6:
|
|
182
|
-
maxFee = _e;
|
|
183
197
|
signerDetails = {
|
|
184
198
|
walletAddress: this.address,
|
|
185
199
|
nonce: nonce,
|
|
186
200
|
maxFee: maxFee,
|
|
201
|
+
version: (0, number_1.toBN)(hash_1.transactionVersion),
|
|
202
|
+
chainId: this.chainId,
|
|
187
203
|
};
|
|
188
204
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
189
205
|
case 7:
|
|
190
|
-
signature =
|
|
191
|
-
calldata =
|
|
206
|
+
signature = _d.sent();
|
|
207
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
192
208
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
193
209
|
type: 'INVOKE_FUNCTION',
|
|
194
210
|
contract_address: this.address,
|
|
@@ -220,7 +236,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
220
236
|
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
221
237
|
.map(hash_1.computeHashOnElements);
|
|
222
238
|
return (0, hash_1.computeHashOnElements)([
|
|
223
|
-
|
|
239
|
+
(0, shortString_1.encodeShortString)('StarkNet Transaction'),
|
|
224
240
|
account,
|
|
225
241
|
(0, hash_1.computeHashOnElements)(hashArray),
|
|
226
242
|
nonce,
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export declare const ONE: import("bn.js");
|
|
|
5
5
|
export declare const TWO: import("bn.js");
|
|
6
6
|
export declare const MASK_250: import("bn.js");
|
|
7
7
|
export declare const MASK_251: import("bn.js");
|
|
8
|
+
export declare enum StarknetChainId {
|
|
9
|
+
MAINNET = "0x534e5f4d41494e",
|
|
10
|
+
TESTNET = "0x534e5f474f45524c49"
|
|
11
|
+
}
|
|
12
|
+
export declare enum TransactionHashPrefix {
|
|
13
|
+
DEPLOY = "0x6465706c6f79",
|
|
14
|
+
INVOKE = "0x696e766f6b65",
|
|
15
|
+
L1_HANDLER = "0x6c315f68616e646c6572"
|
|
16
|
+
}
|
|
8
17
|
/**
|
|
9
18
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
10
19
|
* Please do not edit until the JSON changes.
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
|
|
3
|
+
exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.TransactionHashPrefix = exports.StarknetChainId = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
|
|
4
4
|
var number_1 = require("./utils/number");
|
|
5
5
|
var encode_1 = require("./utils/encode");
|
|
6
6
|
Object.defineProperty(exports, "IS_BROWSER", { enumerable: true, get: function () { return encode_1.IS_BROWSER; } });
|
|
@@ -9,6 +9,17 @@ exports.ONE = (0, number_1.toBN)(1);
|
|
|
9
9
|
exports.TWO = (0, number_1.toBN)(2);
|
|
10
10
|
exports.MASK_250 = exports.TWO.pow((0, number_1.toBN)(250)).sub(exports.ONE); // 2 ** 250 - 1
|
|
11
11
|
exports.MASK_251 = exports.TWO.pow((0, number_1.toBN)(251));
|
|
12
|
+
var StarknetChainId;
|
|
13
|
+
(function (StarknetChainId) {
|
|
14
|
+
StarknetChainId["MAINNET"] = "0x534e5f4d41494e";
|
|
15
|
+
StarknetChainId["TESTNET"] = "0x534e5f474f45524c49";
|
|
16
|
+
})(StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {}));
|
|
17
|
+
var TransactionHashPrefix;
|
|
18
|
+
(function (TransactionHashPrefix) {
|
|
19
|
+
TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
|
|
20
|
+
TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
|
|
21
|
+
TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
|
|
22
|
+
})(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
|
|
12
23
|
/**
|
|
13
24
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
14
25
|
* Please do not edit until the JSON changes.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
+
import { Abi, AbiEntry, AddTransactionResponse, Args, AsyncContractFunction, Calldata, ContractFunction, Invocation, Overrides, ParsedStruct, Result, StructAbi } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
5
6
|
import { ContractInterface } from './interface';
|
|
6
7
|
export declare class Contract implements ContractInterface {
|
|
@@ -114,8 +115,10 @@ export declare class Contract implements ContractInterface {
|
|
|
114
115
|
* @return - parsed response corresponding to the abi
|
|
115
116
|
*/
|
|
116
117
|
protected parseResponse(method: string, response: string[]): Result;
|
|
117
|
-
invoke(method: string, args?: Array<any
|
|
118
|
-
call(method: string, args?: Array<any
|
|
118
|
+
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
119
|
+
call(method: string, args?: Array<any>, { blockIdentifier, }?: {
|
|
120
|
+
blockIdentifier?: BlockIdentifier;
|
|
121
|
+
}): Promise<Result>;
|
|
119
122
|
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
|
|
120
123
|
populate(method: string, args?: Array<any>): Invocation;
|
|
121
124
|
}
|
package/dist/contract/default.js
CHANGED
|
@@ -116,8 +116,20 @@ function buildInvoke(contract, functionAbi) {
|
|
|
116
116
|
args[_i] = arguments[_i];
|
|
117
117
|
}
|
|
118
118
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var inputs, inputsLength, options;
|
|
119
120
|
return __generator(this, function (_a) {
|
|
120
|
-
|
|
121
|
+
inputs = functionAbi.inputs;
|
|
122
|
+
inputsLength = inputs.reduce(function (acc, input) {
|
|
123
|
+
if (!/_len$/.test(input.name)) {
|
|
124
|
+
return acc + 1;
|
|
125
|
+
}
|
|
126
|
+
return acc;
|
|
127
|
+
}, 0);
|
|
128
|
+
options = {};
|
|
129
|
+
if (inputsLength + 1 === args.length && typeof args[args.length - 1] === 'object') {
|
|
130
|
+
Object.assign(options, args.pop());
|
|
131
|
+
}
|
|
132
|
+
return [2 /*return*/, contract.invoke(functionAbi.name, args, options)];
|
|
121
133
|
});
|
|
122
134
|
});
|
|
123
135
|
};
|
|
@@ -550,8 +562,9 @@ var Contract = /** @class */ (function () {
|
|
|
550
562
|
return acc;
|
|
551
563
|
}, []);
|
|
552
564
|
};
|
|
553
|
-
Contract.prototype.invoke = function (method, args) {
|
|
565
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
554
566
|
if (args === void 0) { args = []; }
|
|
567
|
+
if (options === void 0) { options = {}; }
|
|
555
568
|
// ensure contract is connected
|
|
556
569
|
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
557
570
|
// validate method and args
|
|
@@ -563,10 +576,6 @@ var Contract = /** @class */ (function () {
|
|
|
563
576
|
}
|
|
564
577
|
return acc;
|
|
565
578
|
}, 0);
|
|
566
|
-
var overrides = {};
|
|
567
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
568
|
-
Object.assign(overrides, args.pop());
|
|
569
|
-
}
|
|
570
579
|
if (args.length !== inputsLength) {
|
|
571
580
|
throw Error("Invalid number of arguments, expected " + inputsLength + " arguments, but got " + args.length);
|
|
572
581
|
}
|
|
@@ -579,37 +588,31 @@ var Contract = /** @class */ (function () {
|
|
|
579
588
|
};
|
|
580
589
|
if ('execute' in this.providerOrAccount) {
|
|
581
590
|
return this.providerOrAccount.execute(invocation, undefined, {
|
|
582
|
-
maxFee:
|
|
583
|
-
nonce:
|
|
591
|
+
maxFee: options.maxFee,
|
|
592
|
+
nonce: options.nonce,
|
|
584
593
|
});
|
|
585
594
|
}
|
|
586
|
-
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature:
|
|
595
|
+
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }));
|
|
587
596
|
};
|
|
588
|
-
Contract.prototype.call = function (method, args) {
|
|
597
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
589
598
|
if (args === void 0) { args = []; }
|
|
599
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
590
600
|
return __awaiter(this, void 0, void 0, function () {
|
|
591
|
-
var inputs,
|
|
601
|
+
var inputs, calldata;
|
|
592
602
|
var _this = this;
|
|
593
|
-
return __generator(this, function (
|
|
603
|
+
return __generator(this, function (_d) {
|
|
594
604
|
// ensure contract is connected
|
|
595
605
|
(0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
596
606
|
// validate method and args
|
|
597
607
|
this.validateMethodAndArgs('CALL', method, args);
|
|
598
608
|
inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
|
|
599
|
-
inputsLength = inputs.length;
|
|
600
|
-
options = {
|
|
601
|
-
blockIdentifier: null,
|
|
602
|
-
};
|
|
603
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
604
|
-
Object.assign(options, args.pop());
|
|
605
|
-
}
|
|
606
609
|
calldata = this.compileCalldata(args, inputs);
|
|
607
610
|
return [2 /*return*/, this.providerOrAccount
|
|
608
611
|
.callContract({
|
|
609
612
|
contractAddress: this.address,
|
|
610
613
|
calldata: calldata,
|
|
611
614
|
entrypoint: method,
|
|
612
|
-
},
|
|
615
|
+
}, { blockIdentifier: blockIdentifier })
|
|
613
616
|
.then(function (x) { return _this.parseResponse(method, x.result); })];
|
|
614
617
|
});
|
|
615
618
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
+
import { Abi, AddTransactionResponse, AsyncContractFunction, ContractFunction, Invocation, Overrides, Result } from '../types';
|
|
4
5
|
export declare abstract class ContractInterface {
|
|
5
6
|
abstract abi: Abi;
|
|
6
7
|
abstract address: string;
|
|
@@ -45,7 +46,9 @@ export declare abstract class ContractInterface {
|
|
|
45
46
|
* @param args Array of the arguments for the call
|
|
46
47
|
* @returns Result of the call as an array with key value pars
|
|
47
48
|
*/
|
|
48
|
-
abstract call(method: string, args?: Array<any
|
|
49
|
+
abstract call(method: string, args?: Array<any>, options?: {
|
|
50
|
+
blockIdentifier?: BlockIdentifier;
|
|
51
|
+
}): Promise<Result>;
|
|
49
52
|
/**
|
|
50
53
|
* Invokes a method on a contract
|
|
51
54
|
*
|
|
@@ -53,14 +56,16 @@ export declare abstract class ContractInterface {
|
|
|
53
56
|
* @param args Array of the arguments for the invoke
|
|
54
57
|
* @returns Add Transaction Response
|
|
55
58
|
*/
|
|
56
|
-
abstract invoke(method: string, args?: Array<any
|
|
59
|
+
abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
57
60
|
/**
|
|
58
61
|
* Calls a method on a contract
|
|
59
62
|
*
|
|
60
63
|
* @param method name of the method
|
|
61
64
|
* @param args Array of the arguments for the call
|
|
62
65
|
*/
|
|
63
|
-
abstract estimate(method: string, args?: Array<any
|
|
66
|
+
abstract estimate(method: string, args?: Array<any>, options?: {
|
|
67
|
+
blockIdentifier?: BlockIdentifier;
|
|
68
|
+
}): Promise<any>;
|
|
64
69
|
/**
|
|
65
70
|
* Calls a method on a contract
|
|
66
71
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceipt } from '../types';
|
|
2
3
|
import { BigNumberish } from '../utils/number';
|
|
3
4
|
import { ProviderInterface } from './interface';
|
|
@@ -12,8 +13,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
12
13
|
baseUrl: string;
|
|
13
14
|
feederGatewayUrl: string;
|
|
14
15
|
gatewayUrl: string;
|
|
16
|
+
chainId: StarknetChainId;
|
|
15
17
|
constructor(optionsOrProvider?: ProviderOptions | Provider);
|
|
16
18
|
protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
|
|
19
|
+
protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
|
|
17
20
|
private getFetchUrl;
|
|
18
21
|
private getFetchMethod;
|
|
19
22
|
private getQueryString;
|
|
@@ -36,8 +39,8 @@ export declare class Provider implements ProviderInterface {
|
|
|
36
39
|
* @param blockNumber
|
|
37
40
|
* @returns the result of the function on the smart contract.
|
|
38
41
|
*/
|
|
39
|
-
callContract({ contractAddress, entrypoint, calldata }: Call,
|
|
40
|
-
blockIdentifier
|
|
42
|
+
callContract({ contractAddress, entrypoint, calldata }: Call, { blockIdentifier }?: {
|
|
43
|
+
blockIdentifier?: BlockIdentifier;
|
|
41
44
|
}): Promise<CallContractResponse>;
|
|
42
45
|
/**
|
|
43
46
|
* Gets the block information
|
package/dist/provider/default.js
CHANGED
|
@@ -69,6 +69,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
69
69
|
exports.Provider = void 0;
|
|
70
70
|
var axios_1 = __importDefault(require("axios"));
|
|
71
71
|
var url_join_1 = __importDefault(require("url-join"));
|
|
72
|
+
var constants_1 = require("../constants");
|
|
72
73
|
var hash_1 = require("../utils/hash");
|
|
73
74
|
var json_1 = require("../utils/json");
|
|
74
75
|
var number_1 = require("../utils/number");
|
|
@@ -89,16 +90,20 @@ function isEmptyQueryObject(obj) {
|
|
|
89
90
|
var Provider = /** @class */ (function () {
|
|
90
91
|
function Provider(optionsOrProvider) {
|
|
91
92
|
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
93
|
+
var _a;
|
|
92
94
|
if (optionsOrProvider instanceof Provider) {
|
|
93
95
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
94
96
|
this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
|
|
95
97
|
this.gatewayUrl = optionsOrProvider.gatewayUrl;
|
|
98
|
+
this.chainId =
|
|
99
|
+
(_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : Provider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
96
100
|
}
|
|
97
101
|
else {
|
|
98
102
|
var baseUrl = 'baseUrl' in optionsOrProvider
|
|
99
103
|
? optionsOrProvider.baseUrl
|
|
100
104
|
: Provider.getNetworkFromName(optionsOrProvider.network);
|
|
101
105
|
this.baseUrl = baseUrl;
|
|
106
|
+
this.chainId = Provider.getChainIdFromBaseUrl(baseUrl);
|
|
102
107
|
this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
|
|
103
108
|
this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
|
|
104
109
|
}
|
|
@@ -112,6 +117,19 @@ var Provider = /** @class */ (function () {
|
|
|
112
117
|
return 'https://alpha4.starknet.io';
|
|
113
118
|
}
|
|
114
119
|
};
|
|
120
|
+
Provider.getChainIdFromBaseUrl = function (baseUrl) {
|
|
121
|
+
try {
|
|
122
|
+
var url = new URL(baseUrl);
|
|
123
|
+
if (url.host.includes('mainnet.starknet.io')) {
|
|
124
|
+
return constants_1.StarknetChainId.MAINNET;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (_a) {
|
|
128
|
+
// eslint-disable-next-line no-console
|
|
129
|
+
console.error("Could not parse baseUrl: " + baseUrl);
|
|
130
|
+
}
|
|
131
|
+
return constants_1.StarknetChainId.TESTNET;
|
|
132
|
+
};
|
|
115
133
|
Provider.prototype.getFetchUrl = function (endpoint) {
|
|
116
134
|
var gatewayUrlEndpoints = ['add_transaction'];
|
|
117
135
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
@@ -219,12 +237,12 @@ var Provider = /** @class */ (function () {
|
|
|
219
237
|
* @param blockNumber
|
|
220
238
|
* @returns the result of the function on the smart contract.
|
|
221
239
|
*/
|
|
222
|
-
Provider.prototype.callContract = function (_a,
|
|
223
|
-
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint,
|
|
224
|
-
|
|
240
|
+
Provider.prototype.callContract = function (_a, _b) {
|
|
241
|
+
var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint, _c = _a.calldata, calldata = _c === void 0 ? [] : _c;
|
|
242
|
+
var _d = _b === void 0 ? {} : _b, _e = _d.blockIdentifier, blockIdentifier = _e === void 0 ? 'pending' : _e;
|
|
225
243
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
return __generator(this, function (
|
|
227
|
-
return [2 /*return*/, this.fetchEndpoint('call_contract',
|
|
244
|
+
return __generator(this, function (_f) {
|
|
245
|
+
return [2 /*return*/, this.fetchEndpoint('call_contract', { blockIdentifier: blockIdentifier }, {
|
|
228
246
|
signature: [],
|
|
229
247
|
contract_address: contractAddress,
|
|
230
248
|
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
@@ -261,7 +279,7 @@ var Provider = /** @class */ (function () {
|
|
|
261
279
|
* @returns Bytecode and ABI of compiled contract
|
|
262
280
|
*/
|
|
263
281
|
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
264
|
-
if (blockIdentifier === void 0) { blockIdentifier =
|
|
282
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
265
283
|
return __awaiter(this, void 0, void 0, function () {
|
|
266
284
|
return __generator(this, function (_a) {
|
|
267
285
|
return [2 /*return*/, this.fetchEndpoint('get_code', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
|
|
@@ -281,7 +299,7 @@ var Provider = /** @class */ (function () {
|
|
|
281
299
|
* @returns the value of the storage variable
|
|
282
300
|
*/
|
|
283
301
|
Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
284
|
-
if (blockIdentifier === void 0) { blockIdentifier =
|
|
302
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
285
303
|
return __awaiter(this, void 0, void 0, function () {
|
|
286
304
|
return __generator(this, function (_a) {
|
|
287
305
|
return [2 /*return*/, this.fetchEndpoint('get_storage_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress, key: key })];
|
|
@@ -402,29 +420,28 @@ var Provider = /** @class */ (function () {
|
|
|
402
420
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
403
421
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
404
422
|
return __awaiter(this, void 0, void 0, function () {
|
|
405
|
-
var onchain, res, message, error;
|
|
423
|
+
var onchain, res, successStates, errorStates, message, error;
|
|
406
424
|
return __generator(this, function (_a) {
|
|
407
425
|
switch (_a.label) {
|
|
408
426
|
case 0:
|
|
409
427
|
onchain = false;
|
|
410
|
-
|
|
428
|
+
_a.label = 1;
|
|
411
429
|
case 1:
|
|
412
|
-
|
|
413
|
-
_a.label = 2;
|
|
414
|
-
case 2:
|
|
415
|
-
if (!!onchain) return [3 /*break*/, 5];
|
|
430
|
+
if (!!onchain) return [3 /*break*/, 4];
|
|
416
431
|
// eslint-disable-next-line no-await-in-loop
|
|
417
432
|
return [4 /*yield*/, wait(retryInterval)];
|
|
418
|
-
case
|
|
433
|
+
case 2:
|
|
419
434
|
// eslint-disable-next-line no-await-in-loop
|
|
420
435
|
_a.sent();
|
|
421
436
|
return [4 /*yield*/, this.getTransactionStatus(txHash)];
|
|
422
|
-
case
|
|
437
|
+
case 3:
|
|
423
438
|
res = _a.sent();
|
|
424
|
-
|
|
439
|
+
successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
|
|
440
|
+
errorStates = ['REJECTED', 'NOT_RECEIVED'];
|
|
441
|
+
if (successStates.includes(res.tx_status)) {
|
|
425
442
|
onchain = true;
|
|
426
443
|
}
|
|
427
|
-
else if (
|
|
444
|
+
else if (errorStates.includes(res.tx_status)) {
|
|
428
445
|
message = res.tx_failure_reason
|
|
429
446
|
? res.tx_status + ": " + res.tx_failure_reason.code + "\n" + res.tx_failure_reason.error_message
|
|
430
447
|
: res.tx_status;
|
|
@@ -432,8 +449,8 @@ var Provider = /** @class */ (function () {
|
|
|
432
449
|
error.response = res;
|
|
433
450
|
throw error;
|
|
434
451
|
}
|
|
435
|
-
return [3 /*break*/,
|
|
436
|
-
case
|
|
452
|
+
return [3 /*break*/, 1];
|
|
453
|
+
case 4: return [2 /*return*/];
|
|
437
454
|
}
|
|
438
455
|
});
|
|
439
456
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import type { AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
|
|
2
3
|
import type { BigNumberish } from '../utils/number';
|
|
3
4
|
import { BlockIdentifier } from './utils';
|
|
@@ -5,6 +6,7 @@ export declare abstract class ProviderInterface {
|
|
|
5
6
|
abstract baseUrl: string;
|
|
6
7
|
abstract feederGatewayUrl: string;
|
|
7
8
|
abstract gatewayUrl: string;
|
|
9
|
+
abstract chainId: StarknetChainId;
|
|
8
10
|
/**
|
|
9
11
|
* Gets the smart contract address on the goerli testnet.
|
|
10
12
|
*
|
package/dist/provider/utils.d.ts
CHANGED
|
@@ -35,8 +35,7 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
35
35
|
*
|
|
36
36
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param blockHash
|
|
38
|
+
* @param blockIdentifier
|
|
40
39
|
* @returns block identifier for API request
|
|
41
40
|
*/
|
|
42
41
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
package/dist/provider/utils.js
CHANGED
|
@@ -36,6 +36,12 @@ exports.txIdentifier = txIdentifier;
|
|
|
36
36
|
* @returns block identifier object
|
|
37
37
|
*/
|
|
38
38
|
function getBlockIdentifier(blockIdentifier) {
|
|
39
|
+
if (blockIdentifier === null) {
|
|
40
|
+
return { type: 'BLOCK_NUMBER', data: null };
|
|
41
|
+
}
|
|
42
|
+
if (blockIdentifier === 'pending') {
|
|
43
|
+
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
44
|
+
}
|
|
39
45
|
if (typeof blockIdentifier === 'number') {
|
|
40
46
|
return { type: 'BLOCK_NUMBER', data: blockIdentifier };
|
|
41
47
|
}
|
|
@@ -45,12 +51,6 @@ function getBlockIdentifier(blockIdentifier) {
|
|
|
45
51
|
if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
|
|
46
52
|
return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
|
|
47
53
|
}
|
|
48
|
-
if (blockIdentifier === null) {
|
|
49
|
-
return { type: 'BLOCK_NUMBER', data: null };
|
|
50
|
-
}
|
|
51
|
-
if (blockIdentifier === 'pending') {
|
|
52
|
-
return { type: 'BLOCK_NUMBER', data: 'pending' };
|
|
53
|
-
}
|
|
54
54
|
if (typeof blockIdentifier === 'string') {
|
|
55
55
|
throw new Error("Invalid block identifier: " + blockIdentifier);
|
|
56
56
|
}
|
|
@@ -62,8 +62,7 @@ exports.getBlockIdentifier = getBlockIdentifier;
|
|
|
62
62
|
*
|
|
63
63
|
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
66
|
-
* @param blockHash
|
|
65
|
+
* @param blockIdentifier
|
|
67
66
|
* @returns block identifier for API request
|
|
68
67
|
*/
|
|
69
68
|
function getFormattedBlockIdentifier(blockIdentifier) {
|
package/dist/signer/default.js
CHANGED
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.Signer = void 0;
|
|
40
40
|
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
41
41
|
var hash_1 = require("../utils/hash");
|
|
42
|
+
var transaction_1 = require("../utils/transaction");
|
|
42
43
|
var typedData_1 = require("../utils/typedData");
|
|
43
44
|
var Signer = /** @class */ (function () {
|
|
44
45
|
function Signer(keyPair) {
|
|
@@ -53,12 +54,13 @@ var Signer = /** @class */ (function () {
|
|
|
53
54
|
};
|
|
54
55
|
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var msgHash;
|
|
57
|
+
var calldata, msgHash;
|
|
57
58
|
return __generator(this, function (_a) {
|
|
58
59
|
if (abis && abis.length !== transactions.length) {
|
|
59
60
|
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, transactionsDetail.nonce);
|
|
63
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(transactionsDetail.walletAddress, transactionsDetail.version, (0, hash_1.getSelectorFromName)('__execute__'), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
|
|
62
64
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
63
65
|
});
|
|
64
66
|
});
|
package/dist/signer/ledger.js
CHANGED
|
@@ -44,6 +44,7 @@ var hw_app_eth_1 = __importDefault(require("@ledgerhq/hw-app-eth"));
|
|
|
44
44
|
var hw_transport_webhid_1 = __importDefault(require("@ledgerhq/hw-transport-webhid"));
|
|
45
45
|
var encode_1 = require("../utils/encode");
|
|
46
46
|
var hash_1 = require("../utils/hash");
|
|
47
|
+
var transaction_1 = require("../utils/transaction");
|
|
47
48
|
var typedData_1 = require("../utils/typedData");
|
|
48
49
|
function hexZeroPad(hash, length) {
|
|
49
50
|
var value = hash;
|
|
@@ -101,9 +102,10 @@ var LedgerBlindSigner = /** @class */ (function () {
|
|
|
101
102
|
};
|
|
102
103
|
LedgerBlindSigner.prototype.signTransaction = function (transactions, transactionsDetail) {
|
|
103
104
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var msgHash;
|
|
105
|
+
var calldata, msgHash;
|
|
105
106
|
return __generator(this, function (_a) {
|
|
106
|
-
|
|
107
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, transactionsDetail.nonce);
|
|
108
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(transactionsDetail.walletAddress, transactionsDetail.version, (0, hash_1.getSelectorFromName)('__execute__'), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
|
|
107
109
|
return [2 /*return*/, this.sign(msgHash)];
|
|
108
110
|
});
|
|
109
111
|
});
|
package/dist/types/api.d.ts
CHANGED
|
@@ -65,7 +65,9 @@ export declare type Endpoints = {
|
|
|
65
65
|
RESPONSE: CallContractResponse;
|
|
66
66
|
};
|
|
67
67
|
estimate_fee: {
|
|
68
|
-
QUERY:
|
|
68
|
+
QUERY: {
|
|
69
|
+
blockIdentifier: BlockIdentifier;
|
|
70
|
+
};
|
|
69
71
|
REQUEST: CallContractTransaction;
|
|
70
72
|
RESPONSE: EstimateFeeResponse;
|
|
71
73
|
};
|
|
@@ -90,6 +92,7 @@ export declare type InvokeFunctionTransaction = {
|
|
|
90
92
|
calldata?: RawCalldata;
|
|
91
93
|
nonce?: BigNumberish;
|
|
92
94
|
max_fee?: BigNumberish;
|
|
95
|
+
version?: BigNumberish;
|
|
93
96
|
};
|
|
94
97
|
export declare type InvokeFunctionTrace = {
|
|
95
98
|
caller_address: string;
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare type Call = Omit<Invocation, 'signature'>;
|
|
|
18
18
|
export declare type InvocationsDetails = {
|
|
19
19
|
nonce?: BigNumberish;
|
|
20
20
|
maxFee?: BigNumberish;
|
|
21
|
+
version?: BigNumberish;
|
|
21
22
|
};
|
|
22
23
|
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
23
24
|
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
package/dist/types/signer.d.ts
CHANGED