UNPKG

480 BJavaScriptView Raw
1// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3
4export const HARDENED = 0x80000000;
5export function hdValidatePath(path) {
6 if (!path.startsWith('m/')) {
7 return false;
8 }
9 const parts = path.split('/').slice(1);
10 for (const p of parts) {
11 const n = /^\d+'?$/.test(p) ? parseInt(p.replace(/'$/, ''), 10) : Number.NaN;
12 if (isNaN(n) || n >= HARDENED || n < 0) {
13 return false;
14 }
15 }
16 return true;
17}
\No newline at end of file