starknet 2.9.0 → 3.2.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 (123) hide show
  1. package/.eslintrc +3 -1
  2. package/CHANGELOG.md +44 -0
  3. package/README.md +16 -14
  4. package/__mocks__/ArgentAccount.json +68548 -51944
  5. package/__mocks__/TestDapp.json +12962 -0
  6. package/__mocks__/contract.json +33191 -0
  7. package/__mocks__/multicall.json +8139 -0
  8. package/__tests__/account.test.ts +101 -122
  9. package/__tests__/accountContract.test.ts +141 -0
  10. package/__tests__/contract.test.ts +183 -34
  11. package/__tests__/fixtures.ts +13 -0
  12. package/__tests__/jest.setup.ts +9 -0
  13. package/__tests__/provider.test.ts +17 -42
  14. package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
  15. package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
  16. package/__tests__/utils/ellipticalCurve.test.ts +20 -13
  17. package/__tests__/utils/utils.test.ts +3 -3
  18. package/account/default.d.ts +66 -0
  19. package/account/default.js +391 -0
  20. package/account/index.d.ts +2 -0
  21. package/account/index.js +27 -0
  22. package/account/interface.d.ts +83 -0
  23. package/account/interface.js +37 -0
  24. package/contract.d.ts +71 -12
  25. package/contract.js +243 -89
  26. package/dist/account/default.d.ts +55 -0
  27. package/dist/account/default.js +246 -0
  28. package/dist/account/index.d.ts +2 -0
  29. package/dist/account/index.js +14 -0
  30. package/dist/account/interface.d.ts +69 -0
  31. package/dist/account/interface.js +27 -0
  32. package/dist/contract.d.ts +71 -9
  33. package/dist/contract.js +214 -65
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/provider/default.d.ts +23 -13
  37. package/dist/provider/default.js +168 -95
  38. package/dist/provider/interface.d.ts +22 -22
  39. package/dist/provider/utils.d.ts +4 -4
  40. package/dist/provider/utils.js +16 -6
  41. package/dist/signer/default.d.ts +7 -51
  42. package/dist/signer/default.js +16 -181
  43. package/dist/signer/index.d.ts +1 -1
  44. package/dist/signer/index.js +1 -1
  45. package/dist/signer/interface.d.ts +18 -38
  46. package/dist/signer/interface.js +2 -20
  47. package/dist/types/api.d.ts +152 -0
  48. package/dist/{types.js → types/api.js} +0 -0
  49. package/dist/types/index.d.ts +3 -0
  50. package/dist/types/index.js +15 -0
  51. package/dist/types/lib.d.ts +57 -0
  52. package/dist/types/lib.js +2 -0
  53. package/dist/types/signer.d.ts +4 -0
  54. package/dist/types/signer.js +2 -0
  55. package/dist/utils/ellipticCurve.js +1 -1
  56. package/dist/utils/hash.d.ts +12 -2
  57. package/dist/utils/hash.js +37 -9
  58. package/dist/utils/number.d.ts +2 -0
  59. package/dist/utils/number.js +32 -2
  60. package/dist/utils/stark.d.ts +2 -9
  61. package/dist/utils/stark.js +44 -14
  62. package/dist/utils/transaction.d.ts +19 -0
  63. package/dist/utils/transaction.js +75 -0
  64. package/dist/utils/typedData/index.d.ts +1 -1
  65. package/dist/utils/typedData/index.js +2 -3
  66. package/index.d.ts +1 -0
  67. package/index.js +1 -0
  68. package/package.json +9 -3
  69. package/provider/default.d.ts +40 -25
  70. package/provider/default.js +232 -180
  71. package/provider/interface.d.ts +28 -34
  72. package/provider/utils.d.ts +4 -4
  73. package/provider/utils.js +15 -6
  74. package/signer/default.d.ts +11 -51
  75. package/signer/default.js +21 -236
  76. package/signer/index.d.ts +1 -1
  77. package/signer/index.js +1 -1
  78. package/signer/interface.d.ts +22 -38
  79. package/signer/interface.js +3 -32
  80. package/src/account/default.ts +130 -0
  81. package/src/account/index.ts +2 -0
  82. package/src/account/interface.ts +91 -0
  83. package/src/contract.ts +246 -77
  84. package/src/index.ts +1 -0
  85. package/src/provider/default.ts +150 -107
  86. package/src/provider/interface.ts +28 -34
  87. package/src/provider/utils.ts +16 -6
  88. package/src/signer/default.ts +26 -124
  89. package/src/signer/index.ts +1 -1
  90. package/src/signer/interface.ts +22 -42
  91. package/src/types/api.ts +176 -0
  92. package/src/types/index.ts +3 -0
  93. package/src/types/lib.ts +72 -0
  94. package/src/types/signer.ts +5 -0
  95. package/src/utils/ellipticCurve.ts +1 -1
  96. package/src/utils/hash.ts +39 -12
  97. package/src/utils/number.ts +12 -1
  98. package/src/utils/stark.ts +14 -15
  99. package/src/utils/transaction.ts +50 -0
  100. package/src/utils/typedData/index.ts +2 -3
  101. package/types/api.d.ts +167 -0
  102. package/{types.js → types/api.js} +0 -0
  103. package/types/index.d.ts +3 -0
  104. package/types/index.js +28 -0
  105. package/types/lib.d.ts +64 -0
  106. package/types/lib.js +2 -0
  107. package/types/signer.d.ts +4 -0
  108. package/types/signer.js +2 -0
  109. package/utils/ellipticCurve.js +1 -1
  110. package/utils/hash.d.ts +15 -6
  111. package/utils/hash.js +42 -10
  112. package/utils/number.d.ts +4 -0
  113. package/utils/number.js +54 -2
  114. package/utils/stark.d.ts +2 -9
  115. package/utils/stark.js +64 -15
  116. package/utils/transaction.d.ts +19 -0
  117. package/utils/transaction.js +99 -0
  118. package/utils/typedData/index.d.ts +1 -1
  119. package/utils/typedData/index.js +2 -3
  120. package/__tests__/signer.test.ts +0 -125
  121. package/dist/types.d.ts +0 -109
  122. package/src/types.ts +0 -131
  123. package/types.d.ts +0 -116
