本文整理汇总了Java中org.web3j.crypto.WalletUtils类的典型用法代码示例。如果您正苦于以下问题:Java WalletUtils类的具体用法?Java WalletUtils怎么用?Java WalletUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WalletUtils类属于org.web3j.crypto包,在下文中一共展示了WalletUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadCredentials
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public static Credentials loadCredentials(EthKeyProperties keyProperties) {
if (keyProperties.getKeyLocation() != null) {
try {
return WalletUtils.loadCredentials(keyProperties.getKeyPassword(), keyProperties.getKeyLocation());
} catch (Exception e) {
throw Throwables.propagate(e);
}
} else if (keyProperties.getPrivateKey() != null) {
return Credentials.create(keyProperties.getPrivateKey());
} else {
throw new IllegalStateException("Either node.eth.key-location or node.eth.test.private-key required");
}
}
示例2: handleResult
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
@Override
public void handleResult(Result result) {
if (typeResult == CameraActivity.TAG_FROM_SEND || typeResult == CameraActivity.TAG_FROM_HOME) {
if (WalletUtils.isValidAddress(result.getText())) {
view.onSuccessfulScanQR(result.getText());
} else {
view.onFailScanQR();
mScannerView.resumeCameraPreview(this);
}
}
if (typeResult == CameraActivity.TAG_FROM_IMPORT) {
if (WalletUtils.isValidPrivateKey(result.getText())) {
view.onSuccessfulScanQR(result.getText());
} else {
view.onFailScanQR();
mScannerView.resumeCameraPreview(this);
}
}
}
示例3: Account
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public Account(String personId, String name, String password, String pathToFile) {
LOG.info("Creating account '" + name + "' for person '" + personId + "' with password '" + password + "'");
this.personId = personId;
this.name = name;
this.pathToFile = pathToFile;
this.password = password;
try {
fileName = WalletUtils.generateFullNewWalletFile(password, new File(pathToFile));
credentials = getCredentials();
if (credentials == null) {
throw new ProcessingException("Failed to obtain account credentials");
}
}
catch (Exception e) {
LOG.error("Failed to create account", e);
throw new ProcessingException("Failed to create account", e);
}
LOG.info("Account successfully created. File at " + pathToFile + "/" + fileName);
}
示例4: getCredentials
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public Credentials getCredentials() {
if (credentials != null) {
return credentials;
}
try {
String fileWithPath = getFile().getAbsolutePath();
credentials = WalletUtils.loadCredentials(password, fileWithPath);
// TODO verify again (performance issue gone now?)
// tried to figure out where the time is used up
// File file = new File(fileWithPath);
// ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); // 8sec
// WalletFile walletFile = objectMapper.readValue(file, WalletFile.class);
// ECKeyPair keyPair = org.web3j.crypto.Wallet.decrypt(password, walletFile); // > 30s
// -> "culprit" is Wallet.generateDerivedScryptKey() inside of Wallet.decrypt
// Credentials credentials = Credentials.create(keyPair);
return credentials;
}
catch (Exception e) {
LOG.error("failed to access credentials in file '" + getFile().getAbsolutePath() + "'", e);
return null;
}
}
示例5: createNewWallet
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
/**
* Este metodo crea una nueva cuenta de ethereum
*
* @param password
* @return String[] Para este ejemplo retornamos el nombre del fichero
* generado y el JSON del contenido
* @throws Exception
*/
public String[] createNewWallet(String password) throws Exception {
try {
File file = new File(WALLET_PATH);
String name = null;
String json = null;
if (file.exists()) {
// al crear el monedero nos retorna el nombre del archivo generado dentro de la carpeta indicada
name = WalletUtils.generateFullNewWalletFile(password, file);
// vamos a abrir el monedero y retornar el json generado
Path path = FileSystems.getDefault().getPath(WALLET_PATH, name);
byte[] b = java.nio.file.Files.readAllBytes(path);
json = new String(b);
return new String[]{name, json};
} else {
throw new Exception("Invalid WALLET_PATH " + WALLET_PATH);
}
} catch (Exception ex) {
throw ex;
}
}
示例6: generateWallet
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public static Wallet generateWallet(Context context, ECKeyPair ecKeyPair,
final String password)
throws WalletNotGeneratedException
{
try {
final String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair));
final File destDirectory = Environment.getExternalStorageDirectory().getAbsoluteFile();
Log.d(TAG, Environment.getExternalStorageState());
final String fileName = WalletUtils.generateWalletFile(password, ecKeyPair, destDirectory, false);
final String destFilePath = destDirectory + "/" + fileName;
return new Wallet(ecKeyPair, destFilePath, address);
} catch (CipherException | IOException e)
{
e.printStackTrace();
throw new WalletNotGeneratedException();
}
}
示例7: sign
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public void sign(String pinCode, WalletInfo walletInfo) throws CantSignedException {
try {
final String fullPassword = pinCode + walletInfo.getSalt();
if (getEcKeyPair() != null) {
credentials = Credentials.create(getEcKeyPair());
} else {
credentials = WalletUtils.loadCredentials(fullPassword, getWalletPath());
}
} catch (IOException | CipherException e) {
e.printStackTrace();
throw new CantSignedException();
}
}
示例8: createWalletFile
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
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);
}
}
示例9: setUpClass
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException, CipherException {
credentials = WalletUtils.loadCredentials("password", KEY_FILE1);
testData1 = TestData.staticGenerate(credentials.getAddress());
parity = Parity.build(new HttpService("http://localhost:8545"));
// parity.personalUnlockAccount(credentials.getAddress(), "password", new BigInteger("100000"));
Cmc cmc = Cmc.load(CMC_ADDR, parity, credentials, GAS_PRICE, GAS_LIMIT);
cmcWrapper = new CmcWrapper(cmc);
// cmcWrapper.bootstrap();
String dnsManagerAddress = cmcWrapper.getAddress(APP_NAME);
SolDnsApp solDnsApp = SolDnsApp.load(dnsManagerAddress, parity, credentials, GAS_PRICE, GAS_LIMIT);
solDnsAppWrapper = new SolDnsAppWrapper(solDnsApp);
}
示例10: getModumToken
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
@Bean
public ModumToken getModumToken() throws IOException, CipherException {
Web3j web3j = Web3j.build(new HttpService());
try {
Credentials credentials = WalletUtils.loadCredentials(password, account);
return ModumToken.load(contract, web3j, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);
} catch (FileNotFoundException e) {
return null;
}
}
示例11: MyWallet
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public MyWallet(String privateKey) throws Exception {
if (!WalletUtils.isValidPrivateKey(privateKey)) {
throw new Exception("Private Key error");
}
credentials = Credentials.create(ECKeyPair.create(hexStringToByteArray(privateKey)));
}
示例12: onCreate
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
@Override
public void onCreate(String line) {
if (view != null) {
init();
if (WalletUtils.isValidAddress(line)) {
view.setAddress(line);
}
view.setBalance(balance);
}
}
示例13: inputData
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
private static String inputData(long contractId, String address, String value) throws Exception {
if (!WalletUtils.isValidAddress(address)) {
throw new Exception("address error");
}
String strContract = "0x" + Long.toHexString(contractId);
String strAddress = stringTo64Symbols(address);
String strValue = stringValueFormat(value, 16);
strValue = stringTo64Symbols(strValue);
return strContract + strAddress + strValue;
}
示例14: TestValidAddress
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
@Test
public void TestValidAddress()
throws ExecutionException, InterruptedException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
for (int i = 0; i < 100; i++) {
MyWallet myWallet = new MyWallet();
if (!WalletUtils.isValidAddress(myWallet.getAddress()) || !WalletUtils
.isValidPrivateKey(myWallet.getPrivateKey())) {
assertTrue(false);
}
}
assertTrue(true);
}
示例15: getSignedWallet
import org.web3j.crypto.WalletUtils; //导入依赖的package包/类
public static Wallet getSignedWallet(String walletFile, String pinCode, String salt)
throws CantSignedException
{
try {
Credentials credentials = WalletUtils.loadCredentials(pinCode + salt, walletFile);
return new Wallet(walletFile, credentials);
} catch (IOException | CipherException e) {
e.printStackTrace();
throw new CantSignedException();
}
}