3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 14:54:15 +00:00

HD Wallets: add a REFUND key purpose and map it to the same branch as RECEIVE_FUNDS for now.

This commit is contained in:
Mike Hearn 2014-03-28 12:40:00 +01:00
parent dbf504faa0
commit c7f7fd29e0
2 changed files with 18 additions and 9 deletions

View File

@ -235,14 +235,22 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
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);

View File

@ -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. */