starknet 2.7.1 → 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 (104) hide show
  1. package/.eslintrc +3 -1
  2. package/CHANGELOG.md +47 -0
  3. package/CONTRIBUTING.md +1 -1
  4. package/README.md +18 -16
  5. package/__mocks__/typedDataExample.json +35 -0
  6. package/__tests__/account.test.ts +52 -87
  7. package/__tests__/accountContract.test.ts +160 -0
  8. package/__tests__/contract.test.ts +3 -1
  9. package/__tests__/jest.setup.ts +9 -0
  10. package/__tests__/provider.test.ts +16 -33
  11. package/__tests__/utils/address.test.ts +16 -0
  12. package/__tests__/utils/typedData.test.ts +1 -36
  13. package/account/default.d.ts +66 -0
  14. package/account/default.js +440 -0
  15. package/account/index.d.ts +2 -0
  16. package/account/index.js +27 -0
  17. package/account/interface.d.ts +83 -0
  18. package/account/interface.js +37 -0
  19. package/constants.d.ts +2 -0
  20. package/constants.js +4 -0
  21. package/contract.d.ts +6 -6
  22. package/contract.js +16 -14
  23. package/dist/account/default.d.ts +55 -0
  24. package/dist/account/default.js +272 -0
  25. package/dist/account/index.d.ts +2 -0
  26. package/dist/account/index.js +14 -0
  27. package/dist/account/interface.d.ts +69 -0
  28. package/dist/account/interface.js +27 -0
  29. package/dist/constants.d.ts +2 -0
  30. package/dist/constants.js +3 -1
  31. package/dist/contract.d.ts +6 -6
  32. package/dist/contract.js +9 -12
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.js +2 -1
  35. package/dist/provider/default.d.ts +27 -16
  36. package/dist/provider/default.js +157 -100
  37. package/dist/provider/interface.d.ts +29 -32
  38. package/dist/provider/utils.d.ts +21 -5
  39. package/dist/provider/utils.js +53 -10
  40. package/dist/signer/default.d.ts +7 -31
  41. package/dist/signer/default.js +25 -121
  42. package/dist/signer/index.d.ts +1 -1
  43. package/dist/signer/index.js +1 -1
  44. package/dist/signer/interface.d.ts +17 -18
  45. package/dist/signer/interface.js +2 -20
  46. package/dist/{types.d.ts → types/api.d.ts} +72 -41
  47. package/dist/{types.js → types/api.js} +0 -0
  48. package/dist/types/index.d.ts +3 -0
  49. package/dist/types/index.js +15 -0
  50. package/dist/types/lib.d.ts +57 -0
  51. package/dist/types/lib.js +2 -0
  52. package/dist/types/signer.d.ts +4 -0
  53. package/dist/types/signer.js +2 -0
  54. package/dist/utils/address.d.ts +2 -0
  55. package/dist/utils/address.js +22 -0
  56. package/dist/utils/number.d.ts +1 -0
  57. package/dist/utils/number.js +5 -1
  58. package/index.d.ts +2 -1
  59. package/index.js +2 -1
  60. package/package.json +8 -2
  61. package/provider/default.d.ts +45 -36
  62. package/provider/default.js +216 -201
  63. package/provider/interface.d.ts +36 -49
  64. package/provider/utils.d.ts +23 -8
  65. package/provider/utils.js +57 -11
  66. package/signer/default.d.ts +11 -31
  67. package/signer/default.js +52 -169
  68. package/signer/index.d.ts +1 -1
  69. package/signer/index.js +1 -1
  70. package/signer/interface.d.ts +21 -18
  71. package/signer/interface.js +3 -32
  72. package/src/account/default.ts +152 -0
  73. package/src/account/index.ts +2 -0
  74. package/src/account/interface.ts +91 -0
  75. package/src/constants.ts +2 -0
  76. package/src/contract.ts +17 -18
  77. package/src/index.ts +2 -1
  78. package/src/provider/default.ts +141 -110
  79. package/src/provider/interface.ts +36 -52
  80. package/src/provider/utils.ts +60 -13
  81. package/src/signer/default.ts +33 -76
  82. package/src/signer/index.ts +1 -1
  83. package/src/signer/interface.ts +21 -20
  84. package/src/types/api.ts +165 -0
  85. package/src/types/index.ts +3 -0
  86. package/src/types/lib.ts +73 -0
  87. package/src/types/signer.ts +5 -0
  88. package/src/utils/address.ts +23 -0
  89. package/src/utils/number.ts +4 -0
  90. package/types/api.d.ts +152 -0
  91. package/{types.js → types/api.js} +0 -0
  92. package/types/index.d.ts +3 -0
  93. package/types/index.js +28 -0
  94. package/types/lib.d.ts +64 -0
  95. package/types/lib.js +2 -0
  96. package/types/signer.d.ts +4 -0
  97. package/types/signer.js +2 -0
  98. package/utils/address.d.ts +2 -0
  99. package/utils/address.js +22 -0
  100. package/utils/number.d.ts +3 -0
  101. package/utils/number.js +8 -1
  102. package/__tests__/signer.test.ts +0 -119
  103. package/src/types.ts +0 -131
  104. package/types.d.ts +0 -116
@@ -0,0 +1,16 @@
1
+ import { addAddressPadding, validateAndParseAddress } from '../../src/utils/address';
2
+ // import { addHexPrefix, removeHexPrefix } from '../../src/utils/encode';
3
+
4
+ describe('validateAndParseAddress', () => {
5
+ test('should pass when correct starknet address is passed', () => {
6
+ const addr = '0x7ee790591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf';
7
+
8
+ return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
9
+ });
10
+
11
+ test('should add 0x prefix if not provided', () => {
12
+ const addr = '0x6eff1d71068df8e6677f59a556151c56ed13e14ad431a9bef6fcb3fc5e6fa7';
13
+
14
+ return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
15
+ });
16
+ });
@@ -1,41 +1,6 @@
1
+ import typedDataExample from '../../__mocks__/typedDataExample.json';
1
2
  import { encodeType, getMessageHash, getStructHash, getTypeHash } from '../../src/utils/typedData';
2
3
 
3
- const typedDataExample = {
4
- types: {
5
- StarkNetDomain: [
6
- { name: 'name', type: 'felt' },
7
- { name: 'version', type: 'felt' },
8
- { name: 'chainId', type: 'felt' },
9
- ],
10
- Person: [
11
- { name: 'name', type: 'felt' },
12
- { name: 'wallet', type: 'felt' },
13
- ],
14
- Mail: [
15
- { name: 'from', type: 'Person' },
16
- { name: 'to', type: 'Person' },
17
- { name: 'contents', type: 'felt' },
18
- ],
19
- },
20
- primaryType: 'Mail',
21
- domain: {
22
- name: 'StarkNet Mail',
23
- version: '1',
24
- chainId: 1,
25
- },
26
- message: {
27
- from: {
28
- name: 'Cow',
29
- wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
30
- },
31
- to: {
32
- name: 'Bob',
33
- wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
34
- },
35
- contents: 'Hello, Bob!',
36
- },
37
- };
38
-
39
4
  describe('typedData', () => {
40
5
  test('should get right type encoding', () => {
41
6
  const typeEncoding = encodeType(typedDataExample, 'Mail');
@@ -0,0 +1,66 @@
1
+ import { Provider } from '../provider';
2
+ import {
3
+ Abi,
4
+ AddTransactionResponse,
5
+ ExecuteInvocation,
6
+ InvocationsDetails,
7
+ KeyPair,
8
+ Signature,
9
+ } from '../types';
10
+ import { BigNumberish } from '../utils/number';
11
+ import { TypedData } from '../utils/typedData';
12
+ import { AccountInterface } from './interface';
13
+ export declare class Account extends Provider implements AccountInterface {
14
+ address: string;
15
+ private signer;
16
+ constructor(provider: Provider, address: string, keyPair: KeyPair);
17
+ getNonce(): Promise<string>;
18
+ /**
19
+ * Invoke execute function in account contract
20
+ *
21
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
22
+ *
23
+ * @param transaction - transaction to be invoked
24
+ * @returns a confirmation of invoking a function on the starknet contract
25
+ */
26
+ execute(
27
+ transactions: ExecuteInvocation | ExecuteInvocation[],
28
+ abis?: Abi[],
29
+ transactionsDetail?: InvocationsDetails
30
+ ): Promise<AddTransactionResponse>;
31
+ /**
32
+ * Sign an JSON object with the starknet private key and return the signature
33
+ *
34
+ * @param json - JSON object to be signed
35
+ * @returns the signature of the JSON object
36
+ * @throws {Error} if the JSON object is not a valid JSON
37
+ */
38
+ signMessage(typedData: TypedData): Promise<Signature>;
39
+ /**
40
+ * Hash a JSON object with pederson hash and return the hash
41
+ *
42
+ * @param json - JSON object to be hashed
43
+ * @returns the hash of the JSON object
44
+ * @throws {Error} if the JSON object is not a valid JSON
45
+ */
46
+ hashMessage(typedData: TypedData): Promise<string>;
47
+ /**
48
+ * Verify a signature of a JSON object
49
+ *
50
+ * @param json - JSON object to be verified
51
+ * @param signature - signature of the JSON object
52
+ * @returns true if the signature is valid, false otherwise
53
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
54
+ */
55
+ verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
56
+ /**
57
+ * Verify a signature of a given hash
58
+ * @warning This method is not recommended, use verifyMessage instead
59
+ *
60
+ * @param hash - hash to be verified
61
+ * @param signature - signature of the hash
62
+ * @returns true if the signature is valid, false otherwise
63
+ * @throws {Error} if the signature is not a valid signature
64
+ */
65
+ verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
66
+ }
@@ -0,0 +1,440 @@
1
+ 'use strict';
2
+ var __extends =
3
+ (this && this.__extends) ||
4
+ (function () {
5
+ var extendStatics = function (d, b) {
6
+ extendStatics =
7
+ Object.setPrototypeOf ||
8
+ ({ __proto__: [] } instanceof Array &&
9
+ function (d, b) {
10
+ d.__proto__ = b;
11
+ }) ||
12
+ function (d, b) {
13
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
14
+ };
15
+ return extendStatics(d, b);
16
+ };
17
+ return function (d, b) {
18
+ if (typeof b !== 'function' && b !== null)
19
+ throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
20
+ extendStatics(d, b);
21
+ function __() {
22
+ this.constructor = d;
23
+ }
24
+ d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
25
+ };
26
+ })();
27
+ var __assign =
28
+ (this && this.__assign) ||
29
+ function () {
30
+ __assign =
31
+ Object.assign ||
32
+ function (t) {
33
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
34
+ s = arguments[i];
35
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
36
+ }
37
+ return t;
38
+ };
39
+ return __assign.apply(this, arguments);
40
+ };
41
+ var __awaiter =
42
+ (this && this.__awaiter) ||
43
+ function (thisArg, _arguments, P, generator) {
44
+ function adopt(value) {
45
+ return value instanceof P
46
+ ? value
47
+ : new P(function (resolve) {
48
+ resolve(value);
49
+ });
50
+ }
51
+ return new (P || (P = Promise))(function (resolve, reject) {
52
+ function fulfilled(value) {
53
+ try {
54
+ step(generator.next(value));
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ }
59
+ function rejected(value) {
60
+ try {
61
+ step(generator['throw'](value));
62
+ } catch (e) {
63
+ reject(e);
64
+ }
65
+ }
66
+ function step(result) {
67
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
68
+ }
69
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
70
+ });
71
+ };
72
+ var __generator =
73
+ (this && this.__generator) ||
74
+ function (thisArg, body) {
75
+ var _ = {
76
+ label: 0,
77
+ sent: function () {
78
+ if (t[0] & 1) throw t[1];
79
+ return t[1];
80
+ },
81
+ trys: [],
82
+ ops: [],
83
+ },
84
+ f,
85
+ y,
86
+ t,
87
+ g;
88
+ return (
89
+ (g = { next: verb(0), throw: verb(1), return: verb(2) }),
90
+ typeof Symbol === 'function' &&
91
+ (g[Symbol.iterator] = function () {
92
+ return this;
93
+ }),
94
+ g
95
+ );
96
+ function verb(n) {
97
+ return function (v) {
98
+ return step([n, v]);
99
+ };
100
+ }
101
+ function step(op) {
102
+ if (f) throw new TypeError('Generator is already executing.');
103
+ while (_)
104
+ try {
105
+ if (
106
+ ((f = 1),
107
+ y &&
108
+ (t =
109
+ op[0] & 2
110
+ ? y['return']
111
+ : op[0]
112
+ ? y['throw'] || ((t = y['return']) && t.call(y), 0)
113
+ : y.next) &&
114
+ !(t = t.call(y, op[1])).done)
115
+ )
116
+ return t;
117
+ if (((y = 0), t)) op = [op[0] & 2, t.value];
118
+ switch (op[0]) {
119
+ case 0:
120
+ case 1:
121
+ t = op;
122
+ break;
123
+ case 4:
124
+ _.label++;
125
+ return { value: op[1], done: false };
126
+ case 5:
127
+ _.label++;
128
+ y = op[1];
129
+ op = [0];
130
+ continue;
131
+ case 7:
132
+ op = _.ops.pop();
133
+ _.trys.pop();
134
+ continue;
135
+ default:
136
+ if (
137
+ !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
138
+ (op[0] === 6 || op[0] === 2)
139
+ ) {
140
+ _ = 0;
141
+ continue;
142
+ }
143
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
144
+ _.label = op[1];
145
+ break;
146
+ }
147
+ if (op[0] === 6 && _.label < t[1]) {
148
+ _.label = t[1];
149
+ t = op;
150
+ break;
151
+ }
152
+ if (t && _.label < t[2]) {
153
+ _.label = t[2];
154
+ _.ops.push(op);
155
+ break;
156
+ }
157
+ if (t[2]) _.ops.pop();
158
+ _.trys.pop();
159
+ continue;
160
+ }
161
+ op = body.call(thisArg, _);
162
+ } catch (e) {
163
+ op = [6, e];
164
+ y = 0;
165
+ } finally {
166
+ f = t = 0;
167
+ }
168
+ if (op[0] & 5) throw op[1];
169
+ return { value: op[0] ? op[1] : void 0, done: true };
170
+ }
171
+ };
172
+ var __rest =
173
+ (this && this.__rest) ||
174
+ function (s, e) {
175
+ var t = {};
176
+ for (var p in s)
177
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
178
+ if (s != null && typeof Object.getOwnPropertySymbols === 'function')
179
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
180
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
181
+ t[p[i]] = s[p[i]];
182
+ }
183
+ return t;
184
+ };
185
+ var __read =
186
+ (this && this.__read) ||
187
+ function (o, n) {
188
+ var m = typeof Symbol === 'function' && o[Symbol.iterator];
189
+ if (!m) return o;
190
+ var i = m.call(o),
191
+ r,
192
+ ar = [],
193
+ e;
194
+ try {
195
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
196
+ } catch (error) {
197
+ e = { error: error };
198
+ } finally {
199
+ try {
200
+ if (r && !r.done && (m = i['return'])) m.call(i);
201
+ } finally {
202
+ if (e) throw e.error;
203
+ }
204
+ }
205
+ return ar;
206
+ };
207
+ var __spreadArray =
208
+ (this && this.__spreadArray) ||
209
+ function (to, from, pack) {
210
+ if (pack || arguments.length === 2)
211
+ for (var i = 0, l = from.length, ar; i < l; i++) {
212
+ if (ar || !(i in from)) {
213
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
214
+ ar[i] = from[i];
215
+ }
216
+ }
217
+ return to.concat(ar || Array.prototype.slice.call(from));
218
+ };
219
+ Object.defineProperty(exports, '__esModule', { value: true });
220
+ exports.Account = void 0;
221
+ var contract_1 = require('../contract');
222
+ var provider_1 = require('../provider');
223
+ var signer_1 = require('../signer');
224
+ var number_1 = require('../utils/number');
225
+ var stark_1 = require('../utils/stark');
226
+ var typedData_1 = require('../utils/typedData');
227
+ var Account = /** @class */ (function (_super) {
228
+ __extends(Account, _super);
229
+ function Account(provider, address, keyPair) {
230
+ var _this = _super.call(this, provider) || this;
231
+ _this.signer = new signer_1.Signer(keyPair);
232
+ _this.address = address;
233
+ return _this;
234
+ }
235
+ Account.prototype.getNonce = function () {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ var result;
238
+ return __generator(this, function (_a) {
239
+ switch (_a.label) {
240
+ case 0:
241
+ return [
242
+ 4 /*yield*/,
243
+ this.callContract({
244
+ contractAddress: this.address,
245
+ entrypoint: 'get_nonce',
246
+ }),
247
+ ];
248
+ case 1:
249
+ result = _a.sent().result;
250
+ return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
251
+ }
252
+ });
253
+ });
254
+ };
255
+ /**
256
+ * Invoke execute function in account contract
257
+ *
258
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
259
+ *
260
+ * @param transaction - transaction to be invoked
261
+ * @returns a confirmation of invoking a function on the starknet contract
262
+ */
263
+ Account.prototype.execute = function (transactions, abis, transactionsDetail) {
264
+ if (abis === void 0) {
265
+ abis = [];
266
+ }
267
+ if (transactionsDetail === void 0) {
268
+ transactionsDetail = {};
269
+ }
270
+ return __awaiter(this, void 0, void 0, function () {
271
+ var _a,
272
+ contractAddress,
273
+ _b,
274
+ calldata,
275
+ entrypoint,
276
+ invocation,
277
+ nonce,
278
+ nonceBn,
279
+ _c,
280
+ _d,
281
+ calldataDecimal,
282
+ signature,
283
+ entrypointSelector;
284
+ return __generator(this, function (_e) {
285
+ switch (_e.label) {
286
+ case 0:
287
+ if (Array.isArray(transactions) && transactions.length !== 1) {
288
+ throw new Error('Only one transaction at a time is currently supported');
289
+ }
290
+ (_a = Array.isArray(transactions) ? transactions[0] : transactions),
291
+ (contractAddress = _a.contractAddress),
292
+ (_b = _a.calldata),
293
+ (calldata = _b === void 0 ? [] : _b),
294
+ (entrypoint = _a.entrypoint),
295
+ (invocation = __rest(_a, ['contractAddress', 'calldata', 'entrypoint']));
296
+ nonce = transactionsDetail.nonce;
297
+ _c = number_1.toBN;
298
+ if (!(nonce !== null && nonce !== void 0)) return [3 /*break*/, 1];
299
+ _d = nonce;
300
+ return [3 /*break*/, 3];
301
+ case 1:
302
+ return [4 /*yield*/, this.getNonce()];
303
+ case 2:
304
+ _d = _e.sent();
305
+ _e.label = 3;
306
+ case 3:
307
+ nonceBn = _c.apply(void 0, [_d]);
308
+ calldataDecimal = (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata);
309
+ return [
310
+ 4 /*yield*/,
311
+ this.signer.signTransaction(
312
+ [
313
+ __assign(__assign({}, invocation), {
314
+ contractAddress: contractAddress,
315
+ calldata: calldataDecimal,
316
+ entrypoint: entrypoint,
317
+ }),
318
+ ],
319
+ { walletAddress: this.address, nonce: nonceBn },
320
+ abis
321
+ ),
322
+ ];
323
+ case 4:
324
+ signature = _e.sent();
325
+ entrypointSelector = (0, stark_1.getSelectorFromName)(entrypoint);
326
+ return [
327
+ 2 /*return*/,
328
+ _super.prototype.invokeFunction.call(this, {
329
+ contractAddress: this.address,
330
+ entrypoint: 'execute',
331
+ calldata: __spreadArray(
332
+ __spreadArray(
333
+ [contractAddress, entrypointSelector, calldataDecimal.length.toString()],
334
+ __read(calldataDecimal),
335
+ false
336
+ ),
337
+ [nonceBn.toString()],
338
+ false
339
+ ),
340
+ signature: signature,
341
+ }),
342
+ ];
343
+ }
344
+ });
345
+ });
346
+ };
347
+ /**
348
+ * Sign an JSON object with the starknet private key and return the signature
349
+ *
350
+ * @param json - JSON object to be signed
351
+ * @returns the signature of the JSON object
352
+ * @throws {Error} if the JSON object is not a valid JSON
353
+ */
354
+ Account.prototype.signMessage = function (typedData) {
355
+ return __awaiter(this, void 0, void 0, function () {
356
+ return __generator(this, function (_a) {
357
+ return [2 /*return*/, this.signer.signMessage(typedData, this.address)];
358
+ });
359
+ });
360
+ };
361
+ /**
362
+ * Hash a JSON object with pederson hash and return the hash
363
+ *
364
+ * @param json - JSON object to be hashed
365
+ * @returns the hash of the JSON object
366
+ * @throws {Error} if the JSON object is not a valid JSON
367
+ */
368
+ Account.prototype.hashMessage = function (typedData) {
369
+ return __awaiter(this, void 0, void 0, function () {
370
+ return __generator(this, function (_a) {
371
+ return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
372
+ });
373
+ });
374
+ };
375
+ /**
376
+ * Verify a signature of a JSON object
377
+ *
378
+ * @param json - JSON object to be verified
379
+ * @param signature - signature of the JSON object
380
+ * @returns true if the signature is valid, false otherwise
381
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
382
+ */
383
+ Account.prototype.verifyMessageHash = function (hash, signature) {
384
+ return __awaiter(this, void 0, void 0, function () {
385
+ var _a;
386
+ return __generator(this, function (_b) {
387
+ switch (_b.label) {
388
+ case 0:
389
+ _b.trys.push([0, 2, , 3]);
390
+ return [
391
+ 4 /*yield*/,
392
+ this.callContract({
393
+ contractAddress: this.address,
394
+ entrypoint: 'is_valid_signature',
395
+ calldata: (0, contract_1.compileCalldata)({
396
+ hash: (0, number_1.toBN)(hash).toString(),
397
+ signature: signature.map(function (x) {
398
+ return (0, number_1.toBN)(x).toString();
399
+ }),
400
+ }),
401
+ }),
402
+ ];
403
+ case 1:
404
+ _b.sent();
405
+ return [2 /*return*/, true];
406
+ case 2:
407
+ _a = _b.sent();
408
+ return [2 /*return*/, false];
409
+ case 3:
410
+ return [2 /*return*/];
411
+ }
412
+ });
413
+ });
414
+ };
415
+ /**
416
+ * Verify a signature of a given hash
417
+ * @warning This method is not recommended, use verifyMessage instead
418
+ *
419
+ * @param hash - hash to be verified
420
+ * @param signature - signature of the hash
421
+ * @returns true if the signature is valid, false otherwise
422
+ * @throws {Error} if the signature is not a valid signature
423
+ */
424
+ Account.prototype.verifyMessage = function (typedData, signature) {
425
+ return __awaiter(this, void 0, void 0, function () {
426
+ var hash;
427
+ return __generator(this, function (_a) {
428
+ switch (_a.label) {
429
+ case 0:
430
+ return [4 /*yield*/, this.hashMessage(typedData)];
431
+ case 1:
432
+ hash = _a.sent();
433
+ return [2 /*return*/, this.verifyMessageHash(hash, signature)];
434
+ }
435
+ });
436
+ });
437
+ };
438
+ return Account;
439
+ })(provider_1.Provider);
440
+ exports.Account = Account;
@@ -0,0 +1,2 @@
1
+ export * from './default';
2
+ export * from './interface';
@@ -0,0 +1,27 @@
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
+ Object.defineProperty(o, k2, {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ },
12
+ });
13
+ }
14
+ : function (o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ });
18
+ var __exportStar =
19
+ (this && this.__exportStar) ||
20
+ function (m, exports) {
21
+ for (var p in m)
22
+ if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
23
+ __createBinding(exports, m, p);
24
+ };
25
+ Object.defineProperty(exports, '__esModule', { value: true });
26
+ __exportStar(require('./default'), exports);
27
+ __exportStar(require('./interface'), exports);
@@ -0,0 +1,83 @@
1
+ import { ProviderInterface } from '../provider';
2
+ import {
3
+ Abi,
4
+ AddTransactionResponse,
5
+ DeployContractPayload,
6
+ ExecuteInvocation,
7
+ InvocationsDetails,
8
+ Signature,
9
+ } from '../types';
10
+ import { BigNumberish } from '../utils/number';
11
+ import { TypedData } from '../utils/typedData/types';
12
+ export declare abstract class AccountInterface extends ProviderInterface {
13
+ abstract address: string;
14
+ /**
15
+ * Deploys a given compiled contract (json) to starknet
16
+ *
17
+ * @param payload payload to be deployed containing:
18
+ * - compiled contract code
19
+ * - constructor calldata
20
+ * - address salt
21
+ * @param abi the abi of the contract
22
+ * @returns a confirmation of sending a transaction on the starknet contract
23
+ */
24
+ abstract deployContract(
25
+ payload: DeployContractPayload,
26
+ abi?: Abi
27
+ ): Promise<AddTransactionResponse>;
28
+ /**
29
+ * Invoke execute function in account contract
30
+ *
31
+ * @param transactions the invocation object or an array of them, containing:
32
+ * - contractAddress - the address of the contract
33
+ * - entrypoint - the entrypoint of the contract
34
+ * - calldata - (defaults to []) the calldata
35
+ * - signature - (defaults to []) the signature
36
+ * @param abi (optional) the abi of the contract for better displaying
37
+ *
38
+ * @returns response from addTransaction
39
+ */
40
+ abstract execute(
41
+ transactions: ExecuteInvocation | ExecuteInvocation[],
42
+ abis?: Abi[],
43
+ transactionsDetail?: InvocationsDetails
44
+ ): Promise<AddTransactionResponse>;
45
+ /**
46
+ * Sign an JSON object for off-chain usage with the starknet private key and return the signature
47
+ * This adds a message prefix so it cant be interchanged with transactions
48
+ *
49
+ * @param json - JSON object to be signed
50
+ * @returns the signature of the JSON object
51
+ * @throws {Error} if the JSON object is not a valid JSON
52
+ */
53
+ abstract signMessage(typedData: TypedData): Promise<Signature>;
54
+ /**
55
+ * Hash a JSON object with pederson hash and return the hash
56
+ * This adds a message prefix so it cant be interchanged with transactions
57
+ *
58
+ * @param json - JSON object to be hashed
59
+ * @returns the hash of the JSON object
60
+ * @throws {Error} if the JSON object is not a valid JSON
61
+ */
62
+ abstract hashMessage(typedData: TypedData): Promise<string>;
63
+ /**
64
+ * Verify a signature of a JSON object
65
+ *
66
+ * @param json - JSON object to be verified
67
+ * @param signature - signature of the JSON object
68
+ * @returns true if the signature is valid, false otherwise
69
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
70
+ */
71
+ abstract verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
72
+ /**
73
+ * Verify a signature of a given hash
74
+ * @warning This method is not recommended, use verifyMessage instead
75
+ *
76
+ * @param hash - hash to be verified
77
+ * @param signature - signature of the hash
78
+ * @returns true if the signature is valid, false otherwise
79
+ * @throws {Error} if the signature is not a valid signature
80
+ */
81
+ abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
82
+ abstract getNonce(): Promise<string>;
83
+ }