Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04a28967c7 | ||
|
|
47c831d672 | ||
|
|
3c4c2cf540 | ||
|
|
f383487764 | ||
|
|
d900dec667 | ||
|
|
49d200fb85 | ||
|
|
2f9d117cc6 | ||
|
|
ef44de3ebe | ||
|
|
76d03bb504 | ||
|
|
b58543237f | ||
|
|
4859157264 | ||
|
|
a5f3ce20ae | ||
|
|
14fe54d2af | ||
|
|
f2d611e26d | ||
|
|
700774b207 | ||
|
|
770446c052 | ||
|
|
f576b99c5c | ||
|
|
678e888a4a | ||
|
|
3335215866 | ||
|
|
d4a64e7a5a | ||
|
|
d778157d5a | ||
|
|
3d0f6dafa5 | ||
|
|
374a6ba5d6 | ||
|
|
eee6160060 | ||
|
|
5202b3febb | ||
|
|
a0d48fdb48 |
@@ -2,7 +2,7 @@ name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '6 1/5 * * *'
|
||||
- cron: '30 1/2 * * *'
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
|
||||
@@ -7,7 +7,7 @@ on:
|
||||
|
||||
jobs:
|
||||
check:
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.issue.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 'Close stale issues and PRs'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '2 2 * * *'
|
||||
- cron: '30 2/2 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
build
|
||||
coverage
|
||||
packages
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/dev authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = require('@polkadot/dev/config/prettier.cjs');
|
||||
@@ -1,5 +1,27 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 6.9.1 Jun 19, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Added `u8aCmp(a, b)` to do sorting compares
|
||||
- Added `arrayRange(size, startAt = 0)` to create a range of numbers
|
||||
- Added extensive mnemonic compare test (optional, skipped)
|
||||
|
||||
|
||||
## 6.8.1 Jun 14, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add Ledger support for Edgeware (Thanks to https://github.com/raykyri)
|
||||
- Fix `naclSeal` doc types (Thanks to https://github.com/agustinustheo)
|
||||
|
||||
Changes:
|
||||
|
||||
- Export `BN` in `@polkadot/util`
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
|
||||
|
||||
## 6.7.1 Jun 6, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
+6
-5
@@ -17,14 +17,15 @@
|
||||
"networks:crosscheck": "polkadot-dev-run-test packages/networks/src/crosscheck",
|
||||
"networks:sync": "node packages/networks/scripts/fromSubstrate.mjs",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck",
|
||||
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck --testPathIgnorePatterns toMiniSecretCmp",
|
||||
"test:mnemonicCmp": "polkadot-dev-run-test packages/util-crypto/src/mnemonic/toMiniSecretCmp.spec.ts",
|
||||
"test:one": "polkadot-dev-run-test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.14.3",
|
||||
"@polkadot/dev": "^0.62.38",
|
||||
"@polkadot/ts": "^0.3.86",
|
||||
"@babel/core": "^7.14.5",
|
||||
"@polkadot/dev": "^0.62.42",
|
||||
"@polkadot/ts": "^0.3.90",
|
||||
"@types/jest": "^26.0.23"
|
||||
},
|
||||
"version": "6.7.1"
|
||||
"version": "6.9.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/hw-ledger-transports",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
@@ -15,7 +15,7 @@
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@ledgerhq/hw-transport-webhid": "^5.51.1",
|
||||
"@ledgerhq/hw-transport-webusb": "^5.53.1"
|
||||
},
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/hw-ledger",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"repository": "github:polkadot-js/common",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
@@ -16,9 +16,9 @@
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/hw-ledger-transports": "6.7.1",
|
||||
"@polkadot/util": "^6.7.1",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/hw-ledger-transports": "6.9.1",
|
||||
"@polkadot/util": "^6.9.1",
|
||||
"@zondax/ledger-polkadot": "^0.14.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
import type Transport from '@ledgerhq/hw-transport';
|
||||
import type { SubstrateApp } from '@zondax/ledger-polkadot';
|
||||
|
||||
import { newDockApp, newEquilibriumApp, newKusamaApp, newPolkadotApp, newPolymeshApp } from '@zondax/ledger-polkadot';
|
||||
import { newDockApp, newEdgewareApp, newEquilibriumApp, newKusamaApp, newPolkadotApp, newPolymeshApp } from '@zondax/ledger-polkadot';
|
||||
|
||||
// These match up with the network keys in the @polkadot/networks package
|
||||
// (which is turn aligns with the substrate/ss58-registry.json as the single
|
||||
// source of truth)
|
||||
export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp> = {
|
||||
'dock-mainnet': newDockApp,
|
||||
edgeware: newEdgewareApp,
|
||||
equilibrium: newEquilibriumApp,
|
||||
kusama: newKusamaApp,
|
||||
polkadot: newPolkadotApp,
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/keyring",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "Keyring management",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
@@ -19,12 +19,12 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/util": "6.7.1",
|
||||
"@polkadot/util-crypto": "6.7.1"
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/util": "6.9.1",
|
||||
"@polkadot/util-crypto": "6.9.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "6.7.1",
|
||||
"@polkadot/util-crypto": "6.7.1"
|
||||
"@polkadot/util": "6.9.1",
|
||||
"@polkadot/util-crypto": "6.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/networks",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A list of all available Substrate networks and their applicable prefixes",
|
||||
"main": "index.js",
|
||||
@@ -16,10 +16,10 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/networks#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0"
|
||||
"@babel/runtime": "^7.14.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "6.7.1",
|
||||
"@polkadot/x-fetch": "6.7.1"
|
||||
"@polkadot/util": "6.9.1",
|
||||
"@polkadot/x-fetch": "6.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isHex } from '@polkadot/util';
|
||||
|
||||
import { knownGenesis, knownLedger } from './defaults';
|
||||
|
||||
describe('defaults', (): void => {
|
||||
it('has hex values for all genesis chains', (): void => {
|
||||
expect(
|
||||
Object.keys(knownGenesis).filter((network) =>
|
||||
!knownGenesis[network].length ||
|
||||
knownGenesis[network].some((g) => !isHex(g, 256))
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('has genesis for all Ledger chains', (): void => {
|
||||
expect(
|
||||
Object.keys(knownLedger).filter((network) =>
|
||||
|
||||
@@ -54,6 +54,7 @@ export const knownIcon: KnownIcon = {
|
||||
// support for ledger
|
||||
export const knownLedger: KnownLedger = {
|
||||
'dock-mainnet': 0x00000252,
|
||||
edgeware: 0x0000020b,
|
||||
equilibrium: 0x05f5e0fd,
|
||||
kusama: 0x000001b2,
|
||||
polkadot: 0x00000162,
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '6.9.1' };
|
||||
|
||||
@@ -515,6 +515,24 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
symbols: ['NET'],
|
||||
website: 'https://social.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Moonbeam',
|
||||
network: 'moonbeam',
|
||||
prefix: 1284,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['GLMR'],
|
||||
website: 'https://moonbeam.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Moonriver',
|
||||
network: 'moonriver',
|
||||
prefix: 1285,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['MOVR'],
|
||||
website: 'https://moonbeam.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Basilisk',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-crypto",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A collection of useful crypto utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
@@ -19,11 +19,11 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/networks": "6.7.1",
|
||||
"@polkadot/util": "6.7.1",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/networks": "6.9.1",
|
||||
"@polkadot/util": "6.9.1",
|
||||
"@polkadot/wasm-crypto": "^4.0.2",
|
||||
"@polkadot/x-randomvalues": "6.7.1",
|
||||
"@polkadot/x-randomvalues": "6.9.1",
|
||||
"base-x": "^3.0.8",
|
||||
"base64-js": "^1.5.1",
|
||||
"blakejs": "^1.1.0",
|
||||
@@ -44,6 +44,6 @@
|
||||
"@types/xxhashjs": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "6.7.1"
|
||||
"@polkadot/util": "6.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { Prefix } from './types';
|
||||
|
||||
import { decodeAddress } from './decode';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { Prefix } from './types';
|
||||
|
||||
import { encodeAddress } from './encode';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
import { bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
import { bnToU8a, compactToU8a, stringToU8a, u8aConcat, u8aSorted } from '@polkadot/util';
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
|
||||
import { bnToHex, compactAddLength, hexToU8a, isBigInt, isBn, isHex, isNumber, isString, stringToU8a } from '@polkadot/util';
|
||||
import { BN, bnToHex, compactAddLength, hexToU8a, isBigInt, isBn, isHex, isNumber, isString, stringToU8a } from '@polkadot/util';
|
||||
|
||||
import { blake2AsU8a } from '../blake2/asU8a';
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { arrayRange, u8aEq } from '@polkadot/util';
|
||||
|
||||
import { cryptoWaitReady, mnemonicGenerate, mnemonicToMiniSecret, naclKeypairFromSeed, schnorrkelKeypairFromSeed } from '..';
|
||||
|
||||
// NOTE: This basically controls how long stuff runs for, YMMV
|
||||
//
|
||||
// - 100 runs with 5 checks, takes 2mins on _my_ machine
|
||||
// - 10_000 runs with 5 checks should be ~3hrs
|
||||
const NUM_RUNS = 100;
|
||||
const NUM_CHECKS = 5;
|
||||
|
||||
// generate either a JS or WASM mnemonic
|
||||
describe.each([true, false])('mnemonicToMiniSecret (compare), onlyJsMnemonic=%p', (onlyJsMnemonic): void => {
|
||||
beforeAll(async (): Promise<void> => {
|
||||
await cryptoWaitReady();
|
||||
});
|
||||
|
||||
// loop through lots of mnemonics
|
||||
describe.each(arrayRange(NUM_RUNS))('run=%p', (): void => {
|
||||
// compare both JS and WASM outputs against original
|
||||
describe.each([true, false])('onlyJsMini=%p', (onlyJsMini): void => {
|
||||
// NOTE we cannot actually use the onlyJsMnemonic flag here
|
||||
const mnemonic = mnemonicGenerate(12);
|
||||
|
||||
describe(mnemonic, (): void => {
|
||||
// do iterations to check and re-check that all matches
|
||||
it.concurrent.each(arrayRange(NUM_CHECKS))('check=%p', (count): void => {
|
||||
const minisecret = mnemonicToMiniSecret(mnemonic, count ? `${count}` : '', onlyJsMnemonic);
|
||||
const edpub = naclKeypairFromSeed(minisecret).publicKey;
|
||||
const srpub = schnorrkelKeypairFromSeed(minisecret).publicKey;
|
||||
|
||||
const testmini = mnemonicToMiniSecret(mnemonic, count ? `${count}` : '', onlyJsMini);
|
||||
|
||||
// explicit minisecret compare
|
||||
expect(
|
||||
u8aEq(minisecret, testmini)
|
||||
).toEqual(true);
|
||||
|
||||
// compare the sr25519 keypair generated
|
||||
expect(
|
||||
u8aEq(srpub, schnorrkelKeypairFromSeed(testmini).publicKey)
|
||||
).toEqual(true);
|
||||
|
||||
// compare ed both in WASM and JS
|
||||
[true, false].forEach((onlyJsEd): void => {
|
||||
expect(
|
||||
u8aEq(edpub, naclKeypairFromSeed(testmini, onlyJsEd).publicKey)
|
||||
).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -31,8 +31,10 @@ describe('naclKeypairFromSeed', (): void => {
|
||||
});
|
||||
|
||||
it('generates a valid publicKey/secretKey pair (u8a)', (): void => {
|
||||
expect(
|
||||
naclKeypairFromSeed(TEST)
|
||||
).toEqual(RESULT);
|
||||
[true, false].forEach((onlyJs): void => {
|
||||
expect(
|
||||
naclKeypairFromSeed(TEST, onlyJs)
|
||||
).toEqual(RESULT);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,8 +21,8 @@ import { ed25519KeypairFromSeed, isReady } from '@polkadot/wasm-crypto';
|
||||
* naclKeypairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
|
||||
* ```
|
||||
*/
|
||||
export function naclKeypairFromSeed (seed: Uint8Array): Keypair {
|
||||
if (isReady()) {
|
||||
export function naclKeypairFromSeed (seed: Uint8Array, onlyJs = false): Keypair {
|
||||
if (!onlyJs && isReady()) {
|
||||
const full = ed25519KeypairFromSeed(seed);
|
||||
|
||||
return {
|
||||
|
||||
@@ -19,7 +19,7 @@ interface Sealed {
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { naclEncrypt } from '@polkadot/util-crypto';
|
||||
* import { naclSeal } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclSeal([...], [...], [...], [...]); // => [...]
|
||||
* ```
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '6.9.1' };
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { hexToBn } from '@polkadot/util';
|
||||
import { BN, hexToBn } from '@polkadot/util';
|
||||
|
||||
import { randomAsHex } from './asHex';
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { assert, bnToU8a, isU8a } from '@polkadot/util';
|
||||
import { assert, BN, bnToU8a, isU8a } from '@polkadot/util';
|
||||
|
||||
import { secp256k1 } from './secp256k1';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BN } from '@polkadot/util';
|
||||
|
||||
import xxhash64AsRaw from './asRaw';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A collection of useful utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
@@ -19,9 +19,9 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/x-textdecoder": "6.7.1",
|
||||
"@polkadot/x-textencoder": "6.7.1",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/x-textdecoder": "6.9.1",
|
||||
"@polkadot/x-textencoder": "6.9.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.11.9",
|
||||
"camelcase": "^5.3.1",
|
||||
|
||||
@@ -8,3 +8,4 @@
|
||||
export { arrayChunk } from './chunk';
|
||||
export { arrayFilter } from './filter';
|
||||
export { arrayFlatten } from './flatten';
|
||||
export { arrayRange } from './range';
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { arrayRange } from '.';
|
||||
|
||||
describe('arrayRange', (): void => {
|
||||
it('does not allow 0 values', (): void => {
|
||||
expect(
|
||||
() => arrayRange(0)
|
||||
).toThrow(/Expected non-zero, positive number as a range size/);
|
||||
});
|
||||
|
||||
it('it creates a range of the specified length', (): void => {
|
||||
expect(
|
||||
arrayRange(10)
|
||||
).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
});
|
||||
|
||||
it('it creates a range of the specified length, with offset', (): void => {
|
||||
expect(
|
||||
arrayRange(7, 3)
|
||||
).toEqual([3, 4, 5, 6, 7, 8, 9]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert } from '../assert';
|
||||
|
||||
/**
|
||||
* @name arrayRange
|
||||
* @summary Returns a range of numbers ith the size and the specified offset
|
||||
* @description
|
||||
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayRange } from '@polkadot/util';
|
||||
*
|
||||
* arrayRange(5); // [0, 1, 2, 3, 4]
|
||||
* arrayRange(3, 5); // [5, 6, 7]
|
||||
* ```
|
||||
*/
|
||||
export function arrayRange (size: number, startAt = 0): number[] {
|
||||
assert(size > 0, 'Expected non-zero, positive number as a range size');
|
||||
|
||||
return new Array(size).fill(0).map((_, i) => i + startAt);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
export { BN };
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN_HUNDRED, BN_ONE, BN_TEN, BN_THOUSAND, BN_ZERO } from '.';
|
||||
import { BN, BN_HUNDRED, BN_ONE, BN_TEN, BN_THOUSAND, BN_ZERO } from '.';
|
||||
|
||||
describe('consts', (): void => {
|
||||
it('BN_ZERO equals 0', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BN } from './bn';
|
||||
|
||||
/**
|
||||
* @name BN_ZERO
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
export * from './consts';
|
||||
|
||||
export { BN } from './bn';
|
||||
export { bnFromHex } from './fromHex';
|
||||
export { bnMax } from './max';
|
||||
export { bnMin } from './min';
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnMax } from '.';
|
||||
import { BN, bnMax } from '.';
|
||||
|
||||
describe('bnMax', (): void => {
|
||||
it('finds BN maximum', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { checkMaxMin } from './util';
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnMin } from '.';
|
||||
import { BN, bnMin } from '.';
|
||||
|
||||
describe('bnMin', (): void => {
|
||||
it('finds BN minimum', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { checkMaxMin } from './util';
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnSqrt } from '.';
|
||||
import { BN, bnSqrt } from '.';
|
||||
|
||||
const TESTS: [string | number | BN | BigInt, string | number][] = [
|
||||
[0, 0],
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
import type { ToBn } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { assert } from '../assert';
|
||||
import { BN_MAX_INTEGER, BN_ONE, BN_ZERO } from '../bn';
|
||||
import { BN } from './bn';
|
||||
import { BN_MAX_INTEGER, BN_ONE, BN_ZERO } from './consts';
|
||||
import { bnToBn } from './toBn';
|
||||
|
||||
const SQRT_MAX_SAFE_INTEGER = new BN(94906265);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnToBn } from '.';
|
||||
import { BN, bnToBn } from '.';
|
||||
|
||||
describe('bnToBn', (): void => {
|
||||
it('converts null values to 0x00', (): void => {
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
|
||||
import type { ToBn } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { hexToBn } from '../hex/toBn';
|
||||
import { isBigInt } from '../is/bigInt';
|
||||
import { isHex } from '../is/hex';
|
||||
import { isToBn } from '../is/toBn';
|
||||
import { BN } from './bn';
|
||||
|
||||
/**
|
||||
* @name bnToBn
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnToHex } from '.';
|
||||
import { BN, bnToHex } from '.';
|
||||
|
||||
describe('bnToHex', (): void => {
|
||||
it('converts null values to 0x00', (): void => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { ToBn, ToBnOptions } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
import { u8aToHex } from '../u8a';
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnToU8a } from '.';
|
||||
import { BN, bnToU8a } from '.';
|
||||
|
||||
describe('bnToU8a', (): void => {
|
||||
it('converts null values to 0x00', (): void => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { ToBn, ToBnOptions } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
import { bnToBn } from './toBn';
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { assert } from '../assert';
|
||||
import { BN } from './bn';
|
||||
|
||||
export function checkMaxMin (type: 'max' | 'min', items: BN[]): BN {
|
||||
assert(items.length >= 1, 'Must provide one or more BN arguments');
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn/bn';
|
||||
import { hexToU8a } from '../hex/toU8a';
|
||||
import { compactFromU8a } from '.';
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN_FOUR } from '../bn';
|
||||
import { BN, BN_FOUR } from '../bn';
|
||||
import { u8aToBn, u8aToU8a } from '../u8a';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { compactToU8a } from '.';
|
||||
|
||||
describe('encode', (): void => {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { assert } from '../assert';
|
||||
import { BN_ONE, BN_TWO, bnToBn, bnToU8a } from '../bn';
|
||||
import { BN, BN_ONE, BN_TWO, bnToBn, bnToU8a } from '../bn';
|
||||
import { u8aConcat } from '../u8a';
|
||||
|
||||
const MAX_U8 = new BN(2).pow(new BN(8 - 2)).subn(1);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { formatBalance } from '.';
|
||||
|
||||
describe('formatBalance', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { SiDef, ToBn } from '../types';
|
||||
|
||||
import { bnToBn } from '../bn/toBn';
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { formatElapsed } from '.';
|
||||
|
||||
describe('formatElapsed', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/ui-util authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { ToBn } from '../types';
|
||||
|
||||
import { bnToBn } from '../bn/toBn';
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { formatNumber } from '.';
|
||||
|
||||
describe('formatNumber', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { ToBn } from '../types';
|
||||
|
||||
import { bnToBn } from '../bn/toBn';
|
||||
|
||||
@@ -6,7 +6,7 @@ import { hexToBn } from '.';
|
||||
describe('hexToBn', (): void => {
|
||||
it('converts prefixed hex values to BN', (): void => {
|
||||
expect(
|
||||
hexToBn(0x81).toString(16)
|
||||
hexToBn('0x81').toString(16)
|
||||
).toBe('81');
|
||||
});
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { ToBnOptions } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn/bn';
|
||||
import { isBoolean } from '../is/boolean';
|
||||
import { hexStripPrefix } from './stripPrefix';
|
||||
|
||||
@@ -32,7 +31,7 @@ function reverse (value: string): string {
|
||||
* hexToBn('0x123480001f'); // => BN(0x123480001f)
|
||||
* ```
|
||||
*/
|
||||
export function hexToBn (value?: string | number | null, options: ToBnOptions | boolean = { isLe: false, isNegative: false }): BN {
|
||||
export function hexToBn (value?: string | null, options: ToBnOptions | boolean = { isLe: false, isNegative: false }): BN {
|
||||
if (!value) {
|
||||
return new BN(0);
|
||||
}
|
||||
@@ -41,9 +40,13 @@ export function hexToBn (value?: string | number | null, options: ToBnOptions |
|
||||
isLe: false,
|
||||
isNegative: false,
|
||||
// Backwards-compatibility
|
||||
...(isBoolean(options) ? { isLe: options } : options)
|
||||
...(
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
: options
|
||||
)
|
||||
};
|
||||
const _value = hexStripPrefix(value as string);
|
||||
const _value = hexStripPrefix(value);
|
||||
|
||||
// FIXME: Use BN's 3rd argument `isLe` once this issue is fixed
|
||||
// https://github.com/indutny/bn.js/issues/208
|
||||
@@ -51,5 +54,7 @@ export function hexToBn (value?: string | number | null, options: ToBnOptions |
|
||||
|
||||
// fromTwos takes as parameter the number of bits, which is the hex length
|
||||
// multiplied by 4.
|
||||
return _options.isNegative ? bn.fromTwos(_value.length * 4) : bn;
|
||||
return _options.isNegative
|
||||
? bn.fromTwos(_value.length * 4)
|
||||
: bn;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { isBn } from '.';
|
||||
|
||||
describe('isBN', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BN } from '../bn/bn';
|
||||
|
||||
/**
|
||||
* @name isBn
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { isChildClass } from '.';
|
||||
|
||||
describe('isChildClass', (): void => {
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Logger } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from './bn';
|
||||
import { logger, loggerFormat } from '.';
|
||||
|
||||
describe('logger', (): void => {
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/util', version: '6.9.1' };
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN } from './bn';
|
||||
import { stringify } from './stringify';
|
||||
|
||||
describe('stringify', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from './bn/bn';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export interface Constructor<T = any> {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aCmp } from '.';
|
||||
|
||||
describe('u8aCmp', (): void => {
|
||||
it('has the same result as localCompare (equal length)', (): void => {
|
||||
const a = 'test abc';
|
||||
const b = 'test def';
|
||||
|
||||
expect(
|
||||
u8aCmp(a, b)
|
||||
).toEqual(a.localeCompare(b));
|
||||
expect(
|
||||
u8aCmp(b, a)
|
||||
).toEqual(b.localeCompare(a));
|
||||
});
|
||||
|
||||
it('has the same result as localCompare (diff length)', (): void => {
|
||||
const a = 'test';
|
||||
const b = 'test abc';
|
||||
|
||||
expect(
|
||||
u8aCmp(a, b)
|
||||
).toEqual(a.localeCompare(b));
|
||||
expect(
|
||||
u8aCmp(b, a)
|
||||
).toEqual(b.localeCompare(a));
|
||||
});
|
||||
|
||||
it('compares between string and Uint8Array', (): void => {
|
||||
expect(
|
||||
u8aCmp(
|
||||
'0x12345678',
|
||||
new Uint8Array([0x12, 0x34, 0x56, 0x78])
|
||||
)
|
||||
).toEqual(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aToU8a } from './toU8a';
|
||||
|
||||
function compare (a: Uint8Array, b: Uint8Array): number {
|
||||
let i = 0;
|
||||
|
||||
while (true) {
|
||||
const overA = i >= a.length;
|
||||
const overB = i >= b.length;
|
||||
|
||||
if (overA && overB) {
|
||||
// both ends reached
|
||||
return 0;
|
||||
} else if (overA) {
|
||||
// a has no more data, b has data
|
||||
return -1;
|
||||
} else if (overB) {
|
||||
// b has no more data, a has data
|
||||
return 1;
|
||||
} else if (a[i] !== b[i]) {
|
||||
// the number in this index doesn't match
|
||||
return a[i] > b[i]
|
||||
? 1
|
||||
: -1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name u8aCmp
|
||||
* @summary Compares two Uint8Arrays for sorting.
|
||||
* @description
|
||||
* For `UInt8Array` (or hex string) input values returning -1, 0 or +1
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { u8aCmp } from '@polkadot/util';
|
||||
*
|
||||
* u8aCmp(new Uint8Array([0x67, 0x65]), new Uint8Array([0x68, 0x65])); // -1
|
||||
* u8aCmp(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // 0
|
||||
* u8aCmp(new Uint8Array([0x69, 0x65]), new Uint8Array([0x68, 0x65])); // +1
|
||||
* ```
|
||||
*/
|
||||
export function u8aCmp (a: Uint8Array | string, b: Uint8Array | string): number {
|
||||
return compare(u8aToU8a(a), u8aToU8a(b));
|
||||
}
|
||||
@@ -1,32 +1,23 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aCmp } from './cmp';
|
||||
import { u8aToU8a } from './toU8a';
|
||||
|
||||
function equals (a: Uint8Array, b: Uint8Array): boolean {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return (a.length === b.length) && (u8aCmp(a, b) === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name u8aEq
|
||||
* @summary Compares two Uint8Arrays.
|
||||
* @summary Compares two Uint8Arrays for equality.
|
||||
* @description
|
||||
* For `UInt8Array` (or hex string) input values true if there is a match.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { { u8aEq } from '@polkadot/util';
|
||||
* import { u8aEq } from '@polkadot/util';
|
||||
*
|
||||
* u8aEq(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // true
|
||||
* ```
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* @summary Utility methods to convert to and from `Uint8Array` objects
|
||||
*/
|
||||
|
||||
export { u8aCmp } from './cmp';
|
||||
export { u8aConcat } from './concat';
|
||||
export { u8aEq } from './eq';
|
||||
export { u8aFixLength } from './fixLength';
|
||||
|
||||
@@ -1,28 +1,22 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isUndefined } from '../is/undefined';
|
||||
import { u8aCmp } from './cmp';
|
||||
|
||||
/**
|
||||
* @name u8aSorted
|
||||
* @summary Sorts an array of Uint8Arrays
|
||||
* @description
|
||||
* For input `UInt8Array[]` return the sorted result
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { u8aSorted} from '@polkadot/util';
|
||||
*
|
||||
* u8aSorted([new Uint8Array([0x69]), new Uint8Array([0x68])]); // [0x68, 0x69]
|
||||
* ```
|
||||
*/
|
||||
export function u8aSorted (u8as: Uint8Array[]): Uint8Array[] {
|
||||
return u8as.sort((a, b): number => {
|
||||
let i = 0;
|
||||
|
||||
while (true) {
|
||||
if (isUndefined(a[i]) && isUndefined(b[i])) {
|
||||
return 0;
|
||||
} else if (isUndefined(a[i])) {
|
||||
return -1;
|
||||
} else if (isUndefined(b[i])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const cmp = a[i] - b[i];
|
||||
|
||||
if (cmp !== 0) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
});
|
||||
return u8as.sort(u8aCmp);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { ToBnOptions } from '../types';
|
||||
|
||||
import { hexToBn } from '../hex/toBn';
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const ALPHABET = new Array(256).fill(0).map((_, n) => n.toString(16).padStart(2, '0'));
|
||||
import { arrayRange } from '../array';
|
||||
|
||||
const ALPHABET = arrayRange(256).map((n) => n.toString(16).padStart(2, '0'));
|
||||
|
||||
/** @internal */
|
||||
function extract (value: Uint8Array): string {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-fetch",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A cross-environment fetch replacement",
|
||||
"browser": "browser.js",
|
||||
@@ -18,8 +18,8 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-fetch#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/x-global": "6.7.1",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/x-global": "6.9.1",
|
||||
"@types/node-fetch": "^2.5.10",
|
||||
"node-fetch": "^2.6.1"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-global",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A cross-environment global replacement",
|
||||
"main": "index.js",
|
||||
@@ -16,7 +16,7 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-global#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@types/node-fetch": "^2.5.10",
|
||||
"node-fetch": "^2.6.1"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-global', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-global', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-randomvalues",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A cross-environment window.crypto.getRandomValues replacement",
|
||||
"browser": "browser.js",
|
||||
@@ -18,8 +18,8 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-randomvalues#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/x-global": "6.7.1"
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/x-global": "6.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-native": "^0.64.10"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-rxjs",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A pass-through interface for RxJs (allowing node + mjs usage)",
|
||||
"main": "index.js",
|
||||
@@ -16,7 +16,7 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-rxjs#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"rxjs": "^6.6.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-rxjs', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-rxjs', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-textdecoder",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A TextDecoder replacement",
|
||||
"browser": "browser.js",
|
||||
@@ -18,7 +18,7 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-textdecoder#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/x-global": "6.7.1"
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/x-global": "6.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-textencoder",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A TextDecoder replacement",
|
||||
"browser": "browser.js",
|
||||
@@ -18,7 +18,7 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-textencoder#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/x-global": "6.7.1"
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/x-global": "6.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', version: '6.9.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/x-ws",
|
||||
"version": "6.7.1",
|
||||
"version": "6.9.1",
|
||||
"type": "module",
|
||||
"description": "A cross-environment WebSocket replacement",
|
||||
"browser": "browser.js",
|
||||
@@ -18,8 +18,8 @@
|
||||
"bugs": "https://github.com/polkadot-js/common/issues",
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-ws#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/x-global": "6.7.1",
|
||||
"@babel/runtime": "^7.14.5",
|
||||
"@polkadot/x-global": "6.9.1",
|
||||
"@types/websocket": "^1.0.2",
|
||||
"websocket": "^1.0.34"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-ws', version: '6.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-ws', version: '6.9.1' };
|
||||
|
||||
Reference in New Issue
Block a user