UNPKG

@metamask/eth-ledger-bridge-keyring

Version:
157 lines 7.24 kB
import { DeviceManagementKitBuilder } from "@ledgerhq/device-management-kit"; import type Transport from "@ledgerhq/hw-transport"; import type { Observable } from "rxjs"; import { AppConfigurationResponse, GetAppNameAndVersionResponse, GetPublicKeyParams, GetPublicKeyResponse, LedgerBridge, LedgerSignDelegationAuthorizationParams, LedgerSignDelegationAuthorizationResponse, LedgerSignMessageParams, LedgerSignMessageResponse, LedgerSignTransactionParams, LedgerSignTransactionResponse, LedgerSignTypedDataParams, LedgerSignTypedDataResponse } from "../ledger-bridge.cjs"; import { LedgerDmkTransportMiddleware } from "./ledger-dmk-transport-middleware.cjs"; export type LedgerDmkBridgeOptions = { transportFactory: Parameters<DeviceManagementKitBuilder['addTransport']>[0]; }; /** * LedgerDmkBridge is a bridge between the LedgerKeyring and the * LedgerDmkTransportMiddleware. * It initializes and manages the DeviceManagementKit internally. * The transport factory is injected via constructor, making it platform-agnostic. */ export declare class LedgerDmkBridge implements LedgerBridge<LedgerDmkBridgeOptions> { #private; get onSessionStateChange(): Observable<{ connected: boolean; }>; get isDeviceConnected(): boolean; constructor(opts: LedgerDmkBridgeOptions); /** * Compatibility shim for the shared {@link LedgerBridge} interface. * * DMK session setup happens externally via `updateSessionId` or `connect`, * so this method is a no-op. * * @returns A promise that resolves immediately. */ init(): Promise<void>; /** * Destroys the bridge and cleans up resources. * * Unsubscribes session monitoring, disposes the transport middleware, and * completes the session-state subject so all subscribers are released. A * fresh subject is installed afterward so the bridge can be reconnected * after destroy. State cleanup happens in a `finally` block so the bridge * is marked disconnected even when middleware `dispose()` rejects. * * @returns A promise that resolves when cleanup is complete. */ destroy(): Promise<void>; /** * Returns the bridge options captured at construction. * * Compatibility shim for the shared {@link LedgerBridge} interface. The DMK * bridge does not use runtime-reconfigurable options; this method exists * only to satisfy the interface contract. * * @returns A promise that resolves with the current bridge options. */ getOptions(): Promise<LedgerDmkBridgeOptions>; /** * Replaces the stored bridge options. * * Compatibility shim for the shared {@link LedgerBridge} interface. Stored * options are not re-applied to the underlying DMK instance or transport * middleware; the values used at construction time remain in effect. * * @param opts - The options to set for the bridge. * @returns A promise that resolves when options are set. */ setOptions(opts: LedgerDmkBridgeOptions): Promise<void>; /** * Updates the session ID used for communication. * * @param sessionId - The session ID from DMK. * @returns A promise that resolves with true if the session was updated successfully. */ updateSessionId(sessionId: string): Promise<boolean>; /** * Starts device discovery for the configured DMK transport. * * @param args - Optional DMK discovery options. * @returns An observable that emits discovered devices. */ startDiscovering(...args: Parameters<LedgerDmkTransportMiddleware['startDiscovering']>): ReturnType<LedgerDmkTransportMiddleware['startDiscovering']>; /** * Connects to a discovered device using the configured DMK transport. * * @param args - The DMK connection arguments. * @returns The created session ID. */ connect(...args: Parameters<LedgerDmkTransportMiddleware['connect']>): ReturnType<LedgerDmkTransportMiddleware['connect']>; /** * Compatibility shim for the shared {@link LedgerBridge} interface. * * DMK transport selection happens through the injected transport factory * at construction time, so this method is a no-op that always succeeds. * * @param _transportType - The requested transport type (ignored). * @returns A promise that resolves with `true`. */ updateTransportMethod(_transportType: string | Transport): Promise<boolean>; openEthApp(): Promise<void>; closeApps(): Promise<void>; /** * Compatibility shim for the shared {@link LedgerBridge} interface. * * The Ethereum signer kit automatically opens the Ethereum app before each * signing operation via DMK's `CallTaskInAppDeviceAction`, so this method * is a no-op that always succeeds. * * @returns A promise that resolves with `true`. */ attemptMakeApp(): Promise<boolean>; /** * Retrieves public key/address for a given HD path. * * @param options0 - The parameters object. * @param options0.hdPath - The HD path to derive the public key from. * @returns A promise that resolves with the public key response. */ getPublicKey({ hdPath, }: GetPublicKeyParams): Promise<GetPublicKeyResponse>; /** * Signs an Ethereum transaction. * * @param options0 - The parameters object. * @param options0.tx - The transaction hex string to sign. * @param options0.hdPath - The HD path for signing. * @returns A promise that resolves with the transaction signature. */ deviceSignTransaction({ tx, hdPath, }: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse>; /** * Signs a personal message. * * @param options0 - The parameters object. * @param options0.hdPath - The HD path for signing. * @param options0.message - The message to sign. * @returns A promise that resolves with the message signature. */ deviceSignMessage({ hdPath, message, }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse>; /** * Signs EIP-712 typed data. * * @param options0 - The parameters object. * @param options0.hdPath - The HD path for signing. * @param options0.message - The typed data message to sign. * @returns A promise that resolves with the typed data signature. */ deviceSignTypedData({ hdPath, message, }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse>; deviceSignDelegationAuthorization({ hdPath, chainId, contractAddress, nonce, }: LedgerSignDelegationAuthorizationParams): Promise<LedgerSignDelegationAuthorizationResponse>; /** * Retrieves the current app name and version. * * @returns A promise that resolves with the app name and version. */ getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>; /** * Retrieves the Ethereum app configuration using the eth-specific * GetAppConfiguration APDU command (CLA 0xE0, INS 0x06). * * @returns A promise that resolves with the app configuration. */ getAppConfiguration(): Promise<AppConfigurationResponse>; } //# sourceMappingURL=ledger-dmk-bridge.d.cts.map