From 2ca96e0160ca4a38025cdd1e91c5d5475950260a Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Thu, 21 Nov 2024 13:54:06 +1000 Subject: [PATCH] Use generics with signAndGetArtifactSignature --- .../http/handlers/signing/SignerForIdentifier.java | 10 ++++++---- .../handlers/signing/TransactionSerializer.java | 9 ++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/signing/SignerForIdentifier.java b/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/signing/SignerForIdentifier.java index d2b717451..69e22f85f 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/signing/SignerForIdentifier.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/signing/SignerForIdentifier.java @@ -44,15 +44,17 @@ public Optional sign(final String identifier, final Bytes data) { } /** - * Sign data for given identifier and return ArtifactSignature. Useful for SECP signing. + * Sign data for given identifier and return ArtifactSignature. Useful for SECP signing usages. * + * @param The specific type of ArtifactSignature * @param identifier The identifier for which to sign data. * @param data Bytes which is signed - * @return Optional ArtifactSignature. Empty if no signer available for given identifier + * @return Optional ArtifactSignature of type T. Empty if no signer available for given identifier */ - public Optional signAndGetArtifactSignature( + @SuppressWarnings("unchecked") + public > Optional signAndGetArtifactSignature( final String identifier, final Bytes data) { - return signerProvider.getSigner(identifier).map(signer -> signer.sign(data)); + return signerProvider.getSigner(identifier).map(signer -> (T) signer.sign(data)); } /** diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java index 186a17b45..4535635ce 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java @@ -78,11 +78,10 @@ private static byte[] prependEip1559TransactionType(byte[] bytesToSign) { private SignatureData sign(final String eth1Address, final byte[] bytesToSign) { final SecpArtifactSignature artifactSignature = - (SecpArtifactSignature) - secpSigner - .signAndGetArtifactSignature( - normaliseIdentifier(eth1Address), Bytes.of(bytesToSign)) - .orElseThrow(() -> new JsonRpcException(SIGNING_FROM_IS_NOT_AN_UNLOCKED_ACCOUNT)); + secpSigner + .signAndGetArtifactSignature( + normaliseIdentifier(eth1Address), Bytes.of(bytesToSign)) + .orElseThrow(() -> new JsonRpcException(SIGNING_FROM_IS_NOT_AN_UNLOCKED_ACCOUNT)); final Signature signature = artifactSignature.getSignatureData();