Why Nostr? What is Njump?
Kind 30818
This is a wiki article about NIP-60: Cashu Wallet You can read it on https://wikifreedia.xyz/a/naddr1qvzqqqrcvgpqqqgmwaehxw309a6xsetxdaex2um59ehx7um5wgcjucm0d5hsqyrwd9cz6cmpwd582tthv9kxcet5xaq5mx
Author Public Key
npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft
Published at
2024-08-07 13:31:26
Kind type
30818
Event JSON
{ "id": "a1fc8018cd60eec7287032dc91e79dcafb1ed82af374909888b08c20aa2d2fca", "pubkey": "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52", "created_at": 1723037486, "kind": 30818, "tags": [ [ "d", "nip-cashu-wallet" ], [ "client", "wikifreedia", "31990:fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52:1716498133442" ], [ "alt", "This is a wiki article about NIP-60: Cashu Wallet\n\nYou can read it on https://wikifreedia.xyz/a/naddr1qvzqqqrcvgpqqqgmwaehxw309a6xsetxdaex2um59ehx7um5wgcjucm0d5hsqyrwd9cz6cmpwd582tthv9kxcet5xaq5mx" ], [ "title", "NIP-60: Cashu Wallet" ], [ "c", "Nostr" ], [ "published_at", "1723037486" ] ], "content": "# NIP-60\n## Cashu Wallet\n`draft` `optional`\n\nThis NIP defines the operations of a cashu-based wallet.\n\nA cashu wallet is a wallet which information is stored in relays to make it accessible across applications.\n\nThe purpose of this NIP is:\n* ease-of-use: new users immediately are able to receive funds without creating accounts with other services.\n* interoperability: users' wallets follows them across applications.\n\nThis NIP doesn't deal with users' *receiving* money from someone else, it's just to keep state of the user's wallet.\n\n# High-level flow\n1. A user has a `kind:37375` event that represents a wallet.\n2. A user has `kind:7375` events that represent the unspent proofs of the wallet. -- The proofs are encrypted with the user's private key.\n3. 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.\n\n## Wallet Event\n```jsonc\n{\n \"kind\": 37375,\n \"content\": nip44_encrypt([\n [ \"balance\", \"100\", \"sat\" ],\n [ \"privkey\", \"hexkey\" ] // explained in NIP-61\n ]),\n \"tags\": [\n [ \"d\", \"my-wallet\" ],\n [ \"mint\", \"https://mint1\" ],\n [ \"mint\", \"https://mint2\" ],\n [ \"mint\", \"https://mint3\" ],\n [ \"name\", \"my shitposting wallet\" ],\n [ \"unit\", \"sat\" ],\n [ \"description\", \"a wallet for my day-to-day shitposting\" ],\n [ \"relay\", \"wss://relay1\" ],\n [ \"relay\", \"wss://relay2\" ],\n ]\n}\n```\n\nThe wallet event is a parameterized replaceable event `kind:37375`.\n\nTags:\n* `d` - wallet ID.\n* `mint` - Mint(s) this wallet uses -- there MUST be one or more mint tags.\n* `relay` - Relays where the wallet and related events can be found. -- one ore more relays SHOULD be specified. If missing, clients should follow [[NIP-65]].\n* `unit` - Base unit of the wallet (e.g. \"sats\", \"usd\", etc).\n* `name` - Optional human-readable name for the wallet.\n* `description` - Optional human-readable description of the wallet.\n* `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.\n* `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.\n\nAny tag, other than the `d` tag, can be [[NIP-44]] encrypted into the `.content` field.\n\n### Deleting a wallet event\nDue to PRE 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.\n\n## Token Event\nToken events are used to record the unspent proofs that come from the mint.\n\nThere can be multiple `kind:7375` events for the same mint, and multiple proofs inside each `kind:7375` event.\n\n```jsonc\n{\n \"kind\": 7375,\n \"content\": nip44_encrypt({\n \"mint\": \"https://stablenut.umint.cash\",\n \"proofs\": [\n {\n \"id\": \"005c2502034d4f12\",\n \"amount\": 1,\n \"secret\": \"z+zyxAVLRqN9lEjxuNPSyRJzEstbl69Jc1vtimvtkPg=\",\n \"C\": \"0241d98a8197ef238a192d47edf191a9de78b657308937b4f7dd0aa53beae72c46\"\n }\n ]\n }),\n \"tags\": [\n [ \"a\", \"37375:\u003cpubkey\u003e:my-wallet\" ]\n ]\n}\n```\n\n`.content` is a [[NIP-44]] encrypted payload storing the mint and the unencoded proofs.\n* `a` an optional tag linking the token to a specific wallet.\n\n### Spending proofs\nWhen one or more proofs of a token are spent, the token event should be [[NIP-09]]-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.\n\n## Spending History Event\nClients SHOULD publish `kind:7376` events to create a transaction history when their balance changes.\n\n```jsonc\n{\n \"kind\": 7376,\n \"content\": nip44_encrypt([\n [ \"direction\", \"in\" ], // in = received, out = sent\n [ \"amount\", \"1\", \"sats\" ],\n [ \"e\", \"\u003cevent-id-of-spent-token\u003e\", \"\u003crelay-hint\u003e\", \"created\" ],\n ]),\n \"tags\": [\n [ \"a\", \"37375:\u003cpubkey\u003e:my-wallet\" ],\n ]\n}\n```\n\n* `direction` - The direction of the transaction; `in` for received funds, `out` for sent funds.\n* `a` - The wallet the transaction is related to.\n\nClients MUST add `e` tags to create references of destroyed and created token events along with the marker of the meaning of the tag:\n* `created` - A new token event was created.\n* `destroyed` - A token event was destroyed.\n* `redeemed` - A [[NIP-61]] nutzap was redeemed.\n\nAll tags can be [[NIP-44]] encrypted. Clients SHOULD leave `e` tags with a `redeemed` marker unencrypted.\n\nMultiple `e` tags can be added to a `kind:7376` event.\n\n# Flow\nA 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]] relays.\n\n## Fetch wallet and token list\nFrom those relays, the client should fetch wallet and token events.\n\n`\"kinds\": [37375, 7375], \"authors\": [\"\u003cmy-pubkey\u003e\"]`\n\n## Fetch proofs\nWhile 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.\n\n## Spending token\nIf Alice spends 4 sats from this token event\n```jsonconc\n{\n \"kind\": 7375,\n \"id\": \"event-id-1\",\n \"content\": nip44_encrypt({\n \"mint\": \"https://stablenut.umint.cash\",\n \"proofs\": [\n { \"id\": \"1\", \"amount\": 1 },\n { \"id\": \"2\", \"amount\": 2 },\n { \"id\": \"3\", \"amount\": 4 },\n { \"id\": \"4\", \"amount\": 8 },\n ]\n }),\n \"tags\": [\n [ \"a\", \"37375:\u003cpubkey\u003e:my-wallet\" ]\n ]\n}\n```\n\nHer client:\n* MUST roll over the unspent proofs:\n```jsonconc\n{\n \"kind\": 7375,\n \"id\": \"event-id-2\",\n \"content\": nip44_encrypt({\n \"mint\": \"https://stablenut.umint.cash\",\n \"proofs\": [\n { \"id\": \"1\", \"amount\": 1 },\n { \"id\": \"2\", \"amount\": 2 },\n { \"id\": \"8\", \"amount\": 8 },\n ]\n }),\n \"tags\": [\n [ \"a\", \"37375:\u003cpubkey\u003e:my-wallet\" ]\n ]\n}\n```\n* MUST delete event `event-id-1`\n* SHOULD create a `kind:7376` event to record the spend\n```jsonconc\n{\n \"kind\": 7376,\n \"content\": nip44_encrypt([\n [ \"direction\", \"out\" ],\n [ \"amount\", \"4\", \"sats\" ],\n [ \"e\", \"\u003cevent-id-1\u003e\", \"\u003crelay-hint\u003e\", \"destroyed\" ],\n [ \"e\", \"\u003cevent-id-2\u003e\", \"\u003crelay-hint\u003e\", \"created\" ],\n ]),\n \"tags\": [\n [ \"a\", \"37375:\u003cpubkey\u003e:my-wallet\" ],\n ]\n}\n```\n\n## Appendix 1: Validating proofs\nClients can optionally validate proofs to make sure they are not working from an old state; this logic is left up to particular implementations to decide when and why to do it, but if some proofs are checked and deemed to have been spent, the client should delete the token and roll over any unspent proof.\n", "sig": "d8b1c13a4d9ce5f8f4da506b16673a84cf0be6ac9d974a1104c84f6b2b343fefe8163d5ea3858a316fd5e7c792f87ca0d8598158747e9be2f7667c57bd1e9995" }