Compare commits

..
8 Commits
Author SHA1 Message Date
Github Actions 72456bb2bd [CI Skip] release/stable 2.15.1
skip-checks: true
2020-06-22 09:33:14 +00:00
Jaco Greeff 87f3fd2827 2.15 (#621) 2020-06-22 11:29:33 +02:00
Github Actions 7254aab68d [CI Skip] release/beta 2.15.0-beta.0
skip-checks: true
2020-06-19 15:39:36 +00:00
Jaco Greeff 95d7160ad0 Test for 0 prefix (#620)
* Test for 0 prefix

* Add test for keyring encodeAddress (& fix)

* Test other branch of ?: check
2020-06-19 17:35:48 +02:00
Github Actions 611b1be481 [CI Skip] release/stable 2.14.1
skip-checks: true
2020-06-16 06:02:06 +00:00
Jaco Greeff 73b35fc188 2.14 (#618) 2020-06-16 07:58:33 +02:00
Github Actions 6c30d5b9fd [CI Skip] release/beta 2.14.0-beta.0
skip-checks: true
2020-06-08 15:58:49 +00:00
Keith Ingram 56d151fe66 Add BN consts and timeToString (#610)
* Add BN consts and timeToString

* docs

* lint

* fixes

* lint

* lint

* add tests, ms

* fix

* test
2020-06-09 03:55:21 +12:00
17 changed files with 893 additions and 810 deletions
+8
View File
@@ -1,5 +1,13 @@
# CHANGELOG
## 2.15.1 Jun 22, 2020
- Adjust keyring to no override 0-prefix (Polkadot live) settings with keychain default
## 2.14.1 Jun 16, 2020
- Add `extractTime` utility conversion (Thanks to https://github.com/kwingram25)
## 2.13.1 Jun 8, 2020
- Fix JS blake2 fallback (non-wasm) to correctly deal with hex inputs
+1 -1
View File
@@ -9,5 +9,5 @@
"packages": [
"packages/*"
],
"version": "2.13.1"
"version": "2.15.1"
}
+4 -4
View File
@@ -21,10 +21,10 @@
"test:one": "polkadot-dev-run-test"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@polkadot/dev": "^0.55.8",
"@babel/core": "^7.10.3",
"@polkadot/dev": "^0.55.11",
"@polkadot/ts": "^0.3.26",
"@types/jest": "^25.2.3"
"@types/jest": "^26.0.0"
},
"version": "2.13.1"
"version": "2.15.1"
}
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/keyring",
"version": "2.13.1",
"version": "2.15.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.10.2",
"@polkadot/util": "2.13.1",
"@polkadot/util-crypto": "2.13.1"
"@babel/runtime": "^7.10.3",
"@polkadot/util": "2.15.1",
"@polkadot/util-crypto": "2.15.1"
}
}
+20
View File
@@ -212,4 +212,24 @@ describe('keypair', (): void => {
expect(pair.verify(MESSAGE, signature)).toBe(true);
});
});
describe('util', (): void => {
let keyring: Keyring;
beforeEach((): void => {
keyring = new Keyring({ ss58Format: 42 });
});
it('can re-encode an address to Polkadot live', (): void => {
expect(
keyring.encodeAddress('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', 0)
).toEqual('15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5');
});
it('can re-encode an address to keyring default', (): void => {
expect(
keyring.encodeAddress('15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5')
).toEqual('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
});
});
});
+2 -2
View File
@@ -5,7 +5,7 @@
import { KeypairType, Keypair } from '@polkadot/util-crypto/types';
import { KeyringInstance, KeyringPair, KeyringPair$Json, KeyringPair$Meta, KeyringOptions } from './types';
import { assert, hexToU8a, isHex, stringToU8a } from '@polkadot/util';
import { assert, hexToU8a, isHex, isUndefined, stringToU8a } from '@polkadot/util';
import { decodeAddress, encodeAddress, keyExtractSuri, keyFromPath, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, secp256k1KeypairFromSeed as secp256k1FromSeed, mnemonicToMiniSecret } from '@polkadot/util-crypto';
import { DEV_PHRASE } from './defaults';
@@ -192,7 +192,7 @@ export default class Keyring implements KeyringInstance {
* @description Encodes the input into an ss58 representation
*/
public encodeAddress = (address: Uint8Array | string, ss58Format?: number): string => {
return encodeAddress(address, ss58Format || this.#ss58);
return encodeAddress(address, isUndefined(ss58Format) ? this.#ss58 : ss58Format);
}
/**
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/util-crypto",
"version": "2.13.1",
"version": "2.15.1",
"description": "A collection of useful crypto utilities for @polkadot",
"main": "index.js",
"keywords": [
@@ -25,15 +25,15 @@
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
"dependencies": {
"@babel/runtime": "^7.10.2",
"@polkadot/util": "2.13.1",
"@babel/runtime": "^7.10.3",
"@polkadot/util": "2.15.1",
"@polkadot/wasm-crypto": "^1.2.1",
"base-x": "^3.0.8",
"bip39": "^3.0.2",
"blakejs": "^1.1.0",
"bn.js": "^5.1.2",
"bs58": "^4.0.1",
"elliptic": "^6.5.2",
"elliptic": "^6.5.3",
"js-sha3": "^0.8.0",
"pbkdf2": "^3.1.1",
"tweetnacl": "^1.0.3",
@@ -21,6 +21,12 @@ describe('encode', (): void => {
).toEqual('7sL6eNJj5ZGV5cn3hhV2deRUsivXfBfMH76wCALCqWj1EKzv');
});
it('can re-encode an address to Polkadot live', (): void => {
expect(
encode('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', 0)
).toEqual('15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5');
});
it('fails when non-valid publicKey provided', (): void => {
expect(
(): string => encode(
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/util",
"version": "2.13.1",
"version": "2.15.1",
"description": "A collection of useful utilities for @polkadot",
"main": "index.js",
"keywords": [
@@ -25,11 +25,11 @@
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"dependencies": {
"@babel/runtime": "^7.10.2",
"@babel/runtime": "^7.10.3",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.2",
"camelcase": "^5.3.1",
"chalk": "^4.0.0",
"chalk": "^4.1.0",
"ip-regex": "^4.1.0"
}
}
+38
View File
@@ -0,0 +1,38 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BN_ZERO, BN_ONE, BN_TEN, BN_HUNDRED, BN_THOUSAND } from '.';
import BN from 'bn.js';
describe('consts', (): void => {
it('BN_ZERO equals 0', (): void => {
expect(
BN_ZERO
).toEqual(new BN(0));
});
it('BN_ONE equals 1', (): void => {
expect(
BN_ONE
).toEqual(new BN(1));
});
it('BN_TEN equals 10', (): void => {
expect(
BN_TEN
).toEqual(new BN(10));
});
it('BN_HUNDRED equals 100', (): void => {
expect(
BN_HUNDRED
).toEqual(new BN(100));
});
it('BN_THOUSAND equals 1000', (): void => {
expect(
BN_THOUSAND
).toEqual(new BN(1000));
});
});
+43
View File
@@ -0,0 +1,43 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
/**
* @name BN_ZERO
* @summary BN constant for 0.
*/
const BN_ZERO: BN = new BN(0);
/**
* @name BN_ONE
* @summary BN constant for 1.
*/
const BN_ONE: BN = new BN(1);
/**
* @name BN_TEN
* @summary BN constant for 10.
*/
const BN_TEN: BN = new BN(10);
/**
* @name BN_HUNDRED
* @summary BN constant for 100.
*/
const BN_HUNDRED: BN = new BN(100);
/**
* @name BN_THOUSAND
* @summary BN constant for 1000.
*/
const BN_THOUSAND: BN = new BN(1000);
export {
BN_ZERO,
BN_ONE,
BN_TEN,
BN_HUNDRED,
BN_THOUSAND
};
+1
View File
@@ -6,6 +6,7 @@
* @summary Utility methods to convert to and from `BN` objects
*/
export * from './consts';
export { default as bnFromHex } from './fromHex';
export { default as bnMax } from './max';
export { default as bnMin } from './min';
+20
View File
@@ -0,0 +1,20 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { extractTime } from '.';
describe('extractTime', (): void => {
const milliseconds = 1e9 + 123;
it('extracts time components correctly', (): void => {
expect(extractTime(milliseconds))
.toEqual({
days: 11,
hours: 13,
milliseconds: 123,
minutes: 46,
seconds: 40
});
});
});
+73
View File
@@ -0,0 +1,73 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Time } from './types';
const HRS = 60 * 60;
const DAY = HRS * 24;
/**
* @name addTime
* @summary Add together two Time arrays
*/
function addTime (a: Time, b: Time): Time {
return {
days: a.days + b.days,
hours: a.hours + b.hours,
milliseconds: a.milliseconds + b.milliseconds,
minutes: a.minutes + b.minutes,
seconds: a.seconds + b.seconds
};
}
const ZERO = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
/**
* @name extractTime
* @summary Convert a quantity of seconds to Time array representing accumulated {days, minutes, hours, seconds, milliseconds}
* @example
* <BR>
*
* ```javascript
* import { extractTime } from '@polkadot/util';
*
* const { days, minutes, hours, seconds, milliseconds } = extractTime(6000); // 0, 0, 10, 0, 0
* ```
*/
export default function extractTime (milliseconds?: number): Time {
if (!milliseconds) {
return ZERO;
} else if (milliseconds < 1000) {
return { ...ZERO, milliseconds };
}
const secs = milliseconds / 1000;
if (secs < 60) {
const seconds = Math.floor(secs);
return addTime({ ...ZERO, seconds }, extractTime(milliseconds - (seconds * 1000)));
}
const mins = secs / 60;
if (mins < 60) {
const minutes = Math.floor(mins);
return addTime({ ...ZERO, minutes }, extractTime(milliseconds - (minutes * 60 * 1000)));
}
const hrs = mins / 60;
if (hrs < 24) {
const hours = Math.floor(hrs);
return addTime({ ...ZERO, hours }, extractTime(milliseconds - (hours * HRS * 1000)));
}
const days = Math.floor(hrs / 24);
return addTime({ ...ZERO, days }, extractTime(milliseconds - (days * DAY * 1000)));
}
+1
View File
@@ -10,6 +10,7 @@ import './polyfill';
export { default as assert } from './assert';
export { default as detectPackage } from './detectPackage';
export { default as extractTime } from './extractTime';
export { default as logger } from './logger';
export { default as promisify } from './promisify';
+8
View File
@@ -40,3 +40,11 @@ export type BnList = {
0: BN;
1: BN;
} & BN[];
export interface Time {
days: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
}
+657 -792
View File
File diff suppressed because it is too large Load Diff