Package org.drasyl.identity
Class Identity
- java.lang.Object
-
- org.drasyl.identity.Identity
-
public abstract class Identity extends Object
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.
-
-
Field Summary
Fields Modifier and Type Field Description static byte
POW_DIFFICULTY
-
Constructor Summary
Constructors Constructor Description Identity()
-
Method Summary
-
-
-
Method Detail
-
getProofOfWork
public abstract ProofOfWork getProofOfWork()
-
getIdentityKeyPair
public abstract KeyPair<IdentityPublicKey,IdentitySecretKey> getIdentityKeyPair()
-
getKeyAgreementKeyPair
public abstract KeyPair<KeyAgreementPublicKey,KeyAgreementSecretKey> getKeyAgreementKeyPair()
-
getIdentityPublicKey
public IdentityPublicKey getIdentityPublicKey()
-
getIdentitySecretKey
public IdentitySecretKey getIdentitySecretKey()
-
toUnmaskedString
public String toUnmaskedString()
UnlikeObject.toString()
, this method returns the identity with the unmasked secret keys.- Returns:
- identity with unmasked secret keys
-
getAddress
public DrasylAddress getAddress()
Returns the address for this identity.- Returns:
- returns the address for this identity.
-
getKeyAgreementPublicKey
public KeyAgreementPublicKey getKeyAgreementPublicKey()
-
getKeyAgreementSecretKey
public KeyAgreementSecretKey getKeyAgreementSecretKey()
-
isValid
public boolean isValid()
Validates the identity by checking whether the proof of work matches the public key.- Returns:
true
if this identity is valid. Otherwisefalse
-
of
public static Identity of(ProofOfWork proofOfWork, KeyPair<IdentityPublicKey,IdentitySecretKey> identityKeyPair, KeyPair<KeyAgreementPublicKey,KeyAgreementSecretKey> keyAgreementKeyPair)
- Throws:
NullPointerException
- ifproofOfWork
,identityKeyPair
orkeyAgreementKeyPair
isnull
.
-
of
public static Identity of(ProofOfWork proofOfWork, IdentityPublicKey identityPublicKey, IdentitySecretKey identitySecretKey)
- Throws:
NullPointerException
- ifproofOfWork
,identityPublicKey
oridentitySecretKey
isnull
.IllegalArgumentException
- ifidentityPublicKey
andidentitySecretKey
can not be converted to a key agreement key pair.
-
of
public static Identity of(ProofOfWork proofOfWork, KeyPair<IdentityPublicKey,IdentitySecretKey> identityKeyPair)
- Throws:
IllegalArgumentException
- ifidentityKeyPair
can not be converted to a key agreement key pair.NullPointerException
- ifproofOfWork
,identityKeyPair
or a key within the pair isnull
-
of
public static Identity of(ProofOfWork proofOfWork, String identityPublicKey, String identitySecretKey)
-
of
public static Identity of(int proofOfWork, KeyPair<IdentityPublicKey,IdentitySecretKey> identityKeyPair, KeyPair<KeyAgreementPublicKey,KeyAgreementSecretKey> keyAgreementKeyPair)
- Throws:
NullPointerException
- ifidentityKeyPair
orkeyAgreementKeyPair
isnull
.
-
of
public static Identity of(int proofOfWork, IdentitySecretKey identitySecretKey)
- Throws:
NullPointerException
- ifidentitySecretKey
isnull
.
-
of
public static Identity of(ProofOfWork proofOfWork, IdentitySecretKey identitySecretKey)
- Throws:
NullPointerException
- ifproofOfWork
oridentitySecretKey
isnull
.
-
of
public static Identity of(int proofOfWork, String identitySecretKey)
- Throws:
IllegalArgumentException
- ifidentitySecretKey
is not a valid secret key.
-
generateIdentity
public static Identity generateIdentity() throws IOException
Generates a new random identity.- Returns:
- the generated identity
- Throws:
IOException
- if an identity could not be generated
-
-