@bytezhang/ledger-adapter 0.0.10 → 0.0.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/entries/node.d.mts +5 -0
- package/dist/entries/node.d.ts +5 -0
- package/dist/entries/react-native.d.mts +5 -0
- package/dist/entries/react-native.d.ts +5 -0
- package/dist/entries/web.d.mts +5 -0
- package/dist/entries/web.d.ts +5 -0
- package/dist/index.d.mts +539 -0
- package/dist/index.d.ts +539 -0
- package/dist/index.js +441 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +440 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { IHardwareWallet, IConnector, TransportType, IUiHandler, DeviceInfo, Response, ChainCapability, HardwareEventMap, DeviceEventListener, ChainForFingerprint, EvmGetAddressParams, EvmAddress, ProgressCallback, EvmGetPublicKeyParams, EvmPublicKey, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignMsgParams, BtcSignature, SolGetAddressParams, SolAddress, SolGetPublicKeyParams, SolPublicKey, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, ConnectionType, DeviceDescriptor, ConnectorDevice, ConnectorSession, ConnectorEventType, ConnectorEventMap, DeviceChangeEvent, HardwareErrorCode } from '@bytezhang/hardware-wallet-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ledger hardware wallet adapter that delegates to an IConnector.
|
|
5
|
+
*
|
|
6
|
+
* This is a thin translation layer that:
|
|
7
|
+
* - Accepts a pre-configured IConnector (transport decisions are made at connector creation time)
|
|
8
|
+
* - Translates IHardwareWallet method calls to connector.call() invocations
|
|
9
|
+
* - Maps connector results/errors to our Response<T> format with enriched error messages
|
|
10
|
+
* - Translates connector events to HardwareEventMap events
|
|
11
|
+
* - Integrates with IUiHandler for permission flows
|
|
12
|
+
*/
|
|
13
|
+
declare class LedgerAdapter implements IHardwareWallet {
|
|
14
|
+
readonly vendor: "ledger";
|
|
15
|
+
private readonly connector;
|
|
16
|
+
private readonly emitter;
|
|
17
|
+
private _uiHandler;
|
|
18
|
+
private _discoveredDevices;
|
|
19
|
+
private _sessions;
|
|
20
|
+
constructor(connector: IConnector);
|
|
21
|
+
get activeTransport(): TransportType | null;
|
|
22
|
+
getAvailableTransports(): TransportType[];
|
|
23
|
+
switchTransport(_type: TransportType): Promise<void>;
|
|
24
|
+
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
25
|
+
init(_config?: unknown): Promise<void>;
|
|
26
|
+
dispose(): Promise<void>;
|
|
27
|
+
searchDevices(): Promise<DeviceInfo[]>;
|
|
28
|
+
connectDevice(connectId: string): Promise<Response<string>>;
|
|
29
|
+
disconnectDevice(connectId: string): Promise<void>;
|
|
30
|
+
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
31
|
+
getSupportedChains(): ChainCapability[];
|
|
32
|
+
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
33
|
+
on(event: string, listener: DeviceEventListener): void;
|
|
34
|
+
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
35
|
+
off(event: string, listener: DeviceEventListener): void;
|
|
36
|
+
cancel(connectId: string): void;
|
|
37
|
+
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
38
|
+
/**
|
|
39
|
+
* Verify that the connected device matches the expected fingerprint.
|
|
40
|
+
*
|
|
41
|
+
* - If deviceId is empty, verification is skipped (returns true).
|
|
42
|
+
* - deviceId is used here as the stored fingerprint to compare against.
|
|
43
|
+
*/
|
|
44
|
+
private _verifyDeviceFingerprint;
|
|
45
|
+
/**
|
|
46
|
+
* Derive an address at the fixed testnet path for fingerprint generation.
|
|
47
|
+
*/
|
|
48
|
+
private _deriveAddressForFingerprint;
|
|
49
|
+
evmGetAddress(connectId: string, _deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
|
|
50
|
+
evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
|
|
51
|
+
evmGetPublicKey(connectId: string, _deviceId: string, params: EvmGetPublicKeyParams): Promise<Response<EvmPublicKey>>;
|
|
52
|
+
evmSignTransaction(connectId: string, _deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
|
|
53
|
+
evmSignMessage(connectId: string, _deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
|
|
54
|
+
evmSignTypedData(connectId: string, _deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
|
|
55
|
+
btcGetAddress(connectId: string, _deviceId: string, params: BtcGetAddressParams): Promise<Response<BtcAddress>>;
|
|
56
|
+
btcGetAddresses(connectId: string, deviceId: string, params: BtcGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<BtcAddress[]>>;
|
|
57
|
+
btcGetPublicKey(connectId: string, _deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
58
|
+
btcSignTransaction(connectId: string, _deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
59
|
+
btcSignMessage(_connectId: string, _deviceId: string, _params: BtcSignMsgParams): Promise<Response<BtcSignature>>;
|
|
60
|
+
btcGetMasterFingerprint(connectId: string, _deviceId: string): Promise<Response<{
|
|
61
|
+
masterFingerprint: string;
|
|
62
|
+
}>>;
|
|
63
|
+
solGetAddress(connectId: string, _deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
|
|
64
|
+
solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
|
|
65
|
+
solGetPublicKey(connectId: string, _deviceId: string, params: SolGetPublicKeyParams): Promise<Response<SolPublicKey>>;
|
|
66
|
+
solSignTransaction(_connectId: string, _deviceId: string, _params: SolSignTxParams): Promise<Response<SolSignedTx>>;
|
|
67
|
+
solSignMessage(_connectId: string, _deviceId: string, _params: SolSignMsgParams): Promise<Response<SolSignature>>;
|
|
68
|
+
/**
|
|
69
|
+
* Ensure at least one device is connected and return a valid connectId.
|
|
70
|
+
*
|
|
71
|
+
* - If a session already exists for the given connectId, reuse it.
|
|
72
|
+
* - If ANY session exists (Ledger IDs are ephemeral), reuse it.
|
|
73
|
+
* - Otherwise: search → 1 device: auto-connect, multiple: ask user, 0: throw.
|
|
74
|
+
*/
|
|
75
|
+
private static readonly MAX_DEVICE_RETRY;
|
|
76
|
+
private _deviceConnectResolve;
|
|
77
|
+
private _connectingPromise;
|
|
78
|
+
private static readonly DEVICE_CONNECT_TIMEOUT_MS;
|
|
79
|
+
/**
|
|
80
|
+
* Wait for user to connect and unlock device.
|
|
81
|
+
* Emits 'ui-request' event via the adapter's own emitter.
|
|
82
|
+
* The consumer (monorepo adapter wrapper) listens for this and shows UI.
|
|
83
|
+
* When user confirms, they call adapter.deviceConnectResponse() which resolves this promise.
|
|
84
|
+
* Times out after 60 seconds if no response is received.
|
|
85
|
+
*/
|
|
86
|
+
private _waitForDeviceConnect;
|
|
87
|
+
/**
|
|
88
|
+
* Called by consumer to respond to ui-request-device-connect.
|
|
89
|
+
* type='confirm' → retry search, type='cancel' → abort.
|
|
90
|
+
*/
|
|
91
|
+
deviceConnectResponse(type: 'confirm' | 'cancel'): void;
|
|
92
|
+
private ensureConnected;
|
|
93
|
+
private _doConnect;
|
|
94
|
+
private _connectFirstOrSelect;
|
|
95
|
+
/**
|
|
96
|
+
* Call the connector with automatic session resolution and disconnect retry.
|
|
97
|
+
*
|
|
98
|
+
* 1. Resolves a valid connectId via ensureConnected()
|
|
99
|
+
* 2. Looks up sessionId from _sessions
|
|
100
|
+
* 3. Calls connector.call()
|
|
101
|
+
* 4. On disconnect error: clears stale session, re-connects, retries once
|
|
102
|
+
*/
|
|
103
|
+
private connectorCall;
|
|
104
|
+
/**
|
|
105
|
+
* Ensure device permission before proceeding.
|
|
106
|
+
* - No connectId (searchDevices): check environment-level permission
|
|
107
|
+
* - With connectId (business methods): check device-level permission
|
|
108
|
+
* If not granted, calls onDevicePermission so the consumer can request access.
|
|
109
|
+
*/
|
|
110
|
+
private _ensureDevicePermission;
|
|
111
|
+
/**
|
|
112
|
+
* Convert a thrown error to a Response failure.
|
|
113
|
+
* Uses mapLedgerError to parse Ledger DMK error codes into HardwareErrorCode values.
|
|
114
|
+
*/
|
|
115
|
+
private errorToFailure;
|
|
116
|
+
/**
|
|
117
|
+
* Generic batch call with progress reporting.
|
|
118
|
+
* If any single call fails, returns the failure immediately.
|
|
119
|
+
*/
|
|
120
|
+
private batchCall;
|
|
121
|
+
private deviceConnectHandler;
|
|
122
|
+
private deviceDisconnectHandler;
|
|
123
|
+
private uiRequestHandler;
|
|
124
|
+
private uiEventHandler;
|
|
125
|
+
private registerEventListeners;
|
|
126
|
+
private unregisterEventListeners;
|
|
127
|
+
private handleUiEvent;
|
|
128
|
+
private connectorDeviceToDeviceInfo;
|
|
129
|
+
private extractDeviceInfoFromPayload;
|
|
130
|
+
private unknownDevice;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface DmkDiscoveredDevice {
|
|
134
|
+
id: string;
|
|
135
|
+
deviceModel: {
|
|
136
|
+
id: string;
|
|
137
|
+
productName: string;
|
|
138
|
+
model: string;
|
|
139
|
+
name: string;
|
|
140
|
+
};
|
|
141
|
+
transport: string;
|
|
142
|
+
[key: string]: unknown;
|
|
143
|
+
}
|
|
144
|
+
interface IDmk {
|
|
145
|
+
startDiscovering(args?: {
|
|
146
|
+
transport?: string;
|
|
147
|
+
}): {
|
|
148
|
+
subscribe(observer: {
|
|
149
|
+
next: (device: DmkDiscoveredDevice) => void;
|
|
150
|
+
error?: (err: unknown) => void;
|
|
151
|
+
}): {
|
|
152
|
+
unsubscribe: () => void;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
stopDiscovering(): void;
|
|
156
|
+
listenToAvailableDevices(args?: {
|
|
157
|
+
transport?: string;
|
|
158
|
+
}): {
|
|
159
|
+
subscribe(observer: {
|
|
160
|
+
next: (devices: DmkDiscoveredDevice[]) => void;
|
|
161
|
+
error?: (err: unknown) => void;
|
|
162
|
+
}): {
|
|
163
|
+
unsubscribe: () => void;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
connect(params: {
|
|
167
|
+
device: DmkDiscoveredDevice;
|
|
168
|
+
}): Promise<string>;
|
|
169
|
+
disconnect(params: {
|
|
170
|
+
sessionId: string;
|
|
171
|
+
}): Promise<void>;
|
|
172
|
+
sendCommand(params: {
|
|
173
|
+
sessionId: string;
|
|
174
|
+
command: unknown;
|
|
175
|
+
}): Promise<unknown>;
|
|
176
|
+
close?(): void;
|
|
177
|
+
}
|
|
178
|
+
interface DeviceActionState$1<T> {
|
|
179
|
+
status: 'pending' | 'completed' | 'error';
|
|
180
|
+
output?: T;
|
|
181
|
+
error?: unknown;
|
|
182
|
+
intermediateValue?: {
|
|
183
|
+
requiredUserInteraction?: string;
|
|
184
|
+
[key: string]: unknown;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
interface SignerEvmAddress {
|
|
188
|
+
address: string;
|
|
189
|
+
publicKey: string;
|
|
190
|
+
}
|
|
191
|
+
interface SignerEvmSignature {
|
|
192
|
+
r: string;
|
|
193
|
+
s: string;
|
|
194
|
+
v: number;
|
|
195
|
+
}
|
|
196
|
+
interface SignerBtcAddress {
|
|
197
|
+
address: string;
|
|
198
|
+
}
|
|
199
|
+
interface TransportProviderOptions {
|
|
200
|
+
logger?: unknown;
|
|
201
|
+
}
|
|
202
|
+
interface TransportProviderInstance {
|
|
203
|
+
dmk: IDmk;
|
|
204
|
+
dispose?: () => Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
interface TransportProvider {
|
|
207
|
+
create(options?: TransportProviderOptions): TransportProviderInstance;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* A function that lazily loads and returns the transport factory
|
|
212
|
+
* for the Ledger DMK builder (e.g. webHidTransportFactory, rnBleTransportFactory).
|
|
213
|
+
*/
|
|
214
|
+
type TransportFactory = () => Promise<unknown>;
|
|
215
|
+
interface LedgerConnectorBaseOptions {
|
|
216
|
+
/**
|
|
217
|
+
* Pre-built DMK instance. If not provided, a DMK will be created
|
|
218
|
+
* lazily on first use via the transport factory.
|
|
219
|
+
*/
|
|
220
|
+
dmk?: IDmk;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Shared base class for Ledger IConnector implementations.
|
|
224
|
+
*
|
|
225
|
+
* Encapsulates all shared logic: device discovery, connection management,
|
|
226
|
+
* method dispatch (EVM / BTC / SOL), signer lifecycle, event emission,
|
|
227
|
+
* and error handling.
|
|
228
|
+
*
|
|
229
|
+
* Subclasses only need to:
|
|
230
|
+
* 1. Supply a transport factory via the constructor.
|
|
231
|
+
* 2. Optionally override `_resolveConnectId()` for transport-specific
|
|
232
|
+
* device identity resolution (e.g. BLE hex ID extraction).
|
|
233
|
+
*/
|
|
234
|
+
declare class LedgerConnectorBase implements IConnector {
|
|
235
|
+
private _deviceManager;
|
|
236
|
+
private _signerManager;
|
|
237
|
+
private _dmk;
|
|
238
|
+
private readonly _eventHandlers;
|
|
239
|
+
private readonly _providedDmk;
|
|
240
|
+
private readonly _createTransport;
|
|
241
|
+
private readonly _connectionType;
|
|
242
|
+
constructor(createTransport: TransportFactory, options?: {
|
|
243
|
+
connectionType?: ConnectionType;
|
|
244
|
+
dmk?: IDmk;
|
|
245
|
+
});
|
|
246
|
+
/**
|
|
247
|
+
* Resolve the connectId for a discovered device descriptor.
|
|
248
|
+
* Default: use the DMK path (ephemeral UUID).
|
|
249
|
+
* Override in subclasses to extract stable identifiers (e.g. BLE hex ID).
|
|
250
|
+
*/
|
|
251
|
+
protected _resolveConnectId(descriptor: DeviceDescriptor): string;
|
|
252
|
+
searchDevices(): Promise<ConnectorDevice[]>;
|
|
253
|
+
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
254
|
+
disconnect(sessionId: string): Promise<void>;
|
|
255
|
+
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
256
|
+
cancel(_sessionId: string): Promise<void>;
|
|
257
|
+
uiResponse(_response: {
|
|
258
|
+
type: string;
|
|
259
|
+
payload: unknown;
|
|
260
|
+
}): void;
|
|
261
|
+
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
262
|
+
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
263
|
+
reset(): void;
|
|
264
|
+
private _evmGetAddress;
|
|
265
|
+
private _evmSignTransaction;
|
|
266
|
+
private _evmSignMessage;
|
|
267
|
+
private _evmSignTypedData;
|
|
268
|
+
private _btcGetAddress;
|
|
269
|
+
private _btcGetPublicKey;
|
|
270
|
+
private _btcSignTransaction;
|
|
271
|
+
private _btcSignMessage;
|
|
272
|
+
private _btcGetMasterFingerprint;
|
|
273
|
+
private _solGetAddress;
|
|
274
|
+
private _solSignTransaction;
|
|
275
|
+
private _solSignMessage;
|
|
276
|
+
/**
|
|
277
|
+
* Lazily create or return the DMK instance.
|
|
278
|
+
* If a DMK was provided via constructor, it is used directly.
|
|
279
|
+
* Otherwise, one is created via the transport factory.
|
|
280
|
+
*/
|
|
281
|
+
protected _getOrCreateDmk(): Promise<IDmk>;
|
|
282
|
+
private _initManagers;
|
|
283
|
+
private _getDeviceManager;
|
|
284
|
+
private _getEthSigner;
|
|
285
|
+
private _createBtcSigner;
|
|
286
|
+
private _createSolSigner;
|
|
287
|
+
private _invalidateSession;
|
|
288
|
+
private _resetManagers;
|
|
289
|
+
private _emit;
|
|
290
|
+
private _wrapError;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Manages device discovery, connection, and session tracking.
|
|
295
|
+
* Wraps DMK's Observable APIs into simpler imperative calls.
|
|
296
|
+
*/
|
|
297
|
+
declare class LedgerDeviceManager {
|
|
298
|
+
private readonly _dmk;
|
|
299
|
+
private readonly _discovered;
|
|
300
|
+
private readonly _sessions;
|
|
301
|
+
private readonly _sessionToDevice;
|
|
302
|
+
private _listenSub;
|
|
303
|
+
constructor(dmk: IDmk);
|
|
304
|
+
/**
|
|
305
|
+
* One-shot enumeration: subscribe to listenToAvailableDevices,
|
|
306
|
+
* take the first emission, unsubscribe, return DeviceDescriptors.
|
|
307
|
+
*/
|
|
308
|
+
enumerate(): Promise<DeviceDescriptor[]>;
|
|
309
|
+
/**
|
|
310
|
+
* Continuous listening: tracks device connect/disconnect via diffing.
|
|
311
|
+
*/
|
|
312
|
+
listen(onChange: (event: DeviceChangeEvent) => void): void;
|
|
313
|
+
stopListening(): void;
|
|
314
|
+
/**
|
|
315
|
+
* Trigger browser device selection (WebHID requestDevice).
|
|
316
|
+
* Starts discovery for a short period, then stops.
|
|
317
|
+
*/
|
|
318
|
+
requestDevice(timeoutMs?: number): Promise<void>;
|
|
319
|
+
/** Connect to a previously discovered device. Returns sessionId. */
|
|
320
|
+
connect(deviceId: string): Promise<string>;
|
|
321
|
+
/** Disconnect a session. */
|
|
322
|
+
disconnect(sessionId: string): Promise<void>;
|
|
323
|
+
getSessionId(deviceId: string): string | undefined;
|
|
324
|
+
getDeviceId(sessionId: string): string | undefined;
|
|
325
|
+
/** Get the underlying DMK instance (needed by SignerManager). */
|
|
326
|
+
getDmk(): IDmk;
|
|
327
|
+
dispose(): void;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* SDK signer interface — duck-typed to avoid hard dependency on
|
|
332
|
+
* @ledgerhq/device-signer-kit-ethereum.
|
|
333
|
+
*/
|
|
334
|
+
interface ISdkSignerEth {
|
|
335
|
+
getAddress(derivationPath: string, options?: {
|
|
336
|
+
checkOnDevice?: boolean;
|
|
337
|
+
}): unknown;
|
|
338
|
+
signTransaction(derivationPath: string, transaction: Uint8Array, options?: unknown): unknown;
|
|
339
|
+
signMessage(derivationPath: string, message: string): unknown;
|
|
340
|
+
signTypedData(derivationPath: string, data: unknown): unknown;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Wraps Ledger's SDK signer (Observable-based DeviceActions) into
|
|
344
|
+
* a simple async interface returning plain serializable data.
|
|
345
|
+
*/
|
|
346
|
+
declare class SignerEth {
|
|
347
|
+
private readonly _sdk;
|
|
348
|
+
onInteraction?: (interaction: string) => void;
|
|
349
|
+
constructor(_sdk: ISdkSignerEth);
|
|
350
|
+
getAddress(derivationPath: string, options?: {
|
|
351
|
+
checkOnDevice?: boolean;
|
|
352
|
+
}): Promise<SignerEvmAddress>;
|
|
353
|
+
signTransaction(derivationPath: string, serializedTxHex: string): Promise<SignerEvmSignature>;
|
|
354
|
+
signMessage(derivationPath: string, message: string): Promise<SignerEvmSignature>;
|
|
355
|
+
signTypedData(derivationPath: string, data: unknown): Promise<SignerEvmSignature>;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
type SignerEthBuilderFn = (args: {
|
|
359
|
+
dmk: IDmk;
|
|
360
|
+
sessionId: string;
|
|
361
|
+
}) => {
|
|
362
|
+
build(): unknown;
|
|
363
|
+
} | Promise<{
|
|
364
|
+
build(): unknown;
|
|
365
|
+
}>;
|
|
366
|
+
/**
|
|
367
|
+
* Manages per-sessionId SignerEth instances.
|
|
368
|
+
* Creates on demand, caches for reuse, invalidates on session change.
|
|
369
|
+
*/
|
|
370
|
+
declare class SignerManager {
|
|
371
|
+
private readonly _cache;
|
|
372
|
+
private readonly _dmk;
|
|
373
|
+
private readonly _builderFn;
|
|
374
|
+
constructor(dmk: IDmk, builderFn?: SignerEthBuilderFn);
|
|
375
|
+
getOrCreate(sessionId: string): Promise<SignerEth>;
|
|
376
|
+
invalidate(sessionId: string): void;
|
|
377
|
+
clearAll(): void;
|
|
378
|
+
private static _defaultBuilder;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* SDK BTC signer interface — duck-typed to avoid hard dependency on
|
|
383
|
+
* @ledgerhq/device-signer-kit-bitcoin.
|
|
384
|
+
*/
|
|
385
|
+
interface ISdkSignerBtc {
|
|
386
|
+
getExtendedPublicKey(derivationPath: string, options?: {
|
|
387
|
+
checkOnDevice?: boolean;
|
|
388
|
+
}): unknown;
|
|
389
|
+
getWalletAddress(wallet: unknown, addressIndex: number, options?: {
|
|
390
|
+
checkOnDevice?: boolean;
|
|
391
|
+
change?: boolean;
|
|
392
|
+
}): unknown;
|
|
393
|
+
getMasterFingerprint(options?: {
|
|
394
|
+
skipOpenApp?: boolean;
|
|
395
|
+
}): unknown;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Wraps Ledger's BTC SDK signer (Observable-based DeviceActions) into
|
|
399
|
+
* a simple async interface returning plain serializable data.
|
|
400
|
+
*/
|
|
401
|
+
declare class SignerBtc {
|
|
402
|
+
private readonly _sdk;
|
|
403
|
+
onInteraction?: (interaction: string) => void;
|
|
404
|
+
constructor(_sdk: ISdkSignerBtc);
|
|
405
|
+
getWalletAddress(wallet: unknown, addressIndex: number, options?: {
|
|
406
|
+
checkOnDevice?: boolean;
|
|
407
|
+
change?: boolean;
|
|
408
|
+
}): Promise<SignerBtcAddress>;
|
|
409
|
+
getExtendedPublicKey(derivationPath: string, options?: {
|
|
410
|
+
checkOnDevice?: boolean;
|
|
411
|
+
}): Promise<string>;
|
|
412
|
+
getMasterFingerprint(options?: {
|
|
413
|
+
skipOpenApp?: boolean;
|
|
414
|
+
}): Promise<Uint8Array>;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* SDK SOL signer interface — duck-typed to avoid hard dependency on
|
|
419
|
+
* @ledgerhq/device-signer-kit-solana.
|
|
420
|
+
*/
|
|
421
|
+
interface ISdkSignerSol {
|
|
422
|
+
getAddress(derivationPath: string, options?: {
|
|
423
|
+
checkOnDevice?: boolean;
|
|
424
|
+
}): unknown;
|
|
425
|
+
signTransaction(derivationPath: string, transaction: Uint8Array, options?: unknown): unknown;
|
|
426
|
+
signMessage(derivationPath: string, message: string | Uint8Array, options?: unknown): unknown;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Wraps Ledger's Solana SDK signer (Observable-based DeviceActions) into
|
|
430
|
+
* a simple async interface returning plain serializable data.
|
|
431
|
+
*
|
|
432
|
+
* The Solana signer's `getAddress` returns a base58-encoded Ed25519 public key,
|
|
433
|
+
* which is also the Solana address.
|
|
434
|
+
*/
|
|
435
|
+
declare class SignerSol {
|
|
436
|
+
private readonly _sdk;
|
|
437
|
+
onInteraction?: (interaction: string) => void;
|
|
438
|
+
constructor(_sdk: ISdkSignerSol);
|
|
439
|
+
/**
|
|
440
|
+
* Get the Solana address (base58-encoded Ed25519 public key) at the given derivation path.
|
|
441
|
+
*/
|
|
442
|
+
getAddress(derivationPath: string, options?: {
|
|
443
|
+
checkOnDevice?: boolean;
|
|
444
|
+
}): Promise<string>;
|
|
445
|
+
/**
|
|
446
|
+
* Sign a Solana transaction.
|
|
447
|
+
*/
|
|
448
|
+
signTransaction(derivationPath: string, transaction: Uint8Array, options?: unknown): Promise<Uint8Array>;
|
|
449
|
+
/**
|
|
450
|
+
* Sign a message with the Solana app.
|
|
451
|
+
*/
|
|
452
|
+
signMessage(derivationPath: string, message: string | Uint8Array, options?: unknown): Promise<Uint8Array>;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** DeviceAction state emitted by DMK signer operations. */
|
|
456
|
+
interface DeviceActionState<T> {
|
|
457
|
+
status: 'pending' | 'completed' | 'error';
|
|
458
|
+
output?: T;
|
|
459
|
+
error?: unknown;
|
|
460
|
+
intermediateValue?: {
|
|
461
|
+
requiredUserInteraction?: string;
|
|
462
|
+
[key: string]: unknown;
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Convert a DMK DeviceAction (Observable-based) into a Promise.
|
|
467
|
+
* Handles pending → completed/error state transitions and interaction callbacks.
|
|
468
|
+
*/
|
|
469
|
+
declare function deviceActionToPromise<T>(action: {
|
|
470
|
+
observable: {
|
|
471
|
+
subscribe(observer: {
|
|
472
|
+
next: (value: DeviceActionState<T>) => void;
|
|
473
|
+
error?: (err: unknown) => void;
|
|
474
|
+
complete?: () => void;
|
|
475
|
+
}): {
|
|
476
|
+
unsubscribe: () => void;
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
}, onInteraction?: (interaction: string) => void): Promise<T>;
|
|
480
|
+
|
|
481
|
+
declare function registerTransport(type: string, provider: TransportProvider): void;
|
|
482
|
+
declare function unregisterTransport(type: string): void;
|
|
483
|
+
declare function getTransportProvider(type: string): TransportProvider | null;
|
|
484
|
+
declare function listRegisteredTransports(): string[];
|
|
485
|
+
declare function clearRegistry(): void;
|
|
486
|
+
|
|
487
|
+
interface AppManagerOptions {
|
|
488
|
+
waitMs?: number;
|
|
489
|
+
maxRetries?: number;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Orchestrates opening / closing Ledger on-device apps so that the
|
|
493
|
+
* correct signer application is running before any signing call.
|
|
494
|
+
*/
|
|
495
|
+
declare class AppManager {
|
|
496
|
+
private readonly _dmk;
|
|
497
|
+
private readonly _waitMs;
|
|
498
|
+
private readonly _maxRetries;
|
|
499
|
+
constructor(dmk: IDmk, options?: AppManagerOptions);
|
|
500
|
+
/**
|
|
501
|
+
* Return the Ledger app name for a given chain ticker,
|
|
502
|
+
* or undefined if the chain is not supported.
|
|
503
|
+
*/
|
|
504
|
+
static getAppName(chain: string): string | undefined;
|
|
505
|
+
/**
|
|
506
|
+
* Ensure the target app is open on the device identified by `sessionId`.
|
|
507
|
+
*
|
|
508
|
+
* Flow:
|
|
509
|
+
* 1. Check the currently running app.
|
|
510
|
+
* 2. If it is already the target, return immediately.
|
|
511
|
+
* 3. If a different app is running (not dashboard), close it first.
|
|
512
|
+
* 4. Open the target app.
|
|
513
|
+
* 5. Poll until the device confirms the target app is running.
|
|
514
|
+
*/
|
|
515
|
+
ensureAppOpen(sessionId: string, targetAppName: string): Promise<void>;
|
|
516
|
+
private _getCurrentApp;
|
|
517
|
+
private _openApp;
|
|
518
|
+
private _closeCurrentApp;
|
|
519
|
+
/**
|
|
520
|
+
* Poll the device until the expected app is reported as running,
|
|
521
|
+
* or throw after `_maxRetries` attempts.
|
|
522
|
+
*/
|
|
523
|
+
private _waitForApp;
|
|
524
|
+
private _isDashboard;
|
|
525
|
+
private _wait;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** Check if an error (or any error in its chain) represents a locked Ledger device. */
|
|
529
|
+
declare function isDeviceLockedError(err: unknown): boolean;
|
|
530
|
+
/**
|
|
531
|
+
* Map a Ledger DMK error to a HardwareErrorCode and human-readable message
|
|
532
|
+
* with actionable recovery information for the caller.
|
|
533
|
+
*/
|
|
534
|
+
declare function mapLedgerError(err: unknown): {
|
|
535
|
+
code: HardwareErrorCode;
|
|
536
|
+
message: string;
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
export { AppManager, type DeviceActionState$1 as DeviceActionState, type DmkDiscoveredDevice, type IDmk, LedgerAdapter, LedgerConnectorBase, type LedgerConnectorBaseOptions, LedgerDeviceManager, SignerBtc, type SignerBtcAddress, SignerEth, type SignerEvmAddress, type SignerEvmSignature, SignerManager, SignerSol, type TransportFactory, type TransportProvider, type TransportProviderInstance, type TransportProviderOptions, clearRegistry, deviceActionToPromise, getTransportProvider, isDeviceLockedError, listRegisteredTransports, mapLedgerError, registerTransport, unregisterTransport };
|