View Source NostrBasics.Event (NostrBasics v0.1.6)
Represents the basic structure of anything that's being sent to/from relays
Link to this section Summary
Functions
Adds an ID to an event that doesn't have one
Simplifies the creation of an event, adding the created_at and tags fields and requiring the bare minimum to do so
Creates an ID for an event that doesn't have one
Converts a NIP-01 JSON string decoded as a map by Jason into an %Event{}
A structure an event has to be converted to prior to being SHA256'd, mainly for ID creation
Converts a NIP-01 JSON string into a %Event{}
Converts a NIP-01 JSON string into a %Event{}
Encodes an event key into the nevent format
Link to this section Types
@type id() :: String.t() | <<_::256>> | <<_::512>>
Link to this section Functions
Adds an ID to an event that doesn't have one
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.add_id
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
Simplifies the creation of an event, adding the created_at and tags fields and requiring the bare minimum to do so
examples
Examples
iex> pubkey = <<0xEFC83F01C8FB309DF2C8866B8C7924CC8B6F0580AFDDE1D6E16E2B6107C2862C::256>>
...> NostrBasics.Event.create(1, "this is the content", pubkey)
%NostrBasics.Event{
pubkey: <<0xefc83f01c8fb309df2c8866b8c7924cc8b6f0580afdde1d6e16e2b6107c2862c::256>>,
kind: 1,
content: "this is the content",
tags: []
}
Creates an ID for an event that doesn't have one
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.create_id
"0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34"
Converts a NIP-01 JSON string decoded as a map by Jason into an %Event{}
examples
Examples
iex> %{
...> "content" => "this is the content",
...> "created_at" => 1675794272,
...> "id" => "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
...> "kind" => 1,
...> "pubkey" => "5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2",
...> "tags" => []
...> }
...> |> NostrBasics.Event.decode()
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
A structure an event has to be converted to prior to being SHA256'd, mainly for ID creation
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.json_for_id
~s([0,"5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2",1675794272,1,[],"this is the content"])
Converts a NIP-01 JSON string into a %Event{}
examples
Examples
iex> ~s({"id":"0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34","pubkey":"5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2","created_at":1675794272,"kind":1,"tags":[],"content":"this is the content"})
...> |> NostrBasics.Event.parse()
{
:ok,
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
}
Converts a NIP-01 JSON string into a %Event{}
examples
Examples
iex> ~s({"id":"0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34","pubkey":"5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2","created_at":1675794272,"kind":1,"tags":[],"content":"this is the content"})
...> |> NostrBasics.Event.parse!()
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
Encodes an event key into the nevent format
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.to_nevent
"nevent1xpnrqvfhve3nywfevcmrxdf3v4nx2wtyx43xvcnxvgenvcesvvmkzvfn8yunvv3hvcukyetrxqexxdpevgcrqepsv43njwrpx4nrxdqq5qzcf"
iex> %NostrBasics.Event{
...> id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34"
...> }
...> |> NostrBasics.Event.to_nevent
"nevent1xpnrqvfhve3nywfevcmrxdf3v4nx2wtyx43xvcnxvgenvcesvvmkzvfn8yunvv3hvcukyetrxqexxdpevgcrqepsv43njwrpx4nrxdqq5qzcf"