starknet 4.5.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 +40 -0
- package/README.md +3 -1
- package/__tests__/account.test.ts +2 -5
- package/__tests__/contract.test.ts +0 -1
- package/__tests__/defaultProvider.test.ts +16 -10
- package/__tests__/rpcProvider.test.ts +107 -12
- package/__tests__/sequencerProvider.test.ts +10 -8
- package/__tests__/utils/ellipticalCurve.test.ts +7 -8
- package/__tests__/utils/utils.test.ts +17 -0
- 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 +24 -12
- package/dist/provider/rpc.js +167 -105
- package/dist/provider/sequencer.d.ts +4 -3
- package/dist/provider/sequencer.js +16 -7
- package/dist/provider/utils.d.ts +11 -35
- package/dist/provider/utils.js +52 -63
- 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 +395 -45
- package/dist/types/api/openrpc.js +21 -3
- package/dist/types/api/rpc.d.ts +34 -191
- 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 +6 -6
- package/dist/utils/responseParser/rpc.js +3 -39
- 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 +24 -12
- package/provider/rpc.js +167 -105
- package/provider/sequencer.d.ts +4 -3
- package/provider/sequencer.js +16 -7
- package/provider/utils.d.ts +11 -35
- package/provider/utils.js +52 -63
- 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 +152 -102
- package/src/provider/sequencer.ts +19 -10
- package/src/provider/utils.ts +43 -56
- package/src/signer/default.ts +8 -8
- package/src/signer/interface.ts +2 -2
- package/src/types/api/openrpc.ts +378 -53
- package/src/types/api/rpc.ts +33 -211
- 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 +13 -27
- package/types/api/openrpc.d.ts +395 -45
- package/types/api/openrpc.js +21 -3
- package/types/api/rpc.d.ts +34 -191
- 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 +6 -6
- package/utils/responseParser/rpc.js +3 -39
- 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,43 @@
|
|
|
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
|
+
|
|
26
|
+
# [4.6.0](https://github.com/0xs34n/starknet.js/compare/v4.5.0...v4.6.0) (2022-09-15)
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
- add test getTransactionCount [skip ci] ([342755a](https://github.com/0xs34n/starknet.js/commit/342755aa99dda016d7aa394a0023b3f2e5d5e963))
|
|
31
|
+
- estimateFee and call block id ([ef1645f](https://github.com/0xs34n/starknet.js/commit/ef1645f740e7c29edea6b091bec9949ec713953f))
|
|
32
|
+
- rpc test update, comepleted rpc to openrpc mapping, rpc provider methods ([8b41e0f](https://github.com/0xs34n/starknet.js/commit/8b41e0fcf36b34b20dfaba356cfc0131f02d7d69))
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
- new Block utility object, rpc fetch clenup, open rpc fetch api ([0d381c8](https://github.com/0xs34n/starknet.js/commit/0d381c89fe655b2628f02e67095ef03cb1721398))
|
|
37
|
+
- read, write and trace api ([d488ab2](https://github.com/0xs34n/starknet.js/commit/d488ab2513b88fdeb4e27b6ec2b7226ffd359445))
|
|
38
|
+
- retry rpc wait for transaction 200 times instead of 100 ([3bc9118](https://github.com/0xs34n/starknet.js/commit/3bc9118cae86fba21e1c85667079079662ba0b7b))
|
|
39
|
+
- updated rpc tests with new methods ([e369d95](https://github.com/0xs34n/starknet.js/commit/e369d95d72f3b39b3e8b8baa99867b94c1d5d1c1))
|
|
40
|
+
|
|
1
41
|
# [4.5.0](https://github.com/0xs34n/starknet.js/compare/v4.4.2...v4.5.0) (2022-09-09)
|
|
2
42
|
|
|
3
43
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -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();
|
|
@@ -139,10 +144,11 @@ describe('defaultProvider', () => {
|
|
|
139
144
|
|
|
140
145
|
describeIfNotDevnet('Provider', () => {
|
|
141
146
|
const provider = getTestProvider();
|
|
147
|
+
let latestBlock;
|
|
142
148
|
describe(`Provider methods if not devnet`, () => {
|
|
143
149
|
describe('getBlock', () => {
|
|
144
|
-
test('pending', async () => {
|
|
145
|
-
|
|
150
|
+
test('getBlock by tag pending', async () => {
|
|
151
|
+
latestBlock = await provider.getBlock();
|
|
146
152
|
expect(latestBlock).toHaveProperty('block_hash');
|
|
147
153
|
expect(latestBlock).toHaveProperty('parent_hash');
|
|
148
154
|
expect(latestBlock).toHaveProperty('block_number');
|
|
@@ -153,11 +159,8 @@ describe('defaultProvider', () => {
|
|
|
153
159
|
expect(Array.isArray(latestBlock.transactions)).toBe(true);
|
|
154
160
|
});
|
|
155
161
|
|
|
156
|
-
test('
|
|
157
|
-
const block = await provider.getBlock(
|
|
158
|
-
'0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43'
|
|
159
|
-
);
|
|
160
|
-
|
|
162
|
+
test('getBlock by Hash', async () => {
|
|
163
|
+
const block = await provider.getBlock(latestBlock.block_hash);
|
|
161
164
|
expect(block).toHaveProperty('block_hash');
|
|
162
165
|
expect(block).toHaveProperty('parent_hash');
|
|
163
166
|
expect(block).toHaveProperty('block_number');
|
|
@@ -168,8 +171,8 @@ describe('defaultProvider', () => {
|
|
|
168
171
|
expect(Array.isArray(block.transactions)).toBe(true);
|
|
169
172
|
});
|
|
170
173
|
|
|
171
|
-
test('
|
|
172
|
-
const block = await provider.getBlock(
|
|
174
|
+
test('getBlock by Number', async () => {
|
|
175
|
+
const block = await provider.getBlock(latestBlock.block_number);
|
|
173
176
|
expect(block).toHaveProperty('block_hash');
|
|
174
177
|
expect(block).toHaveProperty('parent_hash');
|
|
175
178
|
expect(block).toHaveProperty('block_number');
|
|
@@ -218,7 +221,6 @@ describe('defaultProvider', () => {
|
|
|
218
221
|
expect(transaction.transaction_hash).toBeTruthy();
|
|
219
222
|
expect(transaction.contract_address).toBeTruthy();
|
|
220
223
|
expect(Array.isArray(transaction.calldata)).toBe(true);
|
|
221
|
-
expect(transaction.entry_point_selector).toBeTruthy();
|
|
222
224
|
expect(Array.isArray(transaction.signature)).toBe(true);
|
|
223
225
|
expect(transaction.max_fee).toBeTruthy();
|
|
224
226
|
});
|
|
@@ -258,6 +260,10 @@ describe('defaultProvider', () => {
|
|
|
258
260
|
|
|
259
261
|
beforeAll(async () => {
|
|
260
262
|
deployResponse = await provider.deployContract({ contract: compiledErc20 });
|
|
263
|
+
console.log(
|
|
264
|
+
'🚀 ~ file: defaultProvider.test.ts ~ line 264 ~ beforeAll ~ deployResponse',
|
|
265
|
+
deployResponse
|
|
266
|
+
);
|
|
261
267
|
contractAddress = deployResponse.contract_address;
|
|
262
268
|
declareResponse = await provider.declareContract({ contract: compiledErc20 });
|
|
263
269
|
await Promise.all([
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Account, RpcProvider, ec } from '../src';
|
|
1
|
+
import { Account, GetBlockResponse, RpcProvider, ec } from '../src';
|
|
2
2
|
import {
|
|
3
|
+
compiledErc20,
|
|
3
4
|
compiledOpenZeppelinAccount,
|
|
4
5
|
describeIfRpc,
|
|
5
6
|
getTestAccount,
|
|
@@ -20,21 +21,115 @@ describeIfRpc('RPCProvider', () => {
|
|
|
20
21
|
accountPublicKey = ec.getStarkKey(accountKeyPair);
|
|
21
22
|
});
|
|
22
23
|
|
|
24
|
+
test('getChainId', async () => {
|
|
25
|
+
const chainId = await rpcProvider.getChainId();
|
|
26
|
+
expect(chainId).toBe('0x534e5f474f45524c49');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('getPendingTransactions', async () => {
|
|
30
|
+
const transactions = await rpcProvider.getPendingTransactions();
|
|
31
|
+
expect(Array.isArray(transactions)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('getTransactionCount', async () => {
|
|
35
|
+
const count = await rpcProvider.getTransactionCount('latest');
|
|
36
|
+
expect(typeof count).toBe('number');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('getBlockHashAndNumber', async () => {
|
|
40
|
+
const blockHashAndNumber = await rpcProvider.getBlockHashAndNumber();
|
|
41
|
+
expect(blockHashAndNumber).toHaveProperty('block_hash');
|
|
42
|
+
expect(blockHashAndNumber).toHaveProperty('block_number');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('getStateUpdate', async () => {
|
|
46
|
+
const stateUpdate = await rpcProvider.getStateUpdate('latest');
|
|
47
|
+
expect(stateUpdate).toHaveProperty('block_hash');
|
|
48
|
+
expect(stateUpdate).toHaveProperty('new_root');
|
|
49
|
+
expect(stateUpdate).toHaveProperty('old_root');
|
|
50
|
+
expect(stateUpdate).toHaveProperty('state_diff');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
xtest('getProtocolVersion', async () => {
|
|
54
|
+
await rpcProvider.getProtocolVersion();
|
|
55
|
+
});
|
|
56
|
+
|
|
23
57
|
describe('RPC methods', () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
58
|
+
let latestBlock: GetBlockResponse;
|
|
59
|
+
|
|
60
|
+
beforeAll(async () => {
|
|
61
|
+
latestBlock = await rpcProvider.getBlock('latest');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('getBlockWithTxHashes', async () => {
|
|
65
|
+
const blockResponse = await rpcProvider.getBlockWithTxHashes(latestBlock.block_number);
|
|
66
|
+
expect(blockResponse).toHaveProperty('transactions');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('getBlockWithTxs', async () => {
|
|
70
|
+
const blockResponse = await rpcProvider.getBlockWithTxs(latestBlock.block_number);
|
|
71
|
+
expect(blockResponse).toHaveProperty('transactions');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('getTransactionByBlockIdAndIndex', async () => {
|
|
75
|
+
const transaction = await rpcProvider.getTransactionByBlockIdAndIndex(
|
|
76
|
+
latestBlock.block_number,
|
|
77
|
+
0
|
|
78
|
+
);
|
|
79
|
+
expect(transaction).toHaveProperty('transaction_hash');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
xtest('traceBlockTransactions', async () => {
|
|
83
|
+
await rpcProvider.traceBlockTransactions(latestBlock.block_hash);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('deploy contract related tests', () => {
|
|
87
|
+
let contract_address;
|
|
88
|
+
let transaction_hash;
|
|
89
|
+
|
|
90
|
+
beforeAll(async () => {
|
|
91
|
+
({ contract_address, transaction_hash } = await rpcProvider.deployContract({
|
|
92
|
+
contract: compiledOpenZeppelinAccount,
|
|
93
|
+
constructorCalldata: [accountPublicKey],
|
|
94
|
+
addressSalt: accountPublicKey,
|
|
95
|
+
}));
|
|
96
|
+
await rpcProvider.waitForTransaction(transaction_hash);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('deployContract result', () => {
|
|
100
|
+
expect(contract_address).toBeTruthy();
|
|
101
|
+
expect(transaction_hash).toBeTruthy();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('getTransactionByHash', async () => {
|
|
105
|
+
const transaction = await rpcProvider.getTransactionByHash(transaction_hash);
|
|
106
|
+
expect(transaction).toHaveProperty('transaction_hash');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('getClassHashAt', async () => {
|
|
110
|
+
const classHash = await rpcProvider.getClassHashAt('latest', contract_address);
|
|
111
|
+
expect(typeof classHash).toBe('string');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
xtest('traceTransaction', async () => {
|
|
115
|
+
await rpcProvider.traceTransaction(transaction_hash);
|
|
116
|
+
});
|
|
27
117
|
});
|
|
28
118
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
119
|
+
describe('declare contract related tests', () => {
|
|
120
|
+
let class_hash;
|
|
121
|
+
|
|
122
|
+
beforeAll(async () => {
|
|
123
|
+
({ class_hash } = await rpcProvider.declareContract({
|
|
124
|
+
contract: compiledErc20,
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('getClass', async () => {
|
|
129
|
+
const contractClass = await rpcProvider.getClass(class_hash);
|
|
130
|
+
expect(contractClass).toHaveProperty('program');
|
|
131
|
+
expect(contractClass).toHaveProperty('entry_points_by_type');
|
|
34
132
|
});
|
|
35
|
-
await rpcProvider.waitForTransaction(transaction_hash);
|
|
36
|
-
expect(contract_address).toBeTruthy();
|
|
37
|
-
expect(transaction_hash).toBeTruthy();
|
|
38
133
|
});
|
|
39
134
|
|
|
40
135
|
test.todo('getEstimateFee');
|
|
@@ -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
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
3
|
import { constants, hash, json, number, stark } from '../../src';
|
|
4
|
+
import { Block } from '../../src/provider/utils';
|
|
4
5
|
import { pedersen } from '../../src/utils/hash';
|
|
5
6
|
|
|
6
7
|
const { IS_BROWSER } = constants;
|
|
@@ -112,3 +113,19 @@ describe('calculateContractAddressFromHash()', () => {
|
|
|
112
113
|
);
|
|
113
114
|
});
|
|
114
115
|
});
|
|
116
|
+
|
|
117
|
+
describe('new Block()', () => {
|
|
118
|
+
test('Block identifier and queryIdentifier', () => {
|
|
119
|
+
const blockA = new Block(0);
|
|
120
|
+
expect(blockA.identifier).toMatchObject({ block_number: 0 });
|
|
121
|
+
expect(blockA.queryIdentifier).toBe('blockNumber=0');
|
|
122
|
+
|
|
123
|
+
const blockB = new Block('latest');
|
|
124
|
+
expect(blockB.identifier).toBe('latest');
|
|
125
|
+
expect(blockB.queryIdentifier).toBe('blockNumber=latest');
|
|
126
|
+
|
|
127
|
+
const blockC = new Block('0x01');
|
|
128
|
+
expect(blockC.identifier).toMatchObject({ block_hash: '0x01' });
|
|
129
|
+
expect(blockC.queryIdentifier).toBe('blockHash=0x01');
|
|
130
|
+
});
|
|
131
|
+
});
|
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
|