starknet 2.6.0 → 2.8.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.
@@ -81,6 +81,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
81
81
  Object.defineProperty(exports, "__esModule", { value: true });
82
82
  exports.Signer = void 0;
83
83
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
84
+ var contract_1 = require("../contract");
84
85
  var provider_1 = require("../provider");
85
86
  var ellipticCurve_1 = require("../utils/ellipticCurve");
86
87
  var encode_1 = require("../utils/encode");
@@ -180,6 +181,62 @@ var Signer = /** @class */ (function (_super) {
180
181
  });
181
182
  });
182
183
  };
184
+ /**
185
+ * Verify a signature of a JSON object
186
+ *
187
+ * @param json - JSON object to be verified
188
+ * @param signature - signature of the JSON object
189
+ * @returns true if the signature is valid, false otherwise
190
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
191
+ */
192
+ Signer.prototype.verifyMessageHash = function (hash, signature) {
193
+ return __awaiter(this, void 0, void 0, function () {
194
+ var _a;
195
+ return __generator(this, function (_b) {
196
+ switch (_b.label) {
197
+ case 0:
198
+ _b.trys.push([0, 2, , 3]);
199
+ return [4 /*yield*/, this.callContract({
200
+ contract_address: this.address,
201
+ entry_point_selector: (0, stark_1.getSelectorFromName)('is_valid_signature'),
202
+ calldata: (0, contract_1.compileCalldata)({
203
+ hash: (0, number_1.toBN)(hash).toString(),
204
+ signature: signature.map(function (x) { return (0, number_1.toBN)(x).toString(); }),
205
+ }),
206
+ })];
207
+ case 1:
208
+ _b.sent();
209
+ return [2 /*return*/, true];
210
+ case 2:
211
+ _a = _b.sent();
212
+ return [2 /*return*/, false];
213
+ case 3: return [2 /*return*/];
214
+ }
215
+ });
216
+ });
217
+ };
218
+ /**
219
+ * Verify a signature of a given hash
220
+ * @warning This method is not recommended, use verifyMessage instead
221
+ *
222
+ * @param hash - hash to be verified
223
+ * @param signature - signature of the hash
224
+ * @returns true if the signature is valid, false otherwise
225
+ * @throws {Error} if the signature is not a valid signature
226
+ */
227
+ Signer.prototype.verifyMessage = function (typedData, signature) {
228
+ return __awaiter(this, void 0, void 0, function () {
229
+ var hash;
230
+ return __generator(this, function (_a) {
231
+ switch (_a.label) {
232
+ case 0: return [4 /*yield*/, this.hashMessage(typedData)];
233
+ case 1:
234
+ hash = _a.sent();
235
+ return [2 /*return*/, this.verifyMessageHash(hash, signature)];
236
+ }
237
+ });
238
+ });
239
+ };
183
240
  return Signer;
184
241
  }(provider_1.Provider));
185
242
  exports.Signer = Signer;
@@ -1,5 +1,6 @@
1
1
  import { Provider } from '../provider';
2
2
  import { AddTransactionResponse, Signature, Transaction } from '../types';
3
+ import { BigNumberish } from '../utils/number';
3
4
  import { TypedData } from '../utils/typedData/types';
