Skip to content

Commit

Permalink
feat: support 4 bytes per value on app version (#119)
Browse files Browse the repository at this point in the history
* feat: support 4 bytes per value on app version

* chore: update dependencies

* feat: add dependabot config

* fix: dependabot

* fix: format
  • Loading branch information
emmanuelm41 authored Aug 19, 2024
1 parent cc988ae commit b24c126
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Basic dependabot.yml file with
# minimum configuration for two package managers

version: 2
updates:
# Enable version updates for npm
- package-ecosystem: 'npm'
# Look for `package.json` and `lock` files in the `root` directory
directory: '/'
# Check the npm registry for updates every day (weekdays)
schedule:
interval: 'daily'
target-branch: dev

# Enable version updates for GitHub Actions
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
time: '11:00'
commit-message:
prefix: 'chore'
prefix-development: 'chore'
include: 'scope'
target-branch: dev
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"upgrade": "bunx npm-check-updates -i"
},
"dependencies": {
"@ledgerhq/hw-transport": "6.31.0",
"@zondax/ledger-js": "^0.8.2",
"axios": "^1.7.2"
"@ledgerhq/hw-transport": "6.31.2",
"@zondax/ledger-js": "^0.11.0",
"axios": "^1.7.4"
},
"devDependencies": {
"@ledgerhq/hw-transport-mocker": "^6.29.0",
Expand Down
28 changes: 21 additions & 7 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,34 @@ export async function getVersion(transport: Transport, cla: number) {
const errorCodeData = response.subarray(-2)
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]

// 12 bytes + 2 error code
if (response.length !== 14) {
// 12 bytes + 2 error code (2 bytes per value on version)
// 18 bytes + 2 error code (4 bytes per value on version)
if (response.length !== 14 && response.length !== 20) {
return {
return_code: ERROR_CODE.InvalidData,
error_message: errorCodeToString(ERROR_CODE.InvalidData),
}
}

const major = response[1] * 256 + response[2]
const minor = response[3] * 256 + response[4]
const patch = response[5] * 256 + response[6]
const deviceLocked = response[7] === 1
let major, minor, patch, deviceLocked, targetId

if (response.length === 14) {
// 12 bytes + 2 error code (2 bytes per value on version)
major = response.readUInt16BE(1)
minor = response.readUInt16BE(3)
patch = response.readUInt16BE(5)
deviceLocked = response[7] === 1
targetId = (response[8] << 24) + (response[9] << 16) + (response[10] << 8) + (response[11] << 0)
} else {
// 18 bytes + 2 error code (4 bytes per value on version)
major = response.readUInt32BE(1)
minor = response.readUInt32BE(5)
patch = response.readUInt32BE(9)
deviceLocked = response[13] === 1
targetId = (response[14] << 24) + (response[15] << 16) + (response[16] << 8) + (response[17] << 0)
}

// eslint-disable-next-line no-bitwise
const targetId = (response[8] << 24) + (response[9] << 16) + (response[10] << 8) + (response[11] << 0)

return {
return_code: returnCode,
Expand Down
43 changes: 34 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,16 @@
rxjs "^7.8.1"
semver "^7.3.5"

"@ledgerhq/devices@^8.4.2":
version "8.4.2"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-8.4.2.tgz#f1c56194cf1343d56cad49c8feba92ad93432e14"
integrity sha512-oWNTp3jCMaEvRHsXNYE/yo+PFMgXAJGFHLOU1UdE4/fYkniHbD9wdxwyZrZvrxr9hNw4/9wHiThyITwPtMzG7g==
dependencies:
"@ledgerhq/errors" "^6.18.0"
"@ledgerhq/logs" "^6.12.0"
rxjs "^7.8.1"
semver "^7.3.5"

"@ledgerhq/errors@^6.16.4":
version "6.16.4"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.16.4.tgz#a38baffe8b096d9fff3ad839cadb55704c8d8e7b"
Expand All @@ -672,6 +682,11 @@
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.17.0.tgz#0d56361fe6eb7de3b239e661710679f933f1fcca"
integrity sha512-xnOVpy/gUUkusEORdr2Qhw3Vd0MGfjyVGgkGR9Ck6FXE26OIdIQ3tNmG5BdZN+gwMMFJJVxxS4/hr0taQfZ43w==

"@ledgerhq/errors@^6.18.0":
version "6.18.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.18.0.tgz#d55d6a57430d7a86532a9033ce0b45103264c620"
integrity sha512-L3jQWAGyooxRDk/MRlW2v4Ji9+kloBtdmz9wBkHaj2j0n+05rweJSV3GHw9oye1BYMbVFqFffmT4H3hlXlCasw==

"@ledgerhq/hw-transport-mocker@^6.29.0":
version "6.29.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-mocker/-/hw-transport-mocker-6.29.0.tgz#ab5a736817c2dfc33ac779e4153f11f208e71ff8"
Expand Down Expand Up @@ -716,7 +731,17 @@
"@ledgerhq/logs" "^6.12.0"
events "^3.3.0"

"@ledgerhq/[email protected]", "@ledgerhq/hw-transport@^6.31.0":
"@ledgerhq/[email protected]":
version "6.31.2"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.31.2.tgz#79c95f7928a64a0e3b5bc4ea7b5be04b9f738322"
integrity sha512-B27UIzMzm2IXPGYnEB95R7eHxpXBkTBHh6MUJJQZVknt8LilEz1tfpTYUdzAKDGQ+Z5MZyYb01Eh3Zqm3kn3uw==
dependencies:
"@ledgerhq/devices" "^8.4.2"
"@ledgerhq/errors" "^6.18.0"
"@ledgerhq/logs" "^6.12.0"
events "^3.3.0"

"@ledgerhq/hw-transport@^6.31.0":
version "6.31.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.31.0.tgz#82d8154bbcec8dc0104009a646159190fba5ae76"
integrity sha512-BY1poLk8vlJdIYngp8Zfaa/V9n14dqgt1G7iNetVRhJVFEKp9EYONeC3x6q/N7x81LUpzBk6M+T+s46Z4UiXHw==
Expand Down Expand Up @@ -1151,10 +1176,10 @@
"@typescript-eslint/types" "7.14.1"
eslint-visitor-keys "^3.4.3"

"@zondax/ledger-js@^0.8.2":
version "0.8.2"
resolved "https://registry.yarnpkg.com/@zondax/ledger-js/-/ledger-js-0.8.2.tgz#d8b13b539ff7f830f7dd84b9e935e4d268a62de5"
integrity sha512-U/lzNzcJwfYGhhpwUviazihXzIv8w3rM31HbgKWOwF/xVS4/hHSLCGpONEGVwtgYUNDF7L0YfSy95/0H+tGtFA==
"@zondax/ledger-js@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@zondax/ledger-js/-/ledger-js-0.11.0.tgz#709923f5ec0c72cec2e1da80863717beb5c69f48"
integrity sha512-Y+hbuIVIT+QcIrZgJZN8BjpvmLJ9v2+yQtbpYVTtosAw/NNOg/NI6QKMxP4fwomW/6SEK6jaIqsLhTvTZP7qDA==
dependencies:
"@ledgerhq/hw-transport" "6.30.6"

Expand Down Expand Up @@ -1332,10 +1357,10 @@ available-typed-arrays@^1.0.7:
dependencies:
possible-typed-array-names "^1.0.0"

axios@^1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.2.tgz#b625db8a7051fbea61c35a3cbb3a1daa7b9c7621"
integrity sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==
axios@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.4.tgz#4c8ded1b43683c8dd362973c393f3ede24052aa2"
integrity sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
Expand Down

0 comments on commit b24c126

Please sign in to comment.