aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/src/meshbay_cli/client
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-15 01:12:16 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-15 01:12:16 +0200
commit382fcc5f675f9942350013780335315757c245c5 (patch)
treea24ed8732c6d3971b071ed6af3c399d6142b79f4 /packages/meshbay-cli/src/meshbay_cli/client
parent6f68bb6c1970e26de1f66c073ea5d7fecd21840d (diff)
downloadmeshbay-382fcc5f675f9942350013780335315757c245c5.tar.gz
feat(cli): rm, and Delete in the interactive mode
rm deletes files, resolved as get resolves paths and patterns, with the node's rule (design §5.4): the uploading account's devices, or the node's operator account. The whole run is checked against the index first (the entry's uploader_id, the role the join result gives this key): a file outside the rule, or a folder, refuses it before anything is asked or sent. Then one confirmation, or --yes. The node's challenge is checked against what was asked before it is signed. In the interactive mode, Delete on the right pane does the same, asked once per batch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/client')
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/client/remove.py45
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/client/session.py9
2 files changed, 52 insertions, 2 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/client/remove.py b/packages/meshbay-cli/src/meshbay_cli/client/remove.py
new file mode 100644
index 0000000..370cf95
--- /dev/null
+++ b/packages/meshbay-cli/src/meshbay_cli/client/remove.py
@@ -0,0 +1,45 @@
+"""
+Deleting a file from a group (docs/MESHBAY_DESIGN.md §5.4).
+
+The node decides, and on two grounds only: a key paired with it as operator, or
+a live device of the account that uploaded the file — any of them, so a file
+sent from a phone is deleted from the laptop. Being the group's owner on the hub
+is neither. The request is answered with a challenge the client signs with its
+key on the node; the node rebuilds what was signed itself.
+"""
+
+from meshbay_common import MNP_VERSION
+from meshbay_common.adminop import OP_FILE_DELETE, admin_transcript
+
+from ..errors import NODE, CliError
+from .keys import b64, unb64
+from .session import GroupSession
+
+
+def may_delete(session: GroupSession, entry: dict, user_id: str) -> bool:
+ """What the node will accept, known before asking: the operator, or the
+ file's uploader. The node checks again; this only avoids asking in vain."""
+ return session.role == "operator" or entry.get("uploader_id") == user_id
+
+
+async def delete_file(session: GroupSession, file_id: str) -> None:
+ """Delete one file. Raises `NodeRefusal` with the node's reason."""
+ reply = await session.ch.request({"type": "file_delete", "v": MNP_VERSION,
+ "file_id": file_id},
+ "admin_challenge", "file_delete_ack")
+ if reply["type"] == "file_delete_ack":
+ return
+ # What is signed is checked against what was asked, never taken from the
+ # node: a challenge for another operation, file, group or node is refused.
+ if (reply.get("op") != OP_FILE_DELETE or reply.get("subject") != file_id
+ or reply.get("group_id") != session.group_id
+ or reply.get("node_pk") != session.node_pk):
+ raise CliError(NODE, "The node asked to sign something other than this deletion; "
+ "nothing was signed.")
+ transcript = admin_transcript(op=OP_FILE_DELETE, node_pk_b64=session.node_pk,
+ group_id=session.group_id, subject=file_id,
+ nonce=unb64(reply["nonce"]), ts=int(reply["ts"]))
+ await session.ch.request({"type": "admin_response", "v": MNP_VERSION,
+ "op_id": reply["op_id"], "op": OP_FILE_DELETE,
+ "signature": b64(session.identity.sk_ed.sign(transcript))},
+ "file_delete_ack")
diff --git a/packages/meshbay-cli/src/meshbay_cli/client/session.py b/packages/meshbay-cli/src/meshbay_cli/client/session.py
index d5264a2..41bf0d6 100644
--- a/packages/meshbay-cli/src/meshbay_cli/client/session.py
+++ b/packages/meshbay-cli/src/meshbay_cli/client/session.py
@@ -197,7 +197,8 @@ class GroupSession:
def __init__(self, pc: RTCPeerConnection, ch: Channel, group_id: str,
node_id: str, node_pk: str, gek: bytes, ack: dict,
- identity: Identity | None = None, nonce_node: bytes = b""):
+ identity: Identity | None = None, nonce_node: bytes = b"",
+ role: str = ""):
self.pc = pc
self.ch = ch
self.group_id = group_id
@@ -209,6 +210,10 @@ class GroupSession:
# and the nonce that ties a signature to this connection.
self.identity = identity
self.nonce_node = nonce_node
+ # What the node's roster says this key is here: "operator" when it was
+ # paired with the node — the authority to delete anyone's file. Not the
+ # hub's word on who owns the group (docs/MESHBAY_DESIGN.md §3.3).
+ self.role = role
async def index(self) -> dict:
"""`{version, entries, dirs, roots}`, opened under the group key."""
@@ -351,7 +356,7 @@ async def _handshake(account: Account, pc, ch: Channel, group_id: str, node_id:
await _device_hello(account, ch, identity, node_pk, group_id, nonce_s)
await _settle_bundle(account, ch, identity, node_pk, bundle)
return GroupSession(pc, ch, group_id, node_id, node_pk, gek, config,
- identity, nonce_s)
+ identity, nonce_s, str(joined.get("role") or ""))
async def _fetch_bundle(ch: Channel) -> str: