Skip to content

Commit

Permalink
Docs: Add LN address (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch authored Jan 12, 2024
1 parent a78a749 commit 2bb2905
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
4 changes: 3 additions & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

[Home](./overview.md)

- [Creating an order](./new_order.md)
- [Creating a Sell order](./new_order.md)
- [Creating a Buy order with a LN address](./new_order_ln_address.md)
- [Take sell](./take_sell.md)
- [Take sell with a LN address](./take_sell_ln_address.md)
- [Take buy](./take_buy.md)
- [Seller pays hold invoice](./seller_pay_hold_invoice.md)
- [Fiat sent](./fiatsent.md)
Expand Down
103 changes: 103 additions & 0 deletions book/src/new_order_ln_address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Creating a new order

Creating buy order with a [lightning address](https://github.com/andrerfneves/lightning-address) would make the process way faster and easy going, to acomplish the buyer should send a Nostr event kind 4 (an encrypted message) to Mostro with the following content:

```json
{
"Order": {
"version": "1",
"pubkey": "0000147e939bef2b81c27af4c1b702c90c3843f7212a34934bff1e049b7f1427", // Buyer's real pubkey
"action": "NewOrder",
"content": {
"Order": {
"kind": "Buy",
"status": "Pending",
"amount": 0,
"fiat_code": "VES",
"fiat_amount": 100,
"payment_method": "face to face",
"premium": 1,
"buyer_invoice": "[email protected]",
"created_at": 0
}
}
}
}
```

The nostr event will look like this:

```json
{
"id": "cade205b849a872d74ba4d2a978135dbc05b4e5f483bb4403c42627dfd24f67d",
"kind": 4,
"pubkey": "9a42ac72d6466a6dbe5b4b07a8717ee13e55abb6bdd810ea9c321c9a32ee837b", // Buyer's ephemeral pubkey
"content": "base64-encoded-aes-256-cbc-encrypted-JSON-serialized-string",
"tags": [
["p", "dbe0b1be7aafd3cfba92d7463edbd4e33b2969f61bd554d37ac56f032e13355a"] // Mostro's pubkey
],
"created_at": 1234567890,
"sig": "a21eb195fe418613aa9a3a8a78039b090e50dc3f9fb06b0f3fe41c63221adc073a9317a1f28d9db843a43c28d860ba173b70132ca85b0e706f6487d43a57ee82"
}
```

## Confirmation message

Mostro will send back a nip04 event as a confirmation message to the user like the following:

```json
{
"Order": {
"version": "1",
"id": "ede61c96-4c13-4519-bf3a-dcf7f1e9d842",
"pubkey": "0000147e939bef2b81c27af4c1b702c90c3843f7212a34934bff1e049b7f1427",
"content": {
"Order": {
"id": "ede61c96-4c13-4519-bf3a-dcf7f1e9d842",
"kind": "Sell",
"status": "Pending",
"amount": 0,
"fiat_code": "VES",
"fiat_amount": 100,
"payment_method": "face to face",
"premium": 1,
"master_buyer_pubkey": null,
"master_seller_pubkey": null,
"buyer_invoice": "[email protected]",
"created_at": 1698870173
}
}
}
}
```

Mostro publishes this order as an event kind `38383` with status `Pending`:

```json
[
"EVENT",
"RAND",
{
"id": "84fad0d29cb3529d789faeff2033e88fe157a48e071c6a5d1619928289420e31",
"pubkey": "dbe0b1be7aafd3cfba92d7463edbd4e33b2969f61bd554d37ac56f032e13355a",
"created_at": 1702548701,
"kind": 38383,
"tags": [
["d", "ede61c96-4c13-4519-bf3a-dcf7f1e9d842"],
["k", "Sell"],
["f", "VES"],
["s", "Pending"],
["amt", "0"],
["fa", "100"],
["pm", "face to face"],
["premium", "1"],
["y", "mostrop2p"],
["z", "order"]
],
"content": "",
"sig": "7e8fe1eb644f33ff51d8805c02a0e1a6d034e6234eac50ef7a7e0dac68a0414f7910366204fa8217086f90eddaa37ded71e61f736d1838e37c0b73f6a16c4af2"
}
]
```

After a seller takes this order Mostro will not ask for an invoice to the buyer, Mostro will get the buyer's invoice and paid it when the seller releases the funds.
4 changes: 2 additions & 2 deletions book/src/take_sell.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ Mostro updates the nip 33 event with `d` tag `ede61c96-4c13-4519-bf3a-dcf7f1e9d8

## Buyer sends LN invoice

The buyer sends a nip 04 evento to Mostro with the LN invoice, in case the order has a fixed sats amount, the buyer can we skip the previous step, here the unencrypted content of the event:
The buyer sends a nip 04 event to Mostro with the lightning invoice, the action should be the same the buyer just received in the last message from Mostro (`AddInvoice`), here the unencrypted content of the event:

```json
{
"Order": {
"version": "1",
"id": "ede61c96-4c13-4519-bf3a-dcf7f1e9d842",
"pubkey": null,
"action": "TakeSell",
"action": "AddInvoice",
"content": {
"PaymentRequest": [
null,
Expand Down
78 changes: 78 additions & 0 deletions book/src/take_sell_ln_address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Taking a sell order with a lightning address

The buyer can use a [lightning address](https://github.com/andrerfneves/lightning-address) to receive funds and avoid to create and send lightning invoices on each trade, to acomplish this the buyer will send a message in a Nostr event kind 4 to Mostro with the following content:

```json
{
"Order": {
"version": "1",
"id": "ede61c96-4c13-4519-bf3a-dcf7f1e9d842",
"pubkey": "0000147e939bef2b81c27af4c1b702c90c3843f7212a34934bff1e049b7f1427",
"action": "TakeSell",
"content": {
"PaymentRequest": [null, "[email protected]"]
}
}
}
```

The event to send to Mostro would look like this:

```json
{
"id": "cade205b849a872d74ba4d2a978135dbc05b4e5f483bb4403c42627dfd24f67d",
"kind": 4,
"pubkey": "9a42ac72d6466a6dbe5b4b07a8717ee13e55abb6bdd810ea9c321c9a32ee837b",
"content": "base64-encoded-aes-256-cbc-encrypted-JSON-serialized-string",
"tags": [
["p", "dbe0b1be7aafd3cfba92d7463edbd4e33b2969f61bd554d37ac56f032e13355a"]
],
"created_at": 1234567890,
"sig": "a21eb195fe418613aa9a3a8a78039b090e50dc3f9fb06b0f3fe41c63221adc073a9317a1f28d9db843a43c28d860ba173b70132ca85b0e706f6487d43a57ee82"
}
```

## Mostro response

Mostro send a nip 04 event to the buyer with a wrapped `Order` in the content, it would look like this:

```json
{
"Order": {
"version": "1",
"id": "ede61c96-4c13-4519-bf3a-dcf7f1e9d842",
"pubkey": null,
"action": "WaitingSellerToPay",
"content": null
}
}
```

Mostro updates the nip 33 event with `d` tag `ede61c96-4c13-4519-bf3a-dcf7f1e9d842` to change the status to `WaitingPayment`:

```json
[
"EVENT",
"RAND",
{
"id": "eb0582360ebd3836c90711f774fbecb27e600f4a5fedf4fc2d16fc852f8380b1",
"pubkey": "dbe0b1be7aafd3cfba92d7463edbd4e33b2969f61bd554d37ac56f032e13355a",
"created_at": 1702549437,
"kind": 38383,
"tags": [
["d", "ede61c96-4c13-4519-bf3a-dcf7f1e9d842"],
["k", "Sell"],
["f", "VES"],
["s", "WaitingPayment"],
["amt", "7851"],
["fa", "100"],
["pm", "face to face"],
["premium", "1"],
["y", "mostrop2p"],
["z", "order"]
],
"content": "",
"sig": "a835f8620db3ebdd9fa142ae99c599a61da86321c60f7c9fed0cc57169950f4121757ff64a5e998baccf6b68272aa51819c3e688d8ad586c0177b3cd1ab09c0f"
}
]
```

0 comments on commit 2bb2905

Please sign in to comment.