migrate to single replaceable and remove units, remove wallet name and description, force all tags to be encrypted always except for "redeemed".

This commit is contained in:
fiatjaf 2025-02-01 15:17:42 -03:00
parent 195e504c00
commit c2adb4b780
2 changed files with 20 additions and 46 deletions

64
60.md

@ -17,43 +17,30 @@ The purpose of this NIP is:
This NIP doesn't deal with users' *receiving* money from someone else, it's just to keep state of the user's wallet.
# High-level flow
1. A user has a `kind:37375` event that represents a wallet.
1. A user has a `kind:17375` event that represents a wallet.
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.
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.
## Wallet Event
```jsonc
{
"kind": 37375,
"kind": 17375,
"content": nip44_encrypt([
[ "privkey", "hexkey" ],
[ "name", "my shitposting wallet" ],
[ "description", "a wallet for my day-to-day shitposting" ],
[ "mint", "https://mint1" ]
// optionally "mint" and "unit" could go here
[ "mint", "https://mint1" ],
[ "mint", "https://mint2" ]
]),
"tags": [
[ "d", "my-wallet" ],
[ "mint", "https://mint2" ],
[ "mint", "https://mint3" ],
[ "unit", "sat" ]
// optionally "name" and "description" could go here
]
"tags": []
}
```
The wallet event is an addressable event `kind:37375`.
The wallet event is an addressable event `kind:17375`.
Tags:
* `d` - wallet ID.
* `mint` - Mint(s) this wallet uses -- there MUST be one or more mint tags.
* `unit` - Base unit of the wallet (e.g. "sat", "usd", etc).
* `name` - Optional human-readable name for the wallet.
* `description` - Optional human-readable description of the wallet.
* `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.
The client or user MAY decide to put some tags either inside the encrypted `.content` or under the public `.tags`, `name` and `description`, for example. However, `d` MUST always be a public tag, and `mint` and `unit` must be public if the user intends to receive [NIP-61](61.md) nutzaps.
### Deleting a wallet event
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.
@ -79,13 +66,10 @@ There can be multiple `kind:7375` events for the same mint, and multiple proofs
// tokens that were destroyed in the creation of this token (helps on wallet state transitions)
"del": [ "token-event-id-1", "token-event-id-2" ]
}),
"tags": [
[ "a", "37375:<pubkey>:my-wallet" ]
]
"tags": []
}
```
* `a` an optional tag linking the token to a specific wallet.
* `.content` is a [NIP-44](44.md) encrypted payload:
* `mint`: The mint the proofs belong to.
* `proofs`: unecoded proofs
@ -104,26 +88,23 @@ Clients SHOULD publish `kind:7376` events to create a transaction history when t
"kind": 7376,
"content": nip44_encrypt([
[ "direction", "in" ], // in = received, out = sent
[ "amount", "1", "sat" ],
[ "e", "<event-id-of-created-token>", "<relay-hint>", "created" ],
[ "amount", "1" ],
[ "e", "<event-id-of-created-token>", "", "created" ]
]),
"tags": [
[ "a", "37375:<pubkey>:my-wallet" ],
[ "e", "<event-id-of-created-token>", "", "redeemed" ]
]
}
```
* `direction` - The direction of the transaction; `in` for received funds, `out` for sent funds.
* `a` - The wallet the transaction is related to.
Clients MUST add `e` tags to create references of destroyed and created token events along with the marker of the meaning of the tag:
* `created` - A new token event was created.
* `destroyed` - A token event was destroyed.
* `redeemed` - A [NIP-61](61.md) nutzap was redeemed.
like on Wallet events, clients or users may choose to encrypt all tags except for `a` tags and `e` tags with a `redeemed` marker unencrypted.
Multiple `e` tags can be added to a `kind:7376` event.
Multiple `e` tags can be added, and should be encrypted, except for tags with the `redeemed` marker.
# Flow
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.
@ -131,7 +112,7 @@ A client that wants to check for user's wallets information starts by fetching `
## Fetch wallet and token list
From those relays, the client should fetch wallet and token events.
`"kinds": [37375, 7375], "authors": ["<my-pubkey>"]`
`"kinds": [17375, 7375], "authors": ["<my-pubkey>"]`
## Fetch proofs
@ -150,9 +131,7 @@ If Alice spends 4 sats from this token event
{ "id": "4", "amount": 8 },
]
}),
"tags": [
[ "a", "37375:<pubkey>:my-wallet" ]
]
"tags": []
}
```
@ -171,9 +150,7 @@ Her client:
],
"del": [ "event-id-1" ]
}),
"tags": [
[ "a", "37375:<pubkey>:my-wallet" ]
]
"tags": []
}
```
* MUST delete event `event-id-1`
@ -185,17 +162,15 @@ Her client:
"content": nip44_encrypt([
[ "direction", "out" ],
[ "amount", "4", "sats" ],
[ "e", "<event-id-1>", "<relay-hint>", "destroyed" ],
[ "e", "<event-id-2>", "<relay-hint>", "created" ],
[ "e", "<event-id-1>", "", "destroyed" ],
[ "e", "<event-id-2>", "", "created" ],
]),
"tags": [
[ "a", "37375:<pubkey>:my-wallet" ],
]
"tags": []
}
```
## Redeeming a quote (optional)
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 pending).
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).
However, application developers SHOULD use local state when possible and only publish this event when it makes sense in the context of their application.
@ -205,8 +180,7 @@ However, application developers SHOULD use local state when possible and only pu
"content": nip44_encrypt("quote-id"),
"tags": [
[ "expiration", "<expiration-timestamp>" ],
[ "mint", "<mint-url>" ],
[ "a", "37375:<pubkey>:my-wallet" ]
[ "mint", "<mint-url>" ]
]
}
```

2
61.md

@ -52,7 +52,7 @@ Clients MUST prefix the public key they P2PK-lock with `"02"` (for nostr<>cashu
tags: [
[ "unit", "sat" ],
[ "proof", "{\"amount\":1,\"C\":\"02277c66191736eb72fce9d975d08e3191f8f96afb73ab1eec37e4465683066d3f\",\"id\":\"000a93d6f8a1d2c4\",\"secret\":\"[\\\"P2PK\\\",{\\\"nonce\\\":\\\"b00bdd0467b0090a25bdf2d2f0d45ac4e355c482c1418350f273a04fedaaee83\\\",\\\"data\\\":\\\"02eaee8939e3565e48cc62967e2fde9d8e2a4b3ec0081f29eceff5c64ef10ac1ed\\\"}]\"}" ],
[ "u", "https://stablenut.umint.cash", ],
[ "u", "https://stablenut.umint.cash" ],
[ "e", "<zapped-event-id>", "<relay-hint>" ],
[ "p", "e9fbced3a42dcf551486650cc752ab354347dd413b307484e4fd1818ab53f991" ], // recipient of nutzap
]