Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
domain: string,
): Promise<[string, string] | undefined> {
if (!this.isSupportedDomain(domain) || !this.isSupportedNetwork())
return undefined;
const registryRecord = await this.getContractMapValue(
this.registry,
'records',
namehash(domain),
);
if (!registryRecord) return undefined;
let [ownerAddress, resolverAddress] = registryRecord.arguments as [
string,
string,
];
if (ownerAddress.startsWith('0x')) {
ownerAddress = toBech32Address(ownerAddress);
}
return [ownerAddress, resolverAddress];
}
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);
}
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;
}
constructor(privateKey: string) {
this.privateKey = this.normalizePrivateKey(privateKey);
this.publicKey = zcrypto.getPubKeyFromPrivateKey(this.privateKey);
this.address = zcrypto.getAddressFromPublicKey(this.publicKey);
this.bech32Address = zcrypto.toBech32Address(this.address);
}
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 function toAccountFormat(address) {
const isAddress = validation.isAddress(address)
if (!isAddress) {
throw new Error('input param is not address type')
}
return {
base16: toChecksumAddress(address),
bech32: toBech32Address(address)
}
}
source = this.normalizeSource(source);
this.network = source.network as string;
this.url = source.url;
this.zilliqa = new Zilliqa(this.url);
if (!this.network) {
throw new Error('Unspecified network in Namicorn ZNS configuration');
}
if (!this.url) {
throw new Error('Unspecified url in Namicorn ZNS configuration');
}
this.registryAddress = source.registry
? source.registry
: RegistryMap[this.network];
if (this.registryAddress) {
this.registryAddress = this.registryAddress.startsWith('0x')
? toBech32Address(this.registryAddress)
: this.registryAddress;
this.registry = this.zilliqa.contracts.at(this.registryAddress);
}
}