Package com.klaytn.caver.wallet.keyring
Class MultipleKeyring
- java.lang.Object
-
- com.klaytn.caver.wallet.keyring.AbstractKeyring
-
- com.klaytn.caver.wallet.keyring.MultipleKeyring
-
public class MultipleKeyring extends AbstractKeyring
Representing a Keyring which includes "address" and "private keys array"- See Also:
AbstractKeyring
,SingleKeyring
,RoleBasedKeyring
-
-
Constructor Summary
Constructors Constructor Description MultipleKeyring(java.lang.String address, PrivateKey[] keys)
Creates a MultipleKeyring instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractKeyring
copy()
Returns a copied MultipleKeyring instance.java.util.List<SignatureData>
ecsign(java.lang.String txHash, int role)
Signs a transaction hash with all private keys in specific role group and returns a signature list which V is 0 or 1(parity of the y-value of a secp256k1 signature).SignatureData
ecsign(java.lang.String txHash, int role, int index)
Signs a transaction hash with key in specific role group and returns a signature.KeyStore
encrypt(java.lang.String password, KeyStoreOption options)
Encrypts a keyring and returns a KeyStore.(according to KeyStore V4)PrivateKey[]
getKeyByRole(int role)
Returns keys by role.PrivateKey[]
getKeys()
Getter function of keysjava.lang.String[]
getPublicKey()
Returns a public key strings.java.lang.String[]
getPublicKey(boolean compressed)
Returns a public key strings.java.util.List<SignatureData>
sign(java.lang.String txHash, int chainId, int role)
Signs a transaction hash with all keys in specific role group and return signature list.SignatureData
sign(java.lang.String txHash, int chainId, int role, int index)
Signs a transaction hash with key in specific role group and return signature.MessageSigned
signMessage(java.lang.String message, int role)
Signs a hashed data with all key in specific role group and return MessageSigned instance.MessageSigned
signMessage(java.lang.String message, int role, int index)
Signs a hashed data with key in specific role group and return MessageSigned instance.Account
toAccount()
Returns an instance of Account.Account
toAccount(WeightedMultiSigOptions options)
Returns an instance of Account-
Methods inherited from class com.klaytn.caver.wallet.keyring.AbstractKeyring
encrypt, encryptV3, encryptV3, getAddress, getKlaytnWalletKey, isDecoupled, sign, sign
-
-
-
-
Constructor Detail
-
MultipleKeyring
public MultipleKeyring(java.lang.String address, PrivateKey[] keys)
Creates a MultipleKeyring instance.- Parameters:
address
- The address of keyring.keys
- The keys to use in MultipleKeyring.
-
-
Method Detail
-
sign
public java.util.List<SignatureData> sign(java.lang.String txHash, int chainId, int role)
Signs a transaction hash with all keys in specific role group and return signature list.Example :
String txHash = "0x{txHash}"; int chainId = 0; int role = RoleGroup.TRANSACTION; List<SignatureData> signature = keyring.sign(txHash, chainId, role);
- Specified by:
sign
in classAbstractKeyring
- Parameters:
txHash
- The hash of transaction.chainId
- The chainId specific to the network.role
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.- Returns:
List<SignatureData>
-
sign
public SignatureData sign(java.lang.String txHash, int chainId, int role, int index)
Signs a transaction hash with key in specific role group and return signature.Example :
String txHash = "0x{txHash}"; int chainId = 0; int role = RoleGroup.TRANSACTION; int index = 0; SignatureData signature = keyring.sign(txHash, chainId, role, index);
- Specified by:
sign
in classAbstractKeyring
- Parameters:
txHash
- The hash of transaction.chainId
- The chainId specific to the network.role
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.index
- The index of the key to be used in the specific role group.- Returns:
- SignatureData
-
ecsign
public java.util.List<SignatureData> ecsign(java.lang.String txHash, int role)
Signs a transaction hash with all private keys in specific role group and returns a signature list which V is 0 or 1(parity of the y-value of a secp256k1 signature).MultipleKeyring doesn't define the role group, so it signs a transaction using all keys existed in MultipleKeyring.
The role used in caver-java can be checked through
AccountKeyRoleBased.RoleGroup
.Example :
MultipleKeyring keyring = new MultipleKeyring(.....); List<SignatureData> signatureList = keyring.ecsign("0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550", AccountKeyRoleBased.RoleGroup.TRANSACTION);
- Specified by:
ecsign
in classAbstractKeyring
- Parameters:
txHash
- The hash of transaction.role
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.- Returns:
List<SignatureData>
-
ecsign
public SignatureData ecsign(java.lang.String txHash, int role, int index)
Signs a transaction hash with key in specific role group and returns a signature. MultipleKeyring doesn't define the role group, so it signs a transaction using specific key existed in MultipleKeyring. The role used in caver-java can be checked throughAccountKeyRoleBased.RoleGroup
.Example :
MultipleKeyring keyring = new MultipleKeyring(.....); SignatureData signature = keyring.ecsign("0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550", AccountKeyRoleBased.RoleGroup.TRANSACTION, 0);
- Specified by:
ecsign
in classAbstractKeyring
- Parameters:
txHash
- The hash transactionrole
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.index
- The index of the key to be used in the specific role group.- Returns:
- SignatureData
-
signMessage
public MessageSigned signMessage(java.lang.String message, int role)
Signs a hashed data with all key in specific role group and return MessageSigned instance.Example :
Sting message = "message"; int role = RoleGroup.TRANSACTION; MessageSigned signedInfo = keyring.signMessage(message, role);
- Specified by:
signMessage
in classAbstractKeyring
- Parameters:
message
- The data string to sign.role
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.- Returns:
- MessageSigned
-
signMessage
public MessageSigned signMessage(java.lang.String message, int role, int index)
Signs a hashed data with key in specific role group and return MessageSigned instance.Example :
Sting message = "message"; int role = RoleGroup.TRANSACTION; int index = 0; MessageSigned signedInfo = keyring.signMessage(message, role, index);
- Specified by:
signMessage
in classAbstractKeyring
- Parameters:
message
- The data string to sign.role
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.index
- The index of the key to be used in the specific role group.- Returns:
- MessageSigned
-
encrypt
public KeyStore encrypt(java.lang.String password, KeyStoreOption options) throws org.web3j.crypto.CipherException
Encrypts a keyring and returns a KeyStore.(according to KeyStore V4)For more information, please refer to KIP3.
Example :
KeyStoreOption options = KeyStoreOption.getDefaultOptionWithKDF("pbkdf2"); KeyStore encrypted = keyring.encrypt("password", options);
- Specified by:
encrypt
in classAbstractKeyring
- Parameters:
password
- The password to be used for encryption. The encrypted in KeyStore can be decrypted with this password.options
- The options to use when encrypt a keyring.- Returns:
- KeyStore
- Throws:
org.web3j.crypto.CipherException
-
copy
public AbstractKeyring copy()
Returns a copied MultipleKeyring instance.Example :
AbstractKeyring copied = keyring.copy();
- Specified by:
copy
in classAbstractKeyring
- Returns:
- AbstractKeyring
-
getPublicKey
public java.lang.String[] getPublicKey()
Returns a public key strings.It returns a public key as a uncompressed format.
Example :
String[] publicKey = keyring.getPublicKey();
- Returns:
- String array
-
getPublicKey
public java.lang.String[] getPublicKey(boolean compressed)
Returns a public key strings.Example :
String[] publicKey = keyring.getPublicKey(false);
- Parameters:
compressed
- Whether in compressed format or not.- Returns:
- String array
-
getKeyByRole
public PrivateKey[] getKeyByRole(int role)
Returns keys by role. If the key of the role passed as parameter is empty, the default key is returned.Example :
PrivateKey[] privateKeyArr = keyring.getKeyByRole(RoleGroup.TRANSACTION);
- Parameters:
role
- A number indicating the role of the key. seeAccountKeyRoleBased.RoleGroup
.- Returns:
PrivateKey[]
-
toAccount
public Account toAccount()
Returns an instance of Account.Example:
Account account = keyring.toAccount();
- Returns:
- Account
-
toAccount
public Account toAccount(WeightedMultiSigOptions options)
Returns an instance of AccountExample:
BigInteger[] optionWeight = { BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, }; WeightedMultiSigOptions weightedOption = new WeightedMultiSigOptions( BigInteger.ONE, Arrays.asList(optionWeight) ); Account account = keyring.toAccount(weightedOption);
- Parameters:
options
- The options that includes 'threshold' and 'weight'. This is only necessary when keyring use multiple private keys.- Returns:
- Account
-
getKeys
public PrivateKey[] getKeys()
Getter function of keys- Returns:
- PrivateKey Array
-
-