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.
Files changed (99) hide show
  1. package/CHANGELOG.md +40 -1
  2. package/__mocks__/typedDataSessionExample.json +42 -0
  3. package/__tests__/defaultProvider.test.ts +11 -24
  4. package/__tests__/rpcProvider.test.ts +32 -5
  5. package/__tests__/sequencerProvider.test.ts +9 -1
  6. package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +2 -0
  7. package/__tests__/utils/ellipticalCurve.test.ts +5 -0
  8. package/__tests__/utils/merkle.test.ts +146 -0
  9. package/__tests__/utils/typedData.test.ts +107 -9
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +2 -1
  12. package/dist/provider/default.d.ts +2 -2
  13. package/dist/provider/default.js +3 -3
  14. package/dist/provider/interface.d.ts +6 -3
  15. package/dist/provider/rpc.d.ts +9 -4
  16. package/dist/provider/rpc.js +70 -28
  17. package/dist/provider/sequencer.d.ts +2 -2
  18. package/dist/provider/sequencer.js +4 -4
  19. package/dist/provider/utils.d.ts +12 -0
  20. package/dist/provider/utils.js +17 -1
  21. package/dist/signer/default.d.ts +1 -1
  22. package/dist/signer/default.js +1 -0
  23. package/dist/types/api/openrpc.d.ts +151 -0
  24. package/dist/types/api/openrpc.js +9 -0
  25. package/dist/types/api/rpc.d.ts +22 -43
  26. package/dist/types/provider.d.ts +5 -5
  27. package/dist/utils/ellipticCurve.d.ts +13 -0
  28. package/dist/utils/ellipticCurve.js +20 -16
  29. package/dist/utils/hash.js +8 -6
  30. package/dist/utils/merkle.d.ts +10 -0
  31. package/dist/utils/merkle.js +90 -0
  32. package/dist/utils/number.d.ts +1 -0
  33. package/dist/utils/number.js +6 -2
  34. package/dist/utils/responseParser/rpc.d.ts +13 -3
  35. package/dist/utils/responseParser/rpc.js +2 -10
  36. package/dist/utils/responseParser/sequencer.d.ts +4 -1
  37. package/dist/utils/responseParser/sequencer.js +1 -7
  38. package/dist/utils/typedData/index.d.ts +23 -8
  39. package/dist/utils/typedData/index.js +70 -31
  40. package/dist/utils/typedData/types.d.ts +8 -3
  41. package/index.d.ts +1 -0
  42. package/index.js +2 -1
  43. package/package.json +1 -1
  44. package/provider/default.d.ts +2 -2
  45. package/provider/default.js +3 -3
  46. package/provider/interface.d.ts +6 -3
  47. package/provider/rpc.d.ts +9 -4
  48. package/provider/rpc.js +70 -28
  49. package/provider/sequencer.d.ts +2 -2
  50. package/provider/sequencer.js +4 -4
  51. package/provider/utils.d.ts +12 -0
  52. package/provider/utils.js +17 -1
  53. package/signer/default.d.ts +1 -1
  54. package/signer/default.js +1 -0
  55. package/src/index.ts +1 -0
  56. package/src/provider/default.ts +2 -3
  57. package/src/provider/interface.ts +5 -3
  58. package/src/provider/rpc.ts +59 -32
  59. package/src/provider/sequencer.ts +3 -6
  60. package/src/provider/utils.ts +22 -1
  61. package/src/signer/default.ts +2 -2
  62. package/src/types/api/openrpc.ts +168 -0
  63. package/src/types/api/rpc.ts +22 -45
  64. package/src/types/provider.ts +5 -5
  65. package/src/utils/ellipticCurve.ts +20 -16
  66. package/src/utils/hash.ts +8 -6
  67. package/src/utils/merkle.ts +70 -0
  68. package/src/utils/number.ts +5 -1
  69. package/src/utils/responseParser/rpc.ts +16 -13
  70. package/src/utils/responseParser/sequencer.ts +5 -8
  71. package/src/utils/typedData/index.ts +88 -34
  72. package/src/utils/typedData/types.ts +12 -4
  73. package/types/api/openrpc.d.ts +151 -0
  74. package/types/api/openrpc.js +9 -0
  75. package/types/api/rpc.d.ts +22 -43
  76. package/types/provider.d.ts +5 -5
  77. package/utils/ellipticCurve.d.ts +13 -0
  78. package/utils/ellipticCurve.js +20 -16
  79. package/utils/hash.js +8 -6
  80. package/utils/merkle.d.ts +10 -0
  81. package/utils/merkle.js +90 -0
  82. package/utils/number.d.ts +1 -0
  83. package/utils/number.js +6 -2
  84. package/utils/responseParser/rpc.d.ts +13 -3
  85. package/utils/responseParser/rpc.js +2 -10
  86. package/utils/responseParser/sequencer.d.ts +4 -1
  87. package/utils/responseParser/sequencer.js +1 -7
  88. package/utils/typedData/index.d.ts +23 -8
  89. package/utils/typedData/index.js +70 -31
  90. package/utils/typedData/types.d.ts +8 -3
  91. package/www/docs/API/account.md +20 -18
  92. package/www/docs/API/contract.md +10 -10
  93. package/www/docs/API/contractFactory.md +14 -11
  94. package/www/docs/API/provider.md +29 -63
  95. package/www/docs/API/signer.md +8 -10
  96. package/www/docs/API/utils.md +157 -74
  97. package/www/guides/account.md +12 -12
  98. package/www/guides/erc20.md +19 -4
  99. package/www/guides/intro.md +3 -1
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import { BigNumberish } from '../utils/number';
4
4
  import { ProviderInterface } from './interface';
