Socket
Socket
Sign inDemoInstall

secp256k1

Package Overview
Dependencies
Maintainers
2
Versions
59
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.0.0 to 3.0.1

6

bindings.js
'use strict'
module.exports = require('bindings')('secp256k1')
try {
module.exports = require('bindings')('secp256k1')
} catch (err) {
module.exports = require('./elliptic')
}

353

lib/js/bn/index.js

@@ -20,3 +20,3 @@ 'use strict'

var bn = new BN()
bn.words = [n]
bn.words = [n & 0x03ffffff]
bn.length = 1

@@ -56,2 +56,6 @@ return bn

var w = this.words
for (var i = this.length; i < 10; ++i) {
w[i] = 0
}
return new Buffer([

@@ -91,7 +95,7 @@ (w[9] >>> 14) & 0xFF, (w[9] >>> 6) & 0xFF, (w[9] & 0x3F) << 2 | ((w[8] >>> 24) & 0x03), // 0, 1, 2

BN.prototype.strip = function () {
while (this.length > 1 && this.words[this.length - 1] === 0) {
while (this.length > 1 && (this.words[this.length - 1] | 0) === 0) {
this.length--
}
return this._normSign()
return this
}

@@ -102,3 +106,3 @@

*/
BN.prototype._normSign = function () {
BN.prototype.normSign = function () {
// -0 = 0

@@ -113,6 +117,73 @@ if (this.length === 1 && this.words[0] === 0) {

/**
* @return {boolean}
*/
BN.prototype.isEven = function () {
return (this.words[0] & 1) === 0
}
/**
* @return {boolean}
*/
BN.prototype.isOdd = function () {
return (this.words[0] & 1) === 1
}
/**
* @return {boolean}
*/
BN.prototype.isZero = function () {
return this.length === 1 && this.words[0] === 0
}
/**
* @param {BN} num
* @return {number}
*/
BN.prototype.ucmp = function (num) {
if (this.length !== num.length) {
return this.length > num.length ? 1 : -1
}
for (var i = this.length - 1; i >= 0; --i) {
if (this.words[i] !== num.words[i]) {
return this.words[i] > num.words[i] ? 1 : -1
}
}
return 0
}
/**
* @return {boolean}
*/
BN.prototype.gtOne = function () {
return this.length > 1 || this.words[0] > 1
}
/**
* @return {boolean}
*/
BN.prototype.isOverflow = function () {
return this.ucmp(BN.n) >= 0
}
/**
* @return {boolean}
*/
BN.prototype.isHigh = function () {
return this.ucmp(BN.nh) === 1
}
/**
* @return {boolean}
*/
BN.prototype.bitLengthGT256 = function () {
return this.length > 10 || (this.length === 10 && this.words[9] > 0x003fffff)
}
/**
* @param {number} num
* @return {BN}
*/
BN.prototype._iuaddn = function (num) {
BN.prototype.iuaddn = function (num) {
this.words[0] += num

@@ -151,3 +222,3 @@

return this._normSign()
return this.normSign()
}

@@ -216,3 +287,3 @@

return this._normSign()
return this.normSign()
}

@@ -263,3 +334,3 @@

return this.strip()
return this.strip().normSign()
}

@@ -280,3 +351,3 @@

*/
BN._umulTo = function (num1, num2, out) {
BN.umulTo = function (num1, num2, out) {
out.length = num1.length + num2.length - 1

@@ -310,6 +381,6 @@

return out
return out.strip()
}
BN._umulTo10x10 = Math.imul ? optimized.umulTo10x10 : BN._umulTo
BN.umulTo10x10 = Math.imul ? optimized.umulTo10x10 : BN.umulTo

@@ -321,3 +392,9 @@ /**

*/
BN._umulnTo = function (num, k, out) {
BN.umulnTo = function (num, k, out) {
if (k === 0) {
out.words = [0]
out.length = 1
return out
}
for (var i = 0, carry = 0; i < num.length; ++i) {

@@ -347,15 +424,10 @@ var r = num.words[i] * k + carry

switch ((this.length << 5) + num.length) {
// 10 * 10
case 330:
return BN._umulTo10x10(this, num, out)
// 10 * 1
case 321:
return BN._umulnTo(this, num.words[0], out)
// 1 * 10
case 42:
return BN._umulnTo(num, this.words[0], out)
// ? * ?
default:
return BN._umulTo(this, num, out)
if (this.length === 10 && num.length === 10) {
return BN.umulTo10x10(this, num, out)
} else if (this.length === 1) {
return BN.umulnTo(num, this.words[0], out)
} else if (num.length === 1) {
return BN.umulnTo(this, num.words[0], out)
} else {
return BN.umulTo(this, num, out)
}

@@ -365,17 +437,33 @@ }

/**
* @param {number} n
* @param {BN} output
* @return {BN}
*/
BN.prototype.iushrn = function (n) {
var mask = (1 << n) - 1
var m = 26 - n
BN.prototype.isplit = function (output) {
output.length = Math.min(this.length, 9)
for (var i = 0; i < output.length; ++i) {
output.words[i] = this.words[i]
}
for (var i = this.length - 1, carry = 0; i >= 0; --i) {
if (this.length <= 9) {
this.words[0] = 0
this.length = 1
return this
}
// Shift by 9 limbs
var prev = this.words[9]
output.words[output.length++] = prev & 0x003fffff
for (i = 10; i < this.length; ++i) {
var word = this.words[i]
this.words[i] = (carry << m) | (word >>> n)
carry = word & mask
this.words[i - 10] = ((word & 0x003fffff) << 4) | (prev >>> 22)
prev = word
}
prev >>>= 22
this.words[i - 10] = prev
if (this.length > 1 && this.words[this.length - 1] === 0) {
this.length -= 1
if (prev === 0 && this.length > 10) {
this.length -= 10
} else {
this.length -= 9
}

@@ -401,7 +489,7 @@

BN.prototype.ureduce = function () {
var num = this.clone()._isplit(BN.tmp).umul(BN.nc).iadd(BN.tmp)
var num = this.clone().isplit(BN.tmp).umul(BN.nc).iadd(BN.tmp)
if (num.bitLengthGT256()) {
num = num._isplit(BN.tmp).umul(BN.nc).iadd(BN.tmp)
num = num.isplit(BN.tmp).umul(BN.nc).iadd(BN.tmp)
if (num.bitLengthGT256()) {
num = num._isplit(BN.tmp).umul(BN.nc).iadd(BN.tmp)
num = num.isplit(BN.tmp).umul(BN.nc).iadd(BN.tmp)
}

@@ -414,4 +502,25 @@ }

/**
* @param {number} n
* @return {BN}
*/
BN.prototype.ishrn = function (n) {
var mask = (1 << n) - 1
var m = 26 - n
for (var i = this.length - 1, carry = 0; i >= 0; --i) {
var word = this.words[i]
this.words[i] = (carry << m) | (word >>> n)
carry = word & mask
}
if (this.length > 1 && this.words[this.length - 1] === 0) {
this.length -= 1
}
return this
}
/**
* @return {BN}
*/
BN.prototype.uinvm = function () {

@@ -429,8 +538,6 @@ var x = this.clone()

var g = 0
while (x.isEven() && y.isEven()) {
x.iushrn(1)
y.iushrn(1)
++g
for (var k = 1, m = 1; (x.words[0] & m) === 0 && (y.words[0] & m) === 0 && k < 26; ++k, m <<= 1);
x.ishrn(k)
y.ishrn(k)
}

@@ -444,3 +551,3 @@

if (i > 0) {
x.iushrn(i)
x.ishrn(i)
while (i-- > 0) {

@@ -452,4 +559,4 @@ if (A.isOdd() || B.isOdd()) {

A.iushrn(1)
B.iushrn(1)
A.ishrn(1)
B.ishrn(1)
}

@@ -460,3 +567,3 @@ }

if (j > 0) {
y.iushrn(j)
y.ishrn(j)
while (j-- > 0) {

@@ -468,4 +575,4 @@ if (C.isOdd() || D.isOdd()) {

C.iushrn(1)
D.iushrn(1)
C.ishrn(1)
D.ishrn(1)
}

@@ -489,3 +596,3 @@ }

result.negative ^= 1
return result._normSign().iadd(BN.n)
return result.normSign().iadd(BN.n)
} else {

@@ -497,103 +604,5 @@ return C.ureduce()

/**
* @return {boolean}
*/
BN.prototype.isEven = function () {
return (this.words[0] & 1) === 0
}
/**
* @return {boolean}
*/
BN.prototype.isOdd = function () {
return (this.words[0] & 1) === 1
}
/**
* @return {boolean}
*/
BN.prototype.isZero = function () {
return this.length === 1 && this.words[0] === 0
}
/**
* @return {boolean}
*/
BN.prototype.gtOne = function () {
return this.length > 1 || this.words[0] > 1
}
/**
* @return {boolean}
*/
BN.prototype.isOverflow = function () {
return this.ucmp(BN.n) >= 0
}
/**
* @return {boolean}
*/
BN.prototype.isHigh = function () {
return this.ucmp(BN.nh) === 1
}
/**
* @param {BN} num
* @return {number}
*/
BN.prototype.ucmp = function (num) {
if (this.length !== num.length) {
return this.length > num.length ? 1 : -1
}
for (var i = this.length - 1; i >= 0; --i) {
if (this.words[i] !== num.words[i]) {
return this.words[i] > num.words[i] ? 1 : -1
}
}
return 0
}
/**
* @return {boolean}
*/
BN.prototype.bitLengthGT256 = function () {
return this.length > 10 || (this.length === 10 && this.words[9] > 0x003fffff)
}
/**
* @param {BN} output
* @return {BN}
*/
BN.prototype._isplit = function (output) {
output.length = Math.min(this.length, 9)
for (var i = 0; i < output.length; ++i) {
output.words[i] = this.words[i]
}
if (this.length <= 9) {
this.words[0] = 0
this.length = 1
return this
}
// Shift by 9 limbs
var prev = this.words[9]
output.words[output.length++] = prev & 0x003fffff
for (i = 10; i < this.length; ++i) {
var next = this.words[i]
this.words[i - 10] = ((next & 0x003fffff) << 4) | (prev >>> 22)
prev = next
}
this.words[i - 10] = prev >>> 22
this.length -= 9
return this
}
/**
* @return {BN}
*/
BN.prototype._imulK = function () {
BN.prototype.imulK = function () {
this.words[this.length] = 0

@@ -623,6 +632,6 @@ this.words[this.length + 1] = 0

*/
BN.prototype._redIReduce = function () {
this._isplit(BN.tmp)._imulK().iadd(BN.tmp)
BN.prototype.redIReduce = function () {
this.isplit(BN.tmp).imulK().iadd(BN.tmp)
if (this.bitLengthGT256()) {
this._isplit(BN.tmp)._imulK().iadd(BN.tmp)
this.isplit(BN.tmp).imulK().iadd(BN.tmp)
}

@@ -659,8 +668,3 @@

BN.prototype.redAdd = function (num) {
var res = this.add(num)
if (res.ucmp(BN.p) >= 0) {
res.isub(BN.p)
}
return res
return this.clone().redIAdd(num)
}

@@ -685,3 +689,3 @@

BN.prototype.redIAdd7 = function () {
this._iuaddn(7)
this.iuaddn(7)
if (this.ucmp(BN.p) >= 0) {

@@ -699,8 +703,3 @@ this.isub(BN.p)

BN.prototype.redSub = function (num) {
var res = this.sub(num)
if (res.negative !== 0) {
res.iadd(BN.p)
}
return res
return this.clone().redISub(num)
}

@@ -726,3 +725,3 @@

BN.prototype.redMul = function (num) {
return this.umul(num)._redIReduce()
return this.umul(num).redIReduce()
}

@@ -734,3 +733,3 @@

BN.prototype.redSqr = function () {
return this.umul(this)._redIReduce()
return this.umul(this).redIReduce()
}

@@ -783,3 +782,3 @@

if (i > 0) {
a.iushrn(i)
a.ishrn(i)
while (i-- > 0) {

@@ -790,3 +789,3 @@ if (x1.isOdd()) {

x1.iushrn(1)
x1.ishrn(1)
}

@@ -797,3 +796,3 @@ }

if (j > 0) {
b.iushrn(j)
b.ishrn(j)
while (j-- > 0) {

@@ -804,3 +803,3 @@ if (x2.isOdd()) {

x2.iushrn(1)
x2.ishrn(1)
}

@@ -831,5 +830,5 @@ }

res.negative = 0
return res._redIReduce().redNeg()
return res.redIReduce().redNeg()
} else {
return res._redIReduce()
return res.redIReduce()
}

@@ -851,3 +850,3 @@ }

while (!k.isZero()) {
for (var i = 0, d = 1; (k.words[0] & d) === 0 && i < 26; ++i, d <<= 1) {
for (var i = 0, m = 1; (k.words[0] & m) === 0 && i < 26; ++i, m <<= 1) {
naf.push(0)

@@ -857,3 +856,3 @@ }

if (i !== 0) {
k.iushrn(i)
k.ishrn(i)
} else {

@@ -863,3 +862,3 @@ var mod = k.words[0] & wsm1

naf.push(ws2 - mod)
k._iuaddn(mod - ws2).iushrn(1)
k.iuaddn(mod - ws2).ishrn(1)
} else {

@@ -873,3 +872,3 @@ naf.push(mod)

k.iushrn(w)
k.ishrn(w)
}

@@ -897,3 +896,3 @@ }

BN.n = BN.fromBuffer(new Buffer('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 'hex'))
BN.nh = BN.n.clone().iushrn(1)
BN.nh = BN.n.clone().ishrn(1)
BN.nc = BN.fromBuffer(new Buffer('000000000000000000000000000000014551231950B75FC4402DA1732FC9BEBF', 'hex'))

@@ -900,0 +899,0 @@ BN.p = BN.fromBuffer(new Buffer('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex'))

@@ -33,2 +33,6 @@ 'use strict'

ECJPoint.prototype.neg = function () {
if (this.inf) {
return this
}
return new ECJPoint(this.x, this.y.redNeg(), this.z)

@@ -128,21 +132,4 @@ }

/**
* @param {number} pow
* @return {ECJPoint}
*/
ECJPoint.prototype.dblp = function (pow) {
if (pow === 0 || this.inf) {
return this
}
var point = this
for (var i = 0; i < pow; i++) {
point = point.dbl()
}
return point
}
/**
* @return {ECJPoint}
*/
ECJPoint.prototype.dbl = function () {

@@ -218,2 +205,19 @@ if (this.inf) {

/**
* @param {number} pow
* @return {ECJPoint}
*/
ECJPoint.prototype.dblp = function (pow) {
if (pow === 0 || this.inf) {
return this
}
var point = this
for (var i = 0; i < pow; i++) {
point = point.dbl()
}
return point
}
Object.defineProperty(ECJPoint.prototype, 'inf', {

@@ -220,0 +224,0 @@ enumerable: true,

@@ -68,3 +68,3 @@ 'use strict'

// x*x*x + 7 = y*y
if (!x.redSqr().redMul(x).redIAdd7().redISub(y.redSqr()).isZero()) {
if (x.redSqr().redMul(x).redIAdd7().ucmp(y.redSqr()) !== 0) {
return null

@@ -71,0 +71,0 @@ }

'use strict'
var HmacDRBG = require('drbg.js/hmac')
var messages = require('../messages.json')
var nonce_function_rfc6979 = require('./rfc6979')
var BN = require('./bn')

@@ -231,6 +231,2 @@ var ECPoint = require('./ecpoint')

exports.sign = function (message, privateKey, noncefn, data) {
if (noncefn === null) {
noncefn = nonce_function_rfc6979
}
var d = BN.fromBuffer(privateKey)

@@ -241,2 +237,9 @@ if (d.isOverflow() || d.isZero()) {

if (noncefn === null) {
var drbg = new HmacDRBG('sha256', privateKey, message, data)
noncefn = function () {
return drbg.generate(32)
}
}
var bnMessage = BN.fromBuffer(message)

@@ -243,0 +246,0 @@ for (var count = 0; ; ++count) {

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

@@ -31,5 +31,2 @@ "keywords": [

"js.js",
"package.json",
"LICENSE",
"README.md",
"utils/has_lib.sh"

@@ -43,11 +40,9 @@ ],

"scripts": {
"benchmark:node": "node benchmark/benchmark.js",
"clean": "node-gyp clean",
"install": "npm run rebuild",
"lint": "standard",
"prepublish": "node-gyp rebuild && npm run lint && npm run test",
"rebuild": "node-gyp rebuild",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start karma.conf.js",
"test:node": "istanbul test _mocha -- --reporter spec test/index.js"
"test:node": "istanbul test node_modules/mocha/bin/_mocha -- --reporter spec test/index.js"
},

@@ -57,2 +52,3 @@ "dependencies": {

"bn.js": "^4.10.0",
"drbg.js": "^1.0.0",
"elliptic": "^6.2.3",

@@ -80,3 +76,4 @@ "nan": "^2.2.0"

"progress": "^1.1.8",
"standard": "^5.3.1"
"standard": "^5.3.1",
"xorshift.js": "^1.0.1"
},

@@ -89,10 +86,3 @@ "engines": {

"./bindings.js": "./elliptic.js"
},
"standard": {
"globals": [
"describe",
"before",
"it"
]
}
}

@@ -32,3 +32,4 @@ # secp256k1-node

* [API Reference (v3.x)](API.md)
* [API Reference (v3.x)](blob/master/API.md)
* [API Reference (v2.x)](blob/v2.x/API.md)

@@ -80,3 +81,4 @@ ```js

|elliptic|303555 |211777 |62124 |
|embedded|129498 |88958 |20188 |
|embedded|241829 |152989 |35908 |
|diff |25% |38% |73% |

@@ -83,0 +85,0 @@ ##### Performance:

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