@snapshot-labs/snapshot.js 0.12.12 → 0.12.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.12.12",
3
+ "version": "0.12.13",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/networks.json CHANGED
@@ -904,6 +904,20 @@
904
904
  "start": 4219343,
905
905
  "logo": "ipfs://QmXkneyRB6HbHTHRLCZpZqSsawiyJY7b2kZ2V8ydvKYAgv"
906
906
  },
907
+ "2192": {
908
+ "key": "2192",
909
+ "name": "SnaxChain",
910
+ "shortName": "mainnet",
911
+ "chainId": 2192,
912
+ "network": "mainnet",
913
+ "multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
914
+ "rpc": [],
915
+ "explorer": {
916
+ "url": "https://explorer.snaxchain.io"
917
+ },
918
+ "start": 1554893,
919
+ "logo": "ipfs://bafkreibzz757piho2llzkbiszpvalf5k5hpmxcwhvrmgp7vpz2vp4vj7ly"
920
+ },
907
921
  "2221": {
908
922
  "key": "2221",
909
923
  "name": "Kava Testnet",
@@ -1557,7 +1571,7 @@
1557
1571
  "0x8FADE66B79cC9f707aB26799354482EB93a5B7dD"
1558
1572
  ],
1559
1573
  "ensNameWrapper": "0x0635513f179D50A207757E05759CbD106d7dFcE8",
1560
- "ensSubgraph": "https://api.studio.thegraph.com/proxy/49574/enssepolia/version/latest",
1574
+ "ensSubgraph": "https://subgrapher.snapshot.org/subgraph/arbitrum/DmMXLtMZnGbQXASJ7p1jfzLUbBYnYUD9zNBTxpkjHYXV",
1561
1575
  "explorer": {
1562
1576
  "url": "https://sepolia.etherscan.io",
1563
1577
  "apiUrl": "https://api-sepolia.etherscan.io"
@@ -1680,4 +1694,4 @@
1680
1694
  "start": 7521509,
1681
1695
  "logo": "ipfs://QmNnGPr1CNvj12SSGzKARtUHv9FyEfE5nES73U4vBWQSJL"
1682
1696
  }
1683
- }
1697
+ }
@@ -1,5 +1,7 @@
1
1
  import { test, expect, describe } from 'vitest';
2
2
  import evmMessage from '../../test/fixtures/evm/message-alias.json';
3
+ import eip6492Message from '../../test/fixtures/evm/eip-6492.json';
4
+ import eip1271Message from '../../test/fixtures/evm/eip-1271.json';
3
5
  import verify, { getHash } from './evm';
4
6
 
5
7
  describe('verify/evm', () => {
@@ -28,5 +30,61 @@ describe('verify/evm', () => {
28
30
  )
29
31
  ).rejects.toThrowError(/isValidSignature/);
30
32
  });
33
+
34
+ test('should return true if the eip-1271 message signature is valid', async () => {
35
+ expect(
36
+ verify(eip1271Message.address, eip1271Message.sig, eip1271Message.data)
37
+ ).resolves.toBe(true);
38
+ });
39
+
40
+ test('should reject if the eip-1271 message signer address is wrong', async () => {
41
+ expect(
42
+ verify(
43
+ '0xDD983E11Cf84746f3b7589ee1Dc2081c08c40Cb3',
44
+ eip1271Message.sig,
45
+ eip1271Message.data
46
+ )
47
+ ).rejects.toThrowError(/isValidSignature/);
48
+ });
49
+
50
+ test('should reject if the eip-1271 message signature is invalid', async () => {
51
+ const invalidMessageData = Object.assign({}, eip1271Message.data, {
52
+ message: {
53
+ ...eip1271Message.data.message,
54
+ choices: [false]
55
+ }
56
+ });
57
+ expect(
58
+ verify(eip1271Message.address, eip1271Message.sig, invalidMessageData)
59
+ ).rejects.toThrowError(/Hash not approved/);
60
+ });
61
+
62
+ test('should return true if the eip-6492 message signature is valid', async () => {
63
+ expect(
64
+ verify(eip6492Message.address, eip6492Message.sig, eip6492Message.data)
65
+ ).resolves.toBe(true);
66
+ });
67
+
68
+ test('should reject if the eip-6492 message signer address is wrong', async () => {
69
+ expect(
70
+ verify(
71
+ '0xDD983E11Cf84746f3b7589ee1Dc2081c08c40Cb3',
72
+ eip6492Message.sig,
73
+ eip6492Message.data
74
+ )
75
+ ).resolves.toBe(false);
76
+ });
77
+
78
+ test('should reject if the eip-6492 message signature is invalid', async () => {
79
+ const invalidMessageData = Object.assign({}, eip6492Message.data, {
80
+ message: {
81
+ ...eip6492Message.data.message,
82
+ choice: 3
83
+ }
84
+ });
85
+ expect(
86
+ verify(eip6492Message.address, eip6492Message.sig, invalidMessageData)
87
+ ).resolves.toBe(false);
88
+ });
31
89
  });
32
90
  });
