diff options
| author | Jonathan Staab <shtaab@gmail.com> | 2023-08-11 13:09:17 -0700 |
|---|---|---|
| committer | Jonathan Staab <shtaab@gmail.com> | 2023-08-11 13:14:52 -0700 |
| commit | 30696049ccdc9f19b9f737b97290a78d0a64ba9c (patch) | |
| tree | 8b2357b2f46b4103f69f06c5fc2bbbef5c30839d | |
| parent | 00a8f9532eeee918c0417ae0f501c790cd5a3f56 (diff) | |
Deprecate NIP 04
| -rw-r--r-- | 04.md | 4 | ||||
| -rw-r--r-- | 07.md | 6 | ||||
| -rw-r--r-- | 44.md | 16 | ||||
| -rw-r--r-- | 46.md | 10 | ||||
| -rw-r--r-- | README.md | 2 |
5 files changed, 23 insertions, 15 deletions
| @@ -1,10 +1,12 @@ | |||
| 1 | > __Warning__ `unrecommended`: deprecated in favor of [NIP-44](44.md) | ||
| 2 | |||
| 1 | NIP-04 | 3 | NIP-04 |
| 2 | ====== | 4 | ====== |
| 3 | 5 | ||
| 4 | Encrypted Direct Message | 6 | Encrypted Direct Message |
| 5 | ------------------------ | 7 | ------------------------ |
| 6 | 8 | ||
| 7 | `final` `optional` `author:arcbtc` | 9 | `final` `unrecommended` `author:arcbtc` |
| 8 | 10 | ||
| 9 | A special event with kind `4`, meaning "encrypted direct message". It is supposed to have the following attributes: | 11 | A special event with kind `4`, meaning "encrypted direct message". It is supposed to have the following attributes: |
| 10 | 12 | ||
| @@ -18,8 +18,10 @@ async window.nostr.signEvent(event: Event): Event // takes an event object, adds | |||
| 18 | Aside from these two basic above, the following functions can also be implemented optionally: | 18 | Aside from these two basic above, the following functions can also be implemented optionally: |
| 19 | ``` | 19 | ``` |
| 20 | async window.nostr.getRelays(): { [url: string]: {read: boolean, write: boolean} } // returns a basic map of relay urls to relay policies | 20 | async window.nostr.getRelays(): { [url: string]: {read: boolean, write: boolean} } // returns a basic map of relay urls to relay policies |
| 21 | async window.nostr.nip04.encrypt(pubkey, plaintext): string // returns ciphertext and iv as specified in nip-04 | 21 | async window.nostr.nip04.encrypt(pubkey, plaintext): string // returns ciphertext and iv as specified in nip-04 (deprecated) |
| 22 | async window.nostr.nip04.decrypt(pubkey, ciphertext): string // takes ciphertext and iv as specified in nip-04 | 22 | async window.nostr.nip04.decrypt(pubkey, ciphertext): string // takes ciphertext and iv as specified in nip-04 (deprecated) |
| 23 | async window.nostr.nip44.encrypt(pubkey, plaintext): string // returns encrypted payload as specified in nip-44 | ||
| 24 | async window.nostr.nip44.decrypt(pubkey, ciphertext): string // takes encrypted payload as specified in nip-44 | ||
| 23 | ``` | 25 | ``` |
| 24 | 26 | ||
| 25 | ### Implementation | 27 | ### Implementation |
| @@ -8,7 +8,7 @@ Encrypted Payloads (Versioned) | |||
| 8 | 8 | ||
| 9 | The NIP introduces a versioned encryption data model, allowing multiple algorithm choices to exist simultaneously. | 9 | The NIP introduces a versioned encryption data model, allowing multiple algorithm choices to exist simultaneously. |
| 10 | 10 | ||
| 11 | The algorithm described in NIP4 is potentially vulnerable to [padding oracle attacks](https://en.wikipedia.org/wiki/Padding_oracle_attack) and uses keys which are not indistinguishable from random. | 11 | The algorithm described in NIP-04 is potentially vulnerable to [padding oracle attacks](https://en.wikipedia.org/wiki/Padding_oracle_attack) and uses keys which are not indistinguishable from random. For more information, see [here](https://github.com/nostr-protocol/nips/pull/715#issuecomment-1675301250-). |
| 12 | 12 | ||
| 13 | An encrypted payload MUST be encoded as a JSON object. Different versions may have different parameters. Every format has a `v` field specifying its version. | 13 | An encrypted payload MUST be encoded as a JSON object. Different versions may have different parameters. Every format has a `v` field specifying its version. |
| 14 | 14 | ||
| @@ -17,10 +17,6 @@ Currently defined encryption algorithms: | |||
| 17 | - `0x00` - Reserved | 17 | - `0x00` - Reserved |
| 18 | - `0x01` - XChaCha with same key `sha256(ecdh)` per conversation | 18 | - `0x01` - XChaCha with same key `sha256(ecdh)` per conversation |
| 19 | 19 | ||
| 20 | # Version 0 | ||
| 21 | |||
| 22 | Version 0 is not defined, however implementations depending on this NIP MAY choose to support the payload described in NIP 04 in the same places a NIP 44 payload would otherwise be expected. This is intended to allow a smooth transition while clients and signing software adopt the new standard. | ||
| 23 | |||
| 24 | # Version 1 | 20 | # Version 1 |
| 25 | 21 | ||
| 26 | Params: | 22 | Params: |
| @@ -38,11 +34,13 @@ Example: | |||
| 38 | } | 34 | } |
| 39 | ``` | 35 | ``` |
| 40 | 36 | ||
| 41 | **Note**: By default in the [libsecp256k1](https://github.com/bitcoin-core/secp256k1) ECDH implementation, the secret is the SHA256 hash of the shared point (both X and Y coordinates). We are using this exact implementation. In NIP4, unhashed shared point was used. | 37 | # Other Notes |
| 38 | |||
| 39 | By default in the [libsecp256k1](https://github.com/bitcoin-core/secp256k1) ECDH implementation, the secret is the SHA256 hash of the shared point (both X and Y coordinates). We are using this exact implementation. In NIP-94, unhashed shared point was used. | ||
| 42 | 40 | ||
| 43 | ## Code Samples | 41 | # Code Samples |
| 44 | 42 | ||
| 45 | ### Javascript | 43 | ## Javascript |
| 46 | 44 | ||
| 47 | ```javascript | 45 | ```javascript |
| 48 | import {xchacha20} from "@noble/ciphers/chacha" | 46 | import {xchacha20} from "@noble/ciphers/chacha" |
| @@ -99,7 +97,7 @@ export function decrypt(privkey: string, pubkey: string, payload: string) { | |||
| 99 | } | 97 | } |
| 100 | ``` | 98 | ``` |
| 101 | 99 | ||
| 102 | ### Kotlin | 100 | ## Kotlin |
| 103 | 101 | ||
| 104 | ```kotlin | 102 | ```kotlin |
| 105 | // implementation 'fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.10.1' | 103 | // implementation 'fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.10.1' |
| @@ -82,12 +82,18 @@ These are mandatory methods the remote signer app MUST implement: | |||
| 82 | - **get_relays** | 82 | - **get_relays** |
| 83 | - params [] | 83 | - params [] |
| 84 | - result `{ [url: string]: {read: boolean, write: boolean} }` | 84 | - result `{ [url: string]: {read: boolean, write: boolean} }` |
| 85 | - **nip04_encrypt** | 85 | - **nip04_encrypt** (deprecated) |
| 86 | - params [`pubkey`, `plaintext`] | 86 | - params [`pubkey`, `plaintext`] |
| 87 | - result `nip4 ciphertext` | 87 | - result `nip4 ciphertext` |
| 88 | - **nip04_decrypt** | 88 | - **nip04_decrypt** (deprecated) |
| 89 | - params [`pubkey`, `nip4 ciphertext`] | 89 | - params [`pubkey`, `nip4 ciphertext`] |
| 90 | - result [`plaintext`] | 90 | - result [`plaintext`] |
| 91 | - **nip44_encrypt** | ||
| 92 | - params [`pubkey`, `plaintext`] | ||
| 93 | - result `nip44 encrypted payload` | ||
| 94 | - **nip44_decrypt** | ||
| 95 | - params [`pubkey`, `nip44 encrypted payload`] | ||
| 96 | - result [`plaintext`] | ||
| 91 | 97 | ||
| 92 | 98 | ||
| 93 | NOTICE: `pubkey` and `signature` are hex-encoded strings. | 99 | NOTICE: `pubkey` and `signature` are hex-encoded strings. |
| @@ -22,7 +22,7 @@ They exist to document what may be implemented by [Nostr](https://github.com/nos | |||
| 22 | - [NIP-01: Basic protocol flow description](01.md) | 22 | - [NIP-01: Basic protocol flow description](01.md) |
| 23 | - [NIP-02: Contact List and Petnames](02.md) | 23 | - [NIP-02: Contact List and Petnames](02.md) |
| 24 | - [NIP-03: OpenTimestamps Attestations for Events](03.md) | 24 | - [NIP-03: OpenTimestamps Attestations for Events](03.md) |
| 25 | - [NIP-04: Encrypted Direct Message](04.md) | 25 | - [NIP-04: Encrypted Direct Message](04.md) --- **unrecommended**: deprecated in favor of [NIP-44](44.md) |
| 26 | - [NIP-05: Mapping Nostr keys to DNS-based internet identifiers](05.md) | 26 | - [NIP-05: Mapping Nostr keys to DNS-based internet identifiers](05.md) |
| 27 | - [NIP-06: Basic key derivation from mnemonic seed phrase](06.md) | 27 | - [NIP-06: Basic key derivation from mnemonic seed phrase](06.md) |
| 28 | - [NIP-07: `window.nostr` capability for web browsers](07.md) | 28 | - [NIP-07: `window.nostr` capability for web browsers](07.md) |