5
5
  import { RpcProviderOptions } from './rpc';
@@ -16,7 +16,7 @@ export declare class Provider implements ProviderInterface {
16
16
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
17
17
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
18
18
  getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
19
- getStorageAt(contractAddress: string, key: BigNumberish, blockTagOrHash?: BlockTag | BigNumberish): Promise<BigNumberish>;
19
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
20
20
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
21
21
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
22
22
  callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
@@ -86,11 +86,11 @@ var Provider = /** @class */ (function () {
86
86
  });
87
87
  });
88
88
  };
89
- Provider.prototype.getStorageAt = function (contractAddress, key, blockTagOrHash) {
90
- if (blockTagOrHash === void 0) { blockTagOrHash = 'pending'; }
89
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
90
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
91
91
  return __awaiter(this, void 0, void 0, function () {
92
92
  return __generator(this, function (_a) {
93
- return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockTagOrHash)];
93
+ return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockIdentifier)];
94
94
  });
95
95
  });
96
96
  };
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import type { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import type { BigNumberish } from '../utils/number';
4
4
  import { BlockIdentifier } from './utils';
5
5
  export declare abstract class ProviderInterface {
@@ -19,6 +19,9 @@ export declare abstract class ProviderInterface {
19
19
  * @returns the block object
20
20
  */
21
21
  abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
22
+ /**
23
+ * @deprecated The method should not be used
24
+ */
22
25
  abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
23
26
  /**
24
27
  * Gets the contract class of the deployed contract.
@@ -33,10 +36,10 @@ export declare abstract class ProviderInterface {
33
36
  *
34
37
  * @param contractAddress
35
38
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
36
- * @param blockHashOrTag - block hash or tag (pending, latest)
39
+ * @param blockIdentifier - block identifier
37
40
  * @returns the value of the storage variable
38
41
  */
39
- abstract getStorageAt(contractAddress: string, key: BigNumberish, blockHashOrTag?: BlockTag | BigNumberish): Promise<BigNumberish>;
42
+ abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier: BlockIdentifier): Promise<BigNumberish>;
40
43
  /**
41
44
  * Gets the transaction information from a tx id.
42
45
  *
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { BlockTag, Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import { RPC } from '../types/api';
4
4
  import { BigNumberish } from '../utils/number';
5
5
  import { ProviderInterface } from './interface';
@@ -15,16 +15,21 @@ export declare class RpcProvider implements ProviderInterface {
15
15
  protected fetchEndpoint<T extends keyof RPC.Methods>(method: T, request?: RPC.Methods[T]['REQUEST']): Promise<RPC.Methods[T]['RESPONSE']>;
16
16
  getChainId(): Promise<StarknetChainId>;
17
17
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
18
- getStorageAt(contractAddress: string, key: BigNumberish, blockHashOrTag?: BlockTag | BigNumberish): Promise<BigNumberish>;
18
+ getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
19
+ getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
20
+ getNonce(contractAddress: string): Promise<any>;
21
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
19
22
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
23
+ getTransactionByHash(txHash: BigNumberish): Promise<RPC.GetTransactionByHashResponse>;
24
+ getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
20
25
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
21
- getClassAt(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<any>;
26
+ getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any>;
22
27
  getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
23
28
  declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
24
29
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
25
30
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
26
31
  callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
27
- getCode(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<RPC.GetCodeResponse>;
32
+ getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
28
33
  waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
29
34
  /**
30
35
  * Gets the transaction count from a block.
@@ -47,6 +47,7 @@ var number_1 = require("../utils/number");
47
47
  var provider_1 = require("../utils/provider");
48
48
  var rpc_1 = require("../utils/responseParser/rpc");
49
49
  var stark_1 = require("../utils/stark");
50
+ var utils_1 = require("./utils");
50
51
  var RpcProvider = /** @class */ (function () {
51
52
  function RpcProvider(optionsOrProvider) {
52
53
  var _this = this;
@@ -112,36 +113,78 @@ var RpcProvider = /** @class */ (function () {
112
113
  });
113
114
  });
114
115
  };
116
+ // Common Interface
115
117
  RpcProvider.prototype.getBlock = function (blockIdentifier) {
116
118
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
117
119
  return __awaiter(this, void 0, void 0, function () {
118
- var method;
119
120
  return __generator(this, function (_a) {
120
- method = typeof blockIdentifier === 'string' && (0, number_1.isHex)(blockIdentifier)
121
- ? 'starknet_getBlockByHash'
122
- : 'starknet_getBlockByNumber';
123
- return [2 /*return*/, this.fetchEndpoint(method, [blockIdentifier]).then(this.responseParser.parseGetBlockResponse)];
121
+ return [2 /*return*/, this.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse)];
124
122
  });
125
123
  });
126
124
  };
127
- RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockHashOrTag) {
128
- if (blockHashOrTag === void 0) { blockHashOrTag = 'pending'; }
125
+ RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
126
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ var blockIdentifierGetter;
129
+ return __generator(this, function (_a) {
130
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
131
+ return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', [
132
+ blockIdentifierGetter.getIdentifier(),
133
+ ])];
134
+ });
135
+ });
136
+ };
137
+ RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
138
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var blockIdentifierGetter;
141
+ return __generator(this, function (_a) {
142
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
143
+ return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()])];
144
+ });
145
+ });
146
+ };
147
+ RpcProvider.prototype.getNonce = function (contractAddress) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ return __generator(this, function (_a) {
150
+ return [2 /*return*/, this.fetchEndpoint('starknet_getNonce', [contractAddress])];
151
+ });
152
+ });
153
+ };
154
+ RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
155
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
129
156
  return __awaiter(this, void 0, void 0, function () {
130
- var parsedKey;
157
+ var parsedKey, blockIdentifierGetter;
131
158
  return __generator(this, function (_a) {
132
159
  parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
160
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
133
161
  return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', [
134
162
  contractAddress,
135
163
  parsedKey,
136
- blockHashOrTag,
164
+ blockIdentifierGetter.getIdentifier(),
137
165
  ])];
138
166
  });
