Skip to content

Instantly share code, notes, and snippets.

View blakejakopovic's full-sized avatar

Blake Jakopovic blakejakopovic

View GitHub Profile
@blakejakopovic
blakejakopovic / rust_docker
Created February 3, 2024 10:36 — forked from gsquire/rust_docker
A small docker image for rust using alpine linux
FROM alpine:3.6
RUN apk add --no-cache rust cargo
COPY project /build
WORKDIR /build
RUN ["cargo", "build", "--release"]
ENTRYPOINT ["cargo", "run", "--release"]
@blakejakopovic
blakejakopovic / yy.md
Last active May 20, 2023 10:27
NIP-YY - Nostr Service Definition

NIP-YY

Nostr Service Definition

draft optional author:wakoinc

A standardised service definition event allowing services to broadcast services they provide, and client apps to impliment support for a service type that is inter-changable

@blakejakopovic
blakejakopovic / NIP-ZZ.md
Last active May 20, 2023 10:00
NIP-ZZ - 401/402 Unauthorised/Payment Required Nostr HTTP AUTH Flow

NIP-ZZ

401/402 Unauthorised/Payment Required Nostr HTTP AUTH Flow

draft optional author:wakoinc

This NIP is an extension to NIP-98 which allows HTTP authorization using a base64 encoded event header. This NIP documents a typical protocol flow for failure, retry and success - or hard fail.

@blakejakopovic
blakejakopovic / DummyNostrHttpAuthEndpoint.rb
Created May 17, 2023 18:16
Dummy Nostr HTTP AUTH endpoint for NIP-98
require 'sinatra'
get '/public/AUTHIMAGE.jpg' do
auth_header = request.env['HTTP_AUTHORIZATION']
puts auth_header
# Check if the header value starts with "Nostr "
unless auth_header && auth_header.start_with?("Nostr ")
headers['WWW-AUTHENTICATE'] = 'NOSTR-NIP-98'
headers['Access-Control-Expose-Headers'] = 'WWW-Authenticate'
@blakejakopovic
blakejakopovic / Nostr-MyServices.md
Created April 11, 2023 15:15
NIP-XX - My Services

Nostr 'My Services' Event Kind (Draft/Experiment)

A way to support in-app management of services with subscriptions and credits where a payment is due (I guess it can be free too?).

Client UX

A client app can query for these events and show a list of services that are active or have credit remaining. They can show a list of expired (or no credit left) services as well. Clicking a service can allow you to make a payment based on the payment options provided.

What to support

  • Current balance (optional if expiry exists, else mandatory)
  • Current expiry (optional for balance): Represents payment due by
@blakejakopovic
blakejakopovic / nostr_query_engine.md
Last active March 26, 2023 12:14
Nostr missing event query/request features and pain points

Pain Points / design limitations

  • Limit is useless for subscriptions with multiple filters (as how to prioritise which filter results are most important? Left to right?)
  • Hard to do pagination (using since/until, but what limit to use? What if older events shared after you fetch, you’ve now missed it)
  • Race condition between EOSE and CLOSE subscription when you don’t want to stream (option to only return existing data only, without newer broadcast results)
  • Events from new pubkeys are missing basic kind0 data (ideally embed name/display_name for first pubkey event)
  • Websocket congestion control and bottlenecks (single event streamed at a time, blocked by larger events FIFO)
  • Unable to query for ranges of kinds (e.g. {"kinds": [30000-39999]})
  • More?

Missing Features

@blakejakopovic
blakejakopovic / nostr_client_anti_patterns.md
Last active March 22, 2023 09:15
Nostr Client App Anti-Patterns

Nostr Client App Anti-Patterns

With Nostr being an open protocol, and client apps being able to be developed by anyone, it's important that the client apps design around best supporting relays by minimising their client app impact. Remember, if your app has 10,000+ users, and the app's relay interaction code makes relays slower - everyone suffers.

Below are some anti-patterns (things not to do), that can help with relay performance, and ultimately make your client apps faster!

Please help build upon this list - we can move to a repo.. just add comments for now.

  • Updating a subscription too often (triggers new SQL queries)
  • Connecting to a relay multiple times (use a single websocket)
@blakejakopovic
blakejakopovic / nip19.rs
Created March 21, 2023 17:53
Nostr NIP-19 Rust TLV decode
#[macro_use]
extern crate log;
use anyhow::Result;
use bech32::FromBase32;
use secp256k1::hashes::hex::ToHex;
use std::convert::TryFrom;
fn parse_tlv(data: &[u8]) -> Vec<(u8, &[u8])> {
let mut result = vec![];
@blakejakopovic
blakejakopovic / app.rb
Last active March 17, 2023 15:33
Nostr NIP-42 Website Login Example
require 'sinatra'
require 'json'
# class App < Sinatra::Application
configure do
enable :sessions
end
get '/' do
@blakejakopovic
blakejakopovic / NIP-XX.md
Last active March 9, 2023 11:02
NIP-XX - Nostr Proof of Work Service Provider

NIP-XX

Proof of Work Service Provider

draft optional author:wakoinc

This NIP defines a way for clients to request a target proof of work calculation for an event prior to publishing.