-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NUT-18: Payment Requests #124
Merged
Merged
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
b7b0781
added v1 draft
Egge21M b12b4ee
updated reference implementation
Egge21M 9021c09
updated referece Impl. + began formatting
Egge21M 0e9b53d
formatting
Egge21M 80e6d6f
fixed typo & removed ref impl
Egge21M 50fc922
changed transport + token
Egge21M 1632d88
suggestions
callebtc 0c57a0d
fix
callebtc 183d2bb
Merge branch 'main' into requests
callebtc 3349e24
remove TokenV4 JSON, instead use mint unit proofs
callebtc ec0cb4e
add to readme
callebtc 64dc463
fix transport and change tag
callebtc 5734943
change tags to support multiple values
gudnuf 40ec76b
remove NIP-04
gudnuf 0f4ddc2
Merge branch 'main' into requests
callebtc 28e6f9f
remove TokenV4 JSON, instead use mint unit proofs
callebtc 459d66f
add to readme
callebtc 4989f52
fix transport and change tag
callebtc ec3bfa3
change tags to support multiple values
gudnuf 0663344
remove NIP-04
gudnuf a2c6172
readd nutix
callebtc 1c1050d
:erge branch 'requests' of https://github.com/egge21m/nuts into requests
callebtc 211864c
prettier
callebtc 4ec6ec7
Update 18.md
callebtc 8002b5b
remove wrong line
callebtc 09d70ec
add example
callebtc c09e45f
prettier
callebtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# NUT-XX: Payment Requests | ||
|
||
`optional` | ||
|
||
--- | ||
|
||
This NUT introduces a standardised format for payment requests, that supply a sending wallet with all information necessary to complete the transaction. This enables many use-cases where a transaction is better initiated by the receiver (e.g. point of sale). | ||
|
||
## Flow | ||
|
||
1. Receiver creates a payment request, encodes it and displays it to the sender | ||
2. Sender scans the request and constructs a matching token | ||
3. Sender sends the token according to the transport specified in the payment request | ||
4. Receiver receives the token and finalises the transaction | ||
|
||
## Payment Request | ||
|
||
A Payment Request is defined as follows | ||
|
||
```go | ||
type PaymentRequest struct { | ||
A int `amount (optional)` | ||
U string `unit` | ||
R string `mint url (optional)` | ||
D string `description (optional)` | ||
M string `memo (optional)` | ||
T []Transport `transport` | ||
} | ||
``` | ||
|
||
while Transport is defined as | ||
|
||
```go | ||
type Transport struct { | ||
T string `type` | ||
Ta string `target` | ||
} | ||
``` | ||
thesimplekid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- amount: The amount of the requested token (payment amount) | ||
- unit: The unit of the requested token (e.g. sats) | ||
- mint: The mint to use to mint the token | ||
- description: A human readable discription that the sending wallet will display after scanning the request | ||
- transport: The method of transport chosen to transmit the created token to the sender (can be multiple, sorted by preference) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a use case where transport is empty? Or should there be a minimum of one element in the list? |
||
|
||
## Encoded Request | ||
|
||
Cashu Payment Requests can be encoded and displayed/sent as string or qr code. They underlying object is serialised using CBOR and finlly base64 encoded and prefixed with a version byte and standard prefix. | ||
|
||
_Example_ | ||
|
||
```sh | ||
cashrqAaVhQRVhVWNzYXRhTXgiaHR0cHM6Ly9taW50Lm1pbmliaXRzLmNhc2gvQml0Y29pbmFEeCNQbGVzYXNlIHBheSB0aGUgdmVyeSBmaXJzdCBjYXNodSBwcmFUgaJhVGVub3N0cmJUYXhGbnByb2ZpbGUxcXFzZG11cDZlMno2bWNwZXVlNno2a2wwOGhlNDloY2VuNXhucmMzdG5wdncwbWRndGplbWgwc3V4YTBrag | ||
``` | ||
|
||
## Reference Implementation | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/fxamacker/cbor/v2" | ||
) | ||
|
||
const ( | ||
pre = "cashrq" | ||
version = byte(0x01) | ||
) | ||
|
||
type Transport struct { | ||
T string | ||
Ta string | ||
} | ||
type PaymentRequest struct { | ||
A int | ||
U string | ||
M string | ||
D string | ||
T []Transport | ||
} | ||
|
||
func encodeRequest(pr PaymentRequest) string { | ||
b, err := cbor.Marshal(pr) | ||
if err != nil { | ||
log.Fatal("CBOR encoding failed...") | ||
} | ||
b = append([]byte{version}, b...) | ||
encodedString := base64.RawURLEncoding.EncodeToString(b) | ||
res := pre + encodedString | ||
return res | ||
} | ||
|
||
func main() { | ||
t := Transport{T: "nostr", Ta: "nprofile1qqsdmup6e2z6mcpeue6z6kl08he49hcen5xnrc3tnpvw0mdgtjemh0suxa0kj"} | ||
pr := PaymentRequest{A: 21, U: "sat", M: "https://mint.minibits.cash/Bitcoin", D: "Plesase pay the very first cashu pr", T: []Transport{t}} | ||
res := encodeRequest(pr) | ||
fmt.Printf("%s", res) | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the unit also be optional and default to sats?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that as well, however I can receivers run into compatibility issues quickly if they let users choose the unit.