用途:该技能面向 Amethyst 客户端中所有产生已签名 Nostr 事件的操作,帮助开发者在本地密钥、远程 NIP-46 bunker、安卓外部 NIP-55 签名器之间做出选择与适配,并排查“签名已批准但无反应”或签名超时等问题。
主要能力:三类签名器都实现同一抽象契约 NostrSigner(位于 quartz/src/commonMain/.../nip01Core/signers/NostrSigner.kt),包含 sign、nip04Encrypt、nip04Decrypt、nip44Encrypt、nip44Decrypt、decryptZapEvent 等方法。本地实现 NostrSignerInternal 将私钥放在内存中,速度最快;远程实现 NostrSignerRemote 通过 Nostr 私信与 bunker 服务通信,使用 BunkerRequest*/BunkerResponse* 事件类型;安卓外部实现 NostrSignerExternal 通过 Intent 和 content provider 委托给同设备其他应用。另有 NostrSignerSync 作为阻塞包装器供脚本、迁移或测试使用。
使用方式:功能代码通常无需直接接触签名器,应通过 Account 的变更方法(如 account.sendReaction、account.follow)完成签名、发布与本地状态更新;仅当 Account 无对应辅助方法时才直接调用 signer.sign(template) { signed -> ... }。注册入口包括:已有私钥走 NostrSignerInternal;bunker:// URL 调用 NostrSignerRemote.fromBunkerUri 后执行 suspend connect() 完成 NIP-46 握手;已安装外部签名器应用走 ExternalSignerLogin.launch。
限制与注意事项:外部签名器可能被关闭而无结果,远程签名器可能超时,回调可能永不触发,需处理 SignerExceptions 或依赖 Account 层包装。nip04Encrypt 属于 NIP-04 旧路径,新私信应使用 NIP-17 礼物包装走 nip44Encrypt。不要自行缓存签名器输出,避免重复发布。远程签名器断线需要显式重连交互。外部签名器启动需要 Activity 上下文,无法在后台服务中触发。NostrSignerSync 少见,生产代码应使用异步 API。