Package com.klaytn.caver.wallet
Class KeyringContainer
- java.lang.Object
-
- com.klaytn.caver.wallet.KeyringContainer
-
-
Field Summary
Fields Modifier and Type Field Description KeyringFactoryWrapper
keyring
The KeyringFactoryWrapper instance This is added to improve "SDK User Experience" which means giving developers similar development experience with caver-js
-
Constructor Summary
Constructors Constructor Description KeyringContainer()
Creates KeyringContainer instance.KeyringContainer(java.util.List<AbstractKeyring> keyrings)
Creates KeyringContainer instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractKeyring
add(AbstractKeyring keyring)
Adds a keyring to the keyringContainer.java.util.List<java.lang.String>
generate(int num)
Generates keyrings in the keyring container with randomly generated key pairs.java.util.List<java.lang.String>
generate(int num, java.lang.String entropy)
Generates keyrings in the keyring container with randomly generated key pairs.AbstractKeyring
getKeyring(java.lang.String address)
Returns the keyring in container corresponding to the address.boolean
isExisted(java.lang.String address)
Returns true if there is a keyring matching the given address in the wallet.int
length()
Returns the number of keyrings in the KeyringContainer.AbstractKeyring
newKeyring(java.lang.String address, java.lang.String key)
Creates a single type keyring instance with given parameters and adds it to the keyringContainer.AbstractKeyring
newKeyring(java.lang.String address, java.lang.String[] keys)
Creates a multiple type keyring instance with given parameters and add it to the keyringContainer.AbstractKeyring
newKeyring(java.lang.String address, java.util.List<java.lang.String[]> keys)
Creates a role-basd type keyring instance with given parameters and add it to the keyringContainer.boolean
remove(java.lang.String address)
Deletes the keyring that associates with the given address from keyringContainer.AbstractTransaction
sign(java.lang.String address, AbstractTransaction transaction)
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using all keys in the Keyring instance corresponding to the address.AbstractTransaction
sign(java.lang.String address, AbstractTransaction transaction, int index)
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using one key in the keyring instance corresponding to the address.AbstractTransaction
sign(java.lang.String address, AbstractTransaction transaction, int index, java.util.function.Function<AbstractTransaction,java.lang.String> hasher)
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using one key in the keyring instance corresponding to the address.AbstractTransaction
sign(java.lang.String address, AbstractTransaction transaction, java.util.function.Function<AbstractTransaction,java.lang.String> hasher)
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using all keys in the Keyring instance corresponding to the address.AbstractFeeDelegatedTransaction
signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction)
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using all keys in the keyring instance corresponding to the address.AbstractFeeDelegatedTransaction
signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction, int index)
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using one key in the keyring corresponding to the address.AbstractFeeDelegatedTransaction
signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction, int index, java.util.function.Function<AbstractFeeDelegatedTransaction,java.lang.String> hasher)
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using one key in the keyring corresponding to the address.AbstractFeeDelegatedTransaction
signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction, java.util.function.Function<AbstractFeeDelegatedTransaction,java.lang.String> hasher)
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using all keys in the keyring instance corresponding to the address.MessageSigned
signMessage(java.lang.String address, java.lang.String data)
Signs with data and returns MessageSigned instance that includes 'signature', 'message', and 'messageHash'.MessageSigned
signMessage(java.lang.String address, java.lang.String data, int role, int index)
Signs with data and returns MessageSigned instance that includes 'signature', 'message', and 'messageHash'.AbstractKeyring
updateKeyring(AbstractKeyring keyring)
Updates the keyring inside the keyringContainer.
-
-
-
Field Detail
-
keyring
public KeyringFactoryWrapper keyring
The KeyringFactoryWrapper instance This is added to improve "SDK User Experience" which means giving developers similar development experience with caver-js
-
-
Constructor Detail
-
KeyringContainer
public KeyringContainer()
Creates KeyringContainer instance.
-
KeyringContainer
public KeyringContainer(java.util.List<AbstractKeyring> keyrings)
Creates KeyringContainer instance.- Parameters:
keyrings
- An list of keyring
-
-
Method Detail
-
generate
public java.util.List<java.lang.String> generate(int num)
Generates keyrings in the keyring container with randomly generated key pairs.Example :
List<String> addressList = caver.wallet.generate(3);
-
generate
public java.util.List<java.lang.String> generate(int num, java.lang.String entropy)
Generates keyrings in the keyring container with randomly generated key pairs.Example :
List<String> addressList = caver.wallet.generate(3, "entropy");
- Parameters:
num
- The number of keyring to create.entropy
- A random string to increase entropy.- Returns:
- List of address generated Keyring instances
-
length
public int length()
Returns the number of keyrings in the KeyringContainer.Example :
int size = caver.wallet.length();
- Returns:
- int
-
newKeyring
public AbstractKeyring newKeyring(java.lang.String address, java.lang.String key)
Creates a single type keyring instance with given parameters and adds it to the keyringContainer.KeyringContainer manages Keyring instance using Map {string:Keyring} which has address as key value.
Example :
String address = "0x{address}"; String key = caver.wallet.keyring.generateSingleKey(); SingleKeyring keyring = (SingleKeyring)caver.wallet.newKeyring(address, key);
- Parameters:
address
- The address of the keyringkey
- Private key string- Returns:
- AbstractKeyring(SingleKeyring)
-
newKeyring
public AbstractKeyring newKeyring(java.lang.String address, java.lang.String[] keys)
Creates a multiple type keyring instance with given parameters and add it to the keyringContainer. KeyringContainer manages Keyring instance using Map {string:Keyring} which has address as key value.Example :
String address = "0x{address}"; String[] keyArray = caver.wallet.keyring.generateMultipleKeys(3); MultipleKeyring keyring = (MultipleKeyring)caver.wallet.newKeyring(address, keyArray);
- Parameters:
address
- The address of the keyringkeys
- An array of private keys- Returns:
- AbstractKeyring(MultipleKeyring)
-
newKeyring
public AbstractKeyring newKeyring(java.lang.String address, java.util.List<java.lang.String[]> keys)
Creates a role-basd type keyring instance with given parameters and add it to the keyringContainer.KeyringContainer manages Keyring instance using Map {string:Keyring} which has address as key value.
Example :
String address = caver.wallet.keyring.generate().getAddress(); List<String> privateKeys = caver.wallet.keyring.generateRoleBasedKeys(new int[]{3,4,5}); RoleBasedKeyring added = (RoleBasedKeyring)caver.wallet.newKeyring(address, privateKeys);
- Parameters:
address
- The address of the keyringkeys
- A List of private key array- Returns:
- AbstractKeyring(RoleBasedKeyring)
-
updateKeyring
public AbstractKeyring updateKeyring(AbstractKeyring keyring)
Updates the keyring inside the keyringContainer.Query the keyring to be updated from keyringContainer with the keyring's address,
and an error occurs when the keyring is not found in the keyringContainer.
Example :
String updatedAddress = "0x{address}"; String newPrivateKey = caver.wallet.keyring.generateSingleKey(); SingleKeyring newKeyring = (SingleKeyring)caver.wallet.newKeyring(updatedAddress, newPrivateKey); caver.wallet.updateKeyring(newKeyring);
- Parameters:
keyring
- The keyring with new key- Returns:
- AbstractKeyring
-
getKeyring
public AbstractKeyring getKeyring(java.lang.String address)
Returns the keyring in container corresponding to the address.Example : String address = "0x{address}"; AbstractKeyring keyring = caver.wallet.getKeyring(address);
- Parameters:
address
- The address of keyring to query- Returns:
- AbstractKeyring
-
add
public AbstractKeyring add(AbstractKeyring keyring)
Adds a keyring to the keyringContainer.Example :
SingleKeyring keyring = caver.wallet.keyring.generate(); caver.wallet.add(keyring);
- Parameters:
keyring
- Keyring instance to be added.- Returns:
- AbstractKeyring
-
remove
public boolean remove(java.lang.String address)
Deletes the keyring that associates with the given address from keyringContainer.Example :
String address = "0x{address}"; caver.wallet.remove(address);
-
signMessage
public MessageSigned signMessage(java.lang.String address, java.lang.String data)
Signs with data and returns MessageSigned instance that includes 'signature', 'message', and 'messageHash'.It automatically set both 'roleIndex' and 'keyIndex' to 0.
Example :
String address = "0x{address in KeyringContainer}"; String data = "hello"; MessageSigned signed = caver.wallet.signMessage(address, data);
- Parameters:
address
- An address of keyring in keyringContainerdata
- The data string to sign- Returns:
- MessageSigned
-
signMessage
public MessageSigned signMessage(java.lang.String address, java.lang.String data, int role, int index)
Signs with data and returns MessageSigned instance that includes 'signature', 'message', and 'messageHash'.Example :
String address = "0x{address in KeyringContainer}"; String data = "hello"; int role = RoleGroup.TRANSACTION; int index = 0; MessageSigned signed = caver.wallet.signMessage(address, data, role, index);
- Parameters:
address
- An address of keyring in keyringContainerdata
- The data string to sign.role
- A number indication the role of the key. seeAccountKeyRoleBased.RoleGroup
.index
- An index of key to use for signing.- Returns:
- MessageSigned
-
sign
public AbstractTransaction sign(java.lang.String address, AbstractTransaction transaction) throws java.io.IOException
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using all keys in the Keyring instance corresponding to the address.Example :
AbstractTransaction signedTx = caver.wallet.sign("0x{address}", transaction);
-
sign
public AbstractTransaction sign(java.lang.String address, AbstractTransaction transaction, java.util.function.Function<AbstractTransaction,java.lang.String> hasher) throws java.io.IOException
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using all keys in the Keyring instance corresponding to the address.Example :
AbstractTransaction signedTx = caver.wallet.sign("0x{address}", transaction, TransactionHasher::getHashForSignature);
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractTransaction instance to sign.hasher
- A function to return hash of transaction.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
-
sign
public AbstractTransaction sign(java.lang.String address, AbstractTransaction transaction, int index) throws java.io.IOException
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using one key in the keyring instance corresponding to the address.Example :
AbstractTransaction signedTx = caver.wallet.sign("0x{address}", transaction, 0);
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractTransaction instance to signindex
- An index of key to use for signing.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
-
sign
public AbstractTransaction sign(java.lang.String address, AbstractTransaction transaction, int index, java.util.function.Function<AbstractTransaction,java.lang.String> hasher) throws java.io.IOException
Signs the transaction as a sender of the transaction and appends signatures in the transaction instance using one key in the keyring instance corresponding to the address.Example :
AbstractTransaction signedTx = caver.wallet.sign("0x{address}", transaction, 0, TransactionHasher::getHashForSignature);
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractTransaction instance to sign.index
- An index of key to use for signing.hasher
- A function to return hash of transaction.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
-
signAsFeePayer
public AbstractFeeDelegatedTransaction signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction) throws java.io.IOException
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using all keys in the keyring instance corresponding to the address.Example :
AbstractFeeDelegatedTransaction signedTx = caver.wallet.signAsFeePayer("0x{address}", transaction);
- Specified by:
signAsFeePayer
in interfaceIWallet
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractFeeDelegatedTransaction instance to sign.- Returns:
- AbstractFeeDelegatedTransaction
- Throws:
java.io.IOException
-
signAsFeePayer
public AbstractFeeDelegatedTransaction signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction, java.util.function.Function<AbstractFeeDelegatedTransaction,java.lang.String> hasher) throws java.io.IOException
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using all keys in the keyring instance corresponding to the address.Example :
AbstractFeeDelegatedTransaction signedTx = caver.wallet.signAsFeePayer("0x{address}", transaction, TransactionHasher::getHashForSignature);
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractFeeDelegatedTransaction instance to sign.hasher
- A function to return hash of transaction.- Returns:
- AbstractFeeDelegatedTransaction
- Throws:
java.io.IOException
-
signAsFeePayer
public AbstractFeeDelegatedTransaction signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction, int index) throws java.io.IOException
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using one key in the keyring corresponding to the address.Example :
AbstractFeeDelegatedTransaction signedTx = caver.wallet.signAsFeePayer("0x{address}", transaction, 0);
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractFeeDelegatedTransaction instance to sign.index
- An index of key to use for signing.- Returns:
- AbstractFeeDelegatedTransaction
- Throws:
java.io.IOException
-
signAsFeePayer
public AbstractFeeDelegatedTransaction signAsFeePayer(java.lang.String address, AbstractFeeDelegatedTransaction transaction, int index, java.util.function.Function<AbstractFeeDelegatedTransaction,java.lang.String> hasher) throws java.io.IOException
Signs the FeeDelegatedTransaction as a fee payer of the transaction and appends feePayerSignatures in the transaction instance using one key in the keyring corresponding to the address.Example :
AbstractFeeDelegatedTransaction signedTx = caver.wallet.signAsFeePayer("0x{address}", transaction, 0, TransactionHasher::getHashForSignature);
- Parameters:
address
- An address of keyring in KeyringContainer.transaction
- An AbstractFeeDelegatedTransaction instance to sign.index
- An index of key to user for signinghasher
- A function to return hash of transaction.- Returns:
- AbstractFeeDelegatedTransaction
- Throws:
java.io.IOException
-
isExisted
public boolean isExisted(java.lang.String address)
Returns true if there is a keyring matching the given address in the wallet.Exampe :
boolean isExist = caver.wallet.isExisted("0x{address}");
-
-