Skip to content

Commit 16589bb

Browse files
authored
feat: support 4 bytes on app version (#31)
1 parent 9e7ff1f commit 16589bb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/app.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,46 @@ describe('BaseApp', () => {
231231
})
232232
})
233233

234+
it('should retrieve version information (14 bytes)', async () => {
235+
const responseBuffer = Buffer.concat([
236+
Buffer.from([1, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 1]), // Version information
237+
Buffer.from([0x90, 0x00]), // Status code for no errors (0x9000)
238+
])
239+
240+
const transport = new MockTransport(responseBuffer)
241+
const app = new BaseApp(transport, params)
242+
const version = await app.getVersion()
243+
244+
expect(version).toEqual({
245+
major: 7,
246+
minor: 8,
247+
patch: 9,
248+
deviceLocked: true,
249+
targetId: '',
250+
testMode: true,
251+
})
252+
})
253+
254+
it('should retrieve version information (18 bytes)', async () => {
255+
const responseBuffer = Buffer.concat([
256+
Buffer.from([1, 0, 0, 1, 5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0xa, 0xb, 0xc]), // Version information
257+
Buffer.from([0x90, 0x00]), // Status code for no errors (0x9000)
258+
])
259+
260+
const transport = new MockTransport(responseBuffer)
261+
const app = new BaseApp(transport, params)
262+
const version = await app.getVersion()
263+
264+
expect(version).toEqual({
265+
major: 261,
266+
minor: 6,
267+
patch: 7,
268+
deviceLocked: false,
269+
targetId: '000a0b0c',
270+
testMode: true,
271+
})
272+
})
273+
234274
it('should handle missing data', async () => {
235275
const responseBuffer = Buffer.concat([
236276
Buffer.from([0, 1, 2, 3]), // Version information

src/app.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ export default class BaseApp {
168168
// device locked: 1 byte
169169
// targetId: 4 bytes
170170
// total: 8 or 12 bytes
171+
// -----
172+
// test mode: 1 byte
173+
// major, minor, patch: 12 byte total
174+
// device locked: 1 byte
175+
// targetId: 4 bytes
176+
// total: 14 or 18 bytes
171177

172178
let testMode
173179
let major, minor, patch
@@ -182,6 +188,11 @@ export default class BaseApp {
182188
major = response.readBytes(2).readUInt16BE()
183189
minor = response.readBytes(2).readUInt16BE()
184190
patch = response.readBytes(2).readUInt16BE()
191+
} else if (response.length() === 14 || response.length() === 18) {
192+
testMode = response.readBytes(1).readUInt8() !== 0
193+
major = response.readBytes(4).readUInt32BE()
194+
minor = response.readBytes(4).readUInt32BE()
195+
patch = response.readBytes(4).readUInt32BE()
185196
} else {
186197
throw new ResponseError(LedgerError.TechnicalProblem, 'Invalid response length')
187198
}

0 commit comments

Comments
 (0)