org.bitcoinj.core.Utils Java Examples
The following examples show how to use
org.bitcoinj.core.Utils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MnemonicCodeTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@Test public void testVectors() throws Exception { for (int ii = 0; ii < vectors.length; ii += 3) { String vecData = vectors[ii]; String vecCode = vectors[ii+1]; String vecSeed = vectors[ii+2]; List<String> code = mc.toMnemonic(HEX.decode(vecData)); byte[] seed = MnemonicCode.toSeed(code, "TREZOR"); byte[] entropy = mc.toEntropy(split(vecCode)); assertEquals(vecData, HEX.encode(entropy)); assertEquals(vecCode, Utils.join(code)); assertEquals(vecSeed, HEX.encode(seed)); } }
Example #2
Source File: PaymentChannelServerTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowExactTimeWindow() { final TwoWayChannelMessage message = createClientVersionMessage(); final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>(); connection.sendToClient(capture(initiateCapture)); replay(connection); final int expire = 24 * 60 * 60 - 60; // This the default defined in paymentchannel.proto dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){ @Override public long getMaxTimeWindow() { return expire; } @Override public long getMinTimeWindow() { return expire; } }, connection); dut.connectionOpen(); long expectedExpire = Utils.currentTimeSeconds() + expire; dut.receiveMessage(message); assertServerVersion(); assertExpireTime(expectedExpire, initiateCapture); }
Example #3
Source File: DeterministicKeyChain.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public String toString(boolean includePrivateKeys, @Nullable KeyParameter aesKey, NetworkParameters params) { final DeterministicKey watchingKey = getWatchingKey(); final StringBuilder builder = new StringBuilder(); if (seed != null) { if (includePrivateKeys) { DeterministicSeed decryptedSeed = seed.isEncrypted() ? seed.decrypt(getKeyCrypter(), DEFAULT_PASSPHRASE_FOR_MNEMONIC, aesKey) : seed; final List<String> words = decryptedSeed.getMnemonicCode(); builder.append("Seed as words: ").append(Utils.SPACE_JOINER.join(words)).append('\n'); builder.append("Seed as hex: ").append(decryptedSeed.toHexString()).append('\n'); } else { if (seed.isEncrypted()) builder.append("Seed is encrypted\n"); } builder.append("Seed birthday: ").append(seed.getCreationTimeSeconds()).append(" [") .append(Utils.dateTimeFormat(seed.getCreationTimeSeconds() * 1000)).append("]\n"); } else { builder.append("Key birthday: ").append(watchingKey.getCreationTimeSeconds()).append(" [") .append(Utils.dateTimeFormat(watchingKey.getCreationTimeSeconds() * 1000)).append("]\n"); } builder.append("Key to watch: ").append(watchingKey.serializePubB58(params)).append('\n'); formatAddresses(includePrivateKeys, aesKey, params, builder); return builder.toString(); }
Example #4
Source File: BasicKeyChainTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@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)); }
Example #5
Source File: PaymentChannelServerTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowExactTimeWindow() { final TwoWayChannelMessage message = createClientVersionMessage(); final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>(); connection.sendToClient(capture(initiateCapture)); replay(connection); final int expire = 24 * 60 * 60 - 60; // This the default defined in paymentchannel.proto dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties() { @Override public long getMaxTimeWindow() { return expire; } @Override public long getMinTimeWindow() { return expire; } }, connection); dut.connectionOpen(); long expectedExpire = Utils.currentTimeSeconds() + expire; dut.receiveMessage(message); assertServerVersion(); assertExpireTime(expectedExpire, initiateCapture); }
Example #6
Source File: SignPaymentAccountsWindow.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
private void addAccountsToSignContent() { removeContent(); addECKeyField(); headLineLabel.setText(Res.get("popup.accountSigning.signAccounts.headline")); descriptionLabel.setText(Res.get("popup.accountSigning.signAccounts.description", selectedPaymentAccountsList.getItems().size())); ((AutoTooltipButton) actionButton).updateText(Res.get("popup.accountSigning.signAccounts.button")); actionButton.setOnAction(a -> { ECKey arbitratorKey = arbitratorManager.getRegistrationKey(privateKey.getText()); if (arbitratorKey != null) { String arbitratorPubKeyAsHex = Utils.HEX.encode(arbitratorKey.getPubKey()); boolean isKeyValid = arbitratorManager.isPublicKeyInList(arbitratorPubKeyAsHex); if (isKeyValid) { selectedPaymentAccountsList.getItems().forEach(item -> accountAgeWitnessService.arbitratorSignAccountAgeWitness(item.getTradeAmount(), item.getAccountAgeWitness(), arbitratorKey, item.getPeersPubKey())); addSuccessContent(); } } else { new Popup().error(Res.get("popup.accountSigning.signAccounts.ECKey.error")).onClose(this::hide).show(); } }); }
Example #7
Source File: GenerateLowSTests.java From GreenBits with GNU General Public License v3.0 | 6 votes |
/** * Convert a script to a string format that suits the style expected in * tx_valid.json and tx_invalid.json. */ private static String scriptToString(Script scriptPubKey) { final StringBuilder buf = new StringBuilder(); for (ScriptChunk chunk: scriptPubKey.getChunks()) { if (buf.length() > 0) { buf.append(" "); } if (chunk.isOpCode()) { buf.append(getOpCodeName(chunk.opcode)); } else if (chunk.data != null) { // Data chunk buf.append("0x") .append(Integer.toString(chunk.opcode, 16)).append(" 0x") .append(Utils.HEX.encode(chunk.data)); } else { buf.append(chunk.toString()); } } return buf.toString(); }
Example #8
Source File: PaymentChannelServerTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowExactTimeWindow() { final TwoWayChannelMessage message = createClientVersionMessage(); final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>(); connection.sendToClient(capture(initiateCapture)); replay(connection); final int expire = 24 * 60 * 60 - 60; // This the default defined in paymentchannel.proto dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){ @Override public long getMaxTimeWindow() { return expire; } @Override public long getMinTimeWindow() { return expire; } }, connection); dut.connectionOpen(); long expectedExpire = Utils.currentTimeSeconds() + expire; dut.receiveMessage(message); assertServerVersion(); assertExpireTime(expectedExpire, initiateCapture); }
Example #9
Source File: MnemonicCode.java From bcm-android with GNU General Public License v3.0 | 6 votes |
/** * Convert mnemonic word list to seed. */ public static byte[] toSeed(List<String> words, String passphrase) { checkNotNull(passphrase, "A null passphrase is not allowed."); // To create binary seed from mnemonic, we use PBKDF2 function // with mnemonic sentence (in UTF-8) used as a password and // string "mnemonic" + passphrase (again in UTF-8) used as a // salt. Iteration count is set to 4096 and HMAC-SHA512 is // used as a pseudo-random function. Desired length of the // derived key is 512 bits (= 64 bytes). // String pass = Utils.SPACE_JOINER.join(words); String salt = "mnemonic" + passphrase; final Stopwatch watch = Stopwatch.createStarted(); byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64); watch.stop(); log.info("PBKDF2 took {}", watch); return seed; }
Example #10
Source File: KeyChainGroupTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void deterministicUpgradeRotating() throws Exception { group = new KeyChainGroup(MAINNET); group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests. long now = Utils.currentTimeSeconds(); ECKey key1 = new ECKey(); Utils.rollMockClock(86400); ECKey key2 = new ECKey(); Utils.rollMockClock(86400); ECKey key3 = new ECKey(); group.importKeys(key2, key1, key3); group.upgradeToDeterministic(now + 10, null); DeterministicSeed seed = group.getActiveKeyChain().getSeed(); assertNotNull(seed); // Check we used the right key: oldest non rotating. byte[] truncatedBytes = Arrays.copyOfRange(key2.getSecretBytes(), 0, 16); assertArrayEquals(seed.getEntropyBytes(), truncatedBytes); }
Example #11
Source File: MnemonicCode.java From GreenBits with GNU General Public License v3.0 | 6 votes |
/** * Convert mnemonic word list to seed. */ public static byte[] toSeed(List<String> words, String passphrase) { // To create binary seed from mnemonic, we use PBKDF2 function // with mnemonic sentence (in UTF-8) used as a password and // string "mnemonic" + passphrase (again in UTF-8) used as a // salt. Iteration count is set to 4096 and HMAC-SHA512 is // used as a pseudo-random function. Desired length of the // derived key is 512 bits (= 64 bytes). // String pass = Utils.join(words); String salt = "mnemonic" + passphrase; final Stopwatch watch = Stopwatch.createStarted(); byte[] seed = PBKDF2SHA512.derive(pass, salt, PBKDF2_ROUNDS, 64); watch.stop(); log.info("PBKDF2 took {}", watch); return seed; }
Example #12
Source File: BasicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void keysBeforeAndAfter() throws Exception { Utils.setMockClock(); long now = Utils.currentTimeSeconds(); final ECKey key1 = new ECKey(); Utils.rollMockClock(86400); final ECKey key2 = new ECKey(); final List<ECKey> keys = Lists.newArrayList(key1, key2); assertEquals(2, chain.importKeys(keys)); assertNull(chain.findOldestKeyAfter(now + 86400 * 2)); assertEquals(key1, chain.findOldestKeyAfter(now - 1)); assertEquals(key2, chain.findOldestKeyAfter(now + 86400 - 1)); assertEquals(2, chain.findKeysBefore(now + 86400 * 2).size()); assertEquals(1, chain.findKeysBefore(now + 1).size()); assertEquals(0, chain.findKeysBefore(now - 1).size()); }
Example #13
Source File: BasicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@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)); }
Example #14
Source File: DeterministicKeyChain.java From green_android with GNU General Public License v3.0 | 6 votes |
public String toString(boolean includePrivateKeys, NetworkParameters params) { final DeterministicKey watchingKey = getWatchingKey(); final StringBuilder builder = new StringBuilder(); if (seed != null) { if (seed.isEncrypted()) { builder.append("Seed is encrypted\n"); } else if (includePrivateKeys) { final List<String> words = seed.getMnemonicCode(); builder.append("Seed as words: ").append(Utils.join(words)).append('\n'); builder.append("Seed as hex: ").append(seed.toHexString()).append('\n'); } builder.append("Seed birthday: ").append(seed.getCreationTimeSeconds()).append(" [") .append(Utils.dateTimeFormat(seed.getCreationTimeSeconds() * 1000)).append("]\n"); } else { builder.append("Key birthday: ").append(watchingKey.getCreationTimeSeconds()).append(" [") .append(Utils.dateTimeFormat(watchingKey.getCreationTimeSeconds() * 1000)).append("]\n"); } builder.append("Key to watch: ").append(watchingKey.serializePubB58(params)).append('\n'); formatAddresses(includePrivateKeys, params, builder); return builder.toString(); }
Example #15
Source File: Crypto.java From java-sdk with Apache License 2.0 | 5 votes |
public static byte[] sign(byte[] msg, ECKey k) throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] msgHash = digest.digest(msg); ECKey.ECDSASignature signature = k.sign(Sha256Hash.wrap(msgHash)); byte[] result = new byte[64]; System.arraycopy(Utils.bigIntegerToBytes(signature.r, 32), 0, result, 0, 32); System.arraycopy(Utils.bigIntegerToBytes(signature.s, 32), 0, result, 32, 32); return result; }
Example #16
Source File: PaymentChannelServerTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() { broadcaster = createMock(TransactionBroadcaster.class); wallet = createMock(Wallet.class); connection = createMock(PaymentChannelServer.ServerConnection.class); serverVersionCapture = new Capture<TwoWayChannelMessage>(); connection.sendToClient(capture(serverVersionCapture)); Utils.setMockClock(); }
Example #17
Source File: WalletTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test public void keyCreationTime() throws Exception { Utils.setMockClock(); long now = Utils.currentTimeSeconds(); wallet = new Wallet(PARAMS); assertEquals(now, wallet.getEarliestKeyCreationTime()); Utils.rollMockClock(60); wallet.freshReceiveKey(); assertEquals(now, wallet.getEarliestKeyCreationTime()); }
Example #18
Source File: ScriptChunk.java From green_android with GNU General Public License v3.0 | 5 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); if (isOpCode()) { buf.append(getOpCodeName(opcode)); } else if (data != null) { // Data chunk buf.append(getPushDataName(opcode)).append("[").append(Utils.HEX.encode(data)).append("]"); } else { // Small num buf.append(Script.decodeFromOpN(opcode)); } return buf.toString(); }
Example #19
Source File: ExportJsonFilesService.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private List<JsonTxOutput> getJsonTxOutputs(Tx tx) { JsonTxType jsonTxType = getJsonTxType(tx); String jsonTxTypeDisplayString = getJsonTxTypeDisplayString(jsonTxType); return tx.getTxOutputs().stream() .map(txOutput -> { boolean isBsqTxOutputType = daoStateService.isBsqTxOutputType(txOutput); long bsqAmount = isBsqTxOutputType ? txOutput.getValue() : 0; long btcAmount = !isBsqTxOutputType ? txOutput.getValue() : 0; PubKeyScript pubKeyScript = txOutput.getPubKeyScript(); JsonScriptPubKey scriptPubKey = pubKeyScript != null ? new JsonScriptPubKey(pubKeyScript) : null; JsonSpentInfo spentInfo = daoStateService.getSpentInfo(txOutput).map(JsonSpentInfo::new).orElse(null); JsonTxOutputType txOutputType = JsonTxOutputType.valueOf(txOutput.getTxOutputType().name()); int lockTime = txOutput.getLockTime(); String opReturn = txOutput.getOpReturnData() != null ? Utils.HEX.encode(txOutput.getOpReturnData()) : null; boolean isUnspent = daoStateService.isUnspent(txOutput.getKey()); return new JsonTxOutput(tx.getId(), txOutput.getIndex(), bsqAmount, btcAmount, tx.getBlockHeight(), isBsqTxOutputType, tx.getBurntFee(), tx.getInvalidatedBsq(), txOutput.getAddress(), scriptPubKey, spentInfo, tx.getTime(), jsonTxType, jsonTxTypeDisplayString, txOutputType, txOutputType.getDisplayString(), opReturn, lockTime, isUnspent ); }) .collect(Collectors.toList()); }
Example #20
Source File: AlertManager.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private boolean verifySignature(Alert alert) { String alertMessageAsHex = Utils.HEX.encode(alert.getMessage().getBytes(Charsets.UTF_8)); try { ECKey.fromPublicOnly(HEX.decode(pubKeyAsHex)).verifyMessage(alertMessageAsHex, alert.getSignatureAsBase64()); return true; } catch (SignatureException e) { log.warn("verifySignature failed"); return false; } }
Example #21
Source File: PrivateNotificationManager.java From bisq-core with GNU Affero General Public License v3.0 | 5 votes |
private boolean isKeyValid(String privKeyString) { try { privateNotificationSigningKey = ECKey.fromPrivate(new BigInteger(1, HEX.decode(privKeyString))); return pubKeyAsHex.equals(Utils.HEX.encode(privateNotificationSigningKey.getPubKey())); } catch (Throwable t) { return false; } }
Example #22
Source File: PrivateNotificationManager.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private boolean isKeyValid(String privKeyString) { try { privateNotificationSigningKey = ECKey.fromPrivate(new BigInteger(1, HEX.decode(privKeyString))); return pubKeyAsHex.equals(Utils.HEX.encode(privateNotificationSigningKey.getPubKey())); } catch (Throwable t) { return false; } }
Example #23
Source File: ScriptChunk.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public void write(OutputStream stream) throws IOException { if (isOpCode()) { checkState(data == null); stream.write(opcode); } else if (data != null) { if (opcode < OP_PUSHDATA1) { checkState(data.length == opcode); stream.write(opcode); } else if (opcode == OP_PUSHDATA1) { checkState(data.length <= 0xFF); stream.write(OP_PUSHDATA1); stream.write(data.length); } else if (opcode == OP_PUSHDATA2) { checkState(data.length <= 0xFFFF); stream.write(OP_PUSHDATA2); stream.write(0xFF & data.length); stream.write(0xFF & (data.length >> 8)); } else if (opcode == OP_PUSHDATA4) { checkState(data.length <= Script.MAX_SCRIPT_ELEMENT_SIZE); stream.write(OP_PUSHDATA4); Utils.uint32ToByteStreamLE(data.length, stream); } else { throw new RuntimeException("Unimplemented"); } stream.write(data); } else { stream.write(opcode); // smallNum } }
Example #24
Source File: ScriptChunk.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public void write(OutputStream stream) throws IOException { if (isOpCode()) { checkState(data == null); stream.write(opcode); } else if (data != null) { if (opcode < OP_PUSHDATA1) { checkState(data.length == opcode); stream.write(opcode); } else if (opcode == OP_PUSHDATA1) { checkState(data.length <= 0xFF); stream.write(OP_PUSHDATA1); stream.write(data.length); } else if (opcode == OP_PUSHDATA2) { checkState(data.length <= 0xFFFF); stream.write(OP_PUSHDATA2); Utils.uint16ToByteStreamLE(data.length, stream); } else if (opcode == OP_PUSHDATA4) { checkState(data.length <= Script.MAX_SCRIPT_ELEMENT_SIZE); stream.write(OP_PUSHDATA4); Utils.uint32ToByteStreamLE(data.length, stream); } else { throw new RuntimeException("Unimplemented"); } stream.write(data); } else { stream.write(opcode); // smallNum } }
Example #25
Source File: AlertManager.java From bisq-core with GNU Affero General Public License v3.0 | 5 votes |
private boolean isKeyValid(String privKeyString) { try { alertSigningKey = ECKey.fromPrivate(new BigInteger(1, HEX.decode(privKeyString))); return pubKeyAsHex.equals(Utils.HEX.encode(alertSigningKey.getPubKey())); } catch (Throwable t) { return false; } }
Example #26
Source File: WalletTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void scriptCreationTime() throws Exception { Utils.setMockClock(); long now = Utils.currentTimeSeconds(); wallet = new Wallet(UNITTEST); assertEquals(now, wallet.getEarliestKeyCreationTime()); Utils.rollMockClock(-120); wallet.addWatchedAddress(OTHER_ADDRESS); wallet.freshReceiveKey(); assertEquals(now - 120, wallet.getEarliestKeyCreationTime()); }
Example #27
Source File: WalletTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test public void fromKeys() { ECKey key = ECKey.fromPrivate(Utils.HEX.decode("00905b93f990267f4104f316261fc10f9f983551f9ef160854f40102eb71cffdcc")); Wallet wallet = Wallet.fromKeys(PARAMS, Arrays.asList(key)); assertEquals(1, wallet.getImportedKeys().size()); assertEquals(key, wallet.getImportedKeys().get(0)); wallet.upgradeToDeterministic(null); String seed = wallet.getKeyChainSeed().toHexString(); assertEquals("5ca8cd6c01aa004d3c5396c628b78a4a89462f412f460a845b594ac42eceaa264b0e14dcd4fe73d4ed08ce06f4c28facfa85042d26d784ab2798a870bb7af556", seed); }
Example #28
Source File: WalletTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void keyCreationTime() throws Exception { Utils.setMockClock(); long now = Utils.currentTimeSeconds(); wallet = new Wallet(UNITTEST); assertEquals(now, wallet.getEarliestKeyCreationTime()); Utils.rollMockClock(60); wallet.freshReceiveKey(); assertEquals(now, wallet.getEarliestKeyCreationTime()); }
Example #29
Source File: DeterministicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void masterKeyAccount() throws UnreadableWalletException { Utils.setMockClock(); long secs = 1389353062L; DeterministicKey firstReceiveKey = bip44chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey secondReceiveKey = bip44chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey firstChangeKey = bip44chain.getKey(KeyChain.KeyPurpose.CHANGE); DeterministicKey secondChangeKey = bip44chain.getKey(KeyChain.KeyPurpose.CHANGE); NetworkParameters params = MainNetParams.get(); DeterministicKey watchingKey = bip44chain.getWatchingKey(); //m/44'/1'/0' DeterministicKey coinLevelKey = bip44chain.getWatchingKey().getParent(); //m/44'/1' //Simulate Wallet.fromSpendingKeyB58(PARAMS, prv58, secs) final String prv58 = watchingKey.serializePrivB58(params); assertEquals("xprv9yYQhynAmWWuz62PScx5Q2frBET2F1raaXna5A2E9Lj8XWgmKBL7S98Yand8F736j9UCTNWQeiB4yL5pLZP7JDY2tY8eszGQkiKDwBkezeS", prv58); watchingKey = DeterministicKey.deserializeB58(null, prv58, params); watchingKey.setCreationTimeSeconds(secs); DeterministicKeyChain fromPrivBase58Chain = DeterministicKeyChain.spend(watchingKey); assertEquals(secs, fromPrivBase58Chain.getEarliestKeyCreationTime()); fromPrivBase58Chain.setLookaheadSize(10); fromPrivBase58Chain.maybeLookAhead(); verifySpendableKeyChain(firstReceiveKey, secondReceiveKey, firstChangeKey, secondChangeKey, fromPrivBase58Chain, "spending-wallet-from-bip44-serialization.txt"); //Simulate Wallet.fromMasterKey(params, coinLevelKey, 0) DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinLevelKey, new ChildNumber(0, true)); accountKey = accountKey.dropParent(); accountKey.setCreationTimeSeconds(watchingKey.getCreationTimeSeconds()); KeyChainGroup group = new KeyChainGroup(params, accountKey, false); DeterministicKeyChain fromMasterKeyChain = group.getActiveKeyChain(); assertEquals(secs, fromMasterKeyChain.getEarliestKeyCreationTime()); fromMasterKeyChain.setLookaheadSize(10); fromMasterKeyChain.maybeLookAhead(); verifySpendableKeyChain(firstReceiveKey, secondReceiveKey, firstChangeKey, secondChangeKey, fromMasterKeyChain, "spending-wallet-from-bip44-serialization-two.txt"); }
Example #30
Source File: PaymentChannelServerTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() { broadcaster = createMock(TransactionBroadcaster.class); wallet = createMock(Wallet.class); connection = createMock(PaymentChannelServer.ServerConnection.class); serverVersionCapture = new Capture<TwoWayChannelMessage>(); connection.sendToClient(capture(serverVersionCapture)); Utils.setMockClock(); }