npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zilliqa-js/util

v3.5.0

Published

Utilities for working with Zilliqa.

Downloads

16,476

Readme

@zilliqa-js/util

Utility functions useful in Zilliqa-related programs.

Classes

BN

See documentation at bn.js. This is simply a re-export of that library to prevent bloating other @zilliqa-js packages, most of which depend on bn.js in small ways.

Long

See documentation at long.js. This is simply a re-export for similar reasons. Note that long is only required if you need to serialise integers with size greater than or equal to 2^53.

PRESETS

Commonly used variables such as DEVNET_URL. See source for more info.

Functions

intToHexArray(int: number, size: number): string[]

Converts an integer to an array of hexadecimal strings (little endian). Size is the total length of bytes to pad to.

Parameters

  • int: number - the decimal number to convert.

Returns

  • string[] - hexadecimal array representation of the decimal number.

intToByteArray(num: number, size: number): Uint8Array

Converts an integer to a Uint8Array (i.e., byte array).

Parameters

  • num: number - the decimal number to convert

Returns

  • Uint8Array - byte array, padded to size.

hexToByteArray(hex: string): Uint8Array

Converts a hex-encoded string to a Uint8Array. Endianess is not important.

Parameters

  • hex: string

Returns

  • Uint8Array

hexToIntArray(hex: string): number[]

Converts a hex-encoded string to an array of integers.

Parameters

  • hex: string

Returns

  • number[]

pack(a: number, b: number): number

Performs bitwise addition of two 16-bit numbers, returning a 32-bit number. Throws if either number exceeds 16 bits.

Parameters

  • a: number - a 16-bit number.
  • b: number - a 16-bit number.

Returns

  • number - the combined 32-bit number.

compareBytes(a: string, b: string): boolean

Performs a constant time comparison of two hexadecimal values. This avoids timing attacks.

Parameters

  • a: string - hex-encoded string.
  • b: string - hex-encoded string.

Returns

  • boolean - true if the values are equal.

isHex(str: string): boolean

Determines if a given string is hex-encoded.

Parameters

  • str: string.

Returns

  • boolean - true if the string is hex-encoded.

isAddress(address: string): boolean

Determines if a given string is a valid address.

Parameters

  • address: string.

Returns

  • boolean - true if the string is an address.

isBech32(address: string): boolean

Determines if a given string is a valid Zilliqa bech32 address.

Parameters

  • address: string.

Returns

  • boolean - true if the string is a valid Zilliqa bech32 address.

isPrivateKey(privateKey: string): boolean

Determines if a given string is a valid private key.

Parameters

  • privateKey: string.

Returns

  • boolean - true if the string is a valid private key.

isPubKey(pubKey: string): boolean

Determines if a given string is a valid uncompressed public key.

Parameters

  • pubKey: string.

Returns

  • boolean - true if the string is a valid public key.

isSignature(sig: string): boolean

Determines if a given string is a valid Schnorr signature.

Parameters

  • sig: string

Returns

  • boolean - true if the string is a valid signature.

isNumber(x: unknown): boolean

Determines if a given value is a valid JS number.

Parameters

  • x: unknown

Returns

  • boolean - true if the string is a valid signature.

isBN(x: unknown): boolean

Determines if a given value is an instance of BN.js.

Parameters

  • x: unknown

Returns

  • boolean - true if the value is a BN instance.

isString(x: unknown): boolean

Determines if a given value is a valid JS string.

Parameters

  • x: unknown

Returns

  • boolean - true if the value is a string.

isPlainObject(x: unknown): boolean

Determines if a given value is a plain JS object (i.e. directly below Object in the prototype chain).

Parameters

  • x: unknown

Returns

  • boolean - true if the value is a plain object.

matchesObject(x: unknown, test: { [key: string]: Validator[] }): boolean

Determines if a value has the shape specified by test.

Parameters

  • x: unknown
  • test: { [key: string]: Validator[] }

Returns

  • boolean - true if the value matches test.

fromQa(qa: BN, unit: Units, options: Options)

Converts from qa (smallest unit) to zil or li.

Parameters

  • qa: BN - the value to convert from.
  • unit: Units - the unit to be converted to ('zil' | 'qa').
  • options: Options - an object specifying options.

toQa(input: string | number | BN, unit: Units)

Converts zil or li to qa (smallest unit).

Parameters

  • input: string | number | BN - the value to convert from.
  • unit: Units - the unit to be converted from ('zil' | 'li').