use of com.github.dedis.popstellar.model.objects.security.PoPToken in project popstellar by dedis.
the class SocialMediaViewModel method sendChirp.
/**
* Send a chirp to your own channel.
*
* <p>Publish a MessageGeneral containing AddChirp data.
*
* @param text the text written in the chirp
* @param parentId the id of the chirp to which you replied
* @param timestamp the time at which you sent the chirp
*/
public void sendChirp(String text, @Nullable MessageID parentId, long timestamp) {
Log.d(TAG, "Sending a chirp");
Lao lao = getCurrentLao();
if (lao == null) {
Log.e(TAG, LAO_FAILURE_MESSAGE);
return;
}
AddChirp addChirp = new AddChirp(text, parentId, timestamp);
try {
PoPToken token = keyManager.getValidPoPToken(lao);
Channel channel = lao.getChannel().subChannel(SOCIAL).subChannel(token.getPublicKey().getEncoded());
Log.d(TAG, PUBLISH_MESSAGE);
MessageGeneral msg = new MessageGeneral(token, addChirp, gson);
Disposable disposable = networkManager.getMessageSender().publish(token, channel, addChirp).subscribe(() -> Log.d(TAG, "sent chirp with messageId: " + msg.getMessageId()), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_sending_chirp));
disposables.add(disposable);
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
}
}
use of com.github.dedis.popstellar.model.objects.security.PoPToken in project popstellar by dedis.
the class SocialMediaViewModel method deleteChirp.
public void deleteChirp(MessageID chirpId, long timestamp) {
Log.d(TAG, "Deleting the chirp with id: " + chirpId);
Lao lao = getCurrentLao();
if (lao == null) {
Log.e(TAG, LAO_FAILURE_MESSAGE);
return;
}
DeleteChirp deleteChirp = new DeleteChirp(chirpId, timestamp);
try {
PoPToken token = keyManager.getValidPoPToken(lao);
Channel channel = lao.getChannel().subChannel(SOCIAL).subChannel(token.getPublicKey().getEncoded());
Log.d(TAG, PUBLISH_MESSAGE);
MessageGeneral msg = new MessageGeneral(token, deleteChirp, gson);
Disposable disposable = networkManager.getMessageSender().publish(token, channel, deleteChirp).subscribe(() -> {
Log.d(TAG, "Deleted chirp with messageId: " + msg.getMessageId());
Toast.makeText(getApplication().getApplicationContext(), "Deleted chirp!", Toast.LENGTH_LONG).show();
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_delete_chirp));
disposables.add(disposable);
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
}
}
use of com.github.dedis.popstellar.model.objects.security.PoPToken in project popstellar by dedis.
the class Base64DataUtils method generatePoPToken.
/**
* @return a pseudo randomly generated valid Ed25519 keypair
*/
public static PoPToken generatePoPToken() {
byte[] privateKey = new byte[KEY_LENGTH];
RANDOM.nextBytes(privateKey);
Ed25519PrivateKeyParameters privateKeyParameters = new Ed25519PrivateKeyParameters(privateKey, 0);
Ed25519PublicKeyParameters publicKeyParameters = privateKeyParameters.generatePublicKey();
return new PoPToken(privateKey, publicKeyParameters.getEncoded());
}
use of com.github.dedis.popstellar.model.objects.security.PoPToken in project popstellar by dedis.
the class WalletTest method importSeedAndExportSeedAreCoherent.
@Test
public void importSeedAndExportSeedAreCoherent() throws Exception {
String Lao_ID = "1234123412341234";
String Roll_Call_ID = "1234123412341234";
Wallet hdw1 = new Wallet(TestKeysetModule.provideWalletKeysetManager());
hdw1.newSeed();
String seed = String.join(" ", hdw1.exportSeed());
PoPToken res1 = hdw1.generatePoPToken(Lao_ID, Roll_Call_ID);
Wallet hdw2 = new Wallet(TestKeysetModule.provideWalletKeysetManager());
hdw2.importSeed(seed);
PoPToken res2 = hdw2.generatePoPToken(Lao_ID, Roll_Call_ID);
assertEquals(res1, res2);
}
use of com.github.dedis.popstellar.model.objects.security.PoPToken in project popstellar by dedis.
the class LaoDetailViewModel method sendVote.
/**
* Sends a ElectionCastVotes message .
*
* <p>Publish a GeneralMessage containing ElectionCastVotes data.
*
* @param votes the corresponding votes for that election
*/
public void sendVote(List<ElectionVote> votes) {
Election election = mCurrentElection.getValue();
if (election == null) {
Log.d(TAG, "failed to retrieve current election");
return;
}
Log.d(TAG, "sending a new vote in election : " + election + " with election start time" + election.getStartTimestamp());
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
try {
PoPToken token = keyManager.getValidPoPToken(lao);
CastVote castVote = new CastVote(votes, election.getId(), lao.getId());
Channel electionChannel = election.getChannel();
Log.d(TAG, PUBLISH_MESSAGE);
Disposable disposable = networkManager.getMessageSender().publish(token, electionChannel, castVote).doFinally(this::openLaoDetail).subscribe(() -> {
Log.d(TAG, "sent a vote successfully");
// Toast ? + send back to election screen or details screen ?
Toast.makeText(getApplication(), "vote successfully sent !", Toast.LENGTH_LONG).show();
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_send_vote));
disposables.add(disposable);
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
}
}
Aggregations