Add the NIP-89 client tag to published events
Tag published photos (kind 360), deletions (kind 5) and zap requests (kind 9734) with ["client","Marco","31990:1f79058c…:marco.earth","wss://nostr.kosmos.org/"] so clients can attribute them to Marco. Uses applesauce's EventFactory clientTag via a shared app/utils/client-tag helper.
This commit is contained in:
5 files changed
+77
-6
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,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