@onekeyfe/hwk-adapter-core 1.1.26-alpha.102 → 1.1.26-alpha.105

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
@@ -50,9 +50,9 @@ type Response<T> = Success<T> | Failure;
50
50
  declare function success<T>(payload: T): Success<T>;
51
51
  declare function failure(code: HardwareErrorCode, error: string, appName?: string): Failure;
52
52
 
53
- type VendorType = 'trezor' | 'ledger' | 'keystone' | 'keystoneqr';
54
- type ConnectionType = 'usb' | 'ble' | 'qr';
55
- type TransportType = 'usb' | 'ble' | 'hid' | 'bridge' | 'qr';
53
+ type VendorType = 'trezor' | 'ledger';
54
+ type ConnectionType = 'usb' | 'ble';
55
+ type TransportType = 'usb' | 'ble' | 'hid' | 'bridge';
56
56
  /**
57
57
  * Device capabilities — describes what a specific device/connection
58
58
  * combination can or cannot do. Varies by vendor, model, and connection type.
@@ -96,14 +96,8 @@ interface EvmGetAddressParams {
96
96
  interface EvmAddress {
97
97
  address: string;
98
98
  path: string;
99
- }
100
- interface EvmGetPublicKeyParams {
101
- path: string;
102
- showOnDevice?: boolean;
103
- }
104
- interface EvmPublicKey {
105
- publicKey: string;
106
- path: string;
99
+ /** Device-reported secp256k1 public key; populated when the transport exposes it. */
100
+ publicKey?: string;
107
101
  }
