Skip to content

Commit 5a857e8

Browse files
fiatjafeskema
andauthored
nip60/61 updates and simplifications (#1730)
Co-authored-by: Tiago Balas <[email protected]>
1 parent 93568e3 commit 5a857e8

File tree

2 files changed

+75
-111
lines changed

2 files changed

+75
-111
lines changed

60.md

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# NIP-60
2-
## Cashu Wallet
1+
NIP-60
2+
======
3+
4+
Cashu Wallets
5+
-------------
6+
37
`draft` `optional`
48

59
This NIP defines the operations of a cashu-based wallet.
@@ -13,48 +17,28 @@ The purpose of this NIP is:
1317
This NIP doesn't deal with users' *receiving* money from someone else, it's just to keep state of the user's wallet.
1418

1519
# High-level flow
16-
1. A user has a `kind:37375` event that represents a wallet.
20+
1. A user has a `kind:17375` event that represents a wallet.
1721
2. A user has `kind:7375` events that represent the unspent proofs of the wallet. -- The proofs are encrypted with the user's private key.
1822
3. A user has `kind:7376` events that represent the spending history of the wallet -- This history is for informational purposes only and is completely optional.
1923

2024
## Wallet Event
2125
```jsonc
2226
{
23-
"kind": 37375,
27+
"kind": 17375,
2428
"content": nip44_encrypt([
25-
[ "balance", "100", "sat" ],
26-
[ "privkey", "hexkey" ] // explained in NIP-61
27-
]),
28-
"tags": [
29-
[ "d", "my-wallet" ],
29+
[ "privkey", "hexkey" ],
3030
[ "mint", "https://mint1" ],
31-
[ "mint", "https://mint2" ],
32-
[ "mint", "https://mint3" ],
33-
[ "name", "my shitposting wallet" ],
34-
[ "unit", "sat" ],
35-
[ "description", "a wallet for my day-to-day shitposting" ],
36-
[ "relay", "wss://relay1" ],
37-
[ "relay", "wss://relay2" ],
38-
]
31+
[ "mint", "https://mint2" ]
32+
]),
33+
"tags": []
3934
}
4035
```
4136

42-
The wallet event is an addressable event `kind:37375`.
37+
The wallet event is an replaceable event `kind:17375`.
4338

4439
Tags:
45-
* `d` - wallet ID.
4640
* `mint` - Mint(s) this wallet uses -- there MUST be one or more mint tags.
47-
* `relay` - Relays where the wallet and related events can be found. -- one or more relays SHOULD be specified. If missing, clients should follow [NIP-65](65.md).
48-
* `unit` - Base unit of the wallet (e.g. "sat", "usd", etc).
49-
* `name` - Optional human-readable name for the wallet.
50-
* `description` - Optional human-readable description of the wallet.
51-
* `balance` - Optional best-effort balance of the wallet that can serve as a placeholder while an accurate balance is computed from fetching all unspent proofs.
52-
* `privkey` - Private key used to unlock P2PK ecash. MUST be stored encrypted in the `.content` field. **This is a different private key exclusively used for the wallet, not associated in any way to the user's nostr private key** -- This is only used when receiving funds from others, described in NIP-61.
53-
54-
Any tag, other than the `d` tag, can be [NIP-44](44.md) encrypted into the `.content` field.
55-
56-
### Deleting a wallet event
57-
Due to addressable event being hard to delete, if a user wants to delete a wallet, they should empty the event and keep just the `d` identifier and add a `deleted` tag.
41+
* `privkey` - Private key used to unlock P2PK ecash. MUST be stored encrypted in the `.content` field. **This is a different private key exclusively used for the wallet, not associated in any way to the user's Nostr private key** -- This is only used for receiving [NIP-61](61.md) nutzaps.
5842

5943
## Token Event
6044
Token events are used to record unspent proofs.
@@ -67,30 +51,29 @@ There can be multiple `kind:7375` events for the same mint, and multiple proofs
6751
"content": nip44_encrypt({
6852
"mint": "https://stablenut.umint.cash",
6953
"proofs": [
54+
// one or more proofs in the default cashu format
7055
{
7156
"id": "005c2502034d4f12",
7257
"amount": 1,
7358
"secret": "z+zyxAVLRqN9lEjxuNPSyRJzEstbl69Jc1vtimvtkPg=",
7459
"C": "0241d98a8197ef238a192d47edf191a9de78b657308937b4f7dd0aa53beae72c46"
7560
}
7661
],
77-
// tokens that were destroyed in the creation of this token
78-
"del": [ "token-id-1" ]
62+
// tokens that were destroyed in the creation of this token (helps on wallet state transitions)
63+
"del": [ "token-event-id-1", "token-event-id-2" ]
7964
}),
80-
"tags": [
81-
[ "a", "37375:<pubkey>:my-wallet" ]
82-
]
65+
"tags": []
8366
}
8467
```
8568

86-
* `a` an optional tag linking the token to a specific wallet.
87-
* `.content` is a [[NIP-44]] encrypted payload:
69+
* `.content` is a [NIP-44](44.md) encrypted payload:
8870
* `mint`: The mint the proofs belong to.
8971
* `proofs`: unecoded proofs
9072
* `del`: token-ids that were destroyed by the creation of this token. This assists with state transitions.
9173

92-
### Spending proofs
93-
When one or more proofs of a token are spent, the token event should be [NIP-09](09.md)-deleted and, if some proofs are unspent from the same token event, a new token event should be created rolling over the unspent proofs and adding any change outputs to the new token event.
74+
When one or more proofs of a token are spent, the token event should be [NIP-09](09.md)-deleted and, if some proofs are unspent from the same token event, a new token event should be created rolling over the unspent proofs and adding any change outputs to the new token event (the change output should include a `del` field).
75+
76+
The `kind:5` _delete event_ created in the [NIP-09](09.md) process MUST have a tag `["k", "7375"]` to allow easy filtering by clients interested in state transitions.
9477

9578
## Spending History Event
9679
Clients SHOULD publish `kind:7376` events to create a transaction history when their balance changes.
@@ -100,17 +83,16 @@ Clients SHOULD publish `kind:7376` events to create a transaction history when t
10083
"kind": 7376,
10184
"content": nip44_encrypt([
10285
[ "direction", "in" ], // in = received, out = sent
103-
[ "amount", "1", "sat" ],
104-
[ "e", "<event-id-of-created-token>", "<relay-hint>", "created" ],
86+
[ "amount", "1" ],
87+
[ "e", "<event-id-of-created-token>", "", "created" ]
10588
]),
10689
"tags": [
107-
[ "a", "37375:<pubkey>:my-wallet" ],
90+
[ "e", "<event-id-of-created-token>", "", "redeemed" ]
10891
]
10992
}
11093
```
11194

