1 | import { keyExtractPath } from './extractPath.js';
|
2 | const RE_CAPTURE = /^(\w+( \w+)*)((\/\/?[^/]+)*)(\/\/\/(.*))?$/;
|
3 | /**
|
4 | * @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed).
|
5 | */
|
6 | export function keyExtractSuri(suri) {
|
7 | // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
|
8 | const matches = suri.match(RE_CAPTURE);
|
9 | if (matches === null) {
|
10 | throw new Error('Unable to match provided value to a secret URI');
|
11 | }
|
12 | const [, phrase, , derivePath, , , password] = matches;
|
13 | const { path } = keyExtractPath(derivePath);
|
14 | return {
|
15 | derivePath,
|
16 | password,
|
17 | path,
|
18 | phrase
|
19 | };
|
20 | }
|