139
167
  });
140
168
  };
169
+ // common interface
141
170
  RpcProvider.prototype.getTransaction = function (txHash) {
142
171
  return __awaiter(this, void 0, void 0, function () {
143
172
  return __generator(this, function (_a) {
144
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [txHash]).then(this.responseParser.parseGetTransactionResponse)];
173
+ return [2 /*return*/, this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse)];
174
+ });
175
+ });
176
+ };
177
+ RpcProvider.prototype.getTransactionByHash = function (txHash) {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ return __generator(this, function (_a) {
180
+ return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [txHash])];
181
+ });
182
+ });
183
+ };
184
+ RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ return __generator(this, function (_a) {
187
+ return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [blockIdentifier, index])];
145
188
  });
146
189
  });
147
190
  };
@@ -152,11 +195,15 @@ var RpcProvider = /** @class */ (function () {
152
195
  });
153
196
  });
154
197
  };
155
- RpcProvider.prototype.getClassAt = function (contractAddress, _blockIdentifier) {
156
- if (_blockIdentifier === void 0) { _blockIdentifier = 'pending'; }
198
+ RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
157
199
  return __awaiter(this, void 0, void 0, function () {
200
+ var blockIdentifierGetter;
158
201
  return __generator(this, function (_a) {
159
- return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [contractAddress])];
202
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
203
+ return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [
204
+ blockIdentifierGetter.getIdentifier(),
205
+ contractAddress,
206
+ ])];
160
207
  });
