use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ContractsServiceTest method checkTransactional.
@Test
public void checkTransactional() throws Exception {
PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
Contract delorean = Contract.fromDslFile(rootPath + "DeLoreanOwnership.yml");
delorean.addSignerKey(manufacturePrivateKey);
delorean.seal();
delorean.traceErrors();
Contract.Transactional transactional = delorean.createTransactionalSection();
Reference reference = new Reference();
// reference.setName("transactional_example");
transactional.addReference(reference);
Contract deloreanTransactional = delorean.createRevision(transactional);
deloreanTransactional.addSignerKey(manufacturePrivateKey);
deloreanTransactional.seal();
deloreanTransactional.traceErrors();
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ContractsServiceTest method goodRevoke.
@Test
public void goodRevoke() throws Exception {
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
// let's make this key among owners
((SimpleRole) c.getRole("owner")).addKeyRecord(new KeyRecord(goodKey.getPublicKey()));
c.seal();
Contract revokeContract = c.createRevocation(goodKey);
assertTrue(revokeContract.check());
// tc.traceErrors();
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ContractsServiceTest method badRevoke.
@Test
public void badRevoke() throws Exception {
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
c.seal();
PrivateKey issuer = TestKeys.privateKey(2);
Contract tc = c.createRevocation(issuer);
// c can't be revoked with this key!
boolean result = tc.check();
assertFalse(result);
assertEquals(1, tc.getErrors().size());
assertEquals(Errors.FORBIDDEN, tc.getErrors().get(0).getError());
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ExtendedSignatureTest method extractPublicKey.
@Test
public void extractPublicKey() throws Exception {
byte[] data = "Hello world".getBytes();
PrivateKey k = TestKeys.privateKey(3);
byte[] signature = ExtendedSignature.sign(k, data, true);
PublicKey pubKey = k.getPublicKey();
ExtendedSignature es = ExtendedSignature.verify(pubKey, signature, data);
assertNotNull(es);
assertAlmostSame(es.getCreatedAt(), ZonedDateTime.now());
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.keyId(pubKey));
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.extractKeyId(signature));
assertNotNull(es.getPublicKey());
assertEquals(pubKey, es.getPublicKey());
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ExtendedSignatureTest method sign.
@Test
public void sign() throws Exception {
byte[] data = "Hello world".getBytes();
PrivateKey k = TestKeys.privateKey(3);
byte[] signature = ExtendedSignature.sign(k, data);
PublicKey pubKey = k.getPublicKey();
ExtendedSignature es = ExtendedSignature.verify(pubKey, signature, data);
assertNotNull(es);
assertAlmostSame(es.getCreatedAt(), ZonedDateTime.now());
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.keyId(pubKey));
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.extractKeyId(signature));
}
Aggregations