Skip to content

Commit

Permalink
doc: README
Browse files Browse the repository at this point in the history
  • Loading branch information
studioTeaTwo committed Dec 13, 2023
1 parent 70e6e42 commit 5d046c1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 42 deletions.
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
# create-svelte
# Self-Sovereign Blog

Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
The self-sovereign blog is a showcase of "paywall without intermediaries".

## Creating a project
This blog is handcrafted by SvelteKit and can be hosted anywhere. Payments for paywall use Bitcoin which is the border-less internet native money, specifically Lightning Network which is the layer2 of Bitcoin and realizes fast finality and micro payments. The proof of payment is shared between buyers and sellers through messaging using the Nostr protocol.

If you're seeing this, you've probably already done this step. Congrats!
Both Bitcoin and Nostr are the people's networks without specific authorities. So, this paywall is "Self-Sovereignty", with no middlemen involved.

```bash
# create a new project in the current directory
npm create svelte@latest
## Overview

# create a new project in my-app
npm create svelte@latest my-app
```
![](doc/overview.png)

## Developing
The front server is responsible for:

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
1. delivering blog posts that are markdown-based
2. unlocking paywalled content
3. delivering invoices to remove the paywall
4. setting up to subscribe to encypted messages to share the payment proof
5. asking payment authentication/authorization related to all of the above to the API server

```bash
npm run dev
Payment authentication/authorization for paywall follows the [Lightning HTTP 402 Protocol (L402 protocol)](https://github.com/lightning/blips/pull/26) that repurposes the `HTTP 402 Payment Required` error code and is a standardized way of adding micropayments to any existing HTTP-REST or gRPC API.

# or start the server and open the app in a new browser tab
npm run dev -- --open
```
The API server coodinates two networks that are Lightning Network for payments and Nostr protocol for messagings, and executes L402 protocol. You can check the [sample implementation](https://github.com/studioTeaTwo/simple-l402-server) for this blog which wraps the L402 API Key proxy called [Aperture](https://github.com/lightninglabs/aperture).

## Building
Lightning Network is Bitcoin's layer2 used for payment network. Bitcoin is decentralized internet money, so users can pay from any wallet that supports Lightning Network.

To create a production version of your app:
Nostr protocol is a decentralized network similar to Bitcoin, which is used on this blog to share the proof of payment safety and securely without the need for any counterparty. To achieve this, we adopt [NIP-04](https://github.com/nostr-protocol/nips/blob/master/04.md) to exchange direct message encrypted with AES-256-CBC.

```bash
npm run build
```
## L402 protocol flow

You can preview the production build with `npm run preview`.
![](doc/challenge-response.sequence.png)

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
TODO
Binary file added doc/challenge-response.sequence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions doc/challenge-response.sequence.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
@startuml

== challenge phase ==
user -> server: Challenge Request
user -> L402server: Challenge Request
note left: NostrPubKey
server -> server: Create macaroon
server -> LND: Invoice Request
server <-- LND: Invoice Response
user <-- server: Challenge Response
L402server -> L402server: Keep NostrPubKey
L402server -> L402server: Create macaroon
L402server -> LND: Invoice Request
L402server <-- LND: Invoice Response
user <-- L402server: Challenge Response
note right: macaroon + invoice

== answer creation ==
user -> LND: Payment
note left: invoice
server <-- LND: Settlement nortification
server -> server: Get the preimage
server -> Nostr: Event Request
L402server <-- LND: Settlement nortification
L402server -> L402server: Get the preimage
L402server -> Nostr: Event Request
note left
the preimage encrypted
by NostrPubKey
Expand All @@ -23,9 +24,9 @@ user <-- Nostr: Event Response
user -> user: Decrypt the preimage by NostrSecKey

== response phase ==
user -> server: Answer Request
user -> L402server: Answer Request
note left: macaroon + preimage
server -> server: Verify
user <-- server: Answer Response
L402server -> L402server: Verify
user <-- L402server: Answer Response

@enduml
Binary file added doc/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion posts/002_ligtning-nostr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Entering the preimage manually is a problem. Nostr will be a solution.

![](./after.webm)

I'll post an overview and technical details at a later date, though, you can experience it below right now. Of course, it is also possible to prevent private key from revealing using NIP-07.
I'll post an overview and technical details at a later date, though, you can experience it below right now. Of course, it is also possible to prevent Nostr's private key from revealing using NIP-07.

<hr id="l402" hidden>
2 changes: 1 addition & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PUBLIC_BLOG_SERVER, PUBLIC_L402_SERVER, PUBLIC_SERVICE_NPUBKEY } from '
import type { CookieSerializeOptions } from 'cookie';

// Blog author
export const Title = 'Self Sovereign Blog';
export const Title = 'Self-Sovereign Blog';
export const Author = 'TeaTwo';
export const BitcoinDonationAddress = 'bc1q8pmsy0xfrkpr3vky9kw5kjmqrm0fsg70q963dg';

Expand Down
10 changes: 5 additions & 5 deletions src/routes/articles/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@
<button type="button" on:click={handleClickNip07}>NIP-07</button>
<div class="paywall-nostr-description">
<p class="paywall-nostr-description-text">
We use LightningNetwork for paywalled content. First, log in to Nostr. Please pay the
LightningNetwork invoice after that. Nostr is used for the settlement synchronization
which passes the preimage by NIP-04 after paying the invoice. nsecKey is only stored
locally and doesn't share with server.
We use LightningNetwork for paywalled content. First, log in to Nostr, then pay your
LightningNetwork invoice. Nostr is used for the synchronization of payment proof which
passes the preimage of invoice by NIP-04 after paying. Your Nostr's SecKey is only
stored locally and doesn't share with server.
</p>
</div>
</div>
Expand Down Expand Up @@ -334,7 +334,7 @@
padding: 2rem;
overflow-x: auto;
}
:global(.post p>a) {
:global(.post p > a) {
text-decoration-line: underline;
}
article {
Expand Down

0 comments on commit 5d046c1

Please sign in to comment.