@Nullable @Override public ECKey findKeyFromPubHash(byte[] pubkeyHash) { ECKey result; if ((result = basic.findKeyFromPubHash(pubkeyHash)) != null) return result; for (DeterministicKeyChain chain : chains) { if ((result = chain.findKeyFromPubHash(pubkeyHash)) != null) return result; } return null; }
@Nullable @Override public ECKey findKeyFromPubHash(byte[] pubkeyHash) { ECKey result; if ((result = basic.findKeyFromPubHash(pubkeyHash)) != null) return result; for (DeterministicKeyChain chain : chains) { if ((result = chain.findKeyFromPubHash(pubkeyHash)) != null) return result; } return null; }
@Nullable @Override public ECKey findKeyFromPubHash(byte[] pubkeyHash) { ECKey result; if ((result = basic.findKeyFromPubHash(pubkeyHash)) != null) return result; for (DeterministicKeyChain chain : chains) { if ((result = chain.findKeyFromPubHash(pubkeyHash)) != null) return result; } return null; }
@Nullable @Override public ECKey findKeyFromPubHash(byte[] pubkeyHash) { ECKey result; if ((result = basic.findKeyFromPubHash(pubkeyHash)) != null) return result; for (DeterministicKeyChain chain : chains) { if ((result = chain.findKeyFromPubHash(pubkeyHash)) != null) return result; } return null; }
/** * @param unsignedTx The unsigned transaction (expect OP_0 in place of signatures) * @param wallet The wallet * * @return The receiving address path map linking the tx input index to a deterministic path */ private Map<Integer, ImmutableList<ChildNumber>> buildReceivingAddressPathMap(Transaction unsignedTx, Wallet wallet) { log.debug("Building Receiving address path map for transaction {}", unsignedTx); Map<Integer, ImmutableList<ChildNumber>> receivingAddressPathMap = Maps.newHashMap(); // Examine the Tx inputs to determine receiving addresses in use for (int i = 0; i < unsignedTx.getInputs().size(); i++) { TransactionInput input = unsignedTx.getInput(i); // Get input script from the connected transaction output script Script script = input.getScriptSig(); TransactionOutput connectedTransactionOutput = input.getConnectedOutput(); log.debug("Connected transaction output {}", connectedTransactionOutput); if (connectedTransactionOutput != null) { byte[] pubKeyHash = connectedTransactionOutput.getScriptPubKey().getPubKeyHash(); log.debug("Connected transaction pubKeyHash {}", Utils.HEX.encode(pubKeyHash)); DeterministicKey keyFromPubKey = wallet.getActiveKeychain().findKeyFromPubHash(pubKeyHash); Preconditions.checkNotNull(keyFromPubKey, "Could not find deterministic key from given pubKeyHash. Input script index: " + i); receivingAddressPathMap.put(i, keyFromPubKey.getPath()); } else { log.debug("Could not parse tx input script '{}'", script.toString()); } } return receivingAddressPathMap; }
key = Optional.fromNullable(activeKeyChain.findKeyFromPubHash(pubkeyHash)); address = Optional.fromNullable(new Address(MainNetParams.get(), pubkeyHash)); } else { key = Optional.fromNullable(activeKeyChain.findKeyFromPubHash(pubkeyHash)); address = Optional.fromNullable(new Address(MainNetParams.get(), pubkeyHash));
DeterministicKey decKey1 = decChain.findKeyFromPubHash(encKey1.getPubKeyHash()); DeterministicKey decKey2 = decChain.findKeyFromPubHash(encKey2.getPubKeyHash()); assertEquals(decKey1.getPubKeyPoint(), encKey1.getPubKeyPoint()); assertEquals(decKey2.getPubKeyPoint(), encKey2.getPubKeyPoint());
chain = DeterministicKeyChain.fromProtobuf(keys, null).get(0); assertEquals(EXPECTED_SERIALIZATION, protoToString(chain.serializeToProtobuf())); assertEquals(key1, chain.findKeyFromPubHash(key1.getPubKeyHash())); assertEquals(key2, chain.findKeyFromPubHash(key2.getPubKeyHash())); assertEquals(key3, chain.findKeyFromPubHash(key3.getPubKeyHash())); assertEquals(key4, chain.getKey(KeyChain.KeyPurpose.CHANGE)); key1.sign(Sha256Hash.ZERO_HASH);
@Test public void deriveAccountOne() throws Exception { long secs = 1389353062L; DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs); ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); final Address address = Address.fromBase58(UnitTestParams.get(), "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X"); assertEquals(address, key1.toAddress(UnitTestParams.get())); assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", key2.toAddress(UnitTestParams.get()).toString()); assertEquals(key1, chain1.findKeyFromPubHash(address.getHash160())); assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey())); key1.sign(Sha256Hash.ZERO_HASH); ECKey key3 = chain1.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", key3.toAddress(UnitTestParams.get()).toString()); key3.sign(Sha256Hash.ZERO_HASH); }
@Test public void serializeAccountOne() throws Exception { long secs = 1389353062L; DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs); ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); final Address address = Address.fromBase58(UnitTestParams.get(), "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X"); assertEquals(address, key1.toAddress(UnitTestParams.get())); DeterministicKey watching = chain1.getWatchingKey(); List<Protos.Key> keys = chain1.serializeToProtobuf(); KeyChainFactory factory = new KeyChainFactory() { @Override public DeterministicKeyChain makeKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicSeed seed, KeyCrypter crypter, boolean isMarried) { return new AccountOneChain(crypter, seed); } @Override public DeterministicKeyChain makeWatchingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey, boolean isFollowingKey, boolean isMarried) { throw new UnsupportedOperationException(); } }; chain1 = DeterministicKeyChain.fromProtobuf(keys, null, factory).get(0); ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", key2.toAddress(UnitTestParams.get()).toString()); assertEquals(key1, chain1.findKeyFromPubHash(address.getHash160())); assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey())); key1.sign(Sha256Hash.ZERO_HASH); ECKey key3 = chain1.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", key3.toAddress(UnitTestParams.get()).toString()); key3.sign(Sha256Hash.ZERO_HASH); assertEquals(watching, chain1.getWatchingKey()); }
@Test public void derive() throws Exception { ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertFalse(key1.isPubKeyOnly()); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertFalse(key2.isPubKeyOnly()); final Address address = Address.fromBase58(UnitTestParams.get(), "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV"); assertEquals(address, key1.toAddress(UnitTestParams.get())); assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", key2.toAddress(UnitTestParams.get()).toString()); assertEquals(key1, chain.findKeyFromPubHash(address.getHash160())); assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey())); key1.sign(Sha256Hash.ZERO_HASH); assertFalse(key1.isPubKeyOnly()); ECKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertFalse(key3.isPubKeyOnly()); assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(UnitTestParams.get()).toString()); key3.sign(Sha256Hash.ZERO_HASH); assertFalse(key3.isPubKeyOnly()); }