starknet 3.1.0 → 3.4.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 +19 -0
- package/__mocks__/ArgentAccount.json +68548 -51944
- package/__mocks__/TestDapp.json +12962 -0
- package/__tests__/account.test.ts +63 -50
- package/__tests__/accountContract.test.ts +51 -71
- package/__tests__/contract.test.ts +32 -20
- package/__tests__/fixtures.ts +13 -0
- package/__tests__/provider.test.ts +3 -15
- 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 +20 -13
- package/__tests__/utils/utils.test.ts +3 -3
- package/account/default.d.ts +10 -4
- package/account/default.js +165 -84
- package/account/interface.d.ts +2 -2
- package/dist/account/default.d.ts +8 -3
- package/dist/account/default.js +129 -55
- package/dist/account/interface.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/provider/default.d.ts +6 -4
- package/dist/provider/default.js +42 -17
- package/dist/provider/interface.d.ts +5 -1
- package/dist/signer/default.d.ts +1 -1
- package/dist/signer/default.js +6 -18
- package/dist/signer/interface.d.ts +3 -2
- package/dist/types/api.d.ts +5 -0
- package/dist/types/lib.d.ts +3 -3
- package/dist/utils/ellipticCurve.js +1 -1
- package/dist/utils/hash.d.ts +12 -2
- package/dist/utils/hash.js +37 -9
- package/dist/utils/stark.d.ts +0 -8
- package/dist/utils/stark.js +1 -14
- package/dist/utils/transaction.d.ts +19 -0
- package/dist/utils/transaction.js +75 -0
- package/dist/utils/typedData/index.d.ts +1 -1
- package/dist/utils/typedData/index.js +2 -3
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/provider/default.d.ts +6 -4
- package/provider/default.js +55 -19
- package/provider/interface.d.ts +5 -1
- package/signer/default.d.ts +1 -1
- package/signer/default.js +10 -44
- package/signer/interface.d.ts +3 -2
- package/src/account/default.ts +129 -42
- package/src/account/interface.ts +2 -2
- package/src/index.ts +1 -0
- package/src/provider/default.ts +32 -22
- package/src/provider/interface.ts +6 -1
- package/src/signer/default.ts +10 -26
- package/src/signer/interface.ts +3 -2
- package/src/types/api.ts +5 -0
- package/src/types/lib.ts +3 -4
- package/src/utils/ellipticCurve.ts +1 -1
- package/src/utils/hash.ts +39 -12
- package/src/utils/stark.ts +1 -14
- package/src/utils/transaction.ts +50 -0
- package/src/utils/typedData/index.ts +2 -3
- package/types/api.d.ts +5 -0
- package/types/lib.d.ts +3 -3
- package/utils/ellipticCurve.js +1 -1
- package/utils/hash.d.ts +15 -6
- package/utils/hash.js +42 -10
- package/utils/stark.d.ts +0 -8
- package/utils/stark.js +0 -14
- package/utils/transaction.d.ts +19 -0
- package/utils/transaction.js +99 -0
- package/utils/typedData/index.d.ts +1 -1
- package/utils/typedData/index.js +2 -3
package/dist/account/default.js
CHANGED
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -61,17 +50,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
61
50
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
51
|
}
|
|
63
52
|
};
|
|
64
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
65
|
-
var t = {};
|
|
66
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
67
|
-
t[p] = s[p];
|
|
68
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
69
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
70
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
71
|
-
t[p[i]] = s[p[i]];
|
|
72
|
-
}
|
|
73
|
-
return t;
|
|
74
|
-
};
|
|
75
53
|
var __read = (this && this.__read) || function (o, n) {
|
|
76
54
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
77
55
|
if (!m) return o;
|
|
@@ -97,12 +75,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
97
75
|
}
|
|
98
76
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
99
77
|
};
|
|
78
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
+
};
|
|
100
81
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
101
82
|
exports.Account = void 0;
|
|
83
|
+
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
102
84
|
var provider_1 = require("../provider");
|
|
103
85
|
var signer_1 = require("../signer");
|
|
86
|
+
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
87
|
+
var hash_1 = require("../utils/hash");
|
|
104
88
|
var number_1 = require("../utils/number");
|
|
105
89
|
var stark_1 = require("../utils/stark");
|
|
90
|
+
var transaction_1 = require("../utils/transaction");
|
|
106
91
|
var typedData_1 = require("../utils/typedData");
|
|
107
92
|
var Account = /** @class */ (function (_super) {
|
|
108
93
|
__extends(Account, _super);
|
|
@@ -136,47 +121,136 @@ var Account = /** @class */ (function (_super) {
|
|
|
136
121
|
* @param transaction - transaction to be invoked
|
|
137
122
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
138
123
|
*/
|
|
139
|
-
Account.prototype.execute = function (
|
|
140
|
-
|
|
124
|
+
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
if (abis === void 0) { abis = undefined; }
|
|
141
127
|
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
142
128
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
-
var
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
var transactions, signerDetails, _c, _d, signature, calldata;
|
|
130
|
+
var _e;
|
|
131
|
+
return __generator(this, function (_f) {
|
|
132
|
+
switch (_f.label) {
|
|
146
133
|
case 0:
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
nonce = transactionsDetail.nonce;
|
|
134
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
135
|
+
_e = {
|
|
136
|
+
walletAddress: this.address
|
|
137
|
+
};
|
|
152
138
|
_c = number_1.toBN;
|
|
153
|
-
if (!(nonce !== null &&
|
|
154
|
-
_d =
|
|
139
|
+
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
140
|
+
_d = _a;
|
|
155
141
|
return [3 /*break*/, 3];
|
|
156
142
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
157
143
|
case 2:
|
|
158
|
-
_d = (
|
|
159
|
-
|
|
144
|
+
_d = (_f.sent());
|
|
145
|
+
_f.label = 3;
|
|
160
146
|
case 3:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
], { walletAddress: this.address, nonce: nonceBn }, abis)];
|
|
147
|
+
signerDetails = (_e.nonce = _c.apply(void 0, [_d]),
|
|
148
|
+
_e.maxFee = (0, number_1.toBN)((_b = transactionsDetail.maxFee) !== null && _b !== void 0 ? _b : '0'),
|
|
149
|
+
_e);
|
|
150
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
166
151
|
case 4:
|
|
167
|
-
signature =
|
|
168
|
-
|
|
169
|
-
return [2 /*return*/,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
152
|
+
signature = _f.sent();
|
|
153
|
+
calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
|
|
154
|
+
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
155
|
+
type: 'INVOKE_FUNCTION',
|
|
156
|
+
contract_address: this.address,
|
|
157
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
158
|
+
calldata: calldata,
|
|
159
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
160
|
+
})];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
167
|
+
* @deprecated to remove ASAP
|
|
168
|
+
*/
|
|
169
|
+
Account.prototype.LEGACY_addTransaction = function (transaction) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
function hashMulticall(account, transactions, nonce, maxFee) {
|
|
172
|
+
var hashArray = transactions
|
|
173
|
+
.map(function (_a) {
|
|
174
|
+
var contract_address = _a.contract_address, entry_point_selector = _a.entry_point_selector, calldata = _a.calldata;
|
|
175
|
+
return [
|
|
176
|
+
contract_address,
|
|
177
|
+
entry_point_selector,
|
|
178
|
+
(0, hash_1.computeHashOnElements)(calldata || []),
|
|
179
|
+
];
|
|
180
|
+
})
|
|
181
|
+
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
182
|
+
.map(hash_1.computeHashOnElements);
|
|
183
|
+
return (0, hash_1.computeHashOnElements)([
|
|
184
|
+
hash_1.transactionPrefix,
|
|
185
|
+
account,
|
|
186
|
+
(0, hash_1.computeHashOnElements)(hashArray),
|
|
187
|
+
nonce,
|
|
188
|
+
maxFee,
|
|
189
|
+
hash_1.transactionVersion,
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
var nonceBn, result, msgHash, signature, transformCallsToMulticallArrays, fromCallsToExecuteCalldata2, calldata;
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
switch (_a.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
if (transaction.type === 'DEPLOY')
|
|
197
|
+
throw new Error('No DEPLOYS');
|
|
198
|
+
(0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
199
|
+
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
200
|
+
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
|
201
|
+
return [3 /*break*/, 3];
|
|
202
|
+
case 1: return [4 /*yield*/, this.callContract({
|
|
203
|
+
contractAddress: this.address,
|
|
204
|
+
entrypoint: 'get_nonce',
|
|
205
|
+
})];
|
|
206
|
+
case 2:
|
|
207
|
+
result = (_a.sent()).result;
|
|
208
|
+
nonceBn = (0, number_1.toBN)(result[0]);
|
|
209
|
+
_a.label = 3;
|
|
210
|
+
case 3:
|
|
211
|
+
msgHash = hashMulticall(this.address, [transaction], nonceBn.toString(), '0');
|
|
212
|
+
if (!('keyPair' in this.signer)) {
|
|
213
|
+
throw new Error('No keyPair');
|
|
214
|
+
}
|
|
215
|
+
signature = (0, ellipticCurve_1.sign)(this.signer.keyPair, msgHash);
|
|
216
|
+
transformCallsToMulticallArrays = function (calls) {
|
|
217
|
+
var callArray = [];
|
|
218
|
+
var calldata = [];
|
|
219
|
+
calls.forEach(function (call) {
|
|
220
|
+
var data = call.calldata || [];
|
|
221
|
+
callArray.push({
|
|
222
|
+
to: (0, number_1.toBN)(call.contract_address).toString(10),
|
|
223
|
+
selector: (0, number_1.toBN)(call.entry_point_selector).toString(10),
|
|
224
|
+
data_offset: calldata.length.toString(),
|
|
225
|
+
data_len: data.length.toString(),
|
|
226
|
+
});
|
|
227
|
+
calldata.push.apply(calldata, __spreadArray([], __read(data), false));
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
callArray: callArray,
|
|
231
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata),
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
fromCallsToExecuteCalldata2 = function (calls) {
|
|
235
|
+
var _a = transformCallsToMulticallArrays(calls), callArray = _a.callArray, calldata = _a.calldata;
|
|
236
|
+
return __spreadArray(__spreadArray(__spreadArray([
|
|
237
|
+
callArray.length.toString()
|
|
238
|
+
], __read(callArray
|
|
239
|
+
.map(function (_a) {
|
|
240
|
+
var to = _a.to, selector = _a.selector, data_offset = _a.data_offset, data_len = _a.data_len;
|
|
241
|
+
return [to, selector, data_offset, data_len];
|
|
242
|
+
})
|
|
243
|
+
.flat()), false), [
|
|
244
|
+
calldata.length.toString()
|
|
245
|
+
], false), __read(calldata), false);
|
|
246
|
+
};
|
|
247
|
+
calldata = __spreadArray(__spreadArray([], __read(fromCallsToExecuteCalldata2([transaction])), false), [nonceBn.toString()], false);
|
|
248
|
+
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
249
|
+
type: 'INVOKE_FUNCTION',
|
|
250
|
+
contract_address: this.address,
|
|
251
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
252
|
+
calldata: calldata,
|
|
253
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
180
254
|
})];
|
|
181
255
|
}
|
|
182
256
|
});
|
|
@@ -213,7 +287,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
213
287
|
/**
|
|
214
288
|
* Verify a signature of a JSON object
|
|
215
289
|
*
|
|
216
|
-
* @param
|
|
290
|
+
* @param hash - JSON object to be verified
|
|
217
291
|
* @param signature - signature of the JSON object
|
|
218
292
|
* @returns true if the signature is valid, false otherwise
|
|
219
293
|
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
-
import { Abi, AddTransactionResponse,
|
|
2
|
+
import { Abi, AddTransactionResponse, Call, DeployContractPayload, InvocationsDetails, Signature } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { TypedData } from '../utils/typedData/types';
|
|
5
5
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
@@ -27,7 +27,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
27
27
|
*
|
|
28
28
|
* @returns response from addTransaction
|
|
29
29
|
*/
|
|
30
|
-
abstract execute(transactions:
|
|
30
|
+
abstract execute(transactions: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
|
|
31
31
|
/**
|
|
32
32
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
33
33
|
* This adds a message prefix so it cant be interchanged with transactions
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -113,13 +113,15 @@ export declare class Provider implements ProviderInterface {
|
|
|
113
113
|
* Invokes a function on starknet
|
|
114
114
|
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
115
115
|
*
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @param calldata - (optional, default []) calldata
|
|
119
|
-
* @param signature - (optional) signature to send along
|
|
116
|
+
* @param invocation
|
|
117
|
+
* @param _abi - (optional) signature to send along
|
|
120
118
|
* @returns response from addTransaction
|
|
121
119
|
*/
|
|
122
120
|
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
121
|
+
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated use `waitForTransaction` instead
|
|
124
|
+
*/
|
|
123
125
|
waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
124
126
|
}
|
|
125
127
|
export {};
|
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 hash_1 = require("../utils/hash");
|
|
72
73
|
var json_1 = require("../utils/json");
|
|
73
74
|
var number_1 = require("../utils/number");
|
|
74
75
|
var stark_1 = require("../utils/stark");
|
|
@@ -144,8 +145,9 @@ var Provider = /** @class */ (function () {
|
|
|
144
145
|
};
|
|
145
146
|
// typesafe fetch
|
|
146
147
|
Provider.prototype.fetchEndpoint = function (endpoint) {
|
|
148
|
+
var _a;
|
|
147
149
|
// typescript type magiuc to create a nice fitting function interface
|
|
148
|
-
var
|
|
150
|
+
var _b = []; // when both query and request are needed, we cant omit anything
|
|
149
151
|
for (
|
|
150
152
|
// typescript type magiuc to create a nice fitting function interface
|
|
151
153
|
var _i = 1 // when both query and request are needed, we cant omit anything
|
|
@@ -157,28 +159,39 @@ var Provider = /** @class */ (function () {
|
|
|
157
159
|
_i++ // when both query and request are needed, we cant omit anything
|
|
158
160
|
) {
|
|
159
161
|
// typescript type magiuc to create a nice fitting function interface
|
|
160
|
-
|
|
162
|
+
_b[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
|
|
161
163
|
}
|
|
162
164
|
// typescript type magiuc to create a nice fitting function interface
|
|
163
|
-
var
|
|
165
|
+
var _c = __read(_b, 2), query = _c[0], request = _c[1]; // when both query and request are needed, we cant omit anything
|
|
164
166
|
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
-
var baseUrl, method, queryString, headers, data;
|
|
166
|
-
return __generator(this, function (
|
|
167
|
-
switch (
|
|
167
|
+
var baseUrl, method, queryString, headers, data, error_1, data;
|
|
168
|
+
return __generator(this, function (_d) {
|
|
169
|
+
switch (_d.label) {
|
|
168
170
|
case 0:
|
|
169
171
|
baseUrl = this.getFetchUrl(endpoint);
|
|
170
172
|
method = this.getFetchMethod(endpoint);
|
|
171
173
|
queryString = this.getQueryString(query);
|
|
172
174
|
headers = this.getHeaders(method);
|
|
175
|
+
_d.label = 1;
|
|
176
|
+
case 1:
|
|
177
|
+
_d.trys.push([1, 3, , 4]);
|
|
173
178
|
return [4 /*yield*/, axios_1.default.request({
|
|
174
179
|
method: method,
|
|
175
180
|
url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
|
|
176
181
|
data: (0, json_1.stringify)(request),
|
|
177
182
|
headers: headers,
|
|
178
183
|
})];
|
|
179
|
-
case
|
|
180
|
-
data = (
|
|
184
|
+
case 2:
|
|
185
|
+
data = (_d.sent()).data;
|
|
181
186
|
return [2 /*return*/, data];
|
|
187
|
+
case 3:
|
|
188
|
+
error_1 = _d.sent();
|
|
189
|
+
data = (_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
190
|
+
if (data === null || data === void 0 ? void 0 : data.message) {
|
|
191
|
+
throw new Error(data.code + ": " + data.message);
|
|
192
|
+
}
|
|
193
|
+
throw error_1;
|
|
194
|
+
case 4: return [2 /*return*/];
|
|
182
195
|
}
|
|
183
196
|
});
|
|
184
197
|
});
|
|
@@ -216,7 +229,7 @@ var Provider = /** @class */ (function () {
|
|
|
216
229
|
}, {
|
|
217
230
|
signature: [],
|
|
218
231
|
contract_address: contractAddress,
|
|
219
|
-
entry_point_selector: (0,
|
|
232
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
|
|
220
233
|
calldata: calldata,
|
|
221
234
|
})];
|
|
222
235
|
});
|
|
@@ -358,10 +371,8 @@ var Provider = /** @class */ (function () {
|
|
|
358
371
|
* Invokes a function on starknet
|
|
359
372
|
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
360
373
|
*
|
|
361
|
-
* @param
|
|
362
|
-
* @param
|
|
363
|
-
* @param calldata - (optional, default []) calldata
|
|
364
|
-
* @param signature - (optional) signature to send along
|
|
374
|
+
* @param invocation
|
|
375
|
+
* @param _abi - (optional) signature to send along
|
|
365
376
|
* @returns response from addTransaction
|
|
366
377
|
*/
|
|
367
378
|
Provider.prototype.invokeFunction = function (invocation, _abi) {
|
|
@@ -369,15 +380,15 @@ var Provider = /** @class */ (function () {
|
|
|
369
380
|
return this.fetchEndpoint('add_transaction', undefined, {
|
|
370
381
|
type: 'INVOKE_FUNCTION',
|
|
371
382
|
contract_address: invocation.contractAddress,
|
|
372
|
-
entry_point_selector: (0,
|
|
383
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
|
|
373
384
|
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)((_a = invocation.calldata) !== null && _a !== void 0 ? _a : []),
|
|
374
385
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = invocation.signature) !== null && _b !== void 0 ? _b : []),
|
|
375
386
|
});
|
|
376
387
|
};
|
|
377
|
-
Provider.prototype.
|
|
388
|
+
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
378
389
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
379
390
|
return __awaiter(this, void 0, void 0, function () {
|
|
380
|
-
var onchain, res, error;
|
|
391
|
+
var onchain, res, message, error;
|
|
381
392
|
return __generator(this, function (_a) {
|
|
382
393
|
switch (_a.label) {
|
|
383
394
|
case 0:
|
|
@@ -400,7 +411,10 @@ var Provider = /** @class */ (function () {
|
|
|
400
411
|
onchain = true;
|
|
401
412
|
}
|
|
402
413
|
else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
|
|
403
|
-
|
|
414
|
+
message = res.tx_failure_reason
|
|
415
|
+
? res.tx_status + ": " + res.tx_failure_reason.code + "\n" + res.tx_failure_reason.error_message
|
|
416
|
+
: res.tx_status;
|
|
417
|
+
error = new Error(message);
|
|
404
418
|
error.response = res;
|
|
405
419
|
throw error;
|
|
406
420
|
}
|
|
@@ -410,6 +424,17 @@ var Provider = /** @class */ (function () {
|
|
|
410
424
|
});
|
|
411
425
|
});
|
|
412
426
|
};
|
|
427
|
+
/**
|
|
428
|
+
* @deprecated use `waitForTransaction` instead
|
|
429
|
+
*/
|
|
430
|
+
Provider.prototype.waitForTx = function (txHash, retryInterval) {
|
|
431
|
+
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
432
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
433
|
+
return __generator(this, function (_a) {
|
|
434
|
+
return [2 /*return*/, this.waitForTransaction(txHash, retryInterval)];
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
};
|
|
413
438
|
return Provider;
|
|
414
439
|
}());
|
|
415
440
|
exports.Provider = Provider;
|
|
@@ -97,5 +97,9 @@ export declare abstract class ProviderInterface {
|
|
|
97
97
|
* @returns response from addTransaction
|
|
98
98
|
*/
|
|
99
99
|
abstract invokeFunction(invocation: Invocation): Promise<AddTransactionResponse>;
|
|
100
|
-
abstract
|
|
100
|
+
abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated use `waitForTransaction` instead
|
|
103
|
+
*/
|
|
104
|
+
abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
101
105
|
}
|
package/dist/signer/default.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare class Signer implements SignerInterface {
|
|
|
6
6
|
constructor(keyPair: KeyPair);
|
|
7
7
|
getPubKey(): Promise<string>;
|
|
8
8
|
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
9
|
-
signMessage(typedData: TypedData,
|
|
9
|
+
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
10
10
|
}
|
package/dist/signer/default.js
CHANGED
|
@@ -38,10 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Signer = void 0;
|
|
40
40
|
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
41
|
-
var encode_1 = require("../utils/encode");
|
|
42
41
|
var hash_1 = require("../utils/hash");
|
|
43
|
-
var number_1 = require("../utils/number");
|
|
44
|
-
var stark_1 = require("../utils/stark");
|
|
45
42
|
var typedData_1 = require("../utils/typedData");
|
|
46
43
|
var Signer = /** @class */ (function () {
|
|
47
44
|
function Signer(keyPair) {
|
|
@@ -55,31 +52,22 @@ var Signer = /** @class */ (function () {
|
|
|
55
52
|
});
|
|
56
53
|
};
|
|
57
54
|
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
58
|
-
if (abis === void 0) { abis = []; }
|
|
59
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var
|
|
61
|
-
return __generator(this, function (
|
|
62
|
-
if (
|
|
63
|
-
throw new Error('Only one transaction at a time is currently supported by this signer');
|
|
64
|
-
}
|
|
65
|
-
if ((abis === null || abis === void 0 ? void 0 : abis.length) !== 0 && abis.length !== transactions.length) {
|
|
56
|
+
var msgHash;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
if (abis && abis.length !== transactions.length) {
|
|
66
59
|
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
67
60
|
}
|
|
68
|
-
|
|
69
|
-
nonce = transactionsDetail.nonce, walletAddress = transactionsDetail.walletAddress;
|
|
70
|
-
nonceBn = (0, number_1.toBN)(nonce);
|
|
71
|
-
entrypointSelector = (0, stark_1.getSelectorFromName)(entrypoint);
|
|
72
|
-
calldataDecimal = (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata);
|
|
73
|
-
msgHash = (0, encode_1.addHexPrefix)((0, hash_1.hashMessage)(walletAddress, contractAddress, entrypointSelector, calldataDecimal, nonceBn.toString()));
|
|
61
|
+
msgHash = (0, hash_1.hashMulticall)(transactionsDetail.walletAddress, transactions, transactionsDetail.nonce.toString(), transactionsDetail.maxFee.toString());
|
|
74
62
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
75
63
|
});
|
|
76
64
|
});
|
|
77
65
|
};
|
|
78
|
-
Signer.prototype.signMessage = function (typedData,
|
|
66
|
+
Signer.prototype.signMessage = function (typedData, accountAddress) {
|
|
79
67
|
return __awaiter(this, void 0, void 0, function () {
|
|
80
68
|
var msgHash;
|
|
81
69
|
return __generator(this, function (_a) {
|
|
82
|
-
msgHash = (0, typedData_1.getMessageHash)(typedData,
|
|
70
|
+
msgHash = (0, typedData_1.getMessageHash)(typedData, accountAddress);
|
|
83
71
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
84
72
|
});
|
|
85
73
|
});
|
|
@@ -11,11 +11,12 @@ export declare abstract class SignerInterface {
|
|
|
11
11
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
12
12
|
* This adds a message prefix so it cant be interchanged with transactions
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
14
|
+
* @param typedData - JSON object to be signed
|
|
15
|
+
* @param accountAddress - account
|
|
15
16
|
* @returns the signature of the JSON object
|
|
16
17
|
* @throws {Error} if the JSON object is not a valid JSON
|
|
17
18
|
*/
|
|
18
|
-
abstract signMessage(typedData: TypedData,
|
|
19
|
+
abstract signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
|
19
20
|
/**
|
|
20
21
|
* Signs a transaction with the starknet private key and returns the signature
|
|
21
22
|
*
|
package/dist/types/api.d.ts
CHANGED
|
@@ -115,6 +115,11 @@ export declare type GetCodeResponse = {
|
|
|
115
115
|
export declare type GetTransactionStatusResponse = {
|
|
116
116
|
tx_status: Status;
|
|
117
117
|
block_hash: string;
|
|
118
|
+
tx_failure_reason?: {
|
|
119
|
+
tx_id: number;
|
|
120
|
+
code: string;
|
|
121
|
+
error_message: string;
|
|
122
|
+
};
|
|
118
123
|
};
|
|
119
124
|
export declare type GetTransactionResponse = {
|
|
120
125
|
status: Status;
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ec as EC } from 'elliptic';
|
|
2
2
|
import type { BigNumberish } from '../utils/number';
|
|
3
3
|
export declare type KeyPair = EC.KeyPair;
|
|
4
|
-
export declare type Signature =
|
|
4
|
+
export declare type Signature = string[];
|
|
5
5
|
export declare type RawCalldata = BigNumberish[];
|
|
6
6
|
export declare type DeployContractPayload = {
|
|
7
7
|
contract: CompiledContract | string;
|
|
@@ -14,11 +14,11 @@ export declare type Invocation = {
|
|
|
14
14
|
calldata?: RawCalldata;
|
|
15
15
|
signature?: Signature;
|
|
16
16
|
};
|
|
17
|
-
export declare type
|
|
17
|
+
export declare type Call = Omit<Invocation, 'signature'>;
|
|
18
18
|
export declare type InvocationsDetails = {
|
|
19
19
|
nonce?: BigNumberish;
|
|
20
|
+
maxFee?: BigNumberish;
|
|
20
21
|
};
|
|
21
|
-
export declare type Call = Omit<Invocation, 'signature' | 'nonce'>;
|
|
22
22
|
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
23
23
|
export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
|
|
24
24
|
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
@@ -93,7 +93,7 @@ function sign(keyPair, msgHash) {
|
|
|
93
93
|
(0, number_1.assertInRange)(r, constants_1.ONE, (0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.MAX_ECDSA_VAL)), 'r');
|
|
94
94
|
(0, number_1.assertInRange)(s, constants_1.ONE, (0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.EC_ORDER)), 's');
|
|
95
95
|
(0, number_1.assertInRange)(w, constants_1.ONE, (0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.MAX_ECDSA_VAL)), 'w');
|
|
96
|
-
return [r, s];
|
|
96
|
+
return [r.toString(), s.toString()];
|
|
97
97
|
}
|
|
98
98
|
exports.sign = sign;
|
|
99
99
|
function chunkArray(arr, n) {
|
package/dist/utils/hash.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
|
+
import { Call } from '../types';
|
|
2
3
|
import { BigNumberish } from './number';
|
|
4
|
+
export declare const transactionPrefix: string;
|
|
5
|
+
export declare const transactionVersion = 0;
|
|
3
6
|
/**
|
|
4
7
|
* Function to get the starknet keccak hash from a string
|
|
5
8
|
*
|
|
@@ -8,7 +11,14 @@ import { BigNumberish } from './number';
|
|
|
8
11
|
* @returns starknet keccak hash as BigNumber
|
|
9
12
|
*/
|
|
10
13
|
export declare function starknetKeccak(value: string): BN;
|
|
14
|
+
/**
|
|
15
|
+
* Function to get the hex selector from a given function name
|
|
16
|
+
*
|
|
17
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
|
|
18
|
+
* @param funcName - selectors abi function name
|
|
19
|
+
* @returns hex selector of given abi function name
|
|
20
|
+
*/
|
|
21
|
+
export declare function getSelectorFromName(funcName: string): string;
|
|
11
22
|
export declare function pedersen(input: [BigNumberish, BigNumberish]): string;
|
|
12
23
|
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function hashMessage(account: string, to: string, selector: string, calldata: string[], nonce: string): string;
|
|
24
|
+
export declare function hashMulticall(account: string, transactions: Call[], nonce: string, maxFee: string): string;
|