5.0.0 • Published 1 year ago

secp256k1 v5.0.0

Weekly downloads
246,245
License
MIT
Repository
github
Last release
1 year ago

secp256k1-node

This module provides native bindings to bitcoin-core/secp256k1. In browser elliptic will be used as fallback.

Works on node version 14.0.0 or greater, because use N-API.

Installation

from npm

npm install secp256k1

from git
git clone git@github.com:cryptocoinjs/secp256k1-node.git
cd secp256k1-node
git submodule update --init
npm install
Windows

The easiest way to build the package on windows is to install windows-build-tools.

Or install the following software:

And run commands:

npm config set msvs_version 2015 --global
npm install npm@next -g

Based on:

Usage

Private Key generation, Public Key creation, signature creation, signature verification
const { randomBytes } = require('crypto')
const secp256k1 = require('secp256k1')
// or require('secp256k1/elliptic')
//   if you want to use pure js implementation in node

// generate message to sign
// message should have 32-byte length, if you have some other length you can hash message
// for example `msg = sha256(rawMessage)`
const msg = randomBytes(32)

// generate privKey
let privKey
do {
  privKey = randomBytes(32)
} while (!secp256k1.privateKeyVerify(privKey))

// get the public key in a compressed format
const pubKey = secp256k1.publicKeyCreate(privKey)

// sign the message
const sigObj = secp256k1.ecdsaSign(msg, privKey)

// verify the signature
console.log(secp256k1.ecdsaVerify(sigObj.signature, msg, pubKey))
// => true

* .verify return false for high signatures

Get X point of ECDH
const { randomBytes } = require('crypto')
// const secp256k1 = require('./elliptic')
const secp256k1 = require('./')

// generate privKey
function getPrivateKey () {
  while (true) {
    const privKey = randomBytes(32)
    if (secp256k1.privateKeyVerify(privKey)) return privKey
  }
}

// generate private and public keys
const privKey = getPrivateKey()
const pubKey = secp256k1.publicKeyCreate(privKey)

// compressed public key from X and Y
function hashfn (x, y) {
  const pubKey = new Uint8Array(33)
  pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03
  pubKey.set(x, 1)
  return pubKey
}

// get X point of ecdh
const ecdhPointX = secp256k1.ecdh(pubKey, privKey, { hashfn }, Buffer.alloc(33))
console.log(ecdhPointX.toString('hex'))

LICENSE

This library is free and open-source software released under the MIT license.

@blits-labs/filecoin-signing-tools@alebusse/account-lib@thorswap-lib/xpub-scan@tyz-wallet/tyz-wallet-core-client@tyz-wallet/tyz-wallet-core-servicealebusse@debuggor/solana-web3.jsdapid-identity-ethereum@hoprnet/hopr-core@ledgerhq/live-common@bitrabbit/nuls-js@bdcash/corebhp-jsbarjsdhivescrypta-corebcschainjs-walletcsachdkey-nativeweb3daggerhezhouyuanrenchaintestsigtestkratosjstestkuchainjs@bhpnet/bhpnet-js-sdkbhpnetbhpnet-jsbhpnetwork-jssbercoinjs-wallettransact-sdk-javascripticon-signature-utilhtdf_web3_ordinaryweb3_htdfsecux-connectstorj-bridgestorjd@deadcanaries/diglet@deadcanaries/kadence@deadcanaries/orc@orcproject/orcbitcore-wallet-service-sprcbitsong-js-keysbitsong-js-sdkbitsong-js-utilnoah-js-sdkjsstcjsgoathighjs@dzhanavapp/minter-js-sdk@safecoins/web3dec.js.testtrezor-utxo-libsnowgemjs@billyjacoby/injective-derivative-orders@solcial/clientqtum-qnekt@owlmeans/regov-ssi-commoncse30js@liteflow/api@rogerfelipe/digibyte-toolbox-jsdb3jsyongguiob-tn-1tp-new-test1tp-new-test2fork-tw@infinitebrahmanuniverse/nolb-sec@zondax/izari-filecoin-toolsarbundles-esmcosmos-crypto-libvischainviscoin@everything-registry/sub-chunk-2726nftls@uniqys/signatureypc-js-sdkypccryptoypccrypto.js@edendante/dhive@edendante/dsereyxecjs-messagexiaolong-dbchain-clientxud@earthwallet/sdk@earthwallet/keyring@ecla/cosmosjs@ecla/web3.js@ducatus/ducatus-wallet-service-rev@ducatus/ducatuscore-client@ducatus/ducatuscore-wallet-service@ducatus/bitcore-client@ducatus/bitcore-wallet-servicewallet-cosmos-genwallet-basewanchain-crosschainwanchain-crosschainbtcwanchain-dapp-connectwanchain-js-sdkwanchain-utilwanchainjs-util
5.0.0

1 year ago

4.0.3

2 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.8.0

4 years ago

3.7.1

5 years ago

3.7.0

5 years ago

3.6.2

5 years ago

3.6.1

5 years ago

3.6.0

5 years ago

3.5.2

6 years ago

3.5.0

6 years ago

3.4.0

6 years ago

3.3.1

6 years ago

3.3.0

7 years ago

3.2.5

7 years ago

3.2.2

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.10

8 years ago

2.0.9

8 years ago

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago