starknet 3.18.0 → 3.19.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 (163) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +1 -0
  3. package/__mocks__/typedDataStructArrayExample.json +44 -0
  4. package/__tests__/account.test.ts +11 -56
  5. package/__tests__/contract.test.ts +11 -49
  6. package/__tests__/defaultProvider.test.ts +321 -0
  7. package/__tests__/fixtures.ts +32 -11
  8. package/__tests__/rpcProvider.test.ts +17 -0
  9. package/__tests__/sequencerProvider.test.ts +45 -0
  10. package/__tests__/utils/typedData.test.ts +24 -0
  11. package/account/default.d.ts +54 -77
  12. package/account/default.js +271 -596
  13. package/account/index.js +18 -31
  14. package/account/interface.d.ts +66 -95
  15. package/account/interface.js +20 -30
  16. package/constants.d.ts +17 -19
  17. package/constants.js +2038 -2059
  18. package/contract/contractFactory.d.ts +25 -29
  19. package/contract/contractFactory.js +94 -210
  20. package/contract/default.d.ts +117 -146
  21. package/contract/default.js +582 -776
  22. package/contract/index.js +19 -32
  23. package/contract/interface.d.ts +72 -92
  24. package/contract/interface.js +6 -5
  25. package/dist/account/default.d.ts +5 -9
  26. package/dist/account/default.js +35 -169
  27. package/dist/account/interface.d.ts +3 -15
  28. package/dist/contract/contractFactory.js +4 -4
  29. package/dist/contract/default.d.ts +3 -3
  30. package/dist/contract/default.js +3 -2
  31. package/dist/contract/interface.d.ts +2 -2
  32. package/dist/provider/default.d.ts +18 -134
  33. package/dist/provider/default.js +47 -410
  34. package/dist/provider/index.d.ts +2 -0
  35. package/dist/provider/index.js +2 -0
  36. package/dist/provider/interface.d.ts +45 -50
  37. package/dist/provider/rpc.d.ts +57 -0
  38. package/dist/provider/rpc.js +364 -0
  39. package/dist/provider/sequencer.d.ts +66 -0
  40. package/dist/provider/sequencer.js +443 -0
  41. package/dist/types/account.d.ts +2 -3
  42. package/dist/types/api/index.d.ts +16 -0
  43. package/dist/types/api/index.js +18 -0
  44. package/dist/types/api/rpc.d.ts +221 -0
  45. package/dist/types/{api.js → api/rpc.js} +0 -0
  46. package/dist/types/api/sequencer.d.ts +289 -0
  47. package/dist/types/api/sequencer.js +2 -0
  48. package/dist/types/index.d.ts +3 -1
  49. package/dist/types/index.js +15 -1
  50. package/dist/types/lib.d.ts +3 -1
  51. package/dist/types/provider.d.ts +86 -0
  52. package/dist/types/provider.js +2 -0
  53. package/dist/utils/provider.d.ts +4 -0
  54. package/dist/utils/provider.js +38 -0
  55. package/dist/utils/responseParser/index.d.ts +11 -0
  56. package/dist/utils/responseParser/index.js +9 -0
  57. package/dist/utils/responseParser/rpc.d.ts +13 -0
  58. package/dist/utils/responseParser/rpc.js +96 -0
  59. package/dist/utils/responseParser/sequencer.d.ts +13 -0
  60. package/dist/utils/responseParser/sequencer.js +124 -0
  61. package/dist/utils/typedData/index.js +14 -0
  62. package/index.js +42 -75
  63. package/package.json +1 -1
  64. package/provider/default.d.ts +21 -175
  65. package/provider/default.js +139 -703
  66. package/provider/errors.d.ts +4 -4
  67. package/provider/errors.js +30 -40
  68. package/provider/index.d.ts +2 -0
  69. package/provider/index.js +22 -33
  70. package/provider/interface.d.ts +104 -131
  71. package/provider/interface.js +6 -5
  72. package/provider/rpc.d.ts +57 -0
  73. package/provider/rpc.js +364 -0
  74. package/provider/sequencer.d.ts +66 -0
  75. package/provider/sequencer.js +443 -0
  76. package/provider/utils.d.ts +7 -9
  77. package/provider/utils.js +39 -44
  78. package/signer/default.d.ts +5 -9
  79. package/signer/default.js +72 -177
  80. package/signer/index.js +18 -31
  81. package/signer/interface.d.ts +29 -33
  82. package/signer/interface.js +6 -5
  83. package/src/account/default.ts +26 -146
  84. package/src/account/interface.ts +5 -20
  85. package/src/contract/contractFactory.ts +3 -6
  86. package/src/contract/default.ts +6 -4
  87. package/src/contract/interface.ts +2 -2
  88. package/src/provider/default.ts +63 -394
  89. package/src/provider/index.ts +2 -0
  90. package/src/provider/interface.ts +68 -63
  91. package/src/provider/rpc.ts +300 -0
  92. package/src/provider/sequencer.ts +384 -0
  93. package/src/types/account.ts +2 -3
  94. package/src/types/api/index.ts +17 -0
  95. package/src/types/api/rpc.ts +247 -0
  96. package/src/types/api/sequencer.ts +331 -0
  97. package/src/types/index.ts +3 -1
  98. package/src/types/lib.ts +3 -1
  99. package/src/types/provider.ts +108 -0
  100. package/src/utils/provider.ts +28 -0
  101. package/src/utils/responseParser/index.ts +28 -0
  102. package/src/utils/responseParser/rpc.ts +93 -0
  103. package/src/utils/responseParser/sequencer.ts +127 -0
  104. package/src/utils/typedData/index.ts +18 -0
  105. package/types/account.d.ts +5 -7
  106. package/types/account.js +2 -2
  107. package/types/api/index.d.ts +16 -0
  108. package/types/api/index.js +18 -0
  109. package/types/api/rpc.d.ts +221 -0
  110. package/types/api/rpc.js +2 -0
  111. package/types/api/sequencer.d.ts +289 -0
  112. package/types/api/sequencer.js +2 -0
  113. package/types/contract.d.ts +1 -1
  114. package/types/contract.js +2 -2
  115. package/types/index.d.ts +3 -1
  116. package/types/index.js +35 -34
  117. package/types/lib.d.ts +36 -41
  118. package/types/lib.js +2 -2
  119. package/types/provider.d.ts +86 -0
  120. package/types/provider.js +2 -0
  121. package/types/signer.d.ts +2 -2
  122. package/types/signer.js +2 -2
  123. package/utils/address.js +26 -37
  124. package/utils/ellipticCurve.d.ts +1 -6
  125. package/utils/ellipticCurve.js +73 -137
  126. package/utils/encode.js +49 -85
  127. package/utils/hash.d.ts +4 -31
  128. package/utils/hash.js +76 -141
  129. package/utils/json.d.ts +13 -45
  130. package/utils/json.js +15 -22
  131. package/utils/number.d.ts +2 -9
  132. package/utils/number.js +47 -81
  133. package/utils/provider.d.ts +4 -0
  134. package/utils/provider.js +38 -0
  135. package/utils/responseParser/index.d.ts +11 -0
  136. package/utils/responseParser/index.js +9 -0
  137. package/utils/responseParser/rpc.d.ts +13 -0
  138. package/utils/responseParser/rpc.js +96 -0
  139. package/utils/responseParser/sequencer.d.ts +13 -0
  140. package/utils/responseParser/sequencer.js +124 -0
  141. package/utils/shortString.js +13 -21
  142. package/utils/stark.d.ts +0 -1
  143. package/utils/stark.js +59 -93
  144. package/utils/transaction.d.ts +3 -6
  145. package/utils/transaction.js +50 -81
  146. package/utils/typedData/index.d.ts +3 -15
  147. package/utils/typedData/index.js +109 -157
  148. package/utils/typedData/types.d.ts +9 -9
  149. package/utils/typedData/types.js +2 -2
  150. package/utils/typedData/utils.js +6 -6
  151. package/utils/uint256.d.ts +5 -5
  152. package/utils/uint256.js +16 -26
  153. package/www/docs/API/account.md +3 -4
  154. package/www/docs/API/contract.md +2 -2
  155. package/www/docs/API/contractFactory.md +2 -2
  156. package/www/docs/API/provider.md +185 -74
  157. package/www/guides/account.md +1 -8
  158. package/www/guides/erc20.md +3 -0
  159. package/__tests__/provider.test.ts +0 -168
  160. package/dist/types/api.d.ts +0 -261
  161. package/src/types/api.ts +0 -303
  162. package/types/api.d.ts +0 -287
  163. package/types/api.js +0 -2
@@ -0,0 +1,11 @@
1
+ import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
2
+ export declare abstract class ResponseParser {
3
+ abstract parseGetBlockResponse(res: any): GetBlockResponse;
4
+ abstract parseGetTransactionResponse(res: any): GetTransactionResponse;
5
+ abstract parseGetTransactionReceiptResponse(res: any): GetTransactionReceiptResponse;
6
+ abstract parseFeeEstimateResponse(res: any): EstimateFeeResponse;
7
+ abstract parseCallContractResponse(res: any): CallContractResponse;
8
+ abstract parseInvokeFunctionResponse(res: any): InvokeFunctionResponse;
9
+ abstract parseDeployContractResponse(res: any): DeployContractResponse;
10
+ abstract parseDeclareContractResponse(res: any): DeclareContractResponse;
11
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponseParser = void 0;
4
+ var ResponseParser = /** @class */ (function () {
5
+ function ResponseParser() {
6
+ }
7
+ return ResponseParser;
8
+ }());
9
+ exports.ResponseParser = ResponseParser;
@@ -0,0 +1,13 @@
1
+ import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
2
+ import { RPC } from '../../types/api';
3
+ import { ResponseParser } from '.';
4
+ export declare class RPCResponseParser extends ResponseParser {
5
+ parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse;
6
+ parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse;
7
+ parseGetTransactionReceiptResponse(res: RPC.GetTransactionReceiptResponse): GetTransactionReceiptResponse;
8
+ parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
9
+ parseCallContractResponse(res: Array<string>): CallContractResponse;
10
+ parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse;
11
+ parseDeployContractResponse(res: RPC.DeployContractResponse): DeployContractResponse;
12
+ parseDeclareContractResponse(res: RPC.DeclareResponse): DeclareContractResponse;
13
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RPCResponseParser = void 0;
19
+ var number_1 = require("../number");
20
+ var _1 = require(".");
21
+ var RPCResponseParser = /** @class */ (function (_super) {
22
+ __extends(RPCResponseParser, _super);
23
+ function RPCResponseParser() {
24
+ return _super !== null && _super.apply(this, arguments) || this;
25
+ }
26
+ RPCResponseParser.prototype.parseGetBlockResponse = function (res) {
27
+ return {
28
+ accepted_time: res.accepted_time,
29
+ block_hash: res.block_hash,
30
+ block_number: res.block_number,
31
+ gas_price: res.gas_price,
32
+ new_root: res.new_root,
33
+ old_root: res.old_root,
34
+ parent_hash: res.parent_hash,
35
+ sequencer: res.sequencer,
36
+ status: res.status,
37
+ transactions: res.transactions,
38
+ };
39
+ };
40
+ RPCResponseParser.prototype.parseGetTransactionResponse = function (res) {
41
+ return {
42
+ calldata: res.calldata || [],
43
+ contract_address: res.contract_address,
44
+ contract_class: res.contract_class,
45
+ entry_point_selector: res.entry_point_selector,
46
+ max_fee: res.max_fee,
47
+ nonce: res.nonce,
48
+ sender_address: res.sender_address,
49
+ signature: res.signature || [],
50
+ transaction_hash: res.txn_hash,
51
+ version: res.version,
52
+ };
53
+ };
54
+ RPCResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
55
+ return {
56
+ transaction_hash: res.txn_hash,
57
+ actual_fee: res.actual_fee,
58
+ status: res.status,
59
+ status_data: res.status_data,
60
+ messages_sent: res.messages_sent,
61
+ l1_origin_message: res.l1_origin_message,
62
+ events: res.events,
63
+ };
64
+ };
65
+ RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
66
+ return {
67
+ overall_fee: (0, number_1.toBN)(res.overall_fee),
68
+ gas_consumed: (0, number_1.toBN)(res.gas_consumed),
69
+ gas_price: (0, number_1.toBN)(res.gas_price),
70
+ };
71
+ };
72
+ RPCResponseParser.prototype.parseCallContractResponse = function (res) {
73
+ return {
74
+ result: res,
75
+ };
76
+ };
77
+ RPCResponseParser.prototype.parseInvokeFunctionResponse = function (res) {
78
+ return {
79
+ transaction_hash: res.transaction_hash,
80
+ };
81
+ };
82
+ RPCResponseParser.prototype.parseDeployContractResponse = function (res) {
83
+ return {
84
+ transaction_hash: res.transaction_hash,
85
+ contract_address: res.contract_address,
86
+ };
87
+ };
88
+ RPCResponseParser.prototype.parseDeclareContractResponse = function (res) {
89
+ return {
90
+ transaction_hash: res.transaction_hash,
91
+ class_hash: res.class_hash,
92
+ };
93
+ };
94
+ return RPCResponseParser;
95
+ }(_1.ResponseParser));
96
+ exports.RPCResponseParser = RPCResponseParser;
@@ -0,0 +1,13 @@
1
+ import { CallContractResponse, DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse } from '../../types';
2
+ import { Sequencer } from '../../types/api';
3
+ import { ResponseParser } from '.';
4
+ export declare class SequencerAPIResponseParser extends ResponseParser {
5
+ parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse;
6
+ parseGetTransactionResponse(res: Sequencer.GetTransactionResponse): GetTransactionResponse;
7
+ parseGetTransactionReceiptResponse(res: Sequencer.TransactionReceiptResponse): GetTransactionReceiptResponse;
8
+ parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse;
9
+ parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse;
10
+ parseInvokeFunctionResponse(res: Sequencer.AddTransactionResponse): InvokeFunctionResponse;
11
+ parseDeployContractResponse(res: Sequencer.AddTransactionResponse): DeployContractResponse;
12
+ parseDeclareContractResponse(res: Sequencer.AddTransactionResponse): DeclareContractResponse;
13
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.SequencerAPIResponseParser = void 0;
30
+ var number_1 = require("../number");
31
+ var _1 = require(".");
32
+ var SequencerAPIResponseParser = /** @class */ (function (_super) {
33
+ __extends(SequencerAPIResponseParser, _super);
34
+ function SequencerAPIResponseParser() {
35
+ return _super !== null && _super.apply(this, arguments) || this;
36
+ }
37
+ SequencerAPIResponseParser.prototype.parseGetBlockResponse = function (res) {
38
+ return {
39
+ accepted_time: res.timestamp,
40
+ block_hash: res.block_hash,
41
+ block_number: res.block_number,
42
+ gas_price: res.gas_price,
43
+ new_root: res.state_root,
44
+ old_root: undefined,
45
+ parent_hash: res.parent_block_hash,
46
+ sequencer: res.sequencer_address,
47
+ status: res.status,
48
+ transactions: Object.values(res.transactions)
49
+ .map(function (value) { return 'transaction_hash' in value && value.transaction_hash; })
50
+ .filter(Boolean),
51
+ };
52
+ };
53
+ SequencerAPIResponseParser.prototype.parseGetTransactionResponse = function (res) {
54
+ return {
55
+ calldata: 'calldata' in res.transaction ? res.transaction.calldata : [],
56
+ contract_address: 'contract_address' in res.transaction ? res.transaction.contract_address : undefined,
57
+ contract_class: 'contract_class' in res.transaction ? res.transaction.contract_class : undefined,
58
+ entry_point_selector: 'entry_point_selector' in res.transaction
59
+ ? res.transaction.entry_point_selector
60
+ : undefined,
61
+ max_fee: 'max_fee' in res.transaction ? res.transaction.max_fee : undefined,
62
+ nonce: res.transaction.nonce,
63
+ sender_address: 'sender_address' in res.transaction
64
+ ? res.transaction.sender_address
65
+ : undefined,
66
+ signature: 'signature' in res.transaction ? res.transaction.signature : undefined,
67
+ transaction_hash: 'transaction_hash' in res.transaction ? res.transaction.transaction_hash : undefined,
68
+ version: 'version' in res.transaction ? res.transaction.version : undefined,
69
+ };
70
+ };
71
+ SequencerAPIResponseParser.prototype.parseGetTransactionReceiptResponse = function (res) {
72
+ return {
73
+ transaction_hash: res.transaction_hash,
74
+ actual_fee: 'actual_fee' in res ? res.actual_fee : undefined,
75
+ status: res.status,
76
+ status_data: undefined,
77
+ messages_sent: res.l2_to_l1_messages,
78
+ events: res.events,
79
+ l1_origin_message: undefined,
80
+ };
81
+ };
82
+ SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
83
+ if ('overall_fee' in res) {
84
+ var gasInfo = {};
85
+ try {
86
+ gasInfo = {
87
+ gas_consumed: (0, number_1.toBN)(res.gas_usage),
88
+ gas_price: (0, number_1.toBN)(res.gas_price),
89
+ };
90
+ }
91
+ catch (_a) {
92
+ // do nothing
93
+ }
94
+ return __assign({ overall_fee: (0, number_1.toBN)(res.overall_fee) }, gasInfo);
95
+ }
96
+ return {
97
+ overall_fee: (0, number_1.toBN)(res.amount),
98
+ };
99
+ };
100
+ SequencerAPIResponseParser.prototype.parseCallContractResponse = function (res) {
101
+ return {
102
+ result: res.result,
103
+ };
104
+ };
105
+ SequencerAPIResponseParser.prototype.parseInvokeFunctionResponse = function (res) {
106
+ return {
107
+ transaction_hash: res.transaction_hash,
108
+ };
109
+ };
110
+ SequencerAPIResponseParser.prototype.parseDeployContractResponse = function (res) {
111
+ return {
112
+ transaction_hash: res.transaction_hash,
113
+ contract_address: res.address,
114
+ };
115
+ };
116
+ SequencerAPIResponseParser.prototype.parseDeclareContractResponse = function (res) {
117
+ return {
118
+ transaction_hash: res.transaction_hash,
119
+ class_hash: res.class_hash,
120
+ };
121
+ };
122
+ return SequencerAPIResponseParser;
123
+ }(_1.ResponseParser));
124
+ exports.SequencerAPIResponseParser = SequencerAPIResponseParser;
@@ -71,6 +71,11 @@ var getDependencies = function (typedData, type, dependencies) {
71
71
  if (!(0, utils_1.validateTypedData)(typedData)) {
72
72
  throw new Error('Typed data does not match JSON schema');
73
73
  }
74
+ // Include pointers (struct arrays)
75
+ if (type[type.length - 1] === '*') {
76
+ // eslint-disable-next-line no-param-reassign
77
+ type = type.slice(0, -1);
78
+ }
74
79
  if (dependencies.includes(type)) {
75
80
  return dependencies;
76
81
  }
@@ -124,6 +129,15 @@ var encodeValue = function (typedData, type, data) {
124
129
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
125
130
  return [type, (0, exports.getStructHash)(typedData, type, data)];
126
131
  }
132
+ if (Object.keys(typedData.types)
133
+ .map(function (x) { return "".concat(x, "*"); })
134
+ .includes(type)) {
135
+ var structHashes = data.map(function (struct) {
136
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
137
+ return (0, exports.getStructHash)(typedData, type.slice(0, -1), struct);
138
+ });
139
+ return [type, (0, hash_1.computeHashOnElements)(structHashes)];
140
+ }
127
141
  if (type === 'felt*') {
128
142
  return ['felt*', (0, hash_1.computeHashOnElements)(data)];
129
143
  }
package/index.js CHANGED
@@ -1,85 +1,52 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
- }
28
- : function (o, v) {
29
- o['default'] = v;
30
- });
31
- var __exportStar =
32
- (this && this.__exportStar) ||
33
- function (m, exports) {
34
- for (var p in m)
35
- if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
36
- __createBinding(exports, m, p);
37
- };
38
- var __importStar =
39
- (this && this.__importStar) ||
40
- function (mod) {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
41
22
  if (mod && mod.__esModule) return mod;
42
23
  var result = {};
43
- if (mod != null)
44
- for (var k in mod)
45
- if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
46
- __createBinding(result, mod, k);
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
47
25
  __setModuleDefault(result, mod);
48
26
  return result;
49
- };
50
- Object.defineProperty(exports, '__esModule', { value: true });
51
- exports.typedData =
52
- exports.shortString =
53
- exports.uint256 =
54
- exports.ec =
55
- exports.stark =
56
- exports.transaction =
57
- exports.number =
58
- exports.json =
59
- exports.hash =
60
- exports.encode =
61
- exports.constants =
62
- void 0;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.typedData = exports.shortString = exports.uint256 = exports.ec = exports.stark = exports.transaction = exports.number = exports.json = exports.hash = exports.encode = exports.constants = void 0;
63
30
  /**
64
31
  * Main
65
32
  */
