Skip to content

Commit 1b04fa8

Browse files
committed
readme
1 parent 42143ba commit 1b04fa8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ ECDSA signatures use deterministic k, conforming to [RFC 6979](https://www.rfc-e
135135
EdDSA conforms to [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032).
136136
Schnorr (secp256k1-only) conforms to [BIP 340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
137137

138+
Messages are always hashed first.
139+
138140
#### ristretto255, decaf448
139141

140142
```ts
@@ -160,12 +162,10 @@ const sig = secp256k1.sign(msg, secretKey);
160162
const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
161163
```
162164

163-
ECDSA `sign()` allows providing `prehash: false`, which enables using custom hashes.
165+
Default sign() and verify() behavior (`prehash: true`) applies built-in hash function to message first.
166+
For secp256k1 that's sha256, for p521 that's sha512.
164167

165-
A ECDSA signature is not just "math over elliptic curve points".
166-
It's actually math + hashing: p256 is in fact p256 point + sha256 hash.
167-
By default, we hash messages. To use custom hash methods,
168-
make sure to disable prehashing.
168+
Providing `prehash: false` allows user to specify their own hash function (e.g. use secp256k1 + keccak256).
169169

170170
> [!NOTE]
171171
> Previously, in noble-curves v1, `prehash: false` was the default.
@@ -188,8 +188,12 @@ const sigNoRec = secp256k1.sign(msg, secretKey, { format: 'compact' });
188188
const sigInstance = secp256k1.Signature.fromBytes(sigRec, 'recovered');
189189
```
190190

191+
Public key recovery - only supported with ECDSA.
192+
191193
> [!NOTE]
192-
> Only ECDSA supports public key recovery.
194+
> Key recovery is a simple math operation.
195+
> There are no guarantees the signing was actually done.
196+
> It's always possible to forge signatures which would recover into specific public key.
193197
194198
#### Hedged ECDSA with noise
195199

0 commit comments

Comments
 (0)