本文整理汇总了Java中org.bitcoinj.crypto.MnemonicException.MnemonicLengthException方法的典型用法代码示例。如果您正苦于以下问题:Java MnemonicException.MnemonicLengthException方法的具体用法?Java MnemonicException.MnemonicLengthException怎么用?Java MnemonicException.MnemonicLengthException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.crypto.MnemonicException
的用法示例。
在下文中一共展示了MnemonicException.MnemonicLengthException方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRandomSeedWords
import org.bitcoinj.crypto.MnemonicException; //导入方法依赖的package包/类
private List<String> getRandomSeedWords() {
List<String> seedWords;
try {
final MnemonicCode mnemonicCode = new MnemonicCode();
seedWords = mnemonicCode.toMnemonic(getRandomSeed());
} catch (IOException | MnemonicException.MnemonicLengthException e) {
throw new RuntimeException(e);
}
return seedWords;
}
示例2: newWallet
import org.bitcoinj.crypto.MnemonicException; //导入方法依赖的package包/类
/**
* Create new wallet.
*
* @param int nbWords number of words in menmonic
* @param String passphrase optional BIP39 passphrase
* @param int nbAccounts create this number of accounts
*
* @return Wallet
*
*/
public Wallet newWallet(int nbWords, String passphrase, int nbAccounts) throws IOException, MnemonicException.MnemonicLengthException {
Wallet hdw = null;
if((nbWords % 3 != 0) || (nbWords < 12 || nbWords > 24)) {
nbWords = 12;
}
// len == 16 (12 words), len == 24 (18 words), len == 32 (24 words)
int len = (nbWords / 3) * 4;
if(passphrase == null) {
passphrase = "";
}
NetworkParameters params = MainNetParams.get();
SecureRandom random = new SecureRandom();
byte seed[] = new byte[len];
random.nextBytes(seed);
MnemonicCode mc = new MnemonicCode();
hdw = new Wallet(mc, params, seed, passphrase);
wallets.clear();
wallets.add(hdw);
return hdw;
}
示例3: get
import org.bitcoinj.crypto.MnemonicException; //导入方法依赖的package包/类
/**
* Get wallet for this instance.
*
* @return Wallet
*
*/
public Wallet get() throws IOException, MnemonicException.MnemonicLengthException {
if(wallets.size() < 1) {
wallets.clear();
wallets.add(newWallet(12, "", 1));
}
return wallets.get(0);
}
示例4: bytesToMnemonic
import org.bitcoinj.crypto.MnemonicException; //导入方法依赖的package包/类
public static List<String> bytesToMnemonic(byte[] bytes) {
List<String> mnemonic;
try {
mnemonic = MnemonicCode.INSTANCE.toMnemonic(bytes);
} catch (MnemonicException.MnemonicLengthException e) {
throw new RuntimeException(e); // should not happen, we have 16bytes of entropy
}
return mnemonic;
}
示例5: onStart
import org.bitcoinj.crypto.MnemonicException; //导入方法依赖的package包/类
@Override
public void onStart()
{
super.onStart();
WalletState.getState().triggerUpdate();
if (WalletState.getState().getFirstLaunch())
{
// At first launch, calculate the mnemonic and display it to the user
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
try
{
final List<String> mnemonic = MnemonicCode.INSTANCE.toMnemonic(
WalletState.getState().getConfiguration().getSeed());
final String fullMnemonic = Joiner.on(" ").join(mnemonic);
alertDialog.setTitle(getString(R.string.general_first_launch_title));
alertDialog.setMessage(getString(R.string.general_first_launch_message, fullMnemonic));
alertDialog.setPositiveButton(
getString(R.string.general_first_launch_close),
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
WalletState.getState().unsetFirstLaunch();
}
});
alertDialog.show();
}
catch (MnemonicException.MnemonicLengthException exception)
{ }
}
}
示例6: Wallet
import org.bitcoinj.crypto.MnemonicException; //导入方法依赖的package包/类
/**
* Constructor for wallet.
*
* @param MnemonicCode mc mnemonic code object
* @param NetworkParameters params
* @param byte[] seed seed for this wallet
* @param String passphrase optional BIP39 passphrase
* @param int nbAccounts number of accounts to create
*
*/
public Wallet(MnemonicCode mc, NetworkParameters params, byte[] seed, String passphrase) throws MnemonicException.MnemonicLengthException {
wordList = mc.toMnemonic(seed);
init(params, seed, passphrase);
}