66
- __exportStar(require('./contract'), exports);
67
- __exportStar(require('./types'), exports);
68
- __exportStar(require('./provider'), exports);
69
- __exportStar(require('./account'), exports);
70
- __exportStar(require('./signer'), exports);
33
+ __exportStar(require("./contract"), exports);
34
+ __exportStar(require("./types"), exports);
35
+ __exportStar(require("./provider"), exports);
36
+ __exportStar(require("./account"), exports);
37
+ __exportStar(require("./signer"), exports);
71
38
  /**
72
39
  * Utils
73
40
  */
74
- exports.constants = __importStar(require('./constants'));
75
- exports.encode = __importStar(require('./utils/encode'));
76
- exports.hash = __importStar(require('./utils/hash'));
77
- exports.json = __importStar(require('./utils/json'));
78
- exports.number = __importStar(require('./utils/number'));
79
- exports.transaction = __importStar(require('./utils/transaction'));
80
- exports.stark = __importStar(require('./utils/stark'));
81
- exports.ec = __importStar(require('./utils/ellipticCurve'));
82
- exports.uint256 = __importStar(require('./utils/uint256'));
83
- exports.shortString = __importStar(require('./utils/shortString'));
84
- exports.typedData = __importStar(require('./utils/typedData'));
85
- __exportStar(require('./utils/address'), exports);
41
+ exports.constants = __importStar(require("./constants"));
42
+ exports.encode = __importStar(require("./utils/encode"));
43
+ exports.hash = __importStar(require("./utils/hash"));
44
+ exports.json = __importStar(require("./utils/json"));
45
+ exports.number = __importStar(require("./utils/number"));
46
+ exports.transaction = __importStar(require("./utils/transaction"));
47
+ exports.stark = __importStar(require("./utils/stark"));
48
+ exports.ec = __importStar(require("./utils/ellipticCurve"));
49
+ exports.uint256 = __importStar(require("./utils/uint256"));
50
+ exports.shortString = __importStar(require("./utils/shortString"));
51
+ exports.typedData = __importStar(require("./utils/typedData"));
52
+ __exportStar(require("./utils/address"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.18.0",
3
+ "version": "3.19.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,181 +1,27 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import {
3
- Abi,
4
- AddTransactionResponse,
5
- Call,
6
- CallContractResponse,
7
- DeclareContractPayload,
8
- DeployContractPayload,
9
- Endpoints,
10
- GetBlockResponse,
11
- GetCodeResponse,
12
- GetContractAddressesResponse,
13
- GetTransactionResponse,
14
- GetTransactionStatusResponse,
15
- GetTransactionTraceResponse,
16
- Invocation,
17
- TransactionReceiptResponse,
18
- } from '../types';
2
+ import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
19
3
  import { BigNumberish } from '../utils/number';
20
4
  import { ProviderInterface } from './interface';
5
+ import { RpcProviderOptions } from './rpc';
6
+ import { SequencerProviderOptions } from './sequencer';
21
7
  import { BlockIdentifier } from './utils';
22
- declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
23
- declare type ProviderOptions =
24
- | {
25
- network: NetworkName;
26
- }
27
- | {
28
- baseUrl: string;
29
- };
8
+ export interface ProviderOptions {
9
+ sequencer?: SequencerProviderOptions;
10
+ rpc?: RpcProviderOptions;
11
+ }
30
12
  export declare class Provider implements ProviderInterface {
31
- baseUrl: string;
32
- feederGatewayUrl: string;
33
- gatewayUrl: string;
34
- chainId: StarknetChainId;
35
- constructor(optionsOrProvider?: ProviderOptions | ProviderInterface);
36
- protected static getNetworkFromName(
37
- name: NetworkName
38
- ): 'https://alpha-mainnet.starknet.io' | 'https://alpha4.starknet.io';
39
- protected static getChainIdFromBaseUrl(baseUrl: string): StarknetChainId;
40
- private getFetchUrl;
41
- private getFetchMethod;
42
- private getQueryString;
43
- private getHeaders;
44
- protected fetchEndpoint<T extends keyof Endpoints>(
45
- endpoint: T,
46
- ...[query, request]: Endpoints[T]['QUERY'] extends never
47
- ? Endpoints[T]['REQUEST'] extends never
48
- ? []
49
- : [undefined, Endpoints[T]['REQUEST']]
50
- : Endpoints[T]['REQUEST'] extends never
51
- ? [Endpoints[T]['QUERY']]
52
- : [Endpoints[T]['QUERY'], Endpoints[T]['REQUEST']]
53
- ): Promise<Endpoints[T]['RESPONSE']>;
54
- /**
55
- * Gets the smart contract address on the goerli testnet.
56
- *
57
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
58
- * @returns starknet smart contract addresses
59
- */
60
- getContractAddresses(): Promise<GetContractAddressesResponse>;
61
- /**
62
- * Calls a function on the StarkNet contract.
63
- *
64
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
65
- *
66
- * @param invokeTransaction - transaction to be invoked
67
- * @param blockHash
68
- * @param blockNumber
69
- * @returns the result of the function on the smart contract.
70
- */
71
- callContract(
72
- { contractAddress, entrypoint, calldata }: Call,
73
- {
74
- blockIdentifier,
75
- }?: {
76
- blockIdentifier?: BlockIdentifier;
77
- }
78
- ): Promise<CallContractResponse>;
79
- /**
80
- * Gets the block information
81
- *
82
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
83
- *
84
- * @param blockHash
85
- * @param blockNumber
86
- * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
87
- */
88
- getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
89
- /**
90
- * Gets the code of the deployed contract.
91
- *
92
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
93
- *
94
- * @param contractAddress
95
- * @param blockHash
96
- * @param blockNumber
97
- * @returns Bytecode and ABI of compiled contract
98
- */
99
- getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
100
- /**
101
- * Gets the contract's storage variable at a specific key.
102
- *
103
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
104
- *
105
- * @param contractAddress
106
- * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
107
- * @param blockHash
108
- * @param blockNumber
109
- * @returns the value of the storage variable
110
- */
111
- getStorageAt(
112
- contractAddress: string,
113
- key: BigNumberish,
114
- blockIdentifier?: BlockIdentifier
115
- ): Promise<object>;
116
- /**
117
- * Gets the status of a transaction.
118
- *
119
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
120
- *
121
- * @param txHash
122
- * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
123
- */
124
- getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
125
- /**
126
- * Gets the transaction receipt from a tx hash.
127
- *
128
- * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
129
- *
130
- * @param txHash
131
- * @returns the transaction receipt object
132
- */
133
- getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
134
- /**
135
- * Gets the transaction information from a tx id.
136
- *
137
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
138
- *
139
- * @param txHash
140
- * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
141
- */
142
- getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
143
- /**
144
- * Gets the transaction trace from a tx id.
145
- *
146
- *
147
- * @param txHash
148
- * @returns the transaction trace
149
- */
150
- getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
151
- /**
152
- * Declare a given compiled contract (json) on starknet
153
- *
154
- * @param contract - a json object containing the compiled contract
155
- * @returns a confirmation of sending a transaction on the starknet contract
156
- */
157
- declareContract(payload: DeclareContractPayload): Promise<AddTransactionResponse>;
158
- /**
159
- * Deploys a given compiled contract (json) to starknet
160
- *
161
- * @param contract - a json object containing the compiled contract
162
- * @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
163
- * @returns a confirmation of sending a transaction on the starknet contract
164
- */
165
- deployContract(payload: DeployContractPayload, _abi?: Abi): Promise<AddTransactionResponse>;
166
- /**
167
- * Invokes a function on starknet
168
- * @deprecated This method wont be supported as soon as fees are mandatory
169
- *
170
- * @param invocation
171
- * @param _abi - (optional) signature to send along
172
- * @returns response from addTransaction
173
- */
174
- invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
175
- waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
176
- /**
177
- * @deprecated use `waitForTransaction` instead
178
- */
179
- waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
13
+ private provider;
14
+ constructor(providerOrOptions?: ProviderOptions | ProviderInterface);
15
+ get chainId(): StarknetChainId;
16
+ getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
17
+ getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
18
+ getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
19
+ getStorageAt(contractAddress: string, key: BigNumberish, blockTagOrHash?: BlockTag | BigNumberish): Promise<BigNumberish>;
20
+ getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
21
+ getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
22
+ callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
23
+ invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
24
+ deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
25
+ declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
26
+ waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
180
27
  }
181
- export {};