1 | import { keyExtractPath } from '../key/index.js';
|
2 | import { sr25519DerivePublic } from '../sr25519/index.js';
|
3 | import { decodeAddress } from './decode.js';
|
4 | import { encodeAddress } from './encode.js';
|
5 | function filterHard({ isHard }) {
|
6 | return isHard;
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export function deriveAddress(who, suri, ss58Format) {
|
15 | const { path } = keyExtractPath(suri);
|
16 | if (!path.length || path.every(filterHard)) {
|
17 | throw new Error('Expected suri to contain a combination of non-hard paths');
|
18 | }
|
19 | let publicKey = decodeAddress(who);
|
20 | for (const { chainCode } of path) {
|
21 | publicKey = sr25519DerivePublic(publicKey, chainCode);
|
22 | }
|
23 | return encodeAddress(publicKey, ss58Format);
|
24 | }
|