starknet 3.3.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 +6 -0
- package/account/default.d.ts +6 -0
- package/account/default.js +129 -0
- package/dist/account/default.d.ts +6 -1
- package/dist/account/default.js +99 -0
- package/dist/provider/default.d.ts +1 -12
- package/dist/provider/default.js +0 -19
- package/package.json +1 -1
- package/provider/default.d.ts +0 -17
- package/provider/default.js +0 -28
- package/src/account/default.ts +109 -1
- package/src/provider/default.ts +0 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# [3.4.0](https://github.com/seanjameshan/starknet.js/compare/v3.3.0...v3.4.0) (2022-03-10)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **account:** add legacy `addTransaction` method ([94f5d87](https://github.com/seanjameshan/starknet.js/commit/94f5d874c8fb5f6c6586d537b75b92f493a32676))
|
|
6
|
+
|
|
1
7
|
# [3.3.0](https://github.com/seanjameshan/starknet.js/compare/v3.2.0...v3.3.0) (2022-03-08)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/account/default.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
InvocationsDetails,
|
|
7
7
|
KeyPair,
|
|
8
8
|
Signature,
|
|
9
|
+
Transaction,
|
|
9
10
|
} from '../types';
|
|
10
11
|
import { BigNumberish } from '../utils/number';
|
|
11
12
|
import { TypedData } from '../utils/typedData';
|
|
@@ -28,6 +29,11 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
28
29
|
abis?: Abi[] | undefined,
|
|
29
30
|
transactionsDetail?: InvocationsDetails
|
|
30
31
|
): Promise<AddTransactionResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
34
|
+
* @deprecated to remove ASAP
|
|
35
|
+
*/
|
|
36
|
+
LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
31
37
|
/**
|
|
32
38
|
* Sign an JSON object with the starknet private key and return the signature
|
|
33
39
|
*
|
package/account/default.js
CHANGED
|
@@ -189,10 +189,17 @@ var __spreadArray =
|
|
|
189
189
|
}
|
|
190
190
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
191
191
|
};
|
|
192
|
+
var __importDefault =
|
|
193
|
+
(this && this.__importDefault) ||
|
|
194
|
+
function (mod) {
|
|
195
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
196
|
+
};
|
|
192
197
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
193
198
|
exports.Account = void 0;
|
|
199
|
+
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
194
200
|
var provider_1 = require('../provider');
|
|
195
201
|
var signer_1 = require('../signer');
|
|
202
|
+
var ellipticCurve_1 = require('../utils/ellipticCurve');
|
|
196
203
|
var hash_1 = require('../utils/hash');
|
|
197
204
|
var number_1 = require('../utils/number');
|
|
198
205
|
var stark_1 = require('../utils/stark');
|
|
@@ -295,6 +302,128 @@ var Account = /** @class */ (function (_super) {
|
|
|
295
302
|
});
|
|
296
303
|
});
|
|
297
304
|
};
|
|
305
|
+
/**
|
|
306
|
+
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
307
|
+
* @deprecated to remove ASAP
|
|
308
|
+
*/
|
|
309
|
+
Account.prototype.LEGACY_addTransaction = function (transaction) {
|
|
310
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
311
|
+
function hashMulticall(account, transactions, nonce, maxFee) {
|
|
312
|
+
var hashArray = transactions
|
|
313
|
+
.map(function (_a) {
|
|
314
|
+
var contract_address = _a.contract_address,
|
|
315
|
+
entry_point_selector = _a.entry_point_selector,
|
|
316
|
+
calldata = _a.calldata;
|
|
317
|
+
return [
|
|
318
|
+
contract_address,
|
|
319
|
+
entry_point_selector,
|
|
320
|
+
(0, hash_1.computeHashOnElements)(calldata || []),
|
|
321
|
+
];
|
|
322
|
+
})
|
|
323
|
+
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
324
|
+
.map(hash_1.computeHashOnElements);
|
|
325
|
+
return (0,
|
|
326
|
+
hash_1.computeHashOnElements)([hash_1.transactionPrefix, account, (0, hash_1.computeHashOnElements)(hashArray), nonce, maxFee, hash_1.transactionVersion]);
|
|
327
|
+
}
|
|
328
|
+
var nonceBn,
|
|
329
|
+
result,
|
|
330
|
+
msgHash,
|
|
331
|
+
signature,
|
|
332
|
+
transformCallsToMulticallArrays,
|
|
333
|
+
fromCallsToExecuteCalldata2,
|
|
334
|
+
calldata;
|
|
335
|
+
return __generator(this, function (_a) {
|
|
336
|
+
switch (_a.label) {
|
|
337
|
+
case 0:
|
|
338
|
+
if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
|
|
339
|
+
(0,
|
|
340
|
+
minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
|
|
341
|
+
if (!transaction.nonce) return [3 /*break*/, 1];
|
|
342
|
+
nonceBn = (0, number_1.toBN)(transaction.nonce);
|
|
343
|
+
return [3 /*break*/, 3];
|
|
344
|
+
case 1:
|
|
345
|
+
return [
|
|
346
|
+
4 /*yield*/,
|
|
347
|
+
this.callContract({
|
|
348
|
+
contractAddress: this.address,
|
|
349
|
+
entrypoint: 'get_nonce',
|
|
350
|
+
}),
|
|
351
|
+
];
|
|
352
|
+
case 2:
|
|
353
|
+
result = _a.sent().result;
|
|
354
|
+
nonceBn = (0, number_1.toBN)(result[0]);
|
|
355
|
+
_a.label = 3;
|
|
356
|
+
case 3:
|
|
357
|
+
msgHash = hashMulticall(this.address, [transaction], nonceBn.toString(), '0');
|
|
358
|
+
if (!('keyPair' in this.signer)) {
|
|
359
|
+
throw new Error('No keyPair');
|
|
360
|
+
}
|
|
361
|
+
signature = (0, ellipticCurve_1.sign)(this.signer.keyPair, msgHash);
|
|
362
|
+
transformCallsToMulticallArrays = function (calls) {
|
|
363
|
+
var callArray = [];
|
|
364
|
+
var calldata = [];
|
|
365
|
+
calls.forEach(function (call) {
|
|
366
|
+
var data = call.calldata || [];
|
|
367
|
+
callArray.push({
|
|
368
|
+
to: (0, number_1.toBN)(call.contract_address).toString(10),
|
|
369
|
+
selector: (0, number_1.toBN)(call.entry_point_selector).toString(10),
|
|
370
|
+
data_offset: calldata.length.toString(),
|
|
371
|
+
data_len: data.length.toString(),
|
|
372
|
+
});
|
|
373
|
+
calldata.push.apply(calldata, __spreadArray([], __read(data), false));
|
|
374
|
+
});
|
|
375
|
+
return {
|
|
376
|
+
callArray: callArray,
|
|
377
|
+
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata),
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
fromCallsToExecuteCalldata2 = function (calls) {
|
|
381
|
+
var _a = transformCallsToMulticallArrays(calls),
|
|
382
|
+
callArray = _a.callArray,
|
|
383
|
+
calldata = _a.calldata;
|
|
384
|
+
return __spreadArray(
|
|
385
|
+
__spreadArray(
|
|
386
|
+
__spreadArray(
|
|
387
|
+
[callArray.length.toString()],
|
|
388
|
+
__read(
|
|
389
|
+
callArray
|
|
390
|
+
.map(function (_a) {
|
|
391
|
+
var to = _a.to,
|
|
392
|
+
selector = _a.selector,
|
|
393
|
+
data_offset = _a.data_offset,
|
|
394
|
+
data_len = _a.data_len;
|
|
395
|
+
return [to, selector, data_offset, data_len];
|
|
396
|
+
})
|
|
397
|
+
.flat()
|
|
398
|
+
),
|
|
399
|
+
false
|
|
400
|
+
),
|
|
401
|
+
[calldata.length.toString()],
|
|
402
|
+
false
|
|
403
|
+
),
|
|
404
|
+
__read(calldata),
|
|
405
|
+
false
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
calldata = __spreadArray(
|
|
409
|
+
__spreadArray([], __read(fromCallsToExecuteCalldata2([transaction])), false),
|
|
410
|
+
[nonceBn.toString()],
|
|
411
|
+
false
|
|
412
|
+
);
|
|
413
|
+
return [
|
|
414
|
+
2 /*return*/,
|
|
415
|
+
this.fetchEndpoint('add_transaction', undefined, {
|
|
416
|
+
type: 'INVOKE_FUNCTION',
|
|
417
|
+
contract_address: this.address,
|
|
418
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
419
|
+
calldata: calldata,
|
|
420
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
421
|
+
}),
|
|
422
|
+
];
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
};
|
|
298
427
|
/**
|
|
299
428
|
* Sign an JSON object with the starknet private key and return the signature
|
|
300
429
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import { Abi, AddTransactionResponse, Call, InvocationsDetails, KeyPair, Signature } from '../types';
|
|
2
|
+
import { Abi, AddTransactionResponse, Call, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { TypedData } from '../utils/typedData';
|
|
5
5
|
import { AccountInterface } from './interface';
|
|
@@ -17,6 +17,11 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
17
17
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
18
18
|
*/
|
|
19
19
|
execute(calls: Call | Call[], abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
22
|
+
* @deprecated to remove ASAP
|
|
23
|
+
*/
|
|
24
|
+
LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
|
|
20
25
|
/**
|
|
21
26
|
* Sign an JSON object with the starknet private key and return the signature
|
|
22
27
|
*
|
package/dist/account/default.js
CHANGED
|
@@ -75,10 +75,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
75
75
|
}
|
|
76
76
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
77
|
};
|
|
78
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
+
};
|
|
78
81
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
82
|
exports.Account = void 0;
|
|
83
|
+
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
80
84
|
var provider_1 = require("../provider");
|
|
81
85
|
var signer_1 = require("../signer");
|
|
86
|
+
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
82
87
|
var hash_1 = require("../utils/hash");
|
|
83
88
|
var number_1 = require("../utils/number");
|
|
84
89
|
var stark_1 = require("../utils/stark");
|
|
@@ -157,6 +162,100 @@ var Account = /** @class */ (function (_super) {
|
|
|
157
162
|
});
|
|
158
163
|
});
|
|
159
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),
|
|
254
|
+
})];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
160
259
|
/**
|
|
161
260
|
* Sign an JSON object with the starknet private key and return the signature
|
|
162
261
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation,
|
|
1
|
+
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
|
|
2
2
|
import { BigNumberish } from '../utils/number';
|
|
3
3
|
import { ProviderInterface } from './interface';
|
|
4
4
|
import { BlockIdentifier } from './utils';
|
|
@@ -118,17 +118,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
118
118
|
* @returns response from addTransaction
|
|
119
119
|
*/
|
|
120
120
|
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
121
|
-
/**
|
|
122
|
-
* Invokes a function on starknet
|
|
123
|
-
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
124
|
-
*
|
|
125
|
-
* @param contractAddress - target contract address for invoke
|
|
126
|
-
* @param entrypointSelector - target entrypoint selector for
|
|
127
|
-
* @param calldata - (optional, default []) calldata
|
|
128
|
-
* @param signature - (optional) signature to send along
|
|
129
|
-
* @returns response from addTransaction
|
|
130
|
-
*/
|
|
131
|
-
LEGACY_invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?: Signature): Promise<AddTransactionResponse>;
|
|
132
121
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
133
122
|
/**
|
|
134
123
|
* @deprecated use `waitForTransaction` instead
|
package/dist/provider/default.js
CHANGED
|
@@ -385,25 +385,6 @@ var Provider = /** @class */ (function () {
|
|
|
385
385
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = invocation.signature) !== null && _b !== void 0 ? _b : []),
|
|
386
386
|
});
|
|
387
387
|
};
|
|
388
|
-
/**
|
|
389
|
-
* Invokes a function on starknet
|
|
390
|
-
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
391
|
-
*
|
|
392
|
-
* @param contractAddress - target contract address for invoke
|
|
393
|
-
* @param entrypointSelector - target entrypoint selector for
|
|
394
|
-
* @param calldata - (optional, default []) calldata
|
|
395
|
-
* @param signature - (optional) signature to send along
|
|
396
|
-
* @returns response from addTransaction
|
|
397
|
-
*/
|
|
398
|
-
Provider.prototype.LEGACY_invokeFunction = function (contractAddress, entrypointSelector, calldata, signature) {
|
|
399
|
-
return this.fetchEndpoint('add_transaction', undefined, {
|
|
400
|
-
type: 'INVOKE_FUNCTION',
|
|
401
|
-
contract_address: contractAddress,
|
|
402
|
-
entry_point_selector: entrypointSelector,
|
|
403
|
-
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata !== null && calldata !== void 0 ? calldata : []),
|
|
404
|
-
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature !== null && signature !== void 0 ? signature : []),
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
388
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
408
389
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
409
390
|
return __awaiter(this, void 0, void 0, function () {
|
package/package.json
CHANGED
package/provider/default.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
GetTransactionResponse,
|
|
12
12
|
GetTransactionStatusResponse,
|
|
13
13
|
Invocation,
|
|
14
|
-
Signature,
|
|
15
14
|
TransactionReceipt,
|
|
16
15
|
} from '../types';
|
|
17
16
|
import { BigNumberish } from '../utils/number';
|
|
@@ -156,22 +155,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
156
155
|
* @returns response from addTransaction
|
|
157
156
|
*/
|
|
158
157
|
invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
|
|
159
|
-
/**
|
|
160
|
-
* Invokes a function on starknet
|
|
161
|
-
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
162
|
-
*
|
|
163
|
-
* @param contractAddress - target contract address for invoke
|
|
164
|
-
* @param entrypointSelector - target entrypoint selector for
|
|
165
|
-
* @param calldata - (optional, default []) calldata
|
|
166
|
-
* @param signature - (optional) signature to send along
|
|
167
|
-
* @returns response from addTransaction
|
|
168
|
-
*/
|
|
169
|
-
LEGACY_invokeFunction(
|
|
170
|
-
contractAddress: string,
|
|
171
|
-
entrypointSelector: string,
|
|
172
|
-
calldata?: string[],
|
|
173
|
-
signature?: Signature
|
|
174
|
-
): Promise<AddTransactionResponse>;
|
|
175
158
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
176
159
|
/**
|
|
177
160
|
* @deprecated use `waitForTransaction` instead
|
package/provider/default.js
CHANGED
|
@@ -568,34 +568,6 @@ var Provider = /** @class */ (function () {
|
|
|
568
568
|
),
|
|
569
569
|
});
|
|
570
570
|
};
|
|
571
|
-
/**
|
|
572
|
-
* Invokes a function on starknet
|
|
573
|
-
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
574
|
-
*
|
|
575
|
-
* @param contractAddress - target contract address for invoke
|
|
576
|
-
* @param entrypointSelector - target entrypoint selector for
|
|
577
|
-
* @param calldata - (optional, default []) calldata
|
|
578
|
-
* @param signature - (optional) signature to send along
|
|
579
|
-
* @returns response from addTransaction
|
|
580
|
-
*/
|
|
581
|
-
Provider.prototype.LEGACY_invokeFunction = function (
|
|
582
|
-
contractAddress,
|
|
583
|
-
entrypointSelector,
|
|
584
|
-
calldata,
|
|
585
|
-
signature
|
|
586
|
-
) {
|
|
587
|
-
return this.fetchEndpoint('add_transaction', undefined, {
|
|
588
|
-
type: 'INVOKE_FUNCTION',
|
|
589
|
-
contract_address: contractAddress,
|
|
590
|
-
entry_point_selector: entrypointSelector,
|
|
591
|
-
calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
592
|
-
calldata !== null && calldata !== void 0 ? calldata : []
|
|
593
|
-
),
|
|
594
|
-
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(
|
|
595
|
-
signature !== null && signature !== void 0 ? signature : []
|
|
596
|
-
),
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
571
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
600
572
|
if (retryInterval === void 0) {
|
|
601
573
|
retryInterval = 8000;
|
package/src/account/default.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert';
|
|
2
|
+
|
|
1
3
|
import { Provider } from '../provider';
|
|
2
4
|
import { Signer, SignerInterface } from '../signer';
|
|
3
5
|
import {
|
|
@@ -5,10 +7,18 @@ import {
|
|
|
5
7
|
AddTransactionResponse,
|
|
6
8
|
Call,
|
|
7
9
|
InvocationsDetails,
|
|
10
|
+
InvokeFunctionTransaction,
|
|
8
11
|
KeyPair,
|
|
9
12
|
Signature,
|
|
13
|
+
Transaction,
|
|
10
14
|
} from '../types';
|
|
11
|
-
import {
|
|
15
|
+
import { sign } from '../utils/ellipticCurve';
|
|
16
|
+
import {
|
|
17
|
+
computeHashOnElements,
|
|
18
|
+
getSelectorFromName,
|
|
19
|
+
transactionPrefix,
|
|
20
|
+
transactionVersion,
|
|
21
|
+
} from '../utils/hash';
|
|
12
22
|
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
|
|
13
23
|
import { compileCalldata } from '../utils/stark';
|
|
14
24
|
import { fromCallsToExecuteCalldata } from '../utils/transaction';
|
|
@@ -68,6 +78,104 @@ export class Account extends Provider implements AccountInterface {
|
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Temporary method to allow dapps on starknet.js v2 to work with Argent X v3
|
|
83
|
+
* @deprecated to remove ASAP
|
|
84
|
+
*/
|
|
85
|
+
public async LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
|
|
86
|
+
if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
|
|
87
|
+
|
|
88
|
+
assert(
|
|
89
|
+
!transaction.signature,
|
|
90
|
+
"Adding signatures to a signer transaction currently isn't supported"
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
let nonceBn;
|
|
94
|
+
if (transaction.nonce) {
|
|
95
|
+
nonceBn = toBN(transaction.nonce);
|
|
96
|
+
} else {
|
|
97
|
+
const { result } = await this.callContract({
|
|
98
|
+
contractAddress: this.address,
|
|
99
|
+
entrypoint: 'get_nonce',
|
|
100
|
+
});
|
|
101
|
+
nonceBn = toBN(result[0]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hashMulticall(
|
|
105
|
+
account: string,
|
|
106
|
+
transactions: InvokeFunctionTransaction[],
|
|
107
|
+
nonce: string,
|
|
108
|
+
maxFee: string
|
|
109
|
+
) {
|
|
110
|
+
const hashArray = transactions
|
|
111
|
+
.map(({ contract_address, entry_point_selector, calldata }) => [
|
|
112
|
+
contract_address,
|
|
113
|
+
entry_point_selector,
|
|
114
|
+
computeHashOnElements(calldata || []),
|
|
115
|
+
])
|
|
116
|
+
.map(bigNumberishArrayToDecimalStringArray)
|
|
117
|
+
.map(computeHashOnElements);
|
|
118
|
+
|
|
119
|
+
return computeHashOnElements([
|
|
120
|
+
transactionPrefix,
|
|
121
|
+
account,
|
|
122
|
+
computeHashOnElements(hashArray),
|
|
123
|
+
nonce,
|
|
124
|
+
maxFee,
|
|
125
|
+
transactionVersion,
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
const msgHash = hashMulticall(this.address, [transaction], nonceBn.toString(), '0');
|
|
129
|
+
if (!('keyPair' in this.signer)) {
|
|
130
|
+
throw new Error('No keyPair');
|
|
131
|
+
}
|
|
132
|
+
const signature = sign((this.signer as any).keyPair, msgHash);
|
|
133
|
+
|
|
134
|
+
const transformCallsToMulticallArrays = (calls: InvokeFunctionTransaction[]) => {
|
|
135
|
+
const callArray: any[] = [];
|
|
136
|
+
const calldata: BigNumberish[] = [];
|
|
137
|
+
calls.forEach((call) => {
|
|
138
|
+
const data = call.calldata || [];
|
|
139
|
+
callArray.push({
|
|
140
|
+
to: toBN(call.contract_address).toString(10),
|
|
141
|
+
selector: toBN(call.entry_point_selector).toString(10),
|
|
142
|
+
data_offset: calldata.length.toString(),
|
|
143
|
+
data_len: data.length.toString(),
|
|
144
|
+
});
|
|
145
|
+
calldata.push(...data);
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
callArray,
|
|
149
|
+
calldata: bigNumberishArrayToDecimalStringArray(calldata),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const fromCallsToExecuteCalldata2 = (calls: InvokeFunctionTransaction[]): string[] => {
|
|
154
|
+
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
155
|
+
return [
|
|
156
|
+
callArray.length.toString(),
|
|
157
|
+
...callArray
|
|
158
|
+
.map(
|
|
159
|
+
({ to, selector, data_offset, data_len }) =>
|
|
160
|
+
[to, selector, data_offset, data_len] as string[]
|
|
161
|
+
)
|
|
162
|
+
.flat(),
|
|
163
|
+
calldata.length.toString(),
|
|
164
|
+
...calldata,
|
|
165
|
+
];
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const calldata = [...fromCallsToExecuteCalldata2([transaction]), nonceBn.toString()];
|
|
169
|
+
|
|
170
|
+
return this.fetchEndpoint('add_transaction', undefined, {
|
|
171
|
+
type: 'INVOKE_FUNCTION',
|
|
172
|
+
contract_address: this.address,
|
|
173
|
+
entry_point_selector: getSelectorFromName('__execute__'),
|
|
174
|
+
calldata,
|
|
175
|
+
signature: bigNumberishArrayToDecimalStringArray(signature),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
71
179
|
/**
|
|
72
180
|
* Sign an JSON object with the starknet private key and return the signature
|
|
73
181
|
*
|
package/src/provider/default.ts
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
GetTransactionResponse,
|
|
16
16
|
GetTransactionStatusResponse,
|
|
17
17
|
Invocation,
|
|
18
|
-
Signature,
|
|
19
18
|
TransactionReceipt,
|
|
20
19
|
} from '../types';
|
|
21
20
|
import { getSelectorFromName } from '../utils/hash';
|
|
@@ -332,31 +331,6 @@ export class Provider implements ProviderInterface {
|
|
|
332
331
|
});
|
|
333
332
|
}
|
|
334
333
|
|
|
335
|
-
/**
|
|
336
|
-
* Invokes a function on starknet
|
|
337
|
-
* @deprecated This method wont be supported as soon as fees are mandatory
|
|
338
|
-
*
|
|
339
|
-
* @param contractAddress - target contract address for invoke
|
|
340
|
-
* @param entrypointSelector - target entrypoint selector for
|
|
341
|
-
* @param calldata - (optional, default []) calldata
|
|
342
|
-
* @param signature - (optional) signature to send along
|
|
343
|
-
* @returns response from addTransaction
|
|
344
|
-
*/
|
|
345
|
-
public LEGACY_invokeFunction(
|
|
346
|
-
contractAddress: string,
|
|
347
|
-
entrypointSelector: string,
|
|
348
|
-
calldata?: string[],
|
|
349
|
-
signature?: Signature
|
|
350
|
-
): Promise<AddTransactionResponse> {
|
|
351
|
-
return this.fetchEndpoint('add_transaction', undefined, {
|
|
352
|
-
type: 'INVOKE_FUNCTION',
|
|
353
|
-
contract_address: contractAddress,
|
|
354
|
-
entry_point_selector: entrypointSelector,
|
|
355
|
-
calldata: bigNumberishArrayToDecimalStringArray(calldata ?? []),
|
|
356
|
-
signature: bigNumberishArrayToDecimalStringArray(signature ?? []),
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
334
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
361
335
|
let onchain = false;
|
|
362
336
|
await wait(retryInterval);
|