@snapshot-labs/snapshot.js 0.14.11 → 0.14.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/dist/snapshot.cjs.js +5 -35
- package/dist/snapshot.esm.js +12 -42
- package/dist/snapshot.min.js +15 -15
- package/dist/src/verify/starknet.d.ts +1 -1
- package/package.json +1 -1
- package/src/sign/hashedTypes.json +1 -0
- package/src/verify/starknet.spec.ts +29 -11
- package/src/verify/starknet.ts +7 -46
|
@@ -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
|
@@ -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,9 @@
|
|
|
1
1
|
import { test, expect, describe } from 'vitest';
|
|
2
2
|
import starknetMessage from '../../test/fixtures/starknet/message-alias.json';
|
|
3
|
-
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';
|
|
4
7
|
import verify, { getHash } from './starknet';
|
|
5
8
|
import { validateAndParseAddress } from 'starknet';
|
|
6
9
|
import { clone } from '../utils';
|
|
@@ -24,9 +27,16 @@ describe('verify/starknet', () => {
|
|
|
24
27
|
|
|
25
28
|
describe('verify()', () => {
|
|
26
29
|
describe.each([
|
|
27
|
-
['2', starknetMessage],
|
|
28
|
-
['
|
|
29
|
-
|
|
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) => {
|
|
30
40
|
test('should return true if the signature is valid', () => {
|
|
31
41
|
expect(
|
|
32
42
|
verify(message.address, message.sig, message.data, 'SN_MAIN')
|
|
@@ -44,11 +54,19 @@ describe('verify/starknet', () => {
|
|
|
44
54
|
).resolves.toBe(true);
|
|
45
55
|
});
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
if (multisign) {
|
|
58
|
+
test('should throw an error when verifying on a different network', () => {
|
|
59
|
+
expect(
|
|
60
|
+
verify(message.address, message.sig, message.data, 'SN_SEPOLIA')
|
|
61
|
+
).rejects.toThrowError();
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
test('should return true when verifying on a different network', () => {
|
|
65
|
+
expect(
|
|
66
|
+
verify(message.address, message.sig, message.data, 'SN_SEPOLIA')
|
|
67
|
+
).resolves.toBe(true);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
52
70
|
|
|
53
71
|
test('should throw an error if the signature is invalid', () => {
|
|
54
72
|
expect(
|
|
@@ -92,10 +110,10 @@ describe('verify/starknet', () => {
|
|
|
92
110
|
).resolves.toBe(false);
|
|
93
111
|
});
|
|
94
112
|
|
|
95
|
-
test('should
|
|
113
|
+
test('should return false when the signature is not valid', () => {
|
|
96
114
|
expect(
|
|
97
115
|
verify(starknetMessage.address, ['1'], starknetMessage.data, 'SN_MAIN')
|
|
98
|
-
).
|
|
116
|
+
).resolves.toBe(false);
|
|
99
117
|
});
|
|
100
118
|
});
|
|
101
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
|
|
|
@@ -70,22 +40,13 @@ export default async function verify(
|
|
|
70
40
|
options: ProviderOptions = {}
|
|
71
41
|
): Promise<boolean> {
|
|
72
42
|
try {
|
|
73
|
-
const
|
|
74
|
-
ABI,
|
|
75
|
-
address,
|
|
76
|
-
getProvider(network, options)
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (sig.length < 2) {
|
|
80
|
-
throw new Error('Invalid signature format');
|
|
81
|
-
}
|
|
43
|
+
const provider = getProvider(network, options);
|
|
82
44
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
45
|
+
// Check if the contract is deployed
|
|
46
|
+
// Will throw on non-deployed contract
|
|
47
|
+
await provider.getClassAt(address);
|
|
87
48
|
|
|
88
|
-
return
|
|
49
|
+
return provider.verifyMessageInStarknet(data as TypedData, sig, address);
|
|
89
50
|
} catch (e: any) {
|
|
90
51
|
if (e.message.includes('Contract not found')) {
|
|
91
52
|
throw new Error('Contract not deployed');
|