Compare commits

..
13 Commits
Author SHA1 Message Date
Github Actions cd20fe6c8b [CI Skip] release/stable 2.13.1
skip-checks: true
2020-06-08 14:03:31 +00:00
Jaco Greeff 28f8ca73aa 2.13 (#616) 2020-06-08 15:59:47 +02:00
Github Actions f4a8bfc0c0 [CI Skip] release/beta 2.13.0-beta.5
skip-checks: true
2020-06-08 12:33:10 +00:00
Jaco Greeff 94b058d6a3 Align bnToHex signature with bnToU8a (#615) 2020-06-08 14:29:40 +02:00
Github Actions 3d7ddb85a2 [CI Skip] release/beta 2.13.0-beta.4
skip-checks: true
2020-06-08 11:35:08 +00:00
Jaco Greeff f7a2bb895f Fix blake2 U8a JS with hex inputs (#614)
* Fix blake2 U8a JS with hex inputs

* Apply suggestions from code review
2020-06-08 13:31:10 +02:00
Github Actions c1bfcc00b6 [CI Skip] release/beta 2.13.0-beta.3
skip-checks: true
2020-06-06 08:08:42 +00:00
Jaco Greeff b16d8e7c26 Bump deps (#612) 2020-06-06 10:05:02 +02:00
Github Actions 2a4b363fcd [CI Skip] release/beta 2.13.0-beta.2
skip-checks: true
2020-06-05 20:17:13 +00:00
Jaco Greeff de689b8e6f Bump deps (#611) 2020-06-05 22:13:55 +02:00
Github Actions 2e72ab920b [CI Skip] release/beta 2.13.0-beta.1
skip-checks: true
2020-06-02 09:44:29 +00:00
Jaco Greeff 565e6baecd Linting 2020-06-02 11:40:25 +02:00
Jaco Greeff 1e15203b6c Reset to beta 2020-06-02 11:24:23 +02:00
14 changed files with 350 additions and 220 deletions
+6
View File
@@ -1,5 +1,11 @@
# CHANGELOG
## 2.13.1 Jun 8, 2020
- Fix JS blake2 fallback (non-wasm) to correctly deal with hex inputs
- Align `bnToHex` signature with `bnToU8a` (with old/new style)
- Allow `bnTo{Hex,U8a}` to take any value with `.toBn()` signatures
## 2.12.2 Jun 1, 2020
- Fix `isFunction` signature to assert `Function`
+1 -1
View File
@@ -9,5 +9,5 @@
"packages": [
"packages/*"
],
"version": "2.12.2"
"version": "2.13.1"
}
+4 -4
View File
@@ -21,10 +21,10 @@
"test:one": "polkadot-dev-run-test"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@polkadot/dev": "^0.55.6",
"@polkadot/ts": "^0.3.25",
"@babel/core": "^7.10.2",
"@polkadot/dev": "^0.55.8",
"@polkadot/ts": "^0.3.26",
"@types/jest": "^25.2.3"
},
"version": "2.12.2"
"version": "2.13.1"
}
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/keyring",
"version": "2.12.2",
"version": "2.13.1",
"description": "Keyring management",
"main": "index.js",
"publishConfig": {
@@ -27,8 +27,8 @@
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
"dependencies": {
"@babel/runtime": "^7.9.6",
"@polkadot/util": "2.12.2",
"@polkadot/util-crypto": "2.12.2"
"@babel/runtime": "^7.10.2",
"@polkadot/util": "2.13.1",
"@polkadot/util-crypto": "2.13.1"
}
}
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/util-crypto",
"version": "2.12.2",
"version": "2.13.1",
"description": "A collection of useful crypto utilities for @polkadot",
"main": "index.js",
"keywords": [
@@ -25,8 +25,8 @@
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
"dependencies": {
"@babel/runtime": "^7.9.6",
"@polkadot/util": "2.12.2",
"@babel/runtime": "^7.10.2",
"@polkadot/util": "2.13.1",
"@polkadot/wasm-crypto": "^1.2.1",
"base-x": "^3.0.8",
"bip39": "^3.0.2",
@@ -35,7 +35,7 @@
"bs58": "^4.0.1",
"elliptic": "^6.5.2",
"js-sha3": "^0.8.0",
"pbkdf2": "^3.0.17",
"pbkdf2": "^3.1.1",
"tweetnacl": "^1.0.3",
"xxhashjs": "^0.2.2"
},
@@ -43,4 +43,18 @@ describe('blake2AsU8a', (): void => {
hexToU8a('0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923')
);
});
it('has equivalent Wasm/Js outputs on hex inputs', (): void => {
const a = blake2AsU8a('0x123456', 256, null, false);
const b = blake2AsU8a('0x123456', 256, null, true);
expect(a).toEqual(b);
});
it('has equivalent Wasm/Js outputs with key inputs', (): void => {
const a = blake2AsU8a('0x123456', 256, new Uint8Array([1, 2]), false);
const b = blake2AsU8a('0x123456', 256, new Uint8Array([1, 2]), true);
expect(a).toEqual(b);
});
});
+3 -3
View File
@@ -20,10 +20,10 @@ import { blake2b, isReady } from '@polkadot/wasm-crypto';
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa53, 0xf98, 0x1c, 0x4d, 0x0d]
* ```
*/
export default function blake2AsU8a (data: Uint8Array | string, bitLength = 256, key: Uint8Array | null = null): Uint8Array {
export default function blake2AsU8a (data: Uint8Array | string, bitLength = 256, key: Uint8Array | null = null, onlyJs = false): Uint8Array {
const byteLength = Math.ceil(bitLength / 8);
return isReady()
return isReady() && !onlyJs
? blake2b(u8aToU8a(data), u8aToU8a(key), byteLength)
: blakejs.blake2b(data, key, byteLength);
: blakejs.blake2b(u8aToU8a(data), key, byteLength);
}
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/util",
"version": "2.12.2",
"version": "2.13.1",
"description": "A collection of useful utilities for @polkadot",
"main": "index.js",
"keywords": [
@@ -25,7 +25,7 @@
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"dependencies": {
"@babel/runtime": "^7.9.6",
"@babel/runtime": "^7.10.2",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.2",
"camelcase": "^5.3.1",
+6
View File
@@ -25,6 +25,12 @@ describe('bnToHex', (): void => {
).toBe('0x0080');
});
it('converts BN values to a prefixed hex representation (bitLength + le)', (): void => {
expect(
bnToHex(new BN(128), 16, true)
).toBe('0x8000');
});
it('converts BN values to a prefixed hex representation (LE)', (): void => {
expect(
bnToHex(new BN(128), { bitLength: 16, isLe: true })
+8 -3
View File
@@ -2,11 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ToBn, ToBnOptions } from '../types';
import BN from 'bn.js';
import isNumber from '../is/number';
import bnToU8a from './toU8a';
import { ToBnOptions } from '../types';
import { u8aToHex } from '../u8a';
const ZERO_STR = '0x00';
@@ -30,7 +31,9 @@ interface Options extends ToBnOptions {
* bnToHex(new BN(0x123456)); // => '0x123456'
* ```
*/
export default function bnToHex (value?: BN | BigInt | number | null, options: number | Options = { bitLength: -1, isLe: false, isNegative: false }): string {
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | BigInt | number | null, options?: Options): string;
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | BigInt | number | null, bitLength?: number, isLe?: boolean): string;
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | BigInt | number | null, arg1: number | Options = { bitLength: -1, isLe: false, isNegative: false }, arg2?: boolean): string {
if (!value) {
return ZERO_STR;
}
@@ -39,8 +42,10 @@ export default function bnToHex (value?: BN | BigInt | number | null, options: n
isLe: false,
isNegative: false,
// Backwards-compatibility
...(isNumber(options) ? { bitLength: options } : options)
...(isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1)
};
return u8aToHex(bnToU8a(value, _options));
}
export default bnToHex;
+5 -4
View File
@@ -2,11 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ToBn, ToBnOptions } from '../types';
import BN from 'bn.js';
import isNumber from '../is/number';
import bnToBn from './toBn';
import { ToBnOptions } from '../types';
interface Options extends ToBnOptions {
bitLength?: number;
@@ -26,9 +27,9 @@ interface Options extends ToBnOptions {
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
* ```
*/
function bnToU8a (value: BN | BigInt | number | null, options?: Options): Uint8Array;
function bnToU8a (value: BN | BigInt | number | null, bitLength?: number, isLe?: boolean): Uint8Array;
function bnToU8a (value: BN | BigInt | number | null, arg1: number | Options = { bitLength: -1, isLe: true, isNegative: false }, arg2?: boolean): Uint8Array {
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | BigInt | number | null, options?: Options): Uint8Array;
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | BigInt | number | null, bitLength?: number, isLe?: boolean): Uint8Array;
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | BigInt | number | null, arg1: number | Options = { bitLength: -1, isLe: true, isNegative: false }, arg2?: boolean): Uint8Array {
const _options: Options = {
bitLength: -1,
isLe: true,
@@ -26,7 +26,7 @@ describe('TextDecoder', (): void => {
});
it('polyfills with no exceptions (with TextDecoder)', (): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
(global as any).TextDecoder = require('util').TextDecoder;
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -26,7 +26,7 @@ describe('TextEncoder', (): void => {
});
it('polyfills with no exceptions (with TextEncoder)', (): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
(global as any).TextEncoder = require('util').TextEncoder;
// eslint-disable-next-line @typescript-eslint/no-var-requires
+291 -193
View File
File diff suppressed because it is too large Load Diff