From b0af0a8977850cfc6721fb7bf09ce4ee8eba2132 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 4 Aug 2023 22:31:41 +0000 Subject: [PATCH] readme --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ffffde1..353a154 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ import { secp256k1 } from '@noble/curves/secp256k1'; // ESM and Common.js // import { secp256k1 } from 'npm:@noble/curves@1.2.0/secp256k1'; // Deno const priv = secp256k1.utils.randomPrivateKey(); const pub = secp256k1.getPublicKey(priv); -const msg = new Uint8Array(32).fill(1); -const sig = secp256k1.sign(msg, priv); +const msg = new Uint8Array(32).fill(1); // message hash (not message) in ecdsa +const sig = secp256k1.sign(msg, priv); // `{prehash: true}` option is available const isValid = secp256k1.verify(sig, msg, pub) === true; // hex strings are also supported besides Uint8Arrays: @@ -273,7 +273,7 @@ const secq256k1 = weierstrass({ randomBytes, }); -// Replace weierstrass with weierstrassPoints if you don't need ECDSA, hash, hmac, randomBytes +// Replace weierstrass() with weierstrassPoints() if you don't need ECDSA, hash, hmac, randomBytes ``` Short Weierstrass curve's formula is `y² = x³ + ax + b`. `weierstrass` @@ -294,6 +294,10 @@ type CHash = { }; ``` +**Message hash** is expected instead of message itself: + - `.sign(msgHash, privKey)` is default behavior, you need to do `msgHash = hash(msg)` before + - `.sign(msg, privKey, {prehash: true})` if you want the library to handle hashing for you + **Weierstrass points:** 1. Exported as `ProjectivePoint` @@ -389,6 +393,7 @@ More examples: const priv = secq256k1.utils.randomPrivateKey(); secq256k1.getPublicKey(priv); // Convert private key to public. const sig = secq256k1.sign(msg, priv); // Sign msg with private key. +const sig2 = secq256k1.sign(msg, priv, {prehash: true}); // hash(msg) secq256k1.verify(sig, msg, priv); // Verify if sig is correct. const Point = secq256k1.ProjectivePoint;