starknet 4.6.0 → 4.8.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 +44 -0
- package/CONTRIBUTING.md +2 -2
- package/__mocks__/l1l2_compiled.json +10107 -0
- package/__tests__/account.test.ts +2 -5
- package/__tests__/contract.test.ts +0 -1
- package/__tests__/defaultProvider.test.ts +5 -3
- package/__tests__/fixtures.ts +2 -0
- package/__tests__/sequencerProvider.test.ts +50 -9
- package/__tests__/utils/ellipticalCurve.test.ts +7 -8
- package/__tests__/utils/merkle.test.ts +15 -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 +12 -10
- package/dist/provider/rpc.js +80 -72
- package/dist/provider/sequencer.d.ts +6 -4
- package/dist/provider/sequencer.js +36 -7
- 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 +36 -20
- package/dist/types/lib.d.ts +10 -4
- package/dist/types/provider.d.ts +7 -2
- package/dist/utils/hash.d.ts +8 -2
- package/dist/utils/hash.js +20 -5
- package/dist/utils/merkle.js +2 -1
- package/dist/utils/number.d.ts +5 -0
- package/dist/utils/number.js +29 -1
- package/dist/utils/responseParser/rpc.d.ts +2 -5
- package/dist/utils/responseParser/rpc.js +2 -38
- package/dist/utils/responseParser/sequencer.js +7 -19
- 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 +6 -4
- package/provider/sequencer.js +36 -7
- 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 +47 -11
- 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 +39 -20
- package/src/types/lib.ts +7 -5
- package/src/types/provider.ts +7 -2
- package/src/utils/hash.ts +32 -8
- package/src/utils/merkle.ts +2 -1
- package/src/utils/number.ts +27 -0
- package/src/utils/responseParser/rpc.ts +7 -25
- package/src/utils/responseParser/sequencer.ts +12 -7
- package/types/api/openrpc.d.ts +17 -27
- package/types/api/rpc.d.ts +4 -128
- package/types/api/sequencer.d.ts +36 -20
- package/types/lib.d.ts +10 -4
- package/types/provider.d.ts +7 -2
- package/utils/hash.d.ts +8 -2
- package/utils/hash.js +20 -5
- package/utils/merkle.js +2 -1
- package/utils/number.d.ts +5 -0
- package/utils/number.js +29 -1
- package/utils/responseParser/rpc.d.ts +2 -5
- package/utils/responseParser/rpc.js +2 -38
- package/utils/responseParser/sequencer.js +7 -19
- package/www/docs/API/account.md +3 -3
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/provider.md +20 -6
- package/www/docs/API/utils.md +2 -2
- package/www/guides/account.md +1 -1
package/src/types/api/openrpc.ts
CHANGED
|
@@ -8,26 +8,14 @@
|
|
|
8
8
|
* TypeScript Representation of OpenRpc protocol types
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* "type": "string",
|
|
13
|
-
* "title": "Field element",
|
|
14
|
-
* "$comment": "A field element, represented as a string of hex digits",
|
|
15
|
-
* "description": "A field element. Represented as up to 63 hex digits and leading 4 bits zeroed.",
|
|
16
|
-
* "pattern": "^0x0[a-fA-F0-9]{1,63}$"
|
|
17
|
-
*/
|
|
18
11
|
export type FELT = string;
|
|
19
12
|
export type ADDRESS = FELT;
|
|
20
|
-
/**
|
|
21
|
-
* "title": "An integer number in hex format (0x...)",
|
|
22
|
-
* "pattern": "^0x[a-fA-F0-9]+$"
|
|
23
|
-
*/
|
|
24
13
|
type NUM_AS_HEX = string;
|
|
25
14
|
type SIGNATURE = Array<FELT>;
|
|
26
15
|
type ETH_ADDRESS = string;
|
|
27
16
|
type BLOCK_NUMBER = number;
|
|
28
17
|
type BLOCK_HASH = FELT;
|
|
29
18
|
type TXN_HASH = FELT;
|
|
30
|
-
type CHAIN_ID = string;
|
|
31
19
|
type PROTOCOL_VERSION = string;
|
|
32
20
|
type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
33
21
|
type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
|
|
@@ -68,7 +56,6 @@ type PENDING_COMMON_RECEIPT_PROPERTIES = {
|
|
|
68
56
|
actual_fee: FELT;
|
|
69
57
|
};
|
|
70
58
|
type INVOKE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
|
|
71
|
-
// type L1_HANDLER_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
72
59
|
type DECLARE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
73
60
|
type DEPLOY_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
74
61
|
type PENDING_INVOKE_TXN_RECEIPT = PENDING_COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
|
|
@@ -98,18 +85,19 @@ type PENDING_BLOCK_WITH_TX_HASHES = BLOCK_BODY_WITH_TX_HASHES & {
|
|
|
98
85
|
sequencer_address: FELT;
|
|
99
86
|
parent_hash: BLOCK_HASH;
|
|
100
87
|
};
|
|
88
|
+
// transaction_hash, nonce, type optional because of pathfinder not implemented
|
|
101
89
|
type COMMON_TXN_PROPERTIES = {
|
|
102
|
-
transaction_hash
|
|
90
|
+
transaction_hash?: TXN_HASH;
|
|
103
91
|
max_fee: FELT;
|
|
104
92
|
version: NUM_AS_HEX;
|
|
105
93
|
signature: SIGNATURE;
|
|
106
|
-
nonce
|
|
107
|
-
type
|
|
94
|
+
nonce?: FELT;
|
|
95
|
+
type?: TXN_TYPE;
|
|
108
96
|
};
|
|
109
97
|
type FUNCTION_CALL = {
|
|
110
|
-
contract_address
|
|
111
|
-
entry_point_selector
|
|
112
|
-
calldata
|
|
98
|
+
contract_address?: ADDRESS;
|
|
99
|
+
entry_point_selector?: FELT;
|
|
100
|
+
calldata?: Array<FELT>;
|
|
113
101
|
};
|
|
114
102
|
type INVOKE_TXN = COMMON_TXN_PROPERTIES & FUNCTION_CALL;
|
|
115
103
|
type DECLARE_TXN = COMMON_TXN_PROPERTIES & {
|
|
@@ -138,6 +126,7 @@ type PENDING_BLOCK_WITH_TXS = BLOCK_BODY_WITH_TXS & {
|
|
|
138
126
|
sequencer_address: FELT;
|
|
139
127
|
parent_hash: BLOCK_HASH;
|
|
140
128
|
};
|
|
129
|
+
|
|
141
130
|
type CONTRACT_CLASS = {
|
|
142
131
|
program: string; // A base64 representation of the compressed program code
|
|
143
132
|
entry_points_by_type: {
|
|
@@ -234,6 +223,7 @@ type TRACE_ROOT = {
|
|
|
234
223
|
};
|
|
235
224
|
|
|
236
225
|
export namespace OPENRPC {
|
|
226
|
+
export type Nonce = FELT;
|
|
237
227
|
export type BlockWithTxHashes = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
|
|
238
228
|
export type BlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
|
|
239
229
|
export type StateUpdate = STATE_UPDATE;
|
|
@@ -248,7 +238,7 @@ export namespace OPENRPC {
|
|
|
248
238
|
block_hash: BLOCK_HASH;
|
|
249
239
|
block_number: BLOCK_NUMBER;
|
|
250
240
|
};
|
|
251
|
-
export type
|
|
241
|
+
export type CHAIN_ID = string;
|
|
252
242
|
export type PendingTransactions = Array<TXN>;
|
|
253
243
|
export type ProtocolVersion = PROTOCOL_VERSION;
|
|
254
244
|
export type SyncingStatus = false | SYNC_STATUS;
|
|
@@ -257,7 +247,6 @@ export namespace OPENRPC {
|
|
|
257
247
|
page_number: number;
|
|
258
248
|
is_last_page: boolean;
|
|
259
249
|
};
|
|
260
|
-
export type Nonce = FELT;
|
|
261
250
|
export type Trace = TRACE_ROOT;
|
|
262
251
|
export type Traces = Array<{
|
|
263
252
|
transaction_hash: FELT;
|
|
@@ -265,7 +254,7 @@ export namespace OPENRPC {
|
|
|
265
254
|
}>;
|
|
266
255
|
export type TransactionHash = TXN_HASH;
|
|
267
256
|
export type BlockHash = BLOCK_HASH;
|
|
268
|
-
export type EventFilter = EVENT_FILTER;
|
|
257
|
+
export type EventFilter = EVENT_FILTER & RESULT_PAGE_REQUEST;
|
|
269
258
|
export type InvokedTransaction = { transaction_hash: TXN_HASH };
|
|
270
259
|
export type DeclaredTransaction = { transaction_hash: TXN_HASH; class_hash: FELT };
|
|
271
260
|
export type DeployedTransaction = { transaction_hash: TXN_HASH; contract_address: FELT };
|
|
@@ -349,29 +338,35 @@ export namespace OPENRPC {
|
|
|
349
338
|
| Errors.INVALID_BLOCK_ID;
|
|
350
339
|
};
|
|
351
340
|
starknet_blockNumber: {
|
|
341
|
+
params: {};
|
|
352
342
|
result: BLOCK_NUMBER;
|
|
353
343
|
errors: Errors.NO_BLOCKS;
|
|
354
344
|
};
|
|
355
345
|
starknet_blockHashAndNumber: {
|
|
346
|
+
params: {};
|
|
356
347
|
result: BLOCK_HASH & BLOCK_NUMBER;
|
|
357
348
|
errors: Errors.NO_BLOCKS;
|
|
358
349
|
};
|
|
359
350
|
starknet_chainId: {
|
|
351
|
+
params: {};
|
|
360
352
|
result: CHAIN_ID;
|
|
361
353
|
};
|
|
362
354
|
starknet_pendingTransactions: {
|
|
355
|
+
params: {};
|
|
363
356
|
result: PendingTransactions;
|
|
364
357
|
};
|
|
365
358
|
starknet_syncing: {
|
|
359
|
+
params: {};
|
|
366
360
|
result: SyncingStatus;
|
|
367
361
|
};
|
|
368
362
|
starknet_getEvents: {
|
|
369
363
|
params: { filter: EVENT_FILTER & RESULT_PAGE_REQUEST };
|
|
370
|
-
result:
|
|
364
|
+
result: Events;
|
|
371
365
|
errors: Errors.PAGE_SIZE_TOO_BIG;
|
|
372
366
|
};
|
|
367
|
+
// FROM RPC 0.2.0 Pathfinder exception
|
|
373
368
|
starknet_getNonce: {
|
|
374
|
-
params: { contract_address: ADDRESS };
|
|
369
|
+
params: { contract_address: ADDRESS; block_id: BLOCK_ID };
|
|
375
370
|
result: FELT;
|
|
376
371
|
errors: Errors.CONTRACT_NOT_FOUND;
|
|
377
372
|
};
|
|
@@ -397,7 +392,7 @@ export namespace OPENRPC {
|
|
|
397
392
|
starknet_addDeployTransaction: {
|
|
398
393
|
params: {
|
|
399
394
|
contract_address_salt: FELT;
|
|
400
|
-
constructor_calldata: FELT
|
|
395
|
+
constructor_calldata: Array<FELT>;
|
|
401
396
|
contract_definition: CONTRACT_CLASS;
|
|
402
397
|
};
|
|
403
398
|
result: DeployedTransaction;
|
package/src/types/api/rpc.ts
CHANGED
|
@@ -11,9 +11,11 @@ export namespace RPC {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export type ChainId = OPENRPC.
|
|
14
|
+
export type ChainId = OPENRPC.CHAIN_ID;
|
|
15
|
+
export type CallResponse = OPENRPC.CallResponse;
|
|
15
16
|
export type ContractAddress = ADDRESS;
|
|
16
17
|
export type Felt = FELT;
|
|
18
|
+
export type Nonce = OPENRPC.Nonce;
|
|
17
19
|
export type ContractClass = OPENRPC.ContractClass;
|
|
18
20
|
export type StateUpdate = OPENRPC.StateUpdate;
|
|
19
21
|
export type Transaction = OPENRPC.Transaction;
|
|
@@ -40,131 +42,5 @@ export namespace RPC {
|
|
|
40
42
|
export type DeclaredTransaction = OPENRPC.DeclaredTransaction;
|
|
41
43
|
export type DeployedTransaction = OPENRPC.DeployedTransaction;
|
|
42
44
|
|
|
43
|
-
export type Methods =
|
|
44
|
-
starknet_pendingTransactions: {
|
|
45
|
-
QUERY: never;
|
|
46
|
-
REQUEST: any[];
|
|
47
|
-
RESPONSE: PendingTransactions;
|
|
48
|
-
};
|
|
49
|
-
starknet_blockHashAndNumber: {
|
|
50
|
-
QUERY: never;
|
|
51
|
-
REQUEST: any[];
|
|
52
|
-
RESPONSE: BlockHashAndNumber;
|
|
53
|
-
};
|
|
54
|
-
starknet_getClassHashAt: {
|
|
55
|
-
QUERY: never;
|
|
56
|
-
REQUEST: any[];
|
|
57
|
-
RESPONSE: Felt;
|
|
58
|
-
};
|
|
59
|
-
starknet_getStateUpdate: {
|
|
60
|
-
QUERY: never;
|
|
61
|
-
REQUEST: any[];
|
|
62
|
-
RESPONSE: OPENRPC.StateUpdate;
|
|
63
|
-
};
|
|
64
|
-
starknet_getClass: {
|
|
65
|
-
QUERY: never;
|
|
66
|
-
REQUEST: any[];
|
|
67
|
-
RESPONSE: OPENRPC.ContractClass;
|
|
68
|
-
};
|
|
69
|
-
starknet_getBlockWithTxHashes: {
|
|
70
|
-
QUERY: never;
|
|
71
|
-
REQUEST: any[];
|
|
72
|
-
RESPONSE: GetBlockWithTxHashesResponse;
|
|
73
|
-
};
|
|
74
|
-
starknet_getBlockWithTxs: {
|
|
75
|
-
QUERY: never;
|
|
76
|
-
REQUEST: any[];
|
|
77
|
-
RESPONSE: GetBlockWithTxs;
|
|
78
|
-
};
|
|
79
|
-
starknet_getNonce: {
|
|
80
|
-
QUERY: never;
|
|
81
|
-
REQUEST: any[];
|
|
82
|
-
RESPONSE: OPENRPC.Nonce;
|
|
83
|
-
};
|
|
84
|
-
starknet_getStorageAt: {
|
|
85
|
-
QUERY: never;
|
|
86
|
-
REQUEST: any[];
|
|
87
|
-
RESPONSE: GetStorageAtResponse;
|
|
88
|
-
};
|
|
89
|
-
starknet_getTransactionByHash: {
|
|
90
|
-
QUERY: never;
|
|
91
|
-
REQUEST: any[];
|
|
92
|
-
RESPONSE: GetTransactionByHashResponse;
|
|
93
|
-
};
|
|
94
|
-
starknet_getTransactionByBlockIdAndIndex: {
|
|
95
|
-
QUERY: never;
|
|
96
|
-
REQUEST: any[];
|
|
97
|
-
RESPONSE: GetTransactionByBlockIdAndIndex;
|
|
98
|
-
};
|
|
99
|
-
starknet_getTransactionReceipt: {
|
|
100
|
-
QUERY: never;
|
|
101
|
-
REQUEST: any[];
|
|
102
|
-
RESPONSE: TransactionReceipt;
|
|
103
|
-
};
|
|
104
|
-
starknet_getBlockTransactionCount: {
|
|
105
|
-
QUERY: never;
|
|
106
|
-
REQUEST: any[];
|
|
107
|
-
RESPONSE: GetTransactionCountResponse;
|
|
108
|
-
};
|
|
109
|
-
starknet_call: {
|
|
110
|
-
QUERY: never;
|
|
111
|
-
REQUEST: any[];
|
|
112
|
-
RESPONSE: string[];
|
|
113
|
-
};
|
|
114
|
-
starknet_estimateFee: {
|
|
115
|
-
QUERY: never;
|
|
116
|
-
REQUEST: any[];
|
|
117
|
-
RESPONSE: OPENRPC.EstimatedFee;
|
|
118
|
-
};
|
|
119
|
-
starknet_blockNumber: {
|
|
120
|
-
QUERY: never;
|
|
121
|
-
REQUEST: any[];
|
|
122
|
-
RESPONSE: GetBlockNumberResponse;
|
|
123
|
-
};
|
|
124
|
-
starknet_chainId: {
|
|
125
|
-
QUERY: never;
|
|
126
|
-
REQUEST: any[];
|
|
127
|
-
RESPONSE: OPENRPC.ChainId;
|
|
128
|
-
};
|
|
129
|
-
starknet_syncing: {
|
|
130
|
-
QUERY: never;
|
|
131
|
-
REQUEST: any[];
|
|
132
|
-
RESPONSE: GetSyncingStatsResponse;
|
|
133
|
-
};
|
|
134
|
-
starknet_getEvents: {
|
|
135
|
-
QUERY: never;
|
|
136
|
-
REQUEST: any[];
|
|
137
|
-
RESPONSE: GetEventsResponse;
|
|
138
|
-
};
|
|
139
|
-
starknet_addInvokeTransaction: {
|
|
140
|
-
QUERY: never;
|
|
141
|
-
REQUEST: any[];
|
|
142
|
-
RESPONSE: OPENRPC.InvokedTransaction;
|
|
143
|
-
};
|
|
144
|
-
starknet_addDeployTransaction: {
|
|
145
|
-
QUERY: never;
|
|
146
|
-
REQUEST: any[];
|
|
147
|
-
RESPONSE: OPENRPC.DeployedTransaction;
|
|
148
|
-
};
|
|
149
|
-
starknet_addDeclareTransaction: {
|
|
150
|
-
QUERY: never;
|
|
151
|
-
REQUEST: any[];
|
|
152
|
-
RESPONSE: OPENRPC.DeclaredTransaction;
|
|
153
|
-
};
|
|
154
|
-
starknet_getClassAt: {
|
|
155
|
-
QUERY: never;
|
|
156
|
-
REQUEST: any[];
|
|
157
|
-
RESPONSE: any;
|
|
158
|
-
};
|
|
159
|
-
starknet_traceTransaction: {
|
|
160
|
-
QUERY: never;
|
|
161
|
-
REQUEST: any[];
|
|
162
|
-
RESPONSE: any;
|
|
163
|
-
};
|
|
164
|
-
starknet_traceBlockTransactions: {
|
|
165
|
-
QUERY: never;
|
|
166
|
-
REQUEST: any[];
|
|
167
|
-
RESPONSE: any;
|
|
168
|
-
};
|
|
169
|
-
};
|
|
45
|
+
export type Methods = OPENRPC.Methods;
|
|
170
46
|
}
|
|
@@ -27,15 +27,17 @@ export type GetContractAddressesResponse = {
|
|
|
27
27
|
GpsStatementVerifier: string;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export type
|
|
30
|
+
export type FunctionInvocation = {
|
|
31
31
|
caller_address: string;
|
|
32
32
|
contract_address: string;
|
|
33
|
-
code_address: string;
|
|
34
|
-
selector: string;
|
|
35
33
|
calldata: RawCalldata;
|
|
34
|
+
call_type?: string;
|
|
35
|
+
class_hash?: string;
|
|
36
|
+
selector?: string;
|
|
37
|
+
entry_point_type?: EntryPointType;
|
|
36
38
|
result: Array<any>;
|
|
37
39
|
execution_resources: ExecutionResources;
|
|
38
|
-
|
|
40
|
+
internal_calls: Array<FunctionInvocation>;
|
|
39
41
|
events: Array<any>;
|
|
40
42
|
messages: Array<any>;
|
|
41
43
|
};
|
|
@@ -54,18 +56,9 @@ export type ExecutionResources = {
|
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
export type GetTransactionTraceResponse = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
code_address: string;
|
|
61
|
-
selector: string;
|
|
62
|
-
calldata: RawArgs;
|
|
63
|
-
result: Array<any>;
|
|
64
|
-
execution_resources: ExecutionResources;
|
|
65
|
-
internal_call: Array<any>;
|
|
66
|
-
events: Array<any>;
|
|
67
|
-
messages: Array<any>;
|
|
68
|
-
};
|
|
59
|
+
validate_invocation?: FunctionInvocation;
|
|
60
|
+
function_invocation?: FunctionInvocation;
|
|
61
|
+
fee_transfer_invocation?: FunctionInvocation;
|
|
69
62
|
signature: Signature;
|
|
70
63
|
};
|
|
71
64
|
|
|
@@ -73,6 +66,13 @@ export type RawArgs = {
|
|
|
73
66
|
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
74
67
|
};
|
|
75
68
|
|
|
69
|
+
export type CallL1Handler = {
|
|
70
|
+
from_address: string;
|
|
71
|
+
to_address: string;
|
|
72
|
+
entry_point_selector: string;
|
|
73
|
+
payload: Array<string>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
76
|
export namespace Sequencer {
|
|
77
77
|
export type DeclareTransaction = {
|
|
78
78
|
type: 'DECLARE';
|
|
@@ -95,9 +95,8 @@ export namespace Sequencer {
|
|
|
95
95
|
contract_address: string;
|
|
96
96
|
signature?: Signature;
|
|
97
97
|
entry_point_type?: EntryPointType;
|
|
98
|
-
entry_point_selector: string;
|
|
99
98
|
calldata?: RawCalldata;
|
|
100
|
-
nonce
|
|
99
|
+
nonce: BigNumberish;
|
|
101
100
|
max_fee?: BigNumberish;
|
|
102
101
|
version?: BigNumberish;
|
|
103
102
|
};
|
|
@@ -118,6 +117,7 @@ export namespace Sequencer {
|
|
|
118
117
|
|
|
119
118
|
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
120
119
|
transaction_hash: string;
|
|
120
|
+
entry_point_selector: string;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export type TransactionResponse =
|
|
@@ -197,17 +197,23 @@ export namespace Sequencer {
|
|
|
197
197
|
status: Status;
|
|
198
198
|
gas_price: string;
|
|
199
199
|
sequencer_address: string;
|
|
200
|
+
starknet_version: string;
|
|
200
201
|
};
|
|
201
202
|
|
|
202
203
|
export type CallContractTransaction = Omit<
|
|
203
204
|
InvokeFunctionTransaction,
|
|
204
205
|
'type' | 'entry_point_type' | 'nonce'
|
|
205
|
-
|
|
206
|
+
> & { entry_point_selector: string };
|
|
206
207
|
|
|
207
208
|
export type CallContractResponse = {
|
|
208
209
|
result: string[];
|
|
209
210
|
};
|
|
210
211
|
|
|
212
|
+
export type EstimateFeeTransaction = Omit<
|
|
213
|
+
InvokeFunctionTransaction,
|
|
214
|
+
'max_fee' | 'entry_point_type'
|
|
215
|
+
>;
|
|
216
|
+
|
|
211
217
|
// Support 0.9.1 changes in a backward-compatible way
|
|
212
218
|
export type EstimateFeeResponse =
|
|
213
219
|
| {
|
|
@@ -259,6 +265,14 @@ export namespace Sequencer {
|
|
|
259
265
|
REQUEST: never;
|
|
260
266
|
RESPONSE: TransactionReceiptResponse;
|
|
261
267
|
};
|
|
268
|
+
get_nonce: {
|
|
269
|
+
QUERY: {
|
|
270
|
+
contractAddress: string;
|
|
271
|
+
blockIdentifier: BlockIdentifier;
|
|
272
|
+
};
|
|
273
|
+
REQUEST: never;
|
|
274
|
+
RESPONSE: BigNumberish;
|
|
275
|
+
};
|
|
262
276
|
get_storage_at: {
|
|
263
277
|
QUERY: {
|
|
264
278
|
contractAddress: string;
|
|
@@ -294,7 +308,7 @@ export namespace Sequencer {
|
|
|
294
308
|
QUERY: {
|
|
295
309
|
blockIdentifier: BlockIdentifier;
|
|
296
310
|
};
|
|
297
|
-
REQUEST:
|
|
311
|
+
REQUEST: EstimateFeeTransaction;
|
|
298
312
|
RESPONSE: EstimateFeeResponse;
|
|
299
313
|
};
|
|
300
314
|
get_class_by_hash: {
|
|
@@ -327,5 +341,10 @@ export namespace Sequencer {
|
|
|
327
341
|
REQUEST: never;
|
|
328
342
|
RESPONSE: any;
|
|
329
343
|
};
|
|
344
|
+
estimate_message_fee: {
|
|
345
|
+
QUERY: any;
|
|
346
|
+
REQUEST: any;
|
|
347
|
+
RESPONSE: EstimateFeeResponse;
|
|
348
|
+
};
|
|
330
349
|
};
|
|
331
350
|
}
|
package/src/types/lib.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type RawCalldata = BigNumberish[];
|
|
|
9
9
|
export type DeployContractPayload = {
|
|
10
10
|
contract: CompiledContract | string;
|
|
11
11
|
constructorCalldata?: RawCalldata;
|
|
12
|
-
addressSalt?:
|
|
12
|
+
addressSalt?: string;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export type DeclareContractPayload = {
|
|
@@ -17,14 +17,14 @@ export type DeclareContractPayload = {
|
|
|
17
17
|
version?: BigNumberish;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type
|
|
20
|
+
export type CallDetails = {
|
|
21
21
|
contractAddress: string;
|
|
22
|
-
entrypoint: string;
|
|
23
22
|
calldata?: RawCalldata;
|
|
24
|
-
signature?: Signature;
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
export type
|
|
25
|
+
export type Invocation = CallDetails & { signature?: Signature };
|
|
26
|
+
|
|
27
|
+
export type Call = CallDetails & { entrypoint: string };
|
|
28
28
|
|
|
29
29
|
export type InvocationsDetails = {
|
|
30
30
|
nonce?: BigNumberish;
|
|
@@ -32,6 +32,8 @@ export type InvocationsDetails = {
|
|
|
32
32
|
version?: BigNumberish;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
export type InvocationsDetailsWithNonce = InvocationsDetails & { nonce: BigNumberish };
|
|
36
|
+
|
|
35
37
|
export type Status =
|
|
36
38
|
| 'NOT_RECEIVED'
|
|
37
39
|
| 'RECEIVED'
|
package/src/types/provider.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { RPC } from './api/rpc';
|
|
8
|
+
import { Abi, CompressedProgram, RawCalldata, Signature, Status } from './lib';
|
|
8
9
|
|
|
9
10
|
export interface GetBlockResponse {
|
|
10
11
|
timestamp: number;
|
|
@@ -14,6 +15,10 @@ export interface GetBlockResponse {
|
|
|
14
15
|
parent_hash: string;
|
|
15
16
|
status: Status;
|
|
16
17
|
transactions: Array<string>;
|
|
18
|
+
gas_price?: string;
|
|
19
|
+
sequencer_address?: string;
|
|
20
|
+
starknet_version?: string;
|
|
21
|
+
transaction_receipts?: any;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
export interface GetCodeResponse {
|
|
@@ -44,7 +49,7 @@ export interface ContractEntryPoint {
|
|
|
44
49
|
|
|
45
50
|
export interface ContractClass {
|
|
46
51
|
program: CompressedProgram;
|
|
47
|
-
entry_points_by_type:
|
|
52
|
+
entry_points_by_type: RPC.ContractClass['entry_points_by_type'];
|
|
48
53
|
abi?: Abi;
|
|
49
54
|
}
|
|
50
55
|
|
package/src/utils/hash.ts
CHANGED
|
@@ -15,9 +15,17 @@ import {
|
|
|
15
15
|
import { RawCalldata } from '../types/lib';
|
|
16
16
|
import { ec } from './ellipticCurve';
|
|
17
17
|
import { addHexPrefix, buf2hex, removeHexPrefix, utf8ToArray } from './encode';
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import {
|
|
19
|
+
BigNumberish,
|
|
20
|
+
isHex,
|
|
21
|
+
isStringWholeNumber,
|
|
22
|
+
toBN,
|
|
23
|
+
toFelt,
|
|
24
|
+
toHex,
|
|
25
|
+
toHexString,
|
|
26
|
+
} from './number';
|
|
27
|
+
|
|
28
|
+
export const transactionVersion = 1;
|
|
21
29
|
export const feeTransactionVersion = toBN(2).pow(toBN(128)).add(toBN(transactionVersion));
|
|
22
30
|
|
|
23
31
|
export function keccakBn(value: BigNumberish): string {
|
|
@@ -53,6 +61,21 @@ export function getSelectorFromName(funcName: string) {
|
|
|
53
61
|
return toHex(starknetKeccak(funcName));
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Function to get hex selector from function name, decimal string or hex string
|
|
66
|
+
* @param value hex string | decimal string | string
|
|
67
|
+
* @returns Hex selector
|
|
68
|
+
*/
|
|
69
|
+
export function getSelector(value: string) {
|
|
70
|
+
if (isHex(value)) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
if (isStringWholeNumber(value)) {
|
|
74
|
+
return toHexString(value);
|
|
75
|
+
}
|
|
76
|
+
return getSelectorFromName(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
56
79
|
const constantPoints = CONSTANT_POINTS.map((coords: string[]) =>
|
|
57
80
|
ec.curve.point(coords[0], coords[1])
|
|
58
81
|
);
|
|
@@ -124,22 +147,23 @@ export function calculateDeployTransactionHash(
|
|
|
124
147
|
);
|
|
125
148
|
}
|
|
126
149
|
|
|
127
|
-
export function
|
|
150
|
+
export function calculateTransactionHash(
|
|
128
151
|
contractAddress: BigNumberish,
|
|
129
152
|
version: BigNumberish,
|
|
130
|
-
entryPointSelector: BigNumberish,
|
|
131
153
|
calldata: BigNumberish[],
|
|
132
154
|
maxFee: BigNumberish,
|
|
133
|
-
chainId: StarknetChainId
|
|
155
|
+
chainId: StarknetChainId,
|
|
156
|
+
nonce: BigNumberish
|
|
134
157
|
): string {
|
|
135
158
|
return calculateTransactionHashCommon(
|
|
136
159
|
TransactionHashPrefix.INVOKE,
|
|
137
160
|
version,
|
|
138
161
|
contractAddress,
|
|
139
|
-
|
|
162
|
+
0,
|
|
140
163
|
calldata,
|
|
141
164
|
maxFee,
|
|
142
|
-
chainId
|
|
165
|
+
chainId,
|
|
166
|
+
[nonce]
|
|
143
167
|
);
|
|
144
168
|
}
|
|
145
169
|
|
package/src/utils/merkle.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pedersen } from './hash';
|
|
2
|
+
import { toBN } from './number';
|
|
2
3
|
|
|
3
4
|
export class MerkleTree {
|
|
4
5
|
public leaves: string[];
|
|
@@ -31,7 +32,7 @@ export class MerkleTree {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
static hash(a: string, b: string) {
|
|
34
|
-
const [aSorted, bSorted] = [a, b].sort();
|
|
35
|
+
const [aSorted, bSorted] = [toBN(a), toBN(b)].sort((x: any, y: any) => (x.gte(y) ? 1 : -1));
|
|
35
36
|
return pedersen([aSorted, bSorted]);
|
|
36
37
|
}
|
|
37
38
|
|
package/src/utils/number.ts
CHANGED
|
@@ -61,3 +61,30 @@ export function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[
|
|
|
61
61
|
export function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[] {
|
|
62
62
|
return rawCalldata.map((x) => toHex(toBN(x)));
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
export const isStringWholeNumber = (value: string) => /^\d+$/.test(value);
|
|
66
|
+
export const toHexString = (value: string) => toHex(toBN(value));
|
|
67
|
+
|
|
68
|
+
export function getDecimalString(value: string) {
|
|
69
|
+
if (isHex(value)) {
|
|
70
|
+
return hexToDecimalString(value);
|
|
71
|
+
}
|
|
72
|
+
if (isStringWholeNumber(value)) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getHexString(value: string) {
|
|
79
|
+
if (isHex(value)) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if (isStringWholeNumber(value)) {
|
|
83
|
+
return toHexString(value);
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function getHexStringArray(value: Array<string>) {
|
|
89
|
+
return value.map((el) => getHexString(el));
|
|
90
|
+
}
|
|
@@ -4,13 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
6
|
CallContractResponse,
|
|
7
|
-
DeclareContractResponse,
|
|
8
|
-
DeployContractResponse,
|
|
9
7
|
EstimateFeeResponse,
|
|
10
8
|
GetBlockResponse,
|
|
11
9
|
GetTransactionReceiptResponse,
|
|
12
10
|
GetTransactionResponse,
|
|
13
|
-
InvokeFunctionResponse,
|
|
14
11
|
} from '../../types';
|
|
15
12
|
import { RPC } from '../../types/api';
|
|
16
13
|
import { toBN } from '../number';
|
|
@@ -28,7 +25,13 @@ type TransactionReceipt = RPC.TransactionReceipt & {
|
|
|
28
25
|
[key: string]: any;
|
|
29
26
|
};
|
|
30
27
|
|
|
31
|
-
export class RPCResponseParser
|
|
28
|
+
export class RPCResponseParser
|
|
29
|
+
implements
|
|
30
|
+
Omit<
|
|
31
|
+
ResponseParser,
|
|
32
|
+
'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse'
|
|
33
|
+
>
|
|
34
|
+
{
|
|
32
35
|
public parseGetBlockResponse(res: RpcGetBlockResponse): GetBlockResponse {
|
|
33
36
|
return {
|
|
34
37
|
timestamp: res.timestamp,
|
|
@@ -45,7 +48,6 @@ export class RPCResponseParser extends ResponseParser {
|
|
|
45
48
|
return {
|
|
46
49
|
calldata: res.calldata || [],
|
|
47
50
|
contract_address: res.contract_address,
|
|
48
|
-
entry_point_selector: res.entry_point_selector,
|
|
49
51
|
max_fee: res.max_fee,
|
|
50
52
|
nonce: res.nonce,
|
|
51
53
|
signature: res.signature || [],
|
|
@@ -81,24 +83,4 @@ export class RPCResponseParser extends ResponseParser {
|
|
|
81
83
|
result: res,
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
public parseInvokeFunctionResponse(res: RPC.InvokedTransaction): InvokeFunctionResponse {
|
|
86
|
-
return {
|
|
87
|
-
transaction_hash: res.transaction_hash,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public parseDeployContractResponse(res: RPC.DeployedTransaction): DeployContractResponse {
|
|
92
|
-
return {
|
|
93
|
-
transaction_hash: res.transaction_hash,
|
|
94
|
-
contract_address: res.contract_address,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public parseDeclareContractResponse(res: RPC.DeclaredTransaction): DeclareContractResponse {
|
|
99
|
-
return {
|
|
100
|
-
transaction_hash: res.transaction_hash,
|
|
101
|
-
class_hash: res.class_hash,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
86
|
}
|