@obolnetwork/obol-sdk 2.12.6 → 2.13.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.
@@ -124,7 +124,7 @@ var ClusterLockValidationTimeoutError = class _ClusterLockValidationTimeoutError
124
124
  };
125
125
 
126
126
  // src/verification/common.ts
127
- var import_ssz7 = require("@chainsafe/ssz");
127
+ var import_ssz8 = require("@chainsafe/ssz");
128
128
  var import_elliptic = __toESM(require("elliptic"));
129
129
 
130
130
  // src/types.ts
@@ -154,7 +154,7 @@ var import_ethers = require("ethers");
154
154
  // package.json
155
155
  var package_default = {
156
156
  name: "@obolnetwork/obol-sdk",
157
- version: "2.12.6",
157
+ version: "2.13.0",
158
158
  description: "A package for creating Distributed Validators using the Obol API.",
159
159
  bugs: {
160
160
  url: "https://github.com/obolnetwork/obol-sdk/issues"
@@ -575,10 +575,25 @@ var operatorContainerType = new import_ssz.ContainerType({
575
575
  config_signature: new import_ssz.ByteVectorType(65),
576
576
  enr_signature: new import_ssz.ByteVectorType(65)
577
577
  });
578
+ var k1SignatureListType = new import_ssz.ListCompositeType(
579
+ new import_ssz.ByteVectorType(65),
580
+ 32
581
+ );
582
+ var operatorContainerTypeV1X11 = new import_ssz.ContainerType({
583
+ address: new import_ssz.ByteVectorType(20),
584
+ enr: new import_ssz.ByteListType(1024),
585
+ // This needs to be dynamic, since ENRs do not have a fixed length.
586
+ config_signature: k1SignatureListType,
587
+ enr_signature: k1SignatureListType
588
+ });
578
589
  var creatorContainerType = new import_ssz.ContainerType({
579
590
  address: new import_ssz.ByteVectorType(20),
580
591
  config_signature: new import_ssz.ByteVectorType(65)
581
592
  });
593
+ var creatorContainerTypeV1X11 = new import_ssz.ContainerType({
594
+ address: new import_ssz.ByteVectorType(20),
595
+ config_signature: k1SignatureListType
596
+ });
582
597
  var validatorsContainerType = new import_ssz.ContainerType({
583
598
  fee_recipient_address: new import_ssz.ByteVectorType(20),
584
599
  withdrawal_address: new import_ssz.ByteVectorType(20)
@@ -586,9 +601,15 @@ var validatorsContainerType = new import_ssz.ContainerType({
586
601
  var newCreatorContainerType = (configOnly) => {
587
602
  return configOnly ? creatorAddressWrapperType : creatorContainerType;
588
603
  };
604
+ var newCreatorContainerTypeV1X11 = (configOnly) => {
605
+ return configOnly ? creatorAddressWrapperType : creatorContainerTypeV1X11;
606
+ };
589
607
  var newOperatorContainerType = (configOnly) => {
590
608
  return configOnly ? operatorAddressWrapperType : operatorContainerType;
591
609
  };
610
+ var newOperatorContainerTypeV1X11 = (configOnly) => {
611
+ return configOnly ? operatorAddressWrapperType : operatorContainerTypeV1X11;
612
+ };
592
613
  var depositDataContainer = new import_ssz.ContainerType({
593
614
  pubkey: new import_ssz.ByteVectorType(48),
594
615
  withdrawal_credentials: new import_ssz.ByteVectorType(32),
@@ -14343,6 +14364,165 @@ var hashClusterLockV1X10 = (cluster) => {
14343
14364
  };
14344
14365
  var verifyDVV1X10 = verifyDVV1X8;
14345
14366
 
14367
+ // src/verification/v1.11.0.ts
14368
+ var import_uint5 = require("@chainsafe/ssz/lib/type/uint.js");
14369
+ var import_ssz7 = require("@chainsafe/ssz");
14370
+ var splitK1SignatureList = (signature) => {
14371
+ const bytes = (0, import_ssz7.fromHexString)(signature);
14372
+ if (bytes.length === 0) return [];
14373
+ if (bytes.length % 65 !== 0) {
14374
+ throw new Error("Signature length must be a multiple of 65 bytes");
14375
+ }
14376
+ const chunks = [];
14377
+ for (let i = 0; i < bytes.length; i += 65) {
14378
+ chunks.push(bytes.slice(i, i + 65));
14379
+ }
14380
+ return chunks;
14381
+ };
14382
+ var clusterDefinitionContainerTypeV1X11 = (configOnly) => {
14383
+ let returnedContainerType = {
14384
+ uuid: new import_ssz7.ByteListType(64),
14385
+ name: new import_ssz7.ByteListType(256),
14386
+ version: new import_ssz7.ByteListType(16),
14387
+ timestamp: new import_ssz7.ByteListType(32),
14388
+ num_validators: new import_uint5.UintNumberType(8),
14389
+ threshold: new import_uint5.UintNumberType(8),
14390
+ dkg_algorithm: new import_ssz7.ByteListType(32),
14391
+ fork_version: new import_ssz7.ByteVectorType(4),
14392
+ operators: new import_ssz7.ListCompositeType(
14393
+ newOperatorContainerTypeV1X11(configOnly),
14394
+ 256
14395
+ ),
14396
+ creator: newCreatorContainerTypeV1X11(configOnly),
14397
+ validators: new import_ssz7.ListCompositeType(validatorsContainerType, 65536),
14398
+ deposit_amounts: new import_ssz7.ListBasicType(
14399
+ new import_uint5.UintNumberType(8),
14400
+ 256
14401
+ ),
14402
+ consensus_protocol: new import_ssz7.ByteListType(256),
14403
+ target_gas_limit: new import_uint5.UintNumberType(8),
14404
+ compounding: new import_ssz7.BooleanType()
14405
+ };
14406
+ if (!configOnly) {
14407
+ returnedContainerType = __spreadProps(__spreadValues({}, returnedContainerType), {
14408
+ config_hash: new import_ssz7.ByteVectorType(32)
14409
+ });
14410
+ }
14411
+ return new import_ssz7.ContainerType(returnedContainerType);
14412
+ };
14413
+ var hashClusterDefinitionV1X11 = (cluster, configOnly) => {
14414
+ const definitionType = clusterDefinitionContainerTypeV1X11(configOnly);
14415
+ const val = definitionType.defaultValue();
14416
+ val.uuid = strToUint8Array(cluster.uuid);
14417
+ val.name = strToUint8Array(cluster.name);
14418
+ val.version = strToUint8Array(cluster.version);
14419
+ val.timestamp = strToUint8Array(cluster.timestamp);
14420
+ val.num_validators = cluster.num_validators;
14421
+ val.threshold = cluster.threshold;
14422
+ val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
14423
+ val.fork_version = (0, import_ssz7.fromHexString)(cluster.fork_version);
14424
+ val.operators = cluster.operators.map((operator) => {
14425
+ return configOnly ? { address: (0, import_ssz7.fromHexString)(operator.address) } : {
14426
+ address: (0, import_ssz7.fromHexString)(operator.address),
14427
+ enr: strToUint8Array(operator.enr),
14428
+ config_signature: splitK1SignatureList(
14429
+ operator.config_signature
14430
+ ),
14431
+ enr_signature: splitK1SignatureList(operator.enr_signature)
14432
+ };
14433
+ });
14434
+ val.creator = configOnly ? { address: (0, import_ssz7.fromHexString)(cluster.creator.address) } : {
14435
+ address: (0, import_ssz7.fromHexString)(cluster.creator.address),
14436
+ config_signature: splitK1SignatureList(
14437
+ cluster.creator.config_signature
14438
+ )
14439
+ };
14440
+ val.validators = cluster.validators.map((validator) => {
14441
+ return {
14442
+ fee_recipient_address: (0, import_ssz7.fromHexString)(validator.fee_recipient_address),
14443
+ withdrawal_address: (0, import_ssz7.fromHexString)(validator.withdrawal_address)
14444
+ };
14445
+ });
14446
+ if (cluster.deposit_amounts) {
14447
+ val.deposit_amounts = cluster.deposit_amounts.map((amount) => {
14448
+ return parseInt(amount);
14449
+ });
14450
+ }
14451
+ if (cluster.consensus_protocol) {
14452
+ val.consensus_protocol = strToUint8Array(cluster.consensus_protocol);
14453
+ }
14454
+ if (cluster.target_gas_limit) {
14455
+ val.target_gas_limit = cluster.target_gas_limit;
14456
+ }
14457
+ if (cluster.compounding) {
14458
+ val.compounding = cluster.compounding;
14459
+ }
14460
+ if (!configOnly) {
14461
+ val.config_hash = (0, import_ssz7.fromHexString)(cluster.config_hash);
14462
+ }
14463
+ return val;
14464
+ };
14465
+ var dvContainerTypeV1X11 = new import_ssz7.ContainerType({
14466
+ distributed_public_key: new import_ssz7.ByteVectorType(48),
14467
+ public_shares: new import_ssz7.ListCompositeType(new import_ssz7.ByteVectorType(48), 256),
14468
+ partial_deposit_data: new import_ssz7.ListCompositeType(depositDataContainer, 256),
14469
+ builder_registration: builderRegistrationContainer
14470
+ });
14471
+ var clusterLockContainerTypeV1X11 = () => {
14472
+ return new import_ssz7.ContainerType({
14473
+ cluster_definition: clusterDefinitionContainerTypeV1X11(false),
14474
+ distributed_validators: new import_ssz7.ListCompositeType(dvContainerTypeV1X11, 65536)
14475
+ });
14476
+ };
14477
+ var hashClusterLockV1X11 = (cluster) => {
14478
+ const lockType = clusterLockContainerTypeV1X11();
14479
+ const val = lockType.defaultValue();
14480
+ val.cluster_definition = hashClusterDefinitionV1X11(
14481
+ cluster.cluster_definition,
14482
+ false
14483
+ );
14484
+ val.distributed_validators = cluster.distributed_validators.map(
14485
+ (dValidator) => {
14486
+ var _a6, _b2, _c, _d, _e;
14487
+ return {
14488
+ distributed_public_key: (0, import_ssz7.fromHexString)(
14489
+ dValidator.distributed_public_key
14490
+ ),
14491
+ public_shares: dValidator.public_shares.map(
14492
+ (publicShare) => (0, import_ssz7.fromHexString)(publicShare)
14493
+ ),
14494
+ partial_deposit_data: dValidator.partial_deposit_data.map((depositData) => {
14495
+ return {
14496
+ pubkey: (0, import_ssz7.fromHexString)(depositData.pubkey),
14497
+ withdrawal_credentials: (0, import_ssz7.fromHexString)(
14498
+ depositData.withdrawal_credentials
14499
+ ),
14500
+ amount: parseInt(depositData.amount),
14501
+ signature: (0, import_ssz7.fromHexString)(depositData.signature)
14502
+ };
14503
+ }),
14504
+ builder_registration: {
14505
+ message: {
14506
+ fee_recipient: (0, import_ssz7.fromHexString)(
14507
+ (_a6 = dValidator.builder_registration) == null ? void 0 : _a6.message.fee_recipient
14508
+ ),
14509
+ gas_limit: (_b2 = dValidator.builder_registration) == null ? void 0 : _b2.message.gas_limit,
14510
+ timestamp: (_c = dValidator.builder_registration) == null ? void 0 : _c.message.timestamp,
14511
+ pubkey: (0, import_ssz7.fromHexString)(
14512
+ (_d = dValidator.builder_registration) == null ? void 0 : _d.message.pubkey
14513
+ )
14514
+ },
14515
+ signature: (0, import_ssz7.fromHexString)(
14516
+ (_e = dValidator.builder_registration) == null ? void 0 : _e.signature
14517
+ )
14518
+ }
14519
+ };
14520
+ }
14521
+ );
14522
+ return "0x" + Buffer.from(lockType.hashTreeRoot(val).buffer).toString("hex");
14523
+ };
14524
+ var verifyDVV1X11 = verifyDVV1X8;
14525
+
14346
14526
  // src/verification/common.ts
14347
14527
  var clusterConfigOrDefinitionHash = (cluster, configOnly) => {
14348
14528
  let definitionType, val;
@@ -14367,6 +14547,11 @@ var clusterConfigOrDefinitionHash = (cluster, configOnly) => {
14367
14547
  const x = "0x" + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString("hex");
14368
14548
  return x;
14369
14549
  }
14550
+ if (semver.eq(cluster.version, "v1.11.0")) {
14551
+ definitionType = clusterDefinitionContainerTypeV1X11(configOnly);
14552
+ val = hashClusterDefinitionV1X11(cluster, configOnly);
14553
+ return "0x" + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString("hex");
14554
+ }
14370
14555
  throw new Error("unsupported version");
14371
14556
  };
14372
14557
  var clusterLockHash = (clusterLock) => {
@@ -14392,6 +14577,9 @@ var clusterLockHash = (clusterLock) => {
14392
14577
  if (semver.eq(clusterLock.cluster_definition.version, "v1.10.0")) {
14393
14578
  return hashClusterLockV1X10(clusterLock);
14394
14579
  }
14580
+ if (semver.eq(clusterLock.cluster_definition.version, "v1.11.0")) {
14581
+ return hashClusterLockV1X11(clusterLock);
14582
+ }
14395
14583
  throw new Error("unsupported version");
14396
14584
  };
14397
14585
  var validatePOSTConfigHashSigner = (address, signature, configHash, chainId, safeRpcUrl) => __async(null, null, function* () {
@@ -14491,8 +14679,8 @@ var computeSigningRoot = (sszObjectRoot, domain) => {
14491
14679
  };
14492
14680
  var computeDepositMsgRoot = (msg) => {
14493
14681
  const depositMsgVal = depositMessageType.defaultValue();
14494
- depositMsgVal.pubkey = (0, import_ssz7.fromHexString)(msg.pubkey);
14495
- depositMsgVal.withdrawal_credentials = (0, import_ssz7.fromHexString)(
14682
+ depositMsgVal.pubkey = (0, import_ssz8.fromHexString)(msg.pubkey);
14683
+ depositMsgVal.withdrawal_credentials = (0, import_ssz8.fromHexString)(
14496
14684
  msg.withdrawal_credentials
14497
14685
  );
14498
14686
  depositMsgVal.amount = parseInt(msg.amount);
@@ -14506,16 +14694,16 @@ var computeForkDataRoot = (currentVersion, genesisValidatorsRoot) => {
14506
14694
  };
14507
14695
  var computebuilderRegistrationMsgRoot = (msg) => {
14508
14696
  const builderRegistrationMsgVal = builderRegistrationMessageType.defaultValue();
14509
- builderRegistrationMsgVal.fee_recipient = (0, import_ssz7.fromHexString)(msg.fee_recipient);
14697
+ builderRegistrationMsgVal.fee_recipient = (0, import_ssz8.fromHexString)(msg.fee_recipient);
14510
14698
  builderRegistrationMsgVal.gas_limit = msg.gas_limit;
14511
14699
  builderRegistrationMsgVal.timestamp = msg.timestamp;
14512
- builderRegistrationMsgVal.pubkey = (0, import_ssz7.fromHexString)(msg.pubkey);
14700
+ builderRegistrationMsgVal.pubkey = (0, import_ssz8.fromHexString)(msg.pubkey);
14513
14701
  return Buffer.from(
14514
14702
  builderRegistrationMessageType.hashTreeRoot(builderRegistrationMsgVal).buffer
14515
14703
  );
14516
14704
  };
14517
- var computeDomain = (domainType, lockForkVersion, genesisValidatorsRoot = (0, import_ssz7.fromHexString)(GENESIS_VALIDATOR_ROOT)) => {
14518
- const forkVersion = (0, import_ssz7.fromHexString)(
14705
+ var computeDomain = (domainType, lockForkVersion, genesisValidatorsRoot = (0, import_ssz8.fromHexString)(GENESIS_VALIDATOR_ROOT)) => {
14706
+ const forkVersion = (0, import_ssz8.fromHexString)(
14519
14707
  lockForkVersion.substring(2, lockForkVersion.length)
14520
14708
  );
14521
14709
  const forkDataRoot = computeForkDataRoot(forkVersion, genesisValidatorsRoot);
@@ -14524,10 +14712,10 @@ var computeDomain = (domainType, lockForkVersion, genesisValidatorsRoot = (0, im
14524
14712
  domain.set(forkDataRoot.subarray(0, 28), 4);
14525
14713
  return domain;
14526
14714
  };
14527
- var depositDomainForFork = (forkVersion) => computeDomain((0, import_ssz7.fromHexString)(DOMAIN_DEPOSIT), forkVersion);
14528
- var builderDomainForFork = (forkVersion) => computeDomain((0, import_ssz7.fromHexString)(DOMAIN_APPLICATION_BUILDER), forkVersion);
14715
+ var depositDomainForFork = (forkVersion) => computeDomain((0, import_ssz8.fromHexString)(DOMAIN_DEPOSIT), forkVersion);
14716
+ var builderDomainForFork = (forkVersion) => computeDomain((0, import_ssz8.fromHexString)(DOMAIN_APPLICATION_BUILDER), forkVersion);
14529
14717
  var validateDepositDataStructure = (distributedPublicKey, depositData, withdrawalAddress, forkVersion, compounding, precomputedDepositDomain) => {
14530
- const depositDomain = precomputedDepositDomain != null ? precomputedDepositDomain : computeDomain((0, import_ssz7.fromHexString)(DOMAIN_DEPOSIT), forkVersion);
14718
+ const depositDomain = precomputedDepositDomain != null ? precomputedDepositDomain : computeDomain((0, import_ssz8.fromHexString)(DOMAIN_DEPOSIT), forkVersion);
14531
14719
  const withdrawalPrefix = compounding ? "0x02" : "0x01";
14532
14720
  const expectedWithdrawalCredentials = withdrawalPrefix + "0".repeat(22) + withdrawalAddress.toLowerCase().slice(2);
14533
14721
  if (expectedWithdrawalCredentials !== depositData.withdrawal_credentials) {
@@ -14554,14 +14742,14 @@ var depositBlsCheck = (distributedPublicKey, depositData, withdrawalAddress, for
14554
14742
  );
14555
14743
  if (!valid || !depositData.signature || !depositData.pubkey) return null;
14556
14744
  return {
14557
- pubkey: (0, import_ssz7.fromHexString)(depositData.pubkey),
14745
+ pubkey: (0, import_ssz8.fromHexString)(depositData.pubkey),
14558
14746
  message: message2,
14559
- signature: (0, import_ssz7.fromHexString)(depositData.signature)
14747
+ signature: (0, import_ssz8.fromHexString)(depositData.signature)
14560
14748
  };
14561
14749
  };
14562
14750
  var verifyBuilderRegistration = (validator, feeRecipientAddress, forkVersion, precomputedBuilderDomain) => {
14563
14751
  var _a6;
14564
- const builderDomain = precomputedBuilderDomain != null ? precomputedBuilderDomain : computeDomain((0, import_ssz7.fromHexString)(DOMAIN_APPLICATION_BUILDER), forkVersion);
14752
+ const builderDomain = precomputedBuilderDomain != null ? precomputedBuilderDomain : computeDomain((0, import_ssz8.fromHexString)(DOMAIN_APPLICATION_BUILDER), forkVersion);
14565
14753
  if (validator.distributed_public_key !== ((_a6 = validator.builder_registration) == null ? void 0 : _a6.message.pubkey)) {
14566
14754
  return {
14567
14755
  isValidBuilderRegistration: false,
@@ -14597,9 +14785,9 @@ var builderBlsCheck = (validator, feeRecipientAddress, forkVersion, precomputedB
14597
14785
  const sig = (_a6 = validator.builder_registration) == null ? void 0 : _a6.signature;
14598
14786
  if (!isValidBuilderRegistration || !sig) return null;
14599
14787
  return {
14600
- pubkey: (0, import_ssz7.fromHexString)(validator.distributed_public_key),
14788
+ pubkey: (0, import_ssz8.fromHexString)(validator.distributed_public_key),
14601
14789
  message: builderRegistrationMsg,
14602
- signature: (0, import_ssz7.fromHexString)(sig)
14790
+ signature: (0, import_ssz8.fromHexString)(sig)
14603
14791
  };
14604
14792
  };
14605
14793
  var verifyNodeSignatures = (clusterLock) => {
@@ -14641,6 +14829,9 @@ var verifyLockData = (clusterLock) => __async(null, null, function* () {
14641
14829
  if (semver.eq(clusterLock.cluster_definition.version, "v1.10.0")) {
14642
14830
  return yield verifyDVV1X10(clusterLock);
14643
14831
  }
14832
+ if (semver.eq(clusterLock.cluster_definition.version, "v1.11.0")) {
14833
+ return yield verifyDVV1X11(clusterLock);
14834
+ }
14644
14835
  return false;
14645
14836
  });
14646
14837
  var hasUniqueDistributedKeys = (clusterLock) => {