1 |
|
2 |
|
3 | import { assert } from '@polkadot/util';
|
4 | import { keyExtractPath } from "../key/index.js";
|
5 | import { sr25519DerivePublic } from "../sr25519/index.js";
|
6 | import { decodeAddress } from "./decode.js";
|
7 | import { encodeAddress } from "./encode.js";
|
8 |
|
9 | function filterHard({
|
10 | isHard
|
11 | }) {
|
12 | return isHard;
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export function deriveAddress(who, suri, ss58Format) {
|
23 | const {
|
24 | path
|
25 | } = keyExtractPath(suri);
|
26 | assert(path.length && !path.every(filterHard), 'Expected suri to contain a combination of non-hard paths');
|
27 | let publicKey = decodeAddress(who);
|
28 |
|
29 | for (const {
|
30 | chainCode
|
31 | } of path) {
|
32 | publicKey = sr25519DerivePublic(publicKey, chainCode);
|
33 | }
|
34 |
|
35 | return encodeAddress(publicKey, ss58Format);
|
36 | } |
\ | No newline at end of file |