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());
}
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);
}
}
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");
}
}
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());
}
Aggregations