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
ConstructorsModifierConstructorDescriptionprotectedEthereumAgent(KeyPair pair, String passphrase, byte[] salt, String loginName, String ethereumMnemonic) protectedEthereumAgent(PublicKey pubKey, byte[] encryptedPrivate, byte[] salt, String loginName, String ethereumMnemonic, String ethereumAddress) -
Method Summary
Modifier and TypeMethodDescriptionstatic EthereumAgentcreateEthereumAgent(String loginName, String passphrase, ReadWriteRegistryClient regClient, String ethereumMnemonic) static EthereumAgentcreateEthereumAgentWithClient(String loginName, String passphrase, ReadWriteRegistryClient regClient) Creates new agent with given passphrase and login name.static EthereumAgentcreateFromXml(String xml) static EthereumAgentcreateFromXml(Element root) org.web3j.crypto.CredentialsGets registry client that uses the agent's credentials.booleanisLocked()Returns whether the agent is locked or not.voidRemoves decrypted private key and the registry client (which contains user credentials).Returns a XML representation of this object.voidUnlocks this agent.Methods inherited from class i5.las2peer.security.UserAgentImpl
createUserAgent, getEmail, getLoginName, hasEmail, hasLoginName, notifyUnregister, receiveMessage, setEmail, setLoginNameMethods inherited from class i5.las2peer.security.PassphraseAgentImpl
changePassphrase, getPassphrase, getSalt, unlockPrivateKeyMethods inherited from class i5.las2peer.security.AgentImpl
cloneLocked, createFromXml, createFromXml, createSignature, decryptSymmetricKey, encryptPrivateKey, equals, getEncodedPrivate, getIdentifier, getPublicKey, getResponsibleForAgentSafeId, getRunningAtNode, notifyRegistrationTo, signContent, unlockPrivateKeyMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface i5.las2peer.api.security.Agent
getIdentifierMethods 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:
lockPrivateKeyin classPassphraseAgentImpl
-
unlock
public void unlock(String passphrase) throws AgentAccessDeniedException, AgentOperationFailedException Description copied from interface:PassphraseAgentUnlocks this agent.- Specified by:
unlockin interfacePassphraseAgent- Overrides:
unlockin 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:AgentReturns whether the agent is locked or not. -
toXmlString
Description copied from interface:XmlAbleReturns a XML representation of this object.- Specified by:
toXmlStringin interfaceXmlAble- Overrides:
toXmlStringin 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
-