src/activity/client.ts is the only code that talks to the notify service. It has four exported functions and one constant, and it holds no state.
Exports
Export | Behaviour |
|---|---|
| |
Trims, strips trailing slashes, adds | |
"Hosted notify and standalone notify have different endpoint paths." A base whose path ends with | |
| |
One signed read or write. Returns a validated |
The signed request
notificationRequest builds one of two payloads, both with limit: 400:
read: {action: "get-notification-state", limit: 400}
write: {action: "apply-notification-actions", actions: [...], limit: 400}
It then calls createNotifyEnvelope(payload, signer, now) from Crypto: signed envelopes. The signer is adapted from the Identity Signer: principal is principalFromEd25519(publicKey) (34 bytes) and sign wraps the key's synchronous sign. The envelope adds signer and time (from now), signs the strict DAG-CBOR encoding of the map without sig, and returns the bytes of the same map with sig added.
The request:
POST {notifyEndpoint(base)}
Content-Type: application/cbor
redirect: error
body: envelope bytesredirect: "error" carries the comment "Never forward signed identity requests to a redirect's destination." A Bun test starts a redirecting server and asserts that the destination receives nothing.
now is not read here. It is the root contract's time.epochAtZero + performanceNow() stamp, passed through the source. The service rejects times more than 20 seconds from its own clock, which is why the root contract uses a deliberate ask stamp.
Response checks
The private jsonFetch applies exactTimeout: 15000.
parseSnapshot validates the whole body.
accountId, config.accountId and readState.accountId must all equal the signer's account id.
Error messages
Message | Cause |
|---|---|
|
|
| body is not JSON |
the body's | non-2xx status |
|
|
| account id mismatch |
| configured URL has another scheme |
For a load, these reach the screen through Contract's failure(activityData); for a write, through the reply's error.
Grants
Requests need the net.fetch https: grant, and the local fixture needs net.fetch http://127.0.0.1:4790, both listed in app.ts. See Grants and capabilities.
Tests
In activity.test.ts, the group "notify protocol and identity adapter" has 9 tests: discovery keeps the hosted fallback; signed requests refuse redirects; a missing local identity returns the empty state without fetching; another identity's response is refused; hosted, legacy, standalone and path-mounted services resolve; the signer uses principal bytes and signs the map without sig; the mock rejects stale, tampered and zero-sig bytes; malformed snapshots are failures; service errors keep their message.
Known limits
limit is fixed at 400 and there is no paging: beforeMs and siteUid, which the envelope type allows, are never sent.
resolveNotifyUrl does not trim a trailing slash from server and runs on every load and every write (no cache).
Related
Notify service: the protocol from the app's point of view
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime