import { LedgerError } from './consts'; import { ResponsePayload } from './payload'; import { DMKTransport } from './transports/dmk'; import { type ConstructorParams, type INSGeneric, type LedgerTransport, type P1_VALUESGeneric, type ResponseAppInfo, type ResponseDeviceInfo, type ResponseVersion } from './types'; /** * Base class for interacting with a Ledger device. */ export default class BaseApp { readonly transport: LedgerTransport; readonly CLA: number; readonly INS: INSGeneric; readonly P1_VALUES: P1_VALUESGeneric; readonly REQUIRED_PATH_LENGTHS?: number[]; readonly CHUNK_SIZE: number; readonly CUSTOM_APP_ERROR_DESCRIPTION?: Readonly>; /** * Constructs a new BaseApp instance over a Device Management Kit session. * @param transport - A {@link DMKTransport} bound to a connected DMK session. * @param params - The constructor parameters. */ constructor(transport: DMKTransport, params: ConstructorParams); /** * Constructs a new BaseApp instance over any transport that can send an APDU. * * @deprecated Pass a {@link DMKTransport} instead. Ledger deprecated `@ledgerhq/hw-transport` * in favour of the Device Management Kit, and this overload -- which also admits hand-rolled * transports -- is removed in the next major version. Using it logs a one-time warning. * * `DMKTransport` has private members, so only a real instance selects the overload above: an * hw-transport `Transport` or a plain `{ send }` object lands here. Subclasses that forward a * generic transport to `super` land here too, which is what surfaces the deprecation to SDKs. * @param transport - The transport mechanism to communicate with the device. * @param params - The constructor parameters. */ constructor(transport: LedgerTransport, params: ConstructorParams); /** * Serializes a derivation path into a buffer. * @param path - The derivation path in string format. * @returns A buffer representing the serialized path. */ serializePath(path: string): Buffer; /** * Prepares chunks of data to be sent to the device. * @param path - The derivation path. * @param message - The message to be sent. * @returns An array of buffers that are ready to be sent. */ protected prepareChunks(path: string, message: Buffer): Buffer[]; /** * Splits a buffer into chunks of `this.CHUNK_SIZE` size. * @param message - The message to be chunked. * @returns An array of buffers, each representing a chunk of the original message. */ protected messageToChunks(message: Buffer): Buffer[]; /** * Sends a chunk of data to the device and handles the response. * Determines the payload type based on the chunk index and sends the chunk to the device. * Processes the response from the device. * * @param ins - The instruction byte. * @param p2 - P2 parameter byte. * @param chunkIdx - The current chunk index. * @param chunkNum - The total number of chunks. * @param chunk - The chunk data as a buffer. * @returns A promise that resolves to the processed response from the device. * @throws {ResponseError} If the response from the device indicates an error. */ protected sendGenericChunk(ins: number, p2: number, chunkIdx: number, chunkNum: number, chunk: Buffer): Promise; /** * Sends a chunk of data to the device and handles the response. * This method determines the payload type based on the chunk index and sends the chunk to the device. * It then processes the response from the device. * * @param ins - The instruction byte. * @param chunkIdx - The current chunk index. * @param chunkNum - The total number of chunks. * @param chunk - The chunk data as a buffer. * @returns A promise that resolves to the processed response from the device. * @throws {ResponseError} If the response from the device indicates an error. */ protected signSendChunk(ins: number, chunkIdx: number, chunkNum: number, chunk: Buffer): Promise; /** * Retrieves the version information from the device. * @returns A promise that resolves to the version information. * @throws {ResponseError} If the response from the device indicates an error. */ getVersion(): Promise; /** * Retrieves application information from the device. * @returns A promise that resolves to the application information. * @throws {ResponseError} If the response from the device indicates an error. */ appInfo(): Promise; /** * Retrieves device information from the device. * @returns A promise that resolves to the device information. * @throws {ResponseError} If the response from the device indicates an error. */ deviceInfo(): Promise; }