starknet 4.6.0 → 4.7.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 +25 -0
- package/__tests__/account.test.ts +2 -5
- package/__tests__/contract.test.ts +0 -1
- package/__tests__/defaultProvider.test.ts +9 -1
- package/__tests__/sequencerProvider.test.ts +10 -8
- package/__tests__/utils/ellipticalCurve.test.ts +7 -8
- package/account/default.d.ts +3 -2
- package/account/default.js +22 -29
- package/account/interface.d.ts +2 -1
- package/contract/contractFactory.d.ts +1 -2
- package/contract/default.d.ts +2 -2
- package/contract/default.js +7 -3
- package/dist/account/default.d.ts +3 -2
- package/dist/account/default.js +22 -29
- package/dist/account/interface.d.ts +2 -1
- package/dist/contract/contractFactory.d.ts +1 -2
- package/dist/contract/default.d.ts +2 -2
- package/dist/contract/default.js +7 -3
- package/dist/provider/default.d.ts +4 -3
- package/dist/provider/default.js +9 -3
- package/dist/provider/interface.d.ts +10 -3
- package/dist/provider/rpc.d.ts +12 -10
- package/dist/provider/rpc.js +80 -72
- package/dist/provider/sequencer.d.ts +4 -3
- package/dist/provider/sequencer.js +14 -6
- package/dist/signer/default.d.ts +2 -2
- package/dist/signer/default.js +2 -2
- package/dist/signer/interface.d.ts +2 -2
- package/dist/types/api/openrpc.d.ts +17 -27
- package/dist/types/api/rpc.d.ts +4 -128
- package/dist/types/api/sequencer.d.ts +15 -4
- package/dist/types/lib.d.ts +10 -4
- package/dist/types/provider.d.ts +3 -2
- package/dist/utils/hash.d.ts +2 -2
- package/dist/utils/hash.js +5 -5
- package/dist/utils/responseParser/rpc.d.ts +2 -5
- package/dist/utils/responseParser/rpc.js +2 -38
- package/package.json +1 -1
- package/provider/default.d.ts +4 -3
- package/provider/default.js +9 -3
- package/provider/interface.d.ts +10 -3
- package/provider/rpc.d.ts +12 -10
- package/provider/rpc.js +80 -72
- package/provider/sequencer.d.ts +4 -3
- package/provider/sequencer.js +14 -6
- package/signer/default.d.ts +2 -2
- package/signer/default.js +2 -2
- package/signer/interface.d.ts +2 -2
- package/src/account/default.ts +21 -20
- package/src/account/interface.ts +2 -1
- package/src/contract/contractFactory.ts +1 -2
- package/src/contract/default.ts +16 -8
- package/src/provider/default.ts +12 -5
- package/src/provider/interface.ts +15 -4
- package/src/provider/rpc.ts +89 -73
- package/src/provider/sequencer.ts +16 -8
- package/src/signer/default.ts +8 -8
- package/src/signer/interface.ts +2 -2
- package/src/types/api/openrpc.ts +20 -25
- package/src/types/api/rpc.ts +4 -128
- package/src/types/api/sequencer.ts +17 -4
- package/src/types/lib.ts +7 -5
- package/src/types/provider.ts +3 -2
- package/src/utils/hash.ts +7 -6
- package/src/utils/responseParser/rpc.ts +7 -25
- package/types/api/openrpc.d.ts +17 -27
- package/types/api/rpc.d.ts +4 -128
- package/types/api/sequencer.d.ts +15 -4
- package/types/lib.d.ts +10 -4
- package/types/provider.d.ts +3 -2
- package/utils/hash.d.ts +2 -2
- package/utils/hash.js +5 -5
- package/utils/responseParser/rpc.d.ts +2 -5
- package/utils/responseParser/rpc.js +2 -38
- package/www/docs/API/account.md +3 -3
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/provider.md +6 -0
- package/www/docs/API/utils.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# [4.7.0](https://github.com/0xs34n/starknet.js/compare/v4.6.0...v4.7.0) (2022-09-22)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- add blockIdentifier for getNonce ([7f2edab](https://github.com/0xs34n/starknet.js/commit/7f2edab5099eb9679744140bfe80328801a621ab))
|
|
6
|
+
- addressSalt from BigNumberish to string | undefined ([f77784c](https://github.com/0xs34n/starknet.js/commit/f77784c98d1827a8fd64dd1c543beea4284af7b3))
|
|
7
|
+
- block_id identifier cleanup ([24c24e8](https://github.com/0xs34n/starknet.js/commit/24c24e8060b76f6a300b21c3148a15183b802fcb))
|
|
8
|
+
- **ci:** use correct devnet image for release pipeline ([fc2fcbb](https://github.com/0xs34n/starknet.js/commit/fc2fcbb57e48b4cec9197c59120a574b018a54af))
|
|
9
|
+
- cleanup pr.yml ([263e296](https://github.com/0xs34n/starknet.js/commit/263e29658c30e2c80fe1795f89d4c334777fef5e))
|
|
10
|
+
- fix tests for starknet 0.10 ([c2da26d](https://github.com/0xs34n/starknet.js/commit/c2da26d4b92221fdd54fdd8ff37c437529616b21))
|
|
11
|
+
- get_nonce response type ([f0c30bd](https://github.com/0xs34n/starknet.js/commit/f0c30bd4376eb7c70098d77ff2918ea80418a8af))
|
|
12
|
+
- throw error only when nonce is not provided with contract.invoke ([c6bba65](https://github.com/0xs34n/starknet.js/commit/c6bba6517054b5221f227732750092d0c11b566d))
|
|
13
|
+
- ts types fixes and block_id ([bad0b85](https://github.com/0xs34n/starknet.js/commit/bad0b851765b9af70af3a784aeb1ae5adbe29816))
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- add getNonce method on account ([8e935eb](https://github.com/0xs34n/starknet.js/commit/8e935ebaa251279b83fab65397687ef0380358ac))
|
|
18
|
+
- getNonce endpoint for sequencer ([add4900](https://github.com/0xs34n/starknet.js/commit/add4900ad86f40390b68f6f2158cfbb588fe21d6))
|
|
19
|
+
- is_valid_signature -> isValidSignature ([f704f3e](https://github.com/0xs34n/starknet.js/commit/f704f3e9a3aec0744c155fc3bded079fac7284b5))
|
|
20
|
+
- rpc options, methods, fetch with prop types, imp. types, clenup responseParser ([0ab5769](https://github.com/0xs34n/starknet.js/commit/0ab576957b3e193a68ae6f3ceb15d0b042d39b14))
|
|
21
|
+
- rpc optionsOrProvider extend with retries ([46f9634](https://github.com/0xs34n/starknet.js/commit/46f96342be05252de306fba28da74e634e8b9c3f))
|
|
22
|
+
- transaction v1 changes ([e928478](https://github.com/0xs34n/starknet.js/commit/e92847848166170c7d63394993cd74ae79c14a67))
|
|
23
|
+
- update tests ([1af16f4](https://github.com/0xs34n/starknet.js/commit/1af16f475813a15c78d3b049b7453c19023fe53a))
|
|
24
|
+
- use starknet-devnet 0.3.1 ([83e5dd7](https://github.com/0xs34n/starknet.js/commit/83e5dd7f3bfc5d8d492b3761da6e9fe15669d03c))
|
|
25
|
+
|
|
1
26
|
# [4.6.0](https://github.com/0xs34n/starknet.js/compare/v4.5.0...v4.6.0) (2022-09-15)
|
|
2
27
|
|
|
3
28
|
### Bug Fixes
|
|
@@ -76,11 +76,8 @@ describe('deploy and test Wallet', () => {
|
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
test('execute with custom nonce', async () => {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
entrypoint: 'get_nonce',
|
|
82
|
-
});
|
|
83
|
-
const nonce = toBN(result[0]).toNumber();
|
|
79
|
+
const result = await account.getNonce();
|
|
80
|
+
const nonce = toBN(result).toNumber();
|
|
84
81
|
const { transaction_hash } = await account.execute(
|
|
85
82
|
{
|
|
86
83
|
contractAddress: erc20Address,
|
|
@@ -43,7 +43,6 @@ describe('class Contract {}', () => {
|
|
|
43
43
|
expect(res).toHaveProperty('contractAddress');
|
|
44
44
|
expect(res).toHaveProperty('entrypoint');
|
|
45
45
|
expect(res).toHaveProperty('calldata');
|
|
46
|
-
expect(res).toHaveProperty('signature');
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
|
|
@@ -62,6 +62,11 @@ describe('defaultProvider', () => {
|
|
|
62
62
|
return expect(block).toHaveProperty('block_number');
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
test('getNonce()', async () => {
|
|
66
|
+
const nonce = await testProvider.getNonce(exampleContractAddress);
|
|
67
|
+
return expect(nonce).toEqual('0x0');
|
|
68
|
+
});
|
|
69
|
+
|
|
65
70
|
describe('getStorageAt', () => {
|
|
66
71
|
test('with "key" type of number', () => {
|
|
67
72
|
return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
|
|
@@ -216,7 +221,6 @@ describe('defaultProvider', () => {
|
|
|
216
221
|
expect(transaction.transaction_hash).toBeTruthy();
|
|
217
222
|
expect(transaction.contract_address).toBeTruthy();
|
|
218
223
|
expect(Array.isArray(transaction.calldata)).toBe(true);
|
|
219
|
-
expect(transaction.entry_point_selector).toBeTruthy();
|
|
220
224
|
expect(Array.isArray(transaction.signature)).toBe(true);
|
|
221
225
|
expect(transaction.max_fee).toBeTruthy();
|
|
222
226
|
});
|
|
@@ -256,6 +260,10 @@ describe('defaultProvider', () => {
|
|
|
256
260
|
|
|
257
261
|
beforeAll(async () => {
|
|
258
262
|
deployResponse = await provider.deployContract({ contract: compiledErc20 });
|
|
263
|
+
console.log(
|
|
264
|
+
'🚀 ~ file: defaultProvider.test.ts ~ line 264 ~ beforeAll ~ deployResponse',
|
|
265
|
+
deployResponse
|
|
266
|
+
);
|
|
259
267
|
contractAddress = deployResponse.contract_address;
|
|
260
268
|
declareResponse = await provider.declareContract({ contract: compiledErc20 });
|
|
261
269
|
await Promise.all([
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
|
|
10
10
|
// Run only if Devnet Sequencer
|
|
11
11
|
describeIfSequencer('SequencerProvider', () => {
|
|
12
|
-
let
|
|
12
|
+
let sequencerProvider: SequencerProvider;
|
|
13
13
|
let customSequencerProvider: Provider;
|
|
14
14
|
let exampleContractAddress: string;
|
|
15
15
|
|
|
16
16
|
beforeAll(async () => {
|
|
17
|
-
|
|
17
|
+
sequencerProvider = getTestProvider() as SequencerProvider;
|
|
18
18
|
customSequencerProvider = new Provider({
|
|
19
19
|
sequencer: {
|
|
20
20
|
baseUrl: 'https://alpha4.starknet.io',
|
|
@@ -28,32 +28,34 @@ describeIfSequencer('SequencerProvider', () => {
|
|
|
28
28
|
let exampleTransactionHash: string;
|
|
29
29
|
|
|
30
30
|
beforeAll(async () => {
|
|
31
|
-
const { transaction_hash, contract_address } = await
|
|
31
|
+
const { transaction_hash, contract_address } = await sequencerProvider.deployContract({
|
|
32
32
|
contract: compiledErc20,
|
|
33
33
|
});
|
|
34
|
-
await
|
|
34
|
+
await sequencerProvider.waitForTransaction(transaction_hash);
|
|
35
35
|
exampleTransactionHash = transaction_hash;
|
|
36
36
|
exampleContractAddress = contract_address;
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test('getTransactionStatus()', async () => {
|
|
40
|
-
return expect(
|
|
40
|
+
return expect(
|
|
41
|
+
sequencerProvider.getTransactionStatus(exampleTransactionHash)
|
|
42
|
+
).resolves.not.toThrow();
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
test('transaction trace', async () => {
|
|
44
|
-
const transactionTrace = await
|
|
46
|
+
const transactionTrace = await sequencerProvider.getTransactionTrace(exampleTransactionHash);
|
|
45
47
|
expect(transactionTrace).toHaveProperty('function_invocation');
|
|
46
48
|
expect(transactionTrace).toHaveProperty('signature');
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
test('getCode() -> { bytecode }', async () => {
|
|
50
|
-
const code = await
|
|
52
|
+
const code = await sequencerProvider.getCode(exampleContractAddress);
|
|
51
53
|
return expect(Array.isArray(code.bytecode)).toBe(true);
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
describeIfNotDevnet('which are not available on devnet', () => {
|
|
55
57
|
test('getContractAddresses()', async () => {
|
|
56
|
-
const { GpsStatementVerifier, Starknet } = await
|
|
58
|
+
const { GpsStatementVerifier, Starknet } = await sequencerProvider.getContractAddresses();
|
|
57
59
|
expect(typeof GpsStatementVerifier).toBe('string');
|
|
58
60
|
expect(typeof Starknet).toBe('string');
|
|
59
61
|
});
|
|
@@ -2,9 +2,8 @@ import { StarknetChainId } from '../../src/constants';
|
|
|
2
2
|
import { ec, getKeyPair, getStarkKey, sign, verify } from '../../src/utils/ellipticCurve';
|
|
3
3
|
import { removeHexPrefix } from '../../src/utils/encode';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
calculateTransactionHash,
|
|
6
6
|
computeHashOnElements,
|
|
7
|
-
getSelectorFromName,
|
|
8
7
|
pedersen,
|
|
9
8
|
transactionVersion,
|
|
10
9
|
} from '../../src/utils/hash';
|
|
@@ -57,25 +56,25 @@ test('hashMessage()', () => {
|
|
|
57
56
|
const maxFee = '0';
|
|
58
57
|
const calldata = fromCallsToExecuteCalldataWithNonce(transactions, nonce);
|
|
59
58
|
|
|
60
|
-
const hashMsg =
|
|
59
|
+
const hashMsg = calculateTransactionHash(
|
|
61
60
|
account,
|
|
62
61
|
transactionVersion,
|
|
63
|
-
getSelectorFromName('__execute__'),
|
|
64
62
|
calldata,
|
|
65
63
|
maxFee,
|
|
66
|
-
StarknetChainId.TESTNET
|
|
64
|
+
StarknetChainId.TESTNET,
|
|
65
|
+
nonce
|
|
67
66
|
);
|
|
68
67
|
|
|
69
68
|
expect(hashMsg).toMatchInlineSnapshot(
|
|
70
|
-
`"
|
|
69
|
+
`"0x6d1706bd3d1ba7c517be2a2a335996f63d4738e2f182144d078a1dd9997062e"`
|
|
71
70
|
);
|
|
72
71
|
const keyPair = getKeyPair(privateKey);
|
|
73
72
|
const [r, s] = sign(keyPair, removeHexPrefix(hashMsg));
|
|
74
73
|
expect(r.toString()).toMatchInlineSnapshot(
|
|
75
|
-
`"
|
|
74
|
+
`"1427981024487605678086498726488552139932400435436186597196374630267616399345"`
|
|
76
75
|
);
|
|
77
76
|
expect(s.toString()).toMatchInlineSnapshot(
|
|
78
|
-
`"
|
|
77
|
+
`"1853664302719670721837677288395394946745467311923401353018029119631574115563"`
|
|
79
78
|
);
|
|
80
79
|
});
|
|
81
80
|
|
package/account/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProviderInterface, ProviderOptions } from '../provider';
|
|
2
2
|
import { Provider } from '../provider/default';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import { SignerInterface } from '../signer';
|
|
4
5
|
import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
|
|
5
6
|
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
@@ -7,10 +8,10 @@ import { BigNumberish } from '../utils/number';
|
|
|
7
8
|
import { TypedData } from '../utils/typedData';
|
|
8
9
|
import { AccountInterface } from './interface';
|
|
9
10
|
export declare class Account extends Provider implements AccountInterface {
|
|
10
|
-
address: string;
|
|
11
11
|
signer: SignerInterface;
|
|
12
|
+
address: string;
|
|
12
13
|
constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
13
|
-
getNonce(): Promise<
|
|
14
|
+
getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
14
15
|
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
15
16
|
/**
|
|
16
17
|
* Invoke execute function in account contract
|
package/account/default.js
CHANGED
|
@@ -75,62 +75,54 @@ var Account = /** @class */ (function (_super) {
|
|
|
75
75
|
__extends(Account, _super);
|
|
76
76
|
function Account(providerOrOptions, address, keyPairOrSigner) {
|
|
77
77
|
var _this = _super.call(this, providerOrOptions) || this;
|
|
78
|
-
_this.address = address;
|
|
78
|
+
_this.address = address.toLowerCase();
|
|
79
79
|
_this.signer =
|
|
80
80
|
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
|
|
81
81
|
return _this;
|
|
82
82
|
}
|
|
83
|
-
Account.prototype.getNonce = function () {
|
|
83
|
+
Account.prototype.getNonce = function (blockIdentifier) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var result;
|
|
86
85
|
return __generator(this, function (_a) {
|
|
87
|
-
|
|
88
|
-
case 0: return [4 /*yield*/, this.callContract({
|
|
89
|
-
contractAddress: this.address,
|
|
90
|
-
entrypoint: 'get_nonce',
|
|
91
|
-
})];
|
|
92
|
-
case 1:
|
|
93
|
-
result = (_a.sent()).result;
|
|
94
|
-
return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
|
|
95
|
-
}
|
|
86
|
+
return [2 /*return*/, _super.prototype.getNonce.call(this, this.address, blockIdentifier)];
|
|
96
87
|
});
|
|
97
88
|
});
|
|
98
89
|
};
|
|
99
90
|
Account.prototype.estimateFee = function (calls, _a) {
|
|
100
91
|
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
|
|
101
92
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
var transactions, nonce, _c, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
|
|
103
|
-
return __generator(this, function (
|
|
104
|
-
switch (
|
|
93
|
+
var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
|
|
94
|
+
return __generator(this, function (_e) {
|
|
95
|
+
switch (_e.label) {
|
|
105
96
|
case 0:
|
|
106
97
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
98
|
+
_c = number_1.toBN;
|
|
107
99
|
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
108
|
-
|
|
100
|
+
_d = providedNonce;
|
|
109
101
|
return [3 /*break*/, 3];
|
|
110
102
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
111
103
|
case 2:
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
_d = (_e.sent());
|
|
105
|
+
_e.label = 3;
|
|
114
106
|
case 3:
|
|
115
|
-
nonce = _c;
|
|
116
|
-
version = (0, number_1.toBN)(hash_1.
|
|
107
|
+
nonce = _c.apply(void 0, [_d]);
|
|
108
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
117
109
|
return [4 /*yield*/, this.getChainId()];
|
|
118
110
|
case 4:
|
|
119
|
-
chainId =
|
|
111
|
+
chainId = _e.sent();
|
|
120
112
|
signerDetails = {
|
|
121
113
|
walletAddress: this.address,
|
|
122
|
-
nonce:
|
|
114
|
+
nonce: nonce,
|
|
123
115
|
maxFee: constants_1.ZERO,
|
|
124
116
|
version: version,
|
|
125
117
|
chainId: chainId,
|
|
126
118
|
};
|
|
127
119
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
128
120
|
case 5:
|
|
129
|
-
signature =
|
|
130
|
-
calldata = (0, transaction_1.
|
|
131
|
-
return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address,
|
|
121
|
+
signature = _e.sent();
|
|
122
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
|
|
123
|
+
return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
|
|
132
124
|
case 6:
|
|
133
|
-
response =
|
|
125
|
+
response = _e.sent();
|
|
134
126
|
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
|
|
135
127
|
return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
|
|
136
128
|
}
|
|
@@ -191,8 +183,9 @@ var Account = /** @class */ (function (_super) {
|
|
|
191
183
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
192
184
|
case 8:
|
|
193
185
|
signature = _d.sent();
|
|
194
|
-
calldata = (0, transaction_1.
|
|
195
|
-
return [2 /*return*/, this.invokeFunction({ contractAddress: this.address,
|
|
186
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
|
|
187
|
+
return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
|
|
188
|
+
nonce: nonce,
|
|
196
189
|
maxFee: maxFee,
|
|
197
190
|
version: version,
|
|
198
191
|
})];
|
|
@@ -246,7 +239,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
246
239
|
_b.trys.push([0, 2, , 3]);
|
|
247
240
|
return [4 /*yield*/, this.callContract({
|
|
248
241
|
contractAddress: this.address,
|
|
249
|
-
entrypoint: '
|
|
242
|
+
entrypoint: 'isValidSignature',
|
|
250
243
|
calldata: (0, stark_1.compileCalldata)({
|
|
251
244
|
hash: (0, number_1.toBN)(hash).toString(),
|
|
252
245
|
signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
|
package/account/interface.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
@@ -68,5 +69,5 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
68
69
|
* @throws {Error} if the signature is not a valid signature
|
|
69
70
|
*/
|
|
70
71
|
abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
71
|
-
abstract getNonce(): Promise<
|
|
72
|
+
abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
72
73
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
3
|
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
4
|
-
import { BigNumberish } from '../utils/number';
|
|
5
4
|
import { Contract } from './default';
|
|
6
5
|
export declare class ContractFactory {
|
|
7
6
|
abi: Abi;
|
|
@@ -15,7 +14,7 @@ export declare class ContractFactory {
|
|
|
15
14
|
* @param addressSalt (optional) - Address Salt for deployment
|
|
16
15
|
* @returns deployed Contract
|
|
17
16
|
*/
|
|
18
|
-
deploy(constructorCalldata?: RawCalldata, addressSalt?:
|
|
17
|
+
deploy(constructorCalldata?: RawCalldata, addressSalt?: string | undefined): Promise<Contract>;
|
|
19
18
|
/**
|
|
20
19
|
* Attaches to new Provider or Account
|
|
21
20
|
*
|
package/contract/default.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
-
import { Abi, AbiEntry, Args, AsyncContractFunction, Calldata, ContractFunction,
|
|
4
|
+
import { Abi, AbiEntry, Args, AsyncContractFunction, Call, Calldata, ContractFunction, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
|
|
5
5
|
import { BigNumberish } from '../utils/number';
|
|
6
6
|
import { ContractInterface } from './interface';
|
|
7
7
|
export declare class Contract implements ContractInterface {
|
|
@@ -120,5 +120,5 @@ export declare class Contract implements ContractInterface {
|
|
|
120
120
|
blockIdentifier?: BlockIdentifier;
|
|
121
121
|
}): Promise<Result>;
|
|
122
122
|
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
|
|
123
|
-
populate(method: string, args?: Array<any>):
|
|
123
|
+
populate(method: string, args?: Array<any>): Call;
|
|
124
124
|
}
|
package/contract/default.js
CHANGED
|
@@ -181,7 +181,7 @@ var Contract = /** @class */ (function () {
|
|
|
181
181
|
function Contract(abi, address, providerOrAccount) {
|
|
182
182
|
if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
|
|
183
183
|
var _this = this;
|
|
184
|
-
this.address = address;
|
|
184
|
+
this.address = address.toLowerCase();
|
|
185
185
|
this.providerOrAccount = providerOrAccount;
|
|
186
186
|
this.abi = abi;
|
|
187
187
|
this.structs = abi
|
|
@@ -592,9 +592,14 @@ var Contract = /** @class */ (function () {
|
|
|
592
592
|
nonce: options.nonce,
|
|
593
593
|
});
|
|
594
594
|
}
|
|
595
|
+
if (!options.nonce) {
|
|
596
|
+
throw new Error("Nonce is required when invoking a function without an account");
|
|
597
|
+
}
|
|
595
598
|
// eslint-disable-next-line no-console
|
|
596
599
|
console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
|
|
597
|
-
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] })
|
|
600
|
+
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
|
|
601
|
+
nonce: options.nonce,
|
|
602
|
+
});
|
|
598
603
|
};
|
|
599
604
|
Contract.prototype.call = function (method, args, _a) {
|
|
600
605
|
if (args === void 0) { args = []; }
|
|
@@ -644,7 +649,6 @@ var Contract = /** @class */ (function () {
|
|
|
644
649
|
contractAddress: this.address,
|
|
645
650
|
entrypoint: method,
|
|
646
651
|
calldata: this.compileCalldata(args, inputs),
|
|
647
|
-
signature: [],
|
|
648
652
|
};
|
|
649
653
|
};
|
|
650
654
|
return Contract;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProviderInterface, ProviderOptions } from '../provider';
|
|
2
2
|
import { Provider } from '../provider/default';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import { SignerInterface } from '../signer';
|
|
4
5
|
import { Abi, Call, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
|
|
5
6
|
import { EstimateFee, EstimateFeeDetails } from '../types/account';
|
|
@@ -7,10 +8,10 @@ import { BigNumberish } from '../utils/number';
|
|
|
7
8
|
import { TypedData } from '../utils/typedData';
|
|
8
9
|
import { AccountInterface } from './interface';
|
|
9
10
|
export declare class Account extends Provider implements AccountInterface {
|
|
10
|
-
address: string;
|
|
11
11
|
signer: SignerInterface;
|
|
12
|
+
address: string;
|
|
12
13
|
constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
13
|
-
getNonce(): Promise<
|
|
14
|
+
getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
14
15
|
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
15
16
|
/**
|
|
16
17
|
* Invoke execute function in account contract
|
package/dist/account/default.js
CHANGED
|
@@ -75,62 +75,54 @@ var Account = /** @class */ (function (_super) {
|
|
|
75
75
|
__extends(Account, _super);
|
|
76
76
|
function Account(providerOrOptions, address, keyPairOrSigner) {
|
|
77
77
|
var _this = _super.call(this, providerOrOptions) || this;
|
|
78
|
-
_this.address = address;
|
|
78
|
+
_this.address = address.toLowerCase();
|
|
79
79
|
_this.signer =
|
|
80
80
|
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
|
|
81
81
|
return _this;
|
|
82
82
|
}
|
|
83
|
-
Account.prototype.getNonce = function () {
|
|
83
|
+
Account.prototype.getNonce = function (blockIdentifier) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var result;
|
|
86
85
|
return __generator(this, function (_a) {
|
|
87
|
-
|
|
88
|
-
case 0: return [4 /*yield*/, this.callContract({
|
|
89
|
-
contractAddress: this.address,
|
|
90
|
-
entrypoint: 'get_nonce',
|
|
91
|
-
})];
|
|
92
|
-
case 1:
|
|
93
|
-
result = (_a.sent()).result;
|
|
94
|
-
return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
|
|
95
|
-
}
|
|
86
|
+
return [2 /*return*/, _super.prototype.getNonce.call(this, this.address, blockIdentifier)];
|
|
96
87
|
});
|
|
97
88
|
});
|
|
98
89
|
};
|
|
99
90
|
Account.prototype.estimateFee = function (calls, _a) {
|
|
100
91
|
var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
|
|
101
92
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
var transactions, nonce, _c, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
|
|
103
|
-
return __generator(this, function (
|
|
104
|
-
switch (
|
|
93
|
+
var transactions, nonce, _c, _d, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
|
|
94
|
+
return __generator(this, function (_e) {
|
|
95
|
+
switch (_e.label) {
|
|
105
96
|
case 0:
|
|
106
97
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
98
|
+
_c = number_1.toBN;
|
|
107
99
|
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
108
|
-
|
|
100
|
+
_d = providedNonce;
|
|
109
101
|
return [3 /*break*/, 3];
|
|
110
102
|
case 1: return [4 /*yield*/, this.getNonce()];
|
|
111
103
|
case 2:
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
_d = (_e.sent());
|
|
105
|
+
_e.label = 3;
|
|
114
106
|
case 3:
|
|
115
|
-
nonce = _c;
|
|
116
|
-
version = (0, number_1.toBN)(hash_1.
|
|
107
|
+
nonce = _c.apply(void 0, [_d]);
|
|
108
|
+
version = (0, number_1.toBN)(hash_1.transactionVersion);
|
|
117
109
|
return [4 /*yield*/, this.getChainId()];
|
|
118
110
|
case 4:
|
|
119
|
-
chainId =
|
|
111
|
+
chainId = _e.sent();
|
|
120
112
|
signerDetails = {
|
|
121
113
|
walletAddress: this.address,
|
|
122
|
-
nonce:
|
|
114
|
+
nonce: nonce,
|
|
123
115
|
maxFee: constants_1.ZERO,
|
|
124
116
|
version: version,
|
|
125
117
|
chainId: chainId,
|
|
126
118
|
};
|
|
127
119
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
128
120
|
case 5:
|
|
129
|
-
signature =
|
|
130
|
-
calldata = (0, transaction_1.
|
|
131
|
-
return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address,
|
|
121
|
+
signature = _e.sent();
|
|
122
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
|
|
123
|
+
return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, calldata: calldata, signature: signature }, { version: version, nonce: nonce }, blockIdentifier)];
|
|
132
124
|
case 6:
|
|
133
|
-
response =
|
|
125
|
+
response = _e.sent();
|
|
134
126
|
suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
|
|
135
127
|
return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
|
|
136
128
|
}
|
|
@@ -191,8 +183,9 @@ var Account = /** @class */ (function (_super) {
|
|
|
191
183
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
192
184
|
case 8:
|
|
193
185
|
signature = _d.sent();
|
|
194
|
-
calldata = (0, transaction_1.
|
|
195
|
-
return [2 /*return*/, this.invokeFunction({ contractAddress: this.address,
|
|
186
|
+
calldata = (0, transaction_1.fromCallsToExecuteCalldata)(transactions);
|
|
187
|
+
return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, calldata: calldata, signature: signature }, {
|
|
188
|
+
nonce: nonce,
|
|
196
189
|
maxFee: maxFee,
|
|
197
190
|
version: version,
|
|
198
191
|
})];
|
|
@@ -246,7 +239,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
246
239
|
_b.trys.push([0, 2, , 3]);
|
|
247
240
|
return [4 /*yield*/, this.callContract({
|
|
248
241
|
contractAddress: this.address,
|
|
249
|
-
entrypoint: '
|
|
242
|
+
entrypoint: 'isValidSignature',
|
|
250
243
|
calldata: (0, stark_1.compileCalldata)({
|
|
251
244
|
hash: (0, number_1.toBN)(hash).toString(),
|
|
252
245
|
signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
2
3
|
import { SignerInterface } from '../signer';
|
|
3
4
|
import { Abi, Call, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
|
|
4
5
|
import { BigNumberish } from '../utils/number';
|
|
@@ -68,5 +69,5 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
68
69
|
* @throws {Error} if the signature is not a valid signature
|
|
69
70
|
*/
|
|
70
71
|
abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
71
|
-
abstract getNonce(): Promise<
|
|
72
|
+
abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
72
73
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
3
|
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
4
|
-
import { BigNumberish } from '../utils/number';
|
|
5
4
|
import { Contract } from './default';
|
|
6
5
|
export declare class ContractFactory {
|
|
7
6
|
abi: Abi;
|
|
@@ -15,7 +14,7 @@ export declare class ContractFactory {
|
|
|
15
14
|
* @param addressSalt (optional) - Address Salt for deployment
|
|
16
15
|
* @returns deployed Contract
|
|
17
16
|
*/
|
|
18
|
-
deploy(constructorCalldata?: RawCalldata, addressSalt?:
|
|
17
|
+
deploy(constructorCalldata?: RawCalldata, addressSalt?: string | undefined): Promise<Contract>;
|
|
19
18
|
/**
|
|
20
19
|
* Attaches to new Provider or Account
|
|
21
20
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
3
|
import { BlockIdentifier } from '../provider/utils';
|
|
4
|
-
import { Abi, AbiEntry, Args, AsyncContractFunction, Calldata, ContractFunction,
|
|
4
|
+
import { Abi, AbiEntry, Args, AsyncContractFunction, Call, Calldata, ContractFunction, InvokeFunctionResponse, Overrides, ParsedStruct, Result, StructAbi } from '../types';
|
|
5
5
|
import { BigNumberish } from '../utils/number';
|
|
6
6
|
import { ContractInterface } from './interface';
|
|
7
7
|
export declare class Contract implements ContractInterface {
|
|
@@ -120,5 +120,5 @@ export declare class Contract implements ContractInterface {
|
|
|
120
120
|
blockIdentifier?: BlockIdentifier;
|
|
121
121
|
}): Promise<Result>;
|
|
122
122
|
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
|
|
123
|
-
populate(method: string, args?: Array<any>):
|
|
123
|
+
populate(method: string, args?: Array<any>): Call;
|
|
124
124
|
}
|
package/dist/contract/default.js
CHANGED
|
@@ -181,7 +181,7 @@ var Contract = /** @class */ (function () {
|
|
|
181
181
|
function Contract(abi, address, providerOrAccount) {
|
|
182
182
|
if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
|
|
183
183
|
var _this = this;
|
|
184
|
-
this.address = address;
|
|
184
|
+
this.address = address.toLowerCase();
|
|
185
185
|
this.providerOrAccount = providerOrAccount;
|
|
186
186
|
this.abi = abi;
|
|
187
187
|
this.structs = abi
|
|
@@ -592,9 +592,14 @@ var Contract = /** @class */ (function () {
|
|
|
592
592
|
nonce: options.nonce,
|
|
593
593
|
});
|
|
594
594
|
}
|
|
595
|
+
if (!options.nonce) {
|
|
596
|
+
throw new Error("Nonce is required when invoking a function without an account");
|
|
597
|
+
}
|
|
595
598
|
// eslint-disable-next-line no-console
|
|
596
599
|
console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
|
|
597
|
-
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] })
|
|
600
|
+
return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
|
|
601
|
+
nonce: options.nonce,
|
|
602
|
+
});
|
|
598
603
|
};
|
|
599
604
|
Contract.prototype.call = function (method, args, _a) {
|
|
600
605
|
if (args === void 0) { args = []; }
|
|
@@ -644,7 +649,6 @@ var Contract = /** @class */ (function () {
|
|
|
644
649
|
contractAddress: this.address,
|
|
645
650
|
entrypoint: method,
|
|
646
651
|
calldata: this.compileCalldata(args, inputs),
|
|
647
|
-
signature: [],
|
|
648
652
|
};
|
|
649
653
|
};
|
|
650
654
|
return Contract;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation,
|
|
2
|
+
import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { ProviderInterface } from './interface';
|
|
5
5
|
import { RpcProviderOptions } from './rpc';
|
|
@@ -16,12 +16,13 @@ export declare class Provider implements ProviderInterface {
|
|
|
16
16
|
getChainId(): Promise<StarknetChainId>;
|
|
17
17
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
18
18
|
getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
|
|
19
|
-
getEstimateFee(invocation: Invocation,
|
|
19
|
+
getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
|
|
20
|
+
getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
20
21
|
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
21
22
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
22
23
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
23
24
|
callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
24
|
-
invokeFunction(functionInvocation: Invocation, details:
|
|
25
|
+
invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
|
|
25
26
|
deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
|
|
26
27
|
declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
27
28
|
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|