4
5
  export declare abstract class SignerInterface extends Provider {
5
6
  abstract address: string;
@@ -30,4 +31,23 @@ export declare abstract class SignerInterface extends Provider {
30
31
  * @throws {Error} if the JSON object is not a valid JSON
31
32
  */
32
33
  abstract hashMessage(typedData: TypedData): Promise<string>;
34
+ /**
35
+ * Verify a signature of a JSON object
36
+ *
37
+ * @param json - JSON object to be verified
38
+ * @param signature - signature of the JSON object
39
+ * @returns true if the signature is valid, false otherwise
40
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
41
+ */
42
+ abstract verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
43
+ /**
44
+ * Verify a signature of a given hash
45
+ * @warning This method is not recommended, use verifyMessage instead
46
+ *
47
+ * @param hash - hash to be verified
48
+ * @param signature - signature of the hash
49
+ * @returns true if the signature is valid, false otherwise
50
+ * @throws {Error} if the signature is not a valid signature
51
+ */
52
+ abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
33
53
  }
package/dist/types.d.ts CHANGED
@@ -62,7 +62,7 @@ export declare type CallContractResponse = {
62
62
  result: string[];
63
63
  };
64
64
  export declare type GetBlockResponse = {
65
- sequence_number: number;
65
+ block_number: number;
66
66
  state_root: string;
67
67
  block_hash: string;
68
68
  transactions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,46 +40,60 @@ export declare class Provider implements ProviderInterface {
40
40
  /**
41
41
  * Calls a function on the StarkNet contract.
42
42
  *
43
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
43
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
44
44
  *
45
45
  * @param invokeTransaction - transaction to be invoked
46
+ * @param blockHash
46
47
  * @param blockNumber
47
48
  * @returns the result of the function on the smart contract.
48
49
  */
49
50
  callContract(
50
51
  invokeTransaction: CallContractTransaction,
52
+ blockHash?: BigNumberish,
51
53
  blockNumber?: BlockNumber
52
54
  ): Promise<CallContractResponse>;
53
55
  /**
54
- * Gets the block information from a block ID.
56
+ * Gets the block information
55
57
  *
56
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
58
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
57
59
  *
60
+ * @param blockHash
58
61
  * @param blockNumber
59
62
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
60
63
  */
61
- getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
64
+ getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
62
65
  /**
63
66
  * Gets the code of the deployed contract.
64
67
  *
65
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
68
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
66
69
  *
67
70
  * @param contractAddress
71
+ * @param blockHash
68
72
  * @param blockNumber
69
73
  * @returns Bytecode and ABI of compiled contract
70
74
  */
71
- getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
75
+ getCode(
76
+ contractAddress: string,
77
+ blockHash?: BigNumberish,
78
+ blockNumber?: BlockNumber
79
+ ): Promise<GetCodeResponse>;
72
80
  /**
73
81
  * Gets the contract's storage variable at a specific key.
74
82
  *
75
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
83
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
76
84
  *
77
85
  * @param contractAddress
78
86
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
87
+ * @param blockHash
79
88
  * @param blockNumber
80
89
  * @returns the value of the storage variable
81
90
  */
82
- getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
91
+ getStorageAt(
92
+ contractAddress: string,
93
+ key: number,
94
+ blockHash?: BigNumberish,
95
+ blockNumber?: BlockNumber
96
+ ): Promise<object>;
83
97
  /**
84
98
  * Gets the status of a transaction.
85
99
  *
@@ -156,6 +156,7 @@ var url_join_1 = __importDefault(require('url-join'));
156
156
  var json_1 = require('../utils/json');
157
157
  var number_1 = require('../utils/number');
158
158
  var stark_1 = require('../utils/stark');
159
+ var utils_1 = require('./utils');
159
160
  function wait(delay) {
160
161
  return new Promise(function (res) {
161
162
  return setTimeout(res, delay);
@@ -217,28 +218,33 @@ var Provider = /** @class */ (function () {
217
218
  /**
218
219
  * Calls a function on the StarkNet contract.
219
220
  *
220
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
221
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
221
222
  *
222
223
  * @param invokeTransaction - transaction to be invoked
224
+ * @param blockHash
223
225
  * @param blockNumber
224
226
  * @returns the result of the function on the smart contract.
225
227
  */
226
- Provider.prototype.callContract = function (invokeTransaction, blockNumber) {
228
+ Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
227
229
  if (blockNumber === void 0) {
228
230
  blockNumber = null;
229
231
  }
230
232
  return __awaiter(this, void 0, void 0, function () {
231
- var data;
233
+ var formattedBlockIdentifier, data;
232
234
  return __generator(this, function (_a) {
233
235
  switch (_a.label) {
234
236
  case 0:
237
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
238
+ blockHash,
239
+ blockNumber
240
+ );
235
241
  return [
236
242
  4 /*yield*/,
237
243
  axios_1.default.post(
238
244
  (0, url_join_1.default)(
239
245
  this.feederGatewayUrl,
240
246
  'call_contract',
241
- '?blockNumber=' + blockNumber
247
+ formattedBlockIdentifier
242
248
  ),
243
249
  __assign({ signature: [], calldata: [] }, invokeTransaction)
244
250
  ),
@@ -251,29 +257,34 @@ var Provider = /** @class */ (function () {
251
257
  });
252
258
  };
253
259
  /**
254
- * Gets the block information from a block ID.
260
+ * Gets the block information
255
261
  *
256
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
262
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
257
263
  *
264
+ * @param blockHash
258
265
  * @param blockNumber
259
266
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
260
267
  */
261
- Provider.prototype.getBlock = function (blockNumber) {
268
+ Provider.prototype.getBlock = function (blockHash, blockNumber) {
262
269
  if (blockNumber === void 0) {
263
270
  blockNumber = null;
264
271
  }
265
272
  return __awaiter(this, void 0, void 0, function () {
266
- var data;
273
+ var formattedBlockIdentifier, data;
267
274
  return __generator(this, function (_a) {
268
275
  switch (_a.label) {
269
276
  case 0:
277
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
278
+ blockHash,
279
+ blockNumber
280
+ );
270
281
  return [
271
282
  4 /*yield*/,
272
283
  axios_1.default.get(
273
284
  (0, url_join_1.default)(
274
285
  this.feederGatewayUrl,
275
286
  'get_block',
276
- '?blockNumber=' + blockNumber
287
+ formattedBlockIdentifier
277
288
  )
278
289
  ),
279
290
  ];
@@ -287,28 +298,33 @@ var Provider = /** @class */ (function () {
287
298
  /**
288
299
  * Gets the code of the deployed contract.
289
300
  *
290
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
301
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
291
302
  *
292
303
  * @param contractAddress
304
+ * @param blockHash
293
305
  * @param blockNumber
294
306
  * @returns Bytecode and ABI of compiled contract
295
307
  */
296
- Provider.prototype.getCode = function (contractAddress, blockNumber) {
308
+ Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
297
309
  if (blockNumber === void 0) {
298
310
  blockNumber = null;
299
311
  }
300
312
  return __awaiter(this, void 0, void 0, function () {
301
- var data;
313
+ var formattedBlockIdentifier, data;
302
314
  return __generator(this, function (_a) {
303
315
  switch (_a.label) {
304
316
  case 0:
317
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
318
+ blockHash,
319
+ blockNumber
320
+ );
305
321
  return [
306
322
  4 /*yield*/,
307
323
  axios_1.default.get(
308
324
  (0, url_join_1.default)(
309
325
  this.feederGatewayUrl,
310
326
  'get_code',
311
- '?contractAddress=' + contractAddress + '&blockNumber=' + blockNumber
327
+ '?contractAddress=' + contractAddress + '&' + formattedBlockIdentifier
312
328
  )
313
329
  ),
314
330
  ];
@@ -323,22 +339,27 @@ var Provider = /** @class */ (function () {
323
339
  /**
324
340
  * Gets the contract's storage variable at a specific key.
325
341
  *
326
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
342
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
327
343
  *
328
344
  * @param contractAddress
329
345
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
346
+ * @param blockHash
330
347
  * @param blockNumber
331
348
  * @returns the value of the storage variable
332
349
  */
333
- Provider.prototype.getStorageAt = function (contractAddress, key, blockNumber) {
350
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
334
351
  if (blockNumber === void 0) {
335
352
  blockNumber = null;
336
353
  }
337
354
  return __awaiter(this, void 0, void 0, function () {
338
- var data;
355
+ var formattedBlockIdentifier, data;
339
356
  return __generator(this, function (_a) {
340
357
  switch (_a.label) {
341
358
  case 0:
359
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
360
+ blockHash,
361
+ blockNumber
362
+ );
342
363
  return [
343
364
  4 /*yield*/,
344
365
  axios_1.default.get(
@@ -349,8 +370,8 @@ var Provider = /** @class */ (function () {
349
370
  contractAddress +
350
371
  '&key=' +
351
372
  key +
352
- '&blockNumber=' +
353
- blockNumber
373
+ '&' +
374
+ formattedBlockIdentifier
354
375
  )
355
376
  ),
356
377
  ];
@@ -521,7 +542,7 @@ var Provider = /** @class */ (function () {
521
542
  retryInterval = 8000;
522
543
  }
523
544
  return __awaiter(this, void 0, void 0, function () {
524
- var onchain, res;
545
+ var onchain, res, error;
525
546
  return __generator(this, function (_a) {
526
547
  switch (_a.label) {
527
548
  case 0:
@@ -542,10 +563,10 @@ var Provider = /** @class */ (function () {
542
563
  res = _a.sent();
543
564
  if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
544
565
  onchain = true;
545
- } else if (res.tx_status === 'REJECTED') {
546
- throw Error('REJECTED');
547
- } else if (res.tx_status === 'NOT_RECEIVED') {
548
- throw Error('NOT_RECEIVED');
566
+ } else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
567
+ error = Error(res.tx_status);
568
+ error.response = res;
569
+ throw error;
549
570
  }
550
571
  return [3 /*break*/, 2];
551
572
  case 5:
@@ -27,48 +27,58 @@ export declare abstract class ProviderInterface {
27
27
  /**
28
28
  * Calls a function on the StarkNet contract.
29
29
  *
30
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
30
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
31
31
  *
32
32
  * @param invokeTransaction - transaction to be invoked
33
+ * @param blockHash
33
34
  * @param blockNumber
34
35
  * @returns the result of the function on the smart contract.
35
36
  */
36
37
  abstract callContract(
37
38
  invokeTransaction: CallContractTransaction,
39
+ blockHash?: BigNumberish,
38
40
  blockNumber?: BlockNumber
39
41
  ): Promise<CallContractResponse>;
40
42
  /**
41
- * Gets the block information from a block ID.
43
+ * Gets the block information
42
44
  *
43
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
45
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
44
46
  *
47
+ * @param blockHash
45
48
  * @param blockNumber
46
49
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
47
50
  */
48
- abstract getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
51
+ abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
49
52
  /**
50
53
  * Gets the code of the deployed contract.
51
54
  *
52
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
55
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
53
56
  *
54
57
  * @param contractAddress
58
+ * @param blockHash
55
59
  * @param blockNumber
56
60
  * @returns Bytecode and ABI of compiled contract
57
61
  */
58
- abstract getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
62
+ abstract getCode(
63
+ contractAddress: string,
64
+ blockHash?: BigNumberish,
65
+ blockNumber?: BlockNumber
66
+ ): Promise<GetCodeResponse>;
59
67
  /**
60
68
  * Gets the contract's storage variable at a specific key.
61
69
  *
62
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
70
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
63
71
  *
64
72
  * @param contractAddress
65
73
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
74
+ * @param blockHash
66
75
  * @param blockNumber
67
76
  * @returns the value of the storage variable
68
77
  */
69
78
  abstract getStorageAt(
70
79
  contractAddress: string,
71
80
  key: number,
81
+ blockHash?: BigNumberish,
72
82
  blockNumber?: BlockNumber
73
83
  ): Promise<object>;
74
84
  /**
@@ -0,0 +1,30 @@
1
+ import type { BlockNumber } from '../types';
2
+ import { BigNumberish } from '../utils/number';
3
+ /**
4
+ * TODO
5
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
6
+ *
7
+ * @param hashValue
8
+ * @param hashField
9
+ */
10
+ export declare function formatHash(): void;
11
+ /**
12
+ * TODO
13
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
14
+ * @param txHash
15
+ * @param txId
16
+ */
17
+ export declare function txIdentifier(): void;
18
+ /**
19
+ * Gets the block identifier for API request
20
+ *
21
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
22
+ *
23
+ * @param blockNumber
24
+ * @param blockHash
25
+ * @returns block identifier for API request
26
+ */
27
+ export declare function getFormattedBlockIdentifier(
28
+ blockHash?: BigNumberish,
29
+ blockNumber?: BlockNumber
30
+ ): string;
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.getFormattedBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
4
+ /**
5
+ * TODO
6
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
7
+ *
8
+ * @param hashValue
9
+ * @param hashField
10
+ */
11
+ function formatHash() {}
12
+ exports.formatHash = formatHash;
13
+ /**
14
+ * TODO
15
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
16
+ * @param txHash
17
+ * @param txId
18
+ */
19
+ function txIdentifier() {}
20
+ exports.txIdentifier = txIdentifier;
21
+ /**
22
+ * Gets the block identifier for API request
23
+ *
24
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
25
+ *
26
+ * @param blockNumber
27
+ * @param blockHash
28
+ * @returns block identifier for API request
29
+ */
30
+ function getFormattedBlockIdentifier(blockHash, blockNumber) {
31
+ if (blockNumber === void 0) {
32
+ blockNumber = null;
33
+ }
34
+ if (blockHash) {
35
+ return '?blockHash=' + blockHash;
36
+ }
37
+ return '?blockNumber=' + blockNumber;
38
+ }
39
+ exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
@@ -1,5 +1,6 @@
1
1
  import { Provider } from '../provider';
2
2
  import { AddTransactionResponse, KeyPair, Signature, Transaction } from '../types';
3
+ import { BigNumberish } from '../utils/number';
3
4
  import { TypedData } from '../utils/typedData';
4
5
  import { SignerInterface } from './interface';
5
6
  export declare class Signer extends Provider implements SignerInterface {
@@ -31,4 +32,23 @@ export declare class Signer extends Provider implements SignerInterface {
31
32
  * @throws {Error} if the JSON object is not a valid JSON
32
33
  */
33
34
  hashMessage(typedData: TypedData): Promise<string>;
35
+ /**
36
+ * Verify a signature of a JSON object
37
+ *
38
+ * @param json - JSON object to be verified
39
+ * @param signature - signature of the JSON object
40
+ * @returns true if the signature is valid, false otherwise
41
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
42
+ */
43
+ verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
44
+ /**
45
+ * Verify a signature of a given hash
46
+ * @warning This method is not recommended, use verifyMessage instead
47
+ *
48
+ * @param hash - hash to be verified
49
+ * @param signature - signature of the hash
50
+ * @returns true if the signature is valid, false otherwise
51
+ * @throws {Error} if the signature is not a valid signature
52
+ */
53
+ verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
34
54
  }
package/signer/default.js CHANGED
@@ -197,6 +197,7 @@ var __importDefault =
197
197
  Object.defineProperty(exports, '__esModule', { value: true });
198
198
  exports.Signer = void 0;
199
199
  var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
200
+ var contract_1 = require('../contract');
200
201
  var provider_1 = require('../provider');
201
202
  var ellipticCurve_1 = require('../utils/ellipticCurve');
202
203
  var encode_1 = require('../utils/encode');
@@ -323,6 +324,69 @@ var Signer = /** @class */ (function (_super) {
323
324
  });
324
325
  });
325
326
  };
327
+ /**
328
+ * Verify a signature of a JSON object
329
+ *
330
+ * @param json - JSON object to be verified
331
+ * @param signature - signature of the JSON object
332
+ * @returns true if the signature is valid, false otherwise
333
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
334
+ */
335
+ Signer.prototype.verifyMessageHash = function (hash, signature) {
336
+ return __awaiter(this, void 0, void 0, function () {
337
+ var _a;
338
+ return __generator(this, function (_b) {
339
+ switch (_b.label) {
340
+ case 0:
341
+ _b.trys.push([0, 2, , 3]);
342
+ return [
343
+ 4 /*yield*/,
344
+ this.callContract({
345
+ contract_address: this.address,
346
+ entry_point_selector: (0, stark_1.getSelectorFromName)('is_valid_signature'),
347
+ calldata: (0, contract_1.compileCalldata)({
348
+ hash: (0, number_1.toBN)(hash).toString(),
349
+ signature: signature.map(function (x) {
350
+ return (0, number_1.toBN)(x).toString();
351
+ }),
352
+ }),
353
+ }),
354
+ ];
355
+ case 1:
356
+ _b.sent();
357
+ return [2 /*return*/, true];
358
+ case 2:
359
+ _a = _b.sent();
360
+ return [2 /*return*/, false];
361
+ case 3:
362
+ return [2 /*return*/];
363
+ }
364
+ });
365
+ });
366
+ };
367
+ /**
368
+ * Verify a signature of a given hash
369
+ * @warning This method is not recommended, use verifyMessage instead
370
+ *
371
+ * @param hash - hash to be verified
372
+ * @param signature - signature of the hash
373
+ * @returns true if the signature is valid, false otherwise
374
+ * @throws {Error} if the signature is not a valid signature
375
+ */
376
+ Signer.prototype.verifyMessage = function (typedData, signature) {
377
+ return __awaiter(this, void 0, void 0, function () {
378
+ var hash;
379
+ return __generator(this, function (_a) {
380
+ switch (_a.label) {
381
+ case 0:
382
+ return [4 /*yield*/, this.hashMessage(typedData)];
383
+ case 1:
384
+ hash = _a.sent();
385
+ return [2 /*return*/, this.verifyMessageHash(hash, signature)];
386
+ }
387
+ });
388
+ });
389
+ };
326
390
  return Signer;
327
391
  })(provider_1.Provider);
328
392
  exports.Signer = Signer;
@@ -1,5 +1,6 @@
1
1
  import { Provider } from '../provider';
2
2
  import { AddTransactionResponse, Signature, Transaction } from '../types';
3
+ import { BigNumberish } from '../utils/number';
3
4
  import { TypedData } from '../utils/typedData/types';
4
5
  export declare abstract class SignerInterface extends Provider {
5
6
  abstract address: string;
@@ -30,4 +31,23 @@ export declare abstract class SignerInterface extends Provider {
30
31
  * @throws {Error} if the JSON object is not a valid JSON
31
32
  */
32
33
  abstract hashMessage(typedData: TypedData): Promise<string>;
34
+ /**
35
+ * Verify a signature of a JSON object
36
+ *
37
+ * @param json - JSON object to be verified
38
+ * @param signature - signature of the JSON object
39
+ * @returns true if the signature is valid, false otherwise
40
+ * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
41
+ */
42
+ abstract verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
43
+ /**
44
+ * Verify a signature of a given hash
45
+ * @warning This method is not recommended, use verifyMessage instead
46
+ *
47
+ * @param hash - hash to be verified
48
+ * @param signature - signature of the hash
49
+ * @returns true if the signature is valid, false otherwise
50
+ * @throws {Error} if the signature is not a valid signature
51
+ */
52
+ abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
33
53
  }