@onekeyfe/hwk-adapter-core 1.1.26-alpha.7 → 1.1.26-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,50 +1,78 @@
1
+ /**
2
+ * HWK HardwareErrorCode — independent namespace from the legacy
3
+ * `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).
4
+ *
5
+ * All HWK codes are 5-digit (>= 10000) so the two tables never collide
6
+ * even if either side grows. Each sub-category gets a 100-slot block.
7
+ *
8
+ * 10000-10099 Generic / cross-cutting primitives
9
+ * 10100-10199 Device state
10
+ * 10200-10299 Firmware
11
+ * 10300-10399 Transport + OS-level permission
12
+ * 10400-10499 PIN / Passphrase
13
+ * 10500-10599 App lifecycle (wrong app, not open, too old)
14
+ * 10600-10999 RESERVED — future adapter-level categories
15
+ *
16
+ * 11000-11099 EVM APDU (reactive mapping)
17
+ * 11100-11199 Solana APDU
18
+ * 11200-11299 Tron APDU
19
+ * 11300-11399 BTC APDU
20
+ * 11400-11999 RESERVED — future chain APDU blocks (100 per chain)
21
+ *
22
+ * 12000-99999 RESERVED — future major categories
23
+ */
1
24
  declare enum HardwareErrorCode {
2
- UnknownError = 0,
3
- DeviceNotFound = 1,
4
- DeviceDisconnected = 2,
5
- UserRejected = 3,
6
- DeviceBusy = 4,
7
- FirmwareUpdateRequired = 5,
8
- AppNotOpen = 6,
9
- InvalidParams = 7,
10
- TransportError = 8,
11
- OperationTimeout = 9,
12
- MethodNotSupported = 10,
13
- PinInvalid = 5520,
14
- PinCancelled = 5521,
15
- PassphraseRejected = 5522,
16
- DeviceLocked = 5530,
17
- DeviceNotInitialized = 5531,
18
- DeviceInBootloader = 5532,
19
- FirmwareTooOld = 5533,
20
- WrongApp = 5540,
21
- DeviceMismatch = 5560,
22
- BridgeNotFound = 5550,
23
- TransportNotAvailable = 5551,
24
- DevicePermissionDenied = 5570,
25
+ UnknownError = 10000,
26
+ UserRejected = 10001,
27
+ InvalidParams = 10002,
28
+ OperationTimeout = 10003,
29
+ MethodNotSupported = 10004,
30
+ DeviceNotFound = 10100,
31
+ DeviceDisconnected = 10101,
32
+ DeviceBusy = 10102,
33
+ DeviceLocked = 10103,
34
+ DeviceNotInitialized = 10104,
35
+ DeviceInBootloader = 10105,
36
+ DeviceMismatch = 10106,
37
+ FirmwareTooOld = 10200,
38
+ FirmwareUpdateRequired = 10201,
39
+ TransportError = 10300,
40
+ BridgeNotFound = 10301,
41
+ TransportNotAvailable = 10302,
42
+ /**
43
+ * OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
44
+ * unavailable, or dismissed. Consumers surface a single "please grant
45
+ * permission" toast and let the user retry manually.
46
+ */
47
+ DevicePermissionDenied = 10303,
48
+ PinInvalid = 10400,
49
+ PinCancelled = 10401,
50
+ PassphraseRejected = 10402,
51
+ AppNotOpen = 10500,
52
+ WrongApp = 10501,
53
+ /** 0x911c Command code not supported — app predates current SDK. */
54
+ AppTooOld = 10502,
25
55
  /** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
26
56
  * user has not enabled Blind signing on the device. */
27
- EvmBlindSigningRequired = 7001,
57
+ EvmBlindSigningRequired = 11000,
28
58
  /** 0x6984 Plugin not installed */
29
- EvmClearSignPluginMissing = 7002,
59
+ EvmClearSignPluginMissing = 11001,
30
60
  /** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
31
- EvmDataTooLarge = 7003,
61
+ EvmDataTooLarge = 11002,
32
62
  /** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
33
- EvmTxTypeNotSupported = 7004,
34
- /** 0x911c Command code not supported — app predates current SDK */
35
- AppTooOld = 7005,
63
+ EvmTxTypeNotSupported = 11003,
36
64
  /** 0x6808 Blind signing disabled for this instruction. */
37
- SolanaBlindSigningRequired = 7101,
65
+ SolanaBlindSigningRequired = 11100,
38
66
  /** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
39
- TronCustomContractRequired = 7201,
67
+ TronCustomContractRequired = 11200,
40
68
  /** 0x6a8b Transactions Data setting disabled. */
41
- TronDataSigningRequired = 7202,
69
+ TronDataSigningRequired = 11201,
42
70
  /** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
43
- TronSignByHashRequired = 7203,
71
+ TronSignByHashRequired = 11202,
44
72
  /** 0xb008 Wallet policy HMAC mismatch or not registered. */
45
- BtcWalletPolicyHmacMismatch = 7301,
73
+ BtcWalletPolicyHmacMismatch = 11300,
46
74
  /** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
47
- BtcUnexpectedState = 7302
75
+ BtcUnexpectedState = 11301
48
76
  }
49
77
 
50
78
  interface Success<T> {
@@ -571,6 +599,139 @@ declare const SDK: {
571
599
  readonly DEVICE_INTERACTION: "device-interaction";
572
600
  };
573
601
 
602
+ /**
603
+ * Minimal device info returned during discovery (searchDevices).
604
+ * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
605
+ */
606
+ interface ConnectorDevice {
607
+ connectId: string;
608
+ deviceId: string;
609
+ name: string;
610
+ model?: string;
611
+ /** Device capabilities — available from scan time */
612
+ capabilities?: DeviceCapabilities;
613
+ }
614
+ interface ConnectorSession {
615
+ sessionId: string;
616
+ deviceInfo: DeviceInfo;
617
+ }
618
+ type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
619
+ /**
620
+ * Interaction event types emitted via 'ui-event'.
621
+ * These map to user-facing prompts (confirm on device, open app, etc.).
622
+ */
623
+ declare enum EConnectorInteraction {
624
+ /** Device requires user to open a specific app */
625
+ ConfirmOpenApp = "confirm-open-app",
626
+ /** Device requires user to unlock */
627
+ UnlockDevice = "unlock-device",
628
+ /** Device needs user to confirm on device (sign, verify, etc.) */
629
+ ConfirmOnDevice = "confirm-on-device",
630
+ /** Previous interaction completed — clear UI prompt */
631
+ InteractionComplete = "interaction-complete"
632
+ }
633
+ type ConnectorUiEvent = {
634
+ type: EConnectorInteraction.ConfirmOpenApp;
635
+ payload: {
636
+ sessionId: string;
637
+ };
638
+ } | {
639
+ type: EConnectorInteraction.UnlockDevice;
640
+ payload: {
641
+ sessionId: string;
642
+ };
643
+ } | {
644
+ type: EConnectorInteraction.ConfirmOnDevice;
645
+ payload: {
646
+ sessionId: string;
647
+ };
648
+ } | {
649
+ type: EConnectorInteraction.InteractionComplete;
650
+ payload: {
651
+ sessionId: string;
652
+ };
653
+ };
654
+ interface ConnectorEventMap {
655
+ 'device-connect': {
656
+ device: ConnectorDevice;
657
+ };
658
+ 'device-disconnect': {
659
+ connectId: string;
660
+ };
661
+ 'ui-request': {
662
+ type: string;
663
+ payload?: unknown;
664
+ };
665
+ 'ui-event': ConnectorUiEvent;
666
+ }
667
+ interface IConnector {
668
+ /** Physical connection type this connector uses. Fixed at construction. */
669
+ readonly connectionType: ConnectionType;
670
+ searchDevices(): Promise<ConnectorDevice[]>;
671
+ connect(deviceId?: string): Promise<ConnectorSession>;
672
+ disconnect(sessionId: string): Promise<void>;
673
+ call(sessionId: string, method: string, params: unknown): Promise<unknown>;
674
+ cancel(sessionId: string): Promise<void>;
675
+ /** Send a UI response (e.g. PIN, passphrase) to the device. */
676
+ uiResponse(response: UiResponseEvent): void;
677
+ on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
678
+ off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
679
+ reset(): void;
680
+ }
681
+ interface IHardwareBridge {
682
+ searchDevices(params: {
683
+ vendor: VendorType;
684
+ }): Promise<ConnectorDevice[]>;
685
+ connect(params: {
686
+ vendor: VendorType;
687
+ deviceId?: string;
688
+ }): Promise<ConnectorSession>;
689
+ disconnect(params: {
690
+ vendor: VendorType;
691
+ sessionId: string;
692
+ }): Promise<void>;
693
+ call(params: {
694
+ vendor: VendorType;
695
+ sessionId: string;
696
+ method: string;
697
+ callParams: unknown;
698
+ }): Promise<unknown>;
699
+ cancel(params: {
700
+ vendor: VendorType;
701
+ sessionId: string;
702
+ }): Promise<void>;
703
+ uiResponse(params: {
704
+ vendor: VendorType;
705
+ response: UiResponseEvent;
706
+ }): void;
707
+ reset(params: {
708
+ vendor: VendorType;
709
+ }): void;
710
+ /** Register an event handler for connector events forwarded across the bridge. */
711
+ onEvent(params: {
712
+ vendor: VendorType;
713
+ }, handler: (event: {
714
+ type: ConnectorEventType;
715
+ data: unknown;
716
+ }) => void): void;
717
+ /** Unregister a previously registered event handler. */
718
+ offEvent(params: {
719
+ vendor: VendorType;
720
+ }, handler: (event: {
721
+ type: ConnectorEventType;
722
+ data: unknown;
723
+ }) => void): void;
724
+ }
725
+ /**
726
+ * Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
727
+ * Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
728
+ * Events are forwarded via bridge.onEvent / offEvent.
729
+ *
730
+ * Use this anywhere the actual hardware lives behind a process / context boundary
731
+ * (Electron main, extension background, native module, worker, iframe).
732
+ */
733
+ declare function createBridgedConnector(vendor: VendorType, connectionType: ConnectionType, bridge: IHardwareBridge): IConnector;
734
+
574
735
  type ChainCapability = 'evm' | 'btc' | 'sol' | 'tron';
575
736
  interface PassphraseResponse {
576
737
  passphrase: string;
@@ -674,7 +835,7 @@ type SdkEvent = {
674
835
  connectId: string;
675
836
  };
676
837
  };
677
- type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent;
838
+ type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent | ConnectorUiEvent;
678
839
  type DeviceEventListener = (event: HardwareEvent) => void;
679
840
  /**
680
841
  * Type-safe event map for IHardwareWallet.on / .off.
@@ -683,6 +844,7 @@ type DeviceEventListener = (event: HardwareEvent) => void;
683
844
  * and the value is the narrowed event object the listener will receive.
684
845
  */
685
846
  interface HardwareEventMap {
847
+ 'ui-event': ConnectorUiEvent;
686
848
  [DEVICE.CONNECT]: {
687
849
  type: typeof DEVICE.CONNECT;
688
850
  payload: DeviceInfo;
@@ -855,139 +1017,6 @@ interface DeviceDisconnectEvent {
855
1017
  }
856
1018
  type DeviceChangeEvent = DeviceConnectEvent | DeviceDisconnectEvent;
857
1019
 
858
- /**
859
- * Minimal device info returned during discovery (searchDevices).
860
- * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
861
- */
862
- interface ConnectorDevice {
863
- connectId: string;
864
- deviceId: string;
865
- name: string;
866
- model?: string;
867
- /** Device capabilities — available from scan time */
868
- capabilities?: DeviceCapabilities;
869
- }
870
- interface ConnectorSession {
871
- sessionId: string;
872
- deviceInfo: DeviceInfo;
873
- }
874
- type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
875
- /**
876
- * Interaction event types emitted via 'ui-event'.
877
- * These map to user-facing prompts (confirm on device, open app, etc.).
878
- */
879
- declare enum EConnectorInteraction {
880
- /** Device requires user to open a specific app */
881
- ConfirmOpenApp = "confirm-open-app",
882
- /** Device requires user to unlock */
883
- UnlockDevice = "unlock-device",
884
- /** Device needs user to confirm on device (sign, verify, etc.) */
885
- ConfirmOnDevice = "confirm-on-device",
886
- /** Previous interaction completed — clear UI prompt */
887
- InteractionComplete = "interaction-complete"
888
- }
889
- type ConnectorUiEvent = {
890
- type: EConnectorInteraction.ConfirmOpenApp;
891
- payload: {
892
- sessionId: string;
893
- };
894
- } | {
895
- type: EConnectorInteraction.UnlockDevice;
896
- payload: {
897
- sessionId: string;
898
- };
899
- } | {
900
- type: EConnectorInteraction.ConfirmOnDevice;
901
- payload: {
902
- sessionId: string;
903
- };
904
- } | {
905
- type: EConnectorInteraction.InteractionComplete;
906
- payload: {
907
- sessionId: string;
908
- };
909
- };
910
- interface ConnectorEventMap {
911
- 'device-connect': {
912
- device: ConnectorDevice;
913
- };
914
- 'device-disconnect': {
915
- connectId: string;
916
- };
917
- 'ui-request': {
918
- type: string;
919
- payload?: unknown;
920
- };
921
- 'ui-event': ConnectorUiEvent;
922
- }
923
- interface IConnector {
924
- /** Physical connection type this connector uses. Fixed at construction. */
925
- readonly connectionType: ConnectionType;
926
- searchDevices(): Promise<ConnectorDevice[]>;
927
- connect(deviceId?: string): Promise<ConnectorSession>;
928
- disconnect(sessionId: string): Promise<void>;
929
- call(sessionId: string, method: string, params: unknown): Promise<unknown>;
930
- cancel(sessionId: string): Promise<void>;
931
- /** Send a UI response (e.g. PIN, passphrase) to the device. */
932
- uiResponse(response: UiResponseEvent): void;
933
- on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
934
- off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
935
- reset(): void;
936
- }
937
- interface IHardwareBridge {
938
- searchDevices(params: {
939
- vendor: VendorType;
940
- }): Promise<ConnectorDevice[]>;
941
- connect(params: {
942
- vendor: VendorType;
943
- deviceId?: string;
944
- }): Promise<ConnectorSession>;
945
- disconnect(params: {
946
- vendor: VendorType;
947
- sessionId: string;
948
- }): Promise<void>;
949
- call(params: {
950
- vendor: VendorType;
951
- sessionId: string;
952
- method: string;
953
- callParams: unknown;
954
- }): Promise<unknown>;
955
- cancel(params: {
956
- vendor: VendorType;
957
- sessionId: string;
958
- }): Promise<void>;
959
- uiResponse(params: {
960
- vendor: VendorType;
961
- response: UiResponseEvent;
962
- }): void;
963
- reset(params: {
964
- vendor: VendorType;
965
- }): void;
966
- /** Register an event handler for connector events forwarded across the bridge. */
967
- onEvent(params: {
968
- vendor: VendorType;
969
- }, handler: (event: {
970
- type: ConnectorEventType;
971
- data: unknown;
972
- }) => void): void;
973
- /** Unregister a previously registered event handler. */
974
- offEvent(params: {
975
- vendor: VendorType;
976
- }, handler: (event: {
977
- type: ConnectorEventType;
978
- data: unknown;
979
- }) => void): void;
980
- }
981
- /**
982
- * Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
983
- * Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
984
- * Events are forwarded via bridge.onEvent / offEvent.
985
- *
986
- * Use this anywhere the actual hardware lives behind a process / context boundary
987
- * (Electron main, extension background, native module, worker, iframe).
988
- */
989
- declare function createBridgedConnector(vendor: VendorType, connectionType: ConnectionType, bridge: IHardwareBridge): IConnector;
990
-
991
1020
  /**
992
1021
  * Minimal typed event emitter using Map<string, Set<listener>>.
993
1022
  * Each adapter uses this for device events (connect, disconnect, pin, etc.).
@@ -1047,4 +1076,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
1047
1076
  total: number;
1048
1077
  }) => void): Promise<Response<TResult[]>>;
1049
1078
 
1050
- export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignPsbtParams, type BtcSignTxParams, type BtcSignature, type BtcSignedPsbt, type BtcSignedTx, type BtcTxInput, type BtcTxOutput, CHAIN_FINGERPRINT_PATHS, type ChainCapability, type ChainForFingerprint, type ConnectionType, type ConnectorDevice, type ConnectorEventMap, type ConnectorEventType, type ConnectorSession, DEVICE, DEVICE_EVENT, type DeviceCapabilities, type DeviceChangeEvent, type DeviceConnectEvent, type DeviceDescriptor, type DeviceDisconnectEvent, type DeviceEvent, type DeviceEventListener, type DeviceInfo, DeviceJobQueue, type DeviceJobQueueDeps, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type Interruptibility, type JobOptions, type PassphraseResponse, type PreemptionDecision, type PreemptionEvent, type ProgressCallback, type QrDisplayData, type QrResponseData, type Response, SDK, type SdkEvent, type SolAddress, type SolGetAddressParams, type SolSignMsgParams, type SolSignTxParams, type SolSignature, type SolSignedTx, type Success, type TransportType, type TronAddress, type TronGetAddressParams, type TronSignMsgParams, type TronSignTxParams, type TronSignature, type TronSignedTx, TypedEventEmitter, UI_EVENT, UI_REQUEST, UI_REQUEST_CANCELLED_TAG, UI_REQUEST_DEFAULT_TIMEOUT_MS, UI_REQUEST_PREEMPTED_TAG, UI_REQUEST_TIMEOUT_TAG, UI_RESPONSE, type UiRequestEvent, UiRequestRegistry, type UiResponseEvent, type VendorType, batchCall, bytesToHex, compareSemver, createBridgedConnector, deriveDeviceFingerprint, enrichErrorMessage, ensure0x, failure, hexToBytes, padHex64, stripHex, success };
1079
+ export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignPsbtParams, type BtcSignTxParams, type BtcSignature, type BtcSignedPsbt, type BtcSignedTx, type BtcTxInput, type BtcTxOutput, CHAIN_FINGERPRINT_PATHS, type ChainCapability, type ChainForFingerprint, type ConnectionType, type ConnectorDevice, type ConnectorEventMap, type ConnectorEventType, type ConnectorSession, type ConnectorUiEvent, DEVICE, DEVICE_EVENT, type DeviceCapabilities, type DeviceChangeEvent, type DeviceConnectEvent, type DeviceDescriptor, type DeviceDisconnectEvent, type DeviceEvent, type DeviceEventListener, type DeviceInfo, DeviceJobQueue, type DeviceJobQueueDeps, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type Interruptibility, type JobOptions, type PassphraseResponse, type PreemptionDecision, type PreemptionEvent, type ProgressCallback, type QrDisplayData, type QrResponseData, type Response, SDK, type SdkEvent, type SolAddress, type SolGetAddressParams, type SolSignMsgParams, type SolSignTxParams, type SolSignature, type SolSignedTx, type Success, type TransportType, type TronAddress, type TronGetAddressParams, type TronSignMsgParams, type TronSignTxParams, type TronSignature, type TronSignedTx, TypedEventEmitter, UI_EVENT, UI_REQUEST, UI_REQUEST_CANCELLED_TAG, UI_REQUEST_DEFAULT_TIMEOUT_MS, UI_REQUEST_PREEMPTED_TAG, UI_REQUEST_TIMEOUT_TAG, UI_RESPONSE, type UiRequestEvent, UiRequestRegistry, type UiResponseEvent, type VendorType, batchCall, bytesToHex, compareSemver, createBridgedConnector, deriveDeviceFingerprint, enrichErrorMessage, ensure0x, failure, hexToBytes, padHex64, stripHex, success };