Package i5.las2peer.security
Class EthereumAgent
java.lang.Object
i5.las2peer.security.AgentImpl
i5.las2peer.security.PassphraseAgentImpl
i5.las2peer.security.UserAgentImpl
i5.las2peer.security.EthereumAgent
- All Implemented Interfaces:
Agent
,PassphraseAgent
,UserAgent
,MessageReceiver
,XmlAble
,Cloneable
User agent for las2peer networks with blockchain-based registry.
In addition to the usual key pair, this agent has a separate Ethereum key
pair with an associated Ethereum address. (The address can be derived from
the private key.)
In contrast to the regular las2peer key pair, the Ethereum key pair is not
stored as an encrypted private key, but instead as a mnemonic string which
serves the same function but is a standardized, human-readable
representation.
-
Field Summary
Fields inherited from class i5.las2peer.security.UserAgentImpl
sEmail, sLoginName
-
Constructor Summary
ModifierConstructorDescriptionprotected
EthereumAgent
(KeyPair pair, String passphrase, byte[] salt, String loginName, String ethereumMnemonic) protected
EthereumAgent
(PublicKey pubKey, byte[] encryptedPrivate, byte[] salt, String loginName, String ethereumMnemonic, String ethereumAddress) -
Method Summary
Modifier and TypeMethodDescriptionstatic EthereumAgent
createEthereumAgent
(String loginName, String passphrase, ReadWriteRegistryClient regClient, String ethereumMnemonic) static EthereumAgent
createEthereumAgentWithClient
(String loginName, String passphrase, ReadWriteRegistryClient regClient) Creates new agent with given passphrase and login name.static EthereumAgent
createFromXml
(String xml) static EthereumAgent
createFromXml
(Element root) org.web3j.crypto.Credentials
Gets registry client that uses the agent's credentials.boolean
isLocked()
Returns whether the agent is locked or not.void
Removes decrypted private key and the registry client (which contains user credentials).Returns a XML representation of this object.void
Unlocks this agent.Methods inherited from class i5.las2peer.security.UserAgentImpl
createUserAgent, getEmail, getLoginName, hasEmail, hasLoginName, notifyUnregister, receiveMessage, setEmail, setLoginName
Methods inherited from class i5.las2peer.security.PassphraseAgentImpl
changePassphrase, getPassphrase, getSalt, unlockPrivateKey
Methods inherited from class i5.las2peer.security.AgentImpl
cloneLocked, createFromXml, createFromXml, createSignature, decryptSymmetricKey, encryptPrivateKey, equals, getEncodedPrivate, getIdentifier, getPublicKey, getResponsibleForAgentSafeId, getRunningAtNode, notifyRegistrationTo, signContent, unlockPrivateKey
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface i5.las2peer.api.security.Agent
getIdentifier
Methods inherited from interface i5.las2peer.api.security.PassphraseAgent
unlockPrivateKey
-
Constructor Details
-
EthereumAgent
protected EthereumAgent(KeyPair pair, String passphrase, byte[] salt, String loginName, String ethereumMnemonic) throws AgentOperationFailedException, CryptoException -
EthereumAgent
-
-
Method Details
-
lockPrivateKey
public void lockPrivateKey()Removes decrypted private key and the registry client (which contains user credentials).- Overrides:
lockPrivateKey
in classPassphraseAgentImpl
-
unlock
public void unlock(String passphrase) throws AgentAccessDeniedException, AgentOperationFailedException Description copied from interface:PassphraseAgent
Unlocks this agent.- Specified by:
unlock
in interfacePassphraseAgent
- Overrides:
unlock
in classPassphraseAgentImpl
- Parameters:
passphrase
- The passphrase to unlock this agent.- Throws:
AgentAccessDeniedException
- If the passphrase is not valid.AgentOperationFailedException
- If the agent's private key can not be deserialized.
-
isLocked
public boolean isLocked()Description copied from interface:Agent
Returns whether the agent is locked or not. -
toXmlString
Description copied from interface:XmlAble
Returns a XML representation of this object.- Specified by:
toXmlString
in interfaceXmlAble
- Overrides:
toXmlString
in classUserAgentImpl
- Returns:
- a XML String representation
-
createEthereumAgentWithClient
public static EthereumAgent createEthereumAgentWithClient(String loginName, String passphrase, ReadWriteRegistryClient regClient) throws CryptoException, AgentOperationFailedException Creates new agent with given passphrase and login name.- Parameters:
passphrase
- passphrase with which both the agent key pair and the Ethereum key pair are encryptedloginName
- name matching [a-zA-Z].{3,31} (hopefully UTF-8 characters, let's not get too crazy)- Returns:
- new EthereumAgent instance
- Throws:
CryptoException
- if there is an internal error during Ethereum key creationAgentOperationFailedException
-
createEthereumAgent
public static EthereumAgent createEthereumAgent(String loginName, String passphrase, ReadWriteRegistryClient regClient, String ethereumMnemonic) throws CryptoException, AgentOperationFailedException -
getRegistryClient
Gets registry client that uses the agent's credentials. May benull
; useunlock(String)
. -
getEthereumAddress
- Returns:
- address of the Ethereum key pair associated with the agent
-
getEthereumMnemonic
-
getEthereumCredentials
- Throws:
AgentLockedException
-
createFromXml
- Throws:
MalformedXMLException
-
createFromXml
- Throws:
MalformedXMLException
-