The cryptoconditions Package¶
A Python implementation of the Crypto-Conditions spec: a multi-algorithm, multi-level, multi-signature format for expressing conditions and fulfillments.
This implementation doesn’t implement the entire Crypto-Conditions spec. It implements the conditions needed by BigchainDB, and some others. It’s compliant with version 02 and version 03 of the spec.
See also: the rfcs/crypto-conditions repository.
Documentation¶
See https://cryptoconditions.readthedocs.io/en/latest/.
Installation¶
Development release¶
To install cryptoconditions, run this very simple command in your terminal:
$ pip install cryptoconditions
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for cryptoconditions can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/bigchaindb/cryptoconditions
Or download the tarball:
$ curl -OL https://github.com/bigchaindb/cryptoconditions/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Usage¶
Yet to be documented.
ILP Format¶
Condition¶
Conditions are URI encoded as:
ni:///sha-256;<hashed-fingerprint>?fpt=<condition-type>&cost=<cost>&subtypes=<subtypes>
See https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-9.1 for details.
Conditions are binary encoded as:
Crypto-Conditions DEFINITIONS AUTOMATIC TAGS ::= BEGIN
-- Conditions
Condition ::= CHOICE {
preimageSha256 [0] SimpleSha256Condition,
prefixSha256 [1] CompoundSha256Condition,
thresholdSha256 [2] CompoundSha256Condition,
rsaSha256 [3] SimpleSha256Condition,
ed25519Sha256 [4] SimpleSha256Condition
}
SimpleSha256Condition ::= SEQUENCE {
fingerprint OCTET STRING (SIZE(32)),
cost INTEGER (0..4294967295)
}
CompoundSha256Condition ::= SEQUENCE {
fingerprint OCTET STRING (SIZE(32)),
cost INTEGER (0..4294967295),
subtypes ConditionTypes
}
ConditionTypes ::= BIT STRING {
preImageSha256 (0),
prefixSha256 (1),
thresholdSha256 (2),
rsaSha256 (3),
ed25519Sha256 (4)
}
END
See https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-7 for details.
Fulfillment¶
There are no URI encoding rules for fulfillments.
Fulfillments are binary encoded as:
Crypto-Conditions DEFINITIONS AUTOMATIC TAGS ::= BEGIN
-- Fulfillments
Fulfillment ::= CHOICE {
preimageSha256 [0] PreimageFulfillment ,
prefixSha256 [1] PrefixFulfillment,
thresholdSha256 [2] ThresholdFulfillment,
rsaSha256 [3] RsaSha256Fulfillment,
ed25519Sha256 [4] Ed25519Sha512Fulfillment
}
PreimageFulfillment ::= SEQUENCE {
preimage OCTET STRING
}
PrefixFulfillment ::= SEQUENCE {
prefix OCTET STRING,
maxMessageLength INTEGER (0..4294967295),
subfulfillment Fulfillment
}
ThresholdFulfillment ::= SEQUENCE {
subfulfillments SET OF Fulfillment,
subconditions SET OF Condition
}
RsaSha256Fulfillment ::= SEQUENCE {
modulus OCTET STRING,
signature OCTET STRING
}
Ed25519Sha512Fulfillment ::= SEQUENCE {
publicKey OCTET STRING (SIZE(32)),
signature OCTET STRING (SIZE(64))
}
END
See https://tools.ietf.org/html/draft-thomas-crypto-conditions-02#section-7.3 for details.
Examples¶
Preimage Sha 256¶
>>> from cryptoconditions import PreimageSha256
>>> secret = b'Beware! Trying to understand crypto can lead to knowledge intoxications.'
>>> fulfillment = PreimageSha256(preimage=secret)
>>> fulfillment.condition_uri
'ni:///sha-256;xumt48hVcQEXuUx2p2GqVgO4mpq9O_FIYmjb258CkZM?fpt=preimage-sha-256&cost=72'
>>> fulfillment.condition_binary
b'\xa0%\x80 \xc6\xe9\xad\xe3\xc8Uq\x01\x17\xb9Lv\xa7a\xaaV\x03\xb8\x9a\x9a\xbd;\xf1Hbh\xdb\xdb\x9f\x02\x91\x93\x81\x01H'
Library Reference¶
Contributing¶
Fork the cryptoconditions repo on GitHub.
Clone your fork locally and enter into the project:
$ git clone git@github.com:your_github_handle/cryptoconditions.git $ cd cryptoconditions/
Add the
upstream
remote:$ git remote add upstream git@github.com:bigchaindb/cryptoconditions.git
Install in development mode:
$ pip install -e .[dev]
Make sure you can run the tests:
$ pytest -v
For the installation step and running the tests you can also use the provided
docker-compose.yml
file:
$ docker-compose build
$ docker-compose run --rm cryptoconditions pytest -v