@snapshot-labs/snapshot.js 0.12.1 → 0.12.2

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.
@@ -14,6 +14,7 @@ var set = require('lodash.set');
14
14
  var providers$1 = require('@ethersproject/providers');
15
15
  var bytes = require('@ethersproject/bytes');
16
16
  var starknet$1 = require('starknet');
17
+ var bignumber = require('@ethersproject/bignumber');
17
18
  var wallet = require('@ethersproject/wallet');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -1405,11 +1406,11 @@ const RPC_URLS = {
1405
1406
  };
1406
1407
  const ABI = [
1407
1408
  {
1408
- name: 'argent::account::interface::IDeprecatedArgentAccount',
1409
+ name: 'argent::common::account::IAccount',
1409
1410
  type: 'interface',
1410
1411
  items: [
1411
1412
  {
1412
- name: 'isValidSignature',
1413
+ name: 'is_valid_signature',
1413
1414
  type: 'function',
1414
1415
  inputs: [
1415
1416
  {
@@ -1417,7 +1418,7 @@ const ABI = [
1417
1418
  type: 'core::felt252'
1418
1419
  },
1419
1420
  {
1420
- name: 'signatures',
1421
+ name: 'signature',
1421
1422
  type: 'core::array::Array::<core::felt252>'
1422
1423
  }
1423
1424
  ],
@@ -1448,12 +1449,20 @@ function getHash(data, address) {
1448
1449
  }
1449
1450
  function verify(address_1, sig_1, data_1) {
1450
1451
  return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
1451
- const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
1452
- yield contractAccount.isValidSignature(getHash(data, address), [
1453
- sig[0],
1454
- sig[1]
1455
- ]);
1456
- return true;
1452
+ try {
1453
+ const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
1454
+ if (sig.length < 2) {
1455
+ throw new Error('Invalid signature format');
1456
+ }
1457
+ const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
1458
+ return bignumber.BigNumber.from(result).eq(bignumber.BigNumber.from('370462705988'));
1459
+ }
1460
+ catch (e) {
1461
+ if (e.message.includes('Contract not found')) {
1462
+ throw new Error('Contract not deployed');
1463
+ }
1464
+ throw e;
1465
+ }
1457
1466
  });
1458
1467
  }
1459
1468
 
@@ -12,6 +12,7 @@ import set from 'lodash.set';
12
12
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
13
13
  import { hexlify, arrayify } from '@ethersproject/bytes';
14
14
  import { Contract, RpcProvider, typedData, validateAndParseAddress } from 'starknet';
15
+ import { BigNumber } from '@ethersproject/bignumber';
15
16
  import { verifyTypedData } from '@ethersproject/wallet';
16
17
 
17
18
  /*! *****************************************************************************
@@ -1395,11 +1396,11 @@ const RPC_URLS = {
1395
1396
  };
1396
1397
  const ABI = [
1397
1398
  {
1398
- name: 'argent::account::interface::IDeprecatedArgentAccount',
1399
+ name: 'argent::common::account::IAccount',
1399
1400
  type: 'interface',
1400
1401
  items: [
1401
1402
  {
1402
- name: 'isValidSignature',
1403
+ name: 'is_valid_signature',
1403
1404
  type: 'function',
1404
1405
  inputs: [
1405
1406
  {
@@ -1407,7 +1408,7 @@ const ABI = [
1407
1408
  type: 'core::felt252'
1408
1409
  },
1409
1410
  {
1410
- name: 'signatures',
1411
+ name: 'signature',
1411
1412
  type: 'core::array::Array::<core::felt252>'
1412
1413
  }
1413
1414
  ],
@@ -1438,12 +1439,20 @@ function getHash(data, address) {
1438
1439
  }
1439
1440
  function verify(address_1, sig_1, data_1) {
1440
1441
  return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
1441
- const contractAccount = new Contract(ABI, address, getProvider$1(network, options));
1442
- yield contractAccount.isValidSignature(getHash(data, address), [
1443
- sig[0],
1444
- sig[1]
1445
- ]);
1446
- return true;
1442
+ try {
1443
+ const contractAccount = new Contract(ABI, address, getProvider$1(network, options));
1444
+ if (sig.length < 2) {
1445
+ throw new Error('Invalid signature format');
1446
+ }
1447
+ const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
1448
+ return BigNumber.from(result).eq(BigNumber.from('370462705988'));
1449
+ }
1450
+ catch (e) {
1451
+ if (e.message.includes('Contract not found')) {
1452
+ throw new Error('Contract not deployed');
1453
+ }
1454
+ throw e;
1455
+ }
1447
1456
  });
1448
1457
  }
1449
1458