How to use the @polkadot/util.hexToU8a function in @polkadot/util

To help you get started, we’ve selected a few @polkadot/util 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 vue-polkadot / vue-ui / packages / vue-keyring / src / Keyring.ts View on Github external
private loadAddress(json: KeyringJson, key: string): void {
    const { isRecent, whenCreated = 0 } = json.meta;

    if (isRecent && (Date.now() - whenCreated) > RECENT_EXPIRY) {
      this._store.remove(key);
      return;
    }

    const address = this.encodeAddress(
      isHex(json.address)
        ? hexToU8a(json.address)
        // FIXME Just for the transition period (ignoreChecksum)
        : this.decodeAddress(json.address, true)
    );
    const [, hexAddr] = key.split(':');

    this.addresses.add(this._store, address, json);
    this.rewriteKey(json, key, hexAddr, addressKey);
  }
github polkadot-js / ui / packages / ui-keyring / src / Keyring.ts View on Github external
private loadAddress (json: KeyringJson, key: string): void {
    const { isRecent, whenCreated = 0 } = json.meta;

    if (isRecent && (Date.now() - whenCreated) > RECENT_EXPIRY) {
      this._store.remove(key);
      return;
    }

    const address = this.encodeAddress(
      isHex(json.address)
        ? hexToU8a(json.address)
        // FIXME Just for the transition period (ignoreChecksum)
        : this.decodeAddress(json.address, true)
    );
    const [, hexAddr] = key.split(':');

    this.addresses.add(this._store, address, json);
    this.rewriteKey(json, key, hexAddr, addressKey);
  }
github polkadot-js / api / packages / types / src / codec / Enum.ts View on Github external
function decodeFromString (registry: Registry, def: TypesDef, value: string): Decoded {
  return isHex(value)
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    ? decodeFromValue(registry, def, hexToU8a(value))
    : decodeFromJSON(registry, def, value);
}
github polkadot-js / common / packages / keyring / src / testing.ts View on Github external
secretKey: hexToU8a('0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325'),
    publicKey: hexToU8a('0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48')
  },
  {
    seed: 'Bob//stash',
    secretKey: hexToU8a('0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde'),
    publicKey: hexToU8a('0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e')
  },
  {
    seed: 'Charlie',
    secretKey: hexToU8a('0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c'),
    publicKey: hexToU8a('0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22')
  },
  {
    seed: 'Dave',
    secretKey: hexToU8a('0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568'),
    publicKey: hexToU8a('0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20')
  },
  {
    seed: 'Eve',
    secretKey: hexToU8a('0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587'),
    publicKey: hexToU8a('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e')
  },
  {
    seed: 'Ferdie',
    secretKey: hexToU8a('0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426'),
    publicKey: hexToU8a('0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c')
  }
];

/**
 * @name testKeyring
github polkadot-js / common / packages / util-crypto / src / keccak / asU8a.spec.ts View on Github external
describe('keccakAsU8a', (): void => {
  beforeEach(async (): Promise => {
    await waitReady();
  });

  const input = 'test value';
  const output = hexToU8a(
    '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e'
  );

  it('returns an hex representation (string)', (): void => {
    expect(
      keccakAsU8a(input)
    ).toEqual(output);
  });

  it('returns an hex representation (Buffer)', (): void => {
    expect(
      keccakAsU8a(
        Buffer.from(input)
      )
    ).toEqual(output);
  });
github polkadot-js / api / packages / metadata / src / Decorated / Decorated.spec.ts View on Github external
it('should correctly get Alice\'s freeBalance storage key (u8a)', (): void => {
    expect(
      decorated.query
        .balances
        .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
    ).toEqual(
      hexToU8a(
        '0x0101c2261276cc9d1f8598ea4b6a74b15c2f6482b9ade7bc6657aaca787ba1add3b42e3fb4c297a84c5cebc0e78257d213d0927ccc7596044c6ba013dd05522aacba'
      )
    );
  });
github polkadot-js / client / packages / client-db / src / engines / FileStructDb / index.spec.ts View on Github external
Object.entries(raw).forEach(([key, val]): void => {
          trie.put(hexToU8a(key), hexToU8a(val));
        });
github polkadot-js / common / packages / util-crypto / src / mnemonic / toEntropy.ts View on Github external
export default function toEntropy (mnemonic: string): Uint8Array {
  return isReady()
    ? bip39ToEntropy(mnemonic)
    : hexToU8a(
      hexAddPrefix(
        mnemonicToEntropy(mnemonic)
      )
    );
}
github polkadot-js / common / packages / util-rlp / src / encoder / toU8a.ts View on Github external
function convertString (value: string): Uint8Array {
  if (hexHasPrefix(value)) {
    return hexToU8a(value);
  }

  return stringToU8a(value);
}
github polkadot-js / client / packages / client-db / src / state / balance.spec.js View on Github external
get: (key) => {
          switch (u8aToHex(key)) {
            case '0x93b3a06afc9ac6777adff1f6ad2cd5d9':
              return hexToU8a('0x4500000000000000');

            case '0x8e4b46d94b25bb2f5c9fa65f60263160':
              return hexToU8a('0x2a00000000000000');

            default:
              return new Uint8Array([]);
          }
        }
      }).staking;