Package org.bitcoinj.crypto
Class HDPath
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<ChildNumber>
-
- org.bitcoinj.crypto.HDPath
-
- All Implemented Interfaces:
java.lang.Iterable<ChildNumber>,java.util.Collection<ChildNumber>,java.util.List<ChildNumber>
public class HDPath extends java.util.AbstractList<ChildNumber>
HD Key derivation path.HDPathcan be used to represent a full path or a relative path. ThehasPrivateKeybooleanis used for rendering toStringbut (at present) not much else. It defaults tofalsewhich is the preferred setting for a relative path.HDPathis immutable and uses theCollections.UnmodifiableListtype internally.It implements
java.util.List<ChildNumber>to ease migration from the previous GuavaImmutableList<ChildNumber>. It should be a minor breaking change to replaceImmutableList<ChildNumber>withList<ChildNumber>where necessary in your code. Although it is recommended to use theHDPathtype for clarity and for access toHDPath-specific functionality.Take note of the overloaded factory methods
M()andm(). These can be used to very concisely create HDPath objects (especially when statically imported.)
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanhasPrivateKeyprotected java.util.List<ChildNumber>unmodifiableList
-
Constructor Summary
Constructors Constructor Description HDPath(boolean hasPrivateKey, java.util.List<ChildNumber> list)Constructs a path for a public or private key.HDPath(java.util.List<ChildNumber> list)Constructs a path for a public key.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HDPathextend(java.util.List<ChildNumber> path2)Extend the path by appending a relative path.HDPathextend(ChildNumber child1, ChildNumber... children)Extend the path by appending additional ChildNumber objects.HDPathextend(HDPath path2)Extend the path by appending a relative path.ChildNumberget(int index)booleanhasPrivateKey()Is this a path to a private key?static HDPathm()Returns an empty path for a private key.static HDPathm(java.util.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(java.util.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 HDPathparsePath(java.lang.String path)Create an HDPath from a path string.intsize()java.lang.StringtoString()-
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
-
-
-
-
Field Detail
-
hasPrivateKey
protected final boolean hasPrivateKey
-
unmodifiableList
protected final java.util.List<ChildNumber> unmodifiableList
-
-
Constructor Detail
-
HDPath
public HDPath(boolean hasPrivateKey, java.util.List<ChildNumber> list)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
public HDPath(java.util.List<ChildNumber> list)
Constructs a path for a public key.- Parameters:
list- List of children in the path
-
-
Method Detail
-
M
public static HDPath M(java.util.List<ChildNumber> list)
Returns a path for a public key.- Parameters:
list- List of children in the path
-
M
public static HDPath M()
Returns an empty path for a public key.
-
M
public static HDPath M(ChildNumber childNumber)
Returns a path for a public key.- Parameters:
childNumber- Single child in path
-
M
public static HDPath M(ChildNumber... children)
Returns a path for a public key.- Parameters:
children- Children in the path
-
m
public static HDPath m(java.util.List<ChildNumber> list)
Returns a path for a private key.- Parameters:
list- List of children in the path
-
m
public static HDPath m()
Returns an empty path for a private key.
-
m
public static HDPath m(ChildNumber childNumber)
Returns a path for a private key.- Parameters:
childNumber- Single child in path
-
m
public static HDPath m(ChildNumber... children)
Returns a path for a private key.- Parameters:
children- Children in the path
-
parsePath
public static HDPath parsePath(@Nonnull java.lang.String path)
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
public HDPath extend(ChildNumber child1, ChildNumber... children)
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
public HDPath extend(HDPath path2)
Extend the path by appending a relative path.- Parameters:
path2- the relative path to append- Returns:
- A new immutable path
-
extend
public HDPath extend(java.util.List<ChildNumber> path2)
Extend the path by appending a relative path.- Parameters:
path2- the relative path to append- Returns:
- A new immutable path
-
get
public ChildNumber get(int index)
- Specified by:
getin interfacejava.util.List<ChildNumber>- Specified by:
getin classjava.util.AbstractList<ChildNumber>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<ChildNumber>- Specified by:
sizein interfacejava.util.List<ChildNumber>- Specified by:
sizein classjava.util.AbstractCollection<ChildNumber>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<ChildNumber>
-
-