Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: justmoon/node-bignum
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9c3254dbf19c8a56679311e68bba0ae64ef4df7a
Choose a base ref
...
head repository: justmoon/node-bignum
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ef2e02533e598d6df8421000033c4753cde89ee2
Choose a head ref
  • 13 commits
  • 11 files changed
  • 4 contributors

Commits on Jun 16, 2016

  1. remove timeout

    rvagg committed Jun 16, 2016
    Copy the full SHA
    6511d95 View commit details
  2. add --timeout 120 to tap

    rvagg committed Jun 16, 2016
    Copy the full SHA
    312837f View commit details

Commits on Jun 29, 2018

  1. rebuild

    rvagg committed Jun 29, 2018
    Copy the full SHA
    3f4ae9d View commit details
  2. fix: let it support Node.js 10

    XadillaX authored and rvagg committed Jun 29, 2018
    Copy the full SHA
    1951f56 View commit details
  3. Copy the full SHA
    cc354b7 View commit details
  4. 0.13.0

    rvagg committed Jun 29, 2018
    Copy the full SHA
    efde423 View commit details

Commits on Dec 20, 2019

  1. Update README.markdown (#122)

    Add notation referencing BigInt native Object.
    tracker1 authored and rvagg committed Dec 20, 2019
    Copy the full SHA
    ce26c0c View commit details
  2. src: fixes for node 12

    fanatid authored and rvagg committed Dec 20, 2019
    Copy the full SHA
    735da93 View commit details
  3. src: update for Node 13 compat

    rvagg committed Dec 20, 2019
    Copy the full SHA
    a431989 View commit details
  4. Copy the full SHA
    27508d2 View commit details
  5. dist: remove prebuild (for now)

    rvagg committed Dec 20, 2019
    Copy the full SHA
    72951c5 View commit details
  6. ci: replace travis with actions

    rvagg committed Dec 20, 2019
    Copy the full SHA
    0c871e1 View commit details
  7. 0.13.1

    rvagg committed Dec 20, 2019
    Copy the full SHA
    ef2e025 View commit details
Showing with 212 additions and 210 deletions.
  1. +29 −0 .github/workflows/main.yml
  2. +1 −1 .gitignore
  3. +0 −22 .travis.yml
  4. +6 −2 README.markdown
  5. +2 −3 appveyor.yml
  6. +130 −118 bignum.cc
  7. +1 −11 binding.gyp
  8. +7 −11 index.js
  9. +9 −15 package.json
  10. +8 −9 test/big.js
  11. +19 −18 test/buf.js
29 changes: 29 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on: [push, pull_request]

jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest] # windows-latest needs openssl installed in C:\OpenSSL-Win64\
node-version: [10.x, 12.x, 13.x]

steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Install and test with Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm test
env:
CI: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Files
.lock-wscript
pre-gyp-publish.sh
package-lock.json

# Filetypes
.*.swp
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

8 changes: 6 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
bignum
======

[![Travis build status](https://travis-ci.org/justmoon/node-bignum.svg?branch=master)](https://travis-ci.org/justmoon/node-bignum)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/svyho17a4eq2f0a7/branch/master?svg=true)](https://ci.appveyor.com/project/RodVagg/node-bignum/branch/master)
[![Build Status](https://github.com/justmoon/node-bignum/workflows/CI/badge.svg)](https://github.com/justmoon/node-bignum/actions?workflow=CI)

Arbitrary precision integral arithmetic for Node.js using
OpenSSL.
@@ -14,6 +13,11 @@ it uses the builtin bignum functionality provided by OpenSSL. The
advantage is that OpenSSL is already part of Node.js, so this
library does not add any external dependency whatsoever.

BigInt
======

JavaScript now has a BigInt object. If you are using Node 10.4 or newer, you should use or migrate to [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).

differences
===========

5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -7,11 +7,10 @@ environment:
# kudos to serialport for much of this

matrix:
- nodejs_version: "0.10"
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "5"
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "10"

platform:
- x86
248 changes: 130 additions & 118 deletions bignum.cc

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -82,16 +82,6 @@
}
]
]
}, {
'target_name': 'action_after_build',
'type': 'none',
'dependencies': [ '<(module_name)' ],
'copies': [
{
'files': [ '<(PRODUCT_DIR)/<(module_name).node' ],
'destination': '<(module_path)'
}
]
}
]
}
}
18 changes: 7 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var binary = require('node-pre-gyp')
var path = require('path')
var binPath = binary.find(path.resolve(path.join(__dirname, 'package.json')))
var bin = require(binPath)
var bin = require('bindings')('bignum')
var Buffer = require('safe-buffer').Buffer
var BigNum = bin.BigNum

