@ssv-labs/ssv-sdk 0.1.3 → 1.0.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.html +4 -7
- package/README.md +37 -26
- package/dist/{KeyShares-B_4l2THg.js → KeyShares-Bk9uzOlK.js} +194 -51
- package/dist/{KeyShares-ClzHwMUy.mjs → KeyShares-Dlp4Pa3b.mjs} +198 -55
- package/dist/abi/mainnet/v4/getter.d.ts +699 -74
- package/dist/abi/mainnet/v4/setter.d.ts +939 -59
- package/dist/api/subgraph/index.d.ts +36 -1
- package/dist/config/create.d.ts +2 -2
- package/dist/config/globals.d.ts +3 -0
- package/dist/{globals-CDOcDUnk.mjs → config-BdEJjnYA.mjs} +107 -79
- package/dist/{globals-DsaKgq3v.js → config-ClGS9Tic.js} +73 -45
- package/dist/contract-interactions/create.d.ts +1 -1
- package/dist/contract-interactions/types.d.ts +9 -3
- package/dist/graphql/graphql.d.ts +4663 -922
- package/dist/keys.js +1 -1
- package/dist/keys.mjs +5 -5
- package/dist/libs/api/index.d.ts +2 -0
- package/dist/libs/cluster/index.d.ts +3 -1
- package/dist/libs/cluster/methods/deposit.d.ts +150 -4
- package/dist/libs/cluster/methods/exit-validators.d.ts +149 -0
- package/dist/libs/cluster/methods/index.d.ts +3 -1
- package/dist/libs/cluster/methods/liquidate-cluster.d.ts +149 -0
- package/dist/libs/cluster/methods/liquidate-ssv.d.ts +430 -0
- package/dist/libs/cluster/methods/migrate-cluster-to-eth.d.ts +431 -0
- package/dist/libs/cluster/methods/reactivate-cluster.d.ts +149 -0
- package/dist/libs/cluster/methods/register-validators.d.ts +2222 -309
- package/dist/libs/cluster/methods/remove-validators.d.ts +149 -0
- package/dist/libs/cluster/methods/set-fee-recipient.d.ts +149 -0
- package/dist/libs/cluster/methods/withdraw.d.ts +149 -0
- package/dist/libs/dao/index.d.ts +8 -0
- package/dist/libs/dao/methods/commit-root.d.ts +432 -0
- package/dist/libs/dao/methods/index.d.ts +3 -0
- package/dist/libs/dao/methods/update-network-fee-ssv.d.ts +430 -0
- package/dist/libs/dao/methods/withdraw-network-ssv-earnings.d.ts +430 -0
- package/dist/libs/operator/index.d.ts +1525 -32
- package/dist/libs/operator/methods.d.ts +1731 -2
- package/dist/libs/ssv-keys/Encryption/__test__/RsaKeys.d.ts +1 -1
- package/dist/libs/ssv-keys/KeyShares/KeySharesItem.d.ts +1 -1
- package/dist/libs/ssv-keys/SSVKeys.d.ts +1 -1
- package/dist/libs/ssv-keys/exceptions/index.d.ts +1 -1
- package/dist/libs/ssv-keys/index.d.ts +1 -1
- package/dist/libs/ssv-keys/interfaces/index.d.ts +2 -2
- package/dist/libs/utils/index.d.ts +6 -4
- package/dist/libs/utils/methods/calc-deposit-from-runway.d.ts +11 -0
- package/dist/libs/utils/methods/get-cluster-balance.d.ts +3 -1
- package/dist/libs/utils/methods/keyshares.d.ts +4 -2
- package/dist/libs/utils/methods/keystores.d.ts +4 -4
- package/dist/main.d.ts +1 -0
- package/dist/main.js +2714 -729
- package/dist/main.mjs +2746 -761
- package/dist/sdk.d.ts +8 -4
- package/dist/types/contract-interactions.d.ts +11 -0
- package/dist/types/methods.d.ts +4 -3
- package/dist/utils/cluster.d.ts +3 -3
- package/dist/utils/funding.d.ts +29 -0
- package/dist/utils/zod/config.d.ts +1 -1
- package/dist/utils.js +38 -38
- package/dist/utils.mjs +34 -34
- package/package.json +18 -6
|
@@ -2,10 +2,6 @@ import bls from "bls-eth-wasm";
|
|
|
2
2
|
import crypto$1 from "crypto";
|
|
3
3
|
import { keccak256, toHex, sha256 as sha256$1, toBytes, fromHex, getAddress } from "viem";
|
|
4
4
|
import { ValidatorConstraint, registerDecorator, IsNotEmpty, IsDefined, IsInt, IsString, validateSync, IsOptional, IsNumber, Length, ValidateNested } from "class-validator";
|
|
5
|
-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
6
|
-
function getDefaultExportFromCjs(x) {
|
|
7
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
8
|
-
}
|
|
9
5
|
(async () => {
|
|
10
6
|
await bls.init(bls.BLS12_381);
|
|
11
7
|
})();
|
|
@@ -64,6 +60,10 @@ class OwnerNonceFormatError extends SSVKeysException {
|
|
|
64
60
|
this.data = data;
|
|
65
61
|
}
|
|
66
62
|
}
|
|
63
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
64
|
+
function getDefaultExportFromCjs(x) {
|
|
65
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
66
|
+
}
|
|
67
67
|
var forge$C = {
|
|
68
68
|
// default options
|
|
69
69
|
options: {
|
|
@@ -1326,6 +1326,9 @@ util$1.format = function(format) {
|
|
|
1326
1326
|
parts.push("<?>");
|
|
1327
1327
|
}
|
|
1328
1328
|
break;
|
|
1329
|
+
// FIXME: do proper formatting for numbers, etc
|
|
1330
|
+
//case 'f':
|
|
1331
|
+
//case 'd':
|
|
1329
1332
|
case "%":
|
|
1330
1333
|
parts.push("%");
|
|
1331
1334
|
break;
|
|
@@ -9875,6 +9878,7 @@ var _readSignatureParameters = function(oid, obj, fillDefaults) {
|
|
|
9875
9878
|
var _createSignatureDigest = function(options) {
|
|
9876
9879
|
switch (oids[options.signatureOid]) {
|
|
9877
9880
|
case "sha1WithRSAEncryption":
|
|
9881
|
+
// deprecated alias
|
|
9878
9882
|
case "sha1WithRSASignature":
|
|
9879
9883
|
return forge$b.md.sha1.create();
|
|
9880
9884
|
case "md5WithRSAEncryption":
|
|
@@ -9900,6 +9904,7 @@ var _verifySignature = function(options) {
|
|
|
9900
9904
|
var scheme;
|
|
9901
9905
|
switch (cert.signatureOid) {
|
|
9902
9906
|
case oids.sha1WithRSAEncryption:
|
|
9907
|
+
// deprecated alias
|
|
9903
9908
|
case oids.sha1WithRSASignature:
|
|
9904
9909
|
break;
|
|
9905
9910
|
case oids["RSASSA-PSS"]:
|
|
@@ -10390,13 +10395,18 @@ pki$2.certificateExtensionFromAsn1 = function(ext) {
|
|
|
10390
10395
|
};
|
|
10391
10396
|
e.altNames.push(altName);
|
|
10392
10397
|
switch (gn.type) {
|
|
10398
|
+
// rfc822Name
|
|
10393
10399
|
case 1:
|
|
10400
|
+
// dNSName
|
|
10394
10401
|
case 2:
|
|
10402
|
+
// uniformResourceIdentifier (URI)
|
|
10395
10403
|
case 6:
|
|
10396
10404
|
break;
|
|
10405
|
+
// IPAddress
|
|
10397
10406
|
case 7:
|
|
10398
10407
|
altName.ip = forge$b.util.bytesToIP(gn.value);
|
|
10399
10408
|
break;
|
|
10409
|
+
// registeredID
|
|
10400
10410
|
case 8:
|
|
10401
10411
|
altName.oid = asn1$4.derToOid(gn.value);
|
|
10402
10412
|
break;
|
|
@@ -11951,6 +11961,7 @@ function _decodeSafeContents(safeContents, strict, password) {
|
|
|
11951
11961
|
"Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?"
|
|
11952
11962
|
);
|
|
11953
11963
|
}
|
|
11964
|
+
/* fall through */
|
|
11954
11965
|
case pki$1.oids.keyBag:
|
|
11955
11966
|
try {
|
|
11956
11967
|
bag.key = pki$1.privateKeyFromAsn1(bagAsn1);
|
|
@@ -11959,6 +11970,7 @@ function _decodeSafeContents(safeContents, strict, password) {
|
|
|
11959
11970
|
bag.asn1 = bagAsn1;
|
|
11960
11971
|
}
|
|
11961
11972
|
continue;
|
|
11973
|
+
/* Nothing more to do. */
|
|
11962
11974
|
case pki$1.oids.certBag:
|
|
11963
11975
|
validator = certBagValidator;
|
|
11964
11976
|
decoder = function() {
|
|
@@ -17456,7 +17468,10 @@ class ForgeEncrypt {
|
|
|
17456
17468
|
}
|
|
17457
17469
|
try {
|
|
17458
17470
|
const encryptedBytes = lib.util.decode64(encryptedData);
|
|
17459
|
-
const decrypted = this.privateKey.decrypt(
|
|
17471
|
+
const decrypted = this.privateKey.decrypt(
|
|
17472
|
+
encryptedBytes,
|
|
17473
|
+
"RSAES-PKCS1-V1_5"
|
|
17474
|
+
);
|
|
17460
17475
|
return decrypted;
|
|
17461
17476
|
} catch (error) {
|
|
17462
17477
|
return false;
|
|
@@ -17521,12 +17536,16 @@ const OperatorPublicKeyValidator$1 = (publicKey) => {
|
|
|
17521
17536
|
let decodedPublicKey = "";
|
|
17522
17537
|
if (!publicKey.startsWith(begin)) {
|
|
17523
17538
|
if (publicKey.length < 98) {
|
|
17524
|
-
throw new Error(
|
|
17539
|
+
throw new Error(
|
|
17540
|
+
"The length of the operator public key must be at least 98 characters."
|
|
17541
|
+
);
|
|
17525
17542
|
}
|
|
17526
17543
|
try {
|
|
17527
17544
|
decodedPublicKey = lib.util.decode64(publicKey).trim();
|
|
17528
17545
|
} catch (error) {
|
|
17529
|
-
throw new Error(
|
|
17546
|
+
throw new Error(
|
|
17547
|
+
"Failed to decode the operator public key. Ensure it's correctly base64 encoded."
|
|
17548
|
+
);
|
|
17530
17549
|
}
|
|
17531
17550
|
if (!decodedPublicKey.startsWith(begin)) {
|
|
17532
17551
|
throw new Error(`Operator public key does not start with '${begin}'`);
|
|
@@ -17541,12 +17560,16 @@ const OperatorPublicKeyValidator$1 = (publicKey) => {
|
|
|
17541
17560
|
const content = decodedPublicKey.slice(begin.length, publicKey.length - end.length).trim();
|
|
17542
17561
|
decodedOperator = lib.util.decode64(content);
|
|
17543
17562
|
} catch {
|
|
17544
|
-
throw new Error(
|
|
17563
|
+
throw new Error(
|
|
17564
|
+
"Failed to decode the RSA public key. Ensure it's correctly base64 encoded."
|
|
17565
|
+
);
|
|
17545
17566
|
}
|
|
17546
17567
|
try {
|
|
17547
17568
|
encrypt.setPublicKey(decodedOperator);
|
|
17548
17569
|
} catch {
|
|
17549
|
-
throw new Error(
|
|
17570
|
+
throw new Error(
|
|
17571
|
+
"Invalid operator key format, make sure the operator exists in the network."
|
|
17572
|
+
);
|
|
17550
17573
|
}
|
|
17551
17574
|
} catch (error) {
|
|
17552
17575
|
throw new OperatorPublicKeyError(
|
|
@@ -17590,7 +17613,10 @@ class Threshold {
|
|
|
17590
17613
|
*/
|
|
17591
17614
|
async create(privateKeyString, operatorIds) {
|
|
17592
17615
|
if (!privateKeyString.startsWith("0x")) {
|
|
17593
|
-
throw new PrivateKeyFormatError(
|
|
17616
|
+
throw new PrivateKeyFormatError(
|
|
17617
|
+
privateKeyString,
|
|
17618
|
+
"The private key must be provided in the 0x format."
|
|
17619
|
+
);
|
|
17594
17620
|
}
|
|
17595
17621
|
operatorIds.map((operatorId) => {
|
|
17596
17622
|
if (!Number.isInteger(operatorId)) {
|
|
@@ -17611,7 +17637,9 @@ class Threshold {
|
|
|
17611
17637
|
if (!bls.deserializeHexStrToSecretKey) {
|
|
17612
17638
|
await bls.init(bls.BLS12_381);
|
|
17613
17639
|
}
|
|
17614
|
-
this.privateKey = bls.deserializeHexStrToSecretKey(
|
|
17640
|
+
this.privateKey = bls.deserializeHexStrToSecretKey(
|
|
17641
|
+
privateKeyString.replace("0x", "")
|
|
17642
|
+
);
|
|
17615
17643
|
this.publicKey = this.privateKey.getPublicKey();
|
|
17616
17644
|
msk.push(this.privateKey);
|
|
17617
17645
|
mpk.push(this.publicKey);
|
|
@@ -17985,6 +18013,7 @@ var scrypt = { exports: {} };
|
|
|
17985
18013
|
arraycopy(B, Bi, XY, 0, Yi);
|
|
17986
18014
|
state = 1;
|
|
17987
18015
|
i1 = 0;
|
|
18016
|
+
// Fall through
|
|
17988
18017
|
case 1:
|
|
17989
18018
|
steps = N - i1;
|
|
17990
18019
|
if (steps > limit) {
|
|
@@ -18011,6 +18040,7 @@ var scrypt = { exports: {} };
|
|
|
18011
18040
|
}
|
|
18012
18041
|
i1 = 0;
|
|
18013
18042
|
state = 2;
|
|
18043
|
+
// Fall through
|
|
18014
18044
|
case 2:
|
|
18015
18045
|
steps = N - i1;
|
|
18016
18046
|
if (steps > limit) {
|
|
@@ -18107,11 +18137,17 @@ class EthereumKeyStore {
|
|
|
18107
18137
|
privateKey = "";
|
|
18108
18138
|
constructor(keyStoreData) {
|
|
18109
18139
|
if (!keyStoreData) {
|
|
18110
|
-
throw new KeyStoreDataFormatError(
|
|
18140
|
+
throw new KeyStoreDataFormatError(
|
|
18141
|
+
keyStoreData,
|
|
18142
|
+
"Key store data should be JSON or string"
|
|
18143
|
+
);
|
|
18111
18144
|
}
|
|
18112
18145
|
this.keyStoreData = typeof keyStoreData === "string" ? JSON.parse(keyStoreData) : keyStoreData;
|
|
18113
18146
|
if (!this.keyStoreData.version) {
|
|
18114
|
-
throw new KeyStoreInvalidError(
|
|
18147
|
+
throw new KeyStoreInvalidError(
|
|
18148
|
+
this.keyStoreData,
|
|
18149
|
+
"Invalid keystore file"
|
|
18150
|
+
);
|
|
18115
18151
|
}
|
|
18116
18152
|
}
|
|
18117
18153
|
// getPublicKey(): string {
|
|
@@ -18151,15 +18187,32 @@ class EthereumKeyStore {
|
|
|
18151
18187
|
const dklen = kdfparams.dklen;
|
|
18152
18188
|
let derivedKey;
|
|
18153
18189
|
if (json.crypto.kdf === "scrypt") {
|
|
18154
|
-
derivedKey = scryptExports.syncScrypt(
|
|
18190
|
+
derivedKey = scryptExports.syncScrypt(
|
|
18191
|
+
Buffer.from(password),
|
|
18192
|
+
salt,
|
|
18193
|
+
kdfparams.n,
|
|
18194
|
+
kdfparams.r,
|
|
18195
|
+
kdfparams.p,
|
|
18196
|
+
dklen
|
|
18197
|
+
);
|
|
18155
18198
|
} else if (json.crypto.kdf === "pbkdf2") {
|
|
18156
|
-
if (kdfparams.prf !== "hmac-sha256")
|
|
18157
|
-
|
|
18199
|
+
if (kdfparams.prf !== "hmac-sha256")
|
|
18200
|
+
throw new EthereumWalletError("Unsupported PBKDF2 params");
|
|
18201
|
+
derivedKey = crypto$1.pbkdf2Sync(
|
|
18202
|
+
Buffer.from(password),
|
|
18203
|
+
salt,
|
|
18204
|
+
kdfparams.c,
|
|
18205
|
+
dklen,
|
|
18206
|
+
"sha256"
|
|
18207
|
+
);
|
|
18158
18208
|
} else {
|
|
18159
18209
|
throw new EthereumWalletError("Unsupported kdf type");
|
|
18160
18210
|
}
|
|
18161
18211
|
const ciphertext = Buffer.from(json.crypto.ciphertext, "hex");
|
|
18162
|
-
const macCheck = Buffer.concat([
|
|
18212
|
+
const macCheck = Buffer.concat([
|
|
18213
|
+
Buffer.from(derivedKey.slice(16, 32)),
|
|
18214
|
+
ciphertext
|
|
18215
|
+
]);
|
|
18163
18216
|
const mac = keccak256(toHex(macCheck)).replace(/^0x/, "");
|
|
18164
18217
|
if (mac !== json.crypto.mac.toLowerCase()) {
|
|
18165
18218
|
throw new EthereumWalletError("Invalid password");
|
|
@@ -18188,12 +18241,21 @@ class EthereumKeyStore {
|
|
|
18188
18241
|
if (prf !== "hmac-sha256") {
|
|
18189
18242
|
throw new EthereumWalletError("Unsupported parameters to PBKDF2");
|
|
18190
18243
|
}
|
|
18191
|
-
derivedKey = crypto$1.pbkdf2Sync(
|
|
18244
|
+
derivedKey = crypto$1.pbkdf2Sync(
|
|
18245
|
+
Buffer.from(password),
|
|
18246
|
+
salt,
|
|
18247
|
+
c,
|
|
18248
|
+
dklen,
|
|
18249
|
+
"sha256"
|
|
18250
|
+
);
|
|
18192
18251
|
} else {
|
|
18193
18252
|
throw new EthereumWalletError("Unsupported key derivation scheme");
|
|
18194
18253
|
}
|
|
18195
18254
|
const ciphertext = Buffer.from(cipher.message, "hex");
|
|
18196
|
-
const checksumBuffer = Buffer.concat([
|
|
18255
|
+
const checksumBuffer = Buffer.concat([
|
|
18256
|
+
Buffer.from(derivedKey.slice(16, 32)),
|
|
18257
|
+
ciphertext
|
|
18258
|
+
]);
|
|
18197
18259
|
const hashFn = checksum.function === "sha256" ? sha256$1 : keccak256;
|
|
18198
18260
|
const calculatedMac = hashFn(toHex(checksumBuffer));
|
|
18199
18261
|
if (calculatedMac.replace(/^0x/, "") !== checksum.message.toLowerCase()) {
|
|
@@ -18228,7 +18290,9 @@ class Encryption {
|
|
|
18228
18290
|
OperatorPublicKeyValidator$1(operatorPublicKey);
|
|
18229
18291
|
const forgeEncrypt = new ForgeEncrypt();
|
|
18230
18292
|
forgeEncrypt.setPublicKey(operatorPublicKey);
|
|
18231
|
-
const encryptedPrivateKey = forgeEncrypt.encrypt(
|
|
18293
|
+
const encryptedPrivateKey = forgeEncrypt.encrypt(
|
|
18294
|
+
this.shares[idx].privateKey
|
|
18295
|
+
);
|
|
18232
18296
|
if (!encryptedPrivateKey) {
|
|
18233
18297
|
throw new OperatorPublicKeyError(
|
|
18234
18298
|
{
|
|
@@ -18319,10 +18383,18 @@ const operatorSortedList = (operators) => {
|
|
|
18319
18383
|
const validatedOperators = operators.map((operator) => {
|
|
18320
18384
|
const id = parseInt(`${operator.id}`, 10);
|
|
18321
18385
|
if (isNaN(id)) {
|
|
18322
|
-
throw new OperatorsCountsMismatchError(
|
|
18386
|
+
throw new OperatorsCountsMismatchError(
|
|
18387
|
+
ids,
|
|
18388
|
+
operatorKeys,
|
|
18389
|
+
`Invalid operator ID: ${operator.id}`
|
|
18390
|
+
);
|
|
18323
18391
|
}
|
|
18324
18392
|
if (!operator.operatorKey) {
|
|
18325
|
-
throw new OperatorsCountsMismatchError(
|
|
18393
|
+
throw new OperatorsCountsMismatchError(
|
|
18394
|
+
ids,
|
|
18395
|
+
operatorKeys,
|
|
18396
|
+
`Operator key is missing for operator ID: ${id}`
|
|
18397
|
+
);
|
|
18326
18398
|
}
|
|
18327
18399
|
return { ...operator, id };
|
|
18328
18400
|
});
|
|
@@ -18344,14 +18416,18 @@ class SingleSharesSignatureInvalid extends SSVKeysException {
|
|
|
18344
18416
|
}
|
|
18345
18417
|
}
|
|
18346
18418
|
const hexArrayToBytes = (hexArr) => {
|
|
18347
|
-
const uint8Array = new Uint8Array(
|
|
18419
|
+
const uint8Array = new Uint8Array(
|
|
18420
|
+
hexArr.flatMap((hex) => Array.from(toBytes(hex)))
|
|
18421
|
+
);
|
|
18348
18422
|
return Buffer.from(uint8Array);
|
|
18349
18423
|
};
|
|
18350
18424
|
const buildSignature = async (dataToSign, privateKeyHex) => {
|
|
18351
18425
|
if (!bls.deserializeHexStrToSecretKey) {
|
|
18352
18426
|
await bls.init(bls.BLS12_381);
|
|
18353
18427
|
}
|
|
18354
|
-
const privateKey = bls.deserializeHexStrToSecretKey(
|
|
18428
|
+
const privateKey = bls.deserializeHexStrToSecretKey(
|
|
18429
|
+
privateKeyHex.replace("0x", "")
|
|
18430
|
+
);
|
|
18355
18431
|
const messageHash = keccak256(toBytes(dataToSign));
|
|
18356
18432
|
const messageBytes = fromHex(messageHash, "bytes");
|
|
18357
18433
|
const signature = privateKey.sign(messageBytes);
|
|
@@ -18359,12 +18435,19 @@ const buildSignature = async (dataToSign, privateKeyHex) => {
|
|
|
18359
18435
|
return `0x${signatureHex}`;
|
|
18360
18436
|
};
|
|
18361
18437
|
const validateSignature = async (signedData, signatureHex, publicKey) => {
|
|
18362
|
-
const blsPublicKey = bls.deserializeHexStrToPublicKey(
|
|
18363
|
-
|
|
18438
|
+
const blsPublicKey = bls.deserializeHexStrToPublicKey(
|
|
18439
|
+
publicKey.replace("0x", "")
|
|
18440
|
+
);
|
|
18441
|
+
const signature = bls.deserializeHexStrToSignature(
|
|
18442
|
+
signatureHex.replace("0x", "")
|
|
18443
|
+
);
|
|
18364
18444
|
const messageHashHex = keccak256(toBytes(signedData));
|
|
18365
18445
|
const messageHashBytes = fromHex(messageHashHex, "bytes");
|
|
18366
18446
|
if (!blsPublicKey.verify(signature, messageHashBytes)) {
|
|
18367
|
-
throw new SingleSharesSignatureInvalid(
|
|
18447
|
+
throw new SingleSharesSignatureInvalid(
|
|
18448
|
+
signatureHex,
|
|
18449
|
+
"Single shares signature is invalid"
|
|
18450
|
+
);
|
|
18368
18451
|
}
|
|
18369
18452
|
};
|
|
18370
18453
|
const privateToPublicKey = async (privateKey) => {
|
|
@@ -18386,11 +18469,17 @@ let OpeatorsListValidatorConstraint = class {
|
|
|
18386
18469
|
const operatorIds = /* @__PURE__ */ new Set(), operatorPublicKeys = /* @__PURE__ */ new Set();
|
|
18387
18470
|
for (const operator of operatorsList || []) {
|
|
18388
18471
|
if (operatorIds.has(operator.id)) {
|
|
18389
|
-
throw new DuplicatedOperatorIdError(
|
|
18472
|
+
throw new DuplicatedOperatorIdError(
|
|
18473
|
+
operator,
|
|
18474
|
+
`The operator ID '${operator.id}' is duplicated in the list`
|
|
18475
|
+
);
|
|
18390
18476
|
}
|
|
18391
18477
|
operatorIds.add(operator.id);
|
|
18392
18478
|
if (operatorPublicKeys.has(operator.operatorKey)) {
|
|
18393
|
-
throw new DuplicatedOperatorPublicKeyError(
|
|
18479
|
+
throw new DuplicatedOperatorPublicKeyError(
|
|
18480
|
+
operator,
|
|
18481
|
+
`The public key for operator ID ${operator.id} is duplicated in the list`
|
|
18482
|
+
);
|
|
18394
18483
|
}
|
|
18395
18484
|
operatorPublicKeys.add(operator.operatorKey);
|
|
18396
18485
|
}
|
|
@@ -18428,10 +18517,15 @@ let PublicKeyValidatorConstraint = class {
|
|
|
18428
18517
|
if (typeof value === "string") {
|
|
18429
18518
|
bls.deserializeHexStrToPublicKey(value.replace("0x", ""));
|
|
18430
18519
|
} else {
|
|
18431
|
-
value.forEach(
|
|
18520
|
+
value.forEach(
|
|
18521
|
+
(item) => bls.deserializeHexStrToPublicKey(item.replace("0x", ""))
|
|
18522
|
+
);
|
|
18432
18523
|
}
|
|
18433
18524
|
} catch (e) {
|
|
18434
|
-
throw new BLSDeserializeError(
|
|
18525
|
+
throw new BLSDeserializeError(
|
|
18526
|
+
value,
|
|
18527
|
+
"Failed to BLS deserialize validator public key"
|
|
18528
|
+
);
|
|
18435
18529
|
}
|
|
18436
18530
|
return true;
|
|
18437
18531
|
}
|
|
@@ -18471,7 +18565,10 @@ let OwnerAddressValidatorConstraint = class {
|
|
|
18471
18565
|
try {
|
|
18472
18566
|
getAddress(value);
|
|
18473
18567
|
} catch {
|
|
18474
|
-
throw new OwnerAddressFormatError(
|
|
18568
|
+
throw new OwnerAddressFormatError(
|
|
18569
|
+
value,
|
|
18570
|
+
"Owner address is not a valid Ethereum address"
|
|
18571
|
+
);
|
|
18475
18572
|
}
|
|
18476
18573
|
return true;
|
|
18477
18574
|
}
|
|
@@ -18504,7 +18601,10 @@ var __decorateClass$5 = (decorators, target, key, kind) => {
|
|
|
18504
18601
|
let OwnerNonceValidatorConstraint = class {
|
|
18505
18602
|
validate(value) {
|
|
18506
18603
|
if (!Number.isInteger(value) || value < 0) {
|
|
18507
|
-
throw new OwnerNonceFormatError(
|
|
18604
|
+
throw new OwnerNonceFormatError(
|
|
18605
|
+
value,
|
|
18606
|
+
"Owner nonce is not positive integer"
|
|
18607
|
+
);
|
|
18508
18608
|
}
|
|
18509
18609
|
return true;
|
|
18510
18610
|
}
|
|
@@ -18541,12 +18641,20 @@ let MatchLengthValidatorConstraint = class {
|
|
|
18541
18641
|
if (!Array.isArray(value)) {
|
|
18542
18642
|
Object.values(value).forEach((arr) => {
|
|
18543
18643
|
if (relatedLength !== arr.length) {
|
|
18544
|
-
throw new OperatorsCountsMismatchError(
|
|
18644
|
+
throw new OperatorsCountsMismatchError(
|
|
18645
|
+
args.object[relatedPropertyName],
|
|
18646
|
+
value,
|
|
18647
|
+
customError.message
|
|
18648
|
+
);
|
|
18545
18649
|
}
|
|
18546
18650
|
});
|
|
18547
18651
|
} else {
|
|
18548
18652
|
if (relatedLength !== value.length) {
|
|
18549
|
-
throw new OperatorsCountsMismatchError(
|
|
18653
|
+
throw new OperatorsCountsMismatchError(
|
|
18654
|
+
args.object[relatedPropertyName],
|
|
18655
|
+
value,
|
|
18656
|
+
customError.message
|
|
18657
|
+
);
|
|
18550
18658
|
}
|
|
18551
18659
|
}
|
|
18552
18660
|
return true;
|
|
@@ -18726,7 +18834,10 @@ const _KeySharesItem = class _KeySharesItem2 {
|
|
|
18726
18834
|
async buildPayload(metaData, toSignatureData) {
|
|
18727
18835
|
const { ownerAddress, ownerNonce, privateKey } = toSignatureData;
|
|
18728
18836
|
if (!Number.isInteger(ownerNonce) || ownerNonce < 0) {
|
|
18729
|
-
throw new OwnerNonceFormatError(
|
|
18837
|
+
throw new OwnerNonceFormatError(
|
|
18838
|
+
ownerNonce,
|
|
18839
|
+
"Owner nonce is not positive integer"
|
|
18840
|
+
);
|
|
18730
18841
|
}
|
|
18731
18842
|
let address;
|
|
18732
18843
|
try {
|
|
@@ -18739,10 +18850,15 @@ const _KeySharesItem = class _KeySharesItem2 {
|
|
|
18739
18850
|
}
|
|
18740
18851
|
const payload = this.payload.build({
|
|
18741
18852
|
publicKey: metaData.publicKey,
|
|
18742
|
-
operatorIds: operatorSortedList(metaData.operators).map(
|
|
18853
|
+
operatorIds: operatorSortedList(metaData.operators).map(
|
|
18854
|
+
(operator) => operator.id
|
|
18855
|
+
),
|
|
18743
18856
|
encryptedShares: metaData.encryptedShares
|
|
18744
18857
|
});
|
|
18745
|
-
const signature = await buildSignature(
|
|
18858
|
+
const signature = await buildSignature(
|
|
18859
|
+
`${address}:${ownerNonce}`,
|
|
18860
|
+
privateKey
|
|
18861
|
+
);
|
|
18746
18862
|
const signSharesBytes = hexArrayToBytes([signature, payload.sharesData]);
|
|
18747
18863
|
payload.sharesData = `0x${signSharesBytes.toString("hex")}`;
|
|
18748
18864
|
await this.validateSingleShares(payload.sharesData, {
|
|
@@ -18755,11 +18871,18 @@ const _KeySharesItem = class _KeySharesItem2 {
|
|
|
18755
18871
|
async validateSingleShares(shares, fromSignatureData) {
|
|
18756
18872
|
const { ownerAddress, ownerNonce, publicKey } = fromSignatureData;
|
|
18757
18873
|
if (!Number.isInteger(ownerNonce) || ownerNonce < 0) {
|
|
18758
|
-
throw new OwnerNonceFormatError(
|
|
18874
|
+
throw new OwnerNonceFormatError(
|
|
18875
|
+
ownerNonce,
|
|
18876
|
+
"Owner nonce is not positive integer"
|
|
18877
|
+
);
|
|
18759
18878
|
}
|
|
18760
18879
|
const address = getAddress(ownerAddress);
|
|
18761
18880
|
const signaturePt = shares.replace("0x", "").substring(0, SIGNATURE_LENGTH);
|
|
18762
|
-
await validateSignature(
|
|
18881
|
+
await validateSignature(
|
|
18882
|
+
`${address}:${ownerNonce}`,
|
|
18883
|
+
`0x${signaturePt}`,
|
|
18884
|
+
publicKey
|
|
18885
|
+
);
|
|
18763
18886
|
}
|
|
18764
18887
|
/**
|
|
18765
18888
|
* Build shares from bytes string and operators list length
|
|
@@ -18776,7 +18899,9 @@ const _KeySharesItem = class _KeySharesItem2 {
|
|
|
18776
18899
|
const sharesPt = bytes.slice(2 + SIGNATURE_LENGTH);
|
|
18777
18900
|
const pkSplit = sharesPt.substring(0, operatorCount * PUBLIC_KEY_LENGTH);
|
|
18778
18901
|
const pkBytes = toBytes("0x" + pkSplit);
|
|
18779
|
-
const sharesPublicKeys = this.splitArray(operatorCount, pkBytes).map(
|
|
18902
|
+
const sharesPublicKeys = this.splitArray(operatorCount, pkBytes).map(
|
|
18903
|
+
(item) => toHex(item)
|
|
18904
|
+
);
|
|
18780
18905
|
const eSplit = bytes.substring(operatorCount * PUBLIC_KEY_LENGTH);
|
|
18781
18906
|
const eBytes = toBytes("0x" + eSplit);
|
|
18782
18907
|
const encryptedKeys = this.splitArray(operatorCount, eBytes).map(
|
|
@@ -18878,7 +19003,10 @@ class SSVKeys {
|
|
|
18878
19003
|
*/
|
|
18879
19004
|
async createThreshold(privateKey, operators) {
|
|
18880
19005
|
const sortedOperators = operatorSortedList(operators);
|
|
18881
|
-
this.threshold = await new Threshold().create(
|
|
19006
|
+
this.threshold = await new Threshold().create(
|
|
19007
|
+
privateKey,
|
|
19008
|
+
sortedOperators.map((item) => item.id)
|
|
19009
|
+
);
|
|
18882
19010
|
return this.threshold;
|
|
18883
19011
|
}
|
|
18884
19012
|
/**
|
|
@@ -18888,7 +19016,9 @@ class SSVKeys {
|
|
|
18888
19016
|
*/
|
|
18889
19017
|
async encryptShares(operators, shares) {
|
|
18890
19018
|
const sortedOperators = operatorSortedList(operators);
|
|
18891
|
-
const decodedOperatorPublicKeys = sortedOperators.map(
|
|
19019
|
+
const decodedOperatorPublicKeys = sortedOperators.map(
|
|
19020
|
+
(item) => Buffer.from(item.operatorKey, "base64").toString()
|
|
19021
|
+
);
|
|
18892
19022
|
return new Encryption(decodedOperatorPublicKeys, shares).encrypt();
|
|
18893
19023
|
}
|
|
18894
19024
|
/**
|
|
@@ -18924,7 +19054,10 @@ class SSVKeys {
|
|
|
18924
19054
|
let signatureErrorMessage = "";
|
|
18925
19055
|
let errorMessage = "";
|
|
18926
19056
|
try {
|
|
18927
|
-
const restoredShares = keySharesItem.buildSharesFromBytes(
|
|
19057
|
+
const restoredShares = keySharesItem.buildSharesFromBytes(
|
|
19058
|
+
shares,
|
|
19059
|
+
operatorsCount
|
|
19060
|
+
);
|
|
18928
19061
|
const { sharesPublicKeys, encryptedKeys } = restoredShares;
|
|
18929
19062
|
restoredSharesPublicKeys = sharesPublicKeys;
|
|
18930
19063
|
restoredSharesEncryptedKeys = encryptedKeys;
|
|
@@ -18934,7 +19067,11 @@ class SSVKeys {
|
|
|
18934
19067
|
errorMessage = "Can not extract shares from bytes";
|
|
18935
19068
|
}
|
|
18936
19069
|
if (!sharesError && !errorMessage) {
|
|
18937
|
-
const signatureData = {
|
|
19070
|
+
const signatureData = {
|
|
19071
|
+
ownerNonce,
|
|
19072
|
+
publicKey: validatorPublicKey,
|
|
19073
|
+
ownerAddress
|
|
19074
|
+
};
|
|
18938
19075
|
try {
|
|
18939
19076
|
await keySharesItem.validateSingleShares(shares, signatureData);
|
|
18940
19077
|
} catch (e) {
|
|
@@ -18957,12 +19094,14 @@ class SSVKeys {
|
|
|
18957
19094
|
isSharesValid: !sharesError,
|
|
18958
19095
|
sharesPublicKeys: restoredSharesPublicKeys,
|
|
18959
19096
|
encryptedKeys: restoredSharesEncryptedKeys,
|
|
18960
|
-
memo: !!sharesError || !!signatureError ? [
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
|
|
19097
|
+
memo: !!sharesError || !!signatureError ? [
|
|
19098
|
+
{
|
|
19099
|
+
message: errorMessage,
|
|
19100
|
+
error: sharesError || signatureError,
|
|
19101
|
+
data: `${sharesErrorMessage}${signatureErrorMessage ? ". " + signatureErrorMessage : ""}`,
|
|
19102
|
+
blockNumber
|
|
19103
|
+
}
|
|
19104
|
+
] : []
|
|
18966
19105
|
};
|
|
18967
19106
|
}
|
|
18968
19107
|
}
|
|
@@ -19262,6 +19401,8 @@ let SemVer$2 = class SemVer {
|
|
|
19262
19401
|
this.inc("patch", identifier, identifierBase);
|
|
19263
19402
|
this.inc("pre", identifier, identifierBase);
|
|
19264
19403
|
break;
|
|
19404
|
+
// If the input is a non-prerelease version, this acts the same as
|
|
19405
|
+
// prepatch.
|
|
19265
19406
|
case "prerelease":
|
|
19266
19407
|
if (this.prerelease.length === 0) {
|
|
19267
19408
|
this.inc("patch", identifier, identifierBase);
|
|
@@ -19295,6 +19436,8 @@ let SemVer$2 = class SemVer {
|
|
|
19295
19436
|
}
|
|
19296
19437
|
this.prerelease = [];
|
|
19297
19438
|
break;
|
|
19439
|
+
// This probably shouldn't be used publicly.
|
|
19440
|
+
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
|
|
19298
19441
|
case "pre": {
|
|
19299
19442
|
const base = Number(identifierBase) ? 1 : 0;
|
|
19300
19443
|
if (this.prerelease.length === 0) {
|
|
@@ -19451,10 +19594,10 @@ __decorateClass([
|
|
|
19451
19594
|
], _KeyShares.prototype, "shares");
|
|
19452
19595
|
let KeyShares = _KeyShares;
|
|
19453
19596
|
export {
|
|
19454
|
-
|
|
19597
|
+
KeyShares as K,
|
|
19455
19598
|
OperatorPublicKeyError as O,
|
|
19456
19599
|
SSVKeys as S,
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19600
|
+
KeySharesItem as a,
|
|
19601
|
+
OperatorsCountsMismatchError as b,
|
|
19602
|
+
SSVKeysException as c
|
|
19460
19603
|
};
|