Readonly
addTweak a privateKey by adding tweakValue
to it.
Returns an error message if the private key is invalid or if the addition fails.
a valid secp256k1 private key
256 bit value to tweak by (BE)
Readonly
addTweak a publicKey
by adding tweakValue
times the generator to it.
Returns an error message if the provided public key could not be parsed or is not valid, or if the addition failed.
The returned public key will be in compressed format.
a public key.
256 bit value to tweak by (BE)
Readonly
addTweak a publicKey
by adding tweakValue
times the generator to it.
Returns an error message if the provided public key could not be parsed or is not valid, or if the addition failed.
The returned public key will be in uncompressed format.
a public key.
256 bit value to tweak by (BE)
Readonly
compressCompress a valid ECDSA public key. Returns a public key in compressed format (33 bytes, header byte 0x02 or 0x03).
This function supports parsing compressed (33 bytes, header byte 0x02 or 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header byte 0x06 or 0x07) format public keys.
Returns an error message if the provided public key could not be parsed or is not valid.
Readonly
deriveDerive a compressed public key from a valid secp256k1 private key.
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1, 32-byte private key
Readonly
deriveDerive an uncompressed public key from a valid secp256k1 private key.
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1, 32-byte private key
Readonly
malleateMalleate a compact-encoded ECDSA signature.
This is done by negating the S value modulo the order of the curve, "flipping" the sign of the random point R that is not included in the signature.
Returns an error message if compact-signature parsing fails.
a compact-encoded ECDSA signature to malleate, max 72 bytes
Readonly
malleateMalleate a DER-encoded ECDSA signature.
This is done by negating the S value modulo the order of the curve, "flipping" the sign of the random point R that is not included in the signature.
Returns an error message if DER-signature parsing fails.
a DER-encoded ECDSA signature to malleate, max 72 bytes
Readonly
mulTweak a privateKey by multiplying it by a tweakValue
.
Returns an error message if the private key is invalid or if the multiplication fails.
a valid secp256k1 private key
256 bit value to tweak by (BE)
Readonly
mulTweak a publicKey
by multiplying tweakValue
to it.
Returns an error message if the provided public key could not be parsed or is not valid, or if the multiplication failed.
The returned public key will be in compressed format.
a public key.
256 bit value to tweak by (BE)
Readonly
mulTweak a publicKey
by multiplying tweakValue
to it.
Returns an error message if the provided public key could not be parsed or is not valid, or if the multiplication failed.
The returned public key will be in uncompressed format.
a public key.
256 bit value to tweak by (BE)
Readonly
normalizeNormalize a compact-encoded ECDSA signature to lower-S form.
Returns an error message if compact-signature parsing fails.
a compact-encoded ECDSA signature to normalize to lower-S form, max 72 bytes
Readonly
normalizeNormalize a DER-encoded ECDSA signature to lower-S form.
Returns an error message if DER-signature parsing fails.
a DER-encoded ECDSA signature to normalize to lower-S form, max 72 bytes
Readonly
recoverCompute a compressed public key from a valid signature, recovery number,
and the messageHash
used to generate them.
Returns an error message if the provided arguments are mismatched.
an ECDSA signature in compact format
the hash used to generate the signature and recovery number
Readonly
recoverCompute an uncompressed public key from a valid signature, recovery
number, and the messageHash
used to generate them.
Returns an error message if the provided arguments are mismatched.
an ECDSA signature in compact format
the hash used to generate the signature and recovery number
Readonly
signCreate an ECDSA signature in compact format. The created signature is always in lower-S form and follows RFC 6979.
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1 private key
the 32-byte message hash to be signed
Readonly
signCreate an ECDSA signature in DER format. The created signature is always in lower-S form and follows RFC 6979.
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1, 32-byte private key
the 32-byte message hash to be signed
Readonly
signCreate an ECDSA signature in compact format. The created signature is always in lower-S form and follows RFC 6979.
Also returns a recovery number for use in the recoverPublicKey*
functions
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1, 32-byte private key
the 32-byte message hash to be signed
Readonly
signCreate a Secp256k1 EC-Schnorr-SHA256 signature (Bitcoin Cash construction).
Signatures are 64-bytes, non-malleable, and support both batch validation
and multiparty signing. Nonces are generated using RFC6979, where the
Section 3.6, 16-byte ASCII "additional data" is set to Schnorr+SHA256
.
This avoids leaking a private key by inadvertently creating both an ECDSA
signature and a Schnorr signature using the same nonce.
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1, 32-byte private key
the 32-byte message hash to be signed
Readonly
signatureConvert a compact-encoded ECDSA signature to DER encoding.
Returns an error message if parsing of compact-encoded signature fails.
a compact-encoded ECDSA signature to convert
Readonly
signatureDERToConvert a DER-encoded ECDSA signature to compact encoding.
Returns an error message if parsing of DER-encoded signature fails.
a DER-encoded ECDSA signature to convert
Readonly
uncompressUncompress a valid ECDSA public key. Returns a public key in uncompressed format (65 bytes, header byte 0x04).
This function supports parsing compressed (33 bytes, header byte 0x02 or 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header byte 0x06 or 0x07) format public keys.
Returns an error message if the provided public key could not be parsed or is not valid.
a public key to uncompress
Readonly
validateVerify that a private key is valid for secp256k1. Note, this library requires all private keys to be provided as 32-byte Uint8Arrays (an array length of 32).
Nearly every 256-bit number is a valid secp256k1 private key. Specifically,
any 256-bit number greater than or equal to 0x01
and less than
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140
is a valid private key. This range is part of the definition of the
secp256k1 elliptic curve parameters.
This method returns true if the private key is valid or false if it isn't.
a 32-byte private key to validate
Readonly
validateVerify that a public key is valid for secp256k1.
This method returns true if the public key is valid or false if it isn't.
a public key to validate
Readonly
verifyNormalize a signature to lower-S form, then verifySignatureCompactLowS
.
a compact-encoded ECDSA signature to verify, max 72 bytes
a public key, in either compressed (33-byte) or uncompressed (65-byte) format
the 32-byte message hash signed by the signature
Readonly
verifyVerify a compact-encoded ECDSA signature
using the provided publicKey
and messageHash
. This method also returns false if the signature is not
in normalized lower-S form.
a compact-encoded ECDSA signature to verify, max 72 bytes
a public key, in either compressed (33-byte) or uncompressed (65-byte) format
the 32-byte message hash signed by the signature
Readonly
verifyNormalize a signature to lower-S form, then verifySignatureDERLowS
.
a DER-encoded ECDSA signature to verify, max 72 bytes
a public key, in either compressed (33-byte) or uncompressed (65-byte) format
the 32-byte message hash signed by the signature
Readonly
verifyVerify a DER-encoded ECDSA signature
using the provided publicKey
and
messageHash
. This method also returns false if the signature is not in
normalized lower-S form.
a DER-encoded ECDSA signature to verify, max 72 bytes
a public key, in either compressed (33-byte) or uncompressed (65-byte) format
the 32-byte message hash signed by the signature
Readonly
verifyVerify a Secp256k1 EC-Schnorr-SHA256 signature (Bitcoin Cash construction).
a 64-byte schnorr signature to verify
a public key, in either compressed (33-byte) or uncompressed (65-byte) format
the 32-byte message hash signed by the signature
Generated using TypeDoc
An object that exposes a set of purely-functional Secp256k1 methods.
Example