use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.
the class EpochUpdateConstraintScrypt method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(ValidatorStakeData.class, SubstateTypeId.VALIDATOR_STAKE_DATA.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var isRegistered = REFieldSerialization.deserializeBoolean(buf);
var amount = REFieldSerialization.deserializeUInt256(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var ownership = REFieldSerialization.deserializeUInt256(buf);
var rakePercentage = REFieldSerialization.deserializeInt(buf);
var ownerAddress = REFieldSerialization.deserializeAccountREAddr(buf);
return ValidatorStakeData.create(delegate, amount, ownership, rakePercentage, ownerAddress, isRegistered);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeBoolean(buf, s.isRegistered());
buf.put(s.amount().toByteArray());
REFieldSerialization.serializeKey(buf, s.validatorKey());
buf.put(s.totalOwnership().toByteArray());
buf.putInt(s.rakePercentage());
REFieldSerialization.serializeREAddr(buf, s.ownerAddr());
}, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> ValidatorStakeData.createVirtual((ECPublicKey) k)));
os.substate(new SubstateDefinition<>(StakeOwnership.class, SubstateTypeId.STAKE_OWNERSHIP.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var owner = REFieldSerialization.deserializeAccountREAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new StakeOwnership(delegate, owner, amount);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeKey(buf, s.delegateKey());
REFieldSerialization.serializeREAddr(buf, s.owner());
buf.put(s.amount().toByteArray());
}));
os.substate(new SubstateDefinition<>(ExitingStake.class, SubstateTypeId.EXITING_STAKE.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var epochUnlocked = REFieldSerialization.deserializeNonNegativeLong(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var owner = REFieldSerialization.deserializeAccountREAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new ExitingStake(epochUnlocked, delegate, owner, amount);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
buf.putLong(s.epochUnlocked());
REFieldSerialization.serializeKey(buf, s.delegateKey());
REFieldSerialization.serializeREAddr(buf, s.owner());
buf.put(s.amount().toByteArray());
}));
registerGenesisTransitions(os);
// Epoch update
epochUpdate(os);
}
use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.
the class RoundUpdateConstraintScrypt method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(ValidatorBFTData.class, SubstateTypeId.VALIDATOR_BFT_DATA.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var key = REFieldSerialization.deserializeKey(buf);
var proposalsCompleted = REFieldSerialization.deserializeNonNegativeLong(buf);
var proposalsMissed = REFieldSerialization.deserializeNonNegativeLong(buf);
return new ValidatorBFTData(key, proposalsCompleted, proposalsMissed);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeKey(buf, s.validatorKey());
buf.putLong(s.completedProposals());
buf.putLong(s.missedProposals());
}, (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k)));
os.procedure(new DownProcedure<>(VoidReducerState.class, RoundData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> ReducerResult.incomplete(new EndPrevRound(d))));
os.procedure(new DownProcedure<>(EndPrevRound.class, ValidatorBFTData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> {
var closedRound = s.getClosedRound().view();
var next = new StartValidatorBFTUpdate(closedRound);
next.beginUpdate(d);
return ReducerResult.incomplete(next);
}));
os.procedure(new DownProcedure<>(StartValidatorBFTUpdate.class, ValidatorBFTData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> ReducerResult.incomplete(s.beginUpdate(d))));
os.procedure(new UpProcedure<>(StartValidatorBFTUpdate.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> {
var next = s.exit();
return ReducerResult.incomplete(next.update(u, c));
}));
os.procedure(new UpProcedure<>(UpdatingValidatorBFTData.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.update(u, c))));
os.procedure(new UpProcedure<>(StartNextRound.class, RoundData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> {
s.update(u);
return ReducerResult.complete();
}));
}
use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.
the class MessageCentralValidatorSyncTest method when_send_error_response__then_message_central_will_send_error_response.
@Test
public void when_send_error_response__then_message_central_will_send_error_response() {
QuorumCertificate qc = mock(QuorumCertificate.class);
HighQC highQC = mock(HighQC.class);
when(highQC.highestQC()).thenReturn(qc);
when(highQC.highestCommittedQC()).thenReturn(qc);
BFTNode node = mock(BFTNode.class);
ECPublicKey ecPublicKey = mock(ECPublicKey.class);
when(node.getKey()).thenReturn(ecPublicKey);
final var request = new GetVerticesRequest(HashUtils.random256(), 3);
sync.verticesErrorResponseDispatcher().dispatch(node, new GetVerticesErrorResponse(highQC, request));
verify(messageCentral, times(1)).send(eq(NodeId.fromPublicKey(ecPublicKey)), any(GetVerticesErrorResponseMessage.class));
}
use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.
the class MessageCentralValidatorSyncTest method setUp.
@Before
public void setUp() {
this.self = mock(BFTNode.class);
ECPublicKey pubKey = mock(ECPublicKey.class);
when(self.getKey()).thenReturn(pubKey);
this.messageCentral = MessageCentralMockProvider.get();
this.hasher = new RandomHasher();
this.sync = new MessageCentralValidatorSync(messageCentral, hasher);
}
use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.
the class KeyVerifyTestScenarioRunner method doRunTestVector.
@Override
public void doRunTestVector(KeyVerifyTestVector testVector) throws AssertionError {
ECPublicKey publicKey = null;
try {
publicKey = ECPublicKey.fromBytes(fromHexString(testVector.input.publicKeyUncompressed));
} catch (Exception e) {
throw new AssertionError("Failed to construct public key from hex", e);
}
ECDSASignature signature = ECDSASignature.decodeFromDER(fromHexString(testVector.input.signatureDerEncoded));
byte[] hashedMessageToVerify = sha256Hash(fromHexString(testVector.input.msg));
assertEquals(testVector.expected.isValid, publicKey.verify(hashedMessageToVerify, signature));
}
Aggregations