tiny-secp256k1

Build Status NPM js-standard-style

This library is under development, and, like the secp256k1 C library it depends on, this is a research effort to determine an optimal API for end-users of the bitcoinjs ecosystem.

Installation

npm

npm install tiny-secp256k1

yarn

yarn add tiny-secp256k1

If you are having problems, please read the guide at secp256k1-node, as the build instructions should be exactly the same (and this module is a direct derivation).

Documentation

isPoint (A)

isPoint :: Buffer -> Bool

Returns false if

isPointCompressed (A)

isPointCompressed :: Buffer -> Bool

Returns false if the signature is not compressed.

isPrivate (d)

isPrivate :: Buffer -> Bool

Returns false if

pointAdd (A, B[, compressed])

pointAdd :: Buffer -> Buffer [-> Bool] -> Maybe Buffer

Returns null if result is at infinity.

Throws:

pointAddScalar (A, tweak[, compressed])

pointAddScalar :: Buffer -> Buffer [-> Bool] -> Maybe Buffer

Returns null if result is at infinity.

Throws:

pointCompress (A, compressed)

pointCompress :: Buffer -> Bool -> Buffer
Throws:

pointFromScalar (d[, compressed])

pointFromScalar :: Buffer [-> Bool] -> Maybe Buffer

Returns null if result is at infinity.

Throws:

pointMultiply (A, tweak[, compressed])

pointMultiply :: Buffer -> Buffer [-> Bool] -> Maybe Buffer

Returns null if result is at infinity.

Throws:

privateAdd (d, tweak)

privateAdd :: Buffer -> Buffer -> Maybe Buffer

Returns null if result is equal to 0.

Throws:

privateSub (d, tweak)

privateSub :: Buffer -> Buffer -> Maybe Buffer

Returns null if result is equal to 0.

Throws:

sign (h, d)

sign :: Buffer -> Buffer -> Buffer

Returns normalized signatures, each of (r, s) values are guaranteed to less than order / 2. Uses RFC6979.

Throws:

signWithEntropy (h, d, e)

sign :: Buffer -> Buffer -> Buffer -> Buffer

Returns normalized signatures, each of (r, s) values are guaranteed to less than order / 2. Uses RFC6979. Adds e as Added Entropy to the deterministic k generation.

Throws:

verify (h, Q, signature[, strict = false])

verify :: Buffer -> Buffer -> Buffer -> Bool

Returns false if any of (r, s) values are equal to 0, or if the signature is rejected.

If strict is true, valid signatures with any of (r, s) values greater than order / 2 are rejected.

Throws:

Credit

This is a partially derived work of https://github.com/cryptocoinjs/secp256k1-node, specifically this commit.

This library uses the native library secp256k1 by the bitcoin-core developers, including derivatives of its tests and test vectors.

LICENSE MIT