Skip to content

Commit 62dafef

Browse files
authored
improved typing (#25)
1 parent 4812e73 commit 62dafef

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

bun.lockb

4.15 KB
Binary file not shown.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"@ledgerhq/hw-transport-mocker": "^6.28.6",
4242
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
4343
"@types/jest": "29.5.12",
44-
"@types/node": "^20.12.11",
45-
"@typescript-eslint/eslint-plugin": "^7.8.0",
46-
"@typescript-eslint/parser": "^7.8.0",
44+
"@types/node": "^20.12.12",
45+
"@typescript-eslint/eslint-plugin": "^7.9.0",
46+
"@typescript-eslint/parser": "^7.9.0",
4747
"eslint": "^9.2.0",
4848
"eslint-config-prettier": "^9.1.0",
4949
"eslint-config-standard-with-typescript": "^39.0.0",

src/bip32.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*****************************************************************************/
1616
import { HARDENED, LedgerError } from './consts'
1717
import { ResponseError } from './responseError'
18+
import { BIP32Path } from './types'
1819

1920
/**
2021
* Serializes a derivation path into a buffer.
2122
* @param path - The derivation path in string format.
2223
* @returns A buffer representing the serialized path.
2324
* @throws {ResponseError} If the path format is incorrect or invalid.
2425
*/
25-
export function serializePath(path: string, requiredPathLengths?: number[]): Buffer {
26+
export function serializePath(path: BIP32Path, requiredPathLengths?: number[]): Buffer {
2627
if (typeof path !== 'string') {
2728
// NOTE: this is probably unnecessary
2829
throw new ResponseError(LedgerError.GenericError, "Path should be a string (e.g \"m/44'/461'/5'/0/3\")")
@@ -71,7 +72,7 @@ export function serializePath(path: string, requiredPathLengths?: number[]): Buf
7172
* @returns The derivation path in string format.
7273
* @throws {Error} If the array length is not a multiple of 4 or if the array contains invalid values.
7374
*/
74-
export function numbersToBip32Path(items: number[]): string {
75+
export function numbersToBip32Path(items: number[]): BIP32Path {
7576
if (items.length === 0) {
7677
throw new ResponseError(LedgerError.GenericError, 'The items array cannot be empty.')
7778
}
@@ -99,7 +100,7 @@ export function numbersToBip32Path(items: number[]): string {
99100
* @returns The derivation path in string format.
100101
* @throws {Error} If the buffer length is not a multiple of 4 or if the buffer contains invalid values.
101102
*/
102-
export function bufferToBip32Path(buffer: Buffer): string {
103+
export function bufferToBip32Path(buffer: Buffer): BIP32Path {
103104
if (buffer.length % 4 !== 0) {
104105
throw new ResponseError(LedgerError.GenericError, 'The buffer length must be a multiple of 4.')
105106
}

src/payload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ResponseError } from './responseError'
1818

1919
export class ResponsePayload {
2020
private offset = 0
21-
private internalBuffer: Buffer
21+
private readonly internalBuffer: Buffer
2222

2323
constructor(payload: Buffer) {
2424
this.internalBuffer = payload

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ export interface ConstructorParams {
7777
chunkSize: number
7878
acceptedPathLengths?: number[]
7979
}
80+
81+
export type BIP32Path = string

0 commit comments

Comments
 (0)