Crypto: signed envelopes
The two request envelope formats in src/crypto/envelopes.ts: the agents protocol v3 action and the notify service request, and how their signing conventions differ.

src/crypto/envelopes.ts signs requests, as opposed to the published blobs covered in Blobs. It has two formats with two different signing conventions, and the tests keep them apart on purpose ("distinct agents and notify signing conventions").

Agents action envelope

signAgentActionWith(input) takes {signer, accountUid, action, timestampMs, delegation?} and returns the signed object. createAgentEnvelope(input) wraps it with encodeBlob, returning {bytes, cid, value} ready to post as application/cbor.

Field

Value

type

"AgentsAction"

signer

the signing key's 34-byte principal

sig

64 zero bytes while signing, then the signature

account

principal bytes of accountUid

capability

the delegation's capability CID, as a string, only when delegated

capabilityBlob

the capability blob bytes, only when supplied

protocol

3

action

the caller's action with undefined values removed, plus ts

Details that matter:

    ts is nested inside action and is a plain integer from wireTimestamp, not a bigint.

    The signature is over the client encode (the variant that would turn an undefined into null), with sig zeroed. This is the same zero-signature convention as blobs, so verifyBlob accepts the result.

    If the signer's account id differs from accountUid and no delegation is given, it throws The local key holds no delegation for this account.

AgentsSignerDelegation is {capabilityCid, capabilityBlob?}.

The running agents module builds its envelope in its own file on top of cbor.ts and primitives.ts; see Agents: signed action envelope and endpoints. This function is the reference checked against the original client's bytes.

Notify envelope

createNotifyEnvelope(payload, signer, timestampMs, accountUid?) returns {bytes, unsignedBytes, signature}.

The body is the payload's own fields plus:

Field

Value

signer

34-byte principal

time

integer milliseconds from wireTimestamp

accountUid

only when passed

sig

the signature, added after signing

The convention differs from blobs: the service "signs strict DAG-CBOR WITHOUT sig, then adds sig to the transmitted body". The signed bytes contain no sig key at all, so verifyBlob returns false for a notify body, and the test asserts exactly that.

NotificationPayload allows only known wire shapes:

    {action: 'get-notification-state', limit, beforeMs?, siteUid?}

    {action: 'apply-notification-actions', actions, limit, beforeMs?, siteUid?}

    {action: 'get-email-subscribers'}

The caller is Activity: notify client and signed requests; the receiving side is the Notify service. The service accepts only a narrow time window, which is why the timestamp is supplied by the contract rather than read here; see State, refresh and stale-reply patterns.

Tests

crypto.test.ts has 4 tests in this group:

    two agents envelopes (direct and delegated) byte for byte against the original client, including the CID,

    the missing-delegation refusal,

    the notify state and apply-actions bodies against the original client's fetch bodies, with the signature verified over unsignedBytes.

review.test.ts adds one test that a fractional clock yields an integer action.ts. How the vectors are produced is in Parity vectors.

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

Unsubscribe anytime