diff options
| author | Jon Staab <jstaab@protonmail.com> | 2023-05-12 05:10:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-12 05:10:45 -0700 |
| commit | e5302f84c74cf42d878a3ed18257a16bc0d3b748 (patch) | |
| tree | b1a3ad9c0317bf7c38f34c500559b66ff7c0a22d /26.md | |
| parent | 1c728516dfdc7508ce27eda222bde78466e3457d (diff) | |
| parent | 4208652dc7a39c63c39559b13c656ec30400fcba (diff) | |
Merge branch 'master' into patch-1
Diffstat (limited to '26.md')
| -rw-r--r-- | 26.md | 76 |
1 files changed, 59 insertions, 17 deletions
| @@ -19,48 +19,90 @@ This NIP introduces a new tag: `delegation` which is formatted as follows: | |||
| 19 | "delegation", | 19 | "delegation", |
| 20 | <pubkey of the delegator>, | 20 | <pubkey of the delegator>, |
| 21 | <conditions query string>, | 21 | <conditions query string>, |
| 22 | <64-bytes schnorr signature of the sha256 hash of the delegation token> | 22 | <delegation token: 64-byte Schnorr signature of the sha256 hash of the delegation string> |
| 23 | ] | 23 | ] |
| 24 | ``` | 24 | ``` |
| 25 | 25 | ||
| 26 | ##### Delegation Token | 26 | ##### Delegation Token |
| 27 | 27 | ||
| 28 | The **delegation token** should be a 64-bytes schnorr signature of the sha256 hash of the following string: | 28 | The **delegation token** should be a 64-byte Schnorr signature of the sha256 hash of the following string: |
| 29 | 29 | ||
| 30 | ``` | 30 | ``` |
| 31 | nostr:delegation:<pubkey of publisher (delegatee)>:<conditions query string> | 31 | nostr:delegation:<pubkey of publisher (delegatee)>:<conditions query string> |
| 32 | ``` | 32 | ``` |
| 33 | 33 | ||
| 34 | For example, the token `c33c88ba78ec3c760e49db591ac5f7b129e3887c8af7729795e85a0588007e5ac89b46549232d8f918eefd73e726cb450135314bfda419c030d0b6affe401ec1` is signed by `86f0689bd48dcd19c67a19d994f938ee34f251d8c39976290955ff585f2db42e` and consists of: | 34 | ##### Conditions Query String |
| 35 | 35 | ||
| 36 | ```json | 36 | The following fields and operators are supported in the above query string: |
| 37 | nostr:delegation:62903b1ff41559daf9ee98ef1ae67cc52f301bb5ce26d14baba3052f649c3f49:kind=1&created_at>1640995200 | 37 | |
| 38 | ``` | 38 | *Fields*: |
| 39 | 1. `kind` | ||
| 40 | - *Operators*: | ||
| 41 | - `=${KIND_NUMBER}` - delegatee may only sign events of this kind | ||
| 42 | 2. `created_at` | ||
| 43 | - *Operators*: | ||
| 44 | - `<${TIMESTAMP}` - delegatee may only sign events created ***before*** the specified timestamp | ||
| 45 | - `>${TIMESTAMP}` - delegatee may only sign events created ***after*** the specified timestamp | ||
| 46 | |||
| 47 | 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 `&`. | ||
| 48 | |||
| 49 | For example, the following condition strings are valid: | ||
| 50 | |||
| 51 | - `kind=1&created_at<1675721813` | ||
| 52 | - `kind=0&kind=1&created_at>1675721813` | ||
| 53 | - `kind=1&created_at>1674777689&created_at<1675721813` | ||
| 54 | |||
| 55 | For the vast majority of use-cases, it is advisable that query strings should include a `created_at` ***after*** condition reflecting the current time, to prevent the delegatee from publishing historic notes on the delegator's behalf. | ||
| 39 | 56 | ||
| 40 | #### Example | 57 | #### Example |
| 41 | 58 | ||
| 42 | Below is an example of an event published by `62903b1ff41559daf9ee98ef1ae67cc52f301bb5ce26d14baba3052f649c3f49`, on behalf of `86f0689bd48dcd19c67a19d994f938ee34f251d8c39976290955ff585f2db42e`. | 59 | ``` |
| 60 | # Delegator: | ||
| 61 | privkey: ee35e8bb71131c02c1d7e73231daa48e9953d329a4b701f7133c8f46dd21139c | ||
| 62 | pubkey: 8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd | ||
| 63 | |||
| 64 | # Delegatee: | ||
| 65 | privkey: 777e4f60b4aa87937e13acc84f7abcc3c93cc035cb4c1e9f7a9086dd78fffce1 | ||
| 66 | pubkey: 477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396 | ||
| 67 | ``` | ||
| 43 | 68 | ||
| 69 | Delegation string to grant note publishing authorization to the delegatee (477318cf) from now, for the next 30 days, given the current timestamp is `1674834236`. | ||
| 70 | ```json | ||
| 71 | nostr:delegation:477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396:kind=1&created_at>1674834236&created_at<1677426236 | ||
| 72 | ``` | ||
| 73 | |||
| 74 | The delegator (8e0d3d3e) then signs a SHA256 hash of the above delegation string, the result of which is the delegation token: | ||
| 75 | ``` | ||
| 76 | 6f44d7fe4f1c09f3954640fb58bd12bae8bb8ff4120853c4693106c82e920e2b898f1f9ba9bd65449a987c39c0423426ab7b53910c0c6abfb41b30bc16e5f524 | ||
| 77 | ``` | ||
| 78 | |||
| 79 | 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. | ||
| 44 | ```json | 80 | ```json |
| 45 | { | 81 | { |
| 46 | "id": "a080fd288b60ac2225ff2e2d815291bd730911e583e177302cc949a15dc2b2dc", | 82 | "id": "e93c6095c3db1c31d15ac771f8fc5fb672f6e52cd25505099f62cd055523224f", |
| 47 | "pubkey": "62903b1ff41559daf9ee98ef1ae67cc52f301bb5ce26d14baba3052f649c3f49", | 83 | "pubkey": "477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396", |
| 48 | "created_at": 1660896109, | 84 | "created_at": 1677426298, |
| 49 | "kind": 1, | 85 | "kind": 1, |
| 50 | "tags": [ | 86 | "tags": [ |
| 51 | [ | 87 | [ |
| 52 | "delegation", | 88 | "delegation", |
| 53 | "86f0689bd48dcd19c67a19d994f938ee34f251d8c39976290955ff585f2db42e", | 89 | "8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd", |
| 54 | "kind=1&created_at>1640995200", | 90 | "kind=1&created_at>1674834236&created_at<1677426236", |
| 55 | "c33c88ba78ec3c760e49db591ac5f7b129e3887c8af7729795e85a0588007e5ac89b46549232d8f918eefd73e726cb450135314bfda419c030d0b6affe401ec1" | 91 | "6f44d7fe4f1c09f3954640fb58bd12bae8bb8ff4120853c4693106c82e920e2b898f1f9ba9bd65449a987c39c0423426ab7b53910c0c6abfb41b30bc16e5f524" |
| 56 | ] | 92 | ] |
| 57 | ], | 93 | ], |
| 58 | "content": "Hello world", | 94 | "content": "Hello, world!", |
| 59 | "sig": "cd4a3cd20dc61dcbc98324de561a07fd23b3d9702115920c0814b5fb822cc5b7c5bcdaf3fa326d24ed50c5b9c8214d66c75bae34e3a84c25e4d122afccb66eb6" | 95 | "sig": "633db60e2e7082c13a47a6b19d663d45b2a2ebdeaf0b4c35ef83be2738030c54fc7fd56d139652937cdca875ee61b51904a1d0d0588a6acd6168d7be2909d693" |
| 60 | } | 96 | } |
| 61 | ``` | 97 | ``` |
| 62 | 98 | ||
| 99 | The event should be considered a valid delegation if the conditions are satisfied (`kind=1`, `created_at>1674834236` and `created_at<1677426236` in this example) and, upon validation of the delegation token, are found to be unchanged from the conditions in the original delegation string. | ||
| 100 | |||
| 101 | Clients should display the delegated note as if it was published directly by the delegator (8e0d3d3e). | ||
| 102 | |||
| 103 | |||
| 104 | #### Relay & Client Support | ||
| 63 | 105 | ||
| 64 | #### Relay & Client Querying Support | 106 | Relays should answer requests such as `["REQ", "", {"authors": ["A"]}]` by querying both the `pubkey` and delegation tags `[1]` value. |
| 65 | 107 | ||
| 66 | Relays should answer requests such as `["REQ", "", {"authors": ["A"]}]` by querying both the `pubkey` and delegation tags `[1]` value. | 108 | Relays SHOULD allow the delegator (8e0d3d3e) to delete the events published by the delegatee (477318cf). \ No newline at end of file |