Package com.klaytn.caver.wallet.keyring
Class PrivateKey
- java.lang.Object
-
- com.klaytn.caver.wallet.keyring.PrivateKey
-
public class PrivateKey extends java.lang.Object
Represents a PrivateKey class that includes private key string
-
-
Constructor Summary
Constructors Constructor Description PrivateKey(java.lang.String privateKey)
Creates a PrivateKey instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SignatureData
ecsign(java.lang.String sigHash)
Signs with hashed data and returns signature data.static PrivateKey
generate()
Create a random PrivateKey instance.static PrivateKey
generate(java.lang.String entropy)
Create a PrivateKey instance with entropy.java.lang.String
getDerivedAddress()
Returns derived address from private key string.java.lang.String
getPrivateKey()
Getter function of private key stringjava.lang.String
getPublicKey(boolean compressed)
Returns public key string.SignatureData
sign(java.lang.String sigHash, int chainId)
Signs transactionHash with key and returns signature.SignatureData
signMessage(java.lang.String messageHash)
Signs hashed data with key and returns signature.
-
-
-
Method Detail
-
generate
public static PrivateKey generate()
Create a random PrivateKey instance.PrivateKey privateKey = PrivateKey.generate();
- Returns:
- PrivateKey
-
generate
public static PrivateKey generate(java.lang.String entropy)
Create a PrivateKey instance with entropy.String entropy = "entropy"; PrivateKey privateKey = PrivateKey.generate(entropy);
- Parameters:
entropy
- The entropy string- Returns:
- PrivateKey
-
sign
public SignatureData sign(java.lang.String sigHash, int chainId)
Signs transactionHash with key and returns signature.Example :
int chainId = 1; String hash = "0x{hash}"; PrivateKey prvKey = new PrivateKey("{privateKeyString}"); SignatureData sign = prvKey.sign(hash, chainId);
- Parameters:
sigHash
- The has of transactionHashchainId
- The chainId or network- Returns:
- SignatureData
-
ecsign
public SignatureData ecsign(java.lang.String sigHash)
Signs with hashed data and returns signature data.It returns a signature which has v as a parity of the y value(0 for even, 1 for odd) of secp256k1 signature.
Example :
String hash = "0x{hash}"; PrivateKey prvKey = new PrivateKey("{privateKeyString}"); SignatureData sign = prvKey.ecsign(hash);
- Parameters:
sigHash
- The hash to sign- Returns:
- SignatureData
-
signMessage
public SignatureData signMessage(java.lang.String messageHash)
Signs hashed data with key and returns signature.Example :
String msgHash = "0x{hash}"; PrivateKey prvKey = new PrivateKey("{privateKeyString}"); SignatureData sign = prvKey.signMessage(msgHash);
- Parameters:
messageHash
- The hash of data to sign- Returns:
- SignatureData
-
getPublicKey
public java.lang.String getPublicKey(boolean compressed)
Returns public key string.Example :
PrivateKey prvKey = new PrivateKey("{privateKeyString}"); String publicKey = prvKey.getPublicKey(true);
- Parameters:
compressed
- If true, it returns compressed format- Returns:
- String
-
getDerivedAddress
public java.lang.String getDerivedAddress()
Returns derived address from private key string.Example :
PrivateKey prvKey = new PrivateKey("{privateKeyString}"); String address = prvKey.getDerivedAddress();
- Returns:
- String
-
getPrivateKey
public java.lang.String getPrivateKey()
Getter function of private key string- Returns:
- String
-
-