Crypto: changes, refs, comments and profiles
The signed blob builders in src/crypto, file by file: field layouts, the zero-signature convention, CID parameters, signer shapes and the tests that pin the bytes.

These files build the signed, content-addressed blobs the mobile app publishes. Each is adapted from the matching file in frontend/packages/client/src, with two deliberate differences: time is always an argument, and hashing is pure JavaScript. The resulting bytes go to the site through Publishing signed blobs.

The signing convention

Every Seed blob is signed the same way:

    Build the object with sig set to 64 zero bytes and signer set to the 34-byte principal.

    Encode it as strict DAG-CBOR and sign those bytes with Ed25519.

    Replace sig with the 64-byte signature and encode again. Those are the published bytes.

Timestamps are BigInt(wireTimestamp(ms)), so a fractional Exact clock value is floored first (Primitives).

blob.ts

blob.ts holds the content-addressing helpers.

Function

Behaviour

cidFromBytes(bytes)

CIDv1, codec 0x71 (dag-cbor), multihash 0x12 (sha2-256)

encodeBlob(value)

{bytes, cid, value} using the client encode (an undefined becomes CBOR null)

verifyBlob(bytes)

Decodes, requires a 34-byte 0xed 0x01 signer, re-encodes with a zeroed sig and verifies. Returns false on any failure

signing.ts

signing.ts is internal ("Not exported from the package index").

    cborCodec: {code: 0x71, name: 'DAG-CBOR', encode} over the strict encoder.

    normalizeBytes(data): copies into an owned, exact-length Uint8Array.

    signObject(signer, data): signs strictEncode(data).

    signerPublicKey(signer): the principal from either signer shape.

    toPublishInput(blobData, extraBlobs?): {blobs: [{data}, ...extras]}. The primary blob carries no cid; extras keep theirs.

signer.ts

signer.ts reconciles two signer shapes that "grew up independently" in the client:

Type

Shape

HMSigner

{getPublicKey(): Promise<Uint8Array>, sign(data): Promise<Uint8Array>}

PrincipalSigner

{principal: Uint8Array, sign(data): Promise<Uint8Array>}

AnySigner

either

toHMSigner and toPrincipalSigner convert between them. In both, the public key is the 34-byte principal. signerFromKeyPair(key) in index.ts adapts a KeyPair or a raw seed to an object satisfying both.

change.ts

change.ts builds document Changes in two steps.

createChangeOps({ops, genesisCid?, deps?, depth?, timestampMs}) returns {unsignedBytes, ts}. createChange(unsignedBytes, signer) fills signer, signs, and returns {bytes, cid, genesis, ts}.

Field

Value

type

"Change"

body

{ops, opCount} where opCount is ops.length

signer

null when unsigned, then the principal

ts

bigint milliseconds

sig

null when unsigned, then the signature

genesis, deps, depth

present only when genesisCid is given; deps defaults to [], depth to 1

DocumentOperation is one of SetAttributes (attrs: [{key: string[], value}]), MoveBlocks, ReplaceBlock, DeleteBlocks. The app only emits SetAttributes.

createHomeGenesisChange(signer) returns the genesis of an account's home document: {type: "Change", signer, sig, ts: 0} and nothing else. It is deterministic on purpose, so "every device of an account derives the same home genesis". The comment warns that any other document built on it "becomes the home document as far as the daemon is concerned", and records that this happened to sixty documents on 2026-09-15. A non-home document's first content Change is its own genesis.

ref.ts

createVersionRef(input, signer) returns a publish input holding one Ref blob.

Field

Value

Omitted when

type

"Ref"

never

signer, ts, sig

principal, bigint ms, signature

never

genesisBlob

CID parsed from genesis

never

heads

CIDs from version split on .

never

generation

number

it is 0

space

principal bytes of space

it equals the signer

path

string such as /my-doc

it is empty

capability

CID

not given

visibility

string such as Private

empty

comment.ts

createComment(input, signer) returns the publish input: the Comment blob first, then any attachment blobs.

Field

Value

type

"Comment"

body

publishable blocks

space

principal bytes decoded from docId.uid

path

/a/b form of docId.path, or empty

version

CIDs of the commented document version

replyParent, threadRoot

CIDs, only for replies

signer, ts, sig

as above

visibility

only when set

Content handling, in order:

    trimTrailingEmptyBlocks drops trailing empty Paragraph or Heading nodes.

    A quote target (quoting: {blockId, range?}, or the deprecated quotingBlockId) wraps the content in an Embed block (childrenType: "Group", view: "Content") whose link is pinned to the exact version with no latest flag. Its id is quoteBlockId, or 8 random characters from a 62-character alphabet drawn with rejection sampling.

    blockToPublishable flattens each node: Paragraph, Heading, Math, Code, Image, Video, File, Button, Embed, WebEmbed and Slot are accepted, anything else throws Unsupported block type. An empty Paragraph is dropped unless it has children or a childrenType (a list container).

    Annotations are reduced to known fields; Bold, Italic, Underline, Strike, Code, Link, Embed, TextColor, BackgroundColor, TextSize, TextFamily are accepted. validateExclusiveAnnotations throws when two colour, size or family annotations with different values overlap.

    undefined values are stripped, because strict DAG-CBOR refuses them.

commentRecordIdFromBlob(bytes) computes the comment's record id: <base58btc signer>/<tsid>, where the tsid is base58btc of 10 bytes: the low 48 bits of ts big-endian, then the first 4 bytes of the blob's SHA-256.

The app sends a single Paragraph; see Discuss: loading and posting.

profile.ts

createProfilePublishBlobs(input, signer) builds a home-document metadata update.

Input

Meaning

account

account id, used as the Ref's space with path ''

metadata

one SetAttributes op per key, with key: [name]

timestampMs

used for the Change and the Ref

previous

{genesis, version, depth, generation} of the existing home document

capability

optional capability CID for the Ref

Without previous it creates the home genesis, a Change of depth 1 depending on it, and a Ref with generation 1: three blobs. With previous it keeps the genesis and generation, depends on the previous heads, and uses depth + 1: two blobs. It returns {changeCid, genesis, generation, blobs}. Profile is the caller.

types.ts

types.ts declares HMSigner, HMPublishBlobsInput, HMAnnotation, HMBlockNode and UnpackedHypermediaId, plus hmIdPathToEntityQueryPath and packHmId (builds hm://uid/path?v=...#block[start:end]).

Tests

In crypto.test.ts, "signed CBOR and CID vectors from the real client" has 12 tests: the Change (unsigned and signed bytes), the home Ref, fresh and existing profiles, six comment shapes with their record ids, rejection of bad annotations and blocks, and attachments plus tamper detection. Six more tests check the home genesis for six seeds. All compare against parity vectors.

User stories

The code described here exists to deliver these stories. Each story lists this page in its Trace (traceability).

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Attributes
name
Crypto: changes, refs, comments and profiles
summary
The signed blob builders in src/crypto, file by file: field layouts, the zero-signature convention, CID parameters, signer shapes and the tests that pin the bytes.