Networks bundling adjustments (#1056)

* Add networks to util bundle

* Bundling for @polkadot/networks

* Move to util-crypto

* Comment

* Update lock

* Re-adjust detectPackage

* Only exports

* Adjust

* Adjust tests

* crosscheck adjust
This commit is contained in:
Jaco
2021-07-09 14:03:21 +02:00
committed by GitHub
parent 337deab526
commit 24548e84e1
9 changed files with 70 additions and 44 deletions
+2
View File
@@ -3,9 +3,11 @@
## master
- **Breaking change** The `@polkadot/x-rxjs` package has been removed. In `rxjs` 7.2.0 the compatibility issues at the base layer has been solved.
- **Breaking change** The named exports in `@polkadot/networks` has been changed
Changes:
- Adjust `@polkadot/networks` to fully-descriptive exports
- Remove `@polkadot/x-rxjs`, direct import from `rxjs >= 7.2.0` required
- Allow building as a completely stand-alone browser bundle (experimental)
+5 -5
View File
@@ -8,7 +8,7 @@ import fs from 'fs';
import { stringify } from '@polkadot/util';
import { fetch } from '@polkadot/x-fetch';
import { all } from './';
import { allNetworks } from './';
const OUTPUT = './.github/ss58-check.md';
const SUBSTRATE_REGISTRY = 'https://raw.githubusercontent.com/paritytech/substrate/master/ss58-registry.json';
@@ -32,19 +32,19 @@ describe('check latest Substrate ss58 registry', (): void => {
});
it('has the same number as the original', (): void => {
assertAndLog(all.length === original.registry.length, `Number of entries mismatched:: Expected ${original.registry.length} found ${all.length}`);
assertAndLog(allNetworks.length === original.registry.length, `Number of entries mismatched:: Expected ${original.registry.length} found ${allNetworks.length}`);
});
it('has no missing any entries', (): void => {
const missing = original.registry
.filter(({ prefix }) => !all.some((n) => n.prefix === prefix))
.filter(({ prefix }) => !allNetworks.some((n) => n.prefix === prefix))
.map(({ displayName, prefix }) => `${displayName} (${prefix})`);
assertAndLog(!missing.length, `Missing entries found: ${stringify(missing, 2)}`);
});
it('has no extra entries', (): void => {
const missing = all
const missing = allNetworks
.filter(({ prefix }) => !original.registry.some((n) => n.prefix === prefix))
.map(({ displayName, prefix }) => `${displayName} (${prefix})`);
@@ -55,7 +55,7 @@ describe('check latest Substrate ss58 registry', (): void => {
const fields = Object.keys(original.schema) as (keyof KnownSubstrate)[];
const errors = original.registry
.map((n): [string, string[]] => {
const other = all.find(({ prefix }) => prefix === n.prefix);
const other = allNetworks.find(({ prefix }) => prefix === n.prefix);
return [
`${n.displayName} (${n.prefix})`,
+13 -13
View File
@@ -4,25 +4,25 @@
import type { SubstrateNetwork } from './types';
import { knownGenesis, knownIcon, knownLedger, knownTestnet } from './defaults';
import filtered, { all, available } from '.';
import { allNetworks, availableNetworks, selectableNetworks } from '.';
describe('filtered', (): void => {
describe('selectableNetworks', (): void => {
it('has the correct starting order', (): void => {
expect(filtered.slice(0, 3).map(({ prefix }) => prefix)).toEqual([0, 2, 42]);
expect(selectableNetworks.slice(0, 3).map(({ prefix }) => prefix)).toEqual([0, 2, 42]);
});
it('has no ignored networks', (): void => {
expect(available.some(({ isIgnored }) => isIgnored)).toEqual(false);
expect(availableNetworks.some(({ isIgnored }) => isIgnored)).toEqual(false);
});
it('has no reserved networks', (): void => {
expect(available.some(({ prefix }) => prefix === 47)).toEqual(false);
expect(availableNetworks.some(({ prefix }) => prefix === 47)).toEqual(false);
});
it('has all genesis information', (): void => {
it('has allNetworks genesis information', (): void => {
expect(
Object.entries(knownGenesis).filter(([network, genesisHash]) =>
available.some((a) =>
availableNetworks.some((a) =>
a.network === network &&
genesisHash.some((g, index) => a.genesisHash[index] !== g)
)
@@ -30,10 +30,10 @@ describe('filtered', (): void => {
).toEqual([]);
});
it('has all ledger details', (): void => {
it('has allNetworks ledger details', (): void => {
expect(
Object.entries(knownLedger).filter(([network, slip44]) =>
available.some((a) =>
availableNetworks.some((a) =>
a.network === network && (
a.slip44 !== slip44 ||
!a.hasLedgerSupport ||
@@ -47,16 +47,16 @@ describe('filtered', (): void => {
it('has no testnets exposed', (): void => {
expect(
Object.keys(knownTestnet).filter((network) =>
available.some((a) =>
availableNetworks.some((a) =>
a.network === network
)
)
).toEqual([]);
});
it('has all icons, except for overrides', (): void => {
it('has allNetworks icons, except for overrides', (): void => {
expect(
available.filter(({ icon, network }) =>
availableNetworks.filter(({ icon, network }) =>
icon !== 'substrate' &&
knownIcon[network] !== icon
)
@@ -67,7 +67,7 @@ describe('filtered', (): void => {
const dupes: SubstrateNetwork[] = [];
const uniques: SubstrateNetwork[] = [];
all.forEach((a): void => {
allNetworks.forEach((a): void => {
if (uniques.some((u) => u.prefix === a.prefix)) {
dupes.push(a);
} else {
+3 -3
View File
@@ -11,7 +11,7 @@ export { packageInfo } from './packageInfo';
// These are known prefixes that are not sorted
const UNSORTED = [0, 2, 42];
export const all = knownSubstrate.map((o): SubstrateNetwork => {
export const allNetworks = knownSubstrate.map((o): SubstrateNetwork => {
const network = o.network || '';
const n = o as SubstrateNetwork;
@@ -30,7 +30,7 @@ export const all = knownSubstrate.map((o): SubstrateNetwork => {
// - we only include those where we have a standardAccount
// - when no icon has been specified, default to substrate
// - sort by name, however we keep 0, 2, 42 first in the list
export const available = all
export const availableNetworks = allNetworks
.filter((n): n is Network => !n.isIgnored && !!n.network)
.sort((a, b) =>
UNSORTED.includes(a.prefix) === UNSORTED.includes(b.prefix)
@@ -43,4 +43,4 @@ export const available = all
);
// A filtered list of those chains we have details about (genesisHashes)
export default available.filter((n) => n.genesisHash.length || n.prefix === 42);
export const selectableNetworks = availableNetworks.filter((n) => n.genesisHash.length || n.prefix === 42);
+2 -2
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { available } from '@polkadot/networks';
import { availableNetworks } from '../networks';
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: available.map(({ prefix }) => prefix),
allowedPrefix: availableNetworks.map(({ prefix }) => prefix),
prefix: 42
};
+1
View File
@@ -19,6 +19,7 @@ export * from './json';
export * from './keccak';
export * from './key';
export * from './mnemonic';
export * from './networks';
export * from './nacl';
export * from './pbkdf2';
export * from './random';
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from '@polkadot/networks';
+1 -2
View File
@@ -8,7 +8,6 @@ import { createBundle } from '@polkadot/dev/config/rollup';
const pkgs = [
'@polkadot/hw-ledger',
'@polkadot/keyring',
'@polkadot/networks',
'@polkadot/util',
'@polkadot/util-crypto'
];
@@ -17,7 +16,7 @@ const external = [
...pkgs
];
const entries = ['hw-ledger-transports', 'x-fetch', 'x-global', 'x-randomvalues', 'x-textdecoder', 'x-textencoder', 'x-ws'].reduce((all, p) => ({
const entries = ['hw-ledger-transports', 'networks', 'x-fetch', 'x-global', 'x-randomvalues', 'x-textdecoder', 'x-textencoder', 'x-ws'].reduce((all, p) => ({
...all,
[`@polkadot/${p}`]: path.resolve(process.cwd(), `packages/${p}/build`)
}), {});
+39 -19
View File
@@ -2,40 +2,60 @@
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style></style>
<title>Bundler tests</title>
<style>
pre {
margin: 0.5rem 0;
}
pre.header {
background: #ddd;
margin-top: 1.5rem;
padding: 0.25rem 0.75rem;
}
</style>
</head>
<body>
Executing bundle tests, see the dev console for output ...
<script>
function log (label, result) {
label.startsWith('*')
? console.log(label)
: console.log(label.padStart(24), '=', result);
const pre = document.createElement('pre');
if (typeof result !== 'undefined') {
pre.innerHTML = `${label.padStart(24)} = ${result}`;
} else {
pre.innerHTML = label;
pre.className = 'header';
}
document.body.appendChild(pre);
}
</script>
<script src="packages/util/build/bundle-polkadot-util.js"></script>
<script>
log('*** polkadotUtil');
log('u8aToHex', polkadotUtil.u8aToHex(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])));
log('bnToBn', polkadotUtil.bnToBn(123).addn(1).toString());
</script>
<script src="packages/networks/build/bundle-polkadot-networks.js"></script>
<script>
log('*** polkadotNetworks');
log('available', polkadotNetworks.available.map(({ displayName }) => displayName).join('; '));
log('polkadotUtil');
const { bnToBn, u8aToHex } = polkadotUtil;
log('u8aToHex', u8aToHex(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])));
log('bnToBn', bnToBn(123).addn(1).toString());
</script>
<script src="packages/util-crypto/build/bundle-polkadot-util-crypto.js"></script>
<script>
log('*** polkadotUtilCrypto');
log('blake2AsHex', polkadotUtilCrypto.blake2AsHex(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])));
log('blake2AsHex (js)', polkadotUtilCrypto.blake2AsHex(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]), 256, null, true));
log('polkadotUtilCrypto');
const { blake2AsHex, selectableNetworks } = polkadotUtilCrypto;
log('blake2AsHex', blake2AsHex(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])));
log('blake2AsHex (js)', blake2AsHex(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]), 256, null, true));
log('selectableNetworks', selectableNetworks.map(({ displayName }) => displayName).join('; '));
</script>
<script src="packages/keyring/build/bundle-polkadot-keyring.js"></script>
<script>
log('*** polkadotKeyring');
log('polkadotKeyring');
const keyring = new polkadotKeyring.Keyring();
const { Keyring } = polkadotKeyring;
const keyring = new Keyring();
const alice = keyring.addFromUri('//Alice');
log('alice.address', alice.address);