org.web3j.crypto.Wallet.createLight()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.web3j.crypto.Wallet.createLight()方法的一些代码示例,展示了Wallet.createLight()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wallet.createLight()方法的具体详情如下:
包路径:org.web3j.crypto.Wallet
类名称:Wallet
方法名:createLight

Wallet.createLight介绍

暂无

代码示例

代码示例来源:origin: web3j/web3j

public static String generateWalletFile(
    String password, ECKeyPair ecKeyPair, File destinationDirectory, boolean useFullScrypt)
    throws CipherException, IOException {
  WalletFile walletFile;
  if (useFullScrypt) {
    walletFile = Wallet.createStandard(password, ecKeyPair);
  } else {
    walletFile = Wallet.createLight(password, ecKeyPair);
  }
  String fileName = getWalletFileName(walletFile);
  File destination = new File(destinationDirectory, fileName);
  objectMapper.writeValue(destination, walletFile);
  return fileName;
}

代码示例来源:origin: web3j/web3j

@Test
public void testCreateLight() throws Exception {
  testCreate(Wallet.createLight(SampleKeys.PASSWORD, SampleKeys.KEY_PAIR));
}

代码示例来源:origin: web3j/web3j

@Test
public void testEncryptDecryptLight() throws Exception {
  testEncryptDecrypt(Wallet.createLight(SampleKeys.PASSWORD, SampleKeys.KEY_PAIR));
}

代码示例来源:origin: uncleleonfan/FunWallet

@Override
  public void run() {
    try {
      File walletDir = contextWrapper.getDir("eth", Context.MODE_PRIVATE);
      if (walletDir.exists() && walletDir.listFiles().length > 0) {
        File[] files = walletDir.listFiles();
        wallet = objectMapper.readValue(files[0], WalletFile.class);
      } else {
        ECKeyPair ecKeyPair = Keys.createEcKeyPair();
        wallet  = Wallet.createLight(PASSWORD, ecKeyPair);
        String walletFileName = getWalletFileName(wallet);
        File destination = new File(walletDir, walletFileName);
        objectMapper.writeValue(destination, wallet);
      }
      if (listener != null && wallet != null) {
        listener.onWalletLoaded(wallet);
      }
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (NoSuchProviderException e) {
      e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
      e.printStackTrace();
    } catch (CipherException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
});

代码示例来源:origin: ethjava/web3j-sample

System.out.println("助记词种子 " + Arrays.toString(mnemonicSeedBytes));
ECKeyPair mnemonicKeyPair = ECKeyPair.create(mnemonicSeedBytes);
WalletFile walletFile = Wallet.createLight(password, mnemonicKeyPair);
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
WalletFile walletFile = Wallet.createLight(password, keyPair);
System.out.println("eth address " + "0x" + walletFile.getAddress());
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();

代码示例来源:origin: uncleleonfan/FunWallet

private WalletFile createWalletFile(List<String> words) throws MnemonicException.MnemonicLengthException, MnemonicException.MnemonicWordException, MnemonicException.MnemonicChecksumException, CipherException {
  byte[] seeds = MnemonicCode.INSTANCE.toEntropy(words);
  DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(seeds);
  DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(masterPrivateKey);
  DeterministicKey child = deterministicHierarchy.deriveChild(DeterministicKeyChain.BIP44_ACCOUNT_ZERO_PATH, true,
      true, ChildNumber.ZERO);
  ECKeyPair ecKeyPair = ECKeyPair.create(child.getPrivKeyBytes());
  return Wallet.createLight(PASSWORD, ecKeyPair);
}

代码示例来源:origin: terryjiao/BitcoinWallet

private static List<String> generateKeyPairs(String mnemonic) throws InvalidKeySpecException, NoSuchAlgorithmException, CipherException {
  // 1. we just need eth wallet for now
  AddressIndex ethAddressIndex = BIP44.m().purpose44().coinType(60).account(0).external().address(0);
  AddressIndex btcAddressIndex = BIP44.m().purpose44().coinType(0).account(0).external().address(0);
  // 2. calculate seed from mnemonics , then get master/root key ; Note that the bip39 passphrase we set "" for common
  String seed;
  String salt = "mnemonic";
  seed = getSeed(mnemonic, salt);
  System.out.println(seed);
  ExtendedPrivateKey rootKey = ExtendedPrivateKey.fromSeed(hexStringToByteArray(seed), Bitcoin.MAIN_NET);
  // 3. get child private key deriving from master/root key
  ExtendedPrivateKey childPrivateKey = rootKey.derive(ethAddressIndex, AddressIndex.DERIVATION);
  // 4. get key pair
  byte[] privateKeyBytes = childPrivateKey.getKey(); //child private key
  ECKeyPair keyPair = ECKeyPair.create(privateKeyBytes);
  walletFile = Wallet.createLight(password, keyPair);
  List<String> returnList = EthAddress(childPrivateKey, keyPair);
  childPrivateKey = rootKey.derive(btcAddressIndex, AddressIndex.DERIVATION);
  bitcoinAddress(childPrivateKey);
  return returnList;
}

相关文章

微信公众号

最新文章

更多