nips/26.md

105 lines
4.0 KiB
Markdown
Raw Normal View History

2022-08-04 04:33:38 -04:00
NIP: 26
=======
Delegated Event Signing
-----
2022-08-24 08:24:50 -04:00
`draft` `optional` `author:markharding` `author:minds`
2022-08-04 04:33:38 -04:00
2022-08-24 08:24:50 -04:00
This NIP defines how events can be delegated so that they can be signed by other keypairs.
2022-08-04 04:33:38 -04:00
Another application of this proposal is to abstract away the use of the 'root' keypairs when interacting with clients. For example, a user could generate new keypairs for each client they wish to use and authorize those keypairs to generate events on behalf of their root pubkey, where the root keypair is stored in cold storage.
2022-08-24 08:24:50 -04:00
#### Introducing the 'delegation' tag
2022-08-04 04:33:38 -04:00
2022-08-24 08:24:50 -04:00
This NIP introduces a new tag: `delegation` which is formatted as follows:
2022-08-04 04:33:38 -04:00
```json
[
2022-08-24 08:24:50 -04:00
"delegation",
<pubkey of the delegator>,
<conditions query string>,
<64-bytes schnorr signature of the sha256 hash of the delegation token>
2022-08-04 04:33:38 -04:00
]
```
2022-08-24 08:24:50 -04:00
##### Delegation Token
2022-08-04 04:33:38 -04:00
The **delegation token** should be a 64-byte Schnorr signature of the sha256 hash of the following string:
2022-08-04 04:33:38 -04:00
2022-08-24 08:24:50 -04:00
```
nostr:delegation:<pubkey of publisher (delegatee)>:<conditions query string>
2022-08-04 04:33:38 -04:00
```
##### Conditions Query String
The following fields and operators are supported in the above query string:
*Fields*:
1. `kind`
- *Operators*:
- `=${KIND_NUMBER}` - delegator may only sign events of this kind
2. `created_at`
- *Operators*:
- `<${TIMESTAMP}` - delegator may only sign events created ***before*** the specified timestamp
- `>${TIMESTAMP}` - delegator may only sign events created ***after*** the specified timestamp
In order to create a single condition, you must use a supported field and operator. Multiple conditions can be used in a single query string, including on the same field. Conditions must be combined with `&`.
For example, the following condition strings are valid:
- `kind=1&created_at<1675721813`
- `kind=0&kind=1&created_at>1675721813`
- `kind=1&created_at>1674777689&created_at<1675721813`
2022-08-04 04:33:38 -04:00
#### Example
2022-08-04 04:33:38 -04:00
```
# Delegator:
privkey: ee35e8bb71131c02c1d7e73231daa48e9953d329a4b701f7133c8f46dd21139c
pubkey: 8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd
2022-08-04 04:33:38 -04:00
# Delegatee:
privkey: 777e4f60b4aa87937e13acc84f7abcc3c93cc035cb4c1e9f7a9086dd78fffce1
pubkey: 477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396
```
Delegation string to grant note publishing authorization to the delegatee (477318cf) for the next 30 days.
```json
nostr:delegation:477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396:kind=1&created_at<1675721885
```
2022-08-04 04:33:38 -04:00
The delegator (8e0d3d3e) then signs the above delegation string, the result of which is the delegation token:
```
cbc49c65fe04a3181d72fb5a9f1c627e329d5f45d300a2dfed1c3e788b7834dad48a6d27d8e244af39c77381334ede97d4fd15abe80f35fda695fd9bd732aa1e
```
2022-08-04 04:33:38 -04:00
The delegatee (477318cf) can now construct an event on behalf of the delegator (8e0d3d3e). The delegatee then signs the event with its own private key and publishes.
2022-08-04 04:33:38 -04:00
```json
{
"id": "ac4c71e69c39b1bd605de812543ebfaf81d5af365354f061d48981fb61e00b8a",
"pubkey": "477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396",
"created_at": 1673129661,
2022-08-24 08:24:50 -04:00
"kind": 1,
"tags": [
[
"delegation",
"8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd",
"kind=1&created_at<1675721813",
"cbc49c65fe04a3181d72fb5a9f1c627e329d5f45d300a2dfed1c3e788b7834dad48a6d27d8e244af39c77381334ede97d4fd15abe80f35fda695fd9bd732aa1e"
2022-08-24 08:24:50 -04:00
]
],
"content": "Hello, world!",
"sig": "55ed9a78d6449b8c189b6dbc34bc4bcd34dcc79e6da6c9078268fe3d7c0cbe62b1b907ffb76ba591e83895b1329bf2e6e16f3b0cd5827272e420d419c6f0f0b5"
2022-08-04 04:33:38 -04:00
}
```
The event should be considered a valid delegation if the conditions are satisfied (`kind=1` and `created_at<1675721813` in this example) and, upon validation of the delegation token, are found to be unchanged from the conditions in the original delegation string.
Clients should display the delegated note as if it was published directly by the delegator (8e0d3d3e).
2022-08-24 08:24:50 -04:00
#### Relay & Client Querying Support
Relays should answer requests such as `["REQ", "", {"authors": ["A"]}]` by querying both the `pubkey` and delegation tags `[1]` value.