starknet 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # [2.8.0](https://github.com/seanjameshan/starknet.js/compare/v2.7.2...v2.8.0) (2022-02-02)
2
+
3
+ ### Features
4
+
5
+ - add tests ([e495d48](https://github.com/seanjameshan/starknet.js/commit/e495d4899141a79fe310d4fe76f70df03b1551ca))
6
+ - implement verifyMessage and verifyMessageHash ([bc9c4e9](https://github.com/seanjameshan/starknet.js/commit/bc9c4e9574cc453af35705eb4488602ea33cc2cb))
7
+
8
+ ## [2.7.2](https://github.com/seanjameshan/starknet.js/compare/v2.7.1...v2.7.2) (2022-01-20)
9
+
10
+ ### Bug Fixes
11
+
12
+ - **CONTRIBUTING:** wrong link ([2622a6c](https://github.com/seanjameshan/starknet.js/commit/2622a6c984259a6928e9ab02892b8de60b8c749e))
13
+
14
+ ## [2.7.1](https://github.com/seanjameshan/starknet.js/compare/v2.7.0...v2.7.1) (2022-01-04)
15
+
16
+ ### Bug Fixes
17
+
18
+ - **types:** add block_number property to GetBlockResponse interface ([696cf5a](https://github.com/seanjameshan/starknet.js/commit/696cf5ae565bd16365045cc1f20e9fa55184d054))
19
+
20
+ # [2.7.0](https://github.com/seanjameshan/starknet.js/compare/v2.6.0...v2.7.0) (2022-01-03)
21
+
22
+ ### Bug Fixes
23
+
24
+ - add response to the waitForTx error ([e25bdfd](https://github.com/seanjameshan/starknet.js/commit/e25bdfd428fd36e105ed272ea39462845bae5805))
25
+
26
+ ### Features
27
+
28
+ - **blockHash:** add blockHash and fix test cases ([4e107eb](https://github.com/seanjameshan/starknet.js/commit/4e107eb7e97a9b8d2efd74b2074a7d82365c932e))
29
+
1
30
  # [2.6.0](https://github.com/seanjameshan/starknet.js/compare/v2.5.0...v2.6.0) (2021-12-29)
2
31
 
3
32
  ### Bug Fixes
package/CONTRIBUTING.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  We love pull requests. And following this guidelines will make your pull request easier to merge.
4
4
 
5
- If you want to contribute but don’t know what to do, take a look at these two labels: [help wanted](https://github.com/seanjameshan/starknet/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [good first issue](https://github.com/seanjameshan/starknet/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).
5
+ If you want to contribute but don’t know what to do, take a look at these two labels: [help wanted](https://github.com/seanjameshan/starknet.js/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [good first issue](https://github.com/seanjameshan/starknet.js/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).
6
6
 
7
7
  _[Use GitHub interface](https://blog.sapegin.me/all/open-source-for-everyone/) for simple documentation changes, otherwise follow the steps below._
8
8
 
package/README.md CHANGED
@@ -58,7 +58,7 @@ const CONTRACT_ADDRESS =
58
58
  **/
59
59
 
60
60
  /** Reset the liquidity pool **/
61
- const addTokenResponse = await provider.addTransaction({
61
+ const addTokenResponse = await defaultProvider.addTransaction({
62
62
  type: "INVOKE_FUNCTION",
63
63
  contract_address: CONTRACT_ADDRESS,
64
64
  entry_point_selector: getSelectorFromName("init_pool"),
@@ -71,7 +71,7 @@ console.log(addTokenResponse);
71
71
  **/
72
72
 
73
73
  /** Get the balance of the liquidity pool of token A **/
74
- const poolBalanceTokenA = await callContract({
74
+ const poolBalanceTokenA = await defaultProvider.callContract({
75
75
  contract_address: CONTRACT_ADDRESS,
76
76
  entry_point_selector: getSelectorFromName("get_pool_token_balance"),
77
77
  calldata: ["1"],
@@ -80,7 +80,7 @@ const balanceA = poolBalanceTokenA.result[0];
80
80
  console.log('token a liquidity pool balance: ', parseInt(balanceA, 16));
81
81
 
82
82
  /** Get the balance of the liquidity pool of token B **/
83
- const poolBalanceTokenB = await callContract({
83
+ const poolBalanceTokenB = await defaultProvider.callContract({
84
84
  contract_address: CONTRACT_ADDRESS,
85
85
  entry_point_selector: getSelectorFromName("get_pool_token_balance"),
86
86
  calldata: ["2"],
@@ -0,0 +1,35 @@
1
+ {
2
+ "types": {
3
+ "StarkNetDomain": [
4
+ { "name": "name", "type": "felt" },
5
+ { "name": "version", "type": "felt" },
6
+ { "name": "chainId", "type": "felt" }
7
+ ],
8
+ "Person": [
9
+ { "name": "name", "type": "felt" },
10
+ { "name": "wallet", "type": "felt" }
11
+ ],
12
+ "Mail": [
13
+ { "name": "from", "type": "Person" },
14
+ { "name": "to", "type": "Person" },
15
+ { "name": "contents", "type": "felt" }
16
+ ]
17
+ },
18
+ "primaryType": "Mail",
19
+ "domain": {
20
+ "name": "StarkNet Mail",
21
+ "version": "1",
22
+ "chainId": 1
23
+ },
24
+ "message": {
25
+ "from": {
26
+ "name": "Cow",
27
+ "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
28
+ },
29
+ "to": {
30
+ "name": "Bob",
31
+ "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
32
+ },
33
+ "contents": "Hello, Bob!"
34
+ }
35
+ }
@@ -13,38 +13,53 @@ describe('defaultProvider', () => {
13
13
  expect(typeof GpsStatementVerifier).toBe('string');
14
14
  expect(typeof Starknet).toBe('string');
15
15
  });
16
- test('getBlock()', () => {
17
- return expect(defaultProvider.getBlock(870)).resolves.not.toThrow();
16
+ test('getBlock(blockHash=0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d, blockNumber=undefined)', () => {
17
+ return expect(
18
+ defaultProvider.getBlock(
19
+ '0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d'
20
+ )
21
+ ).resolves.not.toThrow();
22
+ });
23
+ test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
24
+ return expect(defaultProvider.getBlock(undefined, 36657)).resolves.not.toThrow();
18
25
  });
19
- test('getBlock(blockNumber=null)', () => {
26
+ test('getBlock(blockHash=undefined, blockNumber=null)', () => {
20
27
  return expect(defaultProvider.getBlock()).resolves.not.toThrow();
21
28
  });
29
+ test('getBlock() -> { blockNumber }', async () => {
30
+ const block = await defaultProvider.getBlock();
31
+ return expect(block).toHaveProperty('block_number');
32
+ });
22
33
  test('getCode()', () => {
23
34
  return expect(
24
35
  defaultProvider.getCode(
25
- '0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61',
26
- 870
36
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
37
+ undefined,
38
+ 36663
27
39
  )
28
40
  ).resolves.not.toThrow();
29
41
  });
30
- test('getCode(blockNumber=null)', () => {
42
+ test('getCode(blockHash=undefined, blockNumber=null)', () => {
31
43
  return expect(
32
- defaultProvider.getCode('0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61')
44
+ defaultProvider.getCode(
45
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166'
46
+ )
33
47
  ).resolves.not.toThrow();
34
48
  });
35
49
  test('getStorageAt()', () => {
36
50
  return expect(
37
51
  defaultProvider.getStorageAt(
38
- '0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61',
52
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
39
53
  0,
40
- 870
54
+ undefined,
55
+ 36663
41
56
  )
42
57
  ).resolves.not.toThrow();
43
58
  });
44
- test('getStorageAt(blockNumber=null)', () => {
59
+ test('getStorageAt(blockHash=undefined, blockNumber=null)', () => {
45
60
  return expect(
46
61
  defaultProvider.getStorageAt(
47
- '0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61',
62
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
48
63
  0
49
64
  )
50
65
  ).resolves.not.toThrow();
@@ -52,14 +67,14 @@ describe('defaultProvider', () => {
52
67
  test('getTransactionStatus()', async () => {
53
68
  return expect(
54
69
  defaultProvider.getTransactionStatus(
55
- '0x72add9621ecdcb07405a4f943fe410bf57003ca250400f01ce70f8a6fc72147'
70
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
56
71
  )
57
72
  ).resolves.not.toThrow();
58
73
  });
59
74
  test('getTransaction()', async () => {
60
75
  return expect(
61
76
  defaultProvider.getTransaction(
62
- '0x72add9621ecdcb07405a4f943fe410bf57003ca250400f01ce70f8a6fc72147'
77
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
63
78
  )
64
79
  ).resolves.not.toThrow();
65
80
  });
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
 
3
+ import typedDataExample from '../__mocks__/typedDataExample.json';
3
4
  import {
4
5
  CompiledContract,
5
6
  Contract,
@@ -116,4 +117,9 @@ describe('deploy and test Wallet', () => {
116
117
  expect(code).toBe('TRANSACTION_RECEIVED');
117
118
  await defaultProvider.waitForTx(transaction_hash);
118
119
  });
120
+ test('sign and verify offchain message', async () => {
121
+ const signature = await signer.signMessage(typedDataExample);
122
+
123
+ expect(await signer.verifyMessage(typedDataExample, signature)).toBe(true);
124
+ });
119
125
  });
@@ -1,41 +1,6 @@
1
+ import typedDataExample from '../../__mocks__/typedDataExample.json';
1
2
  import { encodeType, getMessageHash, getStructHash, getTypeHash } from '../../src/utils/typedData';
2
3
 
3
- const typedDataExample = {
4
- types: {
5
- StarkNetDomain: [
6
- { name: 'name', type: 'felt' },
7
- { name: 'version', type: 'felt' },
8
- { name: 'chainId', type: 'felt' },
9
- ],
10
- Person: [
11
- { name: 'name', type: 'felt' },
12
- { name: 'wallet', type: 'felt' },
13
- ],
14
- Mail: [
15
- { name: 'from', type: 'Person' },
16
- { name: 'to', type: 'Person' },
17
- { name: 'contents', type: 'felt' },
18
- ],
19
- },
20
- primaryType: 'Mail',
21
- domain: {
22
- name: 'StarkNet Mail',
23
- version: '1',
24
- chainId: 1,
25
- },
26
- message: {
27
- from: {
28
- name: 'Cow',
29
- wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
30
- },
31
- to: {
32
- name: 'Bob',
33
- wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
34
- },
35
- contents: 'Hello, Bob!',
36
- },
37
- };
38
-
39
4
  describe('typedData', () => {
40
5
  test('should get right type encoding', () => {
41
6
  const typeEncoding = encodeType(typedDataExample, 'Mail');
@@ -23,43 +23,47 @@ export declare class Provider implements ProviderInterface {
23
23
  /**
24
24
  * Calls a function on the StarkNet contract.
25
25
  *
26
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
26
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
27
27
  *
28
28
  * @param invokeTransaction - transaction to be invoked
29
+ * @param blockHash
29
30
  * @param blockNumber
30
31
  * @returns the result of the function on the smart contract.
31
32
  */
32
- callContract(invokeTransaction: CallContractTransaction, blockNumber?: BlockNumber): Promise<CallContractResponse>;
33
+ callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
33
34
  /**
34
- * Gets the block information from a block ID.
35
+ * Gets the block information
35
36
  *
36
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
37
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
37
38
  *
39
+ * @param blockHash
38
40
  * @param blockNumber
39
41
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
40
42
  */
41
- getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
43
+ getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
42
44
  /**
43
45
  * Gets the code of the deployed contract.
44
46
  *
45
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
47
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
46
48
  *
47
49
  * @param contractAddress
50
+ * @param blockHash
48
51
  * @param blockNumber
49
52
  * @returns Bytecode and ABI of compiled contract
50
53
  */
51
- getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
54
+ getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
52
55
  /**
53
56
  * Gets the contract's storage variable at a specific key.
54
57
  *
55
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
58
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
56
59
  *
57
60
  * @param contractAddress
58
61
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
62
+ * @param blockHash
59
63
  * @param blockNumber
60
64
  * @returns the value of the storage variable
61
65
  */
62
- getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
66
+ getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
63
67
  /**
64
68
  * Gets the status of a transaction.
65
69
  *
@@ -56,6 +56,7 @@ var url_join_1 = __importDefault(require("url-join"));
56
56
  var json_1 = require("../utils/json");
57
57
  var number_1 = require("../utils/number");
58
58
  var stark_1 = require("../utils/stark");
59
+ var utils_1 = require("./utils");
59
60
  function wait(delay) {
60
61
  return new Promise(function (res) { return setTimeout(res, delay); });
61
62
  }
@@ -107,19 +108,22 @@ var Provider = /** @class */ (function () {
107
108
  /**
108
109
  * Calls a function on the StarkNet contract.
109
110
  *
110
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
111
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
111
112
  *
112
113
  * @param invokeTransaction - transaction to be invoked
114
+ * @param blockHash
113
115
  * @param blockNumber
114
116
  * @returns the result of the function on the smart contract.
115
117
  */
116
- Provider.prototype.callContract = function (invokeTransaction, blockNumber) {
118
+ Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
117
119
  if (blockNumber === void 0) { blockNumber = null; }
118
120
  return __awaiter(this, void 0, void 0, function () {
119
- var data;
121
+ var formattedBlockIdentifier, data;
120
122
  return __generator(this, function (_a) {
121
123
  switch (_a.label) {
122
- case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockNumber=" + blockNumber), __assign({ signature: [], calldata: [] }, invokeTransaction))];
124
+ case 0:
125
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
126
+ return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier), __assign({ signature: [], calldata: [] }, invokeTransaction))];
123
127
  case 1:
124
128
  data = (_a.sent()).data;
125
129
  return [2 /*return*/, data];
@@ -128,20 +132,23 @@ var Provider = /** @class */ (function () {
128
132
  });
129
133
  };
130
134
  /**
131
- * Gets the block information from a block ID.
135
+ * Gets the block information
132
136
  *
133
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
137
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
134
138
  *
139
+ * @param blockHash
135
140
  * @param blockNumber
136
141
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
137
142
  */
138
- Provider.prototype.getBlock = function (blockNumber) {
143
+ Provider.prototype.getBlock = function (blockHash, blockNumber) {
139
144
  if (blockNumber === void 0) { blockNumber = null; }
140
145
  return __awaiter(this, void 0, void 0, function () {
141
- var data;
146
+ var formattedBlockIdentifier, data;
142
147
  return __generator(this, function (_a) {
143
148
  switch (_a.label) {
144
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', "?blockNumber=" + blockNumber))];
149
+ case 0:
150
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
151
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier))];
145
152
  case 1:
146
153
  data = (_a.sent()).data;
147
154
  return [2 /*return*/, data];
@@ -152,19 +159,22 @@ var Provider = /** @class */ (function () {
152
159
  /**
153
160
  * Gets the code of the deployed contract.
154
161
  *
155
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
162
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
156
163
  *
157
164
  * @param contractAddress
165
+ * @param blockHash
158
166
  * @param blockNumber
159
167
  * @returns Bytecode and ABI of compiled contract
160
168
  */
161
- Provider.prototype.getCode = function (contractAddress, blockNumber) {
169
+ Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
162
170
  if (blockNumber === void 0) { blockNumber = null; }
163
171
  return __awaiter(this, void 0, void 0, function () {
164
- var data;
172
+ var formattedBlockIdentifier, data;
165
173
  return __generator(this, function (_a) {
166
174
  switch (_a.label) {
167
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&blockNumber=" + blockNumber))];
175
+ case 0:
176
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
177
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&" + formattedBlockIdentifier))];
168
178
  case 1:
169
179
  data = (_a.sent()).data;
170
180
  return [2 /*return*/, data];
@@ -176,20 +186,23 @@ var Provider = /** @class */ (function () {
176
186
  /**
177
187
  * Gets the contract's storage variable at a specific key.
178
188
  *
179
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
189
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
180
190
  *
181
191
  * @param contractAddress
182
192
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
193
+ * @param blockHash
183
194
  * @param blockNumber
184
195
  * @returns the value of the storage variable
185
196
  */
186
- Provider.prototype.getStorageAt = function (contractAddress, key, blockNumber) {
197
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
187
198
  if (blockNumber === void 0) { blockNumber = null; }
188
199
  return __awaiter(this, void 0, void 0, function () {
189
- var data;
200
+ var formattedBlockIdentifier, data;
190
201
  return __generator(this, function (_a) {
191
202
  switch (_a.label) {
192
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&blockNumber=" + blockNumber))];
203
+ case 0:
204
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
205
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&" + formattedBlockIdentifier))];
193
206
  case 1:
194
207
  data = (_a.sent()).data;
195
208
  return [2 /*return*/, data];
@@ -307,7 +320,7 @@ var Provider = /** @class */ (function () {
307
320
  Provider.prototype.waitForTx = function (txHash, retryInterval) {
308
321
  if (retryInterval === void 0) { retryInterval = 8000; }
309
322
  return __awaiter(this, void 0, void 0, function () {
310
- var onchain, res;
323
+ var onchain, res, error;
311
324
  return __generator(this, function (_a) {
312
325
  switch (_a.label) {
313
326
  case 0:
@@ -329,11 +342,10 @@ var Provider = /** @class */ (function () {
329
342
  if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
330
343
  onchain = true;
331
344
  }
332
- else if (res.tx_status === 'REJECTED') {
333
- throw Error('REJECTED');
334
- }
335
- else if (res.tx_status === 'NOT_RECEIVED') {
336
- throw Error('NOT_RECEIVED');
345
+ else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
346
+ error = Error(res.tx_status);
347
+ error.response = res;
348
+ throw error;
337
349
  }
338
350
  return [3 /*break*/, 2];
339
351
  case 5: return [2 /*return*/];
@@ -14,43 +14,47 @@ export declare abstract class ProviderInterface {
14
14
  /**
15
15
  * Calls a function on the StarkNet contract.
16
16
  *
17
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
17
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
18
18
  *
19
19
  * @param invokeTransaction - transaction to be invoked
20
+ * @param blockHash
20
21
  * @param blockNumber
21
22
  * @returns the result of the function on the smart contract.
22
23
  */
23
- abstract callContract(invokeTransaction: CallContractTransaction, blockNumber?: BlockNumber): Promise<CallContractResponse>;
24
+ abstract callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
24
25
  /**
25
- * Gets the block information from a block ID.
26
+ * Gets the block information
26
27
  *
27
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
28
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
28
29
  *
30
+ * @param blockHash
29
31
  * @param blockNumber
30
32
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
31
33
  */
32
- abstract getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
34
+ abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
33
35
  /**
34
36
  * Gets the code of the deployed contract.
35
37
  *
36
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
38
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
37
39
  *
38
40
  * @param contractAddress
41
+ * @param blockHash
39
42
  * @param blockNumber
40
43
  * @returns Bytecode and ABI of compiled contract
41
44
  */
42
- abstract getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
45
+ abstract getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
43
46
  /**
44
47
  * Gets the contract's storage variable at a specific key.
45
48
  *
46
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
49
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
47
50
  *
48
51
  * @param contractAddress
49
52
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
53
+ * @param blockHash
50
54
  * @param blockNumber
51
55
  * @returns the value of the storage variable
52
56
  */
53
- abstract getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
57
+ abstract getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
54
58
  /**
55
59
  * Gets the status of a transaction.
56
60
  *
@@ -0,0 +1,27 @@
1
+ import type { BlockNumber } from '../types';
2
+ import { BigNumberish } from '../utils/number';
3
+ /**
4
+ * TODO
5
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
6
+ *
7
+ * @param hashValue
8
+ * @param hashField
9
+ */
10
+ export declare function formatHash(): void;
11
+ /**
12
+ * TODO
13
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
14
+ * @param txHash
15
+ * @param txId
16
+ */
17
+ export declare function txIdentifier(): void;
18
+ /**
19
+ * Gets the block identifier for API request
20
+ *
21
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
22
+ *
23
+ * @param blockNumber
24
+ * @param blockHash
25
+ * @returns block identifier for API request
26
+ */
27
+ export declare function getFormattedBlockIdentifier(blockHash?: BigNumberish, blockNumber?: BlockNumber): string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFormattedBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
4
+ /**
5
+ * TODO
6
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
7
+ *
8
+ * @param hashValue
9
+ * @param hashField
10
+ */
11
+ function formatHash() { }
12
+ exports.formatHash = formatHash;
13
+ /**
14
+ * TODO
15
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
16
+ * @param txHash
17
+ * @param txId
18
+ */
19
+ function txIdentifier() { }
20
+ exports.txIdentifier = txIdentifier;
21
+ /**
22
+ * Gets the block identifier for API request
23
+ *
24
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
25
+ *
26
+ * @param blockNumber
27
+ * @param blockHash
28
+ * @returns block identifier for API request
29
+ */
30
+ function getFormattedBlockIdentifier(blockHash, blockNumber) {
31
+ if (blockNumber === void 0) { blockNumber = null; }
32
+ if (blockHash) {
33
+ return "?blockHash=" + blockHash;
34
+ }
35
+ return "?blockNumber=" + blockNumber;
36
+ }
37
+ exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
@@ -1,5 +1,6 @@
1
1
  import { Provider } from '../provider';
2
2
  import { AddTransactionResponse, KeyPair, Signature, Transaction } from '../types';
3
+ import { BigNumberish } from '../utils/number';
3
4
  import { TypedData } from '../utils/typedData';
4
5
  import { SignerInterface } from './interface';
5
6
  export declare class Signer extends Provider implements SignerInterface {
@@ -31,4 +32,23 @@ export declare class Signer extends Provider implements SignerInterface {
31
32
  * @throws {Error} if the JSON object is not a valid JSON
32
33
  */
33
34
  hashMessage(typedData: TypedData): Promise<string>;
35
+ /**
36
+ * Verify a signature of a JSON object
37
+ *
38
+ * @param json - JSON object to be verified
39
+ * @param signature - signature of the JSON object
40
+ * @returns true if the signature is valid, false otherwise
41
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
42
+ */
43
+ verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
44
+ /**
45
+ * Verify a signature of a given hash
46
+ * @warning This method is not recommended, use verifyMessage instead
47
+ *
48
+ * @param hash - hash to be verified
49
+ * @param signature - signature of the hash
50
+ * @returns true if the signature is valid, false otherwise
51
+ * @throws {Error} if the signature is not a valid signature
52
+ */
53
+ verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
34
54
  }