Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@1inch/byte-utils

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@1inch/byte-utils

Contains helpers to work with bytes

  • 2.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
389
decreased by-47.72%
Maintainers
0
Weekly downloads
 
Created
Source

@1inch/byte-utils

Contains helpers to work with bytes

Installation

npm install @1inch/byte-utils

Docs

:toolbox: Functions

  • isHexString
  • isHexBytes

:gear: isHexString

Check that string starts with 0x and has only valid hex symbols

FunctionType
isHexString(val: string) => boolean

:gear: isHexBytes

Check that string is valid hex with 0x prefix and length is even

FunctionType
isHexBytes(val: string) => boolean

:wrench: Constants

:gear: UINT_8_MAX

ConstantType
UINT_8_MAXbigint

:gear: UINT_24_MAX

ConstantType
UINT_24_MAXbigint

:gear: UINT_32_MAX

ConstantType
UINT_32_MAXbigint

:gear: UINT_40_MAX

ConstantType
UINT_40_MAXbigint

:gear: UINT_48_MAX

ConstantType
UINT_48_MAXbigint

:gear: UINT_80_MAX

ConstantType
UINT_80_MAXbigint

:gear: UINT_160_MAX

ConstantType
UINT_160_MAXbigint

:gear: UINT_128_MAX

ConstantType
UINT_128_MAXbigint

:gear: UINT_256_MAX

ConstantType
UINT_256_MAXbigint

:factory: BitMask

Class to define bit mask: new BitMask(16, 32) is for bits from [16, 32) => 0xffff0000

Methods

:gear: toString
MethodType
toString() => string
:gear: toBigInt
MethodType
toBigInt() => bigint

:factory: BN

Class to work with bits in bignumber Immutable, all methods return new value

Methods

:gear: fromNumber
MethodType
fromNumber(n: number) => BN
:gear: fromHex
MethodType
fromHex(hex: string) => BN
:gear: add

Add value

MethodType
add(other: BN) => BN
:gear: sub

Subtract value

MethodType
sub(other: BN) => BN
:gear: setBit
MethodType
setBit(n: bigint, value: 0 or 1) => BN
:gear: getBit
MethodType
getBit(n: bigint) => 0 or 1
:gear: shiftLeft
MethodType
shiftLeft(n: bigint) => BN
:gear: shiftRight
MethodType
shiftRight(n: bigint) => BN
:gear: and
MethodType
and(other: bigint or BN) => BN
:gear: or
MethodType
or(other: bigint or BN) => BN
:gear: xor
MethodType
xor(other: bigint or BN) => BN
:gear: isZero
MethodType
isZero() => boolean
:gear: isOne
MethodType
isOne() => boolean
:gear: getMask

Return bits defined in mask as BN

MethodType
getMask(mask: BitMask) => BN
:gear: setMask

Set bits defined in mask to value if value is bigger than mask then error will be thrown

MethodType
setMask(mask: BitMask, value: bigint or BN) => BN
:gear: clearMask

Set bits defined in mask to 0s

MethodType
clearMask(mask: BitMask) => BN
:gear: toHex

Return 0x prefixed string with hex representation of BN, padded with '0s' if padNum specified

MethodType
toHex(padNum?: number) => string
:gear: toNumber

Convert BN to Number

Caution: value will be rounded for numbers > Number.MAX_SAFE_INTEGER

MethodType
toNumber() => number

:factory: BytesIter

Class to iterate through bytes string by parsing individual bytes

Methods

:gear: BigInt
MethodType
BigInt(bytes: string) => BytesIter<bigint>
:gear: String
MethodType
String(bytes: string) => BytesIter<string>
:gear: rest

Returns all not consumed bytes

MethodType
rest() => T
:gear: isEmpty
MethodType
isEmpty() => boolean
:gear: nextByte
MethodType
nextByte(side?: Side) => T
:gear: nextBytes
MethodType
nextBytes(n: number, side?: Side) => T
:gear: nextAddress
MethodType
nextAddress(side?: Side) => T
:gear: nextUint8
MethodType
nextUint8(side?: Side) => T
:gear: nextUint16
MethodType
nextUint16(side?: Side) => T
:gear: nextUint24
MethodType
nextUint24(side?: Side) => T
:gear: nextUint32
MethodType
nextUint32(side?: Side) => T
:gear: nextUint128
MethodType
nextUint128(side?: Side) => T
:gear: nextUint160
MethodType
nextUint160(side?: Side) => T
:gear: nextUint256
MethodType
nextUint256(side?: Side) => T

:factory: BytesBuilder

Helper class to build an arbitrary bytes sequence

Methods

:gear: addAddress
MethodType
addAddress(address: string or bigint or BN) => this
:gear: addBytes
MethodType
addBytes(bytes: string) => this
:gear: addByte
MethodType
addByte(byte: string or bigint or BN) => this
:gear: addUint8
MethodType
addUint8(val: string or bigint or BN) => this
:gear: addUint16
MethodType
addUint16(val: string or bigint or BN) => this
:gear: addUint24
MethodType
addUint24(val: string or bigint or BN) => this
:gear: addUint32
MethodType
addUint32(val: string or bigint or BN) => this
:gear: addUint64
MethodType
addUint64(val: string or bigint or BN) => this
:gear: addUint128
MethodType
addUint128(val: string or bigint or BN) => this
:gear: addUint160
MethodType
addUint160(val: string or bigint or BN) => this
:gear: addUint256
MethodType
addUint256(val: string or bigint or BN) => this
:gear: asBigInt

Returns bytes as single bigint value

MethodType
asBigInt() => bigint
:gear: asHex

Returns hex string

MethodType
asHex(prefixed?: boolean) => string

Parameters:

  • prefixed: should be string prefixed with 0x or not, true by default

FAQs

Package last updated on 31 Jul 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc