Skip to content

Commit

Permalink
Add compatibility layer for H160 addresses (#789)
Browse files Browse the repository at this point in the history
* ⚡ compatibilty layer for H160 addresses

* :broom linter

* 🧼 space before (
  • Loading branch information
vikiival authored Apr 17, 2024
1 parent c77e8d3 commit a694afc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/vue-identicon/src/Identicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 };
Expand Down

0 comments on commit a694afc

Please sign in to comment.