use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.
the class MockStartValidatorKeyPairFactory method createKeyPairForValidator.
private BLSKeyPair createKeyPairForValidator(final int validatorIndex) {
final Bytes hash = Hash.sha256(uintToBytes32(validatorIndex));
final BigInteger privKey = hash.reverse().toUnsignedBigInteger().mod(CURVE_ORDER);
final Bytes32 privKeyBytes = Bytes32.leftPad(Bytes.of(privKey.toByteArray()));
return new BLSKeyPair(BLSSecretKey.fromBytes(privKeyBytes));
}
use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.
the class DataStructureUtil method randomDepositData.
public DepositData randomDepositData() {
BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(nextSeed());
BLSPublicKey pubkey = keyPair.getPublicKey();
Bytes32 withdrawal_credentials = randomBytes32();
DepositMessage proof_of_possession_data = new DepositMessage(pubkey, withdrawal_credentials, getMaxEffectiveBalance());
final Bytes32 domain = computeDomain();
final Bytes signing_root = getSigningRoot(proof_of_possession_data, domain);
BLSSignature proof_of_possession = BLS.sign(keyPair.getSecretKey(), signing_root);
return new DepositData(proof_of_possession_data, proof_of_possession);
}
use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.
the class DataStructureUtil method newDeposits.
public List<DepositWithIndex> newDeposits(int numDeposits) {
List<DepositWithIndex> deposits = new ArrayList<>();
final DepositGenerator depositGenerator = new DepositGenerator(spec);
for (int i = 0; i < numDeposits; i++) {
BLSKeyPair keypair = BLSTestUtil.randomKeyPair(i);
DepositData depositData = depositGenerator.createDepositData(keypair, getMaxEffectiveBalance(), keypair.getPublicKey());
DepositWithIndex deposit = new DepositWithIndex(Deposit.SSZ_SCHEMA.getProofSchema().getDefault(), depositData, UInt64.valueOf(i));
deposits.add(deposit);
}
return deposits;
}
use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.
the class MockStartBeaconStateGeneratorTest method shouldCreateInitialBeaconChainState.
@Test
public void shouldCreateInitialBeaconChainState() {
final UInt64 genesisTime = UInt64.valueOf(498294294824924924L);
final int validatorCount = 10;
final List<BLSKeyPair> validatorKeyPairs = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, validatorCount);
final List<DepositData> deposits = new MockStartDepositGenerator(spec).createDeposits(validatorKeyPairs);
final BeaconState initialBeaconState = new MockStartBeaconStateGenerator(spec).createInitialBeaconState(genesisTime, deposits, Optional.empty());
assertEquals(validatorCount, initialBeaconState.getValidators().size());
assertEquals(validatorCount, initialBeaconState.getEth1_data().getDeposit_count().longValue());
final List<BLSPublicKey> actualValidatorPublicKeys = initialBeaconState.getValidators().stream().map(Validator::getPubkeyBytes).map(BLSPublicKey::fromBytesCompressed).collect(Collectors.toList());
final List<BLSPublicKey> expectedValidatorPublicKeys = validatorKeyPairs.stream().map(BLSKeyPair::getPublicKey).collect(Collectors.toList());
assertEquals(expectedValidatorPublicKeys, actualValidatorPublicKeys);
}
use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.
the class InMemoryStorageSystemBuilder method build.
public StorageSystem build() {
final Database database;
switch(version) {
case LEVELDB_TREE:
database = createLevelDbTreeDatabase();
break;
// Leveldb only varies by db type which doesn't apply to in-memory
case LEVELDB2:
case V6:
database = createV6Database();
break;
// Leveldb only varies by db type which doesn't apply to in-memory
case LEVELDB1:
case V5:
database = createV5Database();
break;
case V4:
database = createV4Database();
break;
default:
throw new UnsupportedOperationException("Unsupported database version: " + version);
}
final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, numberOfValidators);
return StorageSystem.create(database, createRestartSupplier(), storageMode, storeConfig, spec, ChainBuilder.create(spec, validatorKeys));
}
Aggregations