11295
* `direction` - The direction of the transaction; `in` for received funds, `out` for sent funds.
113-
* `a` - The wallet the transaction is related to.
11496

11597
Clients MUST add `e` tags to create references of destroyed and created token events along with the marker of the meaning of the tag:
11698
* `created` - A new token event was created.
@@ -119,18 +101,17 @@ Clients MUST add `e` tags to create references of destroyed and created token ev
119101

120102
All tags can be [NIP-44](44.md) encrypted. Clients SHOULD leave `e` tags with a `redeemed` marker unencrypted.
121103

122-
Multiple `e` tags can be added to a `kind:7376` event.
104+
Multiple `e` tags can be added, and should be encrypted, except for tags with the `redeemed` marker.
123105

124106
# Flow
125107
A client that wants to check for user's wallets information starts by fetching `kind:10019` events from the user's relays, if no event is found, it should fall back to using the user's [NIP-65](65.md) relays.
126108

127109
## Fetch wallet and token list
128110
From those relays, the client should fetch wallet and token events.
129111

130-
`"kinds": [37375, 7375], "authors": ["<my-pubkey>"]`
112+
`"kinds": [17375, 7375], "authors": ["<my-pubkey>"]`
131113

132114
## Fetch proofs
133-
While the client is fetching (and perhaps validating) proofs it can use the optional `balance` tag of the wallet event to display a estimate of the balance of the wallet.
134115

