- commit
- ef4749ac9086a9b338aa3aecc53cafb427c5764a
- parent
- c7a481ac13ea6e29be8e85ec5f9467774e4ec324
- author
- Dami <dami.etoile@gmail.com>
| M | src/ | 3 | +- |
| M | src/ | 3 | +- |
| M | src/ | 4 | -- |
| M | src/ | 16 | +-------- |
| M | src/ | 15 | +-------- |
| A | src/ | 55 | ++++++++++++++++++++++++++++++ |
| M | src/ | 2 | - |
| M | src/ | 3 | +- |
| M | src/ | 12 | ++---- |
| M | src/ | 5 | +-- |
| M | test/ | 3 | +- |
@@ -23,8 +23,9 @@ export { verifyBlossom } from "./auth.ts";
2323 import { tagValues, validate, type Event } from "./event.ts";2424 import { bytesToHex } from "./negentropy.ts";2525 import { localName } from "./pull.ts";26-import { KIND_REPORT, type Relay } from "./relay.ts";26+import { type Relay } from "./relay.ts";2727 import { notify } from "./notify.ts";28+import { KIND_REPORT } from "./kinds.ts";2829 2930 export type Blob = {3031 sha256: string;@@ -9,12 +9,11 @@
99 // get a smaller card that says so.1010 import { naddrEncode, nprofileEncode } from "nostr-tools/nip19";1111 import { svg as qrSVG, encode as qrEncode } from "./qr.ts";12-import { KIND_GROUP_METADATA } from "./identity.ts";1312 import { escapeHTML } from "./ui.ts";1413 import type { Relay } from "./relay.ts";1514 import { whoAsks } from "./auth.ts";15+import { KIND_APP_DATA, KIND_GROUP_METADATA } from "./kinds.ts";1616 17-export const KIND_APP_DATA = 30078;1817 export const CARD_D = "bind.ws/card";1918 export const QR_MAX_BYTES = 512;2019 const CACHE = "public, max-age=300";@@ -3,10 +3,6 @@ import { verifyEvent, type Event } from "nostr-tools/pure";
33 44 export type { Event };55 6-export const KIND_DELETION = 5;7-export const KIND_VANISH = 62;8-export const KIND_AUTH = 22242;9-106 export const isEphemeral = (k: number) => k >= 20000 && k < 30000;117 export const isReplaceable = (k: number) => k === 0 || k === 3 || (k >= 10000 && k < 20000);128 export const isAddressable = (k: number) => k >= 30000 && k < 40000;@@ -9,22 +9,10 @@
99 // a moderator moderates whatever the write rule says.1010 import { now, tagValues, type Event } from "./event.ts";1111 import { claimInvite, inviteCreator, memberInviteGate, mintInvite } from "./invites.ts";12-import { KIND_PROFILE, KIND_PUT_USER, KIND_REMOVE_USER, type GroupFacts } from "./identity.ts";12+import { type GroupFacts } from "./identity.ts";1313 import { can, ROLES, type Action } from "./roles.ts";1414 import type { Relay } from "./relay.ts";15-16-export const KIND_EDIT_METADATA = 9002;17-export const KIND_DELETE_EVENT = 9005;18-export const KIND_CREATE_GROUP = 9007;19-export const KIND_DELETE_GROUP = 9008;20-export const KIND_CREATE_INVITE = 9009;21-export const KIND_PINS = 9010;22-export const KIND_JOIN = 9021;23-export const KIND_LEAVE = 9022;24-// NIP-43's own join and leave requests: ephemeral, no h tag, a claim tag25-// carries the invite code.26-export const KIND_NIP43_JOIN = 28934;27-export const KIND_NIP43_LEAVE = 28936;15+import { KIND_PROFILE, KIND_PUT_USER, KIND_REMOVE_USER, KIND_EDIT_METADATA, KIND_DELETE_EVENT, KIND_CREATE_GROUP, KIND_DELETE_GROUP, KIND_CREATE_INVITE, KIND_PINS, KIND_JOIN, KIND_LEAVE, KIND_NIP43_JOIN, KIND_NIP43_LEAVE } from "./kinds.ts";2816 2917 export const isModeration = (kind: number) => kind >= 9000 && kind <= 9020;3018 export const isNIP43Request = (kind: number) => kind === KIND_NIP43_JOIN || kind === KIND_NIP43_LEAVE;@@ -8,20 +8,7 @@
88 import { finalizeEvent, getPublicKey, generateSecretKey, type Event } from "nostr-tools/pure";99 import { wrapEvent } from "nostr-tools/nip59";1010 import { bytesToHex, hexToBytes } from "./negentropy.ts";11-12-export const KIND_MEMBER_ADDED = 8000;13-export const KIND_MEMBER_REMOVED = 8001;14-export const KIND_ROSTER = 13534;15-export const KIND_PUT_USER = 9000;16-export const KIND_REMOVE_USER = 9001;17-export const KIND_GROUP_METADATA = 39000;18-export const KIND_GROUP_ADMINS = 39001;19-export const KIND_GROUP_MEMBERS = 39002;20-export const KIND_GROUP_ROLES = 39003;21-export const KIND_GROUP_PINS = 39005;22-export const KIND_ROLE_DEF = 33534;23-export const KIND_VIEW = 30078;24-export const KIND_PROFILE = 0;11+import { KIND_PROFILE, KIND_VIEW, KIND_MEMBER_ADDED, KIND_MEMBER_REMOVED, KIND_ROSTER, KIND_ROLE_DEF, KIND_PUT_USER, KIND_REMOVE_USER, KIND_GROUP_METADATA, KIND_GROUP_ADMINS, KIND_GROUP_MEMBERS, KIND_GROUP_ROLES, KIND_GROUP_PINS } from "./kinds.ts";2512 2613 export interface GroupFacts {2714 id: string;@@ -0,0 +1,55 @@
1+// Every event kind the relay treats specially, in one place, by the NIP2+// that defines it. A module that needs one imports it from here.3+4+// NIP-01, 09, 62, 425+export const KIND_PROFILE = 0;6+export const KIND_DELETION = 5;7+export const KIND_VANISH = 62;8+export const KIND_AUTH = 22242;9+10+// NIP-17 and NIP-59: the rumour and the gift wrap the relay writes its owner (notify.ts)11+export const KIND_DM = 14;12+export const KIND_WRAP = 1059;13+14+// NIP-56 reports, through the socket and the /report door15+export const KIND_REPORT = 1984;16+17+// NIP-46 remote signing traffic: ephemeral, encrypted end to end, never stored.18+export const KIND_NOSTR_CONNECT = 24133;19+20+// NIP-78 application data: the views the relay signs (views.ts) and the21+// card's record (card.ts). Presence is ephemeral: 20000 plus the view22+// kind's 78, so a client that knows one can guess the other.23+export const KIND_APP_DATA = 30078;24+export const KIND_VIEW = KIND_APP_DATA;25+export const KIND_PRESENCE = 20078;26+27+// NIP-43 relay membership: the roster, the role definition, and the deltas28+export const KIND_MEMBER_ADDED = 8000;29+export const KIND_MEMBER_REMOVED = 8001;30+export const KIND_ROSTER = 13534;31+export const KIND_ROLE_DEF = 33534;32+// NIP-43's own join and leave requests: ephemeral, no h tag, a claim tag33+// carries the invite code.34+export const KIND_NIP43_JOIN = 28934;35+export const KIND_NIP43_LEAVE = 28936;36+37+// NIP-29 groups: moderation events clients send, and the state the relay signs38+export const KIND_PUT_USER = 9000;39+export const KIND_REMOVE_USER = 9001;40+export const KIND_EDIT_METADATA = 9002;41+export const KIND_DELETE_EVENT = 9005;42+export const KIND_CREATE_GROUP = 9007;43+export const KIND_DELETE_GROUP = 9008;44+export const KIND_CREATE_INVITE = 9009;45+export const KIND_PINS = 9010;46+export const KIND_JOIN = 9021;47+export const KIND_LEAVE = 9022;48+export const KIND_GROUP_METADATA = 39000;49+export const KIND_GROUP_ADMINS = 39001;50+export const KIND_GROUP_MEMBERS = 39002;51+export const KIND_GROUP_ROLES = 39003;52+export const KIND_GROUP_PINS = 39005;53+54+// NIP-66: the discovery record the relay signs about itself55+export const KIND_RELAY_DISCOVERY = 30166;@@ -8,6 +8,7 @@ import { dial } from "./pull.ts";
88 import type { Relay } from "./relay.ts";99 import { viewRowsSince } from "./views.ts";1010 import type { FuelStatus } from "./fuel.ts";11+import { KIND_DM } from "./kinds.ts";1112 1213 export type NotifyKind = "reports" | "fuel" | "jobs" | "succession" | "digest" | "test";1314 export interface NotifySettings {@@ -19,8 +20,6 @@ export interface NotifySettings {
1920 }2021 export const DIGEST_DAYS = 7;2122 22-const KIND_DM = 14;23-export const KIND_WRAP = 1059;2423 const PUSH_RELAYS = 3;2524 const PUSH_TIMEOUT_MS = 4000;2625 // Below this balance, while past an allowance, fuel counts as low.@@ -3,11 +3,11 @@
33 // relay.go; policy is per relay and owner-managed (see manage.ts).44 import { DurableObject } from "cloudflare:workers";55 import { sha256 } from "@noble/hashes/sha2.js";6-import { KIND_AUTH, KIND_VANISH, difficulty, expiration, hasTag, isPrivate, now, tagValues, validate, canonical, type Event } from "./event.ts";6+import { difficulty, expiration, hasTag, isPrivate, now, tagValues, validate, canonical, type Event } from "./event.ts";77 import { match, parseFilter, type Filter } from "./filter.ts";88 import { hllOffset } from "./hll.ts";99 import { Negentropy, bytesToHex, hexToBytes } from "./negentropy.ts";10-import { KIND_RELAY_DISCOVERY, discovery } from "./nip66.ts";10+import { discovery } from "./nip66.ts";1111 import { Audit } from "./audit.ts";1212 import { ERR_DUPLICATE, ERR_TOO_BIG, Store, type Access } from "./store.ts";1313 import { Settings, isReplaceable, isProtected, SUCCESSION_WARN_DAYS } from "./settings.ts";@@ -21,7 +21,6 @@ import { blossom, blobBytes, isBlobPath } from "./blossom.ts";
2121 import { nip96 } from "./nip96.ts";2222 import { dumpBytes, dumpDue, dumpDownload, writeDump } from "./dumps.ts";2323 import { importBytes, importUpload } from "./imports.ts";24-import { KIND_GROUP_PINS } from "./identity.ts";2524 import { DIGEST_DAYS, digestText } from "./notify.ts";2625 import { claimFromProfile, nip05Document } from "./nip05.ts";2726 import { checkInvite, claimInvite, inviteCreator, invitePage, termsPage } from "./invites.ts";@@ -32,13 +31,13 @@ import { leaseDays, leaseNames, validName } from "./names.ts";
3231 import { MAX_JOBS, MAX_STANDING, checkJob, finishRun, newJobID, pruneFinished, pullView, runRound, startRun, type Job, type JobSpec } from "./jobs.ts";3332 import { Hostnames, forgetDomains } from "./domains.ts";3433 import { groupFacts, handleGroupEvent, isGroupManagement, isGroupState, isNIP43Request } from "./groups.ts";35-import { KIND_GROUP_MEMBERS } from "./identity.ts";3634 import { SIGNER_JS } from "./gen/signer.ts";3735 import { isPagePath, pages } from "./pages.ts";3836 import { notify, fuelLow, fuelText } from "./notify.ts";3937 import { card } from "./card.ts";40-import { KIND_PRESENCE, PRESENCE_THROTTLE_S, VIEWS, latestStored, nip11Views, presenceTags, serveView, viewByName, viewD, viewEvent, viewOn, viewStored, type ViewRun } from "./views.ts";38+import { PRESENCE_THROTTLE_S, VIEWS, latestStored, nip11Views, presenceTags, serveView, viewByName, viewD, viewEvent, viewOn, viewStored, type ViewRun } from "./views.ts";4139 import type { Blob } from "./blossom.ts";40+import { KIND_VANISH, KIND_AUTH, KIND_REPORT, KIND_NOSTR_CONNECT, KIND_PRESENCE, KIND_GROUP_MEMBERS, KIND_GROUP_PINS, KIND_RELAY_DISCOVERY } from "./kinds.ts";4241 4342 export interface Env {4443 RELAY: DurableObjectNamespace<Relay>;@@ -81,9 +80,6 @@ export interface Env {
8180 // gate(); 66 is the discovery record the relay signs about itself8281 // (publishDiscovery); 77 is negentropy sync (handleSync).8382 export const SUPPORTED_NIPS = [1, 5, 9, 11, 13, 17, 29, 40, 42, 45, 46, 50, 56, 59, 62, 66, 67, 70, 77, 86, 98];84-export const KIND_REPORT = 1984;85-// NIP-46 remote signing traffic: ephemeral, encrypted end to end, never stored.86-export const KIND_NOSTR_CONNECT = 24133;8783 export const SOFTWARE = "https://bind.ws";8884 export const VERSION = "0.1.0";8985 export const MAX_MESSAGE = 1024 * 1024;@@ -14,11 +14,8 @@
1414 import { bolt11Msats } from "./fuel.ts";1515 import { now, tag, tagValues, type Event } from "./event.ts";1616 import type { Relay } from "./relay.ts";17+import { KIND_VIEW, KIND_PRESENCE } from "./kinds.ts";1718 18-export const KIND_VIEW = 30078;19-// Presence is ephemeral: 20000 plus the view kind's 78, so a client that20-// knows one can guess the other.21-export const KIND_PRESENCE = 20078;2219 export const PRESENCE_ACTIVE_S = 15 * 60;2320 export const PRESENCE_THROTTLE_S = 30;2421 export const viewD = (name: string) => "bind.ws/view/" + name;@@ -5,9 +5,10 @@ import { describe, it, expect } from "vitest";
55 import { finalizeEvent, generateSecretKey, getPublicKey, type Event } from "nostr-tools/pure";66 import { getToken } from "nostr-tools/nip98";77 import type { Relay } from "../../src/relay.ts";8-import { KIND_PRESENCE, KIND_VIEW, viewD } from "../../src/views.ts";8+import { viewD } from "../../src/views.ts";99 import { now, ev, tagsOf, rpc, info, alarm } from "../helpers/relay.ts";1010 import { WS } from "../helpers/ws.ts";11+import { KIND_VIEW, KIND_PRESENCE } from "../../src/kinds.ts";1112 1213 async function view(host: string, name: string, sk: Uint8Array | null = null) {1314 const url = `http://${host}/view/${name}`;