Skip to content

Commit

Permalink
Release v0.36.0
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 5, 2024
1 parent 4f076ba commit 33fb069
Show file tree
Hide file tree
Showing 58 changed files with 249 additions and 413 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
-->

## [Unreleased]
## [v0.36.0]

### Summary

Many, many improvements to `Relay` and `RelayPool` performance (reduced atomic operations and switched to async concurrency),
add `NostrSigner` trait, better methods and struct names (`fetch_events` instead of `get_events_of`, `sync` instead of `reconcile`,
`NostrConnect` instead of `Nip46Signer` and so on), add `LocalRelay` and allow to easily serve it as hidden onion service with the embedded
tor client, allow to keep track of negentropy sync progress, almost halved the weight of JavaScript SDK bindings (from ~6.3MB to ~3.6MB), some fixes and many more!

Note for Python, Kotlin, Swift and JavaScript devs: unfortunately I can't mark things as deprecated in bindings, so this release have many breaking changes, sorry :(
Note for devs who are using `nostr-protocol` (Python), `org.rust-nostr:nostr` (Kotlin), `nostr-swift` (Swift) or `@rust-nostr/nostr` (JavaScript) libraries: these packages are now deprecated. Only the `nostr-sdk` library will be released, which include everything that was in the `nostr` library.

### Changed

* Bump toolchain channel to `1.82.0`
Expand Down Expand Up @@ -692,7 +700,8 @@ added `nostrdb` storage backend, added NIP32 and completed NIP51 support and mor
[rodant]: https://github.com/rodant

<!-- Tags -->
[Unreleased]: https://github.com/rust-nostr/nostr/compare/v0.35.0...HEAD
[Unreleased]: https://github.com/rust-nostr/nostr/compare/v0.36.0...HEAD
[v0.36.0]: https://github.com/rust-nostr/nostr/compare/v0.35.0...v0.36.0
[v0.35.0]: https://github.com/rust-nostr/nostr/compare/v0.34.0...v0.35.0
[v0.34.0]: https://github.com/rust-nostr/nostr/compare/v0.33.0...v0.34.0
[v0.33.0]: https://github.com/rust-nostr/nostr/compare/v0.32.0...v0.33.0
Expand Down
10 changes: 2 additions & 8 deletions book/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

