本文整理汇总了Java中org.bitcoinj.crypto.MnemonicException类的典型用法代码示例。如果您正苦于以下问题:Java MnemonicException类的具体用法?Java MnemonicException怎么用?Java MnemonicException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MnemonicException类属于org.bitcoinj.crypto包,在下文中一共展示了MnemonicException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHDAccountNxt
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
@Test
public void testHDAccountNxt() throws MnemonicException, UnreadableWalletException {
DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0);
DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
DeterministicKey entropy = hierarchy.get(NxtMain.get().getBip44Path(0), false, true);
NxtFamilyKey nxtKey = new NxtFamilyKey(entropy, null, null);
byte[] privateKey = nxtKey.getPrivateKey();
byte[] publicKey = nxtKey.getPublicKey();
NxtAddress address = new NxtAddress(NxtMain.get(), publicKey);
assertArrayEquals(nxtPrivateKey, privateKey);
assertArrayEquals(nxtPublicKey, publicKey);
assertEquals(nxtRsAddress, address.toString());
assertEquals(nxtAccountId, address.getAccountId());
}
示例2: 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;
}
示例3: initFromMasterSeed
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
private Wallet initFromMasterSeed(final String masterSeed) {
try {
final DeterministicSeed seed = getSeed(masterSeed);
seed.check();
return constructFromSeed(seed);
} catch (final UnreadableWalletException | MnemonicException e) {
throw new RuntimeException("Unable to create wallet. Seed is invalid");
}
}
示例4: 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;
}
示例5: 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);
}
示例6: 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;
}
示例7: Wallet
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
public Wallet(List<String> mnemonic, @Nullable String password) throws MnemonicException {
MnemonicCode.INSTANCE.check(mnemonic);
password = password == null ? "" : password;
seed = new DeterministicSeed(mnemonic, null, password, 0);
masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
accountsByType = new LinkedHashMap<CoinType, ArrayList<WalletAccount>>();
accounts = new LinkedHashMap<String, WalletAccount>();
}
示例8: setup
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
@Before
public void setup() throws MnemonicException, UnreadableWalletException {
DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0);
DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
hierarchy = new DeterministicHierarchy(masterKey);
wallet = new Wallet(recoveryPhrase);
nxtAccount = (NxtFamilyWallet)wallet.createAccount(NXT, null);
otherAccount = new NxtFamilyWallet(hierarchy.get(NXT.getBip44Path(1), false, true), NXT);
}
示例9: testHDAccountNxt
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
@Test
public void testHDAccountNxt() throws MnemonicException {
byte[] privateKey = nxtAccount.rootKey.getPrivateKey();
byte[] publicKey = nxtAccount.getPublicKey();
assertArrayEquals(nxtPrivateKey, privateKey);
assertEquals(nxtRsAddress, nxtAccount.getPublicKeyMnemonic());
assertArrayEquals(nxtPublicKey, publicKey);
NxtAddress address = (NxtAddress) nxtAccount.getReceiveAddress();
assertEquals(nxtRsAddress, address.toString());
assertEquals(nxtAccountId, address.getAccountId());
}
示例10: setup
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
@Before
public void setup() throws IOException, MnemonicException {
BriefLogFormatter.init();
wallet = new Wallet(MNEMONIC);
ImmutableList<CoinType> typesToCreate = ImmutableList.of(BitcoinMain.get(),
LitecoinMain.get(), DogecoinMain.get());
wallet.createAccounts(typesToCreate, true, aesKey);
}
示例11: createFromMasterSeed
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
public Single<HDWallet> createFromMasterSeed(final String masterSeed) {
return Single.fromCallable(() -> {
try {
final DeterministicSeed seed = getSeed(masterSeed);
seed.check();
final Wallet wallet = constructFromSeed(seed);
deriveKeysFromWallet(wallet);
saveMasterSeedToStorage(masterSeed);
return this;
} catch (final UnreadableWalletException | MnemonicException e) {
throw new InvalidMasterSeedException(e);
}
});
}
示例12: initialize
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
@Override
protected void initialize() {
addTitledGroupBg(root, gridRow, 2, Res.get("account.seed.backup.title"));
displaySeedWordsTextArea = addLabelTextArea(root, gridRow, Res.get("seed.seedWords"), "", Layout.FIRST_ROW_DISTANCE).second;
displaySeedWordsTextArea.setPrefHeight(60);
displaySeedWordsTextArea.setEditable(false);
datePicker = addLabelDatePicker(root, ++gridRow, Res.get("seed.date")).second;
datePicker.setMouseTransparent(true);
addTitledGroupBg(root, ++gridRow, 2, Res.get("seed.restore.title"), Layout.GROUP_DISTANCE);
seedWordsTextArea = addLabelTextArea(root, gridRow, Res.get("seed.seedWords"), "", Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
seedWordsTextArea.setPrefHeight(60);
restoreDatePicker = addLabelDatePicker(root, ++gridRow, Res.get("seed.date")).second;
restoreButton = addButtonAfterGroup(root, ++gridRow, Res.get("seed.restore"));
addTitledGroupBg(root, ++gridRow, 1, Res.get("shared.information"), Layout.GROUP_DISTANCE);
addMultilineLabel(root, gridRow, Res.get("account.seed.info"),
Layout.FIRST_ROW_AND_GROUP_DISTANCE);
seedWordsValidChangeListener = (observable, oldValue, newValue) -> {
if (newValue) {
seedWordsTextArea.getStyleClass().remove("validation-error");
} else {
seedWordsTextArea.getStyleClass().add("validation-error");
}
};
seedWordsTextAreaChangeListener = (observable, oldValue, newValue) -> {
seedWordsEdited.set(true);
try {
MnemonicCode codec = new MnemonicCode();
codec.check(Splitter.on(" ").splitToList(newValue));
seedWordsValid.set(true);
} catch (IOException | MnemonicException e) {
seedWordsValid.set(false);
}
};
}
示例13: 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)
{ }
}
}
示例14: showRestoreScreen
import org.bitcoinj.crypto.MnemonicException; //导入依赖的package包/类
private void showRestoreScreen() {
Label headLine2Label = new AutoTooltipLabel(Res.get("seed.restore.title"));
headLine2Label.setId("popup-headline");
headLine2Label.setMouseTransparent(true);
GridPane.setHalignment(headLine2Label, HPos.LEFT);
GridPane.setRowIndex(headLine2Label, ++rowIndex);
GridPane.setColumnSpan(headLine2Label, 2);
GridPane.setMargin(headLine2Label, new Insets(30, 0, 0, 0));
gridPane.getChildren().add(headLine2Label);
Separator separator = new Separator();
separator.setMouseTransparent(true);
separator.setOrientation(Orientation.HORIZONTAL);
separator.getStyleClass().add("separator");
GridPane.setHalignment(separator, HPos.CENTER);
GridPane.setRowIndex(separator, ++rowIndex);
GridPane.setColumnSpan(separator, 2);
gridPane.getChildren().add(separator);
Tuple2<Label, TextArea> tuple = addLabelTextArea(gridPane, ++rowIndex, Res.get("seed.seedWords"), "", 5);
seedWordsTextArea = tuple.second;
seedWordsTextArea.setPrefHeight(60);
seedWordsTextArea.getStyleClass().add("text-area");
Tuple2<Label, DatePicker> labelDatePickerTuple2 = addLabelDatePicker(gridPane, ++rowIndex,
Res.get("seed.creationDate"));
datePicker = labelDatePickerTuple2.second;
restoreButton = addButton(gridPane, ++rowIndex, Res.get("seed.restore"));
restoreButton.setDefaultButton(true);
stage.setHeight(340);
// wallet creation date is not encrypted
walletCreationDate = Instant.ofEpochSecond(walletsManager.getChainSeedCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
log.info("walletCreationDate " + walletCreationDate);
datePicker.setValue(walletCreationDate);
restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !seedWordsEdited.get(),
seedWordsValid, seedWordsEdited));
seedWordsValidChangeListener = (observable, oldValue, newValue) -> {
if (newValue) {
seedWordsTextArea.getStyleClass().remove("validation-error");
} else {
seedWordsTextArea.getStyleClass().add("validation-error");
}
};
wordsTextAreaChangeListener = (observable, oldValue, newValue) -> {
seedWordsEdited.set(true);
try {
MnemonicCode codec = new MnemonicCode();
codec.check(Splitter.on(" ").splitToList(newValue));
seedWordsValid.set(true);
} catch (IOException | MnemonicException e) {
seedWordsValid.set(false);
}
};
seedWordsValid.addListener(seedWordsValidChangeListener);
seedWordsTextArea.textProperty().addListener(wordsTextAreaChangeListener);
restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !seedWordsEdited.get(),
seedWordsValid, seedWordsEdited));
restoreButton.setOnAction(e -> onRestore());
seedWordsTextArea.getStyleClass().remove("validation-error");
datePicker.getStyleClass().remove("validation-error");
layout();
}
示例15: 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);
}