@onekeyfe/hwk-adapter-core 1.1.26-alpha.9 → 1.1.26
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 +193 -124
- package/dist/index.d.ts +193 -124
- package/dist/index.js +102 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -27,6 +27,8 @@ declare enum HardwareErrorCode {
|
|
|
27
27
|
InvalidParams = 10002,
|
|
28
28
|
OperationTimeout = 10003,
|
|
29
29
|
MethodNotSupported = 10004,
|
|
30
|
+
/** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */
|
|
31
|
+
UserAborted = 10005,
|
|
30
32
|
DeviceNotFound = 10100,
|
|
31
33
|
DeviceDisconnected = 10101,
|
|
32
34
|
DeviceBusy = 10102,
|
|
@@ -34,6 +36,10 @@ declare enum HardwareErrorCode {
|
|
|
34
36
|
DeviceNotInitialized = 10104,
|
|
35
37
|
DeviceInBootloader = 10105,
|
|
36
38
|
DeviceMismatch = 10106,
|
|
39
|
+
/** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */
|
|
40
|
+
DeviceAppStuck = 10107,
|
|
41
|
+
/** Vendor (Ledger / Trezor) doesn't support the chain at all. */
|
|
42
|
+
ChainNotSupported = 10108,
|
|
37
43
|
FirmwareTooOld = 10200,
|
|
38
44
|
FirmwareUpdateRequired = 10201,
|
|
39
45
|
TransportError = 10300,
|
|
@@ -45,10 +51,19 @@ declare enum HardwareErrorCode {
|
|
|
45
51
|
* permission" toast and let the user retry manually.
|
|
46
52
|
*/
|
|
47
53
|
DevicePermissionDenied = 10303,
|
|
54
|
+
/**
|
|
55
|
+
* BLE SMP pairing did not complete within the GATT bonding window.
|
|
56
|
+
* GATT connected but the device didn't acknowledge SMP — typically
|
|
57
|
+
* because the user didn't confirm the passkey on the device, or the
|
|
58
|
+
* device went out of range mid-pairing. Distinct from OperationTimeout
|
|
59
|
+
* (generic) and from DeviceLocked (Secure Element actually locked).
|
|
60
|
+
*/
|
|
61
|
+
BlePairingTimeout = 10304,
|
|
48
62
|
PinInvalid = 10400,
|
|
49
63
|
PinCancelled = 10401,
|
|
50
64
|
PassphraseRejected = 10402,
|
|
51
|
-
|
|
65
|
+
/** Chain app NOT INSTALLED on device. User must install via Ledger Live. */
|
|
66
|
+
AppNotInstalled = 10500,
|
|
52
67
|
WrongApp = 10501,
|
|
53
68
|
/** 0x911c Command code not supported — app predates current SDK. */
|
|
54
69
|
AppTooOld = 10502,
|
|
@@ -74,6 +89,18 @@ declare enum HardwareErrorCode {
|
|
|
74
89
|
/** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
|
|
75
90
|
BtcUnexpectedState = 11301
|
|
76
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Device-level failures the SDK cannot self-recover from — affect the entire
|
|
94
|
+
* batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-
|
|
95
|
+
* skip in onboarding). Combined with `accounts.length === 0`, signals
|
|
96
|
+
* genuine orphan. Also reused as the batch-abort whitelist for HWK.
|
|
97
|
+
* Single source of truth.
|
|
98
|
+
*
|
|
99
|
+
* UserRejected (device-side reject) is included: pressing reject is an
|
|
100
|
+
* explicit "I don't consent" — continuing the batch to ask again on the
|
|
101
|
+
* next chain is harassment, not helpful.
|
|
102
|
+
*/
|
|
103
|
+
declare const ORPHAN_ELIGIBLE_ERROR_CODES: number[];
|
|
77
104
|
|
|
78
105
|
interface Success<T> {
|
|
79
106
|
success: true;
|
|
@@ -84,11 +111,12 @@ interface Failure {
|
|
|
84
111
|
payload: {
|
|
85
112
|
error: string;
|
|
86
113
|
code: HardwareErrorCode;
|
|
114
|
+
params?: Record<string, unknown>;
|
|
87
115
|
};
|
|
88
116
|
}
|
|
89
117
|
type Response<T> = Success<T> | Failure;
|
|
90
118
|
declare function success<T>(payload: T): Success<T>;
|
|
91
|
-
declare function failure(code: HardwareErrorCode, error: string): Failure;
|
|
119
|
+
declare function failure(code: HardwareErrorCode, error: string, params?: Record<string, unknown>): Failure;
|
|
92
120
|
|
|
93
121
|
type VendorType = 'trezor' | 'ledger';
|
|
94
122
|
type ConnectionType = 'usb' | 'ble';
|
|
@@ -113,13 +141,22 @@ interface DeviceCapabilities {
|
|
|
113
141
|
}
|
|
114
142
|
interface DeviceInfo {
|
|
115
143
|
vendor: VendorType;
|
|
144
|
+
/** Machine model id (e.g. "nanoX"). */
|
|
116
145
|
model: string;
|
|
146
|
+
/** Human-readable model name (e.g. "Ledger Nano X"). */
|
|
147
|
+
modelName?: string;
|
|
117
148
|
firmwareVersion: string;
|
|
118
149
|
deviceId: string;
|
|
119
150
|
connectId: string;
|
|
120
151
|
label?: string;
|
|
121
152
|
connectionType: ConnectionType;
|
|
122
153
|
battery?: number;
|
|
154
|
+
/** BLE signal strength (BLE only). */
|
|
155
|
+
rssi?: number | null;
|
|
156
|
+
/** BLE connectable flag (BLE only). */
|
|
157
|
+
isConnectable?: boolean | null;
|
|
158
|
+
/** USB serial number (USB only). */
|
|
159
|
+
serialNumber?: string;
|
|
123
160
|
/** Device capabilities — varies by vendor, model, and connection type */
|
|
124
161
|
capabilities?: DeviceCapabilities;
|
|
125
162
|
}
|
|
@@ -211,13 +248,8 @@ interface EvmSignature {
|
|
|
211
248
|
signature: string;
|
|
212
249
|
address?: string;
|
|
213
250
|
}
|
|
214
|
-
type ProgressCallback = (progress: {
|
|
215
|
-
index: number;
|
|
216
|
-
total: number;
|
|
217
|
-
}) => void;
|
|
218
251
|
interface IEvmMethods {
|
|
219
252
|
evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
|
|
220
|
-
evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
|
|
221
253
|
evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
|
|
222
254
|
evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
|
|
223
255
|
evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
|
|
@@ -316,7 +348,6 @@ interface BtcSignature {
|
|
|
316
348
|
}
|
|
317
349
|
interface IBtcMethods {
|
|
318
350
|
btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams): Promise<Response<BtcAddress>>;
|
|
319
|
-
btcGetAddresses(connectId: string, deviceId: string, params: BtcGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<BtcAddress[]>>;
|
|
320
351
|
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
321
352
|
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
322
353
|
btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams): Promise<Response<BtcSignedPsbt>>;
|
|
@@ -363,7 +394,6 @@ interface SolSignature {
|
|
|
363
394
|
}
|
|
364
395
|
interface ISolMethods {
|
|
365
396
|
solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
|
|
366
|
-
solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
|
|
367
397
|
solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
|
|
368
398
|
solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
|
|
369
399
|
}
|
|
@@ -397,7 +427,6 @@ interface TronSignature {
|
|
|
397
427
|
}
|
|
398
428
|
interface ITronMethods {
|
|
399
429
|
tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
|
|
400
|
-
tronGetAddresses(connectId: string, deviceId: string, params: TronGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<TronAddress[]>>;
|
|
401
430
|
tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams): Promise<Response<TronSignedTx>>;
|
|
402
431
|
tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams): Promise<Response<TronSignature>>;
|
|
403
432
|
}
|
|
@@ -438,90 +467,6 @@ declare const DEVICE: {
|
|
|
438
467
|
readonly CHANGED: "device-changed";
|
|
439
468
|
};
|
|
440
469
|
|
|
441
|
-
/** 10 min — every UI request is human-in-the-loop; bias toward "wait long". */
|
|
442
|
-
declare const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600000;
|
|
443
|
-
declare const UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
|
|
444
|
-
declare const UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
|
|
445
|
-
declare const UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
|
|
446
|
-
/**
|
|
447
|
-
* Per-type single-slot registry for adapter-level UI requests. A new `wait`
|
|
448
|
-
* of the same type preempts (rejects) the prior one. Unknown response types
|
|
449
|
-
* are dropped silently so the public `uiResponse` entry never throws.
|
|
450
|
-
*/
|
|
451
|
-
declare class UiRequestRegistry {
|
|
452
|
-
private pending;
|
|
453
|
-
wait<T = unknown>(requestType: string, options?: {
|
|
454
|
-
timeoutMs?: number;
|
|
455
|
-
}): Promise<T>;
|
|
456
|
-
resolve(responseType: string, payload: unknown): void;
|
|
457
|
-
cancel(requestType?: string): void;
|
|
458
|
-
reset(): void;
|
|
459
|
-
hasPending(requestType: string): boolean;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Per-device serial job queue with preemption support and stuck recovery.
|
|
464
|
-
* Ensures that only one operation runs at a time per device, with intelligent
|
|
465
|
-
* handling of conflicting operations.
|
|
466
|
-
*
|
|
467
|
-
* The 'confirm' level uses the standard UI request/response flow:
|
|
468
|
-
* emits REQUEST_PREEMPTION → waits for RECEIVE_PREEMPTION via UiRequestRegistry.
|
|
469
|
-
*/
|
|
470
|
-
|
|
471
|
-
type Interruptibility = 'none' | 'safe' | 'confirm';
|
|
472
|
-
type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';
|
|
473
|
-
interface JobOptions {
|
|
474
|
-
interruptibility?: Interruptibility;
|
|
475
|
-
label?: string;
|
|
476
|
-
}
|
|
477
|
-
interface ActiveJobInfo {
|
|
478
|
-
label?: string;
|
|
479
|
-
interruptibility: Interruptibility;
|
|
480
|
-
startedAt: number;
|
|
481
|
-
}
|
|
482
|
-
interface PreemptionEvent {
|
|
483
|
-
deviceId: string;
|
|
484
|
-
currentJob: ActiveJobInfo;
|
|
485
|
-
newJob: {
|
|
486
|
-
label?: string;
|
|
487
|
-
interruptibility: Interruptibility;
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
interface DeviceJobQueueDeps {
|
|
491
|
-
/** Emit a UI request event to the frontend. */
|
|
492
|
-
emit: (event: string, data: unknown) => void;
|
|
493
|
-
/** Registry for waiting on UI responses. */
|
|
494
|
-
uiRegistry: UiRequestRegistry;
|
|
495
|
-
}
|
|
496
|
-
declare class DeviceJobQueue {
|
|
497
|
-
private readonly _queues;
|
|
498
|
-
private readonly _active;
|
|
499
|
-
private readonly _deps;
|
|
500
|
-
/** Incremented on clear() so stale queued jobs can detect invalidation. */
|
|
501
|
-
private _generation;
|
|
502
|
-
constructor(deps?: DeviceJobQueueDeps);
|
|
503
|
-
/**
|
|
504
|
-
* Enqueue a job for a specific device.
|
|
505
|
-
* If a job is already running for this device, behavior depends on interruptibility:
|
|
506
|
-
* - 'none': new job queues silently (no preemption possible)
|
|
507
|
-
* - 'safe': current job is auto-cancelled, new job runs immediately after
|
|
508
|
-
* - 'confirm': emits REQUEST_PREEMPTION and waits for UI response
|
|
509
|
-
*/
|
|
510
|
-
enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
|
|
511
|
-
/** Manually cancel the active job on a device. Returns false if job is non-interruptible. */
|
|
512
|
-
cancelActive(deviceId: string): boolean;
|
|
513
|
-
/** Force cancel regardless of interruptibility. Use for device stuck recovery. */
|
|
514
|
-
forceCancelActive(deviceId: string): boolean;
|
|
515
|
-
/** Get info about the currently active job for a device, or null if idle. */
|
|
516
|
-
getActiveJob(deviceId: string): ActiveJobInfo | null;
|
|
517
|
-
clear(): void;
|
|
518
|
-
/**
|
|
519
|
-
* Request preemption decision via UI request/response flow.
|
|
520
|
-
* Falls back to 'wait' if deps are not provided.
|
|
521
|
-
*/
|
|
522
|
-
private _requestPreemptionDecision;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
470
|
declare const UI_EVENT = "UI_EVENT";
|
|
526
471
|
declare const UI_REQUEST: {
|
|
527
472
|
readonly REQUEST_PIN: "ui-request-pin";
|
|
@@ -533,7 +478,7 @@ declare const UI_REQUEST: {
|
|
|
533
478
|
readonly REQUEST_DEVICE_PERMISSION: "ui-request-device-permission";
|
|
534
479
|
readonly REQUEST_SELECT_DEVICE: "ui-request-select-device";
|
|
535
480
|
readonly REQUEST_DEVICE_CONNECT: "ui-request-device-connect";
|
|
536
|
-
readonly
|
|
481
|
+
readonly REQUEST_BTC_HIGH_INDEX_CONFIRM: "ui-request-btc-high-index-confirm";
|
|
537
482
|
readonly CLOSE_UI_WINDOW: "ui-close";
|
|
538
483
|
readonly DEVICE_PROGRESS: "ui-device_progress";
|
|
539
484
|
readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
|
|
@@ -547,9 +492,15 @@ declare const UI_RESPONSE: {
|
|
|
547
492
|
readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
|
|
548
493
|
readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
|
|
549
494
|
readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
|
|
550
|
-
readonly
|
|
495
|
+
readonly RECEIVE_BTC_HIGH_INDEX_CONFIRM: "receive-btc-high-index-confirm";
|
|
551
496
|
readonly CANCEL: "cancel";
|
|
552
497
|
};
|
|
498
|
+
type DevicePermissionDeniedReason = 'bluetoothTurnedOff' | 'permissionDenied' | (string & Record<never, never>);
|
|
499
|
+
type DevicePermissionResponse = {
|
|
500
|
+
granted: boolean;
|
|
501
|
+
reason?: DevicePermissionDeniedReason;
|
|
502
|
+
message?: string;
|
|
503
|
+
};
|
|
553
504
|
type UiResponseEvent = {
|
|
554
505
|
type: typeof UI_RESPONSE.RECEIVE_PIN;
|
|
555
506
|
payload: string;
|
|
@@ -578,13 +529,11 @@ type UiResponseEvent = {
|
|
|
578
529
|
};
|
|
579
530
|
} | {
|
|
580
531
|
type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
|
|
581
|
-
payload:
|
|
582
|
-
granted: boolean;
|
|
583
|
-
};
|
|
532
|
+
payload: DevicePermissionResponse;
|
|
584
533
|
} | {
|
|
585
|
-
type: typeof UI_RESPONSE.
|
|
534
|
+
type: typeof UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM;
|
|
586
535
|
payload: {
|
|
587
|
-
|
|
536
|
+
confirmed: boolean;
|
|
588
537
|
};
|
|
589
538
|
} | {
|
|
590
539
|
type: typeof UI_RESPONSE.CANCEL;
|
|
@@ -607,7 +556,16 @@ interface ConnectorDevice {
|
|
|
607
556
|
connectId: string;
|
|
608
557
|
deviceId: string;
|
|
609
558
|
name: string;
|
|
559
|
+
/** Machine model id (e.g. "nanoX"). */
|
|
610
560
|
model?: string;
|
|
561
|
+
/** Human-readable model name (e.g. "Ledger Nano X"). */
|
|
562
|
+
modelName?: string;
|
|
563
|
+
/** BLE signal strength (BLE only). */
|
|
564
|
+
rssi?: number | null;
|
|
565
|
+
/** BLE connectable flag (BLE only). */
|
|
566
|
+
isConnectable?: boolean | null;
|
|
567
|
+
/** USB serial number (USB only). */
|
|
568
|
+
serialNumber?: string;
|
|
611
569
|
/** Device capabilities — available from scan time */
|
|
612
570
|
capabilities?: DeviceCapabilities;
|
|
613
571
|
}
|
|
@@ -621,6 +579,8 @@ type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request'
|
|
|
621
579
|
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
622
580
|
*/
|
|
623
581
|
declare enum EConnectorInteraction {
|
|
582
|
+
/** Adapter is actively searching for the device (no session yet) */
|
|
583
|
+
Searching = "searching",
|
|
624
584
|
/** Device requires user to open a specific app */
|
|
625
585
|
ConfirmOpenApp = "confirm-open-app",
|
|
626
586
|
/** Device requires user to unlock */
|
|
@@ -631,6 +591,11 @@ declare enum EConnectorInteraction {
|
|
|
631
591
|
InteractionComplete = "interaction-complete"
|
|
632
592
|
}
|
|
633
593
|
type ConnectorUiEvent = {
|
|
594
|
+
type: EConnectorInteraction.Searching;
|
|
595
|
+
payload: {
|
|
596
|
+
sessionId: string;
|
|
597
|
+
};
|
|
598
|
+
} | {
|
|
634
599
|
type: EConnectorInteraction.ConfirmOpenApp;
|
|
635
600
|
payload: {
|
|
636
601
|
sessionId: string;
|
|
@@ -797,18 +762,23 @@ type UiRequestEvent = {
|
|
|
797
762
|
} | {
|
|
798
763
|
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
799
764
|
payload: {
|
|
765
|
+
/** Vendor that emitted the request, e.g. 'ledger', 'trezor'. */
|
|
766
|
+
vendor: string;
|
|
767
|
+
/**
|
|
768
|
+
* Why the SDK is asking for a reconnect. Lets the app render
|
|
769
|
+
* vendor-aware copy without inspecting message strings.
|
|
770
|
+
* - 'device-not-found': search returned 0 / device not reachable.
|
|
771
|
+
* Future values can be added (e.g. 'pairing-failed') as new fallback
|
|
772
|
+
* causes are surfaced.
|
|
773
|
+
*/
|
|
774
|
+
reason: string;
|
|
775
|
+
/**
|
|
776
|
+
* Best-effort English fallback. Apps should prefer rendering via
|
|
777
|
+
* `vendor` + `reason` for i18n; fall back to this if the combination
|
|
778
|
+
* isn't recognized.
|
|
779
|
+
*/
|
|
800
780
|
message: string;
|
|
801
781
|
};
|
|
802
|
-
} | {
|
|
803
|
-
type: typeof UI_REQUEST.REQUEST_PREEMPTION;
|
|
804
|
-
payload: {
|
|
805
|
-
deviceId: string;
|
|
806
|
-
currentJob: ActiveJobInfo;
|
|
807
|
-
newJob: {
|
|
808
|
-
label?: string;
|
|
809
|
-
interruptibility: Interruptibility;
|
|
810
|
-
};
|
|
811
|
-
};
|
|
812
782
|
} | {
|
|
813
783
|
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
814
784
|
payload: Record<string, never>;
|
|
@@ -914,18 +884,17 @@ interface HardwareEventMap {
|
|
|
914
884
|
[UI_REQUEST.REQUEST_DEVICE_CONNECT]: {
|
|
915
885
|
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
916
886
|
payload: {
|
|
887
|
+
vendor: string;
|
|
888
|
+
reason: string;
|
|
917
889
|
message: string;
|
|
918
890
|
};
|
|
919
891
|
};
|
|
920
|
-
[UI_REQUEST.
|
|
921
|
-
type: typeof UI_REQUEST.
|
|
892
|
+
[UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM]: {
|
|
893
|
+
type: typeof UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM;
|
|
922
894
|
payload: {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
label?: string;
|
|
927
|
-
interruptibility: Interruptibility;
|
|
928
|
-
};
|
|
895
|
+
vendor: string;
|
|
896
|
+
path: string;
|
|
897
|
+
accountIndex: number;
|
|
929
898
|
};
|
|
930
899
|
};
|
|
931
900
|
[UI_REQUEST.CLOSE_UI_WINDOW]: {
|
|
@@ -965,12 +934,13 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
965
934
|
dispose(): Promise<void>;
|
|
966
935
|
getAvailableTransports(): TransportType[];
|
|
967
936
|
switchTransport(type: TransportType): Promise<void>;
|
|
968
|
-
searchDevices(): Promise<DeviceInfo[]>;
|
|
937
|
+
searchDevices(options?: SearchDevicesOptions): Promise<DeviceInfo[]>;
|
|
969
938
|
connectDevice(connectId: string): Promise<Response<string>>;
|
|
970
939
|
disconnectDevice(connectId: string): Promise<void>;
|
|
971
940
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
972
941
|
getSupportedChains(): ChainCapability[];
|
|
973
|
-
|
|
942
|
+
/** Abort the in-flight call. Omit connectId to cancel whatever is active. */
|
|
943
|
+
cancel(connectId?: string): void;
|
|
974
944
|
/** Respond to any pending `ui-request-*`. */
|
|
975
945
|
uiResponse(response: UiResponseEvent): void;
|
|
976
946
|
/**
|
|
@@ -988,6 +958,16 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
988
958
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
989
959
|
off(event: string, listener: DeviceEventListener): void;
|
|
990
960
|
}
|
|
961
|
+
interface SearchDevicesOptions {
|
|
962
|
+
/**
|
|
963
|
+
* Clear cached adapter sessions before scanning.
|
|
964
|
+
*
|
|
965
|
+
* Use this for an explicit "search/add another device" flow on transports
|
|
966
|
+
* whose connectId is not stable, such as Ledger WebHID. Normal refresh scans
|
|
967
|
+
* should leave this false so an active session can still be reused.
|
|
968
|
+
*/
|
|
969
|
+
resetSession?: boolean;
|
|
970
|
+
}
|
|
991
971
|
|
|
992
972
|
/**
|
|
993
973
|
* Low-level device descriptor from Transport layer.
|
|
@@ -1000,12 +980,28 @@ interface DeviceDescriptor {
|
|
|
1000
980
|
product?: number;
|
|
1001
981
|
/** USB vendor ID */
|
|
1002
982
|
vendor?: number;
|
|
1003
|
-
/** Device type/model identifier */
|
|
983
|
+
/** Device type/model identifier (e.g. "nanoX"). */
|
|
1004
984
|
type?: string;
|
|
1005
|
-
/**
|
|
985
|
+
/** Human-readable model name (e.g. "Ledger Nano X"). */
|
|
986
|
+
modelName?: string;
|
|
987
|
+
/** Human-readable display name from the transport layer. */
|
|
1006
988
|
name?: string;
|
|
989
|
+
/** Raw Ledger BLE advertisement name from RN BLE `Device.name`, when available. */
|
|
990
|
+
bleName?: string;
|
|
991
|
+
/** User-visible Ledger BLE local name from the raw RN BLE `Device.localName` field. */
|
|
992
|
+
localName?: string;
|
|
1007
993
|
/** Transport identifier (e.g., 'WEB-HID', 'BLE') */
|
|
1008
994
|
transport?: string;
|
|
995
|
+
/** BLE RSSI when provided by the transport scanner. */
|
|
996
|
+
rssi?: number | null;
|
|
997
|
+
/** BLE advertised service UUIDs, when provided by the scanner. */
|
|
998
|
+
serviceUUIDs?: string[] | null;
|
|
999
|
+
/** BLE connectable flag, when provided by the scanner. */
|
|
1000
|
+
isConnectable?: boolean | null;
|
|
1001
|
+
/** USB product name, when provided by the transport. */
|
|
1002
|
+
productName?: string;
|
|
1003
|
+
/** USB serial number, when provided by the transport. */
|
|
1004
|
+
serialNumber?: string;
|
|
1009
1005
|
}
|
|
1010
1006
|
interface DeviceConnectEvent {
|
|
1011
1007
|
type: 'device-connected';
|
|
@@ -1017,6 +1013,53 @@ interface DeviceDisconnectEvent {
|
|
|
1017
1013
|
}
|
|
1018
1014
|
type DeviceChangeEvent = DeviceConnectEvent | DeviceDisconnectEvent;
|
|
1019
1015
|
|
|
1016
|
+
/**
|
|
1017
|
+
* Pure FIFO job queue. Every enqueue chains onto the tail; jobs run one at
|
|
1018
|
+
* a time across all devices. The queue is intentionally passive — it does
|
|
1019
|
+
* NOT decide whether to interrupt or ask the user. Those are application-
|
|
1020
|
+
* layer concerns owned by the caller (e.g. a UI button handler that wants
|
|
1021
|
+
* to ask "device is busy, interrupt current?" before submitting). The
|
|
1022
|
+
* queue exposes inspection (`getActiveJob`) and explicit cancellation
|
|
1023
|
+
* (`cancelActive` / `cancelAll`) so callers can implement those policies
|
|
1024
|
+
* synchronously, without racing against in-flight enqueues.
|
|
1025
|
+
*/
|
|
1026
|
+
interface JobOptions {
|
|
1027
|
+
label?: string;
|
|
1028
|
+
rejectIfBusy?: boolean;
|
|
1029
|
+
busyError?: Error;
|
|
1030
|
+
}
|
|
1031
|
+
interface ActiveJobInfo {
|
|
1032
|
+
deviceId: string;
|
|
1033
|
+
label?: string;
|
|
1034
|
+
startedAt: number;
|
|
1035
|
+
}
|
|
1036
|
+
declare class DeviceJobQueue {
|
|
1037
|
+
private _tail;
|
|
1038
|
+
private _active;
|
|
1039
|
+
private readonly _jobs;
|
|
1040
|
+
/** Incremented on clear() so queued-but-not-yet-running jobs detect invalidation. */
|
|
1041
|
+
private _generation;
|
|
1042
|
+
private readonly _generationCancelReasons;
|
|
1043
|
+
/**
|
|
1044
|
+
* Enqueue a job. Runs after every previously-enqueued job has settled.
|
|
1045
|
+
* `deviceId` is a label only — used by inspection / cancellation routing.
|
|
1046
|
+
*/
|
|
1047
|
+
enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
|
|
1048
|
+
/** Cancel the active job. If `deviceId` is given, only cancels when it matches. */
|
|
1049
|
+
cancelActive(deviceId?: string): boolean;
|
|
1050
|
+
/** Force cancel the active job. `reason` becomes signal.reason. */
|
|
1051
|
+
forceCancelActive(deviceId?: string, reason?: Error): boolean;
|
|
1052
|
+
/** Cancel the active job (alias for callers that previously needed multi-device cancel). */
|
|
1053
|
+
cancelAllActive(reason?: Error): void;
|
|
1054
|
+
/** Cancel the active job and invalidate queued jobs that have not started. */
|
|
1055
|
+
cancelActiveAndPending(deviceId?: string, reason?: Error): boolean;
|
|
1056
|
+
/** Get info about the currently active job, or null if idle. */
|
|
1057
|
+
getActiveJob(deviceId?: string): ActiveJobInfo | null;
|
|
1058
|
+
/** True if any job is currently running. */
|
|
1059
|
+
isBusy(): boolean;
|
|
1060
|
+
clear(reason?: Error): void;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1020
1063
|
/**
|
|
1021
1064
|
* Minimal typed event emitter using Map<string, Set<listener>>.
|
|
1022
1065
|
* Each adapter uses this for device events (connect, disconnect, pin, etc.).
|
|
@@ -1041,6 +1084,32 @@ declare class TypedEventEmitter<TMap extends Record<string, any> = Record<string
|
|
|
1041
1084
|
removeAllListeners(): void;
|
|
1042
1085
|
}
|
|
1043
1086
|
|
|
1087
|
+
/** 10 min — every UI request is human-in-the-loop; bias toward "wait long". */
|
|
1088
|
+
declare const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600000;
|
|
1089
|
+
declare const UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
|
|
1090
|
+
declare const UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
|
|
1091
|
+
declare const UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
|
|
1092
|
+
/**
|
|
1093
|
+
* Per-type single-slot registry for adapter-level UI requests. A new `wait`
|
|
1094
|
+
* of the same type supersedes (rejects) the prior pending entry. With the
|
|
1095
|
+
* job queue running globally serially, cross-type collisions don't occur in
|
|
1096
|
+
* normal flow — same-type preemption is a defensive measure for callers
|
|
1097
|
+
* that fire the same request twice without waiting on the first.
|
|
1098
|
+
*
|
|
1099
|
+
* Unknown response types are dropped silently so the public `uiResponse`
|
|
1100
|
+
* entry never throws.
|
|
1101
|
+
*/
|
|
1102
|
+
declare class UiRequestRegistry {
|
|
1103
|
+
private pending;
|
|
1104
|
+
wait<T = unknown>(requestType: string, options?: {
|
|
1105
|
+
timeoutMs?: number;
|
|
1106
|
+
}): Promise<T>;
|
|
1107
|
+
resolve(responseType: string, payload: unknown): void;
|
|
1108
|
+
cancel(requestType?: string): void;
|
|
1109
|
+
reset(): void;
|
|
1110
|
+
hasPending(requestType?: string): boolean;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1044
1113
|
/**
|
|
1045
1114
|
* Compare two semver strings (e.g. "2.1.0" vs "2.3.1").
|
|
1046
1115
|
* Returns -1 if a < b, 0 if equal, 1 if a > b.
|
|
@@ -1076,4 +1145,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
|
|
|
1076
1145
|
total: number;
|
|
1077
1146
|
}) => void): Promise<Response<TResult[]>>;
|
|
1078
1147
|
|
|
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
|
|
1148
|
+
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 DevicePermissionDeniedReason, type DevicePermissionResponse, 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 JobOptions, ORPHAN_ELIGIBLE_ERROR_CODES, type PassphraseResponse, type QrDisplayData, type QrResponseData, type Response, SDK, type SdkEvent, type SearchDevicesOptions, 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 };
|