Git Product home page Git Product logo

bigi's Introduction

bigi's People

Contributors

dcousens avatar fanatid avatar jprichardson avatar kenany avatar shesek avatar sidazhang avatar weilu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bigi's Issues

Need isBigInteger

Can we add isBigInteger? As a work-around, what do you recommend?

Look Into Internal Optimizations

There was some discussion about changing this to be backed by a Buffer. I think that'll actually be slower since operations will then be preformed on a 8 bit numbers as opposed to what it uses now.

By analyzing the code, it does appear to in fact take advantage of JavaScript's capability of handling integers up to 53 bits. So porting to JavaScript native typed arrays may actually introduce a performance penalty.

Maybe there may be a way to leverage some of the concepts of asm.js? Not sure. It's worth looking at potential changes and benchmarking them.

inconsistent result compare to other lib

Having a big integer, this is the string representation (10 radix): "61112663125671126633722436054102056730607837166180410453588415302234407842306"

The method toDERInteger() which convert to the bigendian bytes would return:
[0, -121, 28, -118, -93, -127, -101, 97, 127, 69, -4, -15, 127, -126, 42, -104, -89, 8, 44, 66, 30, 73, -84, -5, -54, -93, -87, 83, -28, 113, 30, 50, 2]

But the same method from pointycastle returns:
https://github.com/PointyCastle/pointycastle/blob/master/lib/src/utils.dart#L21

unsigned:
[135, 28, 138, 163, 129, 155, 97, 127, 69, 252, 241, 127, 130, 42, 152, 167, 8, 44, 66, 30, 73, 172, 251, 202, 163, 169, 83, 228, 113, 30, 50, 2]

convert to signed:
[-121, 28, -118, -93, -127, -101, 97, 127, 69, -4, -15, 127, -126, 42, -104, -89, 8, 44, 66, 30, 73, -84, -5, -54, -93, -87, 83, -28, 113, 30, 50, 2]

Wondering what is the leading 0...

Wrong instantiation of BigInteger from buffers and hex for negative numbers

Seems like there are issues in converting buffers to BigInteger instances.
Below you can see the sample code example and the output of it in node.js environment.

'use strict';
const BigInteger = require('bigi');
const bigNegativeNumberString = '-12345678900';
const bigIRepresentation = new BigInteger(bigNegativeNumberString);

console.log([
    bigIRepresentation.toString(),
    BigInteger.fromBuffer(bigIRepresentation.toBuffer()).toString(),
    BigInteger.fromHex(bigIRepresentation.toHex()).toString()
]);

Output:
[ '-12345678900', '1087165948876', '1087165948876' ]

toByteArrayUnsigned() gives signed output

The toByteArrayUnsigned() seems broken:

b=BigInteger('1234567890',10)
b.toByteArrayUnsigned()

results in: [73, -106, 2, -46] while there should be no negative numbers.

In fact, it gives the same result than toByteArray()

Inconsistent output with gatsby on production build

I have a private key of type buffer.

In my local env, when running gatsby build the line BigInteger.fromBuffer(privateKey) console logs this:

BigInteger {0: 5218218, 1: 6291014, 2: 34656281, 3: 1776116, 4: 53518743, 5: 10808093, 6: 62725491, 7: 63913863, 8: 50275223, 9: 1979384, t: 10, s: 0}

When I am in production, run with gatsby build, the same exact line outputs this:

n {0: 5218218, 1: 6291014, 2: 34656281, 3: 1776116, 4: 53518743, 5: 10808093, 6: 62725491, 7: 63913863, 8: 50275223, 9: 1979384, t: 10, s: 0}

so the ecsda signature fails, saying it expects a BigInteger and is receiving type n

How does one create a BigInteger from an integer?

Until we have a constructor: #18
... or a fromInt method, what is the best way to create a BigInteger from a number (even one with a decimal place)?

Here is my work-around, but it produced a number that was much too large in the second case:

BigInteger("11").toString() == "11"
BigInteger("1.1").toString() == "11"

Both lines return true

new BigInteger(1) fails

     TypeError: Cannot read property 'nextBytes' of undefined
      at BigInteger.bnpFromNumber [as fromNumber] (node_modules/bigi/lib/bigi.js:775:6)
      at new BigInteger (node_modules/bigi/lib/bigi.js:7:36)

Is it meant to be supported?

Primality test can return true for composites

It appears the Miller-Rabin test implemented in bigi always chooses the base from the set of primes < 1000, however it is possible to construct a composite that appears prime relative to any fixed set of witnesses, and the paper https://math.dartmouth.edu/~carlp/PDF/reliable.pdf has a proof that there exist integers with no small witnesses at all.

The best fix is probably to choose the witnesses randomly from the range [2,n) which avoids the problem entirely.

Missing byteCount function

I see byteCount method is listed in the document. But when I tried to use it, it throws error:
Object has no method 'byteCount'
Thanks :)

Accept Intergers in the constuctor

It would be nice if you could initialize bigi with an intereger like so

var bi = require('bigi'); 
var aNumber = bi(9);

Currently if you try this you get

typeError: Cannot call method 'nextBytes' of undefined
    at BigInteger.bnpFromNumber [as fromNumber] (/home/null/code/bigi/lib/bigi.js:775:7)
    at new BigInteger (/home/null/code/bigi/lib/bigi.js:7:36)
    at BigInteger (/home/null/code/bigi/lib/bigi.js:4:12)

Incomplete hex

Code is like this below

const num1 = 726
const BigIntegerOne = bigi.fromHex(toHex(num1))

function toHex(num) {
  let hex = num.toString(16)

  return hex
}

When I used the method 'fromHex', I found that it thow an error, "Incomplete hex".
So, I don't know what does it mean.
Could you please tell me the reason why you handle this error message.
Hope see you response in few time.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.