package/src/verify/evm.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { verifyTypedData } from '@ethersproject/wallet';
2
2
  import { _TypedDataEncoder } from '@ethersproject/hash';
3
- import { arrayify } from '@ethersproject/bytes';
3
+ import { arrayify, concat } from '@ethersproject/bytes';
4
4
  import getProvider, { type ProviderOptions } from '../utils/provider';
5
5
  import { call } from '../utils';
6
6
  import type { SignaturePayload } from '.';
7
7
  import type { StaticJsonRpcProvider } from '@ethersproject/providers';
8
+ import { AbiCoder } from '@ethersproject/abi';
9
+
10
+ const ERC6492_DETECTION_SUFFIX =
11
+ '6492649264926492649264926492649264926492649264926492649264926492';
8
12
 
9
13
  function isEqual(a: string, b: string): boolean {
10
14
  return a.toLowerCase() === b.toLowerCase();
@@ -32,8 +36,34 @@ export default async function verify(
32
36
  const provider = getProvider(network, options);
33
37
  const hash = getHash(data);
34
38
 
35
- if (await verifyDefault(address, sig, hash, provider)) return true;
39
+ // Handle EIP-6492
40
+ // https://eips.ethereum.org/EIPS/eip-6492
41
+ //
42
+ // We can actually replace verifyTypedData and verifyDefault with the following code,
43
+ // but https://github.com/AmbireTech/signature-validator/blob/main/contracts/DeploylessUniversalSigValidator.sol
44
+ // also can send an extra network request to the provider. (with verifyTypedData we don't send any extra request)
45
+ //
46
+ if (sig.endsWith(ERC6492_DETECTION_SUFFIX)) {
47
+ try {
48
+ return (
49
+ '0x01' ===
50
+ (await provider.call({
51
+ data: concat([
52
+ '0x60806040523480156200001157600080fd5b50604051620007003803806200070083398101604081905262000034916200056f565b6000620000438484846200004f565b9050806000526001601ff35b600080846001600160a01b0316803b806020016040519081016040528181526000908060200190933c90507f6492649264926492649264926492649264926492649264926492649264926492620000a68462000451565b036200021f57600060608085806020019051810190620000c79190620005ce565b8651929550909350915060000362000192576000836001600160a01b031683604051620000f5919062000643565b6000604051808303816000865af19150503d806000811462000134576040519150601f19603f3d011682016040523d82523d6000602084013e62000139565b606091505b5050905080620001905760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b505b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90620001c4908b90869060040162000661565b602060405180830381865afa158015620001e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200020891906200069d565b6001600160e01b031916149450505050506200044a565b805115620002b157604051630b135d3f60e11b808252906001600160a01b03871690631626ba7e9062000259908890889060040162000661565b602060405180830381865afa15801562000277573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200029d91906200069d565b6001600160e01b031916149150506200044a565b8251604114620003195760405162461bcd60e51b815260206004820152603a6024820152600080516020620006e083398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e677468000000000000606482015260840162000187565b620003236200046b565b506020830151604080850151855186939260009185919081106200034b576200034b620006c9565b016020015160f81c9050601b81148015906200036b57508060ff16601c14155b15620003cf5760405162461bcd60e51b815260206004820152603b6024820152600080516020620006e083398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c75650000000000606482015260840162000187565b6040805160008152602081018083528a905260ff83169181019190915260608101849052608081018390526001600160a01b038a169060019060a0016020604051602081039080840390855afa1580156200042e573d6000803e3d6000fd5b505050602060405103516001600160a01b031614955050505050505b9392505050565b60006020825110156200046357600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b03811681146200049f57600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b83811015620004d5578181015183820152602001620004bb565b50506000910152565b600082601f830112620004f057600080fd5b81516001600160401b03808211156200050d576200050d620004a2565b604051601f8301601f19908116603f01168101908282118183101715620005385762000538620004a2565b816040528381528660208588010111156200055257600080fd5b62000565846020830160208901620004b8565b9695505050505050565b6000806000606084860312156200058557600080fd5b8351620005928162000489565b6020850151604086015191945092506001600160401b03811115620005b657600080fd5b620005c486828701620004de565b9150509250925092565b600080600060608486031215620005e457600080fd5b8351620005f18162000489565b60208501519093506001600160401b03808211156200060f57600080fd5b6200061d87838801620004de565b935060408601519150808211156200063457600080fd5b50620005c486828701620004de565b6000825162000657818460208701620004b8565b9190910192915050565b828152604060208201526000825180604084015262000688816060850160208701620004b8565b601f01601f1916919091016060019392505050565b600060208284031215620006b057600080fd5b81516001600160e01b0319811681146200044a57600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572',
53
+ new AbiCoder().encode(
54
+ ['address', 'bytes32', 'bytes'],
55
+ [address, arrayify(hash), sig]
56
+ )
57
+ ])
58
+ }))
59
+ );
60
+ } catch (error) {
61
+ return false;
62
+ }
63
+ }
36
64
 
65
+ // Handle EIP-1271
66
+ if (await verifyDefault(address, sig, hash, provider)) return true;
37
67
  return await verifyOldVersion(address, sig, hash, provider);
38
68
  }
39
69