Skip to content

Commit 0c7a473

Browse files
committed
feat: add support to custom app error description at app class level
1 parent a394fb2 commit 0c7a473

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/app.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default class BaseApp {
3939
readonly P1_VALUES: P1_VALUESGeneric
4040
readonly REQUIRED_PATH_LENGTHS?: number[]
4141
readonly CHUNK_SIZE: number
42+
readonly CUSTOM_APP_ERROR_DESCRIPTION?: Readonly<Record<LedgerError, string>>
4243

4344
/**
4445
* Constructs a new BaseApp instance.
@@ -56,6 +57,7 @@ export default class BaseApp {
5657
this.P1_VALUES = params.p1Values
5758
this.CHUNK_SIZE = params.chunkSize
5859
this.REQUIRED_PATH_LENGTHS = params.acceptedPathLengths
60+
this.CUSTOM_APP_ERROR_DESCRIPTION = params.customAppErrorDescription
5961
}
6062

6163
/**
@@ -125,7 +127,7 @@ export default class BaseApp {
125127
const statusList = [LedgerError.NoErrors, LedgerError.DataIsInvalid, LedgerError.BadKeyHandle]
126128

127129
const responseBuffer = await this.transport.send(this.CLA, ins, payloadType, p2, chunk, statusList)
128-
const response = processResponse(responseBuffer)
130+
const response = processResponse(responseBuffer, this.CUSTOM_APP_ERROR_DESCRIPTION)
129131

130132
return response
131133
}
@@ -154,7 +156,7 @@ export default class BaseApp {
154156
async getVersion(): Promise<ResponseVersion> {
155157
try {
156158
const responseBuffer = await this.transport.send(this.CLA, this.INS.GET_VERSION, 0, 0)
157-
const response = processResponse(responseBuffer)
159+
const response = processResponse(responseBuffer, this.CUSTOM_APP_ERROR_DESCRIPTION)
158160

159161
// valid options are
160162
// test mode: 1 byte
@@ -224,7 +226,7 @@ export default class BaseApp {
224226
async appInfo(): Promise<ResponseAppInfo> {
225227
try {
226228
const responseBuffer = await this.transport.send(LEDGER_DASHBOARD_CLA, 0x01, 0, 0)
227-
const response = processResponse(responseBuffer)
229+
const response = processResponse(responseBuffer, this.CUSTOM_APP_ERROR_DESCRIPTION)
228230

229231
const formatId = response.readBytes(1).readUInt8()
230232

@@ -264,7 +266,7 @@ export default class BaseApp {
264266
async deviceInfo(): Promise<ResponseDeviceInfo> {
265267
try {
266268
const responseBuffer = await this.transport.send(0xe0, 0x01, 0, 0, Buffer.from([]), [LedgerError.NoErrors, 0x6e00])
267-
const response = processResponse(responseBuffer)
269+
const response = processResponse(responseBuffer, this.CUSTOM_APP_ERROR_DESCRIPTION)
268270

269271
const targetId = response.readBytes(4).toString('hex')
270272

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*****************************************************************************/
16+
import { LedgerCustomError } from './consts'
1617

1718
/**
1819
* Represents the version response from a device.
@@ -76,6 +77,7 @@ export interface ConstructorParams {
7677
p1Values: P1_VALUESGeneric
7778
chunkSize: number
7879
acceptedPathLengths?: number[]
80+
customAppErrorDescription?: Readonly<Record<LedgerCustomError, string>>
7981
}
8082

8183
export type BIP32Path = string

0 commit comments

Comments
 (0)