The Crums Timechain REST API is documented on this page.
The methods in this API can all be accessed via HTTP GET. Even when the HTTP call causes a change in state of the system or causes a new resource (eg crumtrail artifacts) to be created. This is not RESTy, as a GET call is supposed to be a verb that has no side effects (reads but doesn't touch); but it's convenient. Think of the choice of HTTP method in this REST API as a transport layer concern: it doesn't have verb semantics.
The response format is JSON. With one notable exeception, the HTTP response status is always 200 (OK); the exception is when the system witnesses a hash it doesn't remember seeing: in that case, the an HTTP 202 (Accepted) since a new record is in the process of being created. (See below).
There's a good argument for a binary response format: the hash proofs are complicated, validating them requires deep knowledge of their structures, and tho JSON is human readable, it's still hard to interpret. So why bother?
/api/witness | |||
---|---|---|---|
Description |
Accepts a new SHA-256 hash to be witnessed in the timechain and returns a crum as reciept. (A crum is a tuple consisting of a 32-byte hash, and an 8-byte UTC witness time). The returned crum may be later used to retrieve a crumtrail via the "update" method. The HTTP response is 202. This method is idempotent over the duration of a [timechain] block. (The no. of blocks this idempotency is in effect can be configured in the timechain settings, but there's no reason to, since increasing it negatively impacts scalability, but does not offer any tangible user benefit.) In rare cases (a race between clients), this method may return a 200 response with a fully constructed crumtrail (see update). To cover such corner cases, the optional query string parameters the update method takes, may also be supplied. |
||
Method | GET | ||
Paramaters | |||
hash | SHA-256 hash of the object, expressed in either 64 hex digits, or 43 base64-32 (b64) digits. | ||
enc |
Optional. Encoding used to represent 32-byte hashes in JSON response. There are 2 choices:
hex and b64 (the default).
|
||
Example | |||
/api/witness?enc=hex&hash=41f4915e20.. |
/api/update | |||
---|---|---|---|
Description |
Retrieves the crumtrail for the given crum (previously received via the witness method), if the crum's block no. has been committed to the timechain; otherwise, if the crum is valid (is scheduled to be committed to the timechain), then the crum is returned as-is. Finally, if the crum is not valid (is expired, or made up), then this method defaults to the witness method. |
||
Method | GET | ||
Paramaters | |||
hash | SHA-256 hash of the object, expressed in either 64 hex digits, or 43 base64-32 (b64) digits. | ||
utc | UTC time hash was witnessed in milliseconds. | ||
enc |
Optional. Encoding used to represent 32-byte hashes in JSON response. There are 2 choices:
hex and b64 (the default).
|
||
block |
Optional. Block no. chain block proof begins at. Must be no greater than the
block no. utc parameter falls in. Defaults to 1 .
|
||
compress |
Optional. Sets the compression-level of the block proof. There are two
levels: 0 (no compression), and 1 (the default).
The byte size of uncompressed block proofs scales as
O (log n)2, where n is
the no. of block no.s spanned; compressed block proofs scale as
O (log log n) x log n.
|
/api/state | |||
---|---|---|---|
Description |
Returns a block proof asserting the hash of a block at some no. is derived from the hash of blocks at lower no.s. If no arguments are provided, a block proof linking the genesis to the latest block is returned. |
||
Method | GET | ||
Paramaters | |||
enc |
Optional. Encoding used to represent 32-byte hashes in JSON response. There are 2 choices:
hex and b64 (the default).
|
||
block | Optional. Target block no.(s) to be included in block proof. By default, both the genesis and latest block no.s are included. | ||
last |
Optional. If true (case ignored), then the latest committed block is included in
the proof. By default, the latest committed block is included.
| ||
compress |
Optional. Sets the compression-level of the block proof. There are two
levels: 0 (no compression), and 1 (the default).
The byte size of uncompressed block proofs scales as
O (log n)2, where n is
the no. of block no.s spanned; compressed block proofs scale as
O (log log n) x log n.
|
||
Response | Block proof and chain parameters in JSON. The block proof is formatted exactly as that found in the block-proof section of a crumtrail's JSON. | ||
Example | |||
/api/state
|
/api/policy | |||
---|---|---|---|
Description |
Returns the chain paramaters and notary policy settings. These are constant, static values over a typical session. The chain parameters (inception UTC, time-bin resolution) are in fact immutable, but other policy settings may be adjusted over the life of a timechain. While the JSON response is meant to be parsed by software, it's somewhat human readable:
The bin exponent also delineates block time boundaries. For a given block, the minimum (big endian) UTC value has its rightmost bin_exp-bits set to 0 (zero), while all eligible UTC values in the block share the same remaining leftmost bits; and the maximum UTC value in the block has its rightmost bin_exp-bits set to 1 (one). |
||
Method | GET | ||
Example | |||
/api/policy
|
The following utility methods are included. These are not strictly part of the timechain API. They are included as convenience methods for human interaction.
/api/util/verify | |||
---|---|---|---|
Description |
Verifies the given URL-encoded crumtrail is committed to the timechain. The response (in JSON) is the same crumtrail, but with its block proof patched to the most recent state of the chain. A human readable summary precedes the crumtrail's JSON.
This method primarily exists so that a crumtrail may be archived as a
bookmark. See the |
||
Method | GET | ||
Paramaters | |||
crumtrail | URL-encoded crumtrail JSON. | ||
Example | |||
Since the state of a timechain is not known in advance (and since this page is static), a ready made example cannot be provided. The "Bookmark crumtrail" link on the landing page, is an example. |
/api/util/h_codec | |||
---|---|---|---|
Description |
Hash encoding translator. Converts About b64This is slightly non-standard Base64 encoding. It uses the URL / filename-friendly character-set specified in §5 of RFC 4648 but takes liberties (discussed tho not condoned in §3.2) for specifying boundary conditions in a way that does not require padding for our use case. Unlike in some other variants, padding bits must be set to '0', so as to preserve one-to-one-ness, and are pre-pended (two '0' bits), not post-pended. |
||
Method | GET | ||
Paramaters | |||
hash | Either 64 hex digits, or 43 base64-32 (b64) digits. | ||
Example | |||
/api/util/h_codec?hash=47qaLuWWGx3EKUCKMGpwhAblOQ1D3oRHq5yKD7cm2Na
|
GNU Affero General Public License v3 (AGPLv3) |
© 2020-2024 crums.io |