Package org.bitcoinj.crypto
Class HDPath
- All Implemented Interfaces:
Iterable<ChildNumber>,Collection<ChildNumber>,List<ChildNumber>
HD Key derivation path.
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 Guava ImmutableList<ChildNumber>. It should be a minor breaking change
to replace ImmutableList<ChildNumber> with 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.
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
FieldsFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionHDPath(boolean hasPrivateKey, List<ChildNumber> list) Constructs a path for a public or private key.HDPath(List<ChildNumber> list) Constructs a path for a public key. -
Method Summary
Modifier and TypeMethodDescriptionextend(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) booleanIs this a path to a private key?static HDPathm()Returns an empty path for a private key.static HDPathm(List<ChildNumber> list) Returns a path for a private key.static HDPathm(ChildNumber childNumber) Returns a path for a private key.static HDPathm(ChildNumber... children) Returns a path for a private key.static HDPathM()Returns an empty path for a public key.static HDPathM(List<ChildNumber> list) Returns a path for a public key.static HDPathM(ChildNumber childNumber) Returns a path for a public key.static HDPathM(ChildNumber... children) Returns a path for a public key.static HDPathCreate an HDPath from a path string.intsize()toString()Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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
-
-
Constructor Details
-
HDPath
Constructs a path for a public or private key.- 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
-
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
-
get
- Specified by:
getin interfaceList<ChildNumber>- Specified by:
getin classAbstractList<ChildNumber>
-
size
public int size()- Specified by:
sizein interfaceCollection<ChildNumber>- Specified by:
sizein interfaceList<ChildNumber>- Specified by:
sizein classAbstractCollection<ChildNumber>
-
toString
- Overrides:
toStringin classAbstractCollection<ChildNumber>
-