buzz icon indicating copy to clipboard operation
buzz copied to clipboard

feat: Support NIP-46 Remote Signing aka nsec bunker

Open Giszmo opened this issue 4 months ago • 6 comments

Exposing private keys to different clients is a dangerous pattern clients should not encourage. If at all feasible, the app should build on remote signers or discourage pasting existing keys or at the very least allow power users to use a remote signing device.

Nostr does not support key rotation or sub-keys, so users end up with their keys being handled by multiple clients on multiple devices and sometimes even online services. Most social clients these days support nip46.

Giszmo avatar Jul 24 '26 10:07 Giszmo

+1. The strongest case here is agents: every buzz agent holds its own nsec, and a key an agent can read is one prompt injection away from signing anything. NIP-46 puts the key behind a boundary that can say no. That upgrades signing from attributable to enforceable, which matters more for agent members than for any human client. We hit exactly this building Sanctuary (agent key custody: encrypted at rest, transient decrypt for signing, gated approvals). Glad to compare notes.

eriknewton avatar Jul 24 '26 18:07 eriknewton

+1. the attributable vs enforceable framing is right. NIP-46 gets you partway there but it leaves one question open: what enforces the no? if the signer is a process on a general-purpose host, the enforcement is still a software promise and a compromised host, poisoned dependency or stolen key can substitute a signer that says yes to everything while presenting a valid NIP-46 interface.

hardware attestation closes this gap cause the key can only ever be exercised inside an enclave whose measured code hash matches an expected value, enforced by the KMS at key-release time and not by the process itself. signer can't be swapped out without breaking attestation, the session log is hash-chained and independently verifiable and key custody is structural. not even the operator can extract the nsec from a running enclave.

we're building this out in VAR with an evidence-bundle spec called APEX that a third party can verify without trusting us. a natural extension for buzz would be a companion NIP (we've been calling it NIP-EA), an optional ["attest", "<bundle-id>", "<pcr0>", "<attestation-endpoint>"] tag on agent events, so verifiers that care about execution integrity can check it independently and verifiers that don't can ignore it.

would be happy to compare notes because it sounds like we're working on adjacent pieces of this, especially with Sanctuary.

kennethkabogo avatar Jul 26 '26 16:07 kennethkabogo

Agreed on the diagnosis, and I would put the boundary a layer lower.

We enforce at the OS boundary on a general-purpose host: the agent gets its own account, and a kernel packet filter denies that account every destination the operator has not approved. Measurements on an unmodified Hermes agent are here: https://github.com/NousResearch/hermes-agent/issues/4656. Off-list hosts denied 18 of 18, my own account unaffected 30 of 30 in the same window.

That answers a different question than attestation does. Yours establishes that the code holding the key is the code you expect. Mine bounds where a process can talk at all, and needs no enclave.

Honest limit on mine: root is above it. A host compromised to root can disable the filter, and I measured exactly that this week. Enclave-held keys survive that. My wall does not.

Happy to compare notes.

eriknewton avatar Jul 26 '26 23:07 eriknewton

read #4656 measurement in full. the numbers hold up, and so does the corrected ps. agreed these answer different questions and I'd push the distinction one step further than needs no enclave.

Castle Wall's threat model is a process operating within its own privilege level, like a prompt-injected shell command trying to phone home or exfiltrate over the network. against that, a per-uid kernel egress wall is close to free and your data shows it works, but root doesn't need to beat the wall at all to get the key because it can just read the signing process's memory directly with zero network traffic involved. so "root is above it" isn't only "root can disable the filter." the filter is irrelevant to that path from the start because the key is sitting in ordinary process memory the whole time regardless of what's allowed out on the wire.

that's the specific thing enclave memory isolation changes in kind, not degree. on Nitro, the parent instance's own root cannot read enclave memory. it's enforced by the hypervisor below the guest OS and not by anything running inside it that a privileged attacker could introspect or disable. your wall and an attested signer would be bounding different attacker capabilities. egress control is the right answer to "the agent's own logic tries to leave," and it needs no hardware dependency, which matters cause most agents shouldn't need a TEE just to talk to an LLM API. attestation is the answer to "the thing running isn't the agent's logic anymore." the APEX spec is honest about this same boundary from its own side too - hardware attestation is explicitly out of scope for availability and network-layer attacks. a host can starve or terminate the enclave, it just can't forge what was emitted before that happened.

given that, a serious posture for server-hosted buzz agents probably wants both. Castle-Wall-shaped egress bounding as the default for the common case, enclave-held keys for whoever's running the kind of agent where a root-level host compromise is the threat that actually matters. if a fuller writeup happens here, i'll make sure it cites Castle Wall alongside NIP-OA's own gaps; different failure mode, same underlying question of what a signer can prove versus what it can only promise.

kennethkabogo avatar Jul 27 '26 06:07 kennethkabogo

I think the existing device-pairing implementation makes the custody distinction here especially important.

Buzz already avoids manual nsec copy/paste between its own devices through NIP-AB, but today's implemented payload is still the nsec. The secure pairing channel protects the transfer; after pairing, the same identity secret exists in another device keystore, with no per-device revocation. That solves the typing/transport problem, not the custody problem described in this issue.

NIP-46 is the right standard foundation for a real remote-signing option. The repo already reserves bunker and nostrconnect payload variants in the pairing protocol, although no producer or consumer exists yet. Those variants could make Buzz-to-Buzz setup smoother, while direct NIP-46 QR/deep-link flows remain important for third-party signer interoperability. NIP-AB should be an optional convenience layer, not a prerequisite for using an external signer.

