Init with bn.js

This commit is contained in:
Jaco Greeff 2018-06-21 09:54:24 +02:00
commit db12e082f1
11 changed files with 5881 additions and 0 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
build/
coverage/
node_modules/
tmp/
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
package-lock.json
npm-debug.log*
yarn-debug.log*
yarn-error.log*

0
.npmignore Normal file
View File

9
.travis.yml Normal file
View File

@ -0,0 +1,9 @@
language: node_js
node_js:
- "10"
cache:
yarn: true
directories:
- node_modules
script:
- yarn polkadot-dev-build-travis

11
README.md Normal file
View File

@ -0,0 +1,11 @@
# @polkadot/ts
TypeScript definitions for packages that are not (yet) available on (DefinitelyTyped)[https://github.com/DefinitelyTyped/DefinitelyTyped] but are used in `@polkadot` projects.
In general, updates here should have corrsponding PRs on the DefinitelyTyped repo. Tracking should be provided for these.
# libraries
This following libraries are currently included -
- bn.js [DT PR 26717](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26717)

12
bn.js/bn.js-tests.ts Normal file
View File

@ -0,0 +1,12 @@
import BN = require('bn.js');
let bn = new BN(42);
bn = bn.add(bn);
bn.isZero();
bn.byteLength;
BN.isBN(3); // false
BN.isBN(bn); // true
bn.usubn(1); // 41
bn.uaddn(1); // 42

123
bn.js/index.d.ts vendored Normal file
View File

@ -0,0 +1,123 @@
// Type definitions for bn.js 4.11
// Project: https://github.com/indutny/bn.js
// Definitions by: Leonid Logvinov <https://github.com/LogvinovLeon>
// Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
type Endianness = 'le' | 'be';
declare class BN {
constructor(num: number | string | number[] | Buffer, base?: number, endian?: Endianness);
static isBN(val: any): val is BN;
abs(): BN;
iabs(): BN;
uabs(): BN;
add(bn: BN): BN;
addn(num: number): BN;
iadd(bn: BN): BN;
iaddn(num: number): BN;
uadd(bn: BN): BN;
uaddn(num: number): BN;
and(bn: BN): BN;
andn(num: number): BN;
iand(bn: BN): BN;
iandn(num: number): BN;
uand(bn: BN): BN;
uandn(num: number): BN;
bincn(num: number): BN;
bitLength(): number;
byteLength(): number;
clone(): BN;
cmp(bn: BN): number;
cmpn(num: number): number;
div(bn: BN): BN;
divn(num: number): BN;
idiv(bn: BN): BN;
idivn(num: number): BN;
udiv(bn: BN): BN;
udivn(num: number): BN;
divRound(bn: BN): BN;
divRoundn(num: number): BN;
idivRound(bn: BN): BN;
idivRoundn(num: number): BN;
udivRound(bn: BN): BN;
udivRoundn(num: number): BN;
egcd(bn: BN): { a: BN; bn: BN; gcd: BN };
eq(bn: BN): boolean;
eqn(num: number): boolean;
fromTwos(width: number): BN;
gcd(bn: BN): BN;
gt(bn: BN): boolean;
gtn(num: number): boolean;
gte(bn: BN): boolean;
gten(num: number): boolean;
invm(bn: BN): BN;
isEven(): boolean;
isNeg(): boolean;
isOdd(): boolean;
isZero(): boolean;
lt(bn: BN): boolean;
ltn(num: number): boolean;
lte(bn: BN): boolean;
lten(num: number): boolean;
maskn(mask: number): BN;
imaskn(mask: number): BN;
umaskn(mask: number): BN;
mod(mod: BN): BN;
modn(mod: number): BN;
imod(mod: BN): BN;
imodn(mod: number): BN;
umod(mod: BN): BN;
umodn(mod: number): BN;
mul(bn: BN): BN;
muln(num: number): BN;
imul(bn: BN): BN;
imuln(num: number): BN;
umul(bn: BN): BN;
umuln(num: number): BN;
neg(): BN;
notn(bit: number): BN;
or(bn: BN): BN;
ot(num: number): BN;
pow(pow: BN): BN;
pown(pow: number): BN;
ipow(pow: BN): BN;
ipown(pow: number): BN;
upow(pow: BN): BN;
upown(pow: number): BN;
setn(bit: number): BN;
shln(num: number): BN;
iushln(num: number): BN;
ushln(num: number): BN;
shrn(num: number): BN;
iushrn(num: number): BN;
ushrn(num: number): BN;
sqr(): BN;
isqr(): BN;
sub(bn: BN): BN;
subn(num: number): BN;
isub(bn: BN): BN;
isubn(num: number): BN;
usub(bn: BN): BN;
usubn(num: number): BN;
testn(bit: number): BN;
toArray(endian?: Endianness, len?: number): number[];
toBuffer(endian?: Endianness, len?: number): Buffer;
toJSON(): string;
toNumber(): number;
toString(base?: number, len?: number): string;
toTwos(width: number): BN;
xor(bn: BN): BN;
xorn(num: number): BN;
ixor(bn: BN): BN;
ixorn(num: number): BN;
uxor(bn: BN): BN;
uxorn(num: number): BN;
zeroBits(): number;
}
export = BN;

16
bn.js/tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "bn.js-tests.ts"]
}

1
bn.js/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

20
build.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# Copyright 2017-2018 @polkadot/dev authors & contributors
# This software may be modified and distributed under the terms
# of the ISC license. See the LICENSE file for details.
rm -rf build
mkdir -p build
DIRS=( $(ls -1d *) )
for DIR in "${DIRS[@]}"; do
if [ -d "$DIR" ] && [ -f "$DIR/index.d.ts" ]; then
echo ""
echo "*** Copying $DIR"
cp -r $DIR build/
fi
done
exit 0

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "@polkadot/ts",
"version": "0.0.1",
"description": "Typescript definitions that are not (yet) available on https://github.com/DefinitelyTyped/DefinitelyTyped",
"repository": "https://github.com/polkadot-js/ts.git",
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "MIT",
"scripts": {
"build": "./build.sh",
"check": "echo \"No 'yarn run check' available\"",
"test": "echo \"No 'yarn run test' available\""
},
"dependencies": {
"@polkadot/dev": "^0.19.28",
"@types/node": "^10.3.4"
}
}

5659
yarn.lock Normal file

File diff suppressed because it is too large Load Diff