@polkadot/util#u8aEq TypeScript Examples

The following examples show how to use @polkadot/util#u8aEq. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Signer.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
/**
   *
   * @returns The default EVM address generated for the signer's substrate address
   */
  computeDefaultEvmAddress(): string {
    const address = this._substrateAddress;
    const publicKey = decodeAddress(address);

    const isStartWithEvm = u8aEq('evm:', publicKey.slice(0, 4));

    if (isStartWithEvm) {
      return getAddress(u8aToHex(publicKey.slice(4, 24)));
    }

    return getAddress(u8aToHex(blake2AsU8a(u8aConcat('evm:', publicKey), 256).slice(0, 20)));
  }
Example #2
Source File: address.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
computeDefaultEvmAddress = (substrateAddress: HexString | string | Uint8Array): string => {
  if (!isSubstrateAddress) {
    return logger.throwArgumentError('invalid substrate address', 'address', substrateAddress);
  }

  const publicKey = decodeAddress(substrateAddress);

  const isStartWithEvm = u8aEq('evm:', publicKey.slice(0, 4));

  if (isStartWithEvm) {
    return getAddress(u8aToHex(publicKey.slice(4, 24)));
  }

  return getAddress(u8aToHex(blake2AsU8a(u8aConcat('evm:', publicKey), 256).slice(0, 20)));
}
Example #3
Source File: bundle.ts    From phishing with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if a host is in our deny list. Returns a string containing the phishing site if host is a
 * problematic one. Returns null if the address is not associated with phishing.
 */
export async function checkAddress (address: string | Uint8Array, allowCached = true): Promise<string | null> {
  try {
    const u8a = decodeAddress(address);
    const all = await retrieveAddrU8a(allowCached);
    const entry = all.find(([, all]) => all.some((a) => u8aEq(a, u8a))) || [null];

    return entry[0];
  } catch (error) {
    log(error, 'address');

    return null;
  }
}
Example #4
Source File: parachain.ts    From sdk with Apache License 2.0 6 votes vote down vote up
function _extractWinners (ranges: [number, number][], auctionInfo: any, optData: any): any[] {
  return optData.isNone
    ? []
    : optData.unwrap().reduce((winners, optEntry, index): any[] => {
      if (optEntry.isSome) {
        const [accountId, paraId, value] = optEntry.unwrap();
        const period = auctionInfo.leasePeriod || BN_ZERO;
        const [first, last] = ranges[index];

        winners.push({
          accountId: accountId.toString(),
          firstSlot: period.addn(first).toNumber(),
          isCrowdloan: u8aEq(CROWD_PREFIX, accountId.subarray(0, CROWD_PREFIX.length)),
          lastSlot: period.addn(last).toNumber(),
          paraId: paraId.toString(),
          value
        });
      }

      return winners;
    }, []);
}
Example #5
Source File: Signer.ts    From evm-provider.js with Apache License 2.0 6 votes vote down vote up
/**
   *
   * @returns The default EVM address generated for the signer's substrate address
   */
  computeDefaultEvmAddress(): string {
    const address = this._substrateAddress;
    const publicKey = decodeAddress(address);

    const isStartWithEvm = u8aEq('evm:', publicKey.slice(0, 4));

    if (isStartWithEvm) {
      return getAddress(u8aToHex(publicKey.slice(4, 24)));
    }

    return getAddress(
      u8aToHex(blake2AsU8a(u8aConcat('evm:', publicKey), 256).slice(0, 20))
    );
  }