Class HDPath
- All Implemented Interfaces:
Iterable<ChildNumber>
,Collection<ChildNumber>
,List<ChildNumber>
HDPath
can be used to represent a full path or a relative path.
The hasPrivateKey
boolean
is used for rendering to String
but (at present) not much else. It defaults to false
which is the preferred setting for a relative path.
HDPath
is immutable and uses the Collections.UnmodifiableList
type internally.
It implements java.util.List<ChildNumber>
to ease migration
from the previous implementation. When an HDPath
is returned you can treat it as a List<ChildNumber>
where necessary in your code. Although it is recommended to use the HDPath
type for clarity and for
access to HDPath
-specific functionality.
Note that it is possible for HDPath
to be an empty list.
Take note of the overloaded factory methods M()
and m()
. These can be used to very
concisely create HDPath objects (especially when statically imported.)
-
Field Summary
Modifier and TypeFieldDescriptionstatic final HDPath
Partial path with BIP44 purposestatic final HDPath
Partial path with BIP84 purposestatic final HDPath
Partial path with BIP86 purposeprotected final boolean
protected final List<ChildNumber>
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionHDPath
(boolean hasPrivateKey, List<ChildNumber> list) Constructs a path for a public or private key.HDPath
(List<ChildNumber> list) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionReturn a list of all ancestors of this pathancestors
(boolean includeSelf) Return a list of all ancestors of this pathstatic HDPath
deserialize
(List<Integer> integerList) Deserialize a list of integers into an HDPath (internal use only)extend
(List<ChildNumber> path2) Extend the path by appending a relative path.extend
(ChildNumber child1, ChildNumber... children) Extend the path by appending additional ChildNumber objects.Extend the path by appending a relative path.get
(int index) boolean
Is this a path to a private key?list()
Return a simple list ofChildNumber
static HDPath
m()
Returns an empty path for a private key.static HDPath
m
(List<ChildNumber> list) Returns a path for a private key.static HDPath
m
(ChildNumber childNumber) Returns a path for a private key.static HDPath
m
(ChildNumber... children) Returns a path for a private key.static HDPath
M()
Returns an empty path for a public key.static HDPath
M
(List<ChildNumber> list) Returns a path for a public key.static HDPath
M
(ChildNumber childNumber) Returns a path for a public key.static HDPath
M
(ChildNumber... children) Returns a path for a public key.parent()
Return the parent path.static HDPath
Create an HDPath from a path string.int
size()
toString()
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Field Details
-
hasPrivateKey
protected final boolean hasPrivateKey -
unmodifiableList
-
BIP44_PARENT
Partial path with BIP44 purpose -
BIP84_PARENT
Partial path with BIP84 purpose -
BIP86_PARENT
Partial path with BIP86 purpose
-
-
Constructor Details
-
HDPath
Constructs a path for a public or private key. Should probably be a private constructor.- Parameters:
hasPrivateKey
- Whether it is a path to a private key or notlist
- List of children in the path
-
HDPath
Constructs a path for a public key.- Parameters:
list
- List of children in the path
-
-
Method Details
-
deserialize
Deserialize a list of integers into an HDPath (internal use only)- Parameters:
integerList
- A list of integers (what we use in ProtoBuf for an HDPath)- Returns:
- a deserialized HDPath (hasPrivateKey is false/unknown)
-
M
Returns a path for a public key.- Parameters:
list
- List of children in the path
-
M
Returns an empty path for a public key. -
M
Returns a path for a public key.- Parameters:
childNumber
- Single child in path
-
M
Returns a path for a public key.- Parameters:
children
- Children in the path
-
m
Returns a path for a private key.- Parameters:
list
- List of children in the path
-
m
Returns an empty path for a private key. -
m
Returns a path for a private key.- Parameters:
childNumber
- Single child in path
-
m
Returns a path for a private key.- Parameters:
children
- Children in the path
-
parsePath
Create an HDPath from a path string. The path string is a human-friendly representation of the deterministic path. For example: "44H / 0H / 0H / 1 / 1" Where a letter "H" means hardened key. Spaces are ignored. -
hasPrivateKey
public boolean hasPrivateKey()Is this a path to a private key?- Returns:
- true if yes, false if no or a partial path
-
extend
Extend the path by appending additional ChildNumber objects.- Parameters:
child1
- the first child to appendchildren
- zero or more additional children to append- Returns:
- A new immutable path
-
extend
Extend the path by appending a relative path.- Parameters:
path2
- the relative path to append- Returns:
- A new immutable path
-
extend
Extend the path by appending a relative path.- Parameters:
path2
- the relative path to append- Returns:
- A new immutable path
-
list
Return a simple list ofChildNumber
- Returns:
- an unmodifiable list of
ChildNumber
-
parent
Return the parent path.Note that this method defines the parent of a root path as the empty path and the parent of the empty path as the empty path. This behavior is what one would expect of an unmodifiable, copy-on-modify list. If you need to check for edge cases, you can use
AbstractCollection.isEmpty()
before or after usingHDPath#parent()
- Returns:
- parent path (which can be empty -- see above)
-
ancestors
Return a list of all ancestors of this path- Returns:
- unmodifiable list of ancestors
-
ancestors
Return a list of all ancestors of this path- Parameters:
includeSelf
- true if include path for self- Returns:
- unmodifiable list of ancestors
-
get
- Specified by:
get
in interfaceList<ChildNumber>
- Specified by:
get
in classAbstractList<ChildNumber>
-
size
public int size()- Specified by:
size
in interfaceCollection<ChildNumber>
- Specified by:
size
in interfaceList<ChildNumber>
- Specified by:
size
in classAbstractCollection<ChildNumber>
-
toString
- Overrides:
toString
in classAbstractCollection<ChildNumber>
-
M(List)
orm(List)
instead