accounts: return a blank account for verify_credentials if it isn't resolved
This commit is contained in:
parent
1b2f4d9a54
commit
31114b6094
|
@ -5,7 +5,7 @@ import * as mixer from '@/mixer.ts';
|
|||
import { getAuthor, getFollowedPubkeys, getFollows, syncUser } from '@/queries.ts';
|
||||
import { booleanParamSchema, fileSchema } from '@/schema.ts';
|
||||
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||
import { toAccount, toRelationship, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
|
||||
import { accountFromPubkey, toAccount, toRelationship, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
|
||||
import { isFollowing, lookupAccount, nostrNow, Time } from '@/utils.ts';
|
||||
import { paginated, paginationSchema, parseBody } from '@/utils/web.ts';
|
||||
import { createEvent } from '@/utils/web.ts';
|
||||
|
@ -60,9 +60,9 @@ const verifyCredentialsController: AppController = async (c) => {
|
|||
const event = await getAuthor(pubkey);
|
||||
if (event) {
|
||||
return c.json(await toAccount(event, { withSource: true }));
|
||||
} else {
|
||||
return c.json(await accountFromPubkey(pubkey, { withSource: true }));
|
||||
}
|
||||
|
||||
return c.json({ error: 'Could not find user.' }, 404);
|
||||
};
|
||||
|
||||
const accountController: AppController = async (c) => {
|
||||
|
|
|
@ -24,6 +24,7 @@ export {
|
|||
nip13,
|
||||
nip19,
|
||||
nip21,
|
||||
type UnsignedEvent,
|
||||
verifySignature,
|
||||
} from 'npm:nostr-tools@^1.14.0';
|
||||
export { findReplyTag } from 'https://gitlab.com/soapbox-pub/mostr/-/raw/c67064aee5ade5e01597c6d23e22e53c628ef0e2/src/nostr/tags.ts';
|
||||
|
|
|
@ -2,12 +2,12 @@ import { isCWTag } from 'https://gitlab.com/soapbox-pub/mostr/-/raw/c67064aee5ad
|
|||
|
||||
import { Conf } from '@/config.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { type Event, findReplyTag, lodash, nip19, sanitizeHtml, TTLCache, unfurl } from '@/deps.ts';
|
||||
import { type Event, findReplyTag, lodash, nip19, sanitizeHtml, TTLCache, unfurl, type UnsignedEvent } from '@/deps.ts';
|
||||
import { getMediaLinks, parseNoteContent } from '@/note.ts';
|
||||
import { getAuthor, getFollowedPubkeys, getFollows } from '@/queries.ts';
|
||||
import { emojiTagSchema, filteredArray } from '@/schema.ts';
|
||||
import { jsonMediaDataSchema, jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||
import { isFollowing, type Nip05, nostrDate, parseNip05, Time } from '@/utils.ts';
|
||||
import { isFollowing, type Nip05, nostrDate, nostrNow, parseNip05, Time } from '@/utils.ts';
|
||||
import { verifyNip05Cached } from '@/utils/nip05.ts';
|
||||
import { findUser } from '@/db/users.ts';
|
||||
import { DittoAttachment, renderAttachment } from '@/views/attachment.ts';
|
||||
|
@ -19,7 +19,7 @@ interface ToAccountOpts {
|
|||
withSource?: boolean;
|
||||
}
|
||||
|
||||
async function toAccount(event: Event<0>, opts: ToAccountOpts = {}) {
|
||||
async function toAccount(event: UnsignedEvent<0>, opts: ToAccountOpts = {}) {
|
||||
const { withSource = false } = opts;
|
||||
|
||||
const { pubkey } = event;
|
||||
|
@ -75,6 +75,18 @@ async function toAccount(event: Event<0>, opts: ToAccountOpts = {}) {
|
|||
};
|
||||
}
|
||||
|
||||
function accountFromPubkey(pubkey: string, opts: ToAccountOpts = {}) {
|
||||
const event: UnsignedEvent<0> = {
|
||||
kind: 0,
|
||||
pubkey,
|
||||
content: '',
|
||||
tags: [],
|
||||
created_at: nostrNow(),
|
||||
};
|
||||
|
||||
return toAccount(event, opts);
|
||||
}
|
||||
|
||||
async function parseAndVerifyNip05(nip05: string | undefined, pubkey: string): Promise<Nip05 | undefined> {
|
||||
if (nip05 && await verifyNip05Cached(nip05, pubkey)) {
|
||||
return parseNip05(nip05);
|
||||
|
@ -257,7 +269,7 @@ function unfurlCardCached(url: string): Promise<PreviewCard | null> {
|
|||
return card;
|
||||
}
|
||||
|
||||
function toEmojis(event: Event) {
|
||||
function toEmojis(event: UnsignedEvent) {
|
||||
const emojiTags = event.tags.filter((tag) => tag[0] === 'emoji');
|
||||
|
||||
return filteredArray(emojiTagSchema).parse(emojiTags)
|
||||
|
@ -310,4 +322,4 @@ async function toNotificationMention(event: Event<1>, viewerPubkey?: string) {
|
|||
};
|
||||
}
|
||||
|
||||
export { toAccount, toNotification, toRelationship, toStatus };
|
||||
export { accountFromPubkey, toAccount, toNotification, toRelationship, toStatus };
|
||||
|
|
Loading…
Reference in New Issue