Display hex public key on address conversion (#9388)
* Display hex public key on address conversion * CHANGELOG * lint * Adjust imgConvert sorting
This commit is contained in:
parent
a73ac193ab
commit
72ebff86a6
@ -1,5 +1,13 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## master
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Display hex public key in address conversion utility
|
||||||
|
- Disable unreachable endpoints
|
||||||
|
|
||||||
|
|
||||||
## 0.129.1 Apr 30, 2023
|
## 0.129.1 Apr 30, 2023
|
||||||
|
|
||||||
Contributed:
|
Contributed:
|
||||||
|
|||||||
@ -14,8 +14,8 @@ export { chainsBitgreenPNG } from './generated/bitgreenPNG.js';
|
|||||||
export { chainsBittensorPNG } from './generated/bittensorPNG.js';
|
export { chainsBittensorPNG } from './generated/bittensorPNG.js';
|
||||||
export { chainsBrainstormPNG } from './generated/brainstormPNG.js';
|
export { chainsBrainstormPNG } from './generated/brainstormPNG.js';
|
||||||
export { chainsComposableFinancePNG } from './generated/composableFinancePNG.js';
|
export { chainsComposableFinancePNG } from './generated/composableFinancePNG.js';
|
||||||
export { chainsCreditcoinPNG } from './generated/creditcoinPNG.js';
|
|
||||||
export { chainsCreditcoinTestPNG } from './generated/creditcoin-testPNG.js';
|
export { chainsCreditcoinTestPNG } from './generated/creditcoin-testPNG.js';
|
||||||
|
export { chainsCreditcoinPNG } from './generated/creditcoinPNG.js';
|
||||||
export { chainsDebioSVG } from './generated/debioSVG.js';
|
export { chainsDebioSVG } from './generated/debioSVG.js';
|
||||||
export { chainsDorafactoryPNG } from './generated/dorafactoryPNG.js';
|
export { chainsDorafactoryPNG } from './generated/dorafactoryPNG.js';
|
||||||
export { chainsDustyPNG } from './generated/dustyPNG.js';
|
export { chainsDustyPNG } from './generated/dustyPNG.js';
|
||||||
@ -41,8 +41,8 @@ export { chainsMangataxPNG } from './generated/mangataxPNG.js';
|
|||||||
export { chainsMoonsamaPNG } from './generated/moonsamaPNG.js';
|
export { chainsMoonsamaPNG } from './generated/moonsamaPNG.js';
|
||||||
export { chainsMyriadPNG } from './generated/myriadPNG.js';
|
export { chainsMyriadPNG } from './generated/myriadPNG.js';
|
||||||
export { chainsOakPNG } from './generated/oakPNG.js';
|
export { chainsOakPNG } from './generated/oakPNG.js';
|
||||||
export { chainsOrigintrailPNG } from './generated/origintrailPNG.js';
|
|
||||||
export { chainsOrigintrailTestnetPNG } from './generated/origintrail-testnetPNG.js';
|
export { chainsOrigintrailTestnetPNG } from './generated/origintrail-testnetPNG.js';
|
||||||
|
export { chainsOrigintrailPNG } from './generated/origintrailPNG.js';
|
||||||
export { chainsPeaqPNG } from './generated/peaqPNG.js';
|
export { chainsPeaqPNG } from './generated/peaqPNG.js';
|
||||||
export { chainsPendulumSVG } from './generated/pendulumSVG.js';
|
export { chainsPendulumSVG } from './generated/pendulumSVG.js';
|
||||||
export { chainsPicassoSVG } from './generated/picassoSVG.js';
|
export { chainsPicassoSVG } from './generated/picassoSVG.js';
|
||||||
|
|||||||
@ -14,8 +14,8 @@ export { nodesAstarPNG } from './generated/astarPNG.js';
|
|||||||
export { nodesAutomataPNG } from './generated/automataPNG.js';
|
export { nodesAutomataPNG } from './generated/automataPNG.js';
|
||||||
export { nodesAventusSVG } from './generated/aventusSVG.js';
|
export { nodesAventusSVG } from './generated/aventusSVG.js';
|
||||||
export { nodesBajunPNG } from './generated/bajunPNG.js';
|
export { nodesBajunPNG } from './generated/bajunPNG.js';
|
||||||
export { nodesBasiliskPNG } from './generated/basiliskPNG.js';
|
|
||||||
export { nodesBasiliskRococoBgPNG } from './generated/basilisk-rococo-bgPNG.js';
|
export { nodesBasiliskRococoBgPNG } from './generated/basilisk-rococo-bgPNG.js';
|
||||||
|
export { nodesBasiliskPNG } from './generated/basiliskPNG.js';
|
||||||
export { nodesBeastSVG } from './generated/beastSVG.js';
|
export { nodesBeastSVG } from './generated/beastSVG.js';
|
||||||
export { nodesBifrostSVG } from './generated/bifrostSVG.js';
|
export { nodesBifrostSVG } from './generated/bifrostSVG.js';
|
||||||
export { nodesBitcountryPNG } from './generated/bitcountryPNG.js';
|
export { nodesBitcountryPNG } from './generated/bitcountryPNG.js';
|
||||||
@ -75,8 +75,8 @@ export { nodesKulupuSVG } from './generated/kulupuSVG.js';
|
|||||||
export { nodesKusariSVG } from './generated/kusariSVG.js';
|
export { nodesKusariSVG } from './generated/kusariSVG.js';
|
||||||
export { nodesKylinPNG } from './generated/kylinPNG.js';
|
export { nodesKylinPNG } from './generated/kylinPNG.js';
|
||||||
export { nodesLaminarCircleSVG } from './generated/laminar-circleSVG.js';
|
export { nodesLaminarCircleSVG } from './generated/laminar-circleSVG.js';
|
||||||
export { nodesLitentryPNG } from './generated/litentryPNG.js';
|
|
||||||
export { nodesLitentryRococoPNG } from './generated/litentry-rococoPNG.js';
|
export { nodesLitentryRococoPNG } from './generated/litentry-rococoPNG.js';
|
||||||
|
export { nodesLitentryPNG } from './generated/litentryPNG.js';
|
||||||
export { nodesLitmusPNG } from './generated/litmusPNG.js';
|
export { nodesLitmusPNG } from './generated/litmusPNG.js';
|
||||||
export { nodesLoomNetworkPNG } from './generated/loom_networkPNG.js';
|
export { nodesLoomNetworkPNG } from './generated/loom_networkPNG.js';
|
||||||
export { nodesMantaPNG } from './generated/mantaPNG.js';
|
export { nodesMantaPNG } from './generated/mantaPNG.js';
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
// Copyright 2017-2023 @polkadot/app-utilities authors & contributors
|
// Copyright 2017-2023 @polkadot/app-utilities authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { HexString } from '@polkadot/util/types';
|
||||||
|
|
||||||
import React, { useCallback, useMemo, useState } from 'react';
|
import React, { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { createOption } from '@polkadot/app-settings/util';
|
import { createOption } from '@polkadot/app-settings/util';
|
||||||
@ -8,8 +10,8 @@ import { createSs58 } from '@polkadot/apps-config';
|
|||||||
import { allNetworks } from '@polkadot/networks';
|
import { allNetworks } from '@polkadot/networks';
|
||||||
import { Dropdown, InputAddressSimple, Static } from '@polkadot/react-components';
|
import { Dropdown, InputAddressSimple, Static } from '@polkadot/react-components';
|
||||||
import { useApi } from '@polkadot/react-hooks';
|
import { useApi } from '@polkadot/react-hooks';
|
||||||
import { formatNumber } from '@polkadot/util';
|
import { formatNumber, u8aToHex } from '@polkadot/util';
|
||||||
import { base58Decode, checkAddressChecksum, encodeAddress, isAddress } from '@polkadot/util-crypto';
|
import { base58Decode, checkAddressChecksum, decodeAddress, encodeAddress, isAddress } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
import { useTranslation } from './translate.js';
|
import { useTranslation } from './translate.js';
|
||||||
|
|
||||||
@ -18,32 +20,36 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
address: string | null;
|
|
||||||
inputSS58: number;
|
inputSS58: number;
|
||||||
|
publicKey: HexString | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getState (input: string | null): State {
|
function getState (input: string | null): State {
|
||||||
let address: string | null = null;
|
try {
|
||||||
let inputSS58 = 42;
|
if (input && isAddress(input)) {
|
||||||
|
const decoded = base58Decode(input);
|
||||||
|
const [,,, inputSS58] = checkAddressChecksum(decoded);
|
||||||
|
const publicU8a = decodeAddress(input);
|
||||||
|
|
||||||
if (input && isAddress(input)) {
|
return {
|
||||||
const decoded = base58Decode(input);
|
inputSS58,
|
||||||
const [,,, ss58Decoded] = checkAddressChecksum(decoded);
|
publicKey: u8aToHex(publicU8a)
|
||||||
|
};
|
||||||
address = input;
|
}
|
||||||
inputSS58 = ss58Decoded;
|
} catch {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
address,
|
inputSS58: 42,
|
||||||
inputSS58
|
publicKey: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function Addresses ({ className }: Props): React.ReactElement<Props> {
|
function Addresses ({ className }: Props): React.ReactElement<Props> {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { chainSS58 } = useApi();
|
const { chainSS58 } = useApi();
|
||||||
const [{ address, inputSS58 }, setState] = useState<State>({ address: null, inputSS58: 42 });
|
const [{ inputSS58, publicKey }, setState] = useState<State>({ inputSS58: 42, publicKey: null });
|
||||||
const [prefix, setPrefix] = useState(-1);
|
const [prefix, setPrefix] = useState(-1);
|
||||||
|
|
||||||
const setAddress = useCallback(
|
const setAddress = useCallback(
|
||||||
@ -69,8 +75,8 @@ function Addresses ({ className }: Props): React.ReactElement<Props> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const converted = useMemo(
|
const converted = useMemo(
|
||||||
() => address && encodeAddress(address, prefix === -1 ? chainSS58 : prefix),
|
() => publicKey && encodeAddress(publicKey, prefix === -1 ? chainSS58 : prefix),
|
||||||
[address, chainSS58, prefix]
|
[chainSS58, prefix, publicKey]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -78,7 +84,7 @@ function Addresses ({ className }: Props): React.ReactElement<Props> {
|
|||||||
<div className='ui--row'>
|
<div className='ui--row'>
|
||||||
<InputAddressSimple
|
<InputAddressSimple
|
||||||
autoFocus
|
autoFocus
|
||||||
isError={!address}
|
isError={!publicKey}
|
||||||
label={t<string>('address to convert')}
|
label={t<string>('address to convert')}
|
||||||
noConvert
|
noConvert
|
||||||
onChange={setAddress}
|
onChange={setAddress}
|
||||||
@ -92,7 +98,7 @@ function Addresses ({ className }: Props): React.ReactElement<Props> {
|
|||||||
options={prefixOptions}
|
options={prefixOptions}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{address && (
|
{publicKey && (
|
||||||
<>
|
<>
|
||||||
<div className='ui--row'>
|
<div className='ui--row'>
|
||||||
<Static
|
<Static
|
||||||
@ -111,6 +117,13 @@ function Addresses ({ className }: Props): React.ReactElement<Props> {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
<div className='ui--row'>
|
||||||
|
<Static
|
||||||
|
className='full'
|
||||||
|
label={t<string>('hex public key')}
|
||||||
|
value={publicKey}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import path from 'node:path';
|
|||||||
import { formatNumber, stringCamelCase } from '@polkadot/util';
|
import { formatNumber, stringCamelCase } from '@polkadot/util';
|
||||||
|
|
||||||
const MAX_SIZE = 48 * 1024;
|
const MAX_SIZE = 48 * 1024;
|
||||||
|
|
||||||
|
// FIXME The sorting here and the sorting from linting seems like a mismatch...
|
||||||
const HEADER = '// Copyright 2017-2023 @polkadot/apps authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Do not edit. Auto-generated via node scripts/imgConvert.mjs\n\n';
|
const HEADER = '// Copyright 2017-2023 @polkadot/apps authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Do not edit. Auto-generated via node scripts/imgConvert.mjs\n\n';
|
||||||
|
|
||||||
const MIME = {
|
const MIME = {
|
||||||
@ -90,7 +92,13 @@ for (let dir of ['extensions', 'external', 'chains', 'nodes']) {
|
|||||||
console.log('\n', notfound.length.toString().padStart(3), 'not referenced in', dir, '::\n\n\t', notfound.join(', '), '\n');
|
console.log('\n', notfound.length.toString().padStart(3), 'not referenced in', dir, '::\n\n\t', notfound.join(', '), '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(path.join(sub, 'index.ts'), `${HEADER}${Object.keys(result).sort().map((k) => `export { ${k} } from './${result[k]}.js';`).join('\n')}\n`);
|
fs.writeFileSync(path.join(sub, 'index.ts'), `${HEADER}${
|
||||||
|
Object
|
||||||
|
.keys(result)
|
||||||
|
.sort((a, b) => result[a].localeCompare(result[b]))
|
||||||
|
.map((k) => `export { ${k} } from './${result[k]}.js';`)
|
||||||
|
.join('\n')
|
||||||
|
}\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user