Compare commits

..
81 Commits
Author SHA1 Message Date
Github Actions 83975e9235 [CI Skip] release/stable 5.2.1
skip-checks: true
2020-12-27 07:44:02 +00:00
Jaco Greeff 3adf475ef4 5.2 (#821)
* 5.2

* Bump
2020-12-27 08:39:14 +01:00
Github Actions ccc6edebbb [CI Skip] release/beta 5.1.2-3
skip-checks: true
2020-12-25 08:58:15 +00:00
Jaco Greeff 0d7ed7420d Add keccak512 (#820)
* Add keccak512

* dedupe

* Adjust hex test

* ss58

* fix expectation
2020-12-25 09:52:49 +01:00
Github Actions dbf1837b97 [CI Skip] release/beta 5.1.2-2
skip-checks: true
2020-12-24 07:56:46 +00:00
Jaco Greeff 9ae738ac51 Add Valiu (#818) 2020-12-24 08:51:22 +01:00
Github Actions a4000efc43 [CI Skip] release/beta 5.1.2-1
skip-checks: true
2020-12-23 11:03:53 +00:00
Jaco Greeff 7871a17942 Add arrayFlatten (#816)
* Add arrayFlatten

* Add test for arrayFlatten

* Add arrayChunk

* Update packages/util/src/array/chunk.ts
2020-12-23 11:58:59 +01:00
Github Actions 5aad1d09b2 [CI Skip] release/beta 5.1.2-0
skip-checks: true
2020-12-22 09:22:25 +00:00
Jaco Greeff 4eb5d7dfd3 Bump deps (#815)
* Bump deps

* Rewrite
2020-12-22 10:16:34 +01:00
Github Actions 0a841e8f4a [CI Skip] release/stable 5.1.1
skip-checks: true
2020-12-19 14:23:05 +00:00
Jaco Greeff 53ffd0c9f0 5.1 (#813) 2020-12-19 15:17:01 +01:00
Github Actions 5d3a9f2e2e [CI Skip] release/beta 5.0.2-9
skip-checks: true
2020-12-19 10:41:44 +00:00
Jaco Greeff 9d6f38edb3 Bump deps 2020-12-19 11:36:55 +01:00
Github Actions 9e5e032e1d [CI Skip] release/beta 5.0.2-8
skip-checks: true
2020-12-18 10:24:04 +00:00
Jaco Greeff 31426858c6 detectPackage import revert 2020-12-18 11:18:02 +01:00
Github Actions 46b4ca0c91 [CI Skip] release/beta 5.0.2-7
skip-checks: true
2020-12-17 13:02:30 +00:00
Jaco Greeff f4cb68c567 Mark detectPackage as sideEffect 2020-12-17 13:57:41 +01:00
Github Actions ab4b234510 [CI Skip] release/beta 5.0.2-6
skip-checks: true
2020-12-17 12:19:30 +00:00
Jaco Greeff d5151c4f01 Adjust detectPackage 2020-12-17 13:14:38 +01:00
Jaco Greeff 6df4689aa3 Cleanup detectPackage 2020-12-17 13:05:26 +01:00
Github Actions 9727a6a9a5 [CI Skip] release/beta 5.0.2-5
skip-checks: true
2020-12-17 11:42:14 +00:00
Jaco Greeff 7f00182fd9 Bump wasm-crypto 2020-12-17 12:37:21 +01:00
Github Actions 261b0add27 [CI Skip] release/beta 5.0.2-4
skip-checks: true
2020-12-17 11:25:06 +00:00
Jaco Greeff 5d6e753384 sideEffects 2020-12-17 12:20:15 +01:00
Github Actions 15c2e79e6e [CI Skip] release/beta 5.0.2-3
skip-checks: true
2020-12-17 11:12:29 +00:00
Jaco Greeff f763a66219 Allow detectPackage with a function (#811) 2020-12-17 12:07:00 +01:00
Jaco Greeff 1061df6e4a Adjust blakejs commonjs imports (#809) 2020-12-17 12:03:21 +01:00
Github Actions 4c121e6f50 [CI Skip] release/beta 5.0.2-2
skip-checks: true
2020-12-17 10:52:01 +00:00
Jaco Greeff 74b3a04c4a Dedupe 2020-12-17 11:46:57 +01:00
Github Actions e4488463ba [CI Skip] release/beta 5.0.2-1
skip-checks: true
2020-12-16 14:48:44 +00:00
Jaco Greeff c6fd67b5d5 detectPackage with import.meta.url (#810)
* detectPackage with import.meta.url

* Bump dev

* Remove duplicate detectPackage

* Fix detectPackage import
2020-12-16 15:44:00 +01:00
Github Actions e5dc596867 [CI Skip] release/beta 5.0.2-0
skip-checks: true
2020-12-15 14:54:43 +00:00
Jaco Greeff a28f8dad37 detectPackage cleanups (#807) 2020-12-15 15:49:00 +01:00
Github Actions 7855658bfd [CI Skip] release/stable 5.0.1
skip-checks: true
2020-12-13 14:19:15 +00:00
Jaco Greeff de14a85817 5.0 (#800)
* 5.0

* Update CHANGELOG.md

* CHANGELOG
2020-12-13 15:13:40 +01:00
Github Actions de2206bb27 [CI Skip] release/beta 4.2.2-21
skip-checks: true
2020-12-13 12:50:35 +00:00
Jaco Greeff 451a7aecde Adjust memoize normalize for BigInt (#806)
* Adjust memoize normalizer to cater for BigInt

* Update memomize typings

* cleanups

* Renames
2020-12-13 13:46:22 +01:00
Github Actions 5170194105 [CI Skip] release/beta 4.2.2-20
skip-checks: true
2020-12-13 12:11:48 +00:00
Jaco Greeff b2286ac06a Add memoize util (#805)
* Add memoize util

* Allow for instanceId & normalize overrides

* memoize tests
2020-12-13 13:05:58 +01:00
Github Actions 57cc6d6d46 [CI Skip] release/beta 4.2.2-19
skip-checks: true
2020-12-13 09:40:57 +00:00
Jaco Greeff 6e1b5901b3 Update .123trigger 2020-12-13 10:36:28 +01:00
Github Actions 203db7467f [CI Skip] release/beta 4.2.2-18
skip-checks: true
2020-12-13 09:33:25 +00:00
Jaco Greeff aa7d4838c7 Bump wasm-crypto (#803) 2020-12-13 10:28:45 +01:00
Github Actions b778f606c5 [CI Skip] release/beta 4.2.2-17
skip-checks: true
2020-12-12 18:00:15 +00:00
Jaco Greeff 45146efce8 Limit logger size via DEBUG_MAX (#802)
* Limit logger size via DEBUG_MAX

* Any negative disables

* Node imports

* Update test
2020-12-12 18:54:31 +01:00
Github Actions 9229f9f295 [CI Skip] release/beta 4.2.2-16
skip-checks: true
2020-12-12 12:35:27 +00:00
Jaco Greeff 2e1c29a5a8 Bump wasm-crypto (#801) 2020-12-12 13:30:36 +01:00
Github Actions 79f925b589 [CI Skip] release/beta 4.2.2-15
skip-checks: true
2020-12-11 22:34:04 +00:00
Jaco Greeff 572c2789cc Bump dev 2020-12-11 23:28:34 +01:00
Github Actions 913f9636ba [CI Skip] release/beta 4.2.2-14
skip-checks: true
2020-12-11 16:42:05 +00:00
Jaco Greeff 83e5592305 Bump WASM, re-add tests 2020-12-11 17:39:58 +01:00
Github Actions b7e579f6b8 [CI Skip] release/beta 4.2.2-13
skip-checks: true
2020-12-11 16:21:40 +00:00
Jaco Greeff c211b811a6 Skip tests until wasm updated 2020-12-11 17:19:35 +01:00
Jaco Greeff 4c02b25a2d Small adjustments for esm (& default build) (#798) 2020-12-11 17:08:16 +01:00
Github Actions 28b2435019 [CI Skip] release/beta 4.2.2-12
skip-checks: true
2020-12-11 08:58:02 +00:00
Jaco Greeff a0e5d60a0a Bump dev 2020-12-11 09:53:45 +01:00
Github Actions 311eceec0d [CI Skip] release/beta 4.2.2-11
skip-checks: true
2020-12-10 16:24:24 +00:00
Jaco Greeff cf24dcdf22 Build esm alongside (unused, but published) (#797) 2020-12-10 17:19:19 +01:00
Github Actions ead3eceef4 [CI Skip] release/beta 4.2.2-10
skip-checks: true
2020-12-10 14:32:25 +00:00
Jaco Greeff 59df9aefc4 Bump wasm (#795)
* Bump wasm

* Bump wasm

* Bump

* Network kilt, etc.
2020-12-10 15:28:02 +01:00
Github Actions cb97cc1786 [CI Skip] release/beta 4.2.2-9
skip-checks: true
2020-12-09 18:19:43 +00:00
Jaco Greeff cf18ecf193 Bump dev (prefer esm in esm mode) (#794) 2020-12-09 19:14:26 +01:00
Github Actions 6e6b13f29a [CI Skip] release/beta 4.2.2-8
skip-checks: true
2020-12-09 16:42:57 +00:00
Jaco Greeff f75a16159d Bump dev (esm type import changes) (#793) 2020-12-09 17:37:15 +01:00
Github Actions b8fe6be9cc [CI Skip] release/beta 4.2.2-7
skip-checks: true
2020-12-09 15:37:44 +00:00
Jaco Greeff 9993325679 Bump WASM, allow esm alongside cjs (#792) 2020-12-09 16:32:12 +01:00
Github Actions ce8fe9f49d [CI Skip] release/beta 4.2.2-6
skip-checks: true
2020-12-09 10:07:34 +00:00
Jaco Greeff 408a6706b1 Adjust imports (#791) 2020-12-09 11:02:55 +01:00
Github Actions 79c7fa3b75 [CI Skip] release/beta 4.2.2-5
skip-checks: true
2020-12-08 10:30:14 +00:00
Jaco Greeff e9713b6c93 Remove --fix on CI (#790) 2020-12-08 11:25:28 +01:00
Github Actions 706a3e0cc2 [CI Skip] release/beta 4.2.2-4
skip-checks: true
2020-12-07 15:19:14 +00:00
Jaco Greeff b1a40516c1 Bump dev (import sorting) (#789) 2020-12-07 16:13:47 +01:00
Github Actions 7cf449074d [CI Skip] release/beta 4.2.2-3
skip-checks: true
2020-12-05 11:40:41 +00:00
Jaco Greeff 2ce7a79263 Bump deps (minor) (#786)
* Bump deps (minor)

* Update Phala
2020-12-05 12:35:10 +01:00
Github Actions cfa5660d54 [CI Skip] release/beta 4.2.2-2
skip-checks: true
2020-12-01 17:56:59 +00:00
Jaco Greeff 1256f2a54a Bump berry (#783)
* Bump berry

* rewrite
2020-12-01 18:33:29 +01:00
Github Actions 2695afa68e [CI Skip] release/beta 4.2.2-1
skip-checks: true
2020-12-01 12:29:57 +00:00
Jaco Greeff af71673c7b import type (#782) 2020-12-01 13:24:37 +01:00
Github Actions 7f489e1a99 [CI Skip] release/beta 4.2.2-0
skip-checks: true
2020-11-24 11:59:02 +00:00
Jaco Greeff 10fb33877c Bump deps (#779)
* Bump deps

* promisify
2020-11-24 12:53:12 +01:00
167 changed files with 1621 additions and 1216 deletions
+3 -2
View File
@@ -1,2 +1,3 @@
5
2.6.22.12.2
6
2.6.2
2.12.2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-55
View File
File diff suppressed because one or more lines are too long
+55
View File
File diff suppressed because one or more lines are too long
+1 -3
View File
@@ -9,7 +9,5 @@ plugins:
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
yarnPath: .yarn/releases/yarn-2.3.3.cjs
yarnPath: .yarn/releases/yarn-2.4.0.cjs
+37
View File
@@ -1,5 +1,42 @@
# CHANGELOG
## 5.2.1 Dec 27, 2020
Changes:
- Add `arrayFlatten` to merge a series of arrays into a single
- Add `arrayChunk` to chunk an array into multiples of defined size
- Add `bitLength` param (allowed 256, 512) to `keccakAs{Hex, U8a}`
- Align `@polkadot/networks` with Substrate master
## 5.1.1 Dec 19, 2020
Changes:
- `detectPackage` now can take a path-retrieval callback as second argument
- Adjust `blake2js` imports to consistently cater for esm & cjs usage
- Explicitly mark `detectPackage` usage as having side-effects
- Align `@polkadot/networks` with Substrate master
- `@polkadot/wasm-crypto` 3.1.1
## 5.0.1 Dec 13, 2020
**Important** While this package contains no external interface changes, it now compiles and ships both cjs and esm modules. This means that modern bundlers will have more information for tree-shaking available. Additionally when using Node with `.mjs` extensions, the esm version imports will be used on recent Node versions. Adding an export map, as here, may have some impacts so a major semver bump is advised. There may be (small) dragons hiding in the dark corners...
Changes:
- Build and expose both cjs and esm via exports map
- Use `import type { ... }` form for all type imports
- Align with Substrate master network list
- Debug logs now don't depend on `NODE_ENV`, but rather `DEBUG=<type,type,...>` (`*` logs all)
- Limit debug console output via `DEBUG_MAX=<number>` value, trimming when passed
- Add `memoize` util, allowing for function memoization (as used in the API)
- Align `@polkadot/networks` with Substrate master
- `@polkadot/wasm-crypto` 3.0.1
## 4.2.1 Nov 23, 2020
Changes:
+6 -6
View File
@@ -7,7 +7,7 @@
"packages/*"
],
"resolutions": {
"typescript": "^4.0.5"
"typescript": "^4.1.3"
},
"scripts": {
"build": "polkadot-dev-build-ts",
@@ -20,10 +20,10 @@
"test:one": "polkadot-dev-run-test"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@polkadot/dev": "^0.60.3",
"@polkadot/ts": "^0.3.55",
"@types/jest": "^26.0.15"
"@babel/core": "^7.12.10",
"@polkadot/dev": "^0.61.16",
"@polkadot/ts": "^0.3.58",
"@types/jest": "^26.0.19"
},
"version": "4.2.1"
"version": "5.2.1"
}
+9 -10
View File
@@ -1,28 +1,27 @@
{
"name": "@polkadot/keyring",
"version": "4.2.1",
"version": "5.2.1",
"description": "Keyring management",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"main": "index.js",
"sideEffects": false,
"keywords": [
"Polkadot",
"Keyring",
"ed25519"
"module": "index.mjs",
"sideEffects": [
"./detectPackage.js",
"./detectPackage.mjs"
],
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/util": "4.2.1",
"@polkadot/util-crypto": "4.2.1"
"@polkadot/util": "5.2.1",
"@polkadot/util-crypto": "5.2.1"
},
"peerDependencies": {
"@polkadot/util": "4.2.1",
"@polkadot/util-crypto": "4.2.1"
"@polkadot/util": "5.2.1",
"@polkadot/util-crypto": "5.2.1"
}
}
+20 -2
View File
@@ -1,7 +1,25 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
//
// new URL(import.meta.url).pathname)
//
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
// there is a complete dead end with usage thereof
//
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
//
// cjs: util.detectPackage(packageInfo, () => __dirname);
// esm: detectPackage(packageInfo, () => import.meta.url);
//
// With the above we additionally need a .d.ts to just export the packageInfo
import { detectPackage } from '@polkadot/util';
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
import packageInfo from './package-info.json';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
export { packageInfo };
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { hexToU8a, stringToU8a } from '@polkadot/util';
import { cryptoWaitReady, setSS58Format, encodeAddress } from '@polkadot/util-crypto';
import { cryptoWaitReady, encodeAddress, setSS58Format } from '@polkadot/util-crypto';
import Keyring from '.';
+3 -3
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeypairType, Keypair } from '@polkadot/util-crypto/types';
import { KeyringInstance, KeyringPair, KeyringPair$Json, KeyringPair$JsonEncodingTypes, KeyringPair$Meta, KeyringOptions } from './types';
import type { Keypair, KeypairType } from '@polkadot/util-crypto/types';
import type { KeyringInstance, KeyringOptions, KeyringPair, KeyringPair$Json, KeyringPair$JsonEncodingTypes, KeyringPair$Meta } from './types';
import { assert, hexToU8a, isHex, isUndefined, stringToU8a } from '@polkadot/util';
import { base64Decode, decodeAddress, encodeAddress, keyExtractSuri, keyFromPath, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, secp256k1KeypairFromSeed as secp256k1FromSeed, mnemonicToLegacySeed, mnemonicToMiniSecret } from '@polkadot/util-crypto';
import { base64Decode, decodeAddress, encodeAddress, keyExtractSuri, keyFromPath, mnemonicToLegacySeed, mnemonicToMiniSecret, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, secp256k1KeypairFromSeed as secp256k1FromSeed } from '@polkadot/util-crypto';
import { DEV_PHRASE } from './defaults';
import { createPair } from './pair';
+3 -3
View File
@@ -1,13 +1,13 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeyringPair$JsonEncodingTypes } from '../types';
import { PairInfo } from './types';
import type { KeyringPair$JsonEncodingTypes } from '../types';
import type { PairInfo } from './types';
import { assert, stringToU8a, u8aFixLength } from '@polkadot/util';
import { naclDecrypt, scryptEncode, scryptFromU8a } from '@polkadot/util-crypto';
import { ENCODING, NONCE_LENGTH, PKCS8_DIVIDER, PKCS8_HEADER, PUB_LENGTH, SEC_LENGTH, SEED_LENGTH, SCRYPT_LENGTH } from './defaults';
import { ENCODING, NONCE_LENGTH, PKCS8_DIVIDER, PKCS8_HEADER, PUB_LENGTH, SCRYPT_LENGTH, SEC_LENGTH, SEED_LENGTH } from './defaults';
const SEED_OFFSET = PKCS8_HEADER.length;
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeyringPair$JsonEncodingTypes } from '../types';
import type { KeyringPair$JsonEncodingTypes } from '../types';
const ENCODING: KeyringPair$JsonEncodingTypes[] = ['scrypt', 'xsalsa20-poly1305'];
const NONCE_LENGTH = 24;
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { createTestPairs } from '../testingPairs';
import { PKCS8_DIVIDER, PKCS8_HEADER, NONCE_LENGTH, PUB_LENGTH, SCRYPT_LENGTH, SEC_LENGTH } from './defaults';
import { NONCE_LENGTH, PKCS8_DIVIDER, PKCS8_HEADER, PUB_LENGTH, SCRYPT_LENGTH, SEC_LENGTH } from './defaults';
const PKCS8_LENGTH = PKCS8_DIVIDER.length + PKCS8_HEADER.length + PUB_LENGTH + SEC_LENGTH;
const ENCODED_LENGTH = 16 + PKCS8_LENGTH + NONCE_LENGTH + SCRYPT_LENGTH;
+2 -2
View File
@@ -1,9 +1,9 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { PairInfo } from './types';
import type { PairInfo } from './types';
import { u8aConcat, assert } from '@polkadot/util';
import { assert, u8aConcat } from '@polkadot/util';
import { naclEncrypt, scryptEncode, scryptToU8a } from '@polkadot/util-crypto';
import { PKCS8_DIVIDER, PKCS8_HEADER } from './defaults';
+1 -2
View File
@@ -1,9 +1,8 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { cryptoWaitReady, encodeAddress as toSS58, setSS58Format } from '@polkadot/util-crypto';
import { hexToU8a } from '@polkadot/util';
import { cryptoWaitReady, encodeAddress as toSS58, setSS58Format } from '@polkadot/util-crypto';
import { PAIRS } from '../testing';
import { createTestPairs } from '../testingPairs';
+4 -4
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair, KeypairType } from '@polkadot/util-crypto/types';
import { KeyringPair, KeyringPair$Json, KeyringPair$JsonEncodingTypes, KeyringPair$Meta, SignOptions } from '../types';
import { PairInfo } from './types';
import type { Keypair, KeypairType } from '@polkadot/util-crypto/types';
import type { KeyringPair, KeyringPair$Json, KeyringPair$JsonEncodingTypes, KeyringPair$Meta, SignOptions } from '../types';
import type { PairInfo } from './types';
import { assert, u8aConcat, u8aToHex } from '@polkadot/util';
import { blake2AsU8a, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, naclKeypairFromSeed as naclFromSeed, naclSign, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, secp256k1Expand, secp256k1KeypairFromSeed as secp256k1FromSeed, secp256k1Sign, secp256k1Compress, signatureVerify } from '@polkadot/util-crypto';
import { blake2AsU8a, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, naclKeypairFromSeed as naclFromSeed, naclSign, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, secp256k1Compress, secp256k1Expand, secp256k1KeypairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify } from '@polkadot/util-crypto';
import { decodePair } from './decode';
import { encodePair } from './encode';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '../types';
import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '../types';
import { encodeAddress } from '@polkadot/util-crypto';
+2 -2
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeypairType } from '@polkadot/util-crypto/types';
import { KeyringPair$Json, KeyringPair$JsonEncodingTypes, KeyringPair$Meta } from '../types';
import type { KeypairType } from '@polkadot/util-crypto/types';
import type { KeyringPair$Json, KeyringPair$JsonEncodingTypes, KeyringPair$Meta } from '../types';
import { base64Encode } from '@polkadot/util-crypto';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeyringPairs, KeyringPair } from './types';
import type { KeyringPair, KeyringPairs } from './types';
import { assert, isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeyringInstance, KeyringOptions } from './types';
import type { KeyringInstance, KeyringOptions } from './types';
import { hexToU8a } from '@polkadot/util';
+2 -2
View File
@@ -1,10 +1,10 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeyringPair, KeyringOptions } from './types';
import type { KeyringOptions, KeyringPair } from './types';
import { createTestKeyring } from './testing';
import { nobody } from './pair/nobody';
import { createTestKeyring } from './testing';
export interface TestKeyringMap {
[index: string]: KeyringPair;
+2 -2
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from '@polkadot/util-crypto/address/types';
import { KeypairType } from '@polkadot/util-crypto/types';
import type { Prefix } from '@polkadot/util-crypto/address/types';
import type { KeypairType } from '@polkadot/util-crypto/types';
export interface KeyringOptions {
ss58Format?: Prefix;
+4 -7
View File
@@ -1,14 +1,11 @@
{
"name": "@polkadot/networks",
"version": "4.2.1",
"version": "5.2.1",
"description": "A list of all available Substrate networks and their applicable prefixes",
"main": "index.js",
"module": "index.mjs",
"sideEffects": false,
"repository": "github:polkadot-js/common",
"keywords": [
"Polkadot",
"ss58"
],
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
@@ -19,7 +16,7 @@
"@babel/runtime": "^7.12.5"
},
"devDependencies": {
"@polkadot/util": "4.2.1",
"@polkadot/x-fetch": "4.2.1"
"@polkadot/util": "5.2.1",
"@polkadot/x-fetch": "5.2.1"
}
}
+3 -2
View File
@@ -1,10 +1,11 @@
// Copyright 2017-2020 @polkadot/networks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Ss58Registry } from './types';
import type { Ss58Registry } from './types';
import fs from 'fs';
import fetch from '@polkadot/x-fetch';
import { fetch } from '@polkadot/x-fetch';
import { all } from './';
+31 -4
View File
@@ -6,7 +6,7 @@
//
// Once the above is published as a package, the duplication here can be removed
import { Network, NetworkFromSubstrate } from './types';
import type { Network, NetworkFromSubstrate } from './types';
// These are known prefixes that are not sorted
const UNSORTED = [0, 2, 42];
@@ -270,13 +270,13 @@ const all: NetworkFromSubstrate[] = [
website: null
},
{
decimals: null,
decimals: [12],
displayName: 'Phala Network',
network: 'phala',
prefix: 30,
standardAccount: '*25519',
symbols: null,
website: null
symbols: ['PHA'],
website: 'https://phala.network'
},
{
decimals: null,
@@ -296,6 +296,15 @@ const all: NetworkFromSubstrate[] = [
symbols: null,
website: null
},
{
decimals: [15],
displayName: 'Valiu Liquidity Network',
network: 'vln',
prefix: 35,
standardAccount: '*25519',
symbols: ['USDv'],
website: 'https://valiu.com/'
},
{
decimals: [18],
displayName: 'Centrifuge Chain',
@@ -314,6 +323,15 @@ const all: NetworkFromSubstrate[] = [
symbols: ['NODL'],
website: 'https://nodle.io/'
},
{
decimals: [18],
displayName: 'KILT Chain',
network: 'kilt',
prefix: 38,
standardAccount: '*25519',
symbols: ['KILT'],
website: 'https://kilt.io/'
},
{
decimals: [18],
displayName: 'MathChain mainnet',
@@ -332,6 +350,15 @@ const all: NetworkFromSubstrate[] = [
symbols: ['MATH'],
website: 'https://mathwallet.org'
},
{
decimals: null,
displayName: 'Polimec Chain',
network: 'poli',
prefix: 41,
standardAccount: '*25519',
symbols: null,
website: 'https://polimec.io/'
},
{
decimals: null,
displayName: 'Substrate',
+10 -9
View File
@@ -1,11 +1,12 @@
{
"name": "@polkadot/util-crypto",
"version": "4.2.1",
"version": "5.2.1",
"description": "A collection of useful crypto utilities for @polkadot",
"main": "index.js",
"sideEffects": false,
"keywords": [
"Polkadot"
"module": "index.mjs",
"sideEffects": [
"./detectPackage.js",
"./detectPackage.mjs"
],
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
@@ -16,10 +17,10 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/networks": "4.2.1",
"@polkadot/util": "4.2.1",
"@polkadot/wasm-crypto": "^2.0.1",
"@polkadot/x-randomvalues": "4.2.1",
"@polkadot/networks": "5.2.1",
"@polkadot/util": "5.2.1",
"@polkadot/wasm-crypto": "^3.1.1",
"@polkadot/x-randomvalues": "5.2.1",
"base-x": "^3.0.8",
"blakejs": "^1.1.0",
"bn.js": "^4.11.9",
@@ -39,6 +40,6 @@
"@types/xxhashjs": "^0.2.2"
},
"peerDependencies": {
"@polkadot/util": "4.2.1"
"@polkadot/util": "5.2.1"
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { Prefix } from './types';
import { base58Decode } from '../base58/decode';
import { checkAddressChecksum } from './checksum';
@@ -1,9 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { stringToU8a, u8aToHex, hexToU8a } from '@polkadot/util';
import { hexToU8a, stringToU8a, u8aToHex } from '@polkadot/util';
import { TestKeyringMap, createTestPairs } from '../../../keyring/src/testingPairs';
import { createTestPairs, TestKeyringMap } from '../../../keyring/src/testingPairs';
import { decodeAddress } from '.';
describe('decodeAddress', (): void => {
+1 -2
View File
@@ -1,10 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { Prefix } from './types';
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L6
import { assert, isHex, isU8a, u8aToU8a } from '@polkadot/util';
import { base58Decode } from '../base58/decode';
+2 -2
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { Prefix } from './types';
import { assert } from '@polkadot/util';
import { DeriveJunction } from '../key/DeriveJunction';
import { keyExtractPath } from '../key';
import { DeriveJunction } from '../key/DeriveJunction';
import { schnorrkelDerivePublic } from '../schnorrkel';
import { decodeAddress } from './decode';
import { encodeAddress } from './encode';
+1 -2
View File
@@ -1,10 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { Prefix } from './types';
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L34
import { assert, u8aConcat } from '@polkadot/util';
import { base58Encode } from '../base58/encode';
@@ -1,9 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import BN from 'bn.js';
import type BN from 'bn.js';
import type { Prefix } from './types';
import { decodeAddress } from './decode';
import { encodeAddress } from './encode';
@@ -1,9 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import BN from 'bn.js';
import type BN from 'bn.js';
import type { Prefix } from './types';
import { encodeAddress } from './encode';
import { createKeyMulti } from './keyMulti';
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import { addressEq } from '.';
describe('addressEq', (): void => {
@@ -1,12 +1,12 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { HashType } from '../secp256k1/types';
import type { Prefix } from './types';
import { u8aConcat } from '@polkadot/util';
import { secp256k1Hasher } from '../secp256k1/hasher';
import { HashType } from '../secp256k1/types';
import { encodeAddress } from './encode';
/**
@@ -1,7 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import BN from 'bn.js';
import type BN from 'bn.js';
import { bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
import { blake2AsU8a } from '../blake2/asU8a';
+2 -1
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import BN from 'bn.js';
import type BN from 'bn.js';
import { bnToU8a, compactToU8a, stringToU8a, u8aConcat, u8aSorted } from '@polkadot/util';
import { blake2AsU8a } from '../blake2/asU8a';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { Prefix } from './types';
import { defaults } from './defaults';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Prefix } from './types';
import type { Prefix } from './types';
import { u8aSorted } from '@polkadot/util';
+3 -2
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import blakejs from 'blakejs';
import js from 'blakejs';
import { u8aToU8a } from '@polkadot/util';
import { blake2b, isReady } from '@polkadot/wasm-crypto';
@@ -24,5 +25,5 @@ export function blake2AsU8a (data: Uint8Array | string, bitLength = 256, key: Ui
return isReady() && !onlyJs
? blake2b(u8aToU8a(data), u8aToU8a(key), byteLength)
: blakejs.blake2b(u8aToU8a(data), key, byteLength);
: js.blake2b(u8aToU8a(data), key, byteLength);
}
-5
View File
@@ -16,8 +16,3 @@ export function cryptoWaitReady (): Promise<boolean> {
return false;
});
}
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
});
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
//
// new URL(import.meta.url).pathname)
//
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
// there is a complete dead end with usage thereof
//
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
//
// cjs: util.detectPackage(packageInfo, () => __dirname);
// esm: detectPackage(packageInfo, () => import.meta.url);
//
// With the above we additionally need a .d.ts to just export the packageInfo
import { detectPackage } from '@polkadot/util';
import packageInfo from './package-info.json';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
export { packageInfo };
+2 -2
View File
@@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import './cryptoInit';
export * from './crypto';
import './detectPackage';
// all internal exports
export * from './address';
@@ -11,6 +10,7 @@ export * from './base32';
export * from './base58';
export * from './base64';
export * from './blake2';
export * from './crypto';
export * from './ethereum';
export * from './keccak';
export * from './key';
+13 -6
View File
@@ -5,17 +5,24 @@ import { waitReady } from '@polkadot/wasm-crypto';
import { keccakAsHex } from '.';
const value = 'test value';
const result = '2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e';
const BITS: (256 | 512)[] = [256, 512];
const value = 'test';
const result = {
256: '9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658',
512: '1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e'
};
describe('keccakAsHex', (): void => {
beforeEach(async (): Promise<void> => {
await waitReady();
});
it('returns a prefixed hex representation', (): void => {
expect(
keccakAsHex(value)
).toEqual(`0x${result}`);
BITS.forEach((bitLength): void => {
it('returns a prefixed hex representation', (): void => {
expect(
keccakAsHex(value, bitLength)
).toEqual(`0x${result[bitLength]}`);
});
});
});
+2 -2
View File
@@ -19,8 +19,8 @@ import { keccakAsU8a } from './asU8a';
* keccakAsHex('123'); // => 0x...
* ```
*/
export function keccakAsHex (value: Buffer | Uint8Array | string): string {
export function keccakAsHex (value: Buffer | Uint8Array | string, bitLength?: 256 | 512): string {
return u8aToHex(
keccakAsU8a(value)
keccakAsU8a(value, bitLength)
);
}
+31 -18
View File
@@ -6,37 +6,50 @@ import { waitReady } from '@polkadot/wasm-crypto';
import { keccakAsU8a } from '.';
const BITS: (256 | 512)[] = [256, 512];
describe('keccakAsU8a', (): void => {
beforeEach(async (): Promise<void> => {
await waitReady();
});
const input = 'test value';
const output = hexToU8a(
'0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e'
);
const output = {
256: hexToU8a(
'0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e'
),
512: hexToU8a(
'0xc1b50cc57f85ccd968a9d7c7a809dcebd140a548c8e0b67f3afcdd6fc14cca2b1d04187aef24ba0081b74f2ec362431e425760febe94a5607790854cafe5b197'
)
};
[false, true].forEach((onlyJs): void => {
it(`returns an hex representation (string, onlyJs=${onlyJs.toString()})`, (): void => {
expect(
keccakAsU8a(input, onlyJs)
).toEqual(output);
BITS.forEach((bitLength): void => {
[false, true].forEach((onlyJs): void => {
it(`returns an hex representation (string, bitLength=${bitLength}, onlyJs=${onlyJs.toString()})`, (): void => {
expect(
keccakAsU8a(input, bitLength, onlyJs)
).toEqual(output[bitLength]);
});
});
});
[false, true].forEach((onlyJs): void => {
it(`returns an hex representation (Buffer, onlyJs=${onlyJs.toString()})`, (): void => {
expect(
keccakAsU8a(Buffer.from(input), onlyJs)
).toEqual(output);
BITS.forEach((bitLength): void => {
[false, true].forEach((onlyJs): void => {
it(`returns an hex representation (Buffer, bitLength=${bitLength}, onlyJs=${onlyJs.toString()})`, (): void => {
expect(
keccakAsU8a(Buffer.from(input), bitLength, onlyJs)
).toEqual(output[bitLength]);
});
});
});
[false, true].forEach((onlyJs): void => {
it(`returns an hex representation (Uint8Array, onlyJs=${onlyJs.toString()})`, (): void => {
expect(
keccakAsU8a(stringToU8a(input), onlyJs)
).toEqual(output);
BITS.forEach((bitLength): void => {
[false, true].forEach((onlyJs): void => {
it(`returns an hex representation (Uint8Array, bitLength=${bitLength}, onlyJs=${onlyJs.toString()})`, (): void => {
expect(
keccakAsU8a(stringToU8a(input), bitLength, onlyJs)
).toEqual(output[bitLength]);
});
});
});
});
+7 -4
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { keccak256 as keccak256Js } from 'js-sha3';
import js from 'js-sha3';
import { u8aToU8a } from '@polkadot/util';
import { isReady, keccak256 } from '@polkadot/wasm-crypto';
@@ -19,10 +20,12 @@ import { isReady, keccak256 } from '@polkadot/wasm-crypto';
* keccakAsU8a('123'); // => Uint8Array
* ```
*/
export function keccakAsU8a (value: Buffer | Uint8Array | string, onlyJs = false): Uint8Array {
return isReady() && !onlyJs
export function keccakAsU8a (value: Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs = false): Uint8Array {
const is256 = bitLength === 256;
return isReady() && is256 && !onlyJs
? keccak256(u8aToU8a(value))
: new Uint8Array(
keccak256Js.update(u8aToU8a(value)).arrayBuffer()
(is256 ? js.keccak256 : js.keccak512).update(u8aToU8a(value)).arrayBuffer()
);
}
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
/**
* @summary Create Keccak256 values as hex & Uint8Array output
* @summary Create Keccak256/512 values as hex & Uint8Array output
*/
export { keccakAsHex } from './asHex';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { keyExtractPath, ExtractResult } from './extractPath';
import { ExtractResult, keyExtractPath } from './extractPath';
describe('keyExtractPath', (): void => {
it('extracts properly from soft', (): void => {
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { keyExtractSuri, ExtractResult } from './extractSuri';
import { ExtractResult, keyExtractSuri } from './extractSuri';
describe('keyExtractSuri', (): void => {
it('does not extract from invalid suri', (): void => {
+2 -2
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeypairType, Keypair } from '../types';
import type { Keypair, KeypairType } from '../types';
import { DeriveJunction } from './DeriveJunction';
import { keyHdkdEcdsa } from './hdkdEcdsa';
import { keyHdkdEd25519 } from './hdkdEd25519';
import { keyHdkdSr25519 } from './hdkdSr25519';
import { keyHdkdEcdsa } from './hdkdEcdsa';
const generators = {
ecdsa: keyHdkdEcdsa,
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import { assert } from '@polkadot/util';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import { assert } from '@polkadot/util';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import { schnorrkelDeriveHard } from '../schnorrkel/deriveHard';
import { schnorrkelDeriveSoft } from '../schnorrkel/deriveSoft';
+4 -3
View File
@@ -13,7 +13,8 @@
// - Remove setting of wordlost passing of wordlist in functions
// - Remove mnemonicToSeed (we only use the sync variant)
import { sha256 } from 'hash.js';
import hash from 'hash.js';
import { assert, u8aToU8a } from '@polkadot/util';
import { pbkdf2Encode } from '../pbkdf2';
@@ -39,9 +40,9 @@ function bytesToBinary (bytes: number[]): string {
function deriveChecksumBits (entropyBuffer: Uint8Array): string {
const ENT = entropyBuffer.length * 8;
const CS = ENT / 32;
const hash = sha256().update(entropyBuffer).digest();
const result = hash.sha256().update(entropyBuffer).digest();
return bytesToBinary(Array.from(hash)).slice(0, CS);
return bytesToBinary(Array.from(result)).slice(0, CS);
}
function salt (password?: string): string {
@@ -1,9 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { cryptoWaitReady } from '..';
import { mnemonicGenerate, WordCount } from './generate';
import { mnemonicValidate } from './validate';
import { cryptoWaitReady } from '..';
describe('mnemonicGenerate', (): void => {
beforeEach(async (): Promise<void> => {
@@ -3,9 +3,9 @@
import { u8aToHex } from '@polkadot/util';
import { mnemonicToEntropy } from './toEntropy';
import tests from '../schnorrkel/keypair/testing';
import { cryptoWaitReady } from '..';
import { mnemonicToEntropy } from './toEntropy';
describe('mnemonicToEntropy', (): void => {
beforeEach(async (): Promise<void> => {
@@ -3,9 +3,9 @@
import { u8aToHex } from '@polkadot/util';
import { mnemonicToMiniSecret } from './toMiniSecret';
import tests from '../schnorrkel/keypair/testing';
import { cryptoWaitReady } from '..';
import { mnemonicToMiniSecret } from './toMiniSecret';
const MNEMONIC = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
const SEED = '0x4d1ab2a57929edfd018aaa974e62ed557e3f54b4104acabedf73c8f5a1dbb029';
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { mnemonicValidate } from './validate';
import { cryptoWaitReady } from '..';
import { mnemonicValidate } from './validate';
describe('mnemonicValidate', (): void => {
beforeEach(async (): Promise<void> => {
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import * as nacl from 'tweetnacl';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import { naclKeypairFromRandom } from '..';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import * as nacl from 'tweetnacl';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import * as nacl from 'tweetnacl';
@@ -1,10 +1,11 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import * as nacl from 'tweetnacl';
import { isReady, ed25519KeypairFromSeed } from '@polkadot/wasm-crypto';
import { ed25519KeypairFromSeed, isReady } from '@polkadot/wasm-crypto';
/**
* @name naclKeypairFromSeed
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import { stringToU8a } from '@polkadot/util';
+1 -1
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { keyFromPath } from '../key/fromPath';
import { keyExtractPath } from '../key';
import { keyFromPath } from '../key/fromPath';
import { naclBoxKeypairFromSecret, naclKeypairFromString, naclOpen, naclSeal } from '.';
describe('naclOpen', (): void => {
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { naclSeal, naclKeypairFromString, naclBoxKeypairFromSecret } from '.';
import { naclBoxKeypairFromSecret, naclKeypairFromString, naclSeal } from '.';
describe('naclSeal', (): void => {
it('seals a message', (): void => {
+1 -1
View File
@@ -4,7 +4,7 @@
import { stringToU8a } from '@polkadot/util';
import { waitReady } from '@polkadot/wasm-crypto';
import { naclSign, naclKeypairFromSeed } from '.';
import { naclKeypairFromSeed, naclSign } from '.';
describe('naclSign', (): void => {
beforeEach(async (): Promise<void> => {
+3 -2
View File
@@ -1,11 +1,12 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import * as nacl from 'tweetnacl';
import { assert, u8aToU8a } from '@polkadot/util';
import { isReady, ed25519Sign } from '@polkadot/wasm-crypto';
import { ed25519Sign, isReady } from '@polkadot/wasm-crypto';
/**
* @name naclSign
+1 -1
View File
@@ -4,7 +4,7 @@
import { stringToU8a } from '@polkadot/util';
import { waitReady } from '@polkadot/wasm-crypto';
import { naclVerify, naclKeypairFromSeed } from '.';
import { naclKeypairFromSeed, naclVerify } from '.';
describe('naclVerify', (): void => {
let publicKey: Uint8Array;
+2 -1
View File
@@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
import * as nacl from 'tweetnacl';
import { assert, u8aToU8a } from '@polkadot/util';
import { isReady, ed25519Verify } from '@polkadot/wasm-crypto';
import { ed25519Verify, isReady } from '@polkadot/wasm-crypto';
/**
* @name naclSign
-12
View File
@@ -1,12 +0,0 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
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);
}
+4 -3
View File
@@ -3,7 +3,8 @@
// Adapted from https://gist.github.com/calvinmetcalf/91e8e84dc63c75f2aa53
import { hmac, sha512 } from 'hash.js';
import hash from 'hash.js';
import { u8aConcat } from '@polkadot/util';
export function pbkdf2Sync (password: Uint8Array, salt: Uint8Array, rounds: number, len = 64): Uint8Array {
@@ -17,14 +18,14 @@ export function pbkdf2Sync (password: Uint8Array, salt: Uint8Array, rounds: numb
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
let prev = hmac(sha512, password).update(block).digest();
let prev = hash.hmac(hash.sha512, password).update(block).digest();
const md = prev;
let i = 0;
while (++i < rounds) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
prev = hmac(sha512, password).update(prev).digest();
prev = hash.hmac(hash.sha512, password).update(prev).digest();
let j = -1;
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import BN from 'bn.js';
import { hexToBn } from '@polkadot/util';
import { randomAsHex } from './asHex';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import getRandomValues from '@polkadot/x-randomvalues';
import { getRandomValues } from '@polkadot/x-randomvalues';
/**
* @name randomAsU8a
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import { sr25519DeriveKeypairHard } from '@polkadot/wasm-crypto';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import { sr25519DeriveKeypairSoft } from '@polkadot/wasm-crypto';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import { sr25519KeypairFromSeed } from '@polkadot/wasm-crypto';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
const SEC_LEN = 64;
const PUB_LEN = 32;
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import { u8aConcat } from '@polkadot/util';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import type { Keypair } from '../types';
import { assert, u8aToU8a } from '@polkadot/util';
import { sr25519Sign } from '@polkadot/wasm-crypto';
+2 -1
View File
@@ -1,9 +1,10 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Params } from './types';
import type { Params } from './types';
import scryptsy from 'scryptsy';
import { bufferToU8a, u8aToBuffer, u8aToU8a } from '@polkadot/util';
import { isReady, scrypt } from '@polkadot/wasm-crypto';
+2 -2
View File
@@ -1,9 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Params } from './types';
import type { Params } from './types';
import { u8aToBn, assert } from '@polkadot/util';
import { assert, u8aToBn } from '@polkadot/util';
import { DEFAULT_PARAMS } from './defaults';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Params } from './types';
import type { Params } from './types';
import { bnToU8a, u8aConcat } from '@polkadot/util';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { HashType } from './types';
import type { HashType } from './types';
import { blake2AsU8a } from '../blake2';
import { keccakAsU8a } from '../keccak';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { u8aToHex, hexToU8a } from '@polkadot/util';
import { hexToU8a, u8aToHex } from '@polkadot/util';
import { mnemonicToMiniSecret } from '../../mnemonic';
import { secp256k1KeypairFromSeed } from '..';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../../types';
import type { Keypair } from '../../types';
import { assert, bnToU8a } from '@polkadot/util';
@@ -1,7 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { ec as EC } from 'elliptic';
import elliptic from 'elliptic';
const EC = elliptic.ec;
export const secp256k1 = new EC('secp256k1');
+2 -2
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keypair } from '../types';
import { HashType } from './types';
import type { Keypair } from '../types';
import type { HashType } from './types';
import { assert, bnToU8a, u8aConcat } from '@polkadot/util';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { HashType } from './types';
import type { HashType } from './types';
import { assert, u8aEq, u8aToU8a } from '@polkadot/util';
+1
View File
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import * as nacl from 'tweetnacl';
import { isReady, sha512 } from '@polkadot/wasm-crypto';
/**
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { KeypairType, VerifyResult } from '../types';
import type { KeypairType, VerifyResult } from '../types';
import { assert, u8aToU8a } from '@polkadot/util';
@@ -1,15 +1,16 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import hasher from 'xxhashjs/lib/xxhash64';
import xx from 'xxhashjs';
import { isBuffer, isString, u8aToBuffer } from '@polkadot/util';
export default function xxhash64AsValue (data: Buffer | Uint8Array | string, seed: number): number {
if (isBuffer(data) || isString(data)) {
return hasher(data, seed);
return xx.h64(data, seed);
}
return hasher(
return xx.h64(
u8aToBuffer(data),
seed
);
+2 -2
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
declare module 'xxhashjs/lib/xxhash64' {
declare module 'xxhashjs' {
export interface HashInterface {
(data: string | Buffer, seed: number): number;
}
const h64: HashInterface;
export = h64;
export = { h64 };
}
+5 -6
View File
@@ -1,11 +1,10 @@
{
"name": "@polkadot/util",
"version": "4.2.1",
"version": "5.2.1",
"description": "A collection of useful utilities for @polkadot",
"main": "index.js",
"keywords": [
"Polkadot"
],
"module": "index.mjs",
"sideEffects": false,
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
@@ -15,8 +14,8 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/x-textdecoder": "4.2.1",
"@polkadot/x-textencoder": "4.2.1",
"@polkadot/x-textdecoder": "5.2.1",
"@polkadot/x-textencoder": "5.2.1",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.11.9",
"camelcase": "^5.3.1",
+12
View File
@@ -0,0 +1,12 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { arrayChunk } from '.';
describe('arrayChunk', (): void => {
it('chunks arrays', (): void => {
expect(
arrayChunk([1, 2, 3, 4, 5, 6, 7], 3)
).toEqual([[1, 2, 3], [4, 5, 6], [7]]);
});
});
+29
View File
@@ -0,0 +1,29 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
/**
* @name arrayChunk
* @summary Split T[] into T[][] based on the defind size
* @description
* Returns a set ao arrays based on the chunksize
* @example
* <BR>
*
* ```javascript
* import { arrayChunk } from '@polkadot/util';
*
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
* ```
*/
export function arrayChunk <T> (array: T[], chunkSize: number): T[][] {
const outputSize = Math.ceil(array.length / chunkSize);
const output = Array<T[]>(outputSize);
for (let index = 0; index < outputSize; index++) {
const offset = index * chunkSize;
output[index] = array.slice(offset, offset + chunkSize);
}
return output;
}

Some files were not shown because too many files have changed in this diff Show More