PreimageSha256

types~ PreimageSha256

PREIMAGE-SHA-256: Hashlock condition using SHA-256.

This type of condition is also called a hashlock. By creating a hash of a difficult-to-guess 256-bit random or pseudo-random integer it is possible to create a condition which the creator can trivially fulfill by publishing the random value. However, for anyone else, the condition is cryptgraphically hard to fulfill, because they would have to find a preimage for the given condition hash.

PREIMAGE-SHA-256 is assigned the type ID 0. It relies on the SHA-256 and PREIMAGE feature suites which corresponds to a feature bitmask of 0x03.

Constructor

new PreimageSha256()

Source:

Methods

setPreimage(preimage)

Provide a preimage.

The preimage is the only input to a SHA256 hashlock condition.

Note that the preimage should contain enough (pseudo-random) data in order to be difficult to guess. A sufficiently large secret seed and a cryptographically secure pseudo-random number generator (CSPRNG) can be used to avoid having to store each individual preimage.

Parameters:
Name Type Description
preimage Buffer

Secret data that will be hashed to form the condition.

Source:

validate(Message) → {Boolean}

Validate this fulfillment.

For a SHA256 hashlock fulfillment, successful parsing implies that the fulfillment is valid, so this method is a no-op.

Parameters:
Name Type Description
Message Buffer

(ignored in this condition type)

Source:
Returns:

Validation result

Type
Boolean