I would avoid choosing one URI direction as the universal device flow. nostrconnect:// is convenient when desktop is the client and a phone scans as signer; in the reciprocal topology, where desktop signs for mobile, it can put the camera burden back on the desktop. The practical design likely needs QR, deep link, and copy/share options, with the scanning device chosen by topology.

For a v1, I would expect:

  • the client can represent an identity using a pubkey plus remote-signer connection, with no local nsec;
  • standard NIP-46 sign_event and NIP-44 encrypt/decrypt;
  • clear permission and signer identity confirmation during connection;
  • persistent connection metadata without persisting bearer secrets insecurely;
  • signer-side revocation/logout and client UI for lost or replaced devices;
  • explicit behavior when the signer is offline or declines an operation;
  • measured NIP-42 authentication latency against Buzz relay's five-second deadline;
  • an explicit statement that NIP-GS Git object signing is not supported by standard NIP-46 in v1.

There is also a product-positioning constraint. Buzz's sovereignty vision says that the user's key and portable identity remain theirs. A user-chosen remote signer—phone, hardware device, self-hosted service, or optional custodian—can fit that model. A privileged hosted identity provider would be in tension with it. Implementing the standard interface first, with any custodial service presented as one optional provider, preserves that choice. Keycast is a useful concrete compatibility target and optional provider, but it should not define the Buzz interface.

#6467 appears to be the active place for the shared signer abstraction. My preference would be to keep this issue focused on the human login/custody UX while ensuring both efforts use the same underlying signer boundary.

NotThatKindOfDrLiz avatar Aug 24 '26 15:08 NotThatKindOfDrLiz

@NotThatKindOfDrLiz the transport/signer split you're proposing looks right to me, and I think it's firmer than a design preference — there's a mechanical reason for it.

The 5s NIP-42 window is a bootstrap circularity, not a latency budget.

For a host with no local key the chain closes on itself: signing the kind:22242 auth event needs a NIP-46 round trip → which needs publishing kind:24133 to the transport relay → and if that transport relay is the Buzz relay, publishing needs to already be authenticated.

The auth gate has no kind exemption; it's the first thing both handlers do, before any dispatch:

  • crates/buzz-relay/src/handlers/event.rs:634-654 → _ => "auth-required: not authenticated"
  • crates/buzz-relay/src/handlers/req.rs:83-92 → "auth-required: authenticate before subscribing"
  • crates/buzz-relay/src/connection.rs:29 and :255-267 → AUTH_TIMEOUT = 5s, then cancel() closes the connection (buzz_ws_auth_timeouts_total)

So it deadlocks rather than times out, and no latency measurement changes that. 24133 also appears nowhere in the tree, so there's no NIP-46 awareness on the relay side today. The consequence is that the NIP-46 transport has to be a relay reachable without the auth it's being used to obtain — which is your signer-vs-transport boundary, reached from the other direction.

There's already an in-tree precedent for that transport. buzz-pair-relay is an unauthenticated ephemeral sidecar relay — no auth-required/AuthState/NIP-42 anywhere in it — locked to a single kind (lib.rs:323 "kinds must be [24134]", lib.rs:450-451). Structurally that's what a 24133 channel needs, and it sits right next to the variants you found: PayloadType::Bunker/::Connect are reserved at crates/buzz-core/src/pairing/types.rs:67-69 and produced by nothing — the only other references are a label mapping in crates/buzz-pairing-cli/src/main.rs:316-317. Existing NIP-46 signers already do this — Keycast's docs put a public relay in the bunker URI's relay= (wss://relay.damus.io in its examples), which is what this constraint forces rather than a stylistic choice.

That may argue for pulling your slice 5 (the no-direct-relay gateway) earlier than last for the agent case specifically, since an agent host with no local key can't bootstrap without a transport. The human case in #2700 is less exposed in practice, because a bunker:// URI carries its own relay= transport (relay.nsec.app and friends) which isn't the community relay — but it's the same circularity the moment 24133 is routed over the community relay, which is exactly what a PayloadType::Bunker pairing flow would tempt someone into.

On slice 1 sizing, in case it helps the internal check: NostrSigner is already available at the pinned version, so no dependency bump. Cargo.toml:72 pins nostr = "0.44", and in 0.44.7 the trait is at src/signer.rs:92, impl NostrSigner for Keys at src/key/mod.rs:262, re-exported at src/lib.rs:69. SignerBackend at signer.rs:76 already carries the NostrConnect variant. And there's no async_trait — the methods return BoxedFuture<'a, T> = Pin<Box<dyn Future + Send + 'a>> (util/mod.rs:26), so the trait gets you out-of-tree signers without a proc-macro in the path.

Measured on main @ 040b203f: 0 references to NostrSigner, and 465 sign_with_keys call sites — buzz-test-client 162, buzz-relay 81, buzz-db 47, buzz-acp 45, buzz-core 36, buzz-cli 32, buzz-workflow 18, buzz-sdk 18. The relay's and buzz-db's are the relay signing its own events and never want a remote signer, so the agent path is ~96 sites. The cost there isn't the trait, it's that sign_with_keys is sync while sign_event is async: each migrated site gains an .await, so enclosing sync fns become async and that propagates to callers.

Happy to wait for the internal answer before touching anything in-tree.

bonpiedlaroute avatar Aug 24 '26 21:08 bonpiedlaroute