@snapshot-labs/snapshot.js 0.14.16 → 0.14.18
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 +7 -59
- package/dist/snapshot.esm.js +8 -60
- package/dist/snapshot.min.js +1 -1
- package/dist/src/sign/types.d.ts +0 -18
- package/dist/src/verify/starknet.d.ts +1 -2
- package/package.json +1 -1
- package/src/networks.json +2 -6
- package/src/sign/index.ts +4 -8
- package/src/sign/types.ts +1 -40
- package/src/verify/starknet.spec.ts +28 -8
- package/src/verify/starknet.ts +3 -18
package/dist/src/sign/types.d.ts
CHANGED
|
@@ -163,24 +163,6 @@ export declare const voteStringTypes: {
|
|
|
163
163
|
type: string;
|
|
164
164
|
}[];
|
|
165
165
|
};
|
|
166
|
-
export declare const vote2Types: {
|
|
167
|
-
Vote: {
|
|
168
|
-
name: string;
|
|
169
|
-
type: string;
|
|
170
|
-
}[];
|
|
171
|
-
};
|
|
172
|
-
export declare const voteArray2Types: {
|
|
173
|
-
Vote: {
|
|
174
|
-
name: string;
|
|
175
|
-
type: string;
|
|
176
|
-
}[];
|
|
177
|
-
};
|
|
178
|
-
export declare const voteString2Types: {
|
|
179
|
-
Vote: {
|
|
180
|
-
name: string;
|
|
181
|
-
type: string;
|
|
182
|
-
}[];
|
|
183
|
-
};
|
|
184
166
|
export declare const followTypes: {
|
|
185
167
|
Follow: {
|
|
186
168
|
name: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ProviderOptions } from '../utils/provider';
|
|
2
2
|
import type { SignaturePayload } from '.';
|
|
3
|
-
export type NetworkType = 'SN_MAIN' | 'SN_SEPOLIA';
|
|
4
3
|
export declare function isStarknetMessage(data: SignaturePayload): boolean;
|
|
5
4
|
export declare function getHash(data: SignaturePayload, address: string): string;
|
|
6
|
-
export default function verify(address: string, sig: string[], data: SignaturePayload, network?:
|
|
5
|
+
export default function verify(address: string, sig: string[], data: SignaturePayload, network?: string, options?: ProviderOptions): Promise<boolean>;
|
package/package.json
CHANGED
package/src/networks.json
CHANGED
|
@@ -2026,9 +2026,7 @@
|
|
|
2026
2026
|
"explorer": {
|
|
2027
2027
|
"url": "https://starkscan.co"
|
|
2028
2028
|
},
|
|
2029
|
-
"rpc": [
|
|
2030
|
-
"https://starknet-mainnet.public.blastapi.io"
|
|
2031
|
-
],
|
|
2029
|
+
"rpc": [],
|
|
2032
2030
|
"start": 8446,
|
|
2033
2031
|
"logo": "ipfs://bafkreihbjafyh7eud7r6e5743esaamifcttsvbspfwcrfoc5ykodjdi67m"
|
|
2034
2032
|
},
|
|
@@ -2045,9 +2043,7 @@
|
|
|
2045
2043
|
"explorer": {
|
|
2046
2044
|
"url": "https://sepolia.starkscan.co"
|
|
2047
2045
|
},
|
|
2048
|
-
"rpc": [
|
|
2049
|
-
"https://starknet-sepolia.public.blastapi.io"
|
|
2050
|
-
],
|
|
2046
|
+
"rpc": [],
|
|
2051
2047
|
"start": 7,
|
|
2052
2048
|
"logo": "ipfs://bafkreihbjafyh7eud7r6e5743esaamifcttsvbspfwcrfoc5ykodjdi67m"
|
|
2053
2049
|
}
|
package/src/sign/index.ts
CHANGED
|
@@ -25,9 +25,6 @@ import {
|
|
|
25
25
|
voteTypes,
|
|
26
26
|
voteArrayTypes,
|
|
27
27
|
voteStringTypes,
|
|
28
|
-
vote2Types,
|
|
29
|
-
voteArray2Types,
|
|
30
|
-
voteString2Types,
|
|
31
28
|
followTypes,
|
|
32
29
|
subscribeTypes,
|
|
33
30
|
unfollowTypes,
|
|
@@ -169,15 +166,14 @@ export default class Client {
|
|
|
169
166
|
if (!message.reason) message.reason = '';
|
|
170
167
|
if (!message.app) message.app = '';
|
|
171
168
|
if (!message.metadata) message.metadata = '{}';
|
|
172
|
-
|
|
173
|
-
let type = type2 ? vote2Types : voteTypes;
|
|
169
|
+
let type = voteTypes;
|
|
174
170
|
if (['approval', 'ranked-choice'].includes(message.type))
|
|
175
|
-
type =
|
|
171
|
+
type = voteArrayTypes;
|
|
176
172
|
if (!isShutter && ['quadratic', 'weighted'].includes(message.type)) {
|
|
177
|
-
type =
|
|
173
|
+
type = voteStringTypes;
|
|
178
174
|
message.choice = JSON.stringify(message.choice);
|
|
179
175
|
}
|
|
180
|
-
if (isShutter) type =
|
|
176
|
+
if (isShutter) type = voteStringTypes;
|
|
181
177
|
delete message.privacy;
|
|
182
178
|
// @ts-ignore
|
|
183
179
|
delete message.type;
|
package/src/sign/types.ts
CHANGED
|
@@ -197,7 +197,7 @@ export const cancelProposal2Types = {
|
|
|
197
197
|
{ name: 'from', type: 'string' },
|
|
198
198
|
{ name: 'space', type: 'string' },
|
|
199
199
|
{ name: 'timestamp', type: 'uint64' },
|
|
200
|
-
{ name: 'proposal', type: '
|
|
200
|
+
{ name: 'proposal', type: 'string' }
|
|
201
201
|
]
|
|
202
202
|
};
|
|
203
203
|
|
|
@@ -240,45 +240,6 @@ export const voteStringTypes = {
|
|
|
240
240
|
]
|
|
241
241
|
};
|
|
242
242
|
|
|
243
|
-
export const vote2Types = {
|
|
244
|
-
Vote: [
|
|
245
|
-
{ name: 'from', type: 'string' },
|
|
246
|
-
{ name: 'space', type: 'string' },
|
|
247
|
-
{ name: 'timestamp', type: 'uint64' },
|
|
248
|
-
{ name: 'proposal', type: 'bytes32' },
|
|
249
|
-
{ name: 'choice', type: 'uint32' },
|
|
250
|
-
{ name: 'reason', type: 'string' },
|
|
251
|
-
{ name: 'app', type: 'string' },
|
|
252
|
-
{ name: 'metadata', type: 'string' }
|
|
253
|
-
]
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
export const voteArray2Types = {
|
|
257
|
-
Vote: [
|
|
258
|
-
{ name: 'from', type: 'string' },
|
|
259
|
-
{ name: 'space', type: 'string' },
|
|
260
|
-
{ name: 'timestamp', type: 'uint64' },
|
|
261
|
-
{ name: 'proposal', type: 'bytes32' },
|
|
262
|
-
{ name: 'choice', type: 'uint32[]' },
|
|
263
|
-
{ name: 'reason', type: 'string' },
|
|
264
|
-
{ name: 'app', type: 'string' },
|
|
265
|
-
{ name: 'metadata', type: 'string' }
|
|
266
|
-
]
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
export const voteString2Types = {
|
|
270
|
-
Vote: [
|
|
271
|
-
{ name: 'from', type: 'string' },
|
|
272
|
-
{ name: 'space', type: 'string' },
|
|
273
|
-
{ name: 'timestamp', type: 'uint64' },
|
|
274
|
-
{ name: 'proposal', type: 'bytes32' },
|
|
275
|
-
{ name: 'choice', type: 'string' },
|
|
276
|
-
{ name: 'reason', type: 'string' },
|
|
277
|
-
{ name: 'app', type: 'string' },
|
|
278
|
-
{ name: 'metadata', type: 'string' }
|
|
279
|
-
]
|
|
280
|
-
};
|
|
281
|
-
|
|
282
243
|
export const followTypes = {
|
|
283
244
|
Follow: [
|
|
284
245
|
{ name: 'from', type: 'address' },
|
|
@@ -39,7 +39,7 @@ describe('verify/starknet', () => {
|
|
|
39
39
|
])('with a %s signature', (_, message, multisign = false) => {
|
|
40
40
|
test('should return true if the signature is valid', () => {
|
|
41
41
|
expect(
|
|
42
|
-
verify(message.address, message.sig, message.data, '
|
|
42
|
+
verify(message.address, message.sig, message.data, '0x534e5f4d41494e')
|
|
43
43
|
).resolves.toBe(true);
|
|
44
44
|
});
|
|
45
45
|
|
|
@@ -49,7 +49,7 @@ describe('verify/starknet', () => {
|
|
|
49
49
|
validateAndParseAddress(message.address),
|
|
50
50
|
message.sig,
|
|
51
51
|
message.data,
|
|
52
|
-
'
|
|
52
|
+
'0x534e5f4d41494e'
|
|
53
53
|
)
|
|
54
54
|
).resolves.toBe(true);
|
|
55
55
|
});
|
|
@@ -57,13 +57,23 @@ describe('verify/starknet', () => {
|
|
|
57
57
|
if (multisign) {
|
|
58
58
|
test('should throw an error when verifying on a different network', () => {
|
|
59
59
|
expect(
|
|
60
|
-
verify(
|
|
60
|
+
verify(
|
|
61
|
+
message.address,
|
|
62
|
+
message.sig,
|
|
63
|
+
message.data,
|
|
64
|
+
'0x534e5f5345504f4c4941'
|
|
65
|
+
)
|
|
61
66
|
).rejects.toThrowError();
|
|
62
67
|
});
|
|
63
68
|
} else {
|
|
64
69
|
test('should return true when verifying on a different network', () => {
|
|
65
70
|
expect(
|
|
66
|
-
verify(
|
|
71
|
+
verify(
|
|
72
|
+
message.address,
|
|
73
|
+
message.sig,
|
|
74
|
+
message.data,
|
|
75
|
+
'0x534e5f5345504f4c4941'
|
|
76
|
+
)
|
|
67
77
|
).resolves.toBe(true);
|
|
68
78
|
});
|
|
69
79
|
}
|
|
@@ -85,7 +95,7 @@ describe('verify/starknet', () => {
|
|
|
85
95
|
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A',
|
|
86
96
|
starknetMessage.sig,
|
|
87
97
|
starknetMessage.data,
|
|
88
|
-
'
|
|
98
|
+
'0x534e5f4d41494e'
|
|
89
99
|
)
|
|
90
100
|
).rejects.toThrowError('Contract not deployed');
|
|
91
101
|
});
|
|
@@ -96,7 +106,7 @@ describe('verify/starknet', () => {
|
|
|
96
106
|
starknetMessage.address,
|
|
97
107
|
['1', '2'],
|
|
98
108
|
starknetMessage.data,
|
|
99
|
-
'
|
|
109
|
+
'0x534e5f4d41494e'
|
|
100
110
|
)
|
|
101
111
|
).resolves.toBe(false);
|
|
102
112
|
});
|
|
@@ -106,13 +116,23 @@ describe('verify/starknet', () => {
|
|
|
106
116
|
data.message.timestamp = 1234;
|
|
107
117
|
|
|
108
118
|
expect(
|
|
109
|
-
verify(
|
|
119
|
+
verify(
|
|
120
|
+
starknetMessage.address,
|
|
121
|
+
starknetMessage.sig,
|
|
122
|
+
data,
|
|
123
|
+
'0x534e5f4d41494e'
|
|
124
|
+
)
|
|
110
125
|
).resolves.toBe(false);
|
|
111
126
|
});
|
|
112
127
|
|
|
113
128
|
test('should return false when the signature is not valid', () => {
|
|
114
129
|
expect(
|
|
115
|
-
verify(
|
|
130
|
+
verify(
|
|
131
|
+
starknetMessage.address,
|
|
132
|
+
['1'],
|
|
133
|
+
starknetMessage.data,
|
|
134
|
+
'0x534e5f4d41494e'
|
|
135
|
+
)
|
|
116
136
|
).resolves.toBe(false);
|
|
117
137
|
});
|
|
118
138
|
});
|
package/src/verify/starknet.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import networks from '../networks.json';
|
|
1
|
+
import { typedData, TypedData } from 'starknet';
|
|
3
2
|
import type { ProviderOptions } from '../utils/provider';
|
|
4
3
|
import type { SignaturePayload } from '.';
|
|
5
|
-
|
|
6
|
-
export type NetworkType = 'SN_MAIN' | 'SN_SEPOLIA';
|
|
7
|
-
|
|
8
|
-
const RPC_URLS: Record<NetworkType, string> = {
|
|
9
|
-
SN_MAIN: networks[constants.StarknetChainId.SN_MAIN]?.rpc?.[0],
|
|
10
|
-
SN_SEPOLIA: networks[constants.StarknetChainId.SN_SEPOLIA]?.rpc?.[0]
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function getProvider(network: NetworkType, options: ProviderOptions) {
|
|
14
|
-
if (!RPC_URLS[network]) throw new Error('Invalid network');
|
|
15
|
-
|
|
16
|
-
return new RpcProvider({
|
|
17
|
-
nodeUrl: options?.broviderUrl ?? RPC_URLS[network]
|
|
18
|
-
});
|
|
19
|
-
}
|
|
4
|
+
import getProvider from '../utils/provider';
|
|
20
5
|
|
|
21
6
|
export function isStarknetMessage(data: SignaturePayload): boolean {
|
|
22
7
|
return !!data.primaryType && !!data.types.StarkNetDomain;
|
|
@@ -36,7 +21,7 @@ export default async function verify(
|
|
|
36
21
|
address: string,
|
|
37
22
|
sig: string[],
|
|
38
23
|
data: SignaturePayload,
|
|
39
|
-
network
|
|
24
|
+
network = '0x534e5f4d41494e',
|
|
40
25
|
options: ProviderOptions = {}
|
|
41
26
|
): Promise<boolean> {
|
|
42
27
|
try {
|