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 ID
  • twitter - Twitter username, proof is a Tweet ID
  • mastodon - Mastodon instance/@username, proof is a Post ID
  • telegram - Telegram user ID, proof is channel/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

identity()

@type identity() :: %{platform: String.t(), identity: String.t(), proof: String.t()}

External identity with platform, identity, and proof

Functions

build_tags(identities)

@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"}
])

from_tags(tags)

@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"}]

parse(platform_identity)

@spec parse(binary()) :: {:ok, {platform :: binary(), identity :: binary()}} | :error

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

proof_url(arg1)

@spec proof_url(identity() | map()) :: binary() | nil

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"

supported_platform?(platform)

@spec supported_platform?(binary()) :: boolean()

Checks if a platform name is in the list of supported platforms.

Examples

NIP39.supported_platform?("github")
# => true

NIP39.supported_platform?("unknown")
# => false

supported_platforms()

@spec supported_platforms() :: [String.t()]

Returns the list of supported platforms.

to_tag(arg1)

@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"]}