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


Java UnreadableWalletException类代码示例

本文整理汇总了Java中org.bitcoinj.store.UnreadableWalletException的典型用法代码示例。如果您正苦于以下问题:Java UnreadableWalletException类的具体用法?Java UnreadableWalletException怎么用?Java UnreadableWalletException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UnreadableWalletException类属于org.bitcoinj.store包,在下文中一共展示了UnreadableWalletException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromProtobuf

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
/**
 * Returns the key chain found in the given list of keys.
 */
public static NxtFamilyKey fromProtobuf(List<Protos.Key> keys, @Nullable KeyCrypter crypter)
        throws UnreadableWalletException {
    if (keys.size() != 2) {
        throw new UnreadableWalletException("Expected 2 keys, NXT secret and Curve25519 " +
                "pub/priv pair, instead got: " + keys.size());
    }

    Protos.Key entropyProto = keys.get(0);
    DeterministicKey entropyKey = KeyUtils.getDeterministicKey(entropyProto, null, crypter);

    Protos.Key publicKeyProto = keys.get(1);
    if (publicKeyProto.getType() != Protos.Key.Type.ORIGINAL) {
        throw new UnreadableWalletException("Unexpected type for NXT public key: " +
                publicKeyProto.getType());
    }
    byte[] publicKeyBytes = publicKeyProto.getPublicKey().toByteArray();

    return new NxtFamilyKey(entropyKey, publicKeyBytes);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:23,代码来源:NxtFamilyKey.java

示例2: encryption

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
public void encryption(SimpleHDKeyChain unencChain) throws UnreadableWalletException {
    DeterministicKey key1 = unencChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    SimpleHDKeyChain encChain = unencChain.toEncrypted("open secret");
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    checkEncryptedKeyChain(encChain, key1);

    // Round-trip to ensure de/serialization works and that we can store two chains and they both deserialize.
    List<Protos.Key> serialized = encChain.toProtobuf();
    System.out.println(protoToString(serialized));
    encChain = SimpleHDKeyChain.fromProtobuf(serialized, encChain.getKeyCrypter());
    checkEncryptedKeyChain(encChain, unencChain.findKeyFromPubKey(key1.getPubKey()));

    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    // Decrypt and check the keys match.
    SimpleHDKeyChain decChain = encChain.toDecrypted("open secret");
    DeterministicKey decKey1 = decChain.findKeyFromPubHash(encKey1.getPubKeyHash());
    DeterministicKey decKey2 = decChain.findKeyFromPubHash(encKey2.getPubKeyHash());
    assertEquals(decKey1.getPubKeyPoint(), encKey1.getPubKeyPoint());
    assertEquals(decKey2.getPubKeyPoint(), encKey2.getPubKeyPoint());
    assertFalse(decKey1.isEncrypted());
    assertFalse(decKey2.isEncrypted());
    assertNotEquals(encKey1.getParent(), decKey1.getParent());   // parts of a different hierarchy
    // Check we can once again derive keys from the decrypted chain.
    decChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).sign(Sha256Hash.ZERO_HASH);
    decChain.getKey(KeyChain.KeyPurpose.CHANGE).sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:27,代码来源:SimpleHDKeyChainTest.java

示例3: testHDAccountNxt

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的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());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:18,代码来源:NxtFamilyTest.java

