From 0bb4ccf5c97e9cca4116162cb5c1017a50b3487e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 30 Apr 2024 18:43:53 -0500 Subject: [PATCH] Move nostr-tools to an import alias --- deno.json | 2 ++ src/config.ts | 4 +++- src/controllers/api/accounts.ts | 2 +- src/controllers/api/oauth.ts | 3 ++- src/controllers/api/search.ts | 2 +- src/controllers/api/statuses.ts | 3 ++- src/controllers/well-known/webfinger.ts | 2 +- src/deps.ts | 18 ------------------ src/middleware/auth19.ts | 3 ++- src/nostr-wasm.ts | 4 ++++ src/note.ts | 4 +++- src/schemas/nostr.ts | 2 +- src/server.ts | 1 + src/storages/InternalRelay.ts | 2 +- src/storages/hydrate.ts | 2 +- src/storages/pool-store.ts | 4 +++- src/utils.ts | 2 +- src/utils/api.ts | 3 ++- src/utils/nip05.ts | 4 +++- src/utils/nip98.ts | 3 ++- src/views/mastodon/accounts.ts | 4 +++- src/views/mastodon/emojis.ts | 3 ++- src/views/mastodon/statuses.ts | 2 +- src/workers/verify.worker.ts | 5 ++++- 24 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 src/nostr-wasm.ts diff --git a/deno.json b/deno.json index b83aaa6..a617569 100644 --- a/deno.json +++ b/deno.json @@ -26,6 +26,8 @@ "@std/streams": "jsr:@std/streams@^0.223.0", "hono": "https://deno.land/x/hono@v3.10.1/mod.ts", "hono/middleware": "https://deno.land/x/hono@v3.10.1/middleware.ts", + "nostr-tools": "npm:nostr-tools@^2.5.1", + "nostr-wasm": "npm:nostr-wasm@^0.1.0", "kysely": "npm:kysely@^0.26.3", "kysely_deno_postgres": "https://deno.land/x/kysely_deno_postgres@v0.4.0/mod.ts", "zod": "npm:zod@^3.23.4", diff --git a/src/config.ts b/src/config.ts index c259563..8331f71 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,9 @@ import url from 'node:url'; + +import { getPublicKey, nip19 } from 'nostr-tools'; import { z } from 'zod'; -import { dotenv, getPublicKey, nip19 } from '@/deps.ts'; +import { dotenv } from '@/deps.ts'; /** Load environment config from `.env` */ await dotenv.load({ diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 0289799..a3ac378 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -1,9 +1,9 @@ import { NostrFilter } from '@nostrify/nostrify'; +import { nip19 } from 'nostr-tools'; import { z } from 'zod'; import { type AppController } from '@/app.ts'; import { Conf } from '@/config.ts'; -import { nip19 } from '@/deps.ts'; import { getAuthor, getFollowedPubkeys } from '@/queries.ts'; import { booleanParamSchema, fileSchema } from '@/schema.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; diff --git a/src/controllers/api/oauth.ts b/src/controllers/api/oauth.ts index 7ada2a4..4f1f495 100644 --- a/src/controllers/api/oauth.ts +++ b/src/controllers/api/oauth.ts @@ -1,6 +1,7 @@ +import { nip19 } from 'nostr-tools'; import { z } from 'zod'; -import { lodash, nip19 } from '@/deps.ts'; +import { lodash } from '@/deps.ts'; import { AppController } from '@/app.ts'; import { nostrNow } from '@/utils.ts'; import { parseBody } from '@/utils/api.ts'; diff --git a/src/controllers/api/search.ts b/src/controllers/api/search.ts index 2facd80..63561c4 100644 --- a/src/controllers/api/search.ts +++ b/src/controllers/api/search.ts @@ -1,8 +1,8 @@ import { NostrEvent, NostrFilter } from '@nostrify/nostrify'; +import { nip19 } from 'nostr-tools'; import { z } from 'zod'; import { AppController } from '@/app.ts'; -import { nip19 } from '@/deps.ts'; import { booleanParamSchema } from '@/schema.ts'; import { nostrIdSchema } from '@/schemas/nostr.ts'; import { searchStore } from '@/storages.ts'; diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index d257d98..2c94a71 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -1,10 +1,11 @@ import { NIP05, NostrEvent, NostrFilter } from '@nostrify/nostrify'; +import { nip19 } from 'nostr-tools'; import { z } from 'zod'; import { type AppController } from '@/app.ts'; import { Conf } from '@/config.ts'; import { getUnattachedMediaByIds } from '@/db/unattached-media.ts'; -import { ISO6391, nip19 } from '@/deps.ts'; +import { ISO6391 } from '@/deps.ts'; import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { addTag, deleteTag } from '@/tags.ts'; diff --git a/src/controllers/well-known/webfinger.ts b/src/controllers/well-known/webfinger.ts index 9a24576..38bc994 100644 --- a/src/controllers/well-known/webfinger.ts +++ b/src/controllers/well-known/webfinger.ts @@ -1,7 +1,7 @@ +import { nip19 } from 'nostr-tools'; import { z } from 'zod'; import { Conf } from '@/config.ts'; -import { nip19 } from '@/deps.ts'; import { localNip05Lookup } from '@/utils/nip05.ts'; import type { AppContext, AppController } from '@/app.ts'; diff --git a/src/deps.ts b/src/deps.ts index f7e09cb..1c001d7 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,18 +1,5 @@ import 'https://gitlab.com/soapbox-pub/deno-safe-fetch/-/raw/v1.0.0/load.ts'; export { RelayPoolWorker } from 'npm:nostr-relaypool2@0.6.34'; -export { - type EventTemplate, - getEventHash, - matchFilter, - matchFilters, - nip05, - nip13, - nip19, - nip21, - type UnsignedEvent, - type VerifiedEvent, -} from 'npm:nostr-tools@^2.3.1'; -export { finalizeEvent, getPublicKey, verifyEvent } from 'npm:nostr-tools@^2.3.1/wasm'; export { parseFormData } from 'npm:formdata-helper@^0.3.0'; // @deno-types="npm:@types/lodash@4.14.194" export { default as lodash } from 'https://esm.sh/lodash@4.17.21'; @@ -69,8 +56,3 @@ export { default as Debug } from 'https://gitlab.com/soapbox-pub/stickynotes/-/r export { Stickynotes } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.3.0/mod.ts'; export type * as TypeFest from 'npm:type-fest@^4.3.0'; - -import { setNostrWasm } from 'npm:nostr-tools@^2.3.1/wasm'; -import { initNostrWasm } from 'npm:nostr-wasm@^0.1.0'; - -await initNostrWasm().then(setNostrWasm); diff --git a/src/middleware/auth19.ts b/src/middleware/auth19.ts index d81c257..90fc444 100644 --- a/src/middleware/auth19.ts +++ b/src/middleware/auth19.ts @@ -1,6 +1,7 @@ import { HTTPException } from 'hono'; +import { getPublicKey, nip19 } from 'nostr-tools'; + import { type AppMiddleware } from '@/app.ts'; -import { getPublicKey, nip19 } from '@/deps.ts'; /** We only accept "Bearer" type. */ const BEARER_REGEX = new RegExp(`^Bearer (${nip19.BECH32_REGEX.source})$`); diff --git a/src/nostr-wasm.ts b/src/nostr-wasm.ts new file mode 100644 index 0000000..4413590 --- /dev/null +++ b/src/nostr-wasm.ts @@ -0,0 +1,4 @@ +import { setNostrWasm } from 'nostr-tools/wasm'; +import { initNostrWasm } from 'nostr-wasm'; + +await initNostrWasm().then(setNostrWasm); diff --git a/src/note.ts b/src/note.ts index a19a793..fe03d7f 100644 --- a/src/note.ts +++ b/src/note.ts @@ -1,5 +1,7 @@ +import { nip19, nip21 } from 'nostr-tools'; + import { Conf } from '@/config.ts'; -import { linkify, linkifyStr, mime, nip19, nip21 } from '@/deps.ts'; +import { linkify, linkifyStr, mime } from '@/deps.ts'; import { type DittoAttachment } from '@/views/mastodon/attachments.ts'; linkify.registerCustomProtocol('nostr', true); diff --git a/src/schemas/nostr.ts b/src/schemas/nostr.ts index 0497093..7f51f6c 100644 --- a/src/schemas/nostr.ts +++ b/src/schemas/nostr.ts @@ -1,6 +1,6 @@ +import { getEventHash, verifyEvent } from 'nostr-tools'; import { z } from 'zod'; -import { getEventHash, verifyEvent } from '@/deps.ts'; import { jsonSchema, safeUrlSchema } from '@/schema.ts'; /** Schema to validate Nostr hex IDs such as event IDs and pubkeys. */ diff --git a/src/server.ts b/src/server.ts index 68af681..4825e99 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,6 @@ import '@/precheck.ts'; import '@/sentry.ts'; +import '@/nostr-wasm.ts'; import app from '@/app.ts'; import { Conf } from '@/config.ts'; diff --git a/src/storages/InternalRelay.ts b/src/storages/InternalRelay.ts index d42f94f..233a095 100644 --- a/src/storages/InternalRelay.ts +++ b/src/storages/InternalRelay.ts @@ -9,8 +9,8 @@ import { NRelay, } from '@nostrify/nostrify'; import { Machina } from '@nostrify/nostrify/utils'; +import { matchFilter } from 'nostr-tools'; -import { matchFilter } from '@/deps.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { purifyEvent } from '@/storages/hydrate.ts'; diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index 619b798..dbe277a 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -1,7 +1,7 @@ import { NostrEvent, NStore } from '@nostrify/nostrify'; +import { matchFilter } from 'nostr-tools'; import { db } from '@/db.ts'; -import { matchFilter } from '@/deps.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; import { DittoTables } from '@/db/DittoTables.ts'; import { Conf } from '@/config.ts'; diff --git a/src/storages/pool-store.ts b/src/storages/pool-store.ts index 6620ec9..93ca24e 100644 --- a/src/storages/pool-store.ts +++ b/src/storages/pool-store.ts @@ -1,5 +1,7 @@ import { NostrEvent, NostrFilter, NSet, NStore } from '@nostrify/nostrify'; -import { Debug, matchFilters, type RelayPoolWorker } from '@/deps.ts'; +import { matchFilters } from 'nostr-tools'; + +import { Debug, type RelayPoolWorker } from '@/deps.ts'; import { normalizeFilters } from '@/filter.ts'; import { purifyEvent } from '@/storages/hydrate.ts'; import { abortError } from '@/utils/abort.ts'; diff --git a/src/utils.ts b/src/utils.ts index 747ea43..085d8af 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import { NostrEvent } from '@nostrify/nostrify'; +import { EventTemplate, getEventHash, nip19 } from 'nostr-tools'; import { z } from 'zod'; -import { type EventTemplate, getEventHash, nip19 } from '@/deps.ts'; import { nostrIdSchema } from '@/schemas/nostr.ts'; /** Get the current time in Nostr format. */ diff --git a/src/utils/api.ts b/src/utils/api.ts index cd4e6e2..3f89d3f 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,10 +1,11 @@ import { NostrEvent, NostrFilter } from '@nostrify/nostrify'; import { type Context, HTTPException } from 'hono'; +import { EventTemplate } from 'nostr-tools'; import { z } from 'zod'; import { type AppContext } from '@/app.ts'; import { Conf } from '@/config.ts'; -import { Debug, EventTemplate, parseFormData, type TypeFest } from '@/deps.ts'; +import { Debug, parseFormData, type TypeFest } from '@/deps.ts'; import * as pipeline from '@/pipeline.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts'; import { APISigner } from '@/signers/APISigner.ts'; diff --git a/src/utils/nip05.ts b/src/utils/nip05.ts index 4de6411..d7a2d98 100644 --- a/src/utils/nip05.ts +++ b/src/utils/nip05.ts @@ -1,6 +1,8 @@ import { NIP05 } from '@nostrify/nostrify'; +import { nip19 } from 'nostr-tools'; + import { Conf } from '@/config.ts'; -import { Debug, nip19 } from '@/deps.ts'; +import { Debug } from '@/deps.ts'; import { SimpleLRU } from '@/utils/SimpleLRU.ts'; import { Time } from '@/utils/time.ts'; import { eventsDB } from '@/storages.ts'; diff --git a/src/utils/nip98.ts b/src/utils/nip98.ts index 80df9ae..74e60a4 100644 --- a/src/utils/nip98.ts +++ b/src/utils/nip98.ts @@ -1,5 +1,6 @@ import { NostrEvent } from '@nostrify/nostrify'; -import { type EventTemplate, nip13 } from '@/deps.ts'; +import { EventTemplate, nip13 } from 'nostr-tools'; + import { decode64Schema, jsonSchema } from '@/schema.ts'; import { signedEventSchema } from '@/schemas/nostr.ts'; import { eventAge, findTag, nostrNow, sha256 } from '@/utils.ts'; diff --git a/src/views/mastodon/accounts.ts b/src/views/mastodon/accounts.ts index a0f9bb7..18f3a9d 100644 --- a/src/views/mastodon/accounts.ts +++ b/src/views/mastodon/accounts.ts @@ -1,5 +1,7 @@ +import { nip19, UnsignedEvent } from 'nostr-tools'; + import { Conf } from '@/config.ts'; -import { lodash, nip19, type UnsignedEvent } from '@/deps.ts'; +import { lodash } from '@/deps.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { getLnurl } from '@/utils/lnurl.ts'; diff --git a/src/views/mastodon/emojis.ts b/src/views/mastodon/emojis.ts index 0ba2895..089f2cb 100644 --- a/src/views/mastodon/emojis.ts +++ b/src/views/mastodon/emojis.ts @@ -1,4 +1,5 @@ -import { UnsignedEvent } from '@/deps.ts'; +import { UnsignedEvent } from 'nostr-tools'; + import { EmojiTag, emojiTagSchema } from '@/schemas/nostr.ts'; import { filteredArray } from '@/schema.ts'; diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index b367555..06ef164 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -1,8 +1,8 @@ import { NostrEvent } from '@nostrify/nostrify'; import { isCWTag } from 'https://gitlab.com/soapbox-pub/mostr/-/raw/c67064aee5ade5e01597c6d23e22e53c628ef0e2/src/nostr/tags.ts'; +import { nip19 } from 'nostr-tools'; import { Conf } from '@/config.ts'; -import { nip19 } from '@/deps.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; import { getMediaLinks, parseNoteContent } from '@/note.ts'; import { jsonMediaDataSchema } from '@/schemas/nostr.ts'; diff --git a/src/workers/verify.worker.ts b/src/workers/verify.worker.ts index 0b5f668..d72387a 100644 --- a/src/workers/verify.worker.ts +++ b/src/workers/verify.worker.ts @@ -1,5 +1,8 @@ import { NostrEvent } from '@nostrify/nostrify'; -import { Comlink, type VerifiedEvent, verifyEvent } from '@/deps.ts'; +import { VerifiedEvent, verifyEvent } from 'nostr-tools'; + +import { Comlink } from '@/deps.ts'; +import '@/nostr-wasm.ts'; export const VerifyWorker = { verifyEvent(event: NostrEvent): event is VerifiedEvent {