/** * <p>Clear the device back to factory settings</p> */ public void wipeDevice() { // Set the FSM context context.beginWipeDeviceUseCase(); }
/** * <p>Change or remove the device PIN.</p> * * @param remove True if an existing PIN should be removed */ public void changePIN(boolean remove) { // Set the FSM context context.beginChangePIN(remove); }
/** * <p>Request a deterministic hierarchy based on the given child numbers.</p> * * <p>This can be used to create a "watching wallet" that does not contain any private keys so long * as all hardened child numbers are included.</p> * * @param childNumbers The list of child numbers representing a path that may include hardened entries */ public void requestDeterministicHierarchy(List<ChildNumber> childNumbers) { // Set the FSM context context.beginGetDeterministicHierarchyUseCase(childNumbers); }
/** * <p>Ping the device</p> * * <p>This will trigger a SHOW_OPERATION_SUCCEEDED</p> */ public void requestPing() { // Let the state changes occur as a result of the internal messages context.getClient().ping(); }
@Override protected void internalTransition(HardwareWalletClient client, HardwareWalletContext context, MessageEvent event) { switch (event.getEventType()) { case DEVICE_FAILED: context.resetToFailed(); break; case DEVICE_DETACHED: // Do nothing break; case DEVICE_ATTACHED: context.resetToAttached(); break; default: handleUnexpectedMessageEvent(context, event); } } }
@Override protected void internalTransition(HardwareWalletClient client, HardwareWalletContext context, MessageEvent event) { context.resetToConnected(); } }
/** * <p>Reset the context back to an attached state (clear device information and transition to connected)</p> */ public void resetToAttached() { log.debug("Reset to 'attached'"); // Clear relevant information resetAll(); // Perform the state change currentState = HardwareWalletStates.newAttachedState(); // No high level event for this state }
/** * <p>Reset the context back to a connected state (clear device information and transition to initialised)</p> */ public void resetToConnected() { log.debug("Reset to 'connected'"); // Clear relevant information resetAll(); // Perform the state change currentState = HardwareWalletStates.newConnectedState(); // No high level event for this state }
/** * <p>Reset the context back to a disconnected state (device is attached but communication has not been established)</p> */ public void resetToDisconnected() { log.debug("Reset to 'disconnected'"); // Clear relevant information resetAll(); // Perform the state change currentState = HardwareWalletStates.newDisconnectedState(); // No high level event for this state }
/** * <p>Reset the context back to a failed state (retain device information but prevent further communication)</p> */ public void resetToFailed() { log.debug("Reset to 'failed'"); // Clear relevant information resetAllButFeatures(); // Perform the state change currentState = HardwareWalletStates.newFailedState(); // Fire the high level event HardwareWalletEvents.fireHardwareWalletEvent(HardwareWalletEventType.SHOW_DEVICE_FAILED, client.name()); }
/** * <p> * Provide additional entropy to the device to reduce risk of hardware compromise</p> * @param entropy Random bytes provided by a secure random number generator (see {@link #generateEntropy()} */ public void provideEntropy(byte[] entropy) { // Set the FSM context context.continueCreateWallet_Entropy(entropy); }
/** * <p>Request that the device signs the given transaction (unlimited number of inputs/outputs).</p> * * @param transaction The transaction containing all the inputs and outputs * @param receivingAddressPathMap The paths to the receiving addresses for this transaction keyed by input index * @param changeAddressPathMap The paths to the change address for this transaction keyed by Address */ public void signTx(Transaction transaction, Map<Integer, ImmutableList<ChildNumber>> receivingAddressPathMap, Map<Address, ImmutableList<ChildNumber>> changeAddressPathMap) { // Set the FSM context context.beginSignTxUseCase(transaction, receivingAddressPathMap, changeAddressPathMap); }
/** * <p>Reset all context state, excepting Features, to ensure a fresh context</p> */ private void resetAllButFeatures() { Optional<Features> originalFeatures = this.features; resetAll(); this.features = originalFeatures; }
/** * <p>Request some identity data to be signed using an address key from the device. The device will respond by providing * the signed data based on the key derived using the <a href="https://en.bitcoin.it/wiki/BIP_0044">BIP-44</a> deterministic * wallet approach from the master node.</p> * * <p>Notes:</p> * <ol> * <li>Provide a hidden challenge as random data used as a nonce</li> * <li></li> * </ol> * * @param identity The identity information to sign */ public void signIdentity(Identity identity) { // Set the FSM context context.beginSignIdentityUseCase(identity); }
/** * @return A new failed state */ public static FailedState newFailedState() { log.debug("Transitioning to 'failed' state"); return new FailedState(); }
/** * @return A new confirm sign tx state */ public static ConfirmSignTxState newConfirmSignTxState() { log.debug("Transitioning to 'confirm SignTx' state"); return new ConfirmSignTxState(); }
/** * @return A new disconnected state */ public static DisconnectedState newDisconnectedState() { log.debug("Transitioning to 'disconnected' state"); return new DisconnectedState(); }
/** * @return A new confirm cipher key state */ public static HardwareWalletState newConfirmCipherKeyState() { log.debug("Transitioning to 'confirm CipherKey' state"); return new ConfirmCipherKeyState(); }
@Override public void await(HardwareWalletContext context) { // Trigger a state transition via the response event context.getClient().connect(); }
@Override public void await(HardwareWalletContext context) { // Trigger a state transition via the response event context.getClient().initialise(); }