Condition

types~ Condition

Crypto-condition.

A primary design goal of crypto-conditions was to keep the size of conditions constant. Even a complex multi-signature can be represented by the same size condition as a simple hashlock.

However, this means that a condition only carries the absolute minimum information required. It does not tell you anything about its structure.

All that is included with a condition is the fingerprint (usually a hash of the parts of the fulfillment that are known up-front, e.g. public keys), the maximum fulfillment size, the set of features used and the condition type.

This information is just enough that an implementation can tell with certainty whether it would be able to process the corresponding fulfillment.

Constructor

new Condition()

Source:

Methods

(static) fromBinary(data) → {Condition}

Create a Condition object from a binary blob.

This method will parse a stream of binary data and construct a corresponding Condition object.

Parameters:
Name Type Description
data Buffer

Condition in binary format

Source:
Returns:

Resulting object

Type
Condition

(static) fromUri(serializedCondition) → {Condition}

Create a Condition object from a URI.

This method will parse a condition URI and construct a corresponding Condition object.

Parameters:
Name Type Description
serializedCondition String

URI representing the condition

Source:
Returns:

Resulting object

Type
Condition

getCost() → {Number}

Return the maximum fulfillment length.

The maximum fulfillment length is the maximum allowed length for any fulfillment payload to fulfill this condition.

The condition defines a maximum fulfillment length which all implementations will enforce. This allows implementations to verify that their local maximum fulfillment size is guaranteed to accomodate any possible fulfillment for this condition.

Otherwise an attacker could craft a fulfillment which exceeds the maximum size of one implementation, but meets the maximum size of another, thereby violating the fundamental property that fulfillments are either valid everywhere or nowhere.

Source:
Returns:

Maximum length (in bytes) of any fulfillment payload that fulfills this condition..

Type
Number

getHash() → {Buffer}

Return the hash of the condition.

A primary component of all conditions is the hash. It encodes the static properties of the condition. This method enables the conditions to be constant size, no matter how complex they actually are. The data used to generate the hash consists of all the static properties of the condition and is provided later as part of the fulfillment.

Source:
Returns:

Hash of the condition

Type
Buffer

getSubtypes() → {Number}

Return the subtypes of this condition.

For simple condition types this is simply the set of bits representing the features required by the condition type.

For structural conditions, this is the bitwise OR of the bitmasks of the condition and all its subconditions, recursively.

Source:
Returns:

Bitmask required to verify this condition.

Type
Number

getTypeId() → {Number}

Return the type of this condition.

The type is a unique integer ID assigned to each type of condition.

Source:
Returns:

Type corresponding to this condition.

Type
Number

serializeBinary() → {Buffer}

Serialize condition to a buffer.

Encodes the condition as a string of bytes. This is used internally for encoding subconditions, but can also be used to passing around conditions in a binary protocol for instance.

Source:
Returns:

Serialized condition

Type
Buffer

serializeUri() → {String}

Generate the URI form encoding of this condition.

Turns the condition into a URI containing only URL-safe characters. This format is convenient for passing around conditions in URLs, JSON and other text-based formats.

Source:
Returns:

Condition as a URI

Type
String

setCost(Maximum)

Set the maximum fulfillment length.

The maximum fulfillment length is normally calculated automatically, when calling Fulfillment#getCondition. However, when

Parameters:
Name Type Description
Maximum Number

fulfillment payload length in bytes.

Source:

setHash(hash)

Validate and set the hash of this condition.

Typically conditions are generated from fulfillments and the hash is calculated automatically. However, sometimes it may be necessary to construct a condition URI from a known hash. This method enables that case.

Parameters:
Name Type Description
hash Buffer

Hash as binary.

Source:

setSubtypes(subtypes)

Set the subtypes.

Sets the required subtypes to validate a fulfillment for this condition.

Parameters:
Name Type Description
subtypes Number

Integer representation of subtypes.

Source:

setTypeId(type)

Set the type.

Sets the type ID for this condition.

Parameters:
Name Type Description
type Number

Integer representation of type.

Source:

validate() → {Boolean}

Ensure the condition is valid according the local rules.

Checks the condition against the local subtypes (supported condition types) and the local maximum fulfillment size.

Source:
Returns:

Whether the condition is valid according to local rules.

Type
Boolean