starknet 2.9.0 → 3.0.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 (90) hide show
  1. package/.eslintrc +3 -1
  2. package/CHANGELOG.md +24 -0
  3. package/README.md +16 -14
  4. package/__tests__/account.test.ts +52 -87
  5. package/__tests__/accountContract.test.ts +160 -0
  6. package/__tests__/contract.test.ts +3 -1
  7. package/__tests__/jest.setup.ts +9 -0
  8. package/__tests__/provider.test.ts +15 -30
  9. package/account/default.d.ts +66 -0
  10. package/account/default.js +440 -0
  11. package/account/index.d.ts +2 -0
  12. package/account/index.js +27 -0
  13. package/account/interface.d.ts +83 -0
  14. package/account/interface.js +37 -0
  15. package/contract.d.ts +6 -6
  16. package/contract.js +16 -14
  17. package/dist/account/default.d.ts +55 -0
  18. package/dist/account/default.js +272 -0
  19. package/dist/account/index.d.ts +2 -0
  20. package/dist/account/index.js +14 -0
  21. package/dist/account/interface.d.ts +69 -0
  22. package/dist/account/interface.js +27 -0
  23. package/dist/contract.d.ts +6 -6
  24. package/dist/contract.js +9 -12
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/provider/default.d.ts +23 -13
  28. package/dist/provider/default.js +150 -93
  29. package/dist/provider/interface.d.ts +22 -22
  30. package/dist/provider/utils.d.ts +4 -4
  31. package/dist/provider/utils.js +16 -6
  32. package/dist/signer/default.d.ts +7 -51
  33. package/dist/signer/default.js +24 -177
  34. package/dist/signer/index.d.ts +1 -1
  35. package/dist/signer/index.js +1 -1
  36. package/dist/signer/interface.d.ts +16 -37
  37. package/dist/signer/interface.js +2 -20
  38. package/dist/{types.d.ts → types/api.d.ts} +72 -41
  39. package/dist/{types.js → types/api.js} +0 -0
  40. package/dist/types/index.d.ts +3 -0
  41. package/dist/types/index.js +15 -0
  42. package/dist/types/lib.d.ts +57 -0
  43. package/dist/types/lib.js +2 -0
  44. package/dist/types/signer.d.ts +4 -0
  45. package/dist/types/signer.js +2 -0
  46. package/dist/utils/number.d.ts +1 -0
  47. package/dist/utils/number.js +5 -1
  48. package/index.d.ts +1 -1
  49. package/index.js +1 -1
  50. package/package.json +8 -2
  51. package/provider/default.d.ts +40 -25
  52. package/provider/default.js +205 -178
  53. package/provider/interface.d.ts +28 -34
  54. package/provider/utils.d.ts +4 -4
  55. package/provider/utils.js +15 -6
  56. package/signer/default.d.ts +11 -51
  57. package/signer/default.js +51 -232
  58. package/signer/index.d.ts +1 -1
  59. package/signer/index.js +1 -1
  60. package/signer/interface.d.ts +20 -37
  61. package/signer/interface.js +3 -32
  62. package/src/account/default.ts +152 -0
  63. package/src/account/index.ts +2 -0
  64. package/src/account/interface.ts +91 -0
  65. package/src/contract.ts +17 -18
  66. package/src/index.ts +1 -1
  67. package/src/provider/default.ts +137 -99
  68. package/src/provider/interface.ts +28 -34
  69. package/src/provider/utils.ts +16 -6
  70. package/src/signer/default.ts +33 -115
  71. package/src/signer/index.ts +1 -1
  72. package/src/signer/interface.ts +20 -41
  73. package/src/types/api.ts +165 -0
  74. package/src/types/index.ts +3 -0
  75. package/src/types/lib.ts +73 -0
  76. package/src/types/signer.ts +5 -0
  77. package/src/utils/number.ts +4 -0
  78. package/types/api.d.ts +152 -0
  79. package/{types.js → types/api.js} +0 -0
  80. package/types/index.d.ts +3 -0
  81. package/types/index.js +28 -0
  82. package/types/lib.d.ts +64 -0
  83. package/types/lib.js +2 -0
  84. package/types/signer.d.ts +4 -0
  85. package/types/signer.js +2 -0
  86. package/utils/number.d.ts +3 -0
  87. package/utils/number.js +8 -1
  88. package/__tests__/signer.test.ts +0 -125
  89. package/src/types.ts +0 -131
  90. package/types.d.ts +0 -116
