Skip to content

Documentation / @cashconnect-js/core / primitives/hasher

Hasher

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:17

Represents a hash primitive that provides various cryptographic hashing capabilities. This class handles conversions between different formats (bytes, hex, UTF-8) and supports multiple hashing algorithms (SHA256, RIPEMD160, Hash160, Hash256).

Constructors

Constructor

ts
new Hasher(bytes): Hasher;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:22

Creates a new Hash instance.

Parameters
ParameterTypeDescription
bytesUint8ArrayThe byte array representation of the data to be hashed
Returns

Hasher

Methods

fromBytes()

ts
static fromBytes(bytes): Hasher;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:29

Creates a Hash instance from a byte array.

Parameters
ParameterTypeDescription
bytesUint8ArrayThe byte array to create the hash from
Returns

Hasher

A new Hash instance containing the provided bytes

fromBase64()

ts
static fromBase64(base64): Hasher;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:39

Creates a Hash instance from a Base64 string.

Parameters
ParameterTypeDescription
base64stringThe Base64 string to create the hash from
Returns

Hasher

A new Hash instance containing the bytes converted from the Base64 string

Throws

If the provided string is not valid Base64

fromHex()

ts
static fromHex(hex): Hasher;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:54

Creates a Hash instance from a hexadecimal string.

Parameters
ParameterTypeDescription
hexstringThe hexadecimal string to create the hash from
Returns

Hasher

A new Hash instance containing the bytes converted from the hex string

Throws

If the provided string is not valid hexadecimal

fromUTF8()

ts
static fromUTF8(utf8): Hasher;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:68

Creates a Hash instance from a UTF-8 string.

Parameters
ParameterTypeDescription
utf8stringThe UTF-8 string to create the hash from
Returns

Hasher

A new Hash instance containing the bytes converted from the UTF-8 string

toSHA256Bytes()

ts
toSHA256Bytes(): Uint8Array;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:76

Computes the SHA256 hash of the stored bytes.

Returns

Uint8Array

A Uint8Array containing the SHA256 hash

toSHA256Hex()

ts
toSHA256Hex(): string;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:84

Computes the SHA256 hash of the stored bytes and returns it as a hexadecimal string.

Returns

string

The SHA256 hash as a hexadecimal string

toRIPEMD160Bytes()

ts
toRIPEMD160Bytes(): Uint8Array;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:92

Computes the RIPEMD160 hash of the stored bytes.

Returns

Uint8Array

A Uint8Array containing the RIPEMD160 hash

toRIPEMD160Hex()

ts
toRIPEMD160Hex(): string;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:100

Computes the RIPEMD160 hash of the stored bytes and returns it as a hexadecimal string.

Returns

string

The RIPEMD160 hash as a hexadecimal string

toHash160Bytes()

ts
toHash160Bytes(): Uint8Array;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:109

Computes the Hash160 (RIPEMD160(SHA256(x))) of the stored bytes. This is commonly used in cryptocurrency addresses.

Returns

Uint8Array

A Uint8Array containing the Hash160 value

toHash160Hex()

ts
toHash160Hex(): string;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:117

Computes the Hash160 (RIPEMD160(SHA256(x))) of the stored bytes and returns it as a hexadecimal string.

Returns

string

The Hash160 value as a hexadecimal string

toHash256Bytes()

ts
toHash256Bytes(): Uint8Array;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:126

Computes the Hash256 (SHA256(SHA256(x))) of the stored bytes. This is commonly used for computing block hashes in Bitcoin.

Returns

Uint8Array

A Uint8Array containing the Hash256 value

toHash256Hex()

ts
toHash256Hex(): string;

Defined in: cashconnect-js/packages/core/src/primitives/hasher.ts:134

Computes the Hash256 (SHA256(SHA256(x))) of the stored bytes and returns it as a hexadecimal string.

Returns

string

The Hash256 value as a hexadecimal string

Properties

PropertyModifierTypeDescriptionDefined in
bytespublicUint8ArrayThe byte array representation of the data to be hashedcashconnect-js/packages/core/src/primitives/hasher.ts:22