@onekeyfe/hwk-adapter-core 1.1.26-alpha.105 → 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 -252
- package/dist/index.d.ts +255 -252
- package/dist/index.js +114 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -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
|
}
|
|
@@ -371,13 +410,6 @@ interface QrResponseData {
|
|
|
371
410
|
urData: string;
|
|
372
411
|
}
|
|
373
412
|
|
|
374
|
-
/**
|
|
375
|
-
* Chain fingerprint utilities for device identity verification.
|
|
376
|
-
*
|
|
377
|
-
* Ledger devices have ephemeral IDs that change every session.
|
|
378
|
-
* To verify that the same seed/device is connected, we derive an address
|
|
379
|
-
* at a fixed path (account 0, index 0) and hash it into a stable "chain fingerprint".
|
|
380
|
-
*/
|
|
381
413
|
/**
|
|
382
414
|
* Fixed derivation paths used to generate chain fingerprints.
|
|
383
415
|
* Uses standard index 0 — Ledger firmware shows device confirmation for
|
|
@@ -390,13 +422,19 @@ interface QrResponseData {
|
|
|
390
422
|
declare const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string>;
|
|
391
423
|
type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';
|
|
392
424
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
* pulling in a SHA-256 dependency. This is NOT used for security —
|
|
397
|
-
* only for device identity matching.
|
|
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.
|
|
398
428
|
*/
|
|
399
|
-
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
|
+
};
|
|
400
438
|
|
|
401
439
|
/** 10 min — every UI request is human-in-the-loop; bias toward "wait long". */
|
|
402
440
|
declare const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600000;
|
|
@@ -416,7 +454,7 @@ declare class UiRequestRegistry {
|
|
|
416
454
|
resolve(responseType: string, payload: unknown): void;
|
|
417
455
|
cancel(requestType?: string): void;
|
|
418
456
|
reset(): void;
|
|
419
|
-
hasPending(requestType
|
|
457
|
+
hasPending(requestType?: string): boolean;
|
|
420
458
|
}
|
|
421
459
|
|
|
422
460
|
/**
|
|
@@ -457,6 +495,8 @@ declare class DeviceJobQueue {
|
|
|
457
495
|
private readonly _queues;
|
|
458
496
|
private readonly _active;
|
|
459
497
|
private readonly _deps;
|
|
498
|
+
/** Incremented on clear() so stale queued jobs can detect invalidation. */
|
|
499
|
+
private _generation;
|
|
460
500
|
constructor(deps?: DeviceJobQueueDeps);
|
|
461
501
|
/**
|
|
462
502
|
* Enqueue a job for a specific device.
|
|
@@ -468,8 +508,8 @@ declare class DeviceJobQueue {
|
|
|
468
508
|
enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
|
|
469
509
|
/** Manually cancel the active job on a device. Returns false if job is non-interruptible. */
|
|
470
510
|
cancelActive(deviceId: string): boolean;
|
|
471
|
-
/** Force cancel regardless of interruptibility.
|
|
472
|
-
forceCancelActive(deviceId: string): boolean;
|
|
511
|
+
/** Force cancel regardless of interruptibility. `reason` becomes signal.reason. */
|
|
512
|
+
forceCancelActive(deviceId: string, reason?: Error): boolean;
|
|
473
513
|
/** Get info about the currently active job for a device, or null if idle. */
|
|
474
514
|
getActiveJob(deviceId: string): ActiveJobInfo | null;
|
|
475
515
|
clear(): void;
|
|
@@ -504,6 +544,7 @@ declare const UI_RESPONSE: {
|
|
|
504
544
|
readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
|
|
505
545
|
readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
|
|
506
546
|
readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
|
|
547
|
+
readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
|
|
507
548
|
readonly RECEIVE_PREEMPTION: "receive-preemption";
|
|
508
549
|
readonly CANCEL: "cancel";
|
|
509
550
|
};
|
|
@@ -533,6 +574,11 @@ type UiResponseEvent = {
|
|
|
533
574
|
payload: {
|
|
534
575
|
confirmed: boolean;
|
|
535
576
|
};
|
|
577
|
+
} | {
|
|
578
|
+
type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
|
|
579
|
+
payload: {
|
|
580
|
+
granted: boolean;
|
|
581
|
+
};
|
|
536
582
|
} | {
|
|
537
583
|
type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;
|
|
538
584
|
payload: {
|
|
@@ -543,18 +589,6 @@ type UiResponseEvent = {
|
|
|
543
589
|
payload?: undefined;
|
|
544
590
|
};
|
|
545
591
|
|
|
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
|
-
|
|
558
592
|
/** Events generated by SDK internal detection (not from hardware directly). */
|
|
559
593
|
declare const SDK: {
|
|
560
594
|
readonly DEVICE_STUCK: "device-stuck";
|
|
@@ -563,6 +597,139 @@ declare const SDK: {
|
|
|
563
597
|
readonly DEVICE_INTERACTION: "device-interaction";
|
|
564
598
|
};
|
|
565
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
|
+
|
|
566
733
|
type ChainCapability = 'evm' | 'btc' | 'sol' | 'tron';
|
|
567
734
|
interface PassphraseResponse {
|
|
568
735
|
passphrase: string;
|
|
@@ -615,7 +782,11 @@ type UiRequestEvent = {
|
|
|
615
782
|
};
|
|
616
783
|
} | {
|
|
617
784
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
618
|
-
payload:
|
|
785
|
+
payload: {
|
|
786
|
+
transportType: TransportType;
|
|
787
|
+
connectId?: string;
|
|
788
|
+
deviceId?: string;
|
|
789
|
+
};
|
|
619
790
|
} | {
|
|
620
791
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
621
792
|
payload: {
|
|
@@ -625,8 +796,6 @@ type UiRequestEvent = {
|
|
|
625
796
|
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
626
797
|
payload: {
|
|
627
798
|
message: string;
|
|
628
|
-
retryCount: number;
|
|
629
|
-
maxRetries: number;
|
|
630
799
|
};
|
|
631
800
|
} | {
|
|
632
801
|
type: typeof UI_REQUEST.REQUEST_PREEMPTION;
|
|
@@ -664,7 +833,7 @@ type SdkEvent = {
|
|
|
664
833
|
connectId: string;
|
|
665
834
|
};
|
|
666
835
|
};
|
|
667
|
-
type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent;
|
|
836
|
+
type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent | ConnectorUiEvent;
|
|
668
837
|
type DeviceEventListener = (event: HardwareEvent) => void;
|
|
669
838
|
/**
|
|
670
839
|
* Type-safe event map for IHardwareWallet.on / .off.
|
|
@@ -673,6 +842,7 @@ type DeviceEventListener = (event: HardwareEvent) => void;
|
|
|
673
842
|
* and the value is the narrowed event object the listener will receive.
|
|
674
843
|
*/
|
|
675
844
|
interface HardwareEventMap {
|
|
845
|
+
'ui-event': ConnectorUiEvent;
|
|
676
846
|
[DEVICE.CONNECT]: {
|
|
677
847
|
type: typeof DEVICE.CONNECT;
|
|
678
848
|
payload: DeviceInfo;
|
|
@@ -727,7 +897,11 @@ interface HardwareEventMap {
|
|
|
727
897
|
};
|
|
728
898
|
[UI_REQUEST.REQUEST_DEVICE_PERMISSION]: {
|
|
729
899
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
730
|
-
payload:
|
|
900
|
+
payload: {
|
|
901
|
+
transportType: TransportType;
|
|
902
|
+
connectId?: string;
|
|
903
|
+
deviceId?: string;
|
|
904
|
+
};
|
|
731
905
|
};
|
|
732
906
|
[UI_REQUEST.REQUEST_SELECT_DEVICE]: {
|
|
733
907
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
@@ -739,8 +913,6 @@ interface HardwareEventMap {
|
|
|
739
913
|
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
740
914
|
payload: {
|
|
741
915
|
message: string;
|
|
742
|
-
retryCount: number;
|
|
743
|
-
maxRetries: number;
|
|
744
916
|
};
|
|
745
917
|
};
|
|
746
918
|
[UI_REQUEST.REQUEST_PREEMPTION]: {
|
|
@@ -784,47 +956,6 @@ interface HardwareEventMap {
|
|
|
784
956
|
};
|
|
785
957
|
};
|
|
786
958
|
}
|
|
787
|
-
/**
|
|
788
|
-
* Same-process callbacks for prompts and OS-level permission.
|
|
789
|
-
* Cross-process flows use events + `uiResponse` + `UiRequestRegistry` instead.
|
|
790
|
-
*/
|
|
791
|
-
interface IUiHandler {
|
|
792
|
-
onPinRequest(device: DeviceInfo): Promise<string>;
|
|
793
|
-
onPassphraseRequest(device: DeviceInfo): Promise<string | PassphraseResponse>;
|
|
794
|
-
onQrDisplay(device: DeviceInfo, data: QrDisplayData): Promise<QrResponseData>;
|
|
795
|
-
/**
|
|
796
|
-
* Check if device access permission is already granted.
|
|
797
|
-
* Returns { granted, context? }.
|
|
798
|
-
* - granted: true → skip onDevicePermission
|
|
799
|
-
* - granted: false → adapter calls onDevicePermission with the context
|
|
800
|
-
* - context: consumer-defined data passed through to onDevicePermission
|
|
801
|
-
*
|
|
802
|
-
* When connectId/deviceId are undefined (searchDevices), check environment-level
|
|
803
|
-
* permissions (USB: any paired device exists; BLE: bluetooth on + location permission).
|
|
804
|
-
* When connectId/deviceId are provided (business methods), check device-level
|
|
805
|
-
* permissions (USB: target device authorized; BLE: bluetooth on + device connected).
|
|
806
|
-
*/
|
|
807
|
-
checkDevicePermission?(params: {
|
|
808
|
-
transportType: TransportType;
|
|
809
|
-
connectId?: string;
|
|
810
|
-
deviceId?: string;
|
|
811
|
-
}): Promise<{
|
|
812
|
-
granted: boolean;
|
|
813
|
-
context?: Record<string, unknown>;
|
|
814
|
-
}>;
|
|
815
|
-
/**
|
|
816
|
-
* Request device access permission from the user.
|
|
817
|
-
* Only called when checkDevicePermission returns granted: false (or is not set).
|
|
818
|
-
*
|
|
819
|
-
* The handler decides what to do based on transportType + context:
|
|
820
|
-
* - usb/hid: open pairing page or call requestWebUSBDevice
|
|
821
|
-
* - ble: enable bluetooth, request location permission, start scanning
|
|
822
|
-
*/
|
|
823
|
-
onDevicePermission(params: {
|
|
824
|
-
transportType: TransportType;
|
|
825
|
-
context?: Record<string, unknown>;
|
|
826
|
-
}): Promise<void>;
|
|
827
|
-
}
|
|
828
959
|
interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, ISolMethods, ITronMethods {
|
|
829
960
|
readonly vendor: string;
|
|
830
961
|
readonly activeTransport: TransportType | null;
|
|
@@ -837,7 +968,8 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
837
968
|
disconnectDevice(connectId: string): Promise<void>;
|
|
838
969
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
839
970
|
getSupportedChains(): ChainCapability[];
|
|
840
|
-
|
|
971
|
+
/** Abort the in-flight call. Omit connectId to cancel whatever is active. */
|
|
972
|
+
cancel(connectId?: string): void;
|
|
841
973
|
/** Respond to any pending `ui-request-*`. */
|
|
842
974
|
uiResponse(response: UiResponseEvent): void;
|
|
843
975
|
/**
|
|
@@ -850,7 +982,6 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
850
982
|
* especially for vendors with ephemeral connectId/deviceId.
|
|
851
983
|
*/
|
|
852
984
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
853
|
-
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
854
985
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
855
986
|
on(event: string, listener: DeviceEventListener): void;
|
|
856
987
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -885,137 +1016,6 @@ interface DeviceDisconnectEvent {
|
|
|
885
1016
|
}
|
|
886
1017
|
type DeviceChangeEvent = DeviceConnectEvent | DeviceDisconnectEvent;
|
|
887
1018
|
|
|
888
|
-
/**
|
|
889
|
-
* Minimal device info returned during discovery (searchDevices).
|
|
890
|
-
* At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
|
|
891
|
-
*/
|
|
892
|
-
interface ConnectorDevice {
|
|
893
|
-
connectId: string;
|
|
894
|
-
deviceId: string;
|
|
895
|
-
name: string;
|
|
896
|
-
model?: string;
|
|
897
|
-
/** Device capabilities — available from scan time */
|
|
898
|
-
capabilities?: DeviceCapabilities;
|
|
899
|
-
}
|
|
900
|
-
interface ConnectorSession {
|
|
901
|
-
sessionId: string;
|
|
902
|
-
deviceInfo: DeviceInfo;
|
|
903
|
-
}
|
|
904
|
-
type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
|
|
905
|
-
/**
|
|
906
|
-
* Interaction event types emitted via 'ui-event'.
|
|
907
|
-
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
908
|
-
*/
|
|
909
|
-
declare enum EConnectorInteraction {
|
|
910
|
-
/** Device requires user to open a specific app */
|
|
911
|
-
ConfirmOpenApp = "confirm-open-app",
|
|
912
|
-
/** Device requires user to unlock */
|
|
913
|
-
UnlockDevice = "unlock-device",
|
|
914
|
-
/** Device needs user to confirm on device (sign, verify, etc.) */
|
|
915
|
-
ConfirmOnDevice = "confirm-on-device",
|
|
916
|
-
/** Previous interaction completed — clear UI prompt */
|
|
917
|
-
InteractionComplete = "interaction-complete"
|
|
918
|
-
}
|
|
919
|
-
type ConnectorUiEvent = {
|
|
920
|
-
type: EConnectorInteraction.ConfirmOpenApp;
|
|
921
|
-
payload: {
|
|
922
|
-
sessionId: string;
|
|
923
|
-
};
|
|
924
|
-
} | {
|
|
925
|
-
type: EConnectorInteraction.UnlockDevice;
|
|
926
|
-
payload: {
|
|
927
|
-
sessionId: string;
|
|
928
|
-
};
|
|
929
|
-
} | {
|
|
930
|
-
type: EConnectorInteraction.ConfirmOnDevice;
|
|
931
|
-
payload: {
|
|
932
|
-
sessionId: string;
|
|
933
|
-
};
|
|
934
|
-
} | {
|
|
935
|
-
type: EConnectorInteraction.InteractionComplete;
|
|
936
|
-
payload: {
|
|
937
|
-
sessionId: string;
|
|
938
|
-
};
|
|
939
|
-
};
|
|
940
|
-
interface ConnectorEventMap {
|
|
941
|
-
'device-connect': {
|
|
942
|
-
device: ConnectorDevice;
|
|
943
|
-
};
|
|
944
|
-
'device-disconnect': {
|
|
945
|
-
connectId: string;
|
|
946
|
-
};
|
|
947
|
-
'ui-request': {
|
|
948
|
-
type: string;
|
|
949
|
-
payload?: unknown;
|
|
950
|
-
};
|
|
951
|
-
'ui-event': ConnectorUiEvent;
|
|
952
|
-
}
|
|
953
|
-
interface IConnector {
|
|
954
|
-
searchDevices(): Promise<ConnectorDevice[]>;
|
|
955
|
-
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
956
|
-
disconnect(sessionId: string): Promise<void>;
|
|
957
|
-
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
958
|
-
cancel(sessionId: string): Promise<void>;
|
|
959
|
-
/** Send a UI response (e.g. PIN, passphrase) to the device. */
|
|
960
|
-
uiResponse(response: UiResponseEvent): void;
|
|
961
|
-
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
962
|
-
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
963
|
-
reset(): void;
|
|
964
|
-
}
|
|
965
|
-
interface IHardwareBridge {
|
|
966
|
-
searchDevices(params: {
|
|
967
|
-
vendor: VendorType;
|
|
968
|
-
}): Promise<ConnectorDevice[]>;
|
|
969
|
-
connect(params: {
|
|
970
|
-
vendor: VendorType;
|
|
971
|
-
deviceId?: string;
|
|
972
|
-
}): Promise<ConnectorSession>;
|
|
973
|
-
disconnect(params: {
|
|
974
|
-
vendor: VendorType;
|
|
975
|
-
sessionId: string;
|
|
976
|
-
}): Promise<void>;
|
|
977
|
-
call(params: {
|
|
978
|
-
vendor: VendorType;
|
|
979
|
-
sessionId: string;
|
|
980
|
-
method: string;
|
|
981
|
-
callParams: unknown;
|
|
982
|
-
}): Promise<unknown>;
|
|
983
|
-
cancel(params: {
|
|
984
|
-
vendor: VendorType;
|
|
985
|
-
sessionId: string;
|
|
986
|
-
}): Promise<void>;
|
|
987
|
-
uiResponse(params: {
|
|
988
|
-
vendor: VendorType;
|
|
989
|
-
response: UiResponseEvent;
|
|
990
|
-
}): void;
|
|
991
|
-
reset(params: {
|
|
992
|
-
vendor: VendorType;
|
|
993
|
-
}): void;
|
|
994
|
-
/** Register an event handler for connector events forwarded across the bridge. */
|
|
995
|
-
onEvent(params: {
|
|
996
|
-
vendor: VendorType;
|
|
997
|
-
}, handler: (event: {
|
|
998
|
-
type: ConnectorEventType;
|
|
999
|
-
data: unknown;
|
|
1000
|
-
}) => void): void;
|
|
1001
|
-
/** Unregister a previously registered event handler. */
|
|
1002
|
-
offEvent(params: {
|
|
1003
|
-
vendor: VendorType;
|
|
1004
|
-
}, handler: (event: {
|
|
1005
|
-
type: ConnectorEventType;
|
|
1006
|
-
data: unknown;
|
|
1007
|
-
}) => void): void;
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
|
|
1011
|
-
* Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
|
|
1012
|
-
* Events are forwarded via bridge.onEvent / offEvent.
|
|
1013
|
-
*
|
|
1014
|
-
* Use this anywhere the actual hardware lives behind a process / context boundary
|
|
1015
|
-
* (Electron main, extension background, native module, worker, iframe).
|
|
1016
|
-
*/
|
|
1017
|
-
declare function createBridgedConnector(vendor: VendorType, bridge: IHardwareBridge): IConnector;
|
|
1018
|
-
|
|
1019
1019
|
/**
|
|
1020
1020
|
* Minimal typed event emitter using Map<string, Set<listener>>.
|
|
1021
1021
|
* Each adapter uses this for device events (connect, disconnect, pin, etc.).
|
|
@@ -1052,7 +1052,10 @@ declare function ensure0x(hex: string): string;
|
|
|
1052
1052
|
declare function stripHex(hex: string): string;
|
|
1053
1053
|
/** Pad hex to 64 chars (32 bytes) with 0x prefix */
|
|
1054
1054
|
declare function padHex64(hex: string): string;
|
|
1055
|
-
/**
|
|
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
|
+
*/
|
|
1056
1059
|
declare function hexToBytes(hex: string): Uint8Array;
|
|
1057
1060
|
/** Convert a Uint8Array to a hex string (no 0x prefix). */
|
|
1058
1061
|
declare function bytesToHex(bytes: Uint8Array): string;
|
|
@@ -1072,4 +1075,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
|
|
|
1072
1075
|
total: number;
|
|
1073
1076
|
}) => void): Promise<Response<TResult[]>>;
|
|
1074
1077
|
|
|
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
|
|
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 };
|