360 Secure SkillHub
360 安全技能中心

nostr-auth

该技能从本地主密钥派生 per-service secp256k1 密钥,签署 kind-22242 Nostr 登录挑战事件,可选 POST 到服务回调;提供 pubkey、sign、dry-run 操作,并说明密钥文件权限、回调检查与失败处理。脚本仅用 Node.js 内置模块,要求 Node.js 20.19+。

dyegolara
dyegolara
热度 7.64
最近更新 2026-09-03 07:23:50
分类:安全依赖:代码执行 / 读写文件 / 第三方 API应用场景:API 集成 / 自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add nostr-auth
Metadata
name
nostr-auth
description
Authenticate to Nostr sign-in challenges (NIP-07 style) without a wallet or browser extension. Signs kind-22242 AUTH challenge events with a secp256k1 (BIP-340) key derived from a local master secret and optionally submits them to the service callback. Use when a site or API asks for a signed Nostr event to prove key ownership. More methods coming: NIP-98 HTTP Auth, NIP-42 relay AUTH, NIP-05.
version
1.0.0
homepage
https://github.com/dyegolara/nostr-auth-agents
metadata
{"openclaw":{"requires":{"bins":["node"]},"envVars":[{"name":"NOSTR_AUTH_KEYFILE","required":false,"description":"Optional path for the persistent 32-byte master secret."}]}}

Nostr sign-in (NIP-07)

Use this skill for authentication only — signing sign-in events that prove ownership of a Nostr identity. It never publishes notes, connects to relays beyond the configured callback, or requires a wallet or browser extension.

Inputs

  • A sign-in challenge from a "Sign in with Nostr" page or API — either an event template (kind, tags, content) or a challenge string.
  • Optional --domain for the service host (used for deterministic key derivation), --callback URL to submit the signed event to.
  • Optional --dry-run when the signed event must be inspected before submission.

Do not invent or alter challenges. Ask for a fresh challenge when the service reports it was already used.

Run

The bundled helper uses only Node.js built-ins and lives at:

<skill_dir>/scripts/nostr_auth.js

Inspect the identity and signature without authenticating:

node <skill_dir>/scripts/nostr_auth.js pubkey --domain example.com
node <skill_dir>/scripts/nostr_auth.js --challenge "<hex>" --relay "wss://..." --dry-run --json

After confirming the service and callback are expected, submit:

node <skill_dir>/scripts/nostr_auth.js --challenge "<hex>" --relay "wss://..." --callback "https://example.com/verify" --json

Or sign a full event template:

node <skill_dir>/scripts/nostr_auth.js sign '{"kind":22242,"tags":[["challenge","<hex>"]],"content":""}' --domain example.com --callback https://example.com/verify --json

The helper requires Node.js 20.19 or newer. The only network request is the final callback POST.

Protocol

  1. Derive a per-service secp256k1 private key: HMAC-SHA256(master, domain), from the persisted master secret (~/.config/nostr-auth/master.key, mode 0600).
  2. Build the event (kind 22242 for challenges by default), compute the NIP-01 id sha256(JSON.stringify([0, pubkey, created_at, kind, tags, content])).
  3. Sign the raw 32-byte id with BIP-340 schnorr; store the 64-byte signature as hex in event.sig.
  4. POST {"event": <signed>} to the callback. Interpret {"status":"OK"} as accepted; a fresh challenge is needed after {"status":"ERROR"}.

Identity and safety

  • Keep the master secret local (0600); expose the nsec to nobody.
  • Per-domain derivation keeps unrelated services from correlating identity.
  • Inspect the callback URL and signed event in --dry-run before submitting.
  • The npub derived here is an agent identity — it is not the same key as a user's browser extension unless the master secret comes from it.

Failure handling

  • Invalid hex / odd length — malformed key or challenge input.
  • Callback returned non-JSON or HTTP <n> — the service is down or the URL is wrong; verify --callback.
  • {"status":"ERROR"} — challenge may already be used; request a fresh one.

Self-test (offline, cost-free)

cd <skill_dir>
npm test

The local mock service validates the full sign → submit → verify roundtrip.