@onekeyfe/hwk-adapter-core 1.1.26-alpha.106 → 1.1.26-alpha.11
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 +255 -244
- package/dist/index.d.ts +255 -244
- package/dist/index.js +110 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,37 +1,84 @@
|
|
|
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 =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
UnknownError = 10000,
|
|
26
|
+
UserRejected = 10001,
|
|
27
|
+
InvalidParams = 10002,
|
|
28
|
+
OperationTimeout = 10003,
|
|
29
|
+
MethodNotSupported = 10004,
|
|
30
|
+
/** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */
|
|
31
|
+
UserAborted = 10005,
|
|
32
|
+
DeviceNotFound = 10100,
|
|
33
|
+
DeviceDisconnected = 10101,
|
|
34
|
+
DeviceBusy = 10102,
|
|
35
|
+
DeviceLocked = 10103,
|
|
36
|
+
DeviceNotInitialized = 10104,
|
|
37
|
+
DeviceInBootloader = 10105,
|
|
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,
|
|
43
|
+
FirmwareTooOld = 10200,
|
|
44
|
+
FirmwareUpdateRequired = 10201,
|
|
45
|
+
TransportError = 10300,
|
|
46
|
+
BridgeNotFound = 10301,
|
|
47
|
+
TransportNotAvailable = 10302,
|
|
48
|
+
/**
|
|
49
|
+
* OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
|
|
50
|
+
* unavailable, or dismissed. Consumers surface a single "please grant
|
|
51
|
+
* permission" toast and let the user retry manually.
|
|
52
|
+
*/
|
|
53
|
+
DevicePermissionDenied = 10303,
|
|
54
|
+
PinInvalid = 10400,
|
|
55
|
+
PinCancelled = 10401,
|
|
56
|
+
PassphraseRejected = 10402,
|
|
57
|
+
AppNotOpen = 10500,
|
|
58
|
+
WrongApp = 10501,
|
|
59
|
+
/** 0x911c Command code not supported — app predates current SDK. */
|
|
60
|
+
AppTooOld = 10502,
|
|
24
61
|
/** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
|
|
25
62
|
* user has not enabled Blind signing on the device. */
|
|
26
|
-
EvmBlindSigningRequired =
|
|
63
|
+
EvmBlindSigningRequired = 11000,
|
|
27
64
|
/** 0x6984 Plugin not installed */
|
|
28
|
-
EvmClearSignPluginMissing =
|
|
65
|
+
EvmClearSignPluginMissing = 11001,
|
|
29
66
|
/** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
|
|
30
|
-
EvmDataTooLarge =
|
|
67
|
+
EvmDataTooLarge = 11002,
|
|
31
68
|
/** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
|
|
32
|
-
EvmTxTypeNotSupported =
|
|
33
|
-
/**
|
|
34
|
-
|
|
69
|
+
EvmTxTypeNotSupported = 11003,
|
|
70
|
+
/** 0x6808 Blind signing disabled for this instruction. */
|
|
71
|
+
SolanaBlindSigningRequired = 11100,
|
|
72
|
+
/** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
|
|
73
|
+
TronCustomContractRequired = 11200,
|
|
74
|
+
/** 0x6a8b Transactions Data setting disabled. */
|
|
75
|
+
TronDataSigningRequired = 11201,
|
|
76
|
+
/** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
|
|
77
|
+
TronSignByHashRequired = 11202,
|
|
78
|
+
/** 0xb008 Wallet policy HMAC mismatch or not registered. */
|
|
79
|
+
BtcWalletPolicyHmacMismatch = 11300,
|
|
80
|
+
/** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
|
|
81
|
+
BtcUnexpectedState = 11301
|
|
35
82
|
}
|
|
36
83
|
|
|
37
84
|
interface Success<T> {
|
|
@@ -43,12 +90,11 @@ interface Failure {
|
|
|
43
90
|
payload: {
|
|
44
91
|
error: string;
|
|
45
92
|
code: HardwareErrorCode;
|
|
46
|
-
appName?: string;
|
|
47
93
|
};
|
|
48
94
|
}
|
|
49
95
|
type Response<T> = Success<T> | Failure;
|
|
50
96
|
declare function success<T>(payload: T): Success<T>;
|
|
51
|
-
declare function failure(code: HardwareErrorCode, error: string
|
|
97
|
+
declare function failure(code: HardwareErrorCode, error: string): Failure;
|
|
52
98
|
|
|
53
99
|
type VendorType = 'trezor' | 'ledger';
|
|
54
100
|
type ConnectionType = 'usb' | 'ble';
|
|
@@ -171,13 +217,8 @@ interface EvmSignature {
|
|
|
171
217
|
signature: string;
|
|
172
218
|
address?: string;
|
|
173
219
|
}
|
|
174
|
-
type ProgressCallback = (progress: {
|
|
175
|
-
index: number;
|
|
176
|
-
total: number;
|
|
177
|
-
}) => void;
|
|
178
220
|
interface IEvmMethods {
|
|
179
221
|
evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
|
|
180
|
-
evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
|
|
181
222
|
evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
|
|
182
223
|
evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
|
|
183
224
|
evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
|
|
@@ -250,10 +291,10 @@ interface BtcRefTransaction {
|
|
|
250
291
|
locktime: number;
|
|
251
292
|
}
|
|
252
293
|
interface BtcSignedTx {
|
|
253
|
-
signatures: string[];
|
|
254
294
|
serializedTx: string;
|
|
295
|
+
/** Present when the wallet returns per-input sigs separately (e.g. Trezor). */
|
|
296
|
+
signatures?: string[];
|
|
255
297
|
txid?: string;
|
|
256
|
-
signedPsbt?: string;
|
|
257
298
|
}
|
|
258
299
|
interface BtcSignPsbtParams {
|
|
259
300
|
psbt: string;
|
|
@@ -271,11 +312,11 @@ interface BtcSignMsgParams {
|
|
|
271
312
|
}
|
|
272
313
|
interface BtcSignature {
|
|
273
314
|
signature: string;
|
|
274
|
-
|
|
315
|
+
/** Optional — not all adapters return it (e.g. Ledger DMK). Derive via btcGetAddress if needed. */
|
|
316
|
+
address?: string;
|
|
275
317
|
}
|
|
276
318
|
interface IBtcMethods {
|
|
277
319
|
btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams): Promise<Response<BtcAddress>>;
|
|
278
|
-
btcGetAddresses(connectId: string, deviceId: string, params: BtcGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<BtcAddress[]>>;
|
|
279
320
|
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
280
321
|
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
281
322
|
btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams): Promise<Response<BtcSignedPsbt>>;
|
|
@@ -322,7 +363,6 @@ interface SolSignature {
|
|
|
322
363
|
}
|
|
323
364
|
interface ISolMethods {
|
|
324
365
|
solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
|
|
325
|
-
solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
|
|
326
366
|
solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
|
|
327
367
|
solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
|
|
328
368
|
}
|
|
@@ -356,7 +396,6 @@ interface TronSignature {
|
|
|
356
396
|
}
|
|
357
397
|
interface ITronMethods {
|
|
358
398
|
tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
|
|
359
|
-
tronGetAddresses(connectId: string, deviceId: string, params: TronGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<TronAddress[]>>;
|
|
360
399
|
tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams): Promise<Response<TronSignedTx>>;
|
|
361
400
|
tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams): Promise<Response<TronSignature>>;
|
|
362
401
|
}
|
|
@@ -383,12 +422,19 @@ interface QrResponseData {
|
|
|
383
422
|
declare const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string>;
|
|
384
423
|
type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';
|
|
385
424
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* device identity matching. Not used for security decisions.
|
|
425
|
+
* 16-char SHA-256 fingerprint for device-identity verification.
|
|
426
|
+
* Callers must canonicalize input (e.g. EVM address → lowercase) —
|
|
427
|
+
* encoding variations otherwise cause false DeviceMismatch.
|
|
390
428
|
*/
|
|
391
|
-
declare function deriveDeviceFingerprint(
|
|
429
|
+
declare function deriveDeviceFingerprint(value: string): string;
|
|
430
|
+
|
|
431
|
+
declare const DEVICE_EVENT = "DEVICE_EVENT";
|
|
432
|
+
/** Events originating from the hardware device. */
|
|
433
|
+
declare const DEVICE: {
|
|
434
|
+
readonly CONNECT: "device-connect";
|
|
435
|
+
readonly DISCONNECT: "device-disconnect";
|
|
436
|
+
readonly CHANGED: "device-changed";
|
|
437
|
+
};
|
|
392
438
|
|
|
393
439
|
/** 10 min — every UI request is human-in-the-loop; bias toward "wait long". */
|
|
394
440
|
declare const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600000;
|
|
@@ -408,7 +454,7 @@ declare class UiRequestRegistry {
|
|
|
408
454
|
resolve(responseType: string, payload: unknown): void;
|
|
409
455
|
cancel(requestType?: string): void;
|
|
410
456
|
reset(): void;
|
|
411
|
-
hasPending(requestType
|
|
457
|
+
hasPending(requestType?: string): boolean;
|
|
412
458
|
}
|
|
413
459
|
|
|
414
460
|
/**
|
|
@@ -449,6 +495,8 @@ declare class DeviceJobQueue {
|
|
|
449
495
|
private readonly _queues;
|
|
450
496
|
private readonly _active;
|
|
451
497
|
private readonly _deps;
|
|
498
|
+
/** Incremented on clear() so stale queued jobs can detect invalidation. */
|
|
499
|
+
private _generation;
|
|
452
500
|
constructor(deps?: DeviceJobQueueDeps);
|
|
453
501
|
/**
|
|
454
502
|
* Enqueue a job for a specific device.
|
|
@@ -460,8 +508,8 @@ declare class DeviceJobQueue {
|
|
|
460
508
|
enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
|
|
461
509
|
/** Manually cancel the active job on a device. Returns false if job is non-interruptible. */
|
|
462
510
|
cancelActive(deviceId: string): boolean;
|
|
463
|
-
/** Force cancel regardless of interruptibility.
|
|
464
|
-
forceCancelActive(deviceId: string): boolean;
|
|
511
|
+
/** Force cancel regardless of interruptibility. `reason` becomes signal.reason. */
|
|
512
|
+
forceCancelActive(deviceId: string, reason?: Error): boolean;
|
|
465
513
|
/** Get info about the currently active job for a device, or null if idle. */
|
|
466
514
|
getActiveJob(deviceId: string): ActiveJobInfo | null;
|
|
467
515
|
clear(): void;
|
|
@@ -496,6 +544,7 @@ declare const UI_RESPONSE: {
|
|
|
496
544
|
readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
|
|
497
545
|
readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
|
|
498
546
|
readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
|
|
547
|
+
readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
|
|
499
548
|
readonly RECEIVE_PREEMPTION: "receive-preemption";
|
|
500
549
|
readonly CANCEL: "cancel";
|
|
501
550
|
};
|
|
@@ -525,6 +574,11 @@ type UiResponseEvent = {
|
|
|
525
574
|
payload: {
|
|
526
575
|
confirmed: boolean;
|
|
527
576
|
};
|
|
577
|
+
} | {
|
|
578
|
+
type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
|
|
579
|
+
payload: {
|
|
580
|
+
granted: boolean;
|
|
581
|
+
};
|
|
528
582
|
} | {
|
|
529
583
|
type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;
|
|
530
584
|
payload: {
|
|
@@ -535,18 +589,6 @@ type UiResponseEvent = {
|
|
|
535
589
|
payload?: undefined;
|
|
536
590
|
};
|
|
537
591
|
|
|
538
|
-
declare const DEVICE_EVENT = "DEVICE_EVENT";
|
|
539
|
-
/** Events originating from the hardware device. */
|
|
540
|
-
declare const DEVICE: {
|
|
541
|
-
readonly CONNECT: "device-connect";
|
|
542
|
-
readonly DISCONNECT: "device-disconnect";
|
|
543
|
-
readonly CHANGED: "device-changed";
|
|
544
|
-
readonly ACQUIRE: "device-acquire";
|
|
545
|
-
readonly RELEASE: "device-release";
|
|
546
|
-
readonly FEATURES: "features";
|
|
547
|
-
readonly SUPPORT_FEATURES: "support_features";
|
|
548
|
-
};
|
|
549
|
-
|
|
550
592
|
/** Events generated by SDK internal detection (not from hardware directly). */
|
|
551
593
|
declare const SDK: {
|
|
552
594
|
readonly DEVICE_STUCK: "device-stuck";
|
|
@@ -555,6 +597,139 @@ declare const SDK: {
|
|
|
555
597
|
readonly DEVICE_INTERACTION: "device-interaction";
|
|
556
598
|
};
|
|
557
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Minimal device info returned during discovery (searchDevices).
|
|
602
|
+
* At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
|
|
603
|
+
*/
|
|
604
|
+
interface ConnectorDevice {
|
|
605
|
+
connectId: string;
|
|
606
|
+
deviceId: string;
|
|
607
|
+
name: string;
|
|
608
|
+
model?: string;
|
|
609
|
+
/** Device capabilities — available from scan time */
|
|
610
|
+
capabilities?: DeviceCapabilities;
|
|
611
|
+
}
|
|
612
|
+
interface ConnectorSession {
|
|
613
|
+
sessionId: string;
|
|
614
|
+
deviceInfo: DeviceInfo;
|
|
615
|
+
}
|
|
616
|
+
type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
|
|
617
|
+
/**
|
|
618
|
+
* Interaction event types emitted via 'ui-event'.
|
|
619
|
+
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
620
|
+
*/
|
|
621
|
+
declare enum EConnectorInteraction {
|
|
622
|
+
/** Device requires user to open a specific app */
|
|
623
|
+
ConfirmOpenApp = "confirm-open-app",
|
|
624
|
+
/** Device requires user to unlock */
|
|
625
|
+
UnlockDevice = "unlock-device",
|
|
626
|
+
/** Device needs user to confirm on device (sign, verify, etc.) */
|
|
627
|
+
ConfirmOnDevice = "confirm-on-device",
|
|
628
|
+
/** Previous interaction completed — clear UI prompt */
|
|
629
|
+
InteractionComplete = "interaction-complete"
|
|
630
|
+
}
|
|
631
|
+
type ConnectorUiEvent = {
|
|
632
|
+
type: EConnectorInteraction.ConfirmOpenApp;
|
|
633
|
+
payload: {
|
|
634
|
+
sessionId: string;
|
|
635
|
+
};
|
|
636
|
+
} | {
|
|
637
|
+
type: EConnectorInteraction.UnlockDevice;
|
|
638
|
+
payload: {
|
|
639
|
+
sessionId: string;
|
|
640
|
+
};
|
|
641
|
+
} | {
|
|
642
|
+
type: EConnectorInteraction.ConfirmOnDevice;
|
|
643
|
+
payload: {
|
|
644
|
+
sessionId: string;
|
|
645
|
+
};
|
|
646
|
+
} | {
|
|
647
|
+
type: EConnectorInteraction.InteractionComplete;
|
|
648
|
+
payload: {
|
|
649
|
+
sessionId: string;
|
|
650
|
+
};
|
|
651
|
+
};
|
|
652
|
+
interface ConnectorEventMap {
|
|
653
|
+
'device-connect': {
|
|
654
|
+
device: ConnectorDevice;
|
|
655
|
+
};
|
|
656
|
+
'device-disconnect': {
|
|
657
|
+
connectId: string;
|
|
658
|
+
};
|
|
659
|
+
'ui-request': {
|
|
660
|
+
type: string;
|
|
661
|
+
payload?: unknown;
|
|
662
|
+
};
|
|
663
|
+
'ui-event': ConnectorUiEvent;
|
|
664
|
+
}
|
|
665
|
+
interface IConnector {
|
|
666
|
+
/** Physical connection type this connector uses. Fixed at construction. */
|
|
667
|
+
readonly connectionType: ConnectionType;
|
|
668
|
+
searchDevices(): Promise<ConnectorDevice[]>;
|
|
669
|
+
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
670
|
+
disconnect(sessionId: string): Promise<void>;
|
|
671
|
+
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
672
|
+
cancel(sessionId: string): Promise<void>;
|
|
673
|
+
/** Send a UI response (e.g. PIN, passphrase) to the device. */
|
|
674
|
+
uiResponse(response: UiResponseEvent): void;
|
|
675
|
+
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
676
|
+
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
677
|
+
reset(): void;
|
|
678
|
+
}
|
|
679
|
+
interface IHardwareBridge {
|
|
680
|
+
searchDevices(params: {
|
|
681
|
+
vendor: VendorType;
|
|
682
|
+
}): Promise<ConnectorDevice[]>;
|
|
683
|
+
connect(params: {
|
|
684
|
+
vendor: VendorType;
|
|
685
|
+
deviceId?: string;
|
|
686
|
+
}): Promise<ConnectorSession>;
|
|
687
|
+
disconnect(params: {
|
|
688
|
+
vendor: VendorType;
|
|
689
|
+
sessionId: string;
|
|
690
|
+
}): Promise<void>;
|
|
691
|
+
call(params: {
|
|
692
|
+
vendor: VendorType;
|
|
693
|
+
sessionId: string;
|
|
694
|
+
method: string;
|
|
695
|
+
callParams: unknown;
|
|
696
|
+
}): Promise<unknown>;
|
|
697
|
+
cancel(params: {
|
|
698
|
+
vendor: VendorType;
|
|
699
|
+
sessionId: string;
|
|
700
|
+
}): Promise<void>;
|
|
701
|
+
uiResponse(params: {
|
|
702
|
+
vendor: VendorType;
|
|
703
|
+
response: UiResponseEvent;
|
|
704
|
+
}): void;
|
|
705
|
+
reset(params: {
|
|
706
|
+
vendor: VendorType;
|
|
707
|
+
}): void;
|
|
708
|
+
/** Register an event handler for connector events forwarded across the bridge. */
|
|
709
|
+
onEvent(params: {
|
|
710
|
+
vendor: VendorType;
|
|
711
|
+
}, handler: (event: {
|
|
712
|
+
type: ConnectorEventType;
|
|
713
|
+
data: unknown;
|
|
714
|
+
}) => void): void;
|
|
715
|
+
/** Unregister a previously registered event handler. */
|
|
716
|
+
offEvent(params: {
|
|
717
|
+
vendor: VendorType;
|
|
718
|
+
}, handler: (event: {
|
|
719
|
+
type: ConnectorEventType;
|
|
720
|
+
data: unknown;
|
|
721
|
+
}) => void): void;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
|
|
725
|
+
* Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
|
|
726
|
+
* Events are forwarded via bridge.onEvent / offEvent.
|
|
727
|
+
*
|
|
728
|
+
* Use this anywhere the actual hardware lives behind a process / context boundary
|
|
729
|
+
* (Electron main, extension background, native module, worker, iframe).
|
|
730
|
+
*/
|
|
731
|
+
declare function createBridgedConnector(vendor: VendorType, connectionType: ConnectionType, bridge: IHardwareBridge): IConnector;
|
|
732
|
+
|
|
558
733
|
type ChainCapability = 'evm' | 'btc' | 'sol' | 'tron';
|
|
559
734
|
interface PassphraseResponse {
|
|
560
735
|
passphrase: string;
|
|
@@ -607,7 +782,11 @@ type UiRequestEvent = {
|
|
|
607
782
|
};
|
|
608
783
|
} | {
|
|
609
784
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
610
|
-
payload:
|
|
785
|
+
payload: {
|
|
786
|
+
transportType: TransportType;
|
|
787
|
+
connectId?: string;
|
|
788
|
+
deviceId?: string;
|
|
789
|
+
};
|
|
611
790
|
} | {
|
|
612
791
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
613
792
|
payload: {
|
|
@@ -617,8 +796,6 @@ type UiRequestEvent = {
|
|
|
617
796
|
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
618
797
|
payload: {
|
|
619
798
|
message: string;
|
|
620
|
-
retryCount: number;
|
|
621
|
-
maxRetries: number;
|
|
622
799
|
};
|
|
623
800
|
} | {
|
|
624
801
|
type: typeof UI_REQUEST.REQUEST_PREEMPTION;
|
|
@@ -656,7 +833,7 @@ type SdkEvent = {
|
|
|
656
833
|
connectId: string;
|
|
657
834
|
};
|
|
658
835
|
};
|
|
659
|
-
type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent;
|
|
836
|
+
type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent | ConnectorUiEvent;
|
|
660
837
|
type DeviceEventListener = (event: HardwareEvent) => void;
|
|
661
838
|
/**
|
|
662
839
|
* Type-safe event map for IHardwareWallet.on / .off.
|
|
@@ -665,6 +842,7 @@ type DeviceEventListener = (event: HardwareEvent) => void;
|
|
|
665
842
|
* and the value is the narrowed event object the listener will receive.
|
|
666
843
|
*/
|
|
667
844
|
interface HardwareEventMap {
|
|
845
|
+
'ui-event': ConnectorUiEvent;
|
|
668
846
|
[DEVICE.CONNECT]: {
|
|
669
847
|
type: typeof DEVICE.CONNECT;
|
|
670
848
|
payload: DeviceInfo;
|
|
@@ -719,7 +897,11 @@ interface HardwareEventMap {
|
|
|
719
897
|
};
|
|
720
898
|
[UI_REQUEST.REQUEST_DEVICE_PERMISSION]: {
|
|
721
899
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
722
|
-
payload:
|
|
900
|
+
payload: {
|
|
901
|
+
transportType: TransportType;
|
|
902
|
+
connectId?: string;
|
|
903
|
+
deviceId?: string;
|
|
904
|
+
};
|
|
723
905
|
};
|
|
724
906
|
[UI_REQUEST.REQUEST_SELECT_DEVICE]: {
|
|
725
907
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
@@ -731,8 +913,6 @@ interface HardwareEventMap {
|
|
|
731
913
|
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
732
914
|
payload: {
|
|
733
915
|
message: string;
|
|
734
|
-
retryCount: number;
|
|
735
|
-
maxRetries: number;
|
|
736
916
|
};
|
|
737
917
|
};
|
|
738
918
|
[UI_REQUEST.REQUEST_PREEMPTION]: {
|
|
@@ -776,47 +956,6 @@ interface HardwareEventMap {
|
|
|
776
956
|
};
|
|
777
957
|
};
|
|
778
958
|
}
|
|
779
|
-
/**
|
|
780
|
-
* Same-process callbacks for prompts and OS-level permission.
|
|
781
|
-
* Cross-process flows use events + `uiResponse` + `UiRequestRegistry` instead.
|
|
782
|
-
*/
|
|
783
|
-
interface IUiHandler {
|
|
784
|
-
onPinRequest(device: DeviceInfo): Promise<string>;
|
|
785
|
-
onPassphraseRequest(device: DeviceInfo): Promise<string | PassphraseResponse>;
|
|
786
|
-
onQrDisplay(device: DeviceInfo, data: QrDisplayData): Promise<QrResponseData>;
|
|
787
|
-
/**
|
|
788
|
-
* Check if device access permission is already granted.
|
|
789
|
-
* Returns { granted, context? }.
|
|
790
|
-
* - granted: true → skip onDevicePermission
|
|
791
|
-
* - granted: false → adapter calls onDevicePermission with the context
|
|
792
|
-
* - context: consumer-defined data passed through to onDevicePermission
|
|
793
|
-
*
|
|
794
|
-
* When connectId/deviceId are undefined (searchDevices), check environment-level
|
|
795
|
-
* permissions (USB: any paired device exists; BLE: bluetooth on + location permission).
|
|
796
|
-
* When connectId/deviceId are provided (business methods), check device-level
|
|
797
|
-
* permissions (USB: target device authorized; BLE: bluetooth on + device connected).
|
|
798
|
-
*/
|
|
799
|
-
checkDevicePermission?(params: {
|
|
800
|
-
transportType: TransportType;
|
|
801
|
-
connectId?: string;
|
|
802
|
-
deviceId?: string;
|
|
803
|
-
}): Promise<{
|
|
804
|
-
granted: boolean;
|
|
805
|
-
context?: Record<string, unknown>;
|
|
806
|
-
}>;
|
|
807
|
-
/**
|
|
808
|
-
* Request device access permission from the user.
|
|
809
|
-
* Only called when checkDevicePermission returns granted: false (or is not set).
|
|
810
|
-
*
|
|
811
|
-
* The handler decides what to do based on transportType + context:
|
|
812
|
-
* - usb/hid: open pairing page or call requestWebUSBDevice
|
|
813
|
-
* - ble: enable bluetooth, request location permission, start scanning
|
|
814
|
-
*/
|
|
815
|
-
onDevicePermission(params: {
|
|
816
|
-
transportType: TransportType;
|
|
817
|
-
context?: Record<string, unknown>;
|
|
818
|
-
}): Promise<void>;
|
|
819
|
-
}
|
|
820
959
|
interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, ISolMethods, ITronMethods {
|
|
821
960
|
readonly vendor: string;
|
|
822
961
|
readonly activeTransport: TransportType | null;
|
|
@@ -829,7 +968,8 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
829
968
|
disconnectDevice(connectId: string): Promise<void>;
|
|
830
969
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
831
970
|
getSupportedChains(): ChainCapability[];
|
|
832
|
-
|
|
971
|
+
/** Abort the in-flight call. Omit connectId to cancel whatever is active. */
|
|
972
|
+
cancel(connectId?: string): void;
|
|
833
973
|
/** Respond to any pending `ui-request-*`. */
|
|
834
974
|
uiResponse(response: UiResponseEvent): void;
|
|
835
975
|
/**
|
|
@@ -842,7 +982,6 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
842
982
|
* especially for vendors with ephemeral connectId/deviceId.
|
|
843
983
|
*/
|
|
844
984
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
845
|
-
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
846
985
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
847
986
|
on(event: string, listener: DeviceEventListener): void;
|
|
848
987
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -877,137 +1016,6 @@ interface DeviceDisconnectEvent {
|
|
|
877
1016
|
}
|
|
878
1017
|
type DeviceChangeEvent = DeviceConnectEvent | DeviceDisconnectEvent;
|
|
879
1018
|
|
|
880
|
-
/**
|
|
881
|
-
* Minimal device info returned during discovery (searchDevices).
|
|
882
|
-
* At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
|
|
883
|
-
*/
|
|
884
|
-
interface ConnectorDevice {
|
|
885
|
-
connectId: string;
|
|
886
|
-
deviceId: string;
|
|
887
|
-
name: string;
|
|
888
|
-
model?: string;
|
|
889
|
-
/** Device capabilities — available from scan time */
|
|
890
|
-
capabilities?: DeviceCapabilities;
|
|
891
|
-
}
|
|
892
|
-
interface ConnectorSession {
|
|
893
|
-
sessionId: string;
|
|
894
|
-
deviceInfo: DeviceInfo;
|
|
895
|
-
}
|
|
896
|
-
type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
|
|
897
|
-
/**
|
|
898
|
-
* Interaction event types emitted via 'ui-event'.
|
|
899
|
-
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
900
|
-
*/
|
|
901
|
-
declare enum EConnectorInteraction {
|
|
902
|
-
/** Device requires user to open a specific app */
|
|
903
|
-
ConfirmOpenApp = "confirm-open-app",
|
|
904
|
-
/** Device requires user to unlock */
|
|
905
|
-
UnlockDevice = "unlock-device",
|
|
906
|
-
/** Device needs user to confirm on device (sign, verify, etc.) */
|
|
907
|
-
ConfirmOnDevice = "confirm-on-device",
|
|
908
|
-
/** Previous interaction completed — clear UI prompt */
|
|
909
|
-
InteractionComplete = "interaction-complete"
|
|
910
|
-
}
|
|
911
|
-
type ConnectorUiEvent = {
|
|
912
|
-
type: EConnectorInteraction.ConfirmOpenApp;
|
|
913
|
-
payload: {
|
|
914
|
-
sessionId: string;
|
|
915
|
-
};
|
|
916
|
-
} | {
|
|
917
|
-
type: EConnectorInteraction.UnlockDevice;
|
|
918
|
-
payload: {
|
|
919
|
-
sessionId: string;
|
|
920
|
-
};
|
|
921
|
-
} | {
|
|
922
|
-
type: EConnectorInteraction.ConfirmOnDevice;
|
|
923
|
-
payload: {
|
|
924
|
-
sessionId: string;
|
|
925
|
-
};
|
|
926
|
-
} | {
|
|
927
|
-
type: EConnectorInteraction.InteractionComplete;
|
|
928
|
-
payload: {
|
|
929
|
-
sessionId: string;
|
|
930
|
-
};
|
|
931
|
-
};
|
|
932
|
-
interface ConnectorEventMap {
|
|
933
|
-
'device-connect': {
|
|
934
|
-
device: ConnectorDevice;
|
|
935
|
-
};
|
|
936
|
-
'device-disconnect': {
|
|
937
|
-
connectId: string;
|
|
938
|
-
};
|
|
939
|
-
'ui-request': {
|
|
940
|
-
type: string;
|
|
941
|
-
payload?: unknown;
|
|
942
|
-
};
|
|
943
|
-
'ui-event': ConnectorUiEvent;
|
|
944
|
-
}
|
|
945
|
-
interface IConnector {
|
|
946
|
-
searchDevices(): Promise<ConnectorDevice[]>;
|
|
947
|
-
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
948
|
-
disconnect(sessionId: string): Promise<void>;
|
|
949
|
-
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
950
|
-
cancel(sessionId: string): Promise<void>;
|
|
951
|
-
/** Send a UI response (e.g. PIN, passphrase) to the device. */
|
|
952
|
-
uiResponse(response: UiResponseEvent): void;
|
|
953
|
-
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
954
|
-
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
955
|
-
reset(): void;
|
|
956
|
-
}
|
|
957
|
-
interface IHardwareBridge {
|
|
958
|
-
searchDevices(params: {
|
|
959
|
-
vendor: VendorType;
|
|
960
|
-
}): Promise<ConnectorDevice[]>;
|
|
961
|
-
connect(params: {
|
|
962
|
-
vendor: VendorType;
|
|
963
|
-
deviceId?: string;
|
|
964
|
-
}): Promise<ConnectorSession>;
|
|
965
|
-
disconnect(params: {
|
|
966
|
-
vendor: VendorType;
|
|
967
|
-
sessionId: string;
|
|
968
|
-
}): Promise<void>;
|
|
969
|
-
call(params: {
|
|
970
|
-
vendor: VendorType;
|
|
971
|
-
sessionId: string;
|
|
972
|
-
method: string;
|
|
973
|
-
callParams: unknown;
|
|
974
|
-
}): Promise<unknown>;
|
|
975
|
-
cancel(params: {
|
|
976
|
-
vendor: VendorType;
|
|
977
|
-
sessionId: string;
|
|
978
|
-
}): Promise<void>;
|
|
979
|
-
uiResponse(params: {
|
|
980
|
-
vendor: VendorType;
|
|
981
|
-
response: UiResponseEvent;
|
|
982
|
-
}): void;
|
|
983
|
-
reset(params: {
|
|
984
|
-
vendor: VendorType;
|
|
985
|
-
}): void;
|
|
986
|
-
/** Register an event handler for connector events forwarded across the bridge. */
|
|
987
|
-
onEvent(params: {
|
|
988
|
-
vendor: VendorType;
|
|
989
|
-
}, handler: (event: {
|
|
990
|
-
type: ConnectorEventType;
|
|
991
|
-
data: unknown;
|
|
992
|
-
}) => void): void;
|
|
993
|
-
/** Unregister a previously registered event handler. */
|
|
994
|
-
offEvent(params: {
|
|
995
|
-
vendor: VendorType;
|
|
996
|
-
}, handler: (event: {
|
|
997
|
-
type: ConnectorEventType;
|
|
998
|
-
data: unknown;
|
|
999
|
-
}) => void): void;
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
|
|
1003
|
-
* Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
|
|
1004
|
-
* Events are forwarded via bridge.onEvent / offEvent.
|
|
1005
|
-
*
|
|
1006
|
-
* Use this anywhere the actual hardware lives behind a process / context boundary
|
|
1007
|
-
* (Electron main, extension background, native module, worker, iframe).
|
|
1008
|
-
*/
|
|
1009
|
-
declare function createBridgedConnector(vendor: VendorType, bridge: IHardwareBridge): IConnector;
|
|
1010
|
-
|
|
1011
1019
|
/**
|
|
1012
1020
|
* Minimal typed event emitter using Map<string, Set<listener>>.
|
|
1013
1021
|
* Each adapter uses this for device events (connect, disconnect, pin, etc.).
|
|
@@ -1044,7 +1052,10 @@ declare function ensure0x(hex: string): string;
|
|
|
1044
1052
|
declare function stripHex(hex: string): string;
|
|
1045
1053
|
/** Pad hex to 64 chars (32 bytes) with 0x prefix */
|
|
1046
1054
|
declare function padHex64(hex: string): string;
|
|
1047
|
-
/**
|
|
1055
|
+
/**
|
|
1056
|
+
* Convert a hex string (with or without 0x prefix) to a Uint8Array.
|
|
1057
|
+
* Throws on invalid hex (non-hex characters, odd length).
|
|
1058
|
+
*/
|
|
1048
1059
|
declare function hexToBytes(hex: string): Uint8Array;
|
|
1049
1060
|
/** Convert a Uint8Array to a hex string (no 0x prefix). */
|
|
1050
1061
|
declare function bytesToHex(bytes: Uint8Array): string;
|
|
@@ -1064,4 +1075,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
|
|
|
1064
1075
|
total: number;
|
|
1065
1076
|
}) => void): Promise<Response<TResult[]>>;
|
|
1066
1077
|
|
|
1067
|
-
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
|
|
1078
|
+
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 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 };
|