Package org.drasyl.identity
Class Identity
java.lang.Object
java.net.SocketAddress
org.drasyl.identity.Identity
- All Implemented Interfaces:
Serializable
Represents the private identity of a peer (includes the proof of work, the public and private
key). Should be kept secret!
This is an immutable object.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IdentityGenerates a new random identity.Returns the address for this identity.abstract KeyPair<IdentityPublicKey,IdentitySecretKey> abstract ProofOfWorkbooleanisValid()Validates the identity by checking whether the proof of work matches the public key.static Identitystatic Identitystatic Identityof(int proofOfWork, IdentitySecretKey identitySecretKey) static Identityof(int proofOfWork, KeyPair<IdentityPublicKey, IdentitySecretKey> identityKeyPair, KeyPair<KeyAgreementPublicKey, KeyAgreementSecretKey> keyAgreementKeyPair) static Identityof(ProofOfWork proofOfWork, String identityPublicKey, String identitySecretKey) static Identityof(ProofOfWork proofOfWork, IdentityPublicKey identityPublicKey, IdentitySecretKey identitySecretKey) static Identityof(ProofOfWork proofOfWork, IdentitySecretKey identitySecretKey) static Identityof(ProofOfWork proofOfWork, KeyPair<IdentityPublicKey, IdentitySecretKey> identityKeyPair) static Identityof(ProofOfWork proofOfWork, KeyPair<IdentityPublicKey, IdentitySecretKey> identityKeyPair, KeyPair<KeyAgreementPublicKey, KeyAgreementSecretKey> keyAgreementKeyPair) UnlikeObject.toString(), this method returns the identity with the unmasked secret keys.
-
Field Details
-
POW_DIFFICULTY
public static final byte POW_DIFFICULTY
-
-
Constructor Details
-
Identity
public Identity()
-
-
Method Details
-
getProofOfWork
-
getIdentityKeyPair
-
getKeyAgreementKeyPair
-
getIdentityPublicKey
-
getIdentitySecretKey
-
toUnmaskedString
UnlikeObject.toString(), this method returns the identity with the unmasked secret keys.- Returns:
- identity with unmasked secret keys
-
getAddress
Returns the address for this identity.- Returns:
- returns the address for this identity.
-
getKeyAgreementPublicKey
-
getKeyAgreementSecretKey
-
isValid
public boolean isValid()Validates the identity by checking whether the proof of work matches the public key.- Returns:
trueif this identity is valid. Otherwisefalse
-
of
public static Identity of(ProofOfWork proofOfWork, KeyPair<IdentityPublicKey, IdentitySecretKey> identityKeyPair, KeyPair<KeyAgreementPublicKey, KeyAgreementSecretKey> keyAgreementKeyPair) - Throws:
NullPointerException- ifproofOfWork,identityKeyPairorkeyAgreementKeyPairisnull.
-
of
public static Identity of(ProofOfWork proofOfWork, IdentityPublicKey identityPublicKey, IdentitySecretKey identitySecretKey) - Throws:
NullPointerException- ifproofOfWork,identityPublicKeyoridentitySecretKeyisnull.IllegalArgumentException- ifidentityPublicKeyandidentitySecretKeycan not be converted to a key agreement key pair.
-
of
public static Identity of(ProofOfWork proofOfWork, KeyPair<IdentityPublicKey, IdentitySecretKey> identityKeyPair) - Throws:
IllegalArgumentException- ifidentityKeyPaircan not be converted to a key agreement key pair.NullPointerException- ifproofOfWork,identityKeyPairor a key within the pair isnull
-
of
public static Identity of(ProofOfWork proofOfWork, String identityPublicKey, String identitySecretKey) -
of
-
of
public static Identity of(int proofOfWork, KeyPair<IdentityPublicKey, IdentitySecretKey> identityKeyPair, KeyPair<KeyAgreementPublicKey, KeyAgreementSecretKey> keyAgreementKeyPair) - Throws:
NullPointerException- ifidentityKeyPairorkeyAgreementKeyPairisnull.
-
of
- Throws:
NullPointerException- ifidentitySecretKeyisnull.
-
of
- Throws:
NullPointerException- ifproofOfWorkoridentitySecretKeyisnull.
-
of
- Throws:
IllegalArgumentException- ifidentitySecretKeyis not a valid secret key.
-
generateIdentity
Generates a new random identity.- Returns:
- the generated identity
- Throws:
IOException- if an identity could not be generated
-