public class DeterministicKey extends ECKey
DeterministicHierarchy
. As per
the BIP 32 specification it is a pair
(key, chaincode). If you know its path in the tree and its chain code you can derive more keys from this. To obtain
one of these, you can call HDKeyDerivation.createMasterPrivateKey(byte[])
.ECKey.ECDSASignature, ECKey.KeyIsEncryptedException, ECKey.MissingPrivateKeyException
Modifier and Type | Field and Description |
---|---|
static int |
HEADER_PRIV
The 4 byte header that serializes in base58 to "xprv"
|
static int |
HEADER_PUB
The 4 byte header that serializes in base58 to "xpub"
|
creationTimeSeconds, CURVE, CURVE_PARAMS, encryptedPrivateKey, FAKE_SIGNATURES, HALF_CURVE_ORDER, keyCrypter, priv, pub, PUBKEY_COMPARATOR
Constructor and Description |
---|
DeterministicKey(DeterministicKey keyToClone,
DeterministicKey newParent)
Clones the key
|
DeterministicKey(ImmutableList<ChildNumber> childNumberPath,
byte[] chainCode,
BigInteger priv,
DeterministicKey parent)
Constructs a key from its components.
|
DeterministicKey(ImmutableList<ChildNumber> childNumberPath,
byte[] chainCode,
org.spongycastle.math.ec.ECPoint publicAsPoint,
BigInteger priv,
DeterministicKey parent)
Constructs a key from its components.
|
DeterministicKey(ImmutableList<ChildNumber> childNumberPath,
byte[] chainCode,
KeyCrypter crypter,
org.spongycastle.math.ec.ECPoint pub,
EncryptedData priv,
DeterministicKey parent)
Constructs a key from its components.
|
Modifier and Type | Method and Description |
---|---|
DeterministicKey |
decrypt(KeyCrypter keyCrypter,
org.spongycastle.crypto.params.KeyParameter aesKey)
Create a decrypted private key with the keyCrypter and AES key supplied.
|
DeterministicKey |
decrypt(org.spongycastle.crypto.params.KeyParameter aesKey)
Create a decrypted private key with AES key.
|
DeterministicKey |
derive(int child)
Derives a child at the given index (note: not the "i" value).
|
static DeterministicKey |
deserialize(DeterministicKey parent,
byte[] serializedKey) |
static DeterministicKey |
deserializeB58(DeterministicKey parent,
String base58) |
DeterministicKey |
encrypt(KeyCrypter keyCrypter,
org.spongycastle.crypto.params.KeyParameter aesKey)
Create an encrypted private key with the keyCrypter and the AES key supplied.
|
DeterministicKey |
encrypt(KeyCrypter keyCrypter,
org.spongycastle.crypto.params.KeyParameter aesKey,
DeterministicKey newParent) |
boolean |
equals(Object o)
Verifies equality of all fields but NOT the parent pointer (thus the same key derived in two separate heirarchy
objects will equal each other.
|
byte[] |
getChainCode()
Returns the chain code associated with this key.
|
ChildNumber |
getChildNumber()
Returns the last element of the path returned by
getPath() |
long |
getCreationTimeSeconds()
The creation time of a deterministic key is equal to that of its parent, unless this key is the root of a tree
in which case the time is stored alongside the key as per normal, see
ECKey.getCreationTimeSeconds() . |
byte[] |
getFingerprint()
Returns the first 32 bits of the result of
getIdentifier() . |
byte[] |
getIdentifier()
Returns RIPE-MD160(SHA256(pub key bytes)).
|
KeyCrypter |
getKeyCrypter()
Returns this keys
KeyCrypter or the keycrypter of its parent key. |
DeterministicKey |
getParent() |
ImmutableList<ChildNumber> |
getPath()
Returns the path through some
DeterministicHierarchy which reaches this keys position in the tree. |
String |
getPathAsString()
Returns the path of this key as a human readable string starting with M to indicate the master key.
|
BigInteger |
getPrivKey()
Returns the private key of this deterministic key.
|
byte[] |
getPrivKeyBytes33()
Returns private key bytes, padded with zeros to 33 bytes.
|
DeterministicKey |
getPubOnly()
Returns the same key with the private part removed.
|
int |
hashCode() |
boolean |
isEncrypted()
A deterministic key is considered to be encrypted if it has access to encrypted private key bytes, OR if its
parent does.
|
byte[] |
serializePrivate() |
String |
serializePrivB58() |
String |
serializePubB58() |
byte[] |
serializePublic() |
ECKey.ECDSASignature |
sign(Sha256Hash input,
org.spongycastle.crypto.params.KeyParameter aesKey)
Signs the given hash and returns the R and S components as BigIntegers.
|
String |
toString() |
compressPoint, decompress, decompressPoint, doSign, encryptionIsReversible, fromASN1, fromEncrypted, fromPrivate, fromPrivate, fromPrivate, fromPrivate, fromPrivateAndPrecalculatedPublic, fromPrivateAndPrecalculatedPublic, fromPublicOnly, fromPublicOnly, getEncryptedData, getEncryptedPrivateKey, getEncryptionType, getPrivateKeyEncoded, getPrivKeyBytes, getPubKey, getPubKeyHash, getPubKeyPoint, getSecretBytes, hasPrivKey, isCompressed, isPubKeyCanonical, isPubKeyOnly, maybeDecrypt, publicKeyFromPrivate, recoverFromSignature, setCreationTimeSeconds, sign, signedMessageToKey, signMessage, signMessage, toAddress, toASN1, toStringWithPrivate, verify, verify, verify, verify, verifyMessage
public static final int HEADER_PUB
public static final int HEADER_PRIV
public DeterministicKey(ImmutableList<ChildNumber> childNumberPath, byte[] chainCode, org.spongycastle.math.ec.ECPoint publicAsPoint, @Nullable BigInteger priv, @Nullable DeterministicKey parent)
public DeterministicKey(ImmutableList<ChildNumber> childNumberPath, byte[] chainCode, BigInteger priv, @Nullable DeterministicKey parent)
public DeterministicKey(ImmutableList<ChildNumber> childNumberPath, byte[] chainCode, KeyCrypter crypter, org.spongycastle.math.ec.ECPoint pub, EncryptedData priv, @Nullable DeterministicKey parent)
public DeterministicKey(DeterministicKey keyToClone, DeterministicKey newParent)
public ImmutableList<ChildNumber> getPath()
DeterministicHierarchy
which reaches this keys position in the tree.
A path can be written as 1/2/1 which means the first child of the root, the second child of that node, then
the first child of that node.public String getPathAsString()
public ChildNumber getChildNumber()
getPath()
public byte[] getChainCode()
public byte[] getIdentifier()
public byte[] getFingerprint()
getIdentifier()
.@Nullable public DeterministicKey getParent()
public byte[] getPrivKeyBytes33()
IllegalStateException
- if the private key bytes are missing.public DeterministicKey getPubOnly()
public DeterministicKey encrypt(KeyCrypter keyCrypter, org.spongycastle.crypto.params.KeyParameter aesKey) throws KeyCrypterException
ECKey
encrypt
in class ECKey
keyCrypter
- The keyCrypter that specifies exactly how the encrypted bytes are created.aesKey
- The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached as it is slow to create).KeyCrypterException
public DeterministicKey encrypt(KeyCrypter keyCrypter, org.spongycastle.crypto.params.KeyParameter aesKey, @Nullable DeterministicKey newParent) throws KeyCrypterException
KeyCrypterException
public boolean isEncrypted()
isEncrypted
in interface EncryptableItem
isEncrypted
in class ECKey
@Nullable public KeyCrypter getKeyCrypter()
KeyCrypter
or the keycrypter of its parent key.getKeyCrypter
in class ECKey
public ECKey.ECDSASignature sign(Sha256Hash input, @Nullable org.spongycastle.crypto.params.KeyParameter aesKey) throws KeyCrypterException
ECKey
ECKey.ECDSASignature.encodeToDER()
instead. However sometimes the independent components can be useful, for instance, if you're doing to do further
EC maths on them.sign
in class ECKey
aesKey
- The AES key to use for decryption of the private key. If null then no decryption is required.KeyCrypterException
- if there's something wrong with aesKey.public DeterministicKey decrypt(KeyCrypter keyCrypter, org.spongycastle.crypto.params.KeyParameter aesKey) throws KeyCrypterException
ECKey
decrypt
in class ECKey
keyCrypter
- The keyCrypter that specifies exactly how the decrypted bytes are created.aesKey
- The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached).KeyCrypterException
public DeterministicKey decrypt(org.spongycastle.crypto.params.KeyParameter aesKey) throws KeyCrypterException
ECKey
decrypt
in class ECKey
aesKey
- The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached).KeyCrypterException
public DeterministicKey derive(int child)
public BigInteger getPrivKey()
getPrivKey
in class ECKey
IllegalStateException
- if the parents are encrypted or a watching chain.public byte[] serializePublic()
public byte[] serializePrivate()
public String serializePubB58()
public String serializePrivB58()
public static DeterministicKey deserializeB58(@Nullable DeterministicKey parent, String base58)
public static DeterministicKey deserialize(@Nullable DeterministicKey parent, byte[] serializedKey)
public long getCreationTimeSeconds()
ECKey.getCreationTimeSeconds()
.getCreationTimeSeconds
in interface EncryptableItem
getCreationTimeSeconds
in class ECKey
public boolean equals(Object o)
Copyright © 2014. All rights reserved.