aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/api.md')
-rw-r--r--docs/api.md20
1 files changed, 12 insertions, 8 deletions
diff --git a/docs/api.md b/docs/api.md
index 2665306..41a4f4d 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -164,7 +164,8 @@ way on every node:
* **The same key**: one write wins, the same one everywhere. "Newest" means by
Automerge's operation order (the write made after seeing more changes; between equals,
by the writer's actor ID), not by any clock: of two truly concurrent writes, which wins
- is arbitrary, but it is the same on every node.
+ is arbitrary, but it is the same on every node. Values their users signed come first
+ (Signed values, below): of those, the one its user numbered highest (`seq`).
* **Maps written at the same key** merge into one: their keys are united, each key as
above.
* **A write and a delete** of the same key: the write stays (a delete removes only what
@@ -312,17 +313,20 @@ document.
## Signed values
Where the swarm has its users sign values ([`access.md`](access.md), Values signed by
-their users), a user writes one by signing it with its SSH key: the payload, one line
-of JSON, then the signature, as `application/continuum-signed`.
+their users), a user writes one by signing it with its SSH key: the value, one line of
+JSON; the meta, one line of JSON; then the signature of those two lines (without the
+second's newline), as `application/continuum-signed`.
```sh
# The swarm it is for; the envelope there, if any, and what replaces it names: its
-# SHA-256 (none: "").
+# SHA-256 (none: "") and the number after its own (none: 0).
swarm=$(curl -sf -u alice localhost:3000/auth/whoami | jq -r .swarm)
read=$(curl -sf -u alice -H 'Accept: text/plain' 'localhost:3000/store/config?raw=true')
prev=${read:+$(printf %s "$read" | sha256sum | cut -d' ' -f1)}
-printf '{"swarm":"%s","path":["config"],"value":{"mode":"fast"},"user":"alice","at":%s,"prev":"%s"}' \
- "$swarm" "$(date +%s000)" "$prev" > payload
+meta=$(printf %s "$read" | cut -d. -f3 | tr _- /+ | jq -Rr '@base64d')
+seq=${meta:+$(( $(printf %s "$meta" | jq .seq) + 1 ))}
+printf '{"mode":"fast"}\n{"swarm":"%s","path":["config"],"user":"alice","at":%s,"seq":%s,"prev":"%s"}' \
+ "$swarm" "$(date +%s000)" "${seq:-0}" "$prev" > payload
ssh-keygen -Y sign -f ~/.ssh/id_ed25519 -n continuum-value payload
{ cat payload; echo; cat payload.sig; } | curl -X PUT localhost:3000/store/config \
-u alice -H 'Content-Type: application/continuum-signed' --data-binary @-
@@ -330,8 +334,8 @@ ssh-keygen -Y sign -f ~/.ssh/id_ed25519 -n continuum-value payload
The node writes it as its envelope if the authenticated user signed it (`403` if not),
for this swarm and this path, with one of its keys, may write there (`403`), and it replaces what is
-there (`prev`, the SHA-256 of the envelope it replaces; `409` if it names another:
-read again and sign anew), and only where values are signed (`409` elsewhere). It
+there (`prev`, the SHA-256 of the envelope it replaces, and `seq`, one more than that
+one's; `409` if it names another: read again and sign anew), and only where values are signed (`409` elsewhere). It
answers with the value, as a `PUT` does; a signed `null` deletes, with `204`. It stays
as an envelope (reads show nothing there), so the value written next names it in
`prev`: the chain goes on through deletions, and an envelope from before one can't be