UNPKG

649 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { keyHdkdEcdsa } from "./hdkdEcdsa.js";
4import { keyHdkdEd25519 } from "./hdkdEd25519.js";
5import { keyHdkdSr25519 } from "./hdkdSr25519.js";
6const generators = {
7 ecdsa: keyHdkdEcdsa,
8 ed25519: keyHdkdEd25519,
9 // FIXME This is Substrate-compatible, not Ethereum-compatible
10 ethereum: keyHdkdEcdsa,
11 sr25519: keyHdkdSr25519
12};
13export function keyFromPath(pair, path, type) {
14 const keyHdkd = generators[type];
15 let result = pair;
16
17 for (const junction of path) {
18 result = keyHdkd(result, junction);
19 }
20
21 return result;
22}
\No newline at end of file