Add NIP-89 app handler docs and Nostr publishing scripts #132
No files matched your search
@@ -8,6 +8,7 @@ import { modifier } from 'ember-modifier';
|
||||
import { task } from 'ember-concurrency';
|
||||
import { EventFactory } from 'applesauce-core';
|
||||
import { encodePointer } from 'applesauce-core/helpers/pointers';
|
||||
import { withMarcoClientTag } from '../utils/client-tag';
|
||||
import or from 'ember-truth-helpers/helpers/or';
|
||||
import config from 'marco/config/environment';
|
||||
import DropdownMenu from './dropdown-menu';
|
||||
@@ -303,9 +304,11 @@ export default class PhotoGallery extends Component {
|
||||
tags.push(['i', this.currentPhoto.placeIdentifier]);
|
||||
}
|
||||
|
||||
const event = await EventFactory.fromKind(5)
|
||||
.content('Deleted photo')
|
||||
.modifyPublicTags(() => tags)
|
||||
const event = await withMarcoClientTag(
|
||||
EventFactory.fromKind(5)
|
||||
.content('Deleted photo')
|
||||
.modifyPublicTags(() => tags)
|
||||
)
|
||||
.as(this.nostrAuth.signer)
|
||||
.sign();
|
||||
const responses = await this.nostrRelay.publish(
|
||||
|
||||
@@ -9,6 +9,7 @@ import PlacePhotoUploadItem from './place-photo-upload-item';
|
||||
import Icon from '#components/icon';
|
||||
import { getSuggestedPhotoTags } from '../utils/photo-tag-suggestions';
|
||||
import { buildPlacePhotoTags } from '../utils/photo-tags';
|
||||
import { withMarcoClientTag } from '../utils/client-tag';
|
||||
import capitalize from '../helpers/capitalize';
|
||||
import includes from '../helpers/includes';
|
||||
import { fn } from '@ember/helper';
|
||||
@@ -167,9 +168,11 @@ export default class PlacePhotoUpload extends Component {
|
||||
});
|
||||
|
||||
// NIP-XX draft Place Photo event
|
||||
const event = await EventFactory.fromKind(360)
|
||||
.content('')
|
||||
.modifyPublicTags(() => tags)
|
||||
const event = await withMarcoClientTag(
|
||||
EventFactory.fromKind(360)
|
||||
.content('')
|
||||
.modifyPublicTags(() => tags)
|
||||
)
|
||||
.as(this.nostrAuth.signer)
|
||||
.sign();
|
||||
const responses = await this.nostrRelay.publish(
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from 'applesauce-common/helpers';
|
||||
import { getInboxes } from 'applesauce-core/helpers/mailboxes';
|
||||
import { firstValueFrom, timeout, catchError, of } from 'rxjs';
|
||||
import { MARCO_CLIENT_NAME, MARCO_HANDLER_POINTER } from '../utils/client-tag';
|
||||
|
||||
const DEFAULT_ZAP_RELAYS = [
|
||||
'wss://relay.damus.io',
|
||||
@@ -150,6 +151,7 @@ export default class NostrZapService extends Service {
|
||||
|
||||
return await ZapRequestFactory.event(event, amountMsats, relays)
|
||||
.message(message || '')
|
||||
.clientTag(MARCO_CLIENT_NAME, MARCO_HANDLER_POINTER)
|
||||
.as(signer)
|
||||
.sign();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// NIP-89 `client` tag for events published by Marco. It points at Marco's own
|
||||
// app handler (kind 31990) so other clients can attribute the event to the app.
|
||||
|
||||
export const MARCO_CLIENT_NAME = 'Marco';
|
||||
|
||||
export const MARCO_HANDLER_POINTER = {
|
||||
pubkey: '1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb',
|
||||
identifier: 'marco.earth',
|
||||
relays: ['wss://nostr.kosmos.org'],
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the NIP-89 client tag to an EventFactory (or subclass) and returns it,
|
||||
* so it can be chained: `withMarcoClientTag(factory).as(signer).sign()`.
|
||||
*
|
||||
* @param {object} factory An applesauce EventFactory
|
||||
* @returns {object} The same factory with the client tag operation queued
|
||||
*/
|
||||
export function withMarcoClientTag(factory) {
|
||||
return factory.clientTag(MARCO_CLIENT_NAME, MARCO_HANDLER_POINTER);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
# Marco as a NIP-89 App Handler
|
||||
|
||||
[NIP-89](https://github.com/nostr-protocol/nips/blob/master/89.md) lets clients
|
||||
discover applications that can handle an otherwise unknown event kind. Marco
|
||||
declares itself as the handler for the place media kinds it defines:
|
||||
|
||||
- `kind 360` — Place Photos and Videos (see
|
||||
[`nip-place-photos.md`](./nip-place-photos.md))
|
||||
- `kind 30360` — Place Reviews (to be added when
|
||||
[`nip-place-reviews.md`](./nip-place-reviews.md) ships)
|
||||
|
||||
Two events are involved:
|
||||
|
||||
| Event | Kind | Published by | Purpose |
|
||||
| -------------- | ------- | --------------------- | --------------------------------------------------- |
|
||||
| App handler | `31990` | the author's **npub** | Describes Marco and where to open each handled kind |
|
||||
| Recommendation | `31989` | a **user** key | Recommends Marco's handler to that user's followers |
|
||||
|
||||
Both are addressable: re-publishing with the same author and `d` tag replaces
|
||||
the previous event.
|
||||
|
||||
## Identity
|
||||
|
||||
Marco's app handler is signed by the author's own npub — the same identity that
|
||||
authors the NIP specs — so it appears on NostrHub under a real Nostr account
|
||||
rather than a separate app key:
|
||||
|
||||
```
|
||||
pubkey: 1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb
|
||||
npub: npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees
|
||||
naddr: naddr1qq9k6ctjvdhjuetpwf6xsq3qraustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89sxpqqqp70va9myaa
|
||||
```
|
||||
|
||||
The key itself is never stored in this repository. The publishing scripts sign
|
||||
through `nak` with an explicit signer from `NOSTR_SECRET_KEY` (an `nsec`/hex
|
||||
key, or a NIP-46 `bunker://` URL for a desktop signer), and `MARCO_APP_PUBKEY`
|
||||
in `scripts/nostr-common.sh` guards against signing from any other key. See
|
||||
[`publishing.md`](./publishing.md) for the shared setup.
|
||||
|
||||
## App handler event (`kind 31990`)
|
||||
|
||||
```json
|
||||
{
|
||||
"kind": 31990,
|
||||
"pubkey": "1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb",
|
||||
"content": "{\"name\":\"Marco\",\"about\":\"Unhosted maps app, enhancing OpenStreetMap with decentralized user data and content\",\"picture\":\"https://marco.earth/icons/icon-192.png\",\"website\":\"https://marco.earth\",\"nip05\":\"marco@kosmos.org\"}",
|
||||
"tags": [
|
||||
["d", "marco.earth"],
|
||||
["k", "360"],
|
||||
["web", "https://marco.earth/e/<bech32>", "nevent"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/01.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/07.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/09.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/19.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/21.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/46.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/57.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/65.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/73.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/89.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/92.md"],
|
||||
["i", "https://github.com/nostr-protocol/nips/blob/master/B7.md"],
|
||||
[
|
||||
"a",
|
||||
"30817:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:place-photos-and-videos",
|
||||
"wss://nostr.kosmos.org",
|
||||
"nip"
|
||||
],
|
||||
["t", "maps"],
|
||||
[
|
||||
"a",
|
||||
"30617:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:marco",
|
||||
"wss://relay.ngit.dev"
|
||||
]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- **`content`** is optional kind-0-style metadata. Because the app key is not an
|
||||
account users follow, Marco carries its name/description/icon/website here
|
||||
instead of (or in addition to) a `kind 0`.
|
||||
- **`d`** is `marco.earth`, so the addressable coordinate is
|
||||
`31990:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:marco.earth`.
|
||||
- **`k`** lists every event kind Marco handles. Add `["k", "30360"]` when place
|
||||
reviews ship.
|
||||
- **`web`** is a URL template. Clients replace `<bech32>` with the NIP-19
|
||||
encoding of the entity to open, then load the URL. Marco resolves this at
|
||||
`/e/:event_id`, reads the event's `i` tag and opens its place. When the event
|
||||
is a place photo, it focuses that photo in the place's carousel (the place URL
|
||||
gains a `?photo=<event-id>` query param). It accepts a raw 64-hex event id,
|
||||
`note1`/`nevent1`/`naddr1` codes (relay hints included), an optional `nostr:`
|
||||
prefix, and full permalinks (resolved via the last path segment).
|
||||
- The second `web` value (`nevent`) makes the tag kind-specific. When reviews
|
||||
ship, add an `naddr` template (reviews are addressable) pointing at the same
|
||||
route, since an `naddr` resolves to the reviewed place too.
|
||||
- **`i`** tags advertise the official NIPs Marco implements, and one **`a`** tag
|
||||
references Marco's own kind-30817 NIP (Place Photos and Videos). See
|
||||
[Implemented NIPs](#implemented-nips).
|
||||
- **`content.nip05`** is the app's NIP-05 identifier.
|
||||
- **`t`** tags are categories; NostrHub renders them as hashtags.
|
||||
- The kind-30617 **`a`** tag links Marco's ngit repository (with a relay hint),
|
||||
which NostrHub shows as the app's source.
|
||||
|
||||
## Implemented NIPs
|
||||
|
||||
The handler lists what Marco implements so directories such as NostrHub's app
|
||||
list can show it. NostrHub reads two shapes:
|
||||
|
||||
- official NIPs as `i` tags whose value is the NIP's file URL in
|
||||
[nostr-protocol/nips](https://github.com/nostr-protocol/nips), e.g.
|
||||
`["i", "https://github.com/nostr-protocol/nips/blob/master/89.md"]`;
|
||||
- custom NIPs (kind 30817) as an `a` tag marked `nip`, e.g.
|
||||
`["a", "30817:<pubkey>:place-photos-and-videos", "wss://nostr.kosmos.org", "nip"]`.
|
||||
|
||||
The set (edit `MARCO_NIPS` and `MARCO_NIP_PHOTOS_D` in
|
||||
`scripts/nostr-common.sh`):
|
||||
|
||||
| NIP | What Marco uses it for |
|
||||
| --- | ----------------------------------------- |
|
||||
| 01 | Base protocol |
|
||||
| 07 | `window.nostr` extension signer |
|
||||
| 09 | Photo deletion (kind 5) |
|
||||
| 19 | bech32 entities (`npub`/`nevent`/`naddr`) |
|
||||
| 21 | `nostr:` URIs |
|
||||
| 46 | Nostr Connect remote signer |
|
||||
| 57 | Zaps (kinds 9734/9735) |
|
||||
| 65 | Reading relay lists (kind 10002) |
|
||||
| 73 | External content IDs (`osm:`) |
|
||||
| 89 | App handlers (this NIP) |
|
||||
| 92 | `imeta` media metadata |
|
||||
| B7 | Blossom blob upload/delete (kind 24242) |
|
||||
|
||||
The [NipId & NIP References](https://nostrhub.io/naddr1qvzqqqrcvypzphm8lxn7gyf9w3wtu7k0hhxsx6ghsrry8hmm44c0t5ss3uk5lssqqqrxu6ts95mnxjpcazr)
|
||||
extension of NIP-73 defines a more general `["i", "<nipid>", …]` + `["k", "nip"]`
|
||||
form (`github.com:nostr-protocol/nips:89`, or `30817:<pubkey>:<d>`), but
|
||||
NostrHub's app directory does not parse it, so the shapes above are used
|
||||
instead.
|
||||
|
||||
## Recommendation event (`kind 31989`)
|
||||
|
||||
Published from a _user's_ account (`scripts/publish-app-recommendation.sh`):
|
||||
|
||||
```json
|
||||
{
|
||||
"kind": 31989,
|
||||
"pubkey": "<user-pubkey>",
|
||||
"content": "",
|
||||
"tags": [
|
||||
["d", "360"],
|
||||
[
|
||||
"a",
|
||||
"31990:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:marco.earth",
|
||||
"wss://nostr.kosmos.org",
|
||||
"web"
|
||||
],
|
||||
[
|
||||
"a",
|
||||
"31990:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:marco.earth",
|
||||
"wss://relay.primal.net",
|
||||
"web"
|
||||
]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- **`d`** is the supported event kind this recommendation applies to (`360`
|
||||
now; publish another with `d = 30360` later).
|
||||
- Each **`a`** tag is the app-handler coordinate plus a relay hint and the
|
||||
platform (`web`). Two tags give clients two places to find the handler.
|
||||
|
||||
## Relays
|
||||
|
||||
Publishing targets live in `scripts/nostr-relays.txt` (one URL per line; `#`
|
||||
comments allowed). `scripts/nostr-common.sh` loads them into `NOSTR_RELAYS`;
|
||||
edit that file to change where events are sent. An explicitly set
|
||||
`NOSTR_RELAYS` environment variable overrides it.
|
||||
|
||||
## Publishing
|
||||
|
||||
```sh
|
||||
# app handler, signed by the author's own npub
|
||||
NOSTR_SECRET_KEY='bunker://...' ./scripts/publish-app-handler.sh
|
||||
|
||||
# recommendation, signed by your own key
|
||||
NOSTR_SECRET_KEY='<your key or bunker>' ./scripts/publish-app-recommendation.sh
|
||||
|
||||
# retire an old handler (only its author key can delete it)
|
||||
NOSTR_SECRET_KEY='<old app key>' ./scripts/unpublish-app-handler.sh --dry-run
|
||||
NOSTR_SECRET_KEY='<old app key>' ./scripts/unpublish-app-handler.sh
|
||||
|
||||
# add --dry-run to any script to sign and print without publishing
|
||||
```
|
||||
|
||||
`MARCO_APP_PUBKEY` in `scripts/nostr-common.sh` holds the handler's author npub;
|
||||
the scripts refuse to sign from any other key. `unpublish-app-handler.sh`
|
||||
targets `MARCO_OLD_APP_PUBKEY` by default (pass a pubkey to override).
|
||||
@@ -0,0 +1,77 @@
|
||||
# Publishing Marco's NIPs on Nostr
|
||||
|
||||
Marco distributes the place NIPs both as files in `doc/nostr/` and as Nostr
|
||||
events, so they are discoverable and updatable without a git host.
|
||||
|
||||
## Custom NIPs (`kind 30817`)
|
||||
|
||||
Marco publishes each spec as a **`kind 30817` "Custom NIP"** event, the
|
||||
_NIPs on Nostr_ convention:
|
||||
|
||||
- `content` — the full Markdown of the spec
|
||||
- `["d", "<slug>"]` — unique identifier
|
||||
- `["title", "<title>"]`
|
||||
- `["k", "<kind>", "<kind name>"]` — the event kind(s) the spec defines
|
||||
- `["status", "review"]` — NostrHub metadata (not part of the kind-30817 spec)
|
||||
|
||||
Kind 30817 is addressable, so the spec is identified by `(pubkey, d)`. Editing
|
||||
the file and re-running the publish script **replaces** the previous event;
|
||||
this only works from the original author's key, which the script enforces.
|
||||
|
||||
### Published specs
|
||||
|
||||
| Spec | `d` | `k` | Status |
|
||||
| ----------------- | ------------------------- | ------- | ----------------- |
|
||||
| Photos and Videos | `place-photos-and-videos` | `360` | published |
|
||||
| Place Reviews | `place-reviews` | `30360` | not yet published |
|
||||
|
||||
The published photos spec is authored by
|
||||
|
||||
```
|
||||
npub: npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees
|
||||
hex: 1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb
|
||||
naddr: naddr1qvzqqqrcvypzq8meqkx80g3yuklzymy0qfx2ekk56aqc2ht4ak03z3em4r4cdcwtqqthqmrpvdjj6urgda6x7uedv9hxgttkd9jx2mmnl2q70n
|
||||
```
|
||||
|
||||
and is readable at
|
||||
https://nostrhub.io/naddr1qvzqqqrcvypzq8meqkx80g3yuklzymy0qfx2ekk56aqc2ht4ak03z3em4r4cdcwtqqthqmrpvdjj6urgda6x7uedv9hxgttkd9jx2mmnl2q70n.
|
||||
|
||||
## Relays
|
||||
|
||||
All publishing scripts read their relay list from `scripts/nostr-relays.txt`
|
||||
(one URL per line; `#` comments allowed), loaded into `NOSTR_RELAYS` by
|
||||
`scripts/nostr-common.sh`. Edit that file to change where events are sent; an
|
||||
explicitly set `NOSTR_RELAYS` environment variable overrides it.
|
||||
|
||||
## Scripts
|
||||
|
||||
| Script | Publishes |
|
||||
| --------------------------------------- | --------------------------------------------------- |
|
||||
| `scripts/publish-nip.sh photos` | `nip-place-photos.md` as kind 30817 |
|
||||
| `scripts/publish-nip.sh reviews` | `nip-place-reviews.md` as kind 30817 (when ready) |
|
||||
| `scripts/publish-app-handler.sh` | Marco's NIP-89 app handler (kind 31990) |
|
||||
| `scripts/publish-app-recommendation.sh` | A NIP-89 recommendation (kind 31989) pointing at it |
|
||||
|
||||
Each script signs via `nak` with an explicit `NOSTR_SECRET_KEY` and refuses to
|
||||
run without one, so nak's machine default key is never used by accident. The
|
||||
NIP scripts additionally verify the signer is the spec's author, so an update
|
||||
cannot accidentally fork the spec instead of replacing it.
|
||||
|
||||
## Signing
|
||||
|
||||
`NOSTR_SECRET_KEY` accepts an `nsec`, hex or `ncryptsec` key, or a NIP-46
|
||||
`bunker://` URL to sign with a desktop signer over Nostr Connect. For example:
|
||||
|
||||
```sh
|
||||
NOSTR_SECRET_KEY='bunker://<remote-pubkey>?relay=wss://relay.example' \
|
||||
./scripts/publish-nip.sh photos
|
||||
```
|
||||
|
||||
Use `--dry-run` to sign and print the event without publishing:
|
||||
|
||||
```sh
|
||||
NOSTR_SECRET_KEY='...' ./scripts/publish-nip.sh photos --dry-run
|
||||
```
|
||||
|
||||
See [`nip-89-app-handler.md`](./nip-89-app-handler.md) for the app handler and
|
||||
recommendation events.
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
# Shared configuration for Marco's Nostr publishing scripts.
|
||||
#
|
||||
# Sourced (not executed) by:
|
||||
# scripts/publish-app-handler.sh
|
||||
# scripts/publish-app-recommendation.sh
|
||||
# scripts/publish-nip.sh
|
||||
#
|
||||
# Nothing here is secret. Signing is done through nak with an explicit signer
|
||||
# from the environment (nsec, hex, ncryptsec or a NIP-46 bunker:// URL).
|
||||
|
||||
# Prints an error and exits.
|
||||
die() {
|
||||
echo "error: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Relays every script publishes to. Edit scripts/nostr-relays.txt (one URL per
|
||||
# line) instead of this file. An explicitly set NOSTR_RELAYS overrides it.
|
||||
if [ -z "${NOSTR_RELAYS:-}" ]; then
|
||||
RELAYS_FILE="${NOSTR_RELAYS_FILE:-$(dirname "$0")/nostr-relays.txt}"
|
||||
[ -f "$RELAYS_FILE" ] || die "relay list not found: $RELAYS_FILE (create it or set NOSTR_RELAYS)"
|
||||
NOSTR_RELAYS=$(
|
||||
tr -d '\r' <"$RELAYS_FILE" |
|
||||
sed -e 's/#.*//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d' |
|
||||
tr '\n' ' '
|
||||
)
|
||||
NOSTR_RELAYS=${NOSTR_RELAYS% }
|
||||
[ -n "$NOSTR_RELAYS" ] || die "no relays found in $RELAYS_FILE"
|
||||
fi
|
||||
|
||||
# Hex pubkey that signs and therefore owns Marco's NIP-89 app handler
|
||||
# (kind 31990). This is the author's own npub (the same identity that authors
|
||||
# the NIP specs), so the handler appears under a real Nostr identity rather
|
||||
# than a separate app key. The scripts refuse to publish from any other key.
|
||||
MARCO_APP_PUBKEY="1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb"
|
||||
|
||||
# The previous dedicated "Marco app" key. Its handler (same `d`) is a separate
|
||||
# addressable coordinate that must be deleted explicitly with
|
||||
# scripts/unpublish-app-handler.sh. Safe to remove once it is gone.
|
||||
MARCO_OLD_APP_PUBKEY="72424a5bdb8b3e6bcb2731643d43b26f3e3750ae61e5d601719aabd12ee94316"
|
||||
|
||||
# "d" identifier of Marco's NIP-89 app handler (kind 31990).
|
||||
MARCO_APP_D="marco.earth"
|
||||
|
||||
# App metadata advertised in the handler:
|
||||
# - NIP-05 identifier (goes into `content.nip05`)
|
||||
# - category tags, one `["t", <tag>]` each (NostrHub shows these as
|
||||
# hashtags/categories)
|
||||
# - git repo reference: a kind-30617 `a` tag plus a relay hint
|
||||
MARCO_APP_NIP05="marco@kosmos.org"
|
||||
MARCO_APP_TAGS="maps"
|
||||
MARCO_APP_REPO="30617:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:marco"
|
||||
MARCO_APP_REPO_RELAY="wss://relay.ngit.dev"
|
||||
|
||||
# Author of the published NIP specs (kind 30817, "NIPs on Nostr"). A published
|
||||
# spec can only be updated by this key; publishing from another key would fork
|
||||
# the spec instead of replacing it, so the scripts guard against it.
|
||||
NIP_SPEC_PUBKEY="1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb"
|
||||
|
||||
# Official NIPs Marco implements, advertised in the app handler (kind 31990) as
|
||||
# NIP references so directories like NostrHub can list them. Space separated
|
||||
# two-character identifiers (B7 is Blossom). See doc/nostr/nip-89-app-handler.md.
|
||||
MARCO_NIPS="01 07 09 19 21 46 57 65 73 89 92 B7"
|
||||
|
||||
# "d" identifier of Marco's own published NIP (kind 30817): Place Photos and
|
||||
# Videos. The app handler references it via its `a` address.
|
||||
MARCO_NIP_PHOTOS_D="place-photos-and-videos"
|
||||
|
||||
# Relay hint for the custom NIP reference.
|
||||
MARCO_NIP_RELAY="wss://nostr.kosmos.org"
|
||||
|
||||
# Requires an explicit signer so we never silently fall back to nak's machine
|
||||
# default key. Exports NAK_SEC for the nak calls.
|
||||
require_signer() {
|
||||
command -v nak >/dev/null 2>&1 || die "nak is not installed (https://github.com/fiatjaf/nak)"
|
||||
[ -n "${NOSTR_SECRET_KEY:-}" ] || die "set NOSTR_SECRET_KEY (nsec, hex, ncryptsec or bunker://...) first"
|
||||
NAK_SEC="$NOSTR_SECRET_KEY"
|
||||
export NAK_SEC
|
||||
}
|
||||
|
||||
# Reads a signed event (nak prints compact, single-line JSON) on stdin and
|
||||
# prints its pubkey.
|
||||
event_pubkey() {
|
||||
sed -n 's/.*"pubkey":"\([0-9a-f]\{64\}\)".*/\1/p'
|
||||
}
|
||||
|
||||
# Refuses to continue when the signer is not the expected identity.
|
||||
# $1 expected pubkey ("" skips the check), $2 actual pubkey.
|
||||
assert_pubkey() {
|
||||
if [ -n "$1" ] && [ "$2" != "$1" ]; then
|
||||
die "signer is $2, expected $1 — wrong key for this event"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
# Relays every Nostr publish script sends to.
|
||||
#
|
||||
# One WebSocket URL per line. Blank lines and everything after a "#" are
|
||||
# ignored. Edit this file to change where Marco publishes its NIP-89 app
|
||||
# handler, recommendations and kind-30817 specs.
|
||||
#
|
||||
# Read by scripts/nostr-common.sh into NOSTR_RELAYS. Set the NOSTR_RELAYS
|
||||
# environment variable to override this file entirely.
|
||||
|
||||
# Marco's home relay
|
||||
wss://nostr.kosmos.org
|
||||
|
||||
# Relays used by the Ditto/NostrHub clients
|
||||
wss://relay.ditto.pub
|
||||
wss://relay.dreamith.to
|
||||
|
||||
# General public relays
|
||||
wss://nos.lol
|
||||
wss://relay.primal.net
|
||||
wss://relay.nostr.band
|
||||
wss://relay.snort.social
|
||||
wss://relay.damus.io
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Publish (or re-publish) Marco's NIP-89 app handler (kind 31990).
|
||||
#
|
||||
# Kind 31990 is addressable, so re-running this replaces the previous event
|
||||
# (same author + "d" tag). See doc/nostr/nip-89-app-handler.md.
|
||||
#
|
||||
# Usage:
|
||||
# NOSTR_SECRET_KEY='bunker://...' ./scripts/publish-app-handler.sh [--dry-run]
|
||||
#
|
||||
set -eu
|
||||
|
||||
. "$(dirname "$0")/nostr-common.sh"
|
||||
|
||||
DRY_RUN=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
*) die "unknown argument: $arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
require_signer
|
||||
|
||||
APP_ORIGIN="https://marco.earth"
|
||||
APP_CONTENT="{\"name\":\"Marco\",\"about\":\"Unhosted maps app, enhancing OpenStreetMap with decentralized user data and content\",\"picture\":\"$APP_ORIGIN/icons/icon-192.png\",\"website\":\"$APP_ORIGIN\",\"nip05\":\"$MARCO_APP_NIP05\"}"
|
||||
NIP_URL_PREFIX="https://github.com/nostr-protocol/nips/blob/master"
|
||||
|
||||
# "k" tags list every kind this app handles; add k=30360 when place reviews
|
||||
# ship. Clients replace <bech32> with a NIP-19 nevent before opening the URL;
|
||||
# the /e/<nevent> route is implemented in Marco (see the doc).
|
||||
#
|
||||
# "i" tags advertise the official NIPs Marco implements and an "a" tag points
|
||||
# at Marco's own kind-30817 NIP. These are the shapes NostrHub's app directory
|
||||
# reads (see doc/nostr/nip-89-app-handler.md).
|
||||
set -- nak event --sec "$NAK_SEC" -k 31990 \
|
||||
-d "$MARCO_APP_D" \
|
||||
-t k=360 \
|
||||
-t "web=$APP_ORIGIN/e/<bech32>;nevent" \
|
||||
-c "$APP_CONTENT"
|
||||
|
||||
for nip in $MARCO_NIPS; do
|
||||
set -- "$@" -t "i=$NIP_URL_PREFIX/$nip.md"
|
||||
done
|
||||
|
||||
set -- "$@" -t "a=30817:$NIP_SPEC_PUBKEY:$MARCO_NIP_PHOTOS_D;$MARCO_NIP_RELAY;nip"
|
||||
|
||||
# Category tags (NostrHub shows these as hashtags/categories).
|
||||
for tag in $MARCO_APP_TAGS; do
|
||||
set -- "$@" -t "t=$tag"
|
||||
done
|
||||
|
||||
# Git repo (ngit) reference: kind-30617 address plus relay hint.
|
||||
set -- "$@" -t "a=$MARCO_APP_REPO;$MARCO_APP_REPO_RELAY"
|
||||
|
||||
event=$("$@")
|
||||
|
||||
pubkey=$(printf '%s\n' "$event" | event_pubkey)
|
||||
[ -n "$pubkey" ] || die "could not read pubkey from the signed event"
|
||||
assert_pubkey "$MARCO_APP_PUBKEY" "$pubkey"
|
||||
|
||||
if [ "$DRY_RUN" = 1 ]; then
|
||||
printf '%s\n' "$event"
|
||||
echo "dry run: signed by $pubkey, not published" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "$event" | nak event $NOSTR_RELAYS
|
||||
|
||||
echo "published app handler (kind 31990) as $pubkey"
|
||||
if [ -z "$MARCO_APP_PUBKEY" ]; then
|
||||
echo "record MARCO_APP_PUBKEY=$pubkey in scripts/nostr-common.sh" >&2
|
||||
fi
|
||||
naddr=$(nak encode naddr -k 31990 -a "$pubkey" -d "$MARCO_APP_D" 2>/dev/null || true)
|
||||
if [ -n "$naddr" ]; then
|
||||
echo "naddr: $naddr"
|
||||
fi
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Publish (or re-publish) a NIP-89 recommendation (kind 31989) pointing at
|
||||
# Marco's app handler. Signed by a *user* key (your own), not the app key.
|
||||
#
|
||||
# Kind 31989 is addressable per (author, "d" = supported kind), so re-running
|
||||
# replaces your previous recommendation for that kind.
|
||||
#
|
||||
# Usage:
|
||||
# NOSTR_SECRET_KEY='...' ./scripts/publish-app-recommendation.sh [kind] [--dry-run]
|
||||
#
|
||||
# kind defaults to 360 (place photos); pass 30360 once place reviews ship.
|
||||
#
|
||||
set -eu
|
||||
|
||||
. "$(dirname "$0")/nostr-common.sh"
|
||||
|
||||
DRY_RUN=0
|
||||
RECOMMEND_KIND=360
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
*[!0-9]*) die "unknown argument: $arg" ;;
|
||||
*) RECOMMEND_KIND="$arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$MARCO_APP_PUBKEY" ] || die "set MARCO_APP_PUBKEY in scripts/nostr-common.sh (run publish-app-handler.sh first)"
|
||||
require_signer
|
||||
|
||||
# One "a" tag per relay hint, so clients can find the handler either way.
|
||||
event=$(
|
||||
nak event --sec "$NAK_SEC" -k 31989 \
|
||||
-d "$RECOMMEND_KIND" \
|
||||
-t "a=31990:$MARCO_APP_PUBKEY:$MARCO_APP_D;wss://nostr.kosmos.org;web" \
|
||||
-t "a=31990:$MARCO_APP_PUBKEY:$MARCO_APP_D;wss://relay.primal.net;web"
|
||||
)
|
||||
|
||||
pubkey=$(printf '%s\n' "$event" | event_pubkey)
|
||||
[ -n "$pubkey" ] || die "could not read pubkey from the signed event"
|
||||
|
||||
if [ "$DRY_RUN" = 1 ]; then
|
||||
printf '%s\n' "$event"
|
||||
echo "dry run: signed by $pubkey, not published" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "$event" | nak event $NOSTR_RELAYS
|
||||
|
||||
echo "published recommendation (kind 31989, kind $RECOMMEND_KIND) as $pubkey"
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Publish (or re-publish) one of Marco's NIPs as a kind 30817 "Custom NIP"
|
||||
# ("NIPs on Nostr"). Kind 30817 is addressable, so re-running replaces the
|
||||
# previous version (same author + "d" tag); the spec is updated, not forked.
|
||||
#
|
||||
# See doc/nostr/publishing.md.
|
||||
#
|
||||
# Usage:
|
||||
# NOSTR_SECRET_KEY='...' ./scripts/publish-nip.sh [photos|reviews] [--dry-run]
|
||||
#
|
||||
set -eu
|
||||
|
||||
. "$(dirname "$0")/nostr-common.sh"
|
||||
|
||||
DRY_RUN=0
|
||||
WHICH=photos
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
photos | reviews) WHICH="$arg" ;;
|
||||
*) die "unknown argument: $arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$WHICH" in
|
||||
photos)
|
||||
NIP_PATH="doc/nostr/nip-place-photos.md"
|
||||
NIP_D="place-photos-and-videos"
|
||||
NIP_TITLE="Place Photos and Videos"
|
||||
NIP_KIND="360"
|
||||
;;
|
||||
reviews)
|
||||
NIP_PATH="doc/nostr/nip-place-reviews.md"
|
||||
NIP_D="place-reviews"
|
||||
NIP_TITLE="Place Reviews"
|
||||
NIP_KIND="30360"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Allow running from anywhere: resolve paths against the repo root.
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
NIP_FILE="$root/$NIP_PATH"
|
||||
[ -f "$NIP_FILE" ] || die "spec not found: $NIP_FILE"
|
||||
|
||||
require_signer
|
||||
|
||||
# "status" is NostrHub metadata; the spec-defined tags are d/title/k (see
|
||||
# doc/nostr/publishing.md). The "client" tag is deliberately not set.
|
||||
event=$(
|
||||
nak event --sec "$NAK_SEC" -k 30817 \
|
||||
-d "$NIP_D" \
|
||||
-t "title=$NIP_TITLE" \
|
||||
-t "alt=Nostr Implementation Possibility: $NIP_TITLE" \
|
||||
-t "k=$NIP_KIND;$NIP_TITLE" \
|
||||
-t "status=review" \
|
||||
-c "@$NIP_FILE"
|
||||
)
|
||||
|
||||
pubkey=$(printf '%s\n' "$event" | event_pubkey)
|
||||
[ -n "$pubkey" ] || die "could not read pubkey from the signed event"
|
||||
assert_pubkey "$NIP_SPEC_PUBKEY" "$pubkey"
|
||||
|
||||
if [ "$DRY_RUN" = 1 ]; then
|
||||
printf '%s\n' "$event"
|
||||
echo "dry run: signed by $pubkey, not published" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "$event" | nak event $NOSTR_RELAYS
|
||||
|
||||
echo "published NIP '$NIP_TITLE' (kind 30817) as $pubkey"
|
||||
naddr=$(nak encode naddr -k 30817 -a "$pubkey" -d "$NIP_D" 2>/dev/null || true)
|
||||
if [ -n "$naddr" ]; then
|
||||
echo "naddr: $naddr"
|
||||
fi
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Delete (unpublish) a NIP-89 app handler (kind 31990) by publishing a NIP-09
|
||||
# kind-5 deletion for its addressable coordinate. Only the handler's own author
|
||||
# key can delete it, so NOSTR_SECRET_KEY must be the key that signed it.
|
||||
#
|
||||
# Used to retire Marco's old handler after moving it to the author's own npub.
|
||||
#
|
||||
# Usage:
|
||||
# NOSTR_SECRET_KEY='<old app key>' ./scripts/unpublish-app-handler.sh [<pubkey>] [--dry-run]
|
||||
#
|
||||
# <pubkey> defaults to MARCO_OLD_APP_PUBKEY in scripts/nostr-common.sh.
|
||||
#
|
||||
set -eu
|
||||
|
||||
. "$(dirname "$0")/nostr-common.sh"
|
||||
|
||||
DRY_RUN=0
|
||||
TARGET_PUBKEY="$MARCO_OLD_APP_PUBKEY"
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
*[!0-9a-fA-F]* | '') die "invalid pubkey: $arg" ;;
|
||||
*) TARGET_PUBKEY="$arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$TARGET_PUBKEY" ] || die "no pubkey to unpublish (set MARCO_OLD_APP_PUBKEY or pass one)"
|
||||
TARGET_PUBKEY=$(printf '%s' "$TARGET_PUBKEY" | tr 'A-F' 'a-f')
|
||||
|
||||
# Addressable handler coordinate, e.g. 31990:<pubkey>:marco.earth
|
||||
address="31990:$TARGET_PUBKEY:$MARCO_APP_D"
|
||||
|
||||
require_signer
|
||||
|
||||
# NIP-09: a parameterized replaceable event is deleted with an `a` tag pointing
|
||||
# at its coordinate (the `k` tag names the kind being deleted).
|
||||
event=$(
|
||||
nak event --sec "$NAK_SEC" -k 5 \
|
||||
-t "a=$address" \
|
||||
-t k=31990 \
|
||||
-c ''
|
||||
)
|
||||
|
||||
pubkey=$(printf '%s\n' "$event" | event_pubkey)
|
||||
[ -n "$pubkey" ] || die "could not read pubkey from the signed event"
|
||||
assert_pubkey "$TARGET_PUBKEY" "$pubkey"
|
||||
|
||||
if [ "$DRY_RUN" = 1 ]; then
|
||||
printf '%s\n' "$event"
|
||||
echo "dry run: deletion signed by $pubkey, not published" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "$event" | nak event $NOSTR_RELAYS
|
||||
|
||||
echo "published deletion for $address as $pubkey"
|
||||
@@ -0,0 +1,42 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { EventFactory } from 'applesauce-core';
|
||||
import {
|
||||
MARCO_CLIENT_NAME,
|
||||
MARCO_HANDLER_POINTER,
|
||||
withMarcoClientTag,
|
||||
} from 'marco/utils/client-tag';
|
||||
|
||||
module('Unit | Utility | client-tag', function () {
|
||||
test('exposes the Marco name and handler pointer', function (assert) {
|
||||
assert.strictEqual(MARCO_CLIENT_NAME, 'Marco');
|
||||
assert.deepEqual(MARCO_HANDLER_POINTER, {
|
||||
pubkey:
|
||||
'1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb',
|
||||
identifier: 'marco.earth',
|
||||
relays: ['wss://nostr.kosmos.org'],
|
||||
});
|
||||
});
|
||||
|
||||
test('adds the NIP-89 client tag to an event', async function (assert) {
|
||||
const template = await withMarcoClientTag(EventFactory.fromKind(360));
|
||||
|
||||
assert.deepEqual(
|
||||
template.tags.find((tag) => tag[0] === 'client'),
|
||||
[
|
||||
'client',
|
||||
'Marco',
|
||||
'31990:1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb:marco.earth',
|
||||
'wss://nostr.kosmos.org/',
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
test('does not add the client tag to direct-message kinds', async function (assert) {
|
||||
const template = await withMarcoClientTag(EventFactory.fromKind(4));
|
||||
|
||||
assert.notOk(
|
||||
template.tags.find((tag) => tag[0] === 'client'),
|
||||
'no client tag on a kind 4 event'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user