@obolnetwork/obol-sdk 1.0.16 → 2.0.0
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/README.md +6 -3
- package/dist/cjs/package.json +11 -6
- package/dist/cjs/src/ajv.js +27 -0
- package/dist/cjs/src/constants.js +8 -4
- package/dist/cjs/src/index.js +10 -9
- package/dist/cjs/src/schema.js +8 -0
- package/dist/cjs/src/utils.js +3 -3
- package/dist/cjs/src/verification/common.js +19 -7
- package/dist/cjs/src/verification/termsAndConditions.js +1 -1
- package/dist/cjs/src/verification/v1.6.0.js +1 -1
- package/dist/cjs/src/verification/v1.7.0.js +3 -3
- package/dist/cjs/src/verification/v1.8.0.js +3 -3
- package/dist/cjs/test/fixtures.js +27 -33
- package/dist/cjs/test/methods.test.js +54 -27
- package/dist/esm/package.json +11 -6
- package/dist/esm/src/ajv.js +27 -0
- package/dist/esm/src/base.js +1 -1
- package/dist/esm/src/constants.js +7 -3
- package/dist/esm/src/index.js +11 -10
- package/dist/esm/src/schema.js +8 -0
- package/dist/esm/src/utils.js +3 -3
- package/dist/esm/src/verification/common.js +27 -15
- package/dist/esm/src/verification/sszTypes.js +1 -1
- package/dist/esm/src/verification/termsAndConditions.js +1 -1
- package/dist/esm/src/verification/v1.6.0.js +5 -5
- package/dist/esm/src/verification/v1.7.0.js +8 -8
- package/dist/esm/src/verification/v1.8.0.js +8 -8
- package/dist/esm/test/fixtures.js +27 -33
- package/dist/esm/test/methods.test.js +55 -28
- package/dist/types/src/constants.d.ts +3 -1
- package/dist/types/src/schema.d.ts +8 -0
- package/dist/types/src/types.d.ts +18 -18
- package/package.json +11 -6
- package/src/ajv.ts +38 -7
- package/src/base.ts +22 -18
- package/src/constants.ts +42 -36
- package/src/errors.ts +4 -4
- package/src/index.ts +85 -75
- package/src/schema.ts +10 -2
- package/src/services.ts +6 -6
- package/src/types.ts +65 -65
- package/src/utils.ts +17 -17
- package/src/verification/common.ts +374 -333
- package/src/verification/sszTypes.ts +60 -51
- package/src/verification/termsAndConditions.ts +16 -14
- package/src/verification/v1.6.0.ts +214 -184
- package/src/verification/v1.7.0.ts +268 -233
- package/src/verification/v1.8.0.ts +266 -225
|
@@ -1,79 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ByteListType,
|
|
3
|
+
ByteVectorType,
|
|
4
|
+
ContainerType,
|
|
5
|
+
UintNumberType,
|
|
6
|
+
} from '@chainsafe/ssz';
|
|
7
|
+
import { type UintNumberByteLen } from '@chainsafe/ssz/lib/type/uint';
|
|
3
8
|
|
|
4
9
|
export const operatorAddressWrapperType = new ContainerType({
|
|
5
|
-
|
|
6
|
-
})
|
|
10
|
+
address: new ByteVectorType(20),
|
|
11
|
+
});
|
|
7
12
|
|
|
8
13
|
export const creatorAddressWrapperType = new ContainerType({
|
|
9
|
-
|
|
10
|
-
})
|
|
14
|
+
address: new ByteVectorType(20),
|
|
15
|
+
});
|
|
11
16
|
|
|
12
17
|
export const operatorContainerType = new ContainerType({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
+
address: new ByteVectorType(20),
|
|
19
|
+
enr: new ByteListType(1024), // This needs to be dynamic, since ENRs do not have a fixed length.
|
|
20
|
+
config_signature: new ByteVectorType(65),
|
|
21
|
+
enr_signature: new ByteVectorType(65),
|
|
22
|
+
});
|
|
18
23
|
|
|
19
24
|
export const creatorContainerType = new ContainerType({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
25
|
+
address: new ByteVectorType(20),
|
|
26
|
+
config_signature: new ByteVectorType(65),
|
|
27
|
+
});
|
|
23
28
|
|
|
24
29
|
export const validatorsContainerType = new ContainerType({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
30
|
+
fee_recipient_address: new ByteVectorType(20),
|
|
31
|
+
withdrawal_address: new ByteVectorType(20),
|
|
32
|
+
});
|
|
28
33
|
|
|
29
|
-
export const newCreatorContainerType = (
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
export const newCreatorContainerType = (
|
|
35
|
+
configOnly: boolean,
|
|
36
|
+
): ContainerType<any> => {
|
|
37
|
+
return configOnly ? creatorAddressWrapperType : creatorContainerType;
|
|
38
|
+
};
|
|
32
39
|
|
|
33
|
-
export const newOperatorContainerType = (
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
export const newOperatorContainerType = (
|
|
41
|
+
configOnly: boolean,
|
|
42
|
+
): ContainerType<any> => {
|
|
43
|
+
return configOnly ? operatorAddressWrapperType : operatorContainerType;
|
|
44
|
+
};
|
|
36
45
|
|
|
37
46
|
// Lock
|
|
38
47
|
export const depositDataContainer = new ContainerType({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
48
|
+
pubkey: new ByteVectorType(48),
|
|
49
|
+
withdrawal_credentials: new ByteVectorType(32),
|
|
50
|
+
amount: new UintNumberType(8 as UintNumberByteLen),
|
|
51
|
+
signature: new ByteVectorType(96),
|
|
52
|
+
});
|
|
44
53
|
|
|
45
54
|
export const builderRegistrationMessageContainer = new ContainerType({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
55
|
+
fee_recipient: new ByteVectorType(20),
|
|
56
|
+
gas_limit: new UintNumberType(8 as UintNumberByteLen),
|
|
57
|
+
timestamp: new UintNumberType(8 as UintNumberByteLen),
|
|
58
|
+
pubkey: new ByteVectorType(48),
|
|
59
|
+
});
|
|
51
60
|
|
|
52
61
|
export const builderRegistrationContainer = new ContainerType({
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
62
|
+
message: builderRegistrationMessageContainer,
|
|
63
|
+
signature: new ByteVectorType(96),
|
|
64
|
+
});
|
|
56
65
|
|
|
57
66
|
export const builderRegistrationMessageType = new ContainerType({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
67
|
+
fee_recipient: new ByteVectorType(20),
|
|
68
|
+
gas_limit: new UintNumberType(8 as UintNumberByteLen),
|
|
69
|
+
timestamp: new UintNumberType(8 as UintNumberByteLen),
|
|
70
|
+
pubkey: new ByteVectorType(48),
|
|
71
|
+
});
|
|
63
72
|
|
|
64
73
|
// For domain computation that is used in deposit data and builder registration verification for dv
|
|
65
74
|
export const forkDataType = new ContainerType({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
75
|
+
currentVersion: new ByteVectorType(4),
|
|
76
|
+
genesisValidatorsRoot: new ByteVectorType(32),
|
|
77
|
+
});
|
|
69
78
|
|
|
70
79
|
export const depositMessageType = new ContainerType({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
})
|
|
80
|
+
pubkey: new ByteVectorType(48),
|
|
81
|
+
withdrawal_credentials: new ByteVectorType(32),
|
|
82
|
+
amount: new UintNumberType(8),
|
|
83
|
+
});
|
|
75
84
|
|
|
76
85
|
export const signingRootType = new ContainerType({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
86
|
+
objectRoot: new ByteVectorType(32),
|
|
87
|
+
domain: new ByteVectorType(32),
|
|
88
|
+
});
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import pdf from 'pdf-parse'
|
|
2
|
-
import { ByteListType, ContainerType } from '@chainsafe/ssz'
|
|
3
|
-
import { TERMS_AND_CONDITIONS_URL } from '../constants'
|
|
4
|
-
import { strToUint8Array } from '../utils'
|
|
1
|
+
import pdf from 'pdf-parse';
|
|
2
|
+
import { ByteListType, ContainerType } from '@chainsafe/ssz';
|
|
3
|
+
import { TERMS_AND_CONDITIONS_URL } from '../constants';
|
|
4
|
+
import { strToUint8Array } from '../utils';
|
|
5
5
|
|
|
6
6
|
export const hashTermsAndConditions = async (): Promise<string | null> => {
|
|
7
7
|
try {
|
|
8
8
|
// read the pdf
|
|
9
|
-
const response = await fetch(TERMS_AND_CONDITIONS_URL)
|
|
10
|
-
const pdfBuffarrayBuffer = await response.arrayBuffer()
|
|
11
|
-
const pdfBuffer = Buffer.from(pdfBuffarrayBuffer)
|
|
12
|
-
const data = await pdf(pdfBuffer)
|
|
9
|
+
const response = await fetch(TERMS_AND_CONDITIONS_URL);
|
|
10
|
+
const pdfBuffarrayBuffer = await response.arrayBuffer();
|
|
11
|
+
const pdfBuffer = Buffer.from(pdfBuffarrayBuffer);
|
|
12
|
+
const data = await pdf(pdfBuffer);
|
|
13
13
|
|
|
14
14
|
// ssz hash
|
|
15
15
|
const termsType = new ContainerType({
|
|
16
16
|
terms_and_conditions_hash: new ByteListType(Number.MAX_SAFE_INTEGER),
|
|
17
|
-
})
|
|
17
|
+
});
|
|
18
18
|
|
|
19
|
-
const termsHasVal = termsType.defaultValue()
|
|
19
|
+
const termsHasVal = termsType.defaultValue();
|
|
20
20
|
|
|
21
|
-
termsHasVal.terms_and_conditions_hash = strToUint8Array(
|
|
21
|
+
termsHasVal.terms_and_conditions_hash = strToUint8Array(
|
|
22
|
+
data?.text.replace(/[^a-zA-Z0-9]/g, ''),
|
|
23
|
+
);
|
|
22
24
|
|
|
23
25
|
return (
|
|
24
26
|
'0x' +
|
|
25
27
|
Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex')
|
|
26
|
-
)
|
|
28
|
+
);
|
|
27
29
|
} catch (err) {
|
|
28
|
-
return null
|
|
30
|
+
return null;
|
|
29
31
|
}
|
|
30
|
-
}
|
|
32
|
+
};
|
|
@@ -1,32 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
type UintNumberByteLen,
|
|
3
|
+
UintNumberType,
|
|
4
|
+
} from '@chainsafe/ssz/lib/type/uint';
|
|
5
|
+
import { strToUint8Array } from '../utils';
|
|
6
|
+
import {
|
|
7
|
+
type creatorAddressWrapperType,
|
|
8
|
+
type creatorContainerType,
|
|
9
|
+
newCreatorContainerType,
|
|
10
|
+
newOperatorContainerType,
|
|
11
|
+
type operatorAddressWrapperType,
|
|
12
|
+
type operatorContainerType,
|
|
13
|
+
validatorsContainerType,
|
|
14
|
+
} from './sszTypes';
|
|
15
|
+
import {
|
|
16
|
+
ByteListType,
|
|
17
|
+
ByteVectorType,
|
|
18
|
+
ContainerType,
|
|
19
|
+
ListCompositeType,
|
|
20
|
+
fromHexString,
|
|
21
|
+
} from '@chainsafe/ssz';
|
|
22
|
+
import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
|
|
23
|
+
import {
|
|
24
|
+
type ClusterDefinition,
|
|
25
|
+
type ClusterLock,
|
|
26
|
+
type DepositData,
|
|
27
|
+
} from '../types';
|
|
28
|
+
import { verifyDepositData } from './common';
|
|
29
|
+
import {
|
|
30
|
+
aggregateSignatures,
|
|
31
|
+
verifyAggregate,
|
|
32
|
+
verifyMultiple,
|
|
33
|
+
} from '@chainsafe/bls';
|
|
34
|
+
|
|
35
|
+
// cluster definition
|
|
11
36
|
type DefinitionFieldsV1X6 = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type DefinitionContainerTypeV1X6 =
|
|
29
|
-
ContainerType<DefinitionFieldsV1X6>
|
|
37
|
+
uuid: ByteListType;
|
|
38
|
+
name: ByteListType;
|
|
39
|
+
version: ByteListType;
|
|
40
|
+
timestamp: ByteListType;
|
|
41
|
+
num_validators: UintNumberType;
|
|
42
|
+
threshold: UintNumberType;
|
|
43
|
+
dkg_algorithm: ByteListType;
|
|
44
|
+
fork_version: ByteVectorType;
|
|
45
|
+
operators: ListCompositeType<
|
|
46
|
+
typeof operatorContainerType | typeof operatorAddressWrapperType
|
|
47
|
+
>;
|
|
48
|
+
creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
|
|
49
|
+
validators: ListCompositeType<typeof validatorsContainerType>;
|
|
50
|
+
config_hash?: ByteVectorType;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type DefinitionContainerTypeV1X6 = ContainerType<DefinitionFieldsV1X6>;
|
|
30
54
|
|
|
31
55
|
/**
|
|
32
56
|
* Returns the containerized cluster definition
|
|
@@ -34,193 +58,199 @@ type DefinitionContainerTypeV1X6 =
|
|
|
34
58
|
* @returns SSZ Containerized type of cluster input
|
|
35
59
|
*/
|
|
36
60
|
export const clusterDefinitionContainerTypeV1X6 = (
|
|
37
|
-
|
|
61
|
+
configOnly: boolean,
|
|
38
62
|
): DefinitionContainerTypeV1X6 => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
let returnedContainerType: any = {
|
|
64
|
+
uuid: new ByteListType(64),
|
|
65
|
+
name: new ByteListType(256),
|
|
66
|
+
version: new ByteListType(16),
|
|
67
|
+
timestamp: new ByteListType(32),
|
|
68
|
+
num_validators: new UintNumberType(8 as UintNumberByteLen),
|
|
69
|
+
threshold: new UintNumberType(8 as UintNumberByteLen),
|
|
70
|
+
dkg_algorithm: new ByteListType(32),
|
|
71
|
+
fork_version: new ByteVectorType(4),
|
|
72
|
+
operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
|
|
73
|
+
creator: newCreatorContainerType(configOnly),
|
|
74
|
+
validators: new ListCompositeType(validatorsContainerType, 65536),
|
|
75
|
+
};
|
|
52
76
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
if (!configOnly) {
|
|
78
|
+
returnedContainerType = {
|
|
79
|
+
...returnedContainerType,
|
|
80
|
+
config_hash: new ByteVectorType(32),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
59
83
|
|
|
60
|
-
|
|
61
|
-
}
|
|
84
|
+
return new ContainerType(returnedContainerType);
|
|
85
|
+
};
|
|
62
86
|
|
|
63
87
|
export const hashClusterDefinitionV1X6 = (
|
|
64
|
-
|
|
65
|
-
|
|
88
|
+
cluster: ClusterDefinition,
|
|
89
|
+
configOnly: boolean,
|
|
66
90
|
): ValueOfFields<DefinitionFieldsV1X6> => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
91
|
+
const definitionType = clusterDefinitionContainerTypeV1X6(configOnly);
|
|
92
|
+
|
|
93
|
+
const val = definitionType.defaultValue();
|
|
94
|
+
|
|
95
|
+
// order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
|
|
96
|
+
val.uuid = strToUint8Array(cluster.uuid);
|
|
97
|
+
val.name = strToUint8Array(cluster.name);
|
|
98
|
+
val.version = strToUint8Array(cluster.version);
|
|
99
|
+
val.timestamp = strToUint8Array(cluster.timestamp);
|
|
100
|
+
val.num_validators = cluster.num_validators;
|
|
101
|
+
val.threshold = cluster.threshold;
|
|
102
|
+
val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
|
|
103
|
+
val.fork_version = fromHexString(cluster.fork_version);
|
|
104
|
+
val.operators = cluster.operators.map(operator => {
|
|
105
|
+
return configOnly
|
|
106
|
+
? { address: fromHexString(operator.address) }
|
|
107
|
+
: {
|
|
108
|
+
address: fromHexString(operator.address),
|
|
109
|
+
enr: strToUint8Array(operator.enr as string),
|
|
110
|
+
config_signature: fromHexString(operator.config_signature as string),
|
|
111
|
+
enr_signature: fromHexString(operator.enr_signature as string),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
val.creator = configOnly
|
|
115
|
+
? { address: fromHexString(cluster.creator.address) }
|
|
116
|
+
: {
|
|
117
|
+
address: fromHexString(cluster.creator.address),
|
|
118
|
+
config_signature: fromHexString(
|
|
119
|
+
cluster.creator.config_signature as string,
|
|
120
|
+
),
|
|
121
|
+
};
|
|
122
|
+
val.validators = cluster.validators.map(validator => {
|
|
123
|
+
return {
|
|
124
|
+
fee_recipient_address: fromHexString(validator.fee_recipient_address),
|
|
125
|
+
withdrawal_address: fromHexString(validator.withdrawal_address),
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (!configOnly) {
|
|
130
|
+
val.config_hash = fromHexString(cluster.config_hash);
|
|
131
|
+
}
|
|
132
|
+
return val;
|
|
133
|
+
};
|
|
108
134
|
|
|
109
135
|
// cluster lock
|
|
110
136
|
|
|
111
137
|
const dvContainerTypeV1X6 = new ContainerType({
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
})
|
|
138
|
+
distributed_public_key: new ByteVectorType(48),
|
|
139
|
+
public_shares: new ListCompositeType(new ByteVectorType(48), 256),
|
|
140
|
+
pubkey: new ByteVectorType(48),
|
|
141
|
+
withdrawal_credentials: new ByteVectorType(32),
|
|
142
|
+
amount: new UintNumberType(8 as UintNumberByteLen),
|
|
143
|
+
signature: new ByteVectorType(96),
|
|
144
|
+
});
|
|
119
145
|
|
|
120
146
|
type LockContainerTypeV1X6 = ContainerType<{
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
147
|
+
cluster_definition: DefinitionContainerTypeV1X6;
|
|
148
|
+
distributed_validators: ListCompositeType<typeof dvContainerTypeV1X6>;
|
|
149
|
+
}>;
|
|
124
150
|
|
|
125
151
|
/**
|
|
126
152
|
* @returns SSZ Containerized type of cluster lock
|
|
127
153
|
*/
|
|
128
154
|
const clusterLockContainerTypeV1X6 = (): LockContainerTypeV1X6 => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
155
|
+
return new ContainerType({
|
|
156
|
+
cluster_definition: clusterDefinitionContainerTypeV1X6(false),
|
|
157
|
+
distributed_validators: new ListCompositeType(dvContainerTypeV1X6, 65536),
|
|
158
|
+
});
|
|
159
|
+
};
|
|
134
160
|
|
|
135
161
|
/**
|
|
136
162
|
* @param cluster The published cluster lock
|
|
137
163
|
* @returns The lock hash in of the corresponding cluster
|
|
138
164
|
*/
|
|
139
165
|
export const hashClusterLockV1X6 = (cluster: ClusterLock): string => {
|
|
140
|
-
|
|
166
|
+
const lockType = clusterLockContainerTypeV1X6();
|
|
141
167
|
|
|
142
|
-
|
|
168
|
+
const val = lockType.defaultValue();
|
|
143
169
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
170
|
+
// Check if we can replace with definition_hash
|
|
171
|
+
val.cluster_definition = hashClusterDefinitionV1X6(
|
|
172
|
+
cluster.cluster_definition,
|
|
173
|
+
false,
|
|
174
|
+
);
|
|
175
|
+
val.distributed_validators = cluster.distributed_validators.map(
|
|
176
|
+
dValidator => {
|
|
177
|
+
return {
|
|
178
|
+
distributed_public_key: fromHexString(
|
|
179
|
+
dValidator.distributed_public_key,
|
|
180
|
+
),
|
|
181
|
+
public_shares: dValidator.public_shares.map(publicShare =>
|
|
182
|
+
fromHexString(publicShare),
|
|
183
|
+
),
|
|
184
|
+
pubkey: fromHexString(dValidator.deposit_data?.pubkey as string),
|
|
185
|
+
withdrawal_credentials: fromHexString(
|
|
186
|
+
dValidator.deposit_data?.withdrawal_credentials as string,
|
|
187
|
+
),
|
|
188
|
+
amount: parseInt(dValidator.deposit_data?.amount as string),
|
|
189
|
+
signature: fromHexString(dValidator.deposit_data?.signature as string),
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
|
|
195
|
+
};
|
|
166
196
|
|
|
167
197
|
// DV verification
|
|
168
198
|
export const verifyDVV1X6 = (clusterLock: ClusterLock): boolean => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
for (let i = 0; i < validators.length; i++) {
|
|
176
|
-
const validator = validators[i]
|
|
177
|
-
const validatorPublicShares = validator.public_shares
|
|
178
|
-
const distributedPublicKey = validator.distributed_public_key
|
|
179
|
-
|
|
180
|
-
// Needed in signature_aggregate verification
|
|
181
|
-
for (const element of validatorPublicShares) {
|
|
182
|
-
pubShares.push(fromHexString(element))
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const { isValidDepositData, depositDataMsg } = verifyDepositData(
|
|
186
|
-
distributedPublicKey,
|
|
187
|
-
validator.deposit_data as Partial<DepositData>,
|
|
188
|
-
clusterLock.cluster_definition.validators[i].withdrawal_address,
|
|
189
|
-
clusterLock.cluster_definition.fork_version
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
if (
|
|
193
|
-
!isValidDepositData
|
|
194
|
-
) {
|
|
195
|
-
return false
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
pubKeys.push(fromHexString(validator.distributed_public_key))
|
|
199
|
-
builderRegistrationAndDepositDataMessages.push(depositDataMsg)
|
|
200
|
-
blsSignatures.push(fromHexString(validator.deposit_data?.signature as string))
|
|
201
|
-
}
|
|
199
|
+
const validators = clusterLock.distributed_validators;
|
|
200
|
+
const pubShares = [];
|
|
201
|
+
const pubKeys = [];
|
|
202
|
+
const builderRegistrationAndDepositDataMessages = [];
|
|
203
|
+
const blsSignatures = [];
|
|
202
204
|
|
|
203
|
-
|
|
205
|
+
for (let i = 0; i < validators.length; i++) {
|
|
206
|
+
const validator = validators[i];
|
|
207
|
+
const validatorPublicShares = validator.public_shares;
|
|
208
|
+
const distributedPublicKey = validator.distributed_public_key;
|
|
204
209
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
builderRegistrationAndDepositDataMessages,
|
|
209
|
-
aggregateBLSSignature,
|
|
210
|
-
)
|
|
211
|
-
) {
|
|
212
|
-
return false
|
|
210
|
+
// Needed in signature_aggregate verification
|
|
211
|
+
for (const element of validatorPublicShares) {
|
|
212
|
+
pubShares.push(fromHexString(element));
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
215
|
+
const { isValidDepositData, depositDataMsg } = verifyDepositData(
|
|
216
|
+
distributedPublicKey,
|
|
217
|
+
validator.deposit_data as Partial<DepositData>,
|
|
218
|
+
clusterLock.cluster_definition.validators[i].withdrawal_address,
|
|
219
|
+
clusterLock.cluster_definition.fork_version,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
if (!isValidDepositData) {
|
|
223
|
+
return false;
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
pubKeys.push(fromHexString(validator.distributed_public_key));
|
|
227
|
+
builderRegistrationAndDepositDataMessages.push(depositDataMsg);
|
|
228
|
+
blsSignatures.push(
|
|
229
|
+
fromHexString(validator.deposit_data?.signature as string),
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const aggregateBLSSignature = aggregateSignatures(blsSignatures);
|
|
234
|
+
|
|
235
|
+
if (
|
|
236
|
+
!verifyMultiple(
|
|
237
|
+
pubKeys,
|
|
238
|
+
builderRegistrationAndDepositDataMessages,
|
|
239
|
+
aggregateBLSSignature,
|
|
240
|
+
)
|
|
241
|
+
) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (
|
|
246
|
+
!verifyAggregate(
|
|
247
|
+
pubShares,
|
|
248
|
+
fromHexString(clusterLock.lock_hash),
|
|
249
|
+
fromHexString(clusterLock.signature_aggregate),
|
|
250
|
+
)
|
|
251
|
+
) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return true;
|
|
256
|
+
};
|