@@ -0,0 +1,55 @@
1
+ import { Provider } from '../provider';
2
+ import { Abi, AddTransactionResponse, ExecuteInvocation, InvocationsDetails, KeyPair, Signature } from '../types';
3
+ import { BigNumberish } from '../utils/number';
4
+ import { TypedData } from '../utils/typedData';
5
+ import { AccountInterface } from './interface';
6
+ export declare class Account extends Provider implements AccountInterface {
7
+ address: string;
8
+ private signer;
9
+ constructor(provider: Provider, address: string, keyPair: KeyPair);
10
+ getNonce(): Promise<string>;
11
+ /**
12
+ * Invoke execute function in account contract
13
+ *
14
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
15
+ *
16
+ * @param transaction - transaction to be invoked
17
+ * @returns a confirmation of invoking a function on the starknet contract
18
+ */
19
+ execute(transactions: ExecuteInvocation | ExecuteInvocation[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<AddTransactionResponse>;
20
+ /**
21
+ * Sign an JSON object with the starknet private key and return the signature
22
+ *
23
+ * @param json - JSON object to be signed
24
+ * @returns the signature of the JSON object
25
+ * @throws {Error} if the JSON object is not a valid JSON
26
+ */
27
+ signMessage(typedData: TypedData): Promise<Signature>;
28
+ /**
29
+ * Hash a JSON object with pederson hash and return the hash
30
+ *
31
+ * @param json - JSON object to be hashed
32
+ * @returns the hash of the JSON object
33
+ * @throws {Error} if the JSON object is not a valid JSON
34
+ */
35
+ hashMessage(typedData: TypedData): Promise<string>;
36
+ /**
37
+ * Verify a signature of a JSON object
38
+ *
39
+ * @param json - JSON object to be verified
40
+ * @param signature - signature of the JSON object
41
+ * @returns true if the signature is valid, false otherwise
42
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
43
+ */
44
+ verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
45
+ /**
46
+ * Verify a signature of a given hash
47
+ * @warning This method is not recommended, use verifyMessage instead
48
+ *
49
+ * @param hash - hash to be verified
50
+ * @param signature - signature of the hash
51
+ * @returns true if the signature is valid, false otherwise
52
+ * @throws {Error} if the signature is not a valid signature
53
+ */
54
+ verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
55
+ }
@@ -0,0 +1,272 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ 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;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __rest = (this && this.__rest) || function (s, e) {
65
+ var t = {};
66
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
+ t[p] = s[p];
68
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
+ t[p[i]] = s[p[i]];
72
+ }
73
+ return t;
74
+ };
75
+ var __read = (this && this.__read) || function (o, n) {
76
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
77
+ if (!m) return o;
78
+ var i = m.call(o), r, ar = [], e;
79
+ try {
80
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
+ }
82
+ catch (error) { e = { error: error }; }
83
+ finally {
84
+ try {
85
+ if (r && !r.done && (m = i["return"])) m.call(i);
86
+ }
87
+ finally { if (e) throw e.error; }
88
+ }
89
+ return ar;
90
+ };
91
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
+ if (ar || !(i in from)) {
94
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
+ ar[i] = from[i];
96
+ }
97
+ }
98
+ return to.concat(ar || Array.prototype.slice.call(from));
99
+ };
100
+ Object.defineProperty(exports, "__esModule", { value: true });
101
+ exports.Account = void 0;
102
+ var contract_1 = require("../contract");
103
+ var provider_1 = require("../provider");
104
+ var signer_1 = require("../signer");
105
+ var number_1 = require("../utils/number");
106
+ var stark_1 = require("../utils/stark");
107
+ var typedData_1 = require("../utils/typedData");
108
+ var Account = /** @class */ (function (_super) {
109
+ __extends(Account, _super);
110
+ function Account(provider, address, keyPair) {
111
+ var _this = _super.call(this, provider) || this;
112
+ _this.signer = new signer_1.Signer(keyPair);
113
+ _this.address = address;
114
+ return _this;
115
+ }
116
+ Account.prototype.getNonce = function () {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var result;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0: return [4 /*yield*/, this.callContract({
122
+ contractAddress: this.address,
123
+ entrypoint: 'get_nonce',
124
+ })];
125
+ case 1:
126
+ result = (_a.sent()).result;
127
+ return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ /**
133
+ * Invoke execute function in account contract
134
+ *
135
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
136
+ *
137
+ * @param transaction - transaction to be invoked
138
+ * @returns a confirmation of invoking a function on the starknet contract
139
+ */
140
+ Account.prototype.execute = function (transactions, abis, transactionsDetail) {
141
+ if (abis === void 0) { abis = []; }
142
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ var _a, contractAddress, _b, calldata, entrypoint, invocation, nonce, nonceBn, _c, _d, calldataDecimal, signature, entrypointSelector;
145
+ return __generator(this, function (_e) {
146
+ switch (_e.label) {
147
+ case 0:
148
+ if (Array.isArray(transactions) && transactions.length !== 1) {
149
+ throw new Error('Only one transaction at a time is currently supported');
150
+ }
151
+ _a = Array.isArray(transactions) ? transactions[0] : transactions, contractAddress = _a.contractAddress, _b = _a.calldata, calldata = _b === void 0 ? [] : _b, entrypoint = _a.entrypoint, invocation = __rest(_a, ["contractAddress", "calldata", "entrypoint"]);
152
+ nonce = transactionsDetail.nonce;
153
+ _c = number_1.toBN;
154
+ if (!(nonce !== null && nonce !== void 0)) return [3 /*break*/, 1];
155
+ _d = nonce;
156
+ return [3 /*break*/, 3];
157
+ case 1: return [4 /*yield*/, this.getNonce()];
158
+ case 2:
159
+ _d = (_e.sent());
160
+ _e.label = 3;
161
+ case 3:
162
+ nonceBn = _c.apply(void 0, [_d]);
163
+ calldataDecimal = (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata);
164
+ return [4 /*yield*/, this.signer.signTransaction([
165
+ __assign(__assign({}, invocation), { contractAddress: contractAddress, calldata: calldataDecimal, entrypoint: entrypoint }),
166
+ ], { walletAddress: this.address, nonce: nonceBn }, abis)];
167
+ case 4:
168
+ signature = _e.sent();
169
+ entrypointSelector = (0, stark_1.getSelectorFromName)(entrypoint);
170
+ return [2 /*return*/, _super.prototype.invokeFunction.call(this, {
171
+ contractAddress: this.address,
172
+ entrypoint: 'execute',
173
+ calldata: __spreadArray(__spreadArray([
174
+ contractAddress,
175
+ entrypointSelector,
176
+ calldataDecimal.length.toString()
177
+ ], __read(calldataDecimal), false), [
178
+ nonceBn.toString(),
179
+ ], false),
180
+ signature: signature,
181
+ })];
182
+ }
183
+ });
184
+ });
185
+ };
186
+ /**
187
+ * Sign an JSON object with the starknet private key and return the signature
188
+ *
189
+ * @param json - JSON object to be signed
190
+ * @returns the signature of the JSON object
191
+ * @throws {Error} if the JSON object is not a valid JSON
192
+ */
193
+ Account.prototype.signMessage = function (typedData) {
194
+ return __awaiter(this, void 0, void 0, function () {
195
+ return __generator(this, function (_a) {
196
+ return [2 /*return*/, this.signer.signMessage(typedData, this.address)];
197
+ });
198
+ });
199
+ };
200
+ /**
201
+ * Hash a JSON object with pederson hash and return the hash
202
+ *
203
+ * @param json - JSON object to be hashed
204
+ * @returns the hash of the JSON object
205
+ * @throws {Error} if the JSON object is not a valid JSON
206
+ */
207
+ Account.prototype.hashMessage = function (typedData) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ return __generator(this, function (_a) {
210
+ return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
211
+ });
212
+ });
213
+ };
214
+ /**
215
+ * Verify a signature of a JSON object
216
+ *
217
+ * @param json - JSON object to be verified
218
+ * @param signature - signature of the JSON object
219
+ * @returns true if the signature is valid, false otherwise
220
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
221
+ */
222
+ Account.prototype.verifyMessageHash = function (hash, signature) {
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ var _a;
225
+ return __generator(this, function (_b) {
226
+ switch (_b.label) {
227
+ case 0:
228
+ _b.trys.push([0, 2, , 3]);
229
+ return [4 /*yield*/, this.callContract({
230
+ contractAddress: this.address,
231
+ entrypoint: 'is_valid_signature',
232
+ calldata: (0, contract_1.compileCalldata)({
233
+ hash: (0, number_1.toBN)(hash).toString(),
234
+ signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
235
+ }),
236
+ })];
237
+ case 1:
238
+ _b.sent();
239
+ return [2 /*return*/, true];
240
+ case 2:
241
+ _a = _b.sent();
242
+ return [2 /*return*/, false];
243
+ case 3: return [2 /*return*/];
244
+ }
245
+ });
246
+ });
247
+ };
248
+ /**
249
+ * Verify a signature of a given hash
250
+ * @warning This method is not recommended, use verifyMessage instead
251
+ *
252
+ * @param hash - hash to be verified
253
+ * @param signature - signature of the hash
254
+ * @returns true if the signature is valid, false otherwise
255
+ * @throws {Error} if the signature is not a valid signature
256
+ */
257
+ Account.prototype.verifyMessage = function (typedData, signature) {
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ var hash;
260
+ return __generator(this, function (_a) {
261
+ switch (_a.label) {
262
+ case 0: return [4 /*yield*/, this.hashMessage(typedData)];
263
+ case 1:
264
+ hash = _a.sent();
265
+ return [2 /*return*/, this.verifyMessageHash(hash, signature)];
266
+ }
267
+ });
268
+ });
269
+ };
270
+ return Account;
271
+ }(provider_1.Provider));
272
+ 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, DeployContractPayload, ExecuteInvocation, 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: ExecuteInvocation | ExecuteInvocation[], 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,5 +1,6 @@
1
1
  import { Provider } from './provider';
