starknet 2.7.2 → 3.1.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 (111) hide show
  1. package/.eslintrc +3 -1
  2. package/CHANGELOG.md +54 -0
  3. package/README.md +16 -14
  4. package/__mocks__/contract.json +33191 -0
  5. package/__mocks__/multicall.json +8139 -0
  6. package/__mocks__/typedDataExample.json +35 -0
  7. package/__tests__/account.test.ts +53 -87
  8. package/__tests__/accountContract.test.ts +161 -0
  9. package/__tests__/contract.test.ts +167 -30
  10. package/__tests__/jest.setup.ts +9 -0
  11. package/__tests__/provider.test.ts +19 -34
  12. package/__tests__/utils/address.test.ts +16 -0
  13. package/__tests__/utils/typedData.test.ts +1 -36
  14. package/account/default.d.ts +66 -0
  15. package/account/default.js +439 -0
  16. package/account/index.d.ts +2 -0
  17. package/account/index.js +27 -0
  18. package/account/interface.d.ts +83 -0
  19. package/account/interface.js +37 -0
  20. package/constants.d.ts +2 -0
  21. package/constants.js +4 -0
  22. package/contract.d.ts +71 -12
  23. package/contract.js +243 -89
  24. package/dist/account/default.d.ts +55 -0
  25. package/dist/account/default.js +271 -0
  26. package/dist/account/index.d.ts +2 -0
  27. package/dist/account/index.js +14 -0
  28. package/dist/account/interface.d.ts +69 -0
  29. package/dist/account/interface.js +27 -0
  30. package/dist/constants.d.ts +2 -0
  31. package/dist/constants.js +3 -1
  32. package/dist/contract.d.ts +71 -9
  33. package/dist/contract.js +214 -65
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.js +2 -1
  36. package/dist/provider/default.d.ts +27 -16
  37. package/dist/provider/default.js +157 -100
  38. package/dist/provider/interface.d.ts +29 -32
  39. package/dist/provider/utils.d.ts +21 -5
  40. package/dist/provider/utils.js +53 -10
  41. package/dist/signer/default.d.ts +7 -31
  42. package/dist/signer/default.js +25 -121
  43. package/dist/signer/index.d.ts +1 -1
  44. package/dist/signer/index.js +1 -1
  45. package/dist/signer/interface.d.ts +17 -18
  46. package/dist/signer/interface.js +2 -20
  47. package/dist/types/api.d.ts +147 -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/address.d.ts +2 -0
  56. package/dist/utils/address.js +22 -0
  57. package/dist/utils/number.d.ts +2 -0
  58. package/dist/utils/number.js +32 -2
  59. package/dist/utils/stark.d.ts +2 -1
  60. package/dist/utils/stark.js +44 -1
  61. package/index.d.ts +2 -1
  62. package/index.js +2 -1
  63. package/package.json +9 -3
  64. package/provider/default.d.ts +45 -36
  65. package/provider/default.js +216 -201
  66. package/provider/interface.d.ts +36 -49
  67. package/provider/utils.d.ts +23 -8
  68. package/provider/utils.js +57 -11
  69. package/signer/default.d.ts +11 -31
  70. package/signer/default.js +52 -169
  71. package/signer/index.d.ts +1 -1
  72. package/signer/index.js +1 -1
  73. package/signer/interface.d.ts +21 -18
  74. package/signer/interface.js +3 -32
  75. package/src/account/default.ts +151 -0
  76. package/src/account/index.ts +2 -0
  77. package/src/account/interface.ts +91 -0
  78. package/src/constants.ts +2 -0
  79. package/src/contract.ts +246 -77
  80. package/src/index.ts +2 -1
  81. package/src/provider/default.ts +141 -110
  82. package/src/provider/interface.ts +36 -52
  83. package/src/provider/utils.ts +60 -13
  84. package/src/signer/default.ts +33 -76
  85. package/src/signer/index.ts +1 -1
  86. package/src/signer/interface.ts +21 -20
  87. package/src/types/api.ts +171 -0
  88. package/src/types/index.ts +3 -0
  89. package/src/types/lib.ts +73 -0
  90. package/src/types/signer.ts +5 -0
  91. package/src/utils/address.ts +23 -0
  92. package/src/utils/number.ts +12 -1
  93. package/src/utils/stark.ts +13 -1
  94. package/types/api.d.ts +162 -0
  95. package/{types.js → types/api.js} +0 -0
  96. package/types/index.d.ts +3 -0
  97. package/types/index.js +28 -0
  98. package/types/lib.d.ts +64 -0
  99. package/types/lib.js +2 -0
  100. package/types/signer.d.ts +4 -0
  101. package/types/signer.js +2 -0
  102. package/utils/address.d.ts +2 -0
  103. package/utils/address.js +22 -0
  104. package/utils/number.d.ts +4 -0
  105. package/utils/number.js +54 -2
  106. package/utils/stark.d.ts +2 -1
  107. package/utils/stark.js +64 -1
  108. package/__tests__/signer.test.ts +0 -119
  109. package/dist/types.d.ts +0 -109
  110. package/src/types.ts +0 -131
  111. package/types.d.ts +0 -116
