starknet 3.8.0 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -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 +10 -6
- package/account/default.js +32 -39
- package/account/interface.d.ts +2 -0
- package/constants.d.ts +9 -0
- package/constants.js +13 -0
- package/contract/contractFactory.d.ts +5 -5
- package/contract/default.js +14 -2
- package/dist/account/default.d.ts +6 -6
- package/dist/account/default.js +32 -23
- package/dist/account/interface.d.ts +2 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -1
- package/dist/contract/contractFactory.d.ts +5 -5
- package/dist/contract/default.js +14 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/provider/default.d.ts +4 -1
- package/dist/provider/default.js +20 -1
- package/dist/provider/interface.d.ts +2 -0
- package/dist/signer/default.js +4 -2
- package/dist/signer/ledger.js +4 -2
- package/dist/types/api.d.ts +1 -0
- 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/index.d.ts +1 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/provider/default.d.ts +4 -1
- package/provider/default.js +21 -1
- package/provider/interface.d.ts +2 -0
- package/signer/default.js +12 -5
- package/signer/ledger.js +12 -5
- package/src/account/default.ts +38 -17
- package/src/account/interface.ts +3 -0
- package/src/constants.ts +10 -0
- package/src/contract/contractFactory.ts +5 -5
- package/src/contract/default.ts +13 -2
- package/src/index.ts +1 -0
- package/src/provider/default.ts +23 -2
- package/src/provider/interface.ts +3 -0
- package/src/signer/default.ts +10 -5
- package/src/signer/ledger.ts +10 -5
- package/src/types/api.ts +1 -0
- 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 +1 -0
- 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
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { StarknetChainId } from '../../src/constants';
|
|
1
2
|
import { ec, getKeyPair, getStarkKey, sign, verify } from '../../src/utils/ellipticCurve';
|
|
2
3
|
import { removeHexPrefix } from '../../src/utils/encode';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
calculcateTransactionHash,
|
|
6
|
+
computeHashOnElements,
|
|
7
|
+
getSelectorFromName,
|
|
8
|
+
pedersen,
|
|
9
|
+
transactionVersion,
|
|
10
|
+
} from '../../src/utils/hash';
|
|
4
11
|
import { toBN, toHex } from '../../src/utils/number';
|
|
12
|
+
import { fromCallsToExecuteCalldataWithNonce } from '../../src/utils/transaction';
|
|
5
13
|
|
|
6
14
|
test('getKeyPair()', () => {
|
|
7
15
|
const privateKey = '0x019800ea6a9a73f94aee6a3d2edf018fc770443e90c7ba121e8303ec6b349279';
|
|
@@ -42,17 +50,27 @@ test('hashMessage()', () => {
|
|
|
42
50
|
];
|
|
43
51
|
const nonce = '3';
|
|
44
52
|
const maxFee = '0';
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
|
|
54
|
+
|
|
55
|
+
const hashMsg = calculcateTransactionHash(
|
|
56
|
+
account,
|
|
57
|
+
transactionVersion,
|
|
58
|
+
getSelectorFromName('__execute__'),
|
|
59
|
+
calldata,
|
|
60
|
+
maxFee,
|
|
61
|
+
StarknetChainId.TESTNET
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(hashMsg).toMatchInlineSnapshot(
|
|
65
|
+
`"0x4c337c6bf32b2cf2b8ae54064e4b982c214660e8d0423b431a3fde10b9b9c02"`
|
|
48
66
|
);
|
|
49
67
|
const keyPair = getKeyPair(privateKey);
|
|
50
68
|
const [r, s] = sign(keyPair, removeHexPrefix(hashMsg));
|
|
51
|
-
expect(r.toString()).
|
|
52
|
-
|
|
69
|
+
expect(r.toString()).toMatchInlineSnapshot(
|
|
70
|
+
`"1944132633844378384908742523072599391732300777648030785844673145513474741467"`
|
|
53
71
|
);
|
|
54
|
-
expect(s.toString()).
|
|
55
|
-
|
|
72
|
+
expect(s.toString()).toMatchInlineSnapshot(
|
|
73
|
+
`"1067771353159635307522498807851959257107695451405842425488451092336556917559"`
|
|
56
74
|
);
|
|
57
75
|
});
|
|
58
76
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StarknetChainId, TransactionHashPrefix } from '../../src/constants';
|
|
2
|
+
import { calculateTransactionHashCommon } from '../../src/utils/hash';
|
|
3
|
+
|
|
4
|
+
describe('calculateTransactionHashCommon()', () => {
|
|
5
|
+
test('should match most simple python output', () => {
|
|
6
|
+
const result = calculateTransactionHashCommon(
|
|
7
|
+
TransactionHashPrefix.INVOKE,
|
|
8
|
+
'0x0',
|
|
9
|
+
'0x2a',
|
|
10
|
+
'0x64',
|
|
11
|
+
[],
|
|
12
|
+
'0x0',
|
|
13
|
+
StarknetChainId.TESTNET
|
|
14
|
+
);
|
|
15
|
+
expect(result).toBe('0x7d260744de9d8c55e7675a34512d1951a7b262c79e685d26599edd2948de959');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -77,3 +77,13 @@ describe('computeHashOnElements()', () => {
|
|
|
77
77
|
);
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
|
+
describe('estimatedFeeToMaxFee()', () => {
|
|
81
|
+
test('should return maxFee for 0', () => {
|
|
82
|
+
const res = stark.estimatedFeeToMaxFee(0, 0.15).toNumber();
|
|
83
|
+
expect(res).toBe(0);
|
|
84
|
+
});
|
|
85
|
+
test('should return maxFee for 10_000', () => {
|
|
86
|
+
const res = stark.estimatedFeeToMaxFee(10_000, 0.15).toNumber();
|
|
87
|
+
expect(res).toBe(11_500);
|
|
88
|
+
});
|
|
89
|
+
});
|
package/account/default.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider } from '../provider';
|
|
1
|
+
import { Provider, ProviderInterface } from '../provider';
|
|
2
2
|
import { BlockIdentifier } from '../provider/utils';
|
|
3
3
|
import { SignerInterface } from '../signer';
|
|
4
4
|
import {
|
|
@@ -16,8 +16,12 @@ import { TypedData } from '../utils/typedData';
|
|
|
16
16
|
import { AccountInterface } from './interface';
|
|
17
17
|
export declare class Account extends Provider implements AccountInterface {
|
|
18
18
|
address: string;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
19
|
+
signer: SignerInterface;
|
|
20
|
+
constructor(
|
|
21
|
+
provider: ProviderInterface,
|
|
22
|
+
address: string,
|
|
23
|
+
keyPairOrSigner: KeyPair | SignerInterface
|
|
24
|
+
);
|
|
21
25
|
getNonce(): Promise<string>;
|
|
22
26
|
estimateFee(
|
|
23
27
|
calls: Call | Call[],
|
|
@@ -64,7 +68,8 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
64
68
|
*/
|
|
65
69
|
hashMessage(typedData: TypedData): Promise<string>;
|
|
66
70
|
/**
|
|
67
|
-
* Verify a signature of a
|
|
71
|
+
* Verify a signature of a given hash
|
|
72
|
+
* @warning This method is not recommended, use verifyMessage instead
|
|
68
73
|
*
|
|
69
74
|
* @param hash - JSON object to be verified
|
|
70
75
|
* @param signature - signature of the JSON object
|
|
@@ -73,8 +78,7 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
73
78
|
*/
|
|
74
79
|
verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
75
80
|
/**
|
|
76
|
-
* Verify a signature of a
|
|
77
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
81
|
+
* Verify a signature of a JSON object
|
|
78
82
|
*
|
|
79
83
|
* @param hash - hash to be verified
|
|
80
84
|
* @param signature - signature of the hash
|
package/account/default.js
CHANGED
|
@@ -197,11 +197,13 @@ var __importDefault =
|
|
|
197
197
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
198
198
|
exports.Account = void 0;
|
|
199
199
|
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
200
|
+
var constants_1 = require('../constants');
|
|
200
201
|
var provider_1 = require('../provider');
|
|
201
202
|
var signer_1 = require('../signer');
|
|
202
203
|
var ellipticCurve_1 = require('../utils/ellipticCurve');
|
|
203
204
|
var hash_1 = require('../utils/hash');
|
|
204
205
|
var number_1 = require('../utils/number');
|
|
206
|
+
var shortString_1 = require('../utils/shortString');
|
|
205
207
|
var stark_1 = require('../utils/stark');
|
|
206
208
|
var transaction_1 = require('../utils/transaction');
|
|
207
209
|
var typedData_1 = require('../utils/typedData');
|
|
@@ -240,7 +242,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
240
242
|
_c = _b.blockIdentifier,
|
|
241
243
|
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
242
244
|
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
-
var transactions, nonce, _d, signerDetails, signature, calldata;
|
|
245
|
+
var transactions, nonce, _d, version, signerDetails, signature, calldata;
|
|
244
246
|
return __generator(this, function (_e) {
|
|
245
247
|
switch (_e.label) {
|
|
246
248
|
case 0:
|
|
@@ -255,23 +257,18 @@ var Account = /** @class */ (function (_super) {
|
|
|
255
257
|
_e.label = 3;
|
|
256
258
|
case 3:
|
|
257
259
|
nonce = _d;
|
|
260
|
+
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
258
261
|
signerDetails = {
|
|
259
262
|
walletAddress: this.address,
|
|
260
263
|
nonce: (0, number_1.toBN)(nonce),
|
|
261
|
-
maxFee:
|
|
264
|
+
maxFee: constants_1.ZERO,
|
|
265
|
+
version: version,
|
|
266
|
+
chainId: this.chainId,
|
|
262
267
|
};
|
|
263
268
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
264
269
|
case 4:
|
|
265
270
|
signature = _e.sent();
|
|
266
|
-
calldata =
|
|
267
|
-
__spreadArray(
|
|
268
|
-
[],
|
|
269
|
-
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
270
|
-
false
|
|
271
|
-
),
|
|
272
|
-
[signerDetails.nonce.toString()],
|
|
273
|
-
false
|
|
274
|
-
);
|
|
271
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
275
272
|
return [
|
|
276
273
|
2 /*return*/,
|
|
277
274
|
this.fetchEndpoint(
|
|
@@ -281,6 +278,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
281
278
|
contract_address: this.address,
|
|
282
279
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
283
280
|
calldata: calldata,
|
|
281
|
+
version: (0, number_1.toHex)(version),
|
|
284
282
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
285
283
|
}
|
|
286
284
|
),
|
|
@@ -298,7 +296,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
298
296
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
299
297
|
*/
|
|
300
298
|
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
301
|
-
var _a
|
|
299
|
+
var _a;
|
|
302
300
|
if (abis === void 0) {
|
|
303
301
|
abis = undefined;
|
|
304
302
|
}
|
|
@@ -306,51 +304,46 @@ var Account = /** @class */ (function (_super) {
|
|
|
306
304
|
transactionsDetail = {};
|
|
307
305
|
}
|
|
308
306
|
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
-
var transactions, nonce,
|
|
310
|
-
return __generator(this, function (
|
|
311
|
-
switch (
|
|
307
|
+
var transactions, nonce, _b, _c, maxFee, estimatedFee, signerDetails, signature, calldata;
|
|
308
|
+
return __generator(this, function (_d) {
|
|
309
|
+
switch (_d.label) {
|
|
312
310
|
case 0:
|
|
313
311
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
314
|
-
|
|
312
|
+
_b = number_1.toBN;
|
|
315
313
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0))
|
|
316
314
|
return [3 /*break*/, 1];
|
|
317
|
-
|
|
315
|
+
_c = _a;
|
|
318
316
|
return [3 /*break*/, 3];
|
|
319
317
|
case 1:
|
|
320
318
|
return [4 /*yield*/, this.getNonce()];
|
|
321
319
|
case 2:
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
_c = _d.sent();
|
|
321
|
+
_d.label = 3;
|
|
324
322
|
case 3:
|
|
325
|
-
nonce =
|
|
326
|
-
|
|
323
|
+
nonce = _b.apply(void 0, [_c]);
|
|
324
|
+
maxFee = '0';
|
|
325
|
+
if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0))
|
|
327
326
|
return [3 /*break*/, 4];
|
|
328
|
-
|
|
327
|
+
maxFee = transactionsDetail.maxFee;
|
|
329
328
|
return [3 /*break*/, 6];
|
|
330
329
|
case 4:
|
|
331
330
|
return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
332
331
|
case 5:
|
|
333
|
-
|
|
334
|
-
|
|
332
|
+
estimatedFee = _d.sent().amount;
|
|
333
|
+
maxFee = (0, stark_1.estimatedFeeToMaxFee)(estimatedFee).toString();
|
|
334
|
+
_d.label = 6;
|
|
335
335
|
case 6:
|
|
336
|
-
maxFee = _e;
|
|
337
336
|
signerDetails = {
|
|
338
337
|
walletAddress: this.address,
|
|
339
338
|
nonce: nonce,
|
|
340
339
|
maxFee: maxFee,
|
|
340
|
+
version: (0, number_1.toBN)(hash_1.transactionVersion),
|
|
341
|
+
chainId: this.chainId,
|
|
341
342
|
};
|
|
342
343
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
343
344
|
case 7:
|
|
344
|
-
signature =
|
|
345
|
-
calldata =
|
|
346
|
-
__spreadArray(
|
|
347
|
-
[],
|
|
348
|
-
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
349
|
-
false
|
|
350
|
-
),
|
|
351
|
-
[signerDetails.nonce.toString()],
|
|
352
|
-
false
|
|
353
|
-
);
|
|
345
|
+
signature = _d.sent();
|
|
346
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
354
347
|
return [
|
|
355
348
|
2 /*return*/,
|
|
356
349
|
this.fetchEndpoint('add_transaction', undefined, {
|
|
@@ -387,7 +380,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
387
380
|
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
388
381
|
.map(hash_1.computeHashOnElements);
|
|
389
382
|
return (0,
|
|
390
|
-
hash_1.computeHashOnElements)([
|
|
383
|
+
hash_1.computeHashOnElements)([(0, shortString_1.encodeShortString)('StarkNet Transaction'), account, (0, hash_1.computeHashOnElements)(hashArray), nonce, maxFee, hash_1.transactionVersion]);
|
|
391
384
|
}
|
|
392
385
|
var nonceBn,
|
|
393
386
|
result,
|
|
@@ -517,7 +510,8 @@ var Account = /** @class */ (function (_super) {
|
|
|
517
510
|
});
|
|
518
511
|
};
|
|
519
512
|
/**
|
|
520
|
-
* Verify a signature of a
|
|
513
|
+
* Verify a signature of a given hash
|
|
514
|
+
* @warning This method is not recommended, use verifyMessage instead
|
|
521
515
|
*
|
|
522
516
|
* @param hash - JSON object to be verified
|
|
523
517
|
* @param signature - signature of the JSON object
|
|
@@ -557,8 +551,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
557
551
|
});
|
|
558
552
|
};
|
|
559
553
|
/**
|
|
560
|
-
* Verify a signature of a
|
|
561
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
554
|
+
* Verify a signature of a JSON object
|
|
562
555
|
*
|
|
563
556
|
* @param hash - hash to be verified
|
|
564
557
|
* @param signature - signature of the hash
|
package/account/interface.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
+
import { SignerInterface } from '../signer';
|
|
2
3
|
import {
|
|
3
4
|
Abi,
|
|
4
5
|
AddTransactionResponse,
|
|
@@ -13,6 +14,7 @@ import { BigNumberish } from '../utils/number';
|
|
|
13
14
|
import { TypedData } from '../utils/typedData/types';
|
|
14
15
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
15
16
|
abstract address: string;
|
|
17
|
+
abstract signer: SignerInterface;
|
|
16
18
|
/**
|
|
17
19
|
* Deploys a given compiled contract (json) to starknet
|
|
18
20
|
*
|
package/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/constants.js
CHANGED
|
@@ -8,6 +8,8 @@ exports.CONSTANT_POINTS =
|
|
|
8
8
|
exports.FIELD_SIZE =
|
|
9
9
|
exports.FIELD_GEN =
|
|
10
10
|
exports.FIELD_PRIME =
|
|
11
|
+
exports.TransactionHashPrefix =
|
|
12
|
+
exports.StarknetChainId =
|
|
11
13
|
exports.MASK_251 =
|
|
12
14
|
exports.MASK_250 =
|
|
13
15
|
exports.TWO =
|
|
@@ -28,6 +30,17 @@ exports.ONE = (0, number_1.toBN)(1);
|
|
|
28
30
|
exports.TWO = (0, number_1.toBN)(2);
|
|
29
31
|
exports.MASK_250 = exports.TWO.pow((0, number_1.toBN)(250)).sub(exports.ONE); // 2 ** 250 - 1
|
|
30
32
|
exports.MASK_251 = exports.TWO.pow((0, number_1.toBN)(251));
|
|
33
|
+
var StarknetChainId;
|
|
34
|
+
(function (StarknetChainId) {
|
|
35
|
+
StarknetChainId['MAINNET'] = '0x534e5f4d41494e';
|
|
36
|
+
StarknetChainId['TESTNET'] = '0x534e5f474f45524c49';
|
|
37
|
+
})((StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {})));
|
|
38
|
+
var TransactionHashPrefix;
|
|
39
|
+
(function (TransactionHashPrefix) {
|
|
40
|
+
TransactionHashPrefix['DEPLOY'] = '0x6465706c6f79';
|
|
41
|
+
TransactionHashPrefix['INVOKE'] = '0x696e766f6b65';
|
|
42
|
+
TransactionHashPrefix['L1_HANDLER'] = '0x6c315f68616e646c6572';
|
|
43
|
+
})((TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {})));
|
|
31
44
|
/**
|
|
32
45
|
* 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
|
|
33
46
|
* Please do not edit until the JSON changes.
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AccountInterface } from '../account';
|
|
2
|
+
import { ProviderInterface } from '../provider';
|
|
3
3
|
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
4
4
|
import { BigNumberish } from '../utils/number';
|
|
5
5
|
import { Contract } from './default';
|
|
6
6
|
export declare class ContractFactory {
|
|
7
7
|
abi: Abi;
|
|
8
8
|
compiledContract: CompiledContract;
|
|
9
|
-
providerOrAccount:
|
|
9
|
+
providerOrAccount: ProviderInterface | AccountInterface;
|
|
10
10
|
constructor(
|
|
11
11
|
compiledContract: CompiledContract,
|
|
12
|
-
providerOrAccount?:
|
|
12
|
+
providerOrAccount?: ProviderInterface | AccountInterface,
|
|
13
13
|
abi?: Abi
|
|
14
14
|
);
|
|
15
15
|
/**
|
|
@@ -25,7 +25,7 @@ export declare class ContractFactory {
|
|
|
25
25
|
*
|
|
26
26
|
* @param providerOrAccount - new Provider or Account to attach to
|
|
27
27
|
*/
|
|
28
|
-
connect(providerOrAccount:
|
|
28
|
+
connect(providerOrAccount: ProviderInterface | AccountInterface): ContractFactory;
|
|
29
29
|
/**
|
|
30
30
|
* Attaches current abi and provider or account to the new address
|
|
31
31
|
*
|
package/contract/default.js
CHANGED
|
@@ -224,8 +224,20 @@ function buildInvoke(contract, functionAbi) {
|
|
|
224
224
|
args[_i] = arguments[_i];
|
|
225
225
|
}
|
|
226
226
|
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
var inputs, inputsLength, options;
|
|
227
228
|
return __generator(this, function (_a) {
|
|
228
|
-
|
|
229
|
+
inputs = functionAbi.inputs;
|
|
230
|
+
inputsLength = inputs.reduce(function (acc, input) {
|
|
231
|
+
if (!/_len$/.test(input.name)) {
|
|
232
|
+
return acc + 1;
|
|
233
|
+
}
|
|
234
|
+
return acc;
|
|
235
|
+
}, 0);
|
|
236
|
+
options = {};
|
|
237
|
+
if (inputsLength + 1 === args.length && typeof args[args.length - 1] === 'object') {
|
|
238
|
+
Object.assign(options, args.pop());
|
|
239
|
+
}
|
|
240
|
+
return [2 /*return*/, contract.invoke(functionAbi.name, args, options)];
|
|
229
241
|
});
|
|
230
242
|
});
|
|
231
243
|
};
|
|
@@ -510,7 +522,7 @@ var Contract = /** @class */ (function () {
|
|
|
510
522
|
if (member.type === 'felt') {
|
|
511
523
|
return acc + 1;
|
|
512
524
|
}
|
|
513
|
-
return acc + _this.
|
|
525
|
+
return acc + _this.calculateStructMembers(member.type);
|
|
514
526
|
}, 0);
|
|
515
527
|
};
|
|
516
528
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider } from '../provider';
|
|
1
|
+
import { Provider, ProviderInterface } from '../provider';
|
|
2
2
|
import { BlockIdentifier } from '../provider/utils';
|
|
3
3
|
import { SignerInterface } from '../signer';
|
|
4
4
|
import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
@@ -7,8 +7,8 @@ import { TypedData } from '../utils/typedData';
|
|
|
7
7
|
import { AccountInterface } from './interface';
|
|
8
8
|
export declare class Account extends Provider implements AccountInterface {
|
|
9
9
|
address: string;
|
|
10
|
-
|
|
11
|
-
constructor(provider:
|
|
10
|
+
signer: SignerInterface;
|
|
11
|
+
constructor(provider: ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
12
12
|
getNonce(): Promise<string>;
|
|
13
13
|
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier, }?: {
|
|
14
14
|
nonce?: BigNumberish;
|
|
@@ -45,7 +45,8 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
45
45
|
*/
|
|
46
46
|
hashMessage(typedData: TypedData): Promise<string>;
|
|
47
47
|
/**
|
|
48
|
-
* Verify a signature of a
|
|
48
|
+
* Verify a signature of a given hash
|
|
49
|
+
* @warning This method is not recommended, use verifyMessage instead
|
|
49
50
|
*
|
|
50
51
|
* @param hash - JSON object to be verified
|
|
51
52
|
* @param signature - signature of the JSON object
|
|
@@ -54,8 +55,7 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
54
55
|
*/
|
|
55
56
|
verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
56
57
|
/**
|
|
57
|
-
* Verify a signature of a
|
|
58
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
58
|
+
* Verify a signature of a JSON object
|
|
59
59
|
*
|
|
60
60
|
* @param hash - hash to be verified
|
|
61
61
|
* @param signature - signature of the hash
|
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");
|
|
@@ -117,7 +119,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
117
119
|
Account.prototype.estimateFee = function (calls, _a) {
|
|
118
120
|
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
119
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
-
var transactions, nonce, _d, signerDetails, signature, calldata;
|
|
122
|
+
var transactions, nonce, _d, version, signerDetails, signature, calldata;
|
|
121
123
|
return __generator(this, function (_e) {
|
|
122
124
|
switch (_e.label) {
|
|
123
125
|
case 0:
|
|
@@ -131,19 +133,23 @@ var Account = /** @class */ (function (_super) {
|
|
|
131
133
|
_e.label = 3;
|
|
132
134
|
case 3:
|
|
133
135
|
nonce = _d;
|
|
136
|
+
version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
|
|
134
137
|
signerDetails = {
|
|
135
138
|
walletAddress: this.address,
|
|
136
139
|
nonce: (0, number_1.toBN)(nonce),
|
|
137
|
-
maxFee:
|
|
140
|
+
maxFee: constants_1.ZERO,
|
|
141
|
+
version: version,
|
|
142
|
+
chainId: this.chainId,
|
|
138
143
|
};
|
|
139
144
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
140
145
|
case 4:
|
|
141
146
|
signature = _e.sent();
|
|
142
|
-
calldata =
|
|
147
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
143
148
|
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
144
149
|
contract_address: this.address,
|
|
145
150
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
146
151
|
calldata: calldata,
|
|
152
|
+
version: (0, number_1.toHex)(version),
|
|
147
153
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
148
154
|
})];
|
|
149
155
|
}
|
|
@@ -159,43 +165,46 @@ var Account = /** @class */ (function (_super) {
|
|
|
159
165
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
160
166
|
*/
|
|
161
167
|
Account.prototype.execute = function (calls, abis, transactionsDetail) {
|
|
162
|
-
var _a
|
|
168
|
+
var _a;
|
|
163
169
|
if (abis === void 0) { abis = undefined; }
|
|
164
170
|
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
165
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
-
var transactions, nonce,
|
|
167
|
-
return __generator(this, function (
|
|
168
|
-
switch (
|
|
172
|
+
var transactions, nonce, _b, _c, maxFee, estimatedFee, signerDetails, signature, calldata;
|
|
173
|
+
return __generator(this, function (_d) {
|
|
174
|
+
switch (_d.label) {
|
|
169
175
|
case 0:
|
|
170
176
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
171
|
-
|
|
177
|
+
_b = number_1.toBN;
|
|
172
178
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
173
|
-
|
|
179
|
+
_c = _a;
|
|
174
180
|
return [3 /*break*/, 3];
|
|
175
181
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
176
182
|
case 2:
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
_c = (_d.sent());
|
|
184
|
+
_d.label = 3;
|
|
179
185
|
case 3:
|
|
180
|
-
nonce =
|
|
181
|
-
|
|
182
|
-
|
|
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;
|
|
183
190
|
return [3 /*break*/, 6];
|
|
184
191
|
case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
185
192
|
case 5:
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
estimatedFee = (_d.sent()).amount;
|
|
194
|
+
maxFee = (0, stark_1.estimatedFeeToMaxFee)(estimatedFee).toString();
|
|
195
|
+
_d.label = 6;
|
|
188
196
|
case 6:
|
|
189
|
-
maxFee = _e;
|
|
190
197
|
signerDetails = {
|
|
191
198
|
walletAddress: this.address,
|
|
192
199
|
nonce: nonce,
|
|
193
200
|
maxFee: maxFee,
|
|
201
|
+
version: (0, number_1.toBN)(hash_1.transactionVersion),
|
|
202
|
+
chainId: this.chainId,
|
|
194
203
|
};
|
|
195
204
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
196
205
|
case 7:
|
|
197
|
-
signature =
|
|
198
|
-
calldata =
|
|
206
|
+
signature = _d.sent();
|
|
207
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
199
208
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
200
209
|
type: 'INVOKE_FUNCTION',
|
|
201
210
|
contract_address: this.address,
|
|
@@ -227,7 +236,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
227
236
|
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
228
237
|
.map(hash_1.computeHashOnElements);
|
|
229
238
|
return (0, hash_1.computeHashOnElements)([
|
|
230
|
-
|
|
239
|
+
(0, shortString_1.encodeShortString)('StarkNet Transaction'),
|
|
231
240
|
account,
|
|
232
241
|
(0, hash_1.computeHashOnElements)(hashArray),
|
|
233
242
|
nonce,
|
|
@@ -331,7 +340,8 @@ var Account = /** @class */ (function (_super) {
|
|
|
331
340
|
});
|
|
332
341
|
};
|
|
333
342
|
/**
|
|
334
|
-
* Verify a signature of a
|
|
343
|
+
* Verify a signature of a given hash
|
|
344
|
+
* @warning This method is not recommended, use verifyMessage instead
|
|
335
345
|
*
|
|
336
346
|
* @param hash - JSON object to be verified
|
|
337
347
|
* @param signature - signature of the JSON object
|
|
@@ -365,8 +375,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
365
375
|
});
|
|
366
376
|
};
|
|
367
377
|
/**
|
|
368
|
-
* Verify a signature of a
|
|
369
|
-
* @warning This method is not recommended, use verifyMessage instead
|
|
378
|
+
* Verify a signature of a JSON object
|
|
370
379
|
*
|
|
371
380
|
* @param hash - hash to be verified
|
|
372
381
|
* @param signature - signature of the hash
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
+
import { SignerInterface } from '../signer';
|
|
2
3
|
import { Abi, AddTransactionResponse, Call, DeployContractPayload, EstimateFeeResponse, Invocation, InvocationsDetails, Signature } from '../types';
|
|
3
4
|
import { BigNumberish } from '../utils/number';
|
|
4
5
|
import { TypedData } from '../utils/typedData/types';
|
|
5
6
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
6
7
|
abstract address: string;
|
|
8
|
+
abstract signer: SignerInterface;
|
|
7
9
|
/**
|
|
8
10
|
* Deploys a given compiled contract (json) to starknet
|
|
9
11
|
*
|
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.
|