event fix?
This commit is contained in:
parent
cfe6aa200b
commit
6c6121b504
2 changed files with 20 additions and 23 deletions
|
|
@ -1,13 +1,8 @@
|
||||||
import { getRepository } from "typeorm";
|
import { getRepository } from "typeorm";
|
||||||
import { User } from "./storage/entity/User";
|
import { User } from "./storage/entity/User";
|
||||||
import { UserOffer } from "./storage/entity/UserOffer";
|
import { UserOffer } from "./storage/entity/UserOffer";
|
||||||
import { validateEvent, type Event as BaseNostrEvent } from "nostr-tools";
|
|
||||||
import { ManagementGrant } from "./storage/entity/ManagementGrant";
|
import { ManagementGrant } from "./storage/entity/ManagementGrant";
|
||||||
import { NostrSend, NostrSettings } from "./nostr/handler";
|
import { NostrEvent, NostrSend, NostrSettings } from "./nostr/handler.js";
|
||||||
|
|
||||||
type NostrEvent = BaseNostrEvent & {
|
|
||||||
appId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class ManagementManager {
|
export class ManagementManager {
|
||||||
private nostrSend: NostrSend;
|
private nostrSend: NostrSend;
|
||||||
|
|
@ -30,13 +25,6 @@ export class ManagementManager {
|
||||||
}
|
}
|
||||||
const appPubkey = app.publicKey;
|
const appPubkey = app.publicKey;
|
||||||
|
|
||||||
// Validate event
|
|
||||||
const isValid = validateEvent(event);
|
|
||||||
if (!isValid) {
|
|
||||||
console.error("Invalid event");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check grant
|
// Check grant
|
||||||
const userIdTag = event.tags.find((t: string[]) => t[0] === 'p');
|
const userIdTag = event.tags.find((t: string[]) => t[0] === 'p');
|
||||||
if (!userIdTag) {
|
if (!userIdTag) {
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,16 @@ export type NostrSettings = {
|
||||||
clients: ClientInfo[]
|
clients: ClientInfo[]
|
||||||
maxEventContentLength: number
|
maxEventContentLength: number
|
||||||
}
|
}
|
||||||
export type NostrEvent = {
|
export type NostrEvent = Event & {
|
||||||
id: string
|
/** Identifier of the application as defined in NostrSettings.apps */
|
||||||
pub: string
|
appId: string;
|
||||||
content: string
|
/** High-resolution timer capture when processing began (BigInt serialized as string to keep JSON friendly) */
|
||||||
appId: string
|
startAtNano: string;
|
||||||
startAtNano: string
|
/** wall-clock millis when processing began */
|
||||||
startAtMs: number
|
startAtMs: number;
|
||||||
kind: number
|
/** Convenience duplicate of the sender pubkey (e.pubkey) kept for backwards-compat */
|
||||||
}
|
pub: string;
|
||||||
|
};
|
||||||
|
|
||||||
type SettingsRequest = {
|
type SettingsRequest = {
|
||||||
type: 'settings'
|
type: 'settings'
|
||||||
|
|
@ -216,7 +217,15 @@ export default class Handler {
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
this.eventCallback({ id: eventId, content, pub: e.pubkey, appId: app.appId, startAtNano, startAtMs, kind: e.kind })
|
const nostrEvent: NostrEvent = {
|
||||||
|
...e,
|
||||||
|
content,
|
||||||
|
appId: app.appId,
|
||||||
|
startAtNano,
|
||||||
|
startAtMs,
|
||||||
|
pub: e.pubkey,
|
||||||
|
}
|
||||||
|
this.eventCallback(nostrEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
async Send(initiator: SendInitiator, data: SendData, relays?: string[]) {
|
async Send(initiator: SendInitiator, data: SendData, relays?: string[]) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue