utils/Hex dir

This commit is contained in:
Martti Malmi 2023-08-21 22:53:08 +03:00
parent a7ead39015
commit 91e42f69d3
12 changed files with 44 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import { Link, route } from 'preact-router';
import InfiniteScroll from '@/components/helpers/InfiniteScroll';
import PubSub from '@/nostr/PubSub';
import { getEventReplyingTo, getEventRoot } from '@/nostr/utils';
import SortedMap from '@/utils/SortedMap';
import SortedMap from '@/utils/SortedMap/SortedMap.tsx';
import Key from '../../../nostr/Key';
import { translate as t } from '../../../translations/Translation.mjs';

View File

@ -9,7 +9,7 @@ import {
} from 'nostr-tools';
import { route } from 'preact-router';
import { PublicKey } from '@/utils/Hex.ts';
import { PublicKey } from '@/utils/Hex/Hex.ts';
import localState from '../state/LocalState.ts';
import Helpers from '../utils/Helpers';

View File

@ -4,7 +4,7 @@ import { Event } from 'nostr-tools';
import Filter from '@/nostr/Filter.ts';
import PubSub from '@/nostr/PubSub.ts';
import SortedMap from '@/utils/SortedMap.tsx';
import SortedMap from '@/utils/SortedMap/SortedMap.tsx';
interface SubscribeOptions {
filter: Filter;

View File

@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { EventID, PublicKey } from '@/utils/Hex';
import { EventID, PublicKey } from '@/utils/Hex/Hex.ts';
describe('PublicKey', () => {
it('should convert npub bech32 to hex', () => {
@ -54,4 +54,38 @@ describe('EventID', () => {
expect(eventId.toHex()).toEqual(noteHex);
expect(eventId.toBech32()).toEqual(noteBech32);
});
it('should init from hex', () => {
const hex = '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94';
const eventId = new EventID(hex);
expect(eventId.toHex()).toEqual(hex);
expect(eventId.toBech32()).toEqual(
'note1wdyajan9c9d72wanqe2l34lxgdu3q5esglhquusfkg34fqq6462qh4cjd5',
);
});
it('should fail with too long hex', () => {
const hex =
'7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae947349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94';
expect(() => new EventID(hex)).toThrow();
});
it('equals(hexStr)', () => {
const hex = '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94';
const eventId = new EventID(hex);
expect(eventId.equals(hex)).toEqual(true);
});
it('equals(EventID)', () => {
const hex = '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94';
const eventId = new EventID(hex);
const eventId2 = new EventID(hex);
expect(eventId.equals(eventId2)).toEqual(true);
});
it('equals(bech32)', () => {
const bech32 = 'note1wdyajan9c9d72wanqe2l34lxgdu3q5esglhquusfkg34fqq6462qh4cjd5';
const eventId = new EventID(bech32);
expect(eventId.equals(bech32)).toEqual(true);
});
});

View File

@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import RBSortedMap from '../../../tests/RBSortedMap.ts';
import RBSortedMap from '../../../../tests/RBSortedMap.ts';
import SortedMap from './SortedMap.tsx';

View File

@ -1,7 +1,7 @@
import { useEffect } from 'preact/hooks';
import { route } from 'preact-router';
import { EventID } from '@/utils/Hex.ts';
import { EventID } from '@/utils/Hex/Hex.ts';
import View from '@/views/View.tsx';
import CreateNoteForm from '../components/create/CreateNoteForm';

View File

@ -5,7 +5,7 @@ import InfiniteScroll from '@/components/helpers/InfiniteScroll';
import Key from '../../nostr/Key';
import localState from '../../state/LocalState.ts';
import { translate as t } from '../../translations/Translation.mjs';
import SortedMap from '../../utils/SortedMap';
import SortedMap from '../../utils/SortedMap/SortedMap.tsx';
import ChatListItem from './ChatListItem';
import NewChatButton from './NewChatButton';

View File

@ -14,7 +14,7 @@ import PubSub from '../../nostr/PubSub';
import localState from '../../state/LocalState.ts';
import { translate as t } from '../../translations/Translation.mjs';
import Helpers from '../../utils/Helpers';
import SortedMap from '../../utils/SortedMap';
import SortedMap from '../../utils/SortedMap/SortedMap.tsx';
import ChatMessageForm from './ChatMessageForm';
import { addGroup, sendSecretInvite } from './NewChat';

View File

@ -5,7 +5,7 @@ import SimpleImageModal from '@/components/modal/Image.tsx';
import { useProfile } from '@/nostr/hooks/useProfile.ts';
import { getEventReplyingTo, isRepost } from '@/nostr/utils.ts';
import useLocalState from '@/state/useLocalState.ts';
import { PublicKey } from '@/utils/Hex.ts';
import { PublicKey } from '@/utils/Hex/Hex.ts';
import ProfileHelmet from '@/views/profile/Helmet.tsx';
import Feed from '../../components/feed/Feed.tsx';

View File

@ -1,7 +1,7 @@
import { Event } from 'nostr-tools';
import { bench, describe } from 'vitest';
import SortedMap from '@/utils/SortedMap.tsx';
import SortedMap from '@/utils/SortedMap/SortedMap.tsx';
import events from './events.json';
import RBSortedMap from './RBSortedMap.ts';