Visual demonstration of Elliptic-curve cryptography in the command prompt.
Clone and install this Github repository
git clone https://github.com/johannes67890/EC-crypto.git
npm install
// Run command prompt application
> npm run cdm
// Run test of the applications functions
> npm run test// Create and initialize EC & signature context
const ec = new EC(secp256k1);
const signature = new Signature(secp256k1);
// Generate key pair
const keySet = new KeySet(secp256k1);
const {privateKey, publicKey } = keySet;
// Message to sign
const message = "Hello World!";
// Sign: Hashes and signs thhe decopmressed private key to the signature function.
const signatureValue = signature.signMsg(message, ec.decompressPoint(privateKey));
// Verify: Decopmress public key to verify match of signature function.
const verify = signature.verifyMsg(message, signatureValue, ec.decompressPoint(publicKey));
console.log("Verify: ", verify); // Return true or false// Holds x & y cordinats of the corresponding Point
interface Point {
x: BN;
y: BN;
}
interface signature {
// Holds r & s cordinats of the corresponding signature
r: BN;
s: BN;
}isOnCurve(Point)- Check ifPointis on curve.isInfinity(Point)- Check ifPointis InfinitypointToBN(Point)- Converts typePointto aBNinstancedecompressPoint(BN)- ConvertsBNto typePointconcatPoint(x: BN, y: BN)- Concatenates twoBNinstances into typePointhashMsgSHA256(string)- Hashesstringwith SHA256
-
addMod(x: BN, y: BN)- addMod computesz = (x + y) % p -
subMod(x: BN, y: BN)- subMod computesz = (x - y) % p -
mulMod(x: BN, y: BN)- mulMod computesz = (x * y) % p -
expMod(x: BN, y: BN)- expMod computesz = (x^^y) % pWhere
pis the prime order of the Elliptic curve
-
pointAdd(Point1, Point2)- Computes the sum of two points on the elliptic curve. -
pointDouble(Point)- If two points are coincident, Computes point doubling of the point on the elliptic curve. -
pointMul(k: BN, Point)- multiplies apointby the scalark
signMsg(msg, privateKey, k?)- Returns asignaturefrom a messagemsg, with the correspondingPrivateKey(Precomputedkis optional)verifyMsg(msg, signature, publicKey)- ReturnsTrueorFalseif the signature is valied corresponding to thepublicKeyandmsg
generatePrivateKey()- Generates aBNinstance of a random 32 byte size private Key.generatePublicKey(privateKey: BN)- Generates aBNinstance of a public key fromprivateKey
NOTE: Generate a key pair by initializing new KeySet(curve)
// Generate key pair
const keySet = new KeySet(secp256k1);
const { privateKey, publicKey } = keySet;Secp256k1
More under development