@@ -0,0 +1,246 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __read = (this && this.__read) || function (o, n) {
54
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
55
+ if (!m) return o;
56
+ var i = m.call(o), r, ar = [], e;
57
+ try {
58
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
+ }
60
+ catch (error) { e = { error: error }; }
61
+ finally {
62
+ try {
63
+ if (r && !r.done && (m = i["return"])) m.call(i);
64
+ }
65
+ finally { if (e) throw e.error; }
66
+ }
67
+ return ar;
68
+ };
69
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
+ if (ar || !(i in from)) {
72
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
+ ar[i] = from[i];
74
+ }
75
+ }
76
+ return to.concat(ar || Array.prototype.slice.call(from));
77
+ };
78
+ Object.defineProperty(exports, "__esModule", { value: true });
79
+ exports.Account = void 0;
80
+ var provider_1 = require("../provider");
81
+ var signer_1 = require("../signer");
82
+ var hash_1 = require("../utils/hash");
83
+ var number_1 = require("../utils/number");
84
+ var stark_1 = require("../utils/stark");
85
+ var transaction_1 = require("../utils/transaction");
86
+ var typedData_1 = require("../utils/typedData");
87
+ var Account = /** @class */ (function (_super) {
88
+ __extends(Account, _super);
89
+ function Account(provider, address, keyPair) {
90
+ var _this = _super.call(this, provider) || this;
91
+ _this.signer = new signer_1.Signer(keyPair);
92
+ _this.address = address;
93
+ return _this;
94
+ }
95
+ Account.prototype.getNonce = function () {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ var result;
98
+ return __generator(this, function (_a) {
99
+ switch (_a.label) {
100
+ case 0: return [4 /*yield*/, this.callContract({
101
+ contractAddress: this.address,
102
+ entrypoint: 'get_nonce',
103
+ })];
104
+ case 1:
105
+ result = (_a.sent()).result;
106
+ return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
107
+ }
108
+ });
109
+ });
110
+ };
111
+ /**
112
+ * Invoke execute function in account contract
113
+ *
114
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
115
+ *
116
+ * @param transaction - transaction to be invoked
117
+ * @returns a confirmation of invoking a function on the starknet contract
118
+ */
119
+ Account.prototype.execute = function (calls, abis, transactionsDetail) {
120
+ var _a, _b;
121
+ if (abis === void 0) { abis = undefined; }
122
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var transactions, signerDetails, _c, _d, signature, calldata;
125
+ var _e;
126
+ return __generator(this, function (_f) {
127
+ switch (_f.label) {
128
+ case 0:
129
+ transactions = Array.isArray(calls) ? calls : [calls];
130
+ _e = {
131
+ walletAddress: this.address
132
+ };
133
+ _c = number_1.toBN;
134
+ if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
135
+ _d = _a;
136
+ return [3 /*break*/, 3];
137
+ case 1: return [4 /*yield*/, this.getNonce()];
138
+ case 2:
139
+ _d = (_f.sent());
140
+ _f.label = 3;
141
+ case 3:
142
+ signerDetails = (_e.nonce = _c.apply(void 0, [_d]),
143
+ _e.maxFee = (0, number_1.toBN)((_b = transactionsDetail.maxFee) !== null && _b !== void 0 ? _b : '0'),
144
+ _e);
145
+ return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
146
+ case 4:
147
+ signature = _f.sent();
148
+ calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
149
+ return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
150
+ type: 'INVOKE_FUNCTION',
151
+ contract_address: this.address,
152
+ entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
153
+ calldata: calldata,
154
+ signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
155
+ })];
156
+ }
157
+ });
158
+ });
159
+ };
160
+ /**
161
+ * Sign an JSON object with the starknet private key and return the signature
162
+ *
163
+ * @param json - JSON object to be signed
164
+ * @returns the signature of the JSON object
165
+ * @throws {Error} if the JSON object is not a valid JSON
166
+ */
167
+ Account.prototype.signMessage = function (typedData) {
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ return __generator(this, function (_a) {
170
+ return [2 /*return*/, this.signer.signMessage(typedData, this.address)];
171
+ });
172
+ });
173
+ };
174
+ /**
175
+ * Hash a JSON object with pederson hash and return the hash
176
+ *
177
+ * @param json - JSON object to be hashed
178
+ * @returns the hash of the JSON object
179
+ * @throws {Error} if the JSON object is not a valid JSON
180
+ */
181
+ Account.prototype.hashMessage = function (typedData) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ return __generator(this, function (_a) {
184
+ return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
185
+ });
186
+ });
187
+ };
188
+ /**
189
+ * Verify a signature of a JSON object
190
+ *
191
+ * @param hash - JSON object to be verified
192
+ * @param signature - signature of the JSON object
193
+ * @returns true if the signature is valid, false otherwise
194
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
195
+ */
196
+ Account.prototype.verifyMessageHash = function (hash, signature) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var _a;
199
+ return __generator(this, function (_b) {
200
+ switch (_b.label) {
201
+ case 0:
202
+ _b.trys.push([0, 2, , 3]);
203
+ return [4 /*yield*/, this.callContract({
204
+ contractAddress: this.address,
205
+ entrypoint: 'is_valid_signature',
206
+ calldata: (0, stark_1.compileCalldata)({
207
+ hash: (0, number_1.toBN)(hash).toString(),
208
+ signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
209
+ }),
210
+ })];
211
+ case 1:
212
+ _b.sent();
213
+ return [2 /*return*/, true];
214
+ case 2:
215
+ _a = _b.sent();
216
+ return [2 /*return*/, false];
217
+ case 3: return [2 /*return*/];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ /**
223
+ * Verify a signature of a given hash
224
+ * @warning This method is not recommended, use verifyMessage instead
225
+ *
226
+ * @param hash - hash to be verified
227
+ * @param signature - signature of the hash
228
+ * @returns true if the signature is valid, false otherwise
229
+ * @throws {Error} if the signature is not a valid signature
230
+ */
231
+ Account.prototype.verifyMessage = function (typedData, signature) {
232
+ return __awaiter(this, void 0, void 0, function () {
233
+ var hash;
234
+ return __generator(this, function (_a) {
235
+ switch (_a.label) {
236
+ case 0: return [4 /*yield*/, this.hashMessage(typedData)];
237
+ case 1:
238
+ hash = _a.sent();
239
+ return [2 /*return*/, this.verifyMessageHash(hash, signature)];
240
+ }
241
+ });
242
+ });
243
+ };
244
+ return Account;
245
+ }(provider_1.Provider));
246
+ exports.Account = Account;
@@ -0,0 +1,2 @@
1
+ export * from './default';
2
+ export * from './interface';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./default"), exports);
14
+ __exportStar(require("./interface"), exports);
@@ -0,0 +1,69 @@
1
+ import { ProviderInterface } from '../provider';
2
+ import { Abi, AddTransactionResponse, Call, DeployContractPayload, InvocationsDetails, Signature } from '../types';
3
+ import { BigNumberish } from '../utils/number';
4
+ import { TypedData } from '../utils/typedData/types';
5
+ export declare abstract class AccountInterface extends ProviderInterface {
6
+ abstract address: string;
7
+ /**
8
+ * Deploys a given compiled contract (json) to starknet
9
+ *
10
+ * @param payload payload to be deployed containing:
11
+ * - compiled contract code
12
+ * - constructor calldata
13
+ * - address salt
14
+ * @param abi the abi of the contract
15
+ * @returns a confirmation of sending a transaction on the starknet contract
16
+ */
17
+ abstract deployContract(payload: DeployContractPayload, abi?: Abi): Promise<AddTransactionResponse>;
18
+ /**
19
+ * Invoke execute function in account contract
20
+ *
21
+ * @param transactions the invocation object or an array of them, containing:
22
+ * - contractAddress - the address of the contract
23
+ * - entrypoint - the entrypoint of the contract
24
+ * - calldata - (defaults to []) the calldata
25
+ * - signature - (defaults to []) the signature
26
+ * @param abi (optional) the abi of the contract for better displaying
27
+ *
28
+ * @returns response from addTransaction
29
+ */
30
+ abstract execute(transactions: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
31
+ /**
32
+ * Sign an JSON object for off-chain usage with the starknet private key and return the signature
33
+ * This adds a message prefix so it cant be interchanged with transactions
34
+ *
35
+ * @param json - JSON object to be signed
36
+ * @returns the signature of the JSON object
37
+ * @throws {Error} if the JSON object is not a valid JSON
38
+ */
39
+ abstract signMessage(typedData: TypedData): Promise<Signature>;
40
+ /**
41
+ * Hash a JSON object with pederson hash and return the hash
42
+ * This adds a message prefix so it cant be interchanged with transactions
43
+ *
44
+ * @param json - JSON object to be hashed
45
+ * @returns the hash of the JSON object
46
+ * @throws {Error} if the JSON object is not a valid JSON
47
+ */
48
+ abstract hashMessage(typedData: TypedData): Promise<string>;
49
+ /**
50
+ * Verify a signature of a JSON object
51
+ *
52
+ * @param json - JSON object to be verified
53
+ * @param signature - signature of the JSON object
54
+ * @returns true if the signature is valid, false otherwise
55
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
56
+ */
57
+ abstract verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
58
+ /**
59
+ * Verify a signature of a given hash
60
+ * @warning This method is not recommended, use verifyMessage instead
61
+ *
62
+ * @param hash - hash to be verified
63
+ * @param signature - signature of the hash
64
+ * @returns true if the signature is valid, false otherwise
65
+ * @throws {Error} if the signature is not a valid signature
66
+ */
67
+ abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
68
+ abstract getNonce(): Promise<string>;
69
+ }
@@ -0,0 +1,27 @@
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.AccountInterface = void 0;
19
+ var provider_1 = require("../provider");
20
+ var AccountInterface = /** @class */ (function (_super) {
21
+ __extends(AccountInterface, _super);
22
+ function AccountInterface() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ return AccountInterface;
26
+ }(provider_1.ProviderInterface));
27
+ exports.AccountInterface = AccountInterface;
@@ -1,17 +1,20 @@
1
1
  import { Provider } from './provider';
2
+ import { BlockIdentifier } from './provider/utils';
2
3
  import { Abi, Signature, StructAbi } from './types';
3
4
  import { BigNumberish } from './utils/number';
5
+ export declare type Struct = {
6
+ type: 'struct';
7
+ [k: string]: BigNumberish;
8
+ };
9
+ export declare type ParsedStruct = {
10
+ [key: string]: BigNumberish | ParsedStruct;
11
+ };
4
12
  export declare type Args = {
5
- [inputName: string]: string | string[] | {
6
- type: 'struct';
7
- [k: string]: BigNumberish;
8
- };
13
+ [inputName: string]: BigNumberish | BigNumberish[] | ParsedStruct | ParsedStruct[];
9
14
  };
10
- export declare type Calldata = string[];
11
- export declare function compileCalldata(args: Args): Calldata;
12
15
  export declare class Contract {
13
16
  connectedTo: string | null;
14
- abi: Abi[];
17
+ abi: Abi;
15
18
  structs: {
16
19
  [name: string]: StructAbi;
17
20
  };
@@ -22,11 +25,70 @@ export declare class Contract {
22
25
  * @param abi - Abi of the contract object
23
26
  * @param address (optional) - address to connect to
24
27
  */
25
- constructor(abi: Abi[], address?: string | null, provider?: Provider);
28
+ constructor(abi: Abi, address?: string | null, provider?: Provider);
29
+ /**
30
+ * Saves the address of the contract deployed on network that will be used for interaction
31
+ *
32
+ * @param address - address of the contract
33
+ * @returns Contract
34
+ */
26
35
  connect(address: string): Contract;
36
+ /**
37
+ * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
38
+ *
39
+ * @param type - type of the method
40
+ * @param method - name of the method
41
+ * @param args - arguments that are passed to the method
42
+ */
27
43
  private validateMethodAndArgs;
44
+ /**
45
+ * Deep parse of the object that has been passed to the method
46
+ *
47
+ * @param element - element that needs to be parsed
48
+ * @param type - name of the method
49
+ * @return {string | string[]} - parsed arguments in format that contract is expecting
50
+ */
51
+ private parseCalldataObject;
52
+ /**
53
+ * Parse of the response elements that are converted to Object (Struct) by using the abi
54
+ *
55
+ * @param responseIterator - iterator of the response
56
+ * @param type - type of the struct
57
+ * @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
58
+ */
59
+ private parseResponseStruct;
60
+ /**
61
+ * Parse one field of the calldata by using input field from the abi for that method
62
+ *
63
+ * @param args - value of the field
64
+ * @param input - input(field) information from the abi that will be used to parse the data
65
+ * @return {string | string[]} - parsed arguments in format that contract is expecting
66
+ */
67
+ private parsCalldataField;
68
+ /**
69
+ * Parse the calldata by using input fields from the abi for that method
70
+ *
71
+ * @param args - arguments passed the the method
72
+ * @param inputs - list of inputs(fields) that are in the abi
73
+ * @return {Calldata} - parsed arguments in format that contract is expecting
74
+ */
75
+ private compileCalldata;
76
+ /**
77
+ * Parse elements of the response and structuring them into one field by using output property from the abi for that method
78
+ *
79
+ * @param responseIterator - iterator of the response
80
+ * @param output - output(field) information from the abi that will be used to parse the data
81
+ * @return - parsed response corresponding to the abi structure of the field
82
+ */
28
83
  private parseResponseField;
84
+ /**
85
+ * Parse elements of the response array and structuring them into response object
86
+ *
87
+ * @param method - method name
88
+ * @param response - response from the method
89
+ * @return - parsed response corresponding to the abi
90
+ */
29
91
  private parseResponse;
30
92
  invoke(method: string, args?: Args, signature?: Signature): Promise<import("./types").AddTransactionResponse>;
31
- call(method: string, args?: Args): Promise<Args>;
93
+ call(method: string, args?: Args, blockIdentifier?: BlockIdentifier): Promise<Args>;
32
94
  }