diff --git a/.github/workflows/ss58-registry.yml b/.github/workflows/ss58-registry.yml new file mode 100644 index 000000000..919228ef3 --- /dev/null +++ b/.github/workflows/ss58-registry.yml @@ -0,0 +1,18 @@ +name: Nightly ss58-registry check +on: + schedule: + - cron: '1 5 * * *' + +jobs: + alltests: + strategy: + matrix: + step: ['test:networks'] + name: ${{ matrix.step }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: ${{ matrix.step }} + run: | + yarn install --immutable | grep -v 'YN0013' + yarn ${{ matrix.step }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1ebc024..aaa502e88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Changes: - Rename `mnemonicToBip39` to `mnemonicToLegacySeed` (used in non-Substrate compatible fashion) - Update pair signature verification to handle MultiSignature results - Move documentation to docs repo +- Added `@polkadot/networks` for a list of known networks and their identifying information ## 3.5.1 Sep 27, 2020 diff --git a/jest.config.js b/jest.config.js index f7da09d18..1950a7d87 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,12 +6,14 @@ const config = require('@polkadot/dev/config/jest'); module.exports = Object.assign({}, config, { moduleNameMapper: { '@polkadot/keyring(.*)$': '/packages/keyring/src/$1', + '@polkadot/networks(.*)$': '/packages/networks/src/$1', '@polkadot/util-(crypto)(.*)$': '/packages/util-$1/src/$2', // eslint-disable-next-line sort-keys '@polkadot/util(.*)$': '/packages/util/src/$1' }, modulePathIgnorePatterns: [ '/packages/keyring/build', + '/packages/networks/build', '/packages/util/build', '/packages/util-crypto/build' ], diff --git a/package.json b/package.json index 417b51436..26e677b5e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "clean": "polkadot-dev-clean-build", "postinstall": "polkadot-dev-yarn-only", "test": "polkadot-dev-run-test --coverage --runInBand", - "test:one": "polkadot-dev-run-test" + "test:one": "polkadot-dev-run-test", + "test:networks": "polkadot-dev-run-test packages/networks/src/checkLatest" }, "devDependencies": { "@babel/core": "^7.11.6", diff --git a/packages/networks/LICENSE b/packages/networks/LICENSE new file mode 100644 index 000000000..0d381b2e9 --- /dev/null +++ b/packages/networks/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/networks/README.md b/packages/networks/README.md new file mode 100644 index 000000000..49f98a31d --- /dev/null +++ b/packages/networks/README.md @@ -0,0 +1,5 @@ +# @polkadot/networks + +A list of all available Substrate networks and their applicable prefixes. + +This list is periodically checked against the master list available at https://github.com/paritytech/substrate/blob/master/ss58-registry.json diff --git a/packages/networks/package.json b/packages/networks/package.json new file mode 100644 index 000000000..7eb299fb4 --- /dev/null +++ b/packages/networks/package.json @@ -0,0 +1,36 @@ +{ + "name": "@polkadot/networks", + "version": "3.6.0-beta.6", + "description": "A list of all available Substrate networks and their applicable prefixes", + "main": "index.js", + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/polkadot-js/common.git" + }, + "keywords": [ + "Polkadot", + "Keyring", + "ed25519" + ], + "author": "Jaco Greeff ", + "maintainers": [ + "Jaco Greeff " + ], + "contributors": [], + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/polkadot-js/common/issues" + }, + "homepage": "https://github.com/polkadot-js/common/tree/master/packages/networks#readme", + "dependencies": { + "@babel/runtime": "^7.11.2" + }, + "devDependencies": { + "@polkadot/util": "3.6.0-beta.6", + "@polkadot/x-fetch": "^0.3.2" + } +} diff --git a/packages/networks/src/checkLatest.spec.ts b/packages/networks/src/checkLatest.spec.ts new file mode 100644 index 000000000..9d53fa374 --- /dev/null +++ b/packages/networks/src/checkLatest.spec.ts @@ -0,0 +1,59 @@ +// Copyright 2017-2020 @polkadot/networks authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { Ss58Registry } from './types'; + +import fetch from '@polkadot/x-fetch'; +import { assert } from '@polkadot/util'; + +import { all } from './'; + +describe('check latest Substrate ss58 registry', (): void => { + let original: Ss58Registry; + + beforeAll(async (): Promise => { + const response = await fetch('https://raw.githack.com/paritytech/substrate/master/ss58-registry.json'); + + original = await response.json() as Ss58Registry; + }); + + it('has the same number as the original', (): void => { + expect(all.length).toEqual(original.registry.length); + }); + + it('has no missing any entries', (): void => { + const missing = original.registry + .filter(({ prefix }) => !all.some((n) => n.prefix === prefix)) + .map(({ displayName, prefix }) => `${displayName} (${prefix})}`); + + assert(!missing.length, `Missing entries found: ${missing.join(', ')}`); + }); + + it('has no extra entries', (): void => { + const missing = all + .filter(({ prefix }) => !original.registry.some((n) => n.prefix === prefix)) + .map(({ displayName, prefix }) => `${displayName} (${prefix})}`); + + assert(!missing.length, `Extra entries found: ${missing.join(', ')}`); + }); + + it('has the same values as the original', (): void => { + const fields = Object.keys(original.schema); + const errors = original.registry + .map((n): [string, string[]] => { + const other = all.find(({ prefix }) => prefix === n.prefix); + + return [ + `${n.displayName} (${n.prefix})`, + other + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + ? fields.filter((f) => JSON.stringify(n[f]) !== JSON.stringify(other[f])) + : [] + ]; + }) + .filter(([, fields]) => fields.length); + + assert(!errors.length, `Mismatches found: ${JSON.stringify(errors.map(([name, m]) => `${name} on ${m.join(', ')}`), null, 2)}`); + }); +}); diff --git a/packages/networks/src/index.spec.ts b/packages/networks/src/index.spec.ts new file mode 100644 index 000000000..21d61958b --- /dev/null +++ b/packages/networks/src/index.spec.ts @@ -0,0 +1,10 @@ +// Copyright 2017-2020 @polkadot/networks authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import filtered from './'; + +describe('filtered', (): void => { + it('has the correct starting order', (): void => { + expect(filtered.slice(0, 3).map(({ prefix }) => prefix)).toEqual([0, 2, 42]); + }); +}); diff --git a/packages/networks/src/index.ts b/packages/networks/src/index.ts new file mode 100644 index 000000000..37e70c355 --- /dev/null +++ b/packages/networks/src/index.ts @@ -0,0 +1,386 @@ +// Copyright 2017-2020 @polkadot/networks authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { Network, NetworkFromSubstrate } from './types'; + +// These are known prefixes that are not sorted +const UNSORTED = [0, 2, 42]; + +const all: NetworkFromSubstrate[] = [ + { + decimals: [10], + displayName: 'Polkadot Relay Chain', + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + icon: 'polkadot', + network: 'polkadot', + prefix: 0, + standardAccount: '*25519', + symbols: ['DOT'], + website: 'https://polkadot.network' + }, + { + decimals: null, + displayName: 'This prefix is reserved.', + network: 'reserved1', + prefix: 1, + standardAccount: null, + symbols: null, + website: null + }, + { + decimals: [12], + displayName: 'Kusama Relay Chain', + genesisHash: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', + icon: 'polkadot', + network: 'kusama', + prefix: 2, + standardAccount: '*25519', + symbols: ['KSM'], + website: 'https://kusama.network' + }, + { + decimals: null, + displayName: 'This prefix is reserved.', + network: 'reserved3', + prefix: 3, + standardAccount: null, + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'Katal Chain', + network: 'katalchain', + prefix: 4, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'Plasm Network', + genesisHash: '0x3e86364d4b4894021cb2a0390bcf2feb5517d5292f2de2bb9404227e908b0b8b', + network: 'plasm', + prefix: 5, + standardAccount: '*25519', + symbols: ['PLM'], + website: null + }, + { + decimals: [12], + displayName: 'Bifrost', + network: 'bifrost', + prefix: 6, + standardAccount: '*25519', + symbols: ['BNC'], + website: 'https://bifrost.finance/' + }, + { + decimals: [18], + displayName: 'Edgeware', + genesisHash: '0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b', + network: 'edgeware', + prefix: 7, + standardAccount: '*25519', + symbols: ['EDG'], + website: 'https://edgewa.re' + }, + { + decimals: [18], + displayName: 'Acala Karura Canary', + network: 'karura', + prefix: 8, + standardAccount: '*25519', + symbols: ['KAR'], + website: 'https://acala.network/' + }, + { + decimals: [18], + displayName: 'Laminar Reynolds Canary', + network: 'reynolds', + prefix: 9, + standardAccount: '*25519', + symbols: ['REY'], + website: 'http://laminar.network/' + }, + { + decimals: [18], + displayName: 'Acala', + network: 'acala', + prefix: 10, + standardAccount: '*25519', + symbols: ['ACA'], + website: 'https://acala.network/' + }, + { + decimals: [18], + displayName: 'Laminar', + network: 'laminar', + prefix: 11, + standardAccount: '*25519', + symbols: ['LAMI'], + website: 'http://laminar.network/' + }, + { + decimals: null, + displayName: 'Polymath', + network: 'polymath', + prefix: 12, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'SubstraTEE', + network: 'substratee', + prefix: 13, + standardAccount: '*25519', + symbols: null, + website: 'https://www.substratee.com' + }, + { + decimals: [12], + displayName: 'Kulupu', + genesisHash: '0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba', + network: 'kulupu', + prefix: 16, + standardAccount: '*25519', + symbols: ['KLP'], + website: 'https://kulupu.network/' + }, + { + decimals: null, + displayName: 'Dark Mainnet', + network: 'dark', + prefix: 17, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: [9, 9], + displayName: 'Darwinia Network', + network: 'darwinia', + prefix: 18, + standardAccount: '*25519', + symbols: ['RING', 'KTON'], + website: 'https://darwinia.network/' + }, + { + decimals: [12], + displayName: 'GeekCash', + network: 'geek', + prefix: 19, + standardAccount: '*25519', + symbols: ['GEEK'], + website: 'https://geekcash.org' + }, + { + decimals: null, + displayName: 'Stafi', + genesisHash: '0x290a4149f09ea0e402c74c1c7e96ae4239588577fe78932f94f5404c68243d80', + network: 'stafi', + prefix: 20, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: [6], + displayName: 'Dock Testnet', + network: 'dock-testnet', + prefix: 21, + standardAccount: '*25519', + symbols: ['DCK'], + website: 'https://dock.io' + }, + { + decimals: [6], + displayName: 'Dock Mainnet', + network: 'dock-mainnet', + prefix: 22, + standardAccount: '*25519', + symbols: ['DCK'], + website: 'https://dock.io' + }, + { + decimals: null, + displayName: 'ShiftNrg', + network: 'shift', + prefix: 23, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: [18], + displayName: 'ZERO', + network: 'zero', + prefix: 24, + standardAccount: '*25519', + symbols: ['PLAY'], + website: 'https://zero.io' + }, + { + decimals: [18], + displayName: 'ZERO Alphaville', + network: 'zero-alphaville', + prefix: 25, + standardAccount: '*25519', + symbols: ['PLAY'], + website: 'https://zero.io' + }, + { + decimals: null, + displayName: 'Subsocial', + genesisHash: '0x0bd72c1c305172e1275278aaeb3f161e02eccb7a819e63f62d47bd53a28189f8', + network: 'subsocial', + prefix: 28, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'Phala Network', + network: 'phala', + prefix: 30, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'Robonomics Network', + network: 'robonomics', + prefix: 32, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'DataHighway', + network: 'datahighway', + prefix: 33, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: [18], + displayName: 'Centrifuge Chain', + network: 'centrifuge', + prefix: 36, + standardAccount: '*25519', + symbols: ['RAD'], + website: 'https://centrifuge.io/' + }, + { + decimals: [18], + displayName: 'Nodle Chain', + network: 'nodle', + prefix: 37, + standardAccount: '*25519', + symbols: ['NODL'], + website: 'https://nodle.io/' + }, + { + decimals: [18], + displayName: 'MathChain mainnet', + network: 'mathchain', + prefix: 39, + standardAccount: '*25519', + symbols: ['MATH'], + website: 'https://mathwallet.org' + }, + { + decimals: [18], + displayName: 'MathChain testnet', + network: 'mathchain-testnet', + prefix: 40, + standardAccount: '*25519', + symbols: ['MATH'], + website: 'https://mathwallet.org' + }, + { + decimals: null, + displayName: 'Substrate', + network: 'substrate', + prefix: 42, + standardAccount: '*25519', + symbols: null, + website: 'https://substrate.dev/' + }, + { + decimals: null, + displayName: 'This prefix is reserved.', + network: 'reserved43', + prefix: 43, + standardAccount: null, + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'ChainX', + network: 'chainx', + prefix: 44, + standardAccount: '*25519', + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'This prefix is reserved.', + network: 'reserved46', + prefix: 46, + standardAccount: null, + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'This prefix is reserved.', + network: 'reserved47', + prefix: 47, + standardAccount: null, + symbols: null, + website: null + }, + { + decimals: null, + displayName: 'All prefixes 48 and higher are reserved and cannot be allocated.', + network: 'reserved48', + prefix: 48, + standardAccount: null, + symbols: null, + website: null + } +]; + +const prefixes: number[] = all + .filter(({ standardAccount }) => standardAccount === '*25519') + .map(({ prefix }) => prefix); + +// map, filter & sort to get a trimmed list +// - we only include those where we have a genesisHash (and prefix 42) +// - when no icon has been specified, default to substrate +// - sort by name, however we keep 0, 2, 42 first in the list +const filtered: Network[] = all + .filter((n): n is Network => !!(n as Network).genesisHash || n.prefix === 42) + .map((n) => ({ ...n, icon: n.icon || 'substrate' })) + .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 { all, prefixes }; + +export default filtered; diff --git a/packages/networks/src/types.ts b/packages/networks/src/types.ts new file mode 100644 index 000000000..1720c7f81 --- /dev/null +++ b/packages/networks/src/types.ts @@ -0,0 +1,27 @@ +// Copyright 2017-2020 @polkadot/keyring authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export type Icon = 'beachball' | 'empty' | 'jdenticon' | 'polkadot' | 'substrate'; + +export interface NetworkFromSubstrate { + decimals: number[] | null, + displayName: string; + network: string; + prefix: number; + genesisHash?: string | null; + icon?: Icon | null; + standardAccount: '*25519' | null; + symbols: string[] | null; + website: string | null; +} + +export interface Network extends NetworkFromSubstrate { + genesisHash: string | null; + icon: Icon; +} + +export interface Ss58Registry { + registry: NetworkFromSubstrate[]; + specification: string; + schema: Record; +} diff --git a/packages/util-crypto/package.json b/packages/util-crypto/package.json index 4a65064ad..a6d1897bf 100644 --- a/packages/util-crypto/package.json +++ b/packages/util-crypto/package.json @@ -26,6 +26,7 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme", "dependencies": { "@babel/runtime": "^7.11.2", + "@polkadot/networks": "3.6.0-beta.6", "@polkadot/util": "3.6.0-beta.6", "@polkadot/wasm-crypto": "^1.4.1", "base-x": "^3.0.8", diff --git a/packages/util-crypto/src/address/defaults.ts b/packages/util-crypto/src/address/defaults.ts index 831934fc2..e7d07a27f 100644 --- a/packages/util-crypto/src/address/defaults.ts +++ b/packages/util-crypto/src/address/defaults.ts @@ -1,13 +1,13 @@ // Copyright 2017-2020 @polkadot/util-crypto authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { allowedSS58 } from './ss58'; +import { prefixes } from '@polkadot/networks'; 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], - allowedPrefix: allowedSS58, + allowedPrefix: prefixes, prefix: 42 }; diff --git a/packages/util-crypto/src/address/ss58.ts b/packages/util-crypto/src/address/ss58.ts deleted file mode 100644 index 6df254614..000000000 --- a/packages/util-crypto/src/address/ss58.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2020 @polkadot/util-crypto authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -export const allowedSS58 = [ - // Polkadot - 0, 1, - // Kusama - 2, 3, - // Katal Chain - 4, - // Kulupu - 16, 17, - // Dothereum - 20, - // Dock testnet and mainnet - 21, 22, - // Substrate default - 42, 43, - // Substrate BBQ (deprecated) - 68, 69 -]; diff --git a/tsconfig.json b/tsconfig.json index ad4162b1b..b5151ee73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,8 @@ "paths": { "@polkadot/keyring": [ "packages/keyring/src" ], "@polkadot/keyring/*": [ "packages/keyring/src/*" ], + "@polkadot/networks": [ "packages/networks/src" ], + "@polkadot/networks/*": [ "packages/networks/src/*" ], "@polkadot/util-crypto": [ "packages/util-crypto/src" ], "@polkadot/util-crypto/*": [ "packages/util-crypto/src/*" ], "@polkadot/util": [ "packages/util/src" ], diff --git a/yarn.lock b/yarn.lock index c6fffebf7..0ea19eb1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1820,6 +1820,16 @@ __metadata: languageName: unknown linkType: soft +"@polkadot/networks@3.6.0-beta.6, @polkadot/networks@workspace:packages/networks": + version: 0.0.0-use.local + resolution: "@polkadot/networks@workspace:packages/networks" + dependencies: + "@babel/runtime": ^7.11.2 + "@polkadot/util": 3.6.0-beta.6 + "@polkadot/x-fetch": ^0.3.2 + languageName: unknown + linkType: soft + "@polkadot/ts@npm:^0.3.49": version: 0.3.49 resolution: "@polkadot/ts@npm:0.3.49" @@ -1834,6 +1844,7 @@ __metadata: resolution: "@polkadot/util-crypto@workspace:packages/util-crypto" dependencies: "@babel/runtime": ^7.11.2 + "@polkadot/networks": 3.6.0-beta.6 "@polkadot/util": 3.6.0-beta.6 "@polkadot/wasm-crypto": ^1.4.1 "@types/bn.js": ^4.11.6 @@ -1878,6 +1889,17 @@ __metadata: languageName: node linkType: hard +"@polkadot/x-fetch@npm:^0.3.2": + version: 0.3.2 + resolution: "@polkadot/x-fetch@npm:0.3.2" + dependencies: + "@babel/runtime": ^7.11.2 + "@types/node-fetch": ^2.5.7 + node-fetch: ^2.6.1 + checksum: 51d768e41e01cad09758ab641178cc192c81af85c2d5bd9bc6c033fbf0d6e09af4889e7371ed14e64b6189f55ee5084baa8612287de699a5f3ede8bad7ee9be0 + languageName: node + linkType: hard + "@polkadot/x-textdecoder@npm:^0.3.2": version: 0.3.2 resolution: "@polkadot/x-textdecoder@npm:0.3.2" @@ -2106,6 +2128,16 @@ __metadata: languageName: node linkType: hard +"@types/node-fetch@npm:^2.5.7": + version: 2.5.7 + resolution: "@types/node-fetch@npm:2.5.7" + dependencies: + "@types/node": "*" + form-data: ^3.0.0 + checksum: 101f6e8474407f957dfe1750d82aa0bcaa56347d09c8ba8634e6a901d07032533c0a578860691d915ff8fa230355700c41c04ae7e505840b5d6ff8cc3ece7741 + languageName: node + linkType: hard + "@types/node@npm:*": version: 14.11.5 resolution: "@types/node@npm:14.11.5" @@ -3783,7 +3815,7 @@ __metadata: languageName: node linkType: hard -"combined-stream@npm:^1.0.6, combined-stream@npm:~1.0.6": +"combined-stream@npm:^1.0.6, combined-stream@npm:^1.0.8, combined-stream@npm:~1.0.6": version: 1.0.8 resolution: "combined-stream@npm:1.0.8" dependencies: @@ -5513,6 +5545,17 @@ __metadata: languageName: node linkType: hard +"form-data@npm:^3.0.0": + version: 3.0.0 + resolution: "form-data@npm:3.0.0" + dependencies: + asynckit: ^0.4.0 + combined-stream: ^1.0.8 + mime-types: ^2.1.12 + checksum: 1af88217b449eda6566a0d95185f2baa403ed2a0e3b11547069f6062be66cbac7c8d7a25f0fc59560702e96526e659b5b9e5a8c6fefe00f06da44338191a9133 + languageName: node + linkType: hard + "form-data@npm:~2.3.2": version: 2.3.3 resolution: "form-data@npm:2.3.3" @@ -8311,7 +8354,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"node-fetch@npm:^2.6.0": +"node-fetch@npm:^2.6.0, node-fetch@npm:^2.6.1": version: 2.6.1 resolution: "node-fetch@npm:2.6.1" checksum: cbb171635e538162b977eac5dfe7a1e07a9a02e991924377a6435502291e2f823d306b95aabc455caebf4a118ccf836868462bc70ccc3095af02bb9da61fda37