starknet 4.2.0 → 4.4.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/__mocks__/typedDataSessionExample.json +42 -0
- package/__tests__/defaultProvider.test.ts +11 -24
- package/__tests__/rpcProvider.test.ts +3 -3
- package/__tests__/sequencerProvider.test.ts +40 -2
- package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +2 -0
- package/__tests__/utils/ellipticalCurve.test.ts +5 -0
- package/__tests__/utils/merkle.test.ts +146 -0
- package/__tests__/utils/typedData.test.ts +107 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/provider/default.d.ts +2 -2
- package/dist/provider/default.js +3 -3
- package/dist/provider/interface.d.ts +6 -3
- package/dist/provider/rpc.d.ts +9 -4
- package/dist/provider/rpc.js +67 -25
- package/dist/provider/sequencer.d.ts +2 -2
- package/dist/provider/sequencer.js +9 -9
- package/dist/provider/utils.d.ts +12 -0
- package/dist/provider/utils.js +17 -1
- package/dist/signer/default.d.ts +1 -1
- package/dist/signer/default.js +1 -0
- package/dist/types/api/openrpc.d.ts +151 -0
- package/dist/types/api/openrpc.js +9 -0
- package/dist/types/api/rpc.d.ts +22 -43
- package/dist/types/provider.d.ts +5 -5
- package/dist/utils/ellipticCurve.d.ts +13 -0
- package/dist/utils/ellipticCurve.js +20 -16
- package/dist/utils/hash.js +8 -6
- package/dist/utils/merkle.d.ts +10 -0
- package/dist/utils/merkle.js +90 -0
- package/dist/utils/number.js +1 -1
- package/dist/utils/responseParser/rpc.d.ts +13 -3
- package/dist/utils/responseParser/rpc.js +2 -10
- package/dist/utils/responseParser/sequencer.d.ts +4 -1
- package/dist/utils/responseParser/sequencer.js +1 -7
- package/dist/utils/typedData/index.d.ts +23 -8
- package/dist/utils/typedData/index.js +70 -31
- package/dist/utils/typedData/types.d.ts +8 -3
- package/dist/utils/url.d.ts +7 -0
- package/dist/utils/url.js +49 -0
- package/index.d.ts +2 -0
- package/index.js +3 -1
- package/package.json +1 -1
- package/provider/default.d.ts +2 -2
- package/provider/default.js +3 -3
- package/provider/interface.d.ts +6 -3
- package/provider/rpc.d.ts +9 -4
- package/provider/rpc.js +67 -25
- package/provider/sequencer.d.ts +2 -2
- package/provider/sequencer.js +9 -9
- package/provider/utils.d.ts +12 -0
- package/provider/utils.js +17 -1
- package/signer/default.d.ts +1 -1
- package/signer/default.js +1 -0
- package/src/index.ts +2 -0
- package/src/provider/default.ts +2 -3
- package/src/provider/interface.ts +5 -3
- package/src/provider/rpc.ts +56 -34
- package/src/provider/sequencer.ts +11 -9
- package/src/provider/utils.ts +22 -1
- package/src/signer/default.ts +2 -2
- package/src/types/api/openrpc.ts +168 -0
- package/src/types/api/rpc.ts +22 -45
- package/src/types/provider.ts +5 -5
- package/src/utils/ellipticCurve.ts +20 -16
- package/src/utils/hash.ts +8 -6
- package/src/utils/merkle.ts +70 -0
- package/src/utils/number.ts +1 -1
- package/src/utils/responseParser/rpc.ts +16 -13
- package/src/utils/responseParser/sequencer.ts +5 -8
- package/src/utils/typedData/index.ts +88 -34
- package/src/utils/typedData/types.ts +12 -4
- package/src/utils/url.ts +53 -0
- package/types/api/openrpc.d.ts +151 -0
- package/types/api/openrpc.js +9 -0
- package/types/api/rpc.d.ts +22 -43
- package/types/provider.d.ts +5 -5
- package/utils/ellipticCurve.d.ts +13 -0
- package/utils/ellipticCurve.js +20 -16
- package/utils/hash.js +8 -6
- package/utils/merkle.d.ts +10 -0
- package/utils/merkle.js +90 -0
- package/utils/number.js +1 -1
- package/utils/responseParser/rpc.d.ts +13 -3
- package/utils/responseParser/rpc.js +2 -10
- package/utils/responseParser/sequencer.d.ts +4 -1
- package/utils/responseParser/sequencer.js +1 -7
- package/utils/typedData/index.d.ts +23 -8
- package/utils/typedData/index.js +70 -31
- package/utils/typedData/types.d.ts +8 -3
- package/utils/url.d.ts +7 -0
- package/utils/url.js +49 -0
- package/www/docs/API/account.md +20 -18
- package/www/docs/API/contract.md +10 -10
- package/www/docs/API/contractFactory.md +14 -11
- package/www/docs/API/provider.md +60 -37
- package/www/docs/API/signer.md +8 -10
- package/www/docs/API/utils.md +151 -74
- package/www/guides/account.md +12 -12
- package/www/guides/erc20.md +19 -4
- package/www/guides/intro.md +3 -1
package/www/docs/API/provider.md
CHANGED
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
|
4
4
|
|
|
5
5
|
# Provider
|
|
6
6
|
|
|
7
|
-
The **Provider** API allows you to
|
|
7
|
+
The **Provider** API allows you to interact with the StarkNet network, without signing transactions or messages.
|
|
8
8
|
|
|
9
9
|
Typically, these are _read_ calls on the blockchain.
|
|
10
10
|
|
|
@@ -12,14 +12,32 @@ Typically, these are _read_ calls on the blockchain.
|
|
|
12
12
|
|
|
13
13
|
`new starknet.Provider(optionsOrProvider)`
|
|
14
14
|
|
|
15
|
-
The options for the provider
|
|
15
|
+
The options for the provider depend on the network. The structure of the options object is:
|
|
16
16
|
|
|
17
17
|
- options.**sequencer** - Options for sequencer provider
|
|
18
18
|
- options.**rpc** - Options for RPC provider
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
The easiest way to get started is:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
const provider = new starknet.Provider()
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The above snippet creates a Starknet Provider instance with `goerli-alpha` network.
|
|
21
27
|
|
|
28
|
+
However, if you want to use `mainnet-alpha` or explicitly declare the network, you can use:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const provider = new starknet.Provider({
|
|
32
|
+
sequencer: {
|
|
33
|
+
network: 'mainnet-alpha' // or 'goerli-alpha'
|
|
34
|
+
}
|
|
35
|
+
})
|
|
22
36
|
```
|
|
37
|
+
|
|
38
|
+
If you want more control:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
23
41
|
const provider = new starknet.Provider({
|
|
24
42
|
sequencer: {
|
|
25
43
|
baseUrl: 'https://alpha4.starknet.io',
|
|
@@ -29,7 +47,11 @@ const provider = new starknet.Provider({
|
|
|
29
47
|
})
|
|
30
48
|
```
|
|
31
49
|
|
|
32
|
-
|
|
50
|
+
These are also the default options for the Provider constructor with `network: 'goerli-alpha'`.
|
|
51
|
+
|
|
52
|
+
> **Note**
|
|
53
|
+
>
|
|
54
|
+
> `network` arguement should work in most cases. If you want to use the `sequencer` arguement with `baseUrl`, you will not be able to use the `network` field in the object.
|
|
33
55
|
|
|
34
56
|
## Methods
|
|
35
57
|
|
|
@@ -43,13 +65,13 @@ The call object structure:
|
|
|
43
65
|
|
|
44
66
|
- call.**contractAddress** - Address of the contract
|
|
45
67
|
- call.**entrypoint** - Entrypoint of the call (method name)
|
|
46
|
-
- call.**calldata** - Payload for the invoking
|
|
68
|
+
- call.**calldata** - Payload for the invoking method
|
|
47
69
|
|
|
48
|
-
######
|
|
70
|
+
###### _CallContractResponse_
|
|
49
71
|
|
|
50
|
-
```
|
|
72
|
+
```typescript
|
|
51
73
|
{
|
|
52
|
-
|
|
74
|
+
result: string[];
|
|
53
75
|
}
|
|
54
76
|
```
|
|
55
77
|
|
|
@@ -61,7 +83,7 @@ Gets the block information.
|
|
|
61
83
|
|
|
62
84
|
###### _GetBlockResponse_
|
|
63
85
|
|
|
64
|
-
```
|
|
86
|
+
```typescript
|
|
65
87
|
{
|
|
66
88
|
accepted_time: number;
|
|
67
89
|
block_hash: string;
|
|
@@ -85,7 +107,7 @@ Gets the contract class of the deployed contract.
|
|
|
85
107
|
|
|
86
108
|
###### _ContractClass_
|
|
87
109
|
|
|
88
|
-
```
|
|
110
|
+
```typescript
|
|
89
111
|
{
|
|
90
112
|
program: CompressedProgram;
|
|
91
113
|
entry_points_by_type: EntryPointsByType;
|
|
@@ -95,9 +117,9 @@ Gets the contract class of the deployed contract.
|
|
|
95
117
|
|
|
96
118
|
<hr/>
|
|
97
119
|
|
|
98
|
-
provider.**getStorageAt**(contractAddress, key,
|
|
120
|
+
provider.**getStorageAt**(contractAddress, key, blockIdentifier) => _Promise < string >_
|
|
99
121
|
|
|
100
|
-
Gets the contract's storage variable at a specific key
|
|
122
|
+
Gets the contract's storage variable at a specific key.
|
|
101
123
|
|
|
102
124
|
<hr/>
|
|
103
125
|
|
|
@@ -107,7 +129,7 @@ Gets the status of a transaction.
|
|
|
107
129
|
|
|
108
130
|
###### _GetTransactionReceiptResponse_
|
|
109
131
|
|
|
110
|
-
```
|
|
132
|
+
```typescript
|
|
111
133
|
{
|
|
112
134
|
transaction_hash: string;
|
|
113
135
|
status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
@@ -127,7 +149,7 @@ Gets the transaction information from a tx hash.
|
|
|
127
149
|
|
|
128
150
|
###### _GetTransactionResponse_
|
|
129
151
|
|
|
130
|
-
```
|
|
152
|
+
```typescript
|
|
131
153
|
{
|
|
132
154
|
transaction_hash: string;
|
|
133
155
|
version?: string;
|
|
@@ -146,27 +168,26 @@ Gets the transaction information from a tx hash.
|
|
|
146
168
|
|
|
147
169
|
provider.**declareContract**(payload) => _Promise < DeclareContractResponse >_
|
|
148
170
|
|
|
149
|
-
Declares a contract on Starknet
|
|
171
|
+
Declares a contract on Starknet.
|
|
150
172
|
|
|
151
173
|
###### _DeclareContractResponse_
|
|
152
174
|
|
|
153
|
-
```
|
|
175
|
+
```typescript
|
|
154
176
|
{
|
|
155
177
|
transaction_hash: string;
|
|
156
178
|
class_hash: string;
|
|
157
179
|
};
|
|
180
|
+
```
|
|
158
181
|
|
|
159
182
|
<hr/>
|
|
160
183
|
|
|
161
|
-
```
|
|
162
|
-
|
|
163
184
|
provider.**deployContract**(payload [ , abi ]) => _Promise < DeployContractResponse >_
|
|
164
185
|
|
|
165
|
-
Deploys a contract on Starknet
|
|
186
|
+
Deploys a contract on Starknet.
|
|
166
187
|
|
|
167
188
|
###### _DeployContractResponse_
|
|
168
189
|
|
|
169
|
-
```
|
|
190
|
+
```typescript
|
|
170
191
|
{
|
|
171
192
|
transaction_hash: string;
|
|
172
193
|
contract_address?: string;
|
|
@@ -185,7 +206,7 @@ Wait for the transaction to be accepted on L2 or L1.
|
|
|
185
206
|
|
|
186
207
|
`new starknet.SequencerProvider(optionsOrProvider)`
|
|
187
208
|
|
|
188
|
-
The options for the provider
|
|
209
|
+
The options for the provider depend on the network. The structure of the options object is:
|
|
189
210
|
|
|
190
211
|
- options.**baseUrl** - Base URL of the network
|
|
191
212
|
- options.**feederGatewayUrl** - Feeder Gateway Endpoint of the network
|
|
@@ -193,11 +214,11 @@ The options for the provider depends from the network. The structure of the opti
|
|
|
193
214
|
|
|
194
215
|
or
|
|
195
216
|
|
|
196
|
-
- options.**network** -
|
|
217
|
+
- options.**network** - Either 'mainnet-alpha' or 'goerli-alpha'
|
|
197
218
|
|
|
198
219
|
Example:
|
|
199
220
|
|
|
200
|
-
```
|
|
221
|
+
```typescript
|
|
201
222
|
const provider = new starknet.Provider({
|
|
202
223
|
baseUrl: 'https://alpha4.starknet.io',
|
|
203
224
|
feederGatewayUrl: 'feeder_gateway',
|
|
@@ -207,11 +228,13 @@ const provider = new starknet.Provider({
|
|
|
207
228
|
|
|
208
229
|
## Methods
|
|
209
230
|
|
|
210
|
-
Gets the smart contract address on the network
|
|
231
|
+
Gets the smart contract address on the network.
|
|
211
232
|
|
|
212
233
|
provider.**getContractAddresses**() => _Promise < GetContractAddressesResponse >_
|
|
213
234
|
|
|
214
|
-
|
|
235
|
+
###### _GetContractAddressesResponse_
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
215
238
|
{
|
|
216
239
|
Starknet: string;
|
|
217
240
|
GpsStatementVerifier: string;
|
|
@@ -226,7 +249,7 @@ Gets the status of a transaction.
|
|
|
226
249
|
|
|
227
250
|
###### _GetTransactionStatusResponse_
|
|
228
251
|
|
|
229
|
-
```
|
|
252
|
+
```typescript
|
|
230
253
|
{
|
|
231
254
|
tx_status: 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
232
255
|
block_hash: string;
|
|
@@ -246,7 +269,7 @@ Gets the transaction trace from a tx hash.
|
|
|
246
269
|
|
|
247
270
|
###### _GetTransactionTraceResponse_
|
|
248
271
|
|
|
249
|
-
```
|
|
272
|
+
```typescript
|
|
250
273
|
{
|
|
251
274
|
function_invocation: {
|
|
252
275
|
caller_address: string;
|
|
@@ -254,7 +277,7 @@ Gets the transaction trace from a tx hash.
|
|
|
254
277
|
code_address: string;
|
|
255
278
|
selector: string;
|
|
256
279
|
calldata: {
|
|
257
|
-
|
|
280
|
+
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
258
281
|
};
|
|
259
282
|
result: Array<any>;
|
|
260
283
|
execution_resources: any;
|
|
@@ -276,7 +299,7 @@ Gets the transaction trace from a tx hash.
|
|
|
276
299
|
|
|
277
300
|
Example:
|
|
278
301
|
|
|
279
|
-
```
|
|
302
|
+
```typescript
|
|
280
303
|
const provider = new starknet.RpcProvider({
|
|
281
304
|
nodeUrl: 'URL_TO_STARKNET_RPC_NODE',
|
|
282
305
|
})
|
|
@@ -292,17 +315,17 @@ Gets the transaction count from a block.
|
|
|
292
315
|
|
|
293
316
|
provider.**getBlockNumber**() => _Promise < number >_
|
|
294
317
|
|
|
295
|
-
Gets the latest block number
|
|
318
|
+
Gets the latest block number.
|
|
296
319
|
|
|
297
320
|
<hr/>
|
|
298
321
|
|
|
299
322
|
provider.**getSyncingStats**() => _Promise < GetSyncingStatsResponse >_
|
|
300
323
|
|
|
301
|
-
Gets syncing status of the node
|
|
324
|
+
Gets syncing status of the node.
|
|
302
325
|
|
|
303
|
-
######
|
|
326
|
+
###### _GetSyncingStatsResponse_
|
|
304
327
|
|
|
305
|
-
```
|
|
328
|
+
```typescript
|
|
306
329
|
boolean |
|
|
307
330
|
{
|
|
308
331
|
starting_block_hash: string;
|
|
@@ -318,9 +341,9 @@ boolean |
|
|
|
318
341
|
|
|
319
342
|
provider.**getEvents**(eventFilter) => _Promise < GetEventsResponse >_
|
|
320
343
|
|
|
321
|
-
#####
|
|
344
|
+
##### _EventFilter_
|
|
322
345
|
|
|
323
|
-
```
|
|
346
|
+
```typescript
|
|
324
347
|
type EventFilter = {
|
|
325
348
|
fromBlock: string;
|
|
326
349
|
toBlock: string;
|
|
@@ -331,9 +354,9 @@ type EventFilter = {
|
|
|
331
354
|
};
|
|
332
355
|
```
|
|
333
356
|
|
|
334
|
-
######
|
|
357
|
+
###### _GetEventsResponse_
|
|
335
358
|
|
|
336
|
-
```
|
|
359
|
+
```typescript
|
|
337
360
|
{
|
|
338
361
|
events: StarknetEmittedEvent[];
|
|
339
362
|
page_number: number;
|
package/www/docs/API/signer.md
CHANGED
|
@@ -10,21 +10,21 @@ The **Signer** API allows you to sign transactions and messages, and also allows
|
|
|
10
10
|
|
|
11
11
|
`new starknet.Signer(keyPair)`
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Methods
|
|
14
14
|
|
|
15
15
|
signer.**getPubKey**() => _Promise < string >_
|
|
16
16
|
|
|
17
|
-
Returns public key of the signer
|
|
17
|
+
Returns the public key of the signer.
|
|
18
18
|
|
|
19
19
|
<hr />
|
|
20
20
|
|
|
21
21
|
signer.**signTransaction**(transactions, transactionsDetail [ , abi ]) => _Promise < Signature >_
|
|
22
22
|
|
|
23
|
-
Returns signature of the transaction
|
|
23
|
+
Returns the signature of the transaction.
|
|
24
24
|
|
|
25
|
-
######
|
|
25
|
+
###### _Signature_
|
|
26
26
|
|
|
27
|
-
```
|
|
27
|
+
```typescript
|
|
28
28
|
string[]
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -32,12 +32,10 @@ string[]
|
|
|
32
32
|
|
|
33
33
|
signer.**signMessage**(typedData, accountAddress) => _Promise < Signature >_
|
|
34
34
|
|
|
35
|
-
Returns signature of the transaction
|
|
35
|
+
Returns the signature of the transaction.
|
|
36
36
|
|
|
37
|
-
######
|
|
37
|
+
###### _Signature_
|
|
38
38
|
|
|
39
|
-
```
|
|
39
|
+
```typescript
|
|
40
40
|
string[]
|
|
41
41
|
```
|
|
42
|
-
|
|
43
|
-
<hr />
|
package/www/docs/API/utils.md
CHANGED
|
@@ -4,19 +4,21 @@ sidebar_position: 6
|
|
|
4
4
|
|
|
5
5
|
# Utils
|
|
6
6
|
|
|
7
|
-
Util functions are provided so you can use low level functions in your application.
|
|
7
|
+
Util functions are provided so you can use various low level functions in your application.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## **address**
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Helper functions for starknet addresses.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
import { address } from 'starknet.js';
|
|
15
|
-
```
|
|
13
|
+
### validateAndParseAddress
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
`validateAndParseAddress(address: BigNumberish): string`
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
Checks if the address is valid and, if it is, parses it to the correct format (0x prefix is added if not provided).
|
|
18
|
+
|
|
19
|
+
### getChecksumAddress
|
|
20
|
+
|
|
21
|
+
`getChecksumAddress(address: BigNumberish): string`
|
|
20
22
|
|
|
21
23
|
This function accepts an address as a `BigNumberish` and returns the checksummed address as a string.
|
|
22
24
|
An example:
|
|
@@ -31,47 +33,53 @@ const checksummedAddress = address.getChecksumAddress(addressToCheck);
|
|
|
31
33
|
console.log(checksummedAddress); // 0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
### validateChecksumAddress
|
|
37
|
+
|
|
38
|
+
`validateChecksumAddress(address: string): boolean`
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
This function validates the checksum address.
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
Returns true if the address is valid, false otherwise.
|
|
39
43
|
|
|
40
44
|
<hr />
|
|
41
45
|
|
|
42
|
-
##
|
|
46
|
+
## **stark**
|
|
43
47
|
|
|
44
48
|
Functions for stark specific manipulations.
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
### compressProgram
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
`compressProgram(jsonProgram: Program | string): CompressedProgram`
|
|
49
53
|
|
|
50
54
|
Function to compress compiled cairo program. Accepts a json file representing the compiled cairo program and returns a compressed cairo program.
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
### randomAddress
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
`randomAddress(): string`
|
|
55
59
|
|
|
56
|
-
Function that generates a random
|
|
60
|
+
Function that generates a random stark address.
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
### makeAddress
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
`makeAddress(input: string): string`
|
|
61
65
|
|
|
62
|
-
Function that turns an incompatible address string into stark address format.
|
|
66
|
+
Function that turns an incompatible address string into stark address format.
|
|
67
|
+
|
|
68
|
+
Returns a string.
|
|
63
69
|
|
|
64
70
|
Example: `0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5` -> `0xdfd0f27fce99b50909de0bdd328aed6eabe76bc5`
|
|
65
71
|
|
|
66
|
-
|
|
72
|
+
### formatSignature
|
|
73
|
+
|
|
74
|
+
`formatSignature(sig?: Signature): string[]`
|
|
67
75
|
|
|
68
|
-
|
|
76
|
+
Function that formats a Signature to BigNum and then to string array.
|
|
69
77
|
|
|
70
|
-
|
|
78
|
+
Returns a string array.
|
|
71
79
|
|
|
72
|
-
|
|
80
|
+
### compileCalldata
|
|
73
81
|
|
|
74
|
-
|
|
82
|
+
`compileCalldata(args: RawArgs): Calldata`
|
|
75
83
|
|
|
76
84
|
Function that creates calldata that gets sent to the contract.
|
|
77
85
|
|
|
@@ -86,9 +94,9 @@ await this.callContract({
|
|
|
86
94
|
});
|
|
87
95
|
```
|
|
88
96
|
|
|
89
|
-
|
|
97
|
+
### estimatedFeeToMaxFee
|
|
90
98
|
|
|
91
|
-
|
|
99
|
+
`estimatedFeeToMaxFee(estimatedFee: BigNumberish, overhead: number = 0.5): BN`
|
|
92
100
|
|
|
93
101
|
Function that calculates and returns maximum fee based on the previously estimated one.
|
|
94
102
|
|
|
@@ -96,7 +104,7 @@ Returns a BN.
|
|
|
96
104
|
|
|
97
105
|
<hr />
|
|
98
106
|
|
|
99
|
-
##
|
|
107
|
+
## **number**
|
|
100
108
|
|
|
101
109
|
Various number formatting functions.
|
|
102
110
|
|
|
@@ -106,47 +114,53 @@ Various number formatting functions.
|
|
|
106
114
|
export type BigNumberish = string | number | BN;
|
|
107
115
|
```
|
|
108
116
|
|
|
109
|
-
|
|
117
|
+
### isHex
|
|
110
118
|
|
|
111
|
-
|
|
119
|
+
`isHex(hex: string): boolean`
|
|
112
120
|
|
|
113
121
|
Check if number is in hex format.
|
|
114
122
|
|
|
115
|
-
|
|
123
|
+
### toBN
|
|
124
|
+
|
|
125
|
+
`toBN(number: BigNumberish, base?: number | 'hex'): BN`
|
|
116
126
|
|
|
117
|
-
|
|
127
|
+
Converts BigNumberish to BN.
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
Returns a BN.
|
|
130
|
+
|
|
131
|
+
### toHex
|
|
120
132
|
|
|
121
|
-
|
|
133
|
+
`toHex(number: BN): string`
|
|
122
134
|
|
|
123
|
-
|
|
135
|
+
Converts BN to hex.
|
|
124
136
|
|
|
125
|
-
|
|
137
|
+
Returns a string.
|
|
126
138
|
|
|
127
|
-
|
|
139
|
+
### hexToDecimalString
|
|
128
140
|
|
|
129
|
-
|
|
141
|
+
`hexToDecimalString(hex: string): string`
|
|
130
142
|
|
|
131
143
|
Converts hex string to decimal string.
|
|
132
144
|
|
|
133
|
-
|
|
145
|
+
### toFelt
|
|
146
|
+
|
|
147
|
+
`toFelt(num: BigNumberish): string`
|
|
134
148
|
|
|
135
|
-
|
|
149
|
+
Converts BN to Felt.
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
Returns a string.
|
|
138
152
|
|
|
139
|
-
|
|
153
|
+
### assertInRange
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
`assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName = '')`
|
|
142
156
|
|
|
143
157
|
Asserts input is equal to or greater then `lowerBound` and lower then `upperBound`. Assert message specifies inputName.
|
|
144
158
|
`input`, `lowerBound`, and `upperBound` should be of type BN.
|
|
145
159
|
`inputName` should be a string.
|
|
146
160
|
|
|
147
|
-
|
|
161
|
+
### bigNumberishArrayToDecimalStringArray
|
|
148
162
|
|
|
149
|
-
|
|
163
|
+
`bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[]`
|
|
150
164
|
|
|
151
165
|
Convert BigNumberish array to decimal array. Used for signature conversion.
|
|
152
166
|
|
|
@@ -164,7 +178,7 @@ const signature = await this.signer.signTransaction(transactions, signerDetails)
|
|
|
164
178
|
|
|
165
179
|
<hr />
|
|
166
180
|
|
|
167
|
-
##
|
|
181
|
+
## **uint256**
|
|
168
182
|
|
|
169
183
|
```js
|
|
170
184
|
// Represents an integer in the range [0, 2^256).
|
|
@@ -176,74 +190,81 @@ export interface Uint256 {
|
|
|
176
190
|
}
|
|
177
191
|
```
|
|
178
192
|
|
|
179
|
-
|
|
193
|
+
### uint256ToBN
|
|
180
194
|
|
|
181
|
-
|
|
195
|
+
`uint256ToBN(uint256: Uint256): BN`
|
|
182
196
|
|
|
183
197
|
Function to convert `Uint256` to `BN` (big number), which uses the `bn.js` library.
|
|
184
198
|
|
|
185
|
-
|
|
199
|
+
### isUint256
|
|
186
200
|
|
|
187
|
-
|
|
201
|
+
`isUint256(bn: BigNumberish): boolean`
|
|
188
202
|
|
|
189
203
|
Function to check if `BN` is smaller or equal to `2**256-1`.
|
|
190
204
|
|
|
191
|
-
|
|
205
|
+
### bnToUint256
|
|
192
206
|
|
|
193
|
-
|
|
207
|
+
`bnToUint256(bignumber: BigNumberish): Uint256`
|
|
194
208
|
|
|
195
209
|
Function to convert `BN` to `Uint256`.
|
|
196
210
|
|
|
197
211
|
<hr />
|
|
198
212
|
|
|
199
|
-
##
|
|
213
|
+
## **hash**
|
|
200
214
|
|
|
201
215
|
Various hashing helpers.
|
|
202
216
|
|
|
203
|
-
###
|
|
217
|
+
### starknetKeccak
|
|
218
|
+
|
|
219
|
+
`starknetKeccak(value: string): BN`
|
|
204
220
|
|
|
205
221
|
Function to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
|
|
206
|
-
nction to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
|
|
207
222
|
|
|
208
|
-
|
|
223
|
+
Returns starknet keccak hash as BigNumber.
|
|
224
|
+
|
|
225
|
+
### getSelectorFromName
|
|
226
|
+
|
|
227
|
+
`getSelectorFromName(funcName: string)`
|
|
209
228
|
|
|
210
|
-
|
|
229
|
+
Function to get the hex selector from a given function name.
|
|
211
230
|
|
|
212
|
-
|
|
231
|
+
Returns hex selector of given abi function name.
|
|
213
232
|
|
|
214
|
-
|
|
233
|
+
### pedersen
|
|
215
234
|
|
|
216
|
-
|
|
235
|
+
`pedersen(input: [BigNumberish, BigNumberish])`
|
|
217
236
|
|
|
218
|
-
|
|
237
|
+
Function to get the Pedersen hash for two arguments.
|
|
219
238
|
|
|
220
|
-
|
|
239
|
+
Returns a string.
|
|
221
240
|
|
|
222
|
-
###
|
|
241
|
+
### computeHashOnElements
|
|
223
242
|
|
|
224
|
-
|
|
243
|
+
`computeHashOnElements(data: BigNumberish[])`
|
|
225
244
|
|
|
226
|
-
Function to compute a Pedersen hash on a array of elements.
|
|
245
|
+
Function to compute a Pedersen hash on a array of elements.
|
|
227
246
|
|
|
228
|
-
|
|
247
|
+
Returns a string.
|
|
229
248
|
|
|
230
|
-
###
|
|
249
|
+
### calculateTransactionHashCommon
|
|
250
|
+
|
|
251
|
+
`calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish,contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId, additionalData: BigNumberish[] = []): string`
|
|
231
252
|
|
|
232
253
|
Calculates the transaction hash in the StarkNet network - a unique identifier of the transaction.
|
|
233
254
|
|
|
234
255
|
Called internally in `calculateDeployTransactionHash` and `calculcateTransactionHash`.
|
|
235
256
|
|
|
236
|
-
|
|
257
|
+
### calculateDeployTransactionHash
|
|
237
258
|
|
|
238
|
-
|
|
259
|
+
`calculateDeployTransactionHash(contractAddress: BigNumberish, constructorCalldata: BigNumberish[], version: BigNumberish, chainId: StarknetChainId): string`
|
|
239
260
|
|
|
240
261
|
Function that calculates the deployment transaction hash in the StarkNet network.
|
|
241
262
|
|
|
242
263
|
Internally calls `calculateTransactionHashCommon` with `TransactionHashPrefix.DEPLOY`.
|
|
243
264
|
|
|
244
|
-
|
|
265
|
+
### calculcateTransactionHash
|
|
245
266
|
|
|
246
|
-
|
|
267
|
+
`calculcateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, entryPointSelector: BigNumberish, calldata: BigNumberish[], maxFee: BigNumberish, chainId: StarknetChainId): string`
|
|
247
268
|
|
|
248
269
|
Function that internally calls `calculateTransactionHashCommon`, with `TransactionHashPrefix.INVOKE`.
|
|
249
270
|
|
|
@@ -258,8 +279,64 @@ const hashMsg = calculcateTransactionHash(
|
|
|
258
279
|
);
|
|
259
280
|
```
|
|
260
281
|
|
|
261
|
-
|
|
282
|
+
### calculateContractAddressFromHash
|
|
283
|
+
|
|
284
|
+
`calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawCalldata, deployerAddress: BigNumberish)`
|
|
285
|
+
|
|
286
|
+
Function that calculates contract address from hash.
|
|
287
|
+
|
|
288
|
+
Returns a string.
|
|
289
|
+
|
|
290
|
+
<hr />
|
|
291
|
+
|
|
292
|
+
## **ellipticCurve**
|
|
293
|
+
|
|
294
|
+
Wrapper around the javascript `elliptic` library with additional functionality.
|
|
295
|
+
|
|
296
|
+
### genKeyPair
|
|
297
|
+
|
|
298
|
+
`ec.genKeyPair()`
|
|
299
|
+
|
|
300
|
+
Generate a random key pair.
|
|
301
|
+
|
|
302
|
+
### getKeyPair
|
|
303
|
+
|
|
304
|
+
`getKeyPair(pk: BigNumberish): KeyPair`
|
|
305
|
+
|
|
306
|
+
Get a key pair from a private key.
|
|
307
|
+
|
|
308
|
+
### getStarkKey
|
|
309
|
+
|
|
310
|
+
`getStarkKey(keyPair: KeyPair): string`
|
|
311
|
+
|
|
312
|
+
Public key defined over a Stark-friendly elliptic curve that is different from the standard Ethereum elliptic curve
|
|
313
|
+
|
|
314
|
+
### getKeyPairFromPublicKey
|
|
315
|
+
|
|
316
|
+
`getKeyPairFromPublicKey(publicKey: BigNumberish): KeyPair`
|
|
317
|
+
|
|
318
|
+
Takes a public key and casts it into `elliptic` KeyPair format.
|
|
319
|
+
|
|
320
|
+
Returns keyPair with public key only, which can be used to verify signatures, but can't sign anything.
|
|
321
|
+
|
|
322
|
+
### sign
|
|
323
|
+
|
|
324
|
+
`sign(keyPair: KeyPair, msgHash: string): Signature`
|
|
325
|
+
|
|
326
|
+
Signs a message using the provided key.
|
|
327
|
+
|
|
328
|
+
keyPair should be an KeyPair with a valid private key.
|
|
329
|
+
|
|
330
|
+
Returns an Signature.
|
|
331
|
+
|
|
332
|
+
### verify
|
|
333
|
+
|
|
334
|
+
`verify(keyPair: KeyPair | KeyPair[], msgHash: string, sig: Signature): boolean`
|
|
335
|
+
|
|
336
|
+
Verifies a message using the provided key.
|
|
337
|
+
|
|
338
|
+
keyPair should be an KeyPair with a valid public key.
|
|
262
339
|
|
|
263
|
-
|
|
340
|
+
sig should be an Signature.
|
|
264
341
|
|
|
265
|
-
|
|
342
|
+
Returns true if the verification succeeds.
|