Skip to content
/ ecc-ts Public

Elliptic Curve Cryptography implementation of ECDH and ECDSA on curve secp256k1

License

Notifications You must be signed in to change notification settings

pmuens/ecc-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elliptic Curve Cryptography

A "from scratch" Elliptic Curve Cryptography implementation in TypeScript using the Deno JavaScript runtime.

This repository includes code for the Elliptic-Curve Diffie-Hellman (ECDH) key agreement protocol as well as the Elliptic-Curve Digital Signature Algorithm (ECDSA). Both are implemented on top of the secp256k1 curve that's also used in Bitcoin and Ethereum.

In addition to a "raw" ECDSA implementation there's also one that can be used to sign messages and transact on the Ethereum Blockchain. To do so easily, an Ethers v6 compliant Signer was implemented which wraps the ECDSA functionalities.

Note that the code you'll find here wasn't audited and is definitely not constant time. You should therefore use this codebase as an educational resource which was my intention when I wrote it.

The best way to understand the code is to dive into the *.test.ts or script files and see how different parts of the code interact.

All the resources I've studied to write this implementation can be found in the Useful Resources section.

Setup

  1. git clone <url>
  2. deno test
  3. deno task dev

Scripts

The following are scripts you can run to test the implementation.

Some scripts require you to get some test ETH on Sepolia. There are various faucets available online you can use to get access to testnet ETH.

# Generate a new private- and public key pair.
deno task keys

# Display information for an existing key pair.
PRIVATE_KEY=0x1234567890 deno task keys

# Get the account balance on the Sepolia test network.
PRIVATE_KEY=0x1234567890 deno task balance

# Sign a message.
PRIVATE_KEY=0x1234567890 deno task sign

# Send ETH to another address on the Sepolia test network.
PRIVATE_KEY=0x1234567890 deno task send

Useful Commands

deno init

deno info
deno doc [<path>]
deno repl
deno bench <path>
deno compile [-A] <path>

deno fmt [<path>]
deno lint [<path>]
deno test [<path>]

deno run <path>

deno task dev

Useful Resources