Class: Contract

Contract

Represents a storage contract between a renter and a farmer

new Contract(contract, criteria)

Parameters:
Name Type Description
contract object
Properties
Name Type Argument Description
type string Unique identifier for the contract
renter_hd_key string <optional>
Node extended public key in base58
renter_hd_index number <optional>
Derivation index for signature
renter_id string Node ID of the renter
renter_signature string Renter's cryptographic signature
farmer_hd_key string <optional>
Node extended public key in base58
farmer_hd_index number <optional>
Derivation index for signature
farmer_id string Node ID of the farmer
farmer_signature string Farmer's cryptographic signature
data_size number Number of bytes to store
data_hash string RIPEMD-160 SHA-256 hash of the data
store_begin number UNIX timestamp to start contract
store_end number UNIX timestamp to end the contract
audit_count number Number of audits renter will perform
audit_leaves Array.<string> Merkle leaves for audit tree
payment_storage_price number Total price for storage
payment_download_price number Price per download
payment_destination string Bitcoin address to send funds
criteria object
Properties
Name Type Description
size number Criteria degree OPCODE
duration number Criteria degree OPCODE
availability number Criteria degree OPCODE
speed number Criteria degree OPCODE
Source:

Members


<static> CRITERIA

Defines some default criteria of a Contract
Source:

<static> DEFAULTS

Defines some default properties of a Contract
Source:

<static> MATRIX

Defines the criteria matrix for a Contract
Source:

<static> schema

Defines the JSON Schema of a Contract
Source:

<static> validator

Validation function against the schema
Source:

Methods


<static> compare(c1, c2)

Compares two contracts against each other
Parameters:
Name Type Description
c1 Contract Contract to compare
c2 Contract Contract to compare
Source:
Returns:
Type
boolean

<static> createTopic(criteria)

Create a topical OPCODE byte sequence from the provided criteria
Parameters:
Name Type Description
criteria object
Properties
Name Type Description
size number Criteria degree OPCODE
duration number Criteria degree OPCODE
availability number Criteria degree OPCODE
speed number Criteria degree OPCODE
Source:
Returns:
Type
buffer

<static> diff(c1, c2)

Returns the property names between two contracts that differ
Parameters:
Name Type Description
c1 Contract Contract to compare
c2 contract Contract to compare
Source:
Returns:
changedProperties
Type
Array.<string>

<static> from(data)

Infers the type of object supplied and constructs a contract
Parameters:
Name Type Description
data object | string | buffer
Source:
Returns:
Type
Contract

<static> fromBuffer(buffer)

Creates a contract from a Buffer
Parameters:
Name Type Description
buffer buffer Raw binary blob of contract data
Source:
Returns:
Type
Contract

<static> fromJSON(json)

Creates a contract from a JSON string
Parameters:
Name Type Description
json string JSON encoded contract
Source:
Returns:
Type
Contract

<static> fromObject(object)

Creates a contract from a plain object
Parameters:
Name Type Description
object object Dictionary of contract data
Source:
Returns:
Type
Contract

get(field)

Returns the value for the given contract property
Parameters:
Name Type Description
field string Contract property to get
Source:
Returns:
value
Type
string | number | null

getHash()

Calculates the SHA-256 hash of the serialized contract
Source:
Returns:
Type
buffer

getSigningData()

Returns the string representation of the contract, minus the signature fields, sorted alphanumerically for signing and verifying
Source:
Returns:
Type
string

getTopicBuffer()

Return OPCODE byte sequence for contract publication topic
Source:
Returns:
Type
buffer

getTopicString()

Return OPCODE byte sequence for contract publication topic as hex string
Source:
Returns:
Type
string

isComplete()

Checks if the contract is complete
Source:
Returns:
completed
Type
boolean

set(field, value)

Sets the contract property to the given value
Parameters:
Name Type Description
field string Contract property to set
value string | number Value to set for field
Source:
Returns:
Type
string | number | null

sign(actor, secret)

Signs the contract as the given actor
Parameters:
Name Type Description
actor string One of 'farmer' or 'renter'
secret buffer ECDSA private key
Source:
Returns:
signature
Type
string

signExternal(secret)

Signs the contract with the proved key and returns the signature
Parameters:
Name Type Description
secret buffer ECDSA private key
Source:
Returns:
Type
buffer

toBuffer()

Converts the contract to Buffer
Source:
Returns:
Type
buffer

toJSON()

Converts the contract to JSON string
Source:
Returns:
Type
string

toObject()

Converts the contract to a plain object
Source:
Returns:
Type
object

update(fields)

Applies the provided fields to the contract and validates it
Parameters:
Name Type Description
fields object Contract properties to update
Source:
Returns:
Type
Contract

verify(actor)

Verify the contract signature for the given actor
Parameters:
Name Type Description
actor string One of 'farmer' or 'renter'
Source:
Returns:
Type
boolean

verifyExternal(signature, pubkey)

Verify the provided signature for the contract
Parameters:
Name Type Description
signature buffer The contract signature to verify
pubkey buffer ECDSA public key
Source:
Returns:
Type
boolean