Skip to content

Commit

Permalink
WIP: create nips module
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Mar 14, 2024
1 parent f189734 commit 3a83c39
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 175 deletions.
6 changes: 6 additions & 0 deletions core/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
"./clients": "./clients.ts",
"./protocol": "./protocol.ts",
"./relays": "./relays.ts"
},
"imports": {
"@lophus/lib": "jsr:@lophus/[email protected]"
},
"publish": {
"exclude": ["*_test.ts"]
}
}
11 changes: 8 additions & 3 deletions core/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// deno-lint-ignore-file no-empty-interface

/**
* Implementation of unextendable part of NIP-01 (Nostr basic protocol):
* Implementation of the fundamental part of NIP-01 (Nostr basic protocol):
* https://github.com/nostr-protocol/nips/blob/master/01.md
*
* See also `../../nips/01/protocol.d.ts` for the extendable part.
*
* See also `../../nips/01/protocol.ts` for the remaining "optional" part.
* @module
*/

Expand Down Expand Up @@ -59,6 +58,12 @@ export type EventSerializePrecursor<K extends EventKind = EventKind> = [
content: NostrEvent<K>["content"],
];

/** An event that has not been signed. */
export type UnsignedEvent<K extends EventKind = EventKind> = Omit<
NostrEvent<K>,
"id" | "pubkey" | "sig"
>;

// ----------------------
// Tags
// ----------------------
Expand Down
13 changes: 9 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"imports": {
"@noble/curves": "npm:@noble/curves@^1.3.0",
"@noble/hashes": "npm:@noble/hashes@^1.3.3",
"@lophus/core/clients": "./core/clients.ts",
"@lophus/core/protocol": "./core/protocol.ts",
"@lophus/core/relays": "./core/relays.ts",
"@lophus/lib/types": "./lib/types.ts",
"@lophus/lib/testing": "./lib/testing.ts",
"@lophus/lib/streams": "./lib/streams.ts",
"@lophus/core/clients": "./core/clients.ts",
"@lophus/core/protocol": "./core/protocol.ts",
"@lophus/core/relays": "./core/relays.ts",
"@lophus/nips": "./nips/mod.ts",
"@lophus/nips/01": "./nips/01/mod.ts",
"@lophus/nips/02": "./nips/02/mod.ts",
"@lophus/nips/07": "./nips/07/mod.ts",
"@lophus/nips/42": "./nips/42/mod.ts",
"@lophus/std/env": "./std/env.ts",
"@lophus/std/events": "./std/events.ts",
"@lophus/std/notes": "./std/notes.ts",
Expand All @@ -26,7 +31,7 @@
"build": "mkdir -p ./dist && deno run -A ./bin/bundle.ts",
"cache": "deno cache ./**/*.ts --lock",
"check": "deno check ./**/*.ts",
"lock": "deno task cache --lock-write && git add deno.lock",
"lock": "deno task cache --lock-write",
"pre-commit": "deno fmt && deno lint && deno task -q check && deno task -q lock && deno task -q test",
"test": "deno test -A --no-check",
"update": "deno run --allow-read --allow-env --allow-write --allow-net=registry.npmjs.org,jsr.io --allow-run=deno,git https://deno.land/x/[email protected]/cli.ts deno.json --unstable-lock",
Expand Down
16 changes: 14 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"./streams": "./streams.ts",
"./testing": "./testing.ts",
"./types": "./types.ts"
},
"publish": {
"exclude": ["*_test.ts"]
}
}
Empty file added nips/01/mod.ts
Empty file.
10 changes: 5 additions & 5 deletions nips/01/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Implementation of extendable part of NIP-01 (Nostr basic protocol):
* Implementation of the "optional" part of NIP-01 (Nostr basic protocol):
* https://github.com/nostr-protocol/nips/blob/master/01.md
*
* See also `../../core/protocol.d.ts` for the unextendable part.
* See also `../../core/protocol.ts` for the unextendable part.
*
* @module
*/

import "../../core/protocol.ts";
import type { Url } from "../../lib/types.ts";
import "@lophus/core/protocol";
import type { Url } from "@lophus/lib/types";

