Files
common/packages/util-crypto/src/address/encodeDerived.ts
T
2022-01-01 09:26:11 +02:00

21 lines
820 B
TypeScript

// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import type { Prefix } from './types';
import { decodeAddress } from './decode';
import { encodeAddress } from './encode';
import { createKeyDerived } from './keyDerived';
/**
* @name encodeDerivedAddress
* @summary Creates a derived address as used in Substrate utility.
* @description
* Creates a Substrate derived address based on the input address/publicKey and the index supplied.
*/
export function encodeDerivedAddress (who: HexString | Uint8Array | string, index: bigint | BN | number, ss58Format?: Prefix): string {
return encodeAddress(createKeyDerived(decodeAddress(who), index), ss58Format);
}