Compare commits

..
24 Commits
Author SHA1 Message Date
Github Actions 53249f51b8 [CI Skip] release/stable 7.8.2
skip-checks: true
2021-11-07 07:33:32 +00:00
Jaco 4883106c3d 7.8.2 (#1167) 2021-11-07 09:25:15 +02:00
Github Actions b3f60da550 [CI Skip] release/beta 7.8.2-0
skip-checks: true
2021-11-06 14:03:57 +00:00
Jaco 644f32dfaa Additional isArray (w/ is* opts) (#1166) 2021-11-06 15:56:51 +02:00
Github Actions bf4c6b497f [CI Skip] release/stable 7.8.1
skip-checks: true
2021-11-06 11:26:10 +00:00
Jaco a74ac0a0f9 7.8.1 (#1165) 2021-11-06 13:19:01 +02:00
Github Actions 6701f7420f [CI Skip] release/beta 7.7.2-8
skip-checks: true
2021-11-06 10:56:11 +00:00
Jaco 8e43a2d105 Sync ss58registry (#1164) 2021-11-06 12:48:48 +02:00
Github Actions 9560301883 [CI Skip] release/beta 7.7.2-7
skip-checks: true
2021-11-05 14:36:05 +00:00
qwer951123 889bd36432 Add acala genesis (#1161) 2021-11-05 16:27:33 +02:00
Github Actions e310a63059 [CI Skip] release/beta 7.7.2-6
skip-checks: true
2021-11-04 15:11:31 +00:00
Jaco 98082774f7 Add objectCopy (#1160) 2021-11-04 17:02:45 +02:00
Github Actions 4d680f4b0c [CI Skip] release/beta 7.7.2-5
skip-checks: true
2021-11-04 12:24:30 +00:00
Jaco ff7c086b5b Import lazy* from api repo (#1159) 2021-11-04 14:16:58 +02:00
Github Actions 63b38c56ff [CI Skip] release/beta 7.7.2-4
skip-checks: true
2021-11-04 08:10:38 +00:00
Jaco 8be38e40a1 Bump dev deps (#1158) 2021-11-04 10:01:35 +02:00
Github Actions 9eb2f14dee [CI Skip] release/beta 7.7.2-3
skip-checks: true
2021-11-04 06:24:05 +00:00
Jaco 733d7c1948 Add objectClear & objectSpread (#1157)
* Add objectClear & objectSpread

* Allow null/undefined as a source
2021-11-04 08:16:55 +02:00
Github Actions 08ac55d7cd [CI Skip] release/beta 7.7.2-2
skip-checks: true
2021-11-03 16:21:23 +00:00
Jaco e2f5a85d14 Correct types for Ledger signature (#1156) 2021-11-03 18:13:00 +02:00
Github Actions 77289d0ec0 [CI Skip] release/beta 7.7.2-1
skip-checks: true
2021-11-03 12:49:11 +00:00
Jaco 29406a0010 Bump dev (#1155) 2021-11-03 14:46:44 +02:00
Github Actions 006d55f5c1 [CI Skip] release/beta 7.7.2-0
skip-checks: true
2021-11-03 06:55:22 +00:00
Jaco 650a3ca4a8 Sync ss58 (#1154) 2021-11-03 08:46:52 +02:00
53 changed files with 1061 additions and 855 deletions
+2 -1
View File
@@ -17,4 +17,5 @@
7.0.2 7.0.2
7.0.3 7.0.3
7.1.2 7.1.2
7.8.2
+21
View File
@@ -1,5 +1,26 @@
# CHANGELOG # CHANGELOG
## 7.8.2 Nov 7, 2021
Changes:
- Expose internal `isArray` check
- Move `object{Property, Properties}` from api repo
## 7.8.1 Nov 6, 2021
Contributed:
- Added Acala genesisHash (Thanks to https://github.com/qwer951123)
Changes:
- Add `objectClear` and `objectSpread` utility functions
- Add `lazyMethod` & `lazyMethods` utility functions
- Sync with upstream Substrate ss58 registry
## 7.7.1 Oct 31, 2021 ## 7.7.1 Oct 31, 2021
Contributed: Contributed:
+5 -5
View File
@@ -10,7 +10,7 @@
"url": "https://github.com/polkadot-js/common.git" "url": "https://github.com/polkadot-js/common.git"
}, },
"sideEffects": false, "sideEffects": false,
"version": "7.7.1", "version": "7.8.2",
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
@@ -21,16 +21,16 @@
"clean": "polkadot-dev-clean-build", "clean": "polkadot-dev-clean-build",
"lint": "polkadot-dev-run-lint", "lint": "polkadot-dev-run-lint",
"networks:crosscheck": "polkadot-dev-run-test packages/networks/src/crosscheck", "networks:crosscheck": "polkadot-dev-run-test packages/networks/src/crosscheck",
"networks:sync": "node packages/networks/scripts/fromSubstrate.mjs", "networks:sync": "yarn build && node packages/networks/scripts/fromSubstrate.mjs",
"postinstall": "polkadot-dev-yarn-only", "postinstall": "polkadot-dev-yarn-only",
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck --testPathIgnorePatterns toMiniSecretCmp", "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:mnemonicCmp": "polkadot-dev-run-test packages/util-crypto/src/mnemonic/toMiniSecretCmp.spec.ts",
"test:one": "polkadot-dev-run-test --runInBand" "test:one": "polkadot-dev-run-test --runInBand"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.15.8", "@babel/core": "^7.16.0",
"@polkadot/dev": "^0.63.18", "@polkadot/dev": "^0.63.27",
"@polkadot/ts": "^0.4.12", "@polkadot/ts": "^0.4.13",
"@types/ed2curve": "^0.2.2", "@types/ed2curve": "^0.2.2",
"@types/jest": "^27.0.2" "@types/jest": "^27.0.2"
}, },
+2 -2
View File
@@ -16,12 +16,12 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"browser": "browser.js", "browser": "browser.js",
"main": "node.js", "main": "node.js",
"react-native": "react-native.js", "react-native": "react-native.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@ledgerhq/hw-transport": "^6.11.2", "@ledgerhq/hw-transport": "^6.11.2",
"@ledgerhq/hw-transport-webhid": "^6.11.2", "@ledgerhq/hw-transport-webhid": "^6.11.2",
"@ledgerhq/hw-transport-webusb": "^6.11.2" "@ledgerhq/hw-transport-webusb": "^6.11.2"
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.8.2' };
+4 -4
View File
@@ -19,12 +19,12 @@
"./detectPackage.cjs" "./detectPackage.cjs"
], ],
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/hw-ledger-transports": "7.7.1", "@polkadot/hw-ledger-transports": "7.8.2",
"@polkadot/util": "7.7.1", "@polkadot/util": "7.8.2",
"@zondax/ledger-substrate": "^0.18.0" "@zondax/ledger-substrate": "^0.18.0"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.8.2' };
+3 -1
View File
@@ -1,6 +1,8 @@
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors // Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
export type LedgerTypes = 'hid' | 'u2f' | 'webusb'; export type LedgerTypes = 'hid' | 'u2f' | 'webusb';
export interface AccountOptions { export interface AccountOptions {
@@ -15,7 +17,7 @@ export interface LedgerAddress {
} }
export interface LedgerSignature { export interface LedgerSignature {
signature: string; signature: HexString;
} }
export interface LedgerVersion { export interface LedgerVersion {
+6 -6
View File
@@ -20,15 +20,15 @@
"./detectPackage.cjs" "./detectPackage.cjs"
], ],
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/util": "7.7.1", "@polkadot/util": "7.8.2",
"@polkadot/util-crypto": "7.7.1" "@polkadot/util-crypto": "7.8.2"
}, },
"peerDependencies": { "peerDependencies": {
"@polkadot/util": "7.7.1", "@polkadot/util": "7.8.2",
"@polkadot/util-crypto": "7.7.1" "@polkadot/util-crypto": "7.8.2"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/keyring', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/keyring', version: '7.8.2' };
+2 -2
View File
@@ -6,7 +6,7 @@ import type { EncryptedJsonEncoding, Keypair, KeypairType } from '@polkadot/util
import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta, SignOptions } from '../types'; import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta, SignOptions } from '../types';
import type { PairInfo } from './types'; import type { PairInfo } from './types';
import { assert, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util'; import { assert, objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
import { blake2AsU8a, convertPublicKeyToCurve25519, convertSecretKeyToCurve25519, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, naclKeypairFromSeed as naclFromSeed, naclOpen, naclSeal, naclSign, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVrfSign, schnorrkelVrfVerify, secp256k1Compress, secp256k1Expand, secp256k1KeypairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify } from '@polkadot/util-crypto'; import { blake2AsU8a, convertPublicKeyToCurve25519, convertSecretKeyToCurve25519, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, naclKeypairFromSeed as naclFromSeed, naclOpen, naclSeal, naclSign, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVrfSign, schnorrkelVrfVerify, secp256k1Compress, secp256k1Expand, secp256k1KeypairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify } from '@polkadot/util-crypto';
import { decodePair } from './decode'; import { decodePair } from './decode';
@@ -181,7 +181,7 @@ export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: P
secretKey = new Uint8Array(); secretKey = new Uint8Array();
}, },
setMeta: (additional: KeyringPair$Meta): void => { setMeta: (additional: KeyringPair$Meta): void => {
meta = { ...meta, ...additional }; meta = objectSpread({}, meta, additional);
}, },
sign: (message: HexString | string | Uint8Array, options: SignOptions = {}): Uint8Array => { sign: (message: HexString | string | Uint8Array, options: SignOptions = {}): Uint8Array => {
assert(!isLocked(secretKey), 'Cannot sign with a locked key pair'); assert(!isLocked(secretKey), 'Cannot sign with a locked key pair');
+3 -3
View File
@@ -4,6 +4,7 @@
import type { KeypairType } from '@polkadot/util-crypto/types'; import type { KeypairType } from '@polkadot/util-crypto/types';
import type { KeyringPair$Json, KeyringPair$Meta } from '../types'; import type { KeyringPair$Json, KeyringPair$Meta } from '../types';
import { objectSpread } from '@polkadot/util';
import { jsonEncryptFormat } from '@polkadot/util-crypto'; import { jsonEncryptFormat } from '@polkadot/util-crypto';
interface PairStateJson { interface PairStateJson {
@@ -12,9 +13,8 @@ interface PairStateJson {
} }
export function pairToJson (type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json { export function pairToJson (type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
return { return objectSpread({}, jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
...jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted),
address, address,
meta meta
}; });
} }
+4 -4
View File
@@ -17,13 +17,13 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4" "@babel/runtime": "^7.16.0"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/util": "7.7.1", "@polkadot/util": "7.8.2",
"@polkadot/x-fetch": "7.7.1" "@polkadot/x-fetch": "7.8.2"
} }
} }
+3
View File
@@ -10,6 +10,9 @@ export const substrateRegistry = 'https://raw.githubusercontent.com/paritytech/s
// last. This make lookups for the current a simple genesisHash[0] // last. This make lookups for the current a simple genesisHash[0]
// (See Kusama as an example) // (See Kusama as an example)
export const knownGenesis: KnownGenesis = { export const knownGenesis: KnownGenesis = {
acala: [
'0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c'
],
bifrost: [ bifrost: [
'0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed' '0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed'
], ],
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/networks', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/networks', version: '7.8.2' };
+13 -4
View File
@@ -270,13 +270,13 @@ export const knownSubstrate: KnownSubstrate[] = [
website: null website: null
}, },
{ {
decimals: [18], decimals: [12, 12],
displayName: 'Dhiway CORD Network', displayName: 'CORD Network',
network: 'cord', network: 'cord',
prefix: 29, prefix: 29,
standardAccount: '*25519', standardAccount: '*25519',
symbols: ['DCU'], symbols: ['DHI', 'WAY'],
website: 'https://dhiway.com/' website: 'https://cord.network/'
}, },
{ {
decimals: [12], decimals: [12],
@@ -638,6 +638,15 @@ export const knownSubstrate: KnownSubstrate[] = [
symbols: ['QTZ'], symbols: ['QTZ'],
website: 'https://unique.network' website: 'https://unique.network'
}, },
{
decimals: [18],
displayName: 'Pioneer Network by Bit.Country',
network: 'pioneer_network',
prefix: 268,
standardAccount: '*25519',
symbols: ['NEER'],
website: 'https://bit.country'
},
{ {
decimals: [18], decimals: [18],
displayName: 'Moonbeam', displayName: 'Moonbeam',
+7 -7
View File
@@ -22,14 +22,14 @@
"./detectPackage.cjs" "./detectPackage.cjs"
], ],
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/networks": "7.7.1", "@polkadot/networks": "7.8.2",
"@polkadot/util": "7.7.1", "@polkadot/util": "7.8.2",
"@polkadot/wasm-crypto": "^4.2.1", "@polkadot/wasm-crypto": "^4.2.1",
"@polkadot/x-randomvalues": "7.7.1", "@polkadot/x-randomvalues": "7.8.2",
"base-x": "^3.0.9", "base-x": "^3.0.9",
"base64-js": "^1.5.1", "base64-js": "^1.5.1",
"blakejs": "^1.1.1", "blakejs": "^1.1.1",
@@ -46,11 +46,11 @@
"devDependencies": { "devDependencies": {
"@types/bn.js": "^4.11.6", "@types/bn.js": "^4.11.6",
"@types/create-hash": "^1.2.2", "@types/create-hash": "^1.2.2",
"@types/elliptic": "^6.4.13", "@types/elliptic": "^6.4.14",
"@types/scryptsy": "^2.0.0", "@types/scryptsy": "^2.0.0",
"@types/xxhashjs": "^0.2.2" "@types/xxhashjs": "^0.2.2"
}, },
"peerDependencies": { "peerDependencies": {
"@polkadot/util": "7.7.1" "@polkadot/util": "7.8.2"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/util-crypto', version: '7.8.2' };
+4 -4
View File
@@ -20,12 +20,12 @@
"./detectPackage.cjs" "./detectPackage.cjs"
], ],
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/x-textdecoder": "7.7.1", "@polkadot/x-textdecoder": "7.8.2",
"@polkadot/x-textencoder": "7.7.1", "@polkadot/x-textencoder": "7.8.2",
"@types/bn.js": "^4.11.6", "@types/bn.js": "^4.11.6",
"bn.js": "^4.12.0", "bn.js": "^4.12.0",
"camelcase": "^6.2.0", "camelcase": "^6.2.0",
+9 -8
View File
@@ -5,6 +5,7 @@ import type { HexString, ToBn, ToBnOptions } from '../types';
import type { BN } from './bn'; import type { BN } from './bn';
import { isNumber } from '../is/number'; import { isNumber } from '../is/number';
import { objectSpread } from '../object/spread';
import { u8aToHex } from '../u8a'; import { u8aToHex } from '../u8a';
import { bnToU8a } from './toU8a'; import { bnToU8a } from './toU8a';
@@ -36,14 +37,14 @@ function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number
return ZERO_STR; return ZERO_STR;
} }
const _options = { return u8aToHex(
isLe: false, bnToU8a(value, objectSpread(
isNegative: false, { isLe: false, isNegative: false },
// Backwards-compatibility isNumber(arg1)
...(isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1) ? { bitLength: arg1, isLe: arg2 }
}; : arg1
))
return u8aToHex(bnToU8a(value, _options)); );
} }
export { bnToHex }; export { bnToHex };
+7 -6
View File
@@ -5,6 +5,7 @@ import type { ToBn, ToBnOptions } from '../types';
import type { BN } from './bn'; import type { BN } from './bn';
import { isNumber } from '../is/number'; import { isNumber } from '../is/number';
import { objectSpread } from '../object/spread';
import { bnToBn } from './toBn'; import { bnToBn } from './toBn';
interface Options extends ToBnOptions { interface Options extends ToBnOptions {
@@ -43,12 +44,12 @@ function createValue (valueBn: BN, byteLength: number, { isLe, isNegative }: Opt
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, 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, 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 { 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 = { const options: Options = objectSpread(
bitLength: -1, { bitLength: -1, isLe: true, isNegative: false },
isLe: true, isNumber(arg1)
isNegative: false, ? { bitLength: arg1, isLe: arg2 }
...isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1 : arg1
}; );
const valueBn = bnToBn(value); const valueBn = bnToBn(value);
const byteLength = options.bitLength === -1 const byteLength = options.bitLength === -1
+2
View File
@@ -15,9 +15,11 @@ export * from './extractTime';
export * from './format'; export * from './format';
export * from './hex'; export * from './hex';
export * from './is'; export * from './is';
export * from './lazy';
export * from './logger'; export * from './logger';
export * from './memoize'; export * from './memoize';
export * from './number'; export * from './number';
export * from './object';
export * from './promisify'; export * from './promisify';
export * from './string'; export * from './string';
export * from './stringify'; export * from './stringify';
+8 -6
View File
@@ -3,6 +3,8 @@
import type { Time } from './types'; import type { Time } from './types';
import { objectSpread } from './object/spread';
const HRS = 60 * 60; const HRS = 60 * 60;
const DAY = HRS * 24; const DAY = HRS * 24;
@@ -21,12 +23,12 @@ function addTime (a: Time, b: Time): Time {
}; };
} }
const ZERO = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 }; const ZERO: Time = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
function extractDays (milliseconds: number, hrs: number): Time { function extractDays (milliseconds: number, hrs: number): Time {
const days = Math.floor(hrs / 24); const days = Math.floor(hrs / 24);
return addTime({ ...ZERO, days }, extractTime(milliseconds - (days * DAY * 1000))); return addTime(objectSpread({}, ZERO, { days }), extractTime(milliseconds - (days * DAY * 1000)));
} }
function extractHrs (milliseconds: number, mins: number): Time { function extractHrs (milliseconds: number, mins: number): Time {
@@ -35,7 +37,7 @@ function extractHrs (milliseconds: number, mins: number): Time {
if (hrs < 24) { if (hrs < 24) {
const hours = Math.floor(hrs); const hours = Math.floor(hrs);
return addTime({ ...ZERO, hours }, extractTime(milliseconds - (hours * HRS * 1000))); return addTime(objectSpread({}, ZERO, { hours }), extractTime(milliseconds - (hours * HRS * 1000)));
} }
return extractDays(milliseconds, hrs); return extractDays(milliseconds, hrs);
@@ -47,7 +49,7 @@ function extractMins (milliseconds: number, secs: number): Time {
if (mins < 60) { if (mins < 60) {
const minutes = Math.floor(mins); const minutes = Math.floor(mins);
return addTime({ ...ZERO, minutes }, extractTime(milliseconds - (minutes * 60 * 1000))); return addTime(objectSpread({}, ZERO, { minutes }), extractTime(milliseconds - (minutes * 60 * 1000)));
} }
return extractHrs(milliseconds, mins); return extractHrs(milliseconds, mins);
@@ -59,7 +61,7 @@ function extractSecs (milliseconds: number): Time {
if (secs < 60) { if (secs < 60) {
const seconds = Math.floor(secs); const seconds = Math.floor(secs);
return addTime({ ...ZERO, seconds }, extractTime(milliseconds - (seconds * 1000))); return addTime(objectSpread({}, ZERO, { seconds }), extractTime(milliseconds - (seconds * 1000)));
} }
return extractMins(milliseconds, secs); return extractMins(milliseconds, secs);
@@ -81,7 +83,7 @@ export function extractTime (milliseconds?: number): Time {
if (!milliseconds) { if (!milliseconds) {
return ZERO; return ZERO;
} else if (milliseconds < 1000) { } else if (milliseconds < 1000) {
return { ...ZERO, milliseconds }; return objectSpread({}, ZERO, { milliseconds });
} }
return extractSecs(milliseconds); return extractSecs(milliseconds);
+7 -10
View File
@@ -5,6 +5,7 @@ import type { ToBnOptions } from '../types';
import { BN } from '../bn/bn'; import { BN } from '../bn/bn';
import { isBoolean } from '../is/boolean'; import { isBoolean } from '../is/boolean';
import { objectSpread } from '../object/spread';
import { hexStripPrefix } from './stripPrefix'; import { hexStripPrefix } from './stripPrefix';
function reverse (value: string): string { function reverse (value: string): string {
@@ -36,16 +37,12 @@ export function hexToBn (value?: string | null, options: ToBnOptions | boolean =
return new BN(0); return new BN(0);
} }
const _options: ToBnOptions = { const _options: ToBnOptions = objectSpread(
isLe: false, { isLe: false, isNegative: false },
isNegative: false, isBoolean(options)
// Backwards-compatibility ? { isLe: options }
...( : options
isBoolean(options) );
? { isLe: options }
: options
)
};
const _value = hexStripPrefix(value); const _value = hexStripPrefix(value);
// FIXME: Use BN's 3rd argument `isLe` once this issue is fixed // FIXME: Use BN's 3rd argument `isLe` once this issue is fixed
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
/**
* @name isArray
* @summary Tests for a Array instance.
*/
export function isArray <T> (value: unknown): value is Array<T> {
return Array.isArray(value);
}
+1 -3
View File
@@ -1,8 +1,6 @@
// Copyright 2017-2021 @polkadot/util authors & contributors // Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { isInstanceOf } from './instanceOf';
/** /**
* @name isError * @name isError
* @summary Tests for a `Error` object instance. * @summary Tests for a `Error` object instance.
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
* ``` * ```
*/ */
export function isError (value: unknown): value is Error { export function isError (value: unknown): value is Error {
return isInstanceOf(value, Error); return value instanceof Error;
} }
+1
View File
@@ -4,6 +4,7 @@
/** /**
* @summary Type checking utilities * @summary Type checking utilities
*/ */
export { isArray } from './array';
export { isAscii } from './ascii'; export { isAscii } from './ascii';
export { isBigInt } from './bigInt'; export { isBigInt } from './bigInt';
export { isBn } from './bn'; export { isBn } from './bn';
+1 -2
View File
@@ -5,8 +5,7 @@ import { isFunction } from './function';
import { isObject } from './object'; import { isObject } from './object';
interface Observable { interface Observable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any next: (...params: unknown[]) => unknown;
next: (...params: any[]) => any;
} }
/** /**
+1 -3
View File
@@ -1,8 +1,6 @@
// Copyright 2017-2021 @polkadot/util authors & contributors // Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { isInstanceOf } from './instanceOf';
/** /**
* @name isU8a * @name isU8a
* @summary Tests for a `Uint8Array` object instance. * @summary Tests for a `Uint8Array` object instance.
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
* ``` * ```
*/ */
export function isU8a (value?: unknown): value is Uint8Array { export function isU8a (value?: unknown): value is Uint8Array {
return isInstanceOf(value, Uint8Array); return value instanceof Uint8Array;
} }
+55
View File
@@ -0,0 +1,55 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isUndefined } from './is/undefined';
type AnyFn = (...args: unknown[]) => unknown;
type WithToString = { toString: () => string };
export function lazyMethod <T, K> (result: Record<string, T> | AnyFn, item: K, creator: (d: K) => T, getName?: (d: K) => string): void {
const name = getName
? getName(item)
: (item as WithToString).toString();
let value: T | undefined;
Object.defineProperty(result, name, {
// This allows for re-configuration with the embedded defineProperty below
// and ensures that on tested browsers and Node, it _will_ be redefined
// and thus short-circuited for future access
configurable: true,
enumerable: true,
// Use a function here, we don't want to capture the outer this, i.e.
// don't use arrow functions in this context since we have a this inside
get: function (): T {
// This check should _always_ be false and unneeded, since we override
// with a value below ... however we ensure we are quire vigilant against
// all environment failures, so we are rather be safe than sorry
if (isUndefined(value)) {
value = creator(item);
try {
// re-define the property as a value, next time around this
// getter will only return the computed value
Object.defineProperty(this, name, { value });
} catch {
// ignore any errors, since this _should_ not happen due to
// the "configurable" property above. But if it ever does
// from here-on we will be the cached value the next time
// around (with a very slight dip in performance)
}
}
return value;
}
});
}
export function lazyMethods <T, K> (result: Record<string, T>, items: K[], creator: (v: K) => T, getName?: (m: K) => string): Record<string, T> {
for (let i = 0; i < items.length; i++) {
lazyMethod(result, items[i], creator, getName);
}
return result;
}
+12
View File
@@ -0,0 +1,12 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { objectClear } from '.';
describe('objectClear', (): void => {
it('clears an object', (): void => {
expect(
objectClear({ a: 1, b: 2, c: { d: 3, e: 4 } })
).toEqual({});
});
});
+12
View File
@@ -0,0 +1,12 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export function objectClear <T> (value: Record<string, T>): Record<string, T> {
const keys = Object.keys(value);
for (let i = 0; i < keys.length; i++) {
delete value[keys[i]];
}
return value;
}
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { objectSpread } from './spread';
export function objectCopy <T extends object> (source: T): T {
return objectSpread({}, source);
}
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { objectClear } from './clear';
export { objectCopy } from './copy';
export { objectProperty, objectProperties } from './property';
export { objectSpread } from './spread';
+20
View File
@@ -0,0 +1,20 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isUndefined } from '../is/undefined';
export function objectProperty (that: object, key: string, getter: (k: string) => unknown): void {
// We use both the hasOwnProperty as well as isUndefined checks here, since it may be set
// in inherited classes and _Own_ properties refers to the class only, not only parents
if (!Object.prototype.hasOwnProperty.call(that, key) && isUndefined((that as Record<string, unknown>)[key])) {
const get = () => getter(key);
Object.defineProperty(that, key, { enumerable: true, get });
}
}
export function objectProperties (that: object, keys: string[], getter: (k: string, i: number) => unknown): void {
for (let i = 0; i < keys.length; i++) {
objectProperty(that, keys[i], (k) => getter(k, i));
}
}
+18
View File
@@ -0,0 +1,18 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { objectSpread } from '.';
describe('objectSpread', (): void => {
it('spreads an object from multiple sources', (): void => {
expect(
objectSpread({ a: 1 }, { b: 2 }, { a: 2, c: { d: 3, e: 4 } })
).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } });
});
it('spreads an object from multiple sources (with null & undefined)', (): void => {
expect(
objectSpread({ a: 1 }, null, { b: 2 }, undefined, { a: 2, c: { d: 3, e: 4 } })
).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } });
});
});
+20
View File
@@ -0,0 +1,20 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export function objectSpread <T extends object> (dest: object, ...sources: (object | undefined | null)[]): T {
for (let i = 0; i < sources.length; i++) {
const src = sources[i];
if (src) {
const keys = Object.keys(src);
for (let j = 0; j < keys.length; j++) {
const key = keys[j];
(dest as Record<string, unknown>)[key] = (src as Record<string, unknown>)[key];
}
}
}
return dest as T;
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/util', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/util', version: '7.8.2' };
+3 -3
View File
@@ -17,11 +17,11 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/util": "7.7.1", "@polkadot/util": "7.8.2",
"buffer-es6": "^4.9.3" "buffer-es6": "^4.9.3"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-bundle', version: '7.8.2' };
+4 -4
View File
@@ -17,14 +17,14 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"browser": "browser.js", "browser": "browser.js",
"main": "node.js", "main": "node.js",
"react-native": "react-native.js", "react-native": "react-native.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.7.1", "@polkadot/x-global": "7.8.2",
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
"node-fetch": "^2.6.5" "node-fetch": "^2.6.6"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-fetch', version: '7.8.2' };
+2 -2
View File
@@ -17,9 +17,9 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4" "@babel/runtime": "^7.16.0"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-global', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-global', version: '7.8.2' };
+4 -4
View File
@@ -17,15 +17,15 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"browser": "browser.js", "browser": "browser.js",
"main": "node.js", "main": "node.js",
"react-native": "react-native.js", "react-native": "react-native.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.7.1" "@polkadot/x-global": "7.8.2"
}, },
"devDependencies": { "devDependencies": {
"@types/react-native": "^0.66.1" "@types/react-native": "^0.66.2"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.8.2' };
+3 -3
View File
@@ -17,12 +17,12 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"browser": "browser.js", "browser": "browser.js",
"main": "node.js", "main": "node.js",
"react-native": "react-native.js", "react-native": "react-native.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.7.1" "@polkadot/x-global": "7.8.2"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.8.2' };
+3 -3
View File
@@ -17,12 +17,12 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"browser": "browser.js", "browser": "browser.js",
"main": "node.js", "main": "node.js",
"react-native": "react-native.js", "react-native": "react-native.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.7.1" "@polkadot/x-global": "7.8.2"
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.8.2' };
+3 -3
View File
@@ -17,13 +17,13 @@
}, },
"sideEffects": false, "sideEffects": false,
"type": "module", "type": "module",
"version": "7.7.1", "version": "7.8.2",
"browser": "browser.js", "browser": "browser.js",
"main": "node.js", "main": "node.js",
"react-native": "react-native.js", "react-native": "react-native.js",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.15.4", "@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.7.1", "@polkadot/x-global": "7.8.2",
"@types/websocket": "^1.0.4", "@types/websocket": "^1.0.4",
"websocket": "^1.0.34" "websocket": "^1.0.34"
} }
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit // Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-ws', version: '7.7.1' }; export const packageInfo = { name: '@polkadot/x-ws', version: '7.8.2' };
+748 -739
View File
File diff suppressed because it is too large Load Diff