@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.8 → 1.1.26-alpha.9

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
@@ -166,14 +166,10 @@ declare class LedgerAdapter implements IHardwareWallet {
166
166
  private errorToFailure;
167
167
  private deviceConnectHandler;
168
168
  private deviceDisconnectHandler;
169
- private uiRequestHandler;
170
- private uiEventHandler;
169
+ private uiEventForwarder;
171
170
  private registerEventListeners;
172
171
  private unregisterEventListeners;
173
- private handleUiEvent;
174
172
  private connectorDeviceToDeviceInfo;
175
- private extractDeviceInfoFromPayload;
176
- private unknownDevice;
177
173
  }
178
174
 
179
175
  /**
@@ -276,6 +272,12 @@ declare class LedgerConnectorBase implements IConnector {
276
272
  private _resetSignersAndSessions;
277
273
  private _resetAll;
278
274
  protected _emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
275
+ /**
276
+ * Return a per-call ctx with the chain's Ledger app name pre-bound to
277
+ * wrapError, so chain handlers don't need to repeat `{ defaultAppName: 'X' }`
278
+ * at every catch site. Falls through unchanged for unknown methods.
279
+ */
280
+ private _ctxForMethod;
279
281
  private _wrapError;
280
282
  }
281
283
 
@@ -540,9 +542,16 @@ declare class AppManager {
540
542
  * 5. Poll until the device confirms the target app is running.
541
543
  */
542
544
  /**
543
- * @param onConfirmOnDevice Called after OpenAppCommand succeeds
544
- * the device is now showing a confirmation prompt to the user.
545
- * NOT called if the app is already open or if the app is not installed.
545
+ * @param onConfirmOnDevice Called BEFORE OpenAppCommand is issued the
546
+ * device is about to display "Open <app>" on screen and wait for the
547
+ * user's button press. UI consumers should show their "open app" prompt
548
+ * in response. NOT called when the target app is already open (no user
549
+ * interaction needed in that case).
550
+ *
551
+ * Important: OpenAppCommand is blocking. It does not resolve until the user
552
+ * has physically confirmed on the device, so anything that runs AFTER
553
+ * `await this._openApp(...)` lands AFTER the prompt is already gone.
554
+ * Hence the callback must fire BEFORE that await.
546
555
  */
547
556
  ensureAppOpen(sessionId: string, targetAppName: string, onConfirmOnDevice?: () => void): Promise<void>;
548
557
  private _getCurrentApp;
@@ -567,6 +576,14 @@ type LedgerFailure = Omit<Failure, 'payload'> & {
567
576
  appName?: string;
568
577
  };
569
578
  };
579
+ interface WrapErrorOptions {
580
+ /**
581
+ * Fallback app name when the raw error doesn't carry `appName` itself
582
+ * (DMK signer errors don't). Used by mapLedgerError so downstream
583
+ * AppNotOpen / WrongApp / AppTooOld toasts can interpolate `{appName}`.
584
+ */
585
+ defaultAppName?: string;
586
+ }
570
587
  /**
571
588
  * Structurally compatible with `Failure`; writes `appName` only when provided,
572
589
  * so `'appName' in payload` is a reliable "has info" signal for consumers.
@@ -575,10 +592,11 @@ declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?:
575
592
  /** Check if an error (or any error in its chain) represents a locked Ledger device. */
576
593
  declare function isDeviceLockedError(err: unknown): boolean;
577
594
  /**
578
- * Map a Ledger DMK error to a HardwareErrorCode and human-readable message
579
- * with actionable recovery information for the caller.
595
+ * Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
596
+ * `opts.defaultAppName` fills `appName` when the raw error doesn't carry it
597
+ * (DMK signer errors don't).
580
598
  */