135116
## Spending token
136117
If Alice spends 4 sats from this token event
@@ -147,9 +128,7 @@ If Alice spends 4 sats from this token event
147128
{ "id": "4", "amount": 8 },
148129
]
149130
}),
150-
"tags": [
151-
[ "a", "37375:<pubkey>:my-wallet" ]
152-
]
131+
"tags": []
153132
}
154133
```
155134

@@ -168,9 +147,7 @@ Her client:
168147
],
169148
"del": [ "event-id-1" ]
170149
}),
171-
"tags": [
172-
[ "a", "37375:<pubkey>:my-wallet" ]
173-
]
150+
"tags": []
174151
}
175152
```
176153
* MUST delete event `event-id-1`
@@ -181,29 +158,26 @@ Her client:
181158
"kind": 7376,
182159
"content": nip44_encrypt([
183160
[ "direction", "out" ],
184-
[ "amount", "4", "sats" ],
185-
[ "e", "<event-id-1>", "<relay-hint>", "destroyed" ],
186-
[ "e", "<event-id-2>", "<relay-hint>", "created" ],
161+
[ "amount", "4" ],
162+
[ "e", "<event-id-1>", "", "destroyed" ],
163+
[ "e", "<event-id-2>", "", "created" ],
187164
]),
188-
"tags": [
189-
[ "a", "37375:<pubkey>:my-wallet" ],
190-
]
165+
"tags": []
191166
}
192167
```
193168

194169
## Redeeming a quote (optional)
195-
When creating a quote at a mint, an event can be used to keep the state of the quote ID, which will be used to check when the quote has been paid. These events should be created with an expiration tag [NIP-40](40.md) matching the expiration of the bolt11 received from the mint; this signals to relays when they can safely discard these events.
170+
When creating a quote at a mint, an event can be used to keep the state of the quote ID, which will be used to check when the quote has been paid. These events should be created with an expiration tag [NIP-40](40.md) of 2 weeks (which is around the maximum amount of time a Lightning payment may be in-flight).
196171

197-
Application developers are encouraged to use local state when possible and only publish this event when it makes sense in the context of their application.
172+
However, application developers SHOULD use local state when possible and only publish this event when it makes sense in the context of their application.
198173

199174
```jsonc
200175
{
201176
"kind": 7374,
202177
"content": nip44_encrypt("quote-id"),
203178
"tags": [
204179
[ "expiration", "<expiration-timestamp>" ],
205-
[ "mint", "<mint-url>" ],
206-
[ "a", "37375:<pubkey>:my-wallet" ]
180+
[ "mint", "<mint-url>" ]
207181
]
208182
}
209183
```

61.md

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
# NIP-61:
2-
## Nut Zaps
1+
NIP-61
2+
======
33

4-
A Nut Zap is a P2PK cashu token where the payment itself is the receipt.
4+
Nutzaps
5+
-------
6+
7+
`draft` `optional`
8+
9+
A Nutzap is a P2PK Cashu token in which the payment itself is the receipt.
510

611
# High-level flow
712
Alice wants to nutzap 1 sat to Bob because of an event `event-id-1` she liked.
813

914
## Alice nutzaps Bob
1015
1. Alice fetches event `kind:10019` from Bob to see the mints Bob trusts.
11-
2. She mints a token at that mint (or swaps some tokens she already had in that mint) p2pk-locked to the pubkey Bob has listed in his `kind:10019`.
16+
2. She mints a token at that mint (or swaps some tokens she already had in that mint) P2PK-locked to the pubkey Bob has listed in his `kind:10019`.
1217
3. She publishes a `kind:9321` event to the relays Bob indicated with the proofs she minted.
1318

1419
## Bob receives the nutzap
@@ -29,65 +34,57 @@ Alice wants to nutzap 1 sat to Bob because of an event `event-id-1` she liked.
2934
}
3035
```
3136

32-
`kind:10019` is an event that is useful for others to know how to send money to the user.
33-
34-
* `relay` - Relays where the user will be reading token events from. If a user wants to send money to the user, they should write to these relays.
35-
* `mint` - Mints the user is explicitly agreeing to use to receive funds on. Clients SHOULD not send money on mints not listed here or risk burning their money. Additional markers can be used to list the supported base units of the mint.
36-
* `pubkey` - Pubkey that SHOULD be used to P2PK-lock receiving nutzaps. If not present, clients SHOULD use the pubkey of the recipient. This is explained in Appendix 1.
37+
* `kind:10019` is an event that is useful for others to know how to send money to the user.
38+
* `relay`: relays where the user will be reading token events from. If a user wants to send money to the user, they should write to these relays.
39+
* `mint`: mints the user is explicitly agreeing to use to receive funds on. Clients SHOULD not send money on mints not listed here or risk burning their money. Additional markers can be used to list the supported base units of the mint.
40+
* `pubkey`: Public key that MUST be used to P2PK-lock receiving nutzaps -- implementations MUST NOT use the target user's main Nostr public key. This public key corresponds to the `privkey` field encrypted in a user's [nip-60](60.md) _wallet event_.
3741

