starknet 3.9.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- 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/account/default.js +10 -21
- package/constants.d.ts +9 -0
- package/constants.js +13 -0
- package/dist/account/default.js +9 -5
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +12 -1
- package/dist/provider/default.d.ts +3 -0
- package/dist/provider/default.js +18 -0
- 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/signer.d.ts +2 -0
- package/dist/utils/hash.d.ts +4 -3
- package/dist/utils/hash.js +24 -24
- package/dist/utils/transaction.d.ts +2 -0
- package/dist/utils/transaction.js +5 -1
- package/dist/utils/typedData/index.d.ts +2 -2
- package/dist/utils/typedData/types.d.ts +3 -3
- package/dist/utils/typedData/utils.d.ts +1 -1
- package/package.json +1 -1
- package/provider/default.d.ts +3 -0
- package/provider/default.js +19 -0
- package/provider/interface.d.ts +2 -0
- package/signer/default.js +12 -6
- package/signer/ledger.js +12 -5
- package/src/account/default.ts +16 -9
- package/src/constants.ts +10 -0
- package/src/provider/default.ts +19 -0
- package/src/provider/interface.ts +3 -0
- package/src/signer/default.ts +10 -6
- package/src/signer/ledger.ts +10 -5
- package/src/types/signer.ts +2 -0
- package/src/utils/hash.ts +68 -26
- package/src/utils/transaction.ts +7 -0
- package/types/signer.d.ts +2 -0
- package/utils/hash.d.ts +24 -8
- package/utils/hash.js +55 -28
- 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
|
+
});
|
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');
|
|
@@ -259,21 +261,14 @@ var Account = /** @class */ (function (_super) {
|
|
|
259
261
|
signerDetails = {
|
|
260
262
|
walletAddress: this.address,
|
|
261
263
|
nonce: (0, number_1.toBN)(nonce),
|
|
262
|
-
maxFee:
|
|
264
|
+
maxFee: constants_1.ZERO,
|
|
263
265
|
version: version,
|
|
266
|
+
chainId: this.chainId,
|
|
264
267
|
};
|
|
265
268
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
266
269
|
case 4:
|
|
267
270
|
signature = _e.sent();
|
|
268
|
-
calldata =
|
|
269
|
-
__spreadArray(
|
|
270
|
-
[],
|
|
271
|
-
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
272
|
-
false
|
|
273
|
-
),
|
|
274
|
-
[signerDetails.nonce.toString()],
|
|
275
|
-
false
|
|
276
|
-
);
|
|
271
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
277
272
|
return [
|
|
278
273
|
2 /*return*/,
|
|
279
274
|
this.fetchEndpoint(
|
|
@@ -327,7 +322,8 @@ var Account = /** @class */ (function (_super) {
|
|
|
327
322
|
case 3:
|
|
328
323
|
nonce = _b.apply(void 0, [_c]);
|
|
329
324
|
maxFee = '0';
|
|
330
|
-
if (!transactionsDetail.maxFee
|
|
325
|
+
if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0))
|
|
326
|
+
return [3 /*break*/, 4];
|
|
331
327
|
maxFee = transactionsDetail.maxFee;
|
|
332
328
|
return [3 /*break*/, 6];
|
|
333
329
|
case 4:
|
|
@@ -342,19 +338,12 @@ var Account = /** @class */ (function (_super) {
|
|
|
342
338
|
nonce: nonce,
|
|
343
339
|
maxFee: maxFee,
|
|
344
340
|
version: (0, number_1.toBN)(hash_1.transactionVersion),
|
|
341
|
+
chainId: this.chainId,
|
|
345
342
|
};
|
|
346
343
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
347
344
|
case 7:
|
|
348
345
|
signature = _d.sent();
|
|
349
|
-
calldata =
|
|
350
|
-
__spreadArray(
|
|
351
|
-
[],
|
|
352
|
-
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
353
|
-
false
|
|
354
|
-
),
|
|
355
|
-
[signerDetails.nonce.toString()],
|
|
356
|
-
false
|
|
357
|
-
);
|
|
346
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
358
347
|
return [
|
|
359
348
|
2 /*return*/,
|
|
360
349
|
this.fetchEndpoint('add_transaction', undefined, {
|
|
@@ -391,7 +380,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
391
380
|
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
392
381
|
.map(hash_1.computeHashOnElements);
|
|
393
382
|
return (0,
|
|
394
|
-
hash_1.computeHashOnElements)([
|
|
383
|
+
hash_1.computeHashOnElements)([(0, shortString_1.encodeShortString)('StarkNet Transaction'), account, (0, hash_1.computeHashOnElements)(hashArray), nonce, maxFee, hash_1.transactionVersion]);
|
|
395
384
|
}
|
|
396
385
|
var nonceBn,
|
|
397
386
|
result,
|
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.
|
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");
|
|
@@ -135,13 +137,14 @@ var Account = /** @class */ (function (_super) {
|
|
|
135
137
|
signerDetails = {
|
|
136
138
|
walletAddress: this.address,
|
|
137
139
|
nonce: (0, number_1.toBN)(nonce),
|
|
138
|
-
maxFee:
|
|
140
|
+
maxFee: constants_1.ZERO,
|
|
139
141
|
version: version,
|
|
142
|
+
chainId: this.chainId,
|
|
140
143
|
};
|
|
141
144
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
142
145
|
case 4:
|
|
143
146
|
signature = _e.sent();
|
|
144
|
-
calldata =
|
|
147
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
145
148
|
return [2 /*return*/, this.fetchEndpoint('estimate_fee', { blockIdentifier: blockIdentifier }, {
|
|
146
149
|
contract_address: this.address,
|
|
147
150
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
@@ -182,7 +185,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
182
185
|
case 3:
|
|
183
186
|
nonce = _b.apply(void 0, [_c]);
|
|
184
187
|
maxFee = '0';
|
|
185
|
-
if (!transactionsDetail.maxFee) return [3 /*break*/, 4];
|
|
188
|
+
if (!(transactionsDetail.maxFee || transactionsDetail.maxFee === 0)) return [3 /*break*/, 4];
|
|
186
189
|
maxFee = transactionsDetail.maxFee;
|
|
187
190
|
return [3 /*break*/, 6];
|
|
188
191
|
case 4: return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
@@ -196,11 +199,12 @@ var Account = /** @class */ (function (_super) {
|
|
|
196
199
|
nonce: nonce,
|
|
197
200
|
maxFee: maxFee,
|
|
198
201
|
version: (0, number_1.toBN)(hash_1.transactionVersion),
|
|
202
|
+
chainId: this.chainId,
|
|
199
203
|
};
|
|
200
204
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
201
205
|
case 7:
|
|
202
206
|
signature = _d.sent();
|
|
203
|
-
calldata =
|
|
207
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
|
|
204
208
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
205
209
|
type: 'INVOKE_FUNCTION',
|
|
206
210
|
contract_address: this.address,
|
|
@@ -232,7 +236,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
232
236
|
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
233
237
|
.map(hash_1.computeHashOnElements);
|
|
234
238
|
return (0, hash_1.computeHashOnElements)([
|
|
235
|
-
|
|
239
|
+
(0, shortString_1.encodeShortString)('StarkNet Transaction'),
|
|
236
240
|
account,
|
|
237
241
|
(0, hash_1.computeHashOnElements)(hashArray),
|
|
238
242
|
nonce,
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export declare const ONE: import("bn.js");
|
|
|
5
5
|
export declare const TWO: import("bn.js");
|
|
6
6
|
export declare const MASK_250: import("bn.js");
|
|
7
7
|
export declare const MASK_251: import("bn.js");
|
|
8
|
+
export declare enum StarknetChainId {
|
|
9
|
+
MAINNET = "0x534e5f4d41494e",
|
|
10
|
+
TESTNET = "0x534e5f474f45524c49"
|
|
11
|
+
}
|
|
12
|
+
export declare enum TransactionHashPrefix {
|
|
13
|
+
DEPLOY = "0x6465706c6f79",
|
|
14
|
+
INVOKE = "0x696e766f6b65",
|
|
15
|
+
L1_HANDLER = "0x6c315f68616e646c6572"
|
|
16
|
+
}
|
|
8
17
|
/**
|
|
9
18
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
10
19
|
* Please do not edit until the JSON changes.
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
|
|
3
|
+
exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.TransactionHashPrefix = exports.StarknetChainId = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
|
|
4
4
|
var number_1 = require("./utils/number");
|
|
5
5
|
var encode_1 = require("./utils/encode");
|
|
6
6
|
Object.defineProperty(exports, "IS_BROWSER", { enumerable: true, get: function () { return encode_1.IS_BROWSER; } });
|
|
@@ -9,6 +9,17 @@ exports.ONE = (0, number_1.toBN)(1);
|
|
|
9
9
|
exports.TWO = (0, number_1.toBN)(2);
|
|
10
10
|
exports.MASK_250 = exports.TWO.pow((0, number_1.toBN)(250)).sub(exports.ONE); // 2 ** 250 - 1
|
|
11
11
|
exports.MASK_251 = exports.TWO.pow((0, number_1.toBN)(251));
|
|
12
|
+
var StarknetChainId;
|
|
13
|
+
(function (StarknetChainId) {
|
|
14
|
+
StarknetChainId["MAINNET"] = "0x534e5f4d41494e";
|
|
15
|
+
StarknetChainId["TESTNET"] = "0x534e5f474f45524c49";
|
|
16
|
+
})(StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {}));
|
|
17
|
+
var TransactionHashPrefix;
|
|
18
|
+
(function (TransactionHashPrefix) {
|
|
19
|
+
TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
|
|
20
|
+
TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
|
|
21
|
+
TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
|
|
22
|
+
})(TransactionHashPrefix = exports.TransactionHashPrefix || (exports.TransactionHashPrefix = {}));
|
|
12
23
|
/**
|
|
13
24
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
14
25
|
* Please do not edit until the JSON changes.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceipt } from '../types';
|
|
2
3
|
import { BigNumberish } from '../utils/number';
|
|
3
4
|
import { ProviderInterface } from './interface';
|
|
@@ -12,8 +13,10 @@ export declare class Provider implements ProviderInterface {
|
|
|
12
13
|
baseUrl: string;
|
|
13
14
|
feederGatewayUrl: string;
|
|
14
15
|
gatewayUrl: string;
|
|
16
|
+
chainId: StarknetChainId;
|
|
15
17
|
constructor(optionsOrProvider?: ProviderOptions | Provider);
|
|
16
18
|
protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
|
|
19
|
+
protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
|
|
17
20
|
private getFetchUrl;
|
|
18
21
|
private getFetchMethod;
|
|
19
22
|
private getQueryString;
|
package/dist/provider/default.js
CHANGED
|
@@ -69,6 +69,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
69
69
|
exports.Provider = void 0;
|
|
70
70
|
var axios_1 = __importDefault(require("axios"));
|
|
71
71
|
var url_join_1 = __importDefault(require("url-join"));
|
|
72
|
+
var constants_1 = require("../constants");
|
|
72
73
|
var hash_1 = require("../utils/hash");
|
|
73
74
|
var json_1 = require("../utils/json");
|
|
74
75
|
var number_1 = require("../utils/number");
|
|
@@ -89,16 +90,20 @@ function isEmptyQueryObject(obj) {
|
|
|
89
90
|
var Provider = /** @class */ (function () {
|
|
90
91
|
function Provider(optionsOrProvider) {
|
|
91
92
|
if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
|
|
93
|
+
var _a;
|
|
92
94
|
if (optionsOrProvider instanceof Provider) {
|
|
93
95
|
this.baseUrl = optionsOrProvider.baseUrl;
|
|
94
96
|
this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
|
|
95
97
|
this.gatewayUrl = optionsOrProvider.gatewayUrl;
|
|
98
|
+
this.chainId =
|
|
99
|
+
(_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : Provider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
|
|
96
100
|
}
|
|
97
101
|
else {
|
|
98
102
|
var baseUrl = 'baseUrl' in optionsOrProvider
|
|
99
103
|
? optionsOrProvider.baseUrl
|
|
100
104
|
: Provider.getNetworkFromName(optionsOrProvider.network);
|
|
101
105
|
this.baseUrl = baseUrl;
|
|
106
|
+
this.chainId = Provider.getChainIdFromBaseUrl(baseUrl);
|
|
102
107
|
this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
|
|
103
108
|
this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
|
|
104
109
|
}
|
|
@@ -112,6 +117,19 @@ var Provider = /** @class */ (function () {
|
|
|
112
117
|
return 'https://alpha4.starknet.io';
|
|
113
118
|
}
|
|
114
119
|
};
|
|
120
|
+
Provider.getChainIdFromBaseUrl = function (baseUrl) {
|
|
121
|
+
try {
|
|
122
|
+
var url = new URL(baseUrl);
|
|
123
|
+
if (url.host.includes('mainnet.starknet.io')) {
|
|
124
|
+
return constants_1.StarknetChainId.MAINNET;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (_a) {
|
|
128
|
+
// eslint-disable-next-line no-console
|
|
129
|
+
console.error("Could not parse baseUrl: " + baseUrl);
|
|
130
|
+
}
|
|
131
|
+
return constants_1.StarknetChainId.TESTNET;
|
|
132
|
+
};
|
|
115
133
|
Provider.prototype.getFetchUrl = function (endpoint) {
|
|
116
134
|
var gatewayUrlEndpoints = ['add_transaction'];
|
|
117
135
|
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import type { AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
|
|
2
3
|
import type { BigNumberish } from '../utils/number';
|
|
3
4
|
import { BlockIdentifier } from './utils';
|
|
@@ -5,6 +6,7 @@ export declare abstract class ProviderInterface {
|
|
|
5
6
|
abstract baseUrl: string;
|
|
6
7
|
abstract feederGatewayUrl: string;
|
|
7
8
|
abstract gatewayUrl: string;
|
|
9
|
+
abstract chainId: StarknetChainId;
|
|
8
10
|
/**
|
|
9
11
|
* Gets the smart contract address on the goerli testnet.
|
|
10
12
|
*
|
package/dist/signer/default.js
CHANGED
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.Signer = void 0;
|
|
40
40
|
var ellipticCurve_1 = require("../utils/ellipticCurve");
|
|
41
41
|
var hash_1 = require("../utils/hash");
|
|
42
|
+
var transaction_1 = require("../utils/transaction");
|
|
42
43
|
var typedData_1 = require("../utils/typedData");
|
|
43
44
|
var Signer = /** @class */ (function () {
|
|
44
45
|
function Signer(keyPair) {
|
|
@@ -53,12 +54,13 @@ var Signer = /** @class */ (function () {
|
|
|
53
54
|
};
|
|
54
55
|
Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var msgHash;
|
|
57
|
+
var calldata, msgHash;
|
|
57
58
|
return __generator(this, function (_a) {
|
|
58
59
|
if (abis && abis.length !== transactions.length) {
|
|
59
60
|
throw new Error('ABI must be provided for each transaction or no transaction');
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, transactionsDetail.nonce);
|
|
63
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(transactionsDetail.walletAddress, transactionsDetail.version, (0, hash_1.getSelectorFromName)('__execute__'), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
|
|
62
64
|
return [2 /*return*/, (0, ellipticCurve_1.sign)(this.keyPair, msgHash)];
|
|
63
65
|
});
|
|
64
66
|
});
|
package/dist/signer/ledger.js
CHANGED
|
@@ -44,6 +44,7 @@ var hw_app_eth_1 = __importDefault(require("@ledgerhq/hw-app-eth"));
|
|
|
44
44
|
var hw_transport_webhid_1 = __importDefault(require("@ledgerhq/hw-transport-webhid"));
|
|
45
45
|
var encode_1 = require("../utils/encode");
|
|
46
46
|
var hash_1 = require("../utils/hash");
|
|
47
|
+
var transaction_1 = require("../utils/transaction");
|
|
47
48
|
var typedData_1 = require("../utils/typedData");
|
|
48
49
|
function hexZeroPad(hash, length) {
|
|
49
50
|
var value = hash;
|
|
@@ -101,9 +102,10 @@ var LedgerBlindSigner = /** @class */ (function () {
|
|
|
101
102
|
};
|
|
102
103
|
LedgerBlindSigner.prototype.signTransaction = function (transactions, transactionsDetail) {
|
|
103
104
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var msgHash;
|
|
105
|
+
var calldata, msgHash;
|
|
105
106
|
return __generator(this, function (_a) {
|
|
106
|
-
|
|
107
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, transactionsDetail.nonce);
|
|
108
|
+
msgHash = (0, hash_1.calculcateTransactionHash)(transactionsDetail.walletAddress, transactionsDetail.version, (0, hash_1.getSelectorFromName)('__execute__'), calldata, transactionsDetail.maxFee, transactionsDetail.chainId);
|
|
107
109
|
return [2 /*return*/, this.sign(msgHash)];
|
|
108
110
|
});
|
|
109
111
|
});
|
package/dist/types/signer.d.ts
CHANGED
package/dist/utils/hash.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
|
-
import {
|
|
2
|
+
import { StarknetChainId, TransactionHashPrefix } from '../constants';
|
|
3
3
|
import { BigNumberish } from './number';
|
|
4
|
-
export declare const transactionPrefix: string;
|
|
5
4
|
export declare const transactionVersion = 0;
|
|
6
5
|
export declare const feeTransactionVersion: BN;
|
|
7
6
|
/**
|
|
@@ -22,4 +21,6 @@ export declare function starknetKeccak(value: string): BN;
|
|
|
22
21
|
export declare function getSelectorFromName(funcName: string): string;
|
|
23
22
|
export declare function pedersen(input: [BigNumberish, BigNumberish]): string;
|
|
24
23
|
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
25
|
-
export declare function
|
|
24
|
+
export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData?: BigNumberish[]): string;
|
|
25
|
+
export declare function calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string;
|
|
26
|
+
export declare function calculcateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId): string;
|
package/dist/utils/hash.js
CHANGED
|
@@ -28,15 +28,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.
|
|
31
|
+
exports.calculcateTransactionHash = exports.calculateDeployTransactionHash = exports.calculateTransactionHashCommon = exports.computeHashOnElements = exports.pedersen = exports.getSelectorFromName = exports.starknetKeccak = exports.feeTransactionVersion = exports.transactionVersion = void 0;
|
|
32
32
|
var keccak_1 = require("ethereum-cryptography/keccak");
|
|
33
33
|
var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
|
|
34
34
|
var constants_1 = require("../constants");
|
|
35
35
|
var ellipticCurve_1 = require("./ellipticCurve");
|
|
36
36
|
var encode_1 = require("./encode");
|
|
37
37
|
var number_1 = require("./number");
|
|
38
|
-
var shortString_1 = require("./shortString");
|
|
39
|
-
exports.transactionPrefix = (0, shortString_1.encodeShortString)('StarkNet Transaction');
|
|
40
38
|
exports.transactionVersion = 0;
|
|
41
39
|
exports.feeTransactionVersion = (0, number_1.toBN)(2).pow((0, number_1.toBN)(128)).add((0, number_1.toBN)(exports.transactionVersion));
|
|
42
40
|
function keccakHex(value) {
|
|
@@ -89,26 +87,28 @@ function computeHashOnElements(data) {
|
|
|
89
87
|
return __spreadArray(__spreadArray([], __read(data), false), [data.length], false).reduce(function (x, y) { return pedersen([x, y]); }, 0).toString();
|
|
90
88
|
}
|
|
91
89
|
exports.computeHashOnElements = computeHashOnElements;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
getSelectorFromName(entrypoint),
|
|
100
|
-
computeHashOnElements(calldata || []),
|
|
101
|
-
];
|
|
102
|
-
})
|
|
103
|
-
.map(number_1.bigNumberishArrayToDecimalStringArray)
|
|
104
|
-
.map(computeHashOnElements);
|
|
105
|
-
return computeHashOnElements([
|
|
106
|
-
exports.transactionPrefix,
|
|
107
|
-
account,
|
|
108
|
-
computeHashOnElements(hashArray),
|
|
109
|
-
nonce,
|
|
110
|
-
maxFee,
|
|
90
|
+
// following implementation is based on this python implementation:
|
|
91
|
+
// https://github.com/starkware-libs/cairo-lang/blob/b614d1867c64f3fb2cf4a4879348cfcf87c3a5a7/src/starkware/starknet/core/os/transaction_hash/transaction_hash.py
|
|
92
|
+
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData) {
|
|
93
|
+
if (additionalData === void 0) { additionalData = []; }
|
|
94
|
+
var calldataHash = computeHashOnElements(calldata);
|
|
95
|
+
var dataToHash = __spreadArray([
|
|
96
|
+
txHashPrefix,
|
|
111
97
|
version,
|
|
112
|
-
|
|
98
|
+
contractAddress,
|
|
99
|
+
entryPointSelector,
|
|
100
|
+
calldataHash,
|
|
101
|
+
maxFee,
|
|
102
|
+
chainId
|
|
103
|
+
], __read(additionalData), false);
|
|
104
|
+
return computeHashOnElements(dataToHash);
|
|
105
|
+
}
|
|
106
|
+
exports.calculateTransactionHashCommon = calculateTransactionHashCommon;
|
|
107
|
+
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
108
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.DEPLOY, version, contractAddress, getSelectorFromName('constructor'), constructorCalldata, constants_1.ZERO, chainId);
|
|
109
|
+
}
|
|
110
|
+
exports.calculateDeployTransactionHash = calculateDeployTransactionHash;
|
|
111
|
+
function calculcateTransactionHash(contractAddress, version, entryPointSelector, calldata, maxFee, chainId) {
|
|
112
|
+
return calculateTransactionHashCommon(constants_1.TransactionHashPrefix.INVOKE, version, contractAddress, entryPointSelector, calldata, maxFee, chainId);
|
|
113
113
|
}
|
|
114
|
-
exports.
|
|
114
|
+
exports.calculcateTransactionHash = calculcateTransactionHash;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Call, ParsedStruct } from '../types';
|
|
2
|
+
import { BigNumberish } from './number';
|
|
2
3
|
/**
|
|
3
4
|
* Transforms a list of Calls, each with their own calldata, into
|
|
4
5
|
* two arrays: one with the entrypoints, and one with the concatenated calldata.
|
|
@@ -16,3 +17,4 @@ export declare const transformCallsToMulticallArrays: (calls: Call[]) => {
|
|
|
16
17
|
* @returns
|
|
17
18
|
*/
|
|
18
19
|
export declare const fromCallsToExecuteCalldata: (calls: Call[]) => string[];
|
|
20
|
+
export declare const fromCallsToExecuteCalldataWithNonce: (calls: Call[], nonce: BigNumberish) => string[];
|
|
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.fromCallsToExecuteCalldata = exports.transformCallsToMulticallArrays = void 0;
|
|
28
|
+
exports.fromCallsToExecuteCalldataWithNonce = exports.fromCallsToExecuteCalldata = exports.transformCallsToMulticallArrays = void 0;
|
|
29
29
|
var hash_1 = require("./hash");
|
|
30
30
|
var number_1 = require("./number");
|
|
31
31
|
/**
|
|
@@ -73,3 +73,7 @@ var fromCallsToExecuteCalldata = function (calls) {
|
|
|
73
73
|
], false), __read(calldata), false);
|
|
74
74
|
};
|
|
75
75
|
exports.fromCallsToExecuteCalldata = fromCallsToExecuteCalldata;
|
|
76
|
+
var fromCallsToExecuteCalldataWithNonce = function (calls, nonce) {
|
|
77
|
+
return __spreadArray(__spreadArray([], __read((0, exports.fromCallsToExecuteCalldata)(calls)), false), [(0, number_1.toBN)(nonce).toString()], false);
|
|
78
|
+
};
|
|
79
|
+
exports.fromCallsToExecuteCalldataWithNonce = fromCallsToExecuteCalldataWithNonce;
|
|
@@ -48,8 +48,8 @@ export declare const encodeData: <T extends {
|
|
|
48
48
|
primaryType: string;
|
|
49
49
|
domain: {
|
|
50
50
|
version?: string | undefined;
|
|
51
|
-
name?: string | undefined;
|
|
52
51
|
chainId?: string | number | undefined;
|
|
52
|
+
name?: string | undefined;
|
|
53
53
|
};
|
|
54
54
|
message: Record<string, unknown>;
|
|
55
55
|
}>(typedData: T, type: string, data: T["message"]) => string[][];
|
|
@@ -75,8 +75,8 @@ export declare const getStructHash: <T extends {
|
|
|
75
75
|
primaryType: string;
|
|
76
76
|
domain: {
|
|
77
77
|
version?: string | undefined;
|
|
78
|
-
name?: string | undefined;
|
|
79
78
|
chainId?: string | number | undefined;
|
|
79
|
+
name?: string | undefined;
|
|
80
80
|
};
|
|
81
81
|
message: Record<string, unknown>;
|
|
82
82
|
}>(typedData: T, type: string, data: T["message"]) => string;
|
|
@@ -26,8 +26,8 @@ export declare const STARKNET_TYPE: import("superstruct").Struct<{
|
|
|
26
26
|
export declare type StarkNetType = Infer<typeof STARKNET_TYPE>;
|
|
27
27
|
export declare const STARKNET_DOMAIN_TYPE: import("superstruct").Struct<{
|
|
28
28
|
version?: string | undefined;
|
|
29
|
-
name?: string | undefined;
|
|
30
29
|
chainId?: string | number | undefined;
|
|
30
|
+
name?: string | undefined;
|
|
31
31
|
}, {
|
|
32
32
|
name: import("superstruct").Struct<string | undefined, null>;
|
|
33
33
|
version: import("superstruct").Struct<string | undefined, null>;
|
|
@@ -50,8 +50,8 @@ export declare const STARKNET_TYPED_DATA_TYPE: import("superstruct").Struct<{
|
|
|
50
50
|
primaryType: string;
|
|
51
51
|
domain: {
|
|
52
52
|
version?: string | undefined;
|
|
53
|
-
name?: string | undefined;
|
|
54
53
|
chainId?: string | number | undefined;
|
|
54
|
+
name?: string | undefined;
|
|
55
55
|
};
|
|
56
56
|
message: Record<string, unknown>;
|
|
57
57
|
}, {
|
|
@@ -67,8 +67,8 @@ export declare const STARKNET_TYPED_DATA_TYPE: import("superstruct").Struct<{
|
|
|
67
67
|
primaryType: import("superstruct").Struct<string, null>;
|
|
68
68
|
domain: import("superstruct").Struct<{
|
|
69
69
|
version?: string | undefined;
|
|
70
|
-
name?: string | undefined;
|
|
71
70
|
chainId?: string | number | undefined;
|
|
71
|
+
name?: string | undefined;
|
|
72
72
|
}, {
|
|
73
73
|
name: import("superstruct").Struct<string | undefined, null>;
|
|
74
74
|
version: import("superstruct").Struct<string | undefined, null>;
|
|
@@ -17,8 +17,8 @@ export declare const validateTypedData: (data: unknown) => data is {
|
|
|
17
17
|
primaryType: string;
|
|
18
18
|
domain: {
|
|
19
19
|
version?: string | undefined;
|
|
20
|
-
name?: string | undefined;
|
|
21
20
|
chainId?: string | number | undefined;
|
|
21
|
+
name?: string | undefined;
|
|
22
22
|
};
|
|
23
23
|
message: Record<string, unknown>;
|
|
24
24
|
};
|
package/package.json
CHANGED
package/provider/default.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StarknetChainId } from '../constants';
|
|
1
2
|
import {
|
|
2
3
|
Abi,
|
|
3
4
|
AddTransactionResponse,
|
|
@@ -29,10 +30,12 @@ export declare class Provider implements ProviderInterface {
|
|
|
29
30
|
baseUrl: string;
|
|
30
31
|
feederGatewayUrl: string;
|
|
31
32
|
gatewayUrl: string;
|
|
33
|
+
chainId: StarknetChainId;
|
|
32
34
|
constructor(optionsOrProvider?: ProviderOptions | Provider);
|
|
33
35
|
protected static getNetworkFromName(
|
|
34
36
|
name: NetworkName
|
|
35
37
|
): 'https://alpha-mainnet.starknet.io' | 'https://alpha4.starknet.io';
|
|
38
|
+
protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
|
|
36
39
|
private getFetchUrl;
|
|
37
40
|
private getFetchMethod;
|
|
38
41
|
private getQueryString;
|