2
- import { Abi, Signature, StructAbi } from './types';
2
+ import { BlockIdentifier } from './provider/utils';
3
+ import { Abi, RawCalldata, Signature, StructAbi } from './types';
3
4
  import { BigNumberish } from './utils/number';
4
5
  export declare type Args = {
5
6
  [inputName: string]: string | string[] | {
@@ -7,11 +8,10 @@ export declare type Args = {
7
8
  [k: string]: BigNumberish;
8
9
  };
9
10
  };
10
- export declare type Calldata = string[];
11
- export declare function compileCalldata(args: Args): Calldata;
11
+ export declare function compileCalldata(args: Args): RawCalldata;
12
12
  export declare class Contract {
13
13
  connectedTo: string | null;
14
- abi: Abi[];
14
+ abi: Abi;
15
15
  structs: {
16
16
  [name: string]: StructAbi;
17
17
  };
@@ -22,11 +22,11 @@ export declare class Contract {
22
22
  * @param abi - Abi of the contract object
23
23
  * @param address (optional) - address to connect to
24
24
  */
25
- constructor(abi: Abi[], address?: string | null, provider?: Provider);
25
+ constructor(abi: Abi, address?: string | null, provider?: Provider);
26
26
  connect(address: string): Contract;
27
27
  private validateMethodAndArgs;
28
28
  private parseResponseField;
29
29
  private parseResponse;
30
30
  invoke(method: string, args?: Args, signature?: Signature): Promise<import("./types").AddTransactionResponse>;
31
- call(method: string, args?: Args): Promise<Args>;
31
+ call(method: string, args?: Args, blockIdentifier?: BlockIdentifier): Promise<Args>;
32
32
  }
package/dist/contract.js CHANGED
@@ -79,7 +79,6 @@ exports.Contract = exports.compileCalldata = void 0;
79
79
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
80
80
  var provider_1 = require("./provider");
81
81
  var number_1 = require("./utils/number");
82
- var stark_1 = require("./utils/stark");
83
82
  function parseFelt(candidate) {
84
83
  try {
85
84
  return (0, number_1.toBN)(candidate);
@@ -203,34 +202,32 @@ var Contract = /** @class */ (function () {
203
202
  // validate method and args
204
203
  this.validateMethodAndArgs('INVOKE', method, args);
205
204
  // compile calldata
206
- var entrypointSelector = (0, stark_1.getSelectorFromName)(method);
207
205
  var calldata = compileCalldata(args);
208
- return this.provider.addTransaction({
209
- type: 'INVOKE_FUNCTION',
210
- contract_address: this.connectedTo,
206
+ return this.provider.invokeFunction({
207
+ contractAddress: this.connectedTo,
211
208
  signature: signature,
212
209
  calldata: calldata,
213
- entry_point_selector: entrypointSelector,
210
+ entrypoint: method,
214
211
  });
215
212
  };
216
- Contract.prototype.call = function (method, args) {
213
+ Contract.prototype.call = function (method, args, blockIdentifier) {
217
214
  if (args === void 0) { args = {}; }
215
+ if (blockIdentifier === void 0) { blockIdentifier = null; }
218
216
  return __awaiter(this, void 0, void 0, function () {
219
- var entrypointSelector, calldata;
217
+ var calldata;
220
218
  var _this = this;
221
219
  return __generator(this, function (_a) {
222
220
  // ensure contract is connected
223
221
  (0, minimalistic_assert_1.default)(this.connectedTo !== null, 'contract isnt connected to an address');
224
222
  // validate method and args
225
223
  this.validateMethodAndArgs('CALL', method, args);
226
- entrypointSelector = (0, stark_1.getSelectorFromName)(method);
227
224
  calldata = compileCalldata(args);
228
225
  return [2 /*return*/, this.provider
229
226
  .callContract({
230
- contract_address: this.connectedTo,
227
+ contractAddress: this.connectedTo,
228
+ entrypoint: method,
231
229
  calldata: calldata,
232
- entry_point_selector: entrypointSelector,
233
- })
230
+ }, blockIdentifier)
234
231
  .then(function (x) { return _this.parseResponse(method, x.result); })];
235
232
  });
236
233
  });
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  export * from './types';
5
5
  export * from './contract';
6
6
  export * from './provider';
7
- export * from './signer';
7
+ export * from './account';
8
8
  /**
9
9
  * Utils
10
10
  */
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ exports.typedData = exports.shortString = exports.uint256 = exports.ec = exports
29
29
  __exportStar(require("./types"), exports);
30
30
  __exportStar(require("./contract"), exports);
31
31
  __exportStar(require("./provider"), exports);
32
- __exportStar(require("./signer"), exports);
32
+ __exportStar(require("./account"), exports);
33
33
  /**
34
34
  * Utils
35
35
  */
@@ -1,4 +1,4 @@
1
- import { AddTransactionResponse, CallContractResponse, CallContractTransaction, CompiledContract, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Signature, Transaction } from '../types';
1
+ import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
2
2
  import { BigNumberish } from '../utils/number';
3
3
  import { ProviderInterface } from './interface';
4
4
  import { BlockIdentifier } from './utils';
@@ -14,6 +14,11 @@ export declare class Provider implements ProviderInterface {
14
14
  gatewayUrl: string;
15
15
  constructor(optionsOrProvider?: ProviderOptions | Provider);
16
16
  protected static getNetworkFromName(name: NetworkName): "https://alpha-mainnet.starknet.io" | "https://alpha4.starknet.io";
17
+ private getFetchUrl;
18
+ private getFetchMethod;
19
+ private getQueryString;
20
+ private getHeaders;
21
+ protected fetchEndpoint<T extends keyof Endpoints>(endpoint: T, ...[query, request]: Endpoints[T]['QUERY'] extends never ? Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Endpoints[T]['REQUEST']] : Endpoints[T]['REQUEST'] extends never ? [Endpoints[T]['QUERY']] : [Endpoints[T]['QUERY'], Endpoints[T]['REQUEST']]): Promise<Endpoints[T]['RESPONSE']>;
17
22
  /**
18
23
  * Gets the smart contract address on the goerli testnet.
19
24
  *
@@ -31,7 +36,7 @@ export declare class Provider implements ProviderInterface {
31
36
  * @param blockNumber
32
37
  * @returns the result of the function on the smart contract.
33
38
  */
34
- callContract(invokeTransaction: CallContractTransaction, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
39
+ callContract({ contractAddress, entrypoint, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
35
40
  /**
36
41
  * Gets the block information
37
42
  *
@@ -75,23 +80,27 @@ export declare class Provider implements ProviderInterface {
75
80
  */
76
81
  getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
77
82
  /**
78
- * Gets the transaction information from a tx id.
83
+ * Gets the transaction receipt from a tx hash or tx id.
79
84
  *
80
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
85
+ * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
81
86
  *
82
87
  * @param txHash
83
- * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
88
+ * @param txId
89
+ * @returns the transaction receipt object
84
90
  */
85
- getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
91
+ getTransactionReceipt({ txHash, txId, }: {
92
+ txHash?: BigNumberish;
93
+ txId?: BigNumberish;
94
+ }): Promise<TransactionReceipt>;
86
95
  /**
87
- * Invoke a function on the starknet contract
96
+ * Gets the transaction information from a tx id.
88
97
  *
89
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
98
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
90
99
  *
91
- * @param transaction - transaction to be invoked
92
- * @returns a confirmation of invoking a function on the starknet contract
100
+ * @param txHash
101
+ * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
93
102
  */
94
- addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
103
+ getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
95
104
  /**
96
105
  * Deploys a given compiled contract (json) to starknet
97
106
  *
@@ -99,9 +108,10 @@ export declare class Provider implements ProviderInterface {
99
108
  * @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
100
109
  * @returns a confirmation of sending a transaction on the starknet contract
101
110
  */
102
- deployContract(contract: CompiledContract | string, constructorCalldata?: string[], addressSalt?: BigNumberish): Promise<AddTransactionResponse>;
111
+ deployContract(payload: DeployContractPayload, _abi?: Abi): Promise<AddTransactionResponse>;
103
112
  /**
104
113
  * Invokes a function on starknet
114
+ * @deprecated This method wont be supported as soon as fees are mandatory
105
115
  *
106
116
  * @param contractAddress - target contract address for invoke
107
117
  * @param entrypointSelector - target entrypoint selector for
@@ -109,7 +119,7 @@ export declare class Provider implements ProviderInterface {
109
119
  * @param signature - (optional) signature to send along
110
120
  * @returns response from addTransaction
111
121
  */
112
- invokeFunction(contractAddress: string, entrypointSelector: string, calldata?: string[], signature?: Signature): Promise<AddTransactionResponse>;
122
+ invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse>;
113
123
  waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
114
124
  }
115
125
  export {};