Skip to content

Instantly share code, notes, and snippets.

@justmoon
Last active December 4, 2016 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justmoon/e68a2fb39f6217ad43a05df63c766912 to your computer and use it in GitHub Desktop.
Save justmoon/e68a2fb39f6217ad43a05df63c766912 to your computer and use it in GitHub Desktop.
Conditions as Curried Functions

Crypto-condition types can be viewed as curried functions. Let's take a ed25519 signature condition as an example:

ed25519(pubkey)(signature)(message)
  1. Initially, we start out with the condition type (ed25519). When we apply a first set of parameters (pubkey), it returns a condition.

  2. A condition is another function which expects some kind of proof (signature) and returns a fulfillment.

  3. A fulfillment is again a function. This function verifies whether it (the fulfillment) is valid with respect to a certain message. Hence it takes a message parameter and return either true (valid) or an exception (invalid).

There are five condition types so far:

JS-style syntax

preimageSha256(hash)(preimage)()
rsaSha256(pubkey)(signature)(message)
ed25519(pubkey)(signature)(message)
prefixSha256(subcondition, prefix)(fulfillment)(message)
thresholdSha256(subconditions, threshold)(subfulfillments)(message)

S-expressions

(((preimageSha256 hash) preimage))
(((rsaSha256 pubkey) signature) message)
(((ed25519 pubkey) signature) message)
(((prefixSha256 subcondition prefix) fulfillment) message)
(((thresholdSha256 subconditions threshold) subfulfillments) message)

S-expressions (uncurried)

(preimageSha256 hash preimage)
(rsaSha256 pubkey signature message)
(ed25519 pubkey signature message)
(prefixSha256 subcondition prefix fulfillment message)
(thresholdSha256 subconditions threshold subfulfillments message)

Arrow syntax

preimageSha256 = (hash) => (preimage) => () => {}
rsaSha256 = (pubkey) => (signature) => (message) => {}
ed25519 = (pubkey) => (signature) => (message) => {}
prefixSha256 = (subcondition, prefix) => (fulfillment) => (message) => {}
thresholdSha256 = (subconditions, threshold) => (subfulfillments) => (message) => {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment