public class DeterministicHierarchy
extends java.lang.Object
A DeterministicHierarchy calculates and keeps a whole tree (hierarchy) of keys originating from a single
root key. This implements part of the BIP 32 specification. A deterministic key tree is useful because
Bitcoin's privacy system require new keys to be created for each transaction, but managing all these
keys quickly becomes unwieldy. In particular it becomes hard to back up and distribute them. By having
a way to derive random-looking but deterministic keys we can make wallet backup simpler and gain the
ability to hand out DeterministicKey
s to other people who can then create new addresses
on the fly, without having to contact us.
The hierarchy is started from a single root key, and a location in the tree is given by a path which
is a list of ChildNumber
s.
Modifier and Type | Field and Description |
---|---|
static int |
BIP32_STANDARDISATION_TIME_SECS |
Constructor and Description |
---|
DeterministicHierarchy(DeterministicKey rootKey)
Constructs a new hierarchy rooted at the given key.
|
Modifier and Type | Method and Description |
---|---|
DeterministicKey |
deriveChild(java.util.List<ChildNumber> parentPath,
boolean relative,
boolean createParent,
ChildNumber createChildNumber)
Extends the tree by calculating the requested child for the given path.
|
DeterministicKey |
deriveNextChild(com.google.common.collect.ImmutableList<ChildNumber> parentPath,
boolean relative,
boolean createParent,
boolean privateDerivation)
Extends the tree by calculating the next key that hangs off the given parent path.
|
DeterministicKey |
get(java.util.List<ChildNumber> path,
boolean relativePath,
boolean create)
Returns a key for the given path, optionally creating it.
|
int |
getNumChildren(com.google.common.collect.ImmutableList<ChildNumber> path) |
DeterministicKey |
getRootKey()
Returns the root key that the
DeterministicHierarchy was created with. |
void |
putKey(DeterministicKey key)
Inserts a key into the hierarchy.
|
public static final int BIP32_STANDARDISATION_TIME_SECS
public DeterministicHierarchy(DeterministicKey rootKey)
public final void putKey(DeterministicKey key)
public DeterministicKey get(java.util.List<ChildNumber> path, boolean relativePath, boolean create)
path
- the path to the keyrelativePath
- whether the path is relative to the root pathcreate
- whether the key corresponding to path should be created (with any necessary ancestors) if it doesn't exist alreadyjava.lang.IllegalArgumentException
- if create is false and the path was not found.public DeterministicKey deriveNextChild(com.google.common.collect.ImmutableList<ChildNumber> parentPath, boolean relative, boolean createParent, boolean privateDerivation)
parentPath
- the path to the parentrelative
- whether the path is relative to the root pathcreateParent
- whether the parent corresponding to path should be created (with any necessary ancestors) if it doesn't exist alreadyprivateDerivation
- whether to use private or public derivationjava.lang.IllegalArgumentException
- if the parent doesn't exist and createParent is false.public int getNumChildren(com.google.common.collect.ImmutableList<ChildNumber> path)
public DeterministicKey deriveChild(java.util.List<ChildNumber> parentPath, boolean relative, boolean createParent, ChildNumber createChildNumber)
parentPath
- the path to the parentrelative
- whether the path is relative to the root pathcreateParent
- whether the parent corresponding to path should be created (with any necessary ancestors) if it doesn't exist alreadyjava.lang.IllegalArgumentException
- if the parent doesn't exist and createParent is false.public DeterministicKey getRootKey()
DeterministicHierarchy
was created with.