starknet 2.7.0 → 2.9.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +3 -3
  4. package/__mocks__/typedDataExample.json +35 -0
  5. package/__tests__/provider.test.ts +5 -3
  6. package/__tests__/signer.test.ts +6 -0
  7. package/__tests__/utils/address.test.ts +16 -0
  8. package/__tests__/utils/typedData.test.ts +1 -36
  9. package/constants.d.ts +2 -0
  10. package/constants.js +4 -0
  11. package/dist/constants.d.ts +2 -0
  12. package/dist/constants.js +3 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/provider/default.d.ts +6 -5
  16. package/dist/provider/default.js +12 -12
  17. package/dist/provider/interface.d.ts +11 -14
  18. package/dist/provider/utils.d.ts +17 -1
  19. package/dist/provider/utils.js +39 -6
  20. package/dist/signer/default.d.ts +20 -0
  21. package/dist/signer/default.js +57 -0
  22. package/dist/signer/interface.d.ts +20 -0
  23. package/dist/types.d.ts +1 -1
  24. package/dist/utils/address.d.ts +2 -0
  25. package/dist/utils/address.js +22 -0
  26. package/index.d.ts +1 -0
  27. package/index.js +1 -0
  28. package/package.json +1 -1
  29. package/provider/default.d.ts +5 -11
  30. package/provider/default.js +16 -28
  31. package/provider/interface.d.ts +10 -17
  32. package/provider/utils.d.ts +19 -4
  33. package/provider/utils.js +44 -7
  34. package/signer/default.d.ts +20 -0
  35. package/signer/default.js +64 -0
  36. package/signer/interface.d.ts +20 -0
  37. package/src/constants.ts +2 -0
  38. package/src/index.ts +1 -0
  39. package/src/provider/default.ts +9 -16
  40. package/src/provider/interface.ts +10 -20
  41. package/src/provider/utils.ts +46 -9
  42. package/src/signer/default.ts +40 -1
  43. package/src/signer/interface.ts +22 -0
  44. package/src/types.ts +1 -1
  45. package/src/utils/address.ts +23 -0
  46. package/types.d.ts +1 -1
  47. package/utils/address.d.ts +2 -0
  48. package/utils/address.js +22 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # [2.9.0](https://github.com/seanjameshan/starknet.js/compare/v2.8.0...v2.9.0) (2022-02-04)
2
+
3
+ ### Bug Fixes
4
+
5
+ - introduce block identifier type ([75599a9](https://github.com/seanjameshan/starknet.js/commit/75599a99bbcb5723cfc8575b5fbf994a0bbf5b67))
6
+
7
+ ### Features
8
+
9
+ - **utils:** add validateAndParseAddress function ([c067fc4](https://github.com/seanjameshan/starknet.js/commit/c067fc443e4dc9c22b78ed6c093978a2f37debde))
10
+
11
+ # [2.8.0](https://github.com/seanjameshan/starknet.js/compare/v2.7.2...v2.8.0) (2022-02-02)
12
+
13
+ ### Features
14
+
15
+ - add tests ([e495d48](https://github.com/seanjameshan/starknet.js/commit/e495d4899141a79fe310d4fe76f70df03b1551ca))
16
+ - implement verifyMessage and verifyMessageHash ([bc9c4e9](https://github.com/seanjameshan/starknet.js/commit/bc9c4e9574cc453af35705eb4488602ea33cc2cb))
17
+
18
+ ## [2.7.2](https://github.com/seanjameshan/starknet.js/compare/v2.7.1...v2.7.2) (2022-01-20)
19
+
20
+ ### Bug Fixes
21
+
22
+ - **CONTRIBUTING:** wrong link ([2622a6c](https://github.com/seanjameshan/starknet.js/commit/2622a6c984259a6928e9ab02892b8de60b8c749e))
23
+
24
+ ## [2.7.1](https://github.com/seanjameshan/starknet.js/compare/v2.7.0...v2.7.1) (2022-01-04)
25
+
26
+ ### Bug Fixes
27
+
28
+ - **types:** add block_number property to GetBlockResponse interface ([696cf5a](https://github.com/seanjameshan/starknet.js/commit/696cf5ae565bd16365045cc1f20e9fa55184d054))
29
+
1
30
  # [2.7.0](https://github.com/seanjameshan/starknet.js/compare/v2.6.0...v2.7.0) (2022-01-03)
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
+ }
@@ -21,16 +21,19 @@ describe('defaultProvider', () => {
21
21
  ).resolves.not.toThrow();
22
22
  });
23
23
  test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
24
- return expect(defaultProvider.getBlock(undefined, 36657)).resolves.not.toThrow();
24
+ return expect(defaultProvider.getBlock(36657)).resolves.not.toThrow();
25
25
  });
26
26
  test('getBlock(blockHash=undefined, blockNumber=null)', () => {
27
27
  return expect(defaultProvider.getBlock()).resolves.not.toThrow();
28
28
  });
29
+ test('getBlock() -> { blockNumber }', async () => {
30
+ const block = await defaultProvider.getBlock();
31
+ return expect(block).toHaveProperty('block_number');
32
+ });
29
33
  test('getCode()', () => {
30
34
  return expect(
31
35
  defaultProvider.getCode(
32
36
  '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
33
- undefined,
34
37
  36663
35
38
  )
36
39
  ).resolves.not.toThrow();
@@ -47,7 +50,6 @@ describe('defaultProvider', () => {
47
50
  defaultProvider.getStorageAt(
48
51
  '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
49
52
  0,
50
- undefined,
51
53
  36663
52
54
  )
53
55
  ).resolves.not.toThrow();
@@ -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
  });
@@ -0,0 +1,16 @@
1
+ import { addAddressPadding, validateAndParseAddress } from '../../src/utils/address';
2
+ // import { addHexPrefix, removeHexPrefix } from '../../src/utils/encode';
3
+
4
+ describe('validateAndParseAddress', () => {
5
+ test('should pass when correct starknet address is passed', () => {
6
+ const addr = '0x7ee790591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf';
7
+
8
+ return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
9
+ });
10
+
11
+ test('should add 0x prefix if not provided', () => {
12
+ const addr = '0x6eff1d71068df8e6677f59a556151c56ed13e14ad431a9bef6fcb3fc5e6fa7';
13
+
14
+ return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
15
+ });
16
+ });
@@ -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');
package/constants.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const ZERO: import('bn.js');
4
4
  export declare const ONE: import('bn.js');
5
5
  export declare const TWO: import('bn.js');
6
6
  export declare const MASK_250: import('bn.js');
7
+ export declare const MASK_251: import('bn.js');
7
8
  /**
8
9
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
9
10
  * Please do not edit until the JSON changes.
@@ -11,6 +12,7 @@ export declare const MASK_250: import('bn.js');
11
12
  export declare const FIELD_PRIME =
12
13
  '800000000000011000000000000000000000000000000000000000000000001';
13
14
  export declare const FIELD_GEN = '3';
15
+ export declare const FIELD_SIZE = 251;
14
16
  export declare const EC_ORDER = '800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F';
15
17
  export declare const ALPHA = '1';
16
18
  export declare const BETA = '6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89';
package/constants.js CHANGED
@@ -5,8 +5,10 @@ exports.CONSTANT_POINTS =
5
5
  exports.BETA =
6
6
  exports.ALPHA =
7
7
  exports.EC_ORDER =
8
+ exports.FIELD_SIZE =
8
9
  exports.FIELD_GEN =
9
10
  exports.FIELD_PRIME =
11
+ exports.MASK_251 =
10
12
  exports.MASK_250 =
11
13
  exports.TWO =
12
14
  exports.ONE =
@@ -25,12 +27,14 @@ exports.ZERO = (0, number_1.toBN)(0);
25
27
  exports.ONE = (0, number_1.toBN)(1);
26
28
  exports.TWO = (0, number_1.toBN)(2);
27
29
  exports.MASK_250 = exports.TWO.pow((0, number_1.toBN)(250)).sub(exports.ONE); // 2 ** 250 - 1
30
+ exports.MASK_251 = exports.TWO.pow((0, number_1.toBN)(251));
28
31
  /**
29
32
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
30
33
  * Please do not edit until the JSON changes.
31
34
  */
32
35
  exports.FIELD_PRIME = '800000000000011000000000000000000000000000000000000000000000001';
33
36
  exports.FIELD_GEN = '3';
37
+ exports.FIELD_SIZE = 251;
34
38
  exports.EC_ORDER = '800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F';
35
39
  exports.ALPHA = '1';
36
40
  exports.BETA = '6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89';
@@ -4,12 +4,14 @@ export declare const ZERO: import("bn.js");
4
4
  export declare const ONE: import("bn.js");
5
5
  export declare const TWO: import("bn.js");
6
6
  export declare const MASK_250: import("bn.js");
7
+ export declare const MASK_251: import("bn.js");
7
8
  /**
8
9
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
9
10
  * Please do not edit until the JSON changes.
10
11
  */
11
12
  export declare const FIELD_PRIME = "800000000000011000000000000000000000000000000000000000000000001";
12
13
  export declare const FIELD_GEN = "3";
14
+ export declare const FIELD_SIZE = 251;
13
15
  export declare const EC_ORDER = "800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F";
14
16
  export declare const ALPHA = "1";
15
17
  export declare const BETA = "6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89";
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_GEN = exports.FIELD_PRIME = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
3
+ exports.CONSTANT_POINTS = exports.MAX_ECDSA_VAL = exports.BETA = exports.ALPHA = exports.EC_ORDER = exports.FIELD_SIZE = exports.FIELD_GEN = exports.FIELD_PRIME = exports.MASK_251 = exports.MASK_250 = exports.TWO = exports.ONE = exports.ZERO = exports.IS_BROWSER = void 0;
4
4
  var number_1 = require("./utils/number");
5
5
  var encode_1 = require("./utils/encode");
6
6
  Object.defineProperty(exports, "IS_BROWSER", { enumerable: true, get: function () { return encode_1.IS_BROWSER; } });
@@ -8,12 +8,14 @@ exports.ZERO = (0, number_1.toBN)(0);
8
8
  exports.ONE = (0, number_1.toBN)(1);
9
9
  exports.TWO = (0, number_1.toBN)(2);
10
10
  exports.MASK_250 = exports.TWO.pow((0, number_1.toBN)(250)).sub(exports.ONE); // 2 ** 250 - 1
11
+ exports.MASK_251 = exports.TWO.pow((0, number_1.toBN)(251));
11
12
  /**
12
13
  * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
13
14
  * Please do not edit until the JSON changes.
14
15
  */
15
16
  exports.FIELD_PRIME = '800000000000011000000000000000000000000000000000000000000000001';
16
17
  exports.FIELD_GEN = '3';
18
+ exports.FIELD_SIZE = 251;
17
19
  exports.EC_ORDER = '800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F';
18
20
  exports.ALPHA = '1';
19
21
  exports.BETA = '6F21413EFBE40DE150E596D72F7A8C5609AD26C15C915C1F4CDFCB99CEE9E89';
package/dist/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export * as ec from './utils/ellipticCurve';
18
18
  export * as uint256 from './utils/uint256';
19
19
  export * as shortString from './utils/shortString';
20
20
  export * as typedData from './utils/typedData';
21
+ export * from './utils/address';
package/dist/index.js CHANGED
@@ -43,3 +43,4 @@ exports.ec = __importStar(require("./utils/ellipticCurve"));
43
43
  exports.uint256 = __importStar(require("./utils/uint256"));
44
44
  exports.shortString = __importStar(require("./utils/shortString"));
45
45
  exports.typedData = __importStar(require("./utils/typedData"));
46
+ __exportStar(require("./utils/address"), exports);
@@ -1,6 +1,7 @@
1
- import { AddTransactionResponse, BlockNumber, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
1
+ import { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
2
2
  import { BigNumberish } from '../utils/number';
3
3
  import { ProviderInterface } from './interface';
4
+ import { BlockIdentifier } from './utils';
4
5
  declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
5
6
  declare type ProviderOptions = {
6
7
  network: NetworkName;
@@ -30,7 +31,7 @@ export declare class Provider implements ProviderInterface {
30
31
  * @param blockNumber
31
32
  * @returns the result of the function on the smart contract.
32
33
  */
33
- callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
34
+ callContract(invokeTransaction: CallContractTransaction, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
34
35
  /**
35
36
  * Gets the block information
36
37
  *
@@ -40,7 +41,7 @@ export declare class Provider implements ProviderInterface {
40
41
  * @param blockNumber
41
42
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
42
43
  */
43
- getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
44
+ getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
44
45
  /**
45
46
  * Gets the code of the deployed contract.
46
47
  *
@@ -51,7 +52,7 @@ export declare class Provider implements ProviderInterface {
51
52
  * @param blockNumber
52
53
  * @returns Bytecode and ABI of compiled contract
53
54
  */
54
- getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
55
+ getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
55
56
  /**
56
57
  * Gets the contract's storage variable at a specific key.
57
58
  *
@@ -63,7 +64,7 @@ export declare class Provider implements ProviderInterface {
63
64
  * @param blockNumber
64
65
  * @returns the value of the storage variable
65
66
  */
66
- getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
67
+ getStorageAt(contractAddress: string, key: number, blockIdentifier?: BlockIdentifier): Promise<object>;
67
68
  /**
68
69
  * Gets the status of a transaction.
69
70
  *
@@ -115,14 +115,14 @@ var Provider = /** @class */ (function () {
115
115
  * @param blockNumber
116
116
  * @returns the result of the function on the smart contract.
117
117
  */
118
- Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
119
- if (blockNumber === void 0) { blockNumber = null; }
118
+ Provider.prototype.callContract = function (invokeTransaction, blockIdentifier) {
119
+ if (blockIdentifier === void 0) { blockIdentifier = null; }
120
120
  return __awaiter(this, void 0, void 0, function () {
121
121
  var formattedBlockIdentifier, data;
122
122
  return __generator(this, function (_a) {
123
123
  switch (_a.label) {
124
124
  case 0:
125
- formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
125
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockIdentifier);
126
126
  return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier), __assign({ signature: [], calldata: [] }, invokeTransaction))];
127
127
  case 1:
128
128
  data = (_a.sent()).data;
@@ -140,14 +140,14 @@ var Provider = /** @class */ (function () {
140
140
  * @param blockNumber
141
141
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
142
142
  */
143
- Provider.prototype.getBlock = function (blockHash, blockNumber) {
144
- if (blockNumber === void 0) { blockNumber = null; }
143
+ Provider.prototype.getBlock = function (blockIdentifier) {
144
+ if (blockIdentifier === void 0) { blockIdentifier = null; }
145
145
  return __awaiter(this, void 0, void 0, function () {
146
146
  var formattedBlockIdentifier, data;
147
147
  return __generator(this, function (_a) {
148
148
  switch (_a.label) {
149
149
  case 0:
150
- formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
150
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockIdentifier);
151
151
  return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier))];
152
152
  case 1:
153
153
  data = (_a.sent()).data;
@@ -166,14 +166,14 @@ var Provider = /** @class */ (function () {
166
166
  * @param blockNumber
167
167
  * @returns Bytecode and ABI of compiled contract
168
168
  */
169
- Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
170
- if (blockNumber === void 0) { blockNumber = null; }
169
+ Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
170
+ if (blockIdentifier === void 0) { blockIdentifier = null; }
171
171
  return __awaiter(this, void 0, void 0, function () {
172
172
  var formattedBlockIdentifier, data;
173
173
  return __generator(this, function (_a) {
174
174
  switch (_a.label) {
175
175
  case 0:
176
- formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
176
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockIdentifier);
177
177
  return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&" + formattedBlockIdentifier))];
178
178
  case 1:
179
179
  data = (_a.sent()).data;
@@ -194,14 +194,14 @@ var Provider = /** @class */ (function () {
194
194
  * @param blockNumber
195
195
  * @returns the value of the storage variable
196
196
  */
197
- Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
198
- if (blockNumber === void 0) { blockNumber = null; }
197
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
198
+ if (blockIdentifier === void 0) { blockIdentifier = null; }
199
199
  return __awaiter(this, void 0, void 0, function () {
200
200
  var formattedBlockIdentifier, data;
201
201
  return __generator(this, function (_a) {
202
202
  switch (_a.label) {
203
203
  case 0:
204
- formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
204
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockIdentifier);
205
205
  return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&" + formattedBlockIdentifier))];
206
206
  case 1:
207
207
  data = (_a.sent()).data;
@@ -1,5 +1,6 @@
1
- import type { AddTransactionResponse, BlockNumber, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
1
+ import type { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
2
2
  import type { BigNumberish } from '../utils/number';
3
+ import { BlockIdentifier } from './utils';
3
4
  export declare abstract class ProviderInterface {
4
5
  abstract baseUrl: string;
5
6
  abstract feederGatewayUrl: string;
@@ -17,32 +18,29 @@ export declare abstract class ProviderInterface {
17
18
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
18
19
  *
19
20
  * @param invokeTransaction - transaction to be invoked
20
- * @param blockHash
21
- * @param blockNumber
21
+ * @param blockIdentifier - block identifier
22
22
  * @returns the result of the function on the smart contract.
23
23
  */
24
- abstract callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
24
+ abstract callContract(invokeTransaction: CallContractTransaction, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
25
25
  /**
26
26
  * Gets the block information
27
27
  *
28
28
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
29
29
  *
30
- * @param blockHash
31
- * @param blockNumber
30
+ * @param blockIdentifier - block identifier
32
31
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
33
32
  */
34
- abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
33
+ abstract getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
35
34
  /**
36
35
  * Gets the code of the deployed contract.
37
36
  *
38
37
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
39
38
  *
40
- * @param contractAddress
41
- * @param blockHash
42
- * @param blockNumber
39
+ * @param contractAddress - contract address
40
+ * @param blockIdentifier - block identifier
43
41
  * @returns Bytecode and ABI of compiled contract
44
42
  */
45
- abstract getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
43
+ abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
46
44
  /**
47
45
  * Gets the contract's storage variable at a specific key.
48
46
  *
@@ -50,11 +48,10 @@ export declare abstract class ProviderInterface {
50
48
  *
51
49
  * @param contractAddress
52
50
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
53
- * @param blockHash
54
- * @param blockNumber
51
+ * @param blockIdentifier - block identifier
55
52
  * @returns the value of the storage variable
56
53
  */
57
- abstract getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
54
+ abstract getStorageAt(contractAddress: string, key: number, blockIdentifier?: BlockIdentifier): Promise<object>;
58
55
  /**
59
56
  * Gets the status of a transaction.
60
57
  *
@@ -15,6 +15,21 @@ export declare function formatHash(): void;
15
15
  * @param txId
16
16
  */
17
17
  export declare function txIdentifier(): void;
18
+ export declare type BlockIdentifier = BlockNumber | BigNumberish;
19
+ declare type BlockIdentifierObject = {
20
+ type: 'BLOCK_NUMBER';
21
+ data: BlockNumber;
22
+ } | {
23
+ type: 'BLOCK_HASH';
24
+ data: BigNumberish;
25
+ };
26
+ /**
27
+ * Identifies the block to be queried.
28
+ *
29
+ * @param blockIdentifier - block identifier
30
+ * @returns block identifier object
31
+ */
32
+ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): BlockIdentifierObject;
18
33
  /**
19
34
  * Gets the block identifier for API request
20
35
  *
@@ -24,4 +39,5 @@ export declare function txIdentifier(): void;
24
39
  * @param blockHash
25
40
  * @returns block identifier for API request
26
41
  */
27
- export declare function getFormattedBlockIdentifier(blockHash?: BigNumberish, blockNumber?: BlockNumber): string;
42
+ export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
43
+ export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFormattedBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
3
+ exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
4
+ var number_1 = require("../utils/number");
4
5
  /**
5
6
  * TODO
6
7
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
@@ -18,6 +19,34 @@ exports.formatHash = formatHash;
18
19
  */
19
20
  function txIdentifier() { }
20
21
  exports.txIdentifier = txIdentifier;
22
+ /**
23
+ * Identifies the block to be queried.
24
+ *
25
+ * @param blockIdentifier - block identifier
26
+ * @returns block identifier object
27
+ */
28
+ function getBlockIdentifier(blockIdentifier) {
29
+ if (typeof blockIdentifier === 'number') {
30
+ return { type: 'BLOCK_NUMBER', data: blockIdentifier };
31
+ }
32
+ if (typeof blockIdentifier === 'string' && blockIdentifier.startsWith('0x')) {
33
+ return { type: 'BLOCK_HASH', data: blockIdentifier };
34
+ }
35
+ if (typeof blockIdentifier === 'string' && !Number.isNaN(parseInt(blockIdentifier, 10))) {
36
+ return { type: 'BLOCK_NUMBER', data: parseInt(blockIdentifier, 10) };
37
+ }
38
+ if (blockIdentifier === null) {
39
+ return { type: 'BLOCK_NUMBER', data: null };
40
+ }
41
+ if (blockIdentifier === 'pending') {
42
+ return { type: 'BLOCK_NUMBER', data: 'pending' };
43
+ }
44
+ if (typeof blockIdentifier === 'string') {
45
+ throw new Error("Invalid block identifier: " + blockIdentifier);
46
+ }
47
+ return { type: 'BLOCK_HASH', data: blockIdentifier };
48
+ }
49
+ exports.getBlockIdentifier = getBlockIdentifier;
21
50
  /**
22
51
  * Gets the block identifier for API request
23
52
  *
@@ -27,11 +56,15 @@ exports.txIdentifier = txIdentifier;
27
56
  * @param blockHash
28
57
  * @returns block identifier for API request
29
58
  */
30
- function getFormattedBlockIdentifier(blockHash, blockNumber) {
31
- if (blockNumber === void 0) { blockNumber = null; }
32
- if (blockHash) {
33
- return "?blockHash=" + blockHash;
59
+ function getFormattedBlockIdentifier(blockIdentifier) {
60
+ if (blockIdentifier === void 0) { blockIdentifier = null; }
61
+ var blockIdentifierObject = getBlockIdentifier(blockIdentifier);
62
+ if (blockIdentifierObject.type === 'BLOCK_NUMBER' && blockIdentifierObject.data === null) {
63
+ return '';
64
+ }
65
+ if (blockIdentifierObject.type === 'BLOCK_NUMBER') {
66
+ return "?blockNumber=" + blockIdentifierObject.data;
34
67
  }
35
- return "?blockNumber=" + blockNumber;
68
+ return "?blockHash=" + (0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data));
36
69
  }
37
70
  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
  }