GithubHelp home page GithubHelp logo

gruruya / nmostr Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 0.0 676 KB

Nim library for Nostr

Home Page: https://gruruya.github.io/nmostr/

License: GNU Affero General Public License v3.0

Nim 100.00%
nim nostr bech32

nmostr's Introduction

nmostr

Library for working with Nostr.

Contained modules:

  • Events
  • Messages
  • Bech32
  • Proof of work

Stability: Early days. Functional.

Usage

Compile with -d:ssl for wss:// connections
Example uses guzba's whisky i.e. nimble install whisky

import pkg/[nmostr, whisky]

let keypair = random Keypair
echo "New secret key: " & keypair.seckey.toBech32
echo "The public key: " & keypair.pubkey.toBech32

# Post a note
let socket = newWebSocket("wss://nostr.bongbong.com") # Remember to build with -d:ssl
socket.send CMEvent(event: note(keypair, "Hello world from nmostr!")).toJson
let response = socket.receiveMessage().get.data
echo response

# Read the note back
unpack fromMessage(response), msg:
  when msg is SMOk:
    socket.send CMRequest(id: randomID(), filter: Filter(ids: @[msg.id.hex])).toJson
    echo socket.receiveMessage().get.data

For more, see the reference client niomo and tests.

What is Nostr?

Nostr is a simple decentralized protocol. It defines a standard for sending and receiving messages between users identified by their public keys using generic servers or "relays" that handle storage and logic.

Its popularity grew with the goal of creating a decentralized alternative to Twitter and an alternative to the Fediverse (Mastodon/Pleroma) that doesn't constrain users to one server that can be shut down or blocked.


GitHub CI Minimum supported Nim version License

nmostr's People

Contributors

dependabot[bot] avatar gruruya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nmostr's Issues

Is this project active?

Hi,

I want to help, but I want to know if this project is active. Is this project active?

media type in nmostr?

Hello everyone!

FAQ

I would like to know if it would be possible to have media type in nmostr. Would it be possible to have media type in mnostr?

Motivations

  1. Notes or events in nostr "may not be" text only, in that sense I think we should specify the most common media types as media/plaintext, media/html, media/yaml etc in nostr. In that case, we can support the rfc that specifies this.
  2. [RFC2046] specifies that Media Types (formerly known as MIME types) and Media Subtypes will be assigned and listed by the IANA.
  3. Specifying the rfc for the media type means making the nostr something like "http" - in the most commonly used sense.
  4. There are several discussions about techniques here: Different nostr: schemes for different types of apps/nips, Embedding decentralized media
  5. In my opinion, we should support things like 'url', 'uri' and 'urn'. And with that, having support for all types of media initially for nostr.

Intro

"RFC2046" specifies that Media Types (formerly known as MIME types) and Media Subtypes will be assigned and listed by the IANA. Procedures for registering Media Types can be found in RFC6838, RFC4289, RFC6657. Additional procedures for registering media types for transfer via Real-time Transport Protocol (RTP) can be found in RFC4855. See this: https://www.iana.org/assignments/media-types/media-types.xhtml

Idea

We might have a syntax for media/type as:

import pkg/[nmostr, whisky]
#  The example below is a conceptual sketch for this.
socket.send CMEvent(event: note(keypair, "media/type", "string")).toJson

Syntax

In the theory:

  • URI (uniform resource identifier) identifies a resource (text document, image file, etc)
  • URL (uniform resource locator) is a subset of the URIs that include a network location
  • URN (uniform resource name) is a subset of URIs that include a name within a given space, but no location

Example

example 1: media/urn
urn: urn:<NAMESPACE-IDENTIFIER>:<NAMESPACE-SPECIFIC-STRING>: The placeholder stands for a string representing the resource category you want to identify. The is the resource's specific identifier, and its format depends on the namespace identifier. The following are examples of URNs: urn:isbn:1234567890, urn:ISSN:0167-6423, urn:ietf:rfc:2648

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/urn", "urn:ietf:rfc:2648")).toJson 

example 2: media/uri
uri: https://the-great-chef.com/languages/recipe: The URI acronym stands for Uniform Resource Identifier. Shortly, it is a string that identifies a resource. From a syntactical point of view, a URI string mostly follows the same format as... the URL!

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/uri", "https://the-great-chef.com/languages/recipe")).toJson 

example 3: media/plaintext
In cryptography, plaintext usually means unencrypted information pending input into cryptographic algorithms, usually encryption algorithms.

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/plaintext", "Hello world from nmostr!")).toJson 

example 4: media/url
URL identifies the web address or location of a unique resource.

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/url", "https://jwt.io")).toJson

example 5: media/text-fragments
Text fragments allow you linking directly to a specific portion of text in a web document, without requiring the author to annotate it with an ID, using particular syntax in the URL fragment.

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/text-fragments", "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#:~:text=human")).toJson

example 6: media/bibtext
'BibTeX' stands for a tool and a file format which are used to describe and process lists of references, mostly in conjunction with LaTeX documents.

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/bibtext", "http://sample-opensource-orgs.org/demo/sample.bib")).toJson

example 7: media/ipfs
Relays can't be expected to host media, the infrastructure requirements would be immense. URLs break and many image/video hosts do annoying things that prevent simple unobtrusive viewing of media. Use of decentralized URN to embed media in messages should be normalized.

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/urn", "urn:ipfs:bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")).toJson

example 8: media/bittorrent
Let's assume in this theoretical example that you want to share a link to an iso file of a linux distribution to your friends on nostr. You could do something like this:

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/bittorrent", "https://linuxfreetest.com/linux_2023-05-13_k61.iso.torrent")).toJson

example 9: media/file

file: URI Scheme is a URI scheme defined in RFC 8089, typically used to retrieve files from within one's own computer. This is very useful indoors where you want to share common data paths.

import pkg/[nmostr, whisky]
socket.send CMEvent(event: note(keypair, "media/file", "file://listlinux.com/free/public_html/chaps")).toJson

Implementation

import pkg/[nmostr, whisky]
import std/uri
let host = parseUri("https://nim-lang.org")
assert $host == "https://nim-lang.org"

let keypair = newKeypair()
echo "New secret key: " & keypair.seckey.toBech32
echo "The public key: " & keypair.pubkey.toBech32

# Post a note
let socket = newWebSocket("wss://nostr.oxtr.dev") # Remember to build with -d:ssl
socket.send CMEvent(event: note(keypair, "media/url", host)).toJson
let response = socket.receiveMessage().get.data
echo response

# Read the note back
unpack fromMessage(response), msg:
  when msg is SMOk:
    socket.send CMRequest(id: randomID(), filter: Filter(ids: @[msg.id])).toJson
    echo socket.receiveMessage().get.data

socket.close()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.