当前位置: 首页>>代码示例>>Java>>正文


Java WalletUtils类代码示例

本文整理汇总了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");
    }
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:14,代码来源:EthereumConfig.java

示例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);
    }
  }
}
 
开发者ID:AtlantPlatform,项目名称:atlant-android,代码行数:20,代码来源:CameraPresenterImpl.java

示例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);
}
 
开发者ID:BSI-Business-Systems-Integration-AG,项目名称:trading-network,代码行数:24,代码来源:Account.java

示例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;
    }
  }
 
开发者ID:BSI-Business-Systems-Integration-AG,项目名称:trading-network,代码行数:26,代码来源:Account.java

示例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;
    }
}
 
开发者ID:jestevez,项目名称:ethereum-java-wallet,代码行数:30,代码来源:EthereumWallet.java

示例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();
    }
}
 
开发者ID:humaniq,项目名称:humaniq-android,代码行数:19,代码来源:Wallet.java

示例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();
    }
}
 
开发者ID:humaniq,项目名称:humaniq-android,代码行数:15,代码来源:Wallet.java

示例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);
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:23,代码来源:KeyImporter.java

示例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);
    }
 
开发者ID:kabl,项目名称:sol-dns,代码行数:18,代码来源:SolDnsAppWrapperTest.java

示例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;
    }
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:11,代码来源:Web3.java

示例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)));
}
 
开发者ID:AtlantPlatform,项目名称:atlant-android,代码行数:7,代码来源:MyWallet.java

示例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);
  }
}
 
开发者ID:AtlantPlatform,项目名称:atlant-android,代码行数:11,代码来源:SendPresenterImpl.java

示例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;
}
 
开发者ID:AtlantPlatform,项目名称:atlant-android,代码行数:11,代码来源:TransactionRestHandler.java

示例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);
}
 
开发者ID:AtlantPlatform,项目名称:atlant-android,代码行数:13,代码来源:UnitTestApp.java

示例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();
    }
}
 
开发者ID:humaniq,项目名称:humaniq-android,代码行数:12,代码来源:Wallet.java


注:本文中的org.web3j.crypto.WalletUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。