Package org.web3j.crypto
Class WalletUtils
- java.lang.Object
-
- org.web3j.crypto.WalletUtils
-
- Direct Known Subclasses:
Bip44WalletUtils
public class WalletUtils extends java.lang.Object
Utility functions for working with Wallet files.
-
-
Constructor Summary
Constructors Constructor Description WalletUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.web3j.crypto.Bip39Wallet
generateBip39Wallet(java.lang.String password, java.io.File destinationDirectory)
Generates a BIP-39 compatible Ethereum wallet.static org.web3j.crypto.Bip39Wallet
generateBip39WalletFromMnemonic(java.lang.String password, java.lang.String mnemonic, java.io.File destinationDirectory)
Generates a BIP-39 compatible Ethereum wallet using a mnemonic passed as argument.static java.lang.String
generateFullNewWalletFile(java.lang.String password, java.io.File destinationDirectory)
static java.lang.String
generateLightNewWalletFile(java.lang.String password, java.io.File destinationDirectory)
static java.lang.String
generateNewWalletFile(java.lang.String password, java.io.File destinationDirectory)
static java.lang.String
generateNewWalletFile(java.lang.String password, java.io.File destinationDirectory, boolean useFullScrypt)
static java.lang.String
generateWalletFile(java.lang.String password, org.web3j.crypto.ECKeyPair ecKeyPair, java.io.File destinationDirectory, boolean useFullScrypt)
static java.lang.String
getDefaultKeyDirectory()
static java.lang.String
getMainnetKeyDirectory()
static java.lang.String
getRinkebyKeyDirectory()
Get keystore destination directory for a Rinkeby network.static java.lang.String
getTestnetKeyDirectory()
static boolean
isValidAddress(java.lang.String input)
static boolean
isValidAddress(java.lang.String input, int addressLength)
static boolean
isValidPrivateKey(java.lang.String privateKey)
static org.web3j.crypto.Credentials
loadBip39Credentials(java.lang.String password, java.lang.String mnemonic)
static org.web3j.crypto.Credentials
loadCredentials(java.lang.String password, java.io.File source)
static org.web3j.crypto.Credentials
loadCredentials(java.lang.String password, java.lang.String source)
static org.web3j.crypto.Credentials
loadJsonCredentials(java.lang.String password, java.lang.String content)
Load credentials from JSON wallet string.
-
-
-
Method Detail
-
generateFullNewWalletFile
public static java.lang.String generateFullNewWalletFile(java.lang.String password, java.io.File destinationDirectory) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException, java.security.InvalidAlgorithmParameterException, org.web3j.crypto.CipherException, java.io.IOException
- Parameters:
password
-destinationDirectory
-- Returns:
- Throws:
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
java.security.InvalidAlgorithmParameterException
org.web3j.crypto.CipherException
java.io.IOException
-
generateLightNewWalletFile
public static java.lang.String generateLightNewWalletFile(java.lang.String password, java.io.File destinationDirectory) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException, java.security.InvalidAlgorithmParameterException, org.web3j.crypto.CipherException, java.io.IOException
- Parameters:
password
-destinationDirectory
-- Returns:
- Throws:
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
java.security.InvalidAlgorithmParameterException
org.web3j.crypto.CipherException
java.io.IOException
-
generateNewWalletFile
public static java.lang.String generateNewWalletFile(java.lang.String password, java.io.File destinationDirectory) throws org.web3j.crypto.CipherException, java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException, java.io.IOException
- Parameters:
password
-destinationDirectory
-- Returns:
- Throws:
org.web3j.crypto.CipherException
java.security.InvalidAlgorithmParameterException
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
java.io.IOException
-
generateNewWalletFile
public static java.lang.String generateNewWalletFile(java.lang.String password, java.io.File destinationDirectory, boolean useFullScrypt) throws org.web3j.crypto.CipherException, java.io.IOException, java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
- Parameters:
password
-destinationDirectory
-useFullScrypt
-- Returns:
- Throws:
org.web3j.crypto.CipherException
java.io.IOException
java.security.InvalidAlgorithmParameterException
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
-
generateWalletFile
public static java.lang.String generateWalletFile(java.lang.String password, org.web3j.crypto.ECKeyPair ecKeyPair, java.io.File destinationDirectory, boolean useFullScrypt) throws org.web3j.crypto.CipherException, java.io.IOException
- Parameters:
password
-ecKeyPair
-destinationDirectory
-useFullScrypt
-- Returns:
- Throws:
org.web3j.crypto.CipherException
java.io.IOException
-
generateBip39Wallet
public static org.web3j.crypto.Bip39Wallet generateBip39Wallet(java.lang.String password, java.io.File destinationDirectory) throws org.web3j.crypto.CipherException, java.io.IOException
Generates a BIP-39 compatible Ethereum wallet. The private key for the wallet can be calculated using following algorithm:Key = SHA-256(BIP_39_SEED(mnemonic, password))
- Parameters:
password
- Will be used for both wallet encryption and passphrase for BIP-39 seeddestinationDirectory
- The directory containing the wallet- Returns:
- A BIP-39 compatible Ethereum wallet
- Throws:
org.web3j.crypto.CipherException
- if the underlying cipher is not availablejava.io.IOException
- if the destination cannot be written to
-
generateBip39WalletFromMnemonic
public static org.web3j.crypto.Bip39Wallet generateBip39WalletFromMnemonic(java.lang.String password, java.lang.String mnemonic, java.io.File destinationDirectory) throws org.web3j.crypto.CipherException, java.io.IOException
Generates a BIP-39 compatible Ethereum wallet using a mnemonic passed as argument.- Parameters:
password
- Will be used for both wallet encryption and passphrase for BIP-39 seedmnemonic
- The mnemonic that will be used to generate the seeddestinationDirectory
- The directory containing the wallet- Returns:
- A BIP-39 compatible Ethereum wallet
- Throws:
org.web3j.crypto.CipherException
- if the underlying cipher is not availablejava.io.IOException
- if the destination cannot be written to
-
loadCredentials
public static org.web3j.crypto.Credentials loadCredentials(java.lang.String password, java.lang.String source) throws java.io.IOException, org.web3j.crypto.CipherException
- Parameters:
password
-source
-- Returns:
- Throws:
java.io.IOException
org.web3j.crypto.CipherException
-
loadCredentials
public static org.web3j.crypto.Credentials loadCredentials(java.lang.String password, java.io.File source) throws java.io.IOException, org.web3j.crypto.CipherException
- Parameters:
password
-source
-- Returns:
- Throws:
java.io.IOException
org.web3j.crypto.CipherException
-
loadBip39Credentials
public static org.web3j.crypto.Credentials loadBip39Credentials(java.lang.String password, java.lang.String mnemonic)
- Parameters:
password
-mnemonic
-- Returns:
-
loadJsonCredentials
public static org.web3j.crypto.Credentials loadJsonCredentials(java.lang.String password, java.lang.String content) throws java.io.IOException, org.web3j.crypto.CipherException
Load credentials from JSON wallet string.- Parameters:
password
- - password to decrypt JSON wallet stringcontent
- - JSON wallet content string- Returns:
- Ethereum credentials
- Throws:
org.web3j.crypto.CipherException
- if the underlying cipher is not availablejava.io.IOException
- if a low-level I/O problem (unexpected end-of-input, network error) occurs
-
getDefaultKeyDirectory
public static java.lang.String getDefaultKeyDirectory()
- Returns:
-
getTestnetKeyDirectory
public static java.lang.String getTestnetKeyDirectory()
- Returns:
-
getMainnetKeyDirectory
public static java.lang.String getMainnetKeyDirectory()
- Returns:
-
getRinkebyKeyDirectory
public static java.lang.String getRinkebyKeyDirectory()
Get keystore destination directory for a Rinkeby network.- Returns:
- a String containing destination directory
-
isValidPrivateKey
public static boolean isValidPrivateKey(java.lang.String privateKey)
- Parameters:
privateKey
-- Returns:
-
isValidAddress
public static boolean isValidAddress(java.lang.String input)
- Parameters:
input
-- Returns:
-
isValidAddress
public static boolean isValidAddress(java.lang.String input, int addressLength)
- Parameters:
input
-addressLength
-- Returns:
-
-