module.exports = BigNum
@@ -28,7 +26,7 @@ BigNum.conditionArgs = function (num, base) {
base: 2
}
}
} else if (num.match(/e\-/)) { // negative exponent
} else if (num.match(/e-/)) { // negative exponent
return {
num: Math.floor(Number(num)).toString(),
base: base || 10
@@ -76,7 +74,7 @@ BigNum.prototype.toNumber = function () {
return parseInt(this.toString(), 10)
}

;[ 'add', 'sub', 'mul', 'div', 'mod' ].forEach(function (op) {
;['add', 'sub', 'mul', 'div', 'mod'].forEach(function (op) {
BigNum.prototype[op] = function (num) {
var x
if (BigNum.isBigNum(num)) {
@@ -257,9 +255,7 @@ BigNum.prototype.rand = function (to) {
return this.brand0()
}
} else {
var x = BigNum.isBigNum(to)
? to.sub(this)
: BigNum(to).sub(this)
var x = BigNum.isBigNum(to) ? to.sub(this) : BigNum(to).sub(this)
return x.brand0().add(this)
}
}
@@ -342,7 +338,7 @@ BigNum.prototype.toBuffer = function (opts) {
var len = buf.length === 1 && buf[0] === 0 ? 0 : buf.length
if (buf[0] & 0x80) len++

var ret = new Buffer(4 + len)
var ret = Buffer.alloc(4 + len)
if (len > 0) buf.copy(ret, 4 + (buf[0] & 0x80 ? 1 : 0))
if (buf[0] & 0x80) ret[4] = 0

@@ -377,7 +373,7 @@ BigNum.prototype.toBuffer = function (opts) {
var size = opts.size === 'auto' ? Math.ceil(hex.length / 2) : (opts.size || 1)

len = Math.ceil(hex.length / (2 * size)) * size
buf = new Buffer(len)
buf = Buffer.alloc(len)

// zero-pad the hex string so the chunks are all `size` long
while (hex.length < 2 * len) hex = '0' + hex
24 changes: 9 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bignum",
"version": "0.12.5",
"version": "0.13.1",
"description": "Arbitrary-precision integer arithmetic using OpenSSL",
"main": "./index.js",
"repository": {
@@ -22,24 +22,18 @@
"url": "http://www.justmoon.net"
},
"dependencies": {
"nan": "^2.3.4",
"node-pre-gyp": "~0.6.28"
"bindings": "^1.5.0",
"nan": "^2.14.0",
"safe-buffer": "^5.2.0"
},
"devDependencies": {
"aws-sdk": "~2.4.0",
"put": "~0.0.5",
"standard": "~7.1.2",
"tap": "~5.7.2"
"put": "0.0.6",
"standard": "^14.3.1",
"tap": "^14.10.5"
},
"scripts": {
"install": "node-pre-gyp install --fallback-to-build",
"test": "standard && tap test/*.js"
},
"binary": {
"host": "https://rvagg-node.s3-us-west-2.amazonaws.com",
"module_name": "bignum",
"module_path": "binding/",
"remote_path": "./{name}/v{version}"
"install": "node-gyp rebuild",
"test": "standard && tap --timeout 120 test/*.js"
},
"license": "MIT",
"contributors": [
17 changes: 8 additions & 9 deletions test/big.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var Buffer = require('safe-buffer').Buffer
var BigNum = require('../')
var test = require('tap').test

test.setTimeout(120000)

test('create', { timeout: 120000 }, function (t) {
t.deepEqual(BigNum(1337).toString(), '1337')
t.deepEqual(BigNum('1337').toString(), '1337')
@@ -242,7 +241,7 @@ test('cmp', { timeout: 120000 }, function (t) {
var bi = BigNum(i)

for (var j = -10; j <= 10; j++) {
[ j, BigNum(j) ].forEach(function (jj) {
[j, BigNum(j)].forEach(function (jj) {
t.deepEqual(bi.lt(jj), i < j)
t.deepEqual(bi.le(jj), i <= j)
t.deepEqual(bi.eq(jj), i === j)
@@ -257,8 +256,8 @@ test('cmp', { timeout: 120000 }, function (t) {
})

test('powm', { timeout: 120000 }, function (t) {
var twos = [ 2, '2', BigNum(2), BigNum('2') ]
var tens = [ 100000, '100000', BigNum(100000), BigNum(100000) ]
var twos = [2, '2', BigNum(2), BigNum('2')]
var tens = [100000, '100000', BigNum(100000), BigNum(100000)]
twos.forEach(function (two) {
tens.forEach(function (ten) {
t.deepEqual(
@@ -279,7 +278,7 @@ test('powm', { timeout: 120000 }, function (t) {
})

test('pow', { timeout: 120000 }, function (t) {
[ 2, '2', BigNum(2), BigNum('2') ].forEach(function (two) {
[2, '2', BigNum(2), BigNum('2')].forEach(function (two) {
t.deepEqual(
BigNum('111111111').pow(two).toString(),
'12345678987654321'
@@ -437,7 +436,7 @@ test('primes', { timeout: 120000 }, function (t) {
'5628290459057877291809182450381238927697314822133923421169378062922140081498734424133112032854812293'
]

;[ uniques, wagstaff, big ].forEach(function (xs) {
;[uniques, wagstaff, big].forEach(function (xs) {
xs.forEach(function (x) {
var p = BigNum(x).probPrime()
t.ok(p === true || p === 'maybe')
@@ -513,7 +512,7 @@ test('endian', { timeout: 120000 }, function (t) {
t.deepEqual(b.toBuffer({ endian: 'big', size: 'auto' }).toString('hex'), '0102030405')
t.deepEqual(b.toBuffer({ endian: 'little', size: 'auto' }).toString('hex'), '0504030201')

var c = new Buffer('000102030405', 'hex')
var c = Buffer.from('000102030405', 'hex')
t.deepEqual(BigNum.fromBuffer(c, { endian: 'big', size: 'auto' }).toString(16), '0102030405')
t.deepEqual(BigNum.fromBuffer(c, { endian: 'little', size: 'auto' }).toString(16), '050403020100')

@@ -522,7 +521,7 @@ test('endian', { timeout: 120000 }, function (t) {

test('bitlength', { timeout: 120000 }, function (t) {
var bl = BigNum(
'433593290010590489671135819286259593426549306666324008679782084292' +
'433593290010590489671135819286259593426549306666324008679782084292' +
'2446494189019075159822930571858728009485237489829138626896756141' +
'873895833763224917704497568647701157104426'
).bitLength()
37 changes: 19 additions & 18 deletions test/buf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var BigNum = require('../')
var put = require('put')
var test = require('tap').test
var Buffer = require('safe-buffer').Buffer

test('bufBe', function (t) {
var buf1 = new Buffer([1, 2, 3, 4])
var buf1 = Buffer.from([1, 2, 3, 4])
var num = BigNum.fromBuffer(buf1, { size: 4 }).toNumber()
t.deepEqual(
num,
@@ -22,7 +23,7 @@ test('bufBe', function (t) {
})

test('bufLe', function (t) {
var buf1 = new Buffer([1, 2, 3, 4])
var buf1 = Buffer.from([1, 2, 3, 4])
var num = BigNum
.fromBuffer(buf1, { size: 4, endian: 'little' })
.toNumber()
@@ -36,8 +37,8 @@ test('bufLe', function (t) {
})

test('bufBe_le', function (t) {
var bufBe = new Buffer([1, 2, 3, 4, 5, 6, 7, 8])
var bufLe = new Buffer([4, 3, 2, 1, 8, 7, 6, 5])
var bufBe = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8])
var bufLe = Buffer.from([4, 3, 2, 1, 8, 7, 6, 5])

var numBe = BigNum
.fromBuffer(bufBe, { size: 4, endian: 'big' })
@@ -53,11 +54,11 @@ test('bufBe_le', function (t) {
})

test('buf_high_bits', function (t) {
var bufBe = new Buffer([
var bufBe = Buffer.from([
201, 202, 203, 204,
205, 206, 207, 208
])
var bufLe = new Buffer([
var bufLe = Buffer.from([
204, 203, 202, 201,
208, 207, 206, 205
])
@@ -104,7 +105,7 @@ test('buf_to_from', function (t) {
})

test('toBuf', function (t) {
var buf = new Buffer([ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ])
var buf = Buffer.from([0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f])
var b = BigNum(
0x0a * 256 * 256 * 256 * 256 * 256 +
0x0b * 256 * 256 * 256 * 256 +
@@ -118,12 +119,12 @@ test('toBuf', function (t) {

t.deepEqual(
[].slice.call(b.toBuffer({ endian: 'big', size: 2 })),
[ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ]
[0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
)

t.deepEqual(
[].slice.call(b.toBuffer({ endian: 'little', size: 2 })),
[ 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e ]
[0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e]
)

t.deepEqual(
@@ -135,14 +136,14 @@ test('toBuf', function (t) {
[].slice.call(BigNum(43135012110).toBuffer({
endian: 'little', size: 4
})),
[ 0x0a, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x0c, 0x0b ]
[0x0a, 0x00, 0x00, 0x00, 0x0e, 0x0d, 0x0c, 0x0b]
)

t.deepEqual(
[].slice.call(BigNum(43135012110).toBuffer({
endian: 'big', size: 4
})),
[ 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e ]
[0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e]
)

t.end()
@@ -153,12 +154,12 @@ test('zeroPad', function (t) {

t.deepEqual(
[].slice.call(b.toBuffer({ endian: 'big', size: 4 })),
[ 0x00, 0x12, 0x34, 0x56 ]
[0x00, 0x12, 0x34, 0x56]
)

t.deepEqual(
[].slice.call(b.toBuffer({ endian: 'little', size: 4 })),
[ 0x56, 0x34, 0x12, 0x00 ]
[0x56, 0x34, 0x12, 0x00]
)

t.end()
@@ -169,15 +170,15 @@ test('toMpint', function (t) {
// http://tools.ietf.org/html/rfc4251#page-10

var refs = {
'0': new Buffer([ 0x00, 0x00, 0x00, 0x00 ]),
'9a378f9b2e332a7': new Buffer([
0: Buffer.from([0x00, 0x00, 0x00, 0x00]),
'9a378f9b2e332a7': Buffer.from([
0x00, 0x00, 0x00, 0x08,
0x09, 0xa3, 0x78, 0xf9,
0xb2, 0xe3, 0x32, 0xa7
]),
'80': new Buffer([ 0x00, 0x00, 0x00, 0x02, 0x00, 0x80 ]),
'-1234': new Buffer([ 0x00, 0x00, 0x00, 0x02, 0xed, 0xcc ]),
'-deadbeef': new Buffer([ 0x00, 0x00, 0x00, 0x05, 0xff, 0x21, 0x52, 0x41, 0x11 ])
80: Buffer.from([0x00, 0x00, 0x00, 0x02, 0x00, 0x80]),
'-1234': Buffer.from([0x00, 0x00, 0x00, 0x02, 0xed, 0xcc]),
'-deadbeef': Buffer.from([0x00, 0x00, 0x00, 0x05, 0xff, 0x21, 0x52, 0x41, 0x11])
}

Object.keys(refs).forEach(function (key) {