3842
## Nutzap event
39-
Event `kind:9321` is a nutzap event published by the sender, p-tagging the recipient. The outputs are P2PK-locked to the pubkey the recipient indicated in their `kind:10019` event or to the recipient pubkey if the `kind:10019` event doesn't have a explicit pubkey.
43+
Event `kind:9321` is a nutzap event published by the sender, p-tagging the recipient. The outputs are P2PK-locked to the public key the recipient indicated in their `kind:10019` event.
4044

41-
Clients MUST prefix the pubkey they p2pk-lock with `"02"` (for nostr<>cashu pubkey compatibility).
45+
Clients MUST prefix the public key they P2PK-lock with `"02"` (for nostr<>cashu compatibility).
4246

4347
```jsonc
4448
{
4549
kind: 9321,
4650
content: "Thanks for this great idea.",
4751
pubkey: "sender-pubkey",
4852
tags: [
49-
[ "amount", "1" ],
50-
[ "unit", "sat" ],
5153
[ "proof", "{\"amount\":1,\"C\":\"02277c66191736eb72fce9d975d08e3191f8f96afb73ab1eec37e4465683066d3f\",\"id\":\"000a93d6f8a1d2c4\",\"secret\":\"[\\\"P2PK\\\",{\\\"nonce\\\":\\\"b00bdd0467b0090a25bdf2d2f0d45ac4e355c482c1418350f273a04fedaaee83\\\",\\\"data\\\":\\\"02eaee8939e3565e48cc62967e2fde9d8e2a4b3ec0081f29eceff5c64ef10ac1ed\\\"}]\"}" ],
52-
[ "u", "https://stablenut.umint.cash", ],
54+
[ "u", "https://stablenut.umint.cash" ],
5355
[ "e", "<zapped-event-id>", "<relay-hint>" ],
54-
[ "p", "e9fbced3a42dcf551486650cc752ab354347dd413b307484e4fd1818ab53f991" ], // recipient of nut zap
56+
[ "p", "e9fbced3a42dcf551486650cc752ab354347dd413b307484e4fd1818ab53f991" ], // recipient of nutzap
5557
]
5658
}
5759
```
5860

5961
* `.content` is an optional comment for the nutzap
60-
* `amount` is a shorthand for the combined amount of all outputs. -- Clients SHOULD validate that the sum of the amounts in the outputs matches.
61-
* `unit` is the base unit of the amount.
62-
* `proof` is one ore more proofs p2pk-locked to the pubkey the recipient specified in their `kind:10019` event.
63-
* `u` is the mint the URL of the mint EXACTLY as specified by the recipient's `kind:10019`.
64-
* `e` zero or one event that is being nutzapped.
65-
* `p` exactly one pubkey, specifying the recipient of the nutzap.
66-
67-
WIP: Clients SHOULD embed a DLEQ proof in the nutzap event to make it possible to verify nutzaps without talking to the mint.
62+
* `.tags`:
63+
* `proof` is one ore more proofs P2PK-locked to the public key the recipient specified in their `kind:10019` event and including a DLEQ proof.
64+
* `u` is the mint the URL of the mint EXACTLY as specified by the recipient's `kind:10019`.
65+
* `p` is the Nostr identity public key of nutzap recipient.
66+
* `e` is the event that is being nutzapped, if any.
6867

6968
# Sending a nutzap
7069

7170
* The sender fetches the recipient's `kind:10019`.
7271
* The sender mints/swaps ecash on one of the recipient's listed mints.
73-
* The sender p2pk locks to the recipient's specified pubkey in their `kind:10019`
72+
* The sender P2PK-locks to the recipient's specified public key in their `kind:10019`
7473

7574
# Receiving nutzaps
7675

77-
Clients should REQ for nut zaps:
76+
Clients should REQ for nutzaps:
7877
* Filtering with `#u` for mints they expect to receive ecash from.
7978
* this is to prevent even interacting with mints the user hasn't explicitly signaled.
8079
* Filtering with `since` of the most recent `kind:7376` event the same user has created.
81-
* this can be used as a marker of the nut zaps that have already been swaped by the user -- clients might choose to use other kinds of markers, including internal state -- this is just a guidance of one possible approach.
82-
83-
Clients MIGHT choose to use some kind of filtering (e.g. WoT) to ignore spam.
80+
* this can be used as a marker of the nutzaps that have already been swaped by the user -- clients might choose to use other kinds of markers, including internal state -- this is just a guidance of one possible approach.
8481

