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,7 @@
1
1
  import { StarknetChainId } from '../../constants';
2
+ import { BlockIdentifier } from '../../provider/utils';
2
3
  import { Status } from '../lib';
4
+ import { OPENRPC } from './openrpc';
3
5
  export declare namespace RPC {
4
6
  export type Response = {
5
7
  id: number;
@@ -26,23 +28,9 @@ export declare namespace RPC {
26
28
  gas_consumed: number;
27
29
  gas_price: number;
28
30
  };
29
- export type GetBlockResponse = {
30
- block_hash: string;
31
- parent_hash: string;
32
- block_number: number;
33
- status: Status;
34
- sequencer: string;
35
- new_root: string;
36
- old_root: string;
37
- accepted_time: number;
38
- gas_price: string;
39
- transactions: string[];
40
- };
41
- export type GetCodeResponse = {
42
- bytecode: string[];
43
- abi: string;
44
- };
45
- export type GetStorageAtResponse = string;
31
+ export type GetBlockWithTxHashesResponse = OPENRPC.GetBlockWithTxHashesResponse;
32
+ export type GetBlockWithTxs = OPENRPC.GetBlockWithTxs;
33
+ export type GetStorageAtResponse = OPENRPC.GetStorageAtResponse;
46
34
  export type GetTransactionReceiptResponse = {
47
35
  txn_hash: string;
48
36
  actual_fee: string;
@@ -68,7 +56,8 @@ export declare namespace RPC {
68
56
  contract_class?: GetClassResponse;
69
57
  sender_address?: string;
70
58
  }
71
- export type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
59
+ export type GetTransactionByHashResponse = OPENRPC.GetTransactionByHashResponse;
60
+ export type GetTransactionByBlockIdAndIndex = OPENRPC.GetTransactionByBlockIdAndIndex;
72
61
  export type GetTransactionCountResponse = number;
73
62
  export type GetBlockNumberResponse = number;
74
63
  export type GetSyncingStatsResponse = {
@@ -80,8 +69,8 @@ export declare namespace RPC {
80
69
  highest_block_num: string;
81
70
  } | boolean;
82
71
  export type EventFilter = {
83
- fromBlock: string;
84
- toBlock: string;
72
+ fromBlock: BlockIdentifier;
73
+ toBlock: BlockIdentifier;
85
74
  address: string;
86
75
  keys: string[];
87
76
  page_size: number;
@@ -116,56 +105,46 @@ export declare namespace RPC {
116
105
  payload: string[];
117
106
  };
118
107
  export type Methods = {
119
- starknet_getBlockByHash: {
108
+ starknet_getBlockWithTxHashes: {
120
109
  QUERY: never;
121
110
  REQUEST: any[];
122
- RESPONSE: GetBlockResponse;
111
+ RESPONSE: GetBlockWithTxHashesResponse;
123
112
  };
124
- starknet_getBlockByNumber: {
113
+ starknet_getBlockWithTxs: {
125
114
  QUERY: never;
126
115
  REQUEST: any[];
127
- RESPONSE: GetBlockResponse;
116
+ RESPONSE: GetBlockWithTxs;
128
117
  };
129
- starknet_getStorageAt: {
118
+ starknet_getNonce: {
130
119
  QUERY: never;
131
120
  REQUEST: any[];
132
- RESPONSE: GetStorageAtResponse;
121
+ RESPONSE: string;
133
122
  };
134
- starknet_getTransactionByHash: {
123
+ starknet_getStorageAt: {
135
124
  QUERY: never;
136
125
  REQUEST: any[];
137
- RESPONSE: GetTransactionResponse;
126
+ RESPONSE: GetStorageAtResponse;
138
127
  };
139
- starknet_getTransactionByBlockHashAndIndex: {
128
+ starknet_getTransactionByHash: {
140
129
  QUERY: never;
141
130
  REQUEST: any[];
142
- RESPONSE: GetTransactionResponse;
131
+ RESPONSE: GetTransactionByHashResponse;
143
132
  };
144
- starknet_getTransactionByBlockNumberAndIndex: {
133
+ starknet_getTransactionByBlockIdAndIndex: {
145
134
  QUERY: never;
146
135
  REQUEST: any[];
147
- RESPONSE: GetTransactionResponse;
136
+ RESPONSE: GetTransactionByBlockIdAndIndex;
148
137
  };
149
138
  starknet_getTransactionReceipt: {
150
139
  QUERY: never;
151
140
  REQUEST: any[];
152
141
  RESPONSE: GetTransactionReceiptResponse;
153
142
  };
154
- starknet_getBlockTransactionCountByHash: {
143
+ starknet_getBlockTransactionCount: {
155
144
  QUERY: never;
156
145
  REQUEST: any[];
157
146
  RESPONSE: GetTransactionCountResponse;
158
147
  };
159
- starknet_getBlockTransactionCountByNumber: {
160
- QUERY: never;
161
- REQUEST: any[];
162
- RESPONSE: GetTransactionCountResponse;
163
- };
164
- starknet_getCode: {
165
- QUERY: never;
166
- REQUEST: any[];
167
- RESPONSE: GetCodeResponse;
168
- };
169
148
  starknet_call: {
170
149
  QUERY: never;
171
150
  REQUEST: any[];
@@ -1,17 +1,17 @@
1
+ /**
2
+ * Common interface response
3
+ * Intersection (sequencer response ∩ (∪ rpc responses))
4
+ */
1
5
  import BN from 'bn.js';
2
6
  import { Abi, CompressedProgram, EntryPointsByType, RawCalldata, Signature, Status } from './lib';
3
7
  export interface GetBlockResponse {
4
- accepted_time: number;
8
+ timestamp: number;
5
9
  block_hash: string;
6
10
  block_number: number;
7
- gas_price: string;
8
11
  new_root: string;
9
- old_root?: string;
10
12
  parent_hash: string;
11
- sequencer: string;
12
13
  status: Status;
13
14
  transactions: Array<string>;
14
- starknet_version?: string;
15
15
  }
16
16
  export interface GetCodeResponse {
17
17
  bytecode: string[];
@@ -12,5 +12,18 @@ export declare function getStarkKey(keyPair: KeyPair): string;
12
12
  * @returns keyPair with public key only, which can be used to verify signatures, but cant sign anything
13
13
  */
14
14
  export declare function getKeyPairFromPublicKey(publicKey: BigNumberish): KeyPair;
15
+ /**
16
+ * Signs a message using the provided key.
17
+ *
18
+ * @param keyPair should be an KeyPair with a valid private key.
19
+ * @returns an Signature.
20
+ */
15
21
  export declare function sign(keyPair: KeyPair, msgHash: string): Signature;
22
+ /**
23
+ * Verifies a message using the provided key.
24
+ *
25
+ * @param keyPair should be an KeyPair with a valid public key.
26
+ * @param sig should be an Signature.
27
+ * @returns true if the verification succeeds.
28
+ */
16
29
  export declare function verify(keyPair: KeyPair | KeyPair[], msgHash: string, sig: Signature): boolean;
@@ -37,11 +37,13 @@ exports.ec = new elliptic_1.ec(new elliptic_1.curves.PresetCurve({
37
37
  gRed: false,
38
38
  g: constants_1.CONSTANT_POINTS[1],
39
39
  }));
40
- /*
41
- The function _truncateToN in lib/elliptic/ec/index.js does a shift-right of 4 bits
42
- in some cases. This function does the opposite operation so that
43
- _truncateToN(fixMessage(msg)) == msg.
44
- */
40
+ /**
41
+ * The function _truncateToN in lib/elliptic/ec/index.js does a shift-right of 4 bits
42
+ * in some cases. This function does the opposite operation so that
43
+ * _truncateToN(fixMessage(msg)) == msg.
44
+ *
45
+ * @param msg
46
+ */
45
47
  function fixMessage(msg) {
46
48
  var pureHex = msg.replace(/^0x0*/, '');
47
49
  if (pureHex.length <= 62) {
@@ -77,11 +79,12 @@ function getKeyPairFromPublicKey(publicKey) {
77
79
  return exports.ec.keyFromPublic((0, encode_1.removeHexPrefix)((0, number_1.toHex)(publicKeyBn)), 'hex');
78
80
  }
79
81
  exports.getKeyPairFromPublicKey = getKeyPairFromPublicKey;
80
- /*
81
- Signs a message using the provided key.
82
- key should be an KeyPair with a valid private key.
83
- Returns an Signature.
84
- */
82
+ /**
83
+ * Signs a message using the provided key.
84
+ *
85
+ * @param keyPair should be an KeyPair with a valid private key.
86
+ * @returns an Signature.
87
+ */
85
88
  function sign(keyPair, msgHash) {
86
89
  var msgHashBN = (0, number_1.toBN)((0, encode_1.addHexPrefix)(msgHash));
87
90
  // Verify message hash has valid length.
@@ -101,12 +104,13 @@ function chunkArray(arr, n) {
101
104
  .fill('')
102
105
  .map(function (_, i) { return arr.slice(i * n, i * n + n); });
103
106
  }
104
- /*
105
- Verifies a message using the provided key.
106
- key should be an KeyPair with a valid public key.
107
- msgSignature should be an Signature.
108
- Returns a boolean true if the verification succeeds.
109
- */
107
+ /**
108
+ * Verifies a message using the provided key.
109
+ *
110
+ * @param keyPair should be an KeyPair with a valid public key.
111
+ * @param sig should be an Signature.
112
+ * @returns true if the verification succeeds.
113
+ */
110
114
  function verify(keyPair, msgHash, sig) {
111
115
  var keyPairArray = Array.isArray(keyPair) ? keyPair : [keyPair];
112
116
  var msgHashBN = (0, number_1.toBN)((0, encode_1.addHexPrefix)(msgHash));
@@ -78,13 +78,15 @@ function pedersen(input) {
78
78
  for (var i = 0; i < input.length; i += 1) {
79
79
  var x = (0, number_1.toBN)(input[i]);
80
80
  (0, minimalistic_assert_1.default)(x.gte(constants_1.ZERO) && x.lt((0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.FIELD_PRIME))), "Invalid input: ".concat(input[i]));
81
- for (var j = 0; j < 252; j += 1) {
82
- var pt = constantPoints[2 + i * 252 + j];
83
- (0, minimalistic_assert_1.default)(!point.getX().eq(pt.getX()));
84
- if (x.and(constants_1.ONE).toNumber() !== 0) {
85
- point = point.add(pt);
81
+ if (!x.isZero()) {
82
+ for (var j = 0; j < 252; j += 1) {
83
+ var pt = constantPoints[2 + i * 252 + j];
84
+ (0, minimalistic_assert_1.default)(!point.getX().eq(pt.getX()));
85
+ if (x.and(constants_1.ONE).toNumber() !== 0) {
86
+ point = point.add(pt);
87
+ }
88
+ x = x.shrn(1);
86
89
  }
87
- x = x.shrn(1);
88
90
  }
89
91
  }
90
92
  return (0, encode_1.addHexPrefix)(point.getX().toString(16));
@@ -0,0 +1,10 @@
1
+ export declare class MerkleTree {
2
+ leaves: string[];
3
+ branches: string[][];
4
+ root: string;
5
+ constructor(leafHashes: string[]);
6
+ private build;
7
+ static hash(a: string, b: string): string;
8
+ getProof(leaf: string, branch?: string[], hashPath?: string[]): string[];
9
+ }
10
+ export declare function proofMerklePath(root: string, leaf: string, path: string[]): boolean;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.proofMerklePath = exports.MerkleTree = void 0;
29
+ var hash_1 = require("./hash");
30
+ var MerkleTree = /** @class */ (function () {
31
+ function MerkleTree(leafHashes) {
32
+ this.branches = [];
33
+ this.leaves = leafHashes;
34
+ this.root = this.build(leafHashes);
35
+ }
36
+ MerkleTree.prototype.build = function (leaves) {
37
+ if (leaves.length === 1) {
38
+ return leaves[0];
39
+ }
40
+ if (leaves.length !== this.leaves.length) {
41
+ this.branches.push(leaves);
42
+ }
43
+ var newLeaves = [];
44
+ for (var i = 0; i < leaves.length; i += 2) {
45
+ if (i + 1 === leaves.length) {
46
+ newLeaves.push(leaves[i]);
47
+ }
48
+ else {
49
+ newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
50
+ }
51
+ }
52
+ return this.build(newLeaves);
53
+ };
54
+ MerkleTree.hash = function (a, b) {
55
+ var _a = __read([a, b].sort(), 2), aSorted = _a[0], bSorted = _a[1];
56
+ return (0, hash_1.pedersen)([aSorted, bSorted]);
57
+ };
58
+ MerkleTree.prototype.getProof = function (leaf, branch, hashPath) {
59
+ var _a, _b;
60
+ if (branch === void 0) { branch = this.leaves; }
61
+ if (hashPath === void 0) { hashPath = []; }
62
+ var index = branch.indexOf(leaf);
63
+ if (index === -1) {
64
+ throw new Error('leaf not found');
65
+ }
66
+ if (branch.length === 1) {
67
+ return hashPath;
68
+ }
69
+ var isLeft = index % 2 === 0;
70
+ var neededBranch = (_a = (isLeft ? branch[index + 1] : branch[index - 1])) !== null && _a !== void 0 ? _a : '0x0';
71
+ var newHashPath = __spreadArray(__spreadArray([], __read(hashPath), false), [neededBranch], false);
72
+ var currentBranchLevelIndex = this.leaves.length === branch.length
73
+ ? -1
74
+ : this.branches.findIndex(function (b) { return b.length === branch.length; });
75
+ var nextBranch = (_b = this.branches[currentBranchLevelIndex + 1]) !== null && _b !== void 0 ? _b : [this.root];
76
+ return this.getProof(neededBranch === '0x0'
77
+ ? leaf
78
+ : MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf), nextBranch, newHashPath);
79
+ };
80
+ return MerkleTree;
81
+ }());
82
+ exports.MerkleTree = MerkleTree;
83
+ function proofMerklePath(root, leaf, path) {
84
+ if (path.length === 0) {
85
+ return root === leaf;
86
+ }
87
+ var _a = __read(path), next = _a[0], rest = _a.slice(1);
88
+ return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
89
+ }
90
+ exports.proofMerklePath = proofMerklePath;
@@ -7,3 +7,4 @@ export declare function hexToDecimalString(hex: string): string;
7
7
  export declare function toFelt(num: BigNumberish): string;
8
8
  export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
9
9
  export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
10
+ export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
@@ -26,12 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
29
+ exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
30
30
  var bn_js_1 = __importStar(require("bn.js"));
31
31
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
32
32
  var encode_1 = require("./encode");
33
33
  function isHex(hex) {
34
- return hex.startsWith('0x');
34
+ return /^0x[0-9a-f]*$/i.test(hex);
35
35
  }
36
36
  exports.isHex = isHex;
37
37
  function toBN(number, base) {
@@ -76,3 +76,7 @@ function bigNumberishArrayToDecimalStringArray(rawCalldata) {
76
76
  return rawCalldata.map(function (x) { return toBN(x).toString(10); });
77
77
  }
78
78
  exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
79
+ function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
80
+ return rawCalldata.map(function (x) { return toHex(toBN(x)); });
81
+ }
82
+ exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
@@ -1,14 +1,24 @@
1
+ /**
2
+ * Map RPC Response to common interface response
3
+ * Intersection (sequencer response ∩ (∪ rpc responses))
4
+ */
1
5
  import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
2
6
  import { RPC } from '../../types/api';
3
7
  import { ResponseParser } from '.';
8
+ declare type RpcGetBlockResponse = RPC.GetBlockWithTxHashesResponse & {
9
+ [key: string]: any;
10
+ };
11
+ declare type GetTransactionByHashResponse = RPC.GetTransactionByHashResponse & {
12
+ [key: string]: any;
13
+ };
4
14
  export declare class RPCResponseParser extends ResponseParser {
5
- parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse;
6
- parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse;
15
+ parseGetBlockResponse(res: RpcGetBlockResponse): GetBlockResponse;
16
+ parseGetTransactionResponse(res: GetTransactionByHashResponse): GetTransactionResponse;
7
17
  parseGetTransactionReceiptResponse(res: RPC.GetTransactionReceiptResponse): GetTransactionReceiptResponse;
8
- parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse;
9
18
  parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
10
19
  parseCallContractResponse(res: Array<string>): CallContractResponse;
11
20
  parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse;
12
21
  parseDeployContractResponse(res: RPC.DeployContractResponse): DeployContractResponse;
13
22
  parseDeclareContractResponse(res: RPC.DeclareResponse): DeclareContractResponse;
14
23
  }
24
+ export {};
@@ -25,14 +25,11 @@ var RPCResponseParser = /** @class */ (function (_super) {
25
25
  }
26
26
  RPCResponseParser.prototype.parseGetBlockResponse = function (res) {
27
27
  return {
28
- accepted_time: res.accepted_time,
28
+ timestamp: res.timestamp,
29
29
  block_hash: res.block_hash,
30
30
  block_number: res.block_number,
31
- gas_price: res.gas_price,
32
31
  new_root: res.new_root,
33
- old_root: res.old_root,
34
32
  parent_hash: res.parent_hash,
35
- sequencer: res.sequencer,
36
33
  status: res.status,
37
34
  transactions: res.transactions,
38
35
  };
@@ -41,13 +38,11 @@ var RPCResponseParser = /** @class */ (function (_super) {
41
38
  return {
42
39
  calldata: res.calldata || [],
43
40
  contract_address: res.contract_address,
44
- contract_class: res.contract_class,
45
41
  entry_point_selector: res.entry_point_selector,
46
42
  max_fee: res.max_fee,
47
43
  nonce: res.nonce,
48
- sender_address: res.sender_address,
49
44
  signature: res.signature || [],
50
- transaction_hash: res.txn_hash,
45
+ transaction_hash: res.transaction_hash,
51
46
  version: res.version,
52
47
  };
53
48
  };
@@ -62,9 +57,6 @@ var RPCResponseParser = /** @class */ (function (_super) {
62
57
  events: res.events,
63
58
  };
64
59
  };
65
- RPCResponseParser.prototype.parseGetCodeResponse = function (res) {
66
- return res;
67
- };
68
60
  RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
69
61
  return {
70
62
  overall_fee: (0, number_1.toBN)(res.overall_fee),
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Map Sequencer Response to common interface response
3
+ * Intersection (sequencer response ∩ (∪ rpc responses))
4
+ */
1
5
  import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
2
6
  import { Sequencer } from '../../types/api';
3
7
  import { ResponseParser } from '.';
@@ -5,7 +9,6 @@ export declare class SequencerAPIResponseParser extends ResponseParser {
5
9
  parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse;
6
10
  parseGetTransactionResponse(res: Sequencer.GetTransactionResponse): GetTransactionResponse;
7
11
  parseGetTransactionReceiptResponse(res: Sequencer.TransactionReceiptResponse): GetTransactionReceiptResponse;
8
- parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse;
9
12
  parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse;
10
13
  parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse;
11
14
  parseInvokeFunctionResponse(res: Sequencer.AddTransactionResponse): InvokeFunctionResponse;
@@ -36,14 +36,11 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
36
36
  }
37
37
  SequencerAPIResponseParser.prototype.parseGetBlockResponse = function (res) {
38
38
  return {
39
- accepted_time: res.timestamp,
39
+ timestamp: res.timestamp,
40
40
  block_hash: res.block_hash,
41
41
  block_number: res.block_number,
42
- gas_price: res.gas_price,
43
42
  new_root: res.state_root,
44
- old_root: undefined,
45
43
  parent_hash: res.parent_block_hash,
46
- sequencer: res.sequencer_address,
47
44
  status: res.status,
48
45
  transactions: Object.values(res.transactions)
49
46
  .map(function (value) { return 'transaction_hash' in value && value.transaction_hash; })
@@ -79,9 +76,6 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
79
76
  l1_origin_message: undefined,
80
77
  };
81
78
  };
82
- SequencerAPIResponseParser.prototype.parseGetCodeResponse = function (res) {
83
- return res;
84
- };
85
79
  SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
86
80
  if ('overall_fee' in res) {
87
81
  var gasInfo = {};
@@ -1,6 +1,12 @@
1
1
  import { BigNumberish } from '../number';
2
- import { TypedData } from './types';
2
+ import { StarkNetMerkleType, StarkNetType, TypedData } from './types';
3
3
  export * from './types';
4
+ export declare function prepareSelector(selector: string): string;
5
+ export declare function isMerkleTreeType(type: StarkNetType): type is StarkNetMerkleType;
6
+ interface Context {
7
+ parent?: string;
8
+ key?: string;
9
+ }
4
10
  /**
5
11
  * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
6
12
  * in the resulting array.
@@ -10,7 +16,7 @@ export * from './types';
10
16
  * @param {string[]} [dependencies]
11
17
  * @return {string[]}
12
18
  */
13
- export declare const getDependencies: (typedData: TypedData, type: string, dependencies?: string[]) => string[];
19
+ export declare const getDependencies: (types: TypedData['types'], type: string, dependencies?: string[]) => string[];
14
20
  /**
15
21
  * Encode a type to a string. All dependant types are alphabetically sorted.
16
22
  *
@@ -18,7 +24,7 @@ export declare const getDependencies: (typedData: TypedData, type: string, depen
18
24
  * @param {string} type
19
25
  * @return {string}
20
26
  */
21
- export declare const encodeType: (typedData: TypedData, type: string) => string;
27
+ export declare const encodeType: (types: TypedData['types'], type: string) => string;
22
28
  /**
23
29
  * Get a type string as hash.
24
30
  *
@@ -26,7 +32,17 @@ export declare const encodeType: (typedData: TypedData, type: string) => string;
26
32
  * @param {string} type
27
33
  * @return {string}
28
34
  */
29
- export declare const getTypeHash: (typedData: TypedData, type: string) => string;
35
+ export declare const getTypeHash: (types: TypedData['types'], type: string) => string;
36
+ /**
37
+ * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
38
+ * an array of ABI compatible types, and an array of corresponding values.
39
+ *
40
+ * @param {TypedData} typedData
41
+ * @param {string} type
42
+ * @param {any} data
43
+ * @returns {[string, string]}
44
+ */
45
+ export declare const encodeValue: (types: TypedData['types'], type: string, data: unknown, ctx?: Context) => [string, string];
30
46
  /**
31
47
  * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
32
48
  * dependant types are automatically encoded.
@@ -35,7 +51,7 @@ export declare const getTypeHash: (typedData: TypedData, type: string) => string
35
51
  * @param {string} type
36
52
  * @param {Record<string, any>} data
37
53
  */
38
- export declare const encodeData: <T extends TypedData>(typedData: T, type: string, data: T["message"]) => string[][];
54
+ export declare const encodeData: <T extends TypedData>(types: T["types"], type: string, data: T["message"]) => string[][];
39
55
  /**
40
56
  * Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
41
57
  * types are automatically encoded.
@@ -45,10 +61,9 @@ export declare const encodeData: <T extends TypedData>(typedData: T, type: strin
45
61
  * @param {Record<string, any>} data
46
62
  * @return {Buffer}
47
63
  */
48
- export declare const getStructHash: <T extends TypedData>(typedData: T, type: string, data: T["message"]) => string;
64
+ export declare const getStructHash: <T extends TypedData>(types: T["types"], type: string, data: T["message"]) => string;
49
65
  /**
50
- * Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
51
- * with Keccak256.
66
+ * Get the EIP-191 encoded message to sign, from the typedData object.
52
67
  *
53
68
  * @param {TypedData} typedData
54
69
  * @param {BigNumberish} account