use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class KeyFactory method loadControlMap.
@SuppressWarnings("unchecked")
public void loadControlMap(String path) {
FileInputStream fis = null;
ObjectInputStream ois = null;
log.info("Deserialize controlMap from : " + path);
try {
fis = new FileInputStream(path);
ois = new ObjectInputStream(fis);
controlMap = (Map<Key, SigControl>) ois.readObject();
ois.close();
fis.close();
fis = null;
} catch (Exception e) {
log.error("De-serializable exception catched while working on " + path + ":" + e);
} finally {
try {
if (ois != null) {
ois.close();
}
if (fis != null) {
fis.close();
}
} catch (IOException e) {
log.error("File closing exception catched while closing " + path + ":" + e);
}
}
log.info(" Sucessfully de-serialized controlMap from " + path);
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class OverlappingKeyGenerator method genEd25519AndUpdateMap.
@Override
public Key genEd25519AndUpdateMap(Map<String, PrivateKey> mutablePkMap) {
Key key = precomputed.get(nextKey);
nextKey = (nextKey + 1) % precomputed.size();
String hexPubKey = CommonUtils.hex(key.getEd25519().toByteArray());
mutablePkMap.put(hexPubKey, pkMap.get(hexPubKey));
return key;
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class JThresholdKeyTest method JThresholdKeyWithVariousThresholdTest.
@Test
void JThresholdKeyWithVariousThresholdTest() throws Exception {
Key validContractIDKey = Key.newBuilder().setContractID(ContractID.newBuilder().setContractNum(1L).build()).build();
Key validRSA3072Key = Key.newBuilder().setRSA3072(TxnUtils.randomUtf8ByteString(16)).build();
KeyList validKeyList = KeyList.newBuilder().addKeys(validContractIDKey).addKeys(validRSA3072Key).build();
assertFalse(jThresholdKey(validKeyList, 0).isValid());
assertTrue(jThresholdKey(validKeyList, 1).isValid());
assertTrue(jThresholdKey(validKeyList, 2).isValid());
assertFalse(jThresholdKey(validKeyList, 3).isValid());
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class JThresholdKeyTest method invalidJThresholdKeyTest.
@Test
void invalidJThresholdKeyTest() throws Exception {
Key validED25519Key = Key.newBuilder().setEd25519(TxnUtils.randomUtf8ByteString(JEd25519Key.ED25519_BYTE_LENGTH)).build();
Key validECDSA384Key = Key.newBuilder().setECDSA384(TxnUtils.randomUtf8ByteString(24)).build();
Key validECDSASecp256Key = randomValidECDSASecp256K1Key();
KeyList invalidKeyList1 = KeyList.newBuilder().build();
Key invalidKey1 = thresholdKey(invalidKeyList1, 1);
KeyList invalidKeyList2 = KeyList.newBuilder().addKeys(validED25519Key).addKeys(invalidKey1).build();
Key invalidKey2 = thresholdKey(invalidKeyList2, 2);
KeyList invalidKeyList3 = KeyList.newBuilder().addKeys(validECDSA384Key).addKeys(invalidKey2).build();
Key invalidKey3 = thresholdKey(invalidKeyList2, 2);
KeyList invalidKeyList4 = KeyList.newBuilder().addKeys(validECDSASecp256Key).addKeys(invalidKey3).build();
JKey jThresholdKey1 = JKey.convertKey(invalidKey1, 1);
assertFalse(jThresholdKey1.isValid());
JKey jThresholdKey2 = JKey.convertKey(invalidKey2, 1);
assertFalse(jThresholdKey2.isValid());
assertFalse(jThresholdKey(invalidKeyList3, 1).isValid());
assertFalse(jThresholdKey(invalidKeyList4, 1).isValid());
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class JKeySerializerTest method jKeyECDSASecp256k1KeySerDes.
@Test
void jKeyECDSASecp256k1KeySerDes() throws Exception {
final Map<String, PrivateKey> pubKey2privKeyMap = new HashMap<>();
Key protoKey;
protoKey = genSingleECDSASecp256k1Key(pubKey2privKeyMap);
JKey jkey = JKey.mapKey(protoKey);
byte[] serializedJKey = null;
try {
serializedJKey = jkey.serialize();
} catch (IOException ignore) {
}
try (final var in = new ByteArrayInputStream(serializedJKey);
final var dis = new DataInputStream(in)) {
final JKey jKeyReborn = JKeySerializer.deserialize(dis);
assertAll("JKeyRebornChecks-Top Level", () -> assertNotNull(jKeyReborn), () -> assertTrue(jKeyReborn instanceof JECDSASecp256k1Key), () -> assertFalse(jKeyReborn.hasKeyList()), () -> assertFalse(jKeyReborn.hasThresholdKey()));
} catch (Exception e) {
throw new IllegalStateException(String.format("Failed to deserialize!", e));
}
}
Aggregations