fix: use inner created_at timestamp nip17

This commit is contained in:
kieran 2024-09-22 15:46:26 +01:00
parent a6e6e0a632
commit baed390beb
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
4 changed files with 4 additions and 3 deletions

View File

@ -105,7 +105,7 @@ export class Nip17ChatSystem extends ExternalStore<Array<Chat>> implements ChatS
participants, participants,
messages: messages.map(m => ({ messages: messages.map(m => ({
id: m.id, id: m.id,
created_at: m.created_at, created_at: m.inner.created_at,
from: m.inner.pubkey, from: m.inner.pubkey,
tags: m.tags, tags: m.tags,
content: "", content: "",

View File

@ -44,7 +44,7 @@ export function unixNowMs() {
} }
export function jitter(n: number) { export function jitter(n: number) {
return n * 2 * Math.random() - n; return n * Math.random();
} }
export function deepClone<T>(obj: T) { export function deepClone<T>(obj: T) {

View File

@ -98,7 +98,7 @@ export class EventBuilder {
pubkey: this.#pubkey ?? "", pubkey: this.#pubkey ?? "",
content: this.#content ?? "", content: this.#content ?? "",
kind: this.#kind, kind: this.#kind,
created_at: (this.#createdAt ?? unixNow()) + (this.#jitter ? jitter(this.#jitter) : 0), created_at: (this.#createdAt ?? unixNow()) - (this.#jitter ? jitter(this.#jitter) : 0),
tags: this.#tags.sort((a, b) => a[0].localeCompare(b[0])), tags: this.#tags.sort((a, b) => a[0].localeCompare(b[0])),
} as NostrEvent; } as NostrEvent;
ev.id = EventExt.createId(ev); ev.id = EventExt.createId(ev);

View File

@ -314,6 +314,7 @@ export class EventPublisher {
eb.pow(powTarget, powMiner); eb.pow(powTarget, powMiner);
} }
eb.content(await signer.nip44Encrypt(JSON.stringify(inner), pTag)); eb.content(await signer.nip44Encrypt(JSON.stringify(inner), pTag));
eb.jitter(60 * 60 * 24);
return await eb.buildAndSign(secret); return await eb.buildAndSign(secret);
} }