161
208
  });
162
209
  };
@@ -170,7 +217,7 @@ var RpcProvider = /** @class */ (function () {
170
217
  contract_address: invocation.contractAddress,
171
218
  entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
172
219
  calldata: (0, provider_1.parseCalldata)(invocation.calldata),
173
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(invocation.signature || []),
220
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
174
221
  version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
175
222
  },
176
223
  blockIdentifier,
@@ -202,7 +249,7 @@ var RpcProvider = /** @class */ (function () {
202
249
  contractDefinition = (0, provider_1.parseContract)(contract);
203
250
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', [
204
251
  addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
205
- (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
252
+ (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
206
253
  {
207
254
  program: contractDefinition.program,
208
255
  entry_points_by_type: contractDefinition.entry_points_by_type,
@@ -220,7 +267,7 @@ var RpcProvider = /** @class */ (function () {
220
267
  entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
221
268
  calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
222
269
  },
223
- (0, number_1.bigNumberishArrayToDecimalStringArray)(functionInvocation.signature || []),
270
+ (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
224
271
  (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
225
272
  (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
226
273
  ]).then(this.responseParser.parseInvokeFunctionResponse)];
@@ -248,16 +295,10 @@ var RpcProvider = /** @class */ (function () {
248
295
  });
249
296
  });
250
297
  };
251
- RpcProvider.prototype.getCode = function (contractAddress, _blockIdentifier) {
298
+ RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
252
299
  return __awaiter(this, void 0, void 0, function () {
253
- var result;
254
300
  return __generator(this, function (_a) {
255
- switch (_a.label) {
256
- case 0: return [4 /*yield*/, this.fetchEndpoint('starknet_getCode', [contractAddress])];
257
- case 1:
258
- result = _a.sent();
259
- return [2 /*return*/, this.responseParser.parseGetCodeResponse(result)];
260
- }
301
+ throw new Error('RPC 0.1.0 does not implement getCode function');
261
302
  });
262
303
  });
263
304
  };
@@ -325,11 +366,12 @@ var RpcProvider = /** @class */ (function () {
325
366
  */
326
367
  RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
327
368
  return __awaiter(this, void 0, void 0, function () {
369
+ var blockIdentifierGetter;
328
370
  return __generator(this, function (_a) {
329
- if (typeof blockIdentifier === 'number') {
330
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCountByNumber', [blockIdentifier])];
331
- }
332
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCountByHash', [blockIdentifier])];
371
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
372
+ return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', [
373
+ blockIdentifierGetter.getIdentifier(),
374
+ ])];
333
375
  });
334
376
  });
335
377
  };
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
4
4
  import { BigNumberish } from '../utils/number';
5
5
  import { ProviderInterface } from './interface';
@@ -29,7 +29,7 @@ export declare class SequencerProvider implements ProviderInterface {
29
29
  protected fetchEndpoint<T extends keyof Sequencer.Endpoints>(endpoint: T, ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Sequencer.Endpoints[T]['REQUEST']] : Sequencer.Endpoints[T]['REQUEST'] extends never ? [Sequencer.Endpoints[T]['QUERY']] : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']]): Promise<Sequencer.Endpoints[T]['RESPONSE']>;
30
30
  callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
31
31
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
32
- getStorageAt(contractAddress: string, key: BigNumberish, blockHashOrTag?: BlockTag | BigNumberish): Promise<BigNumberish>;
32
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
33
33
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
34
34
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
35
35
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
@@ -249,14 +249,14 @@ var SequencerProvider = /** @class */ (function () {
249
249
  });
250
250
  });
251
251
  };
