use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class ConsensusHandlerTest method handleConsensusElectAcceptTest.
// handle an electAccept from node3 for the elect of node2
// This test need be run after the elect message was handled, else the messageId would be invalid
private void handleConsensusElectAcceptTest() throws DataHandlingException {
ConsensusElectAccept electAccept = new ConsensusElectAccept(INSTANCE_ID, messageId, true);
MessageGeneral electAcceptMsg = getMsg(NODE_3_KEY, electAccept);
messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electAcceptMsg);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
assertTrue(electInstanceOpt.isPresent());
ElectInstance electInstance = electInstanceOpt.get();
Map<PublicKey, MessageID> acceptorsToMessageId = electInstance.getAcceptorsToMessageId();
assertEquals(1, acceptorsToMessageId.size());
assertEquals(electAcceptMsg.getMessageId(), acceptorsToMessageId.get(NODE_3));
assertEquals(3, lao.getNodes().size());
ConsensusNode organizer = lao.getNode(ORGANIZER);
ConsensusNode node2 = lao.getNode(NODE_2);
ConsensusNode node3 = lao.getNode(NODE_3);
assertNotNull(organizer);
assertNotNull(node2);
assertNotNull(node3);
Set<MessageID> organizerAcceptedMsg = organizer.getAcceptedMessageIds();
Set<MessageID> node2AcceptedMsg = node2.getAcceptedMessageIds();
Set<MessageID> node3AcceptedMsg = node3.getAcceptedMessageIds();
assertTrue(organizerAcceptedMsg.isEmpty());
assertTrue(node2AcceptedMsg.isEmpty());
assertEquals(Sets.newSet(electMsg.getMessageId()), node3AcceptedMsg);
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class ChirpTest method setAndGetSenderTest.
@Test
public void setAndGetSenderTest() {
PublicKey sender = generatePublicKey();
CHIRP.setSender(sender);
assertEquals(sender, CHIRP.getSender());
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class LaoDetailViewModel method onQRCodeDetected.
@Override
public void onQRCodeDetected(Barcode barcode) {
Log.d(TAG, "Detected barcode with value: " + barcode.rawValue);
PublicKey attendee;
try {
attendee = new PublicKey(barcode.rawValue);
} catch (IllegalArgumentException e) {
mScanWarningEvent.postValue(new SingleEvent<>("Invalid QR code. Please try again."));
return;
}
if (attendees.contains(attendee) || Objects.requireNonNull(mWitnesses.getValue()).contains(attendee)) {
mScanWarningEvent.postValue(new SingleEvent<>("This QR code has already been scanned. Please try again."));
return;
}
if (scanningAction == (ScanningAction.ADD_ROLL_CALL_ATTENDEE)) {
attendees.add(attendee);
mAttendeeScanConfirmEvent.postValue(new SingleEvent<>("Attendee has been added."));
mNbAttendeesEvent.postValue(new SingleEvent<>(attendees.size()));
} else if (scanningAction == (ScanningAction.ADD_WITNESS)) {
witnesses.add(attendee);
mWitnessScanConfirmEvent.postValue(new SingleEvent<>(true));
updateLaoWitnesses();
}
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class LaoDetailActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lao_detail_activity);
mViewModel = obtainViewModel(this);
mViewModel.subscribeToLao((String) Objects.requireNonNull(getIntent().getExtras()).get("LAO_ID"));
if (getIntent().getExtras().get("FRAGMENT_TO_OPEN").equals("LaoDetail")) {
setupLaoFragment();
} else {
setupLaoWalletFragment();
}
setupHomeButton();
setupIdentityButton();
setupSocialMediaButton();
// Subscribe to "open lao detail event"
mViewModel.getOpenLaoDetailEvent().observe(this, booleanEvent -> {
Boolean event = booleanEvent.getContentIfNotHandled();
if (event != null) {
setupLaoFragment();
}
});
// Subscribe to "open home" event
setupHomeActivity();
// Subscribe to "open identity" event
setupIdentityFragment();
// Subscribe to " open social media " event
setupSocialMediaActivity();
// Subscribe to " open witness message" event
setupWitnessMessageFragment();
// Subscribe to "add witness" event
setupAddWitness();
// Subscribe to "new lao event" event
handleNewEvent();
// Subscribe to "open roll call" event
mViewModel.getOpenRollCallEvent().observe(this, stringEvent -> {
HomeViewModel.HomeViewAction action = stringEvent.getContentIfNotHandled();
if (action != null) {
openScanning(action);
}
});
mViewModel.getCloseRollCallEvent().observe(this, integerEvent -> {
Integer nextFragment = integerEvent.getContentIfNotHandled();
if (nextFragment != null) {
if (nextFragment.equals(R.id.fragment_lao_detail)) {
mViewModel.openLaoDetail();
} else if (nextFragment.equals(R.id.fragment_home)) {
mViewModel.openHome();
} else if (nextFragment.equals(R.id.fragment_identity)) {
mViewModel.openIdentity();
}
}
});
mViewModel.getPkRollCallEvent().observe(this, stringEvent -> {
PublicKey pk = stringEvent.getContentIfNotHandled();
if (pk != null) {
setupRollCallDetailFragment(pk);
}
});
subscribeWalletEvents();
// Subscribe to "open cast votes event" event
setupCastVotesFragment();
// Subscribe to "open election display" event
setupElectionResultsFragment();
// Subscribe to "open manage election" event
setupManageElectionFragment();
// Subscribe to "open start election" event
setupElectionStartFragment();
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class LaoDetailViewModel method enterRollCall.
public void enterRollCall(String id) {
if (!wallet.isSetUp()) {
mWalletMessageEvent.setValue(new SingleEvent<>(true));
return;
}
String firstLaoId = getCurrentLaoValue().getId();
String errorMessage = "failed to retrieve public key from wallet";
try {
PublicKey publicKey = wallet.generatePoPToken(firstLaoId, id).getPublicKey();
mPkRollCallEvent.postValue(new SingleEvent<>(publicKey));
} catch (Exception e) {
Log.d(TAG, errorMessage, e);
}
}
Aggregations