How to use the @zilliqa-js/crypto.toBech32Address function in @zilliqa-js/crypto

To help you get started, we’ve selected a few @zilliqa-js/crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unstoppabledomains / resolution / src / Zns.ts View on Github external
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];
  }
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
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);
  }
github zilpay / zil-pay / src / filters / toAddress.js View on Github external
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;
}
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-account / src / account.ts View on Github external
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);
  }
github zilpay / zil-pay / extension / inpage / utils.js View on Github external
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)
  };
}
github zilpay / zil-pay / packages / inpage / utils.js View on Github external
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)
  }
}
github unstoppabledomains / resolution / src / Zns.ts View on Github external
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);
    }
  }