Compare commits

...
44 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
Github Actions d3c8112f66 [CI Skip] release/stable 7.7.1
skip-checks: true
2021-10-31 14:51:24 +00:00
Jaco 8880e8fa8c 7.7.1 (#1152)
* 7.7.1

* Extract stringify replacer

* formatting

* linting

* isUnSorted{A, B}

* Adjust

* Complexity?

* Cleanups

* Update packages/util-crypto/src/address/derive.ts

* formatBalance

* Revert formatBalance
2021-10-31 16:44:17 +02:00
Github Actions 481f7f6ee0 [CI Skip] release/beta 7.6.2-8
skip-checks: true
2021-10-31 06:34:35 +00:00
Jaco a4cefa4bfc Adjust base library usage of for vs reduce/map (#1151)
* Adjust base library usage of `for` vs `reduce/map`

* Additional

* Adjust
2021-10-31 08:27:14 +02:00
Github Actions 7ef169585f [CI Skip] release/beta 7.6.2-7
skip-checks: true
2021-10-30 15:52:24 +00:00
Jaco 134b8c3b9f arrayZip (#1150)
* arrayZip

* Update packages/util/src/array/zip.spec.ts

* Update packages/util/src/array/zip.ts
2021-10-30 18:45:20 +03:00
Github Actions 1158551b9e [CI Skip] release/beta 7.6.2-6
skip-checks: true
2021-10-29 07:41:53 +00:00
Jaco 4c2521bc21 Bump deps, update CHANGELOG (#1149) 2021-10-29 10:33:07 +03:00
Github Actions 993e45d148 [CI Skip] release/beta 7.6.2-5
skip-checks: true
2021-10-27 13:46:16 +00:00
Igor 14a0c3f18b Support genshiro network (#1148)
* support genshiro network

* remove registry
2021-10-27 16:39:08 +03:00
Github Actions 9fa71647c1 [CI Skip] release/beta 7.6.2-4
skip-checks: true
2021-10-26 07:17:00 +00:00
Jaco cac98aac03 Adjust testnet detection in @polkadot/networks (#1147) 2021-10-26 10:08:52 +03:00
Github Actions 48158927e1 [CI Skip] release/beta 7.6.2-3
skip-checks: true
2021-10-25 13:33:33 +00:00
Jaco 51082373e6 Bump dev deps (#1145) 2021-10-25 16:26:18 +03:00
Github Actions bf80f76173 [CI Skip] release/beta 7.6.2-2
skip-checks: true
2021-10-25 11:41:59 +00:00
Jaco 474e98b6d1 Bump dev (#1144) 2021-10-25 14:34:55 +03:00
Github Actions 07317b8840 [CI Skip] release/beta 7.6.2-1
skip-checks: true
2021-10-25 09:23:22 +00:00
Jaco 2e46b688cf Update repository location (#1143)
* Update repository location

* Adjust
2021-10-25 12:15:22 +03:00
Github Actions c87cf8c655 [CI Skip] release/beta 7.6.2-0
skip-checks: true
2021-10-25 05:13:27 +00:00
Jaco 9eabf95fc0 Assert chainCode inputs to derive* (#1142)
* Assert chainCode inputs to derive*

* Adjust
2021-10-25 08:04:37 +03:00
91 changed files with 1726 additions and 1265 deletions
+2 -1
View File
@@ -17,4 +17,5 @@
7.0.2
7.0.3
7.1.2
7.1.2
7.8.2
+36
View File
@@ -1,5 +1,41 @@
# 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
Contributed:
- Add Genshiro support (Thanks to https://github.com/Overseven)
Changes:
- Add `arrayZip` to combine a key + value array into entries-like
- Assert `chainCode` inputs to `derive*`, protecting against misuse
- Adjust testnet detection in `@polkadot/networks`
- Adjust base library usage of `for` vs `reduce/map`
- Bump Ledger libraries to latest versions
## 7.6.1 Oct 23, 2021
Changes:
+17 -11
View File
@@ -1,34 +1,40 @@
{
"repository": "https://github.com/polkadot-js/common",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common#readme",
"license": "Apache-2",
"packageManager": "yarn@3.0.1",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"version": "7.8.2",
"workspaces": [
"packages/*"
],
"resolutions": {
"typescript": "^4.4.4"
},
"scripts": {
"build": "polkadot-dev-build-ts",
"build:release": "polkadot-ci-ghact-build",
"build:rollup": "polkadot-exec-rollup --config",
"lint": "polkadot-dev-run-lint",
"clean": "polkadot-dev-clean-build",
"lint": "polkadot-dev-run-lint",
"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",
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck --testPathIgnorePatterns toMiniSecretCmp",
"test:mnemonicCmp": "polkadot-dev-run-test packages/util-crypto/src/mnemonic/toMiniSecretCmp.spec.ts",
"test:one": "polkadot-dev-run-test --runInBand"
},
"devDependencies": {
"@babel/core": "^7.15.8",
"@polkadot/dev": "^0.63.6",
"@polkadot/ts": "^0.4.10",
"@babel/core": "^7.16.0",
"@polkadot/dev": "^0.63.27",
"@polkadot/ts": "^0.4.13",
"@types/ed2curve": "^0.2.2",
"@types/jest": "^27.0.2"
},
"version": "7.6.1",
"packageManager": "yarn@3.0.1"
"resolutions": {
"typescript": "^4.4.4"
}
}
+21 -15
View File
@@ -1,26 +1,32 @@
{
"name": "@polkadot/hw-ledger-transports",
"version": "7.6.1",
"type": "module",
"repository": "github:polkadot-js/common",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"license": "Apache-2.0",
"main": "node.js",
"browser": "browser.js",
"react-native": "react-native.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/hw-ledger-transports#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/hw-ledger-transports",
"repository": {
"directory": "packages/hw-ledger-transports",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@ledgerhq/hw-transport": "^6.11.0",
"@ledgerhq/hw-transport-webhid": "^6.11.0",
"@ledgerhq/hw-transport-webusb": "^6.11.0"
"@babel/runtime": "^7.16.0",
"@ledgerhq/hw-transport": "^6.11.2",
"@ledgerhq/hw-transport-webhid": "^6.11.2",
"@ledgerhq/hw-transport-webusb": "^6.11.2"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-node-hid-singleton": "^6.11.0"
"@ledgerhq/hw-transport-node-hid-singleton": "^6.11.2"
}
}
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.8.2' };
+18 -12
View File
@@ -1,24 +1,30 @@
{
"name": "@polkadot/hw-ledger",
"version": "7.6.1",
"type": "module",
"repository": "github:polkadot-js/common",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/hw-ledger#readme",
"license": "Apache-2.0",
"main": "index.js",
"maintainers": [],
"name": "@polkadot/hw-ledger",
"repository": {
"directory": "packages/hw-ledger",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": [
"./detectPackage.js",
"./detectPackage.cjs"
],
"engines": {
"node": ">=14.0.0"
},
"type": "module",
"version": "7.8.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/hw-ledger-transports": "7.6.1",
"@polkadot/util": "7.6.1",
"@babel/runtime": "^7.16.0",
"@polkadot/hw-ledger-transports": "7.8.2",
"@polkadot/util": "7.8.2",
"@zondax/ledger-substrate": "^0.18.0"
}
}
+2 -1
View File
@@ -4,7 +4,7 @@
import type Transport from '@ledgerhq/hw-transport';
import type { SubstrateApp } from '@zondax/ledger-substrate';
import { newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newStatemineApp } from '@zondax/ledger-substrate';
import { newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newStatemineApp } from '@zondax/ledger-substrate';
// These match up with the keys of the knownLedger object in the @polkadot/networks/defaults.ts
export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp> = {
@@ -12,6 +12,7 @@ export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp>
'dock-mainnet': newDockApp,
edgeware: newEdgewareApp,
equilibrium: newEquilibriumApp,
genshiro: newGenshiroApp,
kusama: newKusamaApp,
'nodle-chain': newNodleApp,
polkadot: newPolkadotApp,
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.6.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
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
export type LedgerTypes = 'hid' | 'u2f' | 'webusb';
export interface AccountOptions {
@@ -15,7 +17,7 @@ export interface LedgerAddress {
}
export interface LedgerSignature {
signature: string;
signature: HexString;
}
export interface LedgerVersion {
+21 -17
View File
@@ -1,30 +1,34 @@
{
"name": "@polkadot/keyring",
"version": "7.6.1",
"type": "module",
"description": "Keyring management",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "Keyring management",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
"license": "Apache-2.0",
"main": "index.js",
"maintainers": [],
"name": "@polkadot/keyring",
"repository": {
"directory": "packages/keyring",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": [
"./detectPackage.js",
"./detectPackage.cjs"
],
"engines": {
"node": ">=14.0.0"
},
"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",
"type": "module",
"version": "7.8.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/util": "7.6.1",
"@polkadot/util-crypto": "7.6.1"
"@babel/runtime": "^7.16.0",
"@polkadot/util": "7.8.2",
"@polkadot/util-crypto": "7.8.2"
},
"peerDependencies": {
"@polkadot/util": "7.6.1",
"@polkadot/util-crypto": "7.6.1"
"@polkadot/util": "7.8.2",
"@polkadot/util-crypto": "7.8.2"
}
}
+5 -5
View File
@@ -18,6 +18,10 @@ const keypairFromSeed = {
sr25519: (seed: Uint8Array): Keypair => schnorrkelFromSeed(seed)
};
function pairToPublic ({ publicKey }: KeyringPair): Uint8Array {
return publicKey;
}
/**
* # @polkadot/keyring
*
@@ -262,11 +266,7 @@ export class Keyring implements KeyringInstance {
* @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
*/
public getPublicKeys (): Uint8Array[] {
return this.#pairs
.all()
.map(({ publicKey }): Uint8Array =>
publicKey
);
return this.#pairs.all().map(pairToPublic);
}
/**
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/keyring', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/keyring', version: '7.8.2' };
+3 -4
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 { PairInfo } from './types';
import { assert, u8aConcat, 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 { decodePair } from './decode';
@@ -48,9 +48,8 @@ const TYPE_ADDRESS = {
sr25519: (p: Uint8Array) => p
};
// Not 100% correct, since it can be a Uint8Array, but an invalid one - just say "undefined" is anything non-valid
function isLocked (secretKey?: Uint8Array): secretKey is undefined {
return !secretKey || secretKey.length === 0 || secretKey.every((b) => b === 0);
return !secretKey || u8aEmpty(secretKey);
}
function vrfHash (proof: Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array {
@@ -182,7 +181,7 @@ export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: P
secretKey = new Uint8Array();
},
setMeta: (additional: KeyringPair$Meta): void => {
meta = { ...meta, ...additional };
meta = objectSpread({}, meta, additional);
},
sign: (message: HexString | string | Uint8Array, options: SignOptions = {}): Uint8Array => {
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 { KeyringPair$Json, KeyringPair$Meta } from '../types';
import { objectSpread } from '@polkadot/util';
import { jsonEncryptFormat } from '@polkadot/util-crypto';
interface PairStateJson {
@@ -12,9 +13,8 @@ interface PairStateJson {
}
export function pairToJson (type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
return {
...jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted),
return objectSpread({}, jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
address,
meta
};
});
}
+2 -2
View File
@@ -121,7 +121,7 @@ export function createTestKeyring (options: KeyringOptions = {}, isDerived = tru
const keyring = new Keyring(options);
const pairs: PairDef[] = (options.type && options.type === 'ethereum') ? PAIRSETHEREUM : PAIRSSR25519;
pairs.forEach(({ name, publicKey, secretKey, seed, type }): void => {
for (const { name, publicKey, secretKey, seed, type } of pairs) {
if (!name && !seed) {
throw new Error('Testing pair should have either a name or a seed');
}
@@ -139,7 +139,7 @@ export function createTestKeyring (options: KeyringOptions = {}, isDerived = tru
pair.lock = (): void => {
// we don't have lock/unlock functionality here
};
});
}
return keyring;
}
+4 -6
View File
@@ -15,11 +15,9 @@ export function createTestPairs (options?: KeyringOptions, isDerived = true): Te
const pairs = keyring.getPairs();
const map: TestKeyringMap = { nobody: nobody() };
return pairs.reduce((result, pair): TestKeyringMap => {
const { name } = pair.meta;
for (const p of pairs) {
map[p.meta.name as string] = p;
}
result[name as string] = pair;
return result;
}, map);
return map;
}
+18 -14
View File
@@ -1,25 +1,29 @@
{
"name": "@polkadot/networks",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A list of all available Substrate networks and their applicable prefixes",
"main": "index.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"repository": "github:polkadot-js/common",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/networks#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/networks",
"repository": {
"directory": "packages/networks",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.15.4"
"@babel/runtime": "^7.16.0"
},
"devDependencies": {
"@polkadot/util": "7.6.1",
"@polkadot/x-fetch": "7.6.1"
"@polkadot/util": "7.8.2",
"@polkadot/x-fetch": "7.8.2"
}
}
+7
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]
// (See Kusama as an example)
export const knownGenesis: KnownGenesis = {
acala: [
'0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c'
],
bifrost: [
'0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed'
],
@@ -25,6 +28,9 @@ export const knownGenesis: KnownGenesis = {
equilibrium: [
'0x6f1a800de3daff7f5e037ddf66ab22ce03ab91874debeddb1086f5f7dbd48925'
],
genshiro: [
'0x9b8cefc0eb5c568b527998bdd76c184e2b76ae561be76e4667072230217ea243'
],
hydradx: [
'0xd2a620c27ec5cbc5621ff9a522689895074f7cca0d08e7134a7804e1a3ba86fc', // Snakenet Gen3-1
'0x10af6e84234477d84dc572bac0789813b254aa490767ed06fb9591191d1073f9', // Snakenet Gen3
@@ -83,6 +89,7 @@ export const knownLedger: KnownLedger = {
'dock-mainnet': 0x00000252,
edgeware: 0x0000020b,
equilibrium: 0x05f5e0fd,
genshiro: 0x05f5e0fc,
kusama: 0x000001b2,
'nodle-chain': 0x000003eb,
polkadot: 0x00000162,
+37 -16
View File
@@ -1,43 +1,64 @@
// Copyright 2017-2021 @polkadot/networks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Network, SubstrateNetwork } from './types';
import type { KnownSubstrate, Network, SubstrateNetwork } from './types';
import { knownGenesis, knownIcon, knownLedger, knownTestnet } from './defaults';
import { knownSubstrate } from './substrate';
// These are known prefixes that are not sorted
const UNSORTED = [0, 2, 42];
const TESTNETS = ['testnet'];
export const allNetworks = knownSubstrate.map((o): SubstrateNetwork => {
function toExpanded (o: KnownSubstrate): SubstrateNetwork {
const network = o.network || '';
const nameParts = network.replace(/_/g, '-').split('-');
const n = o as SubstrateNetwork;
// ledger additions
n.slip44 = knownLedger[network];
n.hasLedgerSupport = !!n.slip44;
// general items
n.genesisHash = knownGenesis[network] || [];
n.icon = knownIcon[network] || 'substrate';
n.isIgnored = !!knownTestnet[network] || (!(o.standardAccount && o.decimals && o.symbols) && o.prefix !== 42);
// filtering
n.isTestnet = !!knownTestnet[network] || TESTNETS.includes(nameParts[nameParts.length - 1]);
n.isIgnored = n.isTestnet || (!(o.standardAccount && o.decimals && o.symbols) && o.prefix !== 42);
return n;
});
}
function filterSelectable ({ genesisHash, prefix }: Network): boolean {
return !!genesisHash.length || prefix === 42;
}
function filterAvailable (n: SubstrateNetwork): n is Network {
return !n.isIgnored && !!n.network;
}
function sortNetworks (a: Network, b: Network): number {
const isUnSortedA = UNSORTED.includes(a.prefix);
const isUnSortedB = UNSORTED.includes(b.prefix);
return isUnSortedA === isUnSortedB
? 0
: isUnSortedA
? -1
: isUnSortedB
? 1
: a.displayName.localeCompare(b.displayName);
}
// This is all the Substrate networks with our additional information
export const allNetworks = knownSubstrate.map(toExpanded);
// The list of available/claimed prefixes
// - no testnets
// - we only include those where we have a standardAccount
// - sort by name, however we keep 0, 2, 42 first in the list
export const availableNetworks = allNetworks
.filter((n): n is Network => !n.isIgnored && !!n.network)
.sort((a, b) =>
UNSORTED.includes(a.prefix) === UNSORTED.includes(b.prefix)
? 0
: UNSORTED.includes(a.prefix)
? -1
: UNSORTED.includes(b.prefix)
? 1
: a.displayName.localeCompare(b.displayName)
);
export const availableNetworks = allNetworks.filter(filterAvailable).sort(sortNetworks);
// A filtered list of those chains we have details about (genesisHashes)
export const selectableNetworks = availableNetworks.filter((n) => n.genesisHash.length || n.prefix === 42);
export const selectableNetworks = availableNetworks.filter(filterSelectable);
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/networks', version: '7.6.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
},
{
decimals: [18],
displayName: 'Dhiway CORD Network',
decimals: [12, 12],
displayName: 'CORD Network',
network: 'cord',
prefix: 29,
standardAccount: '*25519',
symbols: ['DCU'],
website: 'https://dhiway.com/'
symbols: ['DHI', 'WAY'],
website: 'https://cord.network/'
},
{
decimals: [12],
@@ -638,6 +638,15 @@ export const knownSubstrate: KnownSubstrate[] = [
symbols: ['QTZ'],
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],
displayName: 'Moonbeam',
+1
View File
@@ -26,6 +26,7 @@ export interface SubstrateNetwork extends KnownSubstrate {
hasLedgerSupport: boolean;
icon: Icon;
isIgnored: boolean;
isTestnet: boolean;
slip44?: number | null;
}
+24 -20
View File
@@ -1,31 +1,35 @@
{
"name": "@polkadot/util-crypto",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A collection of useful crypto utilities for @polkadot",
"main": "index.js",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/util-crypto",
"repository": {
"directory": "packages/util-crypto",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": [
"./cryptoInit.js",
"./cryptoInit.cjs",
"./detectPackage.js",
"./detectPackage.cjs"
],
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
"type": "module",
"version": "7.8.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/networks": "7.6.1",
"@polkadot/util": "7.6.1",
"@babel/runtime": "^7.16.0",
"@polkadot/networks": "7.8.2",
"@polkadot/util": "7.8.2",
"@polkadot/wasm-crypto": "^4.2.1",
"@polkadot/x-randomvalues": "7.6.1",
"@polkadot/x-randomvalues": "7.8.2",
"base-x": "^3.0.9",
"base64-js": "^1.5.1",
"blakejs": "^1.1.1",
@@ -42,11 +46,11 @@
"devDependencies": {
"@types/bn.js": "^4.11.6",
"@types/create-hash": "^1.2.2",
"@types/elliptic": "^6.4.13",
"@types/elliptic": "^6.4.14",
"@types/scryptsy": "^2.0.0",
"@types/xxhashjs": "^0.2.2"
},
"peerDependencies": {
"@polkadot/util": "7.6.1"
"@polkadot/util": "7.8.2"
}
}
+7 -1
View File
@@ -1,12 +1,18 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Network } from '@polkadot/networks/types';
import { availableNetworks } from '../networks';
function networkToPrefix ({ prefix }: Network): number {
return prefix;
}
export const defaults = {
allowedDecodedLengths: [1, 2, 4, 8, 32, 33],
// publicKey has prefix + 2 checksum bytes, short only prefix + 1 checksum byte
allowedEncodedLengths: [3, 4, 6, 10, 35, 36, 37, 38],
allowedPrefix: availableNetworks.map(({ prefix }) => prefix),
allowedPrefix: availableNetworks.map(networkToPrefix),
prefix: 42
};
+13 -5
View File
@@ -2,16 +2,20 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { DeriveJunction } from '../key/DeriveJunction';
import type { Prefix } from './types';
import { assert } from '@polkadot/util';
import { keyExtractPath } from '../key';
import { DeriveJunction } from '../key/DeriveJunction';
import { schnorrkelDerivePublic } from '../schnorrkel';
import { decodeAddress } from './decode';
import { encodeAddress } from './encode';
function filterHard ({ isHard }: DeriveJunction): boolean {
return isHard;
}
/**
* @name deriveAddress
* @summary Creates a sr25519 derived address from the supplied and path.
@@ -21,9 +25,13 @@ import { encodeAddress } from './encode';
export function deriveAddress (who: HexString | Uint8Array | string, suri: string, ss58Format?: Prefix): string {
const { path } = keyExtractPath(suri);
assert(path.length && !path.some((path) => path.isHard), 'Expected suri to contain a combination of non-hard paths');
assert(path.length && !path.every(filterHard), 'Expected suri to contain a combination of non-hard paths');
return encodeAddress(path.reduce((publicKey: Uint8Array, path: DeriveJunction): Uint8Array => {
return schnorrkelDerivePublic(publicKey, path.chainCode);
}, decodeAddress(who)), ss58Format);
let publicKey = decodeAddress(who);
for (const { chainCode } of path) {
publicKey = schnorrkelDerivePublic(publicKey, chainCode);
}
return encodeAddress(publicKey, ss58Format);
}
+2 -2
View File
@@ -7,7 +7,7 @@ import type { HexString } from '@polkadot/util/types';
import { bnToU8a, compactToU8a, stringToU8a, u8aConcat, u8aSorted } from '@polkadot/util';
import { blake2AsU8a } from '../blake2/asU8a';
import { decodeAddress } from './decode';
import { addressToU8a } from './util';
const PREFIX = stringToU8a('modlpy/utilisuba');
@@ -16,7 +16,7 @@ export function createKeyMulti (who: (HexString | Uint8Array | string)[], thresh
u8aConcat(
PREFIX,
compactToU8a(who.length),
...u8aSorted(who.map((who) => decodeAddress(who))),
...u8aSorted(who.map(addressToU8a)),
bnToU8a(threshold, { bitLength: 16, isLe: true })
)
);
+5 -3
View File
@@ -6,11 +6,13 @@ import type { Prefix } from './types';
import { u8aSorted } from '@polkadot/util';
import { decodeAddress } from './decode';
import { encodeAddress } from './encode';
import { addressToU8a } from './util';
export function sortAddresses (addresses: (HexString | Uint8Array | string)[], ss58Format?: Prefix): string[] {
const u8aToAddress = (u8a: Uint8Array) => encodeAddress(u8a, ss58Format);
return u8aSorted(
addresses.map((who) => decodeAddress(who))
).map((u8a) => encodeAddress(u8a, ss58Format));
addresses.map(addressToU8a)
).map(u8aToAddress);
}
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { decodeAddress } from './decode';
export function addressToU8a (who: string | Uint8Array): Uint8Array {
return decodeAddress(who);
}
+4 -6
View File
@@ -9,13 +9,11 @@ import { BASE32_ALPHABET, BITS_PER_CHAR } from './bs32';
import { base32Validate } from './validate';
// Build the character lookup table:
const LOOKUP = BASE32_ALPHABET
.split('')
.reduce((lookup: Record<string, number>, char: string, index: number): Record<string, number> => {
lookup[char] = index;
const LOOKUP = BASE32_ALPHABET.split('').reduce<Record<string, number>>((lookup, a, i) => {
lookup[a] = i;
return lookup;
}, {});
return lookup;
}, {});
/** @internal */
function decode (output: Uint8Array, input: string, offset: number): [Uint8Array, number, number] {
+12 -13
View File
@@ -44,7 +44,7 @@ function deriveChild (hd: CodedKeypair, index: number): CodedKeypair {
export function hdEthereum (seed: Uint8Array, path = ''): Keypair {
const I = hmacSha512(MASTER_SECRET, seed);
const hd = createCoded(I.slice(0, 32), I.slice(32));
let hd = createCoded(I.slice(0, 32), I.slice(32));
if (!path || path === 'm' || path === 'M' || path === "m'" || path === "M'") {
return hd;
@@ -52,16 +52,15 @@ export function hdEthereum (seed: Uint8Array, path = ''): Keypair {
assert(hdValidatePath(path), 'Invalid derivation path');
return path
.split('/')
.slice(1)
.reduce((hd: CodedKeypair, c): CodedKeypair =>
deriveChild(
hd, parseInt(c, 10) + (
(c.length > 1) && c.endsWith("'")
? HARDENED
: 0
)
), hd
);
const parts = path.split('/').slice(1);
for (const p of parts) {
hd = deriveChild(hd, parseInt(p, 10) + (
(p.length > 1) && p.endsWith("'")
? HARDENED
: 0
));
}
return hd;
}
+15 -14
View File
@@ -12,27 +12,28 @@ import { ledgerDerivePrivate } from './derivePrivate';
import { ledgerMaster } from './master';
export function hdLedger (_mnemonic: string, path: string): Keypair {
const parts = _mnemonic
const words = _mnemonic
.split(' ')
.map((s) => s.trim())
.filter((s) => s);
assert([12, 24, 25].includes(parts.length), 'Expected a mnemonic with 24 words (or 25 including a password)');
assert([12, 24, 25].includes(words.length), 'Expected a mnemonic with 24 words (or 25 including a password)');
const [mnemonic, password] = parts.length === 25
? [parts.slice(0, 24).join(' '), parts[24]]
: [parts.join(' '), ''];
const [mnemonic, password] = words.length === 25
? [words.slice(0, 24).join(' '), words[24]]
: [words.join(' '), ''];
assert(mnemonicValidate(mnemonic), 'Invalid mnemonic passed to ledger derivation');
assert(hdValidatePath(path), 'Invalid derivation path');
return naclKeypairFromSeed(
path
.split('/')
.slice(1)
.map((n) => parseInt(n.replace(/'$/, ''), 10))
.map((n) => (n < HARDENED) ? (n + HARDENED) : n)
.reduce((x, n) => ledgerDerivePrivate(x, n), ledgerMaster(mnemonic, password))
.slice(0, 32)
);
const parts = path.split('/').slice(1);
let seed = ledgerMaster(mnemonic, password);
for (const p of parts) {
const n = parseInt(p.replace(/'$/, ''), 10);
seed = ledgerDerivePrivate(seed, (n < HARDENED) ? (n + HARDENED) : n);
}
return naclKeypairFromSeed(seed.slice(0, 32));
}
+11 -5
View File
@@ -10,9 +10,15 @@ export function hdValidatePath (path: string): boolean {
const parts = path.split('/').slice(1);
return parts.every((n) => /^\d+'?$/.test(n)) && (
!parts
.map((n) => parseInt(n.replace(/'$/, ''), 10))
.some((n) => isNaN(n) || (n >= HARDENED) || (n < 0))
);
for (const p of parts) {
const n = /^\d+'?$/.test(p)
? parseInt(p.replace(/'$/, ''), 10)
: Number.NaN;
if (isNaN(n) || (n >= HARDENED) || (n < 0)) {
return false;
}
}
return true;
}
+3 -3
View File
@@ -23,9 +23,9 @@ export function keyExtractPath (derivePath: string): ExtractResult {
if (parts) {
constructed = parts.join('');
parts.forEach((value: string): void => {
path.push(DeriveJunction.from(value.substr(1)));
});
for (const p of parts) {
path.push(DeriveJunction.from(p.substr(1)));
}
}
assert(constructed === derivePath, () => `Re-constructed path "${constructed}" does not match input`);
+6 -3
View File
@@ -18,8 +18,11 @@ const generators = {
export function keyFromPath (pair: Keypair, path: DeriveJunction[], type: KeypairType): Keypair {
const keyHdkd = generators[type];
let result = pair;
return path.reduce((pair, junction): Keypair => {
return keyHdkd(pair, junction);
}, pair);
for (const junction of path) {
result = keyHdkd(result, junction);
}
return result;
}
+3 -1
View File
@@ -1,13 +1,15 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { compactAddLength, stringToU8a, u8aConcat } from '@polkadot/util';
import { assert, compactAddLength, isU8a, stringToU8a, u8aConcat } from '@polkadot/util';
import { blake2AsU8a } from '../blake2/asU8a';
const HDKD = compactAddLength(stringToU8a('Ed25519HDKD'));
export function naclDeriveHard (seed: Uint8Array, chainCode: Uint8Array): Uint8Array {
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
return blake2AsU8a(
u8aConcat(HDKD, seed, chainCode)
);
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.8.2' };
@@ -1,20 +1,19 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Keypair } from '../types';
import { u8aToU8a } from '@polkadot/util';
import { assert, isU8a } from '@polkadot/util';
import { schnorrkelKeypairFromU8a } from './keypair/fromU8a';
import { schnorrkelKeypairToU8a } from './keypair/toU8a';
export function createDeriveFn (derive: (pair: Uint8Array, cc: Uint8Array) => Uint8Array): (keypair: Keypair, chainCode: HexString | Uint8Array | string) => Keypair {
return (keypair: Keypair, chainCode: HexString | Uint8Array | string) =>
schnorrkelKeypairFromU8a(
derive(
schnorrkelKeypairToU8a(keypair),
u8aToU8a(chainCode)
)
export function createDeriveFn (derive: (pair: Uint8Array, cc: Uint8Array) => Uint8Array): (keypair: Keypair, chainCode: Uint8Array) => Keypair {
return (keypair: Keypair, chainCode: Uint8Array): Keypair => {
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
return schnorrkelKeypairFromU8a(
derive(schnorrkelKeypairToU8a(keypair), chainCode)
);
};
}
@@ -3,13 +3,14 @@
import type { HexString } from '@polkadot/util/types';
import { assert, u8aToU8a } from '@polkadot/util';
import { assert, isU8a, u8aToU8a } from '@polkadot/util';
import { sr25519DerivePublicSoft } from '@polkadot/wasm-crypto';
export function schnorrkelDerivePublic (publicKey: HexString | Uint8Array | string, chainCode: HexString | Uint8Array | string): Uint8Array {
export function schnorrkelDerivePublic (publicKey: HexString | Uint8Array | string, chainCode: Uint8Array): Uint8Array {
const publicKeyU8a = u8aToU8a(publicKey);
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
assert(publicKeyU8a.length === 32, () => `Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
return sr25519DerivePublicSoft(publicKeyU8a, u8aToU8a(chainCode));
return sr25519DerivePublicSoft(publicKeyU8a, chainCode);
}
@@ -1,13 +1,15 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { compactAddLength, stringToU8a, u8aConcat } from '@polkadot/util';
import { assert, compactAddLength, isU8a, stringToU8a, u8aConcat } from '@polkadot/util';
import { blake2AsU8a } from '../blake2/asU8a';
const HDKD = compactAddLength(stringToU8a('Secp256k1HDKD'));
export function secp256k1DeriveHard (seed: Uint8Array, chainCode: Uint8Array): Uint8Array {
assert(isU8a(chainCode) && chainCode.length === 32, 'Invalid chainCode passed to derive');
// NOTE This is specific to the Substrate HDD derivation, so always use the blake2 hasher
return blake2AsU8a(u8aConcat(HDKD, seed, chainCode), 256);
}
+21 -17
View File
@@ -1,27 +1,31 @@
{
"name": "@polkadot/util",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A collection of useful utilities for @polkadot",
"main": "index.js",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/util",
"repository": {
"directory": "packages/util",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": [
"./detectPackage.js",
"./detectPackage.cjs"
],
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"type": "module",
"version": "7.8.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/x-textdecoder": "7.6.1",
"@polkadot/x-textencoder": "7.6.1",
"@babel/runtime": "^7.16.0",
"@polkadot/x-textdecoder": "7.8.2",
"@polkadot/x-textencoder": "7.8.2",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.12.0",
"camelcase": "^6.2.0",
+10 -6
View File
@@ -20,15 +20,19 @@
*/
export function arrayFlatten <T> (arrays: T[][]): T[] {
// pre-allocate based on the combined size
const output = new Array<T>(arrays.reduce((length, array) => length + array.length, 0));
let size = 0;
for (const a of arrays) {
size += a.length;
}
const output = new Array<T>(size);
let index = -1;
for (let a = 0; a < arrays.length; a++) {
const array = arrays[a];
for (const a of arrays) {
// instead of pushing, we just set the entries
for (let e = 0; e < array.length; e++) {
output[++index] = array[e];
for (let e = 0; e < a.length; e++) {
output[++index] = a[e];
}
}
+1
View File
@@ -10,3 +10,4 @@ export { arrayFilter } from './filter';
export { arrayFlatten } from './flatten';
export { arrayRange } from './range';
export { arrayShuffle } from './shuffle';
export { arrayZip } from './zip';
+7 -1
View File
@@ -21,5 +21,11 @@ import { assert } from '../assert';
export function arrayRange (size: number, startAt = 0): number[] {
assert(size > 0, 'Expected non-zero, positive number as a range size');
return new Array(size).fill(0).map((_, i) => i + startAt);
const result = new Array<number>(size).fill(0);
for (let i = 0; i < result.length; i++) {
result[i] = i + startAt;
}
return result;
}
+24
View File
@@ -0,0 +1,24 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { arrayZip } from '.';
describe('arrayZip', (): void => {
it('zips a simple one', (): void => {
expect(
arrayZip(['a', 'b', 'c'], [1, 2, 3])
).toEqual([['a', 1], ['b', 2], ['c', 3]]);
});
it('zips where values > keys', (): void => {
expect(
arrayZip(['a', 'b', 'c'], [1, 2, 3, 4])
).toEqual([['a', 1], ['b', 2], ['c', 3]]);
});
it('zips where values < keys', (): void => {
expect(
arrayZip(['a', 'b', 'c'], [1, 2])
).toEqual([['a', 1], ['b', 2], ['c', undefined]]);
});
});
+12
View File
@@ -0,0 +1,12 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export function arrayZip <K, V> (keys: K[], values: V[]): [K, V][] {
const result = new Array<[K, V]>(keys.length);
for (let i = 0; i < keys.length; i++) {
result[i] = [keys[i], values[i]];
}
return result;
}
+6
View File
@@ -9,4 +9,10 @@ describe('bnMax', (): void => {
bnMax(new BN(1), new BN(2), new BN(3))
).toEqual(new BN(3));
});
it('finds BN maximum', (): void => {
expect(
bnMax(new BN(2), new BN(3), new BN(1))
).toEqual(new BN(3));
});
});
+1 -1
View File
@@ -6,7 +6,7 @@ import { BN, bnMin } from '.';
describe('bnMin', (): void => {
it('finds BN minimum', (): void => {
expect(
bnMin(new BN(1), new BN(2), new BN(3))
bnMin(new BN(2), new BN(1), new BN(3))
).toEqual(new BN(1));
});
});
+9 -8
View File
@@ -5,6 +5,7 @@ import type { HexString, ToBn, ToBnOptions } from '../types';
import type { BN } from './bn';
import { isNumber } from '../is/number';
import { objectSpread } from '../object/spread';
import { u8aToHex } from '../u8a';
import { bnToU8a } from './toU8a';
@@ -36,14 +37,14 @@ function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number
return ZERO_STR;
}
const _options = {
isLe: false,
isNegative: false,
// Backwards-compatibility
...(isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1)
};
return u8aToHex(bnToU8a(value, _options));
return u8aToHex(
bnToU8a(value, objectSpread(
{ isLe: false, isNegative: false },
isNumber(arg1)
? { bitLength: arg1, isLe: arg2 }
: arg1
))
);
}
export { bnToHex };
+7 -6
View File
@@ -5,6 +5,7 @@ import type { ToBn, ToBnOptions } from '../types';
import type { BN } from './bn';
import { isNumber } from '../is/number';
import { objectSpread } from '../object/spread';
import { bnToBn } from './toBn';
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, 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,
isNegative: false,
...isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1
};
const options: Options = objectSpread(
{ bitLength: -1, isLe: true, isNegative: false },
isNumber(arg1)
? { bitLength: arg1, isLe: arg2 }
: arg1
);
const valueBn = bnToBn(value);
const byteLength = options.bitLength === -1
+7 -1
View File
@@ -7,5 +7,11 @@ import { BN } from './bn';
export function checkMaxMin (type: 'max' | 'min', items: BN[]): BN {
assert(items.length >= 1, 'Must provide one or more BN arguments');
return items.reduce<BN>((a, v) => BN[type](a, v), items[0]);
let result = items[0];
for (const v of items) {
result = BN[type](result, v);
}
return result;
}
+2
View File
@@ -15,9 +15,11 @@ export * from './extractTime';
export * from './format';
export * from './hex';
export * from './is';
export * from './lazy';
export * from './logger';
export * from './memoize';
export * from './number';
export * from './object';
export * from './promisify';
export * from './string';
export * from './stringify';
+8 -6
View File
@@ -3,6 +3,8 @@
import type { Time } from './types';
import { objectSpread } from './object/spread';
const HRS = 60 * 60;
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 {
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 {
@@ -35,7 +37,7 @@ function extractHrs (milliseconds: number, mins: number): Time {
if (hrs < 24) {
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);
@@ -47,7 +49,7 @@ function extractMins (milliseconds: number, secs: number): Time {
if (mins < 60) {
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);
@@ -59,7 +61,7 @@ function extractSecs (milliseconds: number): Time {
if (secs < 60) {
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);
@@ -81,7 +83,7 @@ export function extractTime (milliseconds?: number): Time {
if (!milliseconds) {
return ZERO;
} else if (milliseconds < 1000) {
return { ...ZERO, milliseconds };
return objectSpread({}, ZERO, { milliseconds });
}
return extractSecs(milliseconds);
+7 -10
View File
@@ -5,6 +5,7 @@ import type { ToBnOptions } from '../types';
import { BN } from '../bn/bn';
import { isBoolean } from '../is/boolean';
import { objectSpread } from '../object/spread';
import { hexStripPrefix } from './stripPrefix';
function reverse (value: string): string {
@@ -36,16 +37,12 @@ export function hexToBn (value?: string | null, options: ToBnOptions | boolean =
return new BN(0);
}
const _options: ToBnOptions = {
isLe: false,
isNegative: false,
// Backwards-compatibility
...(
isBoolean(options)
? { isLe: options }
: options
)
};
const _options: ToBnOptions = objectSpread(
{ isLe: false, isNegative: false },
isBoolean(options)
? { isLe: options }
: options
);
const _value = hexStripPrefix(value);
// 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);
}
+22 -6
View File
@@ -9,6 +9,19 @@ import { isString } from './string';
const FORMAT = [9, 10, 13];
/** @internal */
function getCharCode0 (s: string): number {
return s.charCodeAt(0);
}
/** @internal */
function isAsciiByte (b: number): boolean {
return (b < 127) && (
(b >= 32) ||
FORMAT.includes(b)
);
}
/**
* @name isAscii
* @summary Tests if the input is printable ASCII
@@ -18,10 +31,13 @@ const FORMAT = [9, 10, 13];
export function isAscii (value?: U8aLike | null): boolean {
const isStringIn = isString(value);
return value
? (isStringIn && !isHex(value)
? value.toString().split('').map((s) => s.charCodeAt(0))
: u8aToU8a(value)
).every((b) => (b < 127) && ((b >= 32) || FORMAT.includes(b)))
: isStringIn;
if (value) {
return (
isStringIn && !isHex(value)
? value.toString().split('').map(getCharCode0)
: u8aToU8a(value)
).every(isAsciiByte);
}
return isStringIn;
}
+6 -1
View File
@@ -17,5 +17,10 @@ interface Compact<T> {
* @summary Tests for SCALE-Compact-like object instance.
*/
export function isCompact <T> (value: unknown): value is Compact<T> {
return isFunction((value as Compact<T>).toBigInt) && isFunction((value as Compact<T>).toBn) && isFunction((value as Compact<T>).toNumber) && isFunction((value as Compact<T>).unwrap);
return (
isFunction((value as Compact<T>).toBigInt) &&
isFunction((value as Compact<T>).toBn) &&
isFunction((value as Compact<T>).toNumber) &&
isFunction((value as Compact<T>).unwrap)
);
}
+1 -3
View File
@@ -1,8 +1,6 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isInstanceOf } from './instanceOf';
/**
* @name isError
* @summary Tests for a `Error` object instance.
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
* ```
*/
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
*/
export { isArray } from './array';
export { isAscii } from './ascii';
export { isBigInt } from './bigInt';
export { isBn } from './bn';
+5 -3
View File
@@ -5,8 +5,7 @@ import { isFunction } from './function';
import { isObject } from './object';
interface Observable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
next: (...params: any[]) => any;
next: (...params: unknown[]) => unknown;
}
/**
@@ -24,5 +23,8 @@ interface Observable {
* ```
*/
export function isObservable (value: unknown): value is Observable {
return isObject(value) && isFunction((value as Observable).next);
return (
isObject(value) &&
isFunction((value as Observable).next)
);
}
+1 -3
View File
@@ -1,8 +1,6 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isInstanceOf } from './instanceOf';
/**
* @name isU8a
* @summary Tests for a `Uint8Array` object instance.
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
* ```
*/
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;
}
+60 -31
View File
@@ -24,11 +24,13 @@ const logTo = {
function formatOther (value: unknown): unknown {
if (value && isObject(value) && value.constructor === Object) {
return Object.keys(value).reduce((result: Record<string, unknown>, key): Record<string, unknown> => {
result[key] = loggerFormat(value[key]);
const result: Record<string, unknown> = {};
return result;
}, {});
for (const k of Object.keys(value)) {
result[k] = loggerFormat(value[k]);
}
return result;
}
return value;
@@ -46,6 +48,20 @@ export function loggerFormat (value: unknown): unknown {
return formatOther(value);
}
function formatWithLength (maxLength: number): (v: unknown) => unknown {
return (v: unknown): unknown => {
if (maxLength <= 0) {
return v;
}
const r = `${v as string}`;
return r.length < maxLength
? v
: `${r.substr(0, maxLength)} ...`;
};
}
function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1): void {
if (values.length === 1 && isFunction(values[0])) {
const fnResult = values[0]() as unknown;
@@ -58,17 +74,7 @@ function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1):
type,
...values
.map(loggerFormat)
.map((v) => {
if (maxSize <= 0) {
return v;
}
const r = `${v as string}`;
return r.length < maxSize
? v
: `${r.substr(0, maxSize)} ...`;
})
.map(formatWithLength(maxSize))
);
}
@@ -76,27 +82,50 @@ function noop (): void {
// noop
}
function isDebugOn (e: string, type: string): boolean {
return !!e && (
e === '*' ||
type === e ||
(
e.endsWith('*') &&
type.startsWith(e.slice(0, -1))
)
);
}
function isDebugOff (e: string, type: string): boolean {
return !!e && (
e.startsWith('-') &&
(
type === e.slice(1) ||
(
e.endsWith('*') &&
type.startsWith(e.slice(1, -1))
)
)
);
}
function getDebugFlag (env: string[], type: string): boolean {
let flag = false;
for (const e of env) {
if (isDebugOn(e, type)) {
flag = true;
} else if (isDebugOff(e, type)) {
flag = false;
}
}
return flag;
}
function parseEnv (type: string): [boolean, number] {
const env = (typeof process === 'object' ? process : {}).env || {};
const maxSize = parseInt(env.DEBUG_MAX || '-1', 10);
let isDebugOn = false;
(env.DEBUG || '')
.toLowerCase()
.split(',')
.forEach((e) => {
if (!!e && (e === '*' || type === e || (e.endsWith('*') && type.startsWith(e.slice(0, -1))))) {
isDebugOn = true;
}
if (!!e && e.startsWith('-') && (type === e.slice(1) || (e.endsWith('*') && type.startsWith(e.slice(1, -1))))) {
isDebugOn = false;
}
});
return [
isDebugOn,
getDebugFlag((env.DEBUG || '').toLowerCase().split(','), type),
isNaN(maxSize)
? -1
: maxSize
+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
export const packageInfo = { name: '@polkadot/util', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/util', version: '7.8.2' };
+9 -9
View File
@@ -3,13 +3,13 @@
import { isBigInt } from './is/bigInt';
export function stringify (args: unknown, space?: string | number): string {
return JSON.stringify(
args,
(_, value: unknown) =>
isBigInt(value)
? value.toString()
: value,
space
);
/** @internal */
function replacer (_: unknown, v: unknown): unknown {
return isBigInt(v)
? v.toString()
: v;
}
export function stringify (args: unknown, space?: string | number): string {
return JSON.stringify(args, replacer, space);
}
+5 -1
View File
@@ -1,6 +1,10 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
function isByteZero (v: number): boolean {
return !v;
}
/**
* @name u8aEmpty
* @summary Tests for a `Uint8Array` for emptyness
@@ -8,5 +12,5 @@
* Checks to see if the input `Uint8Array` has zero length or contains all 0 values.
*/
export function u8aEmpty (value: Uint8Array): boolean {
return value.length === 0 || value.every((v) => !v);
return value.length === 0 || value.every(isByteZero);
}
+16 -10
View File
@@ -44,30 +44,36 @@ function getEntry (name: string): VersionPath[] {
}
function getVersionLength (all: { version: string }[]): number {
return all.reduce((max, { version }) => Math.max(max, version.length), 0);
let length = 0;
for (const { version } of all) {
length = Math.max(length, version.length);
}
return length;
}
/** @internal */
function flattenInfos (all: PackageJson[]): string {
const verLength = getVersionLength(all);
const stringify = ({ name, version }: PackageJson) =>
`\t${version.padEnd(verLength)}\t${name}`;
return all
.map(({ name, version }) => `\t${version.padEnd(verLength)}\t${name}`)
.join('\n');
return all.map(stringify).join('\n');
}
/** @internal */
function flattenVersions (entry: VersionPath[]): string {
const all = entry.map((version: VersionPath | string): VersionPath =>
const toPath = (version: VersionPath | string): VersionPath =>
isString(version)
? { version }
: version
);
: version;
const all = entry.map(toPath);
const verLength = getVersionLength(all);
const stringify = ({ path, version }: VersionPath) =>
`\t${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`;
return all
.map(({ path, version }) => `\t${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`)
.join('\n');
return all.map(stringify).join('\n');
}
/** @internal */
+17 -13
View File
@@ -1,23 +1,27 @@
{
"name": "@polkadot/x-bundle",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A bundler helper",
"main": "index.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-bundle#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-bundle",
"repository": {
"directory": "packages/x-bundle",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/util": "7.6.1",
"@babel/runtime": "^7.16.0",
"@polkadot/util": "7.8.2",
"buffer-es6": "^4.9.3"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.8.2' };
+20 -16
View File
@@ -1,26 +1,30 @@
{
"name": "@polkadot/x-fetch",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A cross-environment fetch replacement",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-fetch#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-fetch",
"repository": {
"directory": "packages/x-fetch",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/x-global": "7.6.1",
"@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.8.2",
"@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
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.8.2' };
+16 -12
View File
@@ -1,21 +1,25 @@
{
"name": "@polkadot/x-global",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A cross-environment global replacement",
"main": "index.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-global#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-global",
"repository": {
"directory": "packages/x-global",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"main": "index.js",
"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
export const packageInfo = { name: '@polkadot/x-global', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-global', version: '7.8.2' };
+20 -16
View File
@@ -1,27 +1,31 @@
{
"name": "@polkadot/x-randomvalues",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A cross-environment window.crypto.getRandomValues replacement",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-randomvalues#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-randomvalues",
"repository": {
"directory": "packages/x-randomvalues",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/x-global": "7.6.1"
"@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.8.2"
},
"devDependencies": {
"@types/react-native": "^0.66.0"
"@types/react-native": "^0.66.2"
}
}
+7 -5
View File
@@ -5,10 +5,12 @@ import crypto from 'crypto';
export { packageInfo } from './packageInfo';
export function getRandomValues <T extends Uint8Array> (arr: T): T {
return crypto.randomBytes(arr.length).reduce((arr, value, index) => {
arr[index] = value;
export function getRandomValues <T extends Uint8Array> (output: T): T {
const bytes = crypto.randomBytes(output.length);
return arr;
}, arr);
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.8.2' };
+9 -9
View File
@@ -19,18 +19,18 @@ interface RNExt {
}
}
function getRandomValuesNative <T extends Uint8Array> (arr: T): T {
return Buffer
.from((NativeModules as RNExt).RNGetRandomValues.getRandomBase64(arr.length), 'base64')
.reduce((arr, byte, index): T => {
arr[index] = byte;
function getRandomValuesNative <T extends Uint8Array> (output: T): T {
const bytes = Buffer.from((NativeModules as RNExt).RNGetRandomValues.getRandomBase64(output.length), 'base64');
return arr;
}, arr);
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}
function getRandomValuesGlobal <T extends Uint8Array> (arr: T): T {
return crypto.getRandomValues(arr);
function getRandomValuesGlobal <T extends Uint8Array> (output: T): T {
return crypto.getRandomValues(output);
}
export const getRandomValues = (
+19 -15
View File
@@ -1,24 +1,28 @@
{
"name": "@polkadot/x-textdecoder",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A TextDecoder replacement",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-textdecoder#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-textdecoder",
"repository": {
"directory": "packages/x-textdecoder",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/x-global": "7.6.1"
"@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.8.2"
}
}
+7 -3
View File
@@ -9,8 +9,12 @@ export class TextDecoder {
}
decode (value: Uint8Array): string {
return value.reduce((str, code): string => {
return str + String.fromCharCode(code);
}, '');
let result = '';
for (const c of value) {
result += String.fromCharCode(c);
}
return result;
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.8.2' };
+19 -15
View File
@@ -1,24 +1,28 @@
{
"name": "@polkadot/x-textencoder",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A TextDecoder replacement",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-textencoder#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-textencoder",
"repository": {
"directory": "packages/x-textencoder",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/x-global": "7.6.1"
"@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.8.2"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.8.2' };
+19 -15
View File
@@ -1,25 +1,29 @@
{
"name": "@polkadot/x-ws",
"version": "7.6.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/common/issues",
"contributors": [],
"description": "A cross-environment WebSocket replacement",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"repository": "github:polkadot-js/common",
"bugs": "https://github.com/polkadot-js/common/issues",
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-ws#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/x-ws",
"repository": {
"directory": "packages/x-ws",
"type": "git",
"url": "https://github.com/polkadot-js/common.git"
},
"sideEffects": false,
"type": "module",
"version": "7.8.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/x-global": "7.6.1",
"@babel/runtime": "^7.16.0",
"@polkadot/x-global": "7.8.2",
"@types/websocket": "^1.0.4",
"websocket": "^1.0.34"
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-ws', version: '7.6.1' };
export const packageInfo = { name: '@polkadot/x-ws', version: '7.8.2' };
+809 -809
View File
File diff suppressed because it is too large Load Diff