Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

secp256k1

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secp256k1 - npm Package Compare versions

Comparing version 3.2.5 to 3.3.0

5

index.js

@@ -5,4 +5,7 @@ 'use strict'

} catch (err) {
console.log('Secp256k1 bindings are not compiled. Pure JS implementation will be used.')
if (process.env.DEBUG) {
console.error('Secp256k1 bindings are not compiled. Pure JS implementation will be used.')
}
module.exports = require('./elliptic')
}

21

lib/der.js
'use strict'
var Buffer = require('safe-buffer').Buffer
var bip66 = require('bip66')
var EC_PRIVKEY_EXPORT_DER_COMPRESSED = new Buffer([
var EC_PRIVKEY_EXPORT_DER_COMPRESSED = Buffer.from([
// begin

@@ -26,3 +27,3 @@ 0x30, 0x81, 0xd3, 0x02, 0x01, 0x01, 0x04, 0x20,

var EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED = new Buffer([
var EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED = Buffer.from([
// begin

@@ -53,3 +54,3 @@ 0x30, 0x82, 0x01, 0x13, 0x02, 0x01, 0x01, 0x04, 0x20,

var ZERO_BUFFER_32 = new Buffer([
var ZERO_BUFFER_32 = Buffer.from([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

@@ -60,3 +61,3 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

exports.privateKeyExport = function (privateKey, publicKey, compressed) {
var result = new Buffer(compressed ? EC_PRIVKEY_EXPORT_DER_COMPRESSED : EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED)
var result = Buffer.from(compressed ? EC_PRIVKEY_EXPORT_DER_COMPRESSED : EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED)
privateKey.copy(result, compressed ? 8 : 9)

@@ -109,6 +110,6 @@ publicKey.copy(result, compressed ? 181 : 214)

exports.signatureExport = function (sigObj) {
var r = Buffer.concat([new Buffer([0]), sigObj.r])
var r = Buffer.concat([Buffer.from([0]), sigObj.r])
for (var lenR = 33, posR = 0; lenR > 1 && r[posR] === 0x00 && !(r[posR + 1] & 0x80); --lenR, ++posR);
var s = Buffer.concat([new Buffer([0]), sigObj.s])
var s = Buffer.concat([Buffer.from([0]), sigObj.s])
for (var lenS = 33, posS = 0; lenS > 1 && s[posS] === 0x00 && !(s[posS + 1] & 0x80); --lenS, ++posS);

@@ -120,4 +121,4 @@

exports.signatureImport = function (sig) {
var r = new Buffer(ZERO_BUFFER_32)
var s = new Buffer(ZERO_BUFFER_32)
var r = Buffer.from(ZERO_BUFFER_32)
var s = Buffer.from(ZERO_BUFFER_32)

@@ -141,4 +142,4 @@ try {

exports.signatureImportLax = function (sig) {
var r = new Buffer(ZERO_BUFFER_32)
var s = new Buffer(ZERO_BUFFER_32)
var r = Buffer.from(ZERO_BUFFER_32)
var s = Buffer.from(ZERO_BUFFER_32)

@@ -145,0 +146,0 @@ var length = sig.length

'use strict'
var Buffer = require('safe-buffer').Buffer
var createHash = require('create-hash')

@@ -71,3 +72,3 @@ var BN = require('bn.js')

return new Buffer(ec.keyFromPrivate(privateKey).getPublic(compressed, true))
return Buffer.from(ec.keyFromPrivate(privateKey).getPublic(compressed, true))
}

@@ -100,3 +101,3 @@

return new Buffer(ec.keyFromPrivate(privateKey).getPublic(compressed, true))
return Buffer.from(ec.keyFromPrivate(privateKey).getPublic(compressed, true))
}

@@ -108,3 +109,3 @@

return new Buffer(pair.getPublic(compressed, true))
return Buffer.from(pair.getPublic(compressed, true))
}

@@ -123,3 +124,3 @@

return new Buffer(ecparams.g.mul(tweak).add(pair.pub).encode(true, compressed))
return Buffer.from(ecparams.g.mul(tweak).add(pair.pub).encode(true, compressed))
}

@@ -134,3 +135,3 @@

return new Buffer(pair.pub.mul(tweak).encode(true, compressed))
return Buffer.from(pair.pub.mul(tweak).encode(true, compressed))
}

@@ -149,3 +150,3 @@

return new Buffer(point.encode(true, compressed))
return Buffer.from(point.encode(true, compressed))
}

@@ -158,3 +159,3 @@

var result = new Buffer(signature)
var result = Buffer.from(signature)
if (s.cmp(ec.nh) === 1) ecparams.n.sub(s).toArrayLike(Buffer, 'be', 32).copy(result, 32)

@@ -235,3 +236,3 @@

var point = ec.recoverPubKey(message, sigObj, recovery)
return new Buffer(point.encode(true, compressed))
return Buffer.from(point.encode(true, compressed))
} catch (err) {

@@ -254,3 +255,3 @@ throw new Error(messages.ECDSA_RECOVER_FAIL)

return new Buffer(pair.pub.mul(scalar).encode(true, compressed))
return Buffer.from(pair.pub.mul(scalar).encode(true, compressed))
}
'use strict'
var Buffer = require('safe-buffer').Buffer
var optimized = require('./optimized')

@@ -42,3 +43,3 @@

return new Buffer([
return Buffer.from([
(w[9] >>> 14) & 0xFF, (w[9] >>> 6) & 0xFF, (w[9] & 0x3F) << 2 | ((w[8] >>> 24) & 0x03), // 0, 1, 2

@@ -648,6 +649,6 @@ (w[8] >>> 16) & 0xFF, (w[8] >>> 8) & 0xFF, w[8] & 0xFF, // 3, 4, 5

BN.n = BN.fromBuffer(new Buffer('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 'hex'))
BN.n = BN.fromBuffer(Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 'hex'))
BN.nh = BN.n.clone().ishrn(1)
BN.nc = BN.fromBuffer(new Buffer('000000000000000000000000000000014551231950B75FC4402DA1732FC9BEBF', 'hex'))
BN.p = BN.fromBuffer(new Buffer('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex'))
BN.nc = BN.fromBuffer(Buffer.from('000000000000000000000000000000014551231950B75FC4402DA1732FC9BEBF', 'hex'))
BN.p = BN.fromBuffer(Buffer.from('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex'))
BN.psn = BN.p.sub(BN.n)

@@ -654,0 +655,0 @@ BN.tmp = new BN()

'use strict'
var Buffer = require('safe-buffer').Buffer
var BN = require('./bn')

@@ -60,7 +61,7 @@ var ECJPoint = require('./ecjpoint')

if (compressed) {
publicKey = new Buffer(33)
publicKey = Buffer.alloc(33)
publicKey[0] = y.isOdd() ? 0x03 : 0x02
x.toBuffer().copy(publicKey, 1)
} else {
publicKey = new Buffer(65)
publicKey = Buffer.alloc(65)
publicKey[0] = 0x04

@@ -67,0 +68,0 @@ x.toBuffer().copy(publicKey, 1)

'use strict'
var Buffer = require('safe-buffer').Buffer
var BN = require('./bn')

@@ -7,4 +8,4 @@ var ECPoint = require('./ecpoint')

function ECPointG () {
this.x = BN.fromBuffer(new Buffer('79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798', 'hex'))
this.y = BN.fromBuffer(new Buffer('483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8', 'hex'))
this.x = BN.fromBuffer(Buffer.from('79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798', 'hex'))
this.y = BN.fromBuffer(Buffer.from('483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8', 'hex'))
this.inf = false

@@ -11,0 +12,0 @@

'use strict'
var Buffer = require('safe-buffer').Buffer
var createHash = require('create-hash')

@@ -97,3 +98,3 @@ var HmacDRBG = require('drbg.js/hmac')

var result = new Buffer(signature)
var result = Buffer.from(signature)
if (s.isHigh()) BN.n.sub(s).toBuffer().copy(result, 32)

@@ -198,3 +199,3 @@

var kpPublicKey = Buffer.concat([new Buffer([0x02 + (recovery & 0x01)]), kpx.toBuffer()])
var kpPublicKey = Buffer.concat([Buffer.from([0x02 + (recovery & 0x01)]), kpx.toBuffer()])
var kp = ECPoint.fromPublicKey(kpPublicKey)

@@ -201,0 +202,0 @@ if (kp === null) break

{
"name": "secp256k1",
"version": "3.2.5",
"version": "3.3.0",
"description": "This module provides native bindings to ecdsa secp256k1 functions",

@@ -58,7 +58,8 @@ "keywords": [

"nan": "^2.2.1",
"prebuild-install": "^2.0.0"
"prebuild-install": "^2.0.0",
"safe-buffer": "^5.1.0"
},
"devDependencies": {
"bignum": "^0.12.5",
"browserify": "^13.0.0",
"browserify": "^14.4.0",
"karma": "^1.3.0",

@@ -72,5 +73,5 @@ "karma-browserify": "^5.0.4",

"node-gyp": "^3.3.1",
"nyc": "^10.0.0",
"nyc": "^11.0.2",
"prebuild": "^6.0.0",
"prebuild-ci": "^1.0.9",
"prebuild-ci": "^2.2.2",
"standard": "*",

@@ -81,3 +82,3 @@ "tape": "^4.5.1",

"engines": {
"node": ">=0.10"
"node": ">=4.0.0"
},

@@ -84,0 +85,0 @@ "gypfile": true,

# secp256k1-node
[![NPM Package](https://img.shields.io/npm/v/secp256k1.svg?style=flat-square)](https://www.npmjs.org/package/secp256k1)
[![Build Status](https://img.shields.io/travis/cryptocoinjs/secp256k1-node.svg?branch=master&style=flat-square)](https://travis-ci.org/cryptocoinjs/secp256k1-node)
[![AppVeyor](https://img.shields.io/appveyor/ci/fanatid/secp256k1-node.svg?branch=master&style=flat-square)](https://ci.appveyor.com/project/fanatid/secp256k1-node)
Version | Mac/Linux | Windows
------- | --------- | -------
[![NPM Package](https://img.shields.io/npm/v/secp256k1.svg?style=flat-square)](https://www.npmjs.org/package/secp256k1) | [![Build Status](https://img.shields.io/travis/cryptocoinjs/secp256k1-node.svg?branch=master&style=flat-square)](https://travis-ci.org/cryptocoinjs/secp256k1-node) | [![AppVeyor](https://img.shields.io/appveyor/ci/fanatid/secp256k1-node.svg?branch=master&style=flat-square)](https://ci.appveyor.com/project/fanatid/secp256k1-node)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
This module provides native bindings to ecdsa [secp256k1](https://github.com/bitcoin-core/secp256k1) functions.
This library is experimental, so use at your own risk. Works on node version 0.10 or greater and in the Browser via browserify.
This module provides native bindings to [bitcoin-core/secp256k1](https://github.com/bitcoin-core/secp256k1). In browser [elliptic](https://github.com/indutny/elliptic) will be used.
This library is experimental, so use at your own risk. Works on node version 4.0.0 or greater.
## Installation
If you have [gmp](https://gmplib.org/) installed [secp256k1](https://github.com/bitcoin-core/secp256k1) will use it.
* arch `pacman -S gmp`
* ubuntu `sudo apt-get install libgmp-dev`
##### from npm

@@ -33,4 +30,6 @@

Required software:
The easies way to build package on windows is install [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools).
Or install next software:
* Git: https://git-scm.com/download/win

@@ -41,3 +40,3 @@ * nvm: https://github.com/coreybutler/nvm-windows

Additional commands:
And run commands:

@@ -49,3 +48,3 @@ ```

Useful resources:
Based on:

@@ -61,24 +60,25 @@ * https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245

```js
var crypto = require('crypto')
var secp256k1 = require('secp256k1')
// or require('secp256k1/js')
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
var msg = crypto.randomBytes(32)
const msg = randomBytes(32)
// generate privKey
var privKey
let privKey
do {
privKey = crypto.randomBytes(32)
privKey = randomBytes(32)
} while (!secp256k1.privateKeyVerify(privKey))
// get the public key in a compressed format
var pubKey = secp256k1.publicKeyCreate(privKey)
const pubKey = secp256k1.publicKeyCreate(privKey)
// sign the message
var sigObj = secp256k1.sign(msg, privKey)
const sigObj = secp256k1.sign(msg, privKey)
// verify the signature
console.log(secp256k1.verify(msg, sigObj.signature, pubKey))
// => true
```

@@ -88,43 +88,8 @@

## Elliptic vs "embedded"
## Second pure js implementation
secp256k1-node has pure JavaScript implementation secp256k1 based on [elliptic](http://github.com/indutny/elliptic), [bn.js](http://github.com/indutny/bn.js), [hash.js](http://github.com/indutny/hash.js).
The main purpose of this implementation is more [high performance](#performance), [smaller size](#code-size) and simple code audit.
Project has yet one secp256k1 implementation based on [elliptic](http://github.com/indutny/elliptic) and [bn.js](http://github.com/indutny/bn.js). The main purpose of this smaller size, high performance and easy code audit. This implementation is super experimental, use it at your own risk.
##### Code size:
| | browserifiable | + uglified | + gzipped |
|:------:|:--------------:|:----------:|:---------:|
|elliptic|303555 |211777 |62124 |
|embedded|241829 |152989 |35908 |
|diff |25% |38% |73% |
##### Performance:
```
$ node benchmark/benchmark.js
Set seed: 5120779d9d961dc818363811b3cf44ace2323ccf5e265749206d37442a0deac5
100% (1000/1000), 2.8s elapsed, eta 0.0s
Create 1000 fixtures
++++++++++++++++++++++++++++++++++++++++++++++++++
Benchmarking: publicKeyCreate
--------------------------------------------------
bindings x 13,945 ops/sec ±0.76% (101 runs sampled)
secp256k1js x 967 ops/sec ±0.41% (100 runs sampled)
elliptic x 838 ops/sec ±0.66% (99 runs sampled)
==================================================
Benchmarking: sign
--------------------------------------------------
bindings x 8,219 ops/sec ±0.13% (102 runs sampled)
secp256k1js x 773 ops/sec ±0.47% (98 runs sampled)
elliptic x 615 ops/sec ±0.43% (97 runs sampled)
==================================================
Benchmarking: verify
--------------------------------------------------
bindings x 5,350 ops/sec ±0.11% (103 runs sampled)
secp256k1js x 208 ops/sec ±0.19% (91 runs sampled)
elliptic x 131 ops/sec ±2.05% (87 runs sampled)
==================================================
```
## LICENSE
This library is free and open-source software released under the MIT license.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc