Class RoleBasedKeyring

    • Constructor Summary

      Constructors 
      Constructor Description
      RoleBasedKeyring​(java.lang.String address, java.util.List<PrivateKey[]> keys)
      Creates a RoleBasedKeyring.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AbstractKeyring copy()
      Returns a copied RoleBasedKeyring 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.
      java.util.List<PrivateKey[]> getKeys()
      Getter function of keys
      java.util.List<java.lang.String[]> getPublicKey()
      Returns a public key strings.
      java.util.List<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​(java.util.List<WeightedMultiSigOptions> options)
      Returns an instance of Account.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RoleBasedKeyring

        public RoleBasedKeyring​(java.lang.String address,
                                java.util.List<PrivateKey[]> keys)
        Creates a RoleBasedKeyring.
        Parameters:
        address - The address of keyring.
        keys - The keys to use in RoleBasedKeyring.
    • 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 class AbstractKeyring
        Parameters:
        txHash - The hash of transaction.
        chainId - The chainId specific to the network.
        role - A number indicating the role of the key. see AccountKeyRoleBased.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 class AbstractKeyring
        Parameters:
        txHash - The hash of transaction.
        chainId - The chainId specific to the network.
        role - A number indicating the role of the key. see AccountKeyRoleBased.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).

        The role used in caver-java can be checked through AccountKeyRoleBased.RoleGroup.

        Example :
         
         RoleBasedKeyring keyring = new RoleBasedKeyring(.....);
         List<SignatureData> signatureList = keyring.ecsign("0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550", AccountKeyRoleBased.RoleGroup.TRANSACTION);
         
         
        Specified by:
        ecsign in class AbstractKeyring
        Parameters:
        txHash - The hash of transaction.
        role - A number indicating the role of the key.
        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.

        The role used in caver-java can be checked through AccountKeyRoleBased.RoleGroup.

        Example :
         
         RoleBasedKeyring keyring = new RoleBasedKeyring(.....);
         SignatureData signature = keyring.ecsign("0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550", AccountKeyRoleBased.RoleGroup.TRANSACTION, 0);
         
         
        Specified by:
        ecsign in class AbstractKeyring
        Parameters:
        txHash - The hash transaction
        role - A number indicating the role of the key.
        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 class AbstractKeyring
        Parameters:
        message - The data string to sign.
        role - A number indicating the role of the key. see AccountKeyRoleBased.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 class AbstractKeyring
        Parameters:
        message - The data string to sign.
        role - A number indicating the role of the key. see AccountKeyRoleBased.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 class AbstractKeyring
        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 RoleBasedKeyring instance.
        Example :
         
         AbstractKeyring copied = keyring.copy();
         
         
        Specified by:
        copy in class AbstractKeyring
        Returns:
        RoleBasedKeyring
      • getPublicKey

        public java.util.List<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.util.List<java.lang.String[]> getPublicKey​(boolean compressed)
        Returns a public key strings.
        Example :
         
         String[] publicKey = keyring.getPublicKey(false);
         
         
        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. You can use `AccountRoleBased.RoleGroup`.
        Returns:
        PrivateKey Array
      • toAccount

        public Account toAccount()
        Returns an instance of Account.
        Example:
         
         Account account = keyring.toAccount();
         
         
        Returns:
        Account
      • toAccount

        public Account toAccount​(java.util.List<WeightedMultiSigOptions> options)
        Returns an instance of Account.
        Example :
         
         BigInteger[][] optionWeight = {
              {BigInteger.ONE, BigInteger.ONE},
              {},
              {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE},
         };
        
         WeightedMultiSigOptions[] weightedOptions = {
            new WeightedMultiSigOptions(BigInteger.valueOf(1), Arrays.asList(optionWeight[0])),
            new WeightedMultiSigOptions(),
            new WeightedMultiSigOptions(BigInteger.valueOf(1), Arrays.asList(optionWeight[2])),
         };
        
         Account account = keyring.toAccount(Arrays.asList(weightedOptions));
        
         
        Parameters:
        options - The option List that includes 'threshold' and 'weight'. This is only necessary when keyring use multiple private keys.
        Returns:
        Account
      • getKeys

        public java.util.List<PrivateKey[]> getKeys()
        Getter function of keys
        Returns:
        PrivateKey Array