Skip to main content

Class: Bytes

Defined in: core-sdk/src/bytes/bytes.ts:17

Base wrapper around a byte array, accepting a Uint8Array, ArrayBuffer, hex string, or another Bytes instance, with an optional length check.

Extended by​

Constructors​

Constructor​

new Bytes(bytes, byteLength?): Bytes

Defined in: core-sdk/src/bytes/bytes.ts:25

Parameters​

bytes​

string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Bytes

byteLength?​

If given, throws unless the resulting length matches (or, for an array, is one of) the expected length(s).

number | number[]

Returns​

Bytes

Properties​

length​

readonly length: number

Defined in: core-sdk/src/bytes/bytes.ts:19

Methods​

equals()​

equals(other): boolean

Defined in: core-sdk/src/bytes/bytes.ts:166

Byte-wise equality against another Bytes instance, raw bytes, or hex string.

Parameters​

other​

string | Uint8Array<ArrayBufferLike> | Bytes

Returns​

boolean


offset()​

offset(index): Uint8Array

Defined in: core-sdk/src/bytes/bytes.ts:110

Returns a copy of the bytes from index to the end.

Parameters​

index​

number

Returns​

Uint8Array


represent()​

represent(): string

Defined in: core-sdk/src/bytes/bytes.ts:173

Human-readable representation, used by debuggers/loggers. Same as toHex.

Returns​

string


toBase32()​

toBase32(): string

Defined in: core-sdk/src/bytes/bytes.ts:138

Encodes as a padded base32 string.

Returns​

string


toBase64()​

toBase64(): string

Defined in: core-sdk/src/bytes/bytes.ts:131

Encodes as a padded base64 string.

Returns​

string


toHex()​

toHex(): string

Defined in: core-sdk/src/bytes/bytes.ts:124

Encodes as a lowercase hex string, with no 0x prefix.

Returns​

string


toJSON()​

toJSON(): unknown

Defined in: core-sdk/src/bytes/bytes.ts:159

Decodes the bytes as UTF-8 JSON.

Returns​

unknown


toString()​

toString(): string

Defined in: core-sdk/src/bytes/bytes.ts:145

Same as toHex.

Returns​

string


toUint8Array()​

toUint8Array(): Uint8Array

Defined in: core-sdk/src/bytes/bytes.ts:117

Returns a copy of the underlying bytes.

Returns​

Uint8Array


toUtf8()​

toUtf8(): string

Defined in: core-sdk/src/bytes/bytes.ts:152

Decodes the bytes as UTF-8 text.

Returns​

string


concat()​

static concat(...arrays): Uint8Array

Defined in: core-sdk/src/bytes/bytes.ts:75

Concatenates any number of byte arrays (or Bytes instances) into one new array.

Parameters​

arrays​

...(Uint8Array<ArrayBufferLike> | Bytes)[]

Returns​

Uint8Array


fromSlice()​

static fromSlice(bytes, start, length?): Bytes

Defined in: core-sdk/src/bytes/bytes.ts:100

Wraps a slice of bytes starting at start, running to the end unless length is given.

Parameters​

bytes​

Uint8Array

start​

number

length?​

number

Returns​

Bytes


fromUtf8()​

static fromUtf8(utf8): Bytes

Defined in: core-sdk/src/bytes/bytes.ts:92

Wraps the UTF-8 encoding of a string.

Parameters​

utf8​

string

Returns​

Bytes


keccak256()​

static keccak256(bytes): Bytes

Defined in: core-sdk/src/bytes/bytes.ts:68

Hashes bytes with keccak256 and wraps the 32-byte digest.

Parameters​

bytes​

string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Bytes

Returns​

Bytes

💬 Get Help