Class AbstractSignatureService
java.lang.Object
org.xrpl.xrpl4j.crypto.core.signing.AbstractSignatureService
- All Implemented Interfaces:
SignatureService
,TransactionSigner
,TransactionVerifier
An abstract implementation of
SignatureService
with common functionality that sub-classes can utilize.-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractSignatureService
(SignatureUtils signatureUtils, AddressUtils addressUtils) Required-args Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract PublicKey
derivePublicKey
(PrivateKey privateKey) Helper method to derive a public key from a private key.protected abstract Signature
ecDsaSign
(PrivateKey privateKey, UnsignedByteArray signableTransactionBytes) Does the actual work of computing a signature using a secp256k1 private-key, as locatable usingprivateKeyMetadata
.protected abstract boolean
ecDsaVerify
(PublicKey publicKey, UnsignedByteArray transactionBytes, Signature signature) Verify a signature.protected abstract Signature
edDsaSign
(PrivateKey privateKey, UnsignedByteArray signableTransactionBytes) Does the actual work of computing a signature using an Ed25519 private-key, as locatable usingprivateKey
.protected abstract boolean
edDsaVerify
(PublicKey publicKey, UnsignedByteArray transactionBytes, Signature signature) Verify a signature.Accessor for theSignatureUtils
used by this class.<T extends Transaction>
SignaturemultiSign
(PrivateKey privateKey, T transaction) Obtain a signature for the supplied unsigned transaction using the suppliedPrivateKey
.sign
(PrivateKey privateKey, UnsignedClaim unsignedClaim) Signs a claim for usage in a Payment Channel.<T extends Transaction>
SingleSingedTransaction<T>sign
(PrivateKey privateKey, T transaction) Obtain a signature for the supplied transaction usingprivateKey
.<T extends Transaction>
booleanverify
(Set<SignatureWithPublicKey> signatureWithPublicKeys, T unsignedTransaction, int minSigners) Verify thatminSigners
from the collection of public keys have supplied signatures for a given signed transaction.<T extends Transaction>
booleanverify
(SignatureWithPublicKey signatureWithPublicKey, T unsignedTransaction) Verify the supplied digital-signature to ensure that it was constructed using the private-key corresponding tosignerPublicKey
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xrpl.xrpl4j.crypto.core.signing.TransactionVerifier
verify
-
Field Details
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Details
-
AbstractSignatureService
Required-args Constructor.- Parameters:
signatureUtils
- ASignatureUtils
.addressUtils
- AAddressUtils
.
-
-
Method Details
-
sign
public <T extends Transaction> SingleSingedTransaction<T> sign(PrivateKey privateKey, T transaction) Description copied from interface:TransactionSigner
Obtain a signature for the supplied transaction usingprivateKey
.- Specified by:
sign
in interfaceTransactionSigner
- Type Parameters:
T
- The typeTransaction
to be signed.- Parameters:
privateKey
- ThePrivateKey
used to signtransaction
.transaction
- TheTransaction
to sign.- Returns:
- A
SingleSingedTransaction
of typeTransactionSigner
containing everything related to a signed transaction.
-
sign
Description copied from interface:TransactionSigner
Signs a claim for usage in a Payment Channel.- Specified by:
sign
in interfaceTransactionSigner
- Parameters:
privateKey
- APrivateKey
used for signing.unsignedClaim
- AnUnsignedClaim
.- Returns:
- A
Signature
.
-
multiSign
Description copied from interface:TransactionSigner
Obtain a signature for the supplied unsigned transaction using the suppliedPrivateKey
. The primary reason this method's signature diverges fromTransactionSigner.sign(PrivateKey, Transaction)
is that for multi-sign scenarios, the interstitially signed transaction is always discarded. Instead, a quorum of signatures is need and then that quorum is submitted to the ledger with the unsigned transaction. Thus, obtaining a multi-signed transaction here is not useful (instead, see TransactionUtils to construct a multisigned transaction).- Specified by:
multiSign
in interfaceTransactionSigner
- Type Parameters:
T
- The type of the transaction to be signed.- Parameters:
privateKey
- ThePrivateKey
used to signtransaction
.transaction
- TheTransaction
to sign.- Returns:
- A
Signature
for the transaction.
-
verify
public <T extends Transaction> boolean verify(SignatureWithPublicKey signatureWithPublicKey, T unsignedTransaction) Description copied from interface:TransactionVerifier
Verify the supplied digital-signature to ensure that it was constructed using the private-key corresponding tosignerPublicKey
.- Specified by:
verify
in interfaceTransactionVerifier
- Type Parameters:
T
- The actual type ofTransaction
.- Parameters:
signatureWithPublicKey
- ASignatureWithPublicKey
used for verification.unsignedTransaction
- TheTransaction
of typeTransactionVerifier
that was signed.- Returns:
true
if the signature is valid and verified;false
otherwise.
-
verify
public <T extends Transaction> boolean verify(Set<SignatureWithPublicKey> signatureWithPublicKeys, T unsignedTransaction, int minSigners) Description copied from interface:TransactionVerifier
Verify thatminSigners
from the collection of public keys have supplied signatures for a given signed transaction.- Specified by:
verify
in interfaceTransactionVerifier
- Type Parameters:
T
- The actual type ofTransaction
.- Parameters:
signatureWithPublicKeys
- ASet
ofSignatureWithPublicKey
used for verification.unsignedTransaction
- The transaction of typeTransactionVerifier
that was signed.minSigners
- The minimum number of signatures required to form a quorum.- Returns:
true
if a minimum number of signatures are valid for the supplied transaction;false
otherwise.
-
edDsaSign
protected abstract Signature edDsaSign(PrivateKey privateKey, UnsignedByteArray signableTransactionBytes) Does the actual work of computing a signature using an Ed25519 private-key, as locatable usingprivateKey
.- Parameters:
privateKey
- ThePrivateKey
to use for signing.signableTransactionBytes
- TheUnsignedByteArray
to sign.- Returns:
- A
Signature
with data that can be used to submit a transaction to the XRP Ledger.
-
ecDsaSign
protected abstract Signature ecDsaSign(PrivateKey privateKey, UnsignedByteArray signableTransactionBytes) Does the actual work of computing a signature using a secp256k1 private-key, as locatable usingprivateKeyMetadata
.- Parameters:
privateKey
- ThePrivateKey
to use for signing.signableTransactionBytes
- TheUnsignedByteArray
to sign.- Returns:
- A
Signature
with data that can be used to submit a transaction to the XRP Ledger.
-
edDsaVerify
protected abstract boolean edDsaVerify(PublicKey publicKey, UnsignedByteArray transactionBytes, Signature signature) Verify a signature.- Parameters:
publicKey
- ThePublicKey
used to verify the signed transaction.transactionBytes
- AnUnsignedByteArray
containing the bytes of the transaction that was signed.signature
- ASignature
over the transaction.- Returns:
true
if the signature is valid;false
otherwise.
-
ecDsaVerify
protected abstract boolean ecDsaVerify(PublicKey publicKey, UnsignedByteArray transactionBytes, Signature signature) Verify a signature.- Parameters:
publicKey
- APublicKey
.transactionBytes
- AnUnsignedByteArray
containing the bytes of the transaction that was signed.signature
- ASignature
over the transaction.- Returns:
true
if the signature is valid;false
otherwise.
-
derivePublicKey
Helper method to derive a public key from a private key.- Parameters:
privateKey
- An instance ofPrivateKey
.- Returns:
- A corresponding
PublicKey
.
-
getSignatureUtils
Accessor for theSignatureUtils
used by this class.- Returns:
- A
SignatureUtils
used by this class.
-