Skip to main content
Version: 1.2.1

Class: MessageHash

A 32 byte message hash used for signing ECDSA messages.

Example

// A SHA256 hash of the string 'Hello World'
const messageHash = MessageHash.sha256('Hello World');
// A Keccak256 hash of the string 'Hello World'
const messageHash = MessageHash.keccak256('Hello World');
// In case you already have a hashed value you can just call the constructor with it:
const messageHash = new MessageHash('aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899');

Constructors

constructor

new MessageHash(bytes): MessageHash

Creates a new MessageHash object from a 32 byte hash represented as Uint8Array or hex string of length 64

Parameters

NameTypeDescription
bytesstring | Uint8ArrayThe 32 bytes of the message hash. Can be a hex string or a Uint8Array

Returns

MessageHash

Properties

bytes

Readonly bytes: Uint8Array


LENGTH

Static Readonly LENGTH: 32

Methods

toHex

toHex(): string

Returns

string


keccak256

keccak256(message): MessageHash

A helper function to create a MessageHash from a string or Uint8Array using keccak256.

Parameters

NameTypeDescription
messagestring | Uint8ArrayThe message to hash. Can be a string or a Uint8Array.

Returns

MessageHash

A MessageHash object representing the keccak256 hash of the message.


sha256

sha256(message): MessageHash

A helper function to create a MessageHash from a string or Uint8Array using SHA256.

Parameters

NameTypeDescription
messagestring | Uint8ArrayThe message to hash. Can be a string or a Uint8Array.

Returns

MessageHash

A MessageHash object representing the SHA256 hash of the message.


sha256d

sha256d(message): MessageHash

A helper function to create a MessageHash from a string or Uint8Array using Double SHA256 (Bitcoin's Sha256d)

Parameters

NameTypeDescription
messagestring | Uint8ArrayThe message to hash. Can be a string or a Uint8Array.

Returns

MessageHash

A MessageHash object representing the Double-SHA256 hash of the message.