Search in sources :

Example 1 with PublicKeyException

use of com.radixdlt.crypto.exception.PublicKeyException in project radixdlt by radixdlt.

the class TimestampedECDSASignatures method fromJSON.

public static TimestampedECDSASignatures fromJSON(JSONArray json) throws DeserializeException {
    var builder = ImmutableMap.<BFTNode, TimestampedECDSASignature>builder();
    for (int i = 0; i < json.length(); i++) {
        var signatureJson = json.getJSONObject(i);
        try {
            var key = ECPublicKey.fromHex(signatureJson.getString("key"));
            var bytes = Bytes.fromHexString(signatureJson.getString("signature"));
            var signature = REFieldSerialization.deserializeSignature(ByteBuffer.wrap(bytes));
            var timestamp = signatureJson.getLong("timestamp");
            builder.put(BFTNode.create(key), TimestampedECDSASignature.from(timestamp, signature));
        } catch (PublicKeyException e) {
            throw new DeserializeException(e.getMessage());
        }
    }
    return new TimestampedECDSASignatures(builder.build());
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 2 with PublicKeyException

use of com.radixdlt.crypto.exception.PublicKeyException in project radixdlt by radixdlt.

the class BouncyCastleKeyHandler method computePublicKey.

@Override
public byte[] computePublicKey(byte[] privateKey) throws PrivateKeyException, PublicKeyException {
    ECKeyUtils.validatePrivate(privateKey);
    var d = new BigInteger(1, privateKey);
    try {
        var publicKeySpec = new ECPublicKeySpec(spec.getG().multiply(d), spec);
        // and are casting to a bouncy castle ECPublicKey.
        return ((ECPublicKey) KeyFactory.getInstance("EC", "BC").generatePublic(publicKeySpec)).getQ().getEncoded(true);
    } catch (Exception e) {
        throw new PublicKeyException(e);
    }
}
Also used : BigInteger(java.math.BigInteger) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) ECPublicKeySpec(org.bouncycastle.jce.spec.ECPublicKeySpec) PrivateKeyException(com.radixdlt.crypto.exception.PrivateKeyException) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException)

Example 3 with PublicKeyException

use of com.radixdlt.crypto.exception.PublicKeyException in project radixdlt by radixdlt.

the class REFieldSerialization method deserializeKey.

public static ECPublicKey deserializeKey(ByteBuffer buf) throws DeserializeException {
    try {
        var keyBytes = new byte[33];
        buf.get(keyBytes);
        return ECPublicKey.fromBytes(keyBytes);
    } catch (PublicKeyException | IllegalArgumentException e) {
        throw new DeserializeException("Could not deserialize key");
    }
}
Also used : PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 4 with PublicKeyException

use of com.radixdlt.crypto.exception.PublicKeyException in project radixdlt by radixdlt.

the class TimestampedECDSASignatures method fromJSON.

public static TimestampedECDSASignatures fromJSON(JSONArray json) throws DeserializeException {
    var builder = ImmutableMap.<BFTNode, TimestampedECDSASignature>builder();
    for (int i = 0; i < json.length(); i++) {
        var signatureJson = json.getJSONObject(i);
        try {
            var key = ECPublicKey.fromHex(signatureJson.getString("key"));
            var bytes = Bytes.fromHexString(signatureJson.getString("signature"));
            var signature = REFieldSerialization.deserializeSignature(ByteBuffer.wrap(bytes));
            var timestamp = signatureJson.getLong("timestamp");
            builder.put(BFTNode.create(key), TimestampedECDSASignature.from(timestamp, signature));
        } catch (PublicKeyException e) {
            throw new DeserializeException(e.getMessage());
        }
    }
    return new TimestampedECDSASignatures(builder.build());
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Aggregations

PublicKeyException (com.radixdlt.crypto.exception.PublicKeyException)4 DeserializeException (com.radixdlt.serialization.DeserializeException)3 BFTNode (com.radixdlt.consensus.bft.BFTNode)1 PrivateKeyException (com.radixdlt.crypto.exception.PrivateKeyException)1 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)1 BigInteger (java.math.BigInteger)1 ECPublicKeySpec (org.bouncycastle.jce.spec.ECPublicKeySpec)1