3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-11 17:55:53 +00:00

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 byte[] entropy;
protected DeterministicSeed seed;
protected DeterministicKey watchingKey;
protected Builder() {
}
@ -214,6 +215,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
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. */
public T passphrase(String passphrase) {
// FIXME support non-empty passphrase
@ -223,7 +229,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
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");
DeterministicKeyChain chain;
@ -232,8 +238,10 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
chain = new DeterministicKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs);
} else if (entropy != null) {
chain = new DeterministicKeyChain(entropy, getPassphrase(), seedCreationTimeSecs);
} else {
} else if (seed != null) {
chain = new DeterministicKeyChain(seed);
} else {
chain = new DeterministicKeyChain(watchingKey, seedCreationTimeSecs);
}
return chain;

View File

@ -91,7 +91,7 @@ public class MarriedKeyChain extends DeterministicKeyChain {
}
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");
MarriedKeyChain chain;
if (threshold == 0)
@ -100,8 +100,10 @@ public class MarriedKeyChain extends DeterministicKeyChain {
chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs);
} else if (entropy != null) {
chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs);
} else {
} else if (seed != null) {
chain = new MarriedKeyChain(seed);
} else {
chain = new MarriedKeyChain(watchingKey, seedCreationTimeSecs);
}
chain.addFollowingAccountKeys(followingKeys, threshold);
return chain;
@ -117,6 +119,10 @@ public class MarriedKeyChain extends DeterministicKeyChain {
super(accountKey, false);
}
MarriedKeyChain(DeterministicKey accountKey, long seedCreationTimeSecs) {
super(accountKey, seedCreationTimeSecs);
}
MarriedKeyChain(DeterministicSeed seed, KeyCrypter crypter) {
super(seed, crypter);
}