Class SingleKeyring

    • Constructor Summary

      Constructors 
      Constructor Description
      SingleKeyring​(java.lang.String address, PrivateKey key)
      Creates a SingleKeyring instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AbstractKeyring copy()
      Returns a copied SingleKeyring instance.
      java.util.List<SignatureData> ecsign​(java.lang.String txHash, int role)
      Signs a transaction hash with private key 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 private key in specific role group and returns a signature list which V is 0 or 1(parity of the y-value of a secp256k1 signature).
      KeyStore encrypt​(java.lang.String password, KeyStoreOption options)
      Encrypts a keyring and returns a KeyStore.(according to KeyStore V4)
      KeyStore encryptV3​(java.lang.String password)
      Encrypts a keyring and returns a KeyStore.(according to KeyStore V3)
      KeyStore encryptV3​(java.lang.String password, KeyStoreOption options)
      Encrypts a keyring and returns a KeyStore.(according to KeyStore V3)
      PrivateKey getKey()
      Getter function for key
      PrivateKey getKeyByRole​(int role)
      returns keys by role.
      java.lang.String getKlaytnWalletKey()
      Returns a KlaytnWalletKey format.
      java.lang.String getPublicKey()
      Return a public key strings.
      java.lang.String getPublicKey​(boolean compressed)
      Return a public key strings.
      boolean isDecoupled()
      Returns true if keyring has decoupled key.
      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.
      • Methods inherited from class java.lang.Object

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

      • SingleKeyring

        public SingleKeyring​(java.lang.String address,
                             PrivateKey key)
        Creates a SingleKeyring instance.
        Parameters:
        address - The address of keyring.
        key - The key to use in SingleKeyring.
    • 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.
        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 private key in specific role group and returns a signature list which V is 0 or 1(parity of the y-value of a secp256k1 signature).

        SingleKeyring doesn't define the role group, so it signs a transaction using key existed in SingleKeyring. The role used in caver-java can be checked through AccountKeyRoleBased.RoleGroup.

        Example :
         
         SingleKeyring keyring = new SingleKeyring(.....);
         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 private key in specific role group and returns a signature list which V is 0 or 1(parity of the y-value of a secp256k1 signature).

        SingleKeyring doesn't define the role group and only have one private key, so it signs a transaction using key existed in SingleKeyring.

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

        The index value must 0.

        Example :
         
         SingleKeyring keyring = new SingleKeyring(.....);
         SignatureData signature = keyring.ecsign("0xe9a11d9ef95fb437f75d07ce768d43e74f158dd54b106e7d3746ce29d545b550", AccountKeyRoleBased.RoleGroup.TRANSACTION, 0);
         
         
        Specified by:
        ecsign in class AbstractKeyring
        Parameters:
        txHash - The hash of 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
      • getKlaytnWalletKey

        public java.lang.String getKlaytnWalletKey()
        Returns a KlaytnWalletKey format.

        Example :
         
         String klaytnWalletKey = keyring.getKlaytnWalletKey();
         
         
        Overrides:
        getKlaytnWalletKey in class AbstractKeyring
        Returns:
        String
      • 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
      • encryptV3

        public KeyStore encryptV3​(java.lang.String password)
                           throws org.web3j.crypto.CipherException
        Encrypts a keyring and returns a KeyStore.(according to KeyStore V3)

        This function automatically execute SCRYPT KDF Function.

        Example :
         
         KeyStore encrypted = keyring.encryptV3("password");
         
         
        Overrides:
        encryptV3 in class AbstractKeyring
        Parameters:
        password - The password to be used for encryption. The encrypted in KeyStore can be decrypted with this password.
        Returns:
        KeyStore
        Throws:
        org.web3j.crypto.CipherException
      • encryptV3

        public KeyStore encryptV3​(java.lang.String password,
                                  KeyStoreOption options)
                           throws org.web3j.crypto.CipherException
        Encrypts a keyring and returns a KeyStore.(according to KeyStore V3)

        Example :
         
         KeyStoreOption options = KeyStoreOption.getDefaultOptionWithKDF("pbkdf2");
         KeyStore encrypted = keyring.encryptV3("password", options);
         
         
        Overrides:
        encryptV3 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
      • isDecoupled

        public boolean isDecoupled()
        Returns true if keyring has decoupled key.
        Example :
         
         boolean decoupled = keyring.isDecoupled();
         
         
        Overrides:
        isDecoupled in class AbstractKeyring
        Returns:
        boolean
      • copy

        public AbstractKeyring copy()
        Returns a copied SingleKeyring instance.
        Example :
         
         AbstractKeyring copied = keyring.copy();
         
         
        Specified by:
        copy in class AbstractKeyring
        Returns:
        AbstractKeyring
      • toAccount

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

        public java.lang.String getPublicKey()
        Return a public key strings.

        It returns a public key as a uncompressed format.

        Example :
         
         String publicKey = keyring.getPublicKey();
         
         
        Returns:
        String
      • getPublicKey

        public java.lang.String getPublicKey​(boolean compressed)
        Return a public key strings.

        Example :
         
         String publicKey = keyring.getPublicKey(false);
         
         
        Parameters:
        compressed - Whether in compressed format or not.
        Returns:
        String
      • 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[] privateKey = keyring.getKeyByRole(RoleGroup.TRANSACTION);
         
         
        Parameters:
        role - A number indicating the role of the key. see AccountKeyRoleBased.RoleGroup.
        Returns:
        PrivateKey Array
      • getKey

        public PrivateKey getKey()
        Getter function for key
        Returns:
        PrivateKey