use of org.web3j.crypto.ECDSASignature in project web3j by web3j.
the class HSMHTTPRequestProcessor method callHSM.
@Override
public Sign.SignatureData callHSM(byte[] dataToSign, HSMHTTPPass pass) {
Request request = createRequest(dataToSign, pass);
try (okhttp3.Response response = client.newCall(request).execute()) {
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
if (responseBody != null) {
String signHex = readResponse(responseBody.byteStream());
byte[] signBytes = Numeric.hexStringToByteArray(signHex);
ECDSASignature signature = CryptoUtils.fromDerFormat(signBytes);
return Sign.createSignatureData(signature, pass.getPublicKey(), dataToSign);
} else {
return null;
}
} else {
int code = response.code();
String text = responseBody == null ? "N/A" : responseBody.string();
throw new ClientConnectionException("Invalid response received: " + code + "; " + text);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return null;
}
use of org.web3j.crypto.ECDSASignature in project signers by ConsenSys.
the class MultiKeyTransactionSigningAcceptanceTestBase method verifySignature.
void verifySignature(String publicKeyHex) {
ECPublicKey pubKey = EthPublicKeyUtils.createPublicKey(Bytes.fromHexString(publicKeyHex));
final Optional<Signer> signer = signerProvider.getSigner(new PublicKeySignerIdentifier(pubKey));
assertThat(signer).isNotEmpty();
final Signature signature = signer.get().sign(DATA_TO_SIGN);
final BigInteger messagePublicKey = recoverPublicKey(signature);
assertThat(EthPublicKeyUtils.createPublicKey(messagePublicKey)).isEqualTo(pubKey);
final ECDSASignature ecdsaSignature = new ECDSASignature(signature.getR(), signature.getS());
assertThat(ecdsaSignature.isCanonical()).isTrue();
}
use of org.web3j.crypto.ECDSASignature in project web3signer by ConsenSys.
the class FilecoinVerify method recoverSignature.
private static BigInteger recoverSignature(final SecpArtifactSignature artifactSignature, final byte[] digest) {
final tech.pegasys.signers.secp256k1.api.Signature signatureData = artifactSignature.getSignatureData();
final ECDSASignature signature = new ECDSASignature(signatureData.getR(), signatureData.getS());
final ECDSASignature canonicalSignature = signature.toCanonicalised();
final int recId = signatureData.getV().intValue();
return Sign.recoverFromSignature(recId, canonicalSignature, digest);
}
Aggregations