@onekeyfe/hwk-adapter-core 1.1.27-alpha.4 → 1.1.27-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -169,95 +169,321 @@ interface DeviceTarget {
169
169
  deviceId: string;
170
170
  }
171
171
 
172
- interface EvmGetAddressParams {
173
- path: string;
174
- showOnDevice?: boolean;
175
- chainId?: number;
172
+ interface QrDisplayData {
173
+ urType: string;
174
+ urData: string;
175
+ animated: boolean;
176
176
  }
177
- interface EvmAddress {
178
- address: string;
179
- path: string;
180
- /** Device-reported secp256k1 public key; populated when the transport exposes it. */
181
- publicKey?: string;
177
+ interface QrResponseData {
178
+ urType: string;
179
+ urData: string;
182
180
  }
183
- interface EvmSignTxParams {
184
- path: string;
181
+
182
+ declare const UI_EVENT = "UI_EVENT";
183
+ declare const UI_REQUEST: {
184
+ readonly REQUEST_PIN: "ui-request-pin";
185
+ readonly REQUEST_PASSPHRASE: "ui-request-passphrase";
186
+ readonly REQUEST_PASSPHRASE_ON_DEVICE: "ui-request-passphrase-on-device";
187
+ readonly REQUEST_BUTTON: "ui-request-button";
188
+ readonly REQUEST_QR_DISPLAY: "ui-request-qr-display";
189
+ readonly REQUEST_QR_SCAN: "ui-request-qr-scan";
190
+ readonly REQUEST_DEVICE_PERMISSION: "ui-request-device-permission";
191
+ readonly REQUEST_SELECT_DEVICE: "ui-request-select-device";
192
+ readonly REQUEST_DEVICE_CONNECT: "ui-request-device-connect";
193
+ readonly REQUEST_BTC_HIGH_INDEX_CONFIRM: "ui-request-btc-high-index-confirm";
194
+ readonly REQUEST_INSTALL_APP: "ui-request-install-app";
195
+ readonly CLOSE_UI_WINDOW: "ui-close";
196
+ readonly DEVICE_PROGRESS: "ui-device_progress";
197
+ readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
198
+ readonly FIRMWARE_TIP: "ui-firmware-tip";
199
+ };
200
+ declare const UI_RESPONSE: {
201
+ readonly RECEIVE_PIN: "receive-pin";
202
+ readonly RECEIVE_PASSPHRASE: "receive-passphrase";
203
+ readonly RECEIVE_PASSPHRASE_ON_DEVICE: "receive-passphrase-on-device";
204
+ readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
205
+ readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
206
+ readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
207
+ readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
208
+ readonly RECEIVE_BTC_HIGH_INDEX_CONFIRM: "receive-btc-high-index-confirm";
209
+ readonly RECEIVE_INSTALL_APP: "receive-install-app";
210
+ readonly CANCEL: "cancel";
211
+ };
212
+ type DevicePermissionDeniedReason = 'bluetoothTurnedOff' | 'permissionDenied' | (string & Record<never, never>);
213
+ type DevicePermissionResponse = {
214
+ granted: boolean;
215
+ reason?: DevicePermissionDeniedReason;
216
+ message?: string;
217
+ };
218
+ type UiResponseEvent = {
219
+ type: typeof UI_RESPONSE.RECEIVE_PIN;
220
+ payload: string;
221
+ } | {
222
+ type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;
223
+ payload: {
224
+ value: string;
225
+ passphraseOnDevice?: boolean;
226
+ save?: boolean;
227
+ };
228
+ } | {
229
+ type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE_ON_DEVICE;
230
+ payload?: undefined;
231
+ } | {
232
+ type: typeof UI_RESPONSE.RECEIVE_QR_RESPONSE;
233
+ payload: QrResponseData;
234
+ } | {
235
+ type: typeof UI_RESPONSE.RECEIVE_SELECT_DEVICE;
236
+ payload: {
237
+ sdkConnectId: string;
238
+ };
239
+ } | {
240
+ type: typeof UI_RESPONSE.RECEIVE_DEVICE_CONNECT;
241
+ payload: {
242
+ confirmed: boolean;
243
+ };
244
+ } | {
245
+ type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
246
+ payload: DevicePermissionResponse;
247
+ } | {
248
+ type: typeof UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM;
249
+ payload: {
250
+ confirmed: boolean;
251
+ };
252
+ } | {
253
+ type: typeof UI_RESPONSE.RECEIVE_INSTALL_APP;
254
+ payload: {
255
+ confirmed: boolean;
256
+ };
257
+ } | {
258
+ type: typeof UI_RESPONSE.CANCEL;
259
+ payload?: undefined;
260
+ };
261
+
262
+ /**
263
+ * Minimal device info returned during discovery (searchDevices).
264
+ * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
265
+ */
266
+ interface ConnectorDevice {
267
+ connectId: string;
268
+ deviceId: string;
269
+ name: string;
270
+ /** Machine model id (e.g. "nanoX"). */
271
+ model?: string;
272
+ /** Human-readable model name (e.g. "Ledger Nano X"). */
273
+ modelName?: string;
274
+ /** BLE signal strength (BLE only). */
275
+ rssi?: number | null;
276
+ /** BLE connectable flag (BLE only). */
277
+ isConnectable?: boolean | null;
278
+ /** USB serial number (USB only). */
279
+ serialNumber?: string;
280
+ /** Device capabilities — available from scan time */
281
+ capabilities?: DeviceCapabilities;
282
+ }
283
+ interface ConnectorSession {
284
+ sessionId: string;
285
+ deviceInfo: DeviceInfo;
286
+ }
287
+ /**
288
+ * Vendor-agnostic bag of extra error fields. Known keys are documented for
289
+ * discoverability; the index signature keeps it open so any connector can
290
+ * carry vendor-specific data without losing it across the bridge.
291
+ */
292
+ interface ConnectorErrorParams {
293
+ /** Vendor SDK error tag (e.g. Ledger DMK `_tag`). */
294
+ _tag?: string;
295
+ /** App involved, e.g. the Ledger app being opened/installed. */
296
+ appName?: string;
297
+ /** Transport / APDU status code (string or number depending on vendor). */
298
+ statusCode?: unknown;
185
299
  /**
186
- * RLP-serialized transaction hex (0x-prefixed or plain).
187
- * When provided, the connector uses this directly instead of individual fields.
188
- * Required for Ledger; Trezor may use individual fields instead.
300
+ * Shallow snapshot of a nested cause. A raw Error does not survive JSON
301
+ * serialization (its `message`/`stack` are non-enumerable), so recovery
302
+ * predicates that recurse into a cause get this plain-object copy instead.
189
303
  */
190
- serializedTx?: string;
191
- /** Contract address or recipient. Optional for contract deployment transactions. */
192
- to?: string;
193
- value?: string;
194
- chainId?: number;
195
- nonce?: string;
196
- gasLimit?: string;
197
- gasPrice?: string;
198
- maxFeePerGas?: string;
199
- maxPriorityFeePerGas?: string;
200
- accessList?: Array<{
201
- address: string;
202
- storageKeys: string[];
203
- }>;
204
- data?: string;
205
- }
206
- interface EvmSignedTx {
207
- /** Recovery id as `0x`-prefixed hex string. */
208
- v: string;
209
- /** ECDSA `r` value as `0x`-prefixed, zero-padded 64-char hex string (32 bytes). */
210
- r: string;
211
- /** ECDSA `s` value as `0x`-prefixed, zero-padded 64-char hex string (32 bytes). */
212
- s: string;
213
- serializedTx?: string;
304
+ originalError?: {
305
+ message?: string;
306
+ code?: number;
307
+ errorCode?: string;
308
+ statusCode?: unknown;
309
+ _tag?: string;
310
+ };
311
+ [key: string]: unknown;
214
312
  }
215
- interface EvmSignMsgParams {
216
- path: string;
313
+ interface ConnectorSerializedError {
217
314
  message: string;
218
- hex?: boolean;
219
- }
220
- type EvmSignTypedDataParams = EvmSignTypedDataFull | EvmSignTypedDataHash;
221
- interface EvmSignTypedDataFull {
222
- path: string;
223
- /** Defaults to `'full'` when omitted. */
224
- mode?: 'full';
225
- data: {
226
- domain: EIP712Domain;
227
- types: Record<string, Array<{
228
- name: string;
229
- type: string;
230
- }>>;
231
- primaryType: string;
232
- message: Record<string, unknown>;
233
- };
234
- metamaskV4Compat?: boolean;
315
+ code?: number;
316
+ errorCode?: string;
317
+ params?: ConnectorErrorParams;
235
318
  }
236
- interface EvmSignTypedDataHash {
237
- path: string;
238
- mode: 'hash';
239
- domainSeparatorHash: string;
240
- messageHash: string;
319
+ type ConnectorCallResult = {
320
+ success: true;
321
+ payload: unknown;
322
+ } | {
323
+ success: false;
324
+ error: ConnectorSerializedError;
325
+ };
326
+ type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
327
+ /**
328
+ * Interaction event types emitted via 'ui-event'.
329
+ * These map to user-facing prompts (confirm on device, open app, etc.).
330
+ */
331
+ declare enum EConnectorInteraction {
332
+ /** Adapter is actively searching for the device (no session yet) */
333
+ Searching = "searching",
334
+ /** Device requires user to open a specific app */
335
+ ConfirmOpenApp = "confirm-open-app",
336
+ /** Device requires user to unlock */
337
+ UnlockDevice = "unlock-device",
338
+ /** Device needs user to confirm on device (sign, verify, etc.) */
339
+ ConfirmOnDevice = "confirm-on-device",
340
+ /** Previous interaction completed — clear UI prompt */
341
+ InteractionComplete = "interaction-complete",
342
+ /**
343
+ * OS-level Ledger app install progress. `progress` is a 0..1 fraction
344
+ * reported by DMK's InstallOrUpdateAppsDeviceAction. Emitted from inside
345
+ * the connector so the progress callback ref never has to cross the
346
+ * IHardwareBridge boundary.
347
+ */
348
+ AppInstallProgress = "app-install-progress"
241
349
  }
242
- interface EIP712Domain {
243
- name?: string;
244
- version?: string;
245
- chainId?: number;
246
- verifyingContract?: string;
247
- salt?: string;
248
- [key: string]: unknown;
350
+ type ConnectorUiEvent = {
351
+ type: EConnectorInteraction.Searching;
352
+ payload: {
353
+ sessionId: string;
354
+ };
355
+ } | {
356
+ type: EConnectorInteraction.ConfirmOpenApp;
357
+ payload: {
358
+ sessionId: string;
359
+ };
360
+ } | {
361
+ type: EConnectorInteraction.UnlockDevice;
362
+ payload: {
363
+ sessionId: string;
364
+ };
365
+ } | {
366
+ type: EConnectorInteraction.ConfirmOnDevice;
367
+ payload: {
368
+ sessionId: string;
369
+ };
370
+ } | {
371
+ type: EConnectorInteraction.InteractionComplete;
372
+ payload: {
373
+ sessionId: string;
374
+ };
375
+ } | {
376
+ type: EConnectorInteraction.AppInstallProgress;
377
+ payload: {
378
+ sessionId: string;
379
+ appName: string;
380
+ progress: number;
381
+ };
382
+ };
383
+ interface ConnectorEventMap {
384
+ 'device-connect': {
385
+ device: ConnectorDevice;
386
+ };
387
+ 'device-disconnect': {
388
+ connectId: string;
389
+ };
390
+ 'ui-request': {
391
+ type: string;
392
+ payload?: unknown;
393
+ };
394
+ 'ui-event': ConnectorUiEvent;
249
395
  }
250
- interface EvmSignature {
251
- /** `0x`-prefixed hex string (r + s + v). */
252
- signature: string;
253
- address?: string;
396
+ interface IConnector {
397
+ /** Physical connection type this connector uses. Fixed at construction. */
398
+ readonly connectionType: ConnectionType;
399
+ searchDevices(): Promise<ConnectorDevice[]>;
400
+ connect(deviceId?: string): Promise<ConnectorSession>;
401
+ disconnect(sessionId: string): Promise<void>;
402
+ call(sessionId: string, method: string, params: unknown): Promise<ConnectorCallResult>;
403
+ cancel(sessionId: string): Promise<void>;
404
+ /** Send a UI response (e.g. PIN, passphrase) to the device. */
405
+ uiResponse(response: UiResponseEvent): void;
406
+ on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
407
+ off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
408
+ reset(): void;
254
409
  }
255
- interface IEvmMethods {
256
- evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
257
- evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
258
- evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
259
- evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
410
+ interface IHardwareBridge {
411
+ searchDevices(params: {
412
+ vendor: VendorType;
413
+ }): Promise<ConnectorDevice[]>;
414
+ connect(params: {
415
+ vendor: VendorType;
416
+ deviceId?: string;
417
+ }): Promise<ConnectorSession>;
418
+ disconnect(params: {
419
+ vendor: VendorType;
420
+ sessionId: string;
421
+ }): Promise<void>;
422
+ call(params: {
423
+ vendor: VendorType;
424
+ sessionId: string;
425
+ method: string;
426
+ callParams: unknown;
427
+ }): Promise<ConnectorCallResult>;
428
+ cancel(params: {
429
+ vendor: VendorType;
430
+ sessionId: string;
431
+ }): Promise<void>;
432
+ uiResponse(params: {
433
+ vendor: VendorType;
434
+ response: UiResponseEvent;
435
+ }): void;
436
+ reset(params: {
437
+ vendor: VendorType;
438
+ }): void;
439
+ /** Register an event handler for connector events forwarded across the bridge. */
440
+ onEvent(params: {
441
+ vendor: VendorType;
442
+ }, handler: (event: {
443
+ type: ConnectorEventType;
444
+ data: unknown;
445
+ }) => void): void;
446
+ /** Unregister a previously registered event handler. */
447
+ offEvent(params: {
448
+ vendor: VendorType;
449
+ }, handler: (event: {
450
+ type: ConnectorEventType;
451
+ data: unknown;
452
+ }) => void): void;
260
453
  }
454
+ /**
455
+ * Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
456
+ * Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
457
+ * Events are forwarded via bridge.onEvent / offEvent.
458
+ *
459
+ * Use this anywhere the actual hardware lives behind a process / context boundary
460
+ * (Electron main, extension background, native module, worker, iframe).
461
+ */
462
+ declare function createBridgedConnector(vendor: VendorType, connectionType: ConnectionType, bridge: IHardwareBridge): IConnector;
463
+ /**
464
+ * Flatten a thrown error into the cross-boundary-safe `ConnectorSerializedError`
465
+ * shape. `message`/`code`/`errorCode` are lifted to the top level; every other
466
+ * own-enumerable field is copied into `params` so NO domain data is lost when
467
+ * the result crosses a host bridge (which may run thrown errors through a
468
+ * field whitelist). A nested `originalError` is shallow-snapshotted because a
469
+ * raw Error does not survive JSON serialization.
470
+ */
471
+ declare function serializeConnectorError(err: unknown): ConnectorSerializedError;
472
+ /**
473
+ * Inverse of `serializeConnectorError`: rebuild a flat Error instance, lifting
474
+ * `params.*` back to own-properties so existing throw-based classifiers/recovery
475
+ * logic (which read `err._tag` / `err.code` / `err.appName` / …) keep working
476
+ * unchanged. The Result shape stays confined to the connector boundary.
477
+ */
478
+ declare function rehydrateConnectorError(error: ConnectorSerializedError): Error;
479
+
480
+ declare const DEVICE_EVENT = "DEVICE_EVENT";
481
+ /** Events originating from the hardware device. */
482
+ declare const DEVICE: {
483
+ readonly CONNECT: "device-connect";
484
+ readonly DISCONNECT: "device-disconnect";
485
+ readonly CHANGED: "device-changed";
486
+ };
261
487
 
262
488
  interface BtcGetAddressParams {
263
489
  path: string;
@@ -351,12 +577,12 @@ interface BtcSignature {
351
577
  address?: string;
352
578
  }
353
579
  interface IBtcMethods {
354
- btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams): Promise<Response<BtcAddress>>;
355
- btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
356
- btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
357
- btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams): Promise<Response<BtcSignedPsbt>>;
358
- btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams): Promise<Response<BtcSignature>>;
359
- btcGetMasterFingerprint(connectId: string, deviceId: string): Promise<Response<{
580
+ btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<BtcAddress>>;
581
+ btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams, commonParams?: ICommonCallParams): Promise<Response<BtcPublicKey>>;
582
+ btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams, commonParams?: ICommonCallParams): Promise<Response<BtcSignedTx>>;
583
+ btcSignPsbt(connectId: string, deviceId: string, params: BtcSignPsbtParams, commonParams?: ICommonCallParams): Promise<Response<BtcSignedPsbt>>;
584
+ btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<BtcSignature>>;
585
+ btcGetMasterFingerprint(connectId: string, deviceId: string, commonParams?: ICommonCallParams): Promise<Response<{
360
586
  masterFingerprint: string;
361
587
  }>>;
362
588
  }
@@ -397,9 +623,9 @@ interface SolSignature {
397
623
  signature: string;
398
624
  }
399
625
  interface ISolMethods {
400
- solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
401
- solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
402
- solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
626
+ solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<SolAddress>>;
627
+ solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams, commonParams?: ICommonCallParams): Promise<Response<SolSignedTx>>;
628
+ solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<SolSignature>>;
403
629
  }
404
630
 
405
631
  interface TronGetAddressParams {
@@ -430,19 +656,9 @@ interface TronSignature {
430
656
  signature: string;
431
657
  }
432
658
  interface ITronMethods {
433
- tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
434
- tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams): Promise<Response<TronSignedTx>>;
435
- tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams): Promise<Response<TronSignature>>;
436
- }
437
-
438
- interface QrDisplayData {
439
- urType: string;
440
- urData: string;
441
- animated: boolean;
442
- }
443
- interface QrResponseData {
444
- urType: string;
445
- urData: string;
659
+ tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<TronAddress>>;
660
+ tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams, commonParams?: ICommonCallParams): Promise<Response<TronSignedTx>>;
661
+ tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<TronSignature>>;
446
662
  }
447
663
 
448
664
  /**
@@ -454,95 +670,14 @@ interface QrResponseData {
454
670
  * - BTC: cointype 1 (testnet)
455
671
  * - SOL: cointype 501, standard 3-level hardened
456
672
  */
457
- declare const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string>;
458
- type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';
459
- /**
460
- * 16-char SHA-256 fingerprint for device-identity verification.
461
- * Callers must canonicalize input (e.g. EVM address → lowercase) —
462
- * encoding variations otherwise cause false DeviceMismatch.
463
- */
464
- declare function deriveDeviceFingerprint(value: string): string;
465
-
466
- declare const DEVICE_EVENT = "DEVICE_EVENT";
467
- /** Events originating from the hardware device. */
468
- declare const DEVICE: {
469
- readonly CONNECT: "device-connect";
470
- readonly DISCONNECT: "device-disconnect";
471
- readonly CHANGED: "device-changed";
472
- };
473
-
474
- declare const UI_EVENT = "UI_EVENT";
475
- declare const UI_REQUEST: {
476
- readonly REQUEST_PIN: "ui-request-pin";
477
- readonly REQUEST_PASSPHRASE: "ui-request-passphrase";
478
- readonly REQUEST_PASSPHRASE_ON_DEVICE: "ui-request-passphrase-on-device";
479
- readonly REQUEST_BUTTON: "ui-request-button";
480
- readonly REQUEST_QR_DISPLAY: "ui-request-qr-display";
481
- readonly REQUEST_QR_SCAN: "ui-request-qr-scan";
482
- readonly REQUEST_DEVICE_PERMISSION: "ui-request-device-permission";
483
- readonly REQUEST_SELECT_DEVICE: "ui-request-select-device";
484
- readonly REQUEST_DEVICE_CONNECT: "ui-request-device-connect";
485
- readonly REQUEST_BTC_HIGH_INDEX_CONFIRM: "ui-request-btc-high-index-confirm";
486
- readonly CLOSE_UI_WINDOW: "ui-close";
487
- readonly DEVICE_PROGRESS: "ui-device_progress";
488
- readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
489
- readonly FIRMWARE_TIP: "ui-firmware-tip";
490
- };
491
- declare const UI_RESPONSE: {
492
- readonly RECEIVE_PIN: "receive-pin";
493
- readonly RECEIVE_PASSPHRASE: "receive-passphrase";
494
- readonly RECEIVE_PASSPHRASE_ON_DEVICE: "receive-passphrase-on-device";
495
- readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
496
- readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
497
- readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
498
- readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
499
- readonly RECEIVE_BTC_HIGH_INDEX_CONFIRM: "receive-btc-high-index-confirm";
500
- readonly CANCEL: "cancel";
501
- };
502
- type DevicePermissionDeniedReason = 'bluetoothTurnedOff' | 'permissionDenied' | (string & Record<never, never>);
503
- type DevicePermissionResponse = {
504
- granted: boolean;
505
- reason?: DevicePermissionDeniedReason;
506
- message?: string;
507
- };
508
- type UiResponseEvent = {
509
- type: typeof UI_RESPONSE.RECEIVE_PIN;
510
- payload: string;
511
- } | {
512
- type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;
513
- payload: {
514
- value: string;
515
- passphraseOnDevice?: boolean;
516
- save?: boolean;
517
- };
518
- } | {
519
- type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE_ON_DEVICE;
520
- payload?: undefined;
521
- } | {
522
- type: typeof UI_RESPONSE.RECEIVE_QR_RESPONSE;
523
- payload: QrResponseData;
524
- } | {
525
- type: typeof UI_RESPONSE.RECEIVE_SELECT_DEVICE;
526
- payload: {
527
- sdkConnectId: string;
528
- };
529
- } | {
530
- type: typeof UI_RESPONSE.RECEIVE_DEVICE_CONNECT;
531
- payload: {
532
- confirmed: boolean;
533
- };
534
- } | {
535
- type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
536
- payload: DevicePermissionResponse;
537
- } | {
538
- type: typeof UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM;
539
- payload: {
540
- confirmed: boolean;
541
- };
542
- } | {
543
- type: typeof UI_RESPONSE.CANCEL;
544
- payload?: undefined;
545
- };
673
+ declare const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string>;
674
+ type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';
675
+ /**
676
+ * 16-char SHA-256 fingerprint for device-identity verification.
677
+ * Callers must canonicalize input (e.g. EVM address → lowercase) —
678
+ * encoding variations otherwise cause false DeviceMismatch.
679
+ */
680
+ declare function deriveDeviceFingerprint(value: string): string;
546
681
 
547
682
  /** Events generated by SDK internal detection (not from hardware directly). */
548
683
  declare const SDK: {
@@ -553,160 +688,35 @@ declare const SDK: {
553
688
  };
554
689
 
555
690
  /**
556
- * Minimal device info returned during discovery (searchDevices).
557
- * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
558
- */
559
- interface ConnectorDevice {
560
- connectId: string;
561
- deviceId: string;
562
- name: string;
563
- /** Machine model id (e.g. "nanoX"). */
564
- model?: string;
565
- /** Human-readable model name (e.g. "Ledger Nano X"). */
566
- modelName?: string;
567
- /** BLE signal strength (BLE only). */
568
- rssi?: number | null;
569
- /** BLE connectable flag (BLE only). */
570
- isConnectable?: boolean | null;
571
- /** USB serial number (USB only). */
572
- serialNumber?: string;
573
- /** Device capabilities — available from scan time */
574
- capabilities?: DeviceCapabilities;
575
- }
576
- interface ConnectorSession {
577
- sessionId: string;
578
- deviceInfo: DeviceInfo;
579
- }
580
- type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event' | 'app-install-progress';
581
- /**
582
- * Interaction event types emitted via 'ui-event'.
583
- * These map to user-facing prompts (confirm on device, open app, etc.).
691
+ * Wallet-level `ui-event` variants. Same shape as `ConnectorUiEvent` except
692
+ * the AppInstallProgress variant's payload is re-keyed by the adapter from
693
+ * connector-internal `sessionId` to the public `connectId`.
584
694
  */
585
- declare enum EConnectorInteraction {
586
- /** Adapter is actively searching for the device (no session yet) */
587
- Searching = "searching",
588
- /** Device requires user to open a specific app */
589
- ConfirmOpenApp = "confirm-open-app",
590
- /** Device requires user to unlock */
591
- UnlockDevice = "unlock-device",
592
- /** Device needs user to confirm on device (sign, verify, etc.) */
593
- ConfirmOnDevice = "confirm-on-device",
594
- /** Previous interaction completed — clear UI prompt */
595
- InteractionComplete = "interaction-complete"
596
- }
597
- type ConnectorUiEvent = {
598
- type: EConnectorInteraction.Searching;
599
- payload: {
600
- sessionId: string;
601
- };
602
- } | {
603
- type: EConnectorInteraction.ConfirmOpenApp;
604
- payload: {
605
- sessionId: string;
606
- };
607
- } | {
608
- type: EConnectorInteraction.UnlockDevice;
609
- payload: {
610
- sessionId: string;
611
- };
612
- } | {
613
- type: EConnectorInteraction.ConfirmOnDevice;
614
- payload: {
615
- sessionId: string;
616
- };
617
- } | {
618
- type: EConnectorInteraction.InteractionComplete;
695
+ type HardwareUiEvent = Exclude<ConnectorUiEvent, {
696
+ type: EConnectorInteraction.AppInstallProgress;
697
+ }> | {
698
+ type: EConnectorInteraction.AppInstallProgress;
619
699
  payload: {
620
- sessionId: string;
621
- };
622
- };
623
- interface ConnectorEventMap {
624
- 'device-connect': {
625
- device: ConnectorDevice;
626
- };
627
- 'device-disconnect': {
628
700
  connectId: string;
629
- };
630
- 'ui-request': {
631
- type: string;
632
- payload?: unknown;
633
- };
634
- 'ui-event': ConnectorUiEvent;
635
- 'app-install-progress': {
636
- sessionId: string;
637
701
  appName: string;
638
702
  progress: number;
639
703
  };
640
- }
641
- interface IConnector {
642
- /** Physical connection type this connector uses. Fixed at construction. */
643
- readonly connectionType: ConnectionType;
644
- searchDevices(): Promise<ConnectorDevice[]>;
645
- connect(deviceId?: string): Promise<ConnectorSession>;
646
- disconnect(sessionId: string): Promise<void>;
647
- call(sessionId: string, method: string, params: unknown): Promise<unknown>;
648
- cancel(sessionId: string): Promise<void>;
649
- /** Send a UI response (e.g. PIN, passphrase) to the device. */
650
- uiResponse(response: UiResponseEvent): void;
651
- on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
652
- off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
653
- reset(): void;
654
- }
655
- interface IHardwareBridge {
656
- searchDevices(params: {
657
- vendor: VendorType;
658
- }): Promise<ConnectorDevice[]>;
659
- connect(params: {
660
- vendor: VendorType;
661
- deviceId?: string;
662
- }): Promise<ConnectorSession>;
663
- disconnect(params: {
664
- vendor: VendorType;
665
- sessionId: string;
666
- }): Promise<void>;
667
- call(params: {
668
- vendor: VendorType;
669
- sessionId: string;
670
- method: string;
671
- callParams: unknown;
672
- }): Promise<unknown>;
673
- cancel(params: {
674
- vendor: VendorType;
675
- sessionId: string;
676
- }): Promise<void>;
677
- uiResponse(params: {
678
- vendor: VendorType;
679
- response: UiResponseEvent;
680
- }): void;
681
- reset(params: {
682
- vendor: VendorType;
683
- }): void;
684
- /** Register an event handler for connector events forwarded across the bridge. */
685
- onEvent(params: {
686
- vendor: VendorType;
687
- }, handler: (event: {
688
- type: ConnectorEventType;
689
- data: unknown;
690
- }) => void): void;
691
- /** Unregister a previously registered event handler. */
692
- offEvent(params: {
693
- vendor: VendorType;
694
- }, handler: (event: {
695
- type: ConnectorEventType;
696
- data: unknown;
697
- }) => void): void;
698
- }
704
+ };
705
+ type ChainCapability = 'evm' | 'btc' | 'sol' | 'tron';
699
706
  /**
700
- * Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
701
- * Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
702
- * Events are forwarded via bridge.onEvent / offEvent.
703
- *
704
- * Use this anywhere the actual hardware lives behind a process / context boundary
705
- * (Electron main, extension background, native module, worker, iframe).
707
+ * Cross-chain / cross-vendor options passed alongside any chain method's
708
+ * own params (the optional last argument). Holds operation-level switches
709
+ * that aren't specific to one chain. Vendor-specific options can be added
710
+ * as typed sub-fields here when a vendor actually needs them.
706
711
  */
707
- declare function createBridgedConnector(vendor: VendorType, connectionType: ConnectionType, bridge: IHardwareBridge): IConnector;
708
-
709
- type ChainCapability = 'evm' | 'btc' | 'sol' | 'tron';
712
+ interface ICommonCallParams {
713
+ /**
714
+ * When the required device app is missing, prompt the user (UI request)
715
+ * to install it, stream install progress, then retry the operation once.
716
+ * Off by default — preserves the plain "app not installed" failure.
717
+ */
718
+ autoInstallApp?: boolean;
719
+ }
710
720
  interface PassphraseResponse {
711
721
  passphrase: string;
712
722
  /** If true, passphrase will be entered on the device. `passphrase` field is ignored. */
@@ -788,6 +798,12 @@ type UiRequestEvent = {
788
798
  */
789
799
  message: string;
790
800
  };
801
+ } | {
802
+ type: typeof UI_REQUEST.REQUEST_INSTALL_APP;
803
+ payload: {
804
+ vendor: string;
805
+ appName: string;
806
+ };
791
807
  } | {
792
808
  type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
793
809
  payload: Record<string, never>;
@@ -814,7 +830,7 @@ type SdkEvent = {
814
830
  connectId: string;
815
831
  };
816
832
  };
817
- type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent | ConnectorUiEvent;
833
+ type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent | HardwareUiEvent;
818
834
  type DeviceEventListener = (event: HardwareEvent) => void;
819
835
  /**
820
836
  * Type-safe event map for IHardwareWallet.on / .off.
@@ -823,15 +839,7 @@ type DeviceEventListener = (event: HardwareEvent) => void;
823
839
  * and the value is the narrowed event object the listener will receive.
824
840
  */
825
841
  interface HardwareEventMap {
826
- 'ui-event': ConnectorUiEvent;
827
- 'app-install-progress': {
828
- type: 'app-install-progress';
829
- payload: {
830
- connectId: string;
831
- appName: string;
832
- progress: number;
833
- };
834
- };
842
+ 'ui-event': HardwareUiEvent;
835
843
  [DEVICE.CONNECT]: {
836
844
  type: typeof DEVICE.CONNECT;
837
845
  payload: DeviceInfo;
@@ -914,6 +922,13 @@ interface HardwareEventMap {
914
922
  accountIndex: number;
915
923
  };
916
924
  };
925
+ [UI_REQUEST.REQUEST_INSTALL_APP]: {
926
+ type: typeof UI_REQUEST.REQUEST_INSTALL_APP;
927
+ payload: {
928
+ vendor: string;
929
+ appName: string;
930
+ };
931
+ };
917
932
  [UI_REQUEST.CLOSE_UI_WINDOW]: {
918
933
  type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
919
934
  payload: Record<string, never>;
@@ -986,6 +1001,96 @@ interface SearchDevicesOptions {
986
1001
  resetSession?: boolean;
987
1002
  }
988
1003
 
1004
+ interface EvmGetAddressParams {
1005
+ path: string;
1006
+ showOnDevice?: boolean;
1007
+ chainId?: number;
1008
+ }
1009
+ interface EvmAddress {
1010
+ address: string;
1011
+ path: string;
1012
+ /** Device-reported secp256k1 public key; populated when the transport exposes it. */
1013
+ publicKey?: string;
1014
+ }
1015
+ interface EvmSignTxParams {
1016
+ path: string;
1017
+ /**
1018
+ * RLP-serialized transaction hex (0x-prefixed or plain).
1019
+ * When provided, the connector uses this directly instead of individual fields.
1020
+ * Required for Ledger; Trezor may use individual fields instead.
1021
+ */
1022
+ serializedTx?: string;
1023
+ /** Contract address or recipient. Optional for contract deployment transactions. */
1024
+ to?: string;
1025
+ value?: string;
1026
+ chainId?: number;
1027
+ nonce?: string;
1028
+ gasLimit?: string;
1029
+ gasPrice?: string;
1030
+ maxFeePerGas?: string;
1031
+ maxPriorityFeePerGas?: string;
1032
+ accessList?: Array<{
1033
+ address: string;
1034
+ storageKeys: string[];
1035
+ }>;
1036
+ data?: string;
1037
+ }
1038
+ interface EvmSignedTx {
1039
+ /** Recovery id as `0x`-prefixed hex string. */
1040
+ v: string;
1041
+ /** ECDSA `r` value as `0x`-prefixed, zero-padded 64-char hex string (32 bytes). */
1042
+ r: string;
1043
+ /** ECDSA `s` value as `0x`-prefixed, zero-padded 64-char hex string (32 bytes). */
1044
+ s: string;
1045
+ serializedTx?: string;
1046
+ }
1047
+ interface EvmSignMsgParams {
1048
+ path: string;
1049
+ message: string;
1050
+ hex?: boolean;
1051
+ }
1052
+ type EvmSignTypedDataParams = EvmSignTypedDataFull | EvmSignTypedDataHash;
1053
+ interface EvmSignTypedDataFull {
1054
+ path: string;
1055
+ /** Defaults to `'full'` when omitted. */
1056
+ mode?: 'full';
1057
+ data: {
1058
+ domain: EIP712Domain;
1059
+ types: Record<string, Array<{
1060
+ name: string;
1061
+ type: string;
1062
+ }>>;
1063
+ primaryType: string;
1064
+ message: Record<string, unknown>;
1065
+ };
1066
+ metamaskV4Compat?: boolean;
1067
+ }
1068
+ interface EvmSignTypedDataHash {
1069
+ path: string;
1070
+ mode: 'hash';
1071
+ domainSeparatorHash: string;
1072
+ messageHash: string;
1073
+ }
1074
+ interface EIP712Domain {
1075
+ name?: string;
1076
+ version?: string;
1077
+ chainId?: number;
1078
+ verifyingContract?: string;
1079
+ salt?: string;
1080
+ [key: string]: unknown;
1081
+ }
1082
+ interface EvmSignature {
1083
+ /** `0x`-prefixed hex string (r + s + v). */
1084
+ signature: string;
1085
+ address?: string;
1086
+ }
1087
+ interface IEvmMethods {
1088
+ evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams, commonParams?: ICommonCallParams): Promise<Response<EvmAddress>>;
1089
+ evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams, commonParams?: ICommonCallParams): Promise<Response<EvmSignedTx>>;
1090
+ evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams, commonParams?: ICommonCallParams): Promise<Response<EvmSignature>>;
1091
+ evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams, commonParams?: ICommonCallParams): Promise<Response<EvmSignature>>;
1092
+ }
1093
+
989
1094
  /**
990
1095
  * Low-level device descriptor from Transport layer.
991
1096
  * Represents a physical device detected by USB/BLE scanning.
@@ -1162,4 +1267,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
1162
1267
  total: number;
1163
1268
  }) => void): Promise<Response<TResult[]>>;
1164
1269
 
1165
- 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 };
1270
+ 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 ConnectorCallResult, type ConnectorDevice, type ConnectorErrorParams, type ConnectorEventMap, type ConnectorEventType, type ConnectorSerializedError, 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 HardwareUiEvent, type IBtcMethods, type ICommonCallParams, 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, rehydrateConnectorError, serializeConnectorError, stripHex, success };