public class HardwareWalletContext extends Object
State context to provide the following to hardware wallet finite state machine:
The finite state machine (FSM) for the hardware wallet requires and tracks various input parameters from the user and from the external environment. This context provides a single location to store these values during state transitions.
Constructor and Description |
---|
HardwareWalletContext(HardwareWalletClient client) |
Modifier and Type | Method and Description |
---|---|
void |
beginChangePIN(boolean remove)
Change or remove the device PIN.
|
void |
beginCipherKeyUseCase(int account,
org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose,
int index,
byte[] key,
byte[] keyValue,
boolean isEncrypting,
boolean askOnDecrypt,
boolean askOnEncrypt)
Begin the "cipher key" use case
|
void |
beginCreateWallet(CreateWalletSpecification specification)
Begin the "create wallet on device" use case
|
void |
beginGetAddressUseCase(int account,
org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose,
int index,
boolean showDisplay)
Begin the "get address" use case
|
void |
beginGetDeterministicHierarchyUseCase(List<org.bitcoinj.crypto.ChildNumber> childNumbers)
Begin the "get deterministic hierarchy" use case
|
void |
beginGetPublicKeyUseCase(int account,
org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose,
int index)
Begin the "get public key" use case
|
void |
beginLoadWallet(LoadWalletSpecification specification)
Begin the "load wallet" use case
|
void |
beginSignMessageUseCase(int account,
org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose,
int index,
byte[] message)
Begin the "sign message key use case
|
void |
beginSignTxUseCase(org.bitcoinj.core.Transaction transaction,
Map<Integer,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> receivingAddressPathMap,
Map<org.bitcoinj.core.Address,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> changeAddressPathMap)
Begin the "sign transaction" use case
|
void |
beginWipeDeviceUseCase()
Begin the "wipe device" use case
|
void |
continueChangePIN_PIN(String pin)
Continue the "change PIN" use case with the provision of the current PIN
|
void |
continueCipherKey_PIN(String pin)
Continue the "cipher key" use case with the provision of the current PIN
|
void |
continueCreateWallet_Entropy(byte[] entropy)
Continue the "create wallet on device" use case with the provision of entropy
|
void |
continueCreateWallet_PIN(String pin)
Continue the "create wallet on device" use case with the provision of a PIN (either first or second)
|
void |
continueGetDeterministicHierarchyUseCase_PIN(String pin)
Continue the "get deterministic hierarchy" use case with the provision of the current PIN
|
void |
continueGetPublicKeyUseCase_PIN(String pin)
Continue the "get public key" use case with the provision of the current PIN
|
void |
continueLoadWallet_PIN(String pin)
Continue the "load wallet" use case with the provision of a PIN (either first or second)
|
void |
continueSignMessage_PIN(String pin)
Continue the "sign message" use case with the provision of the current PIN
|
void |
continueSignTx_PIN(String pin)
Continue the "sign transaction" use case with the provision of the current PIN
|
Map<org.bitcoinj.core.Address,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> |
getChangeAddressPathMap() |
com.google.common.base.Optional<List<org.bitcoinj.crypto.ChildNumber>> |
getChildNumbers() |
HardwareWalletClient |
getClient() |
com.google.common.base.Optional<CreateWalletSpecification> |
getCreateWalletSpecification() |
ContextUseCase |
getCurrentUseCase() |
com.google.common.base.Optional<org.bitcoinj.crypto.DeterministicHierarchy> |
getDeterministicHierarchy() |
com.google.common.base.Optional<org.bitcoinj.crypto.DeterministicKey> |
getDeterministicKey() |
com.google.common.base.Optional<byte[]> |
getEntropy() |
com.google.common.base.Optional<Features> |
getFeatures() |
com.google.common.base.Optional<LoadWalletSpecification> |
getLoadWalletSpecification() |
Map<Integer,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> |
getReceivingAddressPathMap() |
ByteArrayOutputStream |
getSerializedTx()
This value cannot be considered complete until the "SHOW_OPERATION_SUCCESSFUL" message has been received
since it can be built up over several incoming messages
|
Map<Integer,byte[]> |
getSignatures()
Note: When adding this signature using the builder setScriptSig() you'll need to append the SIGHASH 0x01 byte
|
HardwareWalletState |
getState() |
com.google.common.base.Optional<org.bitcoinj.core.Transaction> |
getTransaction() |
void |
onMessageEvent(MessageEvent event) |
void |
resetToAttached()
Reset the context back to an attached state (clear device information and transition to connected)
|
void |
resetToConnected()
Reset the context back to a connected state (clear device information and transition to initialised)
|
void |
resetToDetached()
Reset the context back to a detached state (no device information)
|
void |
resetToDisconnected()
Reset the context back to a disconnected state (device is attached but communication has not been established)
|
void |
resetToFailed()
Reset the context back to a failed state (retain device information but prevent further communication)
|
void |
resetToInitialised()
Reset the context back to the initialised state (standard awaiting state with features)
|
void |
resetToStopped()
Reset the context into a stopped state (the service will have to be stopped and a new one started)
|
void |
setDeterministicHierarchy(org.bitcoinj.crypto.DeterministicHierarchy deterministicHierarchy) |
void |
setDeterministicKey(org.bitcoinj.crypto.DeterministicKey deterministicKey) |
void |
setEntropy(byte[] entropy)
This is normally called after a successful cipher key operation
|
void |
setFeatures(Features features) |
void |
setToConfirmLoadState()
Sets to "confirm load" state
|
void |
setToConfirmResetState()
Sets to "confirm reset" state
|
public HardwareWalletContext(HardwareWalletClient client)
client
- The hardware wallet clientpublic com.google.common.base.Optional<Features> getFeatures()
public void setFeatures(Features features)
public com.google.common.base.Optional<org.bitcoinj.core.Transaction> getTransaction()
public HardwareWalletState getState()
public Map<Integer,byte[]> getSignatures()
Note: When adding this signature using the builder setScriptSig() you'll need to append the SIGHASH 0x01 byte
public ByteArrayOutputStream getSerializedTx()
public void resetToStopped()
Reset the context into a stopped state (the service will have to be stopped and a new one started)
public void resetToFailed()
Reset the context back to a failed state (retain device information but prevent further communication)
public void resetToDetached()
Reset the context back to a detached state (no device information)
public void resetToAttached()
Reset the context back to an attached state (clear device information and transition to connected)
public void resetToConnected()
Reset the context back to a connected state (clear device information and transition to initialised)
public void resetToDisconnected()
Reset the context back to a disconnected state (device is attached but communication has not been established)
public void resetToInitialised()
Reset the context back to the initialised state (standard awaiting state with features)
public HardwareWalletClient getClient()
public com.google.common.base.Optional<CreateWalletSpecification> getCreateWalletSpecification()
public com.google.common.base.Optional<LoadWalletSpecification> getLoadWalletSpecification()
public Map<Integer,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> getReceivingAddressPathMap()
public Map<org.bitcoinj.core.Address,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> getChangeAddressPathMap()
public com.google.common.base.Optional<List<org.bitcoinj.crypto.ChildNumber>> getChildNumbers()
public com.google.common.base.Optional<org.bitcoinj.crypto.DeterministicKey> getDeterministicKey()
public void setDeterministicKey(org.bitcoinj.crypto.DeterministicKey deterministicKey)
public com.google.common.base.Optional<org.bitcoinj.crypto.DeterministicHierarchy> getDeterministicHierarchy()
public void setDeterministicHierarchy(org.bitcoinj.crypto.DeterministicHierarchy deterministicHierarchy)
public ContextUseCase getCurrentUseCase()
public void onMessageEvent(MessageEvent event)
event
- The low level message eventpublic void setToConfirmResetState()
public void setToConfirmLoadState()
public void beginChangePIN(boolean remove)
Change or remove the device PIN.
remove
- True if an existing PIN should be removedpublic void continueChangePIN_PIN(String pin)
Continue the "change PIN" use case with the provision of the current PIN
pin
- The PINpublic void beginWipeDeviceUseCase()
Begin the "wipe device" use case
public void beginGetAddressUseCase(int account, org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose, int index, boolean showDisplay)
Begin the "get address" use case
account
- The plain account number (0 gives maximum compatibility)keyPurpose
- The key purpose (RECEIVE_FUNDS,CHANGE,REFUND,AUTHENTICATION etc)index
- The plain index of the required addressshowDisplay
- True if the device should display the same address to allow the user to verify no tampering has occurred (recommended).public void beginGetPublicKeyUseCase(int account, org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose, int index)
Begin the "get public key" use case
account
- The plain account number (0 gives maximum compatibility)keyPurpose
- The key purpose (RECEIVE_FUNDS,CHANGE,REFUND,AUTHENTICATION etc)index
- The plain index of the required addresspublic void continueGetPublicKeyUseCase_PIN(String pin)
Continue the "get public key" use case with the provision of the current PIN
pin
- The PINpublic void beginGetDeterministicHierarchyUseCase(List<org.bitcoinj.crypto.ChildNumber> childNumbers)
Begin the "get deterministic hierarchy" use case
childNumbers
- The child numbers describing the required chain from the master node including hardening bitspublic void continueGetDeterministicHierarchyUseCase_PIN(String pin)
Continue the "get deterministic hierarchy" use case with the provision of the current PIN
pin
- The PINpublic void beginSignMessageUseCase(int account, org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose, int index, byte[] message)
Begin the "sign message key use case
account
- The plain account number (0 gives maximum compatibility)keyPurpose
- The key purpose (RECEIVE_FUNDS,CHANGE,REFUND,AUTHENTICATION etc)index
- The plain index of the required addressmessage
- The message for signingpublic void continueSignMessage_PIN(String pin)
Continue the "sign message" use case with the provision of the current PIN
pin
- The PINpublic void beginCipherKeyUseCase(int account, org.bitcoinj.wallet.KeyChain.KeyPurpose keyPurpose, int index, byte[] key, byte[] keyValue, boolean isEncrypting, boolean askOnDecrypt, boolean askOnEncrypt)
Begin the "cipher key" use case
account
- The plain account number (0 gives maximum compatibility)keyPurpose
- The key purpose (RECEIVE_FUNDS,CHANGE,REFUND,AUTHENTICATION etc)index
- The plain index of the required addresskey
- The cipher key (e.g. "Some text")keyValue
- The key value (e.g. "[16 bytes of random data]")isEncrypting
- True if encryptingaskOnDecrypt
- True if device should ask on decryptingaskOnEncrypt
- True if device should ask on encryptingpublic void continueCipherKey_PIN(String pin)
Continue the "cipher key" use case with the provision of the current PIN
pin
- The PINpublic void beginLoadWallet(LoadWalletSpecification specification)
Begin the "load wallet" use case
specification
- The specification describing the use of PIN, seed strength etcpublic void continueLoadWallet_PIN(String pin)
Continue the "load wallet" use case with the provision of a PIN (either first or second)
pin
- The PINpublic void beginCreateWallet(CreateWalletSpecification specification)
Begin the "create wallet on device" use case
specification
- The specification describing the use of PIN, seed strength etcpublic void continueCreateWallet_PIN(String pin)
Continue the "create wallet on device" use case with the provision of a PIN (either first or second)
pin
- The PINpublic void continueCreateWallet_Entropy(byte[] entropy)
Continue the "create wallet on device" use case with the provision of entropy
entropy
- The 256 bits of entropy to includepublic void beginSignTxUseCase(org.bitcoinj.core.Transaction transaction, Map<Integer,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> receivingAddressPathMap, Map<org.bitcoinj.core.Address,com.google.common.collect.ImmutableList<org.bitcoinj.crypto.ChildNumber>> changeAddressPathMap)
Begin the "sign transaction" use case
transaction
- The transaction containing the inputs and outputsreceivingAddressPathMap
- The map of paths for our receiving addresseschangeAddressPathMap
- The map paths for our change addresspublic void continueSignTx_PIN(String pin)
Continue the "sign transaction" use case with the provision of the current PIN
pin
- The PINpublic com.google.common.base.Optional<byte[]> getEntropy()
public void setEntropy(byte[] entropy)
This is normally called after a successful cipher key operation
entropy
- The entropy to setCopyright © 2013–2016 Bitcoin Solutions Ltd. All rights reserved.