108
102
  interface EvmSignTxParams {
109
103
  path: string;
@@ -184,7 +178,6 @@ type ProgressCallback = (progress: {
184
178
  interface IEvmMethods {
185
179
  evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
186
180
  evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
187
- evmGetPublicKey(connectId: string, deviceId: string, params: EvmGetPublicKeyParams): Promise<Response<EvmPublicKey>>;
188
181
  evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
189
182
  evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
190
183
  evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
@@ -297,19 +290,10 @@ interface SolGetAddressParams {
297
290
  showOnDevice?: boolean;
298
291
  }
299
292
  interface SolAddress {
300
- /** Base58-encoded Solana address */
293
+ /** Base58-encoded Solana address — this is also the Ed25519 public key. */
301
294
  address: string;
302
295
  path: string;
303
296
  }
304
- interface SolGetPublicKeyParams {
305
- path: string;
306
- showOnDevice?: boolean;
307
- }
308
- interface SolPublicKey {
309
- /** Base58-encoded Ed25519 public key (same as the Solana address) */
310
- publicKey: string;
311
- path: string;
312
- }
313
297
  interface SolSignTxParams {
314
298
  path: string;
315
299
  /** Hex-encoded serialized transaction bytes (no 0x prefix) */
@@ -339,7 +323,6 @@ interface SolSignature {
339
323
  interface ISolMethods {
340
324
  solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
341
325
  solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
342
- solGetPublicKey(connectId: string, deviceId: string, params: SolGetPublicKeyParams): Promise<Response<SolPublicKey>>;
343
326
  solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
344
327
  solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
345
328
  }
@@ -365,7 +348,7 @@ interface TronSignedTx {
365
348
  interface TronSignMsgParams {
366
349
  path: string;
367
350
  /** Message hex (no 0x prefix) */
368
- message: string;
351
+ messageHex: string;
369
352
  }
370
353
  interface TronSignature {
371
354
  /** 65-byte hex-encoded signature (no 0x prefix) */
@@ -415,17 +398,87 @@ type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';
415
398
  */
416
399
  declare function deriveDeviceFingerprint(address: string): string;
417
400
 
418
- declare const DEVICE_EVENT = "DEVICE_EVENT";
419
- /** Events originating from the hardware device. */
420
- declare const DEVICE: {
421
- readonly CONNECT: "device-connect";
422
- readonly DISCONNECT: "device-disconnect";
423
- readonly CHANGED: "device-changed";
424
- readonly ACQUIRE: "device-acquire";
425
- readonly RELEASE: "device-release";
426
- readonly FEATURES: "features";
427
- readonly SUPPORT_FEATURES: "support_features";
428
- };
401
+ /** 10 min every UI request is human-in-the-loop; bias toward "wait long". */
402
+ declare const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600000;
403
+ declare const UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
404
+ declare const UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
405
+ declare const UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
406
+ /**
407
+ * Per-type single-slot registry for adapter-level UI requests. A new `wait`
408
+ * of the same type preempts (rejects) the prior one. Unknown response types
409
+ * are dropped silently so the public `uiResponse` entry never throws.
410
+ */
411
+ declare class UiRequestRegistry {
412
+ private pending;
413
+ wait<T = unknown>(requestType: string, options?: {
414
+ timeoutMs?: number;
415
+ }): Promise<T>;
416
+ resolve(responseType: string, payload: unknown): void;
417
+ cancel(requestType?: string): void;
418
+ reset(): void;
419
+ hasPending(requestType: string): boolean;
420
+ }
421
+
422
+ /**
423
+ * Per-device serial job queue with preemption support and stuck recovery.
424
+ * Ensures that only one operation runs at a time per device, with intelligent
425
+ * handling of conflicting operations.
426
+ *
427
+ * The 'confirm' level uses the standard UI request/response flow:
428
+ * emits REQUEST_PREEMPTION → waits for RECEIVE_PREEMPTION via UiRequestRegistry.
429
+ */
430
+
431
+ type Interruptibility = 'none' | 'safe' | 'confirm';
432
+ type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';
433
+ interface JobOptions {
434
+ interruptibility?: Interruptibility;
435
+ label?: string;
436
+ }
437
+ interface ActiveJobInfo {
438
+ label?: string;
439
+ interruptibility: Interruptibility;
440
+ startedAt: number;
441
+ }
442
+ interface PreemptionEvent {
443
+ deviceId: string;
444
+ currentJob: ActiveJobInfo;
445
+ newJob: {
446
+ label?: string;
447
+ interruptibility: Interruptibility;
448
+ };
449
+ }
450
+ interface DeviceJobQueueDeps {
451
+ /** Emit a UI request event to the frontend. */
452
+ emit: (event: string, data: unknown) => void;
453
+ /** Registry for waiting on UI responses. */
454
+ uiRegistry: UiRequestRegistry;
455
+ }
456
+ declare class DeviceJobQueue {
457
+ private readonly _queues;
458
+ private readonly _active;
459
+ private readonly _deps;
460
+ constructor(deps?: DeviceJobQueueDeps);
461
+ /**
462
+ * Enqueue a job for a specific device.
463
+ * If a job is already running for this device, behavior depends on interruptibility:
464
+ * - 'none': new job queues silently (no preemption possible)
465
+ * - 'safe': current job is auto-cancelled, new job runs immediately after
466
+ * - 'confirm': emits REQUEST_PREEMPTION and waits for UI response
467
+ */
468
+ enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
469
+ /** Manually cancel the active job on a device. Returns false if job is non-interruptible. */
470
+ cancelActive(deviceId: string): boolean;
471
+ /** Force cancel regardless of interruptibility. Use for device stuck recovery. */
472
+ forceCancelActive(deviceId: string): boolean;
473
+ /** Get info about the currently active job for a device, or null if idle. */
474
+ getActiveJob(deviceId: string): ActiveJobInfo | null;
475
+ clear(): void;
476
+ /**
477
+ * Request preemption decision via UI request/response flow.
478
+ * Falls back to 'wait' if deps are not provided.
479
+ */
480
+ private _requestPreemptionDecision;
481
+ }
429
482
 
430
483
  declare const UI_EVENT = "UI_EVENT";
431
484
  declare const UI_REQUEST: {
@@ -438,6 +491,7 @@ declare const UI_REQUEST: {
438
491
  readonly REQUEST_DEVICE_PERMISSION: "ui-request-device-permission";
439
492
  readonly REQUEST_SELECT_DEVICE: "ui-request-select-device";
440
493
  readonly REQUEST_DEVICE_CONNECT: "ui-request-device-connect";
494
+ readonly REQUEST_PREEMPTION: "ui-request-preemption";
441
495
  readonly CLOSE_UI_WINDOW: "ui-close";
442
496
  readonly DEVICE_PROGRESS: "ui-device_progress";
443
497
  readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
@@ -450,6 +504,7 @@ declare const UI_RESPONSE: {
450
504
  readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
451
505
  readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
452
506
  readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
507
+ readonly RECEIVE_PREEMPTION: "receive-preemption";
453
508
  readonly CANCEL: "cancel";
454
509
  };
455
510
  type UiResponseEvent = {
@@ -478,11 +533,28 @@ type UiResponseEvent = {
478
533
  payload: {
479
534
  confirmed: boolean;
480
535
  };
536
+ } | {
537
+ type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;
538
+ payload: {
539
+ decision: PreemptionDecision;
540
+ };
481
541
  } | {
482
542
  type: typeof UI_RESPONSE.CANCEL;
483
543
  payload?: undefined;
484
544
  };
485
545
 
546
+ declare const DEVICE_EVENT = "DEVICE_EVENT";
547
+ /** Events originating from the hardware device. */
548
+ declare const DEVICE: {
549
+ readonly CONNECT: "device-connect";
550
+ readonly DISCONNECT: "device-disconnect";
551
+ readonly CHANGED: "device-changed";
552
+ readonly ACQUIRE: "device-acquire";
553
+ readonly RELEASE: "device-release";
554
+ readonly FEATURES: "features";
555
+ readonly SUPPORT_FEATURES: "support_features";
556
+ };
557
+
486
558
  /** Events generated by SDK internal detection (not from hardware directly). */
487
559
  declare const SDK: {
488
560
  readonly DEVICE_STUCK: "device-stuck";
@@ -556,6 +628,16 @@ type UiRequestEvent = {
556
628
  retryCount: number;
557
629
  maxRetries: number;
558
630
  };
631
+ } | {
632
+ type: typeof UI_REQUEST.REQUEST_PREEMPTION;
633
+ payload: {
634
+ deviceId: string;
635
+ currentJob: ActiveJobInfo;
636
+ newJob: {
637
+ label?: string;
638
+ interruptibility: Interruptibility;
639
+ };
640
+ };
559
641
  } | {
560
642
  type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
561
643
  payload: Record<string, never>;
@@ -661,6 +743,17 @@ interface HardwareEventMap {
661
743
  maxRetries: number;
662
744
  };
663
745
  };
746
+ [UI_REQUEST.REQUEST_PREEMPTION]: {
747
+ type: typeof UI_REQUEST.REQUEST_PREEMPTION;
748
+ payload: {
749
+ deviceId: string;
750
+ currentJob: ActiveJobInfo;
751
+ newJob: {
752
+ label?: string;
753
+ interruptibility: Interruptibility;
754
+ };
755
+ };
756
+ };
664
757
  [UI_REQUEST.CLOSE_UI_WINDOW]: {
665
758
  type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
666
759
  payload: Record<string, never>;
@@ -792,77 +885,6 @@ interface DeviceDisconnectEvent {
792
885
  }
793
886
  type DeviceChangeEvent = DeviceConnectEvent | DeviceDisconnectEvent;
794
887
 
795
- /**
796
- * Per-device serial job queue with preemption support and stuck recovery.
797
- * Ensures that only one operation runs at a time per device, with intelligent
798
- * handling of conflicting operations.
799
- */
800
- type Interruptibility = 'none' | 'safe' | 'confirm';
801
- type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';
802
- interface JobOptions {
803
- interruptibility?: Interruptibility;
804
- label?: string;
805
- }
806
- interface ActiveJobInfo {
807
- label?: string;
808
- interruptibility: Interruptibility;
809
- startedAt: number;
810
- }
811
- interface PreemptionEvent {
812
- deviceId: string;
813
- currentJob: ActiveJobInfo;
814
- newJob: {
815
- label?: string;
816
- interruptibility: Interruptibility;
817
- };
818
- }
819
- declare class DeviceJobQueue {
820
- private readonly _queues;
821
- private readonly _active;
822
- /**
823
- * Called when a new job conflicts with an active 'confirm'-level job.
824
- * UI should show a dialog and return the user's decision.
825
- * If not set, defaults to 'wait' (queue behind current job).
826
- */
827
- onPreemptionRequest?: (event: PreemptionEvent) => Promise<PreemptionDecision>;
828
- /**
829
- * Enqueue a job for a specific device.
830
- * If a job is already running for this device, behavior depends on interruptibility:
831
- * - 'none': new job queues silently (no preemption possible)
832
- * - 'safe': current job is auto-cancelled, new job runs immediately after
833
- * - 'confirm': onPreemptionRequest is called to ask user
834
- */
835
- enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
836
- /** Manually cancel the active job on a device. Returns false if job is non-interruptible. */
837
- cancelActive(deviceId: string): boolean;
838
- /** Force cancel regardless of interruptibility. Use for device stuck recovery. */
839
- forceCancelActive(deviceId: string): boolean;
840
- /** Get info about the currently active job for a device, or null if idle. */
841
- getActiveJob(deviceId: string): ActiveJobInfo | null;
842
- clear(): void;
843
- }
844
-
845
- /**
846
- * Abstraction for UI communication during device interactions.
847
- * Implementations handle different execution contexts:
848
- * - DirectUiBridge: same-process event emitter (default)
849
- * - IframeUiBridge: postMessage-based (future)
850
- * - ExtensionUiBridge: chrome.runtime.sendMessage (future)
851
- */
852
- interface IUiBridge {
853
- /** Ask the user for PIN entry. Returns the PIN string. */
854
- requestPin(device: DeviceInfo, signal?: AbortSignal): Promise<string>;
855
- /** Ask the user for passphrase entry. Returns the passphrase string. */
856
- requestPassphrase(device: DeviceInfo, signal?: AbortSignal): Promise<string>;
857
- /** Notify the UI about a button press request on the device. */
858
- notifyButton(device: DeviceInfo, code?: string): void;
859
- /**
860
- * Ask the user whether to preempt the current device operation.
861
- * Only called for 'confirm'-level operations.
862
- */
863
- requestPreemption(device: DeviceInfo, activeLabel: string, newLabel: string): Promise<PreemptionDecision>;
864
- }
865
-
866
888
  /**
867
889
  * Minimal device info returned during discovery (searchDevices).
868
890
  * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
@@ -1018,27 +1040,6 @@ declare class TypedEventEmitter<TMap extends Record<string, any> = Record<string
1018
1040
  removeAllListeners(): void;
1019
1041
  }
1020
1042
 
1021
- /** 10 min — every UI request is human-in-the-loop; bias toward "wait long". */
1022
- declare const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600000;
1023
- declare const UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
1024
- declare const UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
1025
- declare const UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
1026
- /**
1027
- * Per-type single-slot registry for adapter-level UI requests. A new `wait`
1028
- * of the same type preempts (rejects) the prior one. Unknown response types
1029
- * are dropped silently so the public `uiResponse` entry never throws.
1030
- */
1031
- declare class UiRequestRegistry {
1032
- private pending;
1033
- wait<T = unknown>(requestType: string, options?: {
1034
- timeoutMs?: number;
1035
- }): Promise<T>;
1036
- resolve(responseType: string, payload: unknown): void;
1037
- cancel(requestType?: string): void;
1038
- reset(): void;
1039
- hasPending(requestType: string): boolean;
1040
- }
1041
-
1042
1043
  /**
1043
1044
  * Compare two semver strings (e.g. "2.1.0" vs "2.3.1").
1044
1045
  * Returns -1 if a < b, 0 if equal, 1 if a > b.
@@ -1071,4 +1072,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
1071
1072
  total: number;
1072
1073
  }) => void): Promise<Response<TResult[]>>;
1073
1074
 
1074
- 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 DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmGetPublicKeyParams, type EvmPublicKey, 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 IUiBridge, type IUiHandler, 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 SolGetPublicKeyParams, type SolPublicKey, 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 };
1075
+ 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 IUiHandler, 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 };