UNPKG

@zondax/ledger-js

Version:

TS / Node API for apps running on Ledger devices

40 lines (39 loc) 2.23 kB
/****************************************************************************** * (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ import { LedgerCustomError } from './consts'; import { ResponsePayload } from './payload'; import { ResponseError } from './responseError'; /** * Processes the raw response from a device to extract either the payload or error information. * It reads the last two bytes of the response to determine the return code and constructs * an appropriate response object based on this code. If the return code indicates no errors, * the payload is returned directly. Otherwise, an error object is thrown. * * @param responseRaw - The raw response buffer from the device, potentially containing error codes or data. * @param customErrorList - Custom error description list to convert error code with. * @returns The payload as a buffer if no errors are found. * @throws {ResponseError} An object detailing the error if any is found. */ export declare function processResponse(responseRaw: Buffer, customErrorList?: Record<LedgerCustomError, string>): ResponsePayload; /** * Processes error responses and formats them into a standardized object. * This function is deprecated and should not be used in new implementations. * * @param response - The raw response object that may contain error details. * @param customErrorList - Custom error description list to convert error code with. * @returns A standardized error response object. */ export declare function processErrorResponse(response: any, customErrorList?: Record<LedgerCustomError, string>): ResponseError;