How to use the @polkadot/util-crypto.xxhashAsHex function in @polkadot/util-crypto

To help you get started, we’ve selected a few @polkadot/util-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 polkadot-js / client / packages / client-wasm / src / create / exports.ts View on Github external
export default async function createExports (bytecode: Uint8Array, imports?: WasmExtraImports, memory?: WebAssembly.Memory | null, forceCreate = false): Promise {
  // FIXME This should be the full hash, however it takes 35-65ms - this is a danger area
  const codeHash = xxhashAsHex(bytecode.subarray(0, 2048));
  const lookup = `${codeHash}_${bytecode.length}`;
  let instance = cache.get(lookup);
  const isNewHash = !instance;

  // NOTE compilation is quite resource intensive, here we bypass the actual Uint8Array -> Module compilation when we already have this module bytecode in our cache
  if (!instance || forceCreate) {
    const table = new WebAssembly.Table(DEFAULT_TABLE);

    const wasm = await WebAssembly.instantiate(
      bytecode,
      createImports(memory, table, imports)
    );

    instance = wasm.instance;
    cache.set(lookup, instance);
  }
github polkadot-js / ui / packages / react-qr / src / Display.tsx View on Github external
public static getDerivedStateFromProps ({ value, skipEncoding = false }: Props, prevState: State): Pick | null {
    const valueHash = xxhashAsHex(value);

    if (valueHash === prevState.valueHash) {
      return null;
    }

    const frames: Uint8Array[] = skipEncoding
      ? [value]
      : createFrames(value);

    // encode on demand
    return {
      frames,
      frameIdx: 0,
      image: getDataUrl(frames[0]),
      valueHash
    };
github polkadot-js / apps / packages / react-query / src / Events.tsx View on Github external
api.query.system.events((records: EventRecord[] & Codec): void => {
        const newEvents = records
          .filter(({ event }): boolean => event.section !== 'system')
          .map((record, index): KeyedEvent => ({ key: `${Date.now()}-${index}`, record }));
        const newEventHash = xxhashAsHex(stringToU8a(JSON.stringify(newEvents)));

        if (newEventHash !== prevEventHash) {
          events = [...newEvents, ...events].slice(0, MAX_EVENTS);
          setState(events);
        }
      });
    });
github polkadot-js / apps / packages / app-explorer / src / EventsRecent.tsx View on Github external
static getDerivedStateFromProps ({ system_events = [] }: Props, prevState: State): State | null {
    const prevEventHash = xxhashAsHex(stringToU8a(JSON.stringify(system_events)));

    if (prevEventHash === prevState.prevEventHash) {
      return null;
    }

    const recentEvents = system_events
      .filter(({ event }) => event.section !== 'system')
      .concat(prevState.recentEvents)
      .filter((_, index) => index < MAX_ITEMS);

    return {
      prevEventHash,
      recentEvents
    };
  }
github dappforce / dappforce-subsocial-ui / src / components / main / Status.tsx View on Github external
componentDidUpdate ({ optionsAll = { account: [] as any } as KeyringOptions, queueAction, system_events, t }: Props) {
    const eventHash = xxhashAsHex(stringToU8a(JSON.stringify(system_events || [])));

    if (eventHash === prevEventHash) {
      return;
    }

    prevEventHash = eventHash;

    const addresses = optionsAll.account.map((account) => account.value);

    (system_events || []).forEach(({ event: { data, method, section } }) => {
      if (section === 'balances' && method === 'Transfer') {
        const account = data[1].toString();

        if (addresses.includes(account)) {
          queueAction({
            account,
github polkadot-js / ui / packages / react-qr / src / DisplayAddress.tsx View on Github external
public static getDerivedStateFromProps ({ address, genesisHash }: Props, prevState: State): State | null {
    const data = createAddressPayload(address, genesisHash);
    const dataHash = xxhashAsHex(data);

    if (dataHash === prevState.dataHash) {
      return null;
    }

    return { data, dataHash };
  }
github polkadot-js / apps / packages / apps / src / Content / Status.tsx View on Github external
useEffect((): void => {
    const eventHash = xxhashAsHex(stringToU8a(JSON.stringify(events)));

    if (!optionsAll || eventHash === prevEventHash) {
      return;
    }

    prevEventHash = eventHash;

    const statusses = events && events
      .map(({ event: { data, method, section } }): ActionStatus | null => {
        if (section === 'balances' && method === 'Transfer') {
          const account = data[1].toString();

          if (allAccounts.includes(account)) {
            return {
              account,
              action: `${section}.${method}`,
github polkadot-js / ui / packages / react-qr / src / DisplayPayload.tsx View on Github external
public static getDerivedStateFromProps ({ address, cmd, payload }: Props, prevState: State): State | null {
    const data = createSignPayload(address, cmd, payload);
    const dataHash = xxhashAsHex(data);

    if (dataHash === prevState.dataHash) {
      return null;
    }

    return { data, dataHash };
  }