starknet 4.3.0 → 4.4.1
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 -1
- package/__mocks__/typedDataSessionExample.json +42 -0
- package/__tests__/defaultProvider.test.ts +11 -24
- package/__tests__/rpcProvider.test.ts +32 -5
- package/__tests__/sequencerProvider.test.ts +9 -1
- 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 +1 -0
- package/dist/index.js +2 -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 +70 -28
- package/dist/provider/sequencer.d.ts +2 -2
- package/dist/provider/sequencer.js +4 -4
- 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.d.ts +1 -0
- package/dist/utils/number.js +6 -2
- 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/index.d.ts +1 -0
- package/index.js +2 -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 +70 -28
- package/provider/sequencer.d.ts +2 -2
- package/provider/sequencer.js +4 -4
- 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 +1 -0
- package/src/provider/default.ts +2 -3
- package/src/provider/interface.ts +5 -3
- package/src/provider/rpc.ts +59 -32
- package/src/provider/sequencer.ts +3 -6
- 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 +5 -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/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.d.ts +1 -0
- package/utils/number.js +6 -2
- 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/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 +29 -63
- package/www/docs/API/signer.md +8 -10
- package/www/docs/API/utils.md +157 -74
- package/www/guides/account.md +12 -12
- package/www/guides/erc20.md +19 -4
- package/www/guides/intro.md +3 -1
package/signer/default.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TypedData } from '../utils/typedData';
|
|
|
3
3
|
import { SignerInterface } from './interface';
|
|
4
4
|
export declare class Signer implements SignerInterface {
|
|
5
5
|
protected keyPair: KeyPair;
|
|
6
|
-
constructor(keyPair
|
|
6
|
+
constructor(keyPair?: KeyPair);
|
|
7
7
|
getPubKey(): Promise<string>;
|
|
8
8
|
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
9
9
|
signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
|
package/signer/default.js
CHANGED
|
@@ -43,6 +43,7 @@ var transaction_1 = require("../utils/transaction");
|
|
|
43
43
|
var typedData_1 = require("../utils/typedData");
|
|
44
44
|
var Signer = /** @class */ (function () {
|
|
45
45
|
function Signer(keyPair) {
|
|
46
|
+
if (keyPair === void 0) { keyPair = (0, ellipticCurve_1.genKeyPair)(); }
|
|
46
47
|
this.keyPair = keyPair;
|
|
47
48
|
}
|
|
48
49
|
Signer.prototype.getPubKey = function () {
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * as json from './utils/json';
|
|
|
17
17
|
export * as number from './utils/number';
|
|
18
18
|
export * as transaction from './utils/transaction';
|
|
19
19
|
export * as stark from './utils/stark';
|
|
20
|
+
export * as merkle from './utils/merkle';
|
|
20
21
|
export * as ec from './utils/ellipticCurve';
|
|
21
22
|
export * as uint256 from './utils/uint256';
|
|
22
23
|
export * as shortString from './utils/shortString';
|
package/src/provider/default.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import {
|
|
3
|
-
BlockTag,
|
|
4
3
|
Call,
|
|
5
4
|
CallContractResponse,
|
|
6
5
|
ContractClass,
|
|
@@ -69,9 +68,9 @@ export class Provider implements ProviderInterface {
|
|
|
69
68
|
public async getStorageAt(
|
|
70
69
|
contractAddress: string,
|
|
71
70
|
key: BigNumberish,
|
|
72
|
-
|
|
71
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
73
72
|
): Promise<BigNumberish> {
|
|
74
|
-
return this.provider.getStorageAt(contractAddress, key,
|
|
73
|
+
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import type {
|
|
3
|
-
BlockTag,
|
|
4
3
|
Call,
|
|
5
4
|
CallContractResponse,
|
|
6
5
|
ContractClass,
|
|
@@ -43,6 +42,9 @@ export abstract class ProviderInterface {
|
|
|
43
42
|
*/
|
|
44
43
|
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
45
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated The method should not be used
|
|
47
|
+
*/
|
|
46
48
|
public abstract getCode(
|
|
47
49
|
contractAddress: string,
|
|
48
50
|
blockIdentifier?: BlockIdentifier
|
|
@@ -65,13 +67,13 @@ export abstract class ProviderInterface {
|
|
|
65
67
|
*
|
|
66
68
|
* @param contractAddress
|
|
67
69
|
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
|
|
68
|
-
* @param
|
|
70
|
+
* @param blockIdentifier - block identifier
|
|
69
71
|
* @returns the value of the storage variable
|
|
70
72
|
*/
|
|
71
73
|
public abstract getStorageAt(
|
|
72
74
|
contractAddress: string,
|
|
73
75
|
key: BigNumberish,
|
|
74
|
-
|
|
76
|
+
blockIdentifier: BlockIdentifier
|
|
75
77
|
): Promise<BigNumberish>;
|
|
76
78
|
|
|
77
79
|
/**
|
package/src/provider/rpc.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
2
|
import {
|
|
3
|
-
BlockTag,
|
|
4
3
|
Call,
|
|
5
4
|
CallContractResponse,
|
|
6
5
|
DeclareContractPayload,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
DeployContractResponse,
|
|
10
9
|
EstimateFeeResponse,
|
|
11
10
|
GetBlockResponse,
|
|
11
|
+
GetCodeResponse,
|
|
12
12
|
GetTransactionReceiptResponse,
|
|
13
13
|
GetTransactionResponse,
|
|
14
14
|
Invocation,
|
|
@@ -21,8 +21,7 @@ import { getSelectorFromName } from '../utils/hash';
|
|
|
21
21
|
import { stringify } from '../utils/json';
|
|
22
22
|
import {
|
|
23
23
|
BigNumberish,
|
|
24
|
-
|
|
25
|
-
isHex,
|
|
24
|
+
bigNumberishArrayToHexadecimalStringArray,
|
|
26
25
|
toBN,
|
|
27
26
|
toHex,
|
|
28
27
|
} from '../utils/number';
|
|
@@ -30,7 +29,7 @@ import { parseCalldata, parseContract, wait } from '../utils/provider';
|
|
|
30
29
|
import { RPCResponseParser } from '../utils/responseParser/rpc';
|
|
31
30
|
import { randomAddress } from '../utils/stark';
|
|
32
31
|
import { ProviderInterface } from './interface';
|
|
33
|
-
import { BlockIdentifier } from './utils';
|
|
32
|
+
import { BlockIdentifier, BlockIdentifierClass } from './utils';
|
|
34
33
|
|
|
35
34
|
export type RpcProviderOptions = { nodeUrl: string };
|
|
36
35
|
|
|
@@ -89,34 +88,63 @@ export class RpcProvider implements ProviderInterface {
|
|
|
89
88
|
return this.fetchEndpoint('starknet_chainId');
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
// Common Interface
|
|
92
92
|
public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
|
|
93
|
-
|
|
94
|
-
typeof blockIdentifier === 'string' && isHex(blockIdentifier)
|
|
95
|
-
? 'starknet_getBlockByHash'
|
|
96
|
-
: 'starknet_getBlockByNumber';
|
|
97
|
-
|
|
98
|
-
return this.fetchEndpoint(method, [blockIdentifier]).then(
|
|
93
|
+
return this.getBlockWithTxHashes(blockIdentifier).then(
|
|
99
94
|
this.responseParser.parseGetBlockResponse
|
|
100
95
|
);
|
|
101
96
|
}
|
|
102
97
|
|
|
98
|
+
public async getBlockWithTxHashes(
|
|
99
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
100
|
+
): Promise<RPC.GetBlockWithTxHashesResponse> {
|
|
101
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
102
|
+
return this.fetchEndpoint('starknet_getBlockWithTxHashes', [
|
|
103
|
+
blockIdentifierGetter.getIdentifier(),
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public async getBlockWithTxs(
|
|
108
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
109
|
+
): Promise<RPC.GetBlockWithTxs> {
|
|
110
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
111
|
+
return this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public async getNonce(contractAddress: string): Promise<any> {
|
|
115
|
+
return this.fetchEndpoint('starknet_getNonce', [contractAddress]);
|
|
116
|
+
}
|
|
117
|
+
|
|
103
118
|
public async getStorageAt(
|
|
104
119
|
contractAddress: string,
|
|
105
120
|
key: BigNumberish,
|
|
106
|
-
|
|
121
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
107
122
|
): Promise<BigNumberish> {
|
|
108
123
|
const parsedKey = toHex(toBN(key));
|
|
124
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
109
125
|
return this.fetchEndpoint('starknet_getStorageAt', [
|
|
110
126
|
contractAddress,
|
|
111
127
|
parsedKey,
|
|
112
|
-
|
|
128
|
+
blockIdentifierGetter.getIdentifier(),
|
|
113
129
|
]);
|
|
114
130
|
}
|
|
115
131
|
|
|
132
|
+
// common interface
|
|
116
133
|
public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
|
|
117
|
-
return this.
|
|
118
|
-
|
|
119
|
-
|
|
134
|
+
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public async getTransactionByHash(
|
|
138
|
+
txHash: BigNumberish
|
|
139
|
+
): Promise<RPC.GetTransactionByHashResponse> {
|
|
140
|
+
return this.fetchEndpoint('starknet_getTransactionByHash', [txHash]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public async getTransactionByBlockIdAndIndex(
|
|
144
|
+
blockIdentifier: BlockIdentifier,
|
|
145
|
+
index: number
|
|
146
|
+
): Promise<RPC.GetTransactionByBlockIdAndIndex> {
|
|
147
|
+
return this.fetchEndpoint('starknet_getTransactionByHash', [blockIdentifier, index]);
|
|
120
148
|
}
|
|
121
149
|
|
|
122
150
|
public async getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse> {
|
|
@@ -125,11 +153,12 @@ export class RpcProvider implements ProviderInterface {
|
|
|
125
153
|
);
|
|
126
154
|
}
|
|
127
155
|
|
|
128
|
-
public async getClassAt(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
public async getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any> {
|
|
157
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
158
|
+
return this.fetchEndpoint('starknet_getClassAt', [
|
|
159
|
+
blockIdentifierGetter.getIdentifier(),
|
|
160
|
+
contractAddress,
|
|
161
|
+
]);
|
|
133
162
|
}
|
|
134
163
|
|
|
135
164
|
public async getEstimateFee(
|
|
@@ -142,7 +171,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
142
171
|
contract_address: invocation.contractAddress,
|
|
143
172
|
entry_point_selector: getSelectorFromName(invocation.entrypoint),
|
|
144
173
|
calldata: parseCalldata(invocation.calldata),
|
|
145
|
-
signature:
|
|
174
|
+
signature: bigNumberishArrayToHexadecimalStringArray(invocation.signature || []),
|
|
146
175
|
version: toHex(toBN(invocationDetails?.version || 0)),
|
|
147
176
|
},
|
|
148
177
|
blockIdentifier,
|
|
@@ -173,7 +202,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
173
202
|
|
|
174
203
|
return this.fetchEndpoint('starknet_addDeployTransaction', [
|
|
175
204
|
addressSalt ?? randomAddress(),
|
|
176
|
-
|
|
205
|
+
bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
|
|
177
206
|
{
|
|
178
207
|
program: contractDefinition.program,
|
|
179
208
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
@@ -191,7 +220,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
191
220
|
entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
|
|
192
221
|
calldata: parseCalldata(functionInvocation.calldata),
|
|
193
222
|
},
|
|
194
|
-
|
|
223
|
+
bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
|
|
195
224
|
toHex(toBN(details.maxFee || 0)),
|
|
196
225
|
toHex(toBN(details.version || 0)),
|
|
197
226
|
]).then(this.responseParser.parseInvokeFunctionResponse);
|
|
@@ -214,12 +243,10 @@ export class RpcProvider implements ProviderInterface {
|
|
|
214
243
|
}
|
|
215
244
|
|
|
216
245
|
public async getCode(
|
|
217
|
-
|
|
246
|
+
_contractAddress: string,
|
|
218
247
|
_blockIdentifier?: BlockIdentifier
|
|
219
|
-
): Promise<
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return this.responseParser.parseGetCodeResponse(result);
|
|
248
|
+
): Promise<GetCodeResponse> {
|
|
249
|
+
throw new Error('RPC 0.1.0 does not implement getCode function');
|
|
223
250
|
}
|
|
224
251
|
|
|
225
252
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
@@ -270,10 +297,10 @@ export class RpcProvider implements ProviderInterface {
|
|
|
270
297
|
public async getTransactionCount(
|
|
271
298
|
blockIdentifier: BlockIdentifier
|
|
272
299
|
): Promise<RPC.GetTransactionCountResponse> {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
300
|
+
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
|
|
301
|
+
return this.fetchEndpoint('starknet_getBlockTransactionCount', [
|
|
302
|
+
blockIdentifierGetter.getIdentifier(),
|
|
303
|
+
]);
|
|
277
304
|
}
|
|
278
305
|
|
|
279
306
|
/**
|
|
@@ -2,7 +2,6 @@ import urljoin from 'url-join';
|
|
|
2
2
|
|
|
3
3
|
import { ONE, StarknetChainId, ZERO } from '../constants';
|
|
4
4
|
import {
|
|
5
|
-
BlockTag,
|
|
6
5
|
Call,
|
|
7
6
|
CallContractResponse,
|
|
8
7
|
ContractClass,
|
|
@@ -233,11 +232,11 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
233
232
|
public async getStorageAt(
|
|
234
233
|
contractAddress: string,
|
|
235
234
|
key: BigNumberish,
|
|
236
|
-
|
|
235
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
237
236
|
): Promise<BigNumberish> {
|
|
238
237
|
const parsedKey = toBN(key).toString(10);
|
|
239
238
|
return this.fetchEndpoint('get_storage_at', {
|
|
240
|
-
blockIdentifier
|
|
239
|
+
blockIdentifier,
|
|
241
240
|
contractAddress,
|
|
242
241
|
key: parsedKey,
|
|
243
242
|
});
|
|
@@ -332,9 +331,7 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
332
331
|
contractAddress: string,
|
|
333
332
|
blockIdentifier: BlockIdentifier = 'pending'
|
|
334
333
|
): Promise<Sequencer.GetCodeResponse> {
|
|
335
|
-
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier })
|
|
336
|
-
this.responseParser.parseGetCodeResponse
|
|
337
|
-
);
|
|
334
|
+
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier });
|
|
338
335
|
}
|
|
339
336
|
|
|
340
337
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
package/src/provider/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BlockNumber } from '../types';
|
|
2
|
-
import { BigNumberish, toBN, toHex } from '../utils/number';
|
|
2
|
+
import { BigNumberish, isHex, toBN, toHex } from '../utils/number';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -31,11 +31,32 @@ export function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string
|
|
|
31
31
|
// hex string and BN are detected as block hashes
|
|
32
32
|
// decimal string and number are detected as block numbers
|
|
33
33
|
// null appends nothing to the request url
|
|
34
|
+
|
|
34
35
|
export type BlockIdentifier = BlockNumber | BigNumberish;
|
|
35
36
|
type BlockIdentifierObject =
|
|
36
37
|
| { type: 'BLOCK_NUMBER'; data: BlockNumber }
|
|
37
38
|
| { type: 'BLOCK_HASH'; data: BigNumberish };
|
|
38
39
|
|
|
40
|
+
export class BlockIdentifierClass {
|
|
41
|
+
blockIdentifier: BlockIdentifier;
|
|
42
|
+
|
|
43
|
+
constructor(blockIdentifier: BlockIdentifier) {
|
|
44
|
+
this.blockIdentifier = blockIdentifier;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getIdentifier() {
|
|
48
|
+
if (typeof this.blockIdentifier === 'string' && isHex(this.blockIdentifier)) {
|
|
49
|
+
return { block_hash: this.blockIdentifier };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof this.blockIdentifier === 'number') {
|
|
53
|
+
return { block_number: this.blockIdentifier };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.blockIdentifier;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
39
60
|
/**
|
|
40
61
|
* Identifies the block to be queried.
|
|
41
62
|
*
|
package/src/signer/default.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Abi, Invocation, InvocationsSignerDetails, KeyPair, Signature } from '../types';
|
|
2
|
-
import { getStarkKey, sign } from '../utils/ellipticCurve';
|
|
2
|
+
import { genKeyPair, getStarkKey, sign } from '../utils/ellipticCurve';
|
|
3
3
|
import { calculcateTransactionHash, getSelectorFromName } from '../utils/hash';
|
|
4
4
|
import { fromCallsToExecuteCalldataWithNonce } from '../utils/transaction';
|
|
5
5
|
import { TypedData, getMessageHash } from '../utils/typedData';
|
|
@@ -8,7 +8,7 @@ import { SignerInterface } from './interface';
|
|
|
8
8
|
export class Signer implements SignerInterface {
|
|
9
9
|
protected keyPair: KeyPair;
|
|
10
10
|
|
|
11
|
-
constructor(keyPair: KeyPair) {
|
|
11
|
+
constructor(keyPair: KeyPair = genKeyPair()) {
|
|
12
12
|
this.keyPair = keyPair;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starknet RPC version 0.1.0
|
|
3
|
+
* starknet_api_openrpc version 0.31.0
|
|
4
|
+
*
|
|
5
|
+
* TypeScript Representation of OpenRpc protocol types | results
|
|
6
|
+
* errors are not implemented here only results
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* "type": "string",
|
|
11
|
+
* "title": "Field element",
|
|
12
|
+
* "$comment": "A field element, represented as a string of hex digits",
|
|
13
|
+
* "description": "A field element. Represented as up to 63 hex digits and leading 4 bits zeroed.",
|
|
14
|
+
* "pattern": "^0x0[a-fA-F0-9]{1,63}$"
|
|
15
|
+
*/
|
|
16
|
+
type FELT = string;
|
|
17
|
+
type BLOCK_NUMBER = number;
|
|
18
|
+
type BLOCK_HASH = FELT;
|
|
19
|
+
type TXN_HASH = FELT;
|
|
20
|
+
type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
21
|
+
type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
|
|
22
|
+
type MSG_TO_L1 = {
|
|
23
|
+
to_address: FELT;
|
|
24
|
+
payload: Array<FELT>;
|
|
25
|
+
};
|
|
26
|
+
type EVENT = {
|
|
27
|
+
from_address: FELT;
|
|
28
|
+
keys: Array<FELT>;
|
|
29
|
+
data: Array<FELT>;
|
|
30
|
+
};
|
|
31
|
+
type COMMON_RECEIPT_PROPERTIES = {
|
|
32
|
+
transaction_hash: TXN_HASH;
|
|
33
|
+
actual_fee: FELT;
|
|
34
|
+
status: TXN_STATUS;
|
|
35
|
+
block_hash: BLOCK_HASH;
|
|
36
|
+
block_number: BLOCK_NUMBER;
|
|
37
|
+
type?: TXN_TYPE;
|
|
38
|
+
};
|
|
39
|
+
type INVOKE_TXN_RECEIPT_PROPERTIES = {
|
|
40
|
+
messages_sent: MSG_TO_L1;
|
|
41
|
+
events: EVENT;
|
|
42
|
+
};
|
|
43
|
+
type PENDING_COMMON_RECEIPT_PROPERTIES = {
|
|
44
|
+
transaction_hash: TXN_HASH;
|
|
45
|
+
actual_fee: FELT;
|
|
46
|
+
type?: TXN_TYPE;
|
|
47
|
+
};
|
|
48
|
+
type INVOKE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
|
|
49
|
+
type L1_HANDLER_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
50
|
+
type DECLARE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
51
|
+
type DEPLOY_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
|
|
52
|
+
type PENDING_INVOKE_TXN_RECEIPT = PENDING_COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
|
|
53
|
+
type PENDING_TXN_RECEIPT = PENDING_INVOKE_TXN_RECEIPT | PENDING_COMMON_RECEIPT_PROPERTIES;
|
|
54
|
+
type TXN_RECEIPT =
|
|
55
|
+
| INVOKE_TXN_RECEIPT
|
|
56
|
+
| L1_HANDLER_TXN_RECEIPT
|
|
57
|
+
| DECLARE_TXN_RECEIPT
|
|
58
|
+
| DEPLOY_TXN_RECEIPT
|
|
59
|
+
| PENDING_TXN_RECEIPT;
|
|
60
|
+
|
|
61
|
+
export namespace RPC_1 {
|
|
62
|
+
export type GetTransactionReceiptResponse = TXN_RECEIPT;
|
|
63
|
+
|
|
64
|
+
export type Methods = {
|
|
65
|
+
starknet_getTransactionReceipt: {
|
|
66
|
+
QUERY: never;
|
|
67
|
+
REQUEST: any[];
|
|
68
|
+
RESPONSE: GetTransactionReceiptResponse;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// starknet_getBlockWithTxHashes
|
|
74
|
+
type BLOCK_HEADER = {
|
|
75
|
+
block_hash: BLOCK_HASH;
|
|
76
|
+
parent_hash: BLOCK_HASH;
|
|
77
|
+
block_number: BLOCK_NUMBER;
|
|
78
|
+
new_root: FELT;
|
|
79
|
+
timestamp: number;
|
|
80
|
+
sequencer_address: FELT;
|
|
81
|
+
};
|
|
82
|
+
type BLOCK_BODY_WITH_TX_HASHES = {
|
|
83
|
+
transactions: Array<TXN_HASH>;
|
|
84
|
+
};
|
|
85
|
+
type BLOCK_WITH_TX_HASHES = {
|
|
86
|
+
status: TXN_STATUS;
|
|
87
|
+
} & BLOCK_HEADER &
|
|
88
|
+
BLOCK_BODY_WITH_TX_HASHES;
|
|
89
|
+
type PENDING_BLOCK_WITH_TX_HASHES = BLOCK_BODY_WITH_TX_HASHES & {
|
|
90
|
+
timestamp: number;
|
|
91
|
+
sequencer_address: FELT;
|
|
92
|
+
parent_hash: BLOCK_HASH;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// starknet_getBlockWithTx
|
|
96
|
+
type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
|
|
97
|
+
/**
|
|
98
|
+
* "title": "An integer number in hex format (0x...)",
|
|
99
|
+
* "pattern": "^0x[a-fA-F0-9]+$"
|
|
100
|
+
*/
|
|
101
|
+
type NUM_AS_HEX = string;
|
|
102
|
+
type SIGNATURE = Array<FELT>;
|
|
103
|
+
type COMMON_TXN_PROPERTIES = {
|
|
104
|
+
transaction_hash: TXN_HASH;
|
|
105
|
+
max_fee: FELT;
|
|
106
|
+
version: NUM_AS_HEX;
|
|
107
|
+
signature: SIGNATURE;
|
|
108
|
+
nonce: FELT;
|
|
109
|
+
type: TXN_TYPE;
|
|
110
|
+
};
|
|
111
|
+
type ADDRESS = FELT;
|
|
112
|
+
type FUNCTION_CALL = {
|
|
113
|
+
contract_address: ADDRESS;
|
|
114
|
+
entry_point_selector: FELT;
|
|
115
|
+
calldata: Array<FELT>;
|
|
116
|
+
};
|
|
117
|
+
type INVOKE_TXN = COMMON_TXN_PROPERTIES & FUNCTION_CALL;
|
|
118
|
+
type DECLARE_TXN = COMMON_TXN_PROPERTIES & {
|
|
119
|
+
class_hash: FELT;
|
|
120
|
+
sender_address: ADDRESS;
|
|
121
|
+
};
|
|
122
|
+
type DEPLOY_TXN = {
|
|
123
|
+
transaction_hash: TXN_HASH;
|
|
124
|
+
class_hash: FELT;
|
|
125
|
+
version: NUM_AS_HEX;
|
|
126
|
+
type: TXN_TYPE;
|
|
127
|
+
contract_address: FELT;
|
|
128
|
+
contract_address_salt: FELT;
|
|
129
|
+
constructor_calldata: Array<FELT>;
|
|
130
|
+
};
|
|
131
|
+
type TXN = INVOKE_TXN | DECLARE_TXN | DEPLOY_TXN;
|
|
132
|
+
type BLOCK_BODY_WITH_TXS = {
|
|
133
|
+
transactions: Array<TXN>;
|
|
134
|
+
};
|
|
135
|
+
type BLOCK_WITH_TXS = {
|
|
136
|
+
status: BLOCK_STATUS;
|
|
137
|
+
} & BLOCK_HEADER &
|
|
138
|
+
BLOCK_BODY_WITH_TXS;
|
|
139
|
+
|
|
140
|
+
type PENDING_BLOCK_WITH_TXS = BLOCK_BODY_WITH_TXS & {
|
|
141
|
+
timestamp: number;
|
|
142
|
+
sequencer_address: FELT;
|
|
143
|
+
parent_hash: BLOCK_HASH;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
type CONTRACT_CLASS = {
|
|
147
|
+
program: string; // A base64 representation of the compressed program code
|
|
148
|
+
entry_points_by_type: {
|
|
149
|
+
CONSTRUCTOR: CONTRACT_ENTRY_POINT_LIST;
|
|
150
|
+
EXTERNAL: CONTRACT_ENTRY_POINT_LIST;
|
|
151
|
+
L1_HANDLER: CONTRACT_ENTRY_POINT_LIST;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
type CONTRACT_ENTRY_POINT_LIST = Array<CONTRACT_ENTRY_POINT>;
|
|
156
|
+
type CONTRACT_ENTRY_POINT = {
|
|
157
|
+
offset: NUM_AS_HEX;
|
|
158
|
+
selector: FELT;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export namespace OPENRPC {
|
|
162
|
+
export type GetBlockWithTxHashesResponse = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
|
|
163
|
+
export type GetBlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
|
|
164
|
+
export type GetStorageAtResponse = FELT;
|
|
165
|
+
export type GetTransactionByHashResponse = TXN;
|
|
166
|
+
export type GetTransactionByBlockIdAndIndex = TXN;
|
|
167
|
+
export type GetClassResponse = CONTRACT_CLASS;
|
|
168
|
+
}
|
package/src/types/api/rpc.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { StarknetChainId } from '../../constants';
|
|
2
|
+
import { BlockIdentifier } from '../../provider/utils';
|
|
2
3
|
import { Status } from '../lib';
|
|
4
|
+
import { OPENRPC } from './openrpc';
|
|
3
5
|
|
|
4
6
|
export namespace RPC {
|
|
5
7
|
export type Response = {
|
|
@@ -32,25 +34,9 @@ export namespace RPC {
|
|
|
32
34
|
gas_price: number;
|
|
33
35
|
};
|
|
34
36
|
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
block_number: number;
|
|
39
|
-
status: Status;
|
|
40
|
-
sequencer: string;
|
|
41
|
-
new_root: string;
|
|
42
|
-
old_root: string;
|
|
43
|
-
accepted_time: number;
|
|
44
|
-
gas_price: string;
|
|
45
|
-
transactions: string[];
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type GetCodeResponse = {
|
|
49
|
-
bytecode: string[];
|
|
50
|
-
abi: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type GetStorageAtResponse = string;
|
|
37
|
+
export type GetBlockWithTxHashesResponse = OPENRPC.GetBlockWithTxHashesResponse;
|
|
38
|
+
export type GetBlockWithTxs = OPENRPC.GetBlockWithTxs;
|
|
39
|
+
export type GetStorageAtResponse = OPENRPC.GetStorageAtResponse;
|
|
54
40
|
|
|
55
41
|
export type GetTransactionReceiptResponse = {
|
|
56
42
|
txn_hash: string;
|
|
@@ -81,7 +67,8 @@ export namespace RPC {
|
|
|
81
67
|
sender_address?: string;
|
|
82
68
|
}
|
|
83
69
|
|
|
84
|
-
export type
|
|
70
|
+
export type GetTransactionByHashResponse = OPENRPC.GetTransactionByHashResponse;
|
|
71
|
+
export type GetTransactionByBlockIdAndIndex = OPENRPC.GetTransactionByBlockIdAndIndex;
|
|
85
72
|
|
|
86
73
|
export type GetTransactionCountResponse = number;
|
|
87
74
|
|
|
@@ -99,8 +86,8 @@ export namespace RPC {
|
|
|
99
86
|
| boolean;
|
|
100
87
|
|
|
101
88
|
export type EventFilter = {
|
|
102
|
-
fromBlock:
|
|
103
|
-
toBlock:
|
|
89
|
+
fromBlock: BlockIdentifier;
|
|
90
|
+
toBlock: BlockIdentifier;
|
|
104
91
|
address: string;
|
|
105
92
|
keys: string[];
|
|
106
93
|
page_size: number;
|
|
@@ -143,56 +130,46 @@ export namespace RPC {
|
|
|
143
130
|
};
|
|
144
131
|
|
|
145
132
|
export type Methods = {
|
|
146
|
-
|
|
133
|
+
starknet_getBlockWithTxHashes: {
|
|
147
134
|
QUERY: never;
|
|
148
135
|
REQUEST: any[];
|
|
149
|
-
RESPONSE:
|
|
136
|
+
RESPONSE: GetBlockWithTxHashesResponse;
|
|
150
137
|
};
|
|
151
|
-
|
|
138
|
+
starknet_getBlockWithTxs: {
|
|
152
139
|
QUERY: never;
|
|
153
140
|
REQUEST: any[];
|
|
154
|
-
RESPONSE:
|
|
141
|
+
RESPONSE: GetBlockWithTxs;
|
|
155
142
|
};
|
|
156
|
-
|
|
143
|
+
starknet_getNonce: {
|
|
157
144
|
QUERY: never;
|
|
158
145
|
REQUEST: any[];
|
|
159
|
-
RESPONSE:
|
|
146
|
+
RESPONSE: string;
|
|
160
147
|
};
|
|
161
|
-
|
|
148
|
+
starknet_getStorageAt: {
|
|
162
149
|
QUERY: never;
|
|
163
150
|
REQUEST: any[];
|
|
164
|
-
RESPONSE:
|
|
151
|
+
RESPONSE: GetStorageAtResponse;
|
|
165
152
|
};
|
|
166
|
-
|
|
153
|
+
starknet_getTransactionByHash: {
|
|
167
154
|
QUERY: never;
|
|
168
155
|
REQUEST: any[];
|
|
169
|
-
RESPONSE:
|
|
156
|
+
RESPONSE: GetTransactionByHashResponse;
|
|
170
157
|
};
|
|
171
|
-
|
|
158
|
+
starknet_getTransactionByBlockIdAndIndex: {
|
|
172
159
|
QUERY: never;
|
|
173
160
|
REQUEST: any[];
|
|
174
|
-
RESPONSE:
|
|
161
|
+
RESPONSE: GetTransactionByBlockIdAndIndex;
|
|
175
162
|
};
|
|
176
163
|
starknet_getTransactionReceipt: {
|
|
177
164
|
QUERY: never;
|
|
178
165
|
REQUEST: any[];
|
|
179
166
|
RESPONSE: GetTransactionReceiptResponse;
|
|
180
167
|
};
|
|
181
|
-
|
|
182
|
-
QUERY: never;
|
|
183
|
-
REQUEST: any[];
|
|
184
|
-
RESPONSE: GetTransactionCountResponse;
|
|
185
|
-
};
|
|
186
|
-
starknet_getBlockTransactionCountByNumber: {
|
|
168
|
+
starknet_getBlockTransactionCount: {
|
|
187
169
|
QUERY: never;
|
|
188
170
|
REQUEST: any[];
|
|
189
171
|
RESPONSE: GetTransactionCountResponse;
|
|
190
172
|
};
|
|
191
|
-
starknet_getCode: {
|
|
192
|
-
QUERY: never;
|
|
193
|
-
REQUEST: any[];
|
|
194
|
-
RESPONSE: GetCodeResponse;
|
|
195
|
-
};
|
|
196
173
|
starknet_call: {
|
|
197
174
|
QUERY: never;
|
|
198
175
|
REQUEST: any[];
|
package/src/types/provider.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common interface response
|
|
3
|
+
* Intersection (sequencer response ∩ (∪ rpc responses))
|
|
4
|
+
*/
|
|
1
5
|
import BN from 'bn.js';
|
|
2
6
|
|
|
3
7
|
import { Abi, CompressedProgram, EntryPointsByType, RawCalldata, Signature, Status } from './lib';
|
|
4
8
|
|
|
5
9
|
export interface GetBlockResponse {
|
|
6
|
-
|
|
10
|
+
timestamp: number;
|
|
7
11
|
block_hash: string;
|
|
8
12
|
block_number: number;
|
|
9
|
-
gas_price: string;
|
|
10
13
|
new_root: string;
|
|
11
|
-
old_root?: string;
|
|
12
14
|
parent_hash: string;
|
|
13
|
-
sequencer: string;
|
|
14
15
|
status: Status;
|
|
15
16
|
transactions: Array<string>;
|
|
16
|
-
starknet_version?: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface GetCodeResponse {
|