Skip to content

Commit b771f92

Browse files
authored
upgrade deps + cleanup (#18)
* reorganize package.json * clean up
1 parent 284a845 commit b771f92

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

bun.lockb

1.23 KB
Binary file not shown.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.3.0",
44
"description": "TS / Node API for apps running on Ledger devices",
55
"keywords": [
6+
"Zondax",
67
"Ledger",
78
"Typescript",
8-
"Javascript",
9-
"Zondax"
9+
"Javascript"
1010
],
1111
"homepage": "https://github.com/Zondax/ledger-js",
1212
"bugs": {
@@ -25,7 +25,6 @@
2525
],
2626
"scripts": {
2727
"build": "tsc",
28-
"copy-files": "copyfiles -u 0 src/**/*.proto dist/",
2928
"format": "FORCE_COLOR=1 prettier --write . && sort-package-json",
3029
"format:check": "FORCE_COLOR=1 prettier --check .",
3130
"lint": "eslint .",
@@ -42,14 +41,14 @@
4241
"@ledgerhq/hw-transport-mocker": "^6.28.6",
4342
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
4443
"@types/jest": "29.5.12",
45-
"@types/node": "^18.11.18",
44+
"@types/node": "^20.12.11",
4645
"@typescript-eslint/eslint-plugin": "^7.8.0",
4746
"@typescript-eslint/parser": "^7.8.0",
4847
"eslint": "^9.2.0",
4948
"eslint-config-prettier": "^9.1.0",
5049
"eslint-config-standard-with-typescript": "^34.0.1",
5150
"eslint-plugin-import": "^2.29.1",
52-
"eslint-plugin-n": "^17.4.0",
51+
"eslint-plugin-n": "^17.6.0",
5352
"eslint-plugin-promise": "^6.1.1",
5453
"eslint-plugin-tsdoc": "^0.2.17",
5554
"eslint-plugin-unused-imports": "^3.2.0",

src/app.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import type Transport from '@ledgerhq/hw-transport'
1717

1818
import { errorCodeToString, processErrorResponse } from './common'
19-
import { LedgerError } from './consts'
19+
import { HARDENED, LedgerError, PAYLOAD_TYPE } from './consts'
2020
import {
2121
type ConstructorParams,
2222
type INSGeneric,
@@ -50,7 +50,9 @@ export default class BaseApp {
5050
* @throws {Error} If the path format is incorrect or invalid.
5151
*/
5252
serializePath(path: string): Buffer {
53-
const HARDENED = 0x80000000
53+
if (typeof path !== 'string') {
54+
throw new Error("Path should be a string (e.g \"m/44'/461'/5'/0/3\")")
55+
}
5456

5557
if (!path.startsWith('m/')) {
5658
throw new Error('Path should start with "m/" (e.g "m/44\'/5757\'/5\'/0/3")')
@@ -67,15 +69,18 @@ export default class BaseApp {
6769

6870
pathArray.forEach((child, i) => {
6971
let value = 0
72+
7073
if (child.endsWith("'")) {
7174
value += HARDENED
7275
child = child.slice(0, -1)
7376
}
77+
7478
const numChild = Number(child)
7579

7680
if (Number.isNaN(numChild)) {
7781
throw new Error(`Invalid path : ${child} is not a number. (e.g "m/44'/461'/5'/0/3")`)
7882
}
83+
7984
if (numChild >= HARDENED) {
8085
throw new Error('Incorrect child value (bigger or equal to 0x80000000)')
8186
}
@@ -110,6 +115,31 @@ export default class BaseApp {
110115
return chunks
111116
}
112117

118+
async signSendChunk(ins: number, chunkIdx: number, chunkNum: number, chunk: Buffer) {
119+
let payloadType = PAYLOAD_TYPE.ADD
120+
121+
if (chunkIdx === 1) {
122+
payloadType = PAYLOAD_TYPE.INIT
123+
}
124+
125+
if (chunkIdx === chunkNum) {
126+
payloadType = PAYLOAD_TYPE.LAST
127+
}
128+
129+
return this.transport.send(this.CLA, ins, payloadType, 0, chunk, [0x9000, 0x6984, 0x6a80]).then(response => {
130+
const errorCodeData = response.subarray(-2)
131+
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]
132+
133+
let errorMessage = errorCodeToString(returnCode)
134+
135+
if (returnCode === LedgerError.BadKeyHandle || returnCode === LedgerError.DataIsInvalid) {
136+
errorMessage = `${errorMessage} : ${response.subarray(0, response.length - 2).toString('ascii')}`
137+
}
138+
139+
return response
140+
}, processErrorResponse)
141+
}
142+
113143
/**
114144
* Retrieves the version information from the device.
115145
* @returns A promise that resolves to the version information.

src/consts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*****************************************************************************/
1616

17+
export const HARDENED = 0x80000000
18+
1719
// Payload types for transactions
1820
export const PAYLOAD_TYPE: Readonly<Record<string, number>> = {
1921
INIT: 0x00,

0 commit comments

Comments
 (0)