Skip to content

Commit

Permalink
Use generics with signAndGetArtifactSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
usmansaleem committed Nov 21, 2024
1 parent 3588952 commit 2ca96e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ public Optional<String> 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 <T> 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<ArtifactSignature> signAndGetArtifactSignature(
@SuppressWarnings("unchecked")
public <T extends ArtifactSignature<?>> Optional<T> 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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
.<SecpArtifactSignature>signAndGetArtifactSignature(
normaliseIdentifier(eth1Address), Bytes.of(bytesToSign))
.orElseThrow(() -> new JsonRpcException(SIGNING_FROM_IS_NOT_AN_UNLOCKED_ACCOUNT));

final Signature signature = artifactSignature.getSignatureData();

Expand Down

0 comments on commit 2ca96e0

Please sign in to comment.