Skip to content

Commit

Permalink
book: bump to v0.35.0
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Sep 19, 2024
1 parent 51f5f37 commit b4fbc00
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 72 deletions.
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,5 +8,5 @@ edition = "2021"
members = ["."]

[dependencies]
nostr-sdk = "0.34"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
nostr-sdk = "0.35"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
27 changes: 9 additions & 18 deletions book/snippets/nostr-sdk/rust/src/quickstart.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

use nostr_sdk::prelude::*;

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

let client = Client::new(&my_keys);
let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));

client.add_relay("wss://relay.damus.io").await?;
client
.add_relay_with_opts(
"wss://relay.nostr.info",
RelayOptions::new().proxy(proxy).flags(RelayServiceFlags::default().remove(RelayServiceFlags::WRITE)),
)
.await?;
client
.add_relay_with_opts(
"ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion",
RelayOptions::new().proxy(proxy),
)
.await?;
client.add_read_relay("wss://relay.nostr.info").await?;

client.connect().await;
// ANCHOR_END: create-client
Expand All @@ -42,14 +28,19 @@ pub async fn quickstart() -> Result<()> {

// ANCHOR: create-filter
let filter = Filter::new().kind(Kind::Metadata);
let sub_id: SubscriptionId = client.subscribe(vec![filter], None).await;
let sub_id = client.subscribe(vec![filter], None).await?;
// ANCHOR_END: create-filter

// ANCHOR: notifications
let mut notifications = client.notifications();
while let Ok(notification) = notifications.recv().await {
if let RelayPoolNotification::Event { subscription_id, event, .. } = notification {
if subscription_id == sub_id && event.kind == Kind::Metadata {
if let RelayPoolNotification::Event {
subscription_id,
event,
..
} = notification
{
if subscription_id == *sub_id && event.kind == Kind::Metadata {
// handle the event
break; // Exit
}
Expand Down
4 changes: 2 additions & 2 deletions book/snippets/nostr/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@rust-nostr/nostr": "0.34.0"
"@rust-nostr/nostr": "0.35.0"
}
}
}
10 changes: 6 additions & 4 deletions book/snippets/nostr/js/src/event/builder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Keys, loadWasmSync, EventBuilder, Tag, Timestamp } = require("@rust-nostr/nostr");
const { Keys, loadWasmSync, EventBuilder, Tag, Timestamp, Kind } = require("@rust-nostr/nostr");

function eventBuilder() {
// Load WASM
Expand All @@ -7,7 +7,8 @@ function eventBuilder() {
let keys = Keys.generate();

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

// Compose text note
let textnoteEvent = EventBuilder.textNote("Hello", []).toEvent(keys);
Expand All @@ -20,7 +21,8 @@ function eventBuilder() {
// Compose POW event
let powEvent =
EventBuilder.textNote("Another reply with POW", [Tag.event(textnoteEvent.id)])
.toPowEvent(keys, 20);
.pow(20)
.toEvent(keys);

// Compose note with custom timestamp
let customTimestamp =
Expand All @@ -29,4 +31,4 @@ function eventBuilder() {
.toEvent(keys);
}

module.exports.eventBuilder = eventBuilder;
module.exports.eventBuilder = eventBuilder;
6 changes: 1 addition & 5 deletions book/snippets/nostr/js/src/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ function restore() {
let secretKey = SecretKey.fromBech32("nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85");
let keys2 = new Keys(secretKey);
console.log("Secret key (hex): ", keys2.secretKey.toHex());

// Construct Keys from public key
let publicKey = PublicKey.fromHex("7b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e");
let keys3 = Keys.fromPublicKey(publicKey);
}
// ANCHOR_END: restore

Expand All @@ -50,4 +46,4 @@ function vanity() {

module.exports.vanity = vanity;
module.exports.generate = generate;
module.exports.restore = restore;
module.exports.restore = restore;
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.34.0" }
nostr = { module = "org.rust-nostr:nostr", version = "0.35.0" }

[plugins]
androidLibrary = { id = "com.android.library", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fun builder() {
// Compose POW event
val powEvent =
EventBuilder.textNote("Another reply with POW", listOf(Tag.event(textNoteEvent.id())))
.toPowEvent(keys, 20u);
.pow(20u)
.toEvent(keys);
println(powEvent.asJson())
}
// ANCHOR_END: builder
// ANCHOR_END: builder
4 changes: 2 additions & 2 deletions book/snippets/nostr/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nostr-protocol==0.34.0
mnemonic==0.21
nostr-protocol==0.35.0
mnemonic==0.21
2 changes: 1 addition & 1 deletion book/snippets/nostr/python/src/event/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def event_builder():
reply_event = EventBuilder.text_note("Reply to hello", [Tag.event(textnote_event.id())]).to_event(keys)

# Compose POW event
pow_event = EventBuilder.text_note("Another reply with POW", [Tag.event(textnote_event.id())]).to_pow_event(keys, 20)
pow_event = EventBuilder.text_note("Another reply with POW", [Tag.event(textnote_event.id())]).pow(20).to_event(keys)
4 changes: 2 additions & 2 deletions book/snippets/nostr/python/src/event/kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def kind():
event = EventBuilder.metadata(Metadata()).to_event(keys)
print(f" - Kind metadata(): {event.kind().as_u16()} - {event.kind().as_enum()}")
event = EventBuilder.contact_list([]).to_event(keys)
print(f" - Kind contact_list(): {event.kind().as_u64()} - {event.kind().as_enum()}")
print(f" - Kind contact_list(): {event.kind().as_u16()} - {event.kind().as_enum()}")
# ANCHOR_END: kind-methods

print()
Expand All @@ -54,4 +54,4 @@ def kind():
print(f" - Job Request Event Kind: {kind.as_u16()} - {kind.as_enum()}")
kind = Kind.from_enum(KindEnum.JOB_RESULT(321))
print(f" - Job Result Event Kind: {kind.as_u16()} - {kind.as_enum()}")
# ANCHOR_END: kind-representations
# ANCHOR_END: kind-representations
2 changes: 1 addition & 1 deletion book/snippets/nostr/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"
members = ["."]

[dependencies]
nostr = "0.34"
nostr = "0.35"
3 changes: 2 additions & 1 deletion book/snippets/nostr/rust/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub fn event() -> Result<()> {
// Compose POW event
let pow_event =
EventBuilder::text_note("Another reply with POW", [Tag::event(textnote_event.id)])
.to_pow_event(&keys, 20)?;
.pow(20)
.to_event(&keys)?;

Ok(())
}
19 changes: 11 additions & 8 deletions book/snippets/nostr/rust/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ pub fn generate() -> Result<()> {
let keys = Keys::generate();

let public_key = keys.public_key();
let secret_key = keys.secret_key()?;
let secret_key = keys.secret_key();

println!("Public key (hex): {}", public_key);
println!("Public key (bech32): {}", public_key.to_bech32()?);
println!("Secret key (hex): {}", keys.secret_key()?.to_secret_hex());
println!("Secret key (hex): {}", keys.secret_key().to_secret_hex());
println!("Secret key (bech32): {}", secret_key.to_bech32()?);

Ok(())
}
// ANCHOR_END: generate
Expand All @@ -20,17 +20,20 @@ pub fn generate() -> Result<()> {
pub fn restore() -> Result<()> {
// Parse keys directly from secret key
let keys = Keys::parse("secret-key")?;

// Parse secret key and construct keys
let secret_key = SecretKey::parse("6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e")?;
let secret_key =
SecretKey::parse("6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e")?;
let keys = Keys::new(secret_key);

// Restore from bech32
let secret_key = SecretKey::from_bech32("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99")?;
let secret_key =
SecretKey::from_bech32("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99")?;
let keys = Keys::new(secret_key);

// Restore from hex
let secret_key = SecretKey::from_hex("6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e")?;
let secret_key =
SecretKey::from_hex("6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e")?;
let keys = Keys::new(secret_key);

Ok(())
Expand All @@ -40,7 +43,7 @@ pub fn restore() -> Result<()> {
// ANCHOR: vanity
pub fn vanity() -> Result<()> {
let keys = Keys::vanity(vec!["0000", "yuk", "yuk0"], true, 8)?;
println!("Secret key: {}", keys.secret_key()?.to_bech32()?);
println!("Secret key: {}", keys.secret_key().to_bech32()?);
println!("Public key: {}", keys.public_key().to_bech32()?);
Ok(())
}
Expand Down
11 changes: 6 additions & 5 deletions book/snippets/nostr/rust/src/nip44.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use nostr::prelude::*;

pub fn run() -> Result<()> {
let keys = Keys::generate();

let pk = PublicKey::from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")?;

let ciphertext = nip44::encrypt(keys.secret_key()?, &pk, "my message", nip44::Version::V2)?;
let pk =
PublicKey::from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")?;

let ciphertext = nip44::encrypt(keys.secret_key(), &pk, "my message", nip44::Version::V2)?;
println!("Encrypted: {ciphertext}");

let plaintext = nip44::decrypt(keys.secret_key()?, &pk, ciphertext)?;
let plaintext = nip44::decrypt(keys.secret_key(), &pk, ciphertext)?;
println!("Decrypted: {plaintext}");

Ok(())
}
}
8 changes: 5 additions & 3 deletions book/snippets/nostr/rust/src/nip59.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use nostr::prelude::*;

pub fn run() -> Result<()> {
// Sender keys
let alice_keys = Keys::parse("5c0c523f52a5b6fad39ed2403092df8cebc36318b39383bca6c00808626fab3a")?;
let alice_keys =
Keys::parse("5c0c523f52a5b6fad39ed2403092df8cebc36318b39383bca6c00808626fab3a")?;

// Receiver Keys
let bob_keys = Keys::parse("nsec1j4c6269y9w0q2er2xjw8sv2ehyrtfxq3jwgdlxj6qfn8z4gjsq5qfvfk99")?;

// Compose rumor
let rumor: UnsignedEvent = EventBuilder::text_note("Test", []).to_unsigned_event(alice_keys.public_key());
let rumor: UnsignedEvent =
EventBuilder::text_note("Test", []).to_unsigned_event(alice_keys.public_key());

// Build gift wrap with sender keys
let gw: Event = EventBuilder::gift_wrap(&alice_keys, &bob_keys.public_key(), rumor, None)?;
Expand All @@ -20,4 +22,4 @@ pub fn run() -> Result<()> {
println!("Rumor: {}", rumor.as_json());

Ok(())
}
}
4 changes: 2 additions & 2 deletions book/snippets/nostr/swift/NostrSnippets/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "NostrSnippets",
platforms: [.macOS(.v13)],
dependencies: [
.package(url: "https://github.com/rust-nostr/nostr-swift", from:"0.34.0")
.package(url: "https://github.com/rust-nostr/nostr-swift", from:"0.35.0")
],
targets: [
.executableTarget(
Expand All @@ -17,4 +17,4 @@ let package = Package(
],
path: "Sources"),
]
)
)
12 changes: 6 additions & 6 deletions book/src/nostr-sdk/02-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Add the `nostr-sdk` dependency in your `Cargo.toml` file:

```toml
[dependencies]
nostr-sdk = "0.34"
nostr-sdk = "0.35"
```

Alternatively, you can add it directly from `git` source:

```toml
[dependencies]
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", tag = "v0.34.0" }
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", tag = "v0.35.0" }
```

```admonish info
Expand All @@ -43,7 +43,7 @@ pip install nostr-sdk
Alternatively, you can manually add the dependency in your `requrements.txt`, `setup.py`, etc.:

```
nostr-sdk==0.34.0
nostr-sdk==0.35.0
```

Import the library in your code:
Expand Down Expand Up @@ -100,7 +100,7 @@ Alternatively, you can manually add the dependency in your `package.json` file:
```json
{
"dependencies": {
"@rust-nostr/nostr-sdk": "0.34.0"
"@rust-nostr/nostr-sdk": "0.35.0"
}
}
```
Expand Down Expand Up @@ -152,7 +152,7 @@ repositories {
}

dependencies {
implementation("org.rust-nostr:nostr-sdk:0.34.0")
implementation("org.rust-nostr:nostr-sdk:0.35.0")
}
```

Expand Down Expand Up @@ -202,7 +202,7 @@ as a package dependency in Xcode.
Add the following to the dependencies array in your `Package.swift`:

``` swift
.package(url: "https://github.com/rust-nostr/nostr-sdk-swift.git", from: "0.34.0"),
.package(url: "https://github.com/rust-nostr/nostr-sdk-swift.git", from: "0.35.0"),
```

</section>
Expand Down
Loading

0 comments on commit b4fbc00

Please sign in to comment.