Java Code Examples for org.web3j.crypto.WalletUtils#generateWalletFile()
The following examples show how to use
org.web3j.crypto.WalletUtils#generateWalletFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyImporter.java From client-sdk-java with Apache License 2.0 | 6 votes |
private void createWalletFile(String privateKey) { if (!WalletUtils.isValidPrivateKey(privateKey)) { exitError("Invalid private key specified, must be " + PRIVATE_KEY_LENGTH_IN_HEX + " digit hex value"); } Credentials credentials = Credentials.create(privateKey); String password = getPassword("Please enter a wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( password, credentials.getEcKeyPair(), destination, true); console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } }
Example 2
Source File: KeyImporter.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
private void createWalletFile(String privateKey) { if (!WalletUtils.isValidPrivateKey(privateKey)) { exitError("Invalid private key specified, must be " + PRIVATE_KEY_LENGTH_IN_HEX + " digit hex value"); } Credentials credentials = Credentials.create(privateKey); String password = getPassword("Please enter a wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( password, credentials.getEcKeyPair(), destination, true); console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } }
Example 3
Source File: RegisterParamsTest.java From teku with Apache License 2.0 | 6 votes |
@Test void eth1EncryptedKeystoreReturnsCredential(@TempDir final Path tempDir) throws IOException, CipherException { // create v3 wallet final String keystoreFileName = WalletUtils.generateWalletFile(PASSWORD, EXPECTED_EC_KEYPAIR, tempDir.toFile(), true); final File keystoreFile = tempDir.resolve(keystoreFileName).toFile(); // create password file final File passwordFile = Files.writeString(tempDir.resolve("password.txt"), "test123").toFile(); final Eth1PrivateKeyOptions.Eth1EncryptedKeystoreOptions keystoreOptions = new Eth1PrivateKeyOptions.Eth1EncryptedKeystoreOptions(); keystoreOptions.eth1KeystoreFile = keystoreFile; keystoreOptions.eth1KeystorePasswordFile = passwordFile; final Eth1PrivateKeyOptions eth1PrivateKeyOptions = new Eth1PrivateKeyOptions(); eth1PrivateKeyOptions.keystoreOptions = keystoreOptions; final RegisterParams registerParams = new RegisterParams(commandSpec, eth1PrivateKeyOptions, SHUTDOWN_FUNCTION, consoleAdapter); final Credentials eth1Credentials = registerParams.getEth1Credentials(); assertThat(eth1Credentials.getEcKeyPair()).isEqualTo(EXPECTED_EC_KEYPAIR); }
Example 4
Source File: WalletUpdater.java From client-sdk-java with Apache License 2.0 | 5 votes |
private void run(String walletFileLocation) { File walletFile = new File(walletFileLocation); Credentials credentials = getCredentials(walletFile); console.printf("Wallet for address " + credentials.getAddress() + " loaded\n"); String newPassword = getPassword("Please enter a new wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( newPassword, credentials.getEcKeyPair(), destination, true); console.printf("New wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } String delete = console.readLine( "Would you like to delete your existing wallet file (Y/N)? [N]: "); if (delete.toUpperCase().equals("Y")) { if (!walletFile.delete()) { exitError("Unable to remove wallet file\n"); } else { console.printf("Deleted previous wallet file: %s\n", walletFile.getName()); } } }
Example 5
Source File: WalletUpdater.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
private void run(String walletFileLocation) { File walletFile = new File(walletFileLocation); Credentials credentials = getCredentials(walletFile); console.printf("Wallet for address " + credentials.getAddress() + " loaded\n"); String newPassword = getPassword("Please enter a new wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( newPassword, credentials.getEcKeyPair(), destination, true); console.printf("New wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } String delete = console.readLine( "Would you like to delete your existing wallet file (Y/N)? [N]: "); if (delete.toUpperCase().equals("Y")) { if (!walletFile.delete()) { exitError("Unable to remove wallet file\n"); } else { console.printf("Deleted previous wallet file: %s\n", walletFile.getName()); } } }
Example 6
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public void saveJsonLight() { try { BigInteger b = new BigInteger(Coders.decodeBase64(sharedManager.getLastSyncedBlock()), 16); String filename1 = WalletUtils.generateWalletFile("", ECKeyPair.create(b), com.google.common.io.Files.createTempDir(), false); } catch (Exception e) { e.printStackTrace(); } }
Example 7
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public void saveJsonLight() { try { BigInteger b = new BigInteger(Coders.decodeBase64(sharedManager.getLastSyncedBlock()), 16); String filename1 = WalletUtils.generateWalletFile("", ECKeyPair.create(b), com.google.common.io.Files.createTempDir(), false); } catch (Exception e) { e.printStackTrace(); } }
Example 8
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public void saveJsonLight() { try { BigInteger b = new BigInteger(Coders.decodeBase64(sharedManager.getLastSyncedBlock()), 16); String filename1 = WalletUtils.generateWalletFile("", ECKeyPair.create(b), com.google.common.io.Files.createTempDir(), false); } catch (Exception e) { e.printStackTrace(); } }