-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added NIP-05 Python Example * Updated book page for NIP-05 * Included minor print statement updates to: `json.py`, `keys.py`, `nip44.py` and `nip59.py` Closes #435 Signed-off-by: Yuki Kishimoto <[email protected]>
- Loading branch information
1 parent
56e5e43
commit 169695c
Showing
7 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from nostr_protocol import Keys, Metadata, EventBuilder, PublicKey, verify_nip05, get_nip05_profile | ||
|
||
|
||
def nip05(): | ||
# ANCHOR: set-metadata | ||
# Create metadata object with name and NIP05 | ||
metadata = Metadata() \ | ||
.set_name("TestName") \ | ||
.set_nip05("[email protected]") | ||
# ANCHOR_END: set-metadata | ||
|
||
print() | ||
|
||
# ANCHOR: verify-nip05 | ||
print("Verify NIP-05:") | ||
nip_05 = "[email protected]" | ||
public_key = PublicKey.parse("npub1drvpzev3syqt0kjrls50050uzf25gehpz9vgdw08hvex7e0vgfeq0eseet") | ||
proxy = None | ||
try: | ||
verify_nip05(public_key, nip_05, proxy) | ||
print(f" '{nip_05}' verified, for {public_key.to_bech32()}") | ||
except Exception as e: | ||
print(f" Unable to verify NIP-05, for {public_key.to_bech32()}: {e}") | ||
# ANCHOR_END: verify-nip05 | ||
|
||
# TODO: replace above code with the following one (due to changes to NIP-05 verify func) | ||
# if verify_nip05(public_key, nip_05, proxy): | ||
# print(f" '{nip_05}' verified, for {public_key.to_bech32()}") | ||
# else: | ||
# print(f" Unable to verify NIP-05, for {public_key.to_bech32()}") | ||
|
||
print() | ||
|
||
# ANCHOR: nip05-profile | ||
print("Profile NIP-05:") | ||
nip_05 = "[email protected]" | ||
profile = get_nip05_profile(nip_05) | ||
print(f" {nip_05} Profile: {profile.to_bech32()}") | ||
# ANCHOR_END: nip05-profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from nostr_protocol import Keys, PublicKey, nip44_encrypt, nip44_decrypt, Nip44Version | ||
|
||
def nip44(): | ||
print("\nEncrypting and Decrypting Messages (NIP-44):") | ||
keys = Keys.generate() | ||
|
||
pk = PublicKey.from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798") | ||
|
||
ciphertext = nip44_encrypt(keys.secret_key(), pk, "my message", Nip44Version.V2) | ||
print(f"Encrypted: {ciphertext}") | ||
print(f" Encrypted: {ciphertext}") | ||
|
||
plaintext = nip44_decrypt(keys.secret_key(), pk, ciphertext) | ||
print(f"Decrypted: {plaintext}") | ||
print(f" Decrypted: {plaintext}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,62 @@ | ||
# NIP-05 | ||
## NIP-05 | ||
|
||
As a part of the kind 0 metadata events the optional key `nip05` is used to set and internet identifier value (e.g. `[email protected]`). | ||
Clients can then use this information to make GET requests with the form `https://<domain>/.well-known/nostr.json?name=<local-part>`. | ||
|
||
### Mapping Nostr keys to DNS-based internet identifiers (NIP-05) | ||
|
||
<custom-tabs category="lang"> | ||
|
||
<div slot="title">Rust</div> | ||
<section> | ||
|
||
TODO | ||
|
||
</section> | ||
|
||
<div slot="title">Python</div> | ||
<section> | ||
|
||
Using the `Metadata` class to build the metadata object and incorporate the NIP-05 identifier with the `set_nip05()` function. | ||
|
||
For more details on metadata (or general) events please refer back to the [examples](06-nip01.md) provided for NIP-01. | ||
|
||
```python,ignore | ||
{{#include ../../snippets/nostr/python/src/nip05.py:set-metadata}} | ||
``` | ||
|
||
For verification of NIP-05 identifiers associated with a given `PublicKey` object we can the `verify_nip05()` function as follows: | ||
|
||
```python,ignore | ||
{{#include ../../snippets/nostr/python/src/nip05.py:verify-nip05}} | ||
``` | ||
|
||
To retrieve a sharable profile identifier (as specified in NIP-19) the `get_nip05_profile()` function can be called with the NIP-05 value passed as an argument. | ||
|
||
```python,ignore | ||
{{#include ../../snippets/nostr/python/src/nip05.py:nip05-profile}} | ||
``` | ||
|
||
</section> | ||
|
||
<div slot="title">JavaScript</div> | ||
<section> | ||
|
||
TODO | ||
|
||
</section> | ||
|
||
<div slot="title">Kotlin</div> | ||
<section> | ||
|
||
TODO | ||
|
||
</section> | ||
|
||
<div slot="title">Swift</div> | ||
<section> | ||
|
||
TODO | ||
|
||
</section> | ||
</custom-tabs> |