@snapshot-labs/snapshot.js 0.14.10 → 0.14.12

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.
@@ -1719,7 +1719,7 @@ var networks = {
1719
1719
  "https://celo-mainnet--rpc.datahub.figment.io/apikey/e892a66dc36e4d2d98a5d6406d609796/"
1720
1720
  ],
1721
1721
  explorer: {
1722
- url: "https://explorer.celo.org"
1722
+ url: "https://celoscan.io"
1723
1723
  },
1724
1724
  start: 6599803,
1725
1725
  logo: "ipfs://bafkreidvcofeczigbjr7ddapgdugwso6v2l4iolfxys7qg6kfvu2uduyva"
@@ -2329,14 +2329,39 @@ function getHash(data, address) {
2329
2329
  const { domain, types, primaryType, message } = data;
2330
2330
  return starknet$1.typedData.getMessageHash({ types, primaryType, domain, message }, address);
2331
2331
  }
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
+ }
2332
2360
  function verify(address_1, sig_1, data_1) {
2333
2361
  return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
2334
2362
  try {
2335
2363
  const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
2336
- if (sig.length < 2) {
2337
- throw new Error('Invalid signature format');
2338
- }
2339
- const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
2364
+ const result = yield contractAccount.is_valid_signature(getHash(data, address), getSignatureArray(sig));
2340
2365
  return bignumber.BigNumber.from(result).eq(bignumber.BigNumber.from('370462705988'));
2341
2366
  }
2342
2367
  catch (e) {
@@ -1709,7 +1709,7 @@ var networks = {
1709
1709
  "https://celo-mainnet--rpc.datahub.figment.io/apikey/e892a66dc36e4d2d98a5d6406d609796/"
1710
1710
  ],
1711
1711
  explorer: {
1712
- url: "https://explorer.celo.org"
1712
+ url: "https://celoscan.io"
1713
1713
  },
1714
1714
  start: 6599803,
1715
1715
  logo: "ipfs://bafkreidvcofeczigbjr7ddapgdugwso6v2l4iolfxys7qg6kfvu2uduyva"
@@ -2319,14 +2319,39 @@ function getHash(data, address) {
2319
2319
  const { domain, types, primaryType, message } = data;
2320
2320
  return typedData.getMessageHash({ types, primaryType, domain, message }, address);
2321
2321
  }
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
+ }
2322
2350
  function verify(address_1, sig_1, data_1) {
2323
2351
  return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
2324
2352
  try {
2325
2353
  const contractAccount = new Contract(ABI, address, getProvider$1(network, options));
2326
- if (sig.length < 2) {
2327
- throw new Error('Invalid signature format');
2328
- }
2329
- const result = yield contractAccount.is_valid_signature(getHash(data, address), sig.slice(-2));
2354
+ const result = yield contractAccount.is_valid_signature(getHash(data, address), getSignatureArray(sig));
2330
2355
  return BigNumber.from(result).eq(BigNumber.from('370462705988'));
2331
2356
  }
2332
2357
  catch (e) {