refactor: decode pubkey with right import in search account

This commit is contained in:
P. Reis 2024-04-20 21:52:36 -03:00
parent 49f06869a3
commit 12b030c8aa
2 changed files with 4 additions and 6 deletions

View File

@ -16,7 +16,6 @@ import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { renderRelationship } from '@/views/mastodon/relationships.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';
import { hydrateEvents } from '@/storages/hydrate.ts';
import { decode } from 'npm:nostr-tools@^2.5.0/nip19';
const usernameSchema = z
.string().min(1).max(30)
@ -104,7 +103,7 @@ const accountSearchController: AppController = async (c) => {
if ((results.length < 1) && query.match(/npub1\w+/)) {
const possibleNpub = query;
try {
const npubHex = decode(possibleNpub);
const npubHex = nip19.decode(possibleNpub);
return c.json([await accountFromPubkey(String(npubHex.data))]);
} catch (e) {
console.log(e);

View File

@ -9,7 +9,6 @@ import { nip05Cache } from '@/utils/nip05.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';
import { hydrateEvents } from '@/storages/hydrate.ts';
import { decode } from 'npm:nostr-tools@^2.5.0/nip19';
/** Matches NIP-05 names with or without an @ in front. */
const ACCT_REGEX = /^@?(?:([\w.+-]+)@)?([\w.-]+)$/;
@ -62,7 +61,7 @@ const searchController: AppController = async (c) => {
if ((result.data.type === 'accounts') && (accounts.length < 1) && (result.data.q.match(/npub1\w+/))) {
const possibleNpub = result.data.q;
try {
const npubHex = decode(possibleNpub);
const npubHex = nip19.decode(possibleNpub);
accounts.push(await accountFromPubkey(String(npubHex.data)));
} catch (e) {
console.log(e);
@ -70,8 +69,8 @@ const searchController: AppController = async (c) => {
}
return c.json({
accounts: accounts,
statuses: statuses,
accounts,
statuses,
hashtags: [],
});
};