Skip to content

Commit

Permalink
HD Wallets: add a REFUND key purpose and map it to the same branch as…
Browse files Browse the repository at this point in the history
… RECEIVE_FUNDS for now.
  • Loading branch information
mikehearn committed May 29, 2014
1 parent dbf504f commit c7f7fd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,22 @@ public DeterministicKey getKey(KeyPurpose purpose) {
try {
DeterministicKey key, parentKey;
int index;
if (purpose == KeyPurpose.RECEIVE_FUNDS) {
index = ++issuedExternalKeys;
parentKey = externalKey;
} else if (purpose == KeyPurpose.CHANGE) {
index = ++issuedInternalKeys;
parentKey = internalKey;
} else {
throw new IllegalArgumentException("Unknown key purpose " + purpose);
switch (purpose) {
// Map both REFUND and RECEIVE_KEYS to the same branch for now. Refunds are a feature of the BIP 70
// payment protocol. Later we may wish to map it to a different branch (in a new wallet version?).
// This would allow a watching wallet to only be able to see inbound payments, but not change
// (i.e. spends) or refunds. Might be useful for auditing ...
case RECEIVE_FUNDS:
case REFUND:
index = ++issuedExternalKeys;
parentKey = externalKey;
break;
case CHANGE:
index = ++issuedInternalKeys;
parentKey = internalKey;
break;
default:
throw new UnsupportedOperationException();
}
// TODO: Handle the case where the derived key is >= curve order.
List<DeterministicKey> lookahead = maybeLookAhead(parentKey, index);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/google/bitcoin/wallet/KeyChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public interface KeyChain {

enum KeyPurpose {
RECEIVE_FUNDS,
CHANGE
CHANGE,
REFUND
}

/** Obtains a key intended for the given purpose. The chain may create a new key, derive one, or re-use an old one. */
Expand Down

0 comments on commit c7f7fd2

Please sign in to comment.