Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support version with u32 fields #109

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,48 @@ export function processErrorResponse(response: any) {
}
}

async function getVersionBig(response: Buffer) {
const errorCodeData = response.subarray(-2)
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]

if (response.length !== 20) {
return {
return_code: ERROR_CODE.InvalidData,
error_message: errorCodeToString(ERROR_CODE.InvalidData),
}
}

const major = (response[1] << 24) | (response[2] << 16) | (response[3] << 8) | response[4]
const minor = (response[5] << 24) | (response[6] << 16) | (response[7] << 8) | response[8]
const patch = (response[9] << 24) | (response[10] << 16) | (response[11] << 8) | response[12]

const deviceLocked = response[13] === 1
// eslint-disable-next-line no-bitwise
const targetId = (response[14] << 24) + (response[15] << 16) + (response[16] << 8) + (response[17] << 0)

return {
return_code: returnCode,
error_message: errorCodeToString(returnCode),
// ///
test_mode: response[0] !== 0,
major,
minor,
patch,
deviceLocked,
target_id: targetId.toString(16),
}
}

export async function getVersion(transport: Transport, cla: number) {
try {
const response = await transport.send(cla, INS.GET_VERSION, 0, 0)
// Some chains will return the version using uint32 fields for major, minor and patch
if (response.length === 20) {
return getVersionBig(response)
}

const errorCodeData = response.subarray(-2)
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]

// 12 bytes + 2 error code
if (response.length !== 14) {
return {
Expand Down
Loading