Allow building a MarriedKeyChain with a watchingKey

This commit is contained in:
Oscar Guindzberg
2015-01-20 12:37:58 -03:00
committed by Andreas Schildbach
parent 068da489ef
commit d5f47f37d3
2 changed files with 18 additions and 4 deletions

View File

@@ -162,6 +162,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
protected long seedCreationTimeSecs; protected long seedCreationTimeSecs;
protected byte[] entropy; protected byte[] entropy;
protected DeterministicSeed seed; protected DeterministicSeed seed;
protected DeterministicKey watchingKey;
protected Builder() { protected Builder() {
} }
@@ -214,6 +215,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
return self(); return self();
} }
public T watchingKey(DeterministicKey watchingKey) {
this.watchingKey = watchingKey;
return self();
}
/** The passphrase to use with the generated mnemonic, or null if you would like to use the default empty string. Currently must be the empty string. */ /** The passphrase to use with the generated mnemonic, or null if you would like to use the default empty string. Currently must be the empty string. */
public T passphrase(String passphrase) { public T passphrase(String passphrase) {
// FIXME support non-empty passphrase // FIXME support non-empty passphrase
@@ -223,7 +229,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
public DeterministicKeyChain build() { public DeterministicKeyChain build() {
checkState(random != null || entropy != null || seed != null, "Must provide either entropy or random"); checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey");
checkState(passphrase == null || seed == null, "Passphrase must not be specified with seed"); checkState(passphrase == null || seed == null, "Passphrase must not be specified with seed");
DeterministicKeyChain chain; DeterministicKeyChain chain;
@@ -232,8 +238,10 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
chain = new DeterministicKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); chain = new DeterministicKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs);
} else if (entropy != null) { } else if (entropy != null) {
chain = new DeterministicKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); chain = new DeterministicKeyChain(entropy, getPassphrase(), seedCreationTimeSecs);
} else { } else if (seed != null) {
chain = new DeterministicKeyChain(seed); chain = new DeterministicKeyChain(seed);
} else {
chain = new DeterministicKeyChain(watchingKey, seedCreationTimeSecs);
} }
return chain; return chain;

View File

@@ -91,7 +91,7 @@ public class MarriedKeyChain extends DeterministicKeyChain {
} }
public MarriedKeyChain build() { public MarriedKeyChain build() {
checkState(random != null || entropy != null || seed != null, "Must provide either entropy or random"); checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey");
checkNotNull(followingKeys, "followingKeys must be provided"); checkNotNull(followingKeys, "followingKeys must be provided");
MarriedKeyChain chain; MarriedKeyChain chain;
if (threshold == 0) if (threshold == 0)
@@ -100,8 +100,10 @@ public class MarriedKeyChain extends DeterministicKeyChain {
chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs);
} else if (entropy != null) { } else if (entropy != null) {
chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs);
} else { } else if (seed != null) {
chain = new MarriedKeyChain(seed); chain = new MarriedKeyChain(seed);
} else {
chain = new MarriedKeyChain(watchingKey, seedCreationTimeSecs);
} }
chain.addFollowingAccountKeys(followingKeys, threshold); chain.addFollowingAccountKeys(followingKeys, threshold);
return chain; return chain;
@@ -117,6 +119,10 @@ public class MarriedKeyChain extends DeterministicKeyChain {
super(accountKey, false); super(accountKey, false);
} }
MarriedKeyChain(DeterministicKey accountKey, long seedCreationTimeSecs) {
super(accountKey, seedCreationTimeSecs);
}
MarriedKeyChain(DeterministicSeed seed, KeyCrypter crypter) { MarriedKeyChain(DeterministicSeed seed, KeyCrypter crypter) {
super(seed, crypter); super(seed, crypter);
} }