Skip to content

Latest commit

 

History

History
186 lines (108 loc) · 6.78 KB

API.md

File metadata and controls

186 lines (108 loc) · 6.78 KB

API Reference (v3.x)


.privateKeyVerify(Buffer privateKey) -> Boolean

Verify an ECDSA privateKey.


.privateKeyExport(Buffer privateKey [, Boolean compressed = true]) -> Buffer

Export a privateKey in DER format.


.privateKeyImport(Buffer privateKey) -> Buffer

Import a privateKey in DER format.


.privateKeyNegate(Buffer privateKey) -> Buffer

Negate a privateKey by subtracting it from the order of the curve's base point.


.privateKeyModInverse(Buffer privateKey) -> Buffer

Compute the inverse of a privateKey (modulo the order of the curve's base point).


.privateKeyTweakAdd(Buffer privateKey, Buffer tweak) -> Buffer

Tweak a privateKey by adding tweak to it.


.privateKeyTweakMul(Buffer privateKey, Buffer tweak) -> Buffer

Tweak a privateKey by multiplying it by a tweak.


.publicKeyCreate(Buffer privateKey [, Boolean compressed = true]) -> Buffer

Compute the public key for a privateKey.


.publicKeyConvert(Buffer publicKey [, Boolean compressed = true]) -> Buffer

Convert a publicKey to compressed or uncompressed form.


.publicKeyVerify(Buffer publicKey) -> Boolean

Verify an ECDSA publicKey.


.publicKeyTweakAdd(Buffer publicKey, Buffer tweak [, Boolean compressed = true]) -> Buffer

Tweak a publicKey by adding tweak times the generator to it.


.publicKeyTweakMul(Buffer publicKey, Buffer tweak [, Boolean compressed = true]) -> Buffer

Tweak a publicKey by multiplying it by a tweak value.


.publicKeyCombine(Array publicKeys [, Boolean compressed = true]) -> Buffer

Add a given publicKeys together.


.signatureNormalize(Buffer signature) -> Buffer

Convert a signature to a normalized lower-S form.


.signatureExport(Buffer signature) -> Buffer

Serialize an ECDSA signature in DER format.


.signatureImport(Buffer signature) -> Buffer

Parse a DER ECDSA signature (follow by BIP66).


.signatureImportLax(Buffer signature) -> Buffer

Same as signatureImport but not follow by BIP66.


.sign(Buffer message, Buffer privateKey [, Object options]) -> {signature: Buffer, recovery: number}

Create an ECDSA signature. Always return low-S signature.

Inputs: 32-byte message m, 32-byte scalar key d, 32-byte scalar nonce k.

  • Compute point R = k * G. Reject nonce if R's x coordinate is zero.
  • Compute 32-byte scalar r, the serialization of R's x coordinate.
  • Compose 32-byte scalar s = k^-1 * (r * d + m). Reject nonce if s is zero.
  • The signature is (r, s).
Option: Function noncefn

Nonce generator. By default it is rfc6979.

Function signature:

noncefn(Buffer message, Buffer privateKey, ?Buffer algo, ?Buffer data, Number attempt) -> Buffer
Option: Buffer data

Additional data for noncefn (RFC 6979 3.6) (32 bytes). By default is null.


.verify(Buffer message, Buffer signature, Buffer publicKey) -> Boolean

Verify an ECDSA signature.

Note: return false for high signatures!

Inputs: 32-byte message m, public key point Q, signature: (32-byte r, scalar s).

  • Signature is invalid if r is zero.
  • Signature is invalid if s is zero.
  • Compute point R = (s^-1 * m * G + s^-1 * r * Q). Reject if R is infinity.
  • Signature is valid if R's x coordinate equals to r.

.recover(Buffer message, Buffer signature, Number recovery [, Boolean compressed = true]) -> Buffer

Recover an ECDSA public key from a signature.


.ecdh(Buffer publicKey, Buffer privateKey) -> Buffer

Compute an EC Diffie-Hellman secret and applied sha256 to compressed public key.


.ecdhUnsafe(Buffer publicKey, Buffer privateKey [, Boolean compressed = true]) -> Buffer

Compute an EC Diffie-Hellman secret and return public key as result.