How to use the @polkadot/util/u8a/toHex 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 polkadot-js / apps / packages / ui-signer / src / sign.ts View on Github external
export default function signMessage (publicKey: Uint8Array, nonce: BN | number, value: Uint8Array, apiSupport: EncodingVersions): Signed {
  const message = encodeCall(publicKey, nonce, value, apiSupport);
  const signature = keyring.getPair(publicKey).sign(message);
  const data = u8aConcat(
    prefixes.publicKey,
    message,
    signature
  );

  console.log(`signMessage (${apiSupport}) :   message :: ${u8aToHex(message)}`);
  console.log(`signMessage (${apiSupport}) : signature :: ${u8aToHex(signature)}`);
  console.log(`signMessage (${apiSupport}) :      data :: ${u8aToHex(data)}`);

  return {
    data: u8aConcat(
      bnToU8a(data.length, 32, true),
      data
    ),
    message,
    signature
  };
}
github polkadot-js / apps / packages / app-extrinsics / src / Signer / submit.js View on Github external
export default function submit (api: RxApiInterface, { nonce, publicKey, value }: QueueTx): Promise {
  const message = encodeCall(publicKey, nonce, value);
  const signature = keyring.getPair(publicKey).sign(message);

  console.log('submitExtrinsic: message =', u8aToHex(message));
  console.log('submitExtrinsic: signature =', u8aToHex(signature));

  return api.author
    .submitExtrinsic(u8aConcat(message, signature))
    .toPromise()
    .then((result) => {
      console.log('submitExtrinsic: result=', result);

      return 'sent';
    })
    .catch((error) => {
      console.error('submitExtrinsic: error=', error);

      return 'error';
    });
}
github polkadot-js / api / packages / types / src / Extrinsic.ts View on Github external
toHex (): string {
    return u8aToHex(this.toU8a());
  }
github polkadot-js / common / packages / trie-db-old / src / BaseTrie.ts View on Github external
    l.debug(() => ['put', 'key ->', u8aToHex(key), 'value ->', u8aToHex(value, 256)]);
github polkadot-js / common / packages / trie-db-old / src / Node.ts View on Github external
const format = (value: any): string => {
      if (isU8a(value)) {
        return u8aToHex(value);
      } else if (Array.isArray(value)) {
        return `[${value.map((v) => format(v))}]`;
      } else if (value) {
        return 'object';
      }

      return 'empty';
    };
github polkadot-js / api / packages / api-format / src / format.ts View on Github external
function formatSingleType (formatters: FormattersFunctionMap, type: Param$Types, value: any): any {
  if (type === 'StorageKey') {
    const [key, ...params]: [SectionItem, Array] = value;

    return u8aToHex(
      createStorageKey(key).apply(null, params)
    );
  }

  const formatter = formatters.get(type);

  if (isUndefined(formatter)) {
    l.debug(() => `Unable to find default formatter for '${typeToString(type)}', falling back to echo`);

    return echo(value);
  }

  try {
    return formatter(value);
  } catch (error) {
    throw new Error(`Error formatting '${value.toString()}' as '${typeToString(type)}': ${error.message}`);
github polkadot-js / client / packages / client-p2p / src / peer / send.ts View on Github external
    l.debug(() => `sending ${u8aToHex(encoded)} <= ${utf8}`);