Nostr. NIP39
(Nostr Lib v0.2.1)
(nip39)
View Source
NIP-39: External Identities in Profiles
Adds i tags to kind 0 metadata events for external identity verification.
Tag Format
["i", "platform:identity", "proof"]Supported Platforms
github- GitHub username, proof is a Gist IDtwitter- Twitter username, proof is a Tweet IDmastodon- Mastodoninstance/@username, proof is a Post IDtelegram- Telegram user ID, proof ischannel/message_id
Examples
# Extract identities from event tags
identities = NIP39.from_tags(event.tags)
# => [%{platform: "github", identity: "alice", proof: "abc123"}]
# Build i tags from identity list
tags = NIP39.build_tags([
%{platform: "github", identity: "alice", proof: "abc123"}
])
# => [%Tag{type: :i, data: "github:alice", info: ["abc123"]}]
# Get proof verification URL
NIP39.proof_url(%{platform: "github", identity: "alice", proof: "abc123"})
# => "https://gist.github.com/alice/abc123"See: https://github.com/nostr-protocol/nips/blob/master/39.md
Summary
Types
External identity with platform, identity, and proof
Functions
Builds i tags from a list of identities.
Extracts external identities from i tags.
Parses a "platform:identity" string.
Builds a verification URL for the given identity.
Checks if a platform name is in the list of supported platforms.
Returns the list of supported platforms.
Creates a single i tag from an identity map.
Types
Functions
@spec build_tags([identity()] | [map()]) :: [Nostr.Tag.t()]
Builds i tags from a list of identities.
Examples
NIP39.build_tags([
%{platform: "github", identity: "alice", proof: "abc123"},
%{platform: "twitter", identity: "bob", proof: "12345"}
])
@spec from_tags([Nostr.Tag.t()]) :: [identity()]
Extracts external identities from i tags.
Examples
tags = [
%Tag{type: :i, data: "github:alice", info: ["abc123"]},
%Tag{type: :p, data: "pubkey123", info: []}
]
NIP39.from_tags(tags)
# => [%{platform: "github", identity: "alice", proof: "abc123"}]
Parses a "platform:identity" string.
Examples
NIP39.parse("github:alice")
# => {:ok, {"github", "alice"}}
NIP39.parse("mastodon:bitcoinhackers.org/@alice")
# => {:ok, {"mastodon", "bitcoinhackers.org/@alice"}}
NIP39.parse("invalid")
# => :error
Builds a verification URL for the given identity.
Returns the URL where the proof can be verified, or nil if the platform
is not supported or the identity format is invalid.
Examples
NIP39.proof_url(%{platform: "github", identity: "alice", proof: "abc123"})
# => "https://gist.github.com/alice/abc123"
NIP39.proof_url(%{platform: "twitter", identity: "alice", proof: "12345"})
# => "https://twitter.com/alice/status/12345"
NIP39.proof_url(%{platform: "mastodon", identity: "bitcoinhackers.org/@alice", proof: "67890"})
# => "https://bitcoinhackers.org/@alice/67890"
NIP39.proof_url(%{platform: "telegram", identity: "12345", proof: "channel/678"})
# => "https://t.me/channel/678"
Checks if a platform name is in the list of supported platforms.
Examples
NIP39.supported_platform?("github")
# => true
NIP39.supported_platform?("unknown")
# => false
@spec supported_platforms() :: [String.t()]
Returns the list of supported platforms.
@spec to_tag(identity() | map()) :: Nostr.Tag.t() | nil
Creates a single i tag from an identity map.
Examples
NIP39.to_tag(%{platform: "github", identity: "alice", proof: "abc123"})
# => %Tag{type: :i, data: "github:alice", info: ["abc123"]}