@snapshot-labs/snapshot.js 0.14.12 → 0.14.13

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.
@@ -12,7 +12,6 @@ var addErrors = require('ajv-errors');
12
12
  var providers = require('@ethersproject/providers');
13
13
  var starknet$1 = require('starknet');
14
14
  var bytes = require('@ethersproject/bytes');
15
- var bignumber = require('@ethersproject/bignumber');
16
15
  var wallet = require('@ethersproject/wallet');
17
16
  var abi = require('@ethersproject/abi');
18
17
  var set = require('lodash.set');
@@ -2286,34 +2285,6 @@ const RPC_URLS = {
2286
2285
  SN_MAIN: (_b = (_a = networks[starknet$1.constants.StarknetChainId.SN_MAIN]) === null || _a === void 0 ? void 0 : _a.rpc) === null || _b === void 0 ? void 0 : _b[0],
2287
2286
  SN_SEPOLIA: (_d = (_c = networks[starknet$1.constants.StarknetChainId.SN_SEPOLIA]) === null || _c === void 0 ? void 0 : _c.rpc) === null || _d === void 0 ? void 0 : _d[0]
2288
2287
  };
2289
- const ABI = [
2290
- {
2291
- name: 'argent::common::account::IAccount',
2292
- type: 'interface',
2293
- items: [
2294
- {
2295
- name: 'is_valid_signature',
2296
- type: 'function',
2297
- inputs: [
2298
- {
2299
- name: 'hash',
2300
- type: 'core::felt252'
2301
- },
2302
- {
2303
- name: 'signature',
2304
- type: 'core::array::Array::<core::felt252>'
2305
- }
2306
- ],
2307
- outputs: [
2308
- {
2309
- type: 'core::felt252'
2310
- }
2311
- ],
2312
- state_mutability: 'view'
2313
- }
2314
- ]
2315
- }
2316
- ];
2317
2288
  function getProvider$1(network, options) {
2318
2289
  var _a;
2319
2290
  if (!RPC_URLS[network])
@@ -2329,40 +2300,14 @@ function getHash(data, address) {
2329
2300
  const { domain, types, primaryType, message } = data;
2330
2301
  return starknet$1.typedData.getMessageHash({ types, primaryType, domain, message }, address);
2331
2302
  }
2332
- /**
2333
- * Processes a StarkNet signature array and returns the appropriate signature format
2334
- * for contract verification.
2335
- * Returns the r ands values for each signature in the array.
2336
- *
2337
- * Handles the following cases:
2338
- * - 2-item array: Standard signature, returns as-is.
2339
- * - 3-item array: Some wallets (e.g., Braavos) may return a 3-item array; returns the last two items.
2340
- * - Multi-signer array: For multisig accounts, the array may contain multiple signatures;
2341
- * this function extracts the relevant signature pairs.
2342
- *
2343
- * @param {string[]} sig - The signature array to process. Must have at least 2 items.
2344
- * @returns {string[]} The processed signature array suitable for contract verification.
2345
- * @throws {Error} If the signature array has fewer than 2 items.
2346
- */
2347
- function getSignatureArray(sig) {
2348
- if (sig.length < 2) {
2349
- throw new Error('Invalid signature format');
2350
- }
2351
- if (sig.length <= 3) {
2352
- return sig.slice(-2);
2353
- }
2354
- const results = [];
2355
- for (let i = 1; i < sig.length; i += 4) {
2356
- results.push(sig[i + 2], sig[i + 3]);
2357
- }
2358
- return results;
2359
- }
2360
2303
  function verify(address_1, sig_1, data_1) {
2361
2304
  return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
2362
2305
  try {
2363
- const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
2364
- const result = yield contractAccount.is_valid_signature(getHash(data, address), getSignatureArray(sig));
2365
- return bignumber.BigNumber.from(result).eq(bignumber.BigNumber.from('370462705988'));
2306
+ const provider = getProvider$1(network, options);
2307
+ // Check if the contract is deployed
2308
+ // Will throw on non-deployed contract
2309
+ yield provider.getClassAt(address);
2310
+ return provider.verifyMessageInStarknet(data, sig, address);
2366
2311
  }
2367
2312
  catch (e) {
2368
2313
  if (e.message.includes('Contract not found')) {
@@ -1,5 +1,5 @@
1
1
  import crossFetch from 'cross-fetch';
2
- import { Contract as Contract$1 } from '@ethersproject/contracts';
2
+ import { Contract } from '@ethersproject/contracts';
3
3
  import { isAddress, getAddress } from '@ethersproject/address';
4
4
  import { parseUnits } from '@ethersproject/units';
5
5
  import { _TypedDataEncoder, namehash, ensNormalize } from '@ethersproject/hash';
@@ -8,9 +8,8 @@ import Ajv from 'ajv';
8
8
  import addFormats from 'ajv-formats';
9
9
  import addErrors from 'ajv-errors';
10
10
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
11
- import { RpcProvider, constants as constants$1, Contract, typedData, transaction, uint256, shortString, num, validateAndParseAddress } from 'starknet';
11
+ import { RpcProvider, constants as constants$1, typedData, transaction, uint256, shortString, num, validateAndParseAddress } from 'starknet';
12
12
  import { hexlify, concat, arrayify } from '@ethersproject/bytes';
13
- import { BigNumber } from '@ethersproject/bignumber';
14
13
  import { verifyTypedData } from '@ethersproject/wallet';
15
14
  import { AbiCoder, Interface } from '@ethersproject/abi';
16
15
  import set from 'lodash.set';
@@ -2276,34 +2275,6 @@ const RPC_URLS = {
2276
2275
  SN_MAIN: (_b = (_a = networks[constants$1.StarknetChainId.SN_MAIN]) === null || _a === void 0 ? void 0 : _a.rpc) === null || _b === void 0 ? void 0 : _b[0],
2277
2276
  SN_SEPOLIA: (_d = (_c = networks[constants$1.StarknetChainId.SN_SEPOLIA]) === null || _c === void 0 ? void 0 : _c.rpc) === null || _d === void 0 ? void 0 : _d[0]
2278
2277
  };
2279
- const ABI = [
2280
- {
2281
- name: 'argent::common::account::IAccount',
2282
- type: 'interface',
2283
- items: [
2284
- {
2285
- name: 'is_valid_signature',
2286
- type: 'function',
2287
- inputs: [
2288
- {
2289
- name: 'hash',
2290
- type: 'core::felt252'
2291
- },
2292
- {
2293
- name: 'signature',
2294
- type: 'core::array::Array::<core::felt252>'
2295
- }
2296
- ],
2297
- outputs: [
2298
- {
2299
- type: 'core::felt252'
2300
- }
2301
- ],
2302
- state_mutability: 'view'
2303
- }
2304
- ]
2305
- }
2306
- ];
2307
2278
  function getProvider$1(network, options) {
2308
2279
  var _a;
2309
2280
  if (!RPC_URLS[network])
@@ -2319,40 +2290,14 @@ function getHash(data, address) {
2319
2290
  const { domain, types, primaryType, message } = data;
2320
2291
  return typedData.getMessageHash({ types, primaryType, domain, message }, address);
2321
2292
  }
2322
- /**
2323
- * Processes a StarkNet signature array and returns the appropriate signature format
2324
- * for contract verification.
2325
- * Returns the r ands values for each signature in the array.
2326
- *
2327
- * Handles the following cases:
2328
- * - 2-item array: Standard signature, returns as-is.
2329
- * - 3-item array: Some wallets (e.g., Braavos) may return a 3-item array; returns the last two items.
2330
- * - Multi-signer array: For multisig accounts, the array may contain multiple signatures;
2331
- * this function extracts the relevant signature pairs.
2332
- *
2333
- * @param {string[]} sig - The signature array to process. Must have at least 2 items.
2334
- * @returns {string[]} The processed signature array suitable for contract verification.
2335
- * @throws {Error} If the signature array has fewer than 2 items.
2336
- */
2337
- function getSignatureArray(sig) {
2338
- if (sig.length < 2) {
2339
- throw new Error('Invalid signature format');
2340
- }
2341
- if (sig.length <= 3) {
2342
- return sig.slice(-2);
2343
- }
2344
- const results = [];
2345
- for (let i = 1; i < sig.length; i += 4) {
2346
- results.push(sig[i + 2], sig[i + 3]);
2347
- }
2348
- return results;
2349
- }
2350
2293
  function verify(address_1, sig_1, data_1) {
2351
2294
  return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
2352
2295
  try {
2353
- const contractAccount = new Contract(ABI, address, getProvider$1(network, options));
2354
- const result = yield contractAccount.is_valid_signature(getHash(data, address), getSignatureArray(sig));
2355
- return BigNumber.from(result).eq(BigNumber.from('370462705988'));
2296
+ const provider = getProvider$1(network, options);
2297
+ // Check if the contract is deployed
2298
+ // Will throw on non-deployed contract
2299
+ yield provider.getClassAt(address);
2300
+ return provider.verifyMessageInStarknet(data, sig, address);
2356
2301
  }
2357
2302
  catch (e) {
2358
2303
  if (e.message.includes('Contract not found')) {
@@ -3154,7 +3099,7 @@ const multicallAbi = [
3154
3099
  ];
3155
3100
  function multicall(address_1, provider_1, abi_1, calls_1, limit_1) {
3156
3101
  return __awaiter(this, arguments, void 0, function* (address, provider, abi, calls, limit, options = {}) {
3157
- const multi = new Contract$1(address, multicallAbi, provider);
3102
+ const multi = new Contract(address, multicallAbi, provider);
3158
3103
  const itf = new Interface(abi);
3159
3104
  try {
3160
3105
  const pages = Math.ceil(calls.length / limit);
@@ -3571,7 +3516,7 @@ function getDNSOwner(domain) {
3571
3516
  }
3572
3517
  function call(provider, abi, call, options) {
3573
3518
  return __awaiter(this, void 0, void 0, function* () {
3574
- const contract = new Contract$1(call[0], abi, provider);
3519
+ const contract = new Contract(call[0], abi, provider);
3575
3520
  try {
3576
3521
  const params = call[2] || [];
3577
3522
  return yield contract[call[1]](...params, options || {});
@@ -3693,7 +3638,7 @@ function ipfsGet(gateway_1, ipfsHash_1) {
3693
3638
  function sendTransaction(web3_1, contractAddress_1, abi_1, action_1, params_1) {
3694
3639
  return __awaiter(this, arguments, void 0, function* (web3, contractAddress, abi, action, params, overrides = {}) {
3695
3640
  const signer = web3.getSigner();
3696
- const contract = new Contract$1(contractAddress, abi, web3);
3641
+ const contract = new Contract(contractAddress, abi, web3);
3697
3642
  const contractWithSigner = contract.connect(signer);
3698
3643
  // overrides.gasLimit = 12e6;
3699
3644
  return yield contractWithSigner[action](...params, overrides);
@@ -3893,7 +3838,7 @@ function getEnsOwner(ens_1) {
3893
3838
  }
3894
3839
  const domainType = getDomainType(ens);
3895
3840
  const provider = getProvider(network, options);
3896
- const ensRegistry = new Contract$1(ENS_REGISTRY, ['function owner(bytes32) view returns (address)'], provider);
3841
+ const ensRegistry = new Contract(ENS_REGISTRY, ['function owner(bytes32) view returns (address)'], provider);
3897
3842
  let ensHash;
3898
3843
  try {
3899
3844
  ensHash = namehash(ensNormalize(ens));
@@ -3905,7 +3850,7 @@ function getEnsOwner(ens_1) {
3905
3850
  let owner = yield ensRegistry.owner(ensHash);
3906
3851
  // If owner is the ENSNameWrapper contract, resolve the owner of the name
3907
3852
  if (owner === ensNameWrapper) {
3908
- const ensNameWrapperContract = new Contract$1(ensNameWrapper, ['function ownerOf(uint256) view returns (address)'], provider);
3853
+ const ensNameWrapperContract = new Contract(ensNameWrapper, ['function ownerOf(uint256) view returns (address)'], provider);
3909
3854
  owner = yield ensNameWrapperContract.ownerOf(ensHash);
3910
3855
  }
3911
3856
  if (owner === EMPTY_ADDRESS && domainType === 'other-tld') {