Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function toAccountFormat(address) {
/**
* Replace from base16 to (base16, beach32, base58).
*/
const isAddress = validation.isAddress(address);
if (!isAddress) {
throw new Error('input param is not address type');
}
return {
base16: toChecksumAddress(address),
base58: encodeBase58(address),
bech32: toBech32Address(address)
};
}
export default function (hex, format, isTrim=true) {
let address;
try {
if (format === 'Base16') {
address = toChecksumAddress(hex);
} else if (format === 'Base58') {
address = encodeBase58(hex);
} else if (format === 'Bech32') {
address = toBech32Address(hex);
}
} catch(err) {
return null;
}
if (isTrim) {
address = trim(address);
}
return address;
}
setDefaultAccount(account) {
if (!this.isEnable || !account || !this.isConnect) {
return null;
}
const isAddress = validation.isAddress(account.address);
if (!isAddress) {
throw new Error('input param is not address type');
}
this.defaultAccount = {
base16: toChecksumAddress(account.address),
base58: encodeBase58(account.address),
bech32: toBech32Address(account.address)
};
dispatchEvent(onAddressListing);
}