581
- declare function mapLedgerError(err: unknown): {
599
+ declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
582
600
  code: HardwareErrorCode;
583
601
  message: string;
584
602
  appName?: string;
package/dist/index.d.ts CHANGED
@@ -166,14 +166,10 @@ declare class LedgerAdapter implements IHardwareWallet {
166
166
  private errorToFailure;
167
167
  private deviceConnectHandler;
168
168
  private deviceDisconnectHandler;
169
- private uiRequestHandler;
170
- private uiEventHandler;
169
+ private uiEventForwarder;
171
170
  private registerEventListeners;
172
171
  private unregisterEventListeners;
173
- private handleUiEvent;
174
172
  private connectorDeviceToDeviceInfo;
175
- private extractDeviceInfoFromPayload;
176
- private unknownDevice;
177
173
  }
178
174
 
179
175
  /**
@@ -276,6 +272,12 @@ declare class LedgerConnectorBase implements IConnector {
276
272
  private _resetSignersAndSessions;
277
273
  private _resetAll;
278
274
  protected _emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
275
+ /**
276
+ * Return a per-call ctx with the chain's Ledger app name pre-bound to
277
+ * wrapError, so chain handlers don't need to repeat `{ defaultAppName: 'X' }`
278
+ * at every catch site. Falls through unchanged for unknown methods.
279
+ */
280
+ private _ctxForMethod;
279
281
  private _wrapError;
280
282
  }
281
283
 
@@ -540,9 +542,16 @@ declare class AppManager {
540
542
  * 5. Poll until the device confirms the target app is running.
541
543
  */
542
544
  /**
543
- * @param onConfirmOnDevice Called after OpenAppCommand succeeds
544
- * the device is now showing a confirmation prompt to the user.
545
- * NOT called if the app is already open or if the app is not installed.
545
+ * @param onConfirmOnDevice Called BEFORE OpenAppCommand is issued the
546
+ * device is about to display "Open <app>" on screen and wait for the
547
+ * user's button press. UI consumers should show their "open app" prompt
548
+ * in response. NOT called when the target app is already open (no user
549
+ * interaction needed in that case).
550
+ *
551
+ * Important: OpenAppCommand is blocking. It does not resolve until the user
552
+ * has physically confirmed on the device, so anything that runs AFTER
553
+ * `await this._openApp(...)` lands AFTER the prompt is already gone.
554
+ * Hence the callback must fire BEFORE that await.
546
555
  */
547
556
  ensureAppOpen(sessionId: string, targetAppName: string, onConfirmOnDevice?: () => void): Promise<void>;
548
557
  private _getCurrentApp;
@@ -567,6 +576,14 @@ type LedgerFailure = Omit<Failure, 'payload'> & {
567
576
  appName?: string;
568
577
  };
569
578
  };
579
+ interface WrapErrorOptions {
580
+ /**
581
+ * Fallback app name when the raw error doesn't carry `appName` itself
582
+ * (DMK signer errors don't). Used by mapLedgerError so downstream
583
+ * AppNotOpen / WrongApp / AppTooOld toasts can interpolate `{appName}`.
584
+ */
585
+ defaultAppName?: string;
586
+ }
570
587
  /**
571
588
  * Structurally compatible with `Failure`; writes `appName` only when provided,
572
589
  * so `'appName' in payload` is a reliable "has info" signal for consumers.
@@ -575,10 +592,11 @@ declare function ledgerFailure(code: HardwareErrorCode, error: string, appName?:
575
592
  /** Check if an error (or any error in its chain) represents a locked Ledger device. */
576
593
  declare function isDeviceLockedError(err: unknown): boolean;
577
594
  /**
578
- * Map a Ledger DMK error to a HardwareErrorCode and human-readable message
579
- * with actionable recovery information for the caller.
595
+ * Map a Ledger DMK error to a HardwareErrorCode and human-readable message.
596
+ * `opts.defaultAppName` fills `appName` when the raw error doesn't carry it
597
+ * (DMK signer errors don't).
580
598
  */
581
- declare function mapLedgerError(err: unknown): {
599
+ declare function mapLedgerError(err: unknown, opts?: WrapErrorOptions): {
582
600
  code: HardwareErrorCode;
583
601
  message: string;
584
602
  appName?: string;