use of com.icodici.crypto.KeyAddress in project universa by UniversaBlockchain.
the class BaseNetworkTest method changeOwnerWithAddress.
@Test(timeout = 90000)
public void changeOwnerWithAddress() throws Exception {
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PublicKey> martyPublicKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
martyPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) stepaPublicKeys.add(pk.getPublicKey());
for (PrivateKey pk : martyPrivateKeys) martyPublicKeys.add(pk.getPublicKey());
PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
Contract c1 = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
c1.addSignerKey(key);
c1.seal();
c1.check();
c1.traceErrors();
registerAndCheckApproved(c1);
//
KeyAddress stepaAddress = stepaPublicKeys.iterator().next().getShortAddress();
Contract anonOwnerContract = c1.createRevisionWithAddress(Arrays.asList(key));
anonOwnerContract.addSignerKey(key);
anonOwnerContract.setOwnerKey(stepaAddress);
anonOwnerContract.seal();
anonOwnerContract.check();
anonOwnerContract.traceErrors();
Contract anonAfterSend = imitateSendingTransactionToPartner(anonOwnerContract);
registerAndCheckApproved(anonAfterSend);
assertTrue(anonAfterSend.getOwner().getKeyAddresses().iterator().next().equals(stepaAddress));
assertEquals(0, anonAfterSend.getOwner().getKeys().size());
//
Contract anonSignedContract = anonAfterSend.createRevisionWithAddress(stepaPrivateKeys);
anonSignedContract.addSignerKeys(stepaPrivateKeys);
anonSignedContract.setOwnerKeys(martyPublicKeys);
anonSignedContract.seal();
anonSignedContract.check();
anonSignedContract.traceErrors();
Contract afterSend = imitateSendingTransactionToPartner(anonSignedContract);
registerAndCheckApproved(afterSend);
assertEquals(0, afterSend.getOwner().getKeyAddresses().size());
assertTrue(afterSend.getOwner().isAllowedForKeys(martyPublicKeys));
Contract anonPublishedContract = new Contract(anonSignedContract.getLastSealedBinary());
ItemResult itemResult = node.waitItem(anonPublishedContract.getId(), 8000);
assertEquals(ItemState.APPROVED, itemResult.state);
assertFalse(anonPublishedContract.getSealedByKeys().contains(stepaPublicKeys.iterator().next()));
}
use of com.icodici.crypto.KeyAddress in project universa by UniversaBlockchain.
the class SimpleRoleTest method testAddressRole.
@Test
public void testAddressRole() throws Exception {
Set<KeyAddress> keyAddresses = new HashSet<>();
keyAddresses.add(new KeyAddress(keys.get(0).getPublicKey(), 0, true));
SimpleRole sr = new SimpleRole("tr1", keyAddresses);
Binder serialized = DefaultBiMapper.serialize(sr);
Role r1 = DefaultBiMapper.deserialize(serialized);
Set<PublicKey> pubKeys = new HashSet<>();
pubKeys.add(keys.get(0).getPublicKey());
assertTrue(sr.isAllowedForKeys(pubKeys));
assertTrue(r1.isAllowedForKeys(pubKeys));
assertEquals(sr, r1);
}
use of com.icodici.crypto.KeyAddress in project universa by UniversaBlockchain.
the class SimpleRoleTest method testCloneAsAddressRole.
@Test
public void testCloneAsAddressRole() throws Exception {
Set<KeyAddress> keyAddresses = new HashSet<>();
keyAddresses.add(new KeyAddress(keys.get(0).getPublicKey(), 0, true));
SimpleRole sr = new SimpleRole("tr1", keyAddresses);
SimpleRole r1 = sr.cloneAs("tr2");
SimpleRole r2 = r1.cloneAs("tr1");
assertEquals(sr, r2);
}
use of com.icodici.crypto.KeyAddress in project universa by UniversaBlockchain.
the class CLIMain method doSelectKeyInFolder.
private static void doSelectKeyInFolder(String keysPath, String address) throws IOException {
File folder = new File(keysPath);
KeyAddress keyAddress;
if (!keysPath.endsWith("/"))
keysPath = keysPath.concat("/");
try {
keyAddress = new KeyAddress(address);
} catch (Exception e) {
report("Invalid address.");
finish();
return;
}
if (folder.exists()) {
for (File file : folder.listFiles()) {
if (!file.isDirectory()) {
boolean bResult = false;
try {
PrivateKey key = new PrivateKey(Do.read(keysPath + file.getName()));
bResult = keyAddress.isMatchingKey(key.getPublicKey());
} catch (Exception e) {
bResult = false;
}
if (bResult) {
report("Filekey: " + file.getName());
finish();
return;
}
}
}
report("File not found.");
} else
report("There is no such directory.");
finish();
}
use of com.icodici.crypto.KeyAddress in project universa by UniversaBlockchain.
the class CLIMain method doAddressMatch.
private static void doAddressMatch(String address, String keyFilePath) throws IOException {
boolean bResult = false;
try {
PrivateKey key = new PrivateKey(Do.read(keyFilePath));
KeyAddress keyAddress = new KeyAddress(address);
bResult = keyAddress.isMatchingKey(key.getPublicKey());
} catch (Exception e) {
}
;
report("Matching address: " + address + " with key: " + keyFilePath);
report("Matching result: " + bResult);
finish();
}
Aggregations