Config Event
Once the user has completed initialization, HardwareSDK sends out events regarding device information, UI requests, device requests, etc.
Events
Subscribe to the SDK's events.
HardwareSDK.on(event, callback);Params
event- requiredstringevent type, refer to Eventcallback- requiredfunctioncallback functions
Result
Event objects are usually of the following types.
{
event: string;
type: string;
payload: any;
}The event field is a classification of events, you can distinguish specific events by the type field of the event object, you also import all types of constants in the @onekeyfe/hd-core library.
uiResponse
Some event hardware requires a feedback result. Need to use the uiResponse Api to tell the hardware to process the result.
e.g Request pin, Request passphrase
HardwareSDK.uiResponse({
type: string,
payload: any
});Subscribe to the event
import { HardwareWebSdk as HardwareSDK } from '@onekeyfe/hd-web-sdk';
import { UI_EVENT, UI_RESPONSE, CoreMessage } from '@onekeyfe/hd-core';
HardwareSDK.on(UI_EVENT, (message: CoreMessage) => {
// Handle the PIN code input event
if (message.type === UI_REQUEST.REQUEST_PIN) {
// Demo1 Enter the PIN code on the device
HardwareSDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PIN,
payload: '@@ONEKEY_INPUT_PIN_IN_DEVICE',
});
// Demo2 Software processing Pin code
// Pseudocode
showUIprompts(confirm: (pin)=>{
// Tell the hardware ui request processing result
HardwareSDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PIN,
payload: pin,
});
})
}
// Handle the passphrase event
if (message.type === UI_REQUEST.REQUEST_PASSPHRASE) {
// Demo1 Enter the passphrase on the device
HardwareSDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PASSPHRASE,
payload: {
value: '',
passphraseOnDevice: true,
},
});
// Demo2 Software processing passphrase
// Pseudocode
showUIprompts(confirm: (passphrase)=>{
// Tell the hardware ui request processing result
HardwareSDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PASSPHRASE,
payload: {
value: passphrase,
},
});
})
}
if (message.type === UI_REQUEST.REQUEST_BUTTON) {
// Confirmation is required on the device, a UI prompt can be displayed
}
if (message.type === UI_REQUEST.CLOSE_UI_WINDOW) {
// The method invocation is completed. You may close all UI prompts.
}
});List of events that support subscription
UI_EVENTui-request_pinEnter the PIN code.ui-receive_pinui-request_passphraseEnter the passphrase.ui-request_passphrase_on_deviceEnter the passphrase on the device.ui-buttonConfirm on the device.ui-close_windowThe method invocation is completed. You may close all UI prompts.ui-bluetooth_permissionui-location_permissionui-firmware-progressui-device_not_in_bootloader_mode
UI_RESPONSEui-receive_pinReturn the PIN code valueui-receive_passphraseReturn the passphrase value
DEVICE_EVENTbuttonpinsupport_featuresfeatures
FIRMWARE_EVENTfirmware-release-infoble-firmware-release-info
Last updated
Was this helpful?