// Copyright 2017-2021 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Prefix } from '@polkadot/util-crypto/address/types';
import Vue from 'vue';
import { isHex, isU8a, u8aToHex } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
import { Beachball, Empty, Jdenticon, Polkadot } from './icons';
interface Account {
address: string;
publicKey: string;
}
interface Data {
address: string;
iconSize: number;
publicKey: string;
type: 'beachball' | 'empty' | 'jdenticon' | 'polkadot' | 'substrate';
}
const DEFAULT_SIZE = 64;
function encodeAccount (value: string | Uint8Array, prefix?: Prefix): Account {
try {
const address = isU8a(value) || isHex(value)
? encodeAddress(value as string, prefix)
: value;
const publicKey = u8aToHex(decodeAddress(address, false, prefix));
return { address, publicKey };
} catch (error) {
return { address: '', publicKey: '0x' };
}
}
/**
* @name Identicon
* @description The main Identicon component, taking a number of properties
* @example
* ```html
*