* [Just](https://github.com/casey/just): install with `cargo install just`

Init

```bash
just init
```

You can serve the site with:
Serve the site with:

```bash
just serve
Expand All @@ -22,4 +16,4 @@ To test all the snippets:

```bash
just test
```
```
11 changes: 6 additions & 5 deletions book/justfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[private]
init:
cargo install mdbook --version 0.4.36
cargo install mdbook-admonish --version 1.15.0
@mdbook --version || cargo install mdbook --version 0.4.36
@mdbook-admonish --version || cargo install mdbook-admonish --version 1.15.0

build:
build: init
mdbook build

serve:
serve: init
mdbook serve

test:
cd snippets && just test
cd snippets && just test
4 changes: 2 additions & 2 deletions book/snippets/nostr-sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ edition = "2021"
members = ["."]

[dependencies]
nostr-sdk = "0.35"
nostr-relay-builder = "0.35"
nostr-sdk = "0.36"
nostr-relay-builder = "0.36"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
4 changes: 2 additions & 2 deletions book/snippets/nostr-sdk/rust/src/nip17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pub async fn run() -> Result<()> {
// Sender
let alice_keys =
Keys::parse("5c0c523f52a5b6fad39ed2403092df8cebc36318b39383bca6c00808626fab3a")?;
let alice_client = Client::new(&alice_keys);
let alice_client = Client::new(alice_keys);
alice_client.add_relay(url.clone()).await?;
alice_client.connect().await;

// Receiver
let bob_keys = Keys::parse("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99")?;
let bob_client = Client::new(&bob_keys);
let bob_client = Client::new(bob_keys.clone());
bob_client.add_relay(url.clone()).await?;
bob_client.connect().await;

Expand Down
4 changes: 2 additions & 2 deletions book/snippets/nostr-sdk/rust/src/quickstart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use nostr_sdk::prelude::*;

pub async fn quickstart() -> Result<()> {
// ANCHOR: create-client
let my_keys: Keys = Keys::generate();
let keys: Keys = Keys::generate();

let client = Client::new(&my_keys);
let client = Client::new(keys);

client.add_relay("wss://relay.damus.io").await?;
client.add_read_relay("wss://relay.nostr.info").await?;
Expand Down
4 changes: 2 additions & 2 deletions book/snippets/nostr/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ async function main() {
eventBuilder.eventBuilder();

await relayMessages.run();

nip01.run();
await nip05.run();
nip06.run();
nip19.run();
nip21.run();
nip44.run();

nip59.run();
await nip59.run();
nip65.run();
}

Expand Down
2 changes: 1 addition & 1 deletion book/snippets/nostr/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@rust-nostr/nostr-sdk": "0.35.0",
"@rust-nostr/nostr-sdk": "0.36.0",
"bip39": "^3.1.0"
}
}
10 changes: 5 additions & 5 deletions book/snippets/nostr/js/src/event/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ function eventBuilder() {

// Compose custom event
let kind = new Kind(1111);
let customEvent = new EventBuilder(kind, "", []).toEvent(keys);
let customEvent = new EventBuilder(kind, "", []).signWithKeys(keys);

// Compose text note
let textnoteEvent = EventBuilder.textNote("Hello", []).toEvent(keys);
let textnoteEvent = EventBuilder.textNote("Hello", []).signWithKeys(keys);

// Compose reply to above text note
let replyEvent =
EventBuilder.textNote("Reply to hello", [Tag.event(textnoteEvent.id)])
.toEvent(keys);
.signWithKeys(keys);

// Compose POW event
let powEvent =
EventBuilder.textNote("Another reply with POW", [Tag.event(textnoteEvent.id)])
.pow(20)
.toEvent(keys);
.signWithKeys(keys);

// Compose note with custom timestamp
let customTimestamp =
EventBuilder.textNote("Note with custom timestamp", [])
.customCreatedAt(Timestamp.fromSecs(12345678))
.toEvent(keys);
.signWithKeys(keys);
}

module.exports.eventBuilder = eventBuilder;
2 changes: 1 addition & 1 deletion book/snippets/nostr/js/src/messages/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ async function run() {
await loadWasmAsync();

const keys = Keys.generate();
const event = EventBuilder.textNote("TestTextNoTe", []).toEvent(keys);
const event = EventBuilder.textNote("TestTextNoTe", []).signWithKeys(keys);

console.log("\nRelay Messages:");

Expand Down
2 changes: 1 addition & 1 deletion book/snippets/nostr/js/src/nip01.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function run() {

// Signed event and print details
console.log("Creating Metadata Event:");
let event = builder.toEvent(keys);
let event = builder.signWithKeys(keys);

console.log(" Event Details:");
console.log(` Author : ${event.author.toBech32()}`);
Expand Down
2 changes: 1 addition & 1 deletion book/snippets/nostr/js/src/nip19.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function run() {
// ANCHOR_END: nip19-nsec

// ANCHOR: nip19-note
let event = EventBuilder.textNote("Hello from Rust Nostr JS Bindings!", []).toEvent(keys);
let event = EventBuilder.textNote("Hello from Rust Nostr JS Bindings!", []).signWithKeys(keys);
console.log(` Event : ${event.id.toBech32()}`);
// ANCHOR_END: nip19-note

Expand Down
10 changes: 5 additions & 5 deletions book/snippets/nostr/js/src/nip21.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ function run(){
console.log("Nostr URIs:");

// ANCHOR: npub
// UNCOMMENT_ON_RELEASE: let pk_uri = keys.publicKey.toNostrUri();
// UNCOMMENT_ON_RELEASE: console.log(` Public key (URI): ${pk_uri}`);
let pk_uri = keys.publicKey.toNostrUri();
console.log(` Public key (URI): ${pk_uri}`);
// ANCHOR_END: npub

console.log();
// ANCHOR: note
let event = EventBuilder.textNote("Hello from rust-nostr JS bindings!", []).toEvent(keys);
// UNCOMMENT_ON_RELEASE: let note_uri = event.id.toNostrUri()
// UNCOMMENT_ON_RELEASE: console.log(` Event (URI): ${note_uri}`);
let event = EventBuilder.textNote("Hello from rust-nostr JS bindings!", []).signWithKeys(keys);
let note_uri = event.id.toNostrUri()
console.log(` Event (URI): ${note_uri}`);
// ANCHOR_END: note

console.log();
Expand Down
18 changes: 10 additions & 8 deletions book/snippets/nostr/js/src/nip59.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
const { Keys, EventBuilder, UnwrappedGift, loadWasmSync } = require("@rust-nostr/nostr-sdk");
const { Keys, EventBuilder, UnwrappedGift, loadWasmAsync, NostrSigner} = require("@rust-nostr/nostr-sdk");

function run() {
loadWasmSync();
async function run() {
await loadWasmAsync();

// Sender Keys
const alice_keys = Keys.parse("5c0c523f52a5b6fad39ed2403092df8cebc36318b39383bca6c00808626fab3a")
const alice_keys = Keys.parse("5c0c523f52a5b6fad39ed2403092df8cebc36318b39383bca6c00808626fab3a");
const alice_signer = NostrSigner.keys(alice_keys);

// Receiver Keys
const bob_keys = Keys.parse("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99")
const bob_keys = Keys.parse("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99");
const bob_signer = NostrSigner.keys(bob_keys);

// Compose rumor
const rumor = EventBuilder.textNote("Test", []).toUnsignedEvent(alice_keys.publicKey)
const rumor = EventBuilder.textNote("Test", []).build(alice_keys.publicKey)

// Build gift wrap with sender keys
const gw = EventBuilder.giftWrap(alice_keys, bob_keys.publicKey, rumor)
const gw = await EventBuilder.giftWrap(alice_signer, bob_keys.publicKey, rumor)
console.log("Gift Wrap: " + gw.asJson())

// Extract rumor from gift wrap with receiver keys
let unwrapped_gift = UnwrappedGift.fromGiftWrap(bob_keys, gw);
let unwrapped_gift = await UnwrappedGift.fromGiftWrap(bob_signer, gw);
console.log("Sender: ", unwrapped_gift.sender.toBech32())
console.log("Rumor: ", unwrapped_gift.rumor.asJson())
}
Expand Down
8 changes: 4 additions & 4 deletions book/snippets/nostr/js/src/nip65.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function run(){

// Build/sign event
let builder = EventBuilder.relayList(relays);
let event = builder.toEvent(keys);
let event = builder.signWithKeys(keys);

// Print event as json
console.log(` Event: ${event.asJson()}`);
Expand All @@ -28,16 +28,16 @@ function run(){
console.log();
// ANCHOR: relay-metadata-custom
// Create relay metadata tags
let tag1 = Tag.relayMetadata("wss://relay.damus.io", RelayMetadata.READ);
let tag2 = Tag.relayMetadata("wss://relay.primal.net", RelayMetadata.WRITE);
let tag1 = Tag.relayMetadata("wss://relay.damus.io", RelayMetadata.Read);
let tag2 = Tag.relayMetadata("wss://relay.primal.net", RelayMetadata.Write);
let tag3 = Tag.relayMetadata("wss://relay.nostr.band");

// Build/sign event
let kind = new Kind(10002);
let content = "";
let tags = [tag1, tag2, tag3];
builder = new EventBuilder(kind, content, tags);
event = builder.toEvent(keys);
event = builder.signWithKeys(keys);

// Print event as json
console.log(` Event: ${event.asJson()}`);
Expand Down
2 changes: 1 addition & 1 deletion book/snippets/nostr/kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ agp = "8.1.4"
kotlin = "1.9.22"

[libraries]
nostr = { module = "org.rust-nostr:nostr", version = "0.35.0" }
nostr = { module = "org.rust-nostr:nostr-sdk", version = "0.36.0" }

[plugins]
androidLibrary = { id = "com.android.library", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package rust.nostr.snippets

import rust.nostr.protocol.*
import rust.nostr.sdk.*

// ANCHOR: json
fun json() {
Expand All @@ -19,20 +19,20 @@ fun builder() {
val keys = Keys.generate();

// Compose custom event
val customEvent = EventBuilder(Kind(1111u), "", listOf()).toEvent(keys);
val customEvent = EventBuilder(Kind(1111u), "", listOf()).signWithKeys(keys);

// Compose text note
val textNoteEvent = EventBuilder.textNote("Hello", listOf()).toEvent(keys);
val textNoteEvent = EventBuilder.textNote("Hello", listOf()).signWithKeys(keys);

// Compose reply to above text note
val replyEvent = EventBuilder.textNote("Reply to hello", listOf(Tag.event(textNoteEvent.id())))
.toEvent(keys);
.signWithKeys(keys);

// Compose POW event
val powEvent =
EventBuilder.textNote("Another reply with POW", listOf(Tag.event(textNoteEvent.id())))
.pow(20u)
.toEvent(keys);
.signWithKeys(keys);
println(powEvent.asJson())
}
// ANCHOR_END: builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package rust.nostr.snippets

import rust.nostr.protocol.*
import rust.nostr.sdk.*

// ANCHOR: generate
fun generate() {
Expand Down Expand Up @@ -37,4 +37,4 @@ fun vanity() {
println("Public key: ${keys.publicKey().toBech32()}");
println("Secret key: ${keys.secretKey().toHex()}");
}
// ANCHOR_END: vanity
// ANCHOR_END: vanity
4 changes: 3 additions & 1 deletion book/snippets/nostr/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from src.nip59 import nip59
from src.nip65 import nip65


async def main():
generate()
restore()
Expand All @@ -40,8 +41,9 @@ async def main():
nip19()
nip21()
nip44()
nip59()
await nip59()
nip65()


if __name__ == '__main__':
asyncio.run(main())
2 changes: 1 addition & 1 deletion book/snippets/nostr/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nostr-protocol==0.35.0
nostr-sdk==0.36.0
mnemonic==0.21
11 changes: 6 additions & 5 deletions book/snippets/nostr/python/src/event/builder.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from nostr_protocol import *
from nostr_sdk import *


def event_builder():
keys = Keys.generate()

# Compose custom event
custom_event = EventBuilder(Kind(1111), "", []).to_event(keys)
custom_event = EventBuilder(Kind(1111), "", []).sign_with_keys(keys)

# Compose text note
textnote_event = EventBuilder.text_note("Hello", []).to_event(keys)
textnote_event = EventBuilder.text_note("Hello", []).sign_with_keys(keys)

# Compose reply to above text note
reply_event = EventBuilder.text_note("Reply to hello", [Tag.event(textnote_event.id())]).to_event(keys)
reply_event = EventBuilder.text_note("Reply to hello", [Tag.event(textnote_event.id())]).sign_with_keys(keys)

# Compose POW event
pow_event = EventBuilder.text_note("Another reply with POW", [Tag.event(textnote_event.id())]).pow(20).to_event(keys)
pow_event = EventBuilder.text_note("Another reply with POW", [Tag.event(textnote_event.id())]).pow(20).sign_with_keys(keys)
Loading

0 comments on commit 33fb069

Please sign in to comment.