Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@zilliqa-js/util
Advanced tools
Utility functions useful in Zilliqa-related programs.
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.
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.
int
: number
- the decimal number to convert.string[]
- hexadecimal array representation of the decimal number.intToByteArray(num: number, size: number): Uint8Array
Converts an integer to a Uint8Array
(i.e., byte array).
num
: number
- the decimal number to convertUint8Array
- byte array, padded to size
.hexToByteArray(hex: string): Uint8Array
Converts a hex-encoded string
to a Uint8Array
. Endianess is not important.
hex
: string
Uint8Array
hexToIntArray(hex: string): number[]
Converts a hex-encoded string to an array of integers.
hex
: string
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.
a
: number
- a 16-bit number.b
: number
- a 16-bit number.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.
a
: string
- hex-encoded string.b
: string
- hex-encoded string.boolean
- true
if the values are equal.isHex(str: string): boolean
Determines if a given string is hex-encoded.
str
: string
.boolean
- true
if the string is hex-encoded.isAddress(address: string): boolean
Determines if a given string is a valid address.
address
: string
.boolean
- true
if the string is an address.isBech32(address: string): boolean
Determines if a given string is a valid Zilliqa bech32 address.
address
: string
.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.
privateKey
: string
.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.
pubKey
: string
.boolean
- true
if the string is a valid public key.isSignature(sig: string): boolean
Determines if a given string is a valid Schnorr signature.
sig
: string
boolean
- true
if the string is a valid signature.isNumber(x: unknown): boolean
Determines if a given value is a valid JS number
.
x
: unknown
boolean
- true
if the string is a valid signature.isBN(x: unknown): boolean
Determines if a given value is an instance of BN.js
.
x
: unknown
boolean
- true
if the value is a BN
instance.isString(x: unknown): boolean
Determines if a given value is a valid JS string
.
x
: unknown
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).
x
: unknown
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
.
x
: unknown
test
: { [key: string]: Validator[] }
boolean
- true
if the value matches test
.fromQa(qa: BN, unit: Units, options: Options)
Converts from qa
(smallest unit) to zil
or li
.
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).
input
: string | number | BN
- the value to convert from.unit
: Units
- the unit to be converted from ('zil' | 'li'
).FAQs
Utilities for working with Zilliqa.
The npm package @zilliqa-js/util receives a total of 1,323 weekly downloads. As such, @zilliqa-js/util popularity was classified as popular.
We found that @zilliqa-js/util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.