@obolnetwork/obol-sdk 2.11.4 → 2.11.5-rc.1
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 +33 -0
- package/dist/browser/src/index.js +18280 -0
- package/dist/browser/src/index.js.map +1 -0
- package/dist/cjs/src/index.js +17470 -382
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/esm/src/index.js +17437 -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 +96 -58
- 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/dist/types/src/verification/termsAndConditions.d.ts +0 -1
- 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
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.isValidClusterLock = exports.signingRoot = exports.verifyNodeSignatures = exports.verifyBuilderRegistration = exports.verifyDepositData = exports.clusterLockHash = exports.clusterConfigOrDefinitionHash = void 0;
|
|
39
|
-
const ssz_1 = require("@chainsafe/ssz");
|
|
40
|
-
const elliptic_1 = __importDefault(require("elliptic"));
|
|
41
|
-
const bls_1 = require("@chainsafe/bls");
|
|
42
|
-
const types_js_1 = require("../types.js");
|
|
43
|
-
const semver = __importStar(require("semver"));
|
|
44
|
-
const v1_6_0_js_1 = require("./v1.6.0.js");
|
|
45
|
-
const v1_7_0_js_1 = require("./v1.7.0.js");
|
|
46
|
-
const constants_js_1 = require("../constants.js");
|
|
47
|
-
const sszTypes_js_1 = require("./sszTypes.js");
|
|
48
|
-
const utils_js_1 = require("../utils.js");
|
|
49
|
-
const discv5_1 = require("@chainsafe/discv5");
|
|
50
|
-
const v1_8_0_js_1 = require("./v1.8.0.js");
|
|
51
|
-
const signature_validator_js_1 = require("./signature-validator.js");
|
|
52
|
-
const v1_10_0_js_1 = require("./v1.10.0.js");
|
|
53
|
-
// cluster-definition hash
|
|
54
|
-
/**
|
|
55
|
-
* @param cluster The cluster configuration or the cluster definition
|
|
56
|
-
* @param configOnly a boolean to indicate config hash or definition hash
|
|
57
|
-
* @returns The config hash or the definition hash in of the corresponding cluster
|
|
58
|
-
*/
|
|
59
|
-
const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
|
|
60
|
-
let definitionType, val;
|
|
61
|
-
if (semver.eq(cluster.version, 'v1.6.0')) {
|
|
62
|
-
definitionType = (0, v1_6_0_js_1.clusterDefinitionContainerTypeV1X6)(configOnly);
|
|
63
|
-
val = (0, v1_6_0_js_1.hashClusterDefinitionV1X6)(cluster, configOnly);
|
|
64
|
-
return ('0x' +
|
|
65
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
66
|
-
}
|
|
67
|
-
if (semver.eq(cluster.version, 'v1.7.0')) {
|
|
68
|
-
definitionType = (0, v1_7_0_js_1.clusterDefinitionContainerTypeV1X7)(configOnly);
|
|
69
|
-
val = (0, v1_7_0_js_1.hashClusterDefinitionV1X7)(cluster, configOnly);
|
|
70
|
-
return ('0x' +
|
|
71
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
72
|
-
}
|
|
73
|
-
if (semver.eq(cluster.version, 'v1.8.0')) {
|
|
74
|
-
definitionType = (0, v1_8_0_js_1.clusterDefinitionContainerTypeV1X8)(configOnly);
|
|
75
|
-
val = (0, v1_8_0_js_1.hashClusterDefinitionV1X8)(cluster, configOnly);
|
|
76
|
-
return ('0x' +
|
|
77
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
78
|
-
}
|
|
79
|
-
if (semver.eq(cluster.version, 'v1.10.0')) {
|
|
80
|
-
definitionType = (0, v1_10_0_js_1.clusterDefinitionContainerTypeV1X10)(configOnly);
|
|
81
|
-
val = (0, v1_10_0_js_1.hashClusterDefinitionV1X10)(cluster, configOnly);
|
|
82
|
-
const x = '0x' +
|
|
83
|
-
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex');
|
|
84
|
-
return x;
|
|
85
|
-
}
|
|
86
|
-
throw new Error('unsupported version');
|
|
87
|
-
};
|
|
88
|
-
exports.clusterConfigOrDefinitionHash = clusterConfigOrDefinitionHash;
|
|
89
|
-
// cluster-lock hash
|
|
90
|
-
/**
|
|
91
|
-
* Returns the SSZ cluster lock hash of the given cluster lock object
|
|
92
|
-
* @param cluster The cluster lock whose lock hash needs to be calculated
|
|
93
|
-
* @returns The cluster lock hash in of the corresponding cluster lock
|
|
94
|
-
*/
|
|
95
|
-
const clusterLockHash = (clusterLock) => {
|
|
96
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.6.0')) {
|
|
97
|
-
return (0, v1_6_0_js_1.hashClusterLockV1X6)(clusterLock);
|
|
98
|
-
}
|
|
99
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.7.0')) {
|
|
100
|
-
return (0, v1_7_0_js_1.hashClusterLockV1X7)(clusterLock);
|
|
101
|
-
}
|
|
102
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
|
|
103
|
-
if (clusterLock.cluster_definition.deposit_amounts === null &&
|
|
104
|
-
clusterLock.distributed_validators.some(distributedValidator => {
|
|
105
|
-
var _a;
|
|
106
|
-
return ((_a = distributedValidator.partial_deposit_data) === null || _a === void 0 ? void 0 : _a.length) !== 1 ||
|
|
107
|
-
distributedValidator.partial_deposit_data[0].amount !== '32000000000';
|
|
108
|
-
})) {
|
|
109
|
-
throw new Error('mismatch between deposit_amounts and partial_deposit_data fields');
|
|
110
|
-
}
|
|
111
|
-
return (0, v1_8_0_js_1.hashClusterLockV1X8)(clusterLock);
|
|
112
|
-
}
|
|
113
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
114
|
-
// if (
|
|
115
|
-
// clusterLock.cluster_definition.deposit_amounts === null &&
|
|
116
|
-
// clusterLock.distributed_validators.some(
|
|
117
|
-
// distributedValidator =>
|
|
118
|
-
// distributedValidator.partial_deposit_data?.length !== 1 ||
|
|
119
|
-
// distributedValidator.partial_deposit_data[0].amount !== '32000000000',
|
|
120
|
-
// )
|
|
121
|
-
// ) {
|
|
122
|
-
// throw new Error(
|
|
123
|
-
// 'mismatch between deposit_amounts and partial_deposit_data fields',
|
|
124
|
-
// );
|
|
125
|
-
// }
|
|
126
|
-
return (0, v1_10_0_js_1.hashClusterLockV1X10)(clusterLock);
|
|
127
|
-
}
|
|
128
|
-
// other versions
|
|
129
|
-
throw new Error('unsupported version');
|
|
130
|
-
};
|
|
131
|
-
exports.clusterLockHash = clusterLockHash;
|
|
132
|
-
// Lock verification
|
|
133
|
-
// cluster-definition signatures verification
|
|
134
|
-
const validatePOSTConfigHashSigner = (address, signature, configHash, chainId, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
-
try {
|
|
136
|
-
const data = (0, constants_js_1.signCreatorConfigHashPayload)({ creator_config_hash: configHash }, chainId);
|
|
137
|
-
return yield (0, signature_validator_js_1.validateAddressSignature)({
|
|
138
|
-
address,
|
|
139
|
-
token: signature,
|
|
140
|
-
data,
|
|
141
|
-
chainId,
|
|
142
|
-
safeRpcUrl,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
catch (err) {
|
|
146
|
-
throw err;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
const validatePUTConfigHashSigner = (address, signature, configHash, chainId, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
-
try {
|
|
151
|
-
const data = (0, constants_js_1.signOperatorConfigHashPayload)({ operator_config_hash: configHash }, chainId);
|
|
152
|
-
return yield (0, signature_validator_js_1.validateAddressSignature)({
|
|
153
|
-
address,
|
|
154
|
-
token: signature,
|
|
155
|
-
data,
|
|
156
|
-
chainId,
|
|
157
|
-
safeRpcUrl,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
throw err;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
const validateEnrSigner = (address, signature, payload, chainId, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
-
try {
|
|
166
|
-
const data = (0, constants_js_1.signEnrPayload)({ enr: payload }, chainId);
|
|
167
|
-
return yield (0, signature_validator_js_1.validateAddressSignature)({
|
|
168
|
-
address,
|
|
169
|
-
token: signature,
|
|
170
|
-
data,
|
|
171
|
-
chainId,
|
|
172
|
-
safeRpcUrl,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
catch (err) {
|
|
176
|
-
throw err;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const verifyDefinitionSignatures = (clusterDefinition, definitionType, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
180
|
-
if (definitionType === constants_js_1.DefinitionFlow.Charon) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
const isPOSTConfigHashSignerValid = yield validatePOSTConfigHashSigner(clusterDefinition.creator.address, clusterDefinition.creator.config_signature, clusterDefinition.config_hash, types_js_1.FORK_MAPPING[clusterDefinition.fork_version], safeRpcUrl);
|
|
185
|
-
if (!isPOSTConfigHashSignerValid) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
if (definitionType === constants_js_1.DefinitionFlow.Solo) {
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
for (const operator of clusterDefinition.operators) {
|
|
192
|
-
const isPUTConfigHashSignerValid = yield validatePUTConfigHashSigner(operator.address, operator.config_signature, clusterDefinition.config_hash, types_js_1.FORK_MAPPING[clusterDefinition.fork_version], safeRpcUrl);
|
|
193
|
-
const isENRSignerValid = yield validateEnrSigner(operator.address, operator.enr_signature, operator.enr, types_js_1.FORK_MAPPING[clusterDefinition.fork_version], safeRpcUrl);
|
|
194
|
-
if (!isPUTConfigHashSignerValid || !isENRSignerValid) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
// cluster-lock data verification
|
|
202
|
-
const computeSigningRoot = (sszObjectRoot, domain) => {
|
|
203
|
-
const signingRootDefaultValue = sszTypes_js_1.signingRootType.defaultValue();
|
|
204
|
-
signingRootDefaultValue.objectRoot = sszObjectRoot;
|
|
205
|
-
signingRootDefaultValue.domain = domain;
|
|
206
|
-
return Buffer.from(sszTypes_js_1.signingRootType.hashTreeRoot(signingRootDefaultValue).buffer);
|
|
207
|
-
};
|
|
208
|
-
const computeDepositMsgRoot = (msg) => {
|
|
209
|
-
const depositMsgVal = sszTypes_js_1.depositMessageType.defaultValue();
|
|
210
|
-
depositMsgVal.pubkey = (0, ssz_1.fromHexString)(msg.pubkey);
|
|
211
|
-
depositMsgVal.withdrawal_credentials = (0, ssz_1.fromHexString)(msg.withdrawal_credentials);
|
|
212
|
-
depositMsgVal.amount = parseInt(msg.amount);
|
|
213
|
-
return Buffer.from(sszTypes_js_1.depositMessageType.hashTreeRoot(depositMsgVal).buffer);
|
|
214
|
-
};
|
|
215
|
-
const computeForkDataRoot = (currentVersion, genesisValidatorsRoot) => {
|
|
216
|
-
const forkDataVal = sszTypes_js_1.forkDataType.defaultValue();
|
|
217
|
-
forkDataVal.currentVersion = currentVersion;
|
|
218
|
-
forkDataVal.genesisValidatorsRoot = genesisValidatorsRoot;
|
|
219
|
-
return Buffer.from(sszTypes_js_1.forkDataType.hashTreeRoot(forkDataVal).buffer);
|
|
220
|
-
};
|
|
221
|
-
const computebuilderRegistrationMsgRoot = (msg) => {
|
|
222
|
-
const builderRegistrationMsgVal = sszTypes_js_1.builderRegistrationMessageType.defaultValue();
|
|
223
|
-
builderRegistrationMsgVal.fee_recipient = (0, ssz_1.fromHexString)(msg.fee_recipient);
|
|
224
|
-
builderRegistrationMsgVal.gas_limit = msg.gas_limit;
|
|
225
|
-
builderRegistrationMsgVal.timestamp = msg.timestamp;
|
|
226
|
-
builderRegistrationMsgVal.pubkey = (0, ssz_1.fromHexString)(msg.pubkey);
|
|
227
|
-
return Buffer.from(sszTypes_js_1.builderRegistrationMessageType.hashTreeRoot(builderRegistrationMsgVal)
|
|
228
|
-
.buffer);
|
|
229
|
-
};
|
|
230
|
-
const computeDomain = (domainType, lockForkVersion, genesisValidatorsRoot = (0, ssz_1.fromHexString)(constants_js_1.GENESIS_VALIDATOR_ROOT)) => {
|
|
231
|
-
const forkVersion = (0, ssz_1.fromHexString)(lockForkVersion.substring(2, lockForkVersion.length));
|
|
232
|
-
const forkDataRoot = computeForkDataRoot(forkVersion, genesisValidatorsRoot);
|
|
233
|
-
const domain = new Uint8Array(32);
|
|
234
|
-
domain.set(domainType);
|
|
235
|
-
domain.set(forkDataRoot.subarray(0, 28), 4);
|
|
236
|
-
return domain;
|
|
237
|
-
};
|
|
238
|
-
/**
|
|
239
|
-
* Verify deposit data withdrawal credintials and signature
|
|
240
|
-
* @param {string} forkVersion - fork version in definition file.
|
|
241
|
-
* @param {DistributedValidatorDto} validator - distributed validator.
|
|
242
|
-
* @param {string} withdrawalAddress - withdrawal address in definition file.
|
|
243
|
-
* @returns {boolean} - return if deposit data is valid.
|
|
244
|
-
*/
|
|
245
|
-
const verifyDepositData = (distributedPublicKey, depositData, withdrawalAddress, forkVersion, compounding) => {
|
|
246
|
-
const depositDomain = computeDomain((0, ssz_1.fromHexString)(constants_js_1.DOMAIN_DEPOSIT), forkVersion);
|
|
247
|
-
const withdrawalPrefix = compounding ? '0x02' : '0x01';
|
|
248
|
-
const expectedWithdrawalCredentials = withdrawalPrefix +
|
|
249
|
-
'0'.repeat(22) +
|
|
250
|
-
withdrawalAddress.toLowerCase().slice(2);
|
|
251
|
-
if (expectedWithdrawalCredentials !== depositData.withdrawal_credentials) {
|
|
252
|
-
return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
|
|
253
|
-
}
|
|
254
|
-
if (distributedPublicKey !== depositData.pubkey) {
|
|
255
|
-
return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
|
|
256
|
-
}
|
|
257
|
-
const depositMessageBuffer = computeDepositMsgRoot(depositData);
|
|
258
|
-
const depositDataMessage = (0, exports.signingRoot)(depositDomain, depositMessageBuffer);
|
|
259
|
-
return { isValidDepositData: true, depositDataMsg: depositDataMessage };
|
|
260
|
-
};
|
|
261
|
-
exports.verifyDepositData = verifyDepositData;
|
|
262
|
-
const verifyBuilderRegistration = (validator, feeRecipientAddress, forkVersion) => {
|
|
263
|
-
var _a;
|
|
264
|
-
const builderDomain = computeDomain((0, ssz_1.fromHexString)(constants_js_1.DOMAIN_APPLICATION_BUILDER), forkVersion);
|
|
265
|
-
if (validator.distributed_public_key !==
|
|
266
|
-
((_a = validator.builder_registration) === null || _a === void 0 ? void 0 : _a.message.pubkey)) {
|
|
267
|
-
return {
|
|
268
|
-
isValidBuilderRegistration: false,
|
|
269
|
-
builderRegistrationMsg: new Uint8Array(0),
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
if (feeRecipientAddress.toLowerCase() !==
|
|
273
|
-
validator.builder_registration.message.fee_recipient.toLowerCase()) {
|
|
274
|
-
return {
|
|
275
|
-
isValidBuilderRegistration: false,
|
|
276
|
-
builderRegistrationMsg: new Uint8Array(0),
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
const builderRegistrationMessageBuffer = computebuilderRegistrationMsgRoot(validator.builder_registration.message);
|
|
280
|
-
const builderRegistrationMessage = (0, exports.signingRoot)(builderDomain, builderRegistrationMessageBuffer);
|
|
281
|
-
return {
|
|
282
|
-
isValidBuilderRegistration: true,
|
|
283
|
-
builderRegistrationMsg: builderRegistrationMessage,
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
exports.verifyBuilderRegistration = verifyBuilderRegistration;
|
|
287
|
-
const verifyNodeSignatures = (clusterLock) => {
|
|
288
|
-
const ec = new elliptic_1.default.ec('secp256k1');
|
|
289
|
-
const nodeSignatures = clusterLock.node_signatures;
|
|
290
|
-
const lockHashWithout0x = (0, utils_js_1.hexWithout0x)(clusterLock.lock_hash);
|
|
291
|
-
// node(ENR) signatures
|
|
292
|
-
for (let i = 0; i < nodeSignatures.length; i++) {
|
|
293
|
-
const pubkey = discv5_1.ENR.decodeTxt(clusterLock.cluster_definition.operators[i].enr).publicKey.toString('hex');
|
|
294
|
-
const ENRsignature = {
|
|
295
|
-
r: nodeSignatures[i].slice(2, 66),
|
|
296
|
-
s: nodeSignatures[i].slice(66, 130),
|
|
297
|
-
};
|
|
298
|
-
const nodeSignatureVerification = ec
|
|
299
|
-
.keyFromPublic(pubkey, 'hex')
|
|
300
|
-
.verify(lockHashWithout0x, ENRsignature);
|
|
301
|
-
if (!nodeSignatureVerification) {
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return true;
|
|
306
|
-
};
|
|
307
|
-
exports.verifyNodeSignatures = verifyNodeSignatures;
|
|
308
|
-
const signingRoot = (domain, messageBuffer) => {
|
|
309
|
-
return computeSigningRoot(messageBuffer, domain);
|
|
310
|
-
};
|
|
311
|
-
exports.signingRoot = signingRoot;
|
|
312
|
-
const verifyLockData = (clusterLock) => __awaiter(void 0, void 0, void 0, function* () {
|
|
313
|
-
yield (0, bls_1.init)('herumi');
|
|
314
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.6.0')) {
|
|
315
|
-
return (0, v1_6_0_js_1.verifyDVV1X6)(clusterLock);
|
|
316
|
-
}
|
|
317
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.7.0')) {
|
|
318
|
-
return (0, v1_7_0_js_1.verifyDVV1X7)(clusterLock);
|
|
319
|
-
}
|
|
320
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
|
|
321
|
-
return (0, v1_8_0_js_1.verifyDVV1X8)(clusterLock);
|
|
322
|
-
}
|
|
323
|
-
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
324
|
-
return (0, v1_10_0_js_1.verifyDVV1X10)(clusterLock);
|
|
325
|
-
}
|
|
326
|
-
return false;
|
|
327
|
-
});
|
|
328
|
-
const isValidClusterLock = (clusterLock, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
|
-
try {
|
|
330
|
-
const definitionType = (0, utils_js_1.definitionFlow)(clusterLock.cluster_definition);
|
|
331
|
-
if (definitionType == null) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
const isValidDefinitionData = yield verifyDefinitionSignatures(clusterLock.cluster_definition, definitionType, safeRpcUrl);
|
|
335
|
-
if (!isValidDefinitionData) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
if ((0, exports.clusterConfigOrDefinitionHash)(clusterLock.cluster_definition, false) !==
|
|
339
|
-
clusterLock.cluster_definition.definition_hash) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
if ((0, exports.clusterLockHash)(clusterLock) !== clusterLock.lock_hash) {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
const isValidLockData = yield verifyLockData(clusterLock);
|
|
346
|
-
if (!isValidLockData) {
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
catch (err) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
exports.isValidClusterLock = isValidClusterLock;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.validateSmartContractSignature = exports.validateEOASignature = exports.validateAddressSignature = void 0;
|
|
16
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
17
|
-
const ethers_1 = require("ethers");
|
|
18
|
-
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
19
|
-
const protocol_kit_1 = __importDefault(require("@safe-global/protocol-kit"));
|
|
20
|
-
const constants_1 = require("../constants");
|
|
21
|
-
const utils_1 = require("@safe-global/protocol-kit/dist/src/utils");
|
|
22
|
-
const utils_2 = require("../utils");
|
|
23
|
-
const validateAddressSignature = ({ address, token, data, chainId, safeRpcUrl, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
try {
|
|
25
|
-
const provider = (0, utils_2.getProvider)(chainId, safeRpcUrl);
|
|
26
|
-
if (provider) {
|
|
27
|
-
const contractAddress = yield (0, utils_2.isContractAvailable)(address, provider);
|
|
28
|
-
if (contractAddress) {
|
|
29
|
-
return yield (0, exports.validateSmartContractSignature)({
|
|
30
|
-
token,
|
|
31
|
-
data: data,
|
|
32
|
-
address,
|
|
33
|
-
chainId,
|
|
34
|
-
safeRpcUrl,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return (0, exports.validateEOASignature)({ token, data, address });
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
return (0, exports.validateEOASignature)({ token, data, address });
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
exports.validateAddressSignature = validateAddressSignature;
|
|
45
|
-
const validateEOASignature = ({ token, data, address, }) => {
|
|
46
|
-
try {
|
|
47
|
-
const sig = ethers_1.ethers.Signature.from(token);
|
|
48
|
-
const digest = eth_sig_util_1.TypedDataUtils.eip712Hash(data, eth_sig_util_1.SignTypedDataVersion.V4);
|
|
49
|
-
return (ethers_1.ethers.recoverAddress(digest, sig).toLowerCase() ===
|
|
50
|
-
address.toLocaleLowerCase());
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
console.error(`validate EOA Signature error: ${err}`);
|
|
54
|
-
throw err;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.validateEOASignature = validateEOASignature;
|
|
58
|
-
const validateSmartContractSignature = ({ token, data, address, chainId, safeRpcUrl, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
try {
|
|
60
|
-
const safeProvider = safeRpcUrl !== null && safeRpcUrl !== void 0 ? safeRpcUrl : constants_1.PROVIDER_MAP[chainId];
|
|
61
|
-
const protocolKit = yield protocol_kit_1.default.init({
|
|
62
|
-
provider: safeProvider,
|
|
63
|
-
safeAddress: address,
|
|
64
|
-
});
|
|
65
|
-
const messageHash = (0, utils_1.hashTypedData)(data);
|
|
66
|
-
const isValidSignature = yield protocolKit.isValidSignature(messageHash, token);
|
|
67
|
-
return isValidSignature;
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
throw new Error(`Error validating smart contract signature: ${err.message}`);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
exports.validateSmartContractSignature = validateSmartContractSignature;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signingRootType = exports.depositMessageType = exports.forkDataType = exports.builderRegistrationMessageType = exports.builderRegistrationContainer = exports.builderRegistrationMessageContainer = exports.depositDataContainer = exports.newOperatorContainerType = exports.newCreatorContainerType = exports.validatorsContainerType = exports.creatorContainerType = exports.operatorContainerType = exports.creatorAddressWrapperType = exports.operatorAddressWrapperType = void 0;
|
|
4
|
-
const ssz_1 = require("@chainsafe/ssz");
|
|
5
|
-
exports.operatorAddressWrapperType = new ssz_1.ContainerType({
|
|
6
|
-
address: new ssz_1.ByteVectorType(20),
|
|
7
|
-
});
|
|
8
|
-
exports.creatorAddressWrapperType = new ssz_1.ContainerType({
|
|
9
|
-
address: new ssz_1.ByteVectorType(20),
|
|
10
|
-
});
|
|
11
|
-
exports.operatorContainerType = new ssz_1.ContainerType({
|
|
12
|
-
address: new ssz_1.ByteVectorType(20),
|
|
13
|
-
enr: new ssz_1.ByteListType(1024), // This needs to be dynamic, since ENRs do not have a fixed length.
|
|
14
|
-
config_signature: new ssz_1.ByteVectorType(65),
|
|
15
|
-
enr_signature: new ssz_1.ByteVectorType(65),
|
|
16
|
-
});
|
|
17
|
-
exports.creatorContainerType = new ssz_1.ContainerType({
|
|
18
|
-
address: new ssz_1.ByteVectorType(20),
|
|
19
|
-
config_signature: new ssz_1.ByteVectorType(65),
|
|
20
|
-
});
|
|
21
|
-
exports.validatorsContainerType = new ssz_1.ContainerType({
|
|
22
|
-
fee_recipient_address: new ssz_1.ByteVectorType(20),
|
|
23
|
-
withdrawal_address: new ssz_1.ByteVectorType(20),
|
|
24
|
-
});
|
|
25
|
-
const newCreatorContainerType = (configOnly) => {
|
|
26
|
-
return configOnly ? exports.creatorAddressWrapperType : exports.creatorContainerType;
|
|
27
|
-
};
|
|
28
|
-
exports.newCreatorContainerType = newCreatorContainerType;
|
|
29
|
-
const newOperatorContainerType = (configOnly) => {
|
|
30
|
-
return configOnly ? exports.operatorAddressWrapperType : exports.operatorContainerType;
|
|
31
|
-
};
|
|
32
|
-
exports.newOperatorContainerType = newOperatorContainerType;
|
|
33
|
-
// Lock
|
|
34
|
-
exports.depositDataContainer = new ssz_1.ContainerType({
|
|
35
|
-
pubkey: new ssz_1.ByteVectorType(48),
|
|
36
|
-
withdrawal_credentials: new ssz_1.ByteVectorType(32),
|
|
37
|
-
amount: new ssz_1.UintNumberType(8),
|
|
38
|
-
signature: new ssz_1.ByteVectorType(96),
|
|
39
|
-
});
|
|
40
|
-
exports.builderRegistrationMessageContainer = new ssz_1.ContainerType({
|
|
41
|
-
fee_recipient: new ssz_1.ByteVectorType(20),
|
|
42
|
-
gas_limit: new ssz_1.UintNumberType(8),
|
|
43
|
-
timestamp: new ssz_1.UintNumberType(8),
|
|
44
|
-
pubkey: new ssz_1.ByteVectorType(48),
|
|
45
|
-
});
|
|
46
|
-
exports.builderRegistrationContainer = new ssz_1.ContainerType({
|
|
47
|
-
message: exports.builderRegistrationMessageContainer,
|
|
48
|
-
signature: new ssz_1.ByteVectorType(96),
|
|
49
|
-
});
|
|
50
|
-
exports.builderRegistrationMessageType = new ssz_1.ContainerType({
|
|
51
|
-
fee_recipient: new ssz_1.ByteVectorType(20),
|
|
52
|
-
gas_limit: new ssz_1.UintNumberType(8),
|
|
53
|
-
timestamp: new ssz_1.UintNumberType(8),
|
|
54
|
-
pubkey: new ssz_1.ByteVectorType(48),
|
|
55
|
-
});
|
|
56
|
-
// For domain computation that is used in deposit data and builder registration verification for dv
|
|
57
|
-
exports.forkDataType = new ssz_1.ContainerType({
|
|
58
|
-
currentVersion: new ssz_1.ByteVectorType(4),
|
|
59
|
-
genesisValidatorsRoot: new ssz_1.ByteVectorType(32),
|
|
60
|
-
});
|
|
61
|
-
exports.depositMessageType = new ssz_1.ContainerType({
|
|
62
|
-
pubkey: new ssz_1.ByteVectorType(48),
|
|
63
|
-
withdrawal_credentials: new ssz_1.ByteVectorType(32),
|
|
64
|
-
amount: new ssz_1.UintNumberType(8),
|
|
65
|
-
});
|
|
66
|
-
exports.signingRootType = new ssz_1.ContainerType({
|
|
67
|
-
objectRoot: new ssz_1.ByteVectorType(32),
|
|
68
|
-
domain: new ssz_1.ByteVectorType(32),
|
|
69
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.hashTermsAndConditions = void 0;
|
|
16
|
-
const pdf_parse_1 = __importDefault(require("pdf-parse"));
|
|
17
|
-
const ssz_1 = require("@chainsafe/ssz");
|
|
18
|
-
const constants_1 = require("../constants");
|
|
19
|
-
const utils_1 = require("../utils");
|
|
20
|
-
const hashTermsAndConditions = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
try {
|
|
22
|
-
// read the pdf
|
|
23
|
-
const response = yield fetch(constants_1.TERMS_AND_CONDITIONS_URL);
|
|
24
|
-
const pdfBuffarrayBuffer = yield response.arrayBuffer();
|
|
25
|
-
const pdfBuffer = Buffer.from(pdfBuffarrayBuffer);
|
|
26
|
-
const data = yield (0, pdf_parse_1.default)(pdfBuffer);
|
|
27
|
-
// ssz hash
|
|
28
|
-
const termsType = new ssz_1.ContainerType({
|
|
29
|
-
terms_and_conditions_hash: new ssz_1.ByteListType(Number.MAX_SAFE_INTEGER),
|
|
30
|
-
});
|
|
31
|
-
const termsHasVal = termsType.defaultValue();
|
|
32
|
-
termsHasVal.terms_and_conditions_hash = (0, utils_1.strToUint8Array)(data === null || data === void 0 ? void 0 : data.text.replace(/[^a-zA-Z0-9]/g, ''));
|
|
33
|
-
return ('0x' +
|
|
34
|
-
Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex'));
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
exports.hashTermsAndConditions = hashTermsAndConditions;
|