GithubHelp home page GithubHelp logo

isabella232 / fixed-bn.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ethereumjs/fixed-bn.js

0.0 0.0 0.0 42 KB

a bn.js wrapper that constrains numbers to a fixed width

JavaScript 34.87% TypeScript 65.13%

fixed-bn.js's Introduction

SYNOPSIS

NPM Package Build Status Coverage Status

js-standard-style

a bn.js factory wrapper that constrains numbers to a fixed width

USAGE

const FixedBN = require('fixed-bn.js')

// there are some built in sizes `U64`, `U128`, `U160`, `U256`
const bnNum = new FixedBN.U64('0x5555555')
// use normal bn.js methods
bnNum.iaddn(55)

// toBuffer and toArray allways produces a fixed length result
bnNum.toBuffer()
// <Buffer 00 00 00 00 05 55 55 55>

// you can also create an arbitary fixed lenght bn
// max bit lenght is 199 bits and min length is 2 bits
const I199 = FixedBN(199, 2)
const newBnNum = new I199(390248)

API

Since this module extends BN.js it has the methods as it does plus a few extras.

factory

./index.js:11-87

A factory that produces BN.js constructors for a given width

Parameters

  • maxWidth Integer the max length in bits that the bn.js instance can handle
  • minWidth Integer the min length in bits that the bn.js instance can handle

Returns bn.js returns a bn.js constuctor that that is constained to maxWidth and minWidth

builtin length

the factory has the following builtins

  • FixedBN.U64
  • FixedBN.U128
  • FixedBN.U160
  • FixedBN.U256

bn.js instance

Each instance has the following additional methods

maxWidth

./index.js:35-37

retuns Max Width

Returns integer

minWidth

./index.js:43-45

retuns Min Width

Returns integer

fromBuffer

./index.js:66-68

converts a buffer to a fixed-bn.js

Parameters

  • value (string | integer)
  • endain string
  • endian (optional, default 'be')

isFixBN

./index.js:74-76

checks if a BN instance is a fixed BN instance

Parameters

  • bn bn.js

isSameWidth

./index.js:82-84

checks if a fixed-bn instance is the same width as the contructor

Parameters

  • fixBN bn.js

LICENSE

MPL-2.0

fixed-bn.js's People

Contributors

greenkeeper[bot] avatar s1na avatar axic avatar micahzoltu avatar

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.