upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/60.md
diff options
context:
space:
mode:
authorfiatjaf_ <fiatjaf@gmail.com>2025-02-03 22:36:27 -0300
committerGitHub <noreply@github.com>2025-02-03 22:36:27 -0300
commit5a857e8bf8b88e14a98b1fcff4932034091c9b5c (patch)
tree0ccfa9eef2148d560ae1096078dbc491401c43e5 /60.md
parent93568e39717cd61ff855dc24e4f0ee30a6051f6c (diff)
nip60/61 updates and simplifications (#1730)
Co-authored-by: Tiago Balas <eskema23@gmail.com>
Diffstat (limited to '60.md')
-rw-r--r--60.md98
1 files changed, 36 insertions, 62 deletions
diff --git a/60.md b/60.md
index 69db44f..87449d2 100644
--- a/60.md
+++ b/60.md
@@ -1,5 +1,9 @@
1# NIP-60 1NIP-60
2## Cashu Wallet 2======
3
4Cashu Wallets
5-------------
6
3`draft` `optional` 7`draft` `optional`
4 8
5This NIP defines the operations of a cashu-based wallet. 9This NIP defines the operations of a cashu-based wallet.
@@ -13,48 +17,28 @@ The purpose of this NIP is:
13This NIP doesn't deal with users' *receiving* money from someone else, it's just to keep state of the user's wallet. 17This NIP doesn't deal with users' *receiving* money from someone else, it's just to keep state of the user's wallet.
14 18
15# High-level flow 19# High-level flow
161. A user has a `kind:37375` event that represents a wallet. 201. A user has a `kind:17375` event that represents a wallet.
172. A user has `kind:7375` events that represent the unspent proofs of the wallet. -- The proofs are encrypted with the user's private key. 212. A user has `kind:7375` events that represent the unspent proofs of the wallet. -- The proofs are encrypted with the user's private key.
183. 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. 223. 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.
19 23
20## Wallet Event 24## Wallet Event
21```jsonc 25```jsonc
22{ 26{
23 "kind": 37375, 27 "kind": 17375,
24 "content": nip44_encrypt([ 28 "content": nip44_encrypt([
25 [ "balance", "100", "sat" ], 29 [ "privkey", "hexkey" ],
26 [ "privkey", "hexkey" ] // explained in NIP-61
27 ]),
28 "tags": [
29 [ "d", "my-wallet" ],
30 [ "mint", "https://mint1" ], 30 [ "mint", "https://mint1" ],
31 [ "mint", "https://mint2" ], 31 [ "mint", "https://mint2" ]
32 [ "mint", "https://mint3" ], 32 ]),
33 [ "name", "my shitposting wallet" ], 33 "tags": []
34 [ "unit", "sat" ],
35 [ "description", "a wallet for my day-to-day shitposting" ],
36 [ "relay", "wss://relay1" ],
37 [ "relay", "wss://relay2" ],
38 ]
39} 34}
40``` 35```
41 36
42The wallet event is an addressable event `kind:37375`. 37The wallet event is an replaceable event `kind:17375`.
43 38
44Tags: 39Tags:
45* `d` - wallet ID.
46* `mint` - Mint(s) this wallet uses -- there MUST be one or more mint tags. 40* `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). 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.
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
54Any tag, other than the `d` tag, can be [NIP-44](44.md) encrypted into the `.content` field.
55
56### Deleting a wallet event
57Due 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.
58 42
59## Token Event 43## Token Event
60Token events are used to record unspent proofs. 44Token events are used to record unspent proofs.
@@ -67,6 +51,7 @@ There can be multiple `kind:7375` events for the same mint, and multiple proofs
67 "content": nip44_encrypt({ 51 "content": nip44_encrypt({
68 "mint": "https://stablenut.umint.cash", 52 "mint": "https://stablenut.umint.cash",
69 "proofs": [ 53 "proofs": [
54 // one or more proofs in the default cashu format
70 { 55 {
71 "id": "005c2502034d4f12", 56 "id": "005c2502034d4f12",
72 "amount": 1, 57 "amount": 1,
@@ -74,23 +59,21 @@ There can be multiple `kind:7375` events for the same mint, and multiple proofs
74 "C": "0241d98a8197ef238a192d47edf191a9de78b657308937b4f7dd0aa53beae72c46" 59 "C": "0241d98a8197ef238a192d47edf191a9de78b657308937b4f7dd0aa53beae72c46"
75 } 60 }
76 ], 61 ],
77 // tokens that were destroyed in the creation of this token 62 // tokens that were destroyed in the creation of this token (helps on wallet state transitions)
78 "del": [ "token-id-1" ] 63 "del": [ "token-event-id-1", "token-event-id-2" ]
79 }), 64 }),
80 "tags": [ 65 "tags": []
81 [ "a", "37375:<pubkey>:my-wallet" ]
82 ]
83} 66}
84``` 67```
85 68
86 * `a` an optional tag linking the token to a specific wallet. 69 * `.content` is a [NIP-44](44.md) encrypted payload:
87 * `.content` is a [[NIP-44]] encrypted payload:
88 * `mint`: The mint the proofs belong to. 70 * `mint`: The mint the proofs belong to.
89 * `proofs`: unecoded proofs 71 * `proofs`: unecoded proofs
90 * `del`: token-ids that were destroyed by the creation of this token. This assists with state transitions. 72 * `del`: token-ids that were destroyed by the creation of this token. This assists with state transitions.
91 73
92### Spending proofs 74When 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).
93When 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. 75
76The `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.
94 77
95## Spending History Event 78## Spending History Event
96Clients SHOULD publish `kind:7376` events to create a transaction history when their balance changes. 79Clients 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
100 "kind": 7376, 83 "kind": 7376,
101 "content": nip44_encrypt([ 84 "content": nip44_encrypt([
102 [ "direction", "in" ], // in = received, out = sent 85 [ "direction", "in" ], // in = received, out = sent
103 [ "amount", "1", "sat" ], 86 [ "amount", "1" ],
104 [ "e", "<event-id-of-created-token>", "<relay-hint>", "created" ], 87 [ "e", "<event-id-of-created-token>", "", "created" ]
105 ]), 88 ]),
106 "tags": [ 89 "tags": [
107 [ "a", "37375:<pubkey>:my-wallet" ], 90 [ "e", "<event-id-of-created-token>", "", "redeemed" ]
108 ] 91 ]
109} 92}
110``` 93```
111 94
112* `direction` - The direction of the transaction; `in` for received funds, `out` for sent funds. 95* `direction` - The direction of the transaction; `in` for received funds, `out` for sent funds.
113* `a` - The wallet the transaction is related to.
114 96
115Clients MUST add `e` tags to create references of destroyed and created token events along with the marker of the meaning of the tag: 97Clients MUST add `e` tags to create references of destroyed and created token events along with the marker of the meaning of the tag:
116* `created` - A new token event was created. 98* `created` - A new token event was created.
@@ -119,7 +101,7 @@ Clients MUST add `e` tags to create references of destroyed and created token ev
119 101
120All tags can be [NIP-44](44.md) encrypted. Clients SHOULD leave `e` tags with a `redeemed` marker unencrypted. 102All tags can be [NIP-44](44.md) encrypted. Clients SHOULD leave `e` tags with a `redeemed` marker unencrypted.
121 103
122Multiple `e` tags can be added to a `kind:7376` event. 104Multiple `e` tags can be added, and should be encrypted, except for tags with the `redeemed` marker.
123 105
124# Flow 106# Flow
125A 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. 107A 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.
@@ -127,10 +109,9 @@ A client that wants to check for user's wallets information starts by fetching `
127## Fetch wallet and token list 109## Fetch wallet and token list
128From those relays, the client should fetch wallet and token events. 110From those relays, the client should fetch wallet and token events.
129 111
130`"kinds": [37375, 7375], "authors": ["<my-pubkey>"]` 112`"kinds": [17375, 7375], "authors": ["<my-pubkey>"]`
131 113
132## Fetch proofs 114## Fetch proofs
133While 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.
134 115
135## Spending token 116## Spending token
136If Alice spends 4 sats from this token event 117If Alice spends 4 sats from this token event
@@ -147,9 +128,7 @@ If Alice spends 4 sats from this token event
147 { "id": "4", "amount": 8 }, 128 { "id": "4", "amount": 8 },
148 ] 129 ]
149 }), 130 }),
150 "tags": [ 131 "tags": []
151 [ "a", "37375:<pubkey>:my-wallet" ]
152 ]
153} 132}
154``` 133```
155 134
@@ -168,9 +147,7 @@ Her client:
168 ], 147 ],
169 "del": [ "event-id-1" ] 148 "del": [ "event-id-1" ]
170 }), 149 }),
171 "tags": [ 150 "tags": []
172 [ "a", "37375:<pubkey>:my-wallet" ]
173 ]
174} 151}
175``` 152```
176* MUST delete event `event-id-1` 153* MUST delete event `event-id-1`
@@ -181,20 +158,18 @@ Her client:
181 "kind": 7376, 158 "kind": 7376,
182 "content": nip44_encrypt([ 159 "content": nip44_encrypt([
183 [ "direction", "out" ], 160 [ "direction", "out" ],
184 [ "amount", "4", "sats" ], 161 [ "amount", "4" ],
185 [ "e", "<event-id-1>", "<relay-hint>", "destroyed" ], 162 [ "e", "<event-id-1>", "", "destroyed" ],
186 [ "e", "<event-id-2>", "<relay-hint>", "created" ], 163 [ "e", "<event-id-2>", "", "created" ],
187 ]), 164 ]),
188 "tags": [ 165 "tags": []
189 [ "a", "37375:<pubkey>:my-wallet" ],
190 ]
191} 166}
192``` 167```
193 168
194## Redeeming a quote (optional) 169## Redeeming a quote (optional)
195When 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. 170When 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).
196 171
197Application developers are encouraged to use local state when possible and only publish this event when it makes sense in the context of their application. 172However, application developers SHOULD use local state when possible and only publish this event when it makes sense in the context of their application.
198 173
199```jsonc 174```jsonc
200{ 175{
@@ -202,8 +177,7 @@ Application developers are encouraged to use local state when possible and only
202 "content": nip44_encrypt("quote-id"), 177 "content": nip44_encrypt("quote-id"),
203 "tags": [ 178 "tags": [
204 [ "expiration", "<expiration-timestamp>" ], 179 [ "expiration", "<expiration-timestamp>" ],
205 [ "mint", "<mint-url>" ], 180 [ "mint", "<mint-url>" ]
206 [ "a", "37375:<pubkey>:my-wallet" ]
207 ] 181 ]
208} 182}
209``` 183```