@snapshot-labs/snapshot.js 0.14.12 → 0.14.14
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/dist/snapshot.cjs.js +38 -62
- package/dist/snapshot.esm.js +45 -69
- package/dist/snapshot.min.js +15 -15
- package/dist/src/verify/starknet.d.ts +1 -1
- package/package.json +1 -1
- package/src/networks.json +32 -3
- package/src/verify/starknet.spec.ts +16 -8
- package/src/verify/starknet.ts +7 -74
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SignaturePayload } from '.';
|
|
2
1
|
import type { ProviderOptions } from '../utils/provider';
|
|
2
|
+
import type { SignaturePayload } from '.';
|
|
3
3
|
export type NetworkType = 'SN_MAIN' | 'SN_SEPOLIA';
|
|
4
4
|
export declare function isStarknetMessage(data: SignaturePayload): boolean;
|
|
5
5
|
export declare function getHash(data: SignaturePayload, address: string): string;
|
package/package.json
CHANGED
package/src/networks.json
CHANGED
|
@@ -1332,7 +1332,7 @@
|
|
|
1332
1332
|
"url": "https://basescan.org"
|
|
1333
1333
|
},
|
|
1334
1334
|
"start": 5022,
|
|
1335
|
-
"logo": "ipfs://
|
|
1335
|
+
"logo": "ipfs://bafkreid4ek4gnj6ccxl3yubwj2wr3d5t6dqelvvh4hv5wo5eldkqs725ri"
|
|
1336
1336
|
},
|
|
1337
1337
|
"9001": {
|
|
1338
1338
|
"key": "9001",
|
|
@@ -1769,7 +1769,36 @@
|
|
|
1769
1769
|
"url": "https://base-sepolia.blockscout.com"
|
|
1770
1770
|
},
|
|
1771
1771
|
"start": 1059647,
|
|
1772
|
-
"logo": "ipfs://
|
|
1772
|
+
"logo": "ipfs://bafkreid4ek4gnj6ccxl3yubwj2wr3d5t6dqelvvh4hv5wo5eldkqs725ri",
|
|
1773
|
+
"testnet": true
|
|
1774
|
+
},
|
|
1775
|
+
"88811": {
|
|
1776
|
+
"key": "88811",
|
|
1777
|
+
"name": "Unit Zero",
|
|
1778
|
+
"shortName": "mainnet",
|
|
1779
|
+
"chainId": 88811,
|
|
1780
|
+
"network": "mainnet",
|
|
1781
|
+
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
1782
|
+
"rpc": [],
|
|
1783
|
+
"explorer": {
|
|
1784
|
+
"url": "https://explorer.unit0.dev"
|
|
1785
|
+
},
|
|
1786
|
+
"start": 9727,
|
|
1787
|
+
"logo": "ipfs://bafkreihbmy3rqlammea35nniemipxrwcgitzkiahs6nlrfjunnvgfnakp4"
|
|
1788
|
+
},
|
|
1789
|
+
"88817": {
|
|
1790
|
+
"key": "88817",
|
|
1791
|
+
"name": "Unit Zero testnet",
|
|
1792
|
+
"shortName": "testnet",
|
|
1793
|
+
"chainId": 88817,
|
|
1794
|
+
"network": "testnet",
|
|
1795
|
+
"multicall": "0x017181efb3bDB325C17800799b33Ae80B395024c",
|
|
1796
|
+
"rpc": [],
|
|
1797
|
+
"explorer": {
|
|
1798
|
+
"url": "https://explorer-testnet.unit0.dev"
|
|
1799
|
+
},
|
|
1800
|
+
"start": 3973744,
|
|
1801
|
+
"logo": "ipfs://bafkreihbmy3rqlammea35nniemipxrwcgitzkiahs6nlrfjunnvgfnakp4",
|
|
1773
1802
|
"testnet": true
|
|
1774
1803
|
},
|
|
1775
1804
|
"314159": {
|
|
@@ -2036,4 +2065,4 @@
|
|
|
2036
2065
|
"start": 7,
|
|
2037
2066
|
"logo": "ipfs://bafkreihbjafyh7eud7r6e5743esaamifcttsvbspfwcrfoc5ykodjdi67m"
|
|
2038
2067
|
}
|
|
2039
|
-
}
|
|
2068
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { test, expect, describe } from 'vitest';
|
|
2
2
|
import starknetMessage from '../../test/fixtures/starknet/message-alias.json';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import starknetMessageBraavos from '../../test/fixtures/starknet/message-alias-braavos.json';
|
|
4
|
+
import starknetMessageArgentXGuardian from '../../test/fixtures/starknet/message-alias-argent-x-guardian.json';
|
|
5
|
+
import starknetMessageArgentXStandard from '../../test/fixtures/starknet/message-alias-argent-x-standard.json';
|
|
6
|
+
import starknetMessageArgentXMultisig from '../../test/fixtures/starknet/message-alias-argent-x-multisig.json';
|
|
5
7
|
import verify, { getHash } from './starknet';
|
|
6
8
|
import { validateAndParseAddress } from 'starknet';
|
|
7
9
|
import { clone } from '../utils';
|
|
@@ -25,10 +27,16 @@ describe('verify/starknet', () => {
|
|
|
25
27
|
|
|
26
28
|
describe('verify()', () => {
|
|
27
29
|
describe.each([
|
|
28
|
-
['2 items', starknetMessage, false],
|
|
29
|
-
['
|
|
30
|
-
['
|
|
31
|
-
|
|
30
|
+
['2 items (legacy)', starknetMessage, false],
|
|
31
|
+
['Braavos', starknetMessageBraavos, false],
|
|
32
|
+
['Argent X standard account', starknetMessageArgentXStandard],
|
|
33
|
+
[
|
|
34
|
+
'Argent X account with guardian/Argent X Mobile/Argent Web',
|
|
35
|
+
starknetMessageArgentXGuardian,
|
|
36
|
+
true
|
|
37
|
+
],
|
|
38
|
+
['Argent X multisig account', starknetMessageArgentXMultisig, true]
|
|
39
|
+
])('with a %s signature', (_, message, multisign = false) => {
|
|
32
40
|
test('should return true if the signature is valid', () => {
|
|
33
41
|
expect(
|
|
34
42
|
verify(message.address, message.sig, message.data, 'SN_MAIN')
|
|
@@ -102,10 +110,10 @@ describe('verify/starknet', () => {
|
|
|
102
110
|
).resolves.toBe(false);
|
|
103
111
|
});
|
|
104
112
|
|
|
105
|
-
test('should
|
|
113
|
+
test('should return false when the signature is not valid', () => {
|
|
106
114
|
expect(
|
|
107
115
|
verify(starknetMessage.address, ['1'], starknetMessage.data, 'SN_MAIN')
|
|
108
|
-
).
|
|
116
|
+
).resolves.toBe(false);
|
|
109
117
|
});
|
|
110
118
|
});
|
|
111
119
|
});
|
package/src/verify/starknet.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BigNumber } from '@ethersproject/bignumber';
|
|
1
|
+
import { RpcProvider, typedData, constants, TypedData } from 'starknet';
|
|
3
2
|
import networks from '../networks.json';
|
|
4
|
-
import type { SignaturePayload } from '.';
|
|
5
3
|
import type { ProviderOptions } from '../utils/provider';
|
|
4
|
+
import type { SignaturePayload } from '.';
|
|
6
5
|
|
|
7
6
|
export type NetworkType = 'SN_MAIN' | 'SN_SEPOLIA';
|
|
8
7
|
|
|
@@ -11,35 +10,6 @@ const RPC_URLS: Record<NetworkType, string> = {
|
|
|
11
10
|
SN_SEPOLIA: networks[constants.StarknetChainId.SN_SEPOLIA]?.rpc?.[0]
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
const ABI = [
|
|
15
|
-
{
|
|
16
|
-
name: 'argent::common::account::IAccount',
|
|
17
|
-
type: 'interface',
|
|
18
|
-
items: [
|
|
19
|
-
{
|
|
20
|
-
name: 'is_valid_signature',
|
|
21
|
-
type: 'function',
|
|
22
|
-
inputs: [
|
|
23
|
-
{
|
|
24
|
-
name: 'hash',
|
|
25
|
-
type: 'core::felt252'
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: 'signature',
|
|
29
|
-
type: 'core::array::Array::<core::felt252>'
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
outputs: [
|
|
33
|
-
{
|
|
34
|
-
type: 'core::felt252'
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
state_mutability: 'view'
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
];
|
|
42
|
-
|
|
43
13
|
function getProvider(network: NetworkType, options: ProviderOptions) {
|
|
44
14
|
if (!RPC_URLS[network]) throw new Error('Invalid network');
|
|
45
15
|
|
|
@@ -62,38 +32,6 @@ export function getHash(data: SignaturePayload, address: string): string {
|
|
|
62
32
|
);
|
|
63
33
|
}
|
|
64
34
|
|
|
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
|
-
|
|
97
35
|
export default async function verify(
|
|
98
36
|
address: string,
|
|
99
37
|
sig: string[],
|
|
@@ -102,18 +40,13 @@ export default async function verify(
|
|
|
102
40
|
options: ProviderOptions = {}
|
|
103
41
|
): Promise<boolean> {
|
|
104
42
|
try {
|
|
105
|
-
const
|
|
106
|
-
ABI,
|
|
107
|
-
address,
|
|
108
|
-
getProvider(network, options)
|
|
109
|
-
);
|
|
43
|
+
const provider = getProvider(network, options);
|
|
110
44
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
);
|
|
45
|
+
// Check if the contract is deployed
|
|
46
|
+
// Will throw on non-deployed contract
|
|
47
|
+
await provider.getClassAt(address);
|
|
115
48
|
|
|
116
|
-
return
|
|
49
|
+
return provider.verifyMessageInStarknet(data as TypedData, sig, address);
|
|
117
50
|
} catch (e: any) {
|
|
118
51
|
if (e.message.includes('Contract not found')) {
|
|
119
52
|
throw new Error('Contract not deployed');
|