Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Node.js binding for an Optimized C library for EC operations on curve secp256k1

License

NotificationsYou must be signed in to change notification settings

cryptocoinjs/secp256k1-node

Repository files navigation

This module provides native bindings tobitcoin-core/secp256k1. In browserelliptic will be used as fallback.

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

Installation

from npm

npm install secp256k1

from git
git clone git@github.com:cryptocoinjs/secp256k1-node.gitcd secp256k1-nodegit submodule update --initnpm install
Windows

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

Or install the following software:

And run commands:

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

Based on:

Usage

Private Key generation, Public Key creation, signature creation, signature verification
const{ randomBytes}=require('crypto')constsecp256k1=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)`constmsg=randomBytes(32)// generate privKeyletprivKeydo{privKey=randomBytes(32)}while(!secp256k1.privateKeyVerify(privKey))// get the public key in a compressed formatconstpubKey=secp256k1.publicKeyCreate(privKey)// sign the messageconstsigObj=secp256k1.ecdsaSign(msg,privKey)// verify the signatureconsole.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')constsecp256k1=require('./')// generate privKeyfunctiongetPrivateKey(){while(true){constprivKey=randomBytes(32)if(secp256k1.privateKeyVerify(privKey))returnprivKey}}// generate private and public keysconstprivKey=getPrivateKey()constpubKey=secp256k1.publicKeyCreate(privKey)// compressed public key from X and Yfunctionhashfn(x,y){constpubKey=newUint8Array(33)pubKey[0]=(y[31]&1)===0 ?0x02 :0x03pubKey.set(x,1)returnpubKey}// get X point of ecdhconstecdhPointX=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.

About

Node.js binding for an Optimized C library for EC operations on curve secp256k1

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors21


[8]ページ先頭

©2009-2025 Movatter.jp