252
- SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockHashOrTag) {
253
- if (blockHashOrTag === void 0) { blockHashOrTag = 'pending'; }
252
+ SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
253
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
254
254
  return __awaiter(this, void 0, void 0, function () {
255
255
  var parsedKey;
256
256
  return __generator(this, function (_a) {
257
257
  parsedKey = (0, number_1.toBN)(key).toString(10);
258
258
  return [2 /*return*/, this.fetchEndpoint('get_storage_at', {
259
- blockIdentifier: blockHashOrTag,
259
+ blockIdentifier: blockIdentifier,
260
260
  contractAddress: contractAddress,
261
261
  key: parsedKey,
262
262
  })];
@@ -359,7 +359,7 @@ var SequencerProvider = /** @class */ (function () {
359
359
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
360
360
  return __awaiter(this, void 0, void 0, function () {
361
361
  return __generator(this, function (_a) {
362
- return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetCodeResponse)];
362
+ return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })];
363
363
  });
364
364
  });
365
365
  };
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import type { BlockNumber } from '../types';
2
3
  import { BigNumberish } from '../utils/number';
3
4
  /**
@@ -23,6 +24,17 @@ declare type BlockIdentifierObject = {
23
24
  type: 'BLOCK_HASH';
24
25
  data: BigNumberish;
25
26
  };
27
+ export declare class BlockIdentifierClass {
28
+ blockIdentifier: BlockIdentifier;
29
+ constructor(blockIdentifier: BlockIdentifier);
30
+ getIdentifier(): string | import("bn.js") | {
31
+ block_hash: string;
32
+ block_number?: undefined;
33
+ } | {
34
+ block_number: number;
35
+ block_hash?: undefined;
36
+ } | null;
37
+ }
26
38
  /**
27
39
  * Identifies the block to be queried.
28
40
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
3
+ exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.BlockIdentifierClass = exports.txIdentifier = exports.formatHash = void 0;
4
4
  var number_1 = require("../utils/number");
5
5
  /**
6
6
  *
@@ -29,6 +29,22 @@ function txIdentifier(txHash, txId) {
29
29
  return "transactionHash=".concat(hashString);
30
30
  }
31
31
  exports.txIdentifier = txIdentifier;
32
+ var BlockIdentifierClass = /** @class */ (function () {
33
+ function BlockIdentifierClass(blockIdentifier) {
34
+ this.blockIdentifier = blockIdentifier;
35
+ }
36
+ BlockIdentifierClass.prototype.getIdentifier = function () {
37
+ if (typeof this.blockIdentifier === 'string' && (0, number_1.isHex)(this.blockIdentifier)) {
38
+ return { block_hash: this.blockIdentifier };
39
+ }
40
+ if (typeof this.blockIdentifier === 'number') {
41
+ return { block_number: this.blockIdentifier };
42
+ }
43
+ return this.blockIdentifier;
44
+ };
45
+ return BlockIdentifierClass;
46
+ }());
47
+ exports.BlockIdentifierClass = BlockIdentifierClass;
32
48
  /**
33
49
  * Identifies the block to be queried.
34
50
  *
@@ -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: 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>;
@@ -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 () {
@@ -0,0 +1,151 @@
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
+ * "type": "string",
10
+ * "title": "Field element",
11
+ * "$comment": "A field element, represented as a string of hex digits",
12
+ * "description": "A field element. Represented as up to 63 hex digits and leading 4 bits zeroed.",
13
+ * "pattern": "^0x0[a-fA-F0-9]{1,63}$"
14
+ */
15
+ declare type FELT = string;
16
+ declare type BLOCK_NUMBER = number;
17
+ declare type BLOCK_HASH = FELT;
18
+ declare type TXN_HASH = FELT;
19
+ declare type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
20
+ declare type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
21
+ declare type MSG_TO_L1 = {
22
+ to_address: FELT;
23
+ payload: Array<FELT>;
24
+ };
25
+ declare type EVENT = {
26
+ from_address: FELT;
27
+ keys: Array<FELT>;
28
+ data: Array<FELT>;
29
+ };
30
+ declare type COMMON_RECEIPT_PROPERTIES = {
31
+ transaction_hash: TXN_HASH;
32
+ actual_fee: FELT;
33
+ status: TXN_STATUS;
34
+ block_hash: BLOCK_HASH;
35
+ block_number: BLOCK_NUMBER;
36
+ type?: TXN_TYPE;
37
+ };
38
+ declare type INVOKE_TXN_RECEIPT_PROPERTIES = {
39
+ messages_sent: MSG_TO_L1;
40
+ events: EVENT;
41
+ };
42
+ declare type PENDING_COMMON_RECEIPT_PROPERTIES = {
43
+ transaction_hash: TXN_HASH;
44
+ actual_fee: FELT;
45
+ type?: TXN_TYPE;
46
+ };
47
+ declare type INVOKE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
48
+ declare type L1_HANDLER_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
49
+ declare type DECLARE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
50
+ declare type DEPLOY_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
51
+ declare type PENDING_INVOKE_TXN_RECEIPT = PENDING_COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
52
+ declare type PENDING_TXN_RECEIPT = PENDING_INVOKE_TXN_RECEIPT | PENDING_COMMON_RECEIPT_PROPERTIES;
53
+ declare type TXN_RECEIPT = INVOKE_TXN_RECEIPT | L1_HANDLER_TXN_RECEIPT | DECLARE_TXN_RECEIPT | DEPLOY_TXN_RECEIPT | PENDING_TXN_RECEIPT;
54
+ export declare namespace RPC_1 {
55
+ type GetTransactionReceiptResponse = TXN_RECEIPT;
56
+ type Methods = {
57
+ starknet_getTransactionReceipt: {
58
+ QUERY: never;
59
+ REQUEST: any[];
60
+ RESPONSE: GetTransactionReceiptResponse;
61
+ };
62
+ };
63
+ }
64
+ declare type BLOCK_HEADER = {
65
+ block_hash: BLOCK_HASH;
66
+ parent_hash: BLOCK_HASH;
67
+ block_number: BLOCK_NUMBER;
68
+ new_root: FELT;
69
+ timestamp: number;
70
+ sequencer_address: FELT;
71
+ };
72
+ declare type BLOCK_BODY_WITH_TX_HASHES = {
73
+ transactions: Array<TXN_HASH>;
74
+ };
75
+ declare type BLOCK_WITH_TX_HASHES = {
76
+ status: TXN_STATUS;
77
+ } & BLOCK_HEADER & BLOCK_BODY_WITH_TX_HASHES;
78
+ declare type PENDING_BLOCK_WITH_TX_HASHES = BLOCK_BODY_WITH_TX_HASHES & {
79
+ timestamp: number;
80
+ sequencer_address: FELT;
81
+ parent_hash: BLOCK_HASH;
82
+ };
83
+ declare type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
84
+ /**
85
+ * "title": "An integer number in hex format (0x...)",
86
+ * "pattern": "^0x[a-fA-F0-9]+$"
87
+ */
88
+ declare type NUM_AS_HEX = string;
89
+ declare type SIGNATURE = Array<FELT>;
90
+ declare type COMMON_TXN_PROPERTIES = {
91
+ transaction_hash: TXN_HASH;
92
+ max_fee: FELT;
93
+ version: NUM_AS_HEX;
94
+ signature: SIGNATURE;
95
+ nonce: FELT;
96
+ type: TXN_TYPE;
97
+ };
98
+ declare type ADDRESS = FELT;
99
+ declare type FUNCTION_CALL = {
100
+ contract_address: ADDRESS;
101
+ entry_point_selector: FELT;
102
+ calldata: Array<FELT>;
103
+ };
104
+ declare type INVOKE_TXN = COMMON_TXN_PROPERTIES & FUNCTION_CALL;
105
+ declare type DECLARE_TXN = COMMON_TXN_PROPERTIES & {
106
+ class_hash: FELT;
107
+ sender_address: ADDRESS;
108
+ };
109
+ declare type DEPLOY_TXN = {
110
+ transaction_hash: TXN_HASH;
111
+ class_hash: FELT;
112
+ version: NUM_AS_HEX;
113
+ type: TXN_TYPE;
114
+ contract_address: FELT;
115
+ contract_address_salt: FELT;
116
+ constructor_calldata: Array<FELT>;
117
+ };
118
+ declare type TXN = INVOKE_TXN | DECLARE_TXN | DEPLOY_TXN;
119
+ declare type BLOCK_BODY_WITH_TXS = {
120
+ transactions: Array<TXN>;
121
+ };
122
+ declare type BLOCK_WITH_TXS = {
123
+ status: BLOCK_STATUS;
124
+ } & BLOCK_HEADER & BLOCK_BODY_WITH_TXS;
125
+ declare type PENDING_BLOCK_WITH_TXS = BLOCK_BODY_WITH_TXS & {
126
+ timestamp: number;
127
+ sequencer_address: FELT;
128
+ parent_hash: BLOCK_HASH;
129
+ };
130
+ declare type CONTRACT_CLASS = {
131
+ program: string;
132
+ entry_points_by_type: {
133
+ CONSTRUCTOR: CONTRACT_ENTRY_POINT_LIST;
134
+ EXTERNAL: CONTRACT_ENTRY_POINT_LIST;
135
+ L1_HANDLER: CONTRACT_ENTRY_POINT_LIST;
136
+ };
137
+ };
138
+ declare type CONTRACT_ENTRY_POINT_LIST = Array<CONTRACT_ENTRY_POINT>;
139
+ declare type CONTRACT_ENTRY_POINT = {
140
+ offset: NUM_AS_HEX;
141
+ selector: FELT;
142
+ };
143
+ export declare namespace OPENRPC {
144
+ type GetBlockWithTxHashesResponse = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
145
+ type GetBlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
146
+ type GetStorageAtResponse = FELT;
147
+ type GetTransactionByHashResponse = TXN;
148
+ type GetTransactionByBlockIdAndIndex = TXN;
149
+ type GetClassResponse = CONTRACT_CLASS;
150
+ }
151
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Starknet RPC version 0.1.0
4
+ * starknet_api_openrpc version 0.31.0
5
+ *
6
+ * TypeScript Representation of OpenRpc protocol types | results
7
+ * errors are not implemented here only results
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });