From a694afc24063970f7ce90fd661e18d1f2d73b71b Mon Sep 17 00:00:00 2001 From: Viki Val Date: Wed, 17 Apr 2024 19:01:24 +0200 Subject: [PATCH] Add compatibility layer for H160 addresses (#789) * :zap: compatibilty layer for H160 addresses * :broom linter * :soap: space before ( --- packages/vue-identicon/src/Identicon.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/vue-identicon/src/Identicon.ts b/packages/vue-identicon/src/Identicon.ts index 7c1fcb27..b256ca9a 100644 --- a/packages/vue-identicon/src/Identicon.ts +++ b/packages/vue-identicon/src/Identicon.ts @@ -7,7 +7,7 @@ import type { Prefix } from '@polkadot/util-crypto/address/types'; import { defineComponent, h } from 'vue'; import { isHex, isU8a, u8aToHex } from '@polkadot/util'; -import { decodeAddress, encodeAddress } from '@polkadot/util-crypto'; +import { decodeAddress, encodeAddress, isEthereumAddress } from '@polkadot/util-crypto'; import { Beachball, Empty, Jdenticon, Polkadot } from './icons/index.js'; import { adaptVNodeAttrs } from './util.js'; @@ -27,11 +27,19 @@ interface Data { const DEFAULT_SIZE = 64; +function resolvePublicKey (value: string | Uint8Array, prefix?: Prefix): string { + if (isHex(value) && isEthereumAddress(value)) { + return value.padEnd(66, '0'); + } + + return isU8a(value) || isHex(value) + ? encodeAddress(value as string, prefix) + : value; +} + export function encodeAccount (value: string | Uint8Array, prefix?: Prefix): Account { try { - const address = isU8a(value) || isHex(value) - ? encodeAddress(value as string, prefix) - : value; + const address = resolvePublicKey(value, prefix); const publicKey = u8aToHex(decodeAddress(address, false, prefix)); return { address, publicKey };