Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ without checking it is the request that was built (`roomsKeysAct` does).
## A portal page uses rooms through the wallet's own methods (P7b)

`window.vtaWallet.rooms.{list, choose, forget, info, browse, read, conversation,
putNote, getFile, putFile}` is how a community's member portal shows a member their rooms
putNote, putMessage, getFile, putFile}` is how a community's member portal shows a member their rooms
(VTI `data-rooms-files.md` §8.5). It does **not** loosen "a page is not a
member": `requestTask` and `signTrustTask` still refuse the whole `rooms/`
family. The methods fix the verb, run the flow in the extension, and return
Expand Down Expand Up @@ -1098,6 +1098,15 @@ page's `putNote` on an open room writes `rooms/records/put/0.4` with
like every host request) — there is no group to seal under — after the same
confirmation, which says the note will be readable by the room's host.

**A page sends a chat message with `putMessage`, never a note without a
title.** `writeMessageAsMember` writes the text with no `title`, plus
`kind: "message"` and `writtenAt` where the room's profile lists them — so
every reader shows it as a message, and a room listing neither still shows the
untitled record as one (*Untitled records*, `shownKind`). It is confirmed in the
wallet's window like a note, worded as a message. Keep `putNote`'s title
required: a note and a message are different records, and a page choosing
between them says which.

**An open room's file carries its own key.** With no storage key to derive from, `putRoomFile` mints
32 random bytes for the file, seals the blob exactly as on a sealed tier, and
writes `rooms/records/put/0.4` with the manifest — `fileKey` included — in
Expand Down
8 changes: 8 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ For history before this file, see `git log` on `packages/core`.

## [Unreleased]

### Added

- **`writeMessageAsMember`** writes a chat message to a room as the member:
the text with no `title`, plus `kind: "message"` and `writtenAt` where the
room's profile lists them (`MESSAGE_KIND`). A room listing neither takes it
as an untitled record, which readers show as a message. Sealed on
`attributed` / `private`, in the clear on `open`; create-only.

### Changed

- **BREAKING: a relying-party session step-up no longer takes the session's
Expand Down
35 changes: 35 additions & 0 deletions packages/core/src/rooms/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,41 @@ export async function writeMemberNameAsMember(
return { principal, key, version };
}

/**
* Write a chat message, as the member: a new record whose text is `body`, and
* no `title`.
*
* Where the room's profile lists `kind`, the record says `kind: "message"`, which
* every reader shows as a message; where it lists `writtenAt`, the record carries
* when it was written. A room listing neither still takes the message as an
* untitled record, which a reader keeping a conversation shows as one
* (*Untitled records*, `shownKind`) — never as a note with a made-up title.
* Sealed and signed by the VTA as the member on `attributed` and `private`, in the
* clear on `open` — as the room says, never assumed. Create-only.
*/
export async function writeMessageAsMember(
room: PersonaRoom,
params: { body: string; now?: () => Date },
): Promise<{ principal: string; key: string; version: number }> {
if (params.body.trim() === "") throw new RecordWriteRefused("Not written: a message needs some text.");
const listed = (await roomRecordMembersAsMember(room)) ?? [];
const now = (params.now ?? (() => new Date()))().toISOString().replace(/\.\d{3}Z$/, "Z");
const shape = {
...(listed.includes("kind") ? { kind: MESSAGE_KIND } : {}),
...(listed.includes("writtenAt") ? { writtenAt: now } : {}),
};
const { principal, info } = await roomInfoAsMember(room);
const key = opaqueRecordKey();
const version =
info.visibility === "open"
? await putCleartextAsMember(room, { key, body: params.body, ...shape })
: await writeSealedAsMember(room, { roomId: room.roomId, key, author: principal, body: params.body, ...shape });
return { principal, key, version };
}

/** `RecordKind` for a chat message. */
export const MESSAGE_KIND = "message";

/** The member's own name record, as rule 2 gives it from the records its client holds: what a rewrite near the head writes again. */
export interface OwnMemberName {
key: string;
Expand Down
41 changes: 41 additions & 0 deletions packages/core/tests/rooms.member-name.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
RecordWriteRefused,
rewriteMemberNameAsMember,
writeMemberNameAsMember,
writeMessageAsMember,
shownKind,
} from "../dist/rooms/index.js";

const ALICE = "did:webvh:QmAlice:people.example:alice-room";
Expand Down Expand Up @@ -456,3 +458,42 @@ test("near the head: nothing is written when the write is within 500, the name i
assert.deepEqual(puts(closed.sent), [], "the writer's gate holds for a rewrite too");
});


// ── A chat message (writeMessageAsMember) ──────────────────────────────────

test("message writer: on a sealed tier the body is kind message, the text and writtenAt, no title, signed as the member", async () => {
const r = room({ recordMembers: ["kind", "writtenAt"] });
const out = await writeMessageAsMember(r.room, { body: "Lunch at one?", now: () => new Date("2026-11-25T12:00:00.456Z") });
assert.equal(out.principal, ALICE);
const [body] = r.sealed;
assert.deepEqual(Object.keys(body).sort(), ["author", "body", "key", "kind", "roomId", "version", "writtenAt"]);
assert.equal(body.kind, "message");
assert.equal(body.body, "Lunch at one?");
assert.equal(body.writtenAt, "2026-11-25T12:00:00Z");
assert.equal(body.author, ALICE);
assert.equal(puts(r.sent)[0].payload.expectedVersion, 0, "create-only");
assert.equal(shownKind(body), "message");
});

test("message writer: a room whose profile lists neither still takes it, untitled, which readers show as a message", async () => {
const r = room({ recordMembers: undefined });
await writeMessageAsMember(r.room, { body: "hi" });
const [body] = r.sealed;
assert.deepEqual(Object.keys(body).sort(), ["author", "body", "key", "roomId", "version"]);
assert.equal(shownKind(body), "message");
});

test("message writer: on an open room the cleartext is the message, in the clear, never sealed", async () => {
const r = room({ recordMembers: ["kind"], visibility: "open" });
await writeMessageAsMember(r.room, { body: "hi" });
const [put] = puts(r.sent);
assert.deepEqual(put.payload.cleartext, { kind: "message", body: "hi" });
assert.deepEqual(r.sealed, []);
});

test("message writer: an empty message is refused before anything is asked", async () => {
const r = room({ recordMembers: ["kind"] });
await assert.rejects(writeMessageAsMember(r.room, { body: " \n" }), RecordWriteRefused);
assert.deepEqual(r.vtaAsked, []);
assert.deepEqual(r.sent, []);
});
7 changes: 5 additions & 2 deletions packages/extension/src/bridge-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,9 @@ export type RoomsPageOp =
body?: string;
description?: string;
tags?: string[];
};
}
/** A chat message: text and no title (`writeMessageAsMember`). Confirmed like a note. */
| { op: "putMessage"; hostDid: string; roomId: string; body: string };

export interface RuntimeRoomsPageRequest {
type: typeof RUNTIME_ROOMS_PAGE;
Expand Down Expand Up @@ -3661,7 +3663,8 @@ export type OffscreenRoomsPageOp =
body?: string;
description?: string;
tags?: string[];
};
}
| { op: "putMessage"; hostDid: string; roomId: string; member: string; body: string };

export interface OffscreenRoomsPageRequest {
target: typeof OFFSCREEN_TARGET;
Expand Down
5 changes: 5 additions & 0 deletions packages/extension/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ export interface VtaWalletRooms {
description?: string;
tags?: string[];
}): Promise<{ key: string; version: number }>;
/** Write a chat message as the member — text, no title — after they confirm it.
* It reads as a message in every reader (`kind: "message"` where the room
* takes it, else an untitled record). */
putMessage(params: { hostDid: string; roomId: string; body: string }): Promise<{ key: string; version: number }>;
/** A record's file, once the whole of it has verified against its author's digest. */
getFile(params: {
hostDid: string;
Expand Down Expand Up @@ -675,6 +679,7 @@ if (!window.vtaWallet) {
read: (p) => call("rooms", { op: "read", hostDid: p.hostDid, roomId: p.roomId, key: p.key }),
conversation: (p) => call("rooms", { op: "conversation", hostDid: p.hostDid, roomId: p.roomId }),
putNote: (p) => call("rooms", { ...p, op: "putNote" }),
putMessage: (p) => call("rooms", { op: "putMessage", hostDid: p.hostDid, roomId: p.roomId, body: p.body }),
offers: (p) => call("rooms", { op: "offers", hostDid: p.hostDid }),
acceptOffer: (p) =>
call("rooms", {
Expand Down
15 changes: 12 additions & 3 deletions packages/extension/src/room-consent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,20 @@ function Share({

function Write({ view, decide }: { view: RoomWriteConsentView; decide: (approved: boolean) => void }) {
const isFile = "file" in view.what;
const isMessage = "message" in view.what;
const thing = isFile ? "file" : isMessage ? "message" : "note";
return (
<>
<strong style={{ fontSize: 14 }}>
Add {isFile ? "a file" : "a note"} to this room as you?
{isMessage ? "Send this message to the room as you?" : `Add a ${thing} to this room as you?`}
</strong>
<div style={{ color: "var(--w-muted)", lineHeight: 1.45 }}>
{originHost(view.origin)} asks to write to a room, signed as you. Every member of the room will read it as
yours.
</div>
{view.visibility === "open" && (
<div role="note" style={{ color: "var(--w-muted)", lineHeight: 1.45 }}>
This room is <b>open</b>: {isFile ? "the file's record, and the key that opens it, are" : "the note is"}{" "}
This room is <b>open</b>: {isFile ? "the file's record, and the key that opens it, are" : `the ${thing} is`}{" "}
stored in the clear, so the room's host can read {isFile ? "the file" : "it"} as well as its members.
</div>
)}
Expand Down Expand Up @@ -258,6 +260,13 @@ function Write({ view, decide }: { view: RoomWriteConsentView; decide: (approved
{view.what.mediaType ? ` · ${view.what.mediaType}` : ""}
{view.what.title ? <div>Title: {view.what.title}</div> : null}
</>
) : "message" in view.what ? (
<>
{view.what.excerpt}
<div style={{ fontSize: 11, color: "var(--w-muted)", marginTop: 6 }}>
{view.what.bodyChars} characters
</div>
</>
) : (
<>
<b>{view.what.title}</b>
Expand All @@ -273,7 +282,7 @@ function Write({ view, decide }: { view: RoomWriteConsentView; decide: (approved
<button autoFocus onClick={() => decide(false)} style={{ padding: "8px 16px", fontSize: 13 }}>
Deny
</button>
<Primary onClick={() => decide(true)}>Add {isFile ? "file" : "note"}</Primary>
<Primary onClick={() => decide(true)}>{isMessage ? "Send message" : `Add ${thing}`}</Primary>
</div>
</>
);
Expand Down
21 changes: 21 additions & 0 deletions packages/extension/src/room-page-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,27 @@ export class RoomPageGates {
...(p.tags !== undefined ? { tags: p.tags } : {}),
});
}
case "putMessage": {
const { vta } = await this.atPortal(origin, p.hostDid, { needReach: true });
const member = await this.granted(origin, p.hostDid, vta, p.roomId);
const info = (await this.offscreen(vta, {
op: "info",
hostDid: p.hostDid,
roomId: p.roomId,
member,
})) as PageRoomInfoView;
const decision = await this.deps.prompt({
kind: "write",
origin,
hostDid: p.hostDid,
roomId: p.roomId,
member: info.member,
visibility: info.visibility,
what: { message: true, excerpt: excerpt(p.body), bodyChars: [...p.body].length },
});
if (!decision.approved) throw new RoomPageRefusal("the member declined to send this message", "declined");
return this.offscreen(vta, { op: "putMessage", hostDid: p.hostDid, roomId: p.roomId, member, body: p.body });
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/extension/src/room-page-offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
readSealedVersion,
roomProfileView,
roomsKeysProfileRead,
writeMessageAsMember,
writeSealedAsMember,
type PersonaRoom,
} from "@openvtc/pnm-core/rooms";
Expand Down Expand Up @@ -284,6 +285,10 @@ export async function runRoomsPageOp(
});
return { key, version };
}
case "putMessage": {
const { key, version } = await writeMessageAsMember(await room(op.roomId, op.member), { body: op.body });
return { key, version };
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/extension/src/room-page-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function tags(v: unknown): string | null {
return null;
}

const OPS = new Set(["list", "choose", "forget", "info", "browse", "read", "conversation", "putNote", "offers", "acceptOffer"]);
const OPS = new Set(["list", "choose", "forget", "info", "browse", "read", "conversation", "putNote", "putMessage", "offers", "acceptOffer"]);

/** Why a page's room call is malformed, or `null` when it is well formed. Checked before anything else. */
export function roomsPageParamsRefusal(raw: unknown): string | null {
Expand Down Expand Up @@ -377,6 +377,8 @@ export function roomsPageParamsRefusal(raw: unknown): string | null {
text(op.description, "description", MAX_DESCRIPTION) ??
tags(op.tags)
);
case "putMessage":
return text(op.body, "body", MAX_BODY, true);
default:
return null;
}
Expand Down Expand Up @@ -452,6 +454,7 @@ export interface RoomWriteConsentView {
visibility: string;
what:
| { note: true; title: string; excerpt: string; bodyChars: number }
| { message: true; excerpt: string; bodyChars: number }
| { file: true; name: string; size: number; mediaType?: string; title?: string };
}

Expand Down
Loading