Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
697a452ba6 | ||
|
|
f68294c4e7 | ||
|
|
0130d18945 | ||
|
|
15c9904c96 | ||
|
|
add2749967 | ||
|
|
fe2f054389 | ||
|
|
bb1c117727 | ||
|
|
27c474bd78 | ||
|
|
039b5ec932 | ||
|
|
9eea21e0c4 | ||
|
|
aab533f92e | ||
|
|
2159270d80 | ||
|
|
f1b09eb2e5 | ||
|
|
d08cf8b5fe | ||
|
|
941618b830 | ||
|
|
983ca718ec | ||
|
|
41ebdd5c59 | ||
|
|
8971c89081 | ||
|
|
d1934060e0 | ||
|
|
6d9da39d8b | ||
|
|
4ed096024e |
@@ -1 +1,2 @@
|
|||||||
5
|
5
|
||||||
|
2.6.2
|
||||||
@@ -2,112 +2,20 @@ name: PR
|
|||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
pr:
|
||||||
name: Linting
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [12.x]
|
step: ['lint', 'test', 'build', 'docs']
|
||||||
steps:
|
name: ${{ matrix.step }}
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: lint
|
|
||||||
run: |
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
|
||||||
yarn lint
|
|
||||||
|
|
||||||
test:
|
|
||||||
name: Testing
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- uses: actions/setup-node@v1
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: '12.x'
|
||||||
- name: Config yarn cache
|
- name: ${{ matrix.step }}
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: test
|
|
||||||
env:
|
env:
|
||||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||||
run: |
|
run: |
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
yarn test
|
yarn ${{ matrix.step }}
|
||||||
|
|
||||||
build_code:
|
|
||||||
name: Build Code
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: build
|
|
||||||
run: |
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
|
||||||
yarn build
|
|
||||||
|
|
||||||
build_docs:
|
|
||||||
name: Build Docs
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: build
|
|
||||||
run: |
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
|
||||||
yarn docs
|
|
||||||
|
|||||||
@@ -5,82 +5,36 @@ on:
|
|||||||
- master
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_code:
|
master:
|
||||||
name: Build Code
|
|
||||||
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [12.x]
|
step: ['build:release', 'docs:release']
|
||||||
|
name: ${{ matrix.step }}
|
||||||
|
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_PAT }}
|
token: ${{ secrets.GH_PAT }}
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- uses: actions/setup-node@v1
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: '12.x'
|
||||||
- name: Config yarn cache
|
- name: ${{ matrix.step }}
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: build
|
|
||||||
env:
|
env:
|
||||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||||
|
GH_PAGES_SRC: build-docs
|
||||||
GH_PAT: ${{ secrets.GH_PAT }}
|
GH_PAT: ${{ secrets.GH_PAT }}
|
||||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
yarn polkadot-ci-ghact-build
|
yarn ${{ matrix.step }}
|
||||||
|
|
||||||
build_docs:
|
|
||||||
name: Build Docs
|
|
||||||
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: build
|
|
||||||
env:
|
|
||||||
GH_PAT: ${{ secrets.GH_PAT }}
|
|
||||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
|
||||||
GH_PAGES_SRC: build-docs
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
|
||||||
yarn polkadot-ci-ghact-docs
|
|
||||||
|
|
||||||
dummy:
|
dummy:
|
||||||
name: Dummy
|
name: Dummy
|
||||||
if: "contains(github.event.head_commit.message, '[CI Skip]')"
|
if: "contains(github.event.head_commit.message, '[CI Skip]')"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
steps:
|
||||||
- name: dummy
|
- name: dummy
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Vendored
-58
File diff suppressed because one or more lines are too long
+50
File diff suppressed because one or more lines are too long
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
enableImmutableInstalls: false
|
enableImmutableInstalls: false
|
||||||
|
|
||||||
enableProgressBars: false
|
enableProgressBars: false
|
||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
@@ -7,4 +8,4 @@ plugins:
|
|||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
spec: "@yarnpkg/plugin-interactive-tools"
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-berry.js
|
yarnPath: .yarn/releases/yarn-rc.js
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
# 2.7.1 Mar 31, 2020
|
||||||
|
|
||||||
|
- Add `bnSqrt` to calculate the integer sqrt via Newton iteration
|
||||||
|
- Allow for optional wasm-crypto, specifically via `@polkadot/util-crypto/noWasm`
|
||||||
|
- Misc. CI infrastructure cleanups
|
||||||
|
|
||||||
# 2.6.1 Feb 29, 2020
|
# 2.6.1 Feb 29, 2020
|
||||||
|
|
||||||
- **Breaking change** Following on the 2.0 release, `@polkadot/wasm` was updated to 1.1+. sr25510 now only verifies 0.8+ signatures, closing the loop on dropping Substrate 1.x-era support
|
- **Breaking change** Following on the 2.0 release, `@polkadot/wasm` was updated to 1.1+. sr25510 now only verifies 0.8+ signatures, closing the loop on dropping Substrate 1.x-era support
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@
|
|||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"version": "2.6.1"
|
"version": "2.7.1"
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -11,7 +11,9 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "polkadot-dev-build-ts",
|
"build": "polkadot-dev-build-ts",
|
||||||
|
"build:release": "polkadot-ci-ghact-build",
|
||||||
"docs": "polkadot-dev-build-docs",
|
"docs": "polkadot-dev-build-docs",
|
||||||
|
"docs:release": "polkadot-ci-ghact-docs",
|
||||||
"lint": "polkadot-dev-run-lint",
|
"lint": "polkadot-dev-run-lint",
|
||||||
"clean": "polkadot-dev-clean-build",
|
"clean": "polkadot-dev-clean-build",
|
||||||
"postinstall": "polkadot-dev-yarn-only",
|
"postinstall": "polkadot-dev-yarn-only",
|
||||||
@@ -19,8 +21,9 @@
|
|||||||
"test:one": "polkadot-dev-run-test"
|
"test:one": "polkadot-dev-run-test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.8.6",
|
"@babel/core": "^7.9.0",
|
||||||
"@polkadot/dev": "^0.50.15",
|
"@polkadot/dev": "^0.51.9",
|
||||||
"@polkadot/ts": "^0.3.6"
|
"@polkadot/ts": "^0.3.14",
|
||||||
|
"@types/jest": "^25.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/keyring",
|
"name": "@polkadot/keyring",
|
||||||
"version": "2.6.1",
|
"version": "2.7.1",
|
||||||
"description": "Keyring management",
|
"description": "Keyring management",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.8.4",
|
"@babel/runtime": "^7.9.2",
|
||||||
"@polkadot/util": "2.6.1",
|
"@polkadot/util": "2.7.1",
|
||||||
"@polkadot/util-crypto": "2.6.1"
|
"@polkadot/util-crypto": "2.7.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { decodeAddress, encodeAddress, setSS58Format } from '@polkadot/util-cryp
|
|||||||
import Keyring from './keyring';
|
import Keyring from './keyring';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
detectPackage(require('./package.json'), __dirname);
|
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
|
||||||
|
|
||||||
export default Keyring;
|
export default Keyring;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util-crypto",
|
"name": "@polkadot/util-crypto",
|
||||||
"version": "2.6.1",
|
"version": "2.7.1",
|
||||||
"description": "A collection of useful crypto utilities for @polkadot",
|
"description": "A collection of useful crypto utilities for @polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.8.4",
|
"@babel/runtime": "^7.9.2",
|
||||||
"@polkadot/util": "2.6.1",
|
"@polkadot/util": "2.7.1",
|
||||||
"@polkadot/wasm-crypto": "^1.2.1",
|
"@polkadot/wasm-crypto": "^1.2.1",
|
||||||
"base-x": "^3.0.8",
|
"base-x": "^3.0.8",
|
||||||
"bip39": "^3.0.2",
|
"bip39": "^3.0.2",
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
|
||||||
|
// This software may be modified and distributed under the terms
|
||||||
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
export function isReady (): boolean {
|
||||||
|
// always false, when true it will try and use non-existent functions
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function waitReady (): Promise<boolean> {
|
||||||
|
// always immediate true, our process is done
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util",
|
"name": "@polkadot/util",
|
||||||
"version": "2.6.1",
|
"version": "2.7.1",
|
||||||
"description": "A collection of useful utilities for @polkadot",
|
"description": "A collection of useful utilities for @polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.8.4",
|
"@babel/runtime": "^7.9.2",
|
||||||
"@types/bn.js": "^4.11.6",
|
"@types/bn.js": "^4.11.6",
|
||||||
"bn.js": "^5.1.1",
|
"bn.js": "^5.1.1",
|
||||||
"camelcase": "^5.3.1",
|
"camelcase": "^5.3.1",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
export { default as bnFromHex } from './fromHex';
|
export { default as bnFromHex } from './fromHex';
|
||||||
export { default as bnMax } from './max';
|
export { default as bnMax } from './max';
|
||||||
export { default as bnMin } from './min';
|
export { default as bnMin } from './min';
|
||||||
|
export { default as bnSqrt } from './sqrt';
|
||||||
export { default as bnToBn } from './toBn';
|
export { default as bnToBn } from './toBn';
|
||||||
export { default as bnToHex } from './toHex';
|
export { default as bnToHex } from './toHex';
|
||||||
export { default as bnToU8a } from './toU8a';
|
export { default as bnToU8a } from './toU8a';
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ import BN from 'bn.js';
|
|||||||
import assert from '../assert';
|
import assert from '../assert';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name max
|
* @name bnMax
|
||||||
* @summary Finds and returns the highest value in an array of BNs.
|
* @summary Finds and returns the highest value in an array of BNs.
|
||||||
* @example
|
* @example
|
||||||
* <BR>
|
* <BR>
|
||||||
*
|
*
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import BN from 'bn.js';
|
* import BN from 'bn.js';
|
||||||
* import { max } from '@polkadot/util';
|
* import { bnMax } from '@polkadot/util';
|
||||||
*
|
*
|
||||||
* max([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
|
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export default function max (...items: BN[]): BN {
|
export default function max (...items: BN[]): BN {
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ import BN from 'bn.js';
|
|||||||
import assert from '../assert';
|
import assert from '../assert';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name min
|
* @name bnMin
|
||||||
* @summary Finds and returns the smallest value in an array of BNs.
|
* @summary Finds and returns the smallest value in an array of BNs.
|
||||||
* @example
|
* @example
|
||||||
* <BR>
|
* <BR>
|
||||||
*
|
*
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import BN from 'bn.js';
|
* import BN from 'bn.js';
|
||||||
* import { min } from '@polkadot/util';
|
* import { bnMin } from '@polkadot/util';
|
||||||
*
|
*
|
||||||
* min([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
|
* bnMin([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export default function min (...items: BN[]): BN {
|
export default function min (...items: BN[]): BN {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/util authors & contributors
|
||||||
|
// This software may be modified and distributed under the terms
|
||||||
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
import BN from 'bn.js';
|
||||||
|
|
||||||
|
import { bnSqrt } from '.';
|
||||||
|
|
||||||
|
describe('bnSqrt', (): void => {
|
||||||
|
it('fails on < 0 roots', (): void => {
|
||||||
|
expect(
|
||||||
|
() => bnSqrt(new BN(-1))
|
||||||
|
).toThrow(/negative numbers is not supported/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('finds the sqrt (exact)', (): void => {
|
||||||
|
expect(
|
||||||
|
bnSqrt(new BN(256).mul(new BN(256)))
|
||||||
|
).toEqual(new BN(256));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('finds the sqrt (round)', (): void => {
|
||||||
|
expect(
|
||||||
|
bnSqrt(new BN(266))
|
||||||
|
).toEqual(new BN(16));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('find the sqrt for 1', (): void => {
|
||||||
|
expect(
|
||||||
|
bnSqrt(new BN(1))
|
||||||
|
).toEqual(new BN(1));
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/util authors & contributors
|
||||||
|
// This software may be modified and distributed under the terms
|
||||||
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
import BN from 'bn.js';
|
||||||
|
|
||||||
|
import assert from '../assert';
|
||||||
|
|
||||||
|
// https://golb.hplar.ch/2018/09/javascript-bigint.html
|
||||||
|
function newtonIteration (n: BN, x0: BN): BN {
|
||||||
|
const x1 = n.div(x0).add(x0).shrn(1);
|
||||||
|
|
||||||
|
if (x0.eq(x1) || x0.eq(x1.subn(1))) {
|
||||||
|
return x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newtonIteration(n, x1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name bnSqrt
|
||||||
|
* @summary Calculates the integer square root of a BN
|
||||||
|
* @example
|
||||||
|
* <BR>
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import BN from 'bn.js';
|
||||||
|
* import { bnSqrt } from '@polkadot/util';
|
||||||
|
*
|
||||||
|
* bnSqrt(new BN(16)).toString(); // => '4'
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export default function sqrt (value: BN): BN {
|
||||||
|
assert(value.gten(0), 'square root of negative numbers is not supported');
|
||||||
|
|
||||||
|
return value.ltn(2)
|
||||||
|
? value
|
||||||
|
: newtonIteration(value, new BN(1));
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ type PjsGlobal = NodeJS.Global & PjsChecks;
|
|||||||
type PjsWindow = Window & PjsChecks;
|
type PjsWindow = Window & PjsChecks;
|
||||||
|
|
||||||
function expandPath (path?: string): string {
|
function expandPath (path?: string): string {
|
||||||
return (!path || path.length < 5) ? '<unknown path>' : path;
|
return (!path || path.length < 5) ? '<unknown>' : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
@@ -47,7 +47,7 @@ function flattenVersions (_all: (VersionPath | string)[]): string {
|
|||||||
* @name detectPackage
|
* @name detectPackage
|
||||||
* @summary Checks that a specific package is only imported once
|
* @summary Checks that a specific package is only imported once
|
||||||
*/
|
*/
|
||||||
export default function detectPackage ({ name, version }: PackageJson, path?: string): void {
|
export default function detectPackage ({ name, version }: PackageJson, path?: string | false): void {
|
||||||
const _global = typeof window !== 'undefined'
|
const _global = typeof window !== 'undefined'
|
||||||
? window as PjsWindow
|
? window as PjsWindow
|
||||||
: global as PjsGlobal;
|
: global as PjsGlobal;
|
||||||
@@ -58,7 +58,7 @@ export default function detectPackage ({ name, version }: PackageJson, path?: st
|
|||||||
|
|
||||||
assert(name.startsWith('@polkadot'), `Invalid package descriptor ${name}`);
|
assert(name.startsWith('@polkadot'), `Invalid package descriptor ${name}`);
|
||||||
|
|
||||||
_global.__polkadotjs[name] = [...(_global.__polkadotjs[name] || []), { path, version }];
|
_global.__polkadotjs[name] = [...(_global.__polkadotjs[name] || []), { path: path || '', version }];
|
||||||
|
|
||||||
if (_global.__polkadotjs[name].length !== 1) {
|
if (_global.__polkadotjs[name].length !== 1) {
|
||||||
const versions = flattenVersions(_global.__polkadotjs[name]);
|
const versions = flattenVersions(_global.__polkadotjs[name]);
|
||||||
|
|||||||
Reference in New Issue
Block a user