NIP-01: Basic protocol flow description

User metadata

Rust

Use the Metadata struct to deserialize the content of an event into a struct.

let event = EventBuilder::new(Kind::Metadata, content).sign_with_keys(&keys)?;
let metadata = Metadata::from_json(&event.content)?;

If you have an existing metadata object, it can be used with the EventBuilder struct to create an EventBuilder with the metadata already attached.

let metadata = Metadata::from_json(content)?;
let event = EventBuilder::metadata(&metadata).sign_with_keys(&keys)?;

For documentation on the available struct attributes, check out the Metadata documentation.

Python

Using the Metadata class to build the metadata object and the EventBuilder class to create a Metadata event.

# Create metadata object with desired content
metadata_content = Metadata()\
    .set_name("TestName")\
    .set_display_name("PyTestur")\
    .set_about("This is a Test Account for Rust Nostr Python Bindings")\
    .set_website("https://rust-nostr.org/")\
    .set_picture("https://avatars.githubusercontent.com/u/123304603?s=200&v=4")\
    .set_banner("https://nostr-resources.com/assets/images/cover.png")\
    .set_nip05("TestName@rustNostr.com")

# Build metadata event and assign content
builder = EventBuilder.metadata(metadata_content)

# Signed event and print details
print("Creating Metadata Event:")
event = builder.sign_with_keys(keys)

print(" Event Details:")
print(f"     Author    : {event.author().to_bech32()}")
print(f"     Kind      : {event.kind().as_u16()}")
print(f"     Content   : {event.content()}")
print(f"     Datetime  : {event.created_at().to_human_datetime()}")
print(f"     Signature : {event.signature()}")
print(f"     Verify    : {event.verify()}")
print(f"     JSON      : {event.as_json()}")

Use the Metadata class to deserialize the content of an exsiting metadata event.

# Deserialize Metadata from event
print("Deserializing Metadata Event:")
metadata = Metadata().from_json(event.content())

print(" Metadata Details:")
print(f"     Name      : {metadata.get_name()}")
print(f"     Display   : {metadata.get_display_name()}")
print(f"     About     : {metadata.get_about()}")
print(f"     Website   : {metadata.get_website()}")
print(f"     Picture   : {metadata.get_picture()}")
print(f"     Banner    : {metadata.get_banner()}")
print(f"     NIP05     : {metadata.get_nip05()}")
JavaScript

Using the Metadata class to build the metadata object and the EventBuilder class to create a Metadata event.

// Create metadata object with desired content
let metadataContent = new Metadata()
    .name("TestName")
    .displayName("JsTestur")
    .about("This is a Test Account for Rust Nostr JS Bindings")
    .website("https://rust-nostr.org/")
    .picture("https://avatars.githubusercontent.com/u/123304603?s=200&v=4")
    .banner("https://nostr-resources.com/assets/images/cover.png")
    .nip05("TestName@rustNostr.com");

// Build metadata event and assign content
let builder = EventBuilder.metadata(metadataContent);

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

console.log(" Event Details:");
console.log(`     Author    : ${event.author.toBech32()}`);
console.log(`     Kind      : ${event.kind.valueOf()}`);
console.log(`     Content   : ${event.content.toString()}`);
console.log(`     Datetime  : ${event.createdAt.toHumanDatetime()}`);
console.log(`     Signature : ${event.signature.toString()}`);
console.log(`     Verify    : ${event.verify()}`);
console.log(`     JSON      : ${event.asJson()}`);

Use the Metadata class to deserialize the content of an exsiting metadata event.

// Deserialize Metadata from event
console.log("Deserializing Metadata Event:");
let metadata = Metadata.fromJson(event.content);

console.log(" Metadata Details:");
console.log(`     Name      : ${metadata.getName()}`);
console.log(`     Display   : ${metadata.getDisplayName()}`);
console.log(`     About     : ${metadata.getAbout()}`);
console.log(`     Website   : ${metadata.getWebsite()}`);
console.log(`     Picture   : ${metadata.getPicture()}`);
console.log(`     Banner    : ${metadata.getBanner()}`);
console.log(`     NIP05     : ${metadata.getNip05()}`);
Kotlin

TODO

Swift

TODO

Flutter

TODO