|
15 | 15 | *****************************************************************************/
|
16 | 16 | import { HARDENED, LedgerError } from './consts'
|
17 | 17 | import { ResponseError } from './responseError'
|
| 18 | +import { BIP32Path } from './types' |
18 | 19 |
|
19 | 20 | /**
|
20 | 21 | * Serializes a derivation path into a buffer.
|
21 | 22 | * @param path - The derivation path in string format.
|
22 | 23 | * @returns A buffer representing the serialized path.
|
23 | 24 | * @throws {ResponseError} If the path format is incorrect or invalid.
|
24 | 25 | */
|
25 |
| -export function serializePath(path: string, requiredPathLengths?: number[]): Buffer { |
| 26 | +export function serializePath(path: BIP32Path, requiredPathLengths?: number[]): Buffer { |
26 | 27 | if (typeof path !== 'string') {
|
27 | 28 | // NOTE: this is probably unnecessary
|
28 | 29 | 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
|
71 | 72 | * @returns The derivation path in string format.
|
72 | 73 | * @throws {Error} If the array length is not a multiple of 4 or if the array contains invalid values.
|
73 | 74 | */
|
74 |
| -export function numbersToBip32Path(items: number[]): string { |
| 75 | +export function numbersToBip32Path(items: number[]): BIP32Path { |
75 | 76 | if (items.length === 0) {
|
76 | 77 | throw new ResponseError(LedgerError.GenericError, 'The items array cannot be empty.')
|
77 | 78 | }
|
@@ -99,7 +100,7 @@ export function numbersToBip32Path(items: number[]): string {
|
99 | 100 | * @returns The derivation path in string format.
|
100 | 101 | * @throws {Error} If the buffer length is not a multiple of 4 or if the buffer contains invalid values.
|
101 | 102 | */
|
102 |
| -export function bufferToBip32Path(buffer: Buffer): string { |
| 103 | +export function bufferToBip32Path(buffer: Buffer): BIP32Path { |
103 | 104 | if (buffer.length % 4 !== 0) {
|
104 | 105 | throw new ResponseError(LedgerError.GenericError, 'The buffer length must be a multiple of 4.')
|
105 | 106 | }
|
|
0 commit comments