@onekeyfe/hwk-ledger-adapter 1.1.26-alpha.7 → 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 +29 -11
- package/dist/index.d.ts +29 -11
- package/dist/index.js +193 -156
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -157
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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
|
|
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
|
|
544
|
-
*
|
|
545
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
544
|
-
*
|
|
545
|
-
*
|
|
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
|
-
*
|
|
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;
|