@@ -1,6 +1,8 @@
1
1
  import fs from 'fs';
2
2
 
3
- import { CompiledContract, compileCalldata, defaultProvider, json, stark } from '../src';
3
+ import { CompiledContract, defaultProvider, json, stark } from '../src';
4
+
5
+ const { compileCalldata } = stark;
4
6
 
5
7
  const compiledArgentAccount = json.parse(
6
8
  fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
@@ -21,7 +23,7 @@ describe('defaultProvider', () => {
21
23
  ).resolves.not.toThrow();
22
24
  });
23
25
  test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
24
- return expect(defaultProvider.getBlock(undefined, 36657)).resolves.not.toThrow();
26
+ return expect(defaultProvider.getBlock(36657)).resolves.not.toThrow();
25
27
  });
26
28
  test('getBlock(blockHash=undefined, blockNumber=null)', () => {
27
29
  return expect(defaultProvider.getBlock()).resolves.not.toThrow();
@@ -34,7 +36,6 @@ describe('defaultProvider', () => {
34
36
  return expect(
35
37
  defaultProvider.getCode(
36
38
  '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
37
- undefined,
38
39
  36663
39
40
  )
40
41
  ).resolves.not.toThrow();
@@ -51,7 +52,6 @@ describe('defaultProvider', () => {
51
52
  defaultProvider.getStorageAt(
52
53
  '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
53
54
  0,
54
- undefined,
55
55
  36663
56
56
  )
57
57
  ).resolves.not.toThrow();
@@ -78,11 +78,20 @@ describe('defaultProvider', () => {
78
78
  )
79
79
  ).resolves.not.toThrow();
80
80
  });
81
+
82
+ test('getTransactionReceipt', async () => {
83
+ return expect(
84
+ defaultProvider.getTransactionReceipt({
85
+ txHash: '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348',
86
+ })
87
+ ).resolves.not.toThrow();
88
+ });
89
+
81
90
  test('callContract()', () => {
82
91
  return expect(
83
92
  defaultProvider.callContract({
84
- contract_address: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
85
- entry_point_selector: stark.getSelectorFromName('balance_of'),
93
+ contractAddress: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
94
+ entrypoint: 'balance_of',
86
95
  calldata: compileCalldata({
87
96
  user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
88
97
  }),
@@ -92,45 +101,21 @@ describe('defaultProvider', () => {
92
101
  });
93
102
 
94
103
  describe('addTransaction()', () => {
95
- test('type: "DEPLOY"', async () => {
104
+ test('deployContract()', async () => {
96
105
  const inputContract = compiledArgentAccount as unknown as CompiledContract;
97
106
 
98
- const contractDefinition = {
99
- ...inputContract,
100
- program: stark.compressProgram(inputContract.program),
101
- };
102
-
103
- const response = await defaultProvider.addTransaction({
104
- type: 'DEPLOY',
105
- contract_address_salt: stark.randomAddress(),
106
- constructor_calldata: compileCalldata({
107
+ const response = await defaultProvider.deployContract({
108
+ contract: inputContract,
109
+ constructorCalldata: compileCalldata({
107
110
  signer: stark.randomAddress(),
108
111
  guardian: '0',
109
112
  L1_address: '0',
110
113
  }),
111
- contract_definition: contractDefinition,
112
114
  });
113
115
 
114
116
  expect(response.code).toBe('TRANSACTION_RECEIVED');
115
117
  expect(response.transaction_hash).toBeDefined();
116
118
  expect(response.address).toBeDefined();
117
119
  });
118
-
119
- test('deployContract()', async () => {
120
- const inputContract = compiledArgentAccount as unknown as CompiledContract;
121
-
122
- const response = await defaultProvider.deployContract(
123
- inputContract,
124
- compileCalldata({
125
- signer: stark.randomAddress(),
126
- guardian: '0',
127
- L1_address: '0',
128
- })
129
- );
130
-
131
- expect(response.code).toBe('TRANSACTION_RECEIVED');
132
- expect(response.transaction_hash).toBeDefined();
133
- expect(response.address).toBeDefined();
134
- });
135
120
  });
136
121
  });
@@ -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,439 @@
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 provider_1 = require('../provider');
222
+ var signer_1 = require('../signer');
223
+ var number_1 = require('../utils/number');
224
+ var stark_1 = require('../utils/stark');
225
+ var typedData_1 = require('../utils/typedData');
226
+ var Account = /** @class */ (function (_super) {
227
+ __extends(Account, _super);
228
+ function Account(provider, address, keyPair) {
229
+ var _this = _super.call(this, provider) || this;
230
+ _this.signer = new signer_1.Signer(keyPair);
231
+ _this.address = address;
232
+ return _this;
233
+ }
234
+ Account.prototype.getNonce = function () {
235
+ return __awaiter(this, void 0, void 0, function () {
236
+ var result;
237
+ return __generator(this, function (_a) {
238
+ switch (_a.label) {
239
+ case 0:
240
+ return [
241
+ 4 /*yield*/,
242
+ this.callContract({
243
+ contractAddress: this.address,
244
+ entrypoint: 'get_nonce',
245
+ }),
246
+ ];
247
+ case 1:
248
+ result = _a.sent().result;
249
+ return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[0]))];
250
+ }
251
+ });
252
+ });
253
+ };
254
+ /**
255
+ * Invoke execute function in account contract
256
+ *
257
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
258
+ *
259
+ * @param transaction - transaction to be invoked
260
+ * @returns a confirmation of invoking a function on the starknet contract
261
+ */
262
+ Account.prototype.execute = function (transactions, abis, transactionsDetail) {
263
+ if (abis === void 0) {
264
+ abis = [];
265
+ }
266
+ if (transactionsDetail === void 0) {
267
+ transactionsDetail = {};
268
+ }
269
+ return __awaiter(this, void 0, void 0, function () {
270
+ var _a,
271
+ contractAddress,
272
+ _b,
273
+ calldata,
274
+ entrypoint,
275
+ invocation,
276
+ nonce,
277
+ nonceBn,
278
+ _c,
279
+ _d,
280
+ calldataDecimal,
281
+ signature,
282
+ entrypointSelector;
283
+ return __generator(this, function (_e) {
284
+ switch (_e.label) {
285
+ case 0:
286
+ if (Array.isArray(transactions) && transactions.length !== 1) {
287
+ throw new Error('Only one transaction at a time is currently supported');
288
+ }
289
+ (_a = Array.isArray(transactions) ? transactions[0] : transactions),
290
+ (contractAddress = _a.contractAddress),
291
+ (_b = _a.calldata),
292
+ (calldata = _b === void 0 ? [] : _b),
293
+ (entrypoint = _a.entrypoint),
294
+ (invocation = __rest(_a, ['contractAddress', 'calldata', 'entrypoint']));
295
+ nonce = transactionsDetail.nonce;
296
+ _c = number_1.toBN;
297
+ if (!(nonce !== null && nonce !== void 0)) return [3 /*break*/, 1];
298
+ _d = nonce;
299
+ return [3 /*break*/, 3];
300
+ case 1:
301
+ return [4 /*yield*/, this.getNonce()];
302
+ case 2:
303
+ _d = _e.sent();
304
+ _e.label = 3;
305
+ case 3:
306
+ nonceBn = _c.apply(void 0, [_d]);
307
+ calldataDecimal = (0, number_1.bigNumberishArrayToDecimalStringArray)(calldata);
308
+ return [
309
+ 4 /*yield*/,
310
+ this.signer.signTransaction(
311
+ [
312
+ __assign(__assign({}, invocation), {
313
+ contractAddress: contractAddress,
314
+ calldata: calldataDecimal,
315
+ entrypoint: entrypoint,
316
+ }),
317
+ ],
318
+ { walletAddress: this.address, nonce: nonceBn },
319
+ abis
320
+ ),
321
+ ];
322
+ case 4:
323
+ signature = _e.sent();
324
+ entrypointSelector = (0, stark_1.getSelectorFromName)(entrypoint);
325
+ return [
326
+ 2 /*return*/,
327
+ _super.prototype.invokeFunction.call(this, {
328
+ contractAddress: this.address,
329
+ entrypoint: 'execute',
330
+ calldata: __spreadArray(
331
+ __spreadArray(
332
+ [contractAddress, entrypointSelector, calldataDecimal.length.toString()],
333
+ __read(calldataDecimal),
334
+ false
335
+ ),
336
+ [nonceBn.toString()],
337
+ false
338
+ ),
339
+ signature: signature,
340
+ }),
341
+ ];
342
+ }
343
+ });
344
+ });
345
+ };
346
+ /**
347
+ * Sign an JSON object with the starknet private key and return the signature
348
+ *
349
+ * @param json - JSON object to be signed
350
+ * @returns the signature of the JSON object
351
+ * @throws {Error} if the JSON object is not a valid JSON
352
+ */
353
+ Account.prototype.signMessage = function (typedData) {
354
+ return __awaiter(this, void 0, void 0, function () {
355
+ return __generator(this, function (_a) {
356
+ return [2 /*return*/, this.signer.signMessage(typedData, this.address)];
357
+ });
358
+ });
359
+ };
360
+ /**
361
+ * Hash a JSON object with pederson hash and return the hash
362
+ *
363
+ * @param json - JSON object to be hashed
364
+ * @returns the hash of the JSON object
365
+ * @throws {Error} if the JSON object is not a valid JSON
366
+ */
367
+ Account.prototype.hashMessage = function (typedData) {
368
+ return __awaiter(this, void 0, void 0, function () {
369
+ return __generator(this, function (_a) {
370
+ return [2 /*return*/, (0, typedData_1.getMessageHash)(typedData, this.address)];
371
+ });
372
+ });
373
+ };
374
+ /**
375
+ * Verify a signature of a JSON object
376
+ *
377
+ * @param json - JSON object to be verified
378
+ * @param signature - signature of the JSON object
379
+ * @returns true if the signature is valid, false otherwise
380
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
381
+ */
382
+ Account.prototype.verifyMessageHash = function (hash, signature) {
383
+ return __awaiter(this, void 0, void 0, function () {
384
+ var _a;
385
+ return __generator(this, function (_b) {
386
+ switch (_b.label) {
387
+ case 0:
388
+ _b.trys.push([0, 2, , 3]);
389
+ return [
390
+ 4 /*yield*/,
391
+ this.callContract({
392
+ contractAddress: this.address,
393
+ entrypoint: 'is_valid_signature',
394
+ calldata: (0, stark_1.compileCalldata)({
395
+ hash: (0, number_1.toBN)(hash).toString(),
396
+ signature: signature.map(function (x) {
397
+ return (0, number_1.toBN)(x).toString();
398
+ }),
399
+ }),
400
+ }),
401
+ ];
402
+ case 1:
403
+ _b.sent();
404
+ return [2 /*return*/, true];
405
+ case 2:
406
+ _a = _b.sent();
407
+ return [2 /*return*/, false];
408
+ case 3:
409
+ return [2 /*return*/];
410
+ }
411
+ });
412
+ });
413
+ };
414
+ /**
415
+ * Verify a signature of a given hash
416
+ * @warning This method is not recommended, use verifyMessage instead
417
+ *
418
+ * @param hash - hash to be verified
419
+ * @param signature - signature of the hash
420
+ * @returns true if the signature is valid, false otherwise
421
+ * @throws {Error} if the signature is not a valid signature
422
+ */
423
+ Account.prototype.verifyMessage = function (typedData, signature) {
424
+ return __awaiter(this, void 0, void 0, function () {
425
+ var hash;
426
+ return __generator(this, function (_a) {
427
+ switch (_a.label) {
428
+ case 0:
429
+ return [4 /*yield*/, this.hashMessage(typedData)];
430
+ case 1:
431
+ hash = _a.sent();
432
+ return [2 /*return*/, this.verifyMessageHash(hash, signature)];
433
+ }
434
+ });
435
+ });
436
+ };
437
+ return Account;
438
+ })(provider_1.Provider);
439
+ 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);