Implementing ECDSA from Scratch Without Libraries
Introduction In the previous article, we used the Web Crypto API's crypto.subtle to sign and verify with ECDSA. The API made it easy, but the internals remained a black box. In this article, we imp...

Source: DEV Community
Introduction In the previous article, we used the Web Crypto API's crypto.subtle to sign and verify with ECDSA. The API made it easy, but the internals remained a black box. In this article, we implement ECDSA signing and verification from scratch using only basic arithmetic and mod — no crypto libraries. We output intermediate values at every step to see exactly what's happening. The code and explanations in this article were developed through conversation with AI (Claude). The idea of using a small curve to keep all values to two digits, and the structure of showing intermediate values at each step, emerged from that discussion. Approach: Using a Small Curve Real ECDSA (P-256) uses 256-bit numbers, but the algorithm is independent of curve size. Here we use y² = x³ + x + 4 (mod 97), a small curve where all values fit in two digits. const p = 97n; // Finite field prime const a = 1n; // Curve parameter a const b = 4n; // Curve parameter b // Curve: y² = x³ + ax + b (mod p) The n suffix