refactor: remove @nostr-dev-kit/ndk from the daemon entirely (#44) #45

Merged
padreug merged 1 commit from fix/44-remove-ndk into dev 2026-06-27 00:49:18 +00:00
Owner

Follow-up to #43 (the transport swap). NDK no longer touched the relay/reconnect path, but it lingered in non-transport helpers; this removes it from the daemon completely. The daemon and main-entry bundles now contain zero @nostr-dev-kit/ndk references. Implements #44.

Ported to nostr-tools

File Was (NDK) Now (nostr-tools)
run.ts getKeys NDKPrivateKeySigner(nsec).user().npub getPublicKey(secretKeyBytes) → nip19.npubEncode
admin/commands/create_new_key.ts NDKPrivateKeySigner generate/import/existing generateSecretKey/getPublicKey/nip19
admin/commands/create_account.ts NDKPrivateKeySigner.generate() + NDKUserProfile generateSecretKey + local SkeletonProfile
lib/profile.ts NDK kind:0/3/10002 publish finalizeEvent + throwaway RelayPool
admin/index.ts + utils/dm-user.ts NDK kind:4 boot DM nip04 + finalizeEvent + RelayPool
commands/start.ts NDK NIP-89 (kind:31990) + NDKUser.fromNip05 finalizeEvent + RelayPool + nip05.queryProfile
config/index.ts NDKPrivateKeySigner.generate() default key generateSecretKey + hex
acl/index.ts, authorize.ts type-only (NostrEvent/NIP46Method/Hexpubkey) nostr-tools Event / local types / string

For the NIP-89 announcement I dropped the fetch-existing-d-tag step: this code always uses the default d="24133", so re-publishing replaces the same addressable (kind, author, d) event — identical effect, no read needed.

Latent bug fixed (surfaced by the type change)

authorize.ts's requestAuthorization called param.rawEvent(), but since #43 the signer passes a plain event object (no .rawEvent). The old NDKEvent type hid it; nostr-tools' Event type caught it. A sign_event approval would have recorded "[object Object]" as the request params — now it JSON.stringifys the event.

Scope

@nostr-dev-kit/ndk remains in package.json for one thing only: the standalone CLI src/client.ts — a NIP-46 client (the inverse component), not part of the daemon runtime. This matches #44's carve-out ("CLI may be handled separately"). Porting the CLI to a nostr-tools NIP-46 client (and dropping the npm dependency entirely) can be a small follow-up if wanted.

Tests

lifecycle 7 / relay 2 / nip46 1 / admin 2 green; daemon + main bundles verified NDK-free (grep nostr-dev-kit … = 0); tsc at the pre-existing baseline (3 unrelated authorize.ts / web/authorize.ts errors, untouched). The key-gen / profile / boot-DM / NIP-89 paths aren't unit-tested (no behavior change intended; they mirror the prior NDK logic).

Refs: #44, #43, #42, #41

🤖 Generated with Claude Code

Follow-up to #43 (the transport swap). NDK no longer touched the relay/reconnect path, but it lingered in non-transport helpers; this removes it from the daemon completely. **The daemon and main-entry bundles now contain zero `@nostr-dev-kit/ndk` references.** Implements #44. ## Ported to nostr-tools | File | Was (NDK) | Now (nostr-tools) | |---|---|---| | `run.ts` `getKeys` | `NDKPrivateKeySigner(nsec).user().npub` | `getPublicKey(secretKeyBytes) → nip19.npubEncode` | | `admin/commands/create_new_key.ts` | `NDKPrivateKeySigner` generate/import/existing | `generateSecretKey`/`getPublicKey`/`nip19` | | `admin/commands/create_account.ts` | `NDKPrivateKeySigner.generate()` + `NDKUserProfile` | `generateSecretKey` + local `SkeletonProfile` | | `lib/profile.ts` | NDK kind:0/3/10002 publish | `finalizeEvent` + throwaway `RelayPool` | | `admin/index.ts` + `utils/dm-user.ts` | NDK kind:4 boot DM | nip04 + `finalizeEvent` + `RelayPool` | | `commands/start.ts` | NDK NIP-89 (kind:31990) + `NDKUser.fromNip05` | `finalizeEvent` + `RelayPool` + `nip05.queryProfile` | | `config/index.ts` | `NDKPrivateKeySigner.generate()` default key | `generateSecretKey` + hex | | `acl/index.ts`, `authorize.ts` | type-only (`NostrEvent`/`NIP46Method`/`Hexpubkey`) | nostr-tools `Event` / local types / `string` | For the NIP-89 announcement I dropped the *fetch-existing-d-tag* step: this code always uses the default `d="24133"`, so re-publishing replaces the same addressable (kind, author, d) event — identical effect, no read needed. ## Latent bug fixed (surfaced by the type change) `authorize.ts`'s `requestAuthorization` called `param.rawEvent()`, but since #43 the signer passes a **plain** event object (no `.rawEvent`). The old `NDKEvent` type hid it; nostr-tools' `Event` type caught it. A `sign_event` approval would have recorded `"[object Object]"` as the request params — now it `JSON.stringify`s the event. ## Scope `@nostr-dev-kit/ndk` **remains in `package.json` for one thing only: the standalone CLI** `src/client.ts` — a NIP-46 *client* (the inverse component), not part of the daemon runtime. This matches #44's carve-out ("CLI may be handled separately"). Porting the CLI to a nostr-tools NIP-46 client (and dropping the npm dependency entirely) can be a small follow-up if wanted. ## Tests `lifecycle 7 / relay 2 / nip46 1 / admin 2` green; daemon + main bundles verified NDK-free (`grep nostr-dev-kit … = 0`); `tsc` at the pre-existing baseline (3 unrelated `authorize.ts` / `web/authorize.ts` errors, untouched). The key-gen / profile / boot-DM / NIP-89 paths aren't unit-tested (no behavior change intended; they mirror the prior NDK logic). Refs: #44, #43, #42, #41 🤖 Generated with [Claude Code](https://claude.com/claude-code)
refactor: remove @nostr-dev-kit/ndk from the daemon entirely (#44)
Some checks failed
Docker image / build-and-push-image (push) Has been cancelled
056c52cb5b
Follow-up to #43, which swapped the relay transport off NDK. NDK no longer
touched the relay/reconnect path but lingered in non-transport helpers; this
removes it from the daemon completely. The daemon and main-entry bundles now
contain zero `@nostr-dev-kit/ndk` references.

Ported to nostr-tools:
- run.ts getKeys — `NDKPrivateKeySigner(nsec).user().npub` -> getPublicKey +
  nip19.npubEncode (via secretKeyBytes).
- admin/commands/create_new_key.ts, create_account.ts — key generation
  (generate / import / existing-npub) -> generateSecretKey / getPublicKey /
  nip19; private-key hex via Buffer.
- lib/profile.ts (setupSkeletonProfile) — kind:0/3/10002 publish via a throwaway
  RelayPool + finalizeEvent; NDKUserProfile -> local SkeletonProfile type.
- admin/index.ts notifyAdminsOfNewConnection + utils/dm-user.ts — the one-shot
  boot DM (kind:4 nip04) via a throwaway RelayPool.
- commands/start.ts nip89announcement — kind:31990 NIP-89 handler via finalizeEvent
  + RelayPool, nip05 check via nostr-tools nip05.queryProfile. (Dropped the
  fetch-existing-d-tag step: this code always uses the default d="24133", so a
  re-publish replaces the prior addressable event — same effect.)
- config/index.ts — default-admin-key generation -> generateSecretKey + hex.
- acl/index.ts, authorize.ts — type-only imports (NostrEvent/NIP46Method/Hexpubkey)
  -> nostr-tools Event / local nip46 types / string.

Also fixes a latent bug #43 surfaced here: authorize.ts's requestAuthorization
called `param.rawEvent()`, but since #43 the signer passes a plain event object
(no .rawEvent), so a sign_event approval would have recorded "[object Object]".
The nostr-tools Event type caught it; now it JSON.stringifies the object.

`@nostr-dev-kit/ndk` stays in package.json ONLY for the standalone CLI
(src/client.ts, a NIP-46 *client* — the inverse component), per #44's carve-out.
Porting the CLI to drop the dependency entirely can be a small follow-up.

Tests: lifecycle 7 / relay 2 / nip46 1 / admin 2 green; daemon + main bundles
NDK-free (0 refs); tsc at the pre-existing baseline (3 unrelated authorize.ts /
web/authorize.ts errors).

Refs: #44, #43, #42, #41
padreug deleted branch fix/44-remove-ndk 2026-06-27 00:49:18 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/nsecbunkerd!45
No description provided.