Signatures and valid entries
Every entry of a feed is signed with the author's key, and every client and relay checks every entry it receives. This page gives the entry's exact bytes, each rule an entry must meet and the reason for it, and the strict Ed25519 verification the network requires, in enough detail to write the check without a library of ours. NETWORK.md sections 4.1 and 4.2 are the specification; this page explains them. The Tersenet SDK, at the end, does it all in one call.
The bytes
| Offset | Size | Field |
|---|---|---|
| 0 | 32 | feed key (A) |
| 32 | 4 | seq |
| 36 | 4 | time, Unix seconds |
| 40 | 1 | kind |
| 41 | 3 | blob size |
| 44 | 32 | blob ID |
| 76 | 32 | reply-to, or zeros |
| 108 | 1 | n, the title's length |
| 109 | n | title |
109 + n | 64 | signature: R, then S |
Integers are little-endian. The signed message M is the 13 ASCII bytes terse-entry-0 followed by bytes 0 to 108 + n: everything but the signature. The prefix keeps a signature over an entry from being taken for one over anything else signed with the same key.
The rules
An entry is valid if all of these hold; clients and relays discard any other.
- **Length.** At least 173 bytes,
nat most 120, and exactly 173 +nbytes. Every field is then where the table says, and an entry is at most 293 bytes. - **Title.** Valid UTF-8 (no overlong forms, no surrogates, nothing above U+10FFFF), so every reader shows the same text.
- **Seq.** At least 1:
seq0 means "nothing yet" in a Subscribe'safter. - **Kind.** Not 0 or 255, which are reserved. Kinds 5 to 254 are valid: a later revision may define them, and today's relays must carry them.
- **Size.** 1 to 1,048,576, the sizes a blob may have; 1 to 4,096 for a profile (kind 2), the most a profile document may hold.
- **Name.** For a profile or a program (kinds 2 and 3) the title is a display name: 1 to 48 bytes, no control character (U+0000 to U+001F, U+007F to U+009F) anywhere, and no white space (the Unicode White_Space property, listed in NETWORK.md 4.6) first or last.
- **Signature.** Strict Ed25519 verification, below, of the signature over M under the feed key.
Points and encodings
Ed25519 works on the points of a curve over the integers modulo p = 2^255 − 19. A point is written in 32 bytes: y as a 255-bit little-endian integer, and in the top bit of the last byte the sign of x (its lowest bit). Decoding finds x from y with the curve's equation.
- An encoding is **canonical** if y < p and it is not x = 0 with the sign bit set. Each point has exactly one canonical encoding. Many decoders also accept y ≥ p (taking it modulo p) and the sign bit on x = 0, so one point can have two encodings. A simple test: decode, encode again, compare the 32 bytes.
- The group has order 8 × L, where L = 2^252 + 27742317777372353535851937790883648493 is the order of the base point B. A point P is **of small order** if [8]P is the neutral point (x = 0, y = 1). There are eight.
- A point of large order may still have a small-order component (P = Q + T, with T of small order). That is fine for a key: it is not of small order.
The eight canonical encodings of the points of small order, in hexadecimal: order 1 (the neutral point), order 2, two of order 4, four of order 8:
0100000000000000000000000000000000000000000000000000000000000000 ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000080 26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05 26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85 c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa
A decoder that accepts non-canonical encodings also takes six more to these points: ee then 30 ff then 7f or ff (y = p + 1), ed then 30 ff then 7f or ff (y = p), 01 then 30 00 then 80, and ec then 31 ff (x = 0 with the sign bit set). Comparing with these fourteen byte strings is an alternative to multiplying by 8.
Strict verification
R is the signature's first 32 bytes; S its last 32, an integer of all 256 bits. The signature verifies if and only if:
1. **A is a valid feed key**: its encoding is canonical and the point is not of small order. 2. **S < L.** Not a check of S's top three bits only: S + L passes that. 3. **R decodes to a point not of small order.** Decoding R loosely changes nothing: an R only a loose decoder accepts is of small order or fails step 4. 4. **The cofactorless equation, by bytes.** k is SHA-512(R ‖ A ‖ M), R and A as received, its 64 bytes a little-endian integer reduced modulo L. Compute [S]B − [k]A; its canonical encoding must be exactly the 32 bytes R. Not [8][S]B = [8]R + [8][k]A, the cofactored form.
Why each:
- **A of small order**: for such a key, R = [r]B and S = r make [S]B − [k]A = R whenever [k]A is neutral (always for the neutral point, one time in 8 for one of order 8). Anyone could sign for that feed.
- **Canonical A, S < L, comparing R's bytes**: without them one valid entry has several valid encodings (S + L, another spelling of R or A), which a relay would store as different entries with the same
seq. - **R of small order, and the cofactorless equation**: whether a signature whose R has a small-order component verifies depends on which equation is used. Both are allowed by RFC 8032, so two correct libraries can disagree on the same entry, and relays and clients then disagree on what a feed holds.
With all four, every signature is valid for every conforming implementation or for none, no one but the key's owner can sign for a feed, and each valid entry has exactly one encoding. A key with a small-order component signed by its owner verifies exactly when [k] times that component is neutral: the same for everyone, so it is allowed.
What libraries do
What each verification call does by default, read from its source; "add" is what you must check before calling it.
| Call | Missing | Add |
|---|---|---|
Go ed25519.Verify | canonical A; small-order A, R | 1, 3 |
Rust verify_strict | canonical A | 1 (canonical) |
| libsodium | nothing | nothing |
| OpenSSL | canonical A; small-order A, R | 1, 3 |
| tweetnacl | all but step 4 | 1, 2, 3 |
| noble-ed25519 | 3, 4; by default also 1 | 1, 3, and 4 by hand |
- **Go**,
crypto/ed25519(Go 1.27): refuses S ≥ L and compares R's bytes with the canonical encoding of [S]B − [k]A; its point decoding accepts non-canonical encodings, and nothing refuses small order.filippo.io/edwards25519has what the checks need:SetBytes,Bytes,MultByCofactor. - **Rust**,
ed25519-dalek2.2:verify_strictrefuses small-order A and R and S ≥ L and compares bytes, butVerifyingKey::from_bytesaccepts a non-canonical key. With the crate'slegacy_compatibilityfeature, which any crate in a build can turn on, it checks only S's top three bits. Itsverifyrefuses no small-order point. - **C**, libsodium
crypto_sign_verify_detached(1.0.20, 1.0.21): makes all four checks exactly, unless built withED25519_COMPAT, which replaces checks 1 to 3 with a check of S's top three bits. - **Python**: PyNaCl's
VerifyKey.verifyis libsodium's (it bundles 1.0.20).cryptography'sEd25519PublicKey.verifyis OpenSSL's (its wheels link OpenSSL 4.0.3): S < L, bytes compared, the cofactorless equation, but no canonical or small-order check on A, none on R. - **JavaScript**: Node's
crypto.verifyis OpenSSL's; since Node 24.19 and 26.5 it also refuses small-order A and R (by a list that includes some non-canonical forms), but still accepts other non-canonical keys, so add 1.tweetnacl'snacl.sign.detached.verifymakes no check of S at all.@noble/ed255193.2 checks the cofactored equation, in both its default mode (zip215: true) and the strict one, so checks added before it are not enough: compute step 4 with its point arithmetic.
Test vectors
vectors/entries.txt (format in vectors/README) holds valid entries signed with a public test key and an invalid one for each rule, among them every strict check: small-order-key-signed, small-order-key-order-8-signed, non-canonical-key, non-canonical-signature, small-order-r, non-canonical-r, mixed-order-r. sdk/testdata/strict.txt adds 64 cases of key, message and signature: every point of small order as A and as R, the six non-canonical ones, S + L, S = L, S with its top bit set, R with a component of each small order, and keys with a small-order component, each with the rule it breaks or valid. An implementation that accepts one it should not is wrong.
The SDK's tests run both files: go test ./... in sdk/go, cargo test -p tersenet. cargo test -p terse-cli --test sdk_agreement checks that the reference, both SDKs and tersereader give the same verdict on 4,000 altered entries.
The SDK
sdk/go (package tersenet) and sdk/rust (crate tersenet) make every check on this page, with no options. Go:
e, err := tersenet.VerifyEntry(b)
if err != nil {
return err // names the rule: tersenet.ErrKey, ...
}
fmt.Println(e.Seq, e.Title)
Rust:
let e = tersenet::verify_entry(&bytes)?;
println!("{} {}", e.seq, e.title);
Both also offer Verify / verify (strict verification of any key, message and signature) and ValidFeedKey / valid_feed_key (section 4.1). Each is one short file: sdk/go/tersenet.go, sdk/rust/src/lib.rs. The reference implementation checks entries with the Rust one.