85-
`{ "kinds": [9321], "#p": "my-pubkey", "#u": [ "<mint-1>", "<mint-2>"], "since": <latest-created_at-of-kind-7376> }`.
82+
`{ "kinds": [9321], "#p": ["my-pubkey"], "#u": ["<mint-1>", "<mint-2>"], "since": <latest-created_at-of-kind-7376> }`.
8683

87-
Upon receiving a new nut zap, the client should swap the tokens into a wallet the user controls, either a [[NIP-60]] wallet, their own LN wallet or anything else.
84+
Upon receiving a new nutzap, the client should swap the tokens into a wallet the user controls, either a [NIP-60](60.md) wallet, their own LN wallet or anything else.
8885

8986
## Updating nutzap-redemption history
90-
When claiming a token the client SHOULD create a `kind:7376` event and `e` tag the original nut zap event. This is to record that this token has already been claimed (and shouldn't be attempted again) and as signaling to the recipient that the ecash has been redeemed.
87+
When claiming a token the client SHOULD create a `kind:7376` event and `e` tag the original nutzap event. This is to record that this token has already been claimed (and shouldn't be attempted again) and as signaling to the recipient that the ecash has been redeemed.
9188

9289
Multiple `kind:9321` events can be tagged in the same `kind:7376` event.
9390

@@ -96,7 +93,7 @@ Multiple `kind:9321` events can be tagged in the same `kind:7376` event.
9693
"kind": 7376,
9794
"content": nip44_encrypt([
9895
[ "direction", "in" ], // in = received, out = sent
99-
[ "amount", "1", "sat" ],
96+
[ "amount", "1" ],
10097
[ "e", "<7375-event-id>", "relay-hint", "created" ] // new token event that was created
10198
]),
10299
"tags": [
@@ -107,26 +104,19 @@ Multiple `kind:9321` events can be tagged in the same `kind:7376` event.
107104
}
108105
```
109106

110-
Events that redeem a nutzap SHOULD be published to the sender's [[NIP-65]] relays.
107+
Events that redeem a nutzap SHOULD be published to the sender's [NIP-65](65.md) "read" relays.
111108

112109
## Verifying a Cashu Zap
113-
* Clients SHOULD check that the receiving user has issued a `kind:10019` tagging the mint where the cashu has been minted.
114-
* Clients SHOULD check that the token is locked to the pubkey the user has listed in their `kind:10019`.
110+
When listing or counting zaps received by any given event, observer clients SHOULD:
115111

116-
## Final Considerations
112+
* check that the receiving user has issued a `kind:10019` tagging the mint where the cashu has been minted.
113+
* check that the token is locked to the pubkey the user has listed in their `kind:10019`.
114+
* look at the `u` tag and check that the token is issued in one of the mints listed in the `kind:10019`.
115+
* locally verify the DLEQ proof of the tokens being sent.
117116

118-
1. Clients SHOULD guide their users to use NUT-11 (P2PK) compatible-mints in their `kind:10019` event to avoid receiving nut zaps anyone can spend
117+
All these checks can be done offline (as long as the observer has the receiver mints' keyset and their `kind:10019` event), so the process should be reasonably fast.
119118

119+
## Final Considerations
120+
1. Clients SHOULD guide their users to use NUT-11 (P2PK) and NUT-12 (DLEQ proofs) compatible-mints in their `kind:10019` event to avoid receiving nutzaps anyone can spend.
120121
2. Clients SHOULD normalize and deduplicate mint URLs as described in NIP-65.
121-
122-
3. A nut zap MUST be sent to a mint the recipient has listed in their `kind:10019` event or to the NIP-65 relays of the recipient, failure to do so may result in the recipient donating the tokens to the mint since the recipient might never see the event.
123-
124-
## Appendix 1: Alternative P2PK pubkey
125-
Clients might not have access to the user's private key (i.e. NIP-07, NIP-46 signing) and, as such, the private key to sign cashu spends might not be available, which would make spending the P2PK incoming nutzaps impossible.
126-
127-
For this scenarios clients can:
128-
129-
* add a `pubkey` tag to the `kind:10019` (indicating which pubkey senders should P2PK to)
130-
* store the private key in the `kind:37375` event in the nip44-encrypted `content` field.
131-
132-
This is to avoid depending on NIP-07/46 adaptations to sign cashu payloads.
122+
3. A nutzap event MUST include proofs in one of the mints the recipient has listed in their `kind:10019` and published to the NIP-65 relays of the recipient, failure to do so may result in the recipient donating the tokens to the mint since the recipient might never see the event.

0 commit comments

Comments
 (0)