1 | import { u8aConcat } from '@polkadot/util';
|
2 | import { hasher } from '../secp256k1/hasher.js';
|
3 | import { encodeAddress } from './encode.js';
|
4 | /**
|
5 | * @name evmToAddress
|
6 | * @summary Converts an EVM address to its corresponding SS58 address.
|
7 | */
|
8 | export function evmToAddress(evmAddress, ss58Format, hashType = 'blake2') {
|
9 | const message = u8aConcat('evm:', evmAddress);
|
10 | if (message.length !== 24) {
|
11 | throw new Error(`Converting ${evmAddress}: Invalid evm address length`);
|
12 | }
|
13 | return encodeAddress(hasher(hashType, message), ss58Format);
|
14 | }
|