Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blossom server #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/blossom-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
files
fileMap.json
*.txt
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions examples/blossom-server/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
8 changes: 8 additions & 0 deletions examples/blossom-server/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
38 changes: 38 additions & 0 deletions examples/blossom-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# create-svelte

Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

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

# create a new project in my-app
npm create svelte@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```bash
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
17 changes: 17 additions & 0 deletions examples/blossom-server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'

services:
minio:
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_ROOT_USER: blossom
MINIO_ROOT_PASSWORD: blossom123
volumes:
- minio_data:/data
command: server /data --console-address ":9001"

volumes:
minio_data:
8 changes: 8 additions & 0 deletions examples/blossom-server/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dotenv/config';
import type { Config } from 'drizzle-kit';

export default {
schema: './src/lib/server/db/schema.ts',
out: './drizzle',
driver: 'better-sqlite'
} satisfies Config;
7 changes: 7 additions & 0 deletions examples/blossom-server/drizzle/0000_fine_skrulls.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE `files` (
`hash` text PRIMARY KEY NOT NULL,
`pubkey` text NOT NULL,
`name` text,
`created` integer NOT NULL,
`size` integer NOT NULL
);
1 change: 1 addition & 0 deletions examples/blossom-server/drizzle/0001_wakeful_meltdown.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE files ADD `type` text;
58 changes: 58 additions & 0 deletions examples/blossom-server/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": "5",
"dialect": "sqlite",
"id": "dd74de54-13cc-4a7e-abf8-0705d27686d5",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"files": {
"name": "files",
"columns": {
"hash": {
"name": "hash",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"pubkey": {
"name": "pubkey",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created": {
"name": "created",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"size": {
"name": "size",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
65 changes: 65 additions & 0 deletions examples/blossom-server/drizzle/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"version": "5",
"dialect": "sqlite",
"id": "9509e78c-9d1b-4bc5-b9ec-21c815f712dc",
"prevId": "dd74de54-13cc-4a7e-abf8-0705d27686d5",
"tables": {
"files": {
"name": "files",
"columns": {
"hash": {
"name": "hash",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"pubkey": {
"name": "pubkey",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created": {
"name": "created",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"size": {
"name": "size",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
20 changes: 20 additions & 0 deletions examples/blossom-server/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "5",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1710538859694,
"tag": "0000_fine_skrulls",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1710539937946,
"tag": "0001_wakeful_meltdown",
"breakpoints": true
}
]
}
48 changes: 48 additions & 0 deletions examples/blossom-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "blossom-server",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"db:migrate": "tsx ./scripts/migrate.ts",
"db:generate": "drizzle-kit generate:sqlite",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@tailwindcss/typography": "^0.5.10",
"@types/better-sqlite3": "^7.6.9",
"autoprefixer": "^10.4.18",
"daisyui": "^4.7.3",
"drizzle-kit": "^0.20.14",
"postcss": "^8.4.35",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.4.1",
"tslib": "^2.4.1",
"tsx": "^4.7.1",
"typescript": "^5.0.0",
"vite": "^5.0.3"
},
"type": "module",
"dependencies": {
"@cashu-wallet/core": "workspace:*",
"@cashu-wallet/svelte": "workspace:*",
"@cashu-wallet/svelte-components": "workspace:*",
"@nostr-dev-kit/ndk": "^2.5.0",
"add": "^2.0.6",
"better-sqlite3": "^9.4.3",
"blossom-client": "^0.2.1",
"drizzle-orm": "^0.30.2",
"minio": "^7.1.3",
"nostr-tools": "^2.3.1",
"npm": "^10.5.0"
}
}
6 changes: 6 additions & 0 deletions examples/blossom-server/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
8 changes: 8 additions & 0 deletions examples/blossom-server/scripts/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dotenv/config';
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
import { db } from '../src/lib/server/db/client';

// This will run migrations on the database, skipping the ones already applied
migrate(db, { migrationsFolder: './drizzle' });

// Don't forget to close the connection, otherwise the script will hang
Binary file added examples/blossom-server/sqlite.db
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/blossom-server/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
13 changes: 13 additions & 0 deletions examples/blossom-server/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions examples/blossom-server/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
3 changes: 3 additions & 0 deletions examples/blossom-server/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare interface Window {
nostr?: any;
}
20 changes: 20 additions & 0 deletions examples/blossom-server/src/lib/blossom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ndk from './ndk';
import { getEventHash, type EventTemplate, type VerifiedEvent, verifiedSymbol } from 'nostr-tools';
import { get } from 'svelte/store';

export const signer = async (e: EventTemplate) => {
const $ndk = get(ndk);
if (!$ndk.signer) {
throw new Error('No signer available');
}
if (!$ndk.activeUser) {
throw new Error('No active user');
}

const event = e as VerifiedEvent;
event.pubkey = $ndk.activeUser.pubkey;
event.id = getEventHash(event);
event.sig = await $ndk.signer.sign(event);
event[verifiedSymbol] = true;
return event;
};
1 change: 1 addition & 0 deletions examples/blossom-server/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.
6 changes: 6 additions & 0 deletions examples/blossom-server/src/lib/ndk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import NDK from '@nostr-dev-kit/ndk';
import { writable } from 'svelte/store';

const ndk = writable(new NDK());

export default ndk;
Loading