@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.14.10",
3
+ "version": "0.14.12",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/networks.json CHANGED
@@ -1567,7 +1567,7 @@
1567
1567
  "https://celo-mainnet--rpc.datahub.figment.io/apikey/e892a66dc36e4d2d98a5d6406d609796/"
1568
1568
  ],
1569
1569
  "explorer": {
1570
- "url": "https://explorer.celo.org"
1570
+ "url": "https://celoscan.io"
1571
1571
  },
1572
1572
  "start": 6599803,
1573
1573
  "logo": "ipfs://bafkreidvcofeczigbjr7ddapgdugwso6v2l4iolfxys7qg6kfvu2uduyva"
@@ -57,6 +57,7 @@
57
57
  "6f6cdd15a1e9e6c4ee544231c4fa7b6c7e5183bc2b37fa4bd1a695f458348ab7": "delete-space",
58
58
  "1aad7825b991457fca04aae48a2a49d815ada524e10316af0da5522ea48b3df6": "alias",
59
59
  "8ea9074bff3a30cb61f4f0f0f142c9335c6be828feba0571a45de3f1fd0319c0": "alias",
60
+ "23310e197cbdcd80e506c0dbdd41831c9cf91d103a3ab663b278a1944a210920": "alias",
60
61
  "42f8858a21d4aa232721cb97074851e729829ea362b88bb21f3879899663b586": "follow",
61
62
  "2bb75450e28b06f259ea764cd669de6bde0ba70ce729b0ff05ab9df56e0ff21d": "unfollow",
62
63
  "2ffbebcbd22ef48fd2f4a1182ff1feda7795b57689bd6f0dd73c89e925e7fefb": "profile",
@@ -1,6 +1,7 @@
1
1
  import { test, expect, describe } from 'vitest';
2
2
  import starknetMessage from '../../test/fixtures/starknet/message-alias.json';
3
3
  import starknetMessageRsv from '../../test/fixtures/starknet/message-alias-rsv.json';
4
+ import starknetMessageMultisigner from '../../test/fixtures/starknet/message-alias-multisigner.json';
4
5
  import verify, { getHash } from './starknet';
5
6
  import { validateAndParseAddress } from 'starknet';
6
7
  import { clone } from '../utils';
@@ -24,9 +25,10 @@ describe('verify/starknet', () => {
24
25
 
25
26
  describe('verify()', () => {
26
27
  describe.each([
27
- ['2', starknetMessage],
28
- ['3', starknetMessageRsv]
29
- ])('with a %s items signature', (title, message) => {
28
+ ['2 items', starknetMessage, false],
29
+ ['3 items', starknetMessageRsv, false],
30
+ ['multiple signers', starknetMessageMultisigner, true]
31
+ ])('with a %s signature', (title, message, multisign) => {
30
32
  test('should return true if the signature is valid', () => {
31
33
  expect(
32
34
  verify(message.address, message.sig, message.data, 'SN_MAIN')
@@ -44,11 +46,19 @@ describe('verify/starknet', () => {
44
46
  ).resolves.toBe(true);
45
47
  });
46
48
 
47
- test('should return true when verifying on a different network', () => {
48
- expect(
49
- verify(message.address, message.sig, message.data, 'SN_SEPOLIA')
50
- ).resolves.toBe(true);
51
- });
49
+ if (multisign) {
50
+ test('should throw an error when verifying on a different network', () => {
51
+ expect(
52
+ verify(message.address, message.sig, message.data, 'SN_SEPOLIA')
53
+ ).rejects.toThrowError();
54
+ });
55
+ } else {
56
+ test('should return true when verifying on a different network', () => {
57
+ expect(
58
+ verify(message.address, message.sig, message.data, 'SN_SEPOLIA')
59
+ ).resolves.toBe(true);
60
+ });
61
+ }
52
62
 
53
63
  test('should throw an error if the signature is invalid', () => {
54
64
  expect(
@@ -62,6 +62,38 @@ export function getHash(data: SignaturePayload, address: string): string {
62
62
  );
63
63
  }
64
64
 
65
+ /**
66
+ * Processes a StarkNet signature array and returns the appropriate signature format
67
+ * for contract verification.
68
+ * Returns the r ands values for each signature in the array.
69
+ *
70
+ * Handles the following cases:
71
+ * - 2-item array: Standard signature, returns as-is.
72
+ * - 3-item array: Some wallets (e.g., Braavos) may return a 3-item array; returns the last two items.
73
+ * - Multi-signer array: For multisig accounts, the array may contain multiple signatures;
74
+ * this function extracts the relevant signature pairs.
75
+ *
76
+ * @param {string[]} sig - The signature array to process. Must have at least 2 items.
77
+ * @returns {string[]} The processed signature array suitable for contract verification.
78
+ * @throws {Error} If the signature array has fewer than 2 items.
79
+ */
80
+ function getSignatureArray(sig: string[]): string[] {
81
+ if (sig.length < 2) {
82
+ throw new Error('Invalid signature format');
83
+ }
84
+
85
+ if (sig.length <= 3) {
86
+ return sig.slice(-2);
87
+ }
88
+
89
+ const results: string[] = [];
90
+ for (let i = 1; i < sig.length; i += 4) {
91
+ results.push(sig[i + 2], sig[i + 3]);
92
+ }
93
+
94
+ return results;
95
+ }
96
+
65
97
  export default async function verify(
66
98
  address: string,
67
99
  sig: string[],
@@ -76,13 +108,9 @@ export default async function verify(
76
108
  getProvider(network, options)
77
109
  );
78
110
 
79
- if (sig.length < 2) {
80
- throw new Error('Invalid signature format');
81
- }
82
-
83
111
  const result = await contractAccount.is_valid_signature(
84
112
  getHash(data, address),
85
- sig.slice(-2)
113
+ getSignatureArray(sig)
86
114
  );
87
115
 
88
116
  return BigNumber.from(result).eq(BigNumber.from('370462705988'));