|
| 1 | +# Restore Session |
| 2 | + |
| 3 | +To restore a session from the mnemonic seed on a new device (e.g., moving from mobile to desktop), the client sends a `restore-session` message. Mostro will respond with the relevant orders and disputes so the client can rebuild the session state using the same `trade_index` values. |
| 4 | + |
| 5 | +## Request |
| 6 | + |
| 7 | +Client sends a Gift wrap Nostr event to Mostro with the following rumor's content: |
| 8 | + |
| 9 | +```json |
| 10 | +{ |
| 11 | + "order": { |
| 12 | + "version": 1, |
| 13 | + "action": "restore-session", |
| 14 | + "payload": null |
| 15 | + } |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +## Response |
| 20 | + |
| 21 | +Mostro will respond with a message containing all non-finalized orders (e.g., statuses such as `pending`, `active`, `fiat-sent`, `waiting-buyer-invoice`, `waiting-payment`, `settled-hold-invoice`) and any active disputes. The response format will be: |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "order": { |
| 26 | + "version": 1, |
| 27 | + "action": "restore-session", |
| 28 | + "payload": { |
| 29 | + "orders": [ |
| 30 | + { |
| 31 | + "id": "<Order Id>", |
| 32 | + "trade_index": 1, |
| 33 | + "status": "pending" |
| 34 | + }, |
| 35 | + { |
| 36 | + "id": "<Order Id>", |
| 37 | + "trade_index": 2, |
| 38 | + "status": "active" |
| 39 | + }, |
| 40 | + { |
| 41 | + "id": "<Order Id>", |
| 42 | + "trade_index": 3, |
| 43 | + "status": "fiat-sent" |
| 44 | + } |
| 45 | + ], |
| 46 | + "disputes": [ |
| 47 | + { |
| 48 | + "dispute_id": "<Dispute Id>", |
| 49 | + "order_id": "<Order Id>", |
| 50 | + "trade_index": 4, |
| 51 | + "status": "initiated" |
| 52 | + } |
| 53 | + ] |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### Fields |
| 60 | + |
| 61 | +* `orders`: An array of active or ongoing orders with their `id`, `trade_index`, and current `status`. |
| 62 | +* `disputes`: An array of ongoing disputes with `dispute_id`, the associated `order_id`, and `trade_index`. |
| 63 | + |
| 64 | +## Example Use Case |
| 65 | + |
| 66 | +A user has the following: |
| 67 | + |
| 68 | +* Two `pending` orders (trade index 1 and 2) |
| 69 | +* One `active` order (trade index 3) |
| 70 | +* One active dispute (trade index 4) |
| 71 | + |
| 72 | +When switching to desktop, after restoring the mnemonic, the client sends `restore-session` and receives: |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "order": { |
| 77 | + "version": 1, |
| 78 | + "action": "restore-session", |
| 79 | + "payload": { |
| 80 | + "orders": [ |
| 81 | + { "id": "abc-123", "trade_index": 1, "status": "pending" }, |
| 82 | + { "id": "def-456", "trade_index": 2, "status": "pending" }, |
| 83 | + { "id": "ghi-789", "trade_index": 3, "status": "active" }, |
| 84 | + { "id": "xyz-999", "trade_index": 4, "status": "dispute" } |
| 85 | + ], |
| 86 | + "disputes": [ |
| 87 | + { "dispute_id": "dis-001", "order_id": "xyz-999", "trade_index": 4, "status": "initiated" } |
| 88 | + ] |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
0 commit comments