Search in sources :

Example 1 with AtomicCounter

use of com.hedera.services.legacy.proto.utils.AtomicCounter in project hedera-services by hashgraph.

the class JKeyUtils method genSampleComplexKey.

/**
 * Generates a complex key of given depth with a mix of basic key, threshold key and key list.
 *
 * @param depth
 * 		of the generated key
 * @return generated key
 */
public static Key genSampleComplexKey(final int depth, final Map<String, PrivateKey> pubKey2privKeyMap) {
    Key rv;
    final int numKeys = 3;
    final int threshold = 2;
    if (depth == 1) {
        rv = genSingleEd25519Key(pubKey2privKeyMap);
        // verify the size
        final int size = computeNumOfExpandedKeys(rv, 1, new AtomicCounter());
        assertEquals(1, size);
    } else if (depth == 2) {
        final List<Key> keys = new ArrayList<>();
        keys.add(genSingleEd25519Key(pubKey2privKeyMap));
        keys.add(genSingleECDSASecp256k1Key(pubKey2privKeyMap));
        keys.add(genThresholdKeyInstance(numKeys, threshold, pubKey2privKeyMap));
        keys.add(genKeyListInstance(numKeys, pubKey2privKeyMap));
        rv = genKeyList(keys);
        // verify the size
        final int size = computeNumOfExpandedKeys(rv, 1, new AtomicCounter());
        assertEquals(2 + numKeys * 2, size);
    } else {
        throw new NotImplementedException("Not implemented yet.");
    }
    return rv;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) AtomicCounter(com.hedera.services.legacy.proto.utils.AtomicCounter) ArrayList(java.util.ArrayList) List(java.util.List) KeyList(com.hederahashgraph.api.proto.java.KeyList) Key(com.hederahashgraph.api.proto.java.Key) PrivateKey(java.security.PrivateKey) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) EdDSAPublicKey(net.i2p.crypto.eddsa.EdDSAPublicKey)

Example 2 with AtomicCounter

use of com.hedera.services.legacy.proto.utils.AtomicCounter in project hedera-services by hashgraph.

the class JKeySerializerTest method genSampleComplexKey.

/**
 * Generates a complex key of given depth with a mix of basic key, threshold key and key list.
 *
 * @param depth
 * 		of the generated key
 * @return generated key
 */
private static Key genSampleComplexKey(final int depth, final Map<String, PrivateKey> pubKey2privKeyMap) {
    Key rv = null;
    final int numKeys = 3;
    final int threshold = 2;
    if (depth == 1) {
        rv = genSingleEd25519Key(pubKey2privKeyMap);
        // verify the size
        final int size = computeNumOfExpandedKeys(rv, 1, new AtomicCounter());
        assertEquals(1, size);
    } else if (depth == 2) {
        final List<Key> keys = new ArrayList<>();
        keys.add(genSingleEd25519Key(pubKey2privKeyMap));
        keys.add(genSingleECDSASecp256k1Key(pubKey2privKeyMap));
        keys.add(genThresholdKeyInstance(numKeys, threshold, pubKey2privKeyMap));
        keys.add(genKeyListInstance(numKeys, pubKey2privKeyMap));
        rv = genKeyList(keys);
        // verify the size
        final int size = computeNumOfExpandedKeys(rv, 1, new AtomicCounter());
        assertEquals(2 + numKeys * 2, size);
    } else {
        throw new NotImplementedException("Not implemented yet.");
    }
    return rv;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) AtomicCounter(com.hedera.services.legacy.proto.utils.AtomicCounter) ArrayList(java.util.ArrayList) KeyList(com.hederahashgraph.api.proto.java.KeyList) List(java.util.List) Key(com.hederahashgraph.api.proto.java.Key) PrivateKey(java.security.PrivateKey) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) EdDSAPublicKey(net.i2p.crypto.eddsa.EdDSAPublicKey)

Aggregations

AtomicCounter (com.hedera.services.legacy.proto.utils.AtomicCounter)2 Key (com.hederahashgraph.api.proto.java.Key)2 KeyList (com.hederahashgraph.api.proto.java.KeyList)2 ThresholdKey (com.hederahashgraph.api.proto.java.ThresholdKey)2 PrivateKey (java.security.PrivateKey)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EdDSAPublicKey (net.i2p.crypto.eddsa.EdDSAPublicKey)2 NotImplementedException (org.apache.commons.lang3.NotImplementedException)2