Skip to content

New auth-proof package, simple authentication flow - #169

Merged
sirdeggen merged 4 commits into
bsv-blockchain:mainfrom
kjartan221:auth-proof-lib
May 29, 2026
Merged

New auth-proof package, simple authentication flow#169
sirdeggen merged 4 commits into
bsv-blockchain:mainfrom
kjartan221:auth-proof-lib

Conversation

@kjartan221

Copy link
Copy Markdown
Collaborator

Add @bsv/auth-proof — simple, secure wallet login via signed proofs

Adds a new package under packages/middleware/auth-proof.

What it does

A small, framework- and database-agnostic library for "prove you own this key" endpoints (login, etc.). The client wallet signs a
short-lived proof of identity-key ownership; the server verifies the signature, checks freshness, and consumes the proof once.

  • Signature-based — proves control of the wallet's identity key (asymmetric; the server can't forge it).
  • Expiry-bound — each proof is valid for a short window (default 2 min).
  • Single-use — replay protection via a store the consumer injects (consumeNonce), so the lib stays storage-agnostic.

API

const authClient = new AuthProofClient({ protocol: [2, 'myapp auth'] })
const proof = await authClient.createAuthProof(wallet, backendPublicKey, 'login')

const authServer = new AuthProofServer({ protocol: [2, 'myapp auth'] })
const result = await authServer.verifyAuthProof(serverWallet, proof, 'login', { consumeNonce })

AuthProofClient / AuthProofServer classes are thin wrappers over standalone functions (createAuthProof, verifyAuthProof, …), which are
also exported. Options (protocol, windowMs, clockSkewMs) must match on client and server.

Included

  • src/ — core functions + the two classes, fully typed.
  • Jest tests (13) covering serialization, freshness/expiry bounds, signature verification (including malformed-input handling), and
    single-use/replay.
  • README.md + docs/usage.md with client/server examples and both Mongo-TTL and in-memory consumeNonce patterns.

@kjartan221
kjartan221 requested a review from sirdeggen as a code owner May 29, 2026 17:03
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
5.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@sirdeggen
sirdeggen merged commit b1c086b into bsv-blockchain:main May 29, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants