Search in sources :

Example 26 with PrivateKey

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();
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) Test(org.junit.Test)

Example 27 with PrivateKey

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();
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) Test(org.junit.Test)

Example 28 with PrivateKey

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());
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) Test(org.junit.Test)

Example 29 with PrivateKey

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());
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 30 with PrivateKey

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));
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Aggregations

PrivateKey (com.icodici.crypto.PrivateKey)168 Test (org.junit.Test)122 PublicKey (com.icodici.crypto.PublicKey)76 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)29 Contract (com.icodici.universa.contract.Contract)24 Binder (net.sergeych.tools.Binder)22 IOException (java.io.IOException)16 HashSet (java.util.HashSet)14 ListRole (com.icodici.universa.contract.roles.ListRole)12 SQLException (java.sql.SQLException)11 Ignore (org.junit.Ignore)9 File (java.io.File)8 KeyAddress (com.icodici.crypto.KeyAddress)7 KeyRecord (com.icodici.universa.contract.KeyRecord)7 Role (com.icodici.universa.contract.roles.Role)7 Semaphore (java.util.concurrent.Semaphore)7 RoleLink (com.icodici.universa.contract.roles.RoleLink)5 TimeoutException (java.util.concurrent.TimeoutException)5 Decimal (com.icodici.universa.Decimal)4 HashId (com.icodici.universa.HashId)4