Skip to content

Commit

Permalink
Throw an error when attempting to derive from a master path from a no…
Browse files Browse the repository at this point in the history
…n-master node (#4551).
  • Loading branch information
ricmoo committed Feb 14, 2024
1 parent eaa0aae commit 82b848e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src.ts/wallet/hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ type HDNodeLike<T> = { depth: number, deriveChild: (i: number) => T };
function derivePath<T extends HDNodeLike<T>>(node: T, path: string): T {
const components = path.split("/");

assertArgument(components.length > 0 && (components[0] === "m" || node.depth > 0), "invalid path", "path", path);
assertArgument(components.length > 0, "invalid path", "path", path);

if (components[0] === "m") { components.shift(); }
if (components[0] === "m") {
assertArgument(node.depth === 0, `cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${ node.depth }`, "path", path);
components.shift();
}

let result: T = node;
for (let i = 0; i < components.length; i++) {
Expand Down

0 comments on commit 82b848e

Please sign in to comment.