declare module "../../core/protocol.ts" {
declare module "@lophus/core/protocol" {
interface NipRecord {
1: {
ClientToRelayMessage: "EVENT" | "REQ" | "CLOSE";
Expand Down
Empty file added nips/02/mod.ts
Empty file.
1 change: 1 addition & 0 deletions nips/07/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./protocol.ts";
18 changes: 7 additions & 11 deletions nips/07/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { EventKind, NostrEvent, PublicKey } from "../../core/protocol.ts";
import type { Optional } from "../../lib/types.ts";
import {
EventKind,
NostrEvent,
PublicKey,
UnsignedEvent,
} from "@lophus/core/protocol";

declare module "../../core/protocol.ts" {
declare module "@lophus/core/protocol" {
interface NipRecord {
7: Record<string, never>;
}
}

/**
* An event that has not been signed.
*/
export type UnsignedEvent<K extends EventKind = EventKind> = Optional<
NostrEvent<K>,
"id" | "pubkey" | "sig"
>;

declare global {
interface Window {
nostr?: {
Expand Down
33 changes: 0 additions & 33 deletions nips/07/signs.ts

This file was deleted.

Empty file added nips/42/mod.ts
Empty file.
5 changes: 2 additions & 3 deletions nips/42/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "../../core/protocol.ts";
import "../../core/relays.ts";
import "@lophus/core/protocol";

declare module "../../core/protocol.ts" {
declare module "@lophus/core/protocol" {
interface NipRecord {
42: {
ClientToRelayMessage: "AUTH";
Expand Down
20 changes: 20 additions & 0 deletions nips/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@lophus/nips",
"version": "0.0.14",
"exports": {
".": "./mod.ts",
"./01": "./01/mod.ts",
"./02": "./02/mod.ts",
"./07": "./07/mod.ts",
"./42": "./42/mod.ts"
},
"imports": {
"@std/dotenv": "jsr:@std/dotenv@^0.219.1",
"@std/streams": "jsr:@std/streams@^0.219.1",
"@lophus/lib": "jsr:@lophus/[email protected]",
"@lophus/core": "jsr:@lophus/[email protected]"
},
"publish": {
"exclude": ["*_test.ts"]
}
}
4 changes: 4 additions & 0 deletions nips/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./01/mod.ts";
export * from "./02/mod.ts";
export * from "./07/mod.ts";
export * from "./42/mod.ts";
11 changes: 9 additions & 2 deletions std/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
"exports": {
".": "./mod.ts",
"./env": "./env.ts",
"./events": "./events.ts",
"./notes": "./notes.ts",
"./pools": "./pools.ts",
"./signs": "./signs.ts",
"./times": "./times.ts"
},
"imports": {
"@std/dotenv": "jsr:@std/dotenv@^0.219.1",
"@std/streams": "jsr:@std/streams@^0.219.1",
"@lophus/lib": "jsr:@lophus/lib@^0.0.14",
"@lophus/core": "jsr:@lophus/core@^0.0.14"
},
"publish": {
"exclude": ["*_test.ts"]
}
}
27 changes: 0 additions & 27 deletions std/events.ts

This file was deleted.

51 changes: 0 additions & 51 deletions std/events_test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions std/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from "./env.ts";
export * from "./events.ts";
export * from "./notes.ts";
export * from "./times.ts";
export * from "./signs.ts";
export * from "./pools.ts";
5 changes: 2 additions & 3 deletions std/notes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { Optional } from "@lophus/lib/types";
import type { NostrEvent, RelayUrl } from "@lophus/core/protocol";
import { type EventInit } from "@lophus/std/events";
import { type EventInit } from "@lophus/std/signs";

export type TextNote = EventInit<1>;

export type TextNoteInit = Optional<TextNote, "kind">;
export type TextNoteInit = Omit<TextNote, "kind">;

export class TextNoteComposer extends TransformStream<TextNoteInit, TextNote> {
constructor(readonly opts: { recommendedRelay?: RelayUrl } = {}) {
Expand Down
Loading

0 comments on commit 3a83c39

Please sign in to comment.