Hash

class Hash

A SHA-256 hash, most commonly used for blockhashes.

Parameters:

hash_bytes (bytes) – the hashed bytes.

LENGTH = 32
static default()

The default Hash object.

Returns:

a Hash object.

Return type:

Hash

Example

>>> from solders.hash import Hash
>>> Hash.default()
Hash(
    11111111111111111111111111111111,
)
static from_bytes(raw_bytes)

Construct from bytes. Equivalent to Hash.__init__ but included for the sake of consistency.

Parameters:

raw_bytes (bytes) – the hashed bytes.

Returns:

a Hash object.

Return type:

Hash

static from_json(raw)

Build from a JSON string.

static from_string(s)

Create a Hash from a base-58 string.

Parameters:

s (str) – The base-58 encoded string

Returns:

a Hash object.

Return type:

Hash

Example

>>> from solders.hash import Hash
>>> Hash.from_string("4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM")
Hash(
    4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM,
)
static hash(val)

Return a Sha256 hash for the given data.

Parameters:

val (bytes) – the data to hash.

Returns:

a Hash object.

Return type:

Hash

Example

>>> from solders.hash import Hash
>>> Hash.hash(b"foo")
Hash(
    3yMApqCuCjXDWPrbjfR5mjCPTHqFG8Pux1TxQrEM35jj,
)
static new_unique()

Create a unique Hash for tests and benchmarks.

Returns:

a Hash object.

Return type:

Hash

to_json()

Convert to a JSON string.

exception ParseHashError

Raised when an error is encountered converting a string into a Hash.