示例4: restoreWalletFromProtobuf

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
public static Wallet restoreWalletFromProtobuf(final InputStream is, final NetworkParameters expectedNetworkParameters) throws IOException
{
    try
    {
        final Wallet wallet = new WalletProtobufSerializer().readWallet(is);

        if (!wallet.getParams().equals(expectedNetworkParameters))
            throw new IOException("bad wallet network parameters: " + wallet.getParams().getId());

        return wallet;
    }
    catch (final UnreadableWalletException x)
    {
        throw new IOException("unreadable wallet", x);
    }
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:17,代码来源:WalletUtils.java

示例5: decrypt

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
public DeterministicSeed decrypt(KeyCrypter crypter, String passphrase, KeyParameter aesKey) {
    checkState(isEncrypted());
    checkNotNull(encryptedMnemonicCode);
    List<String> mnemonic = null;
    byte[] seed = null;
    try {
        mnemonic = decodeMnemonicCode(crypter.decrypt(encryptedMnemonicCode, aesKey));
        if (encryptedSeed != null) {
            seed = crypter.decrypt(encryptedSeed, aesKey);
        }
    } catch (UnreadableWalletException e) {
        // TODO what is the best way to handle this exception?
        throw new RuntimeException(e);
    }
    return new DeterministicSeed(mnemonic, seed, passphrase, creationTimeSeconds);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:17,代码来源:DeterministicSeed.java

示例6: serializationUnencrypted

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
@Test
public void serializationUnencrypted() throws UnreadableWalletException {
    Utils.setMockClock();
    Date now = Utils.now();
    final ECKey key1 = new ECKey();
    Utils.rollMockClock(5000);
    final ECKey key2 = new ECKey();
    chain.importKeys(ImmutableList.of(key1, key2));
    List<Protos.Key> keys = chain.serializeToProtobuf();
    assertEquals(2, keys.size());
    assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray());
    assertArrayEquals(key2.getPubKey(), keys.get(1).getPublicKey().toByteArray());
    assertArrayEquals(key1.getPrivKeyBytes(), keys.get(0).getSecretBytes().toByteArray());
    assertArrayEquals(key2.getPrivKeyBytes(), keys.get(1).getSecretBytes().toByteArray());
    long normTime = (long) (Math.floor(now.getTime() / 1000) * 1000);
    assertEquals(normTime, keys.get(0).getCreationTimestamp());
    assertEquals(normTime + 5000 * 1000, keys.get(1).getCreationTimestamp());

    chain = BasicKeyChain.fromProtobufUnencrypted(keys);
    assertEquals(2, chain.getKeys().size());
    assertEquals(key1, chain.getKeys().get(0));
    assertEquals(key2, chain.getKeys().get(1));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:24,代码来源:BasicKeyChainTest.java

示例7: testSaveWalletSeedShouldSaveWalletToDiskAndReloadItFromMSeed

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
public void testSaveWalletSeedShouldSaveWalletToDiskAndReloadItFromMSeed() throws IOException, UnreadableWalletException {
	controller = new WalletController(params, testDirectory, 1);
	controller.setupWalletKit(null);
	
       assertNotNull(controller.getRecieveAddress(false));
       //then save a new wallet file. this one is unencrypted!
       System.out.println("Saving Wallet");
       String seedcode = controller.saveWalletSeed(testWalletDirectory+"testWallet1");
       assertNotNull(seedcode);
       System.out.println(seedcode);
       
       //Load from file 
       String passphrase = "";
       Long creationtime = System.currentTimeMillis();
       
       DeterministicSeed seed = new DeterministicSeed(seedcode, null, passphrase, creationtime);

	WalletController loadedController = new WalletController(params, testDirectory, 1);
	loadedController.setupWalletKit(seed);
	loadedController.getWallet().toString();
       
	assertEquals(controller.getWallet().getWatchingKey(), loadedController.getWallet().getWatchingKey());
       controller.shutdown();
       loadedController.shutdown();
       cleanup();
}
 
开发者ID:JohnnyCryptoCoin,项目名称:speciebox,代码行数:27,代码来源:WalletControllerTest.java

示例8: getType

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
private static CoinType getType(Protos.WalletPocket proto) throws UnreadableWalletException {
    try {
        return CoinID.typeFromId(proto.getNetworkIdentifier());
    } catch (IllegalArgumentException e) {
        throw new UnreadableWalletException("Unknown network parameters ID " +
                proto.getNetworkIdentifier());
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:9,代码来源:WalletProtobufSerializer.java

示例9: loadFromFile

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
/**
 * Returns a wallet deserialized from the given file.
 */
public static Wallet loadFromFile(File f) throws UnreadableWalletException {
    try {
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(f);
            return loadFromFileStream(stream);
        } finally {
            if (stream != null) stream.close();
        }
    } catch (IOException e) {
        throw new UnreadableWalletException("Could not open file", e);
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:17,代码来源:Wallet.java

示例10: decodeMnemonicCode

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
private static List<String> decodeMnemonicCode(byte[] mnemonicCode) throws UnreadableWalletException {
    try {
        return Splitter.on(" ").splitToList(new String(mnemonicCode, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new UnreadableWalletException(e.toString());
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:8,代码来源:Wallet.java

示例11: readWallet

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
/**
 * <p>Loads wallet data from the given protocol buffer and inserts it into the given Wallet object. This is primarily
 * useful when you wish to pre-register extension objects. Note that if loading fails the provided Wallet object
 * may be in an indeterminate state and should be thrown away.</p>
 *
 * <p>A wallet can be unreadable for various reasons, such as inability to open the file, corrupt data, internally
 * inconsistent data, a wallet extension marked as mandatory that cannot be handled and so on. You should always
 * handle {@link UnreadableWalletException} and communicate failure to the user in an appropriate manner.</p>
 *
 * @throws UnreadableWalletException thrown in various error conditions (see description).
 */
public NxtFamilyWallet readWallet(Protos.WalletPocket walletProto, @Nullable KeyCrypter keyCrypter) throws UnreadableWalletException {
    CoinType coinType;
    try {
        coinType = CoinID.typeFromId(walletProto.getNetworkIdentifier());
    } catch (IllegalArgumentException e) {
        throw new UnreadableWalletException("Unknown network parameters ID " + walletProto.getNetworkIdentifier());
    }

    // Read the scrypt parameters that specify how encryption and decryption is performed.
    NxtFamilyKey rootKey;
    if (keyCrypter != null) {
        rootKey = NxtFamilyKey.fromProtobuf(walletProto.getKeyList(), keyCrypter);
    } else {
        rootKey = NxtFamilyKey.fromProtobuf(walletProto.getKeyList());
    }

    NxtFamilyWallet pocket;
    if (walletProto.hasId()) {
        pocket = new NxtFamilyWallet(walletProto.getId(), rootKey, coinType);
    } else {
        pocket = new NxtFamilyWallet(rootKey, coinType);
    }

    if (walletProto.hasDescription()) {
        pocket.setDescription(walletProto.getDescription());
    }

    // TODO ready transactions? Check com.fillerino.core.wallet WalletPocketProtobufSerializer

    return pocket;
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:43,代码来源:NxtFamilyWalletProtobufSerializer.java

示例12: serializeUnencryptedChildRoot

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
@Test
public void serializeUnencryptedChildRoot() throws UnreadableWalletException {
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey rootKey = hierarchy.get(BitcoinTest.get().getBip44Path(0), false, true);
    SimpleHDKeyChain newChain = new SimpleHDKeyChain(rootKey);
    serializeUnencrypted(newChain, DETERMINISTIC_WALLET_SERIALIZATION_TXT_CHILD_ROOT_KEY);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:8,代码来源:SimpleHDKeyChainTest.java

示例13: serializeUnencrypted

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
public void serializeUnencrypted(SimpleHDKeyChain keyChain, String expectedSerialization) throws UnreadableWalletException {
    keyChain.setLookaheadSize(10);

    keyChain.maybeLookAhead();
    DeterministicKey key1 = keyChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = keyChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = keyChain.getKey(KeyChain.KeyPurpose.CHANGE);
    List<Protos.Key> keys = keyChain.toProtobuf();
    // 1 master key, 1 account key, 2 internal keys, 3 derived, 20 lookahead and 5 lookahead threshold.
    int numItems =
                      1  // master key/account key
                    + 2  // ext/int parent keys
                    + (keyChain.getLookaheadSize() + keyChain.getLookaheadThreshold()) * 2   // lookahead zone on each chain
            ;
    assertEquals(numItems, keys.size());

    // Get another key that will be lost during round-tripping, to ensure we can derive it again.
    DeterministicKey key4 = keyChain.getKey(KeyChain.KeyPurpose.CHANGE);

    String sb = protoToString(keys);
    assertEquals(expectedSerialization, sb);

    // Round trip the data back and forth to check it is preserved.
    int oldLookaheadSize = keyChain.getLookaheadSize();
    keyChain = SimpleHDKeyChain.fromProtobuf(keys, null);
    assertEquals(expectedSerialization, protoToString(keyChain.toProtobuf()));
    assertEquals(key1, keyChain.findKeyFromPubHash(key1.getPubKeyHash()));
    assertEquals(key2, keyChain.findKeyFromPubHash(key2.getPubKeyHash()));
    assertEquals(key3, keyChain.findKeyFromPubHash(key3.getPubKeyHash()));
    assertEquals(key4, keyChain.getKey(KeyChain.KeyPurpose.CHANGE));
    key1.sign(Sha256Hash.ZERO_HASH);
    key2.sign(Sha256Hash.ZERO_HASH);
    key3.sign(Sha256Hash.ZERO_HASH);
    key4.sign(Sha256Hash.ZERO_HASH);
    assertEquals(oldLookaheadSize, keyChain.getLookaheadSize());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:37,代码来源:SimpleHDKeyChainTest.java

示例14: encryptionChildRoot

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的package包/类
@Test
public void encryptionChildRoot() throws UnreadableWalletException {
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey rootKey = hierarchy.get(BitcoinTest.get().getBip44Path(0), false, true);
    SimpleHDKeyChain newChain = new SimpleHDKeyChain(rootKey);

    encryption(newChain);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:9,代码来源:SimpleHDKeyChainTest.java

示例15: setup

import org.bitcoinj.store.UnreadableWalletException; //导入依赖的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);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:NxtFamilyWalletTest.java


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