@obolnetwork/obol-sdk 2.11.4 → 2.11.5-rc.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/dist/cjs/src/index.js +17457 -382
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/esm/src/index.js +17424 -361
- package/dist/esm/src/index.js.map +1 -0
- package/dist/types/src/constants.d.ts +1 -2
- package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
- package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
- package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
- package/dist/types/src/splits/splitHelpers.d.ts +3 -3
- package/dist/types/src/utils.d.ts +2 -2
- package/dist/types/src/verification/common.d.ts +0 -2
- package/dist/types/src/verification/signature-validator.d.ts +4 -4
- package/dist/types/src/verification/v1.10.0.d.ts +1 -1
- package/dist/types/src/verification/v1.6.0.d.ts +1 -1
- package/dist/types/src/verification/v1.7.0.d.ts +1 -1
- package/dist/types/src/verification/v1.8.0.d.ts +1 -1
- package/dist/types/test/client/methods.spec.d.ts +17 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/tsup.config.d.ts +2 -0
- package/package.json +79 -54
- package/dist/cjs/package.json +0 -139
- package/dist/cjs/src/abi/BatchDeposit.js +0 -120
- package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
- package/dist/cjs/src/abi/Multicall3.js +0 -253
- package/dist/cjs/src/abi/OVM.js +0 -627
- package/dist/cjs/src/abi/OWR.js +0 -304
- package/dist/cjs/src/abi/SplitMain.js +0 -929
- package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
- package/dist/cjs/src/ajv.js +0 -136
- package/dist/cjs/src/base.js +0 -42
- package/dist/cjs/src/bytecodes.js +0 -19
- package/dist/cjs/src/constants.js +0 -272
- package/dist/cjs/src/eoa/eoa.js +0 -132
- package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
- package/dist/cjs/src/errors.js +0 -11
- package/dist/cjs/src/exits/ethUtils.js +0 -57
- package/dist/cjs/src/exits/exit.js +0 -502
- package/dist/cjs/src/exits/verificationHelpers.js +0 -86
- package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
- package/dist/cjs/src/incentives/incentives.js +0 -119
- package/dist/cjs/src/schema.js +0 -352
- package/dist/cjs/src/services.js +0 -33
- package/dist/cjs/src/splits/splitHelpers.js +0 -571
- package/dist/cjs/src/splits/splits.js +0 -366
- package/dist/cjs/src/types.js +0 -29
- package/dist/cjs/src/utils.js +0 -77
- package/dist/cjs/src/verification/common.js +0 -355
- package/dist/cjs/src/verification/signature-validator.js +0 -73
- package/dist/cjs/src/verification/sszTypes.js +0 -69
- package/dist/cjs/src/verification/termsAndConditions.js +0 -40
- package/dist/cjs/src/verification/v1.10.0.js +0 -146
- package/dist/cjs/src/verification/v1.6.0.js +0 -149
- package/dist/cjs/src/verification/v1.7.0.js +0 -173
- package/dist/cjs/src/verification/v1.8.0.js +0 -196
- package/dist/cjs/test/client/ajv.spec.js +0 -320
- package/dist/cjs/test/client/methods.spec.js +0 -418
- package/dist/cjs/test/eoa/eoa.spec.js +0 -176
- package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
- package/dist/cjs/test/exit/exit.spec.js +0 -399
- package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
- package/dist/cjs/test/fixtures.js +0 -896
- package/dist/cjs/test/incentives/incentives.spec.js +0 -202
- package/dist/cjs/test/splits/splits.spec.js +0 -402
- package/dist/esm/package.json +0 -139
- package/dist/esm/src/abi/BatchDeposit.js +0 -117
- package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
- package/dist/esm/src/abi/Multicall3.js +0 -250
- package/dist/esm/src/abi/OVM.js +0 -624
- package/dist/esm/src/abi/OWR.js +0 -301
- package/dist/esm/src/abi/SplitMain.js +0 -926
- package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
- package/dist/esm/src/ajv.js +0 -129
- package/dist/esm/src/base.js +0 -38
- package/dist/esm/src/bytecodes.js +0 -16
- package/dist/esm/src/constants.js +0 -238
- package/dist/esm/src/eoa/eoa.js +0 -128
- package/dist/esm/src/eoa/eoaHelpers.js +0 -77
- package/dist/esm/src/errors.js +0 -7
- package/dist/esm/src/exits/ethUtils.js +0 -52
- package/dist/esm/src/exits/exit.js +0 -475
- package/dist/esm/src/exits/verificationHelpers.js +0 -81
- package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
- package/dist/esm/src/incentives/incentives.js +0 -115
- package/dist/esm/src/schema.js +0 -349
- package/dist/esm/src/services.js +0 -29
- package/dist/esm/src/splits/splitHelpers.js +0 -554
- package/dist/esm/src/splits/splits.js +0 -362
- package/dist/esm/src/types.js +0 -26
- package/dist/esm/src/utils.js +0 -68
- package/dist/esm/src/verification/common.js +0 -319
- package/dist/esm/src/verification/signature-validator.js +0 -64
- package/dist/esm/src/verification/sszTypes.js +0 -64
- package/dist/esm/src/verification/termsAndConditions.js +0 -33
- package/dist/esm/src/verification/v1.10.0.js +0 -140
- package/dist/esm/src/verification/v1.6.0.js +0 -142
- package/dist/esm/src/verification/v1.7.0.js +0 -166
- package/dist/esm/src/verification/v1.8.0.js +0 -189
- package/dist/esm/test/client/ajv.spec.js +0 -318
- package/dist/esm/test/client/methods.spec.js +0 -393
- package/dist/esm/test/eoa/eoa.spec.js +0 -174
- package/dist/esm/test/exit/ethUtils.spec.js +0 -81
- package/dist/esm/test/exit/exit.spec.js +0 -374
- package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
- package/dist/esm/test/fixtures.js +0 -893
- package/dist/esm/test/incentives/incentives.spec.js +0 -177
- package/dist/esm/test/splits/splits.spec.js +0 -400
- package/src/abi/BatchDeposit.ts +0 -117
- package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
- package/src/abi/Multicall3.ts +0 -250
- package/src/abi/OVM.ts +0 -624
- package/src/abi/OWR.ts +0 -302
- package/src/abi/SplitMain.ts +0 -927
- package/src/abi/splitV2FactoryAbi.ts +0 -417
- package/src/ajv.ts +0 -191
- package/src/base.ts +0 -54
- package/src/bytecodes.ts +0 -32
- package/src/constants.ts +0 -309
- package/src/eoa/eoa.ts +0 -153
- package/src/eoa/eoaHelpers.ts +0 -112
- package/src/errors.ts +0 -8
- package/src/exits/ethUtils.ts +0 -49
- package/src/exits/exit.ts +0 -661
- package/src/exits/verificationHelpers.ts +0 -110
- package/src/incentives/incentiveHelpers.ts +0 -55
- package/src/incentives/incentives.ts +0 -153
- package/src/index.ts +0 -614
- package/src/schema.ts +0 -376
- package/src/services.ts +0 -24
- package/src/splits/splitHelpers.ts +0 -1032
- package/src/splits/splits.ts +0 -504
- package/src/types.ts +0 -687
- package/src/utils.ts +0 -88
- package/src/verification/common.ts +0 -532
- package/src/verification/signature-validator.ts +0 -103
- package/src/verification/sszTypes.ts +0 -88
- package/src/verification/termsAndConditions.ts +0 -32
- package/src/verification/v1.10.0.ts +0 -245
- package/src/verification/v1.6.0.ts +0 -256
- package/src/verification/v1.7.0.ts +0 -309
- package/src/verification/v1.8.0.ts +0 -340
package/src/utils.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { DefinitionFlow, PROVIDER_MAP } from './constants';
|
|
3
|
-
import { FORK_NAMES, type ProviderType, type ClusterDefinition } from './types';
|
|
4
|
-
|
|
5
|
-
export const hexWithout0x = (hex: string): string => {
|
|
6
|
-
return hex.slice(2, hex.length);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const strToUint8Array = (str: string): Uint8Array => {
|
|
10
|
-
return new TextEncoder().encode(str);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const definitionFlow = (
|
|
14
|
-
clusterDefinition: ClusterDefinition,
|
|
15
|
-
): DefinitionFlow | null => {
|
|
16
|
-
if (
|
|
17
|
-
clusterDefinition.creator.address &&
|
|
18
|
-
clusterDefinition.creator.config_signature &&
|
|
19
|
-
clusterDefinition.operators.every(operator => {
|
|
20
|
-
return (
|
|
21
|
-
operator.address &&
|
|
22
|
-
operator.config_signature &&
|
|
23
|
-
operator.enr &&
|
|
24
|
-
operator.enr_signature
|
|
25
|
-
);
|
|
26
|
-
})
|
|
27
|
-
) {
|
|
28
|
-
return DefinitionFlow.Group;
|
|
29
|
-
} else if (
|
|
30
|
-
clusterDefinition.creator.address &&
|
|
31
|
-
clusterDefinition.creator.config_signature &&
|
|
32
|
-
clusterDefinition.operators.every(operator => {
|
|
33
|
-
return (
|
|
34
|
-
!operator.address &&
|
|
35
|
-
!operator.config_signature &&
|
|
36
|
-
operator.enr &&
|
|
37
|
-
!operator.enr_signature
|
|
38
|
-
);
|
|
39
|
-
})
|
|
40
|
-
) {
|
|
41
|
-
return DefinitionFlow.Solo;
|
|
42
|
-
} else if (
|
|
43
|
-
!clusterDefinition.creator.address &&
|
|
44
|
-
!clusterDefinition.creator.config_signature &&
|
|
45
|
-
clusterDefinition.operators.every(operator => {
|
|
46
|
-
return (
|
|
47
|
-
!operator.address &&
|
|
48
|
-
!operator.config_signature &&
|
|
49
|
-
operator.enr &&
|
|
50
|
-
!operator.enr_signature
|
|
51
|
-
);
|
|
52
|
-
})
|
|
53
|
-
) {
|
|
54
|
-
return DefinitionFlow.Charon;
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const findDeployedBytecode = async (
|
|
60
|
-
contractAddress: string,
|
|
61
|
-
provider: ProviderType,
|
|
62
|
-
): Promise<string> => {
|
|
63
|
-
return await provider?.getCode(contractAddress);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const isContractAvailable = async (
|
|
67
|
-
contractAddress: string,
|
|
68
|
-
provider: ProviderType,
|
|
69
|
-
bytecode?: string,
|
|
70
|
-
): Promise<boolean> => {
|
|
71
|
-
const code = await findDeployedBytecode(contractAddress, provider);
|
|
72
|
-
|
|
73
|
-
if (bytecode) {
|
|
74
|
-
return !!code && code === bytecode;
|
|
75
|
-
}
|
|
76
|
-
return !!code && code !== '0x' && code !== '0x0';
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const getProvider = (
|
|
80
|
-
chainId: number,
|
|
81
|
-
rpcUrl?: string,
|
|
82
|
-
): ethers.JsonRpcProvider => {
|
|
83
|
-
const resolvedRpcUrl = rpcUrl ?? PROVIDER_MAP[chainId];
|
|
84
|
-
if (chainId && (!resolvedRpcUrl || resolvedRpcUrl === 'undefined')) {
|
|
85
|
-
throw new Error(`No provider configured for ${FORK_NAMES[chainId]}`);
|
|
86
|
-
}
|
|
87
|
-
return new ethers.JsonRpcProvider(resolvedRpcUrl);
|
|
88
|
-
};
|
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
import { fromHexString } from '@chainsafe/ssz';
|
|
2
|
-
import elliptic from 'elliptic';
|
|
3
|
-
import { init } from '@chainsafe/bls';
|
|
4
|
-
import {
|
|
5
|
-
FORK_MAPPING,
|
|
6
|
-
type ClusterDefinition,
|
|
7
|
-
type ClusterLock,
|
|
8
|
-
type DepositData,
|
|
9
|
-
type BuilderRegistrationMessage,
|
|
10
|
-
type DistributedValidator,
|
|
11
|
-
type SafeRpcUrl,
|
|
12
|
-
} from '../types.js';
|
|
13
|
-
import * as semver from 'semver';
|
|
14
|
-
import {
|
|
15
|
-
clusterDefinitionContainerTypeV1X6,
|
|
16
|
-
hashClusterDefinitionV1X6,
|
|
17
|
-
hashClusterLockV1X6,
|
|
18
|
-
verifyDVV1X6,
|
|
19
|
-
} from './v1.6.0.js';
|
|
20
|
-
import {
|
|
21
|
-
clusterDefinitionContainerTypeV1X7,
|
|
22
|
-
hashClusterDefinitionV1X7,
|
|
23
|
-
hashClusterLockV1X7,
|
|
24
|
-
verifyDVV1X7,
|
|
25
|
-
} from './v1.7.0.js';
|
|
26
|
-
import {
|
|
27
|
-
DOMAIN_APPLICATION_BUILDER,
|
|
28
|
-
DOMAIN_DEPOSIT,
|
|
29
|
-
DefinitionFlow,
|
|
30
|
-
GENESIS_VALIDATOR_ROOT,
|
|
31
|
-
signCreatorConfigHashPayload,
|
|
32
|
-
signEnrPayload,
|
|
33
|
-
signOperatorConfigHashPayload,
|
|
34
|
-
} from '../constants.js';
|
|
35
|
-
import {
|
|
36
|
-
builderRegistrationMessageType,
|
|
37
|
-
depositMessageType,
|
|
38
|
-
forkDataType,
|
|
39
|
-
signingRootType,
|
|
40
|
-
} from './sszTypes.js';
|
|
41
|
-
import { definitionFlow, hexWithout0x } from '../utils.js';
|
|
42
|
-
import { ENR } from '@chainsafe/discv5';
|
|
43
|
-
import {
|
|
44
|
-
clusterDefinitionContainerTypeV1X8,
|
|
45
|
-
hashClusterDefinitionV1X8,
|
|
46
|
-
hashClusterLockV1X8,
|
|
47
|
-
verifyDVV1X8,
|
|
48
|
-
} from './v1.8.0.js';
|
|
49
|
-
import { validateAddressSignature } from './signature-validator.js';
|
|
50
|
-
import {
|
|
51
|
-
clusterDefinitionContainerTypeV1X10,
|
|
52
|
-
hashClusterDefinitionV1X10,
|
|
53
|
-
hashClusterLockV1X10,
|
|
54
|
-
verifyDVV1X10,
|
|
55
|
-
} from './v1.10.0.js';
|
|
56
|
-
|
|
57
|
-
// cluster-definition hash
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @param cluster The cluster configuration or the cluster definition
|
|
61
|
-
* @param configOnly a boolean to indicate config hash or definition hash
|
|
62
|
-
* @returns The config hash or the definition hash in of the corresponding cluster
|
|
63
|
-
*/
|
|
64
|
-
export const clusterConfigOrDefinitionHash = (
|
|
65
|
-
cluster: ClusterDefinition,
|
|
66
|
-
configOnly: boolean,
|
|
67
|
-
): string => {
|
|
68
|
-
let definitionType, val;
|
|
69
|
-
|
|
70
|
-
if (semver.eq(cluster.version, 'v1.6.0')) {
|
|
71
|
-
definitionType = clusterDefinitionContainerTypeV1X6(configOnly);
|
|
72
|
-
val = hashClusterDefinitionV1X6(cluster, configOnly);
|
|
73
|
-
return (
|
|
74
|
-
'0x' +
|
|
75
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex')
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (semver.eq(cluster.version, 'v1.7.0')) {
|
|
80
|
-
definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
|
|
81
|
-
val = hashClusterDefinitionV1X7(cluster, configOnly);
|
|
82
|
-
return (
|
|
83
|
-
'0x' +
|
|
84
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex')
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (semver.eq(cluster.version, 'v1.8.0')) {
|
|
89
|
-
definitionType = clusterDefinitionContainerTypeV1X8(configOnly);
|
|
90
|
-
val = hashClusterDefinitionV1X8(cluster, configOnly);
|
|
91
|
-
return (
|
|
92
|
-
'0x' +
|
|
93
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex')
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (semver.eq(cluster.version, 'v1.10.0')) {
|
|
98
|
-
definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
|
|
99
|
-
val = hashClusterDefinitionV1X10(cluster, configOnly);
|
|
100
|
-
const x =
|
|
101
|
-
'0x' +
|
|
102
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex');
|
|
103
|
-
return x;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
throw new Error('unsupported version');
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// cluster-lock hash
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Returns the SSZ cluster lock hash of the given cluster lock object
|
|
113
|
-
* @param cluster The cluster lock whose lock hash needs to be calculated
|
|
114
|
-
* @returns The cluster lock hash in of the corresponding cluster lock
|
|
115
|
-
*/
|
|
116
|
-
export const clusterLockHash = (clusterLock: ClusterLock): string => {
|
|
117
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.6.0')) {
|
|
118
|
-
return hashClusterLockV1X6(clusterLock);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.7.0')) {
|
|
122
|
-
return hashClusterLockV1X7(clusterLock);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
|
|
126
|
-
if (
|
|
127
|
-
clusterLock.cluster_definition.deposit_amounts === null &&
|
|
128
|
-
clusterLock.distributed_validators.some(
|
|
129
|
-
distributedValidator =>
|
|
130
|
-
distributedValidator.partial_deposit_data?.length !== 1 ||
|
|
131
|
-
distributedValidator.partial_deposit_data[0].amount !== '32000000000',
|
|
132
|
-
)
|
|
133
|
-
) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
'mismatch between deposit_amounts and partial_deposit_data fields',
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return hashClusterLockV1X8(clusterLock);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
142
|
-
// if (
|
|
143
|
-
// clusterLock.cluster_definition.deposit_amounts === null &&
|
|
144
|
-
// clusterLock.distributed_validators.some(
|
|
145
|
-
// distributedValidator =>
|
|
146
|
-
// distributedValidator.partial_deposit_data?.length !== 1 ||
|
|
147
|
-
// distributedValidator.partial_deposit_data[0].amount !== '32000000000',
|
|
148
|
-
// )
|
|
149
|
-
// ) {
|
|
150
|
-
// throw new Error(
|
|
151
|
-
// 'mismatch between deposit_amounts and partial_deposit_data fields',
|
|
152
|
-
// );
|
|
153
|
-
// }
|
|
154
|
-
return hashClusterLockV1X10(clusterLock);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// other versions
|
|
158
|
-
throw new Error('unsupported version');
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// Lock verification
|
|
162
|
-
|
|
163
|
-
// cluster-definition signatures verification
|
|
164
|
-
|
|
165
|
-
const validatePOSTConfigHashSigner = async (
|
|
166
|
-
address: string,
|
|
167
|
-
signature: string,
|
|
168
|
-
configHash: string,
|
|
169
|
-
chainId: FORK_MAPPING,
|
|
170
|
-
safeRpcUrl?: SafeRpcUrl,
|
|
171
|
-
): Promise<boolean> => {
|
|
172
|
-
try {
|
|
173
|
-
const data = signCreatorConfigHashPayload(
|
|
174
|
-
{ creator_config_hash: configHash },
|
|
175
|
-
chainId,
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
return await validateAddressSignature({
|
|
179
|
-
address,
|
|
180
|
-
token: signature,
|
|
181
|
-
data,
|
|
182
|
-
chainId,
|
|
183
|
-
safeRpcUrl,
|
|
184
|
-
});
|
|
185
|
-
} catch (err) {
|
|
186
|
-
throw err;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const validatePUTConfigHashSigner = async (
|
|
191
|
-
address: string,
|
|
192
|
-
signature: string,
|
|
193
|
-
configHash: string,
|
|
194
|
-
chainId: number,
|
|
195
|
-
safeRpcUrl?: SafeRpcUrl,
|
|
196
|
-
): Promise<boolean> => {
|
|
197
|
-
try {
|
|
198
|
-
const data = signOperatorConfigHashPayload(
|
|
199
|
-
{ operator_config_hash: configHash },
|
|
200
|
-
chainId,
|
|
201
|
-
);
|
|
202
|
-
return await validateAddressSignature({
|
|
203
|
-
address,
|
|
204
|
-
token: signature,
|
|
205
|
-
data,
|
|
206
|
-
chainId,
|
|
207
|
-
safeRpcUrl,
|
|
208
|
-
});
|
|
209
|
-
} catch (err) {
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const validateEnrSigner = async (
|
|
215
|
-
address: string,
|
|
216
|
-
signature: string,
|
|
217
|
-
payload: string,
|
|
218
|
-
chainId: number,
|
|
219
|
-
safeRpcUrl?: SafeRpcUrl,
|
|
220
|
-
): Promise<boolean> => {
|
|
221
|
-
try {
|
|
222
|
-
const data = signEnrPayload({ enr: payload }, chainId);
|
|
223
|
-
|
|
224
|
-
return await validateAddressSignature({
|
|
225
|
-
address,
|
|
226
|
-
token: signature,
|
|
227
|
-
data,
|
|
228
|
-
chainId,
|
|
229
|
-
safeRpcUrl,
|
|
230
|
-
});
|
|
231
|
-
} catch (err) {
|
|
232
|
-
throw err;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const verifyDefinitionSignatures = async (
|
|
237
|
-
clusterDefinition: ClusterDefinition,
|
|
238
|
-
definitionType: DefinitionFlow,
|
|
239
|
-
safeRpcUrl?: SafeRpcUrl,
|
|
240
|
-
): Promise<boolean> => {
|
|
241
|
-
if (definitionType === DefinitionFlow.Charon) {
|
|
242
|
-
return true;
|
|
243
|
-
} else {
|
|
244
|
-
const isPOSTConfigHashSignerValid = await validatePOSTConfigHashSigner(
|
|
245
|
-
clusterDefinition.creator.address,
|
|
246
|
-
clusterDefinition.creator.config_signature as string,
|
|
247
|
-
clusterDefinition.config_hash,
|
|
248
|
-
FORK_MAPPING[clusterDefinition.fork_version as keyof typeof FORK_MAPPING],
|
|
249
|
-
safeRpcUrl,
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
if (!isPOSTConfigHashSignerValid) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
if (definitionType === DefinitionFlow.Solo) {
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
for (const operator of clusterDefinition.operators) {
|
|
260
|
-
const isPUTConfigHashSignerValid = await validatePUTConfigHashSigner(
|
|
261
|
-
operator.address,
|
|
262
|
-
operator.config_signature as string,
|
|
263
|
-
clusterDefinition.config_hash,
|
|
264
|
-
FORK_MAPPING[
|
|
265
|
-
clusterDefinition.fork_version as keyof typeof FORK_MAPPING
|
|
266
|
-
],
|
|
267
|
-
safeRpcUrl,
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
const isENRSignerValid = await validateEnrSigner(
|
|
271
|
-
operator.address,
|
|
272
|
-
operator.enr_signature as string,
|
|
273
|
-
operator.enr as string,
|
|
274
|
-
FORK_MAPPING[
|
|
275
|
-
clusterDefinition.fork_version as keyof typeof FORK_MAPPING
|
|
276
|
-
],
|
|
277
|
-
safeRpcUrl,
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
if (!isPUTConfigHashSignerValid || !isENRSignerValid) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// cluster-lock data verification
|
|
290
|
-
const computeSigningRoot = (
|
|
291
|
-
sszObjectRoot: Uint8Array,
|
|
292
|
-
domain: Uint8Array,
|
|
293
|
-
): Uint8Array => {
|
|
294
|
-
const signingRootDefaultValue = signingRootType.defaultValue();
|
|
295
|
-
signingRootDefaultValue.objectRoot = sszObjectRoot;
|
|
296
|
-
signingRootDefaultValue.domain = domain;
|
|
297
|
-
return Buffer.from(
|
|
298
|
-
signingRootType.hashTreeRoot(signingRootDefaultValue).buffer,
|
|
299
|
-
);
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const computeDepositMsgRoot = (msg: Partial<DepositData>): Buffer => {
|
|
303
|
-
const depositMsgVal = depositMessageType.defaultValue();
|
|
304
|
-
|
|
305
|
-
depositMsgVal.pubkey = fromHexString(msg.pubkey as string);
|
|
306
|
-
depositMsgVal.withdrawal_credentials = fromHexString(
|
|
307
|
-
msg.withdrawal_credentials as string,
|
|
308
|
-
);
|
|
309
|
-
depositMsgVal.amount = parseInt(msg.amount as string);
|
|
310
|
-
return Buffer.from(depositMessageType.hashTreeRoot(depositMsgVal).buffer);
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
const computeForkDataRoot = (
|
|
314
|
-
currentVersion: Uint8Array,
|
|
315
|
-
genesisValidatorsRoot: Uint8Array,
|
|
316
|
-
): Uint8Array => {
|
|
317
|
-
const forkDataVal = forkDataType.defaultValue();
|
|
318
|
-
forkDataVal.currentVersion = currentVersion;
|
|
319
|
-
forkDataVal.genesisValidatorsRoot = genesisValidatorsRoot;
|
|
320
|
-
return Buffer.from(forkDataType.hashTreeRoot(forkDataVal).buffer);
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const computebuilderRegistrationMsgRoot = (
|
|
324
|
-
msg: BuilderRegistrationMessage,
|
|
325
|
-
): Buffer => {
|
|
326
|
-
const builderRegistrationMsgVal =
|
|
327
|
-
builderRegistrationMessageType.defaultValue();
|
|
328
|
-
|
|
329
|
-
builderRegistrationMsgVal.fee_recipient = fromHexString(msg.fee_recipient);
|
|
330
|
-
builderRegistrationMsgVal.gas_limit = msg.gas_limit;
|
|
331
|
-
builderRegistrationMsgVal.timestamp = msg.timestamp;
|
|
332
|
-
builderRegistrationMsgVal.pubkey = fromHexString(msg.pubkey);
|
|
333
|
-
return Buffer.from(
|
|
334
|
-
builderRegistrationMessageType.hashTreeRoot(builderRegistrationMsgVal)
|
|
335
|
-
.buffer,
|
|
336
|
-
);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const computeDomain = (
|
|
340
|
-
domainType: Uint8Array,
|
|
341
|
-
lockForkVersion: string,
|
|
342
|
-
genesisValidatorsRoot: Uint8Array = fromHexString(GENESIS_VALIDATOR_ROOT),
|
|
343
|
-
): Uint8Array => {
|
|
344
|
-
const forkVersion = fromHexString(
|
|
345
|
-
lockForkVersion.substring(2, lockForkVersion.length),
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
const forkDataRoot = computeForkDataRoot(forkVersion, genesisValidatorsRoot);
|
|
349
|
-
const domain = new Uint8Array(32);
|
|
350
|
-
domain.set(domainType);
|
|
351
|
-
domain.set(forkDataRoot.subarray(0, 28), 4);
|
|
352
|
-
return domain;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Verify deposit data withdrawal credintials and signature
|
|
357
|
-
* @param {string} forkVersion - fork version in definition file.
|
|
358
|
-
* @param {DistributedValidatorDto} validator - distributed validator.
|
|
359
|
-
* @param {string} withdrawalAddress - withdrawal address in definition file.
|
|
360
|
-
* @returns {boolean} - return if deposit data is valid.
|
|
361
|
-
*/
|
|
362
|
-
export const verifyDepositData = (
|
|
363
|
-
distributedPublicKey: string,
|
|
364
|
-
depositData: Partial<DepositData>,
|
|
365
|
-
withdrawalAddress: string,
|
|
366
|
-
forkVersion: string,
|
|
367
|
-
compounding?: boolean,
|
|
368
|
-
): { isValidDepositData: boolean; depositDataMsg: Uint8Array } => {
|
|
369
|
-
const depositDomain = computeDomain(
|
|
370
|
-
fromHexString(DOMAIN_DEPOSIT),
|
|
371
|
-
forkVersion,
|
|
372
|
-
);
|
|
373
|
-
const withdrawalPrefix = compounding ? '0x02' : '0x01';
|
|
374
|
-
const expectedWithdrawalCredentials =
|
|
375
|
-
withdrawalPrefix +
|
|
376
|
-
'0'.repeat(22) +
|
|
377
|
-
withdrawalAddress.toLowerCase().slice(2);
|
|
378
|
-
|
|
379
|
-
if (expectedWithdrawalCredentials !== depositData.withdrawal_credentials) {
|
|
380
|
-
return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (distributedPublicKey !== depositData.pubkey) {
|
|
384
|
-
return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const depositMessageBuffer = computeDepositMsgRoot(depositData);
|
|
388
|
-
const depositDataMessage = signingRoot(depositDomain, depositMessageBuffer);
|
|
389
|
-
|
|
390
|
-
return { isValidDepositData: true, depositDataMsg: depositDataMessage };
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
export const verifyBuilderRegistration = (
|
|
394
|
-
validator: DistributedValidator,
|
|
395
|
-
feeRecipientAddress: string,
|
|
396
|
-
forkVersion: string,
|
|
397
|
-
): {
|
|
398
|
-
isValidBuilderRegistration: boolean;
|
|
399
|
-
builderRegistrationMsg: Uint8Array;
|
|
400
|
-
} => {
|
|
401
|
-
const builderDomain = computeDomain(
|
|
402
|
-
fromHexString(DOMAIN_APPLICATION_BUILDER),
|
|
403
|
-
forkVersion,
|
|
404
|
-
);
|
|
405
|
-
|
|
406
|
-
if (
|
|
407
|
-
validator.distributed_public_key !==
|
|
408
|
-
validator.builder_registration?.message.pubkey
|
|
409
|
-
) {
|
|
410
|
-
return {
|
|
411
|
-
isValidBuilderRegistration: false,
|
|
412
|
-
builderRegistrationMsg: new Uint8Array(0),
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
if (
|
|
416
|
-
feeRecipientAddress.toLowerCase() !==
|
|
417
|
-
validator.builder_registration.message.fee_recipient.toLowerCase()
|
|
418
|
-
) {
|
|
419
|
-
return {
|
|
420
|
-
isValidBuilderRegistration: false,
|
|
421
|
-
builderRegistrationMsg: new Uint8Array(0),
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const builderRegistrationMessageBuffer = computebuilderRegistrationMsgRoot(
|
|
426
|
-
validator.builder_registration.message,
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
const builderRegistrationMessage = signingRoot(
|
|
430
|
-
builderDomain,
|
|
431
|
-
builderRegistrationMessageBuffer,
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
return {
|
|
435
|
-
isValidBuilderRegistration: true,
|
|
436
|
-
builderRegistrationMsg: builderRegistrationMessage,
|
|
437
|
-
};
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
export const verifyNodeSignatures = (clusterLock: ClusterLock): boolean => {
|
|
441
|
-
const ec = new elliptic.ec('secp256k1');
|
|
442
|
-
const nodeSignatures = clusterLock.node_signatures;
|
|
443
|
-
|
|
444
|
-
const lockHashWithout0x = hexWithout0x(clusterLock.lock_hash);
|
|
445
|
-
// node(ENR) signatures
|
|
446
|
-
for (let i = 0; i < (nodeSignatures as string[]).length; i++) {
|
|
447
|
-
const pubkey = ENR.decodeTxt(
|
|
448
|
-
clusterLock.cluster_definition.operators[i].enr as string,
|
|
449
|
-
).publicKey.toString('hex');
|
|
450
|
-
|
|
451
|
-
const ENRsignature = {
|
|
452
|
-
r: (nodeSignatures as string[])[i].slice(2, 66),
|
|
453
|
-
s: (nodeSignatures as string[])[i].slice(66, 130),
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
const nodeSignatureVerification = ec
|
|
457
|
-
.keyFromPublic(pubkey, 'hex')
|
|
458
|
-
.verify(lockHashWithout0x, ENRsignature);
|
|
459
|
-
|
|
460
|
-
if (!nodeSignatureVerification) {
|
|
461
|
-
return false;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return true;
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
export const signingRoot = (
|
|
469
|
-
domain: Uint8Array,
|
|
470
|
-
messageBuffer: Buffer,
|
|
471
|
-
): Uint8Array => {
|
|
472
|
-
return computeSigningRoot(messageBuffer, domain);
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
const verifyLockData = async (clusterLock: ClusterLock): Promise<boolean> => {
|
|
476
|
-
await init('herumi');
|
|
477
|
-
|
|
478
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.6.0')) {
|
|
479
|
-
return verifyDVV1X6(clusterLock);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.7.0')) {
|
|
483
|
-
return verifyDVV1X7(clusterLock);
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
|
|
487
|
-
return verifyDVV1X8(clusterLock);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
491
|
-
return verifyDVV1X10(clusterLock);
|
|
492
|
-
}
|
|
493
|
-
return false;
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
export const isValidClusterLock = async (
|
|
497
|
-
clusterLock: ClusterLock,
|
|
498
|
-
safeRpcUrl?: SafeRpcUrl,
|
|
499
|
-
): Promise<boolean> => {
|
|
500
|
-
try {
|
|
501
|
-
const definitionType = definitionFlow(clusterLock.cluster_definition);
|
|
502
|
-
if (definitionType == null) {
|
|
503
|
-
return false;
|
|
504
|
-
}
|
|
505
|
-
const isValidDefinitionData = await verifyDefinitionSignatures(
|
|
506
|
-
clusterLock.cluster_definition,
|
|
507
|
-
definitionType,
|
|
508
|
-
safeRpcUrl,
|
|
509
|
-
);
|
|
510
|
-
if (!isValidDefinitionData) {
|
|
511
|
-
return false;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
if (
|
|
515
|
-
clusterConfigOrDefinitionHash(clusterLock.cluster_definition, false) !==
|
|
516
|
-
clusterLock.cluster_definition.definition_hash
|
|
517
|
-
) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
if (clusterLockHash(clusterLock) !== clusterLock.lock_hash) {
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const isValidLockData = await verifyLockData(clusterLock);
|
|
525
|
-
if (!isValidLockData) {
|
|
526
|
-
return false;
|
|
527
|
-
}
|
|
528
|
-
return true;
|
|
529
|
-
} catch (err) {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
import {
|
|
4
|
-
SignTypedDataVersion,
|
|
5
|
-
TypedDataUtils,
|
|
6
|
-
type TypedMessage,
|
|
7
|
-
} from '@metamask/eth-sig-util';
|
|
8
|
-
import Safe from '@safe-global/protocol-kit';
|
|
9
|
-
import { PROVIDER_MAP } from '../constants';
|
|
10
|
-
import { hashTypedData } from '@safe-global/protocol-kit/dist/src/utils';
|
|
11
|
-
import { type EIP712TypedData } from '@safe-global/safe-core-sdk-types';
|
|
12
|
-
import { isContractAvailable, getProvider } from '../utils';
|
|
13
|
-
import { type SafeRpcUrl } from '../types';
|
|
14
|
-
|
|
15
|
-
export const validateAddressSignature = async ({
|
|
16
|
-
address,
|
|
17
|
-
token,
|
|
18
|
-
data,
|
|
19
|
-
chainId,
|
|
20
|
-
safeRpcUrl,
|
|
21
|
-
}: {
|
|
22
|
-
address: string;
|
|
23
|
-
token: string;
|
|
24
|
-
data: TypedMessage<any>;
|
|
25
|
-
chainId: number;
|
|
26
|
-
safeRpcUrl?: SafeRpcUrl;
|
|
27
|
-
}): Promise<boolean> => {
|
|
28
|
-
try {
|
|
29
|
-
const provider = getProvider(chainId, safeRpcUrl);
|
|
30
|
-
if (provider) {
|
|
31
|
-
const contractAddress = await isContractAvailable(address, provider);
|
|
32
|
-
if (contractAddress) {
|
|
33
|
-
return await validateSmartContractSignature({
|
|
34
|
-
token,
|
|
35
|
-
data: data as unknown as EIP712TypedData,
|
|
36
|
-
address,
|
|
37
|
-
chainId,
|
|
38
|
-
safeRpcUrl,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return validateEOASignature({ token, data, address });
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return validateEOASignature({ token, data, address });
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const validateEOASignature = ({
|
|
49
|
-
token,
|
|
50
|
-
data,
|
|
51
|
-
address,
|
|
52
|
-
}: {
|
|
53
|
-
token: string;
|
|
54
|
-
data: TypedMessage<any>;
|
|
55
|
-
address: string;
|
|
56
|
-
}): boolean => {
|
|
57
|
-
try {
|
|
58
|
-
const sig = ethers.Signature.from(token);
|
|
59
|
-
const digest = TypedDataUtils.eip712Hash(data, SignTypedDataVersion.V4);
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
ethers.recoverAddress(digest, sig).toLowerCase() ===
|
|
63
|
-
address.toLocaleLowerCase()
|
|
64
|
-
);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
console.error(`validate EOA Signature error: ${err}`);
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const validateSmartContractSignature = async ({
|
|
72
|
-
token,
|
|
73
|
-
data,
|
|
74
|
-
address,
|
|
75
|
-
chainId,
|
|
76
|
-
safeRpcUrl,
|
|
77
|
-
}: {
|
|
78
|
-
token: string;
|
|
79
|
-
data: EIP712TypedData;
|
|
80
|
-
address: string;
|
|
81
|
-
chainId: number;
|
|
82
|
-
safeRpcUrl?: SafeRpcUrl;
|
|
83
|
-
}): Promise<boolean> => {
|
|
84
|
-
try {
|
|
85
|
-
const safeProvider = safeRpcUrl ?? PROVIDER_MAP[chainId];
|
|
86
|
-
|
|
87
|
-
const protocolKit = await Safe.init({
|
|
88
|
-
provider: safeProvider,
|
|
89
|
-
safeAddress: address,
|
|
90
|
-
});
|
|
91
|
-
const messageHash = hashTypedData(data);
|
|
92
|
-
const isValidSignature = await protocolKit.isValidSignature(
|
|
93
|
-
messageHash,
|
|
94
|
-
token,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return isValidSignature;
|
|
98
|
-
} catch (err: any) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
`Error validating smart contract signature: ${err.message}`,
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
};
|