|
1 | 1 | # Dispute Chat |
2 | 2 |
|
3 | | -Once an admin takes a dispute, both the admin and the involved parties (buyer and seller) can communicate through an encrypted chat using Gift Wrap messages (NIP-59). |
| 3 | +The dispute chat uses the same shared key encryption scheme as the [Peer-to-peer Chat](./chat.md). Instead of computing a shared key between buyer and seller, each party computes an independent shared key with the admin who took the dispute. |
4 | 4 |
|
5 | | -## Sending a message |
| 5 | +## Establishing the shared key |
6 | 6 |
|
7 | | -Users and admins send messages using action `send-dm`. The message content is wrapped in a Gift Wrap event (kind 1059) to ensure privacy and encryption. |
8 | | - |
9 | | -### User sending a message |
10 | | - |
11 | | -Here is an example of a user sending a message to the admin: |
| 7 | +When an admin takes a dispute, Mostro sends an `admin-took-dispute` message to each party (buyer and seller) containing the admin's pubkey: |
12 | 8 |
|
13 | 9 | ```json |
14 | 10 | [ |
15 | 11 | { |
16 | | - "dm": { |
| 12 | + "order": { |
17 | 13 | "version": 1, |
18 | | - "action": "send-dm", |
| 14 | + "id": "<Order Id>", |
| 15 | + "action": "admin-took-dispute", |
19 | 16 | "payload": { |
20 | | - "text_message": "Hello, I need help with this order" |
| 17 | + "peer": { |
| 18 | + "pubkey": "<Admin's pubkey>" |
| 19 | + } |
21 | 20 | } |
22 | 21 | } |
23 | 22 | }, |
24 | 23 | null |
25 | 24 | ] |
26 | 25 | ``` |
27 | 26 |
|
28 | | -### Admin sending a message |
| 27 | +Upon receiving this message, the client computes the shared key using ECDH: |
29 | 28 |
|
30 | | -Admins use the same format to send messages to users: |
| 29 | +``` |
| 30 | +Shared Key = ECDH(tradeKey.private, adminPubkey) |
| 31 | +``` |
| 32 | + |
| 33 | +The admin computes the same shared key from their side: |
| 34 | + |
| 35 | +``` |
| 36 | +Shared Key = ECDH(adminPrivateKey, tradeKey.public) |
| 37 | +``` |
| 38 | + |
| 39 | +Each party (buyer and seller) has its own independent shared key with the admin. A session can have both a peer shared key (for the P2P chat) and an admin shared key (for the dispute chat) simultaneously. |
| 40 | + |
| 41 | +## Sending and receiving messages |
| 42 | + |
| 43 | +Messages are wrapped and unwrapped using the same simplified NIP-59 scheme described in [Peer-to-peer Chat](./chat.md#example). The inner event is a kind 1 event signed by the sender's key, encrypted with NIP-44 and placed inside a kind 1059 Gift Wrap event. |
| 44 | + |
| 45 | +The `p` tag in the wrapper event points to the **admin shared key's pubkey**, not the trade key: |
31 | 46 |
|
32 | 47 | ```json |
33 | | -[ |
34 | | - { |
35 | | - "dm": { |
36 | | - "version": 1, |
37 | | - "action": "send-dm", |
38 | | - "payload": { |
39 | | - "text_message": "I'm reviewing the evidence, please wait" |
40 | | - } |
41 | | - } |
42 | | - }, |
43 | | - null |
44 | | -] |
| 48 | +{ |
| 49 | + "content": "<Encrypted content>", |
| 50 | + "kind": 1059, |
| 51 | + "created_at": 1703021488, |
| 52 | + "pubkey": "<Ephemeral pubkey>", |
| 53 | + "id": "<Event Id>", |
| 54 | + "sig": "<Ephemeral key signature>", |
| 55 | + "tags": [["p", "<Admin Shared Pubkey>"]] |
| 56 | +} |
45 | 57 | ``` |
46 | 58 |
|
47 | | -## Receiving messages |
| 59 | +## Subscribing to messages |
| 60 | + |
| 61 | +Clients subscribe to kind 1059 events filtered by the admin shared key's pubkey: |
| 62 | + |
| 63 | +```json |
| 64 | +{ |
| 65 | + "kinds": [1059], |
| 66 | + "#p": ["<Admin Shared Pubkey>"] |
| 67 | +} |
| 68 | +``` |
48 | 69 |
|
49 | | -Clients must subscribe to kind 1059 events with a `p` tag matching their pubkey. The Gift Wrap protocol (NIP-59) ensures that only the intended recipient can decrypt and read the messages, while preserving the sender's identity through the SEAL layer |
| 70 | +Clients should discard any messages received from pubkeys other than the